Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:01

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/SourceLink.hpp"
0012 #include "Acts/EventData/TrackParameters.hpp"
0013 #include "Acts/Seeding/detail/UtilityFunctions.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Utilities/Delegate.hpp"
0016 #include "Acts/Utilities/GridIterator.hpp"
0017 
0018 namespace Acts {
0019 
0020 /// @brief Seeding algorigthm that extracts
0021 /// the IP parameters and sorts the source links
0022 /// into possible track candidates
0023 ///
0024 /// The algorithm to convert the given source links
0025 /// into seeds -- pairs of IP parameters and the corresponding
0026 /// source links -- as follows: First the source links
0027 /// are sorted into a user-defined grid. Then, iteration over the source links
0028 /// is performed. If a source link is attached to a surface that is
0029 /// in the reference tracking layer, as defined by the user, the IP parameters
0030 /// are estimated and the tracking layers are intersected to construct the
0031 /// core of the "Path". The source links in the subsequent layers are then
0032 /// added to the seed if they lie within the path width of the core.
0033 /// Both the list of source links and the IP parameters are stored in the seed
0034 /// struct.
0035 ///
0036 /// @tparam axis_t Type of the axis to bin
0037 /// the source links
0038 ///
0039 /// @note The algorithm is designed to be used in the
0040 /// context of a telescope-style geometry. The surfaces
0041 /// are assumed to be planar.
0042 ///
0043 /// @note Handling of the rotated surfaces has to happen
0044 /// in the user-defined delegate functions.
0045 class PathSeeder {
0046  public:
0047   using PathSeed =
0048       std::pair<CurvilinearTrackParameters, std::vector<SourceLink>>;
0049 
0050   /// @brief Delegate to estimate the IP parameters
0051   /// and the momentum direction at the reference tracking layer
0052   ///
0053   /// @arg Geometry context to use
0054   /// @arg Pivot source link
0055   ///
0056   /// @return Pair of the track parameters at the IP and
0057   /// the reference tracking layer
0058   using TrackEstimator = Delegate<
0059       std::pair<CurvilinearTrackParameters, CurvilinearTrackParameters>(
0060           const GeometryContext&, const SourceLink&)>;
0061 
0062   /// @brief Delegate to find the intersections for the given pivot
0063   /// source link
0064   ///
0065   /// @arg The geometry context to use
0066   /// @arg Track parameters at the reference tracking layer
0067   ///
0068   /// @return Vector of pairs of the geometry identifier
0069   /// and the local intersection point
0070   using IntersectionLookup =
0071       Delegate<std::vector<std::pair<GeometryIdentifier, Vector2>>(
0072           const GeometryContext&, const CurvilinearTrackParameters&)>;
0073 
0074   /// @brief Delegate to provide the path width around
0075   /// the intersection point to pull the source links
0076   /// from the grid
0077   ///
0078   /// @arg The geometry context to use
0079   /// @arg The geometry identifier to use if the
0080   /// path width is varied across different tracking layers
0081   ///
0082   /// @return The path width in the bin0 and bin1 direction
0083   /// defined with respect to the surface normal
0084   using PathWidthLookup = Delegate<std::pair<double, double>(
0085       const GeometryContext&, const GeometryIdentifier&)>;
0086 
0087   /// @brief The nested configuration struct
0088   struct Config {
0089     /// Parameters estimator
0090     TrackEstimator trackEstimator;
0091     /// Intersection finder
0092     IntersectionLookup intersectionFinder;
0093     /// Path width provider
0094     PathWidthLookup pathWidthProvider;
0095     /// Reference layer IDs
0096     std::vector<GeometryIdentifier> refLayerIds;
0097   };
0098 
0099   /// @brief Constructor
0100   PathSeeder(const Config& config) : m_cfg(config) {};
0101 
0102   /// @brief Destructor
0103   ~PathSeeder() = default;
0104 
0105   /// @brief Extract the IP parameters and
0106   /// sort the source links into the seeds
0107   ///
0108   /// @param gctx The geometry context
0109   /// @param sourceLinkGridLookup The lookup table for the source links
0110   /// @param seedCollection The collection of seeds to fill
0111   template <Acts::detail::SourceLinkGrid grid_t, typename container_t>
0112   void findSeeds(const GeometryContext& gctx,
0113                  const std::unordered_map<GeometryIdentifier, grid_t>&
0114                      sourceLinkGridLookup,
0115                  container_t& seedCollection) const {
0116     // Create the seeds
0117     for (auto& refGeoId : m_cfg.refLayerIds) {
0118       auto refGrid = sourceLinkGridLookup.at(refGeoId);
0119 
0120       for (auto it = refGrid.begin(); it != refGrid.end(); it++) {
0121         std::vector<SourceLink> pivotSourceLinks = *it;
0122 
0123         for (const auto& pivot : pivotSourceLinks) {
0124           // Get the IP parameters
0125           auto [ipParameters, refLayerParameters] =
0126               m_cfg.trackEstimator(gctx, pivot);
0127 
0128           // Intersect with the surfaces
0129           std::vector<std::pair<GeometryIdentifier, Vector2>> intersections =
0130               m_cfg.intersectionFinder(gctx, refLayerParameters);
0131 
0132           // Continue if no intersections
0133           if (intersections.empty()) {
0134             continue;
0135           }
0136 
0137           // Iterate over the intersections
0138           // and get the source links
0139           // in the subsequent layers
0140           std::vector<SourceLink> seedSourceLinks;
0141           for (auto& [geoId, refPoint] : intersections) {
0142             // Get the path width
0143             auto [pathWidth0, pathWidth1] =
0144                 m_cfg.pathWidthProvider(gctx, geoId);
0145 
0146             // Get the bounds of the path
0147             double top0 = refPoint[0] + pathWidth0;
0148             double bot0 = refPoint[0] - pathWidth0;
0149             double top1 = refPoint[1] + pathWidth1;
0150             double bot1 = refPoint[1] - pathWidth1;
0151 
0152             // Get the lookup table for the source links
0153             auto grid = sourceLinkGridLookup.at(geoId);
0154 
0155             // Get the range of bins to search for source links
0156             auto botLeftBin = grid.localBinsFromPosition(Vector2(bot0, bot1));
0157             auto topRightBin = grid.localBinsFromPosition(Vector2(top0, top1));
0158 
0159             // Get the source links from the lookup table
0160             // by iterating over the bin ranges
0161             auto currentBin = botLeftBin;
0162             while (currentBin.at(1) <= topRightBin.at(1)) {
0163               while (currentBin.at(0) <= topRightBin.at(0)) {
0164                 auto sourceLinksToAdd = grid.atLocalBins(currentBin);
0165 
0166                 seedSourceLinks.insert(seedSourceLinks.end(),
0167                                        sourceLinksToAdd.begin(),
0168                                        sourceLinksToAdd.end());
0169 
0170                 currentBin.at(0)++;
0171               }
0172               currentBin.at(1)++;
0173               currentBin.at(0) = botLeftBin.at(0);
0174             }
0175           }
0176           PathSeed seed = {ipParameters, seedSourceLinks};
0177 
0178           // Add the seed to the collection
0179           Acts::detail::pushBackOrInsertAtEnd(seedCollection, seed);
0180         }
0181       }
0182     }
0183   }
0184 
0185  private:
0186   Config m_cfg;
0187 };
0188 
0189 }  // namespace Acts