ATLAS Offline Software
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"
8 
9 namespace GlobalSim {
10 
11  // Main constructor
12  GlobalCellTowerAlgTool::GlobalCellTowerAlgTool(const std::string& type, const std::string& name, const IInterface* parent) :
13  base_class(type, name, parent) {
14  }
15 
16 
17  // Initialize function running before first event
19 
22 
23  return StatusCode::SUCCESS;
24  }
25 
26 
27  // Main functional block running for each event
28  StatusCode GlobalCellTowerAlgTool::run(const EventContext& ctx) const {
29 
30  ATH_MSG_DEBUG("Building cell towers");
31 
32  // Read in GlobalLArCellContainer
33  auto h_gblLArCells = SG::makeHandle(m_gblLArCellContainerKey, ctx);
34  CHECK(h_gblLArCells.isValid());
35  const auto & gblLArCells = *h_gblLArCells;
36 
37  // Define tower array (98 eta bins x 64 phi bins)
38  static constexpr int nEta{98};
39  static constexpr int nPhi{64};
40 
41  std::array<std::array<float, nPhi>, nEta> towerEnergies{};
42 
43  for (const auto& cell : gblLArCells) {
44 
45  // Compute eta and phi indices (binning in steps of 0.1)
46  int eta_index = static_cast<int>(std::floor(cell->eta() * 10)) + 49;
47  int phi_index = static_cast<int>(std::floor(cell->phi() * 10)) + 32;
48 
49  // Ensure indices are within bounds
50  if (eta_index < 0 || eta_index >= nEta || phi_index < 0 || phi_index >= nPhi) continue;
51 
52  // Add cell energy to the corresponding tower
53  towerEnergies[eta_index][phi_index] += cell->getEnergy();
54  }
55 
56  auto h_towerTOBs = SG::makeHandle(m_gblCellTowers, ctx);
57  auto towers = std::make_unique<GenericTobContainer>();
58  towers->reserve(nEta * nPhi);
59 
60  for (int etaBin = 0; etaBin < nEta; ++etaBin) {
61  for (int phiBin = 0; phiBin < nPhi; ++phiBin) {
62 
63  if (towerEnergies[etaBin][phiBin] == 0) continue;
64  int energyBits = std::clamp(static_cast<int>(towerEnergies[etaBin][phiBin]), 0, (1 << 13) - 1);
65 
66  std::string bit_string = makeTowerBits(energyBits, etaBin, phiBin);
67 
68  towers->emplace_back(std::make_shared<GenericTob>(bit_string));
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 
80  // Function which assembles the TOB bitstream for a tower
85  std::string(3, '0');
86  }
87 
88 
89  // Overrides toString() function from base class, unused here
90  std::string GlobalCellTowerAlgTool::toString() const {
91  return {};
92  }
93 
94 } //namespace GlobalSim
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
GlobalSim::GlobalCellTowerAlgTool::m_gblLArCellContainerKey
SG::ReadHandleKey< GlobalSim::GlobalLArCellContainer > m_gblLArCellContainerKey
Key to the GlobalLArCellContainer.
Definition: GlobalCellTowerAlgTool.h:61
GlobalSim::GlobalCellTowerAlgTool::toBinary
static std::string toBinary(int value, int width)
Helper function to convert floating point values into a bitstream.
Definition: GlobalCellTowerAlgTool.h:47
GlobalLArCellContainer.h
TrigVSI::AlgConsts::nPhi
constexpr int nPhi
Default bin number of phi for vertex map.
Definition: Trigger/TrigTools/TrigVrtSecInclusive/TrigVrtSecInclusive/Constants.h:27
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
GlobalCellTowerAlgTool.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
GlobalSim
AlgTool to obtain a selection of eFex RoIs read in from the event store.
Definition: dump.h:8
xAOD::etaBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin
Definition: L2StandAloneMuon_v1.cxx:149
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
GlobalLArCell.h
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
createCablingJSON.eta_index
int eta_index
Definition: createCablingJSON.py:14
GlobalSim::GlobalCellTowerAlgTool::m_gblCellTowers
SG::WriteHandleKey< GenericTobContainer > m_gblCellTowers
Write key for the output cell towers as a GenericTobContainer.
Definition: GlobalCellTowerAlgTool.h:64
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
xAOD::phiBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setPhiMap phiBin
Definition: L2StandAloneMuon_v2.cxx:145
GlobalSim::GlobalCellTowerAlgTool::run
virtual StatusCode run(const EventContext &ctx) const override
Main functional block running for each event.
Definition: GlobalCellTowerAlgTool.cxx:28
GlobalSim::GlobalCellTowerAlgTool::initialize
virtual StatusCode initialize() override
Initialize function running before first event.
Definition: GlobalCellTowerAlgTool.cxx:18
GlobalSim::GlobalCellTowerAlgTool::makeTowerBits
static std::string makeTowerBits(int energy, int etaBin, int phiBin)
Function which assembles the TOB bitstream for a tower.
Definition: GlobalCellTowerAlgTool.cxx:81
RunTileMonitoring.towers
towers
Definition: RunTileMonitoring.py:133
GlobalSim::GlobalCellTowerAlgTool::toString
virtual std::string toString() const override
Overriding toString function from base class.
Definition: GlobalCellTowerAlgTool.cxx:90
TrigVSI::AlgConsts::nEta
constexpr int nEta
Default bin number of eta for vertex map.
Definition: Trigger/TrigTools/TrigVrtSecInclusive/TrigVrtSecInclusive/Constants.h:26
GlobalSim::GlobalCellTowerAlgTool::GlobalCellTowerAlgTool
GlobalCellTowerAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Main constructor.
Definition: GlobalCellTowerAlgTool.cxx:12