ATLAS Offline Software
Loading...
Searching...
No Matches
GepCellTowerAlg.cxx
Go to the documentation of this file.
1/*
2* Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include "./GepCellTowerAlg.h"
6#include "CaloGeoHelpers/CaloSampling.h"
11
12GepCellTowerAlg::GepCellTowerAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
13 AthReentrantAlgorithm( name, pSvcLocator ),
14 m_minEt(0.)
15{
16 declareProperty("minEt", m_minEt);
17}
18
19
21
22
24 ATH_MSG_DEBUG ("Initializing " << name() << "...");
25
26 // Retrieve AlgTools
27 CHECK(m_outputCellTowerKey.initialize());
28 CHECK(m_gepCellsKey.initialize());
29
30 return StatusCode::SUCCESS;
31}
32
34 ATH_MSG_DEBUG ("Finalizing " << name() << "...");
35 return StatusCode::SUCCESS;
36}
37
38StatusCode GepCellTowerAlg::execute(const EventContext& context) const {
39 ATH_MSG_DEBUG ("Executing " << name() << "...");
40 setFilterPassed(false, context); //optional: start with algorithm not passed
41
42 std::vector<Gep::GepCaloCell> cells;
43
44 auto h_gepCellsMap = SG::makeHandle(m_gepCellsKey, context);
45 CHECK(h_gepCellsMap.isValid());
46 const auto & gepCellsMap = *h_gepCellsMap;
47
48 auto cell_map = gepCellsMap.getCellMap();
49
50 // Loop over all cells
51 for (auto const& cell_itr : *cell_map) {
52 cells.push_back(cell_itr.second);
53 }
54
55 // container for CaloCluster wrappers for Gep Clusters
58 CHECK(h_outputCaloClusters.record(std::make_unique<xAOD::CaloClusterContainer>(),
59 std::make_unique<xAOD::CaloClusterAuxContainer>()));
60
61 // Use the indexing and cell energy accumulation functionality
62 // already implemented in xAOD::CaloTower and xAOD::CaloTowerContainer
63 std::vector<std::vector<unsigned int>> cell_ids;
64 auto customTowers = std::make_unique<xAOD::CaloTowerContainer>();
65 auto aux = std::make_unique<xAOD::CaloTowerAuxContainer>();
66 customTowers->setStore(aux.get());
67
68 // Define tower array (98 eta bins x 64 phi bins)
69 static constexpr int nEta{98};
70 static constexpr int nPhi{64};
71 customTowers->configureGrid(nEta,-4.9,4.9,nPhi);
72
73 int nTowers = customTowers->nTowers();
74 cell_ids.resize(nTowers);
75
76 std::vector<std::vector<float>> layerEnergies;
77 layerEnergies.resize(nTowers);
78 for (int iTower=0; iTower < nTowers; ++iTower) layerEnergies[iTower].resize((int)CaloSampling::Unknown);
79
80 for (int iTower=0; iTower < nTowers; ++iTower) {
81 auto tower = std::make_unique<xAOD::CaloTower>();
82 customTowers->push_back(std::move(tower));
83 customTowers->at(iTower)->reset();
84 }
85
86 // Single loop over cells to accumulate energy into the correct tower
87 for (const auto& cell : cells) {
88 if (cell.isBadCell()) continue;
89
90 int idx = customTowers->index(cell.eta,cell.phi);
91 if (idx < 0) continue;
92 // Internally, this results in the cell et being added to the energy (i.e. e, not et) of a
93 // 4-vector with the eta and phi set to the center point of the tower
94 // Effectively accumulating the et of the tower's constituent cells
95 customTowers->at(idx)->addEnergy(cell.et);
96 layerEnergies[idx][cell.sampling] += cell.et;
97 cell_ids[idx].push_back(cell.id);
98 }
99
100 // Store the Gep clusters to a CaloClusters, and write out.
101 for(auto tower: *customTowers){
102 auto p4 = tower->p4();
103 // This is equivalent to checking the et of the tower
104 // since e() is the sum of the et of all constituent cells
105 if ( p4.E() <= m_minEt ) continue;
106
107 // store the calCluster to fix up the Aux container:
108 auto *ptr = h_outputCaloClusters->push_back(std::make_unique<xAOD::CaloCluster>());
109
110 // Unlike what was done here, downstream code will assume that e
111 // is the energy and et is the transverse energy,
112 // so we need to "flip" e and et and make a proper 4-vector here
113 // reminder - p4.e() was until now the et of the tower
114 double eta = p4.Eta();
115 double phi = p4.Phi();
116 double e = p4.E() * std::cosh(eta);
117
118 // ptr is a massless pseudo-particle with energy e
119 // representing a tower. The eta,phi coordinates are
120 // the center of the tower.
121 // When downstream code reads its et, it will
122 // get the measured energy in the tower.
123 ptr->setE(e);
124 ptr->setEta(eta);
125 ptr->setPhi(phi);
126 ptr->setTime(0);
127
128 ptr->setRawE(e);
129 ptr->setRawEta(eta);
130 ptr->setRawPhi(phi);
131 ptr->setRawM(0.0);
132
133 // add all the layer energies to the cluster
134 // these are stored alongside a sampling pattern
135 // the tower eta are used to convert the transverse
136 // energies into E per layer.
137 //Set Sampling pattern:
138 uint32_t samplingPattern=0;
139 for(int i=0;i<(int)CaloSampling::Unknown;i++) {
140 if (layerEnergies[tower->index()].at(i)!=0) samplingPattern |= (0x1U<<i);
141 }
142 //Clear sampling data (if there is any)
143 ptr->clearSamplingData();
144 ptr->setSamplingPattern(samplingPattern);
145
146 //fill the actual sampling energies
147 for(int i=0;i<(int)CaloSampling::Unknown;i++) {
148 CaloSampling::CaloSample sampling_i = static_cast<CaloSampling::CaloSample>(i);
149 if (layerEnergies[tower->index()].at(i)!=0) ptr->setEnergy(sampling_i, layerEnergies[tower->index()].at(i) * std::cosh(eta));
150 }
151
152 auto cccl = std::make_unique<CaloClusterCellLink>();
153
154 for (auto cell_id : cell_ids[tower->index()])
155 cccl->addCell(cell_map->at(cell_id).index, 1.0);
156
157 ptr->addCellLink(std::move(cccl));
158 }
159
160 setFilterPassed(true,context); //if got here, assume that means algorithm passed
161 return StatusCode::SUCCESS;
162}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
#define CHECK(...)
Evaluate an expression and check for errors.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual void setFilterPassed(bool state, const EventContext &ctx) const
An algorithm that can be simultaneously executed in multiple threads.
GepCellTowerAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &) const
virtual StatusCode finalize()
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputCellTowerKey
SG::ReadHandleKey< Gep::GepCellMap > m_gepCellsKey
virtual StatusCode initialize()
virtual ~GepCellTowerAlg()
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())