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{
19
22
23 ATH_CHECK(m_overlapRemovalTool.retrieve());
24
25 ATH_CHECK(m_chrono.retrieve());
26 return StatusCode::SUCCESS;
27}
28
29StatusCode FPGATrackSim::FPGATrackSimRegionMergingAlg::execute(const EventContext& ctx) const
30{
31
32 std::vector<SG::ReadHandle<FPGATrackSimTrackCollection>> incomingFPGATrackSimTrackCollections = m_FPGATrackCollectionKeys.makeHandles(ctx);
34
35 std::vector<SG::ReadHandle<FPGATrackSimRoadCollection>> incomingFPGARoadSimTrackCollections = m_FPGARoadCollectionKeys.makeHandles(ctx);
37
38 std::vector<const FPGATrackSimTrackCollection*> incomingFPGATrackSimTrackCollectionsPtrs;
39 for (SG::ReadHandle<FPGATrackSimTrackCollection>& trackCollection : incomingFPGATrackSimTrackCollections)
40 {
41 if (!trackCollection.isValid())
42 {
43 ATH_MSG_ERROR("Invalid FPGATrackCollection key with name " << trackCollection.key());
44 return StatusCode::FAILURE;
45 }
46 incomingFPGATrackSimTrackCollectionsPtrs.push_back(trackCollection.cptr());
47 }
48
49 std::unique_ptr<FPGATrackSimTrackCollection> finalFPGATracksPtr = std::make_unique<FPGATrackSimTrackCollection>(); // temporary collection
50 ATH_CHECK(mergeTracks(incomingFPGATrackSimTrackCollectionsPtrs, finalFPGATracksPtr));
51 finalFPGATracksHandle = std::move(finalFPGATracksPtr);
52
53 if(m_useRoads){
54 std::vector<const FPGATrackSimRoadCollection*> incomingFPGARoadSimTrackCollectionsPtrs;
55 for (SG::ReadHandle<FPGATrackSimRoadCollection>& roadCollection : incomingFPGARoadSimTrackCollections)
56 {
57 if (!roadCollection.isValid())
58 {
59 ATH_MSG_ERROR("Invalid FPGARoadCollection key with name " << roadCollection.key());
60 return StatusCode::FAILURE;
61 }
62 incomingFPGARoadSimTrackCollectionsPtrs.push_back(roadCollection.cptr());
63 }
64
65 std::unique_ptr<FPGATrackSimRoadCollection> finalFPGARoadsPtr = std::make_unique<FPGATrackSimRoadCollection>(); // temporary collection
66 ATH_CHECK(mergeRoads(incomingFPGARoadSimTrackCollectionsPtrs, finalFPGARoadsPtr));
67
68 finalFPGARoads = std::move(finalFPGARoadsPtr);
69 }
70
71
72
73 return StatusCode::SUCCESS;
74}
75
77{
78 ATH_MSG_INFO("Number of tracks: incoming / passed region OR / passed globalOR: " << m_allIncomingTracks << " / " << m_nPreORTracks << " / " << m_nPostORTracks);
79 return StatusCode::SUCCESS;
80}
81
82StatusCode FPGATrackSim::FPGATrackSimRegionMergingAlg::mergeTracks(const std::vector<const FPGATrackSimTrackCollection*>& inputTracksPtrs,
83 std::unique_ptr<FPGATrackSimTrackCollection>& outputTracks) const {
84 size_t numberOfAllTracks = 0;
85 for (const FPGATrackSimTrackCollection* tracksInRegion : inputTracksPtrs)
86 {
87 numberOfAllTracks += tracksInRegion->size();
88 }
89
90 ATH_MSG_INFO("Filtering and concatenating " << numberOfAllTracks << " tracks from " << inputTracksPtrs.size() << " regions");
91 if constexpr (enableBenchmark) m_chrono->chronoStart("RegionMerging: Merging Tracks");
92 FPGATrackSimTrackCollection regionFilteredTracks;
93 regionFilteredTracks.reserve(numberOfAllTracks);
94 for (const FPGATrackSimTrackCollection* tracksInRegion : inputTracksPtrs)
95 {
96 for (const FPGATrackSimTrack& track : *tracksInRegion)
97 {
98 if (track.passedOR())
99 {
100 regionFilteredTracks.push_back(track);
101 }
102 }
103 }
104 if constexpr (enableBenchmark) m_chrono->chronoStop("RegionMerging: Merging Tracks");
105
106 // Overlap removal: It runs only on the tracks that passed the in-region OR
107 if constexpr (enableBenchmark) m_chrono->chronoStart("RegionMerging: Overlap removal (tracks)");
108 if (m_doOverlapRemoval) ATH_CHECK(m_overlapRemovalTool->runOverlapRemoval(regionFilteredTracks));
109 if constexpr (enableBenchmark) m_chrono->chronoStop("RegionMerging: Overlap removal (tracks)");
110
111 if constexpr (enableBenchmark) m_chrono->chronoStart("RegionMerging: Copying final tracks");
112 outputTracks->reserve(numberOfAllTracks);
113 for (const FPGATrackSimTrack & track: regionFilteredTracks)
114 {
115 if(track.passedOR()) outputTracks->push_back(track);
116 }
117 if constexpr (enableBenchmark) m_chrono->chronoStop("RegionMerging: Copying final tracks");
118
119 m_nPreORTracks.fetch_add(regionFilteredTracks.size(), std::memory_order_relaxed); // number of tracks that passed the region OR only (if configured upstream)
120 m_allIncomingTracks.fetch_add(numberOfAllTracks, std::memory_order_relaxed); // number of all tracks from all regions
121 m_nPostORTracks.fetch_add(outputTracks->size(), std::memory_order_relaxed); // number of tracks that passed the global OR
122
123 return StatusCode::SUCCESS;
124}
125
126
127StatusCode FPGATrackSim::FPGATrackSimRegionMergingAlg::mergeRoads(const std::vector<const FPGATrackSimRoadCollection*>& inputRoads,
128 std::unique_ptr<FPGATrackSimRoadCollection>& outputRoads) const{
129 size_t numberOfAllRoads = 0;
130 for (const FPGATrackSimRoadCollection* roadCollection : inputRoads) {
131 numberOfAllRoads += roadCollection->size();
132 }
133
134 ATH_MSG_INFO("Filtering and concatenating " << numberOfAllRoads << " roads from " << inputRoads.size() << " regions");
135 if constexpr (enableBenchmark) m_chrono->chronoStart("Merging Roads");
136 outputRoads->reserve(numberOfAllRoads);
137
138 for (const FPGATrackSimRoadCollection* roadCollection : inputRoads) {
139 outputRoads->insert(outputRoads->end(), roadCollection->begin(), roadCollection->end());
140 }
141 if constexpr (enableBenchmark) m_chrono->chronoStop("Merging Roads");
142
143 return StatusCode::SUCCESS;
144 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
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
SG::ReadHandleKeyArray< FPGATrackSimRoadCollection > m_FPGARoadCollectionKeys
SG::WriteHandleKey< FPGATrackSimTrackCollection > m_FinalFPGATrackCollectionKey
StatusCode mergeRoads(const std::vector< const FPGATrackSimRoadCollection * > &inputRoads, std::unique_ptr< FPGATrackSimRoadCollection > &outputRoads) const
SG::WriteHandleKey< FPGATrackSimRoadCollection > m_FinalFPGARoadkCollectionKey
virtual StatusCode execute(const EventContext &ctx) const override final
constexpr bool enableBenchmark