HepMC3 event record library: GenParticle.cc Source File

HepMC3 event record library

GenParticle.cc
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6/**
7 * @file GenParticle.cc
8 * @brief Implementation of \b class GenParticle
9 *
10 */
11#include "HepMC3/Attribute.h"
12#include "HepMC3/GenEvent.h"
13#include "HepMC3/GenParticle.h"
14#include "HepMC3/GenVertex.h"
15#include "HepMC3/Setup.h"
16
17
18namespace HepMC3 {
19
20GenParticle::GenParticle(const FourVector &mom, int pidin, int stat):
21 m_event(nullptr),
22 m_id(0) {
23 m_data.pid = pidin;
24 m_data.momentum = mom;
25 m_data.status = stat;
26 m_data.is_mass_set = false;
27 m_data.mass = 0.0;
28}
29
30 GenParticle::GenParticle(const GenParticleData &dat):
31 m_event(nullptr),
32 m_id(0),
33 m_data(dat) {
34}
35
36 double GenParticle::generated_mass() const {
37 return m_data.is_mass_set ? m_data.mass : m_data.momentum.m();
38}
39
40 void GenParticle::set_pid(int pidin) {
41 m_data.pid = pidin;
42}
43
44 void GenParticle::set_status(int stat) {
45 m_data.status = stat;
46}
47
48 void GenParticle::set_momentum(const FourVector& mom) {
49 m_data.momentum = mom;
50}
51
52 void GenParticle::set_generated_mass(double m) {
53 m_data.mass = m;
54 m_data.is_mass_set = true;
55}
56
57 void GenParticle::unset_generated_mass() {
58 m_data.mass = 0.;
59 m_data.is_mass_set = false;
60}
61
62GenVertexPtr GenParticle::production_vertex() {
63 return m_production_vertex.lock();
64}
65
66ConstGenVertexPtr GenParticle::production_vertex() const {
67 return std::const_pointer_cast<const GenVertex>(m_production_vertex.lock());
68}
69
70GenVertexPtr GenParticle::end_vertex() {
71 return m_end_vertex.lock();
72}
73
74ConstGenVertexPtr GenParticle::end_vertex() const {
75 return std::const_pointer_cast<const GenVertex>(m_end_vertex.lock());
76}
77
78std::vector<GenParticlePtr> GenParticle::parents() {
79 return (m_production_vertex.expired())? std::vector<GenParticlePtr>() : production_vertex()->particles_in();
80}
81
82std::vector<ConstGenParticlePtr> GenParticle::parents() const {
83 return (m_production_vertex.expired()) ? std::vector<ConstGenParticlePtr>() : production_vertex()->particles_in();
84}
85
86std::vector<GenParticlePtr> GenParticle::children() {
87 return (m_end_vertex.expired())? std::vector<GenParticlePtr>() : end_vertex()->particles_out();
88}
89
90std::vector<ConstGenParticlePtr> GenParticle::children() const {
91 return (m_end_vertex.expired()) ? std::vector<ConstGenParticlePtr>() : end_vertex()->particles_out();
92}
93
94 bool GenParticle::add_attribute(const std::string& name, std::shared_ptr<Attribute> att) {
95 if ( !parent_event() ) return false;
96 parent_event()->add_attribute(name, att, id());
97 return true;
98}
99
100std::vector<std::string> GenParticle::attribute_names() const {
101 if ( parent_event() ) return parent_event()->attribute_names(id());
102 return {};
103}
104
105 void GenParticle::remove_attribute(const std::string& name) {
106 if ( parent_event() ) parent_event()->remove_attribute(name, id());
107}
108
109std::string GenParticle::attribute_as_string(const std::string& name) const {
110 return parent_event() ? parent_event()->attribute_as_string(name, id()) : std::string();
111}
112
113} // namespace HepMC3
Attribute.h
Definition of class Attribute, class IntAttribute and class StringAttribute.
GenEvent.h
Definition of class GenEvent.
GenParticle.h
Definition of class GenParticle.
GenVertex.h
Definition of class GenVertex.
Setup.h
Definition of class Setup.
HepMC3::FourVector
Generic 4-vector.
Definition FourVector.h:36
HepMC3::GenEvent::attribute_names
std::vector< std::string > attribute_names(const int &id=0) const
Get list of attribute names.
Definition GenEvent.cc:613
HepMC3::GenEvent::add_attribute
void add_attribute(const std::string &name, const std::shared_ptr< Attribute > &att, const int &id=0)
Definition GenEvent.cc:797
HepMC3::GenEvent::remove_attribute
void remove_attribute(const std::string &name, const int &id=0)
Remove attribute.
Definition GenEvent.cc:602
HepMC3::GenEvent::attribute_as_string
std::string attribute_as_string(const std::string &name, const int &id=0) const
Get attribute of any type as string.
Definition GenEvent.cc:776
HepMC3::GenParticle::set_pid
void set_pid(int pid)
Set PDG ID.
Definition GenParticle.cc:40
HepMC3::GenParticle::end_vertex
ConstGenVertexPtr end_vertex() const
Get end vertex (const version).
Definition GenParticle.cc:74
HepMC3::GenParticle::unset_generated_mass
void unset_generated_mass()
Declare that generated mass is not set.
Definition GenParticle.cc:57
HepMC3::GenParticle::GenParticle
GenParticle(const FourVector &momentum=FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Default constructor.
Definition GenParticle.cc:20
HepMC3::GenParticle::m_event
GenEvent * m_event
Parent event.
Definition GenParticle.h:150
HepMC3::GenParticle::remove_attribute
void remove_attribute(const std::string &name)
Remove attribute.
Definition GenParticle.cc:105
HepMC3::GenParticle::m_production_vertex
std::weak_ptr< GenVertex > m_production_vertex
Production vertex.
Definition GenParticle.h:154
HepMC3::GenParticle::children
std::vector< GenParticlePtr > children()
Convenience access to immediate outgoing particles via end vertex.
Definition GenParticle.cc:86
HepMC3::GenParticle::add_attribute
bool add_attribute(const std::string &name, std::shared_ptr< Attribute > att)
Add an attribute to this particle.
Definition GenParticle.cc:94
HepMC3::GenParticle::attribute_names
std::vector< std::string > attribute_names() const
Get list of names of attributes assigned to this particle.
Definition GenParticle.cc:100
HepMC3::GenParticle::m_end_vertex
std::weak_ptr< GenVertex > m_end_vertex
End vertex.
Definition GenParticle.h:155
HepMC3::GenParticle::parents
std::vector< GenParticlePtr > parents()
Convenience access to immediate incoming particles via production vertex.
Definition GenParticle.cc:78
HepMC3::GenParticle::production_vertex
ConstGenVertexPtr production_vertex() const
Get production vertex (const version).
Definition GenParticle.cc:66
HepMC3::GenParticle::set_momentum
void set_momentum(const FourVector &momentum)
Set momentum.
Definition GenParticle.cc:48
HepMC3::GenParticle::set_status
void set_status(int status)
Set status code.
Definition GenParticle.cc:44
HepMC3::GenParticle::parent_event
GenEvent * parent_event()
Get the parent event.
Definition GenParticle.h:63
HepMC3::GenParticle::set_generated_mass
void set_generated_mass(double m)
Set generated mass.
Definition GenParticle.cc:52
HepMC3::GenParticle::generated_mass
double generated_mass() const
Get generated mass.
Definition GenParticle.cc:36
HepMC3::GenParticle::m_id
int m_id
Index.
Definition GenParticle.h:151
HepMC3::GenParticle::m_data
GenParticleData m_data
Particle data.
Definition GenParticle.h:152
HepMC3::GenParticle::attribute_as_string
std::string attribute_as_string(const std::string &name) const
Get attribute of any type as string.
Definition GenParticle.cc:109
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24
HepMC3::GenParticleData
Stores serializable particle information.
Definition GenParticleData.h:24