HepMC event record
GenVertex.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2015 The HepMC collaboration (see AUTHORS for details)
5 //
6 /**
7  * @file GenVertex.cc
8  * @brief Implementation of \b class GenVertex
9  *
10  */
11 #include "HepMC/GenVertex.h"
12 #include "HepMC/GenParticle.h"
13 #include "HepMC/GenEvent.h"
14 #include "HepMC/Search/FindParticles.h"
15 #include "HepMC/Setup.h"
16 #include "HepMC/Attribute.h"
17 #include <algorithm> // std::remove
18 
19 namespace HepMC {
20 
21 
23 m_event(NULL),
24 m_id(0) {
25  m_data.status = 0;
26  m_data.position = pos;
27 }
28 
30 m_event(NULL),
31 m_id(0),
32 m_data(dat) {
33 }
34 
35 
37  if(!p) return;
38 
39  // Avoid duplicates
40  FOREACH( const GenParticlePtr &pp, particles_in() ) {
41  if( pp == p ) return;
42  }
43 
44  m_particles_in.push_back(p);
45 
46  if( p->end_vertex() ) p->end_vertex()->remove_particle_in(p);
47 
48  p->m_end_vertex = m_this.lock();
49 
51 }
52 
53 
55  if(!p) return;
56 
57  // Avoid duplicates
58  FOREACH( const GenParticlePtr &pp, particles_out() ) {
59  if( pp == p ) return;
60  }
61 
62  m_particles_out.push_back(p);
63 
64  if( p->production_vertex() ) p->production_vertex()->remove_particle_out(p);
65 
66  p->m_production_vertex = m_this.lock();
67 
69 }
70 
71 
73  p->m_end_vertex.reset();
74  m_particles_in.erase( std::remove( m_particles_in.begin(), m_particles_in.end(), p), m_particles_in.end());
75 }
76 
77 
79  p->m_production_vertex.reset();
80  m_particles_out.erase( std::remove( m_particles_out.begin(), m_particles_out.end(), p), m_particles_out.end());
81 }
82 
83 
84 const vector<GenParticlePtr> GenVertex::particles(Relationship range) const {
85  return findParticles(GenVertexPtr(const_cast<GenVertex*>(this)), range);
86 }
87 
88 
90 
91  if( has_set_position() ) return m_data.position;
92 
93  // No position information - search ancestors
94  FOREACH( const GenParticlePtr &p, particles_in() ) {
95  const GenVertexPtr &v = p->production_vertex();
96  if(v) return v->position();
97  }
98 
99  if( parent_event() ) return parent_event()->event_pos();
100 
101  return FourVector::ZERO_VECTOR();
102 }
103 
104 void GenVertex::set_position(const FourVector& new_pos) {
105  m_data.position = new_pos;
106 }
107 
108 bool GenVertex::add_attribute(std::string name, shared_ptr<Attribute> att) {
109  if ( !parent_event() ) return false;
110  parent_event()->add_attribute(name, att, id());
111  return true;
112 }
113 
114 void GenVertex::remove_attribute(std::string name) {
115  if ( parent_event() ) parent_event()->remove_attribute(name, id());
116 }
117 
118 string GenVertex::attribute_as_string(string name) const {
119  return parent_event() ? parent_event()->attribute_as_string(name, id()) : string();
120 }
121 
122 vector<string> GenVertex::attribute_names() const {
123  if ( parent_event() ) return parent_event()->attribute_names(id());
124 
125  return vector<string>();
126 }
127 
128 } // namespace HepMC
const vector< GenParticlePtr > & particles_out() const
Get list of outgoing particles.
GenVertexData m_data
Vertex data.
string attribute_as_string(const string &name, int id=0) const
Get attribute of any type as string.
Definition: GenEvent.cc:555
void remove_attribute(string name)
Remove attribute.
Definition: GenVertex.cc:114
vector< string > attribute_names() const
Get list of names of attributes assigned to this particle.
Definition: GenVertex.cc:122
void remove_attribute(const string &name, int id=0)
Remove attribute.
Definition: GenEvent.cc:398
static const FourVector & ZERO_VECTOR()
Static null FourVector = (0,0,0,0)
string attribute_as_string(string name) const
Get attribute of any type as string.
Definition: GenVertex.cc:118
GenVertex(const FourVector &position=FourVector::ZERO_VECTOR())
Default constructor.
Definition: GenVertex.cc:22
bool has_set_position() const
Check if position of this vertex is set.
void remove_particle_out(GenParticlePtr p)
Remove outgoing particle.
Definition: GenVertex.cc:78
vector< GenParticlePtr > m_particles_in
Incoming particle list.
weak_ptr< GenVertex > m_this
Pointer to shared pointer managing this vertex.
const FourVector & position() const
Get vertex position.
Definition: GenVertex.cc:89
Stores serializable vertex information.
void add_particle_in(GenParticlePtr p)
Add incoming particle.
Definition: GenVertex.cc:36
const vector< GenParticlePtr > particles(Relationship range) const
Definition: GenVertex.cc:84
std::vector< string > attribute_names(int id=0) const
Get list of attribute names.
Definition: GenEvent.cc:408
vector< GenParticlePtr > m_particles_out
Outgoing particle list.
void add_attribute(const string &name, const shared_ptr< Attribute > &att, int id=0)
Add event attribute to event.
void add_particle(GenParticlePtr p)
Add particle.
Definition: GenEvent.cc:42
const vector< GenParticlePtr > & particles_in() const
Get list of incoming particles.
vector< GenParticlePtr > findParticles(const GenEvent &evt, FilterEvent filter_type, FilterList filter_list=FilterList())
Find from GenEvent.
FourVector position
Position in time-space.
void add_particle_out(GenParticlePtr p)
Add outgoing particle.
Definition: GenVertex.cc:54
const FourVector & event_pos() const
Vertex representing the overall event position.
Definition: GenEvent.cc:355
Definition of template class SmartPointer.
void remove_particle_in(GenParticlePtr p)
Remove incoming particle.
Definition: GenVertex.cc:72
bool add_attribute(string name, shared_ptr< Attribute > att)
Add event attribute to this vertex.
Definition: GenVertex.cc:108
void set_position(const FourVector &new_pos)
Set vertex position.
Definition: GenVertex.cc:104
SmartPointer< class GenVertex > GenVertexPtr
Smart pointer to GenVertex.
Relationship
List of methods of searching starting from a particle or vertex.