CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
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 51 of file RandExpZiggurat.h.

Constructor & Destructor Documentation

◆ RandExpZiggurat() [1/2]

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

Definition at line 178 of file RandExpZiggurat.h.

178 : localEngine(&anEngine, do_nothing_deleter()), defaultMean(mean)
179{
180}

◆ RandExpZiggurat() [2/2]

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

Definition at line 182 of file RandExpZiggurat.h.

182 : localEngine(anEngine), defaultMean(mean)
183{
184}

◆ ~RandExpZiggurat()

CLHEP::RandExpZiggurat::~RandExpZiggurat ( )
virtual

Definition at line 31 of file RandExpZiggurat.cc.

31 {
32}

Member Function Documentation

◆ distributionName()

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

Definition at line 124 of file RandExpZiggurat.h.

124{return "RandExpZiggurat";}

◆ engine()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 29 of file RandExpZiggurat.cc.

29{return *localEngine;}

◆ fire() [1/2]

float CLHEP::RandExpZiggurat::fire ( )
inline

Definition at line 100 of file RandExpZiggurat.h.

100{return fire(defaultMean);};

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

◆ fire() [2/2]

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

Definition at line 101 of file RandExpZiggurat.h.

101{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 68 of file RandExpZiggurat.cc.

69{
70 for (int i=0; i<size; ++i) vect[i] = fire( defaultMean );
71}

◆ fireArray() [2/4]

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

Definition at line 78 of file RandExpZiggurat.cc.

79{
80 for (int i=0; i<size; ++i) vect[i] = fire( mean );
81}

◆ fireArray() [3/4]

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

Definition at line 63 of file RandExpZiggurat.cc.

64{
65 for (int i=0; i<size; ++i) vect[i] = fire( defaultMean );
66}

◆ fireArray() [4/4]

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

Definition at line 73 of file RandExpZiggurat.cc.

74{
75 for (int i=0; i<size; ++i) vect[i] = fire( mean );
76}

◆ get()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 101 of file RandExpZiggurat.cc.

101 {
102 std::string inName;
103 is >> inName;
104 if (inName != name()) {
105 is.clear(std::ios::badbit | is.rdstate());
106 std::cerr << "Mismatch when expecting to read state of a "
107 << name() << " distribution\n"
108 << "Name found was " << inName
109 << "\nistream is left in the badbit state\n";
110 return is;
111 }
112 if (possibleKeywordInput(is, "Uvec", defaultMean)) {
113 std::vector<unsigned long> t(2);
114 is >> defaultMean >> t[0] >> t[1]; defaultMean = DoubConv::longs2double(t);
115 return is;
116 }
117 // is >> defaultMean encompassed by possibleKeywordInput
118 return is;
119}
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:168

◆ name()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 27 of file RandExpZiggurat.cc.

27{return "RandExpZiggurat";}

Referenced by get(), and put().

◆ operator()() [1/2]

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

Reimplemented from CLHEP::HepRandom.

Definition at line 38 of file RandExpZiggurat.cc.

39{
40 return fire( defaultMean );
41}

◆ operator()() [2/2]

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

Definition at line 114 of file RandExpZiggurat.h.

114{return fire( mean );};

◆ put()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 83 of file RandExpZiggurat.cc.

83 {
84 long pr=os.precision(20);
85 std::vector<unsigned long> t(2);
86 os << " " << name() << "\n";
87 os << "Uvec" << "\n";
88 t = DoubConv::dto2longs(defaultMean);
89 os << defaultMean << " " << t[0] << " " << t[1] << "\n";
90 os.precision(pr);
91 return os;
92#ifdef REMOVED
93 long pr=os.precision(20);
94 os << " " << name() << "\n";
95 os << defaultMean << "\n";
96 os.precision(pr);
97 return os;
98#endif
99}
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:94

◆ shoot() [1/4]

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

Definition at line 71 of file RandExpZiggurat.h.

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

Referenced by main(), shoot(), and shootArray().

◆ shoot() [2/4]

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

Definition at line 72 of file RandExpZiggurat.h.

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

Referenced by shoot().

◆ shoot() [3/4]

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

Definition at line 85 of file RandExpZiggurat.h.

85{return ziggurat_REXP(anEngine);};

◆ shoot() [4/4]

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

Definition at line 86 of file RandExpZiggurat.h.

86{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 48 of file RandExpZiggurat.cc.

49{
50 for (int i=0; i<size; ++i) vect[i] = shoot(mean);
51}

◆ shootArray() [2/4]

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

Definition at line 43 of file RandExpZiggurat.cc.

44{
45 for (int i=0; i<size; ++i) vect[i] = shoot(mean);
46}

◆ shootArray() [3/4]

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

Definition at line 58 of file RandExpZiggurat.cc.

59{
60 for (int i=0; i<size; ++i) vect[i] = shoot(anEngine, mean);
61}

◆ shootArray() [4/4]

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

Definition at line 53 of file RandExpZiggurat.cc.

54{
55 for (int i=0; i<size; ++i) vect[i] = shoot(anEngine, mean);
56}

◆ ziggurat_efix()

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

Definition at line 122 of file RandExpZiggurat.cc.

123{
125
126 unsigned long iz=jz&255;
127
128 float x;
129 for(;;)
130 {
131 if(iz==0) return (7.69711-std::log(ziggurat_UNI(anEngine))); /* iz==0 */
132 x=jz*we[iz];
133 if( fe[iz]+ziggurat_UNI(anEngine)*(fe[iz-1]-fe[iz]) < std::exp(-x) ) return (x);
134
135 /* initiate, try to exit for(;;) loop */
136 jz=ziggurat_SHR3(anEngine);
137 iz=(jz&255);
138 if(jz<ke[iz]) return (jz*we[iz]);
139 }
140}
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 142 of file RandExpZiggurat.cc.

143{
144 const double rzm1 = 2147483648.0, rzm2 = 4294967296.;
145 double dn=3.442619855899,tn=dn,vn=9.91256303526217e-3, q;
146 double de=7.697117470131487, te=de, ve=3.949659822581572e-3;
147 int i;
148
149/* Set up tables for RNOR */
150 q=vn/std::exp(-.5*dn*dn);
151 kn[0]=(unsigned long)((dn/q)*rzm1);
152 kn[1]=0;
153
154 wn[0]=q/rzm1;
155 wn[127]=dn/rzm1;
156
157 fn[0]=1.;
158 fn[127]=std::exp(-.5*dn*dn);
159
160 for(i=126;i>=1;i--) {
161 dn=std::sqrt(-2.*std::log(vn/dn+std::exp(-.5*dn*dn)));
162 kn[i+1]=(unsigned long)((dn/tn)*rzm1);
163 tn=dn;
164 fn[i]=std::exp(-.5*dn*dn);
165 wn[i]=dn/rzm1;
166 }
167
168/* Set up tables for REXP */
169 q = ve/std::exp(-de);
170 ke[0]=(unsigned long)((de/q)*rzm2);
171 ke[1]=0;
172
173 we[0]=q/rzm2;
174 we[255]=de/rzm2;
175
176 fe[0]=1.;
177 fe[255]=std::exp(-de);
178
179 for(i=254;i>=1;i--) {
180 de=-std::log(ve/de+std::exp(-de));
181 ke[i+1]= (unsigned long)((de/te)*rzm2);
182 te=de;
183 fe[i]=std::exp(-de);
184 we[i]=de/rzm2;
185 }
186 ziggurat_is_init=true;
187 return true;
188}
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 152 of file RandExpZiggurat.h.

152 {
154 unsigned long jz=ziggurat_SHR3(anEngine);
155 unsigned long iz=jz&255;
156 return (jz<ke[iz]) ? jz*we[iz] : ziggurat_efix(jz,anEngine);
157 };
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 150 of file RandExpZiggurat.h.

150{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 151 of file RandExpZiggurat.h.

151{return anEngine->flat();};

Referenced by ziggurat_efix().

Member Data Documentation

◆ fe

CLHEP_THREAD_LOCAL float CLHEP::RandExpZiggurat::fe
staticprotected

Definition at line 146 of file RandExpZiggurat.h.

Referenced by ziggurat_efix(), and ziggurat_init().

◆ fn

CLHEP_THREAD_LOCAL float CLHEP::RandExpZiggurat::fn
staticprotected

Definition at line 146 of file RandExpZiggurat.h.

Referenced by ziggurat_init().

◆ ke

CLHEP_THREAD_LOCAL unsigned long CLHEP::RandExpZiggurat::ke
staticprotected

Definition at line 145 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 145 of file RandExpZiggurat.h.

Referenced by ziggurat_init().

◆ we

CLHEP_THREAD_LOCAL float CLHEP::RandExpZiggurat::we
staticprotected

Definition at line 146 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 146 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 148 of file RandExpZiggurat.h.

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


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