27inline int getTruthPDG(
Track& trk,
const std::vector<MCParticle*>* mcParticles,
bool debug =
false) {
28 if (!mcParticles || mcParticles->empty()) {
30 std::cout <<
"utils::getTruthPDG: No MC particles available" << std::endl;
39 std::map<int, int> count_per_particle_id;
44 std::cout <<
"utils::getTruthPDG: Method 1 - track has " << mcp_hits.size() <<
" MCP hits" << std::endl;
47 for (
const auto& [layer_id, particle_id] : mcp_hits) {
48 count_per_particle_id[particle_id]++;
52 if (count_per_particle_id.empty()) {
55 std::cout <<
"utils::getTruthPDG: Method 2 - track has " << svt_hits.GetEntries() <<
" SVT hits" << std::endl;
58 for (
int i = 0; i < svt_hits.GetEntries(); i++) {
62 for (
int part_id : mc_part_ids) {
63 count_per_particle_id[part_id]++;
70 std::cout <<
"utils::getTruthPDG: found " << count_per_particle_id.size() <<
" unique particle IDs" << std::endl;
74 int truth_id{-1}, max_nhits{0};
75 for (
const auto& [particle_id, count] : count_per_particle_id) {
76 if (count > max_nhits) {
77 truth_id = particle_id;
84 std::cout <<
"utils::getTruthPDG: No hits found, returning 0" << std::endl;
91 if (ptr->getID() == truth_id) {
93 std::cout <<
"utils::getTruthPDG: Match found, PDG=" << ptr->getPDG() << std::endl;
100 std::cout <<
"utils::getTruthPDG: No MC particle found with ID " << truth_id << std::endl;
Class used to encapsulate information about a mc particle.
int getTruthPDG(Track &trk, const std::vector< MCParticle * > *mcParticles, bool debug=false)
Get the PDG code of the truth particle best matching this track.