Version: SMASH-3.3
smash::ListModus Class Reference

#include <listmodus.h>

ListModus: Provides a modus for running SMASH on an external particle list, for example as an afterburner calculation.

To use this modus, choose Modus: List

General:
Modus: List

in the configuration file.

Options for ListModus go in the "Modi"→"List" section of the configuration:

Modi:
List:
# options here

For configuring see List.

Since SMASH is searching for collisions in computational frame time 't', all particles need to be at the same time. If this is not the case in the list provided, the particles will be propagated backwards on straight lines ("anti-freestreaming"). To avoid unphysical interactions of these particles, the back-propagated particles receive a formation_time and zero cross_section_scaling_factor. The cross-sections are set to zero during the time, where the particle will just propagate on a straight line again to appear at the formation_time into the system.

Definition at line 57 of file listmodus.h.

Inheritance diagram for smash::ListModus:
smash::ModusDefault smash::ListBoxModus

Classes

struct  InvalidEvents
 Used when external particle list is invalid. More...
 
struct  LoadFailure
 Used when external particle list cannot be found. More...
 

Public Member Functions

 ListModus (Configuration modus_config, const ExperimentParameters &parameters)
 Constructor. More...
 
 ListModus ()=default
 Construct an empty list. More...
 
double initial_conditions (Particles *particles, const ExperimentParameters &parameters)
 Generates initial state of the particles in the system according to a list. More...
 
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, const std::vector< std::string > &optional_quantities={})
 Tries to add a new particle to particles and performs consistency checks: (i) The PDG code is legal and exists in SMASH. More...
 
bool is_list () const
 
- Public Member Functions inherited from smash::ModusDefault
int impose_boundary_conditions (Particles *, const OutputsList &={})
 Enforces sensible positions for the particles. More...
 
bool is_collider () const
 
bool is_box () const
 
bool is_list () const
 
bool is_sphere () const
 
double sqrt_s_NN () const
 
double impact_parameter () const
 
void sample_impact () const
 sample impact parameter for collider modus More...
 
double velocity_projectile () const
 
double velocity_target () const
 
FermiMotion fermi_motion () const
 
double max_timestep (double) const
 
double equilibration_time () const
 
double length () const
 
double radius () const
 
bool calculation_frame_is_fixed_target () const
 
double nuclei_passing_time () const
 Get the passing time of the two nuclei in a collision. More...
 
bool is_IC_for_hybrid () const
 
const InitialConditionParametersIC_parameters () const
 
const std::map< int32_t, double > & fluid_background ()
 
const RectangularLattice< EnergyMomentumTensor > & fluid_lattice ()
 
void build_fluidization_lattice ([[maybe_unused]] const double t, [[maybe_unused]] const std::vector< Particles > &ensembles, [[maybe_unused]] const DensityParameters &dens_par)
 Build lattice of energy momentum tensor. More...
 
Grid< GridOptions::Normalcreate_grid (const Particles &particles, double min_cell_length, double timestep_duration, CollisionCriterion crit, const bool include_unformed_particles, CellSizeStrategy strategy=CellSizeStrategy::Optimal) const
 Creates the Grid with normal boundary conditions. More...
 
std::unique_ptr< GrandCanThermalizercreate_grandcan_thermalizer (Configuration &conf) const
 Creates GrandCanThermalizer. More...
 

Protected Attributes

double start_time_ = 0.
 Starting time for the List; changed to the earliest formation time. More...
 

Private Member Functions

void read_particles_from_next_event_ (Particles &particles)
 Read the next event from file. More...
 
bool file_has_events_ (std::filesystem::path filepath, std::streampos last_position)
 Check if the given file has events left after the given position. More...
 
std::filesystem::path file_path_ (std::optional< int > file_id)
 Return the absolute path of the data file. More...
 
std::string next_event_ ()
 Read the next event. More...
 
void validate_list_of_particles_of_all_events_ () const
 Read and validate all events particles. More...
 
void validate_optional_fields_ () const
 Validate the optional fields. More...
 
void backpropagate_to_same_time_if_needed_ (Particles &particles)
 Judge whether times are the same for all the particles; don't do anti-freestreaming if all particles start already at the same time. More...
 
void insert_optional_quantities_to_ (ParticleData &p, const std::vector< std::string > &optional_quantities) const
 Sets the optional fields given in the input list into a particle. More...
 

