Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TFumiliMinimizer.h
Go to the documentation of this file.
1 // @(#)root/fumili:$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 TFumiliMinimizer
12 
13 #ifndef ROOT_TFumiliMinimizer
14 #define ROOT_TFumiliMinimizer
15 
16 #include "Math/Minimizer.h"
17 
18 #include "Math/FitMethodFunction.h"
19 
20 #include "Rtypes.h"
21 
22 class TFumili;
23 
24 
25 
26 // namespace ROOT {
27 
28 // namespace Math {
29 
30 // class BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>;
31 // class BasicFitMethodFunction<ROOT::Math::IMultiGradFunction>;
32 
33 // }
34 // }
35 
36 
37 
38 /**
39  TFumiliMinimizer class: minimizer implementation based on TFumili.
40 */
41 class TFumiliMinimizer : public ROOT::Math::Minimizer {
42 
43 public:
44 
45  /**
46  Default constructor (an argument is needed by plug-in manager)
47  */
48  TFumiliMinimizer (int dummy=0 );
49 
50 
51  /**
52  Destructor (no operations)
53  */
54  ~TFumiliMinimizer ();
55 
56 private:
57  // usually copying is non trivial, so we make this unaccessible
58 
59  /**
60  Copy constructor
61  */
62  TFumiliMinimizer(const TFumiliMinimizer &);
63 
64  /**
65  Assignment operator
66  */
67  TFumiliMinimizer & operator = (const TFumiliMinimizer & rhs);
68 
69 public:
70 
71  /// set the function to minimize
72  virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func);
73 
74  /// set the function to minimize
75  virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func);
76 
77  /// set free variable
78  virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step);
79 
80  /// set upper/lower limited variable (override if minimizer supports them )
81  virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */);
82 
83 #ifdef LATER
84  /// set lower limit variable (override if minimizer supports them )
85  virtual bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower );
86  /// set upper limit variable (override if minimizer supports them )
87  virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper );
88 #endif
89 
90  /// set fixed variable (override if minimizer supports them )
91  virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);
92 
93  /// set the value of an existing variable
94  virtual bool SetVariableValue(unsigned int ivar, double val );
95 
96  /// method to perform the minimization
97  virtual bool Minimize();
98 
99  /// return minimum function value
100  virtual double MinValue() const { return fMinVal; }
101 
102  /// return expected distance reached from the minimum
103  virtual double Edm() const { return fEdm; }
104 
105  /// return pointer to X values at the minimum
106  virtual const double * X() const { return &fParams.front(); }
107 
108  /// return pointer to gradient values at the minimum
109  virtual const double * MinGradient() const { return 0; } // not available
110 
111  /// number of function calls to reach the minimum
112  virtual unsigned int NCalls() const { return 0; }
113 
114  /// this is <= Function().NDim() which is the total
115  /// number of variables (free+ constrained ones)
116  virtual unsigned int NDim() const { return fDim; }
117 
118  /// number of free variables (real dimension of the problem)
119  /// this is <= Function().NDim() which is the total
120  virtual unsigned int NFree() const { return fNFree; }
121 
122  /// minimizer provides error and error matrix
123  virtual bool ProvidesError() const { return true; }
124 
125  /// return errors at the minimum
126  virtual const double * Errors() const { return &fErrors.front(); }
127 
128  /** return covariance matrices elements
129  if the variable is fixed the matrix is zero
130  The ordering of the variables is the same as in errors
131  */
132  virtual double CovMatrix(unsigned int i, unsigned int j) const {
133  return fCovar[i + fDim* j];
134  }
135 
136  /*
137  return covariance matrix status
138  */
139  virtual int CovMatrixStatus() const {
140  if (fCovar.size() == 0) return 0;
141  return (fStatus ==0) ? 3 : 1;
142  }
143 
144 
145 
146 
147 
148 protected:
149 
150  /// implementation of FCN for Fumili
151  static void Fcn( int &, double * , double & f, double * , int);
152  /// implementation of FCN for Fumili when user provided gradient is used
153  //static void FcnGrad( int &, double * g, double & f, double * , int);
154 
155  /// static function implementing the evaluation of the FCN (it uses static instance fgFumili)
156  static double EvaluateFCN(const double * x, double * g);
157 
158 private:
159 
160 
161  unsigned int fDim;
162  unsigned int fNFree;
163  double fMinVal;
164  double fEdm;
165  std::vector<double> fParams;
166  std::vector<double> fErrors;
167  std::vector<double> fCovar;
168 
169  TFumili * fFumili;
170 
171  // need to have a static copy of the function
172  //NOTE: This is NOT thread safe.
173  static ROOT::Math::FitMethodFunction * fgFunc;
174  static ROOT::Math::FitMethodGradFunction * fgGradFunc;
175 
176  static TFumili * fgFumili; // static instance (used by fcn function)
177 
178  ClassDef(TFumiliMinimizer,1) //Implementation of Minimizer interface using TFumili
179 
180 };
181 
182 
183 
184 #endif /* ROOT_TFumiliMinimizer */