Logo ROOT   6.18/05
Reference Guide
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
26
27#include "RooDataSet.h"
28#include "RooDataHist.h"
29#include "RooGlobalFunc.h"
30#include "RooMsgService.h"
31#include "TFile.h"
32#include "TTree.h"
33
34/** \class RooStats::FeldmanCousins
35 \ingroup Roostats
36
37The FeldmanCousins class (like the Feldman-Cousins technique) is essentially a
38specific configuration of the more general NeymanConstruction. It is a concrete
39implementation of the IntervalCalculator interface that, which uses the
40NeymanConstruction in a particular way. As the name suggests, it returns a
41ConfidenceInterval. In particular, it produces a RooStats::PointSetInterval,
42which is a concrete implementation of the ConfInterval interface.
43
44The Neyman Construction is not a uniquely defined statistical technique, it
45requires that one specify an ordering rule or ordering principle, which is
46usually encoded by choosing a specific test statistic and limits of integration
47(corresponding to upper/lower/central limits). As a result, this class must be
48configured with the corresponding information before it can produce an interval.
49
50In the case of the Feldman-Cousins approach, the ordering principle is the
51likelihood ratio -- motivated by the Neyman-Pearson lemma. When nuisance
52parameters are involved, the profile likelihood ratio is the natural
53generalization. One may either choose to perform the construction over the full
54space of the nuisance parameters, or restrict the nuisance parameters to their
55conditional MLE (eg. profiled values).
56
57*/
58
60
61using namespace RooFit;
62using namespace RooStats;
63using namespace std;
64
65////////////////////////////////////////////////////////////////////////////////
66/// standard constructor
67
68FeldmanCousins::FeldmanCousins(RooAbsData& data, ModelConfig& model) :
69 fSize(0.05),
70 fModel(model),
71 fData(data),
72 fTestStatSampler(0),
73 fPointsToTest(0),
74 fPOIToTest(0),
75 fConfBelt(0),
76 fAdaptiveSampling(false),
77 fAdditionalNToysFactor(1.),
78 fNbins(10),
79 fFluctuateData(true),
80 fDoProfileConstruction(true),
81 fSaveBeltToFile(false),
82 fCreateBelt(false)
83{
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// destructor
88
91 if(fPOIToTest) delete fPOIToTest;
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// set the model
97
99 fModel = model;
100}
101
102////////////////////////////////////////////////////////////////////////////////
103
106 this->CreateTestStatSampler();
107 return fTestStatSampler;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// specify the Test Statistic and create a ToyMC test statistic sampler
112
114 // use the profile likelihood ratio as the test statistic
116
117 // create the ToyMC test statistic sampler
118 fTestStatSampler = new ToyMCSampler(*testStatistic,int(fAdditionalNToysFactor*50./fSize)) ;
123
125 ooccoutP(&fModel,Generation) << "FeldmanCousins: ntoys per point = " << (int) (fAdditionalNToysFactor*50./fSize) << endl;
126 } else{
127 ooccoutP(&fModel,Generation) << "FeldmanCousins: ntoys per point: adaptive" << endl;
128 }
129 if(fFluctuateData){
130 ooccoutP(&fModel,Generation) << "FeldmanCousins: nEvents per toy will fluctuate about expectation" << endl;
131 } else{
132 ooccoutP(&fModel,Generation) << "FeldmanCousins: nEvents per toy will not fluctuate, will always be " << fData.numEntries() << endl;
134 }
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// specify the parameter points to perform the construction.
139/// allow ability to profile on some nuisance parameters
140
142 // get ingredients
143 RooAbsPdf* pdf = fModel.GetPdf();
144 if (!pdf ){
145 ooccoutE(&fModel,Generation) << "FeldmanCousins: ModelConfig has no PDF" << endl;
146 return;
147 }
148
149 // get list of all parameters
152 parameters->add(*fModel.GetNuisanceParameters());
153
154
156 // if parameters include nuisance parameters, do profile construction
157 ooccoutP(&fModel,Generation) << "FeldmanCousins: Model has nuisance parameters, will do profile construction" << endl;
158
159 // set nbins for the POI
161 RooRealVar *myarg2;
162 while ((myarg2 = dynamic_cast<RooRealVar*>(it2.Next()))) {
163 myarg2->setBins(fNbins);
164 }
165
166 // get dataset for POI scan
167 // RooDataHist* parameterScan = NULL;
168 RooAbsData* parameterScan = NULL;
169 if(fPOIToTest)
170 parameterScan = fPOIToTest;
171 else
172 parameterScan = new RooDataHist("parameterScan", "", *fModel.GetParametersOfInterest());
173
174
175 ooccoutP(&fModel,Generation) << "FeldmanCousins: # points to test = " << parameterScan->numEntries() << endl;
176 // make profile construction
179 RooAbsReal* nll = pdf->createNLL(fData,RooFit::CloneData(false));
181
182 RooDataSet* profileConstructionPoints = new RooDataSet("profileConstruction",
183 "profileConstruction",
184 *parameters);
185
186
187 for(Int_t i=0; i<parameterScan->numEntries(); ++i){
188 // here's where we figure out the profiled value of nuisance parameters
189 *parameters = *parameterScan->get(i);
190 profile->getVal();
191 profileConstructionPoints->add(*parameters);
192 }
194 delete profile;
195 delete nll;
196 if(!fPOIToTest) delete parameterScan;
197
198 // done
199 fPointsToTest = profileConstructionPoints;
200
201 } else{
202 // Do full construction
203 ooccoutP(&fModel,Generation) << "FeldmanCousins: Model has no nuisance parameters" << endl;
204
205 TIter it = parameters->createIterator();
206 RooRealVar *myarg;
207 while ((myarg = dynamic_cast<RooRealVar*>(it.Next()))) {
208 myarg->setBins(fNbins);
209 }
210
211 RooDataHist* parameterScan = new RooDataHist("parameterScan", "", *parameters);
212 ooccoutP(&fModel,Generation) << "FeldmanCousins: # points to test = " << parameterScan->numEntries() << endl;
213
214 fPointsToTest = parameterScan;
215 }
216
217 delete parameters;
218
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Main interface to get a RooStats::ConfInterval.
223/// It constructs a RooStats::PointSetInterval.
224
226 // local variables
227 // RooAbsData* data = fData; //fWS->data(fDataName);
228
229 // fill in implied variables given data
231
232 // create the test statistic sampler (private data member fTestStatSampler)
234 this->CreateTestStatSampler();
235
237
238 if(!fFluctuateData)
240
241 // create parameter points to perform construction (private data member fPointsToTest)
242 this->CreateParameterPoints();
243
244 // Create a Neyman Construction
246 // configure it
248 nc.SetTestSize(fSize); // set size of test
249 // nc.SetParameters( fModel.GetParametersOfInterest);
251 nc.SetLeftSideTailFraction(0.); // part of definition of Feldman-Cousins
252 nc.SetData(fData);
258 // use it
259 return nc.GetInterval();
260}
#define ooccoutP(o, a)
Definition: RooMsgService.h:52
#define ooccoutE(o, a)
Definition: RooMsgService.h:54
int Int_t
Definition: RtypesCore.h:41
#define ClassImp(name)
Definition: Rtypes.h:365
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
virtual const RooArgSet * get() const
Definition: RooAbsData.h:80
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:306
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:800
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
virtual RooAbsReal * createProfile(const RooArgSet &paramsOfInterest)
Create a RooProfileLL object that eliminates all nuisance parameters in the present function.
Definition: RooAbsReal.cxx:486
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:81
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
virtual Int_t numEntries() const
Return the number of bins.
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0)
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
void setBins(Int_t nBins, const char *name=0)
Definition: RooRealVar.h:78
The FeldmanCousins class (like the Feldman-Cousins technique) is essentially a specific configuration...
ConfidenceBelt * fConfBelt
virtual PointSetInterval * GetInterval() const
Main interface to get a ConfInterval (will be a PointSetInterval)
void CreateParameterPoints() const
initializes fPointsToTest data member (mutable)
TestStatSampler * GetTestStatSampler() const
Returns instance of TestStatSampler.
void CreateTestStatSampler() const
initializes fTestStatSampler data member (mutable)
virtual ~FeldmanCousins()
destructor
ToyMCSampler * fTestStatSampler
virtual void SetModel(const ModelConfig &)
set the model
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
Definition: ModelConfig.h:231
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
Definition: ModelConfig.h:234
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
Definition: ModelConfig.h:243
void GuessObsAndNuisance(const RooAbsData &data)
guesses Observables and ParametersOfInterest if not already set
Definition: ModelConfig.cxx:50
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
Definition: ModelConfig.h:228
NeymanConstruction is a concrete implementation of the NeymanConstruction interface that,...
virtual void SetTestSize(Double_t size)
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
virtual PointSetInterval * GetInterval() const
Main interface to get a ConfInterval (will be a PointSetInterval)
void SetTestStatSampler(TestStatSampler &sampler)
in addition to interface we also need: Set the TestStatSampler (eg.
void SetLeftSideTailFraction(Double_t 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.
virtual void SetData(RooAbsData &data)
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.
Definition: ToyMCSampler.h:72
virtual void SetObservables(const RooArgSet &o)
Definition: ToyMCSampler.h:173
virtual void SetPdf(RooAbsPdf &pdf)
Definition: ToyMCSampler.h:160
virtual void SetNEventsPerToy(const Int_t nevents)
Definition: ToyMCSampler.h:148
virtual void SetParametersForTestStat(const RooArgSet &nullpoi)
Definition: ToyMCSampler.h:156
TObject * Next()
Definition: TCollection.h:249
Template specialisation used in RooAbsArg:
@ Generation
Definition: RooGlobalFunc.h:57
RooCmdArg CloneData(Bool_t flag)
Namespace for the RooStats classes.
Definition: Asimov.h:20