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
22#include "CepGen/Physics/PDG.h"
25#include "CepGen/Utils/String.h"
26
27namespace 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
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
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
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)
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)
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
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) {
133 return os << "incoming beam particle";
135 return os << "intermediate resonance";
137 return os << "decayed intermediate resonance";
139 return os << "fragmented outgoing beam";
141 return os << "propagator";
143 return os << "incoming parton";
145 return os << "undefined";
147 return os << "final state particle";
149 return os << "particle to be decayed externally";
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) {
159 return os << "unknown";
161 return os << "i.beam 1";
163 return os << "i.beam 2";
165 return os << "o.beam 1";
167 return os << "o.beam 2";
169 return os << "parton 1";
171 return os << "parton 2";
173 return os << "hard pr.";
175 return os << "central";
176 }
177 return os;
178 }
179
181 : std::unordered_map<Particle::Role, Particles, utils::EnumHash<Particle::Role> >() {
182 *this = oth;
183 }
184
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
#define CG_WARNING(mod)
Definition Message.h:228
#define CG_DEBUG_LOOP(mod)
Definition Message.h:224
#define CG_DEBUG(mod)
Definition Message.h:220
Container for a particle's 4-momentum, along with useful methods to ease the development of any matri...
Definition Momentum.h:33
double eta() const
Pseudo-rapidity.
Definition Momentum.cpp:240
Momentum & computeEnergyFromMass(double on_shell_mass)
Compute the mass from 4-momentum.
Definition Momentum.cpp:186
Momentum & setP(double px, double py, double pz, double e)
Set all the components of the 4-momentum (in GeV)
Definition Momentum.cpp:180
Momentum & setEnergy(double)
Set the energy (in GeV)
Definition Momentum.cpp:171
double pt() const
Transverse momentum (in GeV)
Definition Momentum.cpp:232
double phi() const
Azimuthal angle (angle in the transverse plane)
Definition Momentum.cpp:230
double p() const
3-momentum norm (in GeV)
Definition Momentum.h:130
double mass() const
Mass (in GeV) as computed from its energy and momentum.
Definition Momentum.cpp:222
double energy() const
Energy (in GeV)
Definition Momentum.h:136
bool has(spdgid_t) const
Is the particle defined for a given PDG id.
Definition PDG.cpp:46
@ invalid
Definition PDG.h:34
static PDG & get()
Retrieve a unique instance of this particles info collection.
Definition PDG.cpp:41
Kinematic information for one particle.
Definition Particle.h:33
pdgid_t pdgId() const
Retrieve the objectified PDG identifier Set the PDG identifier (along with the particle's electric ch...
Definition Particle.cpp:91
Particle & addDaughter(Particle &part)
Add a decay product.
Definition Particle.cpp:59
Momentum momentum_
Momentum properties handler.
Definition Particle.h:157
float helicity_
Helicity.
Definition Particle.h:158
bool valid()
Is this particle a valid particle which can be used for kinematic computations?
Definition Particle.cpp:37
bool operator<(const Particle &) const
Comparison operator (from unique identifier)
Definition Particle.cpp:30
Role role_
Role in the process.
Definition Particle.h:159
ParticlesIds daughters() const
Identifiers list of all daughter particles.
Definition Particle.h:147
int status_
Decay/stability status.
Definition Particle.h:160
long integerPdgId() const
Retrieve the integer value of the PDG identifier.
Definition Particle.cpp:102
Particle & setMomentum(const Momentum &, bool offshell=false)
Associate a momentum object to this particle.
Definition Particle.cpp:77
Particle & addMother(Particle &part)
Set the mother particle.
Definition Particle.cpp:47
Status
Internal status code for a particle.
Definition Particle.h:36
@ Undecayed
Particle to be decayed externally.
@ Fragmented
Already fragmented outgoing beam.
@ PrimordialIncoming
Incoming beam particle.
@ Incoming
Incoming parton.
@ FinalState
Stable, final state particle.
@ Resonance
Already decayed intermediate resonance.
@ Unfragmented
Particle to be hadronised externally.
@ Propagator
Generic propagator.
@ DebugResonance
Intermediate resonance (for processes developers)
@ Undefined
Undefined particle.
int id() const
Unique identifier (in a Event object context) Set the particle unique identifier in an event.
Definition Particle.h:76
Particle & setIntegerPdgId(long pdg_id)
Definition Particle.cpp:95
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
bool operator==(const Particle &) const
Equality operator.
Definition Particle.cpp:32
bool primary() const
Is this particle a primary particle?
Definition Particle.h:142
bool antiparticle_
Are we dealing with the particle or antiparticle?
Definition Particle.h:156
int id_
Unique identifier in an event.
Definition Particle.h:155
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
@ IncomingBeam2
incoming beam particle
Definition Particle.h:53
@ Parton2
beam incoming parton
Definition Particle.h:59
@ OutgoingBeam1
outgoing beam state/particle
Definition Particle.h:54
@ UnknownRole
Undefined role.
Definition Particle.h:51
@ IncomingBeam1
incoming beam particle
Definition Particle.h:52
@ OutgoingBeam2
outgoing beam state/particle
Definition Particle.h:55
@ Parton1
beam incoming parton
Definition Particle.h:58
@ CentralSystem
Central particles system.
Definition Particle.h:56
@ Intermediate
Intermediate two-parton system.
Definition Particle.h:57
ParticlesIds mothers_
List of mother particles.
Definition Particle.h:161
pdgid_t pdg_id_
PDG id.
Definition Particle.h:163
Particle & setPdgId(pdgid_t pdg, short ch=0)
Set the PDG identifier (along with the particle's electric charge)
Definition Particle.cpp:93
ParticlesIds daughters_
List of daughter particles.
Definition Particle.h:162
Map between a particle's role and its associated Particle object.
Definition Particle.h:174
ParticlesMap & operator=(const ParticlesMap &)
Definition Particle.cpp:185
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition String.h:61
std::string s(const std::string &word, float num, bool show_number)
Add a trailing "s" when needed.
Definition String.cpp:228
bool contains(const std::vector< T > &coll, const T &item)
Check if a vector contains an item.
Definition Collections.h:47
Common namespace for this Monte Carlo generator.
unsigned long long pdgid_t
Alias for the integer-like particle PDG id.
std::ostream & operator<<(std::ostream &os, const Exception::Type &type)
Definition Exception.cpp:59
std::vector< Particle > Particles
List of Particle objects.
Definition Particle.h:169