ATLAS Offline Software
Loading...
Searching...
No Matches
SeedContainer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ACTSTRKEVENT_SEEDCONTAINER_H
6#define ACTSTRKEVENT_SEEDCONTAINER_H 1
7
8#include <algorithm>
9#include <utility>
10#include <vector>
11
12#include "Acts/EventData/SeedContainer2.hpp"
14
15namespace ActsTrk {
16
17// This is similar to Acts::SeedContainer2 but stores pointers to
18// xAOD::SpacePoints instead of indices into an Acts::SpacePointContainer2.
19//
20// Having a separate container is beneficial as there is not too much overlap
21// with Acts::SeedContainer2 and the implementation is rather simple. This
22// decouples us from the implementation of Acts::SeedContainer2 and allows us to
23// link directly to the xAOD::SpacePoints without needing to convert back and
24// forth between indices and pointers.
25
26// hack extension of std::span with necessary at() method for seed parameter
27// estimation
28struct SpacePointRange final : public std::span<const xAOD::SpacePoint* const> {
29 using Base = std::span<const xAOD::SpacePoint* const>;
30
31 using Base::Base;
32
33 const xAOD::SpacePoint* at(std::size_t index) const {
34 if (index >= size()) {
35 throw std::out_of_range("SpacePointRange index out of range");
36 }
37 return Base::operator[](index);
38 }
39};
40
41struct SeedContainer;
42
43struct Seed final {
44 using Index = Acts::SeedIndex2;
45
48
49 const SeedContainer& container() const noexcept { return *m_container; }
50 Index index() const noexcept { return m_index; }
51
53 float quality() const noexcept;
54 float vertexZ() const noexcept;
55
56 // emulate old Acts::Seed methods
57 SpacePointRange sp() const noexcept { return spacePoints(); }
58 float z() const noexcept { return vertexZ(); }
59 float seedQuality() const noexcept { return quality(); }
60
61 private:
62 const SeedContainer* m_container{nullptr};
64};
65
66struct SeedContainer final {
67 using Index = Acts::SeedIndex2;
69
70 std::size_t size() const noexcept { return m_size; }
71 bool empty() const noexcept { return size() == 0; }
72 void reserve(std::size_t size, float averageSpacePoints = 3) noexcept {
74 m_spacePointCounts.reserve(size);
75 m_qualities.reserve(size);
76 m_vertexZs.reserve(size);
77 m_spacePoints.reserve(static_cast<std::size_t>(size * averageSpacePoints));
78 }
79 void clear() noexcept {
80 m_size = 0;
81 m_spacePointOffsets.clear();
82 m_spacePointCounts.clear();
83 m_qualities.clear();
84 m_vertexZs.clear();
85 m_spacePoints.clear();
86 }
87
88 Seed operator[](Index index) const noexcept { return Seed(*this, index); }
89 Seed at(Index index) const {
90 if (index >= size()) {
91 throw std::out_of_range("SeedContainer index out of range");
92 }
93 return Seed(*this, index);
94 }
95
97 const std::uint32_t offset = m_spacePointOffsets[index];
98 const std::uint8_t count = m_spacePointCounts[index];
99 return SpacePointRange(m_spacePoints.data() + offset, count);
100 }
101 float quality(Index index) const noexcept { return m_qualities[index]; }
102 float vertexZ(Index index) const noexcept { return m_vertexZs[index]; }
103
105 Acts::detail::ContainerIterator<SeedContainer, Seed, Index, true>;
106
107 const_iterator begin() const noexcept { return const_iterator(*this, 0); }
108 const_iterator end() const noexcept { return const_iterator(*this, size()); }
109
110 // various push_back() styles
111
114 m_spacePoints.insert(m_spacePoints.end(), spacePoints.begin(),
115 spacePoints.end());
116 return at(m_size++);
117 }
118
119 template <typename arbitrary_sp_range_t, typename xaod_sp_ptr_projector_t>
120 Seed push_back(const arbitrary_sp_range_t& arbitrarySpacePoints,
121 const xaod_sp_ptr_projector_t& xAODspProjector, float quality,
122 float vertexZ) {
123 push_back_(arbitrarySpacePoints.size(), quality, vertexZ);
124 std::ranges::copy(
125 std::views::transform(arbitrarySpacePoints, xAODspProjector),
126 std::back_inserter(m_spacePoints));
127 return at(m_size++);
128 }
129
131 const Acts::ConstSeedProxy2& seed) {
132 return push_back(spacePoints, seed.quality(), seed.vertexZ());
133 }
134
135 template <typename xaod_sp_ptr_projector_t>
136 Seed push_back(const Acts::ConstSeedProxy2& seed,
137 const xaod_sp_ptr_projector_t& xAODspProjector) {
138 return push_back(seed.spacePointIndices(), xAODspProjector, seed);
139 }
140
141 template <typename arbitrary_sp_range_t, typename xaod_sp_ptr_projector_t>
142 Seed push_back(const arbitrary_sp_range_t& arbitrarySpacePoints,
143 const xaod_sp_ptr_projector_t& xAODspProjector,
144 const Acts::ConstSeedProxy2& seed) {
145 return push_back(arbitrarySpacePoints, xAODspProjector, seed.quality(),
146 seed.vertexZ());
147 }
148
149 private:
150 std::uint32_t m_size{0};
151 std::vector<std::uint32_t> m_spacePointOffsets;
152 std::vector<std::uint8_t> m_spacePointCounts;
153 std::vector<float> m_qualities;
154 std::vector<float> m_vertexZs;
155
156 std::vector<const xAOD::SpacePoint*> m_spacePoints;
157
158 void push_back_(std::size_t nSpacePoints, float quality, float vertexZ) {
159 const std::uint32_t offset =
160 static_cast<std::uint32_t>(m_spacePoints.size());
161 const std::uint8_t count = static_cast<std::uint8_t>(nSpacePoints);
162
163 m_spacePointOffsets.push_back(offset);
164 m_spacePointCounts.push_back(count);
165 m_qualities.push_back(quality);
166 m_vertexZs.push_back(vertexZ);
167 }
168};
169
171 return container().spacePoints(m_index);
172}
173inline float Seed::quality() const noexcept {
174 return container().quality(m_index);
175}
176inline float Seed::vertexZ() const noexcept {
177 return container().vertexZ(m_index);
178}
179
180} // namespace ActsTrk
181
182// Set up a CLID for the type:
184CLASS_DEF(ActsTrk::SeedContainer, 1261318102, 2)
185
186#endif
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
size_t size() const
Number of registered mappings.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition index.py:1
Seed at(Index index) const
std::vector< std::uint8_t > m_spacePointCounts
Seed push_back(const Acts::ConstSeedProxy2 &seed, const xaod_sp_ptr_projector_t &xAODspProjector)
std::vector< const xAOD::SpacePoint * > m_spacePoints
Seed push_back(SpacePointRange spacePoints, const Acts::ConstSeedProxy2 &seed)
std::vector< float > m_qualities
bool empty() const noexcept
SpacePointRange spacePoints(Index index) const noexcept
Seed push_back(const arbitrary_sp_range_t &arbitrarySpacePoints, const xaod_sp_ptr_projector_t &xAODspProjector, float quality, float vertexZ)
void push_back_(std::size_t nSpacePoints, float quality, float vertexZ)
Seed push_back(SpacePointRange spacePoints, float quality, float vertexZ)
Seed operator[](Index index) const noexcept
void clear() noexcept
Acts::SeedIndex2 Index
void reserve(std::size_t size, float averageSpacePoints=3) noexcept
float quality(Index index) const noexcept
const_iterator begin() const noexcept
std::vector< float > m_vertexZs
Acts::detail::ContainerIterator< SeedContainer, Seed, Index, true > const_iterator
Seed push_back(const arbitrary_sp_range_t &arbitrarySpacePoints, const xaod_sp_ptr_projector_t &xAODspProjector, const Acts::ConstSeedProxy2 &seed)
std::size_t size() const noexcept
float vertexZ(Index index) const noexcept
const_iterator end() const noexcept
std::vector< std::uint32_t > m_spacePointOffsets
Index index() const noexcept
float vertexZ() const noexcept
const SeedContainer & container() const noexcept
float z() const noexcept
Acts::SeedIndex2 Index
float seedQuality() const noexcept
float quality() const noexcept
SpacePointRange sp() const noexcept
Seed(const SeedContainer &container, Index index)
const SeedContainer * m_container
SpacePointRange spacePoints() const noexcept
std::span< const xAOD::SpacePoint *const > Base
const xAOD::SpacePoint * at(std::size_t index) const