File indexing completed on 2025-01-18 09:57:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012
0013 #include <GaudiKernel/StatusCode.h>
0014 #include <array>
0015 #include <iomanip>
0016 #include <stdexcept>
0017 #include <stdint.h>
0018
0019 namespace Gaudi {
0020 namespace Tr {
0021 class PID {
0022 enum class validated_pid_t { Electron = 0, Muon, Pion, Kaon, Proton };
0023 static constexpr std::array<double, 5> s_mass = { 0.51099891, 105.65837, 139.57018, 493.677, 938.27203 };
0024
0025 validated_pid_t m_value;
0026
0027 static constexpr validated_pid_t validate( int id ) {
0028 switch ( id ) {
0029 case 11:
0030 return validated_pid_t::Electron;
0031 case 13:
0032 return validated_pid_t::Muon;
0033 case 211:
0034 return validated_pid_t::Pion;
0035 case 321:
0036 return validated_pid_t::Kaon;
0037 case 2212:
0038 return validated_pid_t::Proton;
0039 default:
0040 throw std::runtime_error( "invalid PID" );
0041 }
0042 }
0043
0044 public:
0045 constexpr explicit PID( const int id ) : m_value( validate( id ) ) {}
0046
0047 constexpr explicit PID( validated_pid_t pid ) : m_value( pid ) {}
0048
0049 PID() = default;
0050
0051
0052 static constexpr PID Electron() { return PID{ validated_pid_t::Electron }; }
0053
0054 static constexpr PID Muon() { return PID{ validated_pid_t::Muon }; }
0055
0056 static constexpr PID Pion() { return PID{ validated_pid_t::Pion }; }
0057
0058 static constexpr PID Kaon() { return PID{ validated_pid_t::Kaon }; }
0059
0060 static constexpr PID Proton() { return PID{ validated_pid_t::Proton }; }
0061
0062
0063 friend const char* toString( PID pid ) {
0064 switch ( pid.m_value ) {
0065 case validated_pid_t::Electron:
0066 return "Electron";
0067 case validated_pid_t::Muon:
0068 return "Muon";
0069 case validated_pid_t::Pion:
0070 return "Pion";
0071 case validated_pid_t::Kaon:
0072 return "Kaon";
0073 case validated_pid_t::Proton:
0074 return "Proton";
0075 default:
0076 throw std::runtime_error( "Calling toString on invalid PID" );
0077 }
0078 }
0079
0080 friend std::ostream& toStream( const PID& pid, std::ostream& os ) {
0081 return os << std::quoted( toString( pid ), '\'' );
0082 }
0083 friend std::ostream& operator<<( std::ostream& os, const PID& pid ) { return toStream( pid, os ); }
0084
0085 friend StatusCode parse( PID& pid, const std::string& in ) {
0086 for ( PID ref : { Electron(), Muon(), Pion(), Kaon(), Proton() } ) {
0087 if ( in != toString( ref ) ) continue;
0088 pid = ref;
0089 return StatusCode::SUCCESS;
0090 }
0091 return StatusCode::FAILURE;
0092 }
0093
0094
0095 constexpr double mass() const { return s_mass[static_cast<int>( m_value )]; }
0096
0097 constexpr bool isElectron() const { return validated_pid_t::Electron == m_value; }
0098
0099 constexpr bool isMuon() const { return validated_pid_t::Muon == m_value; }
0100
0101 constexpr bool isPion() const { return validated_pid_t::Pion == m_value; }
0102
0103 constexpr bool isKaon() const { return validated_pid_t::Kaon == m_value; }
0104
0105 constexpr bool isProton() const { return validated_pid_t::Proton == m_value; }
0106 };
0107 }
0108 }