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 * 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
23
24#include <Fit/Fitter.h>
25#include <TStopwatch.h>
26#include <TMatrixDSymfwd.h>
27
28#include <fstream>
29#include <memory> // shared_ptr, unique_ptr
30#include <string>
31#include <utility>
32#include <vector>
33
35class RooAbsReal ;
36class RooFitResult ;
37class RooArgList ;
38class RooRealVar ;
39class RooArgSet ;
40class RooPlot ;
41
42class RooMinimizer : public TObject {
43public:
44 enum class FcnMode { classic, gradient, generic_wrapper };
45
47 explicit RooMinimizer(std::shared_ptr<RooFit::TestStatistics::RooAbsL> likelihood,
52
53 ~RooMinimizer() override;
54
55 enum Strategy { Speed=0, Balance=1, Robustness=2 } ;
57 void setStrategy(int strat) ;
58 void setErrorLevel(double level) ;
59 void setEps(double eps) ;
60 void optimizeConst(int flag) ;
61 void setEvalErrorWall(bool flag) ;
62 void setRecoverFromNaNStrength(double strength) ;
63 void setOffsetting(bool flag) ;
64 void setMaxIterations(int n) ;
65 void setMaxFunctionCalls(int n) ;
66
67 int migrad() ;
68 int hesse() ;
69 int minos() ;
70 int minos(const RooArgSet& minosParamList) ;
71 int seek() ;
72 int simplex() ;
73 int improve() ;
74
75 int minimize(const char* type, const char* alg=0) ;
76
77 RooFitResult* save(const char* name=0, const char* title=0) ;
79 double n1=1, double n2=2, double n3=0,
80 double n4=0, double n5=0, double n6=0, unsigned int npoints = 50) ;
81
82 int setPrintLevel(int newLevel) ;
83 void setPrintEvalErrors(int numEvalErrors) ;
84 void setVerbose(bool flag=true) ;
85 void setProfile(bool flag=true) { _profile = flag ; }
86 bool setLogFile(const char* logf=nullptr) ;
87
88 int getPrintLevel() const { return _printLevel; }
89
90 void setMinimizerType(const char* type) ;
91
92 static void cleanup() ;
93 static RooFitResult* lastMinuitFit() ;
94 static RooFitResult* lastMinuitFit(const RooArgList& varList) ;
95
96 void saveStatus(const char* label, int status) { _statusHistory.push_back(std::pair<std::string,int>(label,status)) ; }
97
98 int evalCounter() const ;
99 void zeroEvalCount() ;
100
102 const ROOT::Fit::Fitter* fitter() const ;
103
105
106 int getNPar() const ;
107
108 void applyCovarianceMatrix(TMatrixDSym const& V) ;
109
110private:
111
112 void profileStart() ;
113 void profileStop() ;
114
115 std::ofstream* logfile() ;
116 double& maxFCN() ;
117
118 bool fitFcn() const;
119
120 // constructor helper functions
122 void initMinimizerFcnDependentPart(double defaultErrorLevel);
123
124 int _printLevel = 1;
125 int _status = -99;
126 bool _profile = false;
127
128 bool _verbose = false;
131 bool _profileStart = false;
132
133 std::unique_ptr<TMatrixDSym> _extV;
134
136 std::string _minimizerType = "Minuit";
138
139 static std::unique_ptr<ROOT::Fit::Fitter> _theFitter ;
140
141 std::vector<std::pair<std::string,int> > _statusHistory ;
142
143 ClassDefOverride(RooMinimizer,0) // RooFit interface to ROOT::Fit::Fitter
144} ;
145
146#endif
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition: TGX11.cxx:110
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
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:57
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:42
void setRecoverFromNaNStrength(double strength)
Try to recover from invalid function values.
void optimizeConst(int flag)
If flag is true, perform constant term optimization on function being minimized.
std::vector< std::pair< std::string, int > > _statusHistory
Definition: RooMinimizer.h:141
void initMinimizerFirstPart()
Initialize the part of the minimizer that is independent of the function to be minimized.
std::ofstream * logfile()
RooMinimizer(RooAbsReal &function, FcnMode fcnMode=FcnMode::classic)
Construct MINUIT interface to given function.
int simplex()
Execute SIMPLEX.
std::unique_ptr< TMatrixDSym > _extV
Definition: RooMinimizer.h:133
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.
FcnMode _fcnMode
Definition: RooMinimizer.h:137
void profileStart()
Start profiling timer.
void setProfile(bool flag=true)
Definition: RooMinimizer.h:85
bool setLogFile(const char *logf=nullptr)
void initMinimizerFcnDependentPart(double defaultErrorLevel)
Initialize the part of the minimizer that is dependent on the function to be minimized.
void profileStop()
Stop profiling timer and report results of last session.
int minos()
Execute MINOS.
double & maxFCN()
int hesse()
Execute HESSE.
void setErrorLevel(double level)
Set the level for MINUIT error analysis to the given value.
int getPrintLevel() const
Definition: RooMinimizer.h:88
static std::unique_ptr< ROOT::Fit::Fitter > _theFitter
Definition: RooMinimizer.h:139
void setEvalErrorWall(bool flag)
int migrad()
Execute MIGRAD.
int seek()
Execute SEEK.
void setEps(double eps)
Change MINUIT epsilon.
static RooFitResult * lastMinuitFit()
RooPlot * contour(RooRealVar &var1, RooRealVar &var2, double n1=1, double n2=2, double n3=0, double n4=0, double n5=0, double n6=0, unsigned int npoints=50)
Create and draw a TH2 with the error contours in the parameters var1 and var2.
int improve()
Execute IMPROVE.
static void cleanup()
Cleanup method called by atexit handler installed by RooSentinel to delete all global heap objects wh...
bool _profileStart
Definition: RooMinimizer.h:131
void setOffsetting(bool flag)
Enable internal likelihood offsetting for enhanced numeric precision.
TStopwatch _timer
Definition: RooMinimizer.h:129
bool fitFcn() const
void saveStatus(const char *label, int status)
Definition: RooMinimizer.h:96
~RooMinimizer() override
Destructor.
int setPrintLevel(int newLevel)
Change the MINUIT internal printing level.
ROOT::Math::IMultiGenFunction * getMultiGenFcn() const
void setStrategy(int strat)
Change MINUIT strategy to istrat.
void setVerbose(bool flag=true)
void setPrintEvalErrors(int numEvalErrors)
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
std::string _minimizerType
Definition: RooMinimizer.h:136
void setMaxFunctionCalls(int n)
Change maximum number of likelihood function calss from MINUIT (RooMinimizer default 500 * #parameter...
int evalCounter() const
TStopwatch _cumulTimer
Definition: RooMinimizer.h:130
int minimize(const char *type, const char *alg=0)
Minimise the function passed in the constructor.
int getNPar() const
void setMaxIterations(int n)
Change maximum number of MINUIT iterations (RooMinimizer default 500 * #parameters)
RooAbsMinimizerFcn * _fcn
Definition: RooMinimizer.h:135
void applyCovarianceMatrix(TMatrixDSym const &V)
Apply results of given external covariance matrix.
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:43
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
Mother of all ROOT objects.
Definition: TObject.h:37
Stopwatch class.
Definition: TStopwatch.h:28
const Int_t n
Definition: legend1.C:16
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:167