Import Geant4 10.6.0 source tree

This commit is contained in:
Gabriele Cosmo
2019-12-06 15:12:28 +01:00
parent b2a62ae692
commit 5baee230e9
2997 changed files with 141580 additions and 98673 deletions
@@ -76,8 +76,7 @@ public:
inline const G4Element* SelectRandomAtom(G4double kineticEnergy) const;
inline const G4Element* SelectRandomAtom(const G4double kineticEnergy,
const G4double logEKin,
size_t &lastIndx);
const G4double logEKin) const;
inline const G4Material* GetMaterial() const;
@@ -122,16 +121,32 @@ inline const G4Element* G4EmElementSelector::SelectRandomAtom(G4double e) const
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
inline const G4Element*
G4EmElementSelector::SelectRandomAtom(const G4double e, const G4double loge,
size_t &lastIndx)
G4EmElementSelector::SelectRandomAtom(const G4double e,const G4double loge)const
{
const G4Element* element = (*theElementVector)[nElmMinusOne];
if (nElmMinusOne > 0) {
const G4double x = G4UniformRand();
for (G4int i=0; i<nElmMinusOne; ++i) {
if (x <= (xSections[i])->Value(e, loge, lastIndx)) {
// 1. Determine energy index (only once)
const size_t nBins = (xSections[0])->GetVectorLength();
// handle cases below/above the enrgy grid (by ekin, idx that gives a=0/1)
// ekin = x[0] if e<=x[0] and idx will be 0 ^ a=0 => so y=y0
// ekin = x[N-1] if e>=x[N-1] and idx will be N-2 ^ a=1 => so y=y_{N-1}
const G4double ekin = std::max((xSections[0])->Energy(0),
std::min((xSections[0])->Energy(nBins-1),e));
// compute the lower index of the bin (idx \in [0,N-2] will be guaranted)
const size_t idx = (xSections[0])->ComputeLogVectorBin(loge);
// 2. Do the linear interp.(robust for corner cases through ekin, idx and a)
const G4double x1 = (xSections[0])->Energy(idx);
const G4double x2 = (xSections[0])->Energy(idx+1);
// note: all corner cases of the previous methods are covered and eventually
// gives a=0/1 that results in y=y0\y_{N-1} if e<=x[0]/e>=x[N-1] or
// y=y_i/y_{i+1} if e<x[i]/e>=x[i+1] due to small numerical errors
const G4double a = std::max(0., std::min(1., (ekin - x1)/(x2 - x1)));
const G4double urnd = G4UniformRand();
for (G4int i = 0; i < nElmMinusOne; ++i) {
const G4double y1 = (*xSections[i])[idx];
const G4double y2 = (*xSections[i])[idx+1];
if (urnd <= y1 + a*(y2-y1)) {
element = (*theElementVector)[i];
break;
}