Skip to content

Commit e5d9275

Browse files
committed
update to detray v0.104.1
1 parent acf74f5 commit e5d9275

File tree

23 files changed

+228
-72
lines changed

23 files changed

+228
-72
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct ckf_aborter : detray::actor {
4747
if (navigation.is_on_sensitive() &&
4848
abrt_state.path_from_surface > abrt_state.min_step_length) {
4949
prop_state._heartbeat &= navigation.pause();
50-
abrt_state.success = true;
50+
abrt_state.success = navigation.is_alive();
5151
}
5252

5353
// Reset path from surface
@@ -59,6 +59,7 @@ struct ckf_aborter : detray::actor {
5959
prop_state._heartbeat &= navigation.abort(
6060
"CKF: Maximum number of steps to reach next sensitive surface "
6161
"exceeded");
62+
abrt_state.success = false;
6263
}
6364
}
6465
};

core/include/traccc/finding/candidate_link.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct candidate_link {
2828
// Index to the initial seed
2929
unsigned int seed_idx;
3030

31+
// How many candidates were added to the track
32+
unsigned int n_cand;
33+
3134
// How many times it skipped a surface
3235
unsigned int n_skipped;
3336

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

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

99
// Project include(s).
10+
#include <detray/utils/log.hpp>
11+
1012
#include "traccc/edm/measurement.hpp"
1113
#include "traccc/edm/track_container.hpp"
1214
#include "traccc/edm/track_state_helpers.hpp"
@@ -126,8 +128,11 @@ combinatorial_kalman_filter(
126128
std::vector<std::pair<unsigned int, unsigned int>> tips;
127129

128130
// Create propagator
131+
// @TODO: Turn off the mask tolerance scaling for now
132+
auto prop_config{config.propagation};
133+
prop_config.navigation.estimate_scattering_noise = false;
129134
traccc::details::ckf_propagator_t<detector_t, bfield_t> propagator(
130-
config.propagation);
135+
prop_config);
131136

132137
// Create the input seeds container.
133138
bound_track_parameters_collection_types::const_device seeds{seeds_view};
@@ -139,15 +144,20 @@ combinatorial_kalman_filter(
139144

140145
std::vector<bound_track_parameters<algebra_type>> out_params;
141146

147+
std::vector<std::uint8_t> in_is_edge(seeds.size(), false);
148+
std::vector<std::uint8_t> out_is_edge;
149+
142150
for (unsigned int step = 0u; step < config.max_track_candidates_per_track;
143151
step++) {
144152

153+
DETRAY_DEBUG_HOST("PRPGAGATION STEP: " << step);
145154
TRACCC_VERBOSE("Starting step "
146155
<< step + 1 << " / "
147156
<< config.max_track_candidates_per_track);
148157

149158
// Iterate over input parameters
150159
const std::size_t n_in_params = in_params.size();
160+
DETRAY_DEBUG_HOST("# PARAMS: " << n_in_params);
151161

152162
// Terminate if there is no parameter to proceed
153163
if (n_in_params == 0) {
@@ -156,6 +166,7 @@ combinatorial_kalman_filter(
156166

157167
// Rough estimation on out parameters size
158168
out_params.reserve(n_in_params);
169+
out_is_edge.reserve(n_in_params);
159170

160171
// Previous step ID
161172
std::fill(n_trks_per_seed.begin(), n_trks_per_seed.end(), 0u);
@@ -169,13 +180,22 @@ combinatorial_kalman_filter(
169180
bound_track_parameters<algebra_type>& in_param =
170181
in_params[in_param_id];
171182

183+
DETRAY_DEBUG_HOST("PARAMS: " << in_param);
184+
185+
const bool is_edge{in_is_edge[in_param_id] > 0u};
186+
172187
assert(!in_param.is_invalid());
173188

174189
const unsigned int orig_param_id =
175190
(step == 0
176191
? in_param_id
177192
: links[step - 1][param_to_link[step - 1][in_param_id]]
178193
.seed_idx);
194+
const unsigned int n_cand =
195+
(step == 0
196+
? 0
197+
: links[step - 1][param_to_link[step - 1][in_param_id]]
198+
.n_cand);
179199
const unsigned int skip_counter =
180200
(step == 0
181201
? 0
@@ -239,7 +259,9 @@ combinatorial_kalman_filter(
239259
best_links;
240260

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

244266
// The measurement on surface to handle.
245267
const measurement& meas = measurements.at(meas_id);
@@ -248,7 +270,7 @@ combinatorial_kalman_filter(
248270
auto trk_state =
249271
edm::make_track_state<algebra_type>(measurements, meas_id);
250272

251-
const bool is_line = sf.template visit_mask<is_line_visitor>();
273+
const bool is_line = detail::is_line(sf);
252274

253275
// Run the Kalman update on a copy of the track parameters
254276
const kalman_fitter_status res =
@@ -257,15 +279,20 @@ combinatorial_kalman_filter(
257279

258280
const traccc::scalar chi2 = trk_state.filtered_chi2();
259281

282+
DETRAY_DEBUG_HOST("KF STATUS: " << fitter_debug_msg{res}());
283+
260284
// The chi2 from Kalman update should be less than chi2_max
261285
if (res == kalman_fitter_status::SUCCESS &&
262286
chi2 < config.chi2_max) {
263287

288+
DETRAY_DEBUG_HOST("FOUND MEAS: " << meas_id);
289+
264290
best_links.push_back(
265291
{{.step = step,
266292
.previous_candidate_idx = in_param_id,
267293
.meas_idx = meas_id,
268294
.seed_idx = orig_param_id,
295+
.n_cand = n_cand + 1,
269296
.n_skipped = skip_counter,
270297
.n_consecutive_skipped = 0,
271298
.chi2 = chi2,
@@ -312,12 +339,15 @@ combinatorial_kalman_filter(
312339
.previous_candidate_idx = in_param_id,
313340
.meas_idx = std::numeric_limits<unsigned int>::max(),
314341
.seed_idx = orig_param_id,
315-
.n_skipped = skip_counter + 1,
342+
.n_cand = n_cand,
343+
.n_skipped = is_edge ? skip_counter : skip_counter + 1,
316344
.n_consecutive_skipped = consecutive_skipped + 1,
317345
.chi2 = std::numeric_limits<traccc::scalar>::max(),
318346
.chi2_sum = prev_chi2_sum,
319347
.ndf_sum = prev_ndf_sum});
320348

349+
DETRAY_DEBUG_HOST("HOLE: " << std::boolalpha << !is_edge);
350+
321351
updated_params.push_back(in_param);
322352
TRACCC_VERBOSE("updated_params["
323353
<< updated_params.size() - 1
@@ -363,7 +393,7 @@ combinatorial_kalman_filter(
363393
prob(Lthisbase.chi2_sum,
364394
static_cast<scalar>(Lthisbase.ndf_sum - 5));
365395

366-
if (step + 1 - Lthisbase.n_skipped <=
396+
if (Lthisbase.n_cand <=
367397
config.duplicate_removal_minimum_length ||
368398
Lthisbase.ndf_sum <= 5) {
369399
continue;
@@ -377,7 +407,7 @@ combinatorial_kalman_filter(
377407
auto Lthis = Lthisbase;
378408
auto Lthat = links.at(step).at(tracks.at(j));
379409

380-
if (step + 1 - Lthat.n_skipped <=
410+
if (Lthat.n_cand <=
381411
config.duplicate_removal_minimum_length ||
382412
Lthisbase.ndf_sum <= 5) {
383413
continue;
@@ -438,6 +468,7 @@ combinatorial_kalman_filter(
438468
}
439469

440470
if (this_is_dominated) {
471+
DETRAY_DEBUG_HOST("Track is DEAD!");
441472
param_liveness.at(tracks.at(i)) = 0u;
442473
break;
443474
}
@@ -465,6 +496,8 @@ combinatorial_kalman_filter(
465496
// link to be a tip
466497
if (links.at(step).at(link_id).n_skipped >
467498
config.max_num_skipping_per_cand) {
499+
500+
DETRAY_DEBUG_HOST("MAKE TIP: MAX NO. HOLES");
468501
tips.push_back({step, link_id});
469502
continue;
470503
}
@@ -484,8 +517,8 @@ combinatorial_kalman_filter(
484517
traccc::details::ckf_interactor_t::state s2;
485518
typename interaction_register<
486519
traccc::details::ckf_interactor_t>::state s1{s2};
487-
// typename detray::parameter_resetter<
488-
// typename detector_t::algebra_type>::state s3{};
520+
typename detray::parameter_resetter<
521+
typename detector_t::algebra_type>::state s3{prop_config};
489522
typename detray::momentum_aborter<scalar_type>::state s4{};
490523
typename ckf_aborter::state s5;
491524
// Update the actor config
@@ -494,8 +527,13 @@ combinatorial_kalman_filter(
494527
s5.min_step_length = config.min_step_length_for_next_surface;
495528
s5.max_count = config.max_step_counts_for_next_surface;
496529

530+
DETRAY_DEBUG_HOST("PROPAGATING... ");
497531
// Propagate to the next surface
498-
propagator.propagate(propagation, detray::tie(s0, s1, s2, s4, s5));
532+
propagator.propagate(propagation,
533+
detray::tie(s0, s1, s2, s3, s4, s5));
534+
535+
DETRAY_DEBUG_HOST(
536+
"FINISHED PROPAGATING. PATH: " << s5.path_from_surface);
499537

500538
// If a surface found, add the parameter for the next
501539
// step
@@ -504,25 +542,32 @@ combinatorial_kalman_filter(
504542
assert(!propagation._stepping.bound_params().is_invalid());
505543

506544
out_params.push_back(propagation._stepping.bound_params());
545+
out_is_edge.push_back(
546+
propagation._navigation.is_edge_candidate());
507547
param_to_link[step].push_back(link_id);
508548
}
509549
// Unless the track found a surface, it is considered a
510550
// tip
511551
else if (!s5.success &&
512552
(step >= (config.min_track_candidates_per_track - 1u))) {
553+
554+
DETRAY_DEBUG_HOST("MAKE TIP: NO SENSITIVE");
513555
tips.push_back({step, link_id});
514556
}
515557

516558
// If no more CKF step is expected, current candidate is
517559
// kept as a tip
518560
if (s5.success &&
519561
(step == (config.max_track_candidates_per_track - 1u))) {
562+
DETRAY_DEBUG_HOST("MAKE TIP: MAX CANDIDATES");
520563
tips.push_back({step, link_id});
521564
}
522565
}
523566

524567
in_params = std::move(out_params);
568+
in_is_edge = std::move(out_is_edge);
525569
out_params.clear();
570+
out_is_edge.clear();
526571
}
527572

528573
/**********************
@@ -538,7 +583,7 @@ combinatorial_kalman_filter(
538583
// Get the link corresponding to tip
539584
auto L = links.at(tip.first).at(tip.second);
540585

541-
const unsigned int n_cands = tip.first + 1 - L.n_skipped;
586+
const unsigned int n_cands = L.n_cand;
542587

543588
// Skip if the number of tracks candidates is too small
544589
if (n_cands < config.min_track_candidates_per_track ||

core/include/traccc/fitting/details/kalman_fitting.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ typename edm::track_container<algebra_t>::host kalman_fitting(
8888
result_tracks_device.at(result_tracks_device.size() - 1),
8989
typename edm::track_state_collection<algebra_t>::device{
9090
vecmem::get_data(result.states)},
91-
measurements, seqs_buffer);
91+
measurements, seqs_buffer, fitter.config().propagation);
9292

9393
// Run the fitter. The status that it returns is not used here. The main
9494
// failure modes are saved onto the fitted track itself. Not sure what

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,31 @@
77

88
#pragma once
99

10+
#include <detray/geometry/mask.hpp>
1011
#include <detray/geometry/shapes/line.hpp>
12+
#include <detray/geometry/surface.hpp>
1113

1214
#include "traccc/definitions/qualifiers.hpp"
1315

14-
namespace traccc {
16+
namespace traccc::detail {
1517

16-
struct is_line_visitor {
17-
template <typename mask_group_t, typename index_t>
18-
[[nodiscard]] TRACCC_HOST_DEVICE inline bool operator()(
19-
const mask_group_t& /*mask_group*/, const index_t& /*index*/) const {
20-
using shape_type = typename mask_group_t::value_type::shape;
21-
return std::is_same_v<shape_type, detray::line<true>> ||
22-
std::is_same_v<shape_type, detray::line<false>>;
18+
/// @returns true if the surface has "line" shape
19+
template <typename detector_t>
20+
[[nodiscard]] TRACCC_HOST_DEVICE bool constexpr is_line(
21+
const detray::geometry::surface<detector_t> sf) {
22+
using algebra_t = typename detector_t::algebra_type;
23+
using straw_tube = detray::mask<detray::line<false>, algebra_t>;
24+
using wire_cell = detray::mask<detray::line<true>, algebra_t>;
25+
26+
if constexpr (detector_t::masks::template is_defined<straw_tube>() ||
27+
detector_t::masks::template is_defined<wire_cell>()) {
28+
return (sf.shape_id() ==
29+
detector_t::masks::template get_id<straw_tube>()) ||
30+
(sf.shape_id() ==
31+
detector_t::masks::template get_id<wire_cell>());
32+
} else {
33+
return false;
2334
}
2435
};
2536

26-
} // namespace traccc
37+
} // namespace traccc::detail

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct kalman_actor : detray::actor {
164164
// Run Kalman Gain Updater
165165
const auto sf = navigation.get_surface();
166166

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

169169
kalman_fitter_status res = kalman_fitter_status::SUCCESS;
170170

@@ -215,7 +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) {
218219
navigation.set_high_trust();
220+
//}
219221
}
220222
}
221223
};

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,31 @@ class kalman_fitter {
110110
track_states,
111111
const measurement_collection_types::const_device& measurements,
112112
vecmem::data::vector_view<detray::geometry::barcode>
113-
sequence_buffer)
113+
sequence_buffer,
114+
const detray::propagation::config& prop_cfg)
114115
: m_fit_actor_state{track, track_states, measurements},
115116
m_sequencer_state(
116117
vecmem::device_vector<detray::geometry::barcode>(
117118
sequence_buffer)),
119+
m_parameter_resetter{prop_cfg},
118120
m_fit_res{track},
119121
m_sequence_buffer(sequence_buffer) {}
120122

121123
/// @return the actor chain state
122124
TRACCC_HOST_DEVICE
123125
typename forward_actor_chain_type::state_ref_tuple operator()() {
124126
return detray::tie(m_aborter_state, m_interactor_state,
125-
m_fit_actor_state, m_sequencer_state,
126-
m_step_aborter_state);
127+
m_fit_actor_state, m_parameter_resetter,
128+
m_sequencer_state, m_step_aborter_state);
127129
}
128130

129131
/// @return the actor chain state
130132
TRACCC_HOST_DEVICE
131133
typename backward_actor_chain_type::state_ref_tuple
132134
backward_actor_state() {
133135
return detray::tie(m_aborter_state, m_fit_actor_state,
134-
m_interactor_state, m_step_aborter_state);
136+
m_interactor_state, m_parameter_resetter,
137+
m_step_aborter_state);
135138
}
136139

137140
/// Individual actor states
@@ -140,6 +143,7 @@ class kalman_fitter {
140143
typename forward_fit_actor::state m_fit_actor_state;
141144
typename barcode_sequencer::state m_sequencer_state;
142145
kalman_step_aborter::state m_step_aborter_state{};
146+
typename resetter::state m_parameter_resetter{};
143147

144148
/// Fitting result per track
145149
typename edm::track_collection<algebra_type>::device::proxy_type

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)