TEfficiency.h

Go to the documentation of this file.
00001 #ifndef ROOT_TEfficiency
00002 #define ROOT_TEfficiency
00003 
00004 //standard header
00005 #include <vector>
00006 #include <utility>
00007 
00008 //ROOT header
00009 #ifndef ROOT_TNamed
00010 #include "TNamed.h"
00011 #endif
00012 
00013 #ifndef ROOT_TAttLine
00014 #include "TAttLine.h"
00015 #endif
00016 
00017 #ifndef ROOT_TAttFill
00018 #include "TAttFill.h"
00019 #endif
00020 
00021 #ifndef ROOT_TAttMarker
00022 #include "TAttMarker.h"
00023 #endif
00024 
00025 class TCollection;
00026 class TF1;
00027 class TGraphAsymmErrors;
00028 class TH1;
00029 class TH2;
00030 class TList;
00031 
00032 //|TEfficiency
00033 //------------------------
00034 
00035 class TEfficiency: public TNamed, public TAttLine, public TAttFill, public TAttMarker
00036 {
00037 public:  
00038       //enumaration type for different statistic options for calculating confidence intervals
00039       //kF* ... frequentist methods; kB* ... bayesian methods      
00040       enum EStatOption {
00041          kFCP = 0,                             //Clopper-Pearson interval (recommended by PDG)
00042          kFNormal,                            //normal approximation
00043          kFWilson,                           //Wilson interval
00044          kFAC,                             //Agresti-Coull interval
00045          kFFC,                             //Feldman-Cousins interval
00046          kBJeffrey,                        //Jeffrey interval (Prior ~ Beta(0.5,0.5)
00047          kBUniform,                        //Prior ~ Uniform = Beta(1,1)
00048          kBBayesian                        //user specified Prior ~ Beta(fBeta_alpha,fBeta_beta)
00049       };
00050 
00051 protected:
00052 
00053       Double_t      fBeta_alpha;             //global parameter for prior beta distribution (default = 1)
00054       Double_t      fBeta_beta;              //global parameter for prior beta distribution (default = 1)
00055       std::vector<std::pair<Double_t, Double_t> > fBeta_bin_params;  // parameter for prior beta distribution different bin by bin 
00056                                                                  // (default vector is empty)
00057       Double_t      (*fBoundary)(Int_t,Int_t,Double_t,Bool_t);               //!pointer to a method calculating the boundaries of confidence intervals
00058       Double_t      fConfLevel;              //confidence level (default = 0.95)
00059       TDirectory*   fDirectory;              //!pointer to directory holding this TEfficiency object
00060       TList*        fFunctions;              //->pointer to list of functions
00061       TGraphAsymmErrors* fPaintGraph;        //!temporary graph for painting
00062       TH2*          fPaintHisto;             //!temporary histogram for painting      
00063       TH1*          fPassedHistogram;        //histogram for events which passed certain criteria
00064       EStatOption   fStatisticOption;        //defines how the confidence intervals are determined
00065       TH1*          fTotalHistogram;         //histogram for total number of events
00066       Double_t      fWeight;                 //weight for all events (default = 1)
00067 
00068       enum{
00069          kIsBayesian       = BIT(14),              //bayesian statistics are used
00070          kPosteriorMode    = BIT(15),              //use posterior mean for best estimate (Bayesian statistics)
00071          kShortestInterval = BIT(16),              // use shortest interval
00072          kUseBinPrior      = BIT(17)               // use a different prior for each bin
00073       };
00074 
00075       void          Build(const char* name,const char* title);      
00076       
00077 public:
00078       TEfficiency();   
00079       TEfficiency(const TH1& passed,const TH1& total);
00080       TEfficiency(const char* name,const char* title,Int_t nbins,
00081                    const Double_t* xbins);
00082       TEfficiency(const char* name,const char* title,Int_t nbins,Double_t xlow,
00083                    Double_t xup);
00084       TEfficiency(const char* name,const char* title,Int_t nbinsx,
00085                    Double_t xlow,Double_t xup,Int_t nbinsy,Double_t ylow,
00086                    Double_t yup);
00087       TEfficiency(const char* name,const char* title,Int_t nbinsx,
00088                    const Double_t* xbins,Int_t nbinsy,const Double_t* ybins);
00089       TEfficiency(const char* name,const char* title,Int_t nbinsx,
00090                    Double_t xlow,Double_t xup,Int_t nbinsy,Double_t ylow,
00091                    Double_t yup,Int_t nbinsz,Double_t zlow,Double_t zup);
00092       TEfficiency(const char* name,const char* title,Int_t nbinsx,
00093                    const Double_t* xbins,Int_t nbinsy,const Double_t* ybins,
00094                    Int_t nbinsz,const Double_t* zbins);      
00095       TEfficiency(const TEfficiency& heff);
00096       ~TEfficiency();
00097       
00098       void          Add(const TEfficiency& rEff) {*this += rEff;}
00099       virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
00100       void          Draw(Option_t* opt = "");
00101       virtual void  ExecuteEvent(Int_t event, Int_t px, Int_t py);
00102       void          Fill(Bool_t bPassed,Double_t x,Double_t y=0,Double_t z=0);
00103       Int_t         FindFixBin(Double_t x,Double_t y=0,Double_t z=0) const;
00104       Int_t         Fit(TF1* f1,Option_t* opt="");
00105       // use trick of -1 to return global parameters
00106       Double_t      GetBetaAlpha(Int_t bin = -1) const {return (fBeta_bin_params.size() > (UInt_t)bin) ? fBeta_bin_params[bin].first : fBeta_alpha;}
00107       Double_t      GetBetaBeta(Int_t bin =  -1) const {return (fBeta_bin_params.size() > (UInt_t)bin) ? fBeta_bin_params[bin].second : fBeta_beta;}  
00108       Double_t      GetConfidenceLevel() const {return fConfLevel;}
00109       TH1*          GetCopyPassedHisto() const;
00110       TH1*          GetCopyTotalHisto() const;
00111       Int_t         GetDimension() const;
00112       TDirectory*   GetDirectory() const {return fDirectory;}
00113       Double_t      GetEfficiency(Int_t bin) const;
00114       Double_t      GetEfficiencyErrorLow(Int_t bin) const;
00115       Double_t      GetEfficiencyErrorUp(Int_t bin) const;
00116       Int_t         GetGlobalBin(Int_t binx,Int_t biny=0,Int_t binz=0) const;
00117       TGraphAsymmErrors*   GetPaintedGraph() const { return fPaintGraph; }     
00118       TH2*          GetPaintedHistogram() const { return fPaintHisto; }     
00119       TList*        GetListOfFunctions() const {return fFunctions;}
00120       const TH1*    GetPassedHistogram() const {return fPassedHistogram;}
00121       EStatOption   GetStatisticOption() const {return fStatisticOption;}
00122       const TH1*    GetTotalHistogram() const {return fTotalHistogram;}
00123       Double_t      GetWeight() const {return fWeight;}
00124       void          Merge(TCollection* list);      
00125       TEfficiency&  operator+=(const TEfficiency& rhs);
00126       TEfficiency&  operator=(const TEfficiency& rhs);
00127       void          Paint(Option_t* opt);
00128       void          SavePrimitive(ostream& out,Option_t* opt="");
00129       void          SetBetaAlpha(Double_t alpha);
00130       void          SetBetaBeta(Double_t beta);    
00131       void          SetBetaBinParameters(Int_t bin, Double_t alpha, Double_t beta);
00132       void          SetConfidenceLevel(Double_t level);
00133       void          SetDirectory(TDirectory* dir);
00134       void          SetName(const char* name);
00135       Bool_t        SetPassedEvents(Int_t bin,Int_t events);
00136       Bool_t        SetPassedHistogram(const TH1& rPassed,Option_t* opt);
00137       void          SetPosteriorMode(Bool_t on = true) { SetBit(kPosteriorMode,on); if(on) SetShortestInterval(); } 
00138       void          SetPosteriorAverage(Bool_t on = true) { SetBit(kPosteriorMode,!on); } 
00139       void          SetShortestInterval(Bool_t on = true) { SetBit(kShortestInterval,on); } 
00140       void          SetCentralInterval(Bool_t on = true) { SetBit(kShortestInterval,!on); } 
00141       void          SetStatisticOption(EStatOption option);
00142       void          SetTitle(const char* title);
00143       Bool_t        SetTotalEvents(Int_t bin,Int_t events);
00144       Bool_t        SetTotalHistogram(const TH1& rTotal,Option_t* opt);
00145       void          SetWeight(Double_t weight);    
00146       Bool_t        UsesBayesianStat() const {return TestBit(kIsBayesian);}
00147       Bool_t        UsesPosteriorMode() const   {return TestBit(kPosteriorMode) && TestBit(kIsBayesian);} 
00148       Bool_t        UsesShortestInterval() const   {return TestBit(kShortestInterval) && TestBit(kIsBayesian);} 
00149       Bool_t        UsesPosteriorAverage() const   {return !UsesPosteriorMode();} 
00150       Bool_t        UsesCentralInterval() const   {return !UsesShortestInterval();} 
00151 
00152       static Bool_t CheckBinning(const TH1& pass,const TH1& total);
00153       static Bool_t CheckConsistency(const TH1& pass,const TH1& total,Option_t* opt="");
00154       static Bool_t CheckEntries(const TH1& pass,const TH1& total,Option_t* opt="");
00155       static Double_t Combine(Double_t& up,Double_t& low,Int_t n,const Int_t* pass,const Int_t* total,
00156                               Double_t alpha,Double_t beta,Double_t level=0.683,
00157                               const Double_t* w=0,Option_t* opt="");
00158       static TGraphAsymmErrors* Combine(TCollection* pList,Option_t* opt="",Int_t n=0,const Double_t* w=0);
00159       
00160       //calculating boundaries of confidence intervals
00161       static Double_t AgrestiCoull(Int_t total,Int_t passed,Double_t level,Bool_t bUpper);
00162       static Double_t ClopperPearson(Int_t total,Int_t passed,Double_t level,Bool_t bUpper);
00163       static Double_t Normal(Int_t total,Int_t passed,Double_t level,Bool_t bUpper);
00164       static Double_t Wilson(Int_t total,Int_t passed,Double_t level,Bool_t bUpper);
00165       static Double_t FeldmanCousins(Int_t total,Int_t passed,Double_t level,Bool_t bUpper);
00166       static Bool_t FeldmanCousinsInterval(Int_t total,Int_t passed,Double_t level,Double_t & lower, Double_t & upper);
00167       // Bayesian functions 
00168       static Double_t Bayesian(Int_t total,Int_t passed,Double_t level,Double_t alpha,Double_t beta,Bool_t bUpper, Bool_t bShortest = false);
00169       // helper functions for Bayesian statistics  
00170       static Double_t BetaCentralInterval(Double_t level,Double_t alpha,Double_t beta,Bool_t bUpper);
00171       static Bool_t   BetaShortestInterval(Double_t level,Double_t alpha,Double_t beta,Double_t & lower, Double_t & upper);
00172       static Double_t BetaMean(Double_t alpha,Double_t beta);
00173       static Double_t BetaMode(Double_t alpha,Double_t beta);
00174       
00175       ClassDef(TEfficiency,1)     //calculating efficiencies
00176 };
00177 
00178 const TEfficiency operator+(const TEfficiency& lhs,const TEfficiency& rhs);
00179 
00180 #endif

Generated on Tue Jul 5 14:22:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1