Thermal-FIST 1.6
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
HepMCEventWriter.cpp
Go to the documentation of this file.
2
3#include <string>
4#include <iostream>
5
6#include "ThermalFISTConfig.h"
7
8namespace thermalfist {
9
10 HepMCEventWriter::HepMCEventWriter(const std::string& filename)
11 {
12 if (!filename.empty())
13 OpenFile(filename);
14 }
15
20
21 bool HepMCEventWriter::OpenFile(const std::string& filename)
22 {
23 if (!EventWriter::OpenFile(filename))
24 return false;
25
26 m_fout << std::scientific;
27 m_fout.precision(16);
28
29 if (!m_fout.is_open())
30 return false;
31
32 const std::string header = "HepMC::Version " + std::string("3.01.01") + "\nHepMC::Asciiv3-START_EVENT_LISTING\n";
33 m_fout << header;
34
35 m_fout << "W " << 1 << "\n";
36 m_fout << "N " << "ImportanceSamplingWeight" << "\n";
37
38 std::string version = std::to_string(ThermalFIST_VERSION_MAJOR) + "." + std::to_string(ThermalFIST_VERSION_MINOR);
39 if (ThermalFIST_VERSION_DEVEL != 0) {
40 version += "." + std::to_string(ThermalFIST_VERSION_DEVEL);
41 }
42 m_fout << "T " << "Thermal-FIST" << "\\|";
43 m_fout << version << "\\|";
44 m_fout << "ThermalFistEventGenerator" << "\n";
45
46 return true;
47 }
48
50 {
51 if (m_fout.is_open()) {
52 const std::string footer("HepMC::Asciiv3-END_EVENT_LISTING\n\n");
53 m_fout << footer;
54 m_fout.close();
55 }
56 }
57
59 {
60 if (!m_fout.is_open())
61 return false;
62
63 m_fout << "E " << m_EventNumber++ << " " << 0 << " " << evt.Particles.size() << "\n";
64 m_fout << "U " << "GEV" << " " << "MM" << "\n";
65 m_fout << "W " << evt.weight << "\n";
66
67 for (int ip = 0; ip < evt.Particles.size(); ++ip) {
68 const SimpleParticle& part = evt.Particles[ip];
69 m_fout << "P " << ip + 1 << " " << 0 << " ";
70
71 m_fout << part.PDGID << " ";
72 m_fout << part.px << " " << part.py << " " << part.pz << " " << part.p0 << " ";
73 m_fout << part.m << " ";
74
75 m_fout << 1 << "\n";
76 }
77
78 return true;
79 }
80
81}
virtual bool OpenFile(const std::string &filename)
virtual bool WriteEvent(const SimpleEvent &evt)
virtual bool OpenFile(const std::string &filename)
HepMCEventWriter(const std::string &filename="")
The main namespace where all classes and functions of the Thermal-FIST library reside.
Definition CosmicEoS.h:9
Structure holding information about a single event in the event generator.
Definition SimpleEvent.h:20
double weight
Event weight factor.
Definition SimpleEvent.h:22
std::vector< SimpleParticle > Particles
Vector of all final particles in the event.
Definition SimpleEvent.h:28
Structure holding information about a single particle in the event generator.
double p0
Energy (in GeV)
double pz
3-momentum components (in GeV)