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

#include <RandChiSquare.h>

Inheritance diagram for CLHEP::RandChiSquare:
CLHEP::HepRandom

Public Member Functions

HepRandomEngineengine ()
 
double fire ()
 
double fire (double a)
 
void fireArray (const int size, double *vect)
 
void fireArray (const int size, double *vect, double a)
 
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)
 
std::ostream & put (std::ostream &os) const
 
 RandChiSquare (HepRandomEngine &anEngine, double a=1)
 
 RandChiSquare (HepRandomEngine *anEngine, double a=1)
 
virtual ~RandChiSquare ()
 

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)
 
static double shoot (HepRandomEngine *anEngine)
 
static double shoot (HepRandomEngine *anEngine, double a)
 
static void shootArray (const int size, double *vect, double a=1.0)
 
static void shootArray (HepRandomEngine *anEngine, const int size, double *vect, double a=1.0)
 
static void showEngineStatus ()
 

Static Protected Attributes

static const long seedTable [215][2]
 

Static Private Member Functions

static double genChiSquare (HepRandomEngine *anEngine, double a)
 

Private Attributes

double defaultA
 
std::shared_ptr< HepRandomEnginelocalEngine
 

Detailed Description

Author

Definition at line 36 of file RandChiSquare.h.

Constructor & Destructor Documentation

◆ RandChiSquare() [1/2]

CLHEP::RandChiSquare::RandChiSquare ( HepRandomEngine anEngine,
double  a = 1 
)
inline

◆ RandChiSquare() [2/2]

CLHEP::RandChiSquare::RandChiSquare ( HepRandomEngine anEngine,
double  a = 1 
)
inline

◆ ~RandChiSquare()

CLHEP::RandChiSquare::~RandChiSquare ( )
virtual

Definition at line 30 of file RandChiSquare.cc.

30 {
31}

Member Function Documentation

◆ createInstance()

int CLHEP::HepRandom::createInstance ( )
staticinherited

◆ distributionName()

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

Definition at line 95 of file RandChiSquare.h.

95{return "RandChiSquare";}

◆ engine()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 28 of file RandChiSquare.cc.

28{return *localEngine;}
std::shared_ptr< HepRandomEngine > localEngine

References localEngine.

◆ fire() [1/2]

double CLHEP::RandChiSquare::fire ( )
inline

Referenced by fireArray().

◆ fire() [2/2]

double CLHEP::RandChiSquare::fire ( double  a)

Definition at line 42 of file RandChiSquare.cc.

42 {
43 return genChiSquare( localEngine.get(), a );
44}
static double genChiSquare(HepRandomEngine *anEngine, double a)

References genChiSquare(), and localEngine.

◆ fireArray() [1/2]

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

Definition at line 60 of file RandChiSquare.cc.

60 {
61 for( double* v = vect; v != vect+size; ++v )
62 *v = fire(defaultA);
63}

References defaultA, and fire().

◆ fireArray() [2/2]

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

Definition at line 65 of file RandChiSquare.cc.

66 {
67 for( double* v = vect; v != vect+size; ++v )
68 *v = fire(a);
69}

References fire().

◆ 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

◆ genChiSquare()

double CLHEP::RandChiSquare::genChiSquare ( HepRandomEngine anEngine,
double  a 
)
staticprivate

Definition at line 71 of file RandChiSquare.cc.

72 {
73/******************************************************************
74 * *
75 * Chi Distribution - Ratio of Uniforms with shift *
76 * *
77 ******************************************************************
78 * *
79 * FUNCTION : - chru samples a random number from the Chi *
80 * distribution with parameter a > 1. *
81 * REFERENCE : - J.F. Monahan (1987): An algorithm for *
82 * generating chi random variables, ACM Trans. *
83 * Math. Software 13, 168-172. *
84 * SUBPROGRAM : - anEngine ... pointer to a (0,1)-Uniform *
85 * engine *
86 * *
87 * Implemented by R. Kremer, 1990 *
88 ******************************************************************/
89
90 static CLHEP_THREAD_LOCAL double a_in = -1.0,b,vm,vp,vd;
91 double u,v,z,zz,r;
92
93// Check for invalid input value
94
95 if( a < 1 ) return (-1.0);
96
97 if (a == 1)
98 {
99 for(;;)
100 {
101 u = anEngine->flat();
102 v = anEngine->flat() * 0.857763884960707;
103 z = v / u;
104 if (z < 0) continue;
105 zz = z * z;
106 r = 2.5 - zz;
107 if (z < 0.0) r = r + zz * z / (3.0 * z);
108 if (u < r * 0.3894003915) return(z*z);
109 if (zz > (1.036961043 / u + 1.4)) continue;
110 if (2 * std::log(u) < (- zz * 0.5 )) return(z*z);
111 }
112 }
113 else
114 {
115 if (a != a_in)
116 {
117 b = std::sqrt(a - 1.0);
118 vm = - 0.6065306597 * (1.0 - 0.25 / (b * b + 1.0));
119 vm = (-b > vm)? -b : vm;
120 vp = 0.6065306597 * (0.7071067812 + b) / (0.5 + b);
121 vd = vp - vm;
122 a_in = a;
123 }
124 for(;;)
125 {
126 u = anEngine->flat();
127 v = anEngine->flat() * vd + vm;
128 z = v / u;
129 if (z < -b) continue;
130 zz = z * z;
131 r = 2.5 - zz;
132 if (z < 0.0) r = r + zz * z / (3.0 * (z + b));
133 if (u < r * 0.3894003915) return((z + b)*(z + b));
134 if (zz > (1.036961043 / u + 1.4)) continue;
135 if (2 * std::log(u) < (std::log(1.0 + z / b) * b * b - zz * 0.5 - z * b)) return((z + b)*(z + b));
136 }
137 }
138}
#define CLHEP_THREAD_LOCAL
Definition: thread_local.h:13

