From 32be500aeebbc93fd08078bf14949be0da9a6308 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 19 Dec 2023 22:28:52 +0100 Subject: [PATCH 01/14] Add IVertexFinder and basic compliance + usage --- .../AdaptiveGridDensityVertexFinder.hpp | 11 ++++- .../AdaptiveGridDensityVertexFinder.ipp | 29 +++++------ .../Vertexing/AdaptiveMultiVertexFinder.hpp | 21 ++++++-- .../Vertexing/AdaptiveMultiVertexFinder.ipp | 11 +++-- .../Vertexing/GridDensityVertexFinder.hpp | 15 +++++- .../Vertexing/GridDensityVertexFinder.ipp | 34 ++++++------- Core/include/Acts/Vertexing/IVertexFinder.hpp | 39 +++++++++++++++ .../Acts/Vertexing/IterativeVertexFinder.hpp | 18 ++++++- .../Acts/Vertexing/IterativeVertexFinder.ipp | 22 +++++---- .../Vertexing/TrackDensityVertexFinder.hpp | 11 ++++- .../Vertexing/TrackDensityVertexFinder.ipp | 4 +- .../Acts/Vertexing/VertexFinderConcept.hpp | 48 ------------------- .../Acts/Vertexing/ZScanVertexFinder.hpp | 11 ++++- .../Acts/Vertexing/ZScanVertexFinder.ipp | 4 +- .../AdaptiveMultiVertexFinderAlgorithm.cpp | 2 +- .../src/IterativeVertexFinderAlgorithm.cpp | 3 +- .../AdaptiveMultiVertexFinderTests.cpp | 9 ++-- .../GridDensityVertexFinderTests.cpp | 17 +++---- .../Vertexing/IterativeVertexFinderTests.cpp | 20 ++------ .../TrackDensityVertexFinderTests.cpp | 8 ++-- .../Core/Vertexing/ZScanVertexFinderTests.cpp | 11 +---- 21 files changed, 195 insertions(+), 153 deletions(-) create mode 100644 Core/include/Acts/Vertexing/IVertexFinder.hpp delete mode 100644 Core/include/Acts/Vertexing/VertexFinderConcept.hpp diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp index 5e8ca0bd7d9..db946a3f62f 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp @@ -12,6 +12,7 @@ #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/AdaptiveGridTrackDensity.hpp" #include "Acts/Vertexing/DummyVertexFitter.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/Vertex.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" @@ -31,7 +32,7 @@ namespace Acts { /// /// @tparam vfitter_t Vertex fitter type template > -class AdaptiveGridDensityVertexFinder { +class AdaptiveGridDensityVertexFinder final : public IVertexFinder { using GridDensity = AdaptiveGridTrackDensity; public: @@ -95,7 +96,13 @@ class AdaptiveGridDensityVertexFinder { /// vertex (for consistent interfaces) Result> find(const std::vector& trackVector, const VertexingOptions& vertexingOptions, - State& state) const; + IVertexFinder::State& state) const override; + + IVertexFinder::State makeState() const override { + return IVertexFinder::State{State{}}; + } + + bool hasTrivialState() const override { return true; } /// @brief Constructor for user-defined InputTrack type /// diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp index 9ae2ac50f67..83dda993f26 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp @@ -9,21 +9,22 @@ template auto Acts::AdaptiveGridDensityVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, State& state) const + const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const -> Result> { + auto& thisState = state.as(); // Remove density contributions from tracks removed from track collection - if (m_cfg.cacheGridStateForTrackRemoval && state.isInitialized && - !state.tracksToRemove.empty()) { - for (auto trk : state.tracksToRemove) { - auto it = state.trackDensities.find(trk); - if (it == state.trackDensities.end()) { + if (m_cfg.cacheGridStateForTrackRemoval && thisState.isInitialized && + !thisState.tracksToRemove.empty()) { + for (auto trk : thisState.tracksToRemove) { + auto it = thisState.trackDensities.find(trk); + if (it == thisState.trackDensities.end()) { // Track was never added to grid, so cannot remove it continue; } - m_cfg.gridDensity.subtractTrack(it->second, state.mainDensityMap); + m_cfg.gridDensity.subtractTrack(it->second, thisState.mainDensityMap); } } else { - state.mainDensityMap = DensityMap(); + thisState.mainDensityMap = DensityMap(); // Fill with track densities for (auto trk : trackVector) { const BoundTrackParameters& trkParams = m_cfg.extractParameters(trk); @@ -32,16 +33,16 @@ auto Acts::AdaptiveGridDensityVertexFinder::find( continue; } auto trackDensityMap = - m_cfg.gridDensity.addTrack(trkParams, state.mainDensityMap); + m_cfg.gridDensity.addTrack(trkParams, thisState.mainDensityMap); // Cache track density contribution to main grid if enabled if (m_cfg.cacheGridStateForTrackRemoval) { - state.trackDensities[trk] = std::move(trackDensityMap); + thisState.trackDensities[trk] = std::move(trackDensityMap); } } - state.isInitialized = true; + thisState.isInitialized = true; } - if (state.mainDensityMap.empty()) { + if (thisState.mainDensityMap.empty()) { // No tracks passed selection // Return empty seed, i.e. vertex at constraint position // (Note: Upstream finder should check for this break condition) @@ -55,7 +56,7 @@ auto Acts::AdaptiveGridDensityVertexFinder::find( if (!m_cfg.estimateSeedWidth) { // Get z value of highest density bin - auto maxZTRes = m_cfg.gridDensity.getMaxZTPosition(state.mainDensityMap); + auto maxZTRes = m_cfg.gridDensity.getMaxZTPosition(thisState.mainDensityMap); if (!maxZTRes.ok()) { return maxZTRes.error(); @@ -65,7 +66,7 @@ auto Acts::AdaptiveGridDensityVertexFinder::find( } else { // Get z value of highest density bin and width auto maxZTResAndWidth = - m_cfg.gridDensity.getMaxZTPositionAndWidth(state.mainDensityMap); + m_cfg.gridDensity.getMaxZTPositionAndWidth(thisState.mainDensityMap); if (!maxZTResAndWidth.ok()) { return maxZTResAndWidth.error(); diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp index c76d829fa6c..f9909b275ff 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp @@ -14,6 +14,7 @@ #include "Acts/Utilities/Logger.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/AMVFInfo.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/TrackLinearizer.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" @@ -33,7 +34,7 @@ namespace Acts { /// @tparam vfitter_t Vertex fitter type /// @tparam sfinder_t Seed finder type template -class AdaptiveMultiVertexFinder { +class AdaptiveMultiVertexFinder final : public IVertexFinder { using FitterState_t = typename vfitter_t::State; using SeedFinderState_t = typename sfinder_t::State; @@ -179,6 +180,12 @@ class AdaptiveMultiVertexFinder { "No function to extract parameters " "from InputTrack provided."); } + + if (!m_cfg.seedFinder.hasTrivialState()) { + throw std::invalid_argument( + "AdaptiveMultiVertexFinder: " + "Seed finder state must be trivial."); + } } AdaptiveMultiVertexFinder(AdaptiveMultiVertexFinder&&) = default; @@ -193,7 +200,15 @@ class AdaptiveMultiVertexFinder { /// @return Vector of all reconstructed vertices Result> find(const std::vector& allTracks, const VertexingOptions& vertexingOptions, - State& state) const; + IVertexFinder::State& state) const override; + + IVertexFinder::State makeState() const override { + return IVertexFinder::State{State{}}; + } + + bool hasTrivialState() const override { + return true; + } private: /// Configuration object @@ -221,7 +236,7 @@ class AdaptiveMultiVertexFinder { Result doSeeding( const std::vector& trackVector, Vertex& currentConstraint, const VertexingOptions& vertexingOptions, - SeedFinderState_t& seedFinderState, + IVertexFinder::State& seedFinderState, const std::vector& removedSeedTracks) const; /// @brief Sets constraint vertex after seeding diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp index 21eb89d54b6..7474156a9b7 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp @@ -12,12 +12,13 @@ template auto Acts::AdaptiveMultiVertexFinder::find( const std::vector& allTracks, - const VertexingOptions& vertexingOptions, State& /*state*/) const - -> Result> { + const VertexingOptions& vertexingOptions, + IVertexFinder::State& /*state*/) const -> Result> { if (allTracks.empty()) { ACTS_ERROR("Empty track collection handed to find method"); return VertexingError::EmptyInput; } + // Original tracks const std::vector& origTracks = allTracks; @@ -25,7 +26,7 @@ auto Acts::AdaptiveMultiVertexFinder::find( std::vector seedTracks = allTracks; FitterState_t fitterState(*m_cfg.bField, vertexingOptions.magFieldContext); - SeedFinderState_t seedFinderState; + auto seedFinderState = m_cfg.seedFinder.makeState(); std::vector> allVertices; @@ -141,13 +142,13 @@ template auto Acts::AdaptiveMultiVertexFinder::doSeeding( const std::vector& trackVector, Vertex& currentConstraint, const VertexingOptions& vertexingOptions, - SeedFinderState_t& seedFinderState, + IVertexFinder::State& seedFinderState, const std::vector& removedSeedTracks) const -> Result { VertexingOptions seedOptions = vertexingOptions; seedOptions.constraint = currentConstraint; if constexpr (NeedsRemovedTracks::value) { - seedFinderState.tracksToRemove = removedSeedTracks; + m_cfg.seedFinder.setTrackToRemove(seedFinderState, removedSeedTracks); } // Run seed finder diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp index 6a9b84be263..4e050aa150e 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp @@ -13,6 +13,7 @@ #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/DummyVertexFitter.hpp" #include "Acts/Vertexing/GaussianGridTrackDensity.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/Vertex.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" @@ -20,6 +21,10 @@ namespace Acts { +// namespace detail { +// template +// } + /// @class GridDensityVertexFinder /// @brief Vertex finder that makes use of a track density grid. /// Each single track is modelled as a 2(!)-dim Gaussian distribution grid @@ -33,7 +38,7 @@ namespace Acts { /// in the d0-z0 plane. Note: trkGridSize has to be an odd value. template > -class GridDensityVertexFinder { +class GridDensityVertexFinder final : public IVertexFinder { // Assert odd trkGridSize static_assert(trkGridSize % 2); // Assert bigger main grid than track grid @@ -109,7 +114,13 @@ class GridDensityVertexFinder { /// vertex (for consistent interfaces) Result> find(const std::vector& trackVector, const VertexingOptions& vertexingOptions, - State& state) const; + IVertexFinder::State& state) const override; + + IVertexFinder::State makeState() const override { + return IVertexFinder::State{State{}}; + } + + bool hasTrivialState() const override { return true; } /// @brief Constructor for user-defined InputTrack type /// diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp index 90a0427219d..af99874879e 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp @@ -9,22 +9,24 @@ template auto Acts::GridDensityVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, State& state) const + const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const -> Result> { + + auto& thisState = state.as(); // Remove density contributions from tracks removed from track collection - if (m_cfg.cacheGridStateForTrackRemoval && state.isInitialized && - !state.tracksToRemove.empty()) { + if (m_cfg.cacheGridStateForTrackRemoval && thisState.isInitialized && + !thisState.tracksToRemove.empty()) { // Bool to check if removable tracks, that pass selection, still exist bool couldRemoveTracks = false; - for (auto trk : state.tracksToRemove) { - if (!state.trackSelectionMap.at(trk)) { + for (auto trk : thisState.tracksToRemove) { + if (!thisState.trackSelectionMap.at(trk)) { // Track was never added to grid, so cannot remove it continue; } couldRemoveTracks = true; - auto binAndTrackGrid = state.binAndTrackGridMap.at(trk); + auto binAndTrackGrid = thisState.binAndTrackGridMap.at(trk); m_cfg.gridDensity.removeTrackGridFromMainGrid( - binAndTrackGrid.first, binAndTrackGrid.second, state.mainGrid); + binAndTrackGrid.first, binAndTrackGrid.second, thisState.mainGrid); } if (!couldRemoveTracks) { // No tracks were removed anymore @@ -34,34 +36,34 @@ auto Acts::GridDensityVertexFinder::find( return seedVec; } } else { - state.mainGrid = MainGridVector::Zero(); + thisState.mainGrid = MainGridVector::Zero(); // Fill with track densities for (auto trk : trackVector) { const BoundTrackParameters& trkParams = m_cfg.extractParameters(trk); // Take only tracks that fulfill selection criteria if (!doesPassTrackSelection(trkParams)) { if (m_cfg.cacheGridStateForTrackRemoval) { - state.trackSelectionMap[trk] = false; + thisState.trackSelectionMap[trk] = false; } continue; } auto binAndTrackGrid = - m_cfg.gridDensity.addTrack(trkParams, state.mainGrid); + m_cfg.gridDensity.addTrack(trkParams, thisState.mainGrid); // Cache track density contribution to main grid if enabled if (m_cfg.cacheGridStateForTrackRemoval) { - state.binAndTrackGridMap[trk] = binAndTrackGrid; - state.trackSelectionMap[trk] = true; + thisState.binAndTrackGridMap[trk] = binAndTrackGrid; + thisState.trackSelectionMap[trk] = true; } } - state.isInitialized = true; + thisState.isInitialized = true; } double z = 0; double width = 0; - if (state.mainGrid != MainGridVector::Zero()) { + if (thisState.mainGrid != MainGridVector::Zero()) { if (!m_cfg.estimateSeedWidth) { // Get z value of highest density bin - auto maxZres = m_cfg.gridDensity.getMaxZPosition(state.mainGrid); + auto maxZres = m_cfg.gridDensity.getMaxZPosition(thisState.mainGrid); if (!maxZres.ok()) { return maxZres.error(); @@ -69,7 +71,7 @@ auto Acts::GridDensityVertexFinder::find( z = *maxZres; } else { // Get z value of highest density bin and width - auto maxZres = m_cfg.gridDensity.getMaxZPositionAndWidth(state.mainGrid); + auto maxZres = m_cfg.gridDensity.getMaxZPositionAndWidth(thisState.mainGrid); if (!maxZres.ok()) { return maxZres.error(); diff --git a/Core/include/Acts/Vertexing/IVertexFinder.hpp b/Core/include/Acts/Vertexing/IVertexFinder.hpp new file mode 100644 index 00000000000..b6ff14b4bd5 --- /dev/null +++ b/Core/include/Acts/Vertexing/IVertexFinder.hpp @@ -0,0 +1,39 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2020 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Utilities/Any.hpp" +#include "Acts/Utilities/Result.hpp" +#include "Acts/Vertexing/VertexingOptions.hpp" + +#include + +namespace Acts { + +class Vertex; +struct InputTrack; +struct VertexingOptions; + +class IVertexFinder { + public: + using State = Acts::Any; + + virtual Result> find( + const std::vector& trackVector, + const VertexingOptions& vertexingOptions, State& state) const = 0; + + virtual State makeState() const = 0; + + virtual bool hasTrivialState() const = 0; + + virtual void setTrackToRemove( + State& /*state*/, + const std::vector& /*removedTracks*/) const {} +}; +} // namespace Acts diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index 1d4a573fc8e..1fc15d7de61 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -16,6 +16,7 @@ #include "Acts/Vertexing/FsmwMode1dFinder.hpp" #include "Acts/Vertexing/FullBilloirVertexFitter.hpp" #include "Acts/Vertexing/HelicalTrackLinearizer.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/TrackLinearizer.hpp" #include "Acts/Vertexing/Vertex.hpp" @@ -59,7 +60,7 @@ namespace Acts { /// @tparam vfitter_t Vertex fitter type /// @tparam sfinder_t Seed finder type template -class IterativeVertexFinder { +class IterativeVertexFinder final : public IVertexFinder { static_assert(VertexFitterConcept, "Vertex fitter does not fulfill vertex fitter concept."); @@ -153,6 +154,12 @@ class IterativeVertexFinder { "IterativeVertexFinder: " "No track linearizer provided."); } + + if (!m_cfg.seedFinder.hasTrivialState()) { + throw std::invalid_argument( + "IterativeVertexFinder: " + "Seed finder must have trivial state."); + } } /// @brief Finds vertices corresponding to input trackVector @@ -164,7 +171,14 @@ class IterativeVertexFinder { /// @return Collection of vertices found by finder Result> find(const std::vector& trackVector, const VertexingOptions& vertexingOptions, - State& state) const; + IVertexFinder::State& state) const override; + + IVertexFinder::State makeState() const override { + // @TODO: This is not great + throw std::runtime_error("Not implemented"); + } + + bool hasTrivialState() const override { return false; } private: /// Configuration object diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp index 2bac588af23..0e4860d308e 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp @@ -9,8 +9,9 @@ template auto Acts::IterativeVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, State& state) const + const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const -> Result> { + auto& thisState = state.as(); // Original tracks const std::vector& origTracks = trackVector; // Tracks for seeding @@ -44,8 +45,9 @@ auto Acts::IterativeVertexFinder::find( std::vector tracksToFitSplitVertex; // Fill vector with tracks to fit, only compatible with seed: - auto res = fillTracksToFit(seedTracks, seedVertex, tracksToFit, - tracksToFitSplitVertex, vertexingOptions, state); + auto res = + fillTracksToFit(seedTracks, seedVertex, tracksToFit, + tracksToFitSplitVertex, vertexingOptions, thisState); if (!res.ok()) { return res.error(); @@ -59,7 +61,7 @@ auto Acts::IterativeVertexFinder::find( if (vertexingOptions.useConstraintInFit && !tracksToFit.empty()) { auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - state.fitterState); + thisState.fitterState); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { @@ -67,7 +69,7 @@ auto Acts::IterativeVertexFinder::find( } } else if (!vertexingOptions.useConstraintInFit && tracksToFit.size() > 1) { auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - state.fitterState); + thisState.fitterState); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { @@ -76,7 +78,7 @@ auto Acts::IterativeVertexFinder::find( } if (m_cfg.createSplitVertices && tracksToFitSplitVertex.size() > 1) { auto fitResult = m_cfg.vertexFitter.fit( - tracksToFitSplitVertex, vertexingOptions, state.fitterState); + tracksToFitSplitVertex, vertexingOptions, thisState.fitterState); if (fitResult.ok()) { currentSplitVertex = std::move(*fitResult); } else { @@ -109,7 +111,7 @@ auto Acts::IterativeVertexFinder::find( auto result = reassignTracksToNewVertex( vertexCollection, currentVertex, tracksToFit, seedTracks, - origTracks, vertexingOptions, state); + origTracks, vertexingOptions, thisState); if (!result.ok()) { return result.error(); } @@ -119,7 +121,7 @@ auto Acts::IterativeVertexFinder::find( // still good vertex? might have changed in the meanwhile if (isGoodVertex) { removeUsedCompatibleTracks(currentVertex, tracksToFit, seedTracks, - vertexingOptions, state); + vertexingOptions, thisState); ACTS_DEBUG( "Number of seed tracks after removal of compatible tracks " @@ -137,7 +139,7 @@ auto Acts::IterativeVertexFinder::find( removeTracks(tracksToFitSplitVertex, seedTracks); } else { removeUsedCompatibleTracks(currentSplitVertex, tracksToFitSplitVertex, - seedTracks, vertexingOptions, state); + seedTracks, vertexingOptions, thisState); } } // Now fill vertex collection with vertex @@ -158,7 +160,7 @@ template auto Acts::IterativeVertexFinder::getVertexSeed( const std::vector& seedTracks, const VertexingOptions& vertexingOptions) const -> Result { - typename sfinder_t::State finderState; + auto finderState = m_cfg.seedFinder.makeState(); auto res = m_cfg.seedFinder.find(seedTracks, vertexingOptions, finderState); if (!res.ok()) { diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp index 09f4a076742..f858c377f25 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp @@ -12,6 +12,7 @@ #include "Acts/EventData/TrackParameters.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/GaussianTrackDensity.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/Vertex.hpp" #include "Acts/Vertexing/VertexFitterConcept.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" @@ -32,7 +33,7 @@ namespace Acts { /// @tparam vfitter_t The vertex fitter type (needed to fulfill concept) /// @tparam track_density_t The track density type template -class TrackDensityVertexFinder { +class TrackDensityVertexFinder final : public IVertexFinder { // Provided vertex fitter type should comply with the VertexFitterConcept // to ensure providing an input track type InputTrack_t @@ -59,7 +60,13 @@ class TrackDensityVertexFinder { /// vertex (for consistent interfaces) Result> find(const std::vector& trackVector, const VertexingOptions& vertexingOptions, - State& state) const; + IVertexFinder::State& state) const override; + + IVertexFinder::State makeState() const override { + return IVertexFinder::State{State{}}; + } + + bool hasTrivialState() const override { return true; } /// @brief Constructor for user-defined InputTrack type /// diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp index e8209af930d..2c53f8d91ed 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp @@ -9,8 +9,8 @@ template auto Acts::TrackDensityVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, State& /*state*/) const - -> Result> { + const VertexingOptions& vertexingOptions, + IVertexFinder::State& /*state*/) const -> Result> { typename track_density_t::State densityState(trackVector.size()); // Calculate z seed position diff --git a/Core/include/Acts/Vertexing/VertexFinderConcept.hpp b/Core/include/Acts/Vertexing/VertexFinderConcept.hpp deleted file mode 100644 index cd89d18a52c..00000000000 --- a/Core/include/Acts/Vertexing/VertexFinderConcept.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// This file is part of the Acts project. -// -// Copyright (C) 2019 CERN for the benefit of the Acts project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Definitions/Algebra.hpp" -#include "Acts/Utilities/Result.hpp" -#include "Acts/Utilities/TypeTraits.hpp" -#include "Acts/Vertexing/Vertex.hpp" -#include "Acts/Vertexing/VertexingOptions.hpp" - -namespace Acts { - -namespace Concepts { -namespace VertexFinder { - -template -using state_t = typename T::State; - -METHOD_TRAIT(find_t, find); - -// clang-format off - template - struct VertexFinderConcept { - constexpr static bool state_exists = exists; - static_assert(state_exists, "State type not found"); - - constexpr static bool find_exists = has_method>, - find_t, const std::vector&, - const VertexingOptions&, typename S::State&>; - static_assert(find_exists, "find method not found"); - - constexpr static bool value = require; - }; -// clang-format on -} // namespace VertexFinder -} // namespace Concepts - -template -constexpr bool VertexFinderConcept = - Acts::Concepts ::VertexFinder::VertexFinderConcept::value; - -} // namespace Acts diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp index 958a00ee58b..4dc00821c69 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp @@ -14,6 +14,7 @@ #include "Acts/Utilities/Logger.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/FsmwMode1dFinder.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/Vertex.hpp" #include "Acts/Vertexing/VertexFitterConcept.hpp" @@ -31,7 +32,7 @@ namespace Acts { /// 3. If vertex constraint is given with x=x_constr and y=y_constr, /// the returned vertex position will be (x_constr, y_constr, z0_mode). template -class ZScanVertexFinder { +class ZScanVertexFinder final : public IVertexFinder { static_assert(VertexFitterConcept, "Vertex fitter does not fulfill vertex fitter concept."); @@ -99,7 +100,13 @@ class ZScanVertexFinder { /// vertex (for consistent interfaces) Result> find(const std::vector& trackVector, const VertexingOptions& vertexingOptions, - State& state) const; + IVertexFinder::State& state) const override; + + IVertexFinder::State makeState() const override { + return IVertexFinder::State{State{}}; + } + + bool hasTrivialState() const override { return true; } private: Config m_cfg; diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp b/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp index e9d6c96849d..1e26e48f2aa 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp @@ -9,8 +9,8 @@ template auto Acts::ZScanVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, State& /*state*/) const - -> Result> { + const VertexingOptions& vertexingOptions, + IVertexFinder::State& /*state*/) const -> Result> { double ZResult = 0.; // Prepare the vector of points, on which the 3d mode has later to be // calculated diff --git a/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp b/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp index e98f5167283..3d00ff4f8f9 100644 --- a/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp +++ b/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp @@ -186,7 +186,7 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::executeAfterSeederChoice( ////////////////////////////////////////////// // The vertex finder state - typename Finder::State state; + auto state = finder.makeState(); // Default vertexing options, this is where e.g. a constraint could be set Options finderOpts(ctx.geoContext, ctx.magFieldContext); diff --git a/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp b/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp index 43195131601..caa7ac45118 100644 --- a/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp +++ b/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp @@ -104,7 +104,8 @@ ActsExamples::ProcessCode ActsExamples::IterativeVertexFinderAlgorithm::execute( finderCfg.reassignTracksAfterFirstFit = false; finderCfg.extractParameters.connect<&Acts::InputTrack::extractParameters>(); Finder finder(std::move(finderCfg), logger().clone()); - Finder::State state(*m_cfg.bField, ctx.magFieldContext); + Acts::IVertexFinder::State state{std::in_place_type, + *m_cfg.bField, ctx.magFieldContext}; Options finderOpts(ctx.geoContext, ctx.magFieldContext); // find vertices diff --git a/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp index 74d12ee2033..7dec853dcb3 100644 --- a/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp @@ -32,6 +32,7 @@ #include "Acts/Vertexing/GaussianTrackDensity.hpp" #include "Acts/Vertexing/GridDensityVertexFinder.hpp" #include "Acts/Vertexing/HelicalTrackLinearizer.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/TrackAtVertex.hpp" #include "Acts/Vertexing/TrackDensityVertexFinder.hpp" @@ -124,7 +125,7 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_test) { finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - Finder::State state; + IVertexFinder::State state = finder.makeState(); auto csvData = readTracksAndVertexCSV(toolString); std::vector tracks = std::get(csvData); @@ -283,9 +284,9 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_usertype_test) { Finder::Config finderConfig(std::move(fitter), seedFinder, ipEstimator, bField); finderConfig.extractParameters.connect(extractParameters); - Finder::State state; Finder finder(std::move(finderConfig)); + IVertexFinder::State state = finder.makeState(); auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); @@ -432,7 +433,7 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_grid_seed_finder_test) { finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - Finder::State state; + IVertexFinder::State state = finder.makeState(); auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); @@ -591,7 +592,7 @@ BOOST_AUTO_TEST_CASE( finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - Finder::State state; + IVertexFinder::State state = finder.makeState(); auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); diff --git a/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp index e7c9d065572..1515b34b4d5 100644 --- a/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp @@ -28,6 +28,7 @@ #include "Acts/Vertexing/AdaptiveGridTrackDensity.hpp" #include "Acts/Vertexing/GaussianGridTrackDensity.hpp" #include "Acts/Vertexing/GridDensityVertexFinder.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/Vertex.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" @@ -101,7 +102,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_test) { cfg1.cacheGridStateForTrackRemoval = false; cfg1.extractParameters.connect<&InputTrack::extractParameters>(); Finder1 finder1(cfg1); - Finder1::State state1; + IVertexFinder::State state1 = finder1.makeState(); // Use custom grid density here with same bin size as Finder1 AdaptiveGridTrackDensity::Config adaptiveDensityConfig; @@ -114,7 +115,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_test) { cfg2.cacheGridStateForTrackRemoval = false; cfg2.extractParameters.connect<&InputTrack::extractParameters>(); Finder2 finder2(cfg2); - Finder2::State state2; + IVertexFinder::State state2 = finder2.makeState(); int mySeed = 31415; std::mt19937 gen(mySeed); @@ -275,8 +276,8 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_track_caching_test) { inputTracks.emplace_back(&trk); } - Finder1::State state1; - Finder2::State state2; + IVertexFinder::State state1 = finder1.makeState(); + IVertexFinder::State state2 = finder2.makeState(); double zResult1 = 0; double zResult2 = 0; @@ -322,8 +323,8 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_track_caching_test) { trkCount++; } - state1.tracksToRemove = removedTracks; - state2.tracksToRemove = removedTracks; + state1.as().tracksToRemove = removedTracks; + state2.as().tracksToRemove = removedTracks; auto res3 = finder1.find(inputTracks, vertexingOptions, state1); if (!res3.ok()) { @@ -387,7 +388,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_seed_width_test) { cfg1.estimateSeedWidth = true; cfg1.extractParameters.connect<&InputTrack::extractParameters>(); Finder1 finder1(cfg1); - Finder1::State state1; + IVertexFinder::State state1 = finder1.makeState(); // Use custom grid density here with same bin size as Finder1 AdaptiveGridTrackDensity::Config adaptiveDensityConfig; @@ -401,7 +402,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_seed_width_test) { cfg2.estimateSeedWidth = true; cfg2.extractParameters.connect<&InputTrack::extractParameters>(); Finder2 finder2(cfg2); - Finder2::State state2; + IVertexFinder::State state2 = finder2.makeState(); int mySeed = 31415; std::mt19937 gen(mySeed); diff --git a/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp index 12866d05435..de127b29367 100644 --- a/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp @@ -30,11 +30,11 @@ #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/FullBilloirVertexFitter.hpp" #include "Acts/Vertexing/HelicalTrackLinearizer.hpp" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/IterativeVertexFinder.hpp" #include "Acts/Vertexing/TrackAtVertex.hpp" #include "Acts/Vertexing/Vertex.hpp" -#include "Acts/Vertexing/VertexFinderConcept.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" #include "Acts/Vertexing/ZScanVertexFinder.hpp" @@ -155,9 +155,6 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test) { using ZScanSeedFinder = ZScanVertexFinder; - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); - ZScanSeedFinder::Config seedFinderCfg(ipEstimator); seedFinderCfg.extractParameters.connect<&InputTrack::extractParameters>(); @@ -166,9 +163,6 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test) { // Vertex Finder using VertexFinder = IterativeVertexFinder; - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); - VertexFinder::Config cfg(std::move(bFitter), std::move(sFinder), ipEstimator); cfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); @@ -177,7 +171,7 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test) { cfg.extractParameters.connect<&InputTrack::extractParameters>(); VertexFinder finder(std::move(cfg)); - VertexFinder::State state(*bField, magFieldContext); + IVertexFinder::State state{VertexFinder::State(*bField, magFieldContext)}; // Vector to be filled with all tracks in current event std::vector> tracks; @@ -396,7 +390,7 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_user_track_type) { cfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); VertexFinder finder(std::move(cfg)); - VertexFinder::State state(*bField, magFieldContext); + IVertexFinder::State state{VertexFinder::State(*bField, magFieldContext)}; // Same for user track type tracks std::vector> tracks; @@ -585,9 +579,6 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_athena_reference) { using ZScanSeedFinder = ZScanVertexFinder; - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); - ZScanSeedFinder::Config seedFinderCfg(ipEstimator); seedFinderCfg.extractParameters.connect<&InputTrack::extractParameters>(); @@ -596,9 +587,6 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_athena_reference) { // Vertex Finder using VertexFinder = IterativeVertexFinder; - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); - VertexFinder::Config cfg(std::move(bFitter), std::move(sFinder), ipEstimator); cfg.maxVertices = 200; cfg.maximumChi2cutForSeeding = 49; @@ -607,7 +595,7 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_athena_reference) { cfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); VertexFinder finder(std::move(cfg)); - VertexFinder::State state(*bField, magFieldContext); + IVertexFinder::State state{VertexFinder::State(*bField, magFieldContext)}; auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); diff --git a/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp index 400eeb87b3b..987b49c7465 100644 --- a/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_test) { GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; - Finder::State state; + auto state = finder.makeState(); // Start creating some track parameters Covariance covMat = Covariance::Identity(); @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_constr_test) { GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; - Finder::State state; + auto state = finder.makeState(); // Start creating some track parameters Covariance covMat = Covariance::Identity(); @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_random_test) { GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; - Finder::State state; + auto state = finder.makeState(); int mySeed = 31415; std::mt19937 gen(mySeed); @@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_usertrack_test) { GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect(extractParameters); Finder finder{{{densityCfg}}}; - Finder::State state; + auto state = finder.makeState(); // Start creating some track parameters Covariance covMat = Covariance::Identity(); diff --git a/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp index a91ab9570d2..4716f3aed19 100644 --- a/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp @@ -29,7 +29,6 @@ #include "Acts/Vertexing/FullBilloirVertexFitter.hpp" #include "Acts/Vertexing/HelicalTrackLinearizer.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" -#include "Acts/Vertexing/VertexFinderConcept.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" #include "Acts/Vertexing/ZScanVertexFinder.hpp" @@ -164,9 +163,6 @@ BOOST_AUTO_TEST_CASE(zscan_finder_test) { using VertexFinder = ZScanVertexFinder; - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); - ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); @@ -177,7 +173,7 @@ BOOST_AUTO_TEST_CASE(zscan_finder_test) { VertexingOptions vertexingOptions(geoContext, magFieldContext); - VertexFinder::State state; + auto state = finder.makeState(); auto res = finder.find(inputTracks, vertexingOptions, state); BOOST_CHECK(res.ok()); @@ -285,9 +281,6 @@ BOOST_AUTO_TEST_CASE(zscan_finder_usertrack_test) { using VertexFinder = ZScanVertexFinder; - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); - ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); @@ -301,7 +294,7 @@ BOOST_AUTO_TEST_CASE(zscan_finder_usertrack_test) { cfg.extractParameters.connect(extractParameters); VertexFinder finder(cfg); - VertexFinder::State state; + auto state = finder.makeState(); VertexingOptions vertexingOptions(geoContext, magFieldContext); From b37ef5f81ef30442de9cf1299accb5b7273d9f62 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Wed, 20 Dec 2023 00:15:38 +0100 Subject: [PATCH 02/14] VertexFinders use Seeders as interface finders AMVFinderAlg sets up finder at construction now (not execute) --- .../AdaptiveGridDensityVertexFinder.hpp | 3 - .../AdaptiveGridDensityVertexFinder.ipp | 8 +- .../Vertexing/AdaptiveMultiVertexFinder.hpp | 29 +++-- .../Vertexing/AdaptiveMultiVertexFinder.ipp | 97 ++++++++--------- .../Vertexing/GridDensityVertexFinder.hpp | 3 +- .../Vertexing/GridDensityVertexFinder.ipp | 8 +- .../Acts/Vertexing/IterativeVertexFinder.hpp | 16 ++- .../Acts/Vertexing/IterativeVertexFinder.ipp | 38 ++++--- .../Vertexing/TrackDensityVertexFinder.hpp | 9 +- .../Vertexing/TrackDensityVertexFinder.ipp | 4 +- .../Acts/Vertexing/ZScanVertexFinder.hpp | 4 - .../Acts/Vertexing/ZScanVertexFinder.ipp | 4 +- .../AdaptiveMultiVertexFinderAlgorithm.hpp | 20 ++-- .../IterativeVertexFinderAlgorithm.hpp | 5 +- .../AdaptiveMultiVertexFinderAlgorithm.cpp | 102 +++++++++--------- .../src/IterativeVertexFinderAlgorithm.cpp | 2 +- .../AdaptiveMultiVertexFinderTests.cpp | 24 +++-- .../GridDensityVertexFinderTests.cpp | 6 +- .../Vertexing/IterativeVertexFinderTests.cpp | 18 ++-- .../TrackDensityVertexFinderTests.cpp | 12 +-- .../Core/Vertexing/ZScanVertexFinderTests.cpp | 4 +- 21 files changed, 193 insertions(+), 223 deletions(-) diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp index db946a3f62f..ab1274d1913 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp @@ -29,9 +29,6 @@ namespace Acts { /// with the highest track density is returned as a vertex candidate. /// Unlike the GridDensityVertexFinder, this seeder implements an adaptive /// version where the density grid grows bigger with added tracks. -/// -/// @tparam vfitter_t Vertex fitter type -template > class AdaptiveGridDensityVertexFinder final : public IVertexFinder { using GridDensity = AdaptiveGridTrackDensity; diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp index 83dda993f26..eca5e91a782 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp @@ -6,8 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -template -auto Acts::AdaptiveGridDensityVertexFinder::find( +inline +auto Acts::AdaptiveGridDensityVertexFinder::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const -> Result> { @@ -96,8 +96,8 @@ auto Acts::AdaptiveGridDensityVertexFinder::find( return seedVec; } -template -auto Acts::AdaptiveGridDensityVertexFinder::doesPassTrackSelection( +inline +auto Acts::AdaptiveGridDensityVertexFinder::doesPassTrackSelection( const BoundTrackParameters& trk) const -> bool { // Get required track parameters const double d0 = trk.parameters()[BoundIndices::eBoundLoc0]; diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp index f9909b275ff..3a0a6a159e0 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp @@ -33,19 +33,9 @@ namespace Acts { /// /// @tparam vfitter_t Vertex fitter type /// @tparam sfinder_t Seed finder type -template +template class AdaptiveMultiVertexFinder final : public IVertexFinder { using FitterState_t = typename vfitter_t::State; - using SeedFinderState_t = typename sfinder_t::State; - - template - struct NeedsRemovedTracks : std::false_type {}; - -#ifndef DOXYGEN - template - struct NeedsRemovedTracks - : std::true_type {}; -#endif public: /// Configuration struct @@ -56,7 +46,8 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { /// @param sfinder The seed finder /// @param ipEst ImpactPointEstimator /// @param bIn Input magnetic field - Config(vfitter_t fitter, sfinder_t sfinder, ImpactPointEstimator ipEst, + Config(vfitter_t fitter, std::shared_ptr sfinder, + ImpactPointEstimator ipEst, std::shared_ptr bIn) : vertexFitter(std::move(fitter)), seedFinder(std::move(sfinder)), @@ -67,7 +58,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { vfitter_t vertexFitter; // Vertex seed finder - sfinder_t seedFinder; + std::shared_ptr seedFinder; // ImpactPointEstimator ImpactPointEstimator ipEstimator; @@ -181,7 +172,13 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { "from InputTrack provided."); } - if (!m_cfg.seedFinder.hasTrivialState()) { + if (!m_cfg.seedFinder) { + throw std::invalid_argument( + "AdaptiveMultiVertexFinder: " + "No vertex fitter provided."); + } + + if (!m_cfg.seedFinder->hasTrivialState()) { throw std::invalid_argument( "AdaptiveMultiVertexFinder: " "Seed finder state must be trivial."); @@ -206,9 +203,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { return IVertexFinder::State{State{}}; } - bool hasTrivialState() const override { - return true; - } + bool hasTrivialState() const override { return true; } private: /// Configuration object diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp index 7474156a9b7..516f4a9b288 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp @@ -9,8 +9,8 @@ #include "Acts/Utilities/AlgebraHelpers.hpp" #include "Acts/Vertexing/VertexingError.hpp" -template -auto Acts::AdaptiveMultiVertexFinder::find( +template +auto Acts::AdaptiveMultiVertexFinder::find( const std::vector& allTracks, const VertexingOptions& vertexingOptions, IVertexFinder::State& /*state*/) const -> Result> { @@ -26,7 +26,7 @@ auto Acts::AdaptiveMultiVertexFinder::find( std::vector seedTracks = allTracks; FitterState_t fitterState(*m_cfg.bField, vertexingOptions.magFieldContext); - auto seedFinderState = m_cfg.seedFinder.makeState(); + auto seedFinderState = m_cfg.seedFinder->makeState(); std::vector> allVertices; @@ -138,8 +138,8 @@ auto Acts::AdaptiveMultiVertexFinder::find( return getVertexOutputList(allVerticesPtr, fitterState); } -template -auto Acts::AdaptiveMultiVertexFinder::doSeeding( +template +auto Acts::AdaptiveMultiVertexFinder::doSeeding( const std::vector& trackVector, Vertex& currentConstraint, const VertexingOptions& vertexingOptions, IVertexFinder::State& seedFinderState, @@ -147,13 +147,11 @@ auto Acts::AdaptiveMultiVertexFinder::doSeeding( VertexingOptions seedOptions = vertexingOptions; seedOptions.constraint = currentConstraint; - if constexpr (NeedsRemovedTracks::value) { - m_cfg.seedFinder.setTrackToRemove(seedFinderState, removedSeedTracks); - } + m_cfg.seedFinder->setTrackToRemove(seedFinderState, removedSeedTracks); // Run seed finder auto seedResult = - m_cfg.seedFinder.find(trackVector, seedOptions, seedFinderState); + m_cfg.seedFinder->find(trackVector, seedOptions, seedFinderState); if (!seedResult.ok()) { return seedResult.error(); @@ -167,11 +165,10 @@ auto Acts::AdaptiveMultiVertexFinder::doSeeding( return seedVertex; } -template -auto Acts::AdaptiveMultiVertexFinder:: - setConstraintAfterSeeding(Vertex& currentConstraint, - bool useVertexConstraintInFit, - Vertex& seedVertex) const -> void { +template +auto Acts::AdaptiveMultiVertexFinder::setConstraintAfterSeeding( + Vertex& currentConstraint, bool useVertexConstraintInFit, + Vertex& seedVertex) const -> void { if (useVertexConstraintInFit) { if (!m_cfg.useSeedConstraint) { // Set seed vertex constraint to old constraint before seeding @@ -188,8 +185,8 @@ auto Acts::AdaptiveMultiVertexFinder:: } } -template -auto Acts::AdaptiveMultiVertexFinder::getIPSignificance( +template +auto Acts::AdaptiveMultiVertexFinder::getIPSignificance( const InputTrack& track, const Vertex& vtx, const VertexingOptions& vertexingOptions) const -> Result { // TODO: In original implementation the covariance of the given vertex is set @@ -228,11 +225,10 @@ auto Acts::AdaptiveMultiVertexFinder::getIPSignificance( return significance; } -template -auto Acts::AdaptiveMultiVertexFinder:: - addCompatibleTracksToVertex(const std::vector& tracks, - Vertex& vtx, FitterState_t& fitterState, - const VertexingOptions& vertexingOptions) const +template +auto Acts::AdaptiveMultiVertexFinder::addCompatibleTracksToVertex( + const std::vector& tracks, Vertex& vtx, + FitterState_t& fitterState, const VertexingOptions& vertexingOptions) const -> Result { for (const auto& trk : tracks) { auto params = m_cfg.extractParameters(trk); @@ -259,8 +255,8 @@ auto Acts::AdaptiveMultiVertexFinder:: return {}; } -template -auto Acts::AdaptiveMultiVertexFinder:: +template +auto Acts::AdaptiveMultiVertexFinder:: canRecoverFromNoCompatibleTracks( const std::vector& allTracks, const std::vector& seedTracks, Vertex& vtx, @@ -315,14 +311,12 @@ auto Acts::AdaptiveMultiVertexFinder:: return Result::success(true); } -template -auto Acts::AdaptiveMultiVertexFinder:: - canPrepareVertexForFit(const std::vector& allTracks, - const std::vector& seedTracks, - Vertex& vtx, const Vertex& currentConstraint, - FitterState_t& fitterState, - const VertexingOptions& vertexingOptions) const - -> Result { +template +auto Acts::AdaptiveMultiVertexFinder::canPrepareVertexForFit( + const std::vector& allTracks, + const std::vector& seedTracks, Vertex& vtx, + const Vertex& currentConstraint, FitterState_t& fitterState, + const VertexingOptions& vertexingOptions) const -> Result { // Add vertex info to fitter state fitterState.vtxInfoMap[&vtx] = VertexInfo(currentConstraint, vtx.fullPosition()); @@ -345,12 +339,10 @@ auto Acts::AdaptiveMultiVertexFinder:: return Result::success(*resRec); } -template -auto Acts::AdaptiveMultiVertexFinder:: - checkVertexAndCompatibleTracks(Vertex& vtx, - const std::vector& seedTracks, - FitterState_t& fitterState, - bool useVertexConstraintInFit) const +template +auto Acts::AdaptiveMultiVertexFinder::checkVertexAndCompatibleTracks( + Vertex& vtx, const std::vector& seedTracks, + FitterState_t& fitterState, bool useVertexConstraintInFit) const -> std::pair { bool isGoodVertex = false; int nCompatibleTracks = 0; @@ -386,8 +378,8 @@ auto Acts::AdaptiveMultiVertexFinder:: return {nCompatibleTracks, isGoodVertex}; } -template -auto Acts::AdaptiveMultiVertexFinder:: +template +auto Acts::AdaptiveMultiVertexFinder:: removeCompatibleTracksFromSeedTracks( Vertex& vtx, std::vector& seedTracks, FitterState_t& fitterState, @@ -412,12 +404,11 @@ auto Acts::AdaptiveMultiVertexFinder:: } } -template -auto Acts::AdaptiveMultiVertexFinder:: - removeTrackIfIncompatible(Vertex& vtx, std::vector& seedTracks, - FitterState_t& fitterState, - std::vector& removedSeedTracks, - const GeometryContext& geoCtx) const -> bool { +template +auto Acts::AdaptiveMultiVertexFinder::removeTrackIfIncompatible( + Vertex& vtx, std::vector& seedTracks, + FitterState_t& fitterState, std::vector& removedSeedTracks, + const GeometryContext& geoCtx) const -> bool { // Try to find the track with highest compatibility double maxCompatibility = 0; @@ -469,8 +460,8 @@ auto Acts::AdaptiveMultiVertexFinder:: return true; } -template -auto Acts::AdaptiveMultiVertexFinder::keepNewVertex( +template +auto Acts::AdaptiveMultiVertexFinder::keepNewVertex( Vertex& vtx, const std::vector& allVertices, FitterState_t& fitterState) const -> bool { double contamination = 0.; @@ -497,8 +488,8 @@ auto Acts::AdaptiveMultiVertexFinder::keepNewVertex( return true; } -template -auto Acts::AdaptiveMultiVertexFinder::isMergedVertex( +template +auto Acts::AdaptiveMultiVertexFinder::isMergedVertex( const Vertex& vtx, const std::vector& allVertices) const -> bool { const Vector4& candidatePos = vtx.fullPosition(); const SquareMatrix4& candidateCov = vtx.fullCovariance(); @@ -551,8 +542,8 @@ auto Acts::AdaptiveMultiVertexFinder::isMergedVertex( return false; } -template -auto Acts::AdaptiveMultiVertexFinder::deleteLastVertex( +template +auto Acts::AdaptiveMultiVertexFinder::deleteLastVertex( Vertex& vtx, std::vector>& allVertices, std::vector& allVerticesPtr, FitterState_t& fitterState, const VertexingOptions& vertexingOptions) const -> Result { @@ -591,8 +582,8 @@ auto Acts::AdaptiveMultiVertexFinder::deleteLastVertex( return {}; } -template -auto Acts::AdaptiveMultiVertexFinder::getVertexOutputList( +template +auto Acts::AdaptiveMultiVertexFinder::getVertexOutputList( const std::vector& allVerticesPtr, FitterState_t& fitterState) const -> Acts::Result> { std::vector outputVec; diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp index 4e050aa150e..3d7238307bb 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp @@ -36,8 +36,7 @@ namespace Acts { /// @tparam trkGridSize The 2(!)-dim grid size of a single track, i.e. /// a single track is modelled as a (trkGridSize x trkGridSize) grid /// in the d0-z0 plane. Note: trkGridSize has to be an odd value. -template > +template class GridDensityVertexFinder final : public IVertexFinder { // Assert odd trkGridSize static_assert(trkGridSize % 2); diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp index af99874879e..6c28deb41e2 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp @@ -6,8 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -template -auto Acts::GridDensityVertexFinder::find( +template +auto Acts::GridDensityVertexFinder::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const -> Result> { @@ -100,8 +100,8 @@ auto Acts::GridDensityVertexFinder::find( return seedVec; } -template -auto Acts::GridDensityVertexFinder:: +template +auto Acts::GridDensityVertexFinder:: doesPassTrackSelection(const BoundTrackParameters& trk) const -> bool { // Get required track parameters const double d0 = trk.parameters()[BoundIndices::eBoundLoc0]; diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index 1fc15d7de61..6d60316fe95 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -58,8 +58,7 @@ namespace Acts { //////////////////////////////////////////////////////////// /// /// @tparam vfitter_t Vertex fitter type -/// @tparam sfinder_t Seed finder type -template +template class IterativeVertexFinder final : public IVertexFinder { static_assert(VertexFitterConcept, "Vertex fitter does not fulfill vertex fitter concept."); @@ -73,7 +72,8 @@ class IterativeVertexFinder final : public IVertexFinder { /// @param lin Track linearizer /// @param sfinder The seed finder /// @param est ImpactPointEstimator - Config(vfitter_t fitter, sfinder_t sfinder, ImpactPointEstimator est) + Config(vfitter_t fitter, std::shared_ptr sfinder, + ImpactPointEstimator est) : vertexFitter(std::move(fitter)), seedFinder(std::move(sfinder)), ipEst(std::move(est)) {} @@ -85,7 +85,7 @@ class IterativeVertexFinder final : public IVertexFinder { TrackLinearizer trackLinearizer; /// Vertex seed finder - sfinder_t seedFinder; + std::shared_ptr seedFinder; /// ImpactPointEstimator ImpactPointEstimator ipEst; @@ -155,7 +155,13 @@ class IterativeVertexFinder final : public IVertexFinder { "No track linearizer provided."); } - if (!m_cfg.seedFinder.hasTrivialState()) { + if (!m_cfg.seedFinder) { + throw std::invalid_argument( + "IterativeVertexFinder: " + "No seed finder provided."); + } + + if (!m_cfg.seedFinder->hasTrivialState()) { throw std::invalid_argument( "IterativeVertexFinder: " "Seed finder must have trivial state."); diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp index 0e4860d308e..2c5400b9429 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp @@ -6,8 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -template -auto Acts::IterativeVertexFinder::find( +template +auto Acts::IterativeVertexFinder::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const -> Result> { @@ -156,12 +156,12 @@ auto Acts::IterativeVertexFinder::find( return vertexCollection; } -template -auto Acts::IterativeVertexFinder::getVertexSeed( +template +auto Acts::IterativeVertexFinder::getVertexSeed( const std::vector& seedTracks, const VertexingOptions& vertexingOptions) const -> Result { - auto finderState = m_cfg.seedFinder.makeState(); - auto res = m_cfg.seedFinder.find(seedTracks, vertexingOptions, finderState); + auto finderState = m_cfg.seedFinder->makeState(); + auto res = m_cfg.seedFinder->find(seedTracks, vertexingOptions, finderState); if (!res.ok()) { ACTS_ERROR("Internal seeding error. Number of input tracks: " @@ -190,8 +190,8 @@ auto Acts::IterativeVertexFinder::getVertexSeed( return seedVertex; } -template -void Acts::IterativeVertexFinder::removeTracks( +template +void Acts::IterativeVertexFinder::removeTracks( const std::vector& tracksToRemove, std::vector& seedTracks) const { for (const auto& trk : tracksToRemove) { @@ -211,9 +211,8 @@ void Acts::IterativeVertexFinder::removeTracks( } } -template -Acts::Result -Acts::IterativeVertexFinder::getCompatibility( +template +Acts::Result Acts::IterativeVertexFinder::getCompatibility( const BoundTrackParameters& params, const Vertex& vertex, const Surface& perigeeSurface, const VertexingOptions& vertexingOptions, State& state) const { @@ -248,9 +247,9 @@ Acts::IterativeVertexFinder::getCompatibility( return compatibility; } -template +template Acts::Result -Acts::IterativeVertexFinder::removeUsedCompatibleTracks( +Acts::IterativeVertexFinder::removeUsedCompatibleTracks( Vertex& vertex, std::vector& tracksToFit, std::vector& seedTracks, const VertexingOptions& vertexingOptions, State& state) const { @@ -341,9 +340,8 @@ Acts::IterativeVertexFinder::removeUsedCompatibleTracks( return {}; } -template -Acts::Result -Acts::IterativeVertexFinder::fillTracksToFit( +template +Acts::Result Acts::IterativeVertexFinder::fillTracksToFit( const std::vector& seedTracks, const Vertex& seedVertex, std::vector& tracksToFitOut, std::vector& tracksToFitSplitVertexOut, @@ -415,9 +413,9 @@ Acts::IterativeVertexFinder::fillTracksToFit( return {}; } -template +template Acts::Result -Acts::IterativeVertexFinder::reassignTracksToNewVertex( +Acts::IterativeVertexFinder::reassignTracksToNewVertex( std::vector& vertexCollection, Vertex& currentVertex, std::vector& tracksToFit, std::vector& seedTracks, const std::vector& /* origTracks */, @@ -549,8 +547,8 @@ Acts::IterativeVertexFinder::reassignTracksToNewVertex( return Result::success(isGoodVertex); } -template -int Acts::IterativeVertexFinder::countSignificantTracks( +template +int Acts::IterativeVertexFinder::countSignificantTracks( const Vertex& vtx) const { return std::count_if(vtx.tracks().begin(), vtx.tracks().end(), [this](const TrackAtVertex& trk) { diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp index f858c377f25..6147f82b24a 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp @@ -30,16 +30,9 @@ namespace Acts { /// /// Ref. (1): https://cds.cern.ch/record/2670380 /// -/// @tparam vfitter_t The vertex fitter type (needed to fulfill concept) /// @tparam track_density_t The track density type -template +template class TrackDensityVertexFinder final : public IVertexFinder { - // Provided vertex fitter type should comply with the VertexFitterConcept - // to ensure providing an input track type InputTrack_t - - // static_assert(VertexFitterConcept, - // "Vertex fitter does not fulfill vertex fitter concept."); - public: /// @brief The Config struct struct Config { diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp index 2c53f8d91ed..aa769e149c5 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp @@ -6,8 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -template -auto Acts::TrackDensityVertexFinder::find( +template < typename track_density_t> +auto Acts::TrackDensityVertexFinder< track_density_t>::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& /*state*/) const -> Result> { diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp index 4dc00821c69..97b4637ad99 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp @@ -31,11 +31,7 @@ namespace Acts { /// 2. If no constraint is given, returns (0,0, z0_mode) as vertex position /// 3. If vertex constraint is given with x=x_constr and y=y_constr, /// the returned vertex position will be (x_constr, y_constr, z0_mode). -template class ZScanVertexFinder final : public IVertexFinder { - static_assert(VertexFitterConcept, - "Vertex fitter does not fulfill vertex fitter concept."); - public: /// Configuration struct struct Config { diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp b/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp index 1e26e48f2aa..7167b5ebaba 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp @@ -6,8 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -template -auto Acts::ZScanVertexFinder::find( +inline +auto Acts::ZScanVertexFinder::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& /*state*/) const -> Result> { diff --git a/Examples/Algorithms/Vertexing/include/ActsExamples/Vertexing/AdaptiveMultiVertexFinderAlgorithm.hpp b/Examples/Algorithms/Vertexing/include/ActsExamples/Vertexing/AdaptiveMultiVertexFinderAlgorithm.hpp index 0e1572f8150..36a53f1e0f3 100644 --- a/Examples/Algorithms/Vertexing/include/ActsExamples/Vertexing/AdaptiveMultiVertexFinderAlgorithm.hpp +++ b/Examples/Algorithms/Vertexing/include/ActsExamples/Vertexing/AdaptiveMultiVertexFinderAlgorithm.hpp @@ -78,28 +78,26 @@ class AdaptiveMultiVertexFinderAlgorithm final : public IAlgorithm { AdaptiveMultiVertexFinderAlgorithm(const Config& config, Acts::Logging::Level level); - /// Set up vertex seeder and call the function executeAfterSeederChoice. - /// - /// @param ctx is the algorithm context with event information - /// @return a process code indication success or failure - ProcessCode execute(const AlgorithmContext& ctx) const final; - /// Find vertices using the adaptive multi vertex finder algorithm. /// + /// /// @param ctx is the algorithm context with event information - /// @param seedFinder is the vertex seed finder /// @return a process code indication success or failure - template - ProcessCode executeAfterSeederChoice( - const ActsExamples::AlgorithmContext& ctx, - const vseeder_t& seedFinder) const; + ProcessCode execute(const AlgorithmContext& ctx) const final; /// Get readonly access to the config parameters const Config& config() const { return m_cfg; } private: + Acts::AdaptiveMultiVertexFinder makeVertexFinder() const; + Config m_cfg; + std::shared_ptr m_propagator; + Acts::ImpactPointEstimator m_ipEstimator; + Linearizer m_linearizer; + Acts::AdaptiveMultiVertexFinder m_vertexFinder; + ReadDataHandle m_inputTrackParameters{ this, "InputTrackParameters"}; diff --git a/Examples/Algorithms/Vertexing/include/ActsExamples/Vertexing/IterativeVertexFinderAlgorithm.hpp b/Examples/Algorithms/Vertexing/include/ActsExamples/Vertexing/IterativeVertexFinderAlgorithm.hpp index a3f77b44802..97732f84ed3 100644 --- a/Examples/Algorithms/Vertexing/include/ActsExamples/Vertexing/IterativeVertexFinderAlgorithm.hpp +++ b/Examples/Algorithms/Vertexing/include/ActsExamples/Vertexing/IterativeVertexFinderAlgorithm.hpp @@ -54,9 +54,8 @@ class IterativeVertexFinderAlgorithm final : public IAlgorithm { using Propagator = Acts::Propagator>; using Linearizer = Acts::HelicalTrackLinearizer; using Fitter = Acts::FullBilloirVertexFitter; - using Seeder = - Acts::TrackDensityVertexFinder; - using Finder = Acts::IterativeVertexFinder; + using Seeder = Acts::TrackDensityVertexFinder; + using Finder = Acts::IterativeVertexFinder; using Options = Acts::VertexingOptions; using VertexCollection = std::vector; diff --git a/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp b/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp index 3d00ff4f8f9..dfd421b499f 100644 --- a/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp +++ b/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp @@ -21,6 +21,7 @@ #include "Acts/Vertexing/GaussianTrackDensity.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/TrackAtVertex.hpp" +#include "Acts/Vertexing/TrackDensityVertexFinder.hpp" #include "Acts/Vertexing/Vertex.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" #include "ActsExamples/EventData/ProtoVertex.hpp" @@ -39,7 +40,30 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm:: AdaptiveMultiVertexFinderAlgorithm(const Config& config, Acts::Logging::Level level) : ActsExamples::IAlgorithm("AdaptiveMultiVertexFinder", level), - m_cfg(config) { + m_cfg(config), + m_propagator{[&]() { + // Set up EigenStepper + Acts::EigenStepper<> stepper(m_cfg.bField); + + // Set up the propagator + return std::make_shared(stepper); + }()}, + m_ipEstimator{[&]() { + // Set up ImpactPointEstimator + Acts::ImpactPointEstimator::Config ipEstimatorCfg(m_cfg.bField, + m_propagator); + return Acts::ImpactPointEstimator( + ipEstimatorCfg, logger().cloneWithSuffix("ImpactPointEstimator")); + }()}, + m_linearizer{[&] { + // Set up the helical track linearizer + Linearizer::Config ltConfig; + ltConfig.bField = m_cfg.bField; + ltConfig.propagator = m_propagator; + return Linearizer(ltConfig, + logger().cloneWithSuffix("HelicalTrackLinearizer")); + }()}, + m_vertexFinder{makeVertexFinder()} { if (m_cfg.inputTrackParameters.empty()) { throw std::invalid_argument("Missing input track parameter collection"); } @@ -55,19 +79,16 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm:: m_outputVertices.initialize(m_cfg.outputVertices); } -ActsExamples::ProcessCode -ActsExamples::AdaptiveMultiVertexFinderAlgorithm::execute( - const ActsExamples::AlgorithmContext& ctx) const { +auto ActsExamples::AdaptiveMultiVertexFinderAlgorithm::makeVertexFinder() const + -> Acts::AdaptiveMultiVertexFinder { + std::shared_ptr seedFinder; if (m_cfg.seedFinder == SeedFinder::GaussianSeeder) { - using Seeder = - Acts::TrackDensityVertexFinder; - using Finder = Acts::AdaptiveMultiVertexFinder; + using Seeder = Acts::TrackDensityVertexFinder; + using Finder = Acts::AdaptiveMultiVertexFinder; Acts::GaussianTrackDensity::Config trkDensityCfg; trkDensityCfg.extractParameters .connect<&Acts::InputTrack::extractParameters>(); - Seeder seedFinder{{trkDensityCfg}}; - - return executeAfterSeederChoice(ctx, seedFinder); + seedFinder = std::make_shared(Seeder::Config{trkDensityCfg}); } else if (m_cfg.seedFinder == SeedFinder::AdaptiveGridSeeder) { // Set up track density used during vertex seeding Acts::AdaptiveGridTrackDensity::Config trkDensityCfg; @@ -79,42 +100,17 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::execute( Acts::AdaptiveGridTrackDensity trkDensity(trkDensityCfg); // Set up vertex seeder and finder - using Seeder = Acts::AdaptiveGridDensityVertexFinder; - using Finder = Acts::AdaptiveMultiVertexFinder; + using Seeder = Acts::AdaptiveGridDensityVertexFinder; + using Finder = Acts::AdaptiveMultiVertexFinder; Seeder::Config seederConfig(trkDensity); seederConfig.extractParameters .connect<&Acts::InputTrack::extractParameters>(); - Seeder seedFinder(seederConfig); - return executeAfterSeederChoice(ctx, seedFinder); + seedFinder = std::make_shared(seederConfig); } else { - return ActsExamples::ProcessCode::ABORT; + throw std::invalid_argument("Unknown seed finder"); } -} - -template -ActsExamples::ProcessCode -ActsExamples::AdaptiveMultiVertexFinderAlgorithm::executeAfterSeederChoice( - const ActsExamples::AlgorithmContext& ctx, - const vseeder_t& seedFinder) const { - using Finder = vfinder_t; - // Set up EigenStepper - Acts::EigenStepper<> stepper(m_cfg.bField); - - // Set up the propagator - auto propagator = std::make_shared(stepper); - - // Set up ImpactPointEstimator - Acts::ImpactPointEstimator::Config ipEstimatorCfg(m_cfg.bField, propagator); - Acts::ImpactPointEstimator ipEstimator( - ipEstimatorCfg, logger().cloneWithSuffix("ImpactPointEstimator")); - - // Set up the helical track linearizer - Linearizer::Config ltConfig; - ltConfig.bField = m_cfg.bField; - ltConfig.propagator = propagator; - Linearizer linearizer(ltConfig, - logger().cloneWithSuffix("HelicalTrackLinearizer")); + using Finder = Acts::AdaptiveMultiVertexFinder; // Set up deterministic annealing with user-defined temperatures Acts::AnnealingUtility::Config annealingConfig; @@ -122,18 +118,18 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::executeAfterSeederChoice( Acts::AnnealingUtility annealingUtility(annealingConfig); // Set up the vertex fitter with user-defined annealing - Fitter::Config fitterCfg(ipEstimator); + Fitter::Config fitterCfg(m_ipEstimator); fitterCfg.annealingTool = annealingUtility; fitterCfg.minWeight = 0.001; fitterCfg.doSmoothing = true; fitterCfg.useTime = m_cfg.useTime; fitterCfg.extractParameters.connect<&Acts::InputTrack::extractParameters>(); - fitterCfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); + fitterCfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&m_linearizer); Fitter fitter(std::move(fitterCfg), logger().cloneWithSuffix("AdaptiveMultiVertexFitter")); - typename Finder::Config finderConfig(std::move(fitter), std::move(seedFinder), - ipEstimator, m_cfg.bField); + Finder::Config finderConfig(std::move(fitter), seedFinder, m_ipEstimator, + m_cfg.bField); // Set the initial variance of the 4D vertex position. Since time is on a // numerical scale, we have to provide a greater value in the corresponding // dimension. @@ -149,18 +145,22 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::executeAfterSeederChoice( // Check if vertices are merged in space and time // TODO rename do3dSplitting -> doFullSplitting finderConfig.do3dSplitting = true; - // Reset the maximum significance that two vertices can have before they are - // considered as merged. The default value 3 is tuned for comparing the - // vertices' z-coordinates. Since we consider 4 dimensions here, we need to - // multiply the value by 4 and thus we set it to 3 * 4 = 12. + // Reset the maximum significance that two vertices can have before they + // are considered as merged. The default value 3 is tuned for comparing + // the vertices' z-coordinates. Since we consider 4 dimensions here, we + // need to multiply the value by 4 and thus we set it to 3 * 4 = 12. finderConfig.maxMergeVertexSignificance = 12.; } finderConfig.extractParameters .template connect<&Acts::InputTrack::extractParameters>(); // Instantiate the finder - Finder finder(std::move(finderConfig), logger().clone()); + return Finder(std::move(finderConfig), logger().clone()); +} +ActsExamples::ProcessCode +ActsExamples::AdaptiveMultiVertexFinderAlgorithm::execute( + const ActsExamples::AlgorithmContext& ctx) const { // retrieve input tracks and convert into the expected format const auto& inputTrackParameters = m_inputTrackParameters(ctx); @@ -186,7 +186,7 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::executeAfterSeederChoice( ////////////////////////////////////////////// // The vertex finder state - auto state = finder.makeState(); + auto state = m_vertexFinder.makeState(); // Default vertexing options, this is where e.g. a constraint could be set Options finderOpts(ctx.geoContext, ctx.magFieldContext); @@ -199,7 +199,7 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::executeAfterSeederChoice( ACTS_DEBUG("Have " << inputTrackParameters.size() << " input track parameters, running vertexing"); // find vertices - auto result = finder.find(inputTracks, finderOpts, state); + auto result = m_vertexFinder.find(inputTracks, finderOpts, state); if (result.ok()) { vertices = std::move(result.value()); diff --git a/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp b/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp index caa7ac45118..cf91bb61bbc 100644 --- a/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp +++ b/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp @@ -95,7 +95,7 @@ ActsExamples::ProcessCode ActsExamples::IterativeVertexFinderAlgorithm::execute( Acts::GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&Acts::InputTrack::extractParameters>(); - Seeder seeder{{{densityCfg}}}; + auto seeder = std::make_shared(Seeder::Config{{densityCfg}}); // Set up the actual vertex finder Finder::Config finderCfg(std::move(vertexFitter), seeder, ipEst); finderCfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); diff --git a/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp index 7dec853dcb3..3f416b5da91 100644 --- a/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp @@ -112,13 +112,14 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_test) { Fitter fitter(fitterCfg); - using SeedFinder = TrackDensityVertexFinder; + using SeedFinder = TrackDensityVertexFinder; GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); - SeedFinder seedFinder{{densityCfg}}; + auto seedFinder = + std::make_shared(SeedFinder::Config{densityCfg}); - using Finder = AdaptiveMultiVertexFinder; + using Finder = AdaptiveMultiVertexFinder; Finder::Config finderConfig(std::move(fitter), seedFinder, ipEstimator, bField); @@ -273,13 +274,14 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_usertype_test) { Fitter fitter(fitterCfg); - using SeedFinder = TrackDensityVertexFinder; + using SeedFinder = TrackDensityVertexFinder; GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect(extractParameters); - SeedFinder seedFinder({densityCfg}); + auto seedFinder = + std::make_shared(SeedFinder::Config{densityCfg}); - using Finder = AdaptiveMultiVertexFinder; + using Finder = AdaptiveMultiVertexFinder; Finder::Config finderConfig(std::move(fitter), seedFinder, ipEstimator, bField); @@ -424,9 +426,9 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_grid_seed_finder_test) { seedFinderCfg.cacheGridStateForTrackRemoval = true; seedFinderCfg.extractParameters.connect<&InputTrack::extractParameters>(); - SeedFinder seedFinder(seedFinderCfg); + auto seedFinder = std::make_shared(seedFinderCfg); - using Finder = AdaptiveMultiVertexFinder; + using Finder = AdaptiveMultiVertexFinder; Finder::Config finderConfig(std::move(fitter), std::move(seedFinder), ipEst, bField); @@ -578,14 +580,14 @@ BOOST_AUTO_TEST_CASE( gridDensityCfg.spatialBinExtent = 0.05; AdaptiveGridTrackDensity gridDensity(gridDensityCfg); - using SeedFinder = AdaptiveGridDensityVertexFinder<>; + using SeedFinder = AdaptiveGridDensityVertexFinder; SeedFinder::Config seedFinderCfg(gridDensity); seedFinderCfg.cacheGridStateForTrackRemoval = true; seedFinderCfg.extractParameters.connect<&InputTrack::extractParameters>(); - SeedFinder seedFinder(seedFinderCfg); + auto seedFinder = std::make_shared(seedFinderCfg); - using Finder = AdaptiveMultiVertexFinder; + using Finder = AdaptiveMultiVertexFinder; Finder::Config finderConfig(std::move(fitter), std::move(seedFinder), ipEst, bField); diff --git a/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp index 1515b34b4d5..b623bcadce5 100644 --- a/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_test) { adaptiveDensityConfig.spatialBinExtent = 2. / 30.01 * 1_mm; AdaptiveGridTrackDensity adaptiveDensity(adaptiveDensityConfig); - using Finder2 = AdaptiveGridDensityVertexFinder<>; + using Finder2 = AdaptiveGridDensityVertexFinder; Finder2::Config cfg2(adaptiveDensity); cfg2.cacheGridStateForTrackRemoval = false; cfg2.extractParameters.connect<&InputTrack::extractParameters>(); @@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_track_caching_test) { adaptiveDensityConfig.useHighestSumZPosition = true; AdaptiveGridTrackDensity adaptiveDensity(adaptiveDensityConfig); - using Finder2 = AdaptiveGridDensityVertexFinder<>; + using Finder2 = AdaptiveGridDensityVertexFinder; Finder2::Config cfg2(adaptiveDensity); cfg2.cacheGridStateForTrackRemoval = true; cfg2.extractParameters.connect<&InputTrack::extractParameters>(); @@ -396,7 +396,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_seed_width_test) { adaptiveDensityConfig.spatialBinExtent = 2. / 30.01 * 1_mm; AdaptiveGridTrackDensity adaptiveDensity(adaptiveDensityConfig); - using Finder2 = AdaptiveGridDensityVertexFinder<>; + using Finder2 = AdaptiveGridDensityVertexFinder; Finder2::Config cfg2(adaptiveDensity); cfg2.cacheGridStateForTrackRemoval = false; cfg2.estimateSeedWidth = true; diff --git a/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp index de127b29367..f6a6c4b9437 100644 --- a/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp @@ -153,15 +153,15 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test) { ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); - using ZScanSeedFinder = ZScanVertexFinder; + using ZScanSeedFinder = ZScanVertexFinder; ZScanSeedFinder::Config seedFinderCfg(ipEstimator); seedFinderCfg.extractParameters.connect<&InputTrack::extractParameters>(); - ZScanSeedFinder sFinder(seedFinderCfg); + auto sFinder = std::make_shared(seedFinderCfg); // Vertex Finder - using VertexFinder = IterativeVertexFinder; + using VertexFinder = IterativeVertexFinder; VertexFinder::Config cfg(std::move(bFitter), std::move(sFinder), ipEstimator); @@ -375,14 +375,14 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_user_track_type) { ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); - using ZScanSeedFinder = ZScanVertexFinder; + using ZScanSeedFinder = ZScanVertexFinder; ZScanSeedFinder::Config seedFinderCfg(ipEstimator); seedFinderCfg.extractParameters.connect(extractParameters); - ZScanSeedFinder sFinder(seedFinderCfg); + auto sFinder = std::make_shared(seedFinderCfg); // Vertex Finder - using VertexFinder = IterativeVertexFinder; + using VertexFinder = IterativeVertexFinder; VertexFinder::Config cfg(std::move(bFitter), std::move(sFinder), ipEstimator); cfg.reassignTracksAfterFirstFit = true; @@ -577,15 +577,15 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_athena_reference) { ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); - using ZScanSeedFinder = ZScanVertexFinder; + using ZScanSeedFinder = ZScanVertexFinder; ZScanSeedFinder::Config seedFinderCfg(ipEstimator); seedFinderCfg.extractParameters.connect<&InputTrack::extractParameters>(); - ZScanSeedFinder sFinder(seedFinderCfg); + auto sFinder = std::make_shared(seedFinderCfg); // Vertex Finder - using VertexFinder = IterativeVertexFinder; + using VertexFinder = IterativeVertexFinder; VertexFinder::Config cfg(std::move(bFitter), std::move(sFinder), ipEstimator); cfg.maxVertices = 200; diff --git a/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp index 987b49c7465..5aef35f9034 100644 --- a/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp @@ -70,8 +70,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_test) { Vector3 mom1c{300_MeV, 1000_MeV, 100_MeV}; VertexingOptions vertexingOptions(geoContext, magFieldContext); - using Finder = - TrackDensityVertexFinder, GaussianTrackDensity>; + using Finder = TrackDensityVertexFinder; GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; @@ -151,8 +150,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_constr_test) { // Finder options VertexingOptions vertexingOptions(geoContext, magFieldContext, constraint); - using Finder = - TrackDensityVertexFinder, GaussianTrackDensity>; + using Finder = TrackDensityVertexFinder; GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; @@ -229,8 +227,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_random_test) { Surface::makeShared(pos0); VertexingOptions vertexingOptions(geoContext, magFieldContext); - using Finder = - TrackDensityVertexFinder, GaussianTrackDensity>; + using Finder = TrackDensityVertexFinder; GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; @@ -331,8 +328,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_usertrack_test) { return params.as()->parameters(); }; - using Finder = TrackDensityVertexFinder, - GaussianTrackDensity>; + using Finder = TrackDensityVertexFinder; GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect(extractParameters); diff --git a/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp index 4716f3aed19..877a4151b0d 100644 --- a/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE(zscan_finder_test) { inputTracks.emplace_back(&trk); } - using VertexFinder = ZScanVertexFinder; + using VertexFinder = ZScanVertexFinder; ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); @@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(zscan_finder_usertrack_test) { inputTracks.emplace_back(&trk); } - using VertexFinder = ZScanVertexFinder; + using VertexFinder = ZScanVertexFinder; ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); From 972294587e7c1e4931690eb686e8e40d669964ea Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Wed, 20 Dec 2023 16:54:36 +0100 Subject: [PATCH 03/14] fix: require setTracksToRemove to fix perf regression --- .../Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp | 7 +++++++ Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp | 6 ++++++ Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp | 2 +- Core/include/Acts/Vertexing/IVertexFinder.hpp | 7 +++---- Core/include/Acts/Vertexing/IterativeVertexFinder.hpp | 6 ++++++ Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp | 6 ++++++ Core/include/Acts/Vertexing/ZScanVertexFinder.hpp | 6 ++++++ 7 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp index ab1274d1913..2538ae220cd 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp @@ -101,6 +101,13 @@ class AdaptiveGridDensityVertexFinder final : public IVertexFinder { bool hasTrivialState() const override { return true; } + void setTracksToRemove( + IVertexFinder::State& state, + const std::vector& removedTracks) const override { + auto& thisState = state.template as(); + thisState.tracksToRemove = removedTracks; + } + /// @brief Constructor for user-defined InputTrack type /// /// @param cfg Configuration object diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp index 3a0a6a159e0..6deb3e62d20 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp @@ -205,6 +205,12 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { bool hasTrivialState() const override { return true; } + void setTracksToRemove( + IVertexFinder::State& /*state*/, + const std::vector& /*removedTracks*/) const override { + // Nothing to do here + } + private: /// Configuration object Config m_cfg; diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp index 516f4a9b288..db19af6e9a6 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp @@ -147,7 +147,7 @@ auto Acts::AdaptiveMultiVertexFinder::doSeeding( VertexingOptions seedOptions = vertexingOptions; seedOptions.constraint = currentConstraint; - m_cfg.seedFinder->setTrackToRemove(seedFinderState, removedSeedTracks); + m_cfg.seedFinder->setTracksToRemove(seedFinderState, removedSeedTracks); // Run seed finder auto seedResult = diff --git a/Core/include/Acts/Vertexing/IVertexFinder.hpp b/Core/include/Acts/Vertexing/IVertexFinder.hpp index b6ff14b4bd5..a6d95b1516b 100644 --- a/Core/include/Acts/Vertexing/IVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IVertexFinder.hpp @@ -22,7 +22,7 @@ struct VertexingOptions; class IVertexFinder { public: - using State = Acts::Any; + using State = Acts::AnyBase<128>; virtual Result> find( const std::vector& trackVector, @@ -32,8 +32,7 @@ class IVertexFinder { virtual bool hasTrivialState() const = 0; - virtual void setTrackToRemove( - State& /*state*/, - const std::vector& /*removedTracks*/) const {} + virtual void setTracksToRemove( + State& state, const std::vector& removedTracks) const = 0; }; } // namespace Acts diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index 6d60316fe95..fbd09bcf5fe 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -186,6 +186,12 @@ class IterativeVertexFinder final : public IVertexFinder { bool hasTrivialState() const override { return false; } + void setTracksToRemove( + IVertexFinder::State& /*state*/, + const std::vector& /*removedTracks*/) const override { + // Nothing to do here + } + private: /// Configuration object const Config m_cfg; diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp index 6147f82b24a..7e0e27b7ffc 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp @@ -59,6 +59,12 @@ class TrackDensityVertexFinder final : public IVertexFinder { return IVertexFinder::State{State{}}; } + void setTracksToRemove( + IVertexFinder::State& /*state*/, + const std::vector& /*removedTracks*/) const override { + // Nothing to do here + } + bool hasTrivialState() const override { return true; } /// @brief Constructor for user-defined InputTrack type diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp index 97b4637ad99..c636465c713 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp @@ -104,6 +104,12 @@ class ZScanVertexFinder final : public IVertexFinder { bool hasTrivialState() const override { return true; } + void setTracksToRemove( + IVertexFinder::State& /*state*/, + const std::vector& /*removedTracks*/) const override { + // Nothing to do here + } + private: Config m_cfg; From e146a22db34f277c77f4e54bc134700a536b62da Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Wed, 20 Dec 2023 18:08:32 +0100 Subject: [PATCH 04/14] fixup: GridDensityVertexFinder::setTracksToRemove --- Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp index 3d7238307bb..2521ffd1f35 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp @@ -121,6 +121,13 @@ class GridDensityVertexFinder final : public IVertexFinder { bool hasTrivialState() const override { return true; } + void setTracksToRemove( + IVertexFinder::State& state, + const std::vector& removedTracks) const override { + auto& thisState = state.template as(); + thisState.tracksToRemove = removedTracks; + } + /// @brief Constructor for user-defined InputTrack type /// /// @param cfg Configuration object From c3e9bb24c99d9c648a5197399a7d376f6a65b27e Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 21 Dec 2023 09:22:28 +0100 Subject: [PATCH 05/14] Add virtual destructor to IVertexFinder --- Core/include/Acts/Vertexing/IVertexFinder.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/include/Acts/Vertexing/IVertexFinder.hpp b/Core/include/Acts/Vertexing/IVertexFinder.hpp index a6d95b1516b..16941aaddab 100644 --- a/Core/include/Acts/Vertexing/IVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IVertexFinder.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2020 CERN for the benefit of the Acts project +// Copyright (C) 2023 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -34,5 +34,7 @@ class IVertexFinder { virtual void setTracksToRemove( State& state, const std::vector& removedTracks) const = 0; + + virtual ~IVertexFinder() = default; }; } // namespace Acts From d1fd468536d545424c6f5bbfff1005033d3688a1 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 15 Feb 2024 15:57:24 +0100 Subject: [PATCH 06/14] fix format --- .../Vertexing/AdaptiveGridDensityVertexFinder.ipp | 11 +++++------ .../Acts/Vertexing/AdaptiveMultiVertexFinder.hpp | 4 +--- .../Acts/Vertexing/GridDensityVertexFinder.ipp | 6 +++--- .../Acts/Vertexing/TrackDensityVertexFinder.ipp | 4 ++-- Core/include/Acts/Vertexing/ZScanVertexFinder.ipp | 3 +-- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp index eca5e91a782..666f107330f 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp @@ -6,12 +6,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -inline -auto Acts::AdaptiveGridDensityVertexFinder::find( +inline auto Acts::AdaptiveGridDensityVertexFinder::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const -> Result> { - auto& thisState = state.as(); + auto& thisState = state.as(); // Remove density contributions from tracks removed from track collection if (m_cfg.cacheGridStateForTrackRemoval && thisState.isInitialized && !thisState.tracksToRemove.empty()) { @@ -56,7 +55,8 @@ auto Acts::AdaptiveGridDensityVertexFinder::find( if (!m_cfg.estimateSeedWidth) { // Get z value of highest density bin - auto maxZTRes = m_cfg.gridDensity.getMaxZTPosition(thisState.mainDensityMap); + auto maxZTRes = + m_cfg.gridDensity.getMaxZTPosition(thisState.mainDensityMap); if (!maxZTRes.ok()) { return maxZTRes.error(); @@ -96,8 +96,7 @@ auto Acts::AdaptiveGridDensityVertexFinder::find( return seedVec; } -inline -auto Acts::AdaptiveGridDensityVertexFinder::doesPassTrackSelection( +inline auto Acts::AdaptiveGridDensityVertexFinder::doesPassTrackSelection( const BoundTrackParameters& trk) const -> bool { // Get required track parameters const double d0 = trk.parameters()[BoundIndices::eBoundLoc0]; diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp index 6deb3e62d20..1732418a0b1 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp @@ -219,9 +219,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { std::unique_ptr m_logger; /// Private access to logging instance - const Logger& logger() const { - return *m_logger; - } + const Logger& logger() const { return *m_logger; } /// @brief Calls the seed finder and sets constraints on the found seed /// vertex if desired diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp index 6c28deb41e2..82a34bbf909 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp @@ -11,8 +11,7 @@ auto Acts::GridDensityVertexFinder::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const -> Result> { - - auto& thisState = state.as(); + auto& thisState = state.as(); // Remove density contributions from tracks removed from track collection if (m_cfg.cacheGridStateForTrackRemoval && thisState.isInitialized && !thisState.tracksToRemove.empty()) { @@ -71,7 +70,8 @@ auto Acts::GridDensityVertexFinder::find( z = *maxZres; } else { // Get z value of highest density bin and width - auto maxZres = m_cfg.gridDensity.getMaxZPositionAndWidth(thisState.mainGrid); + auto maxZres = + m_cfg.gridDensity.getMaxZPositionAndWidth(thisState.mainGrid); if (!maxZres.ok()) { return maxZres.error(); diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp index aa769e149c5..1d1014014ef 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp @@ -6,8 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -template < typename track_density_t> -auto Acts::TrackDensityVertexFinder< track_density_t>::find( +template +auto Acts::TrackDensityVertexFinder::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& /*state*/) const -> Result> { diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp b/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp index 7167b5ebaba..76ea5e4c0ca 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp @@ -6,8 +6,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -inline -auto Acts::ZScanVertexFinder::find( +inline auto Acts::ZScanVertexFinder::find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, IVertexFinder::State& /*state*/) const -> Result> { From 8bb63025e4264d3e96854e83fd99a556fa42ce1a Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 21 Dec 2023 09:55:40 +0100 Subject: [PATCH 07/14] Remove VertexFitterConcept (it's not useful at the moment) --- .../Acts/Vertexing/IterativeVertexFinder.hpp | 4 -- .../Vertexing/TrackDensityVertexFinder.hpp | 1 - .../Acts/Vertexing/VertexFitterConcept.hpp | 51 ------------------- .../Acts/Vertexing/ZScanVertexFinder.hpp | 1 - 4 files changed, 57 deletions(-) delete mode 100644 Core/include/Acts/Vertexing/VertexFitterConcept.hpp diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index fbd09bcf5fe..038c7461e8d 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -20,7 +20,6 @@ #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/TrackLinearizer.hpp" #include "Acts/Vertexing/Vertex.hpp" -#include "Acts/Vertexing/VertexFitterConcept.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" #include "Acts/Vertexing/ZScanVertexFinder.hpp" @@ -60,9 +59,6 @@ namespace Acts { /// @tparam vfitter_t Vertex fitter type template class IterativeVertexFinder final : public IVertexFinder { - static_assert(VertexFitterConcept, - "Vertex fitter does not fulfill vertex fitter concept."); - public: /// Configuration struct struct Config { diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp index 7e0e27b7ffc..07888af4f7c 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp @@ -14,7 +14,6 @@ #include "Acts/Vertexing/GaussianTrackDensity.hpp" #include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/Vertex.hpp" -#include "Acts/Vertexing/VertexFitterConcept.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" namespace Acts { diff --git a/Core/include/Acts/Vertexing/VertexFitterConcept.hpp b/Core/include/Acts/Vertexing/VertexFitterConcept.hpp deleted file mode 100644 index bc1aaac5648..00000000000 --- a/Core/include/Acts/Vertexing/VertexFitterConcept.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// This file is part of the Acts project. -// -// Copyright (C) 2019 CERN for the benefit of the Acts project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Definitions/Algebra.hpp" -#include "Acts/Utilities/Result.hpp" -#include "Acts/Utilities/TypeTraits.hpp" -#include "Acts/Vertexing/Vertex.hpp" -#include "Acts/Vertexing/VertexingOptions.hpp" - -namespace Acts { - -namespace Concepts { -namespace VertexFitter { - -template -using state_t = typename T::State; - -METHOD_TRAIT(fit_t, fit); - -// clang-format off - template - struct VertexFitterConcept { - constexpr static bool fit_exists = has_method, - fit_t, - const std::vector&, - const VertexingOptions&, - typename S::State&>; - static_assert(fit_exists, "fit method not found"); - - constexpr static bool state_exists = exists; - static_assert(state_exists, "State type not found"); - - constexpr static bool value = require; - }; -// clang-format on -} // namespace VertexFitter -} // namespace Concepts - -template -constexpr bool VertexFitterConcept = - Acts::Concepts ::VertexFitter::VertexFitterConcept::value; - -} // namespace Acts diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp index c636465c713..7868c66b3b7 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp @@ -17,7 +17,6 @@ #include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/Vertex.hpp" -#include "Acts/Vertexing/VertexFitterConcept.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" #include From 4cbae009b6eb88b31b351244b66e028fcb4b751e Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Fri, 16 Feb 2024 13:53:18 +0100 Subject: [PATCH 08/14] IVertexFinder::makeState accepts magnetic field context --- .../AdaptiveGridDensityVertexFinder.hpp | 4 ++- .../Vertexing/AdaptiveMultiVertexFinder.hpp | 20 ++++++++----- .../Vertexing/AdaptiveMultiVertexFinder.ipp | 6 ++-- .../Vertexing/FullBilloirVertexFitter.hpp | 13 ++------ .../Vertexing/FullBilloirVertexFitter.ipp | 11 +++---- .../Vertexing/GridDensityVertexFinder.hpp | 4 ++- Core/include/Acts/Vertexing/IVertexFinder.hpp | 4 ++- .../Acts/Vertexing/IterativeVertexFinder.hpp | 30 ++++++++++++------- .../Acts/Vertexing/IterativeVertexFinder.ipp | 20 ++++++------- .../Vertexing/TrackDensityVertexFinder.hpp | 4 ++- .../Acts/Vertexing/ZScanVertexFinder.hpp | 3 +- .../AdaptiveMultiVertexFinderAlgorithm.cpp | 2 +- .../Vertexing/src/VertexFitterAlgorithm.cpp | 6 ++-- .../AdaptiveMultiVertexFinderTests.cpp | 8 ++--- .../FullBilloirVertexFitterTests.cpp | 24 +++++++-------- .../GridDensityVertexFinderTests.cpp | 12 ++++---- .../Vertexing/IterativeVertexFinderTests.cpp | 16 +++++----- .../TrackDensityVertexFinderTests.cpp | 8 ++--- .../Core/Vertexing/ZScanVertexFinderTests.cpp | 4 +-- 19 files changed, 109 insertions(+), 90 deletions(-) diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp index 2538ae220cd..931b6ffb7c3 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp @@ -9,6 +9,7 @@ #pragma once #include "Acts/EventData/TrackParameters.hpp" +#include "Acts/MagneticField/MagneticFieldContext.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/AdaptiveGridTrackDensity.hpp" #include "Acts/Vertexing/DummyVertexFitter.hpp" @@ -95,7 +96,8 @@ class AdaptiveGridDensityVertexFinder final : public IVertexFinder { const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const override; - IVertexFinder::State makeState() const override { + IVertexFinder::State makeState( + const Acts::MagneticFieldContext& /*mctx*/) const override { return IVertexFinder::State{State{}}; } diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp index 1732418a0b1..fe43520e6c5 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp @@ -11,6 +11,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/Units.hpp" #include "Acts/EventData/TrackParameters.hpp" +#include "Acts/MagneticField/MagneticFieldContext.hpp" #include "Acts/Utilities/Logger.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/AMVFInfo.hpp" @@ -19,6 +20,7 @@ #include "Acts/Vertexing/TrackLinearizer.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" +#include #include namespace Acts { @@ -153,7 +155,9 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { }; // Config struct /// State struct for fulfilling interface - struct State {}; + struct State { + std::reference_wrapper magContext; + }; /// @brief Constructor for user-defined InputTrack_t type != /// BoundTrackParameters @@ -192,15 +196,17 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { /// /// @param allTracks Input track collection /// @param vertexingOptions Vertexing options - /// @param state State for fulfilling interfaces + /// @param anyState The state object /// /// @return Vector of all reconstructed vertices - Result> find(const std::vector& allTracks, - const VertexingOptions& vertexingOptions, - IVertexFinder::State& state) const override; + Result> find( + const std::vector& allTracks, + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const override; - IVertexFinder::State makeState() const override { - return IVertexFinder::State{State{}}; + IVertexFinder::State makeState( + const Acts::MagneticFieldContext& mctx) const override { + return IVertexFinder::State{State{mctx}}; } bool hasTrivialState() const override { return true; } diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp index db19af6e9a6..5123b2f06b2 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp @@ -13,12 +13,14 @@ template auto Acts::AdaptiveMultiVertexFinder::find( const std::vector& allTracks, const VertexingOptions& vertexingOptions, - IVertexFinder::State& /*state*/) const -> Result> { + IVertexFinder::State& anyState) const -> Result> { if (allTracks.empty()) { ACTS_ERROR("Empty track collection handed to find method"); return VertexingError::EmptyInput; } + State& state = anyState.template as(); + // Original tracks const std::vector& origTracks = allTracks; @@ -26,7 +28,7 @@ auto Acts::AdaptiveMultiVertexFinder::find( std::vector seedTracks = allTracks; FitterState_t fitterState(*m_cfg.bField, vertexingOptions.magFieldContext); - auto seedFinderState = m_cfg.seedFinder->makeState(); + auto seedFinderState = m_cfg.seedFinder->makeState(state.magContext); std::vector> allVertices; diff --git a/Core/include/Acts/Vertexing/FullBilloirVertexFitter.hpp b/Core/include/Acts/Vertexing/FullBilloirVertexFitter.hpp index 082b6628b7b..e409748c497 100644 --- a/Core/include/Acts/Vertexing/FullBilloirVertexFitter.hpp +++ b/Core/include/Acts/Vertexing/FullBilloirVertexFitter.hpp @@ -8,6 +8,7 @@ #pragma once +#include "Acts/MagneticField/MagneticFieldContext.hpp" #include "Acts/MagneticField/MagneticFieldProvider.hpp" #include "Acts/Propagator/EigenStepper.hpp" #include "Acts/Propagator/Propagator.hpp" @@ -47,16 +48,6 @@ namespace Acts { /// Author(s) Russo, F class FullBilloirVertexFitter { public: - struct State { - /// @brief The state constructor - /// - /// @param fieldCache The magnetic field cache - State(MagneticFieldProvider::Cache _fieldCache) - : fieldCache(std::move(_fieldCache)) {} - - MagneticFieldProvider::Cache fieldCache; - }; - struct Config { /// Maximum number of iterations in fitter int maxIterations = 5; @@ -100,7 +91,7 @@ class FullBilloirVertexFitter { /// @return Fitted vertex Result fit(const std::vector& paramVector, const VertexingOptions& vertexingOptions, - State& state) const; + MagneticFieldProvider::Cache& fieldCache) const; private: /// Configuration object diff --git a/Core/include/Acts/Vertexing/FullBilloirVertexFitter.ipp b/Core/include/Acts/Vertexing/FullBilloirVertexFitter.ipp index 15f0d938f32..c640c723a61 100644 --- a/Core/include/Acts/Vertexing/FullBilloirVertexFitter.ipp +++ b/Core/include/Acts/Vertexing/FullBilloirVertexFitter.ipp @@ -56,7 +56,8 @@ struct BilloirVertex { inline Acts::Result Acts::FullBilloirVertexFitter::fit( const std::vector& paramVector, - const VertexingOptions& vertexingOptions, State& state) const { + const VertexingOptions& vertexingOptions, + MagneticFieldProvider::Cache& fieldCache) const { unsigned int nTracks = paramVector.size(); double chi2 = std::numeric_limits::max(); @@ -108,10 +109,10 @@ inline Acts::Result Acts::FullBilloirVertexFitter::fit( const auto& trackParams = m_cfg.extractParameters(trackContainer); - auto result = m_cfg.trackLinearizer( - trackParams, linPoint[3], *perigeeSurface, - vertexingOptions.geoContext, vertexingOptions.magFieldContext, - state.fieldCache); + auto result = + m_cfg.trackLinearizer(trackParams, linPoint[3], *perigeeSurface, + vertexingOptions.geoContext, + vertexingOptions.magFieldContext, fieldCache); if (!result.ok()) { return result.error(); } diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp index 2521ffd1f35..8a8c748e5a6 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp @@ -10,6 +10,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/EventData/TrackParameters.hpp" +#include "Acts/MagneticField/MagneticFieldContext.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/DummyVertexFitter.hpp" #include "Acts/Vertexing/GaussianGridTrackDensity.hpp" @@ -115,7 +116,8 @@ class GridDensityVertexFinder final : public IVertexFinder { const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const override; - IVertexFinder::State makeState() const override { + IVertexFinder::State makeState( + const Acts::MagneticFieldContext& /*mctx*/) const override { return IVertexFinder::State{State{}}; } diff --git a/Core/include/Acts/Vertexing/IVertexFinder.hpp b/Core/include/Acts/Vertexing/IVertexFinder.hpp index 16941aaddab..f9d808211af 100644 --- a/Core/include/Acts/Vertexing/IVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IVertexFinder.hpp @@ -8,6 +8,8 @@ #pragma once +#include "Acts/MagneticField/MagneticFieldContext.hpp" +#include "Acts/MagneticField/MagneticFieldProvider.hpp" #include "Acts/Utilities/Any.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" @@ -28,7 +30,7 @@ class IVertexFinder { const std::vector& trackVector, const VertexingOptions& vertexingOptions, State& state) const = 0; - virtual State makeState() const = 0; + virtual State makeState(const MagneticFieldContext& mctx) const = 0; virtual bool hasTrivialState() const = 0; diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index 038c7461e8d..9d35b7ae255 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -10,6 +10,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/EventData/TrackParameters.hpp" +#include "Acts/MagneticField/MagneticFieldContext.hpp" #include "Acts/MagneticField/MagneticFieldProvider.hpp" #include "Acts/Utilities/Logger.hpp" #include "Acts/Utilities/Result.hpp" @@ -23,6 +24,8 @@ #include "Acts/Vertexing/VertexingOptions.hpp" #include "Acts/Vertexing/ZScanVertexFinder.hpp" +#include + namespace Acts { /// @class IterativeVertexFinder @@ -111,21 +114,25 @@ class IterativeVertexFinder final : public IVertexFinder { /// decide if a track should be checked for reassignment to other vertices double cutOffTrackWeightReassign = 1; - // Function to extract parameters from InputTrack + /// Function to extract parameters from InputTrack InputTrack::Extractor extractParameters; + + /// Magnetic field provider + std::shared_ptr field; }; /// State struct struct State { State(const MagneticFieldProvider& field, const Acts::MagneticFieldContext& magContext) - : ipState(field.makeCache(magContext)), - fitterState(field.makeCache(magContext)), + : magContext(magContext), + ipState(field.makeCache(magContext)), fieldCache(field.makeCache(magContext)) {} + + std::reference_wrapper magContext; + /// The IP estimator state ImpactPointEstimator::State ipState; - /// The fitter state - typename vfitter_t::State fitterState; MagneticFieldProvider::Cache fieldCache; }; @@ -157,10 +164,10 @@ class IterativeVertexFinder final : public IVertexFinder { "No seed finder provided."); } - if (!m_cfg.seedFinder->hasTrivialState()) { + if (!m_cfg.field) { throw std::invalid_argument( "IterativeVertexFinder: " - "Seed finder must have trivial state."); + "No magnetic field provider provided."); } } @@ -175,9 +182,9 @@ class IterativeVertexFinder final : public IVertexFinder { const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const override; - IVertexFinder::State makeState() const override { - // @TODO: This is not great - throw std::runtime_error("Not implemented"); + IVertexFinder::State makeState( + const MagneticFieldContext& mctx) const override { + return IVertexFinder::State{State{*m_cfg.field, mctx}}; } bool hasTrivialState() const override { return false; } @@ -202,7 +209,8 @@ class IterativeVertexFinder final : public IVertexFinder { /// /// @param seedTracks Seeding tracks /// @param vertexingOptions Vertexing options - Result getVertexSeed(const std::vector& seedTracks, + Result getVertexSeed(State& state, + const std::vector& seedTracks, const VertexingOptions& vertexingOptions) const; /// @brief Removes all tracks in tracksToRemove from seedTracks diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp index 2c5400b9429..10d352e350f 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp @@ -24,7 +24,7 @@ auto Acts::IterativeVertexFinder::find( // begin iterating while (seedTracks.size() > 1 && nInterations < m_cfg.maxVertices) { /// Do seeding - auto seedRes = getVertexSeed(seedTracks, vertexingOptions); + auto seedRes = getVertexSeed(thisState, seedTracks, vertexingOptions); if (!seedRes.ok()) { return seedRes.error(); @@ -61,7 +61,7 @@ auto Acts::IterativeVertexFinder::find( if (vertexingOptions.useConstraintInFit && !tracksToFit.empty()) { auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - thisState.fitterState); + thisState.fieldCache); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { @@ -69,7 +69,7 @@ auto Acts::IterativeVertexFinder::find( } } else if (!vertexingOptions.useConstraintInFit && tracksToFit.size() > 1) { auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - thisState.fitterState); + thisState.fieldCache); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { @@ -78,7 +78,7 @@ auto Acts::IterativeVertexFinder::find( } if (m_cfg.createSplitVertices && tracksToFitSplitVertex.size() > 1) { auto fitResult = m_cfg.vertexFitter.fit( - tracksToFitSplitVertex, vertexingOptions, thisState.fitterState); + tracksToFitSplitVertex, vertexingOptions, thisState.fieldCache); if (fitResult.ok()) { currentSplitVertex = std::move(*fitResult); } else { @@ -158,9 +158,9 @@ auto Acts::IterativeVertexFinder::find( template auto Acts::IterativeVertexFinder::getVertexSeed( - const std::vector& seedTracks, + State& state, const std::vector& seedTracks, const VertexingOptions& vertexingOptions) const -> Result { - auto finderState = m_cfg.seedFinder->makeState(); + auto finderState = m_cfg.seedFinder->makeState(state.magContext); auto res = m_cfg.seedFinder->find(seedTracks, vertexingOptions, finderState); if (!res.ok()) { @@ -509,16 +509,16 @@ Acts::IterativeVertexFinder::reassignTracksToNewVertex( // later currentVertex = Vertex(); if (vertexingOptions.useConstraintInFit && !tracksToFit.empty()) { - auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - state.fitterState); + auto fitResult = + m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, state.fieldCache); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { return Result::success(false); } } else if (!vertexingOptions.useConstraintInFit && tracksToFit.size() > 1) { - auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - state.fitterState); + auto fitResult = + m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, state.fieldCache); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp index 07888af4f7c..1f100e24a38 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp @@ -10,6 +10,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/EventData/TrackParameters.hpp" +#include "Acts/MagneticField/MagneticFieldContext.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Vertexing/GaussianTrackDensity.hpp" #include "Acts/Vertexing/IVertexFinder.hpp" @@ -54,7 +55,8 @@ class TrackDensityVertexFinder final : public IVertexFinder { const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const override; - IVertexFinder::State makeState() const override { + IVertexFinder::State makeState( + const Acts::MagneticFieldContext& /*mctx*/) const override { return IVertexFinder::State{State{}}; } diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp index 7868c66b3b7..bdae2bc793f 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp @@ -97,7 +97,8 @@ class ZScanVertexFinder final : public IVertexFinder { const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const override; - IVertexFinder::State makeState() const override { + IVertexFinder::State makeState( + const Acts::MagneticFieldContext& /*mctx*/) const override { return IVertexFinder::State{State{}}; } diff --git a/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp b/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp index dfd421b499f..fbc420c27e1 100644 --- a/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp +++ b/Examples/Algorithms/Vertexing/src/AdaptiveMultiVertexFinderAlgorithm.cpp @@ -186,7 +186,7 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::execute( ////////////////////////////////////////////// // The vertex finder state - auto state = m_vertexFinder.makeState(); + auto state = m_vertexFinder.makeState(ctx.magFieldContext); // Default vertexing options, this is where e.g. a constraint could be set Options finderOpts(ctx.geoContext, ctx.magFieldContext); diff --git a/Examples/Algorithms/Vertexing/src/VertexFitterAlgorithm.cpp b/Examples/Algorithms/Vertexing/src/VertexFitterAlgorithm.cpp index d47bae5d435..1ce62fc90a3 100644 --- a/Examples/Algorithms/Vertexing/src/VertexFitterAlgorithm.cpp +++ b/Examples/Algorithms/Vertexing/src/VertexFitterAlgorithm.cpp @@ -62,7 +62,7 @@ ActsExamples::ProcessCode ActsExamples::VertexFitterAlgorithm::execute( vertexFitterCfg.trackLinearizer.connect<&Linearizer::linearizeTrack>( &linearizer); VertexFitter vertexFitter(vertexFitterCfg); - VertexFitter::State state(m_cfg.bField->makeCache(ctx.magFieldContext)); + auto fieldCache = m_cfg.bField->makeCache(ctx.magFieldContext); ACTS_VERBOSE("Read from '" << m_cfg.inputTrackParameters << "'"); ACTS_VERBOSE("Read from '" << m_cfg.inputProtoVertices << "'"); @@ -100,7 +100,7 @@ ActsExamples::ProcessCode ActsExamples::VertexFitterAlgorithm::execute( if (!m_cfg.doConstrainedFit) { VertexFitterOptions vfOptions(ctx.geoContext, ctx.magFieldContext); - auto fitRes = vertexFitter.fit(inputTracks, vfOptions, state); + auto fitRes = vertexFitter.fit(inputTracks, vfOptions, fieldCache); if (fitRes.ok()) { fittedVertices.push_back(*fitRes); } else { @@ -117,7 +117,7 @@ ActsExamples::ProcessCode ActsExamples::VertexFitterAlgorithm::execute( VertexFitterOptions vfOptionsConstr(ctx.geoContext, ctx.magFieldContext, theConstraint); - auto fitRes = vertexFitter.fit(inputTracks, vfOptionsConstr, state); + auto fitRes = vertexFitter.fit(inputTracks, vfOptionsConstr, fieldCache); if (fitRes.ok()) { fittedVertices.push_back(*fitRes); } else { diff --git a/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp index 3f416b5da91..e0fefc7b364 100644 --- a/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFinderTests.cpp @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_test) { finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - IVertexFinder::State state = finder.makeState(); + IVertexFinder::State state = finder.makeState(magFieldContext); auto csvData = readTracksAndVertexCSV(toolString); std::vector tracks = std::get(csvData); @@ -288,7 +288,7 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_usertype_test) { finderConfig.extractParameters.connect(extractParameters); Finder finder(std::move(finderConfig)); - IVertexFinder::State state = finder.makeState(); + IVertexFinder::State state = finder.makeState(magFieldContext); auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); @@ -435,7 +435,7 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_grid_seed_finder_test) { finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - IVertexFinder::State state = finder.makeState(); + IVertexFinder::State state = finder.makeState(magFieldContext); auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); @@ -594,7 +594,7 @@ BOOST_AUTO_TEST_CASE( finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - IVertexFinder::State state = finder.makeState(); + IVertexFinder::State state = finder.makeState(magFieldContext); auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); diff --git a/Tests/UnitTests/Core/Vertexing/FullBilloirVertexFitterTests.cpp b/Tests/UnitTests/Core/Vertexing/FullBilloirVertexFitterTests.cpp index 47986930e50..ae15fc109d2 100644 --- a/Tests/UnitTests/Core/Vertexing/FullBilloirVertexFitterTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/FullBilloirVertexFitterTests.cpp @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(billoir_vertex_fitter_defaulttrack_test) { vertexFitterCfg.trackLinearizer .connect<&HelicalTrackLinearizer::linearizeTrack>(&linearizer); VertexFitter billoirFitter(vertexFitterCfg); - VertexFitter::State state(bField->makeCache(magFieldContext)); + auto fieldCache = bField->makeCache(magFieldContext); // Vertexing options for default tracks VertexingOptions vfOptions(geoContext, magFieldContext); VertexingOptions vfOptionsConstr(geoContext, magFieldContext, constraint); @@ -166,7 +166,6 @@ BOOST_AUTO_TEST_CASE(billoir_vertex_fitter_defaulttrack_test) { customVertexFitterCfg.trackLinearizer .connect<&HelicalTrackLinearizer::linearizeTrack>(&linearizer); VertexFitter customBilloirFitter(customVertexFitterCfg); - VertexFitter::State customState(bField->makeCache(magFieldContext)); // Vertexing options for custom tracks VertexingOptions customVfOptions(geoContext, magFieldContext); VertexingOptions customVfOptionsConstr(geoContext, magFieldContext, @@ -179,7 +178,7 @@ BOOST_AUTO_TEST_CASE(billoir_vertex_fitter_defaulttrack_test) { // Without constraint Vertex fittedVertex = - billoirFitter.fit(emptyVectorInput, vfOptions, state).value(); + billoirFitter.fit(emptyVectorInput, vfOptions, fieldCache).value(); Vector3 origin(0., 0., 0.); SquareMatrix4 zeroMat = SquareMatrix4::Zero(); @@ -188,7 +187,8 @@ BOOST_AUTO_TEST_CASE(billoir_vertex_fitter_defaulttrack_test) { // With constraint fittedVertex = - billoirFitter.fit(emptyVectorInput, vfOptionsConstr, state).value(); + billoirFitter.fit(emptyVectorInput, vfOptionsConstr, fieldCache) + .value(); BOOST_CHECK_EQUAL(fittedVertex.position(), origin); BOOST_CHECK_EQUAL(fittedVertex.fullCovariance(), zeroMat); @@ -260,9 +260,10 @@ BOOST_AUTO_TEST_CASE(billoir_vertex_fitter_defaulttrack_test) { customInputTracks.push_back(InputTrack{&trk}); } - auto fit = [&trueVertex, &nTracks](const auto& fitter, const auto& trksPtr, - const auto& vfOpts, auto& vfState) { - auto fittedVertex = fitter.fit(trksPtr, vfOpts, vfState).value(); + auto fit = [&trueVertex, &nTracks, &fieldCache](const auto& fitter, + const auto& trksPtr, + const auto& vfOpts) { + auto fittedVertex = fitter.fit(trksPtr, vfOpts, fieldCache).value(); if (!fittedVertex.tracks().empty()) { CHECK_CLOSE_ABS(fittedVertex.position(), trueVertex.head(3), 1_mm); auto tracksAtVtx = fittedVertex.tracks(); @@ -278,22 +279,21 @@ BOOST_AUTO_TEST_CASE(billoir_vertex_fitter_defaulttrack_test) { BOOST_TEST_CONTEXT( "Testing FullBilloirVertexFitter without vertex constraint.") { - fit(billoirFitter, inputTracks, vfOptions, state); + fit(billoirFitter, inputTracks, vfOptions); } BOOST_TEST_CONTEXT( "Testing FullBilloirVertexFitter with vertex constraint.") { - fit(billoirFitter, inputTracks, vfOptionsConstr, state); + fit(billoirFitter, inputTracks, vfOptionsConstr); } BOOST_TEST_CONTEXT( "Testing FullBilloirVertexFitter with custom tracks (no vertex " "constraint).") { - fit(customBilloirFitter, customInputTracks, customVfOptions, customState); + fit(customBilloirFitter, customInputTracks, customVfOptions); } BOOST_TEST_CONTEXT( "Testing FullBilloirVertexFitter with custom tracks (with vertex " "constraint).") { - fit(customBilloirFitter, customInputTracks, customVfOptionsConstr, - customState); + fit(customBilloirFitter, customInputTracks, customVfOptionsConstr); } } } diff --git a/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp index b623bcadce5..ae3d958a2bf 100644 --- a/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/GridDensityVertexFinderTests.cpp @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_test) { cfg1.cacheGridStateForTrackRemoval = false; cfg1.extractParameters.connect<&InputTrack::extractParameters>(); Finder1 finder1(cfg1); - IVertexFinder::State state1 = finder1.makeState(); + IVertexFinder::State state1 = finder1.makeState(magFieldContext); // Use custom grid density here with same bin size as Finder1 AdaptiveGridTrackDensity::Config adaptiveDensityConfig; @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_test) { cfg2.cacheGridStateForTrackRemoval = false; cfg2.extractParameters.connect<&InputTrack::extractParameters>(); Finder2 finder2(cfg2); - IVertexFinder::State state2 = finder2.makeState(); + IVertexFinder::State state2 = finder2.makeState(magFieldContext); int mySeed = 31415; std::mt19937 gen(mySeed); @@ -276,8 +276,8 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_track_caching_test) { inputTracks.emplace_back(&trk); } - IVertexFinder::State state1 = finder1.makeState(); - IVertexFinder::State state2 = finder2.makeState(); + IVertexFinder::State state1 = finder1.makeState(magFieldContext); + IVertexFinder::State state2 = finder2.makeState(magFieldContext); double zResult1 = 0; double zResult2 = 0; @@ -388,7 +388,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_seed_width_test) { cfg1.estimateSeedWidth = true; cfg1.extractParameters.connect<&InputTrack::extractParameters>(); Finder1 finder1(cfg1); - IVertexFinder::State state1 = finder1.makeState(); + IVertexFinder::State state1 = finder1.makeState(magFieldContext); // Use custom grid density here with same bin size as Finder1 AdaptiveGridTrackDensity::Config adaptiveDensityConfig; @@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_seed_width_test) { cfg2.estimateSeedWidth = true; cfg2.extractParameters.connect<&InputTrack::extractParameters>(); Finder2 finder2(cfg2); - IVertexFinder::State state2 = finder2.makeState(); + IVertexFinder::State state2 = finder2.makeState(magFieldContext); int mySeed = 31415; std::mt19937 gen(mySeed); diff --git a/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp index f6a6c4b9437..eed6c0fbfe9 100644 --- a/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/IterativeVertexFinderTests.cpp @@ -124,10 +124,10 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test) { // Number of test events unsigned int nEvents = 5; // = nTest - for (unsigned int iEvent = 0; iEvent < nEvents; ++iEvent) { - // Set up constant B-Field - auto bField = std::make_shared(Vector3{0.0, 0.0, 1_T}); + // Set up constant B-Field + auto bField = std::make_shared(Vector3{0.0, 0.0, 1_T}); + for (unsigned int iEvent = 0; iEvent < nEvents; ++iEvent) { // Set up Eigenstepper EigenStepper<> stepper(bField); @@ -165,6 +165,7 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test) { VertexFinder::Config cfg(std::move(bFitter), std::move(sFinder), ipEstimator); + cfg.field = bField; cfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); cfg.reassignTracksAfterFirstFit = true; @@ -339,10 +340,10 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_user_track_type) { // Number of test events unsigned int nEvents = 5; // = nTest - for (unsigned int iEvent = 0; iEvent < nEvents; ++iEvent) { - // Set up constant B-Field - auto bField = std::make_shared(Vector3{0.0, 0.0, 1_T}); + // Set up constant B-Field + auto bField = std::make_shared(Vector3{0.0, 0.0, 1_T}); + for (unsigned int iEvent = 0; iEvent < nEvents; ++iEvent) { // Set up Eigenstepper EigenStepper<> stepper(bField); @@ -388,7 +389,7 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_user_track_type) { cfg.reassignTracksAfterFirstFit = true; cfg.extractParameters.connect(extractParameters); cfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); - + cfg.field = bField; VertexFinder finder(std::move(cfg)); IVertexFinder::State state{VertexFinder::State(*bField, magFieldContext)}; @@ -593,6 +594,7 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_athena_reference) { cfg.significanceCutSeeding = 12; cfg.extractParameters.connect<&InputTrack::extractParameters>(); cfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); + cfg.field = bField; VertexFinder finder(std::move(cfg)); IVertexFinder::State state{VertexFinder::State(*bField, magFieldContext)}; diff --git a/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp index 5aef35f9034..f144b7f95cc 100644 --- a/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_test) { GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; - auto state = finder.makeState(); + auto state = finder.makeState(magFieldContext); // Start creating some track parameters Covariance covMat = Covariance::Identity(); @@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_constr_test) { GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; - auto state = finder.makeState(); + auto state = finder.makeState(magFieldContext); // Start creating some track parameters Covariance covMat = Covariance::Identity(); @@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_random_test) { GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder{{{densityCfg}}}; - auto state = finder.makeState(); + auto state = finder.makeState(magFieldContext); int mySeed = 31415; std::mt19937 gen(mySeed); @@ -333,7 +333,7 @@ BOOST_AUTO_TEST_CASE(track_density_finder_usertrack_test) { GaussianTrackDensity::Config densityCfg; densityCfg.extractParameters.connect(extractParameters); Finder finder{{{densityCfg}}}; - auto state = finder.makeState(); + auto state = finder.makeState(magFieldContext); // Start creating some track parameters Covariance covMat = Covariance::Identity(); diff --git a/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp b/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp index 877a4151b0d..3ae2042bfb2 100644 --- a/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/ZScanVertexFinderTests.cpp @@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(zscan_finder_test) { VertexingOptions vertexingOptions(geoContext, magFieldContext); - auto state = finder.makeState(); + auto state = finder.makeState(magFieldContext); auto res = finder.find(inputTracks, vertexingOptions, state); BOOST_CHECK(res.ok()); @@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE(zscan_finder_usertrack_test) { cfg.extractParameters.connect(extractParameters); VertexFinder finder(cfg); - auto state = finder.makeState(); + auto state = finder.makeState(magFieldContext); VertexingOptions vertexingOptions(geoContext, magFieldContext); From 29213f8834045883610c810f1a554931a49ddf76 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Fri, 16 Feb 2024 14:57:31 +0100 Subject: [PATCH 09/14] Remove hasTrivialState --- .../Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp | 2 -- Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp | 8 -------- Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp | 2 -- Core/include/Acts/Vertexing/IVertexFinder.hpp | 2 -- Core/include/Acts/Vertexing/IterativeVertexFinder.hpp | 2 -- Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp | 2 -- Core/include/Acts/Vertexing/ZScanVertexFinder.hpp | 2 -- 7 files changed, 20 deletions(-) diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp index 931b6ffb7c3..28d5e61b1ae 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp @@ -101,8 +101,6 @@ class AdaptiveGridDensityVertexFinder final : public IVertexFinder { return IVertexFinder::State{State{}}; } - bool hasTrivialState() const override { return true; } - void setTracksToRemove( IVertexFinder::State& state, const std::vector& removedTracks) const override { diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp index fe43520e6c5..da84374a69b 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp @@ -181,12 +181,6 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { "AdaptiveMultiVertexFinder: " "No vertex fitter provided."); } - - if (!m_cfg.seedFinder->hasTrivialState()) { - throw std::invalid_argument( - "AdaptiveMultiVertexFinder: " - "Seed finder state must be trivial."); - } } AdaptiveMultiVertexFinder(AdaptiveMultiVertexFinder&&) = default; @@ -209,8 +203,6 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder { return IVertexFinder::State{State{mctx}}; } - bool hasTrivialState() const override { return true; } - void setTracksToRemove( IVertexFinder::State& /*state*/, const std::vector& /*removedTracks*/) const override { diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp index 8a8c748e5a6..648f414e7a7 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp @@ -121,8 +121,6 @@ class GridDensityVertexFinder final : public IVertexFinder { return IVertexFinder::State{State{}}; } - bool hasTrivialState() const override { return true; } - void setTracksToRemove( IVertexFinder::State& state, const std::vector& removedTracks) const override { diff --git a/Core/include/Acts/Vertexing/IVertexFinder.hpp b/Core/include/Acts/Vertexing/IVertexFinder.hpp index f9d808211af..a5ac538d311 100644 --- a/Core/include/Acts/Vertexing/IVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IVertexFinder.hpp @@ -32,8 +32,6 @@ class IVertexFinder { virtual State makeState(const MagneticFieldContext& mctx) const = 0; - virtual bool hasTrivialState() const = 0; - virtual void setTracksToRemove( State& state, const std::vector& removedTracks) const = 0; diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index 9d35b7ae255..5270c99505b 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -187,8 +187,6 @@ class IterativeVertexFinder final : public IVertexFinder { return IVertexFinder::State{State{*m_cfg.field, mctx}}; } - bool hasTrivialState() const override { return false; } - void setTracksToRemove( IVertexFinder::State& /*state*/, const std::vector& /*removedTracks*/) const override { diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp index 1f100e24a38..d81db1535d6 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp @@ -66,8 +66,6 @@ class TrackDensityVertexFinder final : public IVertexFinder { // Nothing to do here } - bool hasTrivialState() const override { return true; } - /// @brief Constructor for user-defined InputTrack type /// /// @param cfg Configuration object diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp index bdae2bc793f..71417f42483 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp @@ -102,8 +102,6 @@ class ZScanVertexFinder final : public IVertexFinder { return IVertexFinder::State{State{}}; } - bool hasTrivialState() const override { return true; } - void setTracksToRemove( IVertexFinder::State& /*state*/, const std::vector& /*removedTracks*/) const override { From b18541e75709244a366494dd442a8a94fd3127d3 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Fri, 16 Feb 2024 16:36:00 +0100 Subject: [PATCH 10/14] thisState -> anyState --- .../AdaptiveGridDensityVertexFinder.hpp | 15 ++++---- .../AdaptiveGridDensityVertexFinder.ipp | 33 ++++++++--------- .../Vertexing/GridDensityVertexFinder.hpp | 15 ++++---- .../Vertexing/GridDensityVertexFinder.ipp | 37 +++++++++---------- Core/include/Acts/Vertexing/IVertexFinder.hpp | 2 +- .../Acts/Vertexing/IterativeVertexFinder.hpp | 11 +++--- .../Acts/Vertexing/IterativeVertexFinder.ipp | 25 ++++++------- 7 files changed, 69 insertions(+), 69 deletions(-) diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp index 28d5e61b1ae..db9933cf87a 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp @@ -86,15 +86,16 @@ class AdaptiveGridDensityVertexFinder final : public IVertexFinder { /// /// @param trackVector Input track collection /// @param vertexingOptions Vertexing options - /// @param state The state object to cache the density grid + /// @param anyState The state object to cache the density grid /// and density contributions of each track, to be used /// if cacheGridStateForTrackRemoval == true /// /// @return Vector of vertices, filled with a single /// vertex (for consistent interfaces) - Result> find(const std::vector& trackVector, - const VertexingOptions& vertexingOptions, - IVertexFinder::State& state) const override; + Result> find( + const std::vector& trackVector, + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const override; IVertexFinder::State makeState( const Acts::MagneticFieldContext& /*mctx*/) const override { @@ -102,10 +103,10 @@ class AdaptiveGridDensityVertexFinder final : public IVertexFinder { } void setTracksToRemove( - IVertexFinder::State& state, + IVertexFinder::State& anyState, const std::vector& removedTracks) const override { - auto& thisState = state.template as(); - thisState.tracksToRemove = removedTracks; + auto& state = anyState.template as(); + state.tracksToRemove = removedTracks; } /// @brief Constructor for user-defined InputTrack type diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp index 666f107330f..14242ae8f22 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp @@ -8,22 +8,22 @@ inline auto Acts::AdaptiveGridDensityVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const - -> Result> { - auto& thisState = state.as(); + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const -> Result> { + auto& state = anyState.as(); // Remove density contributions from tracks removed from track collection - if (m_cfg.cacheGridStateForTrackRemoval && thisState.isInitialized && - !thisState.tracksToRemove.empty()) { - for (auto trk : thisState.tracksToRemove) { - auto it = thisState.trackDensities.find(trk); - if (it == thisState.trackDensities.end()) { + if (m_cfg.cacheGridStateForTrackRemoval && state.isInitialized && + !state.tracksToRemove.empty()) { + for (auto trk : state.tracksToRemove) { + auto it = state.trackDensities.find(trk); + if (it == state.trackDensities.end()) { // Track was never added to grid, so cannot remove it continue; } - m_cfg.gridDensity.subtractTrack(it->second, thisState.mainDensityMap); + m_cfg.gridDensity.subtractTrack(it->second, state.mainDensityMap); } } else { - thisState.mainDensityMap = DensityMap(); + state.mainDensityMap = DensityMap(); // Fill with track densities for (auto trk : trackVector) { const BoundTrackParameters& trkParams = m_cfg.extractParameters(trk); @@ -32,16 +32,16 @@ inline auto Acts::AdaptiveGridDensityVertexFinder::find( continue; } auto trackDensityMap = - m_cfg.gridDensity.addTrack(trkParams, thisState.mainDensityMap); + m_cfg.gridDensity.addTrack(trkParams, state.mainDensityMap); // Cache track density contribution to main grid if enabled if (m_cfg.cacheGridStateForTrackRemoval) { - thisState.trackDensities[trk] = std::move(trackDensityMap); + state.trackDensities[trk] = std::move(trackDensityMap); } } - thisState.isInitialized = true; + state.isInitialized = true; } - if (thisState.mainDensityMap.empty()) { + if (state.mainDensityMap.empty()) { // No tracks passed selection // Return empty seed, i.e. vertex at constraint position // (Note: Upstream finder should check for this break condition) @@ -55,8 +55,7 @@ inline auto Acts::AdaptiveGridDensityVertexFinder::find( if (!m_cfg.estimateSeedWidth) { // Get z value of highest density bin - auto maxZTRes = - m_cfg.gridDensity.getMaxZTPosition(thisState.mainDensityMap); + auto maxZTRes = m_cfg.gridDensity.getMaxZTPosition(state.mainDensityMap); if (!maxZTRes.ok()) { return maxZTRes.error(); @@ -66,7 +65,7 @@ inline auto Acts::AdaptiveGridDensityVertexFinder::find( } else { // Get z value of highest density bin and width auto maxZTResAndWidth = - m_cfg.gridDensity.getMaxZTPositionAndWidth(thisState.mainDensityMap); + m_cfg.gridDensity.getMaxZTPositionAndWidth(state.mainDensityMap); if (!maxZTResAndWidth.ok()) { return maxZTResAndWidth.error(); diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp index 648f414e7a7..20441f74266 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp @@ -106,15 +106,16 @@ class GridDensityVertexFinder final : public IVertexFinder { /// /// @param trackVector Input track collection /// @param vertexingOptions Vertexing options - /// @param state The state object to cache the density grid + /// @param anyState The state object to cache the density grid /// and density contributions of each track, to be used /// if cacheGridStateForTrackRemoval == true /// /// @return Vector of vertices, filled with a single /// vertex (for consistent interfaces) - Result> find(const std::vector& trackVector, - const VertexingOptions& vertexingOptions, - IVertexFinder::State& state) const override; + Result> find( + const std::vector& trackVector, + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const override; IVertexFinder::State makeState( const Acts::MagneticFieldContext& /*mctx*/) const override { @@ -122,10 +123,10 @@ class GridDensityVertexFinder final : public IVertexFinder { } void setTracksToRemove( - IVertexFinder::State& state, + IVertexFinder::State& anyState, const std::vector& removedTracks) const override { - auto& thisState = state.template as(); - thisState.tracksToRemove = removedTracks; + auto& state = anyState.template as(); + state.tracksToRemove = removedTracks; } /// @brief Constructor for user-defined InputTrack type diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp index 82a34bbf909..9c3585f5ba6 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp @@ -9,23 +9,23 @@ template auto Acts::GridDensityVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const - -> Result> { - auto& thisState = state.as(); + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const -> Result> { + auto& state = anyState.as(); // Remove density contributions from tracks removed from track collection - if (m_cfg.cacheGridStateForTrackRemoval && thisState.isInitialized && - !thisState.tracksToRemove.empty()) { + if (m_cfg.cacheGridStateForTrackRemoval && state.isInitialized && + !state.tracksToRemove.empty()) { // Bool to check if removable tracks, that pass selection, still exist bool couldRemoveTracks = false; - for (auto trk : thisState.tracksToRemove) { - if (!thisState.trackSelectionMap.at(trk)) { + for (auto trk : state.tracksToRemove) { + if (!state.trackSelectionMap.at(trk)) { // Track was never added to grid, so cannot remove it continue; } couldRemoveTracks = true; - auto binAndTrackGrid = thisState.binAndTrackGridMap.at(trk); + auto binAndTrackGrid = state.binAndTrackGridMap.at(trk); m_cfg.gridDensity.removeTrackGridFromMainGrid( - binAndTrackGrid.first, binAndTrackGrid.second, thisState.mainGrid); + binAndTrackGrid.first, binAndTrackGrid.second, state.mainGrid); } if (!couldRemoveTracks) { // No tracks were removed anymore @@ -35,34 +35,34 @@ auto Acts::GridDensityVertexFinder::find( return seedVec; } } else { - thisState.mainGrid = MainGridVector::Zero(); + state.mainGrid = MainGridVector::Zero(); // Fill with track densities for (auto trk : trackVector) { const BoundTrackParameters& trkParams = m_cfg.extractParameters(trk); // Take only tracks that fulfill selection criteria if (!doesPassTrackSelection(trkParams)) { if (m_cfg.cacheGridStateForTrackRemoval) { - thisState.trackSelectionMap[trk] = false; + state.trackSelectionMap[trk] = false; } continue; } auto binAndTrackGrid = - m_cfg.gridDensity.addTrack(trkParams, thisState.mainGrid); + m_cfg.gridDensity.addTrack(trkParams, state.mainGrid); // Cache track density contribution to main grid if enabled if (m_cfg.cacheGridStateForTrackRemoval) { - thisState.binAndTrackGridMap[trk] = binAndTrackGrid; - thisState.trackSelectionMap[trk] = true; + state.binAndTrackGridMap[trk] = binAndTrackGrid; + state.trackSelectionMap[trk] = true; } } - thisState.isInitialized = true; + state.isInitialized = true; } double z = 0; double width = 0; - if (thisState.mainGrid != MainGridVector::Zero()) { + if (state.mainGrid != MainGridVector::Zero()) { if (!m_cfg.estimateSeedWidth) { // Get z value of highest density bin - auto maxZres = m_cfg.gridDensity.getMaxZPosition(thisState.mainGrid); + auto maxZres = m_cfg.gridDensity.getMaxZPosition(state.mainGrid); if (!maxZres.ok()) { return maxZres.error(); @@ -70,8 +70,7 @@ auto Acts::GridDensityVertexFinder::find( z = *maxZres; } else { // Get z value of highest density bin and width - auto maxZres = - m_cfg.gridDensity.getMaxZPositionAndWidth(thisState.mainGrid); + auto maxZres = m_cfg.gridDensity.getMaxZPositionAndWidth(state.mainGrid); if (!maxZres.ok()) { return maxZres.error(); diff --git a/Core/include/Acts/Vertexing/IVertexFinder.hpp b/Core/include/Acts/Vertexing/IVertexFinder.hpp index a5ac538d311..ba755d53e0a 100644 --- a/Core/include/Acts/Vertexing/IVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IVertexFinder.hpp @@ -33,7 +33,7 @@ class IVertexFinder { virtual State makeState(const MagneticFieldContext& mctx) const = 0; virtual void setTracksToRemove( - State& state, const std::vector& removedTracks) const = 0; + State& anyState, const std::vector& removedTracks) const = 0; virtual ~IVertexFinder() = default; }; diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index 5270c99505b..4be75091f82 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -175,12 +175,13 @@ class IterativeVertexFinder final : public IVertexFinder { /// /// @param trackVector Input tracks /// @param vertexingOptions Vertexing options - /// @param state State for fulfilling interfaces + /// @param anyState State for fulfilling interfaces /// /// @return Collection of vertices found by finder - Result> find(const std::vector& trackVector, - const VertexingOptions& vertexingOptions, - IVertexFinder::State& state) const override; + Result> find( + const std::vector& trackVector, + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const override; IVertexFinder::State makeState( const MagneticFieldContext& mctx) const override { @@ -188,7 +189,7 @@ class IterativeVertexFinder final : public IVertexFinder { } void setTracksToRemove( - IVertexFinder::State& /*state*/, + IVertexFinder::State& /*anyState*/, const std::vector& /*removedTracks*/) const override { // Nothing to do here } diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp index 10d352e350f..be7ec15d3ce 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp @@ -9,9 +9,9 @@ template auto Acts::IterativeVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, IVertexFinder::State& state) const - -> Result> { - auto& thisState = state.as(); + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const -> Result> { + auto& state = anyState.as(); // Original tracks const std::vector& origTracks = trackVector; // Tracks for seeding @@ -24,7 +24,7 @@ auto Acts::IterativeVertexFinder::find( // begin iterating while (seedTracks.size() > 1 && nInterations < m_cfg.maxVertices) { /// Do seeding - auto seedRes = getVertexSeed(thisState, seedTracks, vertexingOptions); + auto seedRes = getVertexSeed(state, seedTracks, vertexingOptions); if (!seedRes.ok()) { return seedRes.error(); @@ -45,9 +45,8 @@ auto Acts::IterativeVertexFinder::find( std::vector tracksToFitSplitVertex; // Fill vector with tracks to fit, only compatible with seed: - auto res = - fillTracksToFit(seedTracks, seedVertex, tracksToFit, - tracksToFitSplitVertex, vertexingOptions, thisState); + auto res = fillTracksToFit(seedTracks, seedVertex, tracksToFit, + tracksToFitSplitVertex, vertexingOptions, state); if (!res.ok()) { return res.error(); @@ -61,7 +60,7 @@ auto Acts::IterativeVertexFinder::find( if (vertexingOptions.useConstraintInFit && !tracksToFit.empty()) { auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - thisState.fieldCache); + state.fieldCache); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { @@ -69,7 +68,7 @@ auto Acts::IterativeVertexFinder::find( } } else if (!vertexingOptions.useConstraintInFit && tracksToFit.size() > 1) { auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - thisState.fieldCache); + state.fieldCache); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { @@ -78,7 +77,7 @@ auto Acts::IterativeVertexFinder::find( } if (m_cfg.createSplitVertices && tracksToFitSplitVertex.size() > 1) { auto fitResult = m_cfg.vertexFitter.fit( - tracksToFitSplitVertex, vertexingOptions, thisState.fieldCache); + tracksToFitSplitVertex, vertexingOptions, state.fieldCache); if (fitResult.ok()) { currentSplitVertex = std::move(*fitResult); } else { @@ -111,7 +110,7 @@ auto Acts::IterativeVertexFinder::find( auto result = reassignTracksToNewVertex( vertexCollection, currentVertex, tracksToFit, seedTracks, - origTracks, vertexingOptions, thisState); + origTracks, vertexingOptions, state); if (!result.ok()) { return result.error(); } @@ -121,7 +120,7 @@ auto Acts::IterativeVertexFinder::find( // still good vertex? might have changed in the meanwhile if (isGoodVertex) { removeUsedCompatibleTracks(currentVertex, tracksToFit, seedTracks, - vertexingOptions, thisState); + vertexingOptions, state); ACTS_DEBUG( "Number of seed tracks after removal of compatible tracks " @@ -139,7 +138,7 @@ auto Acts::IterativeVertexFinder::find( removeTracks(tracksToFitSplitVertex, seedTracks); } else { removeUsedCompatibleTracks(currentSplitVertex, tracksToFitSplitVertex, - seedTracks, vertexingOptions, thisState); + seedTracks, vertexingOptions, state); } } // Now fill vertex collection with vertex From ed6f6c94851843ac092db54a3a61e15a187bf3b1 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Fri, 16 Feb 2024 16:36:09 +0100 Subject: [PATCH 11/14] Add doxygen comments for IVertexFinder --- Core/include/Acts/Vertexing/IVertexFinder.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Core/include/Acts/Vertexing/IVertexFinder.hpp b/Core/include/Acts/Vertexing/IVertexFinder.hpp index ba755d53e0a..56c79d8f036 100644 --- a/Core/include/Acts/Vertexing/IVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IVertexFinder.hpp @@ -22,19 +22,34 @@ class Vertex; struct InputTrack; struct VertexingOptions; +/// Common interface for both vertex finders and vertex seed finders class IVertexFinder { public: + /// Type-erased wrapper for concrete state objects using State = Acts::AnyBase<128>; + /// The main finder method that will return a set of found vertex candidates + /// @param trackVector The input track collection + /// @param vertexingOptions The vertexing options + /// @param state The state object (needs to be created via @c makeState) + /// @return The found vertex candidates virtual Result> find( const std::vector& trackVector, const VertexingOptions& vertexingOptions, State& state) const = 0; + /// Function to create a state object for this concrete vertex finder + /// @param mctx The magnetic field context + /// @return The state object virtual State makeState(const MagneticFieldContext& mctx) const = 0; + /// For vertex finders that have an internal state of active tracks, this + /// method instructs them to mark used tracks for removal + /// @param anyState The state object + /// @param removedTracks The tracks to be removed virtual void setTracksToRemove( State& anyState, const std::vector& removedTracks) const = 0; + /// Virtual destructor virtual ~IVertexFinder() = default; }; } // namespace Acts From dff71c5aa15e21dfff33f450ef54c51734ab23ad Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Fri, 16 Feb 2024 16:48:01 +0100 Subject: [PATCH 12/14] fix shadowing --- Core/include/Acts/Vertexing/IterativeVertexFinder.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index 4be75091f82..97ac15f2ce6 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -124,8 +124,8 @@ class IterativeVertexFinder final : public IVertexFinder { /// State struct struct State { State(const MagneticFieldProvider& field, - const Acts::MagneticFieldContext& magContext) - : magContext(magContext), + const Acts::MagneticFieldContext& _magContext) + : magContext(_magContext), ipState(field.makeCache(magContext)), fieldCache(field.makeCache(magContext)) {} From 4c4853e3491928c08ef85f63b1d5ddbaacea033d Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Mon, 19 Feb 2024 09:23:45 +0100 Subject: [PATCH 13/14] Add b field to IVF in examples algo --- .../Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp b/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp index cf91bb61bbc..5a6faea1494 100644 --- a/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp +++ b/Examples/Algorithms/Vertexing/src/IterativeVertexFinderAlgorithm.cpp @@ -103,6 +103,7 @@ ActsExamples::ProcessCode ActsExamples::IterativeVertexFinderAlgorithm::execute( finderCfg.maxVertices = 200; finderCfg.reassignTracksAfterFirstFit = false; finderCfg.extractParameters.connect<&Acts::InputTrack::extractParameters>(); + finderCfg.field = m_cfg.bField; Finder finder(std::move(finderCfg), logger().clone()); Acts::IVertexFinder::State state{std::in_place_type, *m_cfg.bField, ctx.magFieldContext}; From ed9b41e50eda28eb9ae28d0cfe387bd62937d144 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Mon, 19 Feb 2024 10:40:55 +0100 Subject: [PATCH 14/14] remove dead code --- Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp index 20441f74266..70d21440218 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp @@ -22,10 +22,6 @@ namespace Acts { -// namespace detail { -// template -// } - /// @class GridDensityVertexFinder /// @brief Vertex finder that makes use of a track density grid. /// Each single track is modelled as a 2(!)-dim Gaussian distribution grid