ATLAS Offline Software
G4AtlasDetectorConstructionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Include files
6 #include <type_traits>
7 
8 #include "G4LogicalVolumeStore.hh"
9 #include "G4PhysicalVolumeStore.hh"
10 #include "G4Version.hh"
11 
12 // local
14 
15 //-----------------------------------------------------------------------------
16 // Implementation file for class : G4AtlasDetectorConstructionTool
17 //
18 // 2014-10-03: Andrea Dell'Acqua
19 //-----------------------------------------------------------------------------
20 
21 
22 //=================================
23 // Standard constructor, initializes variables
24 //=================================
26  const std::string& nam,const IInterface* parent )
27  : base_class( type, nam , parent )
28 {
29 }
30 
31 //=================================
32 // Athena method overrides
33 //=================================
35 {
36  ATH_MSG_DEBUG( "Initializing Geometry configuration tools " );
37  for (auto it: m_configurationTools)
38  {
39  ATH_CHECK( it.retrieve() );
40  ATH_CHECK( it->preGeometryConfigure() );
41  }
42 
43  ATH_MSG_DEBUG( "Initializing World detectors in " << name() );
44  ATH_CHECK( m_detTool.retrieve() );
45 
46  ATH_MSG_DEBUG( "Initializing sensitive detectors in " << name() );
47  ATH_CHECK( m_senDetTool.retrieve() );
48 
49  ATH_MSG_DEBUG( "Initializing fastsim in " << name() );
50  ATH_CHECK( m_fastSimTool.retrieve() );
51 
52  ATH_MSG_DEBUG( "Setting up G4 physics regions" );
53  for (auto& it: m_regionCreators)
54  {
55  ATH_CHECK( it.retrieve() );
56  }
57 
59  {
60  ATH_MSG_DEBUG( "Setting up G4 parallel worlds" );
61  for (auto& it: m_parallelWorlds)
62  {
63  ATH_CHECK( it.retrieve() );
64  }
65  }
66 
67  ATH_MSG_DEBUG( "Setting up field managers" );
68  ATH_CHECK( m_fieldManagers.retrieve() );
69 
70  ATH_CHECK( m_G4CaloTransportTool.retrieve( DisableTool{ m_G4CaloTransportTool.empty() } ) );
71 
72  return StatusCode::SUCCESS;
73 }
74 
76 {
77  return m_parallelWorldNames;
78 }
79 
81  -> UPDetectorConstruction {
82  static_assert(std::has_virtual_destructor_v<G4VUserDetectorConstruction>,
83  "G4VUserDetectorConstruction must have a virtual destructor");
84  return {
86  [](G4VUserDetectorConstruction* ptr) { delete ptr; }};
87 }
88 
89 //=================================
90 // G4VUserDetectorConstruction method overrides
91 //=================================
92 G4VPhysicalVolume*
94  ATH_MSG_DEBUG("Detectors " << m_detConstructionTool->m_detTool.name()
95  << " being set as World");
96  m_detConstructionTool->m_detTool->SetAsWorld();
98 
99  ATH_MSG_DEBUG( "Setting up G4 physics regions" );
100  for (auto& it : m_detConstructionTool->m_regionCreators) {
101  it->Construct();
102  }
103 
105  ATH_MSG_DEBUG( "Setting up G4 parallel worlds" );
106  for (auto& it : m_detConstructionTool->m_parallelWorlds) {
107  m_detConstructionTool->m_parallelWorldNames.push_back(it.name());
108  this->RegisterParallelWorld(it->GetParallelWorld());
109  }
110  }
111 
112  ATH_MSG_DEBUG( "Running geometry post-configuration tools" );
114  StatusCode sc = it->postGeometryConfigure();
115  if (!sc.isSuccess())
116  {
117  ATH_MSG_FATAL( "Unable to run post-geometry configuration for " << it->name() );
118  }
119  }
120 
121  // Build world volume and rebuild LV/PV stores if Geant4 is 11 or newer
122  // - Rebuild necessary because Athena may install LV/PV notifiers that change
123  // volume names, which invalidates store maps.
124  G4VPhysicalVolume* wv = m_detConstructionTool->m_detTool->GetWorldVolume();
125 #if G4VERSION_NUMBER > 1079
126  G4LogicalVolumeStore::GetInstance()->SetMapValid(false);
127  G4LogicalVolumeStore::GetInstance()->UpdateMap();
128  G4PhysicalVolumeStore::GetInstance()->SetMapValid(false);
129  G4PhysicalVolumeStore::GetInstance()->UpdateMap();
130 #endif
131 
132  return wv;
133 }
134 
137  ATH_MSG_DEBUG( "Setting up sensitive detectors" );
138  if (m_detConstructionTool->m_senDetTool->initializeSDs().isFailure()) {
139  ATH_MSG_FATAL("Failed to initialize SDs for worker thread");
140  }
141 
142  if(!m_detConstructionTool->m_fastSimTool->initializeFastSims().isSuccess()) {
143  ATH_MSG_FATAL("Failed to initialize Fast Simulation Tool for worker thread");
144  return;
145  }
146 
147  ATH_MSG_DEBUG( "Setting up field managers" );
148  for (auto& fm : m_detConstructionTool->m_fieldManagers) {
149  StatusCode sc = fm->initializeField();
150  if (!sc.isSuccess())
151  {
152  ATH_MSG_FATAL( "Unable to initialise field with " << fm->name() );
153  return;
154  }
155  }
156 
157  if (m_detConstructionTool->m_G4CaloTransportTool.isEnabled()) {
158  ATH_MSG_DEBUG("Setting up G4CaloTransportTool");
159  if (m_detConstructionTool->m_G4CaloTransportTool->initializePropagator()
160  .isFailure()) {
161  ATH_MSG_FATAL("Failed to initialize G4CaloTransportTool for worker thread.");
162  return;
163  }
164  }
165 
166  return;
167 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
G4AtlasDetectorConstructionTool::m_fieldManagers
ToolHandleArray< IFieldManagerTool > m_fieldManagers
Definition: G4AtlasDetectorConstructionTool.h:77
G4AtlasDetectorConstructionTool::G4AtlasDetectorConstructionTool
G4AtlasDetectorConstructionTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: G4AtlasDetectorConstructionTool.cxx:25
G4AtlasDetectorConstructionTool::GetDetectorConstruction
virtual UPDetectorConstruction GetDetectorConstruction() override final
implements the following IDetectorConstructionTool methods
Definition: G4AtlasDetectorConstructionTool.cxx:80
G4AtlasDetectorConstructionTool::m_detTool
ToolHandle< IDetectorGeometryTool > m_detTool
Definition: G4AtlasDetectorConstructionTool.h:71
skel.it
it
Definition: skel.GENtoEVGEN.py:407
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
G4AtlasDetectorConstructionTool::m_senDetTool
PublicToolHandle< ISensitiveDetectorMasterTool > m_senDetTool
Definition: G4AtlasDetectorConstructionTool.h:75
G4AtlasDetectorConstructionTool::G4AtlasDetectorConstruction
G4VUserDetectorConstruction object passed to the G4 run manager Thid shouldn't live longer than the p...
Definition: G4AtlasDetectorConstructionTool.h:41
G4AtlasDetectorConstructionTool::G4AtlasDetectorConstruction::ConstructSDandField
virtual void ConstructSDandField() override final
Definition: G4AtlasDetectorConstructionTool.cxx:136
G4AtlasDetectorConstructionTool::m_fastSimTool
PublicToolHandle< IFastSimulationMasterTool > m_fastSimTool
Definition: G4AtlasDetectorConstructionTool.h:76
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
G4AtlasDetectorConstructionTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
G4AtlasDetectorConstructionTool::m_parallelWorlds
ToolHandleArray< IParallelWorldTool > m_parallelWorlds
Definition: G4AtlasDetectorConstructionTool.h:73
G4AtlasDetectorConstructionTool::G4AtlasDetectorConstruction::Construct
virtual G4VPhysicalVolume * Construct() override final
Definition: G4AtlasDetectorConstructionTool.cxx:93
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
G4AtlasDetectorConstructionTool::m_activateParallelWorlds
Gaudi::Property< bool > m_activateParallelWorlds
Definition: G4AtlasDetectorConstructionTool.h:79
G4AtlasDetectorConstructionTool::m_regionCreators
ToolHandleArray< IRegionCreator > m_regionCreators
Definition: G4AtlasDetectorConstructionTool.h:72
G4AtlasDetectorConstructionTool::m_configurationTools
ToolHandleArray< IG4GeometryConfigurationTool > m_configurationTools
Definition: G4AtlasDetectorConstructionTool.h:74
G4AtlasDetectorConstructionTool::initialize
virtual StatusCode initialize() override final
Initialize method.
Definition: G4AtlasDetectorConstructionTool.cxx:34
G4AtlasDetectorConstructionTool::m_parallelWorldNames
std::vector< std::string > m_parallelWorldNames
Definition: G4AtlasDetectorConstructionTool.h:80
G4AtlasDetectorConstructionTool::GetParallelWorldNames
virtual std::vector< std::string > & GetParallelWorldNames() override final
Definition: G4AtlasDetectorConstructionTool.cxx:75
G4AtlasDetectorConstructionTool::G4AtlasDetectorConstruction::m_detConstructionTool
G4AtlasDetectorConstructionTool * m_detConstructionTool
Definition: G4AtlasDetectorConstructionTool.h:52
G4AtlasDetectorConstructionTool::m_G4CaloTransportTool
PublicToolHandle< IG4CaloTransportTool > m_G4CaloTransportTool
Definition: G4AtlasDetectorConstructionTool.h:78