ROOT  6.06/09
Reference Guide
HypoTestResult.cxx
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke, Sven Kreiss
3 /*************************************************************************
4  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 /*****************************************************************************
12  * Project: RooStats
13  * Package: RooFit/RooStats
14  * @(#)root/roofit/roostats:$Id$
15  * Authors:
16  * Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke, Sven Kreiss
17  *
18  *****************************************************************************/
19 
20 
21 
23 #include "RooAbsReal.h"
24 
25 #ifndef RooStats_RooStatsUtils
26 #include "RooStats/RooStatsUtils.h"
27 #endif
28 
29 #include <limits>
30 #define NaN numeric_limits<float>::quiet_NaN()
31 #define IsNaN(a) TMath::IsNaN(a)
32 
34 
35 using namespace RooStats;
36 using namespace std;
37 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Default constructor
41 
43  TNamed(name,name),
44  fNullPValue(NaN), fAlternatePValue(NaN),
45  fNullPValueError(0), fAlternatePValueError(0),
46  fTestStatisticData(NaN),
47  fAllTestStatisticsData(NULL),
48  fNullDistr(NULL), fAltDistr(NULL),
49  fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
50  fPValueIsRightTail(kTRUE),
51  fBackgroundIsAlt(kFALSE)
52 {
53 }
54 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Alternate constructor
58 
60  TNamed(name,name),
61  fNullPValue(nullp), fAlternatePValue(altp),
62  fNullPValueError(0), fAlternatePValueError(0),
63  fTestStatisticData(NaN),
64  fAllTestStatisticsData(NULL),
65  fNullDistr(NULL), fAltDistr(NULL),
66  fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
67  fPValueIsRightTail(kTRUE),
68  fBackgroundIsAlt(kFALSE)
69 {
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// copy constructor
74 
76  TNamed(other),
77  fNullPValue(NaN), fAlternatePValue(NaN),
78  fNullPValueError(0), fAlternatePValueError(0),
79  fTestStatisticData(NaN),
80  fAllTestStatisticsData(NULL),
81  fNullDistr(NULL), fAltDistr(NULL),
82  fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
83  fPValueIsRightTail( other.GetPValueIsRightTail() ),
84  fBackgroundIsAlt( other.GetBackGroundIsAlt() )
85 {
86  this->Append( &other );
87 }
88 
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Destructor
92 
94 {
95  if( fNullDistr ) delete fNullDistr;
96  if( fAltDistr ) delete fAltDistr;
97 
100 
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// assignment operator
106 
108  if (this == &other) return *this;
109  SetName(other.GetName());
110  SetTitle(other.GetTitle());
111  fNullPValue = other.fNullPValue;
116 
119  if( fNullDistr ) { delete fNullDistr; fNullDistr = NULL; }
120  if( fAltDistr ) { delete fAltDistr; fAltDistr = NULL; }
123  if (fFitInfo) { delete fFitInfo; fFitInfo = NULL; }
124 
127 
128  this->Append( &other );
129 
130  return *this;
131 }
132 
133 
135  // Add additional toy-MC experiments to the current results.
136  // Use the data test statistics of the added object if it is not already
137  // set (otherwise, ignore the new one).
138 
139  if(fNullDistr)
141  else
143 
144  if(fAltDistr)
145  fAltDistr->Add(other->GetAltDistribution());
146  else
148 
149 
150  if( fNullDetailedOutput ) {
152  }else{
154  }
155 
156  if( fAltDetailedOutput ) {
158  }else{
160  }
161 
162  if( fFitInfo ) {
163  if( other->GetFitInfo() ) fFitInfo->append( *other->GetFitInfo() );
164  }else{
165  if( other->GetFitInfo() ) fFitInfo = new RooDataSet( *other->GetFitInfo() );
166  }
167 
168  // if no data is present use the other HypoTestResult's data
170 
173 }
174 
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 
179  fAltDistr = alt;
181 }
182 ////////////////////////////////////////////////////////////////////////////////
183 
185  fNullDistr = null;
187 }
188 ////////////////////////////////////////////////////////////////////////////////
189 
191  fTestStatisticData = tsd;
192 
195 }
196 ////////////////////////////////////////////////////////////////////////////////
197 
199  if (fAllTestStatisticsData) {
200  delete fAllTestStatisticsData;
202  }
203  if (tsd) fAllTestStatisticsData = (const RooArgList*)tsd->snapshot();
204 
207  if( firstTS ) SetTestStatisticData( firstTS->getVal() );
208  }
209 }
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 
214  fPValueIsRightTail = pr;
215 
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 
223  return !IsNaN(fTestStatisticData);
224 }
225 
227  // compute error on Null pvalue
228  return fNullPValueError;
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// compute CLb error
233 /// Clb = 1 - NullPValue()
234 /// must use opposite condition that routine above
235 
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 
244 }
245 
246 ////////////////////////////////////////////////////////////////////////////////
247 /// Taylor expansion series approximation for standard deviation (error propagation)
248 
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Returns an estimate of the error on CLs through combination of the
255 /// errors on CLb and CLsplusb:
256 /// BEGIN_LATEX
257 /// #sigma_{CL_s} = CL_s
258 /// #sqrt{#left( #frac{#sigma_{CL_{s+b}}}{CL_{s+b}} #right)^2 + #left( #frac{#sigma_{CL_{b}}}{CL_{b}} #right)^2}
259 /// END_LATEX
260 
262  if(!fAltDistr || !fNullDistr) return 0.0;
263 
264  // unsigned const int n_b = fNullDistr->GetSamplingDistribution().size();
265  // unsigned const int n_sb = fAltDistr->GetSamplingDistribution().size();
266 
267  // if CLb() == 0 CLs = -1 so return a -1 error
268  if (CLb() == 0 ) return -1;
269 
270  double cl_b_err2 = pow(CLbError(),2);
271  double cl_sb_err2 = pow(CLsplusbError(),2);
272 
273  return TMath::Sqrt(cl_sb_err2 + cl_b_err2 * pow(CLs(),2))/CLb();
274 }
275 
276 
277 
278 // private
279 ////////////////////////////////////////////////////////////////////////////////
280 /// updates the pvalue if sufficient data is available
281 
282 void HypoTestResult::UpdatePValue(const SamplingDistribution* distr, Double_t &pvalue, Double_t &perror, Bool_t /*isNull*/) {
283  if(IsNaN(fTestStatisticData)) return;
284  if(!distr) return;
285 
286  /* Got to be careful for discrete distributions:
287  * To get the right behaviour for limits, the p-value must
288  * include the value of fTestStatistic both for Alt and Null cases
289  */
290  if(fPValueIsRightTail) {
291  pvalue = distr->IntegralAndError(perror, fTestStatisticData, RooNumber::infinity(), kTRUE,
292  kTRUE , kTRUE ); // always closed interval [ fTestStatistic, inf ]
293 
294  }else{
295  pvalue = distr->IntegralAndError(perror, -RooNumber::infinity(), fTestStatisticData, kTRUE,
296  kTRUE, kTRUE ); // // always closed [ -inf, fTestStatistic ]
297  }
298 }
299 
301 {
302  // Print out some information about the results
303  // Note: use Alt/Null labels for the hypotheses here as the Null
304  // might be the s+b hypothesis.
305 
306  bool fromToys = (fAltDistr || fNullDistr);
307 
308  std::cout << std::endl << "Results " << GetName() << ": " << endl;
309  std::cout << " - Null p-value = " << NullPValue();
310  if (fromToys) std::cout << " +/- " << NullPValueError();
311  std::cout << std::endl;
312  std::cout << " - Significance = " << Significance();
313  if (fromToys) std::cout << " +/- " << SignificanceError() << " sigma";
314  std::cout << std::endl;
315  if(fAltDistr)
316  std::cout << " - Number of Alt toys: " << fAltDistr->GetSize() << std::endl;
317  if(fNullDistr)
318  std::cout << " - Number of Null toys: " << fNullDistr->GetSize() << std::endl;
319 
320  if (HasTestStatisticData() ) std::cout << " - Test statistic evaluated on data: " << fTestStatisticData << std::endl;
321  std::cout << " - CL_b: " << CLb();
322  if (fromToys) std::cout << " +/- " << CLbError();
323  std::cout << std::endl;
324  std::cout << " - CL_s+b: " << CLsplusb();
325  if (fromToys) std::cout << " +/- " << CLsplusbError();
326  std::cout << std::endl;
327  std::cout << " - CL_s: " << CLs();
328  if (fromToys) std::cout << " +/- " << CLsError();
329  std::cout << std::endl;
330 
331  return;
332 }
333 
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
void SetAltDistribution(SamplingDistribution *alt)
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
Double_t CLbError() const
The error on the "confidence level" of the null hypothesis.
Double_t IntegralAndError(Double_t &error, Double_t low, Double_t high, Bool_t normalize=kTRUE, Bool_t lowClosed=kTRUE, Bool_t highClosed=kFALSE) const
numerical integral in these limits including error estimation
RooDataSet * GetFitInfo(void) const
const char Option_t
Definition: RtypesCore.h:62
const RooArgList * fAllTestStatisticsData
virtual Double_t CLs() const
CLs is simply CLs+b/CLb (not a method, but a quantity)
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
HypoTestResult is a base class for results from hypothesis tests.
HypoTestResult & operator=(const HypoTestResult &other)
assignment operator
RooDataSet * GetNullDetailedOutput(void) const
RooDataSet * fNullDetailedOutput
Double_t SignificanceError() const
The error on the significance, computed from NullPValueError via error propagation.
void UpdatePValue(const SamplingDistribution *distr, Double_t &pvalue, Double_t &perror, Bool_t pIsRightTail)
updates the pvalue if sufficient data is available
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
SamplingDistribution * GetAltDistribution(void) const
STL namespace.
Int_t GetSize() const
size of samples
virtual Double_t CLsplusb() const
Convert AlternatePValue into a "confidence level".
double normal_pdf(double x, double sigma=1, double x0=0)
Probability density function of the normal (Gaussian) distribution.
null_t< F > null()
RooDataSet * GetAltDetailedOutput(void) const
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
void Print(const Option_t *="") const
double pow(double, double)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
virtual Double_t NullPValue() const
Return p-value for null hypothesis.
void SetAllTestStatisticsData(const RooArgList *tsd)
virtual Double_t CLb() const
Convert NullPValue into a "confidence level".
virtual ~HypoTestResult()
destructor
Double_t NullPValueError() const
The error on the Null p-value.
SamplingDistribution * fAltDistr
#define IsNaN(a)
static Double_t infinity()
Return internal infinity representation.
Definition: RooNumber.cxx:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual Double_t Significance() const
familiar name for the Null p-value in terms of 1-sided Gaussian significance
void Add(const SamplingDistribution *other)
merge two sampling distributions
Bool_t HasTestStatisticData(void) const
Bool_t GetPValueIsRightTail(void) const
void SetTestStatisticData(const Double_t tsd)
This class simply holds a sampling distribution of some test statistic.
HypoTestResult(const char *name=0)
default constructor
virtual void Append(const HypoTestResult *other)
add values from another HypoTestResult
void SetPValueIsRightTail(Bool_t pr)
Namespace for the RooStats classes.
Definition: Asimov.h:20
SamplingDistribution * fNullDistr
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
double Double_t
Definition: RtypesCore.h:55
ClassImp(RooStats::HypoTestResult)
void append(RooDataSet &data)
Add all data points of given data set to this data set.
SamplingDistribution * GetNullDistribution(void) const
#define name(a, b)
Definition: linkTestLib0.cpp:5
#define NULL
Definition: Rtypes.h:82
RooDataSet * fAltDetailedOutput
Double_t CLsplusbError() const
The error on the "confidence level" of the alternative hypothesis.
Double_t GetTestStatisticData(void) const
Int_t getSize() const
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
#define NaN
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
void SetNullDistribution(SamplingDistribution *null)
Double_t CLsError() const
The error on the ratio CLs+b/CLb.
Bool_t GetBackGroundIsAlt(void) const