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 GenParticle.cc
|
---|
8 | * @brief Implementation of \b class GenParticle
|
---|
9 | *
|
---|
10 | */
|
---|
11 | #include "HepMC3/GenParticle.h"
|
---|
12 | #include "HepMC3/GenVertex.h"
|
---|
13 | #include "HepMC3/GenEvent.h"
|
---|
14 | #include "HepMC3/Setup.h"
|
---|
15 | #include "HepMC3/Attribute.h"
|
---|
16 |
|
---|
17 | namespace HepMC3 {
|
---|
18 |
|
---|
19 | GenParticle::GenParticle( const FourVector &mom, int pidin, int stat):
|
---|
20 | m_event(nullptr),
|
---|
21 | m_id(0) {
|
---|
22 | m_data.pid = pidin;
|
---|
23 | m_data.momentum = mom;
|
---|
24 | m_data.status = stat;
|
---|
25 | m_data.is_mass_set = false;
|
---|
26 | m_data.mass = 0.0;
|
---|
27 | }
|
---|
28 |
|
---|
29 | GenParticle::GenParticle( const GenParticleData &dat ):
|
---|
30 | m_event(nullptr),
|
---|
31 | m_id(0),
|
---|
32 | m_data(dat) {
|
---|
33 | }
|
---|
34 |
|
---|
35 | double GenParticle::generated_mass() const {
|
---|
36 | if(m_data.is_mass_set) return m_data.mass;
|
---|
37 | else return m_data.momentum.m();
|
---|
38 | }
|
---|
39 |
|
---|
40 | void GenParticle::set_pid(int pidin) {
|
---|
41 | m_data.pid = pidin;
|
---|
42 | }
|
---|
43 |
|
---|
44 | void GenParticle::set_status(int stat) {
|
---|
45 | m_data.status = stat;
|
---|
46 | }
|
---|
47 |
|
---|
48 | void GenParticle::set_momentum(const FourVector& mom) {
|
---|
49 | m_data.momentum = mom;
|
---|
50 | }
|
---|
51 |
|
---|
52 | void GenParticle::set_generated_mass(double m) {
|
---|
53 | m_data.mass = m;
|
---|
54 | m_data.is_mass_set = true;
|
---|
55 | }
|
---|
56 |
|
---|
57 | void GenParticle::unset_generated_mass() {
|
---|
58 | m_data.mass = 0.;
|
---|
59 | m_data.is_mass_set = false;
|
---|
60 | }
|
---|
61 |
|
---|
62 | GenVertexPtr GenParticle::production_vertex() {
|
---|
63 | return m_production_vertex.lock();
|
---|
64 | }
|
---|
65 |
|
---|
66 | ConstGenVertexPtr GenParticle::production_vertex() const {
|
---|
67 | return std::const_pointer_cast<const GenVertex>(m_production_vertex.lock());
|
---|
68 | }
|
---|
69 |
|
---|
70 | GenVertexPtr GenParticle::end_vertex() {
|
---|
71 | return m_end_vertex.lock();
|
---|
72 | }
|
---|
73 |
|
---|
74 | ConstGenVertexPtr GenParticle::end_vertex() const {
|
---|
75 | return std::const_pointer_cast<const GenVertex>(m_end_vertex.lock());
|
---|
76 | }
|
---|
77 |
|
---|
78 | std::vector<GenParticlePtr> GenParticle::parents() {
|
---|
79 | return (m_production_vertex.expired())? std::vector<GenParticlePtr>() : production_vertex()->particles_in();
|
---|
80 | }
|
---|
81 |
|
---|
82 | std::vector<ConstGenParticlePtr> GenParticle::parents() const {
|
---|
83 | return (m_production_vertex.expired()) ? std::vector<ConstGenParticlePtr>() : production_vertex()->particles_in();
|
---|
84 | }
|
---|
85 |
|
---|
86 | std::vector<GenParticlePtr> GenParticle::children() {
|
---|
87 | return (m_end_vertex.expired())? std::vector<GenParticlePtr>() : end_vertex()->particles_out();
|
---|
88 | }
|
---|
89 |
|
---|
90 | std::vector<ConstGenParticlePtr> GenParticle::children() const {
|
---|
91 | return (m_end_vertex.expired()) ? std::vector<ConstGenParticlePtr>() : end_vertex()->particles_out();
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool GenParticle::add_attribute(const std::string& name, std::shared_ptr<Attribute> att) {
|
---|
95 | if ( !parent_event() ) return false;
|
---|
96 | parent_event()->add_attribute(name, att, id());
|
---|
97 | return true;
|
---|
98 | }
|
---|
99 |
|
---|
100 | std::vector<std::string> GenParticle::attribute_names() const {
|
---|
101 | if ( parent_event() ) return parent_event()->attribute_names(id());
|
---|
102 |
|
---|
103 | return std::vector<std::string>();
|
---|
104 | }
|
---|
105 |
|
---|
106 | void GenParticle::remove_attribute(const std::string& name) {
|
---|
107 | if ( parent_event() ) parent_event()->remove_attribute(name, id());
|
---|
108 | }
|
---|
109 |
|
---|
110 | std::string GenParticle::attribute_as_string(const std::string& name) const {
|
---|
111 | return parent_event() ? parent_event()->attribute_as_string(name, id()) : std::string();
|
---|
112 | }
|
---|
113 |
|
---|
114 | } // namespace HepMC3
|
---|