Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CLHEP::HepJamesRandom Class Reference

#include <JamesRandom.h>

Inheritance diagram for CLHEP::HepJamesRandom:
Collaboration diagram for CLHEP::HepJamesRandom:

Public Member Functions

 HepJamesRandom (std::istream &is)
 
 HepJamesRandom ()
 
 HepJamesRandom (long seed)
 
 HepJamesRandom (int rowIndex, int colIndex)
 
virtual ~HepJamesRandom ()
 
double flat ()
 
void flatArray (const int size, double *vect)
 
void setSeed (long seed, int dum=0)
 
void setSeeds (const long *seeds, int dum=0)
 
void saveStatus (const char filename[]="JamesRand.conf") const
 
void restoreStatus (const char filename[]="JamesRand.conf")
 
void showStatus () const
 
 operator unsigned int ()
 
virtual std::ostream & put (std::ostream &os) const
 
virtual std::istream & get (std::istream &is)
 
virtual std::istream & getState (std::istream &is)
 
std::string name () const
 
std::vector< unsigned long > put () const
 
bool get (const std::vector< unsigned long > &v)
 
bool getState (const std::vector< unsigned long > &v)
 
- Public Member Functions inherited from CLHEP::HepRandomEngine
 HepRandomEngine ()
 
virtual ~HepRandomEngine ()
 
bool operator== (const HepRandomEngine &engine)
 
bool operator!= (const HepRandomEngine &engine)
 
long getSeed () const
 
const long * getSeeds () const
 
virtual operator double ()
 
virtual operator float ()
 

Static Public Member Functions

static std::string beginTag ()
 
static std::string engineName ()
 
- Static Public Member Functions inherited from CLHEP::HepRandomEngine
static std::string beginTag ()
 
static HepRandomEnginenewEngine (std::istream &is)
 
static HepRandomEnginenewEngine (const std::vector< unsigned long > &v)
 

Static Public Attributes

static const unsigned int VECTOR_STATE_SIZE = 202
 

Additional Inherited Members

- Static Protected Member Functions inherited from CLHEP::HepRandomEngine
static double exponent_bit_32 ()
 
static double mantissa_bit_12 ()
 
static double mantissa_bit_24 ()
 
static double mantissa_bit_32 ()
 
static double twoToMinus_32 ()
 
static double twoToMinus_48 ()
 
static double twoToMinus_49 ()
 
static double twoToMinus_53 ()
 
static double nearlyTwoToMinus_54 ()
 
