ATLAS Offline Software
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
13 const std::set<std::string> ActsTrk::TrackSummaryContainer::staticVariables = {
14  "params", "covParams", "nMeasurements", "nHoles", "chi2f",
15  "ndf", "nOutliers", "nSharedHits", "tipIndex", "stemIndex",
16  "particleHypothesis", "surfaceIndex"};
17 
18 using namespace Acts::HashedStringLiteral;
19 const 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 
30  : m_trackBackend(link)
31  {}
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 
50 namespace {
51 template <typename C>
52 std::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 " +
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 
107  m_surfaces = std::move(mtb.m_surfaces);
108 }
109 
111  m_decorations = ActsTrk::detail::restoreDecorations(m_trackBackend->getConstStore(), staticVariables);
112 }
113 
114 std::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
139  m_mutableTrackBackend(std::make_unique<xAOD::TrackSummaryContainer>()),
140  m_mutableTrackBackendAux(std::make_unique<xAOD::TrackSummaryAuxContainer>())
141 {
144 }
145 
148  m_mutableTrackBackend(std::move(other.m_mutableTrackBackend)),
149  m_mutableTrackBackendAux(std::move(other.m_mutableTrackBackendAux))
150 {
153 
154  m_surfaces = std::move(other.m_surfaces);
155  m_decorations = std::move(other.m_decorations);
156 }
157 
158 // move assignment operator
159 //coverity[exn_spec_violation]
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'
168  m_mutableTrackBackend->setStore(m_mutableTrackBackendAux.get());
169  TrackSummaryContainer::m_trackBackend = m_mutableTrackBackend.get();
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 " +
231 }
232 
234  ActsTrk::IndexType itrack) {
235  return m_mutableTrackBackend->at(itrack)->paramsEigen();
236 }
237 
239  ActsTrk::IndexType itrack) {
240  return m_mutableTrackBackend->at(itrack)->covParamsEigen();
241 }
242 
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 
258  m_mutableTrackBackend->reserve(size);
259 }
260 
262  m_mutableTrackBackend->clear();
263  m_surfaces.clear();
264 }
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 
289  m_mutableTrackBackend->at(itrack)->setParticleHypothesis(ActsTrk::ParticleHypothesis::convert(particleHypothesis));
290 }
ActsTrk::TrackSummaryContainer::IndexType
uint32_t IndexType
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:58
ActsTrk::TrackSummaryContainer::parameters
ActsTrk::ConstParameters parameters(ActsTrk::IndexType itrack) const
parameters of the track
Definition: TrackSummaryContainer.cxx:95
ActsTrk::TrackSummaryContainer::m_surfaces
std::vector< std::shared_ptr< const Acts::Surface > > m_surfaces
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:115
TrackSummaryContainer.h
xAOD::TrackSummaryAuxContainer
TrackSummaryAuxContainer_v1 TrackSummaryAuxContainer
Definition: TrackSummaryAuxContainer.h:10
ActsTrk::MutableTrackSummaryContainer::covariance
ActsTrk::Covariance covariance(ActsTrk::IndexType itrack)
write access to covariance
Definition: TrackSummaryContainer.cxx:238
get_generator_info.result
result
Definition: get_generator_info.py:21
ActsTrk::Parameters
Acts::TrackStateTraits< 3, false >::Parameters Parameters
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:51
ActsTrk::MutableTrackSummaryContainer::m_mutableTrackBackend
std::unique_ptr< xAOD::TrackSummaryContainer > m_mutableTrackBackend
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:209
ActsTrk::MutableTrackSummaryContainer::setParticleHypothesis_impl
void setParticleHypothesis_impl(ActsTrk::IndexType itrack, const Acts::ParticleHypothesis &particleHypothesis)
sets particle hypothesis
Definition: TrackSummaryContainer.cxx:288
ActsTrk::TrackSummaryContainer::staticVariables
static const std::set< std::string > staticVariables
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:61
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
index
Definition: index.py:1
hist_file_dump.d
d
Definition: hist_file_dump.py:142
ActsTrk::ParticleHypothesis::convert
xAOD::ParticleHypothesis convert(Acts::ParticleHypothesis h)
Definition: ParticleHypothesisEncoding.cxx:12
ActsTrk::TrackSummaryContainer::particleHypothesis_impl
Acts::ParticleHypothesis particleHypothesis_impl(IndexType itrack) const
return pointer to reference surface
Definition: TrackSummaryContainer.cxx:42
xAOD::pion
@ pion
Definition: TrackingPrimitives.h:197
athena.value
value
Definition: athena.py:124
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
ActsTrk::MutableTrackSummaryContainer::setReferenceSurface_impl
void setReferenceSurface_impl(ActsTrk::IndexType itrack, std::shared_ptr< const Acts::Surface > surface)
point given track to surface The surface ownership is shared
Definition: TrackSummaryContainer.cxx:266
perfmonmt-printer.dest
dest
Definition: perfmonmt-printer.py:189
xAOD::TrackSurfaceAuxContainer_v1
Definition: TrackSurfaceAuxContainer_v1.h:12
ActsTrk::TrackSummaryContainer::component_impl
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType itrack) const
access to components by pointer with type
Definition: TrackSummaryContainer.cxx:79
ActsTrk::TrackSummaryContainer::m_trackBackend
DataLink< xAOD::TrackSummaryContainer > m_trackBackend
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:113
MuonR4::to_string
std::string to_string(const SectorProjector proj)
Definition: MsTrackSeeder.cxx:66
ActsTrk::TrackSummaryContainer::referenceSurface_impl
const Acts::Surface * referenceSurface_impl(ActsTrk::IndexType itrack) const
return pointer to reference surface
Definition: TrackSummaryContainer.cxx:33
ActsTrk::TrackSummaryContainer::restoreDecorations
void restoreDecorations()
Definition: TrackSummaryContainer.cxx:110
ActsTrk::MutableTrackSummaryContainer::clear
void clear()
zeroes container
Definition: TrackSummaryContainer.cxx:261
ActsTrk::MutableTrackSummaryContainer::addTrack_impl
ActsTrk::IndexType addTrack_impl()
adds new track to the tail of the container
Definition: TrackSummaryContainer.cxx:186
ActsTrk::MutableTrackSummaryContainer::reserve
void reserve(ActsTrk::IndexType size)
preallocate number of track objects
Definition: TrackSummaryContainer.cxx:257
ActsTrk::TrackSummaryContainer::size_impl
std::size_t size_impl() const
returns number of stored tracks
Definition: TrackSummaryContainer.cxx:46
ActsTrk::TrackSummaryContainer::decodeSurfaces
void decodeSurfaces(const xAOD::TrackSurfaceContainer *src)
Definition: TrackSummaryContainer.cxx:125
ActsTrk::MutableTrackSummaryContainer::copyDynamicFrom_impl
void copyDynamicFrom_impl(ActsTrk::IndexType itrack, Acts::HashedString key, const std::any &src_ptr)
copies decorations from other container
Definition: TrackSummaryContainer.cxx:208
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ActsTrk::MutableTrackSummaryContainer::component_impl
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType itrack)
write access to decorations
Definition: TrackSummaryContainer.cxx:218
ActsTrk::encodeSurface
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.
Definition: SurfaceEncoding.cxx:72
ActsTrk::ConstParameters
Acts::TrackStateTraits< 3 >::Parameters ConstParameters
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:49
ActsTrk::IndexType
std::uint32_t IndexType
Definition: Decoration.h:14
SurfaceEncoding.h
ActsTrk::MutableTrackSummaryContainer
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:118
ActsTrk::MutableTrackSummaryContainer::operator=
MutableTrackSummaryContainer operator=(const MutableTrackSummaryContainer &)=delete
ActsTrk::TrackSummaryContainer::covariance
ActsTrk::ConstCovariance covariance(ActsTrk::IndexType itrack) const
covariance of the track fit
Definition: TrackSummaryContainer.cxx:100
ActsTrk::Covariance
Acts::TrackStateTraits< 3, false >::Covariance Covariance
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:52
ActsTrk::MutableTrackSummaryContainer::encodeSurfaces
void encodeSurfaces(xAOD::TrackSurfaceAuxContainer *dest, const Acts::GeometryContext &)
Definition: TrackSummaryContainer.cxx:271
ActsTrk::MutableTrackSummaryContainer::removeTrack_impl
void removeTrack_impl(ActsTrk::IndexType itrack)
clears track data under index
Definition: TrackSummaryContainer.cxx:195
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
ActsTrk::TrackSummaryContainer::TrackSummaryContainer
TrackSummaryContainer(const DataLink< xAOD::TrackSummaryContainer > &lin=nullptr)
Definition: TrackSummaryContainer.cxx:28
ActsTrk::TrackSummaryContainer::dynamicKeys_impl
std::vector< Acts::HashedString > dynamicKeys_impl() const
Definition: TrackSummaryContainer.cxx:114
ActsTrk::TrackSummaryContainer
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:56
ActsTrk::ConstCovariance
Acts::TrackStateTraits< 3 >::Covariance ConstCovariance
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:50
ActsTrk::MutableTrackSummaryContainer::m_mutableTrackBackendAux
std::unique_ptr< xAOD::TrackSummaryAuxContainer > m_mutableTrackBackendAux
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:210
TrackSummary.h
ActsTrk::detail::restoreDecorations
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
Definition: Decoration.cxx:21
ActsTrk::MutableTrackSummaryContainer::MutableTrackSummaryContainer
MutableTrackSummaryContainer()
Definition: TrackSummaryContainer.cxx:138
xAOD::ParticleHypothesis
ParticleHypothesis
Definition: TrackingPrimitives.h:193
ParticleHypothesisEncoding.h
ActsTrk::TrackSummaryContainer::fillFrom
void fillFrom(ActsTrk::MutableTrackSummaryContainer &mtb)
Definition: TrackSummaryContainer.cxx:105
ActsTrk::MutableTrackSummaryContainer::ensureDynamicColumns_impl
void ensureDynamicColumns_impl(const MutableTrackSummaryContainer &other)
synchronizes decorations
Definition: TrackSummaryContainer.cxx:243
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:130
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
ActsTrk::TrackSummaryContainer::m_decorations
std::vector< ActsTrk::detail::Decoration > m_decorations
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:114
ActsTrk::TrackSummaryContainer::staticVariableHashes
static const std::set< Acts::HashedString > staticVariableHashes
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:62
ActsTrk::MutableTrackSummaryContainer::parameters
ActsTrk::Parameters parameters(ActsTrk::IndexType itrack)
write access to parameters
Definition: TrackSummaryContainer.cxx:233
ActsTrk::decodeSurface
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 ...
Definition: SurfaceEncoding.cxx:136
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37