Version: SMASH-2.0
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  const EventInfo &) {
116  std::fprintf(file_.get(), "# event %i start\n", event_number);
117 }
118 
119 void ICOutput::at_eventend(const Particles &particles, const int event_number,
120  const EventInfo &) {
121  std::fprintf(file_.get(), "# event %i end\n", event_number);
122 
123  // If the runtime is too short some particles might not yet have
124  // reached the hypersurface. Warning is printed.
125  if (particles.size() != 0) {
127  "End time might be too small for initial conditions output. "
128  "Hypersurface has not yet been crossed by ",
129  particles.size(), " particle(s).");
130  }
131 }
132 
134  const std::unique_ptr<Clock> &,
135  const DensityParameters &,
136  const EventInfo &) {
137  // Dummy, but virtual function needs to be declared.
138 }
139 
140 void ICOutput::at_interaction(const Action &action, const double) {
141  assert(action.get_type() == ProcessType::HyperSurfaceCrossing);
142  assert(action.incoming_particles().size() == 1);
143 
144  ParticleData particle = action.incoming_particles()[0];
145 
146  // transverse mass
147  const double m_trans =
148  std::sqrt(particle.type().mass() * particle.type().mass() +
149  particle.momentum()[1] * particle.momentum()[1] +
150  particle.momentum()[2] * particle.momentum()[2]);
151  // momentum space rapidity
152  const double rapidity =
153  0.5 * std::log((particle.momentum()[0] + particle.momentum()[3]) /
154  (particle.momentum()[0] - particle.momentum()[3]));
155 
156  // Determine if particle is spectator:
157  // Fulfilled if particle is initial nucleon, aka has no prior interactions
158  bool is_spectator = particle.get_history().collisions_per_particle == 0;
159 
160  // write particle data excluding spectators
161  if (!is_spectator) {
162  std::fprintf(file_.get(), "%g %g %g %g %g %g %g %g %s %i \n",
163  particle.position().tau(), particle.position()[1],
164  particle.position()[2], particle.position().eta(), m_trans,
165  particle.momentum()[1], particle.momentum()[2], rapidity,
166  particle.pdgcode().string().c_str(), particle.type().charge());
167  }
168 
169  if (IC_proper_time_ < 0.0) {
170  // First particle that is removed, overwrite negative default
171  IC_proper_time_ = particle.position().tau();
172  } else {
173  // Verify that all other particles have the same proper time
174  const double next_proper_time = particle.position().tau();
175  if (!((next_proper_time - IC_proper_time_) < really_small))
176  throw std::runtime_error(
177  "Hypersurface proper time changed during evolution.");
178  }
179 }
180 
181 } // 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:140
smash::DensityParameters
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:108
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::ICOutput::at_intermediate_time
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:133
smash::ParticleData
Definition: particledata.h:52
action.h
smash::EventInfo
Structure to contain custom data for output.
Definition: outputinterface.h:35
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::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::ICOutput::at_eventstart
void at_eventstart(const Particles &, const int event_number, const EventInfo &) override
Write event start line.
Definition: icoutput.cc:114
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:65
smash::LHyperSurfaceCrossing
static constexpr int LHyperSurfaceCrossing
Definition: hypersurfacecrossingaction.cc:16
smash::ICOutput::IC_proper_time_
double IC_proper_time_
Proper time of the particles removed when extracting initial conditions.
Definition: icoutput.h:88
smash::ICOutput::at_eventend
void at_eventend(const Particles &particles, const int event_number, const EventInfo &) override
Write event end line.
Definition: icoutput.cc:119
smash::ICOutput::file_
RenamingFilePtr file_
Pointer to output file.
Definition: icoutput.h:75
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:57
smash::ICOutput::~ICOutput
~ICOutput()
Definition: icoutput.cc:112
icoutput.h