Import Geant4 10.7.0.beta source tree
This commit is contained in:
@@ -25,9 +25,9 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// GEANT 4 class header file
|
||||
// ------------------------------------------------------------
|
||||
// Class description:
|
||||
//
|
||||
@@ -43,36 +43,39 @@
|
||||
|
||||
#include <CLHEP/Units/PhysicalConstants.h>
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include "G4Exp.hh"
|
||||
#include "G4Types.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
inline G4long G4Poisson(G4double mean)
|
||||
{
|
||||
G4long number = 0;
|
||||
const G4int border = 16;
|
||||
G4long number = 0;
|
||||
const G4int border = 16;
|
||||
const G4double limit = 2e9;
|
||||
|
||||
if(mean <= border)
|
||||
{
|
||||
G4double position = G4UniformRand();
|
||||
G4double position = G4UniformRand();
|
||||
G4double poissonValue = G4Exp(-mean);
|
||||
G4double poissonSum = poissonValue;
|
||||
G4double poissonSum = poissonValue;
|
||||
|
||||
while(poissonSum <= position)
|
||||
{
|
||||
++number;
|
||||
poissonValue *= mean/number;
|
||||
poissonValue *= mean / number;
|
||||
poissonSum += poissonValue;
|
||||
}
|
||||
return number;
|
||||
} // the case of mean <= 16
|
||||
} // the case of mean <= 16
|
||||
|
||||
G4double t = std::sqrt(-2.*std::log(G4UniformRand()))*
|
||||
std::cos(2.*CLHEP::pi*G4UniformRand());
|
||||
G4double value = mean + t*std::sqrt(mean) + 0.5;
|
||||
if(value < 0.) {return 0;}
|
||||
G4double t = std::sqrt(-2. * std::log(G4UniformRand())) *
|
||||
std::cos(2. * CLHEP::pi * G4UniformRand());
|
||||
G4double value = mean + t * std::sqrt(mean) + 0.5;
|
||||
if(value < 0.)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (value >= limit) ? G4long(limit) : G4long(value);
|
||||
}
|
||||
|
||||
#endif /* G4POISSON_HH */
|
||||
#endif /* G4POISSON_HH */
|
||||
|
||||
@@ -28,16 +28,16 @@
|
||||
#ifndef G4QUICKRAND_HH
|
||||
#define G4QUICKRAND_HH
|
||||
|
||||
#include <cstdint>
|
||||
#include "G4Types.hh"
|
||||
#include <cstdint>
|
||||
|
||||
inline G4double G4QuickRand()
|
||||
{
|
||||
static const G4double f = 1. / 4294967296.; // 2^-32
|
||||
static const G4double f = 1. / 4294967296.; // 2^-32
|
||||
|
||||
// Algorithm "xor" from p.4 of G.Marsaglia, "Xorshift RNGs"
|
||||
static G4ThreadLocal uint32_t y = 2463534242;
|
||||
uint32_t x = y;
|
||||
uint32_t x = y;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
@@ -45,4 +45,4 @@ inline G4double G4QuickRand()
|
||||
return x * f;
|
||||
}
|
||||
|
||||
#endif // G4QUICKRAND_HH
|
||||
#endif // G4QUICKRAND_HH
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// GEANT 4 class header file
|
||||
// ------------------------------------------------------------
|
||||
// Class description:
|
||||
//
|
||||
@@ -50,29 +50,30 @@
|
||||
|
||||
#include <CLHEP/Units/PhysicalConstants.h>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "Randomize.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
#include "Randomize.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
// G.Marsaglia (1972) method
|
||||
inline G4ThreeVector G4RandomDirection()
|
||||
{
|
||||
G4double u, v, b;
|
||||
do {
|
||||
u = 2.*G4UniformRand() - 1.;
|
||||
v = 2.*G4UniformRand() - 1.;
|
||||
b = u*u + v*v;
|
||||
} while (b > 1.);
|
||||
G4double a = 2.*std::sqrt(1. - b);
|
||||
return G4ThreeVector(a*u, a*v, 2.*b - 1.);
|
||||
do
|
||||
{
|
||||
u = 2. * G4UniformRand() - 1.;
|
||||
v = 2. * G4UniformRand() - 1.;
|
||||
b = u * u + v * v;
|
||||
} while(b > 1.);
|
||||
G4double a = 2. * std::sqrt(1. - b);
|
||||
return G4ThreeVector(a * u, a * v, 2. * b - 1.);
|
||||
}
|
||||
|
||||
inline G4ThreeVector G4RandomDirection(G4double cosTheta)
|
||||
{
|
||||
G4double z = (1. - cosTheta)*G4UniformRand() + cosTheta;
|
||||
G4double rho = std::sqrt((1.+z)*(1.-z));
|
||||
G4double phi = CLHEP::twopi*G4UniformRand();
|
||||
return G4ThreeVector(rho*std::cos(phi), rho*std::sin(phi), z);
|
||||
G4double z = (1. - cosTheta) * G4UniformRand() + cosTheta;
|
||||
G4double rho = std::sqrt((1. + z) * (1. - z));
|
||||
G4double phi = CLHEP::twopi * G4UniformRand();
|
||||
return G4ThreeVector(rho * std::cos(phi), rho * std::sin(phi), z);
|
||||
}
|
||||
|
||||
#endif /* G4RANDOMDIR_HH */
|
||||
#endif /* G4RANDOMDIR_HH */
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// GEANT 4 class header file
|
||||
// ---------------------------------------------------------------------------
|
||||
// Class description:
|
||||
//
|
||||
// Utility functions
|
||||
// Utility functions
|
||||
|
||||
// History:
|
||||
//
|
||||
@@ -46,11 +46,11 @@
|
||||
|
||||
#include <CLHEP/Units/PhysicalConstants.h>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "Randomize.hh"
|
||||
#include "G4TwoVector.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
#include "G4RandomDirection.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
#include "G4TwoVector.hh"
|
||||
#include "Randomize.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Returns a random lambertian unit vector (rejection sampling)
|
||||
@@ -59,22 +59,22 @@ inline G4ThreeVector G4LambertianRand(const G4ThreeVector& normal)
|
||||
{
|
||||
G4ThreeVector vect;
|
||||
G4double ndotv;
|
||||
G4int count=0;
|
||||
G4int count = 0;
|
||||
const G4int max_trials = 1024;
|
||||
|
||||
do
|
||||
{
|
||||
++count;
|
||||
vect = G4RandomDirection();
|
||||
vect = G4RandomDirection();
|
||||
ndotv = normal * vect;
|
||||
|
||||
if (ndotv < 0.0)
|
||||
if(ndotv < 0.0)
|
||||
{
|
||||
vect = -vect;
|
||||
vect = -vect;
|
||||
ndotv = -ndotv;
|
||||
}
|
||||
|
||||
} while (!(G4UniformRand() < ndotv) && (count < max_trials));
|
||||
} while(!(G4UniformRand() < ndotv) && (count < max_trials));
|
||||
|
||||
return vect;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ inline G4ThreeVector G4PlaneVectorRand(const G4ThreeVector& normal)
|
||||
G4ThreeVector vec1 = normal.orthogonal();
|
||||
G4ThreeVector vec2 = vec1.cross(normal);
|
||||
|
||||
G4double phi = CLHEP::twopi*G4UniformRand();
|
||||
G4double phi = CLHEP::twopi * G4UniformRand();
|
||||
G4double cosphi = std::cos(phi);
|
||||
G4double sinphi = std::sin(phi);
|
||||
|
||||
@@ -99,13 +99,13 @@ inline G4ThreeVector G4PlaneVectorRand(const G4ThreeVector& normal)
|
||||
//
|
||||
inline G4double G4RandomRadiusInRing(G4double rmin, G4double rmax)
|
||||
{
|
||||
if (rmin == rmax)
|
||||
if(rmin == rmax)
|
||||
{
|
||||
return rmin;
|
||||
}
|
||||
G4double k = G4UniformRand();
|
||||
return (rmin <= 0) ? rmax*std::sqrt(k)
|
||||
: std::sqrt(k*rmax*rmax + (1.-k)*rmin*rmin);
|
||||
return (rmin <= 0) ? rmax * std::sqrt(k)
|
||||
: std::sqrt(k * rmax * rmax + (1. - k) * rmin * rmin);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -114,15 +114,16 @@ inline G4double G4RandomRadiusInRing(G4double rmin, G4double rmax)
|
||||
//
|
||||
inline G4TwoVector G4RandomPointInEllipse(G4double a, G4double b)
|
||||
{
|
||||
G4double aa = (a*a == 0) ? 0 : 1/(a*a);
|
||||
G4double bb = (b*b == 0) ? 0 : 1/(b*b);
|
||||
for (G4int i=0; i<1000; ++i)
|
||||
G4double aa = (a * a == 0) ? 0 : 1 / (a * a);
|
||||
G4double bb = (b * b == 0) ? 0 : 1 / (b * b);
|
||||
for(G4int i = 0; i < 1000; ++i)
|
||||
{
|
||||
G4double x = a*(2*G4UniformRand() - 1);
|
||||
G4double y = b*(2*G4UniformRand() - 1);
|
||||
if (x*x*aa + y*y*bb <= 1) return G4TwoVector(x,y);
|
||||
G4double x = a * (2 * G4UniformRand() - 1);
|
||||
G4double y = b * (2 * G4UniformRand() - 1);
|
||||
if(x * x * aa + y * y * bb <= 1)
|
||||
return G4TwoVector(x, y);
|
||||
}
|
||||
return G4TwoVector(0,0);
|
||||
return G4TwoVector(0, 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -131,45 +132,47 @@ inline G4TwoVector G4RandomPointInEllipse(G4double a, G4double b)
|
||||
//
|
||||
inline G4TwoVector G4RandomPointOnEllipse(G4double a, G4double b)
|
||||
{
|
||||
G4double A = std::abs(a);
|
||||
G4double B = std::abs(b);
|
||||
G4double mu_max = std::max(A,B);
|
||||
G4double A = std::abs(a);
|
||||
G4double B = std::abs(b);
|
||||
G4double mu_max = std::max(A, B);
|
||||
|
||||
G4double x,y;
|
||||
for (G4int i=0; i<1000; ++i)
|
||||
G4double x, y;
|
||||
for(G4int i = 0; i < 1000; ++i)
|
||||
{
|
||||
G4double phi = CLHEP::twopi*G4UniformRand();
|
||||
x = std::cos(phi);
|
||||
y = std::sin(phi);
|
||||
G4double mu = std::sqrt((B*x)*(B*x) + (A*y)*(A*y));
|
||||
if (mu_max*G4UniformRand() <= mu) break;
|
||||
G4double phi = CLHEP::twopi * G4UniformRand();
|
||||
x = std::cos(phi);
|
||||
y = std::sin(phi);
|
||||
G4double mu = std::sqrt((B * x) * (B * x) + (A * y) * (A * y));
|
||||
if(mu_max * G4UniformRand() <= mu)
|
||||
break;
|
||||
}
|
||||
return G4TwoVector(A*x,B*y);
|
||||
return G4TwoVector(A * x, B * y);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Returns a random point on ellipsoid (x/a)^2 + (y/b)^2 + (z/c)^2 = 1
|
||||
// (rejection sampling)
|
||||
//
|
||||
inline
|
||||
G4ThreeVector G4RandomPointOnEllipsoid(G4double a, G4double b, G4double c)
|
||||
inline G4ThreeVector G4RandomPointOnEllipsoid(G4double a, G4double b,
|
||||
G4double c)
|
||||
{
|
||||
G4double A = std::abs(a);
|
||||
G4double B = std::abs(b);
|
||||
G4double C = std::abs(c);
|
||||
G4double mu_max = std::max(std::max(A*B,A*C),B*C);
|
||||
G4double A = std::abs(a);
|
||||
G4double B = std::abs(b);
|
||||
G4double C = std::abs(c);
|
||||
G4double mu_max = std::max(std::max(A * B, A * C), B * C);
|
||||
|
||||
G4ThreeVector p;
|
||||
for (G4int i=0; i<1000; ++i)
|
||||
for(G4int i = 0; i < 1000; ++i)
|
||||
{
|
||||
p = G4RandomDirection();
|
||||
G4double xbc = p.x()*B*C;
|
||||
G4double yac = p.y()*A*C;
|
||||
G4double zab = p.z()*A*B;
|
||||
G4double mu = std::sqrt(xbc*xbc + yac*yac + zab*zab);
|
||||
if (mu_max*G4UniformRand() <= mu) break;
|
||||
p = G4RandomDirection();
|
||||
G4double xbc = p.x() * B * C;
|
||||
G4double yac = p.y() * A * C;
|
||||
G4double zab = p.z() * A * B;
|
||||
G4double mu = std::sqrt(xbc * xbc + yac * yac + zab * zab);
|
||||
if(mu_max * G4UniformRand() <= mu)
|
||||
break;
|
||||
}
|
||||
return G4ThreeVector(A*p.x(),B*p.y(),C*p.z());
|
||||
return G4ThreeVector(A * p.x(), B * p.y(), C * p.z());
|
||||
}
|
||||
|
||||
#endif /* G4RANDOMTOOLS_HH */
|
||||
#endif /* G4RANDOMTOOLS_HH */
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// GEANT 4 class header file
|
||||
// ------------------------------------------------------------
|
||||
// Class description:
|
||||
//
|
||||
@@ -54,41 +54,38 @@
|
||||
|
||||
class G4UniformRandPool
|
||||
{
|
||||
public:
|
||||
public:
|
||||
G4UniformRandPool();
|
||||
G4UniformRandPool(/*PoolSize_t&*/ G4int ps);
|
||||
~G4UniformRandPool();
|
||||
|
||||
G4UniformRandPool();
|
||||
G4UniformRandPool( /*PoolSize_t&*/ G4int ps );
|
||||
~G4UniformRandPool();
|
||||
void Resize(/*PoolSize_t*/ G4int newSize);
|
||||
void GetMany(G4double* rnds, G4int howMany);
|
||||
inline G4double GetOne();
|
||||
inline /*PoolSize_t*/ G4int GetPoolSize() const;
|
||||
|
||||
void Resize( /*PoolSize_t*/ G4int newSize );
|
||||
void GetMany( G4double* rnds , G4int howMany );
|
||||
inline G4double GetOne();
|
||||
inline /*PoolSize_t*/ G4int GetPoolSize() const;
|
||||
// These two static methods are used to
|
||||
// simulate the calls of CLHEP::HepRandom
|
||||
//
|
||||
static G4double flat();
|
||||
static void flatArray(G4int howmany, G4double* rnds);
|
||||
|
||||
// These two static methods are used to
|
||||
// simulate the calls of CLHEP::HepRandom
|
||||
//
|
||||
static G4double flat();
|
||||
static void flatArray( G4int howmany, G4double* rnds );
|
||||
private:
|
||||
void Fill(G4int howmany);
|
||||
|
||||
private:
|
||||
|
||||
void Fill( G4int howmany );
|
||||
|
||||
private:
|
||||
|
||||
/*PoolSize_t*/ G4int size;
|
||||
G4double* buffer;
|
||||
G4int currentIdx;
|
||||
private:
|
||||
/*PoolSize_t*/ G4int size;
|
||||
G4double* buffer;
|
||||
G4int currentIdx;
|
||||
};
|
||||
|
||||
inline G4double G4UniformRandPool::GetOne()
|
||||
{
|
||||
// No more available numbers, re-fill
|
||||
//
|
||||
if ( currentIdx >= /*(unsigned int)*/size )
|
||||
if(currentIdx >= /*(unsigned int)*/ size)
|
||||
{
|
||||
Fill(/*(unsigned int)*/size);
|
||||
Fill(/*(unsigned int)*/ size);
|
||||
}
|
||||
|
||||
return buffer[currentIdx++];
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
|
||||
// Distributions used ...
|
||||
//
|
||||
#include <CLHEP/Random/RandFlat.h>
|
||||
#include <CLHEP/Random/RandBit.h>
|
||||
#include <CLHEP/Random/RandExponential.h>
|
||||
#include <CLHEP/Random/RandFlat.h>
|
||||
#include <CLHEP/Random/RandGamma.h>
|
||||
#include <CLHEP/Random/RandGaussQ.h>
|
||||
#include <CLHEP/Random/RandPoissonQ.h>
|
||||
#include <CLHEP/Random/RandExponential.h>
|
||||
#include <CLHEP/Random/RandGeneral.h>
|
||||
#include <CLHEP/Random/RandPoissonQ.h>
|
||||
|
||||
#define G4RandStat CLHEP::HepStat
|
||||
#define G4RandFlat CLHEP::RandFlat
|
||||
@@ -51,4 +51,4 @@
|
||||
|
||||
#define G4UniformRand() CLHEP::HepRandom::getTheEngine()->flat()
|
||||
|
||||
#endif // randomize_h
|
||||
#endif // randomize_h
|
||||
|
||||
Reference in New Issue
Block a user