Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:16

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 #include "ActsPlugins/Detray/DetrayPayloadConverter.hpp"
0010 //
0011 #include "Acts/Material/BinnedSurfaceMaterial.hpp"
0012 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0013 #include "Acts/Material/MaterialSlab.hpp"
0014 #include "Acts/Material/ProtoSurfaceMaterial.hpp"
0015 #include "Acts/Utilities/BinUtility.hpp"
0016 #include "Acts/Utilities/BinningType.hpp"
0017 #include "ActsPlugins/Detray/DetrayConversionUtils.hpp"
0018 
0019 #include <stdexcept>
0020 
0021 #include <detray/io/frontend/payloads.hpp>
0022 
0023 using namespace Acts;
0024 
0025 namespace ActsPlugins {
0026 
0027 using DetraySurfaceMaterial = DetrayPayloadConverter::DetraySurfaceMaterial;
0028 using DetraySurfaceGrid = DetrayPayloadConverter::DetraySurfaceGrid;
0029 
0030 std::optional<DetraySurfaceMaterial>
0031 DetrayPayloadConverter::convertBinnedSurfaceMaterial(
0032     const BinnedSurfaceMaterial& material) {
0033   using enum AxisDirection;
0034   // Get the bin utility and convert to 2D if needed
0035   // Detray expects 2-dimensional grid, currently supported are
0036   // x-y, r-phi, phi-z
0037   auto [bUtility, swapped] =
0038       DetrayConversionUtils::convertBinUtilityTo2D(material.binUtility());
0039 
0040   AxisDirection bVal0 = bUtility.binningData()[0u].binvalue;
0041   AxisDirection bVal1 = bUtility.binningData()[1u].binvalue;
0042 
0043   // Translate into grid index type
0044   detray::io::material_id gridIndexType = detray::io::material_id::unknown;
0045   if (bVal0 == AxisR && bVal1 == AxisPhi) {
0046     gridIndexType = detray::io::material_id::ring2_map;
0047   } else if (bVal0 == AxisPhi && bVal1 == AxisZ) {
0048     gridIndexType = detray::io::material_id::concentric_cylinder2_map;
0049   } else if (bVal0 == AxisX && bVal1 == AxisY) {
0050     gridIndexType = detray::io::material_id::rectangle2_map;
0051   } else {
0052     std::runtime_error(
0053         "DetrayMaterialConverter: Unsupported binning for Detray");
0054   }
0055 
0056   detray::io::grid_payload<detray::io::material_slab_payload,
0057                            detray::io::material_id>
0058       materialGrid;
0059 
0060   detray::io::typed_link_payload<detray::io::material_id> linkPayload{
0061       gridIndexType, 0u};
0062   materialGrid.grid_link = linkPayload;
0063 
0064   // Now convert the (modified) bin utility
0065   for (const auto& bData : bUtility.binningData()) {
0066     auto axisPayload = DetrayConversionUtils::convertBinningData(bData);
0067     materialGrid.axes.push_back(axisPayload);
0068   }
0069 
0070   // Convert the material slabs from the material matrix
0071   auto materialMatrix = material.fullMaterial();
0072   for (std::size_t ib1 = 0; ib1 < materialMatrix.size(); ++ib1) {
0073     for (std::size_t ib0 = 0; ib0 < materialMatrix[0u].size(); ++ib0) {
0074       // Translate into a local bin
0075       std::size_t lb0 = swapped ? ib1 : ib0;
0076       std::size_t lb1 = swapped ? ib0 : ib1;
0077       detray::io::material_slab_payload slab =
0078           DetrayConversionUtils::convertMaterialSlab(materialMatrix[ib1][ib0]);
0079       detray::io::grid_bin_payload<detray::io::material_slab_payload> slabBin{
0080           {static_cast<unsigned int>(lb0), static_cast<unsigned int>(lb1)},
0081           {slab}};
0082       // Fill into the grid
0083       materialGrid.bins.push_back(slabBin);
0084     }
0085   }
0086   return materialGrid;
0087 }
0088 
0089 std::optional<DetraySurfaceMaterial>
0090 DetrayPayloadConverter::convertGridSurfaceMaterial(
0091     const IGridSurfaceMaterialBase& /*material*/) {
0092   throw DetrayUnsupportedMaterialException("detail::IGridSurfaceMaterialBase");
0093 }
0094 
0095 std::optional<DetraySurfaceMaterial>
0096 DetrayPayloadConverter::convertHomogeneousSurfaceMaterial(
0097     const HomogeneousSurfaceMaterial& material) {
0098   return DetrayConversionUtils::convertMaterialSlab(material.materialSlab());
0099 }
0100 
0101 std::optional<DetraySurfaceMaterial>
0102 DetrayPayloadConverter::convertProtoSurfaceMaterialBinUtility(
0103     const ProtoSurfaceMaterialT<Acts::BinUtility>& /*material*/) {
0104   return std::nullopt;
0105 }
0106 
0107 std::optional<DetraySurfaceMaterial>
0108 DetrayPayloadConverter::convertProtoSurfaceMaterialProtoAxes(
0109     const ProtoSurfaceMaterialT<std::vector<DirectedProtoAxis>>& /*material*/) {
0110   return std::nullopt;
0111 }
0112 
0113 DetrayUnsupportedMaterialException::DetrayUnsupportedMaterialException(
0114     std::string_view name)
0115     : std::runtime_error(std::string("Material type ") + std::string(name) +
0116                          " not supported by detray") {}
0117 
0118 }  // namespace ActsPlugins