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/containers.hpp"
0014 #include "detray/definitions/math.hpp"
0015 #include "detray/geometry/surface.hpp"
0016 #include "detray/utils/ranges.hpp"
0017 
0018 namespace detray::detail {
0019 
0020 template <concepts::point2D point2_t, concepts::point3D point3_t>
0021 struct vertexer;
0022 
0023 /// Compute vertices in global frame along the boundary of a surface
0024 ///
0025 /// @param ctx geometry context
0026 /// @param sf the surface
0027 /// @param n_seg the number of segments used along arcs
0028 ///
0029 /// @returns a vector of vetices (3D points)
0030 template <typename detector_t>
0031 DETRAY_HOST constexpr auto get_global_vertices(
0032     const typename detector_t::geometry_context &ctx,
0033     geometry::surface<detector_t> sf, const dindex n_seg) {
0034   using algebra_t = typename detector_t::algebra_type;
0035   using point2_t = dpoint2D<algebra_t>;
0036   using point3_t = dpoint3D<algebra_t>;
0037 
0038   auto vertices = sf.template visit_mask<vertexer<point2_t, point3_t>>(n_seg);
0039   const auto &trf = sf.transform(ctx);
0040 
0041   const std::size_t n_vertices{vertices.size()};
0042   for (std::size_t i = 0u; i < n_vertices; ++i) {
0043     vertices[i] = trf.point_to_global(vertices[i]);
0044   }
0045 
0046   return vertices;
0047 }
0048 
0049 /// Generate phi values along an arc
0050 ///
0051 /// @param start_phi is the start for the arc generation
0052 /// @param end_phi is the end of the arc generation
0053 /// @param n_seg is the number of segments used to generate the arc
0054 ///
0055 /// @return a vector of phi values for the arc
0056 template <concepts::scalar scalar_t>
0057 static inline dvector<scalar_t> phi_values(scalar_t start_phi, scalar_t end_phi,
0058                                            dindex n_seg) {
0059   dvector<scalar_t> values;
0060   values.reserve(n_seg + 1u);
0061   scalar_t step_phi = (end_phi - start_phi) / static_cast<scalar_t>(n_seg);
0062   for (unsigned int istep = 0u; istep <= n_seg; ++istep) {
0063     values.push_back(start_phi + static_cast<scalar_t>(istep) * step_phi);
0064   }
0065   return values;
0066 }
0067 
0068 /// Create a r-phi polygon from principle parameters
0069 ///
0070 /// @param rmin minimum r parameter
0071 /// @param rmax maximum r parameter
0072 /// @param phimin minimum phi parameter
0073 /// @param phimax maximum phi parameters
0074 ///
0075 /// @return a polygon representation of the bin
0076 template <concepts::scalar scalar_t, concepts::point2D point2_t>
0077 inline std::vector<point2_t> r_phi_polygon(scalar_t rmin, scalar_t rmax,
0078                                            scalar_t phimin, scalar_t phimax,
0079                                            unsigned int n_segments = 1u) {
0080   std::vector<point2_t> r_phi_poly;
0081   r_phi_poly.reserve(2u * n_segments + 2u);
0082 
0083   scalar_t cos_min_phi = math::cos(phimin);
0084   scalar_t sin_min_phi = math::sin(phimin);
0085   scalar_t cos_max_phi = math::cos(phimax);
0086   scalar_t sin_max_phi = math::sin(phimax);
0087 
0088   // @TODO add phi generators
0089   r_phi_poly.push_back({rmin * cos_min_phi, rmin * sin_min_phi});
0090   r_phi_poly.push_back({rmin * cos_max_phi, rmin * sin_max_phi});
0091   r_phi_poly.push_back({rmax * cos_max_phi, rmax * sin_max_phi});
0092   r_phi_poly.push_back({rmax * cos_min_phi, rmax * sin_min_phi});
0093 
0094   return r_phi_poly;
0095 }
0096 
0097 /// Functor to produce vertices on a mask collection in a mask tuple container.
0098 template <concepts::point2D point2_t, concepts::point3D point3_t>
0099 struct vertexer {
0100   /// Specialized method to generate vertices per mask group
0101   ///
0102   /// @tparam mask_group_t is the type of the mask collection in a mask cont.
0103   /// @tparam mask_range_t is the type of the according mask range object
0104   ///
0105   /// @param masks is the associated (and split out) mask group
0106   /// @param range is the range list of masks to be processed
0107   ///
0108   /// @return a jagged vector of points of the mask vertices (one per mask)
0109   template <typename mask_group_t, typename mask_range_t>
0110   dvector<dvector<point3_t>> operator()(const mask_group_t &masks,
0111                                         const mask_range_t &range,
0112                                         unsigned int n_segments = 1) {
0113     dvector<dvector<point3_t>> mask_vertices = {};
0114     for (auto i : detray::views::iota(range)) {
0115       mask_vertices.push_back(masks[i].vertices(n_segments));
0116     }
0117     return mask_vertices;
0118   }
0119 };
0120 
0121 }  // namespace detray::detail