ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
telescope_generator.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/surface_factory_interface.hpp"
13#include "detray/core/concepts.hpp"
14#include "detray/core/detail/data_context.hpp"
15#include "detray/definitions/detail/qualifiers.hpp"
16#include "detray/definitions/geometry.hpp"
17#include "detray/definitions/indexing.hpp"
18#include "detray/geometry/mask.hpp"
19#include "detray/geometry/shapes/rectangle2D.hpp"
20#include "detray/tracks/ray.hpp"
21#include "detray/utils/axis_rotation.hpp"
22#include "detray/utils/logging.hpp"
23#include "detray/utils/unit_vectors.hpp"
24
25// System include(s)
26#include <cassert>
27#include <limits>
28
29namespace detray {
30
34template <concepts::detector detector_t, typename mask_shape_t = rectangle2D,
35 typename trajectory_t =
37class telescope_generator final : public surface_factory_interface<detector_t> {
38 using algebra_t = typename detector_t::algebra_type;
39 using scalar_t = dscalar<algebra_t>;
40 using transform3_t = dtransform3D<algebra_t>;
41 using point3_t = dpoint3D<algebra_t>;
42 using vector3_t = dvector3D<algebra_t>;
43
44 public:
50 DETRAY_HOST
52 std::vector<scalar_t> positions,
54 trajectory_t traj)
55 : m_traj{traj},
56 m_positions{std::move(positions)},
57 m_boundaries{boundaries} {}
58
64 DETRAY_HOST
66 scalar_t length, std::size_t n_surfaces,
68 trajectory_t traj)
69 : m_traj{traj}, m_positions{}, m_boundaries{boundaries} {
70 scalar_t pos{0.f};
71 scalar_t dist{n_surfaces > 1u
72 ? length / static_cast<scalar_t>(n_surfaces - 1u)
73 : 0.f};
74 for (std::size_t i = 0u; i < n_surfaces; ++i) {
75 m_positions.push_back(pos);
76 pos += dist;
77 }
78 }
79
81 DETRAY_HOST
82 auto size() const -> dindex override {
83 return static_cast<dindex>(m_positions.size());
84 }
85
87 DETRAY_HOST
88 void clear() override {
89 m_positions.clear();
90 m_boundaries = {};
91 };
92
95 DETRAY_HOST
97 surface_data<detector_t> && /*unused*/) override { /*Do nothing*/ }
98 DETRAY_HOST
100 auto push_back(std::vector<surface_data<detector_t>> && /*unused*/)
101 -> void override { /*Do nothing*/ }
102
103
111 DETRAY_HOST
113 auto operator()(typename detector_t::volume_type &volume,
114 typename detector_t::surface_lookup_container &surfaces,
115 typename detector_t::transform_container &transforms,
116 typename detector_t::mask_container &masks,
117 typename detector_t::geometry_context ctx = {})
118 -> dindex_range override {
119 DETRAY_VERBOSE_HOST("Generate telescope modules...");
120 DETRAY_VERBOSE_HOST("-> Generate " << size() << " surfaces");
121
122 using surface_t = typename detector_t::surface_type;
123 using nav_link_t = typename surface_t::navigation_link;
124 using mask_link_t = typename surface_t::mask_link;
125 using material_link_t = typename surface_t::material_link;
126
127 const dindex surfaces_offset{static_cast<dindex>(surfaces.size())};
128 constexpr auto invalid_src_link{detail::invalid_value<std::uint64_t>()};
129
130 // The type id of the surface mask shape
131 constexpr auto mask_id{
132 types::id<typename detector_t::masks, mask<mask_shape_t, algebra_t>>};
133
134 // The material will be added in a later step
135 constexpr auto no_material{surface_t::material_id::e_none};
136
137 auto volume_idx{volume.index()};
138
139 // Create the module centers
140 const auto mod_placements = module_positions(m_traj, m_positions);
141
142 // Create geometry data
143 for (const auto &mod_placement : mod_placements) {
144 auto mask_volume_link{static_cast<nav_link_t>(volume_idx)};
145
146 // Surfaces with the linking into the local containers
147 mask_link_t mask_link{mask_id, masks.template size<mask_id>()};
148 material_link_t material_link{no_material, dindex_invalid};
149
150 const auto trf_index = transforms.size(ctx);
151 surfaces.push_back({trf_index, mask_link, material_link, volume_idx,
152 surface_id::e_sensitive},
153 invalid_src_link);
154
155 // The rectangle bounds for this module
156 masks.template emplace_back<mask_id>(empty_context{}, m_boundaries,
157 mask_volume_link);
158
159 // Build the transform
160 // Local z axis is the global normal vector
161 vector3_t m_local_z = vector::normalize(mod_placement.dir);
162
163 if constexpr (std::is_same_v<mask_shape_t, detray::line_square> ||
164 std::is_same_v<mask_shape_t, detray::line_circular>) {
165 // For a telescope with wires, rotate z axis 90
166 // degree around vector on x-y plane
167 auto curvi_u =
168 unit_vectors<vector3_t>().make_curvilinear_unit_u(m_local_z);
169 axis_rotation<algebra_t> axis_rot(curvi_u,
171 m_local_z = axis_rot(m_local_z);
172 }
173
174 // Local x axis is the curvilinear vector with respect to local_z
175 auto m_local_x =
176 unit_vectors<vector3_t>().make_curvilinear_unit_u(m_local_z);
177
178 // Create the global-to-local transform of the module
179 transforms.emplace_back(ctx, mod_placement.pos, m_local_z, m_local_x);
180 }
181
182 return {surfaces_offset, static_cast<dindex>(surfaces.size())};
183 }
184
185 private:
187 struct module_placement {
189 point3_t pos;
191 vector3_t dir;
192 };
193
201 inline std::vector<module_placement> module_positions(
202 const trajectory_t &traj, const std::vector<scalar_t> &steps) const {
203 // create and fill the module placements
204 std::vector<module_placement> placements;
205 placements.reserve(steps.size());
206
207 for (const auto s : steps) {
208 placements.push_back({traj.pos(s), traj.dir(s)});
209 }
210
211 return placements;
212 }
213
215 trajectory_t m_traj;
217 std::vector<scalar_t> m_positions;
220};
221
222} // namespace detray
describes a straight-line trajectory
Definition ray.hpp:22
Geometrical shape of a rectangle2D.
Definition rectangle2D.hpp:30
Bind transform and mask data together for surface building.
Definition surface_factory_interface.hpp:37
virtual dindex size() const =0
auto size() const -> dindex override
Definition telescope_generator.hpp:82
auto operator()(typename detector_t::volume_type &volume, typename detector_t::surface_lookup_container &surfaces, typename detector_t::transform_container &transforms, typename detector_t::mask_container &masks, typename detector_t::geometry_context ctx={}) -> dindex_range override
Create a surface telescope.
Definition telescope_generator.hpp:113
void clear() override
Clear the positions and boundaries of the surfaces.
Definition telescope_generator.hpp:88
auto push_back(std::vector< surface_data< detector_t > > &&) -> void override
Ignore supplied surface data because this factory generates its own.
Definition telescope_generator.hpp:100
telescope_generator(std::vector< scalar_t > positions, const darray< scalar_t, mask_shape_t::boundaries::e_size > &boundaries, trajectory_t traj)
Build a surface at every position along the pilot track with the given extent.
Definition telescope_generator.hpp:51
telescope_generator(scalar_t length, std::size_t n_surfaces, darray< scalar_t, mask_shape_t::boundaries::e_size > boundaries, trajectory_t traj)
Infer the sensitive surface placement from the telescope.
Definition telescope_generator.hpp:65
void push_back(surface_data< detector_t > &&) override
This is a surface generator, no external surface data needed.
Definition telescope_generator.hpp:96
Check if a type can be used as a detector.
Definition concepts.hpp:47
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
detail::index_range< dindex > dindex_range
Index ranges and sequences.
Definition indexing.hpp:24
unsigned int dindex
Default index type.
Definition indexing.hpp:18
constexpr dindex dindex_invalid
Global invalid index definition.
Definition indexing.hpp:21
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
get_vector3D_t< A, T > dvector3D
Three-dimensional vector type for algebra A and value type T.
Definition algebra.hpp:80
get_transform3D_t< A, T > dtransform3D
Three-dimensional transform type for algebra A and value type T.
Definition algebra.hpp:84
get_point3D_t< A, T > dpoint3D
Three-dimensional point type for algebra A and value type T.
Definition algebra.hpp:72
static constexpr scalar_t pi
π
Definition units.hpp:136