ATLAS Offline Software
TrackSummaryContainer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
5 #include <Acts/EventData/Types.hpp>
6 #include <stdexcept>
9 
10 // this is list of xAOD container variable names that are "hardcoded" in TrackSummary_v1
11 // their compatibility is maintain ed by the unit tests: AllStaticxAODVaraiblesAreKnown
12 const std::set<std::string> ActsTrk::TrackSummaryContainer::staticVariables = {
13  "params", "covParams", "nMeasurements", "nHoles", "chi2f",
14  "ndf", "nOutliers", "nSharedHits", "tipIndex", "stemIndex",
15  "particleHypothesis", "surfaceIndex"};
16 
17 using namespace Acts::HashedStringLiteral;
18 const std::set<Acts::HashedString> ActsTrk::TrackSummaryContainer::staticVariableHashes = [](){
19  std::set<Acts::HashedString> result;
21  result.insert(Acts::hashString(s));
22  }
23  return result;
24 }();
25 
26 
29  : m_trackBackend(link)
30  {}
31 
33  ActsTrk::IndexType itrack) const {
34  if (itrack >= m_surfaces.size())
35  throw std::out_of_range(
36  "TrackSummaryContainer index out of range when accessing reference "
37  "surface");
38  return m_surfaces[itrack].get();
39 }
40 
42  return ActsTrk::ParticleHypothesis::convert( static_cast<xAOD::ParticleHypothesis>(m_trackBackend->at(itrack)->particleHypothesis()));
43 }
44 
46  return m_trackBackend->size();
47 }
48 
49 namespace {
50 template <typename C>
51 std::any component_impl(C& container, Acts::HashedString key,
52  ActsTrk::IndexType itrack) {
53  using namespace Acts::HashedStringLiteral;
54  switch (key) {
55  case "nMeasurements"_hash:
56  return container.at(itrack)->nMeasurementsPtr();
57  case "nHoles"_hash:
58  return container.at(itrack)->nHolesPtr();
59  case "chi2"_hash:
60  return container.at(itrack)->chi2fPtr();
61  case "ndf"_hash:
62  return container.at(itrack)->ndfPtr();
63  case "nOutliers"_hash:
64  return container.at(itrack)->nOutliersPtr();
65  case "nSharedHits"_hash:
66  return container.at(itrack)->nSharedHitsPtr();
67  case "tipIndex"_hash:
68  return container.at(itrack)->tipIndexPtr();
69  case "stemIndex"_hash:
70  return container.at(itrack)->stemIndexPtr();
71 
72  default:
73  return std::any();
74  }
75 }
76 } // namespace
77 
79  Acts::HashedString key, ActsTrk::IndexType itrack) const {
80  std::any result = ::component_impl(*m_trackBackend, key, itrack);
81  if (result.has_value()) {
82  return result;
83  }
84  for (auto& d : m_decorations) {
85  if (d.hash == key) {
86  // TODO the dynamic case will be eliminated once we switch to use Aux containers directly
87  return d.getter(m_trackBackend->getStore(), itrack, d.auxid);
88  }
89  }
90  throw std::runtime_error("TrackSummaryContainer no such component " +
92 }
93 
95  ActsTrk::IndexType itrack) const {
96  return m_trackBackend->at(itrack)->paramsEigen();
97 }
98 
100  ActsTrk::IndexType itrack) const {
101  return m_trackBackend->at(itrack)->covParamsEigen();
102 }
103 
106  m_surfaces = std::move(mtb.m_surfaces);
107 }
108 
110  m_decorations = ActsTrk::detail::restoreDecorations(m_trackBackend->getConstStore(), staticVariables);
111 }
112 
113 std::vector<Acts::HashedString> ActsTrk::TrackSummaryContainer::dynamicKeys_impl() const {
114  std::vector<Acts::HashedString> result;
115  for ( const auto& d: m_decorations) {
116  if (staticVariableHashes.count(d.hash) == 1) {
117  continue;
118  }
119  result.push_back(d.hash);
120  }
121  return result;
122 }
123 
124 void ActsTrk::TrackSummaryContainer::decodeSurfaces(const xAOD::TrackSurfaceContainer* src, const Acts::GeometryContext& geoContext) {
125  for ( auto xAODSurfacePtr: *src) {
126  m_surfaces.push_back( decodeSurface(xAODSurfacePtr, geoContext));
127  }
128 }
129 
130 
131 
132 
134 // write api
137 
138  m_mutableTrackBackend = std::make_unique<xAOD::TrackSummaryContainer>();
139  m_mutableTrackBackendAux = std::make_unique<xAOD::TrackSummaryAuxContainer>();
140  m_mutableTrackBackend->setStore(m_mutableTrackBackendAux.get());
141 
142  TrackSummaryContainer::m_trackBackend = m_mutableTrackBackend.get();
143 }
144 
147  m_mutableTrackBackend = std::move(other.m_mutableTrackBackend);
148  m_mutableTrackBackendAux = std::move(other.m_mutableTrackBackendAux);
149  m_mutableTrackBackend->setStore(m_mutableTrackBackendAux.get());
150  TrackSummaryContainer::m_trackBackend = m_mutableTrackBackend.get();
151 
152  m_surfaces = std::move(other.m_surfaces);
153  m_decorations = std::move(other.m_decorations);
154 }
155 
156 // move assignment operator
159  //NB. restoreDecorations may throw a GaudiException, resulting in a call to terminate()
160  // because the function is annotated 'noexcept'
161  m_mutableTrackBackend = std::exchange(other.m_mutableTrackBackend, nullptr);
162  m_mutableTrackBackendAux = std::exchange(other.m_mutableTrackBackendAux, nullptr);
163  //setStore throws an exception of type SG::ExcUntrackedSetStore, SG::ExcCLIDMismatch
164  //resulting in a call to terminate() because the function is marked 'noexcept'
165  m_mutableTrackBackend->setStore(m_mutableTrackBackendAux.get());
166  TrackSummaryContainer::m_trackBackend = m_mutableTrackBackend.get();
167 
168  m_surfaces = std::move(other.m_surfaces);
169  m_decorations = std::move(other.m_decorations);
170 
171  //restore decorations
172  // restoreDecorations may throw a GaudiException or SG::ExcBadVarName
173  // resulting in a call to terminate() because the function is marked 'noexcept'
175 
176  // invalidate vector type components of 'other'
177  other.m_surfaces.clear();
178  other.m_decorations.clear();
179 
180  return *this;
181 }
182 
184  m_mutableTrackBackend->push_back(std::make_unique<xAOD::TrackSummary>());
185  m_mutableTrackBackend->back()->resize();
186  // ACTS assumes default to be pion, xAOD::ParticleHypothesis == 0 is geantino
187  m_mutableTrackBackend->back()->setParticleHypothesis(xAOD::pion);
188  m_surfaces.push_back(nullptr);
189  return m_mutableTrackBackend->size() - 1;
190 }
191 
193  ActsTrk::IndexType itrack) {
194  if (itrack >= m_mutableTrackBackend->size()) {
195  throw std::out_of_range("removeTrack_impl");
196  }
197  m_mutableTrackBackend->erase(m_mutableTrackBackend->begin() + itrack);
198 }
199 
200 // this in fact may be a copy from other MutableTrackSymmaryContainer
202  ActsTrk::IndexType itrack, Acts::HashedString key,
203  const std::any& src_ptr) {
204  if ( staticVariableHashes.count(key) == 1) { return; }
205  for ( const auto& d: m_decorations) {
206  if (d.hash != key) { continue; }
207  d.copier(m_mutableTrackBackendAux.get(), itrack, d.auxid, src_ptr);
208  }
209 }
210 
212  Acts::HashedString key, ActsTrk::IndexType itrack) {
213  std::any result = ::component_impl(*m_mutableTrackBackend, key, itrack);
214  if (result.has_value()) {
215  return result;
216  }
217  for (auto& d : m_decorations) {
218  if (d.hash == key) {
219  return d.setter(m_mutableTrackBackendAux.get(), itrack, d.auxid);
220  }
221  }
222  throw std::runtime_error("TrackSummaryContainer no such component " +
224 }
225 
227  ActsTrk::IndexType itrack) {
228  return m_mutableTrackBackend->at(itrack)->paramsEigen();
229 }
230 
232  ActsTrk::IndexType itrack) {
233  return m_mutableTrackBackend->at(itrack)->covParamsEigen();
234 }
235 
238  for (auto& d : other.m_decorations) {
239  m_decorations.push_back(d);
240  }
241 }
242 
244  const TrackSummaryContainer& other) {
245  for (auto& d : other.m_decorations) {
246  m_decorations.push_back(d);
247  }
248 }
249 
251  m_mutableTrackBackend->reserve(size);
252 }
253 
255  m_mutableTrackBackend->clear();
256  m_surfaces.clear();
257 }
258 
260  ActsTrk::IndexType itrack, std::shared_ptr<const Acts::Surface> surface) {
261  m_surfaces[itrack] = surface;
262 }
263 
265  dest->resize(m_surfaces.size());
266  size_t destIndex = 0;
267  // go over all surfaces and for each free surface record persistent version of it in the xAOD
268  // at the same time store index to it updating TrackSummary
269  for ( ActsTrk::IndexType index = 0, eindex = m_surfaces.size(); index < eindex; ++index ) {
270  if ( m_surfaces[index] == nullptr or m_surfaces[index]->geometryId().value() != 0 ) {
271  m_mutableTrackBackend->at(index)->setSurfaceIndex(Acts::kTrackIndexInvalid);
272  } else {
273  m_mutableTrackBackend->at(index)->setSurfaceIndex(destIndex);
274  encodeSurface(dest, destIndex, m_surfaces[index].get(), geoContext);
275  destIndex++;
276  }
277  }
278  dest->resize(destIndex);
279 }
280 
282  m_mutableTrackBackend->at(itrack)->setParticleHypothesis(ActsTrk::ParticleHypothesis::convert(particleHypothesis));
283 }
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:94
ActsTrk::TrackSummaryContainer::m_surfaces
std::vector< std::shared_ptr< const Acts::Surface > > m_surfaces
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:115
TrackSummaryContainer.h
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ActsTrk::MutableTrackSummaryContainer::covariance
ActsTrk::Covariance covariance(ActsTrk::IndexType itrack)
write access to covariance
Definition: TrackSummaryContainer.cxx:231
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::setParticleHypothesis_impl
void setParticleHypothesis_impl(ActsTrk::IndexType itrack, const Acts::ParticleHypothesis &particleHypothesis)
sets particle hypothesis
Definition: TrackSummaryContainer.cxx:281
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:137
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:41
xAOD::pion
@ pion
Definition: TrackingPrimitives.h:196
athena.value
value
Definition: athena.py:122
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:259
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:78
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:32
ActsTrk::TrackSummaryContainer::restoreDecorations
void restoreDecorations()
Definition: TrackSummaryContainer.cxx:109
ActsTrk::MutableTrackSummaryContainer::clear
void clear()
zeroes container
Definition: TrackSummaryContainer.cxx:254
ActsTrk::MutableTrackSummaryContainer::addTrack_impl
ActsTrk::IndexType addTrack_impl()
adds new track to the tail of the container
Definition: TrackSummaryContainer.cxx:183
ActsTrk::MutableTrackSummaryContainer::reserve
void reserve(ActsTrk::IndexType size)
preallocate number of track objects
Definition: TrackSummaryContainer.cxx:250
ActsTrk::TrackSummaryContainer::size_impl
std::size_t size_impl() const
returns number of stored tracks
Definition: TrackSummaryContainer.cxx:45
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:201
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:211
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:55
ActsTrk::ConstParameters
Acts::TrackStateTraits< 3 >::Parameters ConstParameters
Definition: Tracking/Acts/ActsEvent/ActsEvent/TrackSummaryContainer.h:49
ActsTrk::IndexType
std::uint32_t IndexType
Definition: Decoration.h:13
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:99
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:264
ActsTrk::MutableTrackSummaryContainer::removeTrack_impl
void removeTrack_impl(ActsTrk::IndexType itrack)
clears track data under index
Definition: TrackSummaryContainer.cxx:192
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
ActsTrk::TrackSummaryContainer::TrackSummaryContainer
TrackSummaryContainer(const DataLink< xAOD::TrackSummaryContainer > &lin=nullptr)
Definition: TrackSummaryContainer.cxx:27
ActsTrk::TrackSummaryContainer::dynamicKeys_impl
std::vector< Acts::HashedString > dynamicKeys_impl() const
Definition: TrackSummaryContainer.cxx:113
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
TrackSummary.h
ActsTrk::detail::restoreDecorations
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
Definition: Decoration.cxx:9
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
ActsTrk::decodeSurface
std::shared_ptr< const Acts::Surface > decodeSurface(const xAOD::TrackSurface *backend, const Acts::GeometryContext &geoContext)
Creates transient Acts Surface objects given a surface backend implementation should be exact mirror ...
Definition: SurfaceEncoding.cxx:143
ActsTrk::MutableTrackSummaryContainer::MutableTrackSummaryContainer
MutableTrackSummaryContainer()
Definition: TrackSummaryContainer.cxx:136
xAOD::ParticleHypothesis
ParticleHypothesis
Definition: TrackingPrimitives.h:192
ParticleHypothesisEncoding.h
ActsTrk::TrackSummaryContainer::fillFrom
void fillFrom(ActsTrk::MutableTrackSummaryContainer &mtb)
Definition: TrackSummaryContainer.cxx:104
ActsTrk::MutableTrackSummaryContainer::ensureDynamicColumns_impl
void ensureDynamicColumns_impl(const MutableTrackSummaryContainer &other)
synchronizes decorations
Definition: TrackSummaryContainer.cxx:236
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
ActsTrk::TrackSummaryContainer::decodeSurfaces
void decodeSurfaces(const xAOD::TrackSurfaceContainer *src, const Acts::GeometryContext &)
Definition: TrackSummaryContainer.cxx:124
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:226
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37