ATLAS Offline Software
Loading...
Searching...
No Matches
TrackSummaryContainer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5#include <Acts/EventData/Types.hpp>
6#include <stdexcept>
10
11// this is list of xAOD container variable names that are "hardcoded" in TrackSummary_v1
12// their compatibility is maintained by the unit tests: AllStaticxAODVariablesAreKnown
13const std::set<std::string> ActsTrk::TrackSummaryContainer::staticVariables = {
14 "params", "covParams", "nMeasurements", "nHoles", "chi2f",
15 "ndf", "nOutliers", "nSharedHits", "tipIndex", "stemIndex",
16 "particleHypothesis", "surfaceIndex"};
17
18using namespace Acts::HashedStringLiteral;
19const std::set<Acts::HashedString> ActsTrk::TrackSummaryContainer::staticVariableHashes = [](){
20 std::set<Acts::HashedString> result;
22 result.insert(Acts::hashStringDynamic(s));
23 }
24 return result;
25}();
26
27
32
34 ActsTrk::IndexType itrack) const {
35 if (itrack >= m_surfaces.size())
36 throw std::out_of_range(
37 "TrackSummaryContainer index out of range when accessing reference "
38 "surface");
39 return m_surfaces[itrack].get();
40}
41
43 return ActsTrk::ParticleHypothesis::convert( static_cast<xAOD::ParticleHypothesis>(m_trackBackend->at(itrack)->particleHypothesis()));
44}
45
47 return m_trackBackend->size();
48}
49
50namespace {
51template <typename C>
52std::any component_impl(C& container, Acts::HashedString key,
53 ActsTrk::IndexType itrack) {
54 using namespace Acts::HashedStringLiteral;
55 switch (key) {
56 case "nMeasurements"_hash:
57 return container.at(itrack)->nMeasurementsPtr();
58 case "nHoles"_hash:
59 return container.at(itrack)->nHolesPtr();
60 case "chi2"_hash:
61 return container.at(itrack)->chi2fPtr();
62 case "ndf"_hash:
63 return container.at(itrack)->ndfPtr();
64 case "nOutliers"_hash:
65 return container.at(itrack)->nOutliersPtr();
66 case "nSharedHits"_hash:
67 return container.at(itrack)->nSharedHitsPtr();
68 case "tipIndex"_hash:
69 return container.at(itrack)->tipIndexPtr();
70 case "stemIndex"_hash:
71 return container.at(itrack)->stemIndexPtr();
72
73 default:
74 return std::any();
75 }
76}
77} // namespace
78
80 Acts::HashedString key, ActsTrk::IndexType itrack) const {
81 std::any result = ::component_impl(*m_trackBackend, key, itrack);
82 if (result.has_value()) {
83 return result;
84 }
85 for (auto& d : m_decorations) {
86 if (d.hash == key) {
87 // TODO the dynamic case will be eliminated once we switch to use Aux containers directly
88 return d.getter(m_trackBackend->getStore(), itrack, d.auxid);
89 }
90 }
91 throw std::runtime_error("TrackSummaryContainer no such component " +
92 std::to_string(key));
93}
94
96 ActsTrk::IndexType itrack) const {
97 return m_trackBackend->at(itrack)->paramsEigen();
98}
99
101 ActsTrk::IndexType itrack) const {
102 return m_trackBackend->at(itrack)->covParamsEigen();
103}
104
109
113
114std::vector<Acts::HashedString> ActsTrk::TrackSummaryContainer::dynamicKeys_impl() const {
115 std::vector<Acts::HashedString> result;
116 for ( const auto& d: m_decorations) {
117 if (staticVariableHashes.count(d.hash) == 1) {
118 continue;
119 }
120 result.push_back(d.hash);
121 }
122 return result;
123}
124
126 m_surfaces.reserve(src->size());
127 for ( auto xAODSurfacePtr: *src) {
128 m_surfaces.push_back( decodeSurface(xAODSurfacePtr));
129 }
130}
131
132
133
134
136// write api
145
157
158// move assignment operator
159//coverity[exn_spec_violation]
161 ActsTrk::MutableTrackSummaryContainer&& other) noexcept {
162 //NB. restoreDecorations may throw a GaudiException, resulting in a call to terminate()
163 // because the function is annotated 'noexcept'
164 m_mutableTrackBackend = std::exchange(other.m_mutableTrackBackend, nullptr);
165 m_mutableTrackBackendAux = std::exchange(other.m_mutableTrackBackendAux, nullptr);
166 //setStore throws an exception of type SG::ExcUntrackedSetStore, SG::ExcCLIDMismatch
167 //resulting in a call to terminate() because the function is marked 'noexcept'
170
171 m_surfaces = std::move(other.m_surfaces);
172 m_decorations = std::move(other.m_decorations);
173
174 //restore decorations
175 // restoreDecorations may throw a GaudiException or SG::ExcBadVarName
176 // resulting in a call to terminate() because the function is marked 'noexcept'
178
179 // invalidate vector type components of 'other'
180 other.m_surfaces.clear();
181 other.m_decorations.clear();
182
183 return *this;
184}
185
187 m_mutableTrackBackend->push_back(std::make_unique<xAOD::TrackSummary>());
188 m_mutableTrackBackend->back()->resize();
189 // ACTS assumes default to be pion, xAOD::ParticleHypothesis == 0 is geantino
190 m_mutableTrackBackend->back()->setParticleHypothesis(xAOD::pion);
191 m_surfaces.push_back(nullptr);
192 return m_mutableTrackBackend->size() - 1;
193}
194
196 ActsTrk::IndexType itrack) {
197 if (itrack >= m_mutableTrackBackend->size()) {
198 throw std::out_of_range("removeTrack_impl track backend");
199 }
200 if (itrack >= m_surfaces.size()) {
201 throw std::out_of_range("removeTrack_impl surfaces");
202 }
203 m_mutableTrackBackend->erase(m_mutableTrackBackend->begin() + itrack);
204 m_surfaces.erase(m_surfaces.begin() + itrack);
205}
206
207// this in fact may be a copy from other MutableTrackSymmaryContainer
209 ActsTrk::IndexType itrack, Acts::HashedString key,
210 const std::any& src_ptr) {
211 if ( staticVariableHashes.count(key) == 1) { return; }
212 for ( const auto& d: m_decorations) {
213 if (d.hash != key) { continue; }
214 d.copier(m_mutableTrackBackendAux.get(), itrack, d.auxid, src_ptr);
215 }
216}
217
219 Acts::HashedString key, ActsTrk::IndexType itrack) {
220 std::any result = ::component_impl(*m_mutableTrackBackend, key, itrack);
221 if (result.has_value()) {
222 return result;
223 }
224 for (auto& d : m_decorations) {
225 if (d.hash == key) {
226 return d.setter(m_mutableTrackBackendAux.get(), itrack, d.auxid);
227 }
228 }
229 throw std::runtime_error("TrackSummaryContainer no such component " +
230 std::to_string(key));
231}
232
237
242
244 const MutableTrackSummaryContainer& other) {
245 for (auto& d : other.m_decorations) {
246 m_decorations.push_back(d);
247 }
248}
249
251 const TrackSummaryContainer& other) {
252 for (auto& d : other.m_decorations) {
253 m_decorations.push_back(d);
254 }
255}
256
260
265
267 ActsTrk::IndexType itrack, std::shared_ptr<const Acts::Surface> surface) {
268 m_surfaces[itrack] = std::move(surface);
269}
270
272 dest->resize(m_surfaces.size());
273 size_t destIndex = 0;
274 // go over all surfaces and for each free surface record persistent version of it in the xAOD
275 // at the same time store index to it updating TrackSummary
276 for ( ActsTrk::IndexType index = 0, eindex = m_surfaces.size(); index < eindex; ++index ) {
277 if ( m_surfaces[index] == nullptr or m_surfaces[index]->geometryId().value() != 0 ) {
278 m_mutableTrackBackend->at(index)->setSurfaceIndex(Acts::kTrackIndexInvalid);
279 } else {
280 m_mutableTrackBackend->at(index)->setSurfaceIndex(destIndex);
281 encodeSurface(dest, destIndex, m_surfaces[index].get(), geoContext);
282 destIndex++;
283 }
284 }
285 dest->resize(destIndex);
286}
287
288void ActsTrk::MutableTrackSummaryContainer::setParticleHypothesis_impl(ActsTrk::IndexType itrack, const Acts::ParticleHypothesis& particleHypothesis) {
289 m_mutableTrackBackend->at(itrack)->setParticleHypothesis(ActsTrk::ParticleHypothesis::convert(particleHypothesis));
290}
void reserve(ActsTrk::IndexType size)
preallocate number of track objects
ActsTrk::IndexType addTrack_impl()
adds new track to the tail of the container
std::unique_ptr< xAOD::TrackSummaryAuxContainer > m_mutableTrackBackendAux
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType itrack)
write access to decorations
void setParticleHypothesis_impl(ActsTrk::IndexType itrack, const Acts::ParticleHypothesis &particleHypothesis)
sets particle hypothesis
void copyDynamicFrom_impl(ActsTrk::IndexType itrack, Acts::HashedString key, const std::any &src_ptr)
copies decorations from other container
void ensureDynamicColumns_impl(const MutableTrackSummaryContainer &other)
synchronizes decorations
void removeTrack_impl(ActsTrk::IndexType itrack)
clears track data under index
MutableTrackSummaryContainer operator=(const MutableTrackSummaryContainer &)=delete
void setReferenceSurface_impl(ActsTrk::IndexType itrack, std::shared_ptr< const Acts::Surface > surface)
point given track to surface The surface ownership is shared
void encodeSurfaces(xAOD::TrackSurfaceAuxContainer *dest, const Acts::GeometryContext &)
ActsTrk::Covariance covariance(ActsTrk::IndexType itrack)
write access to covariance
ActsTrk::Parameters parameters(ActsTrk::IndexType itrack)
write access to parameters
const Acts::Surface * referenceSurface_impl(ActsTrk::IndexType itrack) const
return pointer to reference surface
Acts::ParticleHypothesis particleHypothesis_impl(IndexType itrack) const
return pointer to reference surface
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType itrack) const
access to components by pointer with type
ActsTrk::ConstParameters parameters(ActsTrk::IndexType itrack) const
parameters of the track
std::size_t size_impl() const
returns number of stored tracks
std::vector< Acts::HashedString > dynamicKeys_impl() const
ActsTrk::ConstCovariance covariance(ActsTrk::IndexType itrack) const
covariance of the track fit
static const std::set< Acts::HashedString > staticVariableHashes
void fillFrom(ActsTrk::MutableTrackSummaryContainer &mtb)
std::vector< std::shared_ptr< const Acts::Surface > > m_surfaces
void decodeSurfaces(const xAOD::TrackSurfaceContainer *src)
TrackSummaryContainer(const DataLink< xAOD::TrackSummaryContainer > &lin=nullptr)
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
struct color C
xAOD::ParticleHypothesis convert(Acts::ParticleHypothesis h)
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
void encodeSurface(xAOD::TrackSurfaceAuxContainer *backend, size_t index, const Acts::Surface *surface, const Acts::GeometryContext &geoContext)
Prepares persistifiable representation of surface into xAOD::TrackSurface object.
std::shared_ptr< const Acts::Surface > decodeSurface(const xAOD::TrackSurface *backend)
Creates transient Acts Surface objects given a surface backend implementation should be exact mirror ...
Acts::TrackStateTraits< 3 >::Covariance ConstCovariance
Acts::TrackStateTraits< 3, false >::Covariance Covariance
Acts::TrackStateTraits< 3, false >::Parameters Parameters
Acts::TrackStateTraits< 3 >::Parameters ConstParameters
std::uint32_t IndexType
Definition Decoration.h:14
Definition index.py:1
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
TrackSurfaceAuxContainer_v1 TrackSurfaceAuxContainer
TrackSurfaceContainer_v1 TrackSurfaceContainer