ROOT  6.06/09
Reference Guide
ParamFunction.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: L. Moneta, A. Zsenei 08/2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License *
10  * as published by the Free Software Foundation; either version 2 *
11  * of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library (see file COPYING); if not, write *
20  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21  * 330, Boston, MA 02111-1307 USA, or contact the author. *
22  * *
23  **********************************************************************/
24 
25 // Header file for class ParamFunction
26 //
27 // Base class for Parametric functions
28 //
29 // Created by: Lorenzo Moneta at Wed Nov 10 16:38:34 2004
30 //
31 // Last update: Wed Nov 10 16:38:34 2004
32 //
33 #ifndef ROOT_Math_ParamFunction
34 #define ROOT_Math_ParamFunction
35 
36 
37 #ifndef ROOT_Math_IParamFunction
38 #include "Math/IParamFunction.h"
39 #endif
40 
41 #include <vector>
42 
43 namespace ROOT {
44 namespace Math {
45 
46 //_____________________________________________________________________________________
47  /**
48  Base template class for all Parametric Functions.
49  The template argument is the type of parameteric function interface is implementing like
50  Parameteric 1D, Multi-Dim or gradient parametric.
51 
52  A parameteric function is a Generic Function with parameters, so
53  it is a function object which carries a state, the parameters.
54  The parameters are described with a standard vector of doubles.
55 
56  This class contains the default implementations for the methods defined in the
57  IParamFunction interface for dealing with parameters
58  Specific parameteric function classes should derive from this class if they want to profit from
59  default implementations for the abstract methods.
60  The derived classes need to implement only the DoEvalPar( x, p) and Clone() methods for non-gradient
61  parameteric functions or DoParameterDerivative(x,p,ipar) for gradient par functions
62 
63 
64  @ingroup ParamFunc
65  */
66 
67 
68 template <class IPFType>
69 class ParamFunction : public IPFType {
70 
71 public:
72 
73  typedef IPFType BaseParFunc;
74  typedef typename IPFType::BaseFunc BaseFunc;
75 
76  /**
77  Construct a parameteric function with npar parameters
78  @param npar number of parameters (default is zero)
79  */
80  ParamFunction(unsigned int npar = 0) :
81  fNpar(npar),
82  fParams( std::vector<double>(npar) )
83  { }
84 
85 
86  // destructor
87  virtual ~ParamFunction() {}
88 
89 
90  // copying constructors (can use default ones)
91 
92 
93 
94 
95  /**
96  Access the parameter values
97  */
98  virtual const double * Parameters() const { return &fParams.front(); }
99 
100  /**
101  Set the parameter values
102  @param p vector of doubles containing the parameter values.
103  */
104  virtual void SetParameters(const double * p)
105  {
106  //fParams = std::vector<double>(p,p+fNpar);
107  assert(fParams.size() == fNpar);
108  std::copy(p,p+fNpar,fParams.begin());
109  }
110 
111  /**
112  Return the number of parameters
113  */
114  unsigned int NPar() const { return fNpar; }
115 
116 
117  //using BaseFunc::operator();
118 
119  /**
120  Return \a true if the calculation of derivatives is implemented
121  */
122 // bool ProvidesGradient() const { return fProvGrad; }
123 
124  /**
125  Return \a true if the calculation of derivatives with respect to the Parameters is implemented
126  */
127  //bool ProvidesParameterGradient() const { return fProvParGrad; }
128 
129 // const std::vector<double> & GetParGradient( double x) {
130 // BaseParFunc::ParameterGradient(x,&fParGradient[0]);
131 // return fParGradient;
132 // }
133 
134 
135 
136 private:
137 
138  // cache number of Parameters for speed efficiency
139  unsigned int fNpar;
140 
141 protected:
142 
143  // Parameters (make protected to be accessible directly by derived classes)
144  std::vector<double> fParams;
145 
146 };
147 
148 } // namespace Math
149 } // namespace ROOT
150 
151 #endif /* ROOT_Math_ParamFunction */
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
#define assert(cond)
Definition: unittest.h:542
STL namespace.
IPFType::BaseFunc BaseFunc
Definition: ParamFunction.h:74
unsigned int fNpar
Return true if the calculation of derivatives is implemented.
virtual void SetParameters(const double *p)
Set the parameter values.
Base template class for all Parametric Functions.
Definition: ParamFunction.h:69
std::vector< double > fParams
unsigned int NPar() const
Return the number of parameters.
Namespace for new Math classes and functions.
virtual const double * Parameters() const
Access the parameter values.
Definition: ParamFunction.h:98
ParamFunction(unsigned int npar=0)
Construct a parameteric function with npar parameters.
Definition: ParamFunction.h:80