CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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 $
3#include "CLHEP/GenericFunctions/defs.h"
4#include "CLHEP/GenericFunctions/Gaussian.hh"
5#include "CLHEP/GenericFunctions/Variable.hh"
6#include <assert.h>
7#include <cmath> // for exp()
8#include <iostream>
9
10#if (defined __STRICT_ANSI__) || (defined _WIN32)
11#ifndef M_PI
12#define M_PI 3.14159265358979323846
13#endif // M_PI
14#endif // __STRICT_ANSI__
15
16namespace Genfun {
17FUNCTION_OBJECT_IMP(Gaussian)
18
20 _mean("Mean", 0.0,-10,10),
21 _sigma("Sigma",1.0,0, 10)
22{}
23
25}
26
28AbsFunction(right),
29_mean(right._mean),
30_sigma(right._sigma)
31{
32}
33
34double Gaussian::operator() (double x) const {
35 double s = _sigma.getValue();
36 double x0 = _mean.getValue();
37 return (1.0/(sqrt(2*M_PI)*s))*
38 exp(-(x-x0)*(x-x0)/(2.0*s*s));
39}
40
42 return _mean;
43}
44
46 return _sigma;
47}
48
49const Parameter & Gaussian::mean() const {
50 return _mean;
51}
52
53const Parameter & Gaussian::sigma() const {
54 return _sigma;
55}
56
57// don't generate warnings about unused parameter inside assert
58#if defined __GNUC__
59 #if __GNUC__ > 3 && __GNUC_MINOR__ > 6
60 #pragma GCC diagnostic push
61 #pragma GCC diagnostic ignored "-Wunused-parameter"
62 #endif
63#endif
64#ifdef __clang__
65 #pragma clang diagnostic push
66 #pragma clang diagnostic ignored "-Wunused-parameter"
67#endif
68Derivative Gaussian::partial(unsigned int index) const {
69 assert(index==0);
70 Variable x;
71 const AbsFunction & fPrime = (*this)*(_mean-x)/_sigma/_sigma;
72 return Derivative(&fPrime);
73}
74#if defined __GNUC__
75 #if __GNUC__ > 3 && __GNUC_MINOR__ > 6
76 #pragma GCC diagnostic pop
77 #endif
78#endif
79#ifdef __clang__
80 #pragma clang diagnostic pop
81#endif
82
83} // namespace Genfun
#define FUNCTION_OBJECT_IMP(classname)
Definition: AbsFunction.hh:149
Parameter & mean()
Definition: Gaussian.cc:41
virtual double operator()(double argument) const override
Definition: Gaussian.cc:34
virtual ~Gaussian()
Definition: Gaussian.cc:24
Derivative partial(unsigned int) const override
Definition: Gaussian.cc:68
Parameter & sigma()
Definition: Gaussian.cc:45
virtual double getValue() const
Definition: Parameter.cc:29
Definition: Abs.hh:14
FunctionNoop Derivative
Definition: AbsFunction.hh:42