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