The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
TrackDefaultParticles.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
14#include <array>
15#include <iomanip>
16#include <stdexcept>
17#include <stdint.h>
18
19namespace Gaudi {
20 namespace Tr {
21 class PID {
22 enum class validated_pid_t { Electron = 0, Muon, Pion, Kaon, Proton };
23 static constexpr std::array<double, 5> s_mass = { 0.51099891, 105.65837, 139.57018, 493.677, 938.27203 };
24
26
27 static constexpr validated_pid_t validate( int id ) {
28 switch ( id ) {
29 case 11:
31 case 13:
33 case 211:
35 case 321:
37 case 2212:
39 default:
40 throw std::runtime_error( "invalid PID" );
41 }
42 }
43
44 public:
45 constexpr explicit PID( const int id ) : m_value( validate( id ) ) {}
46
47 constexpr explicit PID( validated_pid_t pid ) : m_value( pid ) {}
48
49 PID() = delete;
50 // Make the creation of thes PID objects expressive in user code
51 // by calling Gaudi::Tr::PID::Electron()
52 static constexpr PID Electron() { return PID{ validated_pid_t::Electron }; }
53
54 static constexpr PID Muon() { return PID{ validated_pid_t::Muon }; }
55
56 static constexpr PID Pion() { return PID{ validated_pid_t::Pion }; }
57
58 static constexpr PID Kaon() { return PID{ validated_pid_t::Kaon }; }
59
60 static constexpr PID Proton() { return PID{ validated_pid_t::Proton }; }
61
62 // Framwork functions allowing the use of PID inside a property
63 friend const char* toString( PID pid ) {
64 switch ( pid.m_value ) {
66 return "Electron";
68 return "Muon";
70 return "Pion";
72 return "Kaon";
74 return "Proton";
75 default:
76 throw std::runtime_error( "Calling toString on invalid PID" );
77 }
78 }
79
80 friend std::ostream& toStream( const PID& pid, std::ostream& os ) {
81 return os << std::quoted( toString( pid ), '\'' );
82 }
83 friend std::ostream& operator<<( std::ostream& os, const PID& pid ) { return toStream( pid, os ); }
84
85 friend StatusCode parse( PID& pid, std::string_view in ) {
86 for ( PID ref : { Electron(), Muon(), Pion(), Kaon(), Proton() } ) {
87 if ( in != toString( ref ) ) continue;
88 pid = ref;
90 }
92 }
93 //----------------------------------------------------------
94
95 constexpr double mass() const { return s_mass[static_cast<int>( m_value )]; }
96
97 constexpr bool isElectron() const { return validated_pid_t::Electron == m_value; }
98
99 constexpr bool isMuon() const { return validated_pid_t::Muon == m_value; }
100
101 constexpr bool isPion() const { return validated_pid_t::Pion == m_value; }
102
103 constexpr bool isKaon() const { return validated_pid_t::Kaon == m_value; }
104
105 constexpr bool isProton() const { return validated_pid_t::Proton == m_value; }
106 };
107 } // namespace Tr
108} // namespace Gaudi
static constexpr PID Kaon()
constexpr bool isMuon() const
friend std::ostream & operator<<(std::ostream &os, const PID &pid)
static constexpr std::array< double, 5 > s_mass
constexpr bool isKaon() const
constexpr double mass() const
constexpr bool isElectron() const
friend const char * toString(PID pid)
friend StatusCode parse(PID &pid, std::string_view in)
static constexpr validated_pid_t validate(int id)
friend std::ostream & toStream(const PID &pid, std::ostream &os)
constexpr bool isProton() const
constexpr PID(validated_pid_t pid)
static constexpr PID Muon()
static constexpr PID Pion()
constexpr bool isPion() const
constexpr PID(const int id)
validated_pid_t m_value
static constexpr PID Proton()
static constexpr PID Electron()
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1