Private Attributes

std::string particle_list_file_directory_
 File directory of the particle list. More...
 
std::string particle_list_filename_or_prefix_
 Prefix of the file(s) containing the particle list. More...
 
std::optional< int > file_id_
 The id of the current file. More...
 
std::vector< std::string > optional_fields_ {}
 Fields with optional quantities to be read. More...
 
int event_id_
 The unique id of the current event. More...
 
std::streampos last_read_position_ = 0
 Last read position in current file. More...
 
bool warn_about_mass_discrepancy_ = true
 Auxiliary flag to warn about mass-discrepancies only once per instance. More...
 
bool warn_about_off_shell_particles_ = true
 Auxiliary flag to warn about off-shell particles only once per instance. More...
 
SpinInteractionType spin_interaction_type_ = SpinInteractionType::Off
 Auxiliary flag to indicate the type of spin interaction used. More...
 
bool verbose_ = true
 Flag to suppress some error messages. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const ListModus &m)
 Writes the initial state for the List to the output stream. More...
 

Constructor & Destructor Documentation

◆ ListModus() [1/2]

smash::ListModus::ListModus ( Configuration  modus_config,
const ExperimentParameters parameters 
)
explicit

Constructor.

Gathers all configuration variables for the List.

Parameters
[in]modus_configThe configuration object that sets all initial conditions of the experiment
[in]parametersNecessary because of templated usage in Experiment
Exceptions
InvalidEventsIf more than 2 particles are at the same position in any of the events.

Definition at line 42 of file listmodus.cc.

44  : file_id_{std::nullopt}, event_id_{0} {
45  /*
46  * Make some logic on config to understand whether to extract parent or
47  * children keys. These have all the same keys but have a different section
48  * name (like for instance 'ListBox' instead of 'List'). At the moment there
49  * is only one child and this approach is fine enough, although ugly.
50  */
51  const bool is_list =
52  modus_config.has_value(InputKeys::modi_list_fileDirectory);
53  const bool is_list_box =
54  modus_config.has_value(InputKeys::modi_listBox_fileDirectory);
55  if (is_list == is_list_box) {
56  throw std::logic_error(
57  "Unexpected error in ListModus constructor. Either List or ListBox "
58  "sections must be present in configuration.");
59  }
60  Key<std::string> file_prefix_key = InputKeys::modi_list_filePrefix,
61  file_directory_key = InputKeys::modi_list_fileDirectory,
62  filename_key = InputKeys::modi_list_filename;
63  Key<int> shift_id_key = InputKeys::modi_list_shiftId;
64  Key<std::vector<std::string>> optional_quantities_key =
66  if (is_list_box) {
67  file_prefix_key = InputKeys::modi_listBox_filePrefix;
68  file_directory_key = InputKeys::modi_listBox_fileDirectory;
69  filename_key = InputKeys::modi_listBox_filename;
70  shift_id_key = InputKeys::modi_listBox_shiftId;
71  optional_quantities_key = InputKeys::modi_listBox_optionalQuantities;
72  }
73 
74  // Set the default values for the spin interaction type
75  spin_interaction_type_ = param.spin_interaction_type;
76 
77  // Impose strict requirement on possible keys present in configuration file
78  const bool file_prefix_used = modus_config.has_value(file_prefix_key);
79  const bool filename_used = modus_config.has_value(filename_key);
80  if (file_prefix_used == filename_used) {
81  throw std::invalid_argument(
82  "Either 'Filename' or 'File_Prefix' key must be used in 'Modi' section "
83  "in configuration file. Please, adjust your configuration file.");
84  }
85  if (file_prefix_used) {
86  particle_list_filename_or_prefix_ = modus_config.take(file_prefix_key);
87  file_id_ = modus_config.take(shift_id_key);
88  } else {
89  particle_list_filename_or_prefix_ = modus_config.take(filename_key);
90  }
91  particle_list_file_directory_ = modus_config.take(file_directory_key);
92  if (param.n_ensembles > 1) {
93  throw std::runtime_error("ListModus only makes sense with one ensemble");
94  }
95  optional_fields_ = modus_config.take(optional_quantities_key);
98 }
std::optional< int > file_id_
The id of the current file.
Definition: listmodus.h:259
bool is_list() const
Definition: listmodus.h:148
std::string particle_list_filename_or_prefix_
Prefix of the file(s) containing the particle list.
Definition: listmodus.h:256
void validate_optional_fields_() const
Validate the optional fields.
Definition: listmodus.cc:456
SpinInteractionType spin_interaction_type_
Auxiliary flag to indicate the type of spin interaction used.
Definition: listmodus.h:275
std::string particle_list_file_directory_
File directory of the particle list.
Definition: listmodus.h:250
void validate_list_of_particles_of_all_events_() const
Read and validate all events particles.
Definition: listmodus.cc:431
std::vector< std::string > optional_fields_
Fields with optional quantities to be read.
Definition: listmodus.h:262
int event_id_
The unique id of the current event.
Definition: listmodus.h:264
static const Key< std::vector< std::string > > modi_listBox_optionalQuantities
See user guide description for more information.
Definition: input_keys.h:4878
static const Key< std::string > modi_list_fileDirectory
See user guide description for more information.
Definition: input_keys.h:4687
static const Key< std::string > modi_listBox_filePrefix
See user guide description for more information.
Definition: input_keys.h:4837
static const Key< std::vector< std::string > > modi_list_optionalQuantities
See user guide description for more information.
Definition: input_keys.h:4796
static const Key< std::string > modi_list_filename
See user guide description for more information.
Definition: input_keys.h:4702
static const Key< int > modi_listBox_shiftId
See user guide description for more information.
Definition: input_keys.h:4863
static const Key< int > modi_list_shiftId
See user guide description for more information.
Definition: input_keys.h:4732
static const Key< std::string > modi_list_filePrefix
See user guide description for more information.
Definition: input_keys.h:4715
static const Key< std::string > modi_listBox_filename
See user guide description for more information.
Definition: input_keys.h:4824
static const Key< std::string > modi_listBox_fileDirectory
See user guide description for more information.
Definition: input_keys.h:4811

