Skip to content

Commit

Permalink
fix: full chain vertexing (#1299)
Browse files Browse the repository at this point in the history
fix full chain odd vertexing added here #1286

some early discussion here https://mattermost.web.cern.ch/acts/pl/m6psyge3apgcucesrgojeaajny

- output track parameters from `TrackFindingAlgorithm`
- refactor error handling in `*VertexFinderAlgorithm`
- rewire default whiteboard names in python examples
- use IVF in `full_chain_odd.py` with 2 muons (which should give us an actual vertex)
  • Loading branch information
andiwand authored Aug 9, 2022
1 parent 0352563 commit 884d342
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 23 deletions.
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 @@ -59,6 +59,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 @@ -108,6 +111,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 @@ -121,5 +131,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 @@ -679,6 +679,7 @@ def addCKFTracks(
inputSourceLinks="sourcelinks",
inputInitialTrackParameters="estimatedparameters",
outputTrajectories="trajectories",
outputTrackParameters="fittedTrackParameters",
findTracks=acts.examples.TrackFindingAlgorithm.makeTrackFinderFunction(
trackingGeometry, field
),
Expand Down Expand Up @@ -838,7 +839,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 @@ -33,7 +33,6 @@
)
from acts.examples.reconstruction import (
addSeeding,
TruthSeedRanges,
addCKFTracks,
CKFPerformanceConfig,
addVertexFitting,
Expand All @@ -46,7 +45,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 @@ -68,10 +67,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 @@ -80,10 +77,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

0 comments on commit 884d342

Please sign in to comment.