CMS 3D CMS Logo

GFHistManager.h
Go to the documentation of this file.
1 #ifndef __GFHISTMANAGER_H
2 #define __GFHISTMANAGER_H
3 
4  // ROOT includes
5 #include <TObject.h>
6 #include <TArrayI.h>
7 #include <TArrayC.h>
8 #include <TH1.h> // for type Color_t etc.
9 
10 class TObjArray;
11 class TCollection;
12 // class TH1;
13 class TCanvas;
14 class TVirtualPad;
15 class TFile;
16 class TLegend;
17 class TLegendEntry;
18 class GFHistArray;
19 
20 class GFHistManager : public TObject{
21 public:
22  GFHistManager();
23  explicit GFHistManager(TH1* hist);
24  explicit GFHistManager(TCollection* hists);
25  virtual ~GFHistManager();
26 
27  virtual TLegendEntry* AddHist(TH1* hist, Int_t layer = 0, const char* legendTitle = NULL,
28  const char* legOpt = NULL);
29  virtual void AddHists(TCollection* hists, Int_t layer = 0,
30  const char* legendTitle = NULL, const char* legOpt = NULL);
31  virtual TLegendEntry* AddHistSame(TH1* hist, Int_t layer, Int_t nPad,
32  const char* legendTitle=NULL, const char* legOpt=NULL);
33  virtual void AddHistsSame(GFHistArray* hists, Int_t layer,
34  const char* legendTitle = NULL, const char* legOpt = NULL);
35  virtual void AddHistsSame(GFHistArray* hists, Int_t layer, Int_t nPad);
36  virtual void AddLayers(GFHistManager* other);
37  virtual void AddLayer(GFHistManager* other, Int_t layer);
38  virtual void Overlay(GFHistManager* other, Int_t otherLayer, Int_t myLayer,
39  const char* legendTitle);
40  virtual TLegend* AddLegend(Int_t layer, Int_t nPad, const char* header = NULL,
41  Bool_t referAll = kTRUE);
42  virtual Bool_t RemoveLegend(Int_t layer, Int_t nPad);
43  virtual void AddLegend(TLegend* leg, Int_t layer, Int_t nPad);
44  virtual void AddObject(TObject* obj, Int_t layer, Int_t histoNum, Option_t* opt = NULL);
45 
46  virtual void Draw(Option_t * opt = "");
47  virtual void Draw(Int_t layer);
48  using TObject::Print;
49  virtual void Print(const char* filename, Bool_t add = kFALSE);
50 // virtual void Print(const char* filename, Int_t layer);
51  virtual void Clear(Bool_t deleteHists);
52  void Clear(Option_t * = "") {this->Clear(kFALSE);}
53  void Delete(Option_t * = "") {this->Clear(kTRUE);}
54  virtual void SetLegendX1Y1X2Y2(Double_t x1, Double_t y1, Double_t x2, Double_t y2);
55  virtual void SetLegendX1(Double_t x1);// {fLegendX1 = x1;}
56  virtual void SetLegendY1(Double_t y1);// {fLegendY1 = y1;}
57  virtual void SetLegendX2(Double_t x2);// {fLegendX2 = x2;}
58  virtual void SetLegendY2(Double_t y2);// {fLegendY2 = y2;}
59  virtual void SetStatsX1Y1X2Y2(Double_t x1, Double_t y1, Double_t x2, Double_t y2);
60  virtual void SetNumHistsX(UInt_t numX);
61  virtual void SetNumHistsX(UInt_t numX, Int_t layer);
62  virtual void SetNumHistsY(UInt_t numY);
63  virtual void SetNumHistsY(UInt_t numY, Int_t layer);
64  virtual void SetNumHistsXY(UInt_t numX, UInt_t numY);
65  virtual void SetNumHistsXY(UInt_t numX, UInt_t numY, Int_t layer);
66  virtual void SetLogY(Bool_t yesNo = kTRUE);
67  virtual void SetLogY(Int_t layer, Bool_t yesNo = kTRUE);
68  void SetCanvasName(const TString& name);
69  virtual void SetCanvasWidth(Int_t w) {fCanvasWidth = w;}
70  virtual void SetCanvasHeight(Int_t h) {fCanvasHeight = h;}
71  virtual void SetHistsOption(Option_t* option);
72  virtual void SetHistsOption(Option_t* option, Int_t layer);
73  virtual void SetHistsMinMax(Double_t minMax, Bool_t min);
74  virtual void SetHistsMinMax(Double_t minMax, Bool_t min, Int_t layer);
75  static void SetLegendEntryOption(const char* option) {fgLegendEntryOption = option;} // some of "lpf"
76  virtual void AddHistsOption(Option_t* option);
77  virtual void AddHistsOption(Option_t* option, Int_t layer);
78  virtual void SetHistsXTitle(const char* title);
79  virtual void SetHistsXTitle(const char* title, Int_t layer);
80  virtual void SetHistsYTitle(const char* title);
81  virtual void SetHistsYTitle(const char* title, Int_t layer);
82  virtual void SetHistsFillColor(Color_t color);
83  virtual void SetHistsFillColor(Color_t color, Int_t layer);
84  virtual void SetHistsLineWidth(Width_t width);
85  virtual void SetHistsLineWidth(Width_t width, Int_t layer);
86  virtual void SetHistsLineStyle(Int_t style);
87  virtual void SetHistsLineStyle(Int_t style, Int_t layer, Int_t numHistInPad = -1);
88  virtual void SetHistsLineColor(Color_t color);
89  virtual void SetHistsLineColor(Color_t color, Int_t layer);
90  virtual void WriteCanvases(TFile* file);
91  virtual void WriteHistos(TFile* file);
92  virtual void Update();
93  virtual void Update(Int_t layer);
94  virtual Bool_t SetBatch(Bool_t set = kTRUE) {Bool_t r = fBatch; fBatch = set; return r;}
95  virtual Bool_t IsBatch() const {return fBatch;}
96  virtual void ExpandTo(Int_t newDepth);
97 
98  virtual GFHistArray* GetHistsOf(Int_t layer, Int_t histNum, Bool_t mayExpand = kFALSE);
99  virtual TList* GetObjectsOf(Int_t layer, Int_t histNum);
100  virtual Int_t GetNumHistsOf(Int_t layer);
101  virtual TLegend* GetLegendOf(Int_t layer, Int_t nPad);
102  virtual Int_t GetCanvasWidth() const {return fCanvasWidth;}
103  virtual Int_t GetCanvasHeight() const {return fCanvasHeight;}
104  virtual Int_t GetNumHistsX(Int_t layer) const;
105  virtual Int_t GetNumHistsY(Int_t layer) const;
106  virtual Double_t MaxOfHist(const TH1* h) const;
107  virtual Double_t MaxOfHists(const TObjArray* hists) const;
108  virtual Double_t MinOfHist(const TH1* h) const;
109  virtual Double_t MinOfHists(const TObjArray* hists) const;
110  virtual TVirtualPad* GetPad(Int_t layer, Int_t histNum);
111  virtual TCanvas* GetCanvas(Int_t layer, Int_t number = 0);// after draw!!
112  Int_t GetNumLayers() const {return fDepth;}
113  virtual void GetLegendX1Y1X2Y2(Double_t& x1, Double_t& y1, Double_t& x2, Double_t& y2) const;
114 
115  static const Int_t kDefaultPadsPerCanX;// = 2; Doesn't work! Why ???
116  static const Int_t kDefaultPadsPerCanY;// = 2; It should. And it DOES, if we make
117  static const Int_t kDefaultDepth;// = 1; these static const datamembers protected!
118 
119  static Int_t NumberOfSubPadsOf(TCanvas* can);
120  static void MakeDifferentStyle(GFHistArray* hists);
121  Bool_t DrawDiffStyle(Bool_t yesNo) {
122  const Bool_t old = fDrawDiffStyle; fDrawDiffStyle = yesNo; return old;}
123  Bool_t SameWithStats(Bool_t yesNo) {
124  const Bool_t old = fSameWithStats; fSameWithStats = yesNo; return old;}
125 
126 protected:
127  virtual void DrawReally(Int_t layer);
128  virtual void DrawLegend(Int_t layer, Int_t histNo);
129  virtual void DrawObjects(Int_t layer, Int_t histNo);
130  virtual void MakeCanvases(Int_t layer);
131  virtual TObjArray* MakeLegends(Int_t layer);
132  virtual TList* MakeObjList(Int_t layer, Int_t histoNum);
133  virtual void Initialise();
134  virtual Bool_t CheckDepth(const char* method, Int_t layer, Bool_t mayExpand = kTRUE);
135  virtual Bool_t CheckHistNum(const char* method, Int_t layer, Int_t histNum,
136  Bool_t mayExpand = kFALSE);
137  void DrawFuncs(const TH1* hist) const;
138  void ColourStatsBoxes(GFHistArray *hists) const;
139  void ColourFuncs(GFHistArray *hists) const;
140 
141 private:
142  Int_t fDepth; // how many layers of histograms in arrays?
143  TArrayI fNoX; // how many hists in x...
144  TArrayI fNoY; // ... and in y in each canvas array
145  TArrayC fLogY; // whether or not a layer should be plotted in log(y)
146  Double_t fLegendX1; // default position
147  Double_t fLegendY1; // ...of TLegends
148  Double_t fLegendX2; // ... in x
149  Double_t fLegendY2; // .. and y
150  Double_t fStatsX1; // default positions in x and y
151  Double_t fStatsX2; // ...of first statsbox in case
152  Double_t fStatsY1; // ... many have to be drawn
153  Double_t fStatsY2; // ... (subsequent boxes are shifted)
154  TString fCanvasName;
155  Int_t fCanvasWidth; // pixel width
156  Int_t fCanvasHeight; // height of canvases (maybe relativly manipulated...)
157  static TString fgLegendEntryOption; // option used for legend entry style
158  TObjArray* fHistArrays; // array of arrays of arrays of histograms
159  TObjArray* fLegendArrays; // array of arrays to hold potential TLegend's
160  TObjArray* fObjLists; // array of array of lists to hold potential objects
161  TObjArray* fCanArrays; // array of arrays to hold canvases for drawing
162  Bool_t fBatch; // if true: ignore Draw()
163  Bool_t fDrawDiffStyle; // if true(default): call MakeDifferentStyle while Draw
164  Bool_t fSameWithStats; // if true(non-default): use SAMES option to add all stats boxes
165 
166  ClassDef(GFHistManager, 0) // Gero's histogram manager (not writable!)
167 };
168 
169 #endif
void Clear(Option_t *="")
Definition: GFHistManager.h:52
virtual void Print(const char *filename, Bool_t add=kFALSE)
virtual void SetLogY(Bool_t yesNo=kTRUE)
virtual void AddHists(TCollection *hists, Int_t layer=0, const char *legendTitle=NULL, const char *legOpt=NULL)
virtual Bool_t RemoveLegend(Int_t layer, Int_t nPad)
virtual TList * GetObjectsOf(Int_t layer, Int_t histNum)
Bool_t fDrawDiffStyle
Bool_t SameWithStats(Bool_t yesNo)
static void MakeDifferentStyle(GFHistArray *hists)
virtual TLegendEntry * AddHistSame(TH1 *hist, Int_t layer, Int_t nPad, const char *legendTitle=NULL, const char *legOpt=NULL)
T w() const
virtual void Initialise()
TObjArray * fLegendArrays
static const Int_t kDefaultPadsPerCanX
static TString fgLegendEntryOption
virtual Double_t MaxOfHists(const TObjArray *hists) const
virtual TList * MakeObjList(Int_t layer, Int_t histoNum)
Bool_t DrawDiffStyle(Bool_t yesNo)
virtual void Overlay(GFHistManager *other, Int_t otherLayer, Int_t myLayer, const char *legendTitle)
void SetCanvasName(const TString &name)
virtual TLegend * AddLegend(Int_t layer, Int_t nPad, const char *header=NULL, Bool_t referAll=kTRUE)
virtual void SetHistsMinMax(Double_t minMax, Bool_t min)
#define NULL
Definition: scimark2.h:8
virtual void SetHistsLineStyle(Int_t style)
virtual void DrawLegend(Int_t layer, Int_t histNo)
virtual Bool_t IsBatch() const
Definition: GFHistManager.h:95
virtual Bool_t CheckDepth(const char *method, Int_t layer, Bool_t mayExpand=kTRUE)
virtual void SetLegendX2(Double_t x2)
TObjArray * fObjLists
virtual TVirtualPad * GetPad(Int_t layer, Int_t histNum)
void ColourStatsBoxes(GFHistArray *hists) const
TObjArray * fHistArrays
static Int_t NumberOfSubPadsOf(TCanvas *can)
virtual void SetHistsFillColor(Color_t color)
static void SetLegendEntryOption(const char *option)
Definition: GFHistManager.h:75
TObjArray * fCanArrays
Double_t fLegendX2
virtual void SetHistsLineWidth(Width_t width)
virtual void SetLegendY1(Double_t y1)
constexpr std::array< uint8_t, layerIndexSize > layer
virtual TLegend * GetLegendOf(Int_t layer, Int_t nPad)
void DrawFuncs(const TH1 *hist) const
virtual Int_t GetNumHistsX(Int_t layer) const
virtual Int_t GetNumHistsY(Int_t layer) const
Int_t GetNumLayers() const
virtual void DrawObjects(Int_t layer, Int_t histNo)
virtual void ExpandTo(Int_t newDepth)
virtual void SetLegendX1(Double_t x1)
virtual void GetLegendX1Y1X2Y2(Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2) const
virtual void Clear(Bool_t deleteHists)
TString fCanvasName
virtual void SetNumHistsX(UInt_t numX)
Definition: style.py:1
static const Int_t kDefaultDepth
virtual Double_t MaxOfHist(const TH1 *h) const
virtual void WriteCanvases(TFile *file)
virtual void SetHistsXTitle(const char *title)
Bool_t fSameWithStats
Double_t fLegendY1
virtual void Update()
virtual void AddLayer(GFHistManager *other, Int_t layer)
static const Int_t kDefaultPadsPerCanY
virtual void WriteHistos(TFile *file)
virtual void SetCanvasHeight(Int_t h)
Definition: GFHistManager.h:70
virtual Double_t MinOfHists(const TObjArray *hists) const
virtual void SetStatsX1Y1X2Y2(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
virtual void SetHistsLineColor(Color_t color)
__shared__ Hist hist
virtual Int_t GetNumHistsOf(Int_t layer)
virtual void SetLegendX1Y1X2Y2(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
virtual Double_t MinOfHist(const TH1 *h) const
Double_t fLegendY2
virtual void MakeCanvases(Int_t layer)
virtual void DrawReally(Int_t layer)
virtual void SetHistsYTitle(const char *title)
virtual ~GFHistManager()
Double_t fStatsX1
Double_t fStatsY2
virtual void SetLegendY2(Double_t y2)
virtual void AddHistsSame(GFHistArray *hists, Int_t layer, const char *legendTitle=NULL, const char *legOpt=NULL)
virtual Bool_t CheckHistNum(const char *method, Int_t layer, Int_t histNum, Bool_t mayExpand=kFALSE)
virtual TLegendEntry * AddHist(TH1 *hist, Int_t layer=0, const char *legendTitle=NULL, const char *legOpt=NULL)
virtual void Draw(Option_t *opt="")
virtual void SetHistsOption(Option_t *option)
virtual void AddHistsOption(Option_t *option)
Double_t fLegendX1
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
virtual TCanvas * GetCanvas(Int_t layer, Int_t number=0)
Double_t fStatsX2
virtual Bool_t SetBatch(Bool_t set=kTRUE)
Definition: GFHistManager.h:94
virtual void AddLayers(GFHistManager *other)
virtual void SetCanvasWidth(Int_t w)
Definition: GFHistManager.h:69
virtual void SetNumHistsY(UInt_t numY)
virtual Int_t GetCanvasHeight() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual void SetNumHistsXY(UInt_t numX, UInt_t numY)
void Delete(Option_t *="")
Definition: GFHistManager.h:53
Double_t fStatsY1
virtual TObjArray * MakeLegends(Int_t layer)
void ColourFuncs(GFHistArray *hists) const
virtual Int_t GetCanvasWidth() const
virtual void AddObject(TObject *obj, Int_t layer, Int_t histoNum, Option_t *opt=NULL)
virtual GFHistArray * GetHistsOf(Int_t layer, Int_t histNum, Bool_t mayExpand=kFALSE)