Version: SMASH-3.1
action.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2024
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 
195  virtual double perform(Particles *particles, uint32_t id_process);
196 
208  bool is_valid(const Particles &particles) const;
209 
224  bool is_pauli_blocked(const std::vector<Particles> &ensembles,
225  const PauliBlocker &p_bl) const;
226 
232  const ParticleList &incoming_particles() const;
233 
240  void update_incoming(const Particles &particles);
241 
247  const ParticleList &outgoing_particles() const { return outgoing_particles_; }
248 
254  double time_of_execution() const { return time_of_execution_; }
255 
264  virtual double check_conservation(const uint32_t id_process) const;
265 
271  double sqrt_s() const { return total_momentum().abs(); }
272 
284 
291 
297  std::pair<FourVector, FourVector> get_potential_at_interaction_point() const;
298 
304  const int max_inc_idx = incoming_particles_.size() - 1;
306  }
307 
315  static double lambda_tilde(double a, double b, double c) {
316  const double res = (a - b - c) * (a - b - c) - 4. * b * c;
317  if (res < 0.0) {
318  // floating point precision problem
319  return 0.0;
320  }
321  return res;
322  }
323 
330  class InvalidResonanceFormation : public std::invalid_argument {
331  using std::invalid_argument::invalid_argument;
332  };
333 
340  class StochasticBelowEnergyThreshold : public std::runtime_error {
341  using std::runtime_error::runtime_error;
342  };
343 
350  double sqrts, const std::vector<double> &m,
351  std::vector<FourVector> &sampled_momenta);
352 
353  protected:
355  ParticleList incoming_particles_;
356 
363  ParticleList outgoing_particles_;
364 
369  const double time_of_execution_;
370 
373 
379  double box_length_ = -1.0;
380 
387 
390  FourVector mom(0.0, 0.0, 0.0, 0.0);
391  for (const auto &p : incoming_particles_) {
392  mom += p.momentum();
393  }
394  return mom;
395  }
396 
406  template <typename Branch>
407  const Branch *choose_channel(const ProcessBranchList<Branch> &subprocesses,
408  double total_weight) {
409  double random_weight = random::uniform(0., total_weight);
410  double weight_sum = 0.;
411  /* Loop through all subprocesses and select one by Monte Carlo, based on
412  * their weights. */
413  for (const auto &proc : subprocesses) {
414  weight_sum += proc->weight();
415  if (random_weight <= weight_sum) {
416  /* Return the full process information. */
417  return proc.get();
418  }
419  }
420  /* Should never get here. */
422  "Problem in choose_channel: ", subprocesses.size(), " ",
423  weight_sum, " ", total_weight, " ",
424  // random_weight, "\n", *this);
425  random_weight, "\n");
426  std::abort();
427  }
428 
439  virtual std::pair<double, double> sample_masses(
440  double kinetic_energy_cm) const;
441 
451  virtual void sample_angles(std::pair<double, double> masses,
452  double kinetic_energy_cm);
453 
459 
466  virtual void sample_manybody_phasespace();
467 
484 
491  virtual void format_debug_output(std::ostream &out) const = 0;
492 
497  friend std::ostream &operator<<(std::ostream &out, const Action &action) {
498  action.format_debug_output(out);
499  return out;
500  }
501 
502  private:
509  const ParticleType &type_of_pout(const ParticleData &p_out) const {
510  return p_out.type();
511  }
520  const ParticleType &type_of_pout(const ParticleTypePtr &p_out) const {
521  return *p_out;
522  }
523 };
524 
532 inline std::vector<ActionPtr> &operator+=(std::vector<ActionPtr> &lhs,
533  std::vector<ActionPtr> &&rhs) {
534  if (lhs.size() == 0) {
535  lhs = std::move(rhs);
536  } else {
537  lhs.insert(lhs.end(), std::make_move_iterator(rhs.begin()),
538  std::make_move_iterator(rhs.end()));
539  }
540  return lhs;
541 }
542 
547 inline std::ostream &operator<<(std::ostream &out, const ActionPtr &action) {
548  return out << *action;
549 }
550 
555 std::ostream &operator<<(std::ostream &out, const ActionList &actions);
556 
557 } // namespace smash
558 
559 #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:330
Exception for a temporary bugfix for when multiparticle interactions do not have the necessary energy...
Definition: action.h:340
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:302
FourVector total_momentum_of_outgoing_particles() const
Calculate the total kinetic momentum of the outgoing particles.
Definition: action.cc:157
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:188
virtual ~Action()
Virtual Destructor.
int stochastic_position_idx_
This stores a randomly-chosen index to an incoming particle.
Definition: action.h:386
std::pair< FourVector, FourVector > get_potential_at_interaction_point() const
Get the skyrme and asymmetry potential at the interaction point.
Definition: action.cc:112
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:279
ParticleList outgoing_particles_
Initially this stores only the PDG codes of final-state particles.
Definition: action.h:363
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:509
FourVector total_momentum() const
Sum of 4-momenta of incoming particles.
Definition: action.h:389
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:446
const double time_of_execution_
Time at which the action is supposed to be performed (absolute time in the lab frame in fm).
Definition: action.h:369
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:303
virtual double perform(Particles *particles, uint32_t id_process)
Actually perform the action, e.g.
Definition: action.cc:128
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:62
Action(const ParticleList &in_part, double time)
Construct an action object with incoming particles and relative time.
Definition: action.h:44
virtual double check_conservation(const uint32_t id_process) const
Check various conservation laws.
Definition: action.cc:475
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
Definition: action.cc:58
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:254
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:407
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:271
double box_length_
Box length: needed to determine coordinates of collision correctly in case of collision through the w...
Definition: action.h:379
ParticleList incoming_particles_
List with data of incoming particles.
Definition: action.h:355
FourVector get_interaction_point() const
Get the interaction point.
Definition: action.cc:68
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:250
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:315
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:372
const ParticleType & type_of_pout(const ParticleTypePtr &p_out) const
Get the particle type for given pointer to a particle type.
Definition: action.h:520
const ParticleList & outgoing_particles() const
Get the list of particles that resulted from the action.
Definition: action.h:247
bool is_valid(const Particles &particles) const
Check whether the action still applies.
Definition: action.cc:29
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:313
bool is_pauli_blocked(const std::vector< Particles > &ensembles, const PauliBlocker &p_bl) const
Check if the action is Pauli-blocked.
Definition: action.cc:35
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:464
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:676
Particle type contains the static properties of a particle species.
Definition: particletype.h:98
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:153
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:547
friend std::ostream & operator<<(std::ostream &out, const Action &action)
Dispatches formatting to the virtual Action::format_debug_output function.
Definition: action.h:497
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
ProcessTypes are used to identify the type of the process.
Definition: processbranch.h:39
std::vector< ActionPtr > & operator+=(std::vector< ActionPtr > &lhs, std::vector< ActionPtr > &&rhs)
Append vector of action pointers.
Definition: action.h:532