ATLAS Offline Software
Loading...
Searching...
No Matches
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
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//=================================
92G4VPhysicalVolume*
94 ATH_MSG_DEBUG("Detectors " << m_detConstructionTool->m_detTool.name()
95 << " being set as World");
96 m_detConstructionTool->m_detTool->SetAsWorld();
97 m_detConstructionTool->m_detTool->Build();
98
99 ATH_MSG_DEBUG( "Setting up G4 physics regions" );
100 for (auto& it : m_detConstructionTool->m_regionCreators) {
101 it->Construct();
102 }
103
104 if (m_detConstructionTool->m_activateParallelWorlds) {
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" );
113 for (auto it : m_detConstructionTool->m_configurationTools) {
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
G4VUserDetectorConstruction object passed to the G4 run manager Thid shouldn't live longer than the p...
ToolHandleArray< IRegionCreator > m_regionCreators
G4AtlasDetectorConstructionTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
virtual UPDetectorConstruction GetDetectorConstruction() override final
implements the following IDetectorConstructionTool methods
virtual std::vector< std::string > & GetParallelWorldNames() override final
ToolHandleArray< IG4GeometryConfigurationTool > m_configurationTools
ToolHandleArray< IFieldManagerTool > m_fieldManagers
virtual StatusCode initialize() override final
Initialize method.
PublicToolHandle< IG4CaloTransportTool > m_G4CaloTransportTool
ToolHandleArray< IParallelWorldTool > m_parallelWorlds
PublicToolHandle< ISensitiveDetectorMasterTool > m_senDetTool
ToolHandle< IDetectorGeometryTool > m_detTool
PublicToolHandle< IFastSimulationMasterTool > m_fastSimTool