ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
ring2D.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/polar2D.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
34class ring2D {
35 public:
37 static constexpr std::string_view name = "ring2D";
38
40 enum boundaries : unsigned int {
41 e_inner_r = 0u,
42 e_outer_r = 1u,
43 e_size = 2u,
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 = 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[0] - bounds[e_inner_r]),
74 math::fabs(bounds[e_outer_r] - loc_p[0]));
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 the local cartesian frame
94 const dpoint3D<algebra_t> loc_p =
96
97 // Only check the radius
98 return check_boundaries(
99 bounds,
100 dpoint2D<algebra_t>{vector::perp(loc_p),
101 static_cast<dscalar<algebra_t>>(0.f)},
102 tol);
103 }
104
114 template <concepts::scalar scalar_t, concepts::point point_t>
115 DETRAY_HOST_DEVICE constexpr auto check_boundaries(
116 const bounds_type<scalar_t> &bounds, const point_t &loc_p,
117 const scalar_t tol = std::numeric_limits<scalar_t>::epsilon(),
118 const scalar_t /*edge_tol*/ = 0.f) const {
119 return ((loc_p[0] + tol) >= bounds[e_inner_r] &&
120 loc_p[0] <= (bounds[e_outer_r] + tol));
121 }
122
123
129 template <concepts::scalar scalar_t>
130 DETRAY_HOST_DEVICE constexpr scalar_t measure(
131 const bounds_type<scalar_t> &bounds) const {
132 return area(bounds);
133 }
134
140 template <concepts::scalar scalar_t>
141 DETRAY_HOST_DEVICE constexpr scalar_t area(
142 const bounds_type<scalar_t> &bounds) const {
143 return (bounds[e_outer_r] * bounds[e_outer_r] -
144 bounds[e_inner_r] * bounds[e_inner_r]) *
146 }
147
154 template <concepts::scalar scalar_t>
155 DETRAY_HOST_DEVICE constexpr bounds_type<scalar_t> merge(
156 const bounds_type<scalar_t> &bounds,
157 const bounds_type<scalar_t> &o_bounds) const {
158 bounds_type<scalar_t> new_bounds{};
159
160 new_bounds[e_inner_r] = math::min(bounds[e_inner_r], o_bounds[e_inner_r]);
161 new_bounds[e_outer_r] = math::max(bounds[e_outer_r], o_bounds[e_outer_r]);
162
163 return new_bounds;
164 }
165
175 template <concepts::algebra algebra_t>
176 DETRAY_HOST_DEVICE inline darray<dscalar<algebra_t>, 6> local_min_bounds(
177 const bounds_type<dscalar<algebra_t>> &bounds,
178 const dscalar<algebra_t> env =
179 std::numeric_limits<dscalar<algebra_t>>::epsilon()) const {
180 assert(env > 0.f);
181 const dscalar<algebra_t> r_bound{env + bounds[e_outer_r]};
182 return {-r_bound, -r_bound, -env, r_bound, r_bound, env};
183 }
184
186 template <concepts::algebra algebra_t>
187 DETRAY_HOST_DEVICE dpoint3D<algebra_t> centroid(
188 const bounds_type<dscalar<algebra_t>> & /*unused*/) const {
189 return {0.f, 0.f, 0.f};
190 }
191
198 template <concepts::algebra algebra_t>
200 const bounds_type<dscalar<algebra_t>> & /*unused*/,
201 dindex /*unused*/) const {
202 throw std::runtime_error("Vertex generation for rings is not implemented");
203 return {};
204 }
205
212 template <concepts::scalar scalar_t>
213 DETRAY_HOST constexpr bool check_consistency(
214 const bounds_type<scalar_t> &bounds, std::ostream &os) const {
215 constexpr auto tol{10.f * std::numeric_limits<scalar_t>::epsilon()};
216
217 if (math::signbit(bounds[e_inner_r]) || bounds[e_outer_r] < tol) {
218 os << "DETRAY ERROR (HOST): Radius must be in the range [0, "
219 "numeric_max)"
220 << std::endl;
221 return false;
222 }
223 if (bounds[e_inner_r] >= bounds[e_outer_r] ||
224 math::fabs(bounds[e_inner_r] - bounds[e_outer_r]) < tol) {
225 os << "DETRAY ERROR (HOST): Inner radius must be smaller outer "
226 "radius.";
227 return false;
228 }
229
230 return true;
231 }
232};
233
234} // namespace detray
Geometrical shape of a closed ring.
Definition ring2D.hpp:34
constexpr bool check_consistency(const bounds_type< scalar_t > &bounds, std::ostream &os) const
Check consistency of boundary values.
Definition ring2D.hpp:213
static constexpr std::string_view name
The name for this shape.
Definition ring2D.hpp:37
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 ring2D.hpp:71
static constexpr std::size_t dim
Dimension of the local coordinate system.
Definition ring2D.hpp:59
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=0.f) const
Definition ring2D.hpp:115
dvector< dpoint3D< algebra_t > > vertices(const bounds_type< dscalar< algebra_t > > &, dindex) const
Generate vertices in local cartesian frame.
Definition ring2D.hpp:199
constexpr scalar_t measure(const bounds_type< scalar_t > &bounds) const
Measure of the shape: Area.
Definition ring2D.hpp:130
boundaries
Indices describing the entries in the shape boundary array.
Definition ring2D.hpp:40
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 ring2D.hpp:176
constexpr scalar_t area(const bounds_type< scalar_t > &bounds) const
The area of a the shape.
Definition ring2D.hpp:141
darray< scalar_t, boundaries::e_size > bounds_type
Container definition for the shape boundary values.
Definition ring2D.hpp:48
bool_t result_type
Result type of a boundary check.
Definition ring2D.hpp:56
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 >=0.f) const
Check boundary values for a local point.
Definition ring2D.hpp:87
dpoint3D< algebra_t > centroid(const bounds_type< dscalar< algebra_t > > &) const
Definition ring2D.hpp:187
polar2D< algebra_t > local_frame_type
Local coordinate frame for boundary checks.
Definition ring2D.hpp:52
constexpr bounds_type< scalar_t > merge(const bounds_type< scalar_t > &bounds, const bounds_type< scalar_t > &o_bounds) const
Merge two ring/disc shapes.
Definition ring2D.hpp:155
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 polar coordinate frame.
Definition polar2D.hpp:20