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