ATLAS Offline Software
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 
8 #include "CaloEvent/CaloCell.h"
10 
11 
15 
16 #include <limits>
17 
18 CaloTowerxAODFromCells::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 
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 
46 StatusCode 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 
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloTowerxAODFromCells::CaloTowerxAODFromCells
CaloTowerxAODFromCells(const std::string &name, ISvcLocator *pSvcLocator)
Default algorithm constructor.
Definition: CaloTowerxAODFromCells.cxx:18
CaloTowerxAODAlgoBase::cellToTower_t
Definition: CaloTowerxAODAlgoBase.h:57
CaloTowerxAODAlgoBase::initBase
StatusCode initBase()
<
Definition: CaloTowerxAODAlgoBase.cxx:30
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
CaloTowerxAODAlgoBase::getIndexCache
const CellToTowerVec & getIndexCache(const EventContext &ctx) const
Definition: CaloTowerxAODAlgoBase.cxx:63
CaloCell.h
CaloTowerxAODFromCells::m_inputCellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_inputCellContainerKey
Definition: CaloTowerxAODFromCells.h:44
CaloTowerAuxContainer.h
CaloTowerxAODFromCells::m_cellThresholdE
double m_cellThresholdE
Cell energy threshold (only for FilteredCell mode)
Definition: CaloTowerxAODFromCells.h:45
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloTowerContainer.h
CaloTowerxAODAlgoBase::CellToTowerVec
std::vector< std::vector< cellToTower_t > > CellToTowerVec
Definition: CaloTowerxAODAlgoBase.h:63
CaloTowerxAODFromCells::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execute algorithm.
Definition: CaloTowerxAODFromCells.cxx:46
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloTowerxAODAlgoBase::makeContainer
SG::WriteHandle< xAOD::CaloTowerContainer > makeContainer(const EventContext &ctx) const
Intialize m_cellToTower cache.
Definition: CaloTowerxAODAlgoBase.cxx:38
CaloPhiRange.h
CaloPhiRange class declaration.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloTowerxAODFromCells::initialize
virtual StatusCode initialize() override
Initialize algorithm.
Definition: CaloTowerxAODFromCells.cxx:31
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
WriteCellNoiseToCool.cellHash
cellHash
Definition: WriteCellNoiseToCool.py:433
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
min
#define min(a, b)
Definition: cfImp.cxx:40
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloCellContainer.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
IdentifierHash
Definition: IdentifierHash.h:38
CaloTowerxAODAlgoBase
Definition: CaloTowerxAODAlgoBase.h:24
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
readCCLHist.float
float
Definition: readCCLHist.py:83
CaloTowerxAODFromCells::finalize
virtual StatusCode finalize() override
Finalize algorithm.
Definition: CaloTowerxAODFromCells.cxx:98
CaloTowerxAODFromCells::~CaloTowerxAODFromCells
virtual ~CaloTowerxAODFromCells()
Baseclass destructor.
CaloTowerxAODFromCells::m_filterCells
bool m_filterCells
Definition: CaloTowerxAODFromCells.h:48
CaloTowerxAODFromCells.h