Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:06

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/EventData/MeasurementHelpers.hpp"
0012 #include "Acts/EventData/MultiTrajectory.hpp"
0013 #include "Acts/EventData/Types.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/TrackFitting/KalmanFitterError.hpp"
0016 #include "Acts/Utilities/Logger.hpp"
0017 #include "Acts/Utilities/Result.hpp"
0018 
0019 #include <cassert>
0020 #include <system_error>
0021 #include <tuple>
0022 
0023 namespace Acts {
0024 
0025 /// Kalman update step using the gain matrix formalism.
0026 class GainMatrixUpdater {
0027   struct InternalTrackState {
0028     unsigned int calibratedSize;
0029     // This is used to build a covariance matrix view in the .cpp file
0030     const double* calibrated;
0031     const double* calibratedCovariance;
0032     BoundSubspaceIndices projector;
0033 
0034     TrackStateTraits<MultiTrajectoryTraits::MeasurementSizeMax,
0035                      false>::Parameters predicted;
0036     TrackStateTraits<MultiTrajectoryTraits::MeasurementSizeMax,
0037                      false>::Covariance predictedCovariance;
0038     TrackStateTraits<MultiTrajectoryTraits::MeasurementSizeMax,
0039                      false>::Parameters filtered;
0040     TrackStateTraits<MultiTrajectoryTraits::MeasurementSizeMax,
0041                      false>::Covariance filteredCovariance;
0042   };
0043 
0044  public:
0045   /// Run the Kalman update step for a single trajectory state.
0046   ///
0047   /// @tparam kMeasurementSizeMax
0048   /// @param[in,out] trackState The track state
0049   /// @param[in] logger Where to write logging information to
0050   template <typename traj_t>
0051   Result<void> operator()(const GeometryContext& /*gctx*/,
0052                           typename traj_t::TrackStateProxy trackState,
0053                           const Logger& logger = getDummyLogger()) const {
0054     ACTS_VERBOSE("Invoked GainMatrixUpdater");
0055 
0056     // there should be a calibrated measurement
0057     assert(trackState.hasCalibrated());
0058     // we should have predicted state set
0059     assert(trackState.hasPredicted());
0060     // filtering should not have happened yet, but is allocated, therefore set
0061     assert(trackState.hasFiltered());
0062 
0063     // read-only handles. Types are eigen maps to backing storage
0064     // const auto predicted = trackState.predicted();
0065     // const auto predictedCovariance = trackState.predictedCovariance();
0066 
0067     ACTS_VERBOSE(
0068         "Predicted parameters: " << trackState.predicted().transpose());
0069     ACTS_VERBOSE("Predicted covariance:\n" << trackState.predictedCovariance());
0070 
0071     // read-write handles. Types are eigen maps into backing storage.
0072     // This writes directly into the trajectory storage
0073     // auto filtered = trackState.filtered();
0074     // auto filteredCovariance = trackState.filteredCovariance();
0075 
0076     auto [chi2, error] = visitMeasurement(
0077         InternalTrackState{
0078             trackState.calibratedSize(),
0079             // Note that we pass raw pointers here which are used in the correct
0080             // shape later
0081             trackState.effectiveCalibrated().data(),
0082             trackState.effectiveCalibratedCovariance().data(),
0083             trackState.projectorSubspaceIndices(),
0084             trackState.predicted(),
0085             trackState.predictedCovariance(),
0086             trackState.filtered(),
0087             trackState.filteredCovariance(),
0088         },
0089         logger);
0090 
0091     trackState.chi2() = chi2;
0092 
0093     return error ? Result<void>::failure(error) : Result<void>::success();
0094   }
0095 
0096  private:
0097   std::tuple<double, std::error_code> visitMeasurement(
0098       InternalTrackState trackState, const Logger& logger) const;
0099 
0100   template <std::size_t N>
0101   std::tuple<double, std::error_code> visitMeasurementImpl(
0102       InternalTrackState trackState, const Logger& logger) const;
0103 };
0104 
0105 }  // namespace Acts