ATLAS Offline Software
Loading...
Searching...
No Matches
G4UA::MCTruthSteppingAction Class Reference

User action which handles recording-envelope truth tracks. More...

#include <MCTruthSteppingAction.h>

Inheritance diagram for G4UA::MCTruthSteppingAction:
Collaboration diagram for G4UA::MCTruthSteppingAction:

Public Types

using VolumeCollectionMap_t = std::map<std::string, std::string>
 Map of volume name to output TrackRecordCollection name.

Public Member Functions

 MCTruthSteppingAction (const VolumeCollectionMap_t &collMap, 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.
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Private Member Functions

void setupRecEnvelopes ()
 Setup the list of RecordingEnvelope helpers.
void propagatePrimaryInfoToSecondaries (const G4Step *) const
 Propagate parent primary truth attribution to ordinary secondaries.
void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

bool m_isInitialized
 Used to delay initialization until the event loop, after geo is ready.
VolumeCollectionMap_t m_volumeCollectionMap
 Map of volume name to output collection name.
std::vector< RecordingEnvelopem_recordingEnvelopes
 List of RecordingEnvelope helpers to invoke.
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

User action which handles recording-envelope truth tracks.

This user action utilizes RecordingEnvelope objects to save truth tracks at entry/exit layers of certain configured detector layers.

Definition at line 34 of file MCTruthSteppingAction.h.

Member Typedef Documentation

◆ VolumeCollectionMap_t

using G4UA::MCTruthSteppingAction::VolumeCollectionMap_t = std::map<std::string, std::string>

Map of volume name to output TrackRecordCollection name.

Definition at line 42 of file MCTruthSteppingAction.h.

Constructor & Destructor Documentation

◆ MCTruthSteppingAction()

G4UA::MCTruthSteppingAction::MCTruthSteppingAction ( const VolumeCollectionMap_t & collMap,
IMessageSvc * msgSvc,
MSG::Level level )

Construct the action with specified volumes and output collections.

Parameters
[in]collMapA map of recording envelope volume name to output TrackRecordCollection name.

Definition at line 24 of file MCTruthSteppingAction.cxx.

27 : AthMessaging(msgSvc, "MCTruthSteppingAction"),
28 m_isInitialized(false),
29 m_volumeCollectionMap(volCollMap)
30 {
31 msg().setLevel(level);
32 }
AthMessaging()
Default constructor:
MsgStream & msg() const
The standard message stream.
bool m_isInitialized
Used to delay initialization until the event loop, after geo is ready.
VolumeCollectionMap_t m_volumeCollectionMap
Map of volume name to output collection name.

Member Function Documentation

◆ BeginOfEventAction()

void G4UA::MCTruthSteppingAction::BeginOfEventAction ( const G4Event * event)
finaloverridevirtual

Called at the start of each G4 event.

Used to ensure that the TrackRecordCollection WriteHandles are valid.

Definition at line 69 of file MCTruthSteppingAction.cxx.

70 {
71 // First time initialization
72 if(!m_isInitialized) {
74 if (m_recordingEnvelopes.size() == 0) {
75 ATH_MSG_WARNING("No recording envelopes found!");
76 }
77 m_isInitialized = true;
78 }
79 // Every event initialization
80 for (auto& recEnvelope : m_recordingEnvelopes) {
81 if(auto* eventInfo = static_cast<AtlasG4EventUserInfo*>( event->GetUserInformation())){
82 recEnvelope.BeginOfEvent(eventInfo->GetHitCollectionMap()->Find<TrackRecordCollection>(recEnvelope.GetTrackRecordCollectionName()));
83 }
84 }
85 }
#define ATH_MSG_WARNING(x)
AtlasHitsVector< TrackRecord > TrackRecordCollection
void setupRecEnvelopes()
Setup the list of RecordingEnvelope helpers.
std::vector< RecordingEnvelope > m_recordingEnvelopes
List of RecordingEnvelope helpers to invoke.

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 167 of file AthMessaging.h.

168{
169 MsgStream* ms = m_msg_tls.get();
170 if (!ms) {
171 if (!m_initialized.test_and_set()) initMessaging();
172 ms = new MsgStream(m_imsg,m_nm);
173 m_msg_tls.reset( ms );
174 }
175
176 ms->setLevel (m_lvl);
177 return *ms;
178}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels).
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 182 of file AthMessaging.h.

183{ return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 // If user did not set explicit message level we have to initialize
154 // the messaging and retrieve the default via the MessageSvc.
155 if (m_lvl==MSG::NIL && !m_initialized.test_and_set()) initMessaging();
156
157 if (m_lvl <= lvl) {
158 msg() << lvl;
159 return true;
160 } else {
161 return false;
162 }
163}

◆ propagatePrimaryInfoToSecondaries()

void G4UA::MCTruthSteppingAction::propagatePrimaryInfoToSecondaries ( const G4Step * aStep) const
private

Propagate parent primary truth attribution to ordinary secondaries.

Definition at line 138 of file MCTruthSteppingAction.cxx.

