File indexing completed on 2026-12-04 09:46:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Geant4/MaterialSteppingAction.hpp"
0010
0011 #include "ActsExamples/Geant4/EventStore.hpp"
0012
0013 #include <cassert>
0014 #include <cstddef>
0015 #include <ostream>
0016 #include <unordered_map>
0017 #include <utility>
0018
0019 #include <G4Step.hh>
0020 #include <G4Track.hh>
0021
0022 namespace ActsExamples::Geant4 {
0023
0024 MaterialSteppingAction::MaterialSteppingAction(
0025 const Config& cfg, std::unique_ptr<const Acts::Logger> logger)
0026 : G4UserSteppingAction(),
0027 m_cfg(cfg),
0028 m_stepConverter({.excludeMaterials = cfg.excludeMaterials,
0029 .recordElementFractions = cfg.recordElementFractions}),
0030 m_logger(std::move(logger)) {}
0031
0032 void MaterialSteppingAction::UserSteppingAction(const G4Step* stepPtr) {
0033 assert(stepPtr != nullptr);
0034 const G4Step& step = *stepPtr;
0035 assert(step.GetTrack() != nullptr);
0036 const G4Track& track = *step.GetTrack();
0037
0038
0039 auto& materialTracks = eventStore().materialTracks;
0040 const std::size_t trackId = track.GetTrackID() - 1;
0041 auto it = materialTracks.find(trackId);
0042 if (it == materialTracks.end()) {
0043 it = materialTracks.emplace(trackId, m_stepConverter.startTrack(track))
0044 .first;
0045 }
0046
0047 if (m_stepConverter.addStep(step, it->second)) {
0048 ACTS_VERBOSE("Recorded a step with step size = " << step.GetStepLength());
0049 } else {
0050 ACTS_VERBOSE("Skip step without recorded material.");
0051 }
0052 }
0053
0054 }