Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
CLHEP::RandExpZiggurat Class Reference

#include <RandExpZiggurat.h>

+ Inheritance diagram for CLHEP::RandExpZiggurat:

Public Member Functions

 RandExpZiggurat (HepRandomEngine &anEngine, double mean=1.0)
 
 RandExpZiggurat (HepRandomEngine *anEngine, double mean=1.0)
 
virtual ~RandExpZiggurat ()
 
float fire ()
 
float fire (float mean)
 
void fireArray (const int size, float *vect)
 
void fireArray (const int size, double *vect)
 
void fireArray (const int size, float *vect, float mean)
 
void fireArray (const int size, double *vect, double mean)
 
virtual double operator() ()
 
float operator() (float mean)
 
std::ostream & put (std::ostream &os) const
 
std::istream & get (std::istream &is)
 
std::string name () const
 
HepRandomEngineengine ()
 
- Public Member Functions inherited from CLHEP::HepRandom
 HepRandom ()
 
 HepRandom (long seed)
 
 HepRandom (HepRandomEngine &algorithm)
 
 HepRandom (HepRandomEngine *algorithm)
 
virtual ~HepRandom ()
 
double flat ()
 
void flatArray (const int size, double *vect)
 
double flat (HepRandomEngine *theNewEngine)
 
void flatArray (HepRandomEngine *theNewEngine, const int size, double *vect)
 
virtual double operator() ()
 
virtual std::string name () const
 
virtual HepRandomEngineengine ()
 
virtual std::ostream & put (std::ostream &os) const
 
virtual std::istream & get (std::istream &is)
 

Static Public Member Functions

static float shoot ()
 
static float shoot (float mean)
 
static void shootArray (const int size, float *vect, float mean=1.0)
 
static void shootArray (const int size, double *vect, double mean=1.0)
 
static float shoot (HepRandomEngine *anEngine)
 
static float shoot (HepRandomEngine *anEngine, float mean)
 
static void shootArray (HepRandomEngine *anEngine, const int size, float *vect, float mean=1.0)
 
static void shootArray (HepRandomEngine *anEngine, const int size, double *vect, double mean=1.0)
 
static std::string distributionName ()
 
static bool ziggurat_init ()
 
- Static Public Member Functions inherited from CLHEP::HepRandom
static void setTheSeed (long seed, int lxr=3)
 
static long getTheSeed ()
 
static void setTheSeeds (const long *seeds, int aux=-1)
 
static const long * getTheSeeds ()
 
static void getTheTableSeeds (long *seeds, int index)
 
static HepRandomgetTheGenerator ()
 
static void setTheEngine (HepRandomEngine *theNewEngine)
 
static HepRandomEnginegetTheEngine ()
 
static void saveEngineStatus (const char filename[]="Config.conf")
 
static void restoreEngineStatus (const char filename[]="Config.conf")
 
static std::ostream & saveFullState (std::ostream &os)
 
static std::istream & restoreFullState (std::istream &is)
 
static std::ostream & saveDistState (std::ostream &os)
 
static std::istream & restoreDistState (std::istream &is)
 
static std::ostream & saveStaticRandomStates (std::ostream &os)
 
static std::istream & restoreStaticRandomStates (std::istream &is)
 
static void showEngineStatus ()
 
static int createInstance ()
 
static std::string distributionName ()
 

Static Protected Member Functions

static unsigned long ziggurat_SHR3 (HepRandomEngine *anEngine)
 
static float ziggurat_UNI (HepRandomEngine *anEngine)
 
static float ziggurat_REXP (HepRandomEngine *anEngine)
 
static float ziggurat_efix (unsigned long jz, HepRandomEngine *anEngine)
 

Static Protected Attributes

static CLHEP_THREAD_LOCAL unsigned long kn [128]
 
static CLHEP_THREAD_LOCAL unsigned long ke [256]
 
static CLHEP_THREAD_LOCAL float wn [128]
 
static CLHEP_THREAD_LOCAL float fn [128]
 
static CLHEP_THREAD_LOCAL float we [256]
 
static CLHEP_THREAD_LOCAL float fe [256]
 
static CLHEP_THREAD_LOCAL bool ziggurat_is_init = false
 
- Static Protected Attributes inherited from CLHEP::HepRandom
static const long seedTable [215][2]
 

Detailed Description

Author
ATLAS

Definition at line 36 of file RandExpZiggurat.h.

Constructor & Destructor Documentation

◆ RandExpZiggurat() [1/2]

CLHEP::RandExpZiggurat::RandExpZiggurat ( HepRandomEngine anEngine,
double  mean = 1.0 
)
inline

