Geant4 11.4.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 a1, 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)

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 a1, 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 a1, 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 lxr=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 46 of file RandFlat.cc.

46 {
47}

Member Function Documentation

◆ distributionName()

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

Definition at line 137 of file RandFlat.h.

137{return "RandFlat";}

Referenced by restoreDistState(), and saveDistState().

◆ engine()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 44 of file RandFlat.cc.

44{return *localEngine;}

Referenced by shootBit().

◆ fire() [1/3]

double CLHEP::RandFlat::fire ( )
inline

◆ 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 88 of file RandFlat.cc.

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

◆ fireArray() [2/2]

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

Definition at line 96 of file RandFlat.cc.

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

◆ fireBit()

int CLHEP::RandFlat::fireBit ( )
inline

◆ fireInt() [1/2]

long CLHEP::RandFlat::fireInt ( long a1,
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 201 of file RandFlat.cc.

201 {
202 std::string inName;
203 is >> inName;
204 if (inName != name()) {
205 is.clear(std::ios::badbit | is.rdstate());
206 std::cerr << "Mismatch when expecting to read state of a "
207 << name() << " distribution\n"
208 << "Name found was " << inName
209 << "\nistream is left in the badbit state\n";
210 return is;
211 }
212 if (possibleKeywordInput(is, "Uvec", randomInt)) {
213 std::vector<unsigned long> t(2);
214 is >> randomInt >> firstUnusedBit;
215 is >> defaultWidth >>t[0]>>t[1]; defaultWidth = DoubConv::longs2double(t);
216 is >> defaultA >> t[0] >> t[1]; defaultA = DoubConv::longs2double(t);
217 is >> defaultB >> t[0] >> t[1]; defaultB = DoubConv::longs2double(t);
218 if (!is) {
219 is.clear(std::ios::badbit | is.rdstate());
220 std::cerr << "\nRandFlat input failed"
221 << "\nInput stream is probably mispositioned now." << std::endl;
222 return is;
223 }
224 return is;
225 }
226 // is >> randomInt encompassed by possibleKeywordInput
227 is >> firstUnusedBit;
228 is >> defaultWidth >> defaultA >> defaultB;
229 return is;
230}
static double longs2double(const std::vector< unsigned long > &v)
Definition DoubConv.cc:110
std::string name() const
Definition RandFlat.cc:43
bool possibleKeywordInput(IS &is, const std::string &key, T &t)

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

◆ name()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 43 of file RandFlat.cc.

43{return "RandFlat";}

Referenced by get(), and put().

◆ operator()() [1/3]

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

Reimplemented from CLHEP::HepRandom.

Definition at line 49 of file RandFlat.cc.

49 {
50 return fire( defaultA, defaultB );
51}

◆ operator()() [2/3]

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

Definition at line 57 of file RandFlat.cc.

57 {
58 return fire( a, b );
59}

◆ operator()() [3/3]

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

Definition at line 53 of file RandFlat.cc.

53 {
54 return fire( w );
55}

◆ put()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 185 of file RandFlat.cc.

185 {
186 long pr=os.precision(20);
187 std::vector<unsigned long> t(2);
188 os << " " << name() << "\n";
189 os << "Uvec" << "\n";
190 os << randomInt << " " << firstUnusedBit << "\n";
191 t = DoubConv::dto2longs(defaultWidth);
192 os << defaultWidth << " " << t[0] << " " << t[1] << "\n";
193 t = DoubConv::dto2longs(defaultA);
194 os << defaultA << " " << t[0] << " " << t[1] << "\n";
195 t = DoubConv::dto2longs(defaultB);
196 os << defaultB << " " << t[0] << " " << t[1] << "\n";
197 os.precision(pr);
198 return os;
199}
static std::vector< unsigned long > dto2longs(double d)
Definition DoubConv.cc:94

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

◆ restoreDistState()

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

Definition at line 241 of file RandFlat.cc.

241 {
242 std::string inName;
243 is >> inName;
244 if (inName != distributionName()) {
245 is.clear(std::ios::badbit | is.rdstate());
246 std::cerr << "Mismatch when expecting to read static state of a "
247 << distributionName() << " distribution\n"
248 << "Name found was " << inName
249 << "\nistream is left in the badbit state\n";
250 return is;
251 }
252 std::string keyword;
253 std::string c1;
254 std::string c2;
255 is >> keyword;
256 if (keyword!="RANDFLAT") {
257 is.clear(std::ios::badbit | is.rdstate());
258 std::cerr << "Mismatch when expecting to read RANDFLAT bit cache info: "
259 << keyword << "\n";
260 return is;
261 }
262 is >> c1 >> staticRandomInt >> c2 >> staticFirstUnusedBit;
263 return is;
264}
static std::string distributionName()
Definition RandFlat.h:137

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

◆ restoreEngineStatus()

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

Definition at line 148 of file RandFlat.cc.

148 {
149
150 // First restore the engine status just like the base class would do:
151 getTheEngine()->restoreStatus( filename );
152
153 // Now find the line describing the cached data:
154
155 std::ifstream infile ( filename, std::ios::in );
156 if (!infile) return;
157 char inputword[] = "NO_KEYWORD "; // leaves room for 14 characters plus \0
158 while (true) {
159 infile.width(13);
160 infile >> inputword;
161 if (strcmp(inputword,"RANDFLAT")==0) break;
162 if (infile.eof()) break;
163 // If the file ends without the RANDFLAT line, that means this
164 // was a file produced by an earlier version of RandFlat. We will
165 // replicate the old behavior in that case: staticFirstUnusedBit
166 // and staticRandomInt retain their existing values.
167 }
168
169 // Then read and use the caching info:
170
171 if (strcmp(inputword,"RANDFLAT")==0) {
172 char setword[40]; // the longest, staticFirstUnusedBit: has length 21
173 infile.width(39);
174 infile >> setword;
175 // setword should be staticRandomInt:
176 infile >> staticRandomInt;
177 infile.width(39);
178 infile >> setword;
179 // setword should be staticFirstUnusedBit:
180 infile >> staticFirstUnusedBit;
181 }
182
183} // restoreEngineStatus
virtual void restoreStatus(const char filename[]="Config.conf")=0
static HepRandomEngine * getTheEngine()
Definition Random.cc:268

◆ restoreFullState()

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

Definition at line 272 of file RandFlat.cc.

272 {
275 return is;
276}
static std::istream & restoreFullState(std::istream &is)
Definition Random.cc:293
static std::istream & restoreDistState(std::istream &is)
Definition RandFlat.cc:241

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

◆ saveDistState()

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

Definition at line 232 of file RandFlat.cc.

232 {
233 os << distributionName() << "\n";
234 long prec = os.precision(20);
235 os << "RANDFLAT staticRandomInt: " << staticRandomInt
236 << " staticFirstUnusedBit: " << staticFirstUnusedBit << "\n";
237 os.precision(prec);
238 return os;
239}

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

◆ saveEngineStatus()

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

Definition at line 133 of file RandFlat.cc.

133 {
134
135 // First save the engine status just like the base class would do:
136 getTheEngine()->saveStatus( filename );
137
138 // Now append the cached random Int, and first unused bit:
139
140 std::ofstream outfile ( filename, std::ios::app );
141
142 outfile << "RANDFLAT staticRandomInt: " << staticRandomInt
143 << " staticFirstUnusedBit: " << staticFirstUnusedBit << "\n";
144
145} // saveEngineStatus
virtual void saveStatus(const char filename[]="Config.conf") const =0

◆ saveFullState()

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

Definition at line 266 of file RandFlat.cc.

266 {
268 saveDistState(os);
269 return os;
270}
static std::ostream & saveFullState(std::ostream &os)
Definition Random.cc:288
static std::ostream & saveDistState(std::ostream &os)
Definition RandFlat.cc:232

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

◆ shoot() [1/6]

◆ shoot() [2/6]

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

◆ shoot() [3/6]

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

◆ shoot() [4/6]

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

◆ shoot() [5/6]

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

◆ shoot() [6/6]

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 65 of file RandFlat.cc.

65 {
67}
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 69 of file RandFlat.cc.

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

◆ shootArray() [3/4]

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 78 of file RandFlat.cc.

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

◆ shootBit() [1/2]

int CLHEP::RandFlat::shootBit ( )
static

Definition at line 111 of file RandFlat.cc.

111 {
112 if (staticFirstUnusedBit==0)
113 shootBits();
114 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
115 staticFirstUnusedBit>>= 1;
116 return temp!=0;
117}

◆ shootBit() [2/2]

int CLHEP::RandFlat::shootBit ( HepRandomEngine * engine)
static

Definition at line 125 of file RandFlat.cc.

125 {
126 if (staticFirstUnusedBit==0)
127 shootBits(engine);
128 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
129 staticFirstUnusedBit>>= 1;
130 return temp!=0;
131}
HepRandomEngine & engine()
Definition RandFlat.cc:44

◆ shootInt() [1/4]

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

◆ shootInt() [2/4]

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

◆ shootInt() [3/4]

long CLHEP::RandFlat::shootInt ( long a1,
long n )
inlinestatic

◆ shootInt() [4/4]

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

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