Geant4  10.02.p03
CLHEP::RandFlat Class Reference

#include <RandFlat.h>

Inheritance diagram for CLHEP::RandFlat:
Collaboration 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 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 ()
 

Private Member Functions

void fireBits ()
 

Static Private Member Functions

static void shootBits ()
 
static void shootBits (HepRandomEngine *)
 

Private Attributes

unsigned long randomInt
 
unsigned long firstUnusedBit
 
std::shared_ptr< HepRandomEnginelocalEngine
 
double defaultWidth
 
double defaultA
 
double defaultB
 

Static Private Attributes

static const unsigned long MSB = 1ul<<RandFlat::MSBBits
 
static const int MSBBits = 15
 
static CLHEP_THREAD_LOCAL unsigned long staticRandomInt = 0
 
static CLHEP_THREAD_LOCAL unsigned long staticFirstUnusedBit = 0
 

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
Here is the caller graph for this function:

◆ 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 137 of file RandFlat.h.

137 {return "RandFlat";}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ engine()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 42 of file RandFlat.cc.

42 {return *localEngine;}
std::shared_ptr< HepRandomEngine > localEngine
Definition: RandFlat.h:200

◆ fire() [1/3]

double CLHEP::RandFlat::fire ( )
inline
Here is the caller graph for this function:

◆ fire() [2/3]

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

◆ fire() [3/3]

double CLHEP::RandFlat::fire ( double  a,
double  b 
)
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 }
double defaultA
Definition: RandFlat.h:202
double defaultB
Definition: RandFlat.h:203
Here is the call graph for this function:

◆ 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 }
Here is the call graph for this function:

◆ fireBit()

int CLHEP::RandFlat::fireBit ( )
inline

◆ fireBits()

void CLHEP::RandFlat::fireBits ( )
inlineprivate
Here is the caller graph for this function:

◆ fireInt() [1/2]

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

◆ fireInt() [2/2]

long CLHEP::RandFlat::fireInt ( long  a1,
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 }
std::string name() const
Definition: RandFlat.cc:41
double defaultWidth
Definition: RandFlat.h:201
unsigned long randomInt
Definition: RandFlat.h:195
double defaultA
Definition: RandFlat.h:202
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
unsigned long firstUnusedBit
Definition: RandFlat.h:196
double defaultB
Definition: RandFlat.h:203
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:114
Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 41 of file RandFlat.cc.

41 {return "RandFlat";}
Here is the caller graph for this function:

◆ 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 }
double defaultA
Definition: RandFlat.h:202
double defaultB
Definition: RandFlat.h:203
Here is the call graph for this function:

◆ operator()() [2/3]

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

Definition at line 51 of file RandFlat.cc.

51  {
52  return fire( w );
53 }
Here is the call graph for this function:

◆ operator()() [3/3]

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

Definition at line 55 of file RandFlat.cc.

55  {
56  return fire( a, b );
57 }
Here is the call graph for this function:

◆ 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";
162  os << defaultWidth << " " << t[0] << " " << t[1] << "\n";
164  os << defaultA << " " << t[0] << " " << t[1] << "\n";
166  os << defaultB << " " << t[0] << " " << t[1] << "\n";
167  os.precision(pr);
168  return os;
169 }
std::string name() const
Definition: RandFlat.cc:41
double defaultWidth
Definition: RandFlat.h:201
unsigned long randomInt
Definition: RandFlat.h:195
double defaultA
Definition: RandFlat.h:202
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:98
unsigned long firstUnusedBit
Definition: RandFlat.h:196
double defaultB
Definition: RandFlat.h:203
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 CLHEP_THREAD_LOCAL unsigned long staticFirstUnusedBit
Definition: RandFlat.h:198
static CLHEP_THREAD_LOCAL unsigned long staticRandomInt
Definition: RandFlat.h:197
static std::string distributionName()
Definition: RandFlat.h:137
TCanvas * c2
Definition: plot_hist.C:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
static CLHEP_THREAD_LOCAL unsigned long staticFirstUnusedBit
Definition: RandFlat.h:198
ifstream in
Definition: comparison.C:7
static CLHEP_THREAD_LOCAL unsigned long staticRandomInt
Definition: RandFlat.h:197
static HepRandomEngine * getTheEngine()
Definition: Random.cc:166
virtual void restoreStatus(const char filename[]="Config.conf")=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ restoreFullState()

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

