Thermal-FIST
1.6
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
src
library
HRGEventGenerator
EventWriter.cpp
Go to the documentation of this file.
1
#include "
HRGEventGenerator/EventWriter.h
"
2
3
#include <string>
4
#include <iostream>
5
#include <iomanip>
6
7
#include "ThermalFISTConfig.h"
8
9
namespace
thermalfist
{
10
11
EventWriter::EventWriter
(
const
std::string& filename)
12
{
13
if
(!filename.empty())
14
OpenFile
(filename);
15
}
16
17
EventWriter::~EventWriter
()
18
{
19
CloseFile
();
20
}
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
39
void
EventWriter::CloseFile
()
40
{
41
if
(
m_fout
.is_open()) {
42
m_fout
.close();
43
}
44
}
45
46
bool
EventWriter::WriteEvent
(
const
SimpleEvent
& evt)
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
89
bool
EventWriterAsciiExtended::WriteEvent
(
const
SimpleEvent
& evt)
90
{
91
if
(!
m_fout
.is_open())
92
return
false
;
93
++
m_EventNumber
;
94
evt.
writeToFile
(
m_fout
, m_config,
m_EventNumber
);
95
return
true
;
96
}
97
98
bool
EventWriterForUrqmd::WriteEvent
(
const
SimpleEvent
& evt)
99
{
100
if
(!
m_fout
.is_open())
101
return
false
;
102
++
m_EventNumber
;
103
evt.
writeToFileForUrqmd
(
m_fout
);
104
return
true
;
105
}
106
107
bool
EventWriterForSmash::WriteEvent
(
const
SimpleEvent
& evt)
108
{
109
if
(!
m_fout
.is_open())
110
return
false
;
111
++
m_EventNumber
;
112
evt.
writeToFileForSmash
(
m_fout
, m_TPS,
m_EventNumber
);
113
return
true
;
114
}
115
116
}
EventWriter.h
thermalfist::EventWriterAsciiExtended::WriteEvent
bool WriteEvent(const SimpleEvent &evt)
Definition
EventWriter.cpp:89
thermalfist::EventWriterForSmash::WriteEvent
bool WriteEvent(const SimpleEvent &evt)
Definition
EventWriter.cpp:107
thermalfist::EventWriterForUrqmd::WriteEvent
bool WriteEvent(const SimpleEvent &evt)
Definition
EventWriter.cpp:98
thermalfist::EventWriter::CloseFile
virtual void CloseFile()
Definition
EventWriter.cpp:39
thermalfist::EventWriter::m_fout
std::ofstream m_fout
Definition
EventWriter.h:33
thermalfist::EventWriter::~EventWriter
virtual ~EventWriter()
Definition
EventWriter.cpp:17
thermalfist::EventWriter::WriteEvent
virtual bool WriteEvent(const SimpleEvent &evt)
Definition
EventWriter.cpp:46
thermalfist::EventWriter::EventWriter
EventWriter(const std::string &filename="")
Definition
EventWriter.cpp:11
thermalfist::EventWriter::OpenFile
virtual bool OpenFile(const std::string &filename)
Definition
EventWriter.cpp:22
thermalfist::EventWriter::m_EventNumber
int m_EventNumber
Definition
EventWriter.h:34
thermalfist
The main namespace where all classes and functions of the Thermal-FIST library reside.
Definition
CosmicEoS.h:9
thermalfist::SimpleEvent
Structure holding information about a single event in the event generator.
Definition
SimpleEvent.h:20
thermalfist::SimpleEvent::weight
double weight
Event weight factor.
Definition
SimpleEvent.h:22
thermalfist::SimpleEvent::Particles
std::vector< SimpleParticle > Particles
Vector of all final particles in the event.
Definition
SimpleEvent.h:28
thermalfist::SimpleEvent::writeToFileForUrqmd
void writeToFileForUrqmd(std::ofstream &fout) const
Writes the event in a format suitable for UrQMD afterburner, as described here https://github....
Definition
SimpleEvent.cpp:105
thermalfist::SimpleEvent::writeToFileForSmash
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.
Definition
SimpleEvent.cpp:134
thermalfist::SimpleEvent::writeToFile
void writeToFile(std::ofstream &fout, const EventOutputConfig &config=EventOutputConfig(), int eventnumber=1) const
Writes the event to an output file stream.
Definition
SimpleEvent.cpp:14
thermalfist::SimpleParticle
Structure holding information about a single particle in the event generator.
Definition
SimpleParticle.h:15
thermalfist::SimpleParticle::PDGID
long long PDGID
PDG code.
Definition
SimpleParticle.h:19
thermalfist::SimpleParticle::py
double py
Definition
SimpleParticle.h:16
thermalfist::SimpleParticle::p0
double p0
Energy (in GeV)
Definition
SimpleParticle.h:18
thermalfist::SimpleParticle::pz
double pz
3-momentum components (in GeV)
Definition
SimpleParticle.h:16
thermalfist::SimpleParticle::px
double px
Definition
SimpleParticle.h:16
Generated by
1.13.2