Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-17 07:58:53

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/TrackParameters.hpp"
0012 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0013 #include "Acts/Utilities/Result.hpp"
0014 #include "Acts/Vertexing/AdaptiveGridTrackDensity.hpp"
0015 #include "Acts/Vertexing/DummyVertexFitter.hpp"
0016 #include "Acts/Vertexing/IVertexFinder.hpp"
0017 #include "Acts/Vertexing/Vertex.hpp"
0018 #include "Acts/Vertexing/VertexingOptions.hpp"
0019 
0020 #include <unordered_map>
0021 
0022 namespace Acts {
0023 
0024 /// @class AdaptiveGridDensityVertexFinder
0025 /// @brief Vertex finder that makes use of a track density grid.
0026 /// Each single track is modelled as a 2-dim Gaussian distribution grid
0027 /// in the d0-z0 plane, but only the overlap with the z-axis (i.e. a 1-dim
0028 /// density vector) needs to be calculated. All track contributions along the
0029 /// beam axis (main density vector) are superimposed and the z-value of the bin
0030 /// with the highest track density is returned as a vertex candidate.
0031 /// Unlike the GridDensityVertexFinder, this seeder implements an adaptive
0032 /// version where the density grid grows bigger with added tracks.
0033 class AdaptiveGridDensityVertexFinder final : public IVertexFinder {
0034  public:
0035   /// Type alias for the density map used in adaptive grid vertex finding
0036   using DensityMap = AdaptiveGridTrackDensity::DensityMap;
0037 
0038   /// @brief The Config struct
0039   struct Config {
0040     ///@param gDensity The grid density
0041     explicit Config(const AdaptiveGridTrackDensity& gDensity)
0042         : gridDensity(gDensity) {}
0043 
0044     // The grid density object
0045     /// Grid density calculator for track density estimation
0046     AdaptiveGridTrackDensity gridDensity;
0047 
0048     // Cache the main grid and the density contributions (trackGrid and z-bin)
0049     // for every single track.
0050     // This option enables the possibility to calculate the entire main grid
0051     // only once in the first iteration. If tracks are removed from the track
0052     // collection, the individual track density contributions to the main grid
0053     // can just be removed without calculating the entire grid from scratch.
0054     /// Flag to enable caching of grid state for efficient track removal
0055     bool cacheGridStateForTrackRemoval = true;
0056 
0057     // Maximum d0 impact parameter significance to use a track
0058     /// Maximum d0 impact parameter significance threshold
0059     double maxD0TrackSignificance = 3.5;
0060     // Maximum z0 impact parameter significance to use a track
0061     /// Maximum z0 impact parameter significance threshold
0062     double maxZ0TrackSignificance = 12.;
0063     // The actual corresponding cut values in the algorithm
0064     /// Squared d0 significance cut value for track selection
0065     double d0SignificanceCut = maxD0TrackSignificance * maxD0TrackSignificance;
0066     /// Squared z0 significance cut value for track selection
0067     double z0SignificanceCut = maxZ0TrackSignificance * maxZ0TrackSignificance;
0068     /// Flag indicating whether to estimate seed width
0069     bool estimateSeedWidth = false;
0070 
0071     // Function to extract parameters from InputTrack
0072     /// Function to extract track parameters from InputTrack
0073     InputTrack::Extractor extractParameters;
0074   };
0075 
0076   /// @brief The State struct
0077   ///
0078   /// Only needed if cacheGridStateForTrackRemoval == true
0079   struct State {
0080     // Map from the z bin values to the corresponding track density
0081     /// Main density map storing cumulative track density per z-bin
0082     DensityMap mainDensityMap;
0083 
0084     // Map from input track to corresponding track density map
0085     /// Map storing individual track density contributions
0086     std::unordered_map<InputTrack, DensityMap> trackDensities;
0087 
0088     // Store tracks that have been removed from track collection. These
0089     // tracks will be removed from the main grid
0090     /// Vector of tracks to be removed from density calculation
0091     std::vector<InputTrack> tracksToRemove;
0092 
0093     /// Flag indicating whether the state has been initialized
0094     bool isInitialized = false;
0095   };
0096 
0097   /// @brief Function that finds single vertex candidate
0098   ///
0099   /// @param trackVector Input track collection
0100   /// @param vertexingOptions Vertexing options
0101   /// @param anyState The state object to cache the density grid
0102   /// and density contributions of each track, to be used
0103   /// if cacheGridStateForTrackRemoval == true
0104   ///
0105   /// @return Vector of vertices, filled with a single
0106   ///         vertex (for consistent interfaces)
0107   Result<std::vector<Vertex>> find(
0108       const std::vector<InputTrack>& trackVector,
0109       const VertexingOptions& vertexingOptions,
0110       IVertexFinder::State& anyState) const override;
0111 
0112   IVertexFinder::State makeState(
0113       const Acts::MagneticFieldContext& /*mctx*/) const override {
0114     return IVertexFinder::State{State{}};
0115   }
0116 
0117   void setTracksToRemove(
0118       IVertexFinder::State& anyState,
0119       const std::vector<InputTrack>& removedTracks) const override {
0120     auto& state = anyState.template as<State>();
0121     state.tracksToRemove = removedTracks;
0122   }
0123 
0124   /// @brief Constructor for user-defined InputTrack type
0125   ///
0126   /// @param cfg Configuration object
0127   explicit AdaptiveGridDensityVertexFinder(const Config& cfg) : m_cfg(cfg) {}
0128 
0129  private:
0130   /// @brief Checks if a track passes the selection criteria for seeding
0131   ///
0132   /// @param trk The track
0133   ///
0134   /// @return Bool track passes selection
0135   bool doesPassTrackSelection(const BoundTrackParameters& trk) const;
0136 
0137   // The configuration object
0138   const Config m_cfg;
0139 };
0140 
0141 }  // namespace Acts