21#include "CLHEP/Random/Stat.h"
22#include "CLHEP/Random/defs.h"
23#include "CLHEP/Units/PhysicalConstants.h"
52#define Table4size 1000
53#define TableSize (Table0size+Table1size+Table2size+Table3size+Table4size)
61#define Table0step (2.0E-13)
62#define Table1step (4.0E-11)
63#define Table2step (1.0E-8)
64#define Table3step (2.0E-6)
65#define Table4step (5.0E-4)
74#define Table1offset (2*(Table0size))
75#define Table2offset (2*(Table0size + Table1size))
76#define Table3offset (2*(Table0size + Table1size + Table2size))
77#define Table4offset (2*(Table0size + Table1size + Table2size + Table3size))
87static const double gaussTables [2*
TableSize] = {
88#include "gaussTables.cdat"
98std::cout <<
"r = " << r <<
"\n";
105std::cout <<
"r = " << r <<
"sign negative \n";
107 }
else if ( r == .5 ) {
122 const double* tptr = 0;
134 if (index <= 0) index = 1;
139std::cout <<
"index = " << index <<
" dx = " << dx <<
" h = " << h <<
"\n";
146std::cout <<
"offset index = " << index <<
"\n";
149 tptr = &gaussTables [index];
151 }
else if (r < Tsteps[0]) {
158 for (
int tableN = 3; tableN >= 0; tableN-- ) {
159 if ( r < Tsteps[tableN] ) {
continue;}
161std::cout <<
"Using table " << tableN <<
"\n";
163 double step = Tsteps[tableN];
169 if (index == 0) index = 1;
170 if (index >= Tsizes[tableN]) index = Tsizes[tableN] - 1;
174std::cout <<
"index = " << index <<
" dx = " << dx <<
" h = " << h <<
"\n";
176 index = (index<<1) + Toffsets[tableN] - 2;
177 tptr = &gaussTables [index];
196std::cout <<
"y0: " << y0 <<
" y1: " << y1 <<
" d0: " << d0 <<
" d1: " << d1 <<
"\n";
200 double oneMinusX = 1 - dx;
201 double oneMinusX2 = oneMinusX * oneMinusX;
203 double f0 = (2. * dx + 1.) * oneMinusX2;
204 double f1 = (3. - 2. * dx) * x2;
205 double g0 = h * dx * oneMinusX2;
206 double g1 = - h * oneMinusX * x2;
209std::cout <<
"f0: " << f0 <<
" f1: " << f1 <<
" g0: " << g0 <<
" g1: " << g1 <<
"\n";
212 double answer = f0 * y0 + f1 * y1 + g0 * d0 + g1 * d1;
215std::cout <<
"variate is: " << sign*answer <<
"\n";
218 return sign * answer;
248 for (
int i = 1; i < 50; i++ ) {
249 double vn2 = 1.0/(guess*guess);
250 double s1 = -13*11*9*7*5*3 * vn2*vn2*vn2*vn2*vn2*vn2*vn2;
251 s1 += 11*9*7*5*3 * vn2*vn2*vn2*vn2*vn2*vn2;
252 s1 += -9*7*5*3 * vn2*vn2*vn2*vn2*vn2;
253 s1 += 7*5*3 * vn2*vn2*vn2*vn2;
254 s1 += -5*3 * vn2*vn2*vn2;
255 s1 += 3 * vn2*vn2 - vn2 + 1.0;
256 v = std::sqrt ( 2.0 * std::log ( s1 / (r*guess*std::sqrt(CLHEP::twopi)) ) );
257 if ( std::abs(v-guess) < eps )
break;
300 double deriv = std::exp(-x*x) * (2.0 / std::sqrt(CLHEP::pi));
static double flatToGaussian(double r)
static double erfQ(double x)
static double erf(double x)
static double inverseErf(double t)
double transformSmall(double r)