Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * PB, Patrick Bos, NL eScience Center, p.bos@esciencecenter.nl *
10 * *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17#ifndef ROO_MINIMIZER
18#define ROO_MINIMIZER
19
20#include <memory> // shared_ptr, unique_ptr
21
22#include "TObject.h"
23#include "TStopwatch.h"
24#include <fstream>
25#include <vector>
26#include <string>
27#include <utility>
28#include "TMatrixDSymfwd.h"
29
30#include "RooArgList.h" // cannot just use forward decl due to default argument in lastMinuitFit
31
32#include <RooAbsMinimizerFcn.h>
36
37#include "RooSentinel.h"
38#include "RooMsgService.h"
39
40#include "Fit/Fitter.h"
41#include <stdexcept> // logic_error
42
43class RooAbsReal ;
44class RooFitResult ;
45class RooArgList ;
46class RooRealVar ;
47class RooArgSet ;
48class TH2F ;
49class RooPlot ;
50
51class RooMinimizer : public TObject {
52public:
54
55 explicit RooMinimizer(RooAbsReal &function, FcnMode fcnMode = FcnMode::classic);
56 explicit RooMinimizer(std::shared_ptr<RooFit::TestStatistics::RooAbsL> likelihood,
61
62 ~RooMinimizer() override;
63
64 enum Strategy { Speed=0, Balance=1, Robustness=2 } ;
66 void setStrategy(Int_t strat) ;
67 void setErrorLevel(Double_t level) ;
68 void setEps(Double_t eps) ;
69 void optimizeConst(Int_t flag) ;
71 /// \copydoc RooMinimizerFcn::SetRecoverFromNaNStrength()
72 void setRecoverFromNaNStrength(double strength) { fitterFcn()->SetRecoverFromNaNStrength(strength); }
73 void setOffsetting(Bool_t flag) ;
76
77 RooFitResult* fit(const char* options) R__DEPRECATED(6,28,
78 "using RooMinimizer::fit() with string-based options is deprecated. Please use RooAbsPdf::fitTo() instead.");
79
80 Int_t migrad() ;
81 Int_t hesse() ;
82 Int_t minos() ;
83 Int_t minos(const RooArgSet& minosParamList) ;
84 Int_t seek() ;
85 Int_t simplex() ;
86 Int_t improve() ;
87
88 Int_t minimize(const char* type, const char* alg=0) ;
89
90 RooFitResult* save(const char* name=0, const char* title=0) ;
91 RooPlot* contour(RooRealVar& var1, RooRealVar& var2,
92 Double_t n1=1, Double_t n2=2, Double_t n3=0,
93 Double_t n4=0, Double_t n5=0, Double_t n6=0, unsigned int npoints = 50) ;
94
95 Int_t setPrintLevel(Int_t newLevel) ;
96 void setPrintEvalErrors(Int_t numEvalErrors) { fitterFcn()->SetPrintEvalErrors(numEvalErrors); }
97 void setVerbose(Bool_t flag=kTRUE) { _verbose = flag ; fitterFcn()->SetVerbose(flag); }
98 void setProfile(Bool_t flag=kTRUE) { _profile = flag ; }
99 Bool_t setLogFile(const char* logf=0) { return fitterFcn()->SetLogFile(logf); }
100
101 Int_t getPrintLevel() const;
102
103 void setMinimizerType(const char* type) ;
104
105 static void cleanup() ;
106 static RooFitResult* lastMinuitFit(const RooArgList& varList=RooArgList()) ;
107
108 void saveStatus(const char* label, Int_t status) { _statusHistory.push_back(std::pair<std::string,int>(label,status)) ; }
109
110 Int_t evalCounter() const { return fitterFcn()->evalCounter() ; }
112
114 const ROOT::Fit::Fitter* fitter() const ;
115
118
119 inline Int_t getNPar() const { return fitterFcn()->getNDim() ; }
120
121protected:
122
123 friend class RooAbsPdf ;
125
126 void profileStart() ;
127 void profileStop() ;
128
129 inline std::ofstream* logfile() { return fitterFcn()->GetLogFile(); }
130 inline Double_t& maxFCN() { return fitterFcn()->GetMaxFCN() ; }
131
132 const RooAbsMinimizerFcn *fitterFcn() const;
134
135 bool fitFcn() const;
136
137private:
138 // constructor helper functions
140 void initMinimizerFcnDependentPart(double defaultErrorLevel);
141
145
150
152
154 std::string _minimizerType = "Minuit";
156
158
159 std::vector<std::pair<std::string,int> > _statusHistory ;
160
162
163 ClassDefOverride(RooMinimizer,0) // RooFit interface to ROOT::Fit::Fitter
164} ;
165
166#endif
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:516
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDefOverride(name, id)
Definition Rtypes.h:329
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
Fitter class, entry point for performing all type of fits.
Definition Fitter.h:77
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:62
std::ofstream * GetLogFile()
void SetPrintEvalErrors(Int_t numEvalErrors)
void SetEvalErrorWall(Bool_t flag)
void SetVerbose(Bool_t flag=kTRUE)
unsigned int getNDim() const
Bool_t SetLogFile(const char *inLogfile)
Change the file name for logging of a RooMinimizer of all MINUIT steppings through the parameter spac...
void SetRecoverFromNaNStrength(double strength)
Try to recover from invalid function values.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
void setRecoverFromNaNStrength(double strength)
Try to recover from invalid function values.
std::vector< std::pair< std::string, int > > _statusHistory
void initMinimizerFirstPart()
Initialize the part of the minimizer that is independent of the function to be minimized.
std::ofstream * logfile()
Int_t hesse()
Execute HESSE.
Double_t & maxFCN()
void setEvalErrorWall(Bool_t flag)
void setMaxIterations(Int_t n)
Change maximum number of MINUIT iterations (RooMinimizer default 500 * #parameters)
void zeroEvalCount()
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snapshot of current minimizer status.
void setMinimizerType(const char *type)
Choose the minimizer algorithm.
void saveStatus(const char *label, Int_t status)
Int_t improve()
Execute IMPROVE.
FcnMode _fcnMode
void profileStart()
Start profiling timer.
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.
Int_t migrad()
Execute MIGRAD.
Int_t minimize(const char *type, const char *alg=0)
Minimise the function passed in the constructor.
void initMinimizerFcnDependentPart(double defaultErrorLevel)
Initialize the part of the minimizer that is dependent on the function to be minimized.
RooFitResult * fit(const char *options) R__DEPRECATED(6
Parse traditional RooAbsPdf::fitTo driver options.
void profileStop()
Stop profiling timer and report results of last session.
ROOT::Math::IMultiGenFunction * getFitterMultiGenFcn() const
static RooFitResult * lastMinuitFit(const RooArgList &varList=RooArgList())
const RooAbsMinimizerFcn * fitterFcn() const
void setOffsetting(Bool_t flag)
Enable internal likelihood offsetting for enhanced numeric precision.
TMatrixDSym * _extV
Int_t seek()
Execute SEEK.
Bool_t setLogFile(const char *logf=0)
void setProfile(Bool_t flag=kTRUE)
void setEps(Double_t eps)
Change MINUIT epsilon.
void setErrorLevel(Double_t level)
Set the level for MINUIT error analysis to the given value.
RooMinimizer(const RooMinimizer &)
static ROOT::Fit::Fitter * _theFitter
static void cleanup()
Cleanup method called by atexit handler installed by RooSentinel to delete all global heap objects wh...
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
TStopwatch _timer
void setMaxFunctionCalls(Int_t n)
Change maximum number of likelihood function calss from MINUIT (RooMinimizer default 500 * #parameter...
Int_t evalCounter() const
Int_t minos()
Execute MINOS.
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
bool fitFcn() const
~RooMinimizer() override
Destructor.
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
ROOT::Math::IMultiGenFunction * getMultiGenFcn() const
Int_t simplex()
Execute SIMPLEX.
Bool_t _profileStart
Int_t getPrintLevel() const
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
std::string _minimizerType
void setPrintEvalErrors(Int_t numEvalErrors)
TStopwatch _cumulTimer
RooAbsMinimizerFcn * _fcn
void setVerbose(Bool_t flag=kTRUE)
Int_t getNPar() const
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:44
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:251
Mother of all ROOT objects.
Definition TObject.h:41
Stopwatch class.
Definition TStopwatch.h:28
const Int_t n
Definition legend1.C:16