Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
SamplingDistPlot.h
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Authors: Sven Kreiss June 2010
3 // Authors: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
4 /*************************************************************************
5  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOSTATS_SamplingDistPlot
13 #define ROOSTATS_SamplingDistPlot
14 
15 #include "Compression.h"
16 #include "RooList.h"
17 #include "RooPrintable.h"
18 #include "TNamed.h"
19 #include "TIterator.h"
20 #include "TH1F.h"
21 #include "TF1.h"
22 #include "TLegend.h"
23 
25 
26 #include "RooPlot.h"
27 
28 
29 namespace RooStats {
30 
31  class SamplingDistPlot : public TNamed, public RooPrintable {
32 
33  public:
34  /// Constructors for SamplingDistribution
35  SamplingDistPlot(Int_t nbins = 100);
36  SamplingDistPlot(Int_t nbins, Double_t min, Double_t max);
37 // SamplingDistPlot(const char* name, const char* title, Int_t nbins, Double_t xmin, Double_t xmax);
38 
39  /// Destructor of SamplingDistribution
40  virtual ~SamplingDistPlot();
41 
42  /// adds the sampling distribution and returns the scale factor
43  Double_t AddSamplingDistribution(const SamplingDistribution *samplingDist, Option_t *drawOptions="NORMALIZE HIST");
44  /// Like AddSamplingDistribution, but also sets a shaded area in the
45  /// minShaded and maxShaded boundaries.
46  Double_t AddSamplingDistributionShaded(const SamplingDistribution *samplingDist, Double_t minShaded, Double_t maxShaded, Option_t *drawOptions="NORMALIZE HIST");
47 
48  /// add a line
49  void AddLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2, const char* title = NULL);
50  /// add a TH1
51  void AddTH1(TH1* h, Option_t *drawOptions="");
52  /// add a TF1
53  void AddTF1(TF1* f, const char* title = NULL, Option_t *drawOptions="SAME");
54  /// set legend
55  void SetLegend(TLegend* l){ fLegend = l; }
56 
57  void Draw(Option_t *options=0);
58 
59  /// Applies a predefined style if fApplyStyle is kTRUE (default).
60  void ApplyDefaultStyle(void);
61 
62  void SetLineColor(Color_t color, const SamplingDistribution *samplDist = 0);
63  void SetLineWidth(Width_t lwidth, const SamplingDistribution *samplDist = 0);
64  void SetLineStyle(Style_t style, const SamplingDistribution *samplDist = 0);
65 
66  void SetMarkerColor(Color_t color, const SamplingDistribution *samplDist = 0);
67  void SetMarkerStyle(Style_t style, const SamplingDistribution *samplDist = 0);
68  void SetMarkerSize(Size_t size, const SamplingDistribution *samplDist = 0);
69 
70  void RebinDistribution(Int_t rebinFactor, const SamplingDistribution *samplDist = 0);
71 
72  void SetAxisTitle(char *varName) { fVarName = TString(varName); }
73 
74  /// If you do not want SamplingDistPlot to interfere with your style settings, call this
75  /// function with "false" before Draw().
76  void SetApplyStyle(Bool_t s) { fApplyStyle = s; }
77 
78  /// Returns the TH1F associated with the give SamplingDistribution.
79  /// Intended use: Access to member functions of TH1F like GetMean(),
80  /// GetRMS() etc.
81  /// The return objects is managed by SamplingDistPlot
82  TH1F* GetTH1F(const SamplingDistribution *samplDist = NULL);
83  TH1 * GetHistogram(const SamplingDistribution *samplDist = NULL) { return GetTH1F(samplDist); }
84 
85  /// return plotter class used to draw the sampling distribution histograms
86  /// object is managed by SamplingDistPlot
87  RooPlot * GetPlot() { return fRooPlot; }
88 
89  /// changes plot to log scale on x axis
90  void SetLogXaxis(Bool_t lx) { fLogXaxis = lx; }
91  /// changes plot to log scale on y axis
92  void SetLogYaxis(Bool_t ly) { fLogYaxis = ly; }
93 
94  /// change x range
95  void SetXRange( double mi, double ma ) { fXMin = mi; fXMax = ma; }
96  /// change y range
97  void SetYRange( double mi, double ma ) { fYMin = mi; fYMax = ma; }
98 
99  /// write to Root file
100  void DumpToFile(const char* RootFileName, Option_t *option="", const char *ftitle="", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault);
101 
102  private:
103  std::vector<Double_t> fSamplingDistr;
104  std::vector<Double_t> fSampleWeights;
105 
106  Bool_t fIsWeighted;
107 
108  Int_t fBins;
109  Int_t fMarkerType;
110  Int_t fColor;
111 
112  TString fVarName;
113 
114  protected:
115 
116  TH1F* fHist;
117  TLegend *fLegend;
118 
119  RooList fItems; /// holds TH1Fs only
120  RooList fOtherItems; /// other objects to be drawn like TLine etc.
121  TIterator* fIterator; /// TODO remove class variable and instantiate locally as necessary
122  RooPlot* fRooPlot;
123  Bool_t fLogXaxis;
124  Bool_t fLogYaxis;
125 
126  double fXMin, fXMax, fYMin, fYMax;
127 
128  Bool_t fApplyStyle;
129  Style_t fFillStyle;
130 
131  void SetSampleWeights(const SamplingDistribution *samplingDist);
132 
133  void addObject(TObject *obj, Option_t *drawOptions=0); // for TH1Fs only
134  void addOtherObject(TObject *obj, Option_t *drawOptions=0);
135  void GetAbsoluteInterval(Double_t &theMin, Double_t &theMax, Double_t &theYMax) const;
136 
137  ClassDef(SamplingDistPlot,1) /// Class containing the results of the HybridCalculator
138  };
139 }
140 
141 #endif