Skip to content
Draft
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: 2 additions & 2 deletions CI/physmon/workflows/physmon_trackfitting_gx2f_vs_kf.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
)

s.addWriter(
acts.examples.root.RootTrackFitterPerformanceWriter(
acts.examples.root.RootTrackParameterPerformanceWriter(
level=acts.logging.INFO,
inputTracks="selected-tracks-gx2f",
inputParticles="particles_selected",
Expand Down Expand Up @@ -149,7 +149,7 @@
)

s.addWriter(
acts.examples.root.RootTrackFitterPerformanceWriter(
acts.examples.root.RootTrackParameterPerformanceWriter(
level=acts.logging.INFO,
inputTracks="selected-tracks-kf",
inputParticles="particles_selected",
Expand Down
1 change: 1 addition & 0 deletions Examples/Algorithms/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ acts_add_library(
src/SeedsToProtoTracks.cpp
src/TrajectoriesToProtoTracks.cpp
src/TrackSelectorAlgorithm.cpp
src/TrackExtrapolationAlgorithm.cpp
src/TracksToTrajectories.cpp
src/ProtoTracksToTracks.cpp
src/TracksToParameters.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/TrackHelpers.hpp"
#include "ActsExamples/EventData/Track.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IAlgorithm.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"

#include <memory>
#include <string>

namespace Acts {
class MagneticFieldProvider;
class Surface;
class TrackingGeometry;
} // namespace Acts

namespace ActsExamples {

/// Move the track parameters of a track container onto a common surface,
/// typically a perigee.
///
/// The track states are carried over unchanged, so they keep the parameters on
/// their own surfaces; only the track-level parameters are moved. That is the
/// same layering a fitter produces.
///
/// Tracks whose extrapolation fails are dropped, so the output indices differ
/// from the input and any truth matching has to be redone downstream.
class TrackExtrapolationAlgorithm final : public IAlgorithm {
public:
struct Config {
/// Input track collection.
std::string inputTracks;
/// Output track collection.
std::string outputTracks;

/// Surface to move the track parameters to.
std::shared_ptr<const Acts::Surface> targetSurface;
/// Tracking geometry to navigate.
std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry;
/// Magnetic field to propagate in.
std::shared_ptr<const Acts::MagneticFieldProvider> magneticField;

/// Which track state to start the extrapolation from.
Acts::TrackExtrapolationStrategy strategy =
Acts::TrackExtrapolationStrategy::firstOrLast;
};

/// Construct the algorithm.
///
/// @param config the configuration
/// @param logger the logger
explicit TrackExtrapolationAlgorithm(
Config config, std::unique_ptr<const Acts::Logger> logger = nullptr);

/// Extrapolate the tracks of one event.
///
/// @param ctx the algorithm context
/// @return a process code
ProcessCode execute(const AlgorithmContext& ctx) const override;

/// Get readonly access to the config parameters
/// @return the configuration
const Config& config() const { return m_cfg; }

private:
Config m_cfg;

ReadDataHandle<ConstTrackContainer> m_inputTracks{this, "InputTracks"};
WriteDataHandle<ConstTrackContainer> m_outputTracks{this, "OutputTracks"};
};

} // namespace ActsExamples
119 changes: 119 additions & 0 deletions Examples/Algorithms/Utilities/src/TrackExtrapolationAlgorithm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "ActsExamples/Utilities/TrackExtrapolationAlgorithm.hpp"

#include "Acts/EventData/TrackContainer.hpp"
#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "Acts/EventData/VectorTrackContainer.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/MagneticField/MagneticFieldProvider.hpp"
#include "Acts/Propagator/ActorList.hpp"
#include "Acts/Propagator/MaterialInteractor.hpp"
#include "Acts/Propagator/Navigator.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Propagator/StandardAborters.hpp"
#include "Acts/Propagator/SympyStepper.hpp"
#include "Acts/Surfaces/Surface.hpp"

#include <memory>
#include <stdexcept>
#include <utility>

namespace ActsExamples {

TrackExtrapolationAlgorithm::TrackExtrapolationAlgorithm(
Config config, std::unique_ptr<const Acts::Logger> logger)
: IAlgorithm("TrackExtrapolationAlgorithm", std::move(logger)),
m_cfg(std::move(config)) {
if (m_cfg.inputTracks.empty()) {
throw std::invalid_argument("Missing input track collection");
}
if (m_cfg.outputTracks.empty()) {
throw std::invalid_argument("Missing output track collection");
}
if (m_cfg.targetSurface == nullptr) {
throw std::invalid_argument("Missing target surface");
}
if (m_cfg.trackingGeometry == nullptr) {
throw std::invalid_argument("Missing tracking geometry");
}
if (m_cfg.magneticField == nullptr) {
throw std::invalid_argument("Missing magnetic field");
}

m_inputTracks.initialize(m_cfg.inputTracks);
m_outputTracks.initialize(m_cfg.outputTracks);
}

ProcessCode TrackExtrapolationAlgorithm::execute(
const AlgorithmContext& ctx) const {
const ConstTrackContainer& inputTracks = m_inputTracks(ctx);

using Propagator = Acts::Propagator<Acts::SympyStepper, Acts::Navigator>;
using Options = Propagator::Options<
Acts::ActorList<Acts::MaterialInteractor, Acts::EndOfWorldReached>>;

const Propagator propagator(
Acts::SympyStepper(m_cfg.magneticField),
Acts::Navigator({m_cfg.trackingGeometry},
logger().cloneWithSuffix("Navigator")),
logger().cloneWithSuffix("Propagator"));

const Options options(ctx.geoContext, ctx.magFieldContext);

auto trackBackend = std::make_shared<Acts::VectorTrackContainer>();
auto stateBackend = std::make_shared<Acts::VectorMultiTrajectory>();
TrackContainer extrapolated{trackBackend, stateBackend};
extrapolated.ensureDynamicColumns(inputTracks);

std::size_t nFailed = 0;

for (const auto& track : inputTracks) {
auto destination = extrapolated.makeTrack();
destination.copyFromWithoutStates(track);

// `TrackProxy::copyFrom` would copy the states with a hardcoded
// `TrackStatePropMask::All`, which throws on the states of a seed track
// that hold no parameters at all
for (const auto& source : track.trackStatesReversed()) {
auto state = destination.appendTrackState(source.getMask());
state.copyFrom(source, source.getMask(), true);
}
destination.reverseTrackStates();

const auto result = Acts::extrapolateTrackToReferenceSurface(
destination, *m_cfg.targetSurface, propagator, options, m_cfg.strategy,
logger());
if (!result.ok()) {
ACTS_DEBUG("Extrapolation of track " << track.index() << " failed with "
<< result.error());
++nFailed;
extrapolated.removeTrack(destination.index());
}
}

if (nFailed > 0) {
ACTS_DEBUG("Dropped " << nFailed << " of " << inputTracks.size()
<< " tracks that could not be extrapolated");
}

ConstTrackContainer outputTracks{
std::make_shared<Acts::ConstVectorTrackContainer>(
std::move(*trackBackend)),
std::make_shared<Acts::ConstVectorMultiTrajectory>(
std::move(*stateBackend))};

ACTS_DEBUG("Extrapolated " << outputTracks.size() << " tracks");

m_outputTracks(ctx, std::move(outputTracks));

return ProcessCode::SUCCESS;
}

} // namespace ActsExamples
2 changes: 1 addition & 1 deletion Examples/Framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ acts_add_library(
src/Validation/ResPlotTool.cpp
src/Validation/TrackClassification.cpp
src/Validation/PatternRecognitionPerformanceCollector.cpp
src/Validation/TrackFitterPerformanceCollector.cpp
src/Validation/TrackParameterPerformanceCollector.cpp
src/Validation/TrackQualityPlotTool.cpp
src/Validation/TrackSummaryPlotTool.cpp
ACTS_INCLUDE_FOLDER include/ActsExamples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

namespace ActsExamples {

/// Collects track-fitter performance histograms without any file I/O.
/// Collects performance histograms of the track parameters at the track
/// reference surface, without any file I/O.
///
/// Collects residual/pull histograms, efficiency plots, and track summary
/// information for track fitting performance evaluation.
///
/// @note The caller must ensure exclusive access (e.g. hold a mutex) when
/// calling fill(). This class applies no locking of its own.
class TrackFitterPerformanceCollector {
class TrackParameterPerformanceCollector {
public:
struct Config {
ResPlotTool::Config resPlotToolConfig;
Expand All @@ -46,8 +47,8 @@ class TrackFitterPerformanceCollector {
int fitIterations = 3;
};

TrackFitterPerformanceCollector(Config cfg,
std::unique_ptr<const Acts::Logger> logger);
TrackParameterPerformanceCollector(
Config cfg, std::unique_ptr<const Acts::Logger> logger);

/// Fill histograms for one event.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "ActsExamples/Validation/TrackFitterPerformanceCollector.hpp"
#include "ActsExamples/Validation/TrackParameterPerformanceCollector.hpp"

#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/VectorHelpers.hpp"
Expand All @@ -15,7 +15,7 @@

namespace ActsExamples {

TrackFitterPerformanceCollector::TrackFitterPerformanceCollector(
TrackParameterPerformanceCollector::TrackParameterPerformanceCollector(
Config cfg, std::unique_ptr<const Acts::Logger> logger)
: m_cfg(std::move(cfg)),
m_logger(std::move(logger)),
Expand All @@ -24,7 +24,7 @@ TrackFitterPerformanceCollector::TrackFitterPerformanceCollector(
m_trackSummaryPlotTool(m_cfg.trackSummaryPlotToolConfig,
m_logger->level()) {}

void TrackFitterPerformanceCollector::fill(
void TrackParameterPerformanceCollector::fill(
const Acts::GeometryContext& geoContext, const ConstTrackContainer& tracks,
const SimParticleContainer& particles,
const TrackParticleMatching& trackParticleMatching) {
Expand Down Expand Up @@ -107,8 +107,8 @@ void TrackFitterPerformanceCollector::fill(
}
}

void TrackFitterPerformanceCollector::logSummary() const {
ACTS_INFO("=== Track Fitter Performance Summary ===");
void TrackParameterPerformanceCollector::logSummary() const {
ACTS_INFO("=== Track Parameter Performance Summary ===");
ACTS_INFO("Total tracks: " << m_stats.nTotalTracks);
ACTS_INFO("Total matched tracks: " << m_stats.nTotalMatchedTracks);
ACTS_INFO("Total particles: " << m_stats.nTotalParticles);
Expand Down
2 changes: 1 addition & 1 deletion Examples/Io/Root/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ acts_add_library(
src/detail/NuclearInteractionParametrisation.cpp
src/RootPatternRecognitionPerformanceWriter.cpp
src/RootTrackFinderNTupleWriter.cpp
src/RootTrackFitterPerformanceWriter.cpp
src/RootTrackParameterPerformanceWriter.cpp
src/RootVertexNTupleWriter.cpp
src/RootMuonSpacePointWriter.cpp
src/RootMuonSpacePointReader.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "ActsExamples/Framework/WriterT.hpp"
#include "ActsExamples/Validation/EffPlotTool.hpp"
#include "ActsExamples/Validation/ResPlotTool.hpp"
#include "ActsExamples/Validation/TrackFitterPerformanceCollector.hpp"
#include "ActsExamples/Validation/TrackParameterPerformanceCollector.hpp"
#include "ActsExamples/Validation/TrackSummaryPlotTool.hpp"

#include <mutex>
Expand All @@ -36,18 +36,18 @@ namespace ActsExamples {
/// this is done by setting the Config::rootFile pointer to an existing file
///
/// Safe to use from multiple writer threads - uses a std::mutex lock.
class RootTrackFitterPerformanceWriter final
class RootTrackParameterPerformanceWriter final
: public WriterT<ConstTrackContainer> {
public:
struct Config {
/// Input (fitted) track collection.
/// Input track collection.
std::string inputTracks;
/// Input particles collection.
std::string inputParticles;
/// Input track-particle matching.
std::string inputTrackParticleMatching;
/// Output filename.
std::string filePath = "performance_track_fitter.root";
std::string filePath = "performance_track_parameters.root";
/// Plot tool configurations.
ResPlotTool::Config resPlotToolConfig;
EffPlotTool::Config effPlotToolConfig;
Expand All @@ -67,9 +67,10 @@ class RootTrackFitterPerformanceWriter final
/// Construct from configuration and log level.
/// @param config The configuration
/// @param level The logger level
RootTrackFitterPerformanceWriter(Config config, Acts::Logging::Level level);
RootTrackParameterPerformanceWriter(Config config,
Acts::Logging::Level level);

~RootTrackFitterPerformanceWriter() override;
~RootTrackParameterPerformanceWriter() override;

/// Finalize plots.
ProcessCode finalize() override;
Expand All @@ -91,7 +92,7 @@ class RootTrackFitterPerformanceWriter final
std::mutex m_writeMutex;
TFile* m_outputFile{nullptr};
/// Collector holding all plot tools and per-event counters.
TrackFitterPerformanceCollector m_collector;
TrackParameterPerformanceCollector m_collector;
};

} // namespace ActsExamples
Loading
Loading