Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
convert_sartre2eictree.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file convert_sartre2eictree.C
1 // Code takes a Sartre HepMC output and converts it to a MILOU ascii output, which is then built into an EICTree.
2 
3 // 4 final state particles
4 // Scattered electron (KS=2)
5 // Scattered proton (KS=1)
6 // Decay electron and positron (KS=1)
7 // JPsi (KS=1)
9 {
10  TString inputFile("18x275_DVMP_1M_ascii.out");
11  TString outputFile("18x275_DVMP_1M_ascii_converted.out");
12  std::ifstream file(inputFile);
13 
14 
15 
16  std::ofstream output(outputFile);
17  output << "MILOU\n============================================\nI, ievent, linesnum, weight, genprocess, radcorr, truex, trueQ2, truey, truet, treuphi, phibelgen, phibelres, phibelrec\n============================================\nI, K(I,1) K(I,2) K(I,3) K(I,4) K(I,5) P(I,1) P(I,2) P(I,3) P(I,4) P(I,5) V(I,1) V(I,2) V(I,3)\n============================================\n";
19  std::string file_contents;
20  int event_count = 0;
21  int particle_count = 0;
22  while (std::getline(file, str))
23  {
24  file_contents = str;
25  if(file_contents.size()==0)
26  continue;
27  if(file_contents.at(0)=='F')
28  {
29  // Search for the Q2
30  string tmp; // A string to store the word on each iteration.
31  stringstream str_strm(file_contents);
32  vector<string> words; // Create vector to hold our words
33 
34  int counter = 0;
35  while (str_strm >> tmp) {
36  if(counter==5)
37  {
38  if(tmp.find("e")<tmp.length())
39  tmp=tmp.replace(tmp.find("e"),1,"E");
40  break;
41  }
42  counter++;
43  }
44  output << get_arbitrary_event(event_count++,tmp);
45  particle_count = 0;
46  if(event_count%100==0)
47  {
48  cout << "Processing Event " << event_count << endl;
49  }
50  }
51  if(file_contents.at(0)=='P')
52  {
53  // Found a particle
54  // See if it is final state
55  int index_jpsi = file_contents.find(" 443 ");
56  int index_other = file_contents.find(" 1 0 0 ");
57  if(index_jpsi>0||index_other>0)
58  {
59  output << ++particle_count;
60  output << "\t";
61  if(particle_count==1)
62  {
63  output<< "2\t";
64  }
65  else
66  {
67  output << "1\t";
68  }
69  string tmp; // A string to store the word on each iteration.
70  stringstream str_strm(file_contents);
71  vector<string> words; // Create vector to hold our words
72 
73  int counter = 0;
74  while (str_strm >> tmp) {
75  if(counter==2)
76  {
77  output << tmp;
78  output <<"\t 0 \t 0 \t 0 \t";
79  }
80  if(counter>=3&&counter<=7)
81  {
82  if(tmp.find("e")<tmp.length())
83  tmp=tmp.replace(tmp.find("e"),1,"E");
84  output << tmp;
85  output << "\t";
86  }
87  counter++;
88  }
89 
90  output << "0 \t 0 \t 0\n";
91  }
92  }
93  if(particle_count==5)
94  {
95  output<<" =============== Event finished =============== \n";
96  particle_count=0;
97  }
98  }
99  output.close();
100  gSystem->Load("$OPT_SPHENIX/eic-smear_root-5.34.36/lib/libeicsmear.so");
101 
102  BuildTree(outputFile);
103 
104  return 0;
105 }
106 
108 {
110  stringstream ss;
111  ss << "0" << "\t" << x << " 5 1.00000000 0 0 7.56711757E-04 " << Q << " 0.373815268 0.177931070 0.00000000 2.9 2728496 110.619263 -0.310856074\n ============================================\n";
112  alpha = ss.str();
113  return alpha;
114 }