Version: SMASH-1.8
icoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2019-2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/icoutput.h"
11 
12 #include <fstream>
13 
14 #include <boost/filesystem.hpp>
15 
16 #include "smash/action.h"
17 
18 namespace smash {
19 static constexpr int LHyperSurfaceCrossing = LogArea::HyperSurfaceCrossing::id;
20 
99 ICOutput::ICOutput(const bf::path &path, const std::string &name,
100  const OutputParameters &out_par)
101  : OutputInterface(name),
102  file_{path / "SMASH_IC.dat", "w"},
103  out_par_(out_par) {
104  std::fprintf(
105  file_.get(),
106  "# %s initial conditions: hypersurface of constant proper time\n",
107  VERSION_MAJOR);
108  std::fprintf(file_.get(), "# tau x y eta mt px py Rap pdg charge\n");
109  std::fprintf(file_.get(), "# fm fm fm none GeV GeV GeV none none e\n");
110 }
111 
113 
114 void ICOutput::at_eventstart(const Particles &, const int event_number) {
115  std::fprintf(file_.get(), "# event %i start\n", event_number + 1);
116 }
117 
118 void ICOutput::at_eventend(const Particles &particles, const int event_number,
119  double, bool) {
120  std::fprintf(file_.get(), "# event %i end\n", event_number + 1);
121 
122  // If the runtime is too short some particles might not yet have
123  // reached the hypersurface. Warning is printed.
124  if (particles.size() != 0) {
126  "End time might be too small for initial conditions output. "
127  "Hypersurface has not yet been crossed by ",
128  particles.size(), " particle(s).");
129  }
130 }
131 
133  const std::unique_ptr<Clock> &,
134  const DensityParameters &) {
135  // Dummy, but virtual function needs to be declared.
136 }
137 
138 void ICOutput::at_interaction(const Action &action, const double) {
139  assert(action.get_type() == ProcessType::HyperSurfaceCrossing);
140  assert(action.incoming_particles().size() == 1);
141 
142  ParticleData particle = action.incoming_particles()[0];
143 
144  // transverse mass
145  const double m_trans = sqrt(particle.type().mass() * particle.type().mass() +
146  particle.momentum()[1] * particle.momentum()[1] +
147  particle.momentum()[2] * particle.momentum()[2]);
148  // momentum space rapidity
149  const double rapidity =
150  0.5 * log((particle.momentum()[0] + particle.momentum()[3]) /
151  (particle.momentum()[0] - particle.momentum()[3]));
152 
153  // Determine if particle is spectator:
154  // Fulfilled if particle is initial nucleon, aka has no prior interactions
155  bool is_spectator = particle.get_history().collisions_per_particle == 0;
156 
157  // write particle data excluding spectators
158  if (!is_spectator) {
159  std::fprintf(file_.get(), "%g %g %g %g %g %g %g %g %s %i \n",
160  particle.position().tau(), particle.position()[1],
161  particle.position()[2], particle.position().eta(), m_trans,
162  particle.momentum()[1], particle.momentum()[2], rapidity,
163  particle.pdgcode().string().c_str(), particle.type().charge());
164  }
165 
166  if (IC_proper_time_ < 0.0) {
167  // First particle that is removed, overwrite negative default
168  IC_proper_time_ = particle.position().tau();
169  } else {
170  // Verify that all other particles have the same proper time
171  const double next_proper_time = particle.position().tau();
172  if (!((next_proper_time - IC_proper_time_) < really_small))
173  throw std::runtime_error(
174  "Hypersurface proper time changed during evolution.");
175  }
176 }
177 
178 } // namespace smash
smash::Action::get_type
virtual ProcessType get_type() const
Get the process type.
Definition: action.h:131
smash
Definition: action.h:24
smash::ICOutput::at_interaction
void at_interaction(const Action &action, const double) override
Write particle data at the hypersurface crossing point to the IC output.
Definition: icoutput.cc:138
smash::DensityParameters
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:107
smash::ICOutput::ICOutput
ICOutput(const bf::path &path, const std::string &name, const OutputParameters &out_par)
Create a new IC output.
Definition: icoutput.cc:99
smash::Particles::size
size_t size() const
Definition: particles.h:87
smash::ParticleData
Definition: particledata.h:52
action.h
smash::logg
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
smash::ICOutput::at_eventstart
void at_eventstart(const Particles &, const int event_number) override
Write event start line.
Definition: icoutput.cc:114
smash::ICOutput::at_eventend
void at_eventend(const Particles &particles, const int event_number, double, bool) override
Write event end line.
Definition: icoutput.cc:118
smash::really_small
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
smash::RenamingFilePtr::get
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27
smash::OutputParameters
Helper structure for Experiment to hold output options and parameters.
Definition: outputparameters.h:25
smash::OutputInterface
Abstraction of generic output.
Definition: outputinterface.h:35
smash::ICOutput::at_intermediate_time
void at_intermediate_time(const Particles &, const std::unique_ptr< Clock > &, const DensityParameters &) override
Unused, but needed since virtually declared in mother class.
Definition: icoutput.cc:132
smash::LHyperSurfaceCrossing
static constexpr int LHyperSurfaceCrossing
Definition: hypersurfacecrossingaction.cc:18
smash::ICOutput::IC_proper_time_
double IC_proper_time_
Proper time of the particles removed when extracting initial conditions.
Definition: icoutput.h:85
smash::ICOutput::file_
RenamingFilePtr file_
Pointer to output file.
Definition: icoutput.h:72
smash::Particles
Definition: particles.h:33
smash::Action
Definition: action.h:35
smash::ProcessType::HyperSurfaceCrossing
Hypersurface crossing Particles are removed from the evolution and printed to a separate output to se...
smash::Action::incoming_particles
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:59
smash::ICOutput::~ICOutput
~ICOutput()
Definition: icoutput.cc:112
icoutput.h