◆ ListModus() [2/2]

smash::ListModus::ListModus ( )
default

Construct an empty list.

This is needed for children construction but it is offered as public instead of protected as it is also useful for JetScape.

Member Function Documentation

◆ initial_conditions()

double smash::ListModus::initial_conditions ( Particles particles,
const ExperimentParameters parameters 
)

Generates initial state of the particles in the system according to a list.

Parameters
[out]particlesAn empty list that gets filled up by this function
[in]parametersUnused, but necessary because of templated use of this function
Returns
The starting time of the simulation
See also
read_particles_from_next_event_ for possible exceptions thrown.

Definition at line 266 of file listmodus.cc.

267  {
269  if (particles->size() > 0) {
271  } else {
272  start_time_ = 0.0;
273  }
274  event_id_++;
275 
276  return start_time_;
277 }
void backpropagate_to_same_time_if_needed_(Particles &particles)
Judge whether times are the same for all the particles; don't do anti-freestreaming if all particles ...
Definition: listmodus.cc:107
void read_particles_from_next_event_(Particles &particles)
Read the next event from file.
Definition: listmodus.cc:279
double start_time_
Starting time for the List; changed to the earliest formation time.
Definition: listmodus.h:152

◆ try_create_particle()

void smash::ListModus::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,
const std::vector< std::string > &  optional_quantities = {} 
)

Tries to add a new particle to particles and performs consistency checks: (i) The PDG code is legal and exists in SMASH.

If not, a warning is printed and the particle is ignored. (ii) The mass matches the pole mass of pdgcode in SMASH. If it does not, then a warning is printed, the pole mass of the particle is set equal to the corresponding mass from SMASH particle table and it's energy is recomputed as \( E^2 = p^2 + m^2 \). (iii) Any stable particle is on-shell, i.e. \( E^2 - p^2 = m^2 \). If it is not, then a warning is printed and the energy is set to \( E^2 = p^2 + m^2 \). (iv) If there are nan values in the position or momentum of the particle an exception is thrown.

This very tolerant behaviour is justified by the practical usage of SMASH as afterburner. Usually particles unknown to SMASH are rare resonances, which do not play a large role. Mass mismatch is typically less than 1% and comes from rounding and from SMASH enforcing isospin symmetry (for example the mass of neutral pion is artificially forced to be the same as charged pion). On-shellness violation typically comes from the insufficient number of significant digits in the input file + rounding.

