forked from ssevova/hps-lhe-parsers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlhetree_Ap.cc
163 lines (136 loc) · 3.77 KB
/
lhetree_Ap.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <assert.h>
#include "TFile.h"
#include "TTree.h"
#include "TLorentzVector.h"
using namespace std;
class LHEevent {
public:
LHEevent() { };
~LHEevent() { };
int pdgEl;
int pdgEp, pdgEm;
TLorentzVector vEl; //beam e-
TLorentzVector vEp, vEm;// outgoing e-,e+
unsigned npart;
double weight;
double scale;
double xsec;
double nevts;
double nele;
};
bool rewind(std::istringstream *iss, std::string line) {
(*iss).clear();
(*iss).str(line);
(*iss).seekg(0,ios::beg);
return true;
}
int main( int argc, char** argv ) {
std::cout << "start" << std::endl;
ifstream ifs(argv[1]);
int pdgid;
int status,mo1,mo2,dau1,dau2;
double px, py, pz, e, m;
double d1,d2;
unsigned npart;
int dunno1;
double weight, dunno2, dunno3, dunno4;
TFile * f = new TFile(argv[2], "RECREATE");
TTree * t = new TTree( "t","t");
LHEevent myevent;
myevent.xsec = strtod(argv[3], NULL);
myevent.nevts = strtod(argv[4], NULL);
t->Branch( "xsec", &(myevent.xsec) );
t->Branch( "nevts", &(myevent.nevts) );
t->Branch( "npart", &(myevent.npart) );
t->Branch( "weight", &(myevent.weight) );
t->Branch( "scale", &(myevent.scale) );
t->Branch( "nele", &(myevent.nele) );
t->Branch( "pdgEl", &(myevent.pdgEl) );
t->Branch( "vEl", &(myevent.vEl) );
t->Branch( "pdgEp", &(myevent.pdgEp) );
t->Branch( "vEp", &(myevent.vEp) );
t->Branch( "pdgEm", &(myevent.pdgEm) );
t->Branch( "vEm", &(myevent.vEm) );
int fill_count=0;
int line_count=0;
int ele_count=0;
string line;
while( !ifs.eof() ) {
std::getline(ifs,line);
std::istringstream iss;
if( rewind(&iss,line) && (iss >> pdgid >> status >> mo1 >> mo2 >> dau1 >> dau2
>> px >> py >> pz >> e >> m >> d1 >> d2)
) {
#ifdef DEBUG
cout << "index: " << line_count << "\tpdgid: " << pdgid << "\tstatus: " << status
<< "\tmo1: " << mo1 << "\tmo2: " << mo2
<< "\tpx: " << px << "\tpy: " << py
<< "\te: " << e << "\td1: " << d1 << "\tlc: " << line_count << endl;
cout.flush();
#endif
line_count++;
if ( pdgid == 11 && status==1){ //find beam e-
myevent.vEl.SetPxPyPzE(px,py,pz,e);
myevent.pdgEl = pdgid;
ele_count++;
#ifdef DEBUG
cout << "found beam e pdg: " << myevent.pdgEl << "\tpx: " << myevent.vEl.Px() << endl;
#endif
} else if ( pdgid == 611 && status==1){ //find outgoing e- (from A')
myevent.vEm.SetPxPyPzE(px,py,pz,e);
myevent.pdgEm = pdgid;
ele_count++;
#ifdef DEBUG
cout << "found e- pdg: " << myevent.pdgEm << "\tpx: " << myevent.vEm.Px() << endl;
#endif
} else if ( pdgid == -611 && status==1){ //find outgoing e+ (from A')
myevent.vEp.SetPxPyPzE(px,py,pz,e);
myevent.pdgEp = pdgid;
ele_count++;
#ifdef DEBUG
cout << "found e+ pdg: " << myevent.pdgEp << "\tpx: " << myevent.vEp.Px() << endl;
#endif
}
} else if( rewind(&iss,line) && (iss >> npart >> dunno1 >> weight >> dunno2 >> dunno3 >> dunno4)
){
#ifdef DEBUG
cout << "weight: " << weight << "\tnpart: " << npart << endl;
#endif
myevent.npart = npart;
myevent.weight = weight;
myevent.scale = dunno2;
} else {
#ifdef DEBUG
cout << "------------------------------" << endl;
#endif
npart=0;
}
if( !npart ){
#ifdef DEBUG
cout << "!npart" << endl;
#endif
myevent.nele = ele_count;
if( myevent.nele ){
t->Fill();
fill_count++;
#ifdef DEBUG
cout << "filled ..." << fill_count
<< endl;
#endif
}
line_count=0;
myevent.vEm.SetPxPyPzE(0.,0.,0.,0.);
myevent.vEp.SetPxPyPzE(0.,0.,0.,0.);
myevent.vEl.SetPxPyPzE(0.,0.,0.,0.);
ele_count=0;
}
npart--;
}
cout << "fill_count: " << fill_count << endl;
t->Write();
f->Close();
}