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