Definition at line 242 of file RandFlat.cc.

242  {
244  restoreDistState(is);
245  return is;
246 }
static std::istream & restoreDistState(std::istream &is)
Definition: RandFlat.cc:211
static std::istream & restoreFullState(std::istream &is)
Definition: Random.cc:191
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 }
static CLHEP_THREAD_LOCAL unsigned long staticFirstUnusedBit
Definition: RandFlat.h:198
static CLHEP_THREAD_LOCAL unsigned long staticRandomInt
Definition: RandFlat.h:197
static const double prec
Definition: RanecuEngine.cc:58
static std::string distributionName()
Definition: RandFlat.h:137
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
static CLHEP_THREAD_LOCAL unsigned long staticFirstUnusedBit
Definition: RandFlat.h:198
static CLHEP_THREAD_LOCAL unsigned long staticRandomInt
Definition: RandFlat.h:197
static HepRandomEngine * getTheEngine()
Definition: Random.cc:166
virtual void saveStatus(const char filename[]="Config.conf") const =0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 & saveDistState(std::ostream &os)
Definition: RandFlat.cc:202
static std::ostream & saveFullState(std::ostream &os)
Definition: Random.cc:186
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shoot() [1/6]

double CLHEP::RandFlat::shoot ( )
static

Definition at line 59 of file RandFlat.cc.

59  {
60  return HepRandom::getTheEngine()->flat();
61 }
virtual double flat()=0
static HepRandomEngine * getTheEngine()
Definition: Random.cc:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shoot() [2/6]

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

◆ shoot() [3/6]

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

◆ shoot() [4/6]

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

◆ shoot() [5/6]

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

◆ shoot() [6/6]

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

◆ shootArray() [1/4]

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

Definition at line 63 of file RandFlat.cc.

63  {
64  HepRandom::getTheEngine()->flatArray(size,vect);
65 }
static HepRandomEngine * getTheEngine()
Definition: Random.cc:166
virtual void flatArray(const int size, double *vect)=0
Here is the call graph for this function:

◆ 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
Here is the call graph for this function:

◆ 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 }
static double shoot()
Definition: RandFlat.cc:59
Here is the call graph for this function:

◆ shootBit() [1/2]

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

◆ shootBit() [2/2]

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

◆ shootBits() [1/2]

static void CLHEP::RandFlat::shootBits ( )
inlinestaticprivate
Here is the caller graph for this function:

◆ shootBits() [2/2]

static void CLHEP::RandFlat::shootBits ( HepRandomEngine )
inlinestaticprivate

◆ shootInt() [1/4]

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

◆ shootInt() [2/4]

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

◆ shootInt() [3/4]

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

◆ shootInt() [4/4]

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

Member Data Documentation

◆ defaultA

double CLHEP::RandFlat::defaultA
private

Definition at line 202 of file RandFlat.h.

◆ defaultB

double CLHEP::RandFlat::defaultB
private

Definition at line 203 of file RandFlat.h.

◆ defaultWidth

double CLHEP::RandFlat::defaultWidth
private

Definition at line 201 of file RandFlat.h.

◆ firstUnusedBit

unsigned long CLHEP::RandFlat::firstUnusedBit
private

Definition at line 196 of file RandFlat.h.

◆ localEngine

std::shared_ptr<HepRandomEngine> CLHEP::RandFlat::localEngine
private

Definition at line 200 of file RandFlat.h.

◆ MSB

const unsigned long CLHEP::RandFlat::MSB = 1ul<<RandFlat::MSBBits
staticprivate

Definition at line 191 of file RandFlat.h.

◆ MSBBits

const int CLHEP::RandFlat::MSBBits = 15
staticprivate

Definition at line 192 of file RandFlat.h.

◆ randomInt

unsigned long CLHEP::RandFlat::randomInt
private

Definition at line 195 of file RandFlat.h.

◆ staticFirstUnusedBit

CLHEP_THREAD_LOCAL unsigned long CLHEP::RandFlat::staticFirstUnusedBit = 0
staticprivate

Definition at line 198 of file RandFlat.h.

◆ staticRandomInt

CLHEP_THREAD_LOCAL unsigned long CLHEP::RandFlat::staticRandomInt = 0
staticprivate

Definition at line 197 of file RandFlat.h.


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