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 Attributes
CLHEP::RanecuEngine Class Reference

#include <RanecuEngine.h>

Inheritance diagram for CLHEP::RanecuEngine:
CLHEP::HepRandomEngine

Public Member Functions

 RanecuEngine (std::istream &is)
 
 RanecuEngine ()
 
 RanecuEngine (int index)
 
virtual ~RanecuEngine ()
 
double flat ()
 
void flatArray (const int size, double *vect)
 
void setIndex (long index)
 
void setSeed (long index, int dum=0)
 
void setSeeds (const long *seeds, int index=-1)
 
void saveStatus (const char filename[]="Ranecu.conf") const
 
void restoreStatus (const char filename[]="Ranecu.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 Protected Attributes

static const int ecuyer_a = 40014
 
static const int ecuyer_b = 53668
 
static const int ecuyer_c = 12211
 
static const int ecuyer_d = 40692
 
static const int ecuyer_e = 52774
 
static const int ecuyer_f = 3791
 
static const int shift1 = 2147483563
 
static const int shift2 = 2147483399
 
static const unsigned int VECTOR_STATE_SIZE = 4
 

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
Gabri.nosp@m.ele..nosp@m.Cosmo.nosp@m.@cer.nosp@m.n.ch

Definition at line 47 of file RanecuEngine.h.

Constructor & Destructor Documentation

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

Definition at line 97 of file RanecuEngine.cc.

99 {
100  is >> *this;
101 }
CLHEP::RanecuEngine::RanecuEngine ( )

Definition at line 64 of file RanecuEngine.cc.

References CLHEP::HepRandom::getTheTableSeeds(), CLHEP::HepRandomEngine::theSeed, and CLHEP::HepRandomEngine::theSeeds.

66 {
67  int cycle = std::abs(int(numEngines/maxSeq));
68  seq = std::abs(int(numEngines%maxSeq));
69  numEngines += 1;
70  theSeed = seq;
71  long mask = ((cycle & 0x007fffff) << 8);
72  for (int i=0; i<2; ++i) {
73  for (int j=0; j<maxSeq; ++j) {
74  HepRandom::getTheTableSeeds(table[j],j);
75  table[j][i] ^= mask;
76  }
77  }
78  theSeeds = &table[seq][0];
79 }
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:151
CLHEP::RanecuEngine::RanecuEngine ( int  index)

Definition at line 81 of file RanecuEngine.cc.

References CLHEP::HepRandom::getTheTableSeeds(), shift1, CLHEP::HepRandomEngine::theSeed, and CLHEP::HepRandomEngine::theSeeds.

83 {
84  int cycle = std::abs(int(index/maxSeq));
85  seq = std::abs(int(index%maxSeq));
86  theSeed = seq;
87  long mask = ((cycle & 0x000007ff) << 20);
88  for (int j=0; j<maxSeq; ++j) {
89  HepRandom::getTheTableSeeds(table[j],j);
90  table[j][0] ^= mask;
91  table[j][1] ^= mask;
92  }
93  theSeeds = &table[seq][0];
94  further_randomize (seq, 0, index, shift1); // mf 6/22/10
95 }
static const int shift1
Definition: RanecuEngine.h:112
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:151
CLHEP::RanecuEngine::~RanecuEngine ( )
virtual

Definition at line 103 of file RanecuEngine.cc.

103 {}

Member Function Documentation

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

Definition at line 301 of file RanecuEngine.cc.

301  {
302  return "RanecuEngine-begin";
303 }
static std::string CLHEP::RanecuEngine::engineName ( )
inlinestatic

Definition at line 96 of file RanecuEngine.h.

Referenced by restoreStatus().

96 {return "RanecuEngine";}
double CLHEP::RanecuEngine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 191 of file RanecuEngine.cc.

References ecuyer_a, ecuyer_b, ecuyer_c, ecuyer_d, ecuyer_e, ecuyer_f, int(), shift1, and shift2.

192 {
193  const int index = seq;
194  long seed1 = table[index][0];
195  long seed2 = table[index][1];
196 
197  int k1 = (int)(seed1/ecuyer_b);
198  int k2 = (int)(seed2/ecuyer_e);
199 
200  seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
201  if (seed1 < 0) seed1 += shift1;
202  seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
203  if (seed2 < 0) seed2 += shift2;
204 
205  table[index][0] = seed1;
206  table[index][1] = seed2;
207 
208  long diff = seed1-seed2;
209 
210  if (diff <= 0) diff += (shift1-1);
211  return (double)(diff*prec);
212 }
static const int shift1
Definition: RanecuEngine.h:112
static const int ecuyer_b
Definition: RanecuEngine.h:107
static const int ecuyer_f
Definition: RanecuEngine.h:111
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int ecuyer_a
Definition: RanecuEngine.h:106
static const int shift2
Definition: RanecuEngine.h:113
static const int ecuyer_e
Definition: RanecuEngine.h:110
static const int ecuyer_d
Definition: RanecuEngine.h:109
static const int ecuyer_c
Definition: RanecuEngine.h:108
void CLHEP::RanecuEngine::flatArray ( const int  size,
double *  vect 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 214 of file RanecuEngine.cc.

References ecuyer_a, ecuyer_b, ecuyer_c, ecuyer_d, ecuyer_e, ecuyer_f, int(), shift1, and shift2.

215 {
216  const int index = seq;
217  long seed1 = table[index][0];
218  long seed2 = table[index][1];
219  int k1, k2;
220  register int i;
221 
222  for (i=0; i<size; ++i)
223  {
224  k1 = (int)(seed1/ecuyer_b);
225  k2 = (int)(seed2/ecuyer_e);
226 
227  seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
228  if (seed1 < 0) seed1 += shift1;
229  seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
230  if (seed2 < 0) seed2 += shift2;
231 
232  long diff = seed1-seed2;
233  if (diff <= 0) diff += (shift1-1);
234 
235  vect[i] = (double)(diff*prec);
236  }
237  table[index][0] = seed1;
238  table[index][1] = seed2;
239 }
static const int shift1
Definition: RanecuEngine.h:112
static const int ecuyer_b
Definition: RanecuEngine.h:107
static const int ecuyer_f
Definition: RanecuEngine.h:111
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int ecuyer_a
Definition: RanecuEngine.h:106
static const int shift2
Definition: RanecuEngine.h:113
static const int ecuyer_e
Definition: RanecuEngine.h:110
static const int ecuyer_d
Definition: RanecuEngine.h:109
static const int ecuyer_c
Definition: RanecuEngine.h:108
std::istream & CLHEP::RanecuEngine::get ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 282 of file RanecuEngine.cc.

References getState().

283 {
284  char beginMarker [MarkerLen];
285 
286  is >> std::ws;
287  is.width(MarkerLen); // causes the next read to the char* to be <=
288  // that many bytes, INCLUDING A TERMINATION \0
289  // (Stroustrup, section 21.3.2)
290  is >> beginMarker;
291  if (strcmp(beginMarker,"RanecuEngine-begin")) {
292  is.clear(std::ios::badbit | is.rdstate());
293  std::cerr << "\nInput stream mispositioned or"
294  << "\nRanecuEngine state description missing or"
295  << "\nwrong engine type found." << std::endl;
296  return is;
297  }
298  return getState(is);
299 }
virtual std::istream & getState(std::istream &is)
bool CLHEP::RanecuEngine::get ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 344 of file RanecuEngine.cc.

References getState().

344  {
345  if ((v[0] & 0xffffffffUL) != engineIDulong<RanecuEngine>()) {
346  std::cerr <<
347  "\nRanecuEngine get:state vector has wrong ID word - state unchanged\n";
348  return false;
349  }
350  return getState(v);
351 }
virtual std::istream & getState(std::istream &is)
std::istream & CLHEP::RanecuEngine::getState ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 305 of file RanecuEngine.cc.

References int(), CLHEP::possibleKeywordInput(), CLHEP::HepRandomEngine::theSeed, test::v, and VECTOR_STATE_SIZE.

Referenced by get(), and restoreStatus().

306 {
307  if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
308  std::vector<unsigned long> v;
309  unsigned long uu;
310  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
311  is >> uu;
312  if (!is) {
313  is.clear(std::ios::badbit | is.rdstate());
314  std::cerr << "\nRanecuEngine state (vector) description improper."
315  << "\ngetState() has failed."
316  << "\nInput stream is probably mispositioned now." << std::endl;
317  return is;
318  }
319  v.push_back(uu);
320  }
321  getState(v);
322  return (is);
323  }
324 
325 // is >> theSeed; Removed, encompassed by possibleKeywordInput()
326  char endMarker [MarkerLen];
327  for (int i=0; i<2; ++i) {
328  is >> table[theSeed][i];
329  }
330  is >> std::ws;
331  is.width(MarkerLen);
332  is >> endMarker;
333  if (strcmp(endMarker,"RanecuEngine-end")) {
334  is.clear(std::ios::badbit | is.rdstate());
335  std::cerr << "\nRanecuEngine state description incomplete."
336  << "\nInput stream is probably mispositioned now." << std::endl;
337  return is;
338  }
339 
340  seq = int(theSeed);
341  return is;
342 }
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const unsigned int VECTOR_STATE_SIZE
Definition: RanecuEngine.h:115
virtual std::istream & getState(std::istream &is)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
bool CLHEP::RanecuEngine::getState ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 353 of file RanecuEngine.cc.

