CMS 3D CMS Logo

GaussianTail.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 GaussianTail::GaussianTail(double sigma, double threshold) : sigma_(sigma), threshold_(threshold) {
6  s_ = threshold_ / sigma_;
7  ssquare_ = s_ * s_;
8 }
9 
11 
12 double GaussianTail::shoot(RandomEngineAndDistribution const* random) const {
13  // in the zero suppresion case, s is usually >2
14  if (s_ > 1.) {
15  /* Use the "supertail" deviates from the last two steps
16  * of Marsaglia's rectangle-wedge-tail method, as described
17  * in Knuth, v2, 3rd ed, pp 123-128. (See also exercise 11, p139,
18  * and the solution, p586.)
19  */
20 
21  double u, v, x;
22 
23  do {
24  u = random->flatShoot();
25  do {
26  v = random->flatShoot();
27  } while (v == 0.0);
28  x = std::sqrt(ssquare_ - 2 * std::log(v));
29  } while (x * u > s_);
30  return x * sigma_;
31  } else {
32  /* For small s, use a direct rejection method. The limit s < 1
33  can be adjusted to optimise the overall efficiency
34  */
35 
36  double x;
37 
38  do {
39  x = random->gaussShoot();
40  } while (x < s_);
41  return x * sigma_;
42  }
43 }
double threshold_
Definition: GaussianTail.h:24
double shoot(RandomEngineAndDistribution const *) const
Definition: GaussianTail.cc:12
T sqrt(T t)
Definition: SSEVec.h:23
GaussianTail(double sigma=1., double threshold=2.)
Definition: GaussianTail.cc:5
double sigma_
Definition: GaussianTail.h:23
double gaussShoot(double mean=0.0, double sigma=1.0) const
double ssquare_
Definition: GaussianTail.h:26
double flatShoot(double xmin=0.0, double xmax=1.0) const