File indexing completed on 2025-01-18 09:12:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Material/InterpolatedMaterialMap.hpp"
0013 #include "Acts/Material/Material.hpp"
0014 #include "Acts/Material/MaterialMapUtils.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016
0017 #include <array>
0018 #include <cstddef>
0019 #include <vector>
0020
0021 namespace Acts::Test {
0022
0023 BOOST_AUTO_TEST_CASE(materialmap_creation) {
0024
0025 std::vector<double> rPos = {0., 1., 2.};
0026 std::vector<double> xPos = {0., 1., 2.};
0027 std::vector<double> yPos = {0., 1., 2.};
0028 std::vector<double> zPos = {0., 1., 2.};
0029
0030
0031 std::vector<Material> material_rz;
0032 for (int i = 0; i < 9; i++) {
0033 material_rz.push_back(Material::fromMolarDensity(i, i, i, i, i));
0034 }
0035
0036 auto localToGlobalBin_rz = [](std::array<std::size_t, 2> binsRZ,
0037 std::array<std::size_t, 2> nBinsRZ) {
0038 return (binsRZ.at(1) * nBinsRZ.at(0) + binsRZ.at(0));
0039 };
0040
0041 auto mapper_rz =
0042 materialMapperRZ(localToGlobalBin_rz, rPos, zPos, material_rz);
0043
0044 std::vector<std::size_t> nBins_rz = {rPos.size(), zPos.size()};
0045 std::vector<double> minima_rz = {0., 0.};
0046 std::vector<double> maxima_rz = {3., 3.};
0047 BOOST_CHECK(mapper_rz.getNBins() == nBins_rz);
0048
0049
0050 BOOST_CHECK(mapper_rz.getMin() == minima_rz);
0051
0052
0053 BOOST_CHECK(mapper_rz.getMax() == maxima_rz);
0054
0055
0056 std::vector<Material> material_xyz;
0057 for (int i = 0; i < 27; i++) {
0058 material_xyz.push_back(Material::fromMolarDensity(i, i, i, i, i));
0059 }
0060
0061 auto localToGlobalBin_xyz = [](std::array<std::size_t, 3> binsXYZ,
0062 std::array<std::size_t, 3> nBinsXYZ) {
0063 return (binsXYZ.at(0) * (nBinsXYZ.at(1) * nBinsXYZ.at(2)) +
0064 binsXYZ.at(1) * nBinsXYZ.at(2) + binsXYZ.at(2));
0065 };
0066
0067
0068 auto mapper_xyz =
0069 materialMapperXYZ(localToGlobalBin_xyz, xPos, yPos, zPos, material_xyz);
0070
0071 std::vector<std::size_t> nBins_xyz = {xPos.size(), yPos.size(), zPos.size()};
0072 std::vector<double> minima_xyz = {0., 0., 0.};
0073 std::vector<double> maxima_xyz = {3., 3., 3.};
0074 BOOST_CHECK(mapper_xyz.getNBins() == nBins_xyz);
0075
0076
0077 BOOST_CHECK(mapper_xyz.getMin() == minima_xyz);
0078
0079
0080 BOOST_CHECK(mapper_xyz.getMax() == maxima_xyz);
0081
0082
0083 Vector3 pos0_rz(0., 0., 0.);
0084 Vector3 pos1_rz(1., 0., 1.);
0085 Vector3 pos2_rz(0., 2., 2.);
0086 auto value0_rz = mapper_rz.getMaterial(pos0_rz);
0087 auto value1_rz = mapper_rz.getMaterial(pos1_rz);
0088 auto value2_rz = mapper_rz.getMaterial(pos2_rz);
0089
0090 Material mat0_rz = material_rz.at(
0091 localToGlobalBin_rz({{0, 0}}, {{rPos.size(), zPos.size()}}));
0092 Material mat1_rz = material_rz.at(
0093 localToGlobalBin_rz({{1, 1}}, {{rPos.size(), zPos.size()}}));
0094 Material mat2_rz = material_rz.at(
0095 localToGlobalBin_rz({{2, 2}}, {{rPos.size(), zPos.size()}}));
0096
0097
0098
0099 CHECK_CLOSE_ABS(value0_rz.parameters(), mat0_rz.parameters(), 1e-9);
0100 CHECK_CLOSE_ABS(value1_rz.parameters(), mat1_rz.parameters(), 1e-9);
0101 CHECK_CLOSE_ABS(value2_rz.parameters(), mat2_rz.parameters(), 1e-9);
0102
0103
0104 Vector3 pos0_xyz(0., 0., 0.);
0105 Vector3 pos1_xyz(1., 1., 1.);
0106 Vector3 pos2_xyz(2., 2., 2.);
0107 auto value0_xyz = mapper_xyz.getMaterial(pos0_xyz);
0108 auto value1_xyz = mapper_xyz.getMaterial(pos1_xyz);
0109 auto value2_xyz = mapper_xyz.getMaterial(pos2_xyz);
0110
0111 Material mat0_xyz = material_xyz.at(localToGlobalBin_xyz(
0112 {{0, 0, 0}}, {{xPos.size(), yPos.size(), zPos.size()}}));
0113 Material mat1_xyz = material_xyz.at(localToGlobalBin_xyz(
0114 {{1, 1, 1}}, {{xPos.size(), yPos.size(), zPos.size()}}));
0115 Material mat2_xyz = material_xyz.at(localToGlobalBin_xyz(
0116 {{2, 2, 2}}, {{xPos.size(), yPos.size(), zPos.size()}}));
0117
0118
0119
0120 CHECK_CLOSE_ABS(value0_xyz.parameters(), mat0_xyz.parameters(), 1e-9);
0121 CHECK_CLOSE_ABS(value1_xyz.parameters(), mat1_xyz.parameters(), 1e-9);
0122 CHECK_CLOSE_ABS(value2_xyz.parameters(), mat2_xyz.parameters(), 1e-9);
0123 }
0124 }