//  
// Author: Oliver Maria Kind <mailto: kind@physik.hu-berlin.de>
// Update: $Id: AtlHistogramTool.h,v 1.4 2017/01/22 12:16:49 kind Exp $
// Copyright: 2015 (C) Oliver Maria Kind
//
#ifndef ATLAS_AtlHistogramTool
#define ATLAS_AtlHistogramTool
#ifndef ATLAS_AtlAnalysisTool
#include <AtlAnalysisTool.h>
#endif
#ifndef ROOT_THashList
#include <THashList.h>
#endif
#ifndef ROOT_TH1D
#include <TH1D.h>
#endif
#ifndef ROOT_TH2D
#include <TH2D.h>
#endif
#ifndef ROOT_TNamed
#include <TNamed.h>
#endif

class TDirectory;
class AtlSelector;

class AtlHistObject : public TNamed {
    //
    // Small helper class for the histogram tool
    //
    // To be able to store multiple historams with the same name in
    // different folders, the full path name of a histogram is used
    // for fast access to the hash list. The histogram itself stores
    // only the (short) basename as identifier.
    //
  private:
    TH1 *fHistogram; // Histogram
    
  public:
    AtlHistObject(const char* name, const char* title, TH1 *hist) :
    TNamed(name, title) { fHistogram = hist; }
    virtual ~AtlHistObject() {;}
    inline TH1* GetHistogram() { return fHistogram; }
};

class AtlHistogramTool : public AtlAnalysisTool {

  private:
    TDirectory *fParentDir;  // Top-level folder
    THashList  *fHistograms; // List of histograms
    
  public:
    AtlHistogramTool(const char* name, const char* title);
    virtual ~AtlHistogramTool();

    TH1D* Add(const char* hname, const char* title,
	      Int_t nbinsx, Double_t xlow, Double_t xup,
	      const char* xtitle, const char* ytitle);
    TH2D* Add(const char* hname, const char* title,
	      Int_t nbinsx, Double_t xlow, Double_t xup,
	      Int_t nbinsy, Double_t ylow, Double_t yup,
	      const char* xtitle, const char* ytitle,
	      const char* ztitle);
    TH2D* Add(const char* hname, const char* title,
	      Int_t nbinsx, Double_t xlow, Double_t xup,
	      Int_t nbinsy, const Double_t *ybins,
	      const char* xtitle, const char* ytitle,
	      const char* ztitle);
    void Fill(const char* hname, Double_t x, Double_t w);
    void Fill(const char* hname, Double_t x, Double_t y, Double_t w);
    virtual void SetBranchStatus() {;}
    virtual void BookHistograms() {;}
    virtual void FillHistograms() {;}
    virtual void Print() const;

    inline void Fill(const char* path, const char* hname,
		     Double_t x, Double_t w) {
	//
	// Convenience Fill() member function (see the main Fill()
	// function). The given path will be prepended to the
	// histogram name
	//
	Fill(Form("%s/%s", path, hname), x, w);
    }
    inline void Fill(const char* path, const char* hname,
		     Double_t x, Double_t y, Double_t w) {
	//
	// Convenience Fill() member function (see the main Fill()
	// function). The given path will be prepended to the
	// histogram name
	//
	Fill(Form("%s/%s", path, hname), x, y, w);
    }
	
  private:
    TDirectory* MkDirWithParents(const char* dir);
    
    ClassDef(AtlHistogramTool,0) // Histogram tool
};
#endif

 AtlHistogramTool.h:1
 AtlHistogramTool.h:2
 AtlHistogramTool.h:3
 AtlHistogramTool.h:4
 AtlHistogramTool.h:5
 AtlHistogramTool.h:6
 AtlHistogramTool.h:7
 AtlHistogramTool.h:8
 AtlHistogramTool.h:9
 AtlHistogramTool.h:10
 AtlHistogramTool.h:11
 AtlHistogramTool.h:12
 AtlHistogramTool.h:13
 AtlHistogramTool.h:14
 AtlHistogramTool.h:15
 AtlHistogramTool.h:16
 AtlHistogramTool.h:17
 AtlHistogramTool.h:18
 AtlHistogramTool.h:19
 AtlHistogramTool.h:20
 AtlHistogramTool.h:21
 AtlHistogramTool.h:22
 AtlHistogramTool.h:23
 AtlHistogramTool.h:24
 AtlHistogramTool.h:25
 AtlHistogramTool.h:26
 AtlHistogramTool.h:27
 AtlHistogramTool.h:28
 AtlHistogramTool.h:29
 AtlHistogramTool.h:30
 AtlHistogramTool.h:31
 AtlHistogramTool.h:32
 AtlHistogramTool.h:33
 AtlHistogramTool.h:34
 AtlHistogramTool.h:35
 AtlHistogramTool.h:36
 AtlHistogramTool.h:37
 AtlHistogramTool.h:38
 AtlHistogramTool.h:39
 AtlHistogramTool.h:40
 AtlHistogramTool.h:41
 AtlHistogramTool.h:42
 AtlHistogramTool.h:43
 AtlHistogramTool.h:44
 AtlHistogramTool.h:45
 AtlHistogramTool.h:46
 AtlHistogramTool.h:47
 AtlHistogramTool.h:48
 AtlHistogramTool.h:49
 AtlHistogramTool.h:50
 AtlHistogramTool.h:51
 AtlHistogramTool.h:52
 AtlHistogramTool.h:53
 AtlHistogramTool.h:54
 AtlHistogramTool.h:55
 AtlHistogramTool.h:56
 AtlHistogramTool.h:57
 AtlHistogramTool.h:58
 AtlHistogramTool.h:59
 AtlHistogramTool.h:60
 AtlHistogramTool.h:61
 AtlHistogramTool.h:62
 AtlHistogramTool.h:63
 AtlHistogramTool.h:64
 AtlHistogramTool.h:65
 AtlHistogramTool.h:66
 AtlHistogramTool.h:67
 AtlHistogramTool.h:68
 AtlHistogramTool.h:69
 AtlHistogramTool.h:70
 AtlHistogramTool.h:71
 AtlHistogramTool.h:72
 AtlHistogramTool.h:73
 AtlHistogramTool.h:74
 AtlHistogramTool.h:75
 AtlHistogramTool.h:76
 AtlHistogramTool.h:77
 AtlHistogramTool.h:78
 AtlHistogramTool.h:79
 AtlHistogramTool.h:80
 AtlHistogramTool.h:81
 AtlHistogramTool.h:82
 AtlHistogramTool.h:83
 AtlHistogramTool.h:84
 AtlHistogramTool.h:85
 AtlHistogramTool.h:86
 AtlHistogramTool.h:87
 AtlHistogramTool.h:88
 AtlHistogramTool.h:89
 AtlHistogramTool.h:90
 AtlHistogramTool.h:91
 AtlHistogramTool.h:92
 AtlHistogramTool.h:93
 AtlHistogramTool.h:94
 AtlHistogramTool.h:95
 AtlHistogramTool.h:96
 AtlHistogramTool.h:97
 AtlHistogramTool.h:98
 AtlHistogramTool.h:99
 AtlHistogramTool.h:100
 AtlHistogramTool.h:101