CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Alignment/MillePedeAlignmentAlgorithm/macros/GFUtils/GFHistManager.h

Go to the documentation of this file.
00001 #ifndef __GFHISTMANAGER_H
00002 #define __GFHISTMANAGER_H
00003 
00004  // ROOT includes
00005 #include <TObject.h>
00006 #include <TArrayI.h>
00007 #include <TArrayC.h>
00008 #include <TH1.h> // for type Color_t etc.
00009 
00010 class TObjArray;
00011 class TCollection;
00012 // class TH1;
00013 class TCanvas;
00014 class TVirtualPad;
00015 class TFile; 
00016 class TLegend; 
00017 class TLegendEntry; 
00018 class GFHistArray;
00019 
00020 class GFHistManager : public TObject{
00021 public:
00022   GFHistManager();
00023   explicit GFHistManager(TH1* hist); 
00024   explicit GFHistManager(TCollection* hists); 
00025   virtual ~GFHistManager(); 
00026   
00027   virtual TLegendEntry* AddHist(TH1* hist, Int_t layer = 0, const char* legendTitle = NULL,
00028                                 const char* legOpt = NULL);
00029   virtual void AddHists(TCollection* hists, Int_t layer = 0,
00030                         const char* legendTitle = NULL, const char* legOpt = NULL);
00031   virtual TLegendEntry* AddHistSame(TH1* hist, Int_t layer, Int_t nPad, 
00032                                     const char* legendTitle=NULL, const char* legOpt=NULL);
00033   virtual void AddHistsSame(GFHistArray* hists, Int_t layer,
00034                             const char* legendTitle = NULL, const char* legOpt = NULL);
00035   virtual void AddHistsSame(GFHistArray* hists, Int_t layer, Int_t nPad);
00036   virtual void AddLayers(GFHistManager* other);
00037   virtual void AddLayer(GFHistManager* other, Int_t layer);
00038   virtual void Overlay(GFHistManager* other, Int_t otherLayer, Int_t myLayer,
00039                        const char* legendTitle);
00040   virtual TLegend* AddLegend(Int_t layer, Int_t nPad, const char* header = NULL, 
00041                              Bool_t referAll = kTRUE);
00042   virtual Bool_t RemoveLegend(Int_t layer, Int_t nPad);
00043   virtual void AddLegend(TLegend* leg, Int_t layer, Int_t nPad);
00044   virtual void AddObject(TObject* obj, Int_t layer, Int_t histoNum, Option_t* opt = NULL);
00045 
00046   virtual void Draw(Option_t * opt = "");
00047   virtual void Draw(Int_t layer);
00048   using TObject::Print;
00049   virtual void Print(const char* filename, Bool_t add = kFALSE);
00050 //   virtual void Print(const char* filename, Int_t layer);
00051   virtual void Clear(Bool_t deleteHists);
00052   void Clear(Option_t * = "") {this->Clear(kFALSE);}
00053   void Delete(Option_t * = "") {this->Clear(kTRUE);}
00054   virtual void SetLegendX1Y1X2Y2(Double_t x1, Double_t y1, Double_t x2, Double_t y2);
00055   virtual void SetLegendX1(Double_t x1);// {fLegendX1 = x1;}
00056   virtual void SetLegendY1(Double_t y1);// {fLegendY1 = y1;}
00057   virtual void SetLegendX2(Double_t x2);// {fLegendX2 = x2;}
00058   virtual void SetLegendY2(Double_t y2);// {fLegendY2 = y2;}
00059   virtual void SetStatsX1Y1X2Y2(Double_t x1, Double_t y1, Double_t x2, Double_t y2);
00060   virtual void SetNumHistsX(UInt_t numX);
00061   virtual void SetNumHistsX(UInt_t numX, Int_t layer);
00062   virtual void SetNumHistsY(UInt_t numY);
00063   virtual void SetNumHistsY(UInt_t numY, Int_t layer);
00064   virtual void SetNumHistsXY(UInt_t numX, UInt_t numY);
00065   virtual void SetNumHistsXY(UInt_t numX, UInt_t numY, Int_t layer);
00066   virtual void SetLogY(Bool_t yesNo = kTRUE);
00067   virtual void SetLogY(Int_t layer, Bool_t yesNo = kTRUE);
00068   virtual void SetCanvasWidth(Int_t w) {fCanvasWidth = w;}
00069   virtual void SetCanvasHeight(Int_t h) {fCanvasHeight = h;}
00070   virtual void SetHistsOption(Option_t* option);
00071   virtual void SetHistsOption(Option_t* option, Int_t layer);
00072   virtual void SetHistsMinMax(Double_t minMax, Bool_t min);
00073   virtual void SetHistsMinMax(Double_t minMax, Bool_t min, Int_t layer);
00074   static void SetLegendEntryOption(const char* option) {fgLegendEntryOption = option;} // some of "lpf"
00075   virtual void AddHistsOption(Option_t* option);
00076   virtual void AddHistsOption(Option_t* option, Int_t layer);
00077   virtual void SetHistsXTitle(const char* title);
00078   virtual void SetHistsXTitle(const char* title, Int_t layer);
00079   virtual void SetHistsYTitle(const char* title);
00080   virtual void SetHistsYTitle(const char* title, Int_t layer);
00081   virtual void SetHistsFillColor(Color_t color);
00082   virtual void SetHistsFillColor(Color_t color, Int_t layer);
00083   virtual void SetHistsLineWidth(Width_t width);
00084   virtual void SetHistsLineWidth(Width_t  width, Int_t layer);
00085   virtual void SetHistsLineStyle(Int_t style);
00086   virtual void SetHistsLineStyle(Int_t style, Int_t layer, Int_t numHistInPad = -1);
00087   virtual void SetHistsLineColor(Color_t color);
00088   virtual void SetHistsLineColor(Color_t color, Int_t layer);
00089   virtual void WriteCanvases(TFile* file);
00090   virtual void WriteHistos(TFile* file);
00091   virtual void Update();
00092   virtual void Update(Int_t layer);
00093   virtual Bool_t SetBatch(Bool_t set = kTRUE) {Bool_t r = fBatch; fBatch = set; return r;}
00094   virtual Bool_t IsBatch() const {return fBatch;}
00095   virtual void ExpandTo(Int_t newDepth);
00096 
00097   virtual GFHistArray* GetHistsOf(Int_t layer, Int_t histNum, Bool_t mayExpand = kFALSE);
00098   virtual TList* GetObjectsOf(Int_t layer, Int_t histNum);
00099   virtual Int_t GetNumHistsOf(Int_t layer);
00100   virtual TLegend* GetLegendOf(Int_t layer, Int_t nPad);
00101   virtual Int_t GetCanvasWidth() const {return fCanvasWidth;}
00102   virtual Int_t GetCanvasHeight() const {return fCanvasHeight;}
00103   virtual Int_t GetNumHistsX(Int_t layer) const;
00104   virtual Int_t GetNumHistsY(Int_t layer) const;
00105   virtual Double_t MaxOfHist(const TH1* h) const;
00106   virtual Double_t MaxOfHists(const TObjArray* hists) const;
00107   virtual Double_t MinOfHists(const TObjArray* hists) const;
00108   virtual TVirtualPad* GetPad(Int_t layer, Int_t histNum);
00109   virtual TCanvas* GetCanvas(Int_t layer, Int_t number = 0);// after draw!!
00110   Int_t GetNumLayers() const {return fDepth;}
00111   virtual void GetLegendX1Y1X2Y2(Double_t& x1, Double_t& y1, Double_t& x2, Double_t& y2) const;
00112 
00113   static const Int_t kDefaultPadsPerCanX;// = 2; Doesn't work! Why ???
00114   static const Int_t kDefaultPadsPerCanY;// = 2; It should. And it DOES, if we make
00115   static const Int_t kDefaultDepth;// = 1;        these static const datamembers protected!
00116 
00117   static  Int_t NumberOfSubPadsOf(TCanvas* can);
00118   static void MakeDifferentStyle(GFHistArray* hists);
00119   Bool_t   DrawDiffStyle(Bool_t yesNo) {
00120     const Bool_t old = fDrawDiffStyle; fDrawDiffStyle = yesNo; return old;}
00121   Bool_t SameWithStats(Bool_t yesNo) {
00122     const Bool_t old = fSameWithStats; fSameWithStats = yesNo; return old;}
00123 
00124 protected:
00125   virtual void DrawReally(Int_t layer);
00126   virtual void DrawLegend(Int_t layer, Int_t histNo);
00127   virtual void DrawObjects(Int_t layer, Int_t histNo);
00128   virtual void MakeCanvases(Int_t layer);
00129   virtual TObjArray* MakeLegends(Int_t layer);
00130   virtual TList* MakeObjList(Int_t layer, Int_t histoNum);
00131   virtual void Initialise();
00132   virtual Bool_t CheckDepth(const char* method, Int_t layer, Bool_t mayExpand = kTRUE);
00133   virtual Bool_t CheckHistNum(const char* method, Int_t layer, Int_t histNum, 
00134                               Bool_t mayExpand = kFALSE);
00135   void DrawFuncs(const TH1* hist) const;
00136   void ColourStatsBoxes(GFHistArray *hists) const;
00137   void ColourFuncs(GFHistArray *hists) const;
00138 
00139 private:
00140   Int_t        fDepth;         // how many layers of histograms in arrays?
00141   TArrayI      fNoX;           // how many hists in x...
00142   TArrayI      fNoY;           // ... and in y in each canvas array
00143   TArrayC      fLogY;          // whether or not a layer should be plotted in log(y)
00144   Double_t     fLegendX1;      // default position
00145   Double_t     fLegendY1;      // ...of TLegends
00146   Double_t     fLegendX2;      // ... in x
00147   Double_t     fLegendY2;      // .. and y
00148   Double_t     fStatsX1;       // default positions in x and y
00149   Double_t     fStatsX2;       // ...of first statsbox in case
00150   Double_t     fStatsY1;       // ... many have to be drawn
00151   Double_t     fStatsY2;       // ... (subsequent boxes are shifted)
00152   Int_t        fCanvasWidth;   // pixel width
00153   Int_t        fCanvasHeight;  //       height of canvases (maybe relativly manipulated...) 
00154   static TString fgLegendEntryOption; // option used for legend entry style
00155   TObjArray*   fHistArrays;    // array of arrays of arrays of histograms
00156   TObjArray*   fLegendArrays;     // array of arrays to hold potential TLegend's
00157   TObjArray*   fObjLists;      // array of array of lists to hold potential objects
00158   TObjArray*   fCanArrays;     // array of arrays to hold canvases for drawing
00159   Bool_t       fBatch;         // if true: ignore Draw()
00160   Bool_t       fDrawDiffStyle; // if true(default): call MakeDifferentStyle while Draw
00161   Bool_t       fSameWithStats;  // if true(non-default): use SAMES option to add all stats boxes
00162 
00163   ClassDef(GFHistManager, 0)   // Gero's histogram manager (not writable!)
00164 };
00165 
00166 #endif