HepMC event record
GenParticle.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 GenParticle.cc
8  * @brief Implementation of \b class GenParticle
9  *
10  */
11 #include "HepMC/GenParticle.h"
12 #include "HepMC/GenVertex.h"
13 #include "HepMC/GenEvent.h"
14 #include "HepMC/Search/FindParticles.h"
15 #include "HepMC/Setup.h"
16 #include "HepMC/Attribute.h"
17 
18 namespace HepMC {
19 
20 
21 GenParticle::GenParticle( const FourVector &mom, int pidin, int stat):
22 m_event(NULL),
23 m_id(0) {
24  m_data.pid = pidin;
25  m_data.momentum = mom;
26  m_data.status = stat;
27  m_data.is_mass_set = false;
28  m_data.mass = 0.0;
29 }
30 
32 m_event(NULL),
33 m_id(0),
34 m_data(dat) {
35 }
36 
38  if(m_data.is_mass_set) return m_data.mass;
39  else return m_data.momentum.m();
40 }
41 
42 void GenParticle::set_pid(int pidin) {
43  m_data.pid = pidin;
44 }
45 
46 void GenParticle::set_status(int stat) {
47  m_data.status = stat;
48 }
49 
51  m_data.momentum = mom;
52 }
53 
55  m_data.mass = m;
56  m_data.is_mass_set = true;
57 }
58 
60  m_data.mass = 0.;
61  m_data.is_mass_set = false;
62 }
63 
65  return m_production_vertex.lock();
66 }
67 
69  return m_production_vertex.lock();
70 }
71 
73  return m_end_vertex.lock();
74 }
75 
77  return m_end_vertex.lock();
78 }
79 
80 vector<GenParticlePtr> GenParticle::parents() const {
81  return production_vertex() ? production_vertex()->particles_in() : vector<GenParticlePtr>();
82 }
83 
84 vector<GenParticlePtr> GenParticle::children() const {
85  return end_vertex() ? end_vertex()->particles_out() : vector<GenParticlePtr>();
86 }
87 
88 vector<GenParticlePtr> GenParticle::ancestors() const {
89  return production_vertex() ? findParticles(production_vertex(), ANCESTORS) : vector<GenParticlePtr>();
90 }
91 
92 vector<GenParticlePtr> GenParticle::descendants() const {
93  return end_vertex() ? findParticles(end_vertex(), DESCENDANTS) : vector<GenParticlePtr>();
94 }
95 
96 bool GenParticle::add_attribute(std::string name, shared_ptr<Attribute> att) {
97  if ( !parent_event() ) return false;
98  parent_event()->add_attribute(name, att, id());
99  return true;
100 }
101 
102 vector<string> GenParticle::attribute_names() const {
103  if ( parent_event() ) return parent_event()->attribute_names(id());
104 
105  return vector<string>();
106 }
107 
108 void GenParticle::remove_attribute(std::string name) {
109  if ( parent_event() ) parent_event()->remove_attribute(name, id());
110 }
111 
112 string GenParticle::attribute_as_string(string name) const {
113  return parent_event() ? parent_event()->attribute_as_string(name, id()) : string();
114 }
115 
116 } // namespace HepMC
vector< GenParticlePtr > parents() const
Convenience access to immediate incoming particles via production vertex.
Definition: GenParticle.cc:80
Stores serializable particle information.
bool add_attribute(string name, shared_ptr< Attribute > att)
Add an attribute to this particle.
Definition: GenParticle.cc:96
void set_momentum(const FourVector &momentum)
Set momentum.
Definition: GenParticle.cc:50
string attribute_as_string(const string &name, int id=0) const
Get attribute of any type as string.
Definition: GenEvent.cc:555
vector< GenParticlePtr > descendants() const
Convenience access to all outgoing particles via end vertex.
Definition: GenParticle.cc:92
GenEvent * parent_event() const
Get parent event.
const GenVertexPtr production_vertex() const
Get production vertex.
Definition: GenParticle.cc:68
GenParticleData m_data
Particle data.
double generated_mass() const
Get generated mass.
Definition: GenParticle.cc:37
void remove_attribute(string name)
Remove attribute.
Definition: GenParticle.cc:108
void remove_attribute(const string &name, int id=0)
Remove attribute.
Definition: GenEvent.cc:398
void unset_generated_mass()
Declare that generated mass is not set.
Definition: GenParticle.cc:59
string attribute_as_string(string name) const
Get attribute of any type as string.
Definition: GenParticle.cc:112
vector< string > attribute_names() const
Get list of names of attributes assigned to this particle.
Definition: GenParticle.cc:102
void set_status(int status)
Set status code.
Definition: GenParticle.cc:46
vector< GenParticlePtr > children() const
Convenience access to immediate outgoing particles via end vertex.
Definition: GenParticle.cc:84
const GenVertexPtr end_vertex() const
Get end vertex.
Definition: GenParticle.cc:76
std::vector< string > attribute_names(int id=0) const
Get list of attribute names.
Definition: GenEvent.cc:408
void add_attribute(const string &name, const shared_ptr< Attribute > &att, int id=0)
Add event attribute to event.
double m() const
Invariant mass. Returns -sqrt(-m) if e^2 - P^2 is negative.
vector< GenParticlePtr > findParticles(const GenEvent &evt, FilterEvent filter_type, FilterList filter_list=FilterList())
Find from GenEvent.
void set_pid(int pid)
Set PDG ID.
Definition: GenParticle.cc:42
weak_ptr< GenVertex > m_production_vertex
Production vertex.
GenParticle(const FourVector &momentum=FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Default constructor.
Definition: GenParticle.cc:21
bool is_mass_set
Check if generated mass is set.
Definition of template class SmartPointer.
weak_ptr< GenVertex > m_end_vertex
End vertex.
vector< GenParticlePtr > ancestors() const
Convenience access to all incoming particles via production vertex.
Definition: GenParticle.cc:88
void set_generated_mass(double m)
Set generated mass.
Definition: GenParticle.cc:54