ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooMCStudy.h,v 1.18 2007/05/11 10:14:56 verkerke Exp $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_MC_STUDY
#define ROO_MC_STUDY

#include "TList.h"
#include "TNamed.h"
#include "RooArgSet.h"
#include <list>
class RooAbsPdf;
class RooDataSet ;
class RooAbsData ;
class RooAbsGenContext ;
class RooFitResult ;
class RooPlot ;
class RooRealVar ;
class RooAbsMCStudyModule ;

class RooMCStudy : public TNamed {
public:

  RooMCStudy(const RooAbsPdf& model, const RooArgSet& observables, 
	     const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
             const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(), const RooCmdArg& arg5=RooCmdArg::none(),
             const RooCmdArg& arg6=RooCmdArg::none(), const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
	
  RooMCStudy(const RooAbsPdf& genModel, const RooAbsPdf& fitModel, 
	     const RooArgSet& dependents, const char* genOptions="",
	     const char* fitOptions="", const RooDataSet* genProtoData=0,
	     const RooArgSet& projDeps=RooArgSet()) ;
  virtual ~RooMCStudy() ;
  
  // Method to add study modules
  void addModule(RooAbsMCStudyModule& module) ;


  // Run methods
  Bool_t generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char* asciiFilePat=0) ;
  Bool_t generate(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char* asciiFilePat=0) ;
  Bool_t fit(Int_t nSamples, const char* asciiFilePat) ;
  Bool_t fit(Int_t nSamples, TList& dataSetList) ;
  Bool_t addFitResult(const RooFitResult& fr) ;

  // Result accessors
  const RooArgSet* fitParams(Int_t sampleNum) const ;
  const RooFitResult* fitResult(Int_t sampleNum) const ;
  const RooAbsData* genData(Int_t sampleNum) const ;
  const RooDataSet& fitParDataSet() ;
  const RooDataSet* genParDataSet() const { 
    // Return dataset with generator parameters for each toy. When constraints are used these
    // may generally not be the same
    return _genParData ; 
  }

