File indexing completed on 2025-09-15 09:12:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROO_PLOT
0017 #define ROO_PLOT
0018
0019 #include "RooPrintable.h"
0020 #include "TNamed.h"
0021
0022 #include <memory>
0023 #include <cfloat>
0024
0025 class TH1 ;
0026
0027 class RooAbsReal;
0028 class RooAbsRealLValue;
0029 class RooArgSet ;
0030 class RooHist;
0031 class RooCurve ;
0032 class RooPlotable;
0033 class TDirectory ;
0034 class TAttLine;
0035 class TAttFill;
0036 class TAttMarker;
0037 class TAttText;
0038 class TClass ;
0039 class TAxis;
0040 class TBrowser ;
0041 class TLegend;
0042
0043 class RooPlot : public TNamed, public RooPrintable {
0044 public:
0045 using Items = std::vector<std::pair<TObject*,std::string>>;
0046
0047 RooPlot() ;
0048 RooPlot(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins);
0049 RooPlot(double xmin, double xmax, int nBins=100);
0050 RooPlot(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2);
0051 RooPlot(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2,
0052 double xmin, double xmax, double ymin, double ymax);
0053 ~RooPlot() override;
0054
0055 RooPlot(const RooPlot& other) = delete;
0056
0057 static RooPlot* frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins);
0058 static RooPlot* frameWithLabels(const RooAbsRealLValue &var);
0059
0060 RooPlot* emptyClone(const char* name) ;
0061
0062
0063 void Draw(Option_t *options= nullptr) override;
0064
0065
0066 TAxis* GetXaxis() const ;
0067 TAxis* GetYaxis() const ;
0068 Int_t GetNbinsX() const ;
0069 Int_t GetNdivisions(Option_t* axis = "X") const ;
0070 double GetMinimum(double minval = -FLT_MAX) const ;
0071 double GetMaximum(double maxval = FLT_MAX) const ;
0072
0073 void SetAxisColor(Color_t color = 1, Option_t* axis = "X") ;
0074 void SetAxisRange(double xmin, double xmax, Option_t* axis = "X") ;
0075 void SetBarOffset(Float_t offset = 0.25) ;
0076 void SetBarWidth(Float_t width = 0.5) ;
0077 void SetContour(Int_t nlevels, const double* levels = nullptr) ;
0078 void SetContourLevel(Int_t level, double value) ;
0079 void SetDrawOption(Option_t* option = "") override ;
0080 void SetFillAttributes() ;
0081 void SetFillColor(Color_t fcolor) ;
0082 void SetFillStyle(Style_t fstyle) ;
0083 void SetLabelColor(Color_t color = 1, Option_t* axis = "X") ;
0084 void SetLabelFont(Style_t font = 62, Option_t* axis = "X") ;
0085 void SetLabelOffset(Float_t offset = 0.005, Option_t* axis = "X") ;
0086 void SetLabelSize(Float_t size = 0.02, Option_t* axis = "X") ;
0087 void SetLineAttributes() ;
0088 void SetLineColor(Color_t lcolor) ;
0089 void SetLineStyle(Style_t lstyle) ;
0090 void SetLineWidth(Width_t lwidth) ;
0091 void SetMarkerAttributes() ;
0092 void SetMarkerColor(Color_t tcolor = 1) ;
0093 void SetMarkerSize(Size_t msize = 1) ;
0094 void SetMarkerStyle(Style_t mstyle = 1) ;
0095 void SetName(const char *name) override ;
0096 void SetTitle(const char *name) override ;
0097 void SetNameTitle(const char *name, const char* title) override ;
0098 void SetNdivisions(Int_t n = 510, Option_t* axis = "X") ;
0099 void SetOption(Option_t* option = " ") ;
0100 void SetStats(bool stats = true) ;
0101 void SetTickLength(Float_t length = 0.02, Option_t* axis = "X") ;
0102 void SetTitleFont(Style_t font = 62, Option_t* axis = "X") ;
0103 void SetTitleOffset(Float_t offset = 1, Option_t* axis = "X") ;
0104 void SetTitleSize(Float_t size = 0.02, Option_t* axis = "X") ;
0105 void SetXTitle(const char* title) ;
0106 void SetYTitle(const char* title) ;
0107 void SetZTitle(const char* title) ;
0108
0109
0110 const char* nameOf(Int_t idx) const ;
0111 TObject *findObject(const char *name, const TClass* tClass=nullptr) const;
0112 TObject* getObject(Int_t idx) const ;
0113 Stat_t numItems() const {return _items.size();}
0114
0115 void addPlotable(RooPlotable *plotable, Option_t *drawOptions= "", bool invisible=false, bool refreshNorm=false);
0116 void addObject(TObject* obj, Option_t* drawOptions= "", bool invisible=false);
0117 void addTH1(TH1 *hist, Option_t* drawOptions= "", bool invisible=false);
0118 std::unique_ptr<TLegend> BuildLegend() const;
0119
0120 void remove(const char* name=nullptr, bool deleteToo=true) ;
0121
0122
0123 void printName(std::ostream& os) const override ;
0124 void printTitle(std::ostream& os) const override ;
0125 void printClassName(std::ostream& os) const override ;
0126 void printArgs(std::ostream& os) const override ;
0127 void printValue(std::ostream& os) const override ;
0128 void printMultiline(std::ostream& os, Int_t content, bool verbose=false, TString indent="") const override ;
0129
0130 Int_t defaultPrintContents(Option_t* opt) const override ;
0131
0132 inline void Print(Option_t *options= nullptr) const override {
0133 printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
0134 }
0135
0136
0137 inline RooAbsRealLValue *getPlotVar() const { return _plotVar; }
0138
0139 inline double getFitRangeNEvt() const { return _normNumEvts; }
0140 double getFitRangeNEvt(double xlo, double xhi) const ;
0141
0142 inline double getFitRangeBinW() const { return _normBinWidth; }
0143 inline double getPadFactor() const { return _padFactor; }
0144 inline void setPadFactor(double factor) { if(factor >= 0) _padFactor= factor; }
0145 void updateNormVars(const RooArgSet &vars);
0146 const RooArgSet *getNormVars() const { return _normVars; }
0147
0148
0149 TAttLine *getAttLine(const char *name=nullptr) const;
0150 TAttFill *getAttFill(const char *name=nullptr) const;
0151 TAttMarker *getAttMarker(const char *name=nullptr) const;
0152 TAttText *getAttText(const char *name=nullptr) const;
0153
0154
0155 RooCurve* getCurve(const char* name=nullptr) const ;
0156 RooHist* getHist(const char* name=nullptr) const ;
0157
0158
0159
0160 bool drawBefore(const char *before, const char *target);
0161 bool drawAfter(const char *after, const char *target);
0162
0163
0164 TString getDrawOptions(const char *name) const;
0165 bool setDrawOptions(const char *name, TString options);
0166
0167 bool getInvisible(const char* name) const ;
0168 void setInvisible(const char* name, bool flag=true) ;
0169
0170 virtual void SetMaximum(double maximum = -1111) ;
0171 virtual void SetMinimum(double minimum = -1111) ;
0172
0173
0174 double chiSquare(int nFitParam=0) const { return chiSquare(nullptr,nullptr,nFitParam) ; }
0175 double chiSquare(const char* pdfname, const char* histname, int nFitParam=0) const ;
0176
0177 RooHist* residHist(const char* histname=nullptr, const char* pdfname=nullptr,bool normalize=false, bool useAverage=true) const ;
0178
0179 RooHist* pullHist(const char* histname=nullptr, const char* pdfname=nullptr, bool useAverage=true) const
0180 { return residHist(histname,pdfname,true,useAverage); }
0181
0182 void Browse(TBrowser *b) override ;
0183
0184
0185 static bool addDirectoryStatus() ;
0186
0187 static bool setAddDirectoryStatus(bool flag) ;
0188
0189
0190
0191 static void AddDirectory(bool add=true) {
0192 setAddDirectoryStatus(add);
0193 }
0194
0195
0196
0197
0198
0199 static bool AddDirectoryStatus() {
0200 return addDirectoryStatus();
0201 }
0202
0203 void SetDirectory(TDirectory *dir);
0204
0205 static void fillItemsFromTList(Items & items, TList const& tlist);
0206
0207 void createInternalPlotVarClone();
0208
0209 protected:
0210
0211 class DrawOpt {
0212 public:
0213
0214 DrawOpt(const char* _rawOpt=nullptr) : invisible(false) { drawOptions[0] = 0 ; initialize(_rawOpt) ; }
0215 void initialize(const char* _rawOpt) ;
0216 const char* rawOpt() const ;
0217
0218 char drawOptions[128] ;
0219 bool invisible ;
0220 } ;
0221
0222
0223 void initialize();
0224 TString histName() const ;
0225 Items::iterator findItem(std::string const& name);
0226 Items::const_iterator findItem(std::string const& name) const;
0227
0228 void updateYAxis(double ymin, double ymax, const char *label= "");
0229 void updateFitRangeNorm(const TH1* hist);
0230 void updateFitRangeNorm(const RooPlotable* rp, bool refreshNorm=false);
0231
0232 TH1* _hist = nullptr;
0233 Items _items;
0234 double _padFactor;
0235 RooAbsRealLValue *_plotVar = nullptr;
0236 RooArgSet *_plotVarSet = nullptr;
0237 RooArgSet *_normVars = nullptr;
0238
0239 const RooPlotable* _normObj = nullptr;
0240 double _normNumEvts = 0;
0241 double _normBinWidth = 0;
0242
0243 double _defYmin = 1e-5;
0244 double _defYmax = 1.0;
0245
0246 TDirectory* _dir = nullptr;
0247
0248 static bool _addDirStatus ;
0249
0250 ClassDefOverride(RooPlot,3)
0251 };
0252
0253 #endif