Line data Source code
1 : #include "crpropa/ParticleID.h"
2 :
3 : #include "HepPID/ParticleIDMethods.hh"
4 : #include "HepPID/ParticleName.hh"
5 : #include "kiss/convert.h"
6 :
7 : #include <string>
8 :
9 : namespace crpropa {
10 :
11 45069 : int nucleusId(int a, int z) {
12 45069 : if (z < 0)
13 : throw std::runtime_error(
14 0 : "crpropa::Nucleus: no nucleus with Z < 0, A=" + kiss::str(a) + " Z="
15 0 : + kiss::str(z));
16 45069 : if (a < 1)
17 : throw std::runtime_error(
18 0 : "crpropa::Nucleus: no nucleus with A < 1, A=" + kiss::str(a) + " Z="
19 0 : + kiss::str(z));
20 45069 : if (a < z)
21 : throw std::runtime_error(
22 2 : "crpropa::Nucleus: no nucleus with A < Z, A=" + kiss::str(a) + " Z="
23 3 : + kiss::str(z));
24 45068 : return 1000000000 + z * 10000 + a * 10;
25 : }
26 :
27 299901 : int chargeNumber(int id) {
28 299901 : return HepPID::Z(id);
29 : }
30 :
31 152689 : int massNumber(int id) {
32 152689 : if (id == 2112)
33 : return 1;
34 152688 : return HepPID::A(id);
35 : }
36 :
37 40681115 : bool isNucleus(int id) {
38 40681115 : if (id == 2112)
39 : return true; // consider neutron as nucleus
40 40681115 : return HepPID::isNucleus(id);
41 : }
42 :
43 0 : std::string convertIdToName(int id) {
44 : // handle a few extra cases that HepPID doesn't like
45 0 : if (id == 1000000010) // neutron
46 0 : id = 2112;
47 0 : if (id == -1000000010) // anti-neutron
48 0 : id = -2112;
49 0 : if (id == -1000010010) // anti-proton
50 0 : id = -2212;
51 0 : return HepPID::particleName(id);
52 : }
53 :
54 : }
|