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-2020 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  /// Get list of incoming particles
83  const std::vector<GenParticlePtr>& particles_in() { return m_particles_in; }
84  /// Get list of incoming particles (for const access)
85  const std::vector<ConstGenParticlePtr>& particles_in() const;
86  /// Get list of outgoing particles
87  const std::vector<GenParticlePtr>& particles_out() { return m_particles_out; }
88  /// Get list of outgoing particles (for const access)
89  const std::vector<ConstGenParticlePtr>& particles_out() const;
90 
91  /// @brief Get vertex position
92  ///
93  /// Returns the position of this vertex. If a position is not set on _this_ vertex,
94  /// the production vertices of ancestors are searched to find the inherited position.
95  /// FourVector(0,0,0,0) is returned if no position information is found.
96  ///
97  const FourVector& position() const;
98  /// @brief Check if position of this vertex is set
99  bool has_set_position() const { return !(m_data.position.is_zero()); }
100 
101  /// Set vertex position
102  void set_position(const FourVector& new_pos); //!<
103 
104  /// @brief Add event attribute to this vertex
105  ///
106  /// This will overwrite existing attribute if an attribute with
107  /// the same name is present. The attribute will be stored in the
108  /// parent_event(). @return false if there is no parent_event();
109  bool add_attribute(const std::string& name, std::shared_ptr<Attribute> att);
110 
111  /// @brief Get list of names of attributes assigned to this particle
112  std::vector<std::string> attribute_names() const;
113 
114  /// @brief Remove attribute
115  void remove_attribute(const std::string& name);
116 
117  /// @brief Get attribute of type T
118  template<class T>
119  std::shared_ptr<T> attribute(const std::string& name) const;
120 
121  /// @brief Get attribute of any type as string
122  std::string attribute_as_string(const std::string& name) const;
123 
124  /// @name Deprecated functionality
125  //@{
126 
127 
128  /// Add incoming particle by raw pointer
129  /// @deprecated Use GenVertex::add_particle_in( const GenParticlePtr &p ) instead
130  void add_particle_in ( GenParticle *p ) { add_particle_in( GenParticlePtr(p) ); }
131 
132  /// Add outgoing particle by raw pointer
133  /// @deprecated Use GenVertex::add_particle_out( const GenParticlePtr &p ) instead
134  void add_particle_out( GenParticle *p ) { add_particle_out( GenParticlePtr(p) ); }
135 
136 
137  //@}
138 
139 
140 private:
141 
142  /// @name Fields
143  //@{
144  GenEvent *m_event; //!< Parent event
145  int m_id; //!< Vertex id
146  GenVertexData m_data; //!< Vertex data
147 
148  std::vector<GenParticlePtr> m_particles_in; //!< Incoming particle list
149 
150  std::vector<GenParticlePtr> m_particles_out; //!< Outgoing particle list
151  //@}
152 
153 };
154 
155 
156 } // namespace HepMC3
157 
158 #include "HepMC3/GenEvent.h"
159 namespace HepMC3 {
160 /// @brief Get attribute of type T
161 template<class T> std::shared_ptr<T> GenVertex::attribute(const std::string& name) const {
162  return parent_event()?
163  parent_event()->attribute<T>(name, id()): std::shared_ptr<T>();
164 }
165 }
166 
167 #endif
Definition of class GenVertexData.
void add_particle_in(GenParticle *p)
Definition: GenVertex.h:130
Stores vertex-related information.
Definition: GenVertex.h:26
static const FourVector & ZERO_VECTOR()
Static null FourVector = (0,0,0,0)
Definition: FourVector.h:292
bool has_set_position() const
Check if position of this vertex is set.
Definition: GenVertex.h:99
int status() const
Get vertex status code.
Definition: GenVertex.h:66
GenEvent * parent_event()
Get parent event.
Definition: GenVertex.h:49
Stores particle-related information.
Definition: GenParticle.h:31
std::vector< GenParticlePtr > m_particles_out
Outgoing particle list.
Definition: GenVertex.h:150
const std::vector< GenParticlePtr > & particles_in()
Get list of incoming particles.
Definition: GenVertex.h:83
int m_id
Vertex id.
Definition: GenVertex.h:145
GenVertexData m_data
Vertex data.
Definition: GenVertex.h:146
Stores event-related information.
Definition: GenEvent.h:41
Generic 4-vector.
Definition: FourVector.h:35
Stores serializable vertex information.
Definition: GenVertexData.h:22
GenEvent * m_event
Parent event.
Definition: GenVertex.h:144
const std::vector< GenParticlePtr > & particles_out()
Get list of outgoing particles.
Definition: GenVertex.h:87
int id() const
Definition: GenVertex.h:60
void add_particle_out(GenParticle *p)
Definition: GenVertex.h:134
void set_status(int stat)
Set vertex status code.
Definition: GenVertex.h:68
Definition of class GenEvent.
const GenEvent * parent_event() const
Get parent event.
Definition: GenVertex.h:52
Annotation for function names.
Definition: attr.h:36
bool in_event() const
Check if this vertex belongs to an event.
Definition: GenVertex.h:55
std::vector< GenParticlePtr > m_particles_in
Incoming particle list.
Definition: GenVertex.h:148
const GenVertexData & data() const
Get vertex data.
Definition: GenVertex.h:71
Definition of class FourVector.
std::shared_ptr< T > attribute(const std::string &name) const
Get attribute of type T.
Definition: GenVertex.h:161