Version: SMASH-2.0.2
smash::HepMcInterface Class Reference

#include <hepmcinterface.h>

Base class for output handlers that need the HepMC3 structure.

This class can write the full event info or just the initial state (i.e., beam particles) and final state (i.e., final state particle).

The class serves as a base class for output routines that utilizes the HepMC event format (currently HepMcOutput and RivetOutput).

A techincal point: We need to generate HepMC::GenParticle objects, and we need to keep track of which HepMC::GenParticle corresponds to which smash::ParticleData. We therefor set up a map from the smash::ParticleData identifier (integer) to HepMC::GenParticlePtr. We use that map to keep track of the particles and interaction points.

In case full event history:

At each interaction we create a new vertex, and add the incoming particles as "in" particles to that vertex. We also set the appropriate "state" of the incoming particles. That is, if the interaction corresponded to a decay, then the HepMC state is set to two (2). All other interactions are set to one hundred (100) plus the SMASH interaction code (since there is no standard for these codes other than 1: final state, 2: particle has decayed, 4: particle is beam particle).

For outgoing particles this is a bit different. In case of elastic scatterings, SMASH will keep the incoming particle around as an outgoing particle. This is not how the HepMC event record is invisioned. Indeed, the particle has changed momentum and that should be recorded in the event record. In that case, we therefore generate a new particle which we add as outgoing particle.

All outgoing particles of a vertex have their initial status set to one (1 - final state), but it can be changed later due to other interactions.

If the outgoing particle corresponds to an incoming particle, and in particular if the incoming particle is a beam particle (or later fragment thereof), we need to fragment the ion so that the outgoing particle is dissociated from the incoming particle. To that end, we check if the outgoing particle was part of the beam particles. If so, we remove the outgoing particle from the register of identifiers that make up the beam particle, and create a new beam particle. This ensures that the HepMC event record is sound (in most cases).

Definition at line 81 of file hepmcinterface.h.

Inheritance diagram for smash::HepMcInterface:
[legend]
Collaboration diagram for smash::HepMcInterface:
[legend]

Public Types

using AZ = std::pair< int, int >
 Pair of Atomic weight and number. More...
 

Public Member Functions

 HepMcInterface (const std::string &name, const bool full_event, const int total_N, const int proj_N)
 Create HepMC particle event in memory. More...
 
void at_eventstart (const Particles &particles, const int event_number, const EventInfo &event) override
 Add the initial particles information of an event to the central vertex. More...
 
void at_interaction (const Action &action, const double density) override
 Writes collisions to event. More...
 
void at_eventend (const Particles &particles, const int32_t event_number, const EventInfo &event) override
 Add the final particles information of an event to the central vertex. More...
 
- Public Member Functions inherited from smash::OutputInterface
 OutputInterface (std::string name)
 Construct output interface. More...
 
virtual ~OutputInterface ()=default
 
virtual void at_eventend (const Particles &particles, const int event_number, const EventInfo &info)=0
 Output launched at event end. More...
 
virtual void at_intermediate_time (const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventInfo &info)
 Output launched after every N'th timestep. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< DensityOnLattice > &lattice)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< EnergyMomentumTensor > &lattice)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_output (const GrandCanThermalizer &gct)
 Output to write energy-momentum tensor and related quantities from the thermalizer class. More...
 
bool is_dilepton_output () const
 Get, whether this is the dilepton output? More...
 
bool is_photon_output () const
 Get, whether this is the photon output? More...
 
bool is_IC_output () const
 Get, whether this is the IC output? More...
 
const char * to_string (const ThermodynamicQuantity tq)
 Convert thermodynamic quantities to strings. More...
 
const char * to_string (const DensityType dens_type)
 Convert density types to strings. More...
 

Protected Types

enum  Status { beam = 4, fnal = 1, dcy = 2, off = 100 }
 HepMC status codes. More...
 
using IdMap = std::map< int, HepMC3::GenParticlePtr >
 Type of mapping from SMASH ID to HepMC ID. More...
 
