Geant4-11
Public Member Functions | Static Public Member Functions | Static Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
CLHEP::RandBit Class Reference

#include <RandBit.h>

Inheritance diagram for CLHEP::RandBit:
CLHEP::RandFlat CLHEP::HepRandom

Public Member Functions

HepRandomEngineengine ()
 
double fire ()
 
double fire (double a, double b)
 
double fire (double width)
 
void fireArray (const int size, double *vect)
 
void fireArray (const int size, double *vect, double lx, double dx)
 
int fireBit ()
 
long fireInt (long a1, long n)
 
long fireInt (long n)
 
double flat ()
 
double flat (HepRandomEngine *theNewEngine)
 
void flatArray (const int size, double *vect)
 
void flatArray (HepRandomEngine *theNewEngine, const int size, double *vect)
 
std::istream & get (std::istream &is)
 
std::string name () const
 
double operator() ()
 
double operator() (double a, double b)
 
double operator() (double width)
 
std::ostream & put (std::ostream &os) const
 
 RandBit (HepRandomEngine &anEngine)
 
 RandBit (HepRandomEngine &anEngine, double a, double b)
 
 RandBit (HepRandomEngine &anEngine, double width)
 
 RandBit (HepRandomEngine *anEngine)
 
 RandBit (HepRandomEngine *anEngine, double a, double b)
 
 RandBit (HepRandomEngine *anEngine, double width)
 
virtual ~RandBit ()
 

Static Public Member Functions

static int createInstance ()
 
static std::string distributionName ()
 
static HepRandomEnginegetTheEngine ()
 
static HepRandomgetTheGenerator ()
 
static long getTheSeed ()
 
static const long * getTheSeeds ()
 
static void getTheTableSeeds (long *seeds, int index)
 
static std::istream & restoreDistState (std::istream &is)
 
static void restoreEngineStatus (const char filename[]="Config.conf")
 
static std::istream & restoreFullState (std::istream &is)
 
static std::istream & restoreStaticRandomStates (std::istream &is)
 
static std::ostream & saveDistState (std::ostream &os)
 
static void saveEngineStatus (const char filename[]="Config.conf")
 
static std::ostream & saveFullState (std::ostream &os)
 
static std::ostream & saveStaticRandomStates (std::ostream &os)
 
static void setTheEngine (HepRandomEngine *theNewEngine)
 
static void setTheSeed (long seed, int lxr=3)
 
static void setTheSeeds (const long *seeds, int aux=-1)
 
static double shoot ()
 
static double shoot (double a, double b)
 
static double shoot (double width)
 
static double shoot (HepRandomEngine *anEngine)
 
static double shoot (HepRandomEngine *anEngine, double a, double b)
 
static double shoot (HepRandomEngine *anEngine, double width)
 
static void shootArray (const int size, double *vect)
 
static void shootArray (const int size, double *vect, double lx, double dx)
 
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 int shootBit ()
 
static int shootBit (HepRandomEngine *)
 
static long shootInt (HepRandomEngine *anEngine, long a1, long n)
 
static long shootInt (HepRandomEngine *anEngine, long n)
 
static long shootInt (long a1, long n)
 
static long shootInt (long n)
 
static void showEngineStatus ()
 

Static Protected Attributes

static const long seedTable [215][2]
 

Private Member Functions

void fireBits ()
 

Static Private Member Functions

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

Private Attributes

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

Static Private Attributes

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

Detailed Description

Author

Definition at line 38 of file RandBit.h.

Constructor & Destructor Documentation

◆ RandBit() [1/6]

CLHEP::RandBit::RandBit ( HepRandomEngine anEngine)
inline

◆ RandBit() [2/6]

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

◆ RandBit() [3/6]

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

◆ RandBit() [4/6]

CLHEP::RandBit::RandBit ( HepRandomEngine anEngine)
inline

◆ RandBit() [5/6]

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

◆ RandBit() [6/6]

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

◆ ~RandBit()

CLHEP::RandBit::~RandBit ( )
virtual

Definition at line 24 of file RandBit.cc.

24 {
25}

Member Function Documentation

◆ createInstance()

int CLHEP::HepRandom::createInstance ( )
staticinherited

◆ distributionName()

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

Definition at line 79 of file RandBit.h.

79{return "RandBit";}

◆ engine()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 44 of file RandFlat.cc.

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

References CLHEP::RandFlat::localEngine.

◆ fire() [1/3]

double CLHEP::RandFlat::fire ( )
inlineinherited

◆ fire() [2/3]

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

◆ fire() [3/3]

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

◆ fireArray() [1/2]

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

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}
double defaultB
Definition: RandFlat.h:202
double defaultA
Definition: RandFlat.h:201

References CLHEP::RandFlat::defaultA, CLHEP::RandFlat::defaultB, and CLHEP::RandFlat::fire().

◆ fireArray() [2/2]

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

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}

References CLHEP::RandFlat::fire().

◆ fireBit()

int CLHEP::RandBit::fireBit ( )
inline

◆ fireBits()

void CLHEP::RandFlat::fireBits ( )
inlineprivateinherited

◆ fireInt() [1/2]

