Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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.)
 
G4double gaussWithMemory (G4double sigma=1.)
 
ThreeVector normVector (G4double norm=1.)
 
ThreeVector sphereVector (G4double rmax=1.)
 
ThreeVector gaussVector (G4double sigma=1.)
 Generate Gaussianly-distributed ThreeVectors.
 
std::pair< G4double, G4doublecorrelatedGaussian (const G4double corrCoeff, const G4double x0=0., const G4double sigma=1.)
 Generate pairs of correlated Gaussian random numbers.
 
std::pair< G4double, G4doublecorrelatedUniform (const G4double corrCoeff)
 Generate pairs of correlated uniform random numbers.
 
void deleteGenerator ()
 
G4bool isInitialized ()
 
void saveSeeds ()
 Save the status of the random-number generator.
 
SeedVector getSavedSeeds ()
 Get the saved status of the random-number generator.
 
void initialize (Config const *const)
 Initialize generator according to a Config object.
 
Adapter const & getAdapter ()
 
std::ostream & operator<< (std::ostream &out, SeedVector const &sv)
 

Function Documentation

◆ correlatedGaussian()

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 183 of file G4INCLRandom.cc.

183 {
184// assert(corrCoeff<=1. && corrCoeff>=-1.);
185 G4double factor = 1.-corrCoeff*corrCoeff;
186 if(factor<=0.)
187 factor=0.;
188#ifndef INCLXX_IN_GEANT4_MODE
189 const G4double x = gauss(sigma) + x0;
190 const G4double y = corrCoeff * x + gauss(sigma*std::sqrt(factor)) + x0;
191#else
192 const G4double x = gaussWithMemory(sigma) + x0;
193 const G4double y = corrCoeff * x + gaussWithMemory(sigma*std::sqrt(factor)) + x0;
194
195#endif
196 return std::make_pair(x, y);
197 }
double G4double
Definition: G4Types.hh:83
G4double gaussWithMemory(G4double sigma=1.)
G4double gauss(G4double sigma=1.)

Referenced by correlatedUniform().

◆ correlatedUniform()

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

Generate pairs of correlated uniform random numbers.

Definition at line 199 of file G4INCLRandom.cc.

199 {
200 std::pair<G4double,G4double> gaussians = correlatedGaussian(corrCoeff);
201 return std::make_pair(Math::gaussianCDF(gaussians.first), Math::gaussianCDF(gaussians.second));
202 }
std::pair< G4double, G4double > correlatedGaussian(const G4double corrCoeff, const G4double x0=0., const G4double sigma=1.)
Generate pairs of correlated Gaussian random numbers.

◆ deleteGenerator()

void G4INCL::Random::deleteGenerator ( )

Delete the generator

Definition at line 204 of file G4INCLRandom.cc.

204 {
205 delete theGenerator;
206 theGenerator = NULL;
207 delete savedSeeds;
208 savedSeeds = NULL;
209 delete theAdapter;
210 theAdapter = NULL;
211 }
std::shared_ptr< HepRandom > theGenerator
Definition: Random.cc:75

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

◆ gauss()

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

Generate random numbers using gaussian distribution.

Definition at line 137 of file G4INCLRandom.cc.

137 {
138 return G4RandGauss::shoot(0.,sigma);
139 }

Referenced by correlatedGaussian(), G4INCL::NNToMissingStrangenessChannel::fillFinalState(), G4INCL::NpiToMissingStrangenessChannel::fillFinalState(), gauss(), and gaussVector().

◆ gaussVector()

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 178 of file G4INCLRandom.cc.

178 {
179 const G4double sigmax = sigma * Math::oneOverSqrtThree;
180 return ThreeVector(gauss(sigmax), gauss(sigmax), gauss(sigmax));
181 }

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

◆ gaussWithMemory()

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

Generate random numbers using gaussian distribution to be used only for correlated pairs

Definition at line 141 of file G4INCLRandom.cc.

