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 /// @file GenVertex.h
0007 /// @brief Definition of \b class GenVertex
0008 //
0009 #ifndef HEPMC3_GENVERTEX_H
0010 #define HEPMC3_GENVERTEX_H
0011 #include <string>
0012 #include "HepMC3/GenParticle_fwd.h"
0013 #include "HepMC3/GenVertex_fwd.h"
0014 #include "HepMC3/Data/GenVertexData.h"
0015 #include "HepMC3/FourVector.h"
0016 
0017 #ifdef HEPMC3_PROTOBUFIO
0018 namespace HepMC3_pb {
0019 class GenEventData_GenVertexData;
0020 }
0021 #endif
0022 
0023 namespace HepMC3 {
0024 
0025 class Attribute;
0026 class GenEvent;
0027 
0028 /// Stores vertex-related information
0029 class GenVertex : public std::enable_shared_from_this<GenVertex> {
0030 
0031     friend class GenEvent;
0032 
0033 public:
0034 
0035     /// @name Constructors
0036     /// @{
0037 
0038     /// Default constructor
0039     GenVertex( const FourVector& position = FourVector::ZERO_VECTOR() );
0040 
0041     /// Constructor based on vertex data
0042     GenVertex( const GenVertexData& data );
0043 
0044 #ifdef HEPMC3_PROTOBUFIO
0045     /// Constructor based on protobuf messages
0046     GenVertex( HepMC3_pb::GenEventData_GenVertexData const &data );
0047 #endif
0048 
0049     /// @}
0050 
0051 
0052     /// @name Accessors
0053     /// @{
0054 
0055     /// Get parent event
0056     GenEvent* parent_event() { return m_event; }
0057 
0058     /// Get parent event
0059     const GenEvent* parent_event() const { return m_event; }
0060 
0061     /// Check if this vertex belongs to an event
0062     bool in_event() const { return parent_event() != nullptr; }
0063 
0064     /// Get the vertex unique identifier
0065     ///
0066     /// @note This is not the same as id() in HepMC v2, which is now @c status()
0067     int id() const { return m_id; }
0068 
0069     /// Get vertex status code
0070     int status() const { return m_data.status; }
0071     /// Set vertex status code
0072     void set_status(int stat) { m_data.status = stat; }
0073 
0074     /// Get vertex data
0075     const GenVertexData& data() const { return m_data; }
0076 
0077     /// Add incoming particle
0078     void add_particle_in ( GenParticlePtr p);
0079     /// Add outgoing particle
0080     void add_particle_out( GenParticlePtr p);
0081     /// Remove incoming particle
0082     void remove_particle_in ( GenParticlePtr p);
0083     /// Remove outgoing particle
0084     void remove_particle_out( GenParticlePtr p);
0085 
0086     /// Number of incoming particles, HepMC2 compatiility
0087     inline int particles_in_size() const { return m_particles_in.size(); }
0088     /// Number of outgoing particles, HepMC2 compatiility
0089     inline int particles_out_size() const { return m_particles_out.size(); }
0090 
0091 
0092     /// Get list of incoming particles
0093     const std::vector<GenParticlePtr>& particles_in() { return m_particles_in; }
0094     /// Get list of incoming particles (for const access)
0095     const std::vector<ConstGenParticlePtr>& particles_in() const;
0096     /// Get list of outgoing particles
0097     const std::vector<GenParticlePtr>& particles_out() { return m_particles_out; }
0098     /// Get list of outgoing particles (for const access)
0099     const std::vector<ConstGenParticlePtr>& particles_out() const;
0100 
0101     /// @brief Get vertex position
0102     ///
0103     /// Returns the position of this vertex. If a position is not set on _this_ vertex,
0104     /// the production vertices of ancestors are searched to find the inherited position.
0105     /// FourVector(0,0,0,0) is returned if no position information is found.
0106     ///
0107     const FourVector& position() const;
0108     /// @brief Check if position of this vertex is set
0109     bool has_set_position() const { return !(m_data.position.is_zero()); }
0110 
0111     /// Set vertex position
0112     void set_position(const FourVector& new_pos); //!<
0113 
0114     /// @brief Add event attribute to this vertex
0115     ///
0116     /// This will overwrite existing attribute if an attribute with
0117     /// the same name is present. The attribute will be stored in the
0118     /// parent_event(). @return false if there is no parent_event();
0119     bool add_attribute(const std::string& name, std::shared_ptr<Attribute> att);
0120 
0121     /// @brief Get list of names of attributes assigned to this particle
0122     std::vector<std::string> attribute_names() const;
0123 
0124     /// @brief Remove attribute
0125     void remove_attribute(const std::string& name);
0126 
0127     /// @brief Get attribute of type T
0128     template<class T>
0129     std::shared_ptr<T> attribute(const std::string& name) const;
0130 
0131     /// @brief Get attribute of any type as string
0132     std::string attribute_as_string(const std::string& name) const;
0133 
0134 
0135 private:
0136 
0137     /// @name Fields
0138     /// @{
0139     GenEvent       *m_event;  //!< Parent event
0140     int             m_id;     //!< Vertex id
0141     GenVertexData   m_data;   //!< Vertex data
0142 
0143     std::vector<GenParticlePtr>  m_particles_in;  //!< Incoming particle list
0144 
0145     std::vector<GenParticlePtr>  m_particles_out; //!< Outgoing particle list
0146     /// @}
0147 
0148 };
0149 
0150 
0151 } // namespace HepMC3
0152 
0153 #include "HepMC3/GenEvent.h"
0154 namespace HepMC3 {
0155 /// @brief Get attribute of type T
0156 template<class T> std::shared_ptr<T> GenVertex::attribute(const std::string& name) const {
0157     return parent_event()?
0158            parent_event()->attribute<T>(name, id()): std::shared_ptr<T>();
0159 }
0160 }
0161 
0162 #endif