CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
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)
 
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 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 48 of file RandFlat.cc.

48 {
49}

Member Function Documentation

◆ distributionName()

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

Definition at line 138 of file RandFlat.h.

138{return "RandFlat";}

Referenced by restoreDistState(), and saveDistState().

◆ engine()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 46 of file RandFlat.cc.

46{return *localEngine;}

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

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

Referenced by dist_layout().

◆ fireArray() [2/2]

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

Definition at line 98 of file RandFlat.cc.

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

◆ 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

Referenced by dist_layout().

◆ get()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 190 of file RandFlat.cc.

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

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

◆ name()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 45 of file RandFlat.cc.

45{return "RandFlat";}

Referenced by get(), and put().

◆ operator()() [1/3]

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

Reimplemented from CLHEP::HepRandom.

Definition at line 51 of file RandFlat.cc.

51 {
52 return fire( defaultA, defaultB );
53}

◆ operator()() [2/3]

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

Definition at line 59 of file RandFlat.cc.

59 {
60 return fire( a, b );
61}

◆ operator()() [3/3]

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

Definition at line 55 of file RandFlat.cc.

55 {
56 return fire( w );
57}

◆ put()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 159 of file RandFlat.cc.

159 {
160 long pr=os.precision(20);
161 std::vector<unsigned long> t(2);
162 os << " " << name() << "\n";
163 os << "Uvec" << "\n";
164 os << randomInt << " " << firstUnusedBit << "\n";
165 t = DoubConv::dto2longs(defaultWidth);
166 os << defaultWidth << " " << t[0] << " " << t[1] << "\n";
167 t = DoubConv::dto2longs(defaultA);
168 os << defaultA << " " << t[0] << " " << t[1] << "\n";
169 t = DoubConv::dto2longs(defaultB);
170 os << defaultB << " " << t[0] << " " << t[1] << "\n";
171 #ifdef TRACE_IO
172 std::cout << "RandFlat::put(): randomInt = " << randomInt
173 << " firstUnusedBit = " << firstUnusedBit
174 << "\ndefaultWidth = " << defaultWidth
175 << " defaultA = " << defaultA
176 << " defaultB = " << defaultB << "\n";
177 #endif
178 os.precision(pr);
179 return os;
180#ifdef REMOVED
181 long pr=os.precision(20);
182 os << " " << name() << "\n";
183 os << randomInt << " " << firstUnusedBit << "\n";
184 os << defaultWidth << " " << defaultA << " " << defaultB << "\n";
185 os.precision(pr);
186 return os;
187#endif
188}
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 237 of file RandFlat.cc.

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

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

◆ restoreEngineStatus()

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

Definition at line 122 of file RandFlat.cc.

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

Referenced by BrestoreStep().

◆ restoreFullState()

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

Definition at line 268 of file RandFlat.cc.

268 {
271 return is;
272}
static std::istream & restoreFullState(std::istream &is)
Definition: Random.cc:295
static std::istream & restoreDistState(std::istream &is)
Definition: RandFlat.cc:237

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

◆ saveDistState()

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

Definition at line 228 of file RandFlat.cc.

228 {
229 os << distributionName() << "\n";
230 long prec = os.precision(20);
231 os << "RANDFLAT staticRandomInt: " << staticRandomInt
232 << " staticFirstUnusedBit: " << staticFirstUnusedBit << "\n";
233 os.precision(prec);
234 return os;
235}

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

◆ saveEngineStatus()

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

Definition at line 107 of file RandFlat.cc.

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

Referenced by BsaveStep().

◆ saveFullState()

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

Definition at line 262 of file RandFlat.cc.

262 {
264 saveDistState(os);
265 return os;
266}
static std::ostream & saveFullState(std::ostream &os)
Definition: Random.cc:290
static std::ostream & saveDistState(std::ostream &os)
Definition: RandFlat.cc:228

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

◆ shoot() [1/6]

double CLHEP::RandFlat::shoot ( )
static

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

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

Referenced by layout(), and user_layout().

◆ shootArray() [2/4]

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

Definition at line 71 of file RandFlat.cc.

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

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

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

◆ 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  a1,
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  a1,
long  n 
)
inlinestatic

◆ shootInt() [4/4]

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

Referenced by layout(), and user_layout().


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