long CLHEP::RandFlat::fireInt ( long  a1,
long  n 
)
inlineinherited

◆ fireInt() [2/2]

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

◆ flat() [1/2]

double CLHEP::HepRandom::flat ( )
inherited

◆ flat() [2/2]

double CLHEP::HepRandom::flat ( HepRandomEngine theNewEngine)
inlineinherited

◆ flatArray() [1/2]

void CLHEP::HepRandom::flatArray ( const int  size,
double *  vect 
)
inherited

◆ flatArray() [2/2]

void CLHEP::HepRandom::flatArray ( HepRandomEngine theNewEngine,
const int  size,
double *  vect 
)
inlineinherited

◆ get()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 33 of file RandBit.cc.

33 {
34 std::string inName;
35 is >> inName;
36 if (inName != name()) {
37 is.clear(std::ios::badbit | is.rdstate());
38 std::cerr << "Mismatch when expecting to read state of a "
39 << name() << " distribution\n"
40 << "Name found was " << inName
41 << "\nistream is left in the badbit state\n";
42 return is;
43 }
44 RandFlat::get(is);
45 return is;
46}
std::string name() const
Definition: RandBit.cc:22
std::istream & get(std::istream &is)
Definition: RandFlat.cc:173

References CLHEP::RandFlat::get(), and name().

◆ getTheEngine()

HepRandomEngine * CLHEP::HepRandom::getTheEngine ( )
staticinherited

◆ getTheGenerator()

HepRandom * CLHEP::HepRandom::getTheGenerator ( )
staticinherited

◆ getTheSeed()

long CLHEP::HepRandom::getTheSeed ( )
staticinherited

◆ getTheSeeds()

const long * CLHEP::HepRandom::getTheSeeds ( )
staticinherited

◆ getTheTableSeeds()

void CLHEP::HepRandom::getTheTableSeeds ( long *  seeds,
int  index 
)
staticinherited

Definition at line 254 of file Random.cc.

255{
256 if ((index >= 0) && (index < 215)) {
257 seeds[0] = seedTable[index][0];
258 seeds[1] = seedTable[index][1];
259 }
260 else seeds = NULL;
261}
static const long seedTable[215][2]
Definition: Random.h:156

Referenced by CLHEP::HepJamesRandom::HepJamesRandom(), CLHEP::MTwistEngine::MTwistEngine(), CLHEP::RanecuEngine::RanecuEngine(), CLHEP::Ranlux64Engine::Ranlux64Engine(), CLHEP::RanluxEngine::RanluxEngine(), and CLHEP::RanecuEngine::setSeed().

◆ name()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 22 of file RandBit.cc.

22{return "RandBit";}

Referenced by source.g4viscp.G4Scene::create_scene(), get(), mcscore.MCParticle::printout(), put(), and source.g4viscp.G4Scene::update_scene().

◆ operator()() [1/3]

double CLHEP::RandFlat::operator() ( )
virtualinherited

Reimplemented from CLHEP::HepRandom.

Definition at line 49 of file RandFlat.cc.

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

References CLHEP::RandFlat::defaultA, CLHEP::RandFlat::defaultB, and CLHEP::RandFlat::fire().

◆ operator()() [2/3]

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

Definition at line 57 of file RandFlat.cc.

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

References CLHEP::RandFlat::fire().

◆ operator()() [3/3]

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

Definition at line 53 of file RandFlat.cc.

53 {
54 return fire( w );
55}

References CLHEP::RandFlat::fire().

◆ put()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 27 of file RandBit.cc.

27 {
28 os << " " << name() << "\n";
29 RandFlat::put(os);
30 return os;
31}
std::ostream & put(std::ostream &os) const
Definition: RandFlat.cc:157

References name(), and CLHEP::RandFlat::put().

◆ restoreDistState()

static std::istream & CLHEP::RandBit::restoreDistState ( std::istream &  is)
inlinestatic

Definition at line 94 of file RandBit.h.

96 {return RandFlat::restoreDistState(is);}
static std::istream & restoreDistState(std::istream &is)
Definition: RandFlat.cc:213

References CLHEP::RandFlat::restoreDistState().

◆ restoreEngineStatus()

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

Definition at line 120 of file RandFlat.cc.

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

References CLHEP::HepRandom::getTheEngine(), CLHEP::HepRandomEngine::restoreStatus(), CLHEP::RandFlat::staticFirstUnusedBit, and CLHEP::RandFlat::staticRandomInt.

◆ restoreFullState()

static std::istream & CLHEP::RandBit::restoreFullState ( std::istream &  is)
inlinestatic

Definition at line 86 of file RandBit.h.

88 {return RandFlat::restoreFullState(is);}
static std::istream & restoreFullState(std::istream &is)
Definition: RandFlat.cc:244

References CLHEP::RandFlat::restoreFullState().

◆ restoreStaticRandomStates()

std::istream & CLHEP::HepRandom::restoreStaticRandomStates ( std::istream &  is)
staticinherited

Definition at line 302 of file Random.cc.

302 {
304}
static std::istream & restore(std::istream &is)

References CLHEP::StaticRandomStates::restore().

