Version: SMASH-2.2
action.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2021
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_ACTION_H_
11 #define SRC_INCLUDE_SMASH_ACTION_H_
12 
13 #include <stdexcept>
14 #include <utility>
15 #include <vector>
16 
17 #include "lattice.h"
18 #include "particles.h"
19 #include "pauliblocking.h"
20 #include "potentials.h"
21 #include "processbranch.h"
22 #include "random.h"
23 
24 namespace smash {
25 static constexpr int LAction = LogArea::Action::id;
26 
35 class Action {
36  public:
44  Action(const ParticleList &in_part, double time)
45  : incoming_particles_(in_part),
46  time_of_execution_(time + in_part[0].position().x0()) {}
47 
58  Action(const ParticleData &in_part, const ParticleData &out_part, double time,
59  ProcessType type)
60  : incoming_particles_({in_part}),
61  outgoing_particles_({out_part}),
62  time_of_execution_(time + in_part.position().x0()),
63  process_type_(type) {}
64 
75  Action(const ParticleList &in_part, const ParticleList &out_part,
76  double absolute_execution_time, ProcessType type)
77  : incoming_particles_(std::move(in_part)),
78  outgoing_particles_(std::move(out_part)),
79  time_of_execution_(absolute_execution_time),
80  process_type_(type) {}
81 
83  Action(const Action &) = delete;
84 
89  virtual ~Action();
90 
96  bool operator<(const Action &rhs) const {
98  }
99 
112  virtual double get_total_weight() const = 0;
113 
124  virtual double get_partial_weight() const = 0;
125 
131  virtual ProcessType get_type() const { return process_type_; }
132 
140  template <typename Branch>
141  void add_process(ProcessBranchPtr<Branch> &p,
142  ProcessBranchList<Branch> &subprocesses,
143  double &total_weight) {
144  if (p->weight() > 0) {
145  total_weight += p->weight();
146  subprocesses.emplace_back(std::move(p));
147  }
148  }
149 
157  template <typename Branch>
158  void add_processes(ProcessBranchList<Branch> pv,
159  ProcessBranchList<Branch> &subprocesses,
160  double &total_weight) {
161  subprocesses.reserve(subprocesses.size() + pv.size());
162  for (auto &proc : pv) {
163  if (proc->weight() > 0) {
164  total_weight += proc->weight();
165  subprocesses.emplace_back(std::move(proc));
166  }
167  }
168  }
169 
176  virtual void generate_final_state() = 0;
177 
193  virtual void perform(Particles *particles, uint32_t id_process);
194 
206  bool is_valid(const Particles &particles) const;
207 
222  bool is_pauli_blocked(const std::vector<Particles> &ensembles,
223  const PauliBlocker &p_bl) const;
224 
230  const ParticleList &incoming_particles() const;
231 
238  void update_incoming(const Particles &particles);
239 
245  const ParticleList &outgoing_particles() const { return outgoing_particles_; }
246 
252  double time_of_execution() const { return time_of_execution_; }
253 
259  virtual void check_conservation(const uint32_t id_process) const;
260 
266  double sqrt_s() const { return total_momentum().abs(); }
267 
279 
286 
292  std::pair<FourVector, FourVector> get_potential_at_interaction_point() const;
293 
299  const int max_inc_idx = incoming_particles_.size() - 1;
301  }
302 
310  static double lambda_tilde(double a, double b, double c) {
311  const double res = (a - b - c) * (a - b - c) - 4. * b * c;
312  if (res < 0.0) {
313  // floating point precision problem
314  return 0.0;
315  }
316  return res;
317  }
318 
325  class InvalidResonanceFormation : public std::invalid_argument {
326  using std::invalid_argument::invalid_argument;
327  };
328 
335  double sqrts, const std::vector<double> &m,
336  std::vector<FourVector> &sampled_momenta);
337 
338  protected:
340  ParticleList incoming_particles_;
341 
348  ParticleList outgoing_particles_;
349 
354  const double time_of_execution_;
355 
358 
364  double box_length_ = -1.0;
365 
372 
375  FourVector mom(0.0, 0.0, 0.0, 0.0);
376  for (const auto &p : incoming_particles_) {
377  mom += p.momentum();
378  }
379  return mom;
380  }
381 
391  template <typename Branch>
392  const Branch *choose_channel(const ProcessBranchList<Branch> &subprocesses,
393  double total_weight) {
394  double random_weight = random::uniform(0., total_weight);
395  double weight_sum = 0.;
396  /* Loop through all subprocesses and select one by Monte Carlo, based on
397  * their weights. */
398  for (const auto &proc : subprocesses) {
399  weight_sum += proc->weight();
400  if (random_weight <= weight_sum) {
401  /* Return the full process information. */
402  return proc.get();
403  }
404  }
405  /* Should never get here. */
407  "Problem in choose_channel: ", subprocesses.size(), " ",
408  weight_sum, " ", total_weight, " ",
409  // random_weight, "\n", *this);
410  random_weight, "\n");
411  std::abort();
412  }
413 
424  virtual std::pair<double, double> sample_masses(
425  double kinetic_energy_cm) const;
426 
436  virtual void sample_angles(std::pair<double, double> masses,
437  double kinetic_energy_cm);
438 
444 
451  virtual void sample_manybody_phasespace();
452 
469 
476  virtual void format_debug_output(std::ostream &out) const = 0;
477 
482  friend std::ostream &operator<<(std::ostream &out, const Action &action) {
483  action.format_debug_output(out);
484  return out;
485  }
486 
487  private:
494  const ParticleType &type_of_pout(const ParticleData &p_out) const {
495  return p_out.type();
496  }
505  const ParticleType &type_of_pout(const ParticleTypePtr &p_out) const {
506  return *p_out;
507  }
508 };
509 
517 inline std::vector<ActionPtr> &operator+=(std::vector<ActionPtr> &lhs,
518  std::vector<ActionPtr> &&rhs) {
519  if (lhs.size() == 0) {
520  lhs = std::move(rhs);
521  } else {
522  lhs.insert(lhs.end(), std::make_move_iterator(rhs.begin()),
523  std::make_move_iterator(rhs.end()));
524  }
525  return lhs;
526 }
527 
532 inline std::ostream &operator<<(std::ostream &out, const ActionPtr &action) {
533  return out << *action;
534 }
535 
540 std::ostream &operator<<(std::ostream &out, const ActionList &actions);
541 
542 } // namespace smash
543 
544 #endif // SRC_INCLUDE_SMASH_ACTION_H_
Thrown for example when ScatterAction is called to perform with a wrong number of final-state particl...
Definition: action.h:325
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:35
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:300
FourVector total_momentum_of_outgoing_particles() const
Calculate the total kinetic momentum of the outgoing particles.
Definition: action.cc:155
Action(const Action &)=delete
Copying is disabled. Use pointers or create a new Action.
void assign_formation_time_to_outgoing_particles()
Assign the formation time to the outgoing particles.
Definition: action.cc:186
virtual ~Action()
Virtual Destructor.
int stochastic_position_idx_
This stores a randomly-chosen index to an incoming particle.
Definition: action.h:371
std::pair< FourVector, FourVector > get_potential_at_interaction_point() const
Get the skyrme and asymmetry potential at the interaction point.
Definition: action.cc:111
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:277
ParticleList outgoing_particles_
Initially this stores only the PDG codes of final-state particles.
Definition: action.h:348
bool operator<(const Action &rhs) const
Determine whether one action takes place before another in time.
Definition: action.h:96
virtual ProcessType get_type() const
Get the process type.
Definition: action.h:131
const ParticleType & type_of_pout(const ParticleData &p_out) const
Get the type of a given particle.
Definition: action.h:494
FourVector total_momentum() const
Sum of 4-momenta of incoming particles.
Definition: action.h:374
virtual void sample_manybody_phasespace()
Sample the full n-body phase-space (masses, momenta, angles) in the center-of-mass frame for the fina...
Definition: action.cc:443
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:354
virtual double get_total_weight() const =0
Return the total weight value, which is mainly used for the weight output entry.
void set_stochastic_pos_idx()
Setter function that stores a random incoming particle index latter used to determine the interaction...
Definition: action.h:298
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(const ParticleList &in_part, double time)
Construct an action object with incoming particles and relative time.
Definition: action.h:44
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:57
Action(const ParticleList &in_part, const ParticleList &out_part, double absolute_execution_time, ProcessType type)
Construct an action object with the incoming particles, absolute time, and the already known outgoing...
Definition: action.h:75
double time_of_execution() const
Get the time at which the action is supposed to be performed.
Definition: action.h:252
virtual void perform(Particles *particles, uint32_t id_process)
Actually perform the action, e.g.
Definition: action.cc:127
virtual void generate_final_state()=0
Generate the final state for this action.
void add_process(ProcessBranchPtr< Branch > &p, ProcessBranchList< Branch > &subprocesses, double &total_weight)
Add a new subprocess.
Definition: action.h:141
const Branch * choose_channel(const ProcessBranchList< Branch > &subprocesses, double total_weight)
Decide for a particular final-state channel via Monte-Carlo and return it as a ProcessBranch.
Definition: action.h:392
virtual double get_partial_weight() const =0
Return the specific weight for the chosen outgoing channel, which is mainly used for the partial weig...
double sqrt_s() const
Determine the total energy in the center-of-mass frame [GeV].
Definition: action.h:266
double box_length_
Box length: needed to determine coordinates of collision correctly in case of collision through the w...
Definition: action.h:364
ParticleList incoming_particles_
List with data of incoming particles.
Definition: action.h:340
FourVector get_interaction_point() const
Get the interaction point.
Definition: action.cc:67
Action(const ParticleData &in_part, const ParticleData &out_part, double time, ProcessType type)
Construct an action object with the incoming particles, relative time, and the already known outgoing...
Definition: action.h:58
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:248
static double lambda_tilde(double a, double b, double c)
Little helper function that calculates the lambda function (sometimes written with a tilde to better ...
Definition: action.h:310
void add_processes(ProcessBranchList< Branch > pv, ProcessBranchList< Branch > &subprocesses, double &total_weight)
Add several new subprocesses at once.
Definition: action.h:158
ProcessType process_type_
type of process
Definition: action.h:357
virtual void check_conservation(const uint32_t id_process) const
Check various conservation laws.
Definition: action.cc:472
const ParticleType & type_of_pout(const ParticleTypePtr &p_out) const
Get the particle type for given pointer to a particle type.
Definition: action.h:505
const ParticleList & outgoing_particles() const
Get the list of particles that resulted from the action.
Definition: action.h:245
bool is_valid(const Particles &particles) const
Check whether the action still applies.
Definition: action.cc:28
static void sample_manybody_phasespace_impl(double sqrts, const std::vector< double > &m, std::vector< FourVector > &sampled_momenta)
Implementation of the full n-body phase-space sampling (masses, momenta, angles) in the center-of-mas...
Definition: action.cc:311
bool is_pauli_blocked(const std::vector< Particles > &ensembles, const PauliBlocker &p_bl) const
Check if the action is Pauli-blocked.
Definition: action.cc:34
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
double abs() const
calculate the lorentz invariant absolute value
Definition: fourvector.h:459
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:58
const ParticleType & type() const
Get the type of the particle.
Definition: particledata.h:128
A pointer-like interface to global references to ParticleType objects.
Definition: particletype.h:671
Particle type contains the static properties of a particle species.
Definition: particletype.h:97
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
A class that stores parameters needed for Pauli blocking, tabulates necessary integrals and computes ...
Definition: pauliblocking.h:38
#define SMASH_SOURCE_LOCATION
Hackery that is required to output the location in the source code where the log statement occurs.
Definition: logging.h:243
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:532
friend std::ostream & operator<<(std::ostream &out, const Action &action)
Dispatches formatting to the virtual Action::format_debug_output function.
Definition: action.h:482
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
virtual void format_debug_output(std::ostream &out) const =0
Writes information about this action to the out stream.
constexpr int p
Proton.
T uniform_int(T min, T max)
Definition: random.h:100
T uniform(T min, T max)
Definition: random.h:88
Definition: action.h:24
static constexpr int LAction
Definition: action.h:25
ProcessType
Process Types are used to identify the type of the process.
Definition: processbranch.h:25
std::vector< ActionPtr > & operator+=(std::vector< ActionPtr > &lhs, std::vector< ActionPtr > &&rhs)
Append vector of action pointers.
Definition: action.h:517