|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +#define BOOST_TEST_MODULE Test Clusterer MC labels |
| 13 | +#define BOOST_TEST_MAIN |
| 14 | +#define BOOST_TEST_DYN_LINK |
| 15 | +#include <boost/test/unit_test.hpp> |
| 16 | +#include <algorithm> |
| 17 | + |
| 18 | +#include "ITSMFTReconstruction/DigitPixelReader.h" |
| 19 | +#include "SimulationDataFormat/MCTruthContainer.h" |
| 20 | +#ifdef TEST_ITS3_CLUSTERER |
| 21 | +#include "ITS3Reconstruction/Clusterer.h" |
| 22 | +using Clusterer = o2::its3::Clusterer; |
| 23 | +#else |
| 24 | +#include "ITSMFTReconstruction/Clusterer.h" |
| 25 | +using Clusterer = o2::itsmft::Clusterer; |
| 26 | +#endif |
| 27 | + |
| 28 | +namespace |
| 29 | +{ |
| 30 | +using namespace o2::itsmft; |
| 31 | +using MCTruth = o2::dataformats::MCTruthContainer<o2::MCCompLabel>; |
| 32 | +using CompClusCont = std::vector<CompClusterExt>; |
| 33 | +using PatternCont = std::vector<unsigned char>; |
| 34 | +using ROFRecCont = std::vector<ROFRecord>; |
| 35 | + |
| 36 | +struct ClusterResult { |
| 37 | + CompClusCont clusters; |
| 38 | + ROFRecCont rofs; |
| 39 | + MCTruth labels; |
| 40 | +}; |
| 41 | + |
| 42 | +ClusterResult clusterize(const std::vector<Digit>& digits, const ROFRecCont& rofs, int readerDepth, int clustererDepth, bool withTruth = true) |
| 43 | +{ |
| 44 | + MCTruth truth; |
| 45 | + for (size_t i = 0; i < digits.size(); ++i) { |
| 46 | + truth.addElement(i, o2::MCCompLabel(i, 0, 0)); |
| 47 | + } |
| 48 | + o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel> flatTruth; |
| 49 | + truth.flatten_to(flatTruth); |
| 50 | + o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel> truthView(flatTruth); |
| 51 | + |
| 52 | + DigitPixelReader reader; |
| 53 | + reader.setSquashingDepth(readerDepth); |
| 54 | + reader.setSquashingDist(1); |
| 55 | + reader.setMaxBCSeparationToSquash(10); |
| 56 | + reader.setDigits(digits); |
| 57 | + reader.setROFRecords(rofs); |
| 58 | + reader.setDigitsMCTruth(withTruth ? &truthView : nullptr); |
| 59 | + reader.setDecodeNextAuto(true); |
| 60 | + |
| 61 | + Clusterer clusterer; |
| 62 | + clusterer.setNChips(1); |
| 63 | + clusterer.setMaxBCSeparationToMask(0); |
| 64 | + clusterer.setMaxROFDepthToSquash(clustererDepth); |
| 65 | + ClusterResult result; |
| 66 | + PatternCont patterns; |
| 67 | + clusterer.process(1, reader, &result.clusters, &patterns, &result.rofs, &result.labels); |
| 68 | + return result; |
| 69 | +} |
| 70 | + |
| 71 | +void checkLabels(const ClusterResult& result, size_t cluster, const std::vector<int>& expectedTracks) |
| 72 | +{ |
| 73 | + const auto labels = result.labels.getLabels(cluster); |
| 74 | + BOOST_REQUIRE_EQUAL(labels.size(), expectedTracks.size()); |
| 75 | + std::vector<int> tracks; |
| 76 | + for (const auto& label : labels) { |
| 77 | + tracks.push_back(label.getTrackID()); |
| 78 | + BOOST_CHECK_EQUAL(label.getEventID(), 0); |
| 79 | + BOOST_CHECK_EQUAL(label.getSourceID(), 0); |
| 80 | + } |
| 81 | + std::sort(tracks.begin(), tracks.end()); |
| 82 | + BOOST_CHECK_EQUAL_COLLECTIONS(tracks.begin(), tracks.end(), expectedTracks.begin(), expectedTracks.end()); |
| 83 | +} |
| 84 | +} // namespace |
| 85 | + |
| 86 | +BOOST_AUTO_TEST_CASE(SinglePixelSurvivingSquashing) |
| 87 | +{ |
| 88 | + // The first digit in ROF 1 repeats ROF 0 and is squashed away. The survivor |
| 89 | + // must retain digit 2's label rather than the label at the chip's start ID (1). |
| 90 | + const std::vector<Digit> digits{{0, 10, 10}, {0, 10, 10}, {0, 30, 30}}; |
| 91 | + const ROFRecCont rofs{{{0, 1}, 0, 0, 1}, {{1, 1}, 1, 1, 2}}; |
| 92 | + for (int depth : {0, 1}) { |
| 93 | + const auto result = clusterize(digits, rofs, 1, depth); |
| 94 | + BOOST_REQUIRE_EQUAL(result.clusters.size(), 2); |
| 95 | + BOOST_REQUIRE_EQUAL(result.rofs.size(), 2); |
| 96 | + BOOST_CHECK_EQUAL(result.rofs[1].getNEntries(), 1); |
| 97 | + BOOST_CHECK_EQUAL(result.clusters[1].getRow(), 30); |
| 98 | + BOOST_CHECK_EQUAL(result.clusters[1].getCol(), 30); |
| 99 | + checkLabels(result, 0, {0}); |
| 100 | + checkLabels(result, 1, {2}); |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +BOOST_AUTO_TEST_CASE(MultiPixelLabelsAfterSquashingAndSorting) |
| 105 | +{ |
| 106 | + // Digit 1 is merged into ROF 0 and sorted before digit 0; digit 2 repeats |
| 107 | + // digit 0. The remaining two-pixel cluster must use digits 3 and 4. |
| 108 | + const std::vector<Digit> digits{{0, 10, 10}, {0, 10, 9}, {0, 10, 10}, {0, 30, 30}, {0, 31, 30}}; |
| 109 | + const ROFRecCont rofs{{{0, 1}, 0, 0, 1}, {{1, 1}, 1, 1, 4}}; |
| 110 | + for (int depth : {0, 1}) { |
| 111 | + const auto result = clusterize(digits, rofs, 1, depth); |
| 112 | + BOOST_REQUIRE_EQUAL(result.clusters.size(), 2); |
| 113 | + checkLabels(result, 0, {0, 1}); |
| 114 | + checkLabels(result, 1, {3, 4}); |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +BOOST_AUTO_TEST_CASE(LabelsFollowPixelSortingBetweenClusters) |
| 119 | +{ |
| 120 | + // Overflow digits are appended to the chip, then sorted into two different |
| 121 | + // clusters. Check each cluster's labels to detect a lost sorting permutation. |
| 122 | + const std::vector<Digit> digits{{0, 10, 10}, {0, 30, 30}, {0, 10, 9}, {0, 30, 29}, {0, 50, 50}}; |
| 123 | + const ROFRecCont rofs{{{0, 1}, 0, 0, 2}, {{1, 1}, 1, 2, 3}}; |
| 124 | + const auto result = clusterize(digits, rofs, 1, 1); |
| 125 | + BOOST_REQUIRE_EQUAL(result.clusters.size(), 3); |
| 126 | + checkLabels(result, 0, {0, 2}); |
| 127 | + checkLabels(result, 1, {1, 3}); |
| 128 | + checkLabels(result, 2, {4}); |
| 129 | +} |
| 130 | + |
| 131 | +BOOST_AUTO_TEST_CASE(ContiguousDigitsWithClustererSquashingEnabled) |
| 132 | +{ |
| 133 | + const std::vector<Digit> digits{{0, 10, 10}, {0, 30, 30}, {0, 31, 30}}; |
| 134 | + const ROFRecCont rofs{{{0, 1}, 0, 0, 1}, {{1, 1}, 1, 1, 2}}; |
| 135 | + for (int depth : {0, 1}) { |
| 136 | + const auto result = clusterize(digits, rofs, 0, depth); |
| 137 | + BOOST_REQUIRE_EQUAL(result.clusters.size(), 2); |
| 138 | + checkLabels(result, 0, {0}); |
| 139 | + checkLabels(result, 1, {1, 2}); |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +BOOST_AUTO_TEST_CASE(ClusterLabelsRequestedWithoutDigitTruth) |
| 144 | +{ |
| 145 | + const std::vector<Digit> digits{{0, 10, 10}, {0, 30, 30}, {0, 31, 30}}; |
| 146 | + const ROFRecCont rofs{{{0, 1}, 0, 0, 1}, {{1, 1}, 1, 1, 2}}; |
| 147 | + for (int readerDepth : {0, 1}) { |
| 148 | + for (int clustererDepth : {0, 1}) { |
| 149 | + const auto result = clusterize(digits, rofs, readerDepth, clustererDepth, false); |
| 150 | + BOOST_CHECK_EQUAL(result.clusters.size(), 2); |
| 151 | + BOOST_CHECK_EQUAL(result.labels.getNElements(), 0); |
| 152 | + } |
| 153 | + } |
| 154 | +} |
0 commit comments