eicplot  trunk
EIC ROOT plotting utilities
/Users/thomasburton/Documents/projects/eic/Utilities/eicplot/trunk/include/eicplot/MultiPanelPlot.h
00001 
00009 #ifndef _EICPLOT_MULTIPANELPLOT_H_
00010 #define _EICPLOT_MULTIPANELPLOT_H_
00011 
00012 #include <list>
00013 #include <string>
00014 
00015 #include <TH1D.h>
00016 #include <TPad.h>
00017 
00018 class TGaxis;
00019 class TH1;
00020 class TString;
00021 class TVirtualPad;
00022 
00023 namespace erhic {
00024    
00038    class MultiPanelPlot : public TPad {
00039    public:
00040       
00046       MultiPanelPlot(Int_t nColumns = 1, Int_t nRows = 1,
00047                      Color_t colour = kWhite);
00048       
00050       virtual ~MultiPanelPlot();
00051       
00053       virtual void SetLogx(Int_t);
00054 
00056       virtual void SetLogy(Int_t);
00057 
00059       virtual void SetLogz(Int_t);
00060 
00062       virtual Int_t GetLogx() const;
00063 
00065       virtual Int_t GetLogy() const;
00066 
00068       virtual Int_t GetLogz() const;
00069       
00074       virtual void Divide(Int_t nColumns = 1, Int_t nRows = 1,
00075                           Float_t = 0.f, Float_t = 0.f, Int_t color = 0);
00076       
00081       virtual void SetLeftMargin(Float_t);
00082       
00087       virtual void SetRightMargin(Float_t);
00088       
00093       virtual void SetBottomMargin(Float_t);
00094       
00099       virtual void SetTopMargin(Float_t);
00100       
00107       virtual void Draw(Option_t* = "");
00108       
00113       virtual TVirtualPad*      cd(Int_t panel = 0);
00114       
00121       virtual TVirtualPad*      GetPad(Int_t panel) const;
00122       
00127       virtual void Clear(Option_t* = "");
00128       
00132       virtual void Modified(Bool_t flag = 1);
00133       
00135       virtual Int_t GetNPanels() const;
00136       
00138       virtual Int_t GetNColumns() const;
00139       
00141       virtual Int_t GetNRows() const;
00142       
00144       virtual void ApplyAxes(const std::string&);
00145       
00150       virtual bool IsInLeftColumn(Int_t subpadnumber) const;
00151       
00156       virtual bool IsInBottomRow(Int_t subpadnumber) const;
00157       
00162       virtual bool IsInRightColumn(Int_t subpadnumber) const;
00163       
00168       virtual bool IsInTopRow(Int_t subpadnumber) const;
00169       
00170       /* for debuggin */
00171       static void test(const TString& epsName, int rows, int columns);
00172 
00177       bool IsSelf(const TVirtualPad*) const;
00178 
00179    protected:
00180 
00185       unsigned ClearAxes();
00186       
00191       TPad& GetSubPad();
00192       
00196       virtual void PositionSubPad();
00197       
00202       void ConstructXAxis(int padNumber, TH1* histogram);
00203       
00208       void ConstructYAxis(int padNumber, TH1* histogram);
00209       
00214       virtual double GetDrawableX();
00215       
00220       virtual double GetDrawableY();
00221       
00226       virtual TH1* FindHistogram(TVirtualPad*);
00227 
00231       void ApplyMarginForColourPalette(TVirtualPad*, TH1*);
00232       
00233       Int_t mNX; 
00234       Int_t mNY; 
00235       Int_t mLogx; 
00236       Int_t mLogy; 
00237       Int_t mLogz; 
00238       
00239       // The MultiPanelPlot itself contains a sub-pad, onto which the
00240       // histograms are drawn. It is this sub-pad which is divided into
00241       // individual panels for each histogram.
00242       // The only things drawn onto the MultiPanelPlot itself are
00243       //  - the sub-pad
00244       //  - copies of TGaxis objects in the margins at the left and bottom
00245       //    between the edge of the main pad and the sub-pad.
00246       TPad* mSubPad;
00247       
00248       std::list<TGaxis*> mAxes; 
00249       
00250       double mLabelSize;
00251       
00252       ClassDef(MultiPanelPlot, 1)
00253    };
00254    
00255    inline Int_t MultiPanelPlot::GetLogx() const {
00256       return mLogx;
00257    }
00258    
00259    inline Int_t MultiPanelPlot::GetLogy() const {
00260       return mLogy;
00261    }
00262    
00263    inline Int_t MultiPanelPlot::GetLogz() const {
00264       return mLogz;
00265    }
00266    
00267    inline Int_t MultiPanelPlot::GetNPanels() const {
00268       return GetNColumns() * GetNRows();
00269    }
00270    
00271    inline Int_t MultiPanelPlot::GetNColumns() const {
00272       return mNX;
00273    }
00274    
00275    inline Int_t MultiPanelPlot::GetNRows() const {
00276       return mNY;
00277    }
00278    
00279    inline void MultiPanelPlot::Modified(Bool_t flag) {
00280       GetSubPad().Modified(flag);
00281       TPad::Modified(flag);
00282    }
00283    
00284    inline double MultiPanelPlot::GetDrawableX() {
00285       return 1. - GetRightMargin() - GetLeftMargin();
00286    }
00287    
00288    inline double MultiPanelPlot::GetDrawableY() {
00289       return 1. - GetTopMargin() - GetBottomMargin();
00290    }
00291 } // namespace erhic
00292 
00293 #endif