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 maintain ed by the unit tests: AllStaticxAODVaraiblesAreKnown
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
161  //NB. restoreDecorations may throw a GaudiException, resulting in a call to terminate()
162  // because the function is annotated 'noexcept'
163  m_mutableTrackBackend = std::exchange(other.m_mutableTrackBackend, nullptr);
164  m_mutableTrackBackendAux = std::exchange(other.m_mutableTrackBackendAux, nullptr);
165  //setStore throws an exception of type SG::ExcUntrackedSetStore, SG::ExcCLIDMismatch
166  //resulting in a call to terminate() because the function is marked 'noexcept'
167  m_mutableTrackBackend->setStore(m_mutableTrackBackendAux.get());
168  TrackSummaryContainer::m_trackBackend = m_mutableTrackBackend.get();
169 
170  m_surfaces = std::move(other.m_surfaces);
171  m_decorations = std::move(other.m_decorations);
172 
173  //restore decorations
174  // restoreDecorations may throw a GaudiException or SG::ExcBadVarName
175  // resulting in a call to terminate() because the function is marked 'noexcept'
177 
178  // invalidate vector type components of 'other'
179  other.m_surfaces.clear();
180  other.m_decorations.clear();
181 
182  return *this;
183 }
184 
186  m_mutableTrackBackend->push_back(std::make_unique<xAOD::TrackSummary>());
187  m_mutableTrackBackend->back()->resize();
188  // ACTS assumes default to be pion, xAOD::ParticleHypothesis == 0 is geantino
189  m_mutableTrackBackend->back()->setParticleHypothesis(xAOD::pion);
190  m_surfaces.push_back(nullptr);
191  return m_mutableTrackBackend->size() - 1;
192 }
193 
195  ActsTrk::IndexType itrack) {
196  if (itrack >= m_mutableTrackBackend->size()) {
197  throw std::out_of_range("removeTrack_impl track backend");
198  }
199  if (itrack >= m_surfaces.size()) {
200  throw std::out_of_range("removeTrack_impl surfaces");
201  }
202  m_mutableTrackBackend->erase(m_mutableTrackBackend->begin() + itrack);
203  m_surfaces.erase(m_surfaces.begin() + itrack);
204 }
205 
206 // this in fact may be a copy from other MutableTrackSymmaryContainer
208  ActsTrk::IndexType itrack, Acts::HashedString key,
209  const std::any& src_ptr) {
210  if ( staticVariableHashes.count(key) == 1) { return; }
211  for ( const auto& d: m_decorations) {
212  if (d.hash != key) { continue; }
213  d.copier(m_mutableTrackBackendAux.get(), itrack, d.auxid, src_ptr);
214  }
215 }
216 
218  Acts::HashedString key, ActsTrk::IndexType itrack) {
219  std::any result = ::component_impl(*m_mutableTrackBackend, key, itrack);
220  if (result.has_value()) {
221  return result;
222  }
223  for (auto& d : m_decorations) {
224  if (d.hash == key) {
225  return d.setter(m_mutableTrackBackendAux.get(), itrack, d.auxid);
226  }
227  }
228  throw std::runtime_error("TrackSummaryContainer no such component " +
230 }
231 
233  ActsTrk::IndexType itrack) {
234  return m_mutableTrackBackend->at(itrack)->paramsEigen();
235 }
236 
238  ActsTrk::IndexType itrack) {
239  return m_mutableTrackBackend->at(itrack)->covParamsEigen();
240 }
241 
244  for (auto& d : other.m_decorations) {
245  m_decorations.push_back(d);
246  }
247 }
248 
250  const TrackSummaryContainer& other) {
251  for (auto& d : other.m_decorations) {
252  m_decorations.push_back(d);
253  }
254 }
255 
257  m_mutableTrackBackend->reserve(size);
258 }
259 
261  m_mutableTrackBackend->clear();
262  m_surfaces.clear();
263 }
264 
266  ActsTrk::IndexType itrack, std::shared_ptr<const Acts::Surface> surface) {
267  m_surfaces[itrack] = surface;
268 }
269 
271  dest->resize(m_surfaces.size());
272  size_t destIndex = 0;
273  // go over all surfaces and for each free surface record persistent version of it in the xAOD
274  // at the same time store index to it updating TrackSummary
275  for ( ActsTrk::IndexType index = 0, eindex = m_surfaces.size(); index < eindex; ++index ) {
276  if ( m_surfaces[index] == nullptr or m_surfaces[index]->geometryId().value() != 0 ) {
277  m_mutableTrackBackend->at(index)->setSurfaceIndex(Acts::kTrackIndexInvalid);
278  } else {
279  m_mutableTrackBackend->at(index)->setSurfaceIndex(destIndex);
280  encodeSurface(dest, destIndex, m_surfaces[index].get(), geoContext);
281  destIndex++;
282  }
283  }
284  dest->resize(destIndex);
285 }
286 
288  m_mutableTrackBackend->at(itrack)->setParticleHypothesis(ActsTrk::ParticleHypothesis::convert(particleHypothesis));
289 }
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:237
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:287
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
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
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:265
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
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:260
ActsTrk::MutableTrackSummaryContainer::addTrack_impl
ActsTrk::IndexType addTrack_impl()
adds new track to the tail of the container
Definition: TrackSummaryContainer.cxx:185
ActsTrk::MutableTrackSummaryContainer::reserve
void reserve(ActsTrk::IndexType size)
preallocate number of track objects
Definition: TrackSummaryContainer.cxx:256
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:207
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:217
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:270
ActsTrk::MutableTrackSummaryContainer::removeTrack_impl
void removeTrack_impl(ActsTrk::IndexType itrack)
clears track data under index
Definition: TrackSummaryContainer.cxx:194
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
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::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
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:242
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:127
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:232
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