HepMC3 event record library: AssociatedParticle.h Source File

HepMC3 event record library

AssociatedParticle.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_AssociatedParticle_H
7#define HEPMC3_AssociatedParticle_H
8/**
9 * @file AssociatedParticle.h
10 * @brief Definition of \b class AssociatedParticle,
11 *
12 * @class HepMC3::AssociatedParticle
13 * @brief Attribute class allowing
14 * eg. a GenParticle to refer to another GenParticle.
15
16 * @ingroup attributes
17 *
18 */
19
20#include "HepMC3/Attribute.h"
21#include "HepMC3/GenParticle.h"
22
23namespace HepMC3 {
24
25/**
26 * @class HepMC3::IntAttribute
27 * @brief Attribute that holds an Integer implemented as an int
28 *
29 * @ingroup attributes
30 */
31 class AssociatedParticle : public IntAttribute {
32public:
33
34 /** @brief Default constructor */
35 AssociatedParticle() {}
36
37 /** @brief Constructor initializing attribute value */
38 AssociatedParticle(ConstGenParticlePtr p)
39 : IntAttribute(p->id()), m_associated(p) {}
40
41 /** @brief Implementation of Attribute::from_string */
42 bool from_string(const std::string &att) {
43 IntAttribute::from_string(att);
44 if ( associatedId() > int(event()->particles().size()) ||
45 associatedId() <= 0 ) return false;
46 m_associated = event()->particles()[associatedId() -1];
47 return true;
48 }
49
50 /** @brief get id of the associated particle. */
51 int associatedId() const {
52 return value();
53 }
54
55 /** @brief get a pointer to the associated particle. */
56 ConstGenParticlePtr associated() const {
57 return m_associated;
58 }
59
60 /** @brief set the value associated to this Attribute. */
61 void set_associated(ConstGenParticlePtr p) {
62 IntAttribute::set_value(p->id());
63 m_associated = p;
64 }
65
66private:
67
68 ConstGenParticlePtr m_associated; ///< The associated particle.
69
70};
71
72} // namespace HepMC3
73
74#endif
Attribute.h
Definition of class Attribute, class IntAttribute and class StringAttribute.
GenParticle.h
Definition of class GenParticle.
HepMC3::AssociatedParticle::from_string
bool from_string(const std::string &att)
Implementation of Attribute::from_string.
Definition AssociatedParticle.h:42
HepMC3::AssociatedParticle::set_associated
void set_associated(ConstGenParticlePtr p)
set the value associated to this Attribute.
Definition AssociatedParticle.h:61
HepMC3::AssociatedParticle::AssociatedParticle
AssociatedParticle(ConstGenParticlePtr p)
Constructor initializing attribute value.
Definition AssociatedParticle.h:38
HepMC3::AssociatedParticle::m_associated
ConstGenParticlePtr m_associated
The associated particle.
Definition AssociatedParticle.h:68
HepMC3::AssociatedParticle::AssociatedParticle
AssociatedParticle()
Default constructor.
Definition AssociatedParticle.h:35
HepMC3::AssociatedParticle::associatedId
int associatedId() const
get id of the associated particle.
Definition AssociatedParticle.h:51
HepMC3::AssociatedParticle::associated
ConstGenParticlePtr associated() const
get a pointer to the associated particle.
Definition AssociatedParticle.h:56
HepMC3::Attribute::event
const GenEvent * event() const
Definition Attribute.h:108
HepMC3::GenEvent::particles
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const).
Definition GenEvent.cc:39
HepMC3::IntAttribute::set_value
void set_value(const int &i)
set the value associated to this Attribute.
Definition Attribute.h:185
HepMC3::IntAttribute::IntAttribute
IntAttribute()
Default constructor.
Definition Attribute.h:161
HepMC3::IntAttribute::value
int value() const
get the value associated to this Attribute.
Definition Attribute.h:180
HepMC3::IntAttribute::from_string
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
Definition Attribute.h:167
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24