Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:04

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 
0050 //_____________________________________________________________________________________________________
0051 /**
0052    GSLNLSMinimizer class for Non Linear Least Square fitting
0053    It Uses the Levemberg-Marquardt algorithm from
0054    <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Nonlinear-Least_002dSquares-Fitting.html">
0055    GSL Non Linear Least Square fitting</A>.
0056 
0057    @ingroup MultiMin
0058 */
0059 class GSLNLSMinimizer : public  ROOT::Math::BasicMinimizer {
0060 
0061 public:
0062 
0063    /**
0064       Default constructor
0065    */
0066    GSLNLSMinimizer (int type = 0);
0067 
0068    /**
0069       Destructor (no operations)
0070    */
0071    ~GSLNLSMinimizer () override;
0072 
0073 private:
0074    // usually copying is non trivial, so we make this unaccessible
0075 
0076    /**
0077       Copy constructor
0078    */
0079    GSLNLSMinimizer(const GSLNLSMinimizer &) : ROOT::Math::BasicMinimizer() {}
0080 
0081    /**
0082       Assignment operator
0083    */
0084    GSLNLSMinimizer & operator = (const GSLNLSMinimizer & rhs)  {
0085       if (this == &rhs) return *this;  // time saving self-test
0086       return *this;
0087    }
0088 
0089 public:
0090 
0091    /// set the function to minimize
0092    void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
0093 
0094 
0095    /// method to perform the minimization
0096     bool Minimize() override;
0097 
0098 
0099    /// return expected distance reached from the minimum
0100    double Edm() const override { return fEdm; } // not impl. }
0101 
0102 
0103    /// return pointer to gradient values at the minimum
0104    const double *  MinGradient() const override;
0105 
0106    /// number of function calls to reach the minimum
0107    unsigned int NCalls() const override { return fNCalls; }
0108 
0109    /// number of free variables (real dimension of the problem)
0110    /// this is <= Function().NDim() which is the total
0111 //   virtual unsigned int NFree() const { return fNFree; }
0112 
0113    /// minimizer provides error and error matrix
0114    bool ProvidesError() const override { return true; }
0115 
0116    /// return errors at the minimum
0117    const double * Errors() const override { return (!fErrors.empty()) ? &fErrors.front() : nullptr; }
0118 //  {
0119 //       static std::vector<double> err;
0120 //       err.resize(fDim);
0121 //       return &err.front();
0122 //    }
0123 
0124    /** return covariance matrices elements
0125        if the variable is fixed the matrix is zero
0126        The ordering of the variables is the same as in errors
0127    */
0128    double CovMatrix(unsigned int , unsigned int ) const override;
0129 
0130    /// return covariance matrix status
0131    int CovMatrixStatus() const override;
0132 
0133 protected:
0134 
0135    /// Internal method to perform minimization
0136    /// template on the type of method function
0137    template<class Func>
0138    bool DoMinimize(const Func & f);
0139 
0140 
0141 private:
0142 
0143    bool fUseGradFunction = false; // flag to indicate if using external gradients
0144    unsigned int fNFree;      // dimension of the internal function to be minimized
0145    unsigned int fNCalls;        // number of function calls
0146 
0147    ROOT::Math::GSLMultiFit * fGSLMultiFit;        // pointer to GSL multi fit solver
0148 
0149    double fEdm;                                   // edm value
0150    double fLSTolerance;                           // Line Search Tolerance
0151    std::vector<double> fErrors;
0152    std::vector<double> fCovMatrix;              //  cov matrix (stored as cov[ i * dim + j]
0153 
0154 
0155 
0156 };
0157 
0158    } // end namespace Math
0159 
0160 } // end namespace ROOT
0161 
0162 
0163 #endif /* ROOT_Math_GSLNLSMinimizer */