ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
G4UA::HyperspaceCatcher Class Reference

User action for catching cases of the hyperspace bug. More...

#include <HyperspaceCatcher.h>

Inheritance diagram for G4UA::HyperspaceCatcher:
Collaboration diagram for G4UA::HyperspaceCatcher:

Classes

struct  Config
 

Public Member Functions

 HyperspaceCatcher (const Config &config)
 
virtual void BeginOfRunAction (const G4Run *) override
 
virtual void UserSteppingAction (const G4Step *) override
 
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 initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

Config m_config
 
G4VSolid * m_world
 
int m_killCount
 
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 for catching cases of the hyperspace bug.

Definition at line 23 of file HyperspaceCatcher.h.

Constructor & Destructor Documentation

◆ HyperspaceCatcher()

G4UA::HyperspaceCatcher::HyperspaceCatcher ( const Config config)

Definition at line 28 of file HyperspaceCatcher.cxx.

28  :
29  AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),"HyperspaceCatcher"),
31  m_world(0),
32  m_killCount(0)
33  {}

Member Function Documentation

◆ BeginOfRunAction()

void G4UA::HyperspaceCatcher::BeginOfRunAction ( const G4Run *  )
overridevirtual

Definition at line 35 of file HyperspaceCatcher.cxx.

36  {
37  // Highest level implemented is 2 at the moment
39  ATH_MSG_INFO("Treatment level set to " << m_config.treatmentLevel );
40 
41  ATH_MSG_INFO("Set to kill after " << m_config.killAfter );
42 
43  G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
44  for (auto lv : *lvs){
45  if ( lv->GetName()=="Atlas::Atlas" ){
46  m_world=lv->GetSolid();
47  break;
48  }
49  }
50  if (0==m_world){
51  ATH_MSG_FATAL( "Could not find world volume!" );
52  throw std::runtime_error("Could not find world volume!");
53  }
54  }

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

◆ UserSteppingAction()

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

Definition at line 56 of file HyperspaceCatcher.cxx.

57  {
58 
59  bool hs = false;
60 
61  // Various levels of testing. Simple testing at level 0 : just see if it's in the neighborhood
62  G4ThreeVector myPos = aStep->GetPostStepPoint()->GetPosition();
63  if (std::fabs( myPos.x() )>30000. ||
64  std::fabs( myPos.y() )>30000. ||
65  std::fabs( myPos.z() )>50000. ){
66  hs=true;
67  } // Check #1 failed
68  if (!hs && m_config.treatmentLevel<=0) return;
69 
70  if ( m_world->Inside( myPos ) == kOutside ){
71  hs=true;
72  } // Check #2 failed
73  if (!hs && m_config.treatmentLevel<=1) return;
74 
75  G4VSolid * pre = aStep->GetPreStepPoint()->GetPhysicalVolume() &&
76  aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume() ?
77  aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetSolid():0;
78  G4VSolid * post = aStep->GetPostStepPoint()->GetPhysicalVolume() &&
79  aStep->GetPostStepPoint()->GetPhysicalVolume()->GetLogicalVolume() ?
80  aStep->GetPostStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetSolid():0;
81  if ( (post && post->Inside( myPos ) == kOutside ) ||
82  ( pre && pre->Inside( aStep->GetPreStepPoint()->GetPosition() ) == kOutside ) ) {
83  hs=true;
84  } // Check #3 failed
85  if (!hs && m_config.treatmentLevel<=2) return;
86 
87  G4Track *tr = aStep->GetTrack();
88  const G4ThreeVector& mom = tr->GetMomentumDirection();
89 
90  std::cout << "Caught a " << tr->GetDefinition()->GetParticleName() << " at (" << myPos.x()
91  << ", " << myPos.y() << ", " << myPos.z() << ") to (" << mom.x() << ", " << mom.y()
92  << ", " << mom.z() << ") from ";
93  if (aStep->GetPreStepPoint()->GetPhysicalVolume()) {
94  std::cout << aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName();
95  }
96  else std::cout << "noVolume";
97  std::cout << " to ";
98  if (aStep->GetPostStepPoint()->GetPhysicalVolume()) {
99  std::cout << aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
100  }
101  else std::cout << "outOfWorld";
102  std::cout << " with KE=" << tr->GetKineticEnergy() << " pT=" << tr->GetMomentum().perp()
103  << " eta=" << tr->GetMomentum().eta() << " length " << aStep->GetStepLength() << " energy "
104  << aStep->GetTotalEnergyDeposit() << " with process ";
105  if (aStep->GetPostStepPoint()->GetProcessDefinedStep()) {
106  std::cout << aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
107  }
108  else std::cout << "Unknown";
109  std::cout << " from a ";
110  if (tr->GetCreatorProcess()) std::cout << tr->GetCreatorProcess()->GetProcessName();
111  else if (tr->GetParentID()==0) std::cout << "Generator";
112  else std::cout << "pid="<<tr->GetParentID();
113  if (tr->GetLogicalVolumeAtVertex()) std::cout << " in " << tr->GetLogicalVolumeAtVertex()->GetName() << ", ";
114  else std::cout << " nowhere, ";
115  std::cout << tr->GetTrackLength() << " mm ago" << std::endl;
116  ATH_MSG_WARNING( "HYPERSPACE PARTICLE DETECTED!! KILLING!!" );
117 
118  const G4TrackVector *tv = aStep->GetSecondary();
119  for (auto atv : *tv ){
120  if ( m_world->Inside( atv->GetPosition() ) == kOutside ){
121  atv->SetTrackStatus(fStopAndKill);
122  ++m_killCount;
123  ATH_MSG_WARNING("Had to kill a secondary as well");
124  }
125  }
126 
127  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
128  ++m_killCount;
129 
131  ATH_MSG_FATAL( m_config.killAfter << " cases of hyperspace bug found. You have something seriously wrong going on here. Needs to be fixed. Bailing out." );
132  throw std::runtime_error("Hyperspace bug found");
133  }
134  }

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::HyperspaceCatcher::m_config
private

Definition at line 42 of file HyperspaceCatcher.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_killCount

int G4UA::HyperspaceCatcher::m_killCount
private

Definition at line 44 of file HyperspaceCatcher.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_world

G4VSolid* G4UA::HyperspaceCatcher::m_world
private

Definition at line 43 of file HyperspaceCatcher.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
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
G4UA::HyperspaceCatcher::m_killCount
int m_killCount
Definition: HyperspaceCatcher.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4UA::HyperspaceCatcher::Config::treatmentLevel
int treatmentLevel
Definition: HyperspaceCatcher.h:32
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
G4UA::HyperspaceCatcher::Config::killAfter
int killAfter
Definition: HyperspaceCatcher.h:33
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
CreatePhysValWebPage.hs
hs
Definition: CreatePhysValWebPage.py:107
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
G4UA::HyperspaceCatcher::m_world
G4VSolid * m_world
Definition: HyperspaceCatcher.h:43
G4UA::HyperspaceCatcher::m_config
Config m_config
Definition: HyperspaceCatcher.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
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