Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
CLHEP::RandFlat Class Reference

#include <RandFlat.h>

+ Inheritance diagram for CLHEP::RandFlat:

Public Member Functions

 RandFlat (HepRandomEngine &anEngine)
 
 RandFlat (HepRandomEngine &anEngine, double width)
 
 RandFlat (HepRandomEngine &anEngine, double a, double b)
 
 RandFlat (HepRandomEngine *anEngine)
 
 RandFlat (HepRandomEngine *anEngine, double width)
 
 RandFlat (HepRandomEngine *anEngine, double a, double b)
 
virtual ~RandFlat ()
 
double fire ()
 
double fire (double width)
 
double fire (double a, double b)
 
long fireInt (long n)
 
long fireInt (long m, long n)
 
int fireBit ()
 
void fireArray (const int size, double *vect)
 
void fireArray (const int size, double *vect, double lx, double dx)
 
double operator() ()
 
double operator() (double width)
 
double operator() (double a, double b)
 
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)
 
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 double shoot ()
 
static double shoot (double width)
 
static double shoot (double a, double b)
 
static long shootInt (long n)
 
static long shootInt (long m, long n)
 
static int shootBit ()
 
static void shootArray (const int size, double *vect)
 
static void shootArray (const int size, double *vect, double lx, double dx)
 
static double shoot (HepRandomEngine *anEngine)
 
static double shoot (HepRandomEngine *anEngine, double width)
 
static double shoot (HepRandomEngine *anEngine, double a, double b)
 
static long shootInt (HepRandomEngine *anEngine, long n)
 
static long shootInt (HepRandomEngine *anEngine, long m, long n)
 
static int shootBit (HepRandomEngine *)
 
static void shootArray (HepRandomEngine *anEngine, const int size, double *vect)
 
static void shootArray (HepRandomEngine *anEngine, const int size, double *vect, double lx, double dx)
 
static std::string distributionName ()
 
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 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 ()
 

Additional Inherited Members

- Static Protected Attributes inherited from CLHEP::HepRandom
static const long seedTable [215][2]
 

Detailed Description

Constructor & Destructor Documentation

◆ RandFlat() [1/6]

CLHEP::RandFlat::RandFlat ( HepRandomEngine anEngine)
inline

◆ RandFlat() [2/6]

CLHEP::RandFlat::RandFlat ( HepRandomEngine anEngine,
double  width 
)
inline

◆ RandFlat() [3/6]

CLHEP::RandFlat::RandFlat ( HepRandomEngine anEngine,
double  a,
double  b 
)
inline

◆ RandFlat() [4/6]

CLHEP::RandFlat::RandFlat ( HepRandomEngine anEngine)
inline

◆ RandFlat() [5/6]

CLHEP::RandFlat::RandFlat ( HepRandomEngine anEngine,
double  width 
)
inline

◆ RandFlat() [6/6]

CLHEP::RandFlat::RandFlat ( HepRandomEngine anEngine,
double  a,
double  b 
)
inline

◆ ~RandFlat()

CLHEP::RandFlat::~RandFlat ( )
virtual

Definition at line 44 of file RandFlat.cc.

44 {
45}

Member Function Documentation

◆ distributionName()

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

Definition at line 136 of file RandFlat.h.

136{return "RandFlat";}

Referenced by restoreDistState(), and saveDistState().

◆ engine()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 42 of file RandFlat.cc.

42{return *localEngine;}

◆ fire() [1/3]

double CLHEP::RandFlat::fire ( )
inline

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

◆ fire() [2/3]

double CLHEP::RandFlat::fire ( double  a,
double  b 
)
inline

◆ fire() [3/3]

double CLHEP::RandFlat::fire ( double  width)
inline

◆ fireArray() [1/2]

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

Definition at line 86 of file RandFlat.cc.

87{
88 int i;
89
90 for (i=0; i<size; ++i)
91 vect[i] = fire( defaultA, defaultB );
92}

◆ fireArray() [2/2]

void CLHEP::RandFlat::fireArray ( const int  size,
double *  vect,
double  lx,
double  dx 
)

Definition at line 94 of file RandFlat.cc.

96{
97 int i;
98
99 for (i=0; i<size; ++i)
100 vect[i] = fire( lx, dx );
101}

◆ fireBit()

int CLHEP::RandFlat::fireBit ( )
inline

◆ fireInt() [1/2]

long CLHEP::RandFlat::fireInt ( long  m,
long  n 
)
inline

◆ fireInt() [2/2]

long CLHEP::RandFlat::fireInt ( long  n)
inline

◆ get()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 171 of file RandFlat.cc.

