305 : coll_crit_(parameters.coll_crit),
307 config.take({
"Collision_Term",
"Elastic_Cross_Section"}, -1.)),
308 testparticles_(parameters.testparticles),
309 isotropic_(config.take({
"Collision_Term",
"Isotropic"},
false)),
310 two_to_one_(parameters.two_to_one),
311 incl_set_(parameters.included_2to2),
312 incl_multi_set_(parameters.included_multi),
313 scale_xs_(parameters.scale_xs),
314 additional_el_xs_(parameters.additional_el_xs),
315 low_snn_cut_(parameters.low_snn_cut),
316 strings_switch_(parameters.strings_switch),
317 use_AQM_(parameters.use_AQM),
318 strings_with_probability_(parameters.strings_with_probability),
319 nnbar_treatment_(parameters.nnbar_treatment),
320 box_length_(parameters.box_length),
321 string_formation_time_(config.take(
322 {
"Collision_Term",
"String_Parameters",
"Formation_Time"}, 1.)),
323 maximum_cross_section_(parameters.maximum_cross_section),
324 allow_first_collisions_within_nucleus_(
325 parameters.allow_collisions_within_nucleus),
326 only_warn_for_high_prob_(config.take(
327 {
"Collision_Term",
"Only_Warn_For_High_Probability"},
false)) {
328 if (is_constant_elastic_isotropic()) {
330 "Constant elastic isotropic cross-section mode:",
" using ",
331 elastic_parameter_,
" mb as maximal cross-section.");
334 throw std::invalid_argument(
335 "Multi-body reactions (like e.g. 3->1 or 3->2) are only possible with "
338 "criterion. Change your config accordingly.");
344 throw std::invalid_argument(
345 "To prevent double counting it is not possible to enable deuteron 3->2 "
346 "reactions\nand reactions involving the d' at the same time\ni.e. to "
347 "include \"Deuteron_3to2\" in `Multi_Particle_Reactions` and\n "
348 "\"PiDeuteron_to_pidprime\" "
349 "or \"NDeuteron_to_Ndprime\" in `Included_2to2` at the same time.\n"
350 "Change your config accordingly.");
357 throw std::invalid_argument(
358 "In order to conserve detailed balance, when \"NNbar_5to2\" is "
359 "included in\n`Multi_Particle_Reactions`, the `NNbarTreatment` has to "
360 "be set to \"two to five\" and vice versa.");
365 throw std::invalid_argument(
366 "'NNbar' has to be in the list of allowed 2 to 2 processes "
367 "to enable annihilation to go through resonances");
370 if (strings_switch_) {
371 auto subconfig = config[
"Collision_Term"][
"String_Parameters"];
372 string_process_interface_ = make_unique<StringProcess>(
373 subconfig.take({
"String_Tension"}, 1.0), string_formation_time_,
374 subconfig.take({
"Gluon_Beta"}, 0.5),
375 subconfig.take({
"Gluon_Pmin"}, 0.001),
376 subconfig.take({
"Quark_Alpha"}, 2.0),
377 subconfig.take({
"Quark_Beta"}, 7.0),
378 subconfig.take({
"Strange_Supp"}, 0.16),
379 subconfig.take({
"Diquark_Supp"}, 0.036),
380 subconfig.take({
"Sigma_Perp"}, 0.42),
381 subconfig.take({
"StringZ_A_Leading"}, 0.2),
382 subconfig.take({
"StringZ_B_Leading"}, 2.0),
383 subconfig.take({
"StringZ_A"}, 2.0), subconfig.take({
"StringZ_B"}, 0.55),
384 subconfig.take({
"String_Sigma_T"}, 0.5),
385 subconfig.take({
"Form_Time_Factor"}, 1.0),
386 subconfig.take({
"Mass_Dependent_Formation_Times"},
false),
387 subconfig.take({
"Prob_proton_to_d_uu"}, 1. / 3.),
388 subconfig.take({
"Separate_Fragment_Baryon"},
true),
389 subconfig.take({
"Popcorn_Rate"}, 0.15));
395 const std::vector<FourVector>& beam_momentum,
396 const double gcell_vol)
const {
402 assert(data_a.
id() >= 0);
403 assert(data_b.
id() >= 0);
408 bool never_interacted_before =
411 if (in_same_nucleus && never_interacted_before) {
423 const double time_until_collision =
427 if (time_until_collision < 0. || time_until_collision >= dt) {
432 ScatterActionPtr act = make_unique<ScatterAction>(
437 act->set_stochastic_pos_idx();
445 const double distance_squared =
447 ? act->transverse_distance_sqr()
449 ? act->cov_transverse_distance_sqr()
473 const double v_rel = act->relative_velocity();
476 const double prob = xs * v_rel * dt / gcell_vol;
479 "Stochastic collison criterion parameters (2-particles):\nprob = ",
480 prob,
", xs = ", xs,
", v_rel = ", v_rel,
", dt = ", dt,
481 ", gcell_vol = ", gcell_vol,
", testparticles = ",
testparticles_);
484 std::stringstream err;
485 err <<
"Probability larger than 1 for stochastic rates. ( P_22 = " << prob
486 <<
" )\nConsider using smaller timesteps.";
490 throw std::runtime_error(err.str());
496 if (random_no > prob) {
513 const double cross_section_criterion = xs * M_1_PI;
516 if (distance_squared >= cross_section_criterion) {
521 "\n ", data_a,
"\n<-> ", data_b);
526 return std::move(act);
530 const ParticleList& plist,
double dt,
const double gcell_vol)
const {
538 bool all_projectile =
540 return data.belongs_to() == BelongsTo::Projectile;
544 return data.belongs_to() == BelongsTo::Target;
548 return data.get_history().collisions_per_particle == 0;
550 if ((all_projectile || all_target) && none_collided) {
566 ScatterActionMultiPtr act =
567 make_unique<ScatterActionMulti>(plist, time_until_collision);
569 act->set_stochastic_pos_idx();
578 act->get_total_weight() / std::pow(
testparticles_, plist.size() - 1);
582 std::stringstream err;
583 err <<
"Probability larger than 1 for stochastic rates. ( P_nm = " << prob
584 <<
" )\nConsider using smaller timesteps.";
588 throw std::runtime_error(err.str());
594 if (random_no > prob) {
598 return std::move(act);
602 const ParticleList& search_list,
double dt,
const double gcell_vol,
603 const std::vector<FourVector>& beam_momentum)
const {
604 std::vector<ActionPtr> actions;
608 if (p1.id() < p2.id()) {
612 actions.push_back(std::move(act));
622 if (p1.id() < p2.id() && p2.id() < p3.id()) {
626 actions.push_back(std::move(act));
632 search_list.size() >= 5) {
635 if ((p1.id() < p2.id() && p2.id() < p3.id() &&
636 p3.id() < p4.id() && p4.id() < p5.id()) &&
637 (p1.is_pion() && p2.is_pion() && p3.is_pion() &&
638 p4.is_pion() && p5.is_pion())) {
641 {p1, p2, p3, p4, p5}, dt, gcell_vol);
643 actions.push_back(std::move(act));
657 const ParticleList& search_list,
const ParticleList& neighbors_list,
658 double dt,
const std::vector<FourVector>& beam_momentum)
const {
659 std::vector<ActionPtr> actions;
666 assert(p1.id() != p2.id());
670 actions.push_back(std::move(act));
678 const ParticleList& search_list,
const Particles& surrounding_list,
679 double dt,
const std::vector<FourVector>& beam_momentum)
const {
680 std::vector<ActionPtr> actions;
688 auto result = std::find_if(
689 search_list.begin(), search_list.end(),
691 if (result != search_list.end()) {
698 actions.push_back(std::move(act));
706 constexpr
double time = 0.0;
709 const size_t N_pairs = N_isotypes * (N_isotypes - 1) / 2;
711 std::cout << N_isotypes <<
" iso-particle types." << std::endl;
712 std::cout <<
"They can make " << N_pairs <<
" pairs." << std::endl;
713 std::vector<double> momentum_scan_list = {0.1, 0.3, 0.5, 1.0,
714 2.0, 3.0, 5.0, 10.0};
717 if (&A_isotype > &B_isotype) {
720 bool any_nonzero_cs =
false;
721 std::vector<std::string> r_list;
724 if (A_type > B_type) {
728 for (
auto mom : momentum_scan_list) {
729 A.set_4momentum(A.pole_mass(), mom, 0.0, 0.0);
731 ScatterActionPtr act = make_unique<ScatterAction>(
736 act->add_all_scatterings(
741 const double total_cs = act->cross_section();
742 if (total_cs <= 0.0) {
745 any_nonzero_cs =
true;
746 for (
const auto& channel : act->collision_channels()) {
747 const auto type = channel->get_type();
751 r = A_type->name() + B_type->name() + std::string(
" → strings");
755 ? std::string(
" (el)")
757 ? std::string(
" (inel)")
758 : std::string(
" (?)");
759 r = A_type->name() + B_type->name() + std::string(
" → ") +
760 channel->particle_types()[0]->name() +
761 channel->particle_types()[1]->name() + r_type;
769 std::sort(r_list.begin(), r_list.end());
770 r_list.erase(std::unique(r_list.begin(), r_list.end()), r_list.end());
771 if (any_nonzero_cs) {
772 for (
auto r : r_list) {
774 if (r_list.back() != r) {
778 std::cout << std::endl;
808 namespace decaytree {
856 Node(
const std::string& name,
double weight,
857 ParticleTypePtrList&& initial_particles,
858 ParticleTypePtrList&& final_particles, ParticleTypePtrList&& state,
859 std::vector<Node>&& children)
879 ParticleTypePtrList&& initial_particles,
880 ParticleTypePtrList&& final_particles) {
882 ParticleTypePtrList state(
state_);
883 for (
const auto&
p : initial_particles) {
884 state.erase(std::find(state.begin(), state.end(),
p));
886 for (
const auto&
p : final_particles) {
890 std::sort(state.begin(), state.end(),
892 return a->name() < b->name();
895 Node new_node(name, weight, std::move(initial_particles),
896 std::move(final_particles), std::move(state), {});
897 children_.emplace_back(std::move(new_node));
908 std::vector<FinalStateCrossSection> result;
921 for (uint64_t i = 0; i < depth; i++) {
926 child.print_helper(depth + 1);
942 uint64_t depth, std::vector<FinalStateCrossSection>& result,
943 const std::string& name,
double weight,
944 bool show_intermediate_states =
false)
const {
952 std::string new_name;
955 if (show_intermediate_states) {
957 if (!new_name.empty()) {
965 for (
const auto& s :
state_) {
966 new_name += s->name();
969 if (show_intermediate_states) {
978 child.final_state_cross_sections_helper(depth + 1, result, new_name,
979 weight, show_intermediate_states);
993 const DecayBranchPtr& decay,
994 ParticleTypePtrList& final_state) {
995 std::stringstream name;
996 name <<
"[" << res_name <<
"->";
997 for (
const auto&
p : decay->particle_types()) {
999 final_state.push_back(
p);
1023 uint32_t n_unstable = 0;
1024 double sqrts_minus_masses = sqrts;
1029 sqrts_minus_masses -= ptype->
mass();
1032 n_unstable != 0 ? 1. /
static_cast<double>(n_unstable) : 1.;
1036 const double sqrts_decay = sqrts_minus_masses + ptype->
mass();
1037 bool can_decay =
false;
1042 double final_state_mass = 0.;
1043 for (
const auto&
p : decay->particle_types()) {
1044 final_state_mass +=
p->mass();
1046 if (final_state_mass > sqrts_decay) {
1051 ParticleTypePtrList parts;
1053 auto& new_node = node.
add_action(name, norm * decay->weight(), {ptype},
1074 static void deduplicate(std::vector<FinalStateCrossSection>& final_state_xs) {
1075 std::sort(final_state_xs.begin(), final_state_xs.end(),
1078 auto current = final_state_xs.begin();
1079 while (current != final_state_xs.end()) {
1080 auto adjacent = std::adjacent_find(
1081 current, final_state_xs.end(),
1083 return a.name_ == b.name_;
1086 if (adjacent != final_state_xs.end()) {
1087 adjacent->cross_section_ += (adjacent + 1)->cross_section_;
1088 final_state_xs.erase(adjacent + 1);
1095 bool final_state, std::vector<double>& plab)
const {
1096 typedef std::vector<std::pair<double, double>> xs_saver;
1097 std::map<std::string, xs_saver> xs_dump;
1098 std::map<std::string, double> outgoing_total_mass;
1101 int n_momentum_points = 200;
1102 constexpr
double momentum_step = 0.02;
1109 if (plab.size() > 0) {
1110 n_momentum_points = plab.size();
1112 std::sort(plab.begin(), plab.end());
1113 plab.erase(std::unique(plab.begin(), plab.end()), plab.end());
1115 for (
int i = 0; i < n_momentum_points; i++) {
1117 if (plab.size() > 0) {
1120 momentum = momentum_step * (i + 1);
1122 a_data.set_4momentum(m_a, momentum, 0.0, 0.0);
1124 const double sqrts = (a_data.momentum() + b_data.
momentum()).abs();
1125 const ParticleList incoming = {a_data, b_data};
1126 ScatterActionPtr act = make_unique<ScatterAction>(
1136 {&a, &b}, {&a, &b}, {});
1137 const CollisionBranchList& processes = act->collision_channels();
1138 for (
const auto& process : processes) {
1139 const double xs = process->weight();
1144 std::stringstream process_description_stream;
1145 process_description_stream << *process;
1146 const std::string& description = process_description_stream.str();
1148 for (
const auto& ptype : process->particle_types()) {
1149 m_tot += ptype->mass();
1151 outgoing_total_mass[description] = m_tot;
1152 if (!xs_dump[description].empty() &&
1153 std::abs(xs_dump[description].back().first - sqrts) <
1155 xs_dump[description].back().second += xs;
1157 xs_dump[description].push_back(std::make_pair(sqrts, xs));
1160 std::stringstream process_description_stream;
1161 process_description_stream << *process;
1162 const std::string& description = process_description_stream.str();
1163 ParticleTypePtrList initial_particles = {&a, &b};
1164 ParticleTypePtrList final_particles = process->particle_types();
1165 auto& process_node =
1166 tree.
add_action(description, xs, std::move(initial_particles),
1167 std::move(final_particles));
1171 xs_dump[
"total"].push_back(std::make_pair(sqrts, act->cross_section()));
1173 outgoing_total_mass[
"total"] = -1.0;
1178 for (
const auto&
p : final_state_xs) {
1183 if (
p.name_ ==
"") {
1186 outgoing_total_mass[
p.name_] =
p.mass_;
1187 xs_dump[
p.name_].push_back(std::make_pair(sqrts,
p.cross_section_));
1194 for (
auto it = begin(xs_dump); it != end(xs_dump);) {
1196 const xs_saver& xs = (*it).second;
1198 for (
const auto&
p : xs) {
1202 it = xs_dump.erase(it);
1209 std::vector<std::string> all_channels;
1210 for (
const auto& channel : xs_dump) {
1211 all_channels.push_back(channel.first);
1213 std::sort(all_channels.begin(), all_channels.end(),
1214 [&](
const std::string& str_a,
const std::string& str_b) {
1215 return outgoing_total_mass[str_a] < outgoing_total_mass[str_b];
1219 std::cout <<
"# Dumping partial " << a.
name() << b.
name()
1220 <<
" cross-sections in mb, energies in GeV" << std::endl;
1221 std::cout <<
" sqrt_s";
1225 for (
const auto& channel : all_channels) {
1228 std::cout << std::endl;
1231 for (
int i = 0; i < n_momentum_points; i++) {
1233 if (plab.size() > 0) {
1236 momentum = momentum_step * (i + 1);
1238 a_data.set_4momentum(m_a, momentum, 0.0, 0.0);
1240 const double sqrts = (a_data.momentum() + b_data.
momentum()).abs();
1241 std::printf(
"%9.6f", sqrts);
1242 for (
const auto& channel : all_channels) {
1243 const xs_saver energy_and_xs = xs_dump[channel];
1245 for (; j < energy_and_xs.size() && energy_and_xs[j].first < sqrts; j++) {
1248 if (j < energy_and_xs.size() &&
1249 std::abs(energy_and_xs[j].first - sqrts) <
really_small) {
1250 xs = energy_and_xs[j].second;
1252 std::printf(
"%16.6f", xs);
Interface to the SMASH configuration files.
const DecayBranchList & decay_mode_list() const
IsoParticleType is a class to represent isospin multiplets.
static const IsoParticleTypeList & list_all()
Returns a list of all IsoParticleTypes.
ParticleData contains the dynamic information of a certain particle.
void set_4momentum(const FourVector &momentum_vector)
Set the particle's 4-momentum directly.
double xsec_scaling_factor(double delta_time=0.) const
Return the cross section scaling factor at a given time.
uint32_t id_process() const
Get the id of the last action.
const FourVector & momentum() const
Get the particle's 4-momentum.
BelongsTo belongs_to() const
Getter for belongs_to label.
int32_t id() const
Get the id of the particle.
HistoryData get_history() const
Get history information.
double pole_mass() const
Get the particle's pole mass ("on-shell").
const FourVector & position() const
Get the particle's position in Minkowski space.
A pointer-like interface to global references to ParticleType objects.
Particle type contains the static properties of a particle species.
const DecayModes & decay_modes() const
const std::string & name() const
The Particles class abstracts the storage and manipulation of particles.
const int testparticles_
Number of test particles.
const MultiParticleReactionsBitSet incl_multi_set_
List of included multi-particle reactions.
ActionList find_actions_in_cell(const ParticleList &search_list, double dt, const double gcell_vol, const std::vector< FourVector > &beam_momentum) const override
Search for all the possible collisions within one cell.
const double elastic_parameter_
Elastic cross section parameter (in mb).
void dump_cross_sections(const ParticleType &a, const ParticleType &b, double m_a, double m_b, bool final_state, std::vector< double > &plab) const
Print out partial cross-sections of all processes that can occur in the collision of a(mass = m_a) an...
const bool strings_switch_
Switch to turn off string excitation.
const double additional_el_xs_
Additional constant elastic cross section.
const double scale_xs_
Factor by which all (partial) cross sections are scaled.
const bool allow_first_collisions_within_nucleus_
If particles within nucleus are allowed to collide for their first time.
const NNbarTreatment nnbar_treatment_
Switch for NNbar reactions.
const double low_snn_cut_
Elastic collsions between two nucleons with sqrt_s below low_snn_cut_ are excluded.
const bool use_AQM_
Switch to control whether to use AQM or not.
const bool isotropic_
Do all collisions isotropically.
double max_transverse_distance_sqr(int testparticles) const
The maximal distance over which particles can interact in case of the geometric criterion,...
const bool only_warn_for_high_prob_
Switch to turn off throwing an exception for collision probabilities larger than 1.
const CollisionCriterion coll_crit_
Specifies which collision criterion is used.
ScatterActionsFinder(Configuration config, const ExperimentParameters ¶meters)
Constructor of the finder with the given parameters.
const ReactionsBitSet incl_set_
List of included 2<->2 reactions.
const bool two_to_one_
Enable 2->1 processes.
ActionPtr check_collision_two_part(const ParticleData &data_a, const ParticleData &data_b, double dt, const std::vector< FourVector > &beam_momentum={}, const double gcell_vol=0.0) const
Check for a single pair of particles (id_a, id_b) if a collision will happen in the next timestep and...
const double string_formation_time_
Parameter for formation time.
std::unique_ptr< StringProcess > string_process_interface_
Class that deals with strings, interfacing Pythia.
void dump_reactions() const
Prints out all the 2-> n (n > 1) reactions with non-zero cross-sections between all possible pairs of...
ActionPtr check_collision_multi_part(const ParticleList &plist, double dt, const double gcell_vol) const
Check for multiple i.e.
const double box_length_
Box length: needed to determine coordinates of collision correctly in case of collision through the w...
ActionList find_actions_with_surrounding_particles(const ParticleList &search_list, const Particles &surrounding_list, double dt, const std::vector< FourVector > &beam_momentum) const override
Search for all the possible secondary collisions between the outgoing particles and the rest.
const bool strings_with_probability_
Decide whether to implement string fragmentation based on a probability.
ActionList find_actions_with_neighbors(const ParticleList &search_list, const ParticleList &neighbors_list, double dt, const std::vector< FourVector > &beam_momentum) const override
Search for all the possible collisions among the neighboring cells.
double collision_time(const ParticleData &p1, const ParticleData &p2, double dt, const std::vector< FourVector > &beam_momentum) const
Determine the collision time of the two particles.
Collection of useful constants that are known at compile time.
@ TwoToFive
Directly create 5 pions, use with multi-particle reactions.
@ Resonances
Use intermediate Resonances.
@ Stochastic
Stochastic Criteiron.
@ Geometric
(Default) geometric criterion.
@ Covariant
Covariant Criterion.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
static std::string make_decay_name(const std::string &res_name, const DecayBranchPtr &decay, ParticleTypePtrList &final_state)
Generate name for decay and update final state.
static void add_decays(Node &node, double sqrts)
Add nodes for all decays possible from the given node and all of its children.
std::string fill_left(const std::string &s, size_t width, char fill=' ')
Fill string with characters to the left until the given width is reached.
static void deduplicate(std::vector< FinalStateCrossSection > &final_state_xs)
Deduplicate the final-state cross sections by summing.
@ TwoToTwo
2->2 inelastic scattering
@ Elastic
elastic scattering: particles remain the same, only momenta change
@ StringHard
hard string process involving 2->2 QCD process by PYTHIA.
bool all_of(Container &&c, UnaryPredicate &&p)
Convenience wrapper for std::all_of that operates on a complete container.
T pCM_from_s(const T s, const T mass_a, const T mass_b) noexcept
constexpr double really_small
Numerical error tolerance.
void isoclean(std::string &s)
Remove ⁺, ⁻, ⁰ from string.
static constexpr int LFindScatter
bool is_string_soft_process(ProcessType p)
Check if a given process type is a soft string excitation.
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...
constexpr double fm2_mb
mb <-> fm^2 conversion factor.
Helper structure for Experiment.
Represent a final-state cross section.
FinalStateCrossSection(const std::string &name, double cross_section, double mass)
Construct a final-state cross section.
std::string name_
Name of the final state.
double cross_section_
Corresponding cross section in mb.
double mass_
Total mass of final state particles.
int32_t collisions_per_particle
Collision counter per particle, zero only for initially present particles.
Node of a decay tree, representing a possible action (2-to-2 or 1-to-2).
std::vector< Node > children_
Possible actions after this action.
void final_state_cross_sections_helper(uint64_t depth, std::vector< FinalStateCrossSection > &result, const std::string &name, double weight, bool show_intermediate_states=false) const
Internal helper function for final_state_cross_sections, to be called recursively to calculate all fi...
ParticleTypePtrList final_particles_
Final-state particle types in this action.
std::vector< FinalStateCrossSection > final_state_cross_sections() const
Node & add_action(const std::string &name, double weight, ParticleTypePtrList &&initial_particles, ParticleTypePtrList &&final_particles)
Add an action to the children of this node.
ParticleTypePtrList initial_particles_
Initial-state particle types in this action.
void print() const
Print the decay tree starting with this node.
void print_helper(uint64_t depth) const
Internal helper function for print, to be called recursively to print all nodes.
double weight_
Weight (cross section or branching ratio).
Node(const Node &)=delete
Cannot be copied.
Node(const std::string &name, double weight, ParticleTypePtrList &&initial_particles, ParticleTypePtrList &&final_particles, ParticleTypePtrList &&state, std::vector< Node > &&children)
Node(Node &&)=default
Move constructor.
ParticleTypePtrList state_
Particle types corresponding to the global state after this action.
std::string name_
Name for printing.