Version: SMASH-3.0
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 56 of file listmodus.h.

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

Classes

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

Public Member Functions

 ListModus (Configuration modus_config, const ExperimentParameters &parameters)
 Constructor. More...
 
 ListModus ()
 Construct an empty list. Useful for convenient JetScape connection. More...
 
double initial_conditions (Particles *particles, const ExperimentParameters &parameters)
 Generates initial state of the particles in the system according to a list. More...
 
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 particles start already at the same time. 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)
 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
 
void set_file_id (const double file_id_inh)
 set the file id when ListBoxModus is used More...
 
void set_particle_list_file_directory (std::string particle_list_file_directory_inh)
 set the particle_list_directory when ListBoxModus is used More...
 
void set_particle_list_file_prefix (std::string particle_list_file_prefix_inh)
 set the particle_list_prefix when ListBoxModus is used More...
 
void set_event_id (int event_id_inh)
 set the event_id when ListBoxModus is used More...
 
- 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...
 
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

bool file_has_events_ (std::filesystem::path filepath, std::streampos last_position)
 Check if the file given by filepath has events left after streampos last_position. More...
 
std::filesystem::path file_path_ (const int file_id)
 Return the absolute file path based on given integer. More...
 
std::string next_event_ ()
 Read the next event. More...
 

Private Attributes

std::string particle_list_file_directory_
 File directory of the particle list. More...
 
std::string particle_list_file_prefix_
 File prefix of the particle list. More...
 
std::string current_particle_list_file_
 File name of current file. More...
 
const int shift_id_
 shift_id is the start number of file_id_ More...
 
int event_id_
 event_id_ = the unique id of the current event More...
 
int file_id_
 file_id_ is the id of the 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...
 
std::streampos last_read_position_
 last read position in current file More...
 

Friends

std::ostream & operator<< (std::ostream &, const ListModus &)
 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]parametersUnused, but necessary because of templated initialization

Definition at line 38 of file listmodus.cc.

40  : shift_id_(modus_config.take({"List", "Shift_Id"})) {
41  std::string fd = modus_config.take({"List", "File_Directory"});
43 
44  std::string fp = modus_config.take({"List", "File_Prefix"});
46 
47  event_id_ = 0;
49 
50  if (param.n_ensembles > 1) {
51  throw std::runtime_error("ListModus only makes sense with one ensemble");
52  }
53 }
std::string particle_list_file_directory_
File directory of the particle list.
Definition: listmodus.h:200
std::string particle_list_file_prefix_
File prefix of the particle list.
Definition: listmodus.h:203
int file_id_
file_id_ is the id of the current file
Definition: listmodus.h:215
const int shift_id_
shift_id is the start number of file_id_
Definition: listmodus.h:209
int event_id_
event_id_ = the unique id of the current event
Definition: listmodus.h:212

◆ ListModus() [2/2]

smash::ListModus::ListModus ( )
inline

Construct an empty list. Useful for convenient JetScape connection.

Definition at line 72 of file listmodus.h.

72 : shift_id_(0) {}

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
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 120 of file listmodus.cc.

121  {
122  std::string particle_list = next_event_();
123  for (const Line &line : line_parser(particle_list)) {
124  std::istringstream lineinput(line.text);
125  double t, x, y, z, mass, E, px, py, pz;
126  int id, charge;
127  std::string pdg_string;
128  lineinput >> t >> x >> y >> z >> mass >> E >> px >> py >> pz >>
129  pdg_string >> id >> charge;
130  if (lineinput.fail()) {
131  throw LoadFailure(
132  build_error_string("While loading external particle lists data:\n"
133  "Failed to convert the input string to the "
134  "expected data types.",
135  line));
136  }
137  PdgCode pdgcode(pdg_string);
138  logg[LList].debug("Particle ", pdgcode, " (x,y,z)= (", x, ", ", y, ", ", z,
139  ")");
140 
141  // Charge consistency check
142  if (pdgcode.charge() != charge) {
143  logg[LList].error() << "Charge of pdg = " << pdgcode << " != " << charge;
144  throw std::invalid_argument("Inconsistent input (charge).");
145  }
146  try_create_particle(*particles, pdgcode, t, x, y, z, mass, E, px, py, pz);
147  }
148  if (particles->size() > 0) {
149  backpropagate_to_same_time(*particles);
150  } else {
151  start_time_ = 0.0;
152  }
153  event_id_++;
154 
155  return start_time_;
156 }
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 ...
Definition: listmodus.cc:62
double start_time_
Starting time for the List; changed to the earliest formation time.
Definition: listmodus.h:165
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...
Definition: listmodus.cc:99
std::string next_event_()
Read the next event.
Definition: listmodus.cc:185
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
build_vector_< Line > line_parser(const std::string &input)
Helper function for parsing particles.txt and decaymodes.txt.
static constexpr int LList
Definition: listmodus.cc:36
std::string build_error_string(std::string message, const Line &line)
Builds a meaningful error message.

