22 #include <boost/filesystem.hpp>
23 #include <boost/filesystem/fstream.hpp>
37 static constexpr
int LList = LogArea::List::id;
140 : shift_id_(modus_config.take({
"List",
"Shift_Id"})) {
141 std::string fd = modus_config.take({
"List",
"File_Directory"});
144 std::string fp = modus_config.take({
"List",
"File_Prefix"});
150 if (param.n_ensembles > 1) {
151 throw std::runtime_error(
"ListModus only makes sense with one ensemble");
157 out <<
"-- List Modus\nInput directory for external particle lists:\n"
165 double earliest_formation_time = DBL_MAX;
166 double formation_time_difference = 0.0;
167 double reference_formation_time = 0.0;
168 bool first_particle =
true;
169 for (
const auto &particle : particles) {
170 const double t = particle.position().x0();
171 if (t < earliest_formation_time) {
172 earliest_formation_time = t;
174 if (first_particle) {
175 reference_formation_time = t;
176 first_particle =
false;
178 formation_time_difference += std::abs(t - reference_formation_time);
183 bool anti_streaming_needed = (formation_time_difference >
really_small);
185 if (anti_streaming_needed) {
186 for (
auto &particle : particles) {
188 const double t = particle.position().x0();
191 particle.position().threevec() - delta_t * particle.velocity();
193 particle.set_formation_time(t);
194 particle.set_cross_section_scaling_factor(0.0);
200 double t,
double x,
double y,
double z,
201 double mass,
double E,
double px,
double py,
203 constexpr
int max_warns_precision = 10, max_warn_mass_consistency = 10;
212 <<
" [GeV] is inconsistent with SMASH value = "
214 <<
". Forcing E = sqrt(p^2 + m^2)"
215 <<
", where m is SMASH mass.";
219 "Further warnings about SMASH mass versus input mass"
220 " inconsistencies will be suppressed.");
230 <<
"Provided 4-momentum " << particle.
momentum() <<
" and "
231 <<
" mass " << mass <<
" do not satisfy E^2 - p^2 = m^2."
232 <<
" This may originate from the lack of numerical"
233 <<
" precision in the input. Setting E to sqrt(p^2 + m^2).";
237 "Further warnings about E != sqrt(p^2 + m^2) will"
248 logg[
LList].warn() <<
"SMASH does not recognize pdg code " << pdgcode
249 <<
" loaded from file. This particle will be ignored.\n";
258 std::istringstream lineinput(line.text);
259 double t, x, y, z, mass, E, px, py, pz;
261 std::string pdg_string;
262 lineinput >> t >> x >> y >> z >> mass >> E >> px >> py >> pz >>
263 pdg_string >>
id >> charge;
264 if (lineinput.fail()) {
267 "Failed to convert the input string to the "
268 "expected data types.",
272 logg[
LList].debug(
"Particle ", pdgcode,
" (x,y,z)= (", x,
", ", y,
", ", z,
276 if (pdgcode.
charge() != charge) {
277 logg[
LList].error() <<
"Charge of pdg = " << pdgcode <<
" != " << charge;
278 throw std::invalid_argument(
"Inconsistent input (charge).");
280 try_create_particle(*particles, pdgcode, t, x, y, z, mass, E, px, py, pz);
282 if (particles->
size() > 0) {
293 std::stringstream fname;
298 const bf::path fpath = default_path / fname.str();
300 logg[
LList].debug() << fpath.filename().native() <<
'\n';
302 if (!bf::exists(fpath)) {
303 logg[
LList].fatal() << fpath.filename().native() <<
" does not exist! \n"
304 <<
"\n Usage of smash with external particle lists:\n"
305 <<
"1. Put the external particle lists in file \n"
306 <<
"File_Directory/File_Prefix{id} where {id} "
307 <<
"traversal [Shift_Id, Nevent-1]\n"
308 <<
"2. Particles info: t x y z mass p0 px py pz"
309 <<
" pdg ID charge\n"
310 <<
"in units of: fm fm fm fm GeV GeV GeV GeV GeV"
312 throw std::runtime_error(
"External particle list does not exist!");
320 bf::ifstream ifs{fpath};
334 std::string event_string;
335 const std::string needle =
"end";
337 while (getline(ifs, line)) {
338 if (line.find(needle) == std::string::npos) {
339 event_string += line +
"\n";
345 if (!ifs.eof() && (ifs.fail() || ifs.bad())) {
346 logg[
LList].fatal() <<
"Error while reading " << fpath.filename().native();
347 throw std::runtime_error(
"Error while reading external particle list");
357 std::streampos last_position) {
358 bf::ifstream ifs{filepath};
363 if (last_position == -1) {
366 ifs.seekg(last_position);
369 int skipped_lines = 0;
370 const int max_comment_lines = 4;
371 while (std::getline(ifs, line) && line[0] !=
'#' &&
372 skipped_lines++ < max_comment_lines) {
380 logg[
LList].fatal() <<
"Error while reading "
381 << filepath.filename().native();
382 throw std::runtime_error(
"Error while reading external particle list");
391 : shift_id_(modus_config.take({
"ListBox",
"Shift_Id"})),
392 length_(modus_config.take({
"ListBox",
"Length"})) {
393 std::string fd = modus_config.take({
"ListBox",
"File_Directory"});
394 particle_list_file_directory_ = fd;
396 std::string fp = modus_config.take({
"ListBox",
"File_Prefix"});
397 particle_list_file_prefix_ = fp;
400 file_id_ = shift_id_;
408 if (param.n_ensembles > 1) {
409 throw std::runtime_error(
"ListModus only makes sense with one ensemble");
414 const OutputsList &output_list) {
422 data.set_4position(position);
425 make_unique<WallcrossingAction>(incoming_particle, data);
426 for (
const auto &output : output_list) {
427 if (!output->is_dilepton_output() && !output->is_photon_output()) {
428 output->at_interaction(*action, 0.);
434 logg[
LList].debug(
"Moved ", wraps,
" particles back into the box.");
Generic algorithms on containers and ranges.
Interface to the SMASH configuration files.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
double sqr() const
calculate the square of the vector (which is a scalar)
const double length_
Length of the cube's edge in fm/c.
int impose_boundary_conditions(Particles *particles, const OutputsList &output_list={})
Enforces that all particles are inside the box at the beginning of an event.
ListBoxModus(Configuration modus_config, const ExperimentParameters ¶meters)
Constructor (This is the same as for the ListModus)
ListModus: Provides a modus for running SMASH on an external particle list, for example as an afterbu...
void set_particle_list_file_directory(std::string particle_list_file_directory_inh)
set the particle_list_directory when ListBoxModus is used
void backpropagate_to_same_time(Particles &particles)
Judge whether formation times are the same for all the particles; Don't do anti-freestreaming if all ...
bf::path file_path_(const int file_id)
Return the absolute file path based on given integer.
void set_file_id(const double file_id_inh)
set the file id when ListBoxModus is used
std::string particle_list_file_directory_
File directory of the particle list.
std::string particle_list_file_prefix_
File prefix of the particle list.
int file_id_
file_id_ is the id of the current file
ListModus()
Construct an empty list. Useful for convenient JetScape connection.
double start_time_
Starting time for the List; changed to the earliest formation time.
void try_create_particle(Particles &particles, PdgCode pdgcode, double t, double x, double y, double z, double mass, double E, double px, double py, double pz)
Tries to add a new particle to particles and performs consistency checks: (i) The PDG code is legal a...
void set_particle_list_file_prefix(std::string particle_list_file_prefix_inh)
set the particle_list_prefix when ListBoxModus is used
std::streampos last_read_position_
last read position in current file
const int shift_id_
shift_id is the start number of file_id_
bool file_has_events_(bf::path filepath, std::streampos last_position)
Check if the file given by filepath has events left after streampos last_position.
std::string next_event_()
Read the next event.
double initial_conditions(Particles *particles, const ExperimentParameters ¶meters)
Generates initial state of the particles in the system according to a list.
int event_id_
event_id_ = the unique id of the current event
void set_event_id(int event_id_inh)
set the event_id when ListBoxModus is used
int n_warns_precision_
Counter for mass-check warnings to avoid spamming.
int n_warns_mass_consistency_
Counter for energy-momentum conservation warnings to avoid spamming.
ParticleData contains the dynamic information of a certain particle.
void set_4momentum(const FourVector &momentum_vector)
Set the particle's 4-momentum directly.
const ParticleType & type() const
Get the type of the particle.
void set_4position(const FourVector &pos)
Set the particle's 4-position directly.
const FourVector & momentum() const
Get the particle's 4-momentum.
void set_cross_section_scaling_factor(const double &xsec_scal)
Set the particle's initial cross_section_scaling_factor.
double pole_mass() const
Get the particle's pole mass ("on-shell").
void set_formation_time(const double &form_time)
Set the absolute formation time.
const std::string & name() const
The Particles class abstracts the storage and manipulation of particles.
void create(size_t n, PdgCode pdg)
Add n particles of the same type (pdg) to the list.
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
int charge() const
The charge of the particle.
The ThreeVector class represents a physical three-vector with the components .
Collection of useful constants that are known at compile time.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
static bool enforce_periodic_boundaries(Iterator begin, const Iterator &end, typename std::iterator_traits< Iterator >::value_type length)
Enforces periodic boundaries on the given collection of values.
build_vector_< Line > line_parser(const std::string &input)
Helper function for parsing particles.txt and decaymodes.txt.
static constexpr int LList
constexpr double really_small
Numerical error tolerance.
std::string build_error_string(std::string message, const Line &line)
Builds a meaningful error message.
Helper structure for Experiment.
Line consists of a line number and the contents of that line.
Used when external particle list cannot be found.