ParamFunction.h

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: ParamFunction.h 30749 2009-10-15 16:33:04Z brun $
00002 // Authors: L. Moneta, A. Zsenei   08/2005 
00003 
00004  /**********************************************************************
00005   *                                                                    *
00006   * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
00007   *                                                                    *
00008   * This library is free software; you can redistribute it and/or      *
00009   * modify it under the terms of the GNU General Public License        *
00010   * as published by the Free Software Foundation; either version 2     *
00011   * of the License, or (at your option) any later version.             *
00012   *                                                                    *
00013   * This library is distributed in the hope that it will be useful,    *
00014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00016   * General Public License for more details.                           *
00017   *                                                                    *
00018   * You should have received a copy of the GNU General Public License  *
00019   * along with this library (see file COPYING); if not, write          *
00020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00022   *                                                                    *
00023   **********************************************************************/
00024 
00025 // Header file for class ParamFunction
00026 //
00027 // Base class for Parametric functions
00028 // 
00029 // Created by: Lorenzo Moneta  at Wed Nov 10 16:38:34 2004
00030 // 
00031 // Last update: Wed Nov 10 16:38:34 2004
00032 // 
00033 #ifndef ROOT_Math_ParamFunction
00034 #define ROOT_Math_ParamFunction
00035 
00036 
00037 #ifndef ROOT_Math_IParamFunction
00038 #include "Math/IParamFunction.h"
00039 #endif
00040 
00041 #include <vector>
00042 
00043 namespace ROOT {
00044 namespace Math {
00045 
00046 //_____________________________________________________________________________________
00047    /** 
00048       Base template class for all Parametric Functions.
00049       The template argument is the type of parameteric function interface is implementing like
00050       Parameteric 1D, Multi-Dim or gradient parametric. 
00051 
00052       A parameteric function is a Generic Function with parameters, so 
00053       it is a function object which carries a state, the parameters. 
00054       The parameters are described with a standard vector of doubles.
00055 
00056       This class contains the default implementations for the methods defined in the 
00057       IParamFunction interface for dealing with parameters 
00058       Specific parameteric function classes should derive from this class if they want to profit from 
00059       default implementations for the abstract methods. 
00060       The derived classes need to implement only the DoEvalPar( x, p) and Clone() methods for non-gradient 
00061       parameteric functions or DoParameterDerivative(x,p,ipar) for gradient par functions
00062       
00063 
00064       @ingroup ParamFunc
00065    */
00066 
00067 
00068 template <class IPFType>    
00069 class ParamFunction : public IPFType  {
00070 
00071 public: 
00072 
00073    typedef IPFType           BaseParFunc; 
00074    typedef typename IPFType::BaseFunc BaseFunc; 
00075 
00076    /**
00077       Construct a parameteric function with npar parameters
00078       @param npar number of parameters (default is zero)
00079    */
00080    ParamFunction(unsigned int npar = 0) : 
00081       fNpar(npar),  
00082       fParams( std::vector<double>(npar) ) 
00083    {  }
00084 
00085     
00086    // destructor
00087    virtual ~ParamFunction() {}
00088 
00089 
00090    // copying constructors (can use default ones) 
00091 
00092 
00093 
00094     
00095    /**
00096       Access the parameter values
00097    */
00098    virtual const double * Parameters() const { return &fParams.front(); } 
00099 
00100    /**
00101       Set the parameter values
00102       @param p vector of doubles containing the parameter values. 
00103    */
00104    virtual void SetParameters(const double * p)
00105    { 
00106       //fParams = std::vector<double>(p,p+fNpar);
00107       assert(fParams.size() == fNpar);
00108       std::copy(p,p+fNpar,fParams.begin());
00109    } 
00110 
00111    /**
00112       Return the number of parameters
00113    */
00114    unsigned int NPar() const { return fNpar; } 
00115 
00116 
00117    //using BaseFunc::operator();
00118 
00119    /**
00120       Return \a true if the calculation of derivatives is implemented
00121    */
00122 //   bool ProvidesGradient() const {  return fProvGrad; } 
00123 
00124    /**
00125       Return \a true if the calculation of derivatives with respect to the Parameters is implemented
00126    */
00127    //bool ProvidesParameterGradient() const {  return fProvParGrad; } 
00128 
00129 //    const std::vector<double> & GetParGradient( double x) { 
00130 //       BaseParFunc::ParameterGradient(x,&fParGradient[0]);
00131 //       return fParGradient; 
00132 //    } 
00133 
00134 
00135 
00136 private: 
00137 
00138    // cache number of Parameters for speed efficiency
00139    unsigned int fNpar; 
00140 
00141 protected: 
00142   
00143    // Parameters (make protected to be accessible directly by derived classes) 
00144    std::vector<double> fParams;
00145 
00146 }; 
00147 
00148 } // namespace Math
00149 } // namespace ROOT
00150 
00151 #endif /* ROOT_Math_ParamFunction */

Generated on Tue Jul 5 14:25:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1