Import Geant4 11.1.0 source tree
This commit is contained in:
@@ -30,116 +30,19 @@
|
||||
|
||||
#include "G4VParticleChange.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4Track.hh"
|
||||
#include "G4Step.hh"
|
||||
#include "G4TrackFastVector.hh"
|
||||
#include "G4ExceptionSeverity.hh"
|
||||
|
||||
const G4double G4VParticleChange::accuracyForWarning = 1.0e-9;
|
||||
const G4double G4VParticleChange::accuracyForException = 0.001;
|
||||
const G4int G4VParticleChange::maxError = 10;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4VParticleChange::G4VParticleChange()
|
||||
: theSizeOftheListOfSecondaries(G4TrackFastVectorSize)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
// activate CheckIt if in VERBOSE mode
|
||||
debugFlag = true;
|
||||
#endif
|
||||
theListOfSecondaries = new G4TrackFastVector();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4VParticleChange::~G4VParticleChange()
|
||||
{
|
||||
// check if tracks still exist in theListOfSecondaries
|
||||
if(theNumberOfSecondaries > 0)
|
||||
{
|
||||
for(G4int index = 0; index < theNumberOfSecondaries; ++index)
|
||||
{
|
||||
delete(*theListOfSecondaries)[index];
|
||||
}
|
||||
}
|
||||
delete theListOfSecondaries;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4VParticleChange::G4VParticleChange(const G4VParticleChange& right)
|
||||
: theStatusChange(right.theStatusChange)
|
||||
, theSteppingControlFlag(right.theSteppingControlFlag)
|
||||
, theLocalEnergyDeposit(right.theLocalEnergyDeposit)
|
||||
, theNonIonizingEnergyDeposit(right.theNonIonizingEnergyDeposit)
|
||||
, theTrueStepLength(right.theTrueStepLength)
|
||||
, theParentWeight(right.theParentWeight)
|
||||
, theSizeOftheListOfSecondaries(G4TrackFastVectorSize)
|
||||
, verboseLevel(right.verboseLevel)
|
||||
, theFirstStepInVolume(right.theFirstStepInVolume)
|
||||
, theLastStepInVolume(right.theLastStepInVolume)
|
||||
, fSetSecondaryWeightByProcess(right.fSetSecondaryWeightByProcess)
|
||||
, debugFlag(right.debugFlag)
|
||||
{
|
||||
theListOfSecondaries = new G4TrackFastVector();
|
||||
theNumberOfSecondaries = right.theNumberOfSecondaries;
|
||||
for(G4int index = 0; index < theNumberOfSecondaries; ++index)
|
||||
{
|
||||
G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index]));
|
||||
theListOfSecondaries->SetElement(index, newTrack);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4VParticleChange& G4VParticleChange::operator=(const G4VParticleChange& right)
|
||||
{
|
||||
if(this != &right)
|
||||
{
|
||||
if(theNumberOfSecondaries > 0)
|
||||
{
|
||||
for(G4int index = 0; index < theNumberOfSecondaries; ++index)
|
||||
{
|
||||
if((*theListOfSecondaries)[index])
|
||||
delete((*theListOfSecondaries)[index]);
|
||||
}
|
||||
}
|
||||
delete theListOfSecondaries;
|
||||
|
||||
theListOfSecondaries = new G4TrackFastVector();
|
||||
theNumberOfSecondaries = right.theNumberOfSecondaries;
|
||||
for(G4int index = 0; index < theNumberOfSecondaries; ++index)
|
||||
{
|
||||
G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index]));
|
||||
theListOfSecondaries->SetElement(index, newTrack);
|
||||
}
|
||||
theStatusChange = right.theStatusChange;
|
||||
theSteppingControlFlag = right.theSteppingControlFlag;
|
||||
theLocalEnergyDeposit = right.theLocalEnergyDeposit;
|
||||
theNonIonizingEnergyDeposit = right.theNonIonizingEnergyDeposit;
|
||||
theTrueStepLength = right.theTrueStepLength;
|
||||
|
||||
theFirstStepInVolume = right.theFirstStepInVolume;
|
||||
theLastStepInVolume = right.theLastStepInVolume;
|
||||
|
||||
theParentWeight = right.theParentWeight;
|
||||
isParentWeightProposed = right.isParentWeightProposed;
|
||||
fSetSecondaryWeightByProcess = right.fSetSecondaryWeightByProcess;
|
||||
|
||||
theParentGlobalTime = right.theParentGlobalTime;
|
||||
|
||||
verboseLevel = right.verboseLevel;
|
||||
debugFlag = right.debugFlag;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4bool G4VParticleChange::operator==(const G4VParticleChange& right) const
|
||||
{
|
||||
return (this == (G4VParticleChange*) &right);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4bool G4VParticleChange::operator!=(const G4VParticleChange& right) const
|
||||
{
|
||||
return (this != (G4VParticleChange*) &right);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -148,22 +51,20 @@ void G4VParticleChange::AddSecondary(G4Track* aTrack)
|
||||
if(debugFlag)
|
||||
CheckSecondary(*aTrack);
|
||||
|
||||
if(!fSetSecondaryWeightByProcess)
|
||||
aTrack->SetWeight(theParentWeight);
|
||||
|
||||
// add a secondary after size check
|
||||
if(theSizeOftheListOfSecondaries > theNumberOfSecondaries)
|
||||
{
|
||||
// set weight of secondary tracks
|
||||
if(!fSetSecondaryWeightByProcess)
|
||||
aTrack->SetWeight(theParentWeight);
|
||||
theListOfSecondaries->SetElement(theNumberOfSecondaries, aTrack);
|
||||
++theNumberOfSecondaries;
|
||||
theListOfSecondaries[theNumberOfSecondaries] = aTrack;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete aTrack;
|
||||
|
||||
G4Exception("G4VParticleChange::AddSecondary()", "TRACK101", JustWarning,
|
||||
"Secondary buffer is full. The track is deleted!");
|
||||
theListOfSecondaries.push_back(aTrack);
|
||||
++theSizeOftheListOfSecondaries;
|
||||
}
|
||||
++theNumberOfSecondaries;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -231,27 +132,38 @@ G4Step* G4VParticleChange::UpdateStepForPostStep(G4Step* Step)
|
||||
// --------------------------------------------------------------------
|
||||
void G4VParticleChange::DumpInfo() const
|
||||
{
|
||||
// Show header
|
||||
G4int olprc = G4cout.precision(3);
|
||||
auto vol = theCurrentTrack->GetVolume();
|
||||
G4String vname = (nullptr == vol) ? "" : vol->GetName();
|
||||
G4long olprc = G4cout.precision(8);
|
||||
G4cout << " -----------------------------------------------" << G4endl;
|
||||
G4cout << " G4ParticleChange Information " << std::setw(20) << G4endl;
|
||||
G4cout << " G4VParticleChange Information " << G4endl;
|
||||
G4cout << " TrackID : " << theCurrentTrack->GetTrackID()
|
||||
<< G4endl;
|
||||
G4cout << " ParentID : " << theCurrentTrack->GetParentID()
|
||||
<< G4endl;
|
||||
G4cout << " Particle : "
|
||||
<< theCurrentTrack->GetParticleDefinition()->GetParticleName()
|
||||
<< G4endl;
|
||||
G4cout << " Kinetic energy (MeV): "
|
||||
<< theCurrentTrack->GetKineticEnergy() << G4endl;
|
||||
G4cout << " Position (mm) : "
|
||||
<< theCurrentTrack->GetPosition() << G4endl;
|
||||
G4cout << " Direction : "
|
||||
<< theCurrentTrack->GetMomentumDirection() << G4endl;
|
||||
G4cout << " PhysicsVolume : " << vname << G4endl;
|
||||
G4cout << " Material : "
|
||||
<< theCurrentTrack->GetMaterial()->GetName() << G4endl;
|
||||
G4cout << " -----------------------------------------------" << G4endl;
|
||||
|
||||
G4cout << " # of secondaries : " << std::setw(20)
|
||||
<< theNumberOfSecondaries << G4endl;
|
||||
|
||||
if (theNumberOfSecondaries > 0)
|
||||
{
|
||||
G4cout << " Pointer to 2ndaries : " << std::setw(20)
|
||||
<< GetSecondary(0) << G4endl;
|
||||
G4cout << " (Showed only 1st one)" << G4endl;
|
||||
}
|
||||
G4cout << " -----------------------------------------------" << G4endl;
|
||||
|
||||
G4cout << " Energy Deposit (MeV): " << std::setw(20)
|
||||
<< theLocalEnergyDeposit / MeV << G4endl;
|
||||
|
||||
G4cout << " Non-ionizing Energy Deposit (MeV): " << std::setw(11)
|
||||
G4cout << " NIEL Energy Deposit (MeV): " << std::setw(20)
|
||||
<< theNonIonizingEnergyDeposit / MeV << G4endl;
|
||||
|
||||
G4cout << " Track Status : " << std::setw(20);
|
||||
@@ -280,221 +192,169 @@ void G4VParticleChange::DumpInfo() const
|
||||
G4cout << " PostponeToNextEvent";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
G4cout << " True Path Length (mm) : " << std::setw(18)
|
||||
G4cout << " TruePathLength (mm) : " << std::setw(20)
|
||||
<< theTrueStepLength / mm << G4endl;
|
||||
G4cout << " Stepping Control : " << std::setw(20)
|
||||
<< theSteppingControlFlag << G4endl;
|
||||
if(theFirstStepInVolume)
|
||||
{
|
||||
G4cout << " First step in volume" << G4endl;
|
||||
G4cout << " First step in volume" << G4endl;
|
||||
}
|
||||
if(theLastStepInVolume)
|
||||
{
|
||||
G4cout << " Last step in volume" << G4endl;
|
||||
G4cout << " Last step in volume" << G4endl;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if(nError == maxError)
|
||||
{
|
||||
G4cout << " -----------------------------------------------" << G4endl;
|
||||
G4cout << " G4VParticleChange warnings closed " << G4endl;
|
||||
G4cout << " -----------------------------------------------" << G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
G4cout.precision(olprc);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4bool G4VParticleChange::CheckIt(const G4Track&
|
||||
#ifdef G4VERBOSE
|
||||
aTrack
|
||||
#endif
|
||||
)
|
||||
G4bool G4VParticleChange::CheckIt([[maybe_unused]] const G4Track& aTrack)
|
||||
{
|
||||
G4bool exitWithError = false;
|
||||
G4double accuracy;
|
||||
static G4ThreadLocal G4int nError = 0;
|
||||
#ifdef G4VERBOSE
|
||||
const G4int maxError = 30;
|
||||
#endif
|
||||
G4bool isOK = true;
|
||||
|
||||
// Energy deposit should not be negative
|
||||
G4bool itsOKforEnergy = true;
|
||||
accuracy = -1.0 * theLocalEnergyDeposit / MeV;
|
||||
if(accuracy > accuracyForWarning)
|
||||
if(theLocalEnergyDeposit < 0.0)
|
||||
{
|
||||
itsOKforEnergy = false;
|
||||
nError += 1;
|
||||
exitWithError = (accuracy > accuracyForException);
|
||||
isOK = false;
|
||||
++nError;
|
||||
#ifdef G4VERBOSE
|
||||
if(nError < maxError)
|
||||
{
|
||||
G4cout << " G4VParticleChange::CheckIt : ";
|
||||
G4cout << "the energy deposit is negative !!"
|
||||
<< " Difference: " << accuracy << "[MeV] " << G4endl;
|
||||
G4cout << aTrack.GetDefinition()->GetParticleName()
|
||||
<< " E=" << aTrack.GetKineticEnergy() / MeV
|
||||
<< " pos=" << aTrack.GetPosition().x() / m << ", "
|
||||
<< aTrack.GetPosition().y() / m << ", "
|
||||
<< aTrack.GetPosition().z() / m << G4endl;
|
||||
G4cout << " G4VParticleChange::CheckIt : ";
|
||||
G4cout << "the energy deposit " << theLocalEnergyDeposit/MeV
|
||||
<< " MeV is negative !!" << G4endl;
|
||||
}
|
||||
#endif
|
||||
theLocalEnergyDeposit = 0.0;
|
||||
}
|
||||
|
||||
// true path length should not be negative
|
||||
G4bool itsOKforStepLength = true;
|
||||
accuracy = -1.0 * theTrueStepLength / mm;
|
||||
if(accuracy > accuracyForWarning)
|
||||
if(theTrueStepLength < 0.0)
|
||||
{
|
||||
itsOKforStepLength = false;
|
||||
nError += 1;
|
||||
exitWithError = (accuracy > accuracyForException);
|
||||
isOK = false;
|
||||
++nError;
|
||||
#ifdef G4VERBOSE
|
||||
if(nError < maxError)
|
||||
{
|
||||
G4cout << " G4VParticleChange::CheckIt : ";
|
||||
G4cout << "the true step length is negative !!"
|
||||
<< " Difference: " << accuracy << "[MeV] " << G4endl;
|
||||
G4cout << aTrack.GetDefinition()->GetParticleName()
|
||||
<< " E=" << aTrack.GetKineticEnergy() / MeV
|
||||
<< " pos=" << aTrack.GetPosition().x() / m << ", "
|
||||
<< aTrack.GetPosition().y() / m << ", "
|
||||
<< aTrack.GetPosition().z() / m << G4endl;
|
||||
G4cout << " G4VParticleChange::CheckIt : ";
|
||||
G4cout << "true path length " << theTrueStepLength/mm
|
||||
<< " mm is negative !!" << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if(!itsOKforStepLength || !itsOKforEnergy)
|
||||
{
|
||||
// dump out information of this particle change
|
||||
DumpInfo();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Exit with error
|
||||
if(exitWithError)
|
||||
{
|
||||
G4Exception("G4VParticleChange::CheckIt()", "TRACK001", EventMustBeAborted,
|
||||
"Step length and/or energy deposit was illegal");
|
||||
}
|
||||
|
||||
// correction
|
||||
if(!itsOKforStepLength)
|
||||
{
|
||||
theTrueStepLength = (1.e-12) * mm;
|
||||
}
|
||||
if(!itsOKforEnergy)
|
||||
|
||||
if(!isOK)
|
||||
{
|
||||
theLocalEnergyDeposit = 0.0;
|
||||
if(nError < maxError)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
// dump out information of this particle change
|
||||
DumpInfo();
|
||||
#endif
|
||||
G4Exception("G4VParticleChange::CheckIt()", "TRACK001", JustWarning,
|
||||
"Step length and/or energy deposit are illegal");
|
||||
}
|
||||
}
|
||||
return (itsOKforStepLength && itsOKforEnergy);
|
||||
return isOK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4bool G4VParticleChange::CheckSecondary(G4Track& aTrack)
|
||||
{
|
||||
G4bool exitWithError = false;
|
||||
G4double accuracy;
|
||||
static G4ThreadLocal G4int nError = 0;
|
||||
#ifdef G4VERBOSE
|
||||
const G4int maxError = 30;
|
||||
#endif
|
||||
G4bool isOK = true;
|
||||
|
||||
// MomentumDirection should be unit vector
|
||||
G4bool itsOKforMomentum = true;
|
||||
if(aTrack.GetKineticEnergy() > 0.)
|
||||
G4double ekin = aTrack.GetKineticEnergy();
|
||||
auto dir = aTrack.GetMomentumDirection();
|
||||
G4double accuracy = std::abs(dir.mag2() - 1.0);
|
||||
if(accuracy > accuracyForWarning)
|
||||
{
|
||||
accuracy = std::fabs((aTrack.GetMomentumDirection()).mag2() - 1.0);
|
||||
if(accuracy > accuracyForWarning)
|
||||
{
|
||||
itsOKforMomentum = false;
|
||||
nError += 1;
|
||||
exitWithError = exitWithError || (accuracy > accuracyForException);
|
||||
isOK = false;
|
||||
++nError;
|
||||
#ifdef G4VERBOSE
|
||||
if(nError < maxError)
|
||||
{
|
||||
G4cout << " G4VParticleChange::CheckSecondary : ";
|
||||
G4cout << "the Momentum direction is not unit vector !! "
|
||||
<< " Difference: " << accuracy << G4endl;
|
||||
G4cout << aTrack.GetDefinition()->GetParticleName()
|
||||
<< " E=" << aTrack.GetKineticEnergy() / MeV
|
||||
<< " pos=" << aTrack.GetPosition().x() / m << ", "
|
||||
<< aTrack.GetPosition().y() / m << ", "
|
||||
<< aTrack.GetPosition().z() / m << G4endl;
|
||||
}
|
||||
#endif
|
||||
if(nError < maxError)
|
||||
{
|
||||
G4String mname = aTrack.GetCreatorModelName();
|
||||
G4cout << " G4VParticleChange::CheckSecondary : " << G4endl;
|
||||
G4cout << " the momentum direction " << dir
|
||||
<< " is not unit vector !!" << G4endl;
|
||||
G4cout << " Difference=" << accuracy
|
||||
<< " Ekin(MeV)=" << ekin/MeV
|
||||
<< " " << aTrack.GetParticleDefinition()->GetParticleName()
|
||||
<< " created by " << mname
|
||||
<< G4endl;
|
||||
}
|
||||
#endif
|
||||
aTrack.SetMomentumDirection(dir.unit());
|
||||
}
|
||||
|
||||
// Kinetic Energy should not be negative
|
||||
G4bool itsOKforEnergy = true;
|
||||
accuracy = -1.0 * (aTrack.GetKineticEnergy()) / MeV;
|
||||
if(accuracy > accuracyForWarning)
|
||||
if(ekin < 0.0)
|
||||
{
|
||||
itsOKforEnergy = false;
|
||||
nError += 1;
|
||||
exitWithError = exitWithError || (accuracy > accuracyForException);
|
||||
isOK = false;
|
||||
++nError;
|
||||
#ifdef G4VERBOSE
|
||||
if(nError < maxError)
|
||||
{
|
||||
G4cout << " G4VParticleChange::CheckSecondary : ";
|
||||
G4cout << "the kinetic energy is negative !!"
|
||||
<< " Difference: " << accuracy << "[MeV] " << G4endl;
|
||||
G4cout << " G4VParticleChange::CheckSecondary : ";
|
||||
G4cout << "the global time of secondary is earlier than the parent !!"
|
||||
<< " Difference: " << accuracy << "[ns] " << G4endl;
|
||||
G4cout << aTrack.GetDefinition()->GetParticleName()
|
||||
<< " E=" << aTrack.GetKineticEnergy() / MeV
|
||||
<< " pos=" << aTrack.GetPosition().x() / m << ", "
|
||||
<< aTrack.GetPosition().y() / m << ", "
|
||||
<< aTrack.GetPosition().z() / m << G4endl;
|
||||
G4String mname = aTrack.GetCreatorModelName();
|
||||
G4cout << " G4VParticleChange::CheckSecondary : " << G4endl;
|
||||
G4cout << " Ekin(MeV)=" << ekin << " is negative !! "
|
||||
<< aTrack.GetParticleDefinition()->GetParticleName()
|
||||
<< " created by " << mname
|
||||
<< G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// Check timing of secondaries
|
||||
G4bool itsOKforTiming = true;
|
||||
|
||||
accuracy = (theParentGlobalTime - aTrack.GetGlobalTime()) / ns;
|
||||
if(accuracy > accuracyForWarning)
|
||||
{
|
||||
itsOKforTiming = false;
|
||||
nError += 1;
|
||||
exitWithError = (accuracy > accuracyForException);
|
||||
#ifdef G4VERBOSE
|
||||
if(nError < maxError)
|
||||
{
|
||||
G4cout << " G4VParticleChange::CheckSecondary : ";
|
||||
G4cout
|
||||
<< "the global time of secondary goes back comapared to the parent !!"
|
||||
<< " Difference: " << accuracy << "[ns] " << G4endl;
|
||||
G4cout << aTrack.GetDefinition()->GetParticleName()
|
||||
<< " E=" << aTrack.GetKineticEnergy() / MeV
|
||||
<< " pos=" << aTrack.GetPosition().x() / m << ", "
|
||||
<< aTrack.GetPosition().y() / m << ", "
|
||||
<< aTrack.GetPosition().z() / m
|
||||
<< " time=" << aTrack.GetGlobalTime() / ns
|
||||
<< " parent time=" << theParentGlobalTime / ns << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Exit with error
|
||||
if(exitWithError)
|
||||
{
|
||||
G4Exception("G4VParticleChange::CheckSecondary()", "TRACK001",
|
||||
EventMustBeAborted, "Secondary with illegal energy/momentum ");
|
||||
}
|
||||
|
||||
G4bool itsOK = itsOKforMomentum && itsOKforEnergy && itsOKforTiming;
|
||||
|
||||
// correction
|
||||
if(!itsOKforMomentum)
|
||||
{
|
||||
G4double vmag = (aTrack.GetMomentumDirection()).mag();
|
||||
aTrack.SetMomentumDirection((1. / vmag) * aTrack.GetMomentumDirection());
|
||||
}
|
||||
if(!itsOKforEnergy)
|
||||
{
|
||||
aTrack.SetKineticEnergy(0.0);
|
||||
}
|
||||
|
||||
if(!itsOK)
|
||||
// Check timing of secondaries
|
||||
G4double time = aTrack.GetGlobalTime();
|
||||
if(time < theParentGlobalTime)
|
||||
{
|
||||
this->DumpInfo();
|
||||
isOK = false;
|
||||
++nError;
|
||||
#ifdef G4VERBOSE
|
||||
if(nError < maxError)
|
||||
{
|
||||
G4String mname = aTrack.GetCreatorModelName();
|
||||
G4cout << " G4VParticleChange::CheckSecondary : " << G4endl;
|
||||
G4cout << " The global time of secondary goes back compared to the parent !!" << G4endl;
|
||||
G4cout << " ParentTime(ns)=" << theParentGlobalTime/ns
|
||||
<< " SecondaryTime(ns)= " << time/ns
|
||||
<< " Difference(ns)=" << (theParentGlobalTime - time)/ns
|
||||
<< G4endl;
|
||||
G4cout << " Ekin(MeV)=" << ekin
|
||||
<< aTrack.GetParticleDefinition()->GetParticleName()
|
||||
<< " created by " << mname << G4endl;
|
||||
}
|
||||
#endif
|
||||
aTrack.SetGlobalTime(theParentGlobalTime);
|
||||
}
|
||||
|
||||
return itsOK;
|
||||
// Exit with error
|
||||
if(!isOK)
|
||||
{
|
||||
if(nError < maxError)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
DumpInfo();
|
||||
#endif
|
||||
G4Exception("G4VParticleChange::CheckSecondary()", "TRACK001",
|
||||
JustWarning, "Secondary with illegal time and/or energy and/or momentum");
|
||||
}
|
||||
}
|
||||
return isOK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user