Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:11:53

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/Material/GridSurfaceMaterial.hpp"
0012 #include "Acts/Material/MaterialSlab.hpp"
0013 #include "Acts/Utilities/GridAccessHelpers.hpp"
0014 #include "Acts/Utilities/ProtoAxis.hpp"
0015 
0016 #include <memory>
0017 #include <vector>
0018 
0019 namespace Acts::GridSurfaceMaterialFactory {
0020 
0021 /// Create and fill from a single proto axis
0022 ///
0023 /// @param pAxis the type of the ProtoAxis
0024 /// @param materialAccessor the material accessor
0025 /// @param boundToGridLocal the delegate from bound to grid local frame
0026 /// @param globalToGridLocal the delegate from global into grid local frame
0027 /// @param payload the grid payload (material slab / indices)
0028 ///
0029 /// @return a unique pointer to the surface material
0030 template <typename material_accessor_t>
0031 std::unique_ptr<
0032     IGridSurfaceMaterial<typename material_accessor_t::grid_value_type>>
0033 create1D(
0034     const ProtoAxis& pAxis, material_accessor_t&& materialAccessor,
0035     GridAccess::BoundToGridLocal1DimDelegate boundToGridLocal,
0036     GridAccess::GlobalToGridLocal1DimDelegate globalToGridLocal,
0037     const std::vector<typename material_accessor_t::grid_value_type>& payload) {
0038   // Visit the axis type and create the grid surface material
0039   auto ism = pAxis.getAxis().visit(
0040       [&]<typename AxisType>(const AxisType& axis)
0041           -> std::unique_ptr<IGridSurfaceMaterial<
0042               typename material_accessor_t::grid_value_type>> {
0043         using GridType =
0044             Grid<typename material_accessor_t::grid_value_type, AxisType>;
0045         return std::make_unique<
0046             GridSurfaceMaterialT<GridType, material_accessor_t>>(
0047             GridType(axis), std::forward<material_accessor_t>(materialAccessor),
0048             std::move(boundToGridLocal), std::move(globalToGridLocal));
0049       });
0050   // Fill it via the grid view
0051   AnyGridView<typename material_accessor_t::grid_value_type> gv =
0052       ism->gridView();
0053   auto indices = gv.numLocalBins();
0054   for (std::size_t i0 = 0; i0 < indices[0]; ++i0) {
0055     // Offset comes from overflow/underflow bin
0056     gv.atLocalBins({i0 + 1u}) = payload[i0];
0057   }
0058   return ism;
0059 }
0060 
0061 /// Static creation method for the with ProtoAxis objects
0062 ///
0063 /// @param pAxis0 proto axis in direction 0
0064 /// @param pAxis1 proto axis in direction 1
0065 /// @param materialAccessor the material accessor
0066 /// @param boundToGridLocal the delegate from bound to grid local frame
0067 /// @param globalToGridLocal the delegate from global into grid local frame
0068 /// @param payload the grid payload in 2D (material slab / indices)
0069 /// the payload has to be column major, i.e. [i0][i1]
0070 ///
0071 /// @return a unique pointer to the surface material
0072 template <typename material_accessor_t>
0073 std::unique_ptr<
0074     IGridSurfaceMaterial<typename material_accessor_t::grid_value_type>>
0075 create2D(
0076     const ProtoAxis& pAxis0, const ProtoAxis& pAxis1,
0077     material_accessor_t&& materialAccessor,
0078     GridAccess::BoundToGridLocal2DimDelegate boundToGridLocal,
0079     GridAccess::GlobalToGridLocal2DimDelegate globalToGridLocal,
0080     const std::vector<
0081         std::vector<typename material_accessor_t::grid_value_type>>& payload) {
0082   // Validate axis compatibility
0083   auto ism = pAxis0.getAxis().visit(
0084       [&]<typename AxisTypeA>(const AxisTypeA& axisA)
0085           -> std::unique_ptr<IGridSurfaceMaterial<
0086               typename material_accessor_t::grid_value_type>> {
0087         return pAxis1.getAxis().visit(
0088             [&]<typename AxisTypeB>(const AxisTypeB& axisB)
0089                 -> std::unique_ptr<IGridSurfaceMaterial<
0090                     typename material_accessor_t::grid_value_type>> {
0091               using GridType =
0092                   Grid<typename material_accessor_t::grid_value_type, AxisTypeA,
0093                        AxisTypeB>;
0094               return std::make_unique<
0095                   GridSurfaceMaterialT<GridType, material_accessor_t>>(
0096                   GridType(axisA, axisB),
0097                   std::forward<material_accessor_t>(materialAccessor),
0098                   std::move(boundToGridLocal), std::move(globalToGridLocal));
0099             });
0100       });
0101 
0102   // Fill it via the grid view
0103   AnyGridView<typename material_accessor_t::grid_value_type> gv =
0104       ism->gridView();
0105   auto indices = gv.numLocalBins();
0106   for (std::size_t i0 = 0; i0 < indices[0]; ++i0) {
0107     for (std::size_t i1 = 0; i1 < indices[1]; ++i1) {
0108       // Offset comes from overflow/underflow bin
0109       gv.atLocalBins({i0 + 1, i1 + 1}) = payload[i0][i1];
0110     }
0111   }
0112 
0113   return ism;
0114 }
0115 
0116 /// The resolved functions to reduce compile time template bloat
0117 ///  - GridMaterial 1D
0118 /// @param pAxis the proto axis
0119 /// @param materialAccessor the material accessor
0120 /// @param boundToGridLocal the delegate from bound to grid local frame
0121 /// @param globalToGridLocal the delegate from global into grid local frame
0122 /// @param payload the grid payload (material slab / indices)
0123 std::unique_ptr<IGridSurfaceMaterial<MaterialSlab>> create(
0124     const ProtoAxis& pAxis, GridMaterialAccessor&& materialAccessor,
0125     GridAccess::BoundToGridLocal1DimDelegate boundToGridLocal,
0126     GridAccess::GlobalToGridLocal1DimDelegate globalToGridLocal,
0127     const std::vector<MaterialSlab>& payload);
0128 
0129 /// The resolved functions to reduce compile time template bloat
0130 /// - IndexedMaterial 1D
0131 /// @param pAxis the proto axis
0132 /// @param materialAccessor the material accessor
0133 /// @param boundToGridLocal the delegate from bound to grid local frame
0134 /// @param globalToGridLocal the delegate from global into grid local frame
0135 /// @param payload the grid payload (material slab / indices)
0136 std::unique_ptr<IGridSurfaceMaterial<IndexedMaterialAccessor::grid_value_type>>
0137 create(const ProtoAxis& pAxis, IndexedMaterialAccessor&& materialAccessor,
0138        GridAccess::BoundToGridLocal1DimDelegate boundToGridLocal,
0139        GridAccess::GlobalToGridLocal1DimDelegate globalToGridLocal,
0140        const std::vector<IndexedMaterialAccessor::grid_value_type>& payload);
0141 
0142 /// The resolved functions to reduce compile time template bloat
0143 /// - GloballyIndexedMaterial 1D
0144 /// @param pAxis the proto axis
0145 /// @param materialAccessor the material accessor
0146 /// @param boundToGridLocal the delegate from bound to grid local frame
0147 /// @param globalToGridLocal the delegate from global into grid local frame
0148 /// @param payload the grid payload (material slab / indices)
0149 std::unique_ptr<
0150     IGridSurfaceMaterial<GloballyIndexedMaterialAccessor::grid_value_type>>
0151 create(const ProtoAxis& pAxis,
0152        GloballyIndexedMaterialAccessor&& materialAccessor,
0153        GridAccess::BoundToGridLocal1DimDelegate boundToGridLocal,
0154        GridAccess::GlobalToGridLocal1DimDelegate globalToGridLocal,
0155        const std::vector<GloballyIndexedMaterialAccessor::grid_value_type>&
0156            payload);
0157 
0158 /// The resolved functions to reduce compile time template bloat
0159 /// - GridMaterial 2D
0160 /// @param pAxis0 the proto axis in direction 0
0161 /// @param pAxis1 the proto axis in direction 1
0162 /// @param materialAccessor the material accessor
0163 /// @param boundToGridLocal the delegate from bound to grid local frame
0164 /// @param globalToGridLocal the delegate from global into grid local frame
0165 /// @param payload the grid payload (material slab / indices)
0166 std::unique_ptr<IGridSurfaceMaterial<MaterialSlab>> create(
0167     const ProtoAxis& pAxis0, const ProtoAxis& pAxis1,
0168     GridMaterialAccessor&& materialAccessor,
0169     GridAccess::BoundToGridLocal2DimDelegate boundToGridLocal,
0170     GridAccess::GlobalToGridLocal2DimDelegate globalToGridLocal,
0171     const std::vector<std::vector<MaterialSlab>>& payload);
0172 
0173 /// The resolved functions to reduce compile time template bloat
0174 /// - IndexedMaterial 2D
0175 /// @param pAxis0 the proto axis in direction 0
0176 /// @param pAxis1 the proto axis in direction 1
0177 /// @param materialAccessor the material accessor
0178 /// @param boundToGridLocal the delegate from bound to grid local frame
0179 /// @param globalToGridLocal the delegate from global into grid local frame
0180 /// @param payload the grid payload (material slab / indices)
0181 std::unique_ptr<IGridSurfaceMaterial<IndexedMaterialAccessor::grid_value_type>>
0182 create(const ProtoAxis& pAxis0, const ProtoAxis& pAxis1,
0183        IndexedMaterialAccessor&& materialAccessor,
0184        GridAccess::BoundToGridLocal2DimDelegate boundToGridLocal,
0185        GridAccess::GlobalToGridLocal2DimDelegate globalToGridLocal,
0186        const std::vector<std::vector<IndexedMaterialAccessor::grid_value_type>>&
0187            payload);
0188 
0189 /// The resolved functions to reduce compile time template bloat
0190 /// - GloballyIndexedMaterial 2D
0191 /// @param pAxis0 the proto axis in direction 0
0192 /// @param pAxis1 the proto axis in direction 1
0193 /// @param materialAccessor the material accessor
0194 /// @param boundToGridLocal the delegate from bound to grid local frame
0195 /// @param globalToGridLocal the delegate from global into grid local frame
0196 /// @param payload the grid payload (material slab / indices)
0197 std::unique_ptr<
0198     IGridSurfaceMaterial<GloballyIndexedMaterialAccessor::grid_value_type>>
0199 create(const ProtoAxis& pAxis0, const ProtoAxis& pAxis1,
0200        GloballyIndexedMaterialAccessor&& materialAccessor,
0201        GridAccess::BoundToGridLocal2DimDelegate boundToGridLocal,
0202        GridAccess::GlobalToGridLocal2DimDelegate globalToGridLocal,
0203        const std::vector<
0204            std::vector<GloballyIndexedMaterialAccessor::grid_value_type>>&
0205            payload);
0206 }  // namespace Acts::GridSurfaceMaterialFactory