References int(), CLHEP::HepRandomEngine::theSeed, and VECTOR_STATE_SIZE.

353  {
354  if (v.size() != VECTOR_STATE_SIZE ) {
355  std::cerr <<
356  "\nRanecuEngine get:state vector has wrong length - state unchanged\n";
357  return false;
358  }
359  theSeed = v[1];
360  table[theSeed][0] = v[2];
361  table[theSeed][1] = v[3];
362  seq = int(theSeed);
363  return true;
364 }
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const unsigned int VECTOR_STATE_SIZE
Definition: RanecuEngine.h:115
std::string CLHEP::RanecuEngine::name ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 53 of file RanecuEngine.cc.

53 {return "RanecuEngine";}
CLHEP::RanecuEngine::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 241 of file RanecuEngine.cc.

References int().

241  {
242  const int index = seq;
243  long seed1 = table[index][0];
244  long seed2 = table[index][1];
245 
246  int k1 = (int)(seed1/ecuyer_b);
247  int k2 = (int)(seed2/ecuyer_e);
248 
249  seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
250  if (seed1 < 0) seed1 += shift1;
251  seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
252  if (seed2 < 0) seed2 += shift2;
253 
254  table[index][0] = seed1;
255  table[index][1] = seed2;
256  long diff = seed1-seed2;
257  if( diff <= 0 ) diff += (shift1-1);
258 
259  return ((diff << 1) | (seed1&1))& 0xffffffff;
260 }
static const int shift1
Definition: RanecuEngine.h:112
static const int ecuyer_b
Definition: RanecuEngine.h:107
static const int ecuyer_f
Definition: RanecuEngine.h:111
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int ecuyer_a
Definition: RanecuEngine.h:106
static const int shift2
Definition: RanecuEngine.h:113
static const int ecuyer_e
Definition: RanecuEngine.h:110
static const int ecuyer_d
Definition: RanecuEngine.h:109
static const int ecuyer_c
Definition: RanecuEngine.h:108
std::ostream & CLHEP::RanecuEngine::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 262 of file RanecuEngine.cc.

