-
Notifications
You must be signed in to change notification settings - Fork 0
/
myTreeMakerSimple.C~
221 lines (186 loc) · 7.37 KB
/
myTreeMakerSimple.C~
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "myTreeMaker.h"
using namespace std;
Double_t massID(Int_t id) {
switch(abs(id)) {
case 11: return 0.00051099907; //electron
case 2212: return 0.93827231; //proton
case 22: return 0.0; //gamma
case 13: return 0.105658389; //mu
case 15: return 1.7768; //tau
case 211: return 0.13956995; //charged pion
case 111: return 0.1345766; //pi0?
case 12: case 14: case 16: //neutrinos
return 0.0;
// case 221: return 0.54750; //eta
// case 213: return 0.0; //omega
// case 113: return 0.0;
// case 310: return 0.0;
// case 223: return 0.0;
}
//cout << "Undefined particle id, " << id << ", returning 0 mass\n";
return 0.0;
}
void bookHistograms() {
xsecOut = new TTree("xsec", "Cross Section information");
for(int i = 0; i < n; i++) {
if(sets[i]) {
treeOut[i] = new TTree("tree", "Event information");
treeOut[i]->Branch("npart", &npOut, "npart/I" );
treeOut[i]->Branch("tauSys", "TLorentzVector", &tauSys );
treeOut[i]->Branch("gammaSys", "TLorentzVector", &gammaSys );
treeOut[i]->Branch("tau", "TLorentzVector", &tau );
treeOut[i]->Branch("antitau", "TLorentzVector", &antitau );
treeOut[i]->Branch("gamma1", "TLorentzVector", &gamma1 );
treeOut[i]->Branch("gamma2", "TLorentzVector", &gamma2 );
treeOut[i]->Branch("proton1", "TLorentzVector", &proton1 );
treeOut[i]->Branch("proton2", "TLorentzVector", &proton2 );
treeOut[i]->Branch("parent1", parent1Out, "parent1[npart]/I" );
treeOut[i]->Branch("parent2", parent2Out, "parent2[npart]/I" );
treeOut[i]->Branch("status", statusOut, "status[npart]/I" );
treeOut[i]->Branch("pdg", partidOut, "pdg[npart]/I" );
treeOut[i]->Branch("px", px, "px[npart]/D" );
treeOut[i]->Branch("py", py, "py[npart]/D" );
treeOut[i]->Branch("pz", pz, "pz[npart]/D" );
}
}
}
void writeHistograms() {
xsecOut->Write();
for(int i = 0; i < n; i++) {if(sets[i]) treeOut[i]->Write();}
}
void myTreeMaker()
{
for(int i = 0; i < n; i++) sets[i] = 0;
sets[0] = 1; //all events
sets[1] = 0; //invariant mass > 110
sets[2] = 0; // " + pt of each lepton > 33
sets[3] = 0; // " + pt of each lepton > 38
sets[4] = 0; // " + pt of each lepton > 50
sets[5] = 0; //invariant mass > 400
sets[6] = 0; // " + pt of each lepton > 33
sets[7] = 0; // " + pt of each lepton > 38
sets[8] = 0; // " + pt of each lepton > 50
TFile *f1 = TFile::Open("events.root");
TFile *out = new TFile("events_full.root", "RECREATE","Event information from LPair event.root file");
bookHistograms();
TTree *t1 = (TTree*) f1->Get("h4444");
TTree *t2 = (TTree*) f1->Get("run");
Double_t sqrtS,xsec, errxsec;
//inputs read
Double_t pt[N],en[N],eta[N],phi[N],rapidity[N],charge[N];
Int_t partid[N], parent1[N], parent2[N], status[N];
t2->SetBranchAddress("sqrt_s",&sqrtS);
t2->SetBranchAddress("xsect",&xsec);
t2->SetBranchAddress("errxsect",&errxsec);
t1->SetBranchAddress("pt",&pt);
t1->SetBranchAddress("eta",&eta);
t1->SetBranchAddress("phi",&phi);
t1->SetBranchAddress("E",&en);
t1->SetBranchAddress("npart",&np);
t1->SetBranchAddress("pdg_id",&partid);
//t1->SetBranchAddress("m",&m);
t1->SetBranchAddress("status",&status);
t1->SetBranchAddress("parent1",&parent1);
t1->SetBranchAddress("parent2",&parent2);
TTree * t1Copy = t1;
Int_t nevts = t1->GetEntries();
if(nevts<1) { std::cout << "no event in the file\n"; return;}
if(t2->GetEntries() < 1) {
std::cout << "no cross section information\n";
} else {
t2->GetEntry(0);
xsecOut->Branch("xsec", &xsec, "xsec/D" );
xsecOut->Branch("errxsec", &errxsec, "errxsec/D");
xsecOut->Branch("nevts", &nevts, "nevts/I" );
xsecOut->Branch("sqrt_s", &sqrtS, "sqrt_s/D");
xsecOut->Fill();
}
TLorentzVector * part = new TLorentzVector(0.,0.,0.,0.);
for(Int_t i = 0;i < nevts;i++) { //
if(t1 != t1Copy) cout << "not equal tree\n";
t1->GetEntry(i);
if (i%50000==0) cout << i << ", Npart = " << np << endl;
npOut = np;
for(Int_t j = 0; j < np; j++) {
if(j >= npOut) {
cout << "broke out due to np change\n";
break;
}
//cout << "before pz fill, num part: " << np << endl;
pz[j] = (isinf(eta[j])) ? copysign(sqrt(en[j]*en[j] - massID(partid[j])*massID(partid[j])), eta[j]) : pt[j]*sinh(eta[j]);
px[j]=pt[j]*cos(phi[j]);
py[j]=pt[j]*sin(phi[j]);
parent1Out[j]=parent1[j];
parent2Out[j]=parent2[j];
statusOut[j]=status[j];
partidOut[j]=partid[j];
part = new TLorentzVector(px[j],py[j],pz[j],abs(en[j]));
if(partid[j] == 15 and ((parent1[j] == 3 and status[j] != 21) ||
(status[parent1[j]-1] == 21 and partid[parent1[j]-1] == 15))) *tau = *part;
else if(partid[j] == -15 and ((parent1[j] == 3 and status[j] != 21) ||
(status[parent1[j]-1] == 21 and partid[parent1[j]-1] == -15))) *antitau = *part;
else if(partid[j] == 22 and parent1[j] == 1 ) *gamma1 = *part;
else if(partid[j] == 22 and parent1[j] == 2) *gamma2 = *part;
else if(partid[j] == 2212 and parent1[j] == 1) *proton1 = *part;
else if(partid[j] == 2212 and parent1[j] == 2) *proton2 = *part;
cout << "before i%50000 fill\n";
if (i%50000==0) cout << "part " << j <<" lvector: " <<px[j] << " " << py[j] << " " << pz[j] << " " <<
en[j] << "\npart pt, eta, id, status, parent, mass: " << pt[j] << " " << eta[j] << " " <<
partid[j] << " " << status[j] << " " <<
parent1[j] << " " << part->M() << endl;
}
*tauSys = *tau+*antitau;
*gammaSys = *gamma1+*gamma2;
// for(int i = 1; i < n; i++) {
// if(sets[i]) {
// *tauSys[i]=*tauSys;
// *gammaSys[i]=*gammaSys[0];
// *tau[i]=*tau[0];
// *antitau[i]=*antitau[0];
// *gamma1[i]=*gamma[0];
// *gamma2[i]=*gamma2[0];
// *proton1[i]=*proton1[0];
// *proton2[i]=*proton2[0];
// partidOut[i]=partidOut[0];
// parent1Out[i]=parent1Out[0];
// parent2Out[i]=parent2Out[0];
// px[i]=px[0];
// py[i]=py[0];
// pz[i]=pz[0];
// np[i]=np[0];
// }
// }
cout << "before first fill\n";
treeOut[0]->Fill();
cout << "after first fill\n";
cout << tauSys->M() << endl;
// if(tauSys->M() > 110) {
// cout << "before second fill\n";
// if(sets[1]) treeOut[1]->Fill();
// cout << "after second fill\n";
// if(tauSys->M() > 400) {
// if(sets[5]) treeOut[5]->Fill();
// if(tau->Pt() > 33 and antitau->Pt() > 33) {
// if(sets[6]) treeOut[6]->Fill();
// if(tau->Pt() > 38 and antitau->Pt() > 38) {
// if(sets[7]) treeOut[7]->Fill();
// if(tau->Pt() > 50 and antitau->Pt() > 50) {
// if(sets[8]) treeOut[8]->Fill();
// }
// }
// }
// }
// if(tau->Pt() > 33 and antitau->Pt() > 33) {
// if(sets[2]) treeOut[2]->Fill();
// if(tau->Pt() > 38 and antitau->Pt() > 38) {
// if(sets[3]) treeOut[3]->Fill();
// if(tau->Pt() > 50 and antitau->Pt() > 50) {
// if(sets[4]) treeOut[4]->Fill();
// }
// }
// }
// }
}
writeHistograms();
//out.Close();
}