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 
15 namespace Genfun {
16 FUNCTION_OBJECT_IMP(Gaussian)
17 
19  _mean("Mean", 0.0,-10,10),
20  _sigma("Sigma",1.0,0, 10)
21 {}
22 
24 }
25 
27 _mean(right._mean),
28 _sigma(right._sigma)
29 {
30 }
31 
32 double Gaussian::operator() (double x) const {
33  double s = _sigma.getValue();
34  double x0 = _mean.getValue();
35  return (1.0/(sqrt(2*M_PI)*s))*
36  exp(-(x-x0)*(x-x0)/(2.0*s*s));
37 }
38 
40  return _mean;
41 }
42 
44  return _sigma;
45 }
46 
47 const Parameter & Gaussian::mean() const {
48  return _mean;
49 }
50 
51 const Parameter & Gaussian::sigma() const {
52  return _sigma;
53 }
54 
55 
56 
57 Derivative Gaussian::partial(unsigned int index) const {
58  assert(index==0);
59  Variable x;
60  const AbsFunction & fPrime = (*this)*(_mean-x)/_sigma/_sigma;
61  return Derivative(&fPrime);
62 }
63 
64 } // namespace Genfun