Back to home page

EIC code displayed by LXR

 
 

    


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

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(std::span<const double> params) : par(params.begin(), params.end()) {}
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    /**
0069 
0070    Sets the parameters of the ParametricFunction.
0071 
0072    @param params vector containing the Parameter values
0073 
0074    */
0075 
0076    virtual void SetParameters(std::vector<double> const& params) const
0077    {
0078 
0079       assert(params.size() == par.size());
0080       par.assign(params.begin(), params.end());
0081    }
0082 
0083    /**
0084 
0085    Accessor for the state of the parameters.
0086 
0087    @return vector containing the present Parameter settings
0088 
0089    */
0090 
0091    virtual const std::vector<double> &GetParameters() const { return par; }
0092 
0093    /**
0094 
0095    Accessor for the number of  parameters.
0096 
0097    @return the number of function parameters
0098 
0099    */
0100    virtual unsigned int NumberOfParameters() const { return par.size(); }
0101 
0102    // Why do I need to declare it here, it should be inherited without
0103    // any problems, no?
0104 
0105    /**
0106 
0107    Evaluates the function with the given coordinates.
0108 
0109    @param x vector containing the input coordinates
0110 
0111    @return the result of the function evaluation with the given
0112    coordinates.
0113 
0114    */
0115 
0116    double operator()(std::vector<double> const& x) const override = 0;
0117 
0118    /**
0119 
0120    Evaluates the function with the given coordinates and Parameter
0121    values. This member function is useful to implement when speed
0122    is an issue as it is faster to call only one function instead
0123    of two (SetParameters and operator()). The default implementation,
0124    provided for convenience, does the latter.
0125 
0126    @param x vector containing the input coordinates
0127 
0128    @param params vector containing the Parameter values
0129 
0130    @return the result of the function evaluation with the given
0131    coordinates and parameters
0132 
0133    */
0134 
0135    virtual double operator()(std::vector<double> const& x, std::vector<double> const& params) const
0136    {
0137       SetParameters(params);
0138       return operator()(x);
0139    }
0140 
0141    /**
0142 
0143    Member function returning the Gradient of the function with respect
0144    to its variables (but without including gradients with respect to
0145    its internal parameters).
0146 
0147    @param x vector containing the coordinates of the point where the
0148    Gradient is to be calculated.
0149 
0150    @return the Gradient vector of the function at the given point.
0151 
0152    */
0153 
0154    virtual std::vector<double> GetGradient(std::vector<double> const& x) const;
0155 
0156 protected:
0157    /**
0158 
0159    The vector containing the parameters of the function
0160    It is mutable for "historical reasons" as in the hierarchy
0161    methods and classes are const and all the implications of changing
0162    them back to non-const are not clear.
0163 
0164    */
0165 
0166    mutable std::vector<double> par;
0167 };
0168 
0169 } // namespace Minuit2
0170 
0171 } // namespace ROOT
0172 
0173 #endif // ROOT_Minuit2_ParametricFunction