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

refactor: Rework tracklet handling in Examples track finding #3587

Merged
merged 2 commits into from
Sep 4, 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
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
Loading