HepMC3 event record library
GenVertex.cc
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/**
7 * @file GenVertex.cc
8 * @brief Implementation of \b class GenVertex
9 *
10 */
11#include "HepMC3/GenVertex.h"
12#include "HepMC3/GenParticle.h"
13#include "HepMC3/GenEvent.h"
14#include "HepMC3/Setup.h"
15#include "HepMC3/Attribute.h"
16#include <algorithm> // std::remove
17
18namespace HepMC3 {
19
20
22 m_event(nullptr),
23 m_id(0) {
24 m_data.status = 0;
25 m_data.position = pos;
26}
27
29 m_event(nullptr),
30 m_id(0),
31 m_data(dat) {
32}
33
34
35void GenVertex::add_particle_in( GenParticlePtr p ) {
36 if(!p) return;
37
38 // Avoid duplicates
39 if (std::find(particles_in().begin(),particles_in().end(),p)!=particles_in().end()) return;
40
41 m_particles_in.push_back(p);
42
43 if( p->end_vertex() ) p->end_vertex()->remove_particle_in(p);
44
45 p->m_end_vertex = shared_from_this();
46
48}
49
50
51void GenVertex::add_particle_out(GenParticlePtr p ) {
52 if(!p) return;
53
54 // Avoid duplicates
55 if (std::find(particles_out().begin(),particles_out().end(),p)!=particles_out().end()) return;
56
57 m_particles_out.push_back(p);
58
59 if( p->production_vertex() ) p->production_vertex()->remove_particle_out(p);
60
61 p->m_production_vertex = shared_from_this();
62
64}
65
66void GenVertex::remove_particle_in( GenParticlePtr p ) {
67 if(!p) return;
68 if (std::find(m_particles_in.begin(),m_particles_in.end(),p)==m_particles_in.end()) return;
69 p->m_end_vertex.reset();
70 m_particles_in.erase( std::remove( m_particles_in.begin(), m_particles_in.end(), p), m_particles_in.end());
71}
72
73
74void GenVertex::remove_particle_out( GenParticlePtr p ) {
75 if(!p) return;
76 if (std::find(m_particles_out.begin(),m_particles_out.end(),p)==m_particles_out.end()) return;
77 p->m_production_vertex.reset();
78 m_particles_out.erase( std::remove( m_particles_out.begin(), m_particles_out.end(), p), m_particles_out.end());
79}
80
81void GenVertex::set_id(int id) {
82 m_id = id;
83 return;
84}
85
86
87const vector<ConstGenParticlePtr>& GenVertex::particles_in()const {
88 return *(reinterpret_cast<const vector<ConstGenParticlePtr>*>(&m_particles_in));
89}
90
91const vector<ConstGenParticlePtr>& GenVertex::particles_out()const {
92 return *(reinterpret_cast<const vector<ConstGenParticlePtr>*>(&m_particles_out));
93}
94
96
97 if( has_set_position() ) return m_data.position;
98
99 // No position information - look at event and/or search ancestors
100 if( parent_event() )
101 {
102 shared_ptr<IntAttribute> cycles=parent_event()->attribute<IntAttribute>("cycles");
103 //This could be a recussive call. Try to prevent it.
104 if (!cycles||cycles->value()==0)
105 {
106
107 for(ConstGenParticlePtr p: m_particles_in ) {
108 ConstGenVertexPtr v = p->production_vertex();
109 if(v) return v->position();
110 }
111 }
112 return parent_event()->event_pos();
113 }
115}
116
118 m_data.position = new_pos;
119}
120
121bool GenVertex::add_attribute(const std::string& name, shared_ptr<Attribute> att) {
122 if ( !parent_event() ) return false;
123 parent_event()->add_attribute(name, att, id());
124 return true;
125}
126
127void GenVertex::remove_attribute(const std::string& name) {
128 if ( parent_event() ) parent_event()->remove_attribute(name, id());
129}
130
131string GenVertex::attribute_as_string(const std::string& name) const {
132 return parent_event() ? parent_event()->attribute_as_string(name, id()) : string();
133}
134
135vector<string> GenVertex::attribute_names() const {
136 if ( parent_event() ) return parent_event()->attribute_names(id());
137
138 return vector<string>();
139}
140
141} // namespace HepMC3
Definition of class Attribute, class IntAttribute and class StringAttribute.
Definition of class GenEvent.
Definition of class GenParticle.
Definition of class GenVertex.
Definition of class Setup.
Generic 4-vector.
Definition FourVector.h:35
static const FourVector & ZERO_VECTOR()
Static null FourVector = (0,0,0,0)
Definition FourVector.h:274
void remove_attribute(const string &name, const int &id=0)
Remove attribute.
Definition GenEvent.cc:623
void add_particle(GenParticlePtr p)
Add particle.
Definition GenEvent.cc:50
string attribute_as_string(const string &name, const int &id=0) const
Get attribute of any type as string.
Definition GenEvent.cc:800
void add_attribute(const string &name, const shared_ptr< Attribute > &att, const int &id=0)
Add event attribute to event.
Definition GenEvent.h:209
const FourVector & event_pos() const
Vertex representing the overall event position.
Definition GenEvent.cc:417
shared_ptr< T > attribute(const string &name, const int &id=0) const
Get attribute of type T.
Definition GenEvent.h:388
std::vector< string > attribute_names(const int &id=0) const
Get list of attribute names.
Definition GenEvent.cc:635
GenVertex(const FourVector &position=FourVector::ZERO_VECTOR())
Default constructor.
Definition GenVertex.cc:21
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
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 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
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
bool has_set_position() const
Check if position of this vertex is set.
Definition GenVertex.h:100
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
Attribute that holds an Integer implemented as an int.
Definition Attribute.h:158
HepMC3 main namespace.
Definition ReaderGZ.h:28
Stores serializable vertex information.
int status
Vertex status.
FourVector position
Position in time-space.