Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:01

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s)
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/geometry/concepts.hpp"
0014 #include "detray/navigation/intersection/helix_intersector.hpp"
0015 #include "detray/navigation/intersection/intersection_config.hpp"
0016 #include "detray/navigation/intersection/ray_intersector.hpp"
0017 
0018 namespace detray {
0019 
0020 /// @brief Intersection interface for detector surfaces.
0021 ///
0022 /// Composes the different intersector options into a unifyed interface
0023 template <typename shape_t, concepts::algebra algebra_t,
0024           bool resolve_pos = false>
0025 struct intersector {
0026   using algebra_type = algebra_t;
0027   using scalar_type = dscalar<algebra_t>;
0028   using transform3_type = dtransform3D<algebra_t>;
0029 
0030   /// How to intersect surfaces with rays
0031   using ray_intersector_type = ray_intersector<shape_t, algebra_t, resolve_pos>;
0032 
0033   /// How to intersect surfaces with helices
0034   using helix_intersector_type = helix_intersector<shape_t, algebra_t>;
0035 
0036   // Test with int as dummy surface descriptor type
0037   static_assert(
0038       std::same_as<
0039           typename ray_intersector_type::template intersection_type<int>,
0040           typename helix_intersector_type::template intersection_type<int>>);
0041 
0042   // Maximum number of solutions this intersector can produce
0043   static constexpr std::uint8_t n_solutions{math::max(
0044       ray_intersector_type::n_solutions, helix_intersector_type::n_solutions)};
0045 
0046   // Take the helix intersector result type, as it needs more data
0047   using result_type = typename helix_intersector_type::result_type;
0048 
0049   /// Operator function to find intersections between ray and planar mask
0050   ///
0051   /// @param ray is the input ray trajectory
0052   /// @param sf the surface handle the mask is associated with
0053   /// @param mask is the input mask that defines the surface extent
0054   /// @param trf is the surface placement transform
0055   /// @param mask_tolerance is the tolerance for mask edges
0056   /// @param overstep_tol negative cutoff for the path
0057   ///
0058   /// @return the intersection result
0059   /// @{
0060   template <typename S = shape_t>
0061     requires(!concepts::cylindrical_shape<S, algebra_type>)
0062   DETRAY_HOST_DEVICE constexpr result_type point_of_intersection(
0063       const detail::ray<algebra_t> &ray, const transform3_type &trf,
0064       const scalar_type overstep_tol = 0.f) const {
0065     return to_result_type(
0066         ray_intersector_type{}.point_of_intersection(ray, trf, overstep_tol));
0067   }
0068 
0069   template <typename mask_t, typename S = shape_t>
0070     requires concepts::cylindrical_shape<S, algebra_type>
0071   DETRAY_HOST_DEVICE constexpr result_type point_of_intersection(
0072       const detail::ray<algebra_t> &ray, const transform3_type &trf,
0073       const mask_t &mask, const scalar_type overstep_tol = 0.f) const {
0074     return to_result_type(ray_intersector_type{}.point_of_intersection(
0075         ray, trf, mask, overstep_tol));
0076   }
0077 
0078   template <typename S = shape_t>
0079     requires(!concepts::cylindrical_shape<S, algebra_type>)
0080   DETRAY_HOST_DEVICE constexpr result_type point_of_intersection(
0081       const detail::helix<algebra_t> &h, const transform3_type &trf,
0082       const scalar_type /*overstep_tol*/ = 0.f) const {
0083     return helix_intersector_type{}.point_of_intersection(h, trf);
0084   }
0085 
0086   template <typename mask_t, typename S = shape_t>
0087     requires concepts::cylindrical_shape<S, algebra_type>
0088   DETRAY_HOST_DEVICE constexpr result_type point_of_intersection(
0089       const detail::helix<algebra_t> &h, const transform3_type &trf,
0090       const mask_t &mask, const scalar_type /*overstep_tol*/ = 0.f) const {
0091     return helix_intersector_type{}.point_of_intersection(h, trf, mask);
0092   }
0093   /// @}
0094 
0095   /// @returns the intersection(s) between a surface and the ray @param ray
0096   template <typename surface_descr_t, typename mask_t>
0097   DETRAY_HOST_DEVICE inline decltype(auto) operator()(
0098       const detail::ray<algebra_t> &ray, const surface_descr_t &sf,
0099       const mask_t &mask, const transform3_type &trf,
0100       const intersection::config &cfg = {},
0101       const scalar_type external_mask_tol = 0.f) const {
0102     return ray_intersector_type{}(ray, sf, mask, trf, cfg, external_mask_tol);
0103   }
0104 
0105   /// @returns the intersection(s) between a surface and the helix @param h
0106   template <typename surface_descr_t, typename mask_t>
0107   DETRAY_HOST_DEVICE inline decltype(auto) operator()(
0108       const detail::helix<algebra_t> &h, const surface_descr_t &sf,
0109       const mask_t &mask, const transform3_type &trf,
0110       const intersection::config &cfg = {},
0111       const scalar_type /*unused*/ = 0.f) const {
0112     return helix_intersector_type{}(h, sf, mask, trf, cfg);
0113   }
0114 
0115  private:
0116   /// Translate ray intersector results to the common intersector results
0117   DETRAY_HOST_DEVICE
0118   constexpr result_type to_result_type(
0119       const ray_intersector_type::result_type &ray_results) const {
0120     result_type result;
0121     if constexpr (n_solutions > 1) {
0122       for (std::size_t i = 0u; i < n_solutions; ++i) {
0123         result[i] = typename result_type::value_type{ray_results[i]};
0124       }
0125     } else {
0126       result = result_type{ray_results};
0127     }
0128     return result;
0129   }
0130 };
0131 
0132 }  // namespace detray