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);
95 ~TEfficiency() override;
96
97 void Add(const TEfficiency& rEff) {*this += rEff;}
98 void Browse(TBrowser*) override{Draw();}
101 TH2* CreateHistogram(Option_t * opt = "") const;
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);
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;}
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;}
132 void Paint(Option_t* opt) override;
133 void RecursiveRemove(TObject *obj) override;
134 void SavePrimitive(std::ostream& out,Option_t* opt="") override;
140 void SetName(const char* name) override;
142 Bool_t SetPassedHistogram(const TH1& rPassed,Option_t* opt);
149 Bool_t SetBins(Int_t nx, const Double_t *xBins);
151 Bool_t SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t *yBins);
153 Int_t nz, Double_t zmin, Double_t zmax);
154 Bool_t SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t * yBins, Int_t nz,
155 const Double_t *zBins);
156
157 void SetTitle(const char* title) override;
161 void SetWeight(Double_t weight);
168
169 static Bool_t CheckBinning(const TH1& pass,const TH1& total);
170 static Bool_t CheckConsistency(const TH1& pass,const TH1& total,Option_t* opt="");
171 static Bool_t CheckEntries(const TH1& pass,const TH1& total,Option_t* opt="");
172 static Bool_t CheckWeights(const TH1& pass,const TH1& total);
173 static Double_t Combine(Double_t& up,Double_t& low,Int_t n,const Int_t* pass,const Int_t* total,
174 Double_t alpha,Double_t beta,Double_t level=0.683,
175 const Double_t* w=nullptr,Option_t* opt="");
176 static TGraphAsymmErrors* Combine(TCollection* pList,Option_t* opt="",Int_t n=0,const Double_t* w=nullptr);
177
178 //calculating boundaries of confidence intervals
181 static Double_t Normal(Double_t total,Double_t passed,Double_t level,Bool_t bUpper);
182 static Double_t Wilson(Double_t total,Double_t passed,Double_t level,Bool_t bUpper);
186 // Bayesian functions
187 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);
188 // helper functions for Bayesian statistics
190 static Bool_t BetaShortestInterval(Double_t level,Double_t alpha,Double_t beta,Double_t & lower, Double_t & upper);
191 static Double_t BetaMean(Double_t alpha,Double_t beta);
192 static Double_t BetaMode(Double_t alpha,Double_t beta);
193
194 ClassDefOverride(TEfficiency,2) //calculating efficiencies
195};
196
197const TEfficiency operator+(const TEfficiency& lhs,const TEfficiency& rhs);
198
199#endif
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
#define BIT(n)
Definition Rtypes.h:91
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
const TEfficiency operator+(const TEfficiency &lhs, const TEfficiency &rhs)
static unsigned int total
char name[80]
Definition TGX11.cxx:148
float xmin
float ymin
float xmax
float ymax
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
void FillGraph2D(TGraph2DAsymmErrors *graph, Option_t *opt) const
Bool_t UsesCentralInterval() const
void Draw(Option_t *opt="") override
Default Draw method for all objects.
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to an event at (px,py).
void SetPosteriorMode(Bool_t on=true)
TEfficiency(const char *name, const char *title, Int_t nbinsx, const Double_t *xbins, Int_t nbinsy, const Double_t *ybins)
TH2 * CreateHistogram(Option_t *opt="") const
Bool_t SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t *yBins)
TH2 * GetPaintedHistogram() const
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)
Bool_t SetBins(Int_t nx, const Double_t *xBins, Int_t ny, const Double_t *yBins, Int_t nz, const Double_t *zBins)
void Browse(TBrowser *) override
Browse object. May be overridden for another default action.
Definition TEfficiency.h:98
static Double_t AgrestiCoull(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
~TEfficiency() override
TList * GetListOfFunctions()
Long64_t Merge(TCollection *list)
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
EStatOption fStatisticOption
Defines how the confidence intervals are determined.
Definition TEfficiency.h:59
TEfficiency(const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup)
void SetStatisticOption(EStatOption option)
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="")
TGraph2DAsymmErrors * GetPaintedGraph2D() const
void Paint(Option_t *opt) override
This method must be overridden if a class wants to paint itself.
void SetWeight(Double_t weight)
static Double_t BetaMode(Double_t alpha, Double_t beta)
TH1 * fTotalHistogram
Histogram for total number of events.
Definition TEfficiency.h:60
Int_t GetDimension() const
TGraph2DAsymmErrors * fPaintGraph2D
! Temporary graph for painting
Definition TEfficiency.h:56
TEfficiency & operator+=(const TEfficiency &rhs)
Bool_t SetBins(Int_t nx, Double_t xmin, Double_t xmax)
void Build(const char *name, const char *title)
TH1 * GetCopyPassedHisto() const
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)
Double_t GetEfficiencyErrorUp(Int_t bin) const
static Bool_t CheckConsistency(const TH1 &pass, const TH1 &total, Option_t *opt="")
static Double_t MidPInterval(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Double_t fBeta_alpha
Global parameter for prior beta distribution (default = 1).
Definition TEfficiency.h:47
Bool_t UsesBayesianStat() const
static Bool_t CheckWeights(const TH1 &pass, const TH1 &total)
Bool_t SetBins(Int_t nx, const Double_t *xBins)
const TH1 * GetPassedHistogram() const
void SavePrimitive(std::ostream &out, Option_t *opt="") override
Save a primitive as a C++ statement(s) on output stream "out".
static Double_t Wilson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
static Double_t Normal(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
void SetBetaBeta(Double_t beta)
Double_t GetConfidenceLevel() const
void SetName(const char *name) override
Set the name of the TNamed.
TEfficiency(const char *name, const char *title, Int_t nbins, Double_t xlow, Double_t xup)
TGraph2DAsymmErrors * CreateGraph2D(Option_t *opt="") const
Bool_t SetPassedEvents(Int_t bin, Double_t events)
Int_t GetGlobalBin(Int_t binx, Int_t biny=0, Int_t binz=0) const
TH1 * fPassedHistogram
Histogram for events which passed certain criteria.
Definition TEfficiency.h:58
void SetBetaAlpha(Double_t alpha)
Bool_t SetBins(Int_t nx, Double_t xmin, Double_t xmax, Int_t ny, Double_t ymin, Double_t ymax)
@ 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 Double_t FeldmanCousins(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Double_t fWeight
Weight for all events (default = 1).
Definition TEfficiency.h:61
Bool_t SetPassedHistogram(const TH1 &rPassed, Option_t *opt)
Bool_t SetBins(Int_t nx, Double_t xmin, Double_t xmax, Int_t ny, Double_t ymin, Double_t ymax, Int_t nz, Double_t zmin, Double_t zmax)
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
static Double_t BetaCentralInterval(Double_t level, Double_t alpha, Double_t beta, Bool_t bUpper)
Bool_t UsesPosteriorMode() const
TEfficiency(const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup, Int_t nbinsz, Double_t zlow, Double_t zup)
void SetShortestInterval(Bool_t on=true)
const TH1 * GetTotalHistogram() const
Bool_t UsesWeights() const
void FillHistogram(TH2 *h2) const
TEfficiency(const TH1 &passed, const TH1 &total)
Bool_t UsesPosteriorAverage() const
TEfficiency(const char *name, const char *title, Int_t nbinsx, const Double_t *xbins, Int_t nbinsy, const Double_t *ybins, Int_t nbinsz, const Double_t *zbins)
Int_t FindFixBin(Double_t x, Double_t y=0, Double_t z=0) const
TDirectory * GetDirectory() const
TDirectory * fDirectory
! Pointer to directory holding this TEfficiency object
Definition TEfficiency.h:53
void SetUseWeightedEvents(Bool_t on=kTRUE)
TEfficiency & operator=(const TEfficiency &rhs)
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Computes distance from point (px,py) to the object.
Double_t fConfLevel
Confidence level (default = 0.683, 1 sigma).
Definition TEfficiency.h:52
void SetCentralInterval(Bool_t on=true)
TEfficiency(const TEfficiency &heff)
static TGraphAsymmErrors * Combine(TCollection *pList, Option_t *opt="", Int_t n=0, const Double_t *w=nullptr)
static Double_t ClopperPearson(Double_t total, Double_t passed, Double_t level, Bool_t bUpper)
Double_t fBeta_beta
Global parameter for prior beta distribution (default = 1).
Definition TEfficiency.h:48
Double_t GetEfficiency(Int_t bin) const
Bool_t SetTotalHistogram(const TH1 &rTotal, Option_t *opt)
void Fill(Bool_t bPassed, Double_t x, Double_t y=0, Double_t z=0)
void SetDirectory(TDirectory *dir)
static Double_t BetaMean(Double_t alpha, Double_t beta)
static Bool_t CheckEntries(const TH1 &pass, const TH1 &total, Option_t *opt="")
TGraphAsymmErrors * fPaintGraph
! Temporary graph for painting
Definition TEfficiency.h:55
TEfficiency(const char *name, const char *title, Int_t nbins, const Double_t *xbins)
TGraphAsymmErrors * CreateGraph(Option_t *opt="") const
static Bool_t BetaShortestInterval(Double_t level, Double_t alpha, Double_t beta, Double_t &lower, Double_t &upper)
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)
void SetBetaBinParameters(Int_t bin, Double_t alpha, Double_t beta)
Double_t GetWeight() const
void Add(const TEfficiency &rEff)
Definition TEfficiency.h:97
static Bool_t FeldmanCousinsInterval(Double_t total, Double_t passed, Double_t level, Double_t &lower, Double_t &upper)
TH1 * GetCopyTotalHisto() const
void SetConfidenceLevel(Double_t level)
Double_t GetEfficiencyErrorLow(Int_t bin) const
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
static Bool_t CheckBinning(const TH1 &pass, const TH1 &total)
void SetTitle(const char *title) override
Set the title of the TNamed.
TFitResultPtr Fit(TF1 *f1, Option_t *opt="")
void RecursiveRemove(TObject *obj) override
Recursively remove this object from a list.
TH2 * fPaintHisto
! Temporary histogram for painting
Definition TEfficiency.h:57
Definition TF1.h:182
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
Service class for 2-D histogram classes.
Definition TH2.h:30
A doubly linked list.
Definition TList.h:38
TNamed()
Definition TNamed.h:38
Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:888
TObject()
TObject constructor.
Definition TObject.h:259
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
th1 Draw()