diff --git a/Core/include/Acts/EventData/Seed.hpp b/Core/include/Acts/EventData/Seed.hpp index 15484c00496..da58f76d10b 100644 --- a/Core/include/Acts/EventData/Seed.hpp +++ b/Core/include/Acts/EventData/Seed.hpp @@ -13,21 +13,27 @@ namespace Acts { -template +template + requires(N >= 3) class Seed { public: - Seed(const external_spacepoint_t& b, const external_spacepoint_t& m, - const external_spacepoint_t& u); + using value_type = external_spacepoint_t; + static constexpr std::size_t DIM = N; + + template + requires(sizeof...(args_t) == N) && + (std::same_as && ...) + explicit Seed(const args_t&... points); void setVertexZ(float vertex); void setQuality(float seedQuality); - const std::array& sp() const; + const std::array& sp() const; float z() const; float seedQuality() const; private: - std::array m_spacepoints; + std::array m_spacepoints{}; float m_vertexZ{0.f}; float m_seedQuality{-std::numeric_limits::infinity()}; }; diff --git a/Core/include/Acts/EventData/Seed.ipp b/Core/include/Acts/EventData/Seed.ipp index 7fe7404513c..664a6ae196e 100644 --- a/Core/include/Acts/EventData/Seed.ipp +++ b/Core/include/Acts/EventData/Seed.ipp @@ -8,35 +8,42 @@ namespace Acts { -template -Seed::Seed(const external_spacepoint_t& b, - const external_spacepoint_t& m, - const external_spacepoint_t& u) - : m_spacepoints({&b, &m, &u}) {} - -template -void Seed::setVertexZ(float vertex) { +template + requires(N >= 3) +template + requires(sizeof...(args_t) == N) && + (std::same_as && ...) +Seed::Seed(const args_t&... points) + : m_spacepoints({&points...}) {} + +template + requires(N >= 3) +void Seed::setVertexZ(float vertex) { m_vertexZ = vertex; } -template -void Seed::setQuality(float seedQuality) { +template + requires(N >= 3) +void Seed::setQuality(float seedQuality) { m_seedQuality = seedQuality; } -template -const std::array& -Seed::sp() const { +template + requires(N >= 3) +const std::array& +Seed::sp() const { return m_spacepoints; } -template -float Seed::z() const { +template + requires(N >= 3) +float Seed::z() const { return m_vertexZ; } -template -float Seed::seedQuality() const { +template + requires(N >= 3) +float Seed::seedQuality() const { return m_seedQuality; } diff --git a/Tests/UnitTests/Core/EventData/CMakeLists.txt b/Tests/UnitTests/Core/EventData/CMakeLists.txt index 22a914df5b8..5699dc4527f 100644 --- a/Tests/UnitTests/Core/EventData/CMakeLists.txt +++ b/Tests/UnitTests/Core/EventData/CMakeLists.txt @@ -14,5 +14,6 @@ add_unittest(TrackStatePropMask TrackStatePropMaskTests.cpp) add_unittest(ParticleHypothesis ParticleHypothesisTests.cpp) add_unittest(MultiTrajectoryHelpers MultiTrajectoryHelpersTests.cpp) add_unittest(SubspaceHelpers SubspaceHelpersTests.cpp) +add_unittest(SeedEdm SeedEdmTests.cpp) add_non_compile_test(MultiTrajectory TrackContainerComplianceTests.cpp) diff --git a/Tests/UnitTests/Core/EventData/SeedEdmTests.cpp b/Tests/UnitTests/Core/EventData/SeedEdmTests.cpp new file mode 100644 index 00000000000..03b8f037efe --- /dev/null +++ b/Tests/UnitTests/Core/EventData/SeedEdmTests.cpp @@ -0,0 +1,105 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2024 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 http://mozilla.org/MPL/2.0/. + +#include + +#include "Acts/EventData/Seed.hpp" + +#include + +namespace Acts::Test { + +struct SpacePoint {}; + +BOOST_AUTO_TEST_CASE(seed_edm_constructors) { + std::array storage{}; + Acts::Seed seed(storage[0], storage[1], storage[2], + storage[3], storage[4]); + const std::array& sps = seed.sp(); + for (std::size_t i(0ul); i < 5ul; ++i) { + BOOST_CHECK_NE(sps[i], nullptr); + BOOST_CHECK_EQUAL(sps[i], &storage[i]); + } + + // Copy 1 + Acts::Seed seedCopy1(seed); + const std::array& spsCopy1 = seedCopy1.sp(); + for (std::size_t i(0ul); i < 5ul; ++i) { + BOOST_CHECK_NE(spsCopy1[i], nullptr); + BOOST_CHECK_EQUAL(spsCopy1[i], sps[i]); + } + + // Copy 2 + Acts::Seed seedCopy2{seed}; + const std::array& spsCopy2 = seedCopy2.sp(); + for (std::size_t i(0ul); i < 5ul; ++i) { + BOOST_CHECK_NE(spsCopy2[i], nullptr); + BOOST_CHECK_EQUAL(spsCopy2[i], sps[i]); + } + + // Collection + std::vector> seeds{seed}; + // Copy 1 + std::vector> seedsCopy1(seeds); + BOOST_CHECK_EQUAL(seedsCopy1.size(), seeds.size()); + // Copy 2 + std::vector> seedsCopy2{seeds}; + BOOST_CHECK_EQUAL(seedsCopy2.size(), seeds.size()); +} + +BOOST_AUTO_TEST_CASE(seed_edm_default) { + std::array storage{}; + Acts::Seed seed(storage[0], storage[1], storage[2]); + const std::array& sps = seed.sp(); + for (std::size_t i(0ul); i < 3ul; ++i) { + BOOST_CHECK_NE(sps[i], nullptr); + BOOST_CHECK_EQUAL(sps[i], &storage[i]); + } + + seed.setVertexZ(-1.2f); + BOOST_CHECK_EQUAL(seed.z(), -1.2f); + + seed.setQuality(345.23f); + BOOST_CHECK_EQUAL(seed.seedQuality(), 345.23f); +} + +BOOST_AUTO_TEST_CASE(seed_edm_3d) { + std::array storage{}; + Acts::Seed seed(storage[0], storage[1], + storage[2]); + const std::array& sps = seed.sp(); + for (std::size_t i(0ul); i < 3ul; ++i) { + BOOST_CHECK_NE(sps[i], nullptr); + BOOST_CHECK_EQUAL(sps[i], &storage[i]); + } + + seed.setVertexZ(-1.2f); + BOOST_CHECK_EQUAL(seed.z(), -1.2f); + + seed.setQuality(345.23f); + BOOST_CHECK_EQUAL(seed.seedQuality(), 345.23f); +} + +BOOST_AUTO_TEST_CASE(seed_edm_4d) { + std::array storage{}; + Acts::Seed seed(storage[0], storage[1], storage[2], + storage[3]); + const std::array& sps = seed.sp(); + for (std::size_t i(0ul); i < 4ul; ++i) { + BOOST_CHECK_NE(sps[i], nullptr); + BOOST_CHECK_EQUAL(sps[i], &storage[i]); + } + + seed.setVertexZ(-1.2f); + BOOST_CHECK_EQUAL(seed.z(), -1.2f); + + seed.setQuality(345.23f); + BOOST_CHECK_EQUAL(seed.seedQuality(), 345.23f); +} + +} // namespace Acts::Test