| 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" |
| 14 |
#include "HepMC3/Data/GenVertexData.h" |
| 15 |
#include "HepMC3/FourVector.h" |
| 16 |
#include "HepMC3/Errors.h" |
| 17 |
|
| 18 |
namespace HepMC3 { |
| 19 |
|
| 20 |
|
| 21 |
using namespace std; |
| 22 |
|
| 23 |
class Attribute; |
| 24 |
class GenEvent; |
| 25 |
|
| 26 |
/// Stores vertex-related information |
| 27 |
class GenVertex : public std::enable_shared_from_this<GenVertex> { |
| 28 |
|
| 29 |
friend class GenEvent; |
| 30 |
|
| 31 |
public: |
| 32 |
|
| 33 |
/// @name Constructors |
| 34 |
//@{ |
| 35 |
|
| 36 |
/// Default constructor |
| 37 |
GenVertex( const FourVector& position = FourVector::ZERO_VECTOR() ); |
| 38 |
|
| 39 |
/// Constructor based on vertex data |
| 40 |
GenVertex( const GenVertexData& data ); |
| 41 |
|
| 42 |
//@} |
| 43 |
|
| 44 |
public: |
| 45 |
|
| 46 |
/// @name Accessors |
| 47 |
//@{ |
| 48 |
|
| 49 |
/// Get parent event |
| 50 |
GenEvent* parent_event() { return m_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 |
|
| 141 |
private: |
| 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" |
| 160 |
namespace HepMC3 { |
| 161 |
/// @brief Get attribute of type T |
| 162 |
template<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 |