cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
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
21
#include "
CepGen/Core/Exception.h
"
22
#include "
CepGen/Physics/HeavyIon.h
"
23
#include "
CepGen/Physics/PDG.h
"
24
#include "
CepGen/Utils/String.h
"
25
26
namespace
cepgen
{
27
std::ostream&
operator<<
(std::ostream& os,
const
PDG::Id
&
pdg
) {
28
if
(
HeavyIon::isHI
(
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
41
PDG
&
PDG::get
() {
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
48
const
ParticleProperties
&
PDG::operator()
(
spdgid_t
id
)
const
{
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
74
pdgids_t
PDG::particles
()
const
{
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
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
HeavyIon.h
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
CG_INFO
#define CG_INFO(mod)
Definition
Message.h:216
PDG.h
String.h
cepgen::PDG::Id
A class-in-the-middle PDG identifier for printout operations.
Definition
PDG.h:55
cepgen::PDG
A singleton holding all physics constants associated to particles.
Definition
PDG.h:28
cepgen::PDG::colours
double colours(spdgid_t) const
Colour factor for this particle.
Definition
PDG.cpp:88
cepgen::PDG::size
size_t size() const
Number of particles defined in this library.
Definition
PDG.cpp:107
cepgen::PDG::particles
pdgids_t particles() const
All particles ids in this library.
Definition
PDG.cpp:74
cepgen::PDG::operator[]
ParticleProperties & operator[](spdgid_t id)
Definition
PDG.cpp:58
cepgen::PDG::has
bool has(spdgid_t) const
Is the particle defined for a given PDG id.
Definition
PDG.cpp:46
cepgen::PDG::charges
std::vector< double > charges(spdgid_t) const
Electric charges (in ) for this particle and anti-particles.
Definition
PDG.cpp:100
cepgen::PDG::diffractiveProton
@ diffractiveProton
Definition
PDG.h:51
cepgen::PDG::reggeon
@ reggeon
Definition
PDG.h:44
cepgen::PDG::pomeron
@ pomeron
Definition
PDG.h:43
cepgen::PDG::invalid
@ invalid
Definition
PDG.h:34
cepgen::PDG::operator()
const ParticleProperties & operator()(spdgid_t) const
All physical properties for one particle.
Definition
PDG.cpp:48
cepgen::PDG::dump
void dump(std::ostream *=nullptr) const
Dump all particles in this library.
Definition
PDG.cpp:109
cepgen::PDG::width
double width(spdgid_t) const
Resonance width (in GeV)
Definition
PDG.cpp:96
cepgen::PDG::mass
double mass(spdgid_t) const
Particle mass (in GeV)
Definition
PDG.cpp:90
cepgen::PDG::name
const std::string & name(spdgid_t) const
Accessor for particle properties.
Definition
PDG.cpp:81
cepgen::PDG::define
void define(const ParticleProperties &)
Add a new particle definition to the library.
Definition
PDG.cpp:60
cepgen::PDG::get
static PDG & get()
Retrieve a unique instance of this particles info collection.
Definition
PDG.cpp:41
cepgen::PDG::charge
double charge(spdgid_t) const
Electric charge (in ) for this particle.
Definition
PDG.cpp:98
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
cepgen::pdgids_t
std::vector< pdgid_t > pdgids_t
Definition
ParticleProperties.h:27
cepgen::Element::invalid
@ invalid
cepgen::spdgid_t
long long spdgid_t
Definition
ParticleProperties.h:28
cepgen::operator<<
std::ostream & operator<<(std::ostream &os, const Exception::Type &type)
Definition
Exception.cpp:59
pdg
Definition
MCDFileParser.cpp:28
cepgen::HeavyIon::fromPdgId
static HeavyIon fromPdgId(pdgid_t)
Build from a custom PDG id.
Definition
HeavyIon.cpp:34
cepgen::HeavyIon::mass
double mass() const
Total heavy ion mass, in GeV/c2.
Definition
HeavyIon.h:56
cepgen::HeavyIon::isHI
static bool isHI(const spdgid_t &)
Check if the PDG id is compatible with a HI.
Definition
HeavyIon.cpp:54
cepgen::ParticleProperties
A collection of physics constants associated to a single particle.
Definition
ParticleProperties.h:31
cepgen::ParticleProperties::descr
std::string descr
Human-readable name.
Definition
ParticleProperties.h:50
cepgen::ParticleProperties::mass
double mass
Mass, in GeV/c .
Definition
ParticleProperties.h:52
cepgen::ParticleProperties::pdgid
pdgid_t pdgid
PDG identifier.
Definition
ParticleProperties.h:48
cepgen::ParticleProperties::charges
std::vector< int > charges
Electric charges, in /3.
Definition
ParticleProperties.h:54
cepgen::ParticleProperties::name
std::string name
Particle name.
Definition
ParticleProperties.h:49
cepgen::ParticleProperties::integerCharge
short integerCharge() const
Integer charge, in /3.
Definition
ParticleProperties.cpp:57
cepgen::ParticleProperties::width
double width
Decay width, in GeV/c .
Definition
ParticleProperties.h:53
cepgen::ParticleProperties::colours
int colours
Colour factor.
Definition
ParticleProperties.h:51
CepGen
Physics
PDG.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7