diff --git a/Core/include/Acts/EventData/MultiTrajectory.hpp b/Core/include/Acts/EventData/MultiTrajectory.hpp index fa9824abe97..0caf463913c 100644 --- a/Core/include/Acts/EventData/MultiTrajectory.hpp +++ b/Core/include/Acts/EventData/MultiTrajectory.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2019-2020 CERN for the benefit of the Acts project +// Copyright (C) 2019-2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -148,6 +148,7 @@ struct IsReadOnlyMultiTrajectory; /// iterating over specific sub-components. template class MultiTrajectory { + public: using Derived = derived_t; static constexpr bool ReadOnly = IsReadOnlyMultiTrajectory::value; @@ -161,7 +162,6 @@ class MultiTrajectory { template friend class MultiTrajectory; - public: /// Alias for the const version of a track state proxy, with the same /// backends as this container using ConstTrackStateProxy = @@ -461,62 +461,103 @@ class MultiTrajectory { } /// Retrieve a jacobian proxy instance for a jacobian at a given index - /// @param jacIdx Index into the jacobian column + /// @param istate The track state /// @return Mutable proxy template > - typename TrackStateProxy::Covariance jacobian(IndexType jacIdx) { - return self().jacobian_impl(jacIdx); + typename TrackStateProxy::Covariance jacobian(IndexType istate) { + return self().jacobian_impl(istate); } /// Retrieve a jacobian proxy instance for a jacobian at a given index - /// @param jacIdx Index into the jacobian column + /// @param istate The track state /// @return Const proxy - typename ConstTrackStateProxy::Covariance jacobian(IndexType jacIdx) const { - return self().jacobian_impl(jacIdx); + typename ConstTrackStateProxy::Covariance jacobian(IndexType istate) const { + return self().jacobian_impl(istate); } - /// Retrieve a measurement proxy instance for a measurement at a given index + /// Retrieve a calibrated measurement proxy instance for a measurement at a + /// given index /// @tparam measdim the measurement dimension - /// @param measIdx Index into the measurement column + /// @param istate The track state /// @return Mutable proxy template > - typename TrackStateProxy::template Measurement measurement( - IndexType measIdx) { - return self().template measurement_impl(measIdx); + typename TrackStateProxy::template Calibrated calibrated( + IndexType istate) { + return self().template calibrated_impl(istate); } - /// Retrieve a measurement proxy instance for a measurement at a given index + /// Retrieve a calibrated measurement proxy instance for a measurement at a + /// given index /// @tparam measdim the measurement dimension - /// @param measIdx Index into the measurement column + /// @param istate The track state /// @return Const proxy template - typename ConstTrackStateProxy::template Measurement measurement( - IndexType measIdx) const { - return self().template measurement_impl(measIdx); + typename ConstTrackStateProxy::template Calibrated calibrated( + IndexType istate) const { + return self().template calibrated_impl(istate); } - /// Retrieve a measurement covariance proxy instance for a measurement at a - /// given index + /// Retrieve a calibrated measurement covariance proxy instance for a + /// measurement at a given index /// @tparam measdim the measurement dimension - /// @param covIdx Index into the measurement covariance column + /// @param istate The track state /// @return Mutable proxy template > - typename TrackStateProxy::template MeasurementCovariance - measurementCovariance(IndexType covIdx) { - return self().template measurementCovariance_impl(covIdx); + typename TrackStateProxy::template CalibratedCovariance + calibratedCovariance(IndexType istate) { + return self().template calibratedCovariance_impl(istate); } - /// Retrieve a measurement covariance proxy instance for a measurement at a - /// given index - /// @param covIdx Index into the measurement covariance column + template > + typename TrackStateProxy::EffectiveCalibrated effectiveCalibrated( + IndexType istate) { + // This abuses an incorrectly sized vector / matrix to access the + // data pointer! This works (don't use the matrix as is!), but be + // careful! + return typename TrackStateProxy::EffectiveCalibrated{ + calibrated(istate).data(), calibratedSize(istate)}; + } + + typename ConstTrackStateProxy::EffectiveCalibrated effectiveCalibrated( + IndexType istate) const { + // This abuses an incorrectly sized vector / matrix to access the + // data pointer! This works (don't use the matrix as is!), but be + // careful! + return typename ConstTrackStateProxy::EffectiveCalibrated{ + calibrated(istate).data(), calibratedSize(istate)}; + } + + template > + typename TrackStateProxy::EffectiveCalibratedCovariance + effectiveCalibratedCovariance(IndexType istate) { + // This abuses an incorrectly sized vector / matrix to access the + // data pointer! This works (don't use the matrix as is!), but be + // careful! + return typename TrackStateProxy::EffectiveCalibratedCovariance{ + calibratedCovariance(istate).data(), calibratedSize(istate), + calibratedSize(istate)}; + } + + typename ConstTrackStateProxy::EffectiveCalibratedCovariance + effectiveCalibratedCovariance(IndexType istate) const { + // This abuses an incorrectly sized vector / matrix to access the + // data pointer! This works (don't use the matrix as is!), but be + // careful! + return typename ConstTrackStateProxy::EffectiveCalibratedCovariance{ + calibratedCovariance(istate).data(), calibratedSize(istate), + calibratedSize(istate)}; + } + + /// Retrieve a calibrated measurement covariance proxy instance for a + /// measurement at a given index + /// @param istate The track state /// @return Const proxy template - constexpr - typename ConstTrackStateProxy::template MeasurementCovariance - measurementCovariance(IndexType covIdx) const { - return self().template measurementCovariance_impl(covIdx); + typename ConstTrackStateProxy::template CalibratedCovariance + calibratedCovariance(IndexType istate) const { + return self().template calibratedCovariance_impl(istate); } /// Get the calibrated measurement size for a track state diff --git a/Core/include/Acts/EventData/MultiTrajectoryBackendConcept.hpp b/Core/include/Acts/EventData/MultiTrajectoryBackendConcept.hpp index 06f46a4137d..5e5b41ed75d 100644 --- a/Core/include/Acts/EventData/MultiTrajectoryBackendConcept.hpp +++ b/Core/include/Acts/EventData/MultiTrajectoryBackendConcept.hpp @@ -21,11 +21,13 @@ #include #if defined(__cpp_concepts) + #include namespace Acts { namespace detail { + using Parameters = Eigen::Map; using Covariance = Eigen::Map; @@ -59,11 +61,11 @@ concept CommonMultiTrajectoryBackend = requires(const T& cv, HashedString key, { cv.jacobian_impl(istate) } -> std::same_as; { - cv.template measurement_impl<2>(istate) + cv.template calibrated_impl<2>(istate) } -> std::same_as>>; { - cv.template measurementCovariance_impl<2>(istate) + cv.template calibratedCovariance_impl<2>(istate) } -> std::same_as>>; { cv.has_impl(key, istate) } -> std::same_as; @@ -88,11 +90,11 @@ concept ConstMultiTrajectoryBackend = CommonMultiTrajectoryBackend && { v.jacobian_impl(istate) } -> std::same_as; { - v.template measurement_impl<2>(istate) + v.template calibrated_impl<2>(istate) } -> std::same_as>>; { - v.template measurementCovariance_impl<2>(istate) + v.template calibratedCovariance_impl<2>(istate) } -> std::same_as>>; }; @@ -108,11 +110,11 @@ concept MutableMultiTrajectoryBackend = CommonMultiTrajectoryBackend && { v.jacobian_impl(istate) } -> std::same_as; { - v.template measurement_impl<2>(istate) + v.template calibrated_impl<2>(istate) } -> std::same_as>>; { - v.template measurementCovariance_impl<2>(istate) + v.template calibratedCovariance_impl<2>(istate) } -> std::same_as>>; { v.addTrackState_impl() } -> std::same_as; @@ -142,4 +144,5 @@ concept MutableMultiTrajectoryBackend = CommonMultiTrajectoryBackend && }; } // namespace Acts + #endif diff --git a/Core/include/Acts/EventData/TrackProxy.hpp b/Core/include/Acts/EventData/TrackProxy.hpp index 9a19cf88ace..38e4348c1a0 100644 --- a/Core/include/Acts/EventData/TrackProxy.hpp +++ b/Core/include/Acts/EventData/TrackProxy.hpp @@ -193,20 +193,20 @@ class TrackProxy { /// Map-type for a bound parameter vector. This has reference semantics, i.e. /// points at a matrix by an internal pointer. using Parameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; /// Same as @ref Parameters, but with const semantics using ConstParameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; /// Map-type for a bound covariance. This has reference semantics, i.e. /// points at a matrix by an internal pointer. using Covariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; /// Same as @ref Covariance, but with const semantics using ConstCovariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; #ifndef DOXYGEN friend TrackContainer; diff --git a/Core/include/Acts/EventData/TrackStateProxy.hpp b/Core/include/Acts/EventData/TrackStateProxy.hpp index ee0bdc6696f..5e56524007a 100644 --- a/Core/include/Acts/EventData/TrackStateProxy.hpp +++ b/Core/include/Acts/EventData/TrackStateProxy.hpp @@ -75,14 +75,14 @@ class TransitiveConstPointer { T* m_ptr; }; -/// Type construction helper for coefficients and associated covariances. +/// Type construction helper for fixed size coefficients and associated +/// covariances. template -struct Types { - enum { - Flags = Eigen::ColMajor | Eigen::AutoAlign, - }; +struct FixedSizeTypes { + constexpr static auto Flags = Eigen::ColMajor | Eigen::AutoAlign; using Scalar = ActsScalar; + // single items using Coefficients = Eigen::Matrix; using Covariance = Eigen::Matrix; @@ -97,28 +97,52 @@ struct Types { using DynamicCovarianceMap = Eigen::Map>; }; + +// Type construction helper for dynamic sized coefficients and associated +/// covariances. +template +struct DynamicSizeTypes { + constexpr static auto Flags = Eigen::ColMajor | Eigen::AutoAlign; + + using Scalar = ActsScalar; + + using Coefficients = Eigen::Matrix; + using Covariance = + Eigen::Matrix; + using CoefficientsMap = Eigen::Map>; + using CovarianceMap = Eigen::Map>; +}; + } // namespace detail_lt // This is public template struct TrackStateTraits { + using Scalar = ActsScalar; + using Parameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; using Covariance = - typename detail_lt::Types::CovarianceMap; - using Measurement = typename detail_lt::Types::CoefficientsMap; - using MeasurementCovariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; + using Calibrated = + typename detail_lt::FixedSizeTypes::CoefficientsMap; + using CalibratedCovariance = + typename detail_lt::FixedSizeTypes::CovarianceMap; + using EffectiveCalibrated = + typename detail_lt::DynamicSizeTypes::CoefficientsMap; + using EffectiveCalibratedCovariance = + typename detail_lt::DynamicSizeTypes::CovarianceMap; constexpr static auto ProjectorFlags = Eigen::RowMajor | Eigen::AutoAlign; - using Projector = - Eigen::Matrix; + using Projector = Eigen::Matrix; + using EffectiveProjector = Eigen::Matrix; }; /// Proxy object to access a single point on the trajectory. /// /// @tparam SourceLink Type to link back to an original measurement -/// @tparam M Maximum number of measurement dimensions +/// @tparam M Maximum number of measurement dimensions /// @tparam read_only true for read-only access to underlying storage template class TrackStateProxy { @@ -144,25 +168,43 @@ class TrackStateProxy { /// Same as @ref Covariance, but with const semantics using ConstCovariance = typename TrackStateTraits::Covariance; - /// Map-type for a measurement vector, where the local measurement dimension - /// is variable. + /// Map-type for a calibrated measurement vector, where the local measurement + /// dimension is variable. template - using Measurement = typename TrackStateTraits::Measurement; + using Calibrated = typename TrackStateTraits::Calibrated; - /// Same as @c Measurement, but with const semantics + /// Same as @c Calibrated, but with const semantics template - using ConstMeasurement = typename TrackStateTraits::Measurement; + using ConstCalibrated = typename TrackStateTraits::Calibrated; - /// Map-type for a measurement covariance matrix, where the local measurement - /// dimension is variable. + /// Map-type for a calibrated measurement covariance matrix, where the local + /// measurement dimension is variable. template - using MeasurementCovariance = - typename TrackStateTraits::MeasurementCovariance; + using CalibratedCovariance = + typename TrackStateTraits::CalibratedCovariance; - /// Same as @ref MeasurementCovariance, but with const semantics + /// Same as @ref CalibratedCovariance, but with const semantics template - using ConstMeasurementCovariance = - typename TrackStateTraits::MeasurementCovariance; + using ConstCalibratedCovariance = + typename TrackStateTraits::CalibratedCovariance; + + /// Map-type for a measurement vector, where the local measurement dimension + /// is variable. + using EffectiveCalibrated = + typename TrackStateTraits::EffectiveCalibrated; + + /// Same as @c EffectiveCalibrated, but with const semantics + using ConstEffectiveCalibrated = + typename TrackStateTraits::EffectiveCalibrated; + + /// Map-type for a measurement covariance matrix, where the local measurement + /// dimension is variable. + using EffectiveCalibratedCovariance = + typename TrackStateTraits::EffectiveCalibratedCovariance; + + /// Same as @ref EffectiveCalibratedCovariance, but with const semantics + using ConstEffectiveCalibratedCovariance = + typename TrackStateTraits::EffectiveCalibratedCovariance; /// The index type of the track state container using IndexType = TrackIndexType; @@ -179,9 +221,7 @@ class TrackStateProxy { /// Dynamic variant of the projector matrix /// @warning Using this type is discouraged, as it has a runtime overhead using EffectiveProjector = - Eigen::Matrix::ProjectorFlags, M, - eBoundSize>; + typename TrackStateTraits::EffectiveProjector; /// The track state container backend given as a template parameter using Trajectory = trajectory_t; @@ -559,9 +599,6 @@ class TrackStateProxy { /// The projector matrix is packed as a bitset, which is converted to a matrix /// on-demand (and therefore returned by value). /// - /// A convenience function to assign this from the @ref Measurement class - /// is provided, although it's use is discouraged. - /// /// The track state also includes a @ref SourceLink which acts as a proxy /// to the original uncalibrated measurement that the calibrated measurement /// was derived from. It is set and returned by value, to allow unpacking / @@ -674,9 +711,9 @@ class TrackStateProxy { /// @return The measurement vector /// @note Const version template - ConstMeasurement calibrated() const { + ConstCalibrated calibrated() const { assert(has()); - return m_traj->self().template measurement(m_istate); + return m_traj->self().template calibrated(m_istate); } /// Full calibrated measurement vector. Might contain additional zeroed @@ -685,18 +722,18 @@ class TrackStateProxy { /// @note Mutable version template > - Measurement calibrated() { + Calibrated calibrated() { assert(has()); - return m_traj->self().template measurement(m_istate); + return m_traj->self().template calibrated(m_istate); } /// Const full calibrated measurement covariance matrix. The effective /// covariance is located in the top left corner, everything else is zeroed. /// @return The measurement covariance matrix template - ConstMeasurementCovariance calibratedCovariance() const { + ConstCalibratedCovariance calibratedCovariance() const { assert(has()); - return m_traj->self().template measurementCovariance(m_istate); + return m_traj->self().template calibratedCovariance(m_istate); } /// Mutable full calibrated measurement covariance matrix. The effective @@ -704,77 +741,44 @@ class TrackStateProxy { /// @return The measurement covariance matrix template > - MeasurementCovariance calibratedCovariance() { + CalibratedCovariance calibratedCovariance() { assert(has()); - return m_traj->self().template measurementCovariance(m_istate); + return m_traj->self().template calibratedCovariance(m_istate); } /// Mutable dynamic measurement vector with only the valid dimensions. /// @warning The dynamic vector has a runtime overhead! /// @return The effective calibrated measurement vector template > - auto effectiveCalibrated() { - // repackage the data pointer to a dynamic map type - // workaround for gcc8 bug: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86594 - auto* self = this; - return visit_measurement(calibratedSize(), [&](auto N) { - constexpr int kMeasurementSize = decltype(N)::value; - return typename detail_lt::Types::DynamicCoefficientsMap{ - self->template calibrated().data(), - kMeasurementSize}; - }); + EffectiveCalibrated effectiveCalibrated() { + assert(has()); + return m_traj->self().effectiveCalibrated(m_istate); } /// Const dynamic measurement vector with only the valid dimensions. /// @warning The dynamic matrix has a runtime overhead! /// @return The effective calibrated measurement vector - auto effectiveCalibrated() const { - // repackage the data pointer to a dynamic map type - // workaround for gcc8 bug: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86594 - auto* self = this; - return visit_measurement(calibratedSize(), [&](auto N) { - constexpr int kMeasurementSize = decltype(N)::value; - return typename detail_lt::Types::DynamicCoefficientsMap{ - self->template calibrated().data(), - kMeasurementSize}; - }); + ConstEffectiveCalibrated effectiveCalibrated() const { + assert(has()); + return m_traj->self().effectiveCalibrated(m_istate); } /// Mutable dynamic measurement covariance matrix with only the valid /// dimensions. /// @warning The dynamic matrix has a runtime overhead! /// @return The effective calibrated covariance matrix - template > - auto effectiveCalibratedCovariance() { - // repackage the data pointer to a dynamic map type - // workaround for gcc8 bug: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86594 - auto* self = this; - return visit_measurement(calibratedSize(), [&](auto N) { - constexpr int kMeasurementSize = decltype(N)::value; - return typename detail_lt::Types::DynamicCovarianceMap{ - self->template calibratedCovariance().data(), - kMeasurementSize, kMeasurementSize}; - }); + EffectiveCalibratedCovariance effectiveCalibratedCovariance() { + assert(has()); + return m_traj->self().effectiveCalibratedCovariance(m_istate); } /// Const dynamic measurement covariance matrix with only the valid /// dimensions. /// @warning The dynamic matrix has a runtime overhead! /// @return The effective calibrated covariance matrix - auto effectiveCalibratedCovariance() const { - // repackage the data pointer to a dynamic map type - // workaround for gcc8 bug: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86594 - auto* self = this; - return visit_measurement(calibratedSize(), [&](auto N) { - constexpr int kMeasurementSize = decltype(N)::value; - return typename detail_lt::Types::DynamicCovarianceMap{ - self->template calibratedCovariance().data(), - kMeasurementSize, kMeasurementSize}; - }); + ConstEffectiveCalibratedCovariance effectiveCalibratedCovariance() const { + assert(has()); + return m_traj->self().effectiveCalibratedCovariance(m_istate); } /// Return the (dynamic) number of dimensions stored for this measurement. diff --git a/Core/include/Acts/EventData/TrackStateProxyConcept.hpp b/Core/include/Acts/EventData/TrackStateProxyConcept.hpp index f1696c1f4fe..2cf1971ea63 100644 --- a/Core/include/Acts/EventData/TrackStateProxyConcept.hpp +++ b/Core/include/Acts/EventData/TrackStateProxyConcept.hpp @@ -54,9 +54,8 @@ using ConstDynamicMeasurementCovariance = Eigen::Map< constexpr static auto ProjectorFlags = Eigen::RowMajor | Eigen::AutoAlign; using Projector = Eigen::Matrix; - using EffectiveProjector = - Eigen::Matrix; } // namespace detail diff --git a/Core/include/Acts/EventData/VectorMultiTrajectory.hpp b/Core/include/Acts/EventData/VectorMultiTrajectory.hpp index 6c7ae3257da..6707525c7f8 100644 --- a/Core/include/Acts/EventData/VectorMultiTrajectory.hpp +++ b/Core/include/Acts/EventData/VectorMultiTrajectory.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2022 CERN for the benefit of the Acts project +// Copyright (C) 2022-2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -316,15 +316,16 @@ class VectorMultiTrajectoryBase { std::vector m_index; std::vector m_previous; std::vector m_next; - std::vector::Coefficients> m_params; - std::vector::Covariance> m_cov; + std::vector::Coefficients> + m_params; + std::vector::Covariance> m_cov; std::vector m_meas; std::vector m_measOffset; std::vector m_measCov; std::vector m_measCovOffset; - std::vector::Covariance> m_jac; + std::vector::Covariance> m_jac; std::vector> m_sourceLinks; std::vector m_projectors; @@ -394,30 +395,30 @@ class VectorMultiTrajectory final } template - TrackStateProxy::Measurement measurement_impl(IndexType istate) { + TrackStateProxy::Calibrated calibrated_impl(IndexType istate) { IndexType offset = m_measOffset[istate]; - return TrackStateProxy::Measurement{&m_meas[offset]}; + return TrackStateProxy::Calibrated{&m_meas[offset]}; } template - ConstTrackStateProxy::Measurement measurement_impl( + ConstTrackStateProxy::Calibrated calibrated_impl( IndexType istate) const { IndexType offset = m_measOffset[istate]; - return ConstTrackStateProxy::Measurement{&m_meas[offset]}; + return ConstTrackStateProxy::Calibrated{&m_meas[offset]}; } template - TrackStateProxy::MeasurementCovariance measurementCovariance_impl( + TrackStateProxy::CalibratedCovariance calibratedCovariance_impl( IndexType istate) { IndexType offset = m_measCovOffset[istate]; - return TrackStateProxy::MeasurementCovariance{&m_measCov[offset]}; + return TrackStateProxy::CalibratedCovariance{&m_measCov[offset]}; } template - ConstTrackStateProxy::MeasurementCovariance - measurementCovariance_impl(IndexType istate) const { + ConstTrackStateProxy::CalibratedCovariance calibratedCovariance_impl( + IndexType istate) const { IndexType offset = m_measCovOffset[istate]; - return ConstTrackStateProxy::MeasurementCovariance{ + return ConstTrackStateProxy::CalibratedCovariance{ &m_measCov[offset]}; } @@ -548,17 +549,17 @@ class ConstVectorMultiTrajectory final } template - ConstTrackStateProxy::Measurement measurement_impl( + ConstTrackStateProxy::Calibrated calibrated_impl( IndexType istate) const { IndexType offset = m_measOffset[istate]; - return ConstTrackStateProxy::Measurement{&m_meas[offset]}; + return ConstTrackStateProxy::Calibrated{&m_meas[offset]}; } template - ConstTrackStateProxy::MeasurementCovariance - measurementCovariance_impl(IndexType istate) const { + ConstTrackStateProxy::CalibratedCovariance calibratedCovariance_impl( + IndexType istate) const { IndexType offset = m_measCovOffset[istate]; - return ConstTrackStateProxy::MeasurementCovariance{ + return ConstTrackStateProxy::CalibratedCovariance{ &m_measCov[offset]}; } diff --git a/Core/include/Acts/EventData/VectorTrackContainer.hpp b/Core/include/Acts/EventData/VectorTrackContainer.hpp index 4fbfeb569dd..2f9d1e3ef1b 100644 --- a/Core/include/Acts/EventData/VectorTrackContainer.hpp +++ b/Core/include/Acts/EventData/VectorTrackContainer.hpp @@ -44,14 +44,14 @@ class VectorTrackContainerBase { MultiTrajectoryTraits::MeasurementSizeMax; using Parameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; using Covariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; using ConstParameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; using ConstCovariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; protected: VectorTrackContainerBase() = default; @@ -174,8 +174,9 @@ class VectorTrackContainerBase { std::vector m_tipIndex; std::vector m_stemIndex; std::vector m_particleHypothesis; - std::vector::Coefficients> m_params; - std::vector::Covariance> m_cov; + std::vector::Coefficients> + m_params; + std::vector::Covariance> m_cov; std::vector> m_referenceSurfaces; std::vector m_nMeasurements; diff --git a/Core/include/Acts/EventData/detail/GenerateParameters.hpp b/Core/include/Acts/EventData/detail/GenerateParameters.hpp index 955d92e15fe..4042ef5bba6 100644 --- a/Core/include/Acts/EventData/detail/GenerateParameters.hpp +++ b/Core/include/Acts/EventData/detail/GenerateParameters.hpp @@ -56,7 +56,7 @@ inline auto generateParametersCovariance(generator_t& rng) params[i] = stddev[i] * distNormal(rng); } - return std::make_pair(params, cov); + return {params, cov}; } /// Generate a random bound parameters vector and covariance matrix. diff --git a/Core/include/Acts/TrackFinding/MeasurementSelector.ipp b/Core/include/Acts/TrackFinding/MeasurementSelector.ipp index 902c12d90d8..49b03e4730e 100644 --- a/Core/include/Acts/TrackFinding/MeasurementSelector.ipp +++ b/Core/include/Acts/TrackFinding/MeasurementSelector.ipp @@ -62,19 +62,16 @@ MeasurementSelector::select( for (std::size_t i(0ul); i < candidates.size(); ++i) { auto& trackState = candidates[i]; - // This abuses an incorrectly sized vector / matrix to access the - // data pointer! This works (don't use the matrix as is!), but be - // careful! - double chi2 = calculateChi2( - trackState - .template calibrated() - .data(), - trackState - .template calibratedCovariance< - MultiTrajectoryTraits::MeasurementSizeMax>() - .data(), - trackState.predicted(), trackState.predictedCovariance(), - trackState.projector(), trackState.calibratedSize()); + // We access the dynamic size of the matrix here but use them later + // through a template function which accesses the data pointer + // with compile time size. That way the Eigen math operations are + // still done with compile time size and no dynamic memory allocation + // is needed. + double chi2 = + calculateChi2(trackState.effectiveCalibrated().data(), + trackState.effectiveCalibratedCovariance().data(), + trackState.predicted(), trackState.predictedCovariance(), + trackState.projector(), trackState.calibratedSize()); trackState.chi2() = chi2; if (chi2 < minChi2) { diff --git a/Core/src/TrackFinding/MeasurementSelector.cpp b/Core/src/TrackFinding/MeasurementSelector.cpp index 51d0064dbf1..946ca981949 100644 --- a/Core/src/TrackFinding/MeasurementSelector.cpp +++ b/Core/src/TrackFinding/MeasurementSelector.cpp @@ -39,10 +39,10 @@ double MeasurementSelector::calculateChi2( &predictedCovariance, &projector](auto N) -> double { constexpr std::size_t kMeasurementSize = decltype(N)::value; - typename TrackStateTraits::Measurement + typename TrackStateTraits::Calibrated calibrated{fullCalibrated}; - typename TrackStateTraits::MeasurementCovariance + typename TrackStateTraits::CalibratedCovariance calibratedCovariance{fullCalibratedCovariance}; using ParametersVector = ActsVector; diff --git a/Core/src/TrackFitting/GainMatrixUpdater.cpp b/Core/src/TrackFitting/GainMatrixUpdater.cpp index b46ba62dbe5..bea3cf46594 100644 --- a/Core/src/TrackFitting/GainMatrixUpdater.cpp +++ b/Core/src/TrackFitting/GainMatrixUpdater.cpp @@ -33,9 +33,9 @@ std::tuple GainMatrixUpdater::visitMeasurement( using ParametersVector = ActsVector; using CovarianceMatrix = ActsSquareMatrix; - typename TrackStateTraits::Measurement calibrated{ + typename TrackStateTraits::Calibrated calibrated{ trackState.calibrated}; - typename TrackStateTraits::MeasurementCovariance + typename TrackStateTraits::CalibratedCovariance calibratedCovariance{trackState.calibratedCovariance}; ACTS_VERBOSE("Measurement dimension: " << kMeasurementSize); diff --git a/Core/src/TrackFitting/GsfUtils.cpp b/Core/src/TrackFitting/GsfUtils.cpp index 13043c603e2..56ed204fcd4 100644 --- a/Core/src/TrackFitting/GsfUtils.cpp +++ b/Core/src/TrackFitting/GsfUtils.cpp @@ -25,7 +25,7 @@ ActsScalar calculateDeterminant( constexpr std::size_t kMeasurementSize = decltype(N)::value; typename Acts::TrackStateTraits< - kMeasurementSize, true>::MeasurementCovariance calibratedCovariance{ + kMeasurementSize, true>::CalibratedCovariance calibratedCovariance{ fullCalibratedCovariance}; const auto H = diff --git a/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp b/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp index 1a75473efca..028d289a6d7 100644 --- a/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp +++ b/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp @@ -11,6 +11,7 @@ #include "Acts/EventData/MultiTrajectory.hpp" #include "Acts/EventData/ParticleHypothesis.hpp" #include "Acts/EventData/TrackContainer.hpp" +#include "Acts/EventData/TrackStateProxy.hpp" #include "Acts/EventData/detail/DynamicColumn.hpp" #include "Acts/Plugins/Podio/PodioDynamicColumns.hpp" #include "Acts/Plugins/Podio/PodioUtil.hpp" @@ -45,14 +46,14 @@ class PodioTrackContainerBase { MultiTrajectoryTraits::MeasurementSizeMax; using Parameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; using Covariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; using ConstParameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; using ConstCovariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; protected: PodioTrackContainerBase(const PodioUtil::ConversionHelper& helper) diff --git a/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackStateContainer.hpp b/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackStateContainer.hpp index 1714fe9e770..7fd7ba11a6e 100644 --- a/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackStateContainer.hpp +++ b/Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackStateContainer.hpp @@ -43,14 +43,14 @@ class ConstPodioTrackStateContainer; class PodioTrackStateContainerBase { public: using Parameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; using Covariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; using ConstParameters = - typename detail_lt::Types::CoefficientsMap; + typename detail_lt::FixedSizeTypes::CoefficientsMap; using ConstCovariance = - typename detail_lt::Types::CovarianceMap; + typename detail_lt::FixedSizeTypes::CovarianceMap; protected: template @@ -286,16 +286,16 @@ class ConstPodioTrackStateContainer final } template - ConstTrackStateProxy::Measurement measurement_impl( + ConstTrackStateProxy::Calibrated calibrated_impl( IndexType index) const { - return ConstTrackStateProxy::Measurement{ + return ConstTrackStateProxy::Calibrated{ m_collection->at(index).getData().measurement.data()}; } template - ConstTrackStateProxy::MeasurementCovariance - measurementCovariance_impl(IndexType index) const { - return ConstTrackStateProxy::MeasurementCovariance{ + ConstTrackStateProxy::CalibratedCovariance calibratedCovariance_impl( + IndexType index) const { + return ConstTrackStateProxy::CalibratedCovariance{ m_collection->at(index).getData().measurementCovariance.data()}; } @@ -392,29 +392,29 @@ class MutablePodioTrackStateContainer final } template - ConstTrackStateProxy::Measurement measurement_impl( + ConstTrackStateProxy::Calibrated calibrated_impl( IndexType index) const { - return ConstTrackStateProxy::Measurement{ + return ConstTrackStateProxy::Calibrated{ m_collection->at(index).getData().measurement.data()}; } template - TrackStateProxy::Measurement measurement_impl(IndexType index) { - return TrackStateProxy::Measurement{ + TrackStateProxy::Calibrated calibrated_impl(IndexType index) { + return TrackStateProxy::Calibrated{ m_collection->at(index).data().measurement.data()}; } template - ConstTrackStateProxy::MeasurementCovariance - measurementCovariance_impl(IndexType index) const { - return ConstTrackStateProxy::MeasurementCovariance{ + ConstTrackStateProxy::CalibratedCovariance calibratedCovariance_impl( + IndexType index) const { + return ConstTrackStateProxy::CalibratedCovariance{ m_collection->at(index).getData().measurementCovariance.data()}; } template - TrackStateProxy::MeasurementCovariance measurementCovariance_impl( + TrackStateProxy::CalibratedCovariance calibratedCovariance_impl( IndexType index) { - return TrackStateProxy::MeasurementCovariance{ + return TrackStateProxy::CalibratedCovariance{ m_collection->at(index).data().measurementCovariance.data()}; }