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