-
Notifications
You must be signed in to change notification settings - Fork 220
feat: Introduce TrackToTruthJetAlgorithm #4637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7d7da46
7b1de37
6dcc100
97a8b59
2ac9be3
c9f3433
7c93d73
f5343c0
a205c73
9efae0c
2cff0b6
c1720ba
0294448
7d28afa
ce77972
1c4ff77
bdf10b1
3ea04ce
cd43e73
f11f837
33c9aa2
f34faff
2d3ffe2
e612403
c28eada
d294f4b
98c57ea
772e597
547a849
245220e
257cae2
fef4c21
251b222
da33a85
e3661c0
381b2f3
dd818f3
ff87333
fb92def
f29757c
366a45e
5170fff
2b04920
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| acts_add_library(ExamplesJets SHARED src/TruthJetAlgorithm.cpp) | ||
| acts_add_library( | ||
| ExamplesJets | ||
| SHARED | ||
| src/TruthJetAlgorithm.cpp | ||
| src/TrackToTruthJetAlgorithm.cpp | ||
| ) | ||
| target_include_directories( | ||
| ActsExamplesJets | ||
| PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| ) | ||
| target_link_libraries( | ||
| ActsExamplesJets | ||
| PUBLIC Acts::PluginFastJet Acts::ExamplesFramework | ||
| PUBLIC Acts::Core Acts::PluginFastJet Acts::ExamplesFramework | ||
| ) | ||
|
|
||
| acts_compile_headers(ExamplesJets GLOB "include/**/*.hpp") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // 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 "Acts/Plugins/FastJet/Jets.hpp" | ||
| #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 <string> | ||
|
|
||
| #include <fastjet/ClusterSequence.hh> | ||
|
|
||
| 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() override; | ||
|
|
||
| const Config& config() const { return m_cfg; } | ||
|
|
||
| private: | ||
| Config m_cfg; | ||
| ReadDataHandle<ConstTrackContainer> m_inputTracks{this, "inputTracks"}; | ||
| ReadDataHandle<Acts::FastJet::TrackJetContainer> m_inputJets{this, | ||
| "inputJets"}; | ||
| WriteDataHandle<Acts::FastJet::TrackJetContainer> m_outputTrackJets{ | ||
| this, "outputTrackJets"}; | ||
| }; | ||
|
|
||
| } // namespace ActsExamples |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // 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/Utilities/Logger.hpp" | ||
| #include "ActsExamples/Framework/AlgorithmContext.hpp" | ||
|
|
||
| #include <ostream> | ||
| #include <stdexcept> | ||
|
|
||
| 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_DEBUG("Executing track to truth jet matching algorithm"); | ||
|
|
||
| const auto& tracks = m_inputTracks(ctx); | ||
| const auto& truthJets = m_inputJets(ctx); | ||
| // Take a copy that we will modify | ||
| Acts::FastJet::TrackJetContainer jets = truthJets; | ||
|
|
||
| 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; | ||
|
|
||
| ACTS_VERBOSE("Track index: " << track.index() | ||
| << ", momentum: " << track.momentum().x() | ||
| << ", " << track.momentum().y() << ", " | ||
| << track.momentum().z()); | ||
|
|
||
| Acts::FastJet::TruthJetBuilder* matchedJet = nullptr; | ||
|
|
||
| // Loop over the jets to find the closest one | ||
| std::size_t i = 0; | ||
| for (auto& jet : jets) { | ||
| Acts::FastJet::JetProperties jetProps(jet); | ||
|
|
||
| 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(); | ||
| 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 << ": " | ||
| << deltaR | ||
| << ", jet px: " << jetProps.getFourMomentum().x()); | ||
| if (deltaR < m_cfg.maxDeltaR) { | ||
| ACTS_DEBUG("Track " << track.index() << " matches jet " << i | ||
| << " with delta R: " << deltaR); | ||
| } | ||
|
|
||
| i++; | ||
| } // loop over jets | ||
|
|
||
| if (matchedJet != nullptr) { | ||
| Acts::FastJet::JetProperties matchedJetProps(*matchedJet); | ||
| matchedJetProps.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() { | ||
| ACTS_INFO("Finalizing track to truth jet matching algorithm"); | ||
| return ProcessCode::SUCCESS; | ||
| } | ||
|
|
||
| }; // namespace ActsExamples |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| // 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 "ActsPython/Utilities/Helpers.hpp" | ||
| #include "ActsPython/Utilities/Macros.hpp" | ||
|
|
@@ -29,4 +30,13 @@ void addTruthJet(Context& ctx) { | |
| ACTS_PYTHON_DECLARE_ALGORITHM(TruthJetAlgorithm, mex, "TruthJetAlgorithm", | ||
| inputTruthParticles, outputJets, jetPtMin); | ||
| } // addTruthJet | ||
|
|
||
| void addTrackToTruthJet(Context& ctx) { | ||
| auto mex = ctx.get("examples"); | ||
|
|
||
| ACTS_PYTHON_DECLARE_ALGORITHM(TrackToTruthJetAlgorithm, mex, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you do this in the existing |
||
| "TrackToTruthJetAlgorithm", inputTracks, | ||
| inputJets, outputTrackJets, maxDeltaR); | ||
| } // addTrackToTruthJet | ||
|
|
||
| } // namespace ActsPython | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,5 @@ | |
|
|
||
| namespace ActsPython { | ||
| void addTruthJet(Context& /*ctx*/) {} | ||
| void addTrackToTruthJet(Context& /*ctx*/) {} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be done in the same function if we're not going to build either of them separately and not the other one. |
||
| } // namespace ActsPython | ||
Uh oh!
There was an error while loading. Please reload this page.