Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:46

0001 // @(#)root/roostats:$Id$
0002 // Authors: Sven Kreiss    June 2010
0003 // Authors: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
0004 /*************************************************************************
0005  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOSTATS_SamplingDistPlot
0013 #define ROOSTATS_SamplingDistPlot
0014 
0015 #include "Compression.h"
0016 #include "RooPrintable.h"
0017 #include "TNamed.h"
0018 #include "TH1F.h"
0019 #include "TF1.h"
0020 #include "TLegend.h"
0021 #include "TList.h"
0022 
0023 #include <limits>
0024 #include <vector>
0025 
0026 #include "RooStats/SamplingDistribution.h"
0027 
0028 #include "RooPlot.h"
0029 
0030 
0031 namespace RooStats {
0032 
0033  class SamplingDistPlot : public TNamed, public RooPrintable {
0034 
0035    public:
0036     /// Constructors for SamplingDistribution
0037     SamplingDistPlot(Int_t nbins = 100);
0038     SamplingDistPlot(Int_t nbins, double min, double max);
0039 
0040     /// Destructor of SamplingDistribution
0041     ~SamplingDistPlot() override;
0042 
0043     /// adds the sampling distribution and returns the scale factor
0044     double AddSamplingDistribution(const SamplingDistribution *samplingDist, Option_t *drawOptions="NORMALIZE HIST");
0045     /// Like AddSamplingDistribution, but also sets a shaded area in the
0046     /// minShaded and maxShaded boundaries.
0047     double AddSamplingDistributionShaded(const SamplingDistribution *samplingDist, double minShaded, double maxShaded, Option_t *drawOptions="NORMALIZE HIST");
0048 
0049     /// add a line
0050     void AddLine(double x1, double y1, double x2, double y2, const char* title = nullptr);
0051     /// add a TH1
0052     void AddTH1(TH1* h, Option_t *drawOptions="");
0053     /// add a TF1
0054     void AddTF1(TF1* f, const char* title = nullptr, Option_t *drawOptions="SAME");
0055     /// set legend
0056     void SetLegend(TLegend* l){ fLegend = l; }
0057 
0058     void Draw(Option_t *options=nullptr) override;
0059 
0060     /// Applies a predefined style if fApplyStyle is true (default).
0061     void ApplyDefaultStyle(void);
0062 
0063     void SetLineColor(Color_t color, const SamplingDistribution *sampleDist = nullptr);
0064     void SetLineWidth(Width_t lwidth, const SamplingDistribution *sampleDist = nullptr);
0065     void SetLineStyle(Style_t style, const SamplingDistribution *sampleDist = nullptr);
0066 
0067     void SetMarkerColor(Color_t color, const SamplingDistribution *sampleDist = nullptr);
0068     void SetMarkerStyle(Style_t style, const SamplingDistribution *sampleDist = nullptr);
0069     void SetMarkerSize(Size_t size, const SamplingDistribution *sampleDist = nullptr);
0070 
0071     void RebinDistribution(Int_t rebinFactor, const SamplingDistribution *sampleDist = nullptr);
0072 
0073     void SetAxisTitle(char *varName) { fVarName = TString(varName); }
0074 
0075     /// If you do not want SamplingDistPlot to interfere with your style settings, call this
0076     /// function with "false" before Draw().
0077     void SetApplyStyle(bool s) { fApplyStyle = s; }
0078 
0079     /// Returns the TH1F associated with the give SamplingDistribution.
0080     /// Intended use: Access to member functions of TH1F like GetMean(),
0081     /// GetRMS() etc.
0082     /// The return objects is managed by  SamplingDistPlot
0083     TH1F* GetTH1F(const SamplingDistribution *sampleDist = nullptr);
0084     TH1 * GetHistogram(const SamplingDistribution *sampleDist = nullptr) { return GetTH1F(sampleDist); }
0085 
0086     /// return plotter class used to draw the sampling distribution histograms
0087     /// object is managed by SamplingDistPlot
0088     RooPlot * GetPlot() { return fRooPlot; }
0089 
0090     /// changes plot to log scale on x axis
0091     void SetLogXaxis(bool lx) { fLogXaxis = lx; }
0092     /// changes plot to log scale on y axis
0093     void SetLogYaxis(bool ly) { fLogYaxis = ly; }
0094 
0095     /// change x range
0096     void SetXRange( double mi, double ma ) { fXMin = mi; fXMax = ma; }
0097     /// change y range
0098     void SetYRange( double mi, double ma ) { fYMin = mi; fYMax = ma; }
0099 
0100     /// write to Root file
0101     void DumpToFile(const char* RootFileName, Option_t *option="", const char *ftitle="", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault);
0102 
0103   private:
0104     std::vector<double> fSamplingDistr;
0105     std::vector<double> fSampleWeights;
0106 
0107     bool fIsWeighted = false;
0108 
0109     Int_t fBins;
0110     Int_t fMarkerType = 20;
0111     Int_t fColor = 1;
0112 
0113     TString fVarName;
0114 
0115   protected:
0116 
0117     TH1F* fHist = nullptr;
0118     TLegend *fLegend = nullptr;
0119 
0120     TList fItems;       ///< holds TH1Fs only
0121     TList fOtherItems;  ///< other objects to be drawn like TLine etc.
0122     RooPlot* fRooPlot = nullptr;
0123     bool fLogXaxis = false;
0124     bool fLogYaxis = false;
0125 
0126     double fXMin = std::numeric_limits<float>::quiet_NaN();
0127     double fXMax = std::numeric_limits<float>::quiet_NaN();
0128     double fYMin = std::numeric_limits<float>::quiet_NaN();
0129     double fYMax = std::numeric_limits<float>::quiet_NaN();
0130 
0131     bool fApplyStyle = true;
0132     Style_t fFillStyle = 3004;
0133 
0134     void SetSampleWeights(const SamplingDistribution *samplingDist);
0135 
0136     void addObject(TObject *obj, Option_t *drawOptions=nullptr); // for TH1Fs only
0137     void addOtherObject(TObject *obj, Option_t *drawOptions=nullptr);
0138     void GetAbsoluteInterval(double &theMin, double &theMax, double &theYMax) const;
0139 
0140     ClassDefOverride(SamplingDistPlot,2)  /// Class containing the results of the HybridCalculator
0141   };
0142 }
0143 
0144 #endif