ATLAS Offline Software
Loading...
Searching...
No Matches
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
16
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
35typedef 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);
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
112using ColorMap = boost::iterator_property_map<
113 std::vector<boost::default_color_type>::iterator,
114 boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS>, boost::vertex_index_t>::type>;
115
116class JunctionAwareVisitor : public boost::default_bfs_visitor
117{
118 public:
119 JunctionAwareVisitor(int& current, std::vector<int>& in_control_vars, std::vector<std::vector<int>>& in_comps,
120 std::unordered_map<Vertex, std::vector<Vertex>>& in_pred_map, ColorMap in_cmap);
121
122 template <typename VertexT, typename GraphT>
123 void discover_vertex(VertexT v, const GraphT& g);
124
125 template <typename EdgeT, typename GraphT>
126 void examine_edge(EdgeT e, const GraphT& g);
127
128 template <typename VertexT, typename GraphT>
129 void process_edges(VertexT src, VertexT tar, const GraphT& g);
130
131 private:
133 std::vector<int>& m_control_vars;
134 std::vector<std::vector<int>>& m_components;
135 std::unordered_map<Vertex, std::vector<Vertex>>& m_pred_map;
138 int m_n_iter = 1;
139};
140
141#endif // FPGATrackSimGNNRoadMakerTool_H
FPGATrackSim-specific class to represent an edge as a connection between two hits in the detector use...
FPGATrackSim-specific class to represent an hit in the detector used for GNN pattern recognition.
boost::graph_traits< boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS > >::vertex_descriptor Vertex
boost::iterator_property_map< std::vector< boost::default_color_type >::iterator, boost::property_map< boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS >, boost::vertex_index_t >::type > ColorMap
Defines a class for roads.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
void doScoreCut(const std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > &edges)
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)
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)
const std::vector< short > * m_pix_h2l
std::vector< FPGATrackSimRoad > m_roads
const std::vector< TrigInDetSiLayer > * m_layerGeometry
void addRoadForPixelSeed(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, const std::vector< int > &road_hitIDs)
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
void addRoad(const std::vector< std::shared_ptr< const FPGATrackSimHit > > &hits, const std::vector< int > &road_hitIDs)
FPGATrackSimGNNRoadMakerTool(const std::string &, const std::string &, const IInterface *)
std::vector< std::vector< int > > m_component
Gaudi::Property< std::string > m_roadMakerTool
std::vector< std::vector< int > > m_labels
ToolHandle< ITrigL2LayerNumberTool > m_layerNumberTool
std::vector< std::vector< int > > m_road_hit_list
virtual StatusCode initialize() override
std::unordered_map< Vertex, std::vector< Vertex > > & m_pred_map
void discover_vertex(VertexT v, const GraphT &g)
void examine_edge(EdgeT e, const GraphT &g)
std::vector< std::vector< int > > & m_components
void process_edges(VertexT src, VertexT tar, const GraphT &g)
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, ColorMap in_cmap)