16#include "G4StepPoint.hh"
17#include "G4TouchableHistory.hh"
30 int secondarySavingLevel,
34 IMessageSvc* msgSvc, MSG::Level level)
43 msg().setLevel(level);
52 " recording envelopes:");
55 ATH_MSG_DEBUG(
" " << volCollPair.first <<
", " << volCollPair.second);
65 " not found in geometry!");
68 " will NOT be recorded");
94 recEnvelope.BeginOfEvent(eventInfo->GetHitCollectionMap()->Find<
TrackRecordCollection>(recEnvelope.GetTrackRecordCollectionName()));
105 const std::vector<const G4Track*>* secondaries = aStep->GetSecondaryInCurrentStep();
111 const bool processTruth =
115 if (secondaries && !secondaries->empty() && processTruth) {
122 G4StepPoint* preStep = aStep->GetPreStepPoint();
123 G4StepPoint* postStep = aStep->GetPostStepPoint();
125 G4VPhysicalVolume* preVol = preStep->GetPhysicalVolume();
126 G4VPhysicalVolume* postVol = postStep->GetPhysicalVolume();
128 if (preVol == postVol)
return;
130 const G4TouchableHistory* preTHist =
static_cast<const G4TouchableHistory*
>(preStep->GetTouchable());
131 const G4TouchableHistory* postTHist =
static_cast<const G4TouchableHistory*
>(postStep->GetTouchable());
132 const int preStepVolDepth = preTHist->GetHistoryDepth();
133 const int postStepVolDepth = postTHist->GetHistoryDepth();
137 const int envelopeLevel = recEnvelope.GetLevel();
138 if (envelopeLevel <= preStepVolDepth)
141 const G4LogicalVolume* logicalVolume1 =
142 preTHist->GetVolume(preStepVolDepth-envelopeLevel)->GetLogicalVolume();
143 if (logicalVolume1 != recEnvelope.GetLogicalVolume())
continue;
145 if (envelopeLevel <= postStepVolDepth &&
146 logicalVolume1 == postTHist->GetVolume(postStepVolDepth-envelopeLevel)
147 ->GetLogicalVolume())
154 recEnvelope.AddTrackRecord(aStep);
179 if (!primaryGenParticle) {
183 const std::vector<const G4Track*>* secondaries = aStep->GetSecondaryInCurrentStep();
188 for (
const G4Track* secondary : *secondaries) {
189 if (!secondary || secondary->GetUserInformation()) {
193 auto trackInfo = std::make_unique<TrackInformation>();
194 trackInfo->SetPrimaryGenParticle(primaryGenParticle);
196 secondary->SetUserInformation(
trackInfo.release());
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
AtlasHitsVector< TrackRecord > TrackRecordCollection
MsgStream & msg() const
The standard message stream.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
This class is attached to G4Event objects as UserInformation.
std::map< std::string, std::string > VolumeCollectionMap_t
Map of volume name to output TrackRecordCollection name.
bool m_isInitialized
Used to delay initialization until the event loop, after geo is ready.
int m_subDetVolLevel
The level in the G4 volume hierarchy at which we find the sub-detector.
int m_secondarySavingLevel
The saving level for secondaries.
void setupRecEnvelopes()
Setup the list of RecordingEnvelope helpers.
std::vector< RecordingEnvelope > m_recordingEnvelopes
List of RecordingEnvelope helpers to invoke.
ISF::IGeoIDSvc & m_geoIDSvc
ISF GeoID Service used to identify the next detector region.
VolumeCollectionMap_t m_volumeCollectionMap
Map of volume name to output collection name.
void propagatePrimaryInfoToSecondaries(const G4Step *) const
Propagate parent primary truth attribution to ordinary secondaries.
virtual void BeginOfEventAction(const G4Event *) override final
Called at the start of each G4 event.
ISF::ITruthSvc & m_truthRecordSvc
ISF Truth Service used to register truth incidents.
void createTruthIncident(const G4Step *) const
Create and register a truth incident for the current step.
virtual void UserSteppingAction(const G4Step *) override final
Process one particle step.
MCTruthSteppingAction(const VolumeCollectionMap_t &collMap, int secondarySavingLevel, int subDetVolLevel, ISF::ITruthSvc &truthRecordSvc, ISF::IGeoIDSvc &geoIDSvc, IMessageSvc *msgSvc, MSG::Level level)
Construct the action with specified volumes and output collections.
The interface to chose between the sub geometry services, realized as an AlgTool since it does not ha...
Responsible for finding the G4LogicalVolume pointer for each recording envelope and for creating and ...
const std::string & GetTrackRecordCollectionName() const
Returns the name of the TrackRecordCollection to which tracks crossing this recording envelope should...
const std::string & GetVolumeName() const
Returns the name of the recording envelope volume.
bool Initialize()
Finds the pointer to the G4LogicalVolume called m_envelopeVolumeName and the number of levels beneath...
TrackInformation * GetTrackInformation()
Return concrete TrackInformation when callers need fields that are not part of the VTrackInformation ...
bool IsRegisteredSecondary() const
bool IsRegeneratedPrimary() const
ISF_Geant4 specific implementation of the ISF::ITruthIncident.
static AtlasDetDescr::AtlasRegion nextGeoId(const G4Step *aStep, int truthVolLevel, ISF::IGeoIDSvc *geoIDSvc)
AtlasRegion
A simple enum of ATLAS regions and sub-detectors.
HepMC3::GenParticlePtr GenParticlePtr