From 1358df8c3bd0eb4b25f52d14da3d947d6dc1c206 Mon Sep 17 00:00:00 2001 From: Juan Carlos Aranda Huecas Date: Thu, 8 Aug 2024 10:43:43 +0200 Subject: [PATCH] Added printers for the implemented getters in ReconstructedParticle --- include/ral/ReconstructedParticle.h | 48 +++++++++++++ src/ReconstructedParticle.cc | 103 ++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) diff --git a/include/ral/ReconstructedParticle.h b/include/ral/ReconstructedParticle.h index 308d8e2..38d32b0 100644 --- a/include/ral/ReconstructedParticle.h +++ b/include/ral/ReconstructedParticle.h @@ -107,6 +107,54 @@ struct print_PDG { ROOT::VecOps::RVec particles); }; +struct print_energy { + int m_n_events; + int m_n_printed; + print_energy(int n_events); + int operator()( + ROOT::VecOps::RVec particles); +}; + +struct print_momentum { + int m_n_events; + int m_n_printed; + print_momentum(int n_events); + int operator()( + ROOT::VecOps::RVec particles); +}; + +struct print_referencePoint { + int m_n_events; + int m_n_printed; + print_referencePoint(int n_events); + int operator()( + ROOT::VecOps::RVec particles); +}; + +struct print_mass { + int m_n_events; + int m_n_printed; + print_mass(int n_events); + int operator()( + ROOT::VecOps::RVec particles); +}; + +struct print_charge { + int m_n_events; + int m_n_printed; + print_charge(int n_events); + int operator()( + ROOT::VecOps::RVec particles); +}; + +struct print_goodnessOfPID { + int m_n_events; + int m_n_printed; + print_goodnessOfPID(int n_events); + int operator()( + ROOT::VecOps::RVec particles); +}; + } // namespace ReconstructedParticle } // namespace k4::ral diff --git a/src/ReconstructedParticle.cc b/src/ReconstructedParticle.cc index 32440bc..072e390 100644 --- a/src/ReconstructedParticle.cc +++ b/src/ReconstructedParticle.cc @@ -1,4 +1,5 @@ #include "ral/ReconstructedParticle.h" +#include #include #include #include @@ -96,5 +97,107 @@ int print_PDG::operator()( return 0; } +print_energy::print_energy(int n_events) : m_n_events{n_events}, m_n_printed{0} {} + +int print_energy::operator()( + ROOT::VecOps::RVec particles) { + if (m_n_events == m_n_printed) { + throw std::runtime_error("End printing"); + } + auto energies = get_energy(particles); + std::cout << "Printing energy from event " << m_n_printed << std::endl; + for (const float &energy : energies) { + std::cout << energy << " "; + } + std::cout << std::endl; + m_n_printed += 1; + return 0; +} + +print_momentum::print_momentum(int n_events) : m_n_events{n_events}, m_n_printed{0} {} + +int print_momentum::operator()( + ROOT::VecOps::RVec particles) { + if (m_n_events == m_n_printed) { + throw std::runtime_error("End printing"); + } + auto vectors = get_momentum(particles); + std::cout << "Printing momentum from event " << m_n_printed << std::endl; + for (const ROOT::Math::XYZVector &momentum : vectors) { + std::cout << momentum << " "; + } + std::cout << std::endl; + m_n_printed += 1; + return 0; +} + +print_referencePoint::print_referencePoint(int n_events) : m_n_events{n_events}, m_n_printed{0} {} + +int print_referencePoint::operator()( + ROOT::VecOps::RVec particles) { + if (m_n_events == m_n_printed) { + throw std::runtime_error("End printing"); + } + auto points = get_referencePoint(particles); + std::cout << "Printing referencePoint from event " << m_n_printed << std::endl; + for (const ROOT::Math::XYZVector &referencePoint : points) { + std::cout << referencePoint << " "; + } + std::cout << std::endl; + m_n_printed += 1; + return 0; +} + +print_charge::print_charge(int n_events) : m_n_events{n_events}, m_n_printed{0} {} + +int print_charge::operator()( + ROOT::VecOps::RVec particles) { + if (m_n_events == m_n_printed) { + throw std::runtime_error("End printing"); + } + auto charges = get_charge(particles); + std::cout << "Printing charge from event " << m_n_printed << std::endl; + for (const float &charge : charges) { + std::cout << charge << " "; + } + std::cout << std::endl; + m_n_printed += 1; + return 0; +} + +print_mass::print_mass(int n_events) : m_n_events{n_events}, m_n_printed{0} {} + +int print_mass::operator()( + ROOT::VecOps::RVec particles) { + if (m_n_events == m_n_printed) { + throw std::runtime_error("End printing"); + } + auto masses = get_mass(particles); + std::cout << "Printing mass from event " << m_n_printed << std::endl; + for (const float &mass : masses) { + std::cout << mass << " "; + } + std::cout << std::endl; + m_n_printed += 1; + return 0; +} + +print_goodnessOfPID::print_goodnessOfPID(int n_events) : m_n_events{n_events}, m_n_printed{0} {} + +int print_goodnessOfPID::operator()( + ROOT::VecOps::RVec particles) { + if (m_n_events == m_n_printed) { + throw std::runtime_error("End printing"); + } + auto goodnessOfPIDs = get_goodnessOfPID(particles); + std::cout << "Printing goodnessOfPID from event " << m_n_printed << std::endl; + for (const float &goodnessOfPID : goodnessOfPIDs) { + std::cout << goodnessOfPID << " "; + } + std::cout << std::endl; + m_n_printed += 1; + return 0; +} + } // namespace ReconstructedParticle } // namespace k4::ral