Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Functions
G4INCL::Random Namespace Reference

Data Structures

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 ()
 
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 138 of file G4INCLRandom.cc.

References gauss(), and test::x.

Referenced by correlatedUniform().

138  {
139 // assert(corrCoeff<=1. && corrCoeff>=-1.);
140  G4double factor = 1.-corrCoeff*corrCoeff;
141  if(factor<=0.)
142  factor=0.;
143  const G4double x = gauss(sigma) + x0;
144  const G4double y = corrCoeff * x + gauss(sigma*std::sqrt(factor)) + x0;
145  return std::make_pair(x, y);
146  }
double G4double
Definition: G4Types.hh:76
std::pair< G4double, G4double > G4INCL::Random::correlatedUniform ( const G4double  corrCoeff)

Generate pairs of correlated uniform random numbers.

Definition at line 148 of file G4INCLRandom.cc.

References correlatedGaussian(), and G4INCL::Math::gaussianCDF().

148  {
149  std::pair<G4double,G4double> gaussians = correlatedGaussian(corrCoeff);
150  return std::make_pair(Math::gaussianCDF(gaussians.first), Math::gaussianCDF(gaussians.second));
151  }
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.
void G4INCL::Random::deleteGenerator ( )

Delete the generator

Definition at line 153 of file G4INCLRandom.cc.

References theGenerator.

Referenced by G4INCL::INCL::~INCL().

153  {
154  delete theGenerator;
155  theGenerator = 0;
156  }
shared_ptr< HepRandom > theGenerator
Definition: Random.cc:59
G4double G4INCL::Random::gauss ( G4double  sigma = 1.)

Generate random numbers using gaussian distribution.

Definition at line 97 of file G4INCLRandom.cc.

References G4ThreadLocal, shoot(), shoot0(), G4INCL::Math::twoPi, and test::v.

Referenced by correlatedGaussian(), and gaussVector().

97  {
98  // generate a Gaussian random number with standard deviation sigma
99  // uses the flat() and flat0() methods
100  static G4ThreadLocal G4bool generated = false;
101  static G4ThreadLocal G4double u, v;
102 
103  if( !generated )
104  {
105  u = shoot0();
106  v = Math::twoPi*shoot();
107  generated = true;
108  return sigma*std::sqrt(-2*std::log(u))*std::cos(v);
109  }
110  else
111  {
112  generated = false;
113  return sigma*std::sqrt(-2*std::log(u))*std::sin(v);
114  }
115  }
ThreeVector shoot(const G4int Ap, const G4int Af)
#define G4ThreadLocal
Definition: tls.hh:52
G4double shoot0()
Definition: G4INCLRandom.cc:78
bool G4bool
Definition: G4Types.hh:79
const G4double twoPi
double G4double
Definition: G4Types.hh:76
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 133 of file G4INCLRandom.cc.

References gauss(), and G4INCL::Math::oneOverSqrtThree.

Referenced by G4INCL::DeJongSpin::shoot().

133  {
134  const G4double sigmax = sigma * Math::oneOverSqrtThree;
135  return ThreeVector(gauss(sigmax), gauss(sigmax), gauss(sigmax));
136  }
const G4double oneOverSqrtThree
double G4double
Definition: G4Types.hh:76
SeedVector G4INCL::Random::getSeeds ( )

Get the seeds of the current generator.

Definition at line 70 of file G4INCLRandom.cc.

References theGenerator.

Referenced by G4INCL::IAvatar::getFinalState(), and G4INCL::InteractionAvatar::postInteraction().

70  {
71  return theGenerator->getSeeds();
72  }
shared_ptr< HepRandom > theGenerator
Definition: Random.cc:59
G4bool G4INCL::Random::isInitialized ( )

Check if the generator is initialized.

Definition at line 158 of file G4INCLRandom.cc.

References theGenerator.

Referenced by setGenerator().

