CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
CLHEP::RandGaussZiggurat Class Reference

#include <RandGaussZiggurat.h>

+ Inheritance diagram for CLHEP::RandGaussZiggurat:

Public Member Functions

 RandGaussZiggurat (HepRandomEngine &anEngine, double mean=0.0, double stdDev=1.0)
 
 RandGaussZiggurat (HepRandomEngine *anEngine, double mean=0.0, double stdDev=1.0)
 
virtual ~RandGaussZiggurat ()
 
float fire ()
 
float fire (float mean, float stdDev)
 
void fireArray (const int size, float *vect)
 
void fireArray (const int size, double *vect)
 
void fireArray (const int size, float *vect, float mean, float stdDev)
 
void fireArray (const int size, double *vect, double mean, double stdDev)
 
virtual double operator() ()
 
virtual double operator() (double mean, double stdDev)
 
std::ostream & put (std::ostream &os) const
 
std::istream & get (std::istream &is)
 
std::string name () const
 
HepRandomEngineengine ()
 
- Public Member Functions inherited from CLHEP::RandGauss
 RandGauss (HepRandomEngine &anEngine, double mean=0.0, double stdDev=1.0)
 
 RandGauss (HepRandomEngine *anEngine, double mean=0.0, double stdDev=1.0)
 
virtual ~RandGauss ()
 
double fire ()
 
double fire (double mean, double stdDev)
 
void fireArray (const int size, double *vect)
 
void fireArray (const int size, double *vect, double mean, double stdDev)
 
virtual double operator() ()
 
virtual double operator() (double mean, double stdDev)
 
std::string name () const
 
HepRandomEngineengine ()
 
std::ostream & put (std::ostream &os) const
 
std::istream & get (std::istream &is)
 
bool getF () const
 
void setF (bool val)
 
- 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, float stdDev)
 
static void shootArray (const int size, float *vect, float mean=0.0, float stdDev=1.0)
 
static void shootArray (const int size, double *vect, double mean=0.0, double stdDev=1.0)
 
static float shoot (HepRandomEngine *anotherEngine)
 
static float shoot (HepRandomEngine *anotherEngine, float mean, float stdDev)
 
static void shootArray (HepRandomEngine *anotherEngine, const int size, float *vect, float mean=0.0, float stdDev=1.0)
 
static void shootArray (HepRandomEngine *anotherEngine, const int size, double *vect, double mean=0.0, double stdDev=1.0)
 
static std::string distributionName ()
 
static bool ziggurat_init ()
 
- Static Public Member Functions inherited from CLHEP::RandGauss
static double shoot ()
 
static double shoot (double mean, double stdDev)
 
static void shootArray (const int size, double *vect, double mean=0.0, double stdDev=1.0)
 
static double shoot (HepRandomEngine *anEngine)
 
static double shoot (HepRandomEngine *anEngine, double mean, double stdDev)
 
static void shootArray (HepRandomEngine *anEngine, const int size, double *vect, double mean=0.0, double stdDev=1.0)
 
static std::string distributionName ()
 
static bool getFlag ()
 
static void setFlag (bool val)
 
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 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_RNOR (HepRandomEngine *anEngine)
 
static float ziggurat_nfix (long hz, HepRandomEngine *anEngine)
 
- Static Protected Member Functions inherited from CLHEP::RandGauss
static double getVal ()
 
static void setVal (double nextVal)
 

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]
 

Additional Inherited Members

- Protected Member Functions inherited from CLHEP::RandGauss
double normal ()
 
- Protected Attributes inherited from CLHEP::RandGauss
double defaultMean
 
double defaultStdDev
 
std::shared_ptr< HepRandomEnginelocalEngine
 

Detailed Description

Author
ATLAS

Definition at line 38 of file RandGaussZiggurat.h.

Constructor & Destructor Documentation

◆ RandGaussZiggurat() [1/2]

CLHEP::RandGaussZiggurat::RandGaussZiggurat ( HepRandomEngine anEngine,
double  mean = 0.0,
double  stdDev = 1.0 
)
inline

Definition at line 143 of file RandGaussZiggurat.h.

143 : RandGauss(anEngine, mean, stdDev)
144{
145}
RandGauss(HepRandomEngine &anEngine, double mean=0.0, double stdDev=1.0)

◆ RandGaussZiggurat() [2/2]

