diff --git a/examples/run/cpu/seeding_example.cpp b/examples/run/cpu/seeding_example.cpp index ee7d6a6aae..d1a49cede0 100644 --- a/examples/run/cpu/seeding_example.cpp +++ b/examples/run/cpu/seeding_example.cpp @@ -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; @@ -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(); @@ -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; @@ -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; diff --git a/performance/include/traccc/efficiency/finding_performance_writer.hpp b/performance/include/traccc/efficiency/finding_performance_writer.hpp index a9d85803d5..fa31f73a4b 100644 --- a/performance/include/traccc/efficiency/finding_performance_writer.hpp +++ b/performance/include/traccc/efficiency/finding_performance_writer.hpp @@ -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). @@ -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 @@ -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: @@ -72,6 +78,10 @@ class finding_performance_writer { /// Opaque data members for the class std::unique_ptr m_data; + /// Common method to both track finding and ambiguity resolution + void write_common(const std::vector>& tracks, + const event_map2& evt_map); + }; // class finding_performance_writer } // namespace traccc diff --git a/performance/src/efficiency/finding_performance_writer.cpp b/performance/src/efficiency/finding_performance_writer.cpp index 158e5f60e3..be8d5ad2ae 100644 --- a/performance/src/efficiency/finding_performance_writer.cpp +++ b/performance/src/efficiency/finding_performance_writer.cpp @@ -52,24 +52,27 @@ finding_performance_writer::finding_performance_writer(const config& cfg) : m_cfg(cfg), m_data(std::make_unique(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 match_counter; +// For track finding +std::vector> prepare_data( + const track_candidate_container_types::const_view& track_candidates_view) { + std::vector> 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; @@ -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> prepare_data( + const track_state_container_types::const_view& track_states_view) { + std::vector> 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 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>& tracks, + const event_map2& evt_map) { + + std::map 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& measurements = tracks[i]; // Check which particle matches this seed. std::vector particle_hit_counts = @@ -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> 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> tracks = + prepare_data(track_states_view); + write_common(tracks, evt_map); +} + void finding_performance_writer::finalize() { #ifdef TRACCC_HAVE_ROOT