Skip to content

Commit

Permalink
Add support for seeds from N space points
Browse files Browse the repository at this point in the history
  • Loading branch information
cvarni committed Sep 28, 2024
1 parent 2196648 commit 9fb0598
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 23 deletions.
20 changes: 15 additions & 5 deletions Core/include/Acts/EventData/Seed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,31 @@

namespace Acts {

template <typename external_spacepoint_t>
template <typename external_spacepoint_t, std::size_t N = 3ul>
class Seed {
static_assert(N >= 3ul, "A seed needs at least 3 space points");

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 <typename... args_t>
Seed(const args_t&... points)
requires(sizeof...(points) == N) &&
(std::same_as<external_spacepoint_t, args_t> && ...);

void setVertexZ(float vertex);
void setQuality(float seedQuality);

const std::array<const external_spacepoint_t*, 3>& sp() const;
const std::array<const external_spacepoint_t*, N>& sp() const;
float z() const;
float seedQuality() const;

private:
std::array<const external_spacepoint_t*, 3> m_spacepoints;
template <typename... args_t>
void storeValues(const external_spacepoint_t& value, const args_t&... others);

std::array<const external_spacepoint_t*, N> m_spacepoints{};
float m_vertexZ{0.f};
float m_seedQuality{-std::numeric_limits<float>::infinity()};
};
Expand Down
48 changes: 31 additions & 17 deletions Core/include/Acts/EventData/Seed.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,49 @@

namespace Acts {

template <typename external_spacepoint_t>
Seed<external_spacepoint_t>::Seed(const external_spacepoint_t& b,
const external_spacepoint_t& m,
const external_spacepoint_t& u)
: m_spacepoints({&b, &m, &u}) {}

template <typename external_spacepoint_t>
void Seed<external_spacepoint_t>::setVertexZ(float vertex) {
template <typename external_spacepoint_t, std::size_t N>
template <typename... args_t>
Seed<external_spacepoint_t, N>::Seed(const args_t&... points)
requires(sizeof...(points) == N) &&
(std::same_as<external_spacepoint_t, args_t> && ...)
{
storeValues(points...);
}

template <typename external_spacepoint_t, std::size_t N>
template <typename... args_t>
void Seed<external_spacepoint_t, N>::storeValues(
const external_spacepoint_t& value, const args_t&... others) {
constexpr std::size_t M = sizeof...(others);
m_spacepoints[N - M - 1] = &value;
if constexpr (M != 0ul) {
storeValues(others...);
}
}

template <typename external_spacepoint_t, std::size_t N>
void Seed<external_spacepoint_t, N>::setVertexZ(float vertex) {
m_vertexZ = vertex;
}

template <typename external_spacepoint_t>
void Seed<external_spacepoint_t>::setQuality(float seedQuality) {
template <typename external_spacepoint_t, std::size_t N>
void Seed<external_spacepoint_t, N>::setQuality(float seedQuality) {
m_seedQuality = seedQuality;
}

template <typename external_spacepoint_t>
const std::array<const external_spacepoint_t*, 3>&
Seed<external_spacepoint_t>::sp() const {
template <typename external_spacepoint_t, std::size_t N>
const std::array<const external_spacepoint_t*, N>&
Seed<external_spacepoint_t, N>::sp() const {
return m_spacepoints;
}

template <typename external_spacepoint_t>
float Seed<external_spacepoint_t>::z() const {
template <typename external_spacepoint_t, std::size_t N>
float Seed<external_spacepoint_t, N>::z() const {
return m_vertexZ;
}

template <typename external_spacepoint_t>
float Seed<external_spacepoint_t>::seedQuality() const {
template <typename external_spacepoint_t, std::size_t N>
float Seed<external_spacepoint_t, N>::seedQuality() const {
return m_seedQuality;
}

Expand Down
1 change: 0 additions & 1 deletion Core/include/Acts/EventData/SpacePointProxyIterator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ template <typename container_t>
bool SpacePointProxyIterator<container_t>::operator==(
const SpacePointProxyIterator<container_t>& other) const {
return m_container == other.m_container && m_index == other.m_index;
;
}

template <typename container_t>
Expand Down
1 change: 1 addition & 0 deletions Tests/UnitTests/Core/EventData/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
107 changes: 107 additions & 0 deletions Tests/UnitTests/Core/EventData/SeedEdmTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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 <boost/test/unit_test.hpp>

#include "Acts/EventData/Seed.hpp"

#include <vector>

namespace Acts::Test {

struct SpacePoint {};

BOOST_AUTO_TEST_CASE(seed_edm_constructors) {
std::array<Acts::Test::SpacePoint, 5> storage{};
Acts::Seed<Acts::Test::SpacePoint, 5> seed(storage[0], storage[1], storage[2],
storage[3], storage[4]);
const std::array<const Acts::Test::SpacePoint*, 5>& 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<Acts::Test::SpacePoint, 5> seed_copy1(seed);
const std::array<const Acts::Test::SpacePoint*, 5>& sps_copy1 =
seed_copy1.sp();
for (std::size_t i(0ul); i < 5ul; ++i) {
BOOST_CHECK_NE(sps_copy1[i], nullptr);
BOOST_CHECK_EQUAL(sps_copy1[i], sps[i]);
}

// Copy 2
Acts::Seed<Acts::Test::SpacePoint, 5> seed_copy2{seed};
const std::array<const Acts::Test::SpacePoint*, 5>& sps_copy2 =
seed_copy2.sp();
for (std::size_t i(0ul); i < 5ul; ++i) {
BOOST_CHECK_NE(sps_copy2[i], nullptr);
BOOST_CHECK_EQUAL(sps_copy2[i], sps[i]);
}

// Collection
std::vector<Acts::Seed<Acts::Test::SpacePoint, 5>> seeds{seed};
// Copy 1
std::vector<Acts::Seed<Acts::Test::SpacePoint, 5>> seeds_copy1(seeds);
BOOST_CHECK_EQUAL(seeds_copy1.size(), seeds.size());
// Copy 2
std::vector<Acts::Seed<Acts::Test::SpacePoint, 5>> seeds_copy2{seeds};
BOOST_CHECK_EQUAL(seeds_copy2.size(), seeds.size());
}

BOOST_AUTO_TEST_CASE(seed_edm_default) {
std::array<Acts::Test::SpacePoint, 3> storage{};
Acts::Seed<Acts::Test::SpacePoint> seed(storage[0], storage[1], storage[2]);
const std::array<const Acts::Test::SpacePoint*, 3>& 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<Acts::Test::SpacePoint, 3> storage{};
Acts::Seed<Acts::Test::SpacePoint, 3> seed(storage[0], storage[1],
storage[2]);
const std::array<const Acts::Test::SpacePoint*, 3>& 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<Acts::Test::SpacePoint, 4> storage{};
Acts::Seed<Acts::Test::SpacePoint, 4> seed(storage[0], storage[1], storage[2],
storage[3]);
const std::array<const Acts::Test::SpacePoint*, 4>& 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

0 comments on commit 9fb0598

Please sign in to comment.