Parameters
[in]pdgcodePDG code of added particle
[in]tTime of added particle
[in]xx-coordinate of added particle
[in]yy-coordinate of added particle
[in]zz-coordinate of added particle
[in]massMass of added particle
[in]EEnergy of added particle
[in]pxx-component of momentum of added particle
[in]pyy-component of momentum of added particle
[in]pzz-component of momentum of added particle
[in]optional_quantitiesExtra values present in the input list
[out]particlesObject to which the particle is added

Definition at line 135 of file listmodus.cc.

138  {
139  try {
140  ParticleData new_particle =
142  pdgcode, mass, {t, x, y, z}, {E, px, py, pz}, LList,
144  insert_optional_quantities_to_(new_particle, optional_quantities);
145  particles.insert(new_particle);
146  } catch (ParticleType::PdgNotFoundFailure &) {
147  logg[LList].warn() << "SMASH does not recognize pdg code " << pdgcode
148  << " loaded from file. This particle will be ignored.\n";
149  }
150 }
bool warn_about_mass_discrepancy_
Auxiliary flag to warn about mass-discrepancies only once per instance.
Definition: listmodus.h:270
bool warn_about_off_shell_particles_
Auxiliary flag to warn about off-shell particles only once per instance.
Definition: listmodus.h:272
void insert_optional_quantities_to_(ParticleData &p, const std::vector< std::string > &optional_quantities) const
Sets the optional fields given in the input list into a particle.
Definition: listmodus.cc:152
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:40
static constexpr int LList
Definition: listmodus.cc:38
ParticleData create_valid_smash_particle_matching_provided_quantities(PdgCode pdgcode, double mass, const FourVector &four_position, const FourVector &four_momentum, int log_area, bool &mass_warning, bool &on_shell_warning)
This function creates a SMASH particle validating the provided information.

◆ is_list()

bool smash::ListModus::is_list ( ) const
inline
Returns
whether the modus is list modus (which is, yes, trivially true)

Definition at line 148 of file listmodus.h.

148 { return true; }

◆ read_particles_from_next_event_()

void smash::ListModus::read_particles_from_next_event_ ( Particles particles)
private

Read the next event from file.

Parameters
particlesThe list of particles where the read information is stored
Exceptions
runtime_errorIf an input list file could not be found
LoadFailureIf an input list file is not correctly formatted
invalid_argumentIf the listed charge of a particle does not correspond to its pdg charge

Definition at line 279 of file listmodus.cc.

279  {
280  std::string particle_list = next_event_();
281  const std::vector<Line> event_content = line_parser(particle_list);
282  if (event_content.empty()) {
283  if (verbose_) {
284  logg[LList].warn(
285  "Encountered empty event while reading input particle lists data, "
286  "which will result in empty events in the output file!");
287  }
288  return;
289  }
290  for (const Line &line : event_content) {
291  std::istringstream lineinput(line.text);
292  double t, x, y, z, mass, E, px, py, pz;
293  std::string pdg_string;
294  lineinput >> t >> x >> y >> z >> mass >> E >> px >> py >> pz >> pdg_string;
295  std::vector<std::string> optional_quantities(optional_fields_.size());
296  for (size_t i = 0; i < optional_fields_.size(); ++i) {
297  std::string opt{};
298  lineinput >> opt;
299  optional_quantities[i] = std::move(opt);
300  }
301  if (lineinput.fail()) {
302  throw LoadFailure(
303  build_error_string("While loading external particle lists data:\n"
304  "Failed to convert the input string to the "
305  "expected data types.",
306  line));
307  }
308  PdgCode pdgcode(pdg_string);
309  logg[LList].debug("Particle ", pdgcode, " (x,y,z)= (", x, ", ", y, ", ", z,
310  ")");
311 
312  try_create_particle(particles, pdgcode, t, x, y, z, mass, E, px, py, pz,
313  optional_quantities);
314  }
315 }
bool verbose_
Flag to suppress some error messages.
Definition: listmodus.h:283
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, const std::vector< std::string > &optional_quantities={})
Tries to add a new particle to particles and performs consistency checks: (i) The PDG code is legal a...
Definition: listmodus.cc:135
std::string next_event_()
Read the next event.
Definition: listmodus.cc:344
build_vector_< Line > line_parser(const std::string &input)
Helper function for parsing particles.txt and decaymodes.txt.
std::string build_error_string(std::string message, const Line &line)
Builds a meaningful error message.

