File indexing completed on 2025-01-18 09:12:43
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/Tests/CommonHelpers/FloatComparisons.hpp"
0015 #include "Acts/Utilities/Axis.hpp"
0016 #include "Acts/Utilities/AxisDefinitions.hpp"
0017 #include "Acts/Utilities/Grid.hpp"
0018
0019 #include <array>
0020 #include <cstddef>
0021 #include <functional>
0022 #include <iosfwd>
0023 #include <optional>
0024 #include <tuple>
0025 #include <utility>
0026 #include <vector>
0027
0028 namespace Acts::Test {
0029
0030 constexpr unsigned int dim = 2;
0031 using grid_t = Grid<Acts::Material::ParametersVector,
0032 Axis<AxisType::Equidistant>, Axis<AxisType::Equidistant>>;
0033
0034 ActsVector<dim> trafoGlobalToLocal(const Vector3& global) {
0035 return {global.x(), global.y()};
0036 }
0037
0038 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_MaterialCell_test) {
0039
0040 std::array<double, dim> lowerLeft{{0., 0.}};
0041 std::array<double, dim> upperRight{{1., 1.}};
0042 Acts::Material::ParametersVector mat;
0043 mat << 1, 2, 3, 4, 5;
0044 std::array<Acts::Material::ParametersVector, 4> matArray = {mat, mat, mat,
0045 mat};
0046
0047 MaterialMapper<grid_t>::MaterialCell materialCell(
0048 trafoGlobalToLocal, lowerLeft, upperRight, matArray);
0049
0050
0051 BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0.5, 0.5, 0.5)), true);
0052 BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(-1., 0., 0.)), false);
0053 BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0., -1., 0.)), false);
0054 BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0., 0., -1.)), true);
0055 BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(2., 0., 0.)), false);
0056 BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0., 2., 0.)), false);
0057 BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0., 0., 2.)), true);
0058
0059
0060 BOOST_CHECK_EQUAL(materialCell.getMaterial({0.5, 0.5, 0.5}), Material(mat));
0061 }
0062
0063 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_MaterialMapper_test) {
0064
0065 Axis axisX(0, 3, 3);
0066 Axis axisY(0, 3, 3);
0067
0068
0069 auto grid = grid_t(std::make_tuple(std::move(axisX), std::move(axisY)));
0070 Acts::Material::ParametersVector mat;
0071 mat << 1, 2, 3, 4, 5;
0072
0073 for (std::size_t i = 0; i < grid.size(); i++) {
0074 grid.at(i) = mat;
0075 }
0076 MaterialMapper<grid_t> matMap(trafoGlobalToLocal, grid);
0077
0078
0079 BOOST_CHECK_EQUAL(matMap.getMaterial({0.5, 0.5, 0.5}), Material(mat));
0080
0081
0082 MaterialMapper<grid_t>::MaterialCell matCell =
0083 matMap.getMaterialCell({0.5, 0.5, 0.5});
0084 BOOST_CHECK_EQUAL(matCell.getMaterial({0.5, 0.5, 0.5}), Material(mat));
0085
0086
0087 std::vector<std::size_t> nBins = matMap.getNBins();
0088 BOOST_CHECK_EQUAL(nBins[0], 3u);
0089 BOOST_CHECK_EQUAL(nBins[1], 3u);
0090
0091
0092 std::vector<double> limits = matMap.getMin();
0093 CHECK_CLOSE_ABS(limits[0], 0., 1e-4);
0094 CHECK_CLOSE_ABS(limits[1], 0., 1e-4);
0095
0096
0097 limits = matMap.getMax();
0098 CHECK_CLOSE_REL(limits[0], 3., 1e-4);
0099 CHECK_CLOSE_REL(limits[1], 3., 1e-4);
0100
0101
0102 BOOST_CHECK_EQUAL(matMap.isInside(Vector3(1., 1., 1.)), true);
0103 BOOST_CHECK_EQUAL(matMap.isInside(Vector3(-1., 0., 0.)), false);
0104 BOOST_CHECK_EQUAL(matMap.isInside(Vector3(0., -1., 0.)), false);
0105 BOOST_CHECK_EQUAL(matMap.isInside(Vector3(0., 0., -1.)), true);
0106 BOOST_CHECK_EQUAL(matMap.isInside(Vector3(4., 0., 0.)), false);
0107 BOOST_CHECK_EQUAL(matMap.isInside(Vector3(0., 4., 0.)), false);
0108 BOOST_CHECK_EQUAL(matMap.isInside(Vector3(0., 0., 4.)), true);
0109
0110
0111 auto matMapGrid = matMap.getGrid();
0112 for (unsigned int i = 0; i < dim; i++) {
0113 BOOST_CHECK_EQUAL(grid.numLocalBins()[i], matMapGrid.numLocalBins()[i]);
0114 BOOST_CHECK_EQUAL(grid.minPosition()[i], matMapGrid.minPosition()[i]);
0115 BOOST_CHECK_EQUAL(grid.maxPosition()[i], matMapGrid.maxPosition()[i]);
0116 }
0117 for (std::size_t i = 0; i < grid.size(); i++) {
0118 CHECK_CLOSE_REL(grid.at(i), matMapGrid.at(i), 1e-4);
0119 }
0120 }
0121
0122 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_test) {
0123
0124 Axis axisX(0, 3, 3);
0125 Axis axisY(0, 3, 3);
0126
0127
0128 auto grid = grid_t(std::make_tuple(std::move(axisX), std::move(axisY)));
0129 Acts::Material::ParametersVector mat;
0130 mat << 1, 2, 3, 4, 5;
0131
0132 for (std::size_t i = 0; i < grid.size(); i++) {
0133 grid.at(i) = mat;
0134 }
0135 MaterialMapper<grid_t> matMap(trafoGlobalToLocal, grid);
0136 InterpolatedMaterialMap ipolMatMap(std::move(matMap));
0137
0138
0139 BOOST_CHECK_EQUAL(ipolMatMap.material({0.5, 0.5, 0.5}), Material(mat));
0140
0141
0142
0143 std::array<double, dim> lowerLeft{{0., 0.}};
0144 std::array<double, dim> upperRight{{1., 1.}};
0145 std::array<Acts::Material::ParametersVector, 4> matArray = {mat, mat, mat,
0146 mat};
0147
0148 MaterialMapper<grid_t>::MaterialCell materialCell(
0149 trafoGlobalToLocal, lowerLeft, upperRight, matArray);
0150 InterpolatedMaterialMap<MaterialMapper<grid_t>>::Cache cache;
0151 cache.matCell = materialCell;
0152 cache.initialized = true;
0153 BOOST_CHECK_EQUAL(ipolMatMap.getMaterial(Vector3(0.5, 0.5, 0.5), cache),
0154 Material(mat));
0155
0156
0157 BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(1., 1., 1.)), true);
0158 BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(-1., 0., 0.)), false);
0159 BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(0., -1., 0.)), false);
0160 BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(0., 0., -1.)), true);
0161 BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(4., 0., 0.)), false);
0162 BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(0., 4., 0.)), false);
0163 BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(0., 0., 4.)), true);
0164 }
0165 }