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 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 21 of file MCTruthSteppingAction.cxx.

24 : AthMessaging(msgSvc, "MCTruthSteppingAction"),
25 m_isInitialized(false),
26 m_volumeCollectionMap(volCollMap)
27 {
28 msg().setLevel(level);
29 }
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 66 of file MCTruthSteppingAction.cxx.

67 {
68 // First time initialization
69 if(!m_isInitialized) {
71 if (m_recordingEnvelopes.size() == 0) {
72 ATH_MSG_WARNING("No recording envelopes found!");
73 }
74 m_isInitialized = true;
75 }
76 // Every event initialization
77 for (auto& recEnvelope : m_recordingEnvelopes) {
78 if(auto* eventInfo = static_cast<AtlasG4EventUserInfo*>( event->GetUserInformation())){
79 recEnvelope.BeginOfEvent(eventInfo->GetHitCollectionMap()->Find<TrackRecordCollection>(recEnvelope.GetTrackRecordCollectionName()));
80 }
81 }
82 }
#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 163 of file AthMessaging.h.

164{
165 MsgStream* ms = m_msg_tls.get();
166 if (!ms) {
167 if (!m_initialized.test_and_set()) initMessaging();
168 ms = new MsgStream(m_imsg,m_nm);
169 m_msg_tls.reset( ms );
170 }
171
172 ms->setLevel (m_lvl);
173 return *ms;
174}
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 178 of file AthMessaging.h.

179{ 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 (m_lvl <= lvl) {
154 msg() << lvl;
155 return true;
156 } else {
157 return false;
158 }
159}

◆ 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 34 of file MCTruthSteppingAction.cxx.

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

88 {
89 if (m_recordingEnvelopes.size() == 0) return;
90 TrackHelper trackHelper(aStep->GetTrack());
91 if (trackHelper.IsSecondary()) return;
92
93 G4StepPoint* preStep = aStep->GetPreStepPoint();
94 G4StepPoint* postStep = aStep->GetPostStepPoint();
95
96 G4VPhysicalVolume* preVol = preStep->GetPhysicalVolume();
97 G4VPhysicalVolume* postVol = postStep->GetPhysicalVolume();
98
99 if (preVol == postVol) return;
100
101 const G4TouchableHistory* preTHist = static_cast<const G4TouchableHistory*>(preStep->GetTouchable());
102 const G4TouchableHistory* postTHist = static_cast<const G4TouchableHistory*>(postStep->GetTouchable());
103 const int preStepVolDepth = preTHist->GetHistoryDepth();
104 const int postStepVolDepth = postTHist->GetHistoryDepth();
105
106 for (auto& recEnvelope : m_recordingEnvelopes)
107 {
108 const int envelopeLevel = recEnvelope.GetLevel();
109 if (envelopeLevel <= preStepVolDepth)
110 {
111 //NB preTHist->GetVolume(preStepVolDepth) would just give us the World volume.
112 const G4LogicalVolume* logicalVolume1 =
113 preTHist->GetVolume(preStepVolDepth-envelopeLevel)->GetLogicalVolume();
114 if (logicalVolume1 != recEnvelope.GetLogicalVolume()) continue;
115
116 if (envelopeLevel <= postStepVolDepth &&
117 logicalVolume1 == postTHist->GetVolume(postStepVolDepth-envelopeLevel)
118 ->GetLogicalVolume())
119 {
120 continue;
121 }
122
123 // We have a track crossing a recording envelope
124 // volume boundary, so make a TrackRecord
125 recEnvelope.AddTrackRecord(aStep);
126
127 // Done with this volume.
128 break;
129 }
130 }
131 }

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 65 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 71 of file MCTruthSteppingAction.h.

◆ m_volumeCollectionMap

VolumeCollectionMap_t G4UA::MCTruthSteppingAction::m_volumeCollectionMap
private

Map of volume name to output collection name.

Definition at line 68 of file MCTruthSteppingAction.h.


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