Version: SMASH-2.1
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 
329  protected:
331  ParticleList incoming_particles_;
332 
339  ParticleList outgoing_particles_;
340 
345  const double time_of_execution_;
346 
349 
355  double box_length_ = -1.0;
356 
363 
366  FourVector mom(0.0, 0.0, 0.0, 0.0);
367  for (const auto &p : incoming_particles_) {
368  mom += p.momentum();
369  }
370  return mom;
371  }
372 
382  template <typename Branch>
383  const Branch *choose_channel(const ProcessBranchList<Branch> &subprocesses,
384  double total_weight) {
385  double random_weight = random::uniform(0., total_weight);
386  double weight_sum = 0.;
387  /* Loop through all subprocesses and select one by Monte Carlo, based on
388  * their weights. */
389  for (const auto &proc : subprocesses) {
390  weight_sum += proc->weight();
391  if (random_weight <= weight_sum) {
392  /* Return the full process information. */
393  return proc.get();
394  }
395  }
396  /* Should never get here. */
398  "Problem in choose_channel: ", subprocesses.size(), " ",
399  weight_sum, " ", total_weight, " ",
400  // random_weight, "\n", *this);
401  random_weight, "\n");
402  std::abort();
403  }
404 
415  virtual std::pair<double, double> sample_masses(
416  double kinetic_energy_cm) const;
417 
427  virtual void sample_angles(std::pair<double, double> masses,
428  double kinetic_energy_cm);
429 
435 
442  virtual void sample_3body_phasespace();
443 
448  virtual void sample_5body_phasespace();
449 
466 
473  virtual void format_debug_output(std::ostream &out) const = 0;
474 
479  friend std::ostream &operator<<(std::ostream &out, const Action &action) {
480  action.format_debug_output(out);
481  return out;
482  }
483 
484  private:
491  const ParticleType &type_of_pout(const ParticleData &p_out) const {
492  return p_out.type();
493  }
502  const ParticleType &type_of_pout(const ParticleTypePtr &p_out) const {
503  return *p_out;
504  }
505 };
506 
514 inline std::vector<ActionPtr> &operator+=(std::vector<ActionPtr> &lhs,
515  std::vector<ActionPtr> &&rhs) {
516  if (lhs.size() == 0) {
517  lhs = std::move(rhs);
518  } else {
519  lhs.insert(lhs.end(), std::make_move_iterator(rhs.begin()),
520  std::make_move_iterator(rhs.end()));
521  }
522  return lhs;
523 }
524 
529 inline std::ostream &operator<<(std::ostream &out, const ActionPtr &action) {
530  return out << *action;
531 }
532 
537 std::ostream &operator<<(std::ostream &out, const ActionList &actions);
538 
539 } // namespace smash
540 
541 #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:297
FourVector total_momentum_of_outgoing_particles() const
Calculate the total kinetic momentum of the outgoing particles.
Definition: action.cc:152
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:183
virtual ~Action()
Virtual Destructor.
virtual void sample_5body_phasespace()
Sample the full 5-body phase-space (masses, momenta, angles) in the center-of-mass frame for the fina...
Definition: action.cc:345
int stochastic_position_idx_
This stores a randomly-chosen index to an incoming particle.
Definition: action.h:362
std::pair< FourVector, FourVector > get_potential_at_interaction_point() const
Get the skyrme and asymmetry potential at the interaction point.
Definition: action.cc:108
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
ParticleList outgoing_particles_
Initially this stores only the PDG codes of final-state particles.
Definition: action.h:339
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:491
FourVector total_momentum() const
Sum of 4-momenta of incoming particles.
Definition: action.h:365
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:345
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:124
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:383
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:355
ParticleList incoming_particles_
List with data of incoming particles.
Definition: action.h:331
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:245
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
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:348
virtual void check_conservation(const uint32_t id_process) const
Check various conservation laws.
Definition: action.cc:413
const ParticleType & type_of_pout(const ParticleTypePtr &p_out) const
Get the particle type for given pointer to a particle type.
Definition: action.h:502
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
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:665
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:529
friend std::ostream & operator<<(std::ostream &out, const Action &action)
Dispatches formatting to the virtual Action::format_debug_output function.
Definition: action.h:479
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:514