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