Import Geant4 11.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2022-12-09 14:43:28 +01:00
parent c07cea1fe0
commit 9f34590941
3810 changed files with 200490 additions and 182326 deletions
+1 -2
View File
@@ -39,14 +39,13 @@
//---------------------------------------------------------------------
G4FieldTrack* G4FieldTrackUpdator::CreateFieldTrack(const G4Track* trk)
{
G4FieldTrack* ftrk = new G4FieldTrack(
return new G4FieldTrack(
trk->GetPosition(), trk->GetGlobalTime(), trk->GetMomentumDirection(),
trk->GetKineticEnergy(), trk->GetDynamicParticle()->GetMass(),
trk->GetDynamicParticle()->GetCharge(),
trk->GetDynamicParticle()->GetPolarization(),
0.0 // magnetic dipole moment to be implemented
);
return ftrk;
}
//---------------------------------------------------------------------
+52 -335
View File
@@ -33,100 +33,12 @@
#include "G4SystemOfUnits.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include "G4TrackFastVector.hh"
#include "G4DynamicParticle.hh"
#include "G4ExceptionSeverity.hh"
// --------------------------------------------------------------------
G4ParticleChange::G4ParticleChange()
: G4VParticleChange()
{
}
// --------------------------------------------------------------------
G4ParticleChange::~G4ParticleChange()
{
}
// --------------------------------------------------------------------
G4ParticleChange::G4ParticleChange(const G4ParticleChange& right)
: G4VParticleChange(right)
{
theCurrentTrack = right.theCurrentTrack;
theMomentumDirectionChange = right.theMomentumDirectionChange;
thePolarizationChange = right.thePolarizationChange;
thePositionChange = right.thePositionChange;
theGlobalTime0 = right.theGlobalTime0;
theLocalTime0 = right.theLocalTime0;
theTimeChange = right.theTimeChange;
theProperTimeChange = right.theProperTimeChange;
theEnergyChange = right.theEnergyChange;
theVelocityChange = right.theVelocityChange;
isVelocityChanged = true;
theMassChange = right.theMassChange;
theChargeChange = right.theChargeChange;
theMagneticMomentChange = right.theMagneticMomentChange;
}
// --------------------------------------------------------------------
G4ParticleChange& G4ParticleChange::operator=(const G4ParticleChange& 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;
theCurrentTrack = right.theCurrentTrack;
theMomentumDirectionChange = right.theMomentumDirectionChange;
thePolarizationChange = right.thePolarizationChange;
thePositionChange = right.thePositionChange;
theGlobalTime0 = right.theGlobalTime0;
theLocalTime0 = right.theLocalTime0;
theTimeChange = right.theTimeChange;
theProperTimeChange = right.theProperTimeChange;
theEnergyChange = right.theEnergyChange;
theVelocityChange = right.theVelocityChange;
isVelocityChanged = true;
theMassChange = right.theMassChange;
theChargeChange = right.theChargeChange;
theMagneticMomentChange = right.theMagneticMomentChange;
theTrueStepLength = right.theTrueStepLength;
theLocalEnergyDeposit = right.theLocalEnergyDeposit;
theSteppingControlFlag = right.theSteppingControlFlag;
}
return *this;
}
// --------------------------------------------------------------------
G4bool G4ParticleChange::operator==(const G4ParticleChange& right) const
{
return ((G4VParticleChange*) this == (G4VParticleChange*) &right);
}
// --------------------------------------------------------------------
G4bool G4ParticleChange::operator!=(const G4ParticleChange& right) const
{
return ((G4VParticleChange*) this != (G4VParticleChange*) &right);
}
{}
// --------------------------------------------------------------------
void G4ParticleChange::AddSecondary(G4DynamicParticle* aParticle,
@@ -184,6 +96,7 @@ void G4ParticleChange::AddSecondary(G4DynamicParticle* aParticle,
}
// --------------------------------------------------------------------
void G4ParticleChange::AddSecondary(G4Track* aTrack)
{
// add a secondary
@@ -195,7 +108,6 @@ void G4ParticleChange::Initialize(const G4Track& track)
{
// use base class's method at first
G4VParticleChange::Initialize(track);
theCurrentTrack = &track;
// set Energy/Momentum etc. equal to those of the parent particle
const G4DynamicParticle* pParticle = track.GetDynamicParticle();
@@ -215,10 +127,9 @@ void G4ParticleChange::Initialize(const G4Track& track)
thePositionChange = track.GetPosition();
// set TimeChange equal to local time of the parent track
theTimeChange = track.GetLocalTime();
theTimeChange = theLocalTime0 = track.GetLocalTime();
// set initial Local/Global time of the parent track
theLocalTime0 = track.GetLocalTime();
// set initial global time of the parent track
theGlobalTime0 = track.GetGlobalTime();
}
@@ -236,10 +147,8 @@ G4Step* G4ParticleChange::UpdateStepForAlongStep(G4Step* pStep)
// pointer to G4ParticleMometum. Also it is a normalized
// momentum vector
G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
const G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
G4Track* pTrack = pStep->GetTrack();
G4double mass = theMassChange;
// set Mass/Charge/MagneticMoment
pPostStepPoint->SetMass(theMassChange);
@@ -256,39 +165,49 @@ G4Step* G4ParticleChange::UpdateStepForAlongStep(G4Step* pStep)
{
// calculate new momentum
G4ThreeVector pMomentum = pPostStepPoint->GetMomentum()
+ (CalcMomentum(theEnergyChange, theMomentumDirectionChange, mass)
- pPreStepPoint->GetMomentum());
G4double tMomentum = pMomentum.mag();
+ (CalcMomentum(theEnergyChange, theMomentumDirectionChange,
theMassChange) - pPreStepPoint->GetMomentum());
G4double tMomentum2 = pMomentum.mag2();
G4ThreeVector direction(1.0, 0.0, 0.0);
if(tMomentum > 0.)
if(tMomentum2 > 0.)
{
G4double inv_Momentum = 1.0 / tMomentum;
direction = pMomentum * inv_Momentum;
direction = pMomentum / std::sqrt(tMomentum2);
}
pPostStepPoint->SetMomentumDirection(direction);
pPostStepPoint->SetKineticEnergy(energy);
// if velocity is not set it should be recomputed
//
if(!isVelocityChanged)
{
if (theMassChange > 0.0)
{
theVelocityChange = CLHEP::c_light *
std::sqrt(energy*(energy + 2*theMassChange))/(energy + theMassChange);
}
else
{
// zero mass particle
theVelocityChange = CLHEP::c_light;
// optical photon case
if(theCurrentTrack->GetParticleDefinition()->GetPDGEncoding() == -22)
{
G4Track* pTrack = pStep->GetTrack();
G4double e = pTrack->GetKineticEnergy();
pTrack->SetKineticEnergy(energy);
theVelocityChange = pTrack->CalculateVelocityForOpticalPhoton();
pTrack->SetKineticEnergy(e);
}
}
}
pPostStepPoint->SetVelocity(theVelocityChange);
}
else
{
// stop case
// pPostStepPoint->SetMomentumDirection(G4ThreeVector(1., 0., 0.));
pPostStepPoint->SetKineticEnergy(0.0);
pPostStepPoint->SetVelocity(0.0);
}
// calculate velocity
if(!isVelocityChanged)
{
if(energy > 0.0)
{
pTrack->SetKineticEnergy(energy);
theVelocityChange = pTrack->CalculateVelocity();
pTrack->SetKineticEnergy(preEnergy);
}
else if(theMassChange > 0.0)
{
theVelocityChange = 0.0;
}
}
pPostStepPoint->SetVelocity(theVelocityChange);
// update polarization
pPostStepPoint->AddPolarization(thePolarizationChange -
@@ -307,8 +226,7 @@ G4Step* G4ParticleChange::UpdateStepForAlongStep(G4Step* pStep)
}
#ifdef G4VERBOSE
G4Track* aTrack = pStep->GetTrack();
if(debugFlag) { CheckIt(*aTrack); }
if(debugFlag) { CheckIt( *theCurrentTrack ); }
#endif
// update the G4Step specific attributes
@@ -334,22 +252,23 @@ G4Step* G4ParticleChange::UpdateStepForPostStep(G4Step* pStep)
// update kinetic energy and momentum direction
pPostStepPoint->SetMomentumDirection(theMomentumDirectionChange);
pPostStepPoint->SetKineticEnergy(theEnergyChange);
// calculate velocity
pTrack->SetKineticEnergy(theEnergyChange);
if(!isVelocityChanged)
if(theEnergyChange > 0.0)
{
if(theEnergyChange > 0.0)
pPostStepPoint->SetKineticEnergy(theEnergyChange);
pTrack->SetKineticEnergy(theEnergyChange);
if(!isVelocityChanged)
{
theVelocityChange = pTrack->CalculateVelocity();
}
else if(theMassChange > 0.0)
{
theVelocityChange = 0.0;
}
pPostStepPoint->SetVelocity(theVelocityChange);
}
else
{
pPostStepPoint->SetKineticEnergy(0.0);
pPostStepPoint->SetVelocity(0.0);
}
pPostStepPoint->SetVelocity(theVelocityChange);
// update polarization
pPostStepPoint->SetPolarization(thePolarizationChange);
@@ -366,8 +285,7 @@ G4Step* G4ParticleChange::UpdateStepForPostStep(G4Step* pStep)
}
#ifdef G4VERBOSE
G4Track* aTrack = pStep->GetTrack();
if(debugFlag) { CheckIt(*aTrack); }
if(debugFlag) { CheckIt( *theCurrentTrack ); }
#endif
// update the G4Step specific attributes
@@ -390,7 +308,7 @@ G4Step* G4ParticleChange::UpdateStepForAtRest(G4Step* pStep)
pPostStepPoint->SetMomentumDirection(theMomentumDirectionChange);
pPostStepPoint->SetKineticEnergy(theEnergyChange);
if(!isVelocityChanged)
theVelocityChange = pStep->GetTrack()->CalculateVelocity();
theVelocityChange = theCurrentTrack->CalculateVelocity();
pPostStepPoint->SetVelocity(theVelocityChange);
// update polarization
@@ -408,8 +326,7 @@ G4Step* G4ParticleChange::UpdateStepForAtRest(G4Step* pStep)
}
#ifdef G4VERBOSE
G4Track* aTrack = pStep->GetTrack();
if(debugFlag) { CheckIt(*aTrack); }
if(debugFlag) { CheckIt( *theCurrentTrack ); }
#endif
// update the G4Step specific attributes
@@ -422,7 +339,7 @@ void G4ParticleChange::DumpInfo() const
// use base-class DumpInfo
G4VParticleChange::DumpInfo();
G4int oldprc = G4cout.precision(3);
G4long oldprc = G4cout.precision(8);
G4cout << " Mass (GeV) : " << std::setw(20) << theMassChange / GeV
<< G4endl;
@@ -462,203 +379,3 @@ void G4ParticleChange::DumpInfo() const
<< thePolarizationChange.z() << G4endl;
G4cout.precision(oldprc);
}
// --------------------------------------------------------------------
G4bool G4ParticleChange::CheckIt(const G4Track& aTrack)
{
G4bool exitWithError = false;
G4double accuracy;
static G4ThreadLocal G4int nError = 0;
#ifdef G4VERBOSE
const G4int maxError = 30;
#endif
// no check in case of "fStopAndKill"
if(GetTrackStatus() == fStopAndKill)
return G4VParticleChange::CheckIt(aTrack);
// MomentumDirection should be unit vector
G4bool itsOKforMomentum = true;
if(theEnergyChange > 0.)
{
accuracy = std::fabs(theMomentumDirectionChange.mag2() - 1.0);
if(accuracy > accuracyForWarning)
{
itsOKforMomentum = false;
nError += 1;
exitWithError = exitWithError || (accuracy > accuracyForException);
#ifdef G4VERBOSE
if(nError < maxError)
{
G4cout << " G4ParticleChange::CheckIt : ";
G4cout << "the Momentum Change 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
}
}
// both global and proper time should not go back
G4bool itsOKforGlobalTime = true;
accuracy = (aTrack.GetLocalTime() - theTimeChange) / ns;
if(accuracy > accuracyForWarning)
{
itsOKforGlobalTime = false;
nError += 1;
exitWithError = exitWithError || (accuracy > accuracyForException);
#ifdef G4VERBOSE
if(nError < maxError)
{
G4cout << " G4ParticleChange::CheckIt : ";
G4cout << "the local time goes back !!"
<< " 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
<< " global time=" << aTrack.GetGlobalTime() / ns
<< " local time=" << aTrack.GetLocalTime() / ns
<< " proper time=" << aTrack.GetProperTime() / ns << G4endl;
}
#endif
}
G4bool itsOKforProperTime = true;
accuracy = (aTrack.GetProperTime() - theProperTimeChange) / ns;
if(accuracy > accuracyForWarning)
{
itsOKforProperTime = false;
nError += 1;
exitWithError = exitWithError || (accuracy > accuracyForException);
#ifdef G4VERBOSE
if(nError < maxError)
{
G4cout << " G4ParticleChange::CheckIt : ";
G4cout << "the proper time goes back !!"
<< " 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
<< " global time=" << aTrack.GetGlobalTime() / ns
<< " local time=" << aTrack.GetLocalTime() / ns
<< " proper time=" << aTrack.GetProperTime() / ns << G4endl;
}
#endif
}
// kinetic Energy should not be negative
G4bool itsOKforEnergy = true;
accuracy = -1.0 * theEnergyChange / MeV;
if(accuracy > accuracyForWarning)
{
itsOKforEnergy = false;
nError += 1;
exitWithError = exitWithError || (accuracy > accuracyForException);
#ifdef G4VERBOSE
if(nError < maxError)
{
G4cout << " G4ParticleChange::CheckIt : ";
G4cout << "the kinetic energy 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;
}
#endif
}
// velocity should not be less than c_light
G4bool itsOKforVelocity = true;
if(theVelocityChange < 0.)
{
itsOKforVelocity = false;
nError += 1;
exitWithError = true;
#ifdef G4VERBOSE
if(nError < maxError)
{
G4cout << " G4ParticleChange::CheckIt : ";
G4cout << "the velocity is negative !!"
<< " Velocity: " << theVelocityChange / c_light << G4endl;
G4cout << aTrack.GetDefinition()->GetParticleName()
<< " E=" << aTrack.GetKineticEnergy() / MeV
<< " pos=" << aTrack.GetPosition().x() / m << ", "
<< aTrack.GetPosition().y() / m << ", "
<< aTrack.GetPosition().z() / m << G4endl;
}
#endif
}
accuracy = theVelocityChange / c_light - 1.0;
if(accuracy > accuracyForWarning)
{
itsOKforVelocity = false;
nError += 1;
exitWithError = exitWithError || (accuracy > accuracyForException);
#ifdef G4VERBOSE
if(nError < maxError)
{
G4cout << " G4ParticleChange::CheckIt : ";
G4cout << "the velocity is greater than c_light !!" << G4endl;
G4cout << " Velocity: " << theVelocityChange / c_light << G4endl;
G4cout << aTrack.GetDefinition()->GetParticleName()
<< " E=" << aTrack.GetKineticEnergy() / MeV
<< " pos=" << aTrack.GetPosition().x() / m << ", "
<< aTrack.GetPosition().y() / m << ", "
<< aTrack.GetPosition().z() / m << G4endl;
}
#endif
}
G4bool itsOK = itsOKforMomentum && itsOKforEnergy && itsOKforVelocity &&
itsOKforProperTime && itsOKforGlobalTime;
// dump out information of this particle change
#ifdef G4VERBOSE
if(!itsOK)
{
DumpInfo();
}
#endif
// Exit with error
if(exitWithError)
{
G4Exception("G4ParticleChange::CheckIt()", "TRACK003", EventMustBeAborted,
"momentum, energy, and/or time was illegal");
}
// correction
if(!itsOKforMomentum)
{
G4double vmag = theMomentumDirectionChange.mag();
theMomentumDirectionChange = (1. / vmag) * theMomentumDirectionChange;
}
if(!itsOKforGlobalTime)
{
theTimeChange = aTrack.GetLocalTime();
}
if(!itsOKforProperTime)
{
theProperTimeChange = aTrack.GetProperTime();
}
if(!itsOKforEnergy)
{
theEnergyChange = 0.0;
}
if(!itsOKforVelocity)
{
theVelocityChange = c_light;
}
itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
return itsOK;
}
+35 -115
View File
@@ -32,81 +32,12 @@
#include "G4SystemOfUnits.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include "G4TrackFastVector.hh"
#include "G4DynamicParticle.hh"
#include "G4ExceptionSeverity.hh"
// --------------------------------------------------------------------
G4ParticleChangeForDecay::G4ParticleChangeForDecay()
: G4VParticleChange()
{
}
// --------------------------------------------------------------------
G4ParticleChangeForDecay::~G4ParticleChangeForDecay()
{
}
// --------------------------------------------------------------------
G4ParticleChangeForDecay::
G4ParticleChangeForDecay(const G4ParticleChangeForDecay& right)
: G4VParticleChange(right)
{
theGlobalTime0 = right.theGlobalTime0;
theLocalTime0 = right.theLocalTime0;
theTimeChange = right.theTimeChange;
thePolarizationChange = right.thePolarizationChange;
}
// --------------------------------------------------------------------
G4ParticleChangeForDecay&
G4ParticleChangeForDecay::operator=(const G4ParticleChangeForDecay& 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;
theTrueStepLength = right.theTrueStepLength;
theLocalEnergyDeposit = right.theLocalEnergyDeposit;
theSteppingControlFlag = right.theSteppingControlFlag;
theGlobalTime0 = right.theGlobalTime0;
theLocalTime0 = right.theLocalTime0;
theTimeChange = right.theTimeChange;
thePolarizationChange = right.thePolarizationChange;
}
return *this;
}
// --------------------------------------------------------------------
G4bool G4ParticleChangeForDecay::operator==(
const G4ParticleChangeForDecay& right) const
{
return ((G4VParticleChange*) this == (G4VParticleChange*) &right);
}
// --------------------------------------------------------------------
G4bool G4ParticleChangeForDecay::operator!=(
const G4ParticleChangeForDecay& right) const
{
return ((G4VParticleChange*) this != (G4VParticleChange*) &right);
}
{}
// --------------------------------------------------------------------
void G4ParticleChangeForDecay::Initialize(const G4Track& track)
@@ -114,17 +45,14 @@ void G4ParticleChangeForDecay::Initialize(const G4Track& track)
// use base class's method at first
G4VParticleChange::Initialize(track);
const G4DynamicParticle* pParticle = track.GetDynamicParticle();
// set TimeChange equal to local time of the parent track
theTimeChange = track.GetLocalTime();
theLocalTime0 = theTimeChange = track.GetLocalTime();
// set initial Local/Global time of the parent track
theLocalTime0 = track.GetLocalTime();
theGlobalTime0 = track.GetGlobalTime();
// set the Polarization equal to those of the parent track
thePolarizationChange = pParticle->GetPolarization();
thePolarizationChange = track.GetDynamicParticle()->GetPolarization();
}
// --------------------------------------------------------------------
@@ -159,8 +87,7 @@ G4Step* G4ParticleChangeForDecay::UpdateStepForAtRest(G4Step* pStep)
pPostStepPoint->AddProperTime(theTimeChange - theLocalTime0);
#ifdef G4VERBOSE
G4Track* aTrack = pStep->GetTrack();
if(debugFlag) { CheckIt(*aTrack); }
if(debugFlag) { CheckIt(*theCurrentTrack); }
#endif
if(isParentWeightProposed)
@@ -176,63 +103,56 @@ void G4ParticleChangeForDecay::DumpInfo() const
// Show header
G4VParticleChange::DumpInfo();
G4int oldprc = G4cout.precision(3);
G4cout << " proposed local Time (ns) : " << std::setw(20)
G4long oldprc = G4cout.precision(8);
G4cout << " -----------------------------------------------" << G4endl;
G4cout << " G4ParticleChangeForDecay proposes: " << G4endl;
G4cout << " Proposed local Time (ns): " << std::setw(20)
<< theTimeChange / ns << G4endl;
G4cout << " initial local Time (ns) : " << std::setw(20)
G4cout << " Initial local Time (ns) : " << std::setw(20)
<< theLocalTime0 / ns << G4endl;
G4cout << " initial global Time (ns) : " << std::setw(20)
G4cout << " Initial global Time (ns): " << std::setw(20)
<< theGlobalTime0 / ns << G4endl;
G4cout << " Current global Time (ns): " << std::setw(20)
<< theCurrentTrack->GetGlobalTime() / ns << G4endl;
G4cout.precision(oldprc);
}
// --------------------------------------------------------------------
G4bool G4ParticleChangeForDecay::CheckIt(const G4Track& aTrack)
{
G4bool exitWithError = false;
G4double accuracy;
// local time should not go back
G4bool itsOK = true;
accuracy = -1.0 * (theTimeChange - theLocalTime0) / ns;
if(accuracy > accuracyForWarning)
if(theTimeChange < theLocalTime0)
{
itsOK = false;
exitWithError = (accuracy > accuracyForException);
++nError;
#ifdef G4VERBOSE
G4cout << " G4ParticleChangeForDecay::CheckIt : ";
G4cout << "the local time goes back !!"
<< " Difference: " << accuracy << "[ns] " << G4endl;
G4cout << "initial local time " << theLocalTime0 / ns << "[ns] "
<< "initial global time " << theGlobalTime0 / ns << "[ns] "
<< G4endl;
G4cout << aTrack.GetDefinition()->GetParticleName()
<< " E=" << aTrack.GetKineticEnergy() / MeV
<< " pos=" << aTrack.GetPosition().x() / m << ", "
<< aTrack.GetPosition().y() / m << ", "
<< aTrack.GetPosition().z() / m << G4endl;
if(nError < maxError)
{
G4cout << " G4ParticleChangeForDecay::CheckIt : ";
G4cout << "the local time goes back !!"
<< " Difference: " << (theTimeChange - theLocalTime0) / ns
<< "[ns] " << G4endl;
G4cout << "initial local time " << theLocalTime0 / ns << "[ns] "
<< "initial global time " << theGlobalTime0 / ns << "[ns] "
<< G4endl;
}
#endif
theTimeChange = theLocalTime0;
}
// dump out information of this particle change
#ifdef G4VERBOSE
if(!itsOK) { DumpInfo(); }
#endif
// exit with error
if(exitWithError)
{
G4Exception("G4ParticleChangeForDecay::CheckIt()", "TRACK005",
EventMustBeAborted, "time was illegal");
}
// correction
if(!itsOK)
{
theTimeChange = aTrack.GetLocalTime();
if(nError < maxError)
{
#ifdef G4VERBOSE
// dump out information of this particle change
DumpInfo();
#endif
G4Exception("G4ParticleChangeForDecay::CheckIt()", "TRACK005",
JustWarning, "time is illegal");
}
}
itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
return itsOK;
return (itsOK) && G4VParticleChange::CheckIt(aTrack);
}
+22 -114
View File
@@ -37,75 +37,21 @@
#include "G4ExceptionSeverity.hh"
// --------------------------------------------------------------------
G4ParticleChangeForGamma::G4ParticleChangeForGamma()
: G4VParticleChange()
G4ParticleChangeForGamma::G4ParticleChangeForGamma()
{
theSteppingControlFlag = NormalCondition;
// Disable flag that is enabled in G4VParticleChange if G4VERBOSE.
debugFlag = false;
}
// --------------------------------------------------------------------
G4ParticleChangeForGamma::~G4ParticleChangeForGamma()
{
}
// --------------------------------------------------------------------
G4ParticleChangeForGamma::
G4ParticleChangeForGamma(const G4ParticleChangeForGamma& right)
: G4VParticleChange(right)
{
currentTrack = right.currentTrack;
proposedKinEnergy = right.proposedKinEnergy;
proposedMomentumDirection = right.proposedMomentumDirection;
proposedPolarization = right.proposedPolarization;
}
// --------------------------------------------------------------------
G4ParticleChangeForGamma&
G4ParticleChangeForGamma::operator=(const G4ParticleChangeForGamma& 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;
theLocalEnergyDeposit = right.theLocalEnergyDeposit;
theSteppingControlFlag = right.theSteppingControlFlag;
theParentWeight = right.theParentWeight;
currentTrack = right.currentTrack;
proposedKinEnergy = right.proposedKinEnergy;
proposedMomentumDirection = right.proposedMomentumDirection;
proposedPolarization = right.proposedPolarization;
}
return *this;
// Disable flag to avoid check of each secondary at each step
debugFlag = false;
}
// --------------------------------------------------------------------
void G4ParticleChangeForGamma::AddSecondary(G4DynamicParticle* aParticle)
{
// create track
G4Track* aTrack = new G4Track(aParticle, currentTrack->GetGlobalTime(),
currentTrack->GetPosition());
G4Track* aTrack = new G4Track(aParticle, theCurrentTrack->GetGlobalTime(),
theCurrentTrack->GetPosition());
// touchable handle is copied to keep the pointer
aTrack->SetTouchableHandle(currentTrack->GetTouchableHandle());
aTrack->SetTouchableHandle(theCurrentTrack->GetTouchableHandle());
// add a secondary
G4VParticleChange::AddSecondary(aTrack);
@@ -129,19 +75,26 @@ G4Step* G4ParticleChangeForGamma::UpdateStepForAtRest(G4Step* pStep)
G4Step* G4ParticleChangeForGamma::UpdateStepForPostStep(G4Step* pStep)
{
G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
G4Track* pTrack = pStep->GetTrack();
pPostStepPoint->SetKineticEnergy(proposedKinEnergy);
pPostStepPoint->SetMomentumDirection(proposedMomentumDirection);
pPostStepPoint->SetPolarization(proposedPolarization);
// update velocity for scattering process and particles with mass
if(proposedKinEnergy > 0.0)
if(proposedKinEnergy > 0.0)
{
if(pTrack->GetParticleDefinition()->GetPDGMass() > 0.0)
{
pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
pPostStepPoint->SetKineticEnergy(proposedKinEnergy);
G4double mass = theCurrentTrack->GetDefinition()->GetPDGMass();
G4double v = CLHEP::c_light;
if(mass > 0.0) {
v *= std::sqrt(proposedKinEnergy*(proposedKinEnergy + 2*mass))/
(proposedKinEnergy + mass);
}
pPostStepPoint->SetVelocity(v);
}
else
{
pPostStepPoint->SetKineticEnergy(0.0);
pPostStepPoint->SetVelocity(0.0);
}
if(isParentWeightProposed)
@@ -160,7 +113,9 @@ void G4ParticleChangeForGamma::DumpInfo() const
// use base-class DumpInfo
G4VParticleChange::DumpInfo();
G4int oldprc = G4cout.precision(3);
G4long oldprc = G4cout.precision(8);
G4cout << " -----------------------------------------------" << G4endl;
G4cout << " G4ParticleChangeForGamma proposes: " << G4endl;
G4cout << " Kinetic Energy (MeV): " << std::setw(20)
<< proposedKinEnergy / MeV << G4endl;
G4cout << " Momentum Direction: " << std::setw(20)
@@ -170,50 +125,3 @@ void G4ParticleChangeForGamma::DumpInfo() const
G4cout.precision(oldprc);
}
// --------------------------------------------------------------------
G4bool G4ParticleChangeForGamma::CheckIt(const G4Track& aTrack)
{
G4bool itsOK = true;
G4bool exitWithError = false;
G4double accuracy;
// Energy should not be lager than initial value
accuracy = (proposedKinEnergy - aTrack.GetKineticEnergy()) / MeV;
if(accuracy > accuracyForWarning)
{
itsOK = false;
exitWithError = (accuracy > accuracyForException);
#ifdef G4VERBOSE
G4cout << "G4ParticleChangeForGamma::CheckIt: ";
G4cout << "KinEnergy become larger than the initial value!"
<< " 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;
#endif
}
// dump out information of this particle change
#ifdef G4VERBOSE
if(!itsOK) { DumpInfo(); }
#endif
// Exit with error
if(exitWithError)
{
G4Exception("G4ParticleChangeForGamma::CheckIt()", "TRACK004",
EventMustBeAborted, "energy was illegal");
}
// correction
if(!itsOK)
{
proposedKinEnergy = aTrack.GetKineticEnergy();
}
itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
return itsOK;
}
+22 -130
View File
@@ -31,74 +31,13 @@
#include "G4ParticleChangeForLoss.hh"
#include "G4SystemOfUnits.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include "G4DynamicParticle.hh"
#include "G4ExceptionSeverity.hh"
// --------------------------------------------------------------------
G4ParticleChangeForLoss::G4ParticleChangeForLoss()
: G4VParticleChange()
, lowEnergyLimit(1.0 * eV)
{
theSteppingControlFlag = NormalCondition;
// Disable flag that is enabled in G4VParticleChange if G4VERBOSE.
debugFlag = false;
}
// --------------------------------------------------------------------
G4ParticleChangeForLoss::~G4ParticleChangeForLoss()
{
}
// --------------------------------------------------------------------
G4ParticleChangeForLoss::G4ParticleChangeForLoss(
const G4ParticleChangeForLoss& right)
: G4VParticleChange(right)
{
currentTrack = right.currentTrack;
proposedKinEnergy = right.proposedKinEnergy;
lowEnergyLimit = right.lowEnergyLimit;
currentCharge = right.currentCharge;
proposedMomentumDirection = right.proposedMomentumDirection;
}
// --------------------------------------------------------------------
G4ParticleChangeForLoss& G4ParticleChangeForLoss::operator=(
const G4ParticleChangeForLoss& 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;
theLocalEnergyDeposit = right.theLocalEnergyDeposit;
theSteppingControlFlag = right.theSteppingControlFlag;
theParentWeight = right.theParentWeight;
isParentWeightProposed = right.isParentWeightProposed;
fSetSecondaryWeightByProcess = right.fSetSecondaryWeightByProcess;
currentTrack = right.currentTrack;
proposedKinEnergy = right.proposedKinEnergy;
currentCharge = right.currentCharge;
proposedMomentumDirection = right.proposedMomentumDirection;
}
return *this;
debugFlag = false;
}
// --------------------------------------------------------------------
@@ -107,7 +46,9 @@ void G4ParticleChangeForLoss::DumpInfo() const
// use base-class DumpInfo
G4VParticleChange::DumpInfo();
G4int oldprc = G4cout.precision(3);
G4long oldprc = G4cout.precision(8);
G4cout << " -----------------------------------------------" << G4endl;
G4cout << " G4ParticleChangeForLoss proposes: " << G4endl;
G4cout << " Charge (eplus) : " << std::setw(20)
<< currentCharge / eplus << G4endl;
G4cout << " Kinetic Energy (MeV): " << std::setw(20)
@@ -121,82 +62,32 @@ void G4ParticleChangeForLoss::DumpInfo() const
G4cout.precision(oldprc);
}
// --------------------------------------------------------------------
G4bool G4ParticleChangeForLoss::CheckIt(const G4Track& aTrack)
{
G4bool itsOK = true;
G4bool exitWithError = false;
G4double accuracy;
// Energy should not be lager than initial value
accuracy = (proposedKinEnergy - aTrack.GetKineticEnergy()) / MeV;
if(accuracy > accuracyForWarning)
{
itsOK = false;
exitWithError = (accuracy > accuracyForException);
#ifdef G4VERBOSE
G4cout << "G4ParticleChangeForLoss::CheckIt: ";
G4cout << "KinEnergy become larger than the initial value!"
<< " 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;
#endif
}
// dump out information of this particle change
#ifdef G4VERBOSE
if(!itsOK) { DumpInfo(); }
#endif
// exit with error
if(exitWithError)
{
G4Exception("G4ParticleChangeForLoss::CheckIt()", "TRACK004",
EventMustBeAborted, "energy was illegal");
}
// correction
if(!itsOK)
{
proposedKinEnergy = aTrack.GetKineticEnergy();
}
itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
return itsOK;
}
// --------------------------------------------------------------------
G4Step* G4ParticleChangeForLoss::UpdateStepForAlongStep(G4Step* pStep)
{
const G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
G4Track* pTrack = pStep->GetTrack();
// accumulate change of the kinetic energy
G4double preKinEnergy = pPreStepPoint->GetKineticEnergy();
G4double kinEnergy =
pPostStepPoint->GetKineticEnergy() + (proposedKinEnergy - preKinEnergy);
// update kinetic energy and charge
if(kinEnergy < lowEnergyLimit)
pPostStepPoint->SetCharge(currentCharge);
// calculate velocity
if(kinEnergy > 0.0)
{
theLocalEnergyDeposit += kinEnergy;
kinEnergy = 0.0;
pPostStepPoint->SetKineticEnergy(kinEnergy);
// assuming that mass>0, zero mass particles do not have energy loss
pPostStepPoint->SetVelocity(CLHEP::c_light*ComputeBeta(kinEnergy));
}
else
{
pPostStepPoint->SetKineticEnergy(0.0);
pPostStepPoint->SetVelocity(0.0);
}
else
{
pPostStepPoint->SetCharge(currentCharge);
// calculate velocity
pTrack->SetKineticEnergy(kinEnergy);
pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
pTrack->SetKineticEnergy(preKinEnergy);
}
pPostStepPoint->SetKineticEnergy(kinEnergy);
if(isParentWeightProposed)
{
@@ -212,18 +103,19 @@ G4Step* G4ParticleChangeForLoss::UpdateStepForAlongStep(G4Step* pStep)
G4Step* G4ParticleChangeForLoss::UpdateStepForPostStep(G4Step* pStep)
{
G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
G4Track* pTrack = pStep->GetTrack();
pPostStepPoint->SetCharge(currentCharge);
pPostStepPoint->SetMomentumDirection(proposedMomentumDirection);
pPostStepPoint->SetKineticEnergy(proposedKinEnergy);
pTrack->SetKineticEnergy(proposedKinEnergy);
if(proposedKinEnergy > 0.0)
{
pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
pPostStepPoint->SetKineticEnergy(proposedKinEnergy);
// assuming that mass>0, zero mass particles do not have energy loss
pPostStepPoint->SetVelocity(CLHEP::c_light*ComputeBeta(proposedKinEnergy));
}
else
{
pPostStepPoint->SetKineticEnergy(0.0);
pPostStepPoint->SetVelocity(0.0);
}
pPostStepPoint->SetPolarization(proposedPolarization);
+2 -125
View File
@@ -27,63 +27,27 @@
//
// Author: Hisaya Kurashige, 23 March 1998
// Revision: Vladimir Ivantchenko, 16 January 2004
// 23 August 2022
// --------------------------------------------------------------------
#include "G4ParticleChangeForMSC.hh"
#include "G4SystemOfUnits.hh"
#include "G4Track.hh"
#include "G4Step.hh"
#include "G4DynamicParticle.hh"
#include "G4ExceptionSeverity.hh"
// --------------------------------------------------------------------
G4ParticleChangeForMSC::G4ParticleChangeForMSC()
: G4VParticleChange()
G4ParticleChangeForMSC::G4ParticleChangeForMSC()
{
// Disable flag that is enabled in G4VParticleChange if G4VERBOSE.
debugFlag = false;
}
// --------------------------------------------------------------------
G4ParticleChangeForMSC::~G4ParticleChangeForMSC()
{
}
// --------------------------------------------------------------------
G4ParticleChangeForMSC::
G4ParticleChangeForMSC(const G4ParticleChangeForMSC& right)
: G4VParticleChange(right)
{
theMomentumDirection = right.theMomentumDirection;
thePosition = right.thePosition;
}
// --------------------------------------------------------------------
G4ParticleChangeForMSC&
G4ParticleChangeForMSC::operator=(const G4ParticleChangeForMSC& right)
{
if(this != &right)
{
theListOfSecondaries = right.theListOfSecondaries;
theSizeOftheListOfSecondaries = right.theSizeOftheListOfSecondaries;
theNumberOfSecondaries = right.theNumberOfSecondaries;
theStatusChange = right.theStatusChange;
theLocalEnergyDeposit = right.theLocalEnergyDeposit;
theSteppingControlFlag = right.theSteppingControlFlag;
theTrueStepLength = right.theTrueStepLength;
theMomentumDirection = right.theMomentumDirection;
thePosition = right.thePosition;
}
return *this;
}
// --------------------------------------------------------------------
G4Step* G4ParticleChangeForMSC::UpdateStepForAlongStep(G4Step* pStep)
{
// update the G4Step specific attributes
pStep->SetStepLength(theTrueStepLength);
theStatusChange = pStep->GetTrack()->GetTrackStatus();
// multiple scattering calculates the final state of the particle
G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
@@ -96,90 +60,3 @@ G4Step* G4ParticleChangeForMSC::UpdateStepForAlongStep(G4Step* pStep)
return pStep;
}
// --------------------------------------------------------------------
G4Step* G4ParticleChangeForMSC::UpdateStepForPostStep(G4Step* pStep)
{
// multiple scattering calculates the final state of the particle
G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
// update momentum direction
pPostStepPoint->SetMomentumDirection(theMomentumDirection);
// update position
pPostStepPoint->SetPosition(thePosition);
// update the G4Step specific attributes
return pStep;
}
// --------------------------------------------------------------------
void G4ParticleChangeForMSC::DumpInfo() const
{
// use base-class DumpInfo
G4VParticleChange::DumpInfo();
G4int oldprc = G4cout.precision(3);
G4cout << " Position - x (mm) : " << std::setw(20)
<< thePosition.x() / mm << G4endl;
G4cout << " Position - y (mm) : " << std::setw(20)
<< thePosition.y() / mm << G4endl;
G4cout << " Position - z (mm) : " << std::setw(20)
<< thePosition.z() / mm << G4endl;
G4cout << " Momentum Direct - x : " << std::setw(20)
<< theMomentumDirection.x() << G4endl;
G4cout << " Momentum Direct - y : " << std::setw(20)
<< theMomentumDirection.y() << G4endl;
G4cout << " Momentum Direct - z : " << std::setw(20)
<< theMomentumDirection.z() << G4endl;
G4cout.precision(oldprc);
}
// --------------------------------------------------------------------
G4bool G4ParticleChangeForMSC::CheckIt(const G4Track& aTrack)
{
G4bool itsOK = true;
G4bool exitWithError = false;
G4double accuracy;
// check
// MomentumDirection should be unit vector
accuracy = std::fabs(theMomentumDirection.mag2() - 1.0);
if(accuracy > accuracyForWarning)
{
itsOK = false;
exitWithError = (accuracy > accuracyForException);
#ifdef G4VERBOSE
G4cout << " G4ParticleChangeForMSC::CheckIt : ";
G4cout << "the Momentum Change 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
}
// dump out information of this particle change
#ifdef G4VERBOSE
if(!itsOK) { DumpInfo(); }
#endif
// exit with error
if(exitWithError)
{
G4Exception("G4ParticleChangeForMSC::CheckIt()", "300", EventMustBeAborted,
"momentum direction was illegal");
}
// correction
if(!itsOK)
{
G4double vmag = theMomentumDirection.mag();
theMomentumDirection = (1. / vmag) * theMomentumDirection;
}
itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
return itsOK;
}
@@ -36,57 +36,12 @@
#include "G4DynamicParticle.hh"
// --------------------------------------------------------------------
G4ParticleChangeForTransport::G4ParticleChangeForTransport()
: G4ParticleChange()
G4ParticleChangeForTransport::G4ParticleChangeForTransport()
{
// Disable flag that is enabled in G4VParticleChange if G4VERBOSE.
debugFlag = false;
}
// --------------------------------------------------------------------
G4ParticleChangeForTransport::~G4ParticleChangeForTransport()
{
}
// --------------------------------------------------------------------
G4ParticleChangeForTransport::
G4ParticleChangeForTransport(const G4ParticleChangeForTransport& r)
: G4ParticleChange(r)
{
theTouchableHandle = r.theTouchableHandle;
isMomentumChanged = r.isMomentumChanged;
theMaterialChange = r.theMaterialChange;
theMaterialCutsCoupleChange = r.theMaterialCutsCoupleChange;
theSensitiveDetectorChange = r.theSensitiveDetectorChange;
}
// --------------------------------------------------------------------
G4ParticleChangeForTransport&
G4ParticleChangeForTransport::operator=(const G4ParticleChangeForTransport& r)
{
if(this != &r)
{
theListOfSecondaries = r.theListOfSecondaries;
theSizeOftheListOfSecondaries = r.theSizeOftheListOfSecondaries;
theNumberOfSecondaries = r.theNumberOfSecondaries;
theStatusChange = r.theStatusChange;
theTouchableHandle = r.theTouchableHandle;
theMaterialChange = r.theMaterialChange;
theMaterialCutsCoupleChange = r.theMaterialCutsCoupleChange;
theSensitiveDetectorChange = r.theSensitiveDetectorChange;
theMomentumDirectionChange = r.theMomentumDirectionChange;
thePolarizationChange = r.thePolarizationChange;
thePositionChange = r.thePositionChange;
theTimeChange = r.theTimeChange;
theEnergyChange = r.theEnergyChange;
theVelocityChange = r.theVelocityChange;
theTrueStepLength = r.theTrueStepLength;
theLocalEnergyDeposit = r.theLocalEnergyDeposit;
theSteppingControlFlag = r.theSteppingControlFlag;
}
return *this;
}
// --------------------------------------------------------------------
G4Step* G4ParticleChangeForTransport::UpdateStepForAtRest(G4Step* pStep)
{
@@ -125,13 +80,11 @@ G4Step* G4ParticleChangeForTransport::UpdateStepForAlongStep(G4Step* pStep)
pPostStepPoint->SetProperTime(theProperTimeChange);
#ifdef G4VERBOSE
G4Track* aTrack = pStep->GetTrack();
if(debugFlag) { CheckIt(*aTrack); }
if(debugFlag) { CheckIt(*theCurrentTrack); }
#endif
// Update the G4Step specific attributes
pStep->SetStepLength( theTrueStepLength );
// pStep->AddTotalEnergyDeposit( theLocalEnergyDeposit );
pStep->SetControlFlag(theSteppingControlFlag);
return pStep;
@@ -186,9 +139,6 @@ void G4ParticleChangeForTransport::DumpInfo() const
{
// use base-class DumpInfo
G4ParticleChange::DumpInfo();
G4int oldprc = G4cout.precision(3);
G4cout << " Touchable (pointer) : " << std::setw(20)
<< theTouchableHandle() << G4endl;
G4cout.precision(oldprc);
}
+7 -14
View File
@@ -47,20 +47,16 @@ G4Step::G4Step()
G4Step::~G4Step()
{
delete fpPreStepPoint;
fpPreStepPoint = nullptr;
delete fpPostStepPoint;
fpPostStepPoint = nullptr;
secondaryInCurrentStep->clear();
delete secondaryInCurrentStep;
secondaryInCurrentStep = nullptr;
if(fSecondary != nullptr)
{
fSecondary->clear();
delete fSecondary;
}
fSecondary = nullptr;
}
// --------------------------------------------------------------------
@@ -122,10 +118,8 @@ G4Step& G4Step::operator=(const G4Step& right)
secondaryInCurrentStep = right.secondaryInCurrentStep;
fpVectorOfAuxiliaryPointsPointer = right.fpVectorOfAuxiliaryPointsPointer;
if(fpPreStepPoint != nullptr)
{
delete fpPreStepPoint;
}
delete fpPreStepPoint;
if(right.fpPreStepPoint != nullptr)
{
fpPreStepPoint = new G4StepPoint(*(right.fpPreStepPoint));
@@ -134,10 +128,9 @@ G4Step& G4Step::operator=(const G4Step& right)
{
fpPreStepPoint = new G4StepPoint();
}
if(fpPostStepPoint != nullptr)
{
delete fpPostStepPoint;
}
delete fpPostStepPoint;
if(right.fpPostStepPoint != nullptr)
{
fpPostStepPoint = new G4StepPoint(*(right.fpPostStepPoint));
@@ -209,8 +202,8 @@ G4double G4Step::GetDeltaEnergy() const
const std::vector<const G4Track*>* G4Step::GetSecondaryInCurrentStep() const
{
secondaryInCurrentStep->clear();
G4int nSecondary = fSecondary->size();
for(G4int i = nSecondaryByLastStep; i < nSecondary; ++i)
std::size_t nSecondary = fSecondary->size();
for(std::size_t i = nSecondaryByLastStep; i < nSecondary; ++i)
{
secondaryInCurrentStep->push_back((*fSecondary)[i]);
}
+2 -27
View File
@@ -30,36 +30,11 @@
#include "G4StepPoint.hh"
// --------------------------------------------------------------------
G4StepPoint::G4StepPoint()
{}
// --------------------------------------------------------------------
G4StepPoint::G4StepPoint(const G4StepPoint& right)
: fPosition(right.fPosition)
, fGlobalTime(right.fGlobalTime)
, fLocalTime(right.fLocalTime)
, fProperTime(right.fProperTime)
, fMomentumDirection(right.fMomentumDirection)
, fKineticEnergy(right.fKineticEnergy)
, fVelocity(right.fVelocity)
, fpTouchable(right.fpTouchable)
, fpMaterial(right.fpMaterial)
, fpMaterialCutsCouple(right.fpMaterialCutsCouple)
, fpSensitiveDetector(right.fpSensitiveDetector)
, fSafety(right.fSafety)
, fPolarization(right.fPolarization)
, fStepStatus(right.fStepStatus)
, fpProcessDefinedStep(right.fpProcessDefinedStep)
, fMass(right.fMass)
, fCharge(right.fCharge)
, fMagneticMoment(right.fMagneticMoment)
, fWeight(right.fWeight)
{}
// --------------------------------------------------------------------
G4StepPoint& G4StepPoint::operator=(const G4StepPoint& right)
{
// NOTE: this can be removed and operator= made =default if we only expect
// rare self-assignment
if(this != &right)
{
fPosition = right.fPosition;
+6 -7
View File
@@ -51,7 +51,7 @@ G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
, fGlobalTime(aValueTime)
, fVelocity(c_light)
{
fpDynamicParticle = (apValueDynamicParticle)
fpDynamicParticle = (apValueDynamicParticle) != nullptr
? apValueDynamicParticle : new G4DynamicParticle();
// check if the particle type is Optical Photon
is_OpticalPhoton =
@@ -169,7 +169,7 @@ G4double G4Track::CalculateVelocityForOpticalPhoton() const
}
else
{
if(fpTouchable != 0)
if(fpTouchable)
{
mat = fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
}
@@ -230,11 +230,11 @@ G4Track::GetAuxiliaryTrackInformation(G4int id) const
{
if(fpAuxiliaryTrackInformationMap == nullptr)
return nullptr;
auto itr = fpAuxiliaryTrackInformationMap->find(id);
if(itr == fpAuxiliaryTrackInformationMap->cend())
return nullptr;
else
return (*itr).second;
return (*itr).second;
}
// --------------------------------------------------------------------
@@ -262,10 +262,9 @@ void G4Track::ClearAuxiliaryTrackInformation()
{
if(fpAuxiliaryTrackInformationMap == nullptr)
return;
for(auto itr = fpAuxiliaryTrackInformationMap->cbegin();
itr != fpAuxiliaryTrackInformationMap->cend(); ++itr)
for(const auto& itr : *fpAuxiliaryTrackInformationMap)
{
delete(*itr).second;
delete itr.second;
}
delete fpAuxiliaryTrackInformationMap;
fpAuxiliaryTrackInformationMap = nullptr;
+132 -272
View File
@@ -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;
}
// --------------------------------------------------------------------
+5 -11
View File
@@ -30,10 +30,6 @@
#include "G4VUserTrackInformation.hh"
// --------------------------------------------------------------------
G4VUserTrackInformation::G4VUserTrackInformation()
{}
// --------------------------------------------------------------------
G4VUserTrackInformation::G4VUserTrackInformation(const G4String& infoType)
{
@@ -43,8 +39,7 @@ G4VUserTrackInformation::G4VUserTrackInformation(const G4String& infoType)
// --------------------------------------------------------------------
G4VUserTrackInformation::~G4VUserTrackInformation()
{
if(pType != nullptr)
delete pType;
delete pType;
}
// --------------------------------------------------------------------
@@ -61,9 +56,9 @@ G4VUserTrackInformation::operator=(const G4VUserTrackInformation& right)
{
if(this != &right)
{
if(pType != nullptr)
delete pType;
if(right.pType)
delete pType;
if(right.pType != nullptr)
pType = new G4String(*(right.pType));
else
pType = nullptr;
@@ -77,6 +72,5 @@ const G4String& G4VUserTrackInformation::GetType() const
static const G4String NOTYPE = "NONE";
if(pType != nullptr)
return *pType;
else
return NOTYPE;
return NOTYPE;
}