ATLAS Offline Software
Loading...
Searching...
No Matches
ClusterCellRelinkAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3*/
4
10
15{
16 ATH_CHECK( m_cells.initialize() );
17 ATH_CHECK( m_clustersInput.initialize() );
18 ATH_CHECK( m_clustersOutput.initialize() );
19 ATH_CHECK( m_cellLinksOutput.initialize() );
20
21 return StatusCode::SUCCESS;
22}
23
28StatusCode ClusterCellRelinkAlg::execute (const EventContext& ctx) const
29{
31 if(!cells.isValid()) {
32 ATH_MSG_WARNING( "Collection " << m_cells.key() << " is not valid" );
33 return StatusCode::SUCCESS;
34 }
35
36 // input clusters
38 if(!clustersInput.isValid()) {
39 ATH_MSG_WARNING( "Collection " << m_clustersInput.key() << " is not valid" );
40 return StatusCode::SUCCESS;
41 }
42
43 // create new clusters made of cells from another container
45 ATH_CHECK( clustersOutputHandle.record(std::make_unique<xAOD::CaloClusterContainer>(), std::make_unique<xAOD::CaloClusterAuxContainer>()) );
46 xAOD::CaloClusterContainer* clustersOutputContainer = clustersOutputHandle.ptr();
47 clustersOutputContainer->reserve(clustersInput->size());
48
49 for (const xAOD::CaloCluster* oldCluster : *clustersInput) {
50 xAOD::CaloCluster* newCluster = new xAOD::CaloCluster();
51 clustersOutputContainer->push_back(newCluster);
52 *newCluster = *oldCluster;
53 newCluster->addCellLink(new CaloClusterCellLink(cells.ptr()));
54
55 const CaloClusterCellLink* cellLinks = oldCluster->getCellLinks();
57 CaloClusterCellLink::const_iterator lnk_it_e=cellLinks->end();
58 newCluster->getOwnCellLinks()->reserve(cellLinks->size());
59
60 for (;lnk_it!=lnk_it_e;++lnk_it) {
61 const IdentifierHash cellHash = (*lnk_it)->caloDDE()->calo_hash();
62 const int newIdx=cells->findIndex(cellHash);
63 newCluster->addCell(newIdx, lnk_it.weight());
64 }
65 }
66
68 ATH_CHECK( CaloClusterStoreHelper::finalizeClusters(cellLinksOutputHandle, clustersOutputContainer) );
69
70 return StatusCode::SUCCESS;
71}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clustersInput
virtual StatusCode initialize() override
Gaudi initialize method.
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_cellLinksOutput
SG::ReadHandleKey< CaloCellContainer > m_cells
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clustersOutput
virtual StatusCode execute(const EventContext &ctx) const override
Execute the algorithm.
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
This is a "hash" representation of an Identifier.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
void addCellLink(CaloClusterCellLink *CCCL)
CaloClusterCellLink * getOwnCellLinks()
Get a pointer to the owned CaloClusterCellLink object (non-const version)
bool addCell(const unsigned index, const double weight)
Method to add a cell to the cluster (Beware: Kinematics not updated!)
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.