Version: SMASH-3.1
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 83 of file hepmcinterface.h.

Inheritance diagram for smash::HepMcInterface:
smash::OutputInterface smash::HepMcOutput smash::RivetOutput

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)
 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 ()=0
 Pure virtual destructor to make class abstract and prevent its instantiation. More...
 
virtual void at_eventstart (const std::vector< Particles > &, int)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const int, const ThermodynamicQuantity, const DensityType, RectangularLattice< DensityOnLattice >)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const int, const ThermodynamicQuantity, const DensityType, RectangularLattice< EnergyMomentumTensor >)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventend (const int, const ThermodynamicQuantity, const DensityType)
 Output launched at event end. More...
 
virtual void at_eventend (const ThermodynamicQuantity)
 Output launched at event end. More...
 
virtual void at_eventend (const Particles &, const int, const EventInfo &)
 Output launched at event end. More...
 
virtual void at_eventend (const std::vector< Particles > &, const int)
 Output launched at event end. More...
 
virtual void at_intermediate_time (const Particles &, const std::unique_ptr< Clock > &, const DensityParameters &, const EventInfo &)
 Output launched after every N'th time-step. More...
 
virtual void at_intermediate_time (const std::vector< Particles > &, const std::unique_ptr< Clock > &, const DensityParameters &)
 Output launched after every N'th timestep. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity, const DensityType, RectangularLattice< DensityOnLattice > &)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity, const DensityType, RectangularLattice< EnergyMomentumTensor > &)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &, const double)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &, const double, const std::vector< Particles > &, const DensityParameters &)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_lattice_output (const ThermodynamicQuantity, RectangularLattice< EnergyMomentumTensor > &, const double)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_output (const GrandCanThermalizer &)
 Output to write energy-momentum tensor and related quantities from the thermalizer class. More...
 
virtual void fields_output (const std::string, const std::string, RectangularLattice< std::pair< ThreeVector, ThreeVector >> &)
 Write fields in vtk output Fields are a pair of threevectors for example electric and magnetic field. 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...
 
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 86 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 136 of file hepmcinterface.h.

◆ CollCounter

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

Counter of collitions per incoming particle.

Definition at line 138 of file hepmcinterface.h.

Member Enumeration Documentation

◆ Status

HepMC status codes.

Enumerator
beam 
fnal 
dcy 
off 

Definition at line 129 of file hepmcinterface.h.

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

Constructor & Destructor Documentation

◆ HepMcInterface()

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

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

Definition at line 23 of file hepmcinterface.cc.

24  : OutputInterface(name),
25  event_(HepMC3::Units::GEV, HepMC3::Units::MM),
26  ion_(),
27  xs_(),
28  ip_(),
29  full_event_(full_event) {
30  logg[LOutput].debug() << "Name of output: " << name << " "
31  << (full_event_ ? "full event" : "final state only")
32  << " output" << std::endl;
33  ion_ = std::make_shared<HepMC3::GenHeavyIon>();
34  ion_->set(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1.0, -1.0, -1.0, -1.0, -1.0,
35  -1.0);
36 
37  xs_ = std::make_shared<HepMC3::GenCrossSection>();
38  // GenRunInfo: HepMC3 class to store run-related information
39  std::shared_ptr<HepMC3::GenRunInfo> run_info =
40  std::make_shared<HepMC3::GenRunInfo>();
41  std::vector<std::string> weightnames;
42  weightnames.push_back("Default");
43  run_info->set_weight_names(weightnames);
44  HepMC3::GenRunInfo::ToolInfo tool;
45  tool.name = "SMASH";
46  tool.version = SMASH_VERSION;
47 #ifdef GIT_BRANCH
48  tool.version = tool.version + GIT_BRANCH;
49 #endif
50  tool.description = "";
51  run_info->tools().push_back(tool);
52  event_.set_run_info(run_info);
53  HepMC3::Setup::set_debug_level(logg[LOutput].isEnabled<einhard::DEBUG>() ? 5
54  : 0);
55 }
HepMC3::GenVertexPtr ip_
The interaction point.
bool full_event_
Whether the full event or only final-state particles are in the output.
HepMC3::GenEvent event_
The event.
HepMC3::GenHeavyIonPtr ion_
The heavy-ion structure.
HepMC3::GenCrossSectionPtr xs_
Dummy cross-section.
OutputInterface(std::string name)
Construct output interface.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
static constexpr int LOutput

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

