Skip to content

Commit 37c1aae

Browse files
authored
Merge branch 'main' into feat-change-material-to-proto-axis
2 parents 3e58799 + 0cfe0c7 commit 37c1aae

3 files changed

Lines changed: 118 additions & 11 deletions

File tree

Core/include/Acts/Clusterization/Clusterization.ipp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ struct ConnectionsBase {
6565
template <std::size_t GridDim>
6666
class Connections {};
6767

68-
// On 1-D grid, cells have 1 backward neighbor
68+
// On 1-D grid, cells have 1 backward space neighbor, but there can be up to 2
69+
// cells with different times in that space that can connect
6970
template <>
70-
struct Connections<1> : public ConnectionsBase<1> {
71+
struct Connections<1> : public ConnectionsBase<2> {
7172
using ConnectionsBase::ConnectionsBase;
7273
};
7374

74-
// On a 2-D grid, cells have 4 backward neighbors
75+
// On a 2-D grid, cells have 4 backward space neighbors, but there can be up to
76+
// 2 cells with different times in each of those spaces that can connect
7577
template <>
76-
struct Connections<2> : public ConnectionsBase<4> {
78+
struct Connections<2> : public ConnectionsBase<8> {
7779
using ConnectionsBase::ConnectionsBase;
7880
};
7981

Core/include/Acts/Clusterization/TimedClusterization.ipp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ Acts::Ccl::ConnectResult TimedConnect<Cell, N>::operator()(
2525
const Cell& ref, const Cell& iter) const {
2626
Acts::Ccl::ConnectResult spaceCompatibility =
2727
Acts::Ccl::DefaultConnect<Cell, N>::operator()(ref, iter);
28-
if (spaceCompatibility != Acts::Ccl::ConnectResult::eConn) {
29-
return spaceCompatibility;
30-
}
28+
double timeDiff = std::abs(getCellTime(iter) - getCellTime(ref));
3129

32-
if (std::abs(getCellTime(ref) - getCellTime(iter)) < timeTolerance) {
33-
return Acts::Ccl::ConnectResult::eConn;
30+
if (spaceCompatibility == Acts::Ccl::ConnectResult::eDuplicate ||
31+
spaceCompatibility == Acts::Ccl::ConnectResult::eConn) {
32+
return (timeDiff < timeTolerance) ? spaceCompatibility
33+
: Acts::Ccl::ConnectResult::eNoConn;
3434
}
35-
36-
return Acts::Ccl::ConnectResult::eNoConn;
35+
return spaceCompatibility;
3736
}
3837

3938
} // namespace Acts::Ccl

Tests/UnitTests/Core/Clusterization/TimedClusterizationTests.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,44 @@ BOOST_AUTO_TEST_CASE(TimedGrid_1D_withtime) {
9999
}
100100
}
101101

102+
BOOST_AUTO_TEST_CASE(TimedGrid_1D_duplicate_cells) {
103+
// Cells with same position but time difference larger than tolerance should
104+
// not be considered duplicates
105+
CellCollection cells = {Cell(0ul, 0, 0, 0.0), Cell(1ul, 0, 0, 1.0)};
106+
ClusterCollection clusters;
107+
Ccl::ClusteringData data;
108+
109+
Ccl::createClusters<CellCollection, ClusterCollection, 1>(
110+
data, cells, clusters, Ccl::TimedConnect<Cell, 1>(0.5));
111+
BOOST_CHECK_EQUAL(2ul, clusters.size());
112+
113+
// Cells with same position and time difference within tolerance should be
114+
// considered duplicates
115+
cells = {Cell(0ul, 0, 0, 0.0), Cell(1ul, 0, 0, 0.4)};
116+
clusters.clear();
117+
data.clear();
118+
119+
BOOST_CHECK_THROW(
120+
(Ccl::createClusters<CellCollection, ClusterCollection, 1>(
121+
data, cells, clusters, Ccl::TimedConnect<Cell, 1>(0.5))),
122+
std::invalid_argument);
123+
}
124+
125+
BOOST_AUTO_TEST_CASE(TimedGrid_1D_space_and_time) {
126+
// Cells with the same position but large time differences are not duplicates.
127+
// However, they can still be clustered through a neighboring cell if it is
128+
// within the time tolerance for both.
129+
CellCollection cells = {Cell(0ul, 0, 0, 0.0), Cell(1ul, 1, 0, 0.4),
130+
Cell(2ul, 0, 0, 0.8)};
131+
ClusterCollection clusters;
132+
Ccl::ClusteringData data;
133+
134+
Ccl::createClusters<CellCollection, ClusterCollection, 1>(
135+
data, cells, clusters, Ccl::TimedConnect<Cell, 1>(0.5));
136+
BOOST_CHECK_EQUAL(1ul, clusters.size());
137+
BOOST_CHECK_EQUAL(clusters[0].ids.size(), 3ul);
138+
}
139+
102140
BOOST_AUTO_TEST_CASE(TimedGrid_2D_notime) {
103141
// 4x4 matrix
104142
/*
@@ -262,4 +300,72 @@ BOOST_AUTO_TEST_CASE(TimedGrid_2D_noTollerance) {
262300
}
263301
}
264302

303+
BOOST_AUTO_TEST_CASE(TimedGrid_2D_duplicate_cells) {
304+
// Cells with same position but time difference larger than tolerance should
305+
// not be considered duplicates
306+
CellCollection cells = {Cell(0ul, 0, 0, 0.0), Cell(1ul, 0, 0, 1.0)};
307+
ClusterCollection clusters;
308+
Ccl::ClusteringData data;
309+
310+
Ccl::createClusters<CellCollection, ClusterCollection, 2>(
311+
data, cells, clusters, Ccl::TimedConnect<Cell, 2>(0.5));
312+
BOOST_CHECK_EQUAL(2ul, clusters.size());
313+
314+
// Cells with same position and time difference within tolerance should be
315+
// considered duplicates
316+
cells = {Cell(0ul, 0, 0, 0.0), Cell(1ul, 0, 0, 0.4)};
317+
clusters.clear();
318+
data.clear();
319+
320+
BOOST_CHECK_THROW(
321+
(Ccl::createClusters<CellCollection, ClusterCollection, 2>(
322+
data, cells, clusters, Ccl::TimedConnect<Cell, 2>(0.5))),
323+
std::invalid_argument);
324+
}
325+
326+
BOOST_AUTO_TEST_CASE(TimedGrid_2D_space_and_time_conn4) {
327+
// Cells with the same position but large time differences are not duplicates.
328+
// However, they can still be clustered through a neighboring cell if it is
329+
// within the time tolerance for both:
330+
// 3x3 matrix
331+
/*
332+
O X/Z O
333+
X/Z Y X/Z
334+
O X/Z O
335+
*/
336+
CellCollection cells = {
337+
Cell(0ul, 1, 0, 0.0), Cell(1ul, 0, 1, 0.0), Cell(2ul, 2, 1, 0.0),
338+
Cell(3ul, 1, 2, 0.0), Cell(4ul, 1, 0, 0.8), Cell(5ul, 0, 1, 0.8),
339+
Cell(6ul, 2, 1, 0.8), Cell(7ul, 1, 2, 0.8), Cell(8ul, 1, 1, 0.4)};
340+
ClusterCollection clusters;
341+
Ccl::ClusteringData data;
342+
343+
Ccl::createClusters<CellCollection, ClusterCollection, 2>(
344+
data, cells, clusters, Ccl::TimedConnect<Cell, 2>(0.5, false));
345+
BOOST_CHECK_EQUAL(1ul, clusters.size());
346+
BOOST_CHECK_EQUAL(clusters[0].ids.size(), 9ul);
347+
}
348+
349+
BOOST_AUTO_TEST_CASE(TimedGrid_2D_space_and_time_conn8) {
350+
// Cells with the same position but large time differences are not duplicates.
351+
// However, they can still be clustered through a neighboring cell if it is
352+
// within the time tolerance for both:
353+
// 3x3 matrix
354+
/*
355+
Z X O
356+
X Y O
357+
X/Z O O
358+
*/
359+
CellCollection cells = {Cell(0ul, 0, 0, 0.0), Cell(1ul, 0, 2, 0.0),
360+
Cell(2ul, 1, 0, 0.8), Cell(3ul, 0, 1, 0.8),
361+
Cell(4ul, 0, 2, 0.8), Cell(5ul, 1, 1, 0.4)};
362+
ClusterCollection clusters;
363+
Ccl::ClusteringData data;
364+
365+
Ccl::createClusters<CellCollection, ClusterCollection, 2>(
366+
data, cells, clusters, Ccl::TimedConnect<Cell, 2>(0.5, true));
367+
BOOST_CHECK_EQUAL(1ul, clusters.size());
368+
BOOST_CHECK_EQUAL(clusters[0].ids.size(), 6ul);
369+
}
370+
265371
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)