ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaussFunction.h
Go to the documentation of this file.
1 
2 #include "Math/IParamFunction.h"
3 #include <cmath>
4 
5 
7 
8 public:
9 
10  enum {
11  kNPar = 3
12  };
13 
14  GaussFunction(double amp = 1, double mean = 0, double sigma = 1) {
15  fParams[0] = amp;
16  fParams[1] = mean;
17  fParams[2] = sigma;
18  fLogAmp = std::log(amp);
19  }
20 
21  unsigned int NDim() const { return 1; }
22 
23  unsigned int NPar() const { return kNPar; }
24 
25  inline double amp() const { return fParams[0]; }
26  inline double logamp() const { return fLogAmp; }
27  inline double mean() const { return fParams[1]; }
28  inline double sigma() const { return fParams[2]; }
29 
30  const double * Parameters() const { return fParams; }
31 
32  void SetParameters(const double * p) { std::copy(p,p+kNPar,fParams); /* fLogAmp = std::log( p[0] ); */ }
33 
34 
35  ROOT::Math::IMultiGenFunction * Clone() const { return new GaussFunction(amp(), mean(), sigma() ); }
36 
37 
38  // implementing this is much faster
39  double operator()(const double *x, const double * p) {
40  double y = (x[0]-p[1])/p[2];
41  return p[0]*std::exp(-0.5*y*y);
42  }
43 
44  using ROOT::Math::IParamMultiGradFunction::operator();
45 
46  void ParameterGradient(const double *x, const double * p, double * g) const {
47  double a = p[0];
48  double m = p[1];
49  double s = p[2];
50  double y = (x[0]- m )/s;
51  g[0] = std::exp(-0.5*y*y);
52  g[1] = a *g[0]*y/s;
53  g[2] = g[1]*y;
54  }
55 
56 
57 private:
58 
59 
60  double DoEvalPar(const double * x, const double * p) const {
61  double a = p[0];
62  double m = p[1];
63  double s = p[2];
64  double y = (x[0]-m)/s;
65  return a*std::exp(-0.5*y*y);
66  }
67 
68  double DoDerivative(const double *x, unsigned int icoord) const {
69  (void)icoord;
70  assert (icoord == 0);
71  double dGdx = -(*this)(x) * (x[0]-mean())/(sigma()*sigma());
72  return dGdx;
73  }
74 
75  double DoParameterDerivative(const double *x, const double * p, unsigned int ipar) const {
76  double grad[3];
77  ParameterGradient(x, p, &grad[0] );
78  return grad[ipar];
79  }
80 
81 
82  double fParams[kNPar];
83  double fLogAmp;
84 };
void grad()
Definition: grad.C:17
#define assert(cond)
Definition: unittest.h:542
GaussFunction(double amp=1, double mean=0, double sigma=1)
Definition: GaussFunction.h:14
void ParameterGradient(const double *x, const double *p, double *g) const
Evaluate the all the derivatives (gradient vector) of the function with respect to the parameters at ...
Definition: GaussFunction.h:46
TArc * a
Definition: textangle.C:12
double sigma() const
Definition: GaussFunction.h:28
Double_t x[n]
Definition: legend1.C:17
double DoEvalPar(const double *x, const double *p) const
Implementation of the evaluation function using the x values and the parameters.
Definition: GaussFunction.h:60
const double * Parameters() const
Access the parameter values.
Definition: GaussFunction.h:30
double mean() const
Definition: GaussFunction.h:27
TMarker * m
Definition: textangle.C:8
double fParams[kNPar]
Definition: GaussFunction.h:82
void SetParameters(const double *p)
Set the parameter values.
Definition: GaussFunction.h:32
double logamp() const
Definition: GaussFunction.h:26
double DoParameterDerivative(const double *x, const double *p, unsigned int ipar) const
Evaluate the partial derivative w.r.t a parameter ipar , to be implemented by the derived classes...
Definition: GaussFunction.h:75
Interface (abstract class) for parametric gradient multi-dimensional functions providing in addition ...
double amp() const
Definition: GaussFunction.h:25
Double_t y[n]
Definition: legend1.C:17
unsigned int NPar() const
Return the number of Parameters.
Definition: GaussFunction.h:23
ROOT::Math::IMultiGenFunction * Clone() const
Clone a function.
Definition: GaussFunction.h:35
typedef void((*Func_t)())
double operator()(const double *x, const double *p)
Definition: GaussFunction.h:39
unsigned int NDim() const
Retrieve the dimension of the function.
Definition: GaussFunction.h:21
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63
double exp(double)
double log(double)
double DoDerivative(const double *x, unsigned int icoord) const
Definition: GaussFunction.h:68