Logo ROOT  
Reference Guide
RooMinimizer.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * AL, Alfio Lazzaro, INFN Milan, alfio.lazzaro@mi.infn.it *
9  * *
10  * *
11  * Redistribution and use in source and binary forms, *
12  * with or without modification, are permitted according to the terms *
13  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
14  *****************************************************************************/
15 
16 #ifndef __ROOFIT_NOROOMINIMIZER
17 
18 #ifndef ROO_MINIMIZER
19 #define ROO_MINIMIZER
20 
21 #include "TObject.h"
22 #include "TStopwatch.h"
23 #include <fstream>
24 #include <vector>
25 #include <string>
26 #include <utility>
27 #include "TMatrixDSymfwd.h"
28 
29 #include "Fit/Fitter.h"
30 #include "RooMinimizerFcn.h"
31 
32 class RooAbsReal ;
33 class RooFitResult ;
34 class RooArgList ;
35 class RooRealVar ;
36 class RooArgSet ;
37 class TH2F ;
38 class RooPlot ;
39 
40 class RooMinimizer : public TObject {
41 public:
42 
43  RooMinimizer(RooAbsReal& function) ;
44  virtual ~RooMinimizer() ;
45 
46  enum Strategy { Speed=0, Balance=1, Robustness=2 } ;
48  void setStrategy(Int_t strat) ;
49  void setErrorLevel(Double_t level) ;
50  void setEps(Double_t eps) ;
51  void optimizeConst(Int_t flag) ;
53  void setOffsetting(Bool_t flag) ;
54  void setMaxIterations(Int_t n) ;
55  void setMaxFunctionCalls(Int_t n) ;
56 
57  RooFitResult* fit(const char* options) ;
58 
59  Int_t migrad() ;
60  Int_t hesse() ;
61  Int_t minos() ;
62  Int_t minos(const RooArgSet& minosParamList) ;
63  Int_t seek() ;
64  Int_t simplex() ;
65  Int_t improve() ;
66 
67  Int_t minimize(const char* type, const char* alg=0) ;
68 
69  RooFitResult* save(const char* name=0, const char* title=0) ;
70  RooPlot* contour(RooRealVar& var1, RooRealVar& var2,
71  Double_t n1=1, Double_t n2=2, Double_t n3=0,
72  Double_t n4=0, Double_t n5=0, Double_t n6=0, unsigned int npoints = 50) ;
73 
74  Int_t setPrintLevel(Int_t newLevel) ;
75  void setPrintEvalErrors(Int_t numEvalErrors) { fitterFcn()->SetPrintEvalErrors(numEvalErrors); }
76  void setVerbose(Bool_t flag=kTRUE) { _verbose = flag ; fitterFcn()->SetVerbose(flag); }
77  void setProfile(Bool_t flag=kTRUE) { _profile = flag ; }
78  Bool_t setLogFile(const char* logf=0) { return fitterFcn()->SetLogFile(logf); }
79 
80  void setMinimizerType(const char* type) ;
81 
82  static void cleanup() ;
83  static RooFitResult* lastMinuitFit(const RooArgList& varList=RooArgList()) ;
84 
85  void saveStatus(const char* label, Int_t status) { _statusHistory.push_back(std::pair<std::string,int>(label,status)) ; }
86 
87  Int_t evalCounter() const { return fitterFcn()->evalCounter() ; }
89 
91  const ROOT::Fit::Fitter* fitter() const ;
92 
93 protected:
94 
95  friend class RooAbsPdf ;
97 
98  void profileStart() ;
99  void profileStop() ;
100 
101  inline Int_t getNPar() const { return fitterFcn()->NDim() ; }
102  inline std::ofstream* logfile() { return fitterFcn()->GetLogFile(); }
103  inline Double_t& maxFCN() { return fitterFcn()->GetMaxFCN() ; }
104 
105  const RooMinimizerFcn* fitterFcn() const { return ( fitter()->GetFCN() ? ((RooMinimizerFcn*) fitter()->GetFCN()) : _fcn ) ; }
106  RooMinimizerFcn* fitterFcn() { return ( fitter()->GetFCN() ? ((RooMinimizerFcn*) fitter()->GetFCN()) : _fcn ) ; }
107 
108 private:
109 
115 
120 
122 
124  std::string _minimizerType;
125 
127 
128  std::vector<std::pair<std::string,int> > _statusHistory ;
129 
130  RooMinimizer(const RooMinimizer&) ;
131 
132  ClassDef(RooMinimizer,0) // RooFit interface to ROOT::Fit::Fitter
133 } ;
134 
135 
136 #endif
137 
138 #endif
RooMinimizer::Normal
@ Normal
Definition: RooMinimizer.h:47
RooMinimizer::saveStatus
void saveStatus(const char *label, Int_t status)
Definition: RooMinimizer.h:85
RooMinimizer::Speed
@ Speed
Definition: RooMinimizer.h:46
RooMinimizer::Reduced
@ Reduced
Definition: RooMinimizer.h:47
RooMinimizer::minos
Int_t minos()
Execute MINOS.
Definition: RooMinimizer.cxx:410
RooMinimizer::None
@ None
Definition: RooMinimizer.h:47
RooMinimizer::improve
Int_t improve()
Execute IMPROVE.
Definition: RooMinimizer.cxx:565
RooMinimizer::_statusHistory
std::vector< std::pair< std::string, int > > _statusHistory
Definition: RooMinimizer.h:128
n
const Int_t n
Definition: legend1.C:16
RooMinimizer::fitterFcn
const RooMinimizerFcn * fitterFcn() const
Definition: RooMinimizer.h:105
RooMinimizerFcn::SetPrintEvalErrors
void SetPrintEvalErrors(Int_t numEvalErrors)
Definition: RooMinimizerFcn.h:52
RooMinimizer::_timer
TStopwatch _timer
Definition: RooMinimizer.h:117
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooMinimizer::setEps
void setEps(Double_t eps)
Change MINUIT epsilon.
Definition: RooMinimizer.cxx:225
RooMinimizer::_verbose
Bool_t _verbose
Definition: RooMinimizer.h:116
RooMinimizer::save
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snaphot of current minimizer status.
Definition: RooMinimizer.cxx:635
RooMinimizer::~RooMinimizer
virtual ~RooMinimizer()
Destructor.
Definition: RooMinimizer.cxx:156
RooMinimizer::_optConst
Bool_t _optConst
Definition: RooMinimizer.h:112
RooMinimizer::zeroEvalCount
void zeroEvalCount()
Definition: RooMinimizer.h:88
TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
RooMinimizer::setErrorLevel
void setErrorLevel(Double_t level)
Set the level for MINUIT error analysis to the given value.
Definition: RooMinimizer.cxx:214
RooMinimizer::setMaxFunctionCalls
void setMaxFunctionCalls(Int_t n)
Change maximum number of likelihood function calss from MINUIT (RooMinimizer default 500 * #parameter...
Definition: RooMinimizer.cxx:200
RooMinimizerFcn::SetLogFile
Bool_t SetLogFile(const char *inLogfile)
Definition: RooMinimizerFcn.cxx:444
RooMinimizer::PrintLevel
PrintLevel
Definition: RooMinimizer.h:47
RooMinimizer::_printLevel
Int_t _printLevel
Definition: RooMinimizer.h:110
RooMinimizer::profileStop
void profileStop()
Stop profiling timer and report results of last session.
Definition: RooMinimizer.cxx:822
RooMinimizer::RooMinimizer
RooMinimizer(RooAbsReal &function)
Construct MINUIT interface to given function.
Definition: RooMinimizer.cxx:110
TStopwatch.h
RooMinimizerFcn::GetLogFile
std::ofstream * GetLogFile()
Definition: RooMinimizerFcn.h:54
RooMinimizer::_status
Int_t _status
Definition: RooMinimizer.h:111
RooMinimizer::Maximum
@ Maximum
Definition: RooMinimizer.h:47
RooArgList
Definition: RooArgList.h:21
RooMinimizer::Strategy
Strategy
Definition: RooMinimizer.h:46
RooMinimizer::setStrategy
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
Definition: RooMinimizer.cxx:176
RooMinimizer::contour
RooPlot * contour(RooRealVar &var1, RooRealVar &var2, Double_t n1=1, Double_t n2=2, Double_t n3=0, Double_t n4=0, Double_t n5=0, Double_t n6=0, unsigned int npoints=50)
Create and draw a TH2 with the error contours in the parameters var1 and var2.
Definition: RooMinimizer.cxx:710
RooMinimizer::setOffsetting
void setOffsetting(Bool_t flag)
Enable internal likelihood offsetting for enhanced numeric precision.
Definition: RooMinimizer.cxx:235
RooMinimizer::cleanup
static void cleanup()
Cleanup method called by atexit handler installed by RooSentinel to delete all global heap objects wh...
Definition: RooMinimizer.cxx:88
RooMinimizer::migrad
Int_t migrad()
Execute MIGRAD.
Definition: RooMinimizer.cxx:344
RooMinimizer::ExtraForProblem
@ ExtraForProblem
Definition: RooMinimizer.h:47
RooAbsReal
Definition: RooAbsReal.h:61
RooMinimizer::hesse
Int_t hesse()
Execute HESSE.
Definition: RooMinimizer.cxx:373
TMatrixTSym
Definition: TMatrixDSymfwd.h:22
RooMinimizer::lastMinuitFit
static RooFitResult * lastMinuitFit(const RooArgList &varList=RooArgList())
Definition: RooMinimizer.cxx:850
RooMinimizerFcn::GetMaxFCN
Double_t & GetMaxFCN()
Definition: RooMinimizerFcn.h:57
RooMinimizer::setMaxIterations
void setMaxIterations(Int_t n)
Change maximum number of MINUIT iterations (RooMinimizer default 500 * #parameters)
Definition: RooMinimizer.cxx:188
bool
RooFitResult
Definition: RooFitResult.h:40
RooMinimizer::evalCounter
Int_t evalCounter() const
Definition: RooMinimizer.h:87
RooMinimizer::fit
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
Definition: RooMinimizer.cxx:283
RooMinimizerFcn
Definition: RooMinimizerFcn.h:34
RooMinimizer::_theFitter
static ROOT::Fit::Fitter * _theFitter
Definition: RooMinimizer.h:126
RooMinimizer::applyCovarianceMatrix
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
Definition: RooMinimizer.cxx:841
ROOT::Fit::Fitter
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
RooMinimizer::_cumulTimer
TStopwatch _cumulTimer
Definition: RooMinimizer.h:118
RooMinimizerFcn::evalCounter
Int_t evalCounter() const
Definition: RooMinimizerFcn.h:65
TMatrixDSymfwd.h
RooMinimizer::setPrintEvalErrors
void setPrintEvalErrors(Int_t numEvalErrors)
Definition: RooMinimizer.h:75
RooMinimizer::getNPar
Int_t getNPar() const
Definition: RooMinimizer.h:101
RooMinimizerFcn::SetEvalErrorWall
void SetEvalErrorWall(Bool_t flag)
Definition: RooMinimizerFcn.h:51
RooPlot
Definition: RooPlot.h:44
RooMinimizer::_extV
TMatrixDSym * _extV
Definition: RooMinimizer.h:121
RooMinimizer::setMinimizerType
void setMinimizerType(const char *type)
Choose the minimiser algorithm.
Definition: RooMinimizer.cxx:245
RooMinimizer::Balance
@ Balance
Definition: RooMinimizer.h:46
RooMinimizerFcn.h
RooMinimizerFcn::zeroEvalCount
void zeroEvalCount()
Definition: RooMinimizerFcn.h:66
RooMinimizer::setLogFile
Bool_t setLogFile(const char *logf=0)
Definition: RooMinimizer.h:78
RooMinimizer::setProfile
void setProfile(Bool_t flag=kTRUE)
Definition: RooMinimizer.h:77
RooMinimizer::_profileStart
Bool_t _profileStart
Definition: RooMinimizer.h:119
RooMinimizer::maxFCN
Double_t & maxFCN()
Definition: RooMinimizer.h:103
RooMinimizer::_minimizerType
std::string _minimizerType
Definition: RooMinimizer.h:124
Fitter.h
RooMinimizer::minimize
Int_t minimize(const char *type, const char *alg=0)
Minimise the function passed in the constructor.
Definition: RooMinimizer.cxx:312
Double_t
double Double_t
Definition: RtypesCore.h:59
RooMinimizer::seek
Int_t seek()
Execute SEEK.
Definition: RooMinimizer.cxx:507
TObject.h
TStopwatch
Definition: TStopwatch.h:28
TObject
Definition: TObject.h:37
RooMinimizer::fitterFcn
RooMinimizerFcn * fitterFcn()
Definition: RooMinimizer.h:106
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
RooMinimizerFcn::NDim
virtual unsigned int NDim() const
Definition: RooMinimizerFcn.h:44
RooMinimizer::_func
RooAbsReal * _func
Definition: RooMinimizer.h:114
RooAbsPdf
Definition: RooAbsPdf.h:40
type
int type
Definition: TGX11.cxx:121
RooMinimizer::Robustness
@ Robustness
Definition: RooMinimizer.h:46
RooMinimizer::simplex
Int_t simplex()
Execute SIMPLEX.
Definition: RooMinimizer.cxx:536
RooRealVar
Definition: RooRealVar.h:36
RooMinimizer::_profile
Bool_t _profile
Definition: RooMinimizer.h:113
RooMinimizer::logfile
std::ofstream * logfile()
Definition: RooMinimizer.h:102
RooMinimizer::_fcn
RooMinimizerFcn * _fcn
Definition: RooMinimizer.h:123
RooMinimizer
Definition: RooMinimizer.h:40
RooMinimizer::setVerbose
void setVerbose(Bool_t flag=kTRUE)
Definition: RooMinimizer.h:76
RooMinimizer::setEvalErrorWall
void setEvalErrorWall(Bool_t flag)
Definition: RooMinimizer.h:52
RooMinimizer::optimizeConst
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
Definition: RooMinimizer.cxx:603
RooMinimizer::profileStart
void profileStart()
Start profiling timer.
Definition: RooMinimizer.cxx:809
RooMinimizer::setPrintLevel
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
Definition: RooMinimizer.cxx:591
RooMinimizer::fitter
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
Definition: RooMinimizer.cxx:256
RooArgSet
Definition: RooArgSet.h:28
int
RooMinimizerFcn::SetVerbose
void SetVerbose(Bool_t flag=kTRUE)
Definition: RooMinimizerFcn.h:55