Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Afterburner.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Afterburner.cc
1 /*******************************************************************************
2  * Copyright (c) The JETSCAPE Collaboration, 2018
3  *
4  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
5  *
6  * For the list of contributors see AUTHORS.
7  *
8  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
9  *
10  * or via email to bugs.jetscape@gmail.com
11  *
12  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
13  * See COPYING for details.
14  ******************************************************************************/
15 // This is a general basic class for hadronic afterburner
16 
17 #include "./Afterburner.h"
19 
20 using namespace std;
21 
22 namespace Jetscape {
24  // Makes sure that XML file with options and parameters is loaded
26  JSINFO << "Initializing Afterburner : " << GetId() << " ...";
27  // Initialize random number distribution
28  ZeroOneDistribution = uniform_real_distribution<double>{0.0, 1.0};
29  InitTask();
30 }
31 
32 void Afterburner::Exec() {
33  VERBOSE(2) << "Afterburner running: " << GetId() << " ...";
34  ExecuteTask();
35 }
36 
37 std::vector<std::vector<std::shared_ptr<Hadron>>> Afterburner::GetSoftParticlizationHadrons() {
38  auto soft_particlization = JetScapeSignalManager::Instance()->GetSoftParticlizationPointer().lock();
39  if (!soft_particlization) {
40  JSWARN << "No soft particlization module found. Check if fragmentation"
41  << " hadrons are handed to afterburner.";
42  std::vector<std::shared_ptr<Hadron>> hadrons;
43  dummy.push_back(hadrons);
44  return dummy;
45  } else {
46  return soft_particlization->Hadron_list_;
47  }
48 }
49 
50 std::vector<shared_ptr<Hadron>> Afterburner::GetFragmentationHadrons() {
51  JSINFO << "Get fragmentation hadrons in Afterburner";
52  auto hadronization_mgr = JetScapeSignalManager::Instance()->GetHadronizationManagerPointer().lock();
53  if (!hadronization_mgr) {
54  JSWARN << "No hardronization module found. It is necessary to include"
55  << " fragmentation hadrons to afterburner as requested.";
56  exit(1);
57  }
58  std::vector<shared_ptr<Hadron>> h_list;
59  hadronization_mgr->GetHadrons(h_list);
60  JSINFO << "Got " << h_list.size() << " fragmentation hadrons from HadronizationManager.";
61 
62  std::vector<shared_ptr<Hadron>> h_list_new;
63  rand_int_ptr_ = (std::make_shared<std::uniform_int_distribution<int>>(0,1));
64  for (auto h : h_list) {
65  if (h->has_no_position()) {
66  JSDEBUG << "Found fragmentation hadron without properly set position in "
67  "Afterburner.\nInclusion of fragmentation hadrons only "
68  "possible for HybridHadronization.";
69  }
70 
71  //move all the fragmentation hadrons a little bit around to avoid having
72  //multiple hadrons at the same position if they are at the same position
73  const FourVector r = h->x_in();
74  const double rand_x = ZeroOneDistribution(*GetMt19937Generator()) * 2e-4 - 1e-4;
75  const double rand_y = ZeroOneDistribution(*GetMt19937Generator()) * 2e-4 - 1e-4;
76  const double rand_z = ZeroOneDistribution(*GetMt19937Generator()) * 2e-4 - 1e-4;
77  double position_smeared[4] = {r.t(), r.x()+rand_x, r.y()+rand_y, r.z()+rand_z};
78  h->set_x(position_smeared);
79 
80  if ((std::abs(h->pid())>10) && (h->pid() != 21)) {
81  if (h->pstat() > 0) {
82  // convert Kaon-L or Kaon-S into K0 or Anti-K0
83  if (h->pid() == 310 || h->pid() == 130) {
84  const int rand_int = (*rand_int_ptr_)(*GetMt19937Generator());
85  const int id = (rand_int == 0) ? 311 : -311;
86  h->set_id(id);
87  }
88  h_list_new.push_back(h);
89  } else if(h->pstat() < 0) {
90  // convert Kaon-L or Kaon-S into K0 or Anti-K0
91  // change id of negative Kaons to make them consistent with the SMASH output
92  if (h->pid() == 310 || h->pid() == 130) {
93  const int rand_int = (*rand_int_ptr_)(*GetMt19937Generator());
94  const int id = (rand_int == 0) ? 311 : -311;
95  h->set_id(id);
96  }
97  }
98  } else if((std::abs(h->pid())<10) || (h->pid() == 21)){
99  JSWARN << "Found a free quark or gluon! This can not be handed over to SMASH.\n"
100  "Check confinement in hadronization module!";
101  }
102  }
103  return h_list_new;
104 }
105 
106 std::vector<std::vector<std::shared_ptr<Hadron>>> Afterburner::GatherAfterburnerHadrons() {
107  std::vector<std::vector<shared_ptr<Hadron>>> afterburner_had_events;
108  afterburner_had_events = GetSoftParticlizationHadrons();
109 
110  if (GetXMLElementInt({"Afterburner", "output_only_final_state_hadrons"})) {
111  // clear Hadron_list_ in soft_particlization, otherwise the final hadron
112  // output of the writer contains also the soft hadrons which were used as
113  // input for SMASH
114  auto soft_particlization = JetScapeSignalManager::Instance()->GetSoftParticlizationPointer().lock();
115  if (soft_particlization) {
116  soft_particlization->Hadron_list_.clear();
117  }
118  }
119 
120  if (GetXMLElementInt({"Afterburner", "include_fragmentation_hadrons"})) {
121  if (afterburner_had_events.size() > 1) {
122  JSWARN << "Fragmentation hadrons in Afterburner are only possible without "
123  "repeated sampling from SoftParticlization. Exiting.";
124  exit(1);
125  }
126  std::vector<shared_ptr<Hadron>> frag_hadrons = GetFragmentationHadrons();
127 
128  if (GetXMLElementInt({"Afterburner", "output_only_final_state_hadrons"})) {
129  // empty the hadron vector in the hadronization manager to circumvent the
130  // output of these hadrons if they are implemented in the SMASH afterburner
131  auto hadronization_mgr = JetScapeSignalManager::Instance()->GetHadronizationManagerPointer().lock();
132  hadronization_mgr->DeleteRealHadrons();
133  }
134 
135  afterburner_had_events[0].insert(afterburner_had_events[0].end(),
136  frag_hadrons.begin(), frag_hadrons.end());
137  dummy.clear();
138  }
139  return afterburner_had_events;
140 }
141 
142 } // end namespace Jetscape