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 generator parameters for each toy. When constraints are used these
64 /// may generally not be the same as the fitted parameters.
65 const RooDataSet* genParDataSet() const {
66 return _genParData.get();
67 }
68
69 // Plot methods
70 RooPlot* plotParamOn(RooPlot* frame, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
71 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
72 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
73 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
74 RooPlot* plotParam(const RooRealVar& param, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
75 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
76 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
77 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
78 RooPlot* plotParam(const char* paramName, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
79 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
80 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
81 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
82 RooPlot* plotNLL(const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
83 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
84 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
85 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
86 RooPlot* plotError(const RooRealVar& param, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
87 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
88 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
89 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
90 RooPlot* plotPull(const RooRealVar& param, const RooCmdArg& arg1, const RooCmdArg& arg2={},
91 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
92 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
93 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
94
95
96 RooPlot* plotNLL(double lo, double hi, Int_t nBins=100) ;
97 RooPlot* plotError(const RooRealVar& param, double lo, double hi, Int_t nbins=100) ;
98 RooPlot* plotPull(const RooRealVar& param, double lo=-3.0, double hi=3.0, Int_t nbins=25, bool fitGauss=false) ;
99
100protected:
101
102 friend class RooAbsMCStudyModule ;
103
104 RooPlot* makeFrameAndPlotCmd(const RooRealVar& param, RooLinkedList& cmdList, bool symRange=false) const ;
105
106 bool run(bool generate, bool fit, Int_t nSamples, Int_t nEvtPerSample, bool keepGenData, const char* asciiFilePat) ;
107 bool fitSample(RooAbsData* genSample) ;
109
110 void calcPulls() ;
111
112 RooAbsData* _genSample = nullptr; ///< Currently generated sample
113 RooAbsPdf* _genModel = nullptr; ///< Generator model
114 std::unique_ptr<RooAbsGenContext> _genContext; ///< Generator context
115 RooArgSet _genInitParams; ///< List of original generator parameters
116 RooArgSet _genParams; ///< List of actual generator parameters
117 const RooDataSet* _genProtoData ; ///< Generator prototype data set
118 RooArgSet _projDeps ; ///< List of projected dependents in fit
119
120 std::unique_ptr<RooAbsPdf> _constrPdf; ///< Constraints p.d.f
121 std::unique_ptr<RooAbsGenContext> _constrGenContext; ///< Generator context for constraints p.d.f
122
123 RooArgSet _dependents ; ///< List of dependents
124 RooArgSet _allDependents ; ///< List of generate + prototype dependents
125 RooAbsPdf* _fitModel ; ///< Fit model
126 RooArgSet _fitInitParams; ///< List of initial values of fit parameters
127 RooArgSet _fitParams; ///< List of actual fit parameters
128 std::unique_ptr<RooRealVar> _nllVar;
129 std::unique_ptr<RooRealVar> _ngenVar;
130
131 TList _genDataList ; // List of generated data sample
132 TList _fitResList ; // List of RooFitResult fit output objects
133 std::unique_ptr<RooDataSet> _genParData; // List of generated parameters of each sample
134 std::unique_ptr<RooDataSet> _fitParData; // Data set of fit parameters of each sample
135 RooLinkedList _fitOptList ; // Fit option command list
136 bool _extendedGen ; // Add poisson term to number of events to generate?
137 bool _binGenData ; // Bin data between generating and fitting
138 double _nExpGen ; // Number of expected events to generate in extended mode
139 bool _randProto ; // Randomize order of prototype data access
140
141 bool _canAddFitResults ; ///< Allow adding of external fit results?
142 bool _verboseGen ; ///< Verbose generation?
143 bool _perExptGenParams = false; ///< Do generation parameter change per event?
144 bool _silence ; ///< Silent running mode?
145
146 std::list<RooAbsMCStudyModule*> _modList ; ///< List of additional study modules ;
147
148 // Utilities for modules ;
150 void resetFitParams() ;
151 void RecursiveRemove(TObject *obj) override;
152
153 ClassDefOverride(RooMCStudy,0) // A general purpose toy Monte Carlo study manager
154} ;
155
156
157#endif
158
#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:112
RooPlot * makeFrameAndPlotCmd(const RooRealVar &param, RooLinkedList &cmdList, bool symRange=false) const
Internal function.
RooArgSet _projDeps
List of projected dependents in fit.
Definition RooMCStudy.h:118
RooArgSet _genParams
List of actual generator parameters.
Definition RooMCStudy.h:116
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:123
bool _verboseGen
Verbose generation?
Definition RooMCStudy.h:142
std::list< RooAbsMCStudyModule * > _modList
List of additional study modules ;.
Definition RooMCStudy.h:146
std::unique_ptr< RooDataSet > _genParData
Definition RooMCStudy.h:133
RooArgSet _genInitParams
List of original generator parameters.
Definition RooMCStudy.h:115
TList _fitResList
Definition RooMCStudy.h:132
double _nExpGen
Definition RooMCStudy.h:138
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:134
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:136
const RooDataSet * _genProtoData
Generator prototype data set.
Definition RooMCStudy.h:117
bool _canAddFitResults
Allow adding of external fit results?
Definition RooMCStudy.h:141
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:121
bool _perExptGenParams
Do generation parameter change per event?
Definition RooMCStudy.h:143
bool _binGenData
Definition RooMCStudy.h:137
bool _silence
Silent running mode?
Definition RooMCStudy.h:144
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:127
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:114
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 generator parameters for each toy.
Definition RooMCStudy.h:65
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:113
const RooDataSet & fitParDataSet()
Return a RooDataSet containing the post-fit parameters of each toy cycle.
std::unique_ptr< RooRealVar > _nllVar
Definition RooMCStudy.h:128
RooLinkedList _fitOptList
Definition RooMCStudy.h:135
std::unique_ptr< RooAbsPdf > _constrPdf
Constraints p.d.f.
Definition RooMCStudy.h:120
RooArgSet _allDependents
List of generate + prototype dependents.
Definition RooMCStudy.h:124
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:125
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:131
bool _randProto
Definition RooMCStudy.h:139
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:126
std::unique_ptr< RooRealVar > _ngenVar
Definition RooMCStudy.h:129
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