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 = *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 (fPoints) delete fPoints;
97
98 if (fExpected) {
99 // UNDER CONSTRUCTION
100 oocoutI((TObject*)NULL,InputArguments) << "Using expected nuisance parameters." << endl;
101
102 int nBins = fNToys;
103
104 // From FeldmanCousins.cxx:
105 // set nbins for the POI
107 RooRealVar *myarg2;
108 while ((myarg2 = dynamic_cast<RooRealVar*>(it2.Next()))) {
109 myarg2->setBins(nBins);
110 }
111
112
114 *fParams,
115 AllBinned(),
116 ExpectedData(),
117 NumEvents(1) // for Asimov set, this is only a scale factor
118 );
119 if(fPoints->numEntries() != fNToys) {
122 "Adjusted number of toys to number of bins of nuisance parameters: " << fNToys << endl;
123 }
124
125/*
126 // check
127 TCanvas *c1 = new TCanvas;
128 RooPlot *p = dynamic_cast<RooRealVar*>(fParams->first())->frame();
129 fPoints->plotOn(p);
130 p->Draw();
131 for(int x=0; x < fPoints->numEntries(); x++) {
132 fPoints->get(x)->Print("v");
133 cout << fPoints->weight() << endl;
134 }
135*/
136
137 }else{
138 oocoutI((TObject*)NULL,InputArguments) << "Using randomized nuisance parameters." << endl;
139
141 }
142}
143
145
146////////////////////////////////////////////////////////////////////////////////
147
149
150////////////////////////////////////////////////////////////////////////////////
151/// Proof constructor. Do not use.
152
153ToyMCSampler::ToyMCSampler() : fSamplingDistName("SD"), fNToys(1)
154{
155
156 fPdf = NULL;
157 fPriorNuisance = NULL;
158 fNuisancePars = NULL;
159 fObservables = NULL;
160 fGlobalObservables = NULL;
161
162 fSize = 0.05;
163 fNEvents = 0;
168
169 fToysInTails = 0.0;
173
174 fProtoData = NULL;
175
176 fProofConfig = NULL;
178
179 _allVars = NULL ;
180 _gs1 = NULL ;
181 _gs2 = NULL ;
182 _gs3 = NULL ;
183 _gs4 = NULL ;
184
185 //suppress messages for num integration of Roofit
187
189}
190
191////////////////////////////////////////////////////////////////////////////////
192
193ToyMCSampler::ToyMCSampler(TestStatistic &ts, Int_t ntoys) : fSamplingDistName(ts.GetVarName().Data()), fNToys(ntoys)
194{
195 fPdf = NULL;
196 fPriorNuisance = NULL;
197 fNuisancePars = NULL;
198 fObservables = NULL;
199 fGlobalObservables = NULL;
200
201 fSize = 0.05;
202 fNEvents = 0;
207
208 fToysInTails = 0.0;
212
213 fProtoData = NULL;
214
215 fProofConfig = NULL;
217
218 _allVars = NULL ;
219 _gs1 = NULL ;
220 _gs2 = NULL ;
221 _gs3 = NULL ;
222 _gs4 = NULL ;
223
224 //suppress messages for num integration of Roofit
226
228
229 AddTestStatistic(&ts);
230}
231
232////////////////////////////////////////////////////////////////////////////////
233
236
237 ClearCache();
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// only checks, no guessing/determination (do this in calculators,
242/// e.g. using ModelConfig::GuessObsAndNuisance(...))
243
245 bool goodConfig = true;
246
247 if(fTestStatistics.size() == 0 || fTestStatistics[0] == NULL) { ooccoutE((TObject*)NULL,InputArguments) << "Test statistic not set." << endl; goodConfig = false; }
248 if(!fObservables) { ooccoutE((TObject*)NULL,InputArguments) << "Observables not set." << endl; goodConfig = false; }
249 if(!fParametersForTestStat) { ooccoutE((TObject*)NULL,InputArguments) << "Parameter values used to evaluate the test statistic are not set." << endl; goodConfig = false; }
250 if(!fPdf) { ooccoutE((TObject*)NULL,InputArguments) << "Pdf not set." << endl; goodConfig = false; }
251
252
253 //ooccoutI((TObject*)NULL,InputArguments) << "ToyMCSampler configuration:" << endl;
254 //ooccoutI((TObject*)NULL,InputArguments) << "Pdf from SetPdf: " << fPdf << endl;
255 // for( unsigned int i=0; i < fTestStatistics.size(); i++ ) {
256 // ooccoutI((TObject*)NULL,InputArguments) << "test statistics["<<i<<"]: " << fTestStatistics[i] << endl;
257 // }
258 //ooccoutI((TObject*)NULL,InputArguments) << endl;
259
260 return goodConfig;
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Evaluate all test statistics, returning result and any detailed output.
265/// PDF parameter values are saved in case they are modified by
266/// TestStatistic::Evaluate (eg. SimpleLikelihoodRatioTestStat).
267
269 DetailedOutputAggregator detOutAgg;
270 const RooArgList* allTS = EvaluateAllTestStatistics(data, poi, detOutAgg);
271 if (!allTS) return 0;
272 // no need to delete allTS, it is deleted in destructor of detOutAgg
273 return dynamic_cast<RooArgList*>(allTS->snapshot());
274}
275
276////////////////////////////////////////////////////////////////////////////////
277
279 RooArgSet *allVars = fPdf ? fPdf->getVariables() : nullptr;
280 RooArgSet *saveAll = allVars ? allVars->snapshot() : nullptr;
281 for( unsigned int i = 0; i < fTestStatistics.size(); i++ ) {
282 if( fTestStatistics[i] == NULL ) continue;
283 TString name( TString::Format("%s_TS%u", fSamplingDistName.c_str(), i) );
284 std::unique_ptr<RooArgSet> parForTS(poi.snapshot());
285 RooRealVar ts( name, fTestStatistics[i]->GetVarName(), fTestStatistics[i]->Evaluate( data, *parForTS ) );
286 RooArgList tset(ts);
287 detOutAgg.AppendArgSet(&tset);
288 if (const RooArgSet* detOut = fTestStatistics[i]->GetDetailedOutput()) {
289 name.Append("_");
290 detOutAgg.AppendArgSet(detOut, name);
291 }
292 if (saveAll) *allVars = *saveAll; // restore values, perhaps modified by fTestStatistics[i]->Evaluate()
293 }
294 delete saveAll;
295 delete allVars;
296 return detOutAgg.GetAsArgList();
297}
298
299////////////////////////////////////////////////////////////////////////////////
300
302 if(fTestStatistics.size() > 1) {
303 oocoutW((TObject*)NULL, InputArguments) << "Multiple test statistics defined, but only one distribution will be returned." << endl;
304 for( unsigned int i=0; i < fTestStatistics.size(); i++ ) {
305 oocoutW((TObject*)NULL, InputArguments) << " \t test statistic: " << fTestStatistics[i] << endl;
306 }
307 }
308
309 RooDataSet* r = GetSamplingDistributions(paramPointIn);
310 if(r == NULL || r->numEntries() == 0) {
311 oocoutW((TObject*)NULL, Generation) << "no sampling distribution generated" << endl;
312 return NULL;
313 }
314
316 delete r;
317 return samp;
318}
319
320////////////////////////////////////////////////////////////////////////////////
321/// Use for serial and parallel runs.
322
324{
325
326 // ======= S I N G L E R U N ? =======
327 if(!fProofConfig)
328 return GetSamplingDistributionsSingleWorker(paramPointIn);
329
330 // ======= P A R A L L E L R U N =======
331 if (!CheckConfig()){
333 << "Bad COnfiguration in ToyMCSampler "
334 << endl;
335 return nullptr;
336 }
337
338 // turn adaptive sampling off if given
339 if(fToysInTails) {
340 fToysInTails = 0;
342 << "Adaptive sampling in ToyMCSampler is not supported for parallel runs."
343 << endl;
344 }
345
346 // adjust number of toys on the slaves to keep the total number of toys constant
347 Int_t totToys = fNToys;
348 fNToys = (int)ceil((double)fNToys / (double)fProofConfig->GetNExperiments()); // round up
349
350 // create the study instance for parallel processing
351 ToyMCStudy* toymcstudy = new ToyMCStudy ;
352 toymcstudy->SetToyMCSampler(*this);
353 toymcstudy->SetParamPoint(paramPointIn);
355
356 // temporary workspace for proof to avoid messing with TRef
358 RooStudyManager studymanager(w, *toymcstudy);
360
361 RooDataSet* output = toymcstudy->merge();
362
363 // reset the number of toys
364 fNToys = totToys;
365
366 delete toymcstudy;
367 return output;
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// This is the main function for serial runs. It is called automatically
372/// from inside GetSamplingDistribution when no ProofConfig is given.
373/// You should not call this function yourself. This function should
374/// be used by ToyMCStudy on the workers (ie. when you explicitly want
375/// a serial run although ProofConfig is present).
376///
377
379{
380 // Make sure the cache is clear. It is important to clear it here, because
381 // the cache might be invalid even when just the firstPOI was changed, for which
382 // no accessor has to be called. (Fixes a bug when ToyMCSampler is
383 // used with the Neyman Construction)
384 ClearCache();
385
386 if (!CheckConfig()){
388 << "Bad COnfiguration in ToyMCSampler "
389 << endl;
390 return nullptr;
391 }
392
393 // important to cache the paramPoint b/c test statistic might
394 // modify it from event to event
395 RooArgSet *paramPoint = (RooArgSet*) paramPointIn.snapshot();
396 RooArgSet *allVars = fPdf->getVariables();
397 RooArgSet *saveAll = (RooArgSet*) allVars->snapshot();
398
399
400 DetailedOutputAggregator detOutAgg;
401
402 // counts the number of toys in the limits set for adaptive sampling
403 // (taking weights into account; always on first test statistic)
404 Double_t toysInTails = 0.0;
405
406 for (Int_t i = 0; i < fMaxToys; ++i) {
407 // need to check at the beginning for case that zero toys are requested
408 if (toysInTails >= fToysInTails && i+1 > fNToys) break;
409
410 // status update
411 if ( i% 500 == 0 && i>0 ) {
412 oocoutP((TObject*)0,Generation) << "generated toys: " << i << " / " << fNToys;
413 if (fToysInTails) ooccoutP((TObject*)0,Generation) << " (tails: " << toysInTails << " / " << fToysInTails << ")" << std::endl;
414 else ooccoutP((TObject*)0,Generation) << endl;
415 }
416
417 // TODO: change this treatment to keep track of all values so that the threshold
418 // for adaptive sampling is counted for all distributions and not just the
419 // first one.
420 Double_t valueFirst = -999.0, weight = 1.0;
421
422 // set variables to requested parameter point
423 *allVars = *saveAll; // important for example for SimpleLikelihoodRatioTestStat
424
425 RooAbsData* toydata = GenerateToyData(*paramPoint, weight);
426 if (i == 0 && !fPdf->canBeExtended() && dynamic_cast<RooSimultaneous*>(fPdf)) {
427 const RooArgSet* toySet = toydata->get();
428 if (std::none_of(toySet->begin(), toySet->end(), [](const RooAbsArg* arg){
429 return dynamic_cast<const RooAbsCategory*>(arg) != nullptr;
430 }))
431 oocoutE((TObject*)nullptr, Generation) << "ToyMCSampler: Generated toy data didn't contain a category variable, although"
432 " a simultaneous PDF is in use. To generate events for a simultaneous PDF, all components need to be"
433 " extended. Otherwise, the number of events to generate per component cannot be determined." << std::endl;
434 }
435
436 *allVars = *fParametersForTestStat;
437
438 const RooArgList* allTS = EvaluateAllTestStatistics(*toydata, *fParametersForTestStat, detOutAgg);
439 if (allTS->getSize() > Int_t(fTestStatistics.size()))
440 detOutAgg.AppendArgSet( fGlobalObservables, "globObs_" );
441 if (RooRealVar* firstTS = dynamic_cast<RooRealVar*>(allTS->first()))
442 valueFirst = firstTS->getVal();
443
444 delete toydata;
445
446 // check for nan
447 if(valueFirst != valueFirst) {
448 oocoutW((TObject*)NULL, Generation) << "skip: " << valueFirst << ", " << weight << endl;
449 continue;
450 }
451
452 detOutAgg.CommitSet(weight);
453
454 // adaptive sampling checks
455 if (valueFirst <= fAdaptiveLowLimit || valueFirst >= fAdaptiveHighLimit) {
456 if(weight >= 0.) toysInTails += weight;
457 else toysInTails += 1.;
458 }
459 }
460
461 // clean up
462 *allVars = *saveAll;
463 delete saveAll;
464 delete allVars;
465 delete paramPoint;
466
468}
469
470////////////////////////////////////////////////////////////////////////////////
471
473
474
476 ooccoutE((TObject*)NULL,InputArguments) << "Global Observables not set." << endl;
477 return;
478 }
479
480
482
483 // generate one set of global observables and assign it
484 // has problem for sim pdfs
485 RooSimultaneous* simPdf = dynamic_cast<RooSimultaneous*>( &pdf );
486 if (!simPdf) {
487 RooDataSet *one = pdf.generate(*fGlobalObservables, 1);
488
489 const RooArgSet *values = one->get(0);
490 if (!_allVars) {
491 _allVars = pdf.getVariables();
492 }
493 *_allVars = *values;
494 delete one;
495
496 } else {
497
498 if (_pdfList.size() == 0) {
499 RooCategory& channelCat = (RooCategory&)simPdf->indexCat();
500 int nCat = channelCat.numTypes();
501 for (int i=0; i < nCat; ++i){
502 channelCat.setIndex(i);
503 RooAbsPdf* pdftmp = simPdf->getPdf(channelCat.getCurrentLabel());
504 assert(pdftmp);
505 RooArgSet* globtmp = pdftmp->getObservables(*fGlobalObservables);
506 RooAbsPdf::GenSpec* gs = pdftmp->prepareMultiGen(*globtmp, NumEvents(1));
507 _pdfList.push_back(pdftmp);
508 _obsList.push_back(globtmp);
509 _gsList.push_back(gs);
510 }
511 }
512
513 list<RooArgSet*>::iterator oiter = _obsList.begin();
514 list<RooAbsPdf::GenSpec*>::iterator giter = _gsList.begin();
515 for (list<RooAbsPdf*>::iterator iter = _pdfList.begin(); iter != _pdfList.end(); ++iter, ++giter, ++oiter) {
516 //RooDataSet* tmp = (*iter)->generate(**oiter,1) ;
517 RooDataSet* tmp = (*iter)->generate(**giter);
518 **oiter = *tmp->get(0);
519 delete tmp;
520 }
521 }
522
523
524 } else {
525
526 // not using multigen for global observables
528 const RooArgSet *values = one->get(0);
529 RooArgSet* allVars = pdf.getVariables();
530 *allVars = *values;
531 delete allVars;
532 delete one;
533
534 }
535}
536
537////////////////////////////////////////////////////////////////////////////////
538/// This method generates a toy data set for the given parameter point taking
539/// global observables into account.
540/// The values of the generated global observables remain in the pdf's variables.
541/// They have to have those values for the subsequent evaluation of the
542/// test statistics.
543
544RooAbsData* ToyMCSampler::GenerateToyData(RooArgSet& paramPoint, double& weight, RooAbsPdf& pdf) const {
545
546 if(!fObservables) {
547 ooccoutE((TObject*)NULL,InputArguments) << "Observables not set." << endl;
548 return NULL;
549 }
550
551 // assign input paramPoint
552 RooArgSet* allVars = fPdf->getVariables();
553 *allVars = paramPoint;
554
555
556 // create nuisance parameter points
560 oocoutI((TObject*)NULL,InputArguments) << "Cannot use multigen when nuisance parameters vary for every toy" << endl;
561 }
562
563 // generate global observables
564 RooArgSet observables(*fObservables);
566 observables.remove(*fGlobalObservables);
568 }
569
570 // save values to restore later.
571 // but this must remain after(!) generating global observables
572 const RooArgSet* saveVars = (const RooArgSet*)allVars->snapshot();
573
574 if(fNuisanceParametersSampler) { // use nuisance parameters?
575 // Construct a set of nuisance parameters that has the parameters
576 // in the input paramPoint removed. Therefore, no parameter in
577 // paramPoint is randomized.
578 // Therefore when a parameter is given (should be held fixed),
579 // but is also in the list of nuisance parameters, the parameter
580 // will be held fixed. This is useful for debugging to hold single
581 // parameters fixed although under "normal" circumstances it is
582 // randomized.
583 RooArgSet allVarsMinusParamPoint(*allVars);
584 allVarsMinusParamPoint.remove(paramPoint, kFALSE, kTRUE); // match by name
585
586 // get nuisance parameter point and weight
587 fNuisanceParametersSampler->NextPoint(allVarsMinusParamPoint, weight);
588
589
590 }else{
591 weight = 1.0;
592 }
593
594 RooAbsData *data = Generate(pdf, observables);
595
596 // We generated the data with the randomized nuisance parameter (if hybrid)
597 // but now we are setting the nuisance parameters back to where they were.
598 *allVars = *saveVars;
599 delete allVars;
600 delete saveVars;
601
602 return data;
603}
604
605////////////////////////////////////////////////////////////////////////////////
606/// This is the generate function to use in the context of the ToyMCSampler
607/// instead of the standard RooAbsPdf::generate(...).
608/// It takes into account whether the number of events is given explicitly
609/// or whether it should use the expected number of events. It also takes
610/// into account the option to generate a binned data set (*i.e.* RooDataHist).
611
612RooAbsData* ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet* protoData, int forceEvents) const {
613
614 if(fProtoData) {
615 protoData = fProtoData;
616 forceEvents = protoData->numEntries();
617 }
618
619 RooAbsData *data = NULL;
620 int events = forceEvents;
621 if(events == 0) events = fNEvents;
622
623 // cannot use multigen when the nuisance parameters change for every toy
625
626 if (events == 0) {
627 if (pdf.canBeExtended() && pdf.expectedEvents(observables) > 0) {
628 if(fGenerateBinned) {
629 if(protoData) data = pdf.generate(observables, AllBinned(), Extended(), ProtoData(*protoData, true, true));
630 else data = pdf.generate(observables, AllBinned(), Extended());
631 } else {
632 if (protoData) {
633 if (useMultiGen) {
634 if (!_gs2) { _gs2 = pdf.prepareMultiGen(observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true)) ; }
635 data = pdf.generate(*_gs2) ;
636 } else {
637 data = pdf.generate (observables, Extended(), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true));
638 }
639 } else {
640 if (useMultiGen) {
642 data = pdf.generate(*_gs1) ;
643 } else {
645 }
646
647 }
648 }
649 } else {
651 << "ToyMCSampler: Error : pdf is not extended and number of events per toy is zero"
652 << endl;
653 }
654 } else {
655 if (fGenerateBinned) {
656 if(protoData) data = pdf.generate(observables, events, AllBinned(), ProtoData(*protoData, true, true));
657 else data = pdf.generate(observables, events, AllBinned());
658 } else {
659 if (protoData) {
660 if (useMultiGen) {
661 if (!_gs3) { _gs3 = pdf.prepareMultiGen(observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true)); }
662 data = pdf.generate(*_gs3) ;
663 } else {
664 data = pdf.generate (observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag), ProtoData(*protoData, true, true));
665 }
666 } else {
667 if (useMultiGen) {
669 data = pdf.generate(*_gs4) ;
670 } else {
671 data = pdf.generate (observables, NumEvents(events), AutoBinned(fGenerateAutoBinned), GenBinned(fGenerateBinnedTag));
672 }
673 }
674 }
675 }
676
677 // in case of number counting print observables
678 // if (data->numEntries() == 1) {
679 // std::cout << "generate observables : ";
680 // RooStats::PrintListContent(*data->get(0), std::cout);
681 // }
682
683 return data;
684}
685
686////////////////////////////////////////////////////////////////////////////////
687/// Extended interface to append to sampling distribution more samples
688
690 RooArgSet& allParameters,
692 Int_t additionalMC)
693{
694 Int_t tmp = fNToys;
695 fNToys = additionalMC;
696 SamplingDistribution* newSamples = GetSamplingDistribution(allParameters);
697 fNToys = tmp;
698
699 if(last){
700 last->Add(newSamples);
701 delete newSamples;
702 return last;
703 }
704
705 return newSamples;
706}
707
708////////////////////////////////////////////////////////////////////////////////
709/// clear the cache obtained from the pdf used for speeding the toy and global observables generation
710/// needs to be called every time the model pdf (fPdf) changes
711
713
714 if (_gs1) delete _gs1;
715 _gs1 = 0;
716 if (_gs2) delete _gs2;
717 _gs2 = 0;
718 if (_gs3) delete _gs3;
719 _gs3 = 0;
720 if (_gs4) delete _gs4;
721 _gs4 = 0;
722
723 // no need to delete the _pdfList since it is managed by the RooSimultaneous object
724 if (_pdfList.size() > 0) {
725 std::list<RooArgSet*>::iterator oiter = _obsList.begin();
726 for (std::list<RooAbsPdf::GenSpec*>::iterator giter = _gsList.begin(); giter != _gsList.end(); ++giter, ++oiter) {
727 delete *oiter;
728 delete *giter;
729 }
730 _pdfList.clear();
731 _obsList.clear();
732 _gsList.clear();
733 }
734
735 //LM: is this set really needed ??
736 if (_allVars) delete _allVars;
737 _allVars = 0;
738
739}
740
741} // end namespace RooStats
double
Definition: Converters.cxx:921
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
const Bool_t kFALSE
Definition: RtypesCore.h:90
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
char name[80]
Definition: TGX11.cxx:109
double ceil(double)
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Return the observables of this pdf given a set of observables.
Definition: RooAbsArg.h:276
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:1909
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
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:44
virtual const RooArgSet * get() const
Definition: RooAbsData.h:87
virtual Double_t weight() const =0
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:306
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:2160
Bool_t canBeExtended() const
Definition: RooAbsPdf.h:236
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:55
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events from this p.d.f for use in extended likelihood calculations.
Definition: RooAbsPdf.cxx:3283
virtual RooDataSet * generateSimGlobal(const RooArgSet &whatVars, Int_t nEvents)
Special generator interface for generation of 'global observables' – for RooStats tools.
Definition: RooAbsPdf.cxx:2654
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:126
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:23
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:33
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:35
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
Definition: RooRealVar.cxx:418
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:40
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.
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:72
const RooArgSet * fGlobalObservables
Definition: ToyMCSampler.h:257
RooAbsPdf::GenSpec * _gs3
GenSpec #2.
Definition: ToyMCSampler.h:290
std::list< RooAbsPdf::GenSpec * > _gsList
Definition: ToyMCSampler.h:287
std::string fSamplingDistName
Definition: ToyMCSampler.h:253
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:250
RooAbsPdf::GenSpec * _gs2
GenSpec #1.
Definition: ToyMCSampler.h:289
virtual SamplingDistribution * AppendSamplingDistribution(RooArgSet &allParameters, SamplingDistribution *last, Int_t additionalMC)
Extended interface to append to sampling distribution more samples.
NuisanceParametersSampler * fNuisanceParametersSampler
Definition: ToyMCSampler.h:281
const RooArgSet * fObservables
Definition: ToyMCSampler.h:256
virtual RooArgList * EvaluateAllTestStatistics(RooAbsData &data, const RooArgSet &poi)
Evaluate all test statistics, returning result and any detailed output.
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:293
virtual RooAbsData * GenerateToyData(RooArgSet &paramPoint, RooAbsPdf &pdf) const
Definition: ToyMCSampler.h:111
virtual void AddTestStatistic(TestStatistic *t=NULL)
Definition: ToyMCSampler.h:98
const RooArgSet * fNuisancePars
Definition: ToyMCSampler.h:255
std::list< RooArgSet * > _obsList
Definition: ToyMCSampler.h:286
static void SetAlwaysUseMultiGen(Bool_t flag)
std::vector< TestStatistic * > fTestStatistics
Definition: ToyMCSampler.h:251
ToyMCSampler()
Proof constructor. Do not use.
virtual void ClearCache()
clear the cache obtained from the pdf used for speeding the toy and global observables generation nee...
RooAbsPdf::GenSpec * _gs4
GenSpec #3.
Definition: ToyMCSampler.h:291
ProofConfig * fProofConfig
Definition: ToyMCSampler.h:279
const RooDataSet * fProtoData
Definition: ToyMCSampler.h:277
virtual SamplingDistribution * GetSamplingDistribution(RooArgSet &paramPoint)
std::list< RooAbsPdf * > _pdfList
Definition: ToyMCSampler.h:285
RooAbsPdf::GenSpec * _gs1
Definition: ToyMCSampler.h:288
RooAbsPdf * fPriorNuisance
Definition: ToyMCSampler.h:254
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:249
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:401
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition: TRandom.cxx:349
Basic string class.
Definition: TString.h:131
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:2311
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:67
@ NumIntegration
Definition: RooGlobalFunc.h:69
@ InputArguments
Definition: RooGlobalFunc.h:68
Namespace for the RooStats classes.
Definition: Asimov.h:19
void removeTopic(RooFit::MsgTopic oldTopic)
static void output(int code)
Definition: gifencode.c:226