12#include "G4StepPoint.hh"
13#include "G4TouchableHistory.hh"
26 IMessageSvc* msgSvc, MSG::Level level)
31 msg().setLevel(level);
40 " recording envelopes:");
43 ATH_MSG_DEBUG(
" " << volCollPair.first <<
", " << volCollPair.second);
53 " not found in geometry!");
56 " will NOT be recorded");
82 recEnvelope.BeginOfEvent(eventInfo->GetHitCollectionMap()->Find<
TrackRecordCollection>(recEnvelope.GetTrackRecordCollectionName()));
98 G4StepPoint* preStep = aStep->GetPreStepPoint();
99 G4StepPoint* postStep = aStep->GetPostStepPoint();
101 G4VPhysicalVolume* preVol = preStep->GetPhysicalVolume();
102 G4VPhysicalVolume* postVol = postStep->GetPhysicalVolume();
104 if (preVol == postVol)
return;
106 const G4TouchableHistory* preTHist =
static_cast<const G4TouchableHistory*
>(preStep->GetTouchable());
107 const G4TouchableHistory* postTHist =
static_cast<const G4TouchableHistory*
>(postStep->GetTouchable());
108 const int preStepVolDepth = preTHist->GetHistoryDepth();
109 const int postStepVolDepth = postTHist->GetHistoryDepth();
113 const int envelopeLevel = recEnvelope.GetLevel();
114 if (envelopeLevel <= preStepVolDepth)
117 const G4LogicalVolume* logicalVolume1 =
118 preTHist->GetVolume(preStepVolDepth-envelopeLevel)->GetLogicalVolume();
119 if (logicalVolume1 != recEnvelope.GetLogicalVolume())
continue;
121 if (envelopeLevel <= postStepVolDepth &&
122 logicalVolume1 == postTHist->GetVolume(postStepVolDepth-envelopeLevel)
123 ->GetLogicalVolume())
130 recEnvelope.AddTrackRecord(aStep);
147 if (!primaryGenParticle) {
151 const std::vector<const G4Track*>* secondaries = aStep->GetSecondaryInCurrentStep();
156 for (
const G4Track* secondary : *secondaries) {
157 if (!secondary || secondary->GetUserInformation()) {
161 auto trackInfo = std::make_unique<TrackInformation>();
162 trackInfo->SetPrimaryGenParticle(primaryGenParticle);
164 secondary->SetUserInformation(
trackInfo.release());
#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.
void setupRecEnvelopes()
Setup the list of RecordingEnvelope helpers.
std::vector< RecordingEnvelope > m_recordingEnvelopes
List of RecordingEnvelope helpers to invoke.
MCTruthSteppingAction(const VolumeCollectionMap_t &collMap, IMessageSvc *msgSvc, MSG::Level level)
Construct the action with specified volumes and output collections.
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.
virtual void UserSteppingAction(const G4Step *) override final
Process one particle step.
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 ...
HepMC3::GenParticlePtr GenParticlePtr