References put(), and test::v.

263 {
264  char beginMarker[] = "RanecuEngine-begin";
265  os << beginMarker << "\nUvec\n";
266  std::vector<unsigned long> v = put();
267  for (unsigned int i=0; i<v.size(); ++i) {
268  os << v[i] << "\n";
269  }
270  return os;
271 }
std::vector< unsigned long > put() const
std::vector< unsigned long > CLHEP::RanecuEngine::put ( ) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 273 of file RanecuEngine.cc.

References CLHEP::HepRandomEngine::theSeed, and test::v.

Referenced by put(), and saveStatus().

273  {
274  std::vector<unsigned long> v;
275  v.push_back (engineIDulong<RanecuEngine>());
276  v.push_back(static_cast<unsigned long>(theSeed));
277  v.push_back(static_cast<unsigned long>(table[theSeed][0]));
278  v.push_back(static_cast<unsigned long>(table[theSeed][1]));
279  return v;
280 }
void CLHEP::RanecuEngine::restoreStatus ( const char  filename[] = "Ranecu.conf")
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 147 of file RanecuEngine.cc.

References CLHEP::HepRandomEngine::checkFile(), engineName(), getState(), int(), CLHEP::possibleKeywordInput(), CLHEP::HepRandomEngine::theSeed, test::v, and VECTOR_STATE_SIZE.

148 {
149  std::ifstream inFile( filename, std::ios::in);
150  if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
151  std::cerr << " -- Engine state remains unchanged\n";
152  return;
153  }
154  if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
155  std::vector<unsigned long> v;
156  unsigned long xin;
157  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
158  inFile >> xin;
159  if (!inFile) {
160  inFile.clear(std::ios::badbit | inFile.rdstate());
161  std::cerr << "\nJamesRandom state (vector) description improper."
162  << "\nrestoreStatus has failed."
163  << "\nInput stream is probably mispositioned now." << std::endl;
164  return;
165  }
166  v.push_back(xin);
167  }
168  getState(v);
169  return;
170  }
171 
172  if (!inFile.bad() && !inFile.eof()) {
173 // inFile >> theSeed; removed -- encompased by possibleKeywordInput
174  for (int i=0; i<2; ++i)
175  inFile >> table[theSeed][i];
176  seq = int(theSeed);
177  }
178 }
static std::string engineName()
Definition: RanecuEngine.h:96
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const unsigned int VECTOR_STATE_SIZE
Definition: RanecuEngine.h:115
virtual std::istream & getState(std::istream &is)
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:45
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
void CLHEP::RanecuEngine::saveStatus ( const char  filename[] = "Ranecu.conf") const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 134 of file RanecuEngine.cc.

