Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FinalStatePartons.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FinalStatePartons.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 depends on the header.
62  std::string particleSeperator = " ";
63  if (!writeHeaderV2) {
64  particleSeperator = "\t";
65  }
66 
67  auto reader=make_shared<JetScapeReaderAscii>(argv[1]);
68  std::ofstream dist_output (argv[2]); //Format is SN, PID, E, Px, Py, Pz, Eta, Phi
69  int SN=0, TotalPartons=0;
70  while (!reader->Finished())
71  {
72  reader->Next();
73 
74  // cout<<"Analyze current event: "<<reader->GetCurrentEvent()<<endl;
75  auto mShowers=reader->GetPartonShowers();
76 
77  TotalPartons = 0;
78  for (int i=0; i < mShowers.size(); i++)
79  {
80  TotalPartons = TotalPartons + mShowers[i]->GetFinalPartons().size();
81  }
82 
83  if(TotalPartons > 0)
84  {
85  ++SN;
86  if (writeHeaderV2) {
87  // NOTE: Needs consistent "\t" between all entries to simplify parsing later.
88  dist_output << "#"
89  << "\t" << "Event\t" << SN
90  << "\t" << "weight\t" << reader->GetEventWeight()
91  << "\t" << "EPangle\t" << reader->GetEventPlaneAngle()
92  << "\t" << "N_partons\t" << TotalPartons
93  << "\t" << "|" // As a delimiter
94  << "\t" << "N"
95  << "\t" << "pid"
96  << "\t" << "status"
97  << "\t" << "E"
98  << "\t" << "Px"
99  << "\t" << "Py"
100  << "\t" << "Pz"
101  << "\n";
102  }
103  else {
104  dist_output << "#" << "\t"
105  << reader->GetEventPlaneAngle() << "\t"
106  << "Event"
107  << SN << "ID\t"
108  << TotalPartons << "\t"
109  << "pstat-EPx" << "\t"
110  << "Py" << "\t"
111  << "Pz" << "\t"
112  << "Eta" << "\t"<< "Phi" << "\n";
113  }
114 
115  for (int i=0; i < mShowers.size(); i++)
116  {
117  //cout<<" Analyze parton shower: "<<i<<endl;
118  // Let's create a file
119  for (int ipart = 0; ipart < mShowers[i]->GetFinalPartons().size(); ++ipart)
120  {
121  Parton p = *mShowers[i]->GetFinalPartons().at(ipart);
122  // if(abs(p.pid())!=5) continue;
123 
124  dist_output << ipart
125  << particleSeperator << p.pid()
126  << particleSeperator << p.pstat()
127  << particleSeperator << p.e()
128  << particleSeperator << p.px()
129  << particleSeperator << p.py()
130  << particleSeperator << p.pz();
131 
132  // v2 drops eta and phi, so only include it for v1
133  if (!writeHeaderV2) {
134  dist_output << particleSeperator << p.eta()
135  << particleSeperator << p.phi();
136  }
137 
138  // Finish up
139  dist_output << "\n";
140  }
141  }
142  }
143  }
144  // Write the final cross section and error if requested by using header v2
145  if (writeHeaderV2) {
146  // NOTE: Needs consistent "\t" between all entries to simplify parsing later.
147  dist_output << "#"
148  << "\t" << "sigmaGen\t" << reader->GetSigmaGen()
149  << "\t" << "sigmaErr\t" << reader->GetSigmaErr()
150  << "\n";
151  }
152  reader->Close();
153 }