Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/** \class RooStats::HybridResult
17 \ingroup Roostats
18
19Class encapsulating the result of the HybridCalculatorOriginal.
20This class is a fresh rewrite in RooStats of
21RooStatsCms/LimitResults developed by D. Piparo and G. Schott
22New contributions to this class have been written by Matthias Wolf (error estimation)
23
24The objects of this class store and access with lightweight methods the
25information calculated by LimitResults through a Lent calculation using
26MC toy experiments.
27In some ways can be considered an extended and extensible implementation of
28TConfidenceLevel.
29*/
30
31
32#include "RooDataHist.h"
33#include "RooDataSet.h"
34#include "RooGlobalFunc.h" // for RooFit::Extended()
35#include "RooMsgService.h"
36#include "RooRealVar.h"
37#include "RooAbsData.h"
38
40#include "RooStats/HybridPlot.h"
41
42#include <TMath.h>
43
44using namespace RooStats;
45
46////////////////////////////////////////////////////////////////////////////////
47/// Constructor
48
51 fTestStat_data(-999.),
52 fComputationsNulDoneFlag(false),
53 fComputationsAltDoneFlag(false),
54 fSumLargerValues(false)
55{
56 // HybridResult default constructor (with name )
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Constructor
61
63 const std::vector<double>& testStat_sb_vals,
64 const std::vector<double>& testStat_b_vals,
65 bool sumLargerValues ) :
67 fTestStat_data(-999.),
68 fComputationsNulDoneFlag(false),
69 fComputationsAltDoneFlag(false),
70 fSumLargerValues(sumLargerValues)
71{
72 // HybridResult constructor (with name, title and vectors of S+B and B values)
73
76
77 int vector_size_b = testStat_b_vals.size();
79
81 for (int i=0;i<vector_size_sb;++i)
82 fTestStat_sb.push_back(testStat_sb_vals[i]);
83
85 for (int i=0;i<vector_size_b;++i)
86 fTestStat_b.push_back(testStat_b_vals[i]);
87}
88
89
90////////////////////////////////////////////////////////////////////////////////
91/// HybridResult destructor
92
94{
95
96 fTestStat_sb.clear();
97 fTestStat_b.clear();
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// set the value of the test statistics on data
102
110
111////////////////////////////////////////////////////////////////////////////////
112/// Returns \f$1 - CL_{b}\f$ : the B p-value
113
115{
116 if (fComputationsNulDoneFlag==false) {
117 int nToys = fTestStat_b.size();
118 if (nToys==0) {
119 coutE(Eval) << "Error: no toy data present. Returning -1.\n";
120 return -1;
121 }
122
123 double larger_than_measured=0;
124 if (fSumLargerValues) {
125 for (int iToy=0;iToy<nToys;++iToy)
127 } else {
128 for (int iToy=0;iToy<nToys;++iToy)
130 }
131
132 if (larger_than_measured==0) coutW(Eval) << "Warning: CLb = 0 ... maybe more toys are needed!\n";
133
136 }
137
138 return fNullPValue;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Returns \f$CL_{s+b}\f$ : the S+B p-value
143
145{
146 if (fComputationsAltDoneFlag==false) {
147 int nToys = fTestStat_b.size();
148 if (nToys==0) {
149 coutE(Eval) << "Error: no toy data present. Returning -1.\n";
150 return -1;
151 }
152
153 double larger_than_measured=0;
154 if (fSumLargerValues) {
155 for (int iToy=0;iToy<nToys;++iToy)
157 } else {
158 for (int iToy=0;iToy<nToys;++iToy)
160 }
161
162 if (larger_than_measured==0) coutW(Eval) << "Warning: CLsb = 0 ... maybe more toys are needed!\n";
163
166 }
167
168 return fAlternatePValue;
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// Returns an estimate of the error on \f$CL_{b}\f$ assuming a binomial
173/// error on \f$CL_{b}\f$:
174/// \f[
175/// \sigma_{CL_{b}} = \sqrt{CL_{b} \left( 1 - CL_{b} \right) / n_{toys}}
176/// \f]
177
179{
180 unsigned const int n = fTestStat_b.size();
181 return std::sqrt(CLb() * (1. - CLb()) / n);
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Returns an estimate of the error on \f$CL_{s+b}\f$ assuming a binomial
186/// error on \f$CL_{s+b}\f$:
187/// \f[
188/// \sigma_{CL_{s+b}} = \sqrt{CL_{s+b} \left( 1 - CL_{s+b} \right) / n_{toys}}
189/// \f]
190
192{
193 unsigned const int n = fTestStat_sb.size();
194 return std::sqrt(CLsplusb() * (1. - CLsplusb()) / n);
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Returns an estimate of the error on \f$CL_{s}\f$ through combination
199/// of the errors on \f$CL_{b}\f$ and \f$CL_{s+b}\f$:
200/// \f[
201/// \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}
202/// \f]
203
205{
206 unsigned const int n_b = fTestStat_b.size();
207 unsigned const int n_sb = fTestStat_sb.size();
208
209 if (CLb() == 0 || CLsplusb() == 0)
210 return 0;
211
212 double cl_b_err = (1. - CLb()) / (n_b * CLb());
213 double cl_sb_err = (1. - CLsplusb()) / (n_sb * CLsplusb());
214
215 return CLs() * std::sqrt(cl_b_err + cl_sb_err);
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// add additional toy-MC experiments to the current results
220/// use the data test statistics of the added object if none is already present
221/// (otherwise, ignore the new one)
222
224{
225
226 int other_size_sb = other->GetTestStat_sb().size();
227 for (int i=0;i<other_size_sb;++i)
228 fTestStat_sb.push_back(other->GetTestStat_sb()[i]);
229
230 int other_size_b = other->GetTestStat_b().size();
231 for (int i=0;i<other_size_b;++i)
232 fTestStat_b.push_back(other->GetTestStat_b()[i]);
233
234 // if no data is present use the other's HybridResult's data
235 if (fTestStat_data==-999.)
236 fTestStat_data = other->GetTestStat_data();
237
240
241 return;
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// prepare a plot showing a result and return a pointer to a HybridPlot object
246/// the needed arguments are: an object name, a title and the number of bins in the plot
247
248HybridPlot* HybridResult::GetPlot(const char* name,const char* title, int n_bins)
249{
250 // default plot name
252 if ( TString(name)=="" ) {
253 plot_name += GetName();
254 plot_name += "_plot";
255 } else plot_name = name;
256
257 // default plot title
259 if ( TString(title)=="" ) {
260 plot_title += GetTitle();
261 plot_title += "_plot (";
262 plot_title += fTestStat_b.size();
263 plot_title += " toys)";
264 } else plot_title = title;
265
266 HybridPlot* plot = new HybridPlot( plot_name.Data(),
267 plot_title.Data(),
271 n_bins,
272 true );
273 return plot;
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Print out some information about the results
278
279void HybridResult::PrintMore(const char* /*options */)
280{
281 std::cout << "\nResults " << GetName() << ":\n"
282 << " - Number of S+B toys: " << fTestStat_b.size() << std::endl
283 << " - Number of B toys: " << fTestStat_sb.size() << std::endl
284 << " - test statistics evaluated on data: " << fTestStat_data << std::endl
285 << " - CL_b " << CLb() << std::endl
286 << " - CL_s+b " << CLsplusb() << std::endl
287 << " - CL_s " << CLs() << std::endl;
288
289 return;
290}
291
HybridPlot(const char *name, const char *title, const std::vector< double > &sb_values, const std::vector< double > &b_values, double testStat_data, int n_bins, bool verbosity=true)
Constructor.
#define coutW(a)
#define coutE(a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter char TVirtualGLPainter plot
char name[80]
Definition TGX11.cxx:145
This class provides the plots for the result of a study performed with the HybridCalculatorOriginal c...
Definition HybridPlot.h:36
Class encapsulating the result of the HybridCalculatorOriginal.
std::vector< double > fTestStat_b
~HybridResult() override
Destructor of HybridResult.
double AlternatePValue() const override
Returns : the S+B p-value.
void PrintMore(const char *options)
Print out some information about the results.
void Add(HybridResult *other)
add additional toy-MC experiments to the current results use the data test statistics of the added ob...
HybridPlot * GetPlot(const char *name, const char *title, int n_bins) R__DEPRECATED(6
prepare a plot showing a result and return a pointer to a HybridPlot object the needed arguments are:...
std::vector< double > fTestStat_sb
double CLsplusbError() const
The error on the "confidence level" of the alternative hypothesis.
double CLbError() const
The error on the "confidence level" of the null hypothesis.
void SetDataTestStatistics(double testStat_data_val)
set the value of the test statistics on data
HybridResult(const char *name=nullptr)
Default constructor.
double CLsError() const
The error on the ratio .
double NullPValue() const override
Returns : the B p-value.
HypoTestResult is a base class for results from hypothesis tests.
double fNullPValue
p-value for the null hypothesis (small number means disfavoured)
virtual double CLsplusb() const
Convert AlternatePValue into a "confidence level".
virtual double CLs() const
is simply (not a method, but a quantity)
double fAlternatePValue
p-value for the alternate hypothesis (small number means disfavoured)
virtual double CLb() const
Convert NullPValue into a "confidence level".
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
Basic string class.
Definition TString.h:138
const Int_t n
Definition legend1.C:16
Namespace for the RooStats classes.
Definition CodegenImpl.h:66