Import Geant4 9.6.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 17:01:34 +02:00
parent b1eb5424d2
commit e2d2f9810a
10384 changed files with 698580 additions and 628834 deletions
@@ -23,8 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4HadronicProcess.cc,v 1.93 2010-12-01 02:04:39 dennis Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
// $Id$
//
// -------------------------------------------------------------------
//
@@ -36,15 +35,22 @@
// J.L. Chuma, TRIUMF, 10-Mar-1997
//
// Modifications:
// 05-Jul-2010 V.Ivanchenko cleanup commented lines
// 05-Jul-2010 V.Ivanchenko cleanup commented lines
// 20-Jul-2011 M.Kelsey -- null-pointer checks in DumpState()
// 24-Sep-2011 M.Kelsey -- Use envvar G4HADRONIC_RANDOM_FILE to save random
// engine state before each model call
// 18-Oct-2011 M.Kelsey -- Handle final-state cases in conservation checks.
// 14-Mar-2012 G.Folger -- enhance checks for conservation of energy, etc.
// 28-Jul-2012 M.Maire -- add function GetTargetDefinition()
// 14-Sep-2012 Inherit from RestDiscrete, use subtype code (now in ctor) to
// configure base-class
// 28-Sep-2012 Restore inheritance from G4VDiscreteProcess, remove enable-flag
// changing, remove warning message from original ctor.
#include "G4Types.hh"
#include "G4HadronicProcess.hh"
#include "G4Types.hh"
#include "G4SystemOfUnits.hh"
#include "G4HadProjectile.hh"
#include "G4ElementVector.hh"
#include "G4Track.hh"
@@ -64,32 +70,22 @@
#include <typeinfo>
#include <sstream>
//#include <stdlib.h>
#include <iostream>
#include <stdlib.h>
// File-scope variable to capture environment variable at startup
static const char* G4Hadronic_Random_File = getenv("G4HADRONIC_RANDOM_FILE");
// Initialize static variables for isotope production
G4IsoParticleChange * G4HadronicProcess::theIsoResult = 0;
G4IsoParticleChange * G4HadronicProcess::theOldIsoResult = 0;
G4bool G4HadronicProcess::isoIsEnabled = true;
void G4HadronicProcess::
EnableIsotopeProductionGlobally() {isoIsEnabled = true;}
void G4HadronicProcess::
DisableIsotopeProductionGlobally() {isoIsEnabled = false;}
//////////////////////////////////////////////////////////////////
G4HadronicProcess::G4HadronicProcess(const G4String& processName,
G4ProcessType aType)
:G4VDiscreteProcess(processName, aType)
G4ProcessType procType)
: G4VDiscreteProcess(processName, procType)
{
ModelingState = 0;
isoIsOnAnyway = -1;
SetProcessSubType(fHadronInelastic); // Default unless subclass changes
theTotalResult = new G4ParticleChange();
theTotalResult->SetSecondaryWeightByProcess(true);
theInteraction = 0;
@@ -98,60 +94,70 @@ G4HadronicProcess::G4HadronicProcess(const G4String& processName,
aScaleFactor = 1;
xBiasOn = false;
G4HadronicProcess_debug_flag = false;
epReportLevel = 0;
epCheckLevels.first = DBL_MAX;
epCheckLevels.second = DBL_MAX;
levelsSetByProcess = false;
// Make ep checking possible via environment variables
if ( char * ReportLevel = getenv("G4Hadronic_epReportLevel")) {
std::stringstream sRL (ReportLevel);
sRL >> epReportLevel;
//-GF we now take min of process and model levelsSetByProcess = true;
if ( char * RelativeLevel = getenv("G4Hadronic_epCheckRelativeLevel")) {
std::stringstream level(RelativeLevel);
level >> epCheckLevels.first;
}
if ( char * AbsoluteLevel = getenv("G4Hadronic_epCheckAbsoluteLevel")) {
std::stringstream level(AbsoluteLevel);
level >> epCheckLevels.second;
}
//G4cout << " Checking E/p with level " << epReportLevel
// << ", relative/absolute level = " << epCheckLevels.first << " / "<< epCheckLevels.second << G4endl;
}
GetEnergyMomentumCheckEnvvars();
}
//////////////////////////////////////////////////////////////////
G4HadronicProcess::G4HadronicProcess(const G4String& processName,
G4HadronicProcessType aHadSubType)
: G4VDiscreteProcess(processName, fHadronic)
{
SetProcessSubType(aHadSubType);
theTotalResult = new G4ParticleChange();
theTotalResult->SetSecondaryWeightByProcess(true);
theInteraction = 0;
theCrossSectionDataStore = new G4CrossSectionDataStore();
G4HadronicProcessStore::Instance()->Register(this);
aScaleFactor = 1;
xBiasOn = false;
G4HadronicProcess_debug_flag = false;
GetEnergyMomentumCheckEnvvars();
}
G4HadronicProcess::~G4HadronicProcess()
{
{
G4HadronicProcessStore::Instance()->DeRegister(this);
delete theTotalResult;
std::for_each(theProductionModels.begin(),
theProductionModels.end(), G4Delete());
delete theOldIsoResult;
delete theIsoResult;
delete theCrossSectionDataStore;
}
void G4HadronicProcess::GetEnergyMomentumCheckEnvvars() {
levelsSetByProcess = false;
epReportLevel = getenv("G4Hadronic_epReportLevel") ?
strtol(getenv("G4Hadronic_epReportLevel"),0,10) : 0;
epCheckLevels.first = getenv("G4Hadronic_epCheckRelativeLevel") ?
strtod(getenv("G4Hadronic_epCheckRelativeLevel"),0) : DBL_MAX;
epCheckLevels.second = getenv("G4Hadronic_epCheckAbsoluteLevel") ?
strtod(getenv("G4Hadronic_epCheckAbsoluteLevel"),0) : DBL_MAX;
}
void G4HadronicProcess::RegisterMe( G4HadronicInteraction *a )
{
{
if(!a) { return; }
try{GetManagerPointer()->RegisterMe( a );}
try{GetManagerPointer()->RegisterMe( a );}
catch(G4HadronicException & aE)
{
G4ExceptionDescription ed;
ed << "Unrecoverable error in " << GetProcessName()
aE.Report(ed);
ed << "Unrecoverable error in " << GetProcessName()
<< " to register " << a->GetModelName() << G4endl;
G4Exception("G4HadronicProcess::RegisterMe", "had001", FatalException,
ed);
}
G4HadronicProcessStore::Instance()->RegisterInteraction(this, a);
G4HadronicProcessStore::Instance()->RegisterInteraction(this, a);
}
void G4HadronicProcess::PreparePhysicsTable(const G4ParticleDefinition& p)
{
if(getenv("G4HadronicProcess_debug")) {
if(getenv("G4HadronicProcess_debug")) {
G4HadronicProcess_debug_flag = true;
}
G4HadronicProcessStore::Instance()->RegisterParticle(this, &p);
@@ -159,27 +165,39 @@ void G4HadronicProcess::PreparePhysicsTable(const G4ParticleDefinition& p)
void G4HadronicProcess::BuildPhysicsTable(const G4ParticleDefinition& p)
{
theCrossSectionDataStore->BuildPhysicsTable(p);
try
{
theCrossSectionDataStore->BuildPhysicsTable(p);
}
catch(G4HadronicException aR)
{
G4ExceptionDescription ed;
aR.Report(ed);
ed << " hadronic initialisation fails" << G4endl;
G4Exception("G4HadronicProcess::BuildPhysicsTable", "had000",
FatalException,ed);
}
G4HadronicProcessStore::Instance()->PrintInfo(&p);
}
G4double G4HadronicProcess::
GetMeanFreePath(const G4Track &aTrack, G4double, G4ForceCondition *)
{
{
try
{
theLastCrossSection = aScaleFactor*
theCrossSectionDataStore->GetCrossSection(aTrack.GetDynamicParticle(),
theLastCrossSection = aScaleFactor*
theCrossSectionDataStore->GetCrossSection(aTrack.GetDynamicParticle(),
aTrack.GetMaterial());
}
catch(G4HadronicException aR)
{
{
G4ExceptionDescription ed;
aR.Report(ed);
DumpState(aTrack,"GetMeanFreePath",ed);
ed << " Cross section is not available" << G4endl;
G4Exception("G4HadronicProcess::GetMeanFreePath", "had002", FatalException,
ed);
}
}
G4double res = DBL_MAX;
if( theLastCrossSection > 0.0 ) { res = 1.0/theLastCrossSection; }
return res;
@@ -189,35 +207,40 @@ G4VParticleChange*
G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
{
// if primary is not Alive then do nothing
theTotalResult->Clear();
theTotalResult->Initialize(aTrack);
theTotalResult->ProposeWeight(aTrack.GetWeight());
if(aTrack.GetTrackStatus() != fAlive) { return theTotalResult; }
// Find cross section at end of step and check if <= 0
//
const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
G4Material* aMaterial = aTrack.GetMaterial();
G4Element* anElement = 0;
try
{
anElement = theCrossSectionDataStore->SampleZandA(aParticle,
aMaterial,
anElement = theCrossSectionDataStore->SampleZandA(aParticle,
aMaterial,
targetNucleus);
}
catch(G4HadronicException & aR)
{
G4ExceptionDescription ed;
DumpState(aTrack,"SampleZandA",ed);
aR.Report(ed);
DumpState(aTrack,"SampleZandA",ed);
ed << " PostStepDoIt failed on element selection" << G4endl;
G4Exception("G4HadronicProcess::PostStepDoIt", "had003", FatalException,
ed);
}
if (GetElementCrossSection(aParticle, anElement, aMaterial) <= 0.0) {
// No interaction
//theTotalResult->Clear();
return theTotalResult;
}
// check only for charged particles
if(aParticle->GetDefinition()->GetPDGCharge() != 0.0) {
if (GetElementCrossSection(aParticle, anElement, aMaterial) <= 0.0) {
// No interaction
return theTotalResult;
}
}
// Next check for illegal track status
//
@@ -233,7 +256,6 @@ G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
G4Exception("G4HadronicProcess::PostStepDoIt", "had004", JustWarning, ed);
}
// No warning for fStopButAlive which is a legal status here
// theTotalResult->Clear();
return theTotalResult;
}
@@ -243,19 +265,20 @@ G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
G4double kineticEnergy = originalEnergy;
// Get kinetic energy per nucleon for ions
if(aParticle->GetParticleDefinition()->GetBaryonNumber() > 1.5)
if(aParticle->GetParticleDefinition()->GetBaryonNumber() > 1.5)
kineticEnergy/=aParticle->GetParticleDefinition()->GetBaryonNumber();
try
{
theInteraction =
theInteraction =
ChooseHadronicInteraction( kineticEnergy, aMaterial, anElement );
}
catch(G4HadronicException & aE)
{
G4ExceptionDescription ed;
ed << "Target element "<<anElement->GetName()<<" Z= "
<< targetNucleus.GetZ_asInt() << " A= "
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;
@@ -264,9 +287,7 @@ G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
}
// Initialize the hadronic projectile from the track
G4HadProjectile thePro(aTrack);
thePro.Initialise(aTrack);
G4HadFinalState* result = 0;
G4int reentryCount = 0;
@@ -276,7 +297,7 @@ G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
{
// Save random engine if requested for debugging
if (G4Hadronic_Random_File) {
CLHEP::HepRandom::saveEngineStatus(G4Hadronic_Random_File);
CLHEP::HepRandom::saveEngineStatus(G4Hadronic_Random_File);
}
// Call the interaction
result = theInteraction->ApplyYourself( thePro, targetNucleus);
@@ -285,25 +306,30 @@ G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
catch(G4HadronicException aR)
{
G4ExceptionDescription ed;
aR.Report(ed);
ed << "Call for " << theInteraction->GetModelName() << G4endl;
ed << "Target element "<<anElement->GetName()<<" Z= "
<< targetNucleus.GetZ_asInt()
ed << "Target element "<<anElement->GetName()<<" Z= "
<< targetNucleus.GetZ_asInt()
<< " A= " << targetNucleus.GetA_asInt() << G4endl;
DumpState(aTrack,"ApplyYourself",ed);
ed << " ApplyYourself failed" << G4endl;
G4Exception("G4HadronicProcess::PostStepDoIt", "had006", FatalException,
ed);
}
// Check the result for catastrophic energy non-conservation
result = CheckResult(thePro,targetNucleus, result);
if(reentryCount>100) {
G4ExceptionDescription ed;
ed << "Call for " << theInteraction->GetModelName() << G4endl;
ed << "Target element "<<anElement->GetName()<<" Z= "
<< targetNucleus.GetZ_asInt()
ed << "Target element "<<anElement->GetName()<<" Z= "
<< targetNucleus.GetZ_asInt()
<< " A= " << targetNucleus.GetA_asInt() << G4endl;
DumpState(aTrack,"ApplyYourself",ed);
ed << " ApplyYourself does not completed after 100 attempts" << G4endl;
G4Exception("G4HadronicProcess::PostStepDoIt", "had006", FatalException,
ed);
ed);
}
}
while(!result);
@@ -311,23 +337,10 @@ G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
result->SetTrafoToLab(thePro.GetTrafoToLab());
ClearNumberOfInteractionLengthLeft();
/*
if(isoIsOnAnyway!=-1)
{
if(isoIsEnabled||isoIsOnAnyway)
{
result = DoIsotopeCounting(result, aTrack, targetNucleus);
}
}
// Put hadronic final state particles into G4ParticleChange
FillTotalResult(result, aTrack);
*/
// VI: new method
FillResult(result, aTrack);
if (epReportLevel != 0) {
if (epReportLevel != 0) {
CheckEnergyMomentumConservation(aTrack, targetNucleus);
}
return theTotalResult;
@@ -336,104 +349,10 @@ G4HadronicProcess::PostStepDoIt(const G4Track& aTrack, const G4Step&)
void G4HadronicProcess::ProcessDescription(std::ostream& outFile) const
{
outFile << "The description for this process has not been written yet.\n";
outFile << "The description for this process has not been written yet.\n";
}
G4HadFinalState*
G4HadronicProcess::DoIsotopeCounting(G4HadFinalState * aResult,
const G4Track & aTrack,
const G4Nucleus & aNucleus)
{
// get the PC from iso-production
delete theOldIsoResult;
theOldIsoResult = 0;
delete theIsoResult;
theIsoResult = new G4IsoParticleChange;
G4bool done = false;
G4IsoResult * anIsoResult = 0;
for(unsigned int i=0; i<theProductionModels.size(); i++)
{
anIsoResult = theProductionModels[i]->GetIsotope(aTrack, aNucleus);
if(anIsoResult!=0)
{
done = true;
break;
}
}
// If no production models active, use default iso production
if(!done) anIsoResult = ExtractResidualNucleus(aTrack, aNucleus, aResult);
// Add all info explicitely and add typename from model called.
theIsoResult->SetIsotope(anIsoResult->GetIsotope());
theIsoResult->SetProductionPosition(aTrack.GetPosition());
theIsoResult->SetProductionTime(aTrack.GetGlobalTime());
theIsoResult->SetParentParticle(*aTrack.GetDynamicParticle());
theIsoResult->SetMotherNucleus(anIsoResult->GetMotherNucleus());
theIsoResult->SetProducer(typeid(*theInteraction).name());
delete anIsoResult;
// If isotope production is enabled the GetIsotopeProductionInfo()
// method must be called or else a memory leak will result
//
// The following code will fix the memory leak, but remove the
// isotope information:
//
// if(theIsoResult) {
// delete theIsoResult;
// theIsoResult = 0;
// }
return aResult;
}
G4IsoResult*
G4HadronicProcess::ExtractResidualNucleus(const G4Track&,
const G4Nucleus& aNucleus,
G4HadFinalState* aResult)
{
G4double A = aNucleus.GetA_asInt();
G4double Z = aNucleus.GetZ_asInt();
G4double bufferA = 0;
G4double bufferZ = 0;
// loop over aResult, and decrement A, Z accordingly
// cash the max
for(G4int i=0; i<aResult->GetNumberOfSecondaries(); ++i)
{
G4HadSecondary* aSecTrack = aResult->GetSecondary(i);
const G4ParticleDefinition* part = aSecTrack->GetParticle()->GetParticleDefinition();
G4double Q = part->GetPDGCharge()/eplus;
G4double N = part->GetBaryonNumber();
if(bufferA < N)
{
bufferA = N;
bufferZ = Q;
}
Z -= Q;
A -= N;
}
// if the fragment was part of the final state, it is
// assumed to be the heaviest secondary.
if(A<0.1)
{
A = bufferA;
Z = bufferZ;
}
// prepare the IsoResult.
std::ostringstream ost1;
ost1 <<Z<<"_"<<A;
G4String biff = ost1.str();
G4IsoResult * theResult = new G4IsoResult(biff, aNucleus);
return theResult;
}
G4double G4HadronicProcess::XBiasSurvivalProbability()
{
G4double result = 0;
@@ -448,17 +367,15 @@ G4double G4HadronicProcess::XBiasSecondaryWeight()
{
G4double result = 0;
G4double nLTraversed = GetTotalNumberOfInteractionLengthTraversed();
result =
result =
1./aScaleFactor*std::exp(-nLTraversed/aScaleFactor*(1-1./aScaleFactor));
return result;
}
void
void
G4HadronicProcess::FillResult(G4HadFinalState * aR, const G4Track & aT)
{
theTotalResult->Clear();
theTotalResult->Initialize(aT);
theTotalResult->ProposeLocalEnergyDeposit(aR->GetLocalEnergyDeposit());
theTotalResult->ProposeLocalEnergyDeposit(aR->GetLocalEnergyDeposit());
G4double rotation = CLHEP::twopi*G4UniformRand();
G4ThreeVector it(0., 0., 1.);
@@ -503,22 +420,26 @@ G4HadronicProcess::FillResult(G4HadFinalState * aR, const G4Track & aT)
// check secondaries: apply rotation and Lorentz transformation
G4int nSec = aR->GetNumberOfSecondaries();
theTotalResult->SetNumberOfSecondaries(nSec);
if(nSec > 0) {
G4double time0 = aT.GetGlobalTime();
for(G4int i=0; i<nSec; ++i)
{
G4LorentzVector theM = aR->GetSecondary(i)->GetParticle()->Get4Momentum();
theM.rotate(rotation, it);
theM *= aR->GetTrafoToLab();
aR->GetSecondary(i)->GetParticle()->Set4Momentum(theM);
G4double time = aR->GetSecondary(i)->GetTime();
if(time<time0) { time = time0; }
G4double weight = aT.GetWeight();
G4Track* track = new G4Track(aR->GetSecondary(i)->GetParticle(),
time,
aT.GetPosition());
G4double newWeight = aT.GetWeight()*aR->GetSecondary(i)->GetWeight();
if (nSec > 0) {
G4double time0 = aT.GetGlobalTime();
for (G4int i = 0; i < nSec; ++i) {
G4LorentzVector theM = aR->GetSecondary(i)->GetParticle()->Get4Momentum();
theM.rotate(rotation, it);
theM *= aR->GetTrafoToLab();
aR->GetSecondary(i)->GetParticle()->Set4Momentum(theM);
// time of interaction starts from zero
G4double time = aR->GetSecondary(i)->GetTime();
if (time < 0.0) { time = 0.0; }
// take into account global time
time += time0;
G4Track* track = new G4Track(aR->GetSecondary(i)->GetParticle(),
time, aT.GetPosition());
G4double newWeight = weight*aR->GetSecondary(i)->GetWeight();
// G4cout << "#### ParticleDebug "
// <<GetProcessName()<<" "
// <<aR->GetSecondary(i)->GetParticle()->GetDefinition()->GetParticleName()<<" "
@@ -529,28 +450,28 @@ G4HadronicProcess::FillResult(G4HadFinalState * aR, const G4Track & aT)
// <<aR->GetSecondary(i)->GetWeight()<<" "
// <<aR->GetSecondary(i)->GetParticle()->Get4Momentum()<<" "
// <<G4endl;
track->SetWeight(newWeight);
track->SetTouchableHandle(aT.GetTouchableHandle());
theTotalResult->AddSecondary(track);
if(G4HadronicProcess_debug_flag) {
G4double e = track->GetKineticEnergy();
if(e <= 0.0) {
G4ExceptionDescription ed;
DumpState(aT,"Secondary has zero energy",ed);
ed << "Secondary " << track->GetDefinition()->GetParticleName()
<< G4endl;
G4Exception("G4HadronicProcess::FillResults", "had011", JustWarning,ed);
}
}
track->SetWeight(newWeight);
track->SetTouchableHandle(aT.GetTouchableHandle());
theTotalResult->AddSecondary(track);
if (G4HadronicProcess_debug_flag) {
G4double e = track->GetKineticEnergy();
if (e <= 0.0) {
G4ExceptionDescription ed;
DumpState(aT,"Secondary has zero energy",ed);
ed << "Secondary " << track->GetDefinition()->GetParticleName()
<< G4endl;
G4Exception("G4HadronicProcess::FillResults", "had011", JustWarning,ed);
}
}
}
}
aR->Clear();
return;
}
void
G4HadronicProcess::FillTotalResult(G4HadFinalState * aR, const G4Track & aT)
/*
void
G4HadronicProcess::FillTotalResult(G4HadFinalState* aR, const G4Track& aT)
{
theTotalResult->Clear();
theTotalResult->ProposeLocalEnergyDeposit(0.);
@@ -595,7 +516,7 @@ G4HadronicProcess::FillTotalResult(G4HadFinalState * aR, const G4Track & aT)
G4double newM=aT.GetParticleDefinition()->GetPDGMass();
G4double newE=aR->GetEnergyChange() + newM;
G4double newP=std::sqrt(newE*newE - newM*newM);
G4DynamicParticle * aNew =
G4DynamicParticle * aNew =
new G4DynamicParticle(aT.GetParticleDefinition(), newE, newP*aR->GetMomentumChange());
aR->AddSecondary(G4HadSecondary(aNew, newWeight));
}
@@ -603,7 +524,7 @@ G4HadronicProcess::FillTotalResult(G4HadFinalState * aR, const G4Track & aT)
{
G4double newWeight = aR->GetWeightChange()*aT.GetWeight();
theTotalResult->ProposeParentWeight(newWeight); // This is multiplicative
if(aR->GetEnergyChange()>-.5)
if(aR->GetEnergyChange()>-.5)
{
theTotalResult->ProposeEnergy(aR->GetEnergyChange());
}
@@ -615,8 +536,8 @@ G4HadronicProcess::FillTotalResult(G4HadFinalState * aR, const G4Track & aT)
else
{
G4ExceptionDescription ed;
G4cout << "Call for " << theInteraction->GetModelName() << G4endl;
G4cout << "Target Z= "
ed << "Call for " << theInteraction->GetModelName() << G4endl;
ed << "Target Z= "
<< targetNucleus.GetZ_asInt()
<< " A= " << targetNucleus.GetA_asInt() << G4endl;
DumpState(aT,"FillTotalResult",ed);
@@ -631,8 +552,8 @@ G4HadronicProcess::FillTotalResult(G4HadFinalState * aR, const G4Track & aT)
// Use for debugging: G4double newWeight = theTotalResult->GetParentWeight();
G4double newKE = std::max(DBL_MIN, aR->GetEnergyChange());
G4DynamicParticle* aNew = new G4DynamicParticle(aT.GetParticleDefinition(),
aR->GetMomentumChange(),
G4DynamicParticle* aNew = new G4DynamicParticle(aT.GetParticleDefinition(),
aR->GetMomentumChange(),
newKE);
aR->AddSecondary(aNew);
aR->SetStatusChange(stopAndKill);
@@ -671,16 +592,6 @@ G4HadronicProcess::FillTotalResult(G4HadFinalState * aR, const G4Track & aT)
G4double newWeight = aT.GetWeight()*aR->GetSecondary(i)->GetWeight();
if(xBiasOn) { newWeight *= XBiasSecondaryWeight(); }
// G4cout << "#### ParticleDebug "
// <<GetProcessName()<<" "
// <<aR->GetSecondary(i)->GetParticle()->GetDefinition()->GetParticleName()<<" "
// <<aScaleFactor<<" "
// <<XBiasSurvivalProbability()<<" "
// <<XBiasSecondaryWeight()<<" "
// <<aT.GetWeight()<<" "
// <<aR->GetSecondary(i)->GetWeight()<<" "
// <<aR->GetSecondary(i)->GetParticle()->Get4Momentum()<<" "
// <<G4endl;
track->SetWeight(newWeight);
track->SetTouchableHandle(aT.GetTouchableHandle());
theTotalResult->AddSecondary(track);
@@ -689,23 +600,15 @@ G4HadronicProcess::FillTotalResult(G4HadFinalState * aR, const G4Track & aT)
aR->Clear();
return;
}
*/
G4IsoParticleChange* G4HadronicProcess::GetIsotopeProductionInfo()
{
G4IsoParticleChange * anIsoResult = theIsoResult;
if(theIsoResult) theOldIsoResult = theIsoResult;
theIsoResult = 0;
return anIsoResult;
}
void G4HadronicProcess::BiasCrossSectionByFactor(G4double aScale)
void G4HadronicProcess::BiasCrossSectionByFactor(G4double aScale)
{
xBiasOn = true;
aScaleFactor = aScale;
G4String it = GetProcessName();
if( (it != "PhotonInelastic") &&
(it != "ElectroNuclear") &&
G4String it = GetProcessName();
if( (it != "PhotonInelastic") &&
(it != "ElectroNuclear") &&
(it != "PositronNuclear") )
{
G4ExceptionDescription ed;
@@ -721,30 +624,111 @@ void G4HadronicProcess::BiasCrossSectionByFactor(G4double aScale)
}
}
void
G4HadFinalState* G4HadronicProcess::CheckResult(const G4HadProjectile & aPro,const G4Nucleus &aNucleus, G4HadFinalState * result) const
{
// check for catastrophic energy non-conservation, to re-sample the interaction
G4HadronicInteraction * theModel = GetHadronicInteraction();
G4double nuclearMass(0);
if (theModel){
// Compute final-state total energy
G4double finalE(0.);
G4int nSec = result->GetNumberOfSecondaries();
nuclearMass = G4NucleiProperties::GetNuclearMass(aNucleus.GetA_asInt(),
aNucleus.GetZ_asInt());
if (result->GetStatusChange() != stopAndKill) {
// Interaction didn't complete, returned "do nothing" state => reset nucleus
// or the primary survived the interaction (e.g. electro-nuclear ) => keep nucleus
finalE=result->GetLocalEnergyDeposit() +
aPro.GetDefinition()->GetPDGMass() + result->GetEnergyChange();
if( nSec == 0 ){
// Since there are no secondaries, there is no recoil nucleus.
// To check energy balance we must neglect the initial nucleus too.
nuclearMass=0.0;
}
}
for (G4int i = 0; i < nSec; i++) {
finalE += result->GetSecondary(i)->GetParticle()->GetTotalEnergy();
}
G4double deltaE= nuclearMass + aPro.GetTotalEnergy() - finalE;
std::pair<G4double, G4double> checkLevels = theModel->GetFatalEnergyCheckLevels(); // (relative, absolute)
if (std::abs(deltaE) > checkLevels.second && std::abs(deltaE) > checkLevels.first*aPro.GetKineticEnergy()){
// do not delete result, this is a pointer to a data member;
result=0;
G4ExceptionDescription desc;
desc << "Warning: Bad energy non-conservation detected, will "
<< (epReportLevel<0 ? "abort the event" : "re-sample the interaction") << G4endl
<< " Process / Model: " << GetProcessName()<< " / " << theModel->GetModelName() << G4endl
<< " Primary: " << aPro.GetDefinition()->GetParticleName()
<< " (" << aPro.GetDefinition()->GetPDGEncoding() << "),"
<< " E= " << aPro.Get4Momentum().e()
<< ", target nucleus (" << aNucleus.GetZ_asInt() << ","<< aNucleus.GetA_asInt() << ")" << G4endl
<< " E(initial - final) = " << deltaE << " MeV." << G4endl;
G4Exception("G4HadronicProcess:CheckResult()", "had012", epReportLevel<0 ? EventMustBeAborted : JustWarning,desc);
}
}
return result;
}
void
G4HadronicProcess::CheckEnergyMomentumConservation(const G4Track& aTrack,
const G4Nucleus& aNucleus)
{
G4double targetMass =
G4NucleiProperties::GetNuclearMass(aNucleus.GetA_asInt(),aNucleus.GetZ_asInt());
G4LorentzVector projectile4mom = aTrack.GetDynamicParticle()->Get4Momentum();
G4int target_A=aNucleus.GetA_asInt();
G4int target_Z=aNucleus.GetZ_asInt();
G4double targetMass = G4NucleiProperties::GetNuclearMass(target_A,target_Z);
G4LorentzVector target4mom(0, 0, 0, targetMass);
G4LorentzVector projectile4mom = aTrack.GetDynamicParticle()->Get4Momentum();
G4int track_A = aTrack.GetDefinition()->GetBaryonNumber();
G4int track_Z = G4lrint(aTrack.GetDefinition()->GetPDGCharge());
G4int initial_A = target_A + track_A;
G4int initial_Z = target_Z + track_Z;
G4LorentzVector initial4mom = projectile4mom + target4mom;
// Compute final-state momentum for scattering and "do nothing" results
G4LorentzVector final4mom;
if (theTotalResult->GetTrackStatus() == fStopAndKill) {
G4int final_A(0), final_Z(0);
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);
// Use the final energy / momentum
temp.SetMomentumDirection(*theTotalResult->GetMomentumDirection());
temp.SetKineticEnergy(theTotalResult->GetEnergy());
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.
}
}
if( nSec > 0 ) {
G4Track* sec;
G4int nSec = theTotalResult->GetNumberOfSecondaries();
for (G4int i = 0; i < nSec; i++) {
sec = theTotalResult->GetSecondary(i);
final4mom += sec->GetDynamicParticle()->Get4Momentum();
final_A += sec->GetDefinition()->GetBaryonNumber();
final_Z += G4lrint(sec->GetDefinition()->GetPDGCharge());
}
} else { // Interaction didn't complete, returned "do nothing" state
G4Track temp(aTrack);
temp.SetMomentumDirection(*theTotalResult->GetMomentumDirection());
temp.SetKineticEnergy(theTotalResult->GetEnergy());
final4mom = temp.GetDynamicParticle()->Get4Momentum() + target4mom;
}
// Get level-checking information (used to cut-off relative checks)
@@ -766,90 +750,107 @@ G4HadronicProcess::CheckEnergyMomentumConservation(const G4Track& aTrack,
G4double absolute = diff.e();
G4double relative = checkRelative ? absolute/aTrack.GetKineticEnergy() : 0.;
G4double absolute_mom = diff.vect().mag();
G4double relative_mom = checkRelative ? absolute_mom/aTrack.GetMomentum().mag() : 0.;
// Evaluate relative and absolute conservation
G4bool relPass = false;
G4String relResult = "fail";
if (std::abs(relative) < checkLevels.first) {
relPass = true;
relResult = checkRelative ? "pass" : "N/A";
G4bool relPass = true;
G4String relResult = "pass";
if ( std::abs(relative) > checkLevels.first
|| std::abs(relative_mom) > checkLevels.first) {
relPass = false;
relResult = checkRelative ? "fail" : "N/A";
}
G4bool absPass = false;
G4String absResult = "fail";
if (std::abs(absolute) < checkLevels.second) {
absPass = true;
absResult = "pass";
G4bool absPass = true;
G4String absResult = "pass";
if ( std::abs(absolute) > checkLevels.second
|| std::abs(absolute_mom) > checkLevels.second ) {
absPass = false ;
absResult = "fail";
}
G4bool chargePass = true;
G4String chargeResult = "pass";
if ( (initial_A-final_A)!=0
|| (initial_Z-final_Z)!=0 ) {
chargePass = checkLevels.second < DBL_MAX ? false : true;
chargeResult = "fail";
}
G4bool conservationPass = (relPass || absPass) && chargePass;
std::stringstream Myout;
G4bool Myout_notempty(false);
// Options for level of reporting detail:
// 0. off
// 1. report only when E/p not conserved
// 2. report regardless of E/p conservation
// 3. report only when E/p not conserved, with model names, process names, and limits
// 3. report only when E/p not conserved, with model names, process names, and limits
// 4. report regardless of E/p conservation, with model names, process names, and limits
// negative -1.., as above, but send output to stderr
if(std::abs(epReportLevel) == 4) {
Myout << " Process: " << processName << " , Model: " << modelName << G4endl;
Myout << " relative limit " << checkLevels.first << " relative value = "
<< relative << " " << relResult << G4endl;
Myout << " absolute limit (MeV) " << checkLevels.second/MeV << " absolute value (MeV) = "
<< absolute/MeV << " " << absResult << G4endl;
} else if(std::abs(epReportLevel) == 3) {
if (!absPass || !relPass) {
if( std::abs(epReportLevel) == 4
|| ( std::abs(epReportLevel) == 3 && ! conservationPass ) ){
Myout << " Process: " << processName << " , Model: " << modelName << G4endl;
Myout << " Primary: " << aTrack.GetParticleDefinition()->GetParticleName()
<< " (" << aTrack.GetParticleDefinition()->GetPDGEncoding() << "),"
<< " E= " << aTrack.GetDynamicParticle()->Get4Momentum().e()
<< ", target nucleus (" << aNucleus.GetZ_asInt() << ","
<< ", target nucleus (" << aNucleus.GetZ_asInt() << ","
<< aNucleus.GetA_asInt() << ")" << G4endl;
Myout << " relative limit " << checkLevels.first << " relative value = "
<< relative << " " << relResult << G4endl;
Myout << " absolute limit (MeV) " << checkLevels.second/MeV << " absolute value (MeV) = "
<< absolute/MeV << " " << absResult << G4endl;
}
} else if(std::abs(epReportLevel) == 2) {
Myout << " relative value = " << relative << " " << relPass
<< " absolute value (MeV) = " << absolute/MeV << " " << absPass << G4endl;
} else if(std::abs(epReportLevel) == 1) {
if (!absPass || !relPass) {
Myout << " relative value = " << relative << " " << relPass
<< " absolute value (MeV) = " << absolute/MeV << " " << absPass << G4endl;
}
Myout_notempty=true;
}
if ( std::abs(epReportLevel) == 4
|| std::abs(epReportLevel) == 2
|| ! conservationPass ){
Myout << " "<< relResult <<" relative, limit " << checkLevels.first << ", values E/T(0) = "
<< relative << " p/p(0)= " << relative_mom << G4endl;
Myout << " "<< absResult << " absolute, limit (MeV) " << checkLevels.second/MeV << ", values E / p (MeV) = "
<< absolute/MeV << " / " << absolute_mom/MeV << G4endl;
Myout << " "<< chargeResult << " charge/baryon number balance " << (initial_Z-final_Z) << " / " << (initial_A-final_A) << " "<< G4endl;
Myout_notempty=true;
}
Myout.flush();
if ( Myout_notempty ) {
if (epReportLevel > 0) G4cout << Myout.str()<< G4endl;
else if (epReportLevel < 0) G4cerr << Myout.str()<< G4endl;
}
if (epReportLevel > 0) G4cout << Myout.str();
else if (epReportLevel < 0) G4cerr << Myout.str();
}
void G4HadronicProcess::DumpState(const G4Track& aTrack,
void G4HadronicProcess::DumpState(const G4Track& aTrack,
const G4String& method,
G4ExceptionDescription& ed)
{
ed << "Unrecoverable error in the method " << method << " of "
ed << "Unrecoverable error in the method " << method << " of "
<< GetProcessName() << G4endl;
ed << "TrackID= "<< aTrack.GetTrackID() << " ParentID= "
ed << "TrackID= "<< aTrack.GetTrackID() << " ParentID= "
<< aTrack.GetParentID()
<< " " << aTrack.GetParticleDefinition()->GetParticleName()
<< " " << aTrack.GetParticleDefinition()->GetParticleName()
<< G4endl;
ed << "Ekin(GeV)= " << aTrack.GetKineticEnergy()/CLHEP::GeV
<< "; direction= " << aTrack.GetMomentumDirection() << G4endl;
ed << "Ekin(GeV)= " << aTrack.GetKineticEnergy()/CLHEP::GeV
<< "; direction= " << aTrack.GetMomentumDirection() << G4endl;
ed << "Position(mm)= " << aTrack.GetPosition()/CLHEP::mm << ";";
if (aTrack.GetMaterial()) {
if (aTrack.GetMaterial()) {
ed << " material " << aTrack.GetMaterial()->GetName();
}
ed << G4endl;
if (aTrack.GetVolume()) {
ed << "PhysicalVolume <" << aTrack.GetVolume()->GetName()
ed << "PhysicalVolume <" << aTrack.GetVolume()->GetName()
<< ">" << G4endl;
}
}
}
/*
G4ParticleDefinition* G4HadronicProcess::GetTargetDefinition()
{
const G4Nucleus* nuc = GetTargetNucleus();
G4int Z = nuc->GetZ_asInt();
G4int A = nuc->GetA_asInt();
return G4ParticleTable::GetParticleTable()->GetIon(Z,A,0*eV);
}
*/
/* end of file */