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