Version: SMASH-1.5
collidermodus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2018
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 
8 #include "smash/collidermodus.h"
9 
10 #include <algorithm>
11 #include <cmath>
12 #include <cstdlib>
13 #include <cstring>
14 #include <memory>
15 #include <stdexcept>
16 #include <tuple>
17 #include <utility>
18 
19 #include "smash/angles.h"
20 #include "smash/configuration.h"
21 #include "smash/cxx14compat.h"
23 #include "smash/fourvector.h"
24 #include "smash/interpolation.h"
25 #include "smash/kinematics.h"
26 #include "smash/logging.h"
27 #include "smash/numerics.h"
28 #include "smash/particles.h"
29 #include "smash/pdgcode.h"
30 #include "smash/random.h"
31 
32 namespace smash {
33 
257  const ExperimentParameters &params) {
258  Configuration modus_cfg = modus_config["Collider"];
259 
260  // Get the reference frame for the collision calculation.
261  if (modus_cfg.has_value({"Calculation_Frame"})) {
262  frame_ = modus_cfg.take({"Calculation_Frame"});
263  }
264 
266  if (modus_cfg.has_value({"Collisions_Within_Nucleus"})) {
267  cll_in_nucleus_ = modus_cfg.take({"Collisions_Within_Nucleus"});
268  }
269 
270  // Set up the projectile nucleus
271  Configuration proj_cfg = modus_cfg["Projectile"];
272  if (proj_cfg.has_value({"Deformed"})) {
273  projectile_ =
274  create_deformed_nucleus(proj_cfg, params.testparticles, "projectile");
275  } else {
276  projectile_ = make_unique<Nucleus>(proj_cfg, params.testparticles);
277  }
278  if (projectile_->size() < 1) {
279  throw ColliderEmpty("Input Error: Projectile nucleus is empty.");
280  }
281 
282  // Set up the target nucleus
283  Configuration targ_cfg = modus_cfg["Target"];
284  if (targ_cfg.has_value({"Deformed"})) {
285  target_ = create_deformed_nucleus(targ_cfg, params.testparticles, "target");
286  } else {
287  target_ = make_unique<Nucleus>(targ_cfg, params.testparticles);
288  }
289  if (target_->size() < 1) {
290  throw ColliderEmpty("Input Error: Target nucleus is empty.");
291  }
292 
293  // Get the Fermi-Motion input (off, on, frozen)
294  if (modus_cfg.has_value({"Fermi_Motion"})) {
295  // We only read the value, because it is still required by the experiment
296  // class to make sure we don't use frozen Fermi momenta with potentials.
297  fermi_motion_ = modus_cfg.read({"Fermi_Motion"});
298  }
299 
300  // Get the total nucleus-nucleus collision energy. Since there is
301  // no meaningful choice for a default energy, we require the user to
302  // give one (and only one) energy input from the available options.
303  int energy_input = 0;
304  const double mass_projec = projectile_->mass();
305  const double mass_target = target_->mass();
306  // average mass of a particle in that nucleus
307  const double mass_a =
308  projectile_->mass() / projectile_->number_of_particles();
309  const double mass_b = target_->mass() / target_->number_of_particles();
310  // Option 1: Center of mass energy.
311  if (modus_cfg.has_value({"Sqrtsnn"})) {
312  sqrt_s_NN_ = modus_cfg.take({"Sqrtsnn"});
313  // Check that input satisfies the lower bound (everything at rest).
314  if (sqrt_s_NN_ <= mass_a + mass_b) {
316  "Input Error: sqrt(s_NN) is not larger than masses:\n" +
317  std::to_string(sqrt_s_NN_) + " GeV <= " + std::to_string(mass_a) +
318  " GeV + " + std::to_string(mass_b) + " GeV.");
319  }
320  // Set the total nucleus-nucleus collision energy.
321  total_s_ = (sqrt_s_NN_ * sqrt_s_NN_ - mass_a * mass_a - mass_b * mass_b) *
322  mass_projec * mass_target / (mass_a * mass_b) +
323  mass_projec * mass_projec + mass_target * mass_target;
324  energy_input++;
325  }
326  /* Option 2: Kinetic energy per nucleon of the projectile nucleus
327  * (target at rest). */
328  if (modus_cfg.has_value({"E_Kin"})) {
329  const double e_kin = modus_cfg.take({"E_Kin"});
330  if (e_kin < 0) {
332  "Input Error: "
333  "E_Kin must be nonnegative.");
334  }
335  // Set the total nucleus-nucleus collision energy.
336  total_s_ = s_from_Ekin(e_kin * projectile_->number_of_particles(),
337  mass_projec, mass_target);
338  sqrt_s_NN_ = std::sqrt(s_from_Ekin(e_kin, mass_a, mass_b));
339  energy_input++;
340  }
341  // Option 3: Momentum of the projectile nucleus (target at rest).
342  if (modus_cfg.has_value({"P_Lab"})) {
343  const double p_lab = modus_cfg.take({"P_Lab"});
344  if (p_lab < 0) {
346  "Input Error: "
347  "P_Lab must be nonnegative.");
348  }
349  // Set the total nucleus-nucleus collision energy.
350  total_s_ = s_from_plab(p_lab * projectile_->number_of_particles(),
351  mass_projec, mass_target);
352  sqrt_s_NN_ = std::sqrt(s_from_plab(p_lab, mass_a, mass_b));
353  energy_input++;
354  }
355  if (energy_input == 0) {
356  throw std::domain_error(
357  "Input Error: Non-existent collision energy. "
358  "Please provide one of Sqrtsnn/E_Kin/P_Lab.");
359  }
360  if (energy_input > 1) {
361  throw std::domain_error(
362  "Input Error: Redundant collision energy. "
363  "Please provide only one of Sqrtsnn/E_Kin/P_Lab.");
364  }
365 
366  /* Impact parameter setting: Either "Value", "Range", "Max" or "Sample".
367  * Unspecified means 0 impact parameter.*/
368  if (modus_cfg.has_value({"Impact", "Value"})) {
369  impact_ = modus_cfg.take({"Impact", "Value"});
370  imp_min_ = impact_;
371  imp_max_ = impact_;
372  } else {
373  // If impact is not supplied by value, inspect sampling parameters:
374  if (modus_cfg.has_value({"Impact", "Sample"})) {
375  sampling_ = modus_cfg.take({"Impact", "Sample"});
376  if (sampling_ == Sampling::Custom) {
377  if (!(modus_cfg.has_value({"Impact", "Values"}) ||
378  modus_cfg.has_value({"Impact", "Yields"}))) {
379  throw std::domain_error(
380  "Input Error: Need impact parameter spectrum for custom "
381  "sampling. "
382  "Please provide Values and Yields.");
383  }
384  const std::vector<double> impacts =
385  modus_cfg.take({"Impact", "Values"});
386  const std::vector<double> yields = modus_cfg.take({"Impact", "Yields"});
387  if (impacts.size() != yields.size()) {
388  throw std::domain_error(
389  "Input Error: Need as many impact parameter values as yields. "
390  "Please make sure that Values and Yields have the same length.");
391  }
392  impact_interpolation_ = make_unique<InterpolateDataLinear<double>>(
393  InterpolateDataLinear<double>(impacts, yields));
394 
395  const auto imp_minmax =
396  std::minmax_element(impacts.begin(), impacts.end());
397  imp_min_ = *imp_minmax.first;
398  imp_max_ = *imp_minmax.second;
399  yield_max_ = *std::max_element(yields.begin(), yields.end());
400  }
401  }
402  if (modus_cfg.has_value({"Impact", "Range"})) {
403  const std::array<double, 2> range = modus_cfg.take({"Impact", "Range"});
404  imp_min_ = range[0];
405  imp_max_ = range[1];
406  }
407  if (modus_cfg.has_value({"Impact", "Max"})) {
408  imp_min_ = 0.0;
409  imp_max_ = modus_cfg.take({"Impact", "Max"});
410  }
411  }
413 
414  // Look for user-defined initial separation between nuclei.
415  if (modus_cfg.has_value({"Initial_Distance"})) {
416  initial_z_displacement_ = modus_cfg.take({"Initial_Distance"});
417  // the displacement is half the distance (both nuclei are shifted
418  // initial_z_displacement_ away from origin)
420  }
421 }
422 
423 std::ostream &operator<<(std::ostream &out, const ColliderModus &m) {
424  return out << "-- Collider Modus:\n"
425  << "sqrt(S) (nucleus-nucleus) = "
426  << format(std::sqrt(m.total_s_), "GeV\n")
427  << "sqrt(S) (nucleon-nucleon) = " << format(m.sqrt_s_NN_, "GeV\n")
428  << "Projectile:\n"
429  << *m.projectile_ << "\nTarget:\n"
430  << *m.target_;
431 }
432 
433 std::unique_ptr<DeformedNucleus> ColliderModus::create_deformed_nucleus(
434  Configuration &nucleus_cfg, int ntest, const std::string &nucleus_type) {
435  bool auto_deform = nucleus_cfg.take({"Deformed", "Automatic"});
436  bool is_beta2 = nucleus_cfg.has_value({"Deformed", "Beta_2"}) ? true : false;
437  bool is_beta4 = nucleus_cfg.has_value({"Deformed", "Beta_4"}) ? true : false;
438  std::unique_ptr<DeformedNucleus> nucleus;
439 
440  if ((auto_deform && (!is_beta2 && !is_beta4)) ||
441  (!auto_deform && (is_beta2 && is_beta4))) {
442  nucleus = make_unique<DeformedNucleus>(nucleus_cfg, ntest);
443  return nucleus;
444  } else {
445  throw std::domain_error("Deformation of " + nucleus_type +
446  " nucleus not configured "
447  "properly, please check whether all necessary "
448  "parameters are set.");
449  }
450 }
451 
453  const ExperimentParameters &) {
454  const auto &log = logger<LogArea::Collider>();
455  sample_impact();
456 
457  log.info() << "Impact parameter = " << format(impact_, "fm");
458  // Populate the nuclei with appropriately distributed nucleons.
459  // If deformed, this includes rotating the nucleus.
460  projectile_->arrange_nucleons();
461  target_->arrange_nucleons();
462 
463  // Use the total mandelstam variable to get the frame-dependent velocity for
464  // each nucleus. Position a is projectile, position b is target.
465  double v_a, v_b;
466  std::tie(v_a, v_b) =
467  get_velocities(total_s_, projectile_->mass(), target_->mass());
468 
469  // If velocities are larger or equal to 1, throw an exception.
470  if (v_a >= 1.0 || v_b >= 1.0) {
471  throw std::domain_error(
472  "Found velocity equal to or larger than 1 in "
473  "ColliderModus::initial_conditions.\nConsider using "
474  "the center of velocity reference frame.");
475  }
476 
477  // Calculate the beam velocity of the projectile and the target, which will be
478  // used to calculate the beam momenta in experiment.cc
480  velocity_projectile_ = v_a;
481  velocity_target_ = v_b;
482  }
483 
484  // Generate Fermi momenta if necessary
487  // Frozen: Fermi momenta will be ignored during the propagation to
488  // avoid that the nuclei will fly apart.
489  projectile_->generate_fermi_momenta();
490  target_->generate_fermi_momenta();
492  log.info() << "Fermi motion is ON.";
493  } else {
494  log.info() << "FROZEN Fermi motion is on.";
495  }
496  } else if (fermi_motion_ == FermiMotion::Off) {
497  // No Fermi-momenta are generated in this case
498  log.info() << "Fermi motion is OFF.";
499  } else {
500  throw std::domain_error("Invalid Fermi_Motion input.");
501  }
502 
503  // Boost the nuclei to the appropriate velocity.
504  projectile_->boost(v_a);
505  target_->boost(v_b);
506 
507  // Shift the nuclei into starting positions. Contracted spheres with
508  // nuclear radii should touch exactly at t=0. Modus starts at negative
509  // time corresponding to additional initial displacement.
510  const double d_a = std::max(0., projectile_->get_diffusiveness());
511  const double d_b = std::max(0., target_->get_diffusiveness());
512  const double r_a = projectile_->get_nuclear_radius();
513  const double r_b = target_->get_nuclear_radius();
514  const double dz = initial_z_displacement_;
515 
516  const double simulation_time = -dz / std::abs(v_a);
517  const double proj_z = -dz - std::sqrt(1.0 - v_a * v_a) * (r_a + d_a);
518  const double targ_z =
519  +dz * std::abs(v_b / v_a) + std::sqrt(1.0 - v_b * v_b) * (r_b + d_b);
520  projectile_->shift(proj_z, +impact_ / 2.0, simulation_time);
521  target_->shift(targ_z, -impact_ / 2.0, simulation_time);
522 
523  // Put the particles in the nuclei into code particles.
524  projectile_->copy_particles(particles);
525  target_->copy_particles(particles);
526  return simulation_time;
527 }
528 
530  switch (sampling_) {
531  case Sampling::Quadratic: {
532  // quadratic sampling: Note that for bmin > bmax, this still yields
533  // the correct distribution (however canonical() = 0 is then the
534  // upper end, not the lower).
535  impact_ = std::sqrt(imp_min_ * imp_min_ +
538  } break;
539  case Sampling::Custom: {
540  // rejection sampling based on given distribution
541  assert(impact_interpolation_ != nullptr);
542  double probability_random = 1;
543  double probability = 0;
544  double b;
545  while (probability_random > probability) {
547  probability = (*impact_interpolation_)(b) / yield_max_;
548  assert(probability < 1.);
549  probability_random = random::uniform(0., 1.);
550  }
551  impact_ = b;
552  } break;
553  case Sampling::Uniform: {
554  // linear sampling. Still, min > max works fine.
556  }
557  }
558 }
559 
560 std::pair<double, double> ColliderModus::get_velocities(double s, double m_a,
561  double m_b) {
562  double v_a = 0.0;
563  double v_b = 0.0;
564  // Frame dependent calculations of velocities. Assume v_a >= 0, v_b <= 0.
565  switch (frame_) {
567  v_a = center_of_velocity_v(s, m_a, m_b);
568  v_b = -v_a;
569  break;
571  // Compute center of mass momentum.
572  double pCM = pCM_from_s(s, m_a, m_b);
573  v_a = pCM / std::sqrt(m_a * m_a + pCM * pCM);
574  v_b = -pCM / std::sqrt(m_b * m_b + pCM * pCM);
575  } break;
577  v_a = fixed_target_projectile_v(s, m_a, m_b);
578  break;
579  default:
580  throw std::domain_error(
581  "Invalid reference frame in "
582  "ColliderModus::get_velocities.");
583  }
584  return std::make_pair(v_a, v_b);
585 }
586 
587 } // namespace smash
Value read(std::initializer_list< const char *> keys) const
Additional interface for SMASH to read configuration values without removing them.
FormattingHelper< T > format(const T &value, const char *unit, int width=-1, int precision=-1)
Acts as a stream modifier for std::ostream to output an object with an optional suffix string and wit...
Definition: logging.h:310
double yield_max_
Maximum value of yield. Needed for custom impact parameter sampling.
Thrown when the requested energy is smaller than the masses of two particles.
Definition: modusdefault.h:169
double fixed_target_projectile_v(double s, double ma, double mb)
Definition: kinematics.h:39
double velocity_target_
Beam velocity of the target.
static std::unique_ptr< DeformedNucleus > create_deformed_nucleus(Configuration &nucleus_cfg, const int ntest, const std::string &nucleus_type)
Configure Deformed Nucleus.
double center_of_velocity_v(double s, double ma, double mb)
Definition: kinematics.h:26
double impact_
Impact parameter.
T pCM_from_s(const T s, const T mass_a, const T mass_b) noexcept
Definition: kinematics.h:66
Interface to the SMASH configuration files.
std::unique_ptr< InterpolateDataLinear< double > > impact_interpolation_
Pointer to the impact parameter interpolation.
double imp_min_
Minimum value of impact parameter.
Generic numerical functions.
T canonical()
Definition: random.h:110
ColliderModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor.
bool has_value(std::initializer_list< const char *> keys) const
Returns whether there is a non-empty value behind the requested keys.
std::unique_ptr< Nucleus > projectile_
Projectile.
Sample from uniform distribution.
Sampling sampling_
Method used for sampling of impact parameter.
Thrown when either projectile_ or target_ nuclei are empty.
double s_from_plab(double plab, double m_P, double m_T)
Convert p_lab to Mandelstam-s for a fixed-target setup, with a projectile of mass m_P and momentum pl...
Definition: kinematics.h:224
Sample from custom, user-defined distribution.
std::pair< double, double > get_velocities(double mandelstam_s, double m_a, double m_b)
Get the frame dependent velocity for each nucleus, using the current reference frame.
FermiMotion fermi_motion_
An option to include Fermi motion ("off", "on", "frozen")
double initial_z_displacement_
Initial z-displacement of nuclei.
Sample from areal / quadratic distribution.
Don&#39;t use fermi motion.
ColliderModus: Provides a modus for colliding nuclei.
Definition: collidermodus.h:42
double sqrt_s_NN_
Center-of-mass energy of a nucleon-nucleon collision.
T uniform(T min, T max)
Definition: random.h:85
Use fermi motion without potentials.
bool cll_in_nucleus_
An option to accept first collisions within the same nucleus.
double initial_conditions(Particles *particles, const ExperimentParameters &parameters)
Generates initial state of the particles in the system.
std::unique_ptr< Nucleus > target_
Target.
double velocity_projectile_
Beam velocity of the projectile.
void sample_impact()
Sample impact parameter.
int testparticles
Number of test particle.
Value take(std::initializer_list< const char *> keys)
The default interface for SMASH to read configuration values.
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:457
T pCM(const T sqrts, const T mass_a, const T mass_b) noexcept
Definition: kinematics.h:79
double imp_max_
Maximum value of impact parameter.
Helper structure for Experiment.
Use fermi motion in combination with potentials.
CalculationFrame frame_
Reference frame for the system, as specified from config.
Definition: action.h:24
double total_s_
Center-of-mass energy squared of the nucleus-nucleus collision.
double s_from_Ekin(double e_kin, double m_P, double m_T)
Convert E_kin to Mandelstam-s for a fixed-target setup, with a projectile of mass m_P and a kinetic e...
Definition: kinematics.h:211