Logo ROOT  
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>
23class RooAbsPdf;
24class RooDataSet ;
25class RooAbsData ;
26class RooAbsGenContext ;
27class RooFitResult ;
28class RooPlot ;
29class RooRealVar ;
31
32class RooMCStudy : public TNamed {
33public:
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() override ;
41
42 // Method to add study modules
43 void addModule(RooAbsMCStudyModule& module) ;
44
45
46 // Run methods
47 bool generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char* asciiFilePat=0) ;
48 bool generate(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char* asciiFilePat=0) ;
49 bool fit(Int_t nSamples, const char* asciiFilePat) ;
50 bool fit(Int_t nSamples, TList& dataSetList) ;
51 bool addFitResult(const RooFitResult& fr) ;
52
53 // Result accessors
54 const RooArgSet* fitParams(Int_t sampleNum) const ;
55 const RooFitResult* fitResult(Int_t sampleNum) const ;
56 RooAbsData* genData(Int_t sampleNum) const ;
57 const RooDataSet& fitParDataSet() ;
58 /// Return dataset with generator parameters for each toy. When constraints are used these
59 /// may generally not be the same as the fitted parameters.
60 const RooDataSet* genParDataSet() const {
61 return _genParData ;
62 }
63
64 // Plot methods
65 RooPlot* plotParamOn(RooPlot* frame, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
66 const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
67 const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
68 const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
69 RooPlot* plotParam(const RooRealVar& param, 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 char* paramName, 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()) ;
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* plotError(const RooRealVar& param, 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* plotPull(const RooRealVar& param, const RooCmdArg& arg1, 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
90
91 RooPlot* plotNLL(double lo, double hi, Int_t nBins=100) ;
92 RooPlot* plotError(const RooRealVar& param, double lo, double hi, Int_t nbins=100) ;
93 RooPlot* plotPull(const RooRealVar& param, double lo=-3.0, double hi=3.0, Int_t nbins=25, bool fitGauss=false) ;
94
95protected:
96
97 friend class RooAbsMCStudyModule ;
98
99 RooPlot* makeFrameAndPlotCmd(const RooRealVar& param, RooLinkedList& cmdList, bool symRange=false) const ;
100
101 bool run(bool generate, bool fit, Int_t nSamples, Int_t nEvtPerSample, bool keepGenData, const char* asciiFilePat) ;
104
105 void calcPulls() ;
106
107 RooAbsData* _genSample ; ///< Currently generated sample
108 RooAbsPdf* _genModel ; ///< Generator model
109 RooAbsGenContext* _genContext ; ///< Generator context
110 RooArgSet* _genInitParams ; ///< List of original generator parameters
111 RooArgSet* _genParams ; ///< List of actual generator parameters
112 const RooDataSet* _genProtoData ; ///< Generator prototype data set
113 RooArgSet _projDeps ; ///< List of projected dependents in fit
114
115 RooAbsPdf* _constrPdf ; ///< Constraints p.d.f
116 RooAbsGenContext* _constrGenContext ; ///< Generator context for constraints p.d.f
117
118 RooArgSet _dependents ; ///< List of dependents
119 RooArgSet _allDependents ; ///< List of generate + prototype dependents
120 RooAbsPdf* _fitModel ; ///< Fit model
121 RooArgSet* _fitInitParams ; ///< List of initial values of fit parameters
122 RooArgSet* _fitParams ; ///< List of actual fit parameters
125
126 TList _genDataList ; // List of generated data sample
127 TList _fitResList ; // List of RooFitResult fit output objects
128 RooDataSet* _genParData ; // List of of generated parameters of each sample
129 RooDataSet* _fitParData ; // Data set of fit parameters of each sample
130 RooLinkedList _fitOptList ; // Fit option command list
131 bool _extendedGen ; // Add poisson term to number of events to generate?
132 bool _binGenData ; // Bin data between generating and fitting
133 double _nExpGen ; // Number of expected events to generate in extended mode
134 bool _randProto ; // Randomize order of prototype data access
135
136 bool _canAddFitResults ; ///< Allow adding of external fit results?
137 bool _verboseGen ; ///< Verbose generation?
138 bool _perExptGenParams ; ///< Do generation parameter change per event?
139 bool _silence ; ///< Silent running mode?
140
141 std::list<RooAbsMCStudyModule*> _modList ; ///< List of additional study modules ;
142
143 // Utilities for modules ;
145 void resetFitParams() ;
146 void RecursiveRemove(TObject *obj) override;
147
148private:
149
151
152 ClassDefOverride(RooMCStudy,0) // A general purpose toy Monte Carlo study manager
153} ;
154
155
156#endif
157
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
#define hi
Definition: THbookFile.cxx:128
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:62
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
RooAbsMCStudyModule is a base class for add-on modules to RooMCStudy that can perform additional calc...
RooAbsData * genSample()
Return generate sample.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:51
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:38
RooMCStudy is a helper class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies,...
Definition: RooMCStudy.h:32
bool addFitResult(const RooFitResult &fr)
Utility function to add fit result from external fit to this RooMCStudy and process its results throu...
Definition: RooMCStudy.cxx:743
RooAbsData * _genSample
Currently generated sample.
Definition: RooMCStudy.h:107
RooPlot * makeFrameAndPlotCmd(const RooRealVar &param, RooLinkedList &cmdList, bool symRange=false) const
Internal function.
RooArgSet _projDeps
List of projected dependents in fit.
Definition: RooMCStudy.h:113
RooPlot * plotNLL(const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Plot the distribution of the -log(L) values on a newly created frame.
const RooArgSet * fitParams(Int_t sampleNum) const
Return an argset with the fit parameters for the given sample number.
Definition: RooMCStudy.cxx:864
bool generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char *asciiFilePat=0)
Generate and fit 'nSamples' samples of 'nEvtPerSample' events.
Definition: RooMCStudy.cxx:541
void calcPulls()
Calculate the pulls for all fit parameters in the fit results data set, and add them to that dataset.
Definition: RooMCStudy.cxx:777
~RooMCStudy() override
Definition: RooMCStudy.cxx:307
RooArgSet _dependents
List of dependents.
Definition: RooMCStudy.h:118
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:109
bool _verboseGen
Verbose generation?
Definition: RooMCStudy.h:137
std::list< RooAbsMCStudyModule * > _modList
List of additional study modules ;.
Definition: RooMCStudy.h:141
RooAbsGenContext * _constrGenContext
Generator context for constraints p.d.f.
Definition: RooMCStudy.h:116
RooFitResult * refit(RooAbsData *genSample=0)
Redo fit on 'current' toy sample, or if genSample is not nullptr do fit on given sample instead.
Definition: RooMCStudy.cxx:664
TList _fitResList
Definition: RooMCStudy.h:127
bool generate(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char *asciiFilePat=0)
Generate 'nSamples' samples of 'nEvtPerSample' events.
Definition: RooMCStudy.cxx:563
double _nExpGen
Definition: RooMCStudy.h:133
bool fitSample(RooAbsData *genSample)
Internal method.
Definition: RooMCStudy.cxx:691
RooDataSet * _genParData
Definition: RooMCStudy.h:128
bool _extendedGen
Definition: RooMCStudy.h:131
const RooDataSet * _genProtoData
Generator prototype data set.
Definition: RooMCStudy.h:112
bool _canAddFitResults
Allow adding of external fit results?
Definition: RooMCStudy.h:136
const RooFitResult * fitResult(Int_t sampleNum) const
Return the RooFitResult of the fit with the given run number.
Definition: RooMCStudy.cxx:882
bool _perExptGenParams
Do generation parameter change per event?
Definition: RooMCStudy.h:138
bool _binGenData
Definition: RooMCStudy.h:132
bool _silence
Silent running mode?
Definition: RooMCStudy.h:139
RooPlot * plotError(const RooRealVar &param, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Plot the distribution of the fit errors for the specified parameter on a newly created frame.
RooAbsGenContext * _genContext
Generator context.
Definition: RooMCStudy.h:109
RooAbsPdf * _constrPdf
Constraints p.d.f.
Definition: RooMCStudy.h:115
RooArgSet * _fitInitParams
List of initial values of fit parameters.
Definition: RooMCStudy.h:121
RooAbsData * genData(Int_t sampleNum) const
Return the given generated dataset.
Definition: RooMCStudy.cxx:907
RooArgSet * _genInitParams
List of original generator parameters.
Definition: RooMCStudy.h:110
const RooDataSet * genParDataSet() const
Return dataset with generator parameters for each toy.
Definition: RooMCStudy.h:60
void RecursiveRemove(TObject *obj) override
If one of the TObject we have a referenced to is deleted, remove the reference.
RooAbsPdf * _genModel
Generator model.
Definition: RooMCStudy.h:108
const RooDataSet & fitParDataSet()
Return a RooDataSet containing the post-fit parameters of each toy cycle.
Definition: RooMCStudy.cxx:844
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:935
RooLinkedList _fitOptList
Definition: RooMCStudy.h:130
RooArgSet _allDependents
List of generate + prototype dependents.
Definition: RooMCStudy.h:119
RooArgSet * _fitParams
List of actual fit parameters.
Definition: RooMCStudy.h:122
bool run(bool generate, bool fit, Int_t nSamples, Int_t nEvtPerSample, bool keepGenData, const char *asciiFilePat)
Run engine method.
Definition: RooMCStudy.cxx:351
void resetFitParams()
Reset all fit parameters to the initial model parameters at the time of the RooMCStudy constructor.
Definition: RooMCStudy.cxx:619
RooArgSet * _genParams
List of actual generator parameters.
Definition: RooMCStudy.h:111
RooAbsPdf * _fitModel
Fit model.
Definition: RooMCStudy.h:120
bool fit(Int_t nSamples, const char *asciiFilePat)
Fit 'nSamples' datasets, which are read from ASCII files.
Definition: RooMCStudy.cxx:580
RooRealVar * _ngenVar
Definition: RooMCStudy.h:124
TList _genDataList
Definition: RooMCStudy.h:126
bool _randProto
Definition: RooMCStudy.h:134
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:979
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
Definition: RooMCStudy.cxx:330
RooFitResult * doFit(RooAbsData *genSample)
Internal function. Performs actual fit according to specifications.
Definition: RooMCStudy.cxx:629
RooMCStudy(const RooMCStudy &)
RooRealVar * _nllVar
Definition: RooMCStudy.h:123
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.
RooDataSet * _fitParData
Definition: RooMCStudy.h:129
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:43
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
A doubly linked list.
Definition: TList.h:38
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Mother of all ROOT objects.
Definition: TObject.h:37