Skip to content

Commit

Permalink
inherits
Browse files Browse the repository at this point in the history
  • Loading branch information
cvarni authored and cvarni committed Oct 1, 2024
1 parent cb49553 commit 4589935
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 24 deletions.
9 changes: 8 additions & 1 deletion Core/include/Acts/Clusterization/TimedClusterization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "Acts/Clusterization/Clusterization.hpp"
#include "Acts/Definitions/Algebra.hpp"

#include <limits>

namespace Acts::Ccl {

template <typename Cell>
Expand All @@ -19,6 +21,11 @@ concept HasRetrievableTimeInfo = requires(Cell cell) {
};

template <Acts::Ccl::HasRetrievableTimeInfo Cell, std::size_t N>
struct TimedConnect {};
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) {}
};

} // namespace Acts::Ccl
120 changes: 97 additions & 23 deletions Tests/UnitTests/Core/Clusterization/TimedClusterizationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,103 @@
#include "Acts/Clusterization/TimedClusterization.hpp"

namespace Acts::Test {
// Define objects
using Identifier = std::size_t;
struct Cell {
Cell(Identifier identifier, int c, int r, double t)

// Define objects
using Identifier = std::size_t;
struct Cell {
Cell(Identifier identifier, int c, int r, double t)
: id(identifier), column(c), row(r), time(t) {}

Identifier id{};
int column{0};
int row{0};
int label{-1};
double time{0.};
};

struct Cluster {
std::vector<Identifier> ids{};
};

using CellCollection = std::vector<Acts::Test::Cell>;
using ClusterCollection = std::vector<Acts::Test::Cluster>;

BOOST_AUTO_TEST_CASE(TimedGrid_2D_notime) {

}

Identifier id{};
int column{0};
int row{0};
int label{-1};
double time{0.};
};

struct Cluster {
std::vector<Identifier> ids{};
};

using CellCollection = std::vector<Acts::Test::Cell>;
using ClusterCollection = std::vector<Acts::Test::Cluster>;

// Define functions
static inline int getCellRow(const Cell& cell) {
return cell.row;
}

static inline int getCellColumn(const Cell& cell) {
return cell.column;
}

static inline int& getCellLabel(Cell& cell) {
return cell.label;
}

static inline double getCellTime(const Cell& cell) {
return cell.time;
}

static void clusterAddCell(Cluster& cl, const Cell& cell) {
cl.ids.push_back(cell.id);
}

BOOST_AUTO_TEST_CASE(TimedGrid_2D_notime) {
// 4x4 matrix
/*
X O O X
O O O X
X X O O
X O O X
*/
// 7 cells -> 4 clusters in total

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, 4ul, 5ul});
expectedResults.push_back({1ul, 2ul});
expectedResults.push_back({6ul});

ClusterCollection clusters =
Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>(
cells,
Acts::Ccl::TimedConnect<Cell, 2>(std::numeric_limits<double>::max()));

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

// Compare against default connect (only space)
ClusterCollection defaultClusters =
Acts::Ccl::createClusters<CellCollection, ClusterCollection, 2>(
cells, Acts::Ccl::DefaultConnect<Cell, 2>());

BOOST_CHECK_EQUAL(4ul, defaultClusters.size());
BOOST_CHECK_EQUAL(defaultClusters.size(), expectedResults.size());

std::vector<std::size_t> sizes{1, 3, 2, 1};
for (std::size_t i(0); i < clusters.size(); ++i) {
std::vector<Identifier>& timedIds = clusters[i].ids;
std::vector<Identifier>& defaultIds = defaultClusters[i].ids;
const std::vector<Identifier>& expected = expectedResults[i];
BOOST_CHECK_EQUAL(timedIds.size(), defaultIds.size());
BOOST_CHECK_EQUAL(timedIds.size(), sizes[i]);
BOOST_CHECK_EQUAL(timedIds.size(), expected.size());

std::sort(timedIds.begin(), timedIds.end());
std::sort(defaultIds.begin(), defaultIds.end());
for (std::size_t j(0); j < timedIds.size(); ++j) {
BOOST_CHECK_EQUAL(timedIds[j], defaultIds[j]);
BOOST_CHECK_EQUAL(timedIds[j], expected[j]);
}
}
}
} // namespace Acts::Test

0 comments on commit 4589935

Please sign in to comment.