diff --git a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp index 5e8ca0bd7d9..db9933cf87a 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp @@ -9,9 +9,11 @@ #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" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/Vertex.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" @@ -28,10 +30,7 @@ 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 { +class AdaptiveGridDensityVertexFinder final : public IVertexFinder { using GridDensity = AdaptiveGridTrackDensity; public: @@ -87,15 +86,28 @@ class AdaptiveGridDensityVertexFinder { /// /// @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, - State& state) const; + Result> find( + const std::vector& trackVector, + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const override; + + IVertexFinder::State makeState( + const Acts::MagneticFieldContext& /*mctx*/) const override { + return IVertexFinder::State{State{}}; + } + + void setTracksToRemove( + IVertexFinder::State& anyState, + const std::vector& removedTracks) const override { + 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 9ae2ac50f67..14242ae8f22 100644 --- a/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp @@ -6,11 +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/. -template -auto Acts::AdaptiveGridDensityVertexFinder::find( +inline auto Acts::AdaptiveGridDensityVertexFinder::find( const std::vector& trackVector, - const VertexingOptions& vertexingOptions, State& state) const - -> Result> { + 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 && state.isInitialized && !state.tracksToRemove.empty()) { @@ -95,8 +95,7 @@ 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 c76d829fa6c..da84374a69b 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp @@ -11,13 +11,16 @@ #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" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/ImpactPointEstimator.hpp" #include "Acts/Vertexing/TrackLinearizer.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" +#include #include namespace Acts { @@ -32,19 +35,9 @@ namespace Acts { /// /// @tparam vfitter_t Vertex fitter type /// @tparam sfinder_t Seed finder type -template -class AdaptiveMultiVertexFinder { +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 @@ -55,7 +48,8 @@ class AdaptiveMultiVertexFinder { /// @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)), @@ -66,7 +60,7 @@ class AdaptiveMultiVertexFinder { vfitter_t vertexFitter; // Vertex seed finder - sfinder_t seedFinder; + std::shared_ptr seedFinder; // ImpactPointEstimator ImpactPointEstimator ipEstimator; @@ -161,7 +155,9 @@ class AdaptiveMultiVertexFinder { }; // Config struct /// State struct for fulfilling interface - struct State {}; + struct State { + std::reference_wrapper magContext; + }; /// @brief Constructor for user-defined InputTrack_t type != /// BoundTrackParameters @@ -179,6 +175,12 @@ class AdaptiveMultiVertexFinder { "No function to extract parameters " "from InputTrack provided."); } + + if (!m_cfg.seedFinder) { + throw std::invalid_argument( + "AdaptiveMultiVertexFinder: " + "No vertex fitter provided."); + } } AdaptiveMultiVertexFinder(AdaptiveMultiVertexFinder&&) = default; @@ -188,12 +190,24 @@ class AdaptiveMultiVertexFinder { /// /// @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, - State& state) const; + Result> find( + const std::vector& allTracks, + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const override; + + IVertexFinder::State makeState( + const Acts::MagneticFieldContext& mctx) const override { + return IVertexFinder::State{State{mctx}}; + } + + void setTracksToRemove( + IVertexFinder::State& /*state*/, + const std::vector& /*removedTracks*/) const override { + // Nothing to do here + } private: /// Configuration object @@ -203,9 +217,7 @@ class AdaptiveMultiVertexFinder { 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 @@ -221,7 +233,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..5123b2f06b2 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp @@ -9,15 +9,18 @@ #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, State& /*state*/) const - -> Result> { + const VertexingOptions& vertexingOptions, + 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; @@ -25,7 +28,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(state.magContext); std::vector> allVertices; @@ -137,22 +140,20 @@ 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, - 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->setTracksToRemove(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(); @@ -166,11 +167,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 @@ -187,8 +187,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 @@ -227,11 +227,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); @@ -258,8 +257,8 @@ auto Acts::AdaptiveMultiVertexFinder:: return {}; } -template -auto Acts::AdaptiveMultiVertexFinder:: +template +auto Acts::AdaptiveMultiVertexFinder:: canRecoverFromNoCompatibleTracks( const std::vector& allTracks, const std::vector& seedTracks, Vertex& vtx, @@ -314,14 +313,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()); @@ -344,12 +341,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; @@ -385,8 +380,8 @@ auto Acts::AdaptiveMultiVertexFinder:: return {nCompatibleTracks, isGoodVertex}; } -template -auto Acts::AdaptiveMultiVertexFinder:: +template +auto Acts::AdaptiveMultiVertexFinder:: removeCompatibleTracksFromSeedTracks( Vertex& vtx, std::vector& seedTracks, FitterState_t& fitterState, @@ -411,12 +406,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; @@ -468,8 +462,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.; @@ -496,8 +490,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(); @@ -550,8 +544,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 { @@ -590,8 +584,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/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 6a9b84be263..70d21440218 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.hpp @@ -10,9 +10,11 @@ #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" +#include "Acts/Vertexing/IVertexFinder.hpp" #include "Acts/Vertexing/Vertex.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" @@ -31,9 +33,8 @@ 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 > -class GridDensityVertexFinder { +template +class GridDensityVertexFinder final : public IVertexFinder { // Assert odd trkGridSize static_assert(trkGridSize % 2); // Assert bigger main grid than track grid @@ -101,15 +102,28 @@ class GridDensityVertexFinder { /// /// @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, - State& state) const; + Result> find( + const std::vector& trackVector, + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const override; + + IVertexFinder::State makeState( + const Acts::MagneticFieldContext& /*mctx*/) const override { + return IVertexFinder::State{State{}}; + } + + void setTracksToRemove( + IVertexFinder::State& anyState, + const std::vector& removedTracks) const override { + 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 90a0427219d..9c3585f5ba6 100644 --- a/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/GridDensityVertexFinder.ipp @@ -6,11 +6,12 @@ // 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, State& state) const - -> Result> { + 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 && state.isInitialized && !state.tracksToRemove.empty()) { @@ -98,8 +99,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/IVertexFinder.hpp b/Core/include/Acts/Vertexing/IVertexFinder.hpp new file mode 100644 index 00000000000..56c79d8f036 --- /dev/null +++ b/Core/include/Acts/Vertexing/IVertexFinder.hpp @@ -0,0 +1,55 @@ +// This file is part 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 +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#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" + +#include + +namespace Acts { + +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 diff --git a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp index 1d4a573fc8e..97ac15f2ce6 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.hpp @@ -10,19 +10,22 @@ #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" #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" -#include "Acts/Vertexing/VertexFitterConcept.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" #include "Acts/Vertexing/ZScanVertexFinder.hpp" +#include + namespace Acts { /// @class IterativeVertexFinder @@ -57,12 +60,8 @@ namespace Acts { //////////////////////////////////////////////////////////// /// /// @tparam vfitter_t Vertex fitter type -/// @tparam sfinder_t Seed finder type -template -class IterativeVertexFinder { - static_assert(VertexFitterConcept, - "Vertex fitter does not fulfill vertex fitter concept."); - +template +class IterativeVertexFinder final : public IVertexFinder { public: /// Configuration struct struct Config { @@ -72,7 +71,8 @@ class IterativeVertexFinder { /// @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)) {} @@ -84,7 +84,7 @@ class IterativeVertexFinder { TrackLinearizer trackLinearizer; /// Vertex seed finder - sfinder_t seedFinder; + std::shared_ptr seedFinder; /// ImpactPointEstimator ImpactPointEstimator ipEst; @@ -114,21 +114,25 @@ class IterativeVertexFinder { /// 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)), + const Acts::MagneticFieldContext& _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; }; @@ -153,18 +157,42 @@ class IterativeVertexFinder { "IterativeVertexFinder: " "No track linearizer provided."); } + + if (!m_cfg.seedFinder) { + throw std::invalid_argument( + "IterativeVertexFinder: " + "No seed finder provided."); + } + + if (!m_cfg.field) { + throw std::invalid_argument( + "IterativeVertexFinder: " + "No magnetic field provider provided."); + } } /// @brief Finds vertices corresponding to input trackVector /// /// @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, - State& state) const; + Result> find( + const std::vector& trackVector, + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const override; + + IVertexFinder::State makeState( + const MagneticFieldContext& mctx) const override { + return IVertexFinder::State{State{*m_cfg.field, mctx}}; + } + + void setTracksToRemove( + IVertexFinder::State& /*anyState*/, + const std::vector& /*removedTracks*/) const override { + // Nothing to do here + } private: /// Configuration object @@ -180,7 +208,8 @@ class IterativeVertexFinder { /// /// @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 2bac588af23..be7ec15d3ce 100644 --- a/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/IterativeVertexFinder.ipp @@ -6,11 +6,12 @@ // 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, State& state) const - -> Result> { + const VertexingOptions& vertexingOptions, + IVertexFinder::State& anyState) const -> Result> { + auto& state = anyState.as(); // Original tracks const std::vector& origTracks = trackVector; // Tracks for seeding @@ -23,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(state, seedTracks, vertexingOptions); if (!seedRes.ok()) { return seedRes.error(); @@ -59,7 +60,7 @@ auto Acts::IterativeVertexFinder::find( if (vertexingOptions.useConstraintInFit && !tracksToFit.empty()) { auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - state.fitterState); + state.fieldCache); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { @@ -67,7 +68,7 @@ auto Acts::IterativeVertexFinder::find( } } else if (!vertexingOptions.useConstraintInFit && tracksToFit.size() > 1) { auto fitResult = m_cfg.vertexFitter.fit(tracksToFit, vertexingOptions, - state.fitterState); + state.fieldCache); if (fitResult.ok()) { currentVertex = std::move(*fitResult); } else { @@ -76,7 +77,7 @@ auto Acts::IterativeVertexFinder::find( } if (m_cfg.createSplitVertices && tracksToFitSplitVertex.size() > 1) { auto fitResult = m_cfg.vertexFitter.fit( - tracksToFitSplitVertex, vertexingOptions, state.fitterState); + tracksToFitSplitVertex, vertexingOptions, state.fieldCache); if (fitResult.ok()) { currentSplitVertex = std::move(*fitResult); } else { @@ -154,12 +155,12 @@ auto Acts::IterativeVertexFinder::find( return vertexCollection; } -template -auto Acts::IterativeVertexFinder::getVertexSeed( - const std::vector& seedTracks, +template +auto Acts::IterativeVertexFinder::getVertexSeed( + State& state, const std::vector& seedTracks, const VertexingOptions& vertexingOptions) const -> Result { - typename sfinder_t::State finderState; - auto res = m_cfg.seedFinder.find(seedTracks, vertexingOptions, finderState); + auto finderState = m_cfg.seedFinder->makeState(state.magContext); + auto res = m_cfg.seedFinder->find(seedTracks, vertexingOptions, finderState); if (!res.ok()) { ACTS_ERROR("Internal seeding error. Number of input tracks: " @@ -188,8 +189,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) { @@ -209,9 +210,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 { @@ -246,9 +246,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 { @@ -339,9 +339,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, @@ -413,9 +412,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 */, @@ -509,16 +508,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 { @@ -547,8 +546,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 09f4a076742..d81db1535d6 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.hpp @@ -10,10 +10,11 @@ #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" #include "Acts/Vertexing/Vertex.hpp" -#include "Acts/Vertexing/VertexFitterConcept.hpp" #include "Acts/Vertexing/VertexingOptions.hpp" namespace Acts { @@ -29,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 -class TrackDensityVertexFinder { - // 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."); - +template +class TrackDensityVertexFinder final : public IVertexFinder { public: /// @brief The Config struct struct Config { @@ -59,7 +53,18 @@ 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 Acts::MagneticFieldContext& /*mctx*/) const override { + return IVertexFinder::State{State{}}; + } + + void setTracksToRemove( + IVertexFinder::State& /*state*/, + const std::vector& /*removedTracks*/) const override { + // Nothing to do here + } /// @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..1d1014014ef 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp @@ -6,11 +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/. -template -auto Acts::TrackDensityVertexFinder::find( +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/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 958a00ee58b..71417f42483 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.hpp @@ -14,9 +14,9 @@ #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" #include "Acts/Vertexing/VertexingOptions.hpp" #include @@ -30,11 +30,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 { - static_assert(VertexFitterConcept, - "Vertex fitter does not fulfill vertex fitter concept."); - +class ZScanVertexFinder final : public IVertexFinder { public: /// Configuration struct struct Config { @@ -99,7 +95,18 @@ 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 Acts::MagneticFieldContext& /*mctx*/) const override { + return IVertexFinder::State{State{}}; + } + + void setTracksToRemove( + IVertexFinder::State& /*state*/, + const std::vector& /*removedTracks*/) const override { + // Nothing to do here + } private: Config m_cfg; diff --git a/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp b/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp index e9d6c96849d..76ea5e4c0ca 100644 --- a/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/ZScanVertexFinder.ipp @@ -6,11 +6,10 @@ // 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, 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/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 e98f5167283..fbc420c27e1 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 - typename Finder::State state; + 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); @@ -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 43195131601..5a6faea1494 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); @@ -103,8 +103,10 @@ 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()); - 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/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 74d12ee2033..e0fefc7b364 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" @@ -111,20 +112,21 @@ 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); finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - Finder::State state; + IVertexFinder::State state = finder.makeState(magFieldContext); auto csvData = readTracksAndVertexCSV(toolString); std::vector tracks = std::get(csvData); @@ -272,20 +274,21 @@ 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); finderConfig.extractParameters.connect(extractParameters); - Finder::State state; Finder finder(std::move(finderConfig)); + IVertexFinder::State state = finder.makeState(magFieldContext); auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); @@ -423,16 +426,16 @@ 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); finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - Finder::State state; + IVertexFinder::State state = finder.makeState(magFieldContext); auto csvData = readTracksAndVertexCSV(toolString); auto tracks = std::get(csvData); @@ -577,21 +580,21 @@ 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); finderConfig.extractParameters.connect<&InputTrack::extractParameters>(); Finder finder(std::move(finderConfig)); - Finder::State state; + 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 e7c9d065572..ae3d958a2bf 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(magFieldContext); // Use custom grid density here with same bin size as Finder1 AdaptiveGridTrackDensity::Config adaptiveDensityConfig; @@ -109,12 +110,12 @@ 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>(); Finder2 finder2(cfg2); - Finder2::State state2; + IVertexFinder::State state2 = finder2.makeState(magFieldContext); int mySeed = 31415; std::mt19937 gen(mySeed); @@ -229,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>(); @@ -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(magFieldContext); + IVertexFinder::State state2 = finder2.makeState(magFieldContext); 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(magFieldContext); // Use custom grid density here with same bin size as Finder1 AdaptiveGridTrackDensity::Config adaptiveDensityConfig; @@ -395,13 +396,13 @@ 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; cfg2.extractParameters.connect<&InputTrack::extractParameters>(); Finder2 finder2(cfg2); - Finder2::State state2; + 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 12866d05435..eed6c0fbfe9 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" @@ -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); @@ -153,31 +153,26 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test) { ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); - using ZScanSeedFinder = ZScanVertexFinder; - - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); + 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; - - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); + using VertexFinder = IterativeVertexFinder; VertexFinder::Config cfg(std::move(bFitter), std::move(sFinder), ipEstimator); + cfg.field = bField; cfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); cfg.reassignTracksAfterFirstFit = true; 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; @@ -345,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); @@ -381,22 +376,22 @@ 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; cfg.extractParameters.connect(extractParameters); cfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer); - + cfg.field = bField; 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; @@ -583,21 +578,15 @@ BOOST_AUTO_TEST_CASE(iterative_finder_test_athena_reference) { ImpactPointEstimator::Config ipEstimatorCfg(bField, propagator); ImpactPointEstimator ipEstimator(ipEstimatorCfg); - using ZScanSeedFinder = ZScanVertexFinder; - - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); + 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; - - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); + using VertexFinder = IterativeVertexFinder; VertexFinder::Config cfg(std::move(bFitter), std::move(sFinder), ipEstimator); cfg.maxVertices = 200; @@ -605,9 +594,10 @@ 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)); - 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..f144b7f95cc 100644 --- a/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/TrackDensityVertexFinderTests.cpp @@ -70,12 +70,11 @@ 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}}}; - Finder::State state; + auto state = finder.makeState(magFieldContext); // Start creating some track parameters Covariance covMat = Covariance::Identity(); @@ -151,12 +150,11 @@ 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}}}; - Finder::State state; + auto state = finder.makeState(magFieldContext); // Start creating some track parameters Covariance covMat = Covariance::Identity(); @@ -229,12 +227,11 @@ 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}}}; - Finder::State state; + auto state = finder.makeState(magFieldContext); int mySeed = 31415; std::mt19937 gen(mySeed); @@ -331,13 +328,12 @@ 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); Finder finder{{{densityCfg}}}; - Finder::State state; + 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 a91ab9570d2..3ae2042bfb2 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" @@ -162,10 +161,7 @@ BOOST_AUTO_TEST_CASE(zscan_finder_test) { inputTracks.emplace_back(&trk); } - using VertexFinder = ZScanVertexFinder; - - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); + using VertexFinder = ZScanVertexFinder; 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(magFieldContext); auto res = finder.find(inputTracks, vertexingOptions, state); BOOST_CHECK(res.ok()); @@ -283,10 +279,7 @@ BOOST_AUTO_TEST_CASE(zscan_finder_usertrack_test) { inputTracks.emplace_back(&trk); } - using VertexFinder = ZScanVertexFinder; - - static_assert(VertexFinderConcept, - "Vertex finder does not fulfill vertex finder concept."); + using VertexFinder = ZScanVertexFinder; 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(magFieldContext); VertexingOptions vertexingOptions(geoContext, magFieldContext);