Import Geant4 11.2.0 source tree
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "tls.hh"
|
||||
@@ -115,15 +116,15 @@ class G4StatAnalysis
|
||||
// Timing (member functions)
|
||||
inline G4double GetCpuTime() const;
|
||||
// Timing (static functions)
|
||||
static tms*& GetCpuClock()
|
||||
static tms* GetCpuClock()
|
||||
{
|
||||
G4ThreadLocalStatic tms* _instance = nullptr;
|
||||
if(!_instance)
|
||||
G4ThreadLocalStatic std::optional<tms> _instance(std::nullopt);
|
||||
if(_instance == std::nullopt)
|
||||
{
|
||||
_instance = new tms;
|
||||
times(_instance);
|
||||
_instance = tms();
|
||||
times(&_instance.value());
|
||||
}
|
||||
return _instance;
|
||||
return &_instance.value();
|
||||
}
|
||||
// Note: this above implementation was implemented in such a way as to
|
||||
// conserve memory by eliminated every instance from requiring their own
|
||||
@@ -133,7 +134,7 @@ class G4StatAnalysis
|
||||
// manually invoke in some situations
|
||||
static void ResetCpuClock()
|
||||
{
|
||||
tms*& _clock = GetCpuClock();
|
||||
tms* _clock = GetCpuClock();
|
||||
times(_clock);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,52 @@ It must **not** be used as a substitute for writing good git commit messages!
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
## 2023-11-23 Gabriele Cosmo (global-V11-01-26)
|
||||
- Updated tag IDs for geant4-11-02-ref-00.
|
||||
|
||||
## 2023-11-20 Gabriele Cosmo (global-V11-01-25)
|
||||
- Updated tag IDs for geant4-11-02-cand-02.
|
||||
|
||||
## 2023-11-17 I. Hrivnacova (global-V11-01-24)
|
||||
- Fixed memory leak in G4StatAnalysis::GetCpuClock():
|
||||
do not allocate local variable on heap.
|
||||
|
||||
## 2023-11-16 I. Hrivnacova (global-V11-01-23)
|
||||
- Fixed memory leak in G4Type[Recursive]Mutex<T> and simplified code
|
||||
by removing unused function parameter.
|
||||
|
||||
## 2023-11-13 Gabriele Cosmo (global-V11-01-22)
|
||||
- Updated tag IDs for geant4-11-02-cand-01.
|
||||
|
||||
## 2023-11-06 Gabriele Cosmo (global-V11-01-21)
|
||||
- Updated tag IDs for geant4-11-02-cand-00.
|
||||
|
||||
## 2023-11-01 Gabriele Cosmo (global-V11-01-20)
|
||||
- Fixed compilation error on macOS Apple Silicon when enabling FPE_DEBUG.
|
||||
No guarantee on the correctness of signal handling on this platform.
|
||||
Addressing problem report #2571.
|
||||
|
||||
## 2023-10-30 Gabriele Cosmo (global-V11-01-19)
|
||||
- Updated tag IDs for geant4-11-01-ref-10.
|
||||
|
||||
## 2023-09-26 Vladimir Ivantchenko (global-V11-01-18)
|
||||
- G4PhysicsVector, G4PhysicsFreeVector, G4PhysicsLogVector,
|
||||
G4PhysicsLinearVector - added extra method to support optional logarithmic
|
||||
search for bin in free vector needed for HP package update; use static_cast
|
||||
everywhere instead of C type conversion; use uniform class format.
|
||||
|
||||
## 2023-09-25 Gabriele Cosmo (global-V11-01-17)
|
||||
- Updated tag IDs for geant4-11-01-ref-09.
|
||||
|
||||
## 2023-09-05 Makoto Asai (global-V11-01-16)
|
||||
- Adding IgnoreTheIssue enum entry in G4ExceptionSeverity.hh.
|
||||
|
||||
## 2023-08-29 Gabriele Cosmo (global-V11-01-15)
|
||||
- Updated tag IDs for geant4-11-01-ref-08.
|
||||
|
||||
## 2023-07-20 Gabriele Cosmo (global-V11-01-14)
|
||||
- Updated tag IDs for geant4-11-01-ref-07.
|
||||
|
||||
## 2023-06-30 Gabriele Cosmo (global-V11-01-13)
|
||||
- Updated tag IDs for geant4-11-01-ref-06.
|
||||
|
||||
|
||||
@@ -50,8 +50,14 @@
|
||||
//
|
||||
// JustWarning
|
||||
// Just display messages.
|
||||
//
|
||||
// IgnoreTheIssue
|
||||
// No message generated.
|
||||
//
|
||||
|
||||
// Author: M.Asai, 19 August 2002
|
||||
// 05 September 2023 : IgnoreTheIssue added
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4ExceptionSeverity_hh
|
||||
#define G4ExceptionSeverity_hh 1
|
||||
@@ -62,6 +68,7 @@ enum G4ExceptionSeverity
|
||||
FatalErrorInArgument,
|
||||
RunMustBeAborted,
|
||||
EventMustBeAborted,
|
||||
JustWarning
|
||||
JustWarning,
|
||||
IgnoreTheIssue
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -256,7 +256,44 @@ static inline int fedisableexcept(unsigned int excepts)
|
||||
return (fesetenv(&fenv) ? -1 : old_excepts);
|
||||
}
|
||||
|
||||
# endif /* PPC or INTEL enabling */
|
||||
# elif(defined(__arm) || defined(__arm64) || defined(__aarch64__)) // Apple Silicon
|
||||
|
||||
# define FE_EXCEPT_SHIFT 22 // shift flags right to get masks
|
||||
# define FM_ALL_EXCEPT FE_ALL_EXCEPT >> FE_EXCEPT_SHIFT
|
||||
|
||||
static inline int feenableexcept(unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int new_excepts = (excepts & FE_ALL_EXCEPT) >> FE_EXCEPT_SHIFT,
|
||||
old_excepts; // all previous masks
|
||||
|
||||
if(fegetenv(&fenv))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
old_excepts = (fenv.__fpcr & FM_ALL_EXCEPT) << FE_EXCEPT_SHIFT;
|
||||
fenv.__fpcr = (fenv.__fpcr & ~new_excepts) | new_excepts;
|
||||
|
||||
return (fesetenv(&fenv) ? -1 : old_excepts);
|
||||
}
|
||||
|
||||
static inline int fedisableexcept(unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int still_on = ~((excepts & FE_ALL_EXCEPT) >> FE_EXCEPT_SHIFT),
|
||||
old_excepts; // previous masks
|
||||
|
||||
if(fegetenv(&fenv))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
old_excepts = (fenv.__fpcr & FM_ALL_EXCEPT) << FE_EXCEPT_SHIFT;
|
||||
fenv.__fpcr = fenv.__fpcr | still_on;
|
||||
|
||||
return (fesetenv(&fenv) ? -1 : old_excepts);
|
||||
}
|
||||
|
||||
# endif /* PPC or INTEL or Apple Silicon enabling */
|
||||
|
||||
static void TerminationSignalHandler(int sig, siginfo_t* sinfo,
|
||||
void* /* context */)
|
||||
|
||||
@@ -86,6 +86,8 @@ public:
|
||||
// If energy coincide with previously added energy then
|
||||
// this new pair is added after
|
||||
void InsertValues(const G4double energy, const G4double value);
|
||||
|
||||
void EnableLogBinSearch(const G4int n = 1);
|
||||
|
||||
// Obsolete method
|
||||
inline void PutValue(const std::size_t index,
|
||||
|
||||
@@ -92,6 +92,11 @@ public:
|
||||
inline G4double LogVectorValue(const G4double energy,
|
||||
const G4double theLogEnergy) const;
|
||||
|
||||
// Same as the Value() method above but specialised for free vector
|
||||
// with logarithmic seach of bin number
|
||||
inline G4double LogFreeVectorValue(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;
|
||||
@@ -194,6 +199,8 @@ private:
|
||||
const G4double energy) const;
|
||||
|
||||
// Assuming (edgeMin <= energy <= edgeMax).
|
||||
inline std::size_t LogBin(const G4double energy, const G4double loge) const;
|
||||
inline std::size_t BinaryBin(const G4double energy) const;
|
||||
inline std::size_t GetBin(const G4double energy) const;
|
||||
|
||||
protected:
|
||||
@@ -204,9 +211,14 @@ protected:
|
||||
G4double invdBin = 0.0; // 1/Bin width for linear and log vectors
|
||||
G4double logemin = 0.0; // used only for log vector
|
||||
|
||||
G4double iBin1 = 0.0; // 1/Bin width for scale log vector
|
||||
G4double lmin1 = 0.0; // used for log search of free vector
|
||||
|
||||
G4int verboseLevel = 0;
|
||||
std::size_t idxmax = 0;
|
||||
std::size_t imax1 = 0;
|
||||
std::size_t numberOfNodes = 0;
|
||||
std::size_t nLogNodes = 0;
|
||||
|
||||
G4PhysicsVectorType type = T_G4PhysicsFreeVector;
|
||||
// The type of PhysicsVector (enumerator)
|
||||
@@ -214,6 +226,7 @@ protected:
|
||||
std::vector<G4double> binVector; // energy
|
||||
std::vector<G4double> dataVector; // crossection/energyloss
|
||||
std::vector<G4double> secDerivative; // second derivatives
|
||||
std::vector<std::size_t> scale; // log seach
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ inline G4double G4PhysicsVector::Interpolation(const std::size_t idx,
|
||||
|
||||
G4double res = y1 + b * dy;
|
||||
|
||||
if(useSpline) // spline interpolation
|
||||
if (useSpline) // spline interpolation
|
||||
{
|
||||
const G4double c0 = (2.0 - b) * secDerivative[idx];
|
||||
const G4double c1 = (1.0 + b) * secDerivative[idx + 1];
|
||||
@@ -153,8 +153,30 @@ inline G4double G4PhysicsVector::Interpolation(const std::size_t idx,
|
||||
inline std::size_t G4PhysicsVector::ComputeLogVectorBin(
|
||||
const G4double loge) const
|
||||
{
|
||||
return std::min( static_cast<G4int>((loge - logemin) * invdBin),
|
||||
static_cast<G4int>(idxmax) );
|
||||
return static_cast<std::size_t>( std::min( static_cast<G4int>((loge - logemin) * invdBin),
|
||||
static_cast<G4int>(idxmax) ) );
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
inline std::size_t
|
||||
G4PhysicsVector::LogBin(const G4double e, const G4double loge) const
|
||||
{
|
||||
std::size_t idx =
|
||||
scale[std::min( static_cast<G4int>((loge - lmin1) * iBin1),
|
||||
static_cast<G4int>(imax1) )];
|
||||
for (; idx <= idxmax; ++idx)
|
||||
{
|
||||
if (e >= binVector[idx] && e <= binVector[idx + 1]) { break; }
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
inline std::size_t G4PhysicsVector::BinaryBin(const G4double e) const
|
||||
{
|
||||
// Bin location proposed by K.Genser (FNAL)
|
||||
return std::lower_bound(binVector.cbegin(), binVector.cend(), e) -
|
||||
binVector.cbegin() - 1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
@@ -168,14 +190,12 @@ inline std::size_t G4PhysicsVector::GetBin(const G4double e) const
|
||||
break;
|
||||
|
||||
case T_G4PhysicsLinearVector:
|
||||
bin = std::min( static_cast<G4int>((e - edgeMin) * invdBin),
|
||||
static_cast<G4int>(idxmax) );
|
||||
bin = static_cast<std::size_t>( std::min( static_cast<G4int>((e - edgeMin) * invdBin),
|
||||
static_cast<G4int>(idxmax) ) );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Bin location proposed by K.Genser (FNAL)
|
||||
bin = std::lower_bound(binVector.cbegin(), binVector.cend(), e) -
|
||||
binVector.cbegin() - 1;
|
||||
bin = (nLogNodes > 0) ? LogBin(e, G4Log(e)) : BinaryBin(e);
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
@@ -185,12 +205,12 @@ inline G4double
|
||||
G4PhysicsVector::Value(const G4double e, std::size_t& idx) const
|
||||
{
|
||||
G4double res;
|
||||
if(idx + 1 < numberOfNodes &&
|
||||
e >= binVector[idx] && e <= binVector[idx+1])
|
||||
if (idx + 1 < numberOfNodes &&
|
||||
e >= binVector[idx] && e <= binVector[idx+1])
|
||||
{
|
||||
res = Interpolation(idx, e);
|
||||
}
|
||||
else if(e > edgeMin && e < edgeMax)
|
||||
else if (e > edgeMin && e < edgeMax)
|
||||
{
|
||||
idx = GetBin(e);
|
||||
res = Interpolation(idx, e);
|
||||
@@ -202,7 +222,7 @@ G4PhysicsVector::Value(const G4double e, std::size_t& idx) const
|
||||
}
|
||||
else
|
||||
{
|
||||
res = dataVector[numberOfNodes - 1];
|
||||
res = dataVector[idxmax + 1];
|
||||
idx = idxmax;
|
||||
}
|
||||
return res;
|
||||
@@ -212,7 +232,7 @@ G4PhysicsVector::Value(const G4double e, std::size_t& idx) const
|
||||
inline G4double G4PhysicsVector::Value(G4double e) const
|
||||
{
|
||||
G4double res;
|
||||
if(e > edgeMin && e < edgeMax)
|
||||
if (e > edgeMin && e < edgeMax)
|
||||
{
|
||||
const std::size_t idx = GetBin(e);
|
||||
res = Interpolation(idx, e);
|
||||
@@ -223,7 +243,7 @@ inline G4double G4PhysicsVector::Value(G4double e) const
|
||||
}
|
||||
else
|
||||
{
|
||||
res = dataVector[numberOfNodes - 1];
|
||||
res = dataVector[idxmax + 1];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -239,18 +259,39 @@ inline G4double
|
||||
G4PhysicsVector::LogVectorValue(const G4double e, const G4double loge) const
|
||||
{
|
||||
G4double res;
|
||||
if(e > edgeMin && e < edgeMax)
|
||||
if (e > edgeMin && e < edgeMax)
|
||||
{
|
||||
const std::size_t idx = ComputeLogVectorBin(loge);
|
||||
res = Interpolation(idx, e);
|
||||
}
|
||||
else if(e <= edgeMin)
|
||||
else if (e <= edgeMin)
|
||||
{
|
||||
res = dataVector[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
res = dataVector[numberOfNodes - 1];
|
||||
res = dataVector[idxmax - 1];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
inline G4double
|
||||
G4PhysicsVector::LogFreeVectorValue(const G4double e, const G4double loge) const
|
||||
{
|
||||
G4double res;
|
||||
if (e > edgeMin && e < edgeMax)
|
||||
{
|
||||
const std::size_t idx = LogBin(e, loge);
|
||||
res = Interpolation(idx, e);
|
||||
}
|
||||
else if (e <= edgeMin)
|
||||
{
|
||||
res = dataVector[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
res = dataVector[idxmax + 1];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -121,18 +121,10 @@ using thread_unlock =
|
||||
// mutex for specific to type T:
|
||||
// G4AutoLock l(G4TypeMutex<G4Cache<T>>());
|
||||
template <typename _Tp>
|
||||
G4Mutex& G4TypeMutex(const unsigned int& _n = 0)
|
||||
G4Mutex& G4TypeMutex()
|
||||
{
|
||||
static G4Mutex* _mutex = new G4Mutex();
|
||||
if(_n == 0)
|
||||
return *_mutex;
|
||||
|
||||
static std::vector<G4Mutex*> _mutexes;
|
||||
if(_n > _mutexes.size())
|
||||
_mutexes.resize(_n, nullptr);
|
||||
if(!_mutexes[_n])
|
||||
_mutexes[_n] = new G4Mutex();
|
||||
return *(_mutexes[_n - 1]);
|
||||
static G4Mutex _mutex;
|
||||
return _mutex;
|
||||
}
|
||||
|
||||
// Helper function for getting a unique static recursive_mutex for a
|
||||
@@ -143,18 +135,10 @@ G4Mutex& G4TypeMutex(const unsigned int& _n = 0)
|
||||
// G4RecursiveAutoLock
|
||||
// l(G4TypeRecursiveMutex<G4Cache<T>>());
|
||||
template <typename _Tp>
|
||||
G4RecursiveMutex& G4TypeRecursiveMutex(const unsigned int& _n = 0)
|
||||
G4RecursiveMutex& G4TypeRecursiveMutex()
|
||||
{
|
||||
static auto* _mutex = new G4RecursiveMutex();
|
||||
if(_n == 0)
|
||||
return *(_mutex);
|
||||
|
||||
static std::vector<G4RecursiveMutex*> _mutexes;
|
||||
if(_n > _mutexes.size())
|
||||
_mutexes.resize(_n, nullptr);
|
||||
if(!_mutexes[_n])
|
||||
_mutexes[_n] = new G4RecursiveMutex();
|
||||
return *(_mutexes[_n - 1]);
|
||||
static G4RecursiveMutex _mutex;
|
||||
return _mutex;
|
||||
}
|
||||
|
||||
#if defined(G4MULTITHREADED)
|
||||
|
||||
@@ -55,11 +55,11 @@
|
||||
/// (taking December as 0, the start of new development of the next major/minor release).
|
||||
///
|
||||
#ifndef G4VERSION_REFERENCE_TAG
|
||||
#define G4VERSION_REFERENCE_TAG -1
|
||||
#define G4VERSION_REFERENCE_TAG 00
|
||||
#endif
|
||||
|
||||
#ifndef G4VERSION_TAG
|
||||
#define G4VERSION_TAG "$Name: geant4-11-02-beta-01 $"
|
||||
#define G4VERSION_TAG "$Name: geant4-11-02 $"
|
||||
#endif
|
||||
|
||||
// as variables
|
||||
@@ -68,10 +68,10 @@
|
||||
#include "G4Types.hh"
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
static const G4String G4Version = "$Name: geant4-11-02-beta-01 [MT]$";
|
||||
static const G4String G4Version = "$Name: geant4-11-02 [MT]$";
|
||||
#else
|
||||
static const G4String G4Version = "$Name: geant4-11-02-beta-01 $";
|
||||
static const G4String G4Version = "$Name: geant4-11-02 $";
|
||||
#endif
|
||||
static const G4String G4Date = "(30-June-2023)";
|
||||
static const G4String G4Date = "(8-December-2023)";
|
||||
|
||||
#endif
|
||||
|
||||
@@ -96,12 +96,15 @@ void G4Exception(const char* originOfException, const char* exceptionCode,
|
||||
G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
|
||||
<< ee_banner << G4endl;
|
||||
break;
|
||||
default:
|
||||
case JustWarning:
|
||||
G4cout << ws_banner << message.str()
|
||||
<< "*** This is just a warning message. ***" << we_banner
|
||||
<< G4endl;
|
||||
toBeAborted = false;
|
||||
break;
|
||||
default:
|
||||
toBeAborted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(toBeAborted)
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4PhysicsFreeVector.hh"
|
||||
#include "G4Exp.hh"
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4PhysicsFreeVector::G4PhysicsFreeVector(G4bool spline)
|
||||
@@ -42,7 +43,7 @@ G4PhysicsFreeVector::G4PhysicsFreeVector(G4bool spline)
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4PhysicsFreeVector::G4PhysicsFreeVector(G4int length)
|
||||
: G4PhysicsFreeVector((std::size_t)length, false)
|
||||
: G4PhysicsFreeVector(static_cast<std::size_t>(length), false)
|
||||
{}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -51,7 +52,7 @@ G4PhysicsFreeVector::G4PhysicsFreeVector(std::size_t length, G4bool spline)
|
||||
{
|
||||
numberOfNodes = length;
|
||||
|
||||
if(0 < length) {
|
||||
if (0 < length) {
|
||||
binVector.resize(numberOfNodes, 0.0);
|
||||
dataVector.resize(numberOfNodes, 0.0);
|
||||
}
|
||||
@@ -72,7 +73,7 @@ G4PhysicsFreeVector::G4PhysicsFreeVector(const std::vector<G4double>& energies,
|
||||
{
|
||||
numberOfNodes = energies.size();
|
||||
|
||||
if(numberOfNodes != values.size())
|
||||
if (numberOfNodes != values.size())
|
||||
{
|
||||
G4ExceptionDescription ed;
|
||||
ed << "The size of energy vector " << numberOfNodes << " != " << values.size();
|
||||
@@ -93,7 +94,7 @@ G4PhysicsFreeVector::G4PhysicsFreeVector(const G4double* energies,
|
||||
{
|
||||
numberOfNodes = length;
|
||||
|
||||
if(0 < numberOfNodes)
|
||||
if (0 < numberOfNodes)
|
||||
{
|
||||
binVector.resize(numberOfNodes);
|
||||
dataVector.resize(numberOfNodes);
|
||||
@@ -112,7 +113,7 @@ void G4PhysicsFreeVector::PutValues(const std::size_t index,
|
||||
const G4double e,
|
||||
const G4double value)
|
||||
{
|
||||
if(index >= numberOfNodes)
|
||||
if (index >= numberOfNodes)
|
||||
{
|
||||
PrintPutValueError(index, value, "G4PhysicsFreeVector::PutValues ");
|
||||
return;
|
||||
@@ -145,3 +146,34 @@ void G4PhysicsFreeVector::InsertValues(const G4double energy,
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4PhysicsFreeVector::EnableLogBinSearch(const G4int n)
|
||||
{
|
||||
// check if log search is applicable
|
||||
if (0 >= n || edgeMin <= 0.0 || edgeMin == edgeMax || numberOfNodes < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
nLogNodes = static_cast<std::size_t>(static_cast<G4int>(numberOfNodes)/n);
|
||||
if (nLogNodes < 3) { nLogNodes = 3; }
|
||||
scale.resize(nLogNodes, 0);
|
||||
imax1 = nLogNodes - 2;
|
||||
iBin1 = (imax1 + 1) / G4Log(edgeMax/edgeMin);
|
||||
lmin1 = G4Log(edgeMin);
|
||||
scale[0] = 0;
|
||||
scale[imax1 + 1] = idxmax;
|
||||
std::size_t j = 0;
|
||||
for (std::size_t i = 1; i <= imax1; ++i)
|
||||
{
|
||||
G4double e = edgeMin*G4Exp(i/iBin1);
|
||||
for (; j <= idxmax; ++j)
|
||||
{
|
||||
if (binVector[j] <= e && e < binVector[j+1])
|
||||
{
|
||||
scale[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@@ -47,7 +47,7 @@ G4PhysicsLinearVector::G4PhysicsLinearVector(G4double Emin, G4double Emax,
|
||||
: G4PhysicsVector(spline)
|
||||
{
|
||||
numberOfNodes = Nbin + 1;
|
||||
if(Nbin < 1 || Emin >= Emax)
|
||||
if (Nbin < 1 || Emin >= Emax)
|
||||
{
|
||||
G4ExceptionDescription ed;
|
||||
ed << "G4PhysicsLinearVector with wrong parameters: theNbin= " << Nbin
|
||||
@@ -55,7 +55,7 @@ G4PhysicsLinearVector::G4PhysicsLinearVector(G4double Emin, G4double Emax,
|
||||
G4Exception("G4PhysicsLinearVector::G4PhysicsLinearVector()", "glob03",
|
||||
FatalException, ed, "theNbins should be > 0 and Emax > Emin");
|
||||
}
|
||||
if(numberOfNodes < 2)
|
||||
if (numberOfNodes < 2)
|
||||
{
|
||||
numberOfNodes = 2;
|
||||
}
|
||||
@@ -66,10 +66,12 @@ G4PhysicsLinearVector::G4PhysicsLinearVector(G4double Emin, G4double Emax,
|
||||
binVector[0] = Emin;
|
||||
binVector[numberOfNodes - 1] = Emax;
|
||||
Initialise();
|
||||
|
||||
for(std::size_t i = 1; i <= idxmax; ++i)
|
||||
if (2 < numberOfNodes)
|
||||
{
|
||||
binVector[i] = edgeMin + i / invdBin;
|
||||
for(std::size_t i = 1; i <= idxmax; ++i)
|
||||
{
|
||||
binVector[i] = edgeMin + i / invdBin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ G4PhysicsLogVector::G4PhysicsLogVector(G4double Emin, G4double Emax,
|
||||
: G4PhysicsVector(spline)
|
||||
{
|
||||
numberOfNodes = Nbin + 1;
|
||||
if(Nbin < 2 || Emin >= Emax || Emin <= 0.0)
|
||||
if (Nbin < 2 || Emin >= Emax || Emin <= 0.0)
|
||||
{
|
||||
G4ExceptionDescription ed;
|
||||
ed << "G4PhysicsLogVector with wrong parameters: theNbin= " << Nbin
|
||||
@@ -57,7 +57,7 @@ G4PhysicsLogVector::G4PhysicsLogVector(G4double Emin, G4double Emax,
|
||||
G4Exception("G4PhysicsLogVector::G4PhysicsLogVector()", "glob03",
|
||||
FatalException, ed, "Nbins should be > 1 and Emax > Emin > 0");
|
||||
}
|
||||
if(numberOfNodes < 3)
|
||||
if (numberOfNodes < 3)
|
||||
{
|
||||
numberOfNodes = 3;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ G4PhysicsLogVector::G4PhysicsLogVector(G4double Emin, G4double Emax,
|
||||
binVector[numberOfNodes - 1] = Emax;
|
||||
Initialise();
|
||||
|
||||
for(std::size_t i = 1; i <= idxmax; ++i)
|
||||
for (std::size_t i = 1; i <= idxmax; ++i)
|
||||
{
|
||||
binVector[i] = edgeMin*G4Exp(i / invdBin);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ void G4PhysicsLogVector::Initialise()
|
||||
{
|
||||
idxmax = numberOfNodes - 2;
|
||||
edgeMin = binVector[0];
|
||||
edgeMax = binVector[numberOfNodes - 1];
|
||||
edgeMax = binVector[idxmax + 1];
|
||||
invdBin = (idxmax + 1) / G4Log(edgeMax/edgeMin);
|
||||
logemin = G4Log(edgeMin);
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ G4PhysicsVector::G4PhysicsVector(G4bool val)
|
||||
// --------------------------------------------------------------------
|
||||
void G4PhysicsVector::Initialise()
|
||||
{
|
||||
idxmax = numberOfNodes - 2;
|
||||
if(0 < numberOfNodes)
|
||||
if (1 < numberOfNodes)
|
||||
{
|
||||
idxmax = numberOfNodes - 2;
|
||||
edgeMin = binVector[0];
|
||||
edgeMax = binVector[numberOfNodes - 1];
|
||||
edgeMax = binVector[idxmax + 1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void G4PhysicsVector::Initialise()
|
||||
G4bool G4PhysicsVector::Store(std::ofstream& fOut, G4bool ascii) const
|
||||
{
|
||||
// Ascii mode
|
||||
if(ascii)
|
||||
if (ascii)
|
||||
{
|
||||
fOut << *this;
|
||||
return true;
|
||||
@@ -72,7 +72,7 @@ G4bool G4PhysicsVector::Store(std::ofstream& fOut, G4bool ascii) const
|
||||
fOut.write((char*) (&size), sizeof size);
|
||||
|
||||
G4double* value = new G4double[2 * size];
|
||||
for(std::size_t i = 0; i < size; ++i)
|
||||
for (std::size_t i = 0; i < size; ++i)
|
||||
{
|
||||
value[2 * i] = binVector[i];
|
||||
value[2 * i + 1] = dataVector[i];
|
||||
@@ -92,18 +92,20 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
secDerivative.clear();
|
||||
|
||||
// retrieve in ascii mode
|
||||
if(ascii)
|
||||
if (ascii)
|
||||
{
|
||||
// binning
|
||||
fIn >> edgeMin >> edgeMax >> numberOfNodes;
|
||||
if(fIn.fail() || numberOfNodes < 2)
|
||||
if (fIn.fail() || numberOfNodes < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// contents
|
||||
G4int siz = 0;
|
||||
fIn >> siz;
|
||||
if(fIn.fail() || siz != G4int(numberOfNodes))
|
||||
G4int siz0 = 0;
|
||||
fIn >> siz0;
|
||||
if (siz0 < 2) { return false; }
|
||||
std::size_t siz = static_cast<std::size_t>(siz0);
|
||||
if (fIn.fail() || siz != numberOfNodes)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -112,12 +114,12 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
dataVector.reserve(siz);
|
||||
G4double vBin, vData;
|
||||
|
||||
for(G4int i = 0; i < siz; ++i)
|
||||
for (std::size_t i = 0; i < siz; ++i)
|
||||
{
|
||||
vBin = 0.;
|
||||
vData = 0.;
|
||||
fIn >> vBin >> vData;
|
||||
if(fIn.fail())
|
||||
if (fIn.fail())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -140,7 +142,7 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
|
||||
G4double* value = new G4double[2 * size];
|
||||
fIn.read((char*) (value), 2 * size * (sizeof(G4double)));
|
||||
if(G4int(fIn.gcount()) != G4int(2 * size * (sizeof(G4double))))
|
||||
if (static_cast<G4int>(fIn.gcount()) != static_cast<G4int>(2 * size * (sizeof(G4double))))
|
||||
{
|
||||
delete[] value;
|
||||
return false;
|
||||
@@ -148,7 +150,7 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
|
||||
binVector.reserve(size);
|
||||
dataVector.reserve(size);
|
||||
for(std::size_t i = 0; i < size; ++i)
|
||||
for (std::size_t i = 0; i < size; ++i)
|
||||
{
|
||||
binVector.push_back(value[2 * i]);
|
||||
dataVector.push_back(value[2 * i + 1]);
|
||||
@@ -162,7 +164,7 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
// --------------------------------------------------------------
|
||||
void G4PhysicsVector::DumpValues(G4double unitE, G4double unitV) const
|
||||
{
|
||||
for(std::size_t i = 0; i < numberOfNodes; ++i)
|
||||
for (std::size_t i = 0; i < numberOfNodes; ++i)
|
||||
{
|
||||
G4cout << binVector[i] / unitE << " " << dataVector[i] / unitV
|
||||
<< G4endl;
|
||||
@@ -173,16 +175,16 @@ void G4PhysicsVector::DumpValues(G4double unitE, G4double unitV) const
|
||||
std::size_t G4PhysicsVector::FindBin(const G4double energy,
|
||||
std::size_t idx) const
|
||||
{
|
||||
if(idx + 1 < numberOfNodes &&
|
||||
energy >= binVector[idx] && energy <= binVector[idx])
|
||||
if (idx + 1 < numberOfNodes &&
|
||||
energy >= binVector[idx] && energy <= binVector[idx])
|
||||
{
|
||||
return idx;
|
||||
}
|
||||
if(energy <= binVector[1])
|
||||
if (energy <= binVector[1])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(energy >= binVector[idxmax])
|
||||
if (energy >= binVector[idxmax])
|
||||
{
|
||||
return idxmax;
|
||||
}
|
||||
@@ -193,7 +195,7 @@ std::size_t G4PhysicsVector::FindBin(const G4double energy,
|
||||
void G4PhysicsVector::ScaleVector(const G4double factorE,
|
||||
const G4double factorV)
|
||||
{
|
||||
for(std::size_t i = 0; i < numberOfNodes; ++i)
|
||||
for (std::size_t i = 0; i < numberOfNodes; ++i)
|
||||
{
|
||||
binVector[i] *= factorE;
|
||||
dataVector[i] *= factorV;
|
||||
@@ -206,12 +208,12 @@ void G4PhysicsVector::FillSecondDerivatives(const G4SplineType stype,
|
||||
const G4double dir1,
|
||||
const G4double dir2)
|
||||
{
|
||||
if(!useSpline) { return; }
|
||||
if (!useSpline) { return; }
|
||||
// cannot compute derivatives for less than 5 points
|
||||
const std::size_t nmin = (stype == G4SplineType::Base) ? 5 : 4;
|
||||
if(nmin > numberOfNodes)
|
||||
if (nmin > numberOfNodes)
|
||||
{
|
||||
if(0 < verboseLevel)
|
||||
if (0 < verboseLevel)
|
||||
{
|
||||
G4cout << "### G4PhysicsVector: spline cannot be used for "
|
||||
<< numberOfNodes << " points - spline disabled"
|
||||
@@ -222,13 +224,13 @@ void G4PhysicsVector::FillSecondDerivatives(const G4SplineType stype,
|
||||
return;
|
||||
}
|
||||
// check energies of free vector
|
||||
if(type == T_G4PhysicsFreeVector)
|
||||
if (type == T_G4PhysicsFreeVector)
|
||||
{
|
||||
for(std::size_t i=0; i<=idxmax; ++i)
|
||||
for (std::size_t i=0; i<=idxmax; ++i)
|
||||
{
|
||||
if(binVector[i + 1] <= binVector[i])
|
||||
if (binVector[i + 1] <= binVector[i])
|
||||
{
|
||||
if(0 < verboseLevel)
|
||||
if (0 < verboseLevel)
|
||||
{
|
||||
G4cout << "### G4PhysicsVector: spline cannot be used, because "
|
||||
<< " E[" << i << "]=" << binVector[i]
|
||||
@@ -246,7 +248,7 @@ void G4PhysicsVector::FillSecondDerivatives(const G4SplineType stype,
|
||||
Initialise();
|
||||
secDerivative.resize(numberOfNodes);
|
||||
|
||||
if(1 < verboseLevel)
|
||||
if (1 < verboseLevel)
|
||||
{
|
||||
G4cout << "### G4PhysicsVector:: FillSecondDerivatives N="
|
||||
<< numberOfNodes << G4endl;
|
||||
@@ -274,7 +276,7 @@ void G4PhysicsVector::ComputeSecDerivative0()
|
||||
{
|
||||
std::size_t n = numberOfNodes - 1;
|
||||
|
||||
for(std::size_t i = 1; i < n; ++i)
|
||||
for (std::size_t i = 1; i < n; ++i)
|
||||
{
|
||||
secDerivative[i] = 3.0 *
|
||||
((dataVector[i + 1] - dataVector[i]) / (binVector[i + 1] - binVector[i]) -
|
||||
@@ -336,7 +338,7 @@ void G4PhysicsVector::ComputeSecDerivative1()
|
||||
// The back-substitution loop for the triagonal algorithm of solving
|
||||
// a linear system of equations.
|
||||
|
||||
for(std::size_t k = n - 2; k > 1; --k)
|
||||
for (std::size_t k = n - 2; k > 1; --k)
|
||||
{
|
||||
secDerivative[k] *=
|
||||
(secDerivative[k + 1] - u[k] * (binVector[k + 1] - binVector[k - 1]) /
|
||||
@@ -372,7 +374,7 @@ void G4PhysicsVector::ComputeSecDerivative2(G4double firstPointDerivative,
|
||||
// Decomposition loop for tridiagonal algorithm. secDerivative[i]
|
||||
// and u[i] are used for temporary storage of the decomposed factors.
|
||||
|
||||
for(std::size_t i = 1; i < n; ++i)
|
||||
for (std::size_t i = 1; i < n; ++i)
|
||||
{
|
||||
sig =
|
||||
(binVector[i] - binVector[i - 1]) / (binVector[i + 1] - binVector[i - 1]);
|
||||
@@ -397,7 +399,7 @@ void G4PhysicsVector::ComputeSecDerivative2(G4double firstPointDerivative,
|
||||
// The back-substitution loop for the triagonal algorithm of solving
|
||||
// a linear system of equations.
|
||||
|
||||
for(std::size_t k = n - 1; k > 0; --k)
|
||||
for (std::size_t k = n - 1; k > 0; --k)
|
||||
{
|
||||
secDerivative[k] *=
|
||||
(secDerivative[k + 1] - u[k] * (binVector[k + 1] - binVector[k - 1]) /
|
||||
@@ -418,7 +420,7 @@ std::ostream& operator<<(std::ostream& out, const G4PhysicsVector& pv)
|
||||
|
||||
// contents
|
||||
out << pv.dataVector.size() << G4endl;
|
||||
for(std::size_t i = 0; i < pv.dataVector.size(); ++i)
|
||||
for (std::size_t i = 0; i < pv.dataVector.size(); ++i)
|
||||
{
|
||||
out << pv.binVector[i] << " " << pv.dataVector[i] << G4endl;
|
||||
}
|
||||
@@ -430,24 +432,24 @@ std::ostream& operator<<(std::ostream& out, const G4PhysicsVector& pv)
|
||||
//---------------------------------------------------------------
|
||||
G4double G4PhysicsVector::GetEnergy(const G4double val) const
|
||||
{
|
||||
if(0 == numberOfNodes)
|
||||
if (0 == numberOfNodes)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
if(1 == numberOfNodes || val <= dataVector[0])
|
||||
if (1 == numberOfNodes || val <= dataVector[0])
|
||||
{
|
||||
return edgeMin;
|
||||
}
|
||||
if(val >= dataVector[numberOfNodes - 1])
|
||||
if (val >= dataVector[numberOfNodes - 1])
|
||||
{
|
||||
return edgeMax;
|
||||
}
|
||||
std::size_t bin = std::lower_bound(dataVector.cbegin(), dataVector.cend(), val)
|
||||
- dataVector.cbegin() - 1;
|
||||
if(bin > idxmax) { bin = idxmax; }
|
||||
if (bin > idxmax) { bin = idxmax; }
|
||||
G4double res = binVector[bin];
|
||||
G4double del = dataVector[bin + 1] - dataVector[bin];
|
||||
if(del > 0.0)
|
||||
if (del > 0.0)
|
||||
{
|
||||
res += (val - dataVector[bin]) * (binVector[bin + 1] - res) / del;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user