Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 08:18:59

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 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/VectorHelpers.hpp"
0013 
0014 #include <array>
0015 #include <stdexcept>
0016 #include <utility>
0017 
0018 namespace Acts::GridAccessHelpers {
0019 
0020 /// Cast into a lookup position
0021 ///
0022 /// This method allows to transform a global position into a grid position
0023 /// that is specified by binning values. It casts the global position info
0024 /// into a format suitable for the grid.
0025 ///
0026 /// @tparam cast_container is the container type of cast objects
0027 ///
0028 /// @param position is the position of the update call
0029 /// @param globalCasts is the cast value vector from global to grid position
0030 ///
0031 /// @return a grid point in an appropriate format
0032 template <typename grid_type, typename cast_container>
0033 typename grid_type::point_t castPosition(const Vector3& position,
0034                                          const cast_container& globalCasts) {
0035   // Fill the grid point from global, unrolling the cast loop
0036   return [&]<std::size_t... idx>(std::index_sequence<idx...> /*indices*/) {
0037     return typename grid_type::point_t{
0038         VectorHelpers::cast(position, globalCasts[idx])...};
0039   }(std::make_integer_sequence<std::size_t, grid_type::DIM>{});
0040 }
0041 
0042 /// Unroll the local position loop
0043 ///
0044 /// @param lposition is the local position
0045 /// @param laccess the local accessors
0046 /// @param ra is the array to be filled
0047 ///
0048 /// @note void function that fills the provided array
0049 template <typename Array, typename local_indices, std::size_t... idx>
0050 void fillLocal(const Vector2& lposition, const local_indices& laccess,
0051                Array& ra, std::index_sequence<idx...> /*indices*/) {
0052   ((ra[idx] = lposition[laccess[idx]]), ...);
0053 }
0054 
0055 /// Access local parameters for a propriate lookup position
0056 ///
0057 /// This method allows to transform a local position into a
0058 /// grid position, it only works for 1-D and 2-D grids.
0059 ///
0060 /// @param lposition is the position of the update call
0061 /// @param laccess the local accessors
0062 ///
0063 /// @return an array suitable for the grid
0064 template <typename grid_type, typename local_indices>
0065 typename grid_type::point_t accessLocal(const Vector2& lposition,
0066                                         const local_indices& laccess) {
0067   if constexpr (grid_type::DIM > 2u) {
0068     throw std::invalid_argument(
0069         "GridAccessHelper: only 1-D and 2-D grids are possible for local "
0070         "access.");
0071   }
0072   // Fill the grid point from local according to the accessors
0073   typename grid_type::point_t accessed{};
0074   fillLocal(lposition, laccess, accessed,
0075             std::make_integer_sequence<std::size_t, grid_type::DIM>{});
0076   return accessed;
0077 }
0078 
0079 }  // namespace Acts::GridAccessHelpers