Reimplemented from smash::OutputInterface.

Definition at line 57 of file hepmcinterface.cc.

59  {
60  // Clear event and mapping and set event number
61  clear();
62 
63  // Set header stuff on event
64  ion_->impact_parameter = event.impact_parameter;
65  xs_->set_cross_section(1, 1); // Dummy values
66  event_.set_event_number(event_number);
67  event_.set_heavy_ion(ion_);
68 
69  // Create IP only if final state
70  ip_ = std::make_shared<HepMC3::GenVertex>();
71  event_.add_vertex(ip_);
72 
73  // Count up projectile and target
74  smash::FourVector p_proj;
75  smash::FourVector p_targ;
76  AZ az_proj{0, 0};
77  AZ az_targ{0, 0};
78  bool is_coll = (event.impact_parameter >= 0.0);
79 
80  for (auto& data : particles) {
81  if (is_coll) {
82  if (!data.is_neutron() && !data.is_proton()) {
83  throw std::runtime_error(
84  "Particle of PID=" + std::to_string(data.pdgcode().get_decimal()) +
85  " is not a valid HepMC beam particle!");
86  }
87 
88  if (data.belongs_to() == BelongsTo::Projectile) {
89  p_proj += data.momentum();
90  az_proj.first++;
91  az_proj.second += data.type().charge();
92  } else if (data.belongs_to() == BelongsTo::Target) {
93  p_targ += data.momentum();
94  az_targ.first++;
95  az_targ.second += data.type().charge();
96  }
97  }
98 
99  if (!full_event_ && is_coll) {
100  continue;
101  }
102 
103  // If we are not only adding final state particles, but all
104  // interactions, or not in collider modus, then we add all the
105  // incoming particles as outgoing (incoming for non-collider
106  // modus) of the vertex. In that way, we will keep track of
107  // participants and spectators as well as make the event
108  // structure consistent.
109  auto op = make_register(data, Status::fnal);
110  if (is_coll) {
111  ip_->add_particle_out(op);
112  } else {
113  ip_->add_particle_in(op);
114  }
115  }
116 
117  coll_.resize(az_proj.first + az_targ.first);
118  // Make beam particles
119  if (is_coll) {
120  auto proj = make_gen(ion_pdg(az_proj), Status::beam, p_proj);
121  auto targ = make_gen(ion_pdg(az_targ), Status::beam, p_targ);
122 
123  // Add to interaction point if we need to
124  ip_->add_particle_in(proj);
125  ip_->add_particle_in(targ);
126  }
127 }
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
std::pair< int, int > AZ
Pair of Atomic weight and number.
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.
HepMC3::GenParticlePtr make_register(const ParticleData &p, int status=Status::fnal)
Find particle in mapping or generate it.
void clear()
Clear before an event.
CollCounter coll_
Collision counter.

◆ 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 129 of file hepmcinterface.cc.

130  {
131  HepMC3::GenVertexPtr vp;
132  auto type = action.get_type();
133  int status = get_status(type);
134 
135  if (full_event_) {
136  FourVector v = action.get_interaction_point();
137  vp = std::make_shared<HepMC3::GenVertex>(
138  HepMC3::FourVector(v.x1(), v.x2(), v.x3(), v.x0()));
139  event_.add_vertex(vp);
140  vp->add_attribute("weight", std::make_shared<HepMC3::FloatAttribute>(
141  action.get_total_weight()));
142  vp->add_attribute(
143  "partial_weight",
144  std::make_shared<HepMC3::FloatAttribute>(action.get_partial_weight()));
145  }
146 
147  // Now mark participants
148  if (full_event_) {
149  for (auto& i : action.incoming_particles()) {
150  // Create tree
151  HepMC3::GenParticlePtr ip = find_or_make(i, status);
152  ip->set_status(status);
153  vp->add_particle_in(ip);
154  }
155  } else {
156  return;
157  }
158 
159  // Add outgoing particles
160  for (auto& o : action.outgoing_particles()) {
161  vp->add_particle_out(make_register(o, Status::fnal));
162  }
163 }
int get_status(const ProcessType &t) const
Convert SMASH process type to HepMC status.
HepMC3::GenParticlePtr find_or_make(const ParticleData &p, int status=Status::fnal, bool force_new=false)
Find particle in mapping or generate it.

◆ 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 165 of file hepmcinterface.cc.

