13#include "G4StepPoint.hh"
14#include "G4TouchableHistory.hh"
27 int secondarySavingLevel,
29 IMessageSvc* msgSvc, MSG::Level level)
36 msg().setLevel(level);
45 " recording envelopes:");
48 ATH_MSG_DEBUG(
" " << volCollPair.first <<
", " << volCollPair.second);
58 " not found in geometry!");
61 " will NOT be recorded");
87 recEnvelope.BeginOfEvent(eventInfo->GetHitCollectionMap()->Find<
TrackRecordCollection>(recEnvelope.GetTrackRecordCollectionName()));
98 const std::vector<const G4Track*>* secondaries = aStep->GetSecondaryInCurrentStep();
104 const bool processTruth =
108 if (secondaries && !secondaries->empty() && processTruth) {
117 G4StepPoint* preStep = aStep->GetPreStepPoint();
118 G4StepPoint* postStep = aStep->GetPostStepPoint();
120 G4VPhysicalVolume* preVol = preStep->GetPhysicalVolume();
121 G4VPhysicalVolume* postVol = postStep->GetPhysicalVolume();
123 if (preVol == postVol)
return;
125 const G4TouchableHistory* preTHist =
static_cast<const G4TouchableHistory*
>(preStep->GetTouchable());
126 const G4TouchableHistory* postTHist =
static_cast<const G4TouchableHistory*
>(postStep->GetTouchable());
127 const int preStepVolDepth = preTHist->GetHistoryDepth();
128 const int postStepVolDepth = postTHist->GetHistoryDepth();
132 const int envelopeLevel = recEnvelope.GetLevel();
133 if (envelopeLevel <= preStepVolDepth)
136 const G4LogicalVolume* logicalVolume1 =
137 preTHist->GetVolume(preStepVolDepth-envelopeLevel)->GetLogicalVolume();
138 if (logicalVolume1 != recEnvelope.GetLogicalVolume())
continue;
140 if (envelopeLevel <= postStepVolDepth &&
141 logicalVolume1 == postTHist->GetVolume(postStepVolDepth-envelopeLevel)
142 ->GetLogicalVolume())
149 recEnvelope.AddTrackRecord(aStep);
166 if (!primaryGenParticle) {
170 const std::vector<const G4Track*>* secondaries = aStep->GetSecondaryInCurrentStep();
175 for (
const G4Track* secondary : *secondaries) {
176 if (!secondary || secondary->GetUserInformation()) {
180 auto trackInfo = std::make_unique<TrackInformation>();
181 trackInfo->SetPrimaryGenParticle(primaryGenParticle);
183 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.
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.
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.
MCTruthSteppingAction(const VolumeCollectionMap_t &collMap, int secondarySavingLevel, int subDetVolLevel, IMessageSvc *msgSvc, MSG::Level level)
Construct the action with specified volumes and output collections.
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 ...
bool IsRegisteredSecondary() const
bool IsRegeneratedPrimary() const
Singleton class for creating truth incidents.
bool CreateTruthIncident(const G4Step *, int subDetVolLevel) const
Returns true if any of the truth strategies return true.
static const TruthStrategyManager & GetStrategyManager()
Retrieve the (const) singleton instance.
HepMC3::GenParticlePtr GenParticlePtr