171 {
172 std::string inName;
173 is >> inName;
174 if (inName != name()) {
175 is.clear(std::ios::badbit | is.rdstate());
176 std::cerr << "Mismatch when expecting to read state of a "
177 << name() << " distribution\n"
178 << "Name found was " << inName
179 << "\nistream is left in the badbit state\n";
180 return is;
181 }
182 if (possibleKeywordInput(is, "Uvec", randomInt)) {
183 std::vector<unsigned long> t(2);
184 is >> randomInt >> firstUnusedBit;
185 is >> defaultWidth >>t[0]>>t[1]; defaultWidth = DoubConv::longs2double(t);
186 is >> defaultA >> t[0] >> t[1]; defaultA = DoubConv::longs2double(t);
187 is >> defaultB >> t[0] >> t[1]; defaultB = DoubConv::longs2double(t);
188 if (!is) {
189 is.clear(std::ios::badbit | is.rdstate());
190 std::cerr << "\nRandFlat input failed"
191 << "\nInput stream is probably mispositioned now." << std::endl;
192 return is;
193 }
194 return is;
195 }
196 // is >> randomInt encompassed by possibleKeywordInput
197 is >> firstUnusedBit;
198 is >> defaultWidth >> defaultA >> defaultB;
199 return is;
200}
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:114
std::string name() const
Definition: RandFlat.cc:41
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167

Referenced by CLHEP::RandBit::get().

◆ name()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 41 of file RandFlat.cc.

41{return "RandFlat";}

Referenced by get(), and put().

◆ operator()() [1/3]

double CLHEP::RandFlat::operator() ( )
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 47 of file RandFlat.cc.

47 {
48 return fire( defaultA, defaultB );
49}

◆ operator()() [2/3]

double CLHEP::RandFlat::operator() ( double  a,
double  b 
)

Definition at line 55 of file RandFlat.cc.

55 {
56 return fire( a, b );
57}

◆ operator()() [3/3]

double CLHEP::RandFlat::operator() ( double  width)

Definition at line 51 of file RandFlat.cc.

51 {
52 return fire( w );
53}

◆ put()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 155 of file RandFlat.cc.

155 {
156 int pr=os.precision(20);
157 std::vector<unsigned long> t(2);
158 os << " " << name() << "\n";
159 os << "Uvec" << "\n";
160 os << randomInt << " " << firstUnusedBit << "\n";
161 t = DoubConv::dto2longs(defaultWidth);
162 os << defaultWidth << " " << t[0] << " " << t[1] << "\n";
163 t = DoubConv::dto2longs(defaultA);
164 os << defaultA << " " << t[0] << " " << t[1] << "\n";
165 t = DoubConv::dto2longs(defaultB);
166 os << defaultB << " " << t[0] << " " << t[1] << "\n";
167 os.precision(pr);
168 return os;
169}
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:98

Referenced by CLHEP::RandBit::put().

◆ restoreDistState()

std::istream & CLHEP::RandFlat::restoreDistState ( std::istream &  is)
static

Definition at line 211 of file RandFlat.cc.

211 {
212 std::string inName;
213 is >> inName;
214 if (inName != distributionName()) {
215 is.clear(std::ios::badbit | is.rdstate());
216 std::cerr << "Mismatch when expecting to read static state of a "
217 << distributionName() << " distribution\n"
218 << "Name found was " << inName
219 << "\nistream is left in the badbit state\n";
220 return is;
221 }
222 std::string keyword;
223 std::string c1;
224 std::string c2;
225 is >> keyword;
226 if (keyword!="RANDFLAT") {
227 is.clear(std::ios::badbit | is.rdstate());
228 std::cerr << "Mismatch when expecting to read RANDFLAT bit cache info: "
229 << keyword << "\n";
230 return is;
231 }
232 is >> c1 >> staticRandomInt >> c2 >> staticFirstUnusedBit;
233 return is;
234}
static std::string distributionName()
Definition: RandFlat.h:136

Referenced by CLHEP::StaticRandomStates::restore(), CLHEP::RandBit::restoreDistState(), and restoreFullState().

◆ restoreEngineStatus()

void CLHEP::RandFlat::restoreEngineStatus ( const char  filename[] = "Config.conf")
static

Definition at line 118 of file RandFlat.cc.

118 {
119
120 // First restore the engine status just like the base class would do:
121 getTheEngine()->restoreStatus( filename );
122
123 // Now find the line describing the cached data:
124
125 std::ifstream infile ( filename, std::ios::in );
126 if (!infile) return;
127 char inputword[] = "NO_KEYWORD "; // leaves room for 14 characters plus \0
128 while (true) {
129 infile.width(13);
130 infile >> inputword;
131 if (strcmp(inputword,"RANDFLAT")==0) break;
132 if (infile.eof()) break;
133 // If the file ends without the RANDFLAT line, that means this
134 // was a file produced by an earlier version of RandFlat. We will
135 // replicate the old behavior in that case: staticFirstUnusedBit
136 // and staticRandomInt retain their existing values.
137 }
138
139 // Then read and use the caching info:
140
141 if (strcmp(inputword,"RANDFLAT")==0) {
142 char setword[40]; // the longest, staticFirstUnusedBit: has length 21
143 infile.width(39);
144 infile >> setword;
145 // setword should be staticRandomInt:
146 infile >> staticRandomInt;
147 infile.width(39);
148 infile >> setword;
149 // setword should be staticFirstUnusedBit:
150 infile >> staticFirstUnusedBit;
151 }
152
153} // restoreEngineStatus
virtual void restoreStatus(const char filename[]="Config.conf")=0
static HepRandomEngine * getTheEngine()
Definition: Random.cc:165

