File indexing completed on 2026-01-06 09:23:52
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/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/IndexGrid.hpp"
0014 #include "Acts/Geometry/ReferenceGenerators.hpp"
0015 #include "Acts/Surfaces/CylinderSurface.hpp"
0016 #include "Acts/Surfaces/PlaneSurface.hpp"
0017 #include "Acts/Surfaces/RectangleBounds.hpp"
0018 #include "Acts/Utilities/Axis.hpp"
0019 #include "Acts/Utilities/Grid.hpp"
0020 #include "Acts/Utilities/Logger.hpp"
0021
0022 using namespace Acts;
0023
0024 namespace {
0025
0026
0027 template <typename indexed_surface_grid>
0028 std::size_t countBins(const indexed_surface_grid& isGrid) {
0029 std::size_t nonEmptyBins = 0u;
0030 for (std::size_t igb = 0u; igb < isGrid.grid.size(); ++igb) {
0031 const auto& gb = isGrid.grid.at(igb);
0032 if (!gb.empty()) {
0033 ++nonEmptyBins;
0034 }
0035 }
0036 return nonEmptyBins;
0037 }
0038
0039 }
0040
0041 namespace ActsTests {
0042
0043 GeometryContext tContext;
0044
0045 Logging::Level logLevel = Logging::VERBOSE;
0046
0047 BOOST_AUTO_TEST_SUITE(NavigationSuite)
0048
0049 BOOST_AUTO_TEST_CASE(IndexGridXYOneSurfaceCenter) {
0050 ACTS_LOCAL_LOGGER(getDefaultLogger("*** Test 0", logLevel));
0051 ACTS_INFO("Testing X-Y grid.");
0052 ACTS_INFO("Testing one surface with center generator, should lead to 1 bin.");
0053
0054
0055 Axis axisX(AxisBound, -5., 5., 5);
0056 Axis axisY(AxisBound, -5., 5., 5);
0057 Grid gridXY(Type<std::vector<unsigned int>>, std::move(axisX),
0058 std::move(axisY));
0059
0060
0061 IndexGrid<decltype(gridXY)> indexedGridXY(
0062 std::move(gridXY), {AxisDirection::AxisX, AxisDirection::AxisY});
0063
0064
0065 auto rBounds = std::make_shared<RectangleBounds>(4., 4.);
0066 auto pSurface = Surface::makeShared<PlaneSurface>(Transform3::Identity(),
0067 std::move(rBounds));
0068
0069
0070 IndexGridFiller filler{{}};
0071 filler.oLogger = getDefaultLogger("IndexGridFiller", Logging::VERBOSE);
0072 CenterReferenceGenerator generator;
0073 std::vector<std::shared_ptr<Surface>> surfaces = {pSurface};
0074
0075
0076 filler.fill(tContext, indexedGridXY, surfaces, generator);
0077
0078 std::size_t nonEmptyBins = countBins<decltype(indexedGridXY)>(indexedGridXY);
0079
0080 ACTS_INFO("- filled " << nonEmptyBins << " bins of the grid.");
0081 BOOST_CHECK_EQUAL(nonEmptyBins, 1u);
0082 }
0083
0084 BOOST_AUTO_TEST_CASE(IndexGridXYOneSurfaceBinValue) {
0085 ACTS_LOCAL_LOGGER(getDefaultLogger("*** Test 1", logLevel));
0086 ACTS_INFO("Testing X-Y grid.");
0087 ACTS_INFO(
0088 "Testing one surface with bin value generator, should lead to 1 bin.");
0089
0090
0091 Axis axisX(AxisBound, -5., 5., 5);
0092 Axis axisY(AxisBound, -5., 5., 5);
0093 Grid gridXY(Type<std::vector<unsigned int>>, std::move(axisX),
0094 std::move(axisY));
0095
0096
0097 IndexGrid<decltype(gridXY)> indexedGridXY(
0098 std::move(gridXY), {AxisDirection::AxisX, AxisDirection::AxisY});
0099
0100
0101 auto rBounds = std::make_shared<RectangleBounds>(4., 4.);
0102 auto pSurface = Surface::makeShared<PlaneSurface>(Transform3::Identity(),
0103 std::move(rBounds));
0104
0105
0106 IndexGridFiller filler{{}};
0107 filler.oLogger = getDefaultLogger("IndexGridFiller", Logging::VERBOSE);
0108
0109 AxisDirectionReferenceGenerator<AxisDirection::AxisX> generator;
0110 std::vector<std::shared_ptr<Surface>> surfaces = {pSurface};
0111
0112
0113 filler.fill(tContext, indexedGridXY, surfaces, generator);
0114
0115 std::size_t nonEmptyBins = countBins<decltype(indexedGridXY)>(indexedGridXY);
0116 ACTS_INFO("- filled " << nonEmptyBins << " bins of the grid.");
0117 BOOST_CHECK_EQUAL(nonEmptyBins, 1u);
0118 }
0119
0120 BOOST_AUTO_TEST_CASE(IndexGridXYOneSurfacePolyhedron) {
0121 ACTS_LOCAL_LOGGER(getDefaultLogger("*** Test 2", logLevel));
0122 ACTS_INFO("Testing X-Y grid.");
0123 ACTS_INFO(
0124 "Testing one surface with polyhedron generator without expansion, should "
0125 "lead to 5 unique bins, 25 total bins filled");
0126
0127
0128 Axis axisX(AxisBound, -5., 5., 5);
0129 Axis axisY(AxisBound, -5., 5., 5);
0130 Grid gridXY(Type<std::vector<unsigned int>>, std::move(axisX),
0131 std::move(axisY));
0132
0133
0134 IndexGrid<decltype(gridXY)> indexedGridXY(
0135 std::move(gridXY), {AxisDirection::AxisX, AxisDirection::AxisY});
0136
0137
0138 auto rBounds = std::make_shared<RectangleBounds>(4., 4.);
0139 auto pSurface = Surface::makeShared<PlaneSurface>(Transform3::Identity(),
0140 std::move(rBounds));
0141
0142
0143 IndexGridFiller filler{{0u, 0u}};
0144 filler.oLogger = getDefaultLogger("IndexGridFiller", Logging::DEBUG);
0145
0146 PolyhedronReferenceGenerator generator;
0147 std::vector<std::shared_ptr<Surface>> surfaces = {pSurface};
0148
0149
0150 filler.fill(tContext, indexedGridXY, surfaces, generator);
0151
0152 std::size_t nonEmptyBins = countBins<decltype(indexedGridXY)>(indexedGridXY);
0153 ACTS_INFO("- filled " << nonEmptyBins << " bins of the grid.");
0154 BOOST_CHECK_EQUAL(nonEmptyBins, 25u);
0155 }
0156
0157 BOOST_AUTO_TEST_CASE(IndexGridXYOneSurfacePolyhedronBinExpansion) {
0158 ACTS_LOCAL_LOGGER(getDefaultLogger("*** Test 3", logLevel));
0159 ACTS_INFO("Testing X-Y grid.");
0160 ACTS_INFO(
0161 "Testing one surface with polyhedron generator and expansion, should "
0162 "lead to 5 unique bins, 49 total bins filled");
0163
0164
0165 Axis axisX(AxisBound, -9., 9., 9);
0166 Axis axisY(AxisBound, -9., 9., 9);
0167 Grid gridXY(Type<std::vector<unsigned int>>, std::move(axisX),
0168 std::move(axisY));
0169
0170
0171 IndexGrid<decltype(gridXY)> indexedGridXY(
0172 std::move(gridXY), {AxisDirection::AxisX, AxisDirection::AxisY});
0173
0174
0175 auto rBounds = std::make_shared<RectangleBounds>(4., 4.);
0176 auto pSurface = Surface::makeShared<PlaneSurface>(Transform3::Identity(),
0177 std::move(rBounds));
0178
0179
0180 IndexGridFiller filler{{1u, 1u}};
0181 filler.oLogger = getDefaultLogger("IndexGridFiller", Logging::DEBUG);
0182
0183 PolyhedronReferenceGenerator generator;
0184 std::vector<std::shared_ptr<Surface>> surfaces = {pSurface};
0185
0186
0187 filler.fill(tContext, indexedGridXY, surfaces, generator);
0188
0189 std::size_t nonEmptyBins = countBins<decltype(indexedGridXY)>(indexedGridXY);
0190 ACTS_INFO("- filled " << nonEmptyBins << " bins of the grid.");
0191 BOOST_CHECK_EQUAL(nonEmptyBins, 49u);
0192 }
0193
0194 BOOST_AUTO_TEST_CASE(IndexGridZPhiYOneSurfacePolyhedronBinExpansion) {
0195 ACTS_LOCAL_LOGGER(getDefaultLogger("*** Test 4", logLevel));
0196 ACTS_INFO("Testing Phi-Z grid.");
0197 ACTS_INFO(
0198 "Testing one surface with polyhedron generator without expansion, should "
0199 "lead to 5 unique bins, 6 total bins filled");
0200
0201
0202 Axis axisZ(AxisBound, -9., 9., 9);
0203 Axis axisPhi(AxisClosed, -std::numbers::pi, std::numbers::pi, 36);
0204 Grid gridZPhi(Type<std::vector<unsigned int>>, std::move(axisZ),
0205 std::move(axisPhi));
0206
0207
0208 IndexGrid<decltype(gridZPhi)> indexedGridZPhi(
0209 std::move(gridZPhi), {AxisDirection::AxisZ, AxisDirection::AxisPhi});
0210
0211 auto cBounds =
0212 std::make_shared<CylinderBounds>(10, 2., std::numbers::pi / 30, 0.);
0213 auto cSurface = Surface::makeShared<CylinderSurface>(Transform3::Identity(),
0214 std::move(cBounds));
0215
0216
0217 IndexGridFiller filler{{0u, 0u}};
0218 filler.oLogger = getDefaultLogger("IndexGridFiller", Logging::DEBUG);
0219
0220 PolyhedronReferenceGenerator generator;
0221 std::vector<std::shared_ptr<Surface>> surfaces = {cSurface};
0222
0223
0224 filler.fill(tContext, indexedGridZPhi, surfaces, generator);
0225
0226 std::size_t nonEmptyBins =
0227 countBins<decltype(indexedGridZPhi)>(indexedGridZPhi);
0228 ACTS_INFO("- filled " << nonEmptyBins << " bins of the grid.");
0229 BOOST_CHECK_EQUAL(nonEmptyBins, 6u);
0230 }
0231
0232 BOOST_AUTO_TEST_CASE(IndexGridZPhiYOneSurfaceMPIPolyhedronBinExpansion) {
0233 ACTS_LOCAL_LOGGER(getDefaultLogger("*** Test 4", logLevel));
0234 ACTS_INFO("Testing Phi-Z grid.");
0235 ACTS_INFO(
0236 "Testing one surface at std::numbers::pi jump, with polyhedron "
0237 "generator");
0238
0239
0240 Axis axisZ(AxisBound, -9., 9., 9);
0241 Axis axisPhi(AxisClosed, -std::numbers::pi, std::numbers::pi, 36);
0242 Grid gridZPhi(Type<std::vector<unsigned int>>, std::move(axisZ),
0243 std::move(axisPhi));
0244
0245
0246 IndexGrid<decltype(gridZPhi)> indexedGridZPhi(
0247 std::move(gridZPhi), {AxisDirection::AxisZ, AxisDirection::AxisPhi});
0248
0249 auto cBounds =
0250 std::make_shared<CylinderBounds>(10, 2., std::numbers::pi / 10, 0.);
0251 auto tf =
0252 AngleAxis3(std::numbers::pi, Vector3::UnitZ()) * Transform3::Identity();
0253 auto cSurface = Surface::makeShared<CylinderSurface>(tf, std::move(cBounds));
0254
0255
0256 IndexGridFiller filler{{0u, 0u}};
0257 filler.oLogger = getDefaultLogger("IndexGridFiller", Logging::DEBUG);
0258
0259 PolyhedronReferenceGenerator generator;
0260 std::vector<std::shared_ptr<Surface>> surfaces = {cSurface};
0261
0262
0263 filler.fill(tContext, indexedGridZPhi, surfaces, generator);
0264
0265 std::size_t nonEmptyBins =
0266 countBins<decltype(indexedGridZPhi)>(indexedGridZPhi);
0267 ACTS_INFO("- filled " << nonEmptyBins << " bins of the grid.");
0268 BOOST_CHECK_EQUAL(nonEmptyBins, 9u);
0269 }
0270
0271 BOOST_AUTO_TEST_SUITE_END()
0272
0273 }