Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:42:31

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/EventData/TrackParameters.hpp"
0013 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0014 #include "Acts/Utilities/Result.hpp"
0015 #include "Acts/Vertexing/DummyVertexFitter.hpp"
0016 #include "Acts/Vertexing/GaussianGridTrackDensity.hpp"
0017 #include "Acts/Vertexing/IVertexFinder.hpp"
0018 #include "Acts/Vertexing/Vertex.hpp"
0019 #include "Acts/Vertexing/VertexingOptions.hpp"
0020 
0021 #include <map>
0022 
0023 namespace Acts {
0024 
0025 /// @class GridDensityVertexFinder
0026 /// @brief Vertex finder that makes use of a track density grid.
0027 /// Each single track is modelled as a 2(!)-dim Gaussian distribution grid
0028 /// in the d0-z0 plane, but only the overlap with the z-axis (i.e. a 1-dim
0029 /// density vector) needs to be calculated. All track contributions along the
0030 /// beam axis (main density grid) a superimposed and the z-value of the bin
0031 /// with the highest track density is returned as a vertex candidate.
0032 class GridDensityVertexFinder final : public IVertexFinder {
0033  public:
0034   /// Type alias for main grid vector used in density calculations
0035   using MainGridVector = GaussianGridTrackDensity::MainGridVector;
0036   /// Type alias for track grid vector used for individual track density
0037   using TrackGridVector = GaussianGridTrackDensity::TrackGridVector;
0038 
0039   /// @brief The Config struct
0040   struct Config {
0041     ///@param gDensity The grid density
0042     explicit Config(GaussianGridTrackDensity gDensity)
0043         : gridDensity(gDensity) {}
0044 
0045     /// The grid density object for track density calculations
0046     GaussianGridTrackDensity 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 grid state for efficient track removal
0055     bool cacheGridStateForTrackRemoval = true;
0056 
0057     /// Maximum d0 impact parameter significance to use a track
0058     double maxD0TrackSignificance = 3.5;
0059     /// Maximum z0 impact parameter significance to use a track
0060     double maxZ0TrackSignificance = 12.;
0061     /// The actual corresponding cut values in the algorithm for d0
0062     double d0SignificanceCut = maxD0TrackSignificance * maxD0TrackSignificance;
0063     /// The actual corresponding cut values in the algorithm for z0
0064     double z0SignificanceCut = maxZ0TrackSignificance * maxZ0TrackSignificance;
0065     /// Flag to enable seed width estimation from track density
0066     bool estimateSeedWidth = false;
0067 
0068     /// Function to extract parameters from InputTrack
0069     InputTrack::Extractor extractParameters;
0070   };
0071 
0072   /// @brief The State struct
0073   ///
0074   /// Only needed if cacheGridStateForTrackRemoval == true
0075   struct State {
0076     /// Constructor with main grid vector
0077     /// @param mainGrid_ The main density grid for vertex finding
0078     explicit State(MainGridVector mainGrid_) : mainGrid(std::move(mainGrid_)) {}
0079 
0080     /// The main density grid for vertex finding
0081     MainGridVector mainGrid;
0082     /// Map to store z-bin and track grid (i.e. the density contribution of
0083     /// a single track to the main grid) for every single track
0084     std::map<InputTrack, std::pair<int, TrackGridVector>> binAndTrackGridMap;
0085 
0086     /// Map to store bool if track has passed track selection or not
0087     std::map<InputTrack, bool> trackSelectionMap;
0088 
0089     /// Store tracks that have been removed from track collection. These
0090     /// track will be removed from the main grid
0091     std::vector<InputTrack> tracksToRemove;
0092 
0093     /// Flag indicating if 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{
0115         std::in_place_type<State>,
0116         MainGridVector{m_cfg.gridDensity.config().mainGridSize}};
0117   }
0118 
0119   void setTracksToRemove(
0120       IVertexFinder::State& anyState,
0121       const std::vector<InputTrack>& removedTracks) const override {
0122     auto& state = anyState.template as<State>();
0123     state.tracksToRemove = removedTracks;
0124   }
0125 
0126   /// @brief Constructor for user-defined InputTrack type
0127   ///
0128   /// @param cfg Configuration object
0129   explicit GridDensityVertexFinder(const Config& cfg) : m_cfg(cfg) {
0130     if (!m_cfg.extractParameters.connected()) {
0131       throw std::invalid_argument(
0132           "GridDensityVertexFinder: "
0133           "No track parameter extractor provided.");
0134     }
0135   }
0136 
0137  private:
0138   /// @brief Checks if a track passes the selection criteria for seeding
0139   ///
0140   /// @param trk The track
0141   ///
0142   /// @return Bool track passes selection
0143   bool doesPassTrackSelection(const BoundTrackParameters& trk) const;
0144 
0145   // The configuration object
0146   const Config m_cfg;
0147 };
0148 
0149 }  // namespace Acts