12#include "CLHEP/Random/defs.h"
13#include "CLHEP/Random/RandGaussZiggurat.h"
14#include "CLHEP/Units/PhysicalConstants.h"
31 return "RandGaussZiggurat";
36 const double rzm1 = 2147483648.0, rzm2 = 4294967296.;
37 double dn=3.442619855899,tn=dn,vn=9.91256303526217e-3, q;
38 double de=7.697117470131487, te=de, ve=3.949659822581572e-3;
43 kn[0]=(
unsigned long)((dn/q)*rzm1);
50 fn[127]=exp(-.5*dn*dn);
53 dn=sqrt(-2.*log(vn/dn+exp(-.5*dn*dn)));
54 kn[i+1]=(
unsigned long)((dn/tn)*rzm1);
62 ke[0]=(
unsigned long)((de/q)*rzm2);
72 de=-log(ve/de+exp(-de));
73 ke[i+1]= (
unsigned long)((de/te)*rzm2);
88 const float r = 3.442620f;
90 unsigned long iz=hz&127;
101 return (hz>0)? r+x : -r-x;
104 if(
fn[iz]+(1.0 -
ziggurat_UNI(anEngine))*(
fn[iz-1]-
fn[iz]) < exp(-.5*x*x) )
return x;
109 if((
unsigned long)std::abs(hz)<
kn[iz])
return (hz*
wn[iz]);
123 for (
int i=0; i<size; ++i) {
124 vect[i] =
shoot(mean,stdDev);
130 for (
int i=0; i<size; ++i) {
131 vect[i] =
shoot(mean,stdDev);
137 for (
int i=0; i<size; ++i) {
138 vect[i] =
shoot(anEngine,mean,stdDev);
144 for (
int i=0; i<size; ++i) {
145 vect[i] =
shoot(anEngine,mean,stdDev);
151 for (
int i=0; i<size; ++i) {
158 for (
int i=0; i<size; ++i) {
165 for (
int i=0; i<size; ++i) {
166 vect[i] =
fire( mean, stdDev );
172 for (
int i=0; i<size; ++i) {
173 vect[i] =
fire( mean, stdDev );
178 long pr=os.precision(20);
179 os <<
" " <<
name() <<
"\n";
188 if (inName !=
name()) {
189 is.clear(std::ios::badbit | is.rdstate());
190 std::cerr <<
"Mismatch when expecting to read state of a "
191 <<
name() <<
" distribution\n"
192 <<
"Name found was " << inName
193 <<
"\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