◆ file_has_events_()

bool smash::ListModus::file_has_events_ ( std::filesystem::path  filepath,
std::streampos  last_position 
)
private

Check if the given file has events left after the given position.

Parameters
[in]filepathPath to file to be checked
[in]last_positionStream position in file after which check is performed
Returns
true if there is at least one event left, false otherwise
Exceptions
runtime_errorIf file could not be read for whatever reason

Definition at line 390 of file listmodus.cc.

391  {
392  std::ifstream ifs{filepath};
393  std::string line;
394 
395  // last event read read at end of file. we know this because errors are
396  // handled in next_event
397  if (last_position == -1) {
398  return false;
399  }
400  ifs.seekg(last_position);
401  // skip over comment lines, assume that a max. of four consecutive comment
402  // lines can occur
403  int skipped_lines = 0;
404  const int max_comment_lines = 4;
405  while (std::getline(ifs, line) && line[0] != '#' &&
406  skipped_lines++ < max_comment_lines) {
407  }
408 
409  if (ifs.eof()) {
410  return false;
411  }
412 
413  if (!ifs.good()) {
414  if (verbose_) {
415  logg[LList].fatal() << "Error while reading "
416  << filepath.filename().native();
417  }
418  throw std::runtime_error("Error while reading external particle list");
419  }
420 
421  ifs.close();
422  return true;
423 }

◆ file_path_()

std::filesystem::path smash::ListModus::file_path_ ( std::optional< int >  file_id)
private

Return the absolute path of the data file.

If an integer is passed, the filename is constructed using particle_list_filename_or_prefix_ concatenated with the given number, otherwise the file prefix is understood to be the full filename. The file is expected to be in particle_list_file_directory_ folder.

Parameters
[in]file_idAn std::optional integer
Returns
The absolute file path to file
Exceptions
runtime_errorIf file does not exist.

Definition at line 317 of file listmodus.cc.

317  {
318  std::string fname = particle_list_filename_or_prefix_ +
319  ((file_id) ? std::to_string(*file_id) : "");
320 
321  const std::filesystem::path default_path =
322  std::filesystem::absolute(particle_list_file_directory_);
323 
324  const std::filesystem::path fpath = default_path / fname;
325 
326  logg[LList].debug() << "File: " << std::filesystem::absolute(fpath) << '\n';
327 
328  if (!std::filesystem::exists(fpath)) {
329  if (verbose_) {
330  logg[LList].fatal()
331  << fpath.filename().native() << " does not exist! \n\n"
332  << "Usage of smash with external particle lists:\n"
333  << " 1. Put the external particle lists in one or more files\n"
334  << " according to the user guide instructions.\n"
335  << " 2. Particles info: t x y z mass p0 px py pz pdg ID charge\n"
336  << " in units of: fm fm fm fm GeV GeV GeV GeV GeV none none e\n";
337  }
338  throw std::runtime_error("External particle list does not exist!");
339  }
340 
341  return fpath;
342 }
std::string to_string(ThermodynamicQuantity quantity)
Convert a ThermodynamicQuantity enum value to its corresponding string.
Definition: stringify.cc:26

◆ next_event_()

std::string smash::ListModus::next_event_ ( )
private

Read the next event.

Either from the current file if it has more events or from the next file (with file_id_ += 1)

Returns
One event as string.
Exceptions
runtime_errorIf file could not be read for whatever reason.

Definition at line 344 of file listmodus.cc.