  // Plot methods
  RooPlot* plotParamOn(RooPlot* frame, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
                       const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
                       const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
                       const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
  RooPlot* plotParam(const RooRealVar& param, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
                     const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
                     const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
                     const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
  RooPlot* plotParam(const char* paramName, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
                     const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
                     const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
                     const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
  RooPlot* plotNLL(const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
                     const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
                     const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
                     const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
  RooPlot* plotError(const RooRealVar& param, const RooCmdArg& arg1=RooCmdArg::none(), const RooCmdArg& arg2=RooCmdArg::none(),
                     const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
                     const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
                     const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;
  RooPlot* plotPull(const RooRealVar& param, const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg::none(),
                     const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(),
                     const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(),
                     const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) ;


  RooPlot* plotNLL(Double_t lo, Double_t hi, Int_t nBins=100) ;
  RooPlot* plotError(const RooRealVar& param, Double_t lo, Double_t hi, Int_t nbins=100) ;
  RooPlot* plotPull(const RooRealVar& param, Double_t lo=-3.0, Double_t hi=3.0, Int_t nbins=25, Bool_t fitGauss=kFALSE) ;
    
protected:

  friend class RooAbsMCStudyModule ;

  RooPlot* makeFrameAndPlotCmd(const RooRealVar& param, RooLinkedList& cmdList, Bool_t symRange=kFALSE) const ;

  Bool_t run(Bool_t generate, Bool_t fit, Int_t nSamples, Int_t nEvtPerSample, Bool_t keepGenData, const char* asciiFilePat) ;
  Bool_t fitSample(RooAbsData* genSample) ;
  RooFitResult* doFit(RooAbsData* genSample) ;	

  void calcPulls() ;
    
  RooAbsData*       _genSample ;       // Currently generated sample 
  RooAbsPdf*        _genModel ;        // Generator model 
  RooAbsGenContext* _genContext ;      // Generator context 
  RooArgSet*        _genInitParams ;   // List of originalgenerator parameters
  RooArgSet*        _genParams ;       // List of actual generator parameters
  const RooDataSet* _genProtoData ;    // Generator prototype data set
  RooArgSet         _projDeps ;        // List of projected dependents in fit

  RooAbsPdf*        _constrPdf ;        // Constraints p.d.f
  RooAbsGenContext* _constrGenContext ; // Generator context for constraints p.d.f

  RooArgSet    _dependents ;    // List of dependents 
  RooArgSet    _allDependents ; // List of generate + prototype dependents
  RooAbsPdf*   _fitModel ;      // Fit model 
  RooArgSet*   _fitInitParams ; // List of initial values of fit parameters
  RooArgSet*   _fitParams ;     // List of actual fit parameters
  RooRealVar*  _nllVar ;
  RooRealVar*  _ngenVar ; 
  
  TList       _genDataList ;    // List of generated data sample
  TList       _fitResList ;     // List of RooFitResult fit output objects
  RooDataSet* _genParData ;     // List of of generated parameters of each sample
  RooDataSet* _fitParData ;     // Data set of fit parameters of each sample
  TString     _fitOptions ;     // Fit options string
  RooLinkedList _fitOptList ;   // Fit option command list 
  Bool_t      _extendedGen ;    // Add poisson term to number of events to generate?
  Bool_t      _binGenData ;     // Bin data between generating and fitting
  Double_t    _nExpGen ;        // Number of expected events to generate in extended mode
  Bool_t      _randProto ;      // Randomize order of prototype data access

  Bool_t      _canAddFitResults ; // Allow adding of external fit results?
  Bool_t      _verboseGen       ; // Verbose generation?
  Bool_t      _perExptGenParams ; // Do generation parameter change per event?
  Bool_t      _silence          ; // Silent running mode?

  std::list<RooAbsMCStudyModule*> _modList ; // List of additional study modules ;

  // Utilities for modules ;
  RooFitResult* refit(RooAbsData* genSample=0) ;
  void resetFitParams() ;

private:

  RooMCStudy(const RooMCStudy&) ;
	
  ClassDef(RooMCStudy,0) // A general purpose toy Monte Carlo study manager
} ;


#endif

 RooMCStudy.h:1
 RooMCStudy.h:2
 RooMCStudy.h:3
 RooMCStudy.h:4
 RooMCStudy.h:5
 RooMCStudy.h:6
 RooMCStudy.h:7
 RooMCStudy.h:8
 RooMCStudy.h:9
 RooMCStudy.h:10
 RooMCStudy.h:11
 RooMCStudy.h:12
 RooMCStudy.h:13
 RooMCStudy.h:14
 RooMCStudy.h:15
 RooMCStudy.h:16
 RooMCStudy.h:17
 RooMCStudy.h:18
 RooMCStudy.h:19
 RooMCStudy.h:20
 RooMCStudy.h:21
 RooMCStudy.h:22
 RooMCStudy.h:23
 RooMCStudy.h:24
 RooMCStudy.h:25
 RooMCStudy.h:26
 RooMCStudy.h:27
 RooMCStudy.h:28
 RooMCStudy.h:29
 RooMCStudy.h:30
 RooMCStudy.h:31
 RooMCStudy.h:32
 RooMCStudy.h:33
 RooMCStudy.h:34
 RooMCStudy.h:35
 RooMCStudy.h:36
 RooMCStudy.h:37
 RooMCStudy.h:38
 RooMCStudy.h:39
 RooMCStudy.h:40
 RooMCStudy.h:41
 RooMCStudy.h:42
 RooMCStudy.h:43
 RooMCStudy.h:44
 RooMCStudy.h:45
 RooMCStudy.h:46
 RooMCStudy.h:47
 RooMCStudy.h:48
 RooMCStudy.h:49
 RooMCStudy.h:50
 RooMCStudy.h:51
 RooMCStudy.h:52
 RooMCStudy.h:53
 RooMCStudy.h:54
 RooMCStudy.h:55
 RooMCStudy.h:56
 RooMCStudy.h:57
 RooMCStudy.h:58
 RooMCStudy.h:59
 RooMCStudy.h:60
 RooMCStudy.h:61
 RooMCStudy.h:62
 RooMCStudy.h:63
 RooMCStudy.h:64
 RooMCStudy.h:65
 RooMCStudy.h:66
 RooMCStudy.h:67
 RooMCStudy.h:68
 RooMCStudy.h:69
 RooMCStudy.h:70
 RooMCStudy.h:71
 RooMCStudy.h:72
 RooMCStudy.h:73
 RooMCStudy.h:74
 RooMCStudy.h:75
 RooMCStudy.h:76
 RooMCStudy.h:77
 RooMCStudy.h:78
 RooMCStudy.h:79
 RooMCStudy.h:80
 RooMCStudy.h:81
 RooMCStudy.h:82
 RooMCStudy.h:83
 RooMCStudy.h:84
 RooMCStudy.h:85
 RooMCStudy.h:86
 RooMCStudy.h:87
 RooMCStudy.h:88
 RooMCStudy.h:89
 RooMCStudy.h:90
 RooMCStudy.h:91
 RooMCStudy.h:92
 RooMCStudy.h:93
 RooMCStudy.h:94
 RooMCStudy.h:95
 RooMCStudy.h:96
 RooMCStudy.h:97
 RooMCStudy.h:98
 RooMCStudy.h:99
 RooMCStudy.h:100
 RooMCStudy.h:101
 RooMCStudy.h:102
 RooMCStudy.h:103
 RooMCStudy.h:104
 RooMCStudy.h:105
 RooMCStudy.h:106
 RooMCStudy.h:107
 RooMCStudy.h:108
 RooMCStudy.h:109
 RooMCStudy.h:110
 RooMCStudy.h:111
 RooMCStudy.h:112
 RooMCStudy.h:113
 RooMCStudy.h:114
 RooMCStudy.h:115
 RooMCStudy.h:116
 RooMCStudy.h:117
 RooMCStudy.h:118
 RooMCStudy.h:119
 RooMCStudy.h:120
 RooMCStudy.h:121
 RooMCStudy.h:122
 RooMCStudy.h:123
 RooMCStudy.h:124
 RooMCStudy.h:125
 RooMCStudy.h:126
 RooMCStudy.h:127
 RooMCStudy.h:128
 RooMCStudy.h:129
 RooMCStudy.h:130
 RooMCStudy.h:131
 RooMCStudy.h:132
 RooMCStudy.h:133
 RooMCStudy.h:134
 RooMCStudy.h:135
 RooMCStudy.h:136
 RooMCStudy.h:137
 RooMCStudy.h:138
 RooMCStudy.h:139
 RooMCStudy.h:140
 RooMCStudy.h:141
 RooMCStudy.h:142
 RooMCStudy.h:143
 RooMCStudy.h:144
 RooMCStudy.h:145
 RooMCStudy.h:146
 RooMCStudy.h:147
 RooMCStudy.h:148
 RooMCStudy.h:149
 RooMCStudy.h:150
 RooMCStudy.h:151
 RooMCStudy.h:152
 RooMCStudy.h:153
 RooMCStudy.h:154
 RooMCStudy.h:155
 RooMCStudy.h:156
 RooMCStudy.h:157
 RooMCStudy.h:158
 RooMCStudy.h:159
 RooMCStudy.h:160
 RooMCStudy.h:161