Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooPlot.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooPlot.h,v 1.37 2007/06/18 11:52:41 wouter Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_PLOT
0017 #define ROO_PLOT
0018 
0019 #include "RooPrintable.h"
0020 #include "TNamed.h"
0021 
0022 #include <ROOT/RConfig.hxx> // for the R__DEPRECATED macro
0023 
0024 #include <memory>
0025 #include <cfloat>
0026 
0027 class TH1 ;
0028 
0029 class RooAbsReal;
0030 class RooAbsRealLValue;
0031 class RooArgSet ;
0032 class RooHist;
0033 class RooCurve ;
0034 class RooPlotable;
0035 class TDirectory ;
0036 class TAttLine;
0037 class TAttFill;
0038 class TAttMarker;
0039 class TAttText;
0040 class TClass ;
0041 class TAxis;
0042 class TBrowser ;
0043 class TLegend;
0044 
0045 class RooPlot : public TNamed, public RooPrintable {
0046 public:
0047   using Items = std::vector<std::pair<TObject*,std::string>>;
0048 
0049   RooPlot() ;
0050   RooPlot(const char* name, const char* title, const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
0051      R__DEPRECATED(6,36, "Use the constructor that doesn't take the name and title, and then call SetName() and SetTitle() on the RooPlot.");
0052   RooPlot(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins);
0053   RooPlot(double xmin, double xmax, int nBins=100);
0054   RooPlot(double xmin, double xmax, double ymin, double ymax)
0055      R__DEPRECATED(6,36, "Use RooPlot(double xmin, double xmax); SetMinimum(ymin); SetMaximum(ymax);");
0056   RooPlot(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2);
0057   RooPlot(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2,
0058      double xmin, double xmax, double ymin, double ymax);
0059   ~RooPlot() override;
0060 
0061   RooPlot(const RooPlot& other) = delete; // cannot be copied
0062 
0063   static RooPlot* frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins);
0064   static RooPlot* frameWithLabels(const RooAbsRealLValue &var);
0065 
0066   RooPlot* emptyClone(const char* name) ;
0067 
0068   // implement the TH1 interface
0069   void Draw(Option_t *options= nullptr) override;
0070 
0071   // forwarding of relevant TH1 interface
0072   TAxis* GetXaxis() const ;
0073   TAxis* GetYaxis() const ;
0074   Int_t GetNbinsX() const ;
0075   Int_t GetNdivisions(Option_t* axis = "X") const ;
0076   double GetMinimum(double minval = -FLT_MAX) const ;
0077   double GetMaximum(double maxval = FLT_MAX) const ;
0078 
0079   void SetAxisColor(Color_t color = 1, Option_t* axis = "X") ;
0080   void SetAxisRange(double xmin, double xmax, Option_t* axis = "X") ;
0081   void SetBarOffset(Float_t offset = 0.25) ;
0082   void SetBarWidth(Float_t width = 0.5) ;
0083   void SetContour(Int_t nlevels, const double* levels = nullptr) ;
0084   void SetContourLevel(Int_t level, double value) ;
0085   void SetDrawOption(Option_t* option = "") override ;
0086   void SetFillAttributes() ;
0087   void SetFillColor(Color_t fcolor) ;
0088   void SetFillStyle(Style_t fstyle) ;
0089   void SetLabelColor(Color_t color = 1, Option_t* axis = "X") ;
0090   void SetLabelFont(Style_t font = 62, Option_t* axis = "X") ;
0091   void SetLabelOffset(Float_t offset = 0.005, Option_t* axis = "X") ;
0092   void SetLabelSize(Float_t size = 0.02, Option_t* axis = "X") ;
0093   void SetLineAttributes() ;
0094   void SetLineColor(Color_t lcolor) ;
0095   void SetLineStyle(Style_t lstyle) ;
0096   void SetLineWidth(Width_t lwidth) ;
0097   void SetMarkerAttributes() ;
0098   void SetMarkerColor(Color_t tcolor = 1) ;
0099   void SetMarkerSize(Size_t msize = 1) ;
0100   void SetMarkerStyle(Style_t mstyle = 1) ;
0101   void SetName(const char *name) override ;
0102   void SetTitle(const char *name) override ;
0103   void SetNameTitle(const char *name, const char* title) override ;
0104   void SetNdivisions(Int_t n = 510, Option_t* axis = "X") ;
0105   void SetOption(Option_t* option = " ") ;
0106   void SetStats(bool stats = true) ;
0107   void SetTickLength(Float_t length = 0.02, Option_t* axis = "X") ;
0108   void SetTitleFont(Style_t font = 62, Option_t* axis = "X") ;
0109   void SetTitleOffset(Float_t offset = 1, Option_t* axis = "X") ;
0110   void SetTitleSize(Float_t size = 0.02, Option_t* axis = "X") ;
0111   void SetXTitle(const char* title) ;
0112   void SetYTitle(const char* title) ;
0113   void SetZTitle(const char* title) ;
0114 
0115   // container management
0116   const char* nameOf(Int_t idx) const ;
0117   TObject *findObject(const char *name, const TClass* tClass=nullptr) const;
0118   TObject* getObject(Int_t idx) const ;
0119   Stat_t numItems() const {return _items.size();}
0120 
0121   void addPlotable(RooPlotable *plotable, Option_t *drawOptions= "", bool invisible=false, bool refreshNorm=false);
0122   void addObject(TObject* obj, Option_t* drawOptions= "", bool invisible=false);
0123   void addTH1(TH1 *hist, Option_t* drawOptions= "", bool invisible=false);
0124   std::unique_ptr<TLegend> BuildLegend() const;
0125 
0126   void remove(const char* name=nullptr, bool deleteToo=true) ;
0127 
0128   // ascii printing
0129   void printName(std::ostream& os) const override ;
0130   void printTitle(std::ostream& os) const override ;
0131   void printClassName(std::ostream& os) const override ;
0132   void printArgs(std::ostream& os) const override ;
0133   void printValue(std::ostream& os) const override ;
0134   void printMultiline(std::ostream& os, Int_t content, bool verbose=false, TString indent="") const override ;
0135 
0136   Int_t defaultPrintContents(Option_t* opt) const override ;
0137 
0138   inline void Print(Option_t *options= nullptr) const override {
0139     printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
0140   }
0141 
0142   // data member get/set methods
0143   inline RooAbsRealLValue *getPlotVar() const { return _plotVar; }
0144   ///Return the number of events in the fit range
0145   inline double getFitRangeNEvt() const { return _normNumEvts; }
0146   double getFitRangeNEvt(double xlo, double xhi) const ;
0147   ///Return the bin width that is being used to normalise the PDF
0148   inline double getFitRangeBinW() const { return _normBinWidth; }
0149   inline double getPadFactor() const { return _padFactor; }
0150   inline void setPadFactor(double factor) { if(factor >= 0) _padFactor= factor; }
0151   void updateNormVars(const RooArgSet &vars);
0152   const RooArgSet *getNormVars() const { return _normVars; }
0153 
0154   // get attributes of contained objects
0155   TAttLine *getAttLine(const char *name=nullptr) const;
0156   TAttFill *getAttFill(const char *name=nullptr) const;
0157   TAttMarker *getAttMarker(const char *name=nullptr) const;
0158   TAttText *getAttText(const char *name=nullptr) const;
0159 
0160   // Convenient type-safe accessors
0161   RooCurve* getCurve(const char* name=nullptr) const ;
0162   RooHist* getHist(const char* name=nullptr) const ;
0163 
0164 
0165   // rearrange drawing order of contained objects
0166   bool drawBefore(const char *before, const char *target);
0167   bool drawAfter(const char *after, const char *target);
0168 
0169   // get/set drawing options for contained objects
0170   TString getDrawOptions(const char *name) const;
0171   bool setDrawOptions(const char *name, TString options);
0172 
0173   bool getInvisible(const char* name) const ;
0174   void setInvisible(const char* name, bool flag=true) ;
0175 
0176   virtual void SetMaximum(double maximum = -1111) ;
0177   virtual void SetMinimum(double minimum = -1111) ;
0178 
0179   ///Shortcut for RooPlot::chiSquare(const char* pdfname, const char* histname, int nFitParam=nullptr)
0180   double chiSquare(int nFitParam=0) const { return chiSquare(nullptr,nullptr,nFitParam) ; }
0181   double chiSquare(const char* pdfname, const char* histname, int nFitParam=0) const ;
0182 
0183   RooHist* residHist(const char* histname=nullptr, const char* pdfname=nullptr,bool normalize=false, bool useAverage=true) const ;
0184   ///Uses residHist() and sets normalize=true
0185   RooHist* pullHist(const char* histname=nullptr, const char* pdfname=nullptr, bool useAverage=true) const
0186     { return residHist(histname,pdfname,true,useAverage); }
0187 
0188   void Browse(TBrowser *b) override ;
0189 
0190   /// \copydoc AddDirectoryStatus()
0191   static bool addDirectoryStatus() ;
0192   /// \copydoc AddDirectory()
0193   static bool setAddDirectoryStatus(bool flag) ;
0194 
0195   /// Configure whether new instances of RooPlot will add themselves to `gDirectory`.
0196   /// Like TH1::AddDirectory().
0197   static void AddDirectory(bool add=true) {
0198     setAddDirectoryStatus(add);
0199   }
0200   /// Query whether new instances of RooPlot will add themselves to `gDirectory`.
0201   /// When a file has been opened before a RooPlot instance is created,
0202   /// this instance will be associated to the file. Closing the file will e.g.
0203   /// write the instance to the file, and then delete it.
0204   /// Like TH1::AddDirectoryStatus().
0205   static bool AddDirectoryStatus() {
0206     return addDirectoryStatus();
0207   }
0208 
0209   void SetDirectory(TDirectory *dir);
0210 
0211   static void fillItemsFromTList(Items & items, TList const& tlist);
0212 
0213   void createInternalPlotVarClone();
0214 
0215 protected:
0216 
0217   class DrawOpt {
0218     public:
0219 
0220     DrawOpt(const char* _rawOpt=nullptr) : invisible(false) { drawOptions[0] = 0 ; initialize(_rawOpt) ; }
0221     void initialize(const char* _rawOpt) ;
0222     const char* rawOpt() const ;
0223 
0224     char drawOptions[128] ;
0225     bool invisible ;
0226   } ;
0227 
0228 
0229   void initialize();
0230   TString histName() const ;
0231   Items::iterator findItem(std::string const& name);
0232   Items::const_iterator findItem(std::string const& name) const;
0233 
0234   void updateYAxis(double ymin, double ymax, const char *label= "");
0235   void updateFitRangeNorm(const TH1* hist);
0236   void updateFitRangeNorm(const RooPlotable* rp, bool refreshNorm=false);
0237 
0238   TH1* _hist = nullptr;      ///< Histogram that we uses as basis for drawing the content
0239   Items _items;  ///< A list of the items we contain.
0240   double _padFactor;       ///< Scale our y-axis to _padFactor of our maximum contents.
0241   RooAbsRealLValue *_plotVar = nullptr; ///< The variable we are plotting.
0242   RooArgSet *_plotVarSet = nullptr; ///< A list owning the cloned tree nodes of the plotVarClone
0243   RooArgSet *_normVars = nullptr; ///< Variables that PDF plots should be normalized over
0244 
0245   const RooPlotable* _normObj = nullptr; ///<! Pointer to normalization object ;
0246   double _normNumEvts = 0;     ///< Number of events in histogram (for normalization)
0247   double _normBinWidth = 0;    ///< Histogram bin width (for normalization)
0248 
0249   double _defYmin = 1e-5; ///< Default minimum for Yaxis (as calculated from contents)
0250   double _defYmax = 1.0;  ///< Default maximum for Yaxis (as calculated from contents)
0251 
0252   TDirectory* _dir = nullptr; ///<! non-persistent
0253 
0254   static bool _addDirStatus ; ///< static flag controlling AutoDirectoryAdd feature
0255 
0256   ClassDefOverride(RooPlot,3)        // Plot frame and container for graphics objects
0257 };
0258 
0259 #endif