Logo ROOT   6.13/01
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 
20 class TMinuit;
21 
22 
23 
24 namespace ROOT {
25 
26  namespace Minuit {
27 
28 
29  // enumeration specifying the type of TMinuit minimizers
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 
52 public:
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  */
67  ~TMinuitMinimizer ();
68 
69 private:
70  // usually copying is non trivial, so we make this unaccessible
71 
72  /**
73  Copy constructor
74  */
76 
77  /**
78  Assignment operator
79  */
80  TMinuitMinimizer & operator = (const TMinuitMinimizer & rhs);
81 
82 public:
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 protected:
234 
235  /// implementation of FCN for Minuit
236  static void Fcn( int &, double * , double & f, double * , int);
237  /// implementation of FCN for Minuit when user provided gradient is used
238  static void FcnGrad( int &, double * g, double & f, double * , int);
239 
240  /// initialize the TMinuit instance
241  void InitTMinuit(int ndim);
242 
243  /// reset
244  void DoClear();
245 
246  ///release a parameter that is fixed when it is redefined
247  void DoReleaseFixParameter( int ivar);
248 
249  /// retrieve minimum parameters and errors from TMinuit
250  void RetrieveParams();
251 
252  /// retrieve error matrix from TMinuit
253  void RetrieveErrorMatrix();
254 
255  /// check TMinuit instance
256  bool CheckMinuitInstance() const;
257 
258  ///check parameter
259  bool CheckVarIndex(unsigned int ivar) const;
260 
261 private:
262 
263  bool fUsed;
264  bool fMinosRun;
265  unsigned int fDim;
266  std::vector<double> fParams; // vector of output values
267  std::vector<double> fErrors; // vector of output errors
268  std::vector<double> fCovar; // vector storing the covariance matrix
269 
272 
273  static TMinuit * fgMinuit;
274 
275  static bool fgUsed; // flag to control if static instance has done minimization
276  static bool fgUseStaticMinuit; // flag to control if using global TMInuit instance (gMinuit)
277 
278  ClassDef(TMinuitMinimizer,1) //Implementation of Minimizer interface using TMinuit
279 
280 };
281 
282 
283 
284 #endif /* ROOT_TMinuitMinimizer */
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:326
virtual const double * Errors() const
return errors at the minimum
static TMinuit * fgMinuit
Implementation in C++ of the Minuit package written by Fred James.
Definition: TMinuit.h:27
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
std::vector< double > fParams
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
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...
you should not use this method at all Int_t y
Definition: TRolke.cxx:630
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) Plug-in&#39;s exist in ROOT to be able to instantiate the derived classes like ROOT::Math::GSLMinimizer or ROOT::Math::Minuit2Minimizer via the plug-in manager.
Definition: Minimizer.h:78
virtual const double * X() const
return pointer to X values at the minimum
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
static bool fgUseStaticMinuit
* x
Deprecated and error prone model selection interface.
Definition: TRolke.cxx:630
ROOT::Minuit::EMinimizerType fType
virtual unsigned int NDim() const
this is <= Function().NDim() which is the total number of variables (free+ constrained ones) ...
TMinuitMinimizer class: ROOT::Math::Minimizer implementation based on TMinuit.
std::vector< double > fCovar
virtual const double * MinGradient() const
return pointer to gradient values at the minimum
virtual bool ProvidesError() const
minimizer provides error and error matrix
std::vector< double > fErrors