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: Stitch tracks correctly after second pass in Examples Track Finding #3597

Merged
merged 3 commits into from
Sep 9, 2024
Merged
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
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
Loading