ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellsDumperAlg.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 "CaloDetDescr/CaloDetDescrElement.h"
10#include "CaloEvent/CaloTower.h"
12#include <cmath>
13
14namespace MuonR4 {
15
17 ATH_CHECK(m_cellKey.initialize());
19
20 // CaloCell_ID helper (to provide subCalo/sampling via Identifier decoding if desired)
21 ATH_CHECK(detStore()->retrieve(m_caloId, "CaloCell_ID"));
22
23 // Event hash branch
24 m_evtHash = std::make_shared<MuonVal::EventHashBranch>(m_tree.tree());
25 m_tree.addBranch(m_evtHash);
26
27 ATH_CHECK(m_tree.init(this));
28 ATH_MSG_INFO("Initialized Calo dump with:"
29 << " CellContainerKey=" << m_cellKey.key()
30 << " MinCellEnergyMeV=" << m_minE
31 << " MaxCells=" << m_maxCells
32 << " | TowerContainerKey=" << m_towerKey.key()
33 << " MinTowerEnergyMeV=" << m_minTowerE
34 << " MaxTowers=" << m_maxTowers);
35 return StatusCode::SUCCESS;
36}
37
39 ATH_CHECK(m_tree.write());
40 return StatusCode::SUCCESS;
41}
42
43StatusCode CaloCellsDumperAlg::execute(const EventContext& ctx) {
44
45 // -----------------------------
46 // Cells
47 // -----------------------------
48 const CaloCellContainer* cells{};
49 ATH_CHECK(SG::get(cells, m_cellKey, ctx));
50
51 int nStored = 0;
52 for (const CaloCell* cell : *cells) {
53 if (!cell) continue;
54
55 // energy() is in MeV for CaloCell
56 const float eMeV = cell->energy();
57 if (eMeV < m_minE) continue;
58
59 const CaloDetDescrElement* dde = cell->caloDDE();
60 if (!dde) continue;
61
62 // Store Identifier
63 const Identifier& id = cell->ID();
64 m_cell_id.push_back(id);
65
66 // Store position (x,y,z) in mm, eta/phi from DDE
67 const Amg::Vector3D pos(dde->x(), dde->y(), dde->z());
68 m_cell_pos.push_back(pos);
69 m_cell_energy.push_back(eMeV);
70 m_cell_eta.push_back(dde->eta());
71 m_cell_phi.push_back(dde->phi());
72
73 // Sampling / subCalo
74 // - dde->getSampling() gives CaloSampling::CaloSample enum (int)
75 // - CaloCell_ID can decode subCalo for the Identifier
76 m_cell_sampling.push_back(static_cast<int>(dde->getSampling()));
77 m_cell_subCalo.push_back(static_cast<int>(m_caloId->sub_calo(id)));
78 m_cell_isTile.push_back(static_cast<unsigned short>(dde->is_tile()));
79
80 ++nStored;
81 if (m_maxCells.value() > 0 && nStored >= m_maxCells.value()) break;
82 }
83
84 // -----------------------------
85 // Towers
86 // -----------------------------
87 const CaloTowerContainer* towers{};
88 ATH_CHECK(SG::get(towers, m_towerKey, ctx));
89 int nTowStored = 0;
90 for (const CaloTower* tow : *towers) {
91 if (!tow) continue;
92
93 // CaloTower energy is in MeV (same convention as cells)
94 const float eMeV = tow->energy();
95 if (eMeV < m_minTowerE) continue;
96
97 const float eta = tow->eta();
98 const float phi = tow->phi();
99 const float etMeV = eMeV / std::cosh(eta);
100
101 m_tower_energy.push_back(eMeV);
102 m_tower_et.push_back(etMeV);
103 m_tower_eta.push_back(eta);
104 m_tower_phi.push_back(phi);
105
106 // Derived direction vector (unit length) from eta/phi
107 const double theta = 2.0 * std::atan(std::exp(-static_cast<double>(eta)));
108 const double st = std::sin(theta);
109 const double ct = std::cos(theta);
110 const double cp = std::cos(static_cast<double>(phi));
111 const double sp = std::sin(static_cast<double>(phi));
112 const Amg::Vector3D dir(st * cp, st * sp, ct);
113 m_tower_dir.push_back(dir);
114
115 // Try to provide tower "size" (how many cells contribute)
116 m_tower_nCells.push_back(static_cast<unsigned int>(tow->size()));
117
118 ++nTowStored;
119 if (m_maxTowers.value() > 0 && nTowStored >= m_maxTowers.value()) break;
120 }
121
122 if (!m_tree.fill(ctx)) return StatusCode::FAILURE;
123 return StatusCode::SUCCESS;
124}
125
126} // namespace MuonR4
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
Helpers for checking error return status codes and reporting errors.
static Double_t sp
Handle class for reading from StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
Container class for CaloCell.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
This class groups all DetDescr information related to a CaloCell.
CaloCell_ID::CaloSample getSampling() const
cell sampling
Storable container class for CaloTower.
Data class for calorimeter cell towers.
MuonVal::VectorBranch< unsigned short > & m_cell_isTile
SG::ReadHandleKey< CaloTowerContainer > m_towerKey
SG::ReadHandleKey< CaloCellContainer > m_cellKey
MuonVal::VectorBranch< float > & m_cell_eta
std::shared_ptr< MuonVal::EventHashBranch > m_evtHash
StatusCode finalize() override final
MuonVal::ThreeVectorBranch m_tower_dir
Gaudi::Property< float > m_minE
StatusCode execute(const EventContext &ctx) override final
Execute method.
MuonVal::VectorBranch< float > & m_cell_phi
MuonVal::VectorBranch< float > & m_tower_energy
MuonVal::VectorBranch< int > & m_cell_subCalo
MuonVal::ThreeVectorBranch m_cell_pos
MuonVal::VectorBranch< float > & m_tower_et
Gaudi::Property< int > m_maxCells
Gaudi::Property< float > m_minTowerE
MuonVal::VectorBranch< int > & m_cell_sampling
MuonVal::VectorBranch< float > & m_cell_energy
MuonVal::VectorBranch< float > & m_tower_phi
MuonVal::VectorBranch< unsigned int > & m_tower_nCells
Gaudi::Property< int > m_maxTowers
StatusCode initialize() override final
MuonVal::MuonTesterTree m_tree
MuonVal::VectorBranch< float > & m_tower_eta
MuonVal::MuonIdentifierBranch m_cell_id
Eigen::Matrix< double, 3, 1 > Vector3D
This header ties the generic definitions in this package.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.