Back to home page

EIC code displayed by LXR

 
 

    


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

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_AssociatedParticle_H
0007 #define HEPMC3_AssociatedParticle_H
0008 /**
0009  *  @file AssociatedParticle.h
0010  *  @brief Definition of \b class AssociatedParticle,
0011  *
0012  *  @class HepMC3::AssociatedParticle
0013  *  @brief Attribute class allowing
0014  *  eg. a GenParticle to refer to another GenParticle.
0015 
0016  *  @ingroup attributes
0017  *
0018  */
0019 
0020 #include "HepMC3/Attribute.h"
0021 #include "HepMC3/GenParticle.h"
0022 
0023 namespace HepMC3 {
0024 
0025 /**
0026  *  @class HepMC3::IntAttribute
0027  *  @brief Attribute that holds an Integer implemented as an int
0028  *
0029  *  @ingroup attributes
0030  */
0031 class AssociatedParticle : public IntAttribute {
0032 public:
0033 
0034     /** @brief Default constructor */
0035     AssociatedParticle() {}
0036 
0037     /** @brief Constructor initializing attribute value */
0038     AssociatedParticle(ConstGenParticlePtr p)
0039         : IntAttribute(p->id()), m_associated(p) {}
0040 
0041     /** @brief Implementation of Attribute::from_string */
0042     bool from_string(const std::string &att) {
0043         IntAttribute::from_string(att);
0044         if ( associatedId() > int(event()->particles().size()) ||
0045                 associatedId() <= 0  ) return false;
0046         m_associated = event()->particles()[associatedId() -1];
0047         return true;
0048     }
0049 
0050     /** @brief get id of the associated particle. */
0051     int associatedId() const {
0052         return value();
0053     }
0054 
0055     /** @brief get a pointer to the associated particle. */
0056     ConstGenParticlePtr associated() const {
0057         return m_associated;
0058     }
0059 
0060     /** @brief set the value associated to this Attribute. */
0061     void set_associated(ConstGenParticlePtr p) {
0062         IntAttribute::set_value(p->id());
0063         m_associated = p;
0064     }
0065 
0066 private:
0067 
0068     ConstGenParticlePtr m_associated; ///< The associated particle.
0069 
0070 };
0071 
0072 } // namespace HepMC3
0073 
0074 #endif