cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.3
A generic central exclusive processes event generator
Loading...
Searching...
No Matches
PDG.cpp
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2013-2024 Laurent Forthomme
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <iomanip>
20
23#include "CepGen/Physics/PDG.h"
24#include "CepGen/Utils/String.h"
25
26namespace cepgen {
27 std::ostream& operator<<(std::ostream& os, const PDG::Id& pdg) {
29 return os << HeavyIon::fromPdgId(pdg);
30 return os << PDG::get().name(pdg);
31 }
32
33 PDG::PDG() {
34 // PDG id, name, description, colour, mass, width, charge, is fermion
35 define(ParticleProperties(invalid, "invalid", "invalid", 0, -1., -1., {}, false));
36 define(ParticleProperties(diffractiveProton, "diff_proton", "p\u002A", 0, 0., 0., {-3, 3}, false));
37 define(ParticleProperties(pomeron, "pomeron", "\u2119", 0, 0., 0., {}, false));
38 define(ParticleProperties(reggeon, "reggeon", "\u211D", 0, 0., 0., {}, false));
39 }
40
42 static PDG instance;
43 return instance;
44 }
45
46 bool PDG::has(spdgid_t id) const { return particles_.count(std::abs(id)) > 0; }
47
49 auto it = particles_.find(std::abs(id));
50 if (it != particles_.end())
51 return it->second;
52 throw CG_FATAL("PDG").log([this, &id](auto& log) {
53 log << "No particle with PDG id " << id << " in the catalogue. ";
54 dump(&log.stream());
55 });
56 }
57
58 ParticleProperties& PDG::operator[](spdgid_t id) { return particles_[std::abs(id)]; }
59
60 void PDG::define(const ParticleProperties& props) {
61 if (props.pdgid == PDG::invalid && props.name != "invalid")
62 throw CG_FATAL("PDG:define") << "Trying to define a particle with invalid PDG id: " << props << ".";
63 CG_DEBUG("PDG:define").log([&](auto& log) {
64 if (has(props.pdgid))
65 log << "Updating the properties of a particle with PDG id=" << props.pdgid << ".\n\t"
66 << "Old properties: " << operator()(props.pdgid) << ",\n\t"
67 << "New properties: " << props << ".";
68 else
69 log << "Adding a new particle with PDG id=" << std::setw(8) << props.pdgid << ", properties: " << props << ".";
70 });
71 particles_[props.pdgid] = props;
72 }
73
75 pdgids_t out;
76 std::transform(
77 particles_.begin(), particles_.end(), std::back_inserter(out), [](const auto& pt) { return pt.first; });
78 return out;
79 }
80
81 const std::string& PDG::name(spdgid_t id) const {
82 const auto& descr = operator()(id).descr;
83 if (!descr.empty())
84 return descr;
85 return operator()(id).name;
86 }
87
88 double PDG::colours(spdgid_t id) const { return operator()(id).colours; }
89
90 double PDG::mass(spdgid_t id) const {
91 if (HeavyIon::isHI(id))
92 return HeavyIon::fromPdgId(id).mass();
93 return operator()(id).mass;
94 }
95
96 double PDG::width(spdgid_t id) const { return operator()(id).width; }
97
98 double PDG::charge(spdgid_t id) const { return operator()(id).integerCharge() * (id / std::abs(id)) * 1. / 3.; }
99
100 std::vector<double> PDG::charges(spdgid_t id) const {
101 std::vector<double> chs;
102 for (const auto& ch : operator()(id).charges)
103 chs.emplace_back(ch * 1. / 3);
104 return chs;
105 }
106
107 size_t PDG::size() const { return particles_.size(); }
108
109 void PDG::dump(std::ostream* os) const {
110 //--- first build a sorted vector out of the (unsorted) map
111 std::vector<std::pair<pdgid_t, ParticleProperties> > tmp;
112 std::transform(particles_.begin(), particles_.end(), std::back_inserter(tmp), [](const auto& prt) {
113 return std::pair<pdgid_t, ParticleProperties>{prt.first, prt.second};
114 });
115 std::sort(tmp.begin(),
116 tmp.end(),
117 [](const std::pair<pdgid_t, ParticleProperties>& a, const std::pair<pdgid_t, ParticleProperties>& b) {
118 return a.first < b.first;
119 });
120 //--- then the proper dump begins
121 std::ostringstream oss;
122 oss << "List of particles registered:";
123 for (const auto& prt : tmp)
124 if (prt.first != PDG::invalid)
125 oss << utils::format(
126 "\n%16s %-32s\tcharges: {%6s}, colour factor: %1d, mass: %8.4f GeV/c^2, width: %6.3f GeV.",
127 utils::colourise(std::to_string(prt.second.pdgid), utils::Colour::none, utils::Modifier::italic).data(),
128 (utils::boldify(prt.second.name) + " " + (prt.second.fermion ? "fermion" : "boson") + ":").data(),
129 utils::merge(prt.second.charges, ",").data(),
130 prt.second.colours,
131 prt.second.mass,
132 prt.second.width);
133 if (os)
134 (*os) << oss.str();
135 else
136 CG_INFO("PDG") << oss.str();
137 }
138} // namespace cepgen
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_DEBUG(mod)
Definition Message.h:220
#define CG_INFO(mod)
Definition Message.h:216
A class-in-the-middle PDG identifier for printout operations.
Definition PDG.h:55
A singleton holding all physics constants associated to particles.
Definition PDG.h:28
double colours(spdgid_t) const
Colour factor for this particle.
Definition PDG.cpp:88
size_t size() const
Number of particles defined in this library.
Definition PDG.cpp:107
pdgids_t particles() const
All particles ids in this library.
Definition PDG.cpp:74
ParticleProperties & operator[](spdgid_t id)
Definition PDG.cpp:58
bool has(spdgid_t) const
Is the particle defined for a given PDG id.
Definition PDG.cpp:46
std::vector< double > charges(spdgid_t) const
Electric charges (in ) for this particle and anti-particles.
Definition PDG.cpp:100
@ diffractiveProton
Definition PDG.h:51
@ reggeon
Definition PDG.h:44
@ pomeron
Definition PDG.h:43
@ invalid
Definition PDG.h:34
const ParticleProperties & operator()(spdgid_t) const
All physical properties for one particle.
Definition PDG.cpp:48
void dump(std::ostream *=nullptr) const
Dump all particles in this library.
Definition PDG.cpp:109
double width(spdgid_t) const
Resonance width (in GeV)
Definition PDG.cpp:96
double mass(spdgid_t) const
Particle mass (in GeV)
Definition PDG.cpp:90
const std::string & name(spdgid_t) const
Accessor for particle properties.
Definition PDG.cpp:81
void define(const ParticleProperties &)
Add a new particle definition to the library.
Definition PDG.cpp:60
static PDG & get()
Retrieve a unique instance of this particles info collection.
Definition PDG.cpp:41
double charge(spdgid_t) const
Electric charge (in ) for this particle.
Definition PDG.cpp:98
Common namespace for this Monte Carlo generator.
std::vector< pdgid_t > pdgids_t
long long spdgid_t
std::ostream & operator<<(std::ostream &os, const Exception::Type &type)
Definition Exception.cpp:59
static HeavyIon fromPdgId(pdgid_t)
Build from a custom PDG id.
Definition HeavyIon.cpp:34
double mass() const
Total heavy ion mass, in GeV/c2.
Definition HeavyIon.h:56
static bool isHI(const spdgid_t &)
Check if the PDG id is compatible with a HI.
Definition HeavyIon.cpp:54
A collection of physics constants associated to a single particle.
std::string descr
Human-readable name.
double mass
Mass, in GeV/c .
pdgid_t pdgid
PDG identifier.
std::vector< int > charges
Electric charges, in /3.
std::string name
Particle name.
short integerCharge() const
Integer charge, in /3.
double width
Decay width, in GeV/c .