CLHEP::RandGaussZiggurat::RandGaussZiggurat ( HepRandomEngine anEngine,
double  mean = 0.0,
double  stdDev = 1.0 
)
inline

Definition at line 147 of file RandGaussZiggurat.h.

147 : RandGauss(anEngine, mean, stdDev)
148{
149}

◆ ~RandGaussZiggurat()

CLHEP::RandGaussZiggurat::~RandGaussZiggurat ( )
virtual

Definition at line 26 of file RandGaussZiggurat.cc.

26 {
27}

Member Function Documentation

◆ distributionName()

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

Definition at line 88 of file RandGaussZiggurat.h.

88{return "RandGaussZiggurat";}

◆ engine()

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

Reimplemented from CLHEP::RandGauss.

Definition at line 24 of file RandGaussZiggurat.cc.

24{return RandGauss::engine();}
HepRandomEngine & engine()
Definition: RandGauss.cc:47

◆ fire() [1/2]

float CLHEP::RandGaussZiggurat::fire ( )
inline

Definition at line 68 of file RandGaussZiggurat.h.

static float ziggurat_RNOR(HepRandomEngine *anEngine)
double defaultStdDev
Definition: RandGauss.h:154
double defaultMean
Definition: RandGauss.h:153
std::shared_ptr< HepRandomEngine > localEngine
Definition: RandGauss.h:156

Referenced by fireArray().

◆ fire() [2/2]

float CLHEP::RandGaussZiggurat::fire ( float  mean,
float  stdDev 
)
inline

Definition at line 70 of file RandGaussZiggurat.h.

70{return ziggurat_RNOR(localEngine.get()) * stdDev + mean;};

◆ fireArray() [1/4]

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

Definition at line 156 of file RandGaussZiggurat.cc.

157{
158 for (int i=0; i<size; ++i) {
159 vect[i] = fire( defaultMean, defaultStdDev );
160 }
161}

◆ fireArray() [2/4]

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

Definition at line 170 of file RandGaussZiggurat.cc.

171{
172 for (int i=0; i<size; ++i) {
173 vect[i] = fire( mean, stdDev );
174 }
175}

◆ fireArray() [3/4]

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

Definition at line 149 of file RandGaussZiggurat.cc.

150{
151 for (int i=0; i<size; ++i) {
152 vect[i] = fire( defaultMean, defaultStdDev );
153 }
154}

◆ fireArray() [4/4]

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

Definition at line 163 of file RandGaussZiggurat.cc.

164{
165 for (int i=0; i<size; ++i) {
166 vect[i] = fire( mean, stdDev );
167 }
168}

◆ get()

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

Reimplemented from CLHEP::RandGauss.

Definition at line 185 of file RandGaussZiggurat.cc.

185 {
186 std::string inName;
187 is >> inName;
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";
194 return is;
195 }
196 RandGauss::get(is);
197 return is;
198}
std::string name() const
std::istream & get(std::istream &is)
Definition: RandGauss.cc:285

◆ name()

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

Reimplemented from CLHEP::RandGauss.

Definition at line 29 of file RandGaussZiggurat.cc.

30{
31 return "RandGaussZiggurat";
32}

Referenced by get(), and put().

◆ operator()() [1/2]

double CLHEP::RandGaussZiggurat::operator() ( )
virtual

Reimplemented from CLHEP::RandGauss.

Definition at line 113 of file RandGaussZiggurat.cc.

113 {
115}

◆ operator()() [2/2]

double CLHEP::RandGaussZiggurat::operator() ( double  mean,
double  stdDev 
)
virtual

Reimplemented from CLHEP::RandGauss.

Definition at line 117 of file RandGaussZiggurat.cc.

117 {
118 return ziggurat_RNOR(localEngine.get()) * stdDev + mean;
119}

◆ put()

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

Reimplemented from CLHEP::RandGauss.

Definition at line 177 of file RandGaussZiggurat.cc.

177 {
178 long pr=os.precision(20);
179 os << " " << name() << "\n";
180 RandGauss::put(os);
181 os.precision(pr);
182 return os;
183}
std::ostream & put(std::ostream &os) const
Definition: RandGauss.cc:260

◆ shoot() [1/4]

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

Definition at line 50 of file RandGaussZiggurat.h.

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

Referenced by main(), and shootArray().

◆ shoot() [2/4]

static float CLHEP::RandGaussZiggurat::shoot ( float  mean,
float  stdDev 
)
inlinestatic