static bool checkFile (std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
 
- Protected Attributes inherited from CLHEP::HepRandomEngine
long theSeed
 
const long * theSeeds
 

Detailed Description

Author

Definition at line 44 of file JamesRandom.h.

Constructor & Destructor Documentation

CLHEP::HepJamesRandom::HepJamesRandom ( std::istream &  is)

Definition at line 103 of file JamesRandom.cc.

104 : HepRandomEngine()
105 {
106  is >> *this;
107 }
CLHEP::HepJamesRandom::HepJamesRandom ( )

Definition at line 70 of file JamesRandom.cc.

72 {
73  long seeds[2];
74  long seed;
75 
76  int numEngines = numberOfEngines++;
77  int cycle = std::abs(int(numEngines/maxIndex));
78  int curIndex = std::abs(int(numEngines%maxIndex));
79 
80  long mask = ((cycle & 0x007fffff) << 8);
81  HepRandom::getTheTableSeeds( seeds, curIndex );
82  seed = seeds[0]^mask;
83  setSeed(seed,0);
84  setSeeds(&theSeed,0);
85 }
static ush mask[]
Definition: csz_inflate.cc:317
void setSeed(long seed, int dum=0)
Definition: JamesRandom.cc:178
void setSeeds(const long *seeds, int dum=0)
Definition: JamesRandom.cc:230
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

CLHEP::HepJamesRandom::HepJamesRandom ( long  seed)

Definition at line 63 of file JamesRandom.cc.

65 {
66  setSeed(seed,0);
67  setSeeds(&theSeed,0);
68 }
void setSeed(long seed, int dum=0)
Definition: JamesRandom.cc:178
void setSeeds(const long *seeds, int dum=0)
Definition: JamesRandom.cc:230

Here is the call graph for this function:

CLHEP::HepJamesRandom::HepJamesRandom ( int  rowIndex,
int  colIndex 
)

Definition at line 87 of file JamesRandom.cc.

89 {
90  long seed;
91  long seeds[2];
92 
93  int cycle = std::abs(int(rowIndex/maxIndex));
94  int row = std::abs(int(rowIndex%maxIndex));
95  int col = std::abs(int(colIndex%2));
96  long mask = ((cycle & 0x000007ff) << 20);
97  HepRandom::getTheTableSeeds( seeds, row );
98  seed = (seeds[col])^mask;
99  setSeed(seed,0);
100  setSeeds(&theSeed,0);
101 }
static ush mask[]
Definition: csz_inflate.cc:317
void setSeed(long seed, int dum=0)
Definition: JamesRandom.cc:178
void setSeeds(const long *seeds, int dum=0)
Definition: JamesRandom.cc:230
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

CLHEP::HepJamesRandom::~HepJamesRandom ( )
virtual

Definition at line 109 of file JamesRandom.cc.

109 {}

Member Function Documentation

std::string CLHEP::HepJamesRandom::beginTag ( )
static

Definition at line 322 of file JamesRandom.cc.

322  {
323  return "JamesRandom-begin";
324 }
static std::string CLHEP::HepJamesRandom::engineName ( )
inlinestatic

Definition at line 88 of file JamesRandom.h.

88 {return "HepJamesRandom";}

Here is the caller graph for this function:

double CLHEP::HepJamesRandom::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 236 of file JamesRandom.cc.

237 {
238  double uni;
239 
240  do {
241  uni = u[i97] - u[j97];
242  if ( uni < 0.0 ) uni++;
243  u[i97] = uni;
244 
245  if (i97 == 0) i97 = 96;
246  else i97--;
247 
248  if (j97 == 0) j97 = 96;
249  else j97--;
250 
251  c -= cd;
252  if (c < 0.0) c += cm;
253 
254  uni -= c;
255  if (uni < 0.0) uni += 1.0;
256  } while ( uni <= 0.0 || uni >= 1.0 );
257 
258  return uni;
259 }
static const G4double cd
static constexpr double cm
Definition: G4SIunits.hh:119

Here is the caller graph for this function:

void CLHEP::HepJamesRandom::flatArray ( const int  size,
double *  vect 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 261 of file JamesRandom.cc.

262 {
263 // double uni;
264  int i;
265 
266  for (i=0; i<size; ++i) {
267  vect[i] = flat();
268  }
269 }

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 305 of file JamesRandom.cc.

305  {
306  char beginMarker [MarkerLen];
307  is >> std::ws;
308  is.width(MarkerLen); // causes the next read to the char* to be <=
309  // that many bytes, INCLUDING A TERMINATION \0
310  // (Stroustrup, section 21.3.2)
311  is >> beginMarker;
312  if (strcmp(beginMarker,"JamesRandom-begin")) {
313  is.clear(std::ios::badbit | is.rdstate());
314  std::cerr << "\nInput stream mispositioned or"
315  << "\nJamesRandom state description missing or"
316  << "\nwrong engine type found." << std::endl;
317  return is;
318  }
319  return getState(is);
320 }
static const int MarkerLen
Definition: DualRand.cc:67
virtual std::istream & getState(std::istream &is)
Definition: JamesRandom.cc:326

Here is the call graph for this function:

bool CLHEP::HepJamesRandom::get ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 370 of file JamesRandom.cc.

370  {
371  if ( (v[0] & 0xffffffffUL) != engineIDulong<HepJamesRandom>()) {
372  std::cerr <<
373  "\nHepJamesRandom get:state vector has wrong ID word - state unchanged\n";
374  return false;
375  }
376  return getState(v);
377 }
virtual std::istream & getState(std::istream &is)
Definition: JamesRandom.cc:326

Here is the call graph for this function:

std::istream & CLHEP::HepJamesRandom::getState ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 326 of file JamesRandom.cc.

326  {
327  if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
328  std::vector<unsigned long> v;
329  unsigned long uu;
330  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
331  is >> uu;
332  if (!is) {
333  is.clear(std::ios::badbit | is.rdstate());
334  std::cerr << "\nJamesRandom state (vector) description improper."
335  << "\ngetState() has failed."
336  << "\nInput stream is probably mispositioned now." << std::endl;
337  return is;
338  }
339  v.push_back(uu);
340  }
341  getState(v);
342  return (is);
343  }
344 
345 // is >> theSeed; Removed, encompassed by possibleKeywordInput()
346 
347  int ipos, jpos;
348  char endMarker [MarkerLen];
349  for (int i=0; i<97; ++i) {
350  is >> u[i];
351  }
352  is >> c; is >> cd; is >> cm;
353  is >> jpos;
354  is >> std::ws;
355  is.width(MarkerLen);
356  is >> endMarker;
357  if(strcmp(endMarker,"JamesRandom-end")) {
358  is.clear(std::ios::badbit | is.rdstate());
359  std::cerr << "\nJamesRandom state description incomplete."
360  << "\nInput stream is probably mispositioned now." << std::endl;
361  return is;
362  }
363 
364  ipos = (64+jpos)%97;
365  i97 = ipos;
366  j97 = jpos;
367  return is;
368 }
static const int MarkerLen
Definition: DualRand.cc:67
static const G4double cd
virtual std::istream & getState(std::istream &is)
Definition: JamesRandom.cc:326
static constexpr double cm
Definition: G4SIunits.hh:119
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
static const unsigned int VECTOR_STATE_SIZE
Definition: JamesRandom.h:94

