Back to home page

EIC code displayed by LXR

 
 

    


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

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/builders/detail/bin_association.hpp"
0013 #include "detray/utils/grid/axis.hpp"
0014 #include "detray/utils/grid/concepts.hpp"
0015 #include "detray/utils/grid/populators.hpp"
0016 
0017 // System include(s)
0018 #include <cassert>
0019 #include <vector>
0020 
0021 namespace detray {
0022 
0023 /// Fill a surface grid using a local bin index of the grid and a payload.
0024 ///
0025 /// @param grid the grid that should be filled
0026 /// @param det the detector from which to get the surface placements
0027 /// @param vol the volume the grid belongs to
0028 /// @param ctx the geometry context
0029 struct fill_by_bin {
0030   /// Single piece of data for a grid bin
0031   template <std::size_t DIM, typename value_t>
0032   struct bin_data {
0033     /// Bin index on the grid axes
0034     detray::axis::multi_bin<DIM> local_bin_idx;
0035     /// Single element of the bin content, which can be a collection of grid
0036     /// values
0037     value_t single_element;
0038   };
0039 
0040   template <concepts::grid grid_t>
0041   using bin_data_type = bin_data<grid_t::dim, typename grid_t::value_type>;
0042 
0043   template <concepts::grid grid_t, typename volume_t,
0044             typename surface_container_t, typename mask_container,
0045             typename transform_container, typename context_t, typename... Args>
0046   DETRAY_HOST auto operator()(grid_t &grid, const volume_t & /*unused*/,
0047                               const surface_container_t & /*unused*/,
0048                               const mask_container & /*unused*/,
0049                               const context_t /*unused*/,
0050                               std::vector<bin_data_type<grid_t>> &bins) const
0051       -> void {
0052     for (const bin_data_type<grid_t> &bd : bins) {
0053       grid.template populate<attach<>>(bd.local_bin_idx, bd.single_element);
0054     }
0055   }
0056 };
0057 
0058 /// Fill a surface grid using the surface translation.
0059 ///
0060 /// @param grid the grid that should be filled
0061 /// @param det the detector from which to get the surface placements
0062 /// @param vol the volume the grid belongs to
0063 /// @param ctx the geometry context
0064 struct fill_by_pos {
0065   template <concepts::surface_grid grid_t, typename volume_t,
0066             typename surface_container_t, typename mask_container,
0067             typename transform_container, typename context_t, typename... Args>
0068   DETRAY_HOST auto operator()(grid_t &grid, const volume_t &vol,
0069                               const surface_container_t &surfaces,
0070                               const transform_container &transforms,
0071                               const mask_container & /*masks*/,
0072                               const context_t ctx, Args &&.../*unused*/) const
0073       -> void {
0074     // Fill the volumes surfaces into the grid
0075     for (const auto &sf : surfaces) {
0076       // no portals in grids allowed
0077       if (sf.volume() == vol.index() && sf.is_sensitive()) {
0078         const auto &sf_trf = transforms.at(sf.transform(), ctx);
0079         const auto &t = sf_trf.translation();
0080 
0081         // transform to axis coordinate system
0082         const auto loc_pos = grid.project(vol.transform(), t, t);
0083 
0084         // Populate
0085         grid.template populate<attach<>>(loc_pos, sf);
0086       }
0087     }
0088   }
0089 };
0090 
0091 /// Fill a grid surface finder by bin association.
0092 ///
0093 /// @param grid the grid that should be filled
0094 /// @param det the detector from which to get the surface placements
0095 /// @param vol the volume the grid belongs to
0096 /// @param ctx the geometry context
0097 struct bin_associator {
0098   template <typename detector_t, typename volume_type,
0099             concepts::surface_grid grid_t, typename... Args>
0100   DETRAY_HOST auto operator()(grid_t &grid, detector_t &det,
0101                               const volume_type &vol,
0102                               const typename detector_t::geometry_context ctx,
0103                               Args &&.../*unused*/) const -> void {
0104     this->operator()(grid, det.surfaces(vol), det.mask_store(),
0105                      det.transform_store(), ctx);
0106   }
0107 
0108   template <concepts::surface_grid grid_t, typename volume_t,
0109             typename surface_container_t, typename mask_container,
0110             typename transform_container, typename context_t, typename... Args>
0111   DETRAY_HOST auto operator()(grid_t &grid, const volume_t & /*unused*/,
0112                               const surface_container_t &surfaces,
0113                               const transform_container &transforms,
0114                               const mask_container &masks, const context_t ctx,
0115                               Args &&.../*unused*/) const -> void {
0116     using scalar_t = dscalar<typename grid_t::algebra_type>;
0117 
0118     // Fill the surfaces into the grid by matching their contour onto the
0119     // grid bins
0120     bin_association(ctx, surfaces, transforms, masks, grid,
0121                     darray<scalar_t, 2>{0.1f, 0.1f}, false);
0122   }
0123 };
0124 
0125 }  // namespace detray