Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooMCStudy Class Reference

Helper class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies, that involve fitting a PDF to multiple toy Monte Carlo sets.

These may be generated from either same PDF or from a different PDF with similar parameters.

Given a fit and a generator PDF (they might be identical), RooMCStudy can produce toyMC samples and/or fit these. It accumulates the post-fit parameters of each iteration in a dataset. These can be retrieved using fitParams() or fitParDataSet(). This dataset additionally contains the variables

  • NLL: The value of the negative log-likelihood for each run.
  • ngen: The number of events generated for each run.

Additional plotting routines simplify the task of plotting the distribution of the minimized likelihood, the fitted parameter values, fitted error and pull distribution.

RooMCStudy provides the option to insert add-in modules that modify the generate-and-fit cycle and allow to perform extra steps in the cycle. Output of these modules can be stored alongside the fit results in the aggregate results dataset. These study modules should derive from the class RooAbsMCStudyModule.

Check the RooFit tutorials

PyROOT

Some member functions of RooMCStudy that take a RooCmdArg as argument also support keyword arguments. So far, this applies to constructor RooMCStudy(), RooMCStudy::plotParamOn, RooMCStudy::plotParam, RooMCStudy::plotNLL, RooMCStudy::plotError and RooMCStudy::plotPull. For example, the following code is equivalent in PyROOT:

# Directly passing a RooCmdArg:
frame3 = mcstudy.plotPull(mean, ROOT.RooFit.Bins(40), ROOT.RooFit.FitGauss(True))
# With keyword arguments:
frame3 = mcstudy.plotPull(mean, Bins=40, FitGauss=True)

Definition at line 32 of file RooMCStudy.h.

Public Member Functions

 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.
 
 ~RooMCStudy () override
 
bool addFitResult (const RooFitResult &fr)
 Utility function to add fit result from external fit to this RooMCStudy and process its results through the standard RooMCStudy statistics gathering tools.
 
void addModule (RooAbsMCStudyModule &module)
 Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
 
bool fit (Int_t nSamples, const char *asciiFilePat)
 Fit 'nSamples' datasets, which are read from ASCII files.
 
bool fit (Int_t nSamples, TList &dataSetList)
 Fit 'nSamples' datasets, as supplied in 'dataSetList'.
 
const RooArgSetfitParams (Int_t sampleNum) const
 Return an argset with the fit parameters for the given sample number.
 
const RooDataSetfitParDataSet ()
 Return a RooDataSet containing the post-fit parameters of each toy cycle.
 
const RooFitResultfitResult (Int_t sampleNum) const
 Return the RooFitResult of the fit with the given run number.
 
RooAbsDatagenData (Int_t sampleNum) const
 Return the given generated dataset.
 
bool generate (Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char *asciiFilePat=nullptr)
 Generate 'nSamples' samples of 'nEvtPerSample' events.
 
bool generateAndFit (Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char *asciiFilePat=nullptr)
 Generate and fit 'nSamples' samples of 'nEvtPerSample' events.
 
const RooDataSetgenParDataSet () const
 Return dataset with generator parameters for each toy.
 
TClassIsA () const override
 
