Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FinalStateHadrons.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FinalStateHadrons.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 <iostream>
17 #include <fstream>
18 #include <memory>
19 #include <chrono>
20 #include <thread>
21 
22 #include "gzstream.h"
23 #include "PartonShower.h"
24 #include "JetScapeLogger.h"
25 #include "JetScapeReader.h"
26 #include "JetScapeBanner.h"
27 #include "fjcore.hh"
28 
29 #include <GTL/dfs.h>
30 
31 using namespace std;
32 using namespace fjcore;
33 
34 using namespace Jetscape;
35 
36 // You could overload here and then simply use ofstream << p;
37 // ostream & operator<<(ostream & ostr, const fjcore::PseudoJet & jet);
38 
39 
40 // -------------------------------------
41 
42 int main(int argc, char** argv)
43 {
44 
45  // JetScapeLogger::Instance()->SetInfo(false);
46  JetScapeLogger::Instance()->SetDebug(false);
47  JetScapeLogger::Instance()->SetRemark(false);
48  // //SetVerboseLevel (9 a lot of additional debug output ...)
49  // //If you want to suppress it: use SetVerboseLevle(0) or max SetVerboseLevel(9) or 10
50  JetScapeLogger::Instance()->SetVerboseLevel(0);
51 
52  // Whether to write the new header (ie. v2), including xsec info.
53  // To enable, pass anything as the third argument to enable this option.
54  // Default: disabled.
55  bool writeHeaderV2 = false;
56  if (argc > 3) {
57  writeHeaderV2 = static_cast<bool>(argv[3]);
58  std::cout << "NOTE: Writing header v2, and final cross section and error at EOF.\n";
59  }
60 
61  // The seperator between particles _does not_ depend on the header for final state hadrons
62  std::string particleSeperator = " ";
63 
64  auto reader = make_shared<JetScapeReaderAscii>(argv[1]);
65  std::ofstream dist_output (argv[2]); //Format is SN, PID, E, Px, Py, Pz, Eta, Phi
66  vector<shared_ptr<Hadron>> hadrons;
67  int SN=0;
68  while (!reader->Finished())
69  {
70  reader->Next();
71 
72  // cout<<"Analyze current event: "<<reader->GetCurrentEvent()<<endl;
73 
74  //dist_output<<"Event "<< reader->GetCurrentEvent()+1<<endl;
75  hadrons = reader->GetHadrons();
76  cout<<"Number of hadrons is: " << hadrons.size() << endl;
77 
78  if (hadrons.size() > 0)
79  {
80  ++SN;
81  if (writeHeaderV2) {
82  // NOTE: Needs consistent "\t" between all entries to simplify parsing later.
83  dist_output << "#"
84  << "\t" << "Event\t" << SN
85  << "\t" << "weight\t" << reader->GetEventWeight()
86  << "\t" << "EPangle\t" << reader->GetEventPlaneAngle()
87  << "\t" << "N_hadrons\t" << hadrons.size()
88  << "\t" << "|" // As a delimiter
89  << "\t" << "N"
90  << "\t" << "pid"
91  << "\t" << "status"
92  << "\t" << "E"
93  << "\t" << "Px"
94  << "\t" << "Py"
95  << "\t" << "Pz"
96  << "\n";
97  }
98  else {
99  dist_output << "#" << "\t"
100  << reader->GetEventPlaneAngle() << "\t"
101  << "Event"
102  << SN << "ID\t"
103  << hadrons.size() << "\t"
104  << "pstat-EPx" << "\t"
105  << "Py" << "\t"
106  << "Pz" << "\t"
107  << "Eta" << "\t"<< "Phi" << "\n";
108  }
109 
110  for (unsigned int i=0; i<hadrons.size(); i++)
111  {
112  dist_output << i
113  << particleSeperator << hadrons[i].get()->pid()
114  << particleSeperator << hadrons[i].get()->pstat()
115  << particleSeperator << hadrons[i].get()->e()
116  << particleSeperator << hadrons[i].get()->px()
117  << particleSeperator << hadrons[i].get()->py()
118  << particleSeperator << hadrons[i].get()->pz();
119 
120  // v2 drops eta and phi, so only include it for v1
121  if (!writeHeaderV2) {
122  dist_output << particleSeperator << hadrons[i].get()->eta()
123  << particleSeperator << hadrons[i].get()->phi();
124  }
125 
126  // Finish up
127  dist_output << "\n";
128  }
129  }
130  }
131  // Write the final cross section and error if requested by using header v2
132  if (writeHeaderV2) {
133  // NOTE: Needs consistent "\t" between all entries to simplify parsing later.
134  dist_output << "#"
135  << "\t" << "sigmaGen\t" << reader->GetSigmaGen()
136  << "\t" << "sigmaErr\t" << reader->GetSigmaErr()
137  << "\n";
138  }
139  reader->Close();
140 }