Version: SMASH-2.0
smash::HepMcOutput Class Reference

#include <hepmcoutput.h>

SMASH output to HepMC file.

This class writes a vertex connecting all intial particles with all final particles into a HepMC outputfile. In collider mode, projectile and target are combined into single intial particles with a nuclear pdg code. The output file is a human-readable ASCII file. HepMC version 3 is used.

More details of the output format can be found in the User Guide.

Definition at line 41 of file hepmcoutput.h.

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

Public Member Functions

 HepMcOutput (const bf::path &path, std::string name, const OutputParameters &out_par, const int total_N, const int proj_N)
 Create HepMC particle output. More...
 
 ~HepMcOutput ()
 Destructor renames file. More...
 
void at_eventstart (const Particles &particles, const int event_number, const EventInfo &) override
 Add the initial particles information of an event to the central vertex. 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_interaction (const Action &action, const double density)
 Called whenever an action modified one or more particles. 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...
 

Private Member Functions

int construct_nuclear_pdg_code (int na, int nz) const
 Construct nulcear pdg code for porjectile and target, see PDG chapter "Monte Carlo particle numbering scheme" for details. More...
 

Private Attributes

const bf::path filename_
 Filename of output. More...
 
bf::path filename_unfinished_
 Filename of output as long as simulation is still running. 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...
 
std::unique_ptr< HepMC3::WriterAscii > output_file_
 Pointer to Ascii HepMC3 output file. More...
 
std::unique_ptr< HepMC3::GenEvent > current_event_
 HepMC3::GenEvent pointer for current event. More...
 
HepMC3::GenVertexPtr vertex_
 HepMC3::GenVertex pointer for central vertex in event. More...
 

Static Private Attributes

static const int status_code_for_beam_particles = 4
 HepMC convention: status code for target and projecticle particles. More...
 
static const int status_code_for_final_particles = 1
 HepMC convention: status code for final particles. More...
 

Additional Inherited Members

- 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...
 

Constructor & Destructor Documentation

◆ HepMcOutput()

smash::HepMcOutput::HepMcOutput ( const bf::path &  path,
std::string  name,
const OutputParameters out_par,
const int  total_N,
const int  proj_N 
)

Create HepMC particle output.

Parameters
[in]pathOutput path.
[in]nameName of the output.
[in]out_parUnused, needed since inhertied.
[in]total_NTotal number of particles in both nuclei.
[in]proj_NNumber of particles in projectile.

Definition at line 51 of file hepmcoutput.cc.

54  : OutputInterface(name),
55  filename_(path / (name + ".asciiv3")),
56  total_N_(total_N),
57  proj_N_(proj_N) {
59  filename_unfinished_ += +".unfinished";
60  output_file_ =
61  make_unique<HepMC3::WriterAscii>(filename_unfinished_.string());
62 }

◆ ~HepMcOutput()

smash::HepMcOutput::~HepMcOutput ( )

Destructor renames file.

Definition at line 64 of file hepmcoutput.cc.

64 { bf::rename(filename_unfinished_, filename_); }

Member Function Documentation

◆ at_eventstart()

void smash::HepMcOutput::at_eventstart ( const Particles particles,
const int  event_number,
const EventInfo  
)
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
Exceptions
std::invalid_argumentif nuclei with non-nucleon particle (like hypernuclei) are tried to be constructed

Implements smash::OutputInterface.

Definition at line 80 of file hepmcoutput.cc.

