Back to home page

EIC code displayed by LXR

 
 

    


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

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/Axis.hpp"
0014 #include "Acts/Utilities/Grid.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016 #include "Acts/Utilities/Result.hpp"
0017 
0018 #include <string>
0019 #include <vector>
0020 
0021 namespace Acts {
0022 
0023 /// @class HoughVertexFinder
0024 ///
0025 /// @brief Implements the vertex finder based on the spacepoints using Hough transform
0026 /// For more information, see arXiv:2410.14494
0027 /// 0. Assumes there is only 1 vertex and that it has a high multiplicity
0028 /// 1. Estimates what eta range is really necessary
0029 /// 2. Creates Hough space (z_vtx - cot(theta)) from spacepoints within that eta
0030 /// range
0031 /// 3. Subtracts the coincidentally crossed lines in the Hough space
0032 /// 4. Makes a projection to the Z axis and finds a peak - that is the vertex
0033 /// position
0034 /// 5. Repeats 2-4 if necessary
0035 ///
0036 template <typename spacepoint_t>
0037 class HoughVertexFinder {
0038  public:
0039   /// Configuration struct
0040   struct Config {
0041     /// Ideal amount of spacepoints; |eta| range will be limited to
0042     /// contain approximately this amount of SPs
0043     std::uint32_t targetSPs = 10000;
0044 
0045     /// Minimum and maximum ranges in |eta|; the |eta| will not be
0046     /// set outside these bounds even if targetSPs is not reached
0047     double minAbsEta = 0.3f;
0048     /// Maximum absolute pseudorapidity for vertex finding
0049     double maxAbsEta = 4.0f;
0050 
0051     /// Minimum number of hits in Hough plane to consider
0052     /// the cell to contain a track
0053     std::uint32_t minHits = 4;
0054 
0055     /// Number of neighbouring bins in Hough plane
0056     /// to fill in the cot(theta) direction
0057     std::uint32_t fillNeighbours = 0;
0058 
0059     /// The algorithm dynamically choose |eta| range necessary to
0060     /// have a reasonable precision, based on the distribution
0061     /// of the measurements.
0062     /// The first |eta| range starts at 0., the others start at
0063     /// the endpoint of the previous range.
0064     std::vector<double> absEtaRanges{2., 4.};
0065     /// The amount of measurements in the |eta| range expressed
0066     /// as a fraction of all measurements within the whole |eta| range.
0067     /// Measurements are assumed to be distributed uniformly with
0068     /// the |eta| range.
0069     std::vector<double> absEtaFractions{0.4f, 0.6f};
0070 
0071     /// The algorithm starts peak searching considering wide range
0072     /// in Z and then iteratively constrain itself to narrower ranges
0073     /// around previously found peak. At the same time it may adapt
0074     /// other Hough-image parameters in each step.
0075     std::vector<double> rangeIterZ{200. * UnitConstants::mm,
0076                                    30. * UnitConstants::mm,
0077                                    16. * UnitConstants::mm};
0078     /// Number of bins along z-axis of the Hough image for each iteration
0079     std::vector<std::uint32_t> nBinsZIterZ{800, 180, 80};
0080     /// Number of bins along cot(theta)-axis of the Hough image for
0081     /// each iteration
0082     std::vector<std::uint32_t> nBinsCotThetaIterZ{8000, 8000, 8000};
0083 
0084     /// If the actual number of measurements is below "targetSPs", then
0085     /// the number of bins along cot(theta)-axis decreases. Thus, the actual
0086     /// number of bins can be smaller than stated in "nBinsCotThetaIterZ".
0087     /// For every magnitude (in natural logarithm) below targetSPs, the number
0088     /// of bins in cot(theta) will decrease by this factor.
0089     double binsCotThetaDecrease = 1.35f;
0090 
0091     /// Width of the peak when estimating vertex position
0092     std::uint32_t peakWidth = 3;
0093 
0094     /// Default position of the vertex in X, Y, and Z coordinates
0095     Vector3 defVtxPosition{0. * UnitConstants::mm, 0. * UnitConstants::mm,
0096                            0. * UnitConstants::mm};
0097   };
0098 
0099   /// Const access to the config
0100   /// @return Const reference to the configuration object
0101   const Config& config() const { return m_cfg; }
0102 
0103   /// @brief Constructor
0104   /// @param cfg Configuration object
0105   /// @param lgr Logging instance
0106   explicit HoughVertexFinder(
0107       Config cfg,
0108       std::unique_ptr<const Logger> lgr = getDefaultLogger("HoughVertexFinder",
0109                                                            Logging::INFO));
0110 
0111   /// Type alias for count values in Hough histogram bins
0112   using HoughCount_t = std::uint16_t;
0113   /// Type alias for equidistant axis used in Hough transform
0114   using HoughAxis = Axis<AxisType::Equidistant, AxisBoundaryType::Open>;
0115   /// Type alias for 2D histogram used in Hough transform
0116   using HoughHist = Grid<HoughCount_t, HoughAxis, HoughAxis>;
0117 
0118   /// @brief Finds the vertex based on the provided spacepoints
0119   /// @param spacepoints Vector of the input spacepoints; they do not need to be sorted anyhow
0120   /// @return Position of the vertex
0121   Acts::Result<Acts::Vector3> find(
0122       const std::vector<spacepoint_t>& spacepoints) const;
0123 
0124  private:
0125   /// Configuration instance
0126   const Config m_cfg;
0127 
0128   /// @brief Returns the positions of the peak along Z axis in the pojection of the Hough plane
0129   /// @param spacepoints Set of all spacepoints within the event
0130   /// @param vtxOld Previous position of the vertex
0131   /// @param rangeZ Range in along Z around vtxOld_z to consider when looking for the new vertex
0132   /// @param numZBins Number of bins along Z axis
0133   /// @param minCotTheta Minimum theta to consider for the spacepoint
0134   /// @param maxCotTheta Maximum theta to consider for the spacepoint
0135   /// @param numCotThetaBins Number of bins along cot(theta) axis
0136   /// @return Position of the vertex in (X,Y,Z)
0137   Acts::Result<Acts::Vector3> findHoughVertex(
0138       const std::vector<spacepoint_t>& spacepoints, const Acts::Vector3& vtxOld,
0139       double rangeZ, std::uint32_t numZBins, double minCotTheta,
0140       double maxCotTheta, std::uint32_t numCotThetaBins) const;
0141 
0142   /// @brief Finds the peak in the Z axis projection of the Hough space
0143   /// @param houghZProjection Hough space projection after the cleaning procedure
0144   /// @param vtxZPositions Bins position in the Hough space projection
0145   /// @return Position of the peak
0146   Acts::Result<double> findHoughPeak(
0147       const std::vector<std::uint32_t>& houghZProjection,
0148       const std::vector<double>& vtxZPositions) const;
0149 
0150   /// Logging instance
0151   std::unique_ptr<const Logger> m_logger;
0152 
0153   /// Private access to logging instance
0154   const Logger& logger() const { return *m_logger; }
0155 };
0156 
0157 }  // namespace Acts
0158 
0159 #include "HoughVertexFinder.ipp"