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