CMS 3D CMS Logo

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