Version: SMASH-3.4
hepmcinterface.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2021 Christian Holm Christensen
4  * Copyright (c) 2021-2024,2026
5  * SMASH Team
6  *
7  * GNU General Public License (GPLv3 or later)
8  *
9  */
10 
11 #ifndef SRC_INCLUDE_SMASH_HEPMCINTERFACE_H_
12 #define SRC_INCLUDE_SMASH_HEPMCINTERFACE_H_
13 
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <utility>
18 #include <valarray>
19 
20 #include "HepMC3/GenCrossSection.h"
21 #include "HepMC3/GenEvent.h"
22 #include "HepMC3/GenHeavyIon.h"
23 #include "HepMC3/GenParticle.h"
24 #include "HepMC3/GenVertex.h"
25 
26 #include "forwarddeclarations.h"
27 #include "outputinterface.h"
28 #include "outputparameters.h"
29 namespace smash {
30 
31 /**
32  * \ingroup output
33  *
34  * \brief Base class for output handlers that need the HepMC3 structure
35  *
36  * This class can write the full event info or just the initial state
37  * (i.e., beam particles) and final state (i.e., final state
38  * particle).
39  *
40  * The class serves as a base class for output routines that utilizes
41  * the HepMC event format (currently HepMcOutput and RivetOutput).
42  *
43  * A technical point: We need to generate HepMC::GenParticle objects,
44  * and we need to keep track of which HepMC::GenParticle corresponds
45  * to which smash::ParticleData. We therefor set up a map from the
46  * smash::ParticleData identifier (integer) to HepMC::GenParticlePtr.
47  * We use that map to keep track of the particles and interaction
48  * points.
49 
50  * In case full event history:
51  *
52  * At each interaction we create a new vertex, and add the incoming
53  * particles as "in" particles to that vertex. We also set the
54  * appropriate "state" of the incoming particles. That is, if the
55  * interaction corresponded to a decay, then the HepMC state is set to
56  * two (2). All other interactions are set to one hundred (100) plus
57  * the SMASH interaction code (since there is no standard for these
58  * codes other than 1: final state, 2: particle has decayed,
59  * 4: particle is beam particle).
60  *
61  * For outgoing particles this is a bit different. In case of elastic
62  * scatterings, SMASH will keep the incoming particle around as an
63  * outgoing particle. This is not how the HepMC event record is
64  * envisioned. Indeed, the particle has changed momentum and that
65  * should be recorded in the event record. In that case, we therefore
66  * generate a new particle which we add as outgoing particle.
67  *
68  * All outgoing particles of a vertex have their initial status set to
69  * one (1 - final state), but it can be changed later due to other
70  * interactions.
71  *
72  * If the outgoing particle corresponds to an incoming particle, and
73  * in particular if the incoming particle is a beam particle (or later
74  * fragment thereof), we need to fragment the ion so that the outgoing
75  * particle is dissociated from the incoming particle. To that end,
76  * we check if the outgoing particle was part of the beam particles.
77  * If so, we remove the outgoing particle from the register of
78  * identifiers that make up the beam particle, and create a new beam
79  * particle. This ensures that the HepMC event record is sound (in
80  * most cases).
81  */
83  public:
84  /// Pair of Atomic weight and number
85  using AZ = std::pair<int, int>;
86  /**
87  * Create HepMC particle event in memory.
88  *
89  * \param[in] name Name of output
90  * \param[in] full_event Whether the full event or only final-state particles
91  * are printed in the output
92  */
93  HepMcInterface(const std::string& name, const bool full_event);
94  /**
95  * Add the initial particles information of an event to the
96  * central vertex. Construct projectile and target particles with
97  * nuclear pdg code if collider.
98  *
99  * \param[in] particles Current list of all particles.
100  * \param[in] event_label Event/ensemble numbers
101  * \param[in] event Event information
102  * \throw std::runtime_error if nuclei with non-nucleon particle
103  * (like hypernuclei) are tried to be constructed
104  */
105  void at_eventstart(const Particles& particles, const EventLabel& event_label,
106  const EventInfo& event) override;
107  /**
108  * Writes collisions to event.
109  *
110  * \param[in] action an Action object containing incoming,
111  * outgoing particles and type of interactions.
112  * \param[in] density Unused, needed since inherited.
113  */
114  void at_interaction(const Action& action, const double density) override;
115  /**
116  * Add the final particles information of an event to the central vertex.
117  * Store impact paramter and write event.
118  *
119  * \param[in] particles Current list of particles.
120  * \param[in] event_label Event/ensemble numbers
121  * \param[in] event Event info, see \ref event_info
122  */
123  void at_eventend(const Particles& particles, const EventLabel& event_label,
124  const EventInfo& event) override;
125 
126  protected:
127  /** HepMC status codes */
128  enum Status {
129  beam = 4, // Beam particle
130  fnal = 1, // final state `final` is a reserved word
131  dcy = 2, // Decay
132  off = 100
133  };
134  /** Type of mapping from SMASH ID to HepMC ID */
135  using IdMap = std::map<int, HepMC3::GenParticlePtr>;
136  /** Counter of collitions per incoming particle */
137  using CollCounter = std::valarray<int>;
138  /** Clear before an event */
139  void clear();
140  /** Convert SMASH process type to HepMC status */
141  int get_status(const ProcessType& t) const;
142  /**
143  * Make an HepMC particle
144  *
145  * \param[in] pid Particle type identifier
146  * \param[in] status Status code of particle
147  * \param[in] mom Four momentum of particle
148  * \param[in] mass Generator mass of particle
149  *
150  * \return A shared pointer to a HepMC::GenParticle object
151  */
152  HepMC3::GenParticlePtr make_gen(int pid, int status,
153  const smash::FourVector& mom,
154  double mass = -1);
155  /**
156  * Find particle in mapping or generate it.
157  *
158  * \param[in] p ParticleData object
159  * \param[in] status HepMC status code
160  *
161  * \return r The existing or generated particle
162  */
163  HepMC3::GenParticlePtr make_register(const ParticleData& p,
164  int status = Status::fnal);
165  /**
166  * Find particle in mapping or generate it.
167  *
168  * \param[in] p ParticleData object
169  * \param[in] status HepMC status code
170  * \param[in] force_new Create new particle even if could found
171  *
172  * \return r The existing or generated particle
173  */
174  HepMC3::GenParticlePtr find_or_make(const ParticleData& p,
175  int status = Status::fnal,
176  bool force_new = false);
177  /**
178  * Encode ion PDG
179  *
180  * \param[in] az Pair of Atomic weight and number
181  *
182  * \return PDG code of ion
183  */
184  int ion_pdg(const AZ& az) const;
185  /** The event */
186  HepMC3::GenEvent event_;
187  /** The heavy-ion structure */
188  HepMC3::GenHeavyIonPtr ion_;
189  /** Dummy cross-section */
190  HepMC3::GenCrossSectionPtr xs_;
191  /** The interaction point */
192  HepMC3::GenVertexPtr ip_;
193  /** Mapping from ID to particle */
195  /**
196  * Collision counter. For each \f$i_{th}\f$ incoming nucleon we keep track of
197  * how many collisions that particle took in \f$ c_i\f$, classifying it as a
198  * participant if it had at least one collision. So, the total number of
199  * participants is:
200  *
201  * \f[
202  N_{\mathrm{part}} = \sum_i \begin{cases} 1 & c_i>0\\ 0 &c_i=0\end{cases}
203  \f]
204  *
205  * The total number of collisions is given by the sum of the collisions of the
206  * nucleons of the incoming ion, the so called "projectile". Since we are
207  * considering the collisions between the nucleons of both ions, those of
208  * the "target" are already included in the sum.
209  *
210  * \f[
211  N_{\mathrm{coll}} = \sum_i^{N_{\mathrm{projectile}}} c_i\\
212  \f]
213  *
214  */
216  /** counter of binary collisions (e.g., where both incoming
217  particles are from the beams. */
218  int ncoll_;
219  /** counter of hard binary collisions (e.g., where both incoming
220  particles are from the beams. */
222  /** Whether the full event or only final-state particles are in the output */
224 };
225 } // namespace smash
226 
227 #endif // SRC_INCLUDE_SMASH_HEPMCINTERFACE_H_
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:35
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
Base class for output handlers that need the HepMC3 structure.
std::pair< int, int > AZ
Pair of Atomic weight and number.
HepMC3::GenVertexPtr ip_
The interaction point.
std::valarray< int > CollCounter
Counter of collitions per incoming particle.
int ncoll_
counter of binary collisions (e.g., where both incoming particles are from the beams.
bool full_event_
Whether the full event or only final-state particles are in the output.
void at_eventend(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
Add the final particles information of an event to the central vertex.
HepMC3::GenParticlePtr make_gen(int pid, int status, const smash::FourVector &mom, double mass=-1)
Make an HepMC particle.
int ion_pdg(const AZ &az) const
Encode ion PDG.
int get_status(const ProcessType &t) const
Convert SMASH process type to HepMC status.
HepMC3::GenParticlePtr make_register(const ParticleData &p, int status=Status::fnal)
Find particle in mapping or generate it.
int ncoll_hard_
counter of hard binary collisions (e.g., where both incoming particles are from the beams.
void clear()
Clear before an event.
IdMap map_
Mapping from ID to particle.
void at_interaction(const Action &action, const double density) override
Writes collisions to event.
Status
HepMC status codes.
HepMC3::GenParticlePtr find_or_make(const ParticleData &p, int status=Status::fnal, bool force_new=false)
Find particle in mapping or generate it.
HepMC3::GenEvent event_
The event.
std::map< int, HepMC3::GenParticlePtr > IdMap
Type of mapping from SMASH ID to HepMC ID.
HepMC3::GenHeavyIonPtr ion_
The heavy-ion structure.
void at_eventstart(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
Add the initial particles information of an event to the central vertex.
CollCounter coll_
Collision counter.
HepMcInterface(const std::string &name, const bool full_event)
Create HepMC particle event in memory.
HepMC3::GenCrossSectionPtr xs_
Dummy cross-section.
Abstraction of generic output.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:59
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
constexpr int p
Proton.
Definition: action.h:24
ProcessType
ProcessTypes are used to identify the type of the process.
Definition: processbranch.h:39
Structure to contain custom data for output.
Structure to contain information about the event and ensemble numbers.