Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:11:21

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   using DensityMap = AdaptiveGridTrackDensity::DensityMap;
0036 
0037   /// @brief The Config struct
0038   struct Config {
0039     ///@param gDensity The grid density
0040     explicit Config(const AdaptiveGridTrackDensity& gDensity)
0041         : gridDensity(gDensity) {}
0042 
0043     // The grid density object
0044     AdaptiveGridTrackDensity gridDensity;
0045 
0046     // Cache the main grid and the density contributions (trackGrid and z-bin)
0047     // for every single track.
0048     // This option enables the possibility to calculate the entire main grid
0049     // only once in the first iteration. If tracks are removed from the track
0050     // collection, the individual track density contributions to the main grid
0051     // can just be removed without calculating the entire grid from scratch.
0052     bool cacheGridStateForTrackRemoval = true;
0053 
0054     // Maximum d0 impact parameter significance to use a track
0055     double maxD0TrackSignificance = 3.5;
0056     // Maximum z0 impact parameter significance to use a track
0057     double maxZ0TrackSignificance = 12.;
0058     // The actual corresponding cut values in the algorithm
0059     double d0SignificanceCut = maxD0TrackSignificance * maxD0TrackSignificance;
0060     double z0SignificanceCut = maxZ0TrackSignificance * maxZ0TrackSignificance;
0061     bool estimateSeedWidth = false;
0062 
0063     // Function to extract parameters from InputTrack
0064     InputTrack::Extractor extractParameters;
0065   };
0066 
0067   /// @brief The State struct
0068   ///
0069   /// Only needed if cacheGridStateForTrackRemoval == true
0070   struct State {
0071     // Map from the z bin values to the corresponding track density
0072     DensityMap mainDensityMap;
0073 
0074     // Map from input track to corresponding track density map
0075     std::unordered_map<InputTrack, DensityMap> trackDensities;
0076 
0077     // Store tracks that have been removed from track collection. These
0078     // tracks will be removed from the main grid
0079     std::vector<InputTrack> tracksToRemove;
0080 
0081     bool isInitialized = false;
0082   };
0083 
0084   /// @brief Function that finds single vertex candidate
0085   ///
0086   /// @param trackVector Input track collection
0087   /// @param vertexingOptions Vertexing options
0088   /// @param anyState The state object to cache the density grid
0089   /// and density contributions of each track, to be used
0090   /// if cacheGridStateForTrackRemoval == true
0091   ///
0092   /// @return Vector of vertices, filled with a single
0093   ///         vertex (for consistent interfaces)
0094   Result<std::vector<Vertex>> find(
0095       const std::vector<InputTrack>& trackVector,
0096       const VertexingOptions& vertexingOptions,
0097       IVertexFinder::State& anyState) const override;
0098 
0099   IVertexFinder::State makeState(
0100       const Acts::MagneticFieldContext& /*mctx*/) const override {
0101     return IVertexFinder::State{State{}};
0102   }
0103 
0104   void setTracksToRemove(
0105       IVertexFinder::State& anyState,
0106       const std::vector<InputTrack>& removedTracks) const override {
0107     auto& state = anyState.template as<State>();
0108     state.tracksToRemove = removedTracks;
0109   }
0110 
0111   /// @brief Constructor for user-defined InputTrack type
0112   ///
0113   /// @param cfg Configuration object
0114   explicit AdaptiveGridDensityVertexFinder(const Config& cfg) : m_cfg(cfg) {}
0115 
0116  private:
0117   /// @brief Checks if a track passes the selection criteria for seeding
0118   ///
0119   /// @param trk The track
0120   ///
0121   /// @return Bool track passes selection
0122   bool doesPassTrackSelection(const BoundTrackParameters& trk) const;
0123 
0124   // The configuration object
0125   const Config m_cfg;
0126 };
0127 
0128 }  // namespace Acts