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
23#include "MCTruth/TrackHelper.h"
25
27
28// Geant4 includes
29#include "G4ParticleDefinition.hh"
30#include "G4DynamicParticle.hh"
31#include "G4TouchableHistory.hh"
32#include "G4Step.hh"
33#include "G4TransportationManager.hh"
34#include "G4LogicalVolumeStore.hh"
35
36#include "G4EventManager.hh"
37#include "G4Event.hh"
38#include "G4PrimaryParticle.hh"
39
40//#include "G4VPhysicalVolume.hh"
41
42#include <iostream>
43
44namespace G4UA {
45
46namespace iGeant4 {
47
54
56{
57 m_curBaseISP = nullptr;
58 m_atlasG4EvtUserInfo = nullptr;
59 return;
60}
61
63{
64 // get geoID from parent
65 //TODO ELLI AtlasDetDescr::AtlasRegion curGeoID = m_curBaseISP->nextGeoID();
66 //TODO ELLI ATH_MSG_DEBUG( "Currently simulating TrackID = " << aStep->GetTrack()->GetTrackID() <<
67 //TODO ELLI " inside geoID = " << curGeoID );
68
69 //
70 // call the ISFSteppingAction method of the implementation
71 //
73
74 //
75 // propagate the current ISFParticle link to all secondaries
76 //
77 const std::vector<const G4Track*> *secondaryVector = aStep->GetSecondaryInCurrentStep();
78 for ( auto* aConstSecondaryTrack : *secondaryVector ) {
79 // get a non-const G4Track for current secondary (nasty!)
80 G4Track* aSecondaryTrack ATLAS_THREAD_SAFE = const_cast<G4Track*>( aConstSecondaryTrack ); // imposed by Geant4 interface
81
82 auto *trackInfo = ::iGeant4::ISFG4Helper::getISFTrackInfo(*aSecondaryTrack);
83
84 // G4Tracks aready returned to ISF will have a TrackInformation attached to them
85 bool particleReturnedToISF = trackInfo && trackInfo->GetReturnedToISF();
86 if (!particleReturnedToISF) {
87 HepMC::GenParticlePtr generationZeroGenParticle{};
91 generationZeroGenParticle );
92 }
93 } // <- loop over secondaries from this step
94
95 return;
96}
97
99{
100 bool isPrimary = ! aTrack->GetParentID();
101 if (isPrimary) {
102 G4Track* nonConstTrack ATLAS_THREAD_SAFE = const_cast<G4Track*> (aTrack); // imposed by Geant4 interface
103 setupPrimary(*nonConstTrack);
104 } else {
105 setupSecondary(*aTrack);
106 }
107
108 return;
109}
110
112{
113 //
114 // Get PrimaryParticleInformation from G4PrimaryParticle (assigned by TransportTool::addPrimaryVertex)
115 //
116
118 if ( trackInfo ) {
119 G4ExceptionDescription description;
120 description << G4String("PreUserTrackingAction: ")
121 << "Started simulation of primary particle which already has a TrackInformation/TrackBarcodeInfo object attached (trackID: "
122 << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
123 << ", parentID " << aTrack.GetParentID() << ")";
124 G4Exception("iGeant4::TrackProcessorUserActionBase", "TrackInformationAlreadyExists", FatalException, description);
125 return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
126 }
127
128 auto* primaryPartInfo = dynamic_cast <PrimaryParticleInformation*> (aTrack.GetDynamicParticle()->GetPrimaryParticle()->GetUserInformation());
129 if (!primaryPartInfo) {
130 G4ExceptionDescription description;
131 description << G4String("PreUserTrackingAction: ") + "NULL PrimaryParticleInformation pointer for current G4Step (trackID "
132 << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
133 << ", parentID " << aTrack.GetParentID() << ")";
134 G4Exception("iGeant4::TrackProcessorUserActionBase", "NoPPInfo", FatalException, description);
135 return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
136 }
137
138 // get base ISFParticle and link to TrackInformation
139 auto* baseISP = primaryPartInfo->GetISFParticle();
140 if (!baseISP) {
141 G4ExceptionDescription description;
142 description << G4String("PreUserTrackingAction: ") + "No ISFParticle associated with primary particle (trackID: "
143 << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
144 << ", parentID " << aTrack.GetParentID() << ")";
145 G4Exception("iGeant4::TrackProcessorUserActionBase", "NoISFParticle", FatalException, description);
146 return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
147 }
148
149 ISF::TruthBinding* truthBinding = baseISP->getTruthBinding();
150 if (!truthBinding) {
151 G4ExceptionDescription description;
152 description << G4String("PreUserTrackingAction: ") + "No ISF::TruthBinding associated with primary particle (trackID: "
153 << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
154 << ", parentID " << aTrack.GetParentID() << ")";
155 G4Exception("iGeant4::TrackProcessorUserActionBase", "NoISFTruthBinding", FatalException, description);
156 return; // The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
157 }
158
159 int regenerationNr = primaryPartInfo->GetRegenerationNr();
160
161 HepMC::GenParticlePtr primaryGenParticle = truthBinding->getGenerationZeroGenParticle();
162 HepMC::GenParticlePtr generationZeroGenParticle = truthBinding->getGenerationZeroGenParticle();
163 HepMC::GenParticlePtr currentGenParticle = truthBinding->getCurrentGenParticle();
164
165 auto classification = classify(primaryGenParticle,
166 generationZeroGenParticle,
167 currentGenParticle,
168 regenerationNr);
169
170 auto* newTrackInfo = ::iGeant4::ISFG4Helper::attachTrackInfoToNewG4Track(aTrack,
171 *baseISP,
172 classification,
173 generationZeroGenParticle );
174 newTrackInfo->SetRegenerationNr(regenerationNr);
175
177 primaryGenParticle,
178 currentGenParticle);
179
180 return;
181}
182
184{
186
187 HepMC::GenParticlePtr currentGenParticle = trackInfo->GetCurrentGenParticle();
188 HepMC::GenParticlePtr primaryGenParticle = trackInfo->GetPrimaryGenParticle();
189 ISF::ISFParticle* baseISFParticle = trackInfo->GetBaseISFParticle();
190
191 updateCachedParticleInfo(baseISFParticle, primaryGenParticle, currentGenParticle);
192
193 return;
194}
195
197 HepMC::ConstGenParticlePtr primaryGenParticle,
198 HepMC::GenParticlePtr currentGenParticle)
199{
200 m_curBaseISP = baseISFParticle;
201 m_atlasG4EvtUserInfo->SetCurrentPrimaryGenParticle( primaryGenParticle );
202 m_atlasG4EvtUserInfo->SetCurrentGenParticle( currentGenParticle );
203 return;
204}
205
209 HepMC::ConstGenParticlePtr generationZeroGenParticle,
210 HepMC::ConstGenParticlePtr currentGenParticle,
211 int regenerationNumber) const
212{
213 // if particle points to a non-zero truth particle it can not just be a 'simple' Secondary
214
215 if (currentGenParticle) {
216 if (currentGenParticle == primaryGenParticle) {
218 }
219 else if (generationZeroGenParticle == primaryGenParticle && regenerationNumber>0) {
221 }
222 else {
224 }
225 }
226
228}
229
230
231
233{
234 m_curBaseISP = nullptr;
235 return;
236}
237
245
246} // namespace iGeant4
247
248} // 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 ...
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.
void updateCachedParticleInfo(ISF::ISFParticle *baseISFParticle, HepMC::ConstGenParticlePtr primaryGenParticle, HepMC::GenParticlePtr currentGenParticle)
Set the following information as the currently traced particle.
AtlasG4EventUserInfo * m_atlasG4EvtUserInfo
event-global G4 UserInformation
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 AtlasG4EventUserInfo * getAtlasG4EventUserInfo()
return pointer to current AtlasG4EventUserInfo
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:91
GenParticle * GenParticlePtr
Definition GenParticle.h:37
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
std::list< ISF::ISFParticle * > ISFParticleContainer
generic ISFParticle container (not necessarily a std::list!)
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)