Skip to content

Commit

Permalink
fix: ambiguity resolution for 0 tracks (#2070)
Browse files Browse the repository at this point in the history
0 tracks as input resulted in UB. this PR is fixing that

also I bumped into the same boost bug as in #2049 and worked around it again

fixes #2055
  • Loading branch information
andiwand committed Apr 27, 2023
1 parent 2b5457f commit 1f7a8f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct State {
State computeInitialState(const ActsExamples::ConstTrackContainer& tracks,
std::size_t nMeasurementsMin) {
State state;

for (const auto& track : tracks) {
auto trajState = Acts::MultiTrajectoryHelpers::trajectoryState(
tracks.trackStateContainer(), track.tipIndex());
Expand Down Expand Up @@ -120,8 +121,13 @@ void removeTrack(State& state, std::size_t iTrack) {
ActsExamples::ProcessCode ActsExamples::AmbiguityResolutionAlgorithm::execute(
const AlgorithmContext& ctx) const {
const auto& tracks = m_inputTracks(ctx);

ACTS_VERBOSE("number of input tracks " << tracks.size());

auto state = computeInitialState(tracks, m_cfg.nMeasurementsMin);

ACTS_VERBOSE("state initialized");

auto sharedMeasurementsComperator = [&state](std::size_t a, std::size_t b) {
return state.sharedMeasurementsPerTrack[a] <
state.sharedMeasurementsPerTrack[b];
Expand All @@ -139,6 +145,11 @@ ActsExamples::ProcessCode ActsExamples::AmbiguityResolutionAlgorithm::execute(
};

for (std::size_t i = 0; i < m_cfg.maximumIterations; ++i) {
if (state.selectedTracks.empty()) {
ACTS_VERBOSE("no tracks left - exit loop");
break;
}

auto maximumSharedMeasurements = *std::max_element(
state.selectedTracks.begin(), state.selectedTracks.end(),
sharedMeasurementsComperator);
Expand All @@ -158,7 +169,7 @@ ActsExamples::ProcessCode ActsExamples::AmbiguityResolutionAlgorithm::execute(
}

ACTS_INFO("Resolved to " << state.selectedTracks.size() << " tracks from "
<< state.trackTips.size());
<< tracks.size());

std::shared_ptr<Acts::ConstVectorMultiTrajectory> trackStateContainer =
tracks.trackStateContainerHolder();
Expand Down
6 changes: 6 additions & 0 deletions Examples/Framework/include/ActsExamples/EventData/Index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ inline boost::container::flat_multimap<value_t, Index> invertIndexMultimap(

// adopting the unordered sequence will reestablish the correct order
InverseMultimap inverse;
#if BOOST_VERSION < 107800
for (const auto& i : unordered) {
inverse.insert(i);
}
#else
inverse.insert(unordered.begin(), unordered.end());
#endif
return inverse;
}

Expand Down

0 comments on commit 1f7a8f4

Please sign in to comment.