Skip to content
Open
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
17 changes: 7 additions & 10 deletions core/include/traccc/edm/track_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/definitions/track_parametrization.hpp"
#include "traccc/edm/container.hpp"
#include "traccc/utils/trigonometric_helpers.hpp"

// detray include(s).
#include <detray/tracks/tracks.hpp>
Expand Down Expand Up @@ -48,19 +49,15 @@ using bound_track_parameters_collection_types =

// Wrap the phi of track parameters to [-pi,pi]
template <detray::concepts::algebra algebra_t>
TRACCC_HOST_DEVICE inline void wrap_phi(
TRACCC_HOST_DEVICE constexpr void normalize_angles(
bound_track_parameters<algebra_t>& param) {
traccc::scalar phi;
traccc::scalar theta;

std::tie(phi, theta) = detail::wrap_phi_theta(param.phi(), param.theta());

traccc::scalar phi = param.phi();
static constexpr traccc::scalar TWOPI =
2.f * traccc::constant<traccc::scalar>::pi;
phi = math::fmod(phi, TWOPI);
if (phi > traccc::constant<traccc::scalar>::pi) {
phi -= TWOPI;
} else if (phi < -traccc::constant<traccc::scalar>::pi) {
phi += TWOPI;
}
param.set_phi(phi);
param.set_theta(theta);
}

/// Covariance inflation used for track fitting
Expand Down
43 changes: 32 additions & 11 deletions core/include/traccc/finding/details/combinatorial_kalman_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ combinatorial_kalman_filter(
std::vector<std::pair<unsigned int, unsigned int>> tips;

// Create propagator
auto prop_cfg{config.propagation};
prop_cfg.navigation.estimate_scattering_noise = false;
traccc::details::ckf_propagator_t<detector_t, bfield_t> propagator(
config.propagation);
prop_cfg);

// Create the input seeds container.
bound_track_parameters_collection_types::const_device seeds{seeds_view};
Expand Down Expand Up @@ -240,15 +242,14 @@ combinatorial_kalman_filter(

// Iterate over the measurements
for (unsigned int meas_id = lo; meas_id < up; meas_id++) {

// The measurement on surface to handle.
const measurement& meas = measurements.at(meas_id);

// Create a standalone track state object.
auto trk_state =
edm::make_track_state<algebra_type>(measurements, meas_id);

const bool is_line = sf.template visit_mask<is_line_visitor>();
const bool is_line = detail::is_line(sf);

// Run the Kalman update on a copy of the track parameters
const kalman_fitter_status res =
Expand Down Expand Up @@ -484,8 +485,8 @@ combinatorial_kalman_filter(
traccc::details::ckf_interactor_t::state s2;
typename interaction_register<
traccc::details::ckf_interactor_t>::state s1{s2};
// typename detray::parameter_resetter<
// typename detector_t::algebra_type>::state s3{};
typename detray::parameter_resetter<
typename detector_t::algebra_type>::state s3{prop_cfg};
typename detray::momentum_aborter<scalar_type>::state s4{};
typename ckf_aborter::state s5;
// Update the actor config
Expand All @@ -495,21 +496,41 @@ combinatorial_kalman_filter(
s5.max_count = config.max_step_counts_for_next_surface;

// Propagate to the next surface
propagator.propagate(propagation, detray::tie(s0, s1, s2, s4, s5));
propagator.propagate(propagation,
detray::tie(s0, s1, s2, s3, s4, s5));

// If a surface found, add the parameter for the next
// step
if (s5.success) {
bool valid_track{s5.success};
if (valid_track) {
assert(propagation._navigation.is_on_sensitive());
assert(!propagation._stepping.bound_params().is_invalid());

out_params.push_back(propagation._stepping.bound_params());
param_to_link[step].push_back(link_id);
const auto& out_param = propagation._stepping.bound_params();

const scalar theta = out_param.theta();
if (theta <= 0.f ||
theta >= 2.f * constant<traccc::scalar>::pi) {
valid_track = false;
}

if (!std::isfinite(out_param.phi())) {
valid_track = false;
}

if (math::fabs(out_param.qop()) == 0.f) {
valid_track = false;
}

if (valid_track) {
out_params.push_back(out_param);
param_to_link[step].push_back(link_id);
}
}
// Unless the track found a surface, it is considered a
// tip
else if (!s5.success &&
(step >= (config.min_track_candidates_per_track - 1u))) {
if (!valid_track &&
(step >= (config.min_track_candidates_per_track - 1u))) {
tips.push_back({step, link_id});
}

Expand Down
2 changes: 1 addition & 1 deletion core/include/traccc/finding/finding_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct finding_config {
unsigned int max_step_counts_for_next_surface = 100;

/// Maximum Chi-square that is allowed for branching
float chi2_max = 100.f;
float chi2_max = 30.f;

/// Propagation configuration
detray::propagation::config propagation{};
Expand Down
2 changes: 1 addition & 1 deletion core/include/traccc/fitting/details/kalman_fitting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ typename edm::track_container<algebra_t>::host kalman_fitting(
result_tracks_device.at(result_tracks_device.size() - 1),
typename edm::track_state_collection<algebra_t>::device{
vecmem::get_data(result.states)},
measurements, seqs_buffer);
measurements, seqs_buffer, fitter.config().propagation);

// Run the fitter. The status that it returns is not used here. The main
// failure modes are saved onto the fitted track itself. Not sure what
Expand Down
2 changes: 1 addition & 1 deletion core/include/traccc/fitting/fitting_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct fitting_config {
std::size_t barcode_sequence_size_factor = 5;
std::size_t min_barcode_sequence_capacity = 100;
traccc::scalar backward_filter_mask_tolerance =
5.f * traccc::unit<scalar>::mm;
10.f * traccc::unit<scalar>::m;
};

} // namespace traccc
56 changes: 36 additions & 20 deletions core/include/traccc/fitting/kalman_filter/gain_matrix_updater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ struct gain_matrix_updater {
predicted_vec + K * (meas_local - H * predicted_vec);
const matrix_type<6, 6> filtered_cov = (I66 - K * H) * predicted_cov;

// Check the covariance for consistency
if (getter::element(filtered_cov, 0, 0) <= 0.f ||
getter::element(filtered_cov, 1, 1) <= 0.f ||
getter::element(filtered_cov, 2, 2) <= 0.f ||
getter::element(filtered_cov, 3, 3) <= 0.f ||
getter::element(filtered_cov, 4, 4) <= 0.f ||
getter::element(filtered_cov, 5, 5) <= 0.f) {
return kalman_fitter_status::ERROR_UPDATER_INVALID_COVARIANCE;
}

// Return false if track is parallel to z-axis or phi is not finite
if (!std::isfinite(getter::element(filtered_vec, e_bound_theta, 0))) {
return kalman_fitter_status::ERROR_INVERSION;
}

if (!std::isfinite(getter::element(filtered_vec, e_bound_phi, 0))) {
return kalman_fitter_status::ERROR_INVERSION;
}

if (math::fabs(getter::element(filtered_vec, e_bound_qoverp, 0)) ==
0.f) {
return kalman_fitter_status::ERROR_QOP_ZERO;
}

// Residual between measurement and (projected) filtered vector
const matrix_type<D, 1> residual = meas_local - H * filtered_vec;

Expand All @@ -133,36 +157,28 @@ struct gain_matrix_updater {
residual, matrix::inverse(R)) *
residual;

// Return false if track is parallel to z-axis or phi is not finite
const scalar theta = bound_params.theta();

if (theta <= 0.f || theta >= constant<traccc::scalar>::pi) {
return kalman_fitter_status::ERROR_THETA_ZERO;
}

if (!std::isfinite(bound_params.phi())) {
return kalman_fitter_status::ERROR_INVERSION;
}
const scalar chi2_val{getter::element(chi2, 0, 0)};

if (std::abs(bound_params.qop()) == 0.f) {
return kalman_fitter_status::ERROR_QOP_ZERO;
}

if (getter::element(chi2, 0, 0) < 0.f) {
if (chi2_val < 0.f) {
return kalman_fitter_status::ERROR_UPDATER_CHI2_NEGATIVE;
}

if (!std::isfinite(getter::element(chi2, 0, 0))) {
if (!std::isfinite(chi2_val)) {
return kalman_fitter_status::ERROR_UPDATER_CHI2_NOT_FINITE;
}

// Set the track state parameters
// Set the chi2 for this track and measurement
trk_state.filtered_params().set_vector(filtered_vec);
trk_state.filtered_params().set_covariance(filtered_cov);
trk_state.filtered_chi2() = getter::element(chi2, 0, 0);
trk_state.filtered_chi2() = chi2_val;

// Wrap the phi in the range of [-pi, pi]
wrap_phi(trk_state.filtered_params());
// Wrap the phi and theta angles in their valid ranges
normalize_angles(trk_state.filtered_params());

const scalar theta = trk_state.filtered_params().theta();
if (theta <= 0.f || theta >= 2.f * constant<traccc::scalar>::pi) {
return kalman_fitter_status::ERROR_THETA_POLE;
}

assert(!trk_state.filtered_params().is_invalid());

Expand Down
29 changes: 20 additions & 9 deletions core/include/traccc/fitting/kalman_filter/is_line_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@

#pragma once

#include <detray/geometry/mask.hpp>
#include <detray/geometry/shapes/line.hpp>
#include <detray/geometry/surface.hpp>

#include "traccc/definitions/qualifiers.hpp"

namespace traccc {
namespace traccc::detail {

struct is_line_visitor {
template <typename mask_group_t, typename index_t>
[[nodiscard]] TRACCC_HOST_DEVICE inline bool operator()(
const mask_group_t& /*mask_group*/, const index_t& /*index*/) const {
using shape_type = typename mask_group_t::value_type::shape;
return std::is_same_v<shape_type, detray::line<true>> ||
std::is_same_v<shape_type, detray::line<false>>;
/// @returns true if the surface has "line" shape
template <typename detector_t>
[[nodiscard]] TRACCC_HOST_DEVICE bool constexpr is_line(
const detray::geometry::surface<detector_t> sf) {
using algebra_t = typename detector_t::algebra_type;
using straw_tube = detray::mask<detray::line<false>, algebra_t>;
using wire_cell = detray::mask<detray::line<true>, algebra_t>;

if constexpr (detector_t::masks::template is_defined<straw_tube>() ||
detector_t::masks::template is_defined<wire_cell>()) {
return (sf.shape_id() ==
detector_t::masks::template get_id<straw_tube>()) ||
(sf.shape_id() ==
detector_t::masks::template get_id<wire_cell>());
} else {
return false;
}
};

} // namespace traccc
} // namespace traccc::detail
9 changes: 7 additions & 2 deletions core/include/traccc/fitting/kalman_filter/kalman_actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct kalman_actor : detray::actor {
// Run Kalman Gain Updater
const auto sf = navigation.get_surface();

const bool is_line = sf.template visit_mask<is_line_visitor>();
const bool is_line = detail::is_line(sf);

kalman_fitter_status res = kalman_fitter_status::SUCCESS;

Expand All @@ -173,6 +173,9 @@ struct kalman_actor : detray::actor {
kalman_actor_direction::FORWARD_ONLY ||
direction_e ==
kalman_actor_direction::BIDIRECTIONAL) {
// Wrap the phi and theta angles in their valid ranges
normalize_angles(propagation._stepping.bound_params());

// Forward filter
res = gain_matrix_updater<algebra_t>{}(
trk_state, actor_state.m_measurements,
Expand Down Expand Up @@ -215,7 +218,9 @@ struct kalman_actor : detray::actor {
actor_state.next();

// Flag renavigation of the current candidate
navigation.set_high_trust();
if (math::fabs(navigation()) > 1.f * unit<float>::um) {
navigation.set_high_trust();
}
}
}
};
Expand Down
Loading
Loading