TFumiliMinimizer.h

Go to the documentation of this file.
00001 // @(#)root/fumili:$Id: TFumiliMinimizer.h 31604 2009-12-07 19:04:33Z moneta $
00002 // Author: L. Moneta Wed Oct 25 16:28:55 2006
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Header file for class TFumiliMinimizer
00012 
00013 #ifndef ROOT_TFumiliMinimizer
00014 #define ROOT_TFumiliMinimizer
00015 
00016 #ifndef ROOT_Math_Minimizer
00017 #include "Math/Minimizer.h"
00018 #endif
00019 
00020 #ifndef ROOT_Math_FitMethodFunction
00021 #include "Math/FitMethodFunction.h"
00022 #endif
00023 
00024 #ifndef ROOT_Rtypes
00025 #include "Rtypes.h"
00026 #endif
00027 
00028 class TFumili; 
00029 
00030 
00031 
00032 // namespace ROOT { 
00033 
00034 //    namespace Math { 
00035 
00036 //       class BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>; 
00037 //       class BasicFitMethodFunction<ROOT::Math::IMultiGradFunction>; 
00038 
00039 //    }
00040 // }
00041 
00042  
00043 
00044 /** 
00045    TFumiliMinimizer class: minimizer implementation based on TFumili.
00046 */ 
00047 class TFumiliMinimizer  : public ROOT::Math::Minimizer {
00048 
00049 public: 
00050 
00051    /** 
00052       Default constructor (an argument is needed by plug-in manager)
00053    */ 
00054    TFumiliMinimizer (int dummy=0 );
00055 
00056 
00057    /** 
00058       Destructor (no operations)
00059    */ 
00060    ~TFumiliMinimizer (); 
00061 
00062 private:
00063    // usually copying is non trivial, so we make this unaccessible
00064 
00065    /** 
00066       Copy constructor
00067    */ 
00068    TFumiliMinimizer(const TFumiliMinimizer &); 
00069 
00070    /** 
00071       Assignment operator
00072    */ 
00073    TFumiliMinimizer & operator = (const TFumiliMinimizer & rhs); 
00074 
00075 public: 
00076 
00077    /// set the function to minimize
00078    virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func); 
00079 
00080    /// set the function to minimize
00081    virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func); 
00082 
00083    /// set free variable 
00084    virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step); 
00085 
00086    /// set upper/lower limited variable (override if minimizer supports them )
00087    virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */); 
00088 
00089 #ifdef LATER
00090    /// set lower limit variable  (override if minimizer supports them )
00091    virtual bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower );
00092    /// set upper limit variable (override if minimizer supports them )
00093    virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper );
00094 #endif
00095 
00096    /// set fixed variable (override if minimizer supports them )
00097    virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);  
00098 
00099    /// set the value of an existing variable 
00100    virtual bool SetVariableValue(unsigned int ivar, double val );
00101 
00102    /// method to perform the minimization
00103    virtual  bool Minimize(); 
00104 
00105    /// return minimum function value
00106    virtual double MinValue() const { return fMinVal; } 
00107 
00108    /// return expected distance reached from the minimum
00109    virtual double Edm() const { return fEdm; }
00110 
00111    /// return  pointer to X values at the minimum 
00112    virtual const double *  X() const { return &fParams.front(); }
00113 
00114    /// return pointer to gradient values at the minimum 
00115    virtual const double *  MinGradient() const { return 0; } // not available 
00116 
00117    /// number of function calls to reach the minimum 
00118    virtual unsigned int NCalls() const { return 0; } 
00119 
00120    /// this is <= Function().NDim() which is the total 
00121    /// number of variables (free+ constrained ones) 
00122    virtual unsigned int NDim() const { return fDim; }   
00123 
00124    /// number of free variables (real dimension of the problem) 
00125    /// this is <= Function().NDim() which is the total 
00126    virtual unsigned int NFree() const { return fNFree; }  
00127 
00128    /// minimizer provides error and error matrix
00129    virtual bool ProvidesError() const { return true; } 
00130 
00131    /// return errors at the minimum 
00132    virtual const double * Errors() const { return  &fErrors.front(); }
00133 
00134    /** return covariance matrices elements 
00135        if the variable is fixed the matrix is zero
00136        The ordering of the variables is the same as in errors
00137    */ 
00138    virtual double CovMatrix(unsigned int i, unsigned int j) const { 
00139       return fCovar[i + fDim* j]; 
00140    }
00141    
00142    /*
00143      return covariance matrix status 
00144    */
00145    virtual int CovMatrixStatus() const { 
00146       if (fCovar.size() == 0) return 0;
00147       return (fStatus ==0) ? 3 : 1; 
00148    }
00149    
00150 
00151 
00152    
00153 
00154 protected: 
00155 
00156    /// implementation of FCN for Fumili
00157    static void Fcn( int &, double * , double & f, double * , int);
00158    /// implementation of FCN for Fumili when user provided gradient is used
00159    //static void FcnGrad( int &, double * g, double & f, double * , int);
00160 
00161    /// static function implementing the evaluation of the FCN (it uses static instance fgFumili)
00162    static double EvaluateFCN(const double * x, double * g); 
00163 
00164 private: 
00165 
00166 
00167    unsigned int fDim; 
00168    unsigned int fNFree;
00169    double fMinVal;
00170    double fEdm; 
00171    std::vector<double> fParams;
00172    std::vector<double> fErrors;
00173    std::vector<double> fCovar; 
00174 
00175    TFumili * fFumili; 
00176 
00177    // need to have a static copy of the function 
00178    //NOTE: This is NOT thread safe.
00179    static ROOT::Math::FitMethodFunction * fgFunc;
00180    static ROOT::Math::FitMethodGradFunction * fgGradFunc;
00181 
00182    static TFumili * fgFumili; // static instance (used by fcn function) 
00183 
00184    ClassDef(TFumiliMinimizer,1)  //Implementation of Minimizer interface using TFumili 
00185 
00186 }; 
00187 
00188 
00189 
00190 #endif /* ROOT_TFumiliMinimizer */

Generated on Tue Jul 5 14:26:56 2011 for ROOT_528-00b_version by  doxygen 1.5.1