ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HybridResult.cxx
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 
3 /*************************************************************************
4  * Project: RooStats *
5  * Package: RooFit/RooStats *
6  * Authors: *
7  * Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke *
8  *************************************************************************
9  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 ////////////////////////////////////////////////////////////////////////////////
17 
18 
19 
20 #include "RooDataHist.h"
21 #include "RooDataSet.h"
22 #include "RooGlobalFunc.h" // for RooFit::Extended()
23 #include "RooNLLVar.h"
24 #include "RooRealVar.h"
25 #include "RooAbsData.h"
26 
27 #include "RooStats/HybridResult.h"
28 #include "RooStats/HybridPlot.h"
29 
30 
31 /// ClassImp for building the THtml documentation of the class
32 using namespace std;
33 
35 
36 using namespace RooStats;
37 
38 ///////////////////////////////////////////////////////////////////////////
39 
40 HybridResult::HybridResult( const char *name) :
41  HypoTestResult(name),
42  fTestStat_data(-999.),
43  fComputationsNulDoneFlag(false),
44  fComputationsAltDoneFlag(false),
45  fSumLargerValues(false)
46 {
47  // HybridResult default constructor (with name )
48 }
49 
50 ///////////////////////////////////////////////////////////////////////////
51 
52 HybridResult::HybridResult( const char *name,
53  const std::vector<double>& testStat_sb_vals,
54  const std::vector<double>& testStat_b_vals,
55  bool sumLargerValues ) :
56  HypoTestResult(name,0,0),
57  fTestStat_data(-999.),
58  fComputationsNulDoneFlag(false),
59  fComputationsAltDoneFlag(false),
60  fSumLargerValues(sumLargerValues)
61 {
62  // HybridResult constructor (with name, title and vectors of S+B and B values)
63 
64  int vector_size_sb = testStat_sb_vals.size();
65  assert(vector_size_sb>0);
66 
67  int vector_size_b = testStat_b_vals.size();
68  assert(vector_size_b>0);
69 
70  fTestStat_sb.reserve(vector_size_sb);
71  for (int i=0;i<vector_size_sb;++i)
72  fTestStat_sb.push_back(testStat_sb_vals[i]);
73 
74  fTestStat_b.reserve(vector_size_b);
75  for (int i=0;i<vector_size_b;++i)
76  fTestStat_b.push_back(testStat_b_vals[i]);
77 }
78 
79 
80 ///////////////////////////////////////////////////////////////////////////
81 
83 {
84  // HybridResult destructor
85 
86  fTestStat_sb.clear();
87  fTestStat_b.clear();
88 }
89 
90 ///////////////////////////////////////////////////////////////////////////
91 
92 void HybridResult::SetDataTestStatistics(double testStat_data_val)
93 {
94  // set the value of the test statistics on data
95 
98  fTestStat_data = testStat_data_val;
99  return;
100 }
101 
102 ///////////////////////////////////////////////////////////////////////////
103 
105 {
106  // return 1-CL_b : the B p-value
107 
108  if (fComputationsNulDoneFlag==false) {
109  int nToys = fTestStat_b.size();
110  if (nToys==0) {
111  std::cout << "Error: no toy data present. Returning -1.\n";
112  return -1;
113  }
114 
115  double larger_than_measured=0;
116  if (fSumLargerValues) {
117  for (int iToy=0;iToy<nToys;++iToy)
118  if ( fTestStat_b[iToy] >= fTestStat_data ) ++larger_than_measured;
119  } else {
120  for (int iToy=0;iToy<nToys;++iToy)
121  if ( fTestStat_b[iToy] <= fTestStat_data ) ++larger_than_measured;
122  }
123 
124  if (larger_than_measured==0) std::cout << "Warning: CLb = 0 ... maybe more toys are needed!\n";
125 
127  fNullPValue = 1-larger_than_measured/nToys;
128  }
129 
130  return fNullPValue;
131 }
132 
133 ///////////////////////////////////////////////////////////////////////////
134 
136 {
137  // return CL_s+b : the S+B p-value
138 
139  if (fComputationsAltDoneFlag==false) {
140  int nToys = fTestStat_b.size();
141  if (nToys==0) {
142  std::cout << "Error: no toy data present. Returning -1.\n";
143  return -1;
144  }
145 
146  double larger_than_measured=0;
147  if (fSumLargerValues) {
148  for (int iToy=0;iToy<nToys;++iToy)
149  if ( fTestStat_sb[iToy] >= fTestStat_data ) ++larger_than_measured;
150  } else {
151  for (int iToy=0;iToy<nToys;++iToy)
152  if ( fTestStat_sb[iToy] <= fTestStat_data ) ++larger_than_measured;
153  }
154 
155  if (larger_than_measured==0) std::cout << "Warning: CLsb = 0 ... maybe more toys are needed!\n";
156 
158  fAlternatePValue = larger_than_measured/nToys;
159  }
160 
161  return fAlternatePValue;
162 }
163 
164 ///////////////////////////////////////////////////////////////////////////
165 
167 {
168  // Returns an estimate of the error on CLb assuming a binomial error on
169  // CLb:
170  // BEGIN_LATEX
171  // #sigma_{CL_{b}} &=& #sqrt{CL_{b} #left( 1 - CL_{b} #right) / n_{toys}}
172  // END_LATEX
173  unsigned const int n = fTestStat_b.size();
174  return TMath::Sqrt(CLb() * (1. - CLb()) / n);
175 }
176 
177 ///////////////////////////////////////////////////////////////////////////
178 
180 {
181  // Returns an estimate of the error on CLsplusb assuming a binomial
182  // error on CLsplusb:
183  // BEGIN_LATEX
184  // #sigma_{CL_{s+b}} &=& #sqrt{CL_{s+b} #left( 1 - CL_{s+b} #right) / n_{toys}}
185  // END_LATEX
186  unsigned const int n = fTestStat_sb.size();
187  return TMath::Sqrt(CLsplusb() * (1. - CLsplusb()) / n);
188 }
189 
190 ///////////////////////////////////////////////////////////////////////////
191 
193 {
194  // Returns an estimate of the error on CLs through combination of the
195  // errors on CLb and CLsplusb:
196  // BEGIN_LATEX
197  // #sigma_{CL_s} &=& CL_s #sqrt{#left( #frac{#sigma_{CL_{s+b}}}{CL_{s+b}} #right)^2 + #left( #frac{#sigma_{CL_{b}}}{CL_{b}} #right)^2}
198  // END_LATEX
199  unsigned const int n_b = fTestStat_b.size();
200  unsigned const int n_sb = fTestStat_sb.size();
201 
202  if (CLb() == 0 || CLsplusb() == 0)
203  return 0;
204 
205  double cl_b_err = (1. - CLb()) / (n_b * CLb());
206  double cl_sb_err = (1. - CLsplusb()) / (n_sb * CLsplusb());
207 
208  return CLs() * TMath::Sqrt(cl_b_err + cl_sb_err);
209 }
210 
211 ///////////////////////////////////////////////////////////////////////////
212 
214 {
215  // add additional toy-MC experiments to the current results
216  // use the data test statistics of the added object if none is already present (otherwise, ignore the new one)
217 
218  int other_size_sb = other->GetTestStat_sb().size();
219  for (int i=0;i<other_size_sb;++i)
220  fTestStat_sb.push_back(other->GetTestStat_sb()[i]);
221 
222  int other_size_b = other->GetTestStat_b().size();
223  for (int i=0;i<other_size_b;++i)
224  fTestStat_b.push_back(other->GetTestStat_b()[i]);
225 
226  // if no data is present use the other's HybridResult's data
227  if (fTestStat_data==-999.)
228  fTestStat_data = other->GetTestStat_data();
229 
230  fComputationsAltDoneFlag = false;
231  fComputationsNulDoneFlag = false;
232 
233  return;
234 }
235 
236 ///////////////////////////////////////////////////////////////////////////
237 
238 HybridPlot* HybridResult::GetPlot(const char* name,const char* title, int n_bins)
239 {
240  // prepare a plot showing a result and return a pointer to a HybridPlot object
241  // the needed arguments are: an object name, a title and the number of bins in the plot
242 
243  // default plot name
244  TString plot_name;
245  if ( TString(name)=="" ) {
246  plot_name += GetName();
247  plot_name += "_plot";
248  } else plot_name = name;
249 
250  // default plot title
251  TString plot_title;
252  if ( TString(title)=="" ) {
253  plot_title += GetTitle();
254  plot_title += "_plot (";
255  plot_title += fTestStat_b.size();
256  plot_title += " toys)";
257  } else plot_title = title;
258 
259  HybridPlot* plot = new HybridPlot( plot_name.Data(),
260  plot_title.Data(),
261  fTestStat_sb,
262  fTestStat_b,
264  n_bins,
265  true );
266  return plot;
267 }
268 
269 ///////////////////////////////////////////////////////////////////////////
270 
271 void HybridResult::PrintMore(const char* /*options */)
272 {
273  // Print out some information about the results
274 
275  std::cout << "\nResults " << GetName() << ":\n"
276  << " - Number of S+B toys: " << fTestStat_b.size() << std::endl
277  << " - Number of B toys: " << fTestStat_sb.size() << std::endl
278  << " - test statistics evaluated on data: " << fTestStat_data << std::endl
279  << " - CL_b " << CLb() << std::endl
280  << " - CL_s+b " << CLsplusb() << std::endl
281  << " - CL_s " << CLs() << std::endl;
282 
283  return;
284 }
285 
286 
287 
288 
289 
290 
291 
292 
293 
294 
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
HybridPlot * GetPlot(const char *name, const char *title, int n_bins)
virtual Double_t CLs() const
CLs is simply CLs+b/CLb (not a method, but a quantity)
void Add(HybridResult *other)
#define assert(cond)
Definition: unittest.h:542
Basic string class.
Definition: TString.h:137
virtual ~HybridResult()
Destructor of HybridResult.
virtual Double_t CLsplusb() const
Convert AlternatePValue into a "confidence level".
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
Definition: TIterator.cxx:21
Double_t CLsplusbError() const
The error on the "confidence level" of the alternative hypothesis.
void SetDataTestStatistics(double testStat_data_val)
const char * Data() const
Definition: TString.h:349
void plot(TString fname="data.root", TString var0="var0", TString var1="var1")
Definition: createData.C:17
Double_t CLbError() const
The error on the "confidence level" of the null hypothesis.
Double_t NullPValue() const
Return p-value for null hypothesis.
This class provides the plots for the result of a study performed with the HybridCalculatorOriginal c...
Definition: HybridPlot.h:53
virtual Double_t CLb() const
Convert NullPValue into a "confidence level".
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
ClassImp(RooStats::HybridResult) using namespace RooStats
double Double_t
Definition: RtypesCore.h:55
double GetTestStat_data()
Get test statistics value for data.
Definition: HybridResult.h:74
std::vector< double > fTestStat_b
Definition: HybridResult.h:93
std::vector< double > GetTestStat_sb()
Get test statistics values for the sb model.
Definition: HybridResult.h:68
void PrintMore(const char *options)
#define name(a, b)
Definition: linkTestLib0.cpp:5
std::vector< double > GetTestStat_b()
Get test statistics values for the b model.
Definition: HybridResult.h:71
Double_t AlternatePValue() const
Return p-value for alternate hypothesis.
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
const Int_t n
Definition: legend1.C:16
Double_t CLsError() const
The error on the ratio CLs+b/CLb.
std::vector< double > fTestStat_sb
Definition: HybridResult.h:94