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