◆ backpropagate_to_same_time()

void smash::ListModus::backpropagate_to_same_time ( Particles particles)

Judge whether formation 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 formation 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 62 of file listmodus.cc.

62  {
63  /* (1) If particles are already at the same time - don't touch them
64  AND start at the start_time_ from the config. */
65  double earliest_formation_time = DBL_MAX;
66  double formation_time_difference = 0.0;
67  double reference_formation_time = 0.0; // avoid compiler warning
68  bool first_particle = true;
69  for (const auto &particle : particles) {
70  const double t = particle.position().x0();
71  if (t < earliest_formation_time) {
72  earliest_formation_time = t;
73  }
74  if (first_particle) {
75  reference_formation_time = t;
76  first_particle = false;
77  } else {
78  formation_time_difference += std::abs(t - reference_formation_time);
79  }
80  }
81  /* (2) If particles are NOT at the same time -> anti-stream them to
82  the earliest time (Note: not to the start_time_ set by config) */
83  bool anti_streaming_needed = (formation_time_difference > really_small);
84  start_time_ = earliest_formation_time;
85  if (anti_streaming_needed) {
86  for (auto &particle : particles) {
87  /* for hydro output where formation time is different */
88  const double t = particle.position().x0();
89  const double delta_t = t - start_time_;
90  const ThreeVector r =
91  particle.position().threevec() - delta_t * particle.velocity();
92  particle.set_4position(FourVector(start_time_, r));
93  particle.set_formation_time(t);
94  particle.set_cross_section_scaling_factor(0.0);
95  }
96  }
97 }
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37

◆ 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 
)

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 \). 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
[out]particlesstructure, to which the particle is added

Definition at line 99 of file listmodus.cc.

