Fork me on GitHub

source: git/external/HepMC3/GenVertex.cc@ 224c929

Last change on this file since 224c929 was 95a917c, checked in by Pavel Demin <pavel.demin@…>, 3 years ago

add HepMC3 library

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[95a917c]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
21GenVertex::GenVertex( const FourVector& pos):
22 m_event(nullptr),
23 m_id(0) {
24 m_data.status = 0;
25 m_data.position = pos;
26}
27
28GenVertex::GenVertex( const GenVertexData &dat):
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
47 if(m_event) m_event->add_particle(p);
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
63 if(m_event) m_event->add_particle(p);
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 std::vector<ConstGenParticlePtr>& GenVertex::particles_in()const {
88 return *(reinterpret_cast<const std::vector<ConstGenParticlePtr>*>(&m_particles_in));
89}
90
91const std::vector<ConstGenParticlePtr>& GenVertex::particles_out()const {
92 return *(reinterpret_cast<const std::vector<ConstGenParticlePtr>*>(&m_particles_out));
93}
94
95const FourVector& GenVertex::position() const {
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 std::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 }
114 return FourVector::ZERO_VECTOR();
115}
116
117void GenVertex::set_position(const FourVector& new_pos) {
118 m_data.position = new_pos;
119}
120
121bool GenVertex::add_attribute(const std::string& name, std::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
131std::string GenVertex::attribute_as_string(const std::string& name) const {
132 return parent_event() ? parent_event()->attribute_as_string(name, id()) : std::string();
133}
134
135std::vector<std::string> GenVertex::attribute_names() const {
136 if ( parent_event() ) return parent_event()->attribute_names(id());
137
138 return std::vector<std::string>();
139}
140
141} // namespace HepMC3
Note: See TracBrowser for help on using the repository browser.