344  {
345  const std::filesystem::path fpath = file_path_(file_id_);
346  std::ifstream ifs{fpath};
347  ifs.seekg(last_read_position_);
348 
349  if (!file_has_events_(fpath, last_read_position_)) {
350  if (file_id_) {
351  // Get next file and call this function recursively
352  (*file_id_)++;
354  ifs.close();
355  return next_event_();
356  } else {
357  throw std::runtime_error(
358  "Attempt to read in next event in ListModus object but no further "
359  "data found in single provided file. Please, check your setup.");
360  }
361  }
362 
363  // read one event. events marked by line # event end i in case of Oscar
364  // output. Assume one event per file for all other output formats
365  std::string event_string{};
366  const std::string needle = " end ";
367  std::string line{};
368  while (getline(ifs, line)) {
369  if (line.find(needle) == std::string::npos) {
370  event_string += line + "\n";
371  } else {
372  break;
373  }
374  }
375 
376  if (!ifs.eof() && (ifs.fail() || ifs.bad())) {
377  if (verbose_) {
378  logg[LList].fatal() << "Error while reading "
379  << fpath.filename().native();
380  }
381  throw std::runtime_error("Error while reading external particle list");
382  }
383  // save position for next event read
384  last_read_position_ = ifs.tellg();
385  ifs.close();
386 
387  return event_string;
388 }
bool file_has_events_(std::filesystem::path filepath, std::streampos last_position)
Check if the given file has events left after the given position.
Definition: listmodus.cc:390
std::filesystem::path file_path_(std::optional< int > file_id)
Return the absolute path of the data file.
Definition: listmodus.cc:317
std::streampos last_read_position_
Last read position in current file.
Definition: listmodus.h:267

◆ validate_list_of_particles_of_all_events_()

void smash::ListModus::validate_list_of_particles_of_all_events_ ( ) const
private

Read and validate all events particles.

At the moment this is done w.r.t. their positions and errors are reported if more than 2 particles have the same identical position.

Exceptions
InvalidEventsIf more than 2 particles with the same identical position are found.

Definition at line 431 of file listmodus.cc.

431  {
432  ListModus utility_copy{*this};
433  utility_copy.verbose_ = false;
434  utility_copy.warn_about_mass_discrepancy_ = false;
435  utility_copy.warn_about_off_shell_particles_ = false;
436  bool are_there_faulty_events = false;
437  while (true) {
438  try {
439  Particles particles{};
440  utility_copy.read_particles_from_next_event_(particles);
441  if (is_list_of_particles_invalid(particles, utility_copy.event_id_)) {
442  are_there_faulty_events = true;
443  }
444  utility_copy.event_id_++;
445  } catch (const std::exception &) {
446  break;
447  }
448  }
449  if (are_there_faulty_events) {
450  throw InvalidEvents(
451  "More than 2 particles with the same 4-position have been found in the "
452  "same event.\nPlease, check your particles list file.");
453  }
454 }
ListModus()=default
Construct an empty list.
static bool is_list_of_particles_invalid(const Particles &, int)
Definition: listmodus.cc:531

◆ validate_optional_fields_()

void smash::ListModus::validate_optional_fields_ ( ) const
private

Validate the optional fields.

At the moment, it ensures that if at least one spin component is given, all four are given.

Exceptions
std::invalid_argumentif not all spin components are given.

Definition at line 456 of file listmodus.cc.

456  {
457  // If spin interactions are enabled, require all four spin components.
459  std::array<bool, 4> has_spin{{false, false, false, false}};
460  for (const auto &field : optional_fields_) {
461  if (field == "spin0") {
462  has_spin[0] = true;
463  } else if (field == "spinx") {
464  has_spin[1] = true;
465  } else if (field == "spiny") {
466  has_spin[2] = true;
467  } else if (field == "spinz") {
468  has_spin[3] = true;
469  }
470  }
471  for (int c = 0; c < 4; ++c) {
472  if (!has_spin[c]) {
473  throw std::invalid_argument(
474  "When spin interactions are enabled, all four spin components "
475  "(spin0, spinx, spiny, spinz) must be provided in the config "
476  "file.");
477  }
478  }
479  }
480 }
@ Off
No spin interactions.
std::basic_ostream< CharT, Traits > & field(std::basic_ostream< CharT, Traits > &s)
Stream modifier to align the next object to a specific width w.

◆ backpropagate_to_same_time_if_needed_()

void smash::ListModus::backpropagate_to_same_time_if_needed_ ( Particles particles)
private

Judge whether times are the same for all the particles; don't do anti-freestreaming if all particles start already at the same time.

If particles are at different times, calculate earliest time as start_time_ and free-stream all particles back to this time.

Parameters
particlesParticles to be checked and possibly back-streamed.

Definition at line 107 of file listmodus.cc.

