Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FeldmanCousins.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer January 2009
3
4/*************************************************************************
5 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
14
16
18
20
22
25
26#include "RooDataSet.h"
27#include "RooDataHist.h"
28#include "RooGlobalFunc.h"
29#include "RooMsgService.h"
30
31/** \class RooStats::FeldmanCousins
32 \ingroup Roostats
33
34The FeldmanCousins class (like the Feldman-Cousins technique) is essentially a
35specific configuration of the more general NeymanConstruction. It is a concrete
36implementation of the IntervalCalculator interface that, which uses the
37NeymanConstruction in a particular way. As the name suggests, it returns a
38ConfidenceInterval. In particular, it produces a RooStats::PointSetInterval,
39which is a concrete implementation of the ConfInterval interface.
40
41The Neyman Construction is not a uniquely defined statistical technique, it
42requires that one specify an ordering rule or ordering principle, which is
43usually encoded by choosing a specific test statistic and limits of integration
44(corresponding to upper/lower/central limits). As a result, this class must be
45configured with the corresponding information before it can produce an interval.
46
47In the case of the Feldman-Cousins approach, the ordering principle is the
48likelihood ratio -- motivated by the Neyman-Pearson lemma. When nuisance
49parameters are involved, the profile likelihood ratio is the natural
50generalization. One may either choose to perform the construction over the full
51space of the nuisance parameters, or restrict the nuisance parameters to their
52conditional MLE (eg. profiled values).
53
54*/
55
56
57using namespace RooFit;
58using namespace RooStats;
59using std::endl;
60
61////////////////////////////////////////////////////////////////////////////////
62/// standard constructor
63
65 fSize(0.05),
66 fModel(model),
67 fData(data),
68 fTestStatSampler(nullptr),
69 fPointsToTest(nullptr),
70 fPOIToTest(nullptr),
71 fConfBelt(nullptr),
72 fAdaptiveSampling(false),
73 fAdditionalNToysFactor(1.),
74 fNbins(10),
75 fFluctuateData(true),
76 fDoProfileConstruction(true),
77 fSaveBeltToFile(false),
78 fCreateBelt(false)
79{
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// destructor
84
90
91////////////////////////////////////////////////////////////////////////////////
92/// set the model
93
95 fModel = model;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99
105
106////////////////////////////////////////////////////////////////////////////////
107/// specify the Test Statistic and create a ToyMC test statistic sampler
108
110 // use the profile likelihood ratio as the test statistic
112
113 // create the ToyMC test statistic sampler
119
121 ooccoutP(&fModel,Generation) << "FeldmanCousins: ntoys per point = " << (int) (fAdditionalNToysFactor*50./fSize) << std::endl;
122 } else{
123 ooccoutP(&fModel,Generation) << "FeldmanCousins: ntoys per point: adaptive" << std::endl;
124 }
125 if(fFluctuateData){
126 ooccoutP(&fModel,Generation) << "FeldmanCousins: nEvents per toy will fluctuate about expectation" << std::endl;
127 } else{
128 ooccoutP(&fModel,Generation) << "FeldmanCousins: nEvents per toy will not fluctuate, will always be " << fData.numEntries() << std::endl;
130 }
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// specify the parameter points to perform the construction.
135/// allow ability to profile on some nuisance parameters
136
138 // get ingredients
139 RooAbsPdf* pdf = fModel.GetPdf();
140 if (!pdf ){
141 ooccoutE(&fModel,Generation) << "FeldmanCousins: ModelConfig has no PDF" << std::endl;
142 return;
143 }
144
145 // get list of all parameters
148 parameters->add(*fModel.GetNuisanceParameters());
149
150
152 // if parameters include nuisance parameters, do profile construction
153 ooccoutP(&fModel,Generation) << "FeldmanCousins: Model has nuisance parameters, will do profile construction" << std::endl;
154
155 // set nbins for the POI
157 myarg2->setBins(fNbins);
158 }
159
160 // get dataset for POI scan
161 // RooDataHist* parameterScan = nullptr;
162 RooAbsData* parameterScan = nullptr;
163 if (fPOIToTest) {
165 } else {
166 parameterScan = new RooDataHist("parameterScan", "", *fModel.GetParametersOfInterest());
167 }
168
169 ooccoutP(&fModel,Generation) << "FeldmanCousins: # points to test = " << parameterScan->numEntries() << std::endl;
170 // make profile construction
172 RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL) ;
173 std::unique_ptr<RooAbsReal> nll{pdf->createNLL(fData,RooFit::CloneData(false))};
174 std::unique_ptr<RooAbsReal> profile{nll->createProfile(*fModel.GetParametersOfInterest())};
175
176 RooDataSet* profileConstructionPoints = new RooDataSet("profileConstruction",
177 "profileConstruction",
178 *parameters);
179
180
181 for(Int_t i=0; i<parameterScan->numEntries(); ++i){
182 // here's where we figure out the profiled value of nuisance parameters
183 parameters->assign(*parameterScan->get(i));
184 profile->getVal();
185 profileConstructionPoints->add(*parameters);
186 }
187 RooMsgService::instance().setGlobalKillBelow(previous) ;
188 if(!fPOIToTest) delete parameterScan;
189
190 // done
192
193 } else{
194 // Do full construction
195 ooccoutP(&fModel,Generation) << "FeldmanCousins: Model has no nuisance parameters" << std::endl;
196
197 for (auto *myarg : static_range_cast<RooRealVar *>(*parameters)){
198 myarg->setBins(fNbins);
199 }
200
201 RooDataHist* parameterScan = new RooDataHist("parameterScan", "", *parameters);
202 ooccoutP(&fModel,Generation) << "FeldmanCousins: # points to test = " << parameterScan->numEntries() << std::endl;
203
205 }
206
207 delete parameters;
208
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Main interface to get a RooStats::ConfInterval.
213/// It constructs a RooStats::PointSetInterval.
214
216 // local variables
217 // RooAbsData* data = fData; //fWS->data(fDataName);
218
219 // fill in implied variables given data
221
222 // create the test statistic sampler (private data member fTestStatSampler)
224 this->CreateTestStatSampler();
225
227
228 if(!fFluctuateData)
230
231 // create parameter points to perform construction (private data member fPointsToTest)
232 this->CreateParameterPoints();
233
234 // Create a Neyman Construction
236 // configure it
238 nc.SetTestSize(fSize); // set size of test
239 // nc.SetParameters( fModel.GetParametersOfInterest);
241 nc.SetLeftSideTailFraction(0.); // part of definition of Feldman-Cousins
242 nc.SetData(fData);
247 if (fCreateBelt)
249
250 // use it
251 return nc.GetInterval();
252}
dim_t fSize
#define ooccoutP(o, a)
#define ooccoutE(o, a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
RooFit::OwningPtr< RooAbsReal > createNLL(RooAbsData &data, CmdArgs_t const &... cmdArgs)
Construct representation of -log(L) of PDF with given dataset.
Definition RooAbsPdf.h:163
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:40
Container class to hold unbinned data.
Definition RooDataSet.h:34
static RooMsgService & instance()
Return reference to singleton instance.
bool fSaveBeltToFile
controls use if ConfidenceBelt should be saved to a TFile
ConfidenceBelt * fConfBelt
RooAbsData & fData
data set
void CreateParameterPoints() const
initializes fPointsToTest data member (mutable)
void SetModel(const ModelConfig &) override
set the model
FeldmanCousins(RooAbsData &data, ModelConfig &model)
Common constructor.
bool fFluctuateData
tell ToyMCSampler to fluctuate number of entries in dataset
double fSize
size of the test (eg. specified rate of Type I error)
Int_t fNbins
number of samples per variable
PointSetInterval * GetInterval() const override
Main interface to get a ConfInterval (will be a PointSetInterval)
TestStatSampler * GetTestStatSampler() const
Returns instance of TestStatSampler.
void CreateTestStatSampler() const
initializes fTestStatSampler data member (mutable)
double fAdditionalNToysFactor
give user ability to ask for more toys
RooAbsData * fPOIToTest
value of POI points to perform the construction
bool fCreateBelt
controls use if ConfidenceBelt should be saved to a TFile
bool fDoProfileConstruction
instead of full construction over nuisance parameters, do profile
RooAbsData * fPointsToTest
points to perform the construction
ToyMCSampler * fTestStatSampler
the test statistic sampler
~FeldmanCousins() override
destructor
bool fAdaptiveSampling
controls use of adaptive sampling algorithm
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition ModelConfig.h:35
void GuessObsAndNuisance(const RooAbsData &data, bool printModelConfig=true)
Makes sensible guesses of observables, parameters of interest and nuisance parameters if one or multi...
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return nullptr if not existing)
const RooArgSet * GetObservables() const
get RooArgSet for observables (return nullptr if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return nullptr if pdf has not been specified or does not exist)
NeymanConstruction is a concrete implementation of the NeymanConstruction interface that,...
PointSetInterval * GetInterval() const override
Main interface to get a ConfInterval (will be a PointSetInterval)
void SetTestSize(double size) override
set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
void SaveBeltToFile(bool flag=true)
save the confidence belt to a file
ConfidenceBelt * GetConfidenceBelt()
Get confidence belt. This requires that CreateConfBelt() has been called.
void SetTestStatSampler(TestStatSampler &sampler)
in addition to interface we also need: Set the TestStatSampler (eg.
void SetLeftSideTailFraction(double leftSideFraction=0.)
fLeftSideTailFraction*fSize defines lower edge of acceptance region.
void UseAdaptiveSampling(bool flag=true)
adaptive sampling algorithm to speed up interval calculation
void AdditionalNToysFactor(double fact)
give user ability to ask for more toys
void CreateConfBelt(bool flag=true)
should create confidence belt
void SetParameterPointsToTest(RooAbsData &pointsToTest)
User-defined set of points to test.
void SetData(RooAbsData &data) override
Set the DataSet.
PointSetInterval is a concrete implementation of the ConfInterval interface.
ProfileLikelihoodTestStat is an implementation of the TestStatistic interface that calculates the pro...
TestStatSampler is an interface class for a tools which produce RooStats SamplingDistributions.
ToyMCSampler is an implementation of the TestStatSampler interface.
void SetParametersForTestStat(const RooArgSet &nullpoi) override
Set the Pdf, add to the workspace if not already there.
void SetObservables(const RooArgSet &o) override
specify the observables in the dataset (needed to evaluate the test statistic)
void SetPdf(RooAbsPdf &pdf) override
Set the Pdf, add to the workspace if not already there.
virtual void SetNEventsPerToy(const Int_t nevents)
Forces the generation of exactly n events even for extended PDFs.
RooCmdArg CloneData(bool flag)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:64
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Namespace for the RooStats classes.
Definition CodegenImpl.h:58