Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 = std::unique_ptr<RooDataSet>{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
136 fPoints = std::unique_ptr<RooDataSet>{fPrior->generate(*fParams, fNToys)};
137 }
138}
139
141
142////////////////////////////////////////////////////////////////////////////////
143
145
146////////////////////////////////////////////////////////////////////////////////
147/// Proof constructor. Do not use.
148
150 : fSamplingDistName("SD"),
151 fNToys(1),
152 fMaxToys(RooNumber::infinity()),
153 fAdaptiveLowLimit(-RooNumber::infinity()),
154 fAdaptiveHighLimit(RooNumber::infinity())
155{
156 //suppress messages for num integration of Roofit
158}
159
160////////////////////////////////////////////////////////////////////////////////
161
163 : fSamplingDistName(ts.GetVarName().Data()),
164 fNToys(ntoys),
165 fMaxToys(RooNumber::infinity()),
166 fAdaptiveLowLimit(-RooNumber::infinity()),
167 fAdaptiveHighLimit(RooNumber::infinity())
168{
169
170 //suppress messages for num integration of Roofit
172
173 AddTestStatistic(&ts);
174}
175
176////////////////////////////////////////////////////////////////////////////////
177
180
181 ClearCache();
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// only checks, no guessing/determination (do this in calculators,
186/// e.g. using ModelConfig::GuessObsAndNuisance(...))
187
189 bool goodConfig = true;
190
191 if(fTestStatistics.empty() || fTestStatistics[0] == nullptr) { ooccoutE(nullptr,InputArguments) << "Test statistic not set." << endl; goodConfig = false; }
192 if(!fObservables) { ooccoutE(nullptr,InputArguments) << "Observables not set." << endl; goodConfig = false; }
193 if(!fParametersForTestStat) { ooccoutE(nullptr,InputArguments) << "Parameter values used to evaluate the test statistic are not set." << endl; goodConfig = false; }
194 if(!fPdf) { ooccoutE(nullptr,InputArguments) << "Pdf not set." << endl; goodConfig = false; }
195
196 return goodConfig;
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Evaluate all test statistics, returning result and any detailed output.
201/// PDF parameter values are saved in case they are modified by
202/// TestStatistic::Evaluate (eg. SimpleLikelihoodRatioTestStat).
203
205 DetailedOutputAggregator detOutAgg;
206 const RooArgList* allTS = EvaluateAllTestStatistics(data, poi, detOutAgg);
207 if (!allTS) return nullptr;
208 // no need to delete allTS, it is deleted in destructor of detOutAgg
209 return dynamic_cast<RooArgList*>(allTS->snapshot());
210}
211
212////////////////////////////////////////////////////////////////////////////////
213
215 std::unique_ptr<RooArgSet> allVars;
216 std::unique_ptr<RooArgSet> saveAll;
217 if(fPdf) {
218 allVars = std::unique_ptr<RooArgSet>{fPdf->getVariables()};
219 }
220 if(allVars) {
221 saveAll = std::make_unique<RooArgSet>();
222 allVars->snapshot(*saveAll);
223 }
224 for( unsigned int i = 0; i < fTestStatistics.size(); i++ ) {
225 if( fTestStatistics[i] == nullptr ) continue;
226 TString name( TString::Format("%s_TS%u", fSamplingDistName.c_str(), i) );
227 RooArgSet parForTS;
228 poi.snapshot(parForTS);
229 RooRealVar ts( name, fTestStatistics[i]->GetVarName(), fTestStatistics[i]->Evaluate( data, parForTS ) );
230 RooArgList tset(ts);
231 detOutAgg.AppendArgSet(&tset);
232 if (const RooArgSet* detOut = fTestStatistics[i]->GetDetailedOutput()) {
233 name.Append("_");
234 detOutAgg.AppendArgSet(detOut, name);
235 }
236 if (saveAll) {
237 // restore values, perhaps modified by fTestStatistics[i]->Evaluate()
238 allVars->assign(*saveAll);
239 }
240 }
241 return detOutAgg.GetAsArgList();
242}
243
244////////////////////////////////////////////////////////////////////////////////
245
247 if(fTestStatistics.size() > 1) {
248 oocoutW(nullptr, InputArguments) << "Multiple test statistics defined, but only one distribution will be returned." << endl;
249 for( unsigned int i=0; i < fTestStatistics.size(); i++ ) {
250 oocoutW(nullptr, InputArguments) << " \t test statistic: " << fTestStatistics[i] << endl;
251 }
252 }
253
254 std::unique_ptr<RooDataSet> r{GetSamplingDistributions(paramPointIn)};
255 if(r == nullptr || r->numEntries() == 0) {
256 oocoutW(nullptr, Generation) << "no sampling distribution generated" << endl;
257 return nullptr;
258 }
259
260 return new SamplingDistribution( r->GetName(), r->GetTitle(), *r );
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Use for serial and parallel runs.
265
267{
268
269 // ======= S I N G L E R U N ? =======
270 if(!fProofConfig)
271 return GetSamplingDistributionsSingleWorker(paramPointIn);
272
273 // ======= P A R A L L E L R U N =======
274 if (!CheckConfig()){
275 oocoutE(nullptr, InputArguments)
276 << "Bad COnfiguration in ToyMCSampler "
277 << endl;
278 return nullptr;
279 }
280
281 // turn adaptive sampling off if given
282 if(fToysInTails) {
283 fToysInTails = 0;
284 oocoutW(nullptr, InputArguments)
285 << "Adaptive sampling in ToyMCSampler is not supported for parallel runs."
286 << endl;
287 }
288
289 // adjust number of toys on the slaves to keep the total number of toys constant
290 Int_t totToys = fNToys;
291 fNToys = (int)ceil((double)fNToys / (double)fProofConfig->GetNExperiments()); // round up
292
293 // create the study instance for parallel processing
294 ToyMCStudy* toymcstudy = new ToyMCStudy ;
295 toymcstudy->SetToyMCSampler(*this);
296 toymcstudy->SetParamPoint(paramPointIn);
298
299 // temporary workspace for proof to avoid messing with TRef
301 RooStudyManager studymanager(w, *toymcstudy);
303
304 RooDataSet* output = toymcstudy->merge();
305
306 // reset the number of toys
307 fNToys = totToys;
308
309 delete toymcstudy;
310 return output;
311}
312
313////////////////////////////////////////////////////////////////////////////////
314/// This is the main function for serial runs. It is called automatically
315/// from inside GetSamplingDistribution when no ProofConfig is given.
316/// You should not call this function yourself. This function should
317/// be used by ToyMCStudy on the workers (ie. when you explicitly want
318/// a serial run although ProofConfig is present).
319///
320
322{
323 // Make sure the cache is clear. It is important to clear it here, because
324 // the cache might be invalid even when just the firstPOI was changed, for which
325 // no accessor has to be called. (Fixes a bug when ToyMCSampler is
326 // used with the Neyman Construction)
327 ClearCache();
328
329 if (!CheckConfig()){
330 oocoutE(nullptr, InputArguments)
331 << "Bad COnfiguration in ToyMCSampler "
332 << endl;
333 return nullptr;
334 }
335
336 // important to cache the paramPoint b/c test statistic might
337 // modify it from event to event
338 RooArgSet *paramPoint = (RooArgSet*) paramPointIn.snapshot();
339 std::unique_ptr<RooArgSet> allVars{fPdf->getVariables()};
340 RooArgSet *saveAll = (RooArgSet*) allVars->snapshot();
341
342
343 DetailedOutputAggregator detOutAgg;
344
345 // counts the number of toys in the limits set for adaptive sampling
346 // (taking weights into account; always on first test statistic)
347 double toysInTails = 0.0;
348
349 for (Int_t i = 0; i < fMaxToys; ++i) {
350 // need to check at the beginning for case that zero toys are requested
351 if (toysInTails >= fToysInTails && i+1 > fNToys) break;
352
353 // status update
354 if ( i% 500 == 0 && i>0 ) {
355 oocoutP(nullptr,Generation) << "generated toys: " << i << " / " << fNToys;
356 if (fToysInTails) ooccoutP(nullptr,Generation) << " (tails: " << toysInTails << " / " << fToysInTails << ")" << std::endl;
357 else ooccoutP(nullptr,Generation) << endl;
358 }
359
360 // TODO: change this treatment to keep track of all values so that the threshold
361 // for adaptive sampling is counted for all distributions and not just the
362 // first one.
363 double valueFirst = -999.0;
364 double weight = 1.0;
365
366 // set variables to requested parameter point
367 allVars->assign(*saveAll); // important for example for SimpleLikelihoodRatioTestStat
368
369 RooAbsData* toydata = GenerateToyData(*paramPoint, weight);
370 if (i == 0 && !fPdf->canBeExtended() && dynamic_cast<RooSimultaneous*>(fPdf)) {
371 const RooArgSet* toySet = toydata->get();
372 if (std::none_of(toySet->begin(), toySet->end(),
373 [](const RooAbsArg *arg) { return dynamic_cast<const RooAbsCategory *>(arg) != nullptr; })) {
374 oocoutE(nullptr, Generation)
375 << "ToyMCSampler: Generated toy data didn't contain a category variable, although"
376 " a simultaneous PDF is in use. To generate events for a simultaneous PDF, all components need to be"
377 " extended. Otherwise, the number of events to generate per component cannot be determined."
378 << std::endl;
379 }
380 }
381
383
384 const RooArgList* allTS = EvaluateAllTestStatistics(*toydata, *fParametersForTestStat, detOutAgg);
385 if (allTS->size() > fTestStatistics.size())
386 detOutAgg.AppendArgSet( fGlobalObservables, "globObs_" );
387 if (RooRealVar* firstTS = dynamic_cast<RooRealVar*>(allTS->first()))
388 valueFirst = firstTS->getVal();
389
390 delete toydata;
391
392 // check for nan
393 if(valueFirst != valueFirst) {
394 oocoutW(nullptr, Generation) << "skip: " << valueFirst << ", " << weight << endl;
395 continue;
396 }
397
398 detOutAgg.CommitSet(weight);
399
400 // adaptive sampling checks
401 if (valueFirst <= fAdaptiveLowLimit || valueFirst >= fAdaptiveHighLimit) {
402 if(weight >= 0.) toysInTails += weight;
403 else toysInTails += 1.;
404 }
405 }
406
407 // clean up
408 allVars->assign(*saveAll);
409 delete saveAll;
410 delete paramPoint;
411
413}
414
415////////////////////////////////////////////////////////////////////////////////
416
418
419
421 ooccoutE(nullptr,InputArguments) << "Global Observables not set." << endl;
422 return;
423 }
424
425
427
428 // generate one set of global observables and assign it
429 // has problem for sim pdfs
430 RooSimultaneous* simPdf = dynamic_cast<RooSimultaneous*>(&pdf );
431 if (!simPdf) {
432 std::unique_ptr<RooDataSet> one{pdf.generate(*fGlobalObservables, 1)};
433
434 const RooArgSet *values = one->get(0);
435 if (!_allVars) {
436 _allVars = std::unique_ptr<RooArgSet>{pdf.getVariables()};
437 }
438 _allVars->assign(*values);
439
440 } else {
441
442 if (_pdfList.empty()) {
443 auto& channelCat = const_cast<RooCategory&>(static_cast<RooCategory const&>(simPdf->indexCat()));
444 int nCat = channelCat.numTypes();
445 for (int i=0; i < nCat; ++i){
446 channelCat.setIndex(i);
447 RooAbsPdf* pdftmp = simPdf->getPdf(channelCat.getCurrentLabel());
448 assert(pdftmp);
449 std::unique_ptr<RooArgSet> globtmp{pdftmp->getObservables(*fGlobalObservables)};
450 RooAbsPdf::GenSpec* gs = pdftmp->prepareMultiGen(*globtmp, NumEvents(1));
451 _pdfList.push_back(pdftmp);
452 _obsList.emplace_back(std::move(globtmp));
453 _gsList.emplace_back(gs);
454 }
455 }
456
457 // Assign generated values to the observables in _obsList
458 for (unsigned int i = 0; i < _pdfList.size(); ++i) {
459 std::unique_ptr<RooDataSet> tmp( _pdfList[i]->generate(*_gsList[i]) );
460 _obsList[i]->assign(*tmp->get(0));
461 }
462 }
463
464
465 } else {
466
467 // not using multigen for global observables
468 std::unique_ptr<RooDataSet> one{pdf.generateSimGlobal( *fGlobalObservables, 1 )};
469 const RooArgSet *values = one->get(0);
470 std::unique_ptr<RooArgSet> allVars{pdf.getVariables()};
471 allVars->assign(*values);
472
473 }
474}
475
476////////////////////////////////////////////////////////////////////////////////
477/// This method generates a toy data set for the given parameter point taking
478/// global observables into account.
479/// The values of the generated global observables remain in the pdf's variables.
480/// They have to have those values for the subsequent evaluation of the
481/// test statistics.
482
483RooAbsData* ToyMCSampler::GenerateToyData(RooArgSet& paramPoint, double& weight, RooAbsPdf& pdf) const {
484
485 if(!fObservables) {
486 ooccoutE(nullptr,InputArguments) << "Observables not set." << endl;
487 return nullptr;
488 }
489
490 // assign input paramPoint
491 std::unique_ptr<RooArgSet> allVars{fPdf->getVariables()};
492 allVars->assign(paramPoint);
493
494
495 // create nuisance parameter points
499 oocoutI(nullptr,InputArguments) << "Cannot use multigen when nuisance parameters vary for every toy" << endl;
500 }
501
502 // generate global observables
503 RooArgSet observables(*fObservables);
505 observables.remove(*fGlobalObservables);
507 }
508
509 // save values to restore later.
510 // but this must remain after(!) generating global observables
511 const RooArgSet* saveVars = (const RooArgSet*)allVars->snapshot();
512
513 if(fNuisanceParametersSampler) { // use nuisance parameters?
514 // Construct a set of nuisance parameters that has the parameters
515 // in the input paramPoint removed. Therefore, no parameter in
516 // paramPoint is randomized.
517 // Therefore when a parameter is given (should be held fixed),
518 // but is also in the list of nuisance parameters, the parameter
519 // will be held fixed. This is useful for debugging to hold single
520 // parameters fixed although under "normal" circumstances it is
521 // randomized.
522 RooArgSet allVarsMinusParamPoint(*allVars);
523 allVarsMinusParamPoint.remove(paramPoint, false, true); // match by name
524
525 // get nuisance parameter point and weight
526 fNuisanceParametersSampler->NextPoint(allVarsMinusParamPoint, weight);
527
528
529 }else{
530 weight = 1.0;
531 }
532
533 RooAbsData *data = Generate(pdf, observables).release();
534
535 // We generated the data with the randomized nuisance parameter (if hybrid)
536 // but now we are setting the nuisance parameters back to where they were.
537 allVars->assign(*saveVars);
538 delete saveVars;
539
540 return data;
541}
542
543////////////////////////////////////////////////////////////////////////////////
544/// This is the generate function to use in the context of the ToyMCSampler
545/// instead of the standard RooAbsPdf::generate(...).
546/// It takes into account whether the number of events is given explicitly
547/// or whether it should use the expected number of events. It also takes
548/// into account the option to generate a binned data set (*i.e.* RooDataHist).
549
550std::unique_ptr<RooAbsData> ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet* protoData, int forceEvents) const {
551
552 if(fProtoData) {
553 protoData = fProtoData;
554 forceEvents = protoData->numEntries();
555 }
556
557 std::unique_ptr<RooAbsData> data;
558 int events = forceEvents;
559 if(events == 0) events = fNEvents;
560
561 // cannot use multigen when the nuisance parameters change for every toy
563
564 if (events == 0) {
565 if (pdf.canBeExtended() && pdf.expectedEvents(observables) > 0) {
566 if(fGenerateBinned) {
567 if(protoData) data = std::unique_ptr<RooDataSet>{pdf.generate(observables, AllBinned(), Extended(), ProtoData(*protoData, true, true))};
568 else data = std::unique_ptr<RooDataSet>{pdf.generate(observables, AllBinned(), Extended())};
569 } else {
570 if (protoData) {
571 if (useMultiGen) {
572 if (!_gs2) _gs2.reset( pdf.prepareMultiGen(observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true)) );
573 data = std::unique_ptr<RooDataSet>{pdf.generate(*_gs2)};
574 } else {
575 data = std::unique_ptr<RooDataSet>{pdf.generate(observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true))};
576 }
577 } else {
578 if (useMultiGen) {
580 data = std::unique_ptr<RooDataSet>{pdf.generate(*_gs1)};
581 } else {
582 data = std::unique_ptr<RooDataSet>{pdf.generate(observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag) )};
583 }
584
585 }
586 }
587 } else {
588 oocoutE(nullptr,InputArguments)
589 << "ToyMCSampler: Error : pdf is not extended and number of events per toy is zero"
590 << endl;
591 }
592 } else {
593 if (fGenerateBinned) {
594 if(protoData) data = std::unique_ptr<RooDataSet>{pdf.generate(observables, events, AllBinned(), ProtoData(*protoData, true, true))};
595 else data = std::unique_ptr<RooDataSet>{pdf.generate(observables, events, AllBinned())};
596 } else {
597 if (protoData) {
598 if (useMultiGen) {
599 if (!_gs3) _gs3.reset( pdf.prepareMultiGen(observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true)) );
600 data = std::unique_ptr<RooDataSet>{pdf.generate(*_gs3)};
601 } else {
602 data = std::unique_ptr<RooDataSet>{pdf.generate(observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true))};
603 }
604 } else {
605 if (useMultiGen) {
607 data = std::unique_ptr<RooDataSet>{pdf.generate(*_gs4)};
608 } else {
609 data = std::unique_ptr<RooDataSet>{pdf.generate(observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag))};
610 }
611 }
612 }
613 }
614
615 return data;
616}
617
618////////////////////////////////////////////////////////////////////////////////
619/// Extended interface to append to sampling distribution more samples
620
622 RooArgSet& allParameters,
624 Int_t additionalMC)
625{
626 Int_t tmp = fNToys;
627 fNToys = additionalMC;
628 SamplingDistribution* newSamples = GetSamplingDistribution(allParameters);
629 fNToys = tmp;
630
631 if(last){
632 last->Add(newSamples);
633 delete newSamples;
634 return last;
635 }
636
637 return newSamples;
638}
639
640////////////////////////////////////////////////////////////////////////////////
641/// clear the cache obtained from the pdf used for speeding the toy and global observables generation
642/// needs to be called every time the model pdf (fPdf) changes
643
645 _gs1 = nullptr;
646 _gs2 = nullptr;
647 _gs3 = nullptr;
648 _gs4 = nullptr;
649 _allVars = nullptr;
650
651 // no need to delete the _pdfList since it is managed by the RooSimultaneous object
652 if (!_pdfList.empty()) {
653 _pdfList.clear();
654 _obsList.clear();
655 _gsList.clear();
656 }
657}
658
659} // end namespace RooStats
#define oocoutW(o, a)
#define oocoutE(o, a)
#define oocoutI(o, a)
#define ooccoutP(o, a)
#define oocoutP(o, a)
#define ooccoutE(o, a)
#define ClassImp(name)
Definition Rtypes.h:377
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
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expression tree)
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.
Storage_t const & get() const
Const access to the underlying stl container.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
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...
Storage_t::size_type size() const
TIterator begin()
RooAbsArg * first() const
TIterator end() and range-based for loops.")
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
virtual const RooArgSet * get() const
Definition RooAbsData.h:101
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
virtual double expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
Definition RooAbsPdf.h:219
GenSpec * prepareMultiGen(const RooArgSet &whatVars, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={})
Prepare GenSpec configuration object for efficient generation of multiple datasets from identical spe...
RooFit::OwningPtr< RooDataSet > generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={})
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition RooAbsPdf.h:57
virtual RooFit::OwningPtr< RooDataSet > generateSimGlobal(const RooArgSet &whatVars, Int_t nEvents)
Special generator interface for generation of 'global observables' – for RooStats tools.
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:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178
Object to represent discrete states.
Definition RooCategory.h:28
Container class to hold unbinned data.
Definition RooDataSet.h:57
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
Provides numeric constants used in RooFit.
Definition RooNumber.h:22
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition RooRandom.cxx:51
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
const RooAbsCategoryLValue & indexCat() const
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.
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
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
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...
ToyMCSampler is an implementation of the TestStatSampler interface.
const RooArgSet * fGlobalObservables
std::string fSamplingDistName
name of the model
virtual void GenerateGlobalObservables(RooAbsPdf &pdf) const
generate global observables
virtual RooDataSet * GetSamplingDistributionsSingleWorker(RooArgSet &paramPoint)
This is the main function for serial runs.
std::unique_ptr< const RooArgSet > fParametersForTestStat
virtual SamplingDistribution * AppendSamplingDistribution(RooArgSet &allParameters, SamplingDistribution *last, Int_t additionalMC)
Extended interface to append to sampling distribution more samples.
NuisanceParametersSampler * fNuisanceParametersSampler
!
std::unique_ptr< RooAbsPdf::GenSpec > _gs4
! GenSpec #4
const RooArgSet * fObservables
double fToysInTails
minimum no of toys in tails for adaptive sampling (taking weights into account, therefore double) Def...
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
SamplingDistribution * GetSamplingDistribution(RooArgSet &paramPoint) override
main interface
std::unique_ptr< RooAbsPdf::GenSpec > _gs1
! GenSpec #1
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.
virtual RooAbsData * GenerateToyData(RooArgSet &paramPoint, RooAbsPdf &pdf) const
generates toy data without weight
bool fExpectedNuisancePar
whether to use expectation values for nuisance parameters (ie Asimov data set)
bool fUseMultiGen
Use PrepareMultiGen?
std::unique_ptr< RooAbsPdf::GenSpec > _gs2
! GenSpec #2
const RooArgSet * fNuisancePars
std::unique_ptr< RooAbsPdf::GenSpec > _gs3
! GenSpec #3
std::vector< TestStatistic * > fTestStatistics
Int_t fNEvents
number of events per toy (may be ignored depending on settings)
ToyMCSampler()
Proof constructor. Do not use.
std::unique_ptr< RooArgSet > _allVars
!
std::unique_ptr< RooAbsData > Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=nullptr, int forceEvents=0) const
helper for GenerateToyData
static void SetAlwaysUseMultiGen(bool flag)
std::vector< RooAbsPdf * > _pdfList
! We don't own those objects
Int_t fNToys
number of toys to generate
virtual void ClearCache()
helper method for clearing the cache
bool CheckConfig(void)
Checks for sufficient information to do a GetSamplingDistribution(...).
ProofConfig * fProofConfig
!
std::vector< std::unique_ptr< RooArgSet > > _obsList
!
static bool fgAlwaysUseMultiGen
Use PrepareMultiGen always.
double fMaxToys
maximum no of toys (taking weights into account, therefore double)
const RooDataSet * fProtoData
in dev
std::vector< std::unique_ptr< RooAbsPdf::GenSpec > > _gsList
!
RooAbsPdf * fPriorNuisance
prior pdf for nuisance parameters
ToyMCStudy is an implementation of RooAbsStudy for toy Monte Carlo sampling.
Definition ToyMCStudy.h:30
void SetToyMCSampler(ToyMCSampler &t)
Definition ToyMCStudy.h:53
void SetParamPoint(const RooArgSet &paramPoint)
Definition ToyMCStudy.h:54
void SetRandomSeed(unsigned int seed)
Definition ToyMCStudy.h:56
RooDataSet * merge()
Utility class to manage studies that consist of repeated applications of generate-and-fit operations ...
void runProof(Int_t nExperiments, const char *proofHost="", bool showGui=true)
Open PROOF-Lite session.
Persistable container for RooFit projects.
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition TRandom.cxx:361
Basic string class.
Definition TString.h:139
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:2378
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)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
@ NumIntegration
@ InputArguments
Namespace for the RooStats classes.
Definition Asimov.h:19
void removeTopic(RooFit::MsgTopic oldTopic)
static void output()