Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4INCL::Random Namespace Reference

Classes

class  Adapter
 
class  SeedVector
 

Functions

void setGenerator (G4INCL::IRandomGenerator *aGenerator)
 
void setSeeds (const SeedVector &sv)
 
SeedVector getSeeds ()
 
G4double shoot ()
 
G4double shoot0 ()
 
G4double shoot1 ()
 
template<typename T >
shootInteger (T n)
 
G4double gauss (G4double sigma=1.)
 
ThreeVector normVector (G4double norm=1.)
 
ThreeVector sphereVector (G4double rmax=1.)
 
ThreeVector gaussVector (G4double sigma=1.)
 Generate Gaussianly-distributed ThreeVectors. More...
 
std::pair< G4double, G4doublecorrelatedGaussian (const G4double corrCoeff, const G4double x0=0., const G4double sigma=1.)
 Generate pairs of correlated Gaussian random numbers. More...
 
std::pair< G4double, G4doublecorrelatedUniform (const G4double corrCoeff)
 Generate pairs of correlated uniform random numbers. More...
 
void deleteGenerator ()
 
G4bool isInitialized ()
 
void saveSeeds ()
 Save the status of the random-number generator. More...
 
SeedVector getSavedSeeds ()
 Get the saved status of the random-number generator. More...
 
void initialize (Config const *const)
 Initialize generator according to a Config object. More...
 
Adapter const & getAdapter ()
 
std::ostream & operator<< (std::ostream &out, SeedVector const &sv)
 

Function Documentation

std::pair< G4double, G4double > G4INCL::Random::correlatedGaussian ( const G4double  corrCoeff,
const G4double  x0 = 0.,
const G4double  sigma = 1. 
)

Generate pairs of correlated Gaussian random numbers.

Definition at line 155 of file G4INCLRandom.cc.

155  {
156 // assert(corrCoeff<=1. && corrCoeff>=-1.);
157  G4double factor = 1.-corrCoeff*corrCoeff;
158  if(factor<=0.)
159  factor=0.;
160  const G4double x = gauss(sigma) + x0;
161  const G4double y = corrCoeff * x + gauss(sigma*std::sqrt(factor)) + x0;
162  return std::make_pair(x, y);
163  }
tuple x
Definition: test.py:50
static constexpr double gauss
Definition: G4SIunits.hh:270
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

std::pair< G4double, G4double > G4INCL::Random::correlatedUniform ( const G4double  corrCoeff)

Generate pairs of correlated uniform random numbers.

Definition at line 165 of file G4INCLRandom.cc.

165  {
166  std::pair<G4double,G4double> gaussians = correlatedGaussian(corrCoeff);
167  return std::make_pair(Math::gaussianCDF(gaussians.first), Math::gaussianCDF(gaussians.second));
168  }
std::pair< G4double, G4double > correlatedGaussian(const G4double corrCoeff, const G4double x0=0., const G4double sigma=1.)
Generate pairs of correlated Gaussian random numbers.
G4double gaussianCDF(const G4double x)
Cumulative distribution function for Gaussian.

Here is the call graph for this function:

void G4INCL::Random::deleteGenerator ( )

Delete the generator

Definition at line 170 of file G4INCLRandom.cc.

170  {
171  delete theGenerator;
172  theGenerator = NULL;
173  delete savedSeeds;
174  savedSeeds = NULL;
175  delete theAdapter;
176  theAdapter = NULL;
177  }
std::shared_ptr< HepRandom > theGenerator
Definition: Random.cc:72

Here is the caller graph for this function:

G4double G4INCL::Random::gauss ( G4double  sigma = 1.)

Generate random numbers using gaussian distribution.

Definition at line 114 of file G4INCLRandom.cc.

