Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:59

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