107  {
108  /* (1) If particles are already at the same time - don't touch them
109  AND start at the start_time_ from the config. */
110  double earliest_formation_time = DBL_MAX;
111  double formation_time_difference = 0.0;
112  double reference_formation_time = 0.0; // avoid compiler warning
113  bool first_particle = true;
114  for (const auto &particle : particles) {
115  const double t = particle.position().x0();
116  if (t < earliest_formation_time) {
117  earliest_formation_time = t;
118  }
119  if (first_particle) {
120  reference_formation_time = t;
121  first_particle = false;
122  } else {
123  formation_time_difference += std::abs(t - reference_formation_time);
124  }
125  }
126  /* (2) If particles are NOT at the same time -> anti-stream them to
127  the earliest time (Note: not to the start_time_ set by config) */
128  bool anti_streaming_needed = (formation_time_difference > really_small);
129  start_time_ = earliest_formation_time;
130  if (anti_streaming_needed) {
132  }
133 }
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:41
void backpropagate_straight_line(Particles *particles, double to_time)
Definition: propagation.cc:86

◆ insert_optional_quantities_to_()

void smash::ListModus::insert_optional_quantities_to_ ( ParticleData p,
const std::vector< std::string > &  optional_quantities 
) const
private

Sets the optional fields given in the input list into a particle.

A warning is issued if the file is not read exactly as given, which happens if, for example, a float is present in an integer-related field.

Parameters
[in]pparticle to be modified
[in]optional_quantitieslist of values to be set
Exceptions
std::invalid_argumentif the quantities in the input file do not obey the appropriate bounds.

Definition at line 152 of file listmodus.cc.

154  {
155  if (optional_quantities.empty()) {
156  return;
157  } else if (optional_quantities.size() != optional_fields_.size()) {
158  using namespace std::string_literals; // NOLINT(build/namespaces)
159  throw std::out_of_range("Unexpected size mismatch in "s + __func__ +
160  " between the list of optional quantities values "
161  "passed in and the class member optional_fields_");
162  }
163  HistoryData hist = p.get_history();
164  std::ostringstream error_message{"", std::ios_base::ate};
165 
166  for (size_t i = 0; i < optional_fields_.size(); ++i) {
167  size_t len{};
168  auto field = optional_fields_[i];
169  auto quantity = optional_quantities[i];
170  if (field == "ID") {
171  // ID information is not relevant
172  continue;
173  } else if (field == "charge") {
174  const PdgCode pdgcode = p.pdgcode();
175  const int charge = std::stoi(optional_quantities[i], &len);
176  // Charge consistency check
177  if (pdgcode.charge() != charge) {
178  error_message << "Charge of pdg = " << pdgcode << " != " << charge
179  << ".\n";
180  throw std::invalid_argument("Inconsistent input (charge).");
181  }
182  } else if (field == "ncoll") {
183  const int ncoll = std::stoi(optional_quantities[i], &len);
184  if (ncoll < 0) {
185  error_message << "ncoll < 0.\n";
186  }
187  hist.collisions_per_particle = ncoll;
188  } else if (field == "form_time") {
189  p.set_formation_time(std::stod(quantity, &len));
190  } else if (field == "xsecfac") {
191  const double xsecfac = std::stod(quantity, &len);
192  if (xsecfac < 0 || xsecfac > 1) {
193  error_message << "xsecfac < 0 or xsecfac > 1.\n";
194  }
195  p.set_cross_section_scaling_factor(xsecfac);
196  } else if (field == "proc_type") {
197  const int proc_type = std::stoi(quantity, &len);
198  if (!is_valid_process_type(proc_type)) {
199  error_message << "Invalid proc_type.\n";
200  }
201  hist.process_type = static_cast<ProcessType>(proc_type);
202  } else if (field == "time_last_coll") {
203  const double t_last_coll = std::stod(quantity, &len);
204  if (t_last_coll > p.position().x0()) {
205  error_message << "time_last_coll > particle time.\n";
206  }
207  hist.time_last_collision = t_last_coll;
208  } else if (field == "pdg_mother1") {
209  if (quantity != "0") {
210  if (!ParticleType::exists(PdgCode(quantity))) {
211  error_message << "pdg_mother1 cannot be " << quantity << ".\n";
212  }
213  hist.p1 = PdgCode(quantity);
214  len = quantity.size();
215  }
216  } else if (field == "pdg_mother2") {
217  if (quantity != "0") {
218  if (!ParticleType::exists(PdgCode(quantity))) {
219  error_message << "pdg_mother2 cannot be " << quantity << ".\n";
220  }
221  hist.p2 = PdgCode(quantity);
222  len = quantity.size();
223  }
224  } else if (field == "spin0") {
225  const double s0 = std::stod(quantity, &len);
226  p.set_spin_vector_component(0, s0);
227  } else if (field == "spinx") {
228  const double s1 = std::stod(quantity, &len);
229  p.set_spin_vector_component(1, s1);
230  } else if (field == "spiny") {
231  const double s2 = std::stod(quantity, &len);
232  p.set_spin_vector_component(2, s2);
233  } else if (field == "spinz") {
234  const double s3 = std::stod(quantity, &len);
235  p.set_spin_vector_component(3, s3);
236  } else if (field == "perturbative_weight") {
237  const double weight = std::stod(quantity, &len);
238  if (0 > weight || weight > 1) {
239  error_message << "Perturbative weight must be between 0 and 1.\n";
240  }
241  p.set_perturbative_weight(weight);
242  } else {
243  error_message << " Unknown quantities given in the configuration.\n";
244  }
245  /* This is to assist the user, in case of a mistype in the inputfile.
246  * We do not throw here because it may be intentional. */
247  if (len != quantity.size()) {
248  logg[LList].warn()
249  << field << "=" << quantity
250  << " not read exactly as written in the input particle list.\n";
251  }
252  }
253 
254  if (error_message.str().size() > 0) {
255  logg[LList].error()
256  << "The reading-in of optional quantities had the following problems:"
257  << std::endl
258  << error_message.str();
259  throw std::invalid_argument(
260  "Please fix the list of input particles and/or configuration.");
261  }
262  p.set_history(std::move(hist));
263 }
static bool exists(PdgCode pdgcode)
constexpr int p
Proton.
bool is_valid_process_type(int v)
Definition: processbranch.h:92
ProcessType
ProcessTypes are used to identify the type of the process.
Definition: processbranch.h:39