114  {
115  // generate a Gaussian random number with standard deviation sigma
116  // uses the flat() and flat0() methods
117  static G4ThreadLocal G4bool generated = false;
118  static G4ThreadLocal G4double u, v;
119 
120  if( !generated )
121  {
122  u = shoot0();
123  v = Math::twoPi*shoot();
124  generated = true;
125  return sigma*std::sqrt(-2*std::log(u))*std::cos(v);
126  }
127  else
128  {
129  generated = false;
130  return sigma*std::sqrt(-2*std::log(u))*std::sin(v);
131  }
132  }
ThreeVector shoot(const G4int Ap, const G4int Af)
#define G4ThreadLocal
Definition: tls.hh:89
G4double shoot0()
bool G4bool
Definition: G4Types.hh:79
tuple v
Definition: test.py:18
const G4double twoPi
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

ThreeVector G4INCL::Random::gaussVector ( G4double  sigma = 1.)

Generate Gaussianly-distributed ThreeVectors.

Generate ThreeVectors that are distributed as a three-dimensional Gaussian of the given sigma.

Definition at line 150 of file G4INCLRandom.cc.

150  {
151  const G4double sigmax = sigma * Math::oneOverSqrtThree;
152  return ThreeVector(gauss(sigmax), gauss(sigmax), gauss(sigmax));
153  }
static constexpr double gauss
Definition: G4SIunits.hh:270
const G4double oneOverSqrtThree
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

Adapter const & G4INCL::Random::getAdapter ( )

Definition at line 227 of file G4INCLRandom.cc.

227  {
228  return *theAdapter;
229  }
SeedVector G4INCL::Random::getSavedSeeds ( )

Get the saved status of the random-number generator.

Definition at line 198 of file G4INCLRandom.cc.

198  {
199  if(!savedSeeds)
200  savedSeeds = new SeedVector;
201 
202  return *savedSeeds;
203  }
SeedVector G4INCL::Random::getSeeds ( )

Get the seeds of the current generator.

Definition at line 89 of file G4INCLRandom.cc.

89  {
90  return theGenerator->getSeeds();
91  }
std::shared_ptr< HepRandom > theGenerator
Definition: Random.cc:72

Here is the caller graph for this function:

void G4INCL::Random::initialize ( Config const * const  )

Initialize generator according to a Config object.

Definition at line 205 of file G4INCLRandom.cc.

209  {
210 #ifdef INCLXX_IN_GEANT4_MODE
211  Random::setGenerator(new Geant4RandomGenerator());
212 #else // INCLXX_IN_GEANT4_MODE
213  RNGType rng = theConfig->getRNGType();
214  if(rng == RanecuType)
215  setGenerator(new Ranecu(theConfig->getRandomSeeds()));
216  else if(rng == Ranecu3Type)
217  setGenerator(new Ranecu3(theConfig->getRandomSeeds()));
218  else
219  setGenerator(NULL);
220 #endif // INCLXX_IN_GEANT4_MODE
221  }
void setGenerator(G4INCL::IRandomGenerator *aGenerator)
Definition: G4INCLRandom.cc:72

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4INCL::Random::isInitialized ( )

Check if the generator is initialized.

Definition at line 179 of file G4INCLRandom.cc.

179  {
180  if(theGenerator == 0) return false;
181  return true;
182  }
std::shared_ptr< HepRandom > theGenerator
Definition: Random.cc:72

Here is the caller graph for this function:

ThreeVector G4INCL::Random::normVector ( G4double  norm = 1.)

Generate isotropically-distributed ThreeVectors of given norm.

Definition at line 134 of file G4INCLRandom.cc.

134  {
135 
136  const G4double ctheta = (1.-2.*shoot());
137  const G4double stheta = std::sqrt(1.-ctheta*ctheta);
138  const G4double phi = Math::twoPi*shoot();
139  return ThreeVector(
140  norm * stheta * std::cos(phi),
141  norm * stheta * std::sin(phi),
142  norm * ctheta);
143 
144  }
ThreeVector shoot(const G4int Ap, const G4int Af)
const G4double twoPi
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

