ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
surface_material.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/builders/detail/radius_getter.hpp"
13#include "detray/core/concepts.hpp"
14#include "detray/geometry/surface.hpp"
15#include "detray/utils/grid/concepts.hpp"
16
17// Plugin include(s)
18#include "detray/plugins/svgtools/conversion/grid.hpp"
19#include "detray/plugins/svgtools/styling/styling.hpp"
20
21// Actsvg include(s)
22#include "actsvg/proto/surface.hpp"
23
24// System include(s)
25#include <algorithm>
26#include <iterator>
27
28namespace detray::svgtools::conversion {
29
39template <concepts::detector detector_t, typename view_t>
40auto material_grid(const detector_t& detector, const dindex index,
41 const view_t& view,
42 const styling::grid_style& style =
45
46 const auto& sf_desc = detector.surface(index);
47 const auto& link = sf_desc.material();
48
49 // Proactively calculate the reference radius for a cylinder grid
50 // (will only be used if the volume actually holds a barrel grid)
51 auto r =
52 detector.mask_store().template visit<detray::detail::outer_radius_getter>(
53 sf_desc.mask());
54
55 scalar_t cyl_ref_radius{0.f};
56 if (r.has_value()) {
57 cyl_ref_radius = *r;
58 }
59
60 return svgtools::conversion::grid(detector.material_store(), link, view,
61 cyl_ref_radius, style);
62}
63
73 template <typename mat_coll_t, typename index_t,
74 concepts::transform3D transform3_t>
75 DETRAY_HOST inline auto operator()(const mat_coll_t& mat_coll,
76 const index_t& index,
77 const transform3_t& /*unused*/) const {
78 using material_t = typename mat_coll_t::value_type;
79
80 std::vector<std::vector<actsvg::proto::material_slab>> m_matrix;
81
84 using loc_bin_idx_t = typename material_t::loc_bin_index;
85 using algebra_t = typename material_t::local_frame_type::algebra_type;
86
87 const auto material_map = mat_coll.at(index);
88
89 // Create the bin associations
90 dindex edges0 = material_map.template get_axis<0>().nbins();
91 dindex edges1 = material_map.template get_axis<1>().nbins();
92
93 // In the svg convention the phi axis has to be the second axis to
94 // loop over
95 constexpr bool is_cyl{
96 std::is_same_v<typename material_t::local_frame_type,
98 std::is_same_v<typename material_t::local_frame_type,
100 if constexpr (is_cyl) {
101 dindex tmp = edges0;
102 edges0 = edges1;
103 edges1 = tmp;
104 }
105
106 m_matrix.reserve(edges1);
107
108 // Material map is always 2-dimensional
109 for (dindex j = 0u; j < edges1; ++j) {
110 std::vector<actsvg::proto::material_slab> m_matrix_row;
111 m_matrix_row.reserve(edges1);
112
113 for (dindex i = 0u; i < edges0; ++i) {
114 loc_bin_idx_t bin_idx{i, j};
115 if constexpr (is_cyl) {
116 bin_idx = {j, i};
117 }
118
119 const auto& mat_slab = material_map.bin(bin_idx).ref();
120 const auto& mat = mat_slab.get_material();
121
122 actsvg::proto::material_slab p_mat_slab;
123 p_mat_slab._properties = {
124 static_cast<actsvg::scalar>(mat.X0()),
125 static_cast<actsvg::scalar>(mat.L0()),
126 static_cast<actsvg::scalar>(mat.Ar()),
127 static_cast<actsvg::scalar>(mat.Z()),
128 static_cast<actsvg::scalar>(mat.mass_density()),
129 static_cast<actsvg::scalar>(mat_slab.thickness())};
130
131 m_matrix_row.push_back(p_mat_slab);
132 }
133
134 m_matrix.push_back(std::move(m_matrix_row));
135 }
136 }
137
138 return m_matrix;
139 }
140};
141
150template <concepts::detector detector_t, typename view_t>
151auto surface_material(const detector_t& detector,
153 const view_t& view,
156 // Convert grid, if present
157 auto [p_grid, grid_type] = svgtools::conversion::material_grid(
158 detector, d_surface.index(), view, style._grid_style);
159
160 actsvg::proto::surface_material p_material;
161
162 // Create the surface material
163 if (p_grid.has_value()) {
164 // Fill material data
165 auto m_matrix = d_surface.template visit_material<material_converter>(
166 d_surface.transform({}));
167
168 p_material = {m_matrix, *p_grid};
169 p_material._material_ranges =
170 actsvg::proto::material_ranges(p_material._material_matrix);
171
172 svgtools::styling::apply_style(p_material, style);
173 }
174
175 return p_material;
176}
177
178} // namespace detray::svgtools::conversion
Facade for a detray detector surface.
Definition surface.hpp:36
constexpr auto transform(const context &ctx) const -> const transform3_type &
Definition surface.hpp:197
constexpr auto index() const -> dindex
Definition surface.hpp:124
Material map concept: Material grid.
Definition concepts.hpp:106
Material that can used for surfaces.
Definition concepts.hpp:111
Transform concept.
Definition concepts.hpp:126
const styling::grid_style grid_style
Grid style used by the Tableau detector and volumes.
Definition styling.hpp:305
const styling::surface_material_style material_style
Material annotation and gradient style using the viridis scale.
Definition styling.hpp:272
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
grid< algebra_t, axes< shape_t >, bins::single< material_slab< dscalar< algebra_t > > >, simple_serializer, container_t, owning > material_map
Definition of binned material.
Definition material_map.hpp:29
unsigned int dindex
Default index type.
Definition indexing.hpp:18
Projection into a 2D concentric cylindrical frame (No rotation in coordinate transformation).
Definition concentric_cylindrical2D.hpp:21
Projection into a 2D cylindrical coordinate frame.
Definition cylindrical2D.hpp:20
A functor to fill the material proto grid with proto material slabs.
Definition surface_material.hpp:65
auto operator()(const mat_coll_t &mat_coll, const index_t &index, const transform3_t &) const
Convert one material-map entry to the proto material grid matrix.
Definition surface_material.hpp:75
Style applied to an actsvg proto surface_material.
Definition styling.hpp:45