◆ saveDistState()

static std::ostream & CLHEP::RandBit::saveDistState ( std::ostream &  os)
inlinestatic

Definition at line 90 of file RandBit.h.

92 {return RandFlat::saveDistState(os);}
static std::ostream & saveDistState(std::ostream &os)
Definition: RandFlat.cc:204

References CLHEP::RandFlat::saveDistState().

◆ saveEngineStatus()

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

Definition at line 105 of file RandFlat.cc.

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

References demo::app, CLHEP::HepRandom::getTheEngine(), CLHEP::HepRandomEngine::saveStatus(), CLHEP::RandFlat::staticFirstUnusedBit, and CLHEP::RandFlat::staticRandomInt.

◆ saveFullState()

static std::ostream & CLHEP::RandBit::saveFullState ( std::ostream &  os)
inlinestatic

Definition at line 82 of file RandBit.h.

84 {return RandFlat::saveFullState(os);}
static std::ostream & saveFullState(std::ostream &os)
Definition: RandFlat.cc:238

References CLHEP::RandFlat::saveFullState().

◆ saveStaticRandomStates()

std::ostream & CLHEP::HepRandom::saveStaticRandomStates ( std::ostream &  os)
staticinherited

Definition at line 298 of file Random.cc.

298 {
299 return StaticRandomStates::save(os);
300}
static std::ostream & save(std::ostream &os)

References CLHEP::StaticRandomStates::save().

◆ setTheEngine()

void CLHEP::HepRandom::setTheEngine ( HepRandomEngine theNewEngine)
staticinherited

Definition at line 273 of file Random.cc.

274{
275 theDefaults().theEngine.reset( theNewEngine, do_nothing_deleter() );
276}

References CLHEP::anonymous_namespace{Random.cc}::theDefaults(), and CLHEP::anonymous_namespace{Random.cc}::defaults::theEngine.

Referenced by CLHEP::StaticRandomStates::restore().

◆ setTheSeed()

void CLHEP::HepRandom::setTheSeed ( long  seed,
int  lxr = 3 
)
staticinherited

Definition at line 234 of file Random.cc.

235{
236 theDefaults().theEngine->setSeed(seed,lux);
237}
static constexpr double lux

References CLHEP::lux, CLHEP::anonymous_namespace{Random.cc}::theDefaults(), and CLHEP::anonymous_namespace{Random.cc}::defaults::theEngine.

◆ setTheSeeds()

void CLHEP::HepRandom::setTheSeeds ( const long *  seeds,
int  aux = -1 
)
staticinherited

◆ shoot() [1/6]

double CLHEP::RandFlat::shoot ( )
staticinherited

◆ shoot() [2/6]

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

◆ shoot() [3/6]

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

◆ shoot() [4/6]

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

◆ shoot() [5/6]

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

◆ shoot() [6/6]

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

◆ shootArray() [1/4]

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

Definition at line 65 of file RandFlat.cc.

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

References CLHEP::HepRandomEngine::flatArray(), and CLHEP::HepRandom::getTheEngine().

◆ shootArray() [2/4]

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

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

References CLHEP::RandFlat::shoot().

◆ shootArray() [3/4]

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

◆ shootArray() [4/4]

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

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}

References CLHEP::RandFlat::shoot().

◆ shootBit() [1/2]

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

◆ shootBit() [2/2]

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

◆ shootBits() [1/2]

static void CLHEP::RandFlat::shootBits ( )
inlinestaticprivateinherited

◆ shootBits() [2/2]

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

◆ shootInt() [1/4]

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

◆ shootInt() [2/4]

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

◆ shootInt() [3/4]

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

◆ shootInt() [4/4]

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

◆ showEngineStatus()

void CLHEP::HepRandom::showEngineStatus ( )
staticinherited

Field Documentation

◆ defaultA

double CLHEP::RandFlat::defaultA
privateinherited

◆ defaultB

double CLHEP::RandFlat::defaultB
privateinherited

◆ defaultWidth

double CLHEP::RandFlat::defaultWidth
privateinherited

Definition at line 200 of file RandFlat.h.

Referenced by CLHEP::RandFlat::get(), and CLHEP::RandFlat::put().

◆ firstUnusedBit

unsigned long CLHEP::RandFlat::firstUnusedBit
privateinherited

Definition at line 195 of file RandFlat.h.

Referenced by CLHEP::RandFlat::get(), and CLHEP::RandFlat::put().

◆ localEngine

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

Definition at line 199 of file RandFlat.h.

Referenced by CLHEP::RandFlat::engine().

◆ MSB

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

Definition at line 190 of file RandFlat.h.

◆ MSBBits

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

Definition at line 191 of file RandFlat.h.

◆ randomInt

unsigned long CLHEP::RandFlat::randomInt
privateinherited

Definition at line 194 of file RandFlat.h.

Referenced by CLHEP::RandFlat::get(), and CLHEP::RandFlat::put().

◆ seedTable

const long CLHEP::HepRandom::seedTable
staticprotectedinherited

Definition at line 156 of file Random.h.

◆ staticFirstUnusedBit

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

◆ staticRandomInt

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

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