Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Add IVertexFinder interface, use in vertexing #2948

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 <typename vfitter_t = DummyVertexFitter<>>
class AdaptiveGridDensityVertexFinder {
class AdaptiveGridDensityVertexFinder final : public IVertexFinder {
using GridDensity = AdaptiveGridTrackDensity;

public:
Expand Down Expand Up @@ -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<std::vector<Vertex>> find(const std::vector<InputTrack>& trackVector,
const VertexingOptions& vertexingOptions,
State& state) const;
Result<std::vector<Vertex>> find(
const std::vector<InputTrack>& 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<InputTrack>& removedTracks) const override {
auto& state = anyState.template as<State>();
state.tracksToRemove = removedTracks;
}

/// @brief Constructor for user-defined InputTrack type
///
Expand Down
11 changes: 5 additions & 6 deletions Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename vfitter_t>
auto Acts::AdaptiveGridDensityVertexFinder<vfitter_t>::find(
inline auto Acts::AdaptiveGridDensityVertexFinder::find(
const std::vector<InputTrack>& trackVector,
const VertexingOptions& vertexingOptions, State& state) const
-> Result<std::vector<Vertex>> {
const VertexingOptions& vertexingOptions,
IVertexFinder::State& anyState) const -> Result<std::vector<Vertex>> {
auto& state = anyState.as<State>();
// Remove density contributions from tracks removed from track collection
if (m_cfg.cacheGridStateForTrackRemoval && state.isInitialized &&
!state.tracksToRemove.empty()) {
Expand Down Expand Up @@ -95,8 +95,7 @@ auto Acts::AdaptiveGridDensityVertexFinder<vfitter_t>::find(
return seedVec;
}

template <typename vfitter_t>
auto Acts::AdaptiveGridDensityVertexFinder<vfitter_t>::doesPassTrackSelection(
inline auto Acts::AdaptiveGridDensityVertexFinder::doesPassTrackSelection(
const BoundTrackParameters& trk) const -> bool {
// Get required track parameters
const double d0 = trk.parameters()[BoundIndices::eBoundLoc0];
Expand Down
58 changes: 35 additions & 23 deletions Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <functional>
#include <type_traits>

namespace Acts {
Expand All @@ -32,19 +35,9 @@ namespace Acts {
///
/// @tparam vfitter_t Vertex fitter type
/// @tparam sfinder_t Seed finder type
template <typename vfitter_t, typename sfinder_t>
class AdaptiveMultiVertexFinder {
template <typename vfitter_t>
class AdaptiveMultiVertexFinder final : public IVertexFinder {
using FitterState_t = typename vfitter_t::State;
using SeedFinderState_t = typename sfinder_t::State;

template <typename T, typename = int>
struct NeedsRemovedTracks : std::false_type {};

#ifndef DOXYGEN
template <typename T>
struct NeedsRemovedTracks<T, decltype((void)T::tracksToRemove, 0)>
: std::true_type {};
#endif

public:
/// Configuration struct
Expand All @@ -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<const IVertexFinder> sfinder,
ImpactPointEstimator ipEst,
std::shared_ptr<const MagneticFieldProvider> bIn)
: vertexFitter(std::move(fitter)),
seedFinder(std::move(sfinder)),
Expand All @@ -66,7 +60,7 @@ class AdaptiveMultiVertexFinder {
vfitter_t vertexFitter;

// Vertex seed finder
sfinder_t seedFinder;
std::shared_ptr<const IVertexFinder> seedFinder;

// ImpactPointEstimator
ImpactPointEstimator ipEstimator;
Expand Down Expand Up @@ -161,7 +155,9 @@ class AdaptiveMultiVertexFinder {
}; // Config struct

/// State struct for fulfilling interface
struct State {};
struct State {
std::reference_wrapper<const MagneticFieldContext> magContext;
};

/// @brief Constructor for user-defined InputTrack_t type !=
/// BoundTrackParameters
Expand All @@ -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;
Expand All @@ -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<std::vector<Vertex>> find(const std::vector<InputTrack>& allTracks,
const VertexingOptions& vertexingOptions,
State& state) const;
Result<std::vector<Vertex>> find(
const std::vector<InputTrack>& 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<InputTrack>& /*removedTracks*/) const override {
// Nothing to do here
}

private:
/// Configuration object
Expand All @@ -203,9 +217,7 @@ class AdaptiveMultiVertexFinder {
std::unique_ptr<const Logger> 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
Expand All @@ -221,7 +233,7 @@ class AdaptiveMultiVertexFinder {
Result<Vertex> doSeeding(
const std::vector<InputTrack>& trackVector, Vertex& currentConstraint,
const VertexingOptions& vertexingOptions,
SeedFinderState_t& seedFinderState,
IVertexFinder::State& seedFinderState,
const std::vector<InputTrack>& removedSeedTracks) const;

/// @brief Sets constraint vertex after seeding
Expand Down
Loading
Loading