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
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 if (PDG::get().has(pdg_id_))
31 }
32
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_))
45 }
46
47 bool Particle::operator<(const Particle& rhs) const { return id_ >= 0 && rhs.id_ > 0 && id_ < rhs.id_; }
48
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
60 mothers_.clear();
61 return *this;
62 }
63
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
79 daughters_.clear();
80 return *this;
81 }
82
84 const auto ret = daughters_.insert(part.id_);
85 if (status_ > 0)
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)
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
123 if (pdg_id_ = labs(pdg); PDG::get().has(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) {
163 return os << "incoming beam particle";
165 return os << "intermediate resonance";
167 return os << "decayed intermediate resonance";
169 return os << "fragmented outgoing beam";
171 return os << "propagator";
173 return os << "incoming parton";
175 return os << "undefined";
177 return os << "final state particle";
179 return os << "particle to be decayed externally";
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) {
189 return os << "unknown";
191 return os << "i.beam 1";
193 return os << "i.beam 2";
195 return os << "o.beam 1";
197 return os << "o.beam 2";
199 return os << "parton 1";
201 return os << "parton 2";
203 return os << "hard pr.";
205 return os << "central";
206 }
207 return os;
208 }
209
211 : std::unordered_map<Particle::Role, Particles, utils::EnumHash<Particle::Role> >() {
212 *this = oth;
213 }
214
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
#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:187
Momentum & setP(double px, double py, double pz, double e)
Set all the components of the 4-momentum (in GeV)
Definition Momentum.cpp:181
Momentum & setEnergy(double)
Set the energy (in GeV)
Definition Momentum.cpp:172
double pt() const
Transverse momentum (in GeV)
Definition Momentum.cpp:234
double phi() const
Azimuthal angle (angle in the transverse plane)
Definition Momentum.cpp:232
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:224
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:118
Particle & addDaughter(Particle &part)
Add a decay product.
Definition Particle.cpp:83
Momentum momentum_
Momentum properties handler.
Definition Particle.h:159
Particle & clearMothers()
Clear the particle parentage.
Definition Particle.cpp:59
bool valid()
Is this particle a valid particle which can be used for kinematic computations?
Definition Particle.cpp:49
Role role_
Role in the process.
Definition Particle.h:161
ParticlesIds daughters() const
Number of daughter particles.
Definition Particle.h:150
int status_
Decay/stability status.
Definition Particle.h:162
long integerPdgId() const
Retrieve the integer value of the PDG identifier.
Definition Particle.cpp:132
bool operator<(const Particle &rhs) const
Comparison operator (from unique identifier)
Definition Particle.cpp:47
Particle & setMomentum(const Momentum &, bool offshell=false)
Associate a momentum object to this particle.
Definition Particle.cpp:104
Particle & addMother(Particle &part)
Set the mother particle.
Definition Particle.cpp:64
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:77
Particle & setIntegerPdgId(long pdg_id)
Definition Particle.cpp:122
Particle & clearDaughters()
Remove the decay products linking.
Definition Particle.cpp:78
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
bool primary() const
Is this particle a primary particle?
Definition Particle.h:143
bool antiparticle_
Are we dealing with the particle or antiparticle?
Definition Particle.h:158
int id_
Unique identifier in an event.
Definition Particle.h:157
ParticleProperties phys_prop_
Collection of standard, bare-level physical properties.
Definition Particle.h:166
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:163
pdgid_t pdg_id_
PDG id.
Definition Particle.h:165
Particle & setPdgId(pdgid_t pdg, short ch=0)
Set the PDG identifier (along with the particle's electric charge)
Definition Particle.cpp:120
ParticlesIds daughters_
List of daughter particles.
Definition Particle.h:164
Map between a particle's role and its associated Particle object.
Definition Particle.h:177
ParticlesMap & operator=(const ParticlesMap &)
Definition Particle.cpp:215
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition String.h:59
std::string s(const std::string &word, float num, bool show_number)
Add a trailing "s" when needed.
Definition String.cpp:219
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:172
double mass
Mass, in GeV/c .
short integerCharge() const
Integer charge, in /3.