Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooMCStudy.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooMCStudy.h,v 1.18 2007/05/11 10:14:56 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 #ifndef ROO_MC_STUDY
0017 #define ROO_MC_STUDY
0018 
0019 #include "TList.h"
0020 #include "TNamed.h"
0021 #include "RooArgSet.h"
0022 #include <list>
0023 class RooAbsPdf;
0024 class RooDataSet ;
0025 class RooAbsData ;
0026 class RooAbsGenContext ;
0027 class RooFitResult ;
0028 class RooPlot ;
0029 class RooRealVar ;
0030 class RooAbsMCStudyModule ;
0031 
0032 class RooMCStudy : public TNamed {
0033 public:
0034 
0035   RooMCStudy(const RooAbsPdf& model, const RooArgSet& observables,
0036         const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
0037              const RooCmdArg& arg3={}, const RooCmdArg& arg4={}, const RooCmdArg& arg5={},
0038              const RooCmdArg& arg6={}, const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
0039 
0040   ~RooMCStudy() override ;
0041 
0042   // Method to add study modules
0043   void addModule(RooAbsMCStudyModule& module) ;
0044 
0045 
0046   // Run methods
0047   bool generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char* asciiFilePat=nullptr) ;
0048   bool generate(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char* asciiFilePat=nullptr) ;
0049   bool fit(Int_t nSamples, const char* asciiFilePat) ;
0050   bool fit(Int_t nSamples, TList& dataSetList) ;
0051   bool addFitResult(const RooFitResult& fr) ;
0052 
0053   // Result accessors
0054   const RooArgSet* fitParams(Int_t sampleNum) const ;
0055   const RooFitResult* fitResult(Int_t sampleNum) const ;
0056         RooAbsData* genData(Int_t sampleNum) const ;
0057   const RooDataSet& fitParDataSet() ;
0058   /// Return dataset with generator parameters for each toy. When constraints are used these
0059   /// may generally not be the same as the fitted parameters.
0060   const RooDataSet* genParDataSet() const {
0061     return _genParData.get();
0062   }
0063 
0064   // Plot methods
0065   RooPlot* plotParamOn(RooPlot* frame, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
0066                        const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
0067                        const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
0068                        const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
0069   RooPlot* plotParam(const RooRealVar& param, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
0070                      const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
0071                      const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
0072                      const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
0073   RooPlot* plotParam(const char* paramName, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
0074                      const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
0075                      const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
0076                      const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
0077   RooPlot* plotNLL(const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
0078                      const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
0079                      const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
0080                      const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
0081   RooPlot* plotError(const RooRealVar& param, const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
0082                      const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
0083                      const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
0084                      const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
0085   RooPlot* plotPull(const RooRealVar& param, const RooCmdArg& arg1, const RooCmdArg& arg2={},
0086                      const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
0087                      const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
0088                      const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
0089 
0090 
0091   RooPlot* plotNLL(double lo, double hi, Int_t nBins=100) ;
0092   RooPlot* plotError(const RooRealVar& param, double lo, double hi, Int_t nbins=100) ;
0093   RooPlot* plotPull(const RooRealVar& param, double lo=-3.0, double hi=3.0, Int_t nbins=25, bool fitGauss=false) ;
0094 
0095 protected:
0096 
0097   friend class RooAbsMCStudyModule ;
0098 
0099   RooPlot* makeFrameAndPlotCmd(const RooRealVar& param, RooLinkedList& cmdList, bool symRange=false) const ;
0100 
0101   bool run(bool generate, bool fit, Int_t nSamples, Int_t nEvtPerSample, bool keepGenData, const char* asciiFilePat) ;
0102   bool fitSample(RooAbsData* genSample) ;
0103   RooFit::OwningPtr<RooFitResult> doFit(RooAbsData* genSample) ;
0104 
0105   void calcPulls() ;
0106 
0107   RooAbsData*       _genSample = nullptr;       ///< Currently generated sample
0108   RooAbsPdf*        _genModel = nullptr;        ///< Generator model
0109   std::unique_ptr<RooAbsGenContext> _genContext;      ///< Generator context
0110   RooArgSet        _genInitParams;   ///< List of original generator parameters
0111   RooArgSet        _genParams;       ///< List of actual generator parameters
0112   const RooDataSet* _genProtoData ;    ///< Generator prototype data set
0113   RooArgSet         _projDeps ;        ///< List of projected dependents in fit
0114 
0115   std::unique_ptr<RooAbsPdf>        _constrPdf;        ///< Constraints p.d.f
0116   std::unique_ptr<RooAbsGenContext> _constrGenContext; ///< Generator context for constraints p.d.f
0117 
0118   RooArgSet    _dependents ;    ///< List of dependents
0119   RooArgSet    _allDependents ; ///< List of generate + prototype dependents
0120   RooAbsPdf*   _fitModel ;      ///< Fit model
0121   RooArgSet   _fitInitParams; ///< List of initial values of fit parameters
0122   RooArgSet   _fitParams;     ///< List of actual fit parameters
0123   std::unique_ptr<RooRealVar>  _nllVar;
0124   std::unique_ptr<RooRealVar>  _ngenVar;
0125 
0126   TList       _genDataList ;    // List of generated data sample
0127   TList       _fitResList ;     // List of RooFitResult fit output objects
0128   std::unique_ptr<RooDataSet> _genParData;     // List of generated parameters of each sample
0129   std::unique_ptr<RooDataSet> _fitParData;     // Data set of fit parameters of each sample
0130   RooLinkedList _fitOptList ;   // Fit option command list
0131   bool      _extendedGen ;    // Add poisson term to number of events to generate?
0132   bool      _binGenData ;     // Bin data between generating and fitting
0133   double    _nExpGen ;        // Number of expected events to generate in extended mode
0134   bool      _randProto ;      // Randomize order of prototype data access
0135 
0136   bool      _canAddFitResults ; ///< Allow adding of external fit results?
0137   bool      _verboseGen       ; ///< Verbose generation?
0138   bool      _perExptGenParams = false; ///< Do generation parameter change per event?
0139   bool      _silence          ; ///< Silent running mode?
0140 
0141   std::list<RooAbsMCStudyModule*> _modList ; ///< List of additional study modules ;
0142 
0143   // Utilities for modules ;
0144   RooFit::OwningPtr<RooFitResult> refit(RooAbsData* genSample=nullptr) ;
0145   void resetFitParams() ;
0146   void RecursiveRemove(TObject *obj) override;
0147 
0148 private:
0149 
0150   RooMCStudy(const RooMCStudy&) ;
0151 
0152   ClassDefOverride(RooMCStudy,0) // A general purpose toy Monte Carlo study manager
0153 } ;
0154 
0155 
0156 #endif
0157