Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:29:54

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooAbsMCStudyModule.h,v 1.2 2007/05/11 09:11:30 verkerke Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 
0017 #ifndef ROO_ABS_MC_STUDY_MODULE
0018 #define ROO_ABS_MC_STUDY_MODULE
0019 
0020 #include "RooArgSet.h"
0021 #include "RooMCStudy.h"
0022 class RooAbsPdf;
0023 class RooDataSet ;
0024 class RooAbsData ;
0025 class RooAbsGenContext ;
0026 class RooFitResult ;
0027 class RooPlot ;
0028 class RooRealVar ;
0029 
0030 class RooAbsMCStudyModule : public TNamed {
0031 public:
0032 
0033   RooAbsMCStudyModule(const char* name, const char* title) ;
0034   RooAbsMCStudyModule(const RooAbsMCStudyModule& other) ;
0035 
0036   /// Initializer method called upon attachment to given RooMCStudy object
0037   bool doInitializeInstance(RooMCStudy& /*study*/) ;
0038 
0039   /// Initializer called immediately after attachment to RooMCStudy object and initialization of module base class
0040   virtual bool initializeInstance() {
0041     return true ;
0042   }
0043 
0044   /// Method called at the beginning of each RooMCStudy run
0045   virtual bool initializeRun(Int_t /*numSamples*/) {
0046     return true ;
0047   }
0048 
0049   /// Method called at the end of each RooMCStudy run. If a RooDataSet is returned, it must have a length equal to
0050   /// the number of toy experiments performed and will merged with the fitpar dataset of RooMCStudy.
0051   virtual RooDataSet* finalizeRun() {
0052     return nullptr ;
0053   }
0054 
0055   /// Method called after resetting of generator parameters to initial values and before call to generator context
0056   /// Any modifications to generator parameters will affect next generation operation (only)
0057   virtual bool processBeforeGen(Int_t /*sampleNum*/) {
0058     return true ;
0059   }
0060 
0061   /// Method called after generation of toy data sample and resetting of fit parameters to initial values and before
0062   /// actual fit is performed. Any modifications to fit parameters will apply to next fit operation. Note that setConstant
0063   /// flag of fit parameters are not explicitly reset by RooMCStudy, so any changes made to these flags here will persist
0064   virtual bool processBetweenGenAndFit(Int_t /*sampleNum*/) {
0065     return true ;
0066   }
0067 
0068   /// Method called after fit has been performed. It's crucial that this is
0069   /// implemented, because it's the responsability of this method to ensure
0070   /// that this MC study module will not have added an element to its internal
0071   /// RooDataSet if the fit has failed.
0072   virtual bool processAfterFit(bool fitOk) = 0;
0073 
0074 protected:
0075 
0076    // Interface methods to RooMCStudy objects,
0077    // which are only functional after module has been attached to a RooMCStudy object
0078 
0079    /// Refit model using original or specified data sample
0080    RooFit::OwningPtr<RooFitResult> refit(RooAbsData* inGenSample=nullptr);
0081 
0082    /// Return generate sample
0083    RooAbsData* genSample() {
0084      return _mcs ? _mcs->_genSample : nullptr ;
0085    }
0086 
0087    /// Return generator pdf
0088    RooAbsPdf* genModel() {
0089      return _mcs ? _mcs->_genModel : nullptr ;
0090    }
0091 
0092    // Accessor for generator context, generator parameters, prototype data and projected dependents.
0093    RooAbsGenContext* genContext() {
0094      return _mcs ? _mcs->_genContext.get() : nullptr ;
0095    }
0096 
0097    /// Return initial value of generator model parameters
0098    RooArgSet* genInitParams() {
0099      return _mcs ? &_mcs->_genInitParams : nullptr ;
0100    }
0101 
0102    /// Return current value of generator model parameters
0103    RooArgSet* genParams() {
0104      return _mcs ? &_mcs->_genParams : nullptr ;
0105    }
0106 
0107    /// Return generator prototype data provided by user
0108    const RooDataSet* genProtoData() {
0109      return _mcs ? _mcs->_genProtoData : nullptr ;
0110    }
0111 
0112    /// Return projected observables
0113    RooArgSet* projDeps() {
0114      return _mcs ? &_mcs->_projDeps : nullptr ;
0115    }
0116 
0117    // Accessors for fit observables, fit model, current and initial fit parameters and NLL value
0118 
0119    /// Return fit model observables
0120    RooArgSet* dependents() {
0121      return _mcs ? &_mcs->_dependents : nullptr ;
0122    }
0123 
0124    /// Return all observables
0125    RooArgSet* allDependents() {
0126      return _mcs ? &_mcs->_allDependents : nullptr ;
0127    }
0128 
0129    /// Return fit model
0130    RooAbsPdf* fitModel() {
0131      return _mcs ? _mcs->_fitModel : nullptr ;
0132    }
0133 
0134    /// Return initial value of parameters of fit model
0135    RooArgSet* fitInitParams() {
0136      return _mcs ? &_mcs->_fitInitParams : nullptr ;
0137    }
0138 
0139    /// Return current value of parameters of fit model
0140    RooArgSet* fitParams() {
0141      return _mcs ? &_mcs-> _fitParams : nullptr ;
0142    }
0143 
0144    /// Return pointer to RooRealVar holding minimized -log(L) value
0145    RooRealVar* nllVar() {
0146      return _mcs ? _mcs->_nllVar.get() : nullptr ;
0147    }
0148 
0149    // Accessors for fit options, generator and MCstudy configuration flags
0150 
0151    /// Return list of fit options provided by user
0152    RooLinkedList* fitOptList() {
0153      return _mcs ? &_mcs->_fitOptList : nullptr ;
0154    }
0155 
0156    /// If true extended mode generation is requested
0157    bool extendedGen() {
0158      return _mcs ? _mcs->_extendedGen : false ;
0159    }
0160 
0161    /// If true binning of data between generating and fitting is requested
0162    bool binGenData() {
0163      return _mcs ? _mcs->_binGenData : false ;
0164    }
0165 
0166    /// Return expected number of events from generator model
0167    double numExpGen() {
0168      return _mcs ? _mcs->_nExpGen : 0 ;
0169    }
0170 
0171    /// If true randomization of prototype data order is requested
0172    bool randProto() {
0173      return _mcs ? _mcs->_randProto : false ;
0174    }
0175 
0176    /// If true verbose message in the generation step is requested
0177    bool verboseGen() {
0178      return _mcs ? _mcs->_verboseGen : false ;
0179    }
0180 
0181 private:
0182 
0183   RooMCStudy* _mcs ; ///< Pointer to RooMCStudy object module is attached to
0184 
0185   ClassDefOverride(RooAbsMCStudyModule,0) // Monte Carlo study manager add-on module
0186 } ;
0187 
0188 
0189 #endif
0190