Definition at line 158 of file RandExpZiggurat.h.

158 : localEngine(&anEngine, do_nothing_deleter()), defaultMean(mean)
159{
160}

◆ RandExpZiggurat() [2/2]

CLHEP::RandExpZiggurat::RandExpZiggurat ( HepRandomEngine anEngine,
double  mean = 1.0 
)
inline

Definition at line 162 of file RandExpZiggurat.h.

162 : localEngine(anEngine), defaultMean(mean)
163{
164}

◆ ~RandExpZiggurat()

CLHEP::RandExpZiggurat::~RandExpZiggurat ( )
virtual

Definition at line 19 of file RandExpZiggurat.cc.

19 {
20}

Member Function Documentation

◆ distributionName()

static std::string CLHEP::RandExpZiggurat::distributionName ( )
inlinestatic

Definition at line 109 of file RandExpZiggurat.h.

109{return "RandExpZiggurat";}

◆ engine()

HepRandomEngine & CLHEP::RandExpZiggurat::engine ( )
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 17 of file RandExpZiggurat.cc.

17{return *localEngine;}

◆ fire() [1/2]

float CLHEP::RandExpZiggurat::fire ( )
inline

Definition at line 85 of file RandExpZiggurat.h.

85{return fire(float(defaultMean));}

Referenced by fire(), fireArray(), and operator()().

◆ fire() [2/2]

float CLHEP::RandExpZiggurat::fire ( float  mean)
inline

Definition at line 86 of file RandExpZiggurat.h.

86{return ziggurat_REXP(localEngine.get())*mean;}
static float ziggurat_REXP(HepRandomEngine *anEngine)

◆ fireArray() [1/4]

void CLHEP::RandExpZiggurat::fireArray ( const int  size,
double *  vect 
)

Definition at line 56 of file RandExpZiggurat.cc.

57{
58 for (int i=0; i<size; ++i) vect[i] = fire( defaultMean );
59}

◆ fireArray() [2/4]

void CLHEP::RandExpZiggurat::fireArray ( const int  size,
double *  vect,
double  mean 
)

Definition at line 66 of file RandExpZiggurat.cc.

67{
68 for (int i=0; i<size; ++i) vect[i] = fire( mean );
69}

◆ fireArray() [3/4]

void CLHEP::RandExpZiggurat::fireArray ( const int  size,
float *  vect 
)

Definition at line 51 of file RandExpZiggurat.cc.

52{
53 for (int i=0; i<size; ++i) vect[i] = fire( defaultMean );
54}

◆ fireArray() [4/4]

void CLHEP::RandExpZiggurat::fireArray ( const int  size,
float *  vect,
float  mean 
)

Definition at line 61 of file RandExpZiggurat.cc.

62{
63 for (int i=0; i<size; ++i) vect[i] = fire( mean );
64}

◆ get()

std::istream & CLHEP::RandExpZiggurat::get ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 89 of file RandExpZiggurat.cc.

89 {
90 std::string inName;
91 is >> inName;
92 if (inName != name()) {
93 is.clear(std::ios::badbit | is.rdstate());
94 std::cerr << "Mismatch when expecting to read state of a "
95 << name() << " distribution\n"
96 << "Name found was " << inName
97 << "\nistream is left in the badbit state\n";
98 return is;
99 }
100 if (possibleKeywordInput(is, "Uvec", defaultMean)) {
101 std::vector<unsigned long> t(2);
102 is >> defaultMean >> t[0] >> t[1]; defaultMean = DoubConv::longs2double(t);
103 return is;
104 }
105 // is >> defaultMean encompassed by possibleKeywordInput
106 return is;
107}
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:110
std::string name() const
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:166

◆ name()

std::string CLHEP::RandExpZiggurat::name ( ) const
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 15 of file RandExpZiggurat.cc.

15{return "RandExpZiggurat";}

Referenced by get(), and put().

◆ operator()() [1/2]

double CLHEP::RandExpZiggurat::operator() ( )
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 26 of file RandExpZiggurat.cc.

27{
28 return fire( defaultMean );
29}

◆ operator()() [2/2]

float CLHEP::RandExpZiggurat::operator() ( float  mean)
inline

Definition at line 99 of file RandExpZiggurat.h.

99{return fire( mean );}

◆ put()

std::ostream & CLHEP::RandExpZiggurat::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 71 of file RandExpZiggurat.cc.

