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

Cell EDM Rewrite, main branch (2024.09.18.) #712

Merged
merged 17 commits into from
Oct 4, 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ option( TRACCC_USE_SYSTEM_VECMEM
${TRACCC_USE_SYSTEM_LIBS} )
if( TRACCC_SETUP_VECMEM )
if( TRACCC_USE_SYSTEM_VECMEM )
find_package( vecmem 1.8.0 REQUIRED )
find_package( vecmem 1.9.0 REQUIRED )
else()
add_subdirectory( extern/vecmem )
# Make the "VecMem language code" available for the whole project.
Expand Down
5 changes: 3 additions & 2 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ traccc_add_library( traccc_core core TYPE SHARED
"include/traccc/edm/details/container_element.hpp"
"include/traccc/edm/details/device_container.hpp"
"include/traccc/edm/details/host_container.hpp"
"include/traccc/edm/cluster.hpp"
"include/traccc/edm/spacepoint.hpp"
"include/traccc/edm/measurement.hpp"
"include/traccc/edm/particle.hpp"
Expand All @@ -30,7 +29,9 @@ traccc_add_library( traccc_core core TYPE SHARED
"include/traccc/edm/seed.hpp"
"include/traccc/edm/track_candidate.hpp"
"include/traccc/edm/track_state.hpp"
"include/traccc/edm/cell.hpp"
"include/traccc/edm/silicon_cell_collection.hpp"
"include/traccc/edm/impl/silicon_cell_collection.ipp"
"include/traccc/edm/silicon_cluster_collection.hpp"
# Geometry description.
"include/traccc/geometry/detector.hpp"
"include/traccc/geometry/module_map.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// Library include(s).
#include "traccc/clusterization/measurement_creation_algorithm.hpp"
#include "traccc/clusterization/sparse_ccl_algorithm.hpp"
#include "traccc/edm/cell.hpp"
#include "traccc/edm/measurement.hpp"
#include "traccc/edm/silicon_cell_collection.hpp"
#include "traccc/geometry/silicon_detector_description.hpp"
#include "traccc/utils/algorithm.hpp"

Expand All @@ -31,7 +31,7 @@ namespace traccc::host {
///
class clusterization_algorithm
: public algorithm<measurement_collection_types::host(
const cell_collection_types::const_view&,
const edm::silicon_cell_collection::const_view&,
const silicon_detector_description::const_view&)> {

public:
Expand All @@ -50,7 +50,7 @@ class clusterization_algorithm
/// @return The measurements reconstructed for every detector module
///
output_type operator()(
const cell_collection_types::const_view& cells_view,
const edm::silicon_cell_collection::const_view& cells_view,
const silicon_detector_description::const_view& dd_view) const override;

private:
Expand Down
38 changes: 25 additions & 13 deletions core/include/traccc/clusterization/details/measurement_creation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
// Project include(s).
#include "traccc/definitions/primitives.hpp"
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/edm/cell.hpp"
#include "traccc/edm/measurement.hpp"
#include "traccc/edm/silicon_cell_collection.hpp"
#include "traccc/edm/silicon_cluster_collection.hpp"
#include "traccc/geometry/silicon_detector_description.hpp"

namespace traccc::details {
Expand All @@ -21,24 +22,32 @@ TRACCC_HOST_DEVICE
inline scalar signal_cell_modelling(
scalar signal_in, const silicon_detector_description::const_device&);

/// Function for pixel segmentation
TRACCC_HOST_DEVICE
inline vector2 position_from_cell(
const cell& cell,
/// Get the local position of a cell on a module
///
/// @param cell The cell to get the position of
/// @param det_descr The (silicon) detector description
/// @return The local position of the cell
///
template <typename T>
TRACCC_HOST_DEVICE inline vector2 position_from_cell(
const edm::silicon_cell<T>& cell,
const silicon_detector_description::const_device& det_descr);

/// Function used for calculating the properties of the cluster during
/// measurement creation
///
/// @param[in] cluster The vector of cells describing the identified cluster
/// @param[in] det_descr The detector description
/// @param[out] mean The mean position of the cluster/measurement
/// @param[out] var The variation on the mean position of the
/// cluster/measurement
/// @param[in] cluster The silicon cluster to calculate the properties of
/// @param[in] cells All silicon cells in the event
/// @param[in] det_descr The detector description
/// @param[out] mean The mean position of the cluster/measurement
/// @param[out] var The variation on the mean position of the
/// cluster/measurement
/// @param[out] totalWeight The total weight of the cluster/measurement
///
template <typename T>
TRACCC_HOST_DEVICE inline void calc_cluster_properties(
const cell_collection_types::const_device& cluster,
const edm::silicon_cluster<T>& cluster,
const edm::silicon_cell_collection::const_device& cells,
const silicon_detector_description::const_device& det_descr, point2& mean,
point2& var, scalar& totalWeight);

Expand All @@ -48,13 +57,16 @@ TRACCC_HOST_DEVICE inline void calc_cluster_properties(
/// @param[out] measurements Measurement collection where the measurement is to
/// be filled
/// @param[in] index Index of the measurement object to fill
/// @param[in] cluster Cell vector describing the measurement's cluster
/// @param[in] cluster The silicon cluster to turn into a measurement
/// @param[in] cells All silicon cells in the event
/// @param[in] det_descr Detector description
///
template <typename T>
TRACCC_HOST_DEVICE inline void fill_measurement(
measurement_collection_types::device& measurements,
measurement_collection_types::device::size_type index,
const cell_collection_types::const_device& cluster,
const edm::silicon_cluster<T>& cluster,
const edm::silicon_cell_collection::const_device& cells,
const silicon_detector_description::const_device& det_descr);

} // namespace traccc::details
Expand Down
14 changes: 8 additions & 6 deletions core/include/traccc/clusterization/details/sparse_ccl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// Library include(s).
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/edm/cell.hpp"
#include "traccc/edm/silicon_cell_collection.hpp"

// VecMem include(s).
#include <vecmem/containers/device_vector.hpp>
Expand Down Expand Up @@ -47,8 +47,9 @@ TRACCC_HOST_DEVICE inline unsigned int make_union(
///
/// @return boolan to indicate 8-cell connectivity
///
TRACCC_HOST_DEVICE inline bool is_adjacent(const traccc::cell& a,
const traccc::cell& b);
template <typename T1, typename T2>
TRACCC_HOST_DEVICE inline bool is_adjacent(const edm::silicon_cell<T1>& a,
const edm::silicon_cell<T2>& b);

/// Helper method to find define distance,
/// does not need abs, as channels are sorted in
Expand All @@ -59,8 +60,9 @@ TRACCC_HOST_DEVICE inline bool is_adjacent(const traccc::cell& a,
///
/// @return boolan to indicate !8-cell connectivity
///
TRACCC_HOST_DEVICE inline bool is_far_enough(const traccc::cell& a,
const traccc::cell& b);
template <typename T1, typename T2>
TRACCC_HOST_DEVICE inline bool is_far_enough(const edm::silicon_cell<T1>& a,
const edm::silicon_cell<T2>& b);

/// Sparce CCL algorithm
///
Expand All @@ -70,7 +72,7 @@ TRACCC_HOST_DEVICE inline bool is_far_enough(const traccc::cell& a,
/// @return number of clusters
///
TRACCC_HOST_DEVICE inline unsigned int sparse_ccl(
const cell_collection_types::const_device& cells,
const edm::silicon_cell_collection::const_device& cells,
vecmem::device_vector<unsigned int>& labels);

} // namespace traccc::details
Expand Down
77 changes: 49 additions & 28 deletions core/include/traccc/clusterization/impl/measurement_creation.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,42 @@ inline scalar signal_cell_modelling(
return signal_in;
}

TRACCC_HOST_DEVICE
inline vector2 position_from_cell(
const cell& cell,
template <typename T>
TRACCC_HOST_DEVICE inline vector2 position_from_cell(
const edm::silicon_cell<T>& cell,
const silicon_detector_description::const_device& det_descr) {

// Retrieve the specific values based on module idx
const cell::link_type module_link = cell.module_link;
return {
det_descr.reference_x().at(module_link) +
(scalar{0.5} + cell.channel0) * det_descr.pitch_x().at(module_link),
det_descr.reference_y().at(module_link) +
(scalar{0.5} + cell.channel1) *
det_descr.pitch_y().at(module_link)};
// The detector description for the module that the cell is on.
const auto module_dd = det_descr.at(cell.module_index());
// Calculate / construct the local cell position.
return {module_dd.reference_x() +
(scalar{0.5} + cell.channel0()) * module_dd.pitch_x(),
module_dd.reference_y() +
(scalar{0.5} + cell.channel1()) * module_dd.pitch_y()};
}

template <typename T>
TRACCC_HOST_DEVICE inline void calc_cluster_properties(
const cell_collection_types::const_device& cluster,
const edm::silicon_cluster<T>& cluster,
const edm::silicon_cell_collection::const_device& cells,
const silicon_detector_description::const_device& det_descr, point2& mean,
point2& var, scalar& totalWeight) {

point2 offset{0., 0.};
bool first_processed = false;

// Loop over the cells of the cluster.
for (const cell& cell : cluster) {
// Loop over the cell indices of the cluster.
for (const unsigned int cell_idx : cluster.cell_indices()) {

// The cell object.
const auto cell = cells.at(cell_idx);

// Translate the cell readout value into a weight.
const scalar weight = signal_cell_modelling(cell.activation, det_descr);
const scalar weight =
signal_cell_modelling(cell.activation(), det_descr);

// Only consider cells over a minimum threshold.
if (weight > det_descr.threshold().at(cell.module_link)) {
if (weight > det_descr.threshold().at(cell.module_index())) {

// Update all output properties with this cell.
totalWeight += weight;
Expand Down Expand Up @@ -76,10 +81,12 @@ TRACCC_HOST_DEVICE inline void calc_cluster_properties(
mean = mean + offset;
}

template <typename T>
TRACCC_HOST_DEVICE inline void fill_measurement(
measurement_collection_types::device& measurements,
const measurement_collection_types::device::size_type index,
const cell_collection_types::const_device& cluster,
measurement_collection_types::device::size_type index,
const edm::silicon_cluster<T>& cluster,
const edm::silicon_cell_collection::const_device& cells,
const silicon_detector_description::const_device& det_descr) {

// To calculate the mean and variance with high numerical stability
Expand All @@ -92,38 +99,52 @@ TRACCC_HOST_DEVICE inline void fill_measurement(
// [2] The Art of Computer Programming, Donald E. Knuth, second
// edition, chapter 4.2.2.

// A security check.
assert(cluster.empty() == false);
// Security checks.
assert(cluster.cell_indices().empty() == false);
assert([&]() {
const unsigned int module_idx =
cells.module_index().at(cluster.cell_indices().front());
for (const unsigned int cell_idx : cluster.cell_indices()) {
if (cells.module_index().at(cell_idx) != module_idx) {
return false;
}
}
return true;
}() == true);

// Calculate the cluster properties
scalar totalWeight = 0.f;
point2 mean{0.f, 0.f}, var{0.f, 0.f};
calc_cluster_properties(cluster, det_descr, mean, var, totalWeight);
calc_cluster_properties(cluster, cells, det_descr, mean, var, totalWeight);

assert(totalWeight > 0.f);

// Access the measurement in question.
measurement& m = measurements[index];

// The index of the module the cluster is on.
const cell::link_type module_link = cluster.at(0).module_link;

m.module_link = module_link;
m.surface_link = det_descr.geometry_id().at(module_link);
const unsigned int module_idx =
cells.module_index().at(cluster.cell_indices().front());
// The detector description for the module that the cluster is on.
const auto module_dd = det_descr.at(module_idx);

// Fill the measurement object.
m.module_link = module_idx;
m.surface_link = module_dd.geometry_id();
// normalize the cell position
m.local = mean;

// plus pitch^2 / 12
const scalar pitch_x = det_descr.pitch_x().at(module_link);
const scalar pitch_y = det_descr.pitch_y().at(module_link);
const scalar pitch_x = module_dd.pitch_x();
const scalar pitch_y = module_dd.pitch_y();
m.variance = var + point2{pitch_x * pitch_x / static_cast<scalar>(12.),
pitch_y * pitch_y / static_cast<scalar>(12.)};

// For the ambiguity resolution algorithm, give a unique measurement ID
m.measurement_id = index;

// Set the measurement dimensionality.
m.meas_dim = det_descr.dimensions().at(module_link);
m.meas_dim = module_dd.dimensions();
}

} // namespace traccc::details
24 changes: 14 additions & 10 deletions core/include/traccc/clusterization/impl/sparse_ccl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,27 @@ TRACCC_HOST_DEVICE inline unsigned int make_union(
return e;
}

TRACCC_HOST_DEVICE inline bool is_adjacent(const traccc::cell& a,
const traccc::cell& b) {
template <typename T1, typename T2>
TRACCC_HOST_DEVICE inline bool is_adjacent(const edm::silicon_cell<T1>& a,
const edm::silicon_cell<T2>& b) {

return (a.channel0 - b.channel0) * (a.channel0 - b.channel0) <= 1 &&
(a.channel1 - b.channel1) * (a.channel1 - b.channel1) <= 1 &&
a.module_link == b.module_link;
return (a.channel0() - b.channel0()) * (a.channel0() - b.channel0()) <= 1 &&
(a.channel1() - b.channel1()) * (a.channel1() - b.channel1()) <= 1 &&
a.module_index() == b.module_index();
}

TRACCC_HOST_DEVICE inline bool is_far_enough(const traccc::cell& a,
const traccc::cell& b) {
template <typename T1, typename T2>
TRACCC_HOST_DEVICE inline bool is_far_enough(const edm::silicon_cell<T1>& a,
const edm::silicon_cell<T2>& b) {

assert((a.channel1 >= b.channel1) || (a.module_link != b.module_link));
return (a.channel1 > (b.channel1 + 1)) || (a.module_link != b.module_link);
assert((a.channel1() >= b.channel1()) ||
(a.module_index() != b.module_index()));
return (a.channel1() > (b.channel1() + 1)) ||
(a.module_index() != b.module_index());
}

TRACCC_HOST_DEVICE inline unsigned int sparse_ccl(
const cell_collection_types::const_device& cells,
const edm::silicon_cell_collection::const_device& cells,
vecmem::device_vector<unsigned int>& labels) {

unsigned int nlabels = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#pragma once

// Library include(s).
#include "traccc/edm/cluster.hpp"
#include "traccc/edm/measurement.hpp"
#include "traccc/edm/silicon_cell_collection.hpp"
#include "traccc/edm/silicon_cluster_collection.hpp"
#include "traccc/geometry/silicon_detector_description.hpp"
#include "traccc/utils/algorithm.hpp"

Expand All @@ -29,7 +30,8 @@ namespace traccc::host {
///
class measurement_creation_algorithm
: public algorithm<measurement_collection_types::host(
const cluster_container_types::const_view &,
const edm::silicon_cell_collection::const_view &,
const edm::silicon_cluster_collection::const_view &,
const silicon_detector_description::const_view &)> {

public:
Expand All @@ -42,12 +44,14 @@ class measurement_creation_algorithm
/// Callable operator for the connected component, based on one single
/// module
///
/// @param cells_view Cells that were clusterized
/// @param clusters_view Clusters to turn into measurements
/// @param dd_view The detector description
/// @return The reconstructed measurement collection
///
output_type operator()(
const cluster_container_types::const_view &clusters_view,
const edm::silicon_cell_collection::const_view &cells_view,
const edm::silicon_cluster_collection::const_view &clusters_view,
const silicon_detector_description::const_view &dd_view) const override;

private:
Expand Down
Loading
Loading