ATLAS Offline Software
Loading...
Searching...
No Matches
G4UA::LooperKiller Class Referencefinal

A user action to kill looping tracks. More...

#include <LooperKiller.h>

Inheritance diagram for G4UA::LooperKiller:
Collaboration diagram for G4UA::LooperKiller:

Classes

struct  Config
struct  Report

Public Member Functions

 LooperKiller (const Config &config)
virtual void UserSteppingAction (const G4Step *) override
const ReportgetReport () const
 Retrieve results.
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 Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
Config m_config
 My configuration options.
Report m_report
int m_count_steps
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

A user action to kill looping tracks.

Definition at line 22 of file LooperKiller.h.

Member Typedef Documentation

◆ StoreGateSvc_t

Definition at line 54 of file LooperKiller.h.

Constructor & Destructor Documentation

◆ LooperKiller()

G4UA::LooperKiller::LooperKiller ( const Config & config)

Definition at line 31 of file LooperKiller.cxx.

32 : AthMessaging(Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc"),
33 "LooperKiller"),
34 m_evtStore("StoreGateSvc/StoreGateSvc", "LooperKiller"),
35 m_detStore("StoreGateSvc/DetectorStore", "LooperKiller"),
36 m_config(config), m_report(), m_count_steps(0)
37 {
38 }
AthMessaging()
Default constructor:
Config m_config
My configuration options.
StoreGateSvc_t m_evtStore
Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
Pointer to StoreGate (detector store by default)

Member Function Documentation

◆ getReport()

const Report & G4UA::LooperKiller::getReport ( ) const
inline

Retrieve results.

Definition at line 49 of file LooperKiller.h.

50 { return m_report; }

◆ 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; }
MsgStream & msg() const
The standard message stream.

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

◆ UserSteppingAction()

void G4UA::LooperKiller::UserSteppingAction ( const G4Step * aStep)
overridevirtual

Definition at line 41 of file LooperKiller.cxx.

