ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTowerxAODFromClusters.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
8
11#include <memory>
12
13#ifndef CALOTOWER_MAX_CELL_COUNT
14#define CALOTOWER_MAX_CELL_COUNT 200000
15#endif
16
17
18CaloTowerxAODFromClusters::CaloTowerxAODFromClusters(const std::string& name,ISvcLocator* pSvcLocator)
19 : CaloTowerxAODAlgoBase(name,pSvcLocator)
20 , m_inputClusterContainerKey("CaloCalTopoClusters")
21{
22 declareProperty("InputClusterContainer", m_inputClusterContainerKey );
23}
24
26= default;
27
31 return StatusCode::SUCCESS;
32}
33
34StatusCode CaloTowerxAODFromClusters::execute(const EventContext& ctx) const
35{
36 const CellToTowerVec& cellToTower = getIndexCache(ctx);
37 if(cellToTower.empty()) {
38 ATH_MSG_ERROR( "Failed to compute the index cache");
39 return StatusCode::FAILURE;
40 }
41
43
45 this->makeContainer(ctx);
46 if (!caloTowerContainer.isValid())
47 return StatusCode::FAILURE;
48
49 auto addedCellsMap = std::make_unique<std::bitset< CALOTOWER_MAX_CELL_COUNT> >();
50
51 for (const xAOD::CaloCluster* it_cluster : *inputClusterContainer) {
52 const CaloClusterCellLink* cellLinks=it_cluster->getCellLinks();
53 if (!cellLinks) {
54 ATH_MSG_ERROR("Cluster without cell links found in collection: " << inputClusterContainer.name());
55 return StatusCode::FAILURE;
56 }
57
58 for (const CaloCell* cell : *cellLinks) {
59 //Ask cell for it's hash
60 const IdentifierHash cellHash = cell->caloDDE()->calo_hash();
61 //Check it this cell is already part of reducedCellContainer
62 if (!addedCellsMap->test(cellHash)) {
63 addedCellsMap->set(cellHash);
64 assert(cellHash<cellToTower.size());
65 const auto& c2ts=cellToTower[cellHash];
66 //Remember: A cell can contribute to more than one tower!
67 for (const cellToTower_t& c2t : c2ts) {
68 (*caloTowerContainer)[c2t.m_towerIdx]->addEnergy(cell->e()*c2t.m_weight);
69 }//end loop over towers coverd by this cell
70 }//end cell has not been added yet
71 }//end loop over cells in this cluster
72 }//end loop over clusters
73 return StatusCode::SUCCESS;
74}
75
77{ return StatusCode::SUCCESS; }
78
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
std::vector< std::vector< cellToTower_t > > CellToTowerVec
const CellToTowerVec & getIndexCache(const EventContext &ctx) const
SG::WriteHandle< xAOD::CaloTowerContainer > makeContainer(const EventContext &ctx) const
Intialize m_cellToTower cache.
CaloTowerxAODAlgoBase(const std::string &name, ISvcLocator *pSvcLocator)
Default algorithm constructor.
virtual ~CaloTowerxAODFromClusters()
Baseclass destructor.
virtual StatusCode initialize() override
Initialize algorithm.
virtual StatusCode execute(const EventContext &) const override
Execute algorithm.
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_inputClusterContainerKey
CaloTowerxAODFromClusters(const std::string &name, ISvcLocator *pSvcLocator)
Default algorithm constructor.
virtual StatusCode finalize() override
Finalize algorithm.
This is a "hash" representation of an Identifier.
const std::string & name() const
Return the StoreGate ID for the referenced object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.