Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fitting performance writer by changing the measurement comparator #754

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/include/traccc/edm/measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ TRACCC_HOST_DEVICE inline bool operator<(const measurement& lhs,

if (lhs.surface_link != rhs.surface_link) {
return lhs.surface_link < rhs.surface_link;
} else if (math::fabs(lhs.local[0] - rhs.local[0]) > float_epsilon) {
return (lhs.local[0] < rhs.local[0]);
} else {
return (lhs.local[1] < rhs.local[1]);
} else if (lhs.local[0] != rhs.local[0]) {
return lhs.local[0] < rhs.local[0];
} else if (lhs.local[1] != rhs.local[1]) {
return lhs.local[1] < rhs.local[1];
} else if (lhs.variance[0] != rhs.variance[0]) {
return lhs.variance[0] < rhs.variance[0];
} else if (lhs.variance[1] != rhs.variance[1]) {
return lhs.variance[1] < rhs.variance[1];
}
return false;
}

/// Equality operator for measurements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ class fitting_performance_writer {
// Find the contributing particle
// @todo: Use identify_contributing_particles function
std::map<particle, std::size_t> contributing_particles =
meas_to_ptc_map[meas];
meas_to_ptc_map.at(meas);

const particle ptc = contributing_particles.begin()->first;

// Find the truth global position and momentum
const auto global_pos = meas_to_param_map[meas].first;
const auto global_mom = meas_to_param_map[meas].second;
const auto global_pos = meas_to_param_map.at(meas).first;
const auto global_mom = meas_to_param_map.at(meas).second;

const detray::tracking_surface sf{det, meas.surface_link};
using cxt_t = typename detector_t::geometry_context;
Expand Down
28 changes: 18 additions & 10 deletions performance/src/utils/event_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,17 @@ void event_data::setup_csv(bool use_acts_geom_source, const detector_type* det,
auto hid = csv_meas_hit_ids[meas_id].hit_id;
const auto& iohit = csv_hits[hid];

const auto meas = m_measurement_map[meas_id];
const auto meas = m_measurement_map.at(meas_id);
meas_to_cluster_map[meas].push_back(iocell);

const auto& ptc = m_particle_map[iohit.particle_id];
const auto& ptc = m_particle_map.at(iohit.particle_id);
m_cell_to_particle_map[iocell] = ptc;
}

// Fill the meas_to_particle_map
for (auto const& [ms, cluster] : meas_to_cluster_map) {
for (const auto& cell : cluster) {
const auto& ptc = m_cell_to_particle_map[cell];
const auto& ptc = m_cell_to_particle_map.at(cell);
m_meas_to_ptc_map[ms][ptc]++;
}
}
Expand All @@ -209,18 +209,19 @@ void event_data::setup_csv(bool use_acts_geom_source, const detector_type* det,
for (const auto& iomeas : csv_measurements) {

// Hit index
const auto hid = csv_meas_hit_ids[iomeas.measurement_id].hit_id;
const auto hid = csv_meas_hit_ids.at(iomeas.measurement_id).hit_id;

// Make spacepoint
const auto& iohit = csv_hits[hid];
const auto& iohit = csv_hits.at(hid);
point3 global_pos{iohit.tx, iohit.ty, iohit.tz};
point3 global_mom{iohit.tpx, iohit.tpy, iohit.tpz};

// Make particle
const auto& ptc = m_particle_map[iohit.particle_id];
const auto& ptc = m_particle_map.at(iohit.particle_id);

// Construct the measurement object.
traccc::measurement meas = m_measurement_map[iomeas.measurement_id];
const traccc::measurement& meas =
m_measurement_map.at(iomeas.measurement_id);

// Fill measurement to truth global position and momentum map
m_meas_to_param_map[meas] = std::make_pair(global_pos, global_mom);
Expand All @@ -229,8 +230,15 @@ void event_data::setup_csv(bool use_acts_geom_source, const detector_type* det,
m_ptc_to_meas_map[ptc].push_back(meas);

if (!include_silicon_cells) {
// Fill measurement to particle map
m_meas_to_ptc_map[meas][ptc]++;
auto insert_return = m_meas_to_ptc_map.insert({meas, {}});
if (insert_return.second == false) {
throw std::runtime_error(
"The new measurement should not exist in the "
"measurement-to-particle map");
}
// Each measurement is created by a single particle unless we use
// the clusterization results
(*(insert_return.first)).second[ptc] = 1u;
}
}
}
Expand Down Expand Up @@ -305,7 +313,7 @@ track_candidate_container_types::host event_data::generate_truth_candidates(

for (auto const& [ptc, measurements] : m_ptc_to_meas_map) {

const auto& param = m_meas_to_param_map[measurements[0]];
const auto& param = m_meas_to_param_map.at(measurements[0]);
const free_track_parameters free_param(param.first, 0.f, param.second,
ptc.charge);

Expand Down
25 changes: 18 additions & 7 deletions tests/cuda/test_clusterization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "traccc/cuda/clusterization/clusterization_algorithm.hpp"
#include "traccc/definitions/common.hpp"
#include "traccc/geometry/silicon_detector_description.hpp"
#include "traccc/performance/collection_comparator.hpp"

// VecMem include(s).
#include <vecmem/memory/cuda/managed_memory_resource.hpp>
Expand Down Expand Up @@ -63,15 +64,25 @@ TEST(CUDAClustering, SingleModule) {

// Check the results
ASSERT_EQ(copy.get_size(measurements_buffer), 2u);
std::set<measurement> test;
test.insert(measurements[0]);
test.insert(measurements[1]);

std::set<measurement> ref;
ref.insert(
measurement_collection_types::host references;
references.push_back(
{{2.5f, 2.5f}, {0.75f, 0.0833333f}, detray::geometry::barcode{0u}});
ref.insert(
references.push_back(
{{6.5f, 5.5f}, {0.483333f, 0.483333f}, detray::geometry::barcode{0u}});

EXPECT_EQ(test, ref);
for (const auto& test : measurements) {
// 0.01 % uncertainty
auto iso = traccc::details::is_same_object<measurement>(test, 0.0001f);
bool matched = false;

for (const auto& ref : references) {
if (iso(ref)) {
matched = true;
break;
}
}

ASSERT_TRUE(matched);
}
}
25 changes: 18 additions & 7 deletions tests/sycl/test_clusterization.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "tests/cca_test.hpp"
#include "traccc/definitions/common.hpp"
#include "traccc/geometry/silicon_detector_description.hpp"
#include "traccc/performance/collection_comparator.hpp"
#include "traccc/sycl/clusterization/clusterization_algorithm.hpp"

// VecMem include(s).
Expand Down Expand Up @@ -77,15 +78,25 @@ TEST(SYCLClustering, SingleModule) {

// Check the results
EXPECT_EQ(copy.get_size(measurements_buffer), 2u);
std::set<measurement> test;
test.insert(measurements[0]);
test.insert(measurements[1]);

std::set<measurement> ref;
ref.insert(
measurement_collection_types::host references;
references.push_back(
{{2.5f, 2.5f}, {0.75f, 0.0833333f}, detray::geometry::barcode{0u}});
ref.insert(
references.push_back(
{{6.5f, 5.5f}, {0.483333f, 0.483333f}, detray::geometry::barcode{0u}});

EXPECT_EQ(test, ref);
for (const auto& test : measurements) {
// 0.01 % uncertainty
auto iso = traccc::details::is_same_object<measurement>(test, 0.0001f);
bool matched = false;

for (const auto& ref : references) {
if (iso(ref)) {
matched = true;
break;
}
}

ASSERT_TRUE(matched);
}
}
Loading