139 {
140 if (!aStep) {
141 return;
142 }
143
144 TrackHelper parentHelper(aStep->GetTrack());
145 TrackInformation* parentInfo = parentHelper.GetTrackInformation();
146 HepMC::GenParticlePtr primaryGenParticle = parentInfo ? parentInfo->GetPrimaryGenParticle() : nullptr;
147 if (!primaryGenParticle) {
148 return;
149 }
150
151 const std::vector<const G4Track*>* secondaries = aStep->GetSecondaryInCurrentStep();
152 if (!secondaries) {
153 return;
154 }
155
156 for (const G4Track* secondary : *secondaries) {
157 if (!secondary || secondary->GetUserInformation()) {
158 continue;
159 }
160
161 auto trackInfo = std::make_unique<TrackInformation>();
162 trackInfo->SetPrimaryGenParticle(primaryGenParticle);
163 trackInfo->SetClassification(TrackInformation::Secondary);
164 secondary->SetUserInformation(trackInfo.release());
165 }
166 }
HepMC::ConstGenParticlePtr GetPrimaryGenParticle() const
return a pointer to the GenParticle used to create the initial G4PrimaryParticle from which the curre...
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

◆ setupRecEnvelopes()

void G4UA::MCTruthSteppingAction::setupRecEnvelopes ( )
private

Setup the list of RecordingEnvelope helpers.

Definition at line 37 of file MCTruthSteppingAction.cxx.

38 {
39 ATH_MSG_DEBUG("Setting up " << m_volumeCollectionMap.size() <<
40 " recording envelopes:");
42 for(const auto& volCollPair : m_volumeCollectionMap) {
43 ATH_MSG_DEBUG(" " << volCollPair.first << ", " << volCollPair.second);
44
45 // Construct the helper in place on the vector
46 m_recordingEnvelopes.emplace_back(volCollPair.first, volCollPair.second);
47 RecordingEnvelope& recEnvelope = m_recordingEnvelopes.back();
48
49 // Make sure the RecEnvelope can initialize properly
50 if(!recEnvelope.Initialize()) {
51 //FIXME - should this be an error?
52 ATH_MSG_WARNING("Envelope volume " << recEnvelope.GetVolumeName() <<
53 " not found in geometry!");
54 ATH_MSG_WARNING("TrackRecordCollection " <<
55 recEnvelope.GetTrackRecordCollectionName() <<
56 " will NOT be recorded");
57 // Throw away uninitialized RecordingEnvelope
58 m_recordingEnvelopes.pop_back();
59 }
60 }
61 if (m_recordingEnvelopes.size() == 0) {
62 ATH_MSG_WARNING("No recording envelopes found!");
63 }
64 }
#define ATH_MSG_DEBUG(x)
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...

◆ UserSteppingAction()

void G4UA::MCTruthSteppingAction::UserSteppingAction ( const G4Step * aStep)
finaloverridevirtual

Process one particle step.

If the step crosses a recording envelope volume boundary, passes the step to the corresponding RecordingEnvelope to add a TrackRecord.

Definition at line 90 of file MCTruthSteppingAction.cxx.

91 {
93
94 if (m_recordingEnvelopes.size() == 0) return;
95 TrackHelper trackHelper(aStep->GetTrack());
96 if (trackHelper.IsSecondary()) return;
97
98 G4StepPoint* preStep = aStep->GetPreStepPoint();
99 G4StepPoint* postStep = aStep->GetPostStepPoint();
100
101 G4VPhysicalVolume* preVol = preStep->GetPhysicalVolume();
102 G4VPhysicalVolume* postVol = postStep->GetPhysicalVolume();
103
104 if (preVol == postVol) return;
105
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();
110
111 for (auto& recEnvelope : m_recordingEnvelopes)
112 {
113 const int envelopeLevel = recEnvelope.GetLevel();
114 if (envelopeLevel <= preStepVolDepth)
115 {
116 //NB preTHist->GetVolume(preStepVolDepth) would just give us the World volume.
117 const G4LogicalVolume* logicalVolume1 =
118 preTHist->GetVolume(preStepVolDepth-envelopeLevel)->GetLogicalVolume();
119 if (logicalVolume1 != recEnvelope.GetLogicalVolume()) continue;
120
121 if (envelopeLevel <= postStepVolDepth &&
122 logicalVolume1 == postTHist->GetVolume(postStepVolDepth-envelopeLevel)
123 ->GetLogicalVolume())
124 {
125 continue;
126 }
127
128 // We have a track crossing a recording envelope
129 // volume boundary, so make a TrackRecord
130 recEnvelope.AddTrackRecord(aStep);
131
132 // Done with this volume.
133 break;
134 }
135 }
136 }
void propagatePrimaryInfoToSecondaries(const G4Step *) const
Propagate parent primary truth attribution to ordinary secondaries.

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_isInitialized

bool G4UA::MCTruthSteppingAction::m_isInitialized
private

Used to delay initialization until the event loop, after geo is ready.

Definition at line 68 of file MCTruthSteppingAction.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_recordingEnvelopes

std::vector<RecordingEnvelope> G4UA::MCTruthSteppingAction::m_recordingEnvelopes
private

List of RecordingEnvelope helpers to invoke.

Definition at line 74 of file MCTruthSteppingAction.h.

◆ m_volumeCollectionMap

VolumeCollectionMap_t G4UA::MCTruthSteppingAction::m_volumeCollectionMap
private

Map of volume name to output collection name.

Definition at line 71 of file MCTruthSteppingAction.h.


The documentation for this class was generated from the following files: