22 #include <unordered_map>
25 #include <G4ParticleDefinition.hh>
26 #include <G4RunManager.hh>
28 #include <G4UnitsTable.hh>
35 const G4Track* aTrack) {
42 if (not eventStore().hitBuffer.empty()) {
43 eventStore().hitBuffer.clear();
47 auto barcode = makeParticleId(aTrack->GetTrackID(), aTrack->GetParentID());
56 auto [
it, success] = eventStore().particlesInitial.insert(
particle);
61 eventStore().trackIdMapping[aTrack->GetTrackID()] =
particle.particleId();
63 eventStore().particleIdCollisionsInitial++;
66 <<
" detected for initial particles. Skip particle");
71 const G4Track* aTrack) {
74 if (eventStore().trackIdMapping.find(aTrack->GetTrackID()) ==
75 eventStore().trackIdMapping.end()) {
76 ACTS_WARNING(
"Particle ID for track ID " << aTrack->GetTrackID()
77 <<
" not registered. Skip");
81 const auto barcode = eventStore().trackIdMapping.at(aTrack->GetTrackID());
83 auto hasHits = eventStore().particleHitCount.find(barcode) !=
84 eventStore().particleHitCount.end() and
85 eventStore().particleHitCount.at(barcode) > 0;
87 if (not
m_cfg.keepParticlesWithoutHits and not hasHits) {
88 [[maybe_unused]]
auto n = eventStore().particlesInitial.erase(
95 auto [
it, success] = eventStore().particlesFinal.insert(
particle);
98 eventStore().particleIdCollisionsFinal++;
101 <<
" detected for final particles. Skip particle");
106 const G4Track& aTrack,
SimBarcode particleId)
const {
113 const G4ParticleDefinition* particleDef = aTrack.GetParticleDefinition();
114 G4int
pdg = particleDef->GetPDGEncoding();
115 G4double
charge = particleDef->GetPDGCharge();
116 G4double
mass = convertEnergy * particleDef->GetPDGMass();
117 G4ThreeVector pPosition = convertLength * aTrack.GetPosition();
118 G4double pTime = convertTime * aTrack.GetGlobalTime();
119 G4ThreeVector pDirection = aTrack.GetMomentumDirection();
120 G4double
p = convertEnergy * aTrack.GetKineticEnergy();
125 aParticle.
setPosition4(pPosition[0], pPosition[1], pPosition[2], pTime);
126 aParticle.
setDirection(pDirection[0], pDirection[1], pDirection[2]);
131 std::optional<ActsExamples::SimBarcode>
133 G4int parentId)
const {
136 if (eventStore().trackIdMapping.find(trackId) !=
137 eventStore().trackIdMapping.end()) {
141 if (eventStore().trackIdMapping.find(parentId) ==
142 eventStore().trackIdMapping.end()) {
144 <<
" not registered, cannot build barcode");
145 eventStore().parentIdNotFound++;
149 auto pid = eventStore().trackIdMapping.at(parentId).makeDescendant();
152 key.set(0,
pid.vertexPrimary())
153 .
set(1,
pid.vertexSecondary())
154 .
set(2,
pid.particle())
155 .
set(3,
pid.generation());
156 pid.setSubParticle(++eventStore().subparticleMap[key]);