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