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
44 const EventContext& ctx{Gaudi::Hive::currentContext()};
45
46 // -----------------------------
47 // Cells
48 // -----------------------------
49 const CaloCellContainer* cells{};
50 ATH_CHECK(SG::get(cells, m_cellKey, ctx));
51
52 int nStored = 0;
53 for (const CaloCell* cell : *cells) {
54 if (!cell) continue;
55
56 // energy() is in MeV for CaloCell
57 const float eMeV = cell->energy();
58 if (eMeV < m_minE) continue;
59
60 const CaloDetDescrElement* dde = cell->caloDDE();
61 if (!dde) continue;
62
63 // Store Identifier
64 const Identifier& id = cell->ID();
65 m_cell_id.push_back(id);
66
67 // Store position (x,y,z) in mm, eta/phi from DDE
68 const Amg::Vector3D pos(dde->x(), dde->y(), dde->z());
69 m_cell_pos.push_back(pos);
70 m_cell_energy.push_back(eMeV);
71 m_cell_eta.push_back(dde->eta());
72 m_cell_phi.push_back(dde->phi());
73
74 // Sampling / subCalo
75 // - dde->getSampling() gives CaloSampling::CaloSample enum (int)
76 // - CaloCell_ID can decode subCalo for the Identifier
77 m_cell_sampling.push_back(static_cast<int>(dde->getSampling()));
78 m_cell_subCalo.push_back(static_cast<int>(m_caloId->sub_calo(id)));
79 m_cell_isTile.push_back(static_cast<unsigned short>(dde->is_tile()));
80
81 ++nStored;
82 if (m_maxCells.value() > 0 && nStored >= m_maxCells.value()) break;
83 }
84
85 // -----------------------------
86 // Towers
87 // -----------------------------
88 const CaloTowerContainer* towers{};
89 ATH_CHECK(SG::get(towers, m_towerKey, ctx));
90 int nTowStored = 0;
91 for (const CaloTower* tow : *towers) {
92 if (!tow) continue;
93
94 // CaloTower energy is in MeV (same convention as cells)
95 const float eMeV = tow->energy();
96 if (eMeV < m_minTowerE) continue;
97
98 const float eta = tow->eta();
99 const float phi = tow->phi();
100 const float etMeV = eMeV / std::cosh(eta);
101
102 m_tower_energy.push_back(eMeV);
103 m_tower_et.push_back(etMeV);
104 m_tower_eta.push_back(eta);
105 m_tower_phi.push_back(phi);
106
107 // Derived direction vector (unit length) from eta/phi
108 const double theta = 2.0 * std::atan(std::exp(-static_cast<double>(eta)));
109 const double st = std::sin(theta);
110 const double ct = std::cos(theta);
111 const double cp = std::cos(static_cast<double>(phi));
112 const double sp = std::sin(static_cast<double>(phi));
113 const Amg::Vector3D dir(st * cp, st * sp, ct);
114 m_tower_dir.push_back(dir);
115
116 // Try to provide tower "size" (how many cells contribute)
117 m_tower_nCells.push_back(static_cast<unsigned int>(tow->size()));
118
119 ++nTowStored;
120 if (m_maxTowers.value() > 0 && nTowStored >= m_maxTowers.value()) break;
121 }
122
123 if (!m_tree.fill(ctx)) return StatusCode::FAILURE;
124 return StatusCode::SUCCESS;
125}
126
127} // 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
MuonVal::VectorBranch< float > & m_cell_phi
MuonVal::VectorBranch< float > & m_tower_energy
MuonVal::VectorBranch< int > & m_cell_subCalo
StatusCode execute() override final
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.