42 {
43
44 if (aStep->GetTrack()->GetCurrentStepNumber() < m_config.MaxSteps) {
45 if (m_count_steps==0) return;
46 // Track recovered...
47 ATH_MSG_WARNING("Track finished on its own. Congrats. Moving on with the event.");
48 m_count_steps = 0;
49 G4TransportationManager *tm = G4TransportationManager::GetTransportationManager();
50 tm->GetNavigatorForTracking()->SetVerboseLevel(0);
51 tm->GetPropagatorInField()->SetVerboseLevel(0);
52 G4RunManagerKernel *rmk = G4RunManagerKernel::GetRunManagerKernel();
53 rmk->GetTrackingManager()->SetVerboseLevel(0);
54 rmk->GetTrackingManager()->GetSteppingManager()->SetVerboseLevel(0);
55 rmk->GetStackManager()->SetVerboseLevel(0);
56 return;
57 } else if (aStep->GetTrack()->GetCurrentStepNumber() == m_config.MaxSteps) {
58 ATH_MSG_WARNING("LooperKiller triggered!! Hold on to your hats!!!!!!!!" );
59 }
60
61 G4TransportationManager *tm = G4TransportationManager::GetTransportationManager();
62 tm->GetNavigatorForTracking()->SetVerboseLevel(m_config.VerboseLevel);
63 tm->GetPropagatorInField()->SetVerboseLevel(m_config.VerboseLevel);
64
65 G4RunManagerKernel *rmk = G4RunManagerKernel::GetRunManagerKernel();
66 rmk->GetTrackingManager()->SetVerboseLevel(m_config.VerboseLevel);
67 rmk->GetTrackingManager()->GetSteppingManager()->SetVerboseLevel(m_config.VerboseLevel);
68 rmk->GetStackManager()->SetVerboseLevel(m_config.VerboseLevel);
69
71
72 if (m_count_steps>m_config.PrintSteps) {
73 m_count_steps = 0;
74 m_report.killed_tracks++;
75 aStep->GetTrack()->SetTrackStatus(fStopAndKill);
76 tm->GetNavigatorForTracking()->SetVerboseLevel(0);
77 tm->GetPropagatorInField()->SetVerboseLevel(0);
78 rmk->GetTrackingManager()->SetVerboseLevel(0);
79 rmk->GetTrackingManager()->GetSteppingManager()->SetVerboseLevel(0);
80 rmk->GetStackManager()->SetVerboseLevel(0);
81 int pdg_id{0};
82 TrackHelper trackHelper(aStep->GetTrack());
83 if ( m_config.BSM_Only && (trackHelper.IsPrimary() || trackHelper.IsRegisteredSecondary()) ) {
84 HepMC::GenParticlePtr part = trackHelper.GetTrackInformation()->GetCurrentGenParticle();
85 if (part) { pdg_id = part->pdg_id(); }
86 }
87 if ( !m_config.BSM_Only || MC::isBSM(pdg_id)) { // Sometimes we may ony want to bail out for BSM particles.
88 // Bail out...
89 if (m_config.AbortEvent){
90 rmk->GetEventManager()->AbortCurrentEvent();
91 rmk->GetEventManager()->GetNonconstCurrentEvent()->SetEventAborted();
92 }
93 if (m_config.SetError){
94
95 // Set error state in eventInfo
96 SG::ReadHandle<xAOD::EventInfo> eic("McEventInfo");
97 if (! eic.isValid()){
98 ATH_MSG_WARNING( "Failed to retrieve EventInfo" );
99 } else {
100 eic->updateErrorState(xAOD::EventInfo::Core,xAOD::EventInfo::Error);
101 ATH_MSG_WARNING( "Set error state in event info!" );
102 }
103 } // End of set error
104 } // End of BSM-only check
105 const std::string name = aStep->GetTrack()->GetDefinition()->GetParticleName();
106 if ( ( m_config.BSM_Only && !MC::isBSM(pdg_id) ) || !m_config.AbortEvent ) {
107 ATH_MSG_INFO ("Quietly stopped tracking looping " << name
108 << " (trackID " << aStep->GetTrack()->GetTrackID()
109 << ", track pos: "<<aStep->GetTrack()->GetPosition()
110 << ", mom: "<<aStep->GetTrack()->GetMomentum()
111 << ", parentID " << aStep->GetTrack()->GetParentID() << ")");
112 } else {
113 ATH_MSG_WARNING ("Stopped tracking looping " << name
114 << " (trackID " << aStep->GetTrack()->GetTrackID()
115 << ", track pos: "<<aStep->GetTrack()->GetPosition()
116 << ", mom: "<<aStep->GetTrack()->GetMomentum()
117 << ", parentID " << aStep->GetTrack()->GetParentID() << "). The event will abort now.");
118 }
119 } // End of handling end of error time
120 }
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
@ Core
Core flags describing the event.
@ Error
The sub-detector issued an error.
GenParticle * GenParticlePtr
Definition GenParticle.h:37
bool isBSM(const T &p)
APID: graviton and all Higgs extensions are BSM.

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_config

Config G4UA::LooperKiller::m_config
private

My configuration options.

Definition at line 61 of file LooperKiller.h.

◆ m_count_steps

int G4UA::LooperKiller::m_count_steps
private

Definition at line 63 of file LooperKiller.h.

◆ m_detStore

StoreGateSvc_t G4UA::LooperKiller::m_detStore
private

Pointer to StoreGate (detector store by default)

Definition at line 58 of file LooperKiller.h.

◆ m_evtStore

StoreGateSvc_t G4UA::LooperKiller::m_evtStore
private

Pointer to StoreGate (event store by default)

Definition at line 56 of file LooperKiller.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

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

Report G4UA::LooperKiller::m_report
private

Definition at line 62 of file LooperKiller.h.


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