diff --git a/Alignment/include/ActsAlignment/Kernel/detail/AlignmentEngine.hpp b/Alignment/include/ActsAlignment/Kernel/detail/AlignmentEngine.hpp index 1bb21fdc8bd..b26175abcdd 100644 --- a/Alignment/include/ActsAlignment/Kernel/detail/AlignmentEngine.hpp +++ b/Alignment/include/ActsAlignment/Kernel/detail/AlignmentEngine.hpp @@ -208,7 +208,9 @@ TrackAlignmentState trackAlignmentState( measdim) = measCovariance; // (b) Get and fill the bound parameters to measurement projection matrix - const ActsDynamicMatrix H = state.effectiveProjector(); + const ActsDynamicMatrix H = + state.projectorSubspaceHelper().fullProjector().topLeftCorner( + measdim, eBoundSize); alignState.projectionMatrix.block(iMeasurement, iParams, measdim, eBoundSize) = H; // (c) Get and fill the residual diff --git a/Core/include/Acts/EventData/SubspaceHelpers.hpp b/Core/include/Acts/EventData/SubspaceHelpers.hpp index 029dbf372b3..f48690cf036 100644 --- a/Core/include/Acts/EventData/SubspaceHelpers.hpp +++ b/Core/include/Acts/EventData/SubspaceHelpers.hpp @@ -14,8 +14,7 @@ #include "Acts/Utilities/AlgebraHelpers.hpp" #include "Acts/Utilities/Enumerate.hpp" -#include -#include +#include #include @@ -25,30 +24,30 @@ namespace Acts { /// /// Indices must be unique and within the full size of the subspace /// -/// @tparam Container type of the container +/// @tparam index_range_t the type of the container of indices /// -/// @param container the container of indices +/// @param indexRange the range of indices /// @param fullSize the full size of the subspace /// @param subspaceSize the size of the subspace /// /// @return true if the indices are consistent -template -inline static bool checkSubspaceIndices(const Container& container, +template +inline static bool checkSubspaceIndices(const index_range_t& indexRange, std::size_t fullSize, std::size_t subspaceSize) { if (subspaceSize > fullSize) { return false; } - if (static_cast(container.size()) != subspaceSize) { + if (static_cast(indexRange.size()) != subspaceSize) { return false; } - for (auto it = container.begin(); it != container.end();) { + for (auto it = indexRange.begin(); it != indexRange.end();) { auto index = *it; if (index >= fullSize) { return false; } ++it; - if (std::find(it, container.end(), index) != container.end()) { + if (std::find(it, indexRange.end(), index) != indexRange.end()) { return false; } } @@ -69,7 +68,8 @@ inline static SerializedSubspaceIndices serializeSubspaceIndices( { SerializedSubspaceIndices result = 0; for (std::size_t i = 0; i < FullSize; ++i) { - result |= static_cast(indices[i]) << (i * 8); + result |= static_cast(indices[i] & 0xFF) + << (i * 8); } return result; } @@ -88,7 +88,7 @@ inline static SubspaceIndices deserializeSubspaceIndices( { SubspaceIndices result; for (std::size_t i = 0; i < FullSize; ++i) { - result[i] = static_cast(serialized >> (i * 8)); + result[i] = static_cast((serialized >> (i * 8)) & 0xFF); } return result; } @@ -187,8 +187,8 @@ class VariableSubspaceHelper using IndexType = index_t; using Container = boost::container::static_vector; - template - explicit VariableSubspaceHelper(const OtherContainer& indices) { + template + explicit VariableSubspaceHelper(const other_index_range_t& indices) { assert(checkSubspaceIndices(indices, kFullSize, indices.size()) && "Invalid indices"); m_indices.resize(indices.size()); @@ -236,8 +236,8 @@ class FixedSubspaceHelper using IndexType = index_t; using Container = std::array; - template - explicit FixedSubspaceHelper(const OtherContainer& indices) { + template + explicit FixedSubspaceHelper(const other_index_range_t& indices) { assert(checkSubspaceIndices(indices, kFullSize, kSubspaceSize) && "Invalid indices"); std::transform(indices.begin(), indices.end(), m_indices.begin(), diff --git a/Core/include/Acts/EventData/TrackStateProxy.hpp b/Core/include/Acts/EventData/TrackStateProxy.hpp index 3f7ddf1a028..4338c434f77 100644 --- a/Core/include/Acts/EventData/TrackStateProxy.hpp +++ b/Core/include/Acts/EventData/TrackStateProxy.hpp @@ -8,7 +8,6 @@ #pragma once -#include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/TrackParametrization.hpp" #include "Acts/EventData/SourceLink.hpp" #include "Acts/EventData/SubspaceHelpers.hpp" @@ -17,11 +16,11 @@ #include "Acts/EventData/TrackStateType.hpp" #include "Acts/EventData/Types.hpp" #include "Acts/Surfaces/Surface.hpp" -#include "Acts/Utilities/AlgebraHelpers.hpp" #include "Acts/Utilities/HashedString.hpp" #include "Acts/Utilities/Helpers.hpp" #include +#include #include #include @@ -127,11 +126,6 @@ struct TrackStateTraits { 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 EffectiveProjector = Eigen::Matrix; }; /// Proxy object to access a single point on the trajectory. @@ -207,17 +201,6 @@ class TrackStateProxy { /// Sentinel value that indicates an invalid index static constexpr IndexType kInvalid = kTrackIndexInvalid; - /// Matrix representing the projector (measurement mapping function) for a - /// measurement. This is not a map type, but an actual matrix. This matrix - /// is always \f$M \times M\f$, even if the local measurement dimension is lower. - /// The actual \f$N\times M\f$ projector is given by the top \f$N\f$ rows. - using Projector = typename TrackStateTraits::Projector; - - /// Dynamic variant of the projector matrix - /// @warning Using this type is discouraged, as it has a runtime overhead - using EffectiveProjector = - typename TrackStateTraits::EffectiveProjector; - /// The track state container backend given as a template parameter using Trajectory = trajectory_t; @@ -615,145 +598,61 @@ class TrackStateProxy { /// /// @{ - /// Returns the projector (measurement mapping function) for this track - /// state. It is derived from the uncalibrated measurement - /// @note This function returns the overallocated projector. This means it - /// is of dimension MxM, where M is the maximum number of measurement - /// dimensions. The NxM submatrix, where N is the actual dimension of the - /// measurement, is located in the top left corner, everything else is zero. - /// @return The overallocated projector - Projector projector() const; - - /// Returns whether a projector is set - /// @return Whether it is set - bool hasProjector() const { return has(); } - - /// Returns the projector (measurement mapping function) for this track - /// state. It is derived from the uncalibrated measurement - /// @warning This function returns the effective projector. This means it - /// is of dimension \f$N\times M\f$, where \f$N\f$ is the actual dimension of the - /// measurement. - /// @return The effective projector - EffectiveProjector effectiveProjector() const { - return projector().topLeftCorner(calibratedSize(), M); - } - - /// Set the projector on this track state - /// This will convert the projector to a more compact bitset representation - /// and store it. - /// @param projector The projector in the form of a dense matrix - /// @note @p projector is assumed to only have 0s or 1s as components. - template - [[deprecated("use setProjector(span) instead")]] void setProjector( - const Eigen::MatrixBase& projector) - requires(!ReadOnly) + /// Set the projector subspace indices + /// @param subspaceIndices The projector subspace indices to set + template + void setProjectorSubspaceIndices(const index_range_t& subspaceIndices) + requires(!ReadOnly && + std::convertible_to, + std::uint8_t>) { - constexpr int rows = Eigen::MatrixBase::RowsAtCompileTime; - constexpr int cols = Eigen::MatrixBase::ColsAtCompileTime; - - static_assert(rows != -1 && cols != -1, - "Assignment of dynamic matrices is currently not supported."); - assert(has()); - - static_assert(rows <= M, "Given projector has too many rows"); - static_assert(cols <= eBoundSize, "Given projector has too many columns"); - - // set up full size projector with only zeros - typename TrackStateProxy::Projector fullProjector = - decltype(fullProjector)::Zero(); - - // assign (potentially) smaller actual projector to matrix, preserving - // zeroes outside of smaller matrix block. - fullProjector.template topLeftCorner() = projector; - - // convert to bitset before storing - ProjectorBitset projectorBitset = matrixToBitset(fullProjector).to_ulong(); - setProjectorBitset(projectorBitset); - } - - /// Directly get the projector bitset, a compressed form of a projection - /// matrix - /// @note This is mainly to copy explicitly a projector from one state - /// to another. Use the `projector` or `effectiveProjector` method if - /// you want to access the matrix. - /// @return The projector bitset - [[deprecated("use projector() instead")]] ProjectorBitset projectorBitset() - const { - return variableBoundSubspaceHelper().projectorBitset(); + assert(subspaceIndices.size() <= eBoundSize); + BoundSubspaceIndices boundSubspace{}; + std::transform(subspaceIndices.begin(), subspaceIndices.end(), + boundSubspace.begin(), + [](auto i) { return static_cast(i); }); + component() = + serializeSubspaceIndices(boundSubspace); } - /// Set the projector bitset, a compressed form of a projection matrix - /// @param proj The projector bitset - /// - /// @note This is mainly to copy explicitly a projector from one state - /// to another. If you have a projection matrix, set it with - /// `setProjector`. - [[deprecated("use setProjector(span) instead")]] void setProjectorBitset( - ProjectorBitset proj) - requires(!ReadOnly) - { - BoundMatrix projMatrix = bitsetToMatrix(proj); - BoundSubspaceIndices boundSubspace = - projectorToSubspaceIndices(projMatrix); - setBoundSubspaceIndices(boundSubspace); - } + /// Returns whether a projector is set + /// @return Whether it is set + bool hasProjector() const { return has(); } - BoundSubspaceIndices boundSubspaceIndices() const { + /// Returns the projector subspace indices + /// @return The projector subspace indices + BoundSubspaceIndices projectorSubspaceIndices() const { assert(has()); return deserializeSubspaceIndices( component()); } + /// Returns the projector subspace indices + /// @return The projector subspace indices template - SubspaceIndices subspaceIndices() const { - BoundSubspaceIndices boundSubspace = BoundSubspaceIndices(); + SubspaceIndices projectorSubspaceIndices() const { + BoundSubspaceIndices boundSubspace = projectorSubspaceIndices(); SubspaceIndices subspace; std::copy(boundSubspace.begin(), boundSubspace.begin() + measdim, subspace.begin()); return subspace; } - void setBoundSubspaceIndices(BoundSubspaceIndices boundSubspace) - requires(!ReadOnly) - { - assert(has()); - component() = - serializeSubspaceIndices(boundSubspace); - } - - template - void setSubspaceIndices(SubspaceIndices subspace) - requires(!ReadOnly && measdim <= eBoundSize) - { - assert(has()); - BoundSubspaceIndices boundSubspace{}; - std::copy(subspace.begin(), subspace.end(), boundSubspace.begin()); - setBoundSubspaceIndices(boundSubspace); - } - - template - void setSubspaceIndices(std::array subspaceIndices) - requires(!ReadOnly && measdim <= eBoundSize) - { - assert(has()); - BoundSubspaceIndices boundSubspace{}; - std::transform(subspaceIndices.begin(), subspaceIndices.end(), - boundSubspace.begin(), - [](index_t i) { return static_cast(i); }); - setBoundSubspaceIndices(boundSubspace); - } - - VariableBoundSubspaceHelper variableBoundSubspaceHelper() const { - BoundSubspaceIndices boundSubspace = boundSubspaceIndices(); + /// Creates a variable size subspace helper + /// @return The subspace helper + VariableBoundSubspaceHelper projectorSubspaceHelper() const { + BoundSubspaceIndices boundSubspace = projectorSubspaceIndices(); std::span validSubspaceIndices( boundSubspace.begin(), boundSubspace.begin() + calibratedSize()); return VariableBoundSubspaceHelper(validSubspaceIndices); } + /// Creates a fixed size subspace helper + /// @return The subspace helper template - FixedBoundSubspaceHelper fixedBoundSubspaceHelper() const { - SubspaceIndices subspace = subspaceIndices(); + FixedBoundSubspaceHelper projectorSubspaceHelper() const { + SubspaceIndices subspace = projectorSubspaceIndices(); return FixedBoundSubspaceHelper(subspace); } @@ -1028,7 +927,7 @@ class TrackStateProxy { other.template calibratedCovariance().eval()); }); - setBoundSubspaceIndices(other.boundSubspaceIndices()); + setProjectorSubspaceIndices(other.projectorSubspaceIndices()); } } else { if (ACTS_CHECK_BIT(mask, PM::Predicted) && @@ -1073,7 +972,7 @@ class TrackStateProxy { other.template calibratedCovariance().eval()); }); - setBoundSubspaceIndices(other.boundSubspaceIndices()); + setProjectorSubspaceIndices(other.projectorSubspaceIndices()); } } diff --git a/Core/include/Acts/EventData/TrackStateProxy.ipp b/Core/include/Acts/EventData/TrackStateProxy.ipp index e36be5f3c25..16abe8fb3aa 100644 --- a/Core/include/Acts/EventData/TrackStateProxy.ipp +++ b/Core/include/Acts/EventData/TrackStateProxy.ipp @@ -61,11 +61,6 @@ inline auto TrackStateProxy::covariance() const } } -template -inline auto TrackStateProxy::projector() const -> Projector { - return variableBoundSubspaceHelper().fullProjector(); -} - template inline auto TrackStateProxy::getUncalibratedSourceLink() const -> SourceLink { diff --git a/Core/include/Acts/EventData/TrackStateProxyConcept.hpp b/Core/include/Acts/EventData/TrackStateProxyConcept.hpp index 61e98adbc48..4b8a713f864 100644 --- a/Core/include/Acts/EventData/TrackStateProxyConcept.hpp +++ b/Core/include/Acts/EventData/TrackStateProxyConcept.hpp @@ -111,12 +111,6 @@ concept TrackStateProxyConcept = { cv.hasProjector() } -> std::same_as; { v.hasProjector() } -> std::same_as; - { cv.effectiveProjector() } -> std::same_as; - { v.effectiveProjector() } -> std::same_as; - - { cv.projectorBitset() } -> std::same_as; - { v.projectorBitset() } -> std::same_as; - { cv.getUncalibratedSourceLink() } -> std::same_as; { v.getUncalibratedSourceLink() } -> std::same_as; diff --git a/Core/include/Acts/EventData/detail/MultiTrajectoryTestsCommon.hpp b/Core/include/Acts/EventData/detail/MultiTrajectoryTestsCommon.hpp index 368138fe38d..7926ca3ba77 100644 --- a/Core/include/Acts/EventData/detail/MultiTrajectoryTestsCommon.hpp +++ b/Core/include/Acts/EventData/detail/MultiTrajectoryTestsCommon.hpp @@ -471,8 +471,8 @@ class MultiTrajectoryTestsCommon { pc.sourceLink.sourceId); // Explicitly unset to avoid error below ts.unset(TrackStatePropMask::Calibrated); - testSourceLinkCalibratorReturn( - gctx, cctx, SourceLink{ttsb.sourceLink}, ts); + testSourceLinkCalibrator(gctx, cctx, + SourceLink{ttsb.sourceLink}, ts); BOOST_CHECK_EQUAL( ts.getUncalibratedSourceLink().template get().sourceId, ttsb.sourceLink.sourceId); @@ -549,21 +549,6 @@ class MultiTrajectoryTestsCommon { BOOST_CHECK_EQUAL(ts.template calibratedCovariance(), expCov); }); } - - BOOST_CHECK(ts.hasProjector()); - ActsMatrix fullProj; - fullProj.setZero(); - { - Acts::GeometryContext gctx; - Acts::CalibrationContext cctx; - // create a temporary measurement to extract the projector matrix - testSourceLinkCalibratorReturn( - gctx, cctx, SourceLink{pc.sourceLink}, ts); - fullProj = ts.projector(); - } - BOOST_CHECK_EQUAL(ts.effectiveProjector(), - fullProj.topLeftCorner(nMeasurements, eBoundSize)); - BOOST_CHECK_EQUAL(ts.projector(), fullProj); } void testTrackStateProxyAllocations(std::default_random_engine& rng) { @@ -782,7 +767,8 @@ class MultiTrajectoryTestsCommon { }); BOOST_CHECK_NE(ts1.calibratedSize(), ts2.calibratedSize()); - BOOST_CHECK_NE(ts1.projector(), ts2.projector()); + BOOST_CHECK(ts1.projectorSubspaceIndices() != + ts2.projectorSubspaceIndices()); BOOST_CHECK_NE(ts1.jacobian(), ts2.jacobian()); BOOST_CHECK_NE(ts1.chi2(), ts2.chi2()); @@ -813,7 +799,8 @@ class MultiTrajectoryTestsCommon { }); BOOST_CHECK_EQUAL(ts1.calibratedSize(), ts2.calibratedSize()); - BOOST_CHECK_EQUAL(ts1.projector(), ts2.projector()); + BOOST_CHECK(ts1.projectorSubspaceIndices() == + ts2.projectorSubspaceIndices()); BOOST_CHECK_EQUAL(ts1.jacobian(), ts2.jacobian()); BOOST_CHECK_EQUAL(ts1.chi2(), ts2.chi2()); @@ -840,7 +827,8 @@ class MultiTrajectoryTestsCommon { }); BOOST_CHECK_NE(ts1.calibratedSize(), ts2.calibratedSize()); - BOOST_CHECK_NE(ts1.projector(), ts2.projector()); + BOOST_CHECK(ts1.projectorSubspaceIndices() != + ts2.projectorSubspaceIndices()); BOOST_CHECK_NE(ts1.jacobian(), ts2.jacobian()); BOOST_CHECK_NE(ts1.chi2(), ts2.chi2()); @@ -864,7 +852,8 @@ class MultiTrajectoryTestsCommon { }); BOOST_CHECK_EQUAL(ts1.calibratedSize(), ts2.calibratedSize()); - BOOST_CHECK_EQUAL(ts1.projector(), ts2.projector()); + BOOST_CHECK(ts1.projectorSubspaceIndices() == + ts2.projectorSubspaceIndices()); BOOST_CHECK_EQUAL(ts1.jacobian(), ts2.jacobian()); BOOST_CHECK_EQUAL(ts1.chi2(), ts2.chi2()); // always copied diff --git a/Core/include/Acts/EventData/detail/TestSourceLink.hpp b/Core/include/Acts/EventData/detail/TestSourceLink.hpp index 4a98b1a28a9..9a6350e7df4 100644 --- a/Core/include/Acts/EventData/detail/TestSourceLink.hpp +++ b/Core/include/Acts/EventData/detail/TestSourceLink.hpp @@ -18,9 +18,7 @@ #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Utilities/CalibrationContext.hpp" -#include #include -#include #include #include #include @@ -126,7 +124,7 @@ inline std::ostream& operator<<(std::ostream& os, /// @param gctx Unused /// @param trackState TrackState to calibrated template -void testSourceLinkCalibratorReturn( +void testSourceLinkCalibrator( const GeometryContext& /*gctx*/, const CalibrationContext& /*cctx*/, const SourceLink& sourceLink, typename trajectory_t::TrackStateProxy trackState) { @@ -139,30 +137,18 @@ void testSourceLinkCalibratorReturn( trackState.allocateCalibrated(2); trackState.template calibrated<2>() = sl.parameters; trackState.template calibratedCovariance<2>() = sl.covariance; - trackState.setSubspaceIndices(std::array{sl.indices[0], sl.indices[1]}); + trackState.setProjectorSubspaceIndices( + std::array{sl.indices[0], sl.indices[1]}); } else if (sl.indices[0] != Acts::eBoundSize) { trackState.allocateCalibrated(1); trackState.template calibrated<1>() = sl.parameters.head<1>(); trackState.template calibratedCovariance<1>() = sl.covariance.topLeftCorner<1, 1>(); - trackState.setSubspaceIndices(std::array{sl.indices[0]}); + trackState.setProjectorSubspaceIndices(std::array{sl.indices[0]}); } else { throw std::runtime_error( "Tried to extract measurement from invalid TestSourceLink"); } } -/// Extract the measurement from a TestSourceLink. -/// -/// @param gctx Unused -/// @param trackState TrackState to calibrated -template -void testSourceLinkCalibrator( - const GeometryContext& gctx, const CalibrationContext& cctx, - const SourceLink& sourceLink, - typename trajectory_t::TrackStateProxy trackState) { - testSourceLinkCalibratorReturn(gctx, cctx, sourceLink, - trackState); -} - } // namespace Acts::detail::Test diff --git a/Core/include/Acts/TrackFinding/MeasurementSelector.ipp b/Core/include/Acts/TrackFinding/MeasurementSelector.ipp index 30d09c002be..5e13ffd904a 100644 --- a/Core/include/Acts/TrackFinding/MeasurementSelector.ipp +++ b/Core/include/Acts/TrackFinding/MeasurementSelector.ipp @@ -63,7 +63,7 @@ MeasurementSelector::select( trackState.effectiveCalibrated().data(), trackState.effectiveCalibratedCovariance().data(), trackState.predicted(), trackState.predictedCovariance(), - trackState.boundSubspaceIndices(), trackState.calibratedSize()); + trackState.projectorSubspaceIndices(), trackState.calibratedSize()); trackState.chi2() = chi2; if (chi2 < minChi2) { diff --git a/Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp b/Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp index cf5b372f487..5adc8340cfe 100644 --- a/Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp +++ b/Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp @@ -10,7 +10,6 @@ #include "Acts/EventData/MultiTrajectory.hpp" #include "Acts/Geometry/GeometryContext.hpp" -#include "Acts/TrackFitting/KalmanFitterError.hpp" #include "Acts/Utilities/Delegate.hpp" #include "Acts/Utilities/Logger.hpp" #include "Acts/Utilities/Result.hpp" diff --git a/Core/include/Acts/TrackFitting/GainMatrixUpdater.hpp b/Core/include/Acts/TrackFitting/GainMatrixUpdater.hpp index 0ac45a79b1d..9d8ae5a0d03 100644 --- a/Core/include/Acts/TrackFitting/GainMatrixUpdater.hpp +++ b/Core/include/Acts/TrackFitting/GainMatrixUpdater.hpp @@ -80,7 +80,7 @@ class GainMatrixUpdater { // shape later trackState.effectiveCalibrated().data(), trackState.effectiveCalibratedCovariance().data(), - trackState.boundSubspaceIndices(), + trackState.projectorSubspaceIndices(), trackState.predicted(), trackState.predictedCovariance(), trackState.filtered(), diff --git a/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp b/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp index eaa9020053d..dc0bc221e9a 100644 --- a/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp +++ b/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp @@ -423,7 +423,7 @@ void addMeasurementToGx2fSums(Gx2fSystem& extendedSystem, trackState.template calibrated(); const ActsMatrix projector = - trackState.projector().template topLeftCorner(); + trackState.template projectorSubspaceHelper().projector(); const Eigen::MatrixXd projJacobian = projector * extendedJacobian; diff --git a/Core/include/Acts/TrackFitting/MbfSmoother.hpp b/Core/include/Acts/TrackFitting/MbfSmoother.hpp index 02066a642e7..be7a8c12311 100644 --- a/Core/include/Acts/TrackFitting/MbfSmoother.hpp +++ b/Core/include/Acts/TrackFitting/MbfSmoother.hpp @@ -87,9 +87,6 @@ class MbfSmoother { /// Internal track state representation for the smoother. /// @note This allows us to move parts of the implementation into the .cpp struct InternalTrackState final { - using Projector = - typename TrackStateTraits::Projector; using Jacobian = typename TrackStateTraits::Covariance; @@ -105,14 +102,14 @@ class MbfSmoother { // This is used to build a covariance matrix view in the .cpp file const double* calibrated{nullptr}; const double* calibratedCovariance{nullptr}; - Projector projector; + BoundSubspaceIndices projector; template explicit Measurement(TrackStateProxy ts) : calibratedSize(ts.calibratedSize()), calibrated(ts.effectiveCalibrated().data()), calibratedCovariance(ts.effectiveCalibratedCovariance().data()), - projector(ts.projector()) {} + projector(ts.projectorSubspaceIndices()) {} }; Jacobian jacobian; diff --git a/Core/include/Acts/TrackFitting/detail/GainMatrixUpdaterImpl.hpp b/Core/include/Acts/TrackFitting/detail/GainMatrixUpdaterImpl.hpp index 0dce3c2ba21..0437ca551a3 100644 --- a/Core/include/Acts/TrackFitting/detail/GainMatrixUpdaterImpl.hpp +++ b/Core/include/Acts/TrackFitting/detail/GainMatrixUpdaterImpl.hpp @@ -35,7 +35,7 @@ std::tuple GainMatrixUpdater::visitMeasurementImpl( ACTS_VERBOSE("Calibrated measurement: " << calibrated.transpose()); ACTS_VERBOSE("Calibrated measurement covariance:\n" << calibratedCovariance); - std::span validSubspaceIndices( + std::span validSubspaceIndices( trackState.projector.begin(), trackState.projector.begin() + kMeasurementSize); FixedBoundSubspaceHelper subspaceHelper( diff --git a/Core/include/Acts/TrackFitting/detail/GsfUtils.hpp b/Core/include/Acts/TrackFitting/detail/GsfUtils.hpp index 98605052bf6..574a69e8f71 100644 --- a/Core/include/Acts/TrackFitting/detail/GsfUtils.hpp +++ b/Core/include/Acts/TrackFitting/detail/GsfUtils.hpp @@ -13,6 +13,7 @@ #include "Acts/EventData/MultiComponentTrackParameters.hpp" #include "Acts/EventData/MultiTrajectory.hpp" #include "Acts/EventData/TrackParameters.hpp" +#include "Acts/EventData/Types.hpp" #include "Acts/Utilities/Logger.hpp" #include @@ -154,9 +155,7 @@ double calculateDeterminant( const double *fullCalibratedCovariance, TrackStateTraits::Covariance predictedCovariance, - TrackStateTraits::Projector - projector, - unsigned int calibratedSize); + BoundSubspaceIndices projector, unsigned int calibratedSize); /// Reweight the components according to `R. Frühwirth, "Track fitting /// with non-Gaussian noise"`. See also the implementation in Athena at @@ -190,7 +189,8 @@ void computePosteriorWeights( .template calibratedCovariance< MultiTrajectoryTraits::MeasurementSizeMax>() .data(), - state.predictedCovariance(), state.projector(), state.calibratedSize()); + state.predictedCovariance(), state.projectorSubspaceIndices(), + state.calibratedSize()); const auto factor = std::sqrt(1. / detR) * safeExp(-0.5 * chi2); diff --git a/Core/include/Acts/Utilities/TrackHelpers.hpp b/Core/include/Acts/Utilities/TrackHelpers.hpp index 2e86a62910d..2e40c6b4988 100644 --- a/Core/include/Acts/Utilities/TrackHelpers.hpp +++ b/Core/include/Acts/Utilities/TrackHelpers.hpp @@ -693,8 +693,11 @@ std::pair calculateUnbiasedParametersCovariance( return visit_measurement( trackState.calibratedSize(), [&](std::integral_constant) { - auto H = trackState.projector() - .template topLeftCorner(); + FixedBoundSubspaceHelper subspaceHelper = + trackState.template projectorSubspaceHelper(); + + // TODO use subspace helper for projection instead + auto H = subspaceHelper.projector(); auto s = trackState.smoothed(); auto C = trackState.smoothedCovariance(); auto m = trackState.template calibrated(); diff --git a/Core/src/TrackFinding/MeasurementSelector.cpp b/Core/src/TrackFinding/MeasurementSelector.cpp index 2a3c0e2d390..676cf8074ff 100644 --- a/Core/src/TrackFinding/MeasurementSelector.cpp +++ b/Core/src/TrackFinding/MeasurementSelector.cpp @@ -9,7 +9,6 @@ #include "Acts/TrackFinding/MeasurementSelector.hpp" #include "Acts/Definitions/Algebra.hpp" -#include "Acts/Definitions/TrackParametrization.hpp" #include "Acts/EventData/MeasurementHelpers.hpp" #include "Acts/EventData/SubspaceHelpers.hpp" #include "Acts/EventData/Types.hpp" @@ -19,6 +18,8 @@ #include #include #include +#include +#include namespace Acts { @@ -99,7 +100,7 @@ double MeasurementSelector::calculateChi2( using ParametersVector = ActsVector; - std::span validSubspaceIndices( + std::span validSubspaceIndices( projector.begin(), projector.begin() + kMeasurementSize); FixedBoundSubspaceHelper subspaceHelper( validSubspaceIndices); diff --git a/Core/src/TrackFitting/GsfUtils.cpp b/Core/src/TrackFitting/GsfUtils.cpp index b70544e47c6..8ff52f2c1b6 100644 --- a/Core/src/TrackFitting/GsfUtils.cpp +++ b/Core/src/TrackFitting/GsfUtils.cpp @@ -9,8 +9,12 @@ #include "Acts/TrackFitting/detail/GsfUtils.hpp" #include "Acts/EventData/MeasurementHelpers.hpp" +#include "Acts/EventData/SubspaceHelpers.hpp" +#include "Acts/EventData/Types.hpp" #include +#include +#include namespace Acts::detail { @@ -19,17 +23,20 @@ using TrackStateTraits = double calculateDeterminant(const double* fullCalibratedCovariance, TrackStateTraits::Covariance predictedCovariance, - TrackStateTraits::Projector projector, + BoundSubspaceIndices projector, unsigned int calibratedSize) { return visit_measurement(calibratedSize, [&](auto N) { constexpr std::size_t kMeasurementSize = decltype(N)::value; + std::span validSubspaceIndices( + projector.begin(), projector.begin() + kMeasurementSize); + FixedBoundSubspaceHelper subspaceHelper( + validSubspaceIndices); typename Acts::TrackStateTraits< kMeasurementSize, true>::CalibratedCovariance calibratedCovariance{ fullCalibratedCovariance}; - const auto H = - projector.template topLeftCorner().eval(); + const auto H = subspaceHelper.projector(); return (H * predictedCovariance * H.transpose() + calibratedCovariance) .determinant(); diff --git a/Core/src/TrackFitting/MbfSmoother.cpp b/Core/src/TrackFitting/MbfSmoother.cpp index e260a578e38..9b300989e90 100644 --- a/Core/src/TrackFitting/MbfSmoother.cpp +++ b/Core/src/TrackFitting/MbfSmoother.cpp @@ -10,6 +10,8 @@ #include "Acts/EventData/TrackParameterHelpers.hpp" +#include + namespace Acts { void MbfSmoother::calculateSmoothed(InternalTrackState& ts, @@ -42,9 +44,13 @@ void MbfSmoother::visitMeasurement(const InternalTrackState& ts, visit_measurement(measurement.calibratedSize, [&](auto N) -> void { constexpr std::size_t kMeasurementSize = decltype(N)::value; + std::span validSubspaceIndices( + measurement.projector.begin(), + measurement.projector.begin() + kMeasurementSize); + FixedBoundSubspaceHelper subspaceHelper( + validSubspaceIndices); - using MeasurementMatrix = - Eigen::Matrix; + using ProjectorMatrix = Eigen::Matrix; using CovarianceMatrix = Eigen::Matrix; using KalmanGainMatrix = @@ -55,10 +61,8 @@ void MbfSmoother::visitMeasurement(const InternalTrackState& ts, typename TrackStateTraits::CalibratedCovariance calibratedCovariance{measurement.calibratedCovariance}; - // Measurement matrix - const MeasurementMatrix H = - measurement.projector - .template topLeftCorner(); + // Projector matrix + const ProjectorMatrix H = subspaceHelper.projector(); // Residual covariance const CovarianceMatrix S = diff --git a/Examples/Algorithms/TrackFitting/src/RefittingCalibrator.cpp b/Examples/Algorithms/TrackFitting/src/RefittingCalibrator.cpp index eaf2f74bffa..154dc5d7285 100644 --- a/Examples/Algorithms/TrackFitting/src/RefittingCalibrator.cpp +++ b/Examples/Algorithms/TrackFitting/src/RefittingCalibrator.cpp @@ -35,7 +35,7 @@ void RefittingCalibrator::calibrate(const Acts::GeometryContext& /*gctx*/, sl.state.template calibratedCovariance().eval()); }); - trackState.setBoundSubspaceIndices(sl.state.boundSubspaceIndices()); + trackState.setProjectorSubspaceIndices(sl.state.projectorSubspaceIndices()); } } // namespace ActsExamples diff --git a/Examples/Framework/ML/src/NeuralCalibrator.cpp b/Examples/Framework/ML/src/NeuralCalibrator.cpp index 83e4d11354e..83c7a2bc09a 100644 --- a/Examples/Framework/ML/src/NeuralCalibrator.cpp +++ b/Examples/Framework/ML/src/NeuralCalibrator.cpp @@ -190,6 +190,6 @@ void ActsExamples::NeuralCalibrator::calibrate( calibratedCovariance(boundLoc1, boundLoc1) = output[iVar0 + 1]; trackState.allocateCalibrated(calibratedParameters, calibratedCovariance); - trackState.setSubspaceIndices(fixedMeasurement.subspaceIndices()); + trackState.setProjectorSubspaceIndices(fixedMeasurement.subspaceIndices()); }); } diff --git a/Examples/Framework/src/EventData/MeasurementCalibration.cpp b/Examples/Framework/src/EventData/MeasurementCalibration.cpp index 190d37153bb..d7b8c96da70 100644 --- a/Examples/Framework/src/EventData/MeasurementCalibration.cpp +++ b/Examples/Framework/src/EventData/MeasurementCalibration.cpp @@ -43,7 +43,7 @@ void ActsExamples::PassThroughCalibrator::calibrate( trackState.allocateCalibrated(fixedMeasurement.parameters().eval(), fixedMeasurement.covariance().eval()); - trackState.setSubspaceIndices(fixedMeasurement.subspaceIndices()); + trackState.setProjectorSubspaceIndices(fixedMeasurement.subspaceIndices()); }); } diff --git a/Examples/Framework/src/EventData/ScalingCalibrator.cpp b/Examples/Framework/src/EventData/ScalingCalibrator.cpp index 2a956902513..50e693e8b15 100644 --- a/Examples/Framework/src/EventData/ScalingCalibrator.cpp +++ b/Examples/Framework/src/EventData/ScalingCalibrator.cpp @@ -179,6 +179,6 @@ void ActsExamples::ScalingCalibrator::calibrate( calibratedCovariance(boundLoc1, boundLoc1) *= ct.y_scale; trackState.allocateCalibrated(calibratedParameters, calibratedCovariance); - trackState.setSubspaceIndices(fixedMeasurement.subspaceIndices()); + trackState.setProjectorSubspaceIndices(fixedMeasurement.subspaceIndices()); }); } diff --git a/Examples/Io/Root/src/RootTrackStatesWriter.cpp b/Examples/Io/Root/src/RootTrackStatesWriter.cpp index f90fa96ab0e..37d7cdf2fc9 100644 --- a/Examples/Io/Root/src/RootTrackStatesWriter.cpp +++ b/Examples/Io/Root/src/RootTrackStatesWriter.cpp @@ -452,8 +452,8 @@ ProcessCode RootTrackStatesWriter::writeT(const AlgorithmContext& ctx, m_t_eT.push_back(static_cast(truthParams[Acts::eBoundTime])); // expand the local measurements into the full bound space - Acts::BoundVector meas = state.effectiveProjector().transpose() * - state.effectiveCalibrated(); + Acts::BoundVector meas = state.projectorSubspaceHelper().expandVector( + state.effectiveCalibrated()); // extract local and global position Acts::Vector2 local(meas[Acts::eBoundLoc0], meas[Acts::eBoundLoc1]); Acts::Vector3 global = @@ -633,7 +633,9 @@ ProcessCode RootTrackStatesWriter::writeT(const AlgorithmContext& ctx, if (ipar == ePredicted) { // local hit residual info - auto H = state.effectiveProjector(); + auto H = + state.projectorSubspaceHelper().fullProjector().topLeftCorner( + state.calibratedSize(), Acts::eBoundSize); auto V = state.effectiveCalibratedCovariance(); auto resCov = V + H * covariance * H.transpose(); Acts::ActsDynamicVector res = diff --git a/Tests/Benchmarks/TrackEdmBenchmark.cpp b/Tests/Benchmarks/TrackEdmBenchmark.cpp index a85b0482be2..ce14eef8e8a 100644 --- a/Tests/Benchmarks/TrackEdmBenchmark.cpp +++ b/Tests/Benchmarks/TrackEdmBenchmark.cpp @@ -149,7 +149,7 @@ int main(int /*argc*/, char** /*argv[]*/) { std::array indices{0}; std::iota(indices.begin(), indices.end(), 0); - trackState.setBoundSubspaceIndices(indices); + trackState.setProjectorSubspaceIndices(indices); }); trackState.typeFlags().set(TrackStateFlag::MeasurementFlag); diff --git a/Tests/UnitTests/Core/EventData/TrackTestsExtra.cpp b/Tests/UnitTests/Core/EventData/TrackTestsExtra.cpp index f2f27ed8522..ecf49d7cd5b 100644 --- a/Tests/UnitTests/Core/EventData/TrackTestsExtra.cpp +++ b/Tests/UnitTests/Core/EventData/TrackTestsExtra.cpp @@ -457,7 +457,7 @@ BOOST_AUTO_TEST_CASE(CopyTrackProxyCalibrated) { auto track1 = tc.makeTrack(); auto ts = track1.appendTrackState(TrackStatePropMask::Calibrated); ts.allocateCalibrated(kMeasurementSize); - ts.setSubspaceIndices(BoundSubspaceIndices{}); + ts.setProjectorSubspaceIndices(BoundSubspaceIndices{}); auto tsCopy = track1.appendTrackState(TrackStatePropMask::Calibrated); tsCopy.copyFrom(ts, TrackStatePropMask::Calibrated, false); diff --git a/Tests/UnitTests/Core/TrackFitting/FitterTestsCommon.hpp b/Tests/UnitTests/Core/TrackFitting/FitterTestsCommon.hpp index 269370d4fc4..dca8ac045ca 100644 --- a/Tests/UnitTests/Core/TrackFitting/FitterTestsCommon.hpp +++ b/Tests/UnitTests/Core/TrackFitting/FitterTestsCommon.hpp @@ -10,6 +10,7 @@ #include +#include "Acts/Definitions/TrackParametrization.hpp" #include "Acts/Definitions/Units.hpp" #include "Acts/EventData/MultiTrajectory.hpp" #include "Acts/EventData/ProxyAccessor.hpp" @@ -56,9 +57,13 @@ struct TestOutlierFinder { if (!state.hasCalibrated() || !state.hasPredicted()) { return false; } - auto residuals = (state.effectiveCalibrated() - - state.effectiveProjector() * state.predicted()) - .eval(); + auto subspaceHelper = state.projectorSubspaceHelper(); + auto projector = + subspaceHelper.fullProjector() + .topLeftCorner(state.calibratedSize(), Acts::eBoundSize) + .eval(); + auto residuals = + (state.effectiveCalibrated() - projector * state.predicted()).eval(); auto distance = residuals.norm(); return (distanceMax <= distance); } diff --git a/Tests/UnitTests/Core/TrackFitting/MbfSmootherTests.cpp b/Tests/UnitTests/Core/TrackFitting/MbfSmootherTests.cpp index 21d0a347e56..e87d386b5b5 100644 --- a/Tests/UnitTests/Core/TrackFitting/MbfSmootherTests.cpp +++ b/Tests/UnitTests/Core/TrackFitting/MbfSmootherTests.cpp @@ -8,9 +8,7 @@ #include -#include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/TrackParametrization.hpp" -#include "Acts/EventData/MultiTrajectory.hpp" #include "Acts/EventData/TrackStatePropMask.hpp" #include "Acts/EventData/TrackStateType.hpp" #include "Acts/EventData/VectorMultiTrajectory.hpp" @@ -19,7 +17,6 @@ #include "Acts/TrackFitting/MbfSmoother.hpp" #include "Acts/Utilities/Result.hpp" -#include #include #include @@ -59,7 +56,7 @@ BOOST_AUTO_TEST_CASE(Smooth) { ts.allocateCalibrated(2); ts.calibrated<2>() << 0.351, 0.473; ts.calibratedCovariance<2>() << 1e+8, 0., 0., 1e+8; - ts.setSubspaceIndices<2>(projector); + ts.setProjectorSubspaceIndices(projector); ts.filtered() << 0.301, 0.503, std::numbers::pi / 2., 0., 1 / 100., 0.; ts.filteredCovariance() = covTrk; @@ -76,7 +73,7 @@ BOOST_AUTO_TEST_CASE(Smooth) { ts.allocateCalibrated(2); ts.calibrated<2>() << 0.351, 0.473; ts.calibratedCovariance<2>() << 1e+8, 0., 0., 1e+8; - ts.setSubspaceIndices<2>(projector); + ts.setProjectorSubspaceIndices(projector); ts.filtered() << 0.27, 0.53, std::numbers::pi / 2., 0., 1 / 100., 0.; ts.filteredCovariance() = covTrk; @@ -93,7 +90,7 @@ BOOST_AUTO_TEST_CASE(Smooth) { ts.allocateCalibrated(2); ts.calibrated<2>() << 0.351, 0.473; ts.calibratedCovariance<2>() << 1e+8, 0., 0., 1e+8; - ts.setSubspaceIndices<2>(projector); + ts.setProjectorSubspaceIndices(projector); ts.filtered() << 0.33, 0.43, std::numbers::pi / 2., 0., 1 / 100., 0.; ts.filteredCovariance() = covTrk;