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/geometry/coordinates/concentric_cylindrical2D.hpp"
16#include "detray/navigation/intersection/intersection.hpp"
17#include "detray/tracks/ray.hpp"
18
19// System include(s)
20#include <limits>
21
22namespace detray {
23
24template <typename frame_t, concepts::algebra algebra_t, bool resolve_pos>
26
32template <detray::concepts::soa algebra_t, bool resolve_pos>
33struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
34 resolve_pos> {
37 using algebra_type = algebra_t;
51
53 template <typename surface_descr_t>
56
58 template <typename other_algebra_t>
60
61 // Maximum number of solutions this intersector can produce
62 static constexpr std::uint8_t n_solutions{1u};
63
67
75 template <typename mask_t, concepts::algebra other_algebra_t>
76 DETRAY_HOST_DEVICE constexpr result_type point_of_intersection(
78 const transform3_type & /*trf*/, const mask_t &mask,
79 const scalar_type overstep_tol = 0.f) const {
80 const scalar_type r = mask[mask_t::shape::e_r];
81
82 const auto &pos = ray.pos();
83 const auto &dir = ray.dir();
84
85 const value_type rd_perp_2{dir[0] * dir[0] + dir[1] * dir[1]};
86
87 // The ray is parallel to all/any cylinder axes (z-axis)...
88 if (rd_perp_2 < std::numeric_limits<value_type>::epsilon()) [[unlikely]] {
89 return {};
90 }
91
92 // ...otherwise, two solutions should exist, if the descriminator is
93 // greater than zero
94 const scalar_type ro_perp_2 = pos[0] * pos[0] + pos[1] * pos[1];
95 const scalar_type rad_diff = r * r - ro_perp_2;
96
97 const scalar_type rd_perp_inv_2 = 1.f / rd_perp_2;
98 const scalar_type k = -rd_perp_inv_2 * (pos[0] * dir[0] + pos[1] * dir[1]);
99 const scalar_type discr = rd_perp_inv_2 * rad_diff + k * k;
100
101 // No intersection found for any cylinder
102 if (detray::detail::all_of(discr < 0.f)) [[unlikely]] {
103 return {};
104 }
105
106 const scalar_type sqrt_discr = math::sqrt(discr);
107 const scalar_type s1 = k + sqrt_discr;
108 const scalar_type s2 = k - sqrt_discr;
109
110 // Take the nearest solution in every lane
111 auto is_smaller_sol = math::fabs(s1) < math::fabs(s2);
112
113 scalar_type path = 0.f;
114 path(is_smaller_sol) = s1;
115 path(!is_smaller_sol) = s2;
116
117 // If any of the the near solutions is outside the overstepping
118 // tolerance, take the far solution (if it exists)
119 if (const auto outside_overstep_tol = path < overstep_tol;
120 detray::detail::any_of(outside_overstep_tol) &&
121 detray::detail::all_of((discr > 0.f) || !outside_overstep_tol)) {
122 is_smaller_sol =
123 (math::fabs(s1) >= math::fabs(s2)) && outside_overstep_tol;
124 path(is_smaller_sol) = s1;
125 path(!is_smaller_sol) = s2;
126 }
127
128 point2_type loc;
129 loc[0] = 0.f;
130 loc[1] = pos[2] + path * dir[2];
131
132 return {path, loc};
133 }
134};
135
136} // 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_value_t< A > dvalue
Value scalar type of the algebra backend.
Definition algebra.hpp:48
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
dscalar< algebra_t > scalar_type
Scalar calculation type for the configured algebra layout.
Definition ray_cylinder_portal_intersector.hpp:41
dvalue< algebra_t > value_type
Value type stored in the bins or result.
Definition ray_cylinder_portal_intersector.hpp:39
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 > point2_type
Two-dimensional point type used by this intersector.
Definition ray_cylinder_portal_intersector.hpp:43
dpoint3D< algebra_t > point3_type
Three-dimensional point type used by this intersector.
Definition ray_cylinder_portal_intersector.hpp:45
constexpr result_type point_of_intersection(const trajectory_type< other_algebra_t > &ray, const transform3_type &, const mask_t &mask, const scalar_type overstep_tol=0.f) const
Operator function to find intersections between ray and planar mask.
Definition ray_cylinder_portal_intersector.hpp:76
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
dvector3D< algebra_t > vector3_type
Three-dimensional vector type used by this intersector.
Definition ray_cylinder_portal_intersector.hpp:47
algebra_t algebra_type
Algebra policy used by this intersector.
Definition ray_cylinder_portal_intersector.hpp:38
dtransform3D< algebra_t > transform3_type
Transform type used to place the surface.
Definition ray_cylinder_portal_intersector.hpp:49
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