Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:04

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/Units.hpp"
0012 #include "Acts/EventData/SeedContainer2.hpp"
0013 #include "Acts/EventData/SpacePointContainer2.hpp"
0014 #include "Acts/Seeding/SeedConfirmationRangeConfig.hpp"
0015 #include "Acts/Seeding2/DoubletSeedFinder.hpp"
0016 #include "Acts/Seeding2/ITripletSeedFilter.hpp"
0017 #include "Acts/Seeding2/detail/CandidatesForMiddleSp2.hpp"
0018 #include "Acts/Utilities/Logger.hpp"
0019 
0020 #include <memory>
0021 #include <unordered_map>
0022 #include <vector>
0023 
0024 namespace Acts {
0025 
0026 /// @c ITripletSeedCuts can be used to increase or decrease seed weights
0027 /// based on the space points used in a seed. Seed weights are also
0028 /// influenced by the SeedFilter default implementation. This tool is also used
0029 /// to decide if a seed passes a seed weight cut. As the weight is stored in
0030 /// seeds, there are two distinct methods.
0031 class ITripletSeedCuts {
0032  public:
0033   virtual ~ITripletSeedCuts() = default;
0034 
0035   /// Returns seed weight bonus/malus depending on detector considerations.
0036   /// @param bottom bottom space point of the current seed
0037   /// @param middle middle space point of the current seed
0038   /// @param top top space point of the current seed
0039   /// @return seed weight to be added to the seed's weight
0040   virtual float seedWeight(const ConstSpacePointProxy2& bottom,
0041                            const ConstSpacePointProxy2& middle,
0042                            const ConstSpacePointProxy2& top) const = 0;
0043 
0044   /// @param weight the current seed weight
0045   /// @param bottom bottom space point of the current seed
0046   /// @param middle middle space point of the current seed
0047   /// @param top top space point of the current seed
0048   /// @return true if the seed should be kept, false if the seed should be
0049   /// discarded
0050   virtual bool singleSeedCut(float weight, const ConstSpacePointProxy2& bottom,
0051                              const ConstSpacePointProxy2& middle,
0052                              const ConstSpacePointProxy2& top) const = 0;
0053 
0054   /// @param seedCandidates contains collection of seed candidates created for one middle
0055   /// space point in a std::tuple format
0056   virtual void cutPerMiddleSp(
0057       std::span<TripletCandidate2>& seedCandidates) const = 0;
0058 };
0059 
0060 /// @brief Triplet seed filter used in the triplet seeding algorithm
0061 ///
0062 /// Note that this algorithm is designed and tuned for cylindrical detectors and
0063 /// uses R-Z coordinates for the space points.
0064 class BroadTripletSeedFilter final : public ITripletSeedFilter {
0065  public:
0066   /// @brief Structure that holds configuration parameters for the seed filter algorithm
0067   struct Config {
0068     /// Allowed difference in curvature (inverted seed radii) between two
0069     /// compatible seeds
0070     float deltaInvHelixDiameter = 0.00003 * (1 / UnitConstants::mm);
0071     /// Minimum distance between compatible outer space-points to be considered.
0072     /// This is used to avoid counting space-points from the same layer
0073     float deltaRMin = 5 * UnitConstants::mm;
0074     /// Seed weight/score is increased by this value if a compatible seed has
0075     /// been found. This is the c1 factor in the seed score calculation (w = c1
0076     /// * Nt - c2 * d0 - c3 * z0)
0077     float compatSeedWeight = 200;
0078     /// The transverse impact parameters (d0) is multiplied by this factor and
0079     /// subtracted from weight. This is the c2 factor in the seed score
0080     /// calculation (w = c1 * Nt - c2 * d0 - c3 * z0)
0081     float impactWeightFactor = 1;
0082     /// The logitudinal impact parameters (z0) is multiplied by this factor and
0083     /// subtracted from weight. This is the c3 factor in the seed score
0084     /// calculation (w = c1 * Nt - c2 * d0 - c3 * z0)
0085     float zOriginWeightFactor = 1;
0086     /// Maximum number (minus one) of accepted seeds per middle space-point
0087     /// In dense environments many seeds may be found per middle space-point
0088     /// Only seeds with the highest weight will be kept if this limit is reached
0089     unsigned int maxSeedsPerSpM = 5;
0090     /// Maximum limit to number of compatible space-point used in score
0091     /// calculation. We increase by c1 the weight calculation for each
0092     /// compatible space-point until we reach compatSeedLimit
0093     std::size_t compatSeedLimit = 2;
0094 
0095     /// Increment in seed weight if the number of compatible seeds is larger
0096     /// than numSeedIncrement, this is used in case of high occupancy scenarios
0097     /// if we want to increase the weight of the seed by seedWeightIncrement
0098     /// when the number of compatible seeds is higher than a certain value
0099     float seedWeightIncrement = 0;
0100     /// Number of seeds required before `seedWeightIncrement` is applied
0101     float numSeedIncrement = std::numeric_limits<float>::infinity();
0102 
0103     /// Seeding parameters used for quality seed confirmation
0104 
0105     /// Enable quality seed confirmation, this is different than default seeding
0106     /// confirmation because it can also be defined for different (r, z) regions
0107     /// of the detector (e.g. forward or central region) by
0108     /// SeedConfirmationRange. Seeds are classified as "high-quality" seeds and
0109     /// normal quality seeds. Normal quality seeds are only selected if no other
0110     /// "high-quality" seed has been found for that inner-middle doublet.
0111     bool seedConfirmation = false;
0112     /// Contains parameters for central seed confirmation
0113     SeedConfirmationRangeConfig centralSeedConfirmationRange;
0114     /// Contains parameters for forward seed confirmation
0115     SeedConfirmationRangeConfig forwardSeedConfirmationRange;
0116 
0117     /// If seedConfirmation is true we classify seeds as "high-quality" seeds.
0118     /// Seeds that are not confirmed as "high-quality" are only selected if no
0119     /// other "high-quality" seed has been found for that inner-middle doublet
0120     /// Maximum number of normal seeds (not classified as "high-quality" seeds)
0121     /// in seed confirmation
0122     std::uint32_t maxSeedsPerSpMConf = 5;
0123     /// Maximum number of "high-quality" seeds for each inner-middle SP-dublet
0124     /// in seed confirmation. If the limit is reached we check if there is a
0125     /// normal quality seed to be replaced
0126     std::uint32_t maxQualitySeedsPerSpMConf = 5;
0127 
0128     // Other parameters
0129 
0130     /// Use deltaR between top and middle SP instead of top radius to search for
0131     /// compatible SPs
0132     bool useDeltaRinsteadOfTopRadius = false;
0133 
0134     /// Custom cuts interface for experiments
0135     std::shared_ptr<ITripletSeedCuts> experimentCuts;
0136   };
0137 
0138   /// State of the filter that is communicated between different stages
0139   struct State {
0140     /// Collector for triplet candidates associated with middle space points
0141     CandidatesForMiddleSp2 candidatesCollector;
0142 
0143     /// Maximum radius for seed confirmation
0144     float rMaxSeedConf{};
0145 
0146     /// Map to store the best seed quality for each space point
0147     /// This is used to avoid creating seeds with lower quality than the best
0148     /// seed quality already found for that space point
0149     /// The key is the space point index, and the value is the best seed quality
0150     /// found for that space point
0151     /// @note The index is the space point index, not the seed index.
0152     ///       `copyFromIndex` will be used if available.
0153     std::unordered_map<SpacePointIndex2, float> bestSeedQualityMap;
0154   };
0155 
0156   /// Cache for intermediate results to avoid reallocations. No information is
0157   /// carried over between different stages.
0158   struct Cache {
0159     /// Cache for top space point indices during compatibility search
0160     std::vector<std::uint32_t> topSpIndexVec;
0161     /// Cache for compatible seed radii during score calculation
0162     std::vector<float> compatibleSeedR;
0163     /// Cache for sorted triplet candidates during selection
0164     std::vector<TripletCandidate2> sortedCandidates;
0165   };
0166 
0167   /// @param config Configuration parameters for the seed filter
0168   /// @param state Mutable state that is used to store intermediate results
0169   /// @param cache Cache object to store intermediate results
0170   /// @param logger Logger for debugging and information messages
0171   /// @note objects from this class depend on a per-event state and cache
0172   ///       and should not be used across events.
0173   explicit BroadTripletSeedFilter(const Config& config, State& state,
0174                                   Cache& cache, const Logger& logger);
0175 
0176   /// @param spacePoints Container of space points
0177   /// @param spM Middle space point proxy
0178   /// @param topDoublets Collection of top doublets for the middle space point
0179   /// @return true if sufficient top doublets are found
0180   bool sufficientTopDoublets(
0181       const SpacePointContainer2& spacePoints, const ConstSpacePointProxy2& spM,
0182       const DoubletsForMiddleSp& topDoublets) const override;
0183 
0184   void filterTripletTopCandidates(
0185       const SpacePointContainer2& spacePoints, const ConstSpacePointProxy2& spM,
0186       const DoubletsForMiddleSp::Proxy& bottomLink,
0187       const TripletTopCandidates& tripletTopCandidates) const override;
0188 
0189   void filterTripletsMiddleFixed(
0190       const SpacePointContainer2& spacePoints,
0191       SeedContainer2& outputCollection) const override;
0192 
0193  private:
0194   /// Configuration parameters for the seed filter algorithm
0195   const Config* m_cfg{};
0196   /// Mutable state for intermediate results between filter stages
0197   State* m_state{};
0198   /// Cache for temporary data to avoid reallocations
0199   Cache* m_cache{};
0200   /// Logger for debugging and information messages
0201   const Logger* m_logger{};
0202 
0203   const Config& config() const { return *m_cfg; }
0204   State& state() const { return *m_state; }
0205   Cache& cache() const { return *m_cache; }
0206   const Logger& logger() const { return *m_logger; }
0207 };
0208 
0209 }  // namespace Acts