Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-22 07:51:51

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/Material/Interactions.hpp"
0014 #include "Acts/Seeding/SeedConfirmationRangeConfig.hpp"
0015 #include "Acts/Utilities/Delegate.hpp"
0016 
0017 #include <limits>
0018 #include <memory>
0019 #include <numbers>
0020 #include <vector>
0021 
0022 namespace Acts {
0023 
0024 // forward declaration to avoid cyclic dependence
0025 template <typename T>
0026 class SeedFilter;
0027 
0028 /// @brief Structure that holds configuration parameters for the seed finder algorithm
0029 template <typename SpacePoint>
0030 struct SeedFinderConfig {
0031   /// Shared pointer to the seed filter for quality assessment
0032   std::shared_ptr<SeedFilter<SpacePoint>> seedFilter;
0033 
0034   /// Seeding parameters used in the space-point grid creation and bin finding
0035 
0036   /// Geometry Settings + Detector ROI
0037   /// (r, z, phi) range for limiting location of all measurements and grid
0038   /// creation
0039   float phiMin = -std::numbers::pi_v<float>;
0040   /// Maximum phi angle for space-point selection
0041   float phiMax = std::numbers::pi_v<float>;
0042   /// Minimum z coordinate for space-point selection
0043   float zMin = -2800 * UnitConstants::mm;
0044   /// Maximum z coordinate for space-point selection
0045   float zMax = 2800 * UnitConstants::mm;
0046   /// Maximum radius for space-point selection
0047   float rMax = 600 * UnitConstants::mm;
0048   /// WARNING: if rMin is smaller than impactMax, the bin size will be 2*pi,
0049   /// which will make seeding very slow!
0050   float rMin = 33 * UnitConstants::mm;
0051 
0052   /// Vector containing the z-bin edges for non equidistant binning in z
0053   std::vector<float> zBinEdges;
0054 
0055   /// Order of z bins to loop over when searching for SPs
0056   std::vector<std::size_t> zBinsCustomLooping = {};
0057 
0058   /// Radial bin size used in space-point grid
0059   float binSizeR = 1. * UnitConstants::mm;
0060 
0061   /// Seeding parameters used to define the region of interest for middle
0062   /// space-point
0063 
0064   /// Radial range for middle space-point
0065   /// The range can be defined manually with (rMinMiddle, rMaxMiddle). If
0066   /// useVariableMiddleSPRange is set to false and the vector rRangeMiddleSP is
0067   /// empty, we use (rMinMiddle, rMaxMiddle) to cut the middle space-points
0068   float rMinMiddle = 60.f * UnitConstants::mm;
0069   /// Maximum radius for middle space-point selection
0070   float rMaxMiddle = 120.f * UnitConstants::mm;
0071   /// If useVariableMiddleSPRange is set to false, the vector rRangeMiddleSP can
0072   /// be used to define a fixed r range for each z bin: {{rMin, rMax}, ...}
0073   bool useVariableMiddleSPRange = false;
0074   /// Range defined in vector for each z bin
0075   std::vector<std::vector<float>> rRangeMiddleSP;
0076   /// If useVariableMiddleSPRange is true, the radial range will be calculated
0077   /// based on the maximum and minimum r values of the space-points in the event
0078   /// and a deltaR (deltaRMiddleMinSPRange, deltaRMiddleMaxSPRange)
0079   float deltaRMiddleMinSPRange = 10. * UnitConstants::mm;
0080   /// Maximum delta R for variable middle SP range calculation
0081   float deltaRMiddleMaxSPRange = 10. * UnitConstants::mm;
0082 
0083   /// Seeding parameters used to define the cuts on space-point doublets
0084 
0085   /// Minimum radial distance between two doublet components (prefer
0086   /// deltaRMinTopSP and deltaRMinBottomSP to set separate values for outer and
0087   /// inner space-points)
0088   float deltaRMin = 5 * UnitConstants::mm;
0089   /// Maximum radial distance between two doublet components (prefer
0090   /// deltaRMaxTopSP and deltaRMacBottomSP to set separate values for outer and
0091   /// inner space-points)
0092   float deltaRMax = 270 * UnitConstants::mm;
0093   /// Minimum radial distance between middle-outer doublet components
0094   float deltaRMinTopSP = std::numeric_limits<float>::quiet_NaN();
0095   /// Maximum radial distance between middle-outer doublet components
0096   float deltaRMaxTopSP = std::numeric_limits<float>::quiet_NaN();
0097   /// Minimum radial distance between inner-middle doublet components
0098   float deltaRMinBottomSP = std::numeric_limits<float>::quiet_NaN();
0099   /// Maximum radial distance between inner-middle doublet components
0100   float deltaRMaxBottomSP = std::numeric_limits<float>::quiet_NaN();
0101 
0102   /// Maximum value of z-distance between space-points in doublet
0103   float deltaZMax = std::numeric_limits<float>::infinity() * UnitConstants::mm;
0104 
0105   /// Maximum allowed cotTheta between two space-points in doublet, used to
0106   /// check if forward angle is within bounds
0107   float cotThetaMax = 10.01788;  // equivalent to eta = 3 (pseudorapidity)
0108 
0109   /// Limiting location of collision region in z-axis used to check if doublet
0110   /// origin is within reasonable bounds
0111   float collisionRegionMin = -150 * UnitConstants::mm;
0112   /// Maximum z extent of collision region for doublet validation
0113   float collisionRegionMax = +150 * UnitConstants::mm;
0114 
0115   /// Enable cut on the compatibility between interaction point and doublet,
0116   /// this is an useful approximation to speed up the seeding
0117   bool interactionPointCut = false;
0118 
0119   /// Seeding parameters used to define the cuts on space-point triplets
0120 
0121   /// Minimum transverse momentum (pT) used to check the r-z slope compatibility
0122   /// of triplets with maximum multiple scattering effect (produced by the
0123   /// minimum allowed pT particle) + a certain uncertainty term. Check the
0124   /// documentation for more information
0125   /// https://acts.readthedocs.io/en/latest/core/reconstruction/pattern_recognition/seeding.html
0126   float minPt = 400. * UnitConstants::MeV;
0127   /// Number of sigmas of scattering angle to be considered in the minimum pT
0128   /// scattering term
0129   float sigmaScattering = 5;
0130   /// Term that accounts for the thickness of scattering medium in radiation
0131   /// lengths in the Lynch & Dahl correction to the Highland equation default is
0132   /// 5%
0133   /// TODO: necessary to make amount of material dependent on detector region?
0134   float radLengthPerSeed = 0.05;
0135   /// Maximum transverse momentum for scattering calculation
0136   float maxPtScattering = 10 * UnitConstants::GeV;
0137   /// Maximum value of impact parameter estimation of the seed candidates
0138   float impactMax = 20. * UnitConstants::mm;
0139   /// Parameter which can loosen the tolerance of the track seed to form a
0140   /// helix. This is useful for e.g. misaligned seeding.
0141   float helixCutTolerance = 1.;
0142 
0143   /// Seeding parameters used for quality seed confirmation
0144 
0145   /// Enable quality seed confirmation, this is different than default seeding
0146   /// confirmation because it can also be defined for different (r, z) regions
0147   /// of the detector (e.g. forward or central region) by SeedConfirmationRange.
0148   /// Seeds are classified as "high-quality" seeds and normal quality seeds.
0149   /// Normal quality seeds are only selected if no other "high-quality" seeds
0150   /// has been found for that inner-middle doublet.
0151   bool seedConfirmation = false;
0152   /// Contains parameters for central seed confirmation
0153   SeedConfirmationRangeConfig centralSeedConfirmationRange;
0154   /// Contains parameters for forward seed confirmation
0155   SeedConfirmationRangeConfig forwardSeedConfirmationRange;
0156   /// Maximum number (minus one) of accepted seeds per middle space-point
0157   unsigned int maxSeedsPerSpM = 5;
0158 
0159   /// Other parameters
0160 
0161   /// Alignment uncertainties, used for uncertainties in the
0162   /// non-measurement-plane of the modules
0163   /// which otherwise would be 0
0164   /// will be added to spacepoint measurement uncertainties (and therefore also
0165   /// multiplied by sigmaError)
0166   /// FIXME: call align1 and align2
0167   float zAlign = 0 * UnitConstants::mm;
0168   /// Radial alignment uncertainty for space-point uncertainties
0169   float rAlign = 0 * UnitConstants::mm;
0170   /// used for measurement (+alignment) uncertainties.
0171   /// find seeds within 5sigma error ellipse
0172   float sigmaError = 5;
0173 
0174   /// derived values, set on SeedFinder construction
0175   float highland = 0;
0176   /// Squared maximum scattering angle for track validation
0177   float maxScatteringAngle2 = 0;
0178 
0179   /// only for Cuda plugin
0180   int maxBlockSize = 1024;
0181   /// Maximum number of triplets per space-point bin for CUDA
0182   int nTrplPerSpBLimit = 100;
0183   /// Average triplet limit per space-point bin for CUDA
0184   int nAvgTrplPerSpBLimit = 2;
0185 
0186   /// Delegates for accessors to detailed information on double measurement that
0187   /// produced the space point.
0188   /// This is mainly referring to space points produced when combining
0189   /// measurement from strips on back-to-back modules.
0190   /// Enables setting of the following delegates.
0191   bool useDetailedDoubleMeasurementInfo = false;
0192 
0193   /// Delegate function for space-point selection filtering
0194   Delegate<bool(const SpacePoint&)> spacePointSelector{
0195       DelegateFuncTag<voidSpacePointSelector>{}};
0196 
0197   /// Default space point selector that accepts all space points
0198   /// @param sp The space point to evaluate (unused)
0199   /// @return Always returns true (accepts all space points)
0200   static bool voidSpacePointSelector(const SpacePoint& sp) {
0201     static_cast<void>(sp);
0202     return true;
0203   }
0204 
0205   /// Tolerance parameter used to check the compatibility of space-point
0206   /// coordinates in xyz. This is only used in a detector specific check for
0207   /// strip modules
0208   float toleranceParam = 1.1 * UnitConstants::mm;
0209 
0210   /// Delegate to apply experiment specific cuts during doublet finding
0211   Delegate<bool(const SpacePoint& /*middle*/, const SpacePoint& /*other*/,
0212                 float /*cotTheta*/, bool /*isBottomCandidate*/)>
0213       experimentCuts{DelegateFuncTag<&noopExperimentCuts>{}};
0214 
0215   /// defaults experimental cuts to no operation in both seeding algorithms
0216   /// @return Always returns true (no cuts applied)
0217   static bool noopExperimentCuts(const SpacePoint& /*middle*/,
0218                                  const SpacePoint& /*other*/,
0219                                  float /*cotTheta*/,
0220                                  bool /*isBottomCandidate*/) {
0221     return true;
0222   }
0223 
0224   /// Flag indicating whether configuration uses ACTS internal units
0225   bool isInInternalUnits = true;
0226   /// Convert configuration to internal units (no-op as already in internal
0227   /// units)
0228   /// @deprecated SeedFinderConfig uses internal units
0229   /// @return Copy of this configuration (already in internal units)
0230   //[[deprecated("SeedFinderConfig uses internal units")]]
0231   SeedFinderConfig toInternalUnits() const { return *this; }
0232 
0233   /// Calculate derived quantities from the current configuration
0234   /// @return A new configuration with derived quantities calculated
0235   SeedFinderConfig calculateDerivedQuantities() const {
0236     SeedFinderConfig config = *this;
0237     config.highland = approximateHighlandScattering(config.radLengthPerSeed);
0238     const float maxScatteringAngle = config.highland / minPt;
0239     config.maxScatteringAngle2 = maxScatteringAngle * maxScatteringAngle;
0240     return config;
0241   }
0242 };
0243 
0244 struct SeedFinderOptions {
0245   // location of beam in x,y plane.
0246   // used as offset for Space Points
0247   Vector2 beamPos{0 * UnitConstants::mm, 0 * UnitConstants::mm};
0248   // field induction
0249   float bFieldInZ = 2 * UnitConstants::T;
0250 
0251   // derived quantities
0252   float pTPerHelixRadius = std::numeric_limits<float>::quiet_NaN();
0253   float minHelixDiameter2 = std::numeric_limits<float>::quiet_NaN();
0254   float pT2perRadius = std::numeric_limits<float>::quiet_NaN();
0255   float sigmapT2perRadius = std::numeric_limits<float>::quiet_NaN();
0256   float multipleScattering2 = std::numeric_limits<float>::quiet_NaN();
0257 
0258   bool isInInternalUnits = true;
0259   //[[deprecated("SeedFinderOptions uses internal units")]]
0260   SeedFinderOptions toInternalUnits() const { return *this; }
0261 
0262   template <typename Config>
0263   SeedFinderOptions calculateDerivedQuantities(const Config& config) const {
0264     using namespace UnitLiterals;
0265 
0266     SeedFinderOptions options = *this;
0267     // bFieldInZ is in (pT/radius) natively, no need for conversion
0268     options.pTPerHelixRadius = options.bFieldInZ;
0269     options.minHelixDiameter2 =
0270         std::pow(config.minPt * 2 / options.pTPerHelixRadius, 2) *
0271         config.helixCutTolerance;
0272     options.pT2perRadius =
0273         std::pow(config.highland / options.pTPerHelixRadius, 2);
0274     options.sigmapT2perRadius =
0275         options.pT2perRadius * std::pow(2 * config.sigmaScattering, 2);
0276     options.multipleScattering2 =
0277         config.maxScatteringAngle2 * std::pow(config.sigmaScattering, 2);
0278     return options;
0279   }
0280 };
0281 
0282 }  // namespace Acts