From d3e7135b4231813a43ce350e9d29987fd9610a43 Mon Sep 17 00:00:00 2001 From: Juan Carlos Aranda Huecas Date: Fri, 2 Aug 2024 13:52:42 +0200 Subject: [PATCH] Added new print method and basic analyzers for ParticleID --- include/ral/ParticleID.h | 80 +++++++++++++++++++++++ include/ral/ReconstructedParticle.h | 8 +++ src/ParticleID.cc | 58 ++++++++++++++++ src/ReconstructedParticle.cc | 20 ++++++ test/integration/ReconstructedParticle.py | 2 + 5 files changed, 168 insertions(+) create mode 100644 include/ral/ParticleID.h create mode 100644 src/ParticleID.cc diff --git a/include/ral/ParticleID.h b/include/ral/ParticleID.h new file mode 100644 index 0000000..1a74d4c --- /dev/null +++ b/include/ral/ParticleID.h @@ -0,0 +1,80 @@ +#ifndef PARTICLEID_ANALYZERS_H +#define PARTICLEID_ANALYZERS_H + +#include "ROOT/RVec.hxx" +#include "edm4hep/ParticleID.h" + +/** + * Main namespace of the library + */ +namespace k4::ral { + +/** + * Englobe analyzers that acts on the ParticleID class + */ +namespace ParticleID { + +/** + * Get type member from ParticleIDs + * + * Analyzer that can be use to obtain the type member in the class + * ParticleID from edm4hep + * + * @param particles List of particle id in an event + * + */ +ROOT::VecOps::RVec +get_type(ROOT::VecOps::RVec particles); + +/** + * Get PDG member from ParticleIDs + * + * Analyzer that can be use to obtain the PDG member in the class + * ParticleID from edm4hep + * + * @param particles List of particle id in an event + * + */ +ROOT::VecOps::RVec +get_PDG(ROOT::VecOps::RVec particles); + +/** + * Get algorithmType member from ParticleIDs + * + * Analyzer that can be use to obtain the algorithmType member in the class + * ParticleID from edm4hep + * + * @param particles List of particle id in an event + * + */ +ROOT::VecOps::RVec +get_algorithmType(ROOT::VecOps::RVec particles); + +/** + * Get likelihood member from ParticleIDs + * + * Analyzer that can be use to obtain the likelihood member in the class + * ParticleID from edm4hep + * + * @param particles List of particle id in an event + * + */ +ROOT::VecOps::RVec +get_likelihood(ROOT::VecOps::RVec particles); + +/** + * Get parameters member from ParticleIDs + * + * Analyzer that can be use to obtain the parameters member in the class + * ParticleID from edm4hep + * + * @param particles List of particle id in an event + * + */ +ROOT::VecOps::RVec> +get_parameters(ROOT::VecOps::RVec particles); + +} // namespace ParticleID +} // namespace k4::ral + +#endif diff --git a/include/ral/ReconstructedParticle.h b/include/ral/ReconstructedParticle.h index 6d5b5ff..308d8e2 100644 --- a/include/ral/ReconstructedParticle.h +++ b/include/ral/ReconstructedParticle.h @@ -99,6 +99,14 @@ get_mass(ROOT::VecOps::RVec particles); ROOT::VecOps::RVec get_goodnessOfPID( ROOT::VecOps::RVec particles); +struct print_PDG { + int m_n_events; + int m_n_printed; + print_PDG(int n_events); + int operator()( + ROOT::VecOps::RVec particles); +}; + } // namespace ReconstructedParticle } // namespace k4::ral diff --git a/src/ParticleID.cc b/src/ParticleID.cc new file mode 100644 index 0000000..f2e0a69 --- /dev/null +++ b/src/ParticleID.cc @@ -0,0 +1,58 @@ +#include "ral/ParticleID.h" + +namespace k4::ral { + +namespace ParticleID { + +ROOT::VecOps::RVec +get_type(ROOT::VecOps::RVec particles) { + ROOT::VecOps::RVec result; + result.reserve(particles.size()); + for (edm4hep::ParticleID p : particles) { + result.emplace_back(p.type); + } + return result; +} + +ROOT::VecOps::RVec +get_PDG(ROOT::VecOps::RVec particles) { + ROOT::VecOps::RVec result; + result.reserve(particles.size()); + for (edm4hep::ParticleID p : particles) { + result.emplace_back(p.PDG); + } + return result; +} + +ROOT::VecOps::RVec +get_algorithmType(ROOT::VecOps::RVec particles) { + ROOT::VecOps::RVec result; + result.reserve(particles.size()); + for (edm4hep::ParticleID p : particles) { + result.emplace_back(p.algorithmType); + } + return result; +} + +ROOT::VecOps::RVec +get_likelihood(ROOT::VecOps::RVec particles) { + ROOT::VecOps::RVec result; + result.reserve(particles.size()); + for (edm4hep::ParticleID p : particles) { + result.emplace_back(p.likelihood); + } + return result; +} + +ROOT::VecOps::RVec> +get_parameters(ROOT::VecOps::RVec particles) { + ROOT::VecOps::RVec> result; + result.reserve(particles.size()); + for (edm4hep::ParticleID p : particles) { + result.emplace_back(p.parameters); + } + return result; +} + +} // namespace ParticleID +} // namespace k4::ral diff --git a/src/ReconstructedParticle.cc b/src/ReconstructedParticle.cc index a31f084..571a56d 100644 --- a/src/ReconstructedParticle.cc +++ b/src/ReconstructedParticle.cc @@ -1,4 +1,6 @@ #include "ral/ReconstructedParticle.h" +#include +#include namespace k4::ral { @@ -75,5 +77,23 @@ ROOT::VecOps::RVec get_goodnessOfPID( } return result; } + +print_PDG::print_PDG(int n_events) : m_n_events{n_events}, m_n_printed{0} {} +int print_PDG::operator()( + ROOT::VecOps::RVec particles) { + if (m_n_events == m_n_printed) { + std::cout << "Finish printing PDG" << std::endl; + std::exit(0); + } + auto pdgs = get_PDG(particles); + std::cout << "Printing PDG from event " << m_n_printed << std::endl; + for (const int &pdg : pdgs) { + std::cout << pdg << " "; + } + std::cout << std::endl; + m_n_printed += 1; + return 0; +} + } // namespace ReconstructedParticle } // namespace k4::ral diff --git a/test/integration/ReconstructedParticle.py b/test/integration/ReconstructedParticle.py index 3cff476..ceeb854 100644 --- a/test/integration/ReconstructedParticle.py +++ b/test/integration/ReconstructedParticle.py @@ -90,6 +90,8 @@ def get_file(url: str, path: str) -> None: "ReconstructedParticle::get_mass(ReconstructedParticles)") .Define("goodnessOfPID", "ReconstructedParticle::get_goodnessOfPID(ReconstructedParticles)") + .Define("void", + "ReconstructedParticle::print_PDG(5)(ReconstructedParticles)") ) print("Output test result in a new dataframe")