Logo ROOT  
Reference Guide
ToyMCImportanceSampler.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Sven Kreiss January 2012
3// Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
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/** \class RooStats::ToyMCImportanceSampler
13 \ingroup Roostats
14
15ToyMCImportanceSampler is an extension of the ToyMCSampler for Importance Sampling.
16
17Implementation based on a work by Cranmer, Kreiss, Read (in Preparation)
18*/
19
21
22#include "RooMsgService.h"
23
24#include "RooCategory.h"
25#include "TMath.h"
26
27using namespace RooFit;
28using namespace std;
29
30
32
33namespace RooStats {
34
35////////////////////////////////////////////////////////////////////////////////
36
38 for( unsigned int i=0; i < fImportanceSnapshots.size(); i++ ) if(fImportanceSnapshots[i]) delete fImportanceSnapshots[i];
39 for( unsigned int i=0; i < fNullSnapshots.size(); i++ ) if(fNullSnapshots[i]) delete fNullSnapshots[i];
40}
41
42////////////////////////////////////////////////////////////////////////////////
43
46
47 for( unsigned int i=0; i < fImpNLLs.size(); i++ ) if(fImpNLLs[i]) { delete fImpNLLs[i]; fImpNLLs[i] = NULL; }
48 for( unsigned int i=0; i < fNullNLLs.size(); i++ ) if(fNullNLLs[i]) { delete fNullNLLs[i]; fNullNLLs[i] = NULL; }
49}
50
51////////////////////////////////////////////////////////////////////////////////
52
54 if( fNToys == 0 ) return NULL;
55
56 // remember original #toys, but overwrite it temporarily with the #toys per distribution
57 Int_t allToys = fNToys;
58
59 // to keep track of which dataset entry comes form which density, define a roocategory as a label
60 RooCategory densityLabel( "densityLabel", "densityLabel" );
61 densityLabel.defineType( "null", -1 );
62 for( unsigned int i=0; i < fImportanceDensities.size(); i++ )
63 densityLabel.defineType( TString::Format( "impDens_%d", i ), i );
64
65
66 RooDataSet* fullResult = NULL;
67
68 // generate null (negative i) and imp densities (0 and positive i)
69 for( int i = -1; i < (int)fImportanceDensities.size(); i++ ) {
70 if( i < 0 ) {
71 // generate null toys
72 oocoutP((TObject*)0,Generation) << endl << endl << " GENERATING FROM NULL DENSITY " << endl << endl;
73 SetDensityToGenerateFromByIndex( 0, true ); // true = generate from null
74 }else{
75 oocoutP((TObject*)0,Generation) << endl << endl << " GENERATING IMP DENS/SNAP "<<i+1<<" OUT OF "<<fImportanceDensities.size()<<endl<<endl;
76 SetDensityToGenerateFromByIndex( i, false ); // false = generate not from null
77 }
78
79 RooRealVar reweight( "reweight", "reweight", 1.0 );
80 // apply strategy for how to distribute the #toys between the distributions
82 // assuming alltoys = one null + N imp densities. And round up.
83 fNToys = TMath::CeilNint( double(allToys)/(fImportanceDensities.size()+1) );
85 // for N densities, split the toys into (2^(N+1))-1 parts, and assign 2^0 parts to the first
86 // density (which is the null), 2^1 to the second (first imp dens), etc, up to 2^N
87 fNToys = TMath::CeilNint( double(allToys) * pow( double(2) , i+1 ) / (pow( double(2), int(fImportanceDensities.size()+1) )-1) );
88
89 int largestNToys = TMath::CeilNint( allToys * pow( double(2), int(fImportanceDensities.size()) ) / (pow( double(2), int(fImportanceDensities.size()+1) )-1) );
90 reweight.setVal( ((double)largestNToys) / fNToys );
91 }
92
93 ooccoutI((TObject*)NULL,InputArguments) << "Generating " << fNToys << " toys for this density." << endl;
94 ooccoutI((TObject*)NULL,InputArguments) << "Reweight is " << reweight.getVal() << endl;
95
96
98
99 if (result->get()->getSize() > Int_t(fTestStatistics.size())) {
100 // add label
101 densityLabel.setIndex( i );
102 result->addColumn( densityLabel );
103 result->addColumn( reweight );
104 }
105
106 if( !fullResult ) {
107 RooArgSet columns( *result->get() );
108 RooRealVar weightVar ( "weight", "weight", 1.0 );
109 columns.add( weightVar );
110// cout << endl << endl << "Reweighted data columns: " << endl;
111// columns.Print("v");
112// cout << endl;
113 fullResult = new RooDataSet( result->GetName(), result->GetTitle(), columns, "weight" );
114 }
115
116 for( int j=0; j < result->numEntries(); j++ ) {
117// cout << "entry: " << j << endl;
118// result->get(j)->Print();
119// cout << "weight: " << result->weight() << endl;
120// cout << "reweight: " << reweight.getVal() << endl;
121 const RooArgSet* row = result->get(j);
122 fullResult->add( *row, result->weight()*reweight.getVal() );
123 }
124 delete result;
125 }
126
127 // restore #toys
128 fNToys = allToys;
129
130 return fullResult;
131}
132
133////////////////////////////////////////////////////////////////////////////////
134
136 RooArgSet& paramPoint,
137 double& weight
138) const {
139 if( fNullDensities.size() > 1 ) {
140 ooccoutI((TObject*)NULL,InputArguments) << "Null Densities:" << endl;
141 for( unsigned int i=0; i < fNullDensities.size(); i++) {
142 ooccoutI((TObject*)NULL,InputArguments) << " null density["<<i<<"]: " << fNullDensities[i] << " \t null snapshot["<<i<<"]: " << fNullSnapshots[i] << endl;
143 }
144 ooccoutE((TObject*)NULL,InputArguments) << "Cannot use multiple null densities and only ask for one weight." << endl;
145 return NULL;
146 }
147
148 if( fNullDensities.size() == 0 && fPdf ) {
149 ooccoutI((TObject*)NULL,InputArguments) << "No explicit null densities specified. Going to add one based on the given paramPoint and the global fPdf. ... but cannot do that inside const function." << endl;
150 //AddNullDensity( fPdf, &paramPoint );
151 }
152
153 // do not do anything if the given parameter point if fNullSnapshots[0]
154 // ... which is the most common case
155 if( fNullSnapshots[0] != &paramPoint ) {
156 ooccoutD((TObject*)NULL,InputArguments) << "Using given parameter point. Replaces snapshot for the only null currently defined." << endl;
157 if(fNullSnapshots[0]) delete fNullSnapshots[0];
158 fNullSnapshots.clear();
159 fNullSnapshots.push_back( (RooArgSet*)paramPoint.snapshot() );
160 }
161
162 vector<double> weights;
163 weights.push_back( weight );
164
165 vector<double> impNLLs;
166 for( unsigned int i=0; i < fImportanceDensities.size(); i++ ) impNLLs.push_back( 0.0 );
167 vector<double> nullNLLs;
168 for( unsigned int i=0; i < fNullDensities.size(); i++ ) nullNLLs.push_back( 0.0 );
169
170 RooAbsData *d = GenerateToyData( weights, impNLLs, nullNLLs );
171 weight = weights[0];
172 return d;
173}
174
175////////////////////////////////////////////////////////////////////////////////
176
178 RooArgSet& paramPoint,
179 double& weight,
180 vector<double>& impNLLs,
181 double& nullNLL
182) const {
183 if( fNullDensities.size() > 1 ) {
184 ooccoutI((TObject*)NULL,InputArguments) << "Null Densities:" << endl;
185 for( unsigned int i=0; i < fNullDensities.size(); i++) {
186 ooccoutI((TObject*)NULL,InputArguments) << " null density["<<i<<"]: " << fNullDensities[i] << " \t null snapshot["<<i<<"]: " << fNullSnapshots[i] << endl;
187 }
188 ooccoutE((TObject*)NULL,InputArguments) << "Cannot use multiple null densities and only ask for one weight and NLL." << endl;
189 return NULL;
190 }
191
192 if( fNullDensities.size() == 0 && fPdf ) {
193 ooccoutI((TObject*)NULL,InputArguments) << "No explicit null densities specified. Going to add one based on the given paramPoint and the global fPdf. ... but cannot do that inside const function." << endl;
194 //AddNullDensity( fPdf, &paramPoint );
195 }
196
197 ooccoutI((TObject*)NULL,InputArguments) << "Using given parameter point. Overwrites snapshot for the only null currently defined." << endl;
198 if(fNullSnapshots[0]) delete fNullSnapshots[0];
199 fNullSnapshots.clear();
200 fNullSnapshots.push_back( (const RooArgSet*)paramPoint.snapshot() );
201
202 vector<double> weights;
203 weights.push_back( weight );
204
205 vector<double> nullNLLs;
206 nullNLLs.push_back( nullNLL );
207
208 RooAbsData *d = GenerateToyData( weights, impNLLs, nullNLLs );
209 weight = weights[0];
210 nullNLL = nullNLLs[0];
211 return d;
212}
213
214////////////////////////////////////////////////////////////////////////////////
215
217 vector<double>& weights
218) const {
219 if( fNullDensities.size() != weights.size() ) {
220 ooccoutI((TObject*)NULL,InputArguments) << "weights.size() != nullDesnities.size(). You need to provide a vector with the correct size." << endl;
221 //AddNullDensity( fPdf, &paramPoint );
222 }
223
224 vector<double> impNLLs;
225 for( unsigned int i=0; i < fImportanceDensities.size(); i++ ) impNLLs.push_back( 0.0 );
226 vector<double> nullNLLs;
227 for( unsigned int i=0; i < fNullDensities.size(); i++ ) nullNLLs.push_back( 0.0 );
228
229 RooAbsData *d = GenerateToyData( weights, impNLLs, nullNLLs );
230 return d;
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// This method generates a toy data set for importance sampling for the given parameter point taking
235/// global observables into account.
236/// The values of the generated global observables remain in the pdf's variables.
237/// They have to have those values for the subsequent evaluation of the
238/// test statistics.
239
241 vector<double>& weights,
242 vector<double>& impNLLVals,
243 vector<double>& nullNLLVals
244) const {
245
246
247 ooccoutD((TObject*)0,InputArguments) << endl;
248 ooccoutD((TObject*)0,InputArguments) << "GenerateToyDataImportanceSampling" << endl;
249
250 if(!fObservables) {
251 ooccoutE((TObject*)NULL,InputArguments) << "Observables not set." << endl;
252 return NULL;
253 }
254
255 if( fNullDensities.size() == 0 ) {
256 oocoutE((TObject*)NULL,InputArguments) << "ToyMCImportanceSampler: Need to specify the null density explicitly." << endl;
257 return NULL;
258 }
259
260 // catch the case when NLLs are not created (e.g. when ToyMCSampler was streamed for Proof)
261 if( fNullNLLs.size() == 0 && fNullDensities.size() > 0 ) {
262 for( unsigned int i = 0; i < fNullDensities.size(); i++ ) fNullNLLs.push_back( NULL );
263 }
264 if( fImpNLLs.size() == 0 && fImportanceDensities.size() > 0 ) {
265 for( unsigned int i = 0; i < fImportanceDensities.size(); i++ ) fImpNLLs.push_back( NULL );
266 }
267
268 if( fNullDensities.size() != fNullNLLs.size() ) {
269 oocoutE((TObject*)NULL,InputArguments) << "ToyMCImportanceSampler: Something wrong. NullNLLs must be of same size as null densities." << endl;
270 return NULL;
271 }
272
275 ) {
276 oocoutE((TObject*)NULL,InputArguments) << "ToyMCImportanceSampler: no importance density given or index out of range." << endl;
277 return NULL;
278 }
279
280
281 // paramPoint used to be given as parameter
282 // situation is clear when there is only one null.
283 // WHAT TO DO FOR MANY NULL DENSITIES?
284 RooArgSet paramPoint( *fNullSnapshots[0] );
285 //cout << "paramPoint: " << endl;
286 //paramPoint.Print("v");
287
288
289 // assign input paramPoint
290 RooArgSet* allVars = fPdf->getVariables();
291 allVars->assign(paramPoint);
292
293
294 // create nuisance parameter points
297
298 // generate global observables
299 RooArgSet observables(*fObservables);
301 observables.remove(*fGlobalObservables);
302 // WHAT TODO FOR MANY NULL DENSITIES?
304 }
305
306 // save values to restore later.
307 // but this must remain after(!) generating global observables
308 if( !fGenerateFromNull ) {
309 RooArgSet* allVarsImpDens = fImportanceDensities[fIndexGenDensity]->getVariables();
310 allVars->add(*allVarsImpDens);
311 delete allVarsImpDens;
312 }
313 const RooArgSet* saveVars = (const RooArgSet*)allVars->snapshot();
314
315 double globalWeight = 1.0;
316 if(fNuisanceParametersSampler) { // use nuisance parameters?
317 // Construct a set of nuisance parameters that has the parameters
318 // in the input paramPoint removed. Therefore, no parameter in
319 // paramPoint is randomized.
320 // Therefore when a parameter is given (should be held fixed),
321 // but is also in the list of nuisance parameters, the parameter
322 // will be held fixed. This is useful for debugging to hold single
323 // parameters fixed although under "normal" circumstances it is
324 // randomized.
325 RooArgSet allVarsMinusParamPoint(*allVars);
326 allVarsMinusParamPoint.remove(paramPoint, kFALSE, kTRUE); // match by name
327
328 // get nuisance parameter point and weight
329 fNuisanceParametersSampler->NextPoint(allVarsMinusParamPoint, globalWeight);
330 }
331 // populate input weights vector with this globalWeight
332 for( unsigned int i=0; i < weights.size(); i++ ) weights[i] = globalWeight;
333
334 RooAbsData* data = NULL;
335 if( fGenerateFromNull ) {
336 //cout << "gen from null" << endl;
338 data = Generate(*fNullDensities[fIndexGenDensity], observables);
339 }else{
340 // need to be careful here not to overwrite the current state of the
341 // nuisance parameters, ie they must not be part of the snapshot
342 //cout << "gen from imp" << endl;
345 }
346 data = Generate(*fImportanceDensities[fIndexGenDensity], observables);
347 }
348 //cout << "data generated: " << data << endl;
349
350 if (!data) {
351 oocoutE((TObject*)0,InputArguments) << "ToyMCImportanceSampler: error generating data" << endl;
352 return NULL;
353 }
354
355
356
357 // Importance Sampling: adjust weight
358 // Sources: Alex Read, presentation by Michael Woodroofe
359
360 ooccoutD((TObject*)0,InputArguments) << "About to create/calculate all nullNLLs." << endl;
361 for( unsigned int i=0; i < fNullDensities.size(); i++ ) {
362 //oocoutI((TObject*)0,InputArguments) << "Setting variables to nullSnapshot["<<i<<"]"<<endl;
363 //fNullSnapshots[i]->Print("v");
364
365 allVars->assign(*fNullSnapshots[i]);
366 if( !fNullNLLs[i] ) {
367 RooArgSet* allParams = fNullDensities[i]->getParameters(*data);
368 fNullNLLs[i] = fNullDensities[i]->createNLL(*data, RooFit::CloneData(kFALSE), RooFit::Constrain(*allParams),
370 delete allParams;
371 }else{
372 fNullNLLs[i]->setData( *data, kFALSE );
373 }
374 nullNLLVals[i] = fNullNLLs[i]->getVal();
375 // FOR DEBuGGING!!!!!!!!!!!!!!!!!
376 if( !fReuseNLL ) { delete fNullNLLs[i]; fNullNLLs[i] = NULL; }
377 }
378
379
380 // for each null: find minNLLVal of null and all imp densities
381 ooccoutD((TObject*)0,InputArguments) << "About to find the minimum NLLs." << endl;
382 vector<double> minNLLVals;
383 for( unsigned int i=0; i < nullNLLVals.size(); i++ ) minNLLVals.push_back( nullNLLVals[i] );
384
385 for( unsigned int i=0; i < fImportanceDensities.size(); i++ ) {
386 //oocoutI((TObject*)0,InputArguments) << "Setting variables to impSnapshot["<<i<<"]"<<endl;
387 //fImportanceSnapshots[i]->Print("v");
388
389 if( fImportanceSnapshots[i] ) {
390 allVars->assign(*fImportanceSnapshots[i]);
391 }
392 if( !fImpNLLs[i] ) {
393 RooArgSet* allParams = fImportanceDensities[i]->getParameters(*data);
394 fImpNLLs[i] = fImportanceDensities[i]->createNLL(*data, RooFit::CloneData(kFALSE), RooFit::Constrain(*allParams),
396 delete allParams;
397 }else{
398 fImpNLLs[i]->setData( *data, kFALSE );
399 }
400 impNLLVals[i] = fImpNLLs[i]->getVal();
401 // FOR DEBuGGING!!!!!!!!!!!!!!!!!
402 if( !fReuseNLL ) { delete fImpNLLs[i]; fImpNLLs[i] = NULL; }
403
404 for( unsigned int j=0; j < nullNLLVals.size(); j++ ) {
405 if( impNLLVals[i] < minNLLVals[j] ) minNLLVals[j] = impNLLVals[i];
406 ooccoutD((TObject*)0,InputArguments) << "minNLLVals["<<j<<"]: " << minNLLVals[j] << " nullNLLVals["<<j<<"]: " << nullNLLVals[j] << " impNLLVals["<<i<<"]: " << impNLLVals[i] << endl;
407 }
408 }
409
410 // veto toys: this is a sort of "overlap removal" of the various distributions
411 // if not vetoed: apply weight
412 ooccoutD((TObject*)0,InputArguments) << "About to apply vetos and calculate weights." << endl;
413 for( unsigned int j=0; j < nullNLLVals.size(); j++ ) {
414 if ( fApplyVeto && fGenerateFromNull && minNLLVals[j] != nullNLLVals[j] ) weights[j] = 0.0;
415 else if( fApplyVeto && !fGenerateFromNull && minNLLVals[j] != impNLLVals[fIndexGenDensity] ) weights[j] = 0.0;
416 else if( !fGenerateFromNull ) {
417 // apply (for fImportanceGenNorm, the weight is one, so nothing needs to be done here)
418
419 // L(pdf) / L(imp) = exp( NLL(imp) - NLL(pdf) )
420 weights[j] *= exp(minNLLVals[j] - nullNLLVals[j]);
421 }
422
423 ooccoutD((TObject*)0,InputArguments) << "weights["<<j<<"]: " << weights[j] << endl;
424 }
425
426
427
428 allVars->assign(*saveVars);
429 delete allVars;
430 delete saveVars;
431
432 return data;
433}
434
435////////////////////////////////////////////////////////////////////////////////
436/// poi has to be fitted beforehand. This function expects this to be the muhat value.
437
438int ToyMCImportanceSampler::CreateImpDensitiesForOnePOIAdaptively( RooAbsPdf& pdf, const RooArgSet& allPOI, RooRealVar& poi, double nStdDevOverlap, double poiValueForBackground ) {
439 // these might not necessarily be the same thing.
440 double impMaxMu = poi.getVal();
441
442 // this includes the null
443 int n = 1;
444
445 // check whether error is trustworthy
446 if( poi.getError() > 0.01 && poi.getError() < 5.0 ) {
447 n = TMath::CeilNint( poi.getVal() / (2.*nStdDevOverlap*poi.getError()) ); // round up
448 oocoutI((TObject*)0,InputArguments) << "Using fitFavoredMu and error to set the number of imp points" << endl;
449 oocoutI((TObject*)0,InputArguments) << "muhat: " << poi.getVal() << " optimize for distance: " << 2.*nStdDevOverlap*poi.getError() << endl;
450 oocoutI((TObject*)0,InputArguments) << "n = " << n << endl;
451 oocoutI((TObject*)0,InputArguments) << "This results in a distance of: " << impMaxMu / n << endl;
452 }
453
454 // exclude the null, just return the number of importance snapshots
455 return CreateNImpDensitiesForOnePOI( pdf, allPOI, poi, n-1, poiValueForBackground);
456}
457
458////////////////////////////////////////////////////////////////////////////////
459/// n is the number of importance densities
460
461int ToyMCImportanceSampler::CreateNImpDensitiesForOnePOI( RooAbsPdf& pdf, const RooArgSet& allPOI, RooRealVar& poi, int n, double poiValueForBackground ) {
462
463 // these might not necessarily be the same thing.
464 double impMaxMu = poi.getVal();
465
466 // create imp snapshots
467 if( impMaxMu > poiValueForBackground && n > 0 ) {
468 for( int i=1; i <= n; i++ ) {
469 poi.setVal( poiValueForBackground + (double)i/(n)*(impMaxMu - poiValueForBackground) );
470 oocoutI((TObject*)0,InputArguments) << endl << "create point with poi: " << endl;
471 poi.Print();
472
473 // impSnaps without first snapshot because that is null hypothesis
474
475 AddImportanceDensity( &pdf, &allPOI );
476 }
477 }
478
479 return n;
480}
481
482} // end namespace RooStats
#define d(i)
Definition: RSha256.hxx:102
#define oocoutE(o, a)
Definition: RooMsgService.h:48
#define oocoutI(o, a)
Definition: RooMsgService.h:45
#define ooccoutI(o, a)
Definition: RooMsgService.h:53
#define ooccoutD(o, a)
Definition: RooMsgService.h:52
#define oocoutP(o, a)
Definition: RooMsgService.h:46
#define ooccoutE(o, a)
Definition: RooMsgService.h:56
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
Definition: RooAbsArg.h:323
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2010
Int_t getSize() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
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...
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:79
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Definition: RooAbsData.cxx:375
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:35
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:154
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:27
bool defineType(const std::string &label)
Define a state with given name.
virtual Bool_t setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:36
virtual const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a column with the values of the given (function) argument to this dataset.
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
virtual Double_t weight() const override
Return event weight of current event.
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
Double_t getError() const
Definition: RooRealVar.h:60
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:282
Helper class for ToyMCSampler.
Definition: ToyMCSampler.h:38
void NextPoint(RooArgSet &nuisPoint, Double_t &weight)
Assigns new nuisance parameter point to members of nuisPoint.
ToyMCImportanceSampler is an extension of the ToyMCSampler for Importance Sampling.
void AddImportanceDensity(RooAbsPdf *p, const RooArgSet *s)
std::vector< const RooArgSet * > fImportanceSnapshots
std::vector< const RooArgSet * > fNullSnapshots
void SetDensityToGenerateFromByIndex(unsigned int i, bool fromNull=false)
specifies the pdf to sample from
virtual RooAbsData * GenerateToyData(RooArgSet &paramPoint, double &weight) const
std::vector< RooAbsPdf * > fImportanceDensities
virtual RooDataSet * GetSamplingDistributionsSingleWorker(RooArgSet &paramPoint)
This is the main function for serial runs.
virtual void ClearCache()
clear the cache obtained from the pdf used for speeding the toy and global observables generation nee...
int CreateImpDensitiesForOnePOIAdaptively(RooAbsPdf &pdf, const RooArgSet &allPOI, RooRealVar &poi, double nStdDevOverlap=0.5, double poiValueForBackground=0.0)
poi has to be fitted beforehand. This function expects this to be the muhat value.
std::vector< RooAbsPdf * > fNullDensities
std::vector< RooAbsReal * > fImpNLLs
int CreateNImpDensitiesForOnePOI(RooAbsPdf &pdf, const RooArgSet &allPOI, RooRealVar &poi, int n, double poiValueForBackground=0.0)
n is the number of importance densities
std::vector< RooAbsReal * > fNullNLLs
const RooArgSet * fGlobalObservables
Definition: ToyMCSampler.h:252
virtual void GenerateGlobalObservables(RooAbsPdf &pdf) const
virtual RooDataSet * GetSamplingDistributionsSingleWorker(RooArgSet &paramPoint)
This is the main function for serial runs.
RooAbsData * Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=NULL, int forceEvents=0) const
This is the generate function to use in the context of the ToyMCSampler instead of the standard RooAb...
NuisanceParametersSampler * fNuisanceParametersSampler
Definition: ToyMCSampler.h:276
const RooArgSet * fObservables
Definition: ToyMCSampler.h:251
const RooArgSet * fNuisancePars
Definition: ToyMCSampler.h:250
std::vector< TestStatistic * > fTestStatistics
Definition: ToyMCSampler.h:246
virtual void ClearCache()
clear the cache obtained from the pdf used for speeding the toy and global observables generation nee...
RooAbsPdf * fPriorNuisance
Definition: ToyMCSampler.h:249
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2336
RooCmdArg Constrain(const RooArgSet &params)
RooCmdArg CloneData(Bool_t flag)
RooCmdArg ConditionalObservables(Args_t &&... argsOrArgSet)
Create a RooCmdArg to declare conditional observables.
const Int_t n
Definition: legend1.C:16
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
@ Generation
Definition: RooGlobalFunc.h:60
@ InputArguments
Definition: RooGlobalFunc.h:61
Namespace for the RooStats classes.
Definition: Asimov.h:19
Int_t CeilNint(Double_t x)
Definition: TMath.h:649