From 7d7da46f55f57f2989307e8bbe33e5aff82641e4 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Fri, 23 May 2025 18:09:34 +0200 Subject: [PATCH 01/25] Initialize TrackToTruthJetAlg --- Examples/Algorithms/Jets/CMakeLists.txt | 6 ++ .../Jets/TrackToTruthJetAlgorithm.hpp | 55 +++++++++++ .../Jets/src/TrackToTruthJetAlgorithm.cpp | 92 +++++++++++++++++++ .../Python/python/acts/examples/simulation.py | 27 ++++++ Examples/Python/src/ModuleEntry.cpp | 2 + Examples/Python/src/TruthJet.cpp | 15 ++- Examples/Python/src/TruthJetStub.cpp | 3 +- 7 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp create mode 100644 Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp diff --git a/Examples/Algorithms/Jets/CMakeLists.txt b/Examples/Algorithms/Jets/CMakeLists.txt index a8b3a16ff64..b6eb557b5d8 100644 --- a/Examples/Algorithms/Jets/CMakeLists.txt +++ b/Examples/Algorithms/Jets/CMakeLists.txt @@ -1,4 +1,10 @@ acts_add_library(ExamplesJets SHARED src/TruthJetAlgorithm.cpp) +======= +add_library(ActsExamplesJets + SHARED + src/TruthJetAlgorithm.cpp + src/TrackToTruthJetAlgorithm.cpp) +>>>>>>> ee1e83592 (Initialize TrackToTruthJetAlg) target_include_directories( ActsExamplesJets PUBLIC $ diff --git a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp new file mode 100644 index 00000000000..c21f1bebfdb --- /dev/null +++ b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp @@ -0,0 +1,55 @@ +// 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 "ActsExamples/EventData/SimParticle.hpp" +#include "ActsExamples/EventData/Track.hpp" +#include "ActsExamples/Framework/DataHandle.hpp" +#include "ActsExamples/Framework/IAlgorithm.hpp" +#include "ActsExamples/Framework/ProcessCode.hpp" + +#include + +#include +#include +#include + +namespace ActsExamples { +struct AlgorithmContext; + +/// Print all particles. +class TrackToTruthJetAlgorithm : public IAlgorithm { + public: + struct Config { + /// Input tracks collection. + std::string inputTracks; + /// Input jets collection. + std::string inputJets; + /// Output track jets collection. + std::string outputTrackJets; + /// Maximum delta R for track to jet matching. + double maxDeltaR = 0.4; + }; + + TrackToTruthJetAlgorithm(const Config& cfg, Acts::Logging::Level lvl); + + ProcessCode execute(const AlgorithmContext& ctx) const override; + ProcessCode finalize() const; + + const Config& config() const { return m_cfg; } + + private: + Config m_cfg; + ReadDataHandle m_inputTracks {this, "inputTracks"}; + ReadDataHandle> m_inputJets {this, "inputJets"}; + WriteDataHandle> m_outputTrackJets {this, "outputTrackJets"}; +}; + +} // namespace ActsExamples diff --git a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp new file mode 100644 index 00000000000..2509d6a7525 --- /dev/null +++ b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp @@ -0,0 +1,92 @@ +// 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/Jets/TrackToTruthJetAlgorithm.hpp" + +#include "Acts/Definitions/Units.hpp" +#include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/EventData/SimParticle.hpp" +#include "ActsExamples/Framework/AlgorithmContext.hpp" +#include "ActsFatras/EventData/ProcessType.hpp" + +#include +#include + +namespace ActsExamples { + +TrackToTruthJetAlgorithm::TrackToTruthJetAlgorithm(const Config& cfg, + Acts::Logging::Level lvl) + : IAlgorithm("TrackToTruthJetAlgorithm", lvl), m_cfg(cfg) { + if (m_cfg.inputTracks.empty()) { + throw std::invalid_argument("Input tracks are not configured"); + } + if (m_cfg.inputJets.empty()) { + throw std::invalid_argument("Input tracks are not configured"); + } + m_inputTracks.initialize(m_cfg.inputTracks); + m_inputJets.initialize(m_cfg.inputJets); + m_outputTrackJets.initialize(m_cfg.outputTrackJets); +} + +ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( + const ActsExamples::AlgorithmContext& ctx) const { + ACTS_INFO("Executing track to truth jet matching algorithm"); + + const auto& tracks = m_inputTracks(ctx); + const auto& jets = m_inputJets(ctx); + ACTS_DEBUG("TrackToTruthJetAlg - Number of tracks: " << tracks.size()); + ACTS_DEBUG("TrackToTruthJetAlg - Number of jets: " << jets.size()); + + for(const auto& track: tracks) { + + double minDeltaR = m_cfg.maxDeltaR; + int closestJetIndex = -1; + + double trackEnergy = sqrt(track.absoluteMomentum()*track.absoluteMomentum()); // need to add mass here! + + ACTS_DEBUG("Track index: " << track.index() << ", momentum: " << track.momentum().x() << ", " << track.momentum().y() << ", " << track.momentum().z() << ", energy: " << trackEnergy); + + // Create a fastjet::PseudoJet object for the track + fastjet::PseudoJet trackJet(track.momentum().x(), track.momentum().y(), track.momentum().z(), trackEnergy); + trackJet.set_user_index(track.index()); + + // Loop over the jets to find the closest one + for (size_t i = 0; i < jets.size(); ++i) { + const auto& jet = jets[i]; + + ACTS_DEBUG("Jet index: " << i << ", momentum: " << jet.px() << ", " << jet.py() << ", " << jet.pz() << ", energy: " << jet.e()); + + if (trackJet.delta_R(jet) < minDeltaR) { + minDeltaR = trackJet.delta_R(jet); + closestJetIndex = i; + } + + ACTS_DEBUG("Track " << track.index() << " delta R to jet " << i << ": " << trackJet.delta_R(jet)); + + } // loop over jets + + // Properties of the closest jet + if (closestJetIndex != -1) { + const auto& closestJet = jets[closestJetIndex]; + ACTS_DEBUG("Closest jet index: " << closestJetIndex << ", delta R: " << minDeltaR); + ACTS_DEBUG("Closest jet momentum: " << closestJet.px() << ", " << closestJet.py() << ", " << closestJet.pz() << ", energy: " << closestJet.e()); + } else { + ACTS_DEBUG("No jet found within delta R: " << m_cfg.maxDeltaR); + } + } // loop over tracks + + + return ProcessCode::SUCCESS; +} + +ProcessCode ActsExamples::TrackToTruthJetAlgorithm::finalize() const { + ACTS_INFO("Executing track to truth jet matching algorithm"); + return ProcessCode::SUCCESS; +} + +}; // namespace ActsExamples diff --git a/Examples/Python/python/acts/examples/simulation.py b/Examples/Python/python/acts/examples/simulation.py index 2f6e967f38c..84597042567 100644 --- a/Examples/Python/python/acts/examples/simulation.py +++ b/Examples/Python/python/acts/examples/simulation.py @@ -59,6 +59,11 @@ defaults=[None, None], ) +TrackToTruthJetConfig = namedtuple( + "TrackToTruthJetConfig", + ["inputTracks", "inputJets", "outputTrackJets", "maxDeltaR"], + defaults=[None, None, None, None], +) def _getParticleSelectionKWargs(config: ParticleSelectorConfig) -> dict: return { @@ -96,6 +101,13 @@ def _getTruthJetKWargs(config: TruthJetConfig) -> dict: "jetPtMin": config.jetPtMin, } +def _getTrackToTruthJetKWargs(config: TruthJetConfig) -> dict: + return { + "inputTracks": config.inputTracks, + "inputJets": config.inputJets, + "outputTrackJets": config.outputTrackJets, + "maxDeltaR": config.maxDeltaR + } @acts.examples.NamedTypeArgs( momentumConfig=MomentumConfig, @@ -866,3 +878,18 @@ def addTruthJetAlg( ) s.addAlgorithm(truthJetAlg) + +def addTrackToTruthJetAlg( + s: acts.examples.Sequencer, + config: TrackToTruthJetConfig, + loglevel: Optional[acts.logging.Level] = None, +) -> None: + from acts.examples import TrackToTruthJetAlgorithm + + customLogLevel = acts.examples.defaultLogging(s, loglevel) + trackToTruthJetAlg = acts.examples.TrackToTruthJetAlgorithm( + **acts.examples.defaultKWArgs(**_getTrackToTruthJetKWargs(config)), + level=customLogLevel(), + ) + + s.addAlgorithm(trackToTruthJetAlg) diff --git a/Examples/Python/src/ModuleEntry.cpp b/Examples/Python/src/ModuleEntry.cpp index fa891821a43..944e1f10b55 100644 --- a/Examples/Python/src/ModuleEntry.cpp +++ b/Examples/Python/src/ModuleEntry.cpp @@ -54,6 +54,7 @@ void addTruthTracking(Context& ctx); void addTrackFitting(Context& ctx); void addTrackFinding(Context& ctx); void addTruthJet(Context& ctx); +void addTrackToTruthJet(Context& ctx); void addVertexing(Context& ctx); void addAmbiguityResolution(Context& ctx); void addUtilities(Context& ctx); @@ -131,6 +132,7 @@ PYBIND11_MODULE(ActsPythonBindings, m) { addTrackFitting(ctx); addTrackFinding(ctx); addTruthJet(ctx); + addTrackToTruthJet(ctx); addVertexing(ctx); addAmbiguityResolution(ctx); addUtilities(ctx); diff --git a/Examples/Python/src/TruthJet.cpp b/Examples/Python/src/TruthJet.cpp index 1981e5ca3b3..af8a90da0e4 100644 --- a/Examples/Python/src/TruthJet.cpp +++ b/Examples/Python/src/TruthJet.cpp @@ -8,8 +8,7 @@ #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/Jets/TruthJetAlgorithm.hpp" -#include "ActsPython/Utilities/Helpers.hpp" -#include "ActsPython/Utilities/Macros.hpp" +#include "ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp" #include #include @@ -29,4 +28,14 @@ void addTruthJet(Context& ctx) { ACTS_PYTHON_DECLARE_ALGORITHM(TruthJetAlgorithm, mex, "TruthJetAlgorithm", inputTruthParticles, outputJets, jetPtMin); } // addTruthJet -} // namespace ActsPython + +void addTrackToTruthJet(Context& ctx) { + auto mex = ctx.get("examples"); + + ACTS_PYTHON_DECLARE_ALGORITHM(ActsExamples::TrackToTruthJetAlgorithm, mex, + "TrackToTruthJetAlgorithm", inputTracks, inputJets, + outputTrackJets, maxDeltaR); + +} // addTrackToTruthJet + +} // namespace Acts::Python diff --git a/Examples/Python/src/TruthJetStub.cpp b/Examples/Python/src/TruthJetStub.cpp index ec1138366ea..da38644cbbd 100644 --- a/Examples/Python/src/TruthJetStub.cpp +++ b/Examples/Python/src/TruthJetStub.cpp @@ -11,4 +11,5 @@ namespace ActsPython { void addTruthJet(Context& /*ctx*/) {} -} // namespace ActsPython +void addTrackToTruthJet(Context& /*ctx*/) {} +} // namespace Acts::Python From 7b1de37328d0ae05f8bca60929336487638b8803 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Wed, 28 May 2025 13:14:13 +0200 Subject: [PATCH 02/25] Add TrackJetContainer --- .../ActsExamples/Jets/TruthJetAlgorithm.hpp | 4 +- .../Algorithms/Jets/src/TruthJetAlgorithm.cpp | 41 +++++++- .../ActsExamples/EventData/TrackJet.hpp | 99 +++++++++++++++++++ 3 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp diff --git a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TruthJetAlgorithm.hpp b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TruthJetAlgorithm.hpp index de735ae2ca8..d368f7dcf54 100644 --- a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TruthJetAlgorithm.hpp +++ b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TruthJetAlgorithm.hpp @@ -10,6 +10,7 @@ #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/EventData/SimParticle.hpp" +#include "ActsExamples/EventData/TrackJet.hpp" #include "ActsExamples/Framework/DataHandle.hpp" #include "ActsExamples/Framework/IAlgorithm.hpp" #include "ActsExamples/Framework/ProcessCode.hpp" @@ -45,8 +46,7 @@ class TruthJetAlgorithm final : public IAlgorithm { Config m_cfg; ReadDataHandle m_inputTruthParticles{ this, "inputTruthParticles"}; - WriteDataHandle> m_outputJets{this, - "outputJets"}; + WriteDataHandle m_outputJets{this, "outputJets"}; }; } // namespace ActsExamples diff --git a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp index c1656b3bc27..6b5c79ba54f 100644 --- a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp @@ -35,6 +35,8 @@ TruthJetAlgorithm::TruthJetAlgorithm(const Config& cfg, ProcessCode ActsExamples::TruthJetAlgorithm::execute( const ActsExamples::AlgorithmContext& ctx) const { + TrackJetContainer outputJets; + const auto& truthParticles = m_inputTruthParticles(ctx); ACTS_DEBUG("Number of truth particles: " << truthParticles.size()); @@ -57,15 +59,50 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( particleIndex++; } ACTS_DEBUG("Number of input pseudo jets: " << inputPseudoJets.size()); + // Run the jet clustering fastjet::ClusterSequence clusterSeq(inputPseudoJets, defaultJetDefinition); + // Get the jets above a certain pt threshold std::vector jets = sorted_by_pt(clusterSeq.inclusive_jets(m_cfg.jetPtMin)); ACTS_DEBUG("Number of clustered jets: " << jets.size()); - // Store the jets in the output data handle - m_outputJets(ctx, std::move(jets)); + // Prepare jets for the storage - conversion of jets to custom track jet class + // (and later add here the jet classification) + + for (unsigned int i = 0; i < jets.size(); i++) { + // Get information on the jet constituents + std::vector jetConstituents = jets[i].constituents(); + std::vector constituentIndices; + constituentIndices.reserve(jetConstituents.size()); + + // Get the jet classification label later here! For now, we use "unknown" + ActsExamples::jetlabel label = ActsExamples::unknown; + + Acts::Vector4 jetFourMomentum(jets[i].px(), jets[i].py(), jets[i].pz(), + jets[i].e()); + + // Initialize the (track) jet with 4-momentum and jet label + ActsExamples::TrackJet storedJet(jetFourMomentum, label); + + // Add the jet constituents to the (track)jet + for (unsigned int j = 0; j < jetConstituents.size(); j++) { + // Get the index of the constituent in the original input pseudo jets + constituentIndices.push_back(jetConstituents[j].user_index()); + } + + storedJet.setConstituents(constituentIndices); + + outputJets.push_back(storedJet); + ACTS_DEBUG("Stored jet " << i << " with 4-momentum: " << jetFourMomentum(0) + << ", " << jetFourMomentum(1) << ", " + << jetFourMomentum(2) << ", " << jetFourMomentum(3) + << " and " << constituentIndices.size() + << " constituents."); + } + + m_outputJets(ctx, std::move(outputJets)); return ProcessCode::SUCCESS; } diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp new file mode 100644 index 00000000000..12870d64619 --- /dev/null +++ b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp @@ -0,0 +1,99 @@ +// 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/Definitions/Algebra.hpp" + +#include +#include + +namespace ActsExamples { + +enum jetlabel { unknown = -99, ljet = 0, cjet = 4, bjet = 5 }; + +enum hadronlabel { + Hadron = 1, + BBbarMesonPart = 2, + CCbarMesonPart = 3, + BottomMesonPart = 4, + BottomBaryonPart = 5, + CharmedMesonPart = 6, + CharmedBaryonPart = 7, + StrangeMesonPart = 8, + StrangeBaryonPart = 9, + LightMesonPart = 10, + LightBaryonPart = 11, + Unknown = 12 +}; + +class TrackJet { + public: + TrackJet(const Acts::Vector4& fm) { + m_fourMomentum = fm; + m_label = ActsExamples::unknown; + } + + TrackJet(const Acts::Vector4& fm, const ActsExamples::jetlabel jl) { + m_fourMomentum = fm; + m_label = jl; + } + + void setLabel(const ActsExamples::jetlabel jl) { m_label = jl; } + + ActsExamples::jetlabel getLabel() const { return m_label; } + + // TODO::Pass references instead of copies. + + void setConstituents(const std::vector constituents) { + m_constituents = constituents; + } + + std::vector getConstituents() const { return m_constituents; } + + Acts::Vector4 getFourMomentum() const { return m_fourMomentum; } + + void addTrack(const int trk_idx) { m_trk_idxs.push_back(trk_idx); } + + std::vector getTracks() const { return m_trk_idxs; } + + void print() const { + std::cout << "Printing Jet information" << std::endl; + std::cout << "4mom=(" << m_fourMomentum(0) << "," << m_fourMomentum(1) + << "," << m_fourMomentum(2) << "," << m_fourMomentum(3) << ")" + << std::endl; + + std::cout << "Formed by " << m_constituents.size() << std::endl; + + for (auto& constituent : m_constituents) { + std::cout << constituent << " "; + } + std::cout << std::endl; + + std::cout << "With " << m_trk_idxs.size() << " associated tracks" + << std::endl; + for (auto& trkidx : m_trk_idxs) { + std::cout << trkidx << " "; + } + std::cout << std::endl; + }; + + private: + Acts::Vector4 m_fourMomentum{0., 0., 0., 0.}; + ActsExamples::jetlabel m_label{ActsExamples::unknown}; + + // The indices of the constituexonts wrt the global container + std::vector m_constituents{}; + + // The indices of the tracks associated to this jet + std::vector m_trk_idxs{}; +}; + +using TrackJetContainer = std::vector; + +} // namespace ActsExamples From 6dcc100d35d8195185a574e84daa73f4faf94641 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 22 Sep 2025 14:06:29 +0200 Subject: [PATCH 03/25] CMakeList fix 1 --- Examples/Algorithms/Jets/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Examples/Algorithms/Jets/CMakeLists.txt b/Examples/Algorithms/Jets/CMakeLists.txt index b6eb557b5d8..c52309bc253 100644 --- a/Examples/Algorithms/Jets/CMakeLists.txt +++ b/Examples/Algorithms/Jets/CMakeLists.txt @@ -1,10 +1,8 @@ -acts_add_library(ExamplesJets SHARED src/TruthJetAlgorithm.cpp) -======= add_library(ActsExamplesJets SHARED src/TruthJetAlgorithm.cpp src/TrackToTruthJetAlgorithm.cpp) ->>>>>>> ee1e83592 (Initialize TrackToTruthJetAlg) + target_include_directories( ActsExamplesJets PUBLIC $ From 97a8b5924a039ecb358f59ef05f02e0230f69eef Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Wed, 28 May 2025 17:11:41 +0200 Subject: [PATCH 04/25] Fix 2 --- Examples/Algorithms/Jets/CMakeLists.txt | 9 +- .../Jets/TrackToTruthJetAlgorithm.hpp | 9 +- .../Jets/src/TrackToTruthJetAlgorithm.cpp | 87 +++++---- .../Algorithms/Jets/src/TruthJetAlgorithm.cpp | 2 +- .../ActsExamples/EventData/TrackJet.hpp | 4 +- .../Python/python/acts/examples/simulation.py | 8 +- Examples/Python/src/TruthJet.cpp | 8 +- .../Scripts/Python/track_to_truth_test.py | 178 ++++++++++++++++++ 8 files changed, 252 insertions(+), 53 deletions(-) create mode 100644 Examples/Scripts/Python/track_to_truth_test.py diff --git a/Examples/Algorithms/Jets/CMakeLists.txt b/Examples/Algorithms/Jets/CMakeLists.txt index c52309bc253..3e2c0a9e099 100644 --- a/Examples/Algorithms/Jets/CMakeLists.txt +++ b/Examples/Algorithms/Jets/CMakeLists.txt @@ -1,8 +1,9 @@ -add_library(ActsExamplesJets - SHARED +add_library( + ActsExamplesJets + SHARED src/TruthJetAlgorithm.cpp - src/TrackToTruthJetAlgorithm.cpp) - + src/TrackToTruthJetAlgorithm.cpp +) target_include_directories( ActsExamplesJets PUBLIC $ diff --git a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp index c21f1bebfdb..37d97504770 100644 --- a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp +++ b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp @@ -8,9 +8,11 @@ #pragma once +#include "Acts/Definitions/Algebra.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/EventData/SimParticle.hpp" #include "ActsExamples/EventData/Track.hpp" +#include "ActsExamples/EventData/TrackJet.hpp" #include "ActsExamples/Framework/DataHandle.hpp" #include "ActsExamples/Framework/IAlgorithm.hpp" #include "ActsExamples/Framework/ProcessCode.hpp" @@ -47,9 +49,10 @@ class TrackToTruthJetAlgorithm : public IAlgorithm { private: Config m_cfg; - ReadDataHandle m_inputTracks {this, "inputTracks"}; - ReadDataHandle> m_inputJets {this, "inputJets"}; - WriteDataHandle> m_outputTrackJets {this, "outputTrackJets"}; + ReadDataHandle m_inputTracks{this, "inputTracks"}; + ReadDataHandle m_inputJets{this, + "inputJets"}; + WriteDataHandle m_outputTrackJets{this, "outputTrackJets"}; }; } // namespace ActsExamples diff --git a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp index 2509d6a7525..6f83db4f9da 100644 --- a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp @@ -20,7 +20,7 @@ namespace ActsExamples { TrackToTruthJetAlgorithm::TrackToTruthJetAlgorithm(const Config& cfg, - Acts::Logging::Level lvl) + Acts::Logging::Level lvl) : IAlgorithm("TrackToTruthJetAlgorithm", lvl), m_cfg(cfg) { if (m_cfg.inputTracks.empty()) { throw std::invalid_argument("Input tracks are not configured"); @@ -35,57 +35,70 @@ TrackToTruthJetAlgorithm::TrackToTruthJetAlgorithm(const Config& cfg, ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( const ActsExamples::AlgorithmContext& ctx) const { - ACTS_INFO("Executing track to truth jet matching algorithm"); + ACTS_INFO("Executing track to truth jet matching algorithm"); + + const auto& tracks = m_inputTracks(ctx); + TrackJetContainer jets; + jets = m_inputJets(ctx); + + ACTS_DEBUG("TrackToTruthJetAlg - Number of tracks: " << tracks.size()); + ACTS_DEBUG("TrackToTruthJetAlg - Number of jets: " << jets.size()); - const auto& tracks = m_inputTracks(ctx); - const auto& jets = m_inputJets(ctx); - ACTS_DEBUG("TrackToTruthJetAlg - Number of tracks: " << tracks.size()); - ACTS_DEBUG("TrackToTruthJetAlg - Number of jets: " << jets.size()); + for (const auto& track : tracks) { + double minDeltaR = m_cfg.maxDeltaR; + int closestJetIndex = -1; - for(const auto& track: tracks) { + double trackEnergy = + sqrt(track.absoluteMomentum() * + track.absoluteMomentum()); // need to add mass here! - double minDeltaR = m_cfg.maxDeltaR; - int closestJetIndex = -1; + ACTS_DEBUG("Track index: " + << track.index() << ", momentum: " << track.momentum().x() + << ", " << track.momentum().y() << ", " << track.momentum().z() + << ", energy: " << trackEnergy); - double trackEnergy = sqrt(track.absoluteMomentum()*track.absoluteMomentum()); // need to add mass here! - - ACTS_DEBUG("Track index: " << track.index() << ", momentum: " << track.momentum().x() << ", " << track.momentum().y() << ", " << track.momentum().z() << ", energy: " << trackEnergy); - - // Create a fastjet::PseudoJet object for the track - fastjet::PseudoJet trackJet(track.momentum().x(), track.momentum().y(), track.momentum().z(), trackEnergy); - trackJet.set_user_index(track.index()); + // Create a fastjet::PseudoJet object for the track + fastjet::PseudoJet trackJet(track.momentum().x(), track.momentum().y(), + track.momentum().z(), trackEnergy); + trackJet.set_user_index(track.index()); - // Loop over the jets to find the closest one - for (size_t i = 0; i < jets.size(); ++i) { - const auto& jet = jets[i]; + // Loop over the jets to find the closest one + for (std::size_t i = 0; i < jets.size(); ++i) { + const auto& jet = jets[i]; - ACTS_DEBUG("Jet index: " << i << ", momentum: " << jet.px() << ", " << jet.py() << ", " << jet.pz() << ", energy: " << jet.e()); + // Create a fastjet::PseudoJet object for the jet + fastjet::PseudoJet jetPseudo(jet.getFourMomentum()(0), + jet.getFourMomentum()(1), + jet.getFourMomentum()(2), + jet.getFourMomentum()(3)); - if (trackJet.delta_R(jet) < minDeltaR) { - minDeltaR = trackJet.delta_R(jet); - closestJetIndex = i; - } + // TODO: instead pseudo jet use directly eta phi from trackjet + if (trackJet.delta_R(jetPseudo) < minDeltaR) { + minDeltaR = trackJet.delta_R(jetPseudo); + closestJetIndex = i; + } - ACTS_DEBUG("Track " << track.index() << " delta R to jet " << i << ": " << trackJet.delta_R(jet)); + ACTS_DEBUG("Track " << track.index() << " delta R to jet " << i << ": " + << trackJet.delta_R(jetPseudo)); - } // loop over jets + } // loop over jets - // Properties of the closest jet - if (closestJetIndex != -1) { - const auto& closestJet = jets[closestJetIndex]; - ACTS_DEBUG("Closest jet index: " << closestJetIndex << ", delta R: " << minDeltaR); - ACTS_DEBUG("Closest jet momentum: " << closestJet.px() << ", " << closestJet.py() << ", " << closestJet.pz() << ", energy: " << closestJet.e()); - } else { - ACTS_DEBUG("No jet found within delta R: " << m_cfg.maxDeltaR); - } - } // loop over tracks - + // Properties of the closest jet + if (closestJetIndex != -1) { + ACTS_DEBUG("Adding track " << track.index() << " to jet " << closestJetIndex ); + jets[closestJetIndex].addTrack(track.index()); + + } else { + ACTS_DEBUG("No jet found within delta R: " << m_cfg.maxDeltaR); + } + + } // loop over tracks return ProcessCode::SUCCESS; } ProcessCode ActsExamples::TrackToTruthJetAlgorithm::finalize() const { - ACTS_INFO("Executing track to truth jet matching algorithm"); + ACTS_INFO("Finalizing track to truth jet matching algorithm"); return ProcessCode::SUCCESS; } diff --git a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp index 6b5c79ba54f..57b81138ec6 100644 --- a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp @@ -79,7 +79,7 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( // Get the jet classification label later here! For now, we use "unknown" ActsExamples::jetlabel label = ActsExamples::unknown; - + Acts::Vector4 jetFourMomentum(jets[i].px(), jets[i].py(), jets[i].pz(), jets[i].e()); diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp index 12870d64619..bd6bfec378d 100644 --- a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp @@ -14,9 +14,9 @@ #include namespace ActsExamples { - +// TODO: Capitalize enum names for consistency enum jetlabel { unknown = -99, ljet = 0, cjet = 4, bjet = 5 }; - +// TODO: Remove hadronlabel enum hadronlabel { Hadron = 1, BBbarMesonPart = 2, diff --git a/Examples/Python/python/acts/examples/simulation.py b/Examples/Python/python/acts/examples/simulation.py index 84597042567..0100c3987d3 100644 --- a/Examples/Python/python/acts/examples/simulation.py +++ b/Examples/Python/python/acts/examples/simulation.py @@ -65,6 +65,7 @@ defaults=[None, None, None, None], ) + def _getParticleSelectionKWargs(config: ParticleSelectorConfig) -> dict: return { "rhoMin": config.rho[0], @@ -101,14 +102,16 @@ def _getTruthJetKWargs(config: TruthJetConfig) -> dict: "jetPtMin": config.jetPtMin, } + def _getTrackToTruthJetKWargs(config: TruthJetConfig) -> dict: return { "inputTracks": config.inputTracks, "inputJets": config.inputJets, "outputTrackJets": config.outputTrackJets, - "maxDeltaR": config.maxDeltaR + "maxDeltaR": config.maxDeltaR, } + @acts.examples.NamedTypeArgs( momentumConfig=MomentumConfig, etaConfig=EtaConfig, @@ -879,13 +882,14 @@ def addTruthJetAlg( s.addAlgorithm(truthJetAlg) + def addTrackToTruthJetAlg( s: acts.examples.Sequencer, config: TrackToTruthJetConfig, loglevel: Optional[acts.logging.Level] = None, ) -> None: from acts.examples import TrackToTruthJetAlgorithm - + customLogLevel = acts.examples.defaultLogging(s, loglevel) trackToTruthJetAlg = acts.examples.TrackToTruthJetAlgorithm( **acts.examples.defaultKWArgs(**_getTrackToTruthJetKWargs(config)), diff --git a/Examples/Python/src/TruthJet.cpp b/Examples/Python/src/TruthJet.cpp index af8a90da0e4..713bbf994a4 100644 --- a/Examples/Python/src/TruthJet.cpp +++ b/Examples/Python/src/TruthJet.cpp @@ -7,8 +7,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Utilities/Logger.hpp" -#include "ActsExamples/Jets/TruthJetAlgorithm.hpp" #include "ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp" +#include "ActsExamples/Jets/TruthJetAlgorithm.hpp" #include #include @@ -33,9 +33,9 @@ void addTrackToTruthJet(Context& ctx) { auto mex = ctx.get("examples"); ACTS_PYTHON_DECLARE_ALGORITHM(ActsExamples::TrackToTruthJetAlgorithm, mex, - "TrackToTruthJetAlgorithm", inputTracks, inputJets, - outputTrackJets, maxDeltaR); - + "TrackToTruthJetAlgorithm", inputTracks, + inputJets, outputTrackJets, maxDeltaR); + } // addTrackToTruthJet } // namespace Acts::Python diff --git a/Examples/Scripts/Python/track_to_truth_test.py b/Examples/Scripts/Python/track_to_truth_test.py new file mode 100644 index 00000000000..5986618a2cf --- /dev/null +++ b/Examples/Scripts/Python/track_to_truth_test.py @@ -0,0 +1,178 @@ +#!/usr/bin/env python3 + +from pathlib import Path +from typing import Optional + +import acts +import acts.examples + +from truth_tracking_kalman import runTruthTrackingKalman + +u = acts.UnitConstants + +from acts.examples.simulation import ( + addParticleGun, + ParticleConfig, + EtaConfig, + PhiConfig, + MomentumConfig, + TruthJetConfig, + TrackToTruthJetConfig, + addFatras, + addPythia8, + addTruthJetAlg, + addTrackToTruthJetAlg, + addDigitization, + ParticleSelectorConfig, + addDigiParticleSelection, +) +from acts.examples.reconstruction import ( + addSeeding, + SeedingAlgorithm, + addKalmanTracks, +) + +s = acts.examples.Sequencer( + events=1, numThreads=-1, logLevel=acts.logging.INFO +) +outputDir = "/Users/delitez/atlas/acts_v2/ci-dependencies/trackToTruth_output" + +from acts.examples.odd import getOpenDataDetector + +detector = getOpenDataDetector() +trackingGeometry = detector.trackingGeometry() +digiConfigFile = "/Users/delitez/atlas/acts_v2/ci-dependencies/acts/Examples/Configs/odd-digi-smearing-config.json" + +field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T)) + + +rnd = acts.examples.RandomNumbers(seed=42) +outputDir = Path(outputDir) + +addPythia8( + s, + nhard=1, + npileup=1, + hardProcess=["Top:qqbar2ttbar=on"], + vtxGen=acts.examples.GaussianVertexGenerator( + mean=acts.Vector4(0, 0, 0, 0), + stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns), + ), + rnd=rnd, + outputDirRoot=outputDir, + outputDirCsv=outputDir, + writeHepMC3=outputDir + ) + +addFatras( + s, + trackingGeometry, + field, + rnd=rnd, + enableInteractions=True, +) + + +addDigitization( + s, + trackingGeometry, + field, + digiConfigFile=digiConfigFile, + rnd=rnd, + ) + +addDigiParticleSelection( + s, + ParticleSelectorConfig( + pt=(0.9 * u.GeV, None), + measurements=(7, None), + removeNeutral=True, + removeSecondaries=True, + ), + ) + +addSeeding( + s, + trackingGeometry, + field, + rnd=rnd, + inputParticles="particles_generated", + seedingAlgorithm=SeedingAlgorithm.TruthSmeared, + particleHypothesis=acts.ParticleHypothesis.muon, + ) + +reverseFilteringMomThreshold=0 * u.GeV + +addKalmanTracks( + s, + trackingGeometry, + field, + reverseFilteringMomThreshold, + ) + +s.addAlgorithm( + acts.examples.TrackSelectorAlgorithm( + level=acts.logging.INFO, + inputTracks="tracks", + outputTracks="selected-tracks", + selectorConfig=acts.TrackSelector.Config( + minMeasurements=7, + ), + ) + ) +s.addWhiteboardAlias("tracks", "selected-tracks") + +s.addWriter( + acts.examples.RootTrackStatesWriter( + level=acts.logging.INFO, + inputTracks="tracks", + inputParticles="particles_selected", + inputTrackParticleMatching="track_particle_matching", + inputSimHits="simhits", + inputMeasurementSimHitsMap="measurement_simhits_map", + filePath=str(outputDir / "trackstates_kf.root"), + ) + ) + +s.addWriter( + acts.examples.RootTrackSummaryWriter( + level=acts.logging.INFO, + inputTracks="tracks", + inputParticles="particles_selected", + inputTrackParticleMatching="track_particle_matching", + filePath=str(outputDir / "tracksummary_kf.root"), + ) + ) + +s.addWriter( + acts.examples.TrackFitterPerformanceWriter( + level=acts.logging.INFO, + inputTracks="tracks", + inputParticles="particles_selected", + inputTrackParticleMatching="track_particle_matching", + filePath=str(outputDir / "performance_kf.root"), + ) + ) + +addTruthJetAlg( + s, + TruthJetConfig( + inputTruthParticles="particles_generated_selected", + outputJets="truth_jets", + jetPtMin=1 * u.GeV, + ), + loglevel=acts.logging.DEBUG, +) + +addTrackToTruthJetAlg( + s, + TrackToTruthJetConfig( + inputTracks="tracks", + inputJets="truth_jets", + outputTrackJets="track_jets", + maxDeltaR=0.4 + ), + loglevel=acts.logging.DEBUG +) + +s.run() \ No newline at end of file From 2ac9be3c11f530b36850f1e8c6ff8be5b0fddd5c Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Fri, 6 Jun 2025 10:37:57 +0200 Subject: [PATCH 05/25] Bug fix in tracktotruthalg --- .../Jets/src/TrackToTruthJetAlgorithm.cpp | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp index 6f83db4f9da..e46820c0858 100644 --- a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp @@ -38,11 +38,17 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( ACTS_INFO("Executing track to truth jet matching algorithm"); const auto& tracks = m_inputTracks(ctx); - TrackJetContainer jets; - jets = m_inputJets(ctx); + const auto& truthJets = m_inputJets(ctx); + TrackJetContainer jets; // track jets to be filled + //copy truth jets to jets + for (const auto& jet : truthJets) { + jets.emplace_back(jet.getFourMomentum(), jet.getLabel()); + jets.back().setConstituents(jet.getConstituents()); + } - ACTS_DEBUG("TrackToTruthJetAlg - Number of tracks: " << tracks.size()); - ACTS_DEBUG("TrackToTruthJetAlg - Number of jets: " << jets.size()); + ACTS_INFO("TrackToTruthJetAlg - Number of tracks: " << tracks.size()); + ACTS_INFO("TrackToTruthJetAlg - Number of truth jets: " << truthJets.size()); + ACTS_INFO("TrackToTruthJetAlg - Number of jets: " << jets.size()); for (const auto& track : tracks) { double minDeltaR = m_cfg.maxDeltaR; @@ -52,10 +58,10 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( sqrt(track.absoluteMomentum() * track.absoluteMomentum()); // need to add mass here! - ACTS_DEBUG("Track index: " - << track.index() << ", momentum: " << track.momentum().x() - << ", " << track.momentum().y() << ", " << track.momentum().z() - << ", energy: " << trackEnergy); + // ACTS_DEBUG("Track index: " + // << track.index() << ", momentum: " << track.momentum().x() + // << ", " << track.momentum().y() << ", " << track.momentum().z() + // << ", energy: " << trackEnergy); // Create a fastjet::PseudoJet object for the track fastjet::PseudoJet trackJet(track.momentum().x(), track.momentum().y(), @@ -80,19 +86,23 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( ACTS_DEBUG("Track " << track.index() << " delta R to jet " << i << ": " << trackJet.delta_R(jetPseudo)); + if(closestJetIndex != -1) { + ACTS_DEBUG("Closest jet so far: " << closestJetIndex + << " with delta R: " << minDeltaR); + } } // loop over jets - // Properties of the closest jet if (closestJetIndex != -1) { ACTS_DEBUG("Adding track " << track.index() << " to jet " << closestJetIndex ); jets[closestJetIndex].addTrack(track.index()); - - } else { - ACTS_DEBUG("No jet found within delta R: " << m_cfg.maxDeltaR); } } // loop over tracks + + // Write the matched jets to the output + m_outputTrackJets(ctx, std::move(jets)); + return ProcessCode::SUCCESS; } From c9f34339cd843baedeec7da8215678bafa20f356 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 22 Sep 2025 15:13:59 +0200 Subject: [PATCH 06/25] ActsPython related fix --- Examples/Algorithms/Jets/CMakeLists.txt | 9 ++------- Examples/Python/src/TruthJet.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Examples/Algorithms/Jets/CMakeLists.txt b/Examples/Algorithms/Jets/CMakeLists.txt index 3e2c0a9e099..651d65aad0b 100644 --- a/Examples/Algorithms/Jets/CMakeLists.txt +++ b/Examples/Algorithms/Jets/CMakeLists.txt @@ -1,16 +1,11 @@ -add_library( - ActsExamplesJets - SHARED - src/TruthJetAlgorithm.cpp - src/TrackToTruthJetAlgorithm.cpp -) +acts_add_library(ExamplesJets SHARED src/TruthJetAlgorithm.cpp src/TrackToTruthJetAlgorithm.cpp) target_include_directories( ActsExamplesJets PUBLIC $ ) target_link_libraries( ActsExamplesJets - PUBLIC Acts::PluginFastJet Acts::ExamplesFramework + PUBLIC Acts::Core Acts::PluginFastJet Acts::ExamplesFramework ) acts_compile_headers(ExamplesJets GLOB "include/**/*.hpp") diff --git a/Examples/Python/src/TruthJet.cpp b/Examples/Python/src/TruthJet.cpp index 713bbf994a4..311a3da7770 100644 --- a/Examples/Python/src/TruthJet.cpp +++ b/Examples/Python/src/TruthJet.cpp @@ -7,8 +7,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Utilities/Logger.hpp" -#include "ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp" #include "ActsExamples/Jets/TruthJetAlgorithm.hpp" +#include "ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp" +#include "ActsPython/Utilities/Helpers.hpp" +#include "ActsPython/Utilities/Macros.hpp" #include #include @@ -32,10 +34,9 @@ void addTruthJet(Context& ctx) { void addTrackToTruthJet(Context& ctx) { auto mex = ctx.get("examples"); - ACTS_PYTHON_DECLARE_ALGORITHM(ActsExamples::TrackToTruthJetAlgorithm, mex, + ACTS_PYTHON_DECLARE_ALGORITHM(TrackToTruthJetAlgorithm, mex, "TrackToTruthJetAlgorithm", inputTracks, inputJets, outputTrackJets, maxDeltaR); - } // addTrackToTruthJet -} // namespace Acts::Python +} // namespace ActsPython \ No newline at end of file From 7c93d73e31cb60b7ba0ebddfcb99008ca6ed8f59 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 22 Sep 2025 16:26:46 +0200 Subject: [PATCH 07/25] Update TrackToTruthJetAlg --- .../Jets/TrackToTruthJetAlgorithm.hpp | 7 +- .../Jets/src/TrackToTruthJetAlgorithm.cpp | 108 ++++++++++-------- 2 files changed, 61 insertions(+), 54 deletions(-) diff --git a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp index 37d97504770..43f38845ea8 100644 --- a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp +++ b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp @@ -43,16 +43,15 @@ class TrackToTruthJetAlgorithm : public IAlgorithm { TrackToTruthJetAlgorithm(const Config& cfg, Acts::Logging::Level lvl); ProcessCode execute(const AlgorithmContext& ctx) const override; - ProcessCode finalize() const; + ProcessCode finalize() override; const Config& config() const { return m_cfg; } private: Config m_cfg; ReadDataHandle m_inputTracks{this, "inputTracks"}; - ReadDataHandle m_inputJets{this, - "inputJets"}; + ReadDataHandle m_inputJets{this, "inputJets"}; WriteDataHandle m_outputTrackJets{this, "outputTrackJets"}; }; -} // namespace ActsExamples +} // namespace ActsExamples \ No newline at end of file diff --git a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp index e46820c0858..0e4f72c024c 100644 --- a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp @@ -8,11 +8,8 @@ #include "ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp" -#include "Acts/Definitions/Units.hpp" #include "Acts/Utilities/Logger.hpp" -#include "ActsExamples/EventData/SimParticle.hpp" #include "ActsExamples/Framework/AlgorithmContext.hpp" -#include "ActsFatras/EventData/ProcessType.hpp" #include #include @@ -35,81 +32,92 @@ TrackToTruthJetAlgorithm::TrackToTruthJetAlgorithm(const Config& cfg, ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( const ActsExamples::AlgorithmContext& ctx) const { - ACTS_INFO("Executing track to truth jet matching algorithm"); + ACTS_DEBUG("Executing track to truth jet matching algorithm"); const auto& tracks = m_inputTracks(ctx); const auto& truthJets = m_inputJets(ctx); - TrackJetContainer jets; // track jets to be filled - //copy truth jets to jets - for (const auto& jet : truthJets) { - jets.emplace_back(jet.getFourMomentum(), jet.getLabel()); - jets.back().setConstituents(jet.getConstituents()); - } + // Take a copy that we will modify + TrackJetContainer jets = truthJets; - ACTS_INFO("TrackToTruthJetAlg - Number of tracks: " << tracks.size()); - ACTS_INFO("TrackToTruthJetAlg - Number of truth jets: " << truthJets.size()); - ACTS_INFO("TrackToTruthJetAlg - Number of jets: " << jets.size()); + ACTS_DEBUG("TrackToTruthJetAlg - Number of tracks: " << tracks.size()); + ACTS_DEBUG("TrackToTruthJetAlg - Number of truth jets: " << truthJets.size()); + ACTS_DEBUG("TrackToTruthJetAlg - Number of jets: " << jets.size()); for (const auto& track : tracks) { double minDeltaR = m_cfg.maxDeltaR; - int closestJetIndex = -1; - - double trackEnergy = - sqrt(track.absoluteMomentum() * - track.absoluteMomentum()); // need to add mass here! - // ACTS_DEBUG("Track index: " - // << track.index() << ", momentum: " << track.momentum().x() - // << ", " << track.momentum().y() << ", " << track.momentum().z() - // << ", energy: " << trackEnergy); + ACTS_VERBOSE("Track index: " << track.index() + << ", momentum: " << track.momentum().x() + << ", " << track.momentum().y() << ", " + << track.momentum().z()); - // Create a fastjet::PseudoJet object for the track - fastjet::PseudoJet trackJet(track.momentum().x(), track.momentum().y(), - track.momentum().z(), trackEnergy); - trackJet.set_user_index(track.index()); + TrackJet* matchedJet = nullptr; // Loop over the jets to find the closest one - for (std::size_t i = 0; i < jets.size(); ++i) { - const auto& jet = jets[i]; - - // Create a fastjet::PseudoJet object for the jet - fastjet::PseudoJet jetPseudo(jet.getFourMomentum()(0), - jet.getFourMomentum()(1), - jet.getFourMomentum()(2), - jet.getFourMomentum()(3)); - - // TODO: instead pseudo jet use directly eta phi from trackjet - if (trackJet.delta_R(jetPseudo) < minDeltaR) { - minDeltaR = trackJet.delta_R(jetPseudo); - closestJetIndex = i; + std::size_t i = 0; + for (auto& jet : jets) { + // Calculate eta and phi of the jet and track + + double jetPx = jet.getFourMomentum().x(); + double jetPy = jet.getFourMomentum().y(); + double jetPz = jet.getFourMomentum().z(); + double trackPx = track.momentum().x(); + double trackPy = track.momentum().y(); + double trackPz = track.momentum().z(); + double pjet = std::sqrt(jetPx * jetPx + jetPy * jetPy + jetPz * jetPz); + double ptrack = + std::sqrt(trackPx * trackPx + trackPy * trackPy + trackPz * trackPz); + + // Calculate eta and phi for the jet and track + // Note: eta = arctanh(pz/|p|), phi = atan2(py, px) + // where theta is the polar angle of the momentum vector + // and phi is the azimuthal angle in the xy-plane. + // Here we use the four-momentum to calculate eta and phi. + + double jetEta = std::atanh(jetPz / pjet); + double jetPhi = std::atan2(jetPy, jetPx); + double trackEta = std::atanh(trackPz / ptrack); + double trackPhi = std::atan2(trackPy, trackPx); + + // Calculate delta R + double deltaEta = jetEta - trackEta; + double deltaPhi = jetPhi - trackPhi; + double deltaR = std::sqrt(deltaEta * deltaEta + deltaPhi * deltaPhi); + + // Acts::Vector3 jetMom = jet.getFourMomentum().head<3>(); + // double deltaR = Acts::VectorHelpers::deltaR(jetMom, track.momentum()); + + if (deltaR < minDeltaR) { + minDeltaR = deltaR; + matchedJet = &jet; } ACTS_DEBUG("Track " << track.index() << " delta R to jet " << i << ": " - << trackJet.delta_R(jetPseudo)); - if(closestJetIndex != -1) { - ACTS_DEBUG("Closest jet so far: " << closestJetIndex - << " with delta R: " << minDeltaR); + << deltaR + << ", jet px: " << jet.getFourMomentum().head<1>()); + if (deltaR < m_cfg.maxDeltaR) { + ACTS_DEBUG("Track " << track.index() << " matches jet " << i + << " with delta R: " << deltaR); } + i++; } // loop over jets - if (closestJetIndex != -1) { - ACTS_DEBUG("Adding track " << track.index() << " to jet " << closestJetIndex ); - jets[closestJetIndex].addTrack(track.index()); + if (matchedJet != nullptr) { + matchedJet->addTrack(track.index()); } } // loop over tracks - + // Write the matched jets to the output m_outputTrackJets(ctx, std::move(jets)); - return ProcessCode::SUCCESS; } -ProcessCode ActsExamples::TrackToTruthJetAlgorithm::finalize() const { +ProcessCode ActsExamples::TrackToTruthJetAlgorithm::finalize() { ACTS_INFO("Finalizing track to truth jet matching algorithm"); return ProcessCode::SUCCESS; } -}; // namespace ActsExamples +}; // namespace ActsExamples \ No newline at end of file From f5343c0978af5be8816656c89b9e47699b0f19c2 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 22 Sep 2025 16:55:32 +0200 Subject: [PATCH 08/25] update the run script --- .../Python/python/acts/examples/simulation.py | 33 +- Examples/Scripts/Python/track_to_truth_jet.py | 304 ++++++++++++++++++ 2 files changed, 306 insertions(+), 31 deletions(-) create mode 100644 Examples/Scripts/Python/track_to_truth_jet.py diff --git a/Examples/Python/python/acts/examples/simulation.py b/Examples/Python/python/acts/examples/simulation.py index 0100c3987d3..33cd8994e7e 100644 --- a/Examples/Python/python/acts/examples/simulation.py +++ b/Examples/Python/python/acts/examples/simulation.py @@ -53,11 +53,6 @@ defaults=[(None, None)] * 10 + [None] * 4, ) -TruthJetConfig = namedtuple( - "TruthJetConfig", - ["inputTruthParticles", "outputJets", "jetPtMin"], - defaults=[None, None], -) TrackToTruthJetConfig = namedtuple( "TrackToTruthJetConfig", @@ -95,15 +90,7 @@ def _getParticleSelectionKWargs(config: ParticleSelectorConfig) -> dict: } -def _getTruthJetKWargs(config: TruthJetConfig) -> dict: - return { - "inputTruthParticles": config.inputTruthParticles, - "outputJets": config.outputJets, - "jetPtMin": config.jetPtMin, - } - - -def _getTrackToTruthJetKWargs(config: TruthJetConfig) -> dict: +def _getTrackToTruthJetKWargs(config: TrackToTruthJetConfig) -> dict: return { "inputTracks": config.inputTracks, "inputJets": config.inputJets, @@ -867,22 +854,6 @@ def addDigiParticleSelection( ) -def addTruthJetAlg( - s: acts.examples.Sequencer, - config: TruthJetConfig, - loglevel: Optional[acts.logging.Level] = None, -) -> None: - from acts.examples import TruthJetAlgorithm - - customLogLevel = acts.examples.defaultLogging(s, loglevel) - truthJetAlg = acts.examples.TruthJetAlgorithm( - **acts.examples.defaultKWArgs(**_getTruthJetKWargs(config)), - level=customLogLevel(), - ) - - s.addAlgorithm(truthJetAlg) - - def addTrackToTruthJetAlg( s: acts.examples.Sequencer, config: TrackToTruthJetConfig, @@ -896,4 +867,4 @@ def addTrackToTruthJetAlg( level=customLogLevel(), ) - s.addAlgorithm(trackToTruthJetAlg) + s.addAlgorithm(trackToTruthJetAlg) \ No newline at end of file diff --git a/Examples/Scripts/Python/track_to_truth_jet.py b/Examples/Scripts/Python/track_to_truth_jet.py new file mode 100644 index 00000000000..97208e217b7 --- /dev/null +++ b/Examples/Scripts/Python/track_to_truth_jet.py @@ -0,0 +1,304 @@ +#!/usr/bin/env python3 + +from pathlib import Path +from typing import Optional +import argparse +from concurrent.futures import ProcessPoolExecutor, as_completed +import os +import sys +import time + +import acts +import acts.examples + +actsDir = Path(__file__).parent.parent.parent.parent + +from truth_tracking_kalman import runTruthTrackingKalman + +u = acts.UnitConstants + +from acts.examples.simulation import ( + addParticleGun, + ParticleConfig, + EtaConfig, + PhiConfig, + MomentumConfig, + TrackToTruthJetConfig, + addFatras, + addPythia8, + addTrackToTruthJetAlg, + addDigitization, + ParticleSelectorConfig, + addDigiParticleSelection, + addGenParticleSelection, +) +from acts.examples.reconstruction import ( + addSeeding, + SeedingAlgorithm, + addKalmanTracks, + addVertexFitting, + VertexFinder, +) + + +def make_sequencer( + s: acts.examples.Sequencer, outputDir: Path, detector, digiConfig, geoSel, args +): + + trackingGeometry = detector.trackingGeometry() + + field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T)) + + rnd = acts.examples.RandomNumbers(seed=42) + + addPythia8( + s, + nhard=args.hardscatter, + npileup=args.pileup, + hardProcess=["Top:qqbar2ttbar=on"], + vtxGen=acts.examples.GaussianVertexGenerator( + mean=acts.Vector4(0, 0, 0, 0), + stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns), + ), + rnd=rnd, + outputDirRoot=None, + outputDirCsv=None, + writeHepMC3=None, + ) + + # Effective truth level selection for simulation + track reconstruction + addGenParticleSelection( + s, + ParticleSelectorConfig( + rho=(0.0, 24 * u.mm), + absZ=(0.0, 1.0 * u.m), + eta=(-3.0, 3.0), + pt=(500 * u.MeV, None), + ), + ) + + addFatras( + s, + trackingGeometry, + field, + rnd=rnd, + enableInteractions=True, + ) + + addDigitization( + s, + trackingGeometry, + field, + digiConfigFile=digiConfig, + rnd=rnd, + logLevel=acts.logging.ERROR, + ) + + addDigiParticleSelection( + s, + ParticleSelectorConfig( + pt=(0.500 * u.GeV, None), + measurements=(7, None), + removeNeutral=True, + removeSecondaries=False, + ), + ) + + addSeeding( + s, + trackingGeometry, + field, + rnd=rnd, + inputParticles="particles_generated", + particleHypothesis=acts.ParticleHypothesis.pion, + seedingAlgorithm=SeedingAlgorithm.TruthEstimated, + geoSelectionConfigFile=geoSel, + initialSigmas=[ + 1 * u.mm, + 1 * u.mm, + 1 * u.degree, + 1 * u.degree, + 0 * u.e / u.GeV, + 1 * u.ns, + ], + initialSigmaQoverPt=0.1 * u.e / u.GeV, + initialSigmaPtRel=0.1, + initialVarInflation=[1.0] * 6, + ) + + reverseFilteringMomThreshold = 0 * u.GeV + + addKalmanTracks( + s, + trackingGeometry, + field, + reverseFilteringMomThreshold, + logLevel=acts.logging.FATAL, + ) + + s.addAlgorithm( + acts.examples.TrackSelectorAlgorithm( + level=acts.logging.INFO, + inputTracks="tracks", + outputTracks="selected-tracks", + selectorConfig=acts.TrackSelector.Config( + minMeasurements=7, + ), + ) + ) + s.addWhiteboardAlias("tracks", "selected-tracks") + + s.addAlgorithm( + acts.examples.ParticleSelector( + level=acts.logging.INFO, + inputParticles="particles_generated", + outputParticles="jet_input_particles", + ) + ) + + truthJetAlg = acts.examples.TruthJetAlgorithm( + level=acts.logging.DEBUG, + inputTruthParticles="jet_input_particles", + outputJets="truth_jets", + jetPtMin=10 * u.GeV + ) + + s.addAlgorithm(truthJetAlg) + + addTrackToTruthJetAlg( + s, + TrackToTruthJetConfig( + inputTracks="tracks", + inputJets="truth_jets", + outputTrackJets="track_jets", + maxDeltaR=0.4, + ), + loglevel=acts.logging.DEBUG, + ) + +def make_geometry(): + from acts.examples.odd import getOpenDataDetector, getOpenDataDetectorDirectory + + geoDir = getOpenDataDetectorDirectory() + # acts.examples.dump_args_calls(locals()) # show python binding calls + + oddMaterialMap = geoDir / "data/odd-material-maps.root" + assert oddMaterialMap.exists(), f"Material map file {oddMaterialMap} does not exist" + + oddDigiConfig = actsDir / "Examples/Configs/odd-digi-smearing-config.json" + assert oddDigiConfig.exists(), f"Digi config file {oddDigiConfig} does not exist" + + oddSeedingSel = actsDir / "Examples/Configs/odd-seeding-config.json" + assert ( + oddSeedingSel.exists() + ), f"Seeding selection file {oddSeedingSel} does not exist" + + oddMaterialDeco = acts.IMaterialDecorator.fromFile(oddMaterialMap) + + detector = getOpenDataDetector( + odd_dir=geoDir, materialDecorator=oddMaterialDeco, logLevel=acts.logging.INFO + ) + + return detector, oddDigiConfig, oddSeedingSel + + +def job(index: int, events: int, skip: int, outputDir: Path, args): + job_out = outputDir / f"proc_{index:>02d}" + job_out.mkdir(exist_ok=False) + + with (job_out / "out.log").open("w") as log_file: + os.dup2(log_file.fileno(), sys.stdout.fileno()) + os.dup2(log_file.fileno(), sys.stderr.fileno()) + + s = acts.examples.Sequencer( + events=events, + skip=skip, + numThreads=1, + logLevel=acts.logging.INFO, + outputDir=str(job_out), + trackFpes=False, + ) + + detector, oddDigiConfig, oddSeedingSel = make_geometry() + make_sequencer( + s, + job_out, + detector, + digiConfig=oddDigiConfig, + geoSel=oddSeedingSel, + args=args, + ) + + s.run() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--events", "-n", type=int, default=10) + parser.add_argument("--skip", "-s", type=int, default=0) + parser.add_argument("--pileup", "--pu", type=int, default=0) + parser.add_argument("--hardscatter", "--hs", type=int, default=1) + parser.add_argument("--threads", "-t", type=int, default=-1) + parser.add_argument("--procs", type=int, default=1) + parser.add_argument("--csv", action="store_true") + args = parser.parse_args() + + outputDir = Path.cwd() / "trackToTruth_output" + + runs = [int(f.name[1:]) for f in outputDir.glob("r*")] + next_run = max(max(runs), 0) + 1 if len(runs) > 0 else 1 + + outputDir = outputDir / f"r{next_run:03d}" + + print(outputDir) + outputDir.mkdir(exist_ok=True, parents=True) + + if args.procs == 1: + s = acts.examples.Sequencer( + events=args.events, + skip=args.skip, + numThreads=args.threads, + logLevel=acts.logging.INFO, + outputDir=str(outputDir), + trackFpes=False, + ) + + detector, oddDigiConfig, geoSel = make_geometry() + make_sequencer( + s, outputDir, detector, digiConfig=oddDigiConfig, geoSel=geoSel, args=args + ) + + s.run() + else: + + with ProcessPoolExecutor(max_workers=args.procs) as ex: + futures = [] + per_proc = args.events // args.procs + for i in range(args.procs): + skip = i * per_proc + nevents = per_proc + if i == args.procs - 1: + nevents = args.events - skip + + futures.append(ex.submit(job, i, nevents, skip, outputDir, args)) + + spin = r"/-\|" + i = 0 + while any([not f.done() for f in futures]): + time.sleep(0.25) + i += 1 + i = i % len(spin) + + ndone = len([f for f in futures if f.done()]) + sys.stdout.write(f"\r{spin[i]} {ndone} / {len(futures)} done") + print() + + for i, f in enumerate(as_completed(futures)): + try: + f.result() + except Exception as e: + print(f"Job failed with exception: {e}") + + +if __name__ == "__main__": + main() \ No newline at end of file From a205c7387c41e44c7761caf941bbb45d437cd268 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 22 Sep 2025 16:59:10 +0200 Subject: [PATCH 09/25] Run pre-commit --- Examples/Algorithms/Jets/CMakeLists.txt | 7 +- .../Jets/TrackToTruthJetAlgorithm.hpp | 2 +- .../Jets/src/TrackToTruthJetAlgorithm.cpp | 2 +- .../Algorithms/Jets/src/TruthJetAlgorithm.cpp | 2 +- .../Python/python/acts/examples/simulation.py | 2 +- Examples/Python/src/TruthJet.cpp | 4 +- Examples/Python/src/TruthJetStub.cpp | 2 +- Examples/Scripts/Python/track_to_truth_jet.py | 5 +- .../Scripts/Python/track_to_truth_test.py | 198 +++++++++--------- 9 files changed, 114 insertions(+), 110 deletions(-) diff --git a/Examples/Algorithms/Jets/CMakeLists.txt b/Examples/Algorithms/Jets/CMakeLists.txt index 651d65aad0b..988fd00f29f 100644 --- a/Examples/Algorithms/Jets/CMakeLists.txt +++ b/Examples/Algorithms/Jets/CMakeLists.txt @@ -1,4 +1,9 @@ -acts_add_library(ExamplesJets SHARED src/TruthJetAlgorithm.cpp src/TrackToTruthJetAlgorithm.cpp) +acts_add_library( + ExamplesJets + SHARED + src/TruthJetAlgorithm.cpp + src/TrackToTruthJetAlgorithm.cpp +) target_include_directories( ActsExamplesJets PUBLIC $ diff --git a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp index 43f38845ea8..aff93289ff7 100644 --- a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp +++ b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp @@ -54,4 +54,4 @@ class TrackToTruthJetAlgorithm : public IAlgorithm { WriteDataHandle m_outputTrackJets{this, "outputTrackJets"}; }; -} // namespace ActsExamples \ No newline at end of file +} // namespace ActsExamples diff --git a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp index 0e4f72c024c..9e7a35b90df 100644 --- a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp @@ -120,4 +120,4 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::finalize() { return ProcessCode::SUCCESS; } -}; // namespace ActsExamples \ No newline at end of file +}; // namespace ActsExamples diff --git a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp index 57b81138ec6..6b5c79ba54f 100644 --- a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp @@ -79,7 +79,7 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( // Get the jet classification label later here! For now, we use "unknown" ActsExamples::jetlabel label = ActsExamples::unknown; - + Acts::Vector4 jetFourMomentum(jets[i].px(), jets[i].py(), jets[i].pz(), jets[i].e()); diff --git a/Examples/Python/python/acts/examples/simulation.py b/Examples/Python/python/acts/examples/simulation.py index 33cd8994e7e..23ef5bfe1db 100644 --- a/Examples/Python/python/acts/examples/simulation.py +++ b/Examples/Python/python/acts/examples/simulation.py @@ -867,4 +867,4 @@ def addTrackToTruthJetAlg( level=customLogLevel(), ) - s.addAlgorithm(trackToTruthJetAlg) \ No newline at end of file + s.addAlgorithm(trackToTruthJetAlg) diff --git a/Examples/Python/src/TruthJet.cpp b/Examples/Python/src/TruthJet.cpp index 311a3da7770..8f23463597c 100644 --- a/Examples/Python/src/TruthJet.cpp +++ b/Examples/Python/src/TruthJet.cpp @@ -7,8 +7,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Utilities/Logger.hpp" -#include "ActsExamples/Jets/TruthJetAlgorithm.hpp" #include "ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp" +#include "ActsExamples/Jets/TruthJetAlgorithm.hpp" #include "ActsPython/Utilities/Helpers.hpp" #include "ActsPython/Utilities/Macros.hpp" @@ -39,4 +39,4 @@ void addTrackToTruthJet(Context& ctx) { inputJets, outputTrackJets, maxDeltaR); } // addTrackToTruthJet -} // namespace ActsPython \ No newline at end of file +} // namespace ActsPython diff --git a/Examples/Python/src/TruthJetStub.cpp b/Examples/Python/src/TruthJetStub.cpp index da38644cbbd..3244181a605 100644 --- a/Examples/Python/src/TruthJetStub.cpp +++ b/Examples/Python/src/TruthJetStub.cpp @@ -12,4 +12,4 @@ namespace ActsPython { void addTruthJet(Context& /*ctx*/) {} void addTrackToTruthJet(Context& /*ctx*/) {} -} // namespace Acts::Python +} // namespace ActsPython diff --git a/Examples/Scripts/Python/track_to_truth_jet.py b/Examples/Scripts/Python/track_to_truth_jet.py index 97208e217b7..2e1c0abdb46 100644 --- a/Examples/Scripts/Python/track_to_truth_jet.py +++ b/Examples/Scripts/Python/track_to_truth_jet.py @@ -160,7 +160,7 @@ def make_sequencer( level=acts.logging.DEBUG, inputTruthParticles="jet_input_particles", outputJets="truth_jets", - jetPtMin=10 * u.GeV + jetPtMin=10 * u.GeV, ) s.addAlgorithm(truthJetAlg) @@ -176,6 +176,7 @@ def make_sequencer( loglevel=acts.logging.DEBUG, ) + def make_geometry(): from acts.examples.odd import getOpenDataDetector, getOpenDataDetectorDirectory @@ -301,4 +302,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/Examples/Scripts/Python/track_to_truth_test.py b/Examples/Scripts/Python/track_to_truth_test.py index 5986618a2cf..bc40afeab25 100644 --- a/Examples/Scripts/Python/track_to_truth_test.py +++ b/Examples/Scripts/Python/track_to_truth_test.py @@ -11,30 +11,28 @@ u = acts.UnitConstants from acts.examples.simulation import ( - addParticleGun, - ParticleConfig, - EtaConfig, - PhiConfig, - MomentumConfig, - TruthJetConfig, - TrackToTruthJetConfig, - addFatras, - addPythia8, - addTruthJetAlg, - addTrackToTruthJetAlg, - addDigitization, - ParticleSelectorConfig, - addDigiParticleSelection, + addParticleGun, + ParticleConfig, + EtaConfig, + PhiConfig, + MomentumConfig, + TruthJetConfig, + TrackToTruthJetConfig, + addFatras, + addPythia8, + addTruthJetAlg, + addTrackToTruthJetAlg, + addDigitization, + ParticleSelectorConfig, + addDigiParticleSelection, ) from acts.examples.reconstruction import ( - addSeeding, - SeedingAlgorithm, - addKalmanTracks, + addSeeding, + SeedingAlgorithm, + addKalmanTracks, ) -s = acts.examples.Sequencer( - events=1, numThreads=-1, logLevel=acts.logging.INFO -) +s = acts.examples.Sequencer(events=1, numThreads=-1, logLevel=acts.logging.INFO) outputDir = "/Users/delitez/atlas/acts_v2/ci-dependencies/trackToTruth_output" from acts.examples.odd import getOpenDataDetector @@ -50,109 +48,109 @@ outputDir = Path(outputDir) addPythia8( - s, - nhard=1, - npileup=1, - hardProcess=["Top:qqbar2ttbar=on"], - vtxGen=acts.examples.GaussianVertexGenerator( - mean=acts.Vector4(0, 0, 0, 0), - stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns), - ), - rnd=rnd, - outputDirRoot=outputDir, - outputDirCsv=outputDir, - writeHepMC3=outputDir - ) + s, + nhard=1, + npileup=1, + hardProcess=["Top:qqbar2ttbar=on"], + vtxGen=acts.examples.GaussianVertexGenerator( + mean=acts.Vector4(0, 0, 0, 0), + stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns), + ), + rnd=rnd, + outputDirRoot=outputDir, + outputDirCsv=outputDir, + writeHepMC3=outputDir, +) addFatras( - s, - trackingGeometry, - field, - rnd=rnd, - enableInteractions=True, + s, + trackingGeometry, + field, + rnd=rnd, + enableInteractions=True, ) addDigitization( - s, - trackingGeometry, - field, - digiConfigFile=digiConfigFile, - rnd=rnd, - ) + s, + trackingGeometry, + field, + digiConfigFile=digiConfigFile, + rnd=rnd, +) addDigiParticleSelection( - s, - ParticleSelectorConfig( - pt=(0.9 * u.GeV, None), - measurements=(7, None), - removeNeutral=True, - removeSecondaries=True, - ), - ) + s, + ParticleSelectorConfig( + pt=(0.9 * u.GeV, None), + measurements=(7, None), + removeNeutral=True, + removeSecondaries=True, + ), +) addSeeding( - s, - trackingGeometry, - field, - rnd=rnd, - inputParticles="particles_generated", - seedingAlgorithm=SeedingAlgorithm.TruthSmeared, - particleHypothesis=acts.ParticleHypothesis.muon, - ) + s, + trackingGeometry, + field, + rnd=rnd, + inputParticles="particles_generated", + seedingAlgorithm=SeedingAlgorithm.TruthSmeared, + particleHypothesis=acts.ParticleHypothesis.muon, +) -reverseFilteringMomThreshold=0 * u.GeV +reverseFilteringMomThreshold = 0 * u.GeV addKalmanTracks( - s, - trackingGeometry, - field, - reverseFilteringMomThreshold, - ) + s, + trackingGeometry, + field, + reverseFilteringMomThreshold, +) s.addAlgorithm( - acts.examples.TrackSelectorAlgorithm( - level=acts.logging.INFO, - inputTracks="tracks", - outputTracks="selected-tracks", - selectorConfig=acts.TrackSelector.Config( - minMeasurements=7, - ), - ) + acts.examples.TrackSelectorAlgorithm( + level=acts.logging.INFO, + inputTracks="tracks", + outputTracks="selected-tracks", + selectorConfig=acts.TrackSelector.Config( + minMeasurements=7, + ), ) +) s.addWhiteboardAlias("tracks", "selected-tracks") s.addWriter( - acts.examples.RootTrackStatesWriter( - level=acts.logging.INFO, - inputTracks="tracks", - inputParticles="particles_selected", - inputTrackParticleMatching="track_particle_matching", - inputSimHits="simhits", - inputMeasurementSimHitsMap="measurement_simhits_map", - filePath=str(outputDir / "trackstates_kf.root"), - ) + acts.examples.RootTrackStatesWriter( + level=acts.logging.INFO, + inputTracks="tracks", + inputParticles="particles_selected", + inputTrackParticleMatching="track_particle_matching", + inputSimHits="simhits", + inputMeasurementSimHitsMap="measurement_simhits_map", + filePath=str(outputDir / "trackstates_kf.root"), ) +) s.addWriter( - acts.examples.RootTrackSummaryWriter( - level=acts.logging.INFO, - inputTracks="tracks", - inputParticles="particles_selected", - inputTrackParticleMatching="track_particle_matching", - filePath=str(outputDir / "tracksummary_kf.root"), - ) + acts.examples.RootTrackSummaryWriter( + level=acts.logging.INFO, + inputTracks="tracks", + inputParticles="particles_selected", + inputTrackParticleMatching="track_particle_matching", + filePath=str(outputDir / "tracksummary_kf.root"), ) +) s.addWriter( - acts.examples.TrackFitterPerformanceWriter( - level=acts.logging.INFO, - inputTracks="tracks", - inputParticles="particles_selected", - inputTrackParticleMatching="track_particle_matching", - filePath=str(outputDir / "performance_kf.root"), - ) + acts.examples.TrackFitterPerformanceWriter( + level=acts.logging.INFO, + inputTracks="tracks", + inputParticles="particles_selected", + inputTrackParticleMatching="track_particle_matching", + filePath=str(outputDir / "performance_kf.root"), ) +) addTruthJetAlg( s, @@ -170,9 +168,9 @@ inputTracks="tracks", inputJets="truth_jets", outputTrackJets="track_jets", - maxDeltaR=0.4 + maxDeltaR=0.4, ), - loglevel=acts.logging.DEBUG + loglevel=acts.logging.DEBUG, ) -s.run() \ No newline at end of file +s.run() From c1720ba3cf5193e5fee9e0723136740d9df2ff89 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Tue, 23 Sep 2025 11:55:39 +0200 Subject: [PATCH 10/25] Apply clang tidy suggestions --- .../Framework/include/ActsExamples/EventData/TrackJet.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp index bd6bfec378d..00726a35847 100644 --- a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp @@ -34,7 +34,7 @@ enum hadronlabel { class TrackJet { public: - TrackJet(const Acts::Vector4& fm) { + explicit TrackJet(const Acts::Vector4& fm) { m_fourMomentum = fm; m_label = ActsExamples::unknown; } @@ -50,7 +50,7 @@ class TrackJet { // TODO::Pass references instead of copies. - void setConstituents(const std::vector constituents) { + void setConstituents(const std::vector &constituents) { m_constituents = constituents; } From ce779729967c2475998ebc909aafd3797b9a18c3 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Tue, 23 Sep 2025 14:38:53 +0200 Subject: [PATCH 11/25] pre-commit changes --- Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp index 00726a35847..7d5011213e5 100644 --- a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp @@ -50,7 +50,7 @@ class TrackJet { // TODO::Pass references instead of copies. - void setConstituents(const std::vector &constituents) { + void setConstituents(const std::vector& constituents) { m_constituents = constituents; } From 3ea04cefaa396ac3b43707353838855717599a4f Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:09:51 +0200 Subject: [PATCH 12/25] Remove jet and hadron labels (from this PR - stay tuned) --- .../Algorithms/Jets/src/TruthJetAlgorithm.cpp | 7 ++--- .../ActsExamples/EventData/TrackJet.hpp | 28 ------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp index 6b5c79ba54f..9ef2dc6d70c 100644 --- a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp @@ -77,14 +77,11 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( std::vector constituentIndices; constituentIndices.reserve(jetConstituents.size()); - // Get the jet classification label later here! For now, we use "unknown" - ActsExamples::jetlabel label = ActsExamples::unknown; - Acts::Vector4 jetFourMomentum(jets[i].px(), jets[i].py(), jets[i].pz(), jets[i].e()); - // Initialize the (track) jet with 4-momentum and jet label - ActsExamples::TrackJet storedJet(jetFourMomentum, label); + // Initialize the (track) jet with 4-momentum + ActsExamples::TrackJet storedJet(jetFourMomentum); // Add the jet constituents to the (track)jet for (unsigned int j = 0; j < jetConstituents.size(); j++) { diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp index 7d5011213e5..36acb55a2c3 100644 --- a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp @@ -14,40 +14,13 @@ #include namespace ActsExamples { -// TODO: Capitalize enum names for consistency -enum jetlabel { unknown = -99, ljet = 0, cjet = 4, bjet = 5 }; -// TODO: Remove hadronlabel -enum hadronlabel { - Hadron = 1, - BBbarMesonPart = 2, - CCbarMesonPart = 3, - BottomMesonPart = 4, - BottomBaryonPart = 5, - CharmedMesonPart = 6, - CharmedBaryonPart = 7, - StrangeMesonPart = 8, - StrangeBaryonPart = 9, - LightMesonPart = 10, - LightBaryonPart = 11, - Unknown = 12 -}; class TrackJet { public: explicit TrackJet(const Acts::Vector4& fm) { m_fourMomentum = fm; - m_label = ActsExamples::unknown; - } - - TrackJet(const Acts::Vector4& fm, const ActsExamples::jetlabel jl) { - m_fourMomentum = fm; - m_label = jl; } - void setLabel(const ActsExamples::jetlabel jl) { m_label = jl; } - - ActsExamples::jetlabel getLabel() const { return m_label; } - // TODO::Pass references instead of copies. void setConstituents(const std::vector& constituents) { @@ -85,7 +58,6 @@ class TrackJet { private: Acts::Vector4 m_fourMomentum{0., 0., 0., 0.}; - ActsExamples::jetlabel m_label{ActsExamples::unknown}; // The indices of the constituexonts wrt the global container std::vector m_constituents{}; From cd43e7308c8936f8029f6ec5bffd35475b52caee Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:11:19 +0200 Subject: [PATCH 13/25] Some pre-commit changes --- .../Framework/include/ActsExamples/EventData/TrackJet.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp index 36acb55a2c3..fffa6b1aeff 100644 --- a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp @@ -17,9 +17,7 @@ namespace ActsExamples { class TrackJet { public: - explicit TrackJet(const Acts::Vector4& fm) { - m_fourMomentum = fm; - } + explicit TrackJet(const Acts::Vector4& fm) { m_fourMomentum = fm; } // TODO::Pass references instead of copies. From f11f83796a8f6e04cb9b7f16a95a745085267d74 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 25 Sep 2025 17:11:17 +0200 Subject: [PATCH 14/25] Rename TrackJets as Jets --- Plugins/FastJet/CMakeLists.txt | 2 +- .../include/Acts/Plugins/FastJet/{TrackJets.hpp => Jets.hpp} | 2 +- .../include/Acts/Plugins/FastJet/{TrackJets.ipp => Jets.ipp} | 0 Plugins/FastJet/src/{TrackJets.cpp => Jets.cpp} | 2 +- Tests/UnitTests/Plugins/FastJet/CMakeLists.txt | 2 +- Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename Plugins/FastJet/include/Acts/Plugins/FastJet/{TrackJets.hpp => Jets.hpp} (99%) rename Plugins/FastJet/include/Acts/Plugins/FastJet/{TrackJets.ipp => Jets.ipp} (100%) rename Plugins/FastJet/src/{TrackJets.cpp => Jets.cpp} (94%) diff --git a/Plugins/FastJet/CMakeLists.txt b/Plugins/FastJet/CMakeLists.txt index 3ff9207c538..a52dd236527 100644 --- a/Plugins/FastJet/CMakeLists.txt +++ b/Plugins/FastJet/CMakeLists.txt @@ -1,7 +1,7 @@ acts_add_library( PluginFastJet SHARED - src/TrackJets.cpp + src/Jets.cpp ACTS_INCLUDE_FOLDER include/Acts ) diff --git a/Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.hpp b/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp similarity index 99% rename from Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.hpp rename to Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp index 5a0e87a39f6..e84c1d70181 100644 --- a/Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.hpp +++ b/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp @@ -85,4 +85,4 @@ class TrackJetSequence { } // namespace Acts::FastJet -#include "TrackJets.ipp" +#include "Jets.ipp" diff --git a/Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.ipp b/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.ipp similarity index 100% rename from Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.ipp rename to Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.ipp diff --git a/Plugins/FastJet/src/TrackJets.cpp b/Plugins/FastJet/src/Jets.cpp similarity index 94% rename from Plugins/FastJet/src/TrackJets.cpp rename to Plugins/FastJet/src/Jets.cpp index f3e4c8a794c..347bb0236d0 100644 --- a/Plugins/FastJet/src/TrackJets.cpp +++ b/Plugins/FastJet/src/Jets.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 "Acts/Plugins/FastJet/TrackJets.hpp" +#include "Acts/Plugins/FastJet/Jets.hpp" namespace Acts::FastJet { diff --git a/Tests/UnitTests/Plugins/FastJet/CMakeLists.txt b/Tests/UnitTests/Plugins/FastJet/CMakeLists.txt index b20f3f8a67b..3fd93a57389 100644 --- a/Tests/UnitTests/Plugins/FastJet/CMakeLists.txt +++ b/Tests/UnitTests/Plugins/FastJet/CMakeLists.txt @@ -1,2 +1,2 @@ set(unittest_extra_libraries ActsPluginFastJet) -add_unittest(TrackJetsTests TrackJetsTests.cpp) +add_unittest(JetsTests JetsTests.cpp) diff --git a/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp b/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp index 0006b6c487c..8d972523cb2 100644 --- a/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp +++ b/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp @@ -8,7 +8,7 @@ #include -#include +#include class Track { public: From 33c9aa21220ce992304e92e78be692ba648ee360 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 25 Sep 2025 17:13:14 +0200 Subject: [PATCH 15/25] Rename TrackJetSequence as TrackJetBuilder --- .../include/Acts/Plugins/FastJet/Jets.hpp | 10 ++++---- Plugins/FastJet/src/Jets.cpp | 11 ++++---- .../Plugins/FastJet/TrackJetsTests.cpp | 25 +++++++++---------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp b/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp index e84c1d70181..222d5623e5a 100644 --- a/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp +++ b/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp @@ -47,17 +47,17 @@ class InputTracks { TrackContainer& m_tracks; }; -class TrackJetSequence { +class TrackJetBuilder { public: /// Factory function to create a sequence of track jets /// /// @param tracks the input tracks /// @jetDef the jet definition to use, defaults to "DefaultJetDefinition" - static TrackJetSequence create( + static TrackJetBuilder create( std::vector& tracks, const fastjet::JetDefinition& jetDef = DefaultJetDefinition); - static TrackJetSequence create( + static TrackJetBuilder create( std::vector&& tracks, const fastjet::JetDefinition& jetDef = DefaultJetDefinition) { return create(tracks, jetDef); @@ -74,10 +74,10 @@ class TrackJetSequence { float etaMax = 2.5); private: - /// Main constructor. Users should call "TrackJetSequence::create" instead + /// Main constructor. Users should call "TrackJetBuilder::create" instead /// /// @param clusterSeq the fastjet::ClusterSequence object - explicit TrackJetSequence(const fastjet::ClusterSequence& clusterSeq) + explicit TrackJetBuilder(const fastjet::ClusterSequence& clusterSeq) : m_clusterSeq{clusterSeq} {} fastjet::ClusterSequence m_clusterSeq{}; diff --git a/Plugins/FastJet/src/Jets.cpp b/Plugins/FastJet/src/Jets.cpp index 347bb0236d0..930590d89b7 100644 --- a/Plugins/FastJet/src/Jets.cpp +++ b/Plugins/FastJet/src/Jets.cpp @@ -10,15 +10,14 @@ namespace Acts::FastJet { -TrackJetSequence TrackJetSequence::create( - std::vector& tracks, - const fastjet::JetDefinition& jetDef) { +TrackJetBuilder TrackJetBuilder::create(std::vector& tracks, + const fastjet::JetDefinition& jetDef) { fastjet::ClusterSequence cs(tracks, jetDef); - return TrackJetSequence(cs); + return TrackJetBuilder(cs); } -std::vector TrackJetSequence::jets(float ptMin, - float etaMax) { +std::vector TrackJetBuilder::jets(float ptMin, + float etaMax) { fastjet::Selector sel_eta = fastjet::SelectorAbsEtaMax(etaMax); return sel_eta(m_clusterSeq.inclusive_jets(ptMin)); } diff --git a/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp b/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp index 8d972523cb2..a0965d68b67 100644 --- a/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp +++ b/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp @@ -62,8 +62,8 @@ BOOST_AUTO_TEST_CASE(SingleTrack) { Acts::FastJet::InputTracks inputTracks(tracks); - Acts::FastJet::TrackJetSequence jetSeq = - Acts::FastJet::TrackJetSequence::create(inputTracks.fourMomenta()); + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); std::vector jets = jetSeq.jets(); BOOST_CHECK_EQUAL(jets.size(), 1); @@ -82,8 +82,8 @@ BOOST_AUTO_TEST_CASE(TwoTracksTwoJets) { Acts::FastJet::InputTracks inputTracks(tracks); - Acts::FastJet::TrackJetSequence jetSeq = - Acts::FastJet::TrackJetSequence::create(inputTracks.fourMomenta()); + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); std::vector jets = jetSeq.jets(); BOOST_CHECK_EQUAL(jets.size(), 2); @@ -107,8 +107,8 @@ BOOST_AUTO_TEST_CASE(TwoTracksOneJet) { Acts::FastJet::InputTracks inputTracks(tracks); - Acts::FastJet::TrackJetSequence jetSeq = - Acts::FastJet::TrackJetSequence::create(inputTracks.fourMomenta()); + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); std::vector jets = jetSeq.jets(); BOOST_CHECK_EQUAL(jets.size(), 1); @@ -132,8 +132,8 @@ BOOST_AUTO_TEST_CASE(TracksInJetCore) { Acts::FastJet::InputTracks inputTracks(tracks); - Acts::FastJet::TrackJetSequence jetSeq = - Acts::FastJet::TrackJetSequence::create(inputTracks.fourMomenta()); + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); std::vector jets = jetSeq.jets(); BOOST_REQUIRE_EQUAL(jets.size(), 1); @@ -154,9 +154,8 @@ BOOST_AUTO_TEST_CASE(TracksInJetCore) { } BOOST_AUTO_TEST_CASE(EmptyTrackContainer) { - Acts::FastJet::TrackJetSequence jetSeq = - Acts::FastJet::TrackJetSequence::create( - std::vector()); + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(std::vector()); BOOST_CHECK_EQUAL(jetSeq.jets().size(), 0); } @@ -164,8 +163,8 @@ BOOST_AUTO_TEST_CASE(InvalidCoreRadius) { TrackContainer tracks; tracks.insert(Track(100, 0, 0)); Acts::FastJet::InputTracks inputTracks(tracks); - Acts::FastJet::TrackJetSequence jetSeq = - Acts::FastJet::TrackJetSequence::create(inputTracks.fourMomenta()); + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); BOOST_CHECK_THROW(inputTracks.tracksInJet(jetSeq.jets()[0], -1.0), std::invalid_argument); } From f34faff853baf47d3313f8ee19eda8501de92bf9 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Thu, 25 Sep 2025 17:24:39 +0200 Subject: [PATCH 16/25] Change another name because --- .../Plugins/FastJet/TrackJetsTests.cpp | 170 ------------------ 1 file changed, 170 deletions(-) delete mode 100644 Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp diff --git a/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp b/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp deleted file mode 100644 index a0965d68b67..00000000000 --- a/Tests/UnitTests/Plugins/FastJet/TrackJetsTests.cpp +++ /dev/null @@ -1,170 +0,0 @@ -// 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 - -#include - -class Track { - public: - static constexpr float mass = 139.57061 * Acts::UnitConstants::MeV; - - Track(float pt, float eta, float phi) { - Acts::Vector3 p3 = Acts::Vector3::Zero(); - p3[0] = pt * std::cos(phi); - p3[1] = pt * std::sin(phi); - p3[2] = pt * std::sinh(eta); - float e = std::sqrt(mass * mass + p3.squaredNorm()); - m_fourMom[0] = p3[0]; - m_fourMom[1] = p3[1]; - m_fourMom[2] = p3[2]; - m_fourMom[3] = e; - } - - Acts::Vector4 fourMomentum() const { return m_fourMom; } - - private: - Acts::Vector4 m_fourMom{}; -}; - -bool operator==(Track const& lhs, Track const& rhs) { - return lhs.fourMomentum() == rhs.fourMomentum(); -} - -class TrackContainer { - public: - using TrackProxy = Track; - - TrackContainer() = default; - void insert(Track track) { m_vec.push_back(std::move(track)); } - std::size_t size() { return m_vec.size(); } - - using ConstTrackProxy = const Track&; - ConstTrackProxy getTrack(std::size_t i) { - if (i < size()) { - return m_vec[i]; - } - throw std::runtime_error("Too few tracks"); - } - - private: - std::vector m_vec{}; -}; - -BOOST_AUTO_TEST_CASE(SingleTrack) { - TrackContainer tracks; - tracks.insert(Track(100, 0, 0)); - - Acts::FastJet::InputTracks inputTracks(tracks); - - Acts::FastJet::TrackJetBuilder jetSeq = - Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); - std::vector jets = jetSeq.jets(); - - BOOST_CHECK_EQUAL(jets.size(), 1); - BOOST_CHECK_EQUAL(jets[0].constituents().size(), 1); - BOOST_CHECK_EQUAL(jets[0].constituents()[0].user_index(), 0); - BOOST_CHECK_CLOSE(jets[0].pt(), 100, 1e-3); - BOOST_CHECK_CLOSE(jets[0].eta(), 0, 1e-3); - BOOST_CHECK_CLOSE(jets[0].phi(), 0, 1e-3); - BOOST_CHECK_CLOSE(jets[0].m(), Track::mass, 1); -} - -BOOST_AUTO_TEST_CASE(TwoTracksTwoJets) { - TrackContainer tracks; - tracks.insert(Track(100, 0, 0.0)); - tracks.insert(Track(100, 0, std::numbers::pi)); - - Acts::FastJet::InputTracks inputTracks(tracks); - - Acts::FastJet::TrackJetBuilder jetSeq = - Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); - std::vector jets = jetSeq.jets(); - - BOOST_CHECK_EQUAL(jets.size(), 2); - - std::vector trks_0 = inputTracks.tracksInJet(jets[0]); - BOOST_CHECK_EQUAL(trks_0.size(), 1); - BOOST_CHECK(trks_0[0] == tracks.getTrack(0) || - trks_0[0] == tracks.getTrack(1)); - - std::vector trks_1 = inputTracks.tracksInJet(jets[1]); - BOOST_CHECK_EQUAL(trks_1.size(), 1); - BOOST_CHECK(trks_1[0] == tracks.getTrack(0) || - trks_1[0] == tracks.getTrack(1)); - BOOST_CHECK(trks_0[0] != trks_1[0]); -} - -BOOST_AUTO_TEST_CASE(TwoTracksOneJet) { - TrackContainer tracks; - tracks.insert(Track(100, 0, 0.0)); - tracks.insert(Track(100, 0, 0.2)); - - Acts::FastJet::InputTracks inputTracks(tracks); - - Acts::FastJet::TrackJetBuilder jetSeq = - Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); - std::vector jets = jetSeq.jets(); - - BOOST_CHECK_EQUAL(jets.size(), 1); - - std::vector trks_0 = inputTracks.tracksInJet(jets[0]); - BOOST_CHECK_EQUAL(trks_0.size(), 2); - BOOST_CHECK(trks_0[0] == tracks.getTrack(0) || - trks_0[0] == tracks.getTrack(1)); - BOOST_CHECK(trks_0[1] == tracks.getTrack(0) || - trks_0[1] == tracks.getTrack(1)); - BOOST_CHECK(trks_0[0] != trks_0[1]); -} - -BOOST_AUTO_TEST_CASE(TracksInJetCore) { - TrackContainer tracks; - tracks.insert(Track(100, 0, 0)); - tracks.insert(Track(10, 0.05, 0)); - tracks.insert(Track(10, -0.05, 0)); - tracks.insert(Track(10, 0.2, 0)); - tracks.insert(Track(10, -0.2, 0)); - - Acts::FastJet::InputTracks inputTracks(tracks); - - Acts::FastJet::TrackJetBuilder jetSeq = - Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); - std::vector jets = jetSeq.jets(); - - BOOST_REQUIRE_EQUAL(jets.size(), 1); - - std::vector trks = inputTracks.tracksInJet(jets[0], 0.1); - BOOST_CHECK_EQUAL(trks.size(), 3); - - BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(0)) != - trks.end()); - BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(1)) != - trks.end()); - BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(2)) != - trks.end()); - BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(3)) == - trks.end()); - BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(4)) == - trks.end()); -} - -BOOST_AUTO_TEST_CASE(EmptyTrackContainer) { - Acts::FastJet::TrackJetBuilder jetSeq = - Acts::FastJet::TrackJetBuilder::create(std::vector()); - BOOST_CHECK_EQUAL(jetSeq.jets().size(), 0); -} - -BOOST_AUTO_TEST_CASE(InvalidCoreRadius) { - TrackContainer tracks; - tracks.insert(Track(100, 0, 0)); - Acts::FastJet::InputTracks inputTracks(tracks); - Acts::FastJet::TrackJetBuilder jetSeq = - Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); - BOOST_CHECK_THROW(inputTracks.tracksInJet(jetSeq.jets()[0], -1.0), - std::invalid_argument); -} From 2d3ffe2bd86c61819cf90eafcea64756db59720f Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Fri, 26 Sep 2025 09:42:58 +0200 Subject: [PATCH 17/25] Add forgotten file --- Tests/UnitTests/Plugins/FastJet/JetsTests.cpp | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 Tests/UnitTests/Plugins/FastJet/JetsTests.cpp diff --git a/Tests/UnitTests/Plugins/FastJet/JetsTests.cpp b/Tests/UnitTests/Plugins/FastJet/JetsTests.cpp new file mode 100644 index 00000000000..a0965d68b67 --- /dev/null +++ b/Tests/UnitTests/Plugins/FastJet/JetsTests.cpp @@ -0,0 +1,170 @@ +// 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 + +#include + +class Track { + public: + static constexpr float mass = 139.57061 * Acts::UnitConstants::MeV; + + Track(float pt, float eta, float phi) { + Acts::Vector3 p3 = Acts::Vector3::Zero(); + p3[0] = pt * std::cos(phi); + p3[1] = pt * std::sin(phi); + p3[2] = pt * std::sinh(eta); + float e = std::sqrt(mass * mass + p3.squaredNorm()); + m_fourMom[0] = p3[0]; + m_fourMom[1] = p3[1]; + m_fourMom[2] = p3[2]; + m_fourMom[3] = e; + } + + Acts::Vector4 fourMomentum() const { return m_fourMom; } + + private: + Acts::Vector4 m_fourMom{}; +}; + +bool operator==(Track const& lhs, Track const& rhs) { + return lhs.fourMomentum() == rhs.fourMomentum(); +} + +class TrackContainer { + public: + using TrackProxy = Track; + + TrackContainer() = default; + void insert(Track track) { m_vec.push_back(std::move(track)); } + std::size_t size() { return m_vec.size(); } + + using ConstTrackProxy = const Track&; + ConstTrackProxy getTrack(std::size_t i) { + if (i < size()) { + return m_vec[i]; + } + throw std::runtime_error("Too few tracks"); + } + + private: + std::vector m_vec{}; +}; + +BOOST_AUTO_TEST_CASE(SingleTrack) { + TrackContainer tracks; + tracks.insert(Track(100, 0, 0)); + + Acts::FastJet::InputTracks inputTracks(tracks); + + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); + std::vector jets = jetSeq.jets(); + + BOOST_CHECK_EQUAL(jets.size(), 1); + BOOST_CHECK_EQUAL(jets[0].constituents().size(), 1); + BOOST_CHECK_EQUAL(jets[0].constituents()[0].user_index(), 0); + BOOST_CHECK_CLOSE(jets[0].pt(), 100, 1e-3); + BOOST_CHECK_CLOSE(jets[0].eta(), 0, 1e-3); + BOOST_CHECK_CLOSE(jets[0].phi(), 0, 1e-3); + BOOST_CHECK_CLOSE(jets[0].m(), Track::mass, 1); +} + +BOOST_AUTO_TEST_CASE(TwoTracksTwoJets) { + TrackContainer tracks; + tracks.insert(Track(100, 0, 0.0)); + tracks.insert(Track(100, 0, std::numbers::pi)); + + Acts::FastJet::InputTracks inputTracks(tracks); + + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); + std::vector jets = jetSeq.jets(); + + BOOST_CHECK_EQUAL(jets.size(), 2); + + std::vector trks_0 = inputTracks.tracksInJet(jets[0]); + BOOST_CHECK_EQUAL(trks_0.size(), 1); + BOOST_CHECK(trks_0[0] == tracks.getTrack(0) || + trks_0[0] == tracks.getTrack(1)); + + std::vector trks_1 = inputTracks.tracksInJet(jets[1]); + BOOST_CHECK_EQUAL(trks_1.size(), 1); + BOOST_CHECK(trks_1[0] == tracks.getTrack(0) || + trks_1[0] == tracks.getTrack(1)); + BOOST_CHECK(trks_0[0] != trks_1[0]); +} + +BOOST_AUTO_TEST_CASE(TwoTracksOneJet) { + TrackContainer tracks; + tracks.insert(Track(100, 0, 0.0)); + tracks.insert(Track(100, 0, 0.2)); + + Acts::FastJet::InputTracks inputTracks(tracks); + + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); + std::vector jets = jetSeq.jets(); + + BOOST_CHECK_EQUAL(jets.size(), 1); + + std::vector trks_0 = inputTracks.tracksInJet(jets[0]); + BOOST_CHECK_EQUAL(trks_0.size(), 2); + BOOST_CHECK(trks_0[0] == tracks.getTrack(0) || + trks_0[0] == tracks.getTrack(1)); + BOOST_CHECK(trks_0[1] == tracks.getTrack(0) || + trks_0[1] == tracks.getTrack(1)); + BOOST_CHECK(trks_0[0] != trks_0[1]); +} + +BOOST_AUTO_TEST_CASE(TracksInJetCore) { + TrackContainer tracks; + tracks.insert(Track(100, 0, 0)); + tracks.insert(Track(10, 0.05, 0)); + tracks.insert(Track(10, -0.05, 0)); + tracks.insert(Track(10, 0.2, 0)); + tracks.insert(Track(10, -0.2, 0)); + + Acts::FastJet::InputTracks inputTracks(tracks); + + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); + std::vector jets = jetSeq.jets(); + + BOOST_REQUIRE_EQUAL(jets.size(), 1); + + std::vector trks = inputTracks.tracksInJet(jets[0], 0.1); + BOOST_CHECK_EQUAL(trks.size(), 3); + + BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(0)) != + trks.end()); + BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(1)) != + trks.end()); + BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(2)) != + trks.end()); + BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(3)) == + trks.end()); + BOOST_CHECK(std::find(trks.begin(), trks.end(), tracks.getTrack(4)) == + trks.end()); +} + +BOOST_AUTO_TEST_CASE(EmptyTrackContainer) { + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(std::vector()); + BOOST_CHECK_EQUAL(jetSeq.jets().size(), 0); +} + +BOOST_AUTO_TEST_CASE(InvalidCoreRadius) { + TrackContainer tracks; + tracks.insert(Track(100, 0, 0)); + Acts::FastJet::InputTracks inputTracks(tracks); + Acts::FastJet::TrackJetBuilder jetSeq = + Acts::FastJet::TrackJetBuilder::create(inputTracks.fourMomenta()); + BOOST_CHECK_THROW(inputTracks.tracksInJet(jetSeq.jets()[0], -1.0), + std::invalid_argument); +} From e612403df86557220d6c860f45cea21b9f1a43ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Elitez?= <108287101+delitez@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:25:01 +0200 Subject: [PATCH 18/25] Apply suggestion from @paulgessinger Co-authored-by: Paul Gessinger --- Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp index fffa6b1aeff..c1a7e1e3bad 100644 --- a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp @@ -25,7 +25,7 @@ class TrackJet { m_constituents = constituents; } - std::vector getConstituents() const { return m_constituents; } + const std::vector& getConstituents() const { return m_constituents; } Acts::Vector4 getFourMomentum() const { return m_fourMomentum; } From c28eadab4ae9e40ddd5064078c23f25a353dc6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=20Elitez?= <108287101+delitez@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:25:08 +0200 Subject: [PATCH 19/25] Apply suggestion from @paulgessinger Co-authored-by: Paul Gessinger --- Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp index c1a7e1e3bad..4596f98dab6 100644 --- a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp @@ -31,7 +31,7 @@ class TrackJet { void addTrack(const int trk_idx) { m_trk_idxs.push_back(trk_idx); } - std::vector getTracks() const { return m_trk_idxs; } + const std::vector& getTracks() const { return m_trk_idxs; } void print() const { std::cout << "Printing Jet information" << std::endl; From fef4c21df049407840c30bc2aa2605538faefbe7 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:13:24 +0200 Subject: [PATCH 20/25] Merge track and particle jet builders under fastjet plugin --- .../ActsExamples/Jets/TruthJetAlgorithm.hpp | 10 +- .../Algorithms/Jets/src/TruthJetAlgorithm.cpp | 18 +- Examples/Scripts/Python/track_to_truth_jet.py | 20 +- .../Scripts/Python/track_to_truth_test.py | 176 ------------------ .../Acts/Plugins/FastJet/TrackJets.hpp | 69 +++++++ 5 files changed, 95 insertions(+), 198 deletions(-) delete mode 100644 Examples/Scripts/Python/track_to_truth_test.py diff --git a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TruthJetAlgorithm.hpp b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TruthJetAlgorithm.hpp index d368f7dcf54..95b7e3be375 100644 --- a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TruthJetAlgorithm.hpp +++ b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TruthJetAlgorithm.hpp @@ -8,9 +8,9 @@ #pragma once +#include "Acts/Plugins/FastJet/Jets.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/EventData/SimParticle.hpp" -#include "ActsExamples/EventData/TrackJet.hpp" #include "ActsExamples/Framework/DataHandle.hpp" #include "ActsExamples/Framework/IAlgorithm.hpp" #include "ActsExamples/Framework/ProcessCode.hpp" @@ -21,6 +21,11 @@ namespace fastjet { class PseudoJet; } +namespace ActsFastJet { +class TruthJetBuilder; +class JetProperties; +} // namespace ActsFastJet + namespace ActsExamples { struct AlgorithmContext; @@ -46,7 +51,8 @@ class TruthJetAlgorithm final : public IAlgorithm { Config m_cfg; ReadDataHandle m_inputTruthParticles{ this, "inputTruthParticles"}; - WriteDataHandle m_outputJets{this, "outputJets"}; + WriteDataHandle m_outputJets{this, + "outputJets"}; }; } // namespace ActsExamples diff --git a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp index 9ef2dc6d70c..d097c51b1d8 100644 --- a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp @@ -35,7 +35,7 @@ TruthJetAlgorithm::TruthJetAlgorithm(const Config& cfg, ProcessCode ActsExamples::TruthJetAlgorithm::execute( const ActsExamples::AlgorithmContext& ctx) const { - TrackJetContainer outputJets; + Acts::FastJet::TrackJetContainer outputJets; const auto& truthParticles = m_inputTruthParticles(ctx); @@ -58,7 +58,8 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( inputPseudoJets.push_back(pseudoJet); particleIndex++; } - ACTS_DEBUG("Number of input pseudo jets: " << inputPseudoJets.size()); + ACTS_DEBUG("Number of input pseudo jets from truth particles: " + << inputPseudoJets.size()); // Run the jet clustering fastjet::ClusterSequence clusterSeq(inputPseudoJets, defaultJetDefinition); @@ -66,7 +67,7 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( // Get the jets above a certain pt threshold std::vector jets = sorted_by_pt(clusterSeq.inclusive_jets(m_cfg.jetPtMin)); - ACTS_DEBUG("Number of clustered jets: " << jets.size()); + ACTS_DEBUG("Number of clustered truth jets: " << jets.size()); // Prepare jets for the storage - conversion of jets to custom track jet class // (and later add here the jet classification) @@ -81,7 +82,7 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( jets[i].e()); // Initialize the (track) jet with 4-momentum - ActsExamples::TrackJet storedJet(jetFourMomentum); + Acts::FastJet::TruthJetBuilder storedJet(jetFourMomentum); // Add the jet constituents to the (track)jet for (unsigned int j = 0; j < jetConstituents.size(); j++) { @@ -89,14 +90,11 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( constituentIndices.push_back(jetConstituents[j].user_index()); } - storedJet.setConstituents(constituentIndices); + Acts::FastJet::JetProperties jetProps(jets[i]); + jetProps.setConstituents(constituentIndices); outputJets.push_back(storedJet); - ACTS_DEBUG("Stored jet " << i << " with 4-momentum: " << jetFourMomentum(0) - << ", " << jetFourMomentum(1) << ", " - << jetFourMomentum(2) << ", " << jetFourMomentum(3) - << " and " << constituentIndices.size() - << " constituents."); + ACTS_DEBUG("Stored jet properties: " << jetProps); } m_outputJets(ctx, std::move(outputJets)); diff --git a/Examples/Scripts/Python/track_to_truth_jet.py b/Examples/Scripts/Python/track_to_truth_jet.py index 2e1c0abdb46..e9f9143e011 100644 --- a/Examples/Scripts/Python/track_to_truth_jet.py +++ b/Examples/Scripts/Python/track_to_truth_jet.py @@ -165,16 +165,16 @@ def make_sequencer( s.addAlgorithm(truthJetAlg) - addTrackToTruthJetAlg( - s, - TrackToTruthJetConfig( - inputTracks="tracks", - inputJets="truth_jets", - outputTrackJets="track_jets", - maxDeltaR=0.4, - ), - loglevel=acts.logging.DEBUG, - ) + # addTrackToTruthJetAlg( + # s, + # TrackToTruthJetConfig( + # inputTracks="tracks", + # inputJets="truth_jets", + # outputTrackJets="track_jets", + # maxDeltaR=0.4, + # ), + # loglevel=acts.logging.DEBUG, + # ) def make_geometry(): diff --git a/Examples/Scripts/Python/track_to_truth_test.py b/Examples/Scripts/Python/track_to_truth_test.py deleted file mode 100644 index bc40afeab25..00000000000 --- a/Examples/Scripts/Python/track_to_truth_test.py +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/env python3 - -from pathlib import Path -from typing import Optional - -import acts -import acts.examples - -from truth_tracking_kalman import runTruthTrackingKalman - -u = acts.UnitConstants - -from acts.examples.simulation import ( - addParticleGun, - ParticleConfig, - EtaConfig, - PhiConfig, - MomentumConfig, - TruthJetConfig, - TrackToTruthJetConfig, - addFatras, - addPythia8, - addTruthJetAlg, - addTrackToTruthJetAlg, - addDigitization, - ParticleSelectorConfig, - addDigiParticleSelection, -) -from acts.examples.reconstruction import ( - addSeeding, - SeedingAlgorithm, - addKalmanTracks, -) - -s = acts.examples.Sequencer(events=1, numThreads=-1, logLevel=acts.logging.INFO) -outputDir = "/Users/delitez/atlas/acts_v2/ci-dependencies/trackToTruth_output" - -from acts.examples.odd import getOpenDataDetector - -detector = getOpenDataDetector() -trackingGeometry = detector.trackingGeometry() -digiConfigFile = "/Users/delitez/atlas/acts_v2/ci-dependencies/acts/Examples/Configs/odd-digi-smearing-config.json" - -field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T)) - - -rnd = acts.examples.RandomNumbers(seed=42) -outputDir = Path(outputDir) - -addPythia8( - s, - nhard=1, - npileup=1, - hardProcess=["Top:qqbar2ttbar=on"], - vtxGen=acts.examples.GaussianVertexGenerator( - mean=acts.Vector4(0, 0, 0, 0), - stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns), - ), - rnd=rnd, - outputDirRoot=outputDir, - outputDirCsv=outputDir, - writeHepMC3=outputDir, -) - -addFatras( - s, - trackingGeometry, - field, - rnd=rnd, - enableInteractions=True, -) - - -addDigitization( - s, - trackingGeometry, - field, - digiConfigFile=digiConfigFile, - rnd=rnd, -) - -addDigiParticleSelection( - s, - ParticleSelectorConfig( - pt=(0.9 * u.GeV, None), - measurements=(7, None), - removeNeutral=True, - removeSecondaries=True, - ), -) - -addSeeding( - s, - trackingGeometry, - field, - rnd=rnd, - inputParticles="particles_generated", - seedingAlgorithm=SeedingAlgorithm.TruthSmeared, - particleHypothesis=acts.ParticleHypothesis.muon, -) - -reverseFilteringMomThreshold = 0 * u.GeV - -addKalmanTracks( - s, - trackingGeometry, - field, - reverseFilteringMomThreshold, -) - -s.addAlgorithm( - acts.examples.TrackSelectorAlgorithm( - level=acts.logging.INFO, - inputTracks="tracks", - outputTracks="selected-tracks", - selectorConfig=acts.TrackSelector.Config( - minMeasurements=7, - ), - ) -) -s.addWhiteboardAlias("tracks", "selected-tracks") - -s.addWriter( - acts.examples.RootTrackStatesWriter( - level=acts.logging.INFO, - inputTracks="tracks", - inputParticles="particles_selected", - inputTrackParticleMatching="track_particle_matching", - inputSimHits="simhits", - inputMeasurementSimHitsMap="measurement_simhits_map", - filePath=str(outputDir / "trackstates_kf.root"), - ) -) - -s.addWriter( - acts.examples.RootTrackSummaryWriter( - level=acts.logging.INFO, - inputTracks="tracks", - inputParticles="particles_selected", - inputTrackParticleMatching="track_particle_matching", - filePath=str(outputDir / "tracksummary_kf.root"), - ) -) - -s.addWriter( - acts.examples.TrackFitterPerformanceWriter( - level=acts.logging.INFO, - inputTracks="tracks", - inputParticles="particles_selected", - inputTrackParticleMatching="track_particle_matching", - filePath=str(outputDir / "performance_kf.root"), - ) -) - -addTruthJetAlg( - s, - TruthJetConfig( - inputTruthParticles="particles_generated_selected", - outputJets="truth_jets", - jetPtMin=1 * u.GeV, - ), - loglevel=acts.logging.DEBUG, -) - -addTrackToTruthJetAlg( - s, - TrackToTruthJetConfig( - inputTracks="tracks", - inputJets="truth_jets", - outputTrackJets="track_jets", - maxDeltaR=0.4, - ), - loglevel=acts.logging.DEBUG, -) - -s.run() diff --git a/Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.hpp b/Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.hpp index 5a0e87a39f6..7e6382a182d 100644 --- a/Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.hpp +++ b/Plugins/FastJet/include/Acts/Plugins/FastJet/TrackJets.hpp @@ -8,6 +8,7 @@ #pragma once +#include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/Common.hpp" #include "Acts/Definitions/Units.hpp" @@ -83,6 +84,74 @@ class TrackJetSequence { fastjet::ClusterSequence m_clusterSeq{}; }; +class TruthJetBuilder { + public: + explicit TruthJetBuilder(const Acts::Vector4& fm) { m_fourMomentum = fm; } + + private: + Acts::Vector4 m_fourMomentum{0., 0., 0., 0.}; +}; + +class JetProperties { + public: + /// Constructor; saves a reference to the jet + /// @param jet the jet + explicit JetProperties(const fastjet::PseudoJet& jet) : m_jet{jet} {} + + /// @brief Set the jet constituents + /// @param constituents the indices of the constituent tracks + void setConstituents(const std::vector& constituents) { + m_constituents = constituents; + } + /// @brief Get the jet constituents + /// @return the indices of the constituent tracks + const std::vector& getConstituents() const { return m_constituents; } + + /// @brief Get the jet 4-momentum + /// @return the jet 4-momentum as an Acts::Vector4 + Acts::Vector4 getFourMomentum() const { return m_fourMomentum; } + + /// @brief Add a track to the jet + /// @param trk_idx the index of the track to add + void addTrack(const int trackIndex) { m_trackIndices.push_back(trackIndex); } + + /// @brief Get the tracks associated to this jet + /// @return the indices of the associated tracks + const std::vector& getTracks() const { return m_trackIndices; } + + /// @brief Print the jet information + friend std::ostream& operator<<(std::ostream& os, + const JetProperties& jetProps) { + os << "Jet 4-momentum: " << jetProps.getFourMomentum().transpose() + << std::endl; + os << "Constituents: "; + for (const auto& constituent : jetProps.getConstituents()) { + os << constituent << " "; + } + os << std::endl; + if (!jetProps.getTracks().empty()) { + os << "Associated tracks: "; + for (const auto& trkidx : jetProps.getTracks()) { + os << trkidx << " "; + } + os << std::endl; + } else { + os << "No associated tracks." << std::endl; + } + return os; + } + + private: + const fastjet::PseudoJet& m_jet; + Acts::Vector4 m_fourMomentum{m_jet.px(), m_jet.py(), m_jet.pz(), m_jet.e()}; + // The indices of the constituents wrt the global container + std::vector m_constituents{}; + // The indices of the tracks associated to this jet + std::vector m_trackIndices{}; +}; + +using TrackJetContainer = std::vector; + } // namespace Acts::FastJet #include "TrackJets.ipp" From da33a8567dd5f4dca2a6715d44c5fe8c26dfa917 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:43:15 +0200 Subject: [PATCH 21/25] Fixes for TruthJetBuilder --- .../Jets/TrackToTruthJetAlgorithm.hpp | 10 +++++----- .../Jets/src/TrackToTruthJetAlgorithm.cpp | 18 ++++++++++-------- .../Algorithms/Jets/src/TruthJetAlgorithm.cpp | 2 +- .../include/Acts/Plugins/FastJet/Jets.hpp | 8 +++++--- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp index aff93289ff7..fa99e35e881 100644 --- a/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp +++ b/Examples/Algorithms/Jets/include/ActsExamples/Jets/TrackToTruthJetAlgorithm.hpp @@ -9,10 +9,10 @@ #pragma once #include "Acts/Definitions/Algebra.hpp" +#include "Acts/Plugins/FastJet/Jets.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/EventData/SimParticle.hpp" #include "ActsExamples/EventData/Track.hpp" -#include "ActsExamples/EventData/TrackJet.hpp" #include "ActsExamples/Framework/DataHandle.hpp" #include "ActsExamples/Framework/IAlgorithm.hpp" #include "ActsExamples/Framework/ProcessCode.hpp" @@ -20,8 +20,6 @@ #include #include -#include -#include namespace ActsExamples { struct AlgorithmContext; @@ -50,8 +48,10 @@ class TrackToTruthJetAlgorithm : public IAlgorithm { private: Config m_cfg; ReadDataHandle m_inputTracks{this, "inputTracks"}; - ReadDataHandle m_inputJets{this, "inputJets"}; - WriteDataHandle m_outputTrackJets{this, "outputTrackJets"}; + ReadDataHandle m_inputJets{this, + "inputJets"}; + WriteDataHandle m_outputTrackJets{ + this, "outputTrackJets"}; }; } // namespace ActsExamples diff --git a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp index 9e7a35b90df..7ce76cdd18b 100644 --- a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp @@ -37,7 +37,7 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( const auto& tracks = m_inputTracks(ctx); const auto& truthJets = m_inputJets(ctx); // Take a copy that we will modify - TrackJetContainer jets = truthJets; + Acts::FastJet::TrackJetContainer jets = truthJets; ACTS_DEBUG("TrackToTruthJetAlg - Number of tracks: " << tracks.size()); ACTS_DEBUG("TrackToTruthJetAlg - Number of truth jets: " << truthJets.size()); @@ -51,16 +51,16 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( << ", " << track.momentum().y() << ", " << track.momentum().z()); - TrackJet* matchedJet = nullptr; + Acts::FastJet::TruthJetBuilder* matchedJet = nullptr; // Loop over the jets to find the closest one std::size_t i = 0; for (auto& jet : jets) { - // Calculate eta and phi of the jet and track + Acts::FastJet::JetProperties jetProps(jet); - double jetPx = jet.getFourMomentum().x(); - double jetPy = jet.getFourMomentum().y(); - double jetPz = jet.getFourMomentum().z(); + double jetPx = jetProps.getFourMomentum().x(); + double jetPy = jetProps.getFourMomentum().y(); + double jetPz = jetProps.getFourMomentum().z(); double trackPx = track.momentum().x(); double trackPy = track.momentum().y(); double trackPz = track.momentum().z(); @@ -94,7 +94,7 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( ACTS_DEBUG("Track " << track.index() << " delta R to jet " << i << ": " << deltaR - << ", jet px: " << jet.getFourMomentum().head<1>()); + << ", jet px: " << jetProps.getFourMomentum().x()); if (deltaR < m_cfg.maxDeltaR) { ACTS_DEBUG("Track " << track.index() << " matches jet " << i << " with delta R: " << deltaR); @@ -103,8 +103,10 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( i++; } // loop over jets + Acts::FastJet::JetProperties matchedJetProps(*matchedJet); + if (matchedJet != nullptr) { - matchedJet->addTrack(track.index()); + matchedJetProps.addTrack(track.index()); } } // loop over tracks diff --git a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp index d097c51b1d8..3bef376361d 100644 --- a/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TruthJetAlgorithm.cpp @@ -90,7 +90,7 @@ ProcessCode ActsExamples::TruthJetAlgorithm::execute( constituentIndices.push_back(jetConstituents[j].user_index()); } - Acts::FastJet::JetProperties jetProps(jets[i]); + Acts::FastJet::JetProperties jetProps(storedJet); jetProps.setConstituents(constituentIndices); outputJets.push_back(storedJet); diff --git a/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp b/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp index e3869e6896d..451925a9b48 100644 --- a/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp +++ b/Plugins/FastJet/include/Acts/Plugins/FastJet/Jets.hpp @@ -87,6 +87,7 @@ class TrackJetBuilder { class TruthJetBuilder { public: explicit TruthJetBuilder(const Acts::Vector4& fm) { m_fourMomentum = fm; } + const Acts::Vector4 getTruthJetFourMomentum() const { return m_fourMomentum; } private: Acts::Vector4 m_fourMomentum{0., 0., 0., 0.}; @@ -96,7 +97,8 @@ class JetProperties { public: /// Constructor; saves a reference to the jet /// @param jet the jet - explicit JetProperties(const fastjet::PseudoJet& jet) : m_jet{jet} {} + explicit JetProperties(const TruthJetBuilder& truthJet) + : m_truthJet{truthJet} {} /// @brief Set the jet constituents /// @param constituents the indices of the constituent tracks @@ -142,8 +144,8 @@ class JetProperties { } private: - const fastjet::PseudoJet& m_jet; - Acts::Vector4 m_fourMomentum{m_jet.px(), m_jet.py(), m_jet.pz(), m_jet.e()}; + const TruthJetBuilder& m_truthJet; + Acts::Vector4 m_fourMomentum{m_truthJet.getTruthJetFourMomentum()}; // The indices of the constituents wrt the global container std::vector m_constituents{}; // The indices of the tracks associated to this jet From e3661c03c20fcc6b699c4c844462ad09bce22dec Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Mon, 29 Sep 2025 11:39:54 +0200 Subject: [PATCH 22/25] Delete TrackJet.hpp --- .../ActsExamples/EventData/TrackJet.hpp | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100644 Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp diff --git a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp b/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp deleted file mode 100644 index 4596f98dab6..00000000000 --- a/Examples/Framework/include/ActsExamples/EventData/TrackJet.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// 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/Definitions/Algebra.hpp" - -#include -#include - -namespace ActsExamples { - -class TrackJet { - public: - explicit TrackJet(const Acts::Vector4& fm) { m_fourMomentum = fm; } - - // TODO::Pass references instead of copies. - - void setConstituents(const std::vector& constituents) { - m_constituents = constituents; - } - - const std::vector& getConstituents() const { return m_constituents; } - - Acts::Vector4 getFourMomentum() const { return m_fourMomentum; } - - void addTrack(const int trk_idx) { m_trk_idxs.push_back(trk_idx); } - - const std::vector& getTracks() const { return m_trk_idxs; } - - void print() const { - std::cout << "Printing Jet information" << std::endl; - std::cout << "4mom=(" << m_fourMomentum(0) << "," << m_fourMomentum(1) - << "," << m_fourMomentum(2) << "," << m_fourMomentum(3) << ")" - << std::endl; - - std::cout << "Formed by " << m_constituents.size() << std::endl; - - for (auto& constituent : m_constituents) { - std::cout << constituent << " "; - } - std::cout << std::endl; - - std::cout << "With " << m_trk_idxs.size() << " associated tracks" - << std::endl; - for (auto& trkidx : m_trk_idxs) { - std::cout << trkidx << " "; - } - std::cout << std::endl; - }; - - private: - Acts::Vector4 m_fourMomentum{0., 0., 0., 0.}; - - // The indices of the constituexonts wrt the global container - std::vector m_constituents{}; - - // The indices of the tracks associated to this jet - std::vector m_trk_idxs{}; -}; - -using TrackJetContainer = std::vector; - -} // namespace ActsExamples From ff8733393d67dbf1b67431d88a06f7be3937d5ca Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Tue, 30 Sep 2025 16:53:15 +0200 Subject: [PATCH 23/25] Remove extra script and add jet clustering into full_chain_odd --- Examples/Scripts/Python/full_chain_odd.py | 88 +++++ Examples/Scripts/Python/track_to_truth_jet.py | 305 ------------------ Examples/Scripts/Python/truth_jet_test.py | 36 --- 3 files changed, 88 insertions(+), 341 deletions(-) delete mode 100644 Examples/Scripts/Python/track_to_truth_jet.py delete mode 100644 Examples/Scripts/Python/truth_jet_test.py diff --git a/Examples/Scripts/Python/full_chain_odd.py b/Examples/Scripts/Python/full_chain_odd.py index 35cc91a960c..7ef0672ce39 100755 --- a/Examples/Scripts/Python/full_chain_odd.py +++ b/Examples/Scripts/Python/full_chain_odd.py @@ -12,8 +12,10 @@ PhiConfig, ParticleConfig, ParticleSelectorConfig, + TrackToTruthJetConfig, addParticleGun, addPythia8, + addTrackToTruthJetAlg, addGenParticleSelection, addFatras, addGeant4, @@ -23,8 +25,10 @@ ) from acts.examples.reconstruction import ( addSeeding, + SeedingAlgorithm, CkfConfig, addCKFTracks, + addKalmanTracks, TrackSelectorConfig, addAmbiguityResolution, AmbiguityResolutionConfig, @@ -142,6 +146,12 @@ default=True, action=argparse.BooleanOptionalAction, ) +parser.add_argument( + "--jet-clustering", + help="Switch jet clustering on/off", + default=False, + action=argparse.BooleanOptionalAction, +) args = parser.parse_args() @@ -182,6 +192,10 @@ outputDir=str(outputDir), ) +if args.jet_clustering: + args.reco = False # disable track reco if jet clustering is requested + args.ttbar = True # force ttbar for jet clustering + if args.edm4hep: import acts.examples.edm4hep from acts.examples.podio import PodioReader @@ -330,6 +344,80 @@ ), ) +if args.jet_clustering: + addSeeding( + s, + trackingGeometry, + field, + rnd=rnd, + inputParticles="particles_generated", + particleHypothesis=acts.ParticleHypothesis.pion, + seedingAlgorithm=SeedingAlgorithm.TruthEstimated, + geoSelectionConfigFile=oddSeedingSel, + initialSigmas=[ + 1 * u.mm, + 1 * u.mm, + 1 * u.degree, + 1 * u.degree, + 0 * u.e / u.GeV, + 1 * u.ns, + ], + initialSigmaQoverPt=0.1 * u.e / u.GeV, + initialSigmaPtRel=0.1, + initialVarInflation=[1.0] * 6, + ) + + reverseFilteringMomThreshold = 0 * u.GeV + + addKalmanTracks( + s, + trackingGeometry, + field, + reverseFilteringMomThreshold, + logLevel=acts.logging.FATAL, + ) + + s.addAlgorithm( + acts.examples.TrackSelectorAlgorithm( + level=acts.logging.INFO, + inputTracks="tracks", + outputTracks="selected-tracks", + selectorConfig=acts.TrackSelector.Config( + minMeasurements=7, + ), + ) + ) + s.addWhiteboardAlias("tracks", "selected-tracks") + + s.addAlgorithm( + acts.examples.ParticleSelector( + level=acts.logging.INFO, + inputParticles="particles_generated", + outputParticles="jet_input_particles", + ) + ) + + truthJetAlg = acts.examples.TruthJetAlgorithm( + level=acts.logging.DEBUG, + inputTruthParticles="jet_input_particles", + outputJets="truth_jets", + jetPtMin=10 * u.GeV, + inputHepMC3Event="pythia8-event", + ) + + s.addAlgorithm(truthJetAlg) + + addTrackToTruthJetAlg( + s, + TrackToTruthJetConfig( + inputTracks="tracks", + inputJets="truth_jets", + outputTrackJets="track_jets", + maxDeltaR=0.4, + ), + loglevel=acts.logging.INFO, + ) + if args.reco: addSeeding( s, diff --git a/Examples/Scripts/Python/track_to_truth_jet.py b/Examples/Scripts/Python/track_to_truth_jet.py deleted file mode 100644 index e9f9143e011..00000000000 --- a/Examples/Scripts/Python/track_to_truth_jet.py +++ /dev/null @@ -1,305 +0,0 @@ -#!/usr/bin/env python3 - -from pathlib import Path -from typing import Optional -import argparse -from concurrent.futures import ProcessPoolExecutor, as_completed -import os -import sys -import time - -import acts -import acts.examples - -actsDir = Path(__file__).parent.parent.parent.parent - -from truth_tracking_kalman import runTruthTrackingKalman - -u = acts.UnitConstants - -from acts.examples.simulation import ( - addParticleGun, - ParticleConfig, - EtaConfig, - PhiConfig, - MomentumConfig, - TrackToTruthJetConfig, - addFatras, - addPythia8, - addTrackToTruthJetAlg, - addDigitization, - ParticleSelectorConfig, - addDigiParticleSelection, - addGenParticleSelection, -) -from acts.examples.reconstruction import ( - addSeeding, - SeedingAlgorithm, - addKalmanTracks, - addVertexFitting, - VertexFinder, -) - - -def make_sequencer( - s: acts.examples.Sequencer, outputDir: Path, detector, digiConfig, geoSel, args -): - - trackingGeometry = detector.trackingGeometry() - - field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T)) - - rnd = acts.examples.RandomNumbers(seed=42) - - addPythia8( - s, - nhard=args.hardscatter, - npileup=args.pileup, - hardProcess=["Top:qqbar2ttbar=on"], - vtxGen=acts.examples.GaussianVertexGenerator( - mean=acts.Vector4(0, 0, 0, 0), - stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns), - ), - rnd=rnd, - outputDirRoot=None, - outputDirCsv=None, - writeHepMC3=None, - ) - - # Effective truth level selection for simulation + track reconstruction - addGenParticleSelection( - s, - ParticleSelectorConfig( - rho=(0.0, 24 * u.mm), - absZ=(0.0, 1.0 * u.m), - eta=(-3.0, 3.0), - pt=(500 * u.MeV, None), - ), - ) - - addFatras( - s, - trackingGeometry, - field, - rnd=rnd, - enableInteractions=True, - ) - - addDigitization( - s, - trackingGeometry, - field, - digiConfigFile=digiConfig, - rnd=rnd, - logLevel=acts.logging.ERROR, - ) - - addDigiParticleSelection( - s, - ParticleSelectorConfig( - pt=(0.500 * u.GeV, None), - measurements=(7, None), - removeNeutral=True, - removeSecondaries=False, - ), - ) - - addSeeding( - s, - trackingGeometry, - field, - rnd=rnd, - inputParticles="particles_generated", - particleHypothesis=acts.ParticleHypothesis.pion, - seedingAlgorithm=SeedingAlgorithm.TruthEstimated, - geoSelectionConfigFile=geoSel, - initialSigmas=[ - 1 * u.mm, - 1 * u.mm, - 1 * u.degree, - 1 * u.degree, - 0 * u.e / u.GeV, - 1 * u.ns, - ], - initialSigmaQoverPt=0.1 * u.e / u.GeV, - initialSigmaPtRel=0.1, - initialVarInflation=[1.0] * 6, - ) - - reverseFilteringMomThreshold = 0 * u.GeV - - addKalmanTracks( - s, - trackingGeometry, - field, - reverseFilteringMomThreshold, - logLevel=acts.logging.FATAL, - ) - - s.addAlgorithm( - acts.examples.TrackSelectorAlgorithm( - level=acts.logging.INFO, - inputTracks="tracks", - outputTracks="selected-tracks", - selectorConfig=acts.TrackSelector.Config( - minMeasurements=7, - ), - ) - ) - s.addWhiteboardAlias("tracks", "selected-tracks") - - s.addAlgorithm( - acts.examples.ParticleSelector( - level=acts.logging.INFO, - inputParticles="particles_generated", - outputParticles="jet_input_particles", - ) - ) - - truthJetAlg = acts.examples.TruthJetAlgorithm( - level=acts.logging.DEBUG, - inputTruthParticles="jet_input_particles", - outputJets="truth_jets", - jetPtMin=10 * u.GeV, - ) - - s.addAlgorithm(truthJetAlg) - - # addTrackToTruthJetAlg( - # s, - # TrackToTruthJetConfig( - # inputTracks="tracks", - # inputJets="truth_jets", - # outputTrackJets="track_jets", - # maxDeltaR=0.4, - # ), - # loglevel=acts.logging.DEBUG, - # ) - - -def make_geometry(): - from acts.examples.odd import getOpenDataDetector, getOpenDataDetectorDirectory - - geoDir = getOpenDataDetectorDirectory() - # acts.examples.dump_args_calls(locals()) # show python binding calls - - oddMaterialMap = geoDir / "data/odd-material-maps.root" - assert oddMaterialMap.exists(), f"Material map file {oddMaterialMap} does not exist" - - oddDigiConfig = actsDir / "Examples/Configs/odd-digi-smearing-config.json" - assert oddDigiConfig.exists(), f"Digi config file {oddDigiConfig} does not exist" - - oddSeedingSel = actsDir / "Examples/Configs/odd-seeding-config.json" - assert ( - oddSeedingSel.exists() - ), f"Seeding selection file {oddSeedingSel} does not exist" - - oddMaterialDeco = acts.IMaterialDecorator.fromFile(oddMaterialMap) - - detector = getOpenDataDetector( - odd_dir=geoDir, materialDecorator=oddMaterialDeco, logLevel=acts.logging.INFO - ) - - return detector, oddDigiConfig, oddSeedingSel - - -def job(index: int, events: int, skip: int, outputDir: Path, args): - job_out = outputDir / f"proc_{index:>02d}" - job_out.mkdir(exist_ok=False) - - with (job_out / "out.log").open("w") as log_file: - os.dup2(log_file.fileno(), sys.stdout.fileno()) - os.dup2(log_file.fileno(), sys.stderr.fileno()) - - s = acts.examples.Sequencer( - events=events, - skip=skip, - numThreads=1, - logLevel=acts.logging.INFO, - outputDir=str(job_out), - trackFpes=False, - ) - - detector, oddDigiConfig, oddSeedingSel = make_geometry() - make_sequencer( - s, - job_out, - detector, - digiConfig=oddDigiConfig, - geoSel=oddSeedingSel, - args=args, - ) - - s.run() - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("--events", "-n", type=int, default=10) - parser.add_argument("--skip", "-s", type=int, default=0) - parser.add_argument("--pileup", "--pu", type=int, default=0) - parser.add_argument("--hardscatter", "--hs", type=int, default=1) - parser.add_argument("--threads", "-t", type=int, default=-1) - parser.add_argument("--procs", type=int, default=1) - parser.add_argument("--csv", action="store_true") - args = parser.parse_args() - - outputDir = Path.cwd() / "trackToTruth_output" - - runs = [int(f.name[1:]) for f in outputDir.glob("r*")] - next_run = max(max(runs), 0) + 1 if len(runs) > 0 else 1 - - outputDir = outputDir / f"r{next_run:03d}" - - print(outputDir) - outputDir.mkdir(exist_ok=True, parents=True) - - if args.procs == 1: - s = acts.examples.Sequencer( - events=args.events, - skip=args.skip, - numThreads=args.threads, - logLevel=acts.logging.INFO, - outputDir=str(outputDir), - trackFpes=False, - ) - - detector, oddDigiConfig, geoSel = make_geometry() - make_sequencer( - s, outputDir, detector, digiConfig=oddDigiConfig, geoSel=geoSel, args=args - ) - - s.run() - else: - - with ProcessPoolExecutor(max_workers=args.procs) as ex: - futures = [] - per_proc = args.events // args.procs - for i in range(args.procs): - skip = i * per_proc - nevents = per_proc - if i == args.procs - 1: - nevents = args.events - skip - - futures.append(ex.submit(job, i, nevents, skip, outputDir, args)) - - spin = r"/-\|" - i = 0 - while any([not f.done() for f in futures]): - time.sleep(0.25) - i += 1 - i = i % len(spin) - - ndone = len([f for f in futures if f.done()]) - sys.stdout.write(f"\r{spin[i]} {ndone} / {len(futures)} done") - print() - - for i, f in enumerate(as_completed(futures)): - try: - f.result() - except Exception as e: - print(f"Job failed with exception: {e}") - - -if __name__ == "__main__": - main() diff --git a/Examples/Scripts/Python/truth_jet_test.py b/Examples/Scripts/Python/truth_jet_test.py deleted file mode 100644 index 20e0d14ff08..00000000000 --- a/Examples/Scripts/Python/truth_jet_test.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 -import acts -import acts.examples -from acts.examples.simulation import addPythia8, addTruthJetAlg, TruthJetConfig - - -outputDir = "./truth_jet_test_output" -u = acts.UnitConstants -rnd = acts.examples.RandomNumbers(seed=42) - -s = acts.examples.Sequencer(events=10, outputDir=outputDir) - -addPythia8( - s, - hardProcess=["Top:qqbar2ttbar=on"], - npileup=50, - vtxGen=acts.examples.GaussianVertexGenerator( - mean=acts.Vector4(0, 0, 0, 0), - stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 5.0 * u.ns), - ), - rnd=rnd, - outputDirRoot=outputDir, - outputDirCsv=outputDir, -) - -addTruthJetAlg( - s, - TruthJetConfig( - inputTruthParticles="particles_generated", - outputJets="output_jets", - jetPtMin=20 * u.GeV, - ), - loglevel=acts.logging.INFO, -) - -s.run() From 366a45e357c3989e05260f46a72c67baeb071530 Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:10:45 +0200 Subject: [PATCH 24/25] Fix for full_chain_odd --- Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp | 3 +-- Examples/Scripts/Python/full_chain_odd.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp index 7ce76cdd18b..8773beaf9e5 100644 --- a/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp +++ b/Examples/Algorithms/Jets/src/TrackToTruthJetAlgorithm.cpp @@ -103,9 +103,8 @@ ProcessCode ActsExamples::TrackToTruthJetAlgorithm::execute( i++; } // loop over jets - Acts::FastJet::JetProperties matchedJetProps(*matchedJet); - if (matchedJet != nullptr) { + Acts::FastJet::JetProperties matchedJetProps(*matchedJet); matchedJetProps.addTrack(track.index()); } diff --git a/Examples/Scripts/Python/full_chain_odd.py b/Examples/Scripts/Python/full_chain_odd.py index 7ef0672ce39..025706a86e0 100755 --- a/Examples/Scripts/Python/full_chain_odd.py +++ b/Examples/Scripts/Python/full_chain_odd.py @@ -398,11 +398,10 @@ ) truthJetAlg = acts.examples.TruthJetAlgorithm( - level=acts.logging.DEBUG, + level=acts.logging.INFO, inputTruthParticles="jet_input_particles", outputJets="truth_jets", - jetPtMin=10 * u.GeV, - inputHepMC3Event="pythia8-event", + jetPtMin=10 * u.GeV ) s.addAlgorithm(truthJetAlg) From 2b049206b9c1f3dd399fdaf959d433371da71afc Mon Sep 17 00:00:00 2001 From: Doga Elitez <108287101+delitez@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:37:58 +0200 Subject: [PATCH 25/25] Forgotten pre-commit --- Examples/Scripts/Python/full_chain_odd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Scripts/Python/full_chain_odd.py b/Examples/Scripts/Python/full_chain_odd.py index 025706a86e0..55fdacff61a 100755 --- a/Examples/Scripts/Python/full_chain_odd.py +++ b/Examples/Scripts/Python/full_chain_odd.py @@ -401,7 +401,7 @@ level=acts.logging.INFO, inputTruthParticles="jet_input_particles", outputJets="truth_jets", - jetPtMin=10 * u.GeV + jetPtMin=10 * u.GeV, ) s.addAlgorithm(truthJetAlg)