◆ restoreFullState()

std::istream & CLHEP::RandFlat::restoreFullState ( std::istream &  is)
static

Definition at line 242 of file RandFlat.cc.

242 {
245 return is;
246}
static std::istream & restoreFullState(std::istream &is)
Definition: Random.cc:190
static std::istream & restoreDistState(std::istream &is)
Definition: RandFlat.cc:211

Referenced by CLHEP::RandBit::restoreFullState().

◆ saveDistState()

std::ostream & CLHEP::RandFlat::saveDistState ( std::ostream &  os)
static

Definition at line 202 of file RandFlat.cc.

202 {
203 os << distributionName() << "\n";
204 int prec = os.precision(20);
205 os << "RANDFLAT staticRandomInt: " << staticRandomInt
206 << " staticFirstUnusedBit: " << staticFirstUnusedBit << "\n";
207 os.precision(prec);
208 return os;
209}

Referenced by CLHEP::StaticRandomStates::save(), CLHEP::RandBit::saveDistState(), and saveFullState().

◆ saveEngineStatus()

void CLHEP::RandFlat::saveEngineStatus ( const char  filename[] = "Config.conf")
static

Definition at line 103 of file RandFlat.cc.

103 {
104
105 // First save the engine status just like the base class would do:
106 getTheEngine()->saveStatus( filename );
107
108 // Now append the cached random Int, and first unused bit:
109
110 std::ofstream outfile ( filename, std::ios::app );
111
112 outfile << "RANDFLAT staticRandomInt: " << staticRandomInt
113 << " staticFirstUnusedBit: " << staticFirstUnusedBit << "\n";
114
115} // saveEngineStatus
virtual void saveStatus(const char filename[]="Config.conf") const =0

◆ saveFullState()

std::ostream & CLHEP::RandFlat::saveFullState ( std::ostream &  os)
static

Definition at line 236 of file RandFlat.cc.

236 {
238 saveDistState(os);
239 return os;
240}
static std::ostream & saveFullState(std::ostream &os)
Definition: Random.cc:185
static std::ostream & saveDistState(std::ostream &os)
Definition: RandFlat.cc:202

Referenced by CLHEP::RandBit::saveFullState().

◆ shoot() [1/6]

◆ shoot() [2/6]

static double CLHEP::RandFlat::shoot ( double  a,
double  b 
)
inlinestatic

◆ shoot() [3/6]

static double CLHEP::RandFlat::shoot ( double  width)
inlinestatic

◆ shoot() [4/6]

static double CLHEP::RandFlat::shoot ( HepRandomEngine anEngine)
inlinestatic

◆ shoot() [5/6]

static double CLHEP::RandFlat::shoot ( HepRandomEngine anEngine,
double  a,
double  b 
)
inlinestatic

◆ shoot() [6/6]

static double CLHEP::RandFlat::shoot ( HepRandomEngine anEngine,
double  width 
)
inlinestatic

◆ shootArray() [1/4]

void CLHEP::RandFlat::shootArray ( const int  size,
double *  vect 
)
static

Definition at line 63 of file RandFlat.cc.

63 {
65}
virtual void flatArray(const int size, double *vect)=0

◆ shootArray() [2/4]

void CLHEP::RandFlat::shootArray ( const int  size,
double *  vect,
double  lx,
double  dx 
)
static

Definition at line 67 of file RandFlat.cc.

69{
70 int i;
71
72 for (i=0; i<size; ++i)
73 vect[i] = shoot(lx,dx);
74}
static double shoot()
Definition: RandFlat.cc:59

◆ shootArray() [3/4]

static void CLHEP::RandFlat::shootArray ( HepRandomEngine anEngine,
const int  size,
double *  vect 
)
inlinestatic

◆ shootArray() [4/4]

void CLHEP::RandFlat::shootArray ( HepRandomEngine anEngine,
const int  size,
double *  vect,
double  lx,
double  dx 
)
static

Definition at line 76 of file RandFlat.cc.

79{
80 int i;
81
82 for (i=0; i<size; ++i)
83 vect[i] = shoot(anEngine,lx,dx);
84}

◆ shootBit() [1/2]

static int CLHEP::RandFlat::shootBit ( )
inlinestatic

◆ shootBit() [2/2]

static int CLHEP::RandFlat::shootBit ( HepRandomEngine )
inlinestatic

◆ shootInt() [1/4]

static long CLHEP::RandFlat::shootInt ( HepRandomEngine anEngine,
long  m,
long  n 
)
inlinestatic

◆ shootInt() [2/4]

static long CLHEP::RandFlat::shootInt ( HepRandomEngine anEngine,
long  n 
)
inlinestatic

◆ shootInt() [3/4]

static long CLHEP::RandFlat::shootInt ( long  m,
long  n 
)
inlinestatic

◆ shootInt() [4/4]

static long CLHEP::RandFlat::shootInt ( long  n)
inlinestatic

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