ROOT logo
// @(#)root/mathmore:$Id: ParamFunction.h 30749 2009-10-15 16:33:04Z brun $
// Authors: L. Moneta, A. Zsenei   08/2005 

 /**********************************************************************
  *                                                                    *
  * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
  *                                                                    *
  * This library is free software; you can redistribute it and/or      *
  * modify it under the terms of the GNU General Public License        *
  * as published by the Free Software Foundation; either version 2     *
  * of the License, or (at your option) any later version.             *
  *                                                                    *
  * This library is distributed in the hope that it will be useful,    *
  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
  * General Public License for more details.                           *
  *                                                                    *
  * You should have received a copy of the GNU General Public License  *
  * along with this library (see file COPYING); if not, write          *
  * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
  * 330, Boston, MA 02111-1307 USA, or contact the author.             *
  *                                                                    *
  **********************************************************************/

// Header file for class ParamFunction
//
// Base class for Parametric functions
// 
// Created by: Lorenzo Moneta  at Wed Nov 10 16:38:34 2004
// 
// Last update: Wed Nov 10 16:38:34 2004
// 
#ifndef ROOT_Math_ParamFunction
#define ROOT_Math_ParamFunction


#ifndef ROOT_Math_IParamFunction
#include "Math/IParamFunction.h"
#endif

#include <vector>

namespace ROOT {
namespace Math {

//_____________________________________________________________________________________
   /** 
      Base template class for all Parametric Functions.
      The template argument is the type of parameteric function interface is implementing like
      Parameteric 1D, Multi-Dim or gradient parametric. 

      A parameteric function is a Generic Function with parameters, so 
      it is a function object which carries a state, the parameters. 
      The parameters are described with a standard vector of doubles.

      This class contains the default implementations for the methods defined in the 
      IParamFunction interface for dealing with parameters 
      Specific parameteric function classes should derive from this class if they want to profit from 
      default implementations for the abstract methods. 
      The derived classes need to implement only the DoEvalPar( x, p) and Clone() methods for non-gradient 
      parameteric functions or DoParameterDerivative(x,p,ipar) for gradient par functions
      

      @ingroup ParamFunc
   */


template <class IPFType>    
class ParamFunction : public IPFType  {

public: 

   typedef IPFType           BaseParFunc; 
   typedef typename IPFType::BaseFunc BaseFunc; 

   /**
      Construct a parameteric function with npar parameters
      @param npar number of parameters (default is zero)
   */
   ParamFunction(unsigned int npar = 0) : 
      fNpar(npar),  
      fParams( std::vector<double>(npar) ) 
   {  }

    
   // destructor
   virtual ~ParamFunction() {}


   // copying constructors (can use default ones) 



    
   /**
      Access the parameter values
   */
   virtual const double * Parameters() const { return &fParams.front(); } 

   /**
      Set the parameter values
      @param p vector of doubles containing the parameter values. 
   */
   virtual void SetParameters(const double * p)
   { 
      //fParams = std::vector<double>(p,p+fNpar);
      assert(fParams.size() == fNpar);
      std::copy(p,p+fNpar,fParams.begin());
   } 

   /**
      Return the number of parameters
   */
   unsigned int NPar() const { return fNpar; } 


   //using BaseFunc::operator();

   /**
      Return \a true if the calculation of derivatives is implemented
   */
//   bool ProvidesGradient() const {  return fProvGrad; } 

   /**
      Return \a true if the calculation of derivatives with respect to the Parameters is implemented
   */
   //bool ProvidesParameterGradient() const {  return fProvParGrad; } 

//    const std::vector<double> & GetParGradient( double x) { 
//       BaseParFunc::ParameterGradient(x,&fParGradient[0]);
//       return fParGradient; 
//    } 



private: 

   // cache number of Parameters for speed efficiency
   unsigned int fNpar; 

protected: 
  
   // Parameters (make protected to be accessible directly by derived classes) 
   std::vector<double> fParams;

}; 

} // namespace Math
} // namespace ROOT

