ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimSlicingEngineTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <array>
6#include <vector>
7
12#include <nlohmann/json.hpp>
13
14FPGATrackSimSlicingEngineTool::FPGATrackSimSlicingEngineTool(std::string const & algname, std::string const & name, IInterface const * ifc) :
15 AthAlgTool(algname,name,ifc) {}
16
17
19{
20 ATH_MSG_INFO("Reading first stage module/layer map in slicing engine: " << m_layerMap);
22 return StatusCode::SUCCESS;
23}
24
26 // Adapted from FPGATrackSimBinnedHits
27 std::ifstream stream(m_layerMap);
28 nlohmann::json data = nlohmann::json::parse(stream);
29
30 std::set<unsigned> modules;
31
32 // Loop over entries in the layer map.
33 for (const auto &binelem : data) {
34 std::vector<unsigned> bin;
35 binelem.at("bin").get_to(bin);
36 auto& lyrmap = binelem["lyrmap"];
37 ATH_MSG_DEBUG("bin = " << bin);
38 ATH_MSG_DEBUG("lyrmap = " << lyrmap);
39 for (auto &lyrelem : lyrmap) {
40 unsigned layer;
41 lyrelem.at("lyr").get_to(layer);
42 lyrelem.at("mods").get_to(modules);
43 ATH_MSG_DEBUG("layer = " << layer);
44 ATH_MSG_DEBUG("mods = " << modules);
45
46 // Build a single set containing all module ID hashes used in the layer map.
47 // NOTE: this assumes the pixel module hashes are all unique?
48 m_layerMapModules.merge(modules);
49 }
50 }
51
52 ATH_MSG_DEBUG("Region Modules: " << m_layerMapModules);
53}
54
55// While this method returns *two* streams, it outputs *three* branches since in the firmware
56// second stage pixels and strips will probably be split.
57void FPGATrackSimSlicingEngineTool::sliceHits(const std::vector<std::shared_ptr<const FPGATrackSimHit>>& hits,
58 std::vector<std::shared_ptr<const FPGATrackSimHit>>& firstHits,
59 std::vector<std::shared_ptr<const FPGATrackSimHit>>& secondHits,
60 std::vector<const FPGATrackSimHit*>& stripHits) {
61
62 const FPGATrackSimRegionMap* rmap_1st = m_FPGATrackSimMapping->SubRegionMap();
63 const FPGATrackSimRegionMap* rmap_2nd = m_FPGATrackSimMapping->SubRegionMap_2nd();
64
65 // NOTE: this now assumes that there is ONE "slice" for each of the three configurations (1st pixels,
66 // 2nd pixels, strips). the subregion map is NO LONGER USED.
67 if (m_rootOutput) {
70 m_slicedFirstPixelHeader->addTower(towerFirstPixel);
71 m_slicedSecondPixelHeader->addTower(towerSecondPixel);
72 }
73
74 // We need to process the strips into a header object no matter what.
76 m_slicedStripHeader->addTower(towerStrips);
77
78 // Loop over all of the hits. Test if they pass region boundaries or not.
79 for (const std::shared_ptr<const FPGATrackSimHit>& hit : hits) {
80 // If the hit falls within the boundaries of ANY subregion in the first or second stage,
81 // it's to be considered "IN REGION". Technically the second stage *should* be a superset
82 // of the first stage but let's be redundant to be safe here.
83 if ((rmap_1st->getRegions(*hit).size() == 0) && (rmap_2nd->getRegions(*hit).size() == 0)) {
84 continue;
85 }
86
87 // Test if the remaining hit is strip or pixel, sort accordingly.
88 // If doSecondStage is false, then all hits are first stage-- so don't worry about the layer map.
89 if (hit->isPixel()) {
90 // In this case, test using the layer map (if we are doing second stage).
91 if (!m_doSecondStage || m_layerMapModules.contains(hit->getIdentifierHash())) {
92 firstHits.push_back(hit);
93 if (m_rootOutput) m_slicedFirstPixelHeader->getTower(0)->addHit(*hit);
94 }
95 if (m_doSecondStage) {
96 secondHits.push_back(hit);
97 if (m_rootOutput) m_slicedSecondPixelHeader->getTower(0)->addHit(*hit);
98 }
99 } else {
100 // Strip hits need to be post-processed in LogicalHitsProcessAlg, so we only put them in a header here.
101 // Unfortunately this has to happen no matter what.
102 // Also populate stripHits vector with pointers to strip hits from the input collection
103 stripHits.push_back(hit.get());
104 m_slicedStripHeader->getTower(0)->addHit(*hit);
105 }
106 }
107
108 ATH_MSG_DEBUG("From " << hits.size() << " total input hits, sent " << firstHits.size() << " (" << secondHits.size() << ") to first (second) stage in region");
109}
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Maps ITK module indices to FPGATrackSim regions.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
std::vector< uint32_t > getRegions(const FPGATrackSimHit &hit) const
FPGATrackSimLogicalEventInputHeader * m_slicedSecondPixelHeader
Gaudi::Property< std::string > m_layerMap
FPGATrackSimLogicalEventInputHeader * m_slicedFirstPixelHeader
FPGATrackSimLogicalEventInputHeader * m_slicedStripHeader
FPGATrackSimSlicingEngineTool(const std::string &, const std::string &, const IInterface *)
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
void sliceHits(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, std::vector< std::shared_ptr< const FPGATrackSimHit > > &firstHits, std::vector< std::shared_ptr< const FPGATrackSimHit > > &secondHits, std::vector< const FPGATrackSimHit * > &stripHits)