141 {
142 // generate a Gaussian random number with standard deviation sigma
143 // uses the flat() and flat0() methods
144 static G4ThreadLocal G4bool generated = false;
145 static G4ThreadLocal G4double u, v;
146
147 if( !generated )
148 {
149 u = shoot0();
150 v = Math::twoPi*shoot();
151 generated = true;
152 return sigma*std::sqrt(-2*std::log(u))*std::cos(v);
153 }
154 else
155 {
156 generated = false;
157 return sigma*std::sqrt(-2*std::log(u))*std::sin(v);
158 }
159 }
bool G4bool
Definition: G4Types.hh:86
G4double shoot0()
#define G4ThreadLocal
Definition: tls.hh:77

Referenced by correlatedGaussian().

◆ getAdapter()

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

Definition at line 257 of file G4INCLRandom.cc.

257 {
258 return *theAdapter;
259 }

◆ getSavedSeeds()

SeedVector G4INCL::Random::getSavedSeeds ( )

Get the saved status of the random-number generator.

Definition at line 232 of file G4INCLRandom.cc.

232 {
233 if(!savedSeeds)
234 savedSeeds = new SeedVector;
235
236 return *savedSeeds;
237 }

◆ getSeeds()

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 }

Referenced by G4INCL::IAvatar::fillFinalState(), G4INCL::INCL::finalizeGlobalInfo(), and G4INCL::InteractionAvatar::postInteraction().

◆ initialize()

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

Initialize generator according to a Config object.

Definition at line 239 of file G4INCLRandom.cc.

243 {
244#ifdef INCLXX_IN_GEANT4_MODE
245 Random::setGenerator(new Geant4RandomGenerator());
246#else // INCLXX_IN_GEANT4_MODE
247 RNGType rng = theConfig->getRNGType();
248 if(rng == RanecuType)
249 setGenerator(new Ranecu(theConfig->getRandomSeeds()));
250 else if(rng == Ranecu3Type)
251 setGenerator(new Ranecu3(theConfig->getRandomSeeds()));
252 else
253 setGenerator(NULL);
254#endif // INCLXX_IN_GEANT4_MODE
255 }
Extended Ranecu-type RNG class.
void setGenerator(G4INCL::IRandomGenerator *aGenerator)
Definition: G4INCLRandom.cc:72

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

◆ isInitialized()

G4bool G4INCL::Random::isInitialized ( )

Check if the generator is initialized.

Definition at line 213 of file G4INCLRandom.cc.

213 {
214 if(theGenerator == 0) return false;
215 return true;
216 }

Referenced by setGenerator().

◆ normVector()

◆ operator<<()

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 }

◆ saveSeeds()

void G4INCL::Random::saveSeeds ( )

Save the status of the random-number generator.

Definition at line 225 of file G4INCLRandom.cc.

225 {
226 if(!savedSeeds)
227 savedSeeds = new SeedVector;
228
229 (*savedSeeds) = theGenerator->getSeeds();
230 }

◆ setGenerator()

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 }
#define INCL_ERROR(x)
G4bool isInitialized()

Referenced by initialize().

◆ setSeeds()

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 }

◆ shoot()

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 }

