Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes
CLHEP::RandExpZiggurat Class Reference

#include <RandExpZiggurat.h>

Inheritance diagram for CLHEP::RandExpZiggurat:
CLHEP::HepRandom

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)
 

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 lux=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 unsigned long kn [128]
 
static unsigned long ke [256]
 
static float wn [128]
 
static float fn [128]
 
static float we [256]
 
static float fe [256]
 
static bool ziggurat_is_init =RandExpZiggurat::ziggurat_init()
 
- Static Protected Attributes inherited from CLHEP::HepRandom
static const long seedTable [215][2]
 

Detailed Description

Author
ATLAS

Definition at line 34 of file RandExpZiggurat.h.

Constructor & Destructor Documentation

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

Definition at line 156 of file RandExpZiggurat.h.

References ziggurat_init(), and ziggurat_is_init.

156  : localEngine(&anEngine), deleteEngine(false), defaultMean(mean)
157 {
159 }
CLHEP::RandExpZiggurat::RandExpZiggurat ( HepRandomEngine anEngine,
double  mean = 1.0 
)
inline

Definition at line 161 of file RandExpZiggurat.h.

References ziggurat_init(), and ziggurat_is_init.

161  : localEngine(anEngine), deleteEngine(true), defaultMean(mean)
162 {
164 }
CLHEP::RandExpZiggurat::~RandExpZiggurat ( )
virtual

Definition at line 18 of file RandExpZiggurat.cc.

18  {
19  if ( deleteEngine ) delete localEngine;
20 }

Member Function Documentation

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

Definition at line 107 of file RandExpZiggurat.h.

107 {return "RandExpZiggurat";}
HepRandomEngine & CLHEP::RandExpZiggurat::engine ( )
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 16 of file RandExpZiggurat.cc.

16 {return *localEngine;}
float CLHEP::RandExpZiggurat::fire ( )
inline

Definition at line 83 of file RandExpZiggurat.h.

References fire().

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

83 {return fire(defaultMean);};
float CLHEP::RandExpZiggurat::fire ( float  mean)
inline

Definition at line 84 of file RandExpZiggurat.h.

References ziggurat_REXP().

84 {return ziggurat_REXP(localEngine)*mean;};
static float ziggurat_REXP(HepRandomEngine *anEngine)
void CLHEP::RandExpZiggurat::fireArray ( const int  size,
float *  vect 
)

Definition at line 52 of file RandExpZiggurat.cc.

References fire().

53 {
54  for (int i=0; i<size; ++i) vect[i] = fire( defaultMean );
55 }
void CLHEP::RandExpZiggurat::fireArray ( const int  size,
double *  vect 
)

Definition at line 57 of file RandExpZiggurat.cc.

References fire().

58 {
59  for (int i=0; i<size; ++i) vect[i] = fire( defaultMean );
60 }
void CLHEP::RandExpZiggurat::fireArray ( const int  size,
float *  vect,
float  mean 
)

Definition at line 62 of file RandExpZiggurat.cc.

References fire().

63 {
64  for (int i=0; i<size; ++i) vect[i] = fire( mean );
65 }
void CLHEP::RandExpZiggurat::fireArray ( const int  size,
double *  vect,
double  mean 
)

Definition at line 67 of file RandExpZiggurat.cc.

References fire().

68 {
69  for (int i=0; i<size; ++i) vect[i] = fire( mean );
70 }
std::istream & CLHEP::RandExpZiggurat::get ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 90 of file RandExpZiggurat.cc.

References CLHEP::DoubConv::longs2double(), name(), and CLHEP::possibleKeywordInput().

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

Reimplemented from CLHEP::HepRandom.

Definition at line 14 of file RandExpZiggurat.cc.

Referenced by get(), and put().

14 {return "RandExpZiggurat";}
double CLHEP::RandExpZiggurat::operator() ( )
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 27 of file RandExpZiggurat.cc.

References fire().

28 {
29  return fire( defaultMean );
30 }
float CLHEP::RandExpZiggurat::operator() ( float  mean)
inline

Definition at line 97 of file RandExpZiggurat.h.

References fire().

97 {return fire( mean );};
std::ostream & CLHEP::RandExpZiggurat::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 72 of file RandExpZiggurat.cc.

References CLHEP::DoubConv::dto2longs(), name(), and gammaraytel::pr.

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

Definition at line 54 of file RandExpZiggurat.h.

References CLHEP::HepRandom::getTheEngine(), and shoot().

Referenced by shoot(), and shootArray().

54 {return shoot(HepRandom::getTheEngine());};
static HepRandomEngine * getTheEngine()
Definition: Random.cc:165
static float CLHEP::RandExpZiggurat::shoot ( float  mean)
inlinestatic

Definition at line 55 of file RandExpZiggurat.h.

References CLHEP::HepRandom::getTheEngine(), and shoot().

Referenced by shoot().

