Thermal-FIST 1.5
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
SimpleEvent.cpp
Go to the documentation of this file.
1/*
2 * Thermal-FIST package
3 *
4 * Copyright (c) 2015-2019 Volodymyr Vovchenko
5 *
6 * GNU General Public License (GPLv3 or later)
7 */
9
10#include <iomanip>
11
12namespace thermalfist {
13
14 void SimpleEvent::writeToFile(std::ofstream& fout, const EventOutputConfig& config, int eventnumber) const
15 {
16 fout << "Event " << eventnumber << std::endl;
17
18 if (config.printWeight)
19 fout << "Weight: " << weight << std::endl;
20
21 fout << std::setw(20) << "pdgid";
22
23 if (config.printCoordinates)
24 fout << std::setw(20) << "r0[fm/c]"
25 << std::setw(20) << "rx[fm]"
26 << std::setw(20) << "ry[fm]"
27 << std::setw(20) << "rz[fm]";
28
29 if (config.printEnergy)
30 fout << std::setw(20) << "p0[GeV/c2]";
31
32 fout << std::setw(20) << "px[GeV/c]"
33 << std::setw(20) << "py[GeV/c]"
34 << std::setw(20) << "pz[GeV/c]";
35
36 if (config.printMotherPdg)
37 fout << std::setw(20) << "mother_pdgid";
38
39 if (config.printDecayEpoch)
40 fout << std::setw(20) << "decay_epoch";
41
42 fout << std::endl;
43
44 fout.precision(10);
45 fout << std::scientific;
46
47 for (size_t i = 0; i < Particles.size(); ++i) {
48 fout << std::setw(20) << Particles[i].PDGID;
49
50 if (config.printCoordinates)
51 fout << std::setw(20) << Particles[i].r0
52 << std::setw(20) << Particles[i].rx
53 << std::setw(20) << Particles[i].ry
54 << std::setw(20) << Particles[i].rz;
55
56
57 if (config.printEnergy)
58 fout << std::setw(20) << Particles[i].p0;
59
60 fout << std::setw(20) << Particles[i].px
61 << std::setw(20) << Particles[i].py
62 << std::setw(20) << Particles[i].pz;
63
64 if (config.printMotherPdg)
65 fout << std::setw(20) << Particles[i].MotherPDGID;
66
67 if (config.printDecayEpoch)
68 fout << std::setw(20) << Particles[i].epoch;
69
70 fout << std::endl;
71 }
72
73
74 if (config.printPhotonsLeptons) {
75 for (size_t i = 0; i < PhotonsLeptons.size(); ++i) {
76 fout << std::setw(20) << PhotonsLeptons[i].PDGID;
77
78 if (config.printCoordinates)
79 fout << std::setw(20) << PhotonsLeptons[i].r0
80 << std::setw(20) << PhotonsLeptons[i].rx
81 << std::setw(20) << PhotonsLeptons[i].ry
82 << std::setw(20) << PhotonsLeptons[i].rz;
83
84 if (config.printEnergy)
85 fout << std::setw(20) << PhotonsLeptons[i].p0;
86
87 fout << std::setw(20) << PhotonsLeptons[i].px
88 << std::setw(20) << PhotonsLeptons[i].py
89 << std::setw(20) << PhotonsLeptons[i].pz;
90
91
92 if (config.printMotherPdg)
93 fout << std::setw(20) << PhotonsLeptons[i].MotherPDGID;
94
95 if (config.printDecayEpoch)
96 fout << std::setw(20) << PhotonsLeptons[i].epoch;
97
98 fout << std::endl;
99 }
100 }
101 fout << std::endl;
102 fout << std::fixed;
103 }
104
105 void SimpleEvent::writeToFileForUrqmd(std::ofstream& fout) const
106 {
107 fout << "# " << Particles.size() << std::endl;
108
109 fout.precision(16);
110 fout << std::scientific;
111
112 const int tabsize = 23;
113
114 for (size_t i = 0; i < Particles.size(); ++i) {
115 fout << std::setw(12) << Particles[i].PDGID << " ";
116
117 fout << std::setw(tabsize) << Particles[i].r0 << " "
118 << std::setw(tabsize) << Particles[i].rx << " "
119 << std::setw(tabsize) << Particles[i].ry << " "
120 << std::setw(tabsize) << Particles[i].rz << " ";
121
122
123 fout << std::setw(tabsize) << Particles[i].p0 << " ";
124 fout << std::setw(tabsize) << Particles[i].px << " "
125 << std::setw(tabsize) << Particles[i].py << " "
126 << std::setw(tabsize) << Particles[i].pz << " ";
127
128 fout << std::endl;
129 }
130
131 fout << std::fixed;
132 }
133
134 void SimpleEvent::writeToFileForSmash(std::ofstream& fout, const ThermalParticleSystem *m_TPS, const int eventnumber) const
135 {
136 int eventnumber_smash = eventnumber -1;
137 if (eventnumber_smash == 0) {
138 fout << "#!OSCAR2013 particle_lists t x y z mass p0 px py pz pdg ID charge" << std::endl;
139 fout << "# Units: fm fm fm fm GeV GeV GeV GeV GeV none none e" << std::endl;
140 fout << "# FISTSampler" << std::endl;
141 }
142
143 fout << "# event "<< eventnumber_smash << " out " << Particles.size() << std::endl;
144
145 fout.precision(10);
146 // fout << std::scientific;
147
148 const int tabsize = 4;
149 int charge;
150
151 // t x y z mass p0 px py pz pdg ID charge
152 for (size_t i = 0; i < Particles.size(); ++i) {
153 if (m_TPS != NULL){
154 charge = m_TPS->ParticleByPDG(Particles[i].PDGID).ElectricCharge();
155 }
156 else{
157 charge = 0;
158 }
159 fout << Particles[i].r0 << " "
160 << Particles[i].rx << " "
161 << Particles[i].ry << " "
162 << Particles[i].rz << " "
163 << Particles[i].m << " "
164 << Particles[i].p0 << " "
165 << Particles[i].px << " "
166 << Particles[i].py << " "
167 << Particles[i].pz << " "
168 << Particles[i].PDGID << " "
169 << i << " "
170 << charge;
171 fout << std::endl;
172 }
173 fout << "# event "<< eventnumber_smash <<" end 0 impact 0.000 scattering_projectile_target yes" << std::endl;
174 fout << std::fixed;
175 }
176
178 {
179 for (size_t i = 0; i < Particles.size(); ++i)
181 for (size_t i = 0; i < AllParticles.size(); ++i)
183 }
184
186 {
187 SimpleEvent ret;
188 ret.Particles.reserve(evt1.Particles.size() + evt2.Particles.size());
189 ret.Particles.insert(ret.Particles.end(), evt1.Particles.begin(), evt1.Particles.end());
190 ret.Particles.insert(ret.Particles.end(), evt2.Particles.begin(), evt2.Particles.end());
191
192 ret.AllParticles.reserve(evt1.AllParticles.size() + evt2.AllParticles.size());
193 ret.AllParticles.insert(ret.AllParticles.end(), evt1.AllParticles.begin(), evt1.AllParticles.end());
194 ret.AllParticles.insert(ret.AllParticles.end(), evt2.AllParticles.begin(), evt2.AllParticles.end());
195
196 ret.DecayMap.reserve(evt1.DecayMap.size() + evt2.DecayMap.size());
197 ret.DecayMap.insert(ret.DecayMap.end(), evt1.DecayMap.begin(), evt1.DecayMap.end());
198 ret.DecayMap.insert(ret.DecayMap.end(), evt2.DecayMap.begin(), evt2.DecayMap.end());
199 int offset = evt1.DecayMap.size();
200 for (int i = evt1.DecayMap.size(); i < ret.DecayMap.size(); i++)
201 if (ret.DecayMap[i] != -1)
202 ret.DecayMap[i] += offset;
203
204 ret.DecayMapFinal.reserve(evt1.DecayMapFinal.size() + evt2.DecayMapFinal.size());
205 ret.DecayMapFinal.insert(ret.DecayMapFinal.end(), evt1.DecayMapFinal.begin(), evt1.DecayMapFinal.end());
206 ret.DecayMapFinal.insert(ret.DecayMapFinal.end(), evt2.DecayMapFinal.begin(), evt2.DecayMapFinal.end());
207 for (int i = evt1.DecayMapFinal.size(); i < ret.DecayMapFinal.size(); i++)
208 ret.DecayMapFinal[i] += offset;
209
210 // TODO: check if proper to combine weights like that
211 ret.weight = evt1.weight * evt2.weight;
212 ret.logweight = evt1.logweight + evt2.logweight;
213
214 return ret;
215 }
216
217} // namespace thermalfist
int ElectricCharge() const
Particle's electric charge.
Class containing the particle list.
const ThermalParticle & ParticleByPDG(long long pdgid) const
ThermalParticle object corresponding to particle species with a provided PDG ID.
The main namespace where all classes and functions of the Thermal-FIST library reside.
Definition CosmicEoS.h:9
Configuration for the event output.
Definition SimpleEvent.h:53
bool printCoordinates
Print the space-time coordinates of the particles.
Definition SimpleEvent.h:68
bool printDecayEpoch
Print the number of successive decays before the particle was produced.
Definition SimpleEvent.h:65
bool printWeight
Print the event weight for importance sampling.
Definition SimpleEvent.h:71
bool printMotherPdg
Output the pdg code of the mother particle.
Definition SimpleEvent.h:59
bool printPhotonsLeptons
Output photons and leptons, if any.
Definition SimpleEvent.h:62
bool printEnergy
Output the particle's energy in addition to its 3-momentum.
Definition SimpleEvent.h:56
static SimpleEvent MergeEvents(const SimpleEvent &evt1, const SimpleEvent &evt2)
Merge particles from two events (e.g. two patches, two canonical volumes, etc.)
SimpleEvent()
Default constructor, empty event.
Definition SimpleEvent.h:44
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
double logweight
Log of the event weight factor.
Definition SimpleEvent.h:25
std::vector< SimpleParticle > AllParticles
Vector of all particles which ever appeared in the event (including those that decay and photons/lept...
Definition SimpleEvent.h:31
void RapidityBoost(double dY)
Rapidity boost by Y -> Y + dY for all particles.
std::vector< int > DecayMap
Definition SimpleEvent.h:38
std::vector< SimpleParticle > PhotonsLeptons
Vector of all decay photons/leptons.
Definition SimpleEvent.h:34
std::vector< int > DecayMapFinal
Vector for each Particles element pointing to the index of the primordial resonance from which this p...
Definition SimpleEvent.h:41
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.