ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Utilities
G4FastSimulation
src
AFatrasG4Tool.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 "
AFatrasG4Tool.h
"
6
#include "
AFatrasG4.h
"
7
8
9
StatusCode
AFatrasG4Tool::initializeFastSim
()
10
{
11
ATH_CHECK
(
FastSimulationBase::initializeFastSim
());
12
ATH_CHECK
(
m_ActsFatrasG4Tool
.retrieve());
13
ATH_CHECK
(
m_pixelHitsKey
.initialize());
14
ATH_CHECK
(
m_sctHitsKey
.initialize());
15
return
StatusCode::SUCCESS;
16
}
17
18
StatusCode
AFatrasG4Tool::BeginOfAthenaEvent
(
HitCollectionMap
& hcm)
19
{
20
ATH_MSG_DEBUG
(
"AFatrasG4Tool:BeginOfAthenaEvent"
);
21
ATH_CHECK
(
FastSimulationBase::BeginOfAthenaEvent
(hcm));
22
if
(msgLvl(MSG::DEBUG)){
23
const
EventContext& ctx = Gaudi::Hive::currentContext();
24
ATH_MSG_DEBUG
(
"BeginOfAthenaEvent slot="
<< ctx.slot());
25
}
26
27
return
StatusCode::SUCCESS;
28
}
29
30
31
G4VFastSimulationModel*
AFatrasG4Tool::makeFastSimModel
()
32
{
33
ATH_MSG_INFO
(
"Initializing Fast Simulation Model AFatrasG4"
);
34
// Create the AFatrasG4 fast simulation model
35
return
new
AFatrasG4
(name(),
getRegion
(),
m_ActsFatrasG4Tool
,
this
);
36
}
37
38
StatusCode
AFatrasG4Tool::EndOfAthenaEvent
(
HitCollectionMap
& hcm)
39
{
40
ATH_MSG_DEBUG
(
"AFatrasG4Tool:EndOfAthenaEvent"
);
41
const
EventContext& ctx = Gaudi::Hive::currentContext();
42
ATH_MSG_DEBUG
(
"EndOfAthenaEvent slot="
<< ctx.slot());
//check if same slot as in BeginOfAthenaEvent
43
44
// create the store record once at the end of each athena event
45
SG::WriteHandle<SiHitCollection>
pixelHandle(
m_pixelHitsKey
, ctx);
46
if
(!pixelHandle.
isValid
()) {
47
ATH_MSG_DEBUG
(
"Pixel container not valid — recording now"
);
48
ATH_CHECK
(pixelHandle.
record
(std::make_unique<SiHitCollection>(
m_pixelHitsKey
.key())));
49
}
else
{
50
ATH_MSG_DEBUG
(
"Pixel container already valid"
);
51
}
52
53
SG::WriteHandle<SiHitCollection>
sctHandle(
m_sctHitsKey
, ctx);
54
if
(!sctHandle.
isValid
()) {
55
ATH_MSG_DEBUG
(
"SCT container not valid — recording now"
);
56
ATH_CHECK
(sctHandle.
record
(std::make_unique<SiHitCollection>(
m_sctHitsKey
.key())));
57
}
else
{
58
ATH_MSG_DEBUG
(
"SCT container already valid"
);
59
}
60
61
if
(msgLvl(MSG::DEBUG)) {
62
// check if record stores created
63
ATH_MSG_DEBUG
(
"---- HIT DEBUG ----"
);
64
ATH_MSG_DEBUG
(
"Slot = "
<< ctx.slot());
65
ATH_MSG_DEBUG
(
"Pixel key = "
<<
m_pixelHitsKey
.key());
66
ATH_MSG_DEBUG
(
"Pixel isPresent = "
<< pixelHandle.
isPresent
());
67
ATH_MSG_DEBUG
(
"Pixel isValid = "
<< pixelHandle.
isValid
());
68
ATH_MSG_DEBUG
(
"SCT key = "
<< sctHandle.
key
());
69
ATH_MSG_DEBUG
(
"SCT isPresent = "
<< sctHandle.
isPresent
());
70
ATH_MSG_DEBUG
(
"SCT isValid = "
<< sctHandle.
isValid
());
71
ATH_MSG_DEBUG
(
"-------------------"
);
72
}
73
74
if
(!pixelHandle.
isValid
() || !sctHandle.
isValid
()) {
75
ATH_MSG_ERROR
(
"Hit containers missing at EndOfAthenaEvent!"
);
76
return
StatusCode::FAILURE;
77
}
78
79
// Get hits from ActsFatrasG4Tool cache
80
const
auto
& pixelHits =
m_ActsFatrasG4Tool
->getPixelHitsCache(ctx);
81
const
auto
& sctHits =
m_ActsFatrasG4Tool
->getSCTHitsCache(ctx);
82
ATH_MSG_DEBUG
(
"Pixel cache size = "
<< pixelHits.size());
83
ATH_MSG_DEBUG
(
"SCT cache size = "
<< sctHits.size());
84
85
// Fill the hits to store handler from the caches
86
for
(
const
auto
&
hit
: pixelHits) {pixelHandle->push_back(
hit
);}
87
for
(
const
auto
&
hit
: sctHits) {sctHandle->push_back(
hit
);}
88
ATH_MSG_DEBUG
(
"After fill:"
);
89
ATH_MSG_DEBUG
(
"Pixel container size = "
<< pixelHandle->size());
90
ATH_MSG_DEBUG
(
"SCT container size = "
<< sctHandle->size());
91
92
// sanity printing
93
if
(msgLvl(MSG::VERBOSE)) {
94
ATH_MSG_VERBOSE
(
"==== FatrasG4Tool: Pixel Hits ===="
);
95
for
(
const
SiHit
&
hit
: *pixelHandle) {
96
const
auto
& start =
hit
.localStartPosition();
97
const
auto
& end =
hit
.localEndPosition();
98
int
barcode =
hit
.particleLink().barcode();
99
100
ATH_MSG_VERBOSE
(
"TrackID="
<< barcode
101
<<
" Edep(MeV)="
<<
hit
.energyLoss()
102
<<
" LocalStart=("
103
<< start.x() <<
", "
104
<< start.y() <<
", "
105
<< start.z() <<
")"
106
<<
" LocalEnd=("
107
<< end.x() <<
", "
108
<< end.y() <<
", "
109
<< end.z() <<
")"
);
110
}
111
ATH_MSG_VERBOSE
(
"==== FatrasG4Tool: SCT Hits ===="
);
112
for
(
const
SiHit
&
hit
: *sctHandle) {
113
const
auto
& start =
hit
.localStartPosition();
114
const
auto
& end =
hit
.localEndPosition();
115
int
barcode =
hit
.particleLink().barcode();
116
117
ATH_MSG_VERBOSE
(
"TrackID="
<< barcode
118
<<
" Edep(MeV)="
<<
hit
.energyLoss()
119
<<
" LocalStart=("
120
<< start.x() <<
", "
121
<< start.y() <<
", "
122
<< start.z() <<
")"
123
<<
" LocalEnd=("
124
<< end.x() <<
", "
125
<< end.y() <<
", "
126
<< end.z() <<
")"
);
127
}
128
}
129
130
// Clear cache for next event
131
m_ActsFatrasG4Tool
->clearCaches(ctx);
132
133
return
FastSimulationBase::EndOfAthenaEvent
(hcm);
134
}
AFatrasG4Tool.h
AFatrasG4.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:30
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:27
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:28
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
AFatrasG4Tool::initializeFastSim
virtual StatusCode initializeFastSim() override final
Method to make the actual fast simulation model itself, which will be owned by the tool.
Definition
AFatrasG4Tool.cxx:9
AFatrasG4Tool::m_sctHitsKey
SG::WriteHandleKey< SiHitCollection > m_sctHitsKey
Definition
AFatrasG4Tool.h:57
AFatrasG4Tool::BeginOfAthenaEvent
virtual StatusCode BeginOfAthenaEvent(HitCollectionMap &) override final
Begin of an athena event - do anything that needs to be done at the beginning of each athena event.
Definition
AFatrasG4Tool.cxx:18
AFatrasG4Tool::m_pixelHitsKey
SG::WriteHandleKey< SiHitCollection > m_pixelHitsKey
Definition
AFatrasG4Tool.h:50
AFatrasG4Tool::makeFastSimModel
virtual G4VFastSimulationModel * makeFastSimModel() override final
Definition
AFatrasG4Tool.cxx:31
AFatrasG4Tool::m_ActsFatrasG4Tool
PublicToolHandle< IActsFatrasG4Tool > m_ActsFatrasG4Tool
Definition
AFatrasG4Tool.h:45
AFatrasG4Tool::EndOfAthenaEvent
virtual StatusCode EndOfAthenaEvent(HitCollectionMap &) override final
End of an athena event - do any tidying up required at the end of each athena event.
Definition
AFatrasG4Tool.cxx:38
AFatrasG4
Definition
AFatrasG4.h:23
FastSimulationBase::BeginOfAthenaEvent
virtual StatusCode BeginOfAthenaEvent(HitCollectionMap &) override
Begin of an athena event - do anything that needs to be done at the beginning of each athena event.
Definition
FastSimulationBase.h:43
FastSimulationBase::initializeFastSim
StatusCode initializeFastSim() override
Construct and setup the fast simulation model.
Definition
FastSimulationBase.cxx:28
FastSimulationBase::EndOfAthenaEvent
virtual StatusCode EndOfAthenaEvent(HitCollectionMap &) override
End of an athena event - do any tidying up required at the end of each athena event.
Definition
FastSimulationBase.h:46
FastSimulationBase::getRegion
G4Region * getRegion() const
Definition
FastSimulationBase.cxx:18
HitCollectionMap
Small wrapper around hit collection map to facilitate accessing the hit collection.
Definition
HitCollectionMap.h:23
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition
AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition
StoreGate/src/VarHandleBase.cxx:400
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SiHit
Definition
SiHit.h:19
Generated on
for ATLAS Offline Software by
1.17.0