Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FPGATrackSimGNNRoadMakerTool.cxx
Go to the documentation of this file.
1 
2 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 
6 
8 // AthAlgTool
9 
10 FPGATrackSimGNNRoadMakerTool::FPGATrackSimGNNRoadMakerTool(const std::string& algname, const std::string &name, const IInterface *ifc)
11  : AthAlgTool(algname, name, ifc) {}
12 
14 {
15  ATH_CHECK(m_FPGATrackSimMapping.retrieve());
16  m_nLayers = m_FPGATrackSimMapping->PlaneMap_1st(0)->getNLogiLayers();
17 
18  return StatusCode::SUCCESS;
19 }
20 
22 // Functions
23 
24 StatusCode FPGATrackSimGNNRoadMakerTool::makeRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & gnn_hits, const std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges, std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads)
25 {
26  m_num_nodes = gnn_hits.size();
27  doScoreCut(edges);
28 
29  if(m_roadMakerTool == "ConnectedComponents") {
31  addRoads(hits, gnn_hits, roads);
32  }
33 
34  resetVectors();
35 
36  return StatusCode::SUCCESS;
37 }
38 
39 void FPGATrackSimGNNRoadMakerTool::doScoreCut(const std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges)
40 {
41  for (const auto& edge : edges) {
42  if(edge->getEdgeScore() > m_edgeScoreCut) {
43  m_pass_edge_index_1.push_back(edge->getEdgeIndex1());
44  m_pass_edge_index_2.push_back(edge->getEdgeIndex2());
45  }
46  }
47 }
48 
50 {
51  // Remove isolated nodes from list of nodes using list of edges and indices
54 
55  int index = 0;
56  for (int node : m_unique_nodes) {
57  m_node_index_map[node] = index++; // Mapping original node index to new graph index
58  }
59 
60  for (const auto& entry : m_node_index_map) {
61  m_unique_indices.push_back(entry.first); // Push the original node index into unique_indices
62  }
63 
64  m_Graph g(m_unique_nodes.size());
65 
66  for (size_t i = 0; i < m_pass_edge_index_1.size(); i++) {
69  add_edge(u, v, g); // Add the edge between the mapped node indices
70  }
71 
72  m_component.resize(num_vertices(g), -1);
73  m_num_components = boost::connected_components(g, &m_component[0]);
74 
75  m_labels.resize(m_num_nodes,-1);
76 
77  for (size_t i = 0; i < m_unique_indices.size(); i++) {
79  }
80 }
81 
82 void FPGATrackSimGNNRoadMakerTool::addRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits,
83  const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & gnn_hits,
84  std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads)
85 {
86  roads.clear();
87  m_roads.clear();
88 
90  for (size_t i = 0; i < m_labels.size(); i++) {
91  if(m_labels[i] != -1) {
92  m_road_hit_list[m_labels[i]].push_back(gnn_hits[i]->getHitID());
93  }
94  }
95 
96  for (const auto& hit_list : m_road_hit_list) {
97  // Temporarily do not make a road if it has more than 20 hits, there is an issue with some big roads which we do not want to work with right now.
98  if (hit_list.size() < 20) {
99  addRoad(hits, hit_list);
100  }
101  }
102 
103  roads.reserve(m_roads.size());
104  for (const FPGATrackSimRoad & r : m_roads) roads.emplace_back(std::make_shared<const FPGATrackSimRoad>(r));
105 }
106 
107 void FPGATrackSimGNNRoadMakerTool::addRoad(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, const std::vector<int>& road_hitIDs)
108 {
109  // Take the HitID values and find the correct hit from FPGATrackSimHit, then insert it into a vector of mapped FPGATrackSimHit which are needed for the FPGATrackSimRoad
110  std::vector<std::shared_ptr<const FPGATrackSimHit>> mapped_road_hits;
111  const FPGATrackSimPlaneMap *pmap = m_FPGATrackSimMapping->PlaneMap_1st(0);
112  layer_bitmask_t hitLayers = 0;
113 
114  for (const auto& hitID : road_hitIDs) {
115  if(hitID+1 < static_cast<int>(hits.size()) && hits[hitID]->isStrip() && hits[hitID+1]->isStrip() &&
116  to_string(hits[hitID]->getHitType()) == "spacepoint" && to_string(hits[hitID+1]->getHitType()) == "spacepoint" &&
117  hits[hitID]->getX() == hits[hitID+1]->getX()) {
118  auto &hit1 = hits[hitID];
119  std::shared_ptr<FPGATrackSimHit> hitCopy1 = std::make_shared<FPGATrackSimHit>(*hit1);
120  pmap->map(*hitCopy1);
121  hitLayers |= 1 << hitCopy1->getLayer();
122  mapped_road_hits.push_back(std::move(hitCopy1));
123  //
124  auto &hit2 = hits[hitID+1];
125  std::shared_ptr<FPGATrackSimHit> hitCopy2 = std::make_shared<FPGATrackSimHit>(*hit2);
126  pmap->map(*hitCopy2);
127  hitLayers |= 1 << hitCopy2->getLayer();
128  mapped_road_hits.push_back(std::move(hitCopy2));
129  }
130  else {
131  auto &hit = hits[hitID];
132  std::shared_ptr<FPGATrackSimHit> hitCopy = std::make_shared<FPGATrackSimHit>(*hit);
133  pmap->map(*hitCopy);
134  hitLayers |= 1 << hitCopy->getLayer();
135  mapped_road_hits.push_back(std::move(hitCopy));
136  }
137  }
138 
139  m_roads.emplace_back();
140  FPGATrackSimRoad & r = m_roads.back();
141  auto sorted_hits = ::sortByLayer(mapped_road_hits);
142  sorted_hits.resize(m_nLayers);
143  r.setRoadID(m_roads.size() - 1);
144  r.setHitLayers(hitLayers);
145  r.setHits(std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>>(std::move(sorted_hits)));
146  r.setSubRegion(0);
147 }
148 
150 {
151  m_pass_edge_index_1.clear();
152  m_pass_edge_index_2.clear();
153  m_unique_nodes.clear();
154  m_node_index_map.clear();
155  m_unique_indices.clear();
156  m_component.clear();
157  m_labels.clear();
158  m_road_hit_list.clear();
159 }
beamspotman.r
def r
Definition: beamspotman.py:676
FPGATrackSimGNNRoadMakerTool::m_edgeScoreCut
Gaudi::Property< float > m_edgeScoreCut
Definition: FPGATrackSimGNNRoadMakerTool.h:61
getMenu.algname
algname
Definition: getMenu.py:54
FPGATrackSimGNNRoadMakerTool::m_component
std::vector< int > m_component
Definition: FPGATrackSimGNNRoadMakerTool.h:75
FPGATrackSimGNNRoadMakerTool::addRoads
void addRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &gnn_hits, std::vector< std::shared_ptr< const FPGATrackSimRoad >> &roads)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:82
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
FPGATrackSimGNNRoadMakerTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimGNNRoadMakerTool.cxx:13
FPGATrackSimGNNRoadMakerTool::m_roadMakerTool
Gaudi::Property< std::string > m_roadMakerTool
Definition: FPGATrackSimGNNRoadMakerTool.h:62
FPGATrackSimGNNRoadMakerTool::m_num_nodes
int m_num_nodes
Definition: FPGATrackSimGNNRoadMakerTool.h:67
FPGATrackSimPlaneMap.h
Maps physical layers to logical layers.
index
Definition: index.py:1
FPGATrackSimGNNRoadMakerTool.h
Implements algorithm to construct a road from a list of hits using edge scores.
FPGATrackSimGNNRoadMakerTool::doConnectedComponents
void doConnectedComponents()
Definition: FPGATrackSimGNNRoadMakerTool.cxx:49
FPGATrackSimHit::getLayer
unsigned getLayer() const
Definition: FPGATrackSimHit.cxx:77
FPGATrackSimGNNRoadMakerTool::m_pass_edge_index_2
std::vector< int > m_pass_edge_index_2
Definition: FPGATrackSimGNNRoadMakerTool.h:69
FPGATrackSimGNNRoadMakerTool::makeRoads
virtual StatusCode makeRoads(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &gnn_hits, const std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges, std::vector< std::shared_ptr< const FPGATrackSimRoad >> &roads)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:24
FPGATrackSimGNNRoadMakerTool::m_unique_nodes
std::set< int > m_unique_nodes
Definition: FPGATrackSimGNNRoadMakerTool.h:71
FPGATrackSimGNNRoadMakerTool::addRoad
void addRoad(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, const std::vector< int > &road_hitIDs)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:107
FPGATrackSimGNNRoadMakerTool::m_node_index_map
std::map< int, int > m_node_index_map
Definition: FPGATrackSimGNNRoadMakerTool.h:72
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
FPGATrackSimGNNRoadMakerTool::resetVectors
void resetVectors()
Definition: FPGATrackSimGNNRoadMakerTool.cxx:149
FPGATrackSimGNNRoadMakerTool::m_nLayers
unsigned m_nLayers
Definition: FPGATrackSimGNNRoadMakerTool.h:70
FPGATrackSimGNNRoadMakerTool::m_labels
std::vector< int > m_labels
Definition: FPGATrackSimGNNRoadMakerTool.h:77
FPGATrackSimPlaneMap::map
void map(FPGATrackSimHit &hit) const
Definition: FPGATrackSimPlaneMap.cxx:234
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimGNNRoadMakerTool::m_pass_edge_index_1
std::vector< int > m_pass_edge_index_1
Definition: FPGATrackSimGNNRoadMakerTool.h:68
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PyPoolBrowser.node
node
Definition: PyPoolBrowser.py:131
FPGATrackSimGNNRoadMakerTool::FPGATrackSimGNNRoadMakerTool
FPGATrackSimGNNRoadMakerTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:10
FPGATrackSimPlaneMap
Definition: FPGATrackSimPlaneMap.h:62
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
FPGATrackSimGNNRoadMakerTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimGNNRoadMakerTool.h:56
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
python.PyAthena.v
v
Definition: PyAthena.py:154
FPGATrackSimGNNRoadMakerTool::m_road_hit_list
std::vector< std::vector< int > > m_road_hit_list
Definition: FPGATrackSimGNNRoadMakerTool.h:78
layer_bitmask_t
uint32_t layer_bitmask_t
Definition: FPGATrackSimTypes.h:22
FPGATrackSimGNNRoadMakerTool::m_num_components
int m_num_components
Definition: FPGATrackSimGNNRoadMakerTool.h:76
FPGATrackSimGNNRoadMakerTool::doScoreCut
void doScoreCut(const std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:39
FPGATrackSimGNNRoadMakerTool::m_roads
std::vector< FPGATrackSimRoad > m_roads
Definition: FPGATrackSimGNNRoadMakerTool.h:94
AthAlgTool
Definition: AthAlgTool.h:26
FPGATrackSimGNNRoadMakerTool::m_unique_indices
std::vector< int > m_unique_indices
Definition: FPGATrackSimGNNRoadMakerTool.h:73
FPGATrackSimGNNRoadMakerTool::m_Graph
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS > m_Graph
Definition: FPGATrackSimGNNRoadMakerTool.h:74
node
Definition: node.h:21
FPGATrackSimRoad
Definition: FPGATrackSimRoad.h:31
sortByLayer
std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit > > > sortByLayer(Container const &hits)
Definition: FPGATrackSimHit.h:297