Skip to content

Commit

Permalink
implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cvarni authored and cvarni committed Oct 1, 2024
1 parent 4589935 commit 88532e6
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Core/include/Acts/Clusterization/Clusterization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ struct Connect2D {
bool conn8{true};
Connect2D() = default;
explicit Connect2D(bool commonCorner) : conn8{commonCorner} {}
ConnectResult operator()(const Cell& ref, const Cell& iter) const;
virtual ConnectResult operator()(const Cell& ref, const Cell& iter) const;
};

// Default connection type for 1-D grids: 2-cell connectivity
template <typename Cell>
struct Connect1D {
ConnectResult operator()(const Cell& ref, const Cell& iter) const;
virtual ConnectResult operator()(const Cell& ref, const Cell& iter) const;
};

// Default connection type based on GridDim
Expand Down
9 changes: 8 additions & 1 deletion Core/include/Acts/Clusterization/TimedClusterization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ struct TimedConnect : public Acts::Ccl::DefaultConnect<Cell, N> {
Acts::ActsScalar timeTollerance{std::numeric_limits<Acts::ActsScalar>::max()};

TimedConnect() = default;
TimedConnect(Acts::ActsScalar time) : timeTollerance(time) {}
TimedConnect(Acts::ActsScalar time)
requires(N == 1);
TimedConnect(Acts::ActsScalar time, bool conn = true)
requires(N == 2);

virtual ConnectResult operator()(const Cell& ref, const Cell& iter) const;
};

} // namespace Acts::Ccl

#include "Acts/Clusterization/TimedClusterization.ipp"
38 changes: 38 additions & 0 deletions Core/include/Acts/Clusterization/TimedClusterization.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// -*- C++ -*-
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

namespace Acts::Ccl {

template <Acts::Ccl::HasRetrievableTimeInfo Cell, std::size_t N>
TimedConnect<Cell, N>::TimedConnect(Acts::ActsScalar time)
requires(N == 1)
: timeTollerance(time) {}

template <Acts::Ccl::HasRetrievableTimeInfo Cell, std::size_t N>
TimedConnect<Cell, N>::TimedConnect(Acts::ActsScalar time, bool conn)
requires(N == 2)
: Acts::Ccl::DefaultConnect<Cell, N>(conn), timeTollerance(time) {}

template <Acts::Ccl::HasRetrievableTimeInfo Cell, std::size_t N>
Acts::Ccl::ConnectResult TimedConnect<Cell, N>::operator()(
const Cell& ref, const Cell& iter) const {
Acts::Ccl::ConnectResult spaceCompatibility =
Acts::Ccl::DefaultConnect<Cell, N>::operator()(ref, iter);
if (spaceCompatibility != Acts::Ccl::ConnectResult::eConn) {
return spaceCompatibility;
}

if (std::abs(getCellTime(ref) - getCellTime(iter)) < timeTollerance) {
return Acts::Ccl::ConnectResult::eConn;
}

return Acts::Ccl::ConnectResult::eNoConn;
}

} // namespace Acts::Ccl
102 changes: 102 additions & 0 deletions Tests/UnitTests/Core/Clusterization/TimedClusterizationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,106 @@ BOOST_AUTO_TEST_CASE(TimedGrid_2D_notime) {
}
}
}

BOOST_AUTO_TEST_CASE(TimedGrid_2D_withtime) {
// 4x4 matrix
/*
X Y O X
O Y Y X
X X Z Z
X O O X
*/
// 7 + 3 + 2 cells -> 4 + 1 + 1 clusters in total

std::vector<Cell> cells;
// X
cells.emplace_back(0ul, 0, 0, 0);
cells.emplace_back(1ul, 3, 0, 0);
cells.emplace_back(2ul, 3, 1, 0);
cells.emplace_back(3ul, 0, 2, 0);
cells.emplace_back(4ul, 1, 2, 0);
cells.emplace_back(5ul, 0, 3, 0);
cells.emplace_back(6ul, 3, 3, 0);
// Y
cells.emplace_back(7ul, 1, 0, 1);
cells.emplace_back(8ul, 1, 1, 1);
cells.emplace_back(9ul, 2, 1, 1);
// Z
cells.emplace_back(10ul, 2, 2, 2);
cells.emplace_back(11ul, 3, 2, 2);

std::vector<std::vector<Identifier>> expectedResults;
expectedResults.push_back({0ul});
expectedResults.push_back({3ul, 4ul, 5ul});
expectedResults.push_back({7ul, 8ul, 9ul});
expectedResults.push_back({10ul, 11ul});
expectedResults.push_back({1ul, 2ul});
expectedResults.push_back({6ul});

ClusterCollection clusters =
Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>(
cells, Acts::Ccl::TimedConnect<Cell, 2>(0.5));

BOOST_CHECK_EQUAL(6ul, clusters.size());

std::vector<std::size_t> sizes{1, 3, 3, 2, 2, 1};
for (std::size_t i(0); i < clusters.size(); ++i) {
std::vector<Identifier>& timedIds = clusters[i].ids;
BOOST_CHECK_EQUAL(timedIds.size(), sizes[i]);
std::sort(timedIds.begin(), timedIds.end());

const std::vector<Identifier>& expected = expectedResults[i];
BOOST_CHECK_EQUAL(timedIds.size(), expected.size());

for (std::size_t j(0); j < timedIds.size(); ++j) {
BOOST_CHECK_EQUAL(timedIds[j], expected[j]);
}
}
}

BOOST_AUTO_TEST_CASE(TimedGrid_2D_noTollerance) {
// 4x4 matrix
/*
X O O X
O O O X
X X O O
X O O X
*/
// 7 cells -> 7 clusters in total
// since time requirement will never be satisfied

std::vector<Cell> cells;
cells.emplace_back(0ul, 0, 0, 0);
cells.emplace_back(1ul, 3, 0, 0);
cells.emplace_back(2ul, 3, 1, 0);
cells.emplace_back(3ul, 0, 2, 0);
cells.emplace_back(4ul, 1, 2, 0);
cells.emplace_back(5ul, 0, 3, 0);
cells.emplace_back(6ul, 3, 3, 0);

std::vector<std::vector<Identifier>> expectedResults;
expectedResults.push_back({0ul});
expectedResults.push_back({3ul});
expectedResults.push_back({5ul});
expectedResults.push_back({4ul});
expectedResults.push_back({1ul});
expectedResults.push_back({2ul});
expectedResults.push_back({6ul});

ClusterCollection clusters =
Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>(
cells, Acts::Ccl::TimedConnect<Cell, 2>(0.));

BOOST_CHECK_EQUAL(7ul, clusters.size());

for (std::size_t i(0); i < clusters.size(); ++i) {
std::vector<Identifier>& timedIds = clusters[i].ids;
const std::vector<Identifier>& expected = expectedResults[i];

BOOST_CHECK_EQUAL(timedIds.size(), 1);
BOOST_CHECK_EQUAL(timedIds.size(), expected.size());
BOOST_CHECK_EQUAL(timedIds[0], expected[0]);
}
}

} // namespace Acts::Test

0 comments on commit 88532e6

Please sign in to comment.