81  {
83  make_unique<HepMC3::GenEvent>(HepMC3::Units::GEV, HepMC3::Units::MM);
84 
85  /* Rivet needs a value for the cross section, but SMASH only knows about
86  * nucleon cross sections, not about cross sections between nuclei,
87  * so a dummy is used. */
88  std::shared_ptr<HepMC3::GenCrossSection> cross_section =
89  std::make_shared<HepMC3::GenCrossSection>();
90  current_event_->add_attribute("GenCrossSection", cross_section);
91  const double dummy_xs = 1.0;
92  cross_section->set_cross_section(dummy_xs, dummy_xs);
93 
94  current_event_->set_event_number(event_number);
95  vertex_ = std::make_shared<HepMC3::GenVertex>();
96  current_event_->add_vertex(vertex_);
97 
98  if (proj_N_ > 0) {
99  // Collider modus: Construct and write projectile and target as two intial
100  // particles
101  int targ_N = total_N_ - proj_N_;
102  int proj_Z = 0;
103  int targ_Z = 0;
104  FourVector total_mom_proj;
105  FourVector total_mom_targ;
106  for (const ParticleData &data : particles) {
107  if (data.id() < proj_N_) {
108  total_mom_proj += data.momentum();
109  if (data.is_proton()) {
110  proj_Z += 1;
111  } else if (!data.is_neutron()) {
112  throw std::invalid_argument(
113  "HepMC output in SMASH only supports colliding nuclei consisting "
114  "of p and n.");
115  }
116  } else {
117  total_mom_targ += data.momentum();
118  if (data.is_proton()) {
119  targ_Z += 1;
120  } else if (!data.is_neutron()) {
121  throw std::invalid_argument(
122  "HepMC output in SMASH only supports colliding nuclei consisting "
123  "of p and n.");
124  }
125  }
126  }
127 
128  const int proj_nuclear_pdg_code =
130  const int targ_nuclear_pdg_code =
131  construct_nuclear_pdg_code(targ_N, targ_Z);
132 
133  HepMC3::GenParticlePtr projectile_p = std::make_shared<HepMC3::GenParticle>(
134  HepMC3::FourVector(total_mom_proj.x1(), total_mom_proj.x2(),
135  total_mom_proj.x3(), total_mom_proj.x0()),
136  proj_nuclear_pdg_code, status_code_for_beam_particles);
137  vertex_->add_particle_in(projectile_p);
138  HepMC3::GenParticlePtr target_p = std::make_shared<HepMC3::GenParticle>(
139  HepMC3::FourVector(total_mom_targ.x1(), total_mom_targ.x2(),
140  total_mom_targ.x3(), total_mom_targ.x0()),
141  targ_nuclear_pdg_code, status_code_for_beam_particles);
142  vertex_->add_particle_in(target_p);
143 
144  } else {
145  // Other modi (not collider): Write all inital particles into output
146  for (const ParticleData &data : particles) {
147  const FourVector mom = data.momentum();
148  HepMC3::GenParticlePtr p = std::make_shared<HepMC3::GenParticle>(
149  HepMC3::FourVector(mom.x1(), mom.x2(), mom.x3(), mom.x0()),
150  data.pdgcode().get_decimal(), status_code_for_beam_particles);
151  vertex_->add_particle_in(p);
152  }
153  }
154 }
Here is the call graph for this function:

◆ at_eventend()

void smash::HepMcOutput::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 156 of file hepmcoutput.cc.

158  {
159  // Set heavy ion attribute, only the impact parameter is known
160  std::shared_ptr<HepMC3::GenHeavyIon> heavy_ion =
161  std::make_shared<HepMC3::GenHeavyIon>();
162  current_event_->add_attribute("GenHeavyIon", heavy_ion);
163  // Impact paramter has to converted to mm (x1E-12), since fm not a supported
164  // unit in HepMC, -1(.0) are placeholders
165  heavy_ion->set(-1, -1, -1, -1, -1, -1, -1, -1, -1,
166  event.impact_parameter * 1E-12, -1.0, -1.0, -1.0, -1.0, -1.0);
167 
168  for (const ParticleData &data : particles) {
169  const FourVector mom = data.momentum();
170  HepMC3::GenParticlePtr p = std::make_shared<HepMC3::GenParticle>(
171  HepMC3::FourVector(mom.x1(), mom.x2(), mom.x3(), mom.x0()),
172  data.pdgcode().get_decimal(), status_code_for_final_particles);
173  vertex_->add_particle_out(p);
174  }
175 
176  output_file_->write_event(*current_event_);
177 }
Here is the call graph for this function:

◆ construct_nuclear_pdg_code()

int smash::HepMcOutput::construct_nuclear_pdg_code ( int  na,
int  nz 
) const
private

Construct nulcear pdg code for porjectile and target, see PDG chapter "Monte Carlo particle numbering scheme" for details.

Parameters
[in]naNumber of all particles in nucleus (A)
[in]nzNumber of all charged particles in nucleus (Z).

Note: Isomers and hypernuclei are not supported. Also note that one would usually create a PdgCode object to store the PDG code of the nuclei. This PdgCode object however would be first constructed with the integer determined here and then directly returned again with a method of the PdgCode class, making the creation of a PdgCode class instance overkill. A possible improvement would be the inclusion of this function in the PdgCode class.

