-
Notifications
You must be signed in to change notification settings - Fork 1
/
TopStudy.cc
276 lines (251 loc) · 10.1 KB
/
TopStudy.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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#include <vector>
#include <iostream>
#include <TString.h>
#include <TFile.h>
#include <TH1.h>
#include <TH2.h>
#include <TSystemDirectory.h>
#include <TClonesArray.h>
#include <TLorentzVector.h>
#include <TList.h>
#include "untuplizer.h"
#include <fstream>
#include <map>
#include <TFile.h>
bool TriggerStatus(string* trigName, vector<bool> &hlt_trigResult, Int_t nsize, string TRIGNAME){
bool triggerstate=false;
for(size_t i=0; i<nsize;i++){
std::string thisTrig= trigName[i];
size_t found = thisTrig.find(TRIGNAME);
if(found==string::npos)continue;
triggerstate= hlt_trigResult[i];
}
return triggerstate;
}
bool is2Jets(int index, int d1, int d2){
bool flag = false;
if(abs(d1) <=6 && abs(d1)!=0) flag = true;
if(flag){
if(abs(d2) <=6 && abs(d2)!=0) return true;
}
return false;
}
bool is1lep1nu(int index, int d1, int d2){
bool flag = false;
if(abs(d1) == 11 || abs(d1) == 13 || abs(d1) ==15) flag = true;
if(flag){
if(abs(d2) == 12 || abs(d2) == 14 || abs(d2) ==16) return true;
}
return false;
}
bool is1Nu1Lep(int index, int d1, int d2){
bool flag = false;
if(abs(d2) == 11 || abs(d2) == 13 || abs(d2) ==15) flag = true;
if(flag){
if(abs(d1) == 12 || abs(d1) == 14 || abs(d1) ==16) return true;
}
return false;
}
void TopStudy(string inputFile){
TString outputFile;
std::vector<string> infiles;
if(inputFile.find(".root")!= std::string::npos)
{
TString endfix=gSystem->GetFromPipe(Form("file=%s; test=${file##*/}; echo \"${test%%.root*}\"",inputFile.data()));
outputFile = Form("ttbar_%s.root",endfix.Data());
cout << "Output file_ = " << outputFile << endl;
}
else{
TString endfix=gSystem->GetFromPipe(Form("file=%s; test=${file##*/}; echo \"${test%%.root*}\"",inputFile.data()));
outputFile = Form("ttbar_%s.root",endfix.Data());
cout << "Output file = " << outputFile.Data() << endl;
TSystemDirectory *base = new TSystemDirectory("root","root");
base->SetDirectory(inputFile.data());
TList *listOfFiles = base->GetListOfFiles();
TIter fileIt(listOfFiles);
TFile *fileH = new TFile();
Long64_t nfiles=0;
while(fileH = (TFile*)fileIt()) {
std::string fileN = fileH->GetName();
std::string baseString = "NCUGlobal";
if(fileN.find("fail") != std::string::npos)continue;
if(fileH->IsFolder()){
std::string newDir=inputFile+fileN;
base->SetDirectory(newDir.data());
TList *listOfFiles2 = base->GetListOfFiles();
TIter fileIt2(listOfFiles2);
TFile *fileH2 = new TFile();
while(fileH2 = (TFile*)fileIt2()) {
std::string fileN2 = fileH2->GetName();
if(fileH2->IsFolder())continue;
if(fileN2.find("fail") != std::string::npos)continue;
if(fileN2.find(baseString) == std::string::npos)continue;
infiles.push_back(Form("%s/%s",newDir.data(),fileN2.data()));
nfiles++;
}
}
}
cout << "Opened " << nfiles << " files" << endl;
}
TreeReader data(infiles);
TH2F* h_2D_dR1 = new TH2F("h_dR1","dR(lep,b) comes from the same top VS Top Pt",100,0,5,100,0,1000);
TH2F* h_2D_dR2 = new TH2F("h_dR2","dR(lep,b) comes from the other top VS Top Pt",100,0,5,100,0,1000);
for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){
if (jEntry % 50000 == 0)
fprintf(stderr, "Processing event %lli of %lli\n", jEntry + 1, data.GetEntriesFast());
data.GetEntry(jEntry);
TClonesArray* FatJetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
Int_t nJet = data.GetInt("FATnJet");
Float_t pfMetRawPt = data.GetFloat("pfMetRawPt");
Float_t pfMetRawPhi = data.GetFloat("pfMetRawPhi");
Float_t *FATjetCISVV2 = data.GetPtrFloat("FATjetCISVV2");
// Int_t *hlt_trigResult = data.GetPtrInt("hlt_trigResult");
vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
std::string* trigName = data.GetPtrString("hlt_trigName");
const Int_t nsize = data.GetPtrStringSize();
float NmaxPt = -9999.0, NsecondPt = -9999.0;
int maxJetIndex = -1;
TLorentzVector maxPt, secondPt;
/********* BJet Selction *************/
for(int ij=0; ij< nJet; ij++){
TLorentzVector* thisJet = (TLorentzVector*)FatJetP4->At(ij);
if(thisJet->Pt() < 200)continue;
if(fabs(thisJet->Eta()) > 2.5)continue;
if(FATjetCISVV2[ij] < 0.605)continue;
if(thisJet->Pt() > NmaxPt){
NmaxPt = thisJet->Pt();
maxPt = *thisJet;
maxJetIndex = ij;
}//leading Jet
if(thisJet->Pt() > NsecondPt){
if(ij == maxJetIndex) continue;
NsecondPt = thisJet->Pt();
secondPt = *thisJet;
}//second Jet
}//AK8PFJets loop
/******* PreSelection **********/
if((maxPt + secondPt).M()>150 || (maxPt + secondPt).M()< 100)continue;
if(pfMetRawPt < 200) continue;
if(fabs(maxPt.Phi()- pfMetRawPhi)<2.5)continue;
if(fabs(secondPt.Phi()- pfMetRawPhi )<2.5)continue;
if(!TriggerStatus(trigName,trigResult,nsize,"HLT_PFMET170_NoiseCleaned_v1") ||
!TriggerStatus(trigName,trigResult,nsize,"HLT_PFMET120_PFMHT120_IDLoose_v1")) continue;
TClonesArray* genParP4 = (TClonesArray*) data.GetPtrTObject("genParP4");
Int_t nGenPar = data.GetInt("nGenPar");
Int_t* genParId = data.GetPtrInt("genParId");
Int_t* genParSt = data.GetPtrInt("genParSt");
Int_t* genMomParId = data.GetPtrInt("genMomParId");
Int_t* genDa1 = data.GetPtrInt("genDa1");
Int_t* genDa2 = data.GetPtrInt("genDa2");
Int_t* genMo1 = data.GetPtrInt("genMo1");
Int_t* genMo2 = data.GetPtrInt("genMo2");
int lep1Index=-1,lep2Index=-1;
int bqaurk_index=-1,abquark_index=-1;
int Pass=0;
int nW_lep=0, nW_had=0;
TLorentzVector ele, antiEle, bjet;
std::vector<int> goodLep, goodbquark, goodtop;
std::vector<int> goodantiLep, goodantib, goodantitop;
/********** Gen Level Info **********/
for(int ig=0; ig < nGenPar; ig++){
// if(genParSt[ig]!=1)continue;
if(abs(genParId[ig]) == 24){
if(abs(genMomParId[ig])!=6)continue;
int da1 = genParId[genDa1[ig]];
int da2 = genParId[genDa2[ig]];
if(is2Jets(ig,da1,da2)){
nW_had++;
}
if(is1lep1nu(ig,da1,da2) || is1Nu1Lep(ig,da1,da2)){
nW_lep++;
}
}
}//select semi loop
/******* semi-leptonic selection *******/
if(nW_had!=1 && nW_lep!=1)continue;
for(int ig=0; ig < nGenPar; ig++){
//for lepton
if(abs(genMomParId[ig])==6 && abs(genParId[ig])==24){
if(genParId[genDa1[ig]]==-11 || genParId[genDa1[ig]]==-13 || genParId[genDa1[ig]]==-15){
goodLep.push_back(genDa1[ig]);
}else if (genParId[genDa2[ig]]==-11 || genParId[genDa2[ig]]==-13 || genParId[genDa2[ig]]==-15){
goodLep.push_back(genDa2[ig]);
}
if(genParId[genDa1[ig]]==11 || genParId[genDa1[ig]]==13 || genParId[genDa1[ig]]==15){
goodantiLep.push_back(genDa1[ig]);
}else if (genParId[genDa2[ig]]==11 || genParId[genDa2[ig]]==13 || genParId[genDa2[ig]]==15){
goodantiLep.push_back(genDa2[ig]);
}
}
// for bjet
if(abs(genParId[ig])==5){
if(genMomParId[ig]==6)goodbquark.push_back(ig);
if(genMomParId[ig]==-6)goodantib.push_back(ig);
}
// for top quark
if(genParId[ig]==6)goodtop.push_back(ig);
if(genParId[ig]==-6)goodantitop.push_back(ig);
/********** Plot **************/
//plot for coming from Same top
for(unsigned int i=0; i< goodLep.size(); i++){
int il = goodLep[i];
TLorentzVector* thisEle = (TLorentzVector*)genParP4->At(il);
for(unsigned int j=0; j < goodbquark.size(); j++){
int jb = goodbquark [j];
TLorentzVector* thisb = (TLorentzVector*)genParP4->At(jb);
for(unsigned int k=0; k < goodtop.size(); k++){
int kt = goodtop[k];
TLorentzVector* thistop = (TLorentzVector*)genParP4->At(kt);
h_2D_dR1->Fill(thisEle->DeltaR(*thisb),thistop->Pt());
}
}
}
// plot for coming from Same antitop
for(unsigned int i=0; i< goodantiLep.size(); i++){
int il = goodantiLep[i];
TLorentzVector* thisEle = (TLorentzVector*)genParP4->At(il);
for(unsigned int j=0; j < goodantib.size(); j++){
int jb = goodantib [j];
TLorentzVector* thisb = (TLorentzVector*)genParP4->At(jb);
for(unsigned int k=0; k < goodantitop.size(); k++){
int kt = goodantitop[k];
TLorentzVector* thistop = (TLorentzVector*)genParP4->At(kt);
h_2D_dR1->Fill(thisEle->DeltaR(*thisb),thistop->Pt());
}
}
}
// plot for coming from Diff top
for(unsigned int i=0; i< goodLep.size(); i++){
int il = goodLep[i];
TLorentzVector* thisEle = (TLorentzVector*)genParP4->At(il);
for(unsigned int j=0; j < goodantib.size(); j++){
int jb = goodantib [j];
TLorentzVector* thisb = (TLorentzVector*)genParP4->At(jb);
for(unsigned int k=0; k < goodtop.size(); k++){
int kt = goodtop[k];
TLorentzVector* thistop = (TLorentzVector*)genParP4->At(kt);
h_2D_dR2->Fill(thisEle->DeltaR(*thisb),thistop->Pt());
}
}
}
// plot for coming from Diff antitop
for(unsigned int i=0; i< goodantiLep.size(); i++){
int il = goodantiLep[i];
TLorentzVector* thisEle = (TLorentzVector*)genParP4->At(il);
for(unsigned int j=0; j < goodbquark.size(); j++){
int jb = goodbquark [j];
TLorentzVector* thisb = (TLorentzVector*)genParP4->At(jb);
for(unsigned int k=0; k < goodtop.size(); k++){
int kt = goodtop[k];
TLorentzVector* thistop = (TLorentzVector*)genParP4->At(kt);
h_2D_dR2->Fill(thisEle->DeltaR(*thisb),thistop->Pt());
}
}
}
}//Gen Loop
}//Entries loop
TFile* outFile = new TFile(outputFile.Data(),"recreate");
h_2D_dR1->Write();
h_2D_dR2->Write();
outFile->Close();
}