ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
surface_descriptor.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/definitions/detail/qualifiers.hpp"
13#include "detray/definitions/geometry.hpp"
14#include "detray/definitions/indexing.hpp"
15#include "detray/geometry/identifier.hpp"
16
17// Sysytem include(s)
18#include <memory>
19
20namespace detray {
21
31template <typename mask_link_t = dtyped_index<dindex, dindex>,
32 typename material_link_t = dtyped_index<dindex, dindex>,
33 typename transform_link_t = dindex,
34 typename navigation_link_t = std::uint_least16_t>
36 public:
38 using navigation_link = navigation_link_t;
40 using transform_link = transform_link_t;
42 using mask_link = mask_link_t;
44 using mask_id = typename mask_link::id_type;
46 using material_link = material_link_t;
48 using material_id = typename material_link::id_type;
49
51 constexpr surface_descriptor() = default;
52
60 DETRAY_HOST
61 constexpr surface_descriptor(const transform_link trf, const mask_link mask,
63 const dindex volume, const surface_id sf_id)
64 : m_identifier{geometry::identifier{}
66 .set_id(sf_id)
67 .set_transform(trf)},
68 m_mask(mask),
69 m_material(material) {}
70
75 DETRAY_HOST_DEVICE
76 constexpr auto operator==(const surface_descriptor &rhs) const -> bool {
77 return (m_mask == rhs.m_mask && m_material == rhs.m_material &&
78 m_identifier == rhs.m_identifier);
79 }
80
83 DETRAY_HOST_DEVICE
84 auto set_identifier(const geometry::identifier geo_id) -> void {
85 m_identifier = geo_id;
86 }
87
89 DETRAY_HOST_DEVICE
90 constexpr auto identifier() const -> geometry::identifier {
91 return m_identifier;
92 }
93
96 DETRAY_HOST_DEVICE
97 auto set_id(const surface_id new_id) -> void { m_identifier.set_id(new_id); }
98
100 DETRAY_HOST_DEVICE
101 constexpr auto id() const -> surface_id { return m_identifier.id(); }
102
105 DETRAY_HOST
106 auto set_volume(const dindex new_idx) -> void {
107 m_identifier.set_volume(new_idx);
108 }
109
111 DETRAY_HOST_DEVICE
112 constexpr auto volume() const -> dindex { return m_identifier.volume(); }
113
116 DETRAY_HOST_DEVICE
117 auto set_index(const dindex new_idx) -> void {
118 m_identifier.set_index(new_idx);
119 }
120
122 DETRAY_HOST_DEVICE
123 constexpr auto index() const -> dindex { return m_identifier.index(); }
124
128 DETRAY_HOST
129 auto update_transform(dindex offset) -> void {
130 m_identifier.set_transform(transform() + offset);
131 }
132
134 DETRAY_HOST_DEVICE
135 constexpr auto transform() const -> dindex {
136 return m_identifier.transform();
137 }
138
142 DETRAY_HOST
143 auto update_mask(dindex offset) -> void { m_mask.shift(offset); }
144
146 DETRAY_HOST_DEVICE
147 constexpr auto mask() const -> const mask_link & { return m_mask; }
148
152 DETRAY_HOST
153 auto update_material(dindex offset) -> void { m_material.shift(offset); }
154
157 DETRAY_HOST_DEVICE
158 constexpr auto material() -> material_link & { return m_material; }
159
161 DETRAY_HOST_DEVICE
162 constexpr auto material() const -> const material_link & {
163 return m_material;
164 }
165
167 DETRAY_HOST_DEVICE
168 constexpr auto has_material() const -> bool {
169 return (m_material.id() != material_link::id_type::e_none) &&
170 !m_material.is_invalid();
171 }
172
174 DETRAY_HOST_DEVICE
175 constexpr auto is_sensitive() const -> bool {
176 return m_identifier.id() == surface_id::e_sensitive;
177 }
178
180 DETRAY_HOST_DEVICE
181 constexpr auto is_portal() const -> bool {
182 return m_identifier.id() == surface_id::e_portal;
183 }
184
186 DETRAY_HOST_DEVICE
187 constexpr auto is_passive() const -> bool {
188 return m_identifier.id() == surface_id::e_passive;
189 }
190
192 DETRAY_HOST
193 friend std::ostream &operator<<(std::ostream &os,
194 const surface_descriptor &sf) {
195 os << sf.m_identifier;
196 os << " | mask: " << sf.m_mask;
197 os << " | mat.: " << sf.m_material;
198 return os;
199 }
200
201 private:
202 geometry::identifier m_identifier{};
203 mask_link m_mask{};
204 material_link m_material{};
205};
206
207} // namespace detray
208
209namespace std {
210
211// Specialize std::hash so surface descriptors can be used in STL containers
212template <typename mask_link_t, typename material_link_t,
213 typename transform_link_t, typename navigation_link_t>
214struct hash<detray::surface_descriptor<mask_link_t, material_link_t,
215 transform_link_t, navigation_link_t>> {
216 using descr_t =
217 detray::surface_descriptor<mask_link_t, material_link_t, transform_link_t,
218 navigation_link_t>;
219
220 auto operator()(const descr_t sf_desc) const noexcept {
221 return std::hash<detray::geometry::identifier::value_t>()(
222 sf_desc.identifier().value());
223 }
224};
225
226} // namespace std
Unique identifier for geometry objects, based on the ACTS GeometryIdentifier.
Definition identifier.hpp:36
constexpr surface_descriptor()=default
Default constructor.
typename mask_link::id_type mask_id
Identifier type of the linked mask.
Definition surface_descriptor.hpp:44
auto set_identifier(const geometry::identifier geo_id) -> void
Sets a new surface identifier.
Definition surface_descriptor.hpp:84
auto update_transform(dindex offset) -> void
Update the transform index.
Definition surface_descriptor.hpp:129
auto update_mask(dindex offset) -> void
Update the mask link.
Definition surface_descriptor.hpp:143
navigation_link_t navigation_link
Link type of the mask to a volume.
Definition surface_descriptor.hpp:38
auto update_material(dindex offset) -> void
Update the material link.
Definition surface_descriptor.hpp:153
constexpr auto has_material() const -> bool
Definition surface_descriptor.hpp:168
constexpr auto volume() const -> dindex
Definition surface_descriptor.hpp:112
friend std::ostream & operator<<(std::ostream &os, const surface_descriptor &sf)
Definition surface_descriptor.hpp:193
constexpr auto is_sensitive() const -> bool
Definition surface_descriptor.hpp:175
constexpr surface_descriptor(const transform_link trf, const mask_link mask, const material_link material, const dindex volume, const surface_id sf_id)
Constructor with full arguments.
Definition surface_descriptor.hpp:61
constexpr auto material() const -> const material_link &
Definition surface_descriptor.hpp:162
transform_link_t transform_link
Broadcast the type of links.
Definition surface_descriptor.hpp:40
constexpr auto operator==(const surface_descriptor &rhs) const -> bool
Equality operator.
Definition surface_descriptor.hpp:76
constexpr auto material() -> material_link &
Definition surface_descriptor.hpp:158
auto set_id(const surface_id new_id) -> void
Definition surface_descriptor.hpp:97
constexpr auto is_portal() const -> bool
Definition surface_descriptor.hpp:181
typename material_link::id_type material_id
Identifier type of the linked material.
Definition surface_descriptor.hpp:48
auto set_volume(const dindex new_idx) -> void
Definition surface_descriptor.hpp:106
constexpr auto identifier() const -> geometry::identifier
Definition surface_descriptor.hpp:90
constexpr auto index() const -> dindex
Definition surface_descriptor.hpp:123
material_link_t material_link
Link type used to locate the surface material.
Definition surface_descriptor.hpp:46
constexpr auto id() const -> surface_id
Definition surface_descriptor.hpp:101
constexpr auto transform() const -> dindex
Definition surface_descriptor.hpp:135
mask_link_t mask_link
might be a single mask, a range of masks or a multiindex in the future
Definition surface_descriptor.hpp:42
constexpr auto is_passive() const -> bool
Definition surface_descriptor.hpp:187
auto set_index(const dindex new_idx) -> void
Sets a new surface index (index in surface collection of surface store).
Definition surface_descriptor.hpp:117
constexpr auto mask() const -> const mask_link &
Definition surface_descriptor.hpp:147
Detray include(s).
Definition array_operators.hpp:18
unsigned int dindex
Default index type.
Definition indexing.hpp:18
surface_id
surface type, resolved during navigation.
Definition geometry.hpp:41