Logo ROOT   6.12/07
Reference Guide
RooMCStudy.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooMCStudy.h,v 1.18 2007/05/11 10:14:56 verkerke Exp $
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 #ifndef ROO_MC_STUDY
17 #define ROO_MC_STUDY
18 
19 #include "TList.h"
20 #include "TNamed.h"
21 #include "RooArgSet.h"
22 #include <list>
23 class RooAbsPdf;
24 class RooDataSet ;
25 class RooAbsData ;
26 class RooAbsGenContext ;
27 class RooFitResult ;
28 class RooPlot ;
29 class RooRealVar ;
30 class RooAbsMCStudyModule ;
31 
32 class RooMCStudy : public TNamed {
33 public:
34 
35  RooMCStudy(const RooAbsPdf& model, const RooArgSet& observables,
36  const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
37  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(), const RooCmdArg& arg5=RooCmdArg::none(),
38  const RooCmdArg& arg6=RooCmdArg::none(), const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
39 
40  RooMCStudy(const RooAbsPdf& genModel, const RooAbsPdf& fitModel,
41  const RooArgSet& dependents, const char* genOptions="",
42  const char* fitOptions="", const RooDataSet* genProtoData=0,
43  const RooArgSet& projDeps=RooArgSet()) ;
44  virtual ~RooMCStudy() ;
45 
46  // Method to add study modules
47  void addModule(RooAbsMCStudyModule& module) ;
48 
49 
50  // Run methods
51  Bool_t generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char* asciiFilePat=0) ;
52  Bool_t generate(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char* asciiFilePat=0) ;
53  Bool_t fit(Int_t nSamples, const char* asciiFilePat) ;
54  Bool_t fit(Int_t nSamples, TList& dataSetList) ;
55  Bool_t addFitResult(const RooFitResult& fr) ;
56 
57  // Result accessors
58  const RooArgSet* fitParams(Int_t sampleNum) const ;
59  const RooFitResult* fitResult(Int_t sampleNum) const ;
60  const RooAbsData* genData(Int_t sampleNum) const ;
61  const RooDataSet& fitParDataSet() ;
62  const RooDataSet* genParDataSet() const {
63  // Return dataset with generator parameters for each toy. When constraints are used these
64  // may generally not be the same
65  return _genParData ;
66  }
67 
68  // Plot methods
69  RooPlot* plotParamOn(RooPlot* frame, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
70  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
71  const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
72  const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
73  RooPlot* plotParam(const RooRealVar& param, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
74  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
75  const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
76  const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
77  RooPlot* plotParam(const char* paramName, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
78  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
79  const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
80  const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
81  RooPlot* plotNLL(const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
82  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
83  const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
84  const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
85  RooPlot* plotError(const RooRealVar& param, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
86  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
87  const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
88  const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
89  RooPlot* plotPull(const RooRealVar& param, const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg::none(),
90  const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
91  const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
92  const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
93 
94 
95  RooPlot* plotNLL(Double_t lo, Double_t hi, Int_t nBins=100) ;
96  RooPlot* plotError(const RooRealVar& param, Double_t lo, Double_t hi, Int_t nbins=100) ;
97  RooPlot* plotPull(const RooRealVar& param, Double_t lo=-3.0, Double_t hi=3.0, Int_t nbins=25, Bool_t fitGauss=kFALSE) ;
98 
99 protected:
100 
101  friend class RooAbsMCStudyModule ;
102 
103  RooPlot* makeFrameAndPlotCmd(const RooRealVar& param, RooLinkedList& cmdList, Bool_t symRange=kFALSE) const ;
104 
105  Bool_t run(Bool_t generate, Bool_t fit, Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char* asciiFilePat) ;
108 
109  void calcPulls() ;
110 
111  RooAbsData* _genSample ; // Currently generated sample
112  RooAbsPdf* _genModel ; // Generator model
113  RooAbsGenContext* _genContext ; // Generator context
114  RooArgSet* _genInitParams ; // List of originalgenerator parameters
115  RooArgSet* _genParams ; // List of actual generator parameters
116  const RooDataSet* _genProtoData ; // Generator prototype data set
117  RooArgSet _projDeps ; // List of projected dependents in fit
118 
119  RooAbsPdf* _constrPdf ; // Constraints p.d.f
120  RooAbsGenContext* _constrGenContext ; // Generator context for constraints p.d.f
121 
122  RooArgSet _dependents ; // List of dependents
123  RooArgSet _allDependents ; // List of generate + prototype dependents
124  RooAbsPdf* _fitModel ; // Fit model
125  RooArgSet* _fitInitParams ; // List of initial values of fit parameters
126  RooArgSet* _fitParams ; // List of actual fit parameters
129 
130  TList _genDataList ; // List of generated data sample
131  TList _fitResList ; // List of RooFitResult fit output objects
132  RooDataSet* _genParData ; // List of of generated parameters of each sample
133  RooDataSet* _fitParData ; // Data set of fit parameters of each sample
134  TString _fitOptions ; // Fit options string
135  RooLinkedList _fitOptList ; // Fit option command list
136  Bool_t _extendedGen ; // Add poisson term to number of events to generate?
137  Bool_t _binGenData ; // Bin data between generating and fitting
138  Double_t _nExpGen ; // Number of expected events to generate in extended mode
139  Bool_t _randProto ; // Randomize order of prototype data access
140 
141  Bool_t _canAddFitResults ; // Allow adding of external fit results?
142  Bool_t _verboseGen ; // Verbose generation?
143  Bool_t _perExptGenParams ; // Do generation parameter change per event?
144  Bool_t _silence ; // Silent running mode?
145 
146  std::list<RooAbsMCStudyModule*> _modList ; // List of additional study modules ;
147 
148  // Utilities for modules ;
150  void resetFitParams() ;
151  virtual void RecursiveRemove(TObject *obj);
152 
153 private:
154 
155  RooMCStudy(const RooMCStudy&) ;
156 
157  ClassDef(RooMCStudy,0) // A general purpose toy Monte Carlo study manager
158 } ;
159 
160 
161 #endif
162 
Bool_t fitSample(RooAbsData *genSample)
Internal method.
Definition: RooMCStudy.cxx:819
Bool_t _silence
Definition: RooMCStudy.h:144
RooFitResult * refit(RooAbsData *genSample=0)
Redo fit on &#39;current&#39; 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 &#39;nSamples&#39; datasets, which are read from ASCII files.
Definition: RooMCStudy.cxx:692
RooMCStudy is a help class to facilitate Monte Carlo studies such as &#39;goodness-of-fit&#39; 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.
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
RooAbsData * genSample()
RooAbsMCStudyModule is a base class for add-on modules to RooMCStudy that can perform additional calc...
RooAbsGenContext * _constrGenContext
Definition: RooMCStudy.h:120
Bool_t _verboseGen
Definition: RooMCStudy.h:142
const RooDataSet & fitParDataSet()
Return a RooDataSet the resulting fit parameters of each toy cycle.
Definition: RooMCStudy.cxx:956
const RooAbsData * genData(Int_t sampleNum) const
Return the given generated dataset.
Basic string class.
Definition: TString.h:125
TList _fitResList
Definition: RooMCStudy.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
RooDataSet * _genParData
Definition: RooMCStudy.h:132
std::list< RooAbsMCStudyModule * > _modList
Definition: RooMCStudy.h:146
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
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:50
#define ClassDef(name, id)
Definition: Rtypes.h:320
Bool_t generate(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char *asciiFilePat=0)
Generate &#39;nSamples&#39; samples of &#39;nEvtPerSample&#39; events.
Definition: RooMCStudy.cxx:675
RooPlot * makeFrameAndPlotCmd(const RooRealVar &param, RooLinkedList &cmdList, Bool_t symRange=kFALSE) const
Internal function.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
RooArgSet * _genParams
Definition: RooMCStudy.h:115
RooAbsPdf * _genModel
Definition: RooMCStudy.h:112
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 &#39;nSamples&#39; samples of &#39;nEvtPerSample&#39; events.
Definition: RooMCStudy.cxx:653
const RooDataSet * _genProtoData
Definition: RooMCStudy.h:116
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
A doubly linked list.
Definition: TList.h:44
RooAbsPdf * _fitModel
Definition: RooMCStudy.h:124
TList _genDataList
Definition: RooMCStudy.h:130
const RooFitResult * fitResult(Int_t sampleNum) const
Return the RooFitResult object of the fit to given sample.
Definition: RooMCStudy.cxx:992
RooRealVar * _ngenVar
Definition: RooMCStudy.h:128
const RooDataSet * genParDataSet() const
Definition: RooMCStudy.h:62
TString _fitOptions
Definition: RooMCStudy.h:134
RooAbsData * _genSample
Definition: RooMCStudy.h:111
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
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
const RooArgSet * fitParams(Int_t sampleNum) const
Return an argset with the fit parameters for the given sample number.
Definition: RooMCStudy.cxx:976
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.
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
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 RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
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
virtual ~RooMCStudy()
Destructor.
Definition: RooMCStudy.cxx:415
RooFitResult * doFit(RooAbsData *genSample)
Internal function. Performs actual fit according to specifications.
Definition: RooMCStudy.cxx:741
Double_t _nExpGen
Definition: RooMCStudy.h:138
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t _canAddFitResults
Definition: RooMCStudy.h:141
Bool_t _extendedGen
Definition: RooMCStudy.h:136
RooAbsGenContext * _genContext
Definition: RooMCStudy.h:113
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 _randProto
Definition: RooMCStudy.h:139
RooArgSet _allDependents
Definition: RooMCStudy.h:123
float type_of_call hi(const int &, const int &)
Bool_t _perExptGenParams
Definition: RooMCStudy.h:143
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