Import Geant4 10.7.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2020-06-26 10:23:25 +02:00
parent c02c370437
commit 67ba86d073
1871 changed files with 174422 additions and 131884 deletions
@@ -23,267 +23,206 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4PhysicsVector inline methods implementation
//
//
//
//---------------------------------------------------------------
// GEANT 4 class source file
//
// G4PhysicsVector.icc
//
// Description:
// A physics vector which has values of energy-loss, cross-section,
// and other physics values of a particle in matter in a given
// range of the energy, momentum, etc.
// This class serves as the base class for a vector having various
// energy scale, for example like 'log', 'linear', 'free', etc.
//
//---------------------------------------------------------------
// Authors:
// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
// - 03 Mar. 1996, K.Amako: Implemented the 1st version
// --------------------------------------------------------------------
inline
G4double G4PhysicsVector::operator[](const size_t index) const
{
return dataVector[index];
}
//---------------------------------------------------------------
inline
G4double G4PhysicsVector::operator()(const size_t index) const
inline G4double G4PhysicsVector::operator[](const std::size_t index) const
{
return dataVector[index];
}
//---------------------------------------------------------------
// ---------------------------------------------------------------
inline
G4double G4PhysicsVector::Energy(const size_t index) const
inline G4double G4PhysicsVector::operator()(const std::size_t index) const
{
return dataVector[index];
}
// ---------------------------------------------------------------
inline G4double G4PhysicsVector::Energy(const std::size_t index) const
{
return binVector[index];
}
//---------------------------------------------------------------
// ---------------------------------------------------------------
inline
G4double G4PhysicsVector::GetMaxEnergy() const
{
return edgeMax;
}
inline G4double G4PhysicsVector::GetMaxEnergy() const { return edgeMax; }
//---------------------------------------------------------------
// ---------------------------------------------------------------
inline
size_t G4PhysicsVector::GetVectorLength() const
inline std::size_t G4PhysicsVector::GetVectorLength() const
{
return numberOfNodes;
}
//------------------------------------------------
// ---------------------------------------------------------------
inline
G4double G4PhysicsVector::LinearInterpolation(size_t idx, G4double e) const
inline void G4PhysicsVector::PutValue(std::size_t index, G4double theValue)
{
// Linear interpolation is used to get the value. Before this method
// is called it is ensured that the energy is inside the bin
// 0 < idx < numberOfNodes-1
return dataVector[idx] +
( dataVector[idx + 1]-dataVector[idx] ) * (e - binVector[idx])
/( binVector[idx + 1]-binVector[idx] );
}
//---------------------------------------------------------------
inline
G4double G4PhysicsVector::SplineInterpolation(size_t idx, G4double e) const
{
// Spline interpolation is used to get the value. Before this method
// is called it is ensured that the energy is inside the bin
// 0 < idx < numberOfNodes-1
static const G4double onesixth = 1.0/6.0;
// check bin value
G4double x1 = binVector[idx];
G4double x2 = binVector[idx + 1];
G4double delta = x2 - x1;
G4double a = (x2 - e)/delta;
G4double b = (e - x1)/delta;
// Final evaluation of cubic spline polynomial for return
G4double y1 = dataVector[idx];
G4double y2 = dataVector[idx + 1];
G4double res = a*y1 + b*y2 +
( (a*a*a - a)*secDerivative[idx] +
(b*b*b - b)*secDerivative[idx + 1] )*delta*delta*onesixth;
return res;
}
//---------------------------------------------------------------
inline
G4double G4PhysicsVector::Interpolation(size_t idx, G4double e) const
{
return useSpline ? SplineInterpolation(idx, e) : LinearInterpolation(idx, e);
}
//---------------------------------------------------------------
inline
void G4PhysicsVector::PutValue(size_t index, G4double theValue)
{
if(index >= numberOfNodes) { PrintPutValueError(index); }
if(index >= numberOfNodes)
{
PrintPutValueError(index);
}
dataVector[index] = theValue;
}
//---------------------------------------------------------------
// ---------------------------------------------------------------
inline
G4bool G4PhysicsVector::IsFilledVectorExist() const
inline G4bool G4PhysicsVector::IsFilledVectorExist() const
{
return (numberOfNodes > 0) ? true : false;
return (numberOfNodes > 0);
}
//---------------------------------------------------------------
// ---------------------------------------------------------------
inline
G4PhysicsVectorType G4PhysicsVector::GetType() const
inline G4PhysicsVectorType G4PhysicsVector::GetType() const { return type; }
// ---------------------------------------------------------------
inline void G4PhysicsVector::SetSpline(G4bool val)
{
return type;
}
// Flag useSpline is "true" only if second derivatives are filled
//---------------------------------------------------------------
// Flag useSpline is "true" only if second derivatives are filled
inline
void G4PhysicsVector::SetSpline(G4bool val)
{
if(val) {
if(0 == secDerivative.size() && 0 < dataVector.size()) {
FillSecondDerivatives();
if(val)
{
if(0 == secDerivative.size() && 0 < dataVector.size())
{
FillSecondDerivatives();
}
} else {
}
else
{
useSpline = false;
secDerivative.clear();
}
}
//---------------------------------------------------------------
// ---------------------------------------------------------------
inline
void G4PhysicsVector::SetVerboseLevel(G4int value)
inline void G4PhysicsVector::SetVerboseLevel(G4int value)
{
verboseLevel = value;
verboseLevel = value;
}
//---------------------------------------------------------------
/*
inline
G4int G4PhysicsVector::GetVerboseLevel() const
{
return verboseLevel;
}
*/
//---------------------------------------------------------------
// ---------------------------------------------------------------
inline
size_t G4PhysicsVector::FindBinLocation(G4double theEnergy) const
inline std::size_t G4PhysicsVector::FindBinLocation(
const G4double theEnergy) const
{
size_t bin;
if(type == T_G4PhysicsLogVector) {
bin = size_t(G4Log(theEnergy)*invdBin - baseBin);
if(bin > 0 && theEnergy < binVector[bin]) { --bin; }
else if(theEnergy > binVector[bin+1]) { ++bin; }
} else if(type == T_G4PhysicsLinearVector) {
bin = size_t( theEnergy*invdBin - baseBin );
if(bin > 0 && theEnergy < binVector[bin]) { --bin; }
else if(theEnergy > binVector[bin+1]) { ++bin; }
} else {
// Bin location proposed by K.Genser (FNAL)
bin = std::lower_bound(binVector.begin(), binVector.end(), theEnergy)
- binVector.begin() - 1;
}
return std::min(bin, numberOfNodes-2);
std::size_t bin;
if(type == T_G4PhysicsLogVector)
{
bin = size_t(std::max(G4Log(theEnergy) * invdBin - baseBin, 0.0));
}
else if(type == T_G4PhysicsLinearVector)
{
bin = size_t(std::max(theEnergy * invdBin - baseBin, 0.0));
}
else
{
// Bin location proposed by K.Genser (FNAL)
bin = std::lower_bound(binVector.begin(), binVector.end(), theEnergy) -
binVector.begin() - 1;
}
return std::min(bin, numberOfNodes - 2);
}
// ---------------------------------------------------------------
//---------------------------------------------------------------
inline size_t G4PhysicsVector::FindBin(G4double e, size_t idx) const
inline std::size_t G4PhysicsVector::FindBin(const G4double e,
const std::size_t idx) const
{
size_t id = idx;
if(e < binVector[1]) {
id = 0;
} else if(e >= binVector[numberOfNodes-2]) {
id = numberOfNodes - 2;
} else if(idx >= numberOfNodes-2 || e < binVector[idx]
|| e > binVector[idx+1]) {
id = FindBinLocation(e);
std::size_t id = idx;
// it is not possible to drop this long if below before
// PAI and diffuse elastic data models will not be improved
if(e < binVector[1])
{
id = 0;
}
else if(e >= binVector[numberOfNodes - 2])
{
id = numberOfNodes - 2;
}
else if(idx > numberOfNodes - 2 || e < binVector[idx] ||
e > binVector[idx + 1])
{
id = FindBinLocation(e);
}
return id;
}
// ---------------------------------------------------------------
//---------------------------------------------------------------
inline
size_t G4PhysicsVector::ComputeLogVectorBin(const G4double loge) const
inline std::size_t G4PhysicsVector::ComputeLogVectorBin(
const G4double loge) const
{
return size_t(std::max(0., std::min(loge*invdBin-baseBin, numberOfNodes-2.)));
return std::size_t(
std::max(0., std::min(loge * invdBin - baseBin, numberOfNodes - 2.)));
}
// ---------------------------------------------------------------
//---------------------------------------------------------------
inline
G4double G4PhysicsVector::Value(G4double theEnergy) const
inline G4double G4PhysicsVector::Value(G4double theEnergy) const
{
size_t idx=0;
std::size_t idx = 0;
return Value(theEnergy, idx);
}
// ---------------------------------------------------------------
//---------------------------------------------------------------
inline
G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) const
inline G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) const
{
size_t idx=0;
std::size_t idx = 0;
return Value(theEnergy, idx);
}
//---------------------------------------------------------------
inline
G4double G4PhysicsVector::LogVectorValue(const G4double theEnergy,
const G4double theLogEnergy) const
// ---------------------------------------------------------------
inline G4double G4PhysicsVector::Interpolation(const std::size_t idx,
const G4double e) const
{
// handle cases below/above the enrgy grid (by ek, idx that gives b=0/1)
// ek = x[0] if e<=x[0] and idx will be 0 ^ b=0 => so y=y0
// ek = x[N-1] if e>=x[N-1] and idx will be N-2 ^ b=1 => so y=y_{N-1}
const G4double ek = std::max(binVector[0],
std::min(binVector[numberOfNodes-1], theEnergy));
// compute the lowerindex of the bin (idx \in [0,N-2] will be guaranted)
const size_t idx = ComputeLogVectorBin(theLogEnergy);
// perform the interpolation
const G4double x1 = binVector[idx];
const G4double x2 = binVector[idx+1];
const G4double dl = x2-x1;
const G4double dl = binVector[idx + 1] - x1;
// note: all corner cases of the previous methods are covered and eventually
// gives b=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 b = std::max(0., std::min(1., (ek - x1)/dl));
if (useSpline) { // spline interpolation
const G4double os = 0.166666666667; // 1./6.
const G4double a = 1.0 - b;
const G4double c0 = (a*a*a-a)*secDerivative[idx];
const G4double c1 = (b*b*b-b)*secDerivative[idx+1];
return a*dataVector[idx] + b*dataVector[idx+1] + (c0+c1)*dl*dl*os;
} else { // linear interpolation
const G4double y1 = dataVector[idx];
const G4double y2 = dataVector[idx+1];
return y1 + b*(y2-y1);
const G4double b = std::max(0., std::min(1., (e - x1) / dl));
G4double res;
if(useSpline) // spline interpolation
{
const G4double os = 0.166666666667; // 1./6.
const G4double a = 1.0 - b;
const G4double c0 = (a * a * a - a) * secDerivative[idx];
const G4double c1 = (b * b * b - b) * secDerivative[idx + 1];
res =
a * dataVector[idx] + b * dataVector[idx + 1] + (c0 + c1) * dl * dl * os;
}
else // linear interpolation
{
const G4double y1 = dataVector[idx];
const G4double y2 = dataVector[idx + 1];
res = y1 + b * (y2 - y1);
}
return res;
}
// ---------------------------------------------------------------
inline G4double G4PhysicsVector::LogVectorValue(
const G4double theEnergy, const G4double theLogEnergy) const
{
// handle cases below/above the energy grid (by ek, idx that gives b=0/1)
// ek = x[0] if e<=x[0] and idx will be 0 ^ b=0 => so y=y0
// ek = x[N-1] if e>=x[N-1] and idx will be N-2 ^ b=1 => so y=y_{N-1}
const G4double ek =
std::max(binVector[0], std::min(binVector[numberOfNodes - 1], theEnergy));
// compute the lowerindex of the bin (idx \in [0,N-2] will be guaranted)
const std::size_t idx = ComputeLogVectorBin(theLogEnergy);
return Interpolation(idx, ek);
}