RooPlotplotError (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.
 
RooPlotplotError (const RooRealVar &param, double lo, double hi, Int_t nbins=100)
 Create a RooPlot of the distribution of the fitted errors of the given parameter.
 
RooPlotplotNLL (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.
 
RooPlotplotNLL (double lo, double hi, Int_t nBins=100)
 Create a RooPlot of the -log(L) distribution in the range lo-hi with 'nBins' bins.
 
RooPlotplotParam (const char *paramName, 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.
 
RooPlotplotParam (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.
 
RooPlotplotParamOn (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.
 
RooPlotplotPull (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.
 
RooPlotplotPull (const RooRealVar &param, double lo=-3.0, double hi=3.0, Int_t nbins=25, bool fitGauss=false)
 Create a RooPlot of the pull distribution for the given parameter.
 
void Streamer (TBuffer &) override
 Stream an object of class TObject.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TNamed &named)
 TNamed copy ctor.
 
 TNamed (const TString &name, const TString &title)
 
virtual ~TNamed ()
 TNamed destructor.
 
void Clear (Option_t *option="") override
 Set name and title to empty strings ("").
 
TObjectClone (const char *newname="") const override
 Make a clone of an object using the Streamer facility.
 
Int_t Compare (const TObject *obj) const override
 Compare two TNamed objects.
 
void Copy (TObject &named) const override
 Copy this to obj.
 
virtual void FillBuffer (char *&buffer)
 Encode TNamed into output buffer.
 
const char * GetName () const override
 Returns name of object.
 
const char * GetTitle () const override
 Returns title of object.
 
ULong_t Hash () const override
 Return hash value for this object.
 
TClassIsA () const override
 
Bool_t IsSortable () const override
 
void ls (Option_t *option="") const override
 List TNamed name and title.
 
TNamedoperator= (const TNamed &rhs)
 TNamed assignment operator.
 
void Print (Option_t *option="") const override
 Print TNamed name and title.
 
virtual void SetName (const char *name)
 Set the name of the TNamed.
 
virtual void SetNameTitle (const char *name, const char *title)
 Set all the TNamed parameters (name and title).
 
virtual void SetTitle (const char *title="")
 Set the title of the TNamed.
 
virtual Int_t Sizeof () const
 Return size of the TNamed part of the TObject.
 
void Streamer (TBuffer &) override
 Stream an object of class TObject.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TObject
 TObject ()
 TObject constructor.
 
 TObject (const TObject &object)
 TObject copy ctor.
 
virtual ~TObject ()
 TObject destructor.
 
void AbstractMethod (const char *method) const
 Use this method to implement an "abstract" method that you don't want to leave purely abstract.
 
virtual void AppendPad (Option_t *option="")
 Append graphics object to current pad.
 
virtual void Browse (TBrowser *b)
 Browse object. May be overridden for another default action.
 
ULong_t CheckedHash ()
 Check and record whether this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object.
 
virtual const char * ClassName () const
 Returns name of class to which the object belongs.
 
virtual void Delete (Option_t *option="")
 Delete this object.
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 Computes distance from point (px,py) to the object.
 
virtual void Draw (Option_t *option="")
 Default Draw method for all objects.
 
virtual void DrawClass () const
 Draw class inheritance tree of the class to which this object belongs.
 
virtual TObjectDrawClone (Option_t *option="") const
 Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
 
virtual void Dump () const
 Dump contents of object on stdout.
 
virtual void Error (const char *method, const char *msgfmt,...) const
 Issue error message.
 
virtual void Execute (const char *method, const char *params, Int_t *error=nullptr)
 Execute method on this object with the given parameter string, e.g.
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr)
 Execute method on this object with parameters stored in the TObjArray.
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 Execute action corresponding to an event at (px,py).
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 Issue fatal error message.
 
virtual TObjectFindObject (const char *name) const
 Must be redefined in derived classes.
 
virtual TObjectFindObject (const TObject *obj) const
 Must be redefined in derived classes.
 
virtual Option_tGetDrawOption () const
 Get option used by the graphics system to draw this object.
 
virtual const char * GetIconName () const
 Returns mime type name of object.
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 Returns string containing info about the object at position (px,py).
 
virtual Option_tGetOption () const
 
virtual UInt_t GetUniqueID () const
 Return the unique object id.
 
virtual Bool_t HandleTimer (TTimer *timer)
 Execute action in response of a timer timing out.
 
Bool_t HasInconsistentHash () const
 Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e.
 
virtual void Info (const char *method, const char *msgfmt,...) const
 Issue info message.
 
virtual Bool_t InheritsFrom (const char *classname) const
 Returns kTRUE if object inherits from class "classname".
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 Returns kTRUE if object inherits from TClass cl.
 
virtual void Inspect () const
 Dump contents of this object in a graphics canvas.
 
void InvertBit (UInt_t f)
 
Bool_t IsDestructed () const
 IsDestructed.
 
virtual Bool_t IsEqual (const TObject *obj) const
 Default equal comparison (objects are equal if they have the same address in memory).
 
virtual Bool_t IsFolder () const
 Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
void MayNotUse (const char *method) const
 Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary).
 
virtual Bool_t Notify ()
 This method must be overridden to handle object notification (the base implementation is no-op).
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 Use this method to declare a method obsolete.
 
void operator delete (void *ptr)
 Operator delete.
 
void operator delete[] (void *ptr)
 Operator delete [].
 
void * operator new (size_t sz)
 
void * operator new (size_t sz, void *vp)
 
void * operator new[] (size_t sz)
 
void * operator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 TObject assignment operator.
 
virtual void Paint (Option_t *option="")
 This method must be overridden if a class wants to paint itself.
 
virtual void Pop ()
 Pop on object drawn in a pad to the top of the display list.
 
virtual Int_t Read (const char *name)
 Read contents of object with specified name from the current directory.
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 Save this object in the file specified by filename.
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 Save a primitive as a C++ statement(s) on output stream "out".
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 Set or unset the user status bits as specified in f.
 
virtual void SetDrawOption (Option_t *option="")
 Set drawing option for object.
 
virtual void SetUniqueID (UInt_t uid)
 Set the unique object id.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 Issue system error message.
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked.
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 Issue warning message.
 
virtual Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
 Write this object to the current directory.
 
virtual Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const
 Write this object to the current directory.
 

Static Public Member Functions

static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TNamed
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TObject
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Longptr_t GetDtorOnly ()
 Return destructor only flag.
 
static Bool_t GetObjectStat ()
 Get status of object stat flag.
 
static void SetDtorOnly (void *obj)
 Set destructor only flag.
 
static void SetObjectStat (Bool_t stat)
 Turn on/off tracking of objects in the TObjectTable.
 

Protected Member Functions

void calcPulls ()
 Calculate the pulls for all fit parameters in the fit results data set, and add them to that dataset.
 
RooFit::OwningPtr< RooFitResultdoFit (RooAbsData *genSample)
 Internal function. Performs actual fit according to specifications.
 
bool fitSample (RooAbsData *genSample)
 Internal method.
 
RooPlotmakeFrameAndPlotCmd (const RooRealVar &param, RooLinkedList &cmdList, bool symRange=false) const
 Internal function.
 
void RecursiveRemove (TObject *obj) override
 If one of the TObject we have a referenced to is deleted, remove the reference.
 
RooFit::OwningPtr< RooFitResultrefit (RooAbsData *genSample=nullptr)
 Redo fit on 'current' toy sample, or if genSample is not nullptr do fit on given sample instead.
 
void resetFitParams ()
 Reset all fit parameters to the initial model parameters at the time of the RooMCStudy constructor.
 
bool run (bool generate, bool fit, Int_t nSamples, Int_t nEvtPerSample, bool keepGenData, const char *asciiFilePat)
 Run engine method.
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 Interface to ErrorHandler (protected).
 
void MakeZombie ()
 

Protected Attributes

RooArgSet _allDependents
 List of generate + prototype dependents.
 
bool _binGenData
 
bool _canAddFitResults
 Allow adding of external fit results?
 
std::unique_ptr< RooAbsGenContext_constrGenContext
 Generator context for constraints p.d.f.
 
std::unique_ptr< RooAbsPdf_constrPdf
 Constraints p.d.f.
 
RooArgSet _dependents
 List of dependents.
 
bool _extendedGen
 
RooArgSet _fitInitParams
 List of initial values of fit parameters.
 
RooAbsPdf_fitModel
 Fit model.
 
RooLinkedList _fitOptList
 
RooArgSet _fitParams
 List of actual fit parameters.
 
std::unique_ptr< RooDataSet_fitParData
 
TList _fitResList
 
std::unique_ptr< RooAbsGenContext_genContext
 Generator context.
 
TList _genDataList
 
RooArgSet _genInitParams
 List of original generator parameters.
 
RooAbsPdf_genModel = nullptr
 Generator model.
 
RooArgSet _genParams
 List of actual generator parameters.
 
std::unique_ptr< RooDataSet_genParData
 
const RooDataSet_genProtoData
 Generator prototype data set.
 
RooAbsData_genSample = nullptr
 Currently generated sample.
 
std::list< RooAbsMCStudyModule * > _modList
 List of additional study modules ;.
 
double _nExpGen
 
std::unique_ptr< RooRealVar_ngenVar
 
std::unique_ptr< RooRealVar_nllVar
 
bool _perExptGenParams = false
 Do generation parameter change per event?
 
RooArgSet _projDeps
 List of projected dependents in fit.
 
bool _randProto
 
bool _silence
 Silent running mode?
 
bool _verboseGen
 Verbose generation?
 
- Protected Attributes inherited from TNamed
TString fName
 
TString fTitle
 

Private Member Functions

 RooMCStudy (const RooMCStudy &)
 

Friends

class RooAbsMCStudyModule
 

Additional Inherited Members

- Public Types inherited from TObject
enum  {
  kIsOnHeap = 0x01000000 , kNotDeleted = 0x02000000 , kZombie = 0x04000000 , kInconsistent = 0x08000000 ,
  kBitMask = 0x00ffffff
}
 
enum  { kSingleKey = (1ULL << ( 0 )) , kOverwrite = (1ULL << ( 1 )) , kWriteDelete = (1ULL << ( 2 )) }
 
enum  EDeprecatedStatusBits { kObjInCanvas = (1ULL << ( 3 )) }
 
enum  EStatusBits {
  kCanDelete = (1ULL << ( 0 )) , kMustCleanup = (1ULL << ( 3 )) , kIsReferenced = (1ULL << ( 4 )) , kHasUUID = (1ULL << ( 5 )) ,
  kCannotPick = (1ULL << ( 6 )) , kNoContextMenu = (1ULL << ( 8 )) , kInvalidObject = (1ULL << ( 13 ))
}
 
- Protected Types inherited from TObject
enum  { kOnlyPrepStep = (1ULL << ( 3 )) }
 

#include <RooMCStudy.h>

Inheritance diagram for RooMCStudy:
[legend]

Constructor & Destructor Documentation

◆ RooMCStudy() [1/2]

RooMCStudy::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.

This class automates generating data from a given PDF, fitting the PDF to data and accumulating the fit statistics.

Parameters
[in]modelThe PDF to be studied
[in]observablesThe variables of the PDF to be considered observables
[in]arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8Optional arguments according to table below.
Optional arguments
Silence() Suppress all RooFit messages during running below PROGRESS level
FitModel(const RooAbsPdf&) The PDF for fitting if it is different from the PDF for generating.
ConditionalObservables(const RooArgSet& set) The set of observables that the PDF should not be normalized over
Binned(bool flag) Bin the dataset before fitting it. Speeds up fitting of large data samples
FitOptions(....) Options to be used for fitting. All named arguments inside FitOptions() are passed to RooAbsPdf::fitTo(). Save() is especially interesting to be able to retrieve fit results of each run using fitResult().
Verbose(bool flag) Activate informational messages in event generation phase
Extended(bool flag) Determine number of events for each sample anew from a Poisson distribution
Constrain(const RooArgSet& pars) Apply internal constraints on given parameters in fit and sample constrained parameter values from constraint p.d.f for each toy.
ExternalConstraints(const RooArgSet& ) Apply internal constraints on given parameters in fit and sample constrained parameter values from constraint p.d.f for each toy.
ProtoData(const RooDataSet&, bool randOrder) Prototype data for the event generation. If the randOrder flag is set, the order of the dataset will be re-randomized for each generation cycle to protect against systematic biases if the number of generated events does not exactly match the number of events in the prototype dataset at the cost of reduced precision with mu equal to the specified number of events

Definition at line 106 of file RooMCStudy.cxx.

◆ ~RooMCStudy()

RooMCStudy::~RooMCStudy ( )
override

Definition at line 289 of file RooMCStudy.cxx.

◆ RooMCStudy() [2/2]

RooMCStudy::RooMCStudy ( const RooMCStudy )
private

Member Function Documentation

◆ addFitResult()

bool RooMCStudy::addFitResult ( const RooFitResult fr)

Utility function to add fit result from external fit to this RooMCStudy and process its results through the standard RooMCStudy statistics gathering tools.

This function allows users to run the toy MC generation and/or fitting in a distributed way and to collect and analyze the results in a RooMCStudy as if they were run locally.

This method is only functional if this RooMCStudy object is cleanm, i.e. it was not used to generate and/or fit any samples.

Definition at line 694 of file RooMCStudy.cxx.

◆ addModule()

void RooMCStudy::addModule ( RooAbsMCStudyModule module)

Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.

Definition at line 301 of file RooMCStudy.cxx.

◆ calcPulls()

void RooMCStudy::calcPulls ( )
protected

Calculate the pulls for all fit parameters in the fit results data set, and add them to that dataset.

Definition at line 728 of file RooMCStudy.cxx.

◆ Class()

static TClass * RooMCStudy::Class ( )
static
Returns
TClass describing this class

◆ Class_Name()

static const char * RooMCStudy::Class_Name ( )
static
Returns
Name of this class

◆ Class_Version()

static constexpr Version_t RooMCStudy::Class_Version ( )
inlinestaticconstexpr
Returns
Version of this class

Definition at line 152 of file RooMCStudy.h.

◆ DeclFileName()

static const char * RooMCStudy::DeclFileName ( )
inlinestatic
Returns
Name of the file containing the class declaration

Definition at line 152 of file RooMCStudy.h.

◆ doFit()

RooFit::OwningPtr< RooFitResult > RooMCStudy::doFit ( RooAbsData genSample)
protected

Internal function. Performs actual fit according to specifications.

Definition at line 589 of file RooMCStudy.cxx.

◆ fit() [1/2]

bool RooMCStudy::fit ( Int_t  nSamples,
const char *  asciiFilePat 
)

Fit 'nSamples' datasets, which are read from ASCII files.

The ascii file pattern, which is a template for snprintf, should look something like "data/toymc_%04d.dat" and should contain one integer field that encodes the sample serial number.

Definition at line 543 of file RooMCStudy.cxx.

◆ fit() [2/2]

bool RooMCStudy::fit ( Int_t  nSamples,
TList dataSetList 
)

Fit 'nSamples' datasets, as supplied in 'dataSetList'.

Definition at line 558 of file RooMCStudy.cxx.

◆ fitParams()

const RooArgSet * RooMCStudy::fitParams ( Int_t  sampleNum) const

Return an argset with the fit parameters for the given sample number.

NB: The fit parameters are only stored for successful fits, thus the maximum sampleNum can be less that the number of generated samples and if so, the indices will be out of synch with genData() and fitResult()

Definition at line 814 of file RooMCStudy.cxx.

◆ fitParDataSet()

const RooDataSet & RooMCStudy::fitParDataSet ( )

Return a RooDataSet containing the post-fit parameters of each toy cycle.

This dataset also contains any additional output that was generated by study modules that were added to this RooMCStudy. By default, the two following variables are added (apart from fit parameters):

  • NLL: The value of the negative log-likelihood for each run.
  • ngen: Number of events generated for each run.

Definition at line 794 of file RooMCStudy.cxx.

◆ fitResult()

const RooFitResult * RooMCStudy::fitResult ( Int_t  sampleNum) const

Return the RooFitResult of the fit with the given run number.

Note
Fit results are not saved by default. This requires passing FitOptions(Save(), ...) to the constructor.

Definition at line 832 of file RooMCStudy.cxx.

◆ fitSample()

bool RooMCStudy::fitSample ( RooAbsData genSample)
protected

Internal method.

Fit given dataset with fit model. If fit converges (TMinuit status code zero) The fit results are appended to the fit results dataset

If the fit option "r" is supplied, the RooFitResult objects will always be saved, regardless of the fit status. RooFitResults objects can be retrieved later via fitResult().

Definition at line 649 of file RooMCStudy.cxx.

◆ genData()

RooAbsData * RooMCStudy::genData ( Int_t  sampleNum) const

Return the given generated dataset.

This method will only return datasets if during the run cycle it was indicated that generator data should be saved.

Definition at line 857 of file RooMCStudy.cxx.

◆ generate()

bool RooMCStudy::generate ( Int_t  nSamples,
Int_t  nEvtPerSample = 0,
bool  keepGenData = false,
const char *  asciiFilePat = nullptr 
)

Generate 'nSamples' samples of 'nEvtPerSample' events.

If keepGenData is set, all generated data sets will be kept in memory and can be accessed later via genData().

Data sets will be written out in ascii form if the pattern string is supplied. The pattern, which is a template for snprintf, should look something like "data/toymc_%04d.dat" and should contain one integer field that encodes the sample serial number.

Definition at line 526 of file RooMCStudy.cxx.

◆ generateAndFit()

bool RooMCStudy::generateAndFit ( Int_t  nSamples,
Int_t  nEvtPerSample = 0,
bool  keepGenData = false,
const char *  asciiFilePat = nullptr 
)

Generate and fit 'nSamples' samples of 'nEvtPerSample' events.

If keepGenData is set, all generated data sets will be kept in memory and can be accessed later via genData().

Data sets will be written out in ascii form if the pattern string is supplied. The pattern, which is a template for snprintf, should look something like "data/toymc_%04d.dat" and should contain one integer field that encodes the sample serial number.

Definition at line 504 of file RooMCStudy.cxx.

◆ genParDataSet()

const RooDataSet * RooMCStudy::genParDataSet ( ) const
inline

Return dataset with generator parameters for each toy.

When constraints are used these may generally not be the same as the fitted parameters.

Definition at line 60 of file RooMCStudy.h.

◆ IsA()

TClass * RooMCStudy::IsA ( ) const
inlineoverridevirtual
Returns
TClass describing current object

Reimplemented from TObject.

Definition at line 152 of file RooMCStudy.h.

◆ makeFrameAndPlotCmd()

RooPlot * RooMCStudy::makeFrameAndPlotCmd ( const RooRealVar param,
RooLinkedList cmdList,
bool  symRange = false 
) const
protected

Internal function.

Construct RooPlot from given parameter and modify the list of named arguments 'cmdList' to only contain the plot arguments that should be forwarded to RooAbsData::plotOn()

Definition at line 1144 of file RooMCStudy.cxx.

◆ plotError() [1/2]

RooMCStudy::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.

Optional arguments
FrameRange(double lo, double hi) Set range of frame to given specification
FrameBins(int bins) Set default number of bins of frame to given number
Frame() Pass supplied named arguments to RooAbsRealLValue::frame() function. See there for list of allowed arguments

If no frame specifications are given, the AutoRange() feature will be used to set a default range. Any other named argument is passed to the RooAbsData::plotOn() call. See that function for allowed options.

PyROOT

The RooMCStudy::plotError() function is pythonized with the command argument pythonization. The keywords must correspond to the CmdArg of the function.

Definition at line 987 of file RooMCStudy.cxx.

◆ plotError() [2/2]

RooPlot * RooMCStudy::plotError ( const RooRealVar param,
double  lo,
double  hi,
Int_t  nbins = 100 
)

Create a RooPlot of the distribution of the fitted errors of the given parameter.

The frame is created with a range [lo,hi] and plotted data will be binned in 'nbins' bins

Definition at line 1214 of file RooMCStudy.cxx.

◆ plotNLL() [1/2]

RooMCStudy::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.

Optional arguments
FrameRange(double lo, double hi) Set range of frame to given specification
FrameBins(int bins) Set default number of bins of frame to given number
Frame() Pass supplied named arguments to RooAbsRealLValue::frame() function. See there for list of allowed arguments

If no frame specifications are given, the AutoRange() feature will be used to set the range. Any other named argument is passed to the RooAbsData::plotOn() call. See that function for allowed options

PyROOT

The RooMCStudy::plotNLL() function is pythonized with the command argument pythonization. The keywords must correspond to the CmdArg of the function.

Definition at line 963 of file RooMCStudy.cxx.

◆ plotNLL() [2/2]

RooPlot * RooMCStudy::plotNLL ( double  lo,
double  hi,
Int_t  nBins = 100 
)

Create a RooPlot of the -log(L) distribution in the range lo-hi with 'nBins' bins.

Definition at line 1200 of file RooMCStudy.cxx.

◆ plotParam() [1/2]

RooMCStudy::plotParam ( const char *  paramName,
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.

Optional arguments
FrameRange(double lo, double hi) Set range of frame to given specification
FrameBins(int bins) Set default number of bins of frame to given number
Frame() Pass supplied named arguments to RooAbsRealLValue::frame() function. See there for list of allowed arguments

If no frame specifications are given, the AutoRange() feature will be used to set the range Any other named argument is passed to the RooAbsData::plotOn() call. See that function for allowed options

PyROOT

The RooMCStudy::plotParam() function is pythonized with the command argument pythonization. The keywords must correspond to the CmdArg of the function.

Definition at line 907 of file RooMCStudy.cxx.

◆ plotParam() [2/2]

RooMCStudy::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.

Optional arguments
FrameRange(double lo, double hi) Set range of frame to given specification
FrameBins(int bins) Set default number of bins of frame to given number
Frame() Pass supplied named arguments to RooAbsRealLValue::frame() function. See there for list of allowed arguments

If no frame specifications are given, the AutoRange() feature will be used to set the range Any other named argument is passed to the RooAbsData::plotOn() call. See that function for allowed options

PyROOT

The RooMCStudy::plotParam() function is pythonized with the command argument pythonization. The keywords must correspond to the CmdArg of the function.

PyROOT

The RooMCStudy::plotParam() function is pythonized with the command argument pythonization. The keywords must correspond to the CmdArg of the function.

Definition at line 929 of file RooMCStudy.cxx.

◆ plotParamOn()

RooMCStudy::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.

The parameter shown is the one from which the RooPlot was created, e.g.

RooPlot* frame = param.frame(100,-10,10) ; mcstudy.paramOn(frame,LineStyle(kDashed)) ;

Any named arguments passed to plotParamOn() are forwarded to the underlying plotOn() call

PyROOT

The RooMCStudy::plotParamOn() function is pythonized with the command argument pythonization. The keywords must correspond to the CmdArg of the function.

Definition at line 885 of file RooMCStudy.cxx.

◆ plotPull() [1/2]

RooMCStudy::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.

If asymmetric errors are calculated in the fit (by MINOS) those will be used in the pull calculation.

If the parameters of the models for generation and fit differ, simple heuristics are used to find the corresponding parameters:

  • Parameters have the same name: They will be used to compute pulls.
  • Parameters have different names: The position of the fit parameter in the set of fit parameters will be computed. The parameter at the same position in the set of generator parameters will be used.

Further options:

Arguments Effect
FrameRange(double lo, double hi) Set range of frame to given specification
FrameBins(int bins) Set default number of bins of frame to given number
Frame() Pass supplied named arguments to RooAbsRealLValue::frame() function. See there for list of allowed arguments
FitGauss(bool flag) Add a gaussian fit to the frame

If no frame specifications are given, the AutoSymRange() feature will be used to set a default range. Any other named argument is passed to the RooAbsData::plotOn(). See that function for allowed options.

If you want to have more control over the Gaussian fit to the pull distribution, you can also do it after the call to plotPull():

RooPlot *frame = mcstudy->plotPull(myVariable, RooFit::Bins(40), RooFit::FitGauss(false));
RooRealVar pullMean("pullMean","Mean of pull",0,-10,10) ;
RooRealVar pullSigma("pullSigma","Width of pull",1,0.1,5) ;
pullMean.setPlotLabel("pull #mu"); // optional (to get nicer plot labels if you want)
pullSigma.setPlotLabel("pull #sigma"); // optional
RooGaussian pullGauss("pullGauss","Gaussian of pull", *frame->getPlotVar(), pullMean, pullSigma);
pullGauss.fitTo(const_cast<RooDataSet&>(mcstudy->fitParDataSet()),
pullGauss.plotOn(frame) ;
pullGauss.paramOn(frame, RooFit::Layout(0.65, 0.9, 0.9)); // optionally specify label position (xmin, xmax, ymax)
Container class to hold unbinned data.
Definition RooDataSet.h:57
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
RooAbsRealLValue * getPlotVar() const
Definition RooPlot.h:139
Variable that can be changed from the outside.
Definition RooRealVar.h:37
RooCmdArg FitGauss(bool flag=true)
RooCmdArg Bins(Int_t nbin)
RooCmdArg Layout(double xmin, double xmax=0.99, double ymin=0.95)
RooCmdArg Minos(bool flag=true)
RooCmdArg PrintLevel(Int_t code)

PyROOT

The RooMCStudy::plotError() function is pythonized with the command argument pythonization. The keywords must correspond to the CmdArg of the function.

Definition at line 1088 of file RooMCStudy.cxx.

◆ plotPull() [2/2]

RooPlot * RooMCStudy::plotPull ( const RooRealVar param,
double  lo = -3.0,
double  hi = 3.0,
Int_t  nbins = 25,
bool  fitGauss = false 
)

Create a RooPlot of the pull distribution for the given parameter.

The range lo-hi is plotted in nbins. If fitGauss is set, an unbinned ML fit of the distribution to a Gaussian p.d.f is performed. The fit result is overlaid on the returned RooPlot and a box with the fitted mean and sigma is added.

If the parameters of the models for generation and fit differ, simple heuristics are used to find the corresponding parameters:

  • Parameters have the same name: They will be used to compute pulls.
  • Parameters have different names: The position of the fit parameter in the set of fit parameters will be computed. The parameter at the same position in the set of generator parameters will be used.

Definition at line 1243 of file RooMCStudy.cxx.

◆ RecursiveRemove()

void RooMCStudy::RecursiveRemove ( TObject obj)
overrideprotectedvirtual

If one of the TObject we have a referenced to is deleted, remove the reference.

Reimplemented from TObject.

Definition at line 1276 of file RooMCStudy.cxx.

◆ refit()

RooFit::OwningPtr< RooFitResult > RooMCStudy::refit ( RooAbsData genSample = nullptr)
protected

Redo fit on 'current' toy sample, or if genSample is not nullptr do fit on given sample instead.

Definition at line 622 of file RooMCStudy.cxx.

◆ resetFitParams()

void RooMCStudy::resetFitParams ( )
protected

Reset all fit parameters to the initial model parameters at the time of the RooMCStudy constructor.

Definition at line 579 of file RooMCStudy.cxx.

◆ run()

bool RooMCStudy::run ( bool  doGenerate,
bool  DoFit,
Int_t  nSamples,
Int_t  nEvtPerSample,
bool  keepGenData,
const char *  asciiFilePat 
)
protected

Run engine method.

Generate and/or fit, according to flags, 'nSamples' samples of 'nEvtPerSample' events. If keepGenData is set, all generated data sets will be kept in memory and can be accessed later via genData().

When generating, data sets will be written out in ascii form if the pattern string is supplied The pattern, which is a template for snprintf, should look something like "data/toymc_%04d.dat" and should contain one integer field that encodes the sample serial number.

When fitting only, data sets may optionally be read from ascii files, using the same file pattern.

Definition at line 322 of file RooMCStudy.cxx.

◆ Streamer()

void RooMCStudy::Streamer ( TBuffer R__b)
overridevirtual

Stream an object of class TObject.

Reimplemented from TObject.

◆ StreamerNVirtual()

void RooMCStudy::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 152 of file RooMCStudy.h.

Friends And Related Symbol Documentation

◆ RooAbsMCStudyModule

friend class RooAbsMCStudyModule
friend

Definition at line 97 of file RooMCStudy.h.

Member Data Documentation

◆ _allDependents

RooArgSet RooMCStudy::_allDependents
protected

List of generate + prototype dependents.

Definition at line 119 of file RooMCStudy.h.

◆ _binGenData

bool RooMCStudy::_binGenData
protected

Definition at line 132 of file RooMCStudy.h.

◆ _canAddFitResults

bool RooMCStudy::_canAddFitResults
protected

Allow adding of external fit results?

Definition at line 136 of file RooMCStudy.h.

◆ _constrGenContext

std::unique_ptr<RooAbsGenContext> RooMCStudy::_constrGenContext
protected

Generator context for constraints p.d.f.

Definition at line 116 of file RooMCStudy.h.

◆ _constrPdf

std::unique_ptr<RooAbsPdf> RooMCStudy::_constrPdf
protected

Constraints p.d.f.

Definition at line 115 of file RooMCStudy.h.

◆ _dependents

RooArgSet RooMCStudy::_dependents
protected

List of dependents.

Definition at line 118 of file RooMCStudy.h.

◆ _extendedGen

bool RooMCStudy::_extendedGen
protected

Definition at line 131 of file RooMCStudy.h.

◆ _fitInitParams

RooArgSet RooMCStudy::_fitInitParams
protected

List of initial values of fit parameters.

Definition at line 121 of file RooMCStudy.h.

◆ _fitModel

RooAbsPdf* RooMCStudy::_fitModel
protected

Fit model.

Definition at line 120 of file RooMCStudy.h.

◆ _fitOptList

RooLinkedList RooMCStudy::_fitOptList
protected

Definition at line 130 of file RooMCStudy.h.

◆ _fitParams

RooArgSet RooMCStudy::_fitParams
protected

List of actual fit parameters.

Definition at line 122 of file RooMCStudy.h.

◆ _fitParData

std::unique_ptr<RooDataSet> RooMCStudy::_fitParData
protected

Definition at line 129 of file RooMCStudy.h.

◆ _fitResList

TList RooMCStudy::_fitResList
protected

Definition at line 127 of file RooMCStudy.h.

◆ _genContext

std::unique_ptr<RooAbsGenContext> RooMCStudy::_genContext
protected

Generator context.

Definition at line 109 of file RooMCStudy.h.

◆ _genDataList

TList RooMCStudy::_genDataList
protected

Definition at line 126 of file RooMCStudy.h.

◆ _genInitParams

RooArgSet RooMCStudy::_genInitParams
protected

List of original generator parameters.

Definition at line 110 of file RooMCStudy.h.

◆ _genModel

RooAbsPdf* RooMCStudy::_genModel = nullptr
protected

Generator model.

Definition at line 108 of file RooMCStudy.h.

◆ _genParams

RooArgSet RooMCStudy::_genParams
protected

List of actual generator parameters.

Definition at line 111 of file RooMCStudy.h.

◆ _genParData

std::unique_ptr<RooDataSet> RooMCStudy::_genParData
protected

Definition at line 128 of file RooMCStudy.h.

◆ _genProtoData

const RooDataSet* RooMCStudy::_genProtoData
protected

Generator prototype data set.

Definition at line 112 of file RooMCStudy.h.

◆ _genSample

RooAbsData* RooMCStudy::_genSample = nullptr
protected

Currently generated sample.

Definition at line 107 of file RooMCStudy.h.

◆ _modList

std::list<RooAbsMCStudyModule*> RooMCStudy::_modList
protected

List of additional study modules ;.

Definition at line 141 of file RooMCStudy.h.

◆ _nExpGen

double RooMCStudy::_nExpGen
protected

Definition at line 133 of file RooMCStudy.h.

◆ _ngenVar

std::unique_ptr<RooRealVar> RooMCStudy::_ngenVar
protected

Definition at line 124 of file RooMCStudy.h.

◆ _nllVar

std::unique_ptr<RooRealVar> RooMCStudy::_nllVar
protected

Definition at line 123 of file RooMCStudy.h.

◆ _perExptGenParams

bool RooMCStudy::_perExptGenParams = false
protected

Do generation parameter change per event?

Definition at line 138 of file RooMCStudy.h.

◆ _projDeps

RooArgSet RooMCStudy::_projDeps
protected

List of projected dependents in fit.

Definition at line 113 of file RooMCStudy.h.

◆ _randProto

bool RooMCStudy::_randProto
protected

Definition at line 134 of file RooMCStudy.h.

◆ _silence

bool RooMCStudy::_silence
protected

Silent running mode?

Definition at line 139 of file RooMCStudy.h.

◆ _verboseGen

bool RooMCStudy::_verboseGen
protected

Verbose generation?

Definition at line 137 of file RooMCStudy.h.

Libraries for RooMCStudy:

The documentation for this class was generated from the following files: