CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Gaussian.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: Gaussian.cc,v 1.8 2010/06/16 18:22:01 garren Exp $
6#include <assert.h>
7#include <cmath> // for exp()
8
9#if (defined __STRICT_ANSI__) || (defined _WIN32)
10#ifndef M_PI
11#define M_PI 3.14159265358979323846
12#endif // M_PI
13#endif // __STRICT_ANSI__
14
15namespace Genfun {
16FUNCTION_OBJECT_IMP(Gaussian)
17
19 _mean("Mean", 0.0,-10,10),
20 _sigma("Sigma",1.0,0, 10)
21{}
22
25
27AbsFunction(right),
28_mean(right._mean),
29_sigma(right._sigma)
30{
31}
32
33double Gaussian::operator() (double x) const {
34 double s = _sigma.getValue();
35 double x0 = _mean.getValue();
36 return (1.0/(sqrt(2*M_PI)*s))*
37 exp(-(x-x0)*(x-x0)/(2.0*s*s));
38}
39
41 return _mean;
42}
43
45 return _sigma;
46}
47
48const Parameter & Gaussian::mean() const {
49 return _mean;
50}
51
52const Parameter & Gaussian::sigma() const {
53 return _sigma;
54}
55
56
57
58Derivative Gaussian::partial(unsigned int index) const {
59 assert(index==0);
60 Variable x;
61 const AbsFunction & fPrime = (*this)*(_mean-x)/_sigma/_sigma;
62 return Derivative(&fPrime);
63}
64
65} // namespace Genfun
#define FUNCTION_OBJECT_IMP(classname)
Parameter & mean()
Definition Gaussian.cc:40
virtual double operator()(double argument) const
Definition Gaussian.cc:33
Derivative partial(unsigned int) const
Definition Gaussian.cc:58
virtual ~Gaussian()
Definition Gaussian.cc:23
Parameter & sigma()
Definition Gaussian.cc:44
virtual double getValue() const
Definition Parameter.cc:27