std::ostream& G4INCL::Random::operator<< ( std::ostream &  out,
SeedVector const &  sv 
)

Definition at line 50 of file G4INCLRandomSeedVector.cc.

50  {
51  if(sv.size()<=0)
52  return out;
53  for(size_t i=0; i<sv.size()-1; ++i)
54  out << sv.at(i) << '\t';
55  out << sv.at(sv.size()-1);
56  return out;
57  }
void G4INCL::Random::saveSeeds ( )

Save the status of the random-number generator.

Definition at line 191 of file G4INCLRandom.cc.

191  {
192  if(!savedSeeds)
193  savedSeeds = new SeedVector;
194 
195  (*savedSeeds) = theGenerator->getSeeds();
196  }
std::shared_ptr< HepRandom > theGenerator
Definition: Random.cc:72
void G4INCL::Random::setGenerator ( G4INCL::IRandomGenerator aGenerator)

Set the random number generator implementation to be used globally by INCL.

See Also
G4INCL::IRandomGenerator

Definition at line 72 of file G4INCLRandom.cc.

72  {
73  if(isInitialized()) {
74  INCL_ERROR("INCL random number generator already initialized." << '\n');
75  } else {
76 #ifdef INCL_COUNT_RND_CALLS
77  nCalls = 0;
78 #endif
79  theGenerator = aGenerator;
80  }
81  if(!theAdapter)
82  theAdapter = new Adapter();
83  }
std::shared_ptr< HepRandom > theGenerator
Definition: Random.cc:72
#define INCL_ERROR(x)
G4bool isInitialized()

Here is the call graph for this function:

Here is the caller graph for this function:

void G4INCL::Random::setSeeds ( const SeedVector &  sv)

Set the seeds of the current generator.

Definition at line 85 of file G4INCLRandom.cc.

85  {
86  theGenerator->setSeeds(sv);
87  }
std::shared_ptr< HepRandom > theGenerator
Definition: Random.cc:72
G4double G4INCL::Random::shoot ( )

Generate flat distribution of random numbers.

Definition at line 93 of file G4INCLRandom.cc.

93  {
94 #ifdef INCL_COUNT_RND_CALLS
95  nCalls++;
96 #endif
97  return theGenerator->flat();
98  }
std::shared_ptr< HepRandom > theGenerator
Definition: Random.cc:72

Here is the caller graph for this function:

G4double G4INCL::Random::shoot0 ( )

Return a random number in the ]0,1] interval

Definition at line 100 of file G4INCLRandom.cc.

100  {
101  G4double r;
102  while( (r=shoot()) <= 0. ) /* Loop checking, 10.07.2015, D.Mancusi */
103  ;
104  return r;
105  }
ThreeVector shoot(const G4int Ap, const G4int Af)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

G4double G4INCL::Random::shoot1 ( )

Return a random number in the [0,1[ interval

Definition at line 107 of file G4INCLRandom.cc.

107  {
108  G4double r;
109  while( (r=shoot()) >= 1. ) /* Loop checking, 10.07.2015, D.Mancusi */
110  ;
111  return r;
112  }
ThreeVector shoot(const G4int Ap, const G4int Af)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
T G4INCL::Random::shootInteger ( n)

Return a random integer in the [0,n[ interval

Definition at line 96 of file G4INCLRandom.hh.

96  {
97  return static_cast<T>(shoot1() * n);
98  }
G4double shoot1()
const G4int n

Here is the call graph for this function:

Here is the caller graph for this function:

ThreeVector G4INCL::Random::sphereVector ( G4double  rmax = 1.)

Generate ThreeVectors that are uniformly distributed in a sphere of radius rmax.

Definition at line 146 of file G4INCLRandom.cc.

146  {
147  return normVector( rmax*Math::pow13(shoot0()) );
148  }
G4double shoot0()
ThreeVector normVector(G4double norm=1.)
G4double pow13(G4double x)

Here is the call graph for this function: