ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTowerxAODFromCells.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
9
10
14
15#include <limits>
16
17CaloTowerxAODFromCells::CaloTowerxAODFromCells(const std::string& name,ISvcLocator* pSvcLocator)
18 : CaloTowerxAODAlgoBase(name,pSvcLocator)
19{
20}
21
23= default;
24
26
27 m_filterCells=(m_cellThresholdE!=std::numeric_limits<float>::min());
29
30 // process modes
31 if ( m_filterCells ) {
32 ATH_MSG_INFO("[Configuration::Status] FilterCell mode configured with Ecell > " << m_cellThresholdE << " MeV");
33 } else {
34 ATH_MSG_INFO("[Configuration::Status] Using all cells");
35 }
36
37 return initBase();
38}
39
40StatusCode CaloTowerxAODFromCells::execute(const EventContext& ctx) const
41{
42 const CellToTowerVec& cellToTower = getIndexCache(ctx);
43 if(cellToTower.empty()) {
44 ATH_MSG_ERROR( "Failed to compute the index cache");
45 return StatusCode::FAILURE;
46 }
47
49 if (!inputCellContainer.isValid()) {
50 ATH_MSG_ERROR( "Can't retrieve CaloCellContainer with key " << inputCellContainer.name() );
51 return StatusCode::FAILURE;
52 }
53
55 this->makeContainer(ctx);
56 if (!caloTowerContainer.isValid())
57 return StatusCode::FAILURE;
58
59 const size_t nCell2Tower=cellToTower.size();
60 if (nCell2Tower<inputCellContainer->size()) {
61 ATH_MSG_ERROR( "Number of cells larger than size of internal cell2tower cache. nCells="
62 << inputCellContainer->size() << ", cell2tower size=" << nCell2Tower );
63 return StatusCode::FAILURE;
64 }
65
66 for (const CaloCell* cell : *inputCellContainer) {
67
68 if (!m_filterCells || (cell->e()> m_cellThresholdE)) {
69
70 const IdentifierHash cellHash=cell->caloDDE()->calo_hash();
71 assert(cellHash<cellToTower.size());
72 if (!(cellHash<cellToTower.size())) {
73 ATH_MSG_ERROR( "Cell2Tower mapping too small " << cellToTower.size() << ", expected at least" << cellHash );
74 return StatusCode::FAILURE;
75 }
76 const auto& c2ts=cellToTower[cellHash];
77 //Remember: A cell can contribute to more than one tower!
78 for (const cellToTower_t& c2t : c2ts) {
79 if (c2t.m_towerIdx > caloTowerContainer->size()) {
80 ATH_MSG_ERROR( "Tower container size too small " << caloTowerContainer->size() << ", expected at least" << c2t.m_towerIdx );
81 return StatusCode::FAILURE;
82 }
83 (*caloTowerContainer)[c2t.m_towerIdx]->addEnergy(cell->e()*c2t.m_weight);
84 }//end loop over towers coverd by this cell
85 }// end if filter cells
86 }//end loop over cells
87
88
89 return StatusCode::SUCCESS;
90}
91
93{ return StatusCode::SUCCESS; }
94
95
96
97
98
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
CaloPhiRange class declaration.
size_t size() const
Number of registered mappings.
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 StatusCode execute(const EventContext &ctx) const override
Execute algorithm.
virtual StatusCode initialize() override
Initialize algorithm.
Gaudi::Property< double > m_cellThresholdE
Cell energy threshold (only for FilteredCell mode).
CaloTowerxAODFromCells(const std::string &name, ISvcLocator *pSvcLocator)
Default algorithm constructor.
SG::ReadHandleKey< CaloCellContainer > m_inputCellContainerKey
virtual StatusCode finalize() override
Finalize algorithm.
virtual ~CaloTowerxAODFromCells()
Baseclass destructor.
This is a "hash" representation of an Identifier.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const std::string & name() const
Return the StoreGate ID for the referenced object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?