ATLAS Offline Software
Loading...
Searching...
No Matches
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
10{
12 ATH_CHECK(m_ActsFatrasG4Tool.retrieve());
13 ATH_CHECK(m_pixelHitsKey.initialize());
14 ATH_CHECK(m_sctHitsKey.initialize());
15 return StatusCode::SUCCESS;
16}
17
19{
20 ATH_MSG_DEBUG("AFatrasG4Tool:BeginOfAthenaEvent");
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
31G4VFastSimulationModel* 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
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
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
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
134}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
bool hit(const Container &ids, int pdgId)
virtual StatusCode initializeFastSim() override final
Method to make the actual fast simulation model itself, which will be owned by the tool.
SG::WriteHandleKey< SiHitCollection > m_sctHitsKey
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.
SG::WriteHandleKey< SiHitCollection > m_pixelHitsKey
virtual G4VFastSimulationModel * makeFastSimModel() override final
PublicToolHandle< IActsFatrasG4Tool > m_ActsFatrasG4Tool
virtual StatusCode EndOfAthenaEvent(HitCollectionMap &) override final
End of an athena event - do any tidying up required at the end of each athena event.
virtual StatusCode BeginOfAthenaEvent(HitCollectionMap &) override
Begin of an athena event - do anything that needs to be done at the beginning of each athena event.
StatusCode initializeFastSim() override
Construct and setup the fast simulation model.
virtual StatusCode EndOfAthenaEvent(HitCollectionMap &) override
End of an athena event - do any tidying up required at the end of each athena event.
G4Region * getRegion() const
Small wrapper around hit collection map to facilitate accessing the hit collection.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
bool isPresent() const
Is the referenced object present in SG?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Definition SiHit.h:19