cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Particle.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/Event/Particle.h
"
22
#include "
CepGen/Physics/PDG.h
"
23
#include "
CepGen/Utils/Collections.h
"
24
#include "
CepGen/Utils/Message.h
"
25
#include "
CepGen/Utils/String.h
"
26
27
namespace
cepgen
{
28
Particle::Particle
(
Role
role,
pdgid_t
pdgId,
Status
st) : role_(role), status_((int)st), pdg_id_(pdgId) {}
29
30
bool
Particle::operator<
(
const
Particle
& rhs)
const
{
return
id_
>= 0 && rhs.
id_
> 0 &&
id_
< rhs.
id_
; }
31
32
bool
Particle::operator==
(
const
Particle
& oth)
const
{
33
return
id_
== oth.
id_
&&
pdg_id_
== oth.
pdg_id_
&&
antiparticle_
== oth.
antiparticle_
&&
34
helicity_
== oth.
helicity_
&&
status_
== oth.
status_
&&
momentum_
== oth.
momentum_
;
35
}
36
37
bool
Particle::valid
() {
38
if
(
pdg_id_
==
PDG::invalid
)
39
return
false
;
40
if
(
momentum_
.
p
() == 0. &&
momentum_
.
mass
() == 0.)
41
return
false
;
42
return
true
;
43
}
44
45
float
Particle::charge
()
const
{
return
(
antiparticle_
? -1 : +1) *
PDG::get
()(
pdg_id_
).integerCharge() / 3.; }
46
47
Particle
&
Particle::addMother
(
Particle
& part) {
48
if
(
const
auto
ret =
mothers_
.insert(part.
id_
); ret.second) {
49
CG_DEBUG_LOOP
(
"Particle"
) <<
"Particle "
<<
id
() <<
" (pdgId="
<< part.
pdg_id_
<<
") "
<<
"is a new mother of "
50
<<
id_
<<
" (pdgId="
<<
pdg_id_
<<
")."
;
51
if
(!
utils::contains
(part.
daughters_
,
id_
))
52
part.
addDaughter
(*
this
);
53
else
if
(part.
status_
> 0)
54
part.
status_
= (int)
Status::Propagator
;
55
}
56
return
*
this
;
57
}
58
59
Particle
&
Particle::addDaughter
(
Particle
& part) {
60
if
(
const
auto
ret =
daughters_
.insert(part.
id_
); ret.second) {
61
CG_DEBUG_LOOP
(
"Particle"
) <<
"Particle "
<< part.
role_
<<
" (pdgId="
<< part.
pdg_id_
<<
") "
62
<<
"is a new daughter of "
<<
role_
<<
" (pdgId="
<<
pdg_id_
<<
")."
;
63
if
(!
utils::contains
(part.
mothers_
,
id_
))
64
part.
addMother
(*
this
);
65
if
(
status_
> 0)
66
status_
= (int)
Status::Propagator
;
67
}
68
CG_DEBUG_LOOP
(
"Particle"
).log([&](
auto
& dbg) {
69
dbg <<
"Particle "
<<
role_
<<
" (pdgId="
<< (int)
pdg_id_
<<
")"
<<
" has now "
70
<<
utils::s
(
"daughter"
,
daughters_
.size(),
true
) <<
":"
;
71
for
(
const
auto
& daughter :
daughters_
)
72
dbg <<
utils::format
(
"\n\t * id=%d"
, daughter);
73
});
74
return
*
this
;
75
}
76
77
Particle
&
Particle::setMomentum
(
const
Momentum
& mom,
bool
offshell) {
78
momentum_
= mom;
79
if
(!offshell)
80
momentum_
.
computeEnergyFromMass
(
PDG::get
().mass(
pdg_id_
));
81
return
*
this
;
82
}
83
84
Particle
&
Particle::setMomentum
(
double
px,
double
py,
double
pz,
double
e) {
85
momentum_
.
setP
(px, py, pz).
setEnergy
(e);
86
if
(fabs(e -
momentum_
.
energy
()) > 1.e-6)
// more than 1 eV difference
87
CG_WARNING
(
"Particle"
) <<
"Energy difference: "
<< e -
momentum_
.
energy
();
88
return
*
this
;
89
}
90
91
pdgid_t
Particle::pdgId
()
const
{
return
pdg_id_
; }
92
93
Particle
&
Particle::setPdgId
(
pdgid_t
pdg
,
short
ch) {
return
setIntegerPdgId
(
pdg
* (ch == 0 ? 1 : ch / abs(ch))); }
94
95
Particle
&
Particle::setIntegerPdgId
(
long
pdg
) {
96
if
(
pdg_id_
= labs(
pdg
);
PDG::get
().
has
(
pdg_id_
))
97
CG_DEBUG
(
"Particle:setIntegerPdgId"
) <<
"Particle PDG id set to "
<<
pdg_id_
<<
"."
;
98
antiparticle_
=
pdg
< 0;
99
return
*
this
;
100
}
101
102
long
Particle::integerPdgId
()
const
{
return
static_cast<
long
>
(
pdg_id_
) * (
antiparticle_
? -1 : +1); }
103
104
std::ostream&
operator<<
(std::ostream& os,
const
Particle
& part) {
105
os << std::resetiosflags(std::ios::showbase) <<
"Particle["
<< part.
id_
<<
"]{role="
<< part.
role_
106
<<
", status="
<< (int)part.
status_
<<
", "
<<
"pdg="
<< part.
integerPdgId
() <<
", p4="
<< part.
momentum_
107
<<
" GeV, m="
<< part.
momentum_
.
mass
() <<
" GeV, "
<<
"p⟂="
<< part.
momentum_
.
pt
()
108
<<
" GeV, eta="
<< part.
momentum_
.
eta
() <<
", phi="
<< part.
momentum_
.
phi
();
109
if
(part.
primary
())
110
os <<
", primary"
;
111
else
{
112
os <<
", "
<<
utils::s
(
"mother"
, part.
mothers_
.size());
113
if
(!part.
mothers_
.empty()) {
114
os <<
"="
;
115
std::string delim;
116
for
(
const
auto
moth : part.
mothers_
)
117
os << delim << moth, delim =
","
;
118
}
119
}
120
const
auto
& daughters_list = part.
daughters
();
121
if
(!daughters_list.empty()) {
122
os <<
", "
<<
utils::s
(
"daughter"
, daughters_list.size()) <<
"="
;
123
std::string delim;
124
for
(
const
auto
& daughter : daughters_list)
125
os << delim << daughter, delim =
","
;
126
}
127
return
os <<
"}"
;
128
}
129
130
std::ostream&
operator<<
(std::ostream& os,
const
Particle::Status
& st) {
131
switch
(st) {
132
case
Particle::Status::PrimordialIncoming
:
133
return
os <<
"incoming beam particle"
;
134
case
Particle::Status::DebugResonance
:
135
return
os <<
"intermediate resonance"
;
136
case
Particle::Status::Resonance
:
137
return
os <<
"decayed intermediate resonance"
;
138
case
Particle::Status::Fragmented
:
139
return
os <<
"fragmented outgoing beam"
;
140
case
Particle::Status::Propagator
:
141
return
os <<
"propagator"
;
142
case
Particle::Status::Incoming
:
143
return
os <<
"incoming parton"
;
144
case
Particle::Status::Undefined
:
145
return
os <<
"undefined"
;
146
case
Particle::Status::FinalState
:
147
return
os <<
"final state particle"
;
148
case
Particle::Status::Undecayed
:
149
return
os <<
"particle to be decayed externally"
;
150
case
Particle::Status::Unfragmented
:
151
return
os <<
"particle to be hadronised externally"
;
152
}
153
return
os;
154
}
155
156
std::ostream&
operator<<
(std::ostream& os,
const
Particle::Role
& rl) {
157
switch
(rl) {
158
case
Particle::UnknownRole
:
159
return
os <<
"unknown"
;
160
case
Particle::IncomingBeam1
:
161
return
os <<
"i.beam 1"
;
162
case
Particle::IncomingBeam2
:
163
return
os <<
"i.beam 2"
;
164
case
Particle::OutgoingBeam1
:
165
return
os <<
"o.beam 1"
;
166
case
Particle::OutgoingBeam2
:
167
return
os <<
"o.beam 2"
;
168
case
Particle::Parton1
:
169
return
os <<
"parton 1"
;
170
case
Particle::Parton2
:
171
return
os <<
"parton 2"
;
172
case
Particle::Intermediate
:
173
return
os <<
"hard pr."
;
174
case
Particle::CentralSystem
:
175
return
os <<
"central"
;
176
}
177
return
os;
178
}
179
180
ParticlesMap::ParticlesMap
(
const
ParticlesMap
& oth)
181
: std::unordered_map<
Particle
::Role,
Particles
, utils::EnumHash<
Particle
::Role> >() {
182
*
this
= oth;
183
}
184
185
ParticlesMap
&
ParticlesMap::operator=
(
const
ParticlesMap
& oth) {
186
for
(
const
auto
& parts_vs_role : oth)
187
for
(
const
auto
& part : parts_vs_role.second)
188
(*
this
)[parts_vs_role.first].emplace_back(
Particle
(part));
189
return
*
this
;
190
}
191
}
// namespace cepgen
Collections.h
Message.h
CG_WARNING
#define CG_WARNING(mod)
Definition
Message.h:228
CG_DEBUG_LOOP
#define CG_DEBUG_LOOP(mod)
Definition
Message.h:224
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
PDG.h
Particle.h
String.h
cepgen::Momentum
Container for a particle's 4-momentum, along with useful methods to ease the development of any matri...
Definition
Momentum.h:33
cepgen::Momentum::eta
double eta() const
Pseudo-rapidity.
Definition
Momentum.cpp:240
cepgen::Momentum::computeEnergyFromMass
Momentum & computeEnergyFromMass(double on_shell_mass)
Compute the mass from 4-momentum.
Definition
Momentum.cpp:186
cepgen::Momentum::setP
Momentum & setP(double px, double py, double pz, double e)
Set all the components of the 4-momentum (in GeV)
Definition
Momentum.cpp:180
cepgen::Momentum::setEnergy
Momentum & setEnergy(double)
Set the energy (in GeV)
Definition
Momentum.cpp:171
cepgen::Momentum::pt
double pt() const
Transverse momentum (in GeV)
Definition
Momentum.cpp:232
cepgen::Momentum::phi
double phi() const
Azimuthal angle (angle in the transverse plane)
Definition
Momentum.cpp:230
cepgen::Momentum::p
double p() const
3-momentum norm (in GeV)
Definition
Momentum.h:130
cepgen::Momentum::mass
double mass() const
Mass (in GeV) as computed from its energy and momentum.
Definition
Momentum.cpp:222
cepgen::Momentum::energy
double energy() const
Energy (in GeV)
Definition
Momentum.h:136
cepgen::PDG::has
bool has(spdgid_t) const
Is the particle defined for a given PDG id.
Definition
PDG.cpp:46
cepgen::PDG::invalid
@ invalid
Definition
PDG.h:34
cepgen::PDG::get
static PDG & get()
Retrieve a unique instance of this particles info collection.
Definition
PDG.cpp:41
cepgen::Particle
Kinematic information for one particle.
Definition
Particle.h:33
cepgen::Particle::pdgId
pdgid_t pdgId() const
Retrieve the objectified PDG identifier Set the PDG identifier (along with the particle's electric ch...
Definition
Particle.cpp:91
cepgen::Particle::addDaughter
Particle & addDaughter(Particle &part)
Add a decay product.
Definition
Particle.cpp:59
cepgen::Particle::momentum_
Momentum momentum_
Momentum properties handler.
Definition
Particle.h:157
cepgen::Particle::helicity_
float helicity_
Helicity.
Definition
Particle.h:158
cepgen::Particle::valid
bool valid()
Is this particle a valid particle which can be used for kinematic computations?
Definition
Particle.cpp:37
cepgen::Particle::operator<
bool operator<(const Particle &) const
Comparison operator (from unique identifier)
Definition
Particle.cpp:30
cepgen::Particle::role_
Role role_
Role in the process.
Definition
Particle.h:159
cepgen::Particle::daughters
ParticlesIds daughters() const
Identifiers list of all daughter particles.
Definition
Particle.h:147
cepgen::Particle::status_
int status_
Decay/stability status.
Definition
Particle.h:160
cepgen::Particle::integerPdgId
long integerPdgId() const
Retrieve the integer value of the PDG identifier.
Definition
Particle.cpp:102
cepgen::Particle::setMomentum
Particle & setMomentum(const Momentum &, bool offshell=false)
Associate a momentum object to this particle.
Definition
Particle.cpp:77
cepgen::Particle::addMother
Particle & addMother(Particle &part)
Set the mother particle.
Definition
Particle.cpp:47
cepgen::Particle::Status
Status
Internal status code for a particle.
Definition
Particle.h:36
cepgen::Particle::Status::Undecayed
@ Undecayed
Particle to be decayed externally.
cepgen::Particle::Status::Fragmented
@ Fragmented
Already fragmented outgoing beam.
cepgen::Particle::Status::PrimordialIncoming
@ PrimordialIncoming
Incoming beam particle.
cepgen::Particle::Status::Incoming
@ Incoming
Incoming parton.
cepgen::Particle::Status::FinalState
@ FinalState
Stable, final state particle.
cepgen::Particle::Status::Resonance
@ Resonance
Already decayed intermediate resonance.
cepgen::Particle::Status::Unfragmented
@ Unfragmented
Particle to be hadronised externally.
cepgen::Particle::Status::Propagator
@ Propagator
Generic propagator.
cepgen::Particle::Status::DebugResonance
@ DebugResonance
Intermediate resonance (for processes developers)
cepgen::Particle::Status::Undefined
@ Undefined
Undefined particle.
cepgen::Particle::id
int id() const
Unique identifier (in a Event object context) Set the particle unique identifier in an event.
Definition
Particle.h:76
cepgen::Particle::setIntegerPdgId
Particle & setIntegerPdgId(long pdg_id)
Definition
Particle.cpp:95
cepgen::Particle::charge
float charge() const
Electric charge (given as a float number, for the quarks and bound states) Set whether we are coping ...
Definition
Particle.cpp:45
cepgen::Particle::operator==
bool operator==(const Particle &) const
Equality operator.
Definition
Particle.cpp:32
cepgen::Particle::primary
bool primary() const
Is this particle a primary particle?
Definition
Particle.h:142
cepgen::Particle::antiparticle_
bool antiparticle_
Are we dealing with the particle or antiparticle?
Definition
Particle.h:156
cepgen::Particle::id_
int id_
Unique identifier in an event.
Definition
Particle.h:155
cepgen::Particle::Particle
Particle(Role role=Role::UnknownRole, pdgid_t id=0, Status st=Status::Undefined)
Build using the role of the particle in the process and its PDG id.
Definition
Particle.cpp:28
cepgen::Particle::Role
Role
Definition
Particle.h:50
cepgen::Particle::IncomingBeam2
@ IncomingBeam2
incoming beam particle
Definition
Particle.h:53
cepgen::Particle::Parton2
@ Parton2
beam incoming parton
Definition
Particle.h:59
cepgen::Particle::OutgoingBeam1
@ OutgoingBeam1
outgoing beam state/particle
Definition
Particle.h:54
cepgen::Particle::UnknownRole
@ UnknownRole
Undefined role.
Definition
Particle.h:51
cepgen::Particle::IncomingBeam1
@ IncomingBeam1
incoming beam particle
Definition
Particle.h:52
cepgen::Particle::OutgoingBeam2
@ OutgoingBeam2
outgoing beam state/particle
Definition
Particle.h:55
cepgen::Particle::Parton1
@ Parton1
beam incoming parton
Definition
Particle.h:58
cepgen::Particle::CentralSystem
@ CentralSystem
Central particles system.
Definition
Particle.h:56
cepgen::Particle::Intermediate
@ Intermediate
Intermediate two-parton system.
Definition
Particle.h:57
cepgen::Particle::mothers_
ParticlesIds mothers_
List of mother particles.
Definition
Particle.h:161
cepgen::Particle::pdg_id_
pdgid_t pdg_id_
PDG id.
Definition
Particle.h:163
cepgen::Particle::setPdgId
Particle & setPdgId(pdgid_t pdg, short ch=0)
Set the PDG identifier (along with the particle's electric charge)
Definition
Particle.cpp:93
cepgen::Particle::daughters_
ParticlesIds daughters_
List of daughter particles.
Definition
Particle.h:162
cepgen::ParticlesMap
Map between a particle's role and its associated Particle object.
Definition
Particle.h:174
cepgen::ParticlesMap::ParticlesMap
ParticlesMap()=default
cepgen::ParticlesMap::operator=
ParticlesMap & operator=(const ParticlesMap &)
Definition
Particle.cpp:185
cepgen::utils::format
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition
String.h:61
cepgen::utils::s
std::string s(const std::string &word, float num, bool show_number)
Add a trailing "s" when needed.
Definition
String.cpp:228
cepgen::utils::contains
bool contains(const std::vector< T > &coll, const T &item)
Check if a vector contains an item.
Definition
Collections.h:47
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
cepgen::pdgid_t
unsigned long long pdgid_t
Alias for the integer-like particle PDG id.
Definition
ParticleProperties.h:26
cepgen::operator<<
std::ostream & operator<<(std::ostream &os, const Exception::Type &type)
Definition
Exception.cpp:59
cepgen::Particles
std::vector< Particle > Particles
List of Particle objects.
Definition
Particle.h:169
pdg
Definition
MCDFileParser.cpp:28
CepGen
Event
Particle.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7