22 #include <boost/filesystem.hpp> 23 #include <boost/filesystem/fstream.hpp> 123 : shift_id_(modus_config.take({
"List",
"Shift_Id"})) {
124 std::string fd = modus_config.take({
"List",
"File_Directory"});
127 std::string fp = modus_config.take({
"List",
"File_Prefix"});
136 out <<
"-- List Modus\nInput directory for external particle lists:\n" 144 double earliest_formation_time = DBL_MAX;
145 double formation_time_difference = 0.0;
146 double reference_formation_time = 0.0;
147 bool first_particle =
true;
148 for (
const auto &particle : particles) {
149 const double t = particle.position().x0();
150 if (t < earliest_formation_time) {
151 earliest_formation_time = t;
153 if (first_particle) {
154 reference_formation_time = t;
155 first_particle =
false;
157 formation_time_difference += std::abs(t - reference_formation_time);
162 bool anti_streaming_needed = (formation_time_difference >
really_small);
164 if (anti_streaming_needed) {
165 for (
auto &particle : particles) {
167 const double t = particle.position().x0();
170 particle.position().threevec() - delta_t * particle.velocity();
171 particle.set_4position(
FourVector(start_time_, r));
172 particle.set_formation_time(t);
173 particle.set_cross_section_scaling_factor(0.0);
179 double t,
double x,
double y,
double z,
180 double mass,
double E,
double px,
double py,
182 constexpr
int max_warns_precision = 10, max_warn_mass_consistency = 10;
183 const auto &log = logger<LogArea::List>();
190 log.warn() <<
"Provided mass of " << particle.
type().
name() <<
" = " 191 << mass <<
" [GeV] is inconsistent with SMASH value = " 192 << particle.
pole_mass() <<
". Forcing E = sqrt(p^2 + m^2)" 193 <<
", where m is SMASH mass.";
197 "Further warnings about SMASH mass versus input mass" 198 " inconsistencies will be suppressed.");
207 log.warn() <<
"Provided 4-momentum " << particle.
momentum() <<
" and " 208 <<
" mass " << mass <<
" do not satisfy E^2 - p^2 = m^2." 209 <<
" This may originate from the lack of numerical" 210 <<
" precision in the input. Setting E to sqrt(p^2 + m^2).";
214 "Further warnings about E != sqrt(p^2 + m^2) will" 225 log.warn() <<
"SMASH does not recognize pdg code " << pdgcode
226 <<
" loaded from file. This particle will be ignored.\n";
233 const auto &log = logger<LogArea::List>();
237 std::istringstream lineinput(line.text);
238 double t, x, y, z, mass, E, px, py, pz;
240 std::string pdg_string;
241 lineinput >> t >> x >> y >> z >> mass >> E >> px >> py >> pz >>
242 pdg_string >>
id >> charge;
243 if (lineinput.fail()) {
246 "Failed to convert the input string to the " 247 "expected data types.",
251 log.debug(
"Particle ", pdgcode,
" (x,y,z)= (", x,
", ", y,
", ", z,
")");
254 if (pdgcode.
charge() != charge) {
255 log.error() <<
"Charge of pdg = " << pdgcode <<
" != " << charge;
256 throw std::invalid_argument(
"Inconsistent input (charge).");
258 try_create_particle(*particles, pdgcode, t, x, y, z, mass, E, px, py, pz);
267 const auto &log = logger<LogArea::List>();
268 std::stringstream fname;
273 const bf::path fpath = default_path / fname.str();
275 log.debug() << fpath.filename().native() <<
'\n';
277 if (!bf::exists(fpath)) {
278 log.fatal() << fpath.filename().native() <<
" does not exist! \n" 279 <<
"\n Usage of smash with external particle lists:\n" 280 <<
"1. Put the external particle lists in file \n" 281 <<
"File_Directory/File_Prefix{id} where {id} " 282 <<
"traversal [Shift_Id, Nevent-1]\n" 283 <<
"2. Particles info: t x y z mass p0 px py pz" 284 <<
" pdg ID charge\n" 285 <<
"in units of: fm fm fm fm GeV GeV GeV GeV GeV" 286 <<
" none none none\n";
287 throw std::runtime_error(
"External particle list does not exist!");
294 const auto &log = logger<LogArea::List>();
297 bf::ifstream ifs{fpath};
311 std::string event_string;
312 const std::string needle =
"end";
314 while (getline(ifs, line)) {
315 if (line.find(needle) == std::string::npos) {
316 event_string += line +
"\n";
322 if (!ifs.eof() && (ifs.fail() || ifs.bad())) {
323 log.fatal() <<
"Error while reading " << fpath.filename().native();
324 throw std::runtime_error(
"Error while reading external particle list");
334 std::streampos last_position) {
335 const auto &log = logger<LogArea::List>();
336 bf::ifstream ifs{filepath};
341 if (last_position == -1) {
344 ifs.seekg(last_position);
347 int skipped_lines = 0;
348 const int max_comment_lines = 4;
349 while (std::getline(ifs, line) && line[0] !=
'#' &&
350 skipped_lines++ < max_comment_lines) {
358 log.fatal() <<
"Error while reading " << filepath.filename().native();
359 throw std::runtime_error(
"Error while reading external particle list");
int charge() const
The charge of the particle.
std::string particle_list_file_directory_
File directory of the particle list.
double initial_conditions(Particles *particles, const ExperimentParameters ¶meters)
Generates initial state of the particles in the system according to a list.
The ThreeVector class represents a physical three-vector with the components .
constexpr double really_small
Numerical error tolerance.
int file_id_
file_id_ is the id of the current file
ListModus()
Construct an empty list. Useful for convenient JetScape connection.
ListModus: Provides a modus for running SMASH on an external particle list, for example as an afterbu...
void create(size_t n, PdgCode pdg)
Add n particles of the same type (pdg) to the list.
Collection of useful constants that are known at compile time.
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 ...
Interface to the SMASH configuration files.
int n_warns_mass_consistency_
Counter for energy-momentum conservation warnings to avoid spamming.
void set_formation_time(const double &form_time)
Set the absolute formation time.
Used when external particle list cannot be found.
const std::string & name() const
Generic algorithms on containers and ranges.
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_4momentum(const FourVector &momentum_vector)
Set the particle's 4-momentum directly.
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
double start_time_
Starting time for the List; changed to the earliest formation time.
int n_warns_precision_
Counter for mass-check warnings to avoid spamming.
const ParticleType & type() const
Get the type of the particle.
double sqr() const
calculate the square of the vector (which is a scalar)
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.
double pole_mass() const
Get the particle's pole mass ("on-shell").
int event_id_
event_id_ = the unique id of the current event
build_vector_< Line > line_parser(const std::string &input)
Helper function for parsing particles.txt and decaymodes.txt.
std::string particle_list_file_prefix_
File prefix of the particle list.
void set_4position(const FourVector &pos)
Set the particle's 4-position directly.
const int shift_id_
shift_id is the start number of file_id_
The Particles class abstracts the storage and manipulation of particles.
void set_cross_section_scaling_factor(const double &xsec_scal)
Set the particle's initial cross_section_scaling_factor.
std::string next_event_()
Read the next event.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
std::string build_error_string(std::string message, const Line &line)
Builds a meaningful error message.
Helper structure for Experiment.
ParticleData contains the dynamic information of a certain particle.
Line consists of a line number and the contents of that line.
friend std::ostream & operator<<(std::ostream &, const ListModus &)
Writes the initial state for the List to the output stream.
std::streampos last_read_position_
last read position in current file
bf::path file_path_(const int file_id)
Return the absolute file path based on given integer.
const FourVector & momentum() const
Get the particle's 4-momentum.