Skip to content

Commit

Permalink
Merge pull request #521 from SylvainJoube/greedy-ambiguity-resolution…
Browse files Browse the repository at this point in the history
…-performance

Add Ambiguity Resolution Performance Writer
  • Loading branch information
krasznaa authored Mar 5, 2024
2 parents 3be655e + 8c616af commit 5f0fa34
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 6 deletions.
17 changes: 17 additions & 0 deletions examples/run/cpu/seeding_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ int seq_run(const traccc::seeding_input_options& /*i_cfg*/,
traccc::fitting_performance_writer fit_performance_writer(
traccc::fitting_performance_writer::config{});

traccc::finding_performance_writer::config ar_writer_cfg;
ar_writer_cfg.file_path = "performance_track_ambiguity_resolution.root";
ar_writer_cfg.algorithm_name = "ambiguity_resolution";
traccc::finding_performance_writer ar_performance_writer(ar_writer_cfg);

// Output stats
uint64_t n_spacepoints = 0;
uint64_t n_measurements = 0;
Expand Down Expand Up @@ -198,6 +203,10 @@ int seq_run(const traccc::seeding_input_options& /*i_cfg*/,
track_states = host_fitting(host_det, field, track_candidates);
n_fitted_tracks += track_states.size();

/*-----------------------------------------
Ambiguity Resolution with Greedy Solver
-----------------------------------------*/

if (common_opts.perform_ambiguity_resolution) {
track_states_ar = host_ambiguity_resolution(track_states);
n_ambiguity_free_tracks += track_states_ar.size();
Expand Down Expand Up @@ -226,6 +235,11 @@ int seq_run(const traccc::seeding_input_options& /*i_cfg*/,
find_performance_writer.write(traccc::get_data(track_candidates),
evt_map);

if (common_opts.perform_ambiguity_resolution) {
ar_performance_writer.write(traccc::get_data(track_states_ar),
evt_map);
}

for (unsigned int i = 0; i < track_states.size(); i++) {
const auto& trk_states_per_track = track_states.at(i).items;

Expand All @@ -241,6 +255,9 @@ int seq_run(const traccc::seeding_input_options& /*i_cfg*/,
sd_performance_writer.finalize();
find_performance_writer.finalize();
fit_performance_writer.finalize();
if (common_opts.perform_ambiguity_resolution) {
ar_performance_writer.finalize();
}
}

std::cout << "==> Statistics ... " << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// Project include(s).
#include "traccc/edm/track_candidate.hpp"
#include "traccc/edm/track_state.hpp"
#include "traccc/io/event_map2.hpp"

// System include(s).
Expand All @@ -35,6 +36,8 @@ class finding_performance_writer {
/// Configuration for the tool
struct config {

// Algorithm name, for ROOT display
std::string algorithm_name = "finding";
/// Output filename.
std::string file_path = "performance_track_finding.root";
/// Output file mode
Expand Down Expand Up @@ -63,6 +66,9 @@ class finding_performance_writer {
track_candidates_view,
const event_map2& evt_map);

void write(const track_state_container_types::const_view& track_states_view,
const event_map2& evt_map);

void finalize();

private:
Expand All @@ -72,6 +78,10 @@ class finding_performance_writer {
/// Opaque data members for the class
std::unique_ptr<details::finding_performance_writer_data> m_data;

/// Common method to both track finding and ambiguity resolution
void write_common(const std::vector<std::vector<measurement>>& tracks,
const event_map2& evt_map);

}; // class finding_performance_writer

} // namespace traccc
75 changes: 69 additions & 6 deletions performance/src/efficiency/finding_performance_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,27 @@ finding_performance_writer::finding_performance_writer(const config& cfg)
: m_cfg(cfg),
m_data(std::make_unique<details::finding_performance_writer_data>(cfg)) {

m_data->m_eff_plot_tool.book("finding", m_data->m_eff_plot_cache);
m_data->m_duplication_plot_tool.book("finding",
m_data->m_eff_plot_tool.book(m_cfg.algorithm_name,
m_data->m_eff_plot_cache);
m_data->m_duplication_plot_tool.book(m_cfg.algorithm_name,
m_data->m_duplication_plot_cache);
}

finding_performance_writer::~finding_performance_writer() {}

void finding_performance_writer::write(
const track_candidate_container_types::const_view& track_candidates_view,
const event_map2& evt_map) {
namespace {

std::map<particle_id, std::size_t> match_counter;
// For track finding
std::vector<std::vector<measurement>> prepare_data(
const track_candidate_container_types::const_view& track_candidates_view) {
std::vector<std::vector<measurement>> result;

// Iterate over the tracks.
track_candidate_container_types::const_device track_candidates(
track_candidates_view);

const unsigned int n_tracks = track_candidates.size();
result.reserve(n_tracks);

for (unsigned int i = 0; i < n_tracks; i++) {
const auto& cands = track_candidates.at(i).items;
Expand All @@ -79,6 +82,48 @@ void finding_performance_writer::write(
for (const auto& cand : cands) {
measurements.push_back(cand);
}
result.push_back(std::move(measurements));
}
return result;
}

// For track finding
std::vector<std::vector<measurement>> prepare_data(
const track_state_container_types::const_view& track_states_view) {
std::vector<std::vector<measurement>> result;

// Iterate over the tracks.
track_state_container_types::const_device track_states(track_states_view);

const unsigned int n_tracks = track_states.size();
result.reserve(n_tracks);

for (unsigned int i = 0; i < n_tracks; i++) {
auto const& [fit_res, states] = track_states.at(i);
std::vector<measurement> measurements;
measurements.reserve(states.size());
for (const auto& st : states) {
measurements.push_back(st.get_measurement());
}
result.push_back(std::move(measurements));
}
return result;
}

} // namespace

void finding_performance_writer::write_common(
const std::vector<std::vector<measurement>>& tracks,
const event_map2& evt_map) {

std::map<particle_id, std::size_t> match_counter;

// Iterate over the tracks.
const unsigned int n_tracks = tracks.size();

for (unsigned int i = 0; i < n_tracks; i++) {

const std::vector<measurement>& measurements = tracks[i];

// Check which particle matches this seed.
std::vector<particle_hit_count> particle_hit_counts =
Expand Down Expand Up @@ -112,6 +157,24 @@ void finding_performance_writer::write(
}
}

/// For track finding
void finding_performance_writer::write(
const track_candidate_container_types::const_view& track_candidates_view,
const event_map2& evt_map) {
std::vector<std::vector<measurement>> tracks =
prepare_data(track_candidates_view);
write_common(tracks, evt_map);
}

/// For ambiguity resolution
void finding_performance_writer::write(
const track_state_container_types::const_view& track_states_view,
const event_map2& evt_map) {
std::vector<std::vector<measurement>> tracks =
prepare_data(track_states_view);
write_common(tracks, evt_map);
}

void finding_performance_writer::finalize() {

#ifdef TRACCC_HAVE_ROOT
Expand Down

0 comments on commit 5f0fa34

Please sign in to comment.