File indexing completed on 2025-01-18 09:12:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Clusterization/TimedClusterization.hpp"
0012
0013 namespace Acts::Test {
0014
0015
0016 using Identifier = std::size_t;
0017 struct Cell {
0018 Cell(Identifier identifier, int c, int r, double t)
0019 : id(identifier), column(c), row(r), time(t) {}
0020
0021 Identifier id{};
0022 int column{0};
0023 int row{0};
0024 int label{-1};
0025 double time{0.};
0026 };
0027
0028 struct Cluster {
0029 std::vector<Identifier> ids{};
0030 };
0031
0032 using CellCollection = std::vector<Acts::Test::Cell>;
0033 using ClusterCollection = std::vector<Acts::Test::Cluster>;
0034
0035
0036 static inline int getCellRow(const Cell& cell) {
0037 return cell.row;
0038 }
0039
0040 static inline int getCellColumn(const Cell& cell) {
0041 return cell.column;
0042 }
0043
0044 static inline int& getCellLabel(Cell& cell) {
0045 return cell.label;
0046 }
0047
0048 static inline double getCellTime(const Cell& cell) {
0049 return cell.time;
0050 }
0051
0052 static void clusterAddCell(Cluster& cl, const Cell& cell) {
0053 cl.ids.push_back(cell.id);
0054 }
0055
0056 BOOST_AUTO_TEST_CASE(TimedGrid_1D_withtime) {
0057
0058
0059
0060
0061
0062
0063 std::vector<Cell> cells;
0064
0065 cells.emplace_back(0ul, 0, -1, 0);
0066 cells.emplace_back(1ul, 1, -1, 0);
0067 cells.emplace_back(2ul, 2, -1, 0);
0068 cells.emplace_back(3ul, 5, -1, 0);
0069 cells.emplace_back(4ul, 8, -1, 0);
0070 cells.emplace_back(5ul, 9, -1, 0);
0071
0072 cells.emplace_back(6ul, 3, 0, 1);
0073 cells.emplace_back(7ul, 6, 1, 1);
0074 cells.emplace_back(8ul, 7, 1, 1);
0075
0076 std::vector<std::vector<Identifier>> expectedResults;
0077 expectedResults.push_back({0ul, 1ul, 2ul});
0078 expectedResults.push_back({6ul});
0079 expectedResults.push_back({3ul});
0080 expectedResults.push_back({7ul, 8ul});
0081 expectedResults.push_back({4ul, 5ul});
0082
0083 ClusterCollection clusters =
0084 Acts::Ccl::createClusters<CellCollection, ClusterCollection, 1>(
0085 cells, Acts::Ccl::TimedConnect<Cell, 1>(0.5));
0086
0087 BOOST_CHECK_EQUAL(5ul, clusters.size());
0088
0089 for (std::size_t i(0); i < clusters.size(); ++i) {
0090 std::vector<Identifier>& timedIds = clusters[i].ids;
0091 const std::vector<Identifier>& expected = expectedResults[i];
0092 std::sort(timedIds.begin(), timedIds.end());
0093 BOOST_CHECK_EQUAL(timedIds.size(), expected.size());
0094
0095 for (std::size_t j(0); j < timedIds.size(); ++j) {
0096 BOOST_CHECK_EQUAL(timedIds[j], expected[j]);
0097 }
0098 }
0099 }
0100
0101 BOOST_AUTO_TEST_CASE(TimedGrid_2D_notime) {
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 std::vector<Cell> cells;
0112 cells.emplace_back(0ul, 0, 0, 0);
0113 cells.emplace_back(1ul, 3, 0, 0);
0114 cells.emplace_back(2ul, 3, 1, 0);
0115 cells.emplace_back(3ul, 0, 2, 0);
0116 cells.emplace_back(4ul, 1, 2, 0);
0117 cells.emplace_back(5ul, 0, 3, 0);
0118 cells.emplace_back(6ul, 3, 3, 0);
0119
0120 std::vector<std::vector<Identifier>> expectedResults;
0121 expectedResults.push_back({0ul});
0122 expectedResults.push_back({3ul, 4ul, 5ul});
0123 expectedResults.push_back({1ul, 2ul});
0124 expectedResults.push_back({6ul});
0125
0126 ClusterCollection clusters =
0127 Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>(
0128 cells,
0129 Acts::Ccl::TimedConnect<Cell, 2>(std::numeric_limits<double>::max()));
0130
0131 BOOST_CHECK_EQUAL(4ul, clusters.size());
0132
0133
0134 ClusterCollection defaultClusters =
0135 Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>(
0136 cells, Acts::Ccl::DefaultConnect<Cell, 2>());
0137
0138 BOOST_CHECK_EQUAL(4ul, defaultClusters.size());
0139 BOOST_CHECK_EQUAL(defaultClusters.size(), expectedResults.size());
0140
0141 std::vector<std::size_t> sizes{1, 3, 2, 1};
0142 for (std::size_t i(0); i < clusters.size(); ++i) {
0143 std::vector<Identifier>& timedIds = clusters[i].ids;
0144 std::vector<Identifier>& defaultIds = defaultClusters[i].ids;
0145 const std::vector<Identifier>& expected = expectedResults[i];
0146 BOOST_CHECK_EQUAL(timedIds.size(), defaultIds.size());
0147 BOOST_CHECK_EQUAL(timedIds.size(), sizes[i]);
0148 BOOST_CHECK_EQUAL(timedIds.size(), expected.size());
0149
0150 std::sort(timedIds.begin(), timedIds.end());
0151 std::sort(defaultIds.begin(), defaultIds.end());
0152 for (std::size_t j(0); j < timedIds.size(); ++j) {
0153 BOOST_CHECK_EQUAL(timedIds[j], defaultIds[j]);
0154 BOOST_CHECK_EQUAL(timedIds[j], expected[j]);
0155 }
0156 }
0157 }
0158
0159 BOOST_AUTO_TEST_CASE(TimedGrid_2D_withtime) {
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 std::vector<Cell> cells;
0170
0171 cells.emplace_back(0ul, 0, 0, 0);
0172 cells.emplace_back(1ul, 3, 0, 0);
0173 cells.emplace_back(2ul, 3, 1, 0);
0174 cells.emplace_back(3ul, 0, 2, 0);
0175 cells.emplace_back(4ul, 1, 2, 0);
0176 cells.emplace_back(5ul, 0, 3, 0);
0177 cells.emplace_back(6ul, 3, 3, 0);
0178
0179 cells.emplace_back(7ul, 1, 0, 1);
0180 cells.emplace_back(8ul, 1, 1, 1);
0181 cells.emplace_back(9ul, 2, 1, 1);
0182
0183 cells.emplace_back(10ul, 2, 2, 2);
0184 cells.emplace_back(11ul, 3, 2, 2);
0185
0186 std::vector<std::vector<Identifier>> expectedResults;
0187 expectedResults.push_back({0ul});
0188 expectedResults.push_back({3ul, 4ul, 5ul});
0189 expectedResults.push_back({7ul, 8ul, 9ul});
0190 expectedResults.push_back({10ul, 11ul});
0191 expectedResults.push_back({1ul, 2ul});
0192 expectedResults.push_back({6ul});
0193
0194 ClusterCollection clusters =
0195 Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>(
0196 cells, Acts::Ccl::TimedConnect<Cell, 2>(0.5));
0197
0198 BOOST_CHECK_EQUAL(6ul, clusters.size());
0199
0200 std::vector<std::size_t> sizes{1, 3, 3, 2, 2, 1};
0201 for (std::size_t i(0); i < clusters.size(); ++i) {
0202 std::vector<Identifier>& timedIds = clusters[i].ids;
0203 BOOST_CHECK_EQUAL(timedIds.size(), sizes[i]);
0204 std::sort(timedIds.begin(), timedIds.end());
0205
0206 const std::vector<Identifier>& expected = expectedResults[i];
0207 BOOST_CHECK_EQUAL(timedIds.size(), expected.size());
0208
0209 for (std::size_t j(0); j < timedIds.size(); ++j) {
0210 BOOST_CHECK_EQUAL(timedIds[j], expected[j]);
0211 }
0212 }
0213 }
0214
0215 BOOST_AUTO_TEST_CASE(TimedGrid_2D_noTollerance) {
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226 std::vector<Cell> cells;
0227 cells.emplace_back(0ul, 0, 0, 0);
0228 cells.emplace_back(1ul, 3, 0, 0);
0229 cells.emplace_back(2ul, 3, 1, 0);
0230 cells.emplace_back(3ul, 0, 2, 0);
0231 cells.emplace_back(4ul, 1, 2, 0);
0232 cells.emplace_back(5ul, 0, 3, 0);
0233 cells.emplace_back(6ul, 3, 3, 0);
0234
0235 std::vector<std::vector<Identifier>> expectedResults;
0236 expectedResults.push_back({0ul});
0237 expectedResults.push_back({3ul});
0238 expectedResults.push_back({5ul});
0239 expectedResults.push_back({4ul});
0240 expectedResults.push_back({1ul});
0241 expectedResults.push_back({2ul});
0242 expectedResults.push_back({6ul});
0243
0244 ClusterCollection clusters =
0245 Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>(
0246 cells, Acts::Ccl::TimedConnect<Cell, 2>(0.));
0247
0248 BOOST_CHECK_EQUAL(7ul, clusters.size());
0249
0250 for (std::size_t i(0); i < clusters.size(); ++i) {
0251 std::vector<Identifier>& timedIds = clusters[i].ids;
0252 const std::vector<Identifier>& expected = expectedResults[i];
0253
0254 BOOST_CHECK_EQUAL(timedIds.size(), 1);
0255 BOOST_CHECK_EQUAL(timedIds.size(), expected.size());
0256 BOOST_CHECK_EQUAL(timedIds[0], expected[0]);
0257 }
0258 }
0259
0260 }