Skip to content

Commit

Permalink
refactor!: Hard-code vertex fitter, finder + density combinations (#2952
Browse files Browse the repository at this point in the history
)

They're not actually exchangeable, there's a 1:1 correspondence that they can be used in. Therefore, we don't need to template the finders on the only respective valid density.

- `AdaptiveGridDensityVertexFinder` => `AdaptiveGridTrackDensity`
- `AdaptiveMultiVertexFinder` => `AdaptiveMultiVertexFitter`
- `TrackDensityVertexFinder` => `GaussianTrackDensity`
- `IterativeVertexFinder` => `FullBilloirVertexFitter`

The main reason for this is that the vertex fitters and the track densities do not actually have common interfaces. This is probably desirable, but out of scope for this refactor, and should probably be implemented with an interface like `IVertexFinder`.

Part of:
- #2842 

Blocked by:
- #2951
  • Loading branch information
paulgessinger authored Feb 20, 2024
1 parent fc75469 commit 8ccefe1
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ namespace Acts {
/// Unlike the GridDensityVertexFinder, this seeder implements an adaptive
/// version where the density grid grows bigger with added tracks.
class AdaptiveGridDensityVertexFinder final : public IVertexFinder {
using GridDensity = AdaptiveGridTrackDensity;

public:
using DensityMap = typename GridDensity::DensityMap;
using DensityMap = AdaptiveGridTrackDensity::DensityMap;

/// @brief The Config struct
struct Config {
///@param gDensity The grid density
Config(const GridDensity& gDensity) : gridDensity(gDensity) {}
Config(const AdaptiveGridTrackDensity& gDensity) : gridDensity(gDensity) {}

// The grid density object
GridDensity gridDensity;
AdaptiveGridTrackDensity gridDensity;

// Cache the main grid and the density contributions (trackGrid and z-bin)
// for every single track.
Expand Down
37 changes: 14 additions & 23 deletions Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/Result.hpp"
#include "Acts/Vertexing/AMVFInfo.hpp"
#include "Acts/Vertexing/AdaptiveMultiVertexFitter.hpp"
#include "Acts/Vertexing/IVertexFinder.hpp"
#include "Acts/Vertexing/ImpactPointEstimator.hpp"
#include "Acts/Vertexing/TrackLinearizer.hpp"
Expand All @@ -25,19 +26,9 @@

namespace Acts {
/// @brief Implements an iterative vertex finder
///
////////////////////////////////////////////////////////////
///
/// Brief description of the algorithm implemented:
/// TODO
///
////////////////////////////////////////////////////////////
///
/// @tparam vfitter_t Vertex fitter type
/// @tparam sfinder_t Seed finder type
template <typename vfitter_t>
class AdaptiveMultiVertexFinder final : public IVertexFinder {
using FitterState_t = typename vfitter_t::State;
using VertexFitter = AdaptiveMultiVertexFitter;
using VertexFitterState = VertexFitter::State;

public:
/// Configuration struct
Expand All @@ -48,7 +39,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
/// @param sfinder The seed finder
/// @param ipEst ImpactPointEstimator
/// @param bIn Input magnetic field
Config(vfitter_t fitter, std::shared_ptr<const IVertexFinder> sfinder,
Config(VertexFitter fitter, std::shared_ptr<const IVertexFinder> sfinder,
ImpactPointEstimator ipEst,
std::shared_ptr<const MagneticFieldProvider> bIn)
: vertexFitter(std::move(fitter)),
Expand All @@ -57,7 +48,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
bField{std::move(bIn)} {}

// Vertex fitter
vfitter_t vertexFitter;
VertexFitter vertexFitter;

// Vertex seed finder
std::shared_ptr<const IVertexFinder> seedFinder;
Expand Down Expand Up @@ -264,7 +255,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
/// @param vertexingOptions Vertexing options
Result<void> addCompatibleTracksToVertex(
const std::vector<InputTrack>& tracks, Vertex& vtx,
FitterState_t& fitterState,
VertexFitterState& fitterState,
const VertexingOptions& vertexingOptions) const;

/// @brief Method that tries to recover from cases where no tracks
Expand All @@ -282,7 +273,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
Result<bool> canRecoverFromNoCompatibleTracks(
const std::vector<InputTrack>& allTracks,
const std::vector<InputTrack>& seedTracks, Vertex& vtx,
const Vertex& currentConstraint, FitterState_t& fitterState,
const Vertex& currentConstraint, VertexFitterState& fitterState,
const VertexingOptions& vertexingOptions) const;

/// @brief Method that tries to prepare the vertex for the fit
Expand All @@ -299,7 +290,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
Result<bool> canPrepareVertexForFit(
const std::vector<InputTrack>& allTracks,
const std::vector<InputTrack>& seedTracks, Vertex& vtx,
const Vertex& currentConstraint, FitterState_t& fitterState,
const Vertex& currentConstraint, VertexFitterState& fitterState,
const VertexingOptions& vertexingOptions) const;

/// @brief Method that checks if vertex is a good vertex and if
Expand All @@ -313,7 +304,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
/// @return pair(nCompatibleTracks, isGoodVertex)
std::pair<int, bool> checkVertexAndCompatibleTracks(
Vertex& vtx, const std::vector<InputTrack>& seedTracks,
FitterState_t& fitterState, bool useVertexConstraintInFit) const;
VertexFitterState& fitterState, bool useVertexConstraintInFit) const;

/// @brief Method that removes all tracks that are compatible with
/// current vertex from seedTracks
Expand All @@ -325,7 +316,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
/// removed
void removeCompatibleTracksFromSeedTracks(
Vertex& vtx, std::vector<InputTrack>& seedTracks,
FitterState_t& fitterState,
VertexFitterState& fitterState,
std::vector<InputTrack>& removedSeedTracks) const;

/// @brief Method that tries to remove an incompatible track
Expand All @@ -341,7 +332,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
/// @return Incompatible track was removed
bool removeTrackIfIncompatible(Vertex& vtx,
std::vector<InputTrack>& seedTracks,
FitterState_t& fitterState,
VertexFitterState& fitterState,
std::vector<InputTrack>& removedSeedTracks,
const GeometryContext& geoCtx) const;

Expand All @@ -354,7 +345,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
///
/// @return Keep new vertex
bool keepNewVertex(Vertex& vtx, const std::vector<Vertex*>& allVertices,
FitterState_t& fitterState) const;
VertexFitterState& fitterState) const;

/// @brief Method that evaluates if the new vertex candidate is
/// merged with one of the previously found vertices
Expand All @@ -376,7 +367,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
/// @param vertexingOptions Vertexing options
Result<void> deleteLastVertex(
Vertex& vtx, std::vector<std::unique_ptr<Vertex>>& allVertices,
std::vector<Vertex*>& allVerticesPtr, FitterState_t& fitterState,
std::vector<Vertex*>& allVerticesPtr, VertexFitterState& fitterState,
const VertexingOptions& vertexingOptions) const;

/// @brief Prepares the output vector of vertices
Expand All @@ -387,7 +378,7 @@ class AdaptiveMultiVertexFinder final : public IVertexFinder {
/// @return The output vertex collection
Result<std::vector<Vertex>> getVertexOutputList(
const std::vector<Vertex*>& allVerticesPtr,
FitterState_t& fitterState) const;
VertexFitterState& fitterState) const;
};

} // namespace Acts
Expand Down
78 changes: 32 additions & 46 deletions Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include "Acts/Utilities/AlgebraHelpers.hpp"
#include "Acts/Vertexing/VertexingError.hpp"

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::find(
inline auto Acts::AdaptiveMultiVertexFinder::find(
const std::vector<InputTrack>& allTracks,
const VertexingOptions& vertexingOptions,
IVertexFinder::State& anyState) const -> Result<std::vector<Vertex>> {
Expand All @@ -27,7 +26,8 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::find(
// Seed tracks
std::vector<InputTrack> seedTracks = allTracks;

FitterState_t fitterState(*m_cfg.bField, vertexingOptions.magFieldContext);
VertexFitterState fitterState(*m_cfg.bField,
vertexingOptions.magFieldContext);
auto seedFinderState = m_cfg.seedFinder->makeState(state.magContext);

std::vector<std::unique_ptr<Vertex>> allVertices;
Expand Down Expand Up @@ -140,8 +140,7 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::find(
return getVertexOutputList(allVerticesPtr, fitterState);
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::doSeeding(
inline auto Acts::AdaptiveMultiVertexFinder::doSeeding(
const std::vector<InputTrack>& trackVector, Vertex& currentConstraint,
const VertexingOptions& vertexingOptions,
IVertexFinder::State& seedFinderState,
Expand All @@ -167,8 +166,7 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::doSeeding(
return seedVertex;
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::setConstraintAfterSeeding(
inline auto Acts::AdaptiveMultiVertexFinder::setConstraintAfterSeeding(
Vertex& currentConstraint, bool useVertexConstraintInFit,
Vertex& seedVertex) const -> void {
if (useVertexConstraintInFit) {
Expand All @@ -187,8 +185,7 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::setConstraintAfterSeeding(
}
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::getIPSignificance(
inline auto Acts::AdaptiveMultiVertexFinder::getIPSignificance(
const InputTrack& track, const Vertex& vtx,
const VertexingOptions& vertexingOptions) const -> Result<double> {
// TODO: In original implementation the covariance of the given vertex is set
Expand Down Expand Up @@ -227,11 +224,10 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::getIPSignificance(
return significance;
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::addCompatibleTracksToVertex(
inline auto Acts::AdaptiveMultiVertexFinder::addCompatibleTracksToVertex(
const std::vector<InputTrack>& tracks, Vertex& vtx,
FitterState_t& fitterState, const VertexingOptions& vertexingOptions) const
-> Result<void> {
VertexFitterState& fitterState,
const VertexingOptions& vertexingOptions) const -> Result<void> {
for (const auto& trk : tracks) {
auto params = m_cfg.extractParameters(trk);
auto pos = params.position(vertexingOptions.geoContext);
Expand All @@ -257,13 +253,11 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::addCompatibleTracksToVertex(
return {};
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::
canRecoverFromNoCompatibleTracks(
const std::vector<InputTrack>& allTracks,
const std::vector<InputTrack>& seedTracks, Vertex& vtx,
const Vertex& currentConstraint, FitterState_t& fitterState,
const VertexingOptions& vertexingOptions) const -> Result<bool> {
inline auto Acts::AdaptiveMultiVertexFinder::canRecoverFromNoCompatibleTracks(
const std::vector<InputTrack>& allTracks,
const std::vector<InputTrack>& seedTracks, Vertex& vtx,
const Vertex& currentConstraint, VertexFitterState& fitterState,
const VertexingOptions& vertexingOptions) const -> Result<bool> {
// Recover from cases where no compatible tracks to vertex
// candidate were found
// TODO: This is for now how it's done in athena... this look a bit
Expand Down Expand Up @@ -313,11 +307,10 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::
return Result<bool>::success(true);
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::canPrepareVertexForFit(
inline auto Acts::AdaptiveMultiVertexFinder::canPrepareVertexForFit(
const std::vector<InputTrack>& allTracks,
const std::vector<InputTrack>& seedTracks, Vertex& vtx,
const Vertex& currentConstraint, FitterState_t& fitterState,
const Vertex& currentConstraint, VertexFitterState& fitterState,
const VertexingOptions& vertexingOptions) const -> Result<bool> {
// Add vertex info to fitter state
fitterState.vtxInfoMap[&vtx] =
Expand All @@ -341,10 +334,9 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::canPrepareVertexForFit(
return Result<bool>::success(*resRec);
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::checkVertexAndCompatibleTracks(
inline auto Acts::AdaptiveMultiVertexFinder::checkVertexAndCompatibleTracks(
Vertex& vtx, const std::vector<InputTrack>& seedTracks,
FitterState_t& fitterState, bool useVertexConstraintInFit) const
VertexFitterState& fitterState, bool useVertexConstraintInFit) const
-> std::pair<int, bool> {
bool isGoodVertex = false;
int nCompatibleTracks = 0;
Expand Down Expand Up @@ -380,12 +372,11 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::checkVertexAndCompatibleTracks(
return {nCompatibleTracks, isGoodVertex};
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::
removeCompatibleTracksFromSeedTracks(
Vertex& vtx, std::vector<InputTrack>& seedTracks,
FitterState_t& fitterState,
std::vector<InputTrack>& removedSeedTracks) const -> void {
inline auto
Acts::AdaptiveMultiVertexFinder::removeCompatibleTracksFromSeedTracks(
Vertex& vtx, std::vector<InputTrack>& seedTracks,
VertexFitterState& fitterState,
std::vector<InputTrack>& removedSeedTracks) const -> void {
for (const auto& trk : fitterState.vtxInfoMap[&vtx].trackLinks) {
const auto& trkAtVtx =
fitterState.tracksAtVerticesMap.at(std::make_pair(trk, &vtx));
Expand All @@ -406,10 +397,9 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::
}
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::removeTrackIfIncompatible(
inline auto Acts::AdaptiveMultiVertexFinder::removeTrackIfIncompatible(
Vertex& vtx, std::vector<InputTrack>& seedTracks,
FitterState_t& fitterState, std::vector<InputTrack>& removedSeedTracks,
VertexFitterState& fitterState, std::vector<InputTrack>& removedSeedTracks,
const GeometryContext& geoCtx) const -> bool {
// Try to find the track with highest compatibility
double maxCompatibility = 0;
Expand Down Expand Up @@ -462,10 +452,9 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::removeTrackIfIncompatible(
return true;
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::keepNewVertex(
inline auto Acts::AdaptiveMultiVertexFinder::keepNewVertex(
Vertex& vtx, const std::vector<Vertex*>& allVertices,
FitterState_t& fitterState) const -> bool {
VertexFitterState& fitterState) const -> bool {
double contamination = 0.;
double contaminationNum = 0;
double contaminationDeNom = 0;
Expand All @@ -490,8 +479,7 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::keepNewVertex(
return true;
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::isMergedVertex(
inline auto Acts::AdaptiveMultiVertexFinder::isMergedVertex(
const Vertex& vtx, const std::vector<Vertex*>& allVertices) const -> bool {
const Vector4& candidatePos = vtx.fullPosition();
const SquareMatrix4& candidateCov = vtx.fullCovariance();
Expand Down Expand Up @@ -544,10 +532,9 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::isMergedVertex(
return false;
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::deleteLastVertex(
inline auto Acts::AdaptiveMultiVertexFinder::deleteLastVertex(
Vertex& vtx, std::vector<std::unique_ptr<Vertex>>& allVertices,
std::vector<Vertex*>& allVerticesPtr, FitterState_t& fitterState,
std::vector<Vertex*>& allVerticesPtr, VertexFitterState& fitterState,
const VertexingOptions& vertexingOptions) const -> Result<void> {
allVertices.pop_back();
allVerticesPtr.pop_back();
Expand Down Expand Up @@ -584,10 +571,9 @@ auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::deleteLastVertex(
return {};
}

template <typename vfitter_t>
auto Acts::AdaptiveMultiVertexFinder<vfitter_t>::getVertexOutputList(
inline auto Acts::AdaptiveMultiVertexFinder::getVertexOutputList(
const std::vector<Vertex*>& allVerticesPtr,
FitterState_t& fitterState) const -> Acts::Result<std::vector<Vertex>> {
VertexFitterState& fitterState) const -> Acts::Result<std::vector<Vertex>> {
std::vector<Vertex> outputVec;
for (auto vtx : allVerticesPtr) {
auto& outVtx = *vtx;
Expand Down
1 change: 0 additions & 1 deletion Core/include/Acts/Vertexing/GaussianTrackDensity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace Acts {
/// their d0 and z0 perigee parameters (mean value) and covariance
/// matrices (determining the width of the function)
class GaussianTrackDensity {
// @TODO: Remove template
public:
/// @brief Struct to store information for a single track
struct TrackEntry {
Expand Down
11 changes: 4 additions & 7 deletions Core/include/Acts/Vertexing/IterativeVertexFinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ namespace Acts {
/// from tracksAtVertex if not compatible.
/// 5. Add vertex to vertexCollection
/// 6. Repeat until no seedTracks are left or max. number of vertices found
///
////////////////////////////////////////////////////////////
///
/// @tparam vfitter_t Vertex fitter type
template <typename vfitter_t>
class IterativeVertexFinder final : public IVertexFinder {
using VertexFitter = FullBilloirVertexFitter;

public:
/// Configuration struct
struct Config {
Expand All @@ -71,14 +68,14 @@ class IterativeVertexFinder final : public IVertexFinder {
/// @param lin Track linearizer
/// @param sfinder The seed finder
/// @param est ImpactPointEstimator
Config(vfitter_t fitter, std::shared_ptr<IVertexFinder> sfinder,
Config(VertexFitter fitter, std::shared_ptr<IVertexFinder> sfinder,
ImpactPointEstimator est)
: vertexFitter(std::move(fitter)),
seedFinder(std::move(sfinder)),
ipEst(std::move(est)) {}

/// Vertex fitter
vfitter_t vertexFitter;
VertexFitter vertexFitter;

/// Track linearizer
TrackLinearizer trackLinearizer;
Expand Down
Loading

0 comments on commit 8ccefe1

Please sign in to comment.