ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimRegionMergingAlg.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
4
5constexpr bool enableBenchmark =
6#ifdef BENCHMARK_FPGATRACKSIM
7 true;
8#else
9 false;
10#endif
11
12FPGATrackSim::FPGATrackSimRegionMergingAlg::FPGATrackSimRegionMergingAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {
13}
14
16{
20
24
25 ATH_CHECK(m_overlapRemovalTool.retrieve());
26
27 ATH_CHECK(m_chrono.retrieve());
28 return StatusCode::SUCCESS;
29}
30
31StatusCode FPGATrackSim::FPGATrackSimRegionMergingAlg::execute(const EventContext& ctx) const
32{
33
34 std::vector<SG::ReadHandle<FPGATrackSimTrackCollection>> incomingFPGATrackSimTrackCollections = m_FPGATrackCollectionKeys.makeHandles(ctx);
36
37 std::vector<SG::ReadHandle<FPGATrackSimRoadCollection>> incomingFPGARoadSimTrackCollections = m_FPGARoadCollectionKeys.makeHandles(ctx);
39
40 std::vector<SG::ReadHandle<FPGATrackSimHitContainer>> incomingFPGAHitsInRoadsCollections = m_FPGAHitsInRoadsCollectionKeys.makeHandles(ctx);
42
43 std::vector<const FPGATrackSimTrackCollection*> incomingFPGATrackSimTrackCollectionsPtrs;
44 for (SG::ReadHandle<FPGATrackSimTrackCollection>& trackCollection : incomingFPGATrackSimTrackCollections)
45 {
46 if (!trackCollection.isValid())
47 {
48 ATH_MSG_ERROR("Invalid FPGATrackCollection key with name " << trackCollection.key());
49 return StatusCode::FAILURE;
50 }
51 incomingFPGATrackSimTrackCollectionsPtrs.push_back(trackCollection.cptr());
52 }
53
54 std::unique_ptr<FPGATrackSimTrackCollection> finalFPGATracksPtr = std::make_unique<FPGATrackSimTrackCollection>(); // temporary collection
55 ATH_CHECK(mergeTracks(incomingFPGATrackSimTrackCollectionsPtrs, finalFPGATracksPtr));
56 finalFPGATracksHandle = std::move(finalFPGATracksPtr);
57
58 if(m_useRoads){
59 std::vector<const FPGATrackSimRoadCollection*> incomingFPGARoadSimTrackCollectionsPtrs;
60 std::vector<const FPGATrackSimHitContainer*> incomingFPGAHitsInRoadsCollectionsPtrs;
61 for (SG::ReadHandle<FPGATrackSimRoadCollection>& roadCollection : incomingFPGARoadSimTrackCollections)
62 {
63 if (!roadCollection.isValid())
64 {
65 ATH_MSG_ERROR("Invalid FPGARoadCollection key with name " << roadCollection.key());
66 return StatusCode::FAILURE;
67 }
68 incomingFPGARoadSimTrackCollectionsPtrs.push_back(roadCollection.cptr());
69 }
70 for (SG::ReadHandle<FPGATrackSimHitContainer>& hitsInRoadsCollection : incomingFPGAHitsInRoadsCollections)
71 {
72 if (!hitsInRoadsCollection.isValid())
73 {
74 ATH_MSG_ERROR("Invalid FPGAHitsInRoadsCollection key with name " << hitsInRoadsCollection.key());
75 return StatusCode::FAILURE;
76 }
77 incomingFPGAHitsInRoadsCollectionsPtrs.push_back(hitsInRoadsCollection.cptr());
78 }
79 if (incomingFPGARoadSimTrackCollectionsPtrs.size() != incomingFPGAHitsInRoadsCollectionsPtrs.size()) {
80 ATH_MSG_ERROR("Number of road collections and hit containers do not match: " << incomingFPGARoadSimTrackCollectionsPtrs.size() << " vs " << incomingFPGAHitsInRoadsCollectionsPtrs.size());
81 return StatusCode::FAILURE;
82 }
83
84 std::unique_ptr<FPGATrackSimRoadCollection> finalFPGARoadsPtr = std::make_unique<FPGATrackSimRoadCollection>(); // temporary collection
85 std::unique_ptr<FPGATrackSimHitContainer> finalFPGAHitsInRoadsPtr = std::make_unique<FPGATrackSimHitContainer>(); // temporary collection
86 ATH_CHECK(mergeRoads(incomingFPGARoadSimTrackCollectionsPtrs,
87 incomingFPGAHitsInRoadsCollectionsPtrs,
88 finalFPGARoadsPtr,
89 finalFPGAHitsInRoadsPtr));
90
91 finalFPGARoads = std::move(finalFPGARoadsPtr);
92 finalFPGAHitsInRoads = std::move(finalFPGAHitsInRoadsPtr);
93 }
94
95
96
97 return StatusCode::SUCCESS;
98}
99
101{
102 ATH_MSG_INFO("Number of tracks: incoming / passed region OR / passed globalOR: " << m_allIncomingTracks << " / " << m_nPreORTracks << " / " << m_nPostORTracks);
103 return StatusCode::SUCCESS;
104}
105
106StatusCode FPGATrackSim::FPGATrackSimRegionMergingAlg::mergeTracks(const std::vector<const FPGATrackSimTrackCollection*>& inputTracksPtrs,
107 std::unique_ptr<FPGATrackSimTrackCollection>& outputTracks) const {
108 size_t numberOfAllTracks = 0;
109 for (const FPGATrackSimTrackCollection* tracksInRegion : inputTracksPtrs)
110 {
111 numberOfAllTracks += tracksInRegion->size();
112 }
113
114 ATH_MSG_INFO("Filtering and concatenating " << numberOfAllTracks << " tracks from " << inputTracksPtrs.size() << " regions");
115 if constexpr (enableBenchmark) m_chrono->chronoStart("Merging Tracks");
116 FPGATrackSimTrackCollection regionFilteredTracks;
117 regionFilteredTracks.reserve(numberOfAllTracks);
118 for (const FPGATrackSimTrackCollection* tracksInRegion : inputTracksPtrs)
119 {
120 for (const FPGATrackSimTrack& track : *tracksInRegion)
121 {
122 if (track.passedOR())
123 {
124 regionFilteredTracks.push_back(track);
125 }
126 }
127 }
128 if constexpr (enableBenchmark) m_chrono->chronoStop("Merging Tracks");
129
130 // Overlap removal: It runs only on the tracks that passed the in-region OR
131 if constexpr (enableBenchmark) m_chrono->chronoStart("Overlap removal (tracks)");
132 if (m_doOverlapRemoval) ATH_CHECK(m_overlapRemovalTool->runOverlapRemoval(regionFilteredTracks));
133 if constexpr (enableBenchmark) m_chrono->chronoStop("Overlap removal (tracks)");
134
135 if constexpr (enableBenchmark) m_chrono->chronoStart("Copying final tracks");
136 outputTracks->reserve(numberOfAllTracks);
137 for (const FPGATrackSimTrack & track: regionFilteredTracks)
138 {
139 if(track.passedOR()) outputTracks->push_back(track);
140 }
141 if constexpr (enableBenchmark) m_chrono->chronoStop("Copying final tracks");
142
143 m_nPreORTracks.fetch_add(regionFilteredTracks.size(), std::memory_order_relaxed); // number of tracks that passed the region OR only (if configured upstream)
144 m_allIncomingTracks.fetch_add(numberOfAllTracks, std::memory_order_relaxed); // number of all tracks from all regions
145 m_nPostORTracks.fetch_add(outputTracks->size(), std::memory_order_relaxed); // number of tracks that passed the global OR
146
147 return StatusCode::SUCCESS;
148}
149
150
151StatusCode FPGATrackSim::FPGATrackSimRegionMergingAlg::mergeRoads(const std::vector<const FPGATrackSimRoadCollection*>& inputRoads,
152 const std::vector<const FPGATrackSimHitContainer*>& inputHitsInRoads,
153 std::unique_ptr<FPGATrackSimRoadCollection>& outputRoads,
154 std::unique_ptr<FPGATrackSimHitContainer>& outputHitsInRoads) const{
155 size_t numberOfAllRoads = 0;
156 size_t numberOfAllHitsInRoads = 0;
157 for (const FPGATrackSimRoadCollection* roadCollection : inputRoads) {
158 numberOfAllRoads += roadCollection->size();
159 }
160 for (const FPGATrackSimHitContainer* hitsInRoadsContainer : inputHitsInRoads) {
161 numberOfAllHitsInRoads += hitsInRoadsContainer->size();
162 }
163
164 ATH_MSG_INFO("Filtering and concatenating " << numberOfAllRoads << " roads from " << inputRoads.size() << " regions");
165 if constexpr (enableBenchmark) m_chrono->chronoStart("Merging Roads and HitsInRoads");
166 outputRoads->reserve(numberOfAllRoads);
167 outputHitsInRoads->reserve(numberOfAllHitsInRoads);
168
169 for (size_t i = 0; i < inputRoads.size(); ++i) {
170 const FPGATrackSimRoadCollection* roadCollection = inputRoads[i];
171 const FPGATrackSimHitContainer* hitsInRoadsContainer = inputHitsInRoads[i];
172 outputRoads->insert(outputRoads->end(), roadCollection->begin(), roadCollection->end());
173 outputHitsInRoads->insert(outputHitsInRoads->end(), hitsInRoadsContainer->begin(), hitsInRoadsContainer->end());
174 }
175 if constexpr (enableBenchmark) m_chrono->chronoStop("Merging Roads and HitsInRoads");
176
177 return StatusCode::SUCCESS;
178 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
std::vector< std::vector< FPGATrackSimHit > > FPGATrackSimHitContainer
This algorithm is used to merge track or road collections from multiple regions.
std::vector< FPGATrackSimRoad > FPGATrackSimRoadCollection
std::vector< FPGATrackSimTrack > FPGATrackSimTrackCollection
An algorithm that can be simultaneously executed in multiple threads.
StatusCode mergeTracks(const std::vector< const FPGATrackSimTrackCollection * > &inputTracksPtrs, std::unique_ptr< FPGATrackSimTrackCollection > &outputTracks) const
FPGATrackSimRegionMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKeyArray< FPGATrackSimTrackCollection > m_FPGATrackCollectionKeys
StatusCode mergeRoads(const std::vector< const FPGATrackSimRoadCollection * > &inputRoads, const std::vector< const FPGATrackSimHitContainer * > &inputHitsInRoads, std::unique_ptr< FPGATrackSimRoadCollection > &outputRoads, std::unique_ptr< FPGATrackSimHitContainer > &outputHitsInRoads) const
SG::ReadHandleKeyArray< FPGATrackSimRoadCollection > m_FPGARoadCollectionKeys
SG::WriteHandleKey< FPGATrackSimTrackCollection > m_FinalFPGATrackCollectionKey
SG::ReadHandleKeyArray< FPGATrackSimHitContainer > m_FPGAHitsInRoadsCollectionKeys
SG::WriteHandleKey< FPGATrackSimHitContainer > m_FinalFPGAHitsInRoadsCollectionKey
SG::WriteHandleKey< FPGATrackSimRoadCollection > m_FinalFPGARoadkCollectionKey
virtual StatusCode execute(const EventContext &ctx) const override final
constexpr bool enableBenchmark