Logo ROOT  
Reference Guide
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 
22 RooMCStudy is a helper class to facilitate Monte Carlo studies
23 such as 'goodness-of-fit' studies, that involve fitting a PDF
24 to multiple toy Monte Carlo sets. These may be generated from either same PDF
25 or from a different PDF with similar parameters.
26 
27 Given a fit and a generator PDF (they might be identical), RooMCStudy can produce
28 toyMC samples and/or fit these.
29 It accumulates the post-fit parameters of each iteration in a dataset. These can be
30 retrieved using fitParams() or fitParDataSet(). This dataset additionally contains the
31 variables
32 - NLL: The value of the negative log-likelihood for each run.
33 - ngen: The number of events generated for each run.
34 
35 Additional plotting routines simplify the task of plotting
36 the distribution of the minimized likelihood, the fitted parameter values,
37 fitted error and pull distribution.
38 
39 RooMCStudy provides the option to insert add-in modules
40 that modify the generate-and-fit cycle and allow to perform
41 extra steps in the cycle. Output of these modules can be stored
42 alongside the fit results in the aggregate results dataset.
43 These study modules should derive from the class RooAbsMCStudyModule.
44 
45 Check the RooFit tutorials
46 - rf801_mcstudy.C
47 - rf802_mcstudy_addons.C
48 - rf803_mcstudy_addons2.C
49 - rf804_mcstudy_constr.C
50 for 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 
80 using namespace std ;
81 
83  ;
84 
85 
86 /**
87 Construct Monte Carlo Study Manager. This class automates generating data from a given PDF,
88 fitting 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 */
113 RooMCStudy::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 
330 RooMCStudy::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 {
424  _genDataList.Delete() ;
425  _fitOptList.Delete() ;
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 
466 Bool_t RooMCStudy::run(Bool_t doGenerate, Bool_t DoFit, Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char* asciiFilePat)
467 {
468  RooFit::MsgLevel oldLevel(RooFit::FATAL) ;
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 = *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
538  if (_randProto && _genProtoData && _genProtoData->numEntries()!=nEvt) {
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) {
549  _genSample = _genContext->generate(nEvt) ;
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 
660 Bool_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.
664  _genDataList.Delete() ;
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 
682 Bool_t RooMCStudy::generate(Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char* asciiFilePat)
683 {
684  // Clear any previous data in memory
685  _genDataList.Delete() ;
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 
699 Bool_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 
714 Bool_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.
718  _genDataList.Delete() ;
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,RooFit::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
829  resetFitParams() ;
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) ;
938  _fitParData->addColumn(pull,kFALSE) ;
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 
962  _fitParData->addColumn(pull,kFALSE) ;
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 
1001 const 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 
1072 RooPlot* 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 
1094 RooPlot* 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 
1116 RooPlot* 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 
1174 RooPlot* 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 
1217 RooPlot* 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)) ;
1261  pullGauss.fitTo(*_fitParData,RooFit::Minos(0),RooFit::PrintLevel(-1)) ;
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 
1276 RooPlot* RooMCStudy::makeFrameAndPlotCmd(const RooRealVar& param, RooLinkedList& cmdList, Bool_t symRange) const
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) ;
1308  RooCmdArg autor = symRange ? RooFit::AutoSymRange(*_fitParData,0.2) : RooFit::AutoRange(*_fitParData,0.2) ;
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)) ;
1403  pullGauss.fitTo(*_fitParData,RooFit::Minos(0),RooFit::PrintLevel(-1)) ;
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 
RooFormulaVar.h
ooccoutI
#define ooccoutI(o, a)
Definition: RooMsgService.h:53
RooLinkedList::RecursiveRemove
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
Definition: RooLinkedList.cxx:487
RooAbsRealLValue::frame
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,...
Definition: RooAbsRealLValue.cxx:199
RooCmdArg
Definition: RooCmdArg.h:27
RooAbsPdf::genContext
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.
Definition: RooAbsPdf.cxx:2005
RooMCStudy::_binGenData
Bool_t _binGenData
Definition: RooMCStudy.h:138
RooRealVar::setVal
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:226
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooCmdConfig.h
snprintf
#define snprintf
Definition: civetweb.c:1540
RooMsgService.h
RooFit::Bins
RooCmdArg Bins(Int_t nbin)
Definition: RooGlobalFunc.cxx:174
RooMCStudy::plotParam
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.
Definition: RooMCStudy.cxx:1116
RooAbsData
Definition: RooAbsData.h:46
RooMCStudy::RecursiveRemove
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
Definition: RooMCStudy.cxx:1416
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
oocoutI
#define oocoutI(o, a)
Definition: RooMsgService.h:45
RooMCStudy.h
RooFit::PrintLevel
RooCmdArg PrintLevel(Int_t code)
Definition: RooGlobalFunc.cxx:189
RooMCStudy::_fitModel
RooAbsPdf * _fitModel
Definition: RooMCStudy.h:125
RooMCStudy::fitResult
const RooFitResult * fitResult(Int_t sampleNum) const
Return the RooFitResult of the fit with the given run number.
Definition: RooMCStudy.cxx:1019
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
TString::Data
const char * Data() const
Definition: TString.h:369
coutP
#define coutP(a)
Definition: RooMsgService.h:31
RooMCStudy::fitParams
const RooArgSet * fitParams(Int_t sampleNum) const
Return an argset with the fit parameters for the given sample number.
Definition: RooMCStudy.cxx:1001
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
RooLinkedList::GetSize
Int_t GetSize() const
Definition: RooLinkedList.h:60
RooMCStudy
Definition: RooMCStudy.h:32
coutE
#define coutE(a)
Definition: RooMsgService.h:33
oocoutP
#define oocoutP(o, a)
Definition: RooMsgService.h:46
coutW
#define coutW(a)
Definition: RooMsgService.h:32
RooMCStudy::plotPull
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.
Definition: RooMCStudy.cxx:1217
RooArgList
Definition: RooArgList.h:21
ooccoutP
#define ooccoutP(o, a)
Definition: RooMsgService.h:54
RooMCStudy::genData
RooAbsData * genData(Int_t sampleNum) const
Return the given generated dataset.
Definition: RooMCStudy.cxx:1044
RooAbsData::RecursiveRemove
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
Definition: RooAbsData.cxx:2393
RooMCStudy::_allDependents
RooArgSet _allDependents
Definition: RooMCStudy.h:124
RooMCStudy::doFit
RooFitResult * doFit(RooAbsData *genSample)
Internal function. Performs actual fit according to specifications.
Definition: RooMCStudy.cxx:748
RooLinkedList::At
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
Definition: RooLinkedList.cxx:496
RooFit::Minos
RooCmdArg Minos(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:194
RooMCStudy::~RooMCStudy
virtual ~RooMCStudy()
Definition: RooMCStudy.cxx:422
RooAbsGenContext::generate
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...
Definition: RooAbsGenContext.cxx:152
Int_t
int Int_t
Definition: RtypesCore.h:45
RooMCStudy::_extendedGen
Bool_t _extendedGen
Definition: RooMCStudy.h:137
RooMCStudy::_canAddFitResults
Bool_t _canAddFitResults
Definition: RooMCStudy.h:142
RooMCStudy::_nExpGen
Double_t _nExpGen
Definition: RooMCStudy.h:139
RooMCStudy::_dependents
RooArgSet _dependents
Definition: RooMCStudy.h:123
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
RooMCStudy::resetFitParams
void resetFitParams()
Reset all fit parameters to the initial model parameters at the time of the RooMCStudy constructor.
Definition: RooMCStudy.cxx:738
TGeant4Unit::pc
static constexpr double pc
Definition: TGeant4SystemOfUnits.h:136
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
coutI
#define coutI(a)
Definition: RooMsgService.h:30
RooMCStudy::run
Bool_t run(Bool_t generate, Bool_t fit, Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char *asciiFilePat)
Run engine method.
Definition: RooMCStudy.cxx:466
RooArgSet::add
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooDataSet::merge
Bool_t merge(RooDataSet *data1, RooDataSet *data2=0, RooDataSet *data3=0, RooDataSet *data4=0, RooDataSet *data5=0, RooDataSet *data6=0)
Definition: RooDataSet.cxx:1308
RooAbsReal
Definition: RooAbsReal.h:61
RooPullVar
Definition: RooPullVar.h:24
RooErrorVar
Definition: RooErrorVar.h:28
RooMCStudy::_fitOptList
RooLinkedList _fitOptList
Definition: RooMCStudy.h:136
RooMCStudy::addFitResult
Bool_t addFitResult(const RooFitResult &fr)
Utility function to add fit result from external fit to this RooMCStudy and process its results throu...
Definition: RooMCStudy.cxx:880
oocoutE
#define oocoutE(o, a)
Definition: RooMsgService.h:48
RooMCStudy::_constrPdf
RooAbsPdf * _constrPdf
Definition: RooMCStudy.h:120
RooMCStudy::_fitParams
RooArgSet * _fitParams
Definition: RooMCStudy.h:127
TString
Definition: TString.h:136
RooLinkedList::FindObject
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
Definition: RooLinkedList.cxx:539
RooFit::MsgLevel
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Definition: RooGlobalFunc.h:65
RooGenericPdf.h
RooMCStudy::_perExptGenParams
Bool_t _perExptGenParams
Definition: RooMCStudy.h:144
RooDataSet.h
RooFit::ExternalConstraints
RooCmdArg ExternalConstraints(const RooArgSet &constraintPdfs)
Definition: RooGlobalFunc.cxx:204
RooMCStudy::plotNLL
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.
Definition: RooMCStudy.cxx:1150
RooRealVar::errorVar
RooErrorVar * errorVar() const
Return a RooAbsRealLValue representing the error associated with this variable.
Definition: RooRealVar.cxx:261
RooAbsData::sumEntries
virtual Double_t sumEntries() const =0
RooAbsPdf::plotOn
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:118
bool
TIterator
Definition: TIterator.h:30
RooFitResult
Definition: RooFitResult.h:40
RooCmdArg::subArgs
RooLinkedList & subArgs()
Definition: RooCmdArg.h:46
RooDataSet::get
virtual const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
Definition: RooDataSet.cxx:1038
RooFit::FitOptions
RooCmdArg FitOptions(const char *opts)
Definition: RooGlobalFunc.cxx:184
RooAbsGenContext::setProtoDataOrder
virtual void setProtoDataOrder(Int_t *lut)
Set the traversal order of prototype data to that in the lookup tables passed as argument.
Definition: RooAbsGenContext.cxx:348
RooCmdConfig
Definition: RooCmdConfig.h:27
RooMCStudy::RooMCStudy
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.
Definition: RooMCStudy.cxx:113
RooAbsMCStudyModule.h
RooMCStudy::_nllVar
RooRealVar * _nllVar
Definition: RooMCStudy.h:128
RooAbsArg::getParameters
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Definition: RooAbsArg.cxx:546
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:134
TList::MakeIterator
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:721
hi
float type_of_call hi(const int &, const int &)
TList::At
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:356
RooAbsMCStudyModule
Definition: RooAbsMCStudyModule.h:30
RooMCStudy::_genContext
RooAbsGenContext * _genContext
Definition: RooMCStudy.h:114
RooDataSet::add
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.
Definition: RooDataSet.cxx:1164
RooDataHist
Definition: RooDataHist.h:39
RooFit::AutoSymRange
RooCmdArg AutoSymRange(const RooAbsData &data, Double_t marginFactor=0.1)
Definition: RooGlobalFunc.cxx:175
RooMCStudy::_fitInitParams
RooArgSet * _fitInitParams
Definition: RooMCStudy.h:126
RooMCStudy::refit
RooFitResult * refit(RooAbsData *genSample=0)
Redo fit on 'current' toy sample, or if genSample is not NULL do fit on given sample instead.
Definition: RooMCStudy.cxx:799
RooMCStudy::_randProto
Bool_t _randProto
Definition: RooMCStudy.h:140
RooProdPdf.h
RooAbsPdf::paramOn
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.
Definition: RooAbsPdf.cxx:3152
RooAbsPdf.h
RooFit::FATAL
@ FATAL
Definition: RooGlobalFunc.h:65
RooFitResult::status
Int_t status() const
Definition: RooFitResult.h:77
RooPullVar.h
RooFit::Constrain
RooCmdArg Constrain(const RooArgSet &params)
Definition: RooGlobalFunc.cxx:200
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
TNamed
Definition: TNamed.h:29
RooFit::Generation
@ Generation
Definition: RooGlobalFunc.h:67
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
RooRandom.h
RooDataHist.h
RooFit::Plotting
@ Plotting
Definition: RooGlobalFunc.h:67
RooLinkedList
Definition: RooLinkedList.h:35
RooPlot.h
RooAbsCollection::createIterator
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
Definition: RooAbsCollection.h:118
RooMCStudy::_silence
Bool_t _silence
Definition: RooMCStudy.h:145
RooMsgService::setGlobalKillBelow
void setGlobalKillBelow(RooFit::MsgLevel level)
Definition: RooMsgService.h:160
RooPlot
Definition: RooPlot.h:44
RooMCStudy::fitParDataSet
const RooDataSet & fitParDataSet()
Return a RooDataSet containing the post-fit parameters of each toy cycle.
Definition: RooMCStudy.cxx:981
RooGenContext.h
RooAbsCollection::size
Storage_t::size_type size() const
Definition: RooAbsCollection.h:154
RooAbsData::numEntries
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:307
RooLinkedList::Add
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
RooMCStudy::_modList
std::list< RooAbsMCStudyModule * > _modList
Definition: RooMCStudy.h:147
RooMCStudy::_constrGenContext
RooAbsGenContext * _constrGenContext
Definition: RooMCStudy.h:121
RooMCStudy::_genParData
RooDataSet * _genParData
Definition: RooMCStudy.h:133
RooMCStudy::_genInitParams
RooArgSet * _genInitParams
Definition: RooMCStudy.h:115
oocoutW
#define oocoutW(o, a)
Definition: RooMsgService.h:47
RooRealVar.h
RooFit::ConditionalObservables
RooCmdArg ConditionalObservables(const RooArgSet &set)
Definition: RooGlobalFunc.cxx:196
RooAbsCollection::end
const_iterator end() const
Definition: RooAbsCollection.h:142
RooFit::PROGRESS
@ PROGRESS
Definition: RooGlobalFunc.h:65
RooFitResult.h
RooMCStudy::fitSample
Bool_t fitSample(RooAbsData *genSample)
Internal method.
Definition: RooMCStudy.cxx:826
TIterator::Next
virtual TObject * Next()=0
RooMCStudy::fit
Bool_t fit(Int_t nSamples, const char *asciiFilePat)
Fit 'nSamples' datasets, which are read from ASCII files.
Definition: RooMCStudy.cxx:699
RooMCStudy::_verboseGen
Bool_t _verboseGen
Definition: RooMCStudy.h:143
RooCmdArg::Clone
virtual TObject * Clone(const char *newName=0) const
Make a clone of an object using the Streamer facility.
Definition: RooCmdArg.h:51
RooMCStudy::plotParamOn
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.
Definition: RooMCStudy.cxx:1072
RooGlobalFunc.h
RooDataSet::read
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...
Definition: RooDataSet.cxx:1710
RooMCStudy::_fitParData
RooDataSet * _fitParData
Definition: RooMCStudy.h:134
RooAbsCollection::begin
const_iterator begin() const
Definition: RooAbsCollection.h:138
Double_t
double Double_t
Definition: RtypesCore.h:59
RooMCStudy::_genModel
RooAbsPdf * _genModel
Definition: RooMCStudy.h:113
RooAbsArg::getObservables
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Return the observables of this pdf given a set of observables.
Definition: RooAbsArg.h:294
RooMCStudy::_genParams
RooArgSet * _genParams
Definition: RooMCStudy.h:116
RooMCStudy::_fitResList
TList _fitResList
Definition: RooMCStudy.h:132
RooMCStudy::plotError
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.
Definition: RooMCStudy.cxx:1174
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TRandom::Poisson
virtual Int_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
Definition: TRandom.cxx:391
RooMCStudy::_projDeps
RooArgSet _projDeps
Definition: RooMCStudy.h:118
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
RooAbsData::changeObservableName
virtual Bool_t changeObservableName(const char *from, const char *to)
Definition: RooAbsData.cxx:287
TObject
Definition: TObject.h:37
coutF
#define coutF(a)
Definition: RooMsgService.h:34
RooGenericPdf
Definition: RooGenericPdf.h:25
RooAbsReal::createFundamental
RooAbsArg * createFundamental(const char *newname=0) const
Create a RooRealVar fundamental object with our properties.
Definition: RooAbsReal.cxx:3384
RooMCStudy::makeFrameAndPlotCmd
RooPlot * makeFrameAndPlotCmd(const RooRealVar &param, RooLinkedList &cmdList, Bool_t symRange=kFALSE) const
Internal function.
Definition: RooMCStudy.cxx:1276
RooFit::Range
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
Definition: RooGlobalFunc.cxx:52
name
char name[80]
Definition: TGX11.cxx:110
RooFit::AutoRange
RooCmdArg AutoRange(const RooAbsData &data, Double_t marginFactor=0.1)
Definition: RooGlobalFunc.cxx:176
RooMCStudy::generateAndFit
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.
Definition: RooMCStudy.cxx:660
RooFitResult::floatParsFinal
const RooArgList & floatParsFinal() const
Definition: RooFitResult.h:110
RooDataSet
Definition: RooDataSet.h:33
RooMCStudy::addModule
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
Definition: RooMCStudy.cxx:445
RooMCStudy::calcPulls
void calcPulls()
Calculate the pulls for all fit parameters in the fit results data set, and add them to that dataset.
Definition: RooMCStudy.cxx:914
RooAbsPdf::generateBinned
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:104
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooAbsArg
Definition: RooAbsArg.h:73
RooErrorVar.h
RooRandom::randomGenerator
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:53
RooAbsPdf
Definition: RooAbsPdf.h:40
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
launcher.module
module
Definition: launcher.py:31
RooRealVar::setBins
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
Definition: RooRealVar.cxx:383
RooMCStudy::generate
Bool_t generate(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char *asciiFilePat=0)
Generate 'nSamples' samples of 'nEvtPerSample' events.
Definition: RooMCStudy.cxx:682
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
RooRealVar
Definition: RooRealVar.h:35
RooMCStudy::_genSample
RooAbsData * _genSample
Definition: RooMCStudy.h:112
RooMCStudy::_fitOptions
TString _fitOptions
Definition: RooMCStudy.h:135
TList::RecursiveRemove
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition: TList.cxx:763
RooFit::Save
RooCmdArg Save(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:187
RooProdPdf
Definition: RooProdPdf.h:33
RooArgList.h
RooMCStudy::_genDataList
TList _genDataList
Definition: RooMCStudy.h:131
RooMsgService::instance
static RooMsgService & instance()
Return reference to singleton instance.
Definition: RooMsgService.cxx:363
RooAbsGenContext::attach
virtual void attach(const RooArgSet &params)
Interface to attach given parameters to object in this context.
Definition: RooAbsGenContext.cxx:124
RooMsgService::globalKillBelow
RooFit::MsgLevel globalKillBelow() const
Definition: RooMsgService.h:161
RooMCStudy::_genProtoData
const RooDataSet * _genProtoData
Definition: RooMCStudy.h:117
RooAbsPdf::randomizeProtoOrder
Int_t * randomizeProtoOrder(Int_t nProto, Int_t nGen, Bool_t resample=kFALSE) const
Return lookup table with randomized access order for prototype events, given nProto prototype data ev...
Definition: RooAbsPdf.cxx:2369
RooFitResult::minNll
Double_t minNll() const
Definition: RooFitResult.h:98
RooMCStudy::_ngenVar
RooRealVar * _ngenVar
Definition: RooMCStudy.h:129
RooLinkedList::Delete
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
Definition: RooLinkedList.cxx:587
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
TList
Definition: TList.h:44
RooArgSet
Definition: RooArgSet.h:28
RooDataSet::addColumn
virtual RooAbsArg * addColumn(RooAbsArg &var, Bool_t adjustRange=kTRUE)
Add a column with the values of the given (function) argument to this dataset.
Definition: RooDataSet.cxx:1383
RooAbsCollection::setAttribAll
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...
Definition: RooAbsCollection.cxx:662
int
RooAbsData::reset
virtual void reset()
Definition: RooAbsData.cxx:314
RooAbsPdf::expectedEvents
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:3309
RooAbsPdf::fitTo
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.
Definition: RooAbsPdf.cxx:1261
RooDataSet::write
Bool_t write(const char *filename) const
Write the contents of this dataset to an ASCII file with the specified name.
Definition: RooDataSet.cxx:1897