References outFile, put(), and test::v.

135 {
136  std::ofstream outFile( filename, std::ios::out ) ;
137 
138  if (!outFile.bad()) {
139  outFile << "Uvec\n";
140  std::vector<unsigned long> v = put();
141  for (unsigned int i=0; i<v.size(); ++i) {
142  outFile << v[i] << "\n";
143  }
144  }
145 }
std::ofstream outFile
Definition: GammaRayTel.cc:68
std::vector< unsigned long > put() const
void CLHEP::RanecuEngine::setIndex ( long  index)

Definition at line 127 of file RanecuEngine.cc.

References CLHEP::HepRandomEngine::theSeed, and CLHEP::HepRandomEngine::theSeeds.

128 {
129  seq = std::abs(int(index%maxSeq));
130  theSeed = seq;
131  theSeeds = &table[seq][0];
132 }
void CLHEP::RanecuEngine::setSeed ( long  index,
int  dum = 0 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 105 of file RanecuEngine.cc.

References CLHEP::HepRandom::getTheTableSeeds(), shift1, shift2, CLHEP::HepRandomEngine::theSeed, and CLHEP::HepRandomEngine::theSeeds.

106 {
107  seq = std::abs(int(index%maxSeq));
108  theSeed = seq;
109  HepRandom::getTheTableSeeds(table[seq],seq);
110  theSeeds = &table[seq][0];
111  further_randomize (seq, 0, index, shift1); // mf 6/22/10
112  further_randomize (seq, 1, dum, shift2); // mf 6/22/10
113 }
static const int shift1
Definition: RanecuEngine.h:112
static const int shift2
Definition: RanecuEngine.h:113
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:151
void CLHEP::RanecuEngine::setSeeds ( const long *  seeds,
int  index = -1 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 115 of file RanecuEngine.cc.

References shift1, shift2, CLHEP::HepRandomEngine::theSeed, and CLHEP::HepRandomEngine::theSeeds.

116 {
117  if (pos != -1) {
118  seq = std::abs(int(pos%maxSeq));
119  theSeed = seq;
120  }
121  // only positive seeds are allowed
122  table[seq][0] = std::abs(seeds[0])%shift1;
123  table[seq][1] = std::abs(seeds[1])%shift2;
124  theSeeds = &table[seq][0];
125 }
static const int shift1
Definition: RanecuEngine.h:112
static const int shift2
Definition: RanecuEngine.h:113
void CLHEP::RanecuEngine::showStatus ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 180 of file RanecuEngine.cc.

References CLHEP::HepRandomEngine::theSeed.

181 {
182  std::cout << std::endl;
183  std::cout << "--------- Ranecu engine status ---------" << std::endl;
184  std::cout << " Initial seed (index) = " << theSeed << std::endl;
185  std::cout << " Current couple of seeds = "
186  << table[theSeed][0] << ", "
187  << table[theSeed][1] << std::endl;
188  std::cout << "----------------------------------------" << std::endl;
189 }

Field Documentation

const int CLHEP::RanecuEngine::ecuyer_a = 40014
staticprotected

Definition at line 106 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

const int CLHEP::RanecuEngine::ecuyer_b = 53668
staticprotected

Definition at line 107 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

const int CLHEP::RanecuEngine::ecuyer_c = 12211
staticprotected

Definition at line 108 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

const int CLHEP::RanecuEngine::ecuyer_d = 40692
staticprotected

Definition at line 109 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

const int CLHEP::RanecuEngine::ecuyer_e = 52774
staticprotected

Definition at line 110 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

const int CLHEP::RanecuEngine::ecuyer_f = 3791
staticprotected

Definition at line 111 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

const int CLHEP::RanecuEngine::shift1 = 2147483563
staticprotected

Definition at line 112 of file RanecuEngine.h.

Referenced by flat(), flatArray(), RanecuEngine(), setSeed(), and setSeeds().

const int CLHEP::RanecuEngine::shift2 = 2147483399
staticprotected

Definition at line 113 of file RanecuEngine.h.

Referenced by flat(), flatArray(), setSeed(), and setSeeds().

const unsigned int CLHEP::RanecuEngine::VECTOR_STATE_SIZE = 4
staticprotected

Definition at line 115 of file RanecuEngine.h.

Referenced by getState(), and restoreStatus().


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