ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TFeldmanCousins.cxx
Go to the documentation of this file.
1 // @(#)root/physics:$Id$
2 // Author: Adrian Bevan 2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2001, Liverpool University. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 ////////////////////////////////////////////////////////////////////////////
14 // TFeldmanCousins
15 //
16 // class to calculate the CL upper limit using
17 // the Feldman-Cousins method as described in PRD V57 #7, p3873-3889
18 //
19 // The default confidence interval calvculated using this method is 90%
20 // This is set either by having a default the constructor, or using the
21 // appropriate fraction when instantiating an object of this class (e.g. 0.9)
22 //
23 // The simple extension to a gaussian resolution function bounded at zero
24 // has not been addressed as yet -> `time is of the essence' as they write
25 // on the wall of the maze in that classic game ...
26 //
27 // VARIABLES THAT CAN BE ALTERED
28 // -----------------------------
29 // => depending on your desired precision: The intial values of fMuMin,
30 // fMuMax, fMuStep and fNMax are those used in the PRD:
31 // fMuMin = 0.0
32 // fMuMax = 50.0
33 // fMuStep= 0.005
34 // but there is total flexibility in changing this should you desire.
35 //
36 //
37 // see example of use in $ROOTSYS/tutorials/math/FeldmanCousins.C
38 //
39 // see note about: "Should I use TRolke, TFeldmanCousins, TLimit?"
40 // in the TRolke class description.
41 //
42 // Author: Adrian Bevan, Liverpool University
43 //
44 // Copyright Liverpool University 2001 bevan@slac.stanford.edu
45 ///////////////////////////////////////////////////////////////////////////
46 
47 #include "Riostream.h"
48 #include "TMath.h"
49 #include "TFeldmanCousins.h"
50 
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 ///constructor
55 
57 {
58  fCL = newFC;
59  fUpperLimit = 0.0;
60  fLowerLimit = 0.0;
61  fNobserved = 0.0;
62  fNbackground = 0.0;
63  options.ToLower();
64  if (options.Contains("q")) fQUICK = 1;
65  else fQUICK = 0;
66 
67  fNMax = 50;
68  fMuStep = 0.005;
69  SetMuMin();
70  SetMuMax();
71  SetMuStep();
72 }
73 
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 
78 {
79 }
80 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /////////////////////////////////////////////////////////////////////////////////////////////
84 /// given Nobserved and Nbackground, try different values of mu that give lower limits that//
85 /// are consistent with Nobserved. The closed interval (plus any stragglers) corresponds //
86 /// to the F&C interval //
87 /////////////////////////////////////////////////////////////////////////////////////////////
88 
90 {
91  CalculateUpperLimit(Nobserved, Nbackground);
92  return fLowerLimit;
93 }
94 
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /////////////////////////////////////////////////////////////////////////////////////////////
98 /// given Nobserved and Nbackground, try different values of mu that give upper limits that//
99 /// are consistent with Nobserved. The closed interval (plus any stragglers) corresponds //
100 /// to the F&C interval //
101 /////////////////////////////////////////////////////////////////////////////////////////////
102 
104 {
105  fNobserved = Nobserved;
106  fNbackground = Nbackground;
107 
108  Double_t mu = 0.0;
109 
110  // for each mu construct the ranked table of probabilities and test the
111  // observed number of events with the upper limit
112  Double_t min = -999.0;
113  Double_t max = 0;
114  Int_t iLower = 0;
115 
116  Int_t i;
117  for(i = 0; i <= fNMuStep; i++) {
118  mu = fMuMin + (Double_t)i*fMuStep;
119  Int_t goodChoice = FindLimitsFromTable( mu );
120  if( goodChoice ) {
121  min = mu;
122  iLower = i;
123  break;
124  }
125  }
126 
127  //==================================================================
128  // For quicker evaluation, assume that you get the same results when
129  // you expect the uppper limit to be > Nobserved-Nbackground.
130  // This is certainly true for all of the published tables in the PRD
131  // and is a reasonable assumption in any case.
132  //==================================================================
133 
134  Double_t quickJump = 0.0;
135  if (fQUICK) quickJump = Nobserved-Nbackground-fMuMin;
136  if (quickJump < 0.0) quickJump = 0.0;
137 
138  for(i = iLower+1; i <= fNMuStep; i++) {
139  mu = fMuMin + (Double_t)i*fMuStep + quickJump;
140  Int_t goodChoice = FindLimitsFromTable( mu );
141  if( !goodChoice ) {
142  max = mu;
143  break;
144  }
145  }
146 
147  fUpperLimit = max;
148  fLowerLimit = min;
149 
150  return max;
151 }
152 
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 ////////////////////////////////////////////////////////////////////
156 /// calculate the probability table for a given mu for n = 0, NMAX//
157 /// and return 1 if the number of observed events is consistent //
158 /// with the CL bad //
159 ////////////////////////////////////////////////////////////////////
160 
162 {
163  Double_t *p = new Double_t[fNMax]; //the array of probabilities in the interval MUMIN-MUMAX
164  Double_t *r = new Double_t[fNMax]; //the ratio of likliehoods = P(Mu|Nobserved)/P(MuBest|Nobserved)
165  Int_t *rank = new Int_t[fNMax]; //the ranked array corresponding to R (largest first)
166  Double_t *muBest = new Double_t[fNMax];
167  Double_t *probMuBest = new Double_t[fNMax];
168 
169  //calculate P(i | mu) and P(i | mu)/P(i | mubest)
170  Int_t i;
171  for(i = 0; i < fNMax; i++) {
172  muBest[i] = (Double_t)(i - fNbackground);
173  if(muBest[i]<0.0) muBest[i] = 0.0;
174  probMuBest[i] = Prob(i, muBest[i], fNbackground);
175  p[i] = Prob(i, mu, fNbackground);
176  if(probMuBest[i] == 0.0) r[i] = 0.0;
177  else r[i] = p[i]/probMuBest[i];
178  }
179 
180  //rank the likelihood ratio
181  TMath::Sort(fNMax, r, rank);
182 
183  //search through the probability table and get the i for the CL
184  Double_t sum = 0.0;
185  Int_t iMax = rank[0];
186  Int_t iMin = rank[0];
187  for(i = 0; i < fNMax; i++) {
188  sum += p[rank[i]];
189  if(iMax < rank[i]) iMax = rank[i];
190  if(iMin > rank[i]) iMin = rank[i];
191  if(sum >= fCL) break;
192  }
193 
194  delete [] p;
195  delete [] r;
196  delete [] rank;
197  delete [] muBest;
198  delete [] probMuBest;
199 
200  if((fNobserved <= iMax) && (fNobserved >= iMin)) return 1;
201  else return 0;
202 }
203 
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /////////////////////////////////////////////////
207 /// calculate the poissonian probability for //
208 /// a mean of mu+B events with a variance of N //
209 /////////////////////////////////////////////////
210 
212 {
213  return TMath::Poisson( N, mu+B);
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 ///set maximum value of signal to use in calculating the tables
218 
220 {
221  fMuMax = newMax;
222  fNMax = (Int_t)newMax;
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 ///set the step in signal to use when generating tables
228 
230 {
231  if(newMuStep == 0.0) {
232  std::cout << "TFeldmanCousins::SetMuStep ERROR New step size is zero - unable to change value"<< std::endl;
233  return;
234  } else {
235  fMuStep = newMuStep;
237  }
238 }
static double B[]
void SetMuStep(Double_t newMuStep=0.005)
set the step in signal to use when generating tables
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
Double_t fNbackground
#define N
virtual ~TFeldmanCousins()
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMath.h:1002
ClassImp(TFeldmanCousins) TFeldmanCousins
constructor
ROOT::R::TRInterface & r
Definition: Object.C:4
Int_t FindLimitsFromTable(Double_t mu)
calculate the probability table for a given mu for n = 0, NMAX// and return 1 if the number of observ...
Double_t Poisson(Double_t x, Double_t par)
compute the Poisson distribution function for (x,par) The Poisson PDF is implemented by means of Eule...
Definition: TMath.cxx:564
Double_t Prob(Int_t N, Double_t mu, Double_t B)
calculate the poissonian probability for // a mean of mu+B events with a variance of N // ...
void SetMuMax(Double_t newMax=50.0)
set maximum value of signal to use in calculating the tables
double Double_t
Definition: RtypesCore.h:55
Double_t CalculateLowerLimit(Double_t Nobserved, Double_t Nbackground)
given Nobserved and Nbackground, try different values of mu that give lower limits that// are consist...
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
Double_t fLowerLimit
Double_t fUpperLimit
Double_t CalculateUpperLimit(Double_t Nobserved, Double_t Nbackground)
given Nobserved and Nbackground, try different values of mu that give upper limits that// are consist...