1 | // @(#)root/physics:$Name: not supported by cvs2svn $:$Id: MRolke.cc,v 1.2 2006-10-17 16:32:52 meyer Exp $
|
---|
2 | // Author: Jan Conrad 9/2/2004
|
---|
3 |
|
---|
4 | /*************************************************************************
|
---|
5 | * Copyright (C) 1995-2004, 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 | //////////////////////////////////////////////////////////////////////////////
|
---|
13 | //
|
---|
14 | // MRolke
|
---|
15 | //
|
---|
16 | // This class computes confidence intervals for the rate of a Poisson
|
---|
17 | // in the presence of background and efficiency with a fully frequentist
|
---|
18 | // treatment of the uncertainties in the efficiency and background estimate
|
---|
19 | // using the profile likelihood method.
|
---|
20 | //
|
---|
21 | // The signal is always assumed to be Poisson.
|
---|
22 | //
|
---|
23 | // The method is very similar to the one used in MINUIT (MINOS).
|
---|
24 | //
|
---|
25 | // Two options are offered to deal with cases where the maximum likelihood
|
---|
26 | // estimate (MLE) is not in the physical region. Version "bounded likelihood"
|
---|
27 | // is the one used by MINOS if bounds for the physical region are chosen. Versi// on "unbounded likelihood (the default) allows the MLE to be in the
|
---|
28 | // unphysical region. It has however better coverage.
|
---|
29 | // For more details consult the reference (see below).
|
---|
30 | //
|
---|
31 | //
|
---|
32 | // It allows the following Models:
|
---|
33 | //
|
---|
34 | // 1: Background - Poisson, Efficiency - Binomial (cl,x,y,z,tau,m)
|
---|
35 | // 2: Background - Poisson, Efficiency - Gaussian (cl,xd,y,em,tau,sde)
|
---|
36 | // 3: Background - Gaussian, Efficiency - Gaussian (cl,x,bm,em,sd)
|
---|
37 | // 4: Background - Poisson, Efficiency - known (cl,x,y,tau,e)
|
---|
38 | // 5: Background - Gaussian, Efficiency - known (cl,x,y,z,sdb,e)
|
---|
39 | // 6: Background - known, Efficiency - Binomial (cl,x,z,m,b)
|
---|
40 | // 7: Background - known, Efficiency - Gaussian (cl,x,em,sde,b)
|
---|
41 | //
|
---|
42 | // Parameter definition:
|
---|
43 | //
|
---|
44 | // cl = Confidence level
|
---|
45 | //
|
---|
46 | // x = number of observed events
|
---|
47 | //
|
---|
48 | // y = number of background events
|
---|
49 | //
|
---|
50 | // z = number of simulated signal events
|
---|
51 | //
|
---|
52 | // em = measurement of the efficiency.
|
---|
53 | //
|
---|
54 | // bm = background estimate
|
---|
55 | //
|
---|
56 | // tau = ratio between signal and background region (in case background is
|
---|
57 | // observed) ratio between observed and simulated livetime in case
|
---|
58 | // background is determined from MC.
|
---|
59 | //
|
---|
60 | // sd(x) = sigma of the Gaussian
|
---|
61 | //
|
---|
62 | // e = true efficiency (in case known)
|
---|
63 | //
|
---|
64 | // b = expected background (in case known)
|
---|
65 | //
|
---|
66 | // m = number of MC runs
|
---|
67 | //
|
---|
68 | // mid = ID number of the model ...
|
---|
69 | //
|
---|
70 | // For a description of the method and its properties:
|
---|
71 | //
|
---|
72 | // W.Rolke, A. Lopez, J. Conrad and Fred James
|
---|
73 | // "Limits and Confidence Intervals in presence of nuisance parameters"
|
---|
74 | // http://lanl.arxiv.org/abs/physics/0403059
|
---|
75 | // Nucl.Instrum.Meth.A551:493-503,2005
|
---|
76 | //
|
---|
77 | // Should I use MRolke, TFeldmanCousins, TLimit?
|
---|
78 | // ============================================
|
---|
79 | // 1. I guess MRolke makes TFeldmanCousins obsolete?
|
---|
80 | //
|
---|
81 | // Certainly not. TFeldmanCousins is the fully frequentist construction and
|
---|
82 | // should be used in case of no (or negligible uncertainties). It is however
|
---|
83 | // not capable of treating uncertainties in nuisance parameters.
|
---|
84 | // MRolke is desined for this case and it is shown in the reference above
|
---|
85 | // that it has good coverage properties for most cases, ie it might be
|
---|
86 | // used where FeldmannCousins can't.
|
---|
87 | //
|
---|
88 | // 2. What are the advantages of MRolke over TLimit?
|
---|
89 | //
|
---|
90 | // MRolke is fully frequentist. TLimit treats nuisance parameters Bayesian.
|
---|
91 | // For a coverage study of a Bayesian method refer to
|
---|
92 | // physics/0408039 (Tegenfeldt & J.C). However, this note studies
|
---|
93 | // the coverage of Feldman&Cousins with Bayesian treatment of nuisance
|
---|
94 | // parameters. To make a long story short: using the Bayesian method you
|
---|
95 | // might introduce a small amount of over-coverage (though I haven't shown it
|
---|
96 | // for TLimit). On the other hand, coverage of course is a not so interesting
|
---|
97 | // when you consider yourself a Bayesian.
|
---|
98 | //
|
---|
99 | // Author: Jan Conrad (CERN)
|
---|
100 | //
|
---|
101 | // see example in tutorial Rolke.C
|
---|
102 | //
|
---|
103 | // Copyright CERN 2004 Jan.Conrad@cern.ch
|
---|
104 | //
|
---|
105 | ///////////////////////////////////////////////////////////////////////////
|
---|
106 |
|
---|
107 |
|
---|
108 | #include "MRolke.h"
|
---|
109 | #include "TMath.h"
|
---|
110 | #include "Riostream.h"
|
---|
111 |
|
---|
112 | ClassImp(MRolke)
|
---|
113 |
|
---|
114 | //__________________________________________________________________________
|
---|
115 | MRolke::MRolke(Double_t CL, Option_t * /*option*/)
|
---|
116 | {
|
---|
117 | //constructor
|
---|
118 | fUpperLimit = 0.0;
|
---|
119 | fLowerLimit = 0.0;
|
---|
120 | fCL = CL;
|
---|
121 | fSwitch = 0; // 0: unbounded likelihood
|
---|
122 | // 1: bounded likelihood
|
---|
123 | }
|
---|
124 |
|
---|
125 | //___________________________________________________________________________
|
---|
126 | MRolke::~MRolke()
|
---|
127 | {
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | //___________________________________________________________________________
|
---|
132 | Double_t MRolke::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)
|
---|
133 | {
|
---|
134 | //calculate interval
|
---|
135 | Int_t done = 0;
|
---|
136 | Double_t limit[2];
|
---|
137 |
|
---|
138 | limit[1] = Interval(x,y,z,bm,em,e,mid, sde,sdb,tau,b,m);
|
---|
139 |
|
---|
140 | if (limit[1] > 0) {
|
---|
141 | done = 1;
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (fSwitch == 0) {
|
---|
145 |
|
---|
146 | Int_t trial_x = x;
|
---|
147 |
|
---|
148 | while (done == 0) {
|
---|
149 | trial_x++;
|
---|
150 | limit[1] = Interval(trial_x,y,z,bm,em,e,mid, sde,sdb,tau,b,m);
|
---|
151 | if (limit[1] > 0) done = 1;
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | return limit[1];
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 | //_____________________________________________________________________
|
---|
162 | Double_t MRolke::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)
|
---|
163 | {
|
---|
164 | // Calculates the Confidence Interval
|
---|
165 |
|
---|
166 | //Double_t dchi2 = Chi2Percentile(1,1-fCL);
|
---|
167 | Double_t dchi2 = TMath::ChisquareQuantile(fCL, 1);
|
---|
168 |
|
---|
169 | Double_t tempxy[2],limits[2] = {0,0};
|
---|
170 | Double_t slope,fmid,low,flow,high,fhigh,test,ftest,mu0,maximum,target,l,f0;
|
---|
171 | Double_t med = 0;
|
---|
172 | Double_t maxiter=1000, acc = 0.00001;
|
---|
173 | Int_t bp = 0;
|
---|
174 |
|
---|
175 | if ((mid != 3) && (mid != 5)) bm = (Double_t)y;
|
---|
176 |
|
---|
177 | if ((mid == 3) || (mid == 5)) {
|
---|
178 | if (bm == 0) bm = 0.00001;
|
---|
179 | }
|
---|
180 |
|
---|
181 | if ((mid <= 2) || (mid == 4)) bp = 1;
|
---|
182 |
|
---|
183 |
|
---|
184 | if (bp == 1 && x == 0 && bm > 0 ){
|
---|
185 |
|
---|
186 | for(Int_t i = 0; i < 2; i++) {
|
---|
187 | x++;
|
---|
188 | tempxy[i] = Interval(x,y,z,bm,em,e,mid,sde,sdb,tau,b,m);
|
---|
189 | }
|
---|
190 | slope = tempxy[1] - tempxy[0];
|
---|
191 | limits[1] = tempxy[0] - slope;
|
---|
192 | limits[0] = 0.0;
|
---|
193 | if (limits[1] < 0) limits[1] = 0.0;
|
---|
194 | goto done;
|
---|
195 | }
|
---|
196 |
|
---|
197 | if (bp != 1 && x == 0){
|
---|
198 |
|
---|
199 | for(Int_t i = 0; i < 2; i++) {
|
---|
200 | x++;
|
---|
201 | tempxy[i] = Interval(x,y,z,bm,em,e,mid,sde,sdb,tau,b,m);
|
---|
202 | }
|
---|
203 | slope = tempxy[1] - tempxy[0];
|
---|
204 | limits[1] = tempxy[0] - slope;
|
---|
205 | limits[0] = 0.0;
|
---|
206 | if (limits[1] < 0) limits[1] = 0.0;
|
---|
207 | goto done;
|
---|
208 | }
|
---|
209 |
|
---|
210 | if (bp != 1 && bm == 0){
|
---|
211 | for(Int_t i = 0; i < 2; i++) {
|
---|
212 | bm++;
|
---|
213 | limits[1] = Interval(x,y,z,bm,em,e,mid,sde,sdb,tau,b,m);
|
---|
214 | tempxy[i] = limits[1];
|
---|
215 | }
|
---|
216 | slope = tempxy[1] - tempxy[0];
|
---|
217 | limits[1] = tempxy[0] - slope;
|
---|
218 | if (limits[1] < 0) limits[1] = 0;
|
---|
219 | goto done;
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | if (x == 0 && bm == 0){
|
---|
224 | x++;
|
---|
225 | bm++;
|
---|
226 |
|
---|
227 | limits[1] = Interval(x,y,z,bm,em,e,mid,sde,sdb,tau,b,m);
|
---|
228 | tempxy[0] = limits[1];
|
---|
229 | x = 1;
|
---|
230 | bm = 2;
|
---|
231 | limits[1] = Interval(x,y,z,bm,em,e,mid,sde,sdb,tau,b,m);
|
---|
232 | tempxy[1] = limits[1];
|
---|
233 | x = 2;
|
---|
234 | bm = 1;
|
---|
235 | limits[1] = Interval(x,y,z,bm,em,e,mid,sde,sdb,tau,b,m);
|
---|
236 | limits[1] = 3*tempxy[0] -tempxy[1] - limits[1];
|
---|
237 | if (limits[1] < 0) limits[1] = 0;
|
---|
238 | goto done;
|
---|
239 | }
|
---|
240 |
|
---|
241 | mu0 = Likelihood(0,x,y,z,bm,em,e,mid,sde,sdb,tau,b,m,1);
|
---|
242 |
|
---|
243 | maximum = Likelihood(0,x,y,z,bm,em,e,mid,sde,sdb,tau,b,m,2);
|
---|
244 |
|
---|
245 | test = 0;
|
---|
246 |
|
---|
247 | f0 = Likelihood(test,x,y,z,bm,em,e,mid,sde,sdb,tau,b,m,3);
|
---|
248 |
|
---|
249 | if ( fSwitch == 1 ) { // do this only for the unbounded likelihood case
|
---|
250 | if ( mu0 < 0 ) maximum = f0;
|
---|
251 | }
|
---|
252 |
|
---|
253 | target = maximum - dchi2;
|
---|
254 |
|
---|
255 | if (f0 > target) {
|
---|
256 | limits[0] = 0;
|
---|
257 | } else {
|
---|
258 | if (mu0 < 0){
|
---|
259 | limits[0] = 0;
|
---|
260 | limits[1] = 0;
|
---|
261 | }
|
---|
262 |
|
---|
263 | low = 0;
|
---|
264 | flow = f0;
|
---|
265 | high = mu0;
|
---|
266 | fhigh = maximum;
|
---|
267 |
|
---|
268 | for(Int_t i = 0; i < maxiter; i++) {
|
---|
269 | l = (target-fhigh)/(flow-fhigh);
|
---|
270 | if (l < 0.2) l = 0.2;
|
---|
271 | if (l > 0.8) l = 0.8;
|
---|
272 |
|
---|
273 | med = l*low + (1-l)*high;
|
---|
274 | if(med < 0.01){
|
---|
275 | limits[1]=0.0;
|
---|
276 | goto done;
|
---|
277 | }
|
---|
278 |
|
---|
279 | fmid = Likelihood(med,x,y,z,bm,em,e,mid,sde,sdb,tau,b,m,3);
|
---|
280 |
|
---|
281 | if (fmid > target) {
|
---|
282 | high = med;
|
---|
283 | fhigh = fmid;
|
---|
284 | } else {
|
---|
285 | low = med;
|
---|
286 | flow = fmid;
|
---|
287 | }
|
---|
288 | if ((high-low) < acc*high) break;
|
---|
289 | }
|
---|
290 | limits[0] = med;
|
---|
291 | }
|
---|
292 |
|
---|
293 |
|
---|
294 | if(mu0 > 0) {
|
---|
295 | low = mu0;
|
---|
296 | flow = maximum;
|
---|
297 | } else {
|
---|
298 | low = 0;
|
---|
299 | flow = f0;
|
---|
300 | }
|
---|
301 |
|
---|
302 | test = low +1 ;
|
---|
303 |
|
---|
304 | ftest = Likelihood(test,x,y,z,bm,em,e,mid,sde,sdb,tau,b,m,3);
|
---|
305 |
|
---|
306 | if (ftest < target) {
|
---|
307 | high = test;
|
---|
308 | fhigh = ftest;
|
---|
309 | } else {
|
---|
310 | slope = (ftest - flow)/(test - low);
|
---|
311 | high = test + (target -ftest)/slope;
|
---|
312 | fhigh = Likelihood(high,x,y,z,bm,em,e,mid,sde,sdb,tau,b,m,3);
|
---|
313 | }
|
---|
314 |
|
---|
315 | for(Int_t i = 0; i < maxiter; i++) {
|
---|
316 | l = (target-fhigh)/(flow-fhigh);
|
---|
317 | if (l < 0.2) l = 0.2;
|
---|
318 | if (l > 0.8) l = 0.8;
|
---|
319 | med = l * low + (1.-l)*high;
|
---|
320 | fmid = Likelihood(med,x,y,z,bm,em,e,mid,sde,sdb,tau,b,m,3);
|
---|
321 |
|
---|
322 | if (fmid < target) {
|
---|
323 | high = med;
|
---|
324 | fhigh = fmid;
|
---|
325 | } else {
|
---|
326 | low = med;
|
---|
327 | flow = fmid;
|
---|
328 | }
|
---|
329 | if (high-low < acc*high) break;
|
---|
330 | }
|
---|
331 | limits[1] = med;
|
---|
332 |
|
---|
333 | done:
|
---|
334 |
|
---|
335 | if ( (mid == 4) || (mid==5) ) {
|
---|
336 | limits[0] /= e;
|
---|
337 | limits[1] /= e;
|
---|
338 | }
|
---|
339 |
|
---|
340 |
|
---|
341 | fUpperLimit = limits[1];
|
---|
342 | fLowerLimit = TMath::Max(limits[0],0.0);
|
---|
343 |
|
---|
344 |
|
---|
345 | return limits[1];
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | //___________________________________________________________________________
|
---|
350 | Double_t MRolke::Likelihood(Double_t mu, 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, Int_t what)
|
---|
351 | {
|
---|
352 | // Chooses between the different profile likelihood functions to use for the
|
---|
353 | // different models.
|
---|
354 | // Returns evaluation of the profile likelihood functions.
|
---|
355 |
|
---|
356 | switch (mid) {
|
---|
357 | case 1: return EvalLikeMod1(mu,x,y,z,e,tau,b,m,what);
|
---|
358 | case 2: return EvalLikeMod2(mu,x,y,em,e,sde,tau,b,what);
|
---|
359 | case 3: return EvalLikeMod3(mu,x,bm,em,e,sde,sdb,b,what);
|
---|
360 | case 4: return EvalLikeMod4(mu,x,y,tau,b,what);
|
---|
361 | case 5: return EvalLikeMod5(mu,x,bm,sdb,b,what);
|
---|
362 | case 6: return EvalLikeMod6(mu,x,z,e,b,m,what);
|
---|
363 | case 7: return EvalLikeMod7(mu,x,em,e,sde,b,what);
|
---|
364 | }
|
---|
365 |
|
---|
366 | return 0;
|
---|
367 | }
|
---|
368 |
|
---|
369 | //_________________________________________________________________________
|
---|
370 | Double_t MRolke::EvalLikeMod1(Double_t mu, Int_t x, Int_t y, Int_t z, Double_t e, Double_t tau, Double_t b, Int_t m, Int_t what)
|
---|
371 | {
|
---|
372 | // Calculates the Profile Likelihood for MODEL 1:
|
---|
373 | // Poisson background/ Binomial Efficiency
|
---|
374 | // what = 1: Maximum likelihood estimate is returned
|
---|
375 | // what = 2: Profile Likelihood of Maxmimum Likelihood estimate is returned.
|
---|
376 | // what = 3: Profile Likelihood of Test hypothesis is returned
|
---|
377 | // otherwise parameters as described in the beginning of the class)
|
---|
378 |
|
---|
379 | Double_t f = 0;
|
---|
380 | Double_t zm = Double_t(z)/m;
|
---|
381 |
|
---|
382 | if (what == 1) {
|
---|
383 | f = (x-y/tau)/zm;
|
---|
384 | }
|
---|
385 |
|
---|
386 | if (what == 2) {
|
---|
387 | mu = (x-y/tau)/zm;
|
---|
388 | b = y/tau;
|
---|
389 | Double_t ee = zm;
|
---|
390 | f = LikeMod1(mu,b,ee,x,y,z,tau,m);
|
---|
391 | }
|
---|
392 |
|
---|
393 | if (what == 3) {
|
---|
394 | if (mu == 0){
|
---|
395 | b = (x+y)/(1.0+tau);
|
---|
396 | e = zm;
|
---|
397 | f = LikeMod1(mu,b,e,x,y,z,tau,m);
|
---|
398 | } else {
|
---|
399 | MRolke g;
|
---|
400 | g.ProfLikeMod1(mu,b,e,x,y,z,tau,m);
|
---|
401 | f = LikeMod1(mu,b,e,x,y,z,tau,m);
|
---|
402 | }
|
---|
403 | }
|
---|
404 |
|
---|
405 | return f;
|
---|
406 | }
|
---|
407 |
|
---|
408 | //________________________________________________________________________
|
---|
409 | Double_t MRolke::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)
|
---|
410 | {
|
---|
411 | // Profile Likelihood function for MODEL 1:
|
---|
412 | // Poisson background/ Binomial Efficiency
|
---|
413 |
|
---|
414 | return 2*(x*TMath::Log(e*mu+b)-(e*mu +b)-LogFactorial(x)+y*TMath::Log(tau*b)-tau*b-LogFactorial(y) + TMath::Log(TMath::Factorial(m)) - TMath::Log(TMath::Factorial(m-z)) - TMath::Log(TMath::Factorial(z))+ z * TMath::Log(e) + (m-z)*TMath::Log(1-e));
|
---|
415 | }
|
---|
416 |
|
---|
417 | //________________________________________________________________________
|
---|
418 | void MRolke::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)
|
---|
419 | {
|
---|
420 | // Void needed to calculate estimates of efficiency and background for model 1
|
---|
421 |
|
---|
422 | Double_t med = 0.0,fmid;
|
---|
423 | Int_t maxiter =1000;
|
---|
424 | Double_t acc = 0.00001;
|
---|
425 | Double_t emin = ((m+mu*tau)-TMath::Sqrt((m+mu*tau)*(m+mu*tau)-4 * mu* tau * z))/2/mu/tau;
|
---|
426 |
|
---|
427 | Double_t low = TMath::Max(1e-10,emin+1e-10);
|
---|
428 | Double_t high = 1 - 1e-10;
|
---|
429 |
|
---|
430 | for(Int_t i = 0; i < maxiter; i++) {
|
---|
431 | med = (low+high)/2.;
|
---|
432 |
|
---|
433 | fmid = LikeGradMod1(med,mu,x,y,z,tau,m);
|
---|
434 |
|
---|
435 | if(high < 0.5) acc = 0.00001*high;
|
---|
436 | else acc = 0.00001*(1-high);
|
---|
437 |
|
---|
438 | if ((high - low) < acc*high) break;
|
---|
439 |
|
---|
440 | if(fmid > 0) low = med;
|
---|
441 | else high = med;
|
---|
442 | }
|
---|
443 |
|
---|
444 | e = med;
|
---|
445 | Double_t eta = Double_t(z)/e -Double_t(m-z)/(1-e);
|
---|
446 |
|
---|
447 | b = Double_t(y)/(tau -eta/mu);
|
---|
448 | }
|
---|
449 |
|
---|
450 | //___________________________________________________________________________
|
---|
451 | Double_t MRolke::LikeGradMod1(Double_t e, Double_t mu, Int_t x,Int_t y,Int_t z,Double_t tau,Int_t m)
|
---|
452 | {
|
---|
453 | //gradient model
|
---|
454 | Double_t eta, etaprime, bprime,f;
|
---|
455 | eta = static_cast<double>(z)/e - static_cast<double>(m-z)/(1.0 - e);
|
---|
456 | etaprime = (-1) * (static_cast<double>(m-z)/((1.0 - e)*(1.0 - e)) + static_cast<double>(z)/(e*e));
|
---|
457 | Double_t b = y/(tau - eta/mu);
|
---|
458 | bprime = (b*b * etaprime)/mu/y;
|
---|
459 | f = (mu + bprime) * (x/(e * mu + b) - 1)+(y/b - tau) * bprime + eta;
|
---|
460 | return f;
|
---|
461 | }
|
---|
462 |
|
---|
463 | //___________________________________________________________________________
|
---|
464 | Double_t MRolke::EvalLikeMod2(Double_t mu, Int_t x, Int_t y, Double_t em, Double_t e,Double_t sde, Double_t tau, Double_t b, Int_t what)
|
---|
465 | {
|
---|
466 | // Calculates the Profile Likelihood for MODEL 2:
|
---|
467 | // Poisson background/ Gauss Efficiency
|
---|
468 | // what = 1: Maximum likelihood estimate is returned
|
---|
469 | // what = 2: Profile Likelihood of Maxmimum Likelihood estimate is returned.
|
---|
470 | // what = 3: Profile Likelihood of Test hypothesis is returned
|
---|
471 | // otherwise parameters as described in the beginning of the class)
|
---|
472 |
|
---|
473 | Double_t v = sde*sde;
|
---|
474 | Double_t coef[4],roots[3];
|
---|
475 | Double_t f = 0;
|
---|
476 |
|
---|
477 | if (what == 1) {
|
---|
478 | f = (x-y/tau)/em;
|
---|
479 | }
|
---|
480 |
|
---|
481 | if (what == 2) {
|
---|
482 | mu = (x-y/tau)/em;
|
---|
483 | b = y/tau;
|
---|
484 | e = em;
|
---|
485 | f = LikeMod2(mu,b,e,x,y,em,tau,v);
|
---|
486 | }
|
---|
487 |
|
---|
488 | if (what == 3) {
|
---|
489 | if (mu == 0 ) {
|
---|
490 | b = (x+y)/(1+tau);
|
---|
491 | f = LikeMod2(mu,b,e,x,y,em,tau,v);
|
---|
492 | } else {
|
---|
493 | coef[3] = mu;
|
---|
494 | coef[2] = mu*mu*v-2*em*mu-mu*mu*v*tau;
|
---|
495 | coef[1] = ( - x)*mu*v - mu*mu*mu*v*v*tau - mu*mu*v*em + em*mu*mu*v*tau + em*em*mu - y*mu*v;
|
---|
496 | coef[0] = x*mu*mu*v*v*tau + x*em*mu*v - y*mu*mu*v*v + y*em*mu*v;
|
---|
497 |
|
---|
498 | TMath::RootsCubic(coef,roots[0],roots[1],roots[2]);
|
---|
499 |
|
---|
500 | e = roots[1];
|
---|
501 | b = y/(tau + (em - e)/mu/v);
|
---|
502 | f = LikeMod2(mu,b,e,x,y,em,tau,v);
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | return f;
|
---|
507 | }
|
---|
508 |
|
---|
509 | //_________________________________________________________________________
|
---|
510 | Double_t MRolke::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)
|
---|
511 | {
|
---|
512 | // Profile Likelihood function for MODEL 2:
|
---|
513 | // Poisson background/Gauss Efficiency
|
---|
514 |
|
---|
515 | return 2*(x*TMath::Log(e*mu+b)-(e*mu+b)-LogFactorial(x)+y*TMath::Log(tau*b)-tau*b-LogFactorial(y)-0.9189385-TMath::Log(v)/2-(em-e)*(em-e)/v/2);
|
---|
516 | }
|
---|
517 |
|
---|
518 | //_____________________________________________________________________
|
---|
519 |
|
---|
520 | Double_t MRolke::EvalLikeMod3(Double_t mu, Int_t x, Double_t bm, Double_t em, Double_t e, Double_t sde, Double_t sdb, Double_t b, Int_t what)
|
---|
521 | {
|
---|
522 | // Calculates the Profile Likelihood for MODEL 3:
|
---|
523 | // Gauss background/ Gauss Efficiency
|
---|
524 | // what = 1: Maximum likelihood estimate is returned
|
---|
525 | // what = 2: Profile Likelihood of Maxmimum Likelihood estimate is returned.
|
---|
526 | // what = 3: Profile Likelihood of Test hypothesis is returned
|
---|
527 | // otherwise parameters as described in the beginning of the class)
|
---|
528 |
|
---|
529 | Double_t f = 0.;
|
---|
530 | Double_t v = sde*sde;
|
---|
531 | Double_t u = sdb*sdb;
|
---|
532 |
|
---|
533 | if (what == 1) {
|
---|
534 | f = (x-bm)/em;
|
---|
535 | }
|
---|
536 |
|
---|
537 |
|
---|
538 | if (what == 2) {
|
---|
539 | mu = (x-bm)/em;
|
---|
540 | b = bm;
|
---|
541 | e = em;
|
---|
542 | f = LikeMod3(mu,b,e,x,bm,em,u,v);
|
---|
543 | }
|
---|
544 |
|
---|
545 |
|
---|
546 | if(what == 3) {
|
---|
547 | if(mu == 0.0){
|
---|
548 | b = ((bm-u)+TMath::Sqrt((bm-u)*(bm-u)+4*x*u))/2.;
|
---|
549 | e = em;
|
---|
550 | f = LikeMod3(mu,b,e,x,bm,em,u,v);
|
---|
551 | } else {
|
---|
552 | Double_t temp[3];
|
---|
553 | temp[0] = mu*mu*v+u;
|
---|
554 | temp[1] = mu*mu*mu*v*v+mu*v*u-mu*mu*v*em+mu*v*bm-2*u*em;
|
---|
555 | temp[2] = mu*mu*v*v*bm-mu*v*u*em-mu*v*bm*em+u*em*em-mu*mu*v*v*x;
|
---|
556 | e = (-temp[1]+TMath::Sqrt(temp[1]*temp[1]-4*temp[0]*temp[2]))/2/temp[0];
|
---|
557 | b = bm-(u*(em-e))/v/mu;
|
---|
558 | f = LikeMod3(mu,b,e,x,bm,em,u,v);
|
---|
559 | }
|
---|
560 | }
|
---|
561 |
|
---|
562 | return f;
|
---|
563 | }
|
---|
564 |
|
---|
565 | //____________________________________________________________________
|
---|
566 | Double_t MRolke::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)
|
---|
567 | {
|
---|
568 | // Profile Likelihood function for MODEL 3:
|
---|
569 | // Gauss background/Gauss Efficiency
|
---|
570 |
|
---|
571 | return 2*(x * TMath::Log(e*mu+b)-(e*mu+b)-LogFactorial(x)-1.837877-TMath::Log(u)/2-(bm-b)*(bm-b)/u/2-TMath::Log(v)/2-(em-e)*(em-e)/v/2);
|
---|
572 | }
|
---|
573 |
|
---|
574 | //____________________________________________________________________
|
---|
575 | Double_t MRolke::EvalLikeMod4(Double_t mu, Int_t x, Int_t y, Double_t tau, Double_t b, Int_t what)
|
---|
576 | {
|
---|
577 | // Calculates the Profile Likelihood for MODEL 4:
|
---|
578 | // Poiss background/Efficiency known
|
---|
579 | // what = 1: Maximum likelihood estimate is returned
|
---|
580 | // what = 2: Profile Likelihood of Maxmimum Likelihood estimate is returned.
|
---|
581 | // what = 3: Profile Likelihood of Test hypothesis is returned
|
---|
582 | // otherwise parameters as described in the beginning of the class)
|
---|
583 |
|
---|
584 | Double_t f = 0.0;
|
---|
585 |
|
---|
586 | if (what == 1) f = x-y/tau;
|
---|
587 | if (what == 2) {
|
---|
588 | mu = x-y/tau;
|
---|
589 | b = Double_t(y)/tau;
|
---|
590 | f = LikeMod4(mu,b,x,y,tau);
|
---|
591 | }
|
---|
592 | if (what == 3) {
|
---|
593 | if (mu == 0.0) {
|
---|
594 | b = Double_t(x+y)/(1+tau);
|
---|
595 | f = LikeMod4(mu,b,x,y,tau);
|
---|
596 | } else {
|
---|
597 | b = (x+y-(1+tau)*mu+sqrt((x+y-(1+tau)*mu)*(x+y-(1+tau)*mu)+4*(1+tau)*y*mu))/2/(1+tau);
|
---|
598 | f = LikeMod4(mu,b,x,y,tau);
|
---|
599 | }
|
---|
600 | }
|
---|
601 | return f;
|
---|
602 | }
|
---|
603 |
|
---|
604 | //___________________________________________________________________
|
---|
605 | Double_t MRolke::LikeMod4(Double_t mu,Double_t b,Int_t x,Int_t y,Double_t tau)
|
---|
606 | {
|
---|
607 | // Profile Likelihood function for MODEL 4:
|
---|
608 | // Poiss background/Efficiency known
|
---|
609 |
|
---|
610 | return 2*(x*TMath::Log(mu+b)-(mu+b)-LogFactorial(x)+y*TMath::Log(tau*b)-tau*b-LogFactorial(y) );
|
---|
611 | }
|
---|
612 |
|
---|
613 | //___________________________________________________________________
|
---|
614 | Double_t MRolke::EvalLikeMod5(Double_t mu, Int_t x, Double_t bm, Double_t sdb, Double_t b, Int_t what)
|
---|
615 | {
|
---|
616 | // Calculates the Profile Likelihood for MODEL 5:
|
---|
617 | // Gauss background/Efficiency known
|
---|
618 | // what = 1: Maximum likelihood estimate is returned
|
---|
619 | // what = 2: Profile Likelihood of Maxmimum Likelihood estimate is returned.
|
---|
620 | // what = 3: Profile Likelihood of Test hypothesis is returned
|
---|
621 | // otherwise parameters as described in the beginning of the class)
|
---|
622 |
|
---|
623 | Double_t u=sdb*sdb;
|
---|
624 | Double_t f = 0;
|
---|
625 |
|
---|
626 | if(what == 1) {
|
---|
627 | f = x - bm;
|
---|
628 | }
|
---|
629 | if(what == 2) {
|
---|
630 | mu = x-bm;
|
---|
631 | b = bm;
|
---|
632 | f = LikeMod5(mu,b,x,bm,u);
|
---|
633 | }
|
---|
634 |
|
---|
635 | if (what == 3) {
|
---|
636 | b = ((bm-u-mu)+TMath::Sqrt((bm-u-mu)*(bm-u-mu)-4*(mu*u-mu*bm-u*x)))/2;
|
---|
637 | f = LikeMod5(mu,b,x,bm,u);
|
---|
638 | }
|
---|
639 | return f;
|
---|
640 | }
|
---|
641 |
|
---|
642 | //_______________________________________________________________________
|
---|
643 | Double_t MRolke::LikeMod5(Double_t mu,Double_t b,Int_t x,Double_t bm,Double_t u)
|
---|
644 | {
|
---|
645 | // Profile Likelihood function for MODEL 5:
|
---|
646 | // Gauss background/Efficiency known
|
---|
647 |
|
---|
648 | return 2*(x*TMath::Log(mu+b)-(mu + b)-LogFactorial(x)-0.9189385-TMath::Log(u)/2-((bm-b)*(bm-b))/u/2);
|
---|
649 | }
|
---|
650 |
|
---|
651 | //_______________________________________________________________________
|
---|
652 | Double_t MRolke::EvalLikeMod6(Double_t mu, Int_t x, Int_t z, Double_t e, Double_t b, Int_t m, Int_t what)
|
---|
653 | {
|
---|
654 | // Calculates the Profile Likelihood for MODEL 6:
|
---|
655 | // Gauss known/Efficiency binomial
|
---|
656 | // what = 1: Maximum likelihood estimate is returned
|
---|
657 | // what = 2: Profile Likelihood of Maxmimum Likelihood estimate is returned.
|
---|
658 | // what = 3: Profile Likelihood of Test hypothesis is returned
|
---|
659 | // otherwise parameters as described in the beginning of the class)
|
---|
660 |
|
---|
661 | Double_t coef[4],roots[3];
|
---|
662 | Double_t f = 0.;
|
---|
663 | Double_t zm = Double_t(z)/m;
|
---|
664 |
|
---|
665 | if(what==1){
|
---|
666 | f = (x-b)/zm;
|
---|
667 | }
|
---|
668 |
|
---|
669 | if(what==2){
|
---|
670 | mu = (x-b)/zm;
|
---|
671 | e = zm;
|
---|
672 | f = LikeMod6(mu,b,e,x,z,m);
|
---|
673 | }
|
---|
674 | if(what == 3){
|
---|
675 | if(mu==0){
|
---|
676 | e = zm;
|
---|
677 | } else {
|
---|
678 | coef[3] = mu*mu;
|
---|
679 | coef[2] = mu * b - mu * x - mu*mu - mu * m;
|
---|
680 | coef[1] = mu * x - mu * b + mu * z - m * b;
|
---|
681 | coef[0] = b * z;
|
---|
682 | TMath::RootsCubic(coef,roots[0],roots[1],roots[2]);
|
---|
683 | e = roots[1];
|
---|
684 | }
|
---|
685 | f =LikeMod6(mu,b,e,x,z,m);
|
---|
686 | }
|
---|
687 | return f;
|
---|
688 | }
|
---|
689 |
|
---|
690 | //_______________________________________________________________________
|
---|
691 | Double_t MRolke::LikeMod6(Double_t mu,Double_t b,Double_t e,Int_t x,Int_t z,Int_t m)
|
---|
692 | {
|
---|
693 | // Profile Likelihood function for MODEL 6:
|
---|
694 | // background known/ Efficiency binomial
|
---|
695 |
|
---|
696 | Double_t f = 0.0;
|
---|
697 |
|
---|
698 | if (z > 100 || m > 100) {
|
---|
699 | f = 2*(x*TMath::Log(e*mu+b)-(e*mu+b)-LogFactorial(x)+(m*TMath::Log(m) - m)-(z*TMath::Log(z) - z) - ((m-z)*TMath::Log(m-z) - m + z)+z*TMath::Log(e)+(m-z)*TMath::Log(1-e));
|
---|
700 | } else {
|
---|
701 | f = 2*(x*TMath::Log(e*mu+b)-(e*mu+b)-LogFactorial(x)+TMath::Log(TMath::Factorial(m))-TMath::Log(TMath::Factorial(z))-TMath::Log(TMath::Factorial(m-z))+z*TMath::Log(e)+(m-z)*TMath::Log(1-e));
|
---|
702 | }
|
---|
703 | return f;
|
---|
704 | }
|
---|
705 |
|
---|
706 |
|
---|
707 | //___________________________________________________________________________
|
---|
708 | Double_t MRolke::EvalLikeMod7(Double_t mu, Int_t x, Double_t em, Double_t e, Double_t sde, Double_t b, Int_t what)
|
---|
709 | {
|
---|
710 | // Calculates the Profile Likelihood for MODEL 7:
|
---|
711 | // background known/Efficiency Gauss
|
---|
712 | // what = 1: Maximum likelihood estimate is returned
|
---|
713 | // what = 2: Profile Likelihood of Maxmimum Likelihood estimate is returned.
|
---|
714 | // what = 3: Profile Likelihood of Test hypothesis is returned
|
---|
715 | // otherwise parameters as described in the beginning of the class)
|
---|
716 |
|
---|
717 | Double_t v=sde*sde;
|
---|
718 | Double_t f = 0.;
|
---|
719 |
|
---|
720 | if(what == 1) {
|
---|
721 | f = (x-b)/em;
|
---|
722 | }
|
---|
723 |
|
---|
724 | if(what == 2) {
|
---|
725 | mu = (x-b)/em;
|
---|
726 | e = em;
|
---|
727 | f = LikeMod7(mu, b, e, x, em, v);
|
---|
728 | }
|
---|
729 |
|
---|
730 | if(what == 3) {
|
---|
731 | if(mu==0) {
|
---|
732 | e = em;
|
---|
733 | } else {
|
---|
734 | e = ( -(mu*em-b-mu*mu*v)-TMath::Sqrt((mu*em-b-mu*mu*v)*(mu*em-b-mu*mu*v)+4*mu*(x*mu*v-mu*b*v + b * em)))/( - mu)/2;
|
---|
735 | }
|
---|
736 | f = LikeMod7(mu, b, e, x, em, v);
|
---|
737 | }
|
---|
738 |
|
---|
739 | return f;
|
---|
740 | }
|
---|
741 |
|
---|
742 | //___________________________________________________________________________
|
---|
743 | Double_t MRolke::LikeMod7(Double_t mu,Double_t b,Double_t e,Int_t x,Double_t em,Double_t v)
|
---|
744 | {
|
---|
745 | // Profile Likelihood function for MODEL 6:
|
---|
746 | // background known/ Efficiency binomial
|
---|
747 |
|
---|
748 | return 2*(x*TMath::Log(e*mu+b)-(e*mu + b)-LogFactorial(x)-0.9189385-TMath::Log(v)/2-(em-e)*(em-e)/v/2);
|
---|
749 | }
|
---|
750 |
|
---|
751 | //______________________________________________________________________
|
---|
752 | Double_t MRolke::EvalPolynomial(Double_t x, const Int_t coef[], Int_t N)
|
---|
753 | {
|
---|
754 | // evaluate polynomial
|
---|
755 |
|
---|
756 | const Int_t *p;
|
---|
757 | p = coef;
|
---|
758 | Double_t ans = *p++;
|
---|
759 | Int_t i = N;
|
---|
760 |
|
---|
761 | do
|
---|
762 | ans = ans * x + *p++;
|
---|
763 | while( --i );
|
---|
764 |
|
---|
765 | return ans;
|
---|
766 | }
|
---|
767 |
|
---|
768 | //______________________________________________________________________
|
---|
769 | Double_t MRolke::EvalMonomial(Double_t x, const Int_t coef[], Int_t N)
|
---|
770 | {
|
---|
771 | // evaluate mononomial
|
---|
772 |
|
---|
773 | Double_t ans;
|
---|
774 | const Int_t *p;
|
---|
775 |
|
---|
776 | p = coef;
|
---|
777 | ans = x + *p++;
|
---|
778 | Int_t i = N-1;
|
---|
779 |
|
---|
780 | do
|
---|
781 | ans = ans * x + *p++;
|
---|
782 | while( --i );
|
---|
783 |
|
---|
784 | return ans;
|
---|
785 | }
|
---|
786 | //--------------------------------------------------------------------------
|
---|
787 | //
|
---|
788 | // Uses Stirling-Wells formula: ln(N!) ~ N*ln(N) - N + 0.5*ln(2piN)
|
---|
789 | // if N exceeds 70, otherwise use the TMath functions
|
---|
790 | //
|
---|
791 | //
|
---|
792 | Double_t MRolke::LogFactorial(Int_t n)
|
---|
793 | {
|
---|
794 | if (n>69)
|
---|
795 | return n*TMath::Log(n)-n + 0.5*TMath::Log(TMath::TwoPi()*n);
|
---|
796 | else
|
---|
797 | return TMath::Log(TMath::Factorial(n));
|
---|
798 | }
|
---|