Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMinuitMinimizer.h
Go to the documentation of this file.
1// @(#)root/minuit:$Id$
2// Author: L. Moneta Wed Oct 25 16:28:55 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class TMinuitMinimizer
12
13#ifndef ROOT_TMinuitMinimizer
14#define ROOT_TMinuitMinimizer
15
16#include "Math/Minimizer.h"
17
18#include "Rtypes.h"
19
20#include <vector>
21#include <string>
22
23class TMinuit;
24
25namespace ROOT {
26
27 namespace Minuit {
28
29
30 // enumeration specifying the type of TMinuit minimizers
37 kSeek
38 };
39
40 }
41}
42
43
44
45/**
46 TMinuitMinimizer class:
47 ROOT::Math::Minimizer implementation based on TMinuit
48
49 @ingroup TMinuit
50*/
52
53public:
54
55 /**
56 Default constructor
57 */
59
60 /**
61 Constructor from a char * (used by PM)
62 */
63 TMinuitMinimizer ( const char * type , unsigned int ndim = 0);
64
65 /**
66 Destructor (no operations)
67 */
68 ~TMinuitMinimizer () override;
69
70private:
71 // usually copying is non trivial, so we make this unaccessible
72
73 /**
74 Copy constructor
75 */
77
78 /**
79 Assignment operator
80 */
82
83public:
84
85 /// set the function to minimize
86 void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
87
88 /// set free variable
89 bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
90
91 /// set upper/lower limited variable (override if minimizer supports them )
92 bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */) override;
93
94 /// set lower limit variable (override if minimizer supports them )
95 bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower ) override;
96
97 /// set upper limit variable (override if minimizer supports them )
98 bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) override;
99
100 /// set fixed variable (override if minimizer supports them )
101 bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */) override;
102
103 /// set the value of an existing variable
104 bool SetVariableValue(unsigned int , double ) override;
105
106 /// set the step size of an existing variable
107 bool SetVariableStepSize(unsigned int , double ) override;
108 /// set the lower-limit of an existing variable
109 bool SetVariableLowerLimit(unsigned int , double ) override;
110 /// set the upper-limit of an existing variable
111 bool SetVariableUpperLimit(unsigned int , double ) override;
112 /// set the limits of an existing variable
113 bool SetVariableLimits(unsigned int ivar, double lower, double upper) override;
114 /// fix an existing variable
115 bool FixVariable(unsigned int) override;
116 /// release an existing variable
117 bool ReleaseVariable(unsigned int) override;
118 /// query if an existing variable is fixed (i.e. considered constant in the minimization)
119 /// note that by default all variables are not fixed
120 bool IsFixedVariable(unsigned int) const override;
121 /// get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
122 bool GetVariableSettings(unsigned int, ROOT::Fit::ParameterSettings & ) const override;
123
124
125 /// method to perform the minimization
126 bool Minimize() override;
127
128 /// return minimum function value
129 double MinValue() const override;
130
131 /// return expected distance reached from the minimum
132 double Edm() const override;
133
134 /// return pointer to X values at the minimum
135 const double * X() const override { return &fParams.front(); }
136
137 /// return pointer to gradient values at the minimum
138 const double * MinGradient() const override { return nullptr; } // not available in Minuit2
139
140 /// number of function calls to reach the minimum
141 unsigned int NCalls() const override;
142
143 /// this is <= Function().NDim() which is the total
144 /// number of variables (free+ constrained ones)
145 unsigned int NDim() const override { return fDim; }
146
147 /// number of free variables (real dimension of the problem)
148 /// this is <= Function().NDim() which is the total
149 unsigned int NFree() const override;
150
151 /// minimizer provides error and error matrix
152 bool ProvidesError() const override { return true; }
153
154 /// return errors at the minimum
155 const double * Errors() const override { return &fErrors.front(); }
156
157 /** return covariance matrices elements
158 if the variable is fixed the matrix is zero
159 The ordering of the variables is the same as in errors
160 */
161 double CovMatrix(unsigned int i, unsigned int j) const override {
162 return ( fCovar.size() > (i + fDim* j) ) ? fCovar[i + fDim* j] : 0;
163 }
164
165 /**
166 Fill the passed array with the covariance matrix elements
167 if the variable is fixed or const the value is zero.
168 The array will be filled as cov[i *ndim + j]
169 The ordering of the variables is the same as in errors and parameter value.
170 This is different from the direct interface of Minuit2 or TMinuit where the
171 values were obtained only to variable parameters
172 */
173 bool GetCovMatrix(double * cov) const override;
174
175 /**
176 Fill the passed array with the Hessian matrix elements
177 The Hessian matrix is the matrix of the second derivatives
178 and is the inverse of the covariance matrix
179 If the variable is fixed or const the values for that variables are zero.
180 The array will be filled as h[i *ndim + j]
181 */
182 bool GetHessianMatrix(double * h) const override;
183
184 ///return status of covariance matrix
185 int CovMatrixStatus() const override;
186
187 ///global correlation coefficient for variable i
188 double GlobalCC(unsigned int ) const override;
189
190 /// minos error for variable i, return false if Minos failed
191 bool GetMinosError(unsigned int i, double & errLow, double & errUp, int = 0) override;
192
193 /// minos status code of last Minos run
194 /// minos status = -1 : Minos is not run
195 /// = 0 : last MINOS run was successful
196 /// > 0 : some problems encountered when running MINOS
197 int MinosStatus() const override { return fMinosStatus; }
198
199 /**
200 perform a full calculation of the Hessian matrix for error calculation
201 */
202 bool Hesse() override;
203
204 /**
205 scan a parameter i around the minimum. A minimization must have been done before,
206 return false if it is not the case
207 */
208 bool Scan(unsigned int i, unsigned int &nstep, double * x, double * y, double xmin = 0, double xmax = 0) override;
209
210 /**
211 find the contour points (xi,xj) of the function for parameter i and j around the minimum
212 The contour will be find for value of the function = Min + ErrorUp();
213 */
214 bool Contour(unsigned int i, unsigned int j, unsigned int & npoints, double *xi, double *xj) override;
215
216
217 void PrintResults() override;
218
219 /// return reference to the objective function
220 ///virtual const ROOT::Math::IGenFunction & Function() const;
221
222 /// get name of variables (override if minimizer support storing of variable names)
223 std::string VariableName(unsigned int ivar) const override;
224
225 /// get index of variable given a variable given a name
226 /// return always -1 . (It is Not implemented)
227 int VariableIndex(const std::string & name) const override;
228
229 /// static function to switch on/off usage of static global TMinuit instance (gMinuit)
230 /// By default it is used (i.e. is on). Method returns the previous state
231 bool static UseStaticMinuit(bool on = true);
232
233 /// suppress the minuit warnings (if called with false will enable them)
234 /// By default they are suppressed only when the printlevel is <= 0
235 void SuppressMinuitWarnings(bool nowarn=true);
236
237 /// set debug mode. Return true if setting was successful
238 bool SetDebug(bool on = true);
239
240protected:
241
242 /// implementation of FCN for Minuit
243 static void Fcn( int &, double * , double & f, double * , int);
244 /// implementation of FCN for Minuit when user provided gradient is used
245 static void FcnGrad( int &, double * g, double & f, double * , int);
246
247 /// initialize the TMinuit instance
248 void InitTMinuit(int ndim);
249
250 /// reset
251 void DoClear();
252
253 ///release a parameter that is fixed when it is redefined
254 void DoReleaseFixParameter( int ivar);
255
256 /// retrieve minimum parameters and errors from TMinuit
257 void RetrieveParams();
258
259 /// retrieve error matrix from TMinuit
260 void RetrieveErrorMatrix();
261
262 /// check TMinuit instance
263 bool CheckMinuitInstance() const;
264
265 ///check parameter
266 bool CheckVarIndex(unsigned int ivar) const;
267
268
269private:
270
271 bool fUsed;
273 unsigned int fDim;
274 int fMinosStatus = -1; // Minos status code
275 std::vector<double> fParams; // vector of output values
276 std::vector<double> fErrors; // vector of output errors
277 std::vector<double> fCovar; // vector storing the covariance matrix
278
281
283
284 static bool fgUsed; // flag to control if static instance has done minimization
285 static bool fgUseStaticMinuit; // flag to control if using global TMInuit instance (gMinuit)
286
287 ClassDef(TMinuitMinimizer,1) //Implementation of Minimizer interface using TMinuit
288
289};
290
291
292
293#endif /* ROOT_TMinuitMinimizer */
#define f(i)
Definition RSha256.hxx:104
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
#define ClassDef(name, id)
Definition Rtypes.h:337
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
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
float xmin
float xmax
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition Minimizer.h:117
TMinuitMinimizer class: ROOT::Math::Minimizer implementation based on TMinuit.
bool FixVariable(unsigned int) override
fix an existing variable
void RetrieveErrorMatrix()
retrieve error matrix from TMinuit
const double * Errors() const override
return errors at the minimum
bool SetFixedVariable(unsigned int, const std::string &, double) override
set fixed variable (override if minimizer supports them )
static TMinuit * fgMinuit
bool SetVariableLimits(unsigned int ivar, double lower, double upper) override
set the limits of an existing variable
static void Fcn(int &, double *, double &f, double *, int)
implementation of FCN for Minuit
bool SetVariable(unsigned int ivar, const std::string &name, double val, double step) override
set free variable
bool ReleaseVariable(unsigned int) override
release an existing variable
static void FcnGrad(int &, double *g, double &f, double *, int)
implementation of FCN for Minuit when user provided gradient is used
ROOT::Minuit::EMinimizerType fType
double CovMatrix(unsigned int i, unsigned int j) const override
return covariance matrices elements if the variable is fixed the matrix is zero The ordering of the v...
bool SetVariableLowerLimit(unsigned int, double) override
set the lower-limit of an existing variable
int VariableIndex(const std::string &name) const override
get index of variable given a variable given a name return always -1 .
double MinValue() const override
return minimum function value
bool SetVariableStepSize(unsigned int, double) override
set the step size of an existing variable
void RetrieveParams()
retrieve minimum parameters and errors from TMinuit
~TMinuitMinimizer() override
Destructor (no operations)
const double * MinGradient() const override
return pointer to gradient values at the minimum
std::vector< double > fErrors
int MinosStatus() const override
minos status code of last Minos run minos status = -1 : Minos is not run = 0 : last MINOS run was suc...
void SetFunction(const ROOT::Math::IMultiGenFunction &func) override
set the function to minimize
bool CheckMinuitInstance() const
check TMinuit instance
bool ProvidesError() const override
minimizer provides error and error matrix
static bool fgUseStaticMinuit
std::vector< double > fCovar
bool Hesse() override
perform a full calculation of the Hessian matrix for error calculation
unsigned int NDim() const override
this is <= Function().NDim() which is the total number of variables (free+ constrained ones)
bool CheckVarIndex(unsigned int ivar) const
check parameter
bool Minimize() override
method to perform the minimization
bool SetVariableValue(unsigned int, double) override
set the value of an existing variable
int CovMatrixStatus() const override
return status of covariance matrix
void SuppressMinuitWarnings(bool nowarn=true)
suppress the minuit warnings (if called with false will enable them) By default they are suppressed o...
bool SetVariableUpperLimit(unsigned int, double) override
set the upper-limit of an existing variable
double Edm() const override
return expected distance reached from the minimum
static bool UseStaticMinuit(bool on=true)
static function to switch on/off usage of static global TMinuit instance (gMinuit) By default it is u...
void PrintResults() override
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const ...
unsigned int NCalls() const override
number of function calls to reach the minimum
TMinuitMinimizer & operator=(const TMinuitMinimizer &rhs)
Assignment operator.
void DoReleaseFixParameter(int ivar)
release a parameter that is fixed when it is redefined
bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double) override
set upper/lower limited variable (override if minimizer supports them )
bool GetMinosError(unsigned int i, double &errLow, double &errUp, int=0) override
minos error for variable i, return false if Minos failed
bool GetVariableSettings(unsigned int, ROOT::Fit::ParameterSettings &) const override
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
double GlobalCC(unsigned int) const override
global correlation coefficient for variable i
const double * X() const override
return pointer to X values at the minimum
bool IsFixedVariable(unsigned int) const override
query if an existing variable is fixed (i.e.
std::string VariableName(unsigned int ivar) const override
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const;
bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper) override
set upper limit variable (override if minimizer supports them )
bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower) override
set lower limit variable (override if minimizer supports them )
unsigned int NFree() const override
number of free variables (real dimension of the problem) this is <= Function().NDim() which is the to...
std::vector< double > fParams
void InitTMinuit(int ndim)
initialize the TMinuit instance
bool GetHessianMatrix(double *h) const override
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
bool Scan(unsigned int i, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0) override
scan a parameter i around the minimum.
bool SetDebug(bool on=true)
set debug mode. Return true if setting was successful
bool GetCovMatrix(double *cov) const override
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
bool Contour(unsigned int i, unsigned int j, unsigned int &npoints, double *xi, double *xj) override
find the contour points (xi,xj) of the function for parameter i and j around the minimum The contour ...
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...