Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooMCStudy.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooMCStudy.cxx
19\class RooMCStudy
20\ingroup Roofitcore
21
22RooMCStudy is a helper class to facilitate Monte Carlo studies
23such as 'goodness-of-fit' studies, that involve fitting a PDF
24to multiple toy Monte Carlo sets. These may be generated from either same PDF
25or from a different PDF with similar parameters.
26
27Given a fit and a generator PDF (they might be identical), RooMCStudy can produce
28toyMC samples and/or fit these.
29It accumulates the post-fit parameters of each iteration in a dataset. These can be
30retrieved using fitParams() or fitParDataSet(). This dataset additionally contains the
31variables
32- NLL: The value of the negative log-likelihood for each run.
33- ngen: The number of events generated for each run.
34
35Additional plotting routines simplify the task of plotting
36the distribution of the minimized likelihood, the fitted parameter values,
37fitted error and pull distribution.
38
39RooMCStudy provides the option to insert add-in modules
40that modify the generate-and-fit cycle and allow to perform
41extra steps in the cycle. Output of these modules can be stored
42alongside the fit results in the aggregate results dataset.
43These study modules should derive from the class RooAbsMCStudyModule.
44
45Check the RooFit tutorials
46- rf801_mcstudy.C
47- rf802_mcstudy_addons.C
48- rf803_mcstudy_addons2.C
49- rf804_mcstudy_constr.C
50for usage examples.
51**/
52
53
54
55#include "RooFit.h"
56#include "snprintf.h"
57#include <iostream>
58
59#include "RooMCStudy.h"
60#include "RooAbsMCStudyModule.h"
61
62#include "RooGenContext.h"
63#include "RooAbsPdf.h"
64#include "RooDataSet.h"
65#include "RooDataHist.h"
66#include "RooRealVar.h"
67#include "RooFitResult.h"
68#include "RooErrorVar.h"
69#include "RooFormulaVar.h"
70#include "RooArgList.h"
71#include "RooPlot.h"
72#include "RooGenericPdf.h"
73#include "RooRandom.h"
74#include "RooCmdConfig.h"
75#include "RooGlobalFunc.h"
76#include "RooPullVar.h"
77#include "RooMsgService.h"
78#include "RooProdPdf.h"
79
80using namespace std ;
81
83 ;
84
85
86/**
87Construct Monte Carlo Study Manager. This class automates generating data from a given PDF,
88fitting the PDF to data and accumulating the fit statistics.
89
90\param[in] model The PDF to be studied
91\param[in] observables The variables of the PDF to be considered observables
92\param[in] argX Arguments from the table below
93
94<table>
95<tr><th> Optional arguments <th>
96<tr><td> Silence() <td> Suppress all RooFit messages during running below PROGRESS level
97<tr><td> FitModel(const RooAbsPdf&) <td> The PDF for fitting if it is different from the PDF for generating.
98<tr><td> ConditionalObservables(const RooArgSet& set) <td> The set of observables that the PDF should _not_ be normalized over
99<tr><td> Binned(Bool_t flag) <td> Bin the dataset before fitting it. Speeds up fitting of large data samples
100<tr><td> FitOptions(const char*) <td> Classic fit options, provided for backward compatibility
101<tr><td> FitOptions(....) <td> Options to be used for fitting. All named arguments inside FitOptions() are passed to RooAbsPdf::fitTo().
102 `Save()` is especially interesting to be able to retrieve fit results of each run using fitResult().
103<tr><td> Verbose(Bool_t flag) <td> Activate informational messages in event generation phase
104<tr><td> Extended(Bool_t flag) <td> Determine number of events for each sample anew from a Poisson distribution
105<tr><td> Constrain(const RooArgSet& pars) <td> Apply internal constraints on given parameters in fit and sample constrained parameter values from constraint p.d.f for each toy.
106<tr><td> ExternalConstraints(const RooArgSet& ) <td> Apply internal constraints on given parameters in fit and sample constrained parameter values from constraint p.d.f for each toy.
107<tr><td> ProtoData(const RooDataSet&, Bool_t randOrder)
108 <td> Prototype data for the event generation. If the randOrder flag is set, the order of the dataset will be re-randomized for each generation
109 cycle to protect against systematic biases if the number of generated events does not exactly match the number of events in the prototype dataset
110 at the cost of reduced precision with mu equal to the specified number of events
111</table>
112*/
113RooMCStudy::RooMCStudy(const RooAbsPdf& model, const RooArgSet& observables,
114 const RooCmdArg& arg1, const RooCmdArg& arg2,
115 const RooCmdArg& arg3,const RooCmdArg& arg4,const RooCmdArg& arg5,
116 const RooCmdArg& arg6,const RooCmdArg& arg7,const RooCmdArg& arg8) : TNamed("mcstudy","mcstudy")
117
118{
119 // Stuff all arguments in a list
120 RooLinkedList cmdList;
121 cmdList.Add(const_cast<RooCmdArg*>(&arg1)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg2)) ;
122 cmdList.Add(const_cast<RooCmdArg*>(&arg3)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg4)) ;
123 cmdList.Add(const_cast<RooCmdArg*>(&arg5)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg6)) ;
124 cmdList.Add(const_cast<RooCmdArg*>(&arg7)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg8)) ;
125
126 // Select the pdf-specific commands
127 RooCmdConfig pc(Form("RooMCStudy::RooMCStudy(%s)",model.GetName())) ;
128
129 pc.defineObject("fitModel","FitModel",0,0) ;
130 pc.defineObject("condObs","ProjectedDependents",0,0) ;
131 pc.defineObject("protoData","PrototypeData",0,0) ;
132 pc.defineSet("cPars","Constrain",0,0) ;
133 pc.defineSet("extCons","ExternalConstraints",0,0) ;
134 pc.defineInt("silence","Silence",0,0) ;
135 pc.defineInt("randProtoData","PrototypeData",0,0) ;
136 pc.defineInt("verboseGen","Verbose",0,0) ;
137 pc.defineInt("extendedGen","Extended",0,0) ;
138 pc.defineInt("binGenData","Binned",0,0) ;
139 pc.defineString("fitOpts","FitOptions",0,"") ;
140 pc.defineInt("dummy","FitOptArgs",0,0) ;
141 pc.defineMutex("FitOptions","FitOptArgs") ; // can have either classic or new-style fit options
142 pc.defineMutex("Constrain","FitOptions") ; // constraints only work with new-style fit options
143 pc.defineMutex("ExternalConstraints","FitOptions") ; // constraints only work with new-style fit options
144
145 // Process and check varargs
146 pc.process(cmdList) ;
147 if (!pc.ok(kTRUE)) {
148 // WVE do something here
149 throw std::string("RooMCStudy::RooMCStudy() Error in parsing arguments passed to contructor") ;
150 return ;
151 }
152
153 // Save fit command options
154 if (pc.hasProcessed("FitOptArgs")) {
155 RooCmdArg* fitOptArg = static_cast<RooCmdArg*>(cmdList.FindObject("FitOptArgs")) ;
156 for (Int_t i=0 ; i<fitOptArg->subArgs().GetSize() ;i++) {
157 _fitOptList.Add(new RooCmdArg(static_cast<RooCmdArg&>(*fitOptArg->subArgs().At(i)))) ;
158 }
159 }
160
161 // Decode command line arguments
162 _silence = pc.getInt("silence") ;
163 _verboseGen = pc.getInt("verboseGen") ;
164 _extendedGen = pc.getInt("extendedGen") ;
165 _binGenData = pc.getInt("binGenData") ;
166 _randProto = pc.getInt("randProtoData") ;
167
168 // Process constraints specifications
169 const RooArgSet* cParsTmp = pc.getSet("cPars") ;
170 const RooArgSet* extCons = pc.getSet("extCons") ;
171
172 RooArgSet* cPars = new RooArgSet ;
173 if (cParsTmp) {
174 cPars->add(*cParsTmp) ;
175 }
176
177 // If constraints are specified, add to fit options
178 if (cPars) {
180 }
181 if (extCons) {
183 }
184
185 // Make list of all constraints
186 RooArgSet allConstraints ;
187 RooArgSet consPars ;
188 if (cPars) {
189 RooArgSet* constraints = model.getAllConstraints(observables,*cPars,kTRUE) ;
190 if (constraints) {
191 allConstraints.add(*constraints) ;
192 delete constraints ;
193 }
194 }
195
196 // Construct constraint p.d.f
197 if (allConstraints.getSize()>0) {
198 _constrPdf = new RooProdPdf("mcs_constr_prod","RooMCStudy constraints product",allConstraints) ;
199
200 if (cPars) {
201 consPars.add(*cPars) ;
202 } else {
203 RooArgSet* params = model.getParameters(observables) ;
204 RooArgSet* cparams = _constrPdf->getObservables(*params) ;
205 consPars.add(*cparams) ;
206 delete params ;
207 delete cparams ;
208 }
210
212
213 coutI(Generation) << "RooMCStudy::RooMCStudy: INFO have pdf with constraints, will generate parameters from constraint pdf for each experiment" << endl ;
214
215
216 } else {
217 _constrPdf = 0 ;
219
221 }
222
223
224 // Extract generator and fit models
225 _genModel = const_cast<RooAbsPdf*>(&model) ;
226 _genSample = 0 ;
227 RooAbsPdf* fitModel = static_cast<RooAbsPdf*>(pc.getObject("fitModel",0)) ;
228 _fitModel = fitModel ? fitModel : _genModel ;
229
230 // Extract conditional observables and prototype data
231 _genProtoData = static_cast<RooDataSet*>(pc.getObject("protoData",0)) ;
232 if (pc.getObject("condObs",0)) {
233 _projDeps.add(static_cast<RooArgSet&>(*pc.getObject("condObs",0))) ;
234 }
235
236 _dependents.add(observables) ;
237
239 _fitOptions = pc.getString("fitOpts") ;
241
243 oocoutW(_fitModel,Generation) << "RooMCStudy::RooMCStudy: WARNING Using generator option 'e' (Poisson distribution of #events) together " << endl
244 << " with a prototype dataset implies incomplete sampling or oversampling of proto data." << endl
245 << " Use option \"r\" to randomize prototype dataset order and thus to randomize" << endl
246 << " the set of over/undersampled prototype events for each generation cycle." << endl ;
247 }
248
250 if (!_binGenData) {
253 } else {
254 _genContext = 0 ;
255 }
256
258
259 // Store list of parameters and save initial values separately
262
264
265 // Place holder for NLL
266 _nllVar = new RooRealVar("NLL","-log(Likelihood)",0) ;
267
268 // Place holder for number of generated events
269 _ngenVar = new RooRealVar("ngen","number of generated events",0) ;
270
271 // Create data set containing parameter values, errors and pulls
272 RooArgSet tmp2(*_fitParams) ;
273 tmp2.add(*_nllVar) ;
274 tmp2.add(*_ngenVar) ;
275
276 // Mark all variable to store their errors in the dataset
277 tmp2.setAttribAll("StoreError",kTRUE) ;
278 tmp2.setAttribAll("StoreAsymError",kTRUE) ;
279 TString fpdName ;
280 if (_fitModel==_genModel) {
281 fpdName = Form("fitParData_%s",_fitModel->GetName()) ;
282 } else {
283 fpdName= Form("fitParData_%s_%s",_fitModel->GetName(),_genModel->GetName()) ;
284 }
285
286 _fitParData = new RooDataSet(fpdName.Data(),"Fit Parameters DataSet",tmp2) ;
287 tmp2.setAttribAll("StoreError",kFALSE) ;
288 tmp2.setAttribAll("StoreAsymError",kFALSE) ;
289
290 if (_perExptGenParams) {
291 _genParData = new RooDataSet("genParData","Generated Parameters dataset",*_genParams) ;
292 } else {
293 _genParData = 0 ;
294 }
295
296 // Append proto variables to allDependents
297 if (_genProtoData) {
299 }
300
301 // Call module initializers
302 list<RooAbsMCStudyModule*>::iterator iter ;
303 for (iter=_modList.begin() ; iter!= _modList.end() ; ++iter) {
304 Bool_t ok = (*iter)->doInitializeInstance(*this) ;
305 if (!ok) {
306 oocoutE(_fitModel,Generation) << "RooMCStudy::ctor: removing study module " << (*iter)->GetName() << " from analysis chain because initialization failed" << endl ;
307 iter = _modList.erase(iter) ;
308 }
309 }
310
311}
312
313
314////////////////////////////////////////////////////////////////////////////////
315/// \deprecated PLEASE USE CONSTRUCTOR WITH NAMED ARGUMENTS. RETAINED FOR BACKWARD COMPATIBILY.
316///
317/// Constructor with a generator and fit model. Both models may point
318/// to the same object. The 'dependents' set of variables is generated
319/// in the generator phase. The optional prototype dataset is passed to
320/// the generator
321///
322/// Available generator options
323/// v - Verbose
324/// e - Extended: use Poisson distribution for Nevts generated
325///
326/// Available fit options
327/// See RooAbsPdf::fitTo()
328///
329
330RooMCStudy::RooMCStudy(const RooAbsPdf& genModel, const RooAbsPdf& fitModel,
331 const RooArgSet& dependents, const char* genOptions,
332 const char* fitOptions, const RooDataSet* genProtoData,
333 const RooArgSet& projDeps) :
334 TNamed("mcstudy","mcstudy"),
335 _genModel((RooAbsPdf*)&genModel),
336 _genProtoData(genProtoData),
337 _projDeps(projDeps),
338 _constrPdf(0),
339 _constrGenContext(0),
340 _dependents(dependents),
341 _allDependents(dependents),
342 _fitModel((RooAbsPdf*)&fitModel),
343 _nllVar(0),
344 _ngenVar(0),
345 _genParData(0),
346 _fitOptions(fitOptions),
347 _canAddFitResults(kTRUE),
348 _perExptGenParams(0),
349 _silence(kFALSE)
350{
351 // Decode generator options
352 TString genOpt(genOptions) ;
353 genOpt.ToLower() ;
354 _verboseGen = genOpt.Contains("v") ;
355 _extendedGen = genOpt.Contains("e") ;
356 _binGenData = genOpt.Contains("b") ;
357 _randProto = genOpt.Contains("r") ;
358
359 if (_extendedGen && genProtoData && !_randProto) {
360 oocoutE(_fitModel,Generation) << "RooMCStudy::RooMCStudy: WARNING Using generator option 'e' (Poisson distribution of #events) together " << endl
361 << " with a prototype dataset implies incomplete sampling or oversampling of proto data." << endl
362 << " Use option \"r\" to randomize prototype dataset order and thus to randomize" << endl
363 << " the set of over/undersampled prototype events for each generation cycle." << endl ;
364 }
365
366 if (!_binGenData) {
367 _genContext = genModel.genContext(dependents,genProtoData,0,_verboseGen) ;
368 } else {
369 _genContext = 0 ;
370 }
372 _genSample = 0 ;
373 RooArgSet* tmp = genModel.getParameters(&dependents) ;
375 delete tmp ;
376
377 // Store list of parameters and save initial values separately
378 _fitParams = fitModel.getParameters(&dependents) ;
380
381 _nExpGen = _extendedGen ? genModel.expectedEvents(&dependents) : 0 ;
382
383 // Place holder for NLL
384 _nllVar = new RooRealVar("NLL","-log(Likelihood)",0) ;
385
386 // Place holder for number of generated events
387 _ngenVar = new RooRealVar("ngen","number of generated events",0) ;
388
389 // Create data set containing parameter values, errors and pulls
390 RooArgSet tmp2(*_fitParams) ;
391 tmp2.add(*_nllVar) ;
392 tmp2.add(*_ngenVar) ;
393
394 // Mark all variable to store their errors in the dataset
395 tmp2.setAttribAll("StoreError",kTRUE) ;
396 tmp2.setAttribAll("StoreAsymError",kTRUE) ;
397 _fitParData = new RooDataSet("fitParData","Fit Parameters DataSet",tmp2) ;
398 tmp2.setAttribAll("StoreError",kFALSE) ;
399 tmp2.setAttribAll("StoreAsymError",kFALSE) ;
400
401 // Append proto variables to allDependents
402 if (genProtoData) {
403 _allDependents.add(*genProtoData->get(),kTRUE) ;
404 }
405
406 // Call module initializers
407 list<RooAbsMCStudyModule*>::iterator iter ;
408 for (iter=_modList.begin() ; iter!= _modList.end() ; ++iter) {
409 Bool_t ok = (*iter)->doInitializeInstance(*this) ;
410 if (!ok) {
411 oocoutE(_fitModel,Generation) << "RooMCStudy::ctor: removing study module " << (*iter)->GetName() << " from analysis chain because initialization failed" << endl ;
412 iter = _modList.erase(iter) ;
413 }
414 }
415
416}
417
418
419
420////////////////////////////////////////////////////////////////////////////////
421
423{
426 delete _ngenVar ;
427 delete _fitParData ;
428 delete _genParData ;
429 delete _fitInitParams ;
430 delete _fitParams ;
431 delete _genInitParams ;
432 delete _genParams ;
433 delete _genContext ;
434 delete _nllVar ;
435 delete _constrPdf ;
436 delete _constrGenContext ;
437}
438
439
440
441////////////////////////////////////////////////////////////////////////////////
442/// Insert given RooMCStudy add-on module to the processing chain
443/// of this MCStudy object
444
446{
447 module.doInitializeInstance(*this) ;
448 _modList.push_back(&module) ;
449}
450
451
452
453////////////////////////////////////////////////////////////////////////////////
454/// Run engine method. Generate and/or fit, according to flags, 'nSamples' samples of 'nEvtPerSample' events.
455/// If keepGenData is set, all generated data sets will be kept in memory and can be accessed
456/// later via genData().
457///
458/// When generating, data sets will be written out in ascii form if the pattern string is supplied
459/// The pattern, which is a template for snprintf, should look something like "data/toymc_%04d.dat"
460/// and should contain one integer field that encodes the sample serial number.
461///
462/// When fitting only, data sets may optionally be read from ascii files, using the same file
463/// pattern.
464///
465
466Bool_t RooMCStudy::run(Bool_t doGenerate, Bool_t DoFit, Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char* asciiFilePat)
467{
469 if (_silence) {
472 }
473
474 list<RooAbsMCStudyModule*>::iterator iter ;
475 for (iter=_modList.begin() ; iter!= _modList.end() ; ++iter) {
476 (*iter)->initializeRun(nSamples) ;
477 }
478
479 Int_t prescale = nSamples>100 ? Int_t(nSamples/100) : 1 ;
480
481 while(nSamples--) {
482
483 if (nSamples%prescale==0) {
484 oocoutP(_fitModel,Generation) << "RooMCStudy::run: " ;
485 if (doGenerate) ooccoutI(_fitModel,Generation) << "Generating " ;
486 if (doGenerate && DoFit) ooccoutI(_fitModel,Generation) << "and " ;
487 if (DoFit) ooccoutI(_fitModel,Generation) << "fitting " ;
488 ooccoutP(_fitModel,Generation) << "sample " << nSamples << endl ;
489 }
490
491 _genSample = 0;
492 Bool_t existingData = kFALSE ;
493 if (doGenerate) {
494 // Generate sample
495 Int_t nEvt(nEvtPerSample) ;
496
497 // Reset generator parameters to initial values
499
500 // If constraints are present, sample generator values from constraints
501 if (_constrPdf) {
503 _genParams->assign(*tmp->get()) ;
504 delete tmp ;
505 }
506
507 // Save generated parameters if required
508 if (_genParData) {
510 }
511
512 // Call module before-generation hook
513 list<RooAbsMCStudyModule*>::iterator iter2 ;
514 for (iter2=_modList.begin() ; iter2!= _modList.end() ; ++iter2) {
515 (*iter2)->processBeforeGen(nSamples) ;
516 }
517
518 if (_binGenData) {
519
520 // Calculate the number of (extended) events for this run
521 if (_extendedGen) {
523 nEvt = RooRandom::randomGenerator()->Poisson(nEvtPerSample==0?_nExpGen:nEvtPerSample) ;
524 }
525
526 // Binned generation
528
529 } else {
530
531 // Calculate the number of (extended) events for this run
532 if (_extendedGen) {
534 nEvt = RooRandom::randomGenerator()->Poisson(nEvtPerSample==0?_nExpGen:nEvtPerSample) ;
535 }
536
537 // Optional randomization of protodata for this run
539 oocoutI(_fitModel,Generation) << "RooMCStudy: (Re)randomizing event order in prototype dataset (Nevt=" << nEvt << ")" << endl ;
541 _genContext->setProtoDataOrder(newOrder) ;
542 delete[] newOrder ;
543 }
544
545 coutP(Generation) << "RooMCStudy: now generating " << nEvt << " events" << endl ;
546
547 // Actual generation of events
548 if (nEvt>0) {
550 } else {
551 // Make empty dataset
552 _genSample = new RooDataSet("emptySample","emptySample",_dependents) ;
553 }
554 }
555
556
557 //} else if (asciiFilePat && &asciiFilePat) { //warning: the address of 'asciiFilePat' will always evaluate as 'true'
558 } else if (asciiFilePat) {
559
560 // Load sample from ASCII file
561 char asciiFile[1024] ;
562 snprintf(asciiFile,1024,asciiFilePat,nSamples) ;
563 RooArgList depList(_allDependents) ;
564 _genSample = RooDataSet::read(asciiFile,depList,"q") ;
565
566 } else {
567
568 // Load sample from internal list
569 _genSample = (RooDataSet*) _genDataList.At(nSamples) ;
570 existingData = kTRUE ;
571 if (!_genSample) {
572 oocoutW(_fitModel,Generation) << "RooMCStudy::run: WARNING: Sample #" << nSamples << " not loaded, skipping" << endl ;
573 continue ;
574 }
575 }
576
577 // Save number of generated events
579
580 // Call module between generation and fitting hook
581 list<RooAbsMCStudyModule*>::iterator iter3 ;
582 for (iter3=_modList.begin() ; iter3!= _modList.end() ; ++iter3) {
583 (*iter3)->processBetweenGenAndFit(nSamples) ;
584 }
585
586 if (DoFit) fitSample(_genSample) ;
587
588 // Call module between generation and fitting hook
589 for (iter3=_modList.begin() ; iter3!= _modList.end() ; ++iter3) {
590 (*iter3)->processAfterFit(nSamples) ;
591 }
592
593 // Optionally write to ascii file
594 if (doGenerate && asciiFilePat && *asciiFilePat) {
595 char asciiFile[1024] ;
596 snprintf(asciiFile,1024,asciiFilePat,nSamples) ;
597 RooDataSet* unbinnedData = dynamic_cast<RooDataSet*>(_genSample) ;
598 if (unbinnedData) {
599 unbinnedData->write(asciiFile) ;
600 } else {
601 coutE(InputArguments) << "RooMCStudy::run(" << GetName() << ") ERROR: ASCII writing of binned datasets is not supported" << endl ;
602 }
603 }
604
605 // Add to list or delete
606 if (!existingData) {
607 if (keepGenData) {
609 } else {
610 delete _genSample ;
611 }
612 }
613 }
614
615 for (iter=_modList.begin() ; iter!= _modList.end() ; ++iter) {
616 RooDataSet* auxData = (*iter)->finalizeRun() ;
617 if (auxData) {
618 _fitParData->merge(auxData) ;
619 }
620 }
621
623
624 if (_genParData) {
625 const RooArgSet* genPars = _genParData->get() ;
626 TIterator* iter2 = genPars->createIterator() ;
627 RooAbsArg* arg ;
628 while((arg=(RooAbsArg*)iter2->Next())) {
629 _genParData->changeObservableName(arg->GetName(),Form("%s_gen",arg->GetName())) ;
630 }
631 delete iter2 ;
632
634 }
635
636 if (DoFit) calcPulls() ;
637
638 if (_silence) {
640 }
641
642 return kFALSE ;
643}
644
645
646
647
648
649
650////////////////////////////////////////////////////////////////////////////////
651/// Generate and fit 'nSamples' samples of 'nEvtPerSample' events.
652/// If keepGenData is set, all generated data sets will be kept in memory and can be accessed
653/// later via genData().
654///
655/// Data sets will be written out in ascii form if the pattern string is supplied.
656/// The pattern, which is a template for snprintf, should look something like "data/toymc_%04d.dat"
657/// and should contain one integer field that encodes the sample serial number.
658///
659
660Bool_t RooMCStudy::generateAndFit(Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char* asciiFilePat)
661{
662 // Clear any previous data in memory
663 _fitResList.Delete() ; // even though the fit results are owned by gROOT, we still want to scratch them here.
665 _fitParData->reset() ;
666
667 return run(kTRUE,kTRUE,nSamples,nEvtPerSample,keepGenData,asciiFilePat) ;
668}
669
670
671
672////////////////////////////////////////////////////////////////////////////////
673/// Generate 'nSamples' samples of 'nEvtPerSample' events.
674/// If keepGenData is set, all generated data sets will be kept in memory
675/// and can be accessed later via genData().
676///
677/// Data sets will be written out in ascii form if the pattern string is supplied.
678/// The pattern, which is a template for snprintf, should look something like "data/toymc_%04d.dat"
679/// and should contain one integer field that encodes the sample serial number.
680///
681
682Bool_t RooMCStudy::generate(Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char* asciiFilePat)
683{
684 // Clear any previous data in memory
686
687 return run(kTRUE,kFALSE,nSamples,nEvtPerSample,keepGenData,asciiFilePat) ;
688}
689
690
691
692////////////////////////////////////////////////////////////////////////////////
693/// Fit 'nSamples' datasets, which are read from ASCII files.
694///
695/// The ascii file pattern, which is a template for snprintf, should look something like "data/toymc_%04d.dat"
696/// and should contain one integer field that encodes the sample serial number.
697///
698
699Bool_t RooMCStudy::fit(Int_t nSamples, const char* asciiFilePat)
700{
701 // Clear any previous data in memory
702 _fitResList.Delete() ; // even though the fit results are owned by gROOT, we still want to scratch them here.
703 _fitParData->reset() ;
704
705 return run(kFALSE,kTRUE,nSamples,0,kFALSE,asciiFilePat) ;
706}
707
708
709
710////////////////////////////////////////////////////////////////////////////////
711/// Fit 'nSamples' datasets, as supplied in 'dataSetList'
712///
713
714Bool_t RooMCStudy::fit(Int_t nSamples, TList& dataSetList)
715{
716 // Clear any previous data in memory
717 _fitResList.Delete() ; // even though the fit results are owned by gROOT, we still want to scratch them here.
719 _fitParData->reset() ;
720
721 // Load list of data sets
722 TIterator* iter = dataSetList.MakeIterator() ;
723 RooAbsData* gset ;
724 while((gset=(RooAbsData*)iter->Next())) {
725 _genDataList.Add(gset) ;
726 }
727 delete iter ;
728
729 return run(kFALSE,kTRUE,nSamples,0,kTRUE,0) ;
730}
731
732
733
734////////////////////////////////////////////////////////////////////////////////
735/// Reset all fit parameters to the initial model
736/// parameters at the time of the RooMCStudy constructor
737
739{
741}
742
743
744
745////////////////////////////////////////////////////////////////////////////////
746/// Internal function. Performs actual fit according to specifications
747
749{
750 // Fit model to data set
751 TString fitOpt2(_fitOptions) ; fitOpt2.Append("r") ;
752 if (_silence) {
753 fitOpt2.Append("b") ;
754 }
755
756 // Optionally bin dataset before fitting
757 RooAbsData* data ;
758 if (_binGenData) {
759 RooArgSet* depList = _fitModel->getObservables(genSample) ;
760 data = new RooDataHist(genSample->GetName(),genSample->GetTitle(),*depList,*genSample) ;
761 delete depList ;
762 } else {
763 data = genSample ;
764 }
765
766 RooFitResult* fr ;
767 if (_fitOptList.GetSize()==0) {
768 if (_projDeps.getSize()>0) {
770 } else {
771 fr = (RooFitResult*) _fitModel->fitTo(*data,RooFitLegacy::FitOptions(fitOpt2)) ;
772 }
773 } else {
774 RooCmdArg save = RooFit::Save() ;
776 RooCmdArg plevel = RooFit::PrintLevel(-1) ;
777 RooLinkedList fitOptList(_fitOptList) ;
778 fitOptList.Add(&save) ;
779 if (_projDeps.getSize()>0) {
780 fitOptList.Add(&condo) ;
781 }
782 if (_silence) {
783 fitOptList.Add(&plevel) ;
784 }
785 fr = (RooFitResult*) _fitModel->fitTo(*data,fitOptList) ;
786 }
787
788 if (_binGenData) delete data ;
789
790 return fr ;
791}
792
793
794
795////////////////////////////////////////////////////////////////////////////////
796/// Redo fit on 'current' toy sample, or if genSample is not NULL
797/// do fit on given sample instead
798
800{
801 if (!genSample) {
802 genSample = _genSample ;
803 }
804
805 RooFitResult* fr(0) ;
806 if (genSample->sumEntries()>0) {
807 fr = doFit(genSample) ;
808 }
809
810 return fr ;
811}
812
813
814
815////////////////////////////////////////////////////////////////////////////////
816/// Internal method. Fit given dataset with fit model. If fit
817/// converges (TMinuit status code zero) The fit results are appended
818/// to the fit results dataset
819///
820/// If the fit option "r" is supplied, the RooFitResult
821/// objects will always be saved, regardless of the
822/// fit status. RooFitResults objects can be retrieved
823/// later via fitResult().
824///
825
827{
828 // Reset all fit parameters to their initial values
830
831 // Perform actual fit
832 Bool_t ok ;
833 RooFitResult* fr(0) ;
834 if (genSample->sumEntries()>0) {
835 fr = doFit(genSample) ;
836 ok = (fr->status()==0) ;
837 } else {
838 ok = kFALSE ;
839 }
840
841 // If fit converged, store parameters and NLL
842 if (ok) {
843 _nllVar->setVal(fr->minNll()) ;
844 RooArgSet tmp(*_fitParams) ;
845 tmp.add(*_nllVar) ;
846 tmp.add(*_ngenVar) ;
847
848 _fitParData->add(tmp) ;
849 }
850
851 // Store fit result if requested by user
852 Bool_t userSaveRequest = kFALSE ;
853 if (_fitOptList.GetSize()>0) {
854 if (_fitOptList.FindObject("Save")) userSaveRequest = kTRUE ;
855 } else {
856 if (_fitOptions.Contains("r")) userSaveRequest = kTRUE ;
857 }
858
859 if (userSaveRequest) {
860 _fitResList.Add(fr) ;
861 } else {
862 delete fr ;
863 }
864
865 return !ok ;
866}
867
868
869
870////////////////////////////////////////////////////////////////////////////////
871/// Utility function to add fit result from external fit to this RooMCStudy
872/// and process its results through the standard RooMCStudy statistics gathering tools.
873/// This function allows users to run the toy MC generation and/or fitting
874/// in a distributed way and to collect and analyze the results in a RooMCStudy
875/// as if they were run locally.
876///
877/// This method is only functional if this RooMCStudy object is cleanm, i.e. it was not used
878/// to generate and/or fit any samples.
879
881{
882 if (!_canAddFitResults) {
883 oocoutE(_fitModel,InputArguments) << "RooMCStudy::addFitResult: ERROR cannot add fit results in current state" << endl ;
884 return kTRUE ;
885 }
886
887 // Transfer contents of fit result to fitParams ;
889
890 // If fit converged, store parameters and NLL
891 Bool_t ok = (fr.status()==0) ;
892 if (ok) {
893 _nllVar->setVal(fr.minNll()) ;
894 RooArgSet tmp(*_fitParams) ;
895 tmp.add(*_nllVar) ;
896 tmp.add(*_ngenVar) ;
897 _fitParData->add(tmp) ;
898 }
899
900 // Store fit result if requested by user
901 if (_fitOptions.Contains("r")) {
902 _fitResList.Add((TObject*)&fr) ;
903 }
904
905 return kFALSE ;
906}
907
908
909
910////////////////////////////////////////////////////////////////////////////////
911/// Calculate the pulls for all fit parameters in
912/// the fit results data set, and add them to that dataset.
913
915{
916 for (auto it = _fitParams->begin(); it != _fitParams->end(); ++it) {
917 const auto par = static_cast<RooRealVar*>(*it);
918 RooErrorVar* err = par->errorVar();
919 _fitParData->addColumn(*err);
920 delete err;
921
922 TString name(par->GetName()), title(par->GetTitle()) ;
923 name.Append("pull") ;
924 title.Append(" Pull") ;
925
926 if (!par->hasError(false)) {
927 coutW(Generation) << "Fit parameter '" << par->GetName() << "' does not have an error."
928 " A pull distribution cannot be generated. This might be caused by the parameter being constant or"
929 " because the fits were not run." << std::endl;
930 continue;
931 }
932
933 // First look in fitParDataset to see if per-experiment generated value has been stored
934 auto genParOrig = static_cast<RooAbsReal*>(_fitParData->get()->find(Form("%s_gen",par->GetName())));
935 if (genParOrig && _perExptGenParams) {
936
937 RooPullVar pull(name,title,*par,*genParOrig) ;
939
940 } else {
941 // If not use fixed generator value
942 genParOrig = static_cast<RooAbsReal*>(_genInitParams->find(par->GetName()));
943
944 if (!genParOrig) {
945 std::size_t index = it - _fitParams->begin();
946 genParOrig = index < _genInitParams->size() ?
947 static_cast<RooAbsReal*>((*_genInitParams)[index]) :
948 nullptr;
949
950 if (genParOrig) {
951 coutW(Generation) << "The fit parameter '" << par->GetName() << "' is not in the model that was used to generate toy data. "
952 "The parameter '" << genParOrig->GetName() << "'=" << genParOrig->getVal() << " was found at the same position in the generator model."
953 " It will be used to compute pulls."
954 "\nIf this is not desired, the parameters of the generator model need to be renamed or reordered." << std::endl;
955 }
956 }
957
958 if (genParOrig) {
959 std::unique_ptr<RooAbsReal> genPar(static_cast<RooAbsReal*>(genParOrig->Clone("truth")));
960 RooPullVar pull(name,title,*par,*genPar);
961
963 } else {
964 coutE(Generation) << "Cannot generate pull distribution for the fit parameter '" << par->GetName() << "'."
965 "\nNo similar parameter was found in the set of parameters that were used to generate toy data." << std::endl;
966 }
967 }
968 }
969}
970
971
972
973
974////////////////////////////////////////////////////////////////////////////////
975/// Return a RooDataSet containing the post-fit parameters of each toy cycle.
976/// This dataset also contains any additional output that was generated
977/// by study modules that were added to this RooMCStudy.
978/// By default, the two following variables are added (apart from fit parameters):
979/// - NLL: The value of the negative log-likelihood for each run.
980/// - ngen: Number of events generated for each run.
982{
983 if (_canAddFitResults) {
984 calcPulls() ;
986 }
987
988 return *_fitParData ;
989}
990
991
992
993////////////////////////////////////////////////////////////////////////////////
994/// Return an argset with the fit parameters for the given sample number
995///
996/// NB: The fit parameters are only stored for successfull fits,
997/// thus the maximum sampleNum can be less that the number
998/// of generated samples and if so, the indeces will
999/// be out of synch with genData() and fitResult()
1000
1001const RooArgSet* RooMCStudy::fitParams(Int_t sampleNum) const
1002{
1003 // Check if sampleNum is in range
1004 if (sampleNum<0 || sampleNum>=_fitParData->numEntries()) {
1005 oocoutE(_fitModel,InputArguments) << "RooMCStudy::fitParams: ERROR, invalid sample number: " << sampleNum << endl ;
1006 return 0 ;
1007 }
1008
1009 return _fitParData->get(sampleNum) ;
1010}
1011
1012
1013
1014////////////////////////////////////////////////////////////////////////////////
1015/// Return the RooFitResult of the fit with the given run number.
1016///
1017/// \note Fit results are not saved by default. This requires passing `FitOptions(Save(), ...)`
1018/// to the constructor.
1020{
1021 // Check if sampleNum is in range
1022 if (sampleNum<0 || sampleNum>=_fitResList.GetSize()) {
1023 oocoutE(_fitModel,InputArguments) << "RooMCStudy::fitResult: ERROR, invalid sample number: " << sampleNum << endl ;
1024 return 0 ;
1025 }
1026
1027 // Retrieve fit result object
1028 const RooFitResult* fr = (RooFitResult*) _fitResList.At(sampleNum) ;
1029 if (fr) {
1030 return fr ;
1031 } else {
1032 oocoutE(_fitModel,InputArguments) << "RooMCStudy::fitResult: ERROR, no fit result saved for sample "
1033 << sampleNum << ", did you use the 'r; fit option?" << endl ;
1034 }
1035 return 0 ;
1036}
1037
1038
1039
1040////////////////////////////////////////////////////////////////////////////////
1041/// Return the given generated dataset. This method will only return datasets
1042/// if during the run cycle it was indicated that generator data should be saved.
1043
1045{
1046 // Check that generated data was saved
1047 if (_genDataList.GetSize()==0) {
1048 oocoutE(_fitModel,InputArguments) << "RooMCStudy::genData() ERROR, generated data was not saved" << endl ;
1049 return 0 ;
1050 }
1051
1052 // Check if sampleNum is in range
1053 if (sampleNum<0 || sampleNum>=_genDataList.GetSize()) {
1054 oocoutE(_fitModel,InputArguments) << "RooMCStudy::genData() ERROR, invalid sample number: " << sampleNum << endl ;
1055 return 0 ;
1056 }
1057
1058 return (RooAbsData*) _genDataList.At(sampleNum) ;
1059}
1060
1061
1062
1063////////////////////////////////////////////////////////////////////////////////
1064/// Plot the distribution of fitted values of a parameter. The parameter shown is the one from which the RooPlot
1065/// was created, e.g.
1066///
1067/// RooPlot* frame = param.frame(100,-10,10) ;
1068/// mcstudy.paramOn(frame,LineStyle(kDashed)) ;
1069///
1070/// Any named arguments passed to plotParamOn() are forwarded to the underlying plotOn() call
1071
1072RooPlot* RooMCStudy::plotParamOn(RooPlot* frame, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
1073 const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
1074{
1075 _fitParData->plotOn(frame,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
1076 return frame ;
1077}
1078
1079
1080
1081////////////////////////////////////////////////////////////////////////////////
1082/// Plot the distribution of the fitted value of the given parameter on a newly created frame.
1083///
1084/// <table>
1085/// <tr><th> Optional arguments <th>
1086/// <tr><td> FrameRange(double lo, double hi) <td> Set range of frame to given specification
1087/// <tr><td> FrameBins(int bins) <td> Set default number of bins of frame to given number
1088/// <tr><td> Frame() <td> Pass supplied named arguments to RooAbsRealLValue::frame() function. See there
1089/// for list of allowed arguments
1090/// </table>
1091/// If no frame specifications are given, the AutoRange() feature will be used to set the range
1092/// Any other named argument is passed to the RooAbsData::plotOn() call. See that function for allowed options
1093
1094RooPlot* RooMCStudy::plotParam(const char* paramName, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
1095 const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
1096{
1097
1098 // Find parameter in fitParDataSet
1099 RooRealVar* param = static_cast<RooRealVar*>(_fitParData->get()->find(paramName)) ;
1100 if (!param) {
1101 oocoutE(_fitModel,InputArguments) << "RooMCStudy::plotParam: ERROR: no parameter defined with name " << paramName << endl ;
1102 return 0 ;
1103 }
1104
1105 // Forward to implementation below
1106 return plotParam(*param,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
1107}
1108
1109
1110
1111////////////////////////////////////////////////////////////////////////////////
1112/// Plot the distribution of the fitted value of the given parameter on a newly created frame.
1113/// \copydetails RooMCStudy::plotParam(const char* paramName, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
1114/// const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
1115
1116RooPlot* RooMCStudy::plotParam(const RooRealVar& param, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
1117 const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
1118{
1119 // Stuff all arguments in a list
1120 RooLinkedList cmdList;
1121 cmdList.Add(const_cast<RooCmdArg*>(&arg1)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg2)) ;
1122 cmdList.Add(const_cast<RooCmdArg*>(&arg3)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg4)) ;
1123 cmdList.Add(const_cast<RooCmdArg*>(&arg5)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg6)) ;
1124 cmdList.Add(const_cast<RooCmdArg*>(&arg7)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg8)) ;
1125
1126 RooPlot* frame = makeFrameAndPlotCmd(param, cmdList) ;
1127 if (frame) {
1128 _fitParData->plotOn(frame, cmdList) ;
1129 }
1130
1131 return frame ;
1132}
1133
1134
1135
1136////////////////////////////////////////////////////////////////////////////////
1137/// Plot the distribution of the -log(L) values on a newly created frame.
1138///
1139/// <table>
1140/// <tr><th> Optional arguments <th>
1141/// <tr><td> FrameRange(double lo, double hi) <td> Set range of frame to given specification
1142/// <tr><td> FrameBins(int bins) <td> Set default number of bins of frame to given number
1143/// <tr><td> Frame() <td> Pass supplied named arguments to RooAbsRealLValue::frame() function. See there
1144/// for list of allowed arguments
1145/// </table>
1146///
1147/// If no frame specifications are given, the AutoRange() feature will be used to set the range.
1148/// Any other named argument is passed to the RooAbsData::plotOn() call. See that function for allowed options
1149
1151 const RooCmdArg& arg3, const RooCmdArg& arg4,
1152 const RooCmdArg& arg5, const RooCmdArg& arg6,
1153 const RooCmdArg& arg7, const RooCmdArg& arg8)
1154{
1155 return plotParam(*_nllVar,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
1156}
1157
1158
1159
1160////////////////////////////////////////////////////////////////////////////////
1161/// Plot the distribution of the fit errors for the specified parameter on a newly created frame.
1162///
1163/// <table>
1164/// <tr><th> Optional arguments <th>
1165/// <tr><td> FrameRange(double lo, double hi) <td> Set range of frame to given specification
1166/// <tr><td> FrameBins(int bins) <td> Set default number of bins of frame to given number
1167/// <tr><td> Frame() <td> Pass supplied named arguments to RooAbsRealLValue::frame() function. See there
1168/// for list of allowed arguments
1169/// </table>
1170///
1171/// If no frame specifications are given, the AutoRange() feature will be used to set a default range.
1172/// Any other named argument is passed to the RooAbsData::plotOn() call. See that function for allowed options.
1173
1174RooPlot* RooMCStudy::plotError(const RooRealVar& param, const RooCmdArg& arg1, const RooCmdArg& arg2,
1175 const RooCmdArg& arg3, const RooCmdArg& arg4,
1176 const RooCmdArg& arg5, const RooCmdArg& arg6,
1177 const RooCmdArg& arg7, const RooCmdArg& arg8)
1178{
1179 if (_canAddFitResults) {
1180 calcPulls() ;
1182 }
1183
1184 RooErrorVar* evar = param.errorVar() ;
1185 RooRealVar* evar_rrv = static_cast<RooRealVar*>(evar->createFundamental()) ;
1186 RooPlot* frame = plotParam(*evar_rrv,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
1187 delete evar_rrv ;
1188 delete evar ;
1189 return frame ;
1190}
1191
1192
1193
1194////////////////////////////////////////////////////////////////////////////////
1195/// Plot the distribution of pull values for the specified parameter on a newly created frame. If asymmetric
1196/// errors are calculated in the fit (by MINOS) those will be used in the pull calculation.
1197///
1198/// If the parameters of the models for generation and fit differ, simple heuristics are used to find the
1199/// corresponding parameters:
1200/// - Parameters have the same name: They will be used to compute pulls.
1201/// - Parameters have different names: The position of the fit parameter in the set of fit parameters will be
1202/// computed. The parameter at the same position in the set of generator parameters will be used.
1203///
1204/// Further options:
1205/// <table>
1206/// <tr><th> Arguments <th> Effect
1207/// <tr><td> FrameRange(double lo, double hi) <td> Set range of frame to given specification
1208/// <tr><td> FrameBins(int bins) <td> Set default number of bins of frame to given number
1209/// <tr><td> Frame() <td> Pass supplied named arguments to RooAbsRealLValue::frame() function. See there
1210/// for list of allowed arguments
1211/// <tr><td> FitGauss(Bool_t flag) <td> Add a gaussian fit to the frame
1212/// </table>
1213///
1214/// If no frame specifications are given, the AutoSymRange() feature will be used to set a default range.
1215/// Any other named argument is passed to the RooAbsData::plotOn(). See that function for allowed options.
1216
1217RooPlot* RooMCStudy::plotPull(const RooRealVar& param, const RooCmdArg& arg1, const RooCmdArg& arg2,
1218 const RooCmdArg& arg3, const RooCmdArg& arg4,
1219 const RooCmdArg& arg5, const RooCmdArg& arg6,
1220 const RooCmdArg& arg7, const RooCmdArg& arg8)
1221{
1222 // Stuff all arguments in a list
1223 RooLinkedList cmdList;
1224 cmdList.Add(const_cast<RooCmdArg*>(&arg1)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg2)) ;
1225 cmdList.Add(const_cast<RooCmdArg*>(&arg3)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg4)) ;
1226 cmdList.Add(const_cast<RooCmdArg*>(&arg5)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg6)) ;
1227 cmdList.Add(const_cast<RooCmdArg*>(&arg7)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg8)) ;
1228
1229 TString name(param.GetName()), title(param.GetTitle()) ;
1230 name.Append("pull") ; title.Append(" Pull") ;
1231 RooRealVar pvar(name,title,-100,100) ;
1232 pvar.setBins(100) ;
1233
1234
1235 RooPlot* frame = makeFrameAndPlotCmd(pvar, cmdList, kTRUE) ;
1236 if (frame) {
1237
1238 // Pick up optonal FitGauss command from list
1239 RooCmdConfig pc(Form("RooMCStudy::plotPull(%s)",_genModel->GetName())) ;
1240 pc.defineInt("fitGauss","FitGauss",0,0) ;
1241 pc.allowUndefined() ;
1242 pc.process(cmdList) ;
1243 Bool_t fitGauss=pc.getInt("fitGauss") ;
1244
1245 // Pass stripped command list to plotOn()
1246 pc.stripCmdList(cmdList,"FitGauss") ;
1247 const bool success = _fitParData->plotOn(frame,cmdList) ;
1248
1249 if (!success) {
1250 coutF(Plotting) << "No pull distribution for the parameter '" << param.GetName() << "'. Check logs for errors." << std::endl;
1251 return frame;
1252 }
1253
1254 // Add Gaussian fit if requested
1255 if (fitGauss) {
1256 RooRealVar pullMean("pullMean","Mean of pull",0,-10,10) ;
1257 RooRealVar pullSigma("pullSigma","Width of pull",1,0.1,5) ;
1258 RooGenericPdf pullGauss("pullGauss","Gaussian of pull",
1259 "exp(-0.5*(@0-@1)*(@0-@1)/(@2*@2))",
1260 RooArgSet(pvar,pullMean,pullSigma)) ;
1262 pullGauss.plotOn(frame) ;
1263 pullGauss.paramOn(frame,_fitParData) ;
1264 }
1265 }
1266 return frame;
1267}
1268
1269
1270
1271////////////////////////////////////////////////////////////////////////////////
1272/// Internal function. Construct RooPlot from given parameter and modify the list of named
1273/// arguments 'cmdList' to only contain the plot arguments that should be forwarded to
1274/// RooAbsData::plotOn()
1275
1277{
1278 // Select the frame-specific commands
1279 RooCmdConfig pc(Form("RooMCStudy::plotParam(%s)",_genModel->GetName())) ;
1280 pc.defineInt("nbins","Bins",0,0) ;
1281 pc.defineDouble("xlo","Range",0,0) ;
1282 pc.defineDouble("xhi","Range",1,0) ;
1283 pc.defineInt("dummy","FrameArgs",0,0) ;
1284 pc.defineMutex("Bins","FrameArgs") ;
1285 pc.defineMutex("Range","FrameArgs") ;
1286
1287 // Process and check varargs
1288 pc.allowUndefined() ;
1289 pc.process(cmdList) ;
1290 if (!pc.ok(kTRUE)) {
1291 return 0 ;
1292 }
1293
1294 // Make frame according to specs
1295 Int_t nbins = pc.getInt("nbins") ;
1296 Double_t xlo = pc.getDouble("xlo") ;
1297 Double_t xhi = pc.getDouble("xhi") ;
1298 RooPlot* frame ;
1299
1300 if (pc.hasProcessed("FrameArgs")) {
1301 // Explicit frame arguments are given, pass them on
1302 RooCmdArg* frameArg = static_cast<RooCmdArg*>(cmdList.FindObject("FrameArgs")) ;
1303 frame = param.frame(frameArg->subArgs()) ;
1304 } else {
1305 // FrameBins, FrameRange or none are given, build custom frame command list
1306 RooCmdArg bins = RooFit::Bins(nbins) ;
1307 RooCmdArg range = RooFit::Range(xlo,xhi) ;
1309 RooLinkedList frameCmdList ;
1310
1311 if (pc.hasProcessed("Bins")) frameCmdList.Add(&bins) ;
1312 if (pc.hasProcessed("Range")) {
1313 frameCmdList.Add(&range) ;
1314 } else {
1315 frameCmdList.Add(&autor) ;
1316 }
1317 frame = param.frame(frameCmdList) ;
1318 }
1319
1320 // Filter frame command from list and pass on to plotOn()
1321 pc.stripCmdList(cmdList,"FrameArgs,Bins,Range") ;
1322
1323 return frame ;
1324}
1325
1326
1327
1328////////////////////////////////////////////////////////////////////////////////
1329/// Create a RooPlot of the -log(L) distribution in the range lo-hi
1330/// with 'nBins' bins
1331
1333{
1334 RooPlot* frame = _nllVar->frame(lo,hi,nBins) ;
1335
1336 _fitParData->plotOn(frame) ;
1337 return frame ;
1338}
1339
1340
1341
1342////////////////////////////////////////////////////////////////////////////////
1343/// Create a RooPlot of the distribution of the fitted errors of the given parameter.
1344/// The frame is created with a range [lo,hi] and plotted data will be binned in 'nbins' bins
1345
1347{
1348 if (_canAddFitResults) {
1349 calcPulls() ;
1351 }
1352
1353 RooErrorVar* evar = param.errorVar() ;
1354 RooPlot* frame = evar->frame(lo,hi,nbins) ;
1355 _fitParData->plotOn(frame) ;
1356
1357 delete evar ;
1358 return frame ;
1359}
1360
1361
1362
1363////////////////////////////////////////////////////////////////////////////////
1364/// Create a RooPlot of the pull distribution for the given
1365/// parameter. The range lo-hi is plotted in nbins. If fitGauss is
1366/// set, an unbinned ML fit of the distribution to a Gaussian p.d.f
1367/// is performed. The fit result is overlaid on the returned RooPlot
1368/// and a box with the fitted mean and sigma is added.
1369///
1370/// If the parameters of the models for generation and fit differ, simple heuristics are used to find the
1371/// corresponding parameters:
1372/// - Parameters have the same name: They will be used to compute pulls.
1373/// - Parameters have different names: The position of the fit parameter in the set of fit parameters will be
1374/// computed. The parameter at the same position in the set of generator parameters will be used.
1375
1377{
1378 if (_canAddFitResults) {
1379 calcPulls() ;
1381 }
1382
1383
1384 TString name(param.GetName()), title(param.GetTitle()) ;
1385 name.Append("pull") ; title.Append(" Pull") ;
1386 RooRealVar pvar(name,title,lo,hi) ;
1387 pvar.setBins(nbins) ;
1388
1389 RooPlot* frame = pvar.frame() ;
1390 const bool success = _fitParData->plotOn(frame);
1391
1392 if (!success) {
1393 coutF(Plotting) << "No pull distribution for the parameter '" << param.GetName() << "'. Check logs for errors." << std::endl;
1394 return frame;
1395 }
1396
1397 if (fitGauss) {
1398 RooRealVar pullMean("pullMean","Mean of pull",0,lo,hi) ;
1399 RooRealVar pullSigma("pullSigma","Width of pull",1,0,5) ;
1400 RooGenericPdf pullGauss("pullGauss","Gaussian of pull",
1401 "exp(-0.5*(@0-@1)*(@0-@1)/(@2*@2))",
1402 RooArgSet(pvar,pullMean,pullSigma)) ;
1404 pullGauss.plotOn(frame) ;
1405 pullGauss.paramOn(frame,_fitParData) ;
1406 }
1407
1408 return frame ;
1409}
1410
1411
1412////////////////////////////////////////////////////////////////////////////////
1413/// If one of the TObject we have a referenced to is deleted, remove the
1414/// reference.
1415
1417{
1421 if (_ngenVar == obj) _ngenVar = nullptr;
1422
1424 if (_fitParData == obj) _fitParData = nullptr;
1425
1427 if (_genParData == obj) _genParData = nullptr;
1428}
1429
#define coutI(a)
#define coutP(a)
#define oocoutW(o, a)
#define coutW(a)
#define coutF(a)
#define oocoutE(o, a)
#define oocoutI(o, a)
#define coutE(a)
#define ooccoutI(o, a)
#define ooccoutP(o, a)
#define oocoutP(o, a)
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
#define hi
char * Form(const char *fmt,...)
#define snprintf
Definition civetweb.c:1540
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:69
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Given a set of possible observables, return the observables that this PDF depends on.
Definition RooAbsArg.h:309
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Int_t getSize() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
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...
Storage_t::size_type size() const
const_iterator begin() const
void setAttribAll(const Text_t *name, Bool_t value=kTRUE)
Set given attribute in each element of the collection by calling each elements setAttribute() functio...
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:82
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
virtual Bool_t changeObservableName(const char *from, const char *to)
virtual void reset()
virtual Double_t sumEntries() const =0
Return effective number of entries in dataset, i.e., sum all weights.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
virtual RooPlot * plotOn(RooPlot *frame, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
virtual void attach(const RooArgSet &params)
Interface to attach given parameters to object in this context.
virtual RooDataSet * generate(Double_t nEvents=0, Bool_t skipInit=kFALSE, Bool_t extendedMode=kFALSE)
Generate the specified number of events with nEvents>0 and and return a dataset containing the genera...
virtual void setProtoDataOrder(Int_t *lut)
Set the traversal order of prototype data to that in the lookup tables passed as argument.
RooAbsMCStudyModule is a base class for add-on modules to RooMCStudy that can perform additional calc...
Bool_t doInitializeInstance(RooMCStudy &)
Store reference to RooMCStudy object that this module relates to and call internal module initializat...
virtual RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, Bool_t verbose=kFALSE) const
Interface function to create a generator context from a p.d.f.
virtual RooDataHist * generateBinned(const RooArgSet &whatVars, Double_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()) const
As RooAbsPdf::generateBinned(const RooArgSet&, const RooCmdArg&,const RooCmdArg&, const RooCmdArg&,...
Definition RooAbsPdf.h:107
virtual RooFitResult * fitTo(RooAbsData &data, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Fit PDF to given dataset.
virtual RooPlot * paramOn(RooPlot *frame, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Add a box with parameter values (and errors) to the specified frame.
virtual RooArgSet * getAllConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, Bool_t stripDisconnected=kTRUE) const
This helper function finds and collects all constraints terms of all component p.d....
virtual RooPlot * plotOn(RooPlot *frame, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none(), const RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
Definition RooAbsPdf.h:121
Int_t * randomizeProtoOrder(Int_t nProto, Int_t nGen, Bool_t resample=kFALSE) const
Return lookup table with randomized order for nProto prototype events.
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
RooPlot * frame(const RooCmdArg &arg1, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create a new RooPlot on the heap with a drawing frame initialized for this object,...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
RooAbsArg * createFundamental(const char *newname=0) const
Create a RooRealVar fundamental object with our properties.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:158
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition RooCmdArg.h:27
RooLinkedList & subArgs()
Definition RooCmdArg.h:46
virtual TObject * Clone(const char *newName=0) const
Make a clone of an object using the Streamer facility.
Definition RooCmdArg.h:51
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
TObject * getObject(const char *name, TObject *obj=0)
Return TObject property registered with name 'name'.
Bool_t defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
void defineMutex(const char *argName1, const char *argName2)
Define arguments named argName1 and argName2 mutually exclusive.
Bool_t defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=0, Bool_t isArray=kFALSE)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
const char * getString(const char *name, const char *defaultValue="", Bool_t convEmptyToNull=kFALSE)
Return string property registered with name 'name'.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
Bool_t defineDouble(const char *name, const char *argName, Int_t doubleNum, Double_t defValue=0.)
Define Double_t property name 'name' mapped to Double_t in slot 'doubleNum' in RooCmdArg with name ar...
Double_t getDouble(const char *name, Double_t defaultValue=0)
Return Double_t property registered with name 'name'.
void allowUndefined(Bool_t flag=kTRUE)
void stripCmdList(RooLinkedList &cmdList, const char *cmdsToPurge)
Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList.
Bool_t defineSet(const char *name, const char *argName, Int_t setNum, const RooArgSet *set=0)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
Bool_t defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", Bool_t appendMode=kFALSE)
Define Double_t property name 'name' mapped to Double_t in slot 'stringNum' in RooCmdArg with name ar...
RooArgSet * getSet(const char *name, RooArgSet *set=0)
Return RooArgSet property registered with name 'name'.
Bool_t ok(Bool_t verbose) const
Return true of parsing was successful.
Bool_t process(const RooCmdArg &arg)
Process given RooCmdArg.
Bool_t hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
The RooDataHist is a container class to hold N-dimensional binned data.
Definition RooDataHist.h:45
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:36
virtual const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a column with the values of the given (function) argument to this dataset.
Bool_t write(const char *filename) const
Write the contents of this dataset to an ASCII file with the specified name.
static RooDataSet * read(const char *filename, const RooArgList &variables, const char *opts="", const char *commonPath="", const char *indexCatName=0)
Read given list of ascii files, and construct a data set, using the given ArgList as structure defini...
Bool_t merge(RooDataSet *data1, RooDataSet *data2=0, RooDataSet *data3=0, RooDataSet *data4=0, RooDataSet *data5=0, RooDataSet *data6=0)
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
RooErrorVar is an auxilary class that represents the error of a RooRealVar as a seperate object.
Definition RooErrorVar.h:28
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Double_t minNll() const
Return minimized -log(L) value.
const RooArgList & floatParsFinal() const
Return list of floarting parameters after fit.
Int_t status() const
Return MINUIT status code.
RooGenericPdf is a concrete implementation of a probability density function, which takes a RooArgLis...
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Int_t GetSize() const
TObject * At(int index) const
Return object stored in sequential position given by index.
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
virtual void Add(TObject *arg)
RooMCStudy is a helper class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies,...
Definition RooMCStudy.h:32
RooAbsData * _genSample
Definition RooMCStudy.h:113
RooArgSet _projDeps
Definition RooMCStudy.h:119
RooPlot * plotNLL(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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Plot the distribution of the -log(L) values on a newly created frame.
const RooArgSet * fitParams(Int_t sampleNum) const
Return an argset with the fit parameters for the given sample number.
void calcPulls()
Calculate the pulls for all fit parameters in the fit results data set, and add them to that dataset.
Bool_t addFitResult(const RooFitResult &fr)
Utility function to add fit result from external fit to this RooMCStudy and process its results throu...
Bool_t run(Bool_t generate, Bool_t fit, Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char *asciiFilePat)
Run engine method.
Bool_t _extendedGen
Definition RooMCStudy.h:138
Bool_t _silence
Definition RooMCStudy.h:146
RooArgSet _dependents
Definition RooMCStudy.h:124
RooMCStudy(const RooAbsPdf &model, const RooArgSet &observables, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Construct Monte Carlo Study Manager.
std::list< RooAbsMCStudyModule * > _modList
Definition RooMCStudy.h:148
RooAbsGenContext * _constrGenContext
Definition RooMCStudy.h:122
RooFitResult * refit(RooAbsData *genSample=0)
Redo fit on 'current' toy sample, or if genSample is not NULL do fit on given sample instead.
TList _fitResList
Definition RooMCStudy.h:133
RooDataSet * _genParData
Definition RooMCStudy.h:134
Bool_t fitSample(RooAbsData *genSample)
Internal method.
const RooDataSet * _genProtoData
Definition RooMCStudy.h:118
const RooFitResult * fitResult(Int_t sampleNum) const
Return the RooFitResult of the fit with the given run number.
Bool_t _perExptGenParams
Definition RooMCStudy.h:145
RooPlot * plotError(const RooRealVar &param, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Plot the distribution of the fit errors for the specified parameter on a newly created frame.
RooAbsGenContext * _genContext
Definition RooMCStudy.h:115
Bool_t _randProto
Definition RooMCStudy.h:141
RooAbsPdf * _constrPdf
Definition RooMCStudy.h:121
RooArgSet * _fitInitParams
Definition RooMCStudy.h:127
Bool_t _canAddFitResults
Definition RooMCStudy.h:143
RooPlot * makeFrameAndPlotCmd(const RooRealVar &param, RooLinkedList &cmdList, Bool_t symRange=kFALSE) const
Internal function.
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
RooAbsData * genData(Int_t sampleNum) const
Return the given generated dataset.
RooArgSet * _genInitParams
Definition RooMCStudy.h:116
Bool_t _binGenData
Definition RooMCStudy.h:139
RooAbsPdf * _genModel
Definition RooMCStudy.h:114
Double_t _nExpGen
Definition RooMCStudy.h:140
const RooDataSet & fitParDataSet()
Return a RooDataSet containing the post-fit parameters of each toy cycle.
RooPlot * plotParamOn(RooPlot *frame, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Plot the distribution of fitted values of a parameter.
RooLinkedList _fitOptList
Definition RooMCStudy.h:137
Bool_t generate(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char *asciiFilePat=0)
Generate 'nSamples' samples of 'nEvtPerSample' events.
RooArgSet _allDependents
Definition RooMCStudy.h:125
virtual ~RooMCStudy()
RooArgSet * _fitParams
Definition RooMCStudy.h:128
void resetFitParams()
Reset all fit parameters to the initial model parameters at the time of the RooMCStudy constructor.
RooArgSet * _genParams
Definition RooMCStudy.h:117
Bool_t _verboseGen
Definition RooMCStudy.h:144
RooAbsPdf * _fitModel
Definition RooMCStudy.h:126
Bool_t generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char *asciiFilePat=0)
Generate and fit 'nSamples' samples of 'nEvtPerSample' events.
Bool_t fit(Int_t nSamples, const char *asciiFilePat)
Fit 'nSamples' datasets, which are read from ASCII files.
RooRealVar * _ngenVar
Definition RooMCStudy.h:130
TList _genDataList
Definition RooMCStudy.h:132
RooPlot * plotParam(const RooRealVar &param, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Plot the distribution of the fitted value of the given parameter on a newly created frame.
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
RooFitResult * doFit(RooAbsData *genSample)
Internal function. Performs actual fit according to specifications.
RooRealVar * _nllVar
Definition RooMCStudy.h:129
RooPlot * plotPull(const RooRealVar &param, const RooCmdArg &arg1, 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(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Plot the distribution of pull values for the specified parameter on a newly created frame.
TString _fitOptions
Definition RooMCStudy.h:136
RooDataSet * _fitParData
Definition RooMCStudy.h:135
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:44
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition RooProdPdf.h:33
RooPullVar represents the pull of a measurement w.r.t.
Definition RooPullVar.h:24
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition RooRandom.cxx:53
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Iterator abstract base class.
Definition TIterator.h:30
virtual TObject * Next()=0
A doubly linked list.
Definition TList.h:38
virtual void Add(TObject *obj)
Definition TList.h:81
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:357
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition TList.cxx:764
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition TList.cxx:722
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
virtual Int_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
Definition TRandom.cxx:402
Basic string class.
Definition TString.h:136
void ToLower()
Change string to lower-case.
Definition TString.cxx:1150
const char * Data() const
Definition TString.h:369
TString & Append(const char *cs)
Definition TString.h:564
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
RooCmdArg AutoSymRange(const RooAbsData &data, Double_t marginFactor=0.1)
RooCmdArg AutoRange(const RooAbsData &data, Double_t marginFactor=0.1)
RooCmdArg Bins(Int_t nbin)
RooCmdArg Constrain(const RooArgSet &params)
RooCmdArg ExternalConstraints(const RooArgSet &constraintPdfs)
RooCmdArg Save(Bool_t flag=kTRUE)
RooCmdArg PrintLevel(Int_t code)
RooCmdArg ConditionalObservables(Args_t &&... argsOrArgSet)
Create a RooCmdArg to declare conditional observables.
RooCmdArg Minos(Bool_t flag=kTRUE)
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
RooCmdArg FitOptions(const char *opts)
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.