Skip to content

Commit

Permalink
Added new print method and basic analyzers for ParticleID
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanki0396 committed Aug 2, 2024
1 parent bab9854 commit d3e7135
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
80 changes: 80 additions & 0 deletions include/ral/ParticleID.h
Original file line number Diff line number Diff line change
@@ -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<int>
get_type(ROOT::VecOps::RVec<edm4hep::ParticleID> 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<int>
get_PDG(ROOT::VecOps::RVec<edm4hep::ParticleID> 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<int>
get_algorithmType(ROOT::VecOps::RVec<edm4hep::ParticleID> 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<float>
get_likelihood(ROOT::VecOps::RVec<edm4hep::ParticleID> 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<ROOT::VecOps::RVec<float>>
get_parameters(ROOT::VecOps::RVec<edm4hep::ParticleID> particles);

} // namespace ParticleID
} // namespace k4::ral

#endif
8 changes: 8 additions & 0 deletions include/ral/ReconstructedParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ get_mass(ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> particles);
ROOT::VecOps::RVec<float> get_goodnessOfPID(
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> particles);

struct print_PDG {
int m_n_events;
int m_n_printed;
print_PDG(int n_events);
int operator()(
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> particles);
};

} // namespace ReconstructedParticle
} // namespace k4::ral

Expand Down
58 changes: 58 additions & 0 deletions src/ParticleID.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "ral/ParticleID.h"

namespace k4::ral {

namespace ParticleID {

ROOT::VecOps::RVec<int>
get_type(ROOT::VecOps::RVec<edm4hep::ParticleID> particles) {
ROOT::VecOps::RVec<int> result;
result.reserve(particles.size());
for (edm4hep::ParticleID p : particles) {
result.emplace_back(p.type);
}
return result;
}

ROOT::VecOps::RVec<int>
get_PDG(ROOT::VecOps::RVec<edm4hep::ParticleID> particles) {
ROOT::VecOps::RVec<int> result;
result.reserve(particles.size());
for (edm4hep::ParticleID p : particles) {
result.emplace_back(p.PDG);
}
return result;
}

ROOT::VecOps::RVec<int>
get_algorithmType(ROOT::VecOps::RVec<edm4hep::ParticleID> particles) {
ROOT::VecOps::RVec<int> result;
result.reserve(particles.size());
for (edm4hep::ParticleID p : particles) {
result.emplace_back(p.algorithmType);
}
return result;
}

ROOT::VecOps::RVec<float>
get_likelihood(ROOT::VecOps::RVec<edm4hep::ParticleID> particles) {
ROOT::VecOps::RVec<float> result;
result.reserve(particles.size());
for (edm4hep::ParticleID p : particles) {
result.emplace_back(p.likelihood);
}
return result;
}

ROOT::VecOps::RVec<ROOT::VecOps::RVec<float>>
get_parameters(ROOT::VecOps::RVec<edm4hep::ParticleID> particles) {
ROOT::VecOps::RVec<ROOT::VecOps::RVec<float>> result;
result.reserve(particles.size());
for (edm4hep::ParticleID p : particles) {
result.emplace_back(p.parameters);
}
return result;
}

} // namespace ParticleID
} // namespace k4::ral
20 changes: 20 additions & 0 deletions src/ReconstructedParticle.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "ral/ReconstructedParticle.h"
#include <cstdlib>
#include <iostream>

namespace k4::ral {

Expand Down Expand Up @@ -75,5 +77,23 @@ ROOT::VecOps::RVec<float> 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<edm4hep::ReconstructedParticleData> 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
2 changes: 2 additions & 0 deletions test/integration/ReconstructedParticle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d3e7135

Please sign in to comment.