ATLAS Offline Software
CaloTowerxAODFromClusters.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 
11 
12 #ifndef CALOTOWER_MAX_CELL_COUNT
13 #define CALOTOWER_MAX_CELL_COUNT 200000
14 #endif
15 
16 
17 CaloTowerxAODFromClusters::CaloTowerxAODFromClusters(const std::string& name,ISvcLocator* pSvcLocator)
18  : CaloTowerxAODAlgoBase(name,pSvcLocator)
19  , m_inputClusterContainerKey("CaloCalTopoClusters")
20 {
21  declareProperty("InputClusterContainer", m_inputClusterContainerKey );
22 }
23 
25 = default;
26 
29  ATH_CHECK( initBase() );
30  return StatusCode::SUCCESS;
31 }
32 
33 StatusCode CaloTowerxAODFromClusters::execute(const EventContext& ctx) const
34 {
35  const CellToTowerVec& cellToTower = getIndexCache(ctx);
36  if(cellToTower.empty()) {
37  ATH_MSG_ERROR( "Failed to compute the index cache");
38  return StatusCode::FAILURE;
39  }
40 
42 
44  this->makeContainer(ctx);
45  if (!caloTowerContainer.isValid())
46  return StatusCode::FAILURE;
47 
48  std::bitset< CALOTOWER_MAX_CELL_COUNT> addedCellsMap;
49 
50  for (const xAOD::CaloCluster* it_cluster : *inputClusterContainer) {
51  const CaloClusterCellLink* cellLinks=it_cluster->getCellLinks();
52  if (!cellLinks) {
53  ATH_MSG_ERROR("Cluster without cell links found in collection: " << inputClusterContainer.name());
54  return StatusCode::FAILURE;
55  }
56 
57  for (const CaloCell* cell : *cellLinks) {
58  //Ask cell for it's hash
59  const IdentifierHash cellHash = cell->caloDDE()->calo_hash();
60  //Check it this cell is already part of reducedCellContainer
61  if (!addedCellsMap.test(cellHash)) {
62  addedCellsMap.set(cellHash);
63  assert(cellHash<cellToTower.size());
64  const auto& c2ts=cellToTower[cellHash];
65  //Remember: A cell can contribute to more than one tower!
66  for (const cellToTower_t& c2t : c2ts) {
67  (*caloTowerContainer)[c2t.m_towerIdx]->addEnergy(cell->e()*c2t.m_weight);
68  }//end loop over towers coverd by this cell
69  }//end cell has not been added yet
70  }//end loop over cells in this cluster
71  }//end loop over clusters
72  return StatusCode::SUCCESS;
73 }
74 
76 { return StatusCode::SUCCESS; }
77 
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
CaloTowerxAODFromClusters::~CaloTowerxAODFromClusters
virtual ~CaloTowerxAODFromClusters()
Baseclass destructor.
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
CaloTowerxAODAlgoBase::getIndexCache
const CellToTowerVec & getIndexCache(const EventContext &ctx) const
Definition: CaloTowerxAODAlgoBase.cxx:63
CaloTowerxAODFromClusters::CaloTowerxAODFromClusters
CaloTowerxAODFromClusters(const std::string &name, ISvcLocator *pSvcLocator)
Default algorithm constructor.
Definition: CaloTowerxAODFromClusters.cxx:17
CaloTowerxAODFromClusters.h
CaloTowerAuxContainer.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
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
CaloTowerxAODFromClusters::initialize
virtual StatusCode initialize() override
Initialize algorithm.
Definition: CaloTowerxAODFromClusters.cxx:27
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
CaloTowerxAODFromClusters::finalize
virtual StatusCode finalize() override
Finalize algorithm.
Definition: CaloTowerxAODFromClusters.cxx:75
WriteCellNoiseToCool.cellHash
cellHash
Definition: WriteCellNoiseToCool.py:433
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
CaloTowerxAODFromClusters::m_inputClusterContainerKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_inputClusterContainerKey
Definition: CaloTowerxAODFromClusters.h:38
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloTowerxAODFromClusters::execute
virtual StatusCode execute(const EventContext &) const override
Execute algorithm.
Definition: CaloTowerxAODFromClusters.cxx:33
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
IdentifierHash
Definition: IdentifierHash.h:38
CaloTowerxAODAlgoBase
Definition: CaloTowerxAODAlgoBase.h:24