Here is the call graph for this function:

Here is the caller graph for this function:

bool CLHEP::HepJamesRandom::getState ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 379 of file JamesRandom.cc.

379  {
380  if (v.size() != VECTOR_STATE_SIZE ) {
381  std::cerr <<
382  "\nHepJamesRandom get:state vector has wrong length - state unchanged\n";
383  return false;
384  }
385  std::vector<unsigned long> t(2);
386  for (int i=0; i<97; ++i) {
387  t[0] = v[2*i+1]; t[1] = v[2*i+2];
388  u[i] = DoubConv::longs2double(t);
389  }
390  t[0] = v[195]; t[1] = v[196]; c = DoubConv::longs2double(t);
391  t[0] = v[197]; t[1] = v[198]; cd = DoubConv::longs2double(t);
392  t[0] = v[199]; t[1] = v[200]; cm = DoubConv::longs2double(t);
393  j97 = v[201];
394  i97 = (64+j97)%97;
395  return true;
396 }
static const G4double cd
static constexpr double cm
Definition: G4SIunits.hh:119
static const unsigned int VECTOR_STATE_SIZE
Definition: JamesRandom.h:94
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:114

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 61 of file JamesRandom.cc.

61 {return "HepJamesRandom";}
CLHEP::HepJamesRandom::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 271 of file JamesRandom.cc.

271  {
272  return ((unsigned int)(flat() * exponent_bit_32()) & 0xffffffff ) |
273  (((unsigned int)( u[i97] * exponent_bit_32())>>16) & 0xff);
274 }
static double exponent_bit_32()
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 276 of file JamesRandom.cc.

276  {
277  char beginMarker[] = "JamesRandom-begin";
278  os << beginMarker << "\nUvec\n";
279  std::vector<unsigned long> v = put();
280  for (unsigned int i=0; i<v.size(); ++i) {
281  os << v[i] << "\n";
282  }
283  return os;
284 }
std::vector< unsigned long > put() const
Definition: JamesRandom.cc:286

Here is the call graph for this function:

std::vector< unsigned long > CLHEP::HepJamesRandom::put ( ) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 286 of file JamesRandom.cc.

286  {
287  std::vector<unsigned long> v;
288  v.push_back (engineIDulong<HepJamesRandom>());
289  std::vector<unsigned long> t;
290  for (int i=0; i<97; ++i) {
291  t = DoubConv::dto2longs(u[i]);
292  v.push_back(t[0]); v.push_back(t[1]);
293  }
294  t = DoubConv::dto2longs(c);
295  v.push_back(t[0]); v.push_back(t[1]);
296  t = DoubConv::dto2longs(cd);
297  v.push_back(t[0]); v.push_back(t[1]);
298  t = DoubConv::dto2longs(cm);
299  v.push_back(t[0]); v.push_back(t[1]);
300  v.push_back(static_cast<unsigned long>(j97));
301  return v;
302 }
static const G4double cd
static constexpr double cm
Definition: G4SIunits.hh:119
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:98

Here is the call graph for this function:

Here is the caller graph for this function:

void CLHEP::HepJamesRandom::restoreStatus ( const char  filename[] = "JamesRand.conf")
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 124 of file JamesRandom.cc.

125 {
126  int ipos, jpos;
127  std::ifstream inFile( filename, std::ios::in);
128  if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
129  std::cerr << " -- Engine state remains unchanged\n";
130  return;
131  }
132  if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
133  std::vector<unsigned long> v;
134  unsigned long xin;
135  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
136  inFile >> xin;
137  if (!inFile) {
138  inFile.clear(std::ios::badbit | inFile.rdstate());
139  std::cerr << "\nJamesRandom state (vector) description improper."
140  << "\nrestoreStatus has failed."
141  << "\nInput stream is probably mispositioned now." << std::endl;
142  return;
143  }
144  v.push_back(xin);
145  }
146  getState(v);
147  return;
148  }
149 
150  if (!inFile.bad() && !inFile.eof()) {
151 // inFile >> theSeed; removed -- encompased by possibleKeywordInput
152  for (int i=0; i<97; ++i)
153  inFile >> u[i];
154  inFile >> c; inFile >> cd; inFile >> cm;
155  inFile >> jpos;
156  ipos = (64+jpos)%97;
157  i97 = ipos;
158  j97 = jpos;
159  }
160 }
static std::string engineName()
Definition: JamesRandom.h:88
static const G4double cd
virtual std::istream & getState(std::istream &is)
Definition: JamesRandom.cc:326
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:45
static constexpr double cm
Definition: G4SIunits.hh:119
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
static const unsigned int VECTOR_STATE_SIZE
Definition: JamesRandom.h:94