102  {
103  try {
104  ParticleData new_particle =
106  pdgcode, mass, {E, px, py, pz}, LList, warn_about_mass_discrepancy_,
108  // Set spatial coordinates, they will later be backpropagated if needed
109  new_particle.set_4position(FourVector(t, x, y, z));
110  new_particle.set_formation_time(t);
111  new_particle.set_cross_section_scaling_factor(1.0);
112  particles.insert(new_particle);
113  } catch (ParticleType::PdgNotFoundFailure &) {
114  logg[LList].warn() << "SMASH does not recognize pdg code " << pdgcode
115  << " loaded from file. This particle will be ignored.\n";
116  }
117 }
bool warn_about_mass_discrepancy_
Auxiliary flag to warn about mass-discrepancies only once per instance.
Definition: listmodus.h:218
bool warn_about_off_shell_particles_
Auxiliary flag to warn about off-shell particles only once per instance.
Definition: listmodus.h:220
void set_4position(const FourVector &pos)
Set the particle's 4-position directly.
Definition: particledata.h:209
ParticleData create_valid_smash_particle_matching_provided_quantities(PdgCode pdgcode, double mass, 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 143 of file listmodus.h.

143 { return true; }

◆ set_file_id()

void smash::ListModus::set_file_id ( const double  file_id_inh)
inline

set the file id when ListBoxModus is used

Definition at line 146 of file listmodus.h.

146 { file_id_ = file_id_inh; }

◆ set_particle_list_file_directory()

void smash::ListModus::set_particle_list_file_directory ( std::string  particle_list_file_directory_inh)
inline

set the particle_list_directory when ListBoxModus is used

Definition at line 149 of file listmodus.h.

150  {
151  particle_list_file_directory_ = particle_list_file_directory_inh;
152  }

◆ set_particle_list_file_prefix()

void smash::ListModus::set_particle_list_file_prefix ( std::string  particle_list_file_prefix_inh)
inline

set the particle_list_prefix when ListBoxModus is used

Definition at line 155 of file listmodus.h.

156  {
157  particle_list_file_prefix_ = particle_list_file_prefix_inh;
158  }

◆ set_event_id()

void smash::ListModus::set_event_id ( int  event_id_inh)
inline

set the event_id when ListBoxModus is used

Definition at line 161 of file listmodus.h.

161 { event_id_ = event_id_inh; }

◆ file_has_events_()

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

Check if the file given by filepath has events left after streampos last_position.

Parameters
[in]filepathPath to file to be checked.
[in]last_positionStreamposition 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 223 of file listmodus.cc.

224  {
225  std::ifstream ifs{filepath};
226  std::string line;
227 
228  // last event read read at end of file. we know this because errors are
229  // handled in next_event
230  if (last_position == -1) {
231  return false;
232  }
233  ifs.seekg(last_position);
234  // skip over comment lines, assume that a max. of four consecutive comment
235  // lines can occur
236  int skipped_lines = 0;
237  const int max_comment_lines = 4;
238  while (std::getline(ifs, line) && line[0] != '#' &&
239  skipped_lines++ < max_comment_lines) {
240  }
241 
242  if (ifs.eof()) {
243  return false;
244  }
245 
246  if (!ifs.good()) {
247  logg[LList].fatal() << "Error while reading "
248  << filepath.filename().native();
249  throw std::runtime_error("Error while reading external particle list");
250  }
251 
252  ifs.close();
253  return true;
254 }

◆ file_path_()

std::filesystem::path smash::ListModus::file_path_ ( const int  file_id)
private

Return the absolute file path based on given integer.

The filename is assumed to have the form (particle_list_prefix)_(file_id)

Parameters
[in]file_idinteger of wanted file
Returns
Absolute file path to file
Exceptions
runtime_errorif file does not exist.

Definition at line 158 of file listmodus.cc.

158  {
159  std::stringstream fname;
160  fname << particle_list_file_prefix_ << file_id;
161 
162  const std::filesystem::path default_path =
163  std::filesystem::absolute(particle_list_file_directory_);
164 
165  const std::filesystem::path fpath = default_path / fname.str();
166 
167  logg[LList].debug() << fpath.filename().native() << '\n';
168 
169  if (!std::filesystem::exists(fpath)) {
170  logg[LList].fatal() << fpath.filename().native() << " does not exist! \n"
171  << "\n Usage of smash with external particle lists:\n"
172  << "1. Put the external particle lists in file \n"
173  << "File_Directory/File_Prefix{id} where {id} "
174  << "traversal [Shift_Id, Nevent-1]\n"
175  << "2. Particles info: t x y z mass p0 px py pz"
176  << " pdg ID charge\n"
177  << "in units of: fm fm fm fm GeV GeV GeV GeV GeV"
178  << " none none e\n";
179  throw std::runtime_error("External particle list does not exist!");
180  }
181 
182  return fpath;
183 }

◆ 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 185 of file listmodus.cc.

185  {
186  const std::filesystem::path fpath = file_path_(file_id_);
187  std::ifstream ifs{fpath};
188  ifs.seekg(last_read_position_);
189 
190  if (!file_has_events_(fpath, last_read_position_)) {
191  // current file out of events. get next file and call this function
192  // recursively.
193  file_id_++;
195  ifs.close();
196  return next_event_();
197  }
198 
199  // read one event. events marked by line # event end i in case of Oscar
200  // output. Assume one event per file for all other output formats
201  std::string event_string;
202  const std::string needle = "end";
203  std::string line;
204  while (getline(ifs, line)) {
205  if (line.find(needle) == std::string::npos) {
206  event_string += line + "\n";
207  } else {
208  break;
209  }
210  }
211 
212  if (!ifs.eof() && (ifs.fail() || ifs.bad())) {
213  logg[LList].fatal() << "Error while reading " << fpath.filename().native();
214  throw std::runtime_error("Error while reading external particle list");
215  }
216  // save position for next event read
217  last_read_position_ = ifs.tellg();
218  ifs.close();
219 
220  return event_string;
221 }
bool file_has_events_(std::filesystem::path filepath, std::streampos last_position)
Check if the file given by filepath has events left after streampos last_position.
Definition: listmodus.cc:223
std::filesystem::path file_path_(const int file_id)
Return the absolute file path based on given integer.
Definition: listmodus.cc:158
std::streampos last_read_position_
last read position in current file
Definition: listmodus.h:223

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 165 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 200 of file listmodus.h.

◆ particle_list_file_prefix_

std::string smash::ListModus::particle_list_file_prefix_
private

File prefix of the particle list.

Definition at line 203 of file listmodus.h.

◆ current_particle_list_file_

std::string smash::ListModus::current_particle_list_file_
private

File name of current file.

Definition at line 206 of file listmodus.h.

◆ shift_id_

const int smash::ListModus::shift_id_
private

shift_id is the start number of file_id_

Definition at line 209 of file listmodus.h.

◆ event_id_

int smash::ListModus::event_id_
private

event_id_ = the unique id of the current event

Definition at line 212 of file listmodus.h.

◆ file_id_

int smash::ListModus::file_id_
private

file_id_ is the id of the current file

Definition at line 215 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 218 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 220 of file listmodus.h.

◆ last_read_position_

std::streampos smash::ListModus::last_read_position_
private

last read position in current file

Definition at line 223 of file listmodus.h.


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