File: GenVertex.cc

package info (click to toggle)
hepmc3 3.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 14,116 kB
  • sloc: fortran: 66,849; cpp: 13,604; ansic: 1,374; xml: 109; sh: 72; makefile: 33
file content (141 lines) | stat: -rw-r--r-- 3,933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// -*- C++ -*-
//
// This file is part of HepMC
// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
//
/**
 *  @file GenVertex.cc
 *  @brief Implementation of \b class GenVertex
 *
 */
#include "HepMC3/GenVertex.h"
#include "HepMC3/GenParticle.h"
#include "HepMC3/GenEvent.h"
#include "HepMC3/Setup.h"
#include "HepMC3/Attribute.h"
#include <algorithm> // std::remove

namespace HepMC3 {


GenVertex::GenVertex( const FourVector& pos):
    m_event(nullptr),
    m_id(0) {
    m_data.status   = 0;
    m_data.position = pos;
}

GenVertex::GenVertex( const GenVertexData &dat):
    m_event(nullptr),
    m_id(0),
    m_data(dat) {
}


void GenVertex::add_particle_in( GenParticlePtr p ) {
    if(!p) return;

    // Avoid duplicates
    if (std::find(particles_in().begin(),particles_in().end(),p)!=particles_in().end()) return;

    m_particles_in.push_back(p);

    if( p->end_vertex() ) p->end_vertex()->remove_particle_in(p);

    p->m_end_vertex = shared_from_this();

    if(m_event) m_event->add_particle(p);
}


void GenVertex::add_particle_out(GenParticlePtr p ) {
    if(!p) return;

    // Avoid duplicates
    if (std::find(particles_out().begin(),particles_out().end(),p)!=particles_out().end()) return;

    m_particles_out.push_back(p);

    if( p->production_vertex() ) p->production_vertex()->remove_particle_out(p);

    p->m_production_vertex = shared_from_this();

    if(m_event) m_event->add_particle(p);
}

void GenVertex::remove_particle_in( GenParticlePtr p ) {
    if(!p) return;
    if (std::find(m_particles_in.begin(),m_particles_in.end(),p)==m_particles_in.end()) return;
    p->m_end_vertex.reset();
    m_particles_in.erase( std::remove( m_particles_in.begin(), m_particles_in.end(), p), m_particles_in.end());
}


void GenVertex::remove_particle_out( GenParticlePtr p ) {
    if(!p) return;
    if (std::find(m_particles_out.begin(),m_particles_out.end(),p)==m_particles_out.end()) return;
    p->m_production_vertex.reset();
    m_particles_out.erase( std::remove( m_particles_out.begin(), m_particles_out.end(), p), m_particles_out.end());
}

void GenVertex::set_id(int id) {
    m_id = id;
    return;
}


const vector<ConstGenParticlePtr>& GenVertex::particles_in()const {
    return *(reinterpret_cast<const vector<ConstGenParticlePtr>*>(&m_particles_in));
}

const vector<ConstGenParticlePtr>& GenVertex::particles_out()const {
    return *(reinterpret_cast<const vector<ConstGenParticlePtr>*>(&m_particles_out));
}

const FourVector& GenVertex::position() const {

    if( has_set_position() ) return m_data.position;

    // No position information - look at event and/or search ancestors
    if( parent_event() )
    {
        shared_ptr<IntAttribute> cycles=parent_event()->attribute<IntAttribute>("cycles");
        //This could be a recussive call.  Try to prevent it.
        if (!cycles||cycles->value()==0)
        {

            for(ConstGenParticlePtr p: m_particles_in ) {
                ConstGenVertexPtr v = p->production_vertex();
                if(v) return v->position();
            }
        }
        return parent_event()->event_pos();
    }
    return FourVector::ZERO_VECTOR();
}

void GenVertex::set_position(const FourVector& new_pos) {
    m_data.position = new_pos;
}

bool GenVertex::add_attribute(const std::string& name, shared_ptr<Attribute> att) {
    if ( !parent_event() ) return false;
    parent_event()->add_attribute(name, att, id());
    return true;
}

void GenVertex::remove_attribute(const std::string& name) {
    if ( parent_event() ) parent_event()->remove_attribute(name, id());
}

string GenVertex::attribute_as_string(const std::string& name) const {
    return parent_event() ? parent_event()->attribute_as_string(name, id()) : string();
}

vector<string> GenVertex::attribute_names() const {
    if ( parent_event() ) return parent_event()->attribute_names(id());

    return vector<string>();
}

} // namespace HepMC3