ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
concentric_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/concentric_cylindrical2D.hpp"
19#include "detray/geometry/detail/shape_utils.hpp"
20
21// System include(s)
22#include <limits>
23#include <ostream>
24#include <stdexcept>
25#include <string_view>
26
27namespace detray {
28
33 public:
35 static constexpr std::string_view name = "concentric_cylinder2D";
36
38 enum boundaries : unsigned int {
39 e_r = 0u,
40 e_lower_z = 1u,
41 e_upper_z = 2u,
42 e_size = 3u,
43 };
44
46 template <concepts::scalar scalar_t>
48
50 template <concepts::algebra algebra_t>
52
54 template <typename bool_t>
55 using result_type = bool_t;
56
58 static constexpr std::size_t dim{2u};
59
69 template <concepts::scalar scalar_t, concepts::point point_t>
70 DETRAY_HOST_DEVICE inline scalar_t min_dist_to_boundary(
71 const bounds_type<scalar_t> &bounds, const point_t &loc_p) const {
72 return math::min(math::fabs(loc_p[1] - bounds[e_lower_z]),
73 math::fabs(bounds[e_upper_z] - loc_p[1]));
74 }
75
83 template <concepts::algebra algebra_t>
84 DETRAY_HOST_DEVICE constexpr result_type<dbool<algebra_t>> check_boundaries(
85 const bounds_type<dscalar<algebra_t>> &bounds,
86 const dtransform3D<algebra_t> & /*trf*/,
87 const dpoint3D<algebra_t> &glob_p,
88 const dscalar<algebra_t> tol =
89 std::numeric_limits<dscalar<algebra_t>>::epsilon(),
90 const dscalar<algebra_t> /*edge_tol*/ = 0.f) const {
91 // Only need the z-position for the check
92 return check_boundaries(
93 bounds,
94 dpoint2D<algebra_t>{static_cast<dscalar<algebra_t>>(0.f), glob_p[2]},
95 tol);
96 }
97
111 template <concepts::scalar scalar_t, concepts::point point_t>
112 DETRAY_HOST_DEVICE constexpr auto check_boundaries(
113 const bounds_type<scalar_t> &bounds, const point_t &loc_p,
114 const scalar_t tol = std::numeric_limits<scalar_t>::epsilon(),
115 const scalar_t /*edge_tol*/ = 0.f) const {
116 return (bounds[e_lower_z] - tol <= loc_p[1] &&
117 loc_p[1] <= bounds[e_upper_z] + tol);
118 }
119
120
126 template <concepts::scalar scalar_t>
127 DETRAY_HOST_DEVICE constexpr scalar_t measure(
128 const bounds_type<scalar_t> &bounds) const {
129 return area(bounds);
130 }
131
137 template <concepts::scalar scalar_t>
138 DETRAY_HOST_DEVICE constexpr scalar_t area(
139 const bounds_type<scalar_t> &bounds) const {
140 return 2.f * constant<scalar_t>::pi * bounds[e_r] *
141 (bounds[e_upper_z] - bounds[e_lower_z]);
142 }
143
150 template <concepts::scalar scalar_t>
151 DETRAY_HOST_DEVICE constexpr bounds_type<scalar_t> merge(
152 const bounds_type<scalar_t> &bounds,
153 const bounds_type<scalar_t> &o_bounds) const {
154 bounds_type<scalar_t> new_bounds{};
155
156 new_bounds[e_r] = math::max(bounds[e_r], o_bounds[e_r]);
157 new_bounds[e_lower_z] = math::min(bounds[e_lower_z], o_bounds[e_lower_z]);
158 new_bounds[e_upper_z] = math::max(bounds[e_upper_z], o_bounds[e_upper_z]);
159
160 return new_bounds;
161 }
162
172 template <concepts::algebra algebra_t>
173 DETRAY_HOST_DEVICE inline darray<dscalar<algebra_t>, 6> local_min_bounds(
174 const bounds_type<dscalar<algebra_t>> &bounds,
175 const dscalar<algebra_t> env =
176 std::numeric_limits<dscalar<algebra_t>>::epsilon()) const {
177 assert(env > 0.f);
178 const dscalar<algebra_t> xy_bound{bounds[e_r] + env};
179 return {-xy_bound, -xy_bound, bounds[e_lower_z] - env,
180 xy_bound, xy_bound, bounds[e_upper_z] + env};
181 }
182
185 template <concepts::algebra algebra_t>
186 DETRAY_HOST_DEVICE dpoint3D<algebra_t> centroid(
187 const bounds_type<dscalar<algebra_t>> &bounds) const {
188 return {static_cast<dscalar<algebra_t>>(0.f),
189 static_cast<dscalar<algebra_t>>(0.f),
190 0.5f * (bounds[e_lower_z] + bounds[e_upper_z])};
191 }
192
200 template <concepts::algebra algebra_t>
202 const bounds_type<dscalar<algebra_t>> & /*unused*/,
203 dindex /*unused*/) const {
204 throw std::runtime_error(
205 "Vertex generation for cylinders is not implemented");
206 return {};
207 }
208
215 template <concepts::scalar scalar_t>
216 DETRAY_HOST constexpr bool check_consistency(
217 const bounds_type<scalar_t> &bounds, std::ostream &os) const {
218 constexpr auto tol{10.f * std::numeric_limits<scalar_t>::epsilon()};
219
220 if (bounds[e_r] < tol) {
221 os << "DETRAY ERROR (HOST): Radius must be in the range (0, "
222 "numeric_max)"
223 << std::endl;
224 return false;
225 }
226 if (bounds[e_lower_z] >= bounds[e_upper_z] ||
227 math::fabs(bounds[e_lower_z] - bounds[e_upper_z]) < tol) {
228 os << "DETRAY ERROR (HOST): Neg. half length must be smaller than "
229 "pos. half "
230 "length.";
231 return false;
232 }
233
234 return true;
235 }
236};
237
238} // namespace detray
Geometrical shape of a 2D concentric cylinder.
Definition concentric_cylinder2D.hpp:32
constexpr scalar_t area(const bounds_type< scalar_t > &bounds) const
The area of a the shape.
Definition concentric_cylinder2D.hpp:138
dpoint3D< algebra_t > centroid(const bounds_type< dscalar< algebra_t > > &bounds) const
Definition concentric_cylinder2D.hpp:186
constexpr bounds_type< scalar_t > merge(const bounds_type< scalar_t > &bounds, const bounds_type< scalar_t > &o_bounds) const
Merge two concentric cylinder shapes.
Definition concentric_cylinder2D.hpp:151
darray< scalar_t, boundaries::e_size > bounds_type
Container definition for the shape boundary values.
Definition concentric_cylinder2D.hpp:47
static constexpr std::size_t dim
Dimension of the local coordinate system.
Definition concentric_cylinder2D.hpp:58
boundaries
Indices describing the entries in the shape boundary array.
Definition concentric_cylinder2D.hpp:38
constexpr bool check_consistency(const bounds_type< scalar_t > &bounds, std::ostream &os) const
Check consistency of boundary values.
Definition concentric_cylinder2D.hpp:216
bool_t result_type
Result type of a boundary check.
Definition concentric_cylinder2D.hpp:55
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 concentric_cylinder2D.hpp:173
concentric_cylindrical2D< algebra_t > local_frame_type
Local coordinate frame for boundary checks.
Definition concentric_cylinder2D.hpp:51
constexpr result_type< dbool< algebra_t > > check_boundaries(const bounds_type< dscalar< algebra_t > > &bounds, const dtransform3D< algebra_t > &, 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 concentric_cylinder2D.hpp:84
dvector< dpoint3D< algebra_t > > vertices(const bounds_type< dscalar< algebra_t > > &, dindex) const
Generate vertices in local cartesian frame.
Definition concentric_cylinder2D.hpp:201
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 concentric_cylinder2D.hpp:70
static constexpr std::string_view name
The name for this shape.
Definition concentric_cylinder2D.hpp:35
constexpr scalar_t measure(const bounds_type< scalar_t > &bounds) const
Measure of the shape: Area.
Definition concentric_cylinder2D.hpp:127
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 concentric_cylinder2D.hpp:112
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
Projection into a 2D concentric cylindrical frame (No rotation in coordinate transformation).
Definition concentric_cylindrical2D.hpp:21
static constexpr scalar_t pi
π
Definition units.hpp:136