ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
cylinder2D.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/algebra.hpp"
13#include "detray/definitions/containers.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15#include "detray/definitions/indexing.hpp"
16#include "detray/definitions/math.hpp"
17#include "detray/definitions/units.hpp"
18#include "detray/geometry/coordinates/cartesian3D.hpp"
19#include "detray/geometry/coordinates/cylindrical2D.hpp"
20#include "detray/geometry/detail/shape_utils.hpp"
21
22// System include(s)
23#include <limits>
24#include <ostream>
25#include <stdexcept>
26#include <string_view>
27
28namespace detray {
29
34 public:
36 static constexpr std::string_view name = "cylinder2D";
37
39 enum boundaries : unsigned int {
40 e_r = 0u,
41 e_lower_z = 1u,
42 e_upper_z = 2u,
43 e_size = 3u,
44 };
45
47 template <concepts::scalar scalar_t>
49
51 template <concepts::algebra algebra_t>
53
55 template <typename bool_t>
56 using result_type = detail::boundary_check_result<bool_t>;
57
59 static constexpr std::size_t dim{2u};
60
70 template <concepts::scalar scalar_t, concepts::point point_t>
71 DETRAY_HOST_DEVICE inline scalar_t min_dist_to_boundary(
72 const bounds_type<scalar_t> &bounds, const point_t &loc_p) const {
73 return math::min(math::fabs(loc_p[1] - bounds[e_lower_z]),
74 math::fabs(bounds[e_upper_z] - loc_p[1]));
75 }
76
86 template <concepts::algebra algebra_t>
87 DETRAY_HOST_DEVICE constexpr result_type<dbool<algebra_t>> check_boundaries(
88 const bounds_type<dscalar<algebra_t>> &bounds,
89 const dtransform3D<algebra_t> &trf, const dpoint3D<algebra_t> &glob_p,
90 const dscalar<algebra_t> tol =
91 std::numeric_limits<dscalar<algebra_t>>::epsilon(),
92 const dscalar<algebra_t> edge_tol = 0.f) const {
93 // Rotate to local cartesian
94 const auto loc_p = cartesian3D<algebra_t>::global_to_local(trf, glob_p, {});
95
96 // Only need the z-position for the check
97 return check_boundaries(
98 bounds,
99 dpoint2D<algebra_t>{static_cast<dscalar<algebra_t>>(0.f), loc_p[2]},
100 tol, edge_tol);
101 }
102
117 template <concepts::scalar scalar_t, concepts::point point_t>
118 DETRAY_HOST_DEVICE constexpr auto check_boundaries(
119 const bounds_type<scalar_t> &bounds, const point_t &loc_p,
120 const scalar_t tol = std::numeric_limits<scalar_t>::epsilon(),
121 const scalar_t edge_tol = 0.f) const {
122 auto inside_mask{((bounds[e_lower_z] - tol) <= loc_p[1] &&
123 loc_p[1] <= (bounds[e_upper_z] + tol))};
124
125 decltype(inside_mask) inside_edge{false};
126 if (detail::any_of(edge_tol > 0.f)) {
127 const scalar_t full_tol{tol + edge_tol};
128 inside_edge = ((bounds[e_lower_z] - full_tol) <= loc_p[1] &&
129 loc_p[1] <= (bounds[e_upper_z] + full_tol));
130 }
131
132 return result_type<decltype(inside_mask)>{inside_mask, inside_edge};
133 }
134
135
141 template <concepts::scalar scalar_t>
142 DETRAY_HOST_DEVICE constexpr scalar_t measure(
143 const bounds_type<scalar_t> &bounds) const {
144 return area(bounds);
145 }
146
152 template <concepts::scalar scalar_t>
153 DETRAY_HOST_DEVICE constexpr scalar_t area(
154 const bounds_type<scalar_t> &bounds) const {
155 return 2.f * constant<scalar_t>::pi * bounds[e_r] *
156 (bounds[e_upper_z] - bounds[e_lower_z]);
157 }
158
165 template <concepts::scalar scalar_t>
166 DETRAY_HOST_DEVICE constexpr bounds_type<scalar_t> merge(
167 const bounds_type<scalar_t> &bounds,
168 const bounds_type<scalar_t> &o_bounds) const {
169 bounds_type<scalar_t> new_bounds{};
170
171 new_bounds[e_r] = math::max(bounds[e_r], o_bounds[e_r]);
172 new_bounds[e_lower_z] = math::min(bounds[e_lower_z], o_bounds[e_lower_z]);
173 new_bounds[e_upper_z] = math::max(bounds[e_upper_z], o_bounds[e_upper_z]);
174
175 return new_bounds;
176 }
177
187 template <concepts::algebra algebra_t>
188 DETRAY_HOST_DEVICE inline darray<dscalar<algebra_t>, 6> local_min_bounds(
189 const bounds_type<dscalar<algebra_t>> &bounds,
190 const dscalar<algebra_t> env =
191 std::numeric_limits<dscalar<algebra_t>>::epsilon()) const {
192 assert(env > 0.f);
193
194 const dscalar<algebra_t> xy_bound{bounds[e_r] + env};
195 return {-xy_bound, -xy_bound, bounds[e_lower_z] - env,
196 xy_bound, xy_bound, bounds[e_upper_z] + env};
197 }
198
201 template <concepts::algebra algebra_t>
202 DETRAY_HOST_DEVICE dpoint3D<algebra_t> centroid(
203 const bounds_type<dscalar<algebra_t>> &bounds) const {
204 return {static_cast<dscalar<algebra_t>>(0.f),
205 static_cast<dscalar<algebra_t>>(0.f),
206 0.5f * (bounds[e_lower_z] + bounds[e_upper_z])};
207 }
208
215 template <concepts::algebra algebra_t>
217 const bounds_type<dscalar<algebra_t>> & /*unused*/,
218 dindex /*unused*/) const {
219 throw std::runtime_error(
220 "Vertex generation for cylinders is not implemented");
221 return {};
222 }
223
230 template <concepts::scalar scalar_t>
231 DETRAY_HOST constexpr bool check_consistency(
232 const bounds_type<scalar_t> &bounds, std::ostream &os) const {
233 constexpr auto tol{10.f * std::numeric_limits<scalar_t>::epsilon()};
234
235 if (bounds[e_r] < tol) {
236 os << "DETRAY ERROR (HOST): Radius must be in the range (0, "
237 "numeric_max)"
238 << std::endl;
239 return false;
240 }
241 if (bounds[e_lower_z] >= bounds[e_upper_z] ||
242 math::fabs(bounds[e_lower_z] - bounds[e_upper_z]) < tol) {
243 os << "DETRAY ERROR (HOST): Neg. half length must be smaller than "
244 "pos. half "
245 "length.";
246 return false;
247 }
248
249 return true;
250 }
251};
252
253} // namespace detray
Geometrical shape of a 2D cylinder.
Definition cylinder2D.hpp:33
cylindrical2D< algebra_t > local_frame_type
Local coordinate frame for boundary checks.
Definition cylinder2D.hpp:52
constexpr bool check_consistency(const bounds_type< scalar_t > &bounds, std::ostream &os) const
Check consistency of boundary values.
Definition cylinder2D.hpp:231
boundaries
Indices describing the entries in the shape boundary array.
Definition cylinder2D.hpp:39
constexpr auto check_boundaries(const bounds_type< scalar_t > &bounds, const point_t &loc_p, const scalar_t tol=std::numeric_limits< scalar_t >::epsilon(), const scalar_t edge_tol=0.f) const
Definition cylinder2D.hpp:118
dvector< dpoint3D< algebra_t > > vertices(const bounds_type< dscalar< algebra_t > > &, dindex) const
Generate vertices in local cartesian frame.
Definition cylinder2D.hpp:216
constexpr scalar_t area(const bounds_type< scalar_t > &bounds) const
The area of a the shape.
Definition cylinder2D.hpp:153
constexpr result_type< dbool< algebra_t > > check_boundaries(const bounds_type< dscalar< algebra_t > > &bounds, const dtransform3D< algebra_t > &trf, const dpoint3D< algebra_t > &glob_p, const dscalar< algebra_t > tol=std::numeric_limits< dscalar< algebra_t > >::epsilon(), const dscalar< algebra_t > edge_tol=0.f) const
Check boundary values for a local point.
Definition cylinder2D.hpp:87
darray< dscalar< algebra_t >, 6 > local_min_bounds(const bounds_type< dscalar< algebra_t > > &bounds, const dscalar< algebra_t > env=std::numeric_limits< dscalar< algebra_t > >::epsilon()) const
Lower and upper point for minimal axis aligned bounding box.
Definition cylinder2D.hpp:188
static constexpr std::string_view name
The name for this shape.
Definition cylinder2D.hpp:36
constexpr bounds_type< scalar_t > merge(const bounds_type< scalar_t > &bounds, const bounds_type< scalar_t > &o_bounds) const
Merge two 2D cylinder shapes.
Definition cylinder2D.hpp:166
darray< scalar_t, boundaries::e_size > bounds_type
Container definition for the shape boundary values.
Definition cylinder2D.hpp:48
scalar_t min_dist_to_boundary(const bounds_type< scalar_t > &bounds, const point_t &loc_p) const
Find the minimum distance to any boundary.
Definition cylinder2D.hpp:71
dpoint3D< algebra_t > centroid(const bounds_type< dscalar< algebra_t > > &bounds) const
Definition cylinder2D.hpp:202
static constexpr std::size_t dim
Dimension of the local coordinate system.
Definition cylinder2D.hpp:59
constexpr scalar_t measure(const bounds_type< scalar_t > &bounds) const
Measure of the shape: Area.
Definition cylinder2D.hpp:142
detail::boundary_check_result< bool_t > result_type
Result type of a boundary check.
Definition cylinder2D.hpp:56
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
vecmem::vector< value_t > dvector
Vector container backed by vecmem.
Definition containers.hpp:34
unsigned int dindex
Default index type.
Definition indexing.hpp:18
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
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
static loc_point global_to_local(const transform3_type &trf, const point3_type &p, const vector3_type &)
This method transforms a point from a global cartesian 3D frame to a local 3D cartesian point Convert...
Definition cartesian3D.hpp:57
static constexpr scalar_t pi
π
Definition units.hpp:136
Projection into a 2D cylindrical coordinate frame.
Definition cylindrical2D.hpp:20