EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InterpolatedMaterialMapTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InterpolatedMaterialMapTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include <boost/test/data/test_case.hpp>
12 #include <boost/test/unit_test.hpp>
13 
19 
20 #include <array>
21 
22 namespace Acts {
23 
24 namespace Test {
25 
26 constexpr unsigned int dim = 2;
29 
31  return {global.x(), global.y()};
32 }
33 
34 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_MaterialCell_test) {
35  // Build a material cell
36  std::array<double, dim> lowerLeft{{0., 0.}};
37  std::array<double, dim> upperRight{{1., 1.}};
38  ActsVectorF<5> mat;
39  mat << 1, 2, 3, 4, 5;
40  std::array<ActsVectorF<5>, 4> matArray = {mat, mat, mat, mat};
41 
43  trafoGlobalToLocal, lowerLeft, upperRight, matArray);
44 
45  // Test InterpolatedMaterialMap::MaterialCell<DIM>::isInside method
46  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3D(0.5, 0.5, 0.5)), true);
47  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3D(-1., 0., 0.)), false);
48  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3D(0., -1., 0.)), false);
49  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3D(0., 0., -1.)), true);
50  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3D(2., 0., 0.)), false);
51  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3D(0., 2., 0.)), false);
52  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3D(0., 0., 2.)), true);
53 
54  // Test the getter
55  CHECK_CLOSE_REL(materialCell.getMaterial({0.5, 0.5, 0.5}), Material(mat),
56  1e-4);
57 }
58 
59 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_MaterialMapper_test) {
60  // Create the axes for the grid
61  detail::EquidistantAxis axisX(0, 3, 3);
62  detail::EquidistantAxis axisY(0, 3, 3);
63 
64  // The material mapping grid
65  auto grid = grid_t(std::make_tuple(std::move(axisX), std::move(axisY)));
66  ActsVectorF<5> mat;
67  mat << 1, 2, 3, 4, 5;
68 
69  for (size_t i = 0; i < grid.size(); i++) {
70  grid.at(i) = mat;
71  }
73 
74  // Test Material getter
75  CHECK_CLOSE_REL(matMap.getMaterial({0.5, 0.5, 0.5}), Material(mat), 1e-4);
76 
77  // Test the MaterialCell getter
79  matMap.getMaterialCell({0.5, 0.5, 0.5});
80  CHECK_CLOSE_REL(matCell.getMaterial({0.5, 0.5, 0.5}), Material(mat), 1e-4);
81 
82  // Test the number of bins getter
83  std::vector<size_t> nBins = matMap.getNBins();
84  BOOST_CHECK_EQUAL(nBins[0], 3u);
85  BOOST_CHECK_EQUAL(nBins[1], 3u);
86 
87  // Test the lower limits
88  std::vector<double> limits = matMap.getMin();
89  CHECK_CLOSE_ABS(limits[0], 0., 1e-4);
90  CHECK_CLOSE_ABS(limits[1], 0., 1e-4);
91 
92  // Test the upper limits
93  limits = matMap.getMax();
94  CHECK_CLOSE_REL(limits[0], 3., 1e-4);
95  CHECK_CLOSE_REL(limits[1], 3., 1e-4);
96 
97  // Test the inside check
98  BOOST_CHECK_EQUAL(matMap.isInside(Vector3D(1., 1., 1.)), true);
99  BOOST_CHECK_EQUAL(matMap.isInside(Vector3D(-1., 0., 0.)), false);
100  BOOST_CHECK_EQUAL(matMap.isInside(Vector3D(0., -1., 0.)), false);
101  BOOST_CHECK_EQUAL(matMap.isInside(Vector3D(0., 0., -1.)), true);
102  BOOST_CHECK_EQUAL(matMap.isInside(Vector3D(4., 0., 0.)), false);
103  BOOST_CHECK_EQUAL(matMap.isInside(Vector3D(0., 4., 0.)), false);
104  BOOST_CHECK_EQUAL(matMap.isInside(Vector3D(0., 0., 4.)), true);
105 
106  // Test the grid getter
107  auto matMapGrid = matMap.getGrid();
108  for (unsigned int i = 0; i < dim; i++) {
109  BOOST_CHECK_EQUAL(grid.numLocalBins()[i], matMapGrid.numLocalBins()[i]);
110  BOOST_CHECK_EQUAL(grid.minPosition()[i], matMapGrid.minPosition()[i]);
111  BOOST_CHECK_EQUAL(grid.maxPosition()[i], matMapGrid.maxPosition()[i]);
112  }
113  for (size_t i = 0; i < grid.size(); i++) {
114  CHECK_CLOSE_REL(grid.at(i), matMapGrid.at(i), 1e-4);
115  }
116 }
117 
118 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_test) {
119  // Create the axes for the grid
120  detail::EquidistantAxis axisX(0, 3, 3);
121  detail::EquidistantAxis axisY(0, 3, 3);
122 
123  // The material mapping grid
124  auto grid = grid_t(std::make_tuple(std::move(axisX), std::move(axisY)));
125  ActsVectorF<5> mat;
126  mat << 1, 2, 3, 4, 5;
127 
128  for (size_t i = 0; i < grid.size(); i++) {
129  grid.at(i) = mat;
130  }
132  InterpolatedMaterialMap ipolMatMap(std::move(matMap));
133 
134  // Test the material getter
135  CHECK_CLOSE_REL(ipolMatMap.material({0.5, 0.5, 0.5}), Material(mat), 1e-4);
136 
137  // Test the material getter with a cache
138  // Build a material cell
139  std::array<double, dim> lowerLeft{{0., 0.}};
140  std::array<double, dim> upperRight{{1., 1.}};
141  std::array<ActsVectorF<5>, 4> matArray = {mat, mat, mat, mat};
142 
143  MaterialMapper<grid_t>::MaterialCell materialCell(
144  trafoGlobalToLocal, lowerLeft, upperRight, matArray);
145  InterpolatedMaterialMap<MaterialMapper<grid_t>>::Cache cache;
146  cache.matCell = materialCell;
147  cache.initialized = true;
148  CHECK_CLOSE_REL(ipolMatMap.getMaterial(Vector3D(0.5, 0.5, 0.5), cache),
149  Material(mat), 1e-4);
150 
151  // Test the inside check
152  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3D(1., 1., 1.)), true);
153  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3D(-1., 0., 0.)), false);
154  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3D(0., -1., 0.)), false);
155  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3D(0., 0., -1.)), true);
156  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3D(4., 0., 0.)), false);
157  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3D(0., 4., 0.)), false);
158  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3D(0., 0., 4.)), true);
159 }
160 } // namespace Test
161 
162 } // namespace Acts