Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TRolke.h
Go to the documentation of this file.
1 
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // TRolke
5 //
6 // This class computes confidence intervals for the rate of a Poisson
7 // in the presence of background and efficiency with a fully frequentist
8 // treatment of the uncertainties in the efficiency and background estimate
9 // using the profile likelihood method.
10 //
11 // Author: Jan Conrad (CERN) 2004
12 // Updated: Johan Lundberg (CERN) 2009
13 //
14 // Copyright CERN 2004,2009 Jan.Conrad@cern.ch,
15 // Johan.Lundberg@cern.ch
16 //
17 // For information about the statistical meaning of the parameters
18 // and the syntax, consult TRolke.cxx
19 // ------------------
20 //
21 // Examples are found in the file Rolke.C
22 // --------------------------------------
23 //
24 //////////////////////////////////////////////////////////////////////////////
25 
26 #ifndef ROOT_TRolke
27 #define ROOT_TRolke
28 
29 #include "TObject.h"
30 #include "TMath.h"
31 
32 // Class definition. This class is not intended to be used as a base class.
33 class TRolke : public TObject
34 {
35 
36 private:
37  Double_t fCL; // confidence level as a fraction [0.9 for 90% ]
38  Double_t fUpperLimit; // the calculated upper limit
39  Double_t fLowerLimit; // the calculated lower limit
40  bool fBounding; // false for unbounded likelihood
41  // true for bounded likelihood
42  Int_t fNumWarningsDeprecated1;
43  Int_t fNumWarningsDeprecated2;
44 
45  /* ----------------------------------------------------------------- */
46  /* These variables are set by the Set methods for the various models */
47  Int_t f_x;
48  Int_t f_y;
49  Int_t f_z;
50  Double_t f_bm;
51  Double_t f_em;
52  Double_t f_e;
53  Int_t f_mid;
54  Double_t f_sde;
55  Double_t f_sdb;
56  Double_t f_tau;
57  Double_t f_b;
58  Int_t f_m;
59 
60  /* ----------------------------------------------------------------- */
61  /* Internal helper functions and methods */
62  // The Calculator
63  Double_t Interval(Int_t x, Int_t y, Int_t z, Double_t bm, Double_t em, Double_t e, Int_t mid, Double_t sde, Double_t sdb, Double_t tau, Double_t b, Int_t m);
64 
65  // LIKELIHOOD ROUTINE
66  Double_t Likelihood(Double_t mu, Int_t x, Int_t y, Int_t z, Double_t bm, Double_t em, Int_t mid, Double_t sde, Double_t sdb, Double_t tau, Double_t b, Int_t m, Int_t what);
67 
68  //MODEL 1
69  Double_t EvalLikeMod1(Double_t mu, Int_t x, Int_t y, Int_t z, Double_t tau, Int_t m, Int_t what);
70  Double_t LikeMod1(Double_t mu, Double_t b, Double_t e, Int_t x, Int_t y, Int_t z, Double_t tau, Int_t m);
71  void ProfLikeMod1(Double_t mu, Double_t &b, Double_t &e, Int_t x, Int_t y, Int_t z, Double_t tau, Int_t m);
72  Double_t LikeGradMod1(Double_t e, Double_t mu, Int_t x, Int_t y, Int_t z, Double_t tau, Int_t m);
73 
74  //MODEL 2
75  Double_t EvalLikeMod2(Double_t mu, Int_t x, Int_t y, Double_t em, Double_t sde, Double_t tau, Int_t what);
76 
77  Double_t LikeMod2(Double_t mu, Double_t b, Double_t e, Int_t x, Int_t y, Double_t em, Double_t tau, Double_t v);
78 
79  //MODEL 3
80  Double_t EvalLikeMod3(Double_t mu, Int_t x, Double_t bm, Double_t em, Double_t sde, Double_t sdb, Int_t what);
81  Double_t LikeMod3(Double_t mu, Double_t b, Double_t e, Int_t x, Double_t bm, Double_t em, Double_t u, Double_t v);
82 
83  //MODEL 4
84  Double_t EvalLikeMod4(Double_t mu, Int_t x, Int_t y, Double_t tau, Int_t what);
85  Double_t LikeMod4(Double_t mu, Double_t b, Int_t x, Int_t y, Double_t tau);
86 
87  //MODEL 5
88  Double_t EvalLikeMod5(Double_t mu, Int_t x, Double_t bm, Double_t sdb, Int_t what);
89  Double_t LikeMod5(Double_t mu, Double_t b, Int_t x, Double_t bm, Double_t u);
90 
91  //MODEL 6
92  Double_t EvalLikeMod6(Double_t mu, Int_t x, Int_t z, Double_t b, Int_t m, Int_t what);
93  Double_t LikeMod6(Double_t mu, Double_t b, Double_t e, Int_t x, Int_t z, Int_t m);
94 
95  //MODEL 7
96  Double_t EvalLikeMod7(Double_t mu, Int_t x, Double_t em, Double_t sde, Double_t b, Int_t what);
97  Double_t LikeMod7(Double_t mu, Double_t b, Double_t e, Int_t x, Double_t em, Double_t v);
98 
99  //MISC
100  static Double_t EvalPolynomial(Double_t x, const Int_t coef[], Int_t N);
101  static Double_t EvalMonomial(Double_t x, const Int_t coef[], Int_t N);
102  Double_t LogFactorial(Int_t n);
103 
104  Double_t ComputeInterval(Int_t x, Int_t y, Int_t z, Double_t bm, Double_t em, Double_t e, Int_t mid, Double_t sde, Double_t sdb, Double_t tau, Double_t b, Int_t m);
105 
106  void SetModelParameters(Int_t x, Int_t y, Int_t z, Double_t bm, Double_t em, Double_t e, Int_t mid, Double_t sde, Double_t sdb, Double_t tau, Double_t b, Int_t m);
107 
108  void SetModelParameters();
109 
110  Double_t GetBackground();
111 
112 public:
113 
114  /* Constructor */
115  TRolke(Double_t CL = 0.9, Option_t *option = "");
116 
117  /* Destructor */
118  virtual ~TRolke();
119 
120  /* Get and set the Confidence Level */
121  Double_t GetCL() const {
122  return fCL;
123  }
124  void SetCL(Double_t CL) {
125  fCL = CL;
126  }
127 
128  /* Set the Confidence Level in terms of Sigmas. */
129  void SetCLSigmas(Double_t CLsigmas) {
130  fCL = TMath::Erf(CLsigmas / TMath::Sqrt(2.0)) ;
131  }
132 
133  // The Set methods for the different models are described in Rolke.cxx
134  // model 1
135  void SetPoissonBkgBinomEff(Int_t x, Int_t y, Int_t z, Double_t tau, Int_t m);
136 
137  // model 2
138  void SetPoissonBkgGaussEff(Int_t x, Int_t y, Double_t em, Double_t tau, Double_t sde);
139 
140  // model 3
141  void SetGaussBkgGaussEff(Int_t x, Double_t bm, Double_t em, Double_t sde, Double_t sdb);
142 
143  // model 4
144  void SetPoissonBkgKnownEff(Int_t x, Int_t y, Double_t tau, Double_t e);
145 
146  // model 5
147  void SetGaussBkgKnownEff(Int_t x, Double_t bm, Double_t sdb, Double_t e);
148 
149  // model 6
150  void SetKnownBkgBinomEff(Int_t x, Int_t z, Int_t m, Double_t b);
151 
152  // model 7
153  void SetKnownBkgGaussEff(Int_t x, Double_t em, Double_t sde, Double_t b);
154 
155  /* Deprecated interface method (read Rolke.cxx). May be removed from future releases */
156  Double_t CalculateInterval(Int_t x, Int_t y, Int_t z, Double_t bm, Double_t em, Double_t e, Int_t mid, Double_t sde, Double_t sdb, Double_t tau, Double_t b, Int_t m);
157 
158  // get the upper and lower limits based on the specified model
159  bool GetLimits(Double_t& low, Double_t& high);
160  Double_t GetUpperLimit();
161  Double_t GetLowerLimit();
162 
163  // get the upper and lower average limits
164  bool GetSensitivity(Double_t& low, Double_t& high, Double_t pPrecision = 0.00001);
165 
166  // get the upper and lower limits for the outcome corresponding to
167  // a given quantile.
168  bool GetLimitsQuantile(Double_t& low, Double_t& high, Int_t& out_x, Double_t integral = 0.5);
169 
170  // get the upper and lower limits for the most likely outcome.
171  bool GetLimitsML(Double_t& low, Double_t& high, Int_t& out_x);
172 
173  // get the value of x corresponding to rejection of the null hypothesis.
174  bool GetCriticalNumber(Int_t& ncrit,Int_t maxtry=-1);
175 
176  /* Get the bounding mode flag. True activates bounded mode. Read
177  TRolke.cxx and the references therein for details. */
178  bool GetBounding() const {
179  return fBounding;
180  }
181 
182  /* Get the bounding mode flag. True activates bounded mode. Read
183  TRolke.cxx and the references therein for details. */
184  void SetBounding(const bool bnd) {
185  fBounding = bnd;
186  }
187 
188  /* Deprecated name for SetBounding. */
189  void SetSwitch(bool bnd) ;
190 
191  /* Dump internals. Option is not used */
192  void Print(Option_t*) const;
193 
194  ClassDef(TRolke, 2)
195 };
196 
197 //calculate confidence limits using the Rolke method
198 #endif
199