Logo ROOT  
Reference Guide
ToyMCSampler.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Sven Kreiss June 2010
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::NuisanceParametersSampler
13 \ingroup Roostats
14
15Helper class for ToyMCSampler. Handles all of the nuisance parameter related
16functions. Once instantiated, it gives a new nuisance parameter point
17at each call to nextPoint(...).
18*/
19
20/** \class RooStats::ToyMCSampler
21 \ingroup Roostats
22
23ToyMCSampler is an implementation of the TestStatSampler interface.
24It generates Toy Monte Carlo for a given parameter point and evaluates a
25TestStatistic.
26
27For parallel runs, ToyMCSampler can be given an instance of ProofConfig
28and then run in parallel using proof or proof-lite. Internally, it uses
29ToyMCStudy with the RooStudyManager.
30*/
31
33
34#include "RooMsgService.h"
35
36#include "RooDataHist.h"
37
38#include "RooRealVar.h"
39
40#include "TCanvas.h"
41#include "RooPlot.h"
42#include "RooRandom.h"
43
44#include "RooStudyManager.h"
45#include "RooStats/ToyMCStudy.h"
48#include "RooSimultaneous.h"
49#include "RooCategory.h"
50
51#include "TMath.h"
52
53
54using namespace RooFit;
55using namespace std;
56
57
59
60namespace RooStats {
61
62////////////////////////////////////////////////////////////////////////////////
63/// Assigns new nuisance parameter point to members of nuisPoint.
64/// nuisPoint can be more objects than just the nuisance
65/// parameters.
66
68
69 // check whether to get new set of nuisanceParPoints
70 if (fIndex >= fNToys) {
71 Refresh();
72 fIndex = 0;
73 }
74
75 // get value
76 nuisPoint.assign(*fPoints->get(fIndex++));
77 weight = fPoints->weight();
78
79 // check whether result will have any influence
80 if(fPoints->weight() == 0.0) {
81 oocoutI((TObject*)NULL,Generation) << "Weight 0 encountered. Skipping." << endl;
82 NextPoint(nuisPoint, weight);
83 }
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Creates the initial set of nuisance parameter points. It also refills the
88/// set with new parameter points if called repeatedly. This helps with
89/// adaptive sampling as the required number of nuisance parameter points
90/// might increase during the run.
91
93
94 if (!fPrior || !fParams) return;
95
96 if (fExpected) {
97 // UNDER CONSTRUCTION
98 oocoutI((TObject*)NULL,InputArguments) << "Using expected nuisance parameters." << endl;
99
100 int nBins = fNToys;
101
102 // From FeldmanCousins.cxx:
103 // set nbins for the POI
105 RooRealVar *myarg2;
106 while ((myarg2 = dynamic_cast<RooRealVar*>(it2.Next()))) {
107 myarg2->setBins(nBins);
108 }
109
110
111 fPoints.reset( fPrior->generate(
112 *fParams,
114 ExpectedData(),
115 NumEvents(1) // for Asimov set, this is only a scale factor
116 ));
117 if(fPoints->numEntries() != fNToys) {
118 fNToys = fPoints->numEntries();
120 "Adjusted number of toys to number of bins of nuisance parameters: " << fNToys << endl;
121 }
122
123/*
124 // check
125 TCanvas *c1 = new TCanvas;
126 RooPlot *p = dynamic_cast<RooRealVar*>(fParams->first())->frame();
127 fPoints->plotOn(p);
128 p->Draw();
129 for(int x=0; x < fPoints->numEntries(); x++) {
130 fPoints->get(x)->Print("v");
131 cout << fPoints->weight() << endl;
132 }
133*/
134
135 }else{
136 oocoutI((TObject*)NULL,InputArguments) << "Using randomized nuisance parameters." << endl;
137
139 }
140}
141
143
144////////////////////////////////////////////////////////////////////////////////
145
147
148////////////////////////////////////////////////////////////////////////////////
149/// Proof constructor. Do not use.
150
151ToyMCSampler::ToyMCSampler() : fSamplingDistName("SD"), fNToys(1)
152{
153
154 fPdf = NULL;
155 fPriorNuisance = NULL;
156 fNuisancePars = NULL;
157 fObservables = NULL;
158 fGlobalObservables = NULL;
159
160 fSize = 0.05;
161 fNEvents = 0;
166
167 fToysInTails = 0.0;
171
172 fProtoData = NULL;
173
174 fProofConfig = NULL;
176
177 //suppress messages for num integration of Roofit
179
181}
182
183////////////////////////////////////////////////////////////////////////////////
184
185ToyMCSampler::ToyMCSampler(TestStatistic &ts, Int_t ntoys) : fSamplingDistName(ts.GetVarName().Data()), fNToys(ntoys)
186{
187 fPdf = NULL;
188 fPriorNuisance = NULL;
189 fNuisancePars = NULL;
190 fObservables = NULL;
191 fGlobalObservables = NULL;
192
193 fSize = 0.05;
194 fNEvents = 0;
199
200 fToysInTails = 0.0;
204
205 fProtoData = NULL;
206
207 fProofConfig = NULL;
209
210 //suppress messages for num integration of Roofit
212
214
215 AddTestStatistic(&ts);
216}
217
218////////////////////////////////////////////////////////////////////////////////
219
222
223 ClearCache();
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// only checks, no guessing/determination (do this in calculators,
228/// e.g. using ModelConfig::GuessObsAndNuisance(...))
229
231 bool goodConfig = true;
232
233 if(fTestStatistics.size() == 0 || fTestStatistics[0] == NULL) { ooccoutE((TObject*)NULL,InputArguments) << "Test statistic not set." << endl; goodConfig = false; }
234 if(!fObservables) { ooccoutE((TObject*)NULL,InputArguments) << "Observables not set." << endl; goodConfig = false; }
235 if(!fParametersForTestStat) { ooccoutE((TObject*)NULL,InputArguments) << "Parameter values used to evaluate the test statistic are not set." << endl; goodConfig = false; }
236 if(!fPdf) { ooccoutE((TObject*)NULL,InputArguments) << "Pdf not set." << endl; goodConfig = false; }
237
238
239 //ooccoutI((TObject*)NULL,InputArguments) << "ToyMCSampler configuration:" << endl;
240 //ooccoutI((TObject*)NULL,InputArguments) << "Pdf from SetPdf: " << fPdf << endl;
241 // for( unsigned int i=0; i < fTestStatistics.size(); i++ ) {
242 // ooccoutI((TObject*)NULL,InputArguments) << "test statistics["<<i<<"]: " << fTestStatistics[i] << endl;
243 // }
244 //ooccoutI((TObject*)NULL,InputArguments) << endl;
245
246 return goodConfig;
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Evaluate all test statistics, returning result and any detailed output.
251/// PDF parameter values are saved in case they are modified by
252/// TestStatistic::Evaluate (eg. SimpleLikelihoodRatioTestStat).
253
255 DetailedOutputAggregator detOutAgg;
256 const RooArgList* allTS = EvaluateAllTestStatistics(data, poi, detOutAgg);
257 if (!allTS) return 0;
258 // no need to delete allTS, it is deleted in destructor of detOutAgg
259 return dynamic_cast<RooArgList*>(allTS->snapshot());
260}
261
262////////////////////////////////////////////////////////////////////////////////
263
265 RooArgSet *allVars = fPdf ? fPdf->getVariables() : nullptr;
266 RooArgSet *saveAll = allVars ? allVars->snapshot() : nullptr;
267 for( unsigned int i = 0; i < fTestStatistics.size(); i++ ) {
268 if( fTestStatistics[i] == NULL ) continue;
269 TString name( TString::Format("%s_TS%u", fSamplingDistName.c_str(), i) );
270 std::unique_ptr<RooArgSet> parForTS(poi.snapshot());
271 RooRealVar ts( name, fTestStatistics[i]->GetVarName(), fTestStatistics[i]->Evaluate( data, *parForTS ) );
272 RooArgList tset(ts);
273 detOutAgg.AppendArgSet(&tset);
274 if (const RooArgSet* detOut = fTestStatistics[i]->GetDetailedOutput()) {
275 name.Append("_");
276 detOutAgg.AppendArgSet(detOut, name);
277 }
278 if (saveAll) {
279 // restore values, perhaps modified by fTestStatistics[i]->Evaluate()
280 allVars->assign(*saveAll);
281 }
282 }
283 delete saveAll;
284 delete allVars;
285 return detOutAgg.GetAsArgList();
286}
287
288////////////////////////////////////////////////////////////////////////////////
289
291 if(fTestStatistics.size() > 1) {
292 oocoutW((TObject*)NULL, InputArguments) << "Multiple test statistics defined, but only one distribution will be returned." << endl;
293 for( unsigned int i=0; i < fTestStatistics.size(); i++ ) {
294 oocoutW((TObject*)NULL, InputArguments) << " \t test statistic: " << fTestStatistics[i] << endl;
295 }
296 }
297
298 RooDataSet* r = GetSamplingDistributions(paramPointIn);
299 if(r == NULL || r->numEntries() == 0) {
300 oocoutW((TObject*)NULL, Generation) << "no sampling distribution generated" << endl;
301 return NULL;
302 }
303
305 delete r;
306 return samp;
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Use for serial and parallel runs.
311
313{
314
315 // ======= S I N G L E R U N ? =======
316 if(!fProofConfig)
317 return GetSamplingDistributionsSingleWorker(paramPointIn);
318
319 // ======= P A R A L L E L R U N =======
320 if (!CheckConfig()){
322 << "Bad COnfiguration in ToyMCSampler "
323 << endl;
324 return nullptr;
325 }
326
327 // turn adaptive sampling off if given
328 if(fToysInTails) {
329 fToysInTails = 0;
331 << "Adaptive sampling in ToyMCSampler is not supported for parallel runs."
332 << endl;
333 }
334
335 // adjust number of toys on the slaves to keep the total number of toys constant
336 Int_t totToys = fNToys;
337 fNToys = (int)ceil((double)fNToys / (double)fProofConfig->GetNExperiments()); // round up
338
339 // create the study instance for parallel processing
340 ToyMCStudy* toymcstudy = new ToyMCStudy ;
341 toymcstudy->SetToyMCSampler(*this);
342 toymcstudy->SetParamPoint(paramPointIn);
344
345 // temporary workspace for proof to avoid messing with TRef
347 RooStudyManager studymanager(w, *toymcstudy);
349
350 RooDataSet* output = toymcstudy->merge();
351
352 // reset the number of toys
353 fNToys = totToys;
354
355 delete toymcstudy;
356 return output;
357}
358
359////////////////////////////////////////////////////////////////////////////////
360/// This is the main function for serial runs. It is called automatically
361/// from inside GetSamplingDistribution when no ProofConfig is given.
362/// You should not call this function yourself. This function should
363/// be used by ToyMCStudy on the workers (ie. when you explicitly want
364/// a serial run although ProofConfig is present).
365///
366
368{
369 // Make sure the cache is clear. It is important to clear it here, because
370 // the cache might be invalid even when just the firstPOI was changed, for which
371 // no accessor has to be called. (Fixes a bug when ToyMCSampler is
372 // used with the Neyman Construction)
373 ClearCache();
374
375 if (!CheckConfig()){
377 << "Bad COnfiguration in ToyMCSampler "
378 << endl;
379 return nullptr;
380 }
381
382 // important to cache the paramPoint b/c test statistic might
383 // modify it from event to event
384 RooArgSet *paramPoint = (RooArgSet*) paramPointIn.snapshot();
385 RooArgSet *allVars = fPdf->getVariables();
386 RooArgSet *saveAll = (RooArgSet*) allVars->snapshot();
387
388
389 DetailedOutputAggregator detOutAgg;
390
391 // counts the number of toys in the limits set for adaptive sampling
392 // (taking weights into account; always on first test statistic)
393 Double_t toysInTails = 0.0;
394
395 for (Int_t i = 0; i < fMaxToys; ++i) {
396 // need to check at the beginning for case that zero toys are requested
397 if (toysInTails >= fToysInTails && i+1 > fNToys) break;
398
399 // status update
400 if ( i% 500 == 0 && i>0 ) {
401 oocoutP((TObject*)0,Generation) << "generated toys: " << i << " / " << fNToys;
402 if (fToysInTails) ooccoutP((TObject*)0,Generation) << " (tails: " << toysInTails << " / " << fToysInTails << ")" << std::endl;
403 else ooccoutP((TObject*)0,Generation) << endl;
404 }
405
406 // TODO: change this treatment to keep track of all values so that the threshold
407 // for adaptive sampling is counted for all distributions and not just the
408 // first one.
409 Double_t valueFirst = -999.0, weight = 1.0;
410
411 // set variables to requested parameter point
412 allVars->assign(*saveAll); // important for example for SimpleLikelihoodRatioTestStat
413
414 RooAbsData* toydata = GenerateToyData(*paramPoint, weight);
415 if (i == 0 && !fPdf->canBeExtended() && dynamic_cast<RooSimultaneous*>(fPdf)) {
416 const RooArgSet* toySet = toydata->get();
417 if (std::none_of(toySet->begin(), toySet->end(), [](const RooAbsArg* arg){
418 return dynamic_cast<const RooAbsCategory*>(arg) != nullptr;
419 }))
420 oocoutE((TObject*)nullptr, Generation) << "ToyMCSampler: Generated toy data didn't contain a category variable, although"
421 " a simultaneous PDF is in use. To generate events for a simultaneous PDF, all components need to be"
422 " extended. Otherwise, the number of events to generate per component cannot be determined." << std::endl;
423 }
424
426
427 const RooArgList* allTS = EvaluateAllTestStatistics(*toydata, *fParametersForTestStat, detOutAgg);
428 if (allTS->getSize() > Int_t(fTestStatistics.size()))
429 detOutAgg.AppendArgSet( fGlobalObservables, "globObs_" );
430 if (RooRealVar* firstTS = dynamic_cast<RooRealVar*>(allTS->first()))
431 valueFirst = firstTS->getVal();
432
433 delete toydata;
434
435 // check for nan
436 if(valueFirst != valueFirst) {
437 oocoutW((TObject*)NULL, Generation) << "skip: " << valueFirst << ", " << weight << endl;
438 continue;
439 }
440
441 detOutAgg.CommitSet(weight);
442
443 // adaptive sampling checks
444 if (valueFirst <= fAdaptiveLowLimit || valueFirst >= fAdaptiveHighLimit) {
445 if(weight >= 0.) toysInTails += weight;
446 else toysInTails += 1.;
447 }
448 }
449
450 // clean up
451 allVars->assign(*saveAll);
452 delete saveAll;
453 delete allVars;
454 delete paramPoint;
455
457}
458
459////////////////////////////////////////////////////////////////////////////////
460
462
463
465 ooccoutE((TObject*)NULL,InputArguments) << "Global Observables not set." << endl;
466 return;
467 }
468
469
471
472 // generate one set of global observables and assign it
473 // has problem for sim pdfs
474 RooSimultaneous* simPdf = dynamic_cast<RooSimultaneous*>( &pdf );
475 if (!simPdf) {
476 RooDataSet *one = pdf.generate(*fGlobalObservables, 1);
477
478 const RooArgSet *values = one->get(0);
479 if (!_allVars) {
480 _allVars.reset(pdf.getVariables());
481 }
482 _allVars->assign(*values);
483 delete one;
484
485 } else {
486
487 if (_pdfList.size() == 0) {
488 RooCategory& channelCat = (RooCategory&)simPdf->indexCat();
489 int nCat = channelCat.numTypes();
490 for (int i=0; i < nCat; ++i){
491 channelCat.setIndex(i);
492 RooAbsPdf* pdftmp = simPdf->getPdf(channelCat.getCurrentLabel());
493 assert(pdftmp);
494 RooArgSet* globtmp = pdftmp->getObservables(*fGlobalObservables);
495 RooAbsPdf::GenSpec* gs = pdftmp->prepareMultiGen(*globtmp, NumEvents(1));
496 _pdfList.push_back(pdftmp);
497 _obsList.emplace_back(globtmp);
498 _gsList.emplace_back(gs);
499 }
500 }
501
502 // Assign generated values to the observables in _obsList
503 for (unsigned int i = 0; i < _pdfList.size(); ++i) {
504 std::unique_ptr<RooDataSet> tmp( _pdfList[i]->generate(*_gsList[i]) );
505 _obsList[i]->assign(*tmp->get(0));
506 }
507 }
508
509
510 } else {
511
512 // not using multigen for global observables
514 const RooArgSet *values = one->get(0);
515 RooArgSet* allVars = pdf.getVariables();
516 allVars->assign(*values);
517 delete allVars;
518 delete one;
519
520 }
521}
522
523////////////////////////////////////////////////////////////////////////////////
524/// This method generates a toy data set for the given parameter point taking
525/// global observables into account.
526/// The values of the generated global observables remain in the pdf's variables.
527/// They have to have those values for the subsequent evaluation of the
528/// test statistics.
529
530RooAbsData* ToyMCSampler::GenerateToyData(RooArgSet& paramPoint, double& weight, RooAbsPdf& pdf) const {
531
532 if(!fObservables) {
533 ooccoutE((TObject*)NULL,InputArguments) << "Observables not set." << endl;
534 return NULL;
535 }
536
537 // assign input paramPoint
538 RooArgSet* allVars = fPdf->getVariables();
539 allVars->assign(paramPoint);
540
541
542 // create nuisance parameter points
546 oocoutI((TObject*)NULL,InputArguments) << "Cannot use multigen when nuisance parameters vary for every toy" << endl;
547 }
548
549 // generate global observables
550 RooArgSet observables(*fObservables);
552 observables.remove(*fGlobalObservables);
554 }
555
556 // save values to restore later.
557 // but this must remain after(!) generating global observables
558 const RooArgSet* saveVars = (const RooArgSet*)allVars->snapshot();
559
560 if(fNuisanceParametersSampler) { // use nuisance parameters?
561 // Construct a set of nuisance parameters that has the parameters
562 // in the input paramPoint removed. Therefore, no parameter in
563 // paramPoint is randomized.
564 // Therefore when a parameter is given (should be held fixed),
565 // but is also in the list of nuisance parameters, the parameter
566 // will be held fixed. This is useful for debugging to hold single
567 // parameters fixed although under "normal" circumstances it is
568 // randomized.
569 RooArgSet allVarsMinusParamPoint(*allVars);
570 allVarsMinusParamPoint.remove(paramPoint, kFALSE, kTRUE); // match by name
571
572 // get nuisance parameter point and weight
573 fNuisanceParametersSampler->NextPoint(allVarsMinusParamPoint, weight);
574
575
576 }else{
577 weight = 1.0;
578 }
579
580 RooAbsData *data = Generate(pdf, observables);
581
582 // We generated the data with the randomized nuisance parameter (if hybrid)
583 // but now we are setting the nuisance parameters back to where they were.
584 allVars->assign(*saveVars);
585 delete allVars;
586 delete saveVars;
587
588 return data;
589}
590
591////////////////////////////////////////////////////////////////////////////////
592/// This is the generate function to use in the context of the ToyMCSampler
593/// instead of the standard RooAbsPdf::generate(...).
594/// It takes into account whether the number of events is given explicitly
595/// or whether it should use the expected number of events. It also takes
596/// into account the option to generate a binned data set (*i.e.* RooDataHist).
597
598RooAbsData* ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet* protoData, int forceEvents) const {
599
600 if(fProtoData) {
601 protoData = fProtoData;
602 forceEvents = protoData->numEntries();
603 }
604
605 RooAbsData *data = NULL;
606 int events = forceEvents;
607 if(events == 0) events = fNEvents;
608
609 // cannot use multigen when the nuisance parameters change for every toy
611
612 if (events == 0) {
613 if (pdf.canBeExtended() && pdf.expectedEvents(observables) > 0) {
614 if(fGenerateBinned) {
615 if(protoData) data = pdf.generate(observables, AllBinned(), Extended(), ProtoData(*protoData, true, true));
616 else data = pdf.generate(observables, AllBinned(), Extended());
617 } else {
618 if (protoData) {
619 if (useMultiGen) {
620 if (!_gs2) _gs2.reset( pdf.prepareMultiGen(observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true)) );
621 data = pdf.generate(*_gs2) ;
622 } else {
623 data = pdf.generate (observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true));
624 }
625 } else {
626 if (useMultiGen) {
628 data = pdf.generate(*_gs1) ;
629 } else {
631 }
632
633 }
634 }
635 } else {
637 << "ToyMCSampler: Error : pdf is not extended and number of events per toy is zero"
638 << endl;
639 }
640 } else {
641 if (fGenerateBinned) {
642 if(protoData) data = pdf.generate(observables, events, AllBinned(), ProtoData(*protoData, true, true));
643 else data = pdf.generate(observables, events, AllBinned());
644 } else {
645 if (protoData) {
646 if (useMultiGen) {
647 if (!_gs3) _gs3.reset( pdf.prepareMultiGen(observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true)) );
648 data = pdf.generate(*_gs3) ;
649 } else {
650 data = pdf.generate (observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true));
651 }
652 } else {
653 if (useMultiGen) {
655 data = pdf.generate(*_gs4) ;
656 } else {
657 data = pdf.generate (observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag));
658 }
659 }
660 }
661 }
662
663 return data;
664}
665
666////////////////////////////////////////////////////////////////////////////////
667/// Extended interface to append to sampling distribution more samples
668
670 RooArgSet& allParameters,
672 Int_t additionalMC)
673{
674 Int_t tmp = fNToys;
675 fNToys = additionalMC;
676 SamplingDistribution* newSamples = GetSamplingDistribution(allParameters);
677 fNToys = tmp;
678
679 if(last){
680 last->Add(newSamples);
681 delete newSamples;
682 return last;
683 }
684
685 return newSamples;
686}
687
688////////////////////////////////////////////////////////////////////////////////
689/// clear the cache obtained from the pdf used for speeding the toy and global observables generation
690/// needs to be called every time the model pdf (fPdf) changes
691
693 _gs1 = nullptr;
694 _gs2 = nullptr;
695 _gs3 = nullptr;
696 _gs4 = nullptr;
697 _allVars = nullptr;
698
699 // no need to delete the _pdfList since it is managed by the RooSimultaneous object
700 if (_pdfList.size() > 0) {
701 _pdfList.clear();
702 _obsList.clear();
703 _gsList.clear();
704 }
705}
706
707} // end namespace RooStats
double
Definition: Converters.cxx:939
ROOT::R::TRInterface & r
Definition: Object.C:4
#define oocoutW(o, a)
Definition: RooMsgService.h:47
#define oocoutE(o, a)
Definition: RooMsgService.h:48
#define oocoutI(o, a)
Definition: RooMsgService.h:45
#define ooccoutP(o, a)
Definition: RooMsgService.h:54
#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
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
char name[80]
Definition: TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Given a set of possible observables, return the observables that this PDF depends on.
Definition: RooAbsArg.h:295
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2010
virtual const char * getCurrentLabel() const
Return label string of current state.
Int_t numTypes(const char *=0) const
Return number of types defined (in range named rangeName if rangeName!=0)
Int_t getSize() const
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
const_iterator end() const
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...
RooAbsArg * first() const
const_iterator begin() const
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:79
virtual const RooArgSet * get() const
Definition: RooAbsData.h:125
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Definition: RooAbsData.cxx:375
GenSpec * prepareMultiGen(const RooArgSet &whatVars, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none())
Prepare GenSpec configuration object for efficient generation of multiple datasets from identical spe...
Definition: RooAbsPdf.cxx:2144
Bool_t canBeExtended() const
If true, PDF can provide extended likelihood term.
Definition: RooAbsPdf.h:263
RooDataSet * generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition: RooAbsPdf.h:57
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
Definition: RooAbsPdf.cxx:3300
virtual RooDataSet * generateSimGlobal(const RooArgSet &whatVars, Int_t nEvents)
Special generator interface for generation of 'global observables' – for RooStats tools.
Definition: RooAbsPdf.cxx:2650
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
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
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'.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
static Double_t infinity()
Return internal infinity representation.
Definition: RooNumber.cxx:49
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:53
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
Definition: RooRealVar.cxx:433
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const RooAbsCategoryLValue & indexCat() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
This class is designed to aid in the construction of RooDataSets and RooArgSets, particularly those n...
void AppendArgSet(const RooAbsCollection *aset, TString prefix="")
For each variable in aset, prepend prefix to its name and add to the internal store.
RooDataSet * GetAsDataSet(TString name, TString title)
Returns all detailed output as a dataset.
void CommitSet(double weight=1.0)
Commit to the result RooDataSet.
Helper class for ToyMCSampler.
Definition: ToyMCSampler.h:38
void Refresh()
Creates the initial set of nuisance parameter points.
void NextPoint(RooArgSet &nuisPoint, Double_t &weight)
Assigns new nuisance parameter point to members of nuisPoint.
std::unique_ptr< RooAbsData > fPoints
Definition: ToyMCSampler.h:63
RooWorkspace & GetWorkspace(void) const
Definition: ProofConfig.h:95
Int_t GetNExperiments(void) const
Definition: ProofConfig.h:99
const char * GetHost(void) const
Definition: ProofConfig.h:97
Bool_t GetShowGui(void) const
Definition: ProofConfig.h:101
This class simply holds a sampling distribution of some test statistic.
void Add(const SamplingDistribution *other)
merge two sampling distributions
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
Definition: TestStatistic.h:31
ToyMCSampler is an implementation of the TestStatSampler interface.
Definition: ToyMCSampler.h:67
const RooArgSet * fGlobalObservables
Definition: ToyMCSampler.h:252
std::string fSamplingDistName
Definition: ToyMCSampler.h:248
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...
std::unique_ptr< const RooArgSet > fParametersForTestStat
Definition: ToyMCSampler.h:245
virtual SamplingDistribution * AppendSamplingDistribution(RooArgSet &allParameters, SamplingDistribution *last, Int_t additionalMC)
Extended interface to append to sampling distribution more samples.
NuisanceParametersSampler * fNuisanceParametersSampler
Definition: ToyMCSampler.h:276
std::unique_ptr< RooAbsPdf::GenSpec > _gs4
GenSpec #3.
Definition: ToyMCSampler.h:286
const RooArgSet * fObservables
Definition: ToyMCSampler.h:251
virtual RooArgList * EvaluateAllTestStatistics(RooAbsData &data, const RooArgSet &poi)
Evaluate all test statistics, returning result and any detailed output.
std::unique_ptr< RooAbsPdf::GenSpec > _gs1
Definition: ToyMCSampler.h:283
virtual RooDataSet * GetSamplingDistributions(RooArgSet &paramPoint)
Use for serial and parallel runs.
Bool_t CheckConfig(void)
only checks, no guessing/determination (do this in calculators, e.g.
static Bool_t fgAlwaysUseMultiGen
GenSpec #4.
Definition: ToyMCSampler.h:288
virtual RooAbsData * GenerateToyData(RooArgSet &paramPoint, RooAbsPdf &pdf) const
Definition: ToyMCSampler.h:106
std::unique_ptr< RooAbsPdf::GenSpec > _gs2
GenSpec #1.
Definition: ToyMCSampler.h:284
virtual void AddTestStatistic(TestStatistic *t=NULL)
Definition: ToyMCSampler.h:93
const RooArgSet * fNuisancePars
Definition: ToyMCSampler.h:250
static void SetAlwaysUseMultiGen(Bool_t flag)
std::unique_ptr< RooAbsPdf::GenSpec > _gs3
GenSpec #2.
Definition: ToyMCSampler.h:285
std::vector< TestStatistic * > fTestStatistics
Definition: ToyMCSampler.h:246
ToyMCSampler()
Proof constructor. Do not use.
std::unique_ptr< RooArgSet > _allVars
Definition: ToyMCSampler.h:279
std::vector< RooAbsPdf * > _pdfList
Definition: ToyMCSampler.h:280
virtual void ClearCache()
clear the cache obtained from the pdf used for speeding the toy and global observables generation nee...
ProofConfig * fProofConfig
Definition: ToyMCSampler.h:274
std::vector< std::unique_ptr< RooArgSet > > _obsList
We don't own those objects.
Definition: ToyMCSampler.h:281
const RooDataSet * fProtoData
Definition: ToyMCSampler.h:272
virtual SamplingDistribution * GetSamplingDistribution(RooArgSet &paramPoint)
std::vector< std::unique_ptr< RooAbsPdf::GenSpec > > _gsList
Definition: ToyMCSampler.h:282
RooAbsPdf * fPriorNuisance
Definition: ToyMCSampler.h:249
ToyMCStudy is an implementation of RooAbsStudy for toy Monte Carlo sampling.
Definition: ToyMCStudy.h:30
void SetToyMCSampler(ToyMCSampler &t)
Definition: ToyMCStudy.h:55
void SetParamPoint(const RooArgSet &paramPoint)
Definition: ToyMCStudy.h:56
void SetRandomSeed(unsigned int seed)
Definition: ToyMCStudy.h:58
RooDataSet * merge()
Definition: ToyMCStudy.cxx:101
RooStudyManager is a utility class to manage studies that consist of repeated applications of generat...
void runProof(Int_t nExperiments, const char *proofHost="", Bool_t showGui=kTRUE)
Open PROOF-Lite session.
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
TObject * Next()
Definition: TCollection.h:251
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:403
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition: TRandom.cxx:360
Basic string class.
Definition: TString.h:136
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 Extended(Bool_t flag=kTRUE)
RooCmdArg ProtoData(const RooDataSet &protoData, Bool_t randomizeOrder=kFALSE, Bool_t resample=kFALSE)
RooCmdArg AllBinned()
RooCmdArg AutoBinned(Bool_t flag=kTRUE)
RooCmdArg NumEvents(Int_t numEvents)
RooCmdArg GenBinned(const char *tag)
RooCmdArg ExpectedData(Bool_t flag=kTRUE)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
@ Generation
Definition: RooGlobalFunc.h:60
@ NumIntegration
Definition: RooGlobalFunc.h:62
@ InputArguments
Definition: RooGlobalFunc.h:61
Namespace for the RooStats classes.
Definition: Asimov.h:19
void removeTopic(RooFit::MsgTopic oldTopic)
static void output(int code)
Definition: gifencode.c:226