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
+38 -2
View File
@@ -1,8 +1,44 @@
# Category track History
See `CONTRIBUTING.rst` for details of **required** info/format for each entry,
which **must** added in reverse chronological order (newest at the top). It must **not**
be used as a substitute for writing good git commit messages!
which **must** added in reverse chronological order (newest at the top).
It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2022-11-16 Gabriele Cosmo (track-V11-00-11)
- Fixed compilation warnings for implicit type conversions on macOS/XCode 14.1.
## 2022-10-31 Vladimir Ivanchenko (track-V11-00-10)
- G4ParticleChangeForMSC - fixed crash in "/tracking/verbose 6"
## 2022-09-13 Vladimir Ivanchenko (track-V11-00-09)
- 2nd round of particle change classes cleanup: improved diagnostic for
problems with primary track parameters or with secondary tracks; ensure
kinetic energy to be positive after a step; improved comments
## 2022-09-08 Makoto Asai (track-V11-00-08)
- G4Step.hh, G4Step.icc - Adding ResetPre/PostStepPoint methods to replace
StepPoint object without deleting the previous object.
## 2022-09-02 Vladimir Ivanchenko (track-V11-00-07)
- G4ParticleChangeForMSC - substitute virtual initialisation by inline
method
## 2022-08-24 Vladimir Ivanchenko (track-V11-00-06)
- General clean-up of all ParticleChange classes:
1) delete copy constructors and operators
2) removed unused methods
3) removed tracking cut 1 eV implemented inside G4ParticleChangeForLoss
4) make more effective handling of secondary tracks
5) substitute G4ParticleChangeForRadDecay by G4ParticleChangeForDecay
6) make all derived classes/methods final
7) removed commented code and useless or incorrect comments, added
improved comments
8) removed duplicated code
## 2022-06-24 Ben Morgan (track-V11-00-05)
- Initial `clang-tidy` fixes and minor simplifications
## 2022-05-25 Alberto Ribon (track-V11-00-04)
- `G4Track`: add methods to get/set information on (short-lived) parent resonance
+2 -2
View File
@@ -46,8 +46,8 @@ class G4FieldTrackUpdator
private:
G4FieldTrackUpdator() {}
~G4FieldTrackUpdator() {}
G4FieldTrackUpdator() = default;
~G4FieldTrackUpdator() = default;
};
#endif
+37 -46
View File
@@ -48,7 +48,6 @@
#include "globals.hh"
#include "G4ios.hh"
#include "G4ThreeVector.hh"
#include "G4ThreeVector.hh"
#include "G4VParticleChange.hh"
class G4DynamicParticle;
@@ -60,18 +59,17 @@ class G4ParticleChange : public G4VParticleChange
G4ParticleChange();
// Default constructor
virtual ~G4ParticleChange();
~G4ParticleChange() override = default;
// Destructor
G4bool operator==(const G4ParticleChange& right) const;
G4bool operator!=(const G4ParticleChange& right) const;
// Equality operators
G4ParticleChange(const G4ParticleChange& right) = delete;
G4ParticleChange& operator=(const G4ParticleChange& right) = delete;
// --- the following methods are for updating G4Step -----
// Return the pointer to G4Step after updating the Step information
// by using final state of the track given by a physics process
virtual G4Step* UpdateStepForAlongStep(G4Step* Step);
G4Step* UpdateStepForAlongStep(G4Step* Step) override;
// A physics process gives the final state of the particle
// relative to the initial state at the beginning of the Step,
// i.e., based on information of G4Track (or equivalently
@@ -82,12 +80,12 @@ class G4ParticleChange : public G4VParticleChange
// pointer to G4ParticleMomentum. Also it is a normalized
// momentum vector
virtual G4Step* UpdateStepForAtRest(G4Step* Step);
virtual G4Step* UpdateStepForPostStep(G4Step* Step);
G4Step* UpdateStepForAtRest(G4Step* Step) override;
G4Step* UpdateStepForPostStep(G4Step* Step) override;
// A physics process gives the final state of the particle
// based on information of G4Track (or equivalently the PreStepPoint)
virtual void Initialize(const G4Track&);
void Initialize(const G4Track&) override;
// Initialize all propoerties by using G4Track information
// --- methods to keep information of the final state ---
@@ -95,62 +93,63 @@ class G4ParticleChange : public G4VParticleChange
// The ProposeXXX methods store (and return in GetXXX methods)
// the "FINAL" values of the Position, Momentum, etc.
const G4ThreeVector* GetMomentumDirection() const;
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz);
void ProposeMomentumDirection(const G4ThreeVector& Pfinal);
inline const G4ThreeVector* GetMomentumDirection() const;
inline void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz);
inline void ProposeMomentumDirection(const G4ThreeVector& Pfinal);
// Get/Propose the MomentumDirection vector: it is the final momentum
// direction
const G4ThreeVector* GetPolarization() const;
void ProposePolarization(G4double Px, G4double Py, G4double Pz);
void ProposePolarization(const G4ThreeVector& finalPoralization);
inline const G4ThreeVector* GetPolarization() const;
inline void ProposePolarization(G4double Px, G4double Py, G4double Pz);
inline void ProposePolarization(const G4ThreeVector& finalPoralization);
// Get/Propose the final Polarization vector
G4double GetEnergy() const;
void ProposeEnergy(G4double finalEnergy);
inline G4double GetEnergy() const;
inline void ProposeEnergy(G4double finalEnergy);
// Get/Propose the final kinetic energy of the current particle
G4double GetVelocity() const;
void ProposeVelocity(G4double finalVelocity);
inline G4double GetVelocity() const;
inline void ProposeVelocity(G4double finalVelocity);
// Get/Propose the final velocity of the current particle
G4double GetProperTime() const;
void ProposeProperTime(G4double finalProperTime);
inline G4double GetProperTime() const;
inline void ProposeProperTime(G4double finalProperTime);
// Get/Propose the final ProperTime
const G4ThreeVector* GetPosition() const;
void ProposePosition(G4double x, G4double y, G4double z);
void ProposePosition(const G4ThreeVector& finalPosition);
inline const G4ThreeVector* GetPosition() const;
inline void ProposePosition(G4double x, G4double y, G4double z);
inline void ProposePosition(const G4ThreeVector& finalPosition);
// Get/Propose the final position of the current particle
void ProposeGlobalTime(G4double t);
void ProposeLocalTime(G4double t);
inline void ProposeGlobalTime(G4double t);
inline void ProposeLocalTime(G4double t);
// Get/Propose the final global/local Time.
// NOTE: DO NOT INVOKE both methods in a step
// Each method affects both local and global time
G4double GetGlobalTime(G4double timeDelay = 0.0) const;
G4double GetLocalTime(G4double timeDelay = 0.0) const;
inline G4double GetGlobalTime(G4double timeDelay = 0.0) const;
inline G4double GetLocalTime(G4double timeDelay = 0.0) const;
// Convert the time delay to the glocbal/local time.
// Can get the final global/local time without argument
G4double GetMass() const;
void ProposeMass(G4double finalMass);
inline G4double GetMass() const;
inline void ProposeMass(G4double finalMass);
// Get/Propose the final dynamical mass in G4DynamicParticle
G4double GetCharge() const;
void ProposeCharge(G4double finalCharge);
inline G4double GetCharge() const;
inline void ProposeCharge(G4double finalCharge);
// Get/Propose the final dynamical charge in G4DynamicParticle
G4double GetMagneticMoment() const;
void ProposeMagneticMoment(G4double finalMagneticMoment);
inline G4double GetMagneticMoment() const;
inline void ProposeMagneticMoment(G4double finalMagneticMoment);
// Get/Propose the final MagneticMoment in G4DynamicParticle
G4ThreeVector GetGlobalPosition(const G4ThreeVector& displacement) const;
inline G4ThreeVector
GetGlobalPosition(const G4ThreeVector& displacement) const;
// Convert the position displacement to the global position
G4ThreeVector CalcMomentum(G4double energy, G4ThreeVector direction,
G4double mass) const;
inline G4ThreeVector CalcMomentum(G4double energy, G4ThreeVector direction,
G4double mass) const;
// Calculate momentum by using Energy, Momentum Direction, and Mass
// --- methods for adding secondaries ---
@@ -175,16 +174,10 @@ class G4ParticleChange : public G4VParticleChange
// --- Dump and debug methods ---
virtual void DumpInfo() const;
virtual G4bool CheckIt(const G4Track&);
void DumpInfo() const override;
protected:
G4ParticleChange(const G4ParticleChange& right);
G4ParticleChange& operator=(const G4ParticleChange& right);
// Hidden copy constructor and assignment operator
G4Step* UpdateStepInfo(G4Step* Step);
// Update the G4Step specific attributes
// (i.e. SteppingControl, LocalEnergyDeposit, and TrueStepLength)
@@ -228,8 +221,6 @@ class G4ParticleChange : public G4VParticleChange
G4double theMagneticMomentChange = 0.0;
// The Changed (final) MagneticMoment of a given track
const G4Track* theCurrentTrack = nullptr;
};
#include "G4ParticleChange.icc"
@@ -44,29 +44,26 @@
class G4DynamicParticle;
class G4ParticleChangeForDecay : public G4VParticleChange
class G4ParticleChangeForDecay final : public G4VParticleChange
{
public:
G4ParticleChangeForDecay();
// Default constructor
virtual ~G4ParticleChangeForDecay();
// Destructor
~G4ParticleChangeForDecay() override = default;
G4bool operator==(const G4ParticleChangeForDecay& right) const;
G4bool operator!=(const G4ParticleChangeForDecay& right) const;
// Equality operators
G4ParticleChangeForDecay(const G4ParticleChangeForDecay& right) = delete;
G4ParticleChangeForDecay& operator=(const G4ParticleChangeForDecay& right) = delete;
// --- the following methods are for updating G4Step -----
// Return the pointer to the G4Step after updating the step information
// by using final state information of the track given by a physics process
// !!! No effect for AlongSteyp
virtual G4Step* UpdateStepForAtRest(G4Step* Step);
virtual G4Step* UpdateStepForPostStep(G4Step* Step);
G4Step* UpdateStepForAtRest(G4Step* Step) final;
G4Step* UpdateStepForPostStep(G4Step* Step) final;
virtual void Initialize(const G4Track&);
void Initialize(const G4Track&) final;
// Initialize all properties by using G4Track information
void ProposeGlobalTime(G4double t);
@@ -87,15 +84,11 @@ class G4ParticleChangeForDecay : public G4VParticleChange
// --- Dump and debug methods ---
virtual void DumpInfo() const;
void DumpInfo() const final;
virtual G4bool CheckIt(const G4Track&);
G4bool CheckIt(const G4Track&) final;
protected:
G4ParticleChangeForDecay(const G4ParticleChangeForDecay& right);
G4ParticleChangeForDecay& operator=(const G4ParticleChangeForDecay& right);
// Hidden copy constructor and assignment operator
private:
G4double theGlobalTime0 = 0.0;
// The global time at Initial
@@ -31,6 +31,7 @@
// Author: Hisaya Kurashige, 23 March 1998
// Revision: Vladimir Ivantchenko, 15 April 2005
// 24 August 2022
// --------------------------------------------------------------------
#ifndef G4ParticleChangeForGamma_hh
#define G4ParticleChangeForGamma_hh 1
@@ -41,67 +42,53 @@
class G4DynamicParticle;
class G4ParticleChangeForGamma : public G4VParticleChange
class G4ParticleChangeForGamma final : public G4VParticleChange
{
public:
public:
G4ParticleChangeForGamma();
// Default constructor
G4ParticleChangeForGamma();
virtual ~G4ParticleChangeForGamma();
// Destructor
~G4ParticleChangeForGamma() override = default;
G4ParticleChangeForGamma(const G4ParticleChangeForGamma& right) = delete;
G4ParticleChangeForGamma& operator=(const G4ParticleChangeForGamma& right) = delete;
// --- the following methods are for updating G4Step -----
G4Step* UpdateStepForAtRest(G4Step* pStep);
G4Step* UpdateStepForPostStep(G4Step* Step);
G4Step* UpdateStepForAtRest(G4Step* pStep) final;
G4Step* UpdateStepForPostStep(G4Step* Step) final;
// A physics process gives the final state of the particle
// based on information of G4Track
inline void InitializeForPostStep(const G4Track&);
inline void InitializeForPostStep(const G4Track&);
// Initialize all properties by using G4Track information
void AddSecondary(G4DynamicParticle* aParticle);
void AddSecondary(G4DynamicParticle* aParticle);
// Add next secondary
inline G4double GetProposedKineticEnergy() const;
inline void SetProposedKineticEnergy(G4double proposedKinEnergy);
inline G4double GetProposedKineticEnergy() const;
inline void SetProposedKineticEnergy(G4double proposedKinEnergy);
// Get/Set the final kinetic energy of the current particle
inline const G4ThreeVector& GetProposedMomentumDirection() const;
inline void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz);
inline void ProposeMomentumDirection(const G4ThreeVector& Pfinal);
// Get/Propose the MomentumDirection vector: it is the final momentum
// direction
inline const G4ThreeVector& GetProposedMomentumDirection() const;
inline void ProposeMomentumDirection(const G4ThreeVector& Pfinal);
// Get/Set the final momentum direction
inline const G4ThreeVector& GetProposedPolarization() const;
inline void ProposePolarization(const G4ThreeVector& dir);
inline void ProposePolarization(G4double Px, G4double Py, G4double Pz);
inline const G4ThreeVector& GetProposedPolarization() const;
inline void ProposePolarization(const G4ThreeVector& dir);
inline void ProposePolarization(G4double Px, G4double Py, G4double Pz);
inline const G4Track* GetCurrentTrack() const;
void DumpInfo() const override;
virtual void DumpInfo() const;
private:
virtual G4bool CheckIt(const G4Track&);
protected:
G4ParticleChangeForGamma(const G4ParticleChangeForGamma& right);
G4ParticleChangeForGamma& operator=(const G4ParticleChangeForGamma& right);
// Hidden copy constructor and assignment operator
private:
const G4Track* currentTrack = nullptr;
// The pointer to G4Track
G4double proposedKinEnergy = 0.0;
G4double proposedKinEnergy = 0.0;
// The final kinetic energy of the current particle
G4ThreeVector proposedMomentumDirection;
G4ThreeVector proposedMomentumDirection;
// The final momentum direction of the current particle
G4ThreeVector proposedPolarization;
G4ThreeVector proposedPolarization;
// The final polarization of the current particle
};
@@ -135,22 +122,6 @@ ProposeMomentumDirection(const G4ThreeVector& dir)
proposedMomentumDirection = dir;
}
inline
void G4ParticleChangeForGamma::ProposeMomentumDirection(G4double Px,
G4double Py,
G4double Pz)
{
proposedMomentumDirection.setX(Px);
proposedMomentumDirection.setY(Py);
proposedMomentumDirection.setZ(Pz);
}
inline
const G4Track* G4ParticleChangeForGamma::GetCurrentTrack() const
{
return currentTrack;
}
inline
const G4ThreeVector& G4ParticleChangeForGamma::GetProposedPolarization() const
{
@@ -176,16 +147,13 @@ void G4ParticleChangeForGamma::ProposePolarization(G4double Px,
inline
void G4ParticleChangeForGamma::InitializeForPostStep(const G4Track& track)
{
theStatusChange = track.GetTrackStatus();
theLocalEnergyDeposit = 0.0;
theNonIonizingEnergyDeposit = 0.0;
InitializeSecondaries(track);
theParentWeight = track.GetWeight();
isParentWeightProposed = false;
InitializeSecondaries();
InitializeLocalEnergyDeposit();
InitializeParentWeight(track);
InitializeStatusChange(track);
proposedKinEnergy = track.GetKineticEnergy();
proposedMomentumDirection = track.GetMomentumDirection();
proposedPolarization = track.GetPolarization();
currentTrack = &track;
}
#endif
+49 -130
View File
@@ -31,94 +31,67 @@
// Author: Hisaya Kurashige, 23 March 1998
// Revision: Vladimir Ivantchenko, 16 January 2004
// 24 August 2022
// --------------------------------------------------------------------
#ifndef G4ParticleChangeForLoss_hh
#define G4ParticleChangeForLoss_hh 1
#include "globals.hh"
#include "G4ios.hh"
#include "G4VParticleChange.hh"
#include "G4DynamicParticle.hh"
class G4DynamicParticle;
class G4ParticleChangeForLoss : public G4VParticleChange
class G4ParticleChangeForLoss final : public G4VParticleChange
{
public:
public:
G4ParticleChangeForLoss();
// Default constructor
G4ParticleChangeForLoss();
virtual ~G4ParticleChangeForLoss();
// Destructor
~G4ParticleChangeForLoss() override = default;
G4ParticleChangeForLoss(const G4ParticleChangeForLoss& right) = delete;
G4ParticleChangeForLoss& operator=(const G4ParticleChangeForLoss& right) = delete;
// --- the following methods are for updating G4Step -----
G4Step* UpdateStepForAlongStep(G4Step* Step);
G4Step* UpdateStepForPostStep(G4Step* Step);
// A physics process gives the final state of the particle
// based on information of G4Track
G4Step* UpdateStepForAlongStep(G4Step* step) final;
G4Step* UpdateStepForPostStep(G4Step* step) final;
void InitializeForAlongStep(const G4Track&);
void InitializeForPostStep(const G4Track&);
// Initialize all properties by using G4Track information
// Initialize all used properties
inline void InitializeForAlongStep(const G4Track&);
inline void InitializeForPostStep(const G4Track&);
inline G4double GetProposedCharge() const;
inline void SetProposedCharge(G4double theCharge);
// Get/Set theCharge
// Get/Set dynamic charge
inline G4double GetProposedCharge() const;
inline void SetProposedCharge(G4double theCharge);
inline G4double GetCharge() const;
inline void ProposeCharge(G4double finalCharge);
// Get/Propose the final dynamical charge in G4DynamicParticle
// Get/Set the final kinetic energy of the current particle
inline G4double GetProposedKineticEnergy() const;
inline void SetProposedKineticEnergy(G4double proposedKinEnergy);
inline G4double GetProposedKineticEnergy() const;
inline void SetProposedKineticEnergy(G4double proposedKinEnergy);
// Get/Set the final kinetic energy of the current particle
// Get/Propose the MomentumDirection vector: it is the final momentum
// direction
inline const G4ThreeVector& GetProposedMomentumDirection() const;
inline void SetProposedMomentumDirection(const G4ThreeVector& dir);
inline void ProposeMomentumDirection(const G4ThreeVector& Pfinal);
inline const G4ThreeVector& GetProposedMomentumDirection() const;
inline void SetProposedMomentumDirection(const G4ThreeVector& dir);
inline const G4ThreeVector& GetMomentumDirection() const;
inline void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz);
inline void ProposeMomentumDirection(const G4ThreeVector& Pfinal);
// Get/Propose the MomentumDirection vector: it is the final momentum
// direction
inline const G4ThreeVector& GetProposedPolarization() const;
inline void ProposePolarization(const G4ThreeVector& dir);
inline void ProposePolarization(G4double Px, G4double Py, G4double Pz);
inline const G4ThreeVector& GetProposedPolarization() const;
inline void ProposePolarization(const G4ThreeVector& dir);
inline void ProposePolarization(G4double Px, G4double Py, G4double Pz);
void DumpInfo() const final;
inline const G4Track* GetCurrentTrack() const;
private:
inline void SetLowEnergyLimit(G4double elimit);
G4double proposedKinEnergy = 0.0;
// The final kinetic energy of the current particle
virtual void DumpInfo() const;
virtual G4bool CheckIt(const G4Track&);
protected:
G4ParticleChangeForLoss(const G4ParticleChangeForLoss& right);
G4ParticleChangeForLoss& operator=(const G4ParticleChangeForLoss& right);
// Hidden copy constructor and assignment operator
private:
const G4Track* currentTrack = nullptr;
// The pointer to G4Track
G4double proposedKinEnergy = 0.0;
// The final kinetic energy of the current particle
G4double lowEnergyLimit = 0.0;
// The limit kinetic energy below which particle is stopped
G4double currentCharge = 0.0;
G4double currentCharge = 0.0;
// The final charge of the current particle
G4ThreeVector proposedMomentumDirection;
// The final momentum direction of the current particle
G4ThreeVector proposedMomentumDirection;
// The final momentum direction of the current particle
G4ThreeVector proposedPolarization;
// The final polarization of the current particle
G4ThreeVector proposedPolarization;
// The final polarization of the current particle
};
// ----------------------
@@ -137,14 +110,7 @@ void G4ParticleChangeForLoss::SetProposedKineticEnergy(G4double energy)
proposedKinEnergy = energy;
}
inline
G4double G4ParticleChangeForLoss::GetProposedCharge() const
{
return currentCharge;
}
inline
G4double G4ParticleChangeForLoss::GetCharge() const
inline G4double G4ParticleChangeForLoss::GetProposedCharge() const
{
return currentCharge;
}
@@ -155,12 +121,6 @@ void G4ParticleChangeForLoss::SetProposedCharge(G4double theCharge)
currentCharge = theCharge;
}
inline
void G4ParticleChangeForLoss::ProposeCharge(G4double theCharge)
{
currentCharge = theCharge;
}
inline
const G4ThreeVector&
G4ParticleChangeForLoss::GetProposedMomentumDirection() const
@@ -168,12 +128,6 @@ G4ParticleChangeForLoss::GetProposedMomentumDirection() const
return proposedMomentumDirection;
}
inline
const G4ThreeVector& G4ParticleChangeForLoss::GetMomentumDirection() const
{
return proposedMomentumDirection;
}
inline
void G4ParticleChangeForLoss::ProposeMomentumDirection(const G4ThreeVector& dir)
{
@@ -187,22 +141,6 @@ G4ParticleChangeForLoss::SetProposedMomentumDirection(const G4ThreeVector& dir)
proposedMomentumDirection = dir;
}
inline
void G4ParticleChangeForLoss::ProposeMomentumDirection(G4double Px,
G4double Py,
G4double Pz)
{
proposedMomentumDirection.setX(Px);
proposedMomentumDirection.setY(Py);
proposedMomentumDirection.setZ(Pz);
}
inline
const G4Track* G4ParticleChangeForLoss::GetCurrentTrack() const
{
return currentTrack;
}
inline
const G4ThreeVector& G4ParticleChangeForLoss::GetProposedPolarization() const
{
@@ -215,49 +153,30 @@ void G4ParticleChangeForLoss::ProposePolarization(const G4ThreeVector& dir)
proposedPolarization = dir;
}
inline
void G4ParticleChangeForLoss::ProposePolarization(G4double Px,
G4double Py,
G4double Pz)
inline void G4ParticleChangeForLoss::ProposePolarization(G4double Px,
G4double Py,
G4double Pz)
{
proposedPolarization.setX(Px);
proposedPolarization.setY(Py);
proposedPolarization.setZ(Pz);
proposedPolarization.set(Px, Py, Pz);
}
inline
void G4ParticleChangeForLoss::InitializeForAlongStep(const G4Track& track)
{
theStatusChange = track.GetTrackStatus();
theLocalEnergyDeposit = 0.0;
theNonIonizingEnergyDeposit = 0.0;
InitializeSecondaries(track);
theParentWeight = track.GetWeight();
// isParentWeightProposed = false;
InitializeSecondaries();
InitializeLocalEnergyDeposit();
InitializeParentWeight(track);
InitializeStatusChange(track);
proposedKinEnergy = track.GetKineticEnergy();
currentCharge = track.GetDynamicParticle()->GetCharge();
currentCharge = track.GetDynamicParticle()->GetCharge();
}
inline
void G4ParticleChangeForLoss::InitializeForPostStep(const G4Track& track)
{
theStatusChange = track.GetTrackStatus();
theLocalEnergyDeposit = 0.0;
theNonIonizingEnergyDeposit = 0.0;
InitializeSecondaries(track);
theParentWeight = track.GetWeight();
// isParentWeightProposed = false;
proposedKinEnergy = track.GetKineticEnergy();
currentCharge = track.GetDynamicParticle()->GetCharge();
InitializeForAlongStep(track);
proposedMomentumDirection = track.GetMomentumDirection();
proposedPolarization = track.GetPolarization();
currentTrack = &track;
}
inline
void G4ParticleChangeForLoss::SetLowEnergyLimit(G4double elimit)
{
lowEnergyLimit = elimit;
proposedPolarization = track.GetPolarization();
}
#endif
+53 -58
View File
@@ -31,6 +31,7 @@
// Author: Hisaya Kurashige, 23 March 1998
// Revision: Vladimir Ivantchenko, 16 January 2004
// 23 August 2022
// --------------------------------------------------------------------
#ifndef G4ParticleChangeForMSC_hh
#define G4ParticleChangeForMSC_hh 1
@@ -38,78 +39,72 @@
#include "globals.hh"
#include "G4ios.hh"
#include "G4ThreeVector.hh"
#include "G4ThreeVector.hh"
#include "G4VParticleChange.hh"
class G4DynamicParticle;
class G4ParticleChangeForMSC : public G4VParticleChange
class G4ParticleChangeForMSC final : public G4VParticleChange
{
public:
public:
G4ParticleChangeForMSC();
// Default constructor
G4ParticleChangeForMSC();
virtual ~G4ParticleChangeForMSC();
// Destructor
~G4ParticleChangeForMSC() override = default;
// --- the following methods are for updating G4Step -----
// Return the pointer to the G4Step after updating the Step information
// by using final state information of the track given by a physics
// process
G4ParticleChangeForMSC(const G4ParticleChangeForMSC& right) = delete;
G4ParticleChangeForMSC& operator=
(const G4ParticleChangeForMSC& right) = delete;
virtual G4Step* UpdateStepForAlongStep(G4Step* Step);
virtual G4Step* UpdateStepForPostStep(G4Step* Step);
// A physics process gives the final state of the particle
// based on information of G4Track (or equivalently the PreStepPoint)
// A multiple scattering process gives the final state of the particle
G4Step* UpdateStepForAlongStep(G4Step* step) final;
virtual void Initialize(const G4Track&);
// Initialize all properties by using G4Track information
// Initialise only properties changed by multiple scattering
inline void InitialiseMSC(const G4Track&, const G4Step& step);
// --- methods to keep information of the final state ---
// IMPORTANT NOTE: despite the name, what the class stores through its
// methods are the "FINAL" values of the Position,
// Momentum, etc.
inline void ProposeMomentumDirection(const G4ThreeVector& Pfinal);
inline const G4ThreeVector* GetProposedMomentumDirection() const;
void ProposeMomentumDirection(const G4ThreeVector& Pfinal);
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz);
const G4ThreeVector* GetMomentumDirection() const;
const G4ThreeVector* GetProposedMomentumDirection() const;
void SetProposedMomentumDirection(const G4ThreeVector& Pfinal);
// Get/Set theMomentumDirectionChange vector: it is the final momentum
// direction
inline void ProposePosition(const G4ThreeVector& finalPosition);
inline const G4ThreeVector& GetProposedPosition() const;
const G4ThreeVector* GetPosition() const;
void ProposePosition(const G4ThreeVector& finalPosition);
const G4ThreeVector* GetProposedPosition() const;
void SetProposedPosition(const G4ThreeVector& finalPosition);
// Get/Set the final position of the current particle
private:
// --- Dump and debug methods ---
G4ThreeVector theMomentumDirection;
// It is the vector containing the final momentum direction
// after multiple scattering is applied along step
virtual void DumpInfo() const;
virtual G4bool CheckIt(const G4Track&);
protected:
G4ParticleChangeForMSC(const G4ParticleChangeForMSC& right);
G4ParticleChangeForMSC& operator=(const G4ParticleChangeForMSC& right);
// Hidden copy constructor and assignment operator
private:
G4ThreeVector theMomentumDirection;
// It is the vector containing the final momentum direction
// after the invoked process. The application of the change
// of the momentum direction of the particle is not done here.
// The responsibility to apply the change is up the entity
// which invoked the process
G4ThreeVector thePosition;
// The changed (final) position of a given particle
G4ThreeVector thePosition;
// The changed of post step position after multiple scattering
};
#include "G4ParticleChangeForMSC.icc"
inline void G4ParticleChangeForMSC::ProposeMomentumDirection(
const G4ThreeVector& P)
{
theMomentumDirection = P;
}
inline const G4ThreeVector*
G4ParticleChangeForMSC::GetProposedMomentumDirection() const
{
return &theMomentumDirection;
}
inline void G4ParticleChangeForMSC::ProposePosition(const G4ThreeVector& P)
{
thePosition = P;
}
inline const G4ThreeVector& G4ParticleChangeForMSC::GetProposedPosition() const
{
return thePosition;
}
inline void
G4ParticleChangeForMSC::InitialiseMSC(const G4Track& track, const G4Step& step)
{
theStatusChange = track.GetTrackStatus();
auto poststep = step.GetPostStepPoint();
thePosition = poststep->GetPosition();
theMomentumDirection = poststep->GetMomentumDirection();
theCurrentTrack = &track;
}
#endif
@@ -1,89 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4ParticleChangeForMSC inline methods implementation
//
// Author: Hisaya Kurashige, 23 March 1998
// Revision: Vladimir Ivantchenko, 16 January 2004
// --------------------------------------------------------------------
inline void G4ParticleChangeForMSC::ProposeMomentumDirection(
const G4ThreeVector& P)
{
theMomentumDirection = P;
}
inline void G4ParticleChangeForMSC::SetProposedMomentumDirection(
const G4ThreeVector& P)
{
theMomentumDirection = P;
}
inline void G4ParticleChangeForMSC::ProposeMomentumDirection(G4double Px,
G4double Py,
G4double Pz)
{
theMomentumDirection.setX(Px);
theMomentumDirection.setY(Py);
theMomentumDirection.setZ(Pz);
}
inline const G4ThreeVector* G4ParticleChangeForMSC::GetMomentumDirection() const
{
return &theMomentumDirection;
}
inline const G4ThreeVector*
G4ParticleChangeForMSC::GetProposedMomentumDirection() const
{
return &theMomentumDirection;
}
inline void G4ParticleChangeForMSC::SetProposedPosition(const G4ThreeVector& P)
{
thePosition = P;
}
inline const G4ThreeVector* G4ParticleChangeForMSC::GetPosition() const
{
return &thePosition;
}
inline const G4ThreeVector* G4ParticleChangeForMSC::GetProposedPosition() const
{
return &thePosition;
}
inline void G4ParticleChangeForMSC::ProposePosition(const G4ThreeVector& P)
{
thePosition = P;
}
inline void G4ParticleChangeForMSC::Initialize(const G4Track& track)
{
theStatusChange = track.GetTrackStatus();
theMomentumDirection = track.GetMomentumDirection();
thePosition = track.GetPosition();
}
@@ -34,61 +34,8 @@
#ifndef G4ParticleChangeForRadDecay_hh
#define G4ParticleChangeForRadDecay_hh 1
#include "globals.hh"
#include "G4ios.hh"
#include "G4ParticleChangeForDecay.hh"
class G4VTouchable;
class G4ParticleChangeForRadDecay : public G4ParticleChangeForDecay
{
public:
G4ParticleChangeForRadDecay() {}
// Default constructor
virtual ~G4ParticleChangeForRadDecay() {}
// Destructor
inline void AddSecondary(G4Track* aSecondary);
// Add a secondary particle to theListOfSecondaries
protected:
inline G4ParticleChangeForRadDecay(const G4ParticleChangeForRadDecay&);
inline G4ParticleChangeForRadDecay& operator=(const G4ParticleChangeForRadDecay&);
// Hidden copy constructor and assignment operator
};
// ----------------------
// Inline methods
// ----------------------
inline G4ParticleChangeForRadDecay::
G4ParticleChangeForRadDecay(const G4ParticleChangeForRadDecay&)
: G4ParticleChangeForDecay() {}
inline
G4ParticleChangeForRadDecay&
G4ParticleChangeForRadDecay::operator=(const G4ParticleChangeForRadDecay&)
{
return *this;
}
inline
void G4ParticleChangeForRadDecay::AddSecondary(G4Track* aTrack)
{
// add a secondary after size check
if(theSizeOftheListOfSecondaries > theNumberOfSecondaries)
{
theListOfSecondaries->SetElement(theNumberOfSecondaries, aTrack);
++theNumberOfSecondaries;
}
else
{
G4Exception("G4ParticleChangeForRadDecay::AddSecondary()", "TRACK101",
JustWarning, "Secondaries buffer is full. Track is deleted!");
}
}
using G4ParticleChangeForRadDecay = G4ParticleChangeForDecay;
#endif
@@ -42,74 +42,71 @@
class G4MaterialCutsCouple;
class G4VSensitiveDetector;
class G4ParticleChangeForTransport : public G4ParticleChange
class G4ParticleChangeForTransport final : public G4ParticleChange
{
public:
G4ParticleChangeForTransport();
// Default constructor
virtual ~G4ParticleChangeForTransport();
// Destructor
~G4ParticleChangeForTransport() override = default;
G4ParticleChangeForTransport(const G4ParticleChangeForTransport& right) = delete;
G4ParticleChangeForTransport& operator=(const G4ParticleChangeForTransport& right) = delete;
// --- the following methods are for updating G4Step ---
// Return the pointer to the G4Step after updating the Step information
// by using final state information of the track given by a physics process
virtual G4Step* UpdateStepForAlongStep(G4Step* Step);
virtual G4Step* UpdateStepForAtRest(G4Step* Step);
virtual G4Step* UpdateStepForPostStep(G4Step* Step);
G4Step* UpdateStepForAlongStep(G4Step* Step) final;
G4Step* UpdateStepForAtRest(G4Step* Step) final;
G4Step* UpdateStepForPostStep(G4Step* Step) final;
// A physics process gives the final state of the particle
// based on information of G4Track (or equivalently the PreStepPoint)
virtual void Initialize(const G4Track&);
void Initialize(const G4Track&) final;
// Initialize all properties by using G4Track information
// --- methods to keep information of the final state ---
// IMPORTANT NOTE: despite the name, what this class stores/returns
// through its methods, are the "FINAL" values of the Position, Momentum, etc.
const G4TouchableHandle& GetTouchableHandle() const;
void SetTouchableHandle(const G4TouchableHandle& fTouchable);
inline const G4TouchableHandle& GetTouchableHandle() const;
inline void SetTouchableHandle(const G4TouchableHandle& fTouchable);
// Get/Set the touchable of the current particle.
// Note: Touchable in PostStepPoint will be updated only after
// PostStepDoIt
G4Material* GetMaterialInTouchable() const;
void SetMaterialInTouchable(G4Material* fMaterial);
inline G4Material* GetMaterialInTouchable() const;
inline void SetMaterialInTouchable(G4Material* fMaterial);
// Get/Propose the material in the touchable of the current particle
const G4MaterialCutsCouple* GetMaterialCutsCoupleInTouchable() const;
void SetMaterialCutsCoupleInTouchable(
inline const G4MaterialCutsCouple* GetMaterialCutsCoupleInTouchable() const;
inline void SetMaterialCutsCoupleInTouchable(
const G4MaterialCutsCouple* fMaterialCutsCouple);
// Get/Set the materialCutsCouple in the touchable of the current
// particle
G4VSensitiveDetector* GetSensitiveDetectorInTouchable() const;
void SetSensitiveDetectorInTouchable(
inline G4VSensitiveDetector* GetSensitiveDetectorInTouchable() const;
inline void SetSensitiveDetectorInTouchable(
G4VSensitiveDetector* fSensitiveDetector);
// Get/Set the sensitive detector in the touchable of the current particle
G4bool GetMomentumChanged() const;
void SetMomentumChanged(G4bool b);
inline G4bool GetMomentumChanged() const;
inline void SetMomentumChanged(G4bool b);
inline void SetPointerToVectorOfAuxiliaryPoints(std::vector<G4ThreeVector>* vec);
inline std::vector<G4ThreeVector>* GetPointerToVectorOfAuxiliaryPoints() const;
inline void
SetPointerToVectorOfAuxiliaryPoints(std::vector<G4ThreeVector>* vec);
inline std::vector<G4ThreeVector>*
GetPointerToVectorOfAuxiliaryPoints() const;
// Smooth representation of curved trajectories
virtual void DumpInfo() const;
void DumpInfo() const final;
protected:
G4ParticleChangeForTransport(const G4ParticleChangeForTransport& right);
G4ParticleChangeForTransport& operator=(const G4ParticleChangeForTransport& right);
// Hidden copy constructor and assignment operator
private:
G4TouchableHandle theTouchableHandle;
// The changed touchable of a given particle
private:
G4bool isMomentumChanged = false;
// The flag which is set if momentum is changed in current step
@@ -93,38 +93,18 @@ inline void G4ParticleChangeForTransport::Initialize(const G4Track& track)
{
// use base class's method at first
InitializeStatusChange(track);
// InitializeLocalEnergyDeposit(track);
InitializeSteppingControl(track);
// InitializeTrueStepLength(track);
// InitializeSecondaries(track);
InitializeSteppingControl();
// set Energy/Momentum etc. equal to those of the parent particle
const G4DynamicParticle* pParticle = track.GetDynamicParticle();
// theEnergyChange = pParticle->GetKineticEnergy();
// theMomentumChange = pParticle->GetMomentumDirection();
theVelocityChange = track.GetVelocity();
isVelocityChanged = false;
thePolarizationChange = pParticle->GetPolarization();
// theProperTimeChange = pParticle->GetProperTime();
// set Position/Time etc. equal to those of the parent track
// thePositionChange = track.GetPosition();
// set TimeChange equal to local time of the parent track
theTimeChange = track.GetLocalTime();
// set initial Local/Global time of the parent track
theLocalTime0 = track.GetLocalTime();
theLocalTime0 = theTimeChange = track.GetLocalTime();
// set initial Global time of the parent track
theGlobalTime0 = track.GetGlobalTime();
// set touchable equal to the next touchable of the parent track
// not set as for now
// theTouchableChange = track.GetNextTouchable();
// NOTE: almost nothing is initialized here.
// theMomentumChange, theProperTimeChange, thePositionChange
// and theTimeChange are set by G4Transportation::AlongStepDoIt();
// the others are not needed.
// Take care when implementing the PostStep related things!
// (P. Urban)
}
inline void G4ParticleChangeForTransport::SetPointerToVectorOfAuxiliaryPoints(
+11 -1
View File
@@ -43,7 +43,7 @@
#ifndef G4Step_hh
#define G4Step_hh 1
#include <stdlib.h> // Include from 'system'
#include <cstdlib> // Include from 'system'
#include <cmath> // Include from 'system'
#include "G4ios.hh" // Include from 'system'
#include <iomanip> // Include from 'system'
@@ -78,11 +78,21 @@ class G4Step
G4StepPoint* GetPreStepPoint() const;
void SetPreStepPoint(G4StepPoint* value);
G4StepPoint* ResetPreStepPoint(G4StepPoint* value=nullptr);
// Pre-Step points
// If Set method is invoked, the previous StepPoint object is deleted.
// If Reset method is invoked, the previous StepPoint object is not deleted
// but its pointer is returned. Thus it's the caller's responsibility to
// properly delete it.
G4StepPoint* GetPostStepPoint() const;
void SetPostStepPoint(G4StepPoint* value);
G4StepPoint* ResetPostStepPoint(G4StepPoint* value=nullptr);
// Post-Step points
// If Set method is invoked, the previous StepPoint object is deleted.
// If Reset method is invoked, the previous StepPoint object is not deleted
// but its pointer is returned. Thus it's the caller's responsibility to
// properly delete it.
G4double GetStepLength() const;
void SetStepLength(G4double value);
+16 -2
View File
@@ -43,6 +43,13 @@ inline void G4Step::SetPreStepPoint(G4StepPoint* value)
fpPreStepPoint = value;
}
inline G4StepPoint* G4Step::ResetPreStepPoint(G4StepPoint* value)
{
G4StepPoint* previousSP = fpPreStepPoint;
fpPreStepPoint = value;
return previousSP;
}
inline G4StepPoint* G4Step::GetPostStepPoint() const
{
return fpPostStepPoint;
@@ -54,6 +61,13 @@ inline void G4Step::SetPostStepPoint(G4StepPoint* value)
fpPostStepPoint = value;
}
inline G4StepPoint* G4Step::ResetPostStepPoint(G4StepPoint* value)
{
G4StepPoint* previousSP = fpPostStepPoint;
fpPostStepPoint = value;
return previousSP;
}
inline G4double G4Step::GetStepLength() const
{
return fStepLength;
@@ -169,7 +183,7 @@ inline void G4Step::InitializeStep(G4Track* aValue)
// and G4StepPoint, G4Step has to manage the copy actions.
//
fpPreStepPoint->SetSafety(0.0);
fpPreStepPoint->SetProcessDefinedStep(0);
fpPreStepPoint->SetProcessDefinedStep(nullptr);
fpPreStepPoint->SetStepStatus(fUndefined);
// G4Track properties
@@ -215,7 +229,7 @@ inline void G4Step::UpdateTrack()
fpTrack->SetGlobalTime(fpPostStepPoint->GetGlobalTime());
fpTrack->SetLocalTime(fpPostStepPoint->GetLocalTime());
// mass, charge, proper time
G4DynamicParticle* pParticle =
auto* pParticle =
(G4DynamicParticle*) (fpTrack->GetDynamicParticle());
pParticle->SetMass(fpPostStepPoint->GetMass());
pParticle->SetCharge(fpPostStepPoint->GetCharge());
+3 -3
View File
@@ -56,11 +56,11 @@ class G4StepPoint
{
public:
G4StepPoint();
~G4StepPoint(){}
G4StepPoint() = default;
~G4StepPoint()= default;
// Constructor/Destructor
G4StepPoint(const G4StepPoint&);
G4StepPoint(const G4StepPoint&) = default;
G4StepPoint& operator=(const G4StepPoint&);
// Copy Constructor and assignment operator
+1 -1
View File
@@ -439,7 +439,7 @@ inline void G4Track::SetParentResonanceID(const G4int parentID)
}
inline G4bool G4Track::HasParentResonance() const {
return ( fParentResonanceDef == nullptr ? false : true );
return ( fParentResonanceDef != nullptr );
}
inline G4int G4Track::GetParentResonancePDGEncoding() const {
+55 -55
View File
@@ -57,11 +57,9 @@
#ifndef G4VParticleChange_hh
#define G4VParticleChange_hh 1
#include <vector>
#include "globals.hh"
#include "G4ios.hh"
#include <cmath>
#include "G4TrackFastVector.hh"
#include "G4TrackStatus.hh"
#include "G4SteppingControl.hh"
#include "G4Step.hh"
@@ -72,14 +70,11 @@ class G4VParticleChange
public:
G4VParticleChange();
// Default constructor
virtual ~G4VParticleChange();
// Destructor
virtual ~G4VParticleChange() = default;
G4bool operator==(const G4VParticleChange& right) const;
G4bool operator!=(const G4VParticleChange& right) const;
// Equality operators; pointer comparison
G4VParticleChange(const G4VParticleChange& right) = delete;
G4VParticleChange& operator=(const G4VParticleChange& right) = delete;
// --- the following methods are for updating G4Step ---
@@ -96,80 +91,83 @@ class G4VParticleChange
// --- the following methods are for TruePathLength ---
G4double GetTrueStepLength() const;
void ProposeTrueStepLength(G4double truePathLength);
inline G4double GetTrueStepLength() const;
inline void ProposeTrueStepLength(G4double truePathLength);
// Get/Propose theTrueStepLength
// --- the following methods are for LocalEnergyDeposit ---
G4double GetLocalEnergyDeposit() const;
void ProposeLocalEnergyDeposit(G4double anEnergyPart);
inline G4double GetLocalEnergyDeposit() const;
inline void ProposeLocalEnergyDeposit(G4double anEnergyPart);
// Get/Propose the locally deposited energy
// --- the following methods are for nonIonizingEnergyDeposit ---
G4double GetNonIonizingEnergyDeposit() const;
void ProposeNonIonizingEnergyDeposit(G4double anEnergyPart);
inline G4double GetNonIonizingEnergyDeposit() const;
inline void ProposeNonIonizingEnergyDeposit(G4double anEnergyPart);
// Get/Propose the non-ionizing deposited energy
// --- the following methods are for TrackStatus ---
G4TrackStatus GetTrackStatus() const;
void ProposeTrackStatus(G4TrackStatus status);
inline G4TrackStatus GetTrackStatus() const;
inline void ProposeTrackStatus(G4TrackStatus status);
// Get/Propose the final TrackStatus of the current particle
inline const G4Track* GetCurrentTrack() const;
// Get primary track pointer
// --- the following methods are for management of SteppingControl ---
G4SteppingControl GetSteppingControl() const;
void ProposeSteppingControl(G4SteppingControl StepControlFlag);
inline G4SteppingControl GetSteppingControl() const;
inline void ProposeSteppingControl(G4SteppingControl StepControlFlag);
// Set/Propose a flag to control stepping manager behaviour
// --- the following methods are for management of initial/last step
G4bool GetFirstStepInVolume() const;
G4bool GetLastStepInVolume() const;
void ProposeFirstStepInVolume(G4bool flag);
void ProposeLastStepInVolume(G4bool flag);
inline G4bool GetFirstStepInVolume() const;
inline G4bool GetLastStepInVolume() const;
inline void ProposeFirstStepInVolume(G4bool flag);
inline void ProposeLastStepInVolume(G4bool flag);
// --- the following methods are for management of secondaries ---
void Clear();
inline void Clear();
// Clear the contents of this objects
// This method should be called after the Tracking(Stepping)
// manager removes all secondaries in theListOfSecondaries
void SetNumberOfSecondaries(G4int totSecondaries);
inline void SetNumberOfSecondaries(G4int totSecondaries);
// SetNumberOfSecondaries must be called just before AddSecondary()
// in order to secure memory space for theListOfSecondaries
// This method resets theNumberOfSecondaries to zero
// (that will be incremented at every AddSecondary() call)
G4int GetNumberOfSecondaries() const;
inline G4int GetNumberOfSecondaries() const;
// Returns the number of secondaries current stored in G4TrackFastVector
G4Track* GetSecondary(G4int anIndex) const;
// Returns the pointer to the generated secondary particle
// which is specified by an Index
inline G4Track* GetSecondary(G4int anIndex) const;
// Returns the pointer to the generated secondary particle,
// which is specified by an Index, no check on boundary is performed
void AddSecondary(G4Track* aSecondary);
// Adds a secondary particle to theListOfSecondaries
// --- the following methods are for management of weights ---
G4double GetWeight() const;
G4double GetParentWeight() const;
inline G4double GetWeight() const;
inline G4double GetParentWeight() const;
// Get weight of the parent (i.e. current) track
void ProposeWeight(G4double finalWeight);
void ProposeParentWeight(G4double finalWeight);
inline void ProposeWeight(G4double finalWeight);
inline void ProposeParentWeight(G4double finalWeight);
// Propose new weight of the parent (i.e. current) track
// As for AlongStepDoIt, the parent weight will be set
// in accumulated manner, i.e. - If two processes propose
// weight of W1 and W2 respectively for the track with initial
// weight of W0 the final weight is set to: (W1/W0) * (W2/W0) * W0
void SetSecondaryWeightByProcess(G4bool);
G4bool IsSecondaryWeightSetByProcess() const;
inline void SetSecondaryWeightByProcess(G4bool);
inline G4bool IsSecondaryWeightSetByProcess() const;
// In default (fSecondaryWeightByProcess flag is false),
// the weight of secondary tracks will be set to the parent weight
// If fSecondaryWeightByProcess flag is true, the weight of secondary
@@ -190,39 +188,36 @@ class G4VParticleChange
virtual void DumpInfo() const;
// Print out information
void SetVerboseLevel(G4int vLevel);
G4int GetVerboseLevel() const;
inline void SetVerboseLevel(G4int vLevel);
inline G4int GetVerboseLevel() const;
virtual G4bool CheckIt(const G4Track&);
// CheckIt method is provided for debug
// CheckIt method for general control in debug regime
void ClearDebugFlag();
void SetDebugFlag();
G4bool GetDebugFlag() const;
inline void ClearDebugFlag();
inline void SetDebugFlag();
inline G4bool GetDebugFlag() const;
// CheckIt method is activated if debug flag is set
// and 'G4VERBOSE' is defined
protected:
G4VParticleChange(const G4VParticleChange& right);
G4VParticleChange& operator=(const G4VParticleChange& right);
// Hidden copy constructor and assignment operator
G4Step* UpdateStepInfo(G4Step* Step);
// Update the G4Step specific attributes
// (i.e. SteppingControl, LocalEnergyDeposit, and TrueStepLength)
void InitializeTrueStepLength(const G4Track&);
void InitializeLocalEnergyDeposit(const G4Track&);
void InitializeSteppingControl(const G4Track&);
void InitializeParentWeight(const G4Track&);
void InitializeParentGlobalTime(const G4Track&);
void InitializeStatusChange(const G4Track&);
void InitializeSecondaries(const G4Track&);
void InitializeStepInVolumeFlags(const G4Track&);
inline void InitializeLocalEnergyDeposit();
inline void InitializeSteppingControl();
inline void InitializeParentWeight(const G4Track&);
inline void InitializeStatusChange(const G4Track&);
inline void InitializeSecondaries();
inline void InitializeFromStep(const G4Step*);
inline G4double ComputeBeta(G4double kinEnergy);
G4bool CheckSecondary(G4Track&);
// CheckSecondary method is provided for debug
// CheckSecondary method is provided to control secondary track
// in debug regime
G4double GetAccuracyForWarning() const;
G4double GetAccuracyForException() const;
@@ -231,9 +226,12 @@ class G4VParticleChange
static const G4double accuracyForWarning;
static const G4double accuracyForException;
static const G4int maxError;
// accuracy levels
G4TrackFastVector* theListOfSecondaries = nullptr;
const G4Track* theCurrentTrack = nullptr;
std::vector<G4Track*> theListOfSecondaries;
// The vector of secondaries
G4TrackStatus theStatusChange = fAlive;
@@ -274,6 +272,8 @@ class G4VParticleChange
G4int verboseLevel = 1;
// The Verbose level
G4int nError = 0;
G4bool theFirstStepInVolume = false;
G4bool theLastStepInVolume = false;
// Flag for initial/last step
+39 -74
View File
@@ -30,7 +30,7 @@
inline G4Track* G4VParticleChange::GetSecondary(G4int anIndex) const
{
return (*theListOfSecondaries)[anIndex];
return theListOfSecondaries[anIndex];
}
inline G4int G4VParticleChange::GetNumberOfSecondaries() const
@@ -43,6 +43,11 @@ inline void G4VParticleChange::ProposeTrackStatus(G4TrackStatus aStatus)
theStatusChange = aStatus;
}
inline const G4Track* G4VParticleChange::GetCurrentTrack() const
{
return theCurrentTrack;
}
inline G4TrackStatus G4VParticleChange::GetTrackStatus() const
{
return theStatusChange;
@@ -133,14 +138,14 @@ inline G4double G4VParticleChange::GetWeight() const
// ----------------------------------------------------------------
// inline functions for Initialization
//
inline void G4VParticleChange::InitializeLocalEnergyDeposit(const G4Track&)
inline void G4VParticleChange::InitializeLocalEnergyDeposit()
{
// clear theLocalEnergyDeposited
theLocalEnergyDeposit = 0.0;
theNonIonizingEnergyDeposit = 0.0;
}
inline void G4VParticleChange::InitializeSteppingControl(const G4Track&)
inline void G4VParticleChange::InitializeSteppingControl()
{
// SteppingControlFlag
theSteppingControlFlag = NormalCondition;
@@ -157,6 +162,7 @@ inline void G4VParticleChange::InitializeStatusChange(const G4Track& track)
{
// set TrackStatus equal to the parent track's one
theStatusChange = track.GetTrackStatus();
theCurrentTrack = &track;
}
inline void G4VParticleChange::InitializeParentWeight(const G4Track& track)
@@ -166,92 +172,45 @@ inline void G4VParticleChange::InitializeParentWeight(const G4Track& track)
isParentWeightProposed = false;
}
inline void G4VParticleChange::InitializeParentGlobalTime(const G4Track& track)
inline void G4VParticleChange::InitializeFromStep(const G4Step* step)
{
// set the parent track's global time at the pre-step point
theParentGlobalTime = track.GetStep()->GetPreStepPoint()->GetGlobalTime();
}
theParentGlobalTime = step->GetPreStepPoint()->GetGlobalTime();
inline void G4VParticleChange::InitializeTrueStepLength(const G4Track& track)
{
// Reset theTrueStepLength
// !! Caution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
theTrueStepLength = track.GetStep()->GetStepLength();
// !! TrueStepLength should be copied from G4Step not G4Track
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
inline void G4VParticleChange::InitializeStepInVolumeFlags(const G4Track& track)
{
const G4Step* aStep = track.GetStep();
theFirstStepInVolume = aStep->IsFirstStepInVolume();
theLastStepInVolume = aStep->IsLastStepInVolume();
}
inline void G4VParticleChange::InitializeSecondaries(const G4Track&)
{
// clear secondaries
if(theNumberOfSecondaries > 0)
{
#ifdef G4VERBOSE
if(verboseLevel > 0)
{
G4cerr << "G4VParticleChange::Initialize() Warning ";
G4cerr << "theListOfSecondaries is not empty " << G4endl;
G4cerr << "All objects in theListOfSecondaries are destroyed!" << G4endl;
}
#endif
for(G4int index = 0; index < theNumberOfSecondaries; index++)
{
if((*theListOfSecondaries)[index])
{
delete(*theListOfSecondaries)[index];
}
}
}
theNumberOfSecondaries = 0;
theTrueStepLength = step->GetStepLength();
theFirstStepInVolume = step->IsFirstStepInVolume();
theLastStepInVolume = step->IsLastStepInVolume();
}
// ----------------------------------------------------------------
// methods for handling secondaries
//
inline void G4VParticleChange::SetNumberOfSecondaries(G4int totSecondaries)
inline void G4VParticleChange::InitializeSecondaries()
{
// check if tracks still exist in theListOfSecondaries
if(theNumberOfSecondaries > 0)
{
#ifdef G4VERBOSE
if(verboseLevel > 0)
{
G4cerr << "G4VParticleChange::SetNumberOfSecondaries() Warning ";
G4cerr << "theListOfSecondaries is not empty ";
}
#endif
for(G4int index = 0; index < theNumberOfSecondaries; index++)
{
if((*theListOfSecondaries)[index])
{
delete(*theListOfSecondaries)[index];
}
}
}
theNumberOfSecondaries = 0;
theSizeOftheListOfSecondaries = totSecondaries;
// Initialize ListOfSecondaries
theListOfSecondaries->Initialize(totSecondaries);
theNumberOfSecondaries = 0;
}
inline void G4VParticleChange::SetNumberOfSecondaries(G4int totSecondaries)
{
if(totSecondaries > theSizeOftheListOfSecondaries)
{
theListOfSecondaries.resize(totSecondaries, nullptr);
theSizeOftheListOfSecondaries = totSecondaries;
}
theNumberOfSecondaries = 0;
}
// ----------------------------------------------------------------
// total
//
inline void G4VParticleChange::Initialize(const G4Track& track)
{
InitializeStatusChange(track);
InitializeLocalEnergyDeposit(track);
InitializeSteppingControl(track);
InitializeTrueStepLength(track);
InitializeSecondaries(track);
InitializeLocalEnergyDeposit();
InitializeSteppingControl();
InitializeSecondaries();
InitializeParentWeight(track);
InitializeParentGlobalTime(track);
InitializeStepInVolumeFlags(track);
InitializeFromStep(track.GetStep());
}
inline void G4VParticleChange::ClearDebugFlag()
@@ -289,3 +248,9 @@ inline void G4VParticleChange::ProposeParentWeight(G4double w)
{
ProposeWeight(w);
}
inline G4double G4VParticleChange::ComputeBeta(G4double ekin)
{
G4double mass = theCurrentTrack->GetDefinition()->GetPDGMass();
return std::sqrt(ekin*(ekin + 2*mass))/(ekin + mass);
}
@@ -55,7 +55,7 @@ class G4VUserTrackInformation
{
public:
G4VUserTrackInformation();
G4VUserTrackInformation() = default;
G4VUserTrackInformation(const G4String& infoType);
// String is provided to indicate the Type of UserTrackInfo class
// User is recommended to set the type of his/her class
-1
View File
@@ -12,7 +12,6 @@ geant4_add_module(G4track
G4ParticleChangeForGamma.hh
G4ParticleChangeForLoss.hh
G4ParticleChangeForMSC.hh
G4ParticleChangeForMSC.icc
G4ParticleChangeForRadDecay.hh
G4ParticleChangeForTransport.hh
G4ParticleChangeForTransport.icc
+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;
}