Here is the call graph for this function:

void CLHEP::HepJamesRandom::saveStatus ( const char  filename[] = "JamesRand.conf") const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 111 of file JamesRandom.cc.

112 {
113  std::ofstream outFile( filename, std::ios::out ) ;
114 
115  if (!outFile.bad()) {
116  outFile << "Uvec\n";
117  std::vector<unsigned long> v = put();
118  for (unsigned int i=0; i<v.size(); ++i) {
119  outFile << v[i] << "\n";
120  }
121  }
122 }
std::vector< unsigned long > put() const
Definition: JamesRandom.cc:286

Here is the call graph for this function:

void CLHEP::HepJamesRandom::setSeed ( long  seed,
int  dum = 0 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 178 of file JamesRandom.cc.

179 {
180  // The input value for "seed" should be within the range [0,900000000]
181  //
182  // Negative seeds result in serious flaws in the randomness;
183  // seeds above 900000000 are OK because of the %177 in the expression for i,
184  // but may have the same effect as other seeds below 900000000.
185 
186  int m, n;
187  float s, t;
188  long mm;
189 
190  if (seed < 0) {
191  std::cout << "Seed for HepJamesRandom must be non-negative\n"
192  << "Seed value supplied was " << seed
193  << "\nUsing its absolute value instead\n";
194  seed = -seed;
195  }
196 
197  long ij = seed/30082;
198  long kl = seed - 30082*ij;
199  long i = (ij/177) % 177 + 2;
200  long j = ij % 177 + 2;
201  long k = (kl/169) % 178 + 1;
202  long l = kl % 169;
203 
204  theSeed = seed;
205 
206  for ( n = 1 ; n < 98 ; n++ ) {
207  s = 0.0;
208  t = 0.5;
209  for ( m = 1 ; m < 25 ; m++) {
210  mm = ( ( (i*j) % 179 ) * k ) % 179;
211  i = j;
212  j = k;
213  k = mm;
214  l = ( 53 * l + 1 ) % 169;
215  if ( (l*mm % 64 ) >= 32 )
216  s += t;
217  t *= 0.5;
218  }
219  u[n-1] = s;
220  }
221  c = 362436.0 / 16777216.0;
222  cd = 7654321.0 / 16777216.0;
223  cm = 16777213.0 / 16777216.0;
224 
225  i97 = 96;
226  j97 = 32;
227 
228 }
static constexpr double m
static const G4double cd
static constexpr double mm
Definition: SystemOfUnits.h:95
static constexpr double cm
Definition: G4SIunits.hh:119
static constexpr double s

Here is the caller graph for this function:

void CLHEP::HepJamesRandom::setSeeds ( const long *  seeds,
int  dum = 0 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 230 of file JamesRandom.cc.

231 {
232  setSeed(seeds ? *seeds : 19780503L, 0);
233  theSeeds = seeds;
234 }
void setSeed(long seed, int dum=0)
Definition: JamesRandom.cc:178
static constexpr double L

Here is the call graph for this function:

Here is the caller graph for this function:

void CLHEP::HepJamesRandom::showStatus ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 162 of file JamesRandom.cc.

163 {
164  std::cout << std::endl;
165  std::cout << "----- HepJamesRandom engine status -----" << std::endl;
166  std::cout << " Initial seed = " << theSeed << std::endl;
167  std::cout << " u[] = ";
168  for (int i=0; i<97; ++i)
169  std::cout << u[i] << " ";
170  std::cout << std::endl;
171  std::cout << " c = " << c << ", cd = " << cd << ", cm = " << cm
172  << std::endl;
173  std::cout << " i97 = " << i97 << ", u[i97] = " << u[i97] << std::endl;
174  std::cout << " j97 = " << j97 << ", u[j97] = " << u[j97] << std::endl;
175  std::cout << "----------------------------------------" << std::endl;
176 }
static const G4double cd
static constexpr double cm
Definition: G4SIunits.hh:119

Member Data Documentation

const unsigned int CLHEP::HepJamesRandom::VECTOR_STATE_SIZE = 202
static

Definition at line 94 of file JamesRandom.h.


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