Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:18

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "Acts/Utilities/detail/periodic.hpp"
0013 
0014 #include <cassert>
0015 
0016 #include <Eigen/Core>
0017 
0018 namespace Acts::detail {
0019 
0020 /// Residuals between bound reference parameters and a measured subspace.
0021 ///
0022 /// @tparam index_container_t SequenceContainer for measured indices
0023 /// @tparam measured_t Measured parameters vector type
0024 /// @tparam residuals_t Residuals vector type
0025 /// @param[in] size Size of the measured parameters subspace
0026 /// @param[in] indices Indices of measured subspace, must have `size` entries
0027 /// @param[in] reference Reference bound parameters
0028 /// @param[in] measured Measured parameters subspace
0029 /// @param[out] residuals Resulting residuals in the measured subspace
0030 ///
0031 /// @note The separate `size` parameter is also used to allow the selection of
0032 ///   the correct residuals methods depending on the parameters type.
0033 template <typename index_container_t, typename measured_t, typename residuals_t>
0034 inline void calculateResiduals(BoundIndices size,
0035                                const index_container_t& indices,
0036                                const BoundVector& reference,
0037                                const Eigen::MatrixBase<measured_t>& measured,
0038                                Eigen::MatrixBase<residuals_t>& residuals) {
0039   using OutputScalar = typename residuals_t::Scalar;
0040 
0041   EIGEN_STATIC_ASSERT_VECTOR_ONLY(measured_t);
0042   EIGEN_STATIC_ASSERT_VECTOR_ONLY(residuals_t);
0043   assert((size <= eBoundSize) && "Measured subspace is too large");
0044   assert((size <= measured.size()) && "Inconsistent measured size");
0045   assert((size <= residuals.size()) && "Inconsistent residuals size");
0046 
0047   for (std::size_t i = 0; i < size; ++i) {
0048     std::size_t fullIndex = indices[i];
0049     // this is neither elegant nor smart but it is the simplest solution.
0050     //
0051     // only phi must be handled specially here. the theta limits can only be
0052     // correctly handled if phi is updated, too. since we can not ensure that
0053     // both are available, it is probably less error-prone to treat theta as a
0054     // regular, unrestricted parameter.
0055     if (fullIndex == eBoundPhi) {
0056       residuals[i] = difference_periodic<OutputScalar>(
0057           measured[i], reference[fullIndex],
0058           static_cast<OutputScalar>(2 * M_PI));
0059     } else {
0060       residuals[i] = measured[i] - reference[fullIndex];
0061     }
0062   }
0063 }
0064 
0065 /// Residuals between free reference parameters and a measured subspace.
0066 ///
0067 /// @tparam index_container_t SequenceContainer for measured inidices
0068 /// @tparam measured_t Measured parameters vector type
0069 /// @tparam residuals_t Residuals vector type
0070 /// @param[in] size Size of the measured parameters subspace
0071 /// @param[in] indices Indices of measured subspace, must have `size` entries
0072 /// @param[in] reference Reference free parameters
0073 /// @param[in] measured Measured parameters subspace
0074 /// @param[out] residuals Resulting residuals in the measured subspace
0075 ///
0076 /// @note The separate `size` parameter is also used to allow the selection of
0077 ///   the correct residuals methods depending on the parameters type.
0078 template <typename index_container_t, typename measured_t, typename residuals_t>
0079 inline void calculateResiduals(FreeIndices size,
0080                                const index_container_t& indices,
0081                                const FreeVector& reference,
0082                                const Eigen::MatrixBase<measured_t>& measured,
0083                                Eigen::MatrixBase<residuals_t>& residuals) {
0084   EIGEN_STATIC_ASSERT_VECTOR_ONLY(measured_t);
0085   EIGEN_STATIC_ASSERT_VECTOR_ONLY(residuals_t);
0086   assert((size <= eFreeSize) && "Measured subspace is too large");
0087   assert((size <= measured.size()) && "Inconsistent measured size");
0088   assert((size <= residuals.size()) && "Inconsistent residuals size");
0089 
0090   for (std::size_t i = 0; i < size; ++i) {
0091     // all free parameters are unrestricted. no need to call parameter traits
0092     residuals[i] = measured[i] - reference[indices[i]];
0093   }
0094 }
0095 
0096 }  // namespace Acts::detail