Definition at line 51 of file RandGaussZiggurat.h.

51{return shoot()*stdDev + mean;};

Referenced by shoot().

◆ shoot() [3/4]

static float CLHEP::RandGaussZiggurat::shoot ( HepRandomEngine anotherEngine)
inlinestatic

Definition at line 59 of file RandGaussZiggurat.h.

59{return ziggurat_RNOR(anotherEngine);};

◆ shoot() [4/4]

static float CLHEP::RandGaussZiggurat::shoot ( HepRandomEngine anotherEngine,
float  mean,
float  stdDev 
)
inlinestatic

Definition at line 60 of file RandGaussZiggurat.h.

60{return shoot(anotherEngine)*stdDev + mean;};

Referenced by shoot().

◆ shootArray() [1/4]

void CLHEP::RandGaussZiggurat::shootArray ( const int  size,
double vect,
double  mean = 0.0,
double  stdDev = 1.0 
)
static

Definition at line 128 of file RandGaussZiggurat.cc.

129{
130 for (int i=0; i<size; ++i) {
131 vect[i] = shoot(mean,stdDev);
132 }
133}

◆ shootArray() [2/4]

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

Definition at line 121 of file RandGaussZiggurat.cc.

122{
123 for (int i=0; i<size; ++i) {
124 vect[i] = shoot(mean,stdDev);
125 }
126}

◆ shootArray() [3/4]

void CLHEP::RandGaussZiggurat::shootArray ( HepRandomEngine anotherEngine,
const int  size,
double vect,
double  mean = 0.0,
double  stdDev = 1.0 
)
static

Definition at line 142 of file RandGaussZiggurat.cc.

143{
144 for (int i=0; i<size; ++i) {
145 vect[i] = shoot(anEngine,mean,stdDev);
146 }
147}

◆ shootArray() [4/4]

void CLHEP::RandGaussZiggurat::shootArray ( HepRandomEngine anotherEngine,
const int  size,
float *  vect,
float  mean = 0.0,
float  stdDev = 1.0 
)
static

Definition at line 135 of file RandGaussZiggurat.cc.

136{
137 for (int i=0; i<size; ++i) {
138 vect[i] = shoot(anEngine,mean,stdDev);
139 }
140}

◆ ziggurat_init()

bool CLHEP::RandGaussZiggurat::ziggurat_init ( )
static

Definition at line 34 of file RandGaussZiggurat.cc.

35{
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;
39 int i;
40
41/* Set up tables for RNOR */
42 q=vn/exp(-.5*dn*dn);
43 kn[0]=(unsigned long)((dn/q)*rzm1);
44 kn[1]=0;
45
46 wn[0]=q/rzm1;
47 wn[127]=dn/rzm1;
48
49 fn[0]=1.;
50 fn[127]=exp(-.5*dn*dn);
51
52 for(i=126;i>=1;i--) {
53 dn=sqrt(-2.*log(vn/dn+exp(-.5*dn*dn)));
54 kn[i+1]=(unsigned long)((dn/tn)*rzm1);
55 tn=dn;
56 fn[i]=exp(-.5*dn*dn);
57 wn[i]=dn/rzm1;
58 }
59
60/* Set up tables for REXP */
61 q = ve/exp(-de);
62 ke[0]=(unsigned long)((de/q)*rzm2);
63 ke[1]=0;
64
65 we[0]=q/rzm2;
66 we[255]=de/rzm2;
67
68 fe[0]=1.;
69 fe[255]=exp(-de);
70
71 for(i=254;i>=1;i--) {
72 de=-log(ve/de+exp(-de));
73 ke[i+1]= (unsigned long)((de/te)*rzm2);
74 te=de;
75 fe[i]=exp(-de);
76 we[i]=de/rzm2;
77 }
79
80 //std::cout<<"Done RandGaussZiggurat::ziggurat_init()"<<std::endl;
81
82 return true;
83}
static CLHEP_THREAD_LOCAL unsigned long ke[256]
static CLHEP_THREAD_LOCAL float fn[128]
static CLHEP_THREAD_LOCAL unsigned long kn[128]
static CLHEP_THREAD_LOCAL float fe[256]
static CLHEP_THREAD_LOCAL float we[256]
static CLHEP_THREAD_LOCAL float wn[128]
static CLHEP_THREAD_LOCAL bool ziggurat_is_init

