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 MinuitOld
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
70 /// set the function to minimize
71 void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
72
73 /// set free variable
74 bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
75
76 /// set upper/lower limited variable (override if minimizer supports them )
77 bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */) override;
78
79 /// set lower limit variable (override if minimizer supports them )
80 bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower ) override;
81
82 /// set upper limit variable (override if minimizer supports them )
83 bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) override;
84
85 /// set fixed variable (override if minimizer supports them )
86 bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */) override;
87
88 /// set the value of an existing variable
89 bool SetVariableValue(unsigned int , double ) override;
90
91 /// set the step size of an existing variable
92 bool SetVariableStepSize(unsigned int , double ) override;
93 /// set the lower-limit of an existing variable
94 bool SetVariableLowerLimit(unsigned int , double ) override;
95 /// set the upper-limit of an existing variable
96 bool SetVariableUpperLimit(unsigned int , double ) override;
97 /// set the limits of an existing variable
98 bool SetVariableLimits(unsigned int ivar, double lower, double upper) override;
99 /// fix an existing variable
100 bool FixVariable(unsigned int) override;
101 /// release an existing variable
102 bool ReleaseVariable(unsigned int) override;
103 /// query if an existing variable is fixed (i.e. considered constant in the minimization)
104 /// note that by default all variables are not fixed
105 bool IsFixedVariable(unsigned int) const override;
106 /// get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
107 bool GetVariableSettings(unsigned int, ROOT::Fit::ParameterSettings & ) const override;
108
109
110 /// method to perform the minimization
111 bool Minimize() override;
112
113 /// return minimum function value
114 double MinValue() const override;
115
116 /// return expected distance reached from the minimum
117 double Edm() const override;
118
119 /// return pointer to X values at the minimum
120 const double * X() const override { return &fParams.front(); }
121
122 /// return pointer to gradient values at the minimum
123 const double * MinGradient() const override { return nullptr; } // not available in Minuit2
124
125 /// number of function calls to reach the minimum
126 unsigned int NCalls() const override;
127
128 /// this is <= Function().NDim() which is the total
129 /// number of variables (free+ constrained ones)
130 unsigned int NDim() const override { return fDim; }
131
132 /// number of free variables (real dimension of the problem)
133 /// this is <= Function().NDim() which is the total
134 unsigned int NFree() const override;
135
136 /// minimizer provides error and error matrix
137 bool ProvidesError() const override { return true; }
138
139 /// return errors at the minimum
140 const double * Errors() const override { return &fErrors.front(); }
141
142 /** return covariance matrices elements
143 if the variable is fixed the matrix is zero
144 The ordering of the variables is the same as in errors
145 */
146 double CovMatrix(unsigned int i, unsigned int j) const override {
147 return ( fCovar.size() > (i + fDim* j) ) ? fCovar[i + fDim* j] : 0;
148 }
149
150 /**
151 Fill the passed array with the covariance matrix elements
152 if the variable is fixed or const the value is zero.
153 The array will be filled as cov[i *ndim + j]
154 The ordering of the variables is the same as in errors and parameter value.
155 This is different from the direct interface of Minuit2 or TMinuit where the
156 values were obtained only to variable parameters
157 */
158 bool GetCovMatrix(double * cov) const override;
159
160 /**
161 Fill the passed array with the Hessian matrix elements
162 The Hessian matrix is the matrix of the second derivatives
163 and is the inverse of the covariance matrix
164 If the variable is fixed or const the values for that variables are zero.
165 The array will be filled as h[i *ndim + j]
166 */
167 bool GetHessianMatrix(double * h) const override;
168
169 ///return status of covariance matrix
170 int CovMatrixStatus() const override;
171
172 ///global correlation coefficient for variable i
173 double GlobalCC(unsigned int ) const override;
174
175 /// minos error for variable i, return false if Minos failed
176 bool GetMinosError(unsigned int i, double & errLow, double & errUp, int = 0) override;
177
178 /// minos status code of last Minos run
179 /// minos status = -1 : Minos is not run
180 /// = 0 : last MINOS run was successful
181 /// > 0 : some problems encountered when running MINOS
182 int MinosStatus() const override { return fMinosStatus; }
183
184 /**
185 perform a full calculation of the Hessian matrix for error calculation
186 */
187 bool Hesse() override;
188
189 /**
190 scan a parameter i around the minimum. A minimization must have been done before,
191 return false if it is not the case
192 */
193 bool Scan(unsigned int i, unsigned int &nstep, double * x, double * y, double xmin = 0, double xmax = 0) override;
194
195 /**
196 find the contour points (xi,xj) of the function for parameter i and j around the minimum
197 The contour will be find for value of the function = Min + ErrorUp();
198 */
199 bool Contour(unsigned int i, unsigned int j, unsigned int & npoints, double *xi, double *xj) override;
200
201
202 void PrintResults() override;
203
204 /// return reference to the objective function
205 ///virtual const ROOT::Math::IGenFunction & Function() const;
206
207 /// get name of variables (override if minimizer support storing of variable names)
208 std::string VariableName(unsigned int ivar) const override;
209
210 /// get index of variable given a variable given a name
211 /// return always -1 . (It is Not implemented)
212 int VariableIndex(const std::string & name) const override;
213
214 /// static function to switch on/off usage of static global TMinuit instance (gMinuit)
215 /// By default it is used (i.e. is on). Method returns the previous state
216 bool static UseStaticMinuit(bool on = true);
217
218 /// suppress the minuit warnings (if called with false will enable them)
219 /// By default they are suppressed only when the printlevel is <= 0
220 void SuppressMinuitWarnings(bool nowarn=true);
221
222 /// set debug mode. Return true if setting was successful
223 bool SetDebug(bool on = true);
224
225protected:
226
227 /// implementation of FCN for Minuit
228 static void Fcn( int &, double * , double & f, double * , int);
229 /// implementation of FCN for Minuit when user provided gradient is used
230 static void FcnGrad( int &, double * g, double & f, double * , int);
231
232 /// initialize the TMinuit instance
233 void InitTMinuit(int ndim);
234
235 /// reset
236 void DoClear();
237
238 ///release a parameter that is fixed when it is redefined
239 void DoReleaseFixParameter( int ivar);
240
241 /// retrieve minimum parameters and errors from TMinuit
242 void RetrieveParams();
243
244 /// retrieve error matrix from TMinuit
245 void RetrieveErrorMatrix();
246
247 /// check TMinuit instance
248 bool CheckMinuitInstance() const;
249
250 ///check parameter
251 bool CheckVarIndex(unsigned int ivar) const;
252
253
254private:
255
256 bool fUsed;
258 unsigned int fDim;
259 int fMinosStatus = -1; // Minos status code
260 std::vector<double> fParams; // vector of output values
261 std::vector<double> fErrors; // vector of output errors
262 std::vector<double> fCovar; // vector storing the covariance matrix
263
266
268
269 static bool fgUsed; // flag to control if static instance has done minimization
270 static bool fgUseStaticMinuit; // flag to control if using global TMInuit instance (gMinuit)
271
272 ClassDef(TMinuitMinimizer,1) //Implementation of Minimizer interface using TMinuit
273
274};
275
276
277
278#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:342
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:119
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
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...