36 static constexpr
int LList = LogArea::List::id;
40 : shift_id_(modus_config.take({
"List",
"Shift_Id"})) {
41 std::string fd = modus_config.take({
"List",
"File_Directory"});
44 std::string fp = modus_config.take({
"List",
"File_Prefix"});
50 if (param.n_ensembles > 1) {
51 throw std::runtime_error(
"ListModus only makes sense with one ensemble");
57 out <<
"-- List Modus\nInput directory for external particle lists:\n"
65 double earliest_formation_time = DBL_MAX;
66 double formation_time_difference = 0.0;
67 double reference_formation_time = 0.0;
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;
75 reference_formation_time = t;
76 first_particle =
false;
78 formation_time_difference += std::abs(t - reference_formation_time);
83 bool anti_streaming_needed = (formation_time_difference >
really_small);
85 if (anti_streaming_needed) {
86 for (
auto &particle : particles) {
88 const double t = particle.position().x0();
91 particle.position().threevec() - delta_t * particle.velocity();
93 particle.set_formation_time(t);
94 particle.set_cross_section_scaling_factor(0.0);
100 double t,
double x,
double y,
double z,
101 double mass,
double E,
double px,
double py,
112 particles.
insert(new_particle);
114 logg[
LList].warn() <<
"SMASH does not recognize pdg code " << pdgcode
115 <<
" loaded from file. This particle will be ignored.\n";
124 std::istringstream lineinput(line.text);
125 double t, x, y, z, mass, E, px, py, pz;
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()) {
133 "Failed to convert the input string to the "
134 "expected data types.",
138 logg[
LList].debug(
"Particle ", pdgcode,
" (x,y,z)= (", x,
", ", y,
", ", z,
142 if (pdgcode.
charge() != charge) {
143 logg[
LList].error() <<
"Charge of pdg = " << pdgcode <<
" != " << charge;
144 throw std::invalid_argument(
"Inconsistent input (charge).");
146 try_create_particle(*particles, pdgcode, t, x, y, z, mass, E, px, py, pz);
148 if (particles->
size() > 0) {
159 std::stringstream fname;
162 const std::filesystem::path default_path =
165 const std::filesystem::path fpath = default_path / fname.str();
167 logg[
LList].debug() << fpath.filename().native() <<
'\n';
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"
179 throw std::runtime_error(
"External particle list does not exist!");
187 std::ifstream ifs{fpath};
201 std::string event_string;
202 const std::string needle =
"end";
204 while (getline(ifs, line)) {
205 if (line.find(needle) == std::string::npos) {
206 event_string += line +
"\n";
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");
224 std::streampos last_position) {
225 std::ifstream ifs{filepath};
230 if (last_position == -1) {
233 ifs.seekg(last_position);
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) {
247 logg[
LList].fatal() <<
"Error while reading "
248 << filepath.filename().native();
249 throw std::runtime_error(
"Error while reading external particle list");
258 : shift_id_(modus_config.take({
"ListBox",
"Shift_Id"})),
259 length_(modus_config.take({
"ListBox",
"Length"})) {
260 std::string fd = modus_config.take({
"ListBox",
"File_Directory"});
261 particle_list_file_directory_ = fd;
263 std::string fp = modus_config.take({
"ListBox",
"File_Prefix"});
264 particle_list_file_prefix_ = fp;
267 file_id_ = shift_id_;
275 if (param.n_ensembles > 1) {
276 throw std::runtime_error(
"ListModus only makes sense with one ensemble");
281 const OutputsList &output_list) {
289 data.set_4position(position);
292 std::make_unique<WallcrossingAction>(incoming_particle, data);
293 for (
const auto &output : output_list) {
294 if (!output->is_dilepton_output() && !output->is_photon_output()) {
295 output->at_interaction(*action, 0.);
301 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.
const double length_
Length of the cube's edge in fm.
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 ...
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.
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...
std::filesystem::path file_path_(const int file_id)
Return the absolute file path based on given integer.
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
bool warn_about_mass_discrepancy_
Auxiliary flag to warn about mass-discrepancies only once per instance.
const int shift_id_
shift_id is the start number of file_id_
bool warn_about_off_shell_particles_
Auxiliary flag to warn about off-shell particles only once per instance.
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
ParticleData contains the dynamic information of a certain particle.
void set_4position(const FourVector &pos)
Set the particle's 4-position directly.
void set_cross_section_scaling_factor(const double &xsec_scal)
Set the particle's initial cross_section_scaling_factor.
void set_formation_time(const double &form_time)
Set the absolute formation time.
The Particles class abstracts the storage and manipulation of particles.
const ParticleData & insert(const ParticleData &p)
Inserts the particle into the list of particles.
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.
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.
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.