File indexing completed on 2025-01-18 09:13:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Material/GridSurfaceMaterial.hpp"
0012 #include "Acts/Material/Material.hpp"
0013 #include "Acts/Material/MaterialSlab.hpp"
0014 #include "Acts/Plugins/Json/MaterialJsonConverter.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016 #include "Acts/Utilities/GridAccessHelpers.hpp"
0017 #include "Acts/Utilities/GridAxisGenerators.hpp"
0018
0019 #include <array>
0020 #include <fstream>
0021 #include <memory>
0022 #include <numbers>
0023 #include <vector>
0024
0025 #include <nlohmann/json.hpp>
0026
0027 BOOST_AUTO_TEST_SUITE(MaterialJsonIO)
0028
0029 BOOST_AUTO_TEST_CASE(IndexedSurfaceMaterial1DTests) {
0030 std::vector<Acts::MaterialSlab> material;
0031 material.emplace_back(Acts::Material(), 0.0);
0032 material.emplace_back(
0033 Acts::Material::fromMolarDensity(1.0, 2.0, 3.0, 4.0, 5.0), 1.0);
0034 material.emplace_back(
0035 Acts::Material::fromMolarDensity(11.0, 12.0, 13.0, 14.0, 15.0), 2.0);
0036 material.emplace_back(
0037 Acts::Material::fromMolarDensity(21.0, 22.0, 23.0, 24.0, 25.0), 3.0);
0038
0039 using EqBound = Acts::GridAxisGenerators::EqBound;
0040 using EqGrid = EqBound::grid_type<std::size_t>;
0041 using Point = EqGrid::point_t;
0042
0043 EqBound eqBound{{0., 5.}, 5};
0044 EqGrid eqGrid{eqBound()};
0045
0046 eqGrid.atPosition(Point{0.5}) = 1u;
0047 eqGrid.atPosition(Point{1.5}) = 0u;
0048 eqGrid.atPosition(Point{2.5}) = 2u;
0049 eqGrid.atPosition(Point{3.5}) = 2u;
0050 eqGrid.atPosition(Point{4.5}) = 3u;
0051
0052 auto localX = std::make_unique<const Acts::GridAccess::LocalSubspace<0u>>();
0053 Acts::IndexedSurfaceMaterial<EqGrid>::BoundToGridLocalDelegate bToX;
0054 bToX.connect<&Acts::GridAccess::LocalSubspace<0u>::toGridLocal>(
0055 std::move(localX));
0056
0057 auto globalX = std::make_unique<
0058 const Acts::GridAccess::GlobalSubspace<Acts::AxisDirection::AxisX>>();
0059 Acts::IndexedSurfaceMaterial<EqGrid>::GlobalToGridLocalDelegate gToX;
0060 gToX.connect<&Acts::GridAccess::GlobalSubspace<
0061 Acts::AxisDirection::AxisX>::toGridLocal>(std::move(globalX));
0062
0063 Acts::IndexedSurfaceMaterial<EqGrid> ism(
0064 std::move(eqGrid), Acts::IndexedMaterialAccessor{std::move(material)},
0065 std::move(bToX), std::move(gToX));
0066
0067 nlohmann::json jMaterial = &ism;
0068
0069
0070 BOOST_REQUIRE(jMaterial.find("material") != jMaterial.end());
0071
0072
0073 const Acts::ISurfaceMaterial* ismRead = nullptr;
0074 Acts::from_json(jMaterial, ismRead);
0075 BOOST_REQUIRE(ismRead != nullptr);
0076
0077
0078 const Acts::IndexedSurfaceMaterial<EqGrid>* ismReadTyped =
0079 dynamic_cast<const Acts::IndexedSurfaceMaterial<EqGrid>*>(ismRead);
0080 BOOST_REQUIRE(ismReadTyped != nullptr);
0081
0082 auto gridRead = ismReadTyped->grid();
0083 BOOST_CHECK(gridRead.atPosition(Point{0.5}) == 1u);
0084 BOOST_CHECK(gridRead.atPosition(Point{1.5}) == 0u);
0085 BOOST_CHECK(gridRead.atPosition(Point{2.5}) == 2u);
0086 BOOST_CHECK(gridRead.atPosition(Point{3.5}) == 2u);
0087 BOOST_CHECK(gridRead.atPosition(Point{4.5}) == 3u);
0088
0089
0090 auto accessorRead = ismReadTyped->materialAccessor();
0091 CHECK_CLOSE_ABS(accessorRead.material[0].thickness(), 0.0, 1e-5);
0092 CHECK_CLOSE_ABS(accessorRead.material[1].thickness(), 1.0, 1e-5);
0093 CHECK_CLOSE_ABS(accessorRead.material[2].thickness(), 2.0, 1e-5);
0094 CHECK_CLOSE_ABS(accessorRead.material[3].thickness(), 3.0, 1e-5);
0095 }
0096
0097 BOOST_AUTO_TEST_CASE(IndexedSurfaceMaterial2DTests) {
0098 std::vector<Acts::MaterialSlab> material;
0099 material.emplace_back(Acts::Material(), 1.0);
0100 material.emplace_back(
0101 Acts::Material::fromMolarDensity(1.0, 2.0, 3.0, 4.0, 5.0), 1.0);
0102 material.emplace_back(
0103 Acts::Material::fromMolarDensity(11.0, 12.0, 13.0, 14.0, 15.0), 1.0);
0104 material.emplace_back(
0105 Acts::Material::fromMolarDensity(21.0, 22.0, 23.0, 24.0, 25.0), 1.0);
0106
0107 using EqBoundEqClosed = Acts::GridAxisGenerators::EqBoundEqClosed;
0108 using EqEqGrid = EqBoundEqClosed::grid_type<std::size_t>;
0109 using Point = EqEqGrid::point_t;
0110
0111 EqBoundEqClosed eqeqBound{
0112 {-1., 1.}, 2, {-std::numbers::pi, std::numbers::pi}, 4};
0113 EqEqGrid eqeqGrid{eqeqBound()};
0114
0115 eqeqGrid.atPosition(Point{-0.5, -std::numbers::pi * 0.75}) =
0116 1u;
0117 eqeqGrid.atPosition(Point{-0.5, -std::numbers::pi / 4.}) = 1u;
0118 eqeqGrid.atPosition(Point{-0.5, std::numbers::pi / 4.}) = 0u;
0119 eqeqGrid.atPosition(Point{-0.5, std::numbers::pi * 0.75}) = 2u;
0120
0121 eqeqGrid.atPosition(Point{0.5, -std::numbers::pi * 0.75}) = 0u;
0122 eqeqGrid.atPosition(Point{0.5, -std::numbers::pi / 4.}) = 3u;
0123 eqeqGrid.atPosition(Point{0.5, std::numbers::pi / 4.}) = 3u;
0124 eqeqGrid.atPosition(Point{0.5, std::numbers::pi * 0.75}) = 0u;
0125
0126 auto boundToGrid =
0127 std::make_unique<const Acts::GridAccess::LocalSubspace<0u, 1u>>();
0128 Acts::IndexedSurfaceMaterial<EqEqGrid>::BoundToGridLocalDelegate bToZPhi;
0129 bToZPhi.connect<&Acts::GridAccess::LocalSubspace<0u, 1u>::toGridLocal>(
0130 std::move(boundToGrid));
0131
0132
0133 auto globalToGrid = std::make_unique<const Acts::GridAccess::GlobalSubspace<
0134 Acts::AxisDirection::AxisZ, Acts::AxisDirection::AxisPhi>>();
0135 Acts::IndexedSurfaceMaterial<EqEqGrid>::GlobalToGridLocalDelegate gToZphi;
0136 gToZphi.connect<&Acts::GridAccess::GlobalSubspace<
0137 Acts::AxisDirection::AxisZ, Acts::AxisDirection::AxisPhi>::toGridLocal>(
0138 std::move(globalToGrid));
0139
0140
0141 Acts::IndexedSurfaceMaterial<EqEqGrid> ism(
0142 std::move(eqeqGrid), Acts::IndexedMaterialAccessor{std::move(material)},
0143 std::move(bToZPhi), std::move(gToZphi));
0144
0145 nlohmann::json jMaterial = &ism;
0146
0147
0148 BOOST_REQUIRE(jMaterial.find("material") != jMaterial.end());
0149
0150
0151 const Acts::ISurfaceMaterial* ismRead = nullptr;
0152 Acts::from_json(jMaterial, ismRead);
0153 BOOST_REQUIRE(ismRead != nullptr);
0154 }
0155
0156 BOOST_AUTO_TEST_SUITE_END()