ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalCellTowerAlgTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8#include "../IO/CommonTOB.h"
9
10#include <bitset>
11
12
13namespace GlobalSim {
14
15 // Main constructor
16 GlobalCellTowerAlgTool::GlobalCellTowerAlgTool(const std::string& type, const std::string& name, const IInterface* parent) :
17 base_class(type, name, parent) {
18 }
19
20
21 // Initialize function running before first event
23
24 CHECK(m_gblLArCellContainerKey.initialize());
25 CHECK(m_gblCellTowers.initialize());
26
27 return StatusCode::SUCCESS;
28 }
29
30
31 // Main functional block running for each event
32 StatusCode
33 GlobalCellTowerAlgTool::run(const std::unique_ptr<IDataCollector>& dc,
34 const EventContext& ctx) const {
35
36 ATH_MSG_DEBUG("Building cell towers");
37 if (dc){dc->collect(*this, "start");}
38
39 // Read in GlobalLArCellContainer
40 auto h_gblLArCells = SG::makeHandle(m_gblLArCellContainerKey, ctx);
41 CHECK(h_gblLArCells.isValid());
42 const auto & gblLArCells = *h_gblLArCells;
43
44 // Define tower array (98 eta bins x 64 phi bins)
45 static constexpr int nEta{98};
46 static constexpr int nPhi{64};
47
48 auto pTowerEnergies = std::make_unique<std::array<std::array<float, nPhi>, nEta>>();
49 auto & towerEnergies = *pTowerEnergies;
50 for (const GlobalSim::GlobalLArCell* cell : gblLArCells) {
51
52 // Compute eta and phi indices (binning in steps of 0.1)
53 int eta_index = static_cast<int>(std::floor(cell->eta() * 10)) + 49;
54 int phi_index = static_cast<int>(std::floor(cell->phi() * 10)) + 32;
55
56 // Ensure indices are within bounds
57 if (eta_index < 0 || eta_index >= nEta || phi_index < 0 || phi_index >= nPhi) continue;
58
59 // Add cell energy to the corresponding tower
60 towerEnergies[eta_index][phi_index] += cell->getEnergy();
61 }
62
63 auto h_towerTOBs = SG::makeHandle(m_gblCellTowers, ctx);
64 auto towers = std::make_unique<IOBitwise::CommonTOBContainer>();
65 towers->reserve(nEta * nPhi);
66
67 for (int etaBin = 0; etaBin < nEta; ++etaBin) {
68 for (int phiBin = 0; phiBin < nPhi; ++phiBin) {
69
70 if (towerEnergies[etaBin][phiBin] == 0) continue;
71 int energyBits = std::clamp(static_cast<int>(towerEnergies[etaBin][phiBin]), 0, (1 << IOBitwise::CommonTOB::s_et_width) - 1);
72
73
74 towers->emplace_back(new IOBitwise::CommonTOB(std::bitset<IOBitwise::CommonTOB::s_et_width>(energyBits),
75 std::bitset<IOBitwise::CommonTOB::s_eta_width>(etaBin),
76 std::bitset<IOBitwise::CommonTOB::s_phi_width>(phiBin)));
77 }
78 }
79
80 ATH_MSG_DEBUG("Built " << towers->size() << " cell towers and stored them as GenericTobs");
81
82 CHECK(h_towerTOBs.record(std::move(towers)));
83
84 if (dc){dc->collect(*this, "end");}
85
86 return StatusCode::SUCCESS;
87 }
88
89 // Overrides toString() function from base class, unused here
91 return {};
92 }
93
94} //namespace GlobalSim
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
virtual StatusCode run(const std::unique_ptr< IDataCollector > &, const EventContext &ctx) const override
Main functional block running for each event.
GlobalCellTowerAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Main constructor.
SG::ReadHandleKey< GlobalSim::GlobalLArCellContainer > m_gblLArCellContainerKey
Key to the GlobalLArCellContainer.
virtual StatusCode initialize() override
Initialize function running before first event.
SG::WriteHandleKey< IOBitwise::CommonTOBContainer > m_gblCellTowers
Write key for the output cell towers as a GenericTobContainer.
virtual std::string toString() const override
Overriding toString function from base class.
static constexpr std::size_t s_et_width
Size of the eT bitset.
Definition CommonTOB.h:28
AlgTool to read in LArStripNeighborhoods, and run the BDT Algorithm.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())