HepMC3 event record library
GenVertex.h
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/// @file GenVertex.h
7/// @brief Definition of \b class GenVertex
8//
9#ifndef HEPMC3_GENVERTEX_H
10#define HEPMC3_GENVERTEX_H
11#include <string>
12#include "HepMC3/GenParticle_fwd.h"
13#include "HepMC3/GenVertex_fwd.h"
15#include "HepMC3/FourVector.h"
16
17namespace HepMC3 {
18
19
20class Attribute;
21class GenEvent;
22
23/// Stores vertex-related information
24class GenVertex : public std::enable_shared_from_this<GenVertex> {
25
26 friend class GenEvent;
27
28public:
29
30 /// @name Constructors
31 /// @{
32
33 /// Default constructor
35
36 /// Constructor based on vertex data
38
39 /// @}
40
41public:
42
43 /// @name Accessors
44 /// @{
45
46 /// Get parent event
48
49 /// Get parent event
50 const GenEvent* parent_event() const { return m_event; }
51
52 /// Check if this vertex belongs to an event
53 bool in_event() const { return parent_event() != nullptr; }
54
55 /// Get the vertex unique identifier
56 ///
57 /// @note This is not the same as id() in HepMC v2, which is now @c status()
58 int id() const { return m_id; }
59
60 /// @brief set the vertex identifier
61 void set_id(int id);
62
63 /// Get vertex status code
64 int status() const { return m_data.status; }
65 /// Set vertex status code
66 void set_status(int stat) { m_data.status = stat; }
67
68 /// Get vertex data
69 const GenVertexData& data() const { return m_data; }
70
71 /// Add incoming particle
72 void add_particle_in ( GenParticlePtr p);
73 /// Add outgoing particle
74 void add_particle_out( GenParticlePtr p);
75 /// Remove incoming particle
76 void remove_particle_in ( GenParticlePtr p);
77 /// Remove outgoing particle
78 void remove_particle_out( GenParticlePtr p);
79
80 /// Number of incoming particles, HepMC2 compatiility
81 inline int particles_in_size() const { return m_particles_in.size(); }
82 /// Number of outgoing particles, HepMC2 compatiility
83 inline int particles_out_size() const { return m_particles_out.size(); }
84
85
86 /// Get list of incoming particles
87 const std::vector<GenParticlePtr>& particles_in() { return m_particles_in; }
88 /// Get list of incoming particles (for const access)
89 const std::vector<ConstGenParticlePtr>& particles_in() const;
90 /// Get list of outgoing particles
91 const std::vector<GenParticlePtr>& particles_out() { return m_particles_out; }
92 /// Get list of outgoing particles (for const access)
93 const std::vector<ConstGenParticlePtr>& particles_out() const;
94
95 /// @brief Get vertex position
96 ///
97 /// Returns the position of this vertex. If a position is not set on _this_ vertex,
98 /// the production vertices of ancestors are searched to find the inherited position.
99 /// FourVector(0,0,0,0) is returned if no position information is found.
100 ///
101 const FourVector& position() const;
102 /// @brief Check if position of this vertex is set
103 bool has_set_position() const { return !(m_data.position.is_zero()); }
104
105 /// Set vertex position
106 void set_position(const FourVector& new_pos); //!<
107
108 /// @brief Add event attribute to this vertex
109 ///
110 /// This will overwrite existing attribute if an attribute with
111 /// the same name is present. The attribute will be stored in the
112 /// parent_event(). @return false if there is no parent_event();
113 bool add_attribute(const std::string& name, std::shared_ptr<Attribute> att);
114
115 /// @brief Get list of names of attributes assigned to this particle
116 std::vector<std::string> attribute_names() const;
117
118 /// @brief Remove attribute
119 void remove_attribute(const std::string& name);
120
121 /// @brief Get attribute of type T
122 template<class T>
123 std::shared_ptr<T> attribute(const std::string& name) const;
124
125 /// @brief Get attribute of any type as string
126 std::string attribute_as_string(const std::string& name) const;
127
128 /// @name Deprecated functionality
129 /// @{
130
131
132 /// Add incoming particle by raw pointer
133 /// @deprecated Use GenVertex::add_particle_in( const GenParticlePtr &p ) instead
134 void add_particle_in ( GenParticle *p ) { add_particle_in( GenParticlePtr(p) ); }
135
136 /// Add outgoing particle by raw pointer
137 /// @deprecated Use GenVertex::add_particle_out( const GenParticlePtr &p ) instead
138 void add_particle_out( GenParticle *p ) { add_particle_out( GenParticlePtr(p) ); }
139
140
141 /// @}
142
143
144private:
145
146 /// @name Fields
147 /// @{
148 GenEvent *m_event; //!< Parent event
149 int m_id; //!< Vertex id
150 GenVertexData m_data; //!< Vertex data
151
152 std::vector<GenParticlePtr> m_particles_in; //!< Incoming particle list
153
154 std::vector<GenParticlePtr> m_particles_out; //!< Outgoing particle list
155 /// @}
156
157};
158
159
160} // namespace HepMC3
161
162#include "HepMC3/GenEvent.h"
163namespace HepMC3 {
164/// @brief Get attribute of type T
165template<class T> std::shared_ptr<T> GenVertex::attribute(const std::string& name) const {
166 return parent_event()?
167 parent_event()->attribute<T>(name, id()): std::shared_ptr<T>();
168}
169}
170
171#endif
Definition of class FourVector.
Definition of class GenEvent.
Definition of class GenVertexData.
Generic 4-vector.
Definition FourVector.h:36
bool is_zero() const
Check if the length of this vertex is zero.
Definition FourVector.h:197
static const FourVector & ZERO_VECTOR()
Static null FourVector = (0,0,0,0)
Definition FourVector.h:297
Stores event-related information.
Definition GenEvent.h:41
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
Definition GenEvent.h:417
Stores particle-related information.
Definition GenParticle.h:28
Stores vertex-related information.
Definition GenVertex.h:24
GenVertex(const FourVector &position=FourVector::ZERO_VECTOR())
Default constructor.
Definition GenVertex.cc:22
void remove_particle_out(GenParticlePtr p)
Remove outgoing particle.
Definition GenVertex.cc:75
GenVertexData m_data
Vertex data.
Definition GenVertex.h:150
const std::vector< GenParticlePtr > & particles_out()
Get list of outgoing particles.
Definition GenVertex.h:91
std::shared_ptr< T > attribute(const std::string &name) const
Get attribute of type T.
Definition GenVertex.h:165
void remove_particle_in(GenParticlePtr p)
Remove incoming particle.
Definition GenVertex.cc:67
std::vector< GenParticlePtr > m_particles_in
Incoming particle list.
Definition GenVertex.h:152
GenEvent * m_event
Parent event.
Definition GenVertex.h:148
void add_particle_in(GenParticlePtr p)
Add incoming particle.
Definition GenVertex.cc:36
void remove_attribute(const std::string &name)
Remove attribute.
Definition GenVertex.cc:125
int particles_in_size() const
Number of incoming particles, HepMC2 compatiility.
Definition GenVertex.h:81
void set_position(const FourVector &new_pos)
Set vertex position.
Definition GenVertex.cc:115
std::vector< GenParticlePtr > m_particles_out
Outgoing particle list.
Definition GenVertex.h:154
bool add_attribute(const std::string &name, std::shared_ptr< Attribute > att)
Add event attribute to this vertex.
Definition GenVertex.cc:119
int id() const
Definition GenVertex.h:58
void add_particle_out(GenParticle *p)
Definition GenVertex.h:138
std::vector< std::string > attribute_names() const
Get list of names of attributes assigned to this particle.
Definition GenVertex.cc:133
const GenVertexData & data() const
Get vertex data.
Definition GenVertex.h:69
void set_id(int id)
set the vertex identifier
Definition GenVertex.cc:82
const FourVector & position() const
Get vertex position.
Definition GenVertex.cc:95
int status() const
Get vertex status code.
Definition GenVertex.h:64
void add_particle_in(GenParticle *p)
Definition GenVertex.h:134
GenEvent * parent_event()
Get parent event.
Definition GenVertex.h:47
int m_id
Vertex id.
Definition GenVertex.h:149
void set_status(int stat)
Set vertex status code.
Definition GenVertex.h:66
bool in_event() const
Check if this vertex belongs to an event.
Definition GenVertex.h:53
bool has_set_position() const
Check if position of this vertex is set.
Definition GenVertex.h:103
int particles_out_size() const
Number of outgoing particles, HepMC2 compatiility.
Definition GenVertex.h:83
const GenEvent * parent_event() const
Get parent event.
Definition GenVertex.h:50
void add_particle_out(GenParticlePtr p)
Add outgoing particle.
Definition GenVertex.cc:52
const std::vector< GenParticlePtr > & particles_in()
Get list of incoming particles.
Definition GenVertex.h:87
std::string attribute_as_string(const std::string &name) const
Get attribute of any type as string.
Definition GenVertex.cc:129
HepMC3 main namespace.
Stores serializable vertex information.
int status
Vertex status.
FourVector position
Position in time-space.