Import Geant4 11.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2024-12-06 11:11:40 +01:00
parent e58e650b32
commit 32390e802b
1984 changed files with 98713 additions and 83996 deletions
@@ -73,7 +73,7 @@ class G4ConvergenceTester
inline G4double GetValueOfMinimizingFunction(std::vector<G4double> x)
{
return slope_fitting_function(x);
return slope_fitting_function(std::move(x));
}
void ComputeStatistics() { calStat(); }
@@ -64,7 +64,7 @@ class G4SimplexDownhill
private:
G4double getValue(std::vector<G4double> x)
{
return target->GetValueOfMinimizingFunction(x);
return target->GetValueOfMinimizingFunction(std::move(x));
}
void initialize();
@@ -113,12 +113,12 @@ void G4SimplexDownhill<T>::initialize()
{
std::vector<G4double> avec(numberOfVariable, 0.0);
avec[i] = 1.0;
currentSimplex[i] = avec;
currentSimplex[i] = std::move(avec);
}
// std::vector< G4double > avec ( numberOfVariable , 0.0 );
std::vector<G4double> avec(numberOfVariable, 1);
currentSimplex[numberOfVariable] = avec;
currentSimplex[numberOfVariable] = std::move(avec);
}
template <class T>
@@ -200,8 +200,6 @@ std::vector<G4double> G4SimplexDownhill<T>::getContractionPoint(
template <class T>
G4bool G4SimplexDownhill<T>::isItGoodEnough()
{
G4bool result = false;
G4double sum =
std::accumulate(currentHeights.begin(), currentHeights.end(), 0.0);
G4double average = sum / (numberOfVariable + 1);
@@ -212,11 +210,11 @@ G4bool G4SimplexDownhill<T>::isItGoodEnough()
delta += std::abs(currentHeights[i] - average);
}
if(delta / (numberOfVariable + 1) / average < max_ratio)
G4bool result = false;
if (average > 0.0)
{
result = true;
result = ((delta / (numberOfVariable + 1) / average) < max_ratio);
}
return result;
}
@@ -274,19 +272,19 @@ void G4SimplexDownhill<T>::doDownhill()
{
// EXPANSION
std::vector<G4double> expansionPoint =
getExpansionPoint(reflectionPoint, centroidPoint);
getExpansionPoint(reflectionPoint, std::move(centroidPoint));
G4double hh = getValue(expansionPoint);
if(hh <= h_L)
{
// Replace
currentSimplex[ih] = expansionPoint;
currentSimplex[ih] = std::move(expansionPoint);
// G4cout << "A" << G4endl;
}
else
{
// Replace
currentSimplex[ih] = reflectionPoint;
currentSimplex[ih] = std::move(reflectionPoint);
// G4cout << "B1" << G4endl;
}
}
@@ -295,7 +293,7 @@ void G4SimplexDownhill<T>::doDownhill()
if(h <= h_H2)
{
// Replace
currentSimplex[ih] = reflectionPoint;
currentSimplex[ih] = std::move(reflectionPoint);
// G4cout << "B2" << G4endl;
}
else
@@ -303,17 +301,17 @@ void G4SimplexDownhill<T>::doDownhill()
if(h <= h_H)
{
// Replace
currentSimplex[ih] = reflectionPoint;
currentSimplex[ih] = std::move(reflectionPoint);
// G4cout << "BC" << G4endl;
}
// CONTRACTION
std::vector<G4double> contractionPoint =
getContractionPoint(currentSimplex[ih], centroidPoint);
getContractionPoint(currentSimplex[ih], std::move(centroidPoint));
G4double hh = getValue(contractionPoint);
if(hh <= h_H)
{
// Replace
currentSimplex[ih] = contractionPoint;
currentSimplex[ih] = std::move(contractionPoint);
// G4cout << "C" << G4endl;
}
else
@@ -326,7 +324,7 @@ void G4SimplexDownhill<T>::doDownhill()
{
vec[k] = (currentSimplex[j][k] + currentSimplex[il][k]) / 2.0;
}
currentSimplex[j] = vec;
currentSimplex[j] = std::move(vec);
}
}
}
@@ -47,7 +47,7 @@ G4ChebyshevApproximation::G4ChebyshevApproximation(function pFunction, G4int n,
{
G4int i = 0, j = 0;
G4double rootSum = 0.0, cofj = 0.0;
G4double* tempFunction = new G4double[fNumber];
auto tempFunction = new G4double[fNumber];
G4double weight = 2.0 / fNumber;
G4double cof = 0.5 * weight * pi; // pi/n
@@ -93,7 +93,7 @@ G4ChebyshevApproximation::G4ChebyshevApproximation(function pFunction, G4int nx,
}
G4int i = 0, j = 0;
G4double rootSum = 0.0, cofj = 0.0;
G4double* tempFunction = new G4double[fNumber];
auto tempFunction = new G4double[fNumber];
G4double weight = 2.0 / fNumber;
G4double cof = 0.5 * weight * pi; // pi/nx
@@ -143,7 +143,7 @@ G4ChebyshevApproximation::G4ChebyshevApproximation(function pFunction,
{
G4int i = 0, j = 0;
G4double rootSum = 0.0, cofj = 0.0;
G4double* tempFunction = new G4double[fNumber];
auto tempFunction = new G4double[fNumber];
G4double weight = 2.0 / fNumber;
G4double cof = 0.5 * weight * pi; // pi/n
@@ -118,6 +118,8 @@ void G4ConvergenceTester::AddScore(G4double x)
void G4ConvergenceTester::calStat()
{
if (n == 0) return;
efficiency = G4double(nonzero_histories.size()) / n;
mean = sum / n;
@@ -223,10 +225,10 @@ void G4ConvergenceTester::calStat()
}
else
{
G4int i = G4int(nonzero_histories.size());
auto i = G4int(nonzero_histories.size());
// 5% criterion
G4int j = G4int(i * 0.05);
auto j = G4int(i * 0.05);
while(G4int(largest_scores.size()) > j)
{
largest_scores.pop_back();
@@ -623,7 +625,7 @@ void G4ConvergenceTester::check_stat_history(std::ostream& out)
second_ally[i] = fom_history[N + i];
}
pearson_r = calc_Pearson_r(G4int(N), first_ally, second_ally);
pearson_r = calc_Pearson_r(G4int(N), std::move(first_ally), std::move(second_ally));
t = pearson_r * std::sqrt((N - 2) / (1 - pearson_r * pearson_r));
if(t < 0.429318)
@@ -691,7 +693,7 @@ void G4ConvergenceTester::calc_slope_fit(const std::vector<G4double>&)
{
// create PDF bins
G4double max = largest_scores.front();
G4int last = G4int(largest_scores.size());
auto last = G4int(largest_scores.size());
G4double min = 0.0;
if(largest_scores.back() != 0)
{
@@ -65,7 +65,7 @@ G4DataInterpolation::G4DataInterpolation(G4double pX[], G4double pY[],
G4int i = 0;
G4double p = 0.0, qn = 0.0, sig = 0.0, un = 0.0;
const G4double maxDerivative = 0.99e30;
G4double* u = new G4double[fNumber - 1];
auto u = new G4double[fNumber - 1];
for(i = 0; i < fNumber; ++i)
{
@@ -152,8 +152,8 @@ G4double G4DataInterpolation::PolynomInterpolation(G4double pX,
G4int i = 0, j = 1, k = 0;
G4double mult = 0.0, difi = 0.0, deltaLow = 0.0, deltaUp = 0.0, cd = 0.0,
y = 0.0;
G4double* c = new G4double[fNumber];
G4double* d = new G4double[fNumber];
auto c = new G4double[fNumber];
auto d = new G4double[fNumber];
G4double diff = std::fabs(pX - fArgument[0]);
for(i = 0; i < fNumber; ++i)
{
@@ -205,7 +205,7 @@ void G4DataInterpolation::PolIntCoefficient(G4double cof[]) const
G4int i = 0, j = 0;
G4double factor;
G4double reducedY = 0.0, mult = 1.0;
G4double* tempArgument = new G4double[fNumber];
auto tempArgument = new G4double[fNumber];
for(i = 0; i < fNumber; ++i)
{
@@ -252,8 +252,8 @@ G4double G4DataInterpolation::RationalPolInterpolation(G4double pX,
G4int i = 0, j = 1, k = 0;
const G4double tolerance = 1.6e-24;
G4double mult = 0.0, difi = 0.0, cd = 0.0, y = 0.0, cof = 0.0;
G4double* c = new G4double[fNumber];
G4double* d = new G4double[fNumber];
auto c = new G4double[fNumber];
auto d = new G4double[fNumber];
G4double diff = std::fabs(pX - fArgument[0]);
for(i = 0; i < fNumber; ++i)
{
@@ -31,6 +31,8 @@
#include "G4GaussHermiteQ.hh"
#include "G4PhysicalConstants.hh"
#include <limits>
// ----------------------------------------------------------
//
// Constructor for Gauss-Hermite
@@ -87,7 +89,12 @@ G4GaussHermiteQ::G4GaussHermiteQ(function pFunction, G4int nHermite)
}
temp = std::sqrt((G4double) 2 * nHermite) * temp2;
newton1 = newton0;
newton0 = newton1 - temp1 / temp;
G4double ratio = std::numeric_limits<G4double>::max();
if(temp > 0.0)
{
ratio = temp1 / temp;
}
newton0 = newton1 - ratio;
if(std::fabs(newton0 - newton1) <= tolerance)
{
break;
+51
View File
@@ -6,6 +6,57 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2024-11-22 Gabriele Cosmo (global-V11-02-26)
- Updated tag IDs for geant4-11-03-ref-00.
## 2024-11-15 Gabriele Cosmo (global-V11-02-25)
- Updated tag IDs for geant4-11-03-cand-01.
## 2024-11-08 Gabriele Cosmo (global-V11-02-24)
- Updated tag IDs for geant4-11-03-cand-00.
## 2024-11-07 Ben Morgan (global-V11-02-23)
- Address Coverity reports:
- 104990: Use of std:move to avoid copy
- 105615: Refactor expression to avoid divide-by-zero (possible false positive)
- 105642: Refactor expression to avoid divide-by-zero (possible false positive)
## 2024-11-04 Philippe Canal (global-V11-02-22)
- Improve stability of static initialization: ensure unique initialization
and finalization of G4ios.
## 2024-10-30 Gabriele Cosmo (global-V11-02-21)
- Updated tag IDs for geant4-11-02-ref-09.
## 2024-10-28 Makoto Asai (global-V11-02-20)
- Added G4AllocatorList::Report() for monitoring G4Allocator objects.
## 2024-09-26 Ben Morgan (global-V11-02-19)
- Move flushing of G4cout etc to G4iosFinalization, attempting to resolve
possible static destruction issue reported by ATLAS.
- https://its.cern.ch/jira/browse/SIM-839
## 2024-09-25 Gabriele Cosmo (global-V11-02-18)
- Added protection in G4ConvergenceTester::calStat() in case of zero histories.
- Updated tag IDs for geant4-11-02-ref-08.
## 2024-08-28 Gabriele Cosmo (global-V11-02-17)
- Updated tag IDs for geant4-11-02-ref-07.
## 2024-07-19 Ben Morgan (global-V11-02-16)
- Fix remaining Coverity defects missed in -15.
- Move std::move
- Restructure division-by-zero in G4SimplexDownhill
## 2024-07-15 Ben Morgan (global-V11-02-15)
- Address Coverity issues from latest monthly run.
- Use of std:move to avoid copies
- Avoid potential division-by-zero in G4SimplexDownhill
- Fixup new clang-tidy warnings.
## 2024-06-28 Ben Morgan (global-V11-02-14)
- Update G4TBBTaskGroup for changes to underlying PTL API
## 2024-06-28 Gabriele Cosmo (global-V11-02-13)
- Updated tag IDs for geant4-11-02-ref-06.
@@ -49,6 +49,7 @@ class G4AllocatorList
~G4AllocatorList();
void Register(G4AllocatorBase*);
void Destroy(G4int nStat = 0, G4int verboseLevel = 0);
void Report(G4bool itemize = true) const;
inline std::size_t Size() const;
private:
@@ -38,20 +38,8 @@
#pragma once
#ifndef G4GMAKE
# include "G4GlobalConfig.hh"
#endif
#include "PTL/TaskGroup.hh"
#if defined(GEANT4_USE_TBB)
# include "PTL/TBBTaskGroup.hh"
#else
# include "PTL/TaskGroup.hh"
#endif
#if defined(GEANT4_USE_TBB)
template <typename Tp, typename Arg = Tp>
using G4TBBTaskGroup = PTL::TBBTaskGroup<Tp, Arg>;
#else
// in new version, TaskGroup handles TBB
template <typename Tp, typename Arg = Tp>
using G4TBBTaskGroup = PTL::TaskGroup<Tp, Arg>;
#endif
@@ -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 06
#define G4VERSION_REFERENCE_TAG 00
#endif
#ifndef G4VERSION_TAG
#define G4VERSION_TAG "$Name: geant4-11-03-beta-01 $"
#define G4VERSION_TAG "$Name: geant4-11-03 $"
#endif
// as variables
@@ -68,10 +68,10 @@
#include "G4Types.hh"
#ifdef G4MULTITHREADED
static const G4String G4Version = "$Name: geant4-11-03-beta-01 [MT]$";
static const G4String G4Version = "$Name: geant4-11-03 [MT]$";
#else
static const G4String G4Version = "$Name: geant4-11-03-beta-01 $";
static const G4String G4Version = "$Name: geant4-11-03 $";
#endif
static const G4String G4Date = "(28-June-2024)";
static const G4String G4Date = "(6-December-2024)";
#endif
@@ -105,3 +105,30 @@ void G4AllocatorList::Destroy(G4int nStat, G4int verboseLevel)
}
fList.clear();
}
void G4AllocatorList::Report(G4bool itemize) const
{
auto itr = fList.cbegin();
G4int j = 0;
G4double mem = 0, tmem = 0;
G4cout << "================== Current memory pools ==================="
<< G4endl;
for(; itr != fList.cend(); ++itr)
{
mem = (*itr)->GetAllocatedSize();
++j;
tmem += mem;
if(itemize)
{
G4cout << "Pool ID '" << (*itr)->GetPoolType()
<< "', size : " << std::setprecision(3) << mem / 1048576
<< std::setprecision(6) << " MB" << G4endl;
}
}
G4cout << "Number of memory pools allocated: " << Size() << G4endl;
G4cout << "Dynamic pools : " << j
<< " / Total memory : " << std::setprecision(2)
<< tmem / 1048576 << std::setprecision(6) << " MB" << G4endl;
G4cout << "============================================================"
<< G4endl;
}
@@ -42,7 +42,7 @@ class G4BuffercoutDestination::BufferImpl
public:
explicit BufferImpl(std::size_t maxSize) : m_maxSize(maxSize) {}
explicit BufferImpl(std::size_t maxSize, FlushFn_t&& f) : m_maxSize(maxSize), m_flushFn(f) {}
explicit BufferImpl(std::size_t maxSize, FlushFn_t&& f) : m_maxSize(maxSize), m_flushFn(std::move(f)) {}
~BufferImpl() = default;
+3 -3
View File
@@ -52,10 +52,10 @@ G4bool G4DataVector::Store(std::ofstream& fOut, G4bool ascii)
}
// Binary Mode
G4int sizeV = G4int(size());
auto sizeV = G4int(size());
fOut.write((char*) (&sizeV), sizeof sizeV);
G4double* value = new G4double[sizeV];
auto value = new G4double[sizeV];
std::size_t i = 0;
for(auto itr = cbegin(); itr != cend(); ++itr, ++i)
{
@@ -108,7 +108,7 @@ G4bool G4DataVector::Retrieve(std::ifstream& fIn, G4bool ascii)
// retrieve in binary mode
fIn.read((char*) (&sizeV), sizeof sizeV);
G4double* value = new G4double[sizeV];
auto value = new G4double[sizeV];
fIn.read((char*) (value), sizeV * (sizeof(G4double)));
if(G4int(fIn.gcount()) != G4int(sizeV * (sizeof(G4double))))
{
@@ -88,7 +88,7 @@ G4bool G4OrderedTable::Store(const G4String& fileName, G4bool ascii)
return false;
}
G4int tableSize = G4int(size()); // Number of elements
auto tableSize = G4int(size()); // Number of elements
if(!ascii)
{
fOut.write((char*) (&tableSize), sizeof tableSize);
@@ -71,7 +71,7 @@ G4bool G4PhysicsVector::Store(std::ofstream& fOut, G4bool ascii) const
std::size_t size = dataVector.size();
fOut.write((char*) (&size), sizeof size);
G4double* value = new G4double[2 * size];
auto value = new G4double[2 * size];
for (std::size_t i = 0; i < size; ++i)
{
value[2 * i] = binVector[i];
@@ -104,7 +104,7 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
G4int siz0 = 0;
fIn >> siz0;
if (siz0 < 2) { return false; }
std::size_t siz = static_cast<std::size_t>(siz0);
auto siz = static_cast<std::size_t>(siz0);
if (fIn.fail() || siz != numberOfNodes)
{
return false;
@@ -140,7 +140,7 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
std::size_t size;
fIn.read((char*) (&size), sizeof size);
G4double* value = new G4double[2 * size];
auto value = new G4double[2 * size];
fIn.read((char*) (value), 2 * size * (sizeof(G4double)));
if (static_cast<G4int>(fIn.gcount()) != static_cast<G4int>(2 * size * (sizeof(G4double))))
{
@@ -295,7 +295,7 @@ void G4PhysicsVector::ComputeSecDerivative1()
// World Scientific, 2000
{
std::size_t n = numberOfNodes - 1;
G4double* u = new G4double[n];
auto u = new G4double[n];
G4double p, sig;
u[1] = ((dataVector[2] - dataVector[1]) / (binVector[2] - binVector[1]) -
@@ -362,7 +362,7 @@ void G4PhysicsVector::ComputeSecDerivative2(G4double firstPointDerivative,
// Cambridge University Press, 1997.
{
std::size_t n = numberOfNodes - 1;
G4double* u = new G4double[n];
auto u = new G4double[n];
G4double p, sig, un;
u[0] = (6.0 / (binVector[1] - binVector[0])) *
+3 -3
View File
@@ -92,7 +92,7 @@ G4Pow::G4Pow()
for(G4int i = 1; i < maxZ; ++i)
{
G4double x = G4double(i);
auto x = G4double(i);
pz13[i] = std::pow(x, onethird);
lz[i] = G4Log(x);
if(i < maxZfact)
@@ -132,7 +132,7 @@ G4double G4Pow::A13High(const G4double a, const bool invert) const
G4double res;
if(a < maxA)
{
const G4int i = static_cast<G4int>(a + 0.5);
const auto i = static_cast<G4int>(a + 0.5);
const G4double x = (a / i - 1.) * onethird;
res = pz13[i] * (1. + x - x * x * (1. - 1.666667 * x));
}
@@ -149,7 +149,7 @@ G4double G4Pow::A13High(const G4double a, const bool invert) const
G4double G4Pow::A13Low(const G4double a, const G4bool invert) const
{
G4double res;
const G4int i = static_cast<G4int>(4. * (a + 0.125));
const auto i = static_cast<G4int>(4. * (a + 0.125));
const G4double y = 0.25 * i;
const G4double x = (a / y - 1.) * onethird;
res = lowa13[i] * (1. + x - x * x * (1. - 1.666667 * x));
@@ -43,11 +43,10 @@ namespace G4coutFormatters
G4String::size_type prev_pos = 0, pos = 0;
while((pos = input.find(separator, pos)) != G4String::npos)
{
G4String substr(input.substr(prev_pos, pos - prev_pos));
output.push_back(substr);
// TBR: shouldn't be worse than push_back+move
output.emplace_back(input.substr(prev_pos, pos - prev_pos));
prev_pos = ++pos;
}
// output.push_back( input.substr(prev_pos,pos-prev_pos));
return output;
}
+42 -15
View File
@@ -52,12 +52,6 @@ class G4strstreambuf : public std::basic_streambuf<char>
~G4strstreambuf() override
{
// flushing buffer...
// std::cout is used because destination object may not be alive.
if (count != 0) {
buffer[count] = '\0';
std::cout << buffer;
}
delete[] buffer;
}
@@ -219,6 +213,11 @@ void G4iosInitialization()
void G4iosFinalization()
{
// Reverse order
// --- Flush
_G4debug_p()->flush();
_G4cout_p()->flush();
_G4cerr_p()->flush();
// --- Streams
delete _G4debug_p();
_G4debug_p() = &std::cout;
@@ -240,17 +239,41 @@ void G4iosFinalization()
# define G4coutbuf (*_G4coutbuf_p())
# define G4cerrbuf (*_G4cerrbuf_p())
// These two functions are guaranteed to be called at load and
// unload of the library containing this code.
// We want to trigger initialization at load time and
// finalization at unloading time. Directly manipulating
// the `.init/.fini` section using the `__attribute__((constructor))`
// (beside that it does not work on Windows) does not work
// where Geant4 is built with static libraries but a downstream
// package is built with shared library and has also executable
// that are linking against those shared library and directly
// to the Geant4 static libraries (for example if the executable
// code calls Geant4 directly in addition to indirectly through
// the shared library).
// In this example, the explicit `.init/.fini` manipulations are
// added twice (because the linker is asked to link with this .o
// file twice and each time needs to add the init and finalization)
// This issue appear also for the initialization on an file static
// including those declared as function static in anonymous namespace.
// To get the behavior we need (where the G4iosFinalization
// and G4iosFinalization are called exactly once), we need to
// associate the initialization with a symbol and/or mechanism that
// the linker is told to de-duplicate even in the example described
// above. So we use an extern object that is guaranteed to be only
// initialized once.
namespace
{
# ifndef WIN32
void setupG4ioSystem() __attribute__((constructor));
void cleanupG4ioSystem() __attribute__((destructor));
# endif
void setupG4ioSystem() { G4iosInitialization(); }
void cleanupG4ioSystem() { G4iosFinalization(); }
struct RAII_G4iosSystem {
RAII_G4iosSystem() {
G4iosInitialization();
}
~RAII_G4iosSystem() {
G4iosFinalization();
}
};
} // namespace
// Extern but not user reachable (anonymous type)
// We want the linker to only create one of those.
extern "C" RAII_G4iosSystem RAII_G4iosSystemObj;
#else // Sequential
@@ -263,7 +286,11 @@ std::ostream G4cout(&G4coutbuf);
std::ostream G4cerr(&G4cerrbuf);
void G4iosInitialization() {}
void G4iosFinalization() {}
void G4iosFinalization() {
G4debug.flush();
G4cout.flush();
G4cerr.flush();
}
#endif