Member Data Documentation

◆ start_time_

double smash::ListModus::start_time_ = 0.
protected

Starting time for the List; changed to the earliest formation time.

Definition at line 152 of file listmodus.h.

◆ particle_list_file_directory_

std::string smash::ListModus::particle_list_file_directory_
private

File directory of the particle list.

Definition at line 250 of file listmodus.h.

◆ particle_list_filename_or_prefix_

std::string smash::ListModus::particle_list_filename_or_prefix_
private

Prefix of the file(s) containing the particle list.

If the user want to use a single file without numbering, this will contain the full filename.

Definition at line 256 of file listmodus.h.

◆ file_id_

std::optional<int> smash::ListModus::file_id_
private

The id of the current file.

Definition at line 259 of file listmodus.h.

◆ optional_fields_

std::vector<std::string> smash::ListModus::optional_fields_ {}
private

Fields with optional quantities to be read.

Definition at line 262 of file listmodus.h.

◆ event_id_

int smash::ListModus::event_id_
private

The unique id of the current event.

Definition at line 264 of file listmodus.h.

◆ last_read_position_

std::streampos smash::ListModus::last_read_position_ = 0
private

Last read position in current file.

Definition at line 267 of file listmodus.h.

◆ warn_about_mass_discrepancy_

bool smash::ListModus::warn_about_mass_discrepancy_ = true
private

Auxiliary flag to warn about mass-discrepancies only once per instance.

Definition at line 270 of file listmodus.h.

◆ warn_about_off_shell_particles_

bool smash::ListModus::warn_about_off_shell_particles_ = true
private

Auxiliary flag to warn about off-shell particles only once per instance.

Definition at line 272 of file listmodus.h.

◆ spin_interaction_type_

SpinInteractionType smash::ListModus::spin_interaction_type_ = SpinInteractionType::Off
private

Auxiliary flag to indicate the type of spin interaction used.

Definition at line 275 of file listmodus.h.

◆ verbose_

bool smash::ListModus::verbose_ = true
private

Flag to suppress some error messages.

This is used during the validation of particles in all events, because there we do not know how many events exist and we simply try to read the next one till an error occurs. This triggers an error message which should not be printed to the user.

Definition at line 283 of file listmodus.h.


The documentation for this class was generated from the following files: