Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:25

0001 // @(#)root/minuit2:$Id$
0002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
0007  *                                                                    *
0008  **********************************************************************/
0009 
0010 #ifndef ROOT_Minuit2_ParametricFunction
0011 #define ROOT_Minuit2_ParametricFunction
0012 
0013 #include "Minuit2/MnConfig.h"
0014 #include <vector>
0015 #include <cassert>
0016 
0017 #include "Minuit2/FCNBase.h"
0018 
0019 namespace ROOT {
0020 
0021 namespace Minuit2 {
0022 
0023 /**
0024 
0025 Function which has parameters. For example, one could define
0026 a one-dimensional Gaussian, by considering x as an input coordinate
0027 for the evaluation of the function, and the mean and the square root
0028 of the variance as parameters.
0029 <p>
0030 AS OF NOW PARAMETRICFUNCTION INHERITS FROM FCNBASE INSTEAD OF
0031 GENERICFUNCTION. THIS IS ONLY BECAUSE NUMERICAL2PGRADIENTCALCULATOR
0032 NEEDS AN FCNBASE OBJECT AND WILL BE CHANGED!!!!!!!!!!!!!!!!
0033 
0034 @ingroup Minuit
0035 
0036 \todo ParametricFunction and all the classes that inherit from it
0037 are inheriting also FCNBase so that the Gradient calculation has
0038 the Up() member function. That is not really good...
0039 
0040 
0041  */
0042 
0043 class ParametricFunction : public FCNBase {
0044 
0045 public:
0046    /**
0047 
0048    Constructor which initializes the ParametricFunction with the
0049    parameters given as input.
0050 
0051    @param params vector containing the initial Parameter values
0052 
0053    */
0054 
0055    ParametricFunction(const std::vector<double> &params) : par(params) {}
0056 
0057    /**
0058 
0059    Constructor which initializes the ParametricFunction by setting
0060    the number of parameters.
0061 
0062    @param nparams number of parameters of the parametric function
0063 
0064    */
0065 
0066    ParametricFunction(int nparams) : par(nparams) {}
0067 
0068    ~ParametricFunction() override {}
0069 
0070    /**
0071 
0072    Sets the parameters of the ParametricFunction.
0073 
0074    @param params vector containing the Parameter values
0075 
0076    */
0077 
0078    virtual void SetParameters(const std::vector<double> &params) const
0079    {
0080 
0081       assert(params.size() == par.size());
0082       par = params;
0083    }
0084 
0085    /**
0086 
0087    Accessor for the state of the parameters.
0088 
0089    @return vector containing the present Parameter settings
0090 
0091    */
0092 
0093    virtual const std::vector<double> &GetParameters() const { return par; }
0094 
0095    /**
0096 
0097    Accessor for the number of  parameters.
0098 
0099    @return the number of function parameters
0100 
0101    */
0102    virtual unsigned int NumberOfParameters() const { return par.size(); }
0103 
0104    // Why do I need to declare it here, it should be inherited without
0105    // any problems, no?
0106 
0107    /**
0108 
0109    Evaluates the function with the given coordinates.
0110 
0111    @param x vector containing the input coordinates
0112 
0113    @return the result of the function evaluation with the given
0114    coordinates.
0115 
0116    */
0117 
0118    double operator()(const std::vector<double> &x) const override = 0;
0119 
0120    /**
0121 
0122    Evaluates the function with the given coordinates and Parameter
0123    values. This member function is useful to implement when speed
0124    is an issue as it is faster to call only one function instead
0125    of two (SetParameters and operator()). The default implementation,
0126    provided for convenience, does the latter.
0127 
0128    @param x vector containing the input coordinates
0129 
0130    @param params vector containing the Parameter values
0131 
0132    @return the result of the function evaluation with the given
0133    coordinates and parameters
0134 
0135    */
0136 
0137    virtual double operator()(const std::vector<double> &x, const std::vector<double> &params) const
0138    {
0139       SetParameters(params);
0140       return operator()(x);
0141    }
0142 
0143    /**
0144 
0145    Member function returning the Gradient of the function with respect
0146    to its variables (but without including gradients with respect to
0147    its internal parameters).
0148 
0149    @param x vector containing the coordinates of the point where the
0150    Gradient is to be calculated.
0151 
0152    @return the Gradient vector of the function at the given point.
0153 
0154    */
0155 
0156    virtual std::vector<double> GetGradient(const std::vector<double> &x) const;
0157 
0158 protected:
0159    /**
0160 
0161    The vector containing the parameters of the function
0162    It is mutable for "historical reasons" as in the hierarchy
0163    methods and classes are const and all the implications of changing
0164    them back to non-const are not clear.
0165 
0166    */
0167 
0168    mutable std::vector<double> par;
0169 };
0170 
0171 } // namespace Minuit2
0172 
0173 } // namespace ROOT
0174 
0175 #endif // ROOT_Minuit2_ParametricFunction