Version: SMASH-3.3
spheremodus.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2012-2025
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/spheremodus.h"
11 
12 #include <cmath>
13 #include <cstdio>
14 #include <cstdlib>
15 #include <list>
16 #include <map>
17 #include <utility>
18 #include <vector>
19 
20 #include "smash/angles.h"
22 #include "smash/configuration.h"
23 #include "smash/constants.h"
24 #include "smash/cxx17compat.h"
26 #include "smash/fourvector.h"
27 #include "smash/hadgas_eos.h"
28 #include "smash/logging.h"
29 #include "smash/particles.h"
30 #include "smash/quantumsampling.h"
31 #include "smash/random.h"
32 #include "smash/threevector.h"
33 
34 namespace smash {
35 static constexpr int LSphere = LogArea::Sphere::id;
36 
38  const ExperimentParameters &)
39  : radius_(modus_config.take(InputKeys::modi_sphere_radius)),
40  sphere_temperature_(
41  modus_config.take(InputKeys::modi_sphere_temperature)),
42  start_time_(modus_config.take(InputKeys::modi_sphere_startTime)),
43  use_thermal_(
44  modus_config.take(InputKeys::modi_sphere_useThermalMultiplicities)),
45  mub_(modus_config.take(InputKeys::modi_sphere_baryonChemicalPotential)),
46  mus_(modus_config.take(InputKeys::modi_sphere_strangeChemicalPotential)),
47  muq_(modus_config.take(InputKeys::modi_sphere_chargeChemicalPotential)),
48  hf_multiplier_(
49  modus_config.take(InputKeys::modi_sphere_heavyFlavorMultiplier)),
50  account_for_resonance_widths_(
51  modus_config.take(InputKeys::modi_sphere_accountResonanceWidths)),
52  init_multipl_(use_thermal_
53  ? std::map<PdgCode, int>()
54  : modus_config.take(
55  InputKeys::modi_sphere_initialMultiplicities)),
56  init_distr_(modus_config.take(InputKeys::modi_sphere_initialCondition)),
57  radial_velocity_(
58  modus_config.take(InputKeys::modi_sphere_addRadialVelocity)),
59  radial_velocity_exponent_(
60  modus_config.take(InputKeys::modi_sphere_addRadialVelocityExponent)),
61  /* Note that it is crucial not to take other keys from the Jet section
62  * before Jet_PDG, since we want here the take to throw in case the user
63  * had a Jet section without the mandatory Jet_PDG key. If all other keys
64  * are taken first, the section is removed from the config because empty,
65  * and has_section(InputSections::m_s_jet) method would return false.
66  */
67  jet_pdg_(modus_config.has_section(InputSections::m_s_jet)
68  ? make_optional<PdgCode>(
69  modus_config.take(InputKeys::modi_sphere_jet_jetPdg))
70  : std::nullopt),
71  jet_mom_(modus_config.take(InputKeys::modi_sphere_jet_jetMomentum)),
72  jet_pos_(modus_config.take(InputKeys::modi_sphere_jet_jetPosition)),
73  jet_back_(modus_config.take(InputKeys::modi_sphere_jet_backToBack)),
74  jet_back_separation_(
75  jet_back_ ? modus_config.take(
76  InputKeys::modi_sphere_jet_backToBackSeparation)
77  : 0),
78  spin_interaction_type_(
79  modus_config.take(InputKeys::collTerm_spinInteractions)) {
80  if (!jet_back_ &&
82  throw std::invalid_argument(
83  "In order to specify 'Back_To_Back_Separation', 'Back_To_Back' must be "
84  "true.");
85  }
86  if (radial_velocity_ > 1.0) {
87  throw std::invalid_argument(
88  "Additional velocity cannot be greater than 1!");
89  }
90  if (sphere_temperature_ <= 0.0) {
91  throw std::invalid_argument("Temperature must be positive!");
92  }
93  if (radial_velocity_exponent_ < 0.0) {
94  throw std::invalid_argument("Flow velocity exponent cannot be negative!");
95  }
96 }
97 
98 /* console output on startup of sphere specific parameters */
99 std::ostream &operator<<(std::ostream &out, const SphereModus &m) {
100  out << "-- Sphere Modus:\nRadius of the sphere: " << m.radius_ << " fm\n";
101  if (m.use_thermal_) {
102  out << "Thermal multiplicities (T = " << m.sphere_temperature_
103  << " GeV, muB = " << m.mub_ << " GeV, muS = " << m.mus_
104  << " GeV, muQ = " << m.muq_ << " GeV)\n";
105  } else {
106  for (const auto &p : m.init_multipl_) {
107  ParticleTypePtr ptype = &ParticleType::find(p.first);
108  out << ptype->name() << " initial multiplicity " << p.second << '\n';
109  }
110  }
111  switch (m.init_distr_) {
113  out << "Boltzmann momentum distribution with T = "
114  << m.sphere_temperature_ << " GeV.\n";
115  break;
117  out << "Fermi/Bose momentum distribution with T = "
118  << m.sphere_temperature_ << " GeV.\n";
119  break;
121  out << "Sphere Initial Condition is IC_ES";
122  break;
124  out << "Sphere Initial Condition is IC_1M";
125  break;
127  out << "Sphere Initial Condition is IC_2M";
128  break;
130  out << "Sphere Initial Condition is IC_Massive";
131  break;
132  }
133  if (m.jet_pdg_) {
134  ParticleTypePtr ptype = &ParticleType::find(m.jet_pdg_.value());
135  const auto pos = m.jet_pos_;
136  if (m.jet_back_) {
137  ParticleTypePtr anti =
138  ptype->has_antiparticle() ? ptype->get_antiparticle() : ptype;
139  out << "Adding a dijet " << ptype->name() << anti->name()
140  << " centered at (" << pos.x1() << ", " << pos.x2() << ", "
141  << pos.x3() << ") separated by " << m.jet_back_separation_
142  << " fm,\neach with " << m.jet_mom_ << " GeV of initial momentum.\n";
143  } else {
144  out << "Adding a " << ptype->name() << " as a jet at (" << pos.x1()
145  << ", " << pos.x2() << ", " << pos.x3() << ") fm with " << m.jet_mom_
146  << " GeV of initial momentum.\n";
147  }
148  }
149  return out;
150 }
151 
152 /* initial_conditions - sets particle data for @particles */
154  const ExperimentParameters &parameters) {
155  FourVector momentum_total(0, 0, 0, 0);
156  const double T = this->sphere_temperature_;
157  const double V = 4.0 / 3.0 * M_PI * radius_ * radius_ * radius_;
158  /* Create NUMBER OF PARTICLES according to configuration */
159  if (use_thermal_) {
160  if (average_multipl_.empty()) {
161  for (const ParticleType &ptype : ParticleType::list_all()) {
162  const bool is_eos_particle = HadronGasEos::is_eos_particle(ptype);
163  const bool use_heavy_flavor = ptype.pdgcode().is_heavy_flavor() &&
165  if (is_eos_particle || use_heavy_flavor) {
166  const double n = HadronGasEos::partial_density(
168  average_multipl_[ptype.pdgcode()] = n * V * parameters.testparticles;
169  if (ptype.pdgcode().is_heavy_flavor()) {
170  average_multipl_[ptype.pdgcode()] *= hf_multiplier_;
171  }
172  }
173  }
174  }
175  double nb_init = 0.0, ns_init = 0.0, nq_init = 0.0;
176  for (const auto &mult : average_multipl_) {
177  const int thermal_mult_int = random::poisson(mult.second);
178  particles->create(thermal_mult_int, mult.first);
179  nb_init += mult.second * mult.first.baryon_number();
180  ns_init += mult.second * mult.first.strangeness();
181  nq_init += mult.second * mult.first.charge();
182  logg[LSphere].debug(mult.first, " initial multiplicity ",
183  thermal_mult_int);
184  }
185  logg[LSphere].info("Initial hadron gas baryon density ", nb_init);
186  logg[LSphere].info("Initial hadron gas strange density ", ns_init);
187  logg[LSphere].info("Initial hadron gas charge density ", nq_init);
188  } else {
189  for (const auto &p : init_multipl_) {
190  particles->create(p.second * parameters.testparticles, p.first);
191  logg[LSphere].debug("Particle ", p.first, " initial multiplicity ",
192  p.second);
193  }
194  }
195  std::unique_ptr<QuantumSampling> quantum_sampling;
197  quantum_sampling = std::make_unique<QuantumSampling>(init_multipl_, V, T);
198  }
199  /* loop over particle data to fill in momentum and position information */
200  for (ParticleData &data : *particles) {
201  Angles phitheta;
202  /* thermal momentum according Maxwell-Boltzmann distribution */
203  double momentum_radial = 0.0, mass = data.pole_mass();
204  /* assign momentum_radial according to requested distribution */
205  switch (init_distr_) {
207  momentum_radial = sample_momenta_IC_ES(T);
208  break;
210  momentum_radial = sample_momenta_1M_IC(T, mass);
211  break;
213  momentum_radial = sample_momenta_2M_IC(T, mass);
214  break;
216  momentum_radial = sample_momenta_non_eq_mass(T, mass);
217  break;
219  default:
221  ? data.type().mass()
222  : HadronGasEos::sample_mass_thermal(data.type(), 1.0 / T);
223  momentum_radial = sample_momenta_from_thermal(T, mass);
224  break;
226  /*
227  * **********************************************************************
228  * Sampling the thermal momentum according Bose/Fermi/Boltzmann
229  * distribution.
230  * We take the pole mass as the mass.
231  * **********************************************************************
232  */
233  mass = data.type().mass();
234  momentum_radial = quantum_sampling->sample(data.pdgcode());
235  break;
236  }
237  phitheta.distribute_isotropically();
238  logg[LSphere].debug(data.type().name(), "(id ", data.id(),
239  ") radial momentum ", momentum_radial, ", direction",
240  phitheta);
241  data.set_4momentum(mass, phitheta.threevec() * momentum_radial);
242  momentum_total += data.momentum();
243  /* uniform sampling in a sphere with radius r */
244  double position_radial;
245  position_radial = std::cbrt(random::canonical()) * radius_;
246  Angles pos_phitheta;
247  pos_phitheta.distribute_isotropically();
248  data.set_4position(
249  FourVector(start_time_, pos_phitheta.threevec() * position_radial));
250  data.set_formation_time(start_time_);
251  }
252 
253  /* Boost in radial direction with an underlying velocity field of the form
254  * u_r = u_0 * (r / R)^n
255  */
256  if (radial_velocity_ > 0.0) {
257  for (ParticleData &data : *particles) {
258  double particle_radius = std::sqrt(data.position().sqr3());
259  auto e_r = data.position().threevec() / particle_radius;
260  auto radial_velocity =
261  -1.0 * radial_velocity_ * e_r *
262  std::pow(particle_radius / radius_, radial_velocity_exponent_);
263  data.set_4momentum(data.momentum().lorentz_boost(radial_velocity));
264  momentum_total += data.momentum();
265  }
266  }
267 
268  /* Make total 3-momentum in sphere 0 and set unpolarized spin vector if spin
269  * interactions are enabled */
270  for (ParticleData &data : *particles) {
271  data.set_4momentum(data.momentum().abs(),
272  data.momentum().threevec() -
273  momentum_total.threevec() / particles->size());
275  data.set_unpolarized_spin_vector();
276  }
277  }
278 
279  /* Add a single highly energetic particle in the center of the sphere (jet) */
280  if (jet_pdg_) {
281  auto &pdg = jet_pdg_.value();
282  auto &jet_particle = particles->create(pdg);
283  auto displacement = ThreeVector(jet_back_separation_ / 2., 0., 0.);
284  jet_particle.set_formation_time(start_time_);
285  jet_particle.set_4position(
286  FourVector(start_time_, jet_pos_ + displacement));
287  jet_particle.set_4momentum(ParticleType::find(pdg).mass(),
288  ThreeVector(jet_mom_, 0., 0.));
289  if (jet_back_) {
290  auto &anti_pdg = pdg.has_antiparticle() ? pdg.get_antiparticle() : pdg;
291  auto &jet_antiparticle = particles->create(anti_pdg);
292  jet_antiparticle.set_formation_time(start_time_);
293  jet_antiparticle.set_4position(
294  FourVector(start_time_, jet_pos_ - displacement));
295  jet_antiparticle.set_4momentum(ParticleType::find(anti_pdg).mass(),
296  ThreeVector(-jet_mom_, 0., 0.));
297  }
299  jet_particle.set_unpolarized_spin_vector();
300  }
301  }
302 
303  /* Recalculate total momentum */
304  momentum_total = FourVector(0, 0, 0, 0);
305  for (ParticleData &data : *particles) {
306  momentum_total += data.momentum();
307  /* IC: debug checks */
308  logg[LSphere].debug() << data;
309  }
310  /* allows to check energy conservation */
311  logg[LSphere].debug() << "Sphere initial total 4-momentum [GeV]: "
312  << momentum_total;
313  return start_time_;
314 }
315 } // namespace smash
Angles provides a common interface for generating directions: i.e., two angles that should be interpr...
Definition: angles.h:59
ThreeVector threevec() const
Definition: angles.h:288
void distribute_isotropically()
Populate the object with a new direction.
Definition: angles.h:199
Interface to the SMASH configuration files.
bool has_value(const Key< T > &key) const
Return whether there is a non-empty value behind the requested key (which is supposed not to refer to...
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
ThreeVector threevec() const
Definition: fourvector.h:329
static double partial_density(const ParticleType &ptype, double T, double mub, double mus, double muq, bool account_for_resonance_widths=false)
Compute partial density of one hadron sort.
Definition: hadgas_eos.cc:270
static double sample_mass_thermal(const ParticleType &ptype, double beta)
Sample resonance mass in a thermal medium.
Definition: hadgas_eos.cc:385
static bool is_eos_particle(const ParticleType &ptype)
Check if a particle belongs to the EoS.
Definition: hadgas_eos.h:355
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:59
A pointer-like interface to global references to ParticleType objects.
Definition: particletype.h:682
Particle type contains the static properties of a particle species.
Definition: particletype.h:98
ParticleTypePtr get_antiparticle() const
Definition: particletype.h:763
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Definition: particletype.cc:99
const std::string & name() const
Definition: particletype.h:142
static const ParticleTypeList & list_all()
Definition: particletype.cc:51
bool has_antiparticle() const
Definition: particletype.h:160
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
size_t size() const
Definition: particles.h:87
void create(size_t n, PdgCode pdg)
Add n particles of the same type (pdg) to the list.
Definition: particles.cc:66
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:108
SphereModus: Provides a modus for expanding matter calculations.
Definition: spheremodus.h:49
const bool account_for_resonance_widths_
In case of thermal initialization:
Definition: spheremodus.h:121
const bool use_thermal_
Whether to use a thermal initialization for all particles instead of specific numbers.
Definition: spheremodus.h:94
const double muq_
Charge chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: spheremodus.h:109
const ThreeVector jet_pos_
Initial position of the jet particle; only used if jet_pdg_ is not nullopt.
Definition: spheremodus.h:162
double sphere_temperature_
Temperature for momentum distribution (in GeV)
Definition: spheremodus.h:87
const double start_time_
Starting time for the Sphere.
Definition: spheremodus.h:89
const double radial_velocity_exponent_
Parameter in the initial flow velocity profile of particles in the sphere, which has the form .
Definition: spheremodus.h:146
const SphereInitialCondition init_distr_
Initialization scheme for momenta in the sphere; used for expanding metric setup.
Definition: spheremodus.h:136
const std::optional< PdgCode > jet_pdg_
Optional PDG code of the particle to use as a jet, i.e.
Definition: spheremodus.h:154
SphereModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor.
Definition: spheremodus.cc:37
const bool jet_back_
Create the back to back jet with the corresponding antiparticle; only used if jet_pdg_ is not nullopt...
Definition: spheremodus.h:167
const SpinInteractionType spin_interaction_type_
Spin interaction type.
Definition: spheremodus.h:174
const double hf_multiplier_
Multiplicative factor for thermal multiplicity of heavy flavored hadrons; only used if use_thermal_ i...
Definition: spheremodus.h:114
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: spheremodus.cc:153
std::map< PdgCode, double > average_multipl_
Average multiplicities in case of thermal initialization.
Definition: spheremodus.h:131
const double mub_
Baryon chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: spheremodus.h:99
const double jet_mom_
Initial momentum of the jet particle; only used if jet_pdg_ is not nullopt.
Definition: spheremodus.h:158
const std::map< PdgCode, int > init_multipl_
Particle multiplicities at initialization; required if use_thermal_ is false.
Definition: spheremodus.h:126
const double jet_back_separation_
Initial separation between the back to back jets; can only be set by the user if jet_back_ is true.
Definition: spheremodus.h:172
const double mus_
Strange chemical potential for thermal initialization; only used if use_thermal_ is true.
Definition: spheremodus.h:104
const double radial_velocity_
Parameter in the initial flow velocity profile of particles in the sphere, which has the form .
Definition: spheremodus.h:141
double radius_
Sphere radius (in fm)
Definition: spheremodus.h:85
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:31
Collection of useful constants that are known at compile time.
@ ThermalMomentaBoltzmann
A thermalized ensemble is generated, with momenta sampled from a Maxwell-Boltzmann distribution.
@ IC_ES
Off-equilibrium distribution used in massless comparisons of SMASH to the extended universe metric.
@ ThermalMomentaQuantum
A thermalized ensemble is generated, with momenta of baryons(mesons) sampled from a Fermi(Bose) distr...
@ IC_Massive
A generalization of IC_ES for the non-zero mass case; note that there is currently no analytical comp...
@ IC_2M
Off-equilibrium distribution used in massless comparisons of SMASH to the extended universe metric.
@ IC_1M
Off-equilibrium distribution used in massless comparisons of SMASH to the extended universe metric.
@ Off
No spin interactions.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:555
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:40
constexpr int p
Proton.
constexpr int n
Neutron.
int poisson(const T &lam)
Returns a Poisson distributed random number.
Definition: random.h:226
T canonical()
Definition: random.h:113
Definition: action.h:24
static constexpr int LSphere
Definition: spheremodus.cc:35
double sample_momenta_from_thermal(const double temperature, const double mass)
Samples a momentum from the Maxwell-Boltzmann (thermal) distribution in a faster way,...
double sample_momenta_IC_ES(const double temperature)
Sample momenta according to the momentum distribution in Bazow:2016oky .
double sample_momenta_non_eq_mass(const double temperature, const double mass)
Samples a momentum via rejection method from the non-equilibrium distribution.
double sample_momenta_1M_IC(const double temperature, const double mass)
Samples a momentum from the non-equilibrium distribution 1M_IC from Bazow:2016oky .
double sample_momenta_2M_IC(const double temperature, const double mass)
Samples a momentum from the non-equilibrium distribution 2M_IC from Bazow:2016oky .
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:41
Helper structure for Experiment.
int testparticles
Number of test-particles.
A container to keep track of all ever existed input keys.
Definition: input_keys.h:1116
static const Key< double > modi_sphere_jet_backToBackSeparation
See user guide description for more information.
Definition: input_keys.h:4459
A container to keep track of all ever existed sections in the input file.
Definition: input_keys.h:48