Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -38,10 +38,6 @@
|
||||
// - 03 Mar. 1996, K.Amako: Implemented the 1st version
|
||||
// Revisions:
|
||||
// - 11 Nov. 2000, H.Kurashige: Use STL vector for dataVector and binVector
|
||||
// - 02 Apr. 2008, A.Bagulya: Added SplineInterpolation() and SetSpline()
|
||||
// - 19 Jun. 2009, V.Ivanchenko: Removed hidden bin
|
||||
// - 15 Mar. 2019 M.Novak: added Value method with the known log-energy value
|
||||
// that can avoid the log call in case of log-vectors
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsVector_hh
|
||||
#define G4PhysicsVector_hh 1
|
||||
@@ -55,175 +51,171 @@
|
||||
#include "G4ios.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
using G4PVDataVector = std::vector<G4double>;
|
||||
|
||||
class G4PhysicsVector
|
||||
{
|
||||
public:
|
||||
explicit G4PhysicsVector(G4bool spline = false);
|
||||
public:
|
||||
// Default constructor - vector will be filled via Retrieve() method
|
||||
// Free vector may be filled via InsertValue(..) method
|
||||
explicit G4PhysicsVector(G4bool spline = false);
|
||||
|
||||
G4PhysicsVector(const G4PhysicsVector&);
|
||||
G4PhysicsVector& operator=(const G4PhysicsVector&);
|
||||
// Copy constructor and assignment operator
|
||||
G4PhysicsVector(const G4PhysicsVector&) = default;
|
||||
G4PhysicsVector& operator=(const G4PhysicsVector&) = default;
|
||||
|
||||
G4bool operator==(const G4PhysicsVector& right) const;
|
||||
G4bool operator!=(const G4PhysicsVector& right) const;
|
||||
// Equality operators
|
||||
// not used operators
|
||||
G4PhysicsVector(const G4PhysicsVector&&) = delete;
|
||||
G4PhysicsVector& operator=(const G4PhysicsVector&&) = delete;
|
||||
G4bool operator==(const G4PhysicsVector& right) const = delete;
|
||||
G4bool operator!=(const G4PhysicsVector& right) const = delete;
|
||||
|
||||
virtual ~G4PhysicsVector();
|
||||
virtual ~G4PhysicsVector() = default;
|
||||
|
||||
G4double Value(G4double theEnergy, std::size_t& lastidx) const;
|
||||
// Get the cross-section/energy-loss value corresponding to the
|
||||
// given energy. An appropriate interpolation is used to calculate
|
||||
// the value. Consumer code gets changed index and may reuse it
|
||||
// for the next call to save CPU for bin location.
|
||||
inline G4double Value(const G4double energy, std::size_t& lastidx) const;
|
||||
|
||||
inline G4double LogVectorValue(const G4double theEnergy,
|
||||
const G4double theLogEnergy) const;
|
||||
// Same as the Value() method above but specialised for log-vector type.
|
||||
// Note, unlike the general Value() method above, this method will work
|
||||
// properly only in case of G4PhysicsLogVector-s.
|
||||
|
||||
inline G4double Value(G4double theEnergy) const;
|
||||
// Get the cross-section/energy-loss value corresponding to the
|
||||
// given energy. An appropriate interpolation is used to calculate
|
||||
// the value. This method is kept for backward compatibility reason,
|
||||
// it should be used instead of the previous method if bin location
|
||||
// cannot be kept thread safe
|
||||
// the value. This method should be used if bin location cannot be
|
||||
// kept in the user code.
|
||||
inline G4double Value(const G4double energy) const;
|
||||
|
||||
inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const;
|
||||
// Obsolete method to get value, 'isOutRange' is not used anymore.
|
||||
// This method is kept for the compatibility reason
|
||||
inline G4double GetValue(const G4double energy, G4bool& isOutRange) const;
|
||||
|
||||
// Same as the Value() method above but specialised for log-vector type.
|
||||
// Note, unlike the general Value() method above, this method will work
|
||||
// properly only for G4PhysicsLogVector.
|
||||
inline G4double LogVectorValue(const G4double energy,
|
||||
const G4double theLogEnergy) const;
|
||||
|
||||
// Returns the value for the specified index of the dataVector
|
||||
// The boundary check will not be done
|
||||
inline G4double operator[](const std::size_t index) const;
|
||||
// Returns the value for the specified index of the dataVector
|
||||
// The boundary check will not be done
|
||||
|
||||
inline G4double operator()(const std::size_t index) const;
|
||||
// Returns the value for the specified index of the dataVector
|
||||
// The boundary check will not be done
|
||||
|
||||
inline void PutValue(std::size_t index, G4double theValue);
|
||||
// Put 'theValue' into the dataVector specified by 'index'.
|
||||
// Put data into the vector at 'index' position.
|
||||
// Take note that the 'index' starts from '0'.
|
||||
// To fill the vector, need to beforehand construct a vector
|
||||
// by the constructor with Emin, Emax, Nbin. 'theValue' should
|
||||
// be the cross-section/energy-loss value corresponding to the
|
||||
// energy of the index
|
||||
// It is assumed that energies are already filled.
|
||||
inline void PutValue(const std::size_t index, const G4double value);
|
||||
|
||||
virtual void ScaleVector(G4double factorE, G4double factorV);
|
||||
// Scale all values of the vector and second derivatives
|
||||
// by factorV, energies by vectorE. This method may be applied
|
||||
// for example after retrieving a vector from an external file to
|
||||
// convert values into Geant4 units
|
||||
|
||||
inline G4double Energy(std::size_t index) const;
|
||||
// Returns the value in the energy specified by 'index'
|
||||
// of the energy vector. The boundary check will not be done.
|
||||
// Use this function when compute cross-section or dEdx
|
||||
// before filling the vector by PutValue()
|
||||
// Use this when compute cross-section, dEdx, or other value
|
||||
// before filling the vector by PutValue().
|
||||
inline G4double Energy(const std::size_t index) const;
|
||||
inline G4double GetLowEdgeEnergy(const std::size_t index) const;
|
||||
|
||||
// Returns the energy of the first and the last point of the vector.
|
||||
inline G4double GetMinEnergy() const;
|
||||
inline G4double GetMaxEnergy() const;
|
||||
// Returns the energy of the last point of the vector
|
||||
|
||||
G4double GetLowEdgeEnergy(std::size_t binNumber) const;
|
||||
// Obsolete method
|
||||
// Get the energy value at the low edge of the specified bin.
|
||||
// Take note that the 'binNumber' starts from '0'.
|
||||
// The boundary check will not be done
|
||||
// Returns the data of the first and the last point of the vector.
|
||||
// If the vector is empty returns zeros.
|
||||
inline G4double GetMinValue() const;
|
||||
inline G4double GetMaxValue() const;
|
||||
|
||||
inline std::size_t GetVectorLength() const;
|
||||
// Get the total length of the vector
|
||||
inline std::size_t GetVectorLength() const;
|
||||
|
||||
inline std::size_t FindBin(const G4double energy,
|
||||
const std::size_t idx) const;
|
||||
// Find low edge index of a bin for given energy.
|
||||
// Min value 0, max value VectorLength-1.
|
||||
// idx is suggested bin number from user code
|
||||
|
||||
inline std::size_t ComputeLogVectorBin(const G4double logenergy) const;
|
||||
// Computes the lower index the energy bin in case of log-vector i.e.
|
||||
// in case of vectors with equal bin widths on log-scale
|
||||
// Note, that no check on the boundary is performed
|
||||
inline std::size_t ComputeLogVectorBin(const G4double logenergy) const;
|
||||
|
||||
void FillSecondDerivatives();
|
||||
// Initialise second derivatives for Spline keeping
|
||||
// 3rd derivative continues - default algorithm.
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
|
||||
void ComputeSecDerivatives();
|
||||
// Initialise second derivatives for Spline using algorithm
|
||||
// which garantee only 1st derivative continues.
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
|
||||
void ComputeSecondDerivatives(G4double firstPointDerivative,
|
||||
G4double endPointDerivative);
|
||||
// Initialise second derivatives for Spline using
|
||||
// user defined 1st derivatives at edge points.
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
|
||||
G4double FindLinearEnergy(G4double rand) const;
|
||||
// Find energy using linear interpolation for vector
|
||||
// filled by cumulative probability function
|
||||
// value of rand should be between 0 and 1
|
||||
|
||||
inline G4bool IsFilledVectorExist() const;
|
||||
// Is non-empty physics vector already exist?
|
||||
|
||||
// Get physics vector type.
|
||||
inline G4PhysicsVectorType GetType() const;
|
||||
// Get physics vector type
|
||||
|
||||
inline void SetSpline(G4bool);
|
||||
// Activate/deactivate Spline interpolation
|
||||
|
||||
// True if using spline interpolation.
|
||||
inline G4bool GetSpline() const;
|
||||
// True if using spline interpolation
|
||||
|
||||
G4bool Store(std::ofstream& fOut, G4bool ascii = false) const;
|
||||
virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii = false);
|
||||
// To store/retrieve persistent data to/from file streams.
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
|
||||
void DumpValues(G4double unitE = 1.0, G4double unitV = 1.0) const;
|
||||
// Print vector
|
||||
|
||||
// Define verbosity level.
|
||||
inline void SetVerboseLevel(G4int value);
|
||||
|
||||
protected:
|
||||
void DeleteData();
|
||||
void CopyData(const G4PhysicsVector& vec);
|
||||
// Internal methods for allowing copy of objects
|
||||
// Find energy using linear interpolation for vector
|
||||
// filled by cumulative probability function.
|
||||
// Assuming that vector is already filled.
|
||||
inline G4double FindLinearEnergy(const G4double rand) const;
|
||||
|
||||
void PrintPutValueError(std::size_t index, G4double e1, G4double e2);
|
||||
// Find low edge index of a bin for given energy.
|
||||
// Min value 0, max value idxmax.
|
||||
std::size_t FindBin(const G4double energy, std::size_t idx) const;
|
||||
|
||||
G4PhysicsVectorType type = T_G4PhysicsVector;
|
||||
// The type of PhysicsVector (enumerator)
|
||||
// Scale all values of the vector by factorV, energies by vectorE.
|
||||
// AFter this method FillSecondDerivatives(...) should be called.
|
||||
// This method may be applied for example after retrieving a vector
|
||||
// from an external file to convert values into Geant4 units.
|
||||
void ScaleVector(const G4double factorE, const G4double factorV);
|
||||
|
||||
// This method should be called when the vector is fully filled
|
||||
// There are 3 types of second derivative computations:
|
||||
// fSplineSimple - 2d derivative continues
|
||||
// fSplineBase - 3d derivative continues (the default)
|
||||
// fSplineFixedEdges - 3d derivatives continues, 1st and last
|
||||
// derivatives are fixed
|
||||
void FillSecondDerivatives(const G4SplineType = G4SplineType::Base,
|
||||
const G4double dir1 = 0.0,
|
||||
const G4double dir2 = 0.0);
|
||||
|
||||
// This method can be applied if both energy and data values
|
||||
// grow monotonically, for example, if in this vector a
|
||||
// cumulative probability density function is stored.
|
||||
G4double GetEnergy(const G4double value) const;
|
||||
|
||||
// To store/retrieve persistent data to/from file streams.
|
||||
G4bool Store(std::ofstream& fOut, G4bool ascii = false) const;
|
||||
G4bool Retrieve(std::ifstream& fIn, G4bool ascii = false);
|
||||
|
||||
// Print vector
|
||||
friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
|
||||
void DumpValues(G4double unitE = 1.0, G4double unitV = 1.0) const;
|
||||
|
||||
protected:
|
||||
|
||||
// The default implements a free vector initialisation.
|
||||
virtual void Initialise();
|
||||
|
||||
void PrintPutValueError(std::size_t index, G4double value,
|
||||
const G4String& text);
|
||||
|
||||
private:
|
||||
|
||||
void ComputeSecDerivative0();
|
||||
void ComputeSecDerivative1();
|
||||
void ComputeSecDerivative2(const G4double firstPointDerivative,
|
||||
const G4double endPointDerivative);
|
||||
// Internal methods for computing of spline coeffitients
|
||||
|
||||
// Linear or spline interpolation.
|
||||
inline G4double Interpolation(const std::size_t idx,
|
||||
const G4double energy) const;
|
||||
|
||||
// Assuming (edgeMin <= energy <= edgeMax).
|
||||
inline std::size_t GetBin(const G4double energy) const;
|
||||
|
||||
protected:
|
||||
|
||||
G4double edgeMin = 0.0; // Energy of first point
|
||||
G4double edgeMax = 0.0; // Energy of the last point
|
||||
|
||||
G4double invdBin = 0.0; // 1/Bin width - useful only for fixed binning
|
||||
G4double baseBin = 0.0; // Set this in constructor for performance
|
||||
G4double invdBin = 0.0; // 1/Bin width for linear and log vectors
|
||||
G4double logemin = 0.0; // used only for log vector
|
||||
|
||||
G4int verboseLevel = 0;
|
||||
G4int verboseLevel = 0;
|
||||
G4int idxmax = 0;
|
||||
std::size_t numberOfNodes = 0;
|
||||
|
||||
G4PVDataVector dataVector; // Vector to keep the crossection/energyloss
|
||||
G4PVDataVector binVector; // Vector to keep energy
|
||||
G4PVDataVector secDerivative; // Vector to keep second derivatives
|
||||
G4PhysicsVectorType type = T_G4PhysicsFreeVector;
|
||||
// The type of PhysicsVector (enumerator)
|
||||
|
||||
private:
|
||||
G4bool SplinePossible();
|
||||
std::vector<G4double> binVector; // energy
|
||||
std::vector<G4double> dataVector; // crossection/energyloss
|
||||
std::vector<G4double> secDerivative; // second derivatives
|
||||
|
||||
inline std::size_t FindBinLocation(const G4double theEnergy) const;
|
||||
// Find low edge index of a bin for given energy.
|
||||
// Min value 0, max value VectorLength-1
|
||||
|
||||
inline G4double Interpolation(const std::size_t idx,
|
||||
const G4double energy) const;
|
||||
private:
|
||||
|
||||
G4bool useSpline = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user