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  /// \copydoc RooMinimizerFcn::SetRecoverFromNaNStrength()
54  void setRecoverFromNaNStrength(double strength) { fitterFcn()->SetRecoverFromNaNStrength(strength); }
55  void setOffsetting(Bool_t flag) ;
56  void setMaxIterations(Int_t n) ;
58 
59  RooFitResult* fit(const char* options) ;
60 
61  Int_t migrad() ;
62  Int_t hesse() ;
63  Int_t minos() ;
64  Int_t minos(const RooArgSet& minosParamList) ;
65  Int_t seek() ;
66  Int_t simplex() ;
67  Int_t improve() ;
68 
69  Int_t minimize(const char* type, const char* alg=0) ;
70 
71  RooFitResult* save(const char* name=0, const char* title=0) ;
72  RooPlot* contour(RooRealVar& var1, RooRealVar& var2,
73  Double_t n1=1, Double_t n2=2, Double_t n3=0,
74  Double_t n4=0, Double_t n5=0, Double_t n6=0, unsigned int npoints = 50) ;
75 
76  Int_t setPrintLevel(Int_t newLevel) ;
77  void setPrintEvalErrors(Int_t numEvalErrors) { fitterFcn()->SetPrintEvalErrors(numEvalErrors); }
78  void setVerbose(Bool_t flag=kTRUE) { _verbose = flag ; fitterFcn()->SetVerbose(flag); }
79  void setProfile(Bool_t flag=kTRUE) { _profile = flag ; }
80  Bool_t setLogFile(const char* logf=0) { return fitterFcn()->SetLogFile(logf); }
81 
82  void setMinimizerType(const char* type) ;
83 
84  static void cleanup() ;
85  static RooFitResult* lastMinuitFit(const RooArgList& varList=RooArgList()) ;
86 
87  void saveStatus(const char* label, Int_t status) { _statusHistory.push_back(std::pair<std::string,int>(label,status)) ; }
88 
89  Int_t evalCounter() const { return fitterFcn()->evalCounter() ; }
91 
93  const ROOT::Fit::Fitter* fitter() const ;
94 
95 protected:
96 
97  friend class RooAbsPdf ;
99 
100  void profileStart() ;
101  void profileStop() ;
102 
103  inline Int_t getNPar() const { return fitterFcn()->NDim() ; }
104  inline std::ofstream* logfile() { return fitterFcn()->GetLogFile(); }
105  inline Double_t& maxFCN() { return fitterFcn()->GetMaxFCN() ; }
106 
107  const RooMinimizerFcn* fitterFcn() const { return ( fitter()->GetFCN() ? ((RooMinimizerFcn*) fitter()->GetFCN()) : _fcn ) ; }
108  RooMinimizerFcn* fitterFcn() { return ( fitter()->GetFCN() ? ((RooMinimizerFcn*) fitter()->GetFCN()) : _fcn ) ; }
109 
110 private:
111 
117 
122 
124 
126  std::string _minimizerType;
127 
129 
130  std::vector<std::pair<std::string,int> > _statusHistory ;
131 
133 
134  ClassDef(RooMinimizer,0) // RooFit interface to ROOT::Fit::Fitter
135 } ;
136 
137 
138 #endif
139 
140 #endif
RooMinimizer::Normal
@ Normal
Definition: RooMinimizer.h:47
RooMinimizer::saveStatus
void saveStatus(const char *label, Int_t status)
Definition: RooMinimizer.h:87
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:130
n
const Int_t n
Definition: legend1.C:16
RooMinimizer::fitterFcn
const RooMinimizerFcn * fitterFcn() const
Definition: RooMinimizer.h:107
RooMinimizerFcn::SetPrintEvalErrors
void SetPrintEvalErrors(Int_t numEvalErrors)
Definition: RooMinimizerFcn.h:57
RooMinimizer::_timer
TStopwatch _timer
Definition: RooMinimizer.h:119
RooMinimizer::fitter
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
Definition: RooMinimizer.cxx:256
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:118
RooMinimizer::save
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snapshot 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:114
RooMinimizer::zeroEvalCount
void zeroEvalCount()
Definition: RooMinimizer.h:90
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)
Change the file name for logging of a RooMinimizer of all MINUIT steppings through the parameter spac...
Definition: RooMinimizerFcn.cxx:414
RooMinimizer::PrintLevel
PrintLevel
Definition: RooMinimizer.h:47
RooMinimizer::_printLevel
Int_t _printLevel
Definition: RooMinimizer.h:112
RooMinimizer::RooMinimizer
RooMinimizer(const RooMinimizer &)
RooMinimizer::profileStop
void profileStop()
Stop profiling timer and report results of last session.
Definition: RooMinimizer.cxx:829
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:59
RooMinimizer::_status
Int_t _status
Definition: RooMinimizer.h:113
RooMinimizer::Maximum
@ Maximum
Definition: RooMinimizer.h:47
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
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:717
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
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
RooMinimizer::hesse
Int_t hesse()
Execute HESSE.
Definition: RooMinimizer.cxx:373
TMatrixTSym< Double_t >
RooMinimizer::lastMinuitFit
static RooFitResult * lastMinuitFit(const RooArgList &varList=RooArgList())
Definition: RooMinimizer.cxx:857
RooMinimizerFcn::GetMaxFCN
Double_t & GetMaxFCN()
Definition: RooMinimizerFcn.h:62
RooMinimizer::setMaxIterations
void setMaxIterations(Int_t n)
Change maximum number of MINUIT iterations (RooMinimizer default 500 * #parameters)
Definition: RooMinimizer.cxx:188
bool
RooFitResult
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
RooMinimizer::evalCounter
Int_t evalCounter() const
Definition: RooMinimizer.h:89
RooMinimizer::setRecoverFromNaNStrength
void setRecoverFromNaNStrength(double strength)
Try to recover from invalid function values.
Definition: RooMinimizer.h:54
RooMinimizer::fit
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
Definition: RooMinimizer.cxx:283
RooMinimizerFcn
RooMinimizerFcn is an interface to the ROOT::Math::IBaseFunctionMultiDim, a function that ROOT's mini...
Definition: RooMinimizerFcn.h:33
RooMinimizerFcn::SetRecoverFromNaNStrength
void SetRecoverFromNaNStrength(double strength)
Try to recover from invalid function values.
Definition: RooMinimizerFcn.h:56
RooMinimizer::_theFitter
static ROOT::Fit::Fitter * _theFitter
Definition: RooMinimizer.h:128
RooMinimizer::applyCovarianceMatrix
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
Definition: RooMinimizer.cxx:848
ROOT::Fit::Fitter
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
RooMinimizer::_cumulTimer
TStopwatch _cumulTimer
Definition: RooMinimizer.h:120
RooMinimizerFcn::evalCounter
Int_t evalCounter() const
Definition: RooMinimizerFcn.h:70
TMatrixDSymfwd.h
RooMinimizer::setPrintEvalErrors
void setPrintEvalErrors(Int_t numEvalErrors)
Definition: RooMinimizer.h:77
RooMinimizer::getNPar
Int_t getNPar() const
Definition: RooMinimizer.h:103
RooMinimizerFcn::SetEvalErrorWall
void SetEvalErrorWall(Bool_t flag)
Definition: RooMinimizerFcn.h:50
RooPlot
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
RooMinimizer::_extV
TMatrixDSym * _extV
Definition: RooMinimizer.h:123
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:71
RooMinimizer::setLogFile
Bool_t setLogFile(const char *logf=0)
Definition: RooMinimizer.h:80
RooMinimizer::setProfile
void setProfile(Bool_t flag=kTRUE)
Definition: RooMinimizer.h:79
RooMinimizer::_profileStart
Bool_t _profileStart
Definition: RooMinimizer.h:121
RooMinimizer::maxFCN
Double_t & maxFCN()
Definition: RooMinimizer.h:105
RooMinimizer::_minimizerType
std::string _minimizerType
Definition: RooMinimizer.h:126
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
Stopwatch class.
Definition: TStopwatch.h:28
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
RooMinimizer::fitterFcn
RooMinimizerFcn * fitterFcn()
Definition: RooMinimizer.h:108
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
RooMinimizerFcn::NDim
virtual unsigned int NDim() const
Retrieve the dimension of the function.
Definition: RooMinimizerFcn.h:43
RooMinimizer::_func
RooAbsReal * _func
Definition: RooMinimizer.h:116
RooAbsPdf
Definition: RooAbsPdf.h:43
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
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:39
RooMinimizer::_profile
Bool_t _profile
Definition: RooMinimizer.h:115
RooMinimizer::logfile
std::ofstream * logfile()
Definition: RooMinimizer.h:104
RooMinimizer::_fcn
RooMinimizerFcn * _fcn
Definition: RooMinimizer.h:125
RooMinimizer
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:40
RooMinimizer::setVerbose
void setVerbose(Bool_t flag=kTRUE)
Definition: RooMinimizer.h:78
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:816
RooMinimizer::setPrintLevel
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
Definition: RooMinimizer.cxx:591
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
int
RooMinimizerFcn::SetVerbose
void SetVerbose(Bool_t flag=kTRUE)
Definition: RooMinimizerFcn.h:60