Version: SMASH-1.7
collidermodus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2019
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 <string>
17 #include <tuple>
18 #include <utility>
19 #include <vector>
20 
21 #include "smash/angles.h"
22 #include "smash/configuration.h"
23 #include "smash/customnucleus.h"
24 #include "smash/cxx14compat.h"
26 #include "smash/fourvector.h"
27 #include "smash/interpolation.h"
28 #include "smash/kinematics.h"
29 #include "smash/logging.h"
30 #include "smash/numerics.h"
31 #include "smash/particles.h"
32 #include "smash/pdgcode.h"
33 #include "smash/random.h"
34 
35 namespace smash {
36 
261  const ExperimentParameters &params) {
262  Configuration modus_cfg = modus_config["Collider"];
263  // Get the reference frame for the collision calculation.
264  if (modus_cfg.has_value({"Calculation_Frame"})) {
265  frame_ = modus_cfg.take({"Calculation_Frame"});
266  }
267 
268  // Determine whether to allow the first collisions within the same nucleus
269  if (modus_cfg.has_value({"Collisions_Within_Nucleus"})) {
270  cll_in_nucleus_ = modus_cfg.take({"Collisions_Within_Nucleus"});
271  }
272  Configuration proj_cfg = modus_cfg["Projectile"];
273  Configuration targ_cfg = modus_cfg["Target"];
274  /* Needed to check if projectile and target in customnucleus are read from
275  * the same input file.*/
276  bool same_file = false;
277  // Set up the projectile nucleus
278  if (proj_cfg.has_value({"Deformed"})) {
279  projectile_ =
280  create_deformed_nucleus(proj_cfg, params.testparticles, "projectile");
281  } else if (proj_cfg.has_value({"Custom"})) {
282  same_file = same_inputfile(proj_cfg, targ_cfg);
283  projectile_ =
284  make_unique<CustomNucleus>(proj_cfg, params.testparticles, same_file);
285  } else {
286  projectile_ = make_unique<Nucleus>(proj_cfg, params.testparticles);
287  }
288  if (projectile_->size() < 1) {
289  throw ColliderEmpty("Input Error: Projectile nucleus is empty.");
290  }
291 
292  // Set up the target nucleus
293  if (targ_cfg.has_value({"Deformed"})) {
294  target_ = create_deformed_nucleus(targ_cfg, params.testparticles, "target");
295  } else if (targ_cfg.has_value({"Custom"})) {
296  target_ =
297  make_unique<CustomNucleus>(targ_cfg, params.testparticles, same_file);
298  } else {
299  target_ = make_unique<Nucleus>(targ_cfg, params.testparticles);
300  }
301  if (target_->size() < 1) {
302  throw ColliderEmpty("Input Error: Target nucleus is empty.");
303  }
304 
305  // Get the Fermi-Motion input (off, on, frozen)
306  if (modus_cfg.has_value({"Fermi_Motion"})) {
307  // We only read the value, because it is still required by the experiment
308  // class to make sure we don't use frozen Fermi momenta with potentials.
309  fermi_motion_ = modus_cfg.read({"Fermi_Motion"});
310  }
311 
312  // Get the total nucleus-nucleus collision energy. Since there is
313  // no meaningful choice for a default energy, we require the user to
314  // give one (and only one) energy input from the available options.
315  int energy_input = 0;
316  const double mass_projec = projectile_->mass();
317  const double mass_target = target_->mass();
318  // average mass of a particle in that nucleus
319  const double mass_a =
320  projectile_->mass() / projectile_->number_of_particles();
321  const double mass_b = target_->mass() / target_->number_of_particles();
322  // Option 1: Center of mass energy.
323  if (modus_cfg.has_value({"Sqrtsnn"})) {
324  sqrt_s_NN_ = modus_cfg.take({"Sqrtsnn"});
325  // Check that input satisfies the lower bound (everything at rest).
326  if (sqrt_s_NN_ <= mass_a + mass_b) {
328  "Input Error: sqrt(s_NN) is not larger than masses:\n" +
329  std::to_string(sqrt_s_NN_) + " GeV <= " + std::to_string(mass_a) +
330  " GeV + " + std::to_string(mass_b) + " GeV.");
331  }
332  // Set the total nucleus-nucleus collision energy.
333  total_s_ = (sqrt_s_NN_ * sqrt_s_NN_ - mass_a * mass_a - mass_b * mass_b) *
334  mass_projec * mass_target / (mass_a * mass_b) +
335  mass_projec * mass_projec + mass_target * mass_target;
336  energy_input++;
337  }
338  /* Option 2: Kinetic energy per nucleon of the projectile nucleus
339  * (target at rest). */
340  if (modus_cfg.has_value({"E_Kin"})) {
341  const double e_kin = modus_cfg.take({"E_Kin"});
342  if (e_kin < 0) {
344  "Input Error: "
345  "E_Kin must be nonnegative.");
346  }
347  // Set the total nucleus-nucleus collision energy.
348  total_s_ = s_from_Ekin(e_kin * projectile_->number_of_particles(),
349  mass_projec, mass_target);
350  sqrt_s_NN_ = std::sqrt(s_from_Ekin(e_kin, mass_a, mass_b));
351  energy_input++;
352  }
353  // Option 3: Momentum of the projectile nucleus (target at rest).
354  if (modus_cfg.has_value({"P_Lab"})) {
355  const double p_lab = modus_cfg.take({"P_Lab"});
356  if (p_lab < 0) {
358  "Input Error: "
359  "P_Lab must be nonnegative.");
360  }
361  // Set the total nucleus-nucleus collision energy.
362  total_s_ = s_from_plab(p_lab * projectile_->number_of_particles(),
363  mass_projec, mass_target);
364  sqrt_s_NN_ = std::sqrt(s_from_plab(p_lab, mass_a, mass_b));
365  energy_input++;
366  }
367  if (energy_input == 0) {
368  throw std::domain_error(
369  "Input Error: Non-existent collision energy. "
370  "Please provide one of Sqrtsnn/E_Kin/P_Lab.");
371  }
372  if (energy_input > 1) {
373  throw std::domain_error(
374  "Input Error: Redundant collision energy. "
375  "Please provide only one of Sqrtsnn/E_Kin/P_Lab.");
376  }
377 
378  /* Impact parameter setting: Either "Value", "Range", "Max" or "Sample".
379  * Unspecified means 0 impact parameter.*/
380  if (modus_cfg.has_value({"Impact", "Value"})) {
381  impact_ = modus_cfg.take({"Impact", "Value"});
382  imp_min_ = impact_;
383  imp_max_ = impact_;
384  } else {
385  // If impact is not supplied by value, inspect sampling parameters:
386  if (modus_cfg.has_value({"Impact", "Sample"})) {
387  sampling_ = modus_cfg.take({"Impact", "Sample"});
388  if (sampling_ == Sampling::Custom) {
389  if (!(modus_cfg.has_value({"Impact", "Values"}) ||
390  modus_cfg.has_value({"Impact", "Yields"}))) {
391  throw std::domain_error(
392  "Input Error: Need impact parameter spectrum for custom "
393  "sampling. "
394  "Please provide Values and Yields.");
395  }
396  const std::vector<double> impacts =
397  modus_cfg.take({"Impact", "Values"});
398  const std::vector<double> yields = modus_cfg.take({"Impact", "Yields"});
399  if (impacts.size() != yields.size()) {
400  throw std::domain_error(
401  "Input Error: Need as many impact parameter values as yields. "
402  "Please make sure that Values and Yields have the same length.");
403  }
404  impact_interpolation_ = make_unique<InterpolateDataLinear<double>>(
405  InterpolateDataLinear<double>(impacts, yields));
406 
407  const auto imp_minmax =
408  std::minmax_element(impacts.begin(), impacts.end());
409  imp_min_ = *imp_minmax.first;
410  imp_max_ = *imp_minmax.second;
411  yield_max_ = *std::max_element(yields.begin(), yields.end());
412  }
413  }
414  if (modus_cfg.has_value({"Impact", "Range"})) {
415  const std::array<double, 2> range = modus_cfg.take({"Impact", "Range"});
416  imp_min_ = range[0];
417  imp_max_ = range[1];
418  }
419  if (modus_cfg.has_value({"Impact", "Max"})) {
420  imp_min_ = 0.0;
421  imp_max_ = modus_cfg.take({"Impact", "Max"});
422  }
423  }
425 
426  // Look for user-defined initial separation between nuclei.
427  if (modus_cfg.has_value({"Initial_Distance"})) {
428  initial_z_displacement_ = modus_cfg.take({"Initial_Distance"});
429  // the displacement is half the distance (both nuclei are shifted
430  // initial_z_displacement_ away from origin)
432  }
433 }
434 
435 std::ostream &operator<<(std::ostream &out, const ColliderModus &m) {
436  return out << "-- Collider Modus:\n"
437  << "sqrt(S) (nucleus-nucleus) = "
438  << format(std::sqrt(m.total_s_), "GeV\n")
439  << "sqrt(S) (nucleon-nucleon) = " << format(m.sqrt_s_NN_, "GeV\n")
440  << "Projectile:\n"
441  << *m.projectile_ << "\nTarget:\n"
442  << *m.target_;
443 }
444 
445 std::unique_ptr<DeformedNucleus> ColliderModus::create_deformed_nucleus(
446  Configuration &nucleus_cfg, int ntest, const std::string &nucleus_type) {
447  bool auto_deform = nucleus_cfg.take({"Deformed", "Automatic"});
448  bool is_beta2 = nucleus_cfg.has_value({"Deformed", "Beta_2"}) ? true : false;
449  bool is_beta4 = nucleus_cfg.has_value({"Deformed", "Beta_4"}) ? true : false;
450  std::unique_ptr<DeformedNucleus> nucleus;
451 
452  if ((auto_deform && (!is_beta2 && !is_beta4)) ||
453  (!auto_deform && (is_beta2 && is_beta4))) {
454  nucleus = make_unique<DeformedNucleus>(nucleus_cfg, ntest, auto_deform);
455  return nucleus;
456  } else {
457  throw std::domain_error("Deformation of " + nucleus_type +
458  " nucleus not configured "
459  "properly, please check whether all necessary "
460  "parameters are set.");
461  }
462 }
463 
465  const ExperimentParameters &) {
466  const auto &log = logger<LogArea::Collider>();
467  sample_impact();
468 
469  log.info() << "Impact parameter = " << format(impact_, "fm");
470  // Populate the nuclei with appropriately distributed nucleons.
471  // If deformed, this includes rotating the nucleus.
472  projectile_->arrange_nucleons();
473  target_->arrange_nucleons();
474 
475  // Use the total mandelstam variable to get the frame-dependent velocity for
476  // each nucleus. Position a is projectile, position b is target.
477  double v_a, v_b;
478  std::tie(v_a, v_b) =
479  get_velocities(total_s_, projectile_->mass(), target_->mass());
480 
481  // If velocities are larger or equal to 1, throw an exception.
482  if (v_a >= 1.0 || v_b >= 1.0) {
483  throw std::domain_error(
484  "Found velocity equal to or larger than 1 in "
485  "ColliderModus::initial_conditions.\nConsider using "
486  "the center of velocity reference frame.");
487  }
488 
489  // Calculate the beam velocity of the projectile and the target, which will be
490  // used to calculate the beam momenta in experiment.cc
492  velocity_projectile_ = v_a;
493  velocity_target_ = v_b;
494  }
495 
496  // Generate Fermi momenta if necessary
499  // Frozen: Fermi momenta will be ignored during the propagation to
500  // avoid that the nuclei will fly apart.
501  projectile_->generate_fermi_momenta();
502  target_->generate_fermi_momenta();
504  log.info() << "Fermi motion is ON.";
505  } else {
506  log.info() << "FROZEN Fermi motion is on.";
507  }
508  } else if (fermi_motion_ == FermiMotion::Off) {
509  // No Fermi-momenta are generated in this case
510  log.info() << "Fermi motion is OFF.";
511  } else {
512  throw std::domain_error("Invalid Fermi_Motion input.");
513  }
514 
515  // Boost the nuclei to the appropriate velocity.
516  projectile_->boost(v_a);
517  target_->boost(v_b);
518 
519  // Shift the nuclei into starting positions. Contracted spheres with
520  // nuclear radii should touch exactly at t=0. Modus starts at negative
521  // time corresponding to additional initial displacement.
522  const double d_a = std::max(0., projectile_->get_diffusiveness());
523  const double d_b = std::max(0., target_->get_diffusiveness());
524  const double r_a = projectile_->get_nuclear_radius();
525  const double r_b = target_->get_nuclear_radius();
526  const double dz = initial_z_displacement_;
527 
528  const double simulation_time = -dz / std::abs(v_a);
529  const double proj_z = -dz - std::sqrt(1.0 - v_a * v_a) * (r_a + d_a);
530  const double targ_z =
531  +dz * std::abs(v_b / v_a) + std::sqrt(1.0 - v_b * v_b) * (r_b + d_b);
532  projectile_->shift(proj_z, +impact_ / 2.0, simulation_time);
533  target_->shift(targ_z, -impact_ / 2.0, simulation_time);
534 
535  // Put the particles in the nuclei into code particles.
536  projectile_->copy_particles(particles);
537  target_->copy_particles(particles);
538  return simulation_time;
539 }
540 
542  switch (sampling_) {
543  case Sampling::Quadratic: {
544  // quadratic sampling: Note that for bmin > bmax, this still yields
545  // the correct distribution (however canonical() = 0 is then the
546  // upper end, not the lower).
547  impact_ = std::sqrt(imp_min_ * imp_min_ +
550  } break;
551  case Sampling::Custom: {
552  // rejection sampling based on given distribution
553  assert(impact_interpolation_ != nullptr);
554  double probability_random = 1;
555  double probability = 0;
556  double b;
557  while (probability_random > probability) {
559  probability = (*impact_interpolation_)(b) / yield_max_;
560  assert(probability < 1.);
561  probability_random = random::uniform(0., 1.);
562  }
563  impact_ = b;
564  } break;
565  case Sampling::Uniform: {
566  // linear sampling. Still, min > max works fine.
568  }
569  }
570 }
571 
572 std::pair<double, double> ColliderModus::get_velocities(double s, double m_a,
573  double m_b) {
574  double v_a = 0.0;
575  double v_b = 0.0;
576  // Frame dependent calculations of velocities. Assume v_a >= 0, v_b <= 0.
577  switch (frame_) {
579  v_a = center_of_velocity_v(s, m_a, m_b);
580  v_b = -v_a;
581  break;
583  // Compute center of mass momentum.
584  double pCM = pCM_from_s(s, m_a, m_b);
585  v_a = pCM / std::sqrt(m_a * m_a + pCM * pCM);
586  v_b = -pCM / std::sqrt(m_b * m_b + pCM * pCM);
587  } break;
589  v_a = fixed_target_projectile_v(s, m_a, m_b);
590  break;
591  default:
592  throw std::domain_error(
593  "Invalid reference frame in "
594  "ColliderModus::get_velocities.");
595  }
596  return std::make_pair(v_a, v_b);
597 }
598 
599 std::string ColliderModus::custom_file_path(const std::string &file_directory,
600  const std::string &file_name) {
601  // make sure that path is correct even if the / at the end is missing
602  if (file_directory.back() == '/') {
603  return file_directory + file_name;
604  } else {
605  return file_directory + '/' + file_name;
606  }
607 }
608 
610  Configuration &targ_config) {
611  /* Check if both nuclei are custom
612  * Only check target as function is called after if statement for projectile.
613  */
614  if (!targ_config.has_value({"Custom"})) {
615  return false;
616  }
617  std::string projectile_file_directory =
618  proj_config.read({"Custom", "File_Directory"});
619  std::string target_file_directory =
620  targ_config.read({"Custom", "File_Directory"});
621  std::string projectile_file_name = proj_config.read({"Custom", "File_Name"});
622  std::string target_file_name = targ_config.read({"Custom", "File_Name"});
623  // Check if files are the same for projectile and target
624  std::string proj_path =
625  custom_file_path(projectile_file_directory, projectile_file_name);
626  std::string targ_path =
627  custom_file_path(target_file_directory, target_file_name);
628  if (proj_path == targ_path) {
629  return true;
630  } else {
631  return false;
632  }
633 }
634 
635 } // namespace smash
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:317
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:188
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
Value read(std::initializer_list< const char * > keys) const
Additional interface for SMASH to read configuration values without removing them.
std::string custom_file_path(const std::string &file_directory, const std::string &file_name)
Creates full path string consisting of file_directory and file_name Needed to initialize a customnucl...
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.
bool has_value(std::initializer_list< const char * > keys) const
Returns whether there is a non-empty value behind the requested keys.
Generic numerical functions.
T canonical()
Definition: random.h:113
ColliderModus(Configuration modus_config, const ExperimentParameters &parameters)
Constructor.
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.
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
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.
bool same_inputfile(Configuration &proj_config, Configuration &targ_config)
Checks if target and projectile are read from the same external file if they are both initialized as ...
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:88
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.
friend std::ostream & operator<<(std::ostream &, const ColliderModus &)
Writes the initial state for the ColliderModus to the output stream.
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
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