MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
GenParticle.h
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_GENPARTICLE_H
7#define HEPMC3_GENPARTICLE_H
16#include <string>
17#include "HepMC3/Data/GenParticleData.h"
18#include "HepMC3/FourVector.h"
19
20#include "HepMC3/GenParticle_fwd.h"
21#include "HepMC3/GenVertex_fwd.h"
22
23#ifdef HEPMC3_PROTOBUFIO
24namespace HepMC3_pb {
25class GenEventData_GenParticleData;
26}
27#endif
28
29namespace HepMC3 {
30
31class GenEvent;
32class Attribute;
33
34class GenParticle : public std::enable_shared_from_this<GenParticle> {
35
36 friend class GenVertex;
37 friend class GenEvent;
38
39//
40// Constructors
41//
42public:
43
45 GenParticle( const FourVector &momentum = FourVector::ZERO_VECTOR(), int pid = 0, int status = 0 );
46
49
50#ifdef HEPMC3_PROTOBUFIO
52 GenParticle( HepMC3_pb::GenEventData_GenParticleData const &data );
53#endif
54
55//
56// Functions
57//
58public:
60 bool in_event() const { return (bool) (m_event); }
61
63 GenEvent* parent_event() { return m_event; }
65 const GenEvent* parent_event() const { return m_event; }
66
68 int id() const { return m_id; }
69
70 const GenParticleData& data() const { return m_data; }
71
72 ConstGenVertexPtr production_vertex() const;
73 ConstGenVertexPtr end_vertex() const;
74
75 GenVertexPtr production_vertex();
76 GenVertexPtr end_vertex();
77
80 std::vector<GenParticlePtr> parents();
81
84 std::vector<ConstGenParticlePtr> parents() const;
85
88 std::vector<GenParticlePtr> children();
89
92 std::vector<ConstGenParticlePtr> children() const;
93
94 int pid() const { return m_data.pid; }
95 int abs_pid() const { return std::abs(pid()); }
96 int status() const { return m_data.status; }
97 const FourVector& momentum() const { return m_data.momentum; }
98 bool is_generated_mass_set() const { return m_data.is_mass_set; }
99
104 double generated_mass() const;
105
106
107 void set_pid(int pid);
108 void set_status(int status);
109 void set_momentum(const FourVector& momentum);
110 void set_generated_mass(double m);
111 void unset_generated_mass();
112
118 bool add_attribute(const std::string& name, std::shared_ptr<Attribute> att);
119
121 std::vector<std::string> attribute_names() const;
122
124 void remove_attribute(const std::string& name);
125
127 template<class T>
128 std::shared_ptr<T> attribute(const std::string& name) const;
129
131 std::string attribute_as_string(const std::string& name) const;
132
133
136
139 int pdg_id() const { return pid(); }
140
143 void set_pdg_id(const int& pidin) { set_pid(pidin); }
144
146//
147// Fields
148//
149private:
150 GenEvent *m_event;
151 int m_id;
152 GenParticleData m_data;
153
154 std::weak_ptr<GenVertex> m_production_vertex;
155 std::weak_ptr<GenVertex> m_end_vertex;
156};
157
158} // namespace HepMC3
159
160
161
162#include "HepMC3/GenEvent.h"
163namespace HepMC3 {
165template<class T> std::shared_ptr<T> GenParticle::attribute(const std::string& name) const {
166 return parent_event()?
167 parent_event()->attribute<T>(name, id()): std::shared_ptr<T>();
168}
169}
170#endif
Base attribute class.
Definition Attribute.h:44
Generic 4-vector.
Definition FourVector.h:36
static const FourVector & ZERO_VECTOR()
Static null FourVector = (0,0,0,0)
Definition FourVector.h:306
Stores event-related information.
Definition GenEvent.h:47
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
Definition GenEvent.h:418
bool is_generated_mass_set() const
Check if generated mass is set.
Definition GenParticle.h:98
std::vector< std::string > attribute_names() const
Get list of names of attributes assigned to this particle.
bool add_attribute(const std::string &name, std::shared_ptr< Attribute > att)
Add an attribute to this particle.
int id() const
Get the particle ID number (not PDG ID)
Definition GenParticle.h:68
void set_momentum(const FourVector &momentum)
Set momentum.
bool in_event() const
Check if this particle belongs to an event.
Definition GenParticle.h:60
const FourVector & momentum() const
Get momentum.
Definition GenParticle.h:97
void set_pdg_id(const int &pidin)
Set PDG ID.
std::vector< GenParticlePtr > parents()
Convenience access to immediate incoming particles via production vertex.
const GenParticleData & data() const
Get particle data.
Definition GenParticle.h:70
int pdg_id() const
Get PDG ID.
std::shared_ptr< T > attribute(const std::string &name) const
Get attribute of type T.
void set_pid(int pid)
Set PDG ID.
void remove_attribute(const std::string &name)
Remove attribute.
int status() const
Get status code.
Definition GenParticle.h:96
std::vector< GenParticlePtr > children()
Convenience access to immediate outgoing particles via end vertex.
ConstGenVertexPtr end_vertex() const
Get end vertex (const version)
void set_generated_mass(double m)
Set generated mass.
std::string attribute_as_string(const std::string &name) const
Get attribute of any type as string.
double generated_mass() const
Get generated mass.
GenParticle(const FourVector &momentum=FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Default constructor.
ConstGenVertexPtr production_vertex() const
Get production vertex (const version)
void unset_generated_mass()
Declare that generated mass is not set.
GenEvent * parent_event()
Get the parent event.
Definition GenParticle.h:63
const GenEvent * parent_event() const
Get the parent event (const)
Definition GenParticle.h:65
void set_status(int status)
Set status code.
int abs_pid() const
Get absolute value of PDG ID.
Definition GenParticle.h:95
int pid() const
Get PDG ID.
Definition GenParticle.h:94
Stores serializable particle information.