Referenced by ziggurat_nfix(), and ziggurat_RNOR().

◆ ziggurat_nfix()

float CLHEP::RandGaussZiggurat::ziggurat_nfix ( long  hz,
HepRandomEngine anEngine 
)
staticprotected

Definition at line 85 of file RandGaussZiggurat.cc.

86{
88 const float r = 3.442620f; /* The start of the right tail */
89 float x, y;
90 unsigned long iz=hz&127;
91 for(;;)
92 {
93 x=hz*wn[iz]; /* iz==0, handles the base strip */
94 if(iz==0) {
95 do {
96 /* change to (1.0 - UNI) as argument to log(), because CLHEP generates [0,1),
97 while the original UNI generates (0,1] */
98 x=-log(1.0 - ziggurat_UNI(anEngine))*0.2904764; /* .2904764 is 1/r */
99 y=-log(1.0 - ziggurat_UNI(anEngine));
100 } while(y+y<x*x);
101 return (hz>0)? r+x : -r-x;
102 }
103 /* iz>0, handle the wedges of other strips */
104 if( fn[iz]+(1.0 - ziggurat_UNI(anEngine))*(fn[iz-1]-fn[iz]) < exp(-.5*x*x) ) return x;
105
106 /* initiate, try to exit for(;;) for loop*/
107 hz=(signed)ziggurat_SHR3(anEngine);
108 iz=hz&127;
109 if((unsigned long)std::abs(hz)<kn[iz]) return (hz*wn[iz]);
110 }
111}
static float ziggurat_UNI(HepRandomEngine *anEngine)
static unsigned long ziggurat_SHR3(HepRandomEngine *anEngine)

Referenced by ziggurat_RNOR().

◆ ziggurat_RNOR()

static float CLHEP::RandGaussZiggurat::ziggurat_RNOR ( HepRandomEngine anEngine)
inlinestaticprotected

Definition at line 116 of file RandGaussZiggurat.h.

116 {
118 long hz=(signed)ziggurat_SHR3(anEngine);
119 unsigned long iz=hz&127;
120 return ((unsigned long)std::abs(hz)<kn[iz]) ? hz*wn[iz] : ziggurat_nfix(hz,anEngine);
121 };
static float ziggurat_nfix(long hz, HepRandomEngine *anEngine)

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

◆ ziggurat_SHR3()

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

Definition at line 114 of file RandGaussZiggurat.h.

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

Referenced by ziggurat_nfix(), and ziggurat_RNOR().

◆ ziggurat_UNI()

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

Definition at line 115 of file RandGaussZiggurat.h.

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

Referenced by ziggurat_nfix().

Member Data Documentation

◆ fe

CLHEP_THREAD_LOCAL float CLHEP::RandGaussZiggurat::fe
staticprotected

Definition at line 110 of file RandGaussZiggurat.h.

Referenced by ziggurat_init().

◆ fn

CLHEP_THREAD_LOCAL float CLHEP::RandGaussZiggurat::fn
staticprotected

Definition at line 110 of file RandGaussZiggurat.h.

Referenced by ziggurat_init(), and ziggurat_nfix().

◆ ke

CLHEP_THREAD_LOCAL unsigned long CLHEP::RandGaussZiggurat::ke
staticprotected

Definition at line 109 of file RandGaussZiggurat.h.

Referenced by ziggurat_init().

◆ kn

CLHEP_THREAD_LOCAL unsigned long CLHEP::RandGaussZiggurat::kn
staticprotected

Definition at line 109 of file RandGaussZiggurat.h.

Referenced by ziggurat_init(), ziggurat_nfix(), and ziggurat_RNOR().

◆ we

CLHEP_THREAD_LOCAL float CLHEP::RandGaussZiggurat::we
staticprotected

Definition at line 110 of file RandGaussZiggurat.h.

Referenced by ziggurat_init().

◆ wn

CLHEP_THREAD_LOCAL float CLHEP::RandGaussZiggurat::wn
staticprotected

Definition at line 110 of file RandGaussZiggurat.h.

Referenced by ziggurat_init(), ziggurat_nfix(), and ziggurat_RNOR().

◆ ziggurat_is_init

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

Definition at line 112 of file RandGaussZiggurat.h.

Referenced by ziggurat_init(), ziggurat_nfix(), and ziggurat_RNOR().


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