ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
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/grid_builder.hpp"
13#include "detray/builders/homogeneous_material_builder.hpp"
14#include "detray/builders/homogeneous_volume_material_builder.hpp"
15#include "detray/builders/material_map_builder.hpp"
16#include "detray/builders/volume_builder.hpp"
17#include "detray/core/concepts.hpp"
18#include "detray/core/detail/container_buffers.hpp"
19#include "detray/core/detail/container_views.hpp"
20#include "detray/core/detail/surface_lookup.hpp"
21#include "detray/core/name_map.hpp"
22#include "detray/definitions/algebra.hpp"
23#include "detray/definitions/containers.hpp"
24#include "detray/definitions/detail/qualifiers.hpp"
25#include "detray/geometry/volume_descriptor.hpp"
26#include "detray/utils/concepts.hpp"
27#include "detray/utils/print_detector.hpp"
28
29// Vecmem include(s)
30#include <vecmem/memory/memory_resource.hpp>
31
32// System include(s)
33#include <sstream>
34#include <string>
35#include <string_view>
36
37namespace detray {
38
39namespace detail {
42template <typename detector_t, concepts::transform3D transform3_t>
43void set_transform(detector_t &det, const transform3_t &trf, unsigned int i) {
44 DETRAY_WARN_HOST(
45 "Modifying transforms in the detector will be deprecated! "
46 "Please, use a separate geometry context in this case");
47 det._transforms.at(i) = trf;
48}
49
58template <concepts::metadata metadata_t, typename container_t>
59class detector {
60 // Allow the building of the detector containers
61 friend class detray::volume_builder<detector<metadata_t, container_t>>;
62 template <concepts::detector, concepts::grid, typename, typename>
63 friend class detray::grid_builder;
65 detector<metadata_t, container_t>>;
67 detector<metadata_t, container_t>>;
68 template <concepts::detector, std::size_t, typename>
73 detector<metadata_t, container_t> &,
75
77 template <typename T>
78 using vector_type = typename container_t::template vector_type<T>;
79
80 public:
83 using metadata = metadata_t;
84
87 using algebra_type = typename metadata::algebra_type;
98
102
107 using surface_type = typename metadata::surface_type;
109 using surface_container = vector_type<surface_type>;
111 using surface_lookup_container = surface_lookup<surface_type, vector_type>;
112
117 typename metadata::template transform_store<vector_type>;
119 using geometry_context = typename transform_container::context_type;
120
123 using mask_container = typename metadata::template mask_store<vector_type>;
125 using masks = typename mask_container::value_types;
126
130 typename metadata::template material_store<container_t>;
132 using material = typename material_container::value_types;
133
138 typename metadata::template accelerator_store<container_t>;
140 using accel = typename accelerator_container::value_types;
141
144 using geo_obj_ids = typename metadata::geo_objects;
146 using material_link = typename material_container::single_link;
148 using accel_link = typename accelerator_container::single_link;
152 using volume_container = vector_type<volume_type>;
153
157 dmulti_view<dvector_view<const volume_type>,
158 typename surface_lookup_container::const_view_type,
159 typename transform_container::const_view_type,
160 typename mask_container::const_view_type,
161 typename material_container::const_view_type,
162 typename accelerator_container::const_view_type>;
163
165
167
168 static_assert(concepts::device_view<view_type>,
169 "Detector view type ill-formed");
170 static_assert(concepts::device_view<const_view_type>,
171 "Detector const view type ill-formed");
172
176 dmulti_buffer<dvector_buffer<volume_type>,
177 typename surface_lookup_container::buffer_type,
178 typename transform_container::buffer_type,
179 typename mask_container::buffer_type,
180 typename material_container::buffer_type,
181 typename accelerator_container::buffer_type>;
182
183 static_assert(concepts::device_buffer<buffer_type>,
184 "Detector buffer type ill-formed");
185
186 detector() = delete;
187 // The detector holds a lot of data and should never be copied
188 detector(const detector &) = delete;
189 detector &operator=(const detector &) = delete;
190
194 detector(detector &&) noexcept = default;
195
199 detector &operator=(detector &&other) noexcept = default;
200
203 DETRAY_HOST
204 explicit detector(vecmem::memory_resource &resource)
205 : _volumes(&resource),
206 _surfaces(resource),
207 _transforms(resource),
208 _masks(resource),
209 _materials(resource),
210 _accelerators(resource) {}
211
215 template <concepts::device_view detector_view_t>
216 DETRAY_HOST_DEVICE explicit detector(detector_view_t &det_data)
217 : _volumes(detray::detail::get<0>(det_data.m_view)),
218 _surfaces(detray::detail::get<1>(det_data.m_view)),
219 _transforms(detray::detail::get<2>(det_data.m_view)),
220 _masks(detray::detail::get<3>(det_data.m_view)),
221 _materials(detray::detail::get<4>(det_data.m_view)),
222 _accelerators(detray::detail::get<5>(det_data.m_view)) {}
223
224
228 std::string name(const name_map &names) const {
229 return names.get_detector_name();
230 }
231
233 DETRAY_HOST_DEVICE
234 inline auto volumes() const -> const vector_type<volume_type> & {
235 return _volumes;
236 }
237
241 DETRAY_HOST_DEVICE
242 inline const auto &volume(dindex volume_index) const {
243 return _volumes[volume_index];
244 }
245
250 DETRAY_HOST
251 inline const auto &volume(const std::string_view volume_name,
252 const name_map &names) const {
253 return _volumes.at(names.at(volume_name));
254 }
255
259 DETRAY_HOST_DEVICE
260 inline const auto &volume(const point3_type &p) const {
261 // Allow to call the volume search data structure
262 // TODO: Add volume accelerator builder
263 volume_type v_desc{};
264 v_desc.template set_accel_link<geo_obj_ids::e_volume>(
265 accel::id::e_volume_default, 0u);
266 tracking_volume world{*this, v_desc};
267
268 dindex volume_index{0u};
269 world.template visit_accelerator<geo_obj_ids::e_volume, volume_search>(
270 p, &volume_index);
271 return _volumes[volume_index];
272 }
273
278 DETRAY_HOST_DEVICE
279 inline const auto &portals() const {
280 // All portals are registered with the brute force search
281 return _accelerators.template get<accel::id::e_surface_brute_force>().all();
282 }
283
285 DETRAY_HOST_DEVICE
286 inline auto surfaces() const -> const surface_lookup_container & {
287 return _surfaces;
288 }
289
294 template <typename query_t>
295 DETRAY_HOST_DEVICE constexpr decltype(auto) surface(query_t &&q) const {
296 return _surfaces.search(std::forward<query_t>(q));
297 }
298
300 DETRAY_HOST_DEVICE
301 inline auto transform_store(const geometry_context & /*ctx*/ = {}) const
302 -> const transform_container & {
303 return _transforms;
304 }
305
307 DETRAY_HOST_DEVICE
308 inline auto mask_store() const -> const mask_container & { return _masks; }
309
311 DETRAY_HOST_DEVICE
312 inline auto material_store() const -> const material_container & {
313 return _materials;
314 }
315
317 DETRAY_HOST_DEVICE
318 inline auto accelerator_store() const -> const accelerator_container & {
319 return _accelerators;
320 }
321
323 DETRAY_HOST auto get_data() -> const_view_type {
324 return const_view_type{detray::get_data(std::as_const(_volumes)),
325 detray::get_data(std::as_const(_surfaces)),
326 detray::get_data(std::as_const(_transforms)),
327 detray::get_data(std::as_const(_masks)),
328 detray::get_data(std::as_const(_materials)),
329 detray::get_data(std::as_const(_accelerators))};
330 }
331
333 DETRAY_HOST auto get_data() const -> const_view_type {
334 return const_view_type{
335 detray::get_data(_volumes), detray::get_data(_surfaces),
336 detray::get_data(_transforms), detray::get_data(_masks),
337 detray::get_data(_materials), detray::get_data(_accelerators)};
338 }
339
340 private:
343 DETRAY_HOST
344 friend std::ostream &operator<<(std::ostream &os, const detector &d) {
345 os << utils::print_detector(d) << std::endl;
346 return os;
347 }
348
350 struct volume_search {
352 template <concepts::accelerator_collection accel_coll_t,
353 typename accel_index_t>
354 DETRAY_HOST_DEVICE inline void operator()(const accel_coll_t &coll,
355 const accel_index_t index,
356 const point3_type &p,
357 dindex *const result) const {
358 using accel_type = typename accel_coll_t::value_type;
359
361 const auto volume_accelerator = coll[index];
362
363 // Only one entry per bin
364 *result = volume_accelerator.search(p).value();
365 }
366 }
367 };
368
370 volume_container _volumes;
371
373 surface_lookup_container _surfaces;
374
376 transform_container _transforms;
377
379 mask_container _masks;
380
382 material_container _materials;
383
385 accelerator_container _accelerators;
386};
387
388} // namespace detail
389
390namespace host {
391
392template <concepts::metadata metadata_t>
393using detector = detray::detail::detector<metadata_t, host_container_types>;
394
395} // namespace host
396
397namespace device {
398
399template <concepts::metadata metadata_t>
400using detector =
401 detray::detail::detector<metadata_t, const_device_container_types>;
402
403} // namespace device
404
405template <typename T>
407
409template <concepts::metadata metadata_t>
410struct detector_traits<metadata_t> {
413 using metadata_type = metadata_t;
414
417 using host = detray::host::detector<metadata_type>;
418
421 using device = detray::device::detector<metadata_type>;
422
425 using view = typename host::const_view_type;
426
429 using buffer = typename host::buffer_type;
430};
431
433template <concepts::metadata metadata_t, typename container_t>
434struct detector_traits<detail::detector<metadata_t, container_t>> {
435 private:
437
438 public:
442 using host = typename T::host;
444 using device = typename T::device;
446 using view = typename T::view;
448 using buffer = typename T::buffer;
449};
450
453
455template <typename D>
457
459template <typename D>
461
463template <typename D>
465
467template <typename D>
469
471template <typename D>
473
475
476} // namespace detray
auto material_store() const -> const material_container &
Definition detector.hpp:312
friend void set_transform(detector< metadata_t, host_container_types > &, const dtransform3D< typename metadata_t::algebra_type > &, unsigned int)
constexpr decltype(auto) surface(query_t &&q) const
Definition detector.hpp:295
dtransform3D< algebra_type > transform3_type
Definition detector.hpp:97
vector_type< volume_type > volume_container
Definition detector.hpp:152
surface_lookup< surface_type, vector_type > surface_lookup_container
Definition detector.hpp:111
typename accelerator_container::value_types accel
Definition detector.hpp:140
dmulti_view< dvector_view< const volume_type >, typename surface_lookup_container::const_view_type, typename transform_container::const_view_type, typename mask_container::const_view_type, typename material_container::const_view_type, typename accelerator_container::const_view_type > const_view_type
Definition detector.hpp:156
auto get_data() -> const_view_type
Definition detector.hpp:323
typename metadata::template mask_store< vector_type > mask_container
Definition detector.hpp:123
typename material_container::single_link material_link
Definition detector.hpp:146
typename metadata::algebra_type algebra_type
Definition detector.hpp:87
typename accelerator_container::single_link accel_link
Definition detector.hpp:148
dmulti_buffer< dvector_buffer< volume_type >, typename surface_lookup_container::buffer_type, typename transform_container::buffer_type, typename mask_container::buffer_type, typename material_container::buffer_type, typename accelerator_container::buffer_type > buffer_type
Definition detector.hpp:175
auto volumes() const -> const vector_type< volume_type > &
Definition detector.hpp:234
typename metadata::geo_objects geo_obj_ids
Definition detector.hpp:144
auto mask_store() const -> const mask_container &
Definition detector.hpp:308
typename metadata::template material_store< host_container_types > material_container
Definition detector.hpp:129
typename metadata::template accelerator_store< host_container_types > accelerator_container
Definition detector.hpp:137
auto transform_store(const geometry_context &={}) const -> const transform_container &
Definition detector.hpp:301
const auto & portals() const
Definition detector.hpp:279
dpoint2D< algebra_type > point2_type
Definition detector.hpp:91
const auto & volume(const std::string_view volume_name, const name_map &names) const
Definition detector.hpp:251
typename metadata::surface_type surface_type
Definition detector.hpp:107
const auto & volume(const point3_type &p) const
Definition detector.hpp:260
friend std::ostream & operator<<(std::ostream &os, const detector &d)
Definition detector.hpp:344
std::string name(const name_map &names) const
Definition detector.hpp:228
dpoint3D< algebra_type > point3_type
Definition detector.hpp:93
dscalar< algebra_type > scalar_type
Definition detector.hpp:89
typename mask_container::value_types masks
Definition detector.hpp:125
detray::name_map name_map
Definition detector.hpp:101
volume_descriptor< geo_obj_ids, accel_link, material_link > volume_type
Definition detector.hpp:150
const_view_type view_type
Definition detector.hpp:166
dvector3D< algebra_type > vector3_type
Definition detector.hpp:95
auto surfaces() const -> const surface_lookup_container &
Definition detector.hpp:286
typename transform_container::context_type geometry_context
Definition detector.hpp:119
vector_type< surface_type > surface_container
Definition detector.hpp:109
typename metadata::template transform_store< vector_type > transform_container
Definition detector.hpp:116
typename material_container::value_types material
Definition detector.hpp:132
auto accelerator_store() const -> const accelerator_container &
Definition detector.hpp:318
auto get_data() const -> const_view_type
Definition detector.hpp:333
const auto & volume(dindex volume_index) const
Definition detector.hpp:242
detector(detector_view_t &det_data)
Definition detector.hpp:216
Build a grid of a certain shape.
Definition grid_builder.hpp:41
Build a volume containing surfaces with material.
Definition homogeneous_material_builder.hpp:32
Build a volume with homogeneous volume material.
Definition homogeneous_volume_material_builder.hpp:31
Build the material maps for a given volume.
Definition material_map_builder.hpp:47
Facade for a detray detector volume.
Definition tracking_volume.hpp:44
Provides basic functionality to build detector volumes.
Definition volume_builder.hpp:36
The detray detector volume descriptor.
Definition volume_descriptor.hpp:37
Concept for a collection of accelerator (data) that can be stored in the detector.
Definition concepts.hpp:51
Acceleration structure that contains volumes (volume indices).
Definition concepts.hpp:73
Detray include(s).
Definition array_operators.hpp:18
typename detector_traits< D >::buffer detector_buffer_t
Buffer type for transferring detector type D.
Definition detector.hpp:472
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
unsigned int dindex
Default index type.
Definition indexing.hpp:18
typename detector_traits< D >::view detector_view_t
Const view type for detector type D.
Definition detector.hpp:468
typename detector_traits< D >::device detector_device_t
Device detector type for metadata type D.
Definition detector.hpp:464
typename detector_traits< D >::metadata_type detector_metadata_t
Some predefined alias types.
Definition detector.hpp:456
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
get_point2D_t< A, T > dpoint2D
Two-dimensional point type for algebra A and value type T.
Definition algebra.hpp:68
typename detector_traits< D >::host detector_host_t
Host detector type for metadata type D.
Definition detector.hpp:460
typename T::buffer buffer
Device-transfer buffer type for detector data.
Definition detector.hpp:448
typename T::view view
Non-owning detector view type.
Definition detector.hpp:446
typename T::device device
Device detector type.
Definition detector.hpp:444
typename T::host host
Host detector type.
Definition detector.hpp:442
typename T::metadata_type metadata_type
Metadata type used to configure a detector.
Definition detector.hpp:440
typename host::buffer_type buffer
Buffer for a detector's data.
Definition detector.hpp:429
metadata_t metadata_type
Metadata type of the detector.
Definition detector.hpp:413
detray::host::detector< metadata_type > host
Host type of the detector.
Definition detector.hpp:417
detray::device::detector< metadata_type > device
Device type of the detector.
Definition detector.hpp:421
typename host::const_view_type view
View of the detector.
Definition detector.hpp:425
Definition detector.hpp:406
Map volume indices to volume names and vice versa.
Definition name_map.hpp:23
decltype(auto) at(dindex idx) const
Returns the name associated with a volume index.
Definition name_map.hpp:64
const std::string & get_detector_name() const
Definition name_map.hpp:31