71 {
72 int pr=os.precision(20);
73 std::vector<unsigned long> t(2);
74 os << " " << name() << "\n";
75 os << "Uvec" << "\n";
76 t = DoubConv::dto2longs(defaultMean);
77 os << defaultMean << " " << t[0] << " " << t[1] << "\n";
78 os.precision(pr);
79 return os;
80#ifdef REMOVED
81 int pr=os.precision(20);
82 os << " " << name() << "\n";
83 os << defaultMean << "\n";
84 os.precision(pr);
85 return os;
86#endif
87}
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:94

◆ shoot() [1/4]

static float CLHEP::RandExpZiggurat::shoot ( )
inlinestatic

Definition at line 56 of file RandExpZiggurat.h.

static HepRandomEngine * getTheEngine()
Definition: Random.cc:268

Referenced by shoot(), and shootArray().

◆ shoot() [2/4]

static float CLHEP::RandExpZiggurat::shoot ( float  mean)
inlinestatic

Definition at line 57 of file RandExpZiggurat.h.

57{return shoot(HepRandom::getTheEngine(),mean);}

Referenced by shoot().

◆ shoot() [3/4]

static float CLHEP::RandExpZiggurat::shoot ( HepRandomEngine anEngine)
inlinestatic

Definition at line 70 of file RandExpZiggurat.h.

70{return ziggurat_REXP(anEngine);}

◆ shoot() [4/4]

static float CLHEP::RandExpZiggurat::shoot ( HepRandomEngine anEngine,
float  mean 
)
inlinestatic

Definition at line 71 of file RandExpZiggurat.h.

71{return shoot(anEngine)*mean;}

Referenced by shoot().

◆ shootArray() [1/4]

void CLHEP::RandExpZiggurat::shootArray ( const int  size,
double *  vect,
double  mean = 1.0 
)
static

Definition at line 36 of file RandExpZiggurat.cc.

37{
38 for (int i=0; i<size; ++i) vect[i] = shoot(mean);
39}

◆ shootArray() [2/4]

void CLHEP::RandExpZiggurat::shootArray ( const int  size,
float *  vect,
float  mean = 1.0 
)
static

Definition at line 31 of file RandExpZiggurat.cc.

32{
33 for (int i=0; i<size; ++i) vect[i] = shoot(mean);
34}

◆ shootArray() [3/4]

void CLHEP::RandExpZiggurat::shootArray ( HepRandomEngine anEngine,
const int  size,
double *  vect,
double  mean = 1.0 
)
static

Definition at line 46 of file RandExpZiggurat.cc.

47{
48 for (int i=0; i<size; ++i) vect[i] = shoot(anEngine, mean);
49}

◆ shootArray() [4/4]

void CLHEP::RandExpZiggurat::shootArray ( HepRandomEngine anEngine,
const int  size,
float *  vect,
float  mean = 1.0 
)
static

Definition at line 41 of file RandExpZiggurat.cc.

42{
43 for (int i=0; i<size; ++i) vect[i] = shoot(anEngine, mean);
44}

◆ ziggurat_efix()

float CLHEP::RandExpZiggurat::ziggurat_efix ( unsigned long  jz,
HepRandomEngine anEngine 
)
staticprotected

Definition at line 110 of file RandExpZiggurat.cc.

111{
113
114 unsigned long iz=jz&255;
115
116 float x;
117 for(;;)
118 {
119 if(iz==0) return (7.69711-std::log(ziggurat_UNI(anEngine))); /* iz==0 */
120 x=jz*we[iz];
121 if( fe[iz]+ziggurat_UNI(anEngine)*(fe[iz-1]-fe[iz]) < std::exp(-x) ) return (x);
122
123 /* initiate, try to exit for(;;) loop */
124 jz=ziggurat_SHR3(anEngine);
125 iz=(jz&255);
126 if(jz<ke[iz]) return (jz*we[iz]);
127 }
128}
static unsigned long ziggurat_SHR3(HepRandomEngine *anEngine)
static CLHEP_THREAD_LOCAL unsigned long ke[256]
static CLHEP_THREAD_LOCAL float fe[256]
static CLHEP_THREAD_LOCAL float we[256]
static float ziggurat_UNI(HepRandomEngine *anEngine)
static CLHEP_THREAD_LOCAL bool ziggurat_is_init

Referenced by ziggurat_REXP().

◆ ziggurat_init()

bool CLHEP::RandExpZiggurat::ziggurat_init ( )
static

Definition at line 130 of file RandExpZiggurat.cc.

