Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:30

0001 // @(#)root/mathmore:$Id$
0002 // Author: L. Moneta Oct 2012
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 
0012 // Header file for class BasicMinimizer
0013 
0014 #ifndef ROOT_Math_BasicMinimizer
0015 #define ROOT_Math_BasicMinimizer
0016 
0017 #include "Math/Minimizer.h"
0018 
0019 
0020 #include "Math/IFunctionfwd.h"
0021 
0022 #include "Math/IParamFunctionfwd.h"
0023 
0024 #include "Math/MinimTransformVariable.h"
0025 
0026 
0027 #include <vector>
0028 #include <map>
0029 #include <string>
0030 
0031 
0032 
0033 namespace ROOT {
0034 
0035 namespace Math {
0036 
0037    class MinimTransformFunction;
0038 
0039 
0040 
0041 //_______________________________________________________________________________
0042 /**
0043    Base Minimizer class, which defines the basic functionality of various minimizer
0044    implementations (apart from Minuit and Minuit2)
0045    It provides support for storing parameter values, step size,
0046    parameter transformation etc.. in case real minimizer implementations do not provide
0047    such functionality.
0048    This is an internal class and should not be used directly by the user
0049 
0050    @ingroup MultiMin
0051 */
0052 
0053 
0054 class BasicMinimizer : public ROOT::Math::Minimizer {
0055 
0056 public:
0057 
0058    /**
0059       Default constructor
0060    */
0061    BasicMinimizer ( );
0062 
0063 
0064    /**
0065       Destructor
0066    */
0067    ~BasicMinimizer () override;
0068 
0069    /// set the function to minimize
0070    void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
0071 
0072    /// set free variable
0073    bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
0074 
0075 
0076    /// set lower limit variable  (override if minimizer supports them )
0077    bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower ) override;
0078    /// set upper limit variable (override if minimizer supports them )
0079    bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) override;
0080    /// set upper/lower limited variable (override if minimizer supports them )
0081    bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */) override;
0082    /// set fixed variable (override if minimizer supports them )
0083    bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */) override;
0084    /// set the value of an existing variable
0085    bool SetVariableValue(unsigned int ivar, double val ) override;
0086    /// set the values of all existing variables (array must be dimensioned to the size of existing parameters)
0087    bool SetVariableValues(const double * x) override;
0088    /// set the step size of an already existing variable
0089    bool SetVariableStepSize(unsigned int ivar, double step ) override;
0090    /// set the lower-limit of an already existing variable
0091    bool SetVariableLowerLimit(unsigned int ivar, double lower) override;
0092    /// set the upper-limit of an already existing variable
0093    bool SetVariableUpperLimit(unsigned int ivar, double upper) override;
0094    /// set the limits of an already existing variable
0095    bool SetVariableLimits(unsigned int ivar, double lower, double upper) override;
0096    /// fix an existing variable
0097    bool FixVariable(unsigned int ivar) override;
0098    /// release an existing variable
0099    bool ReleaseVariable(unsigned int ivar) override;
0100    /// query if an existing variable is fixed (i.e. considered constant in the minimization)
0101    /// note that by default all variables are not fixed
0102    bool IsFixedVariable(unsigned int ivar)  const override;
0103    /// get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
0104    bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings & varObj) const override;
0105    /// get name of variables (override if minimizer support storing of variable names)
0106    std::string VariableName(unsigned int ivar) const override;
0107    /// get index of variable given a variable given a name
0108    /// return -1 if variable is not found
0109    int VariableIndex(const std::string & name) const override;
0110 
0111    /// method to perform the minimization
0112     bool Minimize() override;
0113 
0114    /// return minimum function value
0115    double MinValue() const override { return fMinVal; }
0116 
0117    /// return  pointer to X values at the minimum
0118    const double *  X() const override { return &fValues.front(); }
0119 
0120    /// number of dimensions
0121    unsigned int NDim() const override { return fDim; }
0122 
0123    /// number of free variables (real dimension of the problem)
0124    unsigned int NFree() const override;
0125 
0126    /// total number of parameter defined
0127    virtual unsigned int NPar() const { return fValues.size(); }
0128 
0129    /// return pointer to used objective function
0130    const ROOT::Math::IMultiGenFunction * ObjFunction() const { return fObjFunc; }
0131 
0132    /// return pointer to used gradient object function  (NULL if gradient is not supported)
0133    const ROOT::Math::IMultiGradFunction * GradObjFunction() const;
0134 
0135 
0136    /// print result of minimization
0137    void PrintResult() const;
0138 
0139    /// accessor methods
0140    virtual const double * StepSizes() const { return &fSteps.front(); }
0141 
0142 protected:
0143 
0144    bool CheckDimension() const;
0145 
0146    bool CheckObjFunction() const;
0147 
0148    MinimTransformFunction * CreateTransformation(std::vector<double> & startValues, const ROOT::Math::IMultiGradFunction * func = nullptr);
0149 
0150    void SetFinalValues(const double * x, const MinimTransformFunction * func = nullptr);
0151 
0152    void SetMinValue(double val) { fMinVal = val; }
0153 
0154 private:
0155 
0156    // dimension of the function to be minimized
0157    unsigned int fDim;
0158 
0159    const ROOT::Math::IMultiGenFunction * fObjFunc;
0160 
0161    double fMinVal;
0162    std::vector<double> fValues;
0163    std::vector<double> fSteps;
0164    std::vector<std::string> fNames;
0165    std::vector<ROOT::Math::EMinimVariableType> fVarTypes;       ///< vector specifying the type of variables
0166    std::map< unsigned int, std::pair<double, double> > fBounds; ///< map specifying the bound using as key the parameter index
0167 
0168 };
0169 
0170    } // end namespace Fit
0171 
0172 } // end namespace ROOT
0173 
0174 
0175 
0176 #endif /* ROOT_Math_BasicMinimizer */