55 {return shoot(HepRandom::getTheEngine(),mean);};
static HepRandomEngine * getTheEngine()
Definition: Random.cc:165
static float CLHEP::RandExpZiggurat::shoot ( HepRandomEngine anEngine)
inlinestatic

Definition at line 68 of file RandExpZiggurat.h.

References ziggurat_REXP().

68 {return ziggurat_REXP(anEngine);};
static float ziggurat_REXP(HepRandomEngine *anEngine)
static float CLHEP::RandExpZiggurat::shoot ( HepRandomEngine anEngine,
float  mean 
)
inlinestatic

Definition at line 69 of file RandExpZiggurat.h.

References shoot().

Referenced by shoot().

69 {return shoot(anEngine)*mean;};
void CLHEP::RandExpZiggurat::shootArray ( const int  size,
float *  vect,
float  mean = 1.0 
)
static

Definition at line 32 of file RandExpZiggurat.cc.

References shoot().

33 {
34  for (int i=0; i<size; ++i) vect[i] = shoot(mean);
35 }
void CLHEP::RandExpZiggurat::shootArray ( const int  size,
double *  vect,
double  mean = 1.0 
)
static

Definition at line 37 of file RandExpZiggurat.cc.

References shoot().

38 {
39  for (int i=0; i<size; ++i) vect[i] = shoot(mean);
40 }
void CLHEP::RandExpZiggurat::shootArray ( HepRandomEngine anEngine,
const int  size,
float *  vect,
float  mean = 1.0 
)
static

Definition at line 42 of file RandExpZiggurat.cc.

References shoot().

43 {
44  for (int i=0; i<size; ++i) vect[i] = shoot(anEngine, mean);
45 }
void CLHEP::RandExpZiggurat::shootArray ( HepRandomEngine anEngine,
const int  size,
double *  vect,
double  mean = 1.0 
)
static

Definition at line 47 of file RandExpZiggurat.cc.

References shoot().

48 {
49  for (int i=0; i<size; ++i) vect[i] = shoot(anEngine, mean);
50 }
float CLHEP::RandExpZiggurat::ziggurat_efix ( unsigned long  jz,
HepRandomEngine anEngine 
)
staticprotected

Definition at line 111 of file RandExpZiggurat.cc.

References fe, iz, ke, we, test::x, ziggurat_SHR3(), and ziggurat_UNI().

Referenced by ziggurat_REXP().

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

Definition at line 129 of file RandExpZiggurat.cc.

References fe, fn, ke, kn, we, wn, and ziggurat_is_init.

Referenced by RandExpZiggurat().

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

Definition at line 135 of file RandExpZiggurat.h.

References iz, ke, we, ziggurat_efix(), and ziggurat_SHR3().

Referenced by fire(), and shoot().

135  {
136  unsigned long jz=ziggurat_SHR3(anEngine);
137  unsigned long iz=jz&255;
138  return (jz<ke[iz]) ? jz*we[iz] : ziggurat_efix(jz,anEngine);
139  };
static unsigned long ziggurat_SHR3(HepRandomEngine *anEngine)
G4double iz
Definition: TRTMaterials.hh:39
static float ziggurat_efix(unsigned long jz, HepRandomEngine *anEngine)
static unsigned long ke[256]
static float we[256]
static unsigned long CLHEP::RandExpZiggurat::ziggurat_SHR3 ( HepRandomEngine anEngine)
inlinestaticprotected

Definition at line 133 of file RandExpZiggurat.h.

Referenced by ziggurat_efix(), and ziggurat_REXP().

133 {return (unsigned int)(*anEngine);};
static float CLHEP::RandExpZiggurat::ziggurat_UNI ( HepRandomEngine anEngine)
inlinestaticprotected

Definition at line 134 of file RandExpZiggurat.h.

References CLHEP::HepRandomEngine::flat().

Referenced by ziggurat_efix().

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

Field Documentation

float CLHEP::RandExpZiggurat::fe
staticprotected

Definition at line 129 of file RandExpZiggurat.h.

Referenced by ziggurat_efix(), and ziggurat_init().

float CLHEP::RandExpZiggurat::fn
staticprotected

Definition at line 129 of file RandExpZiggurat.h.

Referenced by ziggurat_init().

unsigned long CLHEP::RandExpZiggurat::ke
staticprotected

Definition at line 128 of file RandExpZiggurat.h.

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

unsigned long CLHEP::RandExpZiggurat::kn
staticprotected

Definition at line 128 of file RandExpZiggurat.h.

Referenced by ziggurat_init().

float CLHEP::RandExpZiggurat::we
staticprotected

Definition at line 129 of file RandExpZiggurat.h.

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

float CLHEP::RandExpZiggurat::wn
staticprotected

Definition at line 129 of file RandExpZiggurat.h.

Referenced by ziggurat_init().

bool CLHEP::RandExpZiggurat::ziggurat_is_init =RandExpZiggurat::ziggurat_init()
staticprotected

Definition at line 131 of file RandExpZiggurat.h.

Referenced by RandExpZiggurat(), and ziggurat_init().


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