using CollCounter = std::valarray< int >
 Counter of collitions per incoming particle. More...
 

Protected Member Functions

void clear ()
 Clear before an event. More...
 
int get_status (const ProcessType &t) const
 Convert SMASH process type to HepMC status. More...
 
HepMC3::GenParticlePtr make_gen (int pid, int status, const smash::FourVector &mom, double mass=-1)
 Make an HepMC particle. More...
 
HepMC3::GenParticlePtr make_register (const ParticleData &p, int status=Status::fnal)
 Find particle in mapping or generate it. More...
 
HepMC3::GenParticlePtr find_or_make (const ParticleData &p, int status=Status::fnal, bool force_new=false)
 Find particle in mapping or generate it. More...
 
int ion_pdg (const AZ &az) const
 Encode ion PDG. More...
 

Protected Attributes

HepMC3::GenEvent event_
 The event. More...
 
HepMC3::GenHeavyIonPtr ion_
 The heavy-ion structure. More...
 
HepMC3::GenCrossSectionPtr xs_
 Dummy cross-section. More...
 
HepMC3::GenVertexPtr ip_
 The interaction point. More...
 
IdMap map_
 Mapping from ID to particle. More...
 
CollCounter coll_
 Collision counter. More...
 
int ncoll_
 counter of binary collisions (e.g., where both incoming particles are from the beams. More...
 
int ncoll_hard_
 counter of hard binary collisions (e.g., where both incoming particles are from the beams. More...
 
const int total_N_
 Total number of nucleons in projectile and target, needed for converting nuclei to single particles. More...
 
const int proj_N_
 Total number of nucleons in projectile, needed for converting nuclei to single particles. More...
 
bool full_event_
 Whether the full event or only final-state particles are in the output. More...
 
- Protected Attributes inherited from smash::OutputInterface
const bool is_dilepton_output_
 Is this the dilepton output? More...
 
const bool is_photon_output_
 Is this the photon output? More...
 
const bool is_IC_output_
 Is this the IC output? More...
 

Member Typedef Documentation

◆ AZ

using smash::HepMcInterface::AZ = std::pair<int, int>

Pair of Atomic weight and number.

Definition at line 84 of file hepmcinterface.h.

◆ IdMap

using smash::HepMcInterface::IdMap = std::map<int, HepMC3::GenParticlePtr>
protected

Type of mapping from SMASH ID to HepMC ID.

Definition at line 137 of file hepmcinterface.h.

◆ CollCounter

using smash::HepMcInterface::CollCounter = std::valarray<int>
protected

Counter of collitions per incoming particle.

Definition at line 139 of file hepmcinterface.h.

Member Enumeration Documentation

◆ Status

HepMC status codes.

Enumerator
beam 
fnal 
dcy 
off 

Definition at line 130 of file hepmcinterface.h.

130  {
131  beam = 4, // Beam particle
132  fnal = 1, // final state `final` is a reserved word
133  dcy = 2, // Decay
134  off = 100
135  };

Constructor & Destructor Documentation

◆ HepMcInterface()

smash::HepMcInterface::HepMcInterface ( const std::string &  name,
const bool  full_event,
const int  total_N,
const int  proj_N 
)

Create HepMC particle event in memory.

Parameters
[in]nameName of output
[in]full_eventWhether the full event or only final-state particles are printed in the output
[in]total_NTotal number of particles in both nuclei.
[in]proj_NNumber of particles in projectile.

Definition at line 18 of file hepmcinterface.cc.

20  : OutputInterface(name),
21  event_(HepMC3::Units::GEV, HepMC3::Units::MM),
22  ion_(),
23  xs_(),
24  ip_(),
25  total_N_(total_N),
26  proj_N_(proj_N),
27  full_event_(full_event) {
28  logg[LOutput].debug() << "Name of output: " << name << " "
29  << (full_event_ ? "full event" : "final state only")
30  << " output" << std::endl;
31  ion_ = std::make_shared<HepMC3::GenHeavyIon>();
32  xs_ = std::make_shared<HepMC3::GenCrossSection>();
33 
34  HepMC3::Setup::set_debug_level(logg[LOutput].isEnabled<einhard::DEBUG>() ? 5
35  : 0);
36 }

Member Function Documentation

◆ at_eventstart()

void smash::HepMcInterface::at_eventstart ( const Particles particles,
const int  event_number,
const EventInfo event 
)
overridevirtual

Add the initial particles information of an event to the central vertex.

Construct projectile and target particles with nuclear pdg code if collider.

Parameters
[in]particlesCurrent list of all particles.
[in]event_numberCurrent event number
[in]eventEvent information
Exceptions
std::runtime_errorif nuclei with non-nucleon particle (like hypernuclei) are tried to be constructed

Implements smash::OutputInterface.

Definition at line 38 of file hepmcinterface.cc.

40  {
41  // Clear event and mapping and set event number
42  clear();
43 
44  // Set header stuff on event
45  ion_->impact_parameter = event.impact_parameter;
46  xs_->set_cross_section(1, 1); // Dummy values
47  event_.set_event_number(event_number);
48  event_.set_heavy_ion(ion_);
49  coll_.resize(total_N_);
50 
51  // Create IP only if final state
52  ip_ = std::make_shared<HepMC3::GenVertex>();
53  event_.add_vertex(ip_);
54 
55  // Count up projectile and target
56  smash::FourVector p_proj;
57  smash::FourVector p_targ;
58  AZ az_proj;
59  AZ az_targ;
60  bool is_coll = proj_N_ > 0 && total_N_ > 0;
61 
62  for (auto& data : particles) {
63  if (is_coll) {
64  if (!data.is_neutron() && !data.is_proton()) {
65  throw std::runtime_error(
66  "Particle of PID=" + std::to_string(data.pdgcode().get_decimal()) +
67  " is not a valid HepMC beam particle!");
68  }
69 
70  bool isproj = data.id() < proj_N_;
71  smash::FourVector& p = (isproj ? p_proj : p_targ);
72  AZ& az = (isproj ? az_proj : az_targ);
73  p += data.momentum();
74  az.second += data.is_proton();
75  az.first++;
76  }
77 
78  if (!full_event_ && is_coll) {
79  continue;
80  }
81 
82  // If we are not only adding final state particles, but all
83  // interactions, or not in collider modus, then we add all the
84  // incoming particles as outgoing (incoming for non-collider
85  // modus) of the vertex. In that way, we will keep track of
86  // participants and spectators as well as make the event
87  // structure consistent.
88  auto op = make_register(data, Status::fnal);
89  if (is_coll) {
90  ip_->add_particle_out(op);
91  } else {
92  ip_->add_particle_in(op);
93  }
94  }
95  // Make beam particles
96  if (is_coll) {
97  auto proj = make_gen(ion_pdg(az_proj), Status::beam, p_proj);
98  auto targ = make_gen(ion_pdg(az_targ), Status::beam, p_targ);
99 
100  // Add to interaction point if we need to
101  ip_->add_particle_in(proj);
102  ip_->add_particle_in(targ);
103  }
104 }
Here is the call graph for this function:

◆ at_interaction()

void smash::HepMcInterface::at_interaction ( const Action action,
const double  density 
)
overridevirtual

Writes collisions to event.

Parameters
[in]actionan Action object containing incoming, outgoing particles and type of interactions.
[in]densityUnused, needed since inherited.

Reimplemented from smash::OutputInterface.

Definition at line 106 of file hepmcinterface.cc.

107  {
108  HepMC3::GenVertexPtr vp;
109  auto type = action.get_type();
110  int status = get_status(type);
111 
112  if (full_event_) {
113  FourVector v = action.get_interaction_point();
114  vp = std::make_shared<HepMC3::GenVertex>(
115  HepMC3::FourVector(v.x1(), v.x2(), v.x3(), v.x0()));
116  vp->add_attribute("weight", std::make_shared<HepMC3::FloatAttribute>(
117  action.get_total_weight()));
118  vp->add_attribute(
119  "partial_weight",
120  std::make_shared<HepMC3::FloatAttribute>(action.get_partial_weight()));
121  event_.add_vertex(vp);
122  }
123 
124  // Now mark participants
125  if (full_event_) {
126  for (auto& i : action.incoming_particles()) {
127  // Create tree
128  HepMC3::GenParticlePtr ip = find_or_make(i, status);
129  ip->set_status(status);
130  vp->add_particle_in(ip);
131  }
132  } else {
133  return;
134  }
135 
136  // Add outgoing particles
137  for (auto& o : action.outgoing_particles()) {
138  vp->add_particle_out(make_register(o, Status::fnal));
139  }
140 }
Here is the call graph for this function:

◆ at_eventend()

void smash::HepMcInterface::at_eventend ( const Particles particles,
const int32_t  event_number,
const EventInfo event 
)
override

Add the final particles information of an event to the central vertex.

Store impact paramter and write event.

Parameters
[in]particlesCurrent list of particles.
[in]event_numberNumber of event.
[in]eventEvent info, see event_info

Definition at line 142 of file hepmcinterface.cc.

144  {
145  // In case this was an empty event
146  if (event.empty_event) {
147  clear();
148  return;
149  }
150  /* since the number of collisions is not an experimental obervable, we set it
151  * to -1.
152  */
153  ion_->Ncoll_hard = -1;
154  ion_->Ncoll = -1;
155  /* This should be the number of participants in the projectile nucleus.
156  * However, to avoid confusion with the Glauber model, we prefer to set it -1.
157  */
158  ion_->Npart_proj = -1;
159  /* his should be the number of participants in the target nucleus.
160  * However, to avoid confusion with the Glauber model, we prefer to set it -1.
161  */
162  ion_->Npart_targ = -1;
163  // If we only do final state events, then take particle
164  // Note, we should already have the particles if not only final
165  // state
166  // Take all passed particles and add as outgoing particles to event
167  for (auto& p : particles) {
168  if (!full_event_) {
169  auto h = make_register(p, Status::fnal);
170  ip_->add_particle_out(h);
171  } else if (map_.find(p.id()) == map_.end()) {
172  throw std::runtime_error("Dangling particle " + std::to_string(p.id()));
173  }
174  }
175 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void smash::HepMcInterface::clear ( )
protected

Clear before an event.

Definition at line 177 of file hepmcinterface.cc.

177  {
178  event_.clear();
179  map_.clear();
180  ip_ = 0;
181  coll_ = 0;
182  ncoll_ = 0;
183  ncoll_hard_ = 0;
184 }
Here is the caller graph for this function:

◆ get_status()

int smash::HepMcInterface::get_status ( const ProcessType t) const
protected

Convert SMASH process type to HepMC status.

Definition at line 186 of file hepmcinterface.cc.

186  {
187  if (t == ProcessType::Decay)
188  return Status::dcy;
189 
190  // Make all other codes SMASH specific
191  return static_cast<int>(t) + static_cast<int>(Status::off);
192 }
Here is the caller graph for this function:

◆ make_gen()

HepMC3::GenParticlePtr smash::HepMcInterface::make_gen ( int  pid,
int  status,
const smash::FourVector mom,
double  mass = -1 
)
protected

Make an HepMC particle.

Parameters
[in]pidParticle type identifier
[in]statusStatus code of particle
[in]momFour momentum of particle
[in]massGenerator mass of particle
Returns
A shared pointer to a HepMC::GenParticle object

Definition at line 194 of file hepmcinterface.cc.

196  {
197  auto p = std::make_shared<HepMC3::GenParticle>(
198  HepMC3::FourVector(mom.x1(), mom.x2(), mom.x3(), mom.x0()), pid, status);
199  if (mass > 0)
200  p->set_generated_mass(mass);
201  return p;
202 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_register()

HepMC3::GenParticlePtr smash::HepMcInterface::make_register ( const ParticleData p,
int  status = Status::fnal 
)
protected

Find particle in mapping or generate it.

Parameters
[in]pParticleData object
[in]statusHepMC status code
Returns
r The existing or generated particle

Definition at line 204 of file hepmcinterface.cc.

205  {
206  int id = p.id();
207  auto h = make_gen(p.pdgcode().get_decimal(), status, p.momentum(),
208  p.type().mass());
209  map_[id] = h;
210 
211  return h;
212 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_or_make()

HepMC3::GenParticlePtr smash::HepMcInterface::find_or_make ( const ParticleData p,
int  status = Status::fnal,
bool  force_new = false 
)
protected

Find particle in mapping or generate it.

Parameters
[in]pParticleData object
[in]statusHepMC status code
[in]force_newCreate new particle even if could found
Returns
r The existing or generated particle

Definition at line 214 of file hepmcinterface.cc.

216  {
217  int id = p.id();
218  if (!force_new) {
219  auto it = map_.find(id);
220  if (it != map_.end()) {
221  return it->second;
222  }
223  }
224 
225  return make_register(p, status);
226 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ion_pdg()

int smash::HepMcInterface::ion_pdg ( const AZ az) const
protected

Encode ion PDG.

Parameters
[in]azPair of Atomic weight and number
Returns
PDG code of ion

Definition at line 228 of file hepmcinterface.cc.

228  {
229  if (az.second == 1 && az.first == 1)
230  return 2212; // Proton
231  if (az.second == 1 && az.first == 0)
232  return 2112; // Neutron
233 
234  return 1'000'000'000 + az.second * 10'000 + az.first * 10;
235 }
Here is the caller graph for this function:

Member Data Documentation

◆ event_

HepMC3::GenEvent smash::HepMcInterface::event_
protected

The event.

Definition at line 188 of file hepmcinterface.h.

◆ ion_

HepMC3::GenHeavyIonPtr smash::HepMcInterface::ion_
protected

The heavy-ion structure.

Definition at line 190 of file hepmcinterface.h.

◆ xs_

HepMC3::GenCrossSectionPtr smash::HepMcInterface::xs_
protected

Dummy cross-section.

Definition at line 192 of file hepmcinterface.h.

◆ ip_

HepMC3::GenVertexPtr smash::HepMcInterface::ip_
protected

The interaction point.

Definition at line 194 of file hepmcinterface.h.

◆ map_

IdMap smash::HepMcInterface::map_
protected

Mapping from ID to particle.

Definition at line 196 of file hepmcinterface.h.

◆ coll_

CollCounter smash::HepMcInterface::coll_
protected

Collision counter.

For each \(i_{th}\) incoming nucleon we keep track of how many collisions that particle took in \( c_i\), classifying it as a participant if it had at least one collision. So, the total number of participants is:

\[ N_{\mathrm{part}} = \sum_i \begin{cases} 1 & c_i>0\\ 0 &c_i=0\end{cases} \]

The total number of collisions is given by the sum of the collisions of the nucleons of the incoming ion, the so called "projectile". Since we are considering the collisions between the nucleons of both ions, those of the "target" are already included in the sum.

\[ N_{\mathrm{coll}} = \sum_i^{N_{\mathrm{projectile}}} c_i\\ \]

Definition at line 217 of file hepmcinterface.h.

◆ ncoll_

int smash::HepMcInterface::ncoll_
protected

counter of binary collisions (e.g., where both incoming particles are from the beams.

Definition at line 220 of file hepmcinterface.h.

◆ ncoll_hard_

int smash::HepMcInterface::ncoll_hard_
protected

counter of hard binary collisions (e.g., where both incoming particles are from the beams.

Definition at line 223 of file hepmcinterface.h.

◆ total_N_

const int smash::HepMcInterface::total_N_
protected

Total number of nucleons in projectile and target, needed for converting nuclei to single particles.

Definition at line 228 of file hepmcinterface.h.

◆ proj_N_

const int smash::HepMcInterface::proj_N_
protected

Total number of nucleons in projectile, needed for converting nuclei to single particles.

Definition at line 233 of file hepmcinterface.h.

◆ full_event_

bool smash::HepMcInterface::full_event_
protected

Whether the full event or only final-state particles are in the output.

Definition at line 235 of file hepmcinterface.h.


The documentation for this class was generated from the following files:
smash::OutputInterface::OutputInterface
OutputInterface(std::string name)
Construct output interface.
Definition: outputinterface.h:72
smash::LOutput
static constexpr int LOutput
Definition: outputinterface.h:24
smash::HepMcInterface::map_
IdMap map_
Mapping from ID to particle.
Definition: hepmcinterface.h:196
smash::HepMcInterface::ncoll_hard_
int ncoll_hard_
counter of hard binary collisions (e.g., where both incoming particles are from the beams.
Definition: hepmcinterface.h:223
smash::HepMcInterface::find_or_make
HepMC3::GenParticlePtr find_or_make(const ParticleData &p, int status=Status::fnal, bool force_new=false)
Find particle in mapping or generate it.
Definition: hepmcinterface.cc:214
smash::HepMcInterface::event_
HepMC3::GenEvent event_
The event.
Definition: hepmcinterface.h:188
smash::ProcessType::Decay
@ Decay
resonance decay
smash::HepMcInterface::total_N_
const int total_N_
Total number of nucleons in projectile and target, needed for converting nuclei to single particles.
Definition: hepmcinterface.h:228
smash::FourVector::x3
double x3() const
Definition: fourvector.h:315
smash::HepMcInterface::ncoll_
int ncoll_
counter of binary collisions (e.g., where both incoming particles are from the beams.
Definition: hepmcinterface.h:220
smash::HepMcInterface::make_gen
HepMC3::GenParticlePtr make_gen(int pid, int status, const smash::FourVector &mom, double mass=-1)
Make an HepMC particle.
Definition: hepmcinterface.cc:194
smash::FourVector::x1
double x1() const
Definition: fourvector.h:307
smash::logg
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
smash::HepMcInterface::off
@ off
Definition: hepmcinterface.h:134
smash::HepMcInterface::xs_
HepMC3::GenCrossSectionPtr xs_
Dummy cross-section.
Definition: hepmcinterface.h:192
smash::HepMcInterface::make_register
HepMC3::GenParticlePtr make_register(const ParticleData &p, int status=Status::fnal)
Find particle in mapping or generate it.
Definition: hepmcinterface.cc:204
smash::HepMcInterface::full_event_
bool full_event_
Whether the full event or only final-state particles are in the output.
Definition: hepmcinterface.h:235
smash::FourVector::x0
double x0() const
Definition: fourvector.h:303
smash::FourVector::x2
double x2() const
Definition: fourvector.h:311
smash::HepMcInterface::fnal
@ fnal
Definition: hepmcinterface.h:132
smash::HepMcInterface::ip_
HepMC3::GenVertexPtr ip_
The interaction point.
Definition: hepmcinterface.h:194
smash::HepMcInterface::ion_pdg
int ion_pdg(const AZ &az) const
Encode ion PDG.
Definition: hepmcinterface.cc:228
smash::HepMcInterface::get_status
int get_status(const ProcessType &t) const
Convert SMASH process type to HepMC status.
Definition: hepmcinterface.cc:186
smash::HepMcInterface::clear
void clear()
Clear before an event.
Definition: hepmcinterface.cc:177
smash::HepMcInterface::ion_
HepMC3::GenHeavyIonPtr ion_
The heavy-ion structure.
Definition: hepmcinterface.h:190
smash::FourVector
Definition: fourvector.h:33
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::HepMcInterface::coll_
CollCounter coll_
Collision counter.
Definition: hepmcinterface.h:217
smash::HepMcInterface::dcy
@ dcy
Definition: hepmcinterface.h:133
smash::HepMcInterface::proj_N_
const int proj_N_
Total number of nucleons in projectile, needed for converting nuclei to single particles.
Definition: hepmcinterface.h:233
smash::HepMcInterface::AZ
std::pair< int, int > AZ
Pair of Atomic weight and number.
Definition: hepmcinterface.h:84
smash::HepMcInterface::beam
@ beam
Definition: hepmcinterface.h:131