167  {
168  // We evaluate if it is a heavy ion collision event
169  bool is_coll = (event.impact_parameter >= 0.0);
170  // In case this was an empty event
171  if (event.empty_event && is_coll) {
172  clear();
173  return;
174  }
175  // Set the weights
176  event_.weights() = std::vector<double>(1, 1);
177  /* since the number of collisions is not an experimental obervable, we set it
178  * to -1.
179  */
180  ion_->Ncoll_hard = -1;
181  ion_->Ncoll = -1;
182  /* This should be the number of participants in the projectile nucleus.
183  * However, to avoid confusion with the Glauber model, we prefer to set it -1.
184  */
185  ion_->Npart_proj = -1;
186  /* This should be the number of participants in the target nucleus.
187  * However, to avoid confusion with the Glauber model, we prefer to set it -1.
188  */
189  ion_->Npart_targ = -1;
190  // If we only do final state events, then take particle
191  // Note, we should already have the particles if not only final
192  // state
193  // Take all passed particles and add as outgoing particles to event
194  for (auto& p : particles) {
195  if (!full_event_) {
196  auto h = make_register(p, Status::fnal);
197  ip_->add_particle_out(h);
198  } else if (map_.find(p.id()) == map_.end()) {
199  throw std::runtime_error("Dangling particle " + std::to_string(p.id()));
200  }
201  }
202 }
IdMap map_
Mapping from ID to particle.
constexpr int p
Proton.

◆ clear()

void smash::HepMcInterface::clear ( )
protected

Clear before an event.

Definition at line 204 of file hepmcinterface.cc.

204  {
205  event_.clear();
206  map_.clear();
207  ip_ = 0;
208  coll_ = 0;
209  ncoll_ = 0;
210  ncoll_hard_ = 0;
211 }
int ncoll_
counter of binary collisions (e.g., where both incoming particles are from the beams.
int ncoll_hard_
counter of hard binary collisions (e.g., where both incoming particles are from the beams.

◆ get_status()

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

Convert SMASH process type to HepMC status.

Definition at line 213 of file hepmcinterface.cc.

213  {
214  if (t == ProcessType::Decay)
215  return Status::dcy;
216 
217  // Make all other codes SMASH specific
218  return static_cast<int>(t) + static_cast<int>(Status::off);
219 }
@ Decay
See here for a short description.

◆ 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 221 of file hepmcinterface.cc.

223  {
224  auto p = std::make_shared<HepMC3::GenParticle>(
225  HepMC3::FourVector(mom.x1(), mom.x2(), mom.x3(), mom.x0()), pid, status);
226  if (mass > 0)
227  p->set_generated_mass(mass);
228  return p;
229 }
double x3() const
Definition: fourvector.h:325
double x2() const
Definition: fourvector.h:321
double x0() const
Definition: fourvector.h:313
double x1() const
Definition: fourvector.h:317

◆ 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 231 of file hepmcinterface.cc.

232  {
233  int id = p.id();
234  auto h = make_gen(p.pdgcode().get_decimal(), status, p.momentum(),
235  p.type().mass());
236  map_[id] = h;
237 
238  return h;
239 }

◆ 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 241 of file hepmcinterface.cc.

243  {
244  int id = p.id();
245  if (!force_new) {
246  auto it = map_.find(id);
247  if (it != map_.end()) {
248  return it->second;
249  }
250  }
251 
252  return make_register(p, status);
253 }

◆ 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 255 of file hepmcinterface.cc.

255  {
256  if (az.second == 1 && az.first == 1)
257  return 2212; // Proton
258  if (az.second == 1 && az.first == 0)
259  return 2112; // Neutron
260 
261  return 1000 * 1000 * 1000 + az.second * 10 * 1000 + az.first * 10;
262 }

Member Data Documentation

◆ event_

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

The event.

Definition at line 187 of file hepmcinterface.h.

◆ ion_

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

The heavy-ion structure.

Definition at line 189 of file hepmcinterface.h.

◆ xs_

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

Dummy cross-section.

Definition at line 191 of file hepmcinterface.h.

◆ ip_

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

The interaction point.

Definition at line 193 of file hepmcinterface.h.

◆ map_

IdMap smash::HepMcInterface::map_
protected

Mapping from ID to particle.

Definition at line 195 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 216 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 219 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 222 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 224 of file hepmcinterface.h.


The documentation for this class was generated from the following files: