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 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/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   using MainGridVector = GaussianGridTrackDensity::MainGridVector;
0035   using TrackGridVector = GaussianGridTrackDensity::TrackGridVector;
0036 
0037   /// @brief The Config struct
0038   struct Config {
0039     ///@param gDensity The grid density
0040     Config(GaussianGridTrackDensity gDensity) : gridDensity(gDensity) {}
0041 
0042     // The grid density object
0043     GaussianGridTrackDensity 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     State(MainGridVector mainGrid_) : mainGrid(std::move(mainGrid_)) {}
0071 
0072     // The main density grid
0073     MainGridVector mainGrid;
0074     // Map to store z-bin and track grid (i.e. the density contribution of
0075     // a single track to the main grid) for every single track
0076     std::map<InputTrack, std::pair<int, TrackGridVector>> binAndTrackGridMap;
0077 
0078     // Map to store bool if track has passed track selection or not
0079     std::map<InputTrack, bool> trackSelectionMap;
0080 
0081     // Store tracks that have been removed from track collection. These
0082     // track will be removed from the main grid
0083     std::vector<InputTrack> tracksToRemove;
0084 
0085     bool isInitialized = false;
0086   };
0087 
0088   /// @brief Function that finds single vertex candidate
0089   ///
0090   /// @param trackVector Input track collection
0091   /// @param vertexingOptions Vertexing options
0092   /// @param anyState The state object to cache the density grid
0093   /// and density contributions of each track, to be used
0094   /// if cacheGridStateForTrackRemoval == true
0095   ///
0096   /// @return Vector of vertices, filled with a single
0097   ///         vertex (for consistent interfaces)
0098   Result<std::vector<Vertex>> find(
0099       const std::vector<InputTrack>& trackVector,
0100       const VertexingOptions& vertexingOptions,
0101       IVertexFinder::State& anyState) const override;
0102 
0103   IVertexFinder::State makeState(
0104       const Acts::MagneticFieldContext& /*mctx*/) const override {
0105     return IVertexFinder::State{
0106         std::in_place_type<State>,
0107         MainGridVector{m_cfg.gridDensity.config().mainGridSize}};
0108   }
0109 
0110   void setTracksToRemove(
0111       IVertexFinder::State& anyState,
0112       const std::vector<InputTrack>& removedTracks) const override {
0113     auto& state = anyState.template as<State>();
0114     state.tracksToRemove = removedTracks;
0115   }
0116 
0117   /// @brief Constructor for user-defined InputTrack type
0118   ///
0119   /// @param cfg Configuration object
0120   GridDensityVertexFinder(const Config& cfg) : m_cfg(cfg) {
0121     if (!m_cfg.extractParameters.connected()) {
0122       throw std::invalid_argument(
0123           "GridDensityVertexFinder: "
0124           "No track parameter extractor provided.");
0125     }
0126   }
0127 
0128  private:
0129   /// @brief Checks if a track passes the selection criteria for seeding
0130   ///
0131   /// @param trk The track
0132   ///
0133   /// @return Bool track passes selection
0134   bool doesPassTrackSelection(const BoundTrackParameters& trk) const;
0135 
0136   // The configuration object
0137   const Config m_cfg;
0138 };
0139 
0140 }  // namespace Acts