CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
RanluxEngine.h
Go to the documentation of this file.
1// $Id: RanluxEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- RanluxEngine ---
7// class header file
8// -----------------------------------------------------------------------
9// This file is part of Geant4 (simulation toolkit for HEP).
10//
11// The algorithm for this random engine has been taken from the original
12// implementation in FORTRAN by Fred James as part of the MATHLIB HEP
13// library.
14// The initialisation is carried out using a Multiplicative Congruential
15// generator using formula constants of L'Ecuyer as described in "F.James,
16// Comp. Phys. Comm. 60 (1990) 329-344".
17
18// =======================================================================
19// Adeyemi Adesanya - Created: 6th November 1995
20// Gabriele Cosmo - Adapted & Revised: 22nd November 1995
21// Adeyemi Adesanya - Added setSeeds() method: 2nd February 1996
22// Gabriele Cosmo - Added flatArray() method: 8th February 1996
23// - Added methods for engine status: 19th November 1996
24// - Added default luxury value for setSeed()
25// and setSeeds(): 21st July 1997
26// J.Marraffino - Added stream operators and related constructor.
27// Added automatic seed selection from seed table and
28// engine counter: 14th Feb 1998
29// Ken Smith - Added conversion operators: 6th Aug 1998
30// Mark Fischler Methods put, get for instance save/restore 12/8/04
31// Mark Fischler methods for anonymous save/restore 12/27/04
32// =======================================================================
33
34#ifndef RanluxEngine_h
35#define RanluxEngine_h 1
36
37#include "CLHEP/Random/defs.h"
38#include "CLHEP/Random/RandomEngine.h"
39
40namespace CLHEP {
41
42/**
43 * @author
44 * @ingroup random
45 */
47
48public:
49
50 RanluxEngine( std::istream& is );
52 RanluxEngine( long seed, int lxr = 3 );
53 RanluxEngine( int rowIndex, int colIndex, int lxr );
54 virtual ~RanluxEngine();
55 // Constructors and destructor
56
57// Luxury level is set in the same way as the original FORTRAN routine.
58// level 0 (p=24): equivalent to the original RCARRY of Marsaglia
59// and Zaman, very long period, but fails many tests.
60// level 1 (p=48): considerable improvement in quality over level 0,
61// now passes the gap test, but still fails spectral test.
62// level 2 (p=97): passes all known tests, but theoretically still
63// defective.
64// level 3 (p=223): DEFAULT VALUE. Any theoretically possible
65// correlations have very small chance of being observed.
66// level 4 (p=389): highest possible luxury, all 24 bits chaotic.
67
68 double flat();
69 // It returns a pseudo random number between 0 and 1,
70 // excluding the end points.
71
72 void flatArray (const int size, double* vect);
73 // Fills the array "vect" of specified size with flat random values.
74
75 void setSeed(long seed, int lxr=3);
76 // Sets the state of the algorithm according to seed.
77
78 void setSeeds(const long * seeds, int lxr=3);
79 // Sets the state of the algorithm according to the zero terminated
80 // array of seeds. Only the first seed is used.
81
82 void saveStatus( const char filename[] = "Ranlux.conf" ) const;
83 // Saves on file Ranlux.conf the current engine status.
84
85 void restoreStatus( const char filename[] = "Ranlux.conf" );
86 // Reads from file Ranlux.conf the last saved engine status
87 // and restores it.
88
89 void showStatus() const;
90 // Dumps the engine status on the screen.
91
92 int getLuxury() const { return luxury; }
93 // Gets the luxury level.
94
95 operator double(); // Returns same as flat()
96 operator float(); // less precise flat, faster if possible
97 operator unsigned int(); // 32-bit flat, but slower than double or float
98
99 virtual std::ostream & put (std::ostream & os) const;
100 virtual std::istream & get (std::istream & is);
101 static std::string beginTag ( );
102 virtual std::istream & getState ( std::istream & is );
103
104 std::string name() const;
105 static std::string engineName() {return "RanluxEngine";}
106
107 std::vector<unsigned long> put () const;
108 bool get (const std::vector<unsigned long> & v);
109 bool getState (const std::vector<unsigned long> & v);
110
111 static const unsigned int VECTOR_STATE_SIZE = 31;
112
113private:
114
115 int nskip, luxury;
116 float float_seed_table[24];
117 int i_lag,j_lag;
118 float carry;
119 int count24;
120 static const int int_modulus = 0x1000000;
121};
122
123} // namespace CLHEP
124
125#ifdef ENABLE_BACKWARDS_COMPATIBILITY
126// backwards compatibility will be enabled ONLY in CLHEP 1.9
127using namespace CLHEP;
128#endif
129
130#endif
static const unsigned int VECTOR_STATE_SIZE
Definition: RanluxEngine.h:111
void flatArray(const int size, double *vect)
std::string name() const
Definition: RanluxEngine.cc:70
void setSeeds(const long *seeds, int lxr=3)
virtual std::istream & getState(std::istream &is)
void saveStatus(const char filename[]="Ranlux.conf") const
std::vector< unsigned long > put() const
static std::string beginTag()
virtual std::istream & get(std::istream &is)
void showStatus() const
int getLuxury() const
Definition: RanluxEngine.h:92
void restoreStatus(const char filename[]="Ranlux.conf")
static std::string engineName()
Definition: RanluxEngine.h:105
void setSeed(long seed, int lxr=3)
#define double(obj)
Definition: excDblThrow.cc:32