File indexing completed on 2024-04-06 12:24:18
0001 #ifndef PhysicsTools_Utilities_Gaussian_h
0002 #define PhysicsTools_Utilities_Gaussian_h
0003 #include "PhysicsTools/Utilities/interface/Parameter.h"
0004
0005 #include <cmath>
0006
0007 namespace funct {
0008
0009 const double oneOverSqrtTwoPi = 1 / sqrt(2 * M_PI);
0010
0011 struct Gaussian {
0012 Gaussian(const Parameter& m, const Parameter& s) : mean(m.ptr()), sigma(s.ptr()) {}
0013 Gaussian(std::shared_ptr<double> m, std::shared_ptr<double> s) : mean(m), sigma(s) {}
0014 Gaussian(double m, double s) : mean(new double(m)), sigma(new double(s)) {}
0015 double operator()(double x) const {
0016 double z = (x - *mean) / *sigma;
0017 if (fabs(z) > 8)
0018 return 0;
0019 return oneOverSqrtTwoPi / *sigma * exp(-z * z / 2);
0020 }
0021 std::shared_ptr<double> mean, sigma;
0022 };
0023
0024 }
0025
0026 #endif