Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetScapeReader.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetScapeReader.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 "JetScapeReader.h"
17 #include <sstream>
18 
19 namespace Jetscape {
20 
21 template <class T> JetScapeReader<T>::JetScapeReader():
22  currentEvent{-1}
23  , sigmaGen{-1}
24  , sigmaErr{-1}
27 {
28  VERBOSE(8);
29 }
30 
31 template <class T> JetScapeReader<T>::~JetScapeReader() { VERBOSE(8); }
32 
33 template <class T> void JetScapeReader<T>::Clear() {
34  nodeVec.clear();
35  edgeVec.clear();
36  //pShower->clear();//pShower=nullptr; //check ...
37  pShowers.clear();
38  hadrons.clear();
39 
40  sigmaGen = -1;
41  sigmaErr = -1;
42  eventWeight = -1;
43  EventPlaneAngle = 0.0;
44 }
45 
46 template <class T> void JetScapeReader<T>::AddNode(string s) {
47  string token;
48  //int counter=0;
49  strT.set(s);
50 
51  vector<string> vS;
52 
53  while (!strT.done()) {
54  token = strT.next();
55  if (token.compare("V") != 0)
56  vS.push_back(token);
57  }
58 
59  nodeVec.push_back(pShower->new_vertex(
60  make_shared<Vertex>(stod(vS[1]), stod(vS[2]), stod(vS[3]), stod(vS[4]))));
61 }
62 
63 template <class T> void JetScapeReader<T>::AddEdge(string s) {
64  if (nodeVec.size() > 1) {
65  string token;
66  //int counter=0;
67  strT.set(s);
68 
69  vector<string> vS;
70 
71  while (!strT.done()) {
72  token = strT.next();
73  if (token.compare("P") != 0)
74  vS.push_back(token);
75  }
76 
77  pShower->new_parton(
78  nodeVec[stoi(vS[0])], nodeVec[stoi(vS[1])],
79  make_shared<Parton>(
80  stoi(vS[2]), stoi(vS[3]), stoi(vS[4]), stod(vS[5]), stod(vS[6]),
81  stod(vS[7]),
82  stod(
83  vS[8]))); // use different constructor wit true spatial posiiton ...
84  } else
85  JSWARN << "Node vector not filled, can not add edges/partons!";
86 }
87 
88 template <class T> void JetScapeReader<T>::AddHadron(string s) {
89  string token;
90  strT.set(s);
91 
92  vector<string> vS;
93  double x[4];
94  x[0] = x[1] = x[2] = x[3] = 0.0;
95  while (!strT.done()) {
96  token = strT.next();
97  if (token.compare("H") != 0)
98  vS.push_back(token);
99  }
100  hadrons.push_back(make_shared<Hadron>(stoi(vS[1]), stoi(vS[2]), stoi(vS[3]),
101  stod(vS[4]), stod(vS[5]), stod(vS[6]),
102  stod(vS[7]), x));
103 }
104 
105 template <class T> void JetScapeReader<T>::Next() {
106  if (currentEvent > 0)
107  Clear();
108 
109  //ReadEvent(currentPos);
110  string line;
111  string token;
112 
113  JSINFO << "Current Event = " << currentEvent;
114 
115  pShowers.push_back(make_shared<PartonShower>());
116  pShower = pShowers[0];
117  currentShower = 1;
118 
119  int nodeZeroCounter = 0;
120  std::string EPAngleStr = "EventPlaneAngle";
121  while (getline(inFile, line)) {
122  strT.set(line);
123 
124  if (strT.isCommentEntry()) {
125 
126  // Cross section
127  if (line.find("sigmaGen") != std::string::npos) {
128  std::stringstream data(line);
130  data >> dummy >> dummy >> sigmaGen;
131  JSDEBUG << " sigma gen=" << sigmaGen;
132  }
133  // Cross section error
134  if (line.find("sigmaErr") != std::string::npos) {
135  std::stringstream data(line);
137  data >> dummy >> dummy >> sigmaErr;
138  JSDEBUG << " sigma err=" << sigmaErr;
139  }
140  // Event weight
141  if (line.find("weight") != std::string::npos) {
142  std::stringstream data(line);
144  data >> dummy >> dummy >> eventWeight;
145  JSDEBUG << " Event weight=" << eventWeight;
146  }
147  // EP angle
148  if (line.find(EPAngleStr) != std::string::npos) {
149  std::stringstream data(line);
151  data >> dummy >> dummy >> EventPlaneAngle;
152  JSDEBUG << " EventPlaneAngle=" << EventPlaneAngle;
153  }
154  continue;
155  }
156 
157  if (strT.isEventEntry()) {
158  int newEvent = stoi(strT.next());
159  if (currentEvent != newEvent && currentEvent > -1) {
160  currentEvent++;
161  break;
162  }
163  currentEvent = newEvent;
164  continue;
165  }
166 
167  // not an event header -- done?
168  if (!strT.isGraphEntry())
169  continue;
170 
171  // node?
172  if (strT.isNodeEntry()) {
173  // catch starting node
174  if (strT.isNodeZero()) {
175  nodeZeroCounter++;
176  if (nodeZeroCounter > currentShower) {
177  nodeVec.clear();
178  edgeVec.clear();
179  pShowers.push_back(make_shared<PartonShower>());
180  pShower = pShowers.back();
181  currentShower++;
182  }
183  }
184  AddNode(line);
185  continue;
186  }
187 
188  // edge?
189  if (strT.isEdgeEntry()) {
190  AddEdge(line);
191  continue;
192  }
193 
194  // rest is list entry == hadron entry
195  // Some questionable nomenclature here - identifying all that begins with "[" as "GraphEntry"
196  // oh well
197  AddHadron(line);
198  }
199 
200  if (Finished())
201  currentEvent++;
202 }
203 
204 template <class T>
205 vector<fjcore::PseudoJet> JetScapeReader<T>::GetHadronsForFastJet() {
206  vector<fjcore::PseudoJet> forFJ;
207 
208  for (auto &h : hadrons) {
209  forFJ.push_back(h->GetPseudoJet());
210  }
211 
212  return forFJ;
213 }
214 
215 template <class T> void JetScapeReader<T>::Init() {
216  VERBOSE(8) << "Open Input File = " << file_name_in;
217  JSINFO << "Open Input File = " << file_name_in;
218 
219  inFile.open(file_name_in.c_str());
220 
221  if (!inFile.good()) {
222  JSWARN << "Corrupt input file!";
223  exit(-1);
224  } else
225  JSINFO << "File opened";
226 
227  currentEvent = 0;
228 }
229 
230 template class JetScapeReader<ifstream>;
231 
232 #ifdef USE_GZIP
233 template class JetScapeReader<igzstream>;
234 #endif
235 
236 } // end namespace Jetscape