Skip to content

Commit 0c20f47

Browse files
committed
new stuff
1 parent fb0537f commit 0c20f47

File tree

17 files changed

+323
-119
lines changed

17 files changed

+323
-119
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ include( traccc-functions )
5252
set( TRACCC_CUSTOM_SCALARTYPE "float" CACHE STRING
5353
"Scalar type to use in the TRACCC code" )
5454

55+
# Temporary setting for the traccc device log level, until it can be removed.
56+
set( TRACCC_DEVICE_LOG_LVL "NONE" CACHE STRING
57+
"Log level for traccc and detray device code" )
58+
5559
# Flags controlling which parts of traccc to build.
5660
option( TRACCC_BUILD_CUDA "Build the CUDA sources included in traccc" FALSE )
5761
option( TRACCC_BUILD_HIP "Build the HIP sources included in traccc" FALSE)

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
// Project include(s)
1111
#include "traccc/definitions/primitives.hpp"
1212
#include "traccc/definitions/qualifiers.hpp"
13+
#include "traccc/utils/logging.hpp"
1314

1415
// detray include(s)
16+
#include <detray/definitions/indexing.hpp>
1517
#include <detray/propagator/base_actor.hpp>
1618

1719
// System include(s)
@@ -24,37 +26,55 @@ struct ckf_aborter : detray::actor {
2426
struct state {
2527
// minimal step length to prevent from staying on the same surface
2628
scalar min_step_length = 0.5f;
29+
2730
/// Maximum step counts that track can make to reach the next surface
28-
unsigned int max_count = 100;
31+
unsigned int max_count = 100u;
32+
unsigned int count = 0u;
2933

30-
bool success = false;
31-
unsigned int count = 0;
34+
/// Previous sensitive surface index
35+
detray::dindex prev_surface_index{detray::dindex_invalid};
36+
/// Current sensitive surface index
37+
detray::dindex surface_index{detray::dindex_invalid};
3238

33-
scalar path_from_surface{0.f};
39+
/// Whether a surface was found
40+
bool success = false;
3441
};
3542

3643
template <typename propagator_state_t>
3744
TRACCC_HOST_DEVICE void operator()(state &abrt_state,
3845
propagator_state_t &prop_state) const {
3946

4047
auto &navigation = prop_state._navigation;
41-
const auto &stepping = prop_state._stepping;
4248

4349
abrt_state.count++;
44-
abrt_state.path_from_surface += stepping.step_size();
4550

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();
51-
}
51+
TRACCC_VERBOSE_HOST_DEVICE("Checking CKF aborter...");
52+
TRACCC_DEBUG_HOST_DEVICE("=> second last sensitive: %d",
53+
abrt_state.prev_surface_index);
54+
TRACCC_DEBUG_HOST_DEVICE("=> last sensitive: %d",
55+
abrt_state.surface_index);
5256

53-
// Reset path from surface
54-
if (navigation.is_on_sensitive()) {
55-
abrt_state.path_from_surface = 0.f;
57+
// Is this a valid sensitive surface to run the CKF on?
58+
const detray::dindex sf_idx{navigation.barcode().index()};
59+
if (!navigation.is_on_sensitive() ||
60+
(abrt_state.surface_index == sf_idx) ||
61+
(abrt_state.prev_surface_index == sf_idx)) {
62+
return;
5663
}
5764

65+
// Update the visited sensitive surfaces and pause the propagation
66+
abrt_state.prev_surface_index = abrt_state.surface_index;
67+
abrt_state.surface_index = sf_idx;
68+
69+
TRACCC_VERBOSE_HOST_DEVICE("Found surface: %d",
70+
abrt_state.surface_index);
71+
72+
prop_state._heartbeat &= navigation.pause();
73+
abrt_state.success = true;
74+
75+
assert(abrt_state.surface_index <
76+
navigation.detector().surfaces().size());
77+
5878
if (abrt_state.count > abrt_state.max_count) {
5979
prop_state._heartbeat &= navigation.abort(
6080
"CKF: Maximum number of steps to reach next sensitive surface "

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

Lines changed: 55 additions & 41 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_candidate_collection.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"
@@ -73,6 +72,8 @@ combinatorial_kalman_filter(
7372
"overstep tolerance");
7473
assert(config.min_track_candidates_per_track >= 1);
7574

75+
const float chi2_min{math::max(10.f, 0.1f * config.chi2_max)};
76+
7677
/// The algebra type
7778
using algebra_type = typename detector_t::algebra_type;
7879
/// The scalar type
@@ -128,8 +129,11 @@ combinatorial_kalman_filter(
128129
std::vector<std::pair<unsigned int, unsigned int>> tips;
129130

130131
// Create propagator
132+
// @TODO: Turn off the mask tolerance scaling for now
133+
auto prop_config{config.propagation};
134+
prop_config.navigation.estimate_scattering_noise = false;
131135
traccc::details::ckf_propagator_t<detector_t, bfield_t> propagator(
132-
config.propagation);
136+
prop_config);
133137

134138
// Create the input seeds container.
135139
bound_track_parameters_collection_types::const_device seeds{seeds_view};
@@ -141,20 +145,19 @@ combinatorial_kalman_filter(
141145

142146
std::vector<bound_track_parameters<algebra_type>> out_params;
143147

144-
std::vector<std::uint8_t> in_is_edge(seeds.size(), false);
145-
std::vector<std::uint8_t> out_is_edge;
148+
std::vector<propagation_data> in_prop_data(seeds.size());
149+
std::vector<propagation_data> out_prop_data;
146150

147151
for (unsigned int step = 0u; step < config.max_track_candidates_per_track;
148152
step++) {
149153

150-
DETRAY_DEBUG_HOST("PRPGAGATION STEP: " << step);
151154
TRACCC_VERBOSE("Starting step "
152155
<< step + 1 << " / "
153156
<< config.max_track_candidates_per_track);
154157

155158
// Iterate over input parameters
156159
const std::size_t n_in_params = in_params.size();
157-
DETRAY_DEBUG_HOST("# PARAMS: " << n_in_params);
160+
TRACCC_VERBOSE("No. Params: " << n_in_params);
158161

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

164167
// Rough estimation on out parameters size
165168
out_params.reserve(n_in_params);
166-
out_is_edge.reserve(n_in_params);
169+
out_prop_data.reserve(n_in_params);
167170

168171
// Previous step ID
169172
std::fill(n_trks_per_seed.begin(), n_trks_per_seed.end(), 0u);
170173

171174
// Parameters updated by Kalman fitter
172175
std::vector<bound_track_parameters<algebra_type>> updated_params;
176+
std::vector<propagation_data> updated_prop_data;
173177

174178
for (unsigned int in_param_id = 0; in_param_id < n_in_params;
175179
in_param_id++) {
176180

177181
bound_track_parameters<algebra_type>& in_param =
178182
in_params[in_param_id];
179183

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

184186
assert(!in_param.is_invalid());
185187

@@ -256,9 +258,9 @@ combinatorial_kalman_filter(
256258
best_links;
257259

258260
// Iterate over the measurements
259-
DETRAY_DEBUG_HOST("# MEAS: " << (up - lo));
261+
TRACCC_VERBOSE("No. measurements: " << (up - lo));
260262
for (unsigned int meas_id = lo; meas_id < up; meas_id++) {
261-
DETRAY_DEBUG_HOST("TESTING MEAS: " << meas_id);
263+
TRACCC_DEBUG("Testing measurement: " << meas_id);
262264

263265
// The measurement on surface to handle.
264266
const measurement& meas = measurements.at(meas_id);
@@ -276,13 +278,14 @@ combinatorial_kalman_filter(
276278

277279
const traccc::scalar chi2 = trk_state.filtered_chi2();
278280

279-
DETRAY_DEBUG_HOST("KF STATUS: " << fitter_debug_msg{res}());
281+
TRACCC_DEBUG("KF status: " << fitter_debug_msg{res}());
280282

281283
// The chi2 from Kalman update should be less than chi2_max
282284
if (res == kalman_fitter_status::SUCCESS &&
283-
chi2 < config.chi2_max) {
285+
((!prop_data.is_edge && chi2 <= config.chi2_max) ||
286+
(chi2 <= chi2_min))) {
284287

285-
DETRAY_DEBUG_HOST("FOUND MEAS: " << meas_id);
288+
TRACCC_VERBOSE("Found measurement: " << meas_id);
286289

287290
best_links.push_back(
288291
{{.step = step,
@@ -319,9 +322,10 @@ combinatorial_kalman_filter(
319322

320323
// Add the updated parameter to the updated parameters
321324
updated_params.push_back(filtered_params);
322-
TRACCC_VERBOSE("updated_params["
323-
<< updated_params.size() - 1
324-
<< "] = " << updated_params.back());
325+
updated_prop_data.push_back(prop_data);
326+
TRACCC_DEBUG("updated_params["
327+
<< updated_params.size() - 1
328+
<< "] = " << updated_params.back());
325329
}
326330

327331
/*****************************************************************
@@ -336,19 +340,22 @@ combinatorial_kalman_filter(
336340
.previous_candidate_idx = in_param_id,
337341
.meas_idx = std::numeric_limits<unsigned int>::max(),
338342
.seed_idx = orig_param_id,
339-
.n_skipped = is_edge ? skip_counter : skip_counter + 1,
340-
.n_consecutive_skipped = consecutive_skipped + 1,
341343
.n_cand = n_cand,
344+
.n_skipped =
345+
prop_data.is_edge ? skip_counter : skip_counter + 1,
346+
.n_consecutive_skipped = consecutive_skipped + 1,
342347
.chi2 = std::numeric_limits<traccc::scalar>::max(),
343348
.chi2_sum = prev_chi2_sum,
344349
.ndf_sum = prev_ndf_sum});
345350

346-
DETRAY_DEBUG_HOST("HOLE: " << std::boolalpha << !is_edge);
351+
TRACCC_VERBOSE("Is hole: " << std::boolalpha
352+
<< !prop_data.is_edge);
347353

348354
updated_params.push_back(in_param);
349-
TRACCC_VERBOSE("updated_params["
350-
<< updated_params.size() - 1
351-
<< "] = " << updated_params.back());
355+
updated_prop_data.push_back(prop_data);
356+
TRACCC_DEBUG("updated_params["
357+
<< updated_params.size() - 1
358+
<< "] = " << updated_params.back());
352359
}
353360
}
354361

@@ -465,7 +472,7 @@ combinatorial_kalman_filter(
465472
}
466473

467474
if (this_is_dominated) {
468-
DETRAY_DEBUG_HOST("Track is DEAD!");
475+
TRACCC_VERBOSE("Track is dead (deduplication)!");
469476
param_liveness.at(tracks.at(i)) = 0u;
470477
break;
471478
}
@@ -491,15 +498,20 @@ combinatorial_kalman_filter(
491498

492499
// If number of skips is larger than the maximum value, consider the
493500
// link to be a tip
494-
if (links.at(step).at(link_id).n_skipped >
495-
config.max_num_skipping_per_cand) {
501+
if ((links.at(step).at(link_id).n_skipped >
502+
config.max_num_skipping_per_cand) ||
503+
(links.at(step).at(link_id).n_consecutive_skipped >
504+
config.max_num_consecutive_skipped)) {
496505

497-
DETRAY_DEBUG_HOST("MAKE TIP: MAX NO. HOLES");
506+
TRACCC_WARNING("Create tip: max no. of holes reached");
498507
tips.push_back({step, link_id});
499508
continue;
500509
}
501510

511+
assert(updated_params.size() == updated_prop_data.size());
502512
const auto& param = updated_params[link_id];
513+
const propagation_data& prop_data = updated_prop_data[link_id];
514+
503515
// Create propagator state
504516
typename traccc::details::ckf_propagator_t<
505517
detector_t, bfield_t>::state propagation(param, field, det);
@@ -515,23 +527,25 @@ combinatorial_kalman_filter(
515527
typename interaction_register<
516528
traccc::details::ckf_interactor_t>::state s1{s2};
517529
typename detray::parameter_resetter<
518-
typename detector_t::algebra_type>::state s3{
519-
config.propagation};
530+
typename detector_t::algebra_type>::state s3{prop_config};
520531
typename detray::momentum_aborter<scalar_type>::state s4{};
521-
typename ckf_aborter::state s5;
532+
typename ckf_aborter::state s5{};
533+
522534
// Update the actor config
523535
s4.min_pT(static_cast<scalar_type>(config.min_pT));
524536
s4.min_p(static_cast<scalar_type>(config.min_p));
537+
s5.prev_surface_index = prop_data.prev_surface;
538+
s5.surface_index = param.surface_link().index();
525539
s5.min_step_length = config.min_step_length_for_next_surface;
526540
s5.max_count = config.max_step_counts_for_next_surface;
527541

528-
DETRAY_DEBUG_HOST("PROPAGATING... ");
542+
TRACCC_DEBUG("Propagating... ");
529543
// Propagate to the next surface
530544
propagator.propagate(propagation,
531545
detray::tie(s0, s1, s2, s3, s4, s5));
532546

533-
DETRAY_DEBUG_HOST(
534-
"FINISHED PROPAGATING. PATH: " << s5.path_from_surface);
547+
TRACCC_DEBUG("Finished propagation: On surface "
548+
<< s5.surface_index);
535549

536550
// If a surface found, add the parameter for the next
537551
// step
@@ -540,32 +554,32 @@ combinatorial_kalman_filter(
540554
assert(!propagation._stepping.bound_params().is_invalid());
541555

542556
out_params.push_back(propagation._stepping.bound_params());
543-
out_is_edge.push_back(
557+
out_prop_data.emplace_back(
558+
s5.prev_surface_index,
544559
propagation._navigation.is_edge_candidate());
545560
param_to_link[step].push_back(link_id);
546561
}
547562
// Unless the track found a surface, it is considered a
548563
// tip
549564
else if (!s5.success &&
550565
(step >= (config.min_track_candidates_per_track - 1u))) {
551-
552-
DETRAY_DEBUG_HOST("MAKE TIP: NO SENSITIVE");
566+
TRACCC_VERBOSE("Create tip: No next sensitive found");
553567
tips.push_back({step, link_id});
554568
}
555569

556570
// If no more CKF step is expected, current candidate is
557571
// kept as a tip
558572
if (s5.success &&
559573
(step == (config.max_track_candidates_per_track - 1u))) {
560-
DETRAY_DEBUG_HOST("MAKE TIP: MAX CANDIDATES");
574+
TRACCC_ERROR("Create tip: Max no. candidates");
561575
tips.push_back({step, link_id});
562576
}
563577
}
564578

565579
in_params = std::move(out_params);
566-
in_is_edge = std::move(out_is_edge);
580+
in_prop_data = std::move(out_prop_data);
567581
out_params.clear();
568-
out_is_edge.clear();
582+
out_prop_data.clear();
569583
}
570584

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

0 commit comments

Comments
 (0)