Import Geant4 11.0.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2021-06-25 16:12:29 +02:00
parent c968e26a39
commit 6399a014b6
4200 changed files with 207479 additions and 237366 deletions
@@ -35,51 +35,169 @@
#include "G4PhysicsFreeVector.hh"
// --------------------------------------------------------------------
G4PhysicsFreeVector::G4PhysicsFreeVector()
: G4PhysicsVector()
{
type = T_G4PhysicsFreeVector;
}
// --------------------------------------------------------------------
G4PhysicsFreeVector::G4PhysicsFreeVector(std::size_t length)
: G4PhysicsVector()
G4PhysicsFreeVector::G4PhysicsFreeVector(std::size_t length, G4bool spline)
: G4PhysicsVector(spline)
{
type = T_G4PhysicsFreeVector;
numberOfNodes = length;
dataVector.reserve(numberOfNodes);
binVector.reserve(numberOfNodes);
if(0 < length) {
dataVector.reserve(numberOfNodes);
binVector.reserve(numberOfNodes);
for(std::size_t i = 0; i < numberOfNodes; ++i)
{
binVector.push_back(0.0);
dataVector.push_back(0.0);
for(std::size_t i = 0; i < numberOfNodes; ++i)
{
binVector.push_back(0.0);
dataVector.push_back(0.0);
}
}
}
// --------------------------------------------------------------------
G4PhysicsFreeVector::G4PhysicsFreeVector(const G4DataVector& theBinVector,
const G4DataVector& theDataVector)
: G4PhysicsVector()
G4PhysicsFreeVector::G4PhysicsFreeVector(std::size_t length, G4double emin,
G4double emax, G4bool spline)
: G4PhysicsFreeVector(length, spline)
{
edgeMin = emin;
edgeMax = emax;
}
// --------------------------------------------------------------------
G4PhysicsFreeVector::G4PhysicsFreeVector(const std::vector<G4double>& energies,
const std::vector<G4double>& values,
G4bool spline)
: G4PhysicsVector(spline)
{
type = T_G4PhysicsFreeVector;
numberOfNodes = theBinVector.size();
numberOfNodes = energies.size();
dataVector.reserve(numberOfNodes);
binVector.reserve(numberOfNodes);
for(std::size_t i = 0; i < numberOfNodes; ++i)
if(numberOfNodes != values.size())
{
binVector.push_back(theBinVector[i]);
dataVector.push_back(theDataVector[i]);
G4ExceptionDescription ed;
ed << "The size of energy vector " << numberOfNodes << " != " << values.size();
G4Exception("G4PhysicsFreeVector constructor: ","glob04", FatalException, ed);
}
if(numberOfNodes > 0)
if(0 < numberOfNodes)
{
binVector.reserve(numberOfNodes);
dataVector.reserve(numberOfNodes);
for(std::size_t i = 0; i < numberOfNodes; ++i)
{
binVector.push_back(energies[i]);
dataVector.push_back(values[i]);
}
edgeMin = binVector[0];
edgeMax = binVector[numberOfNodes - 1];
}
}
// --------------------------------------------------------------------
G4PhysicsFreeVector::~G4PhysicsFreeVector() {}
G4PhysicsFreeVector::G4PhysicsFreeVector(const G4double* energies,
const G4double* values,
std::size_t length,
G4bool spline)
: G4PhysicsVector(spline)
{
type = T_G4PhysicsFreeVector;
numberOfNodes = length;
if(0 < numberOfNodes)
{
binVector.reserve(numberOfNodes);
dataVector.reserve(numberOfNodes);
for(std::size_t i = 0; i < numberOfNodes; ++i)
{
binVector.push_back(energies[i]);
dataVector.push_back(values[i]);
}
edgeMin = binVector[0];
edgeMax = binVector[numberOfNodes - 1];
}
}
// --------------------------------------------------------------------
G4PhysicsFreeVector::~G4PhysicsFreeVector()
{}
// --------------------------------------------------------------------
void G4PhysicsFreeVector::PutValues(std::size_t index, G4double e,
G4double value)
{
if(index >= numberOfNodes)
{
PrintPutValueError(index, binVector[numberOfNodes - 1], e);
}
binVector[index] = e;
dataVector[index] = value;
if(index == 0)
{
edgeMin = edgeMax = e;
}
else if(numberOfNodes == index + 1)
{
edgeMax = e;
}
}
// --------------------------------------------------------------------
void G4PhysicsFreeVector::InsertValues(G4double energy, G4double value)
{
auto binLoc = std::lower_bound(binVector.cbegin(), binVector.cend(), energy);
std::size_t binIdx = binLoc - binVector.cbegin(); // Iterator difference!
auto dataLoc = dataVector.cbegin() + binIdx;
binVector.insert(binLoc, energy);
dataVector.insert(dataLoc, value);
++numberOfNodes;
edgeMin = binVector.front();
edgeMax = binVector.back();
}
// --------------------------------------------------------------------
G4double G4PhysicsFreeVector::GetEnergy(G4double aValue)
{
G4double e;
if(aValue <= GetMinValue())
{
e = edgeMin;
}
else if(aValue >= GetMaxValue())
{
e = edgeMax;
}
else
{
std::size_t closestBin = FindValueBinLocation(aValue);
e = LinearInterpolationOfEnergy(aValue, closestBin);
}
return e;
}
// --------------------------------------------------------------------
std::size_t G4PhysicsFreeVector::FindValueBinLocation(G4double aValue)
{
std::size_t bin =
std::lower_bound(dataVector.cbegin(), dataVector.cend(), aValue) -
dataVector.cbegin() - 1;
bin = std::min(bin, numberOfNodes - 2);
return bin;
}
// --------------------------------------------------------------------
G4double G4PhysicsFreeVector::LinearInterpolationOfEnergy(G4double aValue,
std::size_t bin)
{
G4double res = binVector[bin];
G4double del = dataVector[bin + 1] - dataVector[bin];
if(del > 0.0)
{
res += (aValue - dataVector[bin]) * (binVector[bin + 1] - res) / del;
}
return res;
}
@@ -35,16 +35,16 @@
#include "G4PhysicsLinearVector.hh"
// --------------------------------------------------------------------
G4PhysicsLinearVector::G4PhysicsLinearVector()
: G4PhysicsVector()
G4PhysicsLinearVector::G4PhysicsLinearVector(G4bool spline)
: G4PhysicsVector(spline)
{
type = T_G4PhysicsLinearVector;
}
// --------------------------------------------------------------------
G4PhysicsLinearVector::G4PhysicsLinearVector(G4double theEmin, G4double theEmax,
std::size_t theNbin)
: G4PhysicsVector()
std::size_t theNbin, G4bool spline)
: G4PhysicsVector(spline)
{
numberOfNodes = theNbin + 1;
if(theNbin < 1 || theEmin == theEmax)
@@ -37,16 +37,16 @@
#include "G4Exp.hh"
// --------------------------------------------------------------------
G4PhysicsLogVector::G4PhysicsLogVector()
: G4PhysicsVector()
G4PhysicsLogVector::G4PhysicsLogVector(G4bool spline)
: G4PhysicsVector(spline)
{
type = T_G4PhysicsLogVector;
}
// --------------------------------------------------------------------
G4PhysicsLogVector::G4PhysicsLogVector(G4double theEmin, G4double theEmax,
std::size_t theNbin)
: G4PhysicsVector()
std::size_t theNbin, G4bool spline)
: G4PhysicsVector(spline)
{
numberOfNodes = theNbin + 1;
if(theNbin < 2 || theEmin == theEmax)
@@ -1,145 +0,0 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// G4PhysicsOrderedFreeVector class implementation
//
// Author: Juliet Armstrong (TRIUMF), 13 August 1996
// Revisions:
// - 11.11.2000, H.Kurashige: use STL vector for dataVector and binVector
// - 19.06.2009, V.Ivanchenko: removed hidden bin
// --------------------------------------------------------------------
#include "G4PhysicsOrderedFreeVector.hh"
// --------------------------------------------------------------------
G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector()
: G4PhysicsVector()
{
type = T_G4PhysicsOrderedFreeVector;
}
// --------------------------------------------------------------------
G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector(G4double* Energies,
G4double* Values,
std::size_t VectorLength)
: G4PhysicsVector()
{
type = T_G4PhysicsOrderedFreeVector;
dataVector.reserve(VectorLength);
binVector.reserve(VectorLength);
for(std::size_t i = 0; i < VectorLength; ++i)
{
InsertValues(Energies[i], Values[i]);
}
}
// --------------------------------------------------------------------
G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector(
const std::vector<G4double>& Energies, const std::vector<G4double>& Values)
: G4PhysicsVector()
{
if(Energies.size() != Values.size())
{
G4ExceptionDescription ed;
ed << "The sizes of the two std::vector arguments must be the same";
G4Exception("G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector()",
"glob04", FatalException, ed);
}
type = T_G4PhysicsOrderedFreeVector;
dataVector.reserve(Energies.size());
binVector.reserve(Energies.size());
for(std::size_t i = 0; i < Energies.size(); ++i)
{
InsertValues(Energies[i], Values[i]);
}
}
// --------------------------------------------------------------------
G4PhysicsOrderedFreeVector::~G4PhysicsOrderedFreeVector() {}
// --------------------------------------------------------------------
void G4PhysicsOrderedFreeVector::InsertValues(G4double energy, G4double value)
{
auto binLoc = std::lower_bound(binVector.cbegin(), binVector.cend(), energy);
std::size_t binIdx = binLoc - binVector.cbegin(); // Iterator difference!
auto dataLoc = dataVector.cbegin() + binIdx;
binVector.insert(binLoc, energy);
dataVector.insert(dataLoc, value);
++numberOfNodes;
edgeMin = binVector.front();
edgeMax = binVector.back();
}
// --------------------------------------------------------------------
G4double G4PhysicsOrderedFreeVector::GetEnergy(G4double aValue)
{
G4double e;
if(aValue <= GetMinValue())
{
e = edgeMin;
}
else if(aValue >= GetMaxValue())
{
e = edgeMax;
}
else
{
std::size_t closestBin = FindValueBinLocation(aValue);
e = LinearInterpolationOfEnergy(aValue, closestBin);
}
return e;
}
// --------------------------------------------------------------------
std::size_t G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
{
std::size_t bin =
std::lower_bound(dataVector.cbegin(), dataVector.cend(), aValue) -
dataVector.cbegin() - 1;
bin = std::min(bin, numberOfNodes - 2);
return bin;
}
// --------------------------------------------------------------------
G4double G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(
G4double aValue, std::size_t bin)
{
G4double res = binVector[bin];
G4double del = dataVector[bin + 1] - dataVector[bin];
if(del > 0.0)
{
res += (aValue - dataVector[bin]) * (binVector[bin + 1] - res) / del;
}
return res;
}
+6 -21
View File
@@ -36,12 +36,9 @@
#include <iomanip>
#include <iostream>
#include "G4LPhysicsFreeVector.hh"
#include "G4PhysicsFreeVector.hh"
#include "G4PhysicsLinearVector.hh"
#include "G4PhysicsLnVector.hh"
#include "G4PhysicsLogVector.hh"
#include "G4PhysicsOrderedFreeVector.hh"
#include "G4PhysicsTable.hh"
#include "G4PhysicsVector.hh"
#include "G4PhysicsVectorType.hh"
@@ -147,7 +144,7 @@ G4bool G4PhysicsTable::ExistPhysicsTable(const G4String& fileName) const
// --------------------------------------------------------------------
G4bool G4PhysicsTable::RetrievePhysicsTable(const G4String& fileName,
G4bool ascii)
G4bool ascii, G4bool spline)
{
std::ifstream fIn;
// open input file
@@ -199,7 +196,7 @@ G4bool G4PhysicsTable::RetrievePhysicsTable(const G4String& fileName,
{
fIn >> vType;
}
G4PhysicsVector* pVec = CreatePhysicsVector(vType);
G4PhysicsVector* pVec = CreatePhysicsVector(vType, spline);
if(pVec == nullptr)
{
#ifdef G4VERBOSE
@@ -269,33 +266,21 @@ void G4PhysicsTable::ResetFlagArray()
}
// --------------------------------------------------------------------
G4PhysicsVector* G4PhysicsTable::CreatePhysicsVector(G4int type)
G4PhysicsVector* G4PhysicsTable::CreatePhysicsVector(G4int type, G4bool spline)
{
G4PhysicsVector* pVector = nullptr;
switch(type)
{
case T_G4PhysicsLinearVector:
pVector = new G4PhysicsLinearVector();
pVector = new G4PhysicsLinearVector(spline);
break;
case T_G4PhysicsLogVector:
pVector = new G4PhysicsLogVector();
break;
case T_G4PhysicsLnVector:
pVector = new G4PhysicsLogVector();
pVector = new G4PhysicsLogVector(spline);
break;
case T_G4PhysicsFreeVector:
pVector = new G4PhysicsFreeVector();
break;
case T_G4PhysicsOrderedFreeVector:
pVector = new G4PhysicsOrderedFreeVector();
break;
case T_G4LPhysicsFreeVector:
pVector = new G4PhysicsFreeVector();
pVector = new G4PhysicsFreeVector(spline);
break;
default:
@@ -560,11 +560,12 @@ G4double G4PhysicsVector::FindLinearEnergy(G4double rand) const
//---------------------------------------------------------------
void G4PhysicsVector::PrintPutValueError(std::size_t index)
void G4PhysicsVector::PrintPutValueError(std::size_t index, G4double e1, G4double e2)
{
G4ExceptionDescription ed;
ed << "Vector type " << type << " length= " << numberOfNodes
<< " an attempt to put data at index= " << index;
<< " an attempt to put data at index= " << index
<< " E[index - 1]= " << e1 << "; E[index]= " << e2;
G4Exception("G4PhysicsVector::PutValue()", "gl0005", FatalException, ed,
"Memory overwritten");
}
@@ -23,23 +23,29 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4LPhysicsFreeVector class implementation
// G4ThreadLocalSingleton class implementation
//
// Author: F.W. Jones (TRIUMF), 04-June-1996 - First implementation
// Author: J. Madsen (LBL), May 2021
// --------------------------------------------------------------------
#include "G4LPhysicsFreeVector.hh"
#include "G4ThreadLocalSingleton.hh"
// --------------------------------------------------------------------
G4LPhysicsFreeVector::G4LPhysicsFreeVector()
: G4PhysicsFreeVector()
{}
std::vector<std::function<void()>>& G4ThreadLocalSingleton<void>::GetCallbacks()
{
static auto _instance = fvector_t{};
return _instance;
}
// --------------------------------------------------------------------
G4LPhysicsFreeVector::G4LPhysicsFreeVector(std::size_t length, G4double,
G4double)
: G4PhysicsFreeVector(length)
{}
G4Mutex& G4ThreadLocalSingleton<void>::GetMutex()
{
static G4Mutex _instance{};
return _instance;
}
// --------------------------------------------------------------------
G4LPhysicsFreeVector::~G4LPhysicsFreeVector() {}
void G4ThreadLocalSingleton<void>::Clear()
{
G4AutoLock _lk{ GetMutex() };
for(auto itr : GetCallbacks())
itr();
GetCallbacks().clear();
}
+23 -1
View File
@@ -302,11 +302,25 @@ void G4UnitDefinition::BuildUnitsTable()
new G4UnitDefinition("microsecond", "us", "Time", microsecond);
new G4UnitDefinition("nanosecond", "ns", "Time", nanosecond);
new G4UnitDefinition("picosecond", "ps", "Time", picosecond);
new G4UnitDefinition("minute", "min", "Time", minute);
new G4UnitDefinition("hour", "h", "Time", hour);
new G4UnitDefinition("day", "d", "Time", day);
new G4UnitDefinition("year", "y", "Time", year);
// Frequency
new G4UnitDefinition("hertz", "Hz", "Frequency", hertz);
new G4UnitDefinition("kilohertz", "kHz", "Frequency", kilohertz);
new G4UnitDefinition("megahertz", "MHz", "Frequency", megahertz);
// Velocity
new G4UnitDefinition("cm/ns", "cm/ns", "Velocity", cm/ns);
new G4UnitDefinition("mm/ns", "mm/ns", "Velocity", mm/ns);
new G4UnitDefinition("cm/us", "cm/us", "Velocity", cm/us);
new G4UnitDefinition("km/s" , "km/s" , "Velocity", km/s);
new G4UnitDefinition("cm/ms", "cm/ms", "Velocity", cm/ms);
new G4UnitDefinition( "m/s" , "m/s" , "Velocity", m/s);
new G4UnitDefinition("cm/s" , "cm/s" , "Velocity", cm/s);
new G4UnitDefinition("mm/s" , "mm/s" , "Velocity", mm/s);
// Electric charge
new G4UnitDefinition("eplus", "e+", "Electric charge", eplus);
@@ -319,8 +333,16 @@ void G4UnitDefinition::BuildUnitsTable()
new G4UnitDefinition("gigaelectronvolt", "GeV", "Energy", gigaelectronvolt);
new G4UnitDefinition("teraelectronvolt", "TeV", "Energy", teraelectronvolt);
new G4UnitDefinition("petaelectronvolt", "PeV", "Energy", petaelectronvolt);
new G4UnitDefinition("millielectronVolt", "meV", "Energy", millielectronvolt);
new G4UnitDefinition("joule", "J", "Energy", joule);
//Momentum
new G4UnitDefinition( "eV/c", "eV/c", "Momentum", eV);
new G4UnitDefinition("keV/c", "keV/c", "Momentum", keV);
new G4UnitDefinition("MeV/c", "MeV/c", "Momentum", MeV);
new G4UnitDefinition("GeV/c", "GeV/c", "Momentum", GeV);
new G4UnitDefinition("TeV/c", "TeV/c", "Momentum", TeV);
// Energy/Length
new G4UnitDefinition("GeV/cm", "GeV/cm", "Energy/Length", GeV / cm);
new G4UnitDefinition("MeV/cm", "MeV/cm", "Energy/Length", MeV / cm);