Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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/MagneticField/MagneticFieldProvider.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016 #include "Acts/Utilities/Result.hpp"
0017 #include "Acts/Vertexing/FullBilloirVertexFitter.hpp"
0018 #include "Acts/Vertexing/HelicalTrackLinearizer.hpp"
0019 #include "Acts/Vertexing/IVertexFinder.hpp"
0020 #include "Acts/Vertexing/ImpactPointEstimator.hpp"
0021 #include "Acts/Vertexing/TrackLinearizer.hpp"
0022 #include "Acts/Vertexing/Vertex.hpp"
0023 #include "Acts/Vertexing/VertexingOptions.hpp"
0024 
0025 #include <functional>
0026 
0027 namespace Acts {
0028 
0029 /// @class IterativeVertexFinder
0030 ///
0031 /// @brief Implements an iterative vertex finder
0032 ///
0033 ////////////////////////////////////////////////////////////
0034 ///
0035 /// Brief description of the algorithm implemented:
0036 /// Iterative vertex finder which iteratively finds and fits vertices:
0037 /// 1. A list of seed tracks (`seedTracks`, which is the same as the
0038 ///   input track list to the finder at the very first iteration) is used
0039 ///   to retrieve a single vertex seed using the ZScanVertexFinder.
0040 /// 2. All tracks compatible with the current vertex seed are kept and used
0041 ///   for fitting the single vertex.
0042 /// 3.1 If the vertex is a 'good' vertex (i.e. meets requirements) and no
0043 ///   track reassignment after first fit is required, go to step 4. If vertex
0044 ///   is not a good vertex, remove all tracks in tracksToFit from seedTracks.
0045 /// 3.2 If vertex meets requirements and track reassignment after first fit
0046 ///   is required, iterate over all previously found vertices ("old vertex")
0047 ///   and over all their tracksAtVertex. Compare compatibility of each track
0048 ///   with old vertex and current vertex. If track is more compatible with
0049 ///   current vertex, remove track from old vertex, put track back to
0050 ///   tracksToFit and refit current vertex with additional track.
0051 /// 4. If good vertex, `removeUsedCompatibleTracks` method is called, which
0052 ///   removes all used tracks that are compatible with the fitted vertex
0053 ///   from `tracksToFit` and `seedTracks`. It also removes outliers tracks
0054 ///   from tracksAtVertex if not compatible.
0055 /// 5. Add vertex to vertexCollection
0056 /// 6. Repeat until no seedTracks are left or max. number of vertices found
0057 class IterativeVertexFinder final : public IVertexFinder {
0058   using VertexFitter = FullBilloirVertexFitter;
0059 
0060  public:
0061   /// Configuration struct
0062   struct Config {
0063     /// @brief Config constructor
0064     ///
0065     /// @param fitter Vertex fitter
0066     /// @param sfinder The seed finder
0067     /// @param est ImpactPointEstimator
0068     Config(VertexFitter fitter, std::shared_ptr<IVertexFinder> sfinder,
0069            ImpactPointEstimator est)
0070         : vertexFitter(std::move(fitter)),
0071           seedFinder(std::move(sfinder)),
0072           ipEst(std::move(est)) {}
0073 
0074     /// Vertex fitter
0075     VertexFitter vertexFitter;
0076 
0077     /// Track linearizer
0078     TrackLinearizer trackLinearizer;
0079 
0080     /// Vertex seed finder
0081     std::shared_ptr<IVertexFinder> seedFinder;
0082 
0083     /// ImpactPointEstimator
0084     ImpactPointEstimator ipEst;
0085 
0086     /// Vertex finder configuration variables.
0087     /// Tracks that are within a distance of
0088     ///
0089     /// significanceCutSeeding * sqrt(sigma(d0)^2+sigma(z0)^2)
0090     ///
0091     /// are considered compatible with the vertex.
0092     double significanceCutSeeding = 10;
0093     /// Maximum chi-squared cut for seeding vertex candidates
0094     double maximumChi2cutForSeeding = 36.;
0095     /// Maximum number of vertices to find per event
0096     int maxVertices = 50;
0097 
0098     /// Assign a certain fraction of compatible tracks to a different (so-called
0099     /// split) vertex if boolean is set to true.
0100     bool createSplitVertices = false;
0101     /// Inverse of the fraction of tracks that will be assigned to the split
0102     /// vertex. E.g., if splitVerticesTrkInvFraction = 2, about 50% of
0103     /// compatible tracks will be assigned to the split vertex.
0104     int splitVerticesTrkInvFraction = 2;
0105     /// Flag to enable track reassignment after first vertex fit
0106     bool reassignTracksAfterFirstFit = false;
0107     /// Flag to enable maximum tracks cut per vertex
0108     bool doMaxTracksCut = false;
0109     /// Maximum number of tracks to consider per vertex
0110     int maxTracks = 5000;
0111     /// Minimum track weight threshold for vertex association
0112     double cutOffTrackWeight = 0.01;
0113     /// If `reassignTracksAfterFirstFit` is set this threshold will be used to
0114     /// decide if a track should be checked for reassignment to other vertices
0115     double cutOffTrackWeightReassign = 1;
0116 
0117     /// Function to extract parameters from InputTrack
0118     InputTrack::Extractor extractParameters;
0119 
0120     /// Magnetic field provider
0121     std::shared_ptr<const MagneticFieldProvider> field;
0122   };
0123 
0124   /// State struct
0125   struct State {
0126     /// Constructor with magnetic field provider and context
0127     /// @param field Magnetic field provider for track extrapolation
0128     /// @param _magContext Magnetic field context for field evaluation
0129     State(const MagneticFieldProvider& field,
0130           const Acts::MagneticFieldContext& _magContext)
0131         : magContext(_magContext),
0132           ipState{field.makeCache(magContext)},
0133           fieldCache(field.makeCache(magContext)) {}
0134 
0135     /// Reference to magnetic field context for vertex finding
0136     std::reference_wrapper<const Acts::MagneticFieldContext> magContext;
0137 
0138     /// The IP estimator state
0139     ImpactPointEstimator::State ipState;
0140 
0141     /// Cached magnetic field information for efficient access
0142     MagneticFieldProvider::Cache fieldCache;
0143   };
0144 
0145   /// @brief Constructor for user-defined InputTrack type
0146   ///
0147   /// @param cfg Configuration object
0148   /// @param logger The logging instance
0149   explicit IterativeVertexFinder(Config cfg,
0150                                  std::unique_ptr<const Logger> logger =
0151                                      getDefaultLogger("IterativeVertexFinder",
0152                                                       Logging::INFO));
0153 
0154   /// @brief Finds vertices corresponding to input trackVector
0155   ///
0156   /// @param trackVector Input tracks
0157   /// @param vertexingOptions Vertexing options
0158   /// @param anyState State for fulfilling interfaces
0159   ///
0160   /// @return Collection of vertices found by finder
0161   Result<std::vector<Vertex>> find(
0162       const std::vector<InputTrack>& trackVector,
0163       const VertexingOptions& vertexingOptions,
0164       IVertexFinder::State& anyState) const override;
0165 
0166   IVertexFinder::State makeState(
0167       const MagneticFieldContext& mctx) const override {
0168     return IVertexFinder::State{State{*m_cfg.field, mctx}};
0169   }
0170 
0171   void setTracksToRemove(
0172       IVertexFinder::State& /*anyState*/,
0173       const std::vector<InputTrack>& /*removedTracks*/) const override {
0174     // Nothing to do here
0175   }
0176 
0177  private:
0178   /// Configuration object
0179   const Config m_cfg;
0180 
0181   /// Logging instance
0182   std::unique_ptr<const Logger> m_logger;
0183 
0184   /// Private access to logging instance
0185   const Logger& logger() const { return *m_logger; }
0186 
0187   /// @brief Method that calls seed finder to retrieve a vertex seed
0188   ///
0189   /// @param state The state object
0190   /// @param seedTracks Seeding tracks
0191   /// @param vertexingOptions Vertexing options
0192   ///
0193   /// @return Vertex seed
0194   Result<std::optional<Vertex>> getVertexSeed(
0195       State& state, const std::vector<InputTrack>& seedTracks,
0196       const VertexingOptions& vertexingOptions) const;
0197 
0198   /// @brief Removes all tracks in tracksToRemove from seedTracks
0199   ///
0200   /// @param tracksToRemove Tracks to be removed from seedTracks
0201   /// @param seedTracks List to remove tracks from
0202   void removeTracks(const std::vector<InputTrack>& tracksToRemove,
0203                     std::vector<InputTrack>& seedTracks) const;
0204 
0205   /// @brief Function for calculating how compatible
0206   /// a given track is to a given vertex
0207   ///
0208   /// @param params Track parameters
0209   /// @param vertex The vertex
0210   /// @param perigeeSurface The perigee surface at vertex position
0211   /// @param vertexingOptions Vertexing options
0212   /// @param state The state object
0213   Result<double> getCompatibility(const BoundTrackParameters& params,
0214                                   const Vertex& vertex,
0215                                   const Surface& perigeeSurface,
0216                                   const VertexingOptions& vertexingOptions,
0217                                   State& state) const;
0218 
0219   /// @brief Function that removes used tracks compatible with
0220   /// current vertex (`vertex`) from `tracksToFit` and `seedTracks`
0221   /// as well as outliers from vertex.tracksAtVertex
0222   ///
0223   /// @param vertex Current vertex
0224   /// @param tracksToFit Tracks used to fit `vertex`
0225   /// @param seedTracks Tracks used for vertex seeding
0226   /// @param vertexingOptions Vertexing options
0227   /// @param state The state object
0228   Result<void> removeUsedCompatibleTracks(
0229       Vertex& vertex, std::vector<InputTrack>& tracksToFit,
0230       std::vector<InputTrack>& seedTracks,
0231       const VertexingOptions& vertexingOptions, State& state) const;
0232 
0233   /// @brief Function that fills vector with tracks compatible with seed vertex
0234   ///
0235   /// @param seedTracks List of all available tracks used for seeding
0236   /// @param seedVertex Seed vertex
0237   /// @param tracksToFitOut Tracks to fit
0238   /// @param tracksToFitSplitVertexOut Tracks to fit to split vertex
0239   /// @param vertexingOptions Vertexing options
0240   /// @param state The state object
0241   Result<void> fillTracksToFit(
0242       const std::vector<InputTrack>& seedTracks, const Vertex& seedVertex,
0243       std::vector<InputTrack>& tracksToFitOut,
0244       std::vector<InputTrack>& tracksToFitSplitVertexOut,
0245       const VertexingOptions& vertexingOptions, State& state) const;
0246 
0247   /// @brief Function that reassigns tracks from other vertices
0248   ///        to the current vertex if they are more compatible
0249   ///
0250   /// @param vertexCollection Collection of vertices
0251   /// @param currentVertex Current vertex to assign tracks to
0252   /// @param tracksToFit Tracks to fit vector
0253   /// @param seedTracks Seed tracks vector
0254   /// @param origTracks Vector of original track objects
0255   /// @param vertexingOptions Vertexing options
0256   /// @param state The state object
0257   ///
0258   /// @return Bool if currentVertex is still a good vertex
0259   Result<bool> reassignTracksToNewVertex(
0260       std::vector<Vertex>& vertexCollection, Vertex& currentVertex,
0261       std::vector<InputTrack>& tracksToFit, std::vector<InputTrack>& seedTracks,
0262       const std::vector<InputTrack>& origTracks,
0263       const VertexingOptions& vertexingOptions, State& state) const;
0264 
0265   /// @brief Counts all tracks that are significant for a vertex
0266   ///
0267   /// @param vtx The vertex
0268   ///
0269   /// @return Number of significant tracks
0270   int countSignificantTracks(const Vertex& vtx) const;
0271 };
0272 
0273 }  // namespace Acts