158  {
159  if(theGenerator == 0) return false;
160  return true;
161  }
shared_ptr< HepRandom > theGenerator
Definition: Random.cc:59
ThreeVector G4INCL::Random::normVector ( G4double  norm = 1.)

Generate isotropically-distributed ThreeVectors of given norm.

Definition at line 117 of file G4INCLRandom.cc.

References shoot(), and G4INCL::Math::twoPi.

Referenced by G4INCL::PhaseSpaceDecay::decay(), G4INCL::RecombinationChannel::getFinalState(), and sphereVector().

117  {
118 
119  const G4double ctheta = (1.-2.*shoot());
120  const G4double stheta = std::sqrt(1.-ctheta*ctheta);
121  const G4double phi = Math::twoPi*shoot();
122  return ThreeVector(
123  norm * stheta * std::cos(phi),
124  norm * stheta * std::sin(phi),
125  norm * ctheta);
126 
127  }
ThreeVector shoot(const G4int Ap, const G4int Af)
const G4double twoPi
double G4double
Definition: G4Types.hh:76
std::ostream& G4INCL::Random::operator<< ( std::ostream &  out,
SeedVector const &  sv 
)

Definition at line 55 of file G4INCLRandomSeedVector.cc.

References G4INCL::Random::SeedVector::at(), and G4INCL::Random::SeedVector::size().

55  {
56  if(sv.size()<=0)
57  return out;
58  for(size_t i=0; i<sv.size()-1; ++i)
59  out << sv.at(i) << '\t';
60  out << sv.at(sv.size()-1);
61  return out;
62  }
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 58 of file G4INCLRandom.cc.

References INCL_ERROR, isInitialized(), and theGenerator.

Referenced by G4INCL::INCL::INCL().

58  {
59  if(isInitialized()) {
60  INCL_ERROR("INCL random number generator already initialized." << std::endl);
61  } else {
62  theGenerator = aGenerator;
63  }
64  }
shared_ptr< HepRandom > theGenerator
Definition: Random.cc:59
#define INCL_ERROR(x)
G4bool isInitialized()
void G4INCL::Random::setSeeds ( const SeedVector &  sv)

Set the seeds of the current generator.

Definition at line 66 of file G4INCLRandom.cc.

References theGenerator.

66  {
67  theGenerator->setSeeds(sv);
68  }
shared_ptr< HepRandom > theGenerator
Definition: Random.cc:59
G4double G4INCL::Random::shoot ( )
G4double G4INCL::Random::shoot0 ( )

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

Definition at line 78 of file G4INCLRandom.cc.

References shoot().

Referenced by gauss(), and sphereVector().

78  {
79  G4double r;
80  while( (r=shoot()) <= 0. )
81  ;
82  return r;
83  }
ThreeVector shoot(const G4int Ap, const G4int Af)
double G4double
Definition: G4Types.hh:76
G4double G4INCL::Random::shoot1 ( )

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

Definition at line 85 of file G4INCLRandom.cc.

References shoot().

Referenced by shootInteger(), and G4INCL::shuffleComponentsHelper().

85  {
86  G4double r;
87  while( (r=shoot()) >= 1. )
88  ;
89  return r;
90  }
ThreeVector shoot(const G4int Ap, const G4int Af)
double G4double
Definition: G4Types.hh:76
template<typename T >
T G4INCL::Random::shootInteger ( n)

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

Definition at line 93 of file G4INCLRandom.cc.

References n, and shoot1().

93  {
94  return static_cast<T>(shoot1() * n);
95  }
G4double shoot1()
Definition: G4INCLRandom.cc:85
const G4int n
ThreeVector G4INCL::Random::sphereVector ( G4double  rmax = 1.)

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

Definition at line 129 of file G4INCLRandom.cc.

References normVector(), G4INCL::Math::pow13(), and shoot0().

129  {
130  return normVector( rmax*Math::pow13(shoot0()) );
131  }
G4double shoot0()
Definition: G4INCLRandom.cc:78
ThreeVector normVector(G4double norm=1.)
G4double pow13(G4double x)