From 7fb94519aaeb753fc951b2e0a9601d8f09ace62a Mon Sep 17 00:00:00 2001 From: Stephen Fegan Date: Tue, 9 Jul 2024 11:14:33 +0200 Subject: [PATCH] Add function to convert PDG type code to string --- include/simulation/geant4_shower_generator.hpp | 2 ++ src/simulation/geant4_shower_generator.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/simulation/geant4_shower_generator.hpp b/include/simulation/geant4_shower_generator.hpp index b48a40f1..4d72bf3b 100644 --- a/include/simulation/geant4_shower_generator.hpp +++ b/include/simulation/geant4_shower_generator.hpp @@ -107,6 +107,8 @@ class Geant4ShowerGenerator: public calin::simulation::tracker::ShowerGenerator static double get_material_density(const std::string& material_name); static config_type default_config(); + std::string pdg_type_to_string(int pdg_type); + protected: void construct(unsigned num_atm_layers, VerbosityLevel verbose_level, double default_cut_value_cm, double detector_size, const std::string& material_name); diff --git a/src/simulation/geant4_shower_generator.cpp b/src/simulation/geant4_shower_generator.cpp index a1dbd75e..b97eb308 100644 --- a/src/simulation/geant4_shower_generator.cpp +++ b/src/simulation/geant4_shower_generator.cpp @@ -245,6 +245,19 @@ get_material_density(const std::string& material_name) return material->GetDensity() / (CLHEP::g/CLHEP::cm3); } +std::string Geant4ShowerGenerator::pdg_type_to_string(int pdg_type) +{ + G4ParticleTable* table = G4ParticleTable::GetParticleTable(); + if(table) { + const G4ParticleDefinition* particle = table->FindParticle(pdg_type); + if(particle) { + return particle->GetParticleType(); + } + } + return std::to_string(pdg_type); +} + + Geant4ShowerGenerator::config_type Geant4ShowerGenerator::default_config() { config_type config;