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
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 GlobalCellTowerAlgTool::run(const EventContext& ctx) const {
33
34 ATH_MSG_DEBUG("Building cell towers");
35
36 // Read in GlobalLArCellContainer
37 auto h_gblLArCells = SG::makeHandle(m_gblLArCellContainerKey, ctx);
38 CHECK(h_gblLArCells.isValid());
39 const auto & gblLArCells = *h_gblLArCells;
40
41 // Define tower array (98 eta bins x 64 phi bins)
42 static constexpr int nEta{98};
43 static constexpr int nPhi{64};
44
45 auto pTowerEnergies = std::make_unique<std::array<std::array<float, nPhi>, nEta>>();
46 auto & towerEnergies = *pTowerEnergies;
47 for (const GlobalSim::GlobalLArCell* cell : gblLArCells) {
48
49 // Compute eta and phi indices (binning in steps of 0.1)
50 int eta_index = static_cast<int>(std::floor(cell->eta() * 10)) + 49;
51 int phi_index = static_cast<int>(std::floor(cell->phi() * 10)) + 32;
52
53 // Ensure indices are within bounds
54 if (eta_index < 0 || eta_index >= nEta || phi_index < 0 || phi_index >= nPhi) continue;
55
56 // Add cell energy to the corresponding tower
57 towerEnergies[eta_index][phi_index] += cell->getEnergy();
58 }
59
60 auto h_towerTOBs = SG::makeHandle(m_gblCellTowers, ctx);
61 auto towers = std::make_unique<IOBitwise::CommonTOBContainer>();
62 towers->reserve(nEta * nPhi);
63
64 for (int etaBin = 0; etaBin < nEta; ++etaBin) {
65 for (int phiBin = 0; phiBin < nPhi; ++phiBin) {
66
67 if (towerEnergies[etaBin][phiBin] == 0) continue;
68 int energyBits = std::clamp(static_cast<int>(towerEnergies[etaBin][phiBin]), 0, (1 << IOBitwise::CommonTOB::s_et_width) - 1);
69
70
71 towers->emplace_back(new IOBitwise::CommonTOB(std::bitset<IOBitwise::CommonTOB::s_et_width>(energyBits),
72 std::bitset<IOBitwise::CommonTOB::s_eta_width>(etaBin),
73 std::bitset<IOBitwise::CommonTOB::s_phi_width>(phiBin)));
74 }
75 }
76
77 ATH_MSG_DEBUG("Built " << towers->size() << " cell towers and stored them as GenericTobs");
78
79 CHECK(h_towerTOBs.record(std::move(towers)));
80
81 return StatusCode::SUCCESS;
82 }
83
84 // Overrides toString() function from base class, unused here
86 return {};
87 }
88
89} //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.
static constexpr std::size_t s_et_width
Size of the eT bitset.
Definition CommonTOB.h:28
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())