Import Geant4 10.7.0.beta source tree
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# CMakeLists.txt
|
||||
# Module :
|
||||
# Package: Geant4.src.G4global.
|
||||
#
|
||||
# CMakeLists.txt for building a header-only module.
|
||||
#
|
||||
# Generated on : 24/9/2010
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
if(GEANT4_BUILD_GRANULAR_LIBS)
|
||||
include(Geant4MacroLibraryTargets)
|
||||
GEANT4_GRANULAR_LIBRARY_TARGET(COMPONENT sources.cmake)
|
||||
endif()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,45 +1,24 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# sources.cmake
|
||||
# Module :
|
||||
# Package: Geant4.src.G4global.
|
||||
#
|
||||
# Sources description for a library.
|
||||
# Lists the sources and headers of the code explicitely.
|
||||
# Lists include paths needed.
|
||||
# Lists the internal granular and global dependencies of the library.
|
||||
# Source specific properties should be added at the end.
|
||||
#
|
||||
# Generated on : 24/9/2010
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# List external includes needed.
|
||||
include_directories(${CLHEP_INCLUDE_DIRS})
|
||||
|
||||
# List internal includes needed.
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/global/management/include)
|
||||
|
||||
#
|
||||
# Define the Geant4 Module.
|
||||
#
|
||||
|
||||
include(Geant4MacroDefineModule)
|
||||
GEANT4_DEFINE_MODULE(NAME G4heprandom
|
||||
HEADERS
|
||||
G4Poisson.hh
|
||||
G4QuickRand.hh
|
||||
G4RandomDirection.hh
|
||||
G4RandomTools.hh
|
||||
geant4_define_module(NAME G4heprandom
|
||||
HEADERS
|
||||
G4Poisson.hh
|
||||
G4QuickRand.hh
|
||||
G4RandomDirection.hh
|
||||
G4RandomTools.hh
|
||||
G4UniformRandPool.hh
|
||||
Randomize.hh
|
||||
SOURCES
|
||||
G4Poisson.cc
|
||||
G4UniformRandPool.cc
|
||||
GRANULAR_DEPENDENCIES
|
||||
GLOBAL_DEPENDENCIES
|
||||
LINK_LIBRARIES
|
||||
Randomize.hh
|
||||
SOURCES
|
||||
G4Poisson.cc
|
||||
G4UniformRandPool.cc
|
||||
GRANULAR_DEPENDENCIES
|
||||
G4globman
|
||||
)
|
||||
|
||||
# List any source specific properties here
|
||||
|
||||
|
||||
@@ -24,104 +24,90 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// G4UniformRandPool implementation
|
||||
//
|
||||
// Author: A.Dotti (SLAC)
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#include "G4UniformRandPool.hh"
|
||||
#include "globals.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoDelete.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <climits>
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Not aligned memory
|
||||
//
|
||||
void create_pool( G4double*& buffer , G4int ps )
|
||||
{
|
||||
buffer = new G4double[ps];
|
||||
}
|
||||
void create_pool(G4double*& buffer, G4int ps) { buffer = new G4double[ps]; }
|
||||
|
||||
void destroy_pool( G4double*& buffer)
|
||||
{
|
||||
delete[] buffer;
|
||||
}
|
||||
void destroy_pool(G4double*& buffer) { delete[] buffer; }
|
||||
|
||||
#if defined(WIN32)
|
||||
// No bother with WIN
|
||||
void create_pool_align( G4double*& buffer , G4int ps)
|
||||
{
|
||||
create_pool(buffer,ps);
|
||||
}
|
||||
void destroy_pool_align( G4double*& buffer )
|
||||
{
|
||||
destroy_pool(buffer);
|
||||
}
|
||||
void create_pool_align(G4double*& buffer, G4int ps) { create_pool(buffer, ps); }
|
||||
void destroy_pool_align(G4double*& buffer) { destroy_pool(buffer); }
|
||||
|
||||
#else
|
||||
|
||||
// Align memory pools
|
||||
// Assumption is: static_assert(sizeof(G4double)*CHAR_BIT==64)
|
||||
//
|
||||
void create_pool_align( G4double*& buffer , G4int ps)
|
||||
void create_pool_align(G4double*& buffer, G4int ps)
|
||||
{
|
||||
// POSIX standard way
|
||||
G4int errcode = posix_memalign( (void**) &buffer ,
|
||||
sizeof(G4double)*CHAR_BIT,
|
||||
ps*sizeof(G4double));
|
||||
if ( errcode != 0 )
|
||||
G4int errcode = posix_memalign((void**) &buffer, sizeof(G4double) * CHAR_BIT,
|
||||
ps * sizeof(G4double));
|
||||
if(errcode != 0)
|
||||
{
|
||||
G4Exception("G4UniformRandPool::create_pool_align()",
|
||||
"InvalidCondition", FatalException,
|
||||
"Cannot allocate aligned buffer");
|
||||
G4Exception("G4UniformRandPool::create_pool_align()", "InvalidCondition",
|
||||
FatalException, "Cannot allocate aligned buffer");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void destroy_pool_align( G4double*& buffer )
|
||||
{
|
||||
free(buffer);
|
||||
}
|
||||
void destroy_pool_align(G4double*& buffer) { free(buffer); }
|
||||
#endif
|
||||
|
||||
G4UniformRandPool::G4UniformRandPool()
|
||||
: size(G4UNIFORMRANDPOOL_DEFAULT_POOLSIZE), buffer(0), currentIdx(0)
|
||||
: size(G4UNIFORMRANDPOOL_DEFAULT_POOLSIZE)
|
||||
, buffer(0)
|
||||
, currentIdx(0)
|
||||
{
|
||||
if ( sizeof(G4double)*CHAR_BIT==64 )
|
||||
if(sizeof(G4double) * CHAR_BIT == 64)
|
||||
{
|
||||
create_pool_align(buffer,size);
|
||||
create_pool_align(buffer, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
create_pool(buffer,size);
|
||||
create_pool(buffer, size);
|
||||
}
|
||||
Fill(size);
|
||||
}
|
||||
|
||||
G4UniformRandPool::G4UniformRandPool( G4int siz )
|
||||
: size(siz), buffer(0), currentIdx(0)
|
||||
G4UniformRandPool::G4UniformRandPool(G4int siz)
|
||||
: size(siz)
|
||||
, buffer(0)
|
||||
, currentIdx(0)
|
||||
{
|
||||
if ( sizeof(G4double)*CHAR_BIT==64 )
|
||||
if(sizeof(G4double) * CHAR_BIT == 64)
|
||||
{
|
||||
create_pool_align(buffer,size);
|
||||
create_pool_align(buffer, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
create_pool(buffer,size);
|
||||
create_pool(buffer, size);
|
||||
}
|
||||
Fill(size);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
G4UniformRandPool::~G4UniformRandPool()
|
||||
{
|
||||
if ( sizeof(G4double)*CHAR_BIT==64 )
|
||||
if(sizeof(G4double) * CHAR_BIT == 64)
|
||||
{
|
||||
destroy_pool_align(buffer);
|
||||
}
|
||||
@@ -131,31 +117,31 @@ G4UniformRandPool::~G4UniformRandPool()
|
||||
}
|
||||
}
|
||||
|
||||
void G4UniformRandPool::Resize(/*PoolSize_t*/ G4int newSize )
|
||||
void G4UniformRandPool::Resize(/*PoolSize_t*/ G4int newSize)
|
||||
{
|
||||
if ( newSize != size )
|
||||
if(newSize != size)
|
||||
{
|
||||
destroy_pool(buffer);
|
||||
create_pool(buffer,newSize);
|
||||
size=newSize;
|
||||
create_pool(buffer, newSize);
|
||||
size = newSize;
|
||||
currentIdx = 0;
|
||||
}
|
||||
currentIdx = 0;
|
||||
}
|
||||
|
||||
void G4UniformRandPool::Fill( G4int howmany )
|
||||
void G4UniformRandPool::Fill(G4int howmany)
|
||||
{
|
||||
assert(howmany>0 && howmany <= size);
|
||||
assert(howmany > 0 && howmany <= size);
|
||||
|
||||
// Fill buffer with random numbers
|
||||
//
|
||||
G4Random::getTheEngine()->flatArray(howmany,buffer);
|
||||
G4Random::getTheEngine()->flatArray(howmany, buffer);
|
||||
currentIdx = 0;
|
||||
}
|
||||
|
||||
void G4UniformRandPool::GetMany( G4double* rnds , G4int howmany )
|
||||
void G4UniformRandPool::GetMany(G4double* rnds, G4int howmany)
|
||||
{
|
||||
assert(rnds!=0 && howmany>0);
|
||||
assert(rnds != 0 && howmany > 0);
|
||||
|
||||
// if ( howmany <= 0 ) return;
|
||||
// We generate at max "size" numbers at once, and
|
||||
@@ -164,12 +150,12 @@ void G4UniformRandPool::GetMany( G4double* rnds , G4int howmany )
|
||||
// So:
|
||||
// how many times I need to get "size" numbers?
|
||||
|
||||
const G4int maxcycles = howmany/size;
|
||||
const G4int maxcycles = howmany / size;
|
||||
|
||||
// This is the rest
|
||||
//
|
||||
const G4int peel = howmany%size;
|
||||
assert(peel<size);
|
||||
const G4int peel = howmany % size;
|
||||
assert(peel < size);
|
||||
|
||||
// Ok from now on I will get random numbers in group of "size"
|
||||
// Note that if howmany<size maxcycles == 0
|
||||
@@ -180,18 +166,18 @@ void G4UniformRandPool::GetMany( G4double* rnds , G4int howmany )
|
||||
// and we will request at least "size" rng, so
|
||||
// let's start with a fresh buffer of numbers if needed
|
||||
//
|
||||
if ( maxcycles>0 && currentIdx>0 )
|
||||
if(maxcycles > 0 && currentIdx > 0)
|
||||
{
|
||||
assert(currentIdx<=size);
|
||||
Fill(currentIdx);//<size?currentIdx:size);
|
||||
assert(currentIdx <= size);
|
||||
Fill(currentIdx); //<size?currentIdx:size);
|
||||
}
|
||||
for ( ; cycle < maxcycles ; ++cycle )
|
||||
for(; cycle < maxcycles; ++cycle)
|
||||
{
|
||||
// We can use memcpy of std::copy, it turns out that the two are basically
|
||||
// We can use memcpy of std::copy, it turns out that the two are basically
|
||||
// performance-wise equivalent (expected), since in my tests memcpy is a
|
||||
// little bit faster, I use that
|
||||
//
|
||||
memcpy(rnds+(cycle*size),buffer,sizeof(G4double)*size );
|
||||
memcpy(rnds + (cycle * size), buffer, sizeof(G4double) * size);
|
||||
// std::copy(buffer,buffer+size,rnds+(cycle*size));
|
||||
|
||||
// Get a new set of numbers
|
||||
@@ -205,17 +191,17 @@ void G4UniformRandPool::GetMany( G4double* rnds , G4int howmany )
|
||||
// but if maxcycles==0 currentIdx can be whatever, let's make sure we have
|
||||
// enough fresh numbers
|
||||
//
|
||||
if (currentIdx + peel >= size)
|
||||
if(currentIdx + peel >= size)
|
||||
{
|
||||
Fill(currentIdx<size?currentIdx:size);
|
||||
Fill(currentIdx < size ? currentIdx : size);
|
||||
}
|
||||
memcpy(rnds+(cycle*size) , buffer+currentIdx , sizeof(G4double)*peel );
|
||||
memcpy(rnds + (cycle * size), buffer + currentIdx, sizeof(G4double) * peel);
|
||||
// std::copy(buffer+currentIdx,buffer+(currentIdx+peel), rnds+(cycle*size));
|
||||
|
||||
// Advance index, we are done
|
||||
//
|
||||
currentIdx+=peel;
|
||||
assert(currentIdx<=size);
|
||||
currentIdx += peel;
|
||||
assert(currentIdx <= size);
|
||||
}
|
||||
|
||||
// Static interfaces implementing CLHEP methods
|
||||
@@ -227,7 +213,7 @@ namespace
|
||||
|
||||
G4double G4UniformRandPool::flat()
|
||||
{
|
||||
if ( rndpool == 0 )
|
||||
if(rndpool == 0)
|
||||
{
|
||||
rndpool = new G4UniformRandPool;
|
||||
G4AutoDelete::Register(rndpool);
|
||||
@@ -235,12 +221,12 @@ G4double G4UniformRandPool::flat()
|
||||
return rndpool->GetOne();
|
||||
}
|
||||
|
||||
void G4UniformRandPool::flatArray( G4int howmany, G4double *rnds)
|
||||
void G4UniformRandPool::flatArray(G4int howmany, G4double* rnds)
|
||||
{
|
||||
if ( rndpool == 0 )
|
||||
if(rndpool == 0)
|
||||
{
|
||||
rndpool = new G4UniformRandPool;
|
||||
G4AutoDelete::Register(rndpool);
|
||||
}
|
||||
rndpool->GetMany(rnds,(unsigned int)howmany);
|
||||
rndpool->GetMany(rnds, (unsigned int) howmany);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user