21 return StatusCode::SUCCESS;
27StatusCode
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)
42 return StatusCode::SUCCESS;
47 for (
const auto& edge : edges) {
58 boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> g(
m_unique_nodes.size());
66 std::vector<int> components(num_vertices(g), -1);
67 m_component.resize(num_vertices(g), std::vector<int>(1,-1));
70 for (
size_t i = 0; i != components.size(); ++i){
85 boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> g(
m_unique_nodes.size());
93 std::unordered_map<Vertex, std::vector<Vertex>> pred_map;
95 std::vector<bool> visited(num_vertices(g),
false);
98 m_component.resize(num_vertices(g), std::vector<int>(1, -1));
101 for (
Vertex v = 0; v < num_vertices(g); ++v){
102 if(!visited[v] && boost::in_degree(v,g) == 0){
105 std::vector<boost::default_color_type> color_storage(num_vertices(g));
106 auto color_map = boost::make_iterator_property_map(color_storage.begin(),
get(boost::vertex_index,g));
109 breadth_first_search(g, v, visitor(JA_vis).color_map(color_map));
111 for (
unsigned long u = 0; u != num_vertices(g); ++u){
132 const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & gnn_hits,
133 std::vector<std::shared_ptr<const FPGATrackSimRoad>> & roads)
139 for (
size_t i = 0; i <
m_labels.size(); i++) {
140 for (
auto& current_label :
m_labels[i]){
141 if(current_label != -1) {
148 else {
addRoad(hits, hit_list); }
158 std::vector<std::shared_ptr<const FPGATrackSimHit>> mapped_road_hits;
162 for (
const auto& hitID : road_hitIDs) {
163 if(hitID+1 <
static_cast<int>(hits.size()) && hits[hitID]->isStrip() && hits[hitID+1]->isStrip() &&
164 to_string(hits[hitID]->getHitType()) ==
"spacepoint" &&
to_string(hits[hitID+1]->getHitType()) ==
"spacepoint" &&
165 hits[hitID]->getX() == hits[hitID+1]->getX()) {
166 auto &hit1 = hits[hitID];
167 std::shared_ptr<FPGATrackSimHit> hitCopy1 = std::make_shared<FPGATrackSimHit>(*hit1);
168 pmap->
map(*hitCopy1);
169 hitLayers |= 1 << hitCopy1->getLayer();
170 mapped_road_hits.push_back(std::move(hitCopy1));
172 auto &hit2 = hits[hitID+1];
173 std::shared_ptr<FPGATrackSimHit> hitCopy2 = std::make_shared<FPGATrackSimHit>(*hit2);
174 pmap->
map(*hitCopy2);
175 hitLayers |= 1 << hitCopy2->getLayer();
176 mapped_road_hits.push_back(std::move(hitCopy2));
179 auto &hit = hits[hitID];
180 std::shared_ptr<FPGATrackSimHit> hitCopy = std::make_shared<FPGATrackSimHit>(*hit);
182 hitLayers |= 1 << hitCopy->getLayer();
183 mapped_road_hits.push_back(std::move(hitCopy));
191 r.setHitLayers(hitLayers);
192 r.setHits(std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>>(std::move(sorted_hits)));
198 std::vector<std::shared_ptr<const FPGATrackSimHit>> all_hits;
199 std::vector<std::shared_ptr<const FPGATrackSimHit>> track_hit_list;
201 for (
const auto& hitID : road_hitIDs) {
202 auto &hit = hits[hitID];
203 all_hits.push_back(hit);
207 std::sort(all_hits.begin(), all_hits.end(),
208 [](
const std::shared_ptr<const FPGATrackSimHit>& hit1,
209 const std::shared_ptr<const FPGATrackSimHit>& hit2) {
210 double rho1 = std::hypot(hit1->getX(), hit1->getY());
211 double rho2 = std::hypot(hit2->getX(), hit2->getY());
216 std::unordered_set<int> seenLayers;
217 for (
const auto &hit : all_hits) {
218 short layer =
m_pix_h2l->at(
static_cast<int>(hit->getIdentifierHash()));
220 int combinedId = layerGeometry.
m_subdet;
222 if (seenLayers.count(combinedId) == 0) {
223 track_hit_list.push_back(hit);
224 seenLayers.insert(combinedId);
228 std::size_t nSp = track_hit_list.size();
229 std::vector<std::vector<std::shared_ptr<const FPGATrackSimHit>>> seed_hit_list;
235 auto spacePointIndicesFun = [](std::size_t nSp, std::size_t nSeeds) -> std::vector<std::size_t> {
236 std::vector<std::size_t> idx;
238 for (std::size_t i = 0; i < nSeeds; ++i) {
239 std::size_t pos = (i * (nSp - 1)) / (nSeeds - 1);
240 if (idx.empty() || idx.back() != pos) {
249 std::size_t nSeeds = std::min<std::size_t>(5, nSp);
250 auto indices = spacePointIndicesFun(nSp, nSeeds);
252 for (
auto idx : indices) {
253 seed_hit_list.push_back({track_hit_list[idx]});
258 r.setHits(std::move(seed_hit_list));
292 std::unordered_map<
Vertex, std::vector<Vertex>>& in_pred_map,
ColorMap in_cmap) :
296template <
typename VertexT,
typename GraphT>
305template <
typename EdgeT,
typename GraphT>
308 auto src_node = source(e,g);
309 auto tar_node = target(e,g);
314 if ((
get(
m_color_map, tar_node) == boost::black_color) && (boost::out_degree(tar_node, g) > 0)){
315 m_control_vars[tar_node] = boost:: out_degree(tar_node,g) < 2 ? 1 : -2;
316 auto out_edges = boost::out_edges(tar_node, g);
317 for (
auto it = out_edges.first; it != out_edges.second; ++ it){
318 Vertex next_dst = target(*it, g);
324template <
typename VertexT,
typename GraphT>
326 std::vector<int> src_comp;
331 src_comp.push_back(comp);
338 m_control_vars[tar_node] = boost::out_degree(tar_node, g) < 2 ? 1 : -2;
344 m_control_vars[tar_node] = boost::out_degree(tar_node, g) < 2 ? 1 : -2;
354 m_control_vars[tar_node] = boost::out_degree(tar_node, g) < 2 ? 1 : -2;
356 std::unordered_set<Vertex> visited;
358 if(visited.count(
node))
return;
359 visited.insert(
node);
361 if((std::find(node_comps.begin(), node_comps.end(),
m_current_comp) == node_comps.end()) &&
362 (src_comp.empty() || std::find(node_comps.begin(), node_comps.end(), src_comp[i]) != node_comps.end())){
#define ATH_CHECK
Evaluate an expression and check for errors.
std::vector< std::vector< std::shared_ptr< const FPGATrackSimHit > > > sortByLayer(Container const &hits)
Maps physical layers to logical layers.
void map(FPGATrackSimHit &hit) const
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 ¤t, 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)
std::vector< int > & m_control_vars
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.