9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
15 #include <unordered_map>
24 namespace tt = boost::test_tools;
46 std::vector<size_t> clusterSizes = {2, 2, 2, 3, 6, 6, 7};
47 std::vector<size_t> clusterSizesCut = {1, 1, 1, 1, 1, 1, 1, 2, 2, 3};
48 std::vector<size_t> clusterSizesEdge = {1, 1, 1, 1, 1, 1, 1,
50 size_t nClusters = clusterSizes.size();
51 size_t nClustersCut = clusterSizesCut.size();
52 size_t nClustersEdge = clusterSizesEdge.size();
54 auto globalIndex = [&nBins0](
const size_t&
a,
const size_t&
b) {
55 return (a + nBins0 *
b);
58 std::unordered_map<size_t, std::pair<Acts::DigitizationCell, bool>> testCells;
119 size_t nCellsWithoutDuplicates = testCells.size();
121 std::unordered_map<size_t, std::pair<Acts::DigitizationCell, bool>>
185 size_t nCells = testCells1.size();
188 auto testCells2 = testCells;
189 auto testCells3 = testCells;
190 auto testCells4 = testCells1;
195 Acts::createClusters<Acts::DigitizationCell>(testCells, nBins0,
true, 0.);
197 BOOST_CHECK_EQUAL(mergedCells1.size(), nClusters);
200 std::vector<size_t> clusterSizes1;
201 for (
size_t i = 0; i < mergedCells1.size(); i++) {
202 auto cells = mergedCells1.at(i);
203 for (
auto& cell : cells) {
207 clusterSizes1.push_back(cells.size());
210 std::sort(clusterSizes1.begin(), clusterSizes1.end());
211 BOOST_CHECK_EQUAL_COLLECTIONS(clusterSizes.begin(), clusterSizes.end(),
212 clusterSizes1.begin(), clusterSizes1.end());
218 auto mergedCells2 = Acts::createClusters<Acts::DigitizationCell>(
219 testCells2, nBins0,
false, 0.);
221 BOOST_CHECK_EQUAL(mergedCells2.size(), nClustersEdge);
224 std::vector<size_t> clusterSizes2;
225 for (
size_t i = 0; i < mergedCells2.size(); i++) {
226 auto cells = mergedCells2.at(i);
227 for (
auto& cell : cells) {
231 clusterSizes2.push_back(cells.size());
234 std::sort(clusterSizes2.begin(), clusterSizes2.end());
235 BOOST_CHECK_EQUAL_COLLECTIONS(clusterSizesEdge.begin(),
236 clusterSizesEdge.end(), clusterSizes2.begin(),
237 clusterSizes2.end());
243 auto mergedCells3 = Acts::createClusters<Acts::DigitizationCell>(
244 testCells3, nBins0,
true, 0.);
246 BOOST_CHECK_EQUAL(mergedCells3.size(), nClusters);
249 std::vector<size_t> clusterSizes3;
250 for (
size_t i = 0; i < mergedCells3.size(); i++) {
251 auto cells = mergedCells3.at(i);
252 for (
auto& cell : cells) {
256 clusterSizes3.push_back(cells.size());
259 std::sort(clusterSizes3.begin(), clusterSizes3.end());
260 BOOST_CHECK_EQUAL_COLLECTIONS(clusterSizes.begin(), clusterSizes.end(),
261 clusterSizes3.begin(), clusterSizes3.end());
267 auto mergedCells4 = Acts::createClusters<Acts::DigitizationCell>(
268 testCells4, nBins0,
true, 1.5);
271 BOOST_CHECK_EQUAL(mergedCells4.size(), nClustersCut);
274 std::vector<size_t> clusterSizes4;
275 for (
size_t i = 0; i < mergedCells4.size(); i++) {
276 auto cells = mergedCells4.at(i);
277 for (
auto& cell : cells) {
281 clusterSizes4.push_back(cells.size());
284 std::sort(clusterSizes4.begin(), clusterSizes4.end());
285 BOOST_CHECK_EQUAL_COLLECTIONS(clusterSizesCut.begin(), clusterSizesCut.end(),
286 clusterSizes4.begin(), clusterSizes4.end());
295 std::unordered_map<size_t, std::pair<Acts::DigitizationCell, bool>>
300 size_t nClustersNoTouch = (nCells /
delta) * (nCells / delta);
301 size_t nCellsInClusters = nClustersNoTouch * 3;
303 auto globalIndex = [&nCells](
const size_t&
a,
const size_t&
b) {
304 return (a + nCells *
b);
313 for (
size_t i = 0; i < nCells; i +=
delta) {
314 for (
size_t j = 0; j < nCells; j +=
delta) {
319 auto insertCellA = testCells1.insert({globalIndex(i, j), {cellA,
false}});
320 if (!insertCellA.second) {
323 insertCellA.first->second.first.addCell(cellA,
false);
326 testCells1.insert({globalIndex(i, j + 1), {cellB,
false}});
327 if (!insertCellB.second) {
330 insertCellB.first->second.first.addCell(cellB,
false);
333 testCells1.insert({globalIndex(i + 1, j + 1), {cellC,
false}});
334 if (!insertCellC.second) {
337 insertCellC.first->second.first.addCell(cellC,
false);
342 auto testCells2 = testCells1;
343 auto testCells3 = testCells1;
344 auto testCells5 = testCells1;
345 auto testCells7 = testCells1;
346 auto testCells8 = testCells1;
352 auto mergedCells1 = Acts::createClusters<Acts::DigitizationCell>(
353 testCells1, nCells,
true, 0.);
354 BOOST_CHECK_EQUAL(mergedCells1.size(), nClustersNoTouch);
356 auto mergedCells2 = Acts::createClusters<Acts::DigitizationCell>(
357 testCells2, nCells,
false, 0.);
358 BOOST_CHECK_EQUAL(mergedCells2.size(), nClustersNoTouch);
362 for (
auto& cells : mergedCells1) {
363 for (
auto& i : cells) {
366 BOOST_CHECK_EQUAL(cells.size(),
delta);
373 for (
auto& cells : mergedCells2) {
374 for (
auto& i : cells) {
377 BOOST_CHECK_EQUAL(cells.size(),
delta);
385 size_t nCornerCells = nCells / delta2 * nCells / delta2;
386 size_t nClusters_merged = nClustersNoTouch - nCornerCells * 2;
388 for (
size_t i = 2; i < nCells; i += delta2) {
389 for (
size_t j = 2; j < nCells; j += delta2) {
391 auto insertCell = testCells3.insert({globalIndex(i, j), {cell,
false}});
392 if (!insertCell.second) {
395 insertCell.first->second.first.addCell(cell,
false);
399 auto testCells4 = testCells3;
402 auto mergedCells3 = Acts::createClusters<Acts::DigitizationCell>(
403 testCells3, nCells,
true, 0.);
404 BOOST_CHECK_EQUAL(mergedCells3.size(), nClusters_merged);
407 auto mergedCells4 = Acts::createClusters<Acts::DigitizationCell>(
408 testCells4, nCells,
false, 0.);
409 BOOST_CHECK_EQUAL(mergedCells4.size(), nClustersNoTouch + nCornerCells);
412 for (
size_t i = 2; i < nCells; i += delta2) {
413 for (
size_t j = 2; j < nCells; j += delta2) {
416 testCells5.insert({globalIndex(i, j - 1), {cellA,
false}});
417 if (!insertCellA.second) {
420 insertCellA.first->second.first.addCell(cellA,
false);
424 testCells5.insert({globalIndex(i + 1, j), {cellB,
false}});
425 if (!insertCellB.second) {
428 insertCellB.first->second.first.addCell(cellB,
false);
432 auto testCells6 = testCells5;
435 auto mergedCells5 = Acts::createClusters<Acts::DigitizationCell>(
436 testCells5, nCells,
true, 0.);
437 BOOST_CHECK_EQUAL(mergedCells5.size(), nClusters_merged);
440 auto mergedCells6 = Acts::createClusters<Acts::DigitizationCell>(
441 testCells6, nCells,
false, 0.);
442 BOOST_CHECK_EQUAL(mergedCells6.size(), nClusters_merged);
446 for (
size_t i = 0; i < nCells; i +=
delta) {
447 for (
size_t j = 0; j < nCells; j +=
delta) {
451 auto insertCellA = testCells7.insert({globalIndex(i, j), {cellA,
false}});
452 if (!insertCellA.second) {
455 insertCellA.first->second.first.addCell(cellA,
false);
458 testCells7.insert({globalIndex(i, j + 1), {cellB,
false}});
459 if (!insertCellB.second) {
462 insertCellB.first->second.first.addCell(cellB,
false);
465 insertCellA = testCells8.insert({globalIndex(i, j), {cellA,
false}});
466 if (!insertCellA.second) {
469 insertCellA.first->second.first.addCell(cellA,
true);
471 insertCellB = testCells8.insert({globalIndex(i, j + 1), {cellB,
false}});
472 if (!insertCellB.second) {
475 insertCellB.first->second.first.addCell(cellB,
true);
479 auto testCells9 = testCells8;
481 size_t nCellsInClustersDuplicated =
482 nClustersNoTouch * 3 + nClustersNoTouch * 2;
485 auto mergedCells7 = Acts::createClusters<Acts::DigitizationCell>(
486 testCells7, nCells,
true, 0.);
487 BOOST_CHECK_EQUAL(mergedCells7.size(), nClustersNoTouch);
489 for (
auto& cells : mergedCells7) {
490 for (
auto& i : cells) {
493 BOOST_CHECK_EQUAL(cells.size(), 3
u);
498 auto mergedCells8 = Acts::createClusters<Acts::DigitizationCell>(
499 testCells8, nCells,
true, 0.);
500 BOOST_CHECK_EQUAL(mergedCells8.size(), nClustersNoTouch);
502 for (
auto& cells : mergedCells8) {
503 for (
auto& i : cells) {
506 BOOST_CHECK_EQUAL(cells.size(), 3
u);
511 auto mergedCells9 = Acts::createClusters<Acts::DigitizationCell>(
512 testCells9, nCells,
true, 1.5);
513 BOOST_CHECK_EQUAL(mergedCells9.size(), nClustersNoTouch);
515 for (
auto& cells : mergedCells9) {
516 for (
auto& i : cells) {
519 BOOST_CHECK_EQUAL(cells.size(), 2
u);