npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
GaussianDip.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_GAUSSIANDIP_HH_
2 #define NPSTAT_GAUSSIANDIP_HH_
3 
4 /*!
5 // \file GaussianDip.hh
6 //
7 // \brief "Gaussian dip" function, intended for use in generating
8 // random numbers with acceptance-rejection
9 //
10 // Author: I. Volobouev
11 //
12 // June 2022
13 */
14 
15 #include <cmath>
16 #include <stdexcept>
17 
19 
20 namespace npstat {
21  class GaussianDip : public Functor1<double, double>
22  {
23  public:
24  inline GaussianDip(const double mu, const double sigma, const double a)
25  : mu_(mu), sigma_(sigma), amplitude_(a)
26  {
27  if (sigma_ <= 0.0) throw std::invalid_argument(
28  "In npstat::GaussianDip constructor: sigma must be positive");
29  if (amplitude_ < -1.0) throw std::invalid_argument(
30  "In npstat::GaussianDip constructor: amplitude out of range");
31  }
32 
33  inline virtual ~GaussianDip() {}
34 
35  inline double operator()(const double& x) const
36  {
37  const double delta = (x - mu_)/sigma_;
38  const double f = 1.0 + amplitude_*std::exp(-delta*delta/2.0);
39  if (amplitude_ > 0.0)
40  return 1.0/f;
41  else
42  return f;
43  }
44 
45  private:
46  double mu_;
47  double sigma_;
48  double amplitude_;
49  };
50 }
51 
52 #endif // NPSTAT_GAUSSIANDIP_HH_
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Definition: GaussianDip.hh:22
Definition: AbsArrayProjector.hh:14
Definition: SimpleFunctors.hh:58