References CLHEP_THREAD_LOCAL, and CLHEP::HepRandomEngine::flat().

Referenced by fire(), and shoot().

◆ get()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 151 of file RandChiSquare.cc.

151 {
152 std::string inName;
153 is >> inName;
154 if (inName != name()) {
155 is.clear(std::ios::badbit | is.rdstate());
156 std::cerr << "Mismatch when expecting to read state of a "
157 << name() << " distribution\n"
158 << "Name found was " << inName
159 << "\nistream is left in the badbit state\n";
160 return is;
161 }
162 if (possibleKeywordInput(is, "Uvec", defaultA)) {
163 std::vector<unsigned long> t(2);
164 is >> defaultA >> t[0] >> t[1]; defaultA = DoubConv::longs2double(t);
165 return is;
166 }
167 // is >> defaultA encompassed by possibleKeywordInput
168 return is;
169}
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:110
std::string name() const
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:166

References defaultA, CLHEP::DoubConv::longs2double(), name(), and CLHEP::possibleKeywordInput().

◆ 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::RandChiSquare::name ( ) const
virtual

Reimplemented from CLHEP::HepRandom.

Definition at line 27 of file RandChiSquare.cc.

27{return "RandChiSquare";}

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

◆ operator()() [1/2]

double CLHEP::RandChiSquare::operator() ( )
inlinevirtual

Reimplemented from CLHEP::HepRandom.

◆ operator()() [2/2]

double CLHEP::RandChiSquare::operator() ( double  a)
inline

◆ put()

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

Reimplemented from CLHEP::HepRandom.

Definition at line 140 of file RandChiSquare.cc.

140 {
141 int pr=os.precision(20);
142 std::vector<unsigned long> t(2);
143 os << " " << name() << "\n";
144 os << "Uvec" << "\n";
146 os << defaultA << " " << t[0] << " " << t[1] << "\n";
147 os.precision(pr);
148 return os;
149}
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:94

References defaultA, CLHEP::DoubConv::dto2longs(), and name().

◆ restoreDistState()

static std::istream & CLHEP::HepRandom::restoreDistState ( std::istream &  is)
inlinestaticinherited

Definition at line 136 of file Random.h.

136{return is;}

◆ restoreEngineStatus()

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

Definition at line 283 of file Random.cc.

284{
285 theDefaults().theEngine->restoreStatus( filename );
286}

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

◆ restoreFullState()

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

Definition at line 293 of file Random.cc.

293 {
294 is >> *getTheEngine();
295 return is;
296}
static HepRandomEngine * getTheEngine()
Definition: Random.cc:268

Referenced by CLHEP::RandFlat::restoreFullState(), and CLHEP::RandGauss::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::HepRandom::saveDistState ( std::ostream &  os)
inlinestaticinherited

Definition at line 133 of file Random.h.

133{return os;}

◆ saveEngineStatus()

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

◆ saveFullState()

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

◆ 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/4]

static double CLHEP::RandChiSquare::shoot ( )
inlinestatic

Referenced by shootArray().

◆ shoot() [2/4]

double CLHEP::RandChiSquare::shoot ( double  a)
static

Definition at line 37 of file RandChiSquare.cc.

37 {
38 HepRandomEngine *anEngine = HepRandom::getTheEngine();
39 return genChiSquare( anEngine, a );
40}

References genChiSquare(), and CLHEP::HepRandom::getTheEngine().

◆ shoot() [3/4]

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

◆ shoot() [4/4]

double CLHEP::RandChiSquare::shoot ( HepRandomEngine anEngine,
double  a 
)
static

Definition at line 33 of file RandChiSquare.cc.

33 {
34 return genChiSquare( anEngine, a );
35}

References genChiSquare().

◆ shootArray() [1/2]

void CLHEP::RandChiSquare::shootArray ( const int  size,
double *  vect,
double  a = 1.0 
)
static

Definition at line 46 of file RandChiSquare.cc.

47 {
48 for( double* v = vect; v != vect+size; ++v )
49 *v = shoot(a);
50}
static double shoot()

References shoot().

◆ shootArray() [2/2]

void CLHEP::RandChiSquare::shootArray ( HepRandomEngine anEngine,
const int  size,
double *  vect,
double  a = 1.0 
)
static

Definition at line 52 of file RandChiSquare.cc.

55{
56 for( double* v = vect; v != vect+size; ++v )
57 *v = shoot(anEngine,a);
58}

References shoot().

◆ showEngineStatus()

void CLHEP::HepRandom::showEngineStatus ( )
staticinherited

Field Documentation

◆ defaultA

double CLHEP::RandChiSquare::defaultA
private

Definition at line 103 of file RandChiSquare.h.

Referenced by fireArray(), get(), and put().

◆ localEngine

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

Definition at line 102 of file RandChiSquare.h.

Referenced by engine(), and fire().

◆ seedTable

const long CLHEP::HepRandom::seedTable
staticprotectedinherited

Definition at line 156 of file Random.h.


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