ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
barrel_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/algebra.hpp"
16#include "detray/definitions/detail/qualifiers.hpp"
17#include "detray/definitions/geometry.hpp"
18#include "detray/definitions/indexing.hpp"
19#include "detray/geometry/mask.hpp"
20#include "detray/geometry/shapes/rectangle2D.hpp"
21#include "detray/utils/logging.hpp"
22
23// System include(s)
24#include <algorithm>
25#include <cassert>
26#include <limits>
27
28namespace detray {
29
33template <concepts::scalar scalar_t>
36 scalar_t m_half_z{500.f * unit<scalar_t>::mm};
38 std::vector<scalar_t> m_mask_values{8.4f * unit<scalar_t>::mm,
39 36.f * unit<scalar_t>::mm};
40
41 scalar_t m_tilt_phi{0.14f};
43 scalar_t m_radius{32.f * unit<scalar_t>::mm};
49 std::pair<unsigned int, unsigned int> m_binning = {16u, 14u};
50
56 constexpr barrel_generator_config &half_length(const scalar_t hz) {
57 m_half_z = hz;
58 return *this;
59 }
60
63 barrel_generator_config &module_bounds(const std::vector<scalar_t> &bnds) {
64 m_mask_values.clear();
65 std::ranges::copy(bnds, std::back_inserter(m_mask_values));
66 return *this;
67 }
68
71 constexpr barrel_generator_config &tilt_phi(const scalar_t tilt) {
72 m_tilt_phi = tilt;
73 return *this;
74 }
75
78 constexpr barrel_generator_config &radius(const scalar_t r) {
79 m_radius = r;
80 return *this;
81 }
82
85 constexpr barrel_generator_config &radial_stagger(const scalar_t r_st) {
86 m_radial_stagger = r_st;
87 return *this;
88 }
89
92 constexpr barrel_generator_config &z_overlap(const scalar_t zo) {
93 m_z_overlap = zo;
94 return *this;
95 }
96
100 constexpr barrel_generator_config &binning(const unsigned int n_phi,
101 const unsigned int n_z) {
102 m_binning = {n_phi, n_z};
103 return *this;
104 }
105
109 const std::pair<unsigned int, const unsigned int> &binning) {
111 return *this;
112 }
113
114
119 constexpr scalar_t half_length() const { return m_half_z; }
122 const std::vector<scalar_t> &module_bounds() const { return m_mask_values; }
125 constexpr scalar_t tilt_phi() const { return m_tilt_phi; }
128 constexpr scalar_t radius() const { return m_radius; }
131 constexpr scalar_t radial_stagger() const { return m_radial_stagger; }
134 constexpr scalar_t z_overlap() const { return m_z_overlap; }
137 constexpr const auto &binning() const { return m_binning; }
139};
140
144template <concepts::detector detector_t, typename mask_shape_t = rectangle2D>
145class barrel_generator final : public surface_factory_interface<detector_t> {
146 using algebra_t = typename detector_t::algebra_type;
147 using scalar_t = dscalar<algebra_t>;
148 using transform3_t = dtransform3D<algebra_t>;
149 using point3_t = dpoint3D<algebra_t>;
150 using vector3_t = dvector3D<algebra_t>;
151
152 public:
154 DETRAY_HOST
156 : m_cfg{cfg} {}
157
159 DETRAY_HOST
160 auto size() const -> dindex override {
161 return static_cast<dindex>(m_cfg.binning().first * m_cfg.binning().second);
162 }
163
166 DETRAY_HOST
167 void clear() override { /*Do nothing*/ };
168 DETRAY_HOST
170 surface_data<detector_t> && /*unused*/) override { /*Do nothing*/ }
171 DETRAY_HOST
173 auto push_back(std::vector<surface_data<detector_t>> && /*unused*/)
174 -> void override { /*Do nothing*/ }
175
176
184 DETRAY_HOST
186 auto operator()(typename detector_t::volume_type &volume,
187 typename detector_t::surface_lookup_container &surfaces,
188 typename detector_t::transform_container &transforms,
189 typename detector_t::mask_container &masks,
190 typename detector_t::geometry_context ctx = {})
191 -> dindex_range override {
192 DETRAY_VERBOSE_HOST("Generate silicon tracker barrel modules...");
193 DETRAY_VERBOSE_HOST("-> Generate " << size() << " surfaces");
194
195 using surface_t = typename detector_t::surface_type;
196 using nav_link_t = typename surface_t::navigation_link;
197 using mask_link_t = typename surface_t::mask_link;
198 using material_link_t = typename surface_t::material_link;
199
200 const dindex surfaces_offset{static_cast<dindex>(surfaces.size())};
201 constexpr auto invalid_src_link{detail::invalid_value<std::uint64_t>()};
202
203 // The type id of the surface mask shape
204 constexpr auto mask_id{
205 types::id<typename detector_t::masks, mask<mask_shape_t, algebra_t>>};
206
207 // The material will be added in a later step
208 constexpr auto no_material{surface_t::material_id::e_none};
209
210 auto volume_idx{volume.index()};
211 // Modules link back to mother volume in navigation
212 const auto mask_volume_link{static_cast<nav_link_t>(volume_idx)};
213
214 // surface grid bins
215 const unsigned int n_phi_bins{m_cfg.binning().first};
216 const unsigned int n_z_bins{m_cfg.binning().second};
217
218 // module positions
219 std::vector<point3_t> mod_centers;
220 mod_centers.reserve(n_phi_bins * n_z_bins);
221
222 // prep work
223 const scalar_t phi_step{2.f * constant<scalar_t>::pi /
224 static_cast<scalar_t>(n_phi_bins)};
225 const scalar_t min_phi{-constant<scalar_t>::pi + 0.5f * phi_step};
226
227 // @TODO: Only work for rectangles
228 const scalar_t z_start{
229 -0.5f * static_cast<scalar_t>(n_z_bins - 1u) *
230 (2.f * m_cfg.module_bounds().at(1) - m_cfg.z_overlap())};
231 const scalar_t z_step{(math::fabs(z_start) - z_start) /
232 static_cast<scalar_t>(n_z_bins - 1)};
233
234 // loop over the z bins
235 for (unsigned int z_bin = 0u; z_bin < n_z_bins; ++z_bin) {
236 // prepare z and r
237 const scalar_t mod_z{z_start + static_cast<scalar_t>(z_bin) * z_step};
238 const scalar_t mod_r{
239 (z_bin % 2u) != 0u ? m_cfg.radius() - 0.5f * m_cfg.radial_stagger()
240 : m_cfg.radius() + 0.5f * m_cfg.radial_stagger()};
241
242 for (unsigned int phiBin = 0u; phiBin < n_phi_bins; ++phiBin) {
243 // calculate the current phi value
244 const scalar_t mod_phi{min_phi +
245 static_cast<scalar_t>(phiBin) * phi_step};
246 mod_centers.push_back(point3_t{mod_r * math::cos(mod_phi),
247 mod_r * math::sin(mod_phi), mod_z});
248 }
249 }
250
251 // Create geometry data
252 for (auto &mod_center : mod_centers) {
253 // Surfaces with the linking into the local containers
254 mask_link_t mask_link = {mask_id, {masks.template size<mask_id>(), 1u}};
255 material_link_t material_link{no_material, dindex_invalid};
256 const auto trf_index = transforms.size(ctx);
257
258 surfaces.push_back({trf_index, mask_link, material_link, volume_idx,
259 surface_id::e_sensitive},
260 invalid_src_link);
261
262 // Build the transform
263 // The local phi
264 const scalar_t mod_phi{vector::phi(mod_center)};
265 // Local z axis is the normal vector
266 const scalar_t tilt_phi{m_cfg.tilt_phi()};
267 const vector3_t mod_local_z{math::cos(mod_phi + tilt_phi),
268 math::sin(mod_phi + tilt_phi),
269 static_cast<scalar_t>(0)};
270 // Local x axis the normal to local y,z
271 const vector3_t mod_local_x{-math::sin(mod_phi + tilt_phi),
272 math::cos(mod_phi + tilt_phi),
273 static_cast<scalar_t>(0)};
274
275 // Create the module transform
276 transforms.emplace_back(ctx, mod_center, mod_local_z, mod_local_x);
277 }
278
279 // Add the mask
280 masks.template emplace_back<mask_id>(empty_context{}, m_cfg.module_bounds(),
281 mask_volume_link);
282
283 return {surfaces_offset, static_cast<dindex>(surfaces.size())};
284 }
285
286 private:
288 barrel_generator_config<scalar_t> m_cfg{};
289};
290
291} // namespace detray
void clear() override
This is a surface generator, no external surface data needed.
Definition barrel_generator.hpp:167
void push_back(surface_data< detector_t > &&) override
Add data to the factory.
Definition barrel_generator.hpp:169
auto size() const -> dindex override
Definition barrel_generator.hpp:160
barrel_generator(const barrel_generator_config< scalar_t > &cfg)
Build a barrel layer according to the parameters given in.
Definition barrel_generator.hpp:155
auto push_back(std::vector< surface_data< detector_t > > &&) -> void override
Ignore supplied surface data because this factory generates its own.
Definition barrel_generator.hpp:173
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 pixel tracker barrel layer.
Definition barrel_generator.hpp:186
Bind transform and mask data together for surface building.
Definition surface_factory_interface.hpp:37
virtual dindex size() const =0
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
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
configuration for the barrel module generator
Definition barrel_generator.hpp:34
scalar_t m_z_overlap
Module overlap in z.
Definition barrel_generator.hpp:47
constexpr barrel_generator_config & binning(const std::pair< unsigned int, const unsigned int > &binning)
Set the binning.
Definition barrel_generator.hpp:108
constexpr barrel_generator_config & radius(const scalar_t r)
Set the radius.
Definition barrel_generator.hpp:78
constexpr scalar_t half_length() const
Getters.
Definition barrel_generator.hpp:119
constexpr scalar_t radius() const
Return the radius.
Definition barrel_generator.hpp:128
constexpr barrel_generator_config & tilt_phi(const scalar_t tilt)
Set the tilt phi.
Definition barrel_generator.hpp:71
constexpr scalar_t z_overlap() const
Return the z overlap.
Definition barrel_generator.hpp:134
constexpr barrel_generator_config & binning(const unsigned int n_phi, const unsigned int n_z)
Set the binning.
Definition barrel_generator.hpp:100
constexpr scalar_t radial_stagger() const
Return the radial stagger.
Definition barrel_generator.hpp:131
constexpr scalar_t tilt_phi() const
Return the tilt phi.
Definition barrel_generator.hpp:125
scalar_t m_radial_stagger
Radial module stagger.
Definition barrel_generator.hpp:45
const std::vector< scalar_t > & module_bounds() const
Return the module bounds.
Definition barrel_generator.hpp:122
scalar_t m_radius
Layer radius.
Definition barrel_generator.hpp:43
constexpr barrel_generator_config & half_length(const scalar_t hz)
Setters.
Definition barrel_generator.hpp:56
constexpr barrel_generator_config & z_overlap(const scalar_t zo)
Set the z overlap.
Definition barrel_generator.hpp:92
constexpr barrel_generator_config & radial_stagger(const scalar_t r_st)
Set the radial stagger.
Definition barrel_generator.hpp:85
scalar_t m_half_z
Half length of the barrel (z).
Definition barrel_generator.hpp:36
barrel_generator_config & module_bounds(const std::vector< scalar_t > &bnds)
Set the module bounds.
Definition barrel_generator.hpp:63
constexpr const auto & binning() const
Return the binning.
Definition barrel_generator.hpp:137
scalar_t m_tilt_phi
Phi tilt for modules.
Definition barrel_generator.hpp:41
std::pair< unsigned int, unsigned int > m_binning
Number of modules in phi and z.
Definition barrel_generator.hpp:49
std::vector< scalar_t > m_mask_values
Boundary values for the module masks.
Definition barrel_generator.hpp:38
static constexpr scalar_t pi
π
Definition units.hpp:136
static constexpr scalar_t mm
Native length unit, the millimetre.
Definition units.hpp:27