1 | // -*- C++ -*-
|
---|
2 | //
|
---|
3 | // This file is part of HepMC
|
---|
4 | // Copyright (C) 2014-2020 The HepMC collaboration (see AUTHORS for details)
|
---|
5 | //
|
---|
6 | #ifndef HEPMC3_GENPARTICLE_H
|
---|
7 | #define HEPMC3_GENPARTICLE_H
|
---|
8 | /**
|
---|
9 | * @file GenParticle.h
|
---|
10 | * @brief Definition of \b class GenParticle
|
---|
11 | *
|
---|
12 | * @class HepMC3::GenParticle
|
---|
13 | * @brief Stores particle-related information
|
---|
14 | *
|
---|
15 | */
|
---|
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 | namespace HepMC3 {
|
---|
24 |
|
---|
25 | /** Deprecated */
|
---|
26 | using namespace std;
|
---|
27 |
|
---|
28 | class GenEvent;
|
---|
29 | class Attribute;
|
---|
30 |
|
---|
31 | class GenParticle : public std::enable_shared_from_this<GenParticle> {
|
---|
32 |
|
---|
33 | friend class GenVertex;
|
---|
34 | friend class GenEvent;
|
---|
35 |
|
---|
36 | //
|
---|
37 | // Constructors
|
---|
38 | //
|
---|
39 | public:
|
---|
40 | /** @brief Default constructor */
|
---|
41 | GenParticle( const FourVector &momentum = FourVector::ZERO_VECTOR(), int pid = 0, int status = 0 );
|
---|
42 |
|
---|
43 | /** @brief Constructor based on particle data */
|
---|
44 | GenParticle( const GenParticleData &data );
|
---|
45 |
|
---|
46 | //
|
---|
47 | // Functions
|
---|
48 | //
|
---|
49 | public:
|
---|
50 | /** @brief Check if this particle belongs to an event */
|
---|
51 | bool in_event() const { return (bool)(m_event); }
|
---|
52 |
|
---|
53 | //
|
---|
54 | // Accessors
|
---|
55 | //
|
---|
56 | public:
|
---|
57 |
|
---|
58 | GenEvent* parent_event() { return m_event; } //!< Get parent event
|
---|
59 | const GenEvent* parent_event() const { return m_event; } //!< Get parent event
|
---|
60 | int id() const { return m_id; } //!< Get particle id
|
---|
61 | const GenParticleData& data() const { return m_data; } //!< Get particle data
|
---|
62 |
|
---|
63 |
|
---|
64 | ConstGenVertexPtr production_vertex() const; //!< Get production vertex (const version)
|
---|
65 | ConstGenVertexPtr end_vertex() const; //!< Get end vertex (const version)
|
---|
66 |
|
---|
67 | GenVertexPtr production_vertex(); //!< Get production vertex
|
---|
68 | GenVertexPtr end_vertex(); //!< Get end vertex
|
---|
69 |
|
---|
70 | /// @brief Convenience access to immediate incoming particles via production vertex
|
---|
71 | /// @note Less efficient than via the vertex since return must be by value (in case there is no vertex)
|
---|
72 | std::vector<GenParticlePtr> parents();
|
---|
73 |
|
---|
74 | /// @brief Convenience access to immediate incoming particles via production vertex (const version)
|
---|
75 | /// @note Less efficient than via the vertex since return must be by value (in case there is no vertex)
|
---|
76 | std::vector<ConstGenParticlePtr> parents() const;
|
---|
77 |
|
---|
78 | /// @brief Convenience access to immediate outgoing particles via end vertex
|
---|
79 | /// @note Less efficient than via the vertex since return must be by value (in case there is no vertex)
|
---|
80 | std::vector<GenParticlePtr> children();
|
---|
81 |
|
---|
82 | /// @brief Convenience access to immediate outgoing particles via end vertex
|
---|
83 | /// @note Less efficient than via the vertex since return must be by value (in case there is no vertex)
|
---|
84 | std::vector<ConstGenParticlePtr> children() const;
|
---|
85 |
|
---|
86 | int pid() const { return m_data.pid; } //!< Get PDG ID
|
---|
87 | int abs_pid() const { return abs(pid()); } //!< Get absolute value of PDG ID
|
---|
88 | int status() const { return m_data.status; } //!< Get status code
|
---|
89 | const FourVector& momentum() const { return m_data.momentum; } //!< Get momentum
|
---|
90 | bool is_generated_mass_set() const { return m_data.is_mass_set; } //!< Check if generated mass is set
|
---|
91 |
|
---|
92 | /// @brief Get generated mass
|
---|
93 | ///
|
---|
94 | /// This function will return mass as set by a generator/tool.
|
---|
95 | /// If not set, it will return momentum().m()
|
---|
96 | double generated_mass() const;
|
---|
97 |
|
---|
98 |
|
---|
99 | void set_pid(int pid); //!< Set PDG ID
|
---|
100 | void set_status(int status); //!< Set status code
|
---|
101 | void set_momentum(const FourVector& momentum); //!< Set momentum
|
---|
102 | void set_generated_mass(double m); //!< Set generated mass
|
---|
103 | void unset_generated_mass(); //!< Declare that generated mass is not set
|
---|
104 |
|
---|
105 | /** @brief Add an attribute to this particle
|
---|
106 | *
|
---|
107 | * This will overwrite existing attribute if an attribute with
|
---|
108 | * the same name is present. The attribute will be stored in the
|
---|
109 | * parent_event(). @return false if there is no parent_event();
|
---|
110 | */
|
---|
111 | bool add_attribute(const std::string& name, std::shared_ptr<Attribute> att);
|
---|
112 |
|
---|
113 | /// @brief Get list of names of attributes assigned to this particle
|
---|
114 | std::vector<std::string> attribute_names() const;
|
---|
115 |
|
---|
116 | /// @brief Remove attribute
|
---|
117 | void remove_attribute(const std::string& name);
|
---|
118 |
|
---|
119 | /// @brief Get attribute of type T
|
---|
120 | template<class T>
|
---|
121 | std::shared_ptr<T> attribute(const std::string& name) const;
|
---|
122 |
|
---|
123 | /// @brief Get attribute of any type as string
|
---|
124 | std::string attribute_as_string(const std::string& name) const;
|
---|
125 |
|
---|
126 |
|
---|
127 | /// @name Deprecated functionality
|
---|
128 | //@{
|
---|
129 |
|
---|
130 | /// @brief Get PDG ID
|
---|
131 | /// @deprecated Use pid() instead
|
---|
132 | int pdg_id() const { return pid(); }
|
---|
133 |
|
---|
134 | /// @brief Set PDG ID
|
---|
135 | /// @deprecated Use set_pid() instead
|
---|
136 | void set_pdg_id(const int& pidin) { set_pid(pidin); }
|
---|
137 |
|
---|
138 |
|
---|
139 | //@}
|
---|
140 | //
|
---|
141 | // Fields
|
---|
142 | //
|
---|
143 | private:
|
---|
144 | GenEvent *m_event; //!< Parent event
|
---|
145 | int m_id; //!< Index
|
---|
146 | GenParticleData m_data; //!< Particle data
|
---|
147 |
|
---|
148 | std::weak_ptr<GenVertex> m_production_vertex; //!< Production vertex
|
---|
149 | std::weak_ptr<GenVertex> m_end_vertex; //!< End vertex
|
---|
150 | // weak_ptr<GenParticle> m_this; //!< Pointer to shared pointer managing this particle
|
---|
151 | };
|
---|
152 |
|
---|
153 | } // namespace HepMC3
|
---|
154 |
|
---|
155 | #include "HepMC3/GenEvent.h"
|
---|
156 | namespace HepMC3 {
|
---|
157 | /// @brief Get attribute of type T
|
---|
158 | template<class T> std::shared_ptr<T> GenParticle::attribute(const std::string& name) const {
|
---|
159 | return parent_event()?
|
---|
160 | parent_event()->attribute<T>(name, id()): std::shared_ptr<T>();
|
---|
161 | }
|
---|
162 | }
|
---|
163 | #endif
|
---|