Skip to content

Commit

Permalink
refactor: Rework tracklet handling in Examples track finding (#3587)
Browse files Browse the repository at this point in the history
Reworks the tracklet handling in the Examples track finding algorithm a bit. The extrapolation will now be done anyways if the CKF did not do it which can happen in case the branch stopper stops and keeps a tracklet. Instead of resetting parts of the track quantities here and there we now copy them explicitly from the previous known and desired state.

branched out from #3534
  • Loading branch information
andiwand authored Sep 4, 2024
1 parent 56b8fb4 commit b2cd8fb
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
}
});

Acts::calculateTrackQuantities(track);

if (m_trackSelector.has_value() && !m_trackSelector->isValidTrack(track)) {
return;
}
Expand Down Expand Up @@ -505,6 +507,10 @@ 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;
Expand Down Expand Up @@ -532,18 +538,8 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
ACTS_WARNING("Second track finding failed for seed "
<< iSeed << " with error" << secondResult.error());
} else {
auto firstState =
*std::next(trackCandidate.trackStatesReversed().begin(),
trackCandidate.nTrackStates() - 1);
assert(firstState.previous() == Acts::kTrackIndexInvalid);

auto& secondTracksForSeed = secondResult.value();
for (auto& secondTrack : secondTracksForSeed) {
if (!secondTrack.hasReferenceSurface()) {
ACTS_WARNING("Second track has no reference surface.");
continue;
}

// TODO a copy of the track should not be necessary but is the
// safest way with the current EDM
// TODO a lightweight copy without copying all the track state
Expand All @@ -559,17 +555,19 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
firstState.previous() =
secondTrackCopy.outermostTrackState().index();

trackCandidate.copyFrom(secondTrackCopy, false);

// finalize the track candidate

bool doExtrapolate = true;

if (!m_cfg.reverseSearch) {
// these parameters are already extrapolated by the CKF and have
// the optimal resolution. note that we did not smooth all the
// states.

trackCandidate.parameters() = secondTrackCopy.parameters();
trackCandidate.covariance() = secondTrackCopy.covariance();
trackCandidate.setReferenceSurface(
secondTrackCopy.referenceSurface().getSharedPtr());
// only extrapolate if we did not do it already
doExtrapolate = !trackCandidate.hasReferenceSurface();
} else {
// smooth the full track and extrapolate to the reference

Expand All @@ -585,7 +583,9 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
}

trackCandidate.reverseTrackStates(true);
}

if (doExtrapolate) {
auto secondExtrapolationResult =
Acts::extrapolateTrackToReferenceSurface(
trackCandidate, *pSurface, extrapolator,
Expand All @@ -601,23 +601,20 @@ ProcessCode TrackFindingAlgorithm::execute(const AlgorithmContext& ctx) const {
}
}

Acts::calculateTrackQuantities(trackCandidate);

addTrack(trackCandidate);

++nSecond;
}

// restore `trackCandidate` to its original state in case we need it
// again
firstState.previous() = Acts::kTrackIndexInvalid;
Acts::calculateTrackQuantities(trackCandidate);
}
}
}

// if no second track was found, we will use only the first track
if (nSecond == 0) {
// restore the track to the original state
trackCandidate.copyFrom(firstTrack, false);
firstState.previous() = Acts::kTrackIndexInvalid;

auto firstExtrapolationResult =
Acts::extrapolateTrackToReferenceSurface(
trackCandidate, *pSurface, extrapolator, extrapolationOptions,
Expand Down

0 comments on commit b2cd8fb

Please sign in to comment.