ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
surface_grid.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/definitions/algebra.hpp"
13#include "detray/utils/ranges.hpp"
14
15// Plugin include(s)
16#include "detray/plugins/svgtools/conversion/grid.hpp"
17
18// Actsvg include(s)
19#include "actsvg/core.hpp"
20#include "actsvg/display/geometry.hpp"
21#include "actsvg/meta.hpp"
22#include "actsvg/proto/volume.hpp"
23
24namespace detray::svgtools::meta::display {
25
38template <concepts::point3D point3_t, typename view_t>
39inline auto surface_grid(
40 const std::string& id,
41 const actsvg::proto::volume<std::vector<point3_t>>& p_volume,
42 const detray::svgtools::conversion::detail::grid_type& gr_type,
43 actsvg::svg::object& grid_svg, view_t view) {
44 // Only display grid, if the correct view is requested
45 if constexpr (std::is_same_v<view_t, actsvg::views::x_y>) {
46 if (gr_type != detray::svgtools::conversion::detail::grid_type::e_endcap) {
47 return actsvg::svg::object{};
48 }
49 } else if constexpr (std::is_same_v<view_t, actsvg::views::z_phi> ||
50 std::is_same_v<view_t, actsvg::views::z_rphi>) {
51 if (gr_type != detray::svgtools::conversion::detail::grid_type::e_barrel) {
52 return actsvg::svg::object{};
53 }
54 } else {
55 return actsvg::svg::object{};
56 }
57
58 if (p_volume._surfaces.empty()) {
59 DETRAY_DEBUG_HOST(
60 "-> No sensitive surfaces present - skipping surface grid");
61 return actsvg::svg::object{};
62 }
63
64 if (p_volume._grid_associations.empty()) {
65 DETRAY_DEBUG_HOST(
66 "-> No bin associations found between surfaces and grid - skipping "
67 "surface grid");
68 return actsvg::svg::object{};
69 }
70
71 // Draw the surface grid with bin highlighting
72 const auto& p_surfaces = p_volume._surfaces.front();
73 const auto& bin_associations = p_volume._grid_associations.front();
74
75 // Draw the volume sensitive surfaces
76 std::vector<actsvg::svg::object> sf_svgs;
77 for (const auto& p_surface : p_surfaces) {
78 std::string sf_id{p_surface._name + "_" + view._axis_names.at(0) +
79 view._axis_names.at(1)};
80 if constexpr (std::is_same_v<view_t, actsvg::views::z_rphi>) {
81 view._fixed_r = p_surface._radii.at(0u);
82 }
83 sf_svgs.push_back(
84 actsvg::display::surface(std::move(sf_id), p_surface, view));
85 }
86
87 DETRAY_VERBOSE_HOST("-> Drawing surface grid SVG...");
88
89 DETRAY_DEBUG_HOST("-> Found bin-surface associations for "
90 << bin_associations.size() << " bins:");
91 assert(!bin_associations.empty());
92
93 for ([[maybe_unused]] const auto& [gbin, assoc] :
94 detray::views::enumerate(bin_associations)) {
95 DETRAY_DEBUG_HOST("--> Glob bin: " << gbin);
96
97 for ([[maybe_unused]] const std::size_t sf_idx : assoc) {
98 DETRAY_DEBUG_HOST(" - surface " << sf_idx);
99 }
100 }
101
102 actsvg::svg::object sf_grid_svg;
103 sf_grid_svg._id = p_volume._name + "_surface_grid";
104 sf_grid_svg._tag = "g";
105
106 // Create the surface highlighting
107 actsvg::connectors::connect_action(grid_svg._sub_objects, sf_svgs,
108 bin_associations);
109
110 DETRAY_VERBOSE_HOST("--> Connected surfaces to grid bins");
111
112 sf_grid_svg.add_objects(sf_svgs);
113
114 DETRAY_VERBOSE_HOST("--> Added " << sf_svgs.size()
115 << " surfaces to grid SVG");
116
117 // Create the association info boxes
118 auto x_max = sf_grid_svg._x_range.at(1u);
119 for (auto [ig, g_tile] : detray::views::enumerate(grid_svg._sub_objects)) {
120 // Target surface text
121 std::vector<std::string> bin_text;
122 bin_text.push_back("Bin " + std::to_string(ig) + ":");
123
124 for (const auto [is, sis] :
125 detray::views::enumerate(bin_associations.at(ig))) {
126 const auto& p_surface = p_surfaces.at(sis);
127 std::string info{"- surface: " + std::to_string(sis)};
128 if (p_surface._aux_info.contains("center")) {
129 for (const auto& ci : p_surface._aux_info.at("center")) {
130 info += ci;
131 }
132 }
133 bin_text.push_back(info);
134 }
135 // Make the connected text
136 std::string ctext_id{id + "_ct_" + std::to_string(ig)};
137 auto ctext = actsvg::draw::connected_text(
138 ctext_id, {static_cast<actsvg::scalar>(1.1 * x_max), 0}, bin_text,
139 actsvg::style::font{}, actsvg::style::transform{}, g_tile);
140 sf_grid_svg.add_object(ctext);
141 }
142
143 // Add the grid
144 sf_grid_svg.add_object(grid_svg);
145
146 DETRAY_DEBUG_HOST("-> Surface grid SVG ID: " << sf_grid_svg._id);
147
148 return sf_grid_svg;
149}
150
151} // namespace detray::svgtools::meta::display