Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 09:09:27

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    /// set the function to minimize
0059    void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
0060 
0061    /// set free variable
0062    bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
0063 
0064    /// set upper/lower limited variable (override if minimizer supports them )
0065    bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */) override;
0066 
0067 #ifdef LATER
0068    /// set lower limit variable  (override if minimizer supports them )
0069    virtual bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower );
0070    /// set upper limit variable (override if minimizer supports them )
0071    virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper );
0072 #endif
0073 
0074    /// set fixed variable (override if minimizer supports them )
0075    bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */) override;
0076 
0077    /// set the value of an existing variable
0078    bool SetVariableValue(unsigned int ivar, double val ) override;
0079 
0080    /// method to perform the minimization
0081     bool Minimize() override;
0082 
0083    /// return minimum function value
0084    double MinValue() const override { return fMinVal; }
0085 
0086    /// return expected distance reached from the minimum
0087    double Edm() const override { return fEdm; }
0088 
0089    /// return  pointer to X values at the minimum
0090    const double *  X() const override { return &fParams.front(); }
0091 
0092    /// return pointer to gradient values at the minimum
0093    const double *  MinGradient() const override { return nullptr; } // not available
0094 
0095    /// number of function calls to reach the minimum
0096    unsigned int NCalls() const override { return 0; }
0097 
0098    /// this is <= Function().NDim() which is the total
0099    /// number of variables (free+ constrained ones)
0100    unsigned int NDim() const override { return fDim; }
0101 
0102    /// number of free variables (real dimension of the problem)
0103    /// this is <= Function().NDim() which is the total
0104    unsigned int NFree() const override { return fNFree; }
0105 
0106    /// minimizer provides error and error matrix
0107    bool ProvidesError() const override { return true; }
0108 
0109    /// return errors at the minimum
0110    const double * Errors() const override { return  &fErrors.front(); }
0111 
0112    /** return covariance matrices elements
0113        if the variable is fixed the matrix is zero
0114        The ordering of the variables is the same as in errors
0115    */
0116    double CovMatrix(unsigned int i, unsigned int j) const override {
0117       return fCovar[i + fDim* j];
0118    }
0119 
0120    /*
0121      return covariance matrix status
0122    */
0123    int CovMatrixStatus() const override {
0124       if (fCovar.empty()) return 0;
0125       return (fStatus ==0) ? 3 : 1;
0126    }
0127 
0128 
0129 
0130 
0131 
0132 protected:
0133 
0134    /// implementation of FCN for Fumili
0135    static void Fcn( int &, double * , double & f, double * , int);
0136    /// implementation of FCN for Fumili when user provided gradient is used
0137    //static void FcnGrad( int &, double * g, double & f, double * , int);
0138 
0139    /// static function implementing the evaluation of the FCN (it uses static instance fgFumili)
0140    static double EvaluateFCN(const double * x, double * g);
0141 
0142 private:
0143 
0144 
0145    unsigned int fDim;
0146    unsigned int fNFree;
0147    double fMinVal;
0148    double fEdm;
0149    std::vector<double> fParams;
0150    std::vector<double> fErrors;
0151    std::vector<double> fCovar;
0152 
0153    TFumili * fFumili;
0154 
0155    // need to have a static copy of the function
0156    //NOTE: This is NOT thread safe.
0157    static ROOT::Math::FitMethodFunction * fgFunc;
0158    static ROOT::Math::FitMethodGradFunction * fgGradFunc;
0159 
0160    static TFumili * fgFumili; // static instance (used by fcn function)
0161 
0162    ClassDef(TFumiliMinimizer,1)  //Implementation of Minimizer interface using TFumili
0163 
0164 };
0165 
0166 
0167 
0168 #endif /* ROOT_TFumiliMinimizer */