131{
132 const double rzm1 = 2147483648.0, rzm2 = 4294967296.;
133 double dn=3.442619855899,tn=dn,vn=9.91256303526217e-3, q;
134 double de=7.697117470131487, te=de, ve=3.949659822581572e-3;
135 int i;
136
137/* Set up tables for RNOR */
138 q=vn/std::exp(-.5*dn*dn);
139 kn[0]=(unsigned long)((dn/q)*rzm1);
140 kn[1]=0;
141
142 wn[0]=q/rzm1;
143 wn[127]=dn/rzm1;
144
145 fn[0]=1.;
146 fn[127]=std::exp(-.5*dn*dn);
147
148 for(i=126;i>=1;i--) {
149 dn=std::sqrt(-2.*std::log(vn/dn+std::exp(-.5*dn*dn)));
150 kn[i+1]=(unsigned long)((dn/tn)*rzm1);
151 tn=dn;
152 fn[i]=std::exp(-.5*dn*dn);
153 wn[i]=dn/rzm1;
154 }
155
156/* Set up tables for REXP */
157 q = ve/std::exp(-de);
158 ke[0]=(unsigned long)((de/q)*rzm2);
159 ke[1]=0;
160
161 we[0]=q/rzm2;
162 we[255]=de/rzm2;
163
164 fe[0]=1.;
165 fe[255]=std::exp(-de);
166
167 for(i=254;i>=1;i--) {
168 de=-std::log(ve/de+std::exp(-de));
169 ke[i+1]= (unsigned long)((de/te)*rzm2);
170 te=de;
171 fe[i]=std::exp(-de);
172 we[i]=de/rzm2;
173 }
174 ziggurat_is_init=true;
175 return true;
176}
static CLHEP_THREAD_LOCAL float fn[128]
static CLHEP_THREAD_LOCAL float wn[128]
static CLHEP_THREAD_LOCAL unsigned long kn[128]

Referenced by ziggurat_efix(), and ziggurat_REXP().

◆ ziggurat_REXP()

static float CLHEP::RandExpZiggurat::ziggurat_REXP ( HepRandomEngine anEngine)
inlinestaticprotected

Definition at line 137 of file RandExpZiggurat.h.

137 {
139 unsigned long jz=ziggurat_SHR3(anEngine);
140 unsigned long iz=jz&255;
141 return (jz<ke[iz]) ? jz*we[iz] : ziggurat_efix(jz,anEngine);
142 }
static float ziggurat_efix(unsigned long jz, HepRandomEngine *anEngine)

Referenced by fire(), and shoot().

◆ ziggurat_SHR3()

static unsigned long CLHEP::RandExpZiggurat::ziggurat_SHR3 ( HepRandomEngine anEngine)
inlinestaticprotected

Definition at line 135 of file RandExpZiggurat.h.

135{return (unsigned int)(*anEngine);}

Referenced by ziggurat_efix(), and ziggurat_REXP().

◆ ziggurat_UNI()

static float CLHEP::RandExpZiggurat::ziggurat_UNI ( HepRandomEngine anEngine)
inlinestaticprotected

Definition at line 136 of file RandExpZiggurat.h.

136{return float(anEngine->flat());}

Referenced by ziggurat_efix().

Member Data Documentation

◆ fe

CLHEP_THREAD_LOCAL float CLHEP::RandExpZiggurat::fe
staticprotected

Definition at line 131 of file RandExpZiggurat.h.

Referenced by ziggurat_efix(), and ziggurat_init().

◆ fn

CLHEP_THREAD_LOCAL float CLHEP::RandExpZiggurat::fn
staticprotected

Definition at line 131 of file RandExpZiggurat.h.

Referenced by ziggurat_init().

◆ ke

CLHEP_THREAD_LOCAL unsigned long CLHEP::RandExpZiggurat::ke
staticprotected

Definition at line 130 of file RandExpZiggurat.h.

Referenced by ziggurat_efix(), ziggurat_init(), and ziggurat_REXP().

◆ kn

CLHEP_THREAD_LOCAL unsigned long CLHEP::RandExpZiggurat::kn
staticprotected

Definition at line 130 of file RandExpZiggurat.h.

Referenced by ziggurat_init().

◆ we

CLHEP_THREAD_LOCAL float CLHEP::RandExpZiggurat::we
staticprotected

Definition at line 131 of file RandExpZiggurat.h.

Referenced by ziggurat_efix(), ziggurat_init(), and ziggurat_REXP().

◆ wn

CLHEP_THREAD_LOCAL float CLHEP::RandExpZiggurat::wn
staticprotected

Definition at line 131 of file RandExpZiggurat.h.

Referenced by ziggurat_init().

◆ ziggurat_is_init

CLHEP_THREAD_LOCAL bool CLHEP::RandExpZiggurat::ziggurat_is_init = false
staticprotected

Definition at line 133 of file RandExpZiggurat.h.

Referenced by ziggurat_efix(), ziggurat_init(), and ziggurat_REXP().


The documentation for this class was generated from the following files: