Import Geant4 11.4.0.beta source tree
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4VSIntegration
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// Numerical algorithm for integration of probability density function
|
||||
// and sampling of the energy. Parameters of the algorithm should
|
||||
// be defined by consumer class via the InitialiseIntegrator(..) method.
|
||||
// The method is effective for the case of functions with a peak and long
|
||||
// tail. Tunning of parameters may increase efficiency of the algorithm.
|
||||
// The default set of parameters is optimized for the pre-compound model.
|
||||
//
|
||||
// Created 03.03.2025 V.Ivanchenko
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#ifndef G4VSIntegration_HH
|
||||
#define G4VSIntegration_HH 1
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
class G4VSIntegration
|
||||
{
|
||||
public:
|
||||
G4VSIntegration() = default;
|
||||
|
||||
virtual ~G4VSIntegration() = default;
|
||||
|
||||
// this method should be implemented in a consumer class
|
||||
virtual G4double ProbabilityDensityFunction(G4double) = 0;
|
||||
|
||||
virtual const G4String& ModelName() const;
|
||||
|
||||
// initialisation before run called once
|
||||
// accuracy - accuracy of integration
|
||||
// fact1 - value < 1 to define energy E1: Pmax*fact = P(E1)
|
||||
// and E2: P(E1)*fact = P(E2)
|
||||
// fact2 - value > 1 provides tolerance for max cross section
|
||||
// deltaE - the default step in energy
|
||||
// dmin, dmax - min and max values of step
|
||||
void InitialiseIntegrator(G4double accuracy, G4double fact1, G4double fact2,
|
||||
G4double de, G4double dmin, G4double dmax);
|
||||
|
||||
// compute integral of probability density function
|
||||
G4double ComputeIntegral(const G4double emin, const G4double emax);
|
||||
|
||||
// sample value according to probability density function
|
||||
// it is assumed that ComputeIntegral(emin, emax) was executed
|
||||
G4double SampleValue();
|
||||
|
||||
G4VSIntegration(const G4VSIntegration&) = delete;
|
||||
G4VSIntegration& operator=(const G4VSIntegration&) = delete;
|
||||
G4bool operator==(const G4VSIntegration &right) const = delete;
|
||||
G4bool operator!=(const G4VSIntegration &right) const = delete;
|
||||
|
||||
void SetVerbose(G4int verb) { fVerbose = verb; }
|
||||
|
||||
private:
|
||||
|
||||
G4double fAcc{0.001}; // accuracy of integration
|
||||
G4double fMinDelta{0.1}; // minimal step integration
|
||||
G4double fMaxDelta{2.0}; // maximal step integration
|
||||
G4double fDelta{1.0}; // the default step
|
||||
G4double fFactor1{0.25};
|
||||
G4double fFactor2{1.05};
|
||||
|
||||
// parameters describing function
|
||||
G4double fEmin{0.0};
|
||||
G4double fEmax{0.0};
|
||||
G4double fE1{0.0};
|
||||
G4double fP1{0.0};
|
||||
G4double fE2{0.0};
|
||||
G4double fP2{0.0};
|
||||
G4double fPmax{0.0};
|
||||
|
||||
G4int fVerbose{0};
|
||||
G4int fWarnLimit{4};
|
||||
G4int fnWarn{0};
|
||||
|
||||
G4String dummy{""};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -23,6 +23,7 @@ geant4_add_module(G4hepnumerics
|
||||
G4StatAnalysis.hh
|
||||
G4StatAnalysis.icc
|
||||
G4VGaussianQuadrature.hh
|
||||
G4VSIntegration.hh
|
||||
SOURCES
|
||||
G4AnalyticalPolSolver.cc
|
||||
G4ChebyshevApproximation.cc
|
||||
@@ -36,6 +37,11 @@ geant4_add_module(G4hepnumerics
|
||||
G4JTPolynomialSolver.cc
|
||||
G4SimpleIntegration.cc
|
||||
G4StatDouble.cc
|
||||
G4VGaussianQuadrature.cc)
|
||||
G4VGaussianQuadrature.cc
|
||||
G4VSIntegration.cc)
|
||||
|
||||
geant4_module_link_libraries(G4hepnumerics PUBLIC G4globman)
|
||||
geant4_module_link_libraries(G4hepnumerics
|
||||
PUBLIC
|
||||
G4globman
|
||||
PRIVATE
|
||||
G4heprandom)
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4VSIntegration
|
||||
//
|
||||
// Created 03.03.2025 V.Ivanchenko
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4VSIntegration.hh"
|
||||
#include "Randomize.hh"
|
||||
#include "G4Log.hh"
|
||||
|
||||
void
|
||||
G4VSIntegration::InitialiseIntegrator(G4double acc, G4double f1, G4double f2,
|
||||
G4double de, G4double dmin, G4double dmax)
|
||||
{
|
||||
if (acc > 0.0) { fAcc = acc; }
|
||||
if (f1 > 0.0 && f1 < 1.0) { fFactor1 = f1; }
|
||||
if (f2 > 1.0 && f2 < 5.0) { fFactor2 = f2; }
|
||||
if (de > 0.0) { fDelta = de; }
|
||||
fMinDelta = (dmin <= de && dmin > 0.0) ? dmin : de;
|
||||
fMaxDelta = (dmax > de) ? dmax : de;
|
||||
if (fVerbose > 2) {
|
||||
G4cout << "### G4VSIntegration::InitialiseIntegrator: "
|
||||
<< "fAcc=" << fAcc << " fFact1=" << fFactor1
|
||||
<< " fFact2=" << fFactor2 << " dE=" << fDelta
|
||||
<< " dEmin=" << fMinDelta << " dEmax=" << fMaxDelta << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
G4double
|
||||
G4VSIntegration::ComputeIntegral(const G4double emin, const G4double emax)
|
||||
{
|
||||
G4double res = 0.0;
|
||||
if (emin >= emax) { return res; }
|
||||
fEmin = emin;
|
||||
fEmax = emax;
|
||||
|
||||
// preparing smart binning
|
||||
G4int nbin = G4lrint((emax - emin)/fDelta) + 1;
|
||||
nbin = std::max(nbin, 4);
|
||||
G4double edelta = (emax - emin)/static_cast<G4double>(nbin);
|
||||
nbin += nbin;
|
||||
|
||||
// prepare integration
|
||||
G4double x(emin), y(0.0);
|
||||
fPmax = ProbabilityDensityFunction(x);
|
||||
G4double problast = fPmax;
|
||||
#ifdef G4VERBOSE
|
||||
if (fVerbose > 1) {
|
||||
G4cout << "### G4VSIntegration::ComputeIntegral: "
|
||||
<< "Pmax=" << fPmax << " Emin=" << emin
|
||||
<< " Emax=" << emax << " dE=" << edelta << " nbin=" << nbin
|
||||
<< G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
fE1 = fE2 = emax;
|
||||
fP1 = fP2 = 0.0;
|
||||
G4bool endpoint = false;
|
||||
x += edelta;
|
||||
for (G4int i=0; i<=nbin; ++i) {
|
||||
// the last point - may be earlier due to dynamic interval
|
||||
if (x >= emax) {
|
||||
edelta += emax - x;
|
||||
x = emax;
|
||||
endpoint = true;
|
||||
}
|
||||
y = ProbabilityDensityFunction(x);
|
||||
#ifdef G4VERBOSE
|
||||
if (fVerbose > 2) {
|
||||
G4cout << " " << i << ". E=" << x << " prob=" << y
|
||||
<< " Edel=" << edelta << G4endl;
|
||||
}
|
||||
#endif
|
||||
if (y >= fPmax) {
|
||||
fPmax = y;
|
||||
// for the case of 2nd maximum
|
||||
fP1 = fP2 = 0.0;
|
||||
fE1 = fE2 = emax;
|
||||
} else if (!endpoint) {
|
||||
if (0.0 == fP1) {
|
||||
// definition of the 2nd area
|
||||
if (y < fFactor1*fPmax) {
|
||||
fE1 = x;
|
||||
fP1 = y;
|
||||
}
|
||||
// for the case of 2nd maximum in the 2nd area
|
||||
} else if (y > fP1) {
|
||||
fP2 = 0.0;
|
||||
fP1 = y;
|
||||
fE2 = emax;
|
||||
// definition of the 3d area
|
||||
} else if (0.0 == fP2 && y < fFactor1*fP1) {
|
||||
fE2 = x;
|
||||
fP2 = y;
|
||||
// extra maximum inside the 3d area
|
||||
} else if (0.0 < fP2 && y > fP2) {
|
||||
fP2 = y;
|
||||
}
|
||||
}
|
||||
|
||||
G4double del = (y + problast)*edelta*0.5;
|
||||
res += del;
|
||||
// end of the loop
|
||||
if (del < fAcc*res || endpoint) { break; }
|
||||
problast = y;
|
||||
|
||||
// smart next step definition
|
||||
if (del != res && del > 0.8*res && 0.7*edelta > fMinDelta) {
|
||||
edelta *= 0.7;
|
||||
} else if (del < 0.1*res && 1.5*edelta < fMaxDelta) {
|
||||
edelta *= 1.5;
|
||||
}
|
||||
x += edelta;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if (fVerbose > 1) {
|
||||
G4cout << "### G4VSIntegration::ComputeIntegral: "
|
||||
<< "I=" << res << " E1=" << fE1 << " E2=" << fE2
|
||||
<< " Pmax=" << fPmax << " P1=" << fP1 << " P2=" << fP2
|
||||
<< G4endl;
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
G4double G4VSIntegration::SampleValue()
|
||||
{
|
||||
// should never happen
|
||||
if (fEmin >= fEmax) { return fEmin; }
|
||||
|
||||
fPmax *= fFactor2;
|
||||
|
||||
// two regions with flat and one with exponential majorant
|
||||
G4double b = 1.0;
|
||||
G4double p3 = 0.0;
|
||||
G4double Q3 = 0.0;
|
||||
|
||||
// 2d and 3d areas may be considered
|
||||
if (fP2 > 0.0 && fE2 < fEmax) {
|
||||
Q3 = 2*ProbabilityDensityFunction(fEmax - 0.5*(fEmax - fE2));
|
||||
// exclude 3d area from sampling
|
||||
if (4*Q3 > fP2 || Q3 <= 0.0) {
|
||||
fE2 = fEmax;
|
||||
// 3d area is considered
|
||||
} else {
|
||||
b = 2*G4Log(fP2/Q3)/(fEmax - fE2);
|
||||
p3 = (fP2 - Q3)/b;
|
||||
}
|
||||
}
|
||||
G4double p1 = (fE1 - fEmin)*fPmax;
|
||||
G4double p2 = (fE2 - fE1)*fP1;
|
||||
if (p2 < 1.e-8*p1) {
|
||||
p2 = 0.0;
|
||||
p1 = (fE2 - fEmin)*fPmax;
|
||||
fE1 = fE2;
|
||||
}
|
||||
G4double sum = p1 + p2 + p3;
|
||||
G4double del1 = (fE1 - fEmin)/p1;
|
||||
G4double del2 = (p2 > 0.0) ? (fE2 - fE1)/p2 : 0.0;
|
||||
|
||||
CLHEP::HepRandomEngine* rndm = G4Random::getTheEngine();
|
||||
const G4int nmax = 1000;
|
||||
G4double e, gmax, gg;
|
||||
G4int n = 0;
|
||||
do {
|
||||
++n;
|
||||
G4double q = rndm->flat();
|
||||
G4double p = sum*q;
|
||||
G4int idx = 0;
|
||||
if (p <= p1) {
|
||||
gmax = fPmax;
|
||||
e = del1*p + fEmin;
|
||||
} else if (p <= p1 + p2) {
|
||||
gmax = fP1;
|
||||
e = del2*(p - p1) + fE1;
|
||||
idx = 1;
|
||||
} else {
|
||||
G4double x = 1.0 - rndm->flat()*(1.0 - Q3/fP2);
|
||||
e = fE2 - G4Log(x)/b;
|
||||
gmax = fP2*x;
|
||||
idx = 2;
|
||||
}
|
||||
gg = ProbabilityDensityFunction(e);
|
||||
if ((gg > gmax || n >= nmax) && fVerbose > 0) {
|
||||
++fnWarn;
|
||||
if (fnWarn < fWarnLimit) {
|
||||
G4cout << "### G4VSIntegration::SampleValue() for " << ModelName()
|
||||
<< " in area=" << idx << " n=" << n << " gg/gmax=" << gg/gmax
|
||||
<< " prob=" << gg << " gmax=" << gmax << G4endl;
|
||||
G4cout << " E=" << e << " Emin=" << fEmin << " Emax=" << fEmax
|
||||
<< " E1=" << fE1 << " E2=" << fE2 << " Fmax=" << fPmax
|
||||
<< " F1=" << fP1 << G4endl;
|
||||
}
|
||||
}
|
||||
} while(gmax*rndm->flat() > gg && n < nmax);
|
||||
#ifdef G4VERBOSE
|
||||
if (fVerbose > 1) {
|
||||
G4cout << "### G4VSIntegration::SampleValue for " << ModelName()
|
||||
<< " E=" << e << " Ntry=" << n
|
||||
<< " Emin=" << fEmin << " Emax=" << fEmax << G4endl;
|
||||
}
|
||||
#endif
|
||||
return e;
|
||||
}
|
||||
|
||||
const G4String& G4VSIntegration::ModelName() const
|
||||
{
|
||||
return dummy;
|
||||
}
|
||||
@@ -31,13 +31,13 @@
|
||||
#include "G4Types.hh"
|
||||
#include <cstdint>
|
||||
|
||||
inline G4double G4QuickRand()
|
||||
inline G4double G4QuickRand(uint32_t seed = 0)
|
||||
{
|
||||
static const G4double f = 1. / 4294967296.; // 2^-32
|
||||
static const G4double f = 1. / 4294967296.; // 2^-32
|
||||
|
||||
// Algorithm "xor" from p.4 of G.Marsaglia, "Xorshift RNGs"
|
||||
static G4ThreadLocal uint32_t y = 2463534242;
|
||||
uint32_t x = y;
|
||||
uint32_t x = uint32_t(seed == 0) * y + seed;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
|
||||
+52
-7
@@ -6,24 +6,69 @@ It must **not** be used as a substitute for writing good git commit messages!
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
## 2025-04-09 Gabriele Cosmo (global-V11-02-28)
|
||||
- Updated tag IDs for geant4-11-03-patch-02.
|
||||
## 2025-06-26 Gabriele Cosmo (global-V11-03-16)
|
||||
- Updated tag IDs for geant4-11-03-ref-06.
|
||||
|
||||
## 2025-04-06 Alvaro Tolosa-Delgado
|
||||
## 2025-06-10 Vladimir Ivantchenko (global-V11-03-15)
|
||||
- G4VSIntegration - for 11.4beta verbose level set to zero.
|
||||
|
||||
## 2025-05-28 Gabriele Cosmo (global-V11-03-14)
|
||||
- Updated tag IDs for geant4-11-03-ref-05.
|
||||
|
||||
## 2025-05-19 Vladimir Ivantchenko (global-V11-03-13)
|
||||
- G4VSIntegration - improved warning printout by addition of model name,
|
||||
added extra protections for the case, when probability density function
|
||||
has several peaks, change upper limit on number of warnings in each instance
|
||||
of the class from 10 to 4, fixed a bug in sampling of tail of the distribution.
|
||||
|
||||
## 2025-05-15 Vladimir Ivantchenko (global-V11-03-12)
|
||||
- G4VSIntegration - improved warning printout and add a limit on
|
||||
number of warnings
|
||||
|
||||
## 2025-03-28 Gabriele Cosmo (global-V11-03-11)
|
||||
- Updated tag IDs for geant4-11-03-ref-04.
|
||||
|
||||
## 2025-04-06 Alvaro Tolosa-Delgado (global-V11-03-10)
|
||||
- Add Scintillation, Cherenkov, Transition Radiation and Synchrotron Radiation
|
||||
processes to G4PhysicsModelCatalog::Initialize()
|
||||
|
||||
## 2025-03-21 Gabriele Cosmo (global-V11-02-27)
|
||||
- Updated tag IDs for geant4-11-03-patch-01.
|
||||
## 2025-03-31 Vladimir Ivantchenko (global-V11-03-09)
|
||||
- G4VSIntegration - fixed Coverity report (cosmetics)
|
||||
|
||||
## 2025-03-20 Gabriele Cosmo
|
||||
## 2025-03-28 Gabriele Cosmo (global-V11-03-08)
|
||||
- Updated tag IDs for geant4-11-03-ref-03.
|
||||
|
||||
## 2025-03-25 Vladimir Ivantchenko (global-V11-03-07)
|
||||
- G4VSIntegration - fixed minor inaccuracy in binning
|
||||
|
||||
## 2025-03-24 Evgueni Tcherniaev (global-V11-03-06)
|
||||
- G4QuickRand: Added a possibility to set a seed.
|
||||
|
||||
## 2025-03-20 Gabriele Cosmo (global-V11-03-05)
|
||||
- In G4ThreadLocalSingleton, removed unprotected left-over debug inclusion
|
||||
of G4BackTrace header. Addressing problem report #2649.
|
||||
|
||||
## 2025-01-31 Ben Morgan
|
||||
## 2025-03-03 Vladimir Ivantchenko (global-V11-03-04)
|
||||
- G4VSIntegration - added new utility class for integration of probability
|
||||
density function and sampling of final state dynamically. This is useful
|
||||
for the case, when sampling tables cannot be prepared and stored, instead
|
||||
computations are performed for each case again and again.
|
||||
|
||||
## 2025-02-28 Gabriele Cosmo (global-V11-03-03)
|
||||
- Updated tag IDs for geant4-11-03-ref-02.
|
||||
|
||||
## 2025-01-31 Ben Morgan (global-V11-03-02)
|
||||
- Migrate `tests/` to `tests/ctests_source` for use in CI and Nightly.
|
||||
- Correct logic error in G4PhysicsTable when reading data in binary
|
||||
mode on Windows platforms, identified by migrated unit tests.
|
||||
|
||||
## 2025-01-29 Gabriele Cosmo (global-V11-03-01)
|
||||
- Updated tag IDs for geant4-11-03-ref-01.
|
||||
|
||||
## 2025-01-10 Ben Morgan (global-V11-03-00)
|
||||
- Factor common ieee754 union and helper functions out of G4Log and G4Exp to
|
||||
remove duplication.
|
||||
|
||||
## 2024-11-22 Gabriele Cosmo (global-V11-02-26)
|
||||
- Updated tag IDs for geant4-11-03-ref-00.
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
#else
|
||||
|
||||
# include "G4Types.hh"
|
||||
|
||||
# include "G4IEEE754.hh"
|
||||
# include <cstdint>
|
||||
# include <limits>
|
||||
|
||||
@@ -97,54 +97,6 @@ namespace G4ExpConsts
|
||||
|
||||
const G4float LOG2EF = 1.44269504088896341f;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Used to switch between different type of interpretations of the data
|
||||
// (64 bits)
|
||||
//
|
||||
union ieee754
|
||||
{
|
||||
ieee754()= default;
|
||||
ieee754(G4double thed) { d = thed; };
|
||||
ieee754(uint64_t thell) { ll = thell; };
|
||||
ieee754(G4float thef) { f[0] = thef; };
|
||||
ieee754(uint32_t thei) { i[0] = thei; };
|
||||
G4double d;
|
||||
G4float f[2];
|
||||
uint32_t i[2];
|
||||
uint64_t ll;
|
||||
uint16_t s[4];
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts an unsigned long long to a double
|
||||
//
|
||||
inline G4double uint642dp(uint64_t ll)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.ll = ll;
|
||||
return tmp.d;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts an int to a float
|
||||
//
|
||||
inline G4float uint322sp(G4int x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.i[0] = x;
|
||||
return tmp.f[0];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts a float to an int
|
||||
//
|
||||
inline uint32_t sp2uint32(G4float x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.f[0] = x;
|
||||
return tmp.i[0];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/**
|
||||
* A vectorisable floor implementation, not only triggered by fast-math.
|
||||
@@ -156,7 +108,7 @@ namespace G4ExpConsts
|
||||
// no problem since exp is defined between -708 and 708. Int is enough for
|
||||
// it!
|
||||
int32_t ret = int32_t(x);
|
||||
ret -= (sp2uint32(x) >> 31);
|
||||
ret -= (G4IEEE754::sp2uint32(x) >> 31);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -169,7 +121,7 @@ namespace G4ExpConsts
|
||||
inline G4float fpfloor(const G4float x)
|
||||
{
|
||||
int32_t ret = int32_t(x);
|
||||
ret -= (sp2uint32(x) >> 31);
|
||||
ret -= (G4IEEE754::sp2uint32(x) >> 31);
|
||||
return ret;
|
||||
}
|
||||
} // namespace G4ExpConsts
|
||||
@@ -211,7 +163,7 @@ inline G4double G4Exp(G4double initial_x)
|
||||
x = 1.0 + 2.0 * x;
|
||||
|
||||
// Build 2^n in double.
|
||||
x *= G4ExpConsts::uint642dp((((uint64_t) n) + 1023) << 52);
|
||||
x *= G4IEEE754::uint642dp((((uint64_t) n) + 1023) << 52);
|
||||
|
||||
if(initial_x > G4ExpConsts::EXP_LIMIT)
|
||||
x = std::numeric_limits<G4double>::infinity();
|
||||
@@ -252,7 +204,7 @@ inline G4float G4Expf(G4float initial_x)
|
||||
z += x + 1.0f;
|
||||
|
||||
/* multiply by power of 2 */
|
||||
z *= G4ExpConsts::uint322sp((n + 0x7f) << 23);
|
||||
z *= G4IEEE754::uint322sp((n + 0x7f) << 23);
|
||||
|
||||
if(initial_x > G4ExpConsts::MAXLOGF)
|
||||
z = std::numeric_limits<G4float>::infinity();
|
||||
@@ -262,17 +214,6 @@ inline G4float G4Expf(G4float initial_x)
|
||||
return z;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void expv(const uint32_t size, G4double const* __restrict__ iarray,
|
||||
G4double* __restrict__ oarray);
|
||||
void G4Expv(const uint32_t size, G4double const* __restrict__ iarray,
|
||||
G4double* __restrict__ oarray);
|
||||
void expfv(const uint32_t size, G4float const* __restrict__ iarray,
|
||||
G4float* __restrict__ oarray);
|
||||
void G4Expfv(const uint32_t size, G4float const* __restrict__ iarray,
|
||||
G4float* __restrict__ oarray);
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
#ifndef G4IEEE754_hh
|
||||
#define G4IEEE754_hh 1
|
||||
|
||||
#include "G4Types.hh"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace G4IEEE754
|
||||
{
|
||||
//----------------------------------------------------------------------------
|
||||
// Used to switch between different type of interpretations of the data
|
||||
// (64 bits)
|
||||
//
|
||||
union ieee754
|
||||
{
|
||||
ieee754() = default;
|
||||
ieee754(G4double thed) { d = thed; };
|
||||
ieee754(uint64_t thell) { ll = thell; };
|
||||
ieee754(G4float thef) { f[0] = thef; };
|
||||
ieee754(uint32_t thei) { i[0] = thei; };
|
||||
G4double d;
|
||||
G4float f[2];
|
||||
uint32_t i[2];
|
||||
uint64_t ll;
|
||||
uint16_t s[4];
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts a double to an unsigned long long
|
||||
//
|
||||
inline uint64_t dp2uint64(G4double x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.d = x;
|
||||
return tmp.ll;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts an unsigned long long to a double
|
||||
//
|
||||
inline G4double uint642dp(uint64_t ll)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.ll = ll;
|
||||
return tmp.d;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts an int to a float
|
||||
//
|
||||
inline G4float uint322sp(G4int x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.i[0] = x;
|
||||
return tmp.f[0];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts a float to an int
|
||||
//
|
||||
inline uint32_t sp2uint32(G4float x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.f[0] = x;
|
||||
return tmp.i[0];
|
||||
}
|
||||
} // namespace G4IEEE754
|
||||
|
||||
#endif
|
||||
@@ -64,7 +64,7 @@
|
||||
#else
|
||||
|
||||
# include "G4Types.hh"
|
||||
|
||||
# include "G4IEEE754.hh"
|
||||
# include <cstdint>
|
||||
# include <limits>
|
||||
|
||||
@@ -78,24 +78,6 @@ namespace G4LogConsts
|
||||
const G4double SQRTH = 0.70710678118654752440;
|
||||
const G4float MAXNUMF = 3.4028234663852885981170418348451692544e38f;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Used to switch between different type of interpretations of the data
|
||||
// (64 bits)
|
||||
//
|
||||
union ieee754
|
||||
{
|
||||
ieee754()= default;
|
||||
ieee754(G4double thed) { d = thed; };
|
||||
ieee754(uint64_t thell) { ll = thell; };
|
||||
ieee754(G4float thef) { f[0] = thef; };
|
||||
ieee754(uint32_t thei) { i[0] = thei; };
|
||||
G4double d;
|
||||
G4float f[2];
|
||||
uint32_t i[2];
|
||||
uint64_t ll;
|
||||
uint16_t s[4];
|
||||
};
|
||||
|
||||
inline G4double get_log_px(const G4double x)
|
||||
{
|
||||
const G4double PX1log = 1.01875663804580931796E-4;
|
||||
@@ -140,51 +122,11 @@ namespace G4LogConsts
|
||||
return qx;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts a double to an unsigned long long
|
||||
//
|
||||
inline uint64_t dp2uint64(G4double x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.d = x;
|
||||
return tmp.ll;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts an unsigned long long to a double
|
||||
//
|
||||
inline G4double uint642dp(uint64_t ll)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.ll = ll;
|
||||
return tmp.d;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts an int to a float
|
||||
//
|
||||
inline G4float uint322sp(G4int x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.i[0] = x;
|
||||
return tmp.f[0];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Converts a float to an int
|
||||
//
|
||||
inline uint32_t sp2uint32(G4float x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.f[0] = x;
|
||||
return tmp.i[0];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Like frexp but vectorising and the exponent is a double.
|
||||
inline G4double getMantExponent(const G4double x, G4double& fe)
|
||||
{
|
||||
uint64_t n = dp2uint64(x);
|
||||
uint64_t n = G4IEEE754::dp2uint64(x);
|
||||
|
||||
// Shift to the right up to the beginning of the exponent.
|
||||
// Then with a mask, cut off the sign bit
|
||||
@@ -202,14 +144,14 @@ namespace G4LogConsts
|
||||
const uint64_t p05 = 0x3FE0000000000000ULL; // dp2uint64(0.5);
|
||||
n |= p05;
|
||||
|
||||
return uint642dp(n);
|
||||
return G4IEEE754::uint642dp(n);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Like frexp but vectorising and the exponent is a float.
|
||||
inline G4float getMantExponentf(const G4float x, G4float& fe)
|
||||
{
|
||||
uint32_t n = sp2uint32(x);
|
||||
uint32_t n = G4IEEE754::sp2uint32(x);
|
||||
int32_t e = (n >> 23) - 127;
|
||||
fe = e;
|
||||
|
||||
@@ -218,7 +160,7 @@ namespace G4LogConsts
|
||||
n &= 0x807fffff; // ~0x7f800000;
|
||||
n |= p05f;
|
||||
|
||||
return uint322sp(n);
|
||||
return G4IEEE754::uint322sp(n);
|
||||
}
|
||||
} // namespace G4LogConsts
|
||||
|
||||
@@ -335,17 +277,6 @@ inline G4float G4Logf(G4float x)
|
||||
return res;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void logv(const uint32_t size, G4double const* __restrict__ iarray,
|
||||
G4double* __restrict__ oarray);
|
||||
void G4Logv(const uint32_t size, G4double const* __restrict__ iarray,
|
||||
G4double* __restrict__ oarray);
|
||||
void logfv(const uint32_t size, G4float const* __restrict__ iarray,
|
||||
G4float* __restrict__ oarray);
|
||||
void G4Logfv(const uint32_t size, G4float const* __restrict__ iarray,
|
||||
G4float* __restrict__ oarray);
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif /* LOG_H_ */
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
/// |--> patch number (single digit)
|
||||
///
|
||||
#ifndef G4VERSION_NUMBER
|
||||
#define G4VERSION_NUMBER 1132
|
||||
#define G4VERSION_NUMBER 1140
|
||||
#endif
|
||||
|
||||
/// @def G4VERSION_REFERENCE_TAG
|
||||
@@ -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-03-patch-02 $"
|
||||
#define G4VERSION_TAG "$Name: geant4-11-04-beta-01 $"
|
||||
#endif
|
||||
|
||||
// as variables
|
||||
@@ -68,10 +68,10 @@
|
||||
#include "G4Types.hh"
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
static const G4String G4Version = "$Name: geant4-11-03-patch-02 [MT]$";
|
||||
static const G4String G4Version = "$Name: geant4-11-04-beta-01 [MT]$";
|
||||
#else
|
||||
static const G4String G4Version = "$Name: geant4-11-03-patch-02 $";
|
||||
static const G4String G4Version = "$Name: geant4-11-04-beta-01 $";
|
||||
#endif
|
||||
static const G4String G4Date = "(25-April-2025)";
|
||||
static const G4String G4Date = "(26-June-2025)";
|
||||
|
||||
#endif
|
||||
|
||||
@@ -54,6 +54,7 @@ geant4_add_module(G4globman
|
||||
G4GeometryTolerance.hh
|
||||
G4GlobalConfig.hh.in
|
||||
G4ios.hh
|
||||
G4IEEE754.hh
|
||||
G4LockcoutDestination.hh
|
||||
G4Log.hh
|
||||
G4MasterForwardcoutDestination.hh
|
||||
|
||||
Reference in New Issue
Block a user