Skip to content

Commit

Permalink
Greedy ambiguity resolution from ACTS (acts-project#515)
Browse files Browse the repository at this point in the history
* Seeding example simple copy

* Add greedy ambiguity resolution to seeding_example

* Rename seeding_example_greedy_ambiguity_resolution

* Greedy Solver: call track_states.size() only once

Co-authored-by: beomki-yeo <[email protected]>

* Greedy Solver: call initial_track_states.size() only once

Co-authored-by: beomki-yeo <[email protected]>

* Use traccc::scalar instead of float

* Fix variable declaration (n_initial_track_states)

* Add an option to skip the ambiguity solver

* Merge greedy solver into seeding_example.cpp

* Fix: remove old greedy resolution file on CMake

* Clang-format on common_options.cpp

* Split greedy solver into header + implementation

Implementation path:
core/src/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.cpp

Header path:
core/include/traccc/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp

* Merge greedy solver constructors

Co-authored-by: Attila Krasznahorkay <[email protected]>

* Improve greedy solver logger

---------

Co-authored-by: beomki-yeo <[email protected]>
Co-authored-by: Attila Krasznahorkay <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2024
1 parent dd3f55d commit fd145d8
Show file tree
Hide file tree
Showing 8 changed files with 615 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ traccc_add_library( traccc_core core TYPE SHARED
"include/traccc/seeding/seed_finding.hpp"
"src/seeding/seed_finding.cpp"
"include/traccc/seeding/spacepoint_binning.hpp"
"src/seeding/spacepoint_binning.cpp" )
"src/seeding/spacepoint_binning.cpp"
# Ambiguity resolution
"include/traccc/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp"
"src/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.cpp" )
target_link_libraries( traccc_core
PUBLIC Eigen3::Eigen vecmem::core detray::core traccc::Thrust
traccc::algebra )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// System include
#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <unordered_map>
#include <vector>

// VecMem include(s).
#include <vecmem/containers/vector.hpp>

// Project include(s).
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/edm/track_candidate.hpp"
#include "traccc/edm/track_state.hpp"
#include "traccc/utils/algorithm.hpp"

// Greedy ambiguity resolution adapted from ACTS code

namespace traccc {

/// Evicts tracks that seem to be duplicates or fakes. This algorithm takes a
/// greedy approach in the sense that it will remove the track which looks "most
/// duplicate/fake" first and continues the same process with the rest. That
/// process continues until the final state conditions are met.
///
/// The implementation works as follows:
/// 1) Calculate shared hits per track.
/// 2) If the maximum shared hits criteria is met, we are done.
/// This is the configurable amount of shared hits we are ok with
/// in our experiment.
/// 3) Else, remove the track with the highest relative shared hits (i.e.
/// shared hits / hits).
/// 4) Back to square 1.
class greedy_ambiguity_resolution_algorithm
: public algorithm<track_state_container_types::host(
const typename track_state_container_types::host&)> {

public:
struct config_t {

config_t(){};

/// Maximum amount of shared hits per track. One (1) means "no shared
/// hit allowed".
std::uint32_t maximum_shared_hits = 1;

/// Maximum number of iterations.
std::uint32_t maximum_iterations = 1000000;

/// Minimum number of measurement to form a track.
std::size_t n_measurements_min = 3;

// True if obvious errors should be checked after the completion
// of the algorithm.
bool check_obvious_errs = true;

bool verbose_info = true;
bool verbose_error = true;
bool verbose_flood = false;
};

struct state_t {
std::size_t number_of_tracks{};

/// For this whole comment section, track_index refers to the index of a
/// track in the initial input container.
///
/// There is no (track_id) in this algorithm, only (track_index).

/// Associates each track_index with the track's chi2 value
std::vector<traccc::scalar> track_chi2;

/// Associates each track_index to the track's (measurement_id)s list
std::vector<std::vector<std::size_t>> measurements_per_track;

/// Associates each measurement_id to a set of (track_index)es sharing
/// it
std::unordered_map<std::size_t, std::set<std::size_t>>
tracks_per_measurement;

/// Associates each track_index to its number of shared measurements
/// (among other tracks)
std::vector<std::size_t> shared_measurements_per_track;

/// Keeps the selected tracks indexes that have not (yet) been removed
/// by the algorithm
std::set<std::size_t> selected_tracks;
};

/// Constructor for the greedy ambiguity resolution algorithm
///
/// @param cfg Configuration object
// greedy_ambiguity_resolution_algorithm(const config_type& cfg) :
// _config(cfg) {}
greedy_ambiguity_resolution_algorithm(const config_t cfg = {})
: _config{cfg} {}

/// Run the algorithm
///
/// @param track_states the container of the fitted track parameters
/// @return the container without ambiguous tracks
track_state_container_types::host operator()(
const typename track_state_container_types::host& track_states)
const override;

private:
/// Computes the initial state for the input data. This function accumulates
/// information that will later be used to accelerate the ambiguity
/// resolution.
///
/// @param track_states The input track container (output of the fitting
/// algorithm).
/// @param state An empty state object which is expected to be default
/// constructed.
void compute_initial_state(
const typename track_state_container_types::host& track_states,
state_t& state) const;

/// Updates the state iteratively by evicting one track after the other
/// until the final state conditions are met.
///
/// @param state A state object that was previously filled by the
/// initialization.
void resolve(state_t& state) const;

/// Check for obvious errors returned by the algorithm:
/// - Returned tracks should be independent of each other: they should share
/// a maximum of (_config.maximum_shared_hits - 1) hits per track.
/// - Each removed track should share at least (_config.maximum_shared_hits)
/// with another initial track.
///
/// @param initial_track_states The input track container, as given to
/// compute_initial_state.
/// @param final_state The state object after the resolve method has been
/// called.
bool check_obvious_errors(
const typename track_state_container_types::host& initial_track_states,
state_t& final_state) const;

config_t _config;
};

} // namespace traccc
3 changes: 3 additions & 0 deletions core/include/traccc/edm/measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct measurement {
/// Geometry ID
detray::geometry::barcode surface_link;

// Unique measurement ID
std::size_t measurement_id = 0;

/// Link to Module vector index
using link_type = cell_module_collection_types::view::size_type;
link_type module_link = 0;
Expand Down
Loading

0 comments on commit fd145d8

Please sign in to comment.