Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:12

0001 // -*- C++ -*-
0002 //
0003 // This file is part of HepMC
0004 // Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
0005 //
0006 #ifndef HEPMC3_GENPARTICLE_H
0007 #define HEPMC3_GENPARTICLE_H
0008 /**
0009  *  @file GenParticle.h
0010  *  @brief Definition of \b class GenParticle
0011  *
0012  *  @class HepMC3::GenParticle
0013  *  @brief Stores particle-related information
0014  *
0015  */
0016 #include <string>
0017 #include "HepMC3/Data/GenParticleData.h"
0018 #include "HepMC3/FourVector.h"
0019 
0020 #include "HepMC3/GenParticle_fwd.h"
0021 #include "HepMC3/GenVertex_fwd.h"
0022 
0023 #ifdef HEPMC3_PROTOBUFIO
0024 namespace HepMC3_pb {
0025 class GenEventData_GenParticleData;
0026 }
0027 #endif
0028 
0029 namespace HepMC3 {
0030 
0031 class GenEvent;
0032 class Attribute;
0033 
0034 class GenParticle : public std::enable_shared_from_this<GenParticle> {
0035 
0036     friend class GenVertex;
0037     friend class GenEvent;
0038 
0039 //
0040 // Constructors
0041 //
0042 public:
0043 
0044     /// @brief Default constructor
0045     GenParticle( const FourVector &momentum = FourVector::ZERO_VECTOR(), int pid = 0, int status = 0 );
0046 
0047     /// @brief Constructor based on particle data
0048     GenParticle( const GenParticleData &data );
0049 
0050 #ifdef HEPMC3_PROTOBUFIO
0051     /// @brief Constructor based on protobuf messages
0052     GenParticle( HepMC3_pb::GenEventData_GenParticleData const &data );
0053 #endif
0054 
0055 //
0056 // Functions
0057 //
0058 public:
0059     /// @brief Check if this particle belongs to an event
0060     bool in_event() const { return (bool) (m_event); }
0061 
0062     /// @brief Get the parent event
0063     GenEvent* parent_event() { return m_event; }
0064     /// @brief Get the parent event (const)
0065     const GenEvent* parent_event() const { return m_event; }
0066 
0067     /// @brief Get the particle ID number (*not* PDG ID)
0068     int id() const { return m_id; }
0069 
0070     const GenParticleData& data()         const { return m_data;  } //!< Get particle data
0071 
0072     ConstGenVertexPtr production_vertex() const;        //!< Get production vertex (const version)
0073     ConstGenVertexPtr end_vertex() const;               //!< Get end vertex (const version)
0074 
0075     GenVertexPtr production_vertex();        //!< Get production vertex
0076     GenVertexPtr end_vertex();               //!< Get end vertex
0077 
0078     /// @brief Convenience access to immediate incoming particles via production vertex
0079     /// @note Less efficient than via the vertex since return must be by value (in case there is no vertex)
0080     std::vector<GenParticlePtr> parents();
0081 
0082     /// @brief Convenience access to immediate incoming particles via production vertex (const version)
0083     /// @note Less efficient than via the vertex since return must be by value (in case there is no vertex)
0084     std::vector<ConstGenParticlePtr> parents() const;
0085 
0086     /// @brief Convenience access to immediate outgoing particles via end vertex
0087     /// @note Less efficient than via the vertex since return must be by value (in case there is no vertex)
0088     std::vector<GenParticlePtr> children();
0089 
0090     /// @brief Convenience access to immediate outgoing particles via end vertex
0091     /// @note Less efficient than via the vertex since return must be by value (in case there is no vertex)
0092     std::vector<ConstGenParticlePtr> children() const;
0093 
0094     int   pid()                   const { return m_data.pid;            } //!< Get PDG ID
0095     int   abs_pid()               const { return std::abs(pid());            } //!< Get absolute value of PDG ID
0096     int   status()                const { return m_data.status;         } //!< Get status code
0097     const FourVector& momentum()  const { return m_data.momentum;       } //!< Get momentum
0098     bool  is_generated_mass_set() const { return m_data.is_mass_set;    } //!< Check if generated mass is set
0099 
0100     /// @brief Get generated mass
0101     ///
0102     /// This function will return mass as set by a generator/tool.
0103     /// If not set, it will return momentum().m()
0104     double generated_mass() const;
0105 
0106 
0107     void set_pid(int pid);                         //!< Set PDG ID
0108     void set_status(int status);                   //!< Set status code
0109     void set_momentum(const FourVector& momentum); //!< Set momentum
0110     void set_generated_mass(double m);             //!< Set generated mass
0111     void unset_generated_mass();                   //!< Declare that generated mass is not set
0112 
0113     /// @brief Add an attribute to this particle
0114     ///
0115     ///  This will overwrite existing attribute if an attribute with
0116     ///  the same name is present. The attribute will be stored in the
0117     ///  parent_event(). @return false if there is no parent_event();
0118     bool add_attribute(const std::string& name, std::shared_ptr<Attribute> att);
0119 
0120     /// @brief Get list of names of attributes assigned to this particle
0121     std::vector<std::string> attribute_names() const;
0122 
0123     /// @brief Remove attribute
0124     void remove_attribute(const std::string& name);
0125 
0126     /// @brief Get attribute of type T
0127     template<class T>
0128     std::shared_ptr<T> attribute(const std::string& name) const;
0129 
0130     /// @brief Get attribute of any type as string
0131     std::string attribute_as_string(const std::string& name) const;
0132 
0133 
0134     /// @name Deprecated functionality
0135     /// @{
0136 
0137     /// @brief Get PDG ID
0138     /// @deprecated Use pid() instead
0139     int pdg_id() const { return pid(); }
0140 
0141     /// @brief Set PDG ID
0142     /// @deprecated Use set_pid() instead
0143     void set_pdg_id(const int& pidin) { set_pid(pidin); }
0144 
0145     /// @}
0146 //
0147 // Fields
0148 //
0149 private:
0150     GenEvent        *m_event; //!< Parent event
0151     int              m_id;    //!< Index
0152     GenParticleData  m_data;  //!< Particle data
0153 
0154     std::weak_ptr<GenVertex>    m_production_vertex; //!< Production vertex
0155     std::weak_ptr<GenVertex>    m_end_vertex;        //!< End vertex
0156 };
0157 
0158 } // namespace HepMC3
0159 
0160 
0161 
0162 #include "HepMC3/GenEvent.h"
0163 namespace HepMC3 {
0164 /// @brief Get attribute of type T
0165 template<class T> std::shared_ptr<T> GenParticle::attribute(const std::string& name) const {
0166     return parent_event()?
0167            parent_event()->attribute<T>(name, id()): std::shared_ptr<T>();
0168 }
0169 }
0170 #endif