Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEfficiency.h
Go to the documentation of this file.
1#ifndef ROOT_TEfficiency
2#define ROOT_TEfficiency
3
4//standard header
5#include <vector>
6#include <utility>
7
8//ROOT header
9#include "TNamed.h"
10
11#include "TAttLine.h"
12
13#include "TAttFill.h"
14
15#include "TAttMarker.h"
16
17#include "TFitResultPtr.h"
18
19
20class TCollection;
21class TF1;
24class TH1;
25class TH2;
26class TList;
27
28class TEfficiency: public TNamed, public TAttLine, public TAttFill, public TAttMarker
29{
30public:
31 /// Enumeration type for different statistic options for calculating confidence intervals
32 /// kF* ... frequentist methods; kB* ... bayesian methods
34 kFCP = 0, ///< Clopper-Pearson interval (recommended by PDG)
35 kFNormal, ///< Normal approximation
36 kFWilson, ///< Wilson interval
37 kFAC, ///< Agresti-Coull interval
38 kFFC, ///< Feldman-Cousins interval
39 kBJeffrey, ///< Jeffrey interval (Prior ~ Beta(0.5,0.5)
40 kBUniform, ///< Prior ~ Uniform = Beta(1,1)
41 kBBayesian, ///< User specified Prior ~ Beta(fBeta_alpha,fBeta_beta)
42 kMidP ///< Mid-P Lancaster interval
43 };
44
45protected:
46
47 Double_t fBeta_alpha; ///< Global parameter for prior beta distribution (default = 1)
48 Double_t fBeta_beta; ///< Global parameter for prior beta distribution (default = 1)
49 std::vector<std::pair<Double_t, Double_t> > fBeta_bin_params; ///< Parameter for prior beta distribution different bin by bin
50 ///< (default vector is empty)
51 Double_t (*fBoundary)(Double_t,Double_t,Double_t,Bool_t); ///<! Pointer to a method calculating the boundaries of confidence intervals
52 Double_t fConfLevel; ///< Confidence level (default = 0.683, 1 sigma)
53 TDirectory* fDirectory; ///<! Pointer to directory holding this TEfficiency object
54 TList* fFunctions; ///<->Pointer to list of functions
55 TGraphAsymmErrors* fPaintGraph=nullptr; ///<! Temporary graph for painting
56 TGraph2DAsymmErrors* fPaintGraph2D=nullptr; ///<! Temporary graph for painting
57 TH2* fPaintHisto=nullptr; ///<! Temporary histogram for painting
58 TH1* fPassedHistogram; ///< Histogram for events which passed certain criteria
59 EStatOption fStatisticOption; ///< Defines how the confidence intervals are determined
60 TH1* fTotalHistogram; ///< Histogram for total number of events
61 Double_t fWeight; ///< Weight for all events (default = 1)
62
64 kIsBayesian = BIT(14), ///< Bayesian statistics are used
65 kPosteriorMode = BIT(15), ///< Use posterior mean for best estimate (Bayesian statistics)
66 kShortestInterval = BIT(16), ///< Use shortest interval
67 kUseBinPrior = BIT(17), ///< Use a different prior for each bin
68 kUseWeights = BIT(18) ///< Use weights
69 };
70
71 void Build(const char* name,const char* title);
72 void FillGraph(TGraphAsymmErrors * graph, Option_t * opt) const;
73 void FillGraph2D(TGraph2DAsymmErrors * graph, Option_t * opt) const;
74 void FillHistogram(TH2 * h2) const;
75
76public:
78 TEfficiency(const TH1& passed,const TH1& total);
79 TEfficiency(const char* name,const char* title,Int_t nbins,
80 const Double_t* xbins);
81 TEfficiency(const char* name,const char* title,Int_t nbins,Double_t xlow,
82 Double_t xup);
83 TEfficiency(const char* name,const char* title,Int_t nbinsx,
84 Double_t xlow,Double_t xup,Int_t nbinsy,Double_t ylow,
85 Double_t yup);
86 TEfficiency(const char* name,const char* title,Int_t nbinsx,
87 const Double_t* xbins,Int_t nbinsy,const Double_t* ybins);
88 TEfficiency(const char* name,const char* title,Int_t nbinsx,
89 Double_t xlow,Double_t xup,Int_t nbinsy,Double_t ylow,
90 Double_t yup,Int_t nbinsz,Double_t zlow,Double_t zup);
91 TEfficiency(const char* name,const char* title,Int_t nbinsx,
92 const Double_t* xbins,Int_t nbinsy,const Double_t* ybins,
93 Int_t nbinsz,const Double_t* zbins);
94 TEfficiency(const TEfficiency& heff);
95 ~TEfficiency() override;
96
97 void Add(const TEfficiency& rEff) {*this += rEff;}
98 void Browse(TBrowser*) override{Draw();}
99 TGraphAsymmErrors* CreateGraph(Option_t * opt = "") const;
100 TGraph2DAsymmErrors* CreateGraph2D(Option_t * opt = "") const;
101 TH2* CreateHistogram(Option_t * opt = "") const;
102 Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
103 void Draw(Option_t* opt = "") override;
104 void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
105 void Fill(Bool_t bPassed,Double_t x,Double_t y=0,Double_t z=0);
106 void FillWeighted(Bool_t bPassed,Double_t weight,Double_t x,Double_t y=0,Double_t z=0);
108 TFitResultPtr Fit(TF1* f1,Option_t* opt="");
109 // use trick of -1 to return global parameters
110 Double_t GetBetaAlpha(Int_t bin = -1) const {return (fBeta_bin_params.size() > (UInt_t)bin) ? fBeta_bin_params[bin].first : fBeta_alpha;}
111 Double_t GetBetaBeta(Int_t bin = -1) const {return (fBeta_bin_params.size() > (UInt_t)bin) ? fBeta_bin_params[bin].second : fBeta_beta;}
113 TH1* GetCopyPassedHisto() const;
114 TH1* GetCopyTotalHisto() const;
115 Int_t GetDimension() const;
117 Double_t GetEfficiency(Int_t bin) const;
120 Int_t GetGlobalBin(Int_t binx,Int_t biny=0,Int_t binz=0) const;
125 const TH1* GetPassedHistogram() const {return fPassedHistogram;}
127 const TH1* GetTotalHistogram() const {return fTotalHistogram;}
128 Double_t GetWeight() const {return fWeight;}
131 TEfficiency& operator=(const TEfficiency& rhs);
132 void Paint(Option_t* opt) override;
133 void SavePrimitive(std::ostream& out,Option_t* opt="") override;
134 void SetBetaAlpha(Double_t alpha);
135 void SetBetaBeta(Double_t beta);
136 void SetBetaBinParameters(Int_t bin, Double_t alpha, Double_t beta);
137 void SetConfidenceLevel(Double_t level);
138 void SetDirectory(TDirectory* dir);
139 void SetName(const char* name) override;
140 Bool_t SetPassedEvents(Int_t bin,Int_t events);
141 Bool_t SetPassedHistogram(const TH1& rPassed,Option_t* opt);
148 Bool_t SetBins(Int_t nx, const Double_t *xBins);
150 Bool_t SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t *yBins);
152 Int_t nz, Double_t zmin, Double_t zmax);
153 Bool_t SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t * yBins, Int_t nz,
154 const Double_t *zBins);
155
156 void SetTitle(const char* title) override;
157 Bool_t SetTotalEvents(Int_t bin, Double_t events);
158 Bool_t SetTotalHistogram(const TH1& rTotal,Option_t* opt);
160 void SetWeight(Double_t weight);
167
168 static Bool_t CheckBinning(const TH1& pass,const TH1& total);
169 static Bool_t CheckConsistency(const TH1& pass,const TH1& total,Option_t* opt="");
170 static Bool_t CheckEntries(const TH1& pass,const TH1& total,Option_t* opt="");
171 static Bool_t CheckWeights(const TH1& pass,const TH1& total);
172 static Double_t Combine(Double_t& up,Double_t& low,Int_t n,const Int_t* pass,const Int_t* total,
173 Double_t alpha,Double_t beta,Double_t level=0.683,
174 const Double_t* w=nullptr,Option_t* opt="");
175 static TGraphAsymmErrors* Combine(TCollection* pList,Option_t* opt="",Int_t n=0,const Double_t* w=nullptr);
176
177 //calculating boundaries of confidence intervals
178 static Double_t AgrestiCoull(Double_t total,Double_t passed,Double_t level,Bool_t bUpper);
179 static Double_t ClopperPearson(Double_t total,Double_t passed,Double_t level,Bool_t bUpper);
180 static Double_t Normal(Double_t total,Double_t passed,Double_t level,Bool_t bUpper);
181 static Double_t Wilson(Double_t total,Double_t passed,Double_t level,Bool_t bUpper);
182 static Double_t FeldmanCousins(Double_t total,Double_t passed,Double_t level,Bool_t bUpper);
183 static Bool_t FeldmanCousinsInterval(Double_t total,Double_t passed,Double_t level,Double_t & lower, Double_t & upper);
184 static Double_t MidPInterval(Double_t total,Double_t passed,Double_t level,Bool_t bUpper);
185 // Bayesian functions
186 static Double_t Bayesian(Double_t total,Double_t passed,Double_t level,Double_t alpha,Double_t beta,Bool_t bUpper, Bool_t bShortest = false);
187 // helper functions for Bayesian statistics
188 static Double_t BetaCentralInterval(Double_t level,Double_t alpha,Double_t beta,Bool_t bUpper);
189 static Bool_t BetaShortestInterval(Double_t level,Double_t alpha,Double_t beta,Double_t & lower, Double_t & upper);
190 static Double_t BetaMean(Double_t alpha,Double_t beta);
191 static Double_t BetaMode(Double_t alpha,Double_t beta);
192
193 ClassDefOverride(TEfficiency,2) //calculating efficiencies
194};
195
196const TEfficiency operator+(const TEfficiency& lhs,const TEfficiency& rhs);
197
198#endif
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:69
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define BIT(n)
Definition Rtypes.h:90
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
const TEfficiency operator+(const TEfficiency &lhs, const TEfficiency &rhs)
Addition operator.
static unsigned int total
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
Fill Area Attributes class.
Definition TAttFill.h:19
Line Attributes class.
Definition TAttLine.h:18
Marker Attributes class.
Definition TAttMarker.h:19
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Collection abstract base class.
Definition TCollection.h:65
Describe directory structure in memory.
Definition TDirectory.h:45
Class to handle efficiency histograms.
Definition TEfficiency.h:29
void FillGraph2D(TGraph2DAsymmErrors *graph, Option_t *opt) const
Fill the graph to be painted with information from TEfficiency Internal method called by TEfficiency:...
Bool_t UsesCentralInterval() const
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
static Bool_t FeldmanCousinsInterval(Double_t total, Double_t passed, Double_t level, Double_t &lower, Double_t &upper)
Calculates the interval boundaries using the frequentist methods of Feldman-Cousins.
void SetPosteriorMode(Bool_t on=true)
static Double_t BetaMode(Double_t alpha, Double_t beta)
Compute the mode of the beta distribution.
Bool_t SetPassedEvents(Int_t bin, Int_t events)
Sets the number of passed events in the given global bin.
TH2 * CreateHistogram(Option_t *opt="") const
Create the histogram used to be painted (for dim=2 TEfficiency) The return object is managed by the c...
static Bool_t BetaShortestInterval(Double_t level, Double_t alpha, Double_t beta, Double_t &lower, Double_t &upper)
Calculates the boundaries for a shortest confidence interval for a Beta distribution.
static Bool_t CheckWeights(const TH1 &pass, const TH1 &total)
Check if both histogram are weighted.
static Double_t BetaMean(Double_t alpha, Double_t beta)
Compute the mean (average) of the beta distribution.
TH2 * GetPaintedHistogram() const
TEfficiency()
Default constructor.
Double_t GetBetaAlpha(Int_t bin=-1) const
void SetPosteriorAverage(Bool_t on=true)
void FillWeighted(Bool_t bPassed, Double_t weight, Double_t x, Double_t y=0, Double_t z=0)
This function is used for filling the two histograms with a weight.
void Browse(TBrowser *) override
Browse object. May be overridden for another default action.
Definition TEfficiency.h:98
~TEfficiency() override
default destructor
TList * GetListOfFunctions()
static Double_t Bayesian(Double_t total, Double_t passed, Double_t level, Double_t alpha, Double_t beta, Bool_t bUpper, Bool_t bShortest=false)
Calculates the boundaries for a Bayesian confidence interval (shortest or central interval depending ...
static Double_t AgrestiCoull(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Agresti-Coull interval.
Long64_t Merge(TCollection *list)
Merges the TEfficiency objects in the given list to the given TEfficiency object using the operator+=...
std::vector< std::pair< Double_t, Double_t > > fBeta_bin_params
Parameter for prior beta distribution different bin by bin (default vector is empty)
Definition TEfficiency.h:49
static Double_t FeldmanCousins(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Feldman-Cousins interval.
EStatOption fStatisticOption
Defines how the confidence intervals are determined.
Definition TEfficiency.h:59
void SetStatisticOption(EStatOption option)
Sets the statistic option which affects the calculation of the confidence interval.
TGraph2DAsymmErrors * GetPaintedGraph2D() const
void Paint(Option_t *opt) override
Paints this TEfficiency object.
void SetWeight(Double_t weight)
Sets the global weight for this TEfficiency object.
TH1 * fTotalHistogram
Histogram for total number of events.
Definition TEfficiency.h:60
Int_t GetDimension() const
returns the dimension of the current TEfficiency object
TGraph2DAsymmErrors * fPaintGraph2D
! Temporary graph for painting
Definition TEfficiency.h:56
TEfficiency & operator+=(const TEfficiency &rhs)
Adds the histograms of another TEfficiency object to current histograms.
Bool_t SetBins(Int_t nx, Double_t xmin, Double_t xmax)
Set the bins for the underlined passed and total histograms If the class have been already filled the...
void Build(const char *name, const char *title)
Building standard data structure of a TEfficiency object.
TH1 * GetCopyPassedHisto() const
Returns a cloned version of fPassedHistogram.
Double_t GetEfficiencyErrorUp(Int_t bin) const
Returns the upper error on the efficiency in the given global bin.
Double_t fBeta_alpha
Global parameter for prior beta distribution (default = 1)
Definition TEfficiency.h:47
Bool_t UsesBayesianStat() const
const TH1 * GetPassedHistogram() const
void SavePrimitive(std::ostream &out, Option_t *opt="") override
Have histograms fixed bins along each axis?
void SetBetaBeta(Double_t beta)
Sets the shape parameter β.
Double_t GetConfidenceLevel() const
static Bool_t CheckBinning(const TH1 &pass, const TH1 &total)
Checks binning for each axis.
void SetName(const char *name) override
Sets the name.
TGraph2DAsymmErrors * CreateGraph2D(Option_t *opt="") const
Create the graph used be painted (for dim=1 TEfficiency) The return object is managed by the caller.
static Double_t BetaCentralInterval(Double_t level, Double_t alpha, Double_t beta, Bool_t bUpper)
Calculates the boundaries for a central confidence interval for a Beta distribution.
Int_t GetGlobalBin(Int_t binx, Int_t biny=0, Int_t binz=0) const
Returns the global bin number which can be used as argument for the following functions:
TH1 * fPassedHistogram
Histogram for events which passed certain criteria.
Definition TEfficiency.h:58
static Double_t MidPInterval(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries using the mid-P binomial interval (Lancaster method) from B.
void SetBetaAlpha(Double_t alpha)
Sets the shape parameter α.
@ kIsBayesian
Bayesian statistics are used.
Definition TEfficiency.h:64
@ kUseWeights
Use weights.
Definition TEfficiency.h:68
@ kPosteriorMode
Use posterior mean for best estimate (Bayesian statistics)
Definition TEfficiency.h:65
@ kUseBinPrior
Use a different prior for each bin.
Definition TEfficiency.h:67
@ kShortestInterval
Use shortest interval.
Definition TEfficiency.h:66
static Bool_t CheckEntries(const TH1 &pass, const TH1 &total, Option_t *opt="")
Checks whether bin contents are compatible with binomial statistics.
static Double_t Normal(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Returns the confidence limits for the efficiency supposing that the efficiency follows a normal distr...
Double_t fWeight
Weight for all events (default = 1)
Definition TEfficiency.h:61
Bool_t SetPassedHistogram(const TH1 &rPassed, Option_t *opt)
Sets the histogram containing the passed events.
Double_t GetBetaBeta(Int_t bin=-1) const
Double_t(* fBoundary)(Double_t, Double_t, Double_t, Bool_t)
! Pointer to a method calculating the boundaries of confidence intervals
Definition TEfficiency.h:51
void FillGraph(TGraphAsymmErrors *graph, Option_t *opt) const
Fill the graph to be painted with information from TEfficiency Internal method called by TEfficiency:...
static Double_t Combine(Double_t &up, Double_t &low, Int_t n, const Int_t *pass, const Int_t *total, Double_t alpha, Double_t beta, Double_t level=0.683, const Double_t *w=nullptr, Option_t *opt="")
Bool_t UsesPosteriorMode() const
void SetShortestInterval(Bool_t on=true)
const TH1 * GetTotalHistogram() const
Bool_t UsesWeights() const
void FillHistogram(TH2 *h2) const
Fill the 2d histogram to be painted with information from TEfficiency 2D Internal method called by TE...
Bool_t UsesPosteriorAverage() const
Int_t FindFixBin(Double_t x, Double_t y=0, Double_t z=0) const
Returns the global bin number containing the given values.
TDirectory * GetDirectory() const
TDirectory * fDirectory
! Pointer to directory holding this TEfficiency object
Definition TEfficiency.h:53
void SetUseWeightedEvents(Bool_t on=kTRUE)
static Double_t Wilson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Wilson interval.
TEfficiency & operator=(const TEfficiency &rhs)
Assignment operator.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a graph.
Double_t fConfLevel
Confidence level (default = 0.683, 1 sigma)
Definition TEfficiency.h:52
void SetCentralInterval(Bool_t on=true)
Double_t fBeta_beta
Global parameter for prior beta distribution (default = 1)
Definition TEfficiency.h:48
Double_t GetEfficiency(Int_t bin) const
Returns the efficiency in the given global bin.
Bool_t SetTotalHistogram(const TH1 &rTotal, Option_t *opt)
Sets the histogram containing all events.
void Fill(Bool_t bPassed, Double_t x, Double_t y=0, Double_t z=0)
This function is used for filling the two histograms.
void SetDirectory(TDirectory *dir)
Sets the directory holding this TEfficiency object.
TGraphAsymmErrors * fPaintGraph
! Temporary graph for painting
Definition TEfficiency.h:55
TGraphAsymmErrors * CreateGraph(Option_t *opt="") const
Create the graph used be painted (for dim=1 TEfficiency) The return object is managed by the caller.
EStatOption GetStatisticOption() const
TGraphAsymmErrors * GetPaintedGraph() const
TList * fFunctions
->Pointer to list of functions
Definition TEfficiency.h:54
Bool_t SetTotalEvents(Int_t bin, Double_t events)
Sets the number of total events in the given global bin.
void SetBetaBinParameters(Int_t bin, Double_t alpha, Double_t beta)
Sets different shape parameter α and β for the prior distribution for each bin.
static Bool_t CheckConsistency(const TH1 &pass, const TH1 &total, Option_t *opt="")
Checks the consistence of the given histograms.
Double_t GetWeight() const
void Add(const TEfficiency &rEff)
Definition TEfficiency.h:97
TH1 * GetCopyTotalHisto() const
Returns a cloned version of fTotalHistogram.
static Double_t ClopperPearson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Calculates the boundaries for the frequentist Clopper-Pearson interval.
void SetConfidenceLevel(Double_t level)
Sets the confidence level (0 < level < 1) The default value is 1-sigma :~ 0.683.
Double_t GetEfficiencyErrorLow(Int_t bin) const
Returns the lower error on the efficiency in the given global bin.
Bool_t UsesShortestInterval() const
EStatOption
Enumeration type for different statistic options for calculating confidence intervals kF* ....
Definition TEfficiency.h:33
@ kBJeffrey
Jeffrey interval (Prior ~ Beta(0.5,0.5)
Definition TEfficiency.h:39
@ kFWilson
Wilson interval.
Definition TEfficiency.h:36
@ kFAC
Agresti-Coull interval.
Definition TEfficiency.h:37
@ kMidP
Mid-P Lancaster interval.
Definition TEfficiency.h:42
@ kBUniform
Prior ~ Uniform = Beta(1,1)
Definition TEfficiency.h:40
@ kFFC
Feldman-Cousins interval.
Definition TEfficiency.h:38
@ kBBayesian
User specified Prior ~ Beta(fBeta_alpha,fBeta_beta)
Definition TEfficiency.h:41
@ kFNormal
Normal approximation.
Definition TEfficiency.h:35
@ kFCP
Clopper-Pearson interval (recommended by PDG)
Definition TEfficiency.h:34
void SetTitle(const char *title) override
Sets the title.
TFitResultPtr Fit(TF1 *f1, Option_t *opt="")
Fits the efficiency using the TBinomialEfficiencyFitter class.
TH2 * fPaintHisto
! Temporary histogram for painting
Definition TEfficiency.h:57
1-Dim function class
Definition TF1.h:233
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Graph 2D class with errors.
TGraph with asymmetric error bars.
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
Service class for 2-D histogram classes.
Definition TH2.h:30
A doubly linked list.
Definition TList.h:38
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:786
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TF1 * f1
Definition legend1.C:11
Definition graph.py:1
th1 Draw()