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