(first track monitor, after getting tracks) create a vector of references from a vector of instances
(second track monitor, after set track parameters to truth) create a vector of references from a vector of instances
149{
150 const EventContext& ctx = getContext();
151
152
153 SG::ReadHandle<FPGATrackSimHitCollection> FPGAHits(
m_FPGAHitKey, ctx);
154 if (!FPGAHits.isValid()) {
156 ATH_MSG_WARNING(
"Didn't receive " << FPGAHits.key() <<
" on first event; assuming no input events.");
157 }
158 SmartIF<IEventProcessor> appMgr{service("ApplicationMgr")};
159 if (!appMgr) {
160 ATH_MSG_ERROR(
"Failed to retrieve ApplicationMgr as IEventProcessor");
161 return StatusCode::FAILURE;
162 }
163 return appMgr->stopRun();
164 }
165
166
167 SG::WriteHandle<FPGATrackSimHitCollection> FPGAHits_1st (
m_FPGAHitKey_1st,ctx);
168 SG::WriteHandle<FPGATrackSimHitCollection> FPGAHits_2nd (
m_FPGAHitKey_2nd,ctx);
169 SG::WriteHandle<FPGATrackSimRoadCollection> FPGARoads_1st (
m_FPGARoadKey, ctx);
171
172 ATH_CHECK( FPGAHits_1st.record (std::make_unique<FPGATrackSimHitCollection>()));
173 ATH_CHECK( FPGAHits_2nd.record (std::make_unique<FPGATrackSimHitCollection>()));
174 ATH_CHECK( FPGARoads_1st.record (std::make_unique<FPGATrackSimRoadCollection>()));
175 ATH_CHECK( FPGAHitsInRoads_1st.record (std::make_unique<FPGATrackSimHitContainer>()));
176
177 SG::WriteHandle<FPGATrackSimTrackCollection> FPGATracks_1stHandle (
m_FPGATrackKey, ctx);
178 ATH_CHECK(FPGATracks_1stHandle.record (std::make_unique<FPGATrackSimTrackCollection>()));
179
181 ATH_CHECK( FPGAHitsFiltered_1st.record (std::make_unique<FPGATrackSimHitCollection>()));
182
184 ATH_CHECK( FPGASpacePoints.record (std::make_unique<FPGATrackSimClusterCollection>()));
185
186
187 if (!
m_evtSel->getSelectedEvent()) {
188
189
191 std::vector<FPGATrackSimRoad> roads_1st;
192 std::vector<FPGATrackSimTrack> tracks_1st;
193 auto dataFlowInfo = std::make_unique<FPGATrackSimDataFlowInfo>();
195 }
196
197 return StatusCode::SUCCESS;
198 }
202 }
203
204
206
207
209 if (!FPGAEventInfo.isValid()) {
210 ATH_MSG_ERROR(
"Could not find FPGA Event Info with key " << FPGAEventInfo.key());
211 return StatusCode::FAILURE;
212 }
213 FPGATrackSimEventInfo eventInfo = *FPGAEventInfo.cptr();
218
219 std::vector<std::shared_ptr<const FPGATrackSimHit>> phits_output, phits_all, phits_1st, phits_2nd;
220 {
221 std::optional<Athena::Chrono> chronoSplitHits;
222 if constexpr (
enableBenchmark) chronoSplitHits.emplace(
"1st Stage: Split hits to 1st and 2nd stage",
m_chrono.get());
223
224 phits_1st.reserve(FPGAHits->size());
225 phits_2nd.reserve(FPGAHits->size());
227 for (const FPGATrackSimHit* hit : *(FPGAHits.cptr())) {
228 phits_all.emplace_back(hit, [](const FPGATrackSimHit*) {});
229 }
230
231
233 }
234
235
236 for (auto& hit : phits_1st) {
237 FPGAHits_1st->push_back(new FPGATrackSimHit(*hit));
238 }
239
241
242
243
245 std::optional<Athena::Chrono> chronoSPFormation;
249 for (
const FPGATrackSimCluster& cluster :
m_spacepoints) FPGASpacePoints->push_back(cluster);
250 }
251
252
254 (
m_secondStageStrips ? phits_2nd : phits_1st).emplace_back(&hit, [](
const FPGATrackSimHit*){});
255 }
256 for (auto& hit : phits_2nd) {
257 FPGAHits_2nd->push_back(new FPGATrackSimHit(*hit));
258 }
259
260
261 for (const FPGATrackSimHit* hit : *(FPGAHits_2nd.cptr())) {
262 phits_output.emplace_back(hit, [](const FPGATrackSimHit*){});
263 }
264 ATH_MSG_DEBUG(
"1st stage hits: " << phits_1st.size() <<
" 2nd stage hits: " << phits_2nd.size() );
265 if (phits_1st.empty()) return StatusCode::SUCCESS;
266
267 SG::ReadHandle<FPGATrackSimTruthTrackCollection> FPGATruthTracks(
m_FPGATruthTrackKey, ctx);
268 if (!FPGATruthTracks.isValid()) {
269 ATH_MSG_ERROR(
"Could not find FPGA Truth Track Collection with key " << FPGATruthTracks.key());
270 return StatusCode::FAILURE;
271 }
272
273
275 if (!FPGAOfflineTracks.isValid()) {
276 ATH_MSG_ERROR(
"Could not find FPGA Offline Track Collection with key " << FPGAOfflineTracks.key());
277 return StatusCode::FAILURE;
278 }
279
280
282
284
286 const std::vector<FPGATrackSimTruthTrack>& truthtracks = *FPGATruthTracks;
291 auto monitorRoads = [&](auto& monitor, const auto& roads) {
292 if (!monitor.empty()) {
293 monitor->fillRoad(roads, truthtracks, nLogicalLayers);
294 }
295 };
296
297 std::vector<FPGATrackSimRoad> roads_1st;
298 {
299 std::optional<Athena::Chrono> chronoGetRoads;
301
304 }
305
306
307 {
308
309 std::optional<Athena::Chrono> chronoRoadFiltering;
311 std::vector<FPGATrackSimRoad> postfilter_roads;
314 roads_1st = std::move(postfilter_roads);
315 }
318 }
319
320
321 {
322
323 std::optional<Athena::Chrono> chronoOverlapRemoval;
328 }
329
330
331 {
332
333 std::optional<Athena::Chrono> chronoRoadFiltering2;
335 std::vector<FPGATrackSimRoad> postfilter2_roads;
338 roads_1st = std::move(postfilter2_roads);
339 }
342 }
343
344
346
348
350 auto monitorTracks = [&](auto& monitor, const auto& tracks) {
351 if (monitor.empty()) return;
352
353 std::vector<const FPGATrackSimTrack*> track_ptrs;
354 track_ptrs.reserve(tracks.size());
355
356 if constexpr (std::is_pointer_v<typename std::decay_t<decltype(tracks)>::value_type>) {
357
358 track_ptrs.insert(track_ptrs.end(), tracks.begin(), tracks.end());
359 } else {
360
361 std::transform(tracks.begin(), tracks.end(), std::back_inserter(track_ptrs), [](const auto& t) { return &t; });
362 }
363
364 monitor->fillTrack(track_ptrs, truthtracks, 1.e15);
365 };
366
367 std::vector<FPGATrackSimTrack> tracks_1st;
368 {
369
370 std::optional<Athena::Chrono> chronoGettingTracks;
379 }
380 } else {
383
384 for (const auto& road : roads_1st) {
385 std::vector<FPGATrackSimTrack> tracksForCurrentRoad;
386
387
388 std::vector<FPGATrackSimRoad> roadVec = {road};
390
391
392 if (!tracksForCurrentRoad.empty()) {
393 auto bestTrackIter = std::min_element(
394 tracksForCurrentRoad.begin(), tracksForCurrentRoad.end(),
395 [](
const FPGATrackSimTrack&
a,
const FPGATrackSimTrack& b) {
396 return a.getChi2ndof() < b.getChi2ndof();
397 });
398
399 if (bestTrackIter != tracksForCurrentRoad.end() && bestTrackIter->getChi2ndof() < 1.e15) {
400 tracks_1st.push_back(*bestTrackIter);
401 }
402 }
403 }
404 } else {
406 }
407 }
408 } else {
409 ATH_MSG_DEBUG(
"No tracking. Just running dummy road2track algorith");
411 for (const auto& road : roads_1st) {
412 std::vector<std::shared_ptr<const FPGATrackSimHit>> track_hits;
413 for (
unsigned layer = 0;
layer < road.getNLayers(); ++
layer) {
414 track_hits.insert(track_hits.end(), road.getHits(layer).begin(), road.getHits(layer).end());
415 }
416
417 FPGATrackSimTrack track_cand;
419 for (size_t ihit = 0; ihit < track_hits.size(); ++ihit) {
421 }
422 tracks_1st.push_back(track_cand);
423 }
424 }
426 }
427
428
429
432 for (auto &track : tracks_1st)
433 track.calculateTruth();
434
438 }
439
440
441 {
442
443 std::optional<Athena::Chrono> chronoSetTruthParams;
444 if constexpr (
enableBenchmark) chronoSetTruthParams.emplace(
"1st Stage: Set Track Parameters to Truth",
m_chrono.get());
445
446 for (FPGATrackSimTrack& track : tracks_1st) {
450 track.setQOverPt(truthtracks.front().getQOverPt());
452 track.setD0(truthtracks.front().getD0());
454 track.setPhi(truthtracks.front().getPhi());
456 track.setZ0(truthtracks.front().getZ0());
458 track.setEta(truthtracks.front().getEta());
459 }
460 }
464 }
465
466
467 for (auto const& road : roads_1st) {
468 auto road_hits = std::make_unique<FPGATrackSimHitCollection>();
469 ATH_MSG_DEBUG(
"Hough Road X Y: " << road.getX() <<
" " << road.getY());
470 for (
size_t l = 0;
l < road.getNLayers(); ++
l) {
471 for (const auto& layerH : road.getHits(l)) {
472 road_hits->push_back(new FPGATrackSimHit(*layerH));
473 }
474 }
475 FPGAHitsInRoads_1st->push_back(std::move(*road_hits));
476 FPGARoads_1st->push_back(road);
477 }
478
479 {
480
481 std::optional<Athena::Chrono> chronoOverlapRemoval2;
484
485 std::vector<const FPGATrackSimTrack*> tracks_1st_after_chi2;
486 std::vector<const FPGATrackSimTrack*> tracks_1st_after_overlap;
487 for (const FPGATrackSimTrack& track : tracks_1st) {
490 tracks_1st_after_chi2.push_back(&track);
491 if (
track.passedOR()) {
492 tracks_1st_after_overlap.push_back(&track);
494 }
495 }
496 }
501 }
502
505
506
507 if (truthtracks.size() > 0) {
511
512 unsigned npasschi2(0);
513 unsigned npasschi2OLR(0);
514 if (tracks_1st.size() > 0) {
517 for (const auto& track : tracks_1st) {
519 npasschi2++;
520 if (
track.passedOR()) {
521 npasschi2OLR++;
522 }
523 }
524 }
525 }
530 }
531
532 for (const FPGATrackSimTrack& track : tracks_1st) FPGATracks_1stHandle->push_back(track);
533
534
535
536 std::vector<FPGATrackSimRoad> roadsLRT;
537 std::vector<FPGATrackSimTrack> tracksLRT;
539
540 std::vector<std::shared_ptr<const FPGATrackSimHit>> remainingHits;
541
543 ATH_MSG_DEBUG(
"Doing hit filtering based on prompt tracks.");
545
546 for (const auto &Hit : remainingHits) FPGAHitsFiltered_1st->push_back(new FPGATrackSimHit(*Hit));
547
548 } else {
549 ATH_MSG_DEBUG(
"No hit filtering requested; using all hits for LRT.");
550 remainingHits = std::move(phits_1st);
551 }
552
553
556 }
557
558 auto dataFlowInfo = std::make_unique<FPGATrackSimDataFlowInfo>();
559
560
563 }
564
565
568
569 SmartIF<IEventProcessor> appMgr{service("ApplicationMgr")};
570 if (!appMgr) {
571 ATH_MSG_ERROR(
"Failed to retrieve ApplicationMgr as IEventProcessor");
572 return StatusCode::FAILURE;
573 }
574
575
577 }
578
579
582
583 return StatusCode::SUCCESS;
584}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
void roadsToTrack(std::vector< FPGATrackSimRoad > &roads, std::vector< FPGATrackSimTrack > &track_cands, const FPGATrackSimPlaneMap *pmap)
ToolHandle< FPGATrackSimTrackMonitor > m_1st_stage_road_monitor
Gaudi::Property< int > m_region
Gaudi::Property< bool > m_filterRoads2
Gaudi::Property< bool > m_doTracking
FPGATrackSimLogicalEventInputHeader * m_slicedHitHeader
Gaudi::Property< bool > m_doLRT
ToolHandle< FPGATrackSimSpacePointsToolI > m_spacepointsTool
ToolHandle< FPGATrackSimOverlapRemovalTool > m_overlapRemovalTool_1st
Gaudi::Property< int > m_SetTruthParametersForTracks
SG::WriteHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey_2nd
ToolHandle< FPGATrackSimTrackMonitor > m_1st_stage_road_post_OLR_monitor
ToolHandle< FPGATrackSimSlicingEngineTool > m_slicingEngineTool
Gaudi::Property< bool > m_writeOutputData
ServiceHandle< IChronoStatSvc > m_chrono
Gaudi::Property< bool > m_doGNNPixelSeeding
FPGATrackSimLogicalEventInputHeader * m_slicedStripHeaderPreSP
Gaudi::Property< bool > m_doGNNTrack
ToolHandle< FPGATrackSimHoughRootOutputTool > m_houghRootOutputTool
ToolHandle< FPGATrackSimTrackMonitor > m_1st_stage_road_post_filter_2_monitor
unsigned long m_maxNTracksTot
FPGATrackSimLogicalEventInputHeader * m_slicedFirstPixelHeader
Gaudi::Property< bool > m_doOverlapRemoval
Gaudi::Property< bool > m_doNNTrack
Gaudi::Property< bool > m_writeOutNonSPStripHits
Gaudi::Property< bool > m_doSpacepoints
ToolHandle< IFPGATrackSimRoadFilterTool > m_roadFilterTool
Gaudi::Property< bool > m_outputRoadUnionTool
FPGATrackSimLogicalEventInputHeader * m_slicedSecondPixelHeader
SG::WriteHandleKey< FPGATrackSimRoadCollection > m_FPGARoadKey
ToolHandle< FPGATrackSimNNTrackTool > m_NNTrackTool
ToolHandle< FPGATrackSimLLPRoadFilterTool > m_LRTRoadFilterTool
Gaudi::Property< bool > m_filterRoads
ToolHandle< IFPGATrackSimRoadFinderTool > m_LRTRoadFinderTool
ToolHandle< FPGATrackSimTrackMonitor > m_1st_stage_track_post_OLR_monitor
ToolHandle< FPGATrackSimOutputHeaderTool > m_writeOutputTool
ToolHandle< FPGATrackSimTrackMonitor > m_1st_stage_track_post_setTruth_monitor
SG::ReadHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey
Gaudi::Property< bool > m_secondStageStrips
ToolHandle< FPGATrackSimTrackFitterTool > m_trackFitterTool_1st
Gaudi::Property< bool > m_doLRTHitFiltering
ToolHandle< IFPGATrackSimRoadFilterTool > m_roadFilterTool2
Gaudi::Property< bool > m_passLowestChi2TrackOnly
Gaudi::Property< bool > m_doHoughRootOutput1st
ToolHandle< FPGATrackSimTrackMonitor > m_1st_stage_track_post_chi2_monitor
ToolHandle< FPGATrackSimTrackMonitor > m_1st_stage_track_monitor
StatusCode writeOutputData(const std::vector< FPGATrackSimRoad > &roads_1st, std::vector< FPGATrackSimTrack > const &tracks_1st, FPGATrackSimDataFlowInfo const *dataFlowInfo)
FPGATrackSimLogicalEventOutputHeader * m_logicEventOutputHeader
SG::WriteHandleKey< FPGATrackSimClusterCollection > m_FPGASpacePointsKey
ToolHandle< FPGATrackSimTrackMonitor > m_1st_stage_road_post_filter_1_monitor
SG::WriteHandleKey< FPGATrackSimHitContainer > m_FPGAHitInRoadsKey
Gaudi::Property< float > m_trackScoreCut
unsigned long m_maxNTracksChi2OLRTot
unsigned long m_maxNTracksChi2Tot
SG::ReadHandleKey< FPGATrackSimOfflineTrackCollection > m_FPGAOfflineTrackKey
long m_nTracksChi2OLRFound
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
ToolHandle< FPGATrackSimRoadUnionTool > m_roadFinderTool
SG::WriteHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey_1st
SG::WriteHandleKey< FPGATrackSimTrackCollection > m_FPGATrackKey
Gaudi::Property< int > m_writeRegion
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_evtSel
std::vector< FPGATrackSimCluster > m_spacepoints
Gaudi::Property< bool > m_doMultiTruth
SG::WriteHandleKey< FPGATrackSimHitCollection > m_FPGAHitFilteredKey
SG::ReadHandleKey< FPGATrackSimTruthTrackCollection > m_FPGATruthTrackKey
unsigned long m_maxNRoadsFound
SG::ReadHandleKey< FPGATrackSimEventInfo > m_FPGAEventInfoKey
FPGATrackSimLogicalEventInputHeader * m_slicedStripHeader
void setNLayers(int)
set the number of layers in the track.
void setFPGATrackSimHit(unsigned i, const FPGATrackSimHit &hit)
l
Printing final latex table to .tex output file.
constexpr bool enableBenchmark