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