#endif /* ROOT_Math_ParamFunction */
 ParamFunction.h:1
 ParamFunction.h:2
 ParamFunction.h:3
 ParamFunction.h:4
 ParamFunction.h:5
 ParamFunction.h:6
 ParamFunction.h:7
 ParamFunction.h:8
 ParamFunction.h:9
 ParamFunction.h:10
 ParamFunction.h:11
 ParamFunction.h:12
 ParamFunction.h:13
 ParamFunction.h:14
 ParamFunction.h:15
 ParamFunction.h:16
 ParamFunction.h:17
 ParamFunction.h:18
 ParamFunction.h:19
 ParamFunction.h:20
 ParamFunction.h:21
 ParamFunction.h:22
 ParamFunction.h:23
 ParamFunction.h:24
 ParamFunction.h:25
 ParamFunction.h:26
 ParamFunction.h:27
 ParamFunction.h:28
 ParamFunction.h:29
 ParamFunction.h:30
 ParamFunction.h:31
 ParamFunction.h:32
 ParamFunction.h:33
 ParamFunction.h:34
 ParamFunction.h:35
 ParamFunction.h:36
 ParamFunction.h:37
 ParamFunction.h:38
 ParamFunction.h:39
 ParamFunction.h:40
 ParamFunction.h:41
 ParamFunction.h:42
 ParamFunction.h:43
 ParamFunction.h:44
 ParamFunction.h:45
 ParamFunction.h:46
 ParamFunction.h:47
 ParamFunction.h:48
 ParamFunction.h:49
 ParamFunction.h:50
 ParamFunction.h:51
 ParamFunction.h:52
 ParamFunction.h:53
 ParamFunction.h:54
 ParamFunction.h:55
 ParamFunction.h:56
 ParamFunction.h:57
 ParamFunction.h:58
 ParamFunction.h:59
 ParamFunction.h:60
 ParamFunction.h:61
 ParamFunction.h:62
 ParamFunction.h:63
 ParamFunction.h:64
 ParamFunction.h:65
 ParamFunction.h:66
 ParamFunction.h:67
 ParamFunction.h:68
 ParamFunction.h:69
 ParamFunction.h:70
 ParamFunction.h:71
 ParamFunction.h:72
 ParamFunction.h:73
 ParamFunction.h:74
 ParamFunction.h:75
 ParamFunction.h:76
 ParamFunction.h:77
 ParamFunction.h:78
 ParamFunction.h:79
 ParamFunction.h:80
 ParamFunction.h:81
 ParamFunction.h:82
 ParamFunction.h:83
 ParamFunction.h:84
 ParamFunction.h:85
 ParamFunction.h:86
 ParamFunction.h:87
 ParamFunction.h:88
 ParamFunction.h:89
 ParamFunction.h:90
 ParamFunction.h:91
 ParamFunction.h:92
 ParamFunction.h:93
 ParamFunction.h:94
 ParamFunction.h:95
 ParamFunction.h:96
 ParamFunction.h:97
 ParamFunction.h:98
 ParamFunction.h:99
 ParamFunction.h:100
 ParamFunction.h:101
 ParamFunction.h:102
 ParamFunction.h:103
 ParamFunction.h:104
 ParamFunction.h:105
 ParamFunction.h:106
 ParamFunction.h:107
 ParamFunction.h:108
 ParamFunction.h:109
 ParamFunction.h:110
 ParamFunction.h:111
 ParamFunction.h:112
 ParamFunction.h:113
 ParamFunction.h:114
 ParamFunction.h:115
 ParamFunction.h:116
 ParamFunction.h:117
 ParamFunction.h:118
 ParamFunction.h:119
 ParamFunction.h:120
 ParamFunction.h:121
 ParamFunction.h:122
 ParamFunction.h:123
 ParamFunction.h:124
 ParamFunction.h:125
 ParamFunction.h:126
 ParamFunction.h:127
 ParamFunction.h:128
 ParamFunction.h:129
 ParamFunction.h:130
 ParamFunction.h:131
 ParamFunction.h:132
 ParamFunction.h:133
 ParamFunction.h:134
 ParamFunction.h:135
 ParamFunction.h:136
 ParamFunction.h:137
 ParamFunction.h:138
 ParamFunction.h:139
 ParamFunction.h:140
 ParamFunction.h:141
 ParamFunction.h:142
 ParamFunction.h:143
 ParamFunction.h:144
 ParamFunction.h:145
 ParamFunction.h:146
 ParamFunction.h:147
 ParamFunction.h:148
 ParamFunction.h:149
 ParamFunction.h:150
 ParamFunction.h:151