Skip to content

Commit 8234613

Browse files
committed
Fix overlaps handling in the CKF
1 parent e5d9275 commit 8234613

File tree

15 files changed

+137
-127
lines changed

15 files changed

+137
-127
lines changed

core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ traccc_add_library( traccc_core core TYPE SHARED
8080
# Finding algorithmic code
8181
"include/traccc/finding/candidate_link.hpp"
8282
"include/traccc/finding/finding_config.hpp"
83+
"include/traccc/finding/propagation_data.hpp"
8384
"include/traccc/finding/actors/ckf_aborter.hpp"
8485
"include/traccc/finding/actors/interaction_register.hpp"
8586
"include/traccc/finding/details/combinatorial_kalman_filter_types.hpp"

core/include/traccc/finding/actors/ckf_aborter.hpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "traccc/definitions/qualifiers.hpp"
1313

1414
// detray include(s)
15+
#include <detray/definitions/indexing.hpp>
1516
#include <detray/propagator/base_actor.hpp>
1617

1718
// System include(s)
@@ -22,38 +23,43 @@ namespace traccc {
2223
/// Aborter triggered when the next surface is reached
2324
struct ckf_aborter : detray::actor {
2425
struct state {
25-
// minimal step length to prevent from staying on the same surface
26-
scalar min_step_length = 0.5f;
2726
/// Maximum step counts that track can make to reach the next surface
28-
unsigned int max_count = 100;
27+
unsigned int max_count = 100u;
28+
unsigned int count = 0u;
2929

30-
bool success = false;
31-
unsigned int count = 0;
30+
/// Previous sensitive surface index
31+
detray::dindex prev_surface_index{detray::dindex_invalid};
32+
/// Current sensitive surface index
33+
detray::dindex surface_index{detray::dindex_invalid};
3234

33-
scalar path_from_surface{0.f};
35+
/// Whether a surface was found
36+
bool success = false;
3437
};
3538

3639
template <typename propagator_state_t>
3740
TRACCC_HOST_DEVICE void operator()(state &abrt_state,
3841
propagator_state_t &prop_state) const {
3942

4043
auto &navigation = prop_state._navigation;
41-
const auto &stepping = prop_state._stepping;
4244

4345
abrt_state.count++;
44-
abrt_state.path_from_surface += stepping.step_size();
4546

46-
// Stop at the next sensitive surface
47-
if (navigation.is_on_sensitive() &&
48-
abrt_state.path_from_surface > abrt_state.min_step_length) {
49-
prop_state._heartbeat &= navigation.pause();
50-
abrt_state.success = navigation.is_alive();
47+
// Is this a valid sensitive surface to run the CKF on?
48+
if (!navigation.is_on_sensitive() ||
49+
(abrt_state.surface_index == navigation.barcode().index()) ||
50+
(abrt_state.prev_surface_index == navigation.barcode().index())) {
51+
return;
5152
}
5253

53-
// Reset path from surface
54-
if (navigation.is_on_sensitive()) {
55-
abrt_state.path_from_surface = 0.f;
56-
}
54+
// Update the visited sensitive surfaces and pause the propagation
55+
abrt_state.prev_surface_index = abrt_state.surface_index;
56+
abrt_state.surface_index = navigation.barcode().index();
57+
58+
prop_state._heartbeat &= navigation.pause();
59+
abrt_state.success = true;
60+
61+
assert(abrt_state.surface_index <
62+
navigation.detector().surfaces().size());
5763

5864
if (abrt_state.count > abrt_state.max_count) {
5965
prop_state._heartbeat &= navigation.abort(

core/include/traccc/finding/details/combinatorial_kalman_filter.hpp

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#pragma once
88

99
// Project include(s).
10-
#include <detray/utils/log.hpp>
11-
1210
#include "traccc/edm/measurement.hpp"
1311
#include "traccc/edm/track_container.hpp"
1412
#include "traccc/edm/track_state_helpers.hpp"
@@ -17,6 +15,7 @@
1715
#include "traccc/finding/candidate_link.hpp"
1816
#include "traccc/finding/details/combinatorial_kalman_filter_types.hpp"
1917
#include "traccc/finding/finding_config.hpp"
18+
#include "traccc/finding/propagation_data.hpp"
2019
#include "traccc/fitting/kalman_filter/gain_matrix_updater.hpp"
2120
#include "traccc/fitting/kalman_filter/is_line_visitor.hpp"
2221
#include "traccc/fitting/status_codes.hpp"
@@ -67,10 +66,6 @@ combinatorial_kalman_filter(
6766
const finding_config& config, vecmem::memory_resource& mr,
6867
const Logger& log) {
6968

70-
assert(config.min_step_length_for_next_surface >
71-
math::fabs(config.propagation.navigation.overstep_tolerance) &&
72-
"Min step length for the next surface should be higher than the "
73-
"overstep tolerance");
7469
assert(config.min_track_candidates_per_track >= 1);
7570

7671
/// The algebra type
@@ -81,6 +76,10 @@ combinatorial_kalman_filter(
8176
// Create a logger.
8277
auto logger = [&log]() -> const Logger& { return log; };
8378

79+
// Minimum chi2 cut to use for measurements on surfaces that are edge hits
80+
// (don't accumulate pileup measurements)
81+
const float chi2_min{math::max(10.f, 0.1f * config.chi2_max)};
82+
8483
/*****************************************************************
8584
* Measurement Operations
8685
*****************************************************************/
@@ -144,20 +143,18 @@ combinatorial_kalman_filter(
144143

145144
std::vector<bound_track_parameters<algebra_type>> out_params;
146145

147-
std::vector<std::uint8_t> in_is_edge(seeds.size(), false);
148-
std::vector<std::uint8_t> out_is_edge;
146+
std::vector<propagation_data> in_prop_data(seeds.size());
147+
std::vector<propagation_data> out_prop_data;
149148

150149
for (unsigned int step = 0u; step < config.max_track_candidates_per_track;
151150
step++) {
152151

153-
DETRAY_DEBUG_HOST("PRPGAGATION STEP: " << step);
154152
TRACCC_VERBOSE("Starting step "
155153
<< step + 1 << " / "
156154
<< config.max_track_candidates_per_track);
157155

158156
// Iterate over input parameters
159157
const std::size_t n_in_params = in_params.size();
160-
DETRAY_DEBUG_HOST("# PARAMS: " << n_in_params);
161158

162159
// Terminate if there is no parameter to proceed
163160
if (n_in_params == 0) {
@@ -166,23 +163,22 @@ combinatorial_kalman_filter(
166163

167164
// Rough estimation on out parameters size
168165
out_params.reserve(n_in_params);
169-
out_is_edge.reserve(n_in_params);
166+
out_prop_data.reserve(n_in_params);
170167

171168
// Previous step ID
172169
std::fill(n_trks_per_seed.begin(), n_trks_per_seed.end(), 0u);
173170

174171
// Parameters updated by Kalman fitter
175172
std::vector<bound_track_parameters<algebra_type>> updated_params;
173+
std::vector<propagation_data> updated_prop_data;
176174

177175
for (unsigned int in_param_id = 0; in_param_id < n_in_params;
178176
in_param_id++) {
179177

180178
bound_track_parameters<algebra_type>& in_param =
181179
in_params[in_param_id];
182180

183-
DETRAY_DEBUG_HOST("PARAMS: " << in_param);
184-
185-
const bool is_edge{in_is_edge[in_param_id] > 0u};
181+
const propagation_data& prop_data = in_prop_data[in_param_id];
186182

187183
assert(!in_param.is_invalid());
188184

@@ -259,9 +255,7 @@ combinatorial_kalman_filter(
259255
best_links;
260256

261257
// Iterate over the measurements
262-
DETRAY_DEBUG_HOST("# MEAS: " << (up - lo));
263258
for (unsigned int meas_id = lo; meas_id < up; meas_id++) {
264-
DETRAY_DEBUG_HOST("TESTING MEAS: " << meas_id);
265259

266260
// The measurement on surface to handle.
267261
const measurement& meas = measurements.at(meas_id);
@@ -279,13 +273,10 @@ combinatorial_kalman_filter(
279273

280274
const traccc::scalar chi2 = trk_state.filtered_chi2();
281275

282-
DETRAY_DEBUG_HOST("KF STATUS: " << fitter_debug_msg{res}());
283-
284276
// The chi2 from Kalman update should be less than chi2_max
285277
if (res == kalman_fitter_status::SUCCESS &&
286-
chi2 < config.chi2_max) {
287-
288-
DETRAY_DEBUG_HOST("FOUND MEAS: " << meas_id);
278+
((!prop_data.is_edge && chi2 <= config.chi2_max) ||
279+
(chi2 <= chi2_min))) {
289280

290281
best_links.push_back(
291282
{{.step = step,
@@ -322,6 +313,7 @@ combinatorial_kalman_filter(
322313

323314
// Add the updated parameter to the updated parameters
324315
updated_params.push_back(filtered_params);
316+
updated_prop_data.push_back(prop_data);
325317
TRACCC_VERBOSE("updated_params["
326318
<< updated_params.size() - 1
327319
<< "] = " << updated_params.back());
@@ -340,15 +332,15 @@ combinatorial_kalman_filter(
340332
.meas_idx = std::numeric_limits<unsigned int>::max(),
341333
.seed_idx = orig_param_id,
342334
.n_cand = n_cand,
343-
.n_skipped = is_edge ? skip_counter : skip_counter + 1,
335+
.n_skipped =
336+
prop_data.is_edge ? skip_counter : skip_counter + 1,
344337
.n_consecutive_skipped = consecutive_skipped + 1,
345338
.chi2 = std::numeric_limits<traccc::scalar>::max(),
346339
.chi2_sum = prev_chi2_sum,
347340
.ndf_sum = prev_ndf_sum});
348341

349-
DETRAY_DEBUG_HOST("HOLE: " << std::boolalpha << !is_edge);
350-
351342
updated_params.push_back(in_param);
343+
updated_prop_data.push_back(prop_data);
352344
TRACCC_VERBOSE("updated_params["
353345
<< updated_params.size() - 1
354346
<< "] = " << updated_params.back());
@@ -468,7 +460,6 @@ combinatorial_kalman_filter(
468460
}
469461

470462
if (this_is_dominated) {
471-
DETRAY_DEBUG_HOST("Track is DEAD!");
472463
param_liveness.at(tracks.at(i)) = 0u;
473464
break;
474465
}
@@ -497,12 +488,14 @@ combinatorial_kalman_filter(
497488
if (links.at(step).at(link_id).n_skipped >
498489
config.max_num_skipping_per_cand) {
499490

500-
DETRAY_DEBUG_HOST("MAKE TIP: MAX NO. HOLES");
501491
tips.push_back({step, link_id});
502492
continue;
503493
}
504494

495+
assert(updated_params.size() == updated_prop_data.size());
505496
const auto& param = updated_params[link_id];
497+
const propagation_data& prop_data = updated_prop_data[link_id];
498+
506499
// Create propagator state
507500
typename traccc::details::ckf_propagator_t<
508501
detector_t, bfield_t>::state propagation(param, field, det);
@@ -524,50 +517,45 @@ combinatorial_kalman_filter(
524517
// Update the actor config
525518
s4.min_pT(static_cast<scalar_type>(config.min_pT));
526519
s4.min_p(static_cast<scalar_type>(config.min_p));
527-
s5.min_step_length = config.min_step_length_for_next_surface;
520+
s5.prev_surface_index = prop_data.prev_surface;
521+
s5.surface_index = param.surface_link().index();
528522
s5.max_count = config.max_step_counts_for_next_surface;
529523

530-
DETRAY_DEBUG_HOST("PROPAGATING... ");
531524
// Propagate to the next surface
532525
propagator.propagate(propagation,
533526
detray::tie(s0, s1, s2, s3, s4, s5));
534527

535-
DETRAY_DEBUG_HOST(
536-
"FINISHED PROPAGATING. PATH: " << s5.path_from_surface);
537-
538528
// If a surface found, add the parameter for the next
539529
// step
540530
if (s5.success) {
541531
assert(propagation._navigation.is_on_sensitive());
542532
assert(!propagation._stepping.bound_params().is_invalid());
543533

544534
out_params.push_back(propagation._stepping.bound_params());
545-
out_is_edge.push_back(
535+
out_prop_data.emplace_back(
536+
s5.prev_surface_index,
546537
propagation._navigation.is_edge_candidate());
547538
param_to_link[step].push_back(link_id);
548539
}
549540
// Unless the track found a surface, it is considered a
550541
// tip
551542
else if (!s5.success &&
552543
(step >= (config.min_track_candidates_per_track - 1u))) {
553-
554-
DETRAY_DEBUG_HOST("MAKE TIP: NO SENSITIVE");
555544
tips.push_back({step, link_id});
556545
}
557546

558547
// If no more CKF step is expected, current candidate is
559548
// kept as a tip
560549
if (s5.success &&
561550
(step == (config.max_track_candidates_per_track - 1u))) {
562-
DETRAY_DEBUG_HOST("MAKE TIP: MAX CANDIDATES");
563551
tips.push_back({step, link_id});
564552
}
565553
}
566554

567555
in_params = std::move(out_params);
568-
in_is_edge = std::move(out_is_edge);
556+
in_prop_data = std::move(out_prop_data);
569557
out_params.clear();
570-
out_is_edge.clear();
558+
out_prop_data.clear();
571559
}
572560

573561
/**********************

core/include/traccc/finding/finding_config.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ struct finding_config {
3535
/// Maximum number of consecutive holes
3636
unsigned int max_num_consecutive_skipped = 1;
3737

38-
/// Minimum step length that track should make to reach the next surface. It
39-
/// should be set higher than the overstep tolerance not to make it stay on
40-
/// the same surface
41-
float min_step_length_for_next_surface = 1.2f * traccc::unit<float>::mm;
4238
/// Maximum step counts that track can make to reach the next surface
4339
unsigned int max_step_counts_for_next_surface = 100;
4440

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
/** TRACCC library, part of the ACTS project (R&D line)
3+
*
4+
* (c) 2025 CERN for the benefit of the ACTS project
5+
*
6+
* Mozilla Public License Version 2.0
7+
*/
8+
9+
#pragma once
10+
11+
// Detray include(s).
12+
#include <detray/definitions/indexing.hpp>
13+
14+
namespace traccc {
15+
16+
/// Data from the propagation loop that has to be kept between CKF steps
17+
struct propagation_data {
18+
/// The surface that was visited before the current one (overlaps
19+
/// resolution)
20+
detray::dindex prev_surface{detray::dindex_invalid};
21+
22+
/// Is the current surface hit in the extended tolerance band?
23+
bool is_edge{false};
24+
};
25+
26+
} // namespace traccc

core/include/traccc/fitting/kalman_filter/kalman_actor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ struct kalman_actor : detray::actor {
215215
actor_state.next();
216216

217217
// Flag renavigation of the current candidate
218-
// if (math::fabs(navigation()) > 1.f * unit<float>::um) {
219-
navigation.set_high_trust();
220-
//}
218+
if (math::fabs(navigation()) > 1.f * unit<float>::um) {
219+
navigation.set_high_trust();
220+
}
221221
}
222222
}
223223
};

core/include/traccc/fitting/kalman_filter/two_filters_smoother.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ struct two_filters_smoother {
185185

186186
// Calculate backward chi2
187187
const matrix_type<D, D> R = (I_m - H * K) * V;
188-
assert(matrix::determinant(R) != 0.f);
188+
// assert(matrix::determinant(R) != 0.f);
189189
assert(std::isfinite(matrix::determinant(R)));
190190
const matrix_type<1, 1> chi2 =
191191
algebra::matrix::transposed_product<true, false>(

0 commit comments

Comments
 (0)