Version: SMASH-1.8
boxmodus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2020
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #include <cmath>
8 #include <cstdio>
9 #include <cstdlib>
10 #include <list>
11 #include <map>
12 #include <utility>
13 #include <vector>
14 
15 #include "smash/algorithms.h"
16 #include "smash/angles.h"
17 #include "smash/boxmodus.h"
18 #include "smash/configuration.h"
19 #include "smash/constants.h"
20 #include "smash/cxx14compat.h"
21 #include "smash/distributions.h"
23 #include "smash/hadgas_eos.h"
24 #include "smash/logging.h"
25 #include "smash/macros.h"
26 #include "smash/outputinterface.h"
27 #include "smash/particles.h"
28 #include "smash/processbranch.h"
29 #include "smash/quantumnumbers.h"
30 #include "smash/random.h"
31 #include "smash/threevector.h"
33 
34 namespace smash {
35 static constexpr int LBox = LogArea::Box::id;
36 
37 /* console output on startup of box specific parameters */
38 std::ostream &operator<<(std::ostream &out, const BoxModus &m) {
39  out << "-- Box Modus:\nSize of the box: (" << m.length_ << " fm)³\n";
40  if (m.use_thermal_) {
41  out << "Thermal multiplicities "
42  << "(T = " << m.temperature_ << " GeV, muB = " << m.mub_
43  << " GeV, muS = " << m.mus_ << " GeV)\n";
44  } else {
45  for (const auto &p : m.init_multipl_) {
46  ParticleTypePtr ptype = &ParticleType::find(p.first);
47  out << ptype->name() << " initial multiplicity " << p.second << '\n';
48  }
49  }
51  out << "All initial momenta = 3T = " << 3 * m.temperature_ << " GeV\n";
52  } else {
53  out << "Boltzmann momentum distribution with T = " << m.temperature_
54  << " GeV.\n";
55  }
56  if (m.insert_jet_) {
58  out << "Adding a " << ptype->name() << " as a jet in the middle "
59  << "of the box with " << m.jet_mom_ << " GeV initial momentum.\n";
60  }
61  return out;
62 }
63 
215  const ExperimentParameters &parameters)
216  : initial_condition_(modus_config.take({"Box", "Initial_Condition"})),
217  length_(modus_config.take({"Box", "Length"})),
218  equilibration_time_(
219  modus_config.take({"Box", "Equilibration_Time"}, -1.)),
220  temperature_(modus_config.take({"Box", "Temperature"})),
221  start_time_(modus_config.take({"Box", "Start_Time"}, 0.)),
222  use_thermal_(
223  modus_config.take({"Box", "Use_Thermal_Multiplicities"}, false)),
224  mub_(modus_config.take({"Box", "Baryon_Chemical_Potential"}, 0.)),
225  mus_(modus_config.take({"Box", "Strange_Chemical_Potential"}, 0.)),
226  account_for_resonance_widths_(
227  modus_config.take({"Box", "Account_Resonance_Widths"}, true)),
228  init_multipl_(use_thermal_
229  ? std::map<PdgCode, int>()
230  : modus_config.take({"Box", "Init_Multiplicities"})
231  .convert_for(init_multipl_)),
232  insert_jet_(modus_config.has_value({"Box", "Jet", "Jet_PDG"})),
233  jet_pdg_(insert_jet_ ? modus_config.take({"Box", "Jet", "Jet_PDG"})
234  .convert_for(jet_pdg_)
235  : pdg::p), // dummy default; never used
236  jet_mom_(modus_config.take({"Box", "Jet", "Jet_Momentum"}, 20.)) {
237  if (parameters.res_lifetime_factor < 0.) {
238  throw std::invalid_argument(
239  "Resonance lifetime modifier cannot be negative!");
240  }
241 }
242 
244  const ExperimentParameters &parameters) {
245  double momentum_radial = 0, mass;
246  Angles phitheta;
247  FourVector momentum_total(0, 0, 0, 0);
248  auto uniform_length = random::make_uniform_distribution(0.0, this->length_);
249  const double T = this->temperature_;
250  /* Create NUMBER OF PARTICLES according to configuration, or thermal case */
251  if (use_thermal_) {
252  const double V = length_ * length_ * length_;
253  if (average_multipl_.empty()) {
254  for (const ParticleType &ptype : ParticleType::list_all()) {
255  if (HadronGasEos::is_eos_particle(ptype)) {
256  const double lifetime_factor =
257  ptype.is_stable() ? 1. : parameters.res_lifetime_factor;
258  const double n = lifetime_factor * HadronGasEos::partial_density(
259  ptype, T, mub_, mus_,
261  average_multipl_[ptype.pdgcode()] = n * V * parameters.testparticles;
262  }
263  }
264  }
265  double nb_init = 0.0, ns_init = 0.0;
266  for (const auto &mult : average_multipl_) {
267  const int thermal_mult_int = random::poisson(mult.second);
268  particles->create(thermal_mult_int, mult.first);
269  nb_init += mult.second * mult.first.baryon_number();
270  ns_init += mult.second * mult.first.strangeness();
271  logg[LBox].debug(mult.first, " initial multiplicity ", thermal_mult_int);
272  }
273  logg[LBox].info("Initial hadron gas baryon density ", nb_init);
274  logg[LBox].info("Initial hadron gas strange density ", ns_init);
275  } else {
276  for (const auto &p : init_multipl_) {
277  particles->create(p.second * parameters.testparticles, p.first);
278  logg[LBox].debug("Particle ", p.first, " initial multiplicity ",
279  p.second);
280  }
281  }
282 
283  for (ParticleData &data : *particles) {
284  /* Set MOMENTUM SPACE distribution */
286  /* initial thermal momentum is the average 3T */
287  momentum_radial = 3.0 * T;
288  mass = data.pole_mass();
289  } else {
290  /* thermal momentum according Maxwell-Boltzmann distribution */
292  ? data.type().mass()
293  : HadronGasEos::sample_mass_thermal(data.type(), 1.0 / T);
294  momentum_radial = sample_momenta_from_thermal(T, mass);
295  }
296  phitheta.distribute_isotropically();
297  logg[LBox].debug(data.type().name(), "(id ", data.id(),
298  ") radial momentum ", momentum_radial, ", direction",
299  phitheta);
300  data.set_4momentum(mass, phitheta.threevec() * momentum_radial);
301  momentum_total += data.momentum();
302 
303  /* Set COORDINATE SPACE distribution */
304  ThreeVector pos{uniform_length(), uniform_length(), uniform_length()};
305  data.set_4position(FourVector(start_time_, pos));
307  data.set_formation_time(start_time_);
308  }
309 
310  /* Make total 3-momentum 0 */
311  for (ParticleData &data : *particles) {
312  data.set_4momentum(data.momentum().abs(),
313  data.momentum().threevec() -
314  momentum_total.threevec() / particles->size());
315  }
316 
317  /* Add a single highly energetic particle in the center of the box (jet) */
318  if (insert_jet_) {
319  auto &jet_particle = particles->create(jet_pdg_);
320  jet_particle.set_formation_time(start_time_);
321  jet_particle.set_4position(FourVector(start_time_, 0., 0., 0.));
322  jet_particle.set_4momentum(ParticleType::find(jet_pdg_).mass(),
323  ThreeVector(jet_mom_, 0., 0.));
324  }
325 
326  /* Recalculate total momentum */
327  momentum_total = FourVector(0, 0, 0, 0);
328  for (ParticleData &data : *particles) {
329  momentum_total += data.momentum();
330  /* IC: debug checks */
331  logg[LBox].debug() << data;
332  }
333  /* allows to check energy conservation */
334  logg[LBox].debug() << "Initial total 4-momentum [GeV]: " << momentum_total;
335  return start_time_;
336 }
337 
339  const OutputsList &output_list) {
340  int wraps = 0;
341 
342  for (ParticleData &data : *particles) {
343  FourVector position = data.position();
344  bool wall_hit = enforce_periodic_boundaries(position.begin() + 1,
345  position.end(), length_);
346  if (wall_hit) {
347  const ParticleData incoming_particle(data);
348  data.set_4position(position);
349  ++wraps;
350  ActionPtr action =
351  make_unique<WallcrossingAction>(incoming_particle, data);
352  for (const auto &output : output_list) {
353  if (!output->is_dilepton_output() && !output->is_photon_output()) {
354  output->at_interaction(*action, 0.);
355  }
356  }
357  }
358  }
359  logg[LBox].debug("Moved ", wraps, " particles back into the box.");
360  return wraps;
361 }
362 
363 } // namespace smash
smash
Definition: action.h:24
smash::BoxModus::account_for_resonance_widths_
const bool account_for_resonance_widths_
In case of thermal initialization: true – account for resonance spectral functions,...
Definition: boxmodus.h:163
quantumnumbers.h
processbranch.h
algorithms.h
smash::ParticleData
Definition: particledata.h:52
smash::BoxModus::mub_
const double mub_
Baryon chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: boxmodus.h:152
smash::HadronGasEos::partial_density
static double partial_density(const ParticleType &ptype, double T, double mub, double mus, bool account_for_resonance_widths=false)
Compute partial density of one hadron sort.
Definition: hadgas_eos.cc:234
smash::BoxModus::init_multipl_
const std::map< PdgCode, int > init_multipl_
Particle multiplicities at initialization; required if use_thermal_ is false.
Definition: boxmodus.h:168
smash::BoxModus::length_
const double length_
Length of the cube's edge in fm/c.
Definition: boxmodus.h:136
cxx14compat.h
smash::BoxModus::use_thermal_
const bool use_thermal_
Whether to use a thermal initialization for all particles instead of specific numbers.
Definition: boxmodus.h:147
smash::BoxModus::jet_pdg_
const PdgCode jet_pdg_
Pdg of the particle to use as a jet; necessary if insert_jet_ is true, unused otherwise.
Definition: boxmodus.h:184
smash::BoxModus::temperature_
const double temperature_
Temperature of the Box in GeV.
Definition: boxmodus.h:140
smash::enforce_periodic_boundaries
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.
Definition: algorithms.h:53
smash::BoxModus::insert_jet_
const bool insert_jet_
Whether to insert a single high energy particle at the center of the box (0,0,0).
Definition: boxmodus.h:179
macros.h
smash::operator<<
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Definition: action.h:463
smash::BoxModus
Definition: boxmodus.h:46
smash::Angles::distribute_isotropically
void distribute_isotropically()
Populate the object with a new direction.
Definition: angles.h:188
experimentparameters.h
smash::BoxModus::initial_condition_
const BoxInitialCondition initial_condition_
Initial momenta distribution: thermal or peaked momenta.
Definition: boxmodus.h:134
smash::FourVector::begin
iterator begin()
Definition: fourvector.h:281
smash::ExperimentParameters::res_lifetime_factor
double res_lifetime_factor
Multiplicative factor to be applied to resonance lifetimes; in the case of thermal multiplicities thi...
Definition: experimentparameters.h:57
smash::logg
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
smash::ParticleType::find
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Definition: particletype.cc:105
random.h
smash::BoxModus::mus_
const double mus_
Strange chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: boxmodus.h:157
angles.h
smash::Configuration
Interface to the SMASH configuration files.
Definition: configuration.h:464
smash::Particles::create
void create(size_t n, PdgCode pdg)
Add n particles of the same type (pdg) to the list.
Definition: particles.cc:66
wallcrossingaction.h
smash::ParticleTypePtr
Definition: particletype.h:663
smash::ThreeVector
Definition: threevector.h:31
outputinterface.h
boxmodus.h
smash::HadronGasEos::sample_mass_thermal
static double sample_mass_thermal(const ParticleType &ptype, double beta)
Sample resonance mass in a thermal medium.
Definition: hadgas_eos.cc:325
threevector.h
smash::BoxModus::average_multipl_
std::map< PdgCode, double > average_multipl_
Average multiplicities in case of thermal initialization.
Definition: boxmodus.h:173
smash::ParticleType
Definition: particletype.h:97
smash::ParticleType::name
const std::string & name() const
Definition: particletype.h:141
distributions.h
smash::random::poisson
int poisson(const T &lam)
Returns a Poisson distributed random number.
Definition: random.h:226
smash::random::make_uniform_distribution
uniform_dist< T > make_uniform_distribution(T min, T max)
Definition: random.h:135
smash::FourVector::end
iterator end()
Definition: fourvector.h:284
particles.h
smash::LBox
static constexpr int LBox
Definition: boxmodus.cc:35
smash::Angles::threevec
ThreeVector threevec() const
Definition: angles.h:268
smash::BoxModus::initial_conditions
double initial_conditions(Particles *particles, const ExperimentParameters &parameters)
Generates initial state of the particles in the system according to specified parameters: number of p...
Definition: boxmodus.cc:243
smash::Particles
Definition: particles.h:33
smash::BoxModus::BoxModus
BoxModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor.
Definition: boxmodus.cc:214
smash::HadronGasEos::is_eos_particle
static bool is_eos_particle(const ParticleType &ptype)
Check if a particle belongs to the EoS.
Definition: hadgas_eos.h:308
constants.h
logging.h
configuration.h
BoxInitialCondition::PeakedMomenta
smash::ExperimentParameters
Helper structure for Experiment.
Definition: experimentparameters.h:23
smash::FourVector
Definition: fourvector.h:33
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::Angles
Angles provides a common interface for generating directions: i.e., two angles that should be interpr...
Definition: angles.h:59
hadgas_eos.h
smash::pdg::n
constexpr int n
Neutron.
Definition: pdgcode_constants.h:30
smash::BoxModus::impose_boundary_conditions
int impose_boundary_conditions(Particles *particles, const OutputsList &output_list={})
Enforces that all particles are inside the box at the beginning of an event.
Definition: boxmodus.cc:338
smash::sample_momenta_from_thermal
double sample_momenta_from_thermal(const double temperature, const double mass)
Samples a momentum from the Maxwell-Boltzmann (thermal) distribution in a faster way,...
Definition: distributions.cc:190
smash::ExperimentParameters::testparticles
int testparticles
Number of test particle.
Definition: experimentparameters.h:31
smash::FourVector::threevec
ThreeVector threevec() const
Definition: fourvector.h:319
smash::BoxModus::start_time_
const double start_time_
Initial time of the box.
Definition: boxmodus.h:142
smash::ParticleType::list_all
static const ParticleTypeList & list_all()
Definition: particletype.cc:57
smash::BoxModus::jet_mom_
const double jet_mom_
Initial momentum of the jet particle; only used if insert_jet_ is true.
Definition: boxmodus.h:188