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
67void NuisanceParametersSampler::NextPoint(RooArgSet& nuisPoint, double& weight) {
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(nullptr,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(nullptr,InputArguments) << "Using expected nuisance parameters." << endl;
99
100 int nBins = fNToys;
101
102 // From FeldmanCousins.cxx:
103 // set nbins for the POI
104 for (auto *myarg2 : static_range_cast<RooRealVar *>(*fParams)) {
105 myarg2->setBins(nBins);
106 }
107
108
109 fPoints.reset( fPrior->generate(
110 *fParams,
111 AllBinned(),
113 NumEvents(1) // for Asimov set, this is only a scale factor
114 ));
115 if(fPoints->numEntries() != fNToys) {
116 fNToys = fPoints->numEntries();
117 oocoutI(nullptr,InputArguments) <<
118 "Adjusted number of toys to number of bins of nuisance parameters: " << fNToys << endl;
119 }
120
121/*
122 // check
123 TCanvas *c1 = new TCanvas;
124 RooPlot *p = dynamic_cast<RooRealVar*>(fParams->first())->frame();
125 fPoints->plotOn(p);
126 p->Draw();
127 for(int x=0; x < fPoints->numEntries(); x++) {
128 fPoints->get(x)->Print("v");
129 cout << fPoints->weight() << endl;
130 }
131*/
132
133 }else{
134 oocoutI(nullptr,InputArguments) << "Using randomized nuisance parameters." << endl;
135
137 }
138}
139
141
142////////////////////////////////////////////////////////////////////////////////
143
145
146////////////////////////////////////////////////////////////////////////////////
147/// Proof constructor. Do not use.
148
149ToyMCSampler::ToyMCSampler() : fSamplingDistName("SD"), fNToys(1)
150{
151
152 fPdf = nullptr;
153 fPriorNuisance = nullptr;
154 fNuisancePars = nullptr;
155 fObservables = nullptr;
156 fGlobalObservables = nullptr;
157
158 fSize = 0.05;
159 fNEvents = 0;
160 fGenerateBinned = false;
162 fGenerateAutoBinned = true;
163 fExpectedNuisancePar = false;
164
165 fToysInTails = 0.0;
169
170 fProtoData = nullptr;
171
172 fProofConfig = nullptr;
174
175 //suppress messages for num integration of Roofit
177
178 fUseMultiGen = false ;
179}
180
181////////////////////////////////////////////////////////////////////////////////
182
183ToyMCSampler::ToyMCSampler(TestStatistic &ts, Int_t ntoys) : fSamplingDistName(ts.GetVarName().Data()), fNToys(ntoys)
184{
185 fPdf = nullptr;
186 fPriorNuisance = nullptr;
187 fNuisancePars = nullptr;
188 fObservables = nullptr;
189 fGlobalObservables = nullptr;
190
191 fSize = 0.05;
192 fNEvents = 0;
193 fGenerateBinned = false;
195 fGenerateAutoBinned = true;
196 fExpectedNuisancePar = false;
197
198 fToysInTails = 0.0;
202
203 fProtoData = nullptr;
204
205 fProofConfig = nullptr;
207
208 //suppress messages for num integration of Roofit
210
211 fUseMultiGen = false ;
212
213 AddTestStatistic(&ts);
214}
215
216////////////////////////////////////////////////////////////////////////////////
217
220
221 ClearCache();
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// only checks, no guessing/determination (do this in calculators,
226/// e.g. using ModelConfig::GuessObsAndNuisance(...))
227
229 bool goodConfig = true;
230
231 if(fTestStatistics.empty() || fTestStatistics[0] == nullptr) { ooccoutE(nullptr,InputArguments) << "Test statistic not set." << endl; goodConfig = false; }
232 if(!fObservables) { ooccoutE(nullptr,InputArguments) << "Observables not set." << endl; goodConfig = false; }
233 if(!fParametersForTestStat) { ooccoutE(nullptr,InputArguments) << "Parameter values used to evaluate the test statistic are not set." << endl; goodConfig = false; }
234 if(!fPdf) { ooccoutE(nullptr,InputArguments) << "Pdf not set." << endl; goodConfig = false; }
235
236 return goodConfig;
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Evaluate all test statistics, returning result and any detailed output.
241/// PDF parameter values are saved in case they are modified by
242/// TestStatistic::Evaluate (eg. SimpleLikelihoodRatioTestStat).
243
245 DetailedOutputAggregator detOutAgg;
246 const RooArgList* allTS = EvaluateAllTestStatistics(data, poi, detOutAgg);
247 if (!allTS) return 0;
248 // no need to delete allTS, it is deleted in destructor of detOutAgg
249 return dynamic_cast<RooArgList*>(allTS->snapshot());
250}
251
252////////////////////////////////////////////////////////////////////////////////
253
255 std::unique_ptr<RooArgSet> allVars;
256 std::unique_ptr<RooArgSet> saveAll;
257 if(fPdf) {
258 allVars.reset(fPdf->getVariables());
259 }
260 if(allVars) {
261 saveAll = std::make_unique<RooArgSet>();
262 allVars->snapshot(*saveAll);
263 }
264 for( unsigned int i = 0; i < fTestStatistics.size(); i++ ) {
265 if( fTestStatistics[i] == nullptr ) continue;
266 TString name( TString::Format("%s_TS%u", fSamplingDistName.c_str(), i) );
267 RooArgSet parForTS;
268 poi.snapshot(parForTS);
269 RooRealVar ts( name, fTestStatistics[i]->GetVarName(), fTestStatistics[i]->Evaluate( data, parForTS ) );
270 RooArgList tset(ts);
271 detOutAgg.AppendArgSet(&tset);
272 if (const RooArgSet* detOut = fTestStatistics[i]->GetDetailedOutput()) {
273 name.Append("_");
274 detOutAgg.AppendArgSet(detOut, name);
275 }
276 if (saveAll) {
277 // restore values, perhaps modified by fTestStatistics[i]->Evaluate()
278 allVars->assign(*saveAll);
279 }
280 }
281 return detOutAgg.GetAsArgList();
282}
283
284////////////////////////////////////////////////////////////////////////////////
285
287 if(fTestStatistics.size() > 1) {
288 oocoutW(nullptr, InputArguments) << "Multiple test statistics defined, but only one distribution will be returned." << endl;
289 for( unsigned int i=0; i < fTestStatistics.size(); i++ ) {
290 oocoutW(nullptr, InputArguments) << " \t test statistic: " << fTestStatistics[i] << endl;
291 }
292 }
293
294 RooDataSet* r = GetSamplingDistributions(paramPointIn);
295 if(r == nullptr || r->numEntries() == 0) {
296 oocoutW(nullptr, Generation) << "no sampling distribution generated" << endl;
297 return nullptr;
298 }
299
300 SamplingDistribution* samp = new SamplingDistribution( r->GetName(), r->GetTitle(), *r );
301 delete r;
302 return samp;
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Use for serial and parallel runs.
307
309{
310
311 // ======= S I N G L E R U N ? =======
312 if(!fProofConfig)
313 return GetSamplingDistributionsSingleWorker(paramPointIn);
314
315 // ======= P A R A L L E L R U N =======
316 if (!CheckConfig()){
317 oocoutE(nullptr, InputArguments)
318 << "Bad COnfiguration in ToyMCSampler "
319 << endl;
320 return nullptr;
321 }
322
323 // turn adaptive sampling off if given
324 if(fToysInTails) {
325 fToysInTails = 0;
326 oocoutW(nullptr, InputArguments)
327 << "Adaptive sampling in ToyMCSampler is not supported for parallel runs."
328 << endl;
329 }
330
331 // adjust number of toys on the slaves to keep the total number of toys constant
332 Int_t totToys = fNToys;
333 fNToys = (int)ceil((double)fNToys / (double)fProofConfig->GetNExperiments()); // round up
334
335 // create the study instance for parallel processing
336 ToyMCStudy* toymcstudy = new ToyMCStudy ;
337 toymcstudy->SetToyMCSampler(*this);
338 toymcstudy->SetParamPoint(paramPointIn);
340
341 // temporary workspace for proof to avoid messing with TRef
343 RooStudyManager studymanager(w, *toymcstudy);
345
346 RooDataSet* output = toymcstudy->merge();
347
348 // reset the number of toys
349 fNToys = totToys;
350
351 delete toymcstudy;
352 return output;
353}
354
355////////////////////////////////////////////////////////////////////////////////
356/// This is the main function for serial runs. It is called automatically
357/// from inside GetSamplingDistribution when no ProofConfig is given.
358/// You should not call this function yourself. This function should
359/// be used by ToyMCStudy on the workers (ie. when you explicitly want
360/// a serial run although ProofConfig is present).
361///
362
364{
365 // Make sure the cache is clear. It is important to clear it here, because
366 // the cache might be invalid even when just the firstPOI was changed, for which
367 // no accessor has to be called. (Fixes a bug when ToyMCSampler is
368 // used with the Neyman Construction)
369 ClearCache();
370
371 if (!CheckConfig()){
372 oocoutE(nullptr, InputArguments)
373 << "Bad COnfiguration in ToyMCSampler "
374 << endl;
375 return nullptr;
376 }
377
378 // important to cache the paramPoint b/c test statistic might
379 // modify it from event to event
380 RooArgSet *paramPoint = (RooArgSet*) paramPointIn.snapshot();
381 RooArgSet *allVars = fPdf->getVariables();
382 RooArgSet *saveAll = (RooArgSet*) allVars->snapshot();
383
384
385 DetailedOutputAggregator detOutAgg;
386
387 // counts the number of toys in the limits set for adaptive sampling
388 // (taking weights into account; always on first test statistic)
389 double toysInTails = 0.0;
390
391 for (Int_t i = 0; i < fMaxToys; ++i) {
392 // need to check at the beginning for case that zero toys are requested
393 if (toysInTails >= fToysInTails && i+1 > fNToys) break;
394
395 // status update
396 if ( i% 500 == 0 && i>0 ) {
397 oocoutP(nullptr,Generation) << "generated toys: " << i << " / " << fNToys;
398 if (fToysInTails) ooccoutP(nullptr,Generation) << " (tails: " << toysInTails << " / " << fToysInTails << ")" << std::endl;
399 else ooccoutP(nullptr,Generation) << endl;
400 }
401
402 // TODO: change this treatment to keep track of all values so that the threshold
403 // for adaptive sampling is counted for all distributions and not just the
404 // first one.
405 double valueFirst = -999.0, weight = 1.0;
406
407 // set variables to requested parameter point
408 allVars->assign(*saveAll); // important for example for SimpleLikelihoodRatioTestStat
409
410 RooAbsData* toydata = GenerateToyData(*paramPoint, weight);
411 if (i == 0 && !fPdf->canBeExtended() && dynamic_cast<RooSimultaneous*>(fPdf)) {
412 const RooArgSet* toySet = toydata->get();
413 if (std::none_of(toySet->begin(), toySet->end(), [](const RooAbsArg* arg){
414 return dynamic_cast<const RooAbsCategory*>(arg) != nullptr;
415 }))
416 oocoutE(nullptr, Generation) << "ToyMCSampler: Generated toy data didn't contain a category variable, although"
417 " a simultaneous PDF is in use. To generate events for a simultaneous PDF, all components need to be"
418 " extended. Otherwise, the number of events to generate per component cannot be determined." << std::endl;
419 }
420
422
423 const RooArgList* allTS = EvaluateAllTestStatistics(*toydata, *fParametersForTestStat, detOutAgg);
424 if (allTS->getSize() > Int_t(fTestStatistics.size()))
425 detOutAgg.AppendArgSet( fGlobalObservables, "globObs_" );
426 if (RooRealVar* firstTS = dynamic_cast<RooRealVar*>(allTS->first()))
427 valueFirst = firstTS->getVal();
428
429 delete toydata;
430
431 // check for nan
432 if(valueFirst != valueFirst) {
433 oocoutW(nullptr, Generation) << "skip: " << valueFirst << ", " << weight << endl;
434 continue;
435 }
436
437 detOutAgg.CommitSet(weight);
438
439 // adaptive sampling checks
440 if (valueFirst <= fAdaptiveLowLimit || valueFirst >= fAdaptiveHighLimit) {
441 if(weight >= 0.) toysInTails += weight;
442 else toysInTails += 1.;
443 }
444 }
445
446 // clean up
447 allVars->assign(*saveAll);
448 delete saveAll;
449 delete allVars;
450 delete paramPoint;
451
453}
454
455////////////////////////////////////////////////////////////////////////////////
456
458
459
461 ooccoutE(nullptr,InputArguments) << "Global Observables not set." << endl;
462 return;
463 }
464
465
467
468 // generate one set of global observables and assign it
469 // has problem for sim pdfs
470 RooSimultaneous* simPdf = dynamic_cast<RooSimultaneous*>( &pdf );
471 if (!simPdf) {
472 RooDataSet *one = pdf.generate(*fGlobalObservables, 1);
473
474 const RooArgSet *values = one->get(0);
475 if (!_allVars) {
476 _allVars.reset(pdf.getVariables());
477 }
478 _allVars->assign(*values);
479 delete one;
480
481 } else {
482
483 if (_pdfList.empty()) {
484 RooCategory& channelCat = (RooCategory&)simPdf->indexCat();
485 int nCat = channelCat.numTypes();
486 for (int i=0; i < nCat; ++i){
487 channelCat.setIndex(i);
488 RooAbsPdf* pdftmp = simPdf->getPdf(channelCat.getCurrentLabel());
489 assert(pdftmp);
490 RooArgSet* globtmp = pdftmp->getObservables(*fGlobalObservables);
491 RooAbsPdf::GenSpec* gs = pdftmp->prepareMultiGen(*globtmp, NumEvents(1));
492 _pdfList.push_back(pdftmp);
493 _obsList.emplace_back(globtmp);
494 _gsList.emplace_back(gs);
495 }
496 }
497
498 // Assign generated values to the observables in _obsList
499 for (unsigned int i = 0; i < _pdfList.size(); ++i) {
500 std::unique_ptr<RooDataSet> tmp( _pdfList[i]->generate(*_gsList[i]) );
501 _obsList[i]->assign(*tmp->get(0));
502 }
503 }
504
505
506 } else {
507
508 // not using multigen for global observables
510 const RooArgSet *values = one->get(0);
511 RooArgSet* allVars = pdf.getVariables();
512 allVars->assign(*values);
513 delete allVars;
514 delete one;
515
516 }
517}
518
519////////////////////////////////////////////////////////////////////////////////
520/// This method generates a toy data set for the given parameter point taking
521/// global observables into account.
522/// The values of the generated global observables remain in the pdf's variables.
523/// They have to have those values for the subsequent evaluation of the
524/// test statistics.
525
526RooAbsData* ToyMCSampler::GenerateToyData(RooArgSet& paramPoint, double& weight, RooAbsPdf& pdf) const {
527
528 if(!fObservables) {
529 ooccoutE(nullptr,InputArguments) << "Observables not set." << endl;
530 return nullptr;
531 }
532
533 // assign input paramPoint
534 RooArgSet* allVars = fPdf->getVariables();
535 allVars->assign(paramPoint);
536
537
538 // create nuisance parameter points
542 oocoutI(nullptr,InputArguments) << "Cannot use multigen when nuisance parameters vary for every toy" << endl;
543 }
544
545 // generate global observables
546 RooArgSet observables(*fObservables);
548 observables.remove(*fGlobalObservables);
550 }
551
552 // save values to restore later.
553 // but this must remain after(!) generating global observables
554 const RooArgSet* saveVars = (const RooArgSet*)allVars->snapshot();
555
556 if(fNuisanceParametersSampler) { // use nuisance parameters?
557 // Construct a set of nuisance parameters that has the parameters
558 // in the input paramPoint removed. Therefore, no parameter in
559 // paramPoint is randomized.
560 // Therefore when a parameter is given (should be held fixed),
561 // but is also in the list of nuisance parameters, the parameter
562 // will be held fixed. This is useful for debugging to hold single
563 // parameters fixed although under "normal" circumstances it is
564 // randomized.
565 RooArgSet allVarsMinusParamPoint(*allVars);
566 allVarsMinusParamPoint.remove(paramPoint, false, true); // match by name
567
568 // get nuisance parameter point and weight
569 fNuisanceParametersSampler->NextPoint(allVarsMinusParamPoint, weight);
570
571
572 }else{
573 weight = 1.0;
574 }
575
576 RooAbsData *data = Generate(pdf, observables);
577
578 // We generated the data with the randomized nuisance parameter (if hybrid)
579 // but now we are setting the nuisance parameters back to where they were.
580 allVars->assign(*saveVars);
581 delete allVars;
582 delete saveVars;
583
584 return data;
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// This is the generate function to use in the context of the ToyMCSampler
589/// instead of the standard RooAbsPdf::generate(...).
590/// It takes into account whether the number of events is given explicitly
591/// or whether it should use the expected number of events. It also takes
592/// into account the option to generate a binned data set (*i.e.* RooDataHist).
593
594RooAbsData* ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet* protoData, int forceEvents) const {
595
596 if(fProtoData) {
597 protoData = fProtoData;
598 forceEvents = protoData->numEntries();
599 }
600
601 RooAbsData *data = nullptr;
602 int events = forceEvents;
603 if(events == 0) events = fNEvents;
604
605 // cannot use multigen when the nuisance parameters change for every toy
607
608 if (events == 0) {
609 if (pdf.canBeExtended() && pdf.expectedEvents(observables) > 0) {
610 if(fGenerateBinned) {
611 if(protoData) data = pdf.generate(observables, AllBinned(), Extended(), ProtoData(*protoData, true, true));
612 else data = pdf.generate(observables, AllBinned(), Extended());
613 } else {
614 if (protoData) {
615 if (useMultiGen) {
616 if (!_gs2) _gs2.reset( pdf.prepareMultiGen(observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true)) );
617 data = pdf.generate(*_gs2) ;
618 } else {
619 data = pdf.generate (observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true));
620 }
621 } else {
622 if (useMultiGen) {
624 data = pdf.generate(*_gs1) ;
625 } else {
627 }
628
629 }
630 }
631 } else {
632 oocoutE(nullptr,InputArguments)
633 << "ToyMCSampler: Error : pdf is not extended and number of events per toy is zero"
634 << endl;
635 }
636 } else {
637 if (fGenerateBinned) {
638 if(protoData) data = pdf.generate(observables, events, AllBinned(), ProtoData(*protoData, true, true));
639 else data = pdf.generate(observables, events, AllBinned());
640 } else {
641 if (protoData) {
642 if (useMultiGen) {
643 if (!_gs3) _gs3.reset( pdf.prepareMultiGen(observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true)) );
644 data = pdf.generate(*_gs3) ;
645 } else {
646 data = pdf.generate (observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true));
647 }
648 } else {
649 if (useMultiGen) {
651 data = pdf.generate(*_gs4) ;
652 } else {
654 }
655 }
656 }
657 }
658
659 return data;
660}
661
662////////////////////////////////////////////////////////////////////////////////
663/// Extended interface to append to sampling distribution more samples
664
666 RooArgSet& allParameters,
668 Int_t additionalMC)
669{
670 Int_t tmp = fNToys;
671 fNToys = additionalMC;
672 SamplingDistribution* newSamples = GetSamplingDistribution(allParameters);
673 fNToys = tmp;
674
675 if(last){
676 last->Add(newSamples);
677 delete newSamples;
678 return last;
679 }
680
681 return newSamples;
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// clear the cache obtained from the pdf used for speeding the toy and global observables generation
686/// needs to be called every time the model pdf (fPdf) changes
687
689 _gs1 = nullptr;
690 _gs2 = nullptr;
691 _gs3 = nullptr;
692 _gs4 = nullptr;
693 _allVars = nullptr;
694
695 // no need to delete the _pdfList since it is managed by the RooSimultaneous object
696 if (_pdfList.size() > 0) {
697 _pdfList.clear();
698 _obsList.clear();
699 _gsList.clear();
700 }
701}
702
703} // end namespace RooStats
#define oocoutW(o, a)
Definition: RooMsgService.h:51
#define oocoutE(o, a)
Definition: RooMsgService.h:52
#define oocoutI(o, a)
Definition: RooMsgService.h:49
#define ooccoutP(o, a)
Definition: RooMsgService.h:58
#define oocoutP(o, a)
Definition: RooMsgService.h:50
#define ooccoutE(o, a)
Definition: RooMsgService.h:60
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
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 valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
Definition: RooAbsArg.h:296
RooArgSet * getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2083
virtual const char * getCurrentLabel() const
Return label string of current state.
Int_t numTypes(const char *=nullptr) const
Return number of types defined (in range named rangeName if rangeName!=nullptr)
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
bool empty() const
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
Int_t getSize() const
Return the number of elements in the collection.
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
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:61
virtual const RooArgSet * get() const
Definition: RooAbsData.h:105
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Definition: RooAbsData.cxx:374
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:2112
virtual double expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
Definition: RooAbsPdf.cxx:3255
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:60
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
Definition: RooAbsPdf.h:278
virtual RooDataSet * generateSimGlobal(const RooArgSet &whatVars, Int_t nEvents)
Special generator interface for generation of 'global observables' – for RooStats tools.
Definition: RooAbsPdf.cxx:2615
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:56
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:179
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:28
bool 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:55
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 infinity()
Return internal infinity representation.
Definition: RooNumber.cxx:48
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:51
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
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 &weight)
Assigns new nuisance parameter point to members of nuisPoint.
std::unique_ptr< RooAbsData > fPoints
Definition: ToyMCSampler.h:63
RooWorkspace & GetWorkspace(void) const
returns fWorkspace
Definition: ProofConfig.h:94
Int_t GetNExperiments(void) const
return fNExperiments
Definition: ProofConfig.h:98
const char * GetHost(void) const
returns fHost
Definition: ProofConfig.h:96
bool GetShowGui(void) const
return fShowGui
Definition: ProofConfig.h:100
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:253
std::string fSamplingDistName
name of the model
Definition: ToyMCSampler.h:249
virtual void GenerateGlobalObservables(RooAbsPdf &pdf) const
generate global observables
RooAbsData * Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=nullptr, int forceEvents=0) const
helper for GenerateToyData
virtual RooDataSet * GetSamplingDistributionsSingleWorker(RooArgSet &paramPoint)
This is the main function for serial runs.
std::unique_ptr< const RooArgSet > fParametersForTestStat
Definition: ToyMCSampler.h:246
virtual SamplingDistribution * AppendSamplingDistribution(RooArgSet &allParameters, SamplingDistribution *last, Int_t additionalMC)
Extended interface to append to sampling distribution more samples.
NuisanceParametersSampler * fNuisanceParametersSampler
!
Definition: ToyMCSampler.h:277
std::unique_ptr< RooAbsPdf::GenSpec > _gs4
! GenSpec #4
Definition: ToyMCSampler.h:287
const RooArgSet * fObservables
Definition: ToyMCSampler.h:252
double fToysInTails
minimum no of toys in tails for adaptive sampling (taking weights into account, therefore double) Def...
Definition: ToyMCSampler.h:265
virtual RooArgList * EvaluateAllTestStatistics(RooAbsData &data, const RooArgSet &poi)
Evaluate all test statistics, returning result and any detailed output.
RooAbsPdf * fPdf
densities, snapshots, and test statistics to reweight to
Definition: ToyMCSampler.h:245
SamplingDistribution * GetSamplingDistribution(RooArgSet &paramPoint) override
main interface
std::unique_ptr< RooAbsPdf::GenSpec > _gs1
! GenSpec #1
Definition: ToyMCSampler.h:284
virtual RooDataSet * GetSamplingDistributions(RooArgSet &paramPoint)
Use for serial and parallel runs.
virtual void AddTestStatistic(TestStatistic *t=nullptr)
The pdf can be nullptr in which case the density from SetPdf() is used.
Definition: ToyMCSampler.h:93
virtual RooAbsData * GenerateToyData(RooArgSet &paramPoint, RooAbsPdf &pdf) const
generates toy data without weight
Definition: ToyMCSampler.h:104
bool fExpectedNuisancePar
whether to use expectation values for nuisance parameters (ie Asimov data set)
Definition: ToyMCSampler.h:257
bool fUseMultiGen
Use PrepareMultiGen?
Definition: ToyMCSampler.h:290
std::unique_ptr< RooAbsPdf::GenSpec > _gs2
! GenSpec #2
Definition: ToyMCSampler.h:285
const RooArgSet * fNuisancePars
Definition: ToyMCSampler.h:251
std::unique_ptr< RooAbsPdf::GenSpec > _gs3
! GenSpec #3
Definition: ToyMCSampler.h:286
std::vector< TestStatistic * > fTestStatistics
Definition: ToyMCSampler.h:247
Int_t fNEvents
number of events per toy (may be ignored depending on settings)
Definition: ToyMCSampler.h:255
ToyMCSampler()
Proof constructor. Do not use.
double fAdaptiveLowLimit
tails
Definition: ToyMCSampler.h:270
std::unique_ptr< RooArgSet > _allVars
!
Definition: ToyMCSampler.h:280
static void SetAlwaysUseMultiGen(bool flag)
std::vector< RooAbsPdf * > _pdfList
! We don't own those objects
Definition: ToyMCSampler.h:281
Int_t fNToys
number of toys to generate
Definition: ToyMCSampler.h:254
virtual void ClearCache()
helper method for clearing the cache
bool CheckConfig(void)
Checks for sufficient information to do a GetSamplingDistribution(...).
ProofConfig * fProofConfig
!
Definition: ToyMCSampler.h:275
std::vector< std::unique_ptr< RooArgSet > > _obsList
!
Definition: ToyMCSampler.h:282
static bool fgAlwaysUseMultiGen
Use PrepareMultiGen always.
Definition: ToyMCSampler.h:289
double fMaxToys
maximum no of toys (taking weights into account, therefore double)
Definition: ToyMCSampler.h:268
const RooDataSet * fProtoData
in dev
Definition: ToyMCSampler.h:273
std::vector< std::unique_ptr< RooAbsPdf::GenSpec > > _gsList
!
Definition: ToyMCSampler.h:283
RooAbsPdf * fPriorNuisance
prior pdf for nuisance parameters
Definition: ToyMCSampler.h:250
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 showGui=true)
Open PROOF-Lite session.
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
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:2357
RooCmdArg Extended(bool flag=true)
RooCmdArg ProtoData(const RooDataSet &protoData, bool randomizeOrder=false, bool resample=false)
RooCmdArg AllBinned()
RooCmdArg AutoBinned(bool flag=true)
RooCmdArg NumEvents(Int_t numEvents)
RooCmdArg GenBinned(const char *tag)
RooCmdArg ExpectedData(bool flag=true)
RVec< PromoteType< T > > ceil(const RVec< T > &v)
Definition: RVec.hxx:1813
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18
@ Generation
Definition: RooGlobalFunc.h:62
@ NumIntegration
Definition: RooGlobalFunc.h:64
@ InputArguments
Definition: RooGlobalFunc.h:63
Namespace for the RooStats classes.
Definition: Asimov.h:19
void removeTopic(RooFit::MsgTopic oldTopic)
static void output()