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: full chain vertexing [backport #1299 to develop/v19.x] #1439

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ Acts::AdaptiveMultiVertexFitter<input_track_t, linearizer_t>::fitImpl(
state.vtxInfoMap[currentVtx].constraintVertex.fitQuality());
currentVtx->setFullCovariance(
state.vtxInfoMap[currentVtx].constraintVertex.fullCovariance());
}

else if (currentVtx->fullCovariance() == SymMatrix4::Zero()) {
} else if (currentVtx->fullCovariance() == SymMatrix4::Zero()) {
return VertexingError::NoCovariance;
}
double weight =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class TrackFindingAlgorithm final : public BareAlgorithm {
std::string inputInitialTrackParameters;
/// Output find trajectories collection.
std::string outputTrajectories;
/// Output track parameters collection.
std::string outputTrackParameters;
/// Type erased track finder function.
std::shared_ptr<TrackFinderFunction> findTracks;
/// CKF measurement selector config
Expand Down
12 changes: 12 additions & 0 deletions Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ActsExamples::ProcessCode ActsExamples::TrackFindingAlgorithm::execute(
TrajectoriesContainer trajectories;
trajectories.reserve(initialParameters.size());

// Prepare the output data with TrackParameters
TrackParametersContainer trackParametersContainer;

// Construct a perigee surface as the target surface
auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
Acts::Vector3{0., 0., 0.});
Expand Down Expand Up @@ -103,6 +106,13 @@ ActsExamples::ProcessCode ActsExamples::TrackFindingAlgorithm::execute(
trajectories.emplace_back(trackFindingOutput.fittedStates,
trackFindingOutput.lastMeasurementIndices,
trackFindingOutput.fittedParameters);

const auto& traj = trajectories.back();
for (const auto tip : traj.tips()) {
if (traj.hasTrackParameters(tip)) {
trackParametersContainer.push_back(traj.trackParameters(tip));
}
}
} else {
ACTS_WARNING("Track finding failed for seed " << iseed << " with error"
<< result.error());
Expand All @@ -116,5 +126,7 @@ ActsExamples::ProcessCode ActsExamples::TrackFindingAlgorithm::execute(
<< " track candidates.");

ctx.eventStore.add(m_cfg.outputTrajectories, std::move(trajectories));
ctx.eventStore.add(m_cfg.outputTrackParameters,
std::move(trackParametersContainer));
return ActsExamples::ProcessCode::SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ ActsExamples::AdaptiveMultiVertexFinderAlgorithm::execute(
// find vertices and measure elapsed time
auto result = finder.find(inputTrackPointers, finderOpts, state);

if (not result.ok()) {
if (result.ok()) {
vertices = std::move(result.value());
} else {
ACTS_ERROR("Error in vertex finder: " << result.error().message());
return ProcessCode::ABORT;
}
vertices = *result;
}

auto t2 = std::chrono::high_resolution_clock::now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ ActsExamples::ProcessCode ActsExamples::IterativeVertexFinderAlgorithm::execute(
auto result = finder.find(inputTrackPointers, finderOpts, state);
auto t2 = std::chrono::high_resolution_clock::now();

if (not result.ok()) {
std::vector<Acts::Vertex<Acts::BoundTrackParameters>> vertices;
if (result.ok()) {
vertices = std::move(result.value());
} else {
ACTS_ERROR("Error in vertex finder: " << result.error().message());
return ProcessCode::ABORT;
}
auto vertices = *result;

// show some debug output
ACTS_INFO("Found " << vertices.size() << " vertices in event");
Expand Down
24 changes: 16 additions & 8 deletions Examples/Algorithms/Vertexing/src/VertexFitterAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ ActsExamples::ProcessCode ActsExamples::VertexFitterAlgorithm::execute(
inputTrackPtrCollection.clear();
inputTrackPtrCollection.reserve(protoVertex.size());
for (const auto& trackIdx : protoVertex) {
if (trackIdx >= trackParameters.size()) {
ACTS_ERROR("track parameters " << trackIdx << " does not exist");
continue;
}

inputTrackPtrCollection.push_back(&trackParameters[trackIdx]);
}

Expand All @@ -99,8 +104,7 @@ ActsExamples::ProcessCode ActsExamples::VertexFitterAlgorithm::execute(
if (fitRes.ok()) {
fittedVertices.push_back(*fitRes);
} else {
ACTS_ERROR("Error in vertex fit.");
ACTS_ERROR(fitRes.error().message());
ACTS_ERROR("Error in vertex fitter: " << fitRes.error().message());
}
} else {
// Vertex constraint
Expand All @@ -118,15 +122,19 @@ ActsExamples::ProcessCode ActsExamples::VertexFitterAlgorithm::execute(
if (fitRes.ok()) {
fittedVertices.push_back(*fitRes);
} else {
ACTS_ERROR("Error in vertex fit with constraint.");
ACTS_ERROR(fitRes.error().message());
ACTS_ERROR(
"Error in constrained vertex fitter: " << fitRes.error().message());
}
}

ACTS_DEBUG("Fitted Vertex "
<< fittedVertices.back().fullPosition().transpose());
ACTS_DEBUG(
"Tracks at fitted Vertex: " << fittedVertices.back().tracks().size());
if (fittedVertices.empty()) {
ACTS_DEBUG("No fitted vertex");
} else {
ACTS_DEBUG("Fitted Vertex "
<< fittedVertices.back().fullPosition().transpose());
ACTS_DEBUG(
"Tracks at fitted Vertex: " << fittedVertices.back().tracks().size());
}
}

ctx.eventStore.add(m_cfg.outputVertices, std::move(fittedVertices));
Expand Down
1 change: 1 addition & 0 deletions Examples/Framework/src/Framework/Sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ int ActsExamples::Sequencer::run() {
StopWatch sw(localClocksAlgorithms[ialgo++]);
ACTS_VERBOSE("Execute algorithm: " << alg->name());
if (alg->execute(++context) != ProcessCode::SUCCESS) {
ACTS_FATAL("Failed to execute algorithm: " << alg->name());
throw std::runtime_error("Failed to process event data");
}
}
Expand Down
3 changes: 2 additions & 1 deletion Examples/Python/python/acts/examples/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def addCKFTracks(
inputSourceLinks="sourcelinks",
inputInitialTrackParameters="estimatedparameters",
outputTrajectories="trajectories",
outputTrackParameters="fittedTrackParameters",
findTracks=acts.examples.TrackFindingAlgorithm.makeTrackFinderFunction(
trackingGeometry, field
),
Expand Down Expand Up @@ -839,7 +840,7 @@ def addVertexFitting(
field,
outputDirRoot: Optional[Union[Path, str]] = None,
associatedParticles: str = "particles_input",
trackParameters: str = "estimatedparameters",
trackParameters: str = "trackparameters",
vertexFinder: VertexFinder = VertexFinder.Truth,
logLevel: Optional[acts.logging.Level] = None,
):
Expand Down
1 change: 1 addition & 0 deletions Examples/Python/src/TrackFinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ void addTrackFinding(Context& ctx) {
ACTS_PYTHON_MEMBER(inputSourceLinks);
ACTS_PYTHON_MEMBER(inputInitialTrackParameters);
ACTS_PYTHON_MEMBER(outputTrajectories);
ACTS_PYTHON_MEMBER(outputTrackParameters);
ACTS_PYTHON_MEMBER(findTracks);
ACTS_PYTHON_MEMBER(measurementSelectorCfg);
ACTS_PYTHON_STRUCT_END();
Expand Down
19 changes: 14 additions & 5 deletions Examples/Scripts/Python/full_chain_odd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
)
from acts.examples.reconstruction import (
addSeeding,
TruthSeedRanges,
addCKFTracks,
CKFPerformanceConfig,
addVertexFitting,
Expand All @@ -47,7 +46,7 @@
s,
MomentumConfig(1.0 * u.GeV, 10.0 * u.GeV, True),
EtaConfig(-3.0, 3.0, True),
ParticleConfig(1, acts.PdgParticle.eMuon, True),
ParticleConfig(2, acts.PdgParticle.eMuon, True),
rnd=rnd,
)
s = addFatras(
Expand All @@ -69,10 +68,8 @@
s,
trackingGeometry,
field,
TruthSeedRanges(pt=(1.0 * u.GeV, None), eta=(-2.7, 2.7), nHits=(9, None)),
geoSelectionConfigFile=oddSeedingSel,
outputDirRoot=outputDir,
initialVarInflation=[100, 100, 100, 100, 100, 100],
)
s = addCKFTracks(
s,
Expand All @@ -81,10 +78,22 @@
CKFPerformanceConfig(ptMin=400.0 * u.MeV, nMeasurementsMin=6),
outputDirRoot=outputDir,
)
s.addAlgorithm(
acts.examples.TrackSelector(
level=acts.logging.INFO,
inputTrackParameters="fittedTrackParameters",
outputTrackParameters="trackparameters",
outputTrackIndices="outputTrackIndices",
removeNeutral=True,
absEtaMax=2.5,
loc0Max=4.0 * u.mm, # rho max
ptMin=500 * u.MeV,
)
)
s = addVertexFitting(
s,
field,
vertexFinder=VertexFinder.Truth,
vertexFinder=VertexFinder.Iterative,
outputDirRoot=outputDir,
)

Expand Down