ATLAS Offline Software
Loading...
Searching...
No Matches
MultiTrajectory.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef ActsEvent_MultiTrajectory_h
5#define ActsEvent_MultiTrajectory_h
6#include <memory>
7#include <type_traits>
8#include <variant>
9#include <string_view>
10
11#include "Acts/EventData/MultiTrajectory.hpp"
12#include "Acts/EventData/SourceLink.hpp"
13#include "Acts/EventData/TrackStatePropMask.hpp"
14#include "Acts/EventData/VectorMultiTrajectory.hpp"
15#include "Acts/Utilities/HashedString.hpp"
16#include "Acts/Geometry/TrackingGeometry.hpp"
18#include "Acts/Surfaces/Surface.hpp"
19#include "CxxUtils/concepts.h"
27// #define DEBUG_MTJ
28#ifdef DEBUG_MTJ
29#define INSPECTCALL(_INFO) {std::cout << __FILE__ <<":"<<__LINE__<<" "<<__PRETTY_FUNCTION__<<" "<<_INFO<<std::endl; }
30#else
31#define INSPECTCALL(_INFO)
32#endif
34
35namespace ActsTrk {
36class MutableMultiTrajectory;
37class MultiTrajectory;
38class MutableTrackContainerHandlesHelper;
39} // namespace ActsTrk
40
41namespace Acts {
42class Surface;
43template <typename T>
45
46template <typename T>
48
49template <typename T>
51
52template <>
53struct IsReadOnlyMultiTrajectory<ActsTrk::MultiTrajectory>
54 : std::true_type {};
55
56template <>
57struct IsReadOnlyMultiTrajectory<ActsTrk::MutableMultiTrajectory>
58 : std::false_type {};
59} // namespace Acts
60
61namespace ActsTrk {
62
63using IndexType = std::uint32_t;
64
65using StoredSurface = std::variant<const Acts::Surface*, std::shared_ptr<const Acts::Surface>>;
66
67
77 : public Acts::MultiTrajectory<ActsTrk::MutableMultiTrajectory> {
78 public:
80 using TrackStateProxy = typename Acts::MultiTrajectory<
82 using ConstTrackStateProxy = typename Acts::MultiTrajectory<
84
92
100 ActsTrk::IndexType addTrackState_impl(Acts::TrackStatePropMask mask,
101 ActsTrk::IndexType iprevious);
102
110 Acts::TrackStatePropMask mask);
111
120
121 std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const;
122 std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate);
123
132 bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const;
133
141 constexpr bool hasColumn_impl(Acts::HashedString key) const;
142
149 template <typename T>
150 void addColumn_impl(std::string_view key);
151
158
159 void unset_impl(Acts::TrackStatePropMask target, ActsTrk::IndexType istate);
160
167
169 Acts::TrackStatePropMask shareSource,
170 Acts::TrackStatePropMask shareTarget);
171
178
179 typename ConstTrackStateProxy::ConstParameters parameters_impl(
181 return typename ConstTrackStateProxy::ConstParameters{m_trackParametersAux->params[index].data()};
182 }
183
184 typename TrackStateProxy::Parameters parameters_impl(ActsTrk::IndexType index) {
185 return typename TrackStateProxy::Parameters{m_trackParametersAux->params[index].data()};
186 }
187
194 typename ConstTrackStateProxy::ConstCovariance covariance_impl(
196 return typename ConstTrackStateProxy::ConstCovariance{m_trackParametersAux->covMatrix[index].data()};
197 }
198 typename TrackStateProxy::Covariance covariance_impl(ActsTrk::IndexType index) {
199 return typename TrackStateProxy::Covariance{m_trackParametersAux->covMatrix[index].data()};
200 }
201
208 typename ConstTrackStateProxy::Covariance trackMeasurementsCov(
210 return typename ConstTrackStateProxy::Covariance{m_trackMeasurementsAux->covMatrix[index].data()};
211
212 }
213
214 typename TrackStateProxy::Covariance trackMeasurementsCov(ActsTrk::IndexType index) {
215 return typename TrackStateProxy::Covariance{m_trackMeasurementsAux->covMatrix[index].data()};
216
217 }
218
225
226 inline typename ConstTrackStateProxy::ConstCovariance jacobian_impl(
227 ActsTrk::IndexType istate) const {
228 xAOD::TrackStateIndexType jacIdx = m_trackStatesAux->jacobian[istate];
229 return typename ConstTrackStateProxy::ConstCovariance{m_trackJacobiansAux->jac[jacIdx].data()};
230 }
231
232 typename TrackStateProxy::Covariance jacobian_impl(ActsTrk::IndexType istate) {
233 xAOD::TrackStateIndexType jacIdx = m_trackStatesAux->jacobian[istate];
234 return typename TrackStateProxy::Covariance{m_trackJacobiansAux->jac[jacIdx].data()};
235 }
236
243
244 template <std::size_t measdim>
245 inline typename ConstTrackStateProxy::template ConstCalibrated<measdim>
247 xAOD::TrackStateIndexType measIdx = m_trackStatesAux->calibrated[index];
248 return typename ConstTrackStateProxy::template ConstCalibrated<measdim>{m_trackMeasurementsAux->meas[measIdx].data()};
249 }
250
251 template <std::size_t measdim, bool Enable = true>
252 std::enable_if_t<Enable,
253 typename TrackStateProxy::template Calibrated<measdim>>
255 xAOD::TrackStateIndexType measIdx = m_trackStatesAux->calibrated[index];
256 return typename TrackStateProxy::template Calibrated<measdim>{m_trackMeasurementsAux->meas[measIdx].data()};
257 }
258
265
266 template <std::size_t measdim>
267 inline typename ConstTrackStateProxy::template ConstCalibratedCovariance<measdim>
269 xAOD::TrackStateIndexType measIdx = m_trackStatesAux->calibrated[index];
270 return ConstTrackStateProxy::template ConstCalibratedCovariance<measdim>{m_trackMeasurementsAux->covMatrix[measIdx].data()};
271 }
272 template <std::size_t measdim, bool Enable = true>
273 std::enable_if_t<
274 Enable, typename TrackStateProxy::template CalibratedCovariance<measdim>>
276 xAOD::TrackStateIndexType measIdx = m_trackStatesAux->calibrated[index];
277 return TrackStateProxy::template CalibratedCovariance<measdim>{m_trackMeasurementsAux->covMatrix[measIdx].data()};
278 }
279
285
286 inline Acts::TrackIndexType size_impl() const {
287 return m_trackStatesSize;
288 }
289
294 void clear_impl();
295
300 bool has_backends() const;
301
305 template <typename val_t, typename cov_t>
307 const Eigen::DenseBase<val_t>& val,
308 const Eigen::DenseBase<cov_t>& cov)
309 requires(Eigen::PlainObjectBase<val_t>::RowsAtCompileTime > 0 &&
310 static_cast<unsigned>(Eigen::PlainObjectBase<val_t>::RowsAtCompileTime) <= Acts::eBoundSize &&
311 static_cast<unsigned>(Eigen::PlainObjectBase<val_t>::RowsAtCompileTime) ==
312 static_cast<unsigned>(Eigen::PlainObjectBase<cov_t>::RowsAtCompileTime) &&
313 Eigen::PlainObjectBase<cov_t>::RowsAtCompileTime ==
314 Eigen::PlainObjectBase<cov_t>::ColsAtCompileTime);
315
320
325 const Acts::SourceLink& sourceLink);
326
330 typename Acts::SourceLink getUncalibratedSourceLink_impl(
331 ActsTrk::IndexType istate) const;
332
334 std::shared_ptr<const Acts::Surface>);
335 const Acts::Surface* referenceSurface_impl(IndexType ) const;
336
345 Acts::HashedString key,
346 const std::any& src_ptr);
350 std::vector<Acts::HashedString> dynamicKeys_impl() const;
351
352 // access to some backends (for debugging purposes)
353 // the receiver should not assume ownership or similar
355
357 return m_trackParametersAux.get();
358 }
362
366
370
378 return m_surfacesBackend.get();
379 }
380
381 static const std::set<std::string> s_staticVariables;
382
384
385 private:
386
387 std::unique_ptr<xAOD::TrackStateAuxContainer> m_trackStatesAux;
389
390 std::unique_ptr<xAOD::TrackParametersAuxContainer> m_trackParametersAux;
392
393 std::unique_ptr<xAOD::TrackJacobianAuxContainer> m_trackJacobiansAux;
395
396 std::unique_ptr<xAOD::TrackMeasurementAuxContainer> m_trackMeasurementsAux;
398
399 std::unique_ptr<xAOD::TrackSurfaceContainer> m_surfacesBackend;
400 std::unique_ptr<xAOD::TrackSurfaceAuxContainer> m_surfacesBackendAux;
401 std::vector<ActsTrk::detail::Decoration> m_decorations;
402
403 std::vector<std::optional<Acts::SourceLink>> m_calibratedSourceLinks;
404 std::vector<std::optional<Acts::SourceLink>> m_uncalibratedSourceLinks;
405
406 std::vector<StoredSurface> m_surfaces;
408
410
411 // adjust preallocated size to actually used
412 void trim();
413};
414
421 : public Acts::MultiTrajectory<MultiTrajectory> {
422 public:
423
430
432
433 bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const;
434
435 std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const;
436
437 bool hasColumn_impl(Acts::HashedString key) const;
438
439 typename ConstTrackStateProxy::ConstParameters parameters_impl(
441 return typename ConstTrackStateProxy::ConstParameters{m_trackParametersAux->params[index].data()};
442 }
443
444 typename ConstTrackStateProxy::ConstCovariance covariance_impl(
446 return typename ConstTrackStateProxy::ConstCovariance{m_trackParametersAux->covMatrix[index].data()};
447 }
448
449 inline typename ConstTrackStateProxy::ConstCovariance jacobian_impl(
450 ActsTrk::IndexType istate) const {
451 xAOD::TrackStateIndexType jacIdx = m_trackStatesAux->jacobian[istate];
452 return typename ConstTrackStateProxy::ConstCovariance{m_trackJacobiansAux->jac[jacIdx].data()};
453 }
454
455 template <std::size_t measdim>
456 inline typename ConstTrackStateProxy::template ConstCalibrated<measdim>
458 xAOD::TrackStateIndexType measIdx = m_trackStatesAux->calibrated[istate];
459 return typename ConstTrackStateProxy::template ConstCalibrated<measdim>{m_trackMeasurementsAux->meas[measIdx].data()};
460 }
461
462 template <std::size_t measdim>
463 inline typename ConstTrackStateProxy::template ConstCalibratedCovariance<measdim>
465 xAOD::TrackStateIndexType measIdx = m_trackStatesAux->calibrated[index];
466 return typename ConstTrackStateProxy::template ConstCalibratedCovariance<measdim>{m_trackMeasurementsAux->covMatrix[measIdx].data()};
467 }
468 inline Acts::TrackIndexType size_impl() const { return m_trackStatesAux->size(); }
469
471 typename Acts::SourceLink getUncalibratedSourceLink_impl(ActsTrk::IndexType istate) const;
472
473 const Acts::Surface* referenceSurface_impl(IndexType) const;
474
479 void fillSurfaces(const Acts::TrackingGeometry* geo);
484
486
487 std::vector<Acts::HashedString> dynamicKeys_impl() const;
488
489 private:
495 std::vector<ActsTrk::detail::Decoration> m_decorations;
496
497 // TODO remove once tracking code switches to sourceLinks with EL
498 std::vector<std::optional<Acts::SourceLink>> m_calibratedSourceLinks;
499 // still need this to store SourceLinks with other payloads than
500 // pointer to xAOD::UncalibratedMeasurement e.g. pointer to Trk::Measurements
501 // when converting Trk::Tracks to Acts tracks.
502 std::vector<std::optional<Acts::SourceLink>> m_uncalibratedSourceLinks;
503
504 std::vector<StoredSurface> m_surfaces;
505
507};
508
509
514template<typename IFACE, typename AUX>
515std::unique_ptr<IFACE> makeInterfaceContainer(const AUX* aux) {
516 auto interface = std::make_unique<IFACE>();
517 for ( size_t i = 0, sz = aux->size(); i < sz; ++i) {
518 interface->emplace_back( new std::remove_pointer_t<typename IFACE::value_type>() );
519 }
520 interface->setStore(aux);
521 return interface;
522}
523
524
525} // namespace ActsTrk
526
527#include "MultiTrajectory.icc"
528
529
531CLASS_DEF( ActsTrk::MultiTrajectory , 51219308 , 1 )
532
533// These two lines shouldn't be here, but necessary until we have a proper
534// solution
535#include "Acts/EventData/VectorTrackContainer.hpp"
536CLASS_DEF(Acts::ConstVectorTrackContainer, 1074811884, 1)
537
538#endif
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
static Double_t sz
Read only version of MTJ The implementation is separate as the details are significantly different an...
std::vector< std::optional< Acts::SourceLink > > m_uncalibratedSourceLinks
Acts::TrackIndexType size_impl() const
bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
const DataLink< xAOD::TrackParametersAuxContainer > m_trackParametersAux
Acts::SourceLink getUncalibratedSourceLink_impl(ActsTrk::IndexType istate) const
ConstTrackStateProxy::ConstCovariance jacobian_impl(ActsTrk::IndexType istate) const
const DataLink< xAOD::TrackMeasurementAuxContainer > m_trackMeasurementsAux
std::vector< ActsTrk::detail::Decoration > m_decorations
xAOD::TrackStateContainer m_trackStatesIface
const DataLink< xAOD::TrackStateAuxContainer > m_trackStatesAux
std::vector< Acts::HashedString > dynamicKeys_impl() const
std::vector< std::optional< Acts::SourceLink > > m_calibratedSourceLinks
std::vector< StoredSurface > m_surfaces
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
void moveSurfaces(const ActsTrk::MutableMultiTrajectory *mtj)
reuse surfaces from MutableMultiTrajectory
const Acts::Surface * referenceSurface_impl(IndexType) const
ConstTrackStateProxy::template ConstCalibrated< measdim > calibrated_impl(IndexType istate) const
const DataLink< xAOD::TrackSurfaceAuxContainer > m_trackSurfacesAux
const DataLink< xAOD::TrackJacobianAuxContainer > m_trackJacobiansAux
MultiTrajectory(DataLink< xAOD::TrackStateAuxContainer > trackStates, DataLink< xAOD::TrackParametersAuxContainer > trackParameters, DataLink< xAOD::TrackJacobianAuxContainer > trackJacobians, DataLink< xAOD::TrackMeasurementAuxContainer > trackMeasurements, DataLink< xAOD::TrackSurfaceAuxContainer > trackSurfaces)
void fillSurfaces(const Acts::TrackingGeometry *geo)
Fill surfaces either from persistency or from geometry If the surfaces are already there it means tha...
ConstTrackStateProxy::ConstCovariance covariance_impl(ActsTrk::IndexType index) const
ConstTrackStateProxy::ConstParameters parameters_impl(ActsTrk::IndexType index) const
void moveLinks(const ActsTrk::MutableMultiTrajectory *mtj)
ConstTrackStateProxy::template ConstCalibratedCovariance< measdim > calibratedCovariance_impl(IndexType index) const
bool hasColumn_impl(Acts::HashedString key) const
Athena implementation of ACTS::MultiTrajectory (ReadWrite version) The data is stored in 4 external b...
ConstTrackStateProxy::template ConstCalibratedCovariance< measdim > calibratedCovariance_impl(ActsTrk::IndexType index) const
obtain measurements covariance for a state at given index
ConstTrackStateProxy::template ConstCalibrated< measdim > calibrated_impl(ActsTrk::IndexType index) const
obtain calibrated measurements for a state at given index
TrackStateProxy::Covariance trackMeasurementsCov(ActsTrk::IndexType index)
ConstTrackStateProxy::ConstCovariance jacobian_impl(ActsTrk::IndexType istate) const
obtain jacobian for a state at given index
std::vector< StoredSurface > m_surfaces
static const std::set< std::string > s_staticVariables
MutableMultiTrajectory(ActsTrk::MutableMultiTrajectory &&other)=default
ConstTrackStateProxy::Covariance trackMeasurementsCov(ActsTrk::IndexType index) const
obtain measurement covariances for a state at given index
std::vector< std::optional< Acts::SourceLink > > m_calibratedSourceLinks
xAOD::TrackJacobianAuxContainer * trackJacobiansAux()
bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
checks if given state has requested component
constexpr bool hasColumn_impl(Acts::HashedString key) const
checks if MTJ has requested column (irrespectively of the state)
TrackStateProxy::Covariance jacobian_impl(ActsTrk::IndexType istate)
std::vector< ActsTrk::detail::Decoration > m_decorations
Acts::SourceLink getUncalibratedSourceLink_impl(ActsTrk::IndexType istate) const
Implementation of uncalibrated link fetch.
void allocateCalibrated_impl(IndexType istate, const Eigen::DenseBase< val_t > &val, const Eigen::DenseBase< cov_t > &cov)
Implementation of allocation of calibrated measurements.
void setReferenceSurface_impl(IndexType, std::shared_ptr< const Acts::Surface >)
std::unique_ptr< xAOD::TrackParametersAuxContainer > m_trackParametersAux
const xAOD::TrackParametersAuxContainer * trackParametersAux() const
ActsTrk::IndexType addTrackState_impl(Acts::TrackStatePropMask mask, ActsTrk::IndexType iprevious)
Add state with stograge for data that depends on the mask.
MutableMultiTrajectory & operator=(const ActsTrk::MutableMultiTrajectory &other)=delete
typename Acts::MultiTrajectory< ActsTrk::MutableMultiTrajectory >::TrackStateProxy TrackStateProxy
void unset_impl(Acts::TrackStatePropMask target, ActsTrk::IndexType istate)
unsets a given state
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
Access component by key.
MutableMultiTrajectory()
Construct a new Multi Trajectory object owning backends.
xAOD::TrackStateContainer m_trackStatesIface
std::vector< Acts::HashedString > dynamicKeys_impl() const
returns the keys of all the dynamic columns
std::unique_ptr< xAOD::TrackStateAuxContainer > m_trackStatesAux
std::enable_if_t< Enable, typename TrackStateProxy::template Calibrated< measdim > > calibrated_impl(ActsTrk::IndexType index)
ConstTrackStateProxy::ConstCovariance covariance_impl(ActsTrk::IndexType index) const
obtain covariances for a state at given index
std::unique_ptr< xAOD::TrackSurfaceAuxContainer > m_surfacesBackendAux
const Acts::Surface * referenceSurface_impl(IndexType) const
std::vector< std::optional< Acts::SourceLink > > m_uncalibratedSourceLinks
Acts::TrackIndexType size_impl() const
size of the MTJ
xAOD::TrackSurfaceContainer * trackSurfaces()
std::unique_ptr< xAOD::TrackMeasurementAuxContainer > m_trackMeasurementsAux
void addTrackStateComponents_impl(ActsTrk::IndexType istate, Acts::TrackStatePropMask mask)
Add state components for the given mask.
void copyDynamicFrom_impl(ActsTrk::IndexType istate, Acts::HashedString key, const std::any &src_ptr)
copy dynamic data from another MTJ
xAOD::TrackMeasurementAuxContainer * trackMeasurementsAux()
TrackStateProxy::Covariance covariance_impl(ActsTrk::IndexType index)
ConstTrackStateProxy::ConstParameters parameters_impl(ActsTrk::IndexType index) const
obtains proxy to the track state under given index
const xAOD::TrackSurfaceContainer * trackSurfaces() const
std::unique_ptr< xAOD::TrackSurfaceContainer > m_surfacesBackend
TrackStateProxy::Parameters parameters_impl(ActsTrk::IndexType index)
bool has_backends() const
checks if the backends are connected (i.e.
void shareFrom_impl(ActsTrk::IndexType iself, ActsTrk::IndexType iother, Acts::TrackStatePropMask shareSource, Acts::TrackStatePropMask shareTarget)
shares from a given state
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
Implementation of calibrated size.
std::enable_if_t< Enable, typename TrackStateProxy::template CalibratedCovariance< measdim > > calibratedCovariance_impl(ActsTrk::IndexType index)
xAOD::TrackParametersAuxContainer * trackParametersAux()
void addColumn_impl(std::string_view key)
enables particular decoration, type & name need to be specified
typename Acts::MultiTrajectory< ActsTrk::MutableMultiTrajectory >::ConstTrackStateProxy ConstTrackStateProxy
xAOD::TrackStateAuxContainer * trackStatesAux()
xAOD::TrackSurfaceAuxContainer * trackSurfacesAux()
std::unique_ptr< xAOD::TrackJacobianAuxContainer > m_trackJacobiansAux
void setUncalibratedSourceLink_impl(ActsTrk::IndexType istate, const Acts::SourceLink &sourceLink)
Implementation of uncalibrated link insertion.
void clear_impl()
clears backends decoration columns are still declared
A couple standard-library related concepts.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::variant< const Acts::Surface *, std::shared_ptr< const Acts::Surface > > StoredSurface
std::unique_ptr< IFACE > makeInterfaceContainer(const AUX *aux)
helper to construct interface container for already filled Aux container TODO maybe should be moved t...
std::uint32_t IndexType
Definition Decoration.h:18
Definition index.py:1
TrackStateContainer_v1 TrackStateContainer
TrackSurfaceAuxContainer_v1 TrackSurfaceAuxContainer
TrackSurfaceContainer_v1 TrackSurfaceContainer
TrackStateAuxContainer_v1 TrackStateAuxContainer
TrackParametersAuxContainer_v1 TrackParametersAuxContainer
TrackJacobianAuxContainer_v1 TrackJacobianAuxContainer
TrackMeasurementAuxContainer_v1 TrackMeasurementAuxContainer
uint32_t TrackStateIndexType