Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // @(#)root/mathmore:$Id$
0002 // Authors: L. Moneta, A. Zsenei   08/2005
0003 
0004  /**********************************************************************
0005   *                                                                    *
0006   * Copyright (c) 2004 ROOT Foundation,  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 ParamFunction
0026 //
0027 // Base class for Parametric functions
0028 //
0029 // Created by: Lorenzo Moneta  at Wed Nov 10 16:38:34 2004
0030 //
0031 // Last update: Wed Nov 10 16:38:34 2004
0032 //
0033 #ifndef ROOT_Math_ParamFunction
0034 #define ROOT_Math_ParamFunction
0035 
0036 
0037 #include "Math/IParamFunction.h"
0038 
0039 #include <vector>
0040 
0041 namespace ROOT {
0042 namespace Math {
0043 
0044 //_____________________________________________________________________________________
0045    /**
0046       Base template class for all Parametric Functions.
0047       The template argument is the type of parameteric function interface is implementing like
0048       Parameteric 1D, Multi-Dim or gradient parametric.
0049 
0050       A parameteric function is a Generic Function with parameters, so
0051       it is a function object which carries a state, the parameters.
0052       The parameters are described with a standard vector of doubles.
0053 
0054       This class contains the default implementations for the methods defined in the
0055       IParamFunction interface for dealing with parameters
0056       Specific parameteric function classes should derive from this class if they want to profit from
0057       default implementations for the abstract methods.
0058       The derived classes need to implement only the DoEvalPar( x, p) and Clone() methods for non-gradient
0059       parameteric functions or DoParameterDerivative(x,p,ipar) for gradient par functions
0060 
0061 
0062       @ingroup ParamFunc
0063    */
0064 
0065 
0066 template <class IPFType>
0067 class ParamFunction : public IPFType  {
0068 
0069 public:
0070 
0071    typedef IPFType           BaseParFunc;
0072    typedef typename IPFType::BaseFunc BaseFunc;
0073 
0074    /**
0075       Construct a parameteric function with npar parameters
0076       @param npar number of parameters (default is zero)
0077    */
0078    ParamFunction(unsigned int npar = 0) :
0079       fNpar(npar),
0080       fParams( std::vector<double>(npar) )
0081    {  }
0082 
0083 
0084    // destructor
0085    virtual ~ParamFunction() {}
0086 
0087 
0088    // copying constructors (can use default ones)
0089 
0090 
0091 
0092 
0093    /**
0094       Access the parameter values
0095    */
0096    virtual const double * Parameters() const { return &fParams.front(); }
0097 
0098    /**
0099       Set the parameter values
0100       @param p vector of doubles containing the parameter values.
0101    */
0102    virtual void SetParameters(const double * p)
0103    {
0104       //fParams = std::vector<double>(p,p+fNpar);
0105       assert(fParams.size() == fNpar);
0106       std::copy(p,p+fNpar,fParams.begin());
0107    }
0108 
0109    /**
0110       Return the number of parameters
0111    */
0112    unsigned int NPar() const { return fNpar; }
0113 
0114 
0115    //using BaseFunc::operator();
0116 
0117    /**
0118       Return \a true if the calculation of derivatives is implemented
0119    */
0120 //   bool ProvidesGradient() const {  return fProvGrad; }
0121 
0122    /**
0123       Return \a true if the calculation of derivatives with respect to the Parameters is implemented
0124    */
0125    //bool ProvidesParameterGradient() const {  return fProvParGrad; }
0126 
0127 //    const std::vector<double> & GetParGradient( double x) {
0128 //       BaseParFunc::ParameterGradient(x,&fParGradient[0]);
0129 //       return fParGradient;
0130 //    }
0131 
0132 
0133 
0134 private:
0135 
0136    // cache number of Parameters for speed efficiency
0137    unsigned int fNpar;
0138 
0139 protected:
0140 
0141    // Parameters (make protected to be accessible directly by derived classes)
0142    std::vector<double> fParams;
0143 
0144 };
0145 
0146 } // namespace Math
0147 } // namespace ROOT
0148 
0149 #endif /* ROOT_Math_ParamFunction */