Definition at line 66 of file hepmcoutput.cc.

66  {
67  const int pdg_nuclear_code_prefix = 10 * 1E8;
68  // Hypernuclei not supported here
69  const int pdg_nuclear_code_lambda = 0 * 1E7;
70  const int pdg_nuclear_code_charge = nz * 1E4;
71  const int pdg_nuclear_code_baryon = na * 1E1;
72  // SMASH does not do isomers
73  const int pdg_nuclear_code_isomer = 0 * 1E0;
74 
75  return pdg_nuclear_code_prefix + pdg_nuclear_code_lambda +
76  pdg_nuclear_code_charge + pdg_nuclear_code_baryon +
77  pdg_nuclear_code_isomer;
78 }
Here is the caller graph for this function:

Member Data Documentation

◆ status_code_for_beam_particles

const int smash::HepMcOutput::status_code_for_beam_particles = 4
staticprivate

HepMC convention: status code for target and projecticle particles.

Definition at line 84 of file hepmcoutput.h.

◆ status_code_for_final_particles

const int smash::HepMcOutput::status_code_for_final_particles = 1
staticprivate

HepMC convention: status code for final particles.

Definition at line 86 of file hepmcoutput.h.

◆ filename_

const bf::path smash::HepMcOutput::filename_
private

Filename of output.

Definition at line 89 of file hepmcoutput.h.

◆ filename_unfinished_

bf::path smash::HepMcOutput::filename_unfinished_
private

Filename of output as long as simulation is still running.

Definition at line 91 of file hepmcoutput.h.

◆ total_N_

const int smash::HepMcOutput::total_N_
private

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

Definition at line 97 of file hepmcoutput.h.

◆ proj_N_

const int smash::HepMcOutput::proj_N_
private

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

Definition at line 102 of file hepmcoutput.h.

◆ output_file_

std::unique_ptr<HepMC3::WriterAscii> smash::HepMcOutput::output_file_
private

Pointer to Ascii HepMC3 output file.

Definition at line 122 of file hepmcoutput.h.

◆ current_event_

std::unique_ptr<HepMC3::GenEvent> smash::HepMcOutput::current_event_
private

HepMC3::GenEvent pointer for current event.

Definition at line 125 of file hepmcoutput.h.

◆ vertex_

HepMC3::GenVertexPtr smash::HepMcOutput::vertex_
private

HepMC3::GenVertex pointer for central vertex in event.

Definition at line 128 of file hepmcoutput.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:71
smash::HepMcOutput::proj_N_
const int proj_N_
Total number of nucleons in projectile, needed for converting nuclei to single particles.
Definition: hepmcoutput.h:102
smash::HepMcOutput::total_N_
const int total_N_
Total number of nucleons in projectile and target, needed for converting nuclei to single particles.
Definition: hepmcoutput.h:97
smash::HepMcOutput::filename_unfinished_
bf::path filename_unfinished_
Filename of output as long as simulation is still running.
Definition: hepmcoutput.h:91
smash::HepMcOutput::output_file_
std::unique_ptr< HepMC3::WriterAscii > output_file_
Pointer to Ascii HepMC3 output file.
Definition: hepmcoutput.h:122
smash::HepMcOutput::status_code_for_beam_particles
static const int status_code_for_beam_particles
HepMC convention: status code for target and projecticle particles.
Definition: hepmcoutput.h:84
smash::HepMcOutput::current_event_
std::unique_ptr< HepMC3::GenEvent > current_event_
HepMC3::GenEvent pointer for current event.
Definition: hepmcoutput.h:125
smash::HepMcOutput::status_code_for_final_particles
static const int status_code_for_final_particles
HepMC convention: status code for final particles.
Definition: hepmcoutput.h:86
smash::HepMcOutput::vertex_
HepMC3::GenVertexPtr vertex_
HepMC3::GenVertex pointer for central vertex in event.
Definition: hepmcoutput.h:128
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::HepMcOutput::construct_nuclear_pdg_code
int construct_nuclear_pdg_code(int na, int nz) const
Construct nulcear pdg code for porjectile and target, see PDG chapter "Monte Carlo particle numbering...
Definition: hepmcoutput.cc:66
smash::HepMcOutput::filename_
const bf::path filename_
Filename of output.
Definition: hepmcoutput.h:89