![]() |
|
|||
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/Definitions/Algebra.hpp" 0012 #include "Acts/Definitions/Units.hpp" 0013 #include "Acts/EventData/TrackParameters.hpp" 0014 #include "Acts/MagneticField/MagneticFieldContext.hpp" 0015 #include "Acts/Utilities/Logger.hpp" 0016 #include "Acts/Utilities/Result.hpp" 0017 #include "Acts/Vertexing/AMVFInfo.hpp" 0018 #include "Acts/Vertexing/AdaptiveMultiVertexFitter.hpp" 0019 #include "Acts/Vertexing/IVertexFinder.hpp" 0020 #include "Acts/Vertexing/ImpactPointEstimator.hpp" 0021 #include "Acts/Vertexing/TrackLinearizer.hpp" 0022 #include "Acts/Vertexing/VertexingOptions.hpp" 0023 0024 #include <functional> 0025 #include <type_traits> 0026 0027 namespace Acts { 0028 0029 /// @brief Implements an iterative vertex finder 0030 class AdaptiveMultiVertexFinder final : public IVertexFinder { 0031 using VertexFitter = AdaptiveMultiVertexFitter; 0032 using VertexFitterState = VertexFitter::State; 0033 0034 public: 0035 /// Configuration struct 0036 struct Config { 0037 /// @brief Config constructor 0038 /// 0039 /// @param fitter The vertex fitter 0040 /// @param sfinder The seed finder 0041 /// @param ipEst ImpactPointEstimator 0042 /// @param bIn Input magnetic field 0043 Config(VertexFitter fitter, std::shared_ptr<const IVertexFinder> sfinder, 0044 ImpactPointEstimator ipEst, 0045 std::shared_ptr<const MagneticFieldProvider> bIn) 0046 : vertexFitter(std::move(fitter)), 0047 seedFinder(std::move(sfinder)), 0048 ipEstimator(std::move(ipEst)), 0049 bField{std::move(bIn)} {} 0050 0051 /// Vertex fitter 0052 VertexFitter vertexFitter; 0053 0054 /// Vertex seed finder 0055 std::shared_ptr<const IVertexFinder> seedFinder; 0056 0057 /// ImpactPointEstimator 0058 ImpactPointEstimator ipEstimator; 0059 0060 std::shared_ptr<const MagneticFieldProvider> bField; 0061 0062 /// Max z interval used for adding tracks to fit: 0063 /// When adding a new vertex to the multi vertex fit, 0064 /// only the tracks whose z at PCA is closer 0065 /// to the seeded vertex than tracksMaxZinterval 0066 /// are added to this new vertex. 0067 /// 0068 /// Note: If you cut too hard, you cut out 0069 /// the good cases where the seed finder is not 0070 /// reliable, but the fit would be still able to converge 0071 /// towards the right vertex. If you cut too soft, you 0072 /// consider a lot of tracks which just slow down the fit. 0073 double tracksMaxZinterval = 3. * Acts::UnitConstants::mm; 0074 0075 /// Maximum allowed significance of track position to vertex seed to 0076 /// consider track as compatible to vertex. If useTime is set to true, the 0077 /// time coordinate also contributes to the significance and 0078 /// tracksMaxSignificance needs to be increased. 5 corresponds to a p-value 0079 /// of ~0.92 using `chi2(x=5,ndf=2)` 0080 double tracksMaxSignificance = 5.; 0081 0082 /// Max chi2 value for which tracks are considered compatible with 0083 /// the fitted vertex. These tracks are removed from the seedTracks 0084 /// after the fit has been performed. 0085 double maxVertexChi2 = 18.42; 0086 0087 /// Perform a 'real' multi-vertex fit as intended by the algorithm. 0088 /// If switched to true, always all (!) tracks are considered to be 0089 /// added to the new vertex candidate after seeding. If switched to 0090 /// false, only the seedTracks, i.e. all tracks that are considered 0091 /// as outliers of previously fitted vertices, are used. 0092 bool doRealMultiVertex = true; 0093 0094 /// Decides if you want to use the ```vertexCompatibility``` of the 0095 /// track (set to true) or the ```chi2Track``` (set to false) as an 0096 /// estimate for a track being an outlier or not. 0097 /// In case the track refitting is switched on in the AMVFitter, you 0098 /// may want to use the refitted ```chi2Track```. 0099 bool useFastCompatibility = true; 0100 0101 /// Maximum significance on the distance between two vertices 0102 /// to allow merging of two vertices. 0103 /// 3 corresponds to a p-value of ~0.92 using `chi2(x=3,ndf=1)` 0104 double maxMergeVertexSignificance = 3.; 0105 0106 /// Minimum weight a track has to have to be considered a compatible 0107 /// track with a vertex candidate. 0108 /// 0109 /// Note: This value has to be the same as the one in the AMVFitter. 0110 double minWeight = 0.0001; 0111 0112 /// Maximal number of iterations in the finding procedure 0113 int maxIterations = 100; 0114 0115 /// Include also single track vertices 0116 bool addSingleTrackVertices = false; 0117 0118 /// If doFullSplitting == true, we check the 3D distance (if useTime == 0119 /// false) or the 4D distance (if useTime == true) of the vertices to 0120 /// determine whether they are merged. 0121 /// If doFullSplitting == false, we check the z distance (if useTime == 0122 /// false) or the z-t distance (if useTime == true) of the vertices to 0123 /// determine whether they are merged. 0124 bool doFullSplitting = false; 0125 0126 /// Maximum vertex contamination value 0127 double maximumVertexContamination = 0.5; 0128 0129 /// Use seed vertex as a constraint for the fit 0130 bool useSeedConstraint = true; 0131 0132 /// Variances of the 4D vertex position before the vertex fit if no beamspot 0133 /// constraint is provided 0134 Vector4 initialVariances = Vector4::Constant(1e+8); 0135 0136 /// Default fitQuality for constraint vertex in case no beamspot 0137 /// constraint is provided 0138 std::pair<double, double> defaultConstrFitQuality{0., -3.}; 0139 0140 /// Use the full available vertex covariance information after 0141 /// seeding for the IP estimation. In original implementation 0142 /// this is not (!) done, however, this is probably not correct. 0143 /// So definitely consider setting this to true. 0144 bool useVertexCovForIPEstimation = false; 0145 0146 /// Use time information when assigning tracks to vertices. If this is set 0147 /// to true, useTime of the vertex fitter configuration should also be set 0148 /// to true, and time seeding should be enabled. 0149 bool useTime = false; 0150 0151 /// If set to true, the vertex finder will not break the finding loop. 0152 /// Some seeders are not able to cope with this therefore this is 0153 /// disabled by default. 0154 bool doNotBreakWhileSeeding = false; 0155 0156 /// Function to extract parameters from InputTrack 0157 InputTrack::Extractor extractParameters; 0158 }; 0159 0160 /// State struct for fulfilling interface 0161 struct State { 0162 std::reference_wrapper<const MagneticFieldContext> magContext; 0163 0164 IVertexFinder::State seedFinderState; 0165 }; 0166 0167 /// @brief Constructor for user-defined InputTrack_t type != 0168 /// BoundTrackParameters 0169 /// 0170 /// @param cfg Configuration object 0171 /// @param logger The logging instance 0172 explicit AdaptiveMultiVertexFinder( 0173 Config cfg, std::unique_ptr<const Logger> logger = getDefaultLogger( 0174 "AdaptiveMultiVertexFinder", Logging::INFO)) 0175 : m_cfg(std::move(cfg)), m_logger(std::move(logger)) { 0176 if (!m_cfg.extractParameters.connected()) { 0177 throw std::invalid_argument( 0178 "AdaptiveMultiVertexFinder: " 0179 "No function to extract parameters " 0180 "from InputTrack provided."); 0181 } 0182 0183 if (!m_cfg.seedFinder) { 0184 throw std::invalid_argument( 0185 "AdaptiveMultiVertexFinder: " 0186 "No vertex fitter provided."); 0187 } 0188 } 0189 0190 AdaptiveMultiVertexFinder(AdaptiveMultiVertexFinder&&) = default; 0191 0192 /// @brief Function that performs the adaptive 0193 /// multi-vertex finding 0194 /// 0195 /// @param allTracks Input track collection 0196 /// @param vertexingOptions Vertexing options 0197 /// @param anyState The state object 0198 /// 0199 /// @return Vector of all reconstructed vertices 0200 Result<std::vector<Vertex>> find( 0201 const std::vector<InputTrack>& allTracks, 0202 const VertexingOptions& vertexingOptions, 0203 IVertexFinder::State& anyState) const override; 0204 0205 IVertexFinder::State makeState( 0206 const Acts::MagneticFieldContext& mctx) const override { 0207 return IVertexFinder::State{ 0208 State{mctx, IVertexFinder::State{m_cfg.seedFinder->makeState(mctx)}}}; 0209 } 0210 0211 void setTracksToRemove( 0212 IVertexFinder::State& /*state*/, 0213 const std::vector<InputTrack>& /*removedTracks*/) const override { 0214 // Nothing to do here 0215 } 0216 0217 private: 0218 /// Configuration object 0219 Config m_cfg; 0220 0221 /// Logging instance 0222 std::unique_ptr<const Logger> m_logger; 0223 0224 /// Private access to logging instance 0225 const Logger& logger() const { return *m_logger; } 0226 0227 /// @brief Calls the seed finder and sets constraints on the found seed 0228 /// vertex if desired 0229 /// 0230 /// @param trackVector All tracks to be used for seeding 0231 /// @param currentConstraint Vertex constraint 0232 /// @param vertexingOptions Vertexing options 0233 /// @param seedFinderState The seed finder state 0234 /// @param removedSeedTracks Seed track that have been removed 0235 /// from seed track collection in last iteration 0236 /// 0237 /// @return The seed vertex 0238 Result<std::optional<Vertex>> doSeeding( 0239 const std::vector<InputTrack>& trackVector, Vertex& currentConstraint, 0240 const VertexingOptions& vertexingOptions, 0241 IVertexFinder::State& seedFinderState, 0242 const std::vector<InputTrack>& removedSeedTracks) const; 0243 0244 /// @brief Sets constraint vertex after seeding 0245 /// 0246 /// @param currentConstraint Vertex constraint 0247 /// @param useVertexConstraintInFit Indicates whether constraint is used during vertex fit 0248 /// @param seedVertex Seed vertex 0249 void setConstraintAfterSeeding(Vertex& currentConstraint, 0250 bool useVertexConstraintInFit, 0251 Vertex& seedVertex) const; 0252 0253 /// @brief Calculates the IP significance of a track to a given vertex 0254 /// 0255 /// @param track The track 0256 /// @param vtx The vertex 0257 /// @param vertexingOptions Vertexing options 0258 /// 0259 /// @return The IP significance 0260 Result<double> getIPSignificance( 0261 const InputTrack& track, const Vertex& vtx, 0262 const VertexingOptions& vertexingOptions) const; 0263 0264 /// @brief Adds compatible track to vertex candidate 0265 /// 0266 /// @param tracks The tracks 0267 /// @param vtx The vertex candidate 0268 /// @param[out] fitterState The vertex fitter state 0269 /// @param vertexingOptions Vertexing options 0270 Result<void> addCompatibleTracksToVertex( 0271 const std::vector<InputTrack>& tracks, Vertex& vtx, 0272 VertexFitterState& fitterState, 0273 const VertexingOptions& vertexingOptions) const; 0274 0275 /// @brief Method that tries to recover from cases where no tracks 0276 /// were added to the vertex candidate after seeding 0277 /// 0278 /// @param allTracks The tracks to be considered (either origTrack or 0279 /// seedTracks) 0280 /// @param seedTracks The seed tracks 0281 /// @param[out] vtx The vertex candidate 0282 /// @param currentConstraint Vertex constraint 0283 /// @param[out] fitterState The vertex fitter state 0284 /// @param vertexingOptions Vertexing options 0285 /// 0286 /// return True if recovery was successful, false otherwise 0287 Result<bool> canRecoverFromNoCompatibleTracks( 0288 const std::vector<InputTrack>& allTracks, 0289 const std::vector<InputTrack>& seedTracks, Vertex& vtx, 0290 const Vertex& currentConstraint, VertexFitterState& fitterState, 0291 const VertexingOptions& vertexingOptions) const; 0292 0293 /// @brief Method that tries to prepare the vertex for the fit 0294 /// 0295 /// @param allTracks The tracks to be considered (either origTrack or 0296 /// seedTracks) 0297 /// @param seedTracks The seed tracks 0298 /// @param[out] vtx The vertex candidate 0299 /// @param currentConstraint Vertex constraint 0300 /// @param[out] fitterState The vertex fitter state 0301 /// @param vertexingOptions Vertexing options 0302 /// 0303 /// @return True if preparation was successful, false otherwise 0304 Result<bool> canPrepareVertexForFit( 0305 const std::vector<InputTrack>& allTracks, 0306 const std::vector<InputTrack>& seedTracks, Vertex& vtx, 0307 const Vertex& currentConstraint, VertexFitterState& fitterState, 0308 const VertexingOptions& vertexingOptions) const; 0309 0310 /// @brief Method that checks if vertex is a good vertex and if 0311 /// compatible tracks are available 0312 /// 0313 /// @param vtx The vertex candidate 0314 /// @param seedTracks The seed tracks 0315 /// @param fitterState The vertex fitter state 0316 /// @param useVertexConstraintInFit Indicates whether constraint is used in the vertex fit 0317 /// 0318 /// @return pair(nCompatibleTracks, isGoodVertex) 0319 std::pair<int, bool> checkVertexAndCompatibleTracks( 0320 Vertex& vtx, const std::vector<InputTrack>& seedTracks, 0321 VertexFitterState& fitterState, bool useVertexConstraintInFit) const; 0322 0323 /// @brief Method that removes all tracks that are compatible with 0324 /// current vertex from seedTracks 0325 /// 0326 /// @param vtx The vertex candidate 0327 /// @param[out] seedTracks The seed tracks 0328 /// @param fitterState The vertex fitter state 0329 /// @param[out] removedSeedTracks Collection of seed track that will be 0330 /// removed 0331 void removeCompatibleTracksFromSeedTracks( 0332 Vertex& vtx, std::vector<InputTrack>& seedTracks, 0333 VertexFitterState& fitterState, 0334 std::vector<InputTrack>& removedSeedTracks) const; 0335 0336 /// @brief Method that tries to remove an incompatible track 0337 /// from seed tracks after removing a compatible track failed. 0338 /// 0339 /// @param vtx The vertex candidate 0340 /// @param[out] seedTracks The seed tracks 0341 /// @param fitterState The vertex fitter state 0342 /// @param[out] removedSeedTracks Collection of seed track that will be 0343 /// removed 0344 /// @param[in] geoCtx The geometry context to access global positions 0345 /// 0346 /// @return Incompatible track was removed 0347 bool removeTrackIfIncompatible(Vertex& vtx, 0348 std::vector<InputTrack>& seedTracks, 0349 VertexFitterState& fitterState, 0350 std::vector<InputTrack>& removedSeedTracks, 0351 const GeometryContext& geoCtx) const; 0352 0353 /// @brief Method that evaluates if the new vertex candidate should 0354 /// be kept, i.e. saved, or not 0355 /// 0356 /// @param vtx The vertex candidate 0357 /// @param allVertices All so far found vertices 0358 /// @param fitterState The vertex fitter state 0359 /// 0360 /// @return Keep new vertex 0361 Result<bool> keepNewVertex(Vertex& vtx, 0362 const std::vector<Vertex*>& allVertices, 0363 VertexFitterState& fitterState) const; 0364 0365 /// @brief Method that evaluates if the new vertex candidate is 0366 /// merged with one of the previously found vertices 0367 /// 0368 /// @param vtx The vertex candidate 0369 /// @param allVertices All vertices that were found so far 0370 /// 0371 /// @return Bool indicating whether the vertex is merged 0372 Result<bool> isMergedVertex(const Vertex& vtx, 0373 const std::vector<Vertex*>& allVertices) const; 0374 0375 /// @brief Method that deletes last vertex from list of all vertices 0376 /// and refits all vertices afterwards 0377 /// 0378 /// @param vtx The last added vertex which will be removed 0379 /// @param allVertices Vector containing the unique_ptr to vertices 0380 /// @param allVerticesPtr Vector containing the actual addresses 0381 /// @param fitterState The current vertex fitter state 0382 /// @param vertexingOptions Vertexing options 0383 Result<void> deleteLastVertex( 0384 Vertex& vtx, std::vector<std::unique_ptr<Vertex>>& allVertices, 0385 std::vector<Vertex*>& allVerticesPtr, VertexFitterState& fitterState, 0386 const VertexingOptions& vertexingOptions) const; 0387 0388 /// @brief Prepares the output vector of vertices 0389 /// 0390 /// @param allVerticesPtr Vector of pointers to vertices 0391 /// @param fitterState The vertex fitter state 0392 /// 0393 /// @return The output vertex collection 0394 Result<std::vector<Vertex>> getVertexOutputList( 0395 const std::vector<Vertex*>& allVerticesPtr, 0396 VertexFitterState& fitterState) const; 0397 }; 0398 0399 } // namespace Acts
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |