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
61 const FPGATrackSimRegionMap* rmap_1st = m_FPGATrackSimMapping->SubRegionMap();
62 const FPGATrackSimRegionMap* rmap_2nd = m_FPGATrackSimMapping->SubRegionMap_2nd();
63
64 // NOTE: this now assumes that there is ONE "slice" for each of the three configurations (1st pixels,
65 // 2nd pixels, strips). the subregion map is NO LONGER USED.
66 if (m_rootOutput) {
69 m_slicedFirstPixelHeader->addTower(towerFirstPixel);
70 m_slicedSecondPixelHeader->addTower(towerSecondPixel);
71 }
72
73 // We need to process the strips into a header object no matter what.
75 m_slicedStripHeader->addTower(towerStrips);
76
77 // Loop over all of the hits. Test if they pass region boundaries or not.
78 for (const std::shared_ptr<const FPGATrackSimHit>& hit : hits) {
79 // If the hit falls within the boundaries of ANY subregion in the first or second stage,
80 // it's to be considered "IN REGION". Technically the second stage *should* be a superset
81 // of the first stage but let's be redundant to be safe here.
82 if ((rmap_1st->getRegions(*hit).size() == 0) && (rmap_2nd->getRegions(*hit).size() == 0)) {
83 continue;
84 }
85
86 // Test if the remaining hit is strip or pixel, sort accordingly.
87 // If doSecondStage is false, then all hits are first stage-- so don't worry about the layer map.
88 if (hit->isPixel()) {
89 // In this case, test using the layer map (if we are doing second stage).
90 if (!m_doSecondStage || m_layerMapModules.contains(hit->getIdentifierHash())) {
91 firstHits.push_back(hit);
92 if (m_rootOutput) m_slicedFirstPixelHeader->getTower(0)->addHit(*hit);
93 }
94 if (m_doSecondStage) {
95 secondHits.push_back(hit);
96 if (m_rootOutput) m_slicedSecondPixelHeader->getTower(0)->addHit(*hit);
97 }
98 } else {
99 // Strip hits need to be post-processed in LogicalHitsProcessAlg, so we only put them in a header here.
100 // Unfortunately this has to happen no matter what.
101 m_slicedStripHeader->getTower(0)->addHit(*hit);
102 }
103 }
104
105 ATH_MSG_DEBUG("From " << hits.size() << " total input hits, sent " << firstHits.size() << " (" << secondHits.size() << ") to first (second) stage in region");
106}
#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
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)
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