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

refactor: set full vertex covariance after seeding #2707

Merged
merged 6 commits into from
Nov 21, 2023
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
25 changes: 17 additions & 8 deletions Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2020 CERN for the benefit of the Acts project
// Copyright (C) 2020-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
Expand Down Expand Up @@ -33,22 +33,31 @@ 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 <int trkGridSize = 15, typename vfitter_t = DummyVertexFitter<>>
template <int spatialTrkGridSize = 15, int temporalTrkGridSize = 1,
typename vfitter_t = DummyVertexFitter<>>
class AdaptiveGridDensityVertexFinder {
// Assert odd trkGridSize
static_assert(trkGridSize % 2);
// Assert odd grid sizes
static_assert(spatialTrkGridSize % 2);
static_assert(temporalTrkGridSize % 2);

using InputTrack_t = typename vfitter_t::InputTrack_t;
using GridDensity = AdaptiveGridTrackDensity<trkGridSize>;
using GridDensity =
AdaptiveGridTrackDensity<spatialTrkGridSize, temporalTrkGridSize>;

public:
using DensityMap = typename GridDensity::DensityMap;

/// @brief The Config struct
struct Config {
///@param binSize Bin size of grid in mm
Config(float binSize = 0.1)
: gridDensity(typename GridDensity::Config(binSize)) {}
/// @param spatialBinExtent_ The spatial extent of a bin in mm
Config(float spatialBinExtent = 0.1)
: gridDensity(typename GridDensity::Config(spatialBinExtent)) {}
/// @param spatialBinExtent_ The spatial extent of a bin in mm
/// @param temporalBinExtent_ The temporal extent of a bin in mm
/// @note The speed of light is set to 1, hence the unit.
Config(float spatialBinExtent, float temporalBinExtent)
: gridDensity(typename GridDensity::Config(spatialBinExtent,
temporalBinExtent)) {}
///@param gDensity The grid density
Config(const GridDensity& gDensity) : gridDensity(gDensity) {}

Expand Down
36 changes: 22 additions & 14 deletions Core/include/Acts/Vertexing/AdaptiveGridDensityVertexFinder.ipp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// This file is part of the Acts project.
//
// Copyright (C) 2020 CERN for the benefit of the Acts project
// Copyright (C) 2020-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/.

template <int trkGridSize, typename vfitter_t>
auto Acts::AdaptiveGridDensityVertexFinder<trkGridSize, vfitter_t>::find(
const std::vector<const InputTrack_t*>& trackVector,
const VertexingOptions<InputTrack_t>& vertexingOptions, State& state) const
template <int spatialTrkGridSize, int temporalTrkGridSize, typename vfitter_t>
auto Acts::AdaptiveGridDensityVertexFinder<
spatialTrkGridSize, temporalTrkGridSize,
vfitter_t>::find(const std::vector<const InputTrack_t*>& trackVector,
const VertexingOptions<InputTrack_t>& vertexingOptions,
State& state) const
-> Result<std::vector<Vertex<InputTrack_t>>> {
// Remove density contributions from tracks removed from track collection
if (m_cfg.cacheGridStateForTrackRemoval && state.isInitialized &&
Expand Down Expand Up @@ -56,7 +58,8 @@ auto Acts::AdaptiveGridDensityVertexFinder<trkGridSize, vfitter_t>::find(
}

double z = 0;
double width = 0;
double t = 0;
double zWidth = 0;
if (!state.mainDensityMap.empty()) {
if (!m_cfg.estimateSeedWidth) {
// Get z value of highest density bin
Expand All @@ -66,6 +69,7 @@ auto Acts::AdaptiveGridDensityVertexFinder<trkGridSize, vfitter_t>::find(
return maxZTRes.error();
}
z = (*maxZTRes).first;
t = (*maxZTRes).second;
} else {
// Get z value of highest density bin and width
auto maxZTResAndWidth =
Expand All @@ -75,20 +79,22 @@ auto Acts::AdaptiveGridDensityVertexFinder<trkGridSize, vfitter_t>::find(
return maxZTResAndWidth.error();
}
z = (*maxZTResAndWidth).first.first;
width = (*maxZTResAndWidth).second;
t = (*maxZTResAndWidth).first.second;
zWidth = (*maxZTResAndWidth).second;
}
}

// Construct output vertex
Vector3 seedPos = vertexingOptions.constraint.position() + Vector3(0., 0., z);
// Construct output vertex, t will be 0 if temporalTrkGridSize == 1
Vector4 seedPos =
vertexingOptions.constraint.fullPosition() + Vector4(0., 0., z, t);

Vertex<InputTrack_t> returnVertex = Vertex<InputTrack_t>(seedPos);

SquareMatrix4 seedCov = vertexingOptions.constraint.fullCovariance();

if (width != 0.) {
if (zWidth != 0.) {
// Use z-constraint from seed width
seedCov(2, 2) = width * width;
seedCov(2, 2) = zWidth * zWidth;
}

returnVertex.setFullCovariance(seedCov);
Expand All @@ -98,9 +104,11 @@ auto Acts::AdaptiveGridDensityVertexFinder<trkGridSize, vfitter_t>::find(
return seedVec;
}

template <int trkGridSize, typename vfitter_t>
auto Acts::AdaptiveGridDensityVertexFinder<trkGridSize, vfitter_t>::
doesPassTrackSelection(const BoundTrackParameters& trk) const -> bool {
template <int spatialTrkGridSize, int temporalTrkGridSize, typename vfitter_t>
auto Acts::AdaptiveGridDensityVertexFinder<
spatialTrkGridSize, temporalTrkGridSize,
vfitter_t>::doesPassTrackSelection(const BoundTrackParameters& trk) const
-> bool {
// Get required track parameters
const double d0 = trk.parameters()[BoundIndices::eBoundLoc0];
const double z0 = trk.parameters()[BoundIndices::eBoundLoc1];
Expand Down
9 changes: 5 additions & 4 deletions Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ auto Acts::TrackDensityVertexFinder<vfitter_t, track_density_t>::find(

// Calculate seed position
// Note: constraint position is (0,0,0) if no constraint provided
Vector3 seedPos = vertexingOptions.constraint.position() + Vector3(0., 0., z);
Vector4 seedPos =
vertexingOptions.constraint.fullPosition() + Vector4(0., 0., z, 0.);

Vertex<InputTrack_t> returnVertex = Vertex<InputTrack_t>(seedPos);

SquareMatrix3 seedCov = vertexingOptions.constraint.covariance();
SquareMatrix4 seedCov = vertexingOptions.constraint.fullCovariance();

// Check if a constraint is provided and set the new z position constraint
if (seedCov != SquareMatrix3::Zero() && std::isnormal(zAndWidth.second)) {
if (seedCov != SquareMatrix4::Zero() && std::isnormal(zAndWidth.second)) {
seedCov(eZ, eZ) = zAndWidth.second * zAndWidth.second;
}

returnVertex.setCovariance(seedCov);
returnVertex.setFullCovariance(seedCov);

std::vector<Vertex<InputTrack_t>> seedVec{returnVertex};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::execute(
Seeder seedFinder;
return executeAfterSeederChoice<Seeder, Finder>(ctx, seedFinder);
} else if (m_cfg.seedFinder == SeedFinder::AdaptiveGridSeeder) {
using Seeder = Acts::AdaptiveGridDensityVertexFinder<109, Fitter>;
using Seeder = Acts::AdaptiveGridDensityVertexFinder<109, 1, Fitter>;
using Finder = Acts::AdaptiveMultiVertexFinder<Fitter, Seeder>;
// The seeder config argument corresponds to the bin size in mm
Seeder::Config seederConfig(0.05);
Expand Down