19 return "RandGaussZiggurat";
24 const double rzm1 = 2147483648.0, rzm2 = 4294967296.;
25 double dn=3.442619855899,tn=dn,vn=9.91256303526217e-3, q;
26 double de=7.697117470131487, te=de, ve=3.949659822581572e-3;
30 q=vn/std::exp(-.5*dn*dn);
31 kn[0]=(
unsigned long)((dn/q)*rzm1);
38 fn[127]=std::exp(-.5*dn*dn);
41 dn=std::sqrt(-2.*std::log(vn/dn+std::exp(-.5*dn*dn)));
42 kn[i+1]=(
unsigned long)((dn/tn)*rzm1);
44 fn[i]=std::exp(-.5*dn*dn);
50 ke[0]=(
unsigned long)((de/q)*rzm2);
57 fe[255]=std::exp(-de);
60 de=-std::log(ve/de+std::exp(-de));
61 ke[i+1]= (
unsigned long)((de/te)*rzm2);
76 const float r = 3.442620f;
78 unsigned long iz=hz&127;
89 return (hz>0)? r+x : -r-x;
92 if(
fn[iz]+(1.0 -
ziggurat_UNI(anEngine))*(
fn[iz-1]-
fn[iz]) < std::exp(-.5*x*x) )
return x;
97 if((
unsigned long)std::abs(hz)<
kn[iz])
return (hz*
wn[iz]);
111 for (
int i=0; i<size; ++i) {
112 vect[i] =
shoot(mean,stdDev);
118 for (
int i=0; i<size; ++i) {
119 vect[i] =
shoot(mean,stdDev);
125 for (
int i=0; i<size; ++i) {
126 vect[i] =
shoot(anEngine,mean,stdDev);
132 for (
int i=0; i<size; ++i) {
133 vect[i] =
shoot(anEngine,mean,stdDev);
139 for (
int i=0; i<size; ++i) {
146 for (
int i=0; i<size; ++i) {
153 for (
int i=0; i<size; ++i) {
154 vect[i] =
fire( mean, stdDev );
160 for (
int i=0; i<size; ++i) {
161 vect[i] =
fire( mean, stdDev );
166 int pr=os.precision(20);
167 os <<
" " <<
name() <<
"\n";
176 if (inName !=
name()) {
177 is.clear(std::ios::badbit | is.rdstate());
178 std::cerr <<
"Mismatch when expecting to read state of a "
179 <<
name() <<
" distribution\n"
180 <<
"Name found was " << inName
181 <<
"\nistream is left in the badbit state\n";
static void shootArray(const int size, float *vect, float mean=0.0, float stdDev=1.0)
static CLHEP_THREAD_LOCAL unsigned long ke[256]
std::istream & get(std::istream &is)
static bool ziggurat_init()
void fireArray(const int size, float *vect)
static float ziggurat_nfix(long hz, HepRandomEngine *anEngine)
static float ziggurat_UNI(HepRandomEngine *anEngine)
static CLHEP_THREAD_LOCAL float fn[128]
std::ostream & put(std::ostream &os) const
static float ziggurat_RNOR(HepRandomEngine *anEngine)
virtual double operator()()
static CLHEP_THREAD_LOCAL unsigned long kn[128]
static CLHEP_THREAD_LOCAL float fe[256]
HepRandomEngine & engine()
static CLHEP_THREAD_LOCAL float we[256]
virtual ~RandGaussZiggurat()
static unsigned long ziggurat_SHR3(HepRandomEngine *anEngine)
static CLHEP_THREAD_LOCAL float wn[128]
static CLHEP_THREAD_LOCAL bool ziggurat_is_init
std::istream & get(std::istream &is)
std::ostream & put(std::ostream &os) const
HepRandomEngine & engine()
std::shared_ptr< HepRandomEngine > localEngine
#define CLHEP_THREAD_LOCAL