ATLAS Offline Software
MultiTrajectory.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
11 
13 
14 const std::set<std::string> ActsTrk::MutableMultiTrajectory::s_staticVariables = {
15  "chi2", "pathLength", "typeFlags", "previous", "next", "predicted", "filtered", "smoothed", "jacobian", "calibrated", "measDim",
16  "uncalibratedMeasurement", "uncalibratedMeasurementLink" /*created by converter*/, "geometryId", "surfaceIndex"
17  };
18 
19 namespace {
20  // utility functions facilitate access of dynamic (or static) aux variables
21  template <typename T>
22  using const_span = std::span<T const>;
23 
24  // get an aux variable for elements (read/write)
25  template <typename T>
26  std::span<T> getElementVector( xAOD::AuxContainerBase &aux_container, const SG::ConstAccessor<T> &accessor) {
27  const T *data = static_cast<const T *>(aux_container.getData (accessor.auxid()));
28  T *non_const_data = const_cast< T *>(data); // aux_container is non-const so can be modified.
29  std::span<T> ret(non_const_data, aux_container.size() );
30  return ret;
31  }
32  // get an aux variable for elements (read only)
33  template <typename T>
34  const_span<T> getElementVector(const xAOD::AuxContainerBase &aux_container, const SG::ConstAccessor<T> &accessor) {
35  const T *data = static_cast<const T *>(aux_container.getData (accessor.auxid()));
36  const_span<T> ret( data, aux_container.size() );
37  return ret;
38  }
39 
40  // create a new decoration for all elements using the default value
41  template <typename T>
42  std::span<T> createDecoration(xAOD::AuxContainerBase &aux_container, const SG::Decorator<T> &decor) {
43  std::size_t sz=aux_container.size();
44  T *data = static_cast<T *>(aux_container.getDecoration(decor.auxid(), sz, sz));
45  return std::span<T>( data, sz );
46  }
47 
48  void throwRangeError(const xAOD::AuxContainerBase &aux_container, std::size_t index) {
49  std::stringstream msg;
50  msg << "range error: " << index << " >= " << aux_container.size()
51  << " when accessing container of type " << typeid(xAOD::AuxContainerBase).name();
52  throw std::range_error(msg.str());
53  }
54 
55  // get one an aux variable (dynamic or static) for one element
56  // @throw will throw if the index exceeds the container size
57  template <typename T>
58  const T &getElement(const xAOD::AuxContainerBase &aux_container, const SG::ConstAccessor<T> &accessor, std::size_t index) {
59  if (index>= aux_container.size()) {
60  throwRangeError(aux_container, index);
61  }
62  const_span<const xAOD::UncalibratedMeasurement*> vec = getElementVector(aux_container, accessor);
63  return vec[index];
64  }
65 }
66 
67 
68 template<typename T>
69 const T* to_const_ptr(const std::unique_ptr<T>& ptr) {
70  return ptr.get();
71 }
72 
74  : m_trackStatesAux (std::make_unique<xAOD::TrackStateAuxContainer>()),
75  m_trackParametersAux (std::make_unique<xAOD::TrackParametersAuxContainer>()),
76  m_trackJacobiansAux (std::make_unique<xAOD::TrackJacobianAuxContainer>()),
77  m_trackMeasurementsAux (std::make_unique<xAOD::TrackMeasurementAuxContainer>()),
78  m_surfacesBackend (std::make_unique<xAOD::TrackSurfaceContainer>()),
79  m_surfacesBackendAux (std::make_unique<xAOD::TrackSurfaceAuxContainer>())
80 {
81  INSPECTCALL("c-tor " << this)
82 
83  m_surfacesBackend->setStore(m_surfacesBackendAux.get());
84 
85 }
86 
89  {
90  INSPECTCALL("copy c-tor " << this << " src " << &other << " " << other.size())
91 
92  *m_trackStatesAux.get() = *other.m_trackStatesAux.get();
93  *m_trackParametersAux.get() = *other.m_trackParametersAux.get();
94  *m_trackJacobiansAux.get() = *other.m_trackJacobiansAux.get();
95  *m_trackMeasurementsAux.get() = *other.m_trackMeasurementsAux.get();
96  m_decorations = other.m_decorations;
97  m_calibratedSourceLinks = other.m_calibratedSourceLinks;
98  m_uncalibratedSourceLinks = other.m_uncalibratedSourceLinks;
99 
100  m_surfaces = other.m_surfaces;
101  m_geoContext = other.m_geoContext;
102  INSPECTCALL("copy c-tor done")
103 }
104 
105 
107  return m_trackStatesAux != nullptr and m_trackParametersAux != nullptr and
108  m_trackJacobiansAux != nullptr and m_trackMeasurementsAux != nullptr
109  and m_surfacesBackend != nullptr;
110 }
111 
112 namespace{
113  template<typename CONT>
114  void stepResize( CONT* auxPtr, const size_t realSize, const size_t sizeStep = 20) {
115  if( realSize >= auxPtr->size() ) auxPtr->resize(auxPtr->size()+sizeStep);
116  }
117 }
118 
120  Acts::TrackStatePropMask mask,
122  using namespace Acts::HashedStringLiteral;
123  INSPECTCALL( this << " " << mask << " " << m_trackStatesAux->size() << " " << previous);
124  assert(m_trackStatesAux && "Missing Track States backend");
125  constexpr size_t NDim = 6; // TODO take this from somewhere
126  stepResize(m_trackStatesAux.get(), m_trackStatesSize);
127  m_surfaces.push_back(nullptr);
128 
129  // set kInvalid
130  using Acts::MultiTrajectoryTraits::kInvalid;
131 
132  if (previous >= kInvalid - 1)
133  previous = kInvalid; // fix needed in Acts::MTJ
134  m_trackStatesAux->previous[m_trackStatesSize] = previous;
135  using namespace Acts;
136 
137  auto addParam = [this]() -> ActsTrk::IndexType {
138  stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
139  // TODO ask AK if this resize could be method of aux container
140  m_trackParametersAux->params[m_trackParametersSize].resize(NDim);
141  m_trackParametersAux->covMatrix[m_trackParametersSize].resize(NDim*NDim);
142  m_trackParametersSize++;
143  return m_trackParametersSize-1;
144  };
145 
146  auto addJacobian = [this]() -> ActsTrk::IndexType {
147  stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
148  m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(NDim*NDim);
149  m_trackJacobiansSize++;
150  return m_trackJacobiansSize-1;
151  };
152 
153  auto addMeasurement = [this]() -> ActsTrk::IndexType {
154  stepResize(m_trackMeasurementsAux.get(), m_trackMeasurementsSize );
155  m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(NDim);
156  m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(NDim*NDim);
157  m_trackMeasurementsSize++;
158  return m_trackMeasurementsSize-1;
159  };
160 
161  m_trackStatesAux->predicted[m_trackStatesSize] = kInvalid;
162  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
163  m_trackStatesAux->predicted[m_trackStatesSize] = addParam();
164  }
165 
166  m_trackStatesAux->filtered[m_trackStatesSize] = kInvalid;
167  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
168  m_trackStatesAux->filtered[m_trackStatesSize] = addParam();
169  }
170 
171  m_trackStatesAux->smoothed[m_trackStatesSize] = kInvalid;
172  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
173  m_trackStatesAux->smoothed[m_trackStatesSize] = addParam();
174  }
175 
176  m_trackStatesAux->jacobian[m_trackStatesSize] = kInvalid;
177  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
178  m_trackStatesAux->jacobian[m_trackStatesSize] = addJacobian();
179  }
180 
181  m_uncalibratedSourceLinks.emplace_back(std::nullopt);
182  m_trackStatesAux->calibrated[m_trackStatesSize] = kInvalid;
183  m_trackStatesAux->measDim[m_trackStatesSize] = 0;
184  // @TODO uncalibrated ?
185  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
186  m_trackStatesAux->calibrated[m_trackStatesSize] = addMeasurement();
187  m_calibratedSourceLinks.emplace_back(std::nullopt);
188  m_trackStatesAux->measDim[m_trackStatesSize] = m_trackMeasurementsAux->meas[m_trackStatesAux->calibrated[m_trackStatesSize]].size();
189  }
190 
191  m_trackStatesAux->geometryId[m_trackStatesSize] = InvalidGeoID; // surface is invalid until set
192  m_trackStatesSize++;
193  return m_trackStatesSize-1;
194 }
195 
196 
198  ActsTrk::IndexType istate,
199  Acts::TrackStatePropMask mask) {
200  using namespace Acts::HashedStringLiteral;
201  INSPECTCALL( this << " " << mask << " " << m_trackStatesAux->size() << " " << previous);
202 
203  assert(m_trackStatesAux && "Missing Track States backend");
204  constexpr size_t NDim = 6; // TODO take this from somewhere
205 
206  // set kInvalid
207  using Acts::MultiTrajectoryTraits::kInvalid;
208 
209  using namespace Acts;
210 
211  auto addParam = [this]() -> ActsTrk::IndexType {
212  stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
213  // TODO ask AK if this resize could be method of aux container
214  m_trackParametersAux->params[m_trackParametersSize].resize(NDim);
215  m_trackParametersAux->covMatrix[m_trackParametersSize].resize(NDim*NDim);
216  m_trackParametersSize++;
217  return m_trackParametersSize-1;
218  };
219 
220  auto addJacobian = [this]() -> ActsTrk::IndexType {
221  stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
222  m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(NDim*NDim);
223  m_trackJacobiansSize++;
224  return m_trackJacobiansSize-1;
225  };
226 
227  auto addMeasurement = [this]() -> ActsTrk::IndexType {
228  stepResize(m_trackMeasurementsAux.get(), m_trackMeasurementsSize );
229  m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(NDim);
230  m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(NDim*NDim);
231  m_trackMeasurementsSize++;
232  return m_trackMeasurementsSize-1;
233  };
234 
235  if ((m_trackStatesAux->predicted[istate] == kInvalid) &&
236  ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
237  m_trackStatesAux->predicted[istate] = addParam();
238  }
239 
240  if ((m_trackStatesAux->filtered[istate] == kInvalid) &&
241  ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
242  m_trackStatesAux->filtered[istate] = addParam();
243  }
244 
245  if ((m_trackStatesAux->smoothed[istate] == kInvalid) &&
246  ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
247  m_trackStatesAux->smoothed[istate] = addParam();
248  }
249 
250  if ((m_trackStatesAux->jacobian[istate] == kInvalid) &&
251  ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
252  m_trackStatesAux->jacobian[istate] = addJacobian();
253  }
254 
255  if ((m_trackStatesAux->calibrated[istate] == kInvalid) &&
256  ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
257  m_trackStatesAux->calibrated[istate] = addMeasurement();
258  m_calibratedSourceLinks.emplace_back(std::nullopt);
259  m_trackStatesAux->measDim[istate] = m_trackMeasurementsAux->meas[m_trackStatesAux->calibrated[istate]].size();
260  }
261 }
262 
263 
265  ActsTrk::IndexType iself,
266  ActsTrk::IndexType iother,
267  Acts::TrackStatePropMask shareSource,
268  Acts::TrackStatePropMask shareTarget) {
269 
270  assert(ACTS_CHECK_BIT(this->getTrackState(iother).getMask(), shareSource) &&
271  "Source has incompatible allocation");
272 
273  using PM = Acts::TrackStatePropMask;
274  // set kInvalid
275  using Acts::MultiTrajectoryTraits::kInvalid;
276 
277  ActsTrk::IndexType sourceIndex{kInvalid};
278  switch (shareSource) {
279  case PM::Predicted:
280  sourceIndex = m_trackStatesAux->predicted[iother];
281  break;
282  case PM::Filtered:
283  sourceIndex = m_trackStatesAux->filtered[iother];
284  break;
285  case PM::Smoothed:
286  sourceIndex = m_trackStatesAux->smoothed[iother];
287  break;
288  case PM::Jacobian:
289  sourceIndex = m_trackStatesAux->jacobian[iother];
290  break;
291  default:
292  throw std::domain_error{"MutableMultiTrajectory Unable to share this component"};
293  }
294 
295  assert(sourceIndex != kInvalid);
296 
297  switch (shareTarget) {
298  case PM::Predicted:
299  assert(shareSource != PM::Jacobian);
300  m_trackStatesAux->predicted[iself] = sourceIndex;
301  break;
302  case PM::Filtered:
303  assert(shareSource != PM::Jacobian);
304  m_trackStatesAux->filtered[iself] = sourceIndex;
305  break;
306  case PM::Smoothed:
307  assert(shareSource != PM::Jacobian);
308  m_trackStatesAux->smoothed[iself] = sourceIndex;
309  break;
310  case PM::Jacobian:
311  assert(shareSource == PM::Jacobian);
312  m_trackStatesAux->jacobian[iself] = sourceIndex;
313  break;
314  default:
315  throw std::domain_error{"MutableMultiTrajectory Unable to share this component"};
316  }
317 }
318 
319 
321  Acts::TrackStatePropMask target,
322  ActsTrk::IndexType istate) {
323 
324  using PM = Acts::TrackStatePropMask;
325  // set kInvalid
326  using Acts::MultiTrajectoryTraits::kInvalid;
327 
328  switch (target) {
329  case PM::Predicted:
330  m_trackStatesAux->predicted[istate] = kInvalid;
331  break;
332  case PM::Filtered:
333  m_trackStatesAux->filtered[istate] = kInvalid;
334 
335  break;
336  case PM::Smoothed:
337  m_trackStatesAux->smoothed[istate] = kInvalid;
338  break;
339  case PM::Jacobian:
340  m_trackStatesAux->jacobian[istate] = kInvalid;
341 
342  break;
343  case PM::Calibrated:
344  m_trackStatesAux->calibrated[istate] = kInvalid;
345  // TODO here m_measOffset[istate] and m_measCovOffset[istate] should be
346  // set to kInvalid
347 
348  break;
349  default:
350  throw std::domain_error{"MutableMultiTrajectory Unable to unset this component"};
351  }
352 }
353 
355  Acts::HashedString key, ActsTrk::IndexType istate) {
356  using namespace Acts::HashedStringLiteral;
357  assert(istate < m_trackStatesAux->size() &&
358  "Attempt to reach beyond the Track States container size");
359  INSPECTCALL(key << " " << istate << " non-const component_impl")
360 
361  switch (key) {
362  case "previous"_hash:
363  return &(m_trackStatesAux->previous[istate]);
364  case "next"_hash:
365  return &(m_trackStatesAux->next[istate]);
366  case "chi2"_hash:
367  return &(m_trackStatesAux->chi2[istate]);
368  case "pathLength"_hash:
369  return &(m_trackStatesAux->pathLength[istate]);
370  case "predicted"_hash:
371  return &(m_trackStatesAux->predicted[istate]);
372  case "filtered"_hash:
373  return &(m_trackStatesAux->filtered[istate]);
374  case "smoothed"_hash:
375  return &(m_trackStatesAux->smoothed[istate]);
376  case "projector"_hash: {
377  auto idx = m_trackStatesAux->calibrated[istate];
378  return &(m_trackMeasurementsAux->projector[idx]);
379  }
380  case "measdim"_hash:
381  return &(m_trackStatesAux->measDim[istate]);
382  case "typeFlags"_hash:
383  return &(m_trackStatesAux->typeFlags[istate]);
384 
385  default: {
386  for (auto& d : m_decorations) {
387  if (d.hash == key) {
388  return d.setter(m_trackStatesAux.get(), istate, d.auxid);
389  }
390  }
391  throw std::runtime_error("MutableMultiTrajectory::component_impl no such component " + std::to_string(key));
392  }
393  }
394 }
395 
396 
398  Acts::HashedString key,
399  ActsTrk::IndexType istate) const {
400  using namespace Acts::HashedStringLiteral;
401  assert(istate < m_trackStatesAux->size() &&
402  "Attempt to reach beyond the Track States container size");
403  INSPECTCALL(key << " " << istate << " const component_impl")
404  switch (key) {
405  case "previous"_hash:
406  return &(to_const_ptr(m_trackStatesAux)->previous[istate]);
407  case "next"_hash:
408  return &(to_const_ptr(m_trackStatesAux)->next[istate]);
409  case "chi2"_hash:
410  return &(to_const_ptr(m_trackStatesAux)->chi2[istate]);
411  case "pathLength"_hash:
412  return &(to_const_ptr(m_trackStatesAux)->pathLength[istate]);
413  case "predicted"_hash:
414  return &(to_const_ptr(m_trackStatesAux)->predicted[istate]);
415  case "filtered"_hash:
416  return &(to_const_ptr(m_trackStatesAux)->filtered[istate]);
417  case "smoothed"_hash:
418  return &(to_const_ptr(m_trackStatesAux)->smoothed[istate]);
419  case "jacobian"_hash:
420  return &(to_const_ptr(m_trackStatesAux)->jacobian[istate]);
421  case "projector"_hash:{
422  auto idx = to_const_ptr(m_trackStatesAux)->calibrated[istate];
423  return &(to_const_ptr(m_trackMeasurementsAux)->projector[idx]);
424  }
425  case "calibrated"_hash: {
426  return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
427  }
428  case "calibratedCov"_hash: {
429  return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
430  }
431  case "measdim"_hash:
432  return &(to_const_ptr(m_trackStatesAux)->measDim[istate]);
433  case "typeFlags"_hash:
434  return &(to_const_ptr(m_trackStatesAux)->typeFlags[istate]);
435  default: {
436  for (auto& d : m_decorations) {
437  if (d.hash == key) {
438  INSPECTCALL("getting dynamic variable " << d.name << " " << istate);
439  return d.getter(m_trackStatesAux.get(), istate, d.auxid);
440  }
441  }
442  throw std::runtime_error("MutableMultiTrajectory::component_impl const no such component " + std::to_string(key));
443  }
444  }
445 }
446 
448  Acts::HashedString key, ActsTrk::IndexType istate) const {
449  std::optional<bool> inTrackState =
450  ActsTrk::details::has_impl(m_trackStatesAux.get(), key, istate);
451  if (inTrackState.has_value())
452  return inTrackState.value();
453 
454  // TODO remove once EL based source links are in use only
455  using namespace Acts::HashedStringLiteral;
456  if (key == "uncalibratedSourceLink"_hash){
457  INSPECTCALL(key << " " << istate << " uncalibratedSourceLink")
458  static const SG::Accessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
459  bool has_auxid= m_trackStatesAux->getAuxIDs().test(acc.auxid());
460  if (has_auxid) {
461  return getElement(*m_trackStatesAux, acc, istate) != nullptr;
462  }
463  else {
464  return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
465  }
466  }
467 
468  for (auto& d : m_decorations) {
469  if (d.hash == key) {
470  INSPECTCALL(key << " " << istate << " d.name")
471  return true;
472  }
473  }
474 
475  return false;
476 }
477 
479  INSPECTCALL(this);
480  m_trackStatesAux->resize(0);
481  m_trackStatesSize = 0;
482 
483  m_trackParametersAux->resize(0);
484  m_trackParametersSize = 0;
485 
486  m_trackJacobiansAux->resize(0);
487  m_trackJacobiansSize = 0;
488 
489  m_trackMeasurementsAux->resize(0);
490  m_trackMeasurementsSize = 0;
491 
492  m_surfacesBackend->clear();
493  m_surfaces.clear();
494  m_calibratedSourceLinks.clear();
495  m_uncalibratedSourceLinks.clear();
496 }
497 
498 
500  // Retrieve the calibrated measurement size
501  // INSPECTCALL(istate << " " << trackMeasurements().size());
502  return m_trackStatesAux->measDim[istate];
503 }
504 
505 
507  const Acts::SourceLink& sourceLink) {
508  INSPECTCALL( istate );
509 
510  static const SG::Decorator<const xAOD::UncalibratedMeasurement*> decor{"uncalibratedMeasurement"};
511  if (istate>= m_trackStatesAux->size()) {
512  throw std::range_error("istate out of range on TrackStates when attempting to access uncalibrated measurements");
513  }
514  std::span<const xAOD::UncalibratedMeasurement*> uncalibratedMeasurements = createDecoration(*m_trackStatesAux, decor);
515 
516  // @TODO normally the source links should contain an xAOD::UncalibratedMeasurement pointer
517  // but in some cases some other payload is used e.g. when converting Trk::Tracks.
518  // Only UncalibratedMeasurement pointer can be stored in the xAOD backend. Everything
519  // else has to go into the cache.
520  // Currently there is no possibility to check whether the source link contains a certain payload
521  // so can only catch the bad any cast
522  try {
523  uncalibratedMeasurements[istate] = sourceLink.get<ATLASUncalibSourceLink>();
524  }
525  catch (std::bad_any_cast &err) {
526  assert( istate < m_uncalibratedSourceLinks.size());
527  m_uncalibratedSourceLinks[istate] = sourceLink;
528  }
529 }
530 
532  std::shared_ptr<const Acts::Surface> surface) {
533  if ( istate >= m_surfaces.size() )
534  m_surfaces.resize(istate+1, nullptr);
535 
536  m_trackStatesAux->geometryId[istate] = surface->geometryId().value();
537  if (surface->geometryId().value() == 0) { // free surface, needs recording of properties
538  m_surfacesBackend->push_back(new xAOD::TrackSurface());
539  encodeSurface(m_surfacesBackendAux.get(), m_surfacesBackendAux->size()-1, surface.get(), m_geoContext.context());
540  m_trackStatesAux->surfaceIndex[istate] = m_surfacesBackend->size()-1;
541  m_surfaces[istate] = std::move(surface); // and memory management
542 
543  } else {
544  m_surfaces[istate] = surface.get(); // no memory management, bare pointer
545  }
546  // store surface representation in
547 }
548 
549 namespace {
550  const Acts::Surface* toSurfacePtr(const ActsTrk::StoredSurface& surfaceVariant) {
551  if ( std::holds_alternative<const Acts::Surface*>(surfaceVariant))
552  return std::get<const Acts::Surface*>(surfaceVariant);
553  return std::get<std::shared_ptr<const Acts::Surface>>(surfaceVariant).get();
554  }
555 }
556 
558  if ( istate >= m_surfaces.size() ) throw std::out_of_range("MutableMultiTrajectory index " + std::to_string(istate) + " out of range " + std::to_string(m_surfaces.size()) + " when accessing reference surface");
559  return toSurfacePtr(m_surfaces[istate]);
560 }
561 
563  m_trackStatesAux->resize(m_trackStatesSize);
564  static const SG::Decorator<const xAOD::UncalibratedMeasurement*> decor{"uncalibratedMeasurement"};
565  std::span<const xAOD::UncalibratedMeasurement*> uncalibratedMeasurements = createDecoration(*m_trackStatesAux, decor);
566  (void) uncalibratedMeasurements;
567  m_trackMeasurementsAux->resize(m_trackMeasurementsSize);
568  m_trackJacobiansAux->resize(m_trackJacobiansSize);
569  m_trackParametersAux->resize(m_trackParametersSize);
570 }
571 
573 // ReadOnly MTJ
580  : m_trackStatesAux(trackStates),
581  m_trackParametersAux(trackParameters),
582  m_trackJacobiansAux(trackJacobians),
583  m_trackMeasurementsAux(trackMeasurements),
584  m_trackSurfacesAux(trackSurfaces) {
585  INSPECTCALL("ctor " << this << " " << m_trackStatesAux->size());
587 }
588 
589 bool ActsTrk::MultiTrajectory::has_impl(Acts::HashedString key,
590  ActsTrk::IndexType istate) const {
591  // const auto& trackStates = *m_trackStates;
592  std::optional<bool> inTrackState =
593  ActsTrk::details::has_impl(m_trackStatesAux, key, istate);
594  if (inTrackState.has_value())
595  return inTrackState.value();
596  // TODO remove once EL based source links are in use only
597  using namespace Acts::HashedStringLiteral;
598  if (key == "uncalibratedSourceLink"_hash) {
599  static const SG::Accessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
600  bool has_auxid= m_trackStatesAux->getAuxIDs().test(acc.auxid());
601  if (has_auxid) {
602  return getElement( *m_trackStatesAux, acc, istate) != nullptr;
603  }
604  else {
605  return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
606  }
607  }
608  return false;
609 }
610 
612  Acts::HashedString key, ActsTrk::IndexType istate) const {
613  using namespace Acts::HashedStringLiteral;
614  switch (key) {
615  case "previous"_hash:
616  return &(m_trackStatesAux->previous[istate]);
617  case "next"_hash:
618  return &(m_trackStatesAux->next[istate]);
619  case "chi2"_hash:
620  return &(m_trackStatesAux->chi2[istate]);
621  case "pathLength"_hash:
622  return &(m_trackStatesAux->pathLength[istate]);
623  case "predicted"_hash:
624  return &(m_trackStatesAux->predicted[istate]);
625  case "filtered"_hash:
626  return &(m_trackStatesAux->filtered[istate]);
627  case "smoothed"_hash:
628  return &(m_trackStatesAux->smoothed[istate]);
629  case "jacobian"_hash:
630  return &(m_trackStatesAux->jacobian[istate]);
631  case "projector"_hash: {
632  return &(m_trackMeasurementsAux->projector.at(m_trackStatesAux->calibrated[istate]));
633  }
634  case "calibrated"_hash: {
635  return &(m_trackStatesAux->calibrated[istate]);
636  }
637  case "calibratedCov"_hash: {
638  return &(m_trackStatesAux->calibrated[istate]);
639  }
640  case "measdim"_hash:
641  return &(m_trackStatesAux->measDim[istate]);
642  case "typeFlags"_hash:
643  return &(m_trackStatesAux->typeFlags[istate]);
644  default: {
645  for (auto& d : m_decorations) {
646  if (d.hash == key) {
647  // TODO the dynamic_cast will disappear
648  return d.getter(m_trackStatesAux.cptr(), istate, d.auxid);
649  }
650  }
651  throw std::runtime_error("MultiTrajectory::component_impl no such component " + std::to_string(key));
652  }
653  }
654 }
655 
657  Acts::HashedString key) const {
658  using namespace Acts::HashedStringLiteral;
659  // TODO try using staticVariables set
660  switch (key) {
661  case "previous"_hash:
662  case "next"_hash:
663  case "chi2"_hash:
664  case "pathLength"_hash:
665  case "predicted"_hash:
666  case "filtered"_hash:
667  case "smoothed"_hash:
668  case "jacobian"_hash:
669  case "projector"_hash:
670  case "uncalibratedSourceLink"_hash:
671  case "calibrated"_hash:
672  case "calibratedCov"_hash:
673  case "measdim"_hash:
674  case "typeFlags"_hash:
675  return true;
676  }
677  for (auto& d : m_decorations) {
678  if (d.hash == key) {
679  return true;
680  }
681  }
682  return false;
683 }
684 
687  return m_trackStatesAux->measDim[istate];
688 }
689 
691  m_surfaces = std::move(mtj->m_surfaces);
692 }
693 
694 // TODO remove this implementation once tracking uses only sourceLinks with EL
696  m_calibratedSourceLinks = std::move(mtj->m_calibratedSourceLinks);
697  m_uncalibratedSourceLinks = std::move(mtj->m_uncalibratedSourceLinks);
698 }
699 
700 void ActsTrk::MultiTrajectory::fillSurfaces(const Acts::TrackingGeometry* geo, const Acts::GeometryContext& geoContext ) {
701  if ( not m_surfaces.empty() )
702  return;
703  m_surfaces.resize(m_trackStatesAux->size(), nullptr);
704  for ( IndexType i = 0; i < m_trackStatesAux->size(); i++ ) {
705  auto geoID = m_trackStatesAux->geometryId[i];
706  if ( geoID == InvalidGeoID ) {
707  m_surfaces[i] = nullptr;
708  continue;
709  }
710  if ( geoID != 0 ) {
711  m_surfaces[i] = geo->findSurface(geoID);
712  } else {
713  unsigned int backendIndex = m_trackStatesAux->surfaceIndex[i];
714  std::shared_ptr<const Acts::Surface> surface = decodeSurface( m_trackSurfacesAux, backendIndex, geoContext);
715  m_surfaces[i] = surface; // TODO
716 
717  }
718  }
719 }
720 
721 
722 const Acts::Surface* ActsTrk::MultiTrajectory::referenceSurface_impl(IndexType istate) const {
723  INSPECTCALL( this << " " << istate << " " << m_trackStatesAux->size() << " " << m_surfaces.size() << " surf ptr " << toSurfacePtr(m_surfaces[istate]));
724  if ( istate >= m_surfaces.size() ) throw std::out_of_range("MultiTrajectory index " + std::to_string(istate) + " out of range " + std::to_string(m_surfaces.size()) + " when accessing reference surface");
725  return toSurfacePtr(m_surfaces[istate]);
726 }
727 
728 typename Acts::SourceLink
730  ActsTrk::IndexType istate) const {
731  assert(istate < m_trackStatesAux->size());
732  // at the moment when converting Trk::Track to Acts tracks the measurements on track
733  // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
734  // just contain a pointer to the Trk::Measurement. To keep this functionality
735  // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
736  // or taken from the xAOD backend.
737  static const SG::Accessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
738  if (m_trackStatesAux->getAuxIDs().test(acc.auxid())){
739  return Acts::SourceLink( getElement(*m_trackStatesAux, acc, istate) );
740  }
741  else {
742  return m_uncalibratedSourceLinks[istate].value();
743  }
744 }
745 
746 typename Acts::SourceLink
748  ActsTrk::IndexType istate) const {
749  assert(istate < m_trackStatesAux->size());
750  // at the moment when converting Trk::Track to Acts tracks the measurements on track
751  // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
752  // just contain a pointer to the Trk::Measurement. To keep this functionality
753  // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
754  // or taken from the xAOD backend.
755  static const SG::Accessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
756  if (m_trackStatesAux->getAuxIDs().test(acc.auxid())){
757  return Acts::SourceLink( getElement(*m_trackStatesAux, acc, istate) );
758  }
759  else {
760  return m_uncalibratedSourceLinks[istate].value();
761  }
762 }
ActsTrk::MultiTrajectory::has_impl
bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
Definition: MultiTrajectory.cxx:589
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
fitman.sz
sz
Definition: fitman.py:527
ActsTrk::MutableMultiTrajectory::m_surfaces
std::vector< StoredSurface > m_surfaces
Definition: MultiTrajectory.h:401
ActsTrk::MutableMultiTrajectory::component_impl
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
Access component by key.
Definition: MultiTrajectory.cxx:397
ActsTrk::MutableMultiTrajectory::setUncalibratedSourceLink_impl
void setUncalibratedSourceLink_impl(ActsTrk::IndexType istate, const Acts::SourceLink &sourceLink)
Implementation of uncalibrated link insertion.
Definition: MultiTrajectory.cxx:506
ActsTrk::StoredSurface
std::variant< const Acts::Surface *, std::shared_ptr< const Acts::Surface > > StoredSurface
Definition: MultiTrajectory.h:69
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
ActsTrk::MutableMultiTrajectory::m_decorations
std::vector< ActsTrk::detail::Decoration > m_decorations
Definition: MultiTrajectory.h:396
index
Definition: index.py:1
hist_file_dump.d
d
Definition: hist_file_dump.py:137
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
TrackState.h
AuxContainerBase.h
ActsTrk::MutableMultiTrajectory::referenceSurface_impl
const Acts::Surface * referenceSurface_impl(IndexType) const
Definition: MultiTrajectory.cxx:557
xAOD::AuxContainerBase
Common base class for the auxiliary containers.
Definition: AuxContainerBase.h:59
ActsTrk::MutableMultiTrajectory::m_trackParametersAux
std::unique_ptr< xAOD::TrackParametersAuxContainer > m_trackParametersAux
Definition: MultiTrajectory.h:385
ActsTrk::MultiTrajectory::component_impl
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
Definition: MultiTrajectory.cxx:611
xAOD::TrackSurfaceContainer
TrackSurfaceContainer_v1 TrackSurfaceContainer
Definition: TrackSurfaceContainer.h:11
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
TrackParameters.h
SG::ConstAccessor< T >
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
ActsTrk::MutableMultiTrajectory::addTrackState_impl
ActsTrk::IndexType addTrackState_impl(Acts::TrackStatePropMask mask, ActsTrk::IndexType iprevious)
Add state with stograge for data that depends on the mask.
Definition: MultiTrajectory.cxx:119
SG::Decorator::auxid
SG::auxid_t auxid() const
Return the aux id for this variable.
ActsTrk::MultiTrajectory::hasColumn_impl
bool hasColumn_impl(Acts::HashedString key) const
Definition: MultiTrajectory.cxx:656
to_const_ptr
const T * to_const_ptr(const std::unique_ptr< T > &ptr)
Definition: MultiTrajectory.cxx:69
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
ActsTrk::MutableMultiTrajectory::has_backends
bool has_backends() const
checks if the backends are connected (i.e.
Definition: MultiTrajectory.cxx:106
ActsTrk::MutableMultiTrajectory::m_calibratedSourceLinks
std::vector< std::optional< Acts::SourceLink > > m_calibratedSourceLinks
Definition: MultiTrajectory.h:398
ActsTrk::MutableMultiTrajectory
Athena implementation of ACTS::MultiTrajectory (ReadWrite version) The data is stored in 4 external b...
Definition: MultiTrajectory.h:81
ActsTrk::MutableMultiTrajectory::has_impl
bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
checks if given state has requested component
Definition: MultiTrajectory.cxx:447
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::AuxContainerBase::size
virtual size_t size() const override
Get the size of the container.
Definition: AuxContainerBase.cxx:430
InvalidGeoID
constexpr uint64_t InvalidGeoID
Definition: MultiTrajectory.cxx:12
ActsTrk::MutableMultiTrajectory::m_trackMeasurementsAux
std::unique_ptr< xAOD::TrackMeasurementAuxContainer > m_trackMeasurementsAux
Definition: MultiTrajectory.h:391
ActsTrk::MutableMultiTrajectory::s_staticVariables
static const std::set< std::string > s_staticVariables
Definition: MultiTrajectory.h:376
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::MultiTrajectory::MultiTrajectory
MultiTrajectory(DataLink< xAOD::TrackStateAuxContainer > trackStates, DataLink< xAOD::TrackParametersAuxContainer > trackParameters, DataLink< xAOD::TrackJacobianAuxContainer > trackJacobians, DataLink< xAOD::TrackMeasurementAuxContainer > trackMeasurements, DataLink< xAOD::TrackSurfaceAuxContainer > trackSurfaces)
Definition: MultiTrajectory.cxx:574
ActsTrk::MultiTrajectory::calibratedSize_impl
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
Definition: MultiTrajectory.cxx:686
ActsTrk::IndexType
std::uint32_t IndexType
Definition: Decoration.h:14
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
xAOD::TrackMeasurementAuxContainer
TrackMeasurementAuxContainer_v1 TrackMeasurementAuxContainer
Definition: TrackMeasurementAuxContainer.h:10
ActsTrk::MultiTrajectory::referenceSurface_impl
const Acts::Surface * referenceSurface_impl(IndexType) const
Definition: MultiTrajectory.cxx:722
SG::Decorator< T >
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
Acts
Definition: ChamberAssembleTool.h:18
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::TrackSurface_v1
TrackSurface for Acts MultiTrajectory and TrackSummary.
Definition: TrackSurface_v1.h:22
ActsTrk::MutableMultiTrajectory::m_uncalibratedSourceLinks
std::vector< std::optional< Acts::SourceLink > > m_uncalibratedSourceLinks
Definition: MultiTrajectory.h:399
SurfaceEncoding.h
ActsTrk::MutableMultiTrajectory::addTrackStateComponents_impl
void addTrackStateComponents_impl(ActsTrk::IndexType istate, Acts::TrackStatePropMask mask)
Add state components for the given mask.
Definition: MultiTrajectory.cxx:197
ActsTrk::MutableMultiTrajectory::m_surfacesBackendAux
std::unique_ptr< xAOD::TrackSurfaceAuxContainer > m_surfacesBackendAux
Definition: MultiTrajectory.h:395
INSPECTCALL
#define INSPECTCALL(_INFO)
Definition: MultiTrajectory.h:35
xAOD::TrackParametersAuxContainer
TrackParametersAuxContainer_v1 TrackParametersAuxContainer
Definition: TrackParametersAuxContainer.h:11
ActsTrk::MutableMultiTrajectory::shareFrom_impl
void shareFrom_impl(ActsTrk::IndexType iself, ActsTrk::IndexType iother, Acts::TrackStatePropMask shareSource, Acts::TrackStatePropMask shareTarget)
shares from a given state
Definition: MultiTrajectory.cxx:264
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
ActsTrk::MutableMultiTrajectory::trim
void trim()
Definition: MultiTrajectory.cxx:562
ActsTrk::MultiTrajectory::m_decorations
std::vector< ActsTrk::detail::Decoration > m_decorations
Definition: MultiTrajectory.h:489
xAOD::AuxContainerBase::getDecoration
virtual void * getDecoration(auxid_t auxid, size_t size, size_t capacity) override
Get a pointer to a given array, as a decoration.
Definition: AuxContainerBase.cxx:300
ActsTrk::MutableMultiTrajectory::getUncalibratedSourceLink_impl
Acts::SourceLink getUncalibratedSourceLink_impl(ActsTrk::IndexType istate) const
Implementation of uncalibrated link fetch.
Definition: MultiTrajectory.cxx:729
ActsTrk::MultiTrajectory::m_trackStatesAux
const DataLink< xAOD::TrackStateAuxContainer > m_trackStatesAux
Definition: MultiTrajectory.h:484
ActsTrk::MutableMultiTrajectory::MutableMultiTrajectory
MutableMultiTrajectory()
Construct a new Multi Trajectory object owning backends.
Definition: MultiTrajectory.cxx:73
ActsTrk::MultiTrajectory::moveLinks
void moveLinks(const ActsTrk::MutableMultiTrajectory *mtj)
Definition: MultiTrajectory.cxx:695
ActsTrk::detail::restoreDecorations
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
Definition: Decoration.cxx:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
ActsTrk::MultiTrajectory::getUncalibratedSourceLink_impl
Acts::SourceLink getUncalibratedSourceLink_impl(ActsTrk::IndexType istate) const
Definition: MultiTrajectory.cxx:747
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
xAOD::AuxContainerBase::getData
virtual const void * getData(auxid_t auxid) const override
Get a pointer to a given array.
Definition: AuxContainerBase.cxx:230
TrackMeasurementAuxContainer.h
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
ActsTrk::MutableMultiTrajectory::m_trackStatesAux
std::unique_ptr< xAOD::TrackStateAuxContainer > m_trackStatesAux
Definition: MultiTrajectory.h:382
MultiTrajectory.h
ActsTrk::MultiTrajectory::fillSurfaces
void fillSurfaces(const Acts::TrackingGeometry *geo, const Acts::GeometryContext &geoContext)
Fill surfaces either from persistency or from geometry If the surfaces are already there it means tha...
Definition: MultiTrajectory.cxx:700
ActsTrk::MutableMultiTrajectory::m_surfacesBackend
std::unique_ptr< xAOD::TrackSurfaceContainer > m_surfacesBackend
Definition: MultiTrajectory.h:394
DeMoScan.index
string index
Definition: DeMoScan.py:364
xAOD::TrackStateAuxContainer
TrackStateAuxContainer_v1 TrackStateAuxContainer
Definition: TrackStateAuxContainer.h:11
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
ActsTrk::MutableMultiTrajectory::calibratedSize_impl
void allocateCalibrated_impl(IndexType istate, const Eigen::DenseBase< val_t > &val, const Eigen::DenseBase< cov_t > &cov) requires(Eigen ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
Implementation of allocation of calibrated measurements.
Definition: MultiTrajectory.h:323
LArCellConditions.geo
bool geo
Definition: LArCellConditions.py:46
copySelective.target
string target
Definition: copySelective.py:37
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
ActsTrk::MutableMultiTrajectory::m_geoContext
ActsGeometryContext m_geoContext
Definition: MultiTrajectory.h:402
ActsTrk::MutableMultiTrajectory::m_trackJacobiansAux
std::unique_ptr< xAOD::TrackJacobianAuxContainer > m_trackJacobiansAux
Definition: MultiTrajectory.h:388
ActsTrk::MutableMultiTrajectory::setReferenceSurface_impl
void setReferenceSurface_impl(IndexType, std::shared_ptr< const Acts::Surface >)
Definition: MultiTrajectory.cxx:531
ActsTrk::MultiTrajectory::moveSurfaces
void moveSurfaces(const ActsTrk::MutableMultiTrajectory *mtj)
reuse surfaces from MutableMultiTrajectory
Definition: MultiTrajectory.cxx:690
xAOD::TrackSurfaceAuxContainer
TrackSurfaceAuxContainer_v1 TrackSurfaceAuxContainer
Definition: TrackSurfaceAuxContainer.h:10
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
ActsTrk::MutableMultiTrajectory::clear_impl
void clear_impl()
clears backends decoration columns are still declared
Definition: MultiTrajectory.cxx:478
xAOD::TrackJacobianAuxContainer
TrackJacobianAuxContainer_v1 TrackJacobianAuxContainer
Definition: TrackJacobianAuxContainer.h:10
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
TrackJacobian.h
Trk::previous
@ previous
Definition: BinningData.h:32
ActsTrk::MutableMultiTrajectory::unset_impl
void unset_impl(Acts::TrackStatePropMask target, ActsTrk::IndexType istate)
unsets a given state
Definition: MultiTrajectory.cxx:320
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37