ATLAS Offline Software
Loading...
Searching...
No Matches
TrackCollectionMerger.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Implementation file for class Trk::TrackCollectionMerger
8
10// Version 1.0 11/26/2007 Thomas Koffas
12#include "GaudiKernel/MsgStream.h"
15
17// Constructor
20 ISvcLocator* pSvcLocator)
21 : AthReentrantAlgorithm(name, pSvcLocator) {}
22
24// Initialisation
26StatusCode
28{
29
30 ATH_MSG_DEBUG("Initializing TrackCollectionMerger");
31 ATH_CHECK(m_tracklocation.initialize());
35 ATH_CHECK(m_outtracklocation.initialize());
36 ATH_CHECK(m_assoTool.retrieve(DisableTool{m_assoTool.name().empty()}));
37 ATH_CHECK(m_assoMapName.initialize(!m_assoMapName.key().empty()));
38 return StatusCode::SUCCESS;
39}
40
42// Execute
44StatusCode
45Trk::TrackCollectionMerger::execute(const EventContext& ctx) const{
46
47 auto outputCol = std::make_unique<ConstDataVector<TrackCollection>>(SG::VIEW_ELEMENTS);
48 ATH_MSG_DEBUG("Number of Track collections " << m_tracklocation.size());
49
50 // pre-loop to reserve enough space in the output collection
51 std::vector<const TrackCollection*> trackCollections;
52 trackCollections.reserve(m_tracklocation.size());
53 size_t ttNumber = 0;
54 for (const auto& tcname : m_tracklocation){
56 SG::ReadHandle<TrackCollection> trackCol (tcname, ctx);
57 trackCollections.push_back(trackCol.cptr());
58 ttNumber += trackCol->size();
59 }
60 std::unique_ptr<Trk::PRDtoTrackMap> pPrdToTrackMap(m_assoTool ? m_assoTool->createPRDtoTrackMap() : nullptr);
61 // reserve the right number of entries for the output collection
62 outputCol->reserve(ttNumber);
63 // merging loop
64 for (auto& tciter : trackCollections) {
65 // merge them in
66 if (mergeTrack(tciter, pPrdToTrackMap.get(), outputCol.get()).isFailure()) {
67 ATH_MSG_ERROR("Failed to merge tracks! ");
68 }
69 }
70 ATH_MSG_DEBUG("Size of combined tracks " << outputCol->size());
71
72 auto h_write = SG::makeHandle(m_outtracklocation, ctx);
73 ATH_CHECK(h_write.record(std::move(outputCol)));
74 //
75 if (!m_assoMapName.key().empty()) {
77 if (write_handle.record( m_assoTool->reduceToStorableMap(std::move(pPrdToTrackMap))).isFailure()) {
78 ATH_MSG_FATAL("Failed to add PRD to track association map.");
79 }
80 }
81 //Print common event information
82 ATH_MSG_DEBUG("Done !");
83 return StatusCode::SUCCESS;
84}
85
87// Finalize
89StatusCode
91{
92 return StatusCode::SUCCESS;
93}
94
96// Merge track collections and remove duplicates
98StatusCode
100 Trk::PRDtoTrackMap* pPrdToTrackMap,
101 ConstDataVector<TrackCollection>* outputCol) const
102{
103 // loop over tracks, accept them and add them into association tool
104 if (trackCol && !trackCol->empty()) {
105 ATH_MSG_DEBUG("Size of track collection " << trackCol->size());
106 if (not pPrdToTrackMap)
107 ATH_MSG_WARNING("No valid PRD to Track Map; was the association tool name missing?");
108 // loop over tracks
109 for (const auto* const rf : *trackCol) {
110 outputCol->push_back(rf);
111 // add tracks into PRD tool
112 if (m_assoTool and m_assoTool->addPRDs(*pPrdToTrackMap, *rf).isFailure())
113 ATH_MSG_WARNING("Failed to add PRDs to map");
114 }
115 }
116
117 return StatusCode::SUCCESS;
118}
119
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
An algorithm that can be simultaneously executed in multiple threads.
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual StatusCode execute(const EventContext &ctx) const override final
StatusCode mergeTrack(const TrackCollection *trackCol, Trk::PRDtoTrackMap *pPrdToTrackMap, ConstDataVector< TrackCollection > *outputCol) const
Protected methods:
SG::ReadHandleKeyArray< TrackCollection > m_tracklocation
Protected data:
SG::WriteHandleKey< ConstDataVector< TrackCollection > > m_outtracklocation
Combined track collection.
SG::ReadHandleKey< InDet::TRT_DriftCircleContainer > m_pileupTRT
pileup TRT PRDs, only retrieved if track overlay is on
SG::ReadHandleKey< InDet::SCT_ClusterContainer > m_pileupSCT
pileup SCT PRDs, only retrieved if track overlay is on
SG::ReadHandleKey< InDet::PixelClusterContainer > m_pileupPixel
pileup pixel PRDs, only retrieved if track overlay is on
virtual StatusCode initialize() override final
ToolHandle< Trk::IPRDtoTrackMapTool > m_assoTool
SG::WriteHandleKey< Trk::PRDtoTrackMap > m_assoMapName
the key given to the newly created association map
virtual StatusCode finalize() override final
TrackCollectionMerger(const std::string &name, ISvcLocator *pSvcLocator)
Standard Algotithm methods:
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())