Logo ROOT  
Reference Guide
Go to the documentation of this file.
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 *****************************************************************************/
24#include <Fit/Fitter.h>
25#include <TStopwatch.h>
26#include <TMatrixDSymfwd.h>
28#include <fstream>
29#include <memory> // shared_ptr, unique_ptr
30#include <string>
31#include <utility>
32#include <vector>
35class RooAbsReal;
36class RooFitResult;
37class RooArgList;
38class RooRealVar;
39class RooArgSet;
40class RooPlot;
41class RooDataSet;
43class RooMinimizer : public TObject {
45 /// Config argument to RooMinimizer ctor
46 struct Config {
47 Config() {}
48 double recoverFromNaN = 10.; // RooAbsMinimizerFcn config
49 int printEvalErrors = 10; // RooAbsMinimizerFcn config
50 int doEEWall = 1; // RooAbsMinimizerFcn config
51 int offsetting = -1; // RooAbsMinimizerFcn config
52 const char *logf = nullptr; // RooAbsMinimizerFcn config
53 int nWorkers = getDefaultWorkers(); // RooAbsMinimizerFcn config that can only be set in ctor
54 bool parallelGradient = false; // RooAbsMinimizerFcn config that can only be set in ctor
55 bool parallelLikelihood = false; // RooAbsMinimizerFcn config that can only be set in ctor
56 bool verbose = false; // local config
57 bool profile = false; // local config
58 std::string minimizerType = ""; // local config
59 private:
61 };
63 explicit RooMinimizer(RooAbsReal &function, Config const &cfg = {});
65 ~RooMinimizer() override;
67 enum Strategy { Speed = 0, Balance = 1, Robustness = 2 };
68 enum PrintLevel { None = -1, Reduced = 0, Normal = 1, ExtraForProblem = 2, Maximum = 3 };
70 // Setters on _theFitter
71 void setStrategy(int strat);
72 void setErrorLevel(double level);
73 void setEps(double eps);
74 void setMaxIterations(int n);
75 void setMaxFunctionCalls(int n);
76 void setPrintLevel(int newLevel);
78 // Setters on _fcn
79 void optimizeConst(int flag);
80 void setEvalErrorWall(bool flag) { _cfg.doEEWall = flag; }
81 void setRecoverFromNaNStrength(double strength);
82 void setOffsetting(bool flag);
83 void setPrintEvalErrors(int numEvalErrors) { _cfg.printEvalErrors = numEvalErrors; }
84 void setVerbose(bool flag = true) { _cfg.verbose = flag; }
85 bool setLogFile(const char *logf = nullptr);
87 int migrad();
88 int hesse();
89 int minos();
90 int minos(const RooArgSet &minosParamList);
91 int seek();
92 int simplex();
93 int improve();
95 int minimize(const char *type, const char *alg = nullptr);
97 RooFitResult *save(const char *name = nullptr, const char *title = nullptr);
98 RooPlot *contour(RooRealVar &var1, RooRealVar &var2, double n1 = 1.0, double n2 = 2.0, double n3 = 0.0,
99 double n4 = 0.0, double n5 = 0.0, double n6 = 0.0, unsigned int npoints = 50);
101 void setProfile(bool flag = true) { _cfg.profile = flag; }
102 /// Enable or disable the logging of function evaluations to a RooDataSet.
103 /// \see RooMinimizer::getLogDataSet().
104 /// param[in] flag Boolean flag to disable or enable the functionality.
105 void setLoggingToDataSet(bool flag = true) { _loggingToDataSet = flag; }
107 /// If logging of function evaluations to a RooDataSet is enabled, returns a
108 /// pointer to a dataset with one row per evaluation of the RooAbsReal passed
109 /// to the minimizer. As columns, there are all floating parameters and the
110 /// values they had for that evaluation.
111 /// \see RooMinimizer::setLoggingToDataSet(bool).
112 RooDataSet *getLogDataSet() const { return _logDataSet.get(); }
114 static int getPrintLevel();
116 void setMinimizerType(std::string const &type);
117 std::string const &minimizerType() const { return _cfg.minimizerType; }
119 static void cleanup();
120 static RooFitResult *lastMinuitFit();
121 static RooFitResult *lastMinuitFit(const RooArgList &varList);
123 void saveStatus(const char *label, int status)
124 {
125 _statusHistory.push_back(std::pair<std::string, int>(label, status));
126 }
128 int evalCounter() const;
129 void zeroEvalCount();
132 const ROOT::Fit::Fitter *fitter() const;
136 int getNPar() const;
138 void applyCovarianceMatrix(TMatrixDSym const &V);
141 friend class RooAbsMinimizerFcn;
143 void profileStart();
144 void profileStop();
146 std::ofstream *logfile();
147 double &maxFCN();
149 bool fitFcn() const;
151 // constructor helper functions
153 void initMinimizerFcnDependentPart(double defaultErrorLevel);
155 int _status = -99;
156 bool _profileStart = false;
157 bool _loggingToDataSet = false;
162 std::unique_ptr<TMatrixDSym> _extV;
164 std::unique_ptr<RooAbsMinimizerFcn> _fcn;
166 static std::unique_ptr<ROOT::Fit::Fitter> _theFitter;
168 std::vector<std::pair<std::string, int>> _statusHistory;
170 std::unique_ptr<RooDataSet> _logDataSet;
172 RooMinimizer::Config _cfg; // local config object
174 ClassDefOverride(RooMinimizer, 0) // RooFit interface to ROOT::Fit::Fitter
#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:62
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:56
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
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:43
void setRecoverFromNaNStrength(double strength)
Try to recover from invalid function values.
static int getPrintLevel()
Get the MINUIT internal printing level.
void optimizeConst(int flag)
If flag is true, perform constant term optimization on function being minimized.
void initMinimizerFirstPart()
Initialize the part of the minimizer that is independent of the function to be minimized.
std::ofstream * logfile()
int simplex()
Execute SIMPLEX.
std::unique_ptr< TMatrixDSym > _extV
Definition: RooMinimizer.h:162
void zeroEvalCount()
void setMinimizerType(std::string const &type)
Choose the minimizer algorithm.
std::vector< std::pair< std::string, int > > _statusHistory
Definition: RooMinimizer.h:168
std::unique_ptr< RooDataSet > _logDataSet
Definition: RooMinimizer.h:170
void profileStart()
Start profiling timer.
void setProfile(bool flag=true)
Definition: RooMinimizer.h:101
RooPlot * contour(RooRealVar &var1, RooRealVar &var2, double n1=1.0, double n2=2.0, double n3=0.0, double n4=0.0, double n5=0.0, double n6=0.0, unsigned int npoints=50)
Create and draw a TH2 with the error contours in the parameters var1 and var2.
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 setLoggingToDataSet(bool flag=true)
Enable or disable the logging of function evaluations to a RooDataSet.
Definition: RooMinimizer.h:105
void profileStop()
Stop profiling timer and report results of last session.
int minos()
Execute MINOS.
double & maxFCN()
int hesse()
Execute HESSE.
RooFitResult * save(const char *name=nullptr, const char *title=nullptr)
Save and return a RooFitResult snapshot of current minimizer status.
void setErrorLevel(double level)
Set the level for MINUIT error analysis to the given value.
static std::unique_ptr< ROOT::Fit::Fitter > _theFitter
Definition: RooMinimizer.h:166
void setEvalErrorWall(bool flag)
Definition: RooMinimizer.h:80
int migrad()
Execute MIGRAD.
int seek()
Execute SEEK.
void setEps(double eps)
Change MINUIT epsilon.
void setPrintLevel(int newLevel)
Change the MINUIT internal printing level.
std::string const & minimizerType() const
Definition: RooMinimizer.h:117
static RooFitResult * lastMinuitFit()
int improve()
Execute IMPROVE.
bool _loggingToDataSet
Definition: RooMinimizer.h:157
static void cleanup()
Cleanup method called by atexit handler installed by RooSentinel to delete all global heap objects wh...
bool _profileStart
Definition: RooMinimizer.h:156
void setOffsetting(bool flag)
Enable internal likelihood offsetting for enhanced numeric precision.
TStopwatch _timer
Definition: RooMinimizer.h:159
RooMinimizer::Config _cfg
Definition: RooMinimizer.h:172
RooDataSet * getLogDataSet() const
If logging of function evaluations to a RooDataSet is enabled, returns a pointer to a dataset with on...
Definition: RooMinimizer.h:112
bool fitFcn() const
void saveStatus(const char *label, int status)
Definition: RooMinimizer.h:123
~RooMinimizer() override
int minimize(const char *type, const char *alg=nullptr)
Minimise the function passed in the constructor.
ROOT::Math::IMultiGenFunction * getMultiGenFcn() const
void setStrategy(int strat)
Change MINUIT strategy to istrat.
void setVerbose(bool flag=true)
Definition: RooMinimizer.h:84
void setPrintEvalErrors(int numEvalErrors)
Definition: RooMinimizer.h:83
RooMinimizer(RooAbsReal &function, Config const &cfg={})
Construct MINUIT interface to given function.
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
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:160
int getNPar() const
void setMaxIterations(int n)
Change maximum number of MINUIT iterations (RooMinimizer default 500 * #parameters)
std::unique_ptr< RooAbsMinimizerFcn > _fcn
Definition: RooMinimizer.h:164
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:41
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
Config argument to RooMinimizer ctor.
Definition: RooMinimizer.h:46
const char * logf
Definition: RooMinimizer.h:52
std::string minimizerType
Definition: RooMinimizer.h:58