CMS 3D CMS Logo

Gaussian.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_Gaussian_h
2 #define PhysicsTools_Utilities_Gaussian_h
4 
5 #include <cmath>
6 
7 namespace funct {
8 
9  const double oneOverSqrtTwoPi = 1 / sqrt(2 * M_PI);
10 
11  struct Gaussian {
12  Gaussian(const Parameter& m, const Parameter& s) : mean(m.ptr()), sigma(s.ptr()) {}
13  Gaussian(std::shared_ptr<double> m, std::shared_ptr<double> s) : mean(m), sigma(s) {}
14  Gaussian(double m, double s) : mean(new double(m)), sigma(new double(s)) {}
15  double operator()(double x) const {
16  double z = (x - *mean) / *sigma;
17  if (fabs(z) > 8)
18  return 0;
19  return oneOverSqrtTwoPi / *sigma * exp(-z * z / 2);
20  }
21  std::shared_ptr<double> mean, sigma;
22  };
23 
24 } // namespace funct
25 
26 #endif
Definition: Abs.h:5
const double oneOverSqrtTwoPi
Definition: Gaussian.h:9
std::shared_ptr< double > sigma
Definition: Gaussian.h:21
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
double operator()(double x) const
Definition: Gaussian.h:15
Sqrt< T >::type sqrt(const T &t)
Definition: Sqrt.h:22
Gaussian(const Parameter &m, const Parameter &s)
Definition: Gaussian.h:12
Gaussian(double m, double s)
Definition: Gaussian.h:14
#define M_PI
std::shared_ptr< double > mean
Definition: Gaussian.h:21
float x
Gaussian(std::shared_ptr< double > m, std::shared_ptr< double > s)
Definition: Gaussian.h:13