Thermal-FIST 1.6
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
EventWriter.cpp
Go to the documentation of this file.
2
3#include <string>
4#include <iostream>
5#include <iomanip>
6
7#include "ThermalFISTConfig.h"
8
9namespace thermalfist {
10
11 EventWriter::EventWriter(const std::string& filename)
12 {
13 if (!filename.empty())
14 OpenFile(filename);
15 }
16
21
22 bool EventWriter::OpenFile(const std::string& filename)
23 {
24 if (m_fout.is_open())
25 m_fout.close();
26
27 m_fout.open(filename);
28
29 if (!m_fout.is_open()) {
30 std::cerr << "**ERROR** EventWriter::OpenFile(): Could not open file " << filename << std::endl;
31 return false;
32 }
33
34 m_EventNumber = 0;
35
36 return true;
37 }
38
40 {
41 if (m_fout.is_open()) {
42 m_fout.close();
43 }
44 }
45
47 {
48 if (!m_fout.is_open())
49 return false;
50
51 if (evt.weight != 1.0) {
52 std::cout << "**WARNING** Writing a weighted event to a file. The information about the weight will be lost!" << std::endl;
53 }
54
55 m_fout << "Event " << ++m_EventNumber << std::endl;
56
57 const int tabsize = 25;
58
59 m_fout.precision(16);
60 m_fout << std::scientific;
61
62 m_fout << std::setw(tabsize) << "pdgid";
63
64 m_fout << std::setw(tabsize) << "p0[GeV/c2]";
65
66 m_fout << std::setw(tabsize) << "px[GeV/c]"
67 << std::setw(tabsize) << "py[GeV/c]"
68 << std::setw(tabsize) << "pz[GeV/c]";
69
70 m_fout << std::endl;
71
72 for (size_t i = 0; i < evt.Particles.size(); ++i) {
73 const SimpleParticle& part = evt.Particles[i];
74
75 m_fout << std::setw(tabsize) << part.PDGID;
76
77 m_fout << std::setw(tabsize) << part.p0;
78
79 m_fout << std::setw(tabsize) << part.px
80 << std::setw(tabsize) << part.py
81 << std::setw(tabsize) << part.pz;
82
83 m_fout << std::endl;
84 }
85
86 return true;
87 }
88
90 {
91 if (!m_fout.is_open())
92 return false;
94 evt.writeToFile(m_fout, m_config, m_EventNumber);
95 return true;
96 }
97
99 {
100 if (!m_fout.is_open())
101 return false;
104 return true;
105 }
106
108 {
109 if (!m_fout.is_open())
110 return false;
113 return true;
114 }
115
116}
bool WriteEvent(const SimpleEvent &evt)
bool WriteEvent(const SimpleEvent &evt)
bool WriteEvent(const SimpleEvent &evt)
virtual bool WriteEvent(const SimpleEvent &evt)
EventWriter(const std::string &filename="")
virtual bool OpenFile(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
void writeToFileForUrqmd(std::ofstream &fout) const
Writes the event in a format suitable for UrQMD afterburner, as described here https://github....
void writeToFileForSmash(std::ofstream &fout, const thermalfist::ThermalParticleSystem *TPS=NULL, const int eventnumber=1) const
Writes the event in a format suitable for SMASH afterburner.
void writeToFile(std::ofstream &fout, const EventOutputConfig &config=EventOutputConfig(), int eventnumber=1) const
Writes the event to an output file stream.
Structure holding information about a single particle in the event generator.
double p0
Energy (in GeV)
double pz
3-momentum components (in GeV)