ATLAS Offline Software
Loading...
Searching...
No Matches
SeedContainer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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/Seed.hpp" // only needed for conversion from Acts::Seed
13#include "Acts/EventData/SeedContainer2.hpp"
15
16namespace ActsTrk {
17
18// This is similar to Acts::SeedContainer2 but stores pointers to
19// xAOD::SpacePoints instead of indices into an Acts::SpacePointContainer2.
20//
21// Having a separate container is beneficial as there is not too much overlap
22// with Acts::SeedContainer2 and the implementation is rather simple. This
23// decouples us from the implementation of Acts::SeedContainer2 and allows us to
24// link directly to the xAOD::SpacePoints without needing to convert back and
25// forth between indices and pointers.
26
27// hack extension of std::span with necessary at() method for seed parameter
28// estimation
29struct SpacePointRange final : public std::span<const xAOD::SpacePoint* const> {
30 using Base = std::span<const xAOD::SpacePoint* const>;
31
32 using Base::Base;
33
34 const xAOD::SpacePoint* at(std::size_t index) const {
35 if (index >= size()) {
36 throw std::out_of_range("SpacePointRange index out of range");
37 }
38 return Base::operator[](index);
39 }
40};
41
42struct SeedContainer;
43
44struct Seed final {
45 using Index = Acts::SeedIndex2;
46
49
50 const SeedContainer& container() const noexcept { return *m_container; }
51 Index index() const noexcept { return m_index; }
52
54 float quality() const noexcept;
55 float vertexZ() const noexcept;
56
57 // emulate old Acts::Seed methods
58 SpacePointRange sp() const noexcept { return spacePoints(); }
59 float z() const noexcept { return vertexZ(); }
60 float seedQuality() const noexcept { return quality(); }
61
62 private:
63 const SeedContainer* m_container{nullptr};
65};
66
67struct SeedContainer final {
68 using Index = Acts::SeedIndex2;
70
71 std::size_t size() const noexcept { return m_size; }
72 bool empty() const noexcept { return size() == 0; }
73 void reserve(std::size_t size, float averageSpacePoints = 3) noexcept {
75 m_spacePointCounts.reserve(size);
76 m_qualities.reserve(size);
77 m_vertexZs.reserve(size);
78 m_spacePoints.reserve(static_cast<std::size_t>(size * averageSpacePoints));
79 }
80 void clear() noexcept {
81 m_size = 0;
82 m_spacePointOffsets.clear();
83 m_spacePointCounts.clear();
84 m_qualities.clear();
85 m_vertexZs.clear();
86 m_spacePoints.clear();
87 }
88
89 Seed operator[](Index index) const noexcept { return Seed(*this, index); }
90 Seed at(Index index) const {
91 if (index >= size()) {
92 throw std::out_of_range("SeedContainer index out of range");
93 }
94 return Seed(*this, index);
95 }
96
98 const std::uint32_t offset = m_spacePointOffsets[index];
99 const std::uint8_t count = m_spacePointCounts[index];
100 return SpacePointRange(m_spacePoints.data() + offset, count);
101 }
102 float quality(Index index) const noexcept { return m_qualities[index]; }
103 float vertexZ(Index index) const noexcept { return m_vertexZs[index]; }
104
106 Acts::detail::ContainerIterator<SeedContainer, Seed, Index, true>;
107
108 const_iterator begin() const noexcept { return const_iterator(*this, 0); }
109 const_iterator end() const noexcept { return const_iterator(*this, size()); }
110
111 // various push_back() styles
112
115 m_spacePoints.insert(m_spacePoints.end(), spacePoints.begin(),
116 spacePoints.end());
117 return at(m_size++);
118 }
119
120 template <typename arbitrary_sp_range_t, typename xaod_sp_ptr_projector_t>
121 Seed push_back(const arbitrary_sp_range_t& arbitrarySpacePoints,
122 const xaod_sp_ptr_projector_t& xAODspProjector, float quality,
123 float vertexZ) {
124 push_back_(arbitrarySpacePoints.size(), quality, vertexZ);
125 std::ranges::copy(
126 std::views::transform(arbitrarySpacePoints, xAODspProjector),
127 std::back_inserter(m_spacePoints));
128 return at(m_size++);
129 }
130
132 const Acts::ConstSeedProxy2& seed) {
133 return push_back(spacePoints, seed.quality(), seed.vertexZ());
134 }
135
136 template <typename xaod_sp_ptr_projector_t>
137 Seed push_back(const Acts::ConstSeedProxy2& seed,
138 const xaod_sp_ptr_projector_t& xAODspProjector) {
139 return push_back(seed.spacePointIndices(), xAODspProjector, seed);
140 }
141
142 template <typename arbitrary_sp_range_t, typename xaod_sp_ptr_projector_t>
143 Seed push_back(const arbitrary_sp_range_t& arbitrarySpacePoints,
144 const xaod_sp_ptr_projector_t& xAODspProjector,
145 const Acts::ConstSeedProxy2& seed) {
146 return push_back(arbitrarySpacePoints, xAODspProjector, seed.quality(),
147 seed.vertexZ());
148 }
149
150 // convert from old Acts::Seed<Acts::SpacePointProxy> used by SeedingTool and
151 // OrthogonalSeedingTool
152 template <typename sp_proxy_t, std::size_t N>
153 Seed push_back(const Acts::Seed<sp_proxy_t, N>& pSeed) {
154 return push_back(
155 pSeed.sp(),
156 [](const sp_proxy_t* sp) { return &sp->externalSpacePoint(); },
157 pSeed.seedQuality(), pSeed.z());
158 }
159
160 private:
161 std::uint32_t m_size{0};
162 std::vector<std::uint32_t> m_spacePointOffsets;
163 std::vector<std::uint8_t> m_spacePointCounts;
164 std::vector<float> m_qualities;
165 std::vector<float> m_vertexZs;
166
167 std::vector<const xAOD::SpacePoint*> m_spacePoints;
168
169 void push_back_(std::size_t nSpacePoints, float quality, float vertexZ) {
170 const std::uint32_t offset =
171 static_cast<std::uint32_t>(m_spacePoints.size());
172 const std::uint8_t count = static_cast<std::uint8_t>(nSpacePoints);
173
174 m_spacePointOffsets.push_back(offset);
175 m_spacePointCounts.push_back(count);
176 m_qualities.push_back(quality);
177 m_vertexZs.push_back(vertexZ);
178 }
179};
180
182 return container().spacePoints(m_index);
183}
184inline float Seed::quality() const noexcept {
185 return container().quality(m_index);
186}
187inline float Seed::vertexZ() const noexcept {
188 return container().vertexZ(m_index);
189}
190
191} // namespace ActsTrk
192
193// Set up a CLID for the type:
195CLASS_DEF(ActsTrk::SeedContainer, 1261318102, 2)
196
197#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
static Double_t sp
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
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
Seed push_back(const Acts::Seed< sp_proxy_t, N > &pSeed)
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
Acts::detail::ContainerIterator< SeedContainer, Seed, Index, true > const_iterator
std::vector< float > m_vertexZs
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