![]() |
|
|||
File indexing completed on 2025-08-05 08:08:11
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/CompositeSpacePoint.hpp" 0012 #include "Acts/Utilities/ArrayHelpers.hpp" 0013 #include "Acts/Utilities/Logger.hpp" 0014 #include "Acts/Utilities/detail/Line3DWithPartialDerivatives.hpp" 0015 0016 #include <cstdint> 0017 0018 namespace Acts::Experimental::detail { 0019 /// @brief Helper class to calculate the residual between a straight line and 0020 /// a CompositeSpacePoint measurement as well as the partial derivatives. 0021 /// The residual is expressed as a 3D vector, where first two components 0022 /// describe the spatial residual w.r.t. the precision & non-precision 0023 /// direction, and the last one expresses the residual between the 0024 /// parametrized time of arrival of the track and the measurement's 0025 /// recorded time. 0026 /// 0027 /// For straw type measurements, the precision residual is calculated as 0028 /// the difference between the signed line distance between straw wire & 0029 /// line, and the signed drift radius where the sign simply encodes the 0030 /// left/right amibiguity. If the measurement additionally carries 0031 /// information about the passage along the wire, the non-precision 0032 /// residual is then defined to be the distance along the wire. 0033 /// 0034 /// For strip type measurements, the residual is the distance in the 0035 /// strip-readout plane between the point along the line that intersects 0036 /// the plane and the measurement. 0037 class StrawLineFitAuxiliaries { 0038 public: 0039 using Line_t = Acts::detail::Line3DWithPartialDerivatives<double>; 0040 using LineIndex = Line_t::ParIndex; 0041 using Vector = Line_t::Vector; 0042 enum class FitParIndex : std::uint8_t { 0043 x0 = static_cast<std::uint8_t>(LineIndex::x0), 0044 y0 = static_cast<std::uint8_t>(LineIndex::y0), 0045 theta = static_cast<std::uint8_t>(LineIndex::theta), 0046 phi = static_cast<std::uint8_t>(LineIndex::phi), 0047 t0 = 4, // time offset 0048 nPars = 5 0049 }; 0050 static std::string parName(const FitParIndex idx); 0051 /// @brief Assignment of the residual components. 0052 enum ResidualIdx : std::uint8_t { nonBending = 0, bending = 1, time = 2 }; 0053 /// @brief Configuration object of the residual calculator 0054 struct Config { 0055 /// @brief Flag toggling whether the hessian of the residual shall be calculated 0056 bool useHessian{false}; 0057 /// @brief Flag toggling whether the along the wire component of straws shall be calculated 0058 /// if provided by the straw measurement. 0059 bool calcAlongStraw{true}; 0060 /// @brief Flag toggling whether the residual along the strip direction 0061 /// shall be calculated if the space point does not measure both 0062 /// spatial coordinates on the plane 0063 bool calcAlongStrip{true}; 0064 /// @brief List of fit parameters to which the partial derivative of the 0065 /// residual shall be calculated 0066 std::vector<FitParIndex> parsToUse{FitParIndex::x0, FitParIndex::y0, 0067 FitParIndex::theta, FitParIndex::phi}; 0068 }; 0069 /// @brief Constructor to instantiate a new instance 0070 /// @param cfg: Configuration object to toggle the calculation of the complementary residual components & the full evaluation of the second derivative 0071 /// @param logger: New logging object for debugging 0072 explicit StrawLineFitAuxiliaries( 0073 const Config& cfg, 0074 std::unique_ptr<const Logger> logger = 0075 getDefaultLogger("StrawLineFitAuxiliaries", Logging::Level::INFO)); 0076 0077 /// @brief Updates the spatial residual components between the line and the passed 0078 /// measurement. The result is cached internally and can be later 0079 /// fetched by the residual(), gradient() and hessian() methods. If the 0080 /// residual calculation fails due to parallel line & measurement, all 0081 /// components are set to zero. 0082 /// @param line: Reference to the line to which the residual is calculated 0083 /// @param spacePoint: Reference to the space point measurement to which the residual is calculated 0084 template <CompositeSpacePoint Point_t> 0085 void updateSpatialResidual(const Line_t& line, const Point_t& spacePoint); 0086 0087 /// @brief Returns the previously calculated residual. 0088 const Vector& residual() const; 0089 /// @brief Returns the gradient of the previously calculated residual 0090 /// @param par: Index of the partiald derivative 0091 const Vector& gradient(const FitParIndex param) const; 0092 /// @brief Returns the gradient of the previously calculated residual 0093 /// @param param1: First index of the second partial derivative 0094 /// @param param2: Second index of the second partial derivative 0095 const Vector& hessian(const FitParIndex param1, 0096 const FitParIndex param2) const; 0097 0098 /// @brief Returns whether the passed parameter describes a direction angle 0099 static constexpr bool isDirectionParam(const FitParIndex param) { 0100 return param == FitParIndex::theta || param == FitParIndex::phi; 0101 } 0102 /// @brief Returns whether the passed parameter describes the displacement 0103 /// in the reference plane 0104 static constexpr bool isPositionParam(const FitParIndex param) { 0105 return param == FitParIndex::x0 || param == FitParIndex::y0; 0106 } 0107 /// @brief Calculate whether the track passed on the left (-1) or the right (1) side 0108 /// of the straw wire. Returns 0 for strips 0109 /// @param line: Reference to the 0110 /// @param strawSp: Straw measurement of interest 0111 template <CompositeSpacePoint Point_t> 0112 static int strawSign(const Line_t& line, const Point_t& strawSp); 0113 0114 private: 0115 /// @brief Reference to the logging object 0116 const Logger& logger() const { return *m_logger; } 0117 /// @brief Update the auxiliary variables needed to calculate the residuals 0118 /// of a straw measurement to the current line. They are the 0119 /// projection of the line direction vector into the straw's wire 0120 /// plane and its derivatives. Returns fals if line and wire are 0121 /// parallel to each other 0122 /// @param line: Reference to the line to project 0123 /// @param wireDir: Reference to the straw wire direction vector 0124 bool updateStrawAuxiliaries(const Line_t& line, const Vector& wireDir); 0125 /// @brief Updates the residuals of a straw measurement to a line ignoring 0126 /// the distance along the straw wire. Returns false if the residual 0127 /// cannot be updated due to parallelism between straw wire and line 0128 /// @param line: Reference to the line to which the residual is calculated 0129 /// @param hitMinSeg: Difference of the line reference point & the straw 0130 /// position 0131 /// @param wireDir: Direction vector of the straw wire 0132 /// @param driftRadius: Measured radius of the straw measurement 0133 bool updateStrawResidual(const Line_t& line, const Vector& hitMinSeg, 0134 const Vector& wireDir, const double driftRadius); 0135 /// @brief Calculates the along-the wire component of the straw 0136 /// measurement's residual to the line 0137 /// @param line: Reference to the line to which the residual is calculated 0138 /// @param hitMinSeg: Difference of the line reference point & the straw 0139 /// position 0140 /// @param wireDir: Direction vector of the straw wire 0141 void updateAlongTheStraw(const Line_t& line, const Vector& hitMinSeg, 0142 const Vector& wireDir); 0143 /// @brief Calculates the residual of a strip measurement w.r.t. the line 0144 /// @param line: Reference to the line to which the residual is calculated 0145 /// @param normal: Reference to the vector normal on the strip measurement plane 0146 /// @param sensorN: Reference to the first basis vector inside the strip measruement plane, 0147 /// which is given by the sensor normal 0148 /// @param sensorD: Reference to the second basis vector inside the strip measruement plane, 0149 /// which is given by the sensor direction 0150 /// @param stripPos: Position of the strip measurement 0151 /// @param isBending: Flag toggling whether the precision direction is constrained 0152 /// @param isNonBending: Flag toggling whether the non-precision direction is constrained 0153 void updateStripResidual(const Line_t& line, const Vector& normal, 0154 const Vector& sensorN, const Vector& sensorD, 0155 const Vector& stripPos, const bool isBending, 0156 const bool isNonBending); 0157 /// @brief Resets the residual and all partial derivatives to zero. 0158 void reset(); 0159 Config m_cfg{}; 0160 std::unique_ptr<const Logger> m_logger{}; 0161 0162 /// @brief Cached residual vector calculated from the measurement & the parametrized line 0163 Vector m_residual{Vector::Zero()}; 0164 /// @brief Partial derivatives of the residual w.r.t. the fit parameters parameters 0165 static constexpr std::uint8_t s_nPars = 0166 static_cast<std::uint8_t>(FitParIndex::nPars); 0167 std::array<Vector3, s_nPars> m_gradient{ 0168 filledArray<Vector3, s_nPars>(Vector3::Zero())}; 0169 /// @brief Second partial derivatives of the residual w.r.t. the fit parameters parameters 0170 std::array<Vector3, sumUpToN(s_nPars)> m_hessian{ 0171 filledArray<Vector3, sumUpToN(s_nPars)>(Vector3::Zero())}; 0172 0173 // Auxiliary parameters needed to calculate the residual of the 0174 // point of closest approach and its derivatives 0175 0176 /// @brief Number of spatial line parameters 0177 static constexpr std::uint8_t s_nLinePars = Line_t::s_nPars; 0178 /// @brief projection of the segment direction onto the wire planes 0179 Vector m_projDir{Vector::Zero()}; 0180 0181 /// @brief Partial derivatives of the dir projection w.r.t. line parameters 0182 std::array<Vector, s_nLinePars> m_gradProjDir{ 0183 filledArray<Vector, s_nLinePars>(Vector::Zero())}; 0184 /// @brief Component of the direction vector parallel to the wire 0185 double m_wireProject{1.}; 0186 /// @brief Length squared of the projected direction 0187 double m_invProjDirLenSq{0.}; 0188 /// @brief Inverse of the projected direction length 0189 double m_invProjDirLen{0.}; 0190 /// @brief Partial derivatives of the dir projection lengths w.r.t line parameters 0191 std::array<double, s_nLinePars> m_projDirLenPartial{ 0192 filledArray<double, s_nLinePars>(0.)}; 0193 0194 std::array<Vector, sumUpToN(s_nLinePars)> m_hessianProjDir{ 0195 filledArray<Vector, sumUpToN(s_nLinePars)>(Vector::Zero())}; 0196 /// Transform matrix to treat stereo angles amongst the strips 0197 ActsSquareMatrix<2> m_stereoTrf{ActsSquareMatrix<2>::Identity()}; 0198 }; 0199 0200 } // namespace Acts::Experimental::detail 0201 #include "Acts/Seeding/detail/StrawLineFitAuxiliaries.ipp"
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |