diff --git a/CI/physmon/workflows/physmon_trackfitting_gx2f_vs_kf.py b/CI/physmon/workflows/physmon_trackfitting_gx2f_vs_kf.py index 28ec98c9ae1..4d49fc32872 100755 --- a/CI/physmon/workflows/physmon_trackfitting_gx2f_vs_kf.py +++ b/CI/physmon/workflows/physmon_trackfitting_gx2f_vs_kf.py @@ -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", @@ -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", diff --git a/Examples/Algorithms/Utilities/CMakeLists.txt b/Examples/Algorithms/Utilities/CMakeLists.txt index 13bceaa34c9..433849cb614 100644 --- a/Examples/Algorithms/Utilities/CMakeLists.txt +++ b/Examples/Algorithms/Utilities/CMakeLists.txt @@ -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 diff --git a/Examples/Algorithms/Utilities/include/ActsExamples/Utilities/TrackExtrapolationAlgorithm.hpp b/Examples/Algorithms/Utilities/include/ActsExamples/Utilities/TrackExtrapolationAlgorithm.hpp new file mode 100644 index 00000000000..cf675112bab --- /dev/null +++ b/Examples/Algorithms/Utilities/include/ActsExamples/Utilities/TrackExtrapolationAlgorithm.hpp @@ -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 +#include + +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 targetSurface; + /// Tracking geometry to navigate. + std::shared_ptr trackingGeometry; + /// Magnetic field to propagate in. + std::shared_ptr 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 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 m_inputTracks{this, "InputTracks"}; + WriteDataHandle m_outputTracks{this, "OutputTracks"}; +}; + +} // namespace ActsExamples diff --git a/Examples/Algorithms/Utilities/src/TrackExtrapolationAlgorithm.cpp b/Examples/Algorithms/Utilities/src/TrackExtrapolationAlgorithm.cpp new file mode 100644 index 00000000000..bd58c625e82 --- /dev/null +++ b/Examples/Algorithms/Utilities/src/TrackExtrapolationAlgorithm.cpp @@ -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 +#include +#include + +namespace ActsExamples { + +TrackExtrapolationAlgorithm::TrackExtrapolationAlgorithm( + Config config, std::unique_ptr 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; + using Options = Propagator::Options< + Acts::ActorList>; + + 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(); + auto stateBackend = std::make_shared(); + 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( + std::move(*trackBackend)), + std::make_shared( + std::move(*stateBackend))}; + + ACTS_DEBUG("Extrapolated " << outputTracks.size() << " tracks"); + + m_outputTracks(ctx, std::move(outputTracks)); + + return ProcessCode::SUCCESS; +} + +} // namespace ActsExamples diff --git a/Examples/Framework/CMakeLists.txt b/Examples/Framework/CMakeLists.txt index bef17c77c74..4518fb438c8 100644 --- a/Examples/Framework/CMakeLists.txt +++ b/Examples/Framework/CMakeLists.txt @@ -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 diff --git a/Examples/Framework/include/ActsExamples/Validation/TrackFitterPerformanceCollector.hpp b/Examples/Framework/include/ActsExamples/Validation/TrackParameterPerformanceCollector.hpp similarity index 91% rename from Examples/Framework/include/ActsExamples/Validation/TrackFitterPerformanceCollector.hpp rename to Examples/Framework/include/ActsExamples/Validation/TrackParameterPerformanceCollector.hpp index fd5db898a6d..e4406f035f2 100644 --- a/Examples/Framework/include/ActsExamples/Validation/TrackFitterPerformanceCollector.hpp +++ b/Examples/Framework/include/ActsExamples/Validation/TrackParameterPerformanceCollector.hpp @@ -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; @@ -46,8 +47,8 @@ class TrackFitterPerformanceCollector { int fitIterations = 3; }; - TrackFitterPerformanceCollector(Config cfg, - std::unique_ptr logger); + TrackParameterPerformanceCollector( + Config cfg, std::unique_ptr logger); /// Fill histograms for one event. /// diff --git a/Examples/Framework/src/Validation/TrackFitterPerformanceCollector.cpp b/Examples/Framework/src/Validation/TrackParameterPerformanceCollector.cpp similarity index 92% rename from Examples/Framework/src/Validation/TrackFitterPerformanceCollector.cpp rename to Examples/Framework/src/Validation/TrackParameterPerformanceCollector.cpp index 97b30edc18a..5d0cd441579 100644 --- a/Examples/Framework/src/Validation/TrackFitterPerformanceCollector.cpp +++ b/Examples/Framework/src/Validation/TrackParameterPerformanceCollector.cpp @@ -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" @@ -15,7 +15,7 @@ namespace ActsExamples { -TrackFitterPerformanceCollector::TrackFitterPerformanceCollector( +TrackParameterPerformanceCollector::TrackParameterPerformanceCollector( Config cfg, std::unique_ptr logger) : m_cfg(std::move(cfg)), m_logger(std::move(logger)), @@ -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) { @@ -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); diff --git a/Examples/Io/Root/CMakeLists.txt b/Examples/Io/Root/CMakeLists.txt index bbff57896a4..1f1cbfb3684 100644 --- a/Examples/Io/Root/CMakeLists.txt +++ b/Examples/Io/Root/CMakeLists.txt @@ -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 diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackFitterPerformanceWriter.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackParameterPerformanceWriter.hpp similarity index 87% rename from Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackFitterPerformanceWriter.hpp rename to Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackParameterPerformanceWriter.hpp index c4ab707a315..132c04e1163 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackFitterPerformanceWriter.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackParameterPerformanceWriter.hpp @@ -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 @@ -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 { 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; @@ -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; @@ -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 diff --git a/Examples/Io/Root/src/RootTrackFitterPerformanceWriter.cpp b/Examples/Io/Root/src/RootTrackParameterPerformanceWriter.cpp similarity index 90% rename from Examples/Io/Root/src/RootTrackFitterPerformanceWriter.cpp rename to Examples/Io/Root/src/RootTrackParameterPerformanceWriter.cpp index 42f7a9ceeb3..2f1da57810c 100644 --- a/Examples/Io/Root/src/RootTrackFitterPerformanceWriter.cpp +++ b/Examples/Io/Root/src/RootTrackParameterPerformanceWriter.cpp @@ -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/Io/Root/RootTrackFitterPerformanceWriter.hpp" +#include "ActsExamples/Io/Root/RootTrackParameterPerformanceWriter.hpp" #include "Acts/Utilities/Helpers.hpp" #include "ActsExamples/Framework/AlgorithmContext.hpp" @@ -28,12 +28,13 @@ using ActsPlugins::toRoot; namespace ActsExamples { -RootTrackFitterPerformanceWriter::RootTrackFitterPerformanceWriter( - RootTrackFitterPerformanceWriter::Config config, Acts::Logging::Level level) - : WriterT(config.inputTracks, "RootTrackFitterPerformanceWriter", level), +RootTrackParameterPerformanceWriter::RootTrackParameterPerformanceWriter( + RootTrackParameterPerformanceWriter::Config config, + Acts::Logging::Level level) + : WriterT(config.inputTracks, "RootTrackParameterPerformanceWriter", level), m_cfg(std::move(config)), m_collector( - TrackFitterPerformanceCollector::Config{ + TrackParameterPerformanceCollector::Config{ m_cfg.resPlotToolConfig, m_cfg.effPlotToolConfig, m_cfg.trackSummaryPlotToolConfig, m_cfg.fitMinEntries, m_cfg.fitSigmaRange, m_cfg.fitIterations}, @@ -62,11 +63,11 @@ RootTrackFitterPerformanceWriter::RootTrackFitterPerformanceWriter( } } -RootTrackFitterPerformanceWriter::~RootTrackFitterPerformanceWriter() { +RootTrackParameterPerformanceWriter::~RootTrackParameterPerformanceWriter() { delete m_outputFile; } -ProcessCode RootTrackFitterPerformanceWriter::finalize() { +ProcessCode RootTrackParameterPerformanceWriter::finalize() { if (m_outputFile == nullptr) { return ProcessCode::SUCCESS; } @@ -165,7 +166,7 @@ ProcessCode RootTrackFitterPerformanceWriter::finalize() { return ProcessCode::SUCCESS; } -ProcessCode RootTrackFitterPerformanceWriter::writeT( +ProcessCode RootTrackParameterPerformanceWriter::writeT( const AlgorithmContext& ctx, const ConstTrackContainer& tracks) { // Read truth input collections const auto& particles = m_inputParticles(ctx); diff --git a/Examples/Scripts/Python/pypi_finding_fitting_demo.py b/Examples/Scripts/Python/pypi_finding_fitting_demo.py index f026567ac87..655f2790ff6 100644 --- a/Examples/Scripts/Python/pypi_finding_fitting_demo.py +++ b/Examples/Scripts/Python/pypi_finding_fitting_demo.py @@ -200,11 +200,11 @@ def execute(self, context): s.addWriter(perfWriterFinder) # Add track fitter performance writer - cfg_fitter = acts.examples.PythonTrackFitterPerformanceWriter.Config() + cfg_fitter = acts.examples.PythonTrackParameterPerformanceWriter.Config() cfg_fitter.inputTracks = "fitted_tracks" cfg_fitter.inputParticles = "particles" cfg_fitter.inputTrackParticleMatching = "track_particle_matching" - perfWriterFitter = acts.examples.PythonTrackFitterPerformanceWriter( + perfWriterFitter = acts.examples.PythonTrackParameterPerformanceWriter( cfg_fitter, acts.logging.INFO ) s.addWriter(perfWriterFitter) diff --git a/Examples/Scripts/Python/truth_jet_test.py b/Examples/Scripts/Python/truth_jet_test.py index 6907cd753ab..93bb175d0b3 100644 --- a/Examples/Scripts/Python/truth_jet_test.py +++ b/Examples/Scripts/Python/truth_jet_test.py @@ -50,7 +50,7 @@ from acts.examples.root import ( RootTrackStatesWriter, RootTrackSummaryWriter, - RootTrackFitterPerformanceWriter, + RootTrackParameterPerformanceWriter, ) diff --git a/Examples/Scripts/Python/truth_tracking_gsf.py b/Examples/Scripts/Python/truth_tracking_gsf.py index 85dfafcd9bc..419c5fcc78c 100755 --- a/Examples/Scripts/Python/truth_tracking_gsf.py +++ b/Examples/Scripts/Python/truth_tracking_gsf.py @@ -44,7 +44,7 @@ def runTruthTrackingGsf( RootParticleReader, RootTrackStatesWriter, RootTrackSummaryWriter, - RootTrackFitterPerformanceWriter, + RootTrackParameterPerformanceWriter, ) s = s or acts.examples.Sequencer( @@ -197,7 +197,7 @@ def runTruthTrackingGsf( ) s.addWriter( - RootTrackFitterPerformanceWriter( + RootTrackParameterPerformanceWriter( level=acts.logging.INFO, inputTracks="tracks", inputParticles="particles_selected", diff --git a/Examples/Scripts/Python/truth_tracking_gsf_refitting.py b/Examples/Scripts/Python/truth_tracking_gsf_refitting.py index 4fb7cb66981..0f05f9516c2 100755 --- a/Examples/Scripts/Python/truth_tracking_gsf_refitting.py +++ b/Examples/Scripts/Python/truth_tracking_gsf_refitting.py @@ -8,7 +8,7 @@ from acts.examples.root import ( RootTrackStatesWriter, RootTrackSummaryWriter, - RootTrackFitterPerformanceWriter, + RootTrackParameterPerformanceWriter, ) from truth_tracking_kalman import runTruthTrackingKalman @@ -113,7 +113,7 @@ def runRefittingGsf( ) s.addWriter( - RootTrackFitterPerformanceWriter( + RootTrackParameterPerformanceWriter( level=acts.logging.INFO, inputTracks="gsf_refit_tracks", inputParticles="particles_selected", diff --git a/Examples/Scripts/Python/truth_tracking_gx2f.py b/Examples/Scripts/Python/truth_tracking_gx2f.py index 06ffa5e7e9c..c10bdca4dd5 100644 --- a/Examples/Scripts/Python/truth_tracking_gx2f.py +++ b/Examples/Scripts/Python/truth_tracking_gx2f.py @@ -33,7 +33,7 @@ def runTruthTrackingGx2f( RootParticleReader, RootTrackStatesWriter, RootTrackSummaryWriter, - RootTrackFitterPerformanceWriter, + RootTrackParameterPerformanceWriter, ) from acts.examples.reconstruction import ( @@ -183,7 +183,7 @@ def runTruthTrackingGx2f( ) s.addWriter( - RootTrackFitterPerformanceWriter( + RootTrackParameterPerformanceWriter( level=acts.logging.INFO, inputTracks="tracks", inputParticles="particles_selected", diff --git a/Examples/Scripts/Python/truth_tracking_kalman.py b/Examples/Scripts/Python/truth_tracking_kalman.py index e06ae2cc4af..6e4315f8966 100755 --- a/Examples/Scripts/Python/truth_tracking_kalman.py +++ b/Examples/Scripts/Python/truth_tracking_kalman.py @@ -42,7 +42,7 @@ def runTruthTrackingKalman( RootSimHitReader, RootTrackStatesWriter, RootTrackSummaryWriter, - RootTrackFitterPerformanceWriter, + RootTrackParameterPerformanceWriter, ) from acts.examples.reconstruction import ( @@ -209,7 +209,7 @@ def runTruthTrackingKalman( ) s.addWriter( - RootTrackFitterPerformanceWriter( + RootTrackParameterPerformanceWriter( level=acts.logging.INFO, inputTracks="tracks", inputParticles="particles_selected", diff --git a/Examples/Scripts/Python/truth_tracking_kalman_refitting.py b/Examples/Scripts/Python/truth_tracking_kalman_refitting.py index 576e2b858b2..af07a1bd9d7 100755 --- a/Examples/Scripts/Python/truth_tracking_kalman_refitting.py +++ b/Examples/Scripts/Python/truth_tracking_kalman_refitting.py @@ -7,7 +7,7 @@ from acts.examples.root import ( RootTrackStatesWriter, RootTrackSummaryWriter, - RootTrackFitterPerformanceWriter, + RootTrackParameterPerformanceWriter, ) from truth_tracking_kalman import runTruthTrackingKalman @@ -95,7 +95,7 @@ def runRefittingKf( ) s.addWriter( - RootTrackFitterPerformanceWriter( + RootTrackParameterPerformanceWriter( level=acts.logging.INFO, inputTracks="kf_refit_tracks", inputParticles="particles_selected", diff --git a/Python/Examples/python/__init__.py b/Python/Examples/python/__init__.py index 83998286859..f52f89dbbcb 100644 --- a/Python/Examples/python/__init__.py +++ b/Python/Examples/python/__init__.py @@ -28,6 +28,19 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) +class PythonTrackFitterPerformanceWriter(PythonTrackParameterPerformanceWriter): + """Deprecated alias for :class:`PythonTrackParameterPerformanceWriter`.""" + + def __init__(self, *args, **kwargs): + warnings.warn( + "PythonTrackFitterPerformanceWriter is deprecated, " + "use PythonTrackParameterPerformanceWriter instead", + DeprecationWarning, + stacklevel=2, + ) + super().__init__(*args, **kwargs) + + _rootAliasesSetup = False @@ -58,6 +71,27 @@ def __init__(self, *args, **kwargs): RootTrackFinderPerformanceWriter, ) + class RootTrackFitterPerformanceWriter( + root_module.RootTrackParameterPerformanceWriter + ): + """Deprecated alias for :class:`RootTrackParameterPerformanceWriter`.""" + + def __init__(self, *args, **kwargs): + warnings.warn( + "RootTrackFitterPerformanceWriter is deprecated, " + "use RootTrackParameterPerformanceWriter instead", + DeprecationWarning, + stacklevel=2, + ) + super().__init__(*args, **kwargs) + + RootTrackFitterPerformanceWriter.__module__ = "acts.examples.root" + setattr( + root_module, + "RootTrackFitterPerformanceWriter", + RootTrackFitterPerformanceWriter, + ) + def _tryImportRoot(*names: str): """ diff --git a/Python/Examples/python/reconstruction.py b/Python/Examples/python/reconstruction.py index 0ee23a3a8f8..6707789a49d 100644 --- a/Python/Examples/python/reconstruction.py +++ b/Python/Examples/python/reconstruction.py @@ -1930,13 +1930,13 @@ def addTrackWriters( ( RootTrackSummaryWriter, RootTrackStatesWriter, - RootTrackFitterPerformanceWriter, + RootTrackParameterPerformanceWriter, RootPatternRecognitionPerformanceWriter, RootTrackFinderNTupleWriter, ) = acts.examples._tryImportRoot( "RootTrackSummaryWriter", "RootTrackStatesWriter", - "RootTrackFitterPerformanceWriter", + "RootTrackParameterPerformanceWriter", "RootPatternRecognitionPerformanceWriter", "RootTrackFinderNTupleWriter", ) @@ -1970,14 +1970,14 @@ def addTrackWriters( s.addWriter(trackStatesWriter) if writeFitterPerformance: - trackFitterPerformanceWriter = RootTrackFitterPerformanceWriter( + trackParameterPerformanceWriter = RootTrackParameterPerformanceWriter( level=customLogLevel(), inputTracks=tracks, inputParticles="particles_selected", inputTrackParticleMatching="track_particle_matching", filePath=str(outputDirRoot / f"performance_fitting_{name}.root"), ) - s.addWriter(trackFitterPerformanceWriter) + s.addWriter(trackParameterPerformanceWriter) if writeFinderPerformance: trackFinderPerfWriter = RootPatternRecognitionPerformanceWriter( diff --git a/Python/Examples/src/PythonSpecific.cpp b/Python/Examples/src/PythonSpecific.cpp index 157e6d2bb61..e48b79ae5e8 100644 --- a/Python/Examples/src/PythonSpecific.cpp +++ b/Python/Examples/src/PythonSpecific.cpp @@ -18,7 +18,7 @@ #include "ActsExamples/Validation/EffPlotTool.hpp" #include "ActsExamples/Validation/PatternRecognitionPerformanceCollector.hpp" #include "ActsExamples/Validation/ResPlotTool.hpp" -#include "ActsExamples/Validation/TrackFitterPerformanceCollector.hpp" +#include "ActsExamples/Validation/TrackParameterPerformanceCollector.hpp" #include "ActsExamples/Validation/TrackSummaryPlotTool.hpp" #include "ActsPython/Utilities/Macros.hpp" @@ -183,20 +183,20 @@ class PythonPatternRecognitionPerformanceWriter final } // namespace -/// A ROOT-free writer that collects track-fitter performance histograms and +/// A ROOT-free writer that collects track-parameter performance histograms and /// exposes them to Python via histograms() after s.run(). -class PythonTrackFitterPerformanceWriter final +class PythonTrackParameterPerformanceWriter final : public WriterT { public: struct Config { - /// Input (fitted) tracks collection. + /// Input tracks collection. std::string inputTracks; /// Input particles collection. std::string inputParticles; /// Input track-particle matching. std::string inputTrackParticleMatching; /// Output filename (optional). - std::string filePath = "performance_track_fitter.root"; + std::string filePath = "performance_track_parameters.root"; /// Plot tool configurations. ResPlotTool::Config resPlotToolConfig; EffPlotTool::Config effPlotToolConfig; @@ -207,11 +207,11 @@ class PythonTrackFitterPerformanceWriter final int fitIterations = 3; }; - PythonTrackFitterPerformanceWriter(Config cfg, Acts::Logging::Level lvl) - : WriterT(cfg.inputTracks, "PythonTrackFitterPerformanceWriter", lvl), + PythonTrackParameterPerformanceWriter(Config cfg, Acts::Logging::Level lvl) + : WriterT(cfg.inputTracks, "PythonTrackParameterPerformanceWriter", lvl), m_cfg(std::move(cfg)), m_collector( - TrackFitterPerformanceCollector::Config{ + TrackParameterPerformanceCollector::Config{ m_cfg.resPlotToolConfig, m_cfg.effPlotToolConfig, m_cfg.trackSummaryPlotToolConfig, m_cfg.fitMinEntries, m_cfg.fitSigmaRange, m_cfg.fitIterations}, @@ -308,7 +308,7 @@ class PythonTrackFitterPerformanceWriter final Config m_cfg; std::mutex m_writeMutex; - TrackFitterPerformanceCollector m_collector; + TrackParameterPerformanceCollector m_collector; ReadDataHandle m_inputParticles{this, "InputParticles"}; ReadDataHandle m_inputTrackParticleMatching{ @@ -339,11 +339,11 @@ void addPythonSpecific(py::module_& mex) { } { - using Writer = PythonTrackFitterPerformanceWriter; + using Writer = PythonTrackParameterPerformanceWriter; using Config = Writer::Config; auto w = py::class_>( - mex, "PythonTrackFitterPerformanceWriter") + mex, "PythonTrackParameterPerformanceWriter") .def(py::init(), py::arg("config"), py::arg("level")) .def_property_readonly("config", &Writer::config) diff --git a/Python/Examples/src/Utilities.cpp b/Python/Examples/src/Utilities.cpp index f3d48c8d1a0..65f5919c99c 100644 --- a/Python/Examples/src/Utilities.cpp +++ b/Python/Examples/src/Utilities.cpp @@ -12,6 +12,7 @@ #include "ActsExamples/Utilities/ProtoTracksToSeeds.hpp" #include "ActsExamples/Utilities/ProtoTracksToTracks.hpp" #include "ActsExamples/Utilities/SeedsToProtoTracks.hpp" +#include "ActsExamples/Utilities/TrackExtrapolationAlgorithm.hpp" #include "ActsExamples/Utilities/TracksToParameters.hpp" #include "ActsExamples/Utilities/TracksToTrajectories.hpp" #include "ActsExamples/Utilities/TrajectoriesToProtoTracks.hpp" @@ -45,6 +46,16 @@ void addUtilities(py::module& mex) { inputProtoTracks, inputSpacePoints, outputSeeds, outputProtoTracks); + py::enum_(mex, "TrackExtrapolationStrategy") + .value("first", Acts::TrackExtrapolationStrategy::first) + .value("last", Acts::TrackExtrapolationStrategy::last) + .value("firstOrLast", Acts::TrackExtrapolationStrategy::firstOrLast); + + ACTS_PYTHON_DECLARE_ALGORITHM(TrackExtrapolationAlgorithm, mex, + "TrackExtrapolationAlgorithm", inputTracks, + outputTracks, targetSurface, trackingGeometry, + magneticField, strategy); + ACTS_PYTHON_DECLARE_ALGORITHM( MeasurementMapSelector, mex, "MeasurementMapSelector", inputMeasurements, inputMeasurementParticleMap, outputMeasurementParticleMap, diff --git a/Python/Examples/src/plugins/Root.cpp b/Python/Examples/src/plugins/Root.cpp index cb5fb83efdd..382ca346757 100644 --- a/Python/Examples/src/plugins/Root.cpp +++ b/Python/Examples/src/plugins/Root.cpp @@ -31,7 +31,7 @@ #include "ActsExamples/Io/Root/RootSpacePointPerformanceWriter.hpp" #include "ActsExamples/Io/Root/RootSpacePointWriter.hpp" #include "ActsExamples/Io/Root/RootTrackFinderNTupleWriter.hpp" -#include "ActsExamples/Io/Root/RootTrackFitterPerformanceWriter.hpp" +#include "ActsExamples/Io/Root/RootTrackParameterPerformanceWriter.hpp" #include "ActsExamples/Io/Root/RootTrackParameterWriter.hpp" #include "ActsExamples/Io/Root/RootTrackStatesWriter.hpp" #include "ActsExamples/Io/Root/RootTrackSummaryReader.hpp" @@ -124,6 +124,7 @@ PYBIND11_MODULE(ActsExamplesPythonBindingsRoot, root) { py::class_(root, "ResPlotToolConfig") .def(py::init<>()) + .def_readwrite("paramNames", &ResPlotTool::Config::paramNames) .def_readwrite("varBinning", &ResPlotTool::Config::varBinning); py::class_(root, @@ -167,8 +168,8 @@ PYBIND11_MODULE(ActsExamplesPythonBindingsRoot, root) { treeNameTracks, treeNameParticles); ACTS_PYTHON_DECLARE_WRITER( - RootTrackFitterPerformanceWriter, root, - "RootTrackFitterPerformanceWriter", inputTracks, inputParticles, + RootTrackParameterPerformanceWriter, root, + "RootTrackParameterPerformanceWriter", inputTracks, inputParticles, inputTrackParticleMatching, filePath, resPlotToolConfig, effPlotToolConfig, trackSummaryPlotToolConfig, fitMinEntries, fitSigmaRange, fitIterations, warningThresholdFitFailureFraction); diff --git a/Python/Examples/tests/test_writer.py b/Python/Examples/tests/test_writer.py index e9b9390e441..9123df373a9 100644 --- a/Python/Examples/tests/test_writer.py +++ b/Python/Examples/tests/test_writer.py @@ -36,11 +36,11 @@ try: from acts.examples import ( PythonPatternRecognitionPerformanceWriter, - PythonTrackFitterPerformanceWriter, + PythonTrackParameterPerformanceWriter, ) except ImportError: PythonPatternRecognitionPerformanceWriter = None - PythonTrackFitterPerformanceWriter = None + PythonTrackParameterPerformanceWriter = None from acts.examples.odd import getOpenDataDetectorDirectory @@ -351,13 +351,13 @@ def test_root_writer_interface(writer_name, conf_const, tmp_path, trk_geo): "writer", [ PythonPatternRecognitionPerformanceWriter, - PythonTrackFitterPerformanceWriter, + PythonTrackParameterPerformanceWriter, ], ) @pytest.mark.root @pytest.mark.skipif( PythonPatternRecognitionPerformanceWriter is None - or PythonTrackFitterPerformanceWriter is None, + or PythonTrackParameterPerformanceWriter is None, reason="Python performance writers not available", ) def test_python_writer_interface(writer, conf_const, tmp_path, trk_geo):