File indexing completed on 2025-01-18 09:12:57
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Utilities/AxisDefinitions.hpp"
0012 #include "Acts/Utilities/Grid.hpp"
0013 #include "Acts/Utilities/GridIterator.hpp"
0014
0015 #include <array>
0016 #include <unordered_set>
0017
0018 namespace Acts::Test {
0019
0020 BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) {
0021 const std::size_t nBins = 10ul;
0022 Acts::Axis xAxis(0, 100, nBins);
0023 Acts::Grid grid(Type<double>, std::move(xAxis));
0024
0025 BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul);
0026
0027 Acts::GridGlobalIterator gridStart = grid.begin();
0028 Acts::GridGlobalIterator gridStop = grid.end();
0029
0030 BOOST_CHECK_EQUAL(gridStart == gridStop, false);
0031 BOOST_CHECK_EQUAL(gridStart != gridStop, true);
0032 BOOST_CHECK_EQUAL(gridStart < gridStop, true);
0033 BOOST_CHECK_EQUAL(gridStart <= gridStop, true);
0034 BOOST_CHECK_EQUAL(gridStart > gridStop, false);
0035 BOOST_CHECK_EQUAL(gridStart >= gridStop, false);
0036
0037 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins + 2ul);
0038 auto itr = gridStart++;
0039 BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul);
0040 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins + 2ul);
0041 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins + 1ul);
0042
0043 itr = ++gridStart;
0044 BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul);
0045 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins);
0046
0047 itr = gridStart + std::distance(gridStart, gridStop);
0048 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins);
0049 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), 0ul);
0050 BOOST_CHECK_EQUAL(itr == gridStop, true);
0051
0052 itr = gridStart - 1ul;
0053 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins);
0054 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins + 1ul);
0055
0056 gridStart += std::distance(gridStart, gridStop);
0057 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 0ul);
0058 BOOST_CHECK_EQUAL(gridStart == gridStop, true);
0059
0060 gridStart -= 3ul;
0061 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 3ul);
0062 BOOST_CHECK_EQUAL(gridStart != gridStop, true);
0063
0064 [[maybe_unused]] double value = *gridStart;
0065
0066 Acts::GridGlobalIterator<double, Acts::Axis<AxisType::Equidistant>>
0067 gridDefault;
0068 Acts::GridGlobalIterator gridDummy(grid, 0ul);
0069
0070 BOOST_CHECK_EQUAL(gridDefault == gridDummy, false);
0071 }
0072
0073 BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global_operators) {
0074 const std::size_t nBinsX = 10ul;
0075 const std::size_t nBinsY = 5ul;
0076 Acts::Axis xAxis(0, 100, nBinsX);
0077 Acts::Axis yAxis(0, 100, nBinsY);
0078 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis));
0079
0080 BOOST_CHECK_EQUAL(grid.size(true), (nBinsX + 2ul) * (nBinsY + 2ul));
0081
0082 Acts::GridGlobalIterator gridStart = grid.begin();
0083 Acts::GridGlobalIterator gridStop = grid.end();
0084
0085 BOOST_CHECK_EQUAL(gridStart == gridStop, false);
0086 BOOST_CHECK_EQUAL(gridStart != gridStop, true);
0087 BOOST_CHECK_EQUAL(gridStart < gridStop, true);
0088 BOOST_CHECK_EQUAL(gridStart <= gridStop, true);
0089 BOOST_CHECK_EQUAL(gridStart > gridStop, false);
0090 BOOST_CHECK_EQUAL(gridStart >= gridStop, false);
0091
0092 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true));
0093 auto itr = gridStart++;
0094 BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul);
0095 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), grid.size(true));
0096 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 1ul);
0097
0098 itr = ++gridStart;
0099 BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul);
0100 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul);
0101
0102 itr = gridStart + std::distance(gridStart, gridStop);
0103 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul);
0104 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), 0ul);
0105 BOOST_CHECK_EQUAL(itr == gridStop, true);
0106
0107 itr = gridStart - 1ul;
0108 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul);
0109 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), grid.size(true) - 1ul);
0110
0111 gridStart += std::distance(gridStart, gridStop);
0112 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 0ul);
0113 BOOST_CHECK_EQUAL(gridStart == gridStop, true);
0114
0115 gridStart -= 3ul;
0116 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 3ul);
0117 BOOST_CHECK_EQUAL(gridStart != gridStop, true);
0118
0119 [[maybe_unused]] double value = *gridStart;
0120
0121 Acts::GridGlobalIterator<double, Acts::Axis<AxisType::Equidistant>,
0122 Acts::Axis<AxisType::Equidistant>>
0123 gridDefault;
0124 Acts::GridGlobalIterator gridDummy(grid, 0ul);
0125
0126 BOOST_CHECK_EQUAL(gridDefault == gridDummy, false);
0127 }
0128
0129 BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) {
0130 const std::size_t nBins = 10ul;
0131 Acts::Axis xAxis(0, 100, nBins);
0132 Acts::Grid grid(Type<double>, std::move(xAxis));
0133
0134
0135 BOOST_CHECK_EQUAL(grid.size(false), nBins);
0136 BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul);
0137
0138 const std::array<std::size_t, 1ul> numLocalBins = grid.numLocalBins();
0139 BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins);
0140
0141 Acts::GridGlobalIterator gridStart = grid.begin();
0142 Acts::GridGlobalIterator gridStop = grid.end();
0143 std::size_t numIterations = 0ul;
0144 for (; gridStart != gridStop; gridStart++) {
0145 BOOST_CHECK_EQUAL(gridStart.globalBinIndex(), numIterations);
0146 const std::array<std::size_t, 1ul> locPosition =
0147 gridStart.localBinsIndices();
0148 BOOST_CHECK_EQUAL(numIterations, locPosition[0ul]);
0149 ++numIterations;
0150 }
0151 BOOST_CHECK_EQUAL(numIterations, grid.size(true));
0152 }
0153
0154 BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global) {
0155 const std::size_t nBins = 10ul;
0156 Acts::Axis xAxis(0, 100, nBins);
0157 Acts::Axis yAxis(0, 100, nBins);
0158 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis));
0159
0160
0161 BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins);
0162 BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul));
0163
0164 const std::array<std::size_t, 2ul> numLocalBins = grid.numLocalBins();
0165 BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins);
0166 BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins);
0167
0168 Acts::GridGlobalIterator gridStart = grid.begin();
0169 Acts::GridGlobalIterator gridStop = grid.end();
0170 std::size_t numIterations = 0ul;
0171 for (; gridStart != gridStop; ++gridStart) {
0172 BOOST_CHECK_EQUAL(gridStart.globalBinIndex(), numIterations);
0173 ++numIterations;
0174 }
0175 BOOST_CHECK_EQUAL(numIterations, grid.size(true));
0176 }
0177
0178 BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) {
0179 const std::size_t nBins = 10ul;
0180 const std::size_t nBinsZ = 20ul;
0181 Acts::Axis xAxis(0, 100, nBins);
0182 Acts::Axis yAxis(0, 100, nBins);
0183 Acts::Axis zAxis(0, 100, nBinsZ);
0184 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis),
0185 std::move(zAxis));
0186
0187
0188 BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ);
0189 BOOST_CHECK_EQUAL(grid.size(true),
0190 (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul));
0191
0192 const std::array<std::size_t, 3ul> numLocalBins = grid.numLocalBins();
0193 BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins);
0194 BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins);
0195 BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ);
0196
0197 Acts::GridGlobalIterator gridStart = grid.begin();
0198 Acts::GridGlobalIterator gridStop = grid.end();
0199 std::size_t numIterations = 0ul;
0200 for (; gridStart != gridStop; ++gridStart) {
0201 BOOST_CHECK_EQUAL(gridStart.globalBinIndex(), numIterations);
0202 ++numIterations;
0203 }
0204 BOOST_CHECK_EQUAL(numIterations, grid.size(true));
0205 }
0206
0207 BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) {
0208 const std::size_t nBins = 10ul;
0209 Acts::Axis xAxis(0, 100, nBins);
0210 Acts::Grid grid(Type<double>, std::move(xAxis));
0211
0212 std::array<std::vector<std::size_t>, 1ul> navigation;
0213 navigation[0ul].resize(nBins);
0214 std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul);
0215
0216
0217 Acts::GridLocalIterator gridIterNoNav(grid, {0ul});
0218
0219 Acts::GridLocalIterator gridStart(grid, {0ul}, navigation);
0220
0221 BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul);
0222 BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true);
0223
0224 Acts::GridLocalIterator gridStop(grid, {nBins}, std::move(navigation));
0225
0226 BOOST_CHECK_EQUAL(gridStart == gridStop, false);
0227 BOOST_CHECK_EQUAL(gridStart != gridStop, true);
0228
0229 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(false));
0230 BOOST_CHECK_EQUAL(gridStart != gridStop, true);
0231
0232 auto itr = gridStart++;
0233 BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul);
0234 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins);
0235 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins - 1ul);
0236
0237 itr = ++gridStart;
0238 BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul);
0239 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins - 2ul);
0240
0241 [[maybe_unused]] double value = *gridStart;
0242 std::array<std::size_t, 1ul> locPos = gridStart.localBinsIndices();
0243 BOOST_CHECK_EQUAL(locPos[0ul], 3ul);
0244
0245 std::size_t globPos = gridStart.globalBinIndex();
0246 BOOST_CHECK_EQUAL(globPos, 3ul);
0247
0248 Acts::GridLocalIterator<double, Acts::Axis<AxisType::Equidistant>>
0249 gridDefault;
0250 Acts::GridLocalIterator gridDummy(grid, {0ul});
0251
0252 BOOST_CHECK_EQUAL(gridDefault == gridDummy, false);
0253
0254
0255
0256 itr = std::move(gridStart);
0257 BOOST_CHECK_EQUAL(itr == gridStart, false);
0258 BOOST_CHECK_EQUAL(itr != gridStart, true);
0259 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins - 2ul);
0260 }
0261
0262 BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) {
0263 const std::size_t nBinsX = 10ul;
0264 const std::size_t nBinsY = 5ul;
0265 Acts::Axis xAxis(0, 100, nBinsX);
0266 Acts::Axis yAxis(0, 100, nBinsY);
0267 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis));
0268
0269 std::array<std::vector<std::size_t>, 2ul> navigation;
0270 navigation[0ul].resize(nBinsX);
0271 navigation[1ul].resize(nBinsY);
0272 std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul);
0273 std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul);
0274
0275
0276 Acts::GridLocalIterator gridIterNoNav(grid, {0ul, 0ul});
0277
0278 Acts::GridLocalIterator gridStart(grid, {0ul, 0ul}, navigation);
0279
0280 BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul);
0281 BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true);
0282
0283 Acts::GridLocalIterator gridStop(grid, {nBinsX, nBinsY},
0284 std::move(navigation));
0285
0286 BOOST_CHECK_EQUAL(gridStart == gridStop, false);
0287 BOOST_CHECK_EQUAL(gridStart != gridStop, true);
0288
0289 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(false));
0290 BOOST_CHECK_EQUAL(gridStart != gridStop, true);
0291
0292 auto itr = gridStart++;
0293 BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul);
0294 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBinsX * nBinsY);
0295 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBinsX * nBinsY - 1ul);
0296
0297 itr = ++gridStart;
0298 BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul);
0299 BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBinsX * nBinsY - 2ul);
0300
0301 [[maybe_unused]] double value = *gridStart;
0302 std::array<std::size_t, 2ul> locPos = gridStart.localBinsIndices();
0303 BOOST_CHECK_EQUAL(locPos[0ul], 1ul);
0304 BOOST_CHECK_EQUAL(locPos[1ul], 3ul);
0305
0306 Acts::GridLocalIterator<double, Acts::Axis<AxisType::Equidistant>,
0307 Acts::Axis<AxisType::Equidistant>>
0308 gridDefault;
0309 Acts::GridLocalIterator gridDummy(grid, {0ul, 0ul});
0310
0311 BOOST_CHECK_EQUAL(gridDefault == gridDummy, false);
0312
0313
0314
0315 itr = std::move(gridStart);
0316 BOOST_CHECK_EQUAL(itr == gridStart, false);
0317 BOOST_CHECK_EQUAL(itr != gridStart, true);
0318 BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBinsX * nBinsY - 2ul);
0319 }
0320
0321 BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_notvalid) {
0322 const std::size_t nBins = 10ul;
0323 Acts::Axis xAxis(0, 100, nBins);
0324 Acts::Grid grid(Type<double>, std::move(xAxis));
0325
0326
0327 std::array<std::vector<std::size_t>, 1ul> noNavigation;
0328 BOOST_CHECK_THROW(
0329 (Acts::GridLocalIterator(grid, {0ul}, std::move(noNavigation))),
0330 std::invalid_argument);
0331
0332
0333 std::array<std::vector<std::size_t>, 1ul> tooMuchNavigation;
0334 tooMuchNavigation[0ul].resize(2 * nBins);
0335 std::iota(tooMuchNavigation[0ul].begin(), tooMuchNavigation[0ul].end(), 1ul);
0336 BOOST_CHECK_THROW(
0337 (Acts::GridLocalIterator(grid, {0ul}, std::move(tooMuchNavigation))),
0338 std::invalid_argument);
0339 }
0340
0341 BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) {
0342 const std::size_t nBins = 10ul;
0343 Acts::Axis xAxis(0, 100, nBins);
0344 Acts::Grid grid(Type<double>, std::move(xAxis));
0345
0346
0347 BOOST_CHECK_EQUAL(grid.size(false), nBins);
0348 BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul);
0349
0350 const std::array<std::size_t, 1ul> numLocalBins = grid.numLocalBins();
0351 BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins);
0352
0353 std::array<std::vector<std::size_t>, 1ul> navigation;
0354 navigation[0ul].resize(nBins);
0355 std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul);
0356
0357 Acts::GridLocalIterator gridStart = grid.begin(navigation);
0358 Acts::GridLocalIterator gridStop = grid.end(navigation);
0359 std::size_t numIterations = 0ul;
0360 for (; gridStart != gridStop; ++gridStart) {
0361 ++numIterations;
0362 }
0363 BOOST_CHECK_EQUAL(numIterations, grid.size(false));
0364 }
0365
0366 BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) {
0367 const std::size_t nBins = 10ul;
0368 Acts::Axis xAxis(0, 100, nBins);
0369 Acts::Axis yAxis(0, 100, nBins);
0370 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis));
0371
0372
0373 BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins);
0374 BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul));
0375
0376 const std::array<std::size_t, 2ul> numLocalBins = grid.numLocalBins();
0377 BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins);
0378 BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins);
0379
0380 std::array<std::vector<std::size_t>, 2ul> navigation;
0381 navigation[0ul].resize(nBins);
0382 navigation[1ul].resize(nBins);
0383 for (std::size_t i(0ul); i < 2ul; ++i) {
0384 std::iota(navigation[i].begin(), navigation[i].end(), 1ul);
0385 }
0386
0387 Acts::GridLocalIterator gridStart = grid.begin(navigation);
0388 Acts::GridLocalIterator gridStop = grid.end(navigation);
0389 std::size_t numIterations = 0ul;
0390 for (; gridStart != gridStop; gridStart++) {
0391 ++numIterations;
0392 }
0393 BOOST_CHECK_EQUAL(numIterations, grid.size(false));
0394 }
0395
0396 BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local) {
0397 const std::size_t nBins = 10ul;
0398 const std::size_t nBinsZ = 20ul;
0399 Acts::Axis xAxis(0, 100, nBins);
0400 Acts::Axis yAxis(0, 100, nBins);
0401 Acts::Axis zAxis(0, 100, nBinsZ);
0402 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis),
0403 std::move(zAxis));
0404
0405
0406 BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ);
0407 BOOST_CHECK_EQUAL(grid.size(true),
0408 (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul));
0409
0410 const std::array<std::size_t, 3ul> numLocalBins = grid.numLocalBins();
0411 BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins);
0412 BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins);
0413 BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ);
0414
0415 std::array<std::vector<std::size_t>, 3ul> navigation;
0416 navigation[0ul].resize(nBins);
0417 navigation[1ul].resize(nBins);
0418 navigation[2ul].resize(nBinsZ);
0419 for (std::size_t i(0ul); i < 3ul; ++i) {
0420 std::iota(navigation[i].begin(), navigation[i].end(), 1ul);
0421 }
0422
0423 Acts::GridLocalIterator gridStart = grid.begin(navigation);
0424 Acts::GridLocalIterator gridStop = grid.end(navigation);
0425 std::size_t numIterations = 0ul;
0426 for (; gridStart != gridStop; ++gridStart) {
0427 ++numIterations;
0428 }
0429 BOOST_CHECK_EQUAL(numIterations, grid.size(false));
0430 }
0431
0432 BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_custom_navigation) {
0433 const std::size_t nBins = 10ul;
0434 const std::size_t nBinsZ = 20ul;
0435 Acts::Axis xAxis(0, 100, nBins);
0436 Acts::Axis yAxis(0, 100, nBins);
0437 Acts::Axis zAxis(0, 100, nBinsZ);
0438 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis),
0439 std::move(zAxis));
0440
0441
0442 BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ);
0443 BOOST_CHECK_EQUAL(grid.size(true),
0444 (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul));
0445
0446 const std::array<std::size_t, 3ul> numLocalBins = grid.numLocalBins();
0447 BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins);
0448 BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins);
0449 BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ);
0450
0451 std::array<std::vector<std::size_t>, 3ul> navigation;
0452 navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul};
0453 navigation[1ul] = {6ul, 8ul, 7ul, 1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul};
0454 navigation[2ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul,
0455 6ul, 8ul, 7ul, 11ul, 15ul, 13ul, 12ul,
0456 19ul, 20ul, 14ul, 16ul, 18ul, 17ul};
0457
0458 Acts::GridLocalIterator gridStart = grid.begin(navigation);
0459 Acts::GridLocalIterator gridStop = grid.end(navigation);
0460 std::size_t numIterations = 0ul;
0461 for (; gridStart != gridStop; ++gridStart) {
0462 ++numIterations;
0463 }
0464 BOOST_CHECK_EQUAL(numIterations, grid.size(false));
0465 }
0466
0467 BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) {
0468 const std::size_t nBins = 10ul;
0469 const std::size_t nBinsZ = 20ul;
0470 const std::size_t nBinsJK = 5ul;
0471 Acts::Axis xAxis(0, 100, nBins);
0472 Acts::Axis yAxis(0, 100, nBins);
0473 Acts::Axis zAxis(0, 100, nBinsZ);
0474 Acts::Axis jAxis(0, 100, nBinsJK);
0475 Acts::Axis kAxis(0, 100, nBinsJK);
0476 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis),
0477 std::move(zAxis), std::move(jAxis), std::move(kAxis));
0478
0479
0480 BOOST_CHECK_EQUAL(grid.size(false),
0481 nBins * nBins * nBinsZ * nBinsJK * nBinsJK);
0482 BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) *
0483 (nBinsZ + 2ul) * (nBinsJK + 2ul) *
0484 (nBinsJK + 2ul));
0485
0486 const std::array<std::size_t, 5ul> numLocalBins = grid.numLocalBins();
0487 BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins);
0488 BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins);
0489 BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ);
0490 BOOST_CHECK_EQUAL(numLocalBins[3ul], nBinsJK);
0491 BOOST_CHECK_EQUAL(numLocalBins[4ul], nBinsJK);
0492
0493
0494 std::array<std::vector<std::size_t>, 5ul> navigation;
0495 navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul};
0496 navigation[1ul] = {6ul, 8ul, 7ul, 1ul};
0497 navigation[2ul] = {1ul, 5ul};
0498 navigation[3ul] = {5ul, 3ul, 2ul};
0499 navigation[4ul] = {2ul};
0500
0501 Acts::GridLocalIterator gridStart = grid.begin(navigation);
0502 Acts::GridLocalIterator gridStop = grid.end(navigation);
0503 std::size_t numIterations = 0ul;
0504 for (; gridStart != gridStop; ++gridStart) {
0505 ++numIterations;
0506 }
0507
0508 std::size_t expectedIterations = 1ul;
0509 for (std::size_t i(0ul); i < 5ul; ++i) {
0510 expectedIterations *= navigation[i].size();
0511 }
0512
0513 BOOST_CHECK_EQUAL(numIterations, expectedIterations);
0514 }
0515
0516 BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_norepetitions) {
0517 const std::size_t nBinsX = 5ul;
0518 const std::size_t nBinsY = 5ul;
0519 const std::size_t nBinsZ = 2ul;
0520 Acts::Axis xAxis(0, 100, nBinsX);
0521 Acts::Axis yAxis(0, 100, nBinsY);
0522 Acts::Axis zAxis(0, 100, nBinsZ);
0523 Acts::Grid grid(Type<double>, std::move(xAxis), std::move(yAxis),
0524 std::move(zAxis));
0525
0526 std::array<std::vector<std::size_t>, 3ul> navigation;
0527 navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 4ul};
0528 navigation[1ul] = {4ul, 2ul, 3ul, 5ul, 1ul};
0529 navigation[2ul] = {2ul, 1ul};
0530
0531 std::size_t expectedIterations =
0532 navigation[0ul].size() * navigation[1ul].size() * navigation[2ul].size();
0533
0534
0535 std::unordered_set<std::size_t> allowed_global_bins;
0536 for (std::size_t x : navigation[0ul]) {
0537 for (std::size_t y : navigation[1ul]) {
0538 for (std::size_t z : navigation[2ul]) {
0539 std::array<std::size_t, 3ul> locPos({x, y, z});
0540 std::size_t globPos = grid.globalBinFromLocalBins(locPos);
0541 BOOST_CHECK(!allowed_global_bins.contains(globPos));
0542 allowed_global_bins.insert(globPos);
0543 }
0544 }
0545 }
0546
0547 BOOST_CHECK_EQUAL(expectedIterations, allowed_global_bins.size());
0548
0549 Acts::GridLocalIterator gridStart = grid.begin(navigation);
0550 Acts::GridLocalIterator gridStop = grid.end(navigation);
0551
0552
0553 std::unordered_set<std::size_t> visited_global_bins;
0554
0555 std::size_t numIterations = 0ul;
0556 for (; gridStart != gridStop; ++gridStart) {
0557 ++numIterations;
0558 std::array<std::size_t, 3ul> locPos = gridStart.localBinsIndices();
0559 std::size_t globPos = grid.globalBinFromLocalBins(locPos);
0560 BOOST_CHECK(!visited_global_bins.contains(globPos));
0561 BOOST_CHECK(allowed_global_bins.contains(globPos));
0562 visited_global_bins.insert(globPos);
0563 }
0564
0565 BOOST_CHECK_EQUAL(expectedIterations, numIterations);
0566 BOOST_CHECK_EQUAL(visited_global_bins.size(), allowed_global_bins.size());
0567 }
0568
0569 }