ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. More...
 

Public Member Functions

 MCTruthSteppingAction (const VolumeCollectionMap_t &collMap, IMessageSvc *msgSvc, MSG::Level level)
 Construct the action with specified volumes and output collections. More...
 
virtual void BeginOfEventAction (const G4Event *) override final
 Called at the start of each G4 event. More...
 
virtual void UserSteppingAction (const G4Step *) override final
 Process one particle step. More...
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

void setupRecEnvelopes ()
 Setup the list of RecordingEnvelope helpers. More...
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

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

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

22  : AthMessaging(msgSvc, "MCTruthSteppingAction"),
23  m_isInitialized(false),
24  m_volumeCollectionMap(volCollMap)
25  {
26  msg().setLevel(level);
27  }

Member Function Documentation

◆ BeginOfEventAction()

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

Called at the start of each G4 event.

Used to ensure that the TrackRecordCollection WriteHandles are valid.

Definition at line 64 of file MCTruthSteppingAction.cxx.

65  {
66  // First time initialization
67  if(!m_isInitialized) {
69  if (m_recordingEnvelopes.size() == 0) {
70  ATH_MSG_WARNING("No recording envelopes found!");
71  }
72  m_isInitialized = true;
73  }
74  // Every event initialization
75  for (auto& recEnvelope : m_recordingEnvelopes) {
76  recEnvelope.BeginOfEvent();
77  }
78  }

◆ 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  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ 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 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ 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 179 of file AthMessaging.h.

180 { 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_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

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

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

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

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

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.

◆ 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.

◆ 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:
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
G4UA::MCTruthSteppingAction::m_recordingEnvelopes
std::vector< RecordingEnvelope > m_recordingEnvelopes
List of RecordingEnvelope helpers to invoke.
Definition: MCTruthSteppingAction.h:71
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TrackHelper
Definition: TrackHelper.h:14
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
G4UA::MCTruthSteppingAction::m_volumeCollectionMap
VolumeCollectionMap_t m_volumeCollectionMap
Map of volume name to output collection name.
Definition: MCTruthSteppingAction.h:68
G4UA::MCTruthSteppingAction::setupRecEnvelopes
void setupRecEnvelopes()
Setup the list of RecordingEnvelope helpers.
Definition: MCTruthSteppingAction.cxx:32
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
RecordingEnvelope::Initialize
bool Initialize()
Finds the pointer to the G4LogicalVolume called m_envelopeVolumeName and the number of levels beneath...
Definition: RecordingEnvelope.cxx:54
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
RecordingEnvelope::GetTrackRecordCollectionName
std::string GetTrackRecordCollectionName() const
Returns the name of the TrackRecordCollection to which tracks crossing this recording envelope should...
Definition: RecordingEnvelope.h:93
RecordingEnvelope
Responsible for finding the G4LogicalVolume pointer for each recording envelope and for creating and ...
Definition: RecordingEnvelope.h:25
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
RecordingEnvelope::GetVolumeName
const std::string & GetVolumeName() const
Returns the name of the recording envelope volume.
Definition: RecordingEnvelope.h:83
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
G4UA::MCTruthSteppingAction::m_isInitialized
bool m_isInitialized
Used to delay initialization until the event loop, after geo is ready.
Definition: MCTruthSteppingAction.h:65