Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:13:59

0001 // @(#)root/mathmore:$Id$
0002 // Author: L. Moneta Wed Dec 20 17:16:32 2006
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  * This library is free software; you can redistribute it and/or      *
0009  * modify it under the terms of the GNU General Public License        *
0010  * as published by the Free Software Foundation; either version 2     *
0011  * of the License, or (at your option) any later version.             *
0012  *                                                                    *
0013  * This library is distributed in the hope that it will be useful,    *
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
0016  * General Public License for more details.                           *
0017  *                                                                    *
0018  * You should have received a copy of the GNU General Public License  *
0019  * along with this library (see file COPYING); if not, write          *
0020  * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
0021  * 330, Boston, MA 02111-1307 USA, or contact the author.             *
0022  *                                                                    *
0023  **********************************************************************/
0024 
0025 // Header file for class GSLNLSMinimizer
0026 
0027 #ifndef ROOT_Math_GSLNLSMinimizer
0028 #define ROOT_Math_GSLNLSMinimizer
0029 
0030 
0031 
0032 #include "Math/BasicMinimizer.h"
0033 
0034 #include "Math/IFunctionfwd.h"
0035 
0036 #include "Math/IParamFunctionfwd.h"
0037 
0038 #include "Math/FitMethodFunction.h"
0039 
0040 #include "Math/MinimTransformVariable.h"
0041 
0042 #include <vector>
0043 
0044 namespace ROOT {
0045 
0046    namespace Math {
0047 
0048       class GSLMultiFit;
0049       class GSLMultiFit2;
0050 
0051 //_____________________________________________________________________________________________________
0052 /**
0053    GSLNLSMinimizer class for Non Linear Least Square fitting
0054    It Uses the Levemberg-Marquardt algorithm from
0055    <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Nonlinear-Least_002dSquares-Fitting.html">
0056    GSL Non Linear Least Square fitting</A>.
0057 
0058    @ingroup MultiMin
0059 */
0060 class GSLNLSMinimizer : public  ROOT::Math::BasicMinimizer {
0061 
0062 public:
0063 
0064    /**
0065       Constructor from a type
0066    */
0067    explicit GSLNLSMinimizer (int type);
0068    /**
0069       Constructor from name
0070    */
0071    explicit GSLNLSMinimizer (const char * = nullptr);
0072 
0073 
0074    /**
0075       Destructor (no operations)
0076    */
0077    ~GSLNLSMinimizer () override;
0078 
0079    /// set the function to minimize
0080    void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
0081 
0082 
0083    /// method to perform the minimization
0084     bool Minimize() override;
0085 
0086 
0087    /// return expected distance reached from the minimum
0088    double Edm() const override { return fEdm; } // not impl. }
0089 
0090 
0091    /// return pointer to gradient values at the minimum
0092    const double *  MinGradient() const override;
0093 
0094    /// number of function calls to reach the minimum
0095    unsigned int NCalls() const override { return fNCalls; }
0096 
0097    /// number of free variables (real dimension of the problem)
0098    /// this is <= Function().NDim() which is the total
0099 //   virtual unsigned int NFree() const { return fNFree; }
0100 
0101    /// minimizer provides error and error matrix
0102    bool ProvidesError() const override { return true; }
0103 
0104    /// return errors at the minimum
0105    const double * Errors() const override { return (!fErrors.empty()) ? &fErrors.front() : nullptr; }
0106 //  {
0107 //       static std::vector<double> err;
0108 //       err.resize(fDim);
0109 //       return &err.front();
0110 //    }
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 , unsigned int ) const override;
0117 
0118    /// return covariance matrix status
0119    int CovMatrixStatus() const override;
0120 
0121 protected:
0122 
0123    /// Internal method to perform minimization
0124    /// template on the type of method function
0125    template<class Func, class FitterType>
0126    bool DoMinimize(const Func & f, FitterType * fitter);
0127 
0128 
0129 private:
0130 
0131    bool fUseGradFunction = false; // flag to indicate if using external gradients
0132    unsigned int fNFree;      // dimension of the internal function to be minimized
0133    unsigned int fNCalls;        // number of function calls
0134 
0135    ROOT::Math::GSLMultiFit * fGSLMultiFit = nullptr;        // pointer to old GSL multi fit solver
0136    ROOT::Math::GSLMultiFit2 * fGSLMultiFit2 = nullptr;       // pointer to new GSL multi fit driver
0137 
0138    double fEdm;                                   // edm value
0139    double fLSTolerance;                           // Line Search Tolerance
0140    std::vector<double> fErrors;
0141    std::vector<double> fCovMatrix;              //  cov matrix (stored as cov[ i * dim + j]
0142 
0143 
0144 
0145 };
0146 
0147    } // end namespace Math
0148 
0149 } // end namespace ROOT
0150 
0151 
0152 #endif /* ROOT_Math_GSLNLSMinimizer */