Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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={}, const RooCmdArg& arg2={},
37 const RooCmdArg& arg3={}, const RooCmdArg& arg4={}, const RooCmdArg& arg5={},
38 const RooCmdArg& arg6={}, const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
39
40 RooMCStudy(const RooMCStudy&) = delete;
41 RooMCStudy(RooMCStudy &&) = delete;
42 RooMCStudy& operator=(const RooMCStudy&) = delete;
44
45 ~RooMCStudy() override ;
46
47 // Method to add study modules
49
50
51 // Run methods
52 bool generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char* asciiFilePat=nullptr) ;
53 bool generate(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char* asciiFilePat=nullptr) ;
54 bool fit(Int_t nSamples, const char* asciiFilePat) ;
55 bool fit(Int_t nSamples, TList& dataSetList) ;
56 bool addFitResult(const RooFitResult& fr) ;
57
58 // Result accessors
59 const RooArgSet* fitParams(Int_t sampleNum) const ;
62 const RooDataSet& fitParDataSet() ;
63 /// Return dataset with the generator parameter values used for each toy, including any
64 /// modification by constraint-p.d.f. sampling or by study modules. When constraints are
65 /// used, the values are sampled from the constraint p.d.f.s for each toy and thus generally
66 /// differ from the fitted parameter values. Unlike fitParDataSet(), this dataset has one
67 /// entry per generated toy, including toys for which the fit did not converge.
68 const RooDataSet* genParDataSet() const {
69 return _genParData.get();
70 }
71
72 // Plot methods
73 RooPlot* plotParamOn(RooPlot* frame, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
74 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
75 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
76 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
77 RooPlot* plotParam(const RooRealVar& param, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
78 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
79 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
80 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
81 RooPlot* plotParam(const char* paramName, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
82 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
83 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
84 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
85 RooPlot* plotNLL(const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
86 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
87 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
88 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
89 RooPlot* plotError(const RooRealVar& param, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
90 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
91 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
92 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
93 RooPlot* plotPull(const RooRealVar& param, const RooCmdArg& arg1, const RooCmdArg& arg2={},
94 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
95 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
96 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
97
98
99 RooPlot* plotNLL(double lo, double hi, Int_t nBins=100) ;
100 RooPlot* plotError(const RooRealVar& param, double lo, double hi, Int_t nbins=100) ;
101 RooPlot* plotPull(const RooRealVar& param, double lo=-3.0, double hi=3.0, Int_t nbins=25, bool fitGauss=false) ;
102
103protected:
104
105 friend class RooAbsMCStudyModule ;
106
107 RooPlot* makeFrameAndPlotCmd(const RooRealVar& param, RooLinkedList& cmdList, bool symRange=false) const ;
108
109 bool run(bool generate, bool fit, Int_t nSamples, Int_t nEvtPerSample, bool keepGenData, const char* asciiFilePat) ;
110 bool fitSample(RooAbsData* genSample) ;
112
113 void calcPulls() ;
114
115 RooAbsData* _genSample = nullptr; ///< Currently generated sample
116 RooAbsPdf* _genModel = nullptr; ///< Generator model
117 std::unique_ptr<RooAbsGenContext> _genContext; ///< Generator context
118 RooArgSet _genInitParams; ///< List of original generator parameters
119 RooArgSet _genParams; ///< List of actual generator parameters
120 const RooDataSet* _genProtoData ; ///< Generator prototype data set
121 RooArgSet _projDeps ; ///< List of projected dependents in fit
122
123 std::unique_ptr<RooAbsPdf> _constrPdf; ///< Constraints p.d.f
124 std::unique_ptr<RooAbsGenContext> _constrGenContext; ///< Generator context for constraints p.d.f
125
126 RooArgSet _dependents ; ///< List of dependents
127 RooArgSet _allDependents ; ///< List of generate + prototype dependents
128 RooAbsPdf* _fitModel ; ///< Fit model
129 RooArgSet _fitInitParams; ///< List of initial values of fit parameters
130 RooArgSet _fitParams; ///< List of actual fit parameters
131 std::unique_ptr<RooRealVar> _nllVar;
132 std::unique_ptr<RooRealVar> _ngenVar;
133
134 TList _genDataList ; // List of generated data sample
135 TList _fitResList ; // List of RooFitResult fit output objects
136 std::unique_ptr<RooDataSet> _genParData; // List of generated parameters of each sample
137 std::unique_ptr<RooDataSet> _fitParData; // Data set of fit parameters of each sample
138 RooLinkedList _fitOptList ; // Fit option command list
139 bool _extendedGen ; // Add poisson term to number of events to generate?
140 bool _binGenData ; // Bin data between generating and fitting
141 double _nExpGen ; // Number of expected events to generate in extended mode
142 bool _randProto ; // Randomize order of prototype data access
143
144 bool _canAddFitResults ; ///< Allow adding of external fit results?
145 bool _verboseGen ; ///< Verbose generation?
146 bool _perExptGenParams = false; ///< Do generation parameter change per event?
147 bool _silence ; ///< Silent running mode?
148
149 std::list<RooAbsMCStudyModule*> _modList ; ///< List of additional study modules ;
150
151 // Utilities for modules ;
153 void resetFitParams() ;
154 void RecursiveRemove(TObject *obj) override;
155
156 ClassDefOverride(RooMCStudy,0) // A general purpose toy Monte Carlo study manager
157} ;
158
159
160#endif
161
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
#define hi
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:56
Abstract base class for generator contexts of RooAbsPdf objects.
Base class for add-on modules to RooMCStudy that can perform additional calculations on each generate...
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
Container class to hold unbinned data.
Definition RooDataSet.h:32
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
Helper class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies, that involve fittin...
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...
RooMCStudy & operator=(RooMCStudy &&)=delete
RooPlot * plotParam(const RooRealVar &param, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={})
Plot the distribution of the fitted value of the given parameter on a newly created frame.
RooAbsData * _genSample
Currently generated sample.
Definition RooMCStudy.h:115
RooPlot * makeFrameAndPlotCmd(const RooRealVar &param, RooLinkedList &cmdList, bool symRange=false) const
Internal function.
RooArgSet _projDeps
List of projected dependents in fit.
Definition RooMCStudy.h:121
RooArgSet _genParams
List of actual generator parameters.
Definition RooMCStudy.h:119
const RooArgSet * fitParams(Int_t sampleNum) const
Return an argset with the fit parameters for the given sample number.
void calcPulls()
Calculate the pulls for all fit parameters in the fit results data set, and add them to that dataset.
~RooMCStudy() override
RooArgSet _dependents
List of dependents.
Definition RooMCStudy.h:126
bool _verboseGen
Verbose generation?
Definition RooMCStudy.h:145
std::list< RooAbsMCStudyModule * > _modList
List of additional study modules ;.
Definition RooMCStudy.h:149
std::unique_ptr< RooDataSet > _genParData
Definition RooMCStudy.h:136
RooArgSet _genInitParams
List of original generator parameters.
Definition RooMCStudy.h:118
TList _fitResList
Definition RooMCStudy.h:135
double _nExpGen
Definition RooMCStudy.h:141
bool fitSample(RooAbsData *genSample)
Internal method.
RooPlot * plotNLL(const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={})
Plot the distribution of the -log(L) values on a newly created frame.
std::unique_ptr< RooDataSet > _fitParData
Definition RooMCStudy.h:137
bool generate(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char *asciiFilePat=nullptr)
Generate 'nSamples' samples of 'nEvtPerSample' events.
bool _extendedGen
Definition RooMCStudy.h:139
const RooDataSet * _genProtoData
Generator prototype data set.
Definition RooMCStudy.h:120
bool _canAddFitResults
Allow adding of external fit results?
Definition RooMCStudy.h:144
const RooFitResult * fitResult(Int_t sampleNum) const
Return the RooFitResult of the fit with the given run number.
RooFit::OwningPtr< RooFitResult > doFit(RooAbsData *genSample)
Internal function. Performs actual fit according to specifications.
std::unique_ptr< RooAbsGenContext > _constrGenContext
Generator context for constraints p.d.f.
Definition RooMCStudy.h:124
bool _perExptGenParams
Do generation parameter change per event?
Definition RooMCStudy.h:146
bool _binGenData
Definition RooMCStudy.h:140
bool _silence
Silent running mode?
Definition RooMCStudy.h:147
RooPlot * plotParamOn(RooPlot *frame, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={})
Plot the distribution of fitted values of a parameter.
RooArgSet _fitParams
List of actual fit parameters.
Definition RooMCStudy.h:130
RooPlot * plotError(const RooRealVar &param, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={})
Plot the distribution of the fit errors for the specified parameter on a newly created frame.
std::unique_ptr< RooAbsGenContext > _genContext
Generator context.
Definition RooMCStudy.h:117
RooMCStudy(const RooAbsPdf &model, const RooArgSet &observables, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={})
Construct Monte Carlo Study Manager.
RooFit::OwningPtr< RooFitResult > refit(RooAbsData *genSample=nullptr)
Redo fit on 'current' toy sample, or if genSample is not nullptr do fit on given sample instead.
RooAbsData * genData(Int_t sampleNum) const
Return the given generated dataset.
const RooDataSet * genParDataSet() const
Return dataset with the generator parameter values used for each toy, including any modification by c...
Definition RooMCStudy.h:68
RooMCStudy(RooMCStudy &&)=delete
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:116
const RooDataSet & fitParDataSet()
Return a RooDataSet containing the post-fit parameters of each toy cycle.
std::unique_ptr< RooRealVar > _nllVar
Definition RooMCStudy.h:131
RooLinkedList _fitOptList
Definition RooMCStudy.h:138
std::unique_ptr< RooAbsPdf > _constrPdf
Constraints p.d.f.
Definition RooMCStudy.h:123
RooArgSet _allDependents
List of generate + prototype dependents.
Definition RooMCStudy.h:127
bool run(bool generate, bool fit, Int_t nSamples, Int_t nEvtPerSample, bool keepGenData, const char *asciiFilePat)
Run engine method.
void resetFitParams()
Reset all fit parameters to the initial model parameters at the time of the RooMCStudy constructor.
RooAbsPdf * _fitModel
Fit model.
Definition RooMCStudy.h:128
bool fit(Int_t nSamples, const char *asciiFilePat)
Fit 'nSamples' datasets, which are read from ASCII files.
bool generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char *asciiFilePat=nullptr)
Generate and fit 'nSamples' samples of 'nEvtPerSample' events.
RooPlot * plotPull(const RooRealVar &param, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={})
Plot the distribution of pull values for the specified parameter on a newly created frame.
TList _genDataList
Definition RooMCStudy.h:134
bool _randProto
Definition RooMCStudy.h:142
RooMCStudy & operator=(const RooMCStudy &)=delete
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
RooMCStudy(const RooMCStudy &)=delete
RooArgSet _fitInitParams
List of initial values of fit parameters.
Definition RooMCStudy.h:129
std::unique_ptr< RooRealVar > _ngenVar
Definition RooMCStudy.h:132
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
Variable that can be changed from the outside.
Definition RooRealVar.h:37
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:42
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35