Referenced by G4INCL::DeltaDecayChannel::computeDecayTime(), G4INCL::PionResonanceDecayChannel::computeDecayTime(), G4INCL::SigmaZeroDecayChannel::computeDecayTime(), G4INCL::Nucleus::decayInsideStrangeParticles(), G4INCL::IsotopicDistribution::drawRandomIsotope(), G4INCL::DeltaDecayChannel::fillFinalState(), G4INCL::DeltaProductionChannel::fillFinalState(), G4INCL::ElasticChannel::fillFinalState(), G4INCL::EtaNElasticChannel::fillFinalState(), G4INCL::EtaNToPiNChannel::fillFinalState(), G4INCL::EtaNToPiPiNChannel::fillFinalState(), G4INCL::NDeltaEtaProductionChannel::fillFinalState(), G4INCL::NDeltaOmegaProductionChannel::fillFinalState(), G4INCL::NDeltaToDeltaLKChannel::fillFinalState(), G4INCL::NDeltaToDeltaSKChannel::fillFinalState(), G4INCL::NDeltaToNLKChannel::fillFinalState(), G4INCL::NDeltaToNNKKbChannel::fillFinalState(), G4INCL::NDeltaToNSKChannel::fillFinalState(), G4INCL::NeutralKaonDecayChannel::fillFinalState(), G4INCL::NKbToL2piChannel::fillFinalState(), G4INCL::NKbToNKb2piChannel::fillFinalState(), G4INCL::NKbToNKbpiChannel::fillFinalState(), G4INCL::NKbToS2piChannel::fillFinalState(), G4INCL::NKbToSpiChannel::fillFinalState(), G4INCL::NKToNK2piChannel::fillFinalState(), G4INCL::NKToNKpiChannel::fillFinalState(), G4INCL::NLToNSChannel::fillFinalState(), G4INCL::NNEtaToMultiPionsChannel::fillFinalState(), G4INCL::NNOmegaToMultiPionsChannel::fillFinalState(), G4INCL::NNToMissingStrangenessChannel::fillFinalState(), G4INCL::NNToMultiPionsChannel::fillFinalState(), G4INCL::NNToNLK2piChannel::fillFinalState(), G4INCL::NNToNLKChannel::fillFinalState(), G4INCL::NNToNLKpiChannel::fillFinalState(), G4INCL::NNToNNEtaChannel::fillFinalState(), G4INCL::NNToNNKKbChannel::fillFinalState(), G4INCL::NNToNNOmegaChannel::fillFinalState(), G4INCL::NNToNSK2piChannel::fillFinalState(), G4INCL::NNToNSKChannel::fillFinalState(), G4INCL::NNToNSKpiChannel::fillFinalState(), G4INCL::NpiToLK2piChannel::fillFinalState(), G4INCL::NpiToLKpiChannel::fillFinalState(), G4INCL::NpiToMissingStrangenessChannel::fillFinalState(), G4INCL::NpiToNKKbChannel::fillFinalState(), G4INCL::NpiToSK2piChannel::fillFinalState(), G4INCL::NpiToSKChannel::fillFinalState(), G4INCL::NpiToSKpiChannel::fillFinalState(), G4INCL::OmegaNToPiNChannel::fillFinalState(), G4INCL::OmegaNToPiPiNChannel::fillFinalState(), G4INCL::PiNElasticChannel::fillFinalState(), G4INCL::PiNToEtaChannel::fillFinalState(), G4INCL::PionResonanceDecayChannel::fillFinalState(), G4AblaRandom::flat(), gaussWithMemory(), G4INCL::PhaseSpaceRauboldLynch::generate(), G4INCL::BinaryCollisionAvatar::getChannel(), G4INCL::SurfaceAvatar::getChannel(), G4INCL::PauliGlobal::isBlocked(), G4INCL::PauliStandard::isBlocked(), G4INCL::NKbElasticChannel::KaonMomentum(), G4INCL::NKbToLpiChannel::KaonMomentum(), G4INCL::NKbToNKbChannel::KaonMomentum(), G4INCL::NKbToSpiChannel::KaonMomentum(), G4INCL::NpiToLKChannel::KaonMomentum(), G4INCL::NpiToSKChannel::KaonMomentum(), normVector(), shoot0(), and shoot1().

◆ shoot0()

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 }

Referenced by gaussWithMemory(), and sphereVector().

◆ shoot1()

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 }

Referenced by shootInteger().

◆ shootInteger()

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

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

Definition at line 98 of file G4INCLRandom.hh.

98 {
99 return static_cast<T>(shoot1() * n);
100 }
G4double shoot1()

◆ sphereVector()

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

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

Definition at line 174 of file G4INCLRandom.cc.

174 {
175 return normVector( rmax*Math::pow13(shoot0()) );
176 }
ThreeVector normVector(G4double norm=1.)