|
||||
File indexing completed on 2025-01-18 09:11:14
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/Definitions/Algebra.hpp" 0012 #include "Acts/Definitions/Units.hpp" 0013 #include "Acts/Utilities/Logger.hpp" 0014 #include "Acts/Utilities/Ray.hpp" 0015 #include "Acts/Utilities/Result.hpp" 0016 #include "Acts/Utilities/detail/periodic.hpp" 0017 0018 #include <algorithm> 0019 #include <string> 0020 #include <utility> 0021 #include <vector> 0022 0023 namespace Acts { 0024 0025 /// @class SingleSeedVertexFinder 0026 /// 0027 /// @brief Implements the vertex finder based on the track seeds 0028 /// 0. Assumes there is only 1 vertex and that it has a high multiplicity 0029 /// 1. Sorts out all the input spacepoints based on their distance to the z-axis 0030 /// 2. Create seeds from 3 spacepoints with a small deviation from a straigh 0031 /// line 0032 /// 3. Find a point with a minimal distance from either planes 0033 /// (minimalizeWRT="planes") or rays (minimalizeWRT="rays") defined by the seeds 0034 /// 4. Returns the point position as the vertex 0035 template <typename spacepoint_t> 0036 class SingleSeedVertexFinder { 0037 public: 0038 /// Configuration struct 0039 struct Config { 0040 /// maximum deviation in phi between the near and middle spacepoints or 0041 /// middle and far spacepoints 0042 double maxPhideviation = 0.08; 0043 /// maximum deviation in X-Y between the first 2 spacepoints and the last 2 0044 /// spacepoints 0045 double maxXYdeviation = 0.08; 0046 /// maximum deviation in 3D between the first 2 spacepoints and the last 2 0047 /// spacepoints 0048 double maxXYZdeviation = 0.08; 0049 0050 /// minimum angle between Z axis and a triplet, effectively removing 0051 /// triplets with large |eta| 0052 double minTheta = 1.; 0053 0054 /// thresholds for near, middle, and far spacepoints 0055 double rMinNear = 20.f * Acts::UnitConstants::mm; 0056 double rMaxNear = 60.f * Acts::UnitConstants::mm; 0057 double rMinMiddle = 150.f * Acts::UnitConstants::mm; 0058 double rMaxMiddle = 190.f * Acts::UnitConstants::mm; 0059 double rMinFar = 280.f * Acts::UnitConstants::mm; 0060 double rMaxFar = 320.f * Acts::UnitConstants::mm; 0061 0062 /// number of phi slices, at least 3 to avoid duplicities 0063 /// it should be less than 2*pi/maxPhideviation in order not to loop over 0064 /// triplets that will be rejected by maxPhideviation anyway 0065 std::uint32_t numPhiSlices = 60; 0066 /// use only a fraction of available phi slices to speed up calculations; 0067 double useFracPhiSlices = 0.5; 0068 0069 /// number of z slices 0070 std::uint32_t numZSlices = 150; 0071 /// use only a fraction of available z slices to speed up calculations; 0072 double useFracZSlices = 0.5; 0073 /// maximum |z| to consider, z slices will be done within the range 0074 /// (-maxAbsZ,maxAbsZ) 0075 /// values of maxAbsZ, maxZPosition, rMaxFar, and minTheta should be 0076 /// set reasonably with respect to each other 0077 double maxAbsZ = 450. * Acts::UnitConstants::mm; 0078 0079 /// maximum Z position of the vertex at the point closest to the Z axis 0080 double maxZPosition = 200.f * Acts::UnitConstants::mm; 0081 /// maximum R position of the vertex at the point closest to the Z axis 0082 double maxRPosition = 10.f * Acts::UnitConstants::mm; 0083 0084 /// chi^2 minimalization will happen with respect to "planes" or "rays" 0085 std::string minimalizeWRT = "planes"; 0086 0087 /// maximum number of iterations when discarding triplets with the largest 0088 /// chi^2 0089 std::uint32_t maxIterations = 20; 0090 /// each iteration, discard this fraction of triplets with the largest chi^2 0091 double removeFraction = 0.10; 0092 /// if the vertex estimation moves less than this, stop iterations 0093 double minVtxShift = 0.3f * Acts::UnitConstants::mm; 0094 }; 0095 0096 /// Const access to the config 0097 const Config& config() const { return m_cfg; } 0098 0099 /// @brief Constructor 0100 /// @param cfg Configuration object 0101 /// @param lgr Logging instance 0102 SingleSeedVertexFinder(const Config& cfg, 0103 std::unique_ptr<const Logger> lgr = getDefaultLogger( 0104 "SingleSeedVertexFinder", Logging::INFO)); 0105 0106 /// @brief Destructor 0107 ~SingleSeedVertexFinder() = default; 0108 0109 /// @brief Finds the vertex based on the provided spacepoints 0110 /// @param spacepoints Vector of the input spacepoints; they do not need to be sorted anyhow 0111 /// @return Position of the vertex 0112 Acts::Result<Acts::Vector3> findVertex( 0113 const std::vector<spacepoint_t>& spacepoints) const; 0114 0115 private: 0116 /// @brief Struct to store spacepoint combinations from near, middle, and far parts of the detector. Also stores straight line fit through the spacepoints in case minimalizeWRT=="rays", so it's not fitted twice 0117 struct Triplet { 0118 Triplet(const spacepoint_t& aa, const spacepoint_t& bb, 0119 const spacepoint_t& cc) 0120 : a(aa), b(bb), c(cc), ray(Acts::Vector3::Zero(), {1., 1., 1.}) {} 0121 0122 const spacepoint_t &a, &b, &c; 0123 Acts::Ray3D ray; 0124 }; 0125 0126 /// @brief Struct to store sorted spacepoints for each layer (near, middle, and far), for each slice of phi, and for each slice of z 0127 struct SortedSpacepoints { 0128 SortedSpacepoints(const int phiSize, const int zSize) { 0129 std::vector<std::pair<spacepoint_t const*, double>> helper = {}; 0130 std::vector<std::vector<std::pair<spacepoint_t const*, double>>> helperZ( 0131 zSize, helper); 0132 std::vector< 0133 std::vector<std::vector<std::pair<spacepoint_t const*, double>>>> 0134 helperPhi(phiSize, helperZ); 0135 sortedSP.fill(helperPhi); 0136 } 0137 0138 /// @brief Provides non-const vector of spacepoints for a given layer, phi slice, and z slice 0139 /// @param layer Index of the layer (near=0, middle=1, far=2) 0140 /// @param phi Index of the phi slice 0141 /// @param z Index of the z slice 0142 /// @return Non-const vector of spacepoints 0143 inline std::vector<std::pair<spacepoint_t const*, double>>& addSP(int layer, 0144 int phi, 0145 int z) { 0146 return sortedSP[layer][phi][z]; 0147 } 0148 0149 /// @brief Provides const vector of spacepoints for a given layer, phi slice, and z slice 0150 /// @param layer Index of the layer (near=0, middle=1, far=2) 0151 /// @param phi Index of the phi slice 0152 /// @param z Index of the z slice 0153 /// @return Const vector of spacepoints 0154 inline const std::vector<std::pair<spacepoint_t const*, double>>& getSP( 0155 int layer, int phi, int z) const { 0156 return sortedSP[layer][phi][z]; 0157 } 0158 0159 std::array<std::vector<std::vector< 0160 std::vector<std::pair<spacepoint_t const*, double>>>>, 0161 3> 0162 sortedSP; 0163 }; 0164 0165 /// Configuration instance 0166 Config m_cfg; 0167 0168 /// @brief Sorts spacepoints into a separate vectors for near, middle, and far spacepoints; for each slice of phi; and for each slice of z 0169 /// @param spacepoints Vector of the input spacepoints; 0170 /// @return Struct of the sorted spacepoints 0171 Acts::SingleSeedVertexFinder<spacepoint_t>::SortedSpacepoints sortSpacepoints( 0172 const std::vector<spacepoint_t>& spacepoints) const; 0173 0174 /// @brief Makes triplets from the provided vectors of near, middle, and far spacepoints; for each slice of phi; and for each slice of z 0175 /// @param sortedSpacepoints Struct of the sorted spacepointss 0176 /// @return Vector of valid triplets 0177 std::vector<Triplet> findTriplets( 0178 const Acts::SingleSeedVertexFinder<spacepoint_t>::SortedSpacepoints& 0179 sortedSpacepoints) const; 0180 0181 /// @brief Validate the triplet based on "maxXYdeviation", "maxXYZdeviation", "maxZPosition", and "maxRPosition" 0182 /// @param triplet A single triplet to be validated 0183 /// @return True if the deviations and fitted ray are within the configured ranges 0184 /// If "minimalizeWRT"=="rays", then the fitted ray is also saved to 0185 /// the triplet for later 0186 bool tripletValidationAndUpdate(Triplet& triplet) const; 0187 0188 /// @brief Calculates equation of the plane (alpha*x + beta*y + gamma*z + delta = 0), given the three points 0189 /// @param triplet A single triplet (with 3 spacepoints) 0190 /// @return A pair of {{alpha,beta,gamma},delta} 0191 static std::pair<Acts::Vector3, double> makePlaneFromTriplet( 0192 const Triplet& triplet); 0193 0194 /// @brief Find a point (=the vertex) that has minimum chi^2 with respect to all planes defined by the triplets 0195 /// @param triplets Vector of all valid triplets 0196 /// @return Position {x,y,z} of the vertex 0197 Acts::Vector3 findClosestPointFromPlanes( 0198 const std::vector<Triplet>& triplets) const; 0199 0200 /// @brief Calculates parameters of the ray (starting point + direction), given the three points 0201 /// @param triplet A single triplet (with 3 spacepoints) 0202 /// @return A ray of {starting_point, direction} 0203 static Acts::Ray3D makeRayFromTriplet(const Triplet& triplet); 0204 0205 /// @brief Find a point (=the vertex) that has minimum chi^2 with respect to all rays fitted through the triplets 0206 /// @param triplets Vector of all valid triplets 0207 /// @return Position {x,y,z} of the vertex 0208 Acts::Vector3 findClosestPointFromRays( 0209 const std::vector<Triplet>& triplets) const; 0210 0211 /// Logging instance 0212 std::unique_ptr<const Logger> m_logger; 0213 0214 /// Private access to logging instance 0215 const Logger& logger() const { return *m_logger; } 0216 }; 0217 0218 } // namespace Acts 0219 0220 #include "Acts/Vertexing/SingleSeedVertexFinder.ipp"
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |