Analysis Software
Documentation for sPHENIX simulation 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 
21 
22 #include <array>
23 #include <cstddef>
24 #include <functional>
25 #include <iosfwd>
26 #include <optional>
27 #include <tuple>
28 #include <utility>
29 #include <vector>
30 
31 namespace Acts {
32 
33 namespace Test {
34 
35 constexpr unsigned int dim = 2;
38 
40  return {global.x(), global.y()};
41 }
42 
43 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_MaterialCell_test) {
44  // Build a material cell
45  std::array<double, dim> lowerLeft{{0., 0.}};
46  std::array<double, dim> upperRight{{1., 1.}};
48  mat << 1, 2, 3, 4, 5;
49  std::array<Acts::Material::ParametersVector, 4> matArray = {mat, mat, mat,
50  mat};
51 
53  trafoGlobalToLocal, lowerLeft, upperRight, matArray);
54 
55  // Test InterpolatedMaterialMap::MaterialCell<DIM>::isInside method
56  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0.5, 0.5, 0.5)), true);
57  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(-1., 0., 0.)), false);
58  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0., -1., 0.)), false);
59  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0., 0., -1.)), true);
60  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(2., 0., 0.)), false);
61  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0., 2., 0.)), false);
62  BOOST_CHECK_EQUAL(materialCell.isInside(Vector3(0., 0., 2.)), true);
63 
64  // Test the getter
65  CHECK_CLOSE_REL(materialCell.getMaterial({0.5, 0.5, 0.5}), Material(mat),
66  1e-4);
67 }
68 
69 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_MaterialMapper_test) {
70  // Create the axes for the grid
71  detail::EquidistantAxis axisX(0, 3, 3);
72  detail::EquidistantAxis axisY(0, 3, 3);
73 
74  // The material mapping grid
75  auto grid = grid_t(std::make_tuple(std::move(axisX), std::move(axisY)));
77  mat << 1, 2, 3, 4, 5;
78 
79  for (size_t i = 0; i < grid.size(); i++) {
80  grid.at(i) = mat;
81  }
83 
84  // Test Material getter
85  CHECK_CLOSE_REL(matMap.getMaterial({0.5, 0.5, 0.5}), Material(mat), 1e-4);
86 
87  // Test the MaterialCell getter
89  matMap.getMaterialCell({0.5, 0.5, 0.5});
90  CHECK_CLOSE_REL(matCell.getMaterial({0.5, 0.5, 0.5}), Material(mat), 1e-4);
91 
92  // Test the number of bins getter
93  std::vector<size_t> nBins = matMap.getNBins();
94  BOOST_CHECK_EQUAL(nBins[0], 3u);
95  BOOST_CHECK_EQUAL(nBins[1], 3u);
96 
97  // Test the lower limits
98  std::vector<double> limits = matMap.getMin();
99  CHECK_CLOSE_ABS(limits[0], 0., 1e-4);
100  CHECK_CLOSE_ABS(limits[1], 0., 1e-4);
101 
102  // Test the upper limits
103  limits = matMap.getMax();
104  CHECK_CLOSE_REL(limits[0], 3., 1e-4);
105  CHECK_CLOSE_REL(limits[1], 3., 1e-4);
106 
107  // Test the inside check
108  BOOST_CHECK_EQUAL(matMap.isInside(Vector3(1., 1., 1.)), true);
109  BOOST_CHECK_EQUAL(matMap.isInside(Vector3(-1., 0., 0.)), false);
110  BOOST_CHECK_EQUAL(matMap.isInside(Vector3(0., -1., 0.)), false);
111  BOOST_CHECK_EQUAL(matMap.isInside(Vector3(0., 0., -1.)), true);
112  BOOST_CHECK_EQUAL(matMap.isInside(Vector3(4., 0., 0.)), false);
113  BOOST_CHECK_EQUAL(matMap.isInside(Vector3(0., 4., 0.)), false);
114  BOOST_CHECK_EQUAL(matMap.isInside(Vector3(0., 0., 4.)), true);
115 
116  // Test the grid getter
117  auto matMapGrid = matMap.getGrid();
118  for (unsigned int i = 0; i < dim; i++) {
119  BOOST_CHECK_EQUAL(grid.numLocalBins()[i], matMapGrid.numLocalBins()[i]);
120  BOOST_CHECK_EQUAL(grid.minPosition()[i], matMapGrid.minPosition()[i]);
121  BOOST_CHECK_EQUAL(grid.maxPosition()[i], matMapGrid.maxPosition()[i]);
122  }
123  for (size_t i = 0; i < grid.size(); i++) {
124  CHECK_CLOSE_REL(grid.at(i), matMapGrid.at(i), 1e-4);
125  }
126 }
127 
128 BOOST_AUTO_TEST_CASE(InterpolatedMaterialMap_test) {
129  // Create the axes for the grid
130  detail::EquidistantAxis axisX(0, 3, 3);
131  detail::EquidistantAxis axisY(0, 3, 3);
132 
133  // The material mapping grid
134  auto grid = grid_t(std::make_tuple(std::move(axisX), std::move(axisY)));
136  mat << 1, 2, 3, 4, 5;
137 
138  for (size_t i = 0; i < grid.size(); i++) {
139  grid.at(i) = mat;
140  }
142  InterpolatedMaterialMap ipolMatMap(std::move(matMap));
143 
144  // Test the material getter
145  CHECK_CLOSE_REL(ipolMatMap.material({0.5, 0.5, 0.5}), Material(mat), 1e-4);
146 
147  // Test the material getter with a cache
148  // Build a material cell
149  std::array<double, dim> lowerLeft{{0., 0.}};
150  std::array<double, dim> upperRight{{1., 1.}};
151  std::array<Acts::Material::ParametersVector, 4> matArray = {mat, mat, mat,
152  mat};
153 
154  MaterialMapper<grid_t>::MaterialCell materialCell(
155  trafoGlobalToLocal, lowerLeft, upperRight, matArray);
156  InterpolatedMaterialMap<MaterialMapper<grid_t>>::Cache cache;
157  cache.matCell = materialCell;
158  cache.initialized = true;
159  CHECK_CLOSE_REL(ipolMatMap.getMaterial(Vector3(0.5, 0.5, 0.5), cache),
160  Material(mat), 1e-4);
161 
162  // Test the inside check
163  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(1., 1., 1.)), true);
164  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(-1., 0., 0.)), false);
165  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(0., -1., 0.)), false);
166  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(0., 0., -1.)), true);
167  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(4., 0., 0.)), false);
168  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(0., 4., 0.)), false);
169  BOOST_CHECK_EQUAL(ipolMatMap.isInside(Vector3(0., 0., 4.)), true);
170 }
171 } // namespace Test
172 
173 } // namespace Acts