ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
build_telescope_detector.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/cuboid_portal_generator.hpp"
13#include "detray/builders/detector_builder.hpp"
14#include "detray/builders/homogeneous_material_builder.hpp"
15#include "detray/builders/homogeneous_material_generator.hpp"
16#include "detray/builders/homogeneous_volume_material_builder.hpp"
17#include "detray/core/detector.hpp"
18#include "detray/definitions/algebra.hpp"
19#include "detray/definitions/units.hpp"
20#include "detray/detectors/telescope_metadata.hpp"
21#include "detray/geometry/mask.hpp"
22#include "detray/material/predefined_materials.hpp"
23#include "detray/tracks/trajectories.hpp"
24#include "detray/utils/consistency_checker.hpp"
25#include "detray/utils/print_detector.hpp"
26
27// Detray test include(s)
28#include "detray/test/common/factories/telescope_generator.hpp"
29
30// Vecmem include(s)
31#include <vecmem/memory/memory_resource.hpp>
32
33// System include(s)
34#include <algorithm>
35#include <limits>
36#include <memory>
37#include <vector>
38
39namespace detray {
40
42template <concepts::algebra algebra_t, typename mask_shape_t = rectangle2D,
43 template <typename> class trajectory_t = detail::ray>
47
52 const trajectory_t<algebra_t> &t = {})
53 : m_mask(m), m_trajectory(t) {
54 // Configure the material generation
55 m_material_config.sensitive_material(silicon_tml<scalar_t>())
56 .passive_material(vacuum<scalar_t>())
57 .portal_material(vacuum<scalar_t>())
58 .thickness(80.f * unit<scalar_t>::um);
59 }
60
64 explicit tel_det_config(const std::vector<scalar_t> &params,
65 const trajectory_t<algebra_t> &t = {})
66 : tel_det_config(mask<mask_shape_t, algebra_t>{params, 0u}, t) {}
67
70 template <typename... Args>
71 requires(std::is_same_v<Args, scalar_t> && ...)
72 explicit tel_det_config(Args &&...args)
74 mask<mask_shape_t, algebra_t>{0u, std::forward<Args>(args)...}) {}
75
79 unsigned int m_n_surfaces{10u};
83 std::vector<scalar_t> m_positions{};
89 trajectory_t<algebra_t> m_trajectory{};
93 volume_builder_options m_builder_opts{.m_deduplicate = false,
94 .m_sort = false};
95
96 bool m_do_check{true};
97
105 m_mask = m;
106 return *this;
107 }
108
111 constexpr tel_det_config &n_surfaces(const unsigned int n) {
112 m_n_surfaces = n;
113 return *this;
114 }
115
118 constexpr tel_det_config &length(const scalar_t l) {
119 assert((l > 0.f) && "Telescope detector length must be greater than zero");
120 m_length = l;
121 return *this;
122 }
123
126 constexpr tel_det_config &positions(const std::vector<scalar_t> &dists) {
127 m_positions.clear();
128 std::ranges::copy_if(dists, std::back_inserter(m_positions),
129 [](scalar_t d) { return (d >= 0.f); });
130 return *this;
131 }
132
136 m_material_config.sensitive_material(mat);
137 return *this;
138 }
139
143 m_volume_material = mat;
144 return *this;
145 }
146
150 assert(t >= 0.f && "Material thickness must be non-negative");
151 m_material_config.thickness(t);
152 return *this;
153 }
154
157 constexpr tel_det_config &pilot_track(const trajectory_t<algebra_t> &traj) {
158 m_trajectory = traj;
159 return *this;
160 }
161
164 constexpr tel_det_config &envelope(const scalar_t e) {
165 assert(e > 0.f && "Portal envelope must be greater than zero");
166 m_envelope = e;
167 return *this;
168 }
169
175 tel_det_config &do_check(const bool check) {
176 m_do_check = check;
177 return *this;
178 }
179
180
186 return m_mask;
187 }
188
190 constexpr unsigned int n_surfaces() const { return m_n_surfaces; }
193 constexpr scalar_t length() const { return m_length; }
196 const std::vector<scalar_t> &positions() const { return m_positions; }
199 constexpr const auto &material_config() const { return m_material_config; }
202 constexpr auto &material_config() { return m_material_config; }
205 constexpr const material<scalar_t> &module_material() const {
206 return m_material_config.sensitive_material();
207 }
208
210 constexpr const material<scalar_t> &volume_material() const {
211 return m_volume_material;
212 }
213
215 constexpr scalar_t mat_thickness() const {
216 return m_material_config.thickness();
217 }
218
220 const trajectory_t<algebra_t> &pilot_track() const { return m_trajectory; }
223 constexpr scalar_t envelope() const { return m_envelope; }
227 return m_builder_opts;
228 }
229
231 bool do_check() const { return m_do_check; }
233};
234
236template <concepts::algebra algebra_t, typename shape_t,
237 template <typename> class trajectory_t>
238DETRAY_HOST_DEVICE tel_det_config(const mask<shape_t, algebra_t> &,
239 const trajectory_t<algebra_t> &)
241
254template <concepts::algebra algebra_t, typename mask_shape_t = rectangle2D,
255 template <typename> class trajectory_t = detail::ray>
257 vecmem::memory_resource &resource,
260 20.f * unit<dscalar<algebra_t>>::mm,
261 20.f * unit<dscalar<algebra_t>>::mm}) {
262 using scalar_t = dscalar<algebra_t>;
263 using metadata_t = telescope_metadata<algebra_t, mask_shape_t>;
264 using builder_t = detector_builder<metadata_t, volume_builder>;
265 using detector_t = typename builder_t::detector_type;
266
267 builder_t det_builder;
268 det_builder.set_name("telescope_detector");
269
270 // Create an empty cuboid volume
271 auto v_builder = det_builder.new_volume(volume_id::e_cuboid);
272 v_builder->set_name("telescope_world_0");
273
274 // Identity transform (volume is centered at origin)
275 v_builder->add_volume_placement();
276
277 // Add module surfaces to volume
278 using telescope_factory =
279 telescope_generator<detector_t, mask_shape_t, trajectory_t<algebra_t>>;
280 std::unique_ptr<surface_factory_interface<detector_t>> tel_generator;
281
282 if (cfg.positions().empty()) {
283 // Automatically position the modules along pilot track
284 tel_generator = std::make_unique<telescope_factory>(
285 cfg.length(), cfg.n_surfaces(), cfg.module_mask().values(),
286 cfg.pilot_track());
287 } else {
288 // Put the modules in the requested portions along pilot track
289 tel_generator = std::make_unique<telescope_factory>(
290 cfg.positions(), cfg.module_mask().values(), cfg.pilot_track());
291 }
292
293 // Add homogeneous material description if a valid material was configured
294 volume_builder_interface<detector_t> *vm_builder{v_builder};
295 std::shared_ptr<surface_factory_interface<detector_t>> module_generator;
296
297 if (cfg.module_material() != detray::vacuum<scalar_t>{}) {
298 // Decorate the builders with homogeneous material
299 vm_builder =
300 det_builder.template decorate<homogeneous_material_builder<detector_t>>(
301 v_builder);
302
303 if (!vm_builder) {
304 throw std::runtime_error("Surface material decoration failed");
305 }
306
307 auto tel_mat_generator =
308 std::make_shared<homogeneous_material_generator<detector_t>>(
309 std::move(tel_generator), cfg.material_config());
310
311 module_generator = std::move(tel_mat_generator);
312
313 } else {
314 module_generator = std::move(tel_generator);
315 }
316
317 // Add a bounding box of portals to the cuboid volume
318 auto portal_generator =
319 std::make_shared<cuboid_portal_generator<detector_t>>(cfg.envelope());
320
321 vm_builder->add_surfaces(module_generator);
322 // (!) The portals must be added after the modules to fit them correctly
323 vm_builder->add_surfaces(portal_generator);
324
325 // TODO: Add brute force volume searcher
326
327 // If requested, add homogeneous volume material
328 if (cfg.volume_material() != detray::vacuum<scalar_t>{}) {
329 auto full_v_builder =
330 det_builder
331 .template decorate<homogeneous_volume_material_builder<detector_t>>(
332 vm_builder);
333
334 if (full_v_builder) {
335 full_v_builder->set_material(cfg.volume_material());
336 } else {
337 throw std::runtime_error("Volume material decoration failed");
338 }
339 }
340
341 // Build and return the detector and fill the name map
342 typename detector_t::name_map name_map{};
343 auto det = det_builder.build(resource, cfg.builder_options(), name_map);
344
345 if (cfg.do_check()) {
346 const bool verbose_check{false};
347 detray::detail::check_consistency(det, verbose_check, name_map);
348 }
349
350 DETRAY_DEBUG_HOST("\n" << detray::utils::print_detector(det, name_map));
351
352 return std::make_pair(std::move(det), std::move(name_map));
353}
354
355} // namespace detray
describes a straight-line trajectory
Definition ray.hpp:22
Mask a region on a surface and link it to a volume.
Definition mask.hpp:46
Geometrical shape of a rectangle2D.
Definition rectangle2D.hpp:30
Interface for volume builders (and volume builder decorators).
Definition volume_builder_interface.hpp:66
Algebra plugin concept.
Definition concepts.hpp:147
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
tel_det_config(const mask< shape_t, algebra_t > &, const trajectory_t< algebra_t > &) -> tel_det_config< algebra_t, shape_t, trajectory_t >
Deduce the type of telescope config.
auto build_telescope_detector(vecmem::memory_resource &resource, const tel_det_config< algebra_t, mask_shape_t, trajectory_t > &cfg=tel_det_config< algebra_t, mask_shape_t, trajectory_t >{ 20.f *unit< dscalar< algebra_t > >::mm, 20.f *unit< dscalar< algebra_t > >::mm})
Builds a detray geometry that contains only one volume with one type of surfaces.
Definition build_telescope_detector.hpp:256
Configuration for the homogeneous material generator.
Definition homogeneous_material_generator.hpp:33
Material composition properties and density data used by interactions.
Definition material.hpp:36
Map volume indices to volume names and vice versa.
Definition name_map.hpp:23
Predefined silicon material using TrackML bulk properties.
Definition predefined_materials.hpp:212
Configure the toy detector.
Definition build_telescope_detector.hpp:44
std::vector< scalar_t > m_positions
Concrete positions where to place the surfaces along the pilot track.
Definition build_telescope_detector.hpp:83
constexpr scalar_t length() const
Return the length.
Definition build_telescope_detector.hpp:193
constexpr tel_det_config & positions(const std::vector< scalar_t > &dists)
Set the positions.
Definition build_telescope_detector.hpp:126
constexpr tel_det_config & mat_thickness(const scalar_t t)
Set the mat thickness.
Definition build_telescope_detector.hpp:149
constexpr tel_det_config & pilot_track(const trajectory_t< algebra_t > &traj)
Set the pilot track.
Definition build_telescope_detector.hpp:157
unsigned int m_n_surfaces
No. of test surfaces in the telescope.
Definition build_telescope_detector.hpp:79
constexpr const material< scalar_t > & volume_material() const
Return the volume material.
Definition build_telescope_detector.hpp:210
constexpr scalar_t mat_thickness() const
Return the mat thickness.
Definition build_telescope_detector.hpp:215
hom_material_config< scalar_t > m_material_config
Configuration for the homogeneous material generator.
Definition build_telescope_detector.hpp:85
constexpr const mask< mask_shape_t, algebra_t > & module_mask() const
Getters.
Definition build_telescope_detector.hpp:185
tel_det_config & do_check(const bool check)
Set the do check.
Definition build_telescope_detector.hpp:175
constexpr tel_det_config & n_surfaces(const unsigned int n)
Set the n surfaces.
Definition build_telescope_detector.hpp:111
constexpr tel_det_config & module_material(const material< scalar_t > &mat)
Set the module material.
Definition build_telescope_detector.hpp:135
volume_builder_options & builder_options()
Return the builder options.
Definition build_telescope_detector.hpp:171
volume_builder_options m_builder_opts
Volume builder configuration.
Definition build_telescope_detector.hpp:93
constexpr tel_det_config & volume_material(const material< scalar_t > &mat)
Set the volume material.
Definition build_telescope_detector.hpp:142
constexpr tel_det_config & envelope(const scalar_t e)
Set the envelope.
Definition build_telescope_detector.hpp:164
mask< mask_shape_t, algebra_t > m_mask
Mask of the test surfaces.
Definition build_telescope_detector.hpp:77
constexpr unsigned int n_surfaces() const
Return the n surfaces.
Definition build_telescope_detector.hpp:190
scalar_t m_envelope
Safety envelope between the test surfaces and the portals.
Definition build_telescope_detector.hpp:91
const trajectory_t< algebra_t > & pilot_track() const
Return the pilot track.
Definition build_telescope_detector.hpp:220
constexpr tel_det_config & module_mask(const mask< mask_shape_t, algebra_t > &m)
Setters.
Definition build_telescope_detector.hpp:103
tel_det_config(const std::vector< scalar_t > &params, const trajectory_t< algebra_t > &t={})
Construct from from mask parameter vector.
Definition build_telescope_detector.hpp:64
scalar_t m_length
Length of the telescope.
Definition build_telescope_detector.hpp:81
const volume_builder_options & builder_options() const
Return the builder options.
Definition build_telescope_detector.hpp:226
tel_det_config(const mask< mask_shape_t, algebra_t > &m, const trajectory_t< algebra_t > &t={})
Construct from existing mask.
Definition build_telescope_detector.hpp:51
trajectory_t< algebra_t > m_trajectory
Pilot track along which to place the surfaces.
Definition build_telescope_detector.hpp:89
constexpr const auto & material_config() const
Return the material config.
Definition build_telescope_detector.hpp:199
constexpr const material< scalar_t > & module_material() const
Return the module material.
Definition build_telescope_detector.hpp:205
constexpr tel_det_config & length(const scalar_t l)
Set the length.
Definition build_telescope_detector.hpp:118
bool m_do_check
Run detector consistency check after reading.
Definition build_telescope_detector.hpp:96
material< scalar_t > m_volume_material
Material for volume.
Definition build_telescope_detector.hpp:87
constexpr auto & material_config()
Return the material configuration.
Definition build_telescope_detector.hpp:202
const std::vector< scalar_t > & positions() const
Return the positions.
Definition build_telescope_detector.hpp:196
bool do_check() const
Return the do check.
Definition build_telescope_detector.hpp:231
constexpr scalar_t envelope() const
Return the envelope.
Definition build_telescope_detector.hpp:223
dscalar< algebra_t > scalar_t
Scalar type used by this configuration.
Definition build_telescope_detector.hpp:46
Unit conversion factors.
Definition units.hpp:22
static constexpr scalar_t um
Length, native unit mm.
Definition units.hpp:25
static constexpr scalar_t mm
Native length unit, the millimetre.
Definition units.hpp:27
Elements Declaration.
Definition predefined_materials.hpp:34
Options for the volume builder classes.
Definition volume_builder_interface.hpp:29