ATLAS Offline Software
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 
5 #include "ClusterCellRelinkAlg.h"
6 #include "StoreGate/ReadHandle.h"
10 
15 {
20 
21  return StatusCode::SUCCESS;
22 }
23 
28 StatusCode 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();
56  CaloClusterCellLink::const_iterator lnk_it=cellLinks->begin();
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 }
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
ClusterCellRelinkAlg::m_clustersOutput
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clustersOutput
Definition: ClusterCellRelinkAlg.h:50
ClusterCellRelinkAlg::m_cells
SG::ReadHandleKey< CaloCellContainer > m_cells
Definition: ClusterCellRelinkAlg.h:42
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ClusterCellRelinkAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execute the algorithm.
Definition: ClusterCellRelinkAlg.cxx:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloClusterAuxContainer.h
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
ClusterCellRelinkAlg::m_clustersInput
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clustersInput
Definition: ClusterCellRelinkAlg.h:46
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ClusterCellRelinkAlg::initialize
virtual StatusCode initialize() override
Gaudi initialize method.
Definition: ClusterCellRelinkAlg.cxx:14
ClusterCellRelinkAlg::m_cellLinksOutput
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_cellLinksOutput
Definition: ClusterCellRelinkAlg.h:54
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
WriteCellNoiseToCool.cellHash
cellHash
Definition: WriteCellNoiseToCool.py:433
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
ClusterCellRelinkAlg.h
xAOD::CaloCluster_v1::addCellLink
void addCellLink(CaloClusterCellLink *CCCL)
Definition: CaloCluster_v1.h:721
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::CaloCluster_v1::getOwnCellLinks
CaloClusterCellLink * getOwnCellLinks()
Get a pointer to the owned CaloClusterCellLink object (non-const version)
Definition: CaloCluster_v1.h:762
xAOD::CaloCluster_v1::addCell
bool addCell(const unsigned index, const double weight)
Method to add a cell to the cluster (Beware: Kinematics not updated!)
Definition: CaloCluster_v1.h:771
ReadHandle.h
Handle class for reading from StoreGate.
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.