25 #include "GaudiKernel/IEventProcessor.h"
28 #ifdef BENCHMARK_LOGICALHITSALG
49 while (std::getline(
ss,
line,
'\n')) {
93 return StatusCode::SUCCESS;
103 const EventContext& ctx = getContext();
109 ATH_MSG_WARNING(
"Didn't receive " << FPGAHits.
key() <<
" on first event; assuming no input events.");
111 SmartIF<IEventProcessor> appMgr{service(
"ApplicationMgr")};
113 ATH_MSG_ERROR(
"Failed to retrieve ApplicationMgr as IEventProcessor");
114 return StatusCode::FAILURE;
116 return appMgr->stopRun();
124 ATH_CHECK( FPGAHits_2nd.
record (std::make_unique<FPGATrackSimHitCollection>()));
125 ATH_CHECK( FPGARoads_1st.
record (std::make_unique<FPGATrackSimRoadCollection>()));
126 ATH_CHECK( FPGAHitsInRoads_1st.
record (std::make_unique<FPGATrackSimHitContainer>()));
129 ATH_CHECK(FPGATracks_1stHandle.
record (std::make_unique<FPGATrackSimTrackCollection>()));
132 ATH_CHECK( FPGAHitsFiltered_1st.
record (std::make_unique<FPGATrackSimHitCollection>()));
135 if (!
m_evtSel->getSelectedEvent()) {
137 return StatusCode::SUCCESS;
145 std::vector<std::shared_ptr<const FPGATrackSimHit>> phits_1st, phits_2nd;
147 phits_1st.reserve(FPGAHits->size());
148 phits_2nd.reserve(FPGAHits->size());
156 FPGAHits_2nd->push_back(hit);
163 if (!FPGATruthTracks.
isValid()) {
164 ATH_MSG_ERROR(
"Could not find FPGA Truth Track Collection with key " << FPGATruthTracks.
key());
165 return StatusCode::FAILURE;
170 if (!FPGAOfflineTracks.
isValid()) {
171 ATH_MSG_ERROR(
"Could not find FPGA Offline Track Collection with key " << FPGAOfflineTracks.
key());
172 return StatusCode::FAILURE;
176 std::vector<std::shared_ptr<const FPGATrackSimRoad>> prefilter_roads;
177 std::vector<std::shared_ptr<const FPGATrackSimRoad>> roads_1st =
182 for (
auto const &road : roads_1st) {
183 unsigned bitmask = road->getHitLayers();
185 if (bitmask & (1 <<
l)) {
195 std::vector<std::shared_ptr<const FPGATrackSimRoad>> postfilter_roads;
199 roads_1st = postfilter_roads;
203 std::vector<std::shared_ptr<const FPGATrackSimRoad>> postfilter2_roads;
206 roads_1st = postfilter2_roads;
215 std::vector<FPGATrackSimTrack> tracks_1st;
224 for (
const auto& road : roads_1st) {
225 std::vector<FPGATrackSimTrack> tracksForCurrentRoad;
228 std::vector<std::shared_ptr<const FPGATrackSimRoad>> roadVec = {road};
232 if (!tracksForCurrentRoad.empty()) {
233 auto bestTrackIter = std::min_element(
234 tracksForCurrentRoad.begin(), tracksForCurrentRoad.end(),
236 return a.getChi2ndof() < b.getChi2ndof();
239 if (bestTrackIter != tracksForCurrentRoad.end() && bestTrackIter->getChi2ndof() < 1.e15) {
240 tracks_1st.push_back(*bestTrackIter);
249 if (!tracks_1st.empty()) {
250 float bestChi2Overall = std::min_element(
251 tracks_1st.begin(), tracks_1st.end(),
253 return a.getChi2ndof() < b.getChi2ndof();
261 float bestchi2 = 1.e15;
264 if (
chi2 < bestchi2) bestchi2 =
chi2;
275 for (
const std::shared_ptr<const FPGATrackSimRoad>& road : roads_1st) {
276 ntrackDummy += road->getNHitCombos();
278 tracks_1st.resize(ntrackDummy);
282 for (
auto const& road : roads_1st) {
283 std::vector<FPGATrackSimHit> road_hits;
284 ATH_MSG_DEBUG(
"Hough Road X Y: " << road->getX() <<
" " << road->getY());
285 for (
size_t l = 0;
l < road->getNLayers(); ++
l) {
286 for (
const auto& layerH : road->getHits(
l)) {
287 road_hits.push_back(*layerH);
290 FPGAHitsInRoads_1st->push_back(road_hits);
291 FPGARoads_1st->push_back(*road);
301 unsigned ntrackOLRChi2 = 0;
305 if (
track.passedOR()) {
310 float chi2olr =
track.getChi2ndof();
324 std::vector<FPGATrackSimTruthTrack> truthtracks = *FPGATruthTracks;
325 std::vector<FPGATrackSimOfflineTrack> offlineTracks = *FPGAOfflineTracks;
326 if (truthtracks.size() > 0) {
339 unsigned npasschi2(0);
340 unsigned npasschi2OLR(0);
341 if (tracks_1st.size() > 0) {
344 for (
const auto&
track : tracks_1st) {
347 if (
track.passedOR()) {
365 std::vector<std::shared_ptr<const FPGATrackSimRoad>> roadsLRT;
366 std::vector<FPGATrackSimTrack> tracksLRT;
369 std::vector<std::shared_ptr<const FPGATrackSimHit>> remainingHits;
372 ATH_MSG_DEBUG(
"Doing hit filtering based on prompt tracks.");
375 for (
const auto &
Hit : remainingHits) FPGAHitsFiltered_1st->push_back(*
Hit);
378 ATH_MSG_DEBUG(
"No hit filtering requested; using all hits for LRT.");
379 remainingHits = phits_1st;
387 auto dataFlowInfo = std::make_unique<FPGATrackSimDataFlowInfo>();
398 SmartIF<IEventProcessor> appMgr{service(
"ApplicationMgr")};
400 ATH_MSG_ERROR(
"Failed to retrieve ApplicationMgr as IEventProcessor");
401 return StatusCode::FAILURE;
404 phits_2nd.insert(phits_2nd.end(), std::make_move_iterator(phits_1st.begin()), std::make_move_iterator(phits_1st.end()));
413 return StatusCode::SUCCESS;
422 std::vector<FPGATrackSimTrack>
const& tracks_1st,
427 ATH_MSG_DEBUG(
"NFPGATrackSimRoads_1st = " << roads_1st.size() <<
", NFPGATrackSimTracks_1st = " << tracks_1st.size());
447 return StatusCode::SUCCESS;
457 ATH_MSG_INFO(
"========================================================================================");
469 ATH_MSG_INFO(
"========================================================================================");
475 ATH_MSG_INFO(
"========================================================================================");
477 return StatusCode::SUCCESS;
487 for (
const auto& hit :
hits)
490 std::stringstream
ss;
491 for (
auto r : regions)