Import Geant4 10.6.0 source tree

This commit is contained in:
Gabriele Cosmo
2019-12-06 15:12:28 +01:00
parent b2a62ae692
commit 5baee230e9
2997 changed files with 141580 additions and 98673 deletions
@@ -34,6 +34,7 @@
#include "G4EnergyRangeManager.hh"
#include "Randomize.hh"
#include "G4HadronicException.hh"
#include "G4SystemOfUnits.hh"
G4EnergyRangeManager::G4EnergyRangeManager()
: theHadronicInteractionCounter(0)
@@ -42,22 +43,6 @@ G4EnergyRangeManager::G4EnergyRangeManager()
G4EnergyRangeManager::~G4EnergyRangeManager()
{}
G4EnergyRangeManager::G4EnergyRangeManager(const G4EnergyRangeManager& right)
{
theHadronicInteractionCounter = right.theHadronicInteractionCounter;
theHadronicInteraction = right.theHadronicInteraction;
}
G4EnergyRangeManager& G4EnergyRangeManager::operator=(
const G4EnergyRangeManager& right)
{
if (this != &right) {
theHadronicInteractionCounter = right.theHadronicInteractionCounter;
theHadronicInteraction = right.theHadronicInteraction;
}
return *this;
}
void G4EnergyRangeManager::RegisterMe(G4HadronicInteraction* a)
{
if(!a) { return; }
@@ -70,16 +55,18 @@ void G4EnergyRangeManager::RegisterMe(G4HadronicInteraction* a)
++theHadronicInteractionCounter;
}
G4HadronicInteraction*
G4EnergyRangeManager::GetHadronicInteraction(const G4HadProjectile & aHadProjectile,
G4Nucleus & aTargetNucleus,
const G4Material* aMaterial,
const G4Element* anElement) const
{
if(0 == theHadronicInteractionCounter) {
throw G4HadronicException(__FILE__, __LINE__,
"GetHadronicInteraction: NO MODELS STORED");
// VI shortcut: if only one interaction is registered skip all checks
if(1 == theHadronicInteractionCounter) { return theHadronicInteraction[0]; }
else if(0 == theHadronicInteractionCounter) {
G4cout << "G4EnergyRangeManager::GetHadronicInteraction: "
<< "no models defined for a process" << G4endl;
return nullptr;
}
G4double kineticEnergy = aHadProjectile.GetKineticEnergy();
@@ -94,11 +81,8 @@ G4EnergyRangeManager::GetHadronicInteraction(const G4HadProjectile & aHadProject
for (G4int i = 0; i<theHadronicInteractionCounter; ++i) {
if ( theHadronicInteraction[i]->IsApplicable( aHadProjectile, aTargetNucleus ) ) {
G4double low = theHadronicInteraction[i]->GetMinEnergy( aMaterial, anElement );
// Work-around for particles with 0 kinetic energy, which still
// require a model to return a ParticleChange
//if (low == 0.) low = -DBL_MIN;
G4double high = theHadronicInteraction[i]->GetMaxEnergy( aMaterial, anElement );
if (low <= kineticEnergy && high > kineticEnergy) {
if (low <= kineticEnergy && high >= kineticEnergy) {
++cou;
emi2 = emi1;
ema2 = ema1;
@@ -110,158 +94,62 @@ G4EnergyRangeManager::GetHadronicInteraction(const G4HadProjectile & aHadProject
}
}
G4int mem = -1;
G4double rand;
G4HadronicInteraction* hi = nullptr;
switch (cou) {
case 0:
G4cout<<"G4EnergyRangeManager:GetHadronicInteraction: counter="
<<theHadronicInteractionCounter<<", Ek="
<<kineticEnergy<<", Material = "<<aMaterial->GetName()
<<", Element = "
<<anElement->GetName()<<G4endl;
for( G4int j=0; j<theHadronicInteractionCounter; ++j)
{
G4HadronicInteraction* HInt=theHadronicInteraction[j];
G4cout<<"*"<<j<<"* low=" <<HInt->GetMinEnergy(aMaterial,anElement)
<<", high="<<HInt->GetMaxEnergy(aMaterial,anElement)<<G4endl;
}
throw G4HadronicException(__FILE__, __LINE__,
"GetHadronicInteraction: No Model found");
return 0;
G4cout << "No model found out of " << theHadronicInteractionCounter << G4endl;
for( G4int j=0; j<theHadronicInteractionCounter; ++j) {
G4HadronicInteraction* hint=theHadronicInteraction[j];
G4cout << " "<< j << ". Elow= " << hint->GetMinEnergy(aMaterial,anElement)
<<", Ehigh= " << hint->GetMaxEnergy(aMaterial,anElement)
<<" " << hint->GetModelName() << G4endl;
}
break;
case 1:
mem = memory;
break;
hi = theHadronicInteraction[memory];
break;
case 2:
if( (emi2<=emi1 && ema2>=ema1) || (emi2>=emi1 && ema2<=ema1) )
{
G4cout<<"G4EnergyRangeManager:GetHadronicInteraction: counter="
<<theHadronicInteractionCounter<<", Ek="
<<kineticEnergy<<", Material = "<<aMaterial->GetName()
<<", Element = "
<<anElement->GetName()<<G4endl;
for( G4int j=0; j<theHadronicInteractionCounter; ++j)
{
G4HadronicInteraction* HInt=theHadronicInteraction[j];
G4cout<<"*"<<j<<"* low=" <<HInt->GetMinEnergy(aMaterial,anElement)
<<", high="<<HInt->GetMaxEnergy(aMaterial,anElement)<<G4endl;
}
throw G4HadronicException(__FILE__, __LINE__,
"GetHadronicInteraction: Energy ranges of two models fully overlapping");
}
rand = G4UniformRand();
if( emi1 < emi2 )
{
if( (ema1-kineticEnergy) < rand*(ema1-emi2) ) {
mem = memor2;
} else {
mem = memory;
}
} else {
if( (ema2-kineticEnergy) < rand*(ema2-emi1) ) {
mem = memory;
} else {
mem = memor2;
}
}
break;
if( (emi2<=emi1 && ema2>=ema1) || (emi2>=emi1 && ema2<=ema1) ) {
G4cout << "Energy ranges of two models fully overlapping " << G4endl;
for( G4int j=0; j<theHadronicInteractionCounter; ++j) {
G4HadronicInteraction* hint=theHadronicInteraction[j];
G4cout << " "<< j << ". Elow= " << hint->GetMinEnergy(aMaterial,anElement)
<<", Ehigh= " << hint->GetMaxEnergy(aMaterial,anElement)
<<" " << hint->GetModelName() << G4endl;
}
} else {
G4double rand = G4UniformRand();
G4int mem;
if( emi1 < emi2 ) {
if( (ema1-kineticEnergy) < rand*(ema1-emi2) ) {
mem = memor2;
} else {
mem = memory;
}
} else {
if( (ema2-kineticEnergy) < rand*(ema2-emi1) ) {
mem = memory;
} else {
mem = memor2;
}
}
hi = theHadronicInteraction[mem];
}
break;
default:
throw G4HadronicException(__FILE__, __LINE__,
"GetHadronicInteraction: More than two competing models in this energy range");
G4cout << "More than two competing models for this energy" << G4endl;
for( G4int j=0; j<theHadronicInteractionCounter; ++j) {
G4HadronicInteraction* hint=theHadronicInteraction[j];
G4cout << " "<< j << ". Elow= " << hint->GetMinEnergy(aMaterial,anElement)
<<", Ehigh= " << hint->GetMaxEnergy(aMaterial,anElement)
<<" " << hint->GetModelName() << G4endl;
}
break;
}
return theHadronicInteraction[mem];
}
G4HadronicInteraction*
G4EnergyRangeManager::GetHadronicInteraction(const G4double kineticEnergy,
const G4Material* aMaterial,
const G4Element* anElement) const
{
if(0 == theHadronicInteractionCounter) {
throw G4HadronicException(__FILE__, __LINE__,
"GetHadronicInteraction: NO MODELS STORED");
}
G4int cou = 0, memory = 0, memor2 = 0;
G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, ema2 = 0.0;
for (G4int i = 0; i<theHadronicInteractionCounter; ++i) {
G4double low = theHadronicInteraction[i]->GetMinEnergy( aMaterial, anElement );
// Work-around for particles with 0 kinetic energy, which still
// require a model to return a ParticleChange
//if (low == 0.) low = -DBL_MIN;
G4double high = theHadronicInteraction[i]->GetMaxEnergy( aMaterial, anElement );
if (low <= kineticEnergy && high > kineticEnergy) {
++cou;
emi2 = emi1;
ema2 = ema1;
emi1 = low;
ema1 = high;
memor2 = memory;
memory = i;
}
}
G4int mem = -1;
G4double rand;
switch (cou) {
case 0:
G4cout<<"G4EnergyRangeManager:GetHadronicInteraction: counter="
<<theHadronicInteractionCounter<<", Ek="
<<kineticEnergy<<", Material = "<<aMaterial->GetName()
<<", Element = "
<<anElement->GetName()<<G4endl;
for( G4int j=0; j<theHadronicInteractionCounter; ++j)
{
G4HadronicInteraction* HInt=theHadronicInteraction[j];
G4cout<<"*"<<j<<"* low=" <<HInt->GetMinEnergy(aMaterial,anElement)
<<", high="<<HInt->GetMaxEnergy(aMaterial,anElement)<<G4endl;
}
throw G4HadronicException(__FILE__, __LINE__,
"GetHadronicInteraction: No Model found");
return 0;
case 1:
mem = memory;
break;
case 2:
if( (emi2<=emi1 && ema2>=ema1) || (emi2>=emi1 && ema2<=ema1) )
{
G4cout<<"G4EnergyRangeManager:GetHadronicInteraction: counter="
<<theHadronicInteractionCounter<<", Ek="
<<kineticEnergy<<", Material = "<<aMaterial->GetName()
<<", Element = "
<<anElement->GetName()<<G4endl;
for( G4int j=0; j<theHadronicInteractionCounter; ++j)
{
G4HadronicInteraction* HInt=theHadronicInteraction[j];
G4cout<<"*"<<j<<"* low=" <<HInt->GetMinEnergy(aMaterial,anElement)
<<", high="<<HInt->GetMaxEnergy(aMaterial,anElement)<<G4endl;
}
throw G4HadronicException(__FILE__, __LINE__,
"GetHadronicInteraction: Energy ranges of two models fully overlapping");
}
rand = G4UniformRand();
if( emi1 < emi2 )
{
if( (ema1-kineticEnergy) < rand*(ema1-emi2) ) {
mem = memor2;
} else {
mem = memory;
}
} else {
if( (ema2-kineticEnergy) < rand*(ema2-emi1) ) {
mem = memory;
} else {
mem = memor2;
}
}
break;
default:
throw G4HadronicException(__FILE__, __LINE__,
"GetHadronicInteraction: More than two competing models in this energy range");
}
return theHadronicInteraction[mem];
return hi;
}
std::vector<G4HadronicInteraction*>&
@@ -270,7 +158,6 @@ G4EnergyRangeManager::GetHadronicInteractionList()
return theHadronicInteraction;
}
#include "G4SystemOfUnits.hh"
void G4EnergyRangeManager::Dump( G4int verbose )
{
G4cout << "G4EnergyRangeManager " << this << G4endl;
@@ -290,10 +177,9 @@ void G4EnergyRangeManager::Dump( G4int verbose )
void
G4EnergyRangeManager::BuildPhysicsTable(const G4ParticleDefinition& aParticleType)
{
for ( std::vector<G4HadronicInteraction*>::iterator
it = theHadronicInteraction.begin() ; it != theHadronicInteraction.end() ; it++ ) {
(*it)->BuildPhysicsTable( aParticleType );
}
for (auto & hadi : theHadronicInteraction) {
hadi->BuildPhysicsTable( aParticleType );
}
}
/* end of file */
@@ -45,6 +45,7 @@
// configure base-class
// 28-Sep-2012 Restore inheritance from G4VDiscreteProcess, remove enable-flag
// changing, remove warning message from original ctor.
// 21-Aug-2019 V.Ivanchenko leave try/catch only for ApplyYourself(..), cleanup
#include "G4HadronicProcess.hh"
@@ -56,19 +57,14 @@
#include "G4Step.hh"
#include "G4Element.hh"
#include "G4ParticleChange.hh"
#include "G4TransportationManager.hh"
#include "G4Navigator.hh"
#include "G4ProcessVector.hh"
#include "G4ProcessManager.hh"
#include "G4StableIsotopes.hh"
#include "G4HadTmpUtil.hh"
#include "G4NucleiProperties.hh"
#include "G4HadronicException.hh"
#include "G4HadronicProcessStore.hh"
#include "G4VCrossSectionDataSet.hh"
#include "G4AutoLock.hh"
#include "G4NistManager.hh"
#include "G4PhysicsModelCatalog.hh"
#include "G4VLeadingParticleBiasing.hh"
@@ -78,11 +74,9 @@
#include <sstream>
#include <iostream>
#include <stdlib.h>
// File-scope variable to capture environment variable at startup
static const char* G4Hadronic_Random_File = getenv("G4HADRONIC_RANDOM_FILE");
static const char* G4Hadronic_Random_File = std::getenv("G4HADRONIC_RANDOM_FILE");
//////////////////////////////////////////////////////////////////
@@ -134,14 +128,14 @@ void G4HadronicProcess::InitialiseLocal() {
void G4HadronicProcess::GetEnergyMomentumCheckEnvvars() {
levelsSetByProcess = false;
epReportLevel = getenv("G4Hadronic_epReportLevel") ?
strtol(getenv("G4Hadronic_epReportLevel"),0,10) : 0;
epReportLevel = std::getenv("G4Hadronic_epReportLevel") ?
std::strtol(std::getenv("G4Hadronic_epReportLevel"),0,10) : 0;
epCheckLevels.first = getenv("G4Hadronic_epCheckRelativeLevel") ?
strtod(getenv("G4Hadronic_epCheckRelativeLevel"),0) : DBL_MAX;
epCheckLevels.first = std::getenv("G4Hadronic_epCheckRelativeLevel") ?
std::strtod(std::getenv("G4Hadronic_epCheckRelativeLevel"),0) : DBL_MAX;
epCheckLevels.second = getenv("G4Hadronic_epCheckAbsoluteLevel") ?
strtod(getenv("G4Hadronic_epCheckAbsoluteLevel"),0) : DBL_MAX;
epCheckLevels.second = std::getenv("G4Hadronic_epCheckAbsoluteLevel") ?
std::strtod(std::getenv("G4Hadronic_epCheckAbsoluteLevel"),0) : DBL_MAX;
}
void G4HadronicProcess::RegisterMe( G4HadronicInteraction *a )
@@ -185,7 +179,7 @@ G4HadronicProcess::GetElementCrossSection(const G4DynamicParticle * part,
void G4HadronicProcess::PreparePhysicsTable(const G4ParticleDefinition& p)
{
if(getenv("G4HadronicProcess_debug")) {
if(std::getenv("G4HadronicProcess_debug")) {
G4HadronicProcess_debug_flag = true;
}
theProcessStore->RegisterParticle(this, &p);
@@ -261,27 +255,29 @@ G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
// Initialize the hadronic projectile from the track
thePro.Initialise(aTrack);
try
{
theInteraction =
ChooseHadronicInteraction( thePro, targetNucleus, aMaterial, anElement );
}
catch(G4HadronicException & aE)
{
theInteraction = ChooseHadronicInteraction(thePro, targetNucleus,
aMaterial, anElement);
if(!theInteraction) {
G4ExceptionDescription ed;
aE.Report(ed);
ed << "Target element "<<anElement->GetName()<<" Z= "
<< targetNucleus.GetZ_asInt() << " A= "
<< targetNucleus.GetA_asInt() << G4endl;
DumpState(aTrack,"ChooseHadronicInteraction",ed);
ed << " No HadronicInteraction found out" << G4endl;
G4Exception("G4HadronicProcess::PostStepDoIt", "had005", FatalException,
ed);
G4Exception("G4HadronicProcess::PostStepDoIt", "had005", FatalException, ed);
return theTotalResult;
}
G4HadFinalState* result = nullptr;
G4int reentryCount = 0;
/*
G4cout << "### " << aParticle->GetDefinition()->GetParticleName()
<< " Ekin(MeV)= " << aParticle->GetKineticEnergy()
<< " Z= " << targetNucleus.GetZ_asInt()
<< " A= " << targetNucleus.GetA_asInt()
<< " by " << theInteraction->GetModelName()
<< G4endl;
*/
do
{
try
@@ -442,8 +438,10 @@ G4HadronicProcess::FillResult(G4HadFinalState * aR, const G4Track & aT)
const G4ParticleDefinition* part = dynParticle->GetDefinition();
G4double mass = part->GetPDGMass();
G4double dmass= dynParticle->GetMass();
if(std::abs(dmass - mass) > 1.5*CLHEP::MeV) {
G4double e = std::max(dynParticle->GetKineticEnergy() + dmass - mass, 0.0);
const G4double delta_mass_lim = 1.0*CLHEP::keV;
const G4double delta_ekin = 0.001*CLHEP::eV;
if(std::abs(dmass - mass) > delta_mass_lim) {
G4double e = std::max(dynParticle->GetKineticEnergy() + dmass - mass, delta_ekin);
if(G4HadronicProcess_debug_flag) {
G4ExceptionDescription ed;
ed << "TrackID= "<< aT.GetTrackID()
@@ -538,7 +536,12 @@ G4HadFinalState* G4HadronicProcess::CheckResult(const G4HadProjectile & aPro,
finalE += pdyn->GetTotalEnergy();
G4double mass_pdg=pdyn->GetDefinition()->GetPDGMass();
G4double mass_dyn=pdyn->GetMass();
if ( std::abs(mass_pdg - mass_dyn) > 0.1*mass_pdg + 1.*MeV){
if ( std::abs(mass_pdg - mass_dyn) > 0.1*mass_pdg + 1.*MeV ) {
// If it is shortlived, then a difference less than 3 times the width is acceptable
if ( pdyn->GetDefinition()->IsShortLived() &&
std::abs(mass_pdg - mass_dyn) < 3.0*pdyn->GetDefinition()->GetPDGWidth() ) {
continue;
}
result->Clear();
result = nullptr;
G4ExceptionDescription desc;
@@ -615,28 +618,27 @@ G4HadronicProcess::CheckEnergyMomentumConservation(const G4Track& aTrack,
G4int nSec = theTotalResult->GetNumberOfSecondaries();
if (theTotalResult->GetTrackStatus() != fStopAndKill) { // If it is Alive
// Either interaction didn't complete, returned "do nothing" state
// or the primary survived the interaction (e.g. electro-nucleus )
G4Track temp(aTrack);
// Either interaction didn't complete, returned "do nothing" state
// or the primary survived the interaction (e.g. electro-nucleus )
// Use the final energy / momentum
temp.SetMomentumDirection(*theTotalResult->GetMomentumDirection());
temp.SetKineticEnergy(theTotalResult->GetEnergy());
// Interaction didn't complete, returned "do nothing" state
// - or suppressed recoil (e.g. Neutron elastic )
final4mom = initial4mom;
final_A = initial_A;
final_Z = initial_Z;
if (nSec > 0 && aTrack.GetDynamicParticle()) {
// The primary remains in final state (e.g. electro-nucleus )
G4Track temp(aTrack);
if( nSec == 0 ){
// Interaction didn't complete, returned "do nothing" state
// - or suppressed recoil (e.g. Neutron elastic )
final4mom = temp.GetDynamicParticle()->Get4Momentum() + target4mom;
final_A = initial_A;
final_Z = initial_Z;
}else{
// The primary remains in final state (e.g. electro-nucleus )
final4mom = temp.GetDynamicParticle()->Get4Momentum();
final_A = track_A;
final_Z = track_Z;
// Expect that the target nucleus will have interacted,
// and its products, including recoil, will be included in secondaries.
}
// Use the final energy / momentum
temp.SetMomentumDirection(*theTotalResult->GetMomentumDirection());
temp.SetKineticEnergy(theTotalResult->GetEnergy());
final4mom = temp.GetDynamicParticle()->Get4Momentum();
final_A = track_A;
final_Z = track_Z;
// Expect that the target nucleus will have interacted,
// and its products, including recoil, will be included in secondaries.
}
}
if( nSec > 0 ) {
G4Track* sec;
@@ -577,7 +577,7 @@ void G4HadronicProcessStore::PrintInfo(const G4ParticleDefinition* part)
if(buildTableStart && part == particle[n_part - 1]) {
buildTableStart = false;
Dump(verbose);
if (getenv("G4PhysListDocDir") ) DumpHtml();
if (std::getenv("G4PhysListDocDir") ) DumpHtml();
G4HadronicInteractionRegistry::Instance()->InitialiseModels();
}
}
@@ -590,8 +590,8 @@ void G4HadronicProcessStore::DumpHtml()
// List processes, models and cross sections for the most important
// particles in descending order of importance
char* dirName = getenv("G4PhysListDocDir");
char* physListName = getenv("G4PhysListName");
char* dirName = std::getenv("G4PhysListDocDir");
char* physListName = std::getenv("G4PhysListName");
if (dirName && physListName) {
// Open output file with path name
@@ -668,7 +668,7 @@ void G4HadronicProcessStore::PrintHtml(const G4ParticleDefinition* theParticle,
m_map.equal_range(theProcess);
outFile << " <ul>\n";
G4String physListName(getenv("G4PhysListName"));
G4String physListName(std::getenv("G4PhysListName"));
for (HPHImap::iterator jt = itmod.first; jt != itmod.second; ++jt) {
outFile << " <li><b><a href=\"" << physListName << "_"
@@ -720,8 +720,8 @@ void G4HadronicProcessStore::PrintHtml(const G4ParticleDefinition* theParticle,
void
G4HadronicProcessStore::PrintModelHtml(const G4HadronicInteraction * mod) const
{
G4String dirName(getenv("G4PhysListDocDir"));
G4String physListName(getenv("G4PhysListName"));
G4String dirName(std::getenv("G4PhysListDocDir"));
G4String physListName(std::getenv("G4PhysListName"));
G4String pathName = dirName + "/" + physListName + "_" + HtmlFileName(mod->GetModelName());
std::ofstream outModel;
outModel.open(pathName);