Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
LooperKiller.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "LooperKiller.h"
6 
7 #include "G4RunManagerKernel.hh"
8 #include "G4TransportationManager.hh"
9 #include "G4Navigator.hh"
10 #include "G4PropagatorInField.hh"
11 #include "G4TrackingManager.hh"
12 #include "G4SteppingManager.hh"
13 #include "G4StackManager.hh"
14 #include "G4EventManager.hh"
15 #include "G4Event.hh"
16 #include "MCTruth/TrackHelper.h"
18 #include "StoreGate/ReadHandle.h"
19 #include "StoreGate/StoreGateSvc.h"
22 
23 #include "GaudiKernel/Bootstrap.h"
24 #include "GaudiKernel/ISvcLocator.h"
25 #include "GaudiKernel/IMessageSvc.h"
26 
27 namespace G4UA
28 {
29 
30  //---------------------------------------------------------------------------
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  }
39 
40  //---------------------------------------------------------------------------
41  void LooperKiller::UserSteppingAction(const G4Step* aStep)
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 
70  m_count_steps++;
71 
73  m_count_steps = 0;
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()) ) {
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 {
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  }
121 
122 } // namespace G4UA
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
G4UA::LooperKiller::Config
Definition: LooperKiller.h:28
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
isBSM
bool isBSM(const T &p)
APID: graviton and all Higgs extensions are BSM.
Definition: AtlasPID.h:783
G4UA::LooperKiller::m_count_steps
int m_count_steps
Definition: LooperKiller.h:63
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TrackHelper.h
G4UA::LooperKiller::Config::AbortEvent
bool AbortEvent
Definition: LooperKiller.h:32
HepMC::GenParticlePtr
GenParticle * GenParticlePtr
Definition: GenParticle.h:37
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
xAOD::EventInfo_v1::Error
@ Error
The sub-detector issued an error.
Definition: EventInfo_v1.h:349
TrackHelper
Definition: TrackHelper.h:14
G4UA::LooperKiller::Report::killed_tracks
long killed_tracks
Definition: LooperKiller.h:39
G4UA::LooperKiller::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition: LooperKiller.cxx:41
G4UA::LooperKiller::Config::PrintSteps
int PrintSteps
Definition: LooperKiller.h:30
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
G4UA::LooperKiller::m_config
Config m_config
My configuration options.
Definition: LooperKiller.h:61
G4UA::LooperKiller::Config::BSM_Only
bool BSM_Only
Definition: LooperKiller.h:34
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
G4UA::LooperKiller::LooperKiller
LooperKiller(const Config &config)
Definition: LooperKiller.cxx:31
G4UA::LooperKiller::m_report
Report m_report
Definition: LooperKiller.h:62
TrackHelper::GetTrackInformation
TrackInformation * GetTrackInformation()
Definition: TrackHelper.h:24
G4UA::LooperKiller::Config::VerboseLevel
int VerboseLevel
Definition: LooperKiller.h:31
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TrackInformation.h
EventInfo.h
TrackHelper::IsRegisteredSecondary
bool IsRegisteredSecondary() const
Definition: TrackHelper.cxx:25
TrackHelper::IsPrimary
bool IsPrimary() const
Definition: TrackHelper.cxx:15
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
G4UA::LooperKiller::Config::SetError
bool SetError
Definition: LooperKiller.h:33
LooperKiller.h
xAOD::EventInfo_v1::updateErrorState
bool updateErrorState(const EventFlagSubDet subDet, const EventFlagErrorState state) const
Update the error state for one particular sub-detector.
Definition: EventInfo_v1.cxx:856
ReadHandle.h
Handle class for reading from StoreGate.
StoreGateSvc.h
xAOD::EventInfo_v1::Core
@ Core
Core flags describing the event.
Definition: EventInfo_v1.h:339
HepMCHelpers.h
G4UA::LooperKiller::Config::MaxSteps
int MaxSteps
Definition: LooperKiller.h:29
TrackInformation::GetCurrentGenParticle
virtual HepMC::ConstGenParticlePtr GetCurrentGenParticle() const override
return a pointer to the GenParticle corresponding to the current G4Track (if there is one).
Definition: TrackInformation.h:49