Version: SMASH-2.0
action.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/action.h"
11 
12 #include <assert.h>
13 #include <algorithm>
14 #include <sstream>
15 
16 #include "smash/angles.h"
17 #include "smash/constants.h"
18 #include "smash/logging.h"
19 #include "smash/pauliblocking.h"
21 #include "smash/quantumnumbers.h"
22 
23 namespace smash {
25 Action::~Action() = default;
26 static constexpr int LPauliBlocking = LogArea::PauliBlocking::id;
27 
28 bool Action::is_valid(const Particles &particles) const {
29  return std::all_of(
31  [&particles](const ParticleData &p) { return particles.is_valid(p); });
32 }
33 
34 bool Action::is_pauli_blocked(const Particles &particles,
35  const PauliBlocker &p_bl) const {
36  // Wall-crossing actions should never be blocked: currently
37  // if the action is blocked, a particle continues to propagate in a straight
38  // line. This would simply bring it out of the box.
40  return false;
41  }
42  for (const auto &p : outgoing_particles_) {
43  if (p.is_baryon()) {
44  const auto f =
45  p_bl.phasespace_dens(p.position().threevec(), p.momentum().threevec(),
46  particles, p.pdgcode(), incoming_particles_);
47  if (f > random::uniform(0., 1.)) {
48  logg[LPauliBlocking].debug("Action ", *this,
49  " is pauli-blocked with f = ", f);
50  return true;
51  }
52  }
53  }
54  return false;
55 }
56 
57 const ParticleList &Action::incoming_particles() const {
58  return incoming_particles_;
59 }
60 
61 void Action::update_incoming(const Particles &particles) {
62  for (auto &p : incoming_particles_) {
63  p = particles.lookup(p);
64  }
65 }
66 
68  // Estimate for the interaction point in the calculational frame
69  FourVector interaction_point = FourVector(0., 0., 0., 0.);
70  for (const auto &part : incoming_particles_) {
71  interaction_point += part.position();
72  }
73  interaction_point /= incoming_particles_.size();
74  /*
75  * In case of periodic boundaries interaction point is not necessarily
76  * (x1 + x2)/2. Consider only one dimension, e.g. x, the rest are analogous.
77  * Instead of x, there can be x + k * L, where k is any integer and L
78  * is period.Interaction point is either. Therefore, interaction point is
79  * (x1 + k * L + x2 + m * L) / 2 = (x1 + x2) / 2 + n * L / 2. We need
80  * this interaction point to be with [0, L], so n can be {-1, 0, 1}.
81  * Which n to choose? Our guiding principle is that n should be such that
82  * interaction point is closest to interacting particles.
83  */
84  if (box_length_ > 0 && stochastic_position_idx_ < 0) {
85  assert(incoming_particles_.size() == 2);
86  const FourVector r1 = incoming_particles_[0].position(),
87  r2 = incoming_particles_[1].position(), r = r1 - r2;
88  for (int i = 1; i < 4; i++) {
89  const double d = std::abs(r[i]);
90  if (d > 0.5 * box_length_) {
91  if (interaction_point[i] >= 0.5 * box_length_) {
92  interaction_point[i] -= 0.5 * box_length_;
93  } else {
94  interaction_point[i] += 0.5 * box_length_;
95  }
96  }
97  }
98  }
99  /* In case of scatterings via the stochastic criterion, use postion of random
100  * incoming particle to prevent density hotspots in grid cell centers. */
101  if (stochastic_position_idx_ >= 0) {
102  interaction_point =
104  }
105  return interaction_point;
106 }
107 
108 std::pair<FourVector, FourVector> Action::get_potential_at_interaction_point()
109  const {
111  FourVector UB = FourVector();
112  FourVector UI3 = FourVector();
113  /* Check:
114  * Lattice is turned on. */
115  if (UB_lat_pointer != nullptr) {
116  UB_lat_pointer->value_at(r, UB);
117  }
118  if (UI3_lat_pointer != nullptr) {
119  UI3_lat_pointer->value_at(r, UI3);
120  }
121  return std::make_pair(UB, UI3);
122 }
123 
124 void Action::perform(Particles *particles, uint32_t id_process) {
125  assert(id_process != 0);
126 
128  // store the history info
130  p.set_history(p.get_history().collisions_per_particle + 1, id_process,
132  }
133  }
134 
135  /* For elastic collisions and box wall crossings it is not necessary to remove
136  * particles from the list and insert new ones, it is enough to update their
137  * properties. */
141 
142  logg[LAction].debug("Particle map now has ", particles->size(), " elements.");
143 
144  /* Check the conservation laws if the modifications of the total kinetic
145  * energy of the outgoing particles by the mean field potentials are not
146  * taken into account. */
147  if (UB_lat_pointer == nullptr && UI3_lat_pointer == nullptr) {
148  check_conservation(id_process);
149  }
150 }
151 
153  const auto potentials = get_potential_at_interaction_point();
154  /* scale_B returns the difference of the total force scales of the skyrme
155  * potential between the initial and final states. */
156  double scale_B = 0.0;
157  /* scale_I3 returns the difference of the total force scales of the symmetry
158  * potential between the initial and final states. */
159  double scale_I3 = 0.0;
160  for (const auto &p_in : incoming_particles_) {
161  // Get the force scale of the incoming particle.
162  const auto scale =
163  ((pot_pointer != nullptr) ? pot_pointer->force_scale(p_in.type())
164  : std::make_pair(0.0, 0));
165  scale_B += scale.first;
166  scale_I3 += scale.second * p_in.type().isospin3_rel();
167  }
168  for (const auto &p_out : outgoing_particles_) {
169  // Get the force scale of the outgoing particle.
170  const auto scale = ((pot_pointer != nullptr)
172  : std::make_pair(0.0, 0));
173  scale_B -= scale.first;
174  scale_I3 -= scale.second * type_of_pout(p_out).isospin3_rel();
175  }
176  /* Rescale to get the potential difference between the
177  * initial and final state, and thus get the total momentum
178  * of the outgoing particles*/
179  return total_momentum() + potentials.first * scale_B +
180  potentials.second * scale_I3;
181 }
182 
184  /* Find incoming particle with largest formation time i.e. the last formed
185  * incoming particle. If all particles form at the same time, take the one
186  * with the lowest cross section scaling factor */
187  ParticleList::iterator last_formed_in_part;
188  bool all_incoming_same_formation_time =
190  [&](const ParticleData &data_comp) {
191  return abs(incoming_particles_[0].formation_time() -
192  data_comp.formation_time()) < really_small;
193  });
194  if (all_incoming_same_formation_time) {
195  last_formed_in_part =
196  std::min_element(incoming_particles_.begin(), incoming_particles_.end(),
197  [](const ParticleData &a, const ParticleData &b) {
198  return a.initial_xsec_scaling_factor() <
199  b.initial_xsec_scaling_factor();
200  });
201  } else {
202  last_formed_in_part =
203  std::max_element(incoming_particles_.begin(), incoming_particles_.end(),
204  [](const ParticleData &a, const ParticleData &b) {
205  return a.formation_time() < b.formation_time();
206  });
207  }
208 
209  const double form_time_begin = last_formed_in_part->begin_formation_time();
210  const double sc = last_formed_in_part->initial_xsec_scaling_factor();
211 
212  if (last_formed_in_part->formation_time() > time_of_execution_) {
213  for (ParticleData &new_particle : outgoing_particles_) {
214  if (new_particle.initial_xsec_scaling_factor() < 1.0) {
215  /* The new cross section scaling factor will be the product of the
216  * cross section scaling factor of the ingoing particles and of the
217  * outgoing ones (since the outgoing ones are also string fragments
218  * and thus take time to form). */
219  double sc_out = new_particle.initial_xsec_scaling_factor();
220  new_particle.set_cross_section_scaling_factor(sc * sc_out);
221  if (last_formed_in_part->formation_time() >
222  new_particle.formation_time()) {
223  /* If the unformed incoming particles' formation time is larger than
224  * the current outgoing particle's formation time, then the latter
225  * is overwritten by the former*/
226  new_particle.set_slow_formation_times(
227  time_of_execution_, last_formed_in_part->formation_time());
228  }
229  } else {
230  // not a string product
231  new_particle.set_slow_formation_times(
232  form_time_begin, last_formed_in_part->formation_time());
233  new_particle.set_cross_section_scaling_factor(sc);
234  }
235  }
236  } else {
237  for (ParticleData &new_particle : outgoing_particles_) {
238  if (new_particle.initial_xsec_scaling_factor() == 1.0) {
239  new_particle.set_formation_time(time_of_execution_);
240  }
241  }
242  }
243 }
244 
245 std::pair<double, double> Action::sample_masses(
246  const double kinetic_energy_cm) const {
247  const ParticleType &t_a = outgoing_particles_[0].type();
248  const ParticleType &t_b = outgoing_particles_[1].type();
249  // start with pole masses
250  std::pair<double, double> masses = {t_a.mass(), t_b.mass()};
251 
252  if (kinetic_energy_cm < t_a.min_mass_kinematic() + t_b.min_mass_kinematic()) {
253  const std::string reaction = incoming_particles_[0].type().name() +
254  incoming_particles_[1].type().name() + "→" +
255  t_a.name() + t_b.name();
257  reaction + ": not enough energy, " + std::to_string(kinetic_energy_cm) +
258  " < " + std::to_string(t_a.min_mass_kinematic()) + " + " +
259  std::to_string(t_b.min_mass_kinematic()));
260  }
261 
262  /* If one of the particles is a resonance, sample its mass. */
263  if (!t_a.is_stable() && t_b.is_stable()) {
264  masses.first = t_a.sample_resonance_mass(t_b.mass(), kinetic_energy_cm);
265  } else if (!t_b.is_stable() && t_a.is_stable()) {
266  masses.second = t_b.sample_resonance_mass(t_a.mass(), kinetic_energy_cm);
267  } else if (!t_a.is_stable() && !t_b.is_stable()) {
268  // two resonances in final state
269  masses = t_a.sample_resonance_masses(t_b, kinetic_energy_cm);
270  }
271  return masses;
272 }
273 
274 void Action::sample_angles(std::pair<double, double> masses,
275  const double kinetic_energy_cm) {
278 
279  const double pcm = pCM(kinetic_energy_cm, masses.first, masses.second);
280  if (!(pcm > 0.0)) {
281  logg[LAction].warn("Particle: ", p_a->pdgcode(), " radial momentum: ", pcm);
282  logg[LAction].warn("Ektot: ", kinetic_energy_cm, " m_a: ", masses.first,
283  " m_b: ", masses.second);
284  }
285  /* Here we assume an isotropic angular distribution. */
286  Angles phitheta;
287  phitheta.distribute_isotropically();
288 
289  p_a->set_4momentum(masses.first, phitheta.threevec() * pcm);
290  p_b->set_4momentum(masses.second, -phitheta.threevec() * pcm);
291  /* Debug message is printed before boost, so that p_a and p_b are
292  * the momenta in the center of mass frame and thus opposite to
293  * each other.*/
294  logg[LAction].debug("p_a: ", *p_a, "\np_b: ", *p_b);
295 }
296 
298  /* This function only operates on 2-particle final states. */
299  assert(outgoing_particles_.size() == 2);
301  const double cm_kin_energy = p_tot.abs();
302  // first sample the masses
303  const std::pair<double, double> masses = sample_masses(cm_kin_energy);
304  // after the masses are fixed (and thus also pcm), sample the angles
305  sample_angles(masses, cm_kin_energy);
306 }
307 
309  assert(outgoing_particles_.size() == 3);
310  if (!outgoing_particles_[0].type().is_stable() ||
311  !outgoing_particles_[1].type().is_stable() ||
312  !outgoing_particles_[2].type().is_stable()) {
313  throw std::invalid_argument(
314  "sample_3body_phasespace: Found resonance in to be sampled outgoing "
315  "particles, but assumes stable particles.");
316  }
317 
318  const double m_a = outgoing_particles_[0].type().mass(),
319  m_b = outgoing_particles_[1].type().mass(),
320  m_c = outgoing_particles_[2].type().mass();
321  const double sqrts = sqrt_s();
322 
323  // sample mab from pCM(sqrt, mab, mc) pCM (mab, ma, mb) <= sqrts^2/4
324  double mab, r, probability, pcm_ab, pcm;
325  do {
326  mab = random::uniform(m_a + m_b, sqrts - m_c);
327  r = random::canonical();
328  pcm = pCM(sqrts, mab, m_c);
329  pcm_ab = pCM(mab, m_a, m_b);
330  probability = pcm * pcm_ab * 4 / (sqrts * sqrts);
331  } while (r > probability);
332  Angles phitheta;
333  phitheta.distribute_isotropically();
334  outgoing_particles_[2].set_4momentum(m_c, pcm * phitheta.threevec());
335  const ThreeVector beta_cm =
336  pcm * phitheta.threevec() / std::sqrt(pcm * pcm + mab * mab);
337 
338  phitheta.distribute_isotropically();
339  outgoing_particles_[0].set_4momentum(m_a, pcm_ab * phitheta.threevec());
340  outgoing_particles_[1].set_4momentum(m_b, -pcm_ab * phitheta.threevec());
341  outgoing_particles_[0].boost_momentum(beta_cm);
342  outgoing_particles_[1].boost_momentum(beta_cm);
343 }
344 
345 void Action::check_conservation(const uint32_t id_process) const {
348  if (before != after) {
349  std::stringstream particle_names;
350  for (const auto &p : incoming_particles_) {
351  particle_names << p.type().name();
352  }
353  particle_names << " vs. ";
354  for (const auto &p : outgoing_particles_) {
355  particle_names << p.type().name();
356  }
357  particle_names << "\n";
358  std::string err_msg = before.report_deviations(after);
359  logg[LAction].error() << particle_names.str() << err_msg;
360  /* Pythia does not conserve energy and momentum at high energy, so we just
361  * print the error and continue. */
364  return;
365  }
366  if (id_process == ID_PROCESS_PHOTON) {
367  throw std::runtime_error("Conservation laws violated in photon process");
368  } else {
369  throw std::runtime_error("Conservation laws violated in process " +
370  std::to_string(id_process));
371  }
372  }
373 }
374 
375 std::ostream &operator<<(std::ostream &out, const ActionList &actions) {
376  out << "ActionList {\n";
377  for (const auto &a : actions) {
378  out << "- " << a << '\n';
379  }
380  return out << '}';
381 }
382 
383 } // namespace smash
smash::Action::sample_angles
virtual void sample_angles(std::pair< double, double > masses, double kinetic_energy_cm)
Sample final-state momenta in general X->2 processes (here: using an isotropical angular distribution...
Definition: action.cc:274
smash
Definition: action.h:24
smash::Action::incoming_particles_
ParticleList incoming_particles_
List with data of incoming particles.
Definition: action.h:326
quantumnumbers.h
smash::ProcessType::StringHard
hard string process involving 2->2 QCD process by PYTHIA.
smash::Action::~Action
virtual ~Action()
Virtual Destructor.
smash::Action::total_momentum
FourVector total_momentum() const
Sum of 4-momenta of incoming particles.
Definition: action.h:360
smash::Action::time_of_execution_
const double time_of_execution_
Time at which the action is supposed to be performed (absolute time in the lab frame in fm/c).
Definition: action.h:340
smash::Action::assign_formation_time_to_outgoing_particles
void assign_formation_time_to_outgoing_particles()
Assign the formation time to the outgoing particles.
Definition: action.cc:183
smash::Particles::size
size_t size() const
Definition: particles.h:87
smash::ParticleData
Definition: particledata.h:52
smash::Action::sample_2body_phasespace
void sample_2body_phasespace()
Sample the full 2-body phase-space (masses, momenta, angles) in the center-of-mass frame for the fina...
Definition: action.cc:297
smash::ParticleData::initial_xsec_scaling_factor
const double & initial_xsec_scaling_factor() const
Get the initially assigned cross section scaling factor.
Definition: particledata.h:272
smash::LPauliBlocking
static constexpr int LPauliBlocking
Definition: action.cc:26
smash::Potentials::force_scale
static std::pair< double, int > force_scale(const ParticleType &data)
Evaluates the scaling factor of the forces acting on the particles.
Definition: potentials.cc:164
smash::Action::is_pauli_blocked
bool is_pauli_blocked(const Particles &particles, const PauliBlocker &p_bl) const
Check if the action is Pauli-blocked.
Definition: action.cc:34
smash::Action::check_conservation
virtual void check_conservation(const uint32_t id_process) const
Check various conservation laws.
Definition: action.cc:345
smash::is_string_soft_process
bool is_string_soft_process(ProcessType p)
Check if a given process type is a soft string excitation.
Definition: processbranch.cc:18
smash::operator<<
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Definition: action.h:518
smash::ParticleType::mass
double mass() const
Definition: particletype.h:144
smash::Angles::distribute_isotropically
void distribute_isotropically()
Populate the object with a new direction.
Definition: angles.h:188
smash::ParticleData::pdgcode
PdgCode pdgcode() const
Get the pdgcode of the particle.
Definition: particledata.h:81
smash::PauliBlocker::phasespace_dens
double phasespace_dens(const ThreeVector &r, const ThreeVector &p, const Particles &particles, const PdgCode pdg, const ParticleList &disregard) const
Calculate phase-space density of a particle species at the point (r,p).
Definition: pauliblocking.cc:67
smash::Action::update_incoming
void update_incoming(const Particles &particles)
Update the incoming particles that are stored in this action to the state they have in the global par...
Definition: action.cc:61
action.h
smash::ParticleData::set_4momentum
void set_4momentum(const FourVector &momentum_vector)
Set the particle's 4-momentum directly.
Definition: particledata.h:158
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::all_of
bool all_of(Container &&c, UnaryPredicate &&p)
Convenience wrapper for std::all_of that operates on a complete container.
Definition: algorithms.h:80
smash::pCM
T pCM(const T sqrts, const T mass_a, const T mass_b) noexcept
Definition: kinematics.h:79
smash::really_small
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
pauliblocking.h
angles.h
smash::UI3_lat_pointer
RectangularLattice< FourVector > * UI3_lat_pointer
Pointer to the symmmetry potential on the lattice.
Definition: potential_globals.cc:16
smash::ThreeVector
Definition: threevector.h:31
smash::ParticleData::formation_time
double formation_time() const
Get the absolute formation time of the particle.
Definition: particledata.h:230
smash::ProcessType::Wall
box wall crossing
smash::PauliBlocker
A class that stores parameters needed for Pauli blocking, tabulates necessary integrals and computes ...
Definition: pauliblocking.h:36
smash::Action::box_length_
double box_length_
Box length: needed to determine coordinates of collision correctly in case of collision through the w...
Definition: action.h:350
smash::ParticleType::sample_resonance_masses
std::pair< double, double > sample_resonance_masses(const ParticleType &t2, const double cms_energy, int L=0) const
Resonance mass sampling for 2-particle final state with two resonances.
Definition: particletype.cc:672
smash::UB_lat_pointer
RectangularLattice< FourVector > * UB_lat_pointer
Pointer to the skyrme potential on the lattice.
Definition: potential_globals.cc:15
smash::ParticleType::is_stable
bool is_stable() const
Definition: particletype.h:239
smash::Particles::update
void update(const ParticleList &old_state, ParticleList &new_state, bool do_replace)
Updates the Particles object, replacing the particles in old_state with the particles in new_state.
Definition: particles.h:200
smash::Action::type_of_pout
const ParticleType & type_of_pout(const ParticleData &p_out) const
Get the type of a given particle.
Definition: action.h:480
smash::ParticleType::sample_resonance_mass
double sample_resonance_mass(const double mass_stable, const double cms_energy, int L=0) const
Resonance mass sampling for 2-particle final state with one resonance (type given by 'this') and one ...
Definition: particletype.cc:615
smash::ParticleType::isospin3_rel
double isospin3_rel() const
Definition: particletype.h:179
smash::QuantumNumbers::report_deviations
std::string report_deviations(const Particles &particles) const
Checks if the current particle list has still the same values and reports about differences.
Definition: quantumnumbers.h:248
smash::Action::process_type_
ProcessType process_type_
type of process
Definition: action.h:343
smash::ParticleType
Definition: particletype.h:97
smash::Action::is_valid
bool is_valid(const Particles &particles) const
Check whether the action still applies.
Definition: action.cc:28
smash::ParticleType::name
const std::string & name() const
Definition: particletype.h:141
smash::LAction
static constexpr int LAction
Definition: action.h:25
smash::Action::get_potential_at_interaction_point
std::pair< FourVector, FourVector > get_potential_at_interaction_point() const
Get the skyrme and asymmetry potential at the interaction point.
Definition: action.cc:108
smash::Action::stochastic_position_idx_
int stochastic_position_idx_
This stores a randomly-chosen index to an incoming particle.
Definition: action.h:357
smash::Action::perform
virtual void perform(Particles *particles, uint32_t id_process)
Actually perform the action, e.g.
Definition: action.cc:124
smash::Action::total_momentum_of_outgoing_particles
FourVector total_momentum_of_outgoing_particles() const
Calculate the total kinetic momentum of the outgoing particles.
Definition: action.cc:152
smash::Particles::lookup
const ParticleData & lookup(const ParticleData &old_state) const
Returns the particle that is currently stored in this object given an old copy of that particle.
Definition: particles.h:222
smash::Action::outgoing_particles_
ParticleList outgoing_particles_
Initially this stores only the PDG codes of final-state particles.
Definition: action.h:334
smash::Action::sample_3body_phasespace
virtual void sample_3body_phasespace()
Sample the full 3-body phase-space (masses, momenta, angles) in the center-of-mass frame for the fina...
Definition: action.cc:308
smash::Angles::threevec
ThreeVector threevec() const
Definition: angles.h:268
smash::Action::sqrt_s
double sqrt_s() const
Determine the total energy in the center-of-mass frame [GeV].
Definition: action.h:266
smash::Particles::is_valid
bool is_valid(const ParticleData &copy) const
Check whether the ParticleData copy is still a valid copy of the one stored in the Particles object.
Definition: particles.h:120
smash::Particles
Definition: particles.h:33
constants.h
logging.h
smash::ProcessType::Elastic
elastic scattering: particles remain the same, only momenta change
smash::FourVector
Definition: fourvector.h:33
smash::Action::get_interaction_point
FourVector get_interaction_point() const
Get the interaction point.
Definition: action.cc:67
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
smash::random::uniform
T uniform(T min, T max)
Definition: random.h:88
smash::ID_PROCESS_PHOTON
constexpr std::uint32_t ID_PROCESS_PHOTON
Process ID for any photon process.
Definition: constants.h:118
smash::ParticleType::min_mass_kinematic
double min_mass_kinematic() const
The minimum mass of the resonance that is kinematically allowed.
Definition: particletype.cc:354
smash::pot_pointer
Potentials * pot_pointer
Pointer to a Potential class.
Definition: potential_globals.cc:17
smash::Action::incoming_particles
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:57
potential_globals.h
smash::Action::sample_masses
virtual std::pair< double, double > sample_masses(double kinetic_energy_cm) const
Sample final-state masses in general X->2 processes (thus also fixing the absolute c....
Definition: action.cc:245
smash::QuantumNumbers
Definition: quantumnumbers.h:53
smash::Action::InvalidResonanceFormation
Definition: action.h:320
smash::random::canonical
T canonical()
Definition: random.h:113
smash::FourVector::threevec
ThreeVector threevec() const
Definition: fourvector.h:319