ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
24 #include "RooAbsReal.h"
25 
26 #ifndef RooStats_RooStatsUtils
27 #include "RooStats/RooStatsUtils.h"
28 #endif
29 
30 #include <limits>
31 #define NaN numeric_limits<float>::quiet_NaN()
32 #define IsNaN(a) TMath::IsNaN(a)
33 
35 
36 using namespace RooStats;
37 using namespace std;
38 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Default constructor
42 
44  TNamed(name,name),
45  fNullPValue(NaN), fAlternatePValue(NaN),
46  fNullPValueError(0), fAlternatePValueError(0),
47  fTestStatisticData(NaN),
48  fAllTestStatisticsData(NULL),
49  fNullDistr(NULL), fAltDistr(NULL),
50  fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
51  fPValueIsRightTail(kTRUE),
52  fBackgroundIsAlt(kFALSE)
53 {
54 }
55 
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Alternate constructor
59 
61  TNamed(name,name),
62  fNullPValue(nullp), fAlternatePValue(altp),
63  fNullPValueError(0), fAlternatePValueError(0),
64  fTestStatisticData(NaN),
65  fAllTestStatisticsData(NULL),
66  fNullDistr(NULL), fAltDistr(NULL),
67  fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
68  fPValueIsRightTail(kTRUE),
69  fBackgroundIsAlt(kFALSE)
70 {
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// copy constructor
75 
77  TNamed(other),
78  fNullPValue(NaN), fAlternatePValue(NaN),
79  fNullPValueError(0), fAlternatePValueError(0),
80  fTestStatisticData(NaN),
81  fAllTestStatisticsData(NULL),
82  fNullDistr(NULL), fAltDistr(NULL),
83  fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
84  fPValueIsRightTail( other.GetPValueIsRightTail() ),
85  fBackgroundIsAlt( other.GetBackGroundIsAlt() )
86 {
87  this->Append( &other );
88 }
89 
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// Destructor
93 
95 {
96  if( fNullDistr ) delete fNullDistr;
97  if( fAltDistr ) delete fAltDistr;
98 
101 
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// assignment operator
107 
109  if (this == &other) return *this;
110  SetName(other.GetName());
111  SetTitle(other.GetTitle());
112  fNullPValue = other.fNullPValue;
117 
120  if( fNullDistr ) delete fNullDistr; fNullDistr = NULL;
121  if( fAltDistr ) delete fAltDistr; fAltDistr = NULL;
124  if (fFitInfo) delete fFitInfo; fFitInfo = NULL;
125 
128 
129  this->Append( &other );
130 
131  return *this;
132 }
133 
134 
136  // Add additional toy-MC experiments to the current results.
137  // Use the data test statistics of the added object if it is not already
138  // set (otherwise, ignore the new one).
139 
140  if(fNullDistr)
142  else
144 
145  if(fAltDistr)
146  fAltDistr->Add(other->GetAltDistribution());
147  else
149 
150 
151  if( fNullDetailedOutput ) {
153  }else{
155  }
156 
157  if( fAltDetailedOutput ) {
159  }else{
161  }
162 
163  if( fFitInfo ) {
164  if( other->GetFitInfo() ) fFitInfo->append( *other->GetFitInfo() );
165  }else{
166  if( other->GetFitInfo() ) fFitInfo = new RooDataSet( *other->GetFitInfo() );
167  }
168 
169  // if no data is present use the other HypoTestResult's data
171 
174 }
175 
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 
180  fAltDistr = alt;
182 }
183 ////////////////////////////////////////////////////////////////////////////////
184 
186  fNullDistr = null;
188 }
189 ////////////////////////////////////////////////////////////////////////////////
190 
192  fTestStatisticData = tsd;
193 
196 }
197 ////////////////////////////////////////////////////////////////////////////////
198 
200  if (fAllTestStatisticsData) {
201  delete fAllTestStatisticsData;
203  }
204  if (tsd) fAllTestStatisticsData = (const RooArgList*)tsd->snapshot();
205 
208  if( firstTS ) SetTestStatisticData( firstTS->getVal() );
209  }
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 
215  fPValueIsRightTail = pr;
216 
219 }
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 
224  return !IsNaN(fTestStatisticData);
225 }
226 
228  // compute error on Null pvalue
229  return fNullPValueError;
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// compute CLb error
234 /// Clb = 1 - NullPValue()
235 /// must use opposite condition that routine above
236 
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Taylor expansion series approximation for standard deviation (error propagation)
249 
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Returns an estimate of the error on CLs through combination of the
256 /// errors on CLb and CLsplusb:
257 /// BEGIN_LATEX
258 /// #sigma_{CL_s} = CL_s
259 /// #sqrt{#left( #frac{#sigma_{CL_{s+b}}}{CL_{s+b}} #right)^2 + #left( #frac{#sigma_{CL_{b}}}{CL_{b}} #right)^2}
260 /// END_LATEX
261 
263  if(!fAltDistr || !fNullDistr) return 0.0;
264 
265  // unsigned const int n_b = fNullDistr->GetSamplingDistribution().size();
266  // unsigned const int n_sb = fAltDistr->GetSamplingDistribution().size();
267 
268  // if CLb() == 0 CLs = -1 so return a -1 error
269  if (CLb() == 0 ) return -1;
270 
271  double cl_b_err2 = pow(CLbError(),2);
272  double cl_sb_err2 = pow(CLsplusbError(),2);
273 
274  return TMath::Sqrt(cl_sb_err2 + cl_b_err2 * pow(CLs(),2))/CLb();
275 }
276 
277 
278 
279 // private
280 ////////////////////////////////////////////////////////////////////////////////
281 /// updates the pvalue if sufficient data is available
282 
284  if(IsNaN(fTestStatisticData)) return;
285  if(!distr) return;
286 
287  /* Got to be careful for discrete distributions:
288  * To get the right behaviour for limits, the p-value must
289  * include the value of fTestStatistic both for Alt and Null cases
290  */
291  if(fPValueIsRightTail) {
292  pvalue = distr->IntegralAndError(perror, fTestStatisticData, RooNumber::infinity(), kTRUE,
293  kTRUE , kTRUE ); // always closed interval [ fTestStatistic, inf ]
294 
295  }else{
296  pvalue = distr->IntegralAndError(perror, -RooNumber::infinity(), fTestStatisticData, kTRUE,
297  kTRUE, kTRUE ); // // always closed [ -inf, fTestStatistic ]
298  }
299 }
300 
302 {
303  // Print out some information about the results
304  // Note: use Alt/Null labels for the hypotheses here as the Null
305  // might be the s+b hypothesis.
306 
307  bool fromToys = (fAltDistr || fNullDistr);
308 
309  std::cout << std::endl << "Results " << GetName() << ": " << endl;
310  std::cout << " - Null p-value = " << NullPValue();
311  if (fromToys) std::cout << " +/- " << NullPValueError();
312  std::cout << std::endl;
313  std::cout << " - Significance = " << Significance();
314  if (fromToys) std::cout << " +/- " << SignificanceError() << " sigma";
315  std::cout << std::endl;
316  if(fAltDistr)
317  std::cout << " - Number of Alt toys: " << fAltDistr->GetSize() << std::endl;
318  if(fNullDistr)
319  std::cout << " - Number of Null toys: " << fNullDistr->GetSize() << std::endl;
320 
321  if (HasTestStatisticData() ) std::cout << " - Test statistic evaluated on data: " << fTestStatisticData << std::endl;
322  std::cout << " - CL_b: " << CLb();
323  if (fromToys) std::cout << " +/- " << CLbError();
324  std::cout << std::endl;
325  std::cout << " - CL_s+b: " << CLsplusb();
326  if (fromToys) std::cout << " +/- " << CLsplusbError();
327  std::cout << std::endl;
328  std::cout << " - CL_s: " << CLs();
329  if (fromToys) std::cout << " +/- " << CLsError();
330  std::cout << std::endl;
331 
332  return;
333 }
334 
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
Int_t GetSize() const
size of samples
virtual Double_t CLsplusb() const
Convert AlternatePValue into a "confidence level".
double distr(double *x, double *p)
Definition: unuranDemo.C:104
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.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
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:49
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
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
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)
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