Logo ROOT   6.07/09
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 
13 #ifndef RooStats_FeldmanCousins
15 #endif
16 
17 #ifndef RooStats_RooStatsUtils
18 #include "RooStats/RooStatsUtils.h"
19 #endif
20 
21 #ifndef RooStats_PointSetInterval
23 #endif
24 
25 #include "RooStats/ModelConfig.h"
26 
28 
31 #include "RooStats/RooStatsUtils.h"
32 
33 #include "RooDataSet.h"
34 #include "RooDataHist.h"
35 #include "RooGlobalFunc.h"
36 #include "RooMsgService.h"
37 #include "TFile.h"
38 #include "TTree.h"
39 
41 
42 using namespace RooFit;
43 using namespace RooStats;
44 using namespace std;
45 
46 
47 /*
48 ////////////////////////////////////////////////////////////////////////////////
49 
50 FeldmanCousins::FeldmanCousins() :
51  // fModel(NULL),
52  fData(0),
53  fTestStatSampler(0),
54  fPointsToTest(0),
55  fAdaptiveSampling(false),
56  fNbins(10),
57  fFluctuateData(true),
58  fDoProfileConstruction(true),
59  fSaveBeltToFile(false),
60  fCreateBelt(false)
61 {
62  // default constructor
63 // fWS = new RooWorkspace("FeldmanCousinsWS");
64 // fOwnsWorkspace = true;
65 // fDataName = "";
66 // fPdfName = "";
67 }
68 */
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// standard constructor
72 
73 FeldmanCousins::FeldmanCousins(RooAbsData& data, ModelConfig& model) :
74  fSize(0.05),
75  fModel(model),
76  fData(data),
77  fTestStatSampler(0),
78  fPointsToTest(0),
79  fPOIToTest(0),
80  fConfBelt(0),
81  fAdaptiveSampling(false),
82  fAdditionalNToysFactor(1.),
83  fNbins(10),
84  fFluctuateData(true),
85  fDoProfileConstruction(true),
86  fSaveBeltToFile(false),
87  fCreateBelt(false)
88 {
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// destructor
93 ///if(fOwnsWorkspace && fWS) delete fWS;
94 
96  if(fPointsToTest) delete fPointsToTest;
97  if(fPOIToTest) delete fPOIToTest;
99 }
100 
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// set the model
104 
105 void FeldmanCousins::SetModel(const ModelConfig & model) {
106  fModel = model;
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 
112  if(!fTestStatSampler)
113  this->CreateTestStatSampler();
114  return fTestStatSampler;
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// specify the Test Statistic and create a ToyMC test statistic sampler
119 
121  // use the profile likelihood ratio as the test statistic
123 
124  // create the ToyMC test statistic sampler
125  fTestStatSampler = new ToyMCSampler(*testStatistic,int(fAdditionalNToysFactor*50./fSize)) ;
126  fTestStatSampler->SetParametersForTestStat(*fModel.GetParametersOfInterest() );
127  if(fModel.GetObservables())
128  fTestStatSampler->SetObservables(*fModel.GetObservables());
129  fTestStatSampler->SetPdf(*fModel.GetPdf());
130 
131  if(!fAdaptiveSampling){
132  ooccoutP(&fModel,Generation) << "FeldmanCousins: ntoys per point = " << (int) (fAdditionalNToysFactor*50./fSize) << endl;
133  } else{
134  ooccoutP(&fModel,Generation) << "FeldmanCousins: ntoys per point: adaptive" << endl;
135  }
136  if(fFluctuateData){
137  ooccoutP(&fModel,Generation) << "FeldmanCousins: nEvents per toy will fluctuate about expectation" << endl;
138  } else{
139  ooccoutP(&fModel,Generation) << "FeldmanCousins: nEvents per toy will not fluctuate, will always be " << fData.numEntries() << endl;
140  fTestStatSampler->SetNEventsPerToy(fData.numEntries());
141  }
142 }
143 
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// specify the parameter points to perform the construction.
147 /// allow ability to profile on some nuisance paramters
148 
150  // get ingredients
151  RooAbsPdf* pdf = fModel.GetPdf();
152  if (!pdf ){
153  ooccoutE(&fModel,Generation) << "FeldmanCousins: ModelConfig has no PDF" << endl;
154  return;
155  }
156 
157  // get list of all paramters
158  RooArgSet* parameters = new RooArgSet(*fModel.GetParametersOfInterest());
160  parameters->add(*fModel.GetNuisanceParameters());
161 
162 
164  // if parameters include nuisance parameters, do profile construction
165  ooccoutP(&fModel,Generation) << "FeldmanCousins: Model has nuisance parameters, will do profile construction" << endl;
166 
167  // set nbins for the POI
169  RooRealVar *myarg2;
170  while ((myarg2 = dynamic_cast<RooRealVar*>(it2.Next()))) {
171  myarg2->setBins(fNbins);
172  }
173 
174  // get dataset for POI scan
175  // RooDataHist* parameterScan = NULL;
176  RooAbsData* parameterScan = NULL;
177  if(fPOIToTest)
178  parameterScan = fPOIToTest;
179  else
180  parameterScan = new RooDataHist("parameterScan", "", *fModel.GetParametersOfInterest());
181 
182 
183  ooccoutP(&fModel,Generation) << "FeldmanCousins: # points to test = " << parameterScan->numEntries() << endl;
184  // make profile construction
187  RooAbsReal* nll = pdf->createNLL(fData,RooFit::CloneData(false));
189 
190  RooDataSet* profileConstructionPoints = new RooDataSet("profileConstruction",
191  "profileConstruction",
192  *parameters);
193 
194 
195  for(Int_t i=0; i<parameterScan->numEntries(); ++i){
196  // here's where we figure out the profiled value of nuisance parameters
197  *parameters = *parameterScan->get(i);
198  profile->getVal();
199  profileConstructionPoints->add(*parameters);
200  }
202  delete profile;
203  delete nll;
204  if(!fPOIToTest) delete parameterScan;
205 
206  // done
207  fPointsToTest = profileConstructionPoints;
208 
209  } else{
210  // Do full construction
211  ooccoutP(&fModel,Generation) << "FeldmanCousins: Model has no nuisance parameters" << endl;
212 
213  TIter it = parameters->createIterator();
214  RooRealVar *myarg;
215  while ((myarg = dynamic_cast<RooRealVar*>(it.Next()))) {
216  myarg->setBins(fNbins);
217  }
218 
219  RooDataHist* parameterScan = new RooDataHist("parameterScan", "", *parameters);
220  ooccoutP(&fModel,Generation) << "FeldmanCousins: # points to test = " << parameterScan->numEntries() << endl;
221 
222  fPointsToTest = parameterScan;
223  }
224 
225  delete parameters;
226 
227 }
228 
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Main interface to get a RooStats::ConfInterval.
232 /// It constructs a RooStats::PointSetInterval.
233 
235  // local variables
236  // RooAbsData* data = fData; //fWS->data(fDataName);
237 
238  // fill in implied variables given data
240 
241  // create the test statistic sampler (private data member fTestStatSampler)
242  if(!fTestStatSampler)
243  this->CreateTestStatSampler();
244 
246 
247  if(!fFluctuateData)
249 
250  // create paramter points to perform construction (private data member fPointsToTest)
251  this->CreateParameterPoints();
252 
253  // Create a Neyman Construction
255  // configure it
257  nc.SetTestSize(fSize); // set size of test
258  // nc.SetParameters( fModel.GetParametersOfInterest);
260  nc.SetLeftSideTailFraction(0.); // part of definition of Feldman-Cousins
261  nc.SetData(fData);
267  // use it
268  return nc.GetInterval();
269 }
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:777
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:52
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
Definition: ModelConfig.h:244
ConfidenceBelt * GetConfidenceBelt()
get confidence belt
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) ...
RooCmdArg CloneData(Bool_t flag)
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically named contents.
TestStatSampler is an interface class for a tools which produce RooStats SamplingDistributions.
void GuessObsAndNuisance(const RooAbsData &data)
guesses Observables and ParametersOfInterest if not already set
Definition: ModelConfig.cxx:32
virtual void SetNEventsPerToy(const Int_t nevents)
Definition: ToyMCSampler.h:177
int Int_t
Definition: RtypesCore.h:41
static RooMsgService & instance()
Return reference to singleton instance.
#define ooccoutP(o, a)
Definition: RooMsgService.h:53
STL namespace.
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
Definition: ModelConfig.h:250
void SetParameterPointsToTest(RooAbsData &pointsToTest)
User-defined set of points to test.
#define ooccoutE(o, a)
Definition: RooMsgService.h:55
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
void AdditionalNToysFactor(double fact)
give user ability to ask for more toys
TIterator * createIterator(Bool_t dir=kIterForward) const
void CreateTestStatSampler() const
initializes fTestStatSampler data member (mutable)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
virtual ~FeldmanCousins()
destructor if(fOwnsWorkspace && fWS) delete fWS;
void setBins(Int_t nBins, const char *name=0)
Definition: RooRealVar.h:78
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
virtual const RooArgSet * get() const
Definition: RooAbsData.h:77
RooFit::MsgLevel globalKillBelow() const
TObject * Next()
Definition: TCollection.h:158
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:269
ToyMCSampler * fTestStatSampler
void setGlobalKillBelow(RooFit::MsgLevel level)
virtual void SetData(RooAbsData &data)
Set the DataSet.
virtual PointSetInterval * GetInterval() const
Main interface to get a ConfInterval (will be a PointSetInterval)
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
ProfileLikelihoodTestStat is an implementation of the TestStatistic interface that calculates the pro...
ToyMCSampler is an implementation of the TestStatSampler interface.
Definition: ToyMCSampler.h:99
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
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 &#39;data&#39; argset, to the data set...
The FeldmanCousins class (like the Feldman-Cousins technique) is essentially a specific configuration...
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
Definition: ModelConfig.h:259
void SetTestStatSampler(TestStatSampler &sampler)
in addition to interface we also need: Set the TestStatSampler (eg.
TestStatSampler * GetTestStatSampler() const
Returns instance of TestStatSampler.
void UseAdaptiveSampling(bool flag=true)
adaptive sampling algorithm to speed up interval caculation
Namespace for the RooStats classes.
Definition: Asimov.h:20
PointSetInterval is a concrete implementation of the ConfInterval interface.
#define ClassImp(name)
Definition: Rtypes.h:279
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
virtual void SetObservables(const RooArgSet &o)
Definition: ToyMCSampler.h:203
void CreateConfBelt(bool flag=true)
should create confidence belt
virtual PointSetInterval * GetInterval() const
Main interface to get a ConfInterval (will be a PointSetInterval)
NeymanConstruction is a concrete implementation of the NeymanConstruction interface that...
virtual Int_t numEntries() const
Return the number of bins.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
void SetLeftSideTailFraction(Double_t leftSideFraction=0.)
fLeftSideTailFraction*fSize defines lower edge of acceptance region.
virtual RooAbsReal * createProfile(const RooArgSet &paramsOfInterest)
Create a RooProfileLL object that eliminates all nuisance parameters in the present function...
Definition: RooAbsReal.cxx:463
void SaveBeltToFile(bool flag=true)
save teh confidence belt to a file
#define NULL
Definition: Rtypes.h:82
virtual void SetModel(const ModelConfig &)
set the model
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
Definition: ModelConfig.h:247
ConfidenceBelt * fConfBelt
void CreateParameterPoints() const
initializes fPointsToTest data member (mutable)
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448