ATLAS Offline Software
Loading...
Searching...
No Matches
TrackProcessorUserActionBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// class header
7
8// ISF includes
11
13
14// ISF Geant4 includes
16
17// Athena includes
20
22#include "MCTruth/TrackHelper.h"
24
26
27// Geant4 includes
28#include "G4ParticleDefinition.hh"
29#include "G4DynamicParticle.hh"
30#include "G4TouchableHistory.hh"
31#include "G4Step.hh"
32#include "G4TransportationManager.hh"
33#include "G4LogicalVolumeStore.hh"
34
35#include "G4Event.hh"
36#include "G4PrimaryParticle.hh"
37
38//#include "G4VPhysicalVolume.hh"
39
40#include <iostream>
41
42namespace G4UA {
43
44namespace iGeant4 {
45
47{
48 m_curBaseISP = nullptr;
49 return;
50}
51
53{
54 m_curBaseISP = nullptr;
55 return;
56}
57
59{
60 // get geoID from parent
61 //TODO ELLI AtlasDetDescr::AtlasRegion curGeoID = m_curBaseISP->nextGeoID();
62 //TODO ELLI ATH_MSG_DEBUG( "Currently simulating TrackID = " << aStep->GetTrack()->GetTrackID() <<
63 //TODO ELLI " inside geoID = " << curGeoID );
64
65 // AdePT currently does not return the G4Secondary vector per G4Step. As the vector is required to attach
66 // the G4VUserInfo in the PreUserTrackingAction below, the G4VUserInfo is not available, which
67 // would lead to nullptr access crashes
68#ifdef ATHSIMULATION_USE_ADEPT
69 return;
70#endif
71 //
72 // call the ISFSteppingAction method of the implementation
73 //
75
76 //
77 // propagate the current ISFParticle link to all secondaries
78 //
79 const std::vector<const G4Track*> *secondaryVector = aStep->GetSecondaryInCurrentStep();
80 if (secondaryVector && !secondaryVector->empty()) {
81 for ( auto* aConstSecondaryTrack : *secondaryVector ) {
82 // get a non-const G4Track for current secondary (nasty!)
83 G4Track* aSecondaryTrack ATLAS_THREAD_SAFE = const_cast<G4Track*>( aConstSecondaryTrack ); // imposed by Geant4 interface
84
85 auto *trackInfo = ::iGeant4::ISFG4Helper::getISFTrackInfo(*aSecondaryTrack);
86
87 // G4Tracks aready returned to ISF will have a TrackInformation attached to them
88 bool particleReturnedToISF = trackInfo && trackInfo->GetReturnedToISF();
89 if (!particleReturnedToISF) {
90 HepMC::GenParticlePtr generationZeroGenParticle{};
94 generationZeroGenParticle );
95 }
96 } // <- loop over secondaries from this step
97 }
98
99 return;
100}
101
103{
104 // AdePT currently does not return the G4Secondary vector per G4Step. As the vector is required to attach
105 // the G4VUserInfo below the G4VUserInfo is not available, which would lead to nullptr access crashes
106#ifdef ATHSIMULATION_USE_ADEPT
107 return;
108#endif
109
110 bool isPrimary = ! aTrack->GetParentID();
111 if (isPrimary) {
112 G4Track* nonConstTrack ATLAS_THREAD_SAFE = const_cast<G4Track*> (aTrack); // imposed by Geant4 interface
113 setupPrimary(*nonConstTrack);
114 } else {
115 setupSecondary(*aTrack);
116 }
117
118 return;
119}
120
122{
123 //
124 // Get PrimaryParticleInformation from G4PrimaryParticle (assigned by TransportTool::addPrimaryVertex)
125 //
126
128 if ( trackInfo ) {
129 G4ExceptionDescription description;
130 description << G4String("PreUserTrackingAction: ")
131 << "Started simulation of primary particle which already has a TrackInformation/TrackBarcodeInfo object attached (trackID: "
132 << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
133 << ", parentID " << aTrack.GetParentID() << ")";
134 G4Exception("iGeant4::TrackProcessorUserActionBase", "TrackInformationAlreadyExists", FatalException, description);
135 return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
136 }
137
138 auto* primaryPartInfo = dynamic_cast <PrimaryParticleInformation*> (aTrack.GetDynamicParticle()->GetPrimaryParticle()->GetUserInformation());
139 if (!primaryPartInfo) {
140 G4ExceptionDescription description;
141 description << G4String("PreUserTrackingAction: ") + "NULL PrimaryParticleInformation pointer for current G4Step (trackID "
142 << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
143 << ", parentID " << aTrack.GetParentID() << ")";
144 G4Exception("iGeant4::TrackProcessorUserActionBase", "NoPPInfo", FatalException, description);
145 return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
146 }
147
148 // get base ISFParticle and link to TrackInformation
149 auto* baseISP = primaryPartInfo->GetISFParticle();
150 if (!baseISP) {
151 G4ExceptionDescription description;
152 description << G4String("PreUserTrackingAction: ") + "No ISFParticle associated with primary particle (trackID: "
153 << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
154 << ", parentID " << aTrack.GetParentID() << ")";
155 G4Exception("iGeant4::TrackProcessorUserActionBase", "NoISFParticle", FatalException, description);
156 return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
157 }
158
159 ISF::TruthBinding* truthBinding = baseISP->getTruthBinding();
160 if (!truthBinding) {
161 G4ExceptionDescription description;
162 description << G4String("PreUserTrackingAction: ") + "No ISF::TruthBinding associated with primary particle (trackID: "
163 << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
164 << ", parentID " << aTrack.GetParentID() << ")";
165 G4Exception("iGeant4::TrackProcessorUserActionBase", "NoISFTruthBinding", FatalException, description);
166 return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
167 }
168
169 int regenerationNr = primaryPartInfo->GetRegenerationNr();
170
171 // Keep the legacy classification based on generation-zero identity; the
172 // true primary is stored separately on TrackInformation by ISFG4Helper.
173 HepMC::GenParticlePtr generationZeroGenParticle = truthBinding->getGenerationZeroGenParticle();
174 HepMC::GenParticlePtr primaryGenParticle = generationZeroGenParticle;
175 HepMC::GenParticlePtr currentGenParticle = truthBinding->getCurrentGenParticle();
176
177 auto classification = classify(primaryGenParticle,
178 generationZeroGenParticle,
179 currentGenParticle,
180 regenerationNr);
181
182 auto* newTrackInfo = ::iGeant4::ISFG4Helper::attachTrackInfoToNewG4Track(aTrack,
183 *baseISP,
184 classification,
185 generationZeroGenParticle );
186 newTrackInfo->SetRegenerationNr(regenerationNr);
187
189
190 return;
191}
192
194{
196
197 ISF::ISFParticle* baseISFParticle = trackInfo->GetBaseISFParticle();
198
199 updateCurrentBaseISFParticle(baseISFParticle);
200
201 return;
202}
203
205{
206 m_curBaseISP = baseISFParticle;
207 return;
208}
209
213 HepMC::ConstGenParticlePtr generationZeroGenParticle,
214 HepMC::ConstGenParticlePtr currentGenParticle,
215 int regenerationNumber) const
216{
217 // if particle points to a non-zero truth particle it can not just be a 'simple' Secondary
218
219 if (currentGenParticle) {
220 if (currentGenParticle == primaryGenParticle) {
222 }
223 else if (generationZeroGenParticle == primaryGenParticle && regenerationNumber>0) {
225 }
226 else {
228 }
229 }
230
232}
233
234
235
237{
238 m_curBaseISP = nullptr;
239 return;
240}
241
243{
244 // For now, just return all particles
247 return result;
248}
249
250} // namespace iGeant4
251
252} // namespace G4UA
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
VTrackInformation::TrackClassification classify(HepMC::ConstGenParticlePtr primaryGenParticle, HepMC::ConstGenParticlePtr generationZeroGenParticle, HepMC::ConstGenParticlePtr currentGenParticle, int regenerationNumber) const
Classify the particle represented by the given set of truth links.
virtual void PreUserTrackingAction(const G4Track *) override
virtual void EndOfEventAction(const G4Event *) override final
virtual void ISFSteppingAction(const G4Step *, ISF::ISFParticle *)=0
This method is called by TrackProcessorUserActionBase after the G4Track->ISFParticle association has ...
void updateCurrentBaseISFParticle(ISF::ISFParticle *baseISFParticle)
Set the base ISFParticle for the currently traced particle.
virtual void PostUserTrackingAction(const G4Track *) override final
virtual void UserSteppingAction(const G4Step *) override final
void setupPrimary(G4Track &)
Setup the given G4Track as the current primary particle which we'll process.
void setupSecondary(const G4Track &)
Setup the given G4Track as the current secondary particle which we'll process.
ISF::ISFParticleContainer ReturnSecondaries(ISF::ISFParticle const *parent)
virtual void BeginOfEventAction(const G4Event *) override final
ISF::ISFParticle * m_curBaseISP
The most recent ISFParticle ancestor that triggers the currently processed G4Track.
The generic ISF particle definition,.
Definition ISFParticle.h:42
HepMC::GenParticlePtr getCurrentGenParticle()
pointer to the particle in the simulation truth
HepMC::GenParticlePtr getGenerationZeroGenParticle()
pointer to the simulation truth particle before any regeneration happened (eg.
This class is attached to G4PrimaryParticle objects as UserInformation.
const ISF::ISFParticle * GetISFParticle() const
return a pointer to the ISFParticle used to create the G4PrimaryParticle
static VTrackInformation * getISFTrackInfo(const G4Track &aTrack)
return a valid UserInformation object of the G4Track for use within the ISF
static TrackInformation * attachTrackInfoToNewG4Track(G4Track &aTrack, ISF::ISFParticle &baseIsp, VTrackInformation::TrackClassification classification, HepMC::GenParticlePtr generationZeroGenParticle=nullptr)
attach a new TrackInformation object to the given new (!) G4Track (the G4Track must not have a UserIn...
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:93
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
std::list< ISF::ISFParticle * > ISFParticleContainer
generic ISFParticle container (not necessarily a std::list!)
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)