Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 09:43:52

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/SeedContainer.hpp"
0013 #include "Acts/EventData/SpacePointContainer.hpp"
0014 #include "Acts/Seeding/DoubletSeedFinder.hpp"
0015 #include "Acts/Seeding/ITripletSeedFilter.hpp"
0016 #include "Acts/Seeding/SeedConfirmationRangeConfig.hpp"
0017 #include "Acts/Seeding/detail/CandidatesForMiddleSp.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 ConstSpacePointProxy& bottom,
0041                            const ConstSpacePointProxy& middle,
0042                            const ConstSpacePointProxy& 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 ConstSpacePointProxy& bottom,
0051                              const ConstSpacePointProxy& middle,
0052                              const ConstSpacePointProxy& 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<TripletCandidate>& 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     /// Weight factor for the abs(delta-eta) penalty between the seed direction
0104     /// and the vector from the beamspot to the seed's pca.
0105     /// Seeds from LLP decays tend toward small delta-eta
0106     /// values due to the correlated direction of the LLP and its decay
0107     /// products. Set to 0 (default) to disable.
0108     float absDeltaEtaWeightFactor = 0;
0109     /// Minimum impact parameter to apply the abs(delta-eta) weight
0110     /// only want to apply to displaced seeds
0111     float absDeltaEtaMinImpact = 2 * UnitConstants::mm;
0112 
0113     /// Seeding parameters used for quality seed confirmation
0114 
0115     /// Enable quality seed confirmation, this is different than default seeding
0116     /// confirmation because it can also be defined for different (r, z) regions
0117     /// of the detector (e.g. forward or central region) by
0118     /// SeedConfirmationRange. Seeds are classified as "high-quality" seeds and
0119     /// normal quality seeds. Normal quality seeds are only selected if no other
0120     /// "high-quality" seed has been found for that inner-middle doublet.
0121     bool seedConfirmation = false;
0122     /// Contains parameters for central seed confirmation
0123     SeedConfirmationRangeConfig centralSeedConfirmationRange;
0124     /// Contains parameters for forward seed confirmation
0125     SeedConfirmationRangeConfig forwardSeedConfirmationRange;
0126 
0127     /// If seedConfirmation is true we classify seeds as "high-quality" seeds.
0128     /// Seeds that are not confirmed as "high-quality" are only selected if no
0129     /// other "high-quality" seed has been found for that inner-middle doublet
0130     /// Maximum number of normal seeds (not classified as "high-quality" seeds)
0131     /// in seed confirmation
0132     std::uint32_t maxSeedsPerSpMConf = 5;
0133     /// Maximum number of "high-quality" seeds for each inner-middle SP-dublet
0134     /// in seed confirmation. If the limit is reached we check if there is a
0135     /// normal quality seed to be replaced
0136     std::uint32_t maxQualitySeedsPerSpMConf = 5;
0137 
0138     // Other parameters
0139 
0140     /// Use deltaR between top and middle SP instead of top radius to search for
0141     /// compatible SPs
0142     bool useDeltaRinsteadOfTopRadius = false;
0143 
0144     /// Custom cuts interface for experiments
0145     std::shared_ptr<ITripletSeedCuts> experimentCuts;
0146   };
0147 
0148   /// State of the filter that is communicated between different stages
0149   struct State {
0150     /// Collector for triplet candidates associated with middle space points
0151     CandidatesForMiddleSp candidatesCollector;
0152 
0153     /// Maximum radius for seed confirmation
0154     float rMaxSeedConf{};
0155 
0156     /// Map to store the best seed quality for each space point.
0157     /// This is used to avoid creating seeds with lower quality than the best
0158     /// seed quality already found for that space point.
0159     /// The key is the space point index, and the value is the best seed quality
0160     /// found for that space point.
0161     /// @note The index is the space point index, not the seed index.
0162     std::unordered_map<SpacePointIndex, float> bestSeedQualityMap;
0163   };
0164 
0165   /// Cache for intermediate results to avoid reallocations. No information is
0166   /// carried over between different stages.
0167   struct Cache {
0168     /// Cache for top space point indices during compatibility search
0169     std::vector<std::uint32_t> topSpIndexVec;
0170     /// Cache for compatible seed radii during score calculation
0171     std::vector<float> compatibleSeedR;
0172     /// Cache for sorted triplet candidates during selection
0173     std::vector<TripletCandidate> sortedCandidates;
0174   };
0175 
0176   /// @param config Configuration parameters for the seed filter
0177   /// @param state Mutable state that is used to store intermediate results
0178   /// @param cache Cache object to store intermediate results
0179   /// @param logger Logger for debugging and information messages
0180   /// @note objects from this class depend on a per-event state and cache
0181   ///       and should not be used across events.
0182   explicit BroadTripletSeedFilter(const Config& config, State& state,
0183                                   Cache& cache, const Logger& logger);
0184 
0185   /// @param spacePoints Container of space points
0186   /// @param spM Middle space point proxy
0187   /// @param topDoublets Collection of top doublets for the middle space point
0188   /// @return true if sufficient top doublets are found
0189   bool sufficientTopDoublets(
0190       const SpacePointContainer& spacePoints, const ConstSpacePointProxy& spM,
0191       const DoubletsForMiddleSp& topDoublets) const override;
0192 
0193   void filterTripletTopCandidates(
0194       const SpacePointContainer& spacePoints, const ConstSpacePointProxy& spM,
0195       const DoubletsForMiddleSp::Proxy& bottomLink,
0196       const TripletTopCandidates& tripletTopCandidates) const override;
0197 
0198   void filterTripletsMiddleFixed(
0199       const SpacePointContainer& spacePoints,
0200       SeedContainer& outputCollection) const override;
0201 
0202  private:
0203   /// Configuration parameters for the seed filter algorithm
0204   const Config* m_cfg{};
0205   /// Mutable state for intermediate results between filter stages
0206   State* m_state{};
0207   /// Cache for temporary data to avoid reallocations
0208   Cache* m_cache{};
0209   /// Logger for debugging and information messages
0210   const Logger* m_logger{};
0211 
0212   const Config& config() const { return *m_cfg; }
0213   State& state() const { return *m_state; }
0214   Cache& cache() const { return *m_cache; }
0215   const Logger& logger() const { return *m_logger; }
0216 };
0217 
0218 }  // namespace Acts