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 "chi2"_hash:
408  return &(to_const_ptr(m_trackStatesAux)->chi2[istate]);
409  case "pathLength"_hash:
410  return &(to_const_ptr(m_trackStatesAux)->pathLength[istate]);
411  case "predicted"_hash:
412  return &(to_const_ptr(m_trackStatesAux)->predicted[istate]);
413  case "filtered"_hash:
414  return &(to_const_ptr(m_trackStatesAux)->filtered[istate]);
415  case "smoothed"_hash:
416  return &(to_const_ptr(m_trackStatesAux)->smoothed[istate]);
417  case "jacobian"_hash:
418  return &(to_const_ptr(m_trackStatesAux)->jacobian[istate]);
419  case "projector"_hash:{
420  auto idx = to_const_ptr(m_trackStatesAux)->calibrated[istate];
421  return &(to_const_ptr(m_trackMeasurementsAux)->projector[idx]);
422  }
423  case "calibrated"_hash: {
424  return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
425  }
426  case "calibratedCov"_hash: {
427  return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
428  }
429  case "measdim"_hash:
430  return &(to_const_ptr(m_trackStatesAux)->measDim[istate]);
431  case "typeFlags"_hash:
432  return &(to_const_ptr(m_trackStatesAux)->typeFlags[istate]);
433  default: {
434  for (auto& d : m_decorations) {
435  if (d.hash == key) {
436  INSPECTCALL("getting dymaic variable " << d.name << " " << istate);
437  return d.getter(m_trackStatesAux.get(), istate, d.auxid);
438  }
439  }
440  throw std::runtime_error("MutableMultiTrajectory::component_impl const no such component " + std::to_string(key));
441  }
442  }
443 }
444 
446  Acts::HashedString key, ActsTrk::IndexType istate) const {
447  std::optional<bool> inTrackState =
448  ActsTrk::details::has_impl(m_trackStatesAux.get(), key, istate);
449  if (inTrackState.has_value())
450  return inTrackState.value();
451 
452  // TODO remove once EL based source links are in use only
453  using namespace Acts::HashedStringLiteral;
454  if (key == "uncalibratedSourceLink"_hash){
455  INSPECTCALL(key << " " << istate << " uncalibratedSourceLink")
456  static const SG::Accessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
457  bool has_auxid= m_trackStatesAux->getAuxIDs().test(acc.auxid());
458  if (has_auxid) {
459  return getElement(*m_trackStatesAux, acc, istate) != nullptr;
460  }
461  else {
462  return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
463  }
464  }
465 
466  for (auto& d : m_decorations) {
467  if (d.hash == key) {
468  INSPECTCALL(key << " " << istate << " d.name")
469  return true;
470  }
471  }
472 
473  return false;
474 }
475 
477  INSPECTCALL(this);
478  m_trackStatesAux->resize(0);
479  m_trackStatesSize = 0;
480 
481  m_trackParametersAux->resize(0);
482  m_trackParametersSize = 0;
483 
484  m_trackJacobiansAux->resize(0);
485  m_trackJacobiansSize = 0;
486 
487  m_trackMeasurementsAux->resize(0);
488  m_trackMeasurementsSize = 0;
489 
490  m_surfacesBackend->clear();
491  m_surfaces.clear();
492  m_calibratedSourceLinks.clear();
493  m_uncalibratedSourceLinks.clear();
494 }
495 
496 
498  m_trackStatesAux->measDim[istate] = measdim;
499  auto idx = m_trackStatesAux->calibrated[istate];
500  m_trackMeasurementsAux->meas[idx].resize(measdim);
501  m_trackMeasurementsAux->covMatrix[idx].resize(measdim*measdim);
502 }
503 
504 
506  // Retrieve the calibrated measurement size
507  // INSPECTCALL(istate << " " << trackMeasurements().size());
508  return m_trackStatesAux->measDim[istate];
509 }
510 
511 
513  const Acts::SourceLink& sourceLink) {
514  INSPECTCALL( istate );
515 
516  static const SG::Decorator<const xAOD::UncalibratedMeasurement*> decor{"uncalibratedMeasurement"};
517  if (istate>= m_trackStatesAux->size()) {
518  throw std::range_error("istate out of range on TrackStates when attempting to acces uncalibrated measurements");
519  }
520  std::span<const xAOD::UncalibratedMeasurement*> uncalibratedMeasurements = createDecoration(*m_trackStatesAux, decor);
521 
522  // @TODO normally the source links should contain an xAOD::UncalibratedMeasurement pointer
523  // but in some cases some other payload is used e.g. when converting Trk::Tracks.
524  // Only UncalibratedMeasurement pointer can be stored in the xAOD backend. Everything
525  // else has to go into the cache.
526  // Currently there is no possibility to check whether the source link contains a certain payload
527  // so can only catch the bad any cast
528  try {
529  uncalibratedMeasurements[istate] = sourceLink.get<ATLASUncalibSourceLink>();
530  }
531  catch (std::bad_any_cast &err) {
532  assert( istate < m_uncalibratedSourceLinks.size());
533  m_uncalibratedSourceLinks[istate] = sourceLink;
534  }
535 }
536 
538  std::shared_ptr<const Acts::Surface> surface) {
539  if ( istate >= m_surfaces.size() )
540  m_surfaces.resize(istate+1, nullptr);
541 
542  m_trackStatesAux->geometryId[istate] = surface->geometryId().value();
543  if (surface->geometryId().value() == 0) { // free surface, needs recording of properties
544  m_surfacesBackend->push_back(new xAOD::TrackSurface());
545  encodeSurface(m_surfacesBackendAux.get(), m_surfacesBackendAux->size()-1, surface.get(), m_geoContext.context());
546  m_trackStatesAux->surfaceIndex[istate] = m_surfacesBackend->size()-1;
547  m_surfaces[istate] = std::move(surface); // and memory management
548 
549  } else {
550  m_surfaces[istate] = surface.get(); // no memory management, bare pointer
551  }
552  // store surface representation in
553 }
554 
555 namespace {
556  const Acts::Surface* toSurfacePtr(const ActsTrk::StoredSurface& surfaceVariant) {
557  if ( std::holds_alternative<const Acts::Surface*>(surfaceVariant))
558  return std::get<const Acts::Surface*>(surfaceVariant);
559  return std::get<std::shared_ptr<const Acts::Surface>>(surfaceVariant).get();
560  }
561 }
562 
564  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");
565  return toSurfacePtr(m_surfaces[istate]);
566 }
567 
569  m_trackStatesAux->resize(m_trackStatesSize);
570  static const SG::Decorator<const xAOD::UncalibratedMeasurement*> decor{"uncalibratedMeasurement"};
571  std::span<const xAOD::UncalibratedMeasurement*> uncalibratedMeasurements = createDecoration(*m_trackStatesAux, decor);
572  (void) uncalibratedMeasurements;
573  m_trackMeasurementsAux->resize(m_trackMeasurementsSize);
574  m_trackJacobiansAux->resize(m_trackJacobiansSize);
575  m_trackParametersAux->resize(m_trackParametersSize);
576 }
577 
579 // ReadOnly MTJ
586  : m_trackStatesAux(trackStates),
587  m_trackParametersAux(trackParameters),
588  m_trackJacobiansAux(trackJacobians),
589  m_trackMeasurementsAux(trackMeasurements),
590  m_trackSurfacesAux(trackSurfaces) {
591  INSPECTCALL("ctor " << this << " " << m_trackStatesAux->size());
593 }
594 
595 bool ActsTrk::MultiTrajectory::has_impl(Acts::HashedString key,
596  ActsTrk::IndexType istate) const {
597  // const auto& trackStates = *m_trackStates;
598  std::optional<bool> inTrackState =
599  ActsTrk::details::has_impl(m_trackStatesAux, key, istate);
600  if (inTrackState.has_value())
601  return inTrackState.value();
602  // TODO remove once EL based source links are in use only
603  using namespace Acts::HashedStringLiteral;
604  if (key == "uncalibratedSourceLink"_hash) {
605  static const SG::Accessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
606  bool has_auxid= m_trackStatesAux->getAuxIDs().test(acc.auxid());
607  if (has_auxid) {
608  return getElement( *m_trackStatesAux, acc, istate) != nullptr;
609  }
610  else {
611  return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
612  }
613  }
614  return false;
615 }
616 
618  Acts::HashedString key, ActsTrk::IndexType istate) const {
619  using namespace Acts::HashedStringLiteral;
620  switch (key) {
621  case "previous"_hash:
622  return &(m_trackStatesAux->previous[istate]);
623  case "chi2"_hash:
624  return &(m_trackStatesAux->chi2[istate]);
625  case "pathLength"_hash:
626  return &(m_trackStatesAux->pathLength[istate]);
627  case "predicted"_hash:
628  return &(m_trackStatesAux->predicted[istate]);
629  case "filtered"_hash:
630  return &(m_trackStatesAux->filtered[istate]);
631  case "smoothed"_hash:
632  return &(m_trackStatesAux->smoothed[istate]);
633  case "jacobian"_hash:
634  return &(m_trackStatesAux->jacobian[istate]);
635  case "projector"_hash: {
636  return &(m_trackMeasurementsAux->projector.at(m_trackStatesAux->calibrated[istate]));
637  }
638  case "calibrated"_hash: {
639  return &(m_trackStatesAux->calibrated[istate]);
640  }
641  case "calibratedCov"_hash: {
642  return &(m_trackStatesAux->calibrated[istate]);
643  }
644  case "measdim"_hash:
645  return &(m_trackStatesAux->measDim[istate]);
646  case "typeFlags"_hash:
647  return &(m_trackStatesAux->typeFlags[istate]);
648  default: {
649  for (auto& d : m_decorations) {
650  if (d.hash == key) {
651  // TODO the dynamic_cast will disappear
652  return d.getter(m_trackStatesAux.cptr(), istate, d.auxid);
653  }
654  }
655  throw std::runtime_error("MultiTrajectory::component_impl no such component " + std::to_string(key));
656  }
657  }
658 }
659 
661  Acts::HashedString key) const {
662  using namespace Acts::HashedStringLiteral;
663  // TODO try using staticVariables set
664  switch (key) {
665  case "previous"_hash:
666  case "chi2"_hash:
667  case "pathLength"_hash:
668  case "predicted"_hash:
669  case "filtered"_hash:
670  case "smoothed"_hash:
671  case "jacobian"_hash:
672  case "projector"_hash:
673  case "uncalibratedSourceLink"_hash:
674  case "calibrated"_hash:
675  case "calibratedCov"_hash:
676  case "measdim"_hash:
677  case "typeFlags"_hash:
678  return true;
679  }
680  for (auto& d : m_decorations) {
681  if (d.hash == key) {
682  return true;
683  }
684  }
685  return false;
686 }
687 
690  return m_trackStatesAux->measDim[istate];
691 }
692 
694  m_surfaces = std::move(mtj->m_surfaces);
695 }
696 
697 // TODO remove this implementation once tracking uses only sourceLinks with EL
699  m_calibratedSourceLinks = std::move(mtj->m_calibratedSourceLinks);
700  m_uncalibratedSourceLinks = std::move(mtj->m_uncalibratedSourceLinks);
701 }
702 
703 void ActsTrk::MultiTrajectory::fillSurfaces(const Acts::TrackingGeometry* geo, const Acts::GeometryContext& geoContext ) {
704  if ( not m_surfaces.empty() )
705  return;
706  m_surfaces.resize(m_trackStatesAux->size(), nullptr);
707  for ( IndexType i = 0; i < m_trackStatesAux->size(); i++ ) {
708  auto geoID = m_trackStatesAux->geometryId[i];
709  if ( geoID == InvalidGeoID ) {
710  m_surfaces[i] = nullptr;
711  continue;
712  }
713  if ( geoID != 0 ) {
714  m_surfaces[i] = geo->findSurface(geoID);
715  } else {
716  unsigned int backendIndex = m_trackStatesAux->surfaceIndex[i];
717  std::shared_ptr<const Acts::Surface> surface = decodeSurface( m_trackSurfacesAux, backendIndex, geoContext);
718  m_surfaces[i] = surface; // TODO
719 
720  }
721  }
722 }
723 
724 
725 const Acts::Surface* ActsTrk::MultiTrajectory::referenceSurface_impl(IndexType istate) const {
726  INSPECTCALL( this << " " << istate << " " << m_trackStatesAux->size() << " " << m_surfaces.size() << " surf ptr " << toSurfacePtr(m_surfaces[istate]));
727  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");
728  return toSurfacePtr(m_surfaces[istate]);
729 }
730 
731 typename Acts::SourceLink
733  ActsTrk::IndexType istate) const {
734  assert(istate < m_trackStatesAux->size());
735  // at the moment when converting Trk::Track to Acts tracks the measurements on track
736  // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
737  // just contain a pointer to the Trk::Measurement. To keep this functionality
738  // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
739  // or taken from the xAOD backend.
740  static const SG::Accessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
741  if (m_trackStatesAux->getAuxIDs().test(acc.auxid())){
742  return Acts::SourceLink( getElement(*m_trackStatesAux, acc, istate) );
743  }
744  else {
745  return m_uncalibratedSourceLinks[istate].value();
746  }
747 }
748 
749 typename Acts::SourceLink
751  ActsTrk::IndexType istate) const {
752  assert(istate < m_trackStatesAux->size());
753  // at the moment when converting Trk::Track to Acts tracks the measurements on track
754  // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
755  // just contain a pointer to the Trk::Measurement. To keep this functionality
756  // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
757  // or taken from the xAOD backend.
758  static const SG::Accessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
759  if (m_trackStatesAux->getAuxIDs().test(acc.auxid())){
760  return Acts::SourceLink( getElement(*m_trackStatesAux, acc, istate) );
761  }
762  else {
763  return m_uncalibratedSourceLinks[istate].value();
764  }
765 }
ActsTrk::MultiTrajectory::has_impl
bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
Definition: MultiTrajectory.cxx:595
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:392
ActsTrk::MutableMultiTrajectory::component_impl
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
Access component by key.
Definition: MultiTrajectory.cxx:397
max
#define max(a, b)
Definition: cfImp.cxx:41
ActsTrk::MutableMultiTrajectory::setUncalibratedSourceLink_impl
void setUncalibratedSourceLink_impl(ActsTrk::IndexType istate, const Acts::SourceLink &sourceLink)
Implementation of uncalibrated link insertion.
Definition: MultiTrajectory.cxx:512
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:387
index
Definition: index.py:1
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TrackState.h
AuxContainerBase.h
ActsTrk::MutableMultiTrajectory::referenceSurface_impl
const Acts::Surface * referenceSurface_impl(IndexType) const
Definition: MultiTrajectory.cxx:563
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:376
ActsTrk::MultiTrajectory::component_impl
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
Definition: MultiTrajectory.cxx:617
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:660
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:389
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:445
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:429
InvalidGeoID
constexpr uint64_t InvalidGeoID
Definition: MultiTrajectory.cxx:12
ActsTrk::MutableMultiTrajectory::m_trackMeasurementsAux
std::unique_ptr< xAOD::TrackMeasurementAuxContainer > m_trackMeasurementsAux
Definition: MultiTrajectory.h:382
ActsTrk::MutableMultiTrajectory::s_staticVariables
static const std::set< std::string > s_staticVariables
Definition: MultiTrajectory.h:367
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:580
ActsTrk::MultiTrajectory::calibratedSize_impl
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
Definition: MultiTrajectory.cxx:689
ActsTrk::IndexType
std::uint32_t IndexType
Definition: Decoration.h:13
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:725
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:390
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:386
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:568
ActsTrk::MutableMultiTrajectory::calibratedSize_impl
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
Implementation of calibrated size.
Definition: MultiTrajectory.cxx:505
ActsTrk::MultiTrajectory::m_decorations
std::vector< ActsTrk::detail::Decoration > m_decorations
Definition: MultiTrajectory.h:480
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:299
ActsTrk::MutableMultiTrajectory::getUncalibratedSourceLink_impl
Acts::SourceLink getUncalibratedSourceLink_impl(ActsTrk::IndexType istate) const
Implementation of uncalibrated link fetch.
Definition: MultiTrajectory.cxx:732
ActsTrk::MultiTrajectory::m_trackStatesAux
const DataLink< xAOD::TrackStateAuxContainer > m_trackStatesAux
Definition: MultiTrajectory.h:475
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:698
ActsTrk::detail::restoreDecorations
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
Definition: Decoration.cxx:9
ActsTrk::MutableMultiTrajectory::allocateCalibrated_impl
void allocateCalibrated_impl(ActsTrk::IndexType istate, std::size_t measdim)
Implementation of allocation of calibrated measurements.
Definition: MultiTrajectory.cxx:497
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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:750
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:229
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:373
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:703
ActsTrk::MutableMultiTrajectory::m_surfacesBackend
std::unique_ptr< xAOD::TrackSurfaceContainer > m_surfacesBackend
Definition: MultiTrajectory.h:385
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
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:393
ActsTrk::MutableMultiTrajectory::m_trackJacobiansAux
std::unique_ptr< xAOD::TrackJacobianAuxContainer > m_trackJacobiansAux
Definition: MultiTrajectory.h:379
ActsTrk::MutableMultiTrajectory::setReferenceSurface_impl
void setReferenceSurface_impl(IndexType, std::shared_ptr< const Acts::Surface >)
Definition: MultiTrajectory.cxx:537
ActsTrk::MultiTrajectory::moveSurfaces
void moveSurfaces(const ActsTrk::MutableMultiTrajectory *mtj)
reuse surfaces from MutableMultiTrajectory
Definition: MultiTrajectory.cxx:693
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:476
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