Version: SMASH-3.1
icoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2019-2020,2022-2023
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/icoutput.h"
11 
12 #include <filesystem>
13 #include <fstream>
14 
15 #include "smash/action.h"
16 
17 namespace smash {
18 static constexpr int LHyperSurfaceCrossing = LogArea::HyperSurfaceCrossing::id;
19 
101 ICOutput::ICOutput(const std::filesystem::path &path, const std::string &name,
102  const OutputParameters &out_par)
103  : OutputInterface(name),
104  file_{path / "SMASH_IC.dat", "w"},
105  out_par_(out_par) {
106  std::fprintf(
107  file_.get(),
108  "# %s initial conditions: hypersurface of constant proper time\n",
109  SMASH_VERSION);
110  std::fprintf(file_.get(),
111  "# tau x y eta mt px py Rap pdg charge "
112  "baryon_number strangeness\n");
113  std::fprintf(file_.get(),
114  "# fm fm fm none GeV GeV GeV none none e "
115  "none none\n");
116 }
117 
119 
120 void ICOutput::at_eventstart(const Particles &, const int event_number,
121  const EventInfo &) {
122  std::fprintf(file_.get(), "# event %i start\n", event_number);
123 }
124 
125 void ICOutput::at_eventend(const Particles &particles, const int event_number,
126  const EventInfo &event) {
127  std::fprintf(file_.get(), "# event %i end\n", event_number);
128 
129  // If the runtime is too short some particles might not yet have
130  // reached the hypersurface. Warning is printed.
131  if (particles.size() != 0 && !event.impose_kinematic_cut_for_SMASH_IC) {
133  "End time might be too small for initial conditions output. "
134  "Hypersurface has not yet been crossed by ",
135  particles.size(), " particle(s).");
136  }
137 }
138 
140  const std::unique_ptr<Clock> &,
141  const DensityParameters &,
142  const EventInfo &) {
143  // Dummy, but virtual function needs to be declared.
144 }
145 
146 void ICOutput::at_interaction(const Action &action, const double) {
147  assert(action.get_type() == ProcessType::HyperSurfaceCrossing);
148  assert(action.incoming_particles().size() == 1);
149 
150  ParticleData particle = action.incoming_particles()[0];
151 
152  // transverse mass
153  const double m_trans =
154  std::sqrt(particle.effective_mass() * particle.effective_mass() +
155  particle.momentum()[1] * particle.momentum()[1] +
156  particle.momentum()[2] * particle.momentum()[2]);
157  // momentum space rapidity
158  const double rapidity =
159  0.5 * std::log((particle.momentum()[0] + particle.momentum()[3]) /
160  (particle.momentum()[0] - particle.momentum()[3]));
161 
162  // Determine if particle is spectator:
163  // Fulfilled if particle is initial nucleon, aka has no prior interactions
164  bool is_spectator = particle.get_history().collisions_per_particle == 0;
165 
166  // write particle data excluding spectators
167  if (!is_spectator) {
168  std::fprintf(file_.get(), "%g %g %g %g %g %g %g %g %s %i %i %i \n",
169  particle.position().tau(), particle.position()[1],
170  particle.position()[2], particle.position().eta(), m_trans,
171  particle.momentum()[1], particle.momentum()[2], rapidity,
172  particle.pdgcode().string().c_str(), particle.type().charge(),
173  particle.type().baryon_number(),
174  particle.type().strangeness());
175  }
176 
177  if (IC_proper_time_ < 0.0) {
178  // First particle that is removed, overwrite negative default
179  IC_proper_time_ = particle.position().tau();
180  } else {
181  // Verify that all other particles have the same proper time
182  const double next_proper_time = particle.position().tau();
183  if (!((next_proper_time - IC_proper_time_) < really_small))
184  throw std::runtime_error(
185  "Hypersurface proper time changed during evolution.");
186  }
187 }
188 
189 } // namespace smash
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:35
virtual ProcessType get_type() const
Get the process type.
Definition: action.h:131
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:58
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:108
double eta() const
calculate the space-time rapidity from the given four vector
Definition: fourvector.h:482
double tau() const
calculate the proper time from the given four vector
Definition: fourvector.h:478
RenamingFilePtr file_
Pointer to output file.
Definition: icoutput.h:75
ICOutput(const std::filesystem::path &path, const std::string &name, const OutputParameters &out_par)
Create a new IC output.
Definition: icoutput.cc:101
double IC_proper_time_
Proper time of the particles removed when extracting initial conditions.
Definition: icoutput.h:88
void at_eventend(const Particles &particles, const int event_number, const EventInfo &event) override
Write event end line.
Definition: icoutput.cc:125
void at_interaction(const Action &action, const double) override
Write particle data at the hypersurface crossing point to the IC output.
Definition: icoutput.cc:146
void at_eventstart(const Particles &, const int event_number, const EventInfo &) override
Write event start line.
Definition: icoutput.cc:120
void at_intermediate_time(const Particles &, const std::unique_ptr< Clock > &, const DensityParameters &, const EventInfo &) override
Unused, but needed since virtually declared in mother class.
Definition: icoutput.cc:139
Abstraction of generic output.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:58
PdgCode pdgcode() const
Get the pdgcode of the particle.
Definition: particledata.h:87
const ParticleType & type() const
Get the type of the particle.
Definition: particledata.h:128
const FourVector & momentum() const
Get the particle's 4-momentum.
Definition: particledata.h:158
double effective_mass() const
Get the particle's effective mass.
Definition: particledata.cc:24
HistoryData get_history() const
Get history information.
Definition: particledata.h:139
const FourVector & position() const
Get the particle's position in Minkowski space.
Definition: particledata.h:204
int strangeness() const
Definition: particletype.h:213
int32_t charge() const
The charge of the particle.
Definition: particletype.h:189
int baryon_number() const
Definition: particletype.h:210
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
size_t size() const
Definition: particles.h:87
std::string string() const
Definition: pdgcode.h:325
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
Definition: action.h:24
static constexpr int LHyperSurfaceCrossing
Definition: binaryoutput.cc:22
@ HyperSurfaceCrossing
See here for a short description.
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
Structure to contain custom data for output.
bool impose_kinematic_cut_for_SMASH_IC
Whether or not kinematic cuts are employed for SMASH IC.
int32_t collisions_per_particle
Collision counter per particle, zero only for initially present particles.
Definition: particledata.h:32
Helper structure for Experiment to hold output options and parameters.