ATLAS Offline Software
FPGATrackSimGNNRoadMakerTool.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 #ifndef FPGATrackSimGNNRoadMakerTool_H
4 #define FPGATrackSimGNNRoadMakerTool_H
5 
17 #include "GaudiKernel/ServiceHandle.h"
19 
24 #include <boost/graph/adjacency_list.hpp>
25 #include <boost/graph/connected_components.hpp>
26 #include <boost/graph/breadth_first_search.hpp>
28 
29 #include <memory>
30 #include <vector>
31 #include <map>
32 #include <unordered_map>
33 #include <set>
34 
35 typedef boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS>>::vertex_descriptor Vertex;
36 
38 {
39  public:
40 
42  // AthAlgTool
43 
44  FPGATrackSimGNNRoadMakerTool(const std::string&, const std::string&, const IInterface*);
45 
46  virtual StatusCode initialize() override;
47 
49  // Functions
50 
51  virtual StatusCode makeRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits,
52  const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & gnn_hits,
53  const std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges,
54  std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads);
55 
56  private:
57 
59  // Handles
60 
61  ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping {this, "FPGATrackSimMappingSvc", "FPGATrackSimMappingSvc"};
62  ToolHandle<ITrigL2LayerNumberTool> m_layerNumberTool{this, "LayerNumberTool", "TrigL2LayerNumberToolITk"};
63 
65  // Properties
66 
67  Gaudi::Property<float> m_edgeScoreCut { this, "edgeScoreCut", 0.0, "Cut value for edge scores to pass for road making algorithm" };
68  Gaudi::Property<std::string> m_roadMakerTool { this, "roadMakerTool", "", "Algorithm to perform graph segmentation into roads"};
69  Gaudi::Property<bool> m_doGNNPixelSeeding { this, "doGNNPixelSeeding", false, "Flag to configure for GNN Pixel Seeding" };
70 
72  // Convenience
73 
74  int m_num_nodes = 0;
75  std::vector<int> m_pass_edge_index_1{};
76  std::vector<int> m_pass_edge_index_2{};
77  unsigned m_nLayers = 0;
78  std::set<int> m_unique_nodes{};
79  std::map<int, int> m_node_index_map{};
80  std::vector<int> m_unique_indices{};
81  std::vector<int> m_control_var{};
82  std::vector<std::vector<int>> m_component{};
84  std::vector<std::vector<int>> m_labels{};
85  std::vector<std::vector<int>> m_road_hit_list{};
86  const std::vector<short>* m_pix_h2l{nullptr};
87  const std::vector<TrigInDetSiLayer>* m_layerGeometry{nullptr};
88 
90  // Helpers
91 
92  void doScoreCut(const std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
93  void doConnectedComponents();
94  void doJunctionAwareCC();
95  void addRoads(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits,
96  const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & gnn_hits,
97  std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads);
98  void addRoad(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, const std::vector<int>& road_hitIDs);
99  void addRoadForPixelSeed(const std::vector<std::shared_ptr<const FPGATrackSimHit>> & hits, const std::vector<int>& road_hitIDs);
100  void resetVectors();
101  void reorderIndices();
102 
104  // Event Storage
105 
106  std::vector<FPGATrackSimRoad> m_roads{};
107 };
108 
110 // Helper: Junctoin Aware BFS visitor
111 class JunctionAwareVisitor : public boost::default_bfs_visitor
112 {
113  public:
114  JunctionAwareVisitor(int& current, std::vector<int>& in_control_vars, std::vector<std::vector<int>>& in_comps,
115  std::unordered_map<Vertex, std::vector<Vertex>>& in_pred_map);
116 
117  template <typename VertexT, typename GraphT>
118  void discover_vertex(VertexT v, const GraphT& g);
119 
120  template <typename EdgeT, typename GraphT>
121  void examine_edge(EdgeT e, const GraphT& g);
122 
123  private:
125  std::vector<int>& m_control_vars;
126  std::vector<std::vector<int>>& m_components;
127  std::unordered_map<Vertex, std::vector<Vertex>>& m_pred_map;
129  int m_n_iter = 1;
130 };
131 
132 #endif // FPGATrackSimGNNRoadMakerTool_H
FPGATrackSimGNNRoadMakerTool::m_layerNumberTool
ToolHandle< ITrigL2LayerNumberTool > m_layerNumberTool
Definition: FPGATrackSimGNNRoadMakerTool.h:62
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
JunctionAwareVisitor::examine_edge
void examine_edge(EdgeT e, const GraphT &g)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:299
FPGATrackSimGNNRoadMakerTool::m_edgeScoreCut
Gaudi::Property< float > m_edgeScoreCut
Definition: FPGATrackSimGNNRoadMakerTool.h:67
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:124
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
JunctionAwareVisitor::m_current_comp
int & m_current_comp
Definition: FPGATrackSimGNNRoadMakerTool.h:124
FPGATrackSimGNNRoadMakerTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimGNNRoadMakerTool.cxx:13
FPGATrackSimGNNRoadMakerTool::m_roadMakerTool
Gaudi::Property< std::string > m_roadMakerTool
Definition: FPGATrackSimGNNRoadMakerTool.h:68
FPGATrackSimGNNRoadMakerTool::m_num_nodes
int m_num_nodes
Definition: FPGATrackSimGNNRoadMakerTool.h:74
FPGATrackSimGNNRoadMakerTool::addRoadForPixelSeed
void addRoadForPixelSeed(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, const std::vector< int > &road_hitIDs)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:189
IFPGATrackSimMappingSvc.h
FPGATrackSimGNNRoadMakerTool::doConnectedComponents
void doConnectedComponents()
Definition: FPGATrackSimGNNRoadMakerTool.cxx:55
FPGATrackSimGNNRoadMakerTool::m_pass_edge_index_2
std::vector< int > m_pass_edge_index_2
Definition: FPGATrackSimGNNRoadMakerTool.h:76
ITrigL2LayerNumberTool.h
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:27
FPGATrackSimGNNRoadMakerTool::m_doGNNPixelSeeding
Gaudi::Property< bool > m_doGNNPixelSeeding
Definition: FPGATrackSimGNNRoadMakerTool.h:69
FPGATrackSimGNNEdge.h
FPGATrackSim-specific class to represent an edge as a connection between two hits in the detector use...
FPGATrackSimGNNRoadMakerTool::m_unique_nodes
std::set< int > m_unique_nodes
Definition: FPGATrackSimGNNRoadMakerTool.h:78
JunctionAwareVisitor::m_initial_comp
int m_initial_comp
Definition: FPGATrackSimGNNRoadMakerTool.h:128
FPGATrackSimGNNRoadMakerTool::addRoad
void addRoad(const std::vector< std::shared_ptr< const FPGATrackSimHit >> &hits, const std::vector< int > &road_hitIDs)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:148
FPGATrackSimGNNRoadMakerTool::m_node_index_map
std::map< int, int > m_node_index_map
Definition: FPGATrackSimGNNRoadMakerTool.h:79
FPGATrackSimGNNRoadMakerTool::m_component
std::vector< std::vector< int > > m_component
Definition: FPGATrackSimGNNRoadMakerTool.h:82
JunctionAwareVisitor::discover_vertex
void discover_vertex(VertexT v, const GraphT &g)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:290
FPGATrackSimGNNRoadMakerTool::resetVectors
void resetVectors()
Definition: FPGATrackSimGNNRoadMakerTool.cxx:256
FPGATrackSimGNNRoadMakerTool::m_nLayers
unsigned m_nLayers
Definition: FPGATrackSimGNNRoadMakerTool.h:77
JunctionAwareVisitor
Definition: FPGATrackSimGNNRoadMakerTool.h:112
FPGATrackSimGNNRoadMakerTool::m_pix_h2l
const std::vector< short > * m_pix_h2l
Definition: FPGATrackSimGNNRoadMakerTool.h:86
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
AthAlgTool.h
JunctionAwareVisitor::m_control_vars
std::vector< int > & m_control_vars
Definition: FPGATrackSimGNNRoadMakerTool.h:125
FPGATrackSimGNNRoadMakerTool::m_pass_edge_index_1
std::vector< int > m_pass_edge_index_1
Definition: FPGATrackSimGNNRoadMakerTool.h:75
JunctionAwareVisitor::m_components
std::vector< std::vector< int > > & m_components
Definition: FPGATrackSimGNNRoadMakerTool.h:126
FPGATrackSimGNNRoadMakerTool
Definition: FPGATrackSimGNNRoadMakerTool.h:38
FPGATrackSimGNNRoadMakerTool::FPGATrackSimGNNRoadMakerTool
FPGATrackSimGNNRoadMakerTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:10
JunctionAwareVisitor::m_n_iter
int m_n_iter
Definition: FPGATrackSimGNNRoadMakerTool.h:129
JunctionAwareVisitor::JunctionAwareVisitor
JunctionAwareVisitor(int &current, std::vector< int > &in_control_vars, std::vector< std::vector< int >> &in_comps, std::unordered_map< Vertex, std::vector< Vertex >> &in_pred_map)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:284
FPGATrackSimGNNRoadMakerTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimGNNRoadMakerTool.h:61
FPGATrackSimGNNHit.h
FPGATrackSim-specific class to represent an hit in the detector used for GNN pattern recognition.
Vertex
boost::graph_traits< boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS > >::vertex_descriptor Vertex
Definition: FPGATrackSimGNNRoadMakerTool.h:35
JunctionAwareVisitor::m_pred_map
std::unordered_map< Vertex, std::vector< Vertex > > & m_pred_map
Definition: FPGATrackSimGNNRoadMakerTool.h:127
FPGATrackSimGNNRoadMakerTool::m_layerGeometry
const std::vector< TrigInDetSiLayer > * m_layerGeometry
Definition: FPGATrackSimGNNRoadMakerTool.h:87
python.PyAthena.v
v
Definition: PyAthena.py:154
FPGATrackSimGNNRoadMakerTool::reorderIndices
void reorderIndices()
Definition: FPGATrackSimGNNRoadMakerTool.cxx:268
FPGATrackSimGNNRoadMakerTool::m_road_hit_list
std::vector< std::vector< int > > m_road_hit_list
Definition: FPGATrackSimGNNRoadMakerTool.h:85
FPGATrackSimGNNRoadMakerTool::m_num_components
int m_num_components
Definition: FPGATrackSimGNNRoadMakerTool.h:83
FPGATrackSimGNNRoadMakerTool::doScoreCut
void doScoreCut(const std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNRoadMakerTool.cxx:45
FPGATrackSimGNNRoadMakerTool::m_roads
std::vector< FPGATrackSimRoad > m_roads
Definition: FPGATrackSimGNNRoadMakerTool.h:106
FPGATrackSimRoad.h
Defines a class for roads.
FPGATrackSimGNNRoadMakerTool::m_control_var
std::vector< int > m_control_var
Definition: FPGATrackSimGNNRoadMakerTool.h:81
AthAlgTool
Definition: AthAlgTool.h:26
FPGATrackSimGNNRoadMakerTool::m_unique_indices
std::vector< int > m_unique_indices
Definition: FPGATrackSimGNNRoadMakerTool.h:80
FPGATrackSimGNNRoadMakerTool::doJunctionAwareCC
void doJunctionAwareCC()
Definition: FPGATrackSimGNNRoadMakerTool.cxx:81
FPGATrackSimGNNRoadMakerTool::m_labels
std::vector< std::vector< int > > m_labels
Definition: FPGATrackSimGNNRoadMakerTool.h:84
ServiceHandle< IFPGATrackSimMappingSvc >