ATLAS Offline Software
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 
14 FPGATrackSimSlicingEngineTool::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);
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.
57 void 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);
93  }
94  if (m_doSecondStage) {
95  secondHits.push_back(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.
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 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
getMenu.algname
algname
Definition: getMenu.py:54
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthMsgStreamMacros.h
FPGATrackSimSlicingEngineTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimSlicingEngineTool.h:46
json
nlohmann::json json
Definition: HistogramDef.cxx:9
FPGATrackSimSlicingEngineTool::sliceHits
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)
Definition: FPGATrackSimSlicingEngineTool.cxx:57
FPGATrackSimSlicingEngineTool::m_slicedFirstPixelHeader
FPGATrackSimLogicalEventInputHeader * m_slicedFirstPixelHeader
Definition: FPGATrackSimSlicingEngineTool.h:54
FPGATrackSimTowerInputHeader.h
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1113
bin
Definition: BinsDiffFromStripMedian.h:43
FPGATrackSimSlicingEngineTool::m_layerMap
Gaudi::Property< std::string > m_layerMap
Definition: FPGATrackSimSlicingEngineTool.h:49
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
FPGATrackSimTowerInputHeader::addHit
void addHit(const FPGATrackSimHit &s)
Definition: FPGATrackSimTowerInputHeader.h:48
FPGATrackSimRegionMap.h
Maps ITK module indices to FPGATrackSim regions.
FPGATrackSimSlicingEngineTool::m_rootOutput
Gaudi::Property< bool > m_rootOutput
Definition: FPGATrackSimSlicingEngineTool.h:48
FPGATrackSimSlicingEngineTool::FPGATrackSimSlicingEngineTool
FPGATrackSimSlicingEngineTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimSlicingEngineTool.cxx:14
FPGATrackSimLogicalEventInputHeader::getTower
FPGATrackSimTowerInputHeader * getTower(size_t index)
Definition: FPGATrackSimLogicalEventInputHeader.h:39
FPGATrackSimSlicingEngineTool::m_slicedStripHeader
FPGATrackSimLogicalEventInputHeader * m_slicedStripHeader
Definition: FPGATrackSimSlicingEngineTool.h:56
FPGATrackSimSlicingEngineTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimSlicingEngineTool.cxx:18
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
FPGATrackSimLogicalEventInputHeader::addTower
void addTower(const FPGATrackSimTowerInputHeader &s)
Definition: FPGATrackSimLogicalEventInputHeader.h:38
FPGATrackSimRegionMap::getRegions
std::vector< uint32_t > getRegions(const FPGATrackSimHit &hit) const
Definition: FPGATrackSimRegionMap.cxx:284
FPGATrackSimSlicingEngineTool.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
FPGATrackSimSlicingEngineTool::readLayerMap
void readLayerMap()
Definition: FPGATrackSimSlicingEngineTool.cxx:25
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:82
FPGATrackSimSlicingEngineTool::m_slicedSecondPixelHeader
FPGATrackSimLogicalEventInputHeader * m_slicedSecondPixelHeader
Definition: FPGATrackSimSlicingEngineTool.h:55
FPGATrackSimRegionMap
Definition: FPGATrackSimRegionMap.h:62
FPGATrackSimSlicingEngineTool::m_layerMapModules
std::set< unsigned > m_layerMapModules
Definition: FPGATrackSimSlicingEngineTool.h:60
AthAlgTool
Definition: AthAlgTool.h:26
FPGATrackSimTowerInputHeader
Definition: FPGATrackSimTowerInputHeader.h:18
FPGATrackSimSlicingEngineTool::m_doSecondStage
Gaudi::Property< bool > m_doSecondStage
Definition: FPGATrackSimSlicingEngineTool.h:50