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 "RooRealVar.h"
36#include "RooAbsData.h"
37
39#include "RooStats/HybridPlot.h"
40
41#include <TMath.h>
42
43/// ClassImp for building the THtml documentation of the class
44
45
46using namespace RooStats;
47
48////////////////////////////////////////////////////////////////////////////////
49/// Constructor
50
53 fTestStat_data(-999.),
54 fComputationsNulDoneFlag(false),
55 fComputationsAltDoneFlag(false),
56 fSumLargerValues(false)
57{
58 // HybridResult default constructor (with name )
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Constructor
63
65 const std::vector<double>& testStat_sb_vals,
66 const std::vector<double>& testStat_b_vals,
67 bool sumLargerValues ) :
69 fTestStat_data(-999.),
70 fComputationsNulDoneFlag(false),
71 fComputationsAltDoneFlag(false),
72 fSumLargerValues(sumLargerValues)
73{
74 // HybridResult constructor (with name, title and vectors of S+B and B values)
75
78
79 int vector_size_b = testStat_b_vals.size();
81
83 for (int i=0;i<vector_size_sb;++i)
84 fTestStat_sb.push_back(testStat_sb_vals[i]);
85
87 for (int i=0;i<vector_size_b;++i)
88 fTestStat_b.push_back(testStat_b_vals[i]);
89}
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// HybridResult destructor
94
96{
97
98 fTestStat_sb.clear();
99 fTestStat_b.clear();
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// set the value of the test statistics on data
104
112
113////////////////////////////////////////////////////////////////////////////////
114/// Returns \f$1 - CL_{b}\f$ : the B p-value
115
117{
118 if (fComputationsNulDoneFlag==false) {
119 int nToys = fTestStat_b.size();
120 if (nToys==0) {
121 std::cout << "Error: no toy data present. Returning -1.\n";
122 return -1;
123 }
124
125 double larger_than_measured=0;
126 if (fSumLargerValues) {
127 for (int iToy=0;iToy<nToys;++iToy)
129 } else {
130 for (int iToy=0;iToy<nToys;++iToy)
132 }
133
134 if (larger_than_measured==0) std::cout << "Warning: CLb = 0 ... maybe more toys are needed!\n";
135
138 }
139
140 return fNullPValue;
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Returns \f$CL_{s+b}\f$ : the S+B p-value
145
147{
148 if (fComputationsAltDoneFlag==false) {
149 int nToys = fTestStat_b.size();
150 if (nToys==0) {
151 std::cout << "Error: no toy data present. Returning -1.\n";
152 return -1;
153 }
154
155 double larger_than_measured=0;
156 if (fSumLargerValues) {
157 for (int iToy=0;iToy<nToys;++iToy)
159 } else {
160 for (int iToy=0;iToy<nToys;++iToy)
162 }
163
164 if (larger_than_measured==0) std::cout << "Warning: CLsb = 0 ... maybe more toys are needed!\n";
165
168 }
169
170 return fAlternatePValue;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Returns an estimate of the error on \f$CL_{b}\f$ assuming a binomial
175/// error on \f$CL_{b}\f$:
176/// \f[
177/// \sigma_{CL_{b}} = \sqrt{CL_{b} \left( 1 - CL_{b} \right) / n_{toys}}
178/// \f]
179
181{
182 unsigned const int n = fTestStat_b.size();
183 return std::sqrt(CLb() * (1. - CLb()) / n);
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Returns an estimate of the error on \f$CL_{s+b}\f$ assuming a binomial
188/// error on \f$CL_{s+b}\f$:
189/// \f[
190/// \sigma_{CL_{s+b}} = \sqrt{CL_{s+b} \left( 1 - CL_{s+b} \right) / n_{toys}}
191/// \f]
192
194{
195 unsigned const int n = fTestStat_sb.size();
196 return std::sqrt(CLsplusb() * (1. - CLsplusb()) / n);
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Returns an estimate of the error on \f$CL_{s}\f$ through combination
201/// of the errors on \f$CL_{b}\f$ and \f$CL_{s+b}\f$:
202/// \f[
203/// \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}
204/// \f]
205
207{
208 unsigned const int n_b = fTestStat_b.size();
209 unsigned const int n_sb = fTestStat_sb.size();
210
211 if (CLb() == 0 || CLsplusb() == 0)
212 return 0;
213
214 double cl_b_err = (1. - CLb()) / (n_b * CLb());
215 double cl_sb_err = (1. - CLsplusb()) / (n_sb * CLsplusb());
216
217 return CLs() * std::sqrt(cl_b_err + cl_sb_err);
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// add additional toy-MC experiments to the current results
222/// use the data test statistics of the added object if none is already present
223/// (otherwise, ignore the new one)
224
226{
227
228 int other_size_sb = other->GetTestStat_sb().size();
229 for (int i=0;i<other_size_sb;++i)
230 fTestStat_sb.push_back(other->GetTestStat_sb()[i]);
231
232 int other_size_b = other->GetTestStat_b().size();
233 for (int i=0;i<other_size_b;++i)
234 fTestStat_b.push_back(other->GetTestStat_b()[i]);
235
236 // if no data is present use the other's HybridResult's data
237 if (fTestStat_data==-999.)
238 fTestStat_data = other->GetTestStat_data();
239
242
243 return;
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// prepare a plot showing a result and return a pointer to a HybridPlot object
248/// the needed arguments are: an object name, a title and the number of bins in the plot
249
250HybridPlot* HybridResult::GetPlot(const char* name,const char* title, int n_bins)
251{
252 // default plot name
254 if ( TString(name)=="" ) {
255 plot_name += GetName();
256 plot_name += "_plot";
257 } else plot_name = name;
258
259 // default plot title
261 if ( TString(title)=="" ) {
262 plot_title += GetTitle();
263 plot_title += "_plot (";
264 plot_title += fTestStat_b.size();
265 plot_title += " toys)";
266 } else plot_title = title;
267
268 HybridPlot* plot = new HybridPlot( plot_name.Data(),
269 plot_title.Data(),
273 n_bins,
274 true );
275 return plot;
276}
277
278////////////////////////////////////////////////////////////////////////////////
279/// Print out some information about the results
280
281void HybridResult::PrintMore(const char* /*options */)
282{
283 std::cout << "\nResults " << GetName() << ":\n"
284 << " - Number of S+B toys: " << fTestStat_b.size() << std::endl
285 << " - Number of B toys: " << fTestStat_sb.size() << std::endl
286 << " - test statistics evaluated on data: " << fTestStat_data << std::endl
287 << " - CL_b " << CLb() << std::endl
288 << " - CL_s+b " << CLsplusb() << std::endl
289 << " - CL_s " << CLs() << std::endl;
290
291 return;
292}
293
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:110
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.
HybridPlot * GetPlot(const char *name, const char *title, int n_bins)
prepare a plot showing a result and return a pointer to a HybridPlot object the needed arguments are:...
void Add(HybridResult *other)
add additional toy-MC experiments to the current results use the data test statistics of the added ob...
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:139
const Int_t n
Definition legend1.C:16
Namespace for the RooStats classes.
Definition CodegenImpl.h:58