Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:42:23

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   /// @return Success or failure of the update procedure with chi2 information
0051   template <typename traj_t>
0052   Result<void> operator()(const GeometryContext& /*gctx*/,
0053                           typename traj_t::TrackStateProxy trackState,
0054                           const Logger& logger = getDummyLogger()) const {
0055     ACTS_VERBOSE("Invoked GainMatrixUpdater");
0056 
0057     // there should be a calibrated measurement
0058     assert(trackState.hasCalibrated());
0059     // we should have predicted state set
0060     assert(trackState.hasPredicted());
0061     // filtering should not have happened yet, but is allocated, therefore set
0062     assert(trackState.hasFiltered());
0063 
0064     // read-only handles. Types are eigen maps to backing storage
0065     // const auto predicted = trackState.predicted();
0066     // const auto predictedCovariance = trackState.predictedCovariance();
0067 
0068     ACTS_VERBOSE(
0069         "Predicted parameters: " << trackState.predicted().transpose());
0070     ACTS_VERBOSE("Predicted covariance:\n" << trackState.predictedCovariance());
0071 
0072     // read-write handles. Types are eigen maps into backing storage.
0073     // This writes directly into the trajectory storage
0074     // auto filtered = trackState.filtered();
0075     // auto filteredCovariance = trackState.filteredCovariance();
0076 
0077     auto [chi2, error] = visitMeasurement(
0078         InternalTrackState{
0079             trackState.calibratedSize(),
0080             // Note that we pass raw pointers here which are used in the correct
0081             // shape later
0082             trackState.effectiveCalibrated().data(),
0083             trackState.effectiveCalibratedCovariance().data(),
0084             trackState.projectorSubspaceIndices(),
0085             trackState.predicted(),
0086             trackState.predictedCovariance(),
0087             trackState.filtered(),
0088             trackState.filteredCovariance(),
0089         },
0090         logger);
0091 
0092     trackState.chi2() = chi2;
0093 
0094     return error ? Result<void>::failure(error) : Result<void>::success();
0095   }
0096 
0097  private:
0098   std::tuple<double, std::error_code> visitMeasurement(
0099       InternalTrackState trackState, const Logger& logger) const;
0100 
0101   template <std::size_t N>
0102   std::tuple<double, std::error_code> visitMeasurementImpl(
0103       InternalTrackState trackState, const Logger& logger) const;
0104 };
0105 
0106 }  // namespace Acts