Logo ROOT   6.07/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 
22 #include "RooAbsReal.h"
23 
24 #ifndef RooStats_RooStatsUtils
25 #include "RooStats/RooStatsUtils.h"
26 #endif
27 
28 #include <limits>
29 #define NaN numeric_limits<float>::quiet_NaN()
30 #define IsNaN(a) TMath::IsNaN(a)
31 
33 
34 using namespace RooStats;
35 using namespace std;
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Default constructor
39 
41  TNamed(name,name),
42  fNullPValue(NaN), fAlternatePValue(NaN),
43  fNullPValueError(0), fAlternatePValueError(0),
44  fTestStatisticData(NaN),
45  fAllTestStatisticsData(NULL),
46  fNullDistr(NULL), fAltDistr(NULL),
47  fNullDetailedOutput(NULL), fAltDetailedOutput(NULL), fFitInfo(NULL),
48  fPValueIsRightTail(kTRUE),
49  fBackgroundIsAlt(kFALSE)
50 {
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Alternate constructor
55 
57  TNamed(name,name),
58  fNullPValue(nullp), fAlternatePValue(altp),
66 {
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// copy constructor
71 
73  TNamed(other),
82 {
83  this->Append( &other );
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Destructor
88 
90 {
91  if( fNullDistr ) delete fNullDistr;
92  if( fAltDistr ) delete fAltDistr;
93 
96 
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// assignment operator
102 
104  if (this == &other) return *this;
105  SetName(other.GetName());
106  SetTitle(other.GetTitle());
107  fNullPValue = other.fNullPValue;
112 
115  if( fNullDistr ) { delete fNullDistr; fNullDistr = NULL; }
116  if( fAltDistr ) { delete fAltDistr; fAltDistr = NULL; }
119  if (fFitInfo) { delete fFitInfo; fFitInfo = NULL; }
120 
123 
124  this->Append( &other );
125 
126  return *this;
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Add additional toy-MC experiments to the current results.
131 /// Use the data test statistics of the added object if it is not already
132 /// set (otherwise, ignore the new one).
133 
135  if(fNullDistr)
137  else
139 
140  if(fAltDistr)
141  fAltDistr->Add(other->GetAltDistribution());
142  else
144 
145 
146  if( fNullDetailedOutput ) {
148  }else{
150  }
151 
152  if( fAltDetailedOutput ) {
154  }else{
156  }
157 
158  if( fFitInfo ) {
159  if( other->GetFitInfo() ) fFitInfo->append( *other->GetFitInfo() );
160  }else{
161  if( other->GetFitInfo() ) fFitInfo = new RooDataSet( *other->GetFitInfo() );
162  }
163 
164  // if no data is present use the other HypoTestResult's data
166 
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 
174  fAltDistr = alt;
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 
181  fNullDistr = null;
183 }
184 
185 ////////////////////////////////////////////////////////////////////////////////
186 
188  fTestStatisticData = tsd;
189 
192 }
193 
194 ////////////////////////////////////////////////////////////////////////////////
195 
198  delete fAllTestStatisticsData;
200  }
201  if (tsd) fAllTestStatisticsData = (const RooArgList*)tsd->snapshot();
202 
205  if( firstTS ) SetTestStatisticData( firstTS->getVal() );
206  }
207 }
208 
209 ////////////////////////////////////////////////////////////////////////////////
210 
212  fPValueIsRightTail = pr;
213 
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 
221  return !IsNaN(fTestStatisticData);
222 }
223 
224 ////////////////////////////////////////////////////////////////////////////////
225 
227  // compute error on Null pvalue
228  return fNullPValueError;
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// compute \f$CL_{b}\f$ error
233 /// \f$CL_{b}\f$ = 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 \f$CL_{s}\f$ through combination of the
255 /// errors on \f$CL_{b}\f$ and \f$CL_{s+b}\f$:
256 /// \f[
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 /// \f]
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 /// updates the pvalue if sufficient data is available
278 
279 void HypoTestResult::UpdatePValue(const SamplingDistribution* distr, Double_t &pvalue, Double_t &perror, Bool_t /*isNull*/) {
280  if(IsNaN(fTestStatisticData)) return;
281  if(!distr) return;
282 
283  /* Got to be careful for discrete distributions:
284  * To get the right behaviour for limits, the p-value must
285  * include the value of fTestStatistic both for Alt and Null cases
286  */
287  if(fPValueIsRightTail) {
288  pvalue = distr->IntegralAndError(perror, fTestStatisticData, RooNumber::infinity(), kTRUE,
289  kTRUE , kTRUE ); // always closed interval [ fTestStatistic, inf ]
290 
291  }else{
292  pvalue = distr->IntegralAndError(perror, -RooNumber::infinity(), fTestStatisticData, kTRUE,
293  kTRUE, kTRUE ); // // always closed [ -inf, fTestStatistic ]
294  }
295 }
296 
297 ////////////////////////////////////////////////////////////////////////////////
298 /// Print out some information about the results
299 /// Note: use Alt/Null labels for the hypotheses here as the Null
300 /// might be the s+b hypothesis.
301 
303 {
304  bool fromToys = (fAltDistr || fNullDistr);
305 
306  std::cout << std::endl << "Results " << GetName() << ": " << endl;
307  std::cout << " - Null p-value = " << NullPValue();
308  if (fromToys) std::cout << " +/- " << NullPValueError();
309  std::cout << std::endl;
310  std::cout << " - Significance = " << Significance();
311  if (fromToys) std::cout << " +/- " << SignificanceError() << " sigma";
312  std::cout << std::endl;
313  if(fAltDistr)
314  std::cout << " - Number of Alt toys: " << fAltDistr->GetSize() << std::endl;
315  if(fNullDistr)
316  std::cout << " - Number of Null toys: " << fNullDistr->GetSize() << std::endl;
317 
318  if (HasTestStatisticData() ) std::cout << " - Test statistic evaluated on data: " << fTestStatisticData << std::endl;
319  std::cout << " - CL_b: " << CLb();
320  if (fromToys) std::cout << " +/- " << CLbError();
321  std::cout << std::endl;
322  std::cout << " - CL_s+b: " << CLsplusb();
323  if (fromToys) std::cout << " +/- " << CLsplusbError();
324  std::cout << std::endl;
325  std::cout << " - CL_s: " << CLs();
326  if (fromToys) std::cout << " +/- " << CLsError();
327  std::cout << std::endl;
328 
329  return;
330 }
331 
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
is simply (not a method, but a quantity)
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
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
Print out some information about the results Note: use Alt/Null labels for the hypotheses here as the...
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)
Namespace for the RooStats classes.
Definition: Asimov.h:20
SamplingDistribution * fNullDistr
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
void append(RooDataSet &data)
Add all data points of given data set to this data set.
SamplingDistribution * GetNullDistribution(void) const
#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="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
char name[80]
Definition: TGX11.cxx:109
void SetNullDistribution(SamplingDistribution *null)
Double_t CLsError() const
The error on the ratio .
Bool_t GetBackGroundIsAlt(void) const