Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/** \class TFeldmanCousins
14 \legacy{TFeldmanCousins, Consider switching to RooStats for non-trivial cases.}
15 \ingroup Physics
16
17Class to calculate the CL upper limit using
18the Feldman-Cousins method as described in PRD V57 #7, p3873-3889
19
20The default confidence interval calculated using this method is 90%
21This is set either by having a default the constructor, or using the
22appropriate fraction when instantiating an object of this class (e.g. 0.9)
23
24The simple extension to a gaussian resolution function bounded at zero
25has not been addressed as yet -> `time is of the essence' as they write
26on the wall of the maze in that classic game ...
27
28#### VARIABLES THAT CAN BE ALTERED
29=> depending on your desired precision: The initial values of fMuMin,
30fMuMax, fMuStep and fNMax are those used in the PRD:
31~~~ {.cpp}
32 fMuMin = 0.0
33 fMuMax = 50.0
34 fMuStep= 0.005
35~~~
36but there is total flexibility in changing this should you desire.
37
38
39see example of use in $ROOTSYS/tutorials/math/FeldmanCousins.C
40
41see note about: "Should I use TRolke, TFeldmanCousins, TLimit?"
42 in the TRolke class description.
43
44\author: Adrian Bevan, Liverpool University
45
46Copyright Liverpool University 2001 bevan@slac.stanford.edu
47*/
48
49#include <iostream>
50#include "TMath.h"
51#include "TFeldmanCousins.h"
52
54
55////////////////////////////////////////////////////////////////////////////////
56/// Constructor.
57
59{
60 fCL = newFC;
61 fUpperLimit = 0.0;
62 fLowerLimit = 0.0;
63 fNobserved = 0.0;
64 fNbackground = 0.0;
65 options.ToLower();
66 if (options.Contains("q")) fQUICK = 1;
67 else fQUICK = 0;
68
69 fNMax = 50;
70 fMuStep = 0.005;
71 SetMuMin();
72 SetMuMax();
73 SetMuStep();
74}
75
76
77////////////////////////////////////////////////////////////////////////////////
78// Destructor.
79
81{
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// given Nobserved and Nbackground, try different values of mu that give lower limits that
86/// are consistent with Nobserved. The closed interval (plus any stragglers) corresponds
87/// to the F&C interval
88
90{
91 CalculateUpperLimit(Nobserved, Nbackground);
92 return fLowerLimit;
93}
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// given Nobserved and Nbackground, try different values of mu that give upper limits that
98/// are consistent with Nobserved. The closed interval (plus any stragglers) corresponds
99/// to the F&C interval
100
102{
103 fNobserved = Nobserved;
104 fNbackground = Nbackground;
105
106 Double_t mu = 0.0;
107
108 // for each mu construct the ranked table of probabilities and test the
109 // observed number of events with the upper limit
110 Double_t min = -999.0;
111 Double_t max = 0;
112 Int_t iLower = 0;
113
114 Int_t i;
115 for(i = 0; i <= fNMuStep; i++) {
116 mu = fMuMin + (Double_t)i*fMuStep;
117 Int_t goodChoice = FindLimitsFromTable( mu );
118 if( goodChoice ) {
119 min = mu;
120 iLower = i;
121 break;
122 }
123 }
124
125 //==================================================================
126 // For quicker evaluation, assume that you get the same results when
127 // you expect the upper limit to be > Nobserved-Nbackground.
128 // This is certainly true for all of the published tables in the PRD
129 // and is a reasonable assumption in any case.
130 //==================================================================
131
132 Double_t quickJump = 0.0;
133 if (fQUICK) quickJump = Nobserved-Nbackground-fMuMin;
134 if (quickJump < 0.0) quickJump = 0.0;
135
136 for(i = iLower+1; i <= fNMuStep; i++) {
137 mu = fMuMin + (Double_t)i*fMuStep + quickJump;
138 Int_t goodChoice = FindLimitsFromTable( mu );
139 if( !goodChoice ) {
140 max = mu;
141 break;
142 }
143 }
144
145 fUpperLimit = max;
146 fLowerLimit = min;
147
148 return max;
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// calculate the probability table for a given mu for n = 0, NMAX
153/// and return 1 if the number of observed events is consistent
154/// with the CL bad
155
157{
158 Double_t *p = new Double_t[fNMax]; //the array of probabilities in the interval MUMIN-MUMAX
159 Double_t *r = new Double_t[fNMax]; //the ratio of likliehoods = P(Mu|Nobserved)/P(MuBest|Nobserved)
160 Int_t *rank = new Int_t[fNMax]; //the ranked array corresponding to R (largest first)
161 Double_t *muBest = new Double_t[fNMax];
162 Double_t *probMuBest = new Double_t[fNMax];
163
164 //calculate P(i | mu) and P(i | mu)/P(i | mubest)
165 Int_t i;
166 for(i = 0; i < fNMax; i++) {
167 muBest[i] = (Double_t)(i - fNbackground);
168 if(muBest[i]<0.0) muBest[i] = 0.0;
169 probMuBest[i] = Prob(i, muBest[i], fNbackground);
170 p[i] = Prob(i, mu, fNbackground);
171 if(probMuBest[i] == 0.0) r[i] = 0.0;
172 else r[i] = p[i]/probMuBest[i];
173 }
174
175 //rank the likelihood ratio
176 TMath::Sort(fNMax, r, rank);
177
178 //search through the probability table and get the i for the CL
179 Double_t sum = 0.0;
180 Int_t iMax = rank[0];
181 Int_t iMin = rank[0];
182 for(i = 0; i < fNMax; i++) {
183 sum += p[rank[i]];
184 if(iMax < rank[i]) iMax = rank[i];
185 if(iMin > rank[i]) iMin = rank[i];
186 if(sum >= fCL) break;
187 }
188
189 delete [] p;
190 delete [] r;
191 delete [] rank;
192 delete [] muBest;
193 delete [] probMuBest;
194
195 if((fNobserved <= iMax) && (fNobserved >= iMin)) return 1;
196 else return 0;
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Calculate the poissonian probability for a mean of mu+B events with a variance of N.
201
203{
204 return TMath::Poisson( N, mu+B);
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// Set maximum value of signal to use in calculating the tables.
209
211{
212 fMuMax = newMax;
213 fNMax = (Int_t)newMax;
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Set the step in signal to use when generating tables.
219
221{
222 if(newMuStep == 0.0) {
223 std::cout << "TFeldmanCousins::SetMuStep ERROR New step size is zero - unable to change value"<< std::endl;
224 return;
225 } else {
226 fMuStep = newMuStep;
228 }
229}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
#define ClassImp(name)
Definition Rtypes.h:377
#define N
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
<div class="legacybox"><h2>Legacy Code</h2> TFeldmanCousins is a legacy interface: there will be no b...
void SetMuMin(Double_t newMin=0.0)
Double_t CalculateLowerLimit(Double_t Nobserved, Double_t Nbackground)
given Nobserved and Nbackground, try different values of mu that give lower limits that are consisten...
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.
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 observed...
void SetMuStep(Double_t newMuStep=0.005)
Set the step in signal to use when generating tables.
void SetMuMax(Double_t newMax=50.0)
Set maximum value of signal to use in calculating the tables.
Double_t CalculateUpperLimit(Double_t Nobserved, Double_t Nbackground)
given Nobserved and Nbackground, try different values of mu that give upper limits that are consisten...
TFeldmanCousins(Double_t newCL=0.9, TString options="")
Constructor.
~TFeldmanCousins() override
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Double_t Poisson(Double_t x, Double_t par)
Computes the Poisson distribution function for (x,par).
Definition TMath.cxx:587
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Sort the n elements of the array a of generic templated type Element.
Definition TMathBase.h:431
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345