File indexing completed on 2024-06-26 07:05:02
0001 #include <string>
0002 #include <cassert>
0003 #include <stdexcept>
0004 #include <map>
0005
0006 #include "Smearer.hh"
0007
0008 ab::Smearer::Smearer(unsigned int seed) :
0009 m_generator(gsl_rng_alloc(gsl_rng_mt19937))
0010 {
0011 gsl_rng_set(m_generator.get(), seed);
0012 }
0013
0014 double ab::Smearer::smear(const double position, const double width, SmearFuncs dist) const {
0015 assert(width >= 0);
0016
0017 double res = position;
0018
0019 if (width == 0)
0020 return res;
0021
0022 if (dist == SmearFuncs::Uniform) {
0023 return (position - width) + 2 * gsl_rng_uniform_pos(m_generator.get()) * width;
0024 }
0025
0026 if (dist == SmearFuncs::Gauss) {
0027 return position + gsl_ran_gaussian(m_generator.get(), width);
0028 }
0029
0030 std::string err_msg = "Unknown vertex function";
0031 throw std::runtime_error(err_msg);
0032 }
0033
0034 double ab::Smearer::gauss(double mean, double width) const {
0035 return mean + gsl_ran_gaussian(m_generator.get(), width);
0036 }
0037
0038 double ab::Smearer::gauss(double width) const {
0039 return gsl_ran_gaussian(m_generator.get(), width);
0040 }
0041
0042
0043 std::string ab::smear_func_to_str(ab::SmearFuncs smear_func) {
0044 static std::map <SmearFuncs, std::string> funcs_str_map = {{ab::SmearFuncs::Uniform, "Uniform"}, {ab::SmearFuncs::Gauss, "Gauss"}};
0045 return funcs_str_map[smear_func];
0046 }