Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:58

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/definitions/detail/qualifiers.hpp"
0014 #include "detray/definitions/indexing.hpp"
0015 #include "detray/material/concepts.hpp"
0016 #include "detray/material/detail/material_accessor.hpp"
0017 #include "detray/material/material.hpp"
0018 #include "detray/navigation/accelerators/search_window.hpp"
0019 #include "detray/navigation/concepts.hpp"
0020 
0021 namespace detray::detail {
0022 
0023 /// A functor to retrieve the volume material parameters at a given position
0024 struct get_material_params {
0025   template <typename mat_group_t, typename index_t, concepts::point point_t>
0026   DETRAY_HOST_DEVICE inline auto operator()(const mat_group_t &mat_group,
0027                                             const index_t &idx,
0028                                             const point_t &loc_p) const {
0029     using material_t = typename mat_group_t::value_type;
0030 
0031     if constexpr (concepts::volume_material<material_t>) {
0032       if constexpr (concepts::homogeneous_material<material_t>) {
0033         // Homogeneous volume material
0034         return &(detail::material_accessor::get(mat_group, idx, loc_p));
0035       } else {
0036         // Volume material maps
0037         return &(detail::material_accessor::get(mat_group, idx, loc_p)
0038                      .get_material());
0039       }
0040     } else {
0041       using scalar_t = typename material_t::scalar_type;
0042       // Cannot be reached for volumes
0043       return static_cast<const material<scalar_t> *>(nullptr);
0044     }
0045   }
0046 };
0047 
0048 /// A functor to access all surfaces registered in an acceleration structure
0049 /// @tparam functor_t functor that performs a task per surface
0050 template <typename functor_t>
0051 struct apply_to_surfaces {
0052   /// Call operator that forwards the functor to all contained surfaces
0053   template <concepts::accelerator_collection accel_coll_t,
0054             typename accel_index_t, typename... Args>
0055   DETRAY_HOST_DEVICE inline void operator()(const accel_coll_t &coll,
0056                                             const accel_index_t index,
0057                                             Args &&...args) const {
0058     using accel_type = typename accel_coll_t::value_type;
0059 
0060     if constexpr (concepts::surface_accelerator<accel_type>) {
0061       // Run over the surfaces in a single acceleration data structure
0062       for (const auto &sf : coll[index].all()) {
0063         functor_t{}(sf, std::forward<Args>(args)...);
0064       }
0065     }
0066   }
0067 };
0068 
0069 /// A functor to find surfaces in the neighborhood of a track position
0070 /// @tparam functor_t functor that performs a task per surface in the
0071 ///                   neighbourhood (e.g. intersection)
0072 template <typename functor_t>
0073 struct apply_to_neighbourhood {
0074   /// Call operator that forwards the neighborhood search call in a volume
0075   /// to a surface finder data structure
0076   template <concepts::accelerator_collection accel_coll_t,
0077             typename accel_index_t, typename detector_t, typename track_t,
0078             typename window_size_t, typename... Args>
0079   DETRAY_HOST_DEVICE inline void operator()(
0080       const accel_coll_t &coll, const accel_index_t index,
0081       const detector_t &det, const typename detector_t::volume_type &volume,
0082       const track_t &track, const search_window<window_size_t, 2> &win_size,
0083       const typename detector_t::geometry_context &ctx, Args &&...args) const {
0084     using accel_type = typename accel_coll_t::value_type;
0085 
0086     decltype(auto) accel = coll[index];
0087 
0088     if constexpr (concepts::surface_accelerator<accel_type>) {
0089       // Run over the surfaces in a single acceleration data structure
0090       for (const auto &sf : accel.search(det, volume, track, win_size, ctx)) {
0091         functor_t{}(sf, std::forward<Args>(args)...);
0092       }
0093     } else if constexpr (concepts::volume_accelerator<accel_type>) {
0094       // Run over the daughter volumes in a single acceleration data
0095       // structure
0096       for (const dindex daughter_idx :
0097            accel.search(det, volume, track, win_size, ctx)) {
0098         functor_t{}(daughter_idx, std::forward<Args>(args)...);
0099       }
0100     }
0101   }
0102 };
0103 
0104 /// A functor to access the daughter volumes of a volume
0105 template <typename functor_t>
0106 struct apply_to_volumes {
0107   /// Call operator that forwards the functor call to all contained daughter
0108   /// volumes
0109   template <concepts::accelerator_collection accel_coll_t,
0110             typename accel_index_t, typename... Args>
0111   DETRAY_HOST_DEVICE inline void operator()(const accel_coll_t & /*accel_col*/,
0112                                             const accel_index_t /*accel_idx*/,
0113                                             Args &&.../*args*/) const {
0114     using accel_type = typename accel_coll_t::value_type;
0115 
0116     if constexpr (concepts::volume_accelerator<accel_type>) {
0117       // Run over all the daughter volumes
0118       // TODO: Implement e.g. BVH
0119     }
0120   }
0121 };
0122 
0123 }  // namespace detray::detail