Skip to content

Commit

Permalink
fix: Stitch tracks correctly after second pass in Examples Track Find…
Browse files Browse the repository at this point in the history
…ing (#3597)

Stich tracks from first measurement not from first state otherwise we can end up with double counting material states.

discovered in #3391
  • Loading branch information
andiwand authored Sep 9, 2024
1 parent 13199a2 commit d80f91f
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,9 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
// has already been updated
seedNumber(trackCandidate) = nSeed - 1;

auto firstState = *std::next(trackCandidate.trackStatesReversed().begin(),
trackCandidate.nTrackStates() - 1);
assert(firstState.previous() == Acts::kTrackIndexInvalid);

if (m_cfg.twoWay) {
std::optional<Acts::VectorMultiTrajectory::TrackStateProxy>
firstMeasurement;
firstMeasurementOpt;
for (auto trackState : trackCandidate.trackStatesReversed()) {
bool isMeasurement = trackState.typeFlags().test(
Acts::TrackStateFlag::MeasurementFlag);
Expand All @@ -524,13 +520,15 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
// decrease resolution because only the smoothing corrected the very
// first prediction as filtering is not possible.
if (isMeasurement && !isOutlier) {
firstMeasurement = trackState;
firstMeasurementOpt = trackState;
}
}

if (firstMeasurement.has_value()) {
if (firstMeasurementOpt.has_value()) {
auto& firstMeasurement = firstMeasurementOpt.value();

Acts::BoundTrackParameters secondInitialParameters =
trackCandidate.createParametersFromState(*firstMeasurement);
trackCandidate.createParametersFromState(firstMeasurement);

auto secondRootBranch = tracksTemp.makeTrack();
secondRootBranch.copyFrom(trackCandidate, false);
Expand All @@ -542,6 +540,9 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
ACTS_WARNING("Second track finding failed for seed "
<< iSeed << " with error" << secondResult.error());
} else {
// store the original previous state to restore it later
auto originalFirstMeasurementPrevious = firstMeasurement.previous();

auto& secondTracksForSeed = secondResult.value();
for (auto& secondTrack : secondTracksForSeed) {
// TODO a copy of the track should not be necessary but is the
Expand All @@ -556,7 +557,7 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
// processed
secondTrackCopy.reverseTrackStates(true);

firstState.previous() =
firstMeasurement.previous() =
secondTrackCopy.outermostTrackState().index();

trackCandidate.copyFrom(secondTrackCopy, false);
Expand Down Expand Up @@ -609,6 +610,9 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {

++nSecond;
}

// restore the original previous state
firstMeasurement.previous() = originalFirstMeasurementPrevious;
}
}
}
Expand All @@ -617,7 +621,6 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
if (nSecond == 0) {
// restore the track to the original state
trackCandidate.copyFrom(firstTrack, false);
firstState.previous() = Acts::kTrackIndexInvalid;

auto firstExtrapolationResult =
Acts::extrapolateTrackToReferenceSurface(
Expand Down

0 comments on commit d80f91f

Please sign in to comment.