ATLAS Offline Software
Loading...
Searching...
No Matches
TrackSummaryContainer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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", "nSplitHits", "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 "nSplitHits"_hash:
69 return container.at(itrack)->nSplitHitsPtr();
70 case "tipIndex"_hash:
71 return container.at(itrack)->tipIndexPtr();
72 case "stemIndex"_hash:
73 return container.at(itrack)->stemIndexPtr();
74
75 default:
76 return std::any();
77 }
78}
79} // namespace
80
82 Acts::HashedString key, ActsTrk::IndexType itrack) const {
83 std::any result = ::component_impl(*m_trackBackend, key, itrack);
84 if (result.has_value()) {
85 return result;
86 }
87 for (auto& d : m_decorations) {
88 if (d.hash == key) {
89 // TODO the dynamic case will be eliminated once we switch to use Aux containers directly
90 return d.getter(m_trackBackend->getStore(), itrack, d.auxid);
91 }
92 }
93 throw std::runtime_error("TrackSummaryContainer no such component " +
94 std::to_string(key));
95}
96
98 ActsTrk::IndexType itrack) const {
99 return m_trackBackend->at(itrack)->paramsEigen();
100}
101
103 ActsTrk::IndexType itrack) const {
104 return m_trackBackend->at(itrack)->covParamsEigen();
105}
106
111
115
116std::vector<Acts::HashedString> ActsTrk::TrackSummaryContainer::dynamicKeys_impl() const {
117 std::vector<Acts::HashedString> result;
118 for ( const auto& d: m_decorations) {
119 if (staticVariableHashes.count(d.hash) == 1) {
120 continue;
121 }
122 result.push_back(d.hash);
123 }
124 return result;
125}
126
128 m_surfaces.reserve(src->size());
129 for ( auto xAODSurfacePtr: *src) {
130 m_surfaces.push_back( decodeSurface(xAODSurfacePtr));
131 }
132}
133
134
135
136
138// write api
147
159
160// move assignment operator
161//coverity[exn_spec_violation]
163 ActsTrk::MutableTrackSummaryContainer&& other) noexcept {
164 //NB. restoreDecorations may throw a GaudiException, resulting in a call to terminate()
165 // because the function is annotated 'noexcept'
166 m_mutableTrackBackend = std::exchange(other.m_mutableTrackBackend, nullptr);
167 m_mutableTrackBackendAux = std::exchange(other.m_mutableTrackBackendAux, nullptr);
168 //setStore throws an exception of type SG::ExcUntrackedSetStore, SG::ExcCLIDMismatch
169 //resulting in a call to terminate() because the function is marked 'noexcept'
172
173 m_surfaces = std::move(other.m_surfaces);
174 m_decorations = std::move(other.m_decorations);
175
176 //restore decorations
177 // restoreDecorations may throw a GaudiException or SG::ExcBadVarName
178 // resulting in a call to terminate() because the function is marked 'noexcept'
180
181 // invalidate vector type components of 'other'
182 other.m_surfaces.clear();
183 other.m_decorations.clear();
184
185 return *this;
186}
187
189 m_mutableTrackBackend->push_back(std::make_unique<xAOD::TrackSummary>());
190 m_mutableTrackBackend->back()->resize();
191 // ACTS assumes default to be pion, xAOD::ParticleHypothesis == 0 is geantino
192 m_mutableTrackBackend->back()->setParticleHypothesis(xAOD::pion);
193 m_surfaces.push_back(nullptr);
194 return m_mutableTrackBackend->size() - 1;
195}
196
198 ActsTrk::IndexType itrack) {
199 if (itrack >= m_mutableTrackBackend->size()) {
200 throw std::out_of_range("removeTrack_impl track backend");
201 }
202 if (itrack >= m_surfaces.size()) {
203 throw std::out_of_range("removeTrack_impl surfaces");
204 }
205 m_mutableTrackBackend->erase(m_mutableTrackBackend->begin() + itrack);
206 m_surfaces.erase(m_surfaces.begin() + itrack);
207}
208
209// this in fact may be a copy from other MutableTrackSymmaryContainer
211 ActsTrk::IndexType itrack, Acts::HashedString key,
212 const std::any& src_ptr) {
213 if ( staticVariableHashes.count(key) == 1) { return; }
214 for ( const auto& d: m_decorations) {
215 if (d.hash != key) { continue; }
216 d.copier(m_mutableTrackBackendAux.get(), itrack, d.auxid, src_ptr);
217 }
218}
219
221 Acts::HashedString key, ActsTrk::IndexType itrack) {
222 std::any result = ::component_impl(*m_mutableTrackBackend, key, itrack);
223 if (result.has_value()) {
224 return result;
225 }
226 for (auto& d : m_decorations) {
227 if (d.hash == key) {
228 return d.setter(m_mutableTrackBackendAux.get(), itrack, d.auxid);
229 }
230 }
231 throw std::runtime_error("TrackSummaryContainer no such component " +
232 std::to_string(key));
233}
234
239
244
246 const MutableTrackSummaryContainer& other) {
247 for (auto& d : other.m_decorations) {
248 m_decorations.push_back(d);
249 }
250}
251
253 const TrackSummaryContainer& other) {
254 for (auto& d : other.m_decorations) {
255 m_decorations.push_back(d);
256 }
257}
258
262
267
269 ActsTrk::IndexType itrack, std::shared_ptr<const Acts::Surface> surface) {
270 m_surfaces[itrack] = std::move(surface);
271}
272
274 dest->resize(m_surfaces.size());
275 size_t destIndex = 0;
276 // go over all surfaces and for each free surface record persistent version of it in the xAOD
277 // at the same time store index to it updating TrackSummary
278 for ( ActsTrk::IndexType index = 0, eindex = m_surfaces.size(); index < eindex; ++index ) {
279 if ( m_surfaces[index] == nullptr or m_surfaces[index]->geometryId().value() != 0 ) {
280 m_mutableTrackBackend->at(index)->setSurfaceIndex(Acts::kTrackIndexInvalid);
281 } else {
282 m_mutableTrackBackend->at(index)->setSurfaceIndex(destIndex);
283 encodeSurface(dest, destIndex, m_surfaces[index].get(), geoContext);
284 destIndex++;
285 }
286 }
287 dest->resize(destIndex);
288}
289
290void ActsTrk::MutableTrackSummaryContainer::setParticleHypothesis_impl(ActsTrk::IndexType itrack, const Acts::ParticleHypothesis& particleHypothesis) {
291 m_mutableTrackBackend->at(itrack)->setParticleHypothesis(ActsTrk::ParticleHypothesis::convert(particleHypothesis));
292}
size_t size() const
Number of registered mappings.
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:132
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:18
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