Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HadronizationManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HadronizationManager.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 
16 #include "HadronizationManager.h"
17 #include "JetScapeLogger.h"
18 #include "JetScapeSignalManager.h"
19 #include <string>
20 #include "Hadronization.h"
21 
22 #include <iostream>
23 #include <vector>
24 
25 #include <thread>
26 #include <future>
27 
28 using namespace std;
29 
30 namespace Jetscape {
31 
32 HadronizationManager::HadronizationManager() {
33  SetId("HadronizationManager");
34  GetFinalPartonListConnected = false;
35  GetHadronListConnected = false;
36  VERBOSE(8);
37 }
38 
39 HadronizationManager::~HadronizationManager() {
40  Clear();
41 
42  // The tasks are hadronization modules
43  if (GetNumberOfTasks() > 0)
44  EraseTaskLast();
45 }
46 
48  JSDEBUG << "Hadronization task List ...";
49 
50  hd.clear();
51 
52  int n = GetNumberOfTasks();
53  for (int i = 1; i < n; i++)
54  EraseTaskLast();
55 
56  JetScapeSignalManager::Instance()->CleanUp();
57  JetScapeTask::ClearTasks();
58  VERBOSE(8) << hd.size();
59 }
60 
62  JSINFO << "Initialize Hadronization Manager ...";
63 
64  if (GetNumberOfTasks() < 1) {
65  JSWARN << " : No valid Hadronization Manager modules found ...";
66  exit(-1);
67  }
68 
69  JSINFO << "Found " << GetNumberOfTasks()
70  << " Hadronization Manager Tasks/Modules Initialize them ... ";
71  JetScapeTask::InitTasks();
72 
73  JSINFO << "Connect HadronizationManager Signal to Energy Loss ...";
74  JetScapeSignalManager::Instance()->ConnectGetFinalPartonListSignal(
75  shared_from_this());
76 }
77 
78 void HadronizationManager::WriteTask(weak_ptr<JetScapeWriter> w) {
79  VERBOSE(8);
80  JetScapeTask::WriteTasks(w);
81 }
82 
83 void HadronizationManager::Exec() {
84 
85  VERBOSE(2) << "Run Hadronization Manager ...";
86  JSDEBUG << "Task Id = " << this_thread::get_id();
87 
88  if (GetNumberOfTasks() < 1) {
89  JSWARN << " : No valid Hadronization modules found ...";
90  exit(-1);
91  }
92 
93  CreateSignalSlots();
94 
95  if (GetGetFinalPartonListConnected()) {
96  GetFinalPartonList(hd);
97  hadrons.clear();
98  GetHadronList(hadrons);
99  VERBOSE(2) << " There are " << hd.size()
100  << " partons ready for hadronization";
101  VERBOSE(2) << " There are already " << hadrons.size() << " hadrons";
102 
103  for (auto it : GetTaskList()) {
104  dynamic_pointer_cast<Hadronization>(it)->AddInPartons(hd);
105  dynamic_pointer_cast<Hadronization>(it)->AddInHadrons(hadrons);
106  }
107  JetScapeTask::ExecuteTasks();
108  } else {
109  VERBOSE(2) << " There are no partons ready for recombination";
110  }
111 }
112 
113 void HadronizationManager::CreateSignalSlots() {
114  for (auto it : GetTaskList()) {
115  for (auto it2 : it->GetTaskList()) {
116  if (!dynamic_pointer_cast<Hadronization>(it2)
117  ->GetTransformPartonsConnected()) {
118  JetScapeSignalManager::Instance()->ConnectTransformPartonsSignal(
119  dynamic_pointer_cast<Hadronization>(it),
120  dynamic_pointer_cast<Hadronization>(it2));
121  }
122  if (!dynamic_pointer_cast<Hadronization>(it2)
123  ->GetGetHydroHyperSurfaceConnected()) {
124  JetScapeSignalManager::Instance()->ConnectGetHydroHyperSurfaceSignal(
125  dynamic_pointer_cast<Hadronization>(it2));
126  }
127  if (!dynamic_pointer_cast<Hadronization>(it2)
128  ->GetGetHydroCellSignalConnected()) {
129  JetScapeSignalManager::Instance()->ConnectGetHydroCellSignal(
130  dynamic_pointer_cast<Hadronization>(it2));
131  }
132  }
133  }
134 
135  JetScapeSignalManager::Instance()->PrintTransformPartonsSignalMap();
136 }
137 
138 void HadronizationManager::GetHadrons(vector<shared_ptr<Hadron>>& signal){
139  //signal = outHadrons;
140  signal.clear();
141  // foreach hadronizon object tasks
142  for(shared_ptr<JetScapeTask> it : GetTaskList()){
143  vector<shared_ptr<Hadron>> tempHadronList;
144  JetScapeTask *jet = it.get();
145  Hadronization *hit = (Hadronization *) jet;
146  tempHadronList = hit->GetHadrons();
147  for(auto hadron : tempHadronList){
148  signal.push_back(hadron);
149  }
150  }
151 }
152 
153 void HadronizationManager::DeleteHadrons() {
154  // foreach hadronizon object tasks
155  for(shared_ptr<JetScapeTask> it : GetTaskList()){
156  JetScapeTask *jet = it.get();
157  Hadronization *hit = (Hadronization *) jet;
158  hit->DeleteHadrons();
159  }
160 }
161 
162 void HadronizationManager::DeleteRealHadrons() {
163  // foreach hadronizon object tasks
164  for(shared_ptr<JetScapeTask> it : GetTaskList()){
165  JetScapeTask *jet = it.get();
166  Hadronization *hit = (Hadronization *) jet;
167  hit->DeleteRealHadrons();
168  }
169 }
170 
171 } // namespace Jetscape