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"
10
11GepCellTowerAlg::GepCellTowerAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
12 AthReentrantAlgorithm( name, pSvcLocator ){
13}
14
15
17
18
20 ATH_MSG_DEBUG ("Initializing " << name() << "...");
21
22 // Retrieve AlgTools
23 CHECK(m_outputCellTowerKey.initialize());
24 CHECK(m_gepCellsKey.initialize());
25
26 return StatusCode::SUCCESS;
27}
28
30 ATH_MSG_DEBUG ("Finalizing " << name() << "...");
31 return StatusCode::SUCCESS;
32}
33
34StatusCode GepCellTowerAlg::execute(const EventContext& context) const {
35 ATH_MSG_DEBUG ("Executing " << name() << "...");
36 setFilterPassed(false, context); //optional: start with algorithm not passed
37
38 std::vector<Gep::GepCaloCell> cells;
39
40 auto h_gepCellsMap = SG::makeHandle(m_gepCellsKey, context);
41 CHECK(h_gepCellsMap.isValid());
42 const auto & gepCellsMap = *h_gepCellsMap;
43
44 auto cell_map = gepCellsMap.getCellMap();
45
46 // Loop over all cells
47 for (auto const& cell_itr : *cell_map) {
48 cells.push_back(cell_itr.second);
49 }
50
51 // container for CaloCluster wrappers for Gep Clusters
54 CHECK(h_outputCaloClusters.record(std::make_unique<xAOD::CaloClusterContainer>(),
55 std::make_unique<xAOD::CaloClusterAuxContainer>()));
56
57 // Use the indexing and cell energy accumulation functionality
58 // already implemented in xAOD::CaloTower and xAOD::CaloTowerContainer
59 std::vector<std::vector<unsigned int>> cell_ids;
60 auto customTowers = std::make_unique<xAOD::CaloTowerContainer>();
61 auto aux = std::make_unique<xAOD::CaloTowerAuxContainer>();
62 customTowers->setStore(aux.get());
63
64 // Define tower array (98 eta bins x 64 phi bins)
65 static constexpr int nEta{98};
66 static constexpr int nPhi{64};
67 customTowers->configureGrid(nEta,-4.9,4.9,nPhi);
68
69 int nTowers = customTowers->nTowers();
70 cell_ids.resize(nTowers);
71
72 for (int iTower=0; iTower < nTowers; ++iTower) {
73 auto tower = std::make_unique<xAOD::CaloTower>();
74 customTowers->push_back(std::move(tower));
75 customTowers->at(iTower)->reset();
76 }
77
78 // Single loop over cells to accumulate energy into the correct tower
79 for (const auto& cell : cells) {
80 if (cell.sigma < 2) continue;
81 if (cell.isBadCell()) continue;
82
83 int idx = customTowers->index(cell.eta,cell.phi);
84 if (idx < 0) continue;
85 // Internally, this results in the cell et being added to the energy (i.e. e, not et) of a
86 // 4-vector with the eta and phi set to the center point of the tower
87 // Effectively accumulating the et of the tower's constituent cells
88 customTowers->at(idx)->addEnergy(cell.et);
89 cell_ids[idx].push_back(cell.id);
90 }
91
92 // Store the Gep clusters to a CaloClusters, and write out.
93 for(auto tower: *customTowers){
94 auto p4 = tower->p4();
95 // This is equivalent to checking the et of the tower
96 // since e() is the sum of the et of all constituent cells
97 if ( p4.E() == 0 ) continue;
98
99 // store the calCluster to fix up the Aux container:
100 auto *ptr = h_outputCaloClusters->push_back(std::make_unique<xAOD::CaloCluster>());
101
102 // Unlike what was done here, downstream code will assume that e
103 // is the energy and et is the transverse energy,
104 // so we need to "flip" e and et and make a proper 4-vector here
105 // reminder - p4.e() was until now the et of the tower
106 double eta = p4.Eta();
107 double phi = p4.Phi();
108 double e = p4.E() * std::cosh(eta);
109
110 // ptr is a massless pseudo-particle with energy e
111 // representing a tower. The eta,phi coordinates are
112 // the center of the tower.
113 // When downstream code reads its et, it will
114 // get the measured energy in the tower.
115 ptr->setE(e);
116 ptr->setEta(eta);
117 ptr->setPhi(phi);
118 ptr->setTime(0);
119
120 auto cccl = std::make_unique<CaloClusterCellLink>();
121
122 for (auto cell_id : cell_ids[tower->index()])
123 cccl->addCell(cell_map->at(cell_id).index, 1.0);
124
125 ptr->addCellLink(std::move(cccl));
126 }
127
128 setFilterPassed(true,context); //if got here, assume that means algorithm passed
129 return StatusCode::SUCCESS;
130}
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.
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())