Warning, file /acts/Examples/Algorithms/Geant4/src/ParticleKillAction.cpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Geant4/ParticleKillAction.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "ActsExamples/Geant4/AlgebraConverters.hpp"
0013 #include "ActsExamples/Geant4/UnitConversion.hpp"
0014 #include "ActsFatras/EventData/SimulationOutcome.hpp"
0015
0016 #include <ostream>
0017 #include <utility>
0018
0019 #include <G4RunManager.hh>
0020 #include <G4Step.hh>
0021 #include <G4StepPoint.hh>
0022 #include <G4Track.hh>
0023 #include <G4UnitsTable.hh>
0024 #include <G4VPhysicalVolume.hh>
0025
0026 namespace ActsExamples::Geant4 {
0027
0028 ParticleKillAction::ParticleKillAction(
0029 const Config& cfg, std::unique_ptr<const Acts::Logger> logger)
0030 : G4UserSteppingAction(), m_cfg(cfg), m_logger(std::move(logger)) {}
0031
0032 void ParticleKillAction::UserSteppingAction(const G4Step* stepPtr) {
0033 assert(stepPtr != nullptr);
0034 const G4Step& step = *stepPtr;
0035
0036 assert(step.GetTrack() != nullptr);
0037 G4Track& track = *step.GetTrack();
0038
0039 const double time = convertTimeToActs * track.GetGlobalTime();
0040 const bool isSecondary =
0041 track.GetDynamicParticle()->GetPrimaryParticle() == nullptr;
0042
0043 const bool outOfVolume =
0044 m_cfg.volume &&
0045 !m_cfg.volume->inside(eventStore().geoContext,
0046 convertPosition(track.GetPosition()));
0047 const bool outOfTime = time > m_cfg.maxTime;
0048 const bool invalidSecondary = m_cfg.secondaries && isSecondary;
0049
0050 if (outOfVolume || outOfTime || invalidSecondary) {
0051 ACTS_DEBUG("Kill track with internal track ID "
0052 << track.GetTrackID() << " at "
0053 << convertPosition(track.GetPosition()) << " and global time "
0054 << time / Acts::UnitConstants::ns << "ns and isSecondary "
0055 << isSecondary);
0056 track.SetTrackStatus(G4TrackStatus::fStopAndKill);
0057 }
0058
0059
0060
0061 if (const auto trackIt = eventStore().trackIdMapping.find(track.GetTrackID());
0062 trackIt != eventStore().trackIdMapping.end()) {
0063
0064 const SimBarcode particleId = trackIt->second;
0065 if (outOfVolume) {
0066 eventStore().particleOutcome[particleId] =
0067 ActsFatras::SimulationOutcome::KilledVolumeExit;
0068 } else if (outOfTime) {
0069 eventStore().particleOutcome[particleId] =
0070 ActsFatras::SimulationOutcome::KilledTime;
0071 } else if (invalidSecondary) {
0072 eventStore().particleOutcome[particleId] =
0073 ActsFatras::SimulationOutcome::KilledSecondaryParticle;
0074 } else if (track.GetTrackStatus() == G4TrackStatus::fStopAndKill) {
0075 eventStore().particleOutcome[particleId] =
0076 ActsFatras::SimulationOutcome::KilledInteraction;
0077 }
0078 }
0079 }
0080
0081 }