cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.3
A generic 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-2021 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
if
(
PDG::get
().has(
pdg_id_
))
30
phys_prop_
=
PDG::get
()(
pdg_id_
);
31
}
32
33
Particle::Particle
(
const
Particle
& part)
34
: id_(part.id_),
35
antiparticle_(part.antiparticle_),
36
momentum_(part.momentum_),
37
helicity_(part.helicity_),
38
role_(part.role_),
39
status_(part.status_),
40
mothers_(part.mothers_),
41
daughters_(part.daughters_),
42
pdg_id_(part.pdg_id_) {
43
if
(
PDG::get
().has(
pdg_id_
))
44
phys_prop_
=
PDG::get
()(
pdg_id_
);
45
}
46
47
bool
Particle::operator<
(
const
Particle
& rhs)
const
{
return
id_
>= 0 && rhs.
id_
> 0 &&
id_
< rhs.
id_
; }
48
49
bool
Particle::valid
() {
50
if
(
pdg_id_
==
PDG::invalid
)
51
return
false
;
52
if
(
momentum_
.
p
() == 0. &&
momentum_
.
mass
() == 0.)
53
return
false
;
54
return
true
;
55
}
56
57
float
Particle::charge
()
const
{
return
(
antiparticle_
? -1 : +1) *
phys_prop_
.
integerCharge
() / 3.; }
58
59
Particle
&
Particle::clearMothers
() {
60
mothers_
.clear();
61
return
*
this
;
62
}
63
64
Particle
&
Particle::addMother
(
Particle
& part) {
65
const
auto
ret =
mothers_
.insert(part.
id_
);
66
if
(part.
status_
> 0)
67
part.
status_
= (int)
Status::Propagator
;
68
69
if
(ret.second) {
70
CG_DEBUG_LOOP
(
"Particle"
) <<
"Particle "
<<
id
() <<
" (pdgId="
<< part.
pdg_id_
<<
") "
71
<<
"is a new mother of "
<<
id_
<<
" (pdgId="
<<
pdg_id_
<<
")."
;
72
if
(!
utils::contains
(part.
daughters_
,
id_
))
73
part.
addDaughter
(*
this
);
74
}
75
return
*
this
;
76
}
77
78
Particle
&
Particle::clearDaughters
() {
79
daughters_
.clear();
80
return
*
this
;
81
}
82
83
Particle
&
Particle::addDaughter
(
Particle
& part) {
84
const
auto
ret =
daughters_
.insert(part.
id_
);
85
if
(
status_
> 0)
86
status_
= (int)
Status::Propagator
;
87
88
CG_DEBUG_LOOP
(
"Particle"
).log([&](
auto
& dbg) {
89
dbg <<
"Particle "
<<
role_
<<
" (pdgId="
<< (int)
pdg_id_
<<
")"
90
<<
" has now "
<<
utils::s
(
"daughter"
,
daughters_
.size(),
true
) <<
":"
;
91
for
(
const
auto
& daughter :
daughters_
)
92
dbg <<
utils::format
(
"\n\t * id=%d"
, daughter);
93
});
94
95
if
(ret.second) {
96
CG_DEBUG_LOOP
(
"Particle"
) <<
"Particle "
<< part.
role_
<<
" (pdgId="
<< part.
pdg_id_
<<
") "
97
<<
"is a new daughter of "
<<
role_
<<
" (pdgId="
<<
pdg_id_
<<
")."
;
98
if
(!
utils::contains
(part.
mothers_
,
id_
))
99
part.
addMother
(*
this
);
100
}
101
return
*
this
;
102
}
103
104
Particle
&
Particle::setMomentum
(
const
Momentum
& mom,
bool
offshell) {
105
momentum_
= mom;
106
if
(!offshell)
107
momentum_
.
computeEnergyFromMass
(
phys_prop_
.
mass
);
108
return
*
this
;
109
}
110
111
Particle
&
Particle::setMomentum
(
double
px,
double
py,
double
pz,
double
e) {
112
momentum_
.
setP
(px, py, pz).
setEnergy
(e);
113
if
(fabs(e -
momentum_
.
energy
()) > 1.e-6)
// more than 1 eV difference
114
CG_WARNING
(
"Particle"
) <<
"Energy difference: "
<< e -
momentum_
.
energy
();
115
return
*
this
;
116
}
117
118
pdgid_t
Particle::pdgId
()
const
{
return
pdg_id_
; }
119
120
Particle
&
Particle::setPdgId
(
pdgid_t
pdg
,
short
ch) {
return
setIntegerPdgId
(
pdg
* (ch == 0 ? 1 : ch / abs(ch))); }
121
122
Particle
&
Particle::setIntegerPdgId
(
long
pdg
) {
123
if
(
pdg_id_
= labs(
pdg
);
PDG::get
().
has
(
pdg_id_
)) {
124
phys_prop_
=
PDG::get
()(
pdg_id_
);
125
CG_DEBUG
(
"Particle:setIntegerPdgId"
) <<
"Particle PDG id set to "
<<
pdg_id_
<<
", "
126
<<
"properties set "
<<
phys_prop_
<<
"."
;
127
}
128
antiparticle_
=
pdg
< 0;
129
return
*
this
;
130
}
131
132
long
Particle::integerPdgId
()
const
{
return
static_cast<
long
>
(
pdg_id_
) * (
antiparticle_
? -1 : +1); }
133
134
std::ostream&
operator<<
(std::ostream& os,
const
Particle
& part) {
135
os << std::resetiosflags(std::ios::showbase) <<
"Particle["
<< part.
id_
<<
"]{role="
<< part.
role_
136
<<
", status="
<< (int)part.
status_
<<
", "
137
<<
"pdg="
<< part.
integerPdgId
() <<
", p4="
<< part.
momentum_
<<
" GeV, m="
<< part.
momentum_
.
mass
() <<
" GeV, "
138
<<
"p⟂="
<< part.
momentum_
.
pt
() <<
" GeV, eta="
<< part.
momentum_
.
eta
() <<
", phi="
<< part.
momentum_
.
phi
();
139
if
(part.
primary
())
140
os <<
", primary"
;
141
else
{
142
os <<
", "
<<
utils::s
(
"mother"
, part.
mothers_
.size());
143
if
(!part.
mothers_
.empty()) {
144
os <<
"="
;
145
std::string delim;
146
for
(
const
auto
moth : part.
mothers_
)
147
os << delim << moth, delim =
","
;
148
}
149
}
150
const
auto
& daughters_list = part.
daughters
();
151
if
(!daughters_list.empty()) {
152
os <<
", "
<<
utils::s
(
"daughter"
, daughters_list.size()) <<
"="
;
153
std::string delim;
154
for
(
const
auto
& daughter : daughters_list)
155
os << delim << daughter, delim =
","
;
156
}
157
return
os <<
"}"
;
158
}
159
160
std::ostream&
operator<<
(std::ostream& os,
const
Particle::Status
& st) {
161
switch
(st) {
162
case
Particle::Status::PrimordialIncoming
:
163
return
os <<
"incoming beam particle"
;
164
case
Particle::Status::DebugResonance
:
165
return
os <<
"intermediate resonance"
;
166
case
Particle::Status::Resonance
:
167
return
os <<
"decayed intermediate resonance"
;
168
case
Particle::Status::Fragmented
:
169
return
os <<
"fragmented outgoing beam"
;
170
case
Particle::Status::Propagator
:
171
return
os <<
"propagator"
;
172
case
Particle::Status::Incoming
:
173
return
os <<
"incoming parton"
;
174
case
Particle::Status::Undefined
:
175
return
os <<
"undefined"
;
176
case
Particle::Status::FinalState
:
177
return
os <<
"final state particle"
;
178
case
Particle::Status::Undecayed
:
179
return
os <<
"particle to be decayed externally"
;
180
case
Particle::Status::Unfragmented
:
181
return
os <<
"particle to be hadronised externally"
;
182
}
183
return
os;
184
}
185
186
std::ostream&
operator<<
(std::ostream& os,
const
Particle::Role
& rl) {
187
switch
(rl) {
188
case
Particle::UnknownRole
:
189
return
os <<
"unknown"
;
190
case
Particle::IncomingBeam1
:
191
return
os <<
"i.beam 1"
;
192
case
Particle::IncomingBeam2
:
193
return
os <<
"i.beam 2"
;
194
case
Particle::OutgoingBeam1
:
195
return
os <<
"o.beam 1"
;
196
case
Particle::OutgoingBeam2
:
197
return
os <<
"o.beam 2"
;
198
case
Particle::Parton1
:
199
return
os <<
"parton 1"
;
200
case
Particle::Parton2
:
201
return
os <<
"parton 2"
;
202
case
Particle::Intermediate
:
203
return
os <<
"hard pr."
;
204
case
Particle::CentralSystem
:
205
return
os <<
"central"
;
206
}
207
return
os;
208
}
209
210
ParticlesMap::ParticlesMap
(
const
ParticlesMap
& oth)
211
: std::unordered_map<
Particle
::Role,
Particles
, utils::EnumHash<
Particle
::Role> >() {
212
*
this
= oth;
213
}
214
215
ParticlesMap
&
ParticlesMap::operator=
(
const
ParticlesMap
& oth) {
216
for
(
const
auto
& parts_vs_role : oth)
217
for
(
const
auto
& part : parts_vs_role.second)
218
(*
this
)[parts_vs_role.first].emplace_back(
Particle
(part));
219
return
*
this
;
220
}
221
}
// 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:187
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:181
cepgen::Momentum::setEnergy
Momentum & setEnergy(double)
Set the energy (in GeV)
Definition
Momentum.cpp:172
cepgen::Momentum::pt
double pt() const
Transverse momentum (in GeV)
Definition
Momentum.cpp:234
cepgen::Momentum::phi
double phi() const
Azimuthal angle (angle in the transverse plane)
Definition
Momentum.cpp:232
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:224
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:118
cepgen::Particle::addDaughter
Particle & addDaughter(Particle &part)
Add a decay product.
Definition
Particle.cpp:83
cepgen::Particle::momentum_
Momentum momentum_
Momentum properties handler.
Definition
Particle.h:159
cepgen::Particle::clearMothers
Particle & clearMothers()
Clear the particle parentage.
Definition
Particle.cpp:59
cepgen::Particle::valid
bool valid()
Is this particle a valid particle which can be used for kinematic computations?
Definition
Particle.cpp:49
cepgen::Particle::role_
Role role_
Role in the process.
Definition
Particle.h:161
cepgen::Particle::daughters
ParticlesIds daughters() const
Number of daughter particles.
Definition
Particle.h:150
cepgen::Particle::status_
int status_
Decay/stability status.
Definition
Particle.h:162
cepgen::Particle::integerPdgId
long integerPdgId() const
Retrieve the integer value of the PDG identifier.
Definition
Particle.cpp:132
cepgen::Particle::operator<
bool operator<(const Particle &rhs) const
Comparison operator (from unique identifier)
Definition
Particle.cpp:47
cepgen::Particle::setMomentum
Particle & setMomentum(const Momentum &, bool offshell=false)
Associate a momentum object to this particle.
Definition
Particle.cpp:104
cepgen::Particle::addMother
Particle & addMother(Particle &part)
Set the mother particle.
Definition
Particle.cpp:64
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:77
cepgen::Particle::setIntegerPdgId
Particle & setIntegerPdgId(long pdg_id)
Definition
Particle.cpp:122
cepgen::Particle::clearDaughters
Particle & clearDaughters()
Remove the decay products linking.
Definition
Particle.cpp:78
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:57
cepgen::Particle::primary
bool primary() const
Is this particle a primary particle?
Definition
Particle.h:143
cepgen::Particle::antiparticle_
bool antiparticle_
Are we dealing with the particle or antiparticle?
Definition
Particle.h:158
cepgen::Particle::id_
int id_
Unique identifier in an event.
Definition
Particle.h:157
cepgen::Particle::phys_prop_
ParticleProperties phys_prop_
Collection of standard, bare-level physical properties.
Definition
Particle.h:166
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:163
cepgen::Particle::pdg_id_
pdgid_t pdg_id_
PDG id.
Definition
Particle.h:165
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:120
cepgen::Particle::daughters_
ParticlesIds daughters_
List of daughter particles.
Definition
Particle.h:164
cepgen::ParticlesMap
Map between a particle's role and its associated Particle object.
Definition
Particle.h:177
cepgen::ParticlesMap::ParticlesMap
ParticlesMap()=default
cepgen::ParticlesMap::operator=
ParticlesMap & operator=(const ParticlesMap &)
Definition
Particle.cpp:215
cepgen::utils::format
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition
String.h:59
cepgen::utils::s
std::string s(const std::string &word, float num, bool show_number)
Add a trailing "s" when needed.
Definition
String.cpp:219
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:172
pdg
Definition
MCDFileParser.cpp:28
cepgen::ParticleProperties::mass
double mass
Mass, in GeV/c .
Definition
ParticleProperties.h:52
cepgen::ParticleProperties::integerCharge
short integerCharge() const
Integer charge, in /3.
Definition
ParticleProperties.cpp:57
CepGen
Event
Particle.cpp
Generated on Thu Apr 25 2024 for CepGen by
1.9.7