ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
ray_cylinder_portal_intersector.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/detail/qualifiers.hpp"
14#include "detray/definitions/math.hpp"
15#include "detray/definitions/units.hpp"
16#include "detray/geometry/coordinates/concentric_cylindrical2D.hpp"
17#include "detray/navigation/intersection/intersection.hpp"
18#include "detray/tracks/ray.hpp"
19
20// System include(s)
21#include <limits>
22#include <type_traits>
23
24namespace detray {
25
26template <typename frame_t, concepts::algebra algebra_t, bool resolve_pos>
28
34template <detray::concepts::aos algebra_t, bool resolve_pos>
36 resolve_pos> {
38 using algebra_type = algebra_t;
43
45 template <typename surface_descr_t>
48
50 template <typename other_algebra_t>
52
53 // Maximum number of solutions this intersector can produce
55 static constexpr std::uint8_t n_solutions{1u};
56
60
73 template <typename mask_t>
74 DETRAY_HOST_DEVICE constexpr result_type point_of_intersection(
76 const dtransform3D<algebra_t> & /*trf*/, const mask_t &mask,
77 const dscalar<algebra_t> overstep_tol = 0.f) const {
78 using scalar_t = dscalar<algebra_t>;
79 using point3_t = dpoint3D<algebra_t>;
80 using vector3_t = dvector3D<algebra_t>;
81
82 const scalar_t r{mask[mask_t::shape::e_r]};
83 constexpr scalar_t inv{detail::invalid_value<dvalue<algebra_t>>()};
84
85 const point3_t &ro = ray.pos();
86 const vector3_t &rd = ray.dir();
87 scalar_t path{inv};
88
89 const scalar_t rd_perp_2{rd[0] * rd[0] + rd[1] * rd[1]};
90
91 // The ray is parallel to the cylinder axis (z-axis)...
92 if (rd_perp_2 < std::numeric_limits<scalar_t>::epsilon()) [[unlikely]] {
93 return {};
94 }
95
96 // ...otherwise, two solutions should exist, if the descriminator is
97 // greater than zero
98 const scalar_t ro_perp_2{ro[0] * ro[0] + ro[1] * ro[1]};
99
100 // Only calculate the path, when not already on surface
101 // 'rad_diff' leads to numerical instabilites in single precision on GPU
102 if (const double rad_diff{r * r - ro_perp_2};
103 math::fabs(rad_diff) > 1.f * unit<scalar_t>::um) {
104 const scalar_t rd_perp_inv_2{1.f / rd_perp_2};
105 const scalar_t k{-rd_perp_inv_2 * (ro[0] * rd[0] + ro[1] * rd[1])};
106 const auto discr{static_cast<scalar_t>(rd_perp_inv_2 * rad_diff + k * k)};
107
108 // No intersection found
109 if (discr < 0.f) [[unlikely]] {
110 return {};
111 }
112
113 const scalar_t sqrt_discr{math::sqrt(discr)};
114 const scalar_t s1{k + sqrt_discr};
115 const scalar_t s2{k - sqrt_discr};
116
117 // Take the nearest solution
118 path = (math::fabs(s1) < math::fabs(s2)) ? s1 : s2;
119
120 // If the near solution is outside the overstepping tolerance, take
121 // the far solution (if it exists)
122 if (path < overstep_tol && sqrt_discr > 0.f) {
123 path = (math::fabs(s1) >= math::fabs(s2)) ? s1 : s2;
124 }
125 } else {
126 path = static_cast<scalar_t>(rad_diff);
127 }
128
129 if (path < overstep_tol) {
130 path = inv;
131 }
132
133 // Only need the global z-component for the mask check
134 return {path, point_type{inv, ro[2] + path * rd[2]}};
135 }
136};
137
138} // namespace detray
describes a straight-line trajectory
Definition ray.hpp:22
This class holds the intersection information.
Definition intersection.hpp:212
Mask a region on a surface and link it to a volume.
Definition mask.hpp:46
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
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
Projection into a 2D concentric cylindrical frame (No rotation in coordinate transformation).
Definition concentric_cylindrical2D.hpp:21
Result of intersector: Point of intersection on a surface.
Definition intersection.hpp:43
concentric_cylindrical2D< algebra_t > frame_type
Coordinate frame of the intersected surface.
Definition ray_cylinder_portal_intersector.hpp:40
intersection2D< surface_descr_t, algebra_t, resolve_pos > intersection_type
Intersection result type associated with a surface descriptor.
Definition ray_cylinder_portal_intersector.hpp:46
dpoint2D< algebra_t > point_type
Point type used for the intersection result.
Definition ray_cylinder_portal_intersector.hpp:42
constexpr result_type point_of_intersection(const trajectory_type< algebra_t > &ray, const dtransform3D< algebra_t > &, const mask_t &mask, const dscalar< algebra_t > overstep_tol=0.f) const
Operator function to find intersections between ray and cylinder mask.
Definition ray_cylinder_portal_intersector.hpp:74
static constexpr std::uint8_t n_solutions
Maximum number of solutions produced by this intersector.
Definition ray_cylinder_portal_intersector.hpp:55
detail::ray< other_algebra_t > trajectory_type
Trajectory representation accepted by this intersector.
Definition ray_cylinder_portal_intersector.hpp:51
algebra_t algebra_type
Algebra policy used by this intersector.
Definition ray_cylinder_portal_intersector.hpp:38
intersection_point< algebra_t, point_type, intersection::contains_pos > result_type
Result type returned by the geometric intersection calculation.
Definition ray_cylinder_portal_intersector.hpp:58
Intersection implementation for detector surfaces using a ray trajectory.
Definition ray_intersector.hpp:31
static constexpr scalar_t um
Length, native unit mm.
Definition units.hpp:25