Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:47

0001 // @(#)root/fumili:$Id$
0002 // Author: L. Moneta Wed Oct 25 16:28:55 2006
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 // Header file for class TFumiliMinimizer
0012 
0013 #ifndef ROOT_TFumiliMinimizer
0014 #define ROOT_TFumiliMinimizer
0015 
0016 #include "Math/Minimizer.h"
0017 
0018 #include "Math/FitMethodFunction.h"
0019 
0020 #include "Rtypes.h"
0021 #include <vector>
0022 #include <string>
0023 
0024 class TFumili;
0025 
0026 
0027 
0028 // namespace ROOT {
0029 
0030 //    namespace Math {
0031 
0032 //       class BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>;
0033 //       class BasicFitMethodFunction<ROOT::Math::IMultiGradFunction>;
0034 
0035 //    }
0036 // }
0037 
0038 
0039 
0040 /**
0041    TFumiliMinimizer class: minimizer implementation based on TFumili.
0042 */
0043 class TFumiliMinimizer  : public ROOT::Math::Minimizer {
0044 
0045 public:
0046 
0047    /**
0048       Default constructor (an argument is needed by plug-in manager)
0049    */
0050    TFumiliMinimizer (int dummy=0 );
0051 
0052 
0053    /**
0054       Destructor (no operations)
0055    */
0056    ~TFumiliMinimizer () override;
0057 
0058 private:
0059    // usually copying is non trivial, so we make this unaccessible
0060 
0061    /**
0062       Copy constructor
0063    */
0064    TFumiliMinimizer(const TFumiliMinimizer &);
0065 
0066    /**
0067       Assignment operator
0068    */
0069    TFumiliMinimizer & operator = (const TFumiliMinimizer & rhs);
0070 
0071 public:
0072 
0073    /// set the function to minimize
0074    void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
0075 
0076    /// set free variable
0077    bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
0078 
0079    /// set upper/lower limited variable (override if minimizer supports them )
0080    bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */) override;
0081 
0082 #ifdef LATER
0083    /// set lower limit variable  (override if minimizer supports them )
0084    virtual bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower );
0085    /// set upper limit variable (override if minimizer supports them )
0086    virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper );
0087 #endif
0088 
0089    /// set fixed variable (override if minimizer supports them )
0090    bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */) override;
0091 
0092    /// set the value of an existing variable
0093    bool SetVariableValue(unsigned int ivar, double val ) override;
0094 
0095    /// method to perform the minimization
0096     bool Minimize() override;
0097 
0098    /// return minimum function value
0099    double MinValue() const override { return fMinVal; }
0100 
0101    /// return expected distance reached from the minimum
0102    double Edm() const override { return fEdm; }
0103 
0104    /// return  pointer to X values at the minimum
0105    const double *  X() const override { return &fParams.front(); }
0106 
0107    /// return pointer to gradient values at the minimum
0108    const double *  MinGradient() const override { return nullptr; } // not available
0109 
0110    /// number of function calls to reach the minimum
0111    unsigned int NCalls() const override { return 0; }
0112 
0113    /// this is <= Function().NDim() which is the total
0114    /// number of variables (free+ constrained ones)
0115    unsigned int NDim() const override { return fDim; }
0116 
0117    /// number of free variables (real dimension of the problem)
0118    /// this is <= Function().NDim() which is the total
0119    unsigned int NFree() const override { return fNFree; }
0120 
0121    /// minimizer provides error and error matrix
0122    bool ProvidesError() const override { return true; }
0123 
0124    /// return errors at the minimum
0125    const double * Errors() const override { return  &fErrors.front(); }
0126 
0127    /** return covariance matrices elements
0128        if the variable is fixed the matrix is zero
0129        The ordering of the variables is the same as in errors
0130    */
0131    double CovMatrix(unsigned int i, unsigned int j) const override {
0132       return fCovar[i + fDim* j];
0133    }
0134 
0135    /*
0136      return covariance matrix status
0137    */
0138    int CovMatrixStatus() const override {
0139       if (fCovar.empty()) return 0;
0140       return (fStatus ==0) ? 3 : 1;
0141    }
0142 
0143 
0144 
0145 
0146 
0147 protected:
0148 
0149    /// implementation of FCN for Fumili
0150    static void Fcn( int &, double * , double & f, double * , int);
0151    /// implementation of FCN for Fumili when user provided gradient is used
0152    //static void FcnGrad( int &, double * g, double & f, double * , int);
0153 
0154    /// static function implementing the evaluation of the FCN (it uses static instance fgFumili)
0155    static double EvaluateFCN(const double * x, double * g);
0156 
0157 private:
0158 
0159 
0160    unsigned int fDim;
0161    unsigned int fNFree;
0162    double fMinVal;
0163    double fEdm;
0164    std::vector<double> fParams;
0165    std::vector<double> fErrors;
0166    std::vector<double> fCovar;
0167 
0168    TFumili * fFumili;
0169 
0170    // need to have a static copy of the function
0171    //NOTE: This is NOT thread safe.
0172    static ROOT::Math::FitMethodFunction * fgFunc;
0173    static ROOT::Math::FitMethodGradFunction * fgGradFunc;
0174 
0175    static TFumili * fgFumili; // static instance (used by fcn function)
0176 
0177    ClassDef(TFumiliMinimizer,1)  //Implementation of Minimizer interface using TFumili
0178 
0179 };
0180 
0181 
0182 
0183 #endif /* ROOT_TFumiliMinimizer */