Changeset 20 in huonglan
- Timestamp:
- Aug 30, 2011, 10:26:47 AM (13 years ago)
- Location:
- SPLOT/NEWREALEASE/MERGEFILES
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
SPLOT/NEWREALEASE/MERGEFILES/MakeFakeData.C
r14 r20 1 #include "WJetSF_EPS_ttbar_withLF.h" 2 1 3 void MakeFakeData(TString TheTreeName = "T") { 2 4 TChain *tdn = new TChain(TheTreeName); … … 14 16 //Top PoPy : 105861 15 17 //Top PoJi : 105860 16 TString ver = "v3";17 18 TString s1 = "/data/atlas/huonglan/FROMLYON/MC/VER3/res"; 18 19 TString s2[78] = {"115423","105200", … … 38 39 39 40 TString s3 = "v3.root"; 41 TString ver = "NEW"; 40 42 41 43 //set the name of 78 files … … 75 77 1, 1, 1, 1, 1, 1, 1, 1}; 76 78 77 if (s2[1]=="105200"){78 TFile *fData = new TFile("res_FakeDataTopMCAtNLO"+ver+"N.root","RECREATE");79 }80 if (s2[1]=="105861"){81 TFile *fData = new TFile("res_FakeDataTopPoPy"+ver+"N.root","RECREATE");82 }83 if (s2[1]=="105860"){84 TFile *fData = new TFile("res_FakeDataTopPoJi"+ver+"N.root","RECREATE");85 }86 87 79 88 80 //compute the weights corresponding 89 //sum all the njets histos90 double njet[29][78], njetE[29][78], njetM[29][78];91 92 for (int i = 0; i < 29; i++){93 for (int j = 0; j < 78; j++){94 njet[i][j] = 0;95 njetE[i][j] = 0;96 njetM[i][j] = 0;97 }98 }99 100 81 float Wei[78]; 101 82 for (int i = 0; i < 78; i++){ … … 116 97 } 117 98 Wei[i] = cx[i]*1035*effFilt[i]/nevtIn; 118 119 TH1F *nj = (TH1F*)f->Get("njetsB");120 TH1F *njE = (TH1F*)f->Get("njetsBE");121 TH1F *njM = (TH1F*)f->Get("njetsBM");122 for (int ib = 1; ib < 30; ib++){123 double bb = nj->GetBinContent(ib);124 double bbE = njE->GetBinContent(ib);125 double bbM = njM->GetBinContent(ib);126 127 njet[ib-1][i] += bb*Wei[i];128 njetE[ib-1][i] += bbE*Wei[i];129 njetM[ib-1][i] += bbM*Wei[i];130 }131 }132 133 double nS[29][6];134 double nSE[29][6];135 double nSM[29][6];136 for (int i = 0; i < 29; i++){137 for (int j = 0; j < 6; j++){138 nS[i][j] = 0;139 nSE[i][j] = 0;140 nSM[i][j] = 0;141 }142 }143 144 for (int j = 0; j < 78; j++){145 if (j==33) continue;146 for (int i = 0; i < 29; i++){147 int k = -1;148 if (j == 0) k = 0;149 if (j == 1) k = 1;150 if (j>=2 && i<=32) k = 2;151 if (j>=33 && i<=39) k = 3;152 if (j>=40 && i<=69) k = 4;153 if (j>=70 && i<=77) k = 5;154 155 nS[i][k] += njet[i][j];156 nSE[i][k] += njetE[i][j];157 nSM[i][k] += njetM[i][j];158 }159 }160 161 TString chan[3] = {"", "E", "M"};162 TH1F *hnjetSig[3];163 TH1F *hnjetTopP[3];164 TH1F *hnjetAllW[3];165 TH1F *hnjetSingT[3];166 TH1F *hnjetAllZ[3];167 TH1F *hnjetQCD[3];168 169 for (int i = 0; i < 3; i++){170 TString hname = "hnjetSig";171 hname += chan[i];172 hnjetSig[i] = new TH1F(hname, "", 29, 1, 31);173 174 hname = "hnjetTopP";175 hname += chan[i];176 hnjetTopP[i] = new TH1F(hname, "", 29, 1, 31);177 178 hname = "hnjetAllW";179 hname += chan[i];180 hnjetAllW[i] = new TH1F(hname, "", 29, 1, 31);181 182 hname = "hnjetSingT";183 hname += chan[i];184 hnjetSingT[i] = new TH1F(hname, "", 29, 1, 31);185 186 hname = "hnjetAllZ";187 hname += chan[i];188 hnjetAllZ[i] = new TH1F(hname, "", 29, 1, 31);189 190 hname = "hnjetQCD";191 hname += chan[i];192 hnjetQCD[i] = new TH1F(hname, "", 29, 1, 31);193 }194 195 196 for (int i = 0; i < 29; i++){197 hnjetSig[0]->SetBinContent(i+1, nS[i][0]);198 hnjetTopP[0]->SetBinContent(i+1, nS[i][1]);199 hnjetAllW[0]->SetBinContent(i+1, nS[i][2]);200 hnjetSingT[0]->SetBinContent(i+1,nS[i][3]);201 hnjetAllZ[0]->SetBinContent(i+1, nS[i][4]);202 hnjetQCD[0]->SetBinContent(i+1, nS[i][5]);203 204 hnjetSig[1]->SetBinContent(i+1, nSE[i][0]);205 hnjetTopP[1]->SetBinContent(i+1, nSE[i][1]);206 hnjetAllW[1]->SetBinContent(i+1, nSE[i][2]);207 hnjetSingT[1]->SetBinContent(i+1,nSE[i][3]);208 hnjetAllZ[1]->SetBinContent(i+1, nSE[i][4]);209 hnjetQCD[1]->SetBinContent(i+1, nSE[i][5]);210 211 hnjetSig[2]->SetBinContent(i+1, nSM[i][0]);212 hnjetTopP[2]->SetBinContent(i+1, nSM[i][1]);213 hnjetAllW[2]->SetBinContent(i+1, nSM[i][2]);214 hnjetSingT[2]->SetBinContent(i+1,nSM[i][3]);215 hnjetAllZ[2]->SetBinContent(i+1, nSM[i][4]);216 hnjetQCD[2]->SetBinContent(i+1, nSM[i][5]);217 99 } 218 100 … … 259 141 260 142 //################################### 261 //********** File Data *************262 //###################################263 264 //MC@NLO : 105200265 //Top PoPy : 105861266 //Top PoJi : 105860267 268 if (s2[1]=="105200"){269 TFile *fData = new TFile("res_FakeDataTopMCAtNLO"+ver+"N.root","RECREATE");270 }271 if (s2[1]=="105861"){272 TFile *fData = new TFile("res_FakeDataTopPoPy"+ver+"N.root","RECREATE");273 }274 if (s2[1]=="105860"){275 TFile *fData = new TFile("res_FakeDataTopPoJi"+ver+"N.root","RECREATE");276 }277 278 TTree *tWeiD = new TTree("Tw","Tw");279 double b_weiD = -100;280 tWeiD->Branch("wei", &b_weiD, "wei/D");281 TTree *tD = tData->CloneTree(0);282 tD->SetName("T");283 tD->SetAutoSave();284 gROOT->cd();285 286 int countD = 0;287 for (int ifi = 0; ifi < tData->GetEntries(); ifi++){288 countD++;289 tData->GetEntry(ifi);290 if (ifi%1000==0) cout << "Reading event " << ifi << " from FakeData tree" << endl;291 292 TString currentFile = tData->GetTree()->GetCurrentFile()->GetName();293 294 for (int i = 0; i < 78; i++){295 if (fname[i]==currentFile)296 b_weiD = Wei[i];297 }298 299 tD->Fill();300 tWeiD->Fill();301 }302 303 fData->cd();304 tD->Write("",TObject::kOverwrite);305 tWeiD->Write();306 fData->Close();307 308 //###################################309 143 //********** File Signal *********** 310 144 //################################### 311 145 312 TFile *fSig = new TFile("res_Signal"+ver+"N.root","RECREATE"); 313 TTree *tWeiS = new TTree("Tw","Tw"); 314 double b_weiS = -100; 315 tWeiS->Branch("wei", &b_weiS, "wei/D"); 316 TTree *tS = tSig->CloneTree(0); 317 tS->SetName("T"); 318 tS->SetAutoSave(); 146 TFile *fSig = new TFile("res_Signal"+ver+".root","RECREATE"); 147 TTree *tWeiS = new TTree("T","T"); 148 float b_weiS = -100; 149 float b_mtophad= -100; 150 float b_HT= -100; 151 float b_cos1= -100; 152 float b_cos2= -100; 153 float b_MinLep1= -100; 154 short b_hfor= -100; 155 short b_hasBadJet= -100; 156 short b_isEleEvent= -100; 157 int b_RunNumber= -100; 158 tWeiS->Branch("wei", &b_weiS, "wei/F"); 159 tWeiS->Branch("mtophad", &b_mtophad, "mtophad/F"); 160 tWeiS->Branch("HT", &b_HT, "HT/F"); 161 tWeiS->Branch("cos1", &b_cos1, "cos1/F"); 162 tWeiS->Branch("cos2", &b_cos2, "cos2/F"); 163 tWeiS->Branch("MinLep1", &b_MinLep1, "MinLep1/F"); 164 tWeiS->Branch("hfor", &b_hfor, "hfor/S"); 165 tWeiS->Branch("hasBadJet", &b_hasBadJet, "hasBadJet/S"); 166 tWeiS->Branch("isEleEvent", &b_isEleEvent, "isEleEvent/S"); 167 tWeiS->Branch("RunNumber", &b_RunNumber, "RunNumber/I"); 319 168 gROOT->cd(); 320 169 … … 323 172 countS++; 324 173 tSig->GetEntry(ifi); 174 b_mtophad = tSig->GetLeaf("mtophad")->GetValue(); 175 b_HT = tSig->GetLeaf("HT")->GetValue(); 176 177 if (b_mtophad<250 || b_HT<620) continue; 325 178 if (ifi%1000==0) cout << "Reading event " << ifi << " from Signal tree" << endl; 326 179 327 TString currentFile = tSig->GetTree()->GetCurrentFile()->GetName(); 328 329 b_weiS = Wei[0]; 330 331 tS->Fill(); 180 //TString currentFile = tSig->GetTree()->GetCurrentFile()->GetName(); 181 182 b_weiS = Wei[0]*tSig->GetLeaf("WeiEvent")->GetValue(); 183 b_cos1 = tSig->GetLeaf("cos_tlepCMtpair")->GetValue(); 184 b_cos2 = tSig->GetLeaf("cosWqq")->GetValue(); 185 b_MinLep1 = tSig->GetLeaf("MinLep1")->GetValue(); 186 b_hfor = (short)tSig->GetLeaf("hfor")->GetValue(); 187 b_isEleEvent = (short)tSig->GetLeaf("isEleEvent")->GetValue(); 188 b_hasBadJet = (short)tSig->GetLeaf("hasBadJet")->GetValue(); 189 b_RunNumber = (int)tSig->GetLeaf("RunNumber_ana")->GetValue(); 190 332 191 tWeiS->Fill(); 333 192 } 334 193 335 194 fSig->cd(); 336 tS->Write("",TObject::kOverwrite);337 195 tWeiS->Write(); 338 for (int i = 0; i < 3; i++){339 hnjetSig[i]->Write();340 }341 196 fSig->Close(); 342 197 … … 344 199 //*************** File AllBkg ***************** 345 200 //############################################## 346 201 TFile *fAllBkg; 347 202 if (s2[1]=="105200"){ 348 TFile *fAllBkg = new TFile("res_AllBkgTopMCAtNLO"+ver+"N.root","RECREATE"); 349 } 350 if (s2[1]=="105861"){ 351 TFile *fAllBkg = new TFile("res_AllBkgTopPoPy"+ver+"N.root","RECREATE"); 352 } 353 if (s2[1]=="105860"){ 354 TFile *fAllBkg = new TFile("res_AllBkgTopPoJi"+ver+"N.root","RECREATE"); 355 } 356 357 TTree *tWeiB = new TTree("Tw","Tw"); 358 double b_weiB = -100; 359 tWeiB->Branch("wei", &b_weiB, "wei/D"); 360 TTree *tB = tAllBkg->CloneTree(0); 361 tB->SetName("T"); 362 tB->SetAutoSave(); 203 fAllBkg = new TFile("res_AllBkgTopMCAtNLO"+ver+".root","RECREATE"); 204 } 205 else if (s2[1]=="105861"){ 206 fAllBkg = new TFile("res_AllBkgTopPoPy"+ver+".root","RECREATE"); 207 } 208 else if (s2[1]=="105860"){ 209 fAllBkg = new TFile("res_AllBkgTopPoJi"+ver+".root","RECREATE"); 210 } else { 211 cout << "Wrong top sample ! Put T1 as default" << endl; 212 fAllBkg = new TFile("res_AllBkgTopMCAtNLO"+ver+".root","RECREATE"); 213 } 214 215 TTree *tWeiB = new TTree("T","T"); 216 tWeiB->Branch("wei", &b_weiS, "wei/F"); 217 tWeiB->Branch("mtophad", &b_mtophad, "mtophad/F"); 218 tWeiB->Branch("HT", &b_HT, "HT/F"); 219 tWeiB->Branch("cos1", &b_cos1, "cos1/F"); 220 tWeiB->Branch("cos2", &b_cos2, "cos2/F"); 221 tWeiB->Branch("MinLep1", &b_MinLep1, "MinLep1/F"); 222 tWeiB->Branch("hfor", &b_hfor, "hfor/S"); 223 tWeiB->Branch("hasBadJet", &b_hasBadJet, "hasBadJet/S"); 224 tWeiB->Branch("isEleEvent", &b_isEleEvent, "isEleEvent/S"); 225 tWeiB->Branch("RunNumber", &b_RunNumber, "RunNumber/I"); 363 226 gROOT->cd(); 364 227 … … 367 230 countB++; 368 231 tAllBkg->GetEntry(ifi); 232 double mt = tAllBkg->GetLeaf("mtophad")->GetValue(); 233 double ht = tAllBkg->GetLeaf("HT")->GetValue(); 234 b_mtophad = mt; 235 b_HT = ht; 236 237 if (mt<250 || ht<620) continue; 369 238 if (ifi%1000==0) cout << "Reading event " << ifi << " from AllBkg tree" << endl; 370 239 371 240 TString currentFile = tAllBkg->GetTree()->GetCurrentFile()->GetName(); 241 b_hfor = (short)tAllBkg->GetLeaf("hfor")->GetValue(); 372 242 for (int i = 0; i < 78; i++){ 243 double kfac = 1, ksE = 1, ksM = 1; 244 if (i>=2 && i<=32) {kfac = 1.2; ksE = 0.906; ksM = 0.814;}//k factor for W+jets 245 if (i>=40 && i<=69) {kfac = 1.25;}//Zjets 246 373 247 if (fname[i]==currentFile) 374 b_weiB = Wei[i]; 375 } 376 tB->Fill(); 248 b_weiS = Wei[i]*(tAllBkg->GetLeaf("WeiEvent")->GetValue())*WJet_SF(b_hfor)*kfac*ksE*ksM; 249 } 250 b_cos1 = tAllBkg->GetLeaf("cos_tlepCMtpair")->GetValue(); 251 b_cos2 = tAllBkg->GetLeaf("cosWqq")->GetValue(); 252 b_MinLep1 = tAllBkg->GetLeaf("MinLep1")->GetValue(); 253 b_isEleEvent = (short)tAllBkg->GetLeaf("isEleEvent")->GetValue(); 254 b_hasBadJet = (short)tAllBkg->GetLeaf("hasBadJet")->GetValue(); 255 b_RunNumber = (int)tAllBkg->GetLeaf("RunNumber_ana")->GetValue(); 377 256 tWeiB->Fill(); 378 257 } 379 258 380 259 fAllBkg->cd(); 381 tB->Write("",TObject::kOverwrite);382 260 tWeiB->Write(); 383 261 fAllBkg->Close(); … … 387 265 //***************** File Top ****************** 388 266 //############################################## 389 267 TFile *fTop; 390 268 if (s2[1]=="105200"){ 391 TFile *fTop = new TFile("res_TopMCAtNLO"+ver+"N.root","RECREATE"); 392 } 393 if (s2[1]=="104061"){ 394 TFile *fTop = new TFile("res_TopPoPy"+ver+"N.root","RECREATE"); 395 } 396 if (s2[1]=="104060"){ 397 TFile *fTop = new TFile("res_TopPoJi"+ver+"N.root","RECREATE"); 398 } 399 400 TTree *tWeiT = new TTree("Tw","Tw"); 401 double b_weiT = -100; 402 tWeiT->Branch("wei", &b_weiT, "wei/D"); 403 TTree *tT = tTop->CloneTree(0); 404 tT->SetName("T"); 405 tT->SetAutoSave(); 406 gROOT->cd(); 407 408 int countT = 0; 269 fTop = new TFile("res_TopMCAtNLO"+ver+".root","RECREATE"); 270 } 271 else if (s2[1]=="105861"){ 272 fTop = new TFile("res_TopPoPy"+ver+".root","RECREATE"); 273 } 274 else if (s2[1]=="105860"){ 275 fTop = new TFile("res_TopPoJi"+ver+".root","RECREATE"); 276 } else { 277 cout << "Wrong top sample ! Put T1 as default" << endl; 278 fTop = new TFile("res_TopMCAtNLO"+ver+".root","RECREATE"); 279 } 280 281 TTree *tWeiT = new TTree("T","T"); 282 tWeiT->Branch("wei", &b_weiS, "wei/F"); 283 tWeiT->Branch("mtophad", &b_mtophad, "mtophad/F"); 284 tWeiT->Branch("HT", &b_HT, "HT/F"); 285 tWeiT->Branch("cos1", &b_cos1, "cos1/F"); 286 tWeiT->Branch("cos2", &b_cos2, "cos2/F"); 287 tWeiT->Branch("MinLep1", &b_MinLep1, "MinLep1/F"); 288 tWeiT->Branch("hfor", &b_hfor, "hfor/S"); 289 tWeiT->Branch("hasBadJet", &b_hasBadJet, "hasBadJet/S"); 290 tWeiT->Branch("isEleEvent", &b_isEleEvent, "isEleEvent/S"); 291 tWeiT->Branch("RunNumber", &b_RunNumber, "RunNumber/I"); 292 gROOT->cd(); 293 294 int countB = 0; 409 295 for (int ifi = 0; ifi < tTop->GetEntries(); ifi++){ 410 count T++;296 countB++; 411 297 tTop->GetEntry(ifi); 298 double mt = tTop->GetLeaf("mtophad")->GetValue(); 299 double ht = tTop->GetLeaf("HT")->GetValue(); 300 b_mtophad = mt; 301 b_HT = ht; 302 303 if (mt<250 || ht<620) continue; 412 304 if (ifi%1000==0) cout << "Reading event " << ifi << " from Top tree" << endl; 413 305 … … 415 307 for (int i = 0; i < 78; i++){ 416 308 if (fname[i]==currentFile) 417 b_weiT = Wei[i]; 418 } 419 tT->Fill(); 309 b_weiS = Wei[i]*(tTop->GetLeaf("WeiEvent")->GetValue()); 310 } 311 b_cos1 = tTop->GetLeaf("cos_tlepCMtpair")->GetValue(); 312 b_hfor = (short)tTop->GetLeaf("hfor")->GetValue(); 313 b_cos2 = tTop->GetLeaf("cosWqq")->GetValue(); 314 b_MinLep1 = tTop->GetLeaf("MinLep1")->GetValue(); 315 b_isEleEvent = (short)tTop->GetLeaf("isEleEvent")->GetValue(); 316 b_hasBadJet = (short)tTop->GetLeaf("hasBadJet")->GetValue(); 317 b_RunNumber = (int)tTop->GetLeaf("RunNumber_ana")->GetValue(); 420 318 tWeiT->Fill(); 421 319 } 422 320 423 321 fTop->cd(); 424 tT->Write("",TObject::kOverwrite);425 322 tWeiT->Write(); 426 for (int i = 0; i < 3; i++){427 hnjetTopP[i]->Write();428 }429 323 fTop->Close(); 430 324 431 432 //################################################ 433 //**************** File Wjets ****************** 434 //################################################ 435 436 TFile *fAllW = new TFile("res_AllW"+ver+"N.root","RECREATE"); 437 TTree *tWeiW = new TTree("Tw","Tw"); 438 double b_weiW = -100; 439 tWeiW->Branch("wei", &b_weiW, "wei/D"); 440 TTree *tW = tAllW->CloneTree(0); 441 tW->SetName("T"); 442 tW->SetAutoSave(); 443 gROOT->cd(); 444 445 int countW = 0; 325 //############################################## 326 //*************** File AllW ***************** 327 //############################################## 328 TFile *fAllW = new TFile("res_AllW"+ver+".root","RECREATE"); 329 330 TTree *tWeiW = new TTree("T","T"); 331 tWeiW->Branch("wei", &b_weiS, "wei/F"); 332 tWeiW->Branch("mtophad", &b_mtophad, "mtophad/F"); 333 tWeiW->Branch("HT", &b_HT, "HT/F"); 334 tWeiW->Branch("cos1", &b_cos1, "cos1/F"); 335 tWeiW->Branch("cos2", &b_cos2, "cos2/F"); 336 tWeiW->Branch("MinLep1", &b_MinLep1, "MinLep1/F"); 337 tWeiW->Branch("hfor", &b_hfor, "hfor/S"); 338 tWeiW->Branch("hasBadJet", &b_hasBadJet, "hasBadJet/S"); 339 tWeiW->Branch("isEleEvent", &b_isEleEvent, "isEleEvent/S"); 340 tWeiW->Branch("RunNumber", &b_RunNumber, "RunNumber/I"); 341 gROOT->cd(); 342 343 int countB = 0; 446 344 for (int ifi = 0; ifi < tAllW->GetEntries(); ifi++){ 447 count W++;345 countB++; 448 346 tAllW->GetEntry(ifi); 347 double mt = tAllW->GetLeaf("mtophad")->GetValue(); 348 double ht = tAllW->GetLeaf("HT")->GetValue(); 349 b_mtophad = mt; 350 b_HT = ht; 351 352 if (mt<250 || ht<620) continue; 449 353 if (ifi%1000==0) cout << "Reading event " << ifi << " from AllW tree" << endl; 450 354 451 355 TString currentFile = tAllW->GetTree()->GetCurrentFile()->GetName(); 452 356 b_hfor = (short)tAllW->GetLeaf("hfor")->GetValue(); 357 for (int i = 0; i < 78; i++){ 358 double kfac = 1, ksE = 1, ksM = 1; 359 if (i>=2 && i<=32) {kfac = 1.2; ksE = 0.906; ksM = 0.814;}//k factor for W+jets 360 361 if (fname[i]==currentFile) 362 b_weiS = Wei[i]*(tAllW->GetLeaf("WeiEvent")->GetValue())*WJet_SF(b_hfor)*kfac*ksE*ksM; 363 } 364 b_cos1 = tAllW->GetLeaf("cos_tlepCMtpair")->GetValue(); 365 b_cos2 = tAllW->GetLeaf("cosWqq")->GetValue(); 366 b_MinLep1 = tAllW->GetLeaf("MinLep1")->GetValue(); 367 b_isEleEvent = (short)tAllW->GetLeaf("isEleEvent")->GetValue(); 368 b_hasBadJet = (short)tAllW->GetLeaf("hasBadJet")->GetValue(); 369 b_RunNumber = (int)tAllW->GetLeaf("RunNumber_ana")->GetValue(); 370 tWeiW->Fill(); 371 } 372 373 fAllW->cd(); 374 tWeiW->Write(); 375 fAllW->Close(); 376 377 //############################################## 378 //*********** File Single Top ***************** 379 //############################################## 380 TFile *fSingT = new TFile("res_SingleTop"+ver+".root","RECREATE"); 381 382 TTree *tWeiST = new TTree("T","T"); 383 tWeiST->Branch("wei", &b_weiS, "wei/F"); 384 tWeiST->Branch("mtophad", &b_mtophad, "mtophad/F"); 385 tWeiST->Branch("HT", &b_HT, "HT/F"); 386 tWeiST->Branch("cos1", &b_cos1, "cos1/F"); 387 tWeiST->Branch("cos2", &b_cos2, "cos2/F"); 388 tWeiST->Branch("MinLep1", &b_MinLep1, "MinLep1/F"); 389 tWeiST->Branch("hfor", &b_hfor, "hfor/S"); 390 tWeiST->Branch("hasBadJet", &b_hasBadJet, "hasBadJet/S"); 391 tWeiST->Branch("isEleEvent", &b_isEleEvent, "isEleEvent/S"); 392 tWeiST->Branch("RunNumber", &b_RunNumber, "RunNumber/I"); 393 gROOT->cd(); 394 395 int countB = 0; 396 for (int ifi = 0; ifi < tSingT->GetEntries(); ifi++){ 397 countB++; 398 tSingT->GetEntry(ifi); 399 double mt = tSingT->GetLeaf("mtophad")->GetValue(); 400 double ht = tSingT->GetLeaf("HT")->GetValue(); 401 b_mtophad = mt; 402 b_HT = ht; 403 404 if (mt<250 || ht<620) continue; 405 if (ifi%1000==0) cout << "Reading event " << ifi << " from SingT tree" << endl; 406 407 TString currentFile = tSingT->GetTree()->GetCurrentFile()->GetName(); 453 408 for (int i = 0; i < 78; i++){ 454 409 if (fname[i]==currentFile) 455 b_weiW = Wei[i]; 456 } 457 458 tW->Fill(); 459 tWeiW->Fill(); 460 } 461 462 fAllW->cd(); 463 tW->Write("",TObject::kOverwrite); 464 tWeiW->Write(); 465 for (int i = 0; i < 3; i++){ 466 hnjetAllW[i]->Write(); 467 } 468 fAllW->Close(); 469 470 //################################################ 471 //**************** File SingT ****************** 472 //################################################ 473 474 TFile *fSingT = new TFile("res_SingT"+ver+"N.root","RECREATE"); 475 TTree *tWeiST = new TTree("Tw","Tw"); 476 double b_weiST = -100; 477 tWeiST->Branch("wei", &b_weiST, "wei/D"); 478 TTree *tST = tSingT->CloneTree(0); 479 tST->SetName("T"); 480 tST->SetAutoSave(); 481 gROOT->cd(); 482 483 int countST = 0; 484 for (int ifi = 0; ifi < tSingT->GetEntries(); ifi++){ 485 countST++; 486 tSingT->GetEntry(ifi); 487 if (ifi%1000==0) cout << "Reading event " << ifi << " from SingT tree" << endl; 488 489 TString currentFile = tSingT->GetTree()->GetCurrentFile()->GetName(); 490 410 b_weiS = Wei[i]*(tSingT->GetLeaf("WeiEvent")->GetValue()); 411 } 412 b_hfor = (short)tSingT->GetLeaf("hfor")->GetValue(); 413 b_cos1 = tSingT->GetLeaf("cos_tlepCMtpair")->GetValue(); 414 b_cos2 = tSingT->GetLeaf("cosWqq")->GetValue(); 415 b_MinLep1 = tSingT->GetLeaf("MinLep1")->GetValue(); 416 b_isEleEvent = (short)tSingT->GetLeaf("isEleEvent")->GetValue(); 417 b_hasBadJet = (short)tSingT->GetLeaf("hasBadJet")->GetValue(); 418 b_RunNumber = (int)tSingT->GetLeaf("RunNumber_ana")->GetValue(); 419 tWeiST->Fill(); 420 } 421 422 fSingT->cd(); 423 tWeiST->Write(); 424 fSingT->Close(); 425 426 //############################################## 427 //*************** File AllZ ***************** 428 //############################################## 429 TFile *fAllZ = new TFile("res_AllZ"+ver+".root","RECREATE"); 430 431 TTree *tWeiZ = new TTree("T","T"); 432 tWeiZ->Branch("wei", &b_weiS, "wei/F"); 433 tWeiZ->Branch("mtophad", &b_mtophad, "mtophad/F"); 434 tWeiZ->Branch("HT", &b_HT, "HT/F"); 435 tWeiZ->Branch("cos1", &b_cos1, "cos1/F"); 436 tWeiZ->Branch("cos2", &b_cos2, "cos2/F"); 437 tWeiZ->Branch("MinLep1", &b_MinLep1, "MinLep1/F"); 438 tWeiZ->Branch("hfor", &b_hfor, "hfor/S"); 439 tWeiZ->Branch("hasBadJet", &b_hasBadJet, "hasBadJet/S"); 440 tWeiZ->Branch("isEleEvent", &b_isEleEvent, "isEleEvent/S"); 441 tWeiZ->Branch("RunNumber", &b_RunNumber, "RunNumber/I"); 442 gROOT->cd(); 443 444 int countB = 0; 445 for (int ifi = 0; ifi < tAllZ->GetEntries(); ifi++){ 446 countB++; 447 tAllZ->GetEntry(ifi); 448 double mt = tAllZ->GetLeaf("mtophad")->GetValue(); 449 double ht = tAllZ->GetLeaf("HT")->GetValue(); 450 b_mtophad = mt; 451 b_HT = ht; 452 453 if (mt<250 || ht<620) continue; 454 if (ifi%1000==0) cout << "Reading event " << ifi << " from AllZ tree" << endl; 455 456 TString currentFile = tAllZ->GetTree()->GetCurrentFile()->GetName(); 457 b_hfor = (short)tAllZ->GetLeaf("hfor")->GetValue(); 458 for (int i = 0; i < 78; i++){ 459 double kfac = 1, ksE = 1, ksM = 1; 460 if (i>=40 && i<=69) {kfac = 1.25;}//Zjets 461 462 if (fname[i]==currentFile) 463 b_weiS = Wei[i]*(tAllZ->GetLeaf("WeiEvent")->GetValue())*WJet_SF(b_hfor)*kfac*ksE*ksM; 464 } 465 b_cos1 = tAllZ->GetLeaf("cos_tlepCMtpair")->GetValue(); 466 b_cos2 = tAllZ->GetLeaf("cosWqq")->GetValue(); 467 b_MinLep1 = tAllZ->GetLeaf("MinLep1")->GetValue(); 468 b_isEleEvent = (short)tAllZ->GetLeaf("isEleEvent")->GetValue(); 469 b_hasBadJet = (short)tAllZ->GetLeaf("hasBadJet")->GetValue(); 470 b_RunNumber = (int)tAllZ->GetLeaf("RunNumber_ana")->GetValue(); 471 tWeiZ->Fill(); 472 } 473 474 fAllZ->cd(); 475 tWeiZ->Write(); 476 fAllZ->Close(); 477 478 //############################################## 479 //**************** File QCD ******************* 480 //############################################## 481 TFile *fQCD = new TFile("res_QCD"+ver+".root","RECREATE"); 482 483 TTree *tWeiQCD = new TTree("T","T"); 484 tWeiQCD->Branch("wei", &b_weiS, "wei/F"); 485 tWeiQCD->Branch("mtophad", &b_mtophad, "mtophad/F"); 486 tWeiQCD->Branch("HT", &b_HT, "HT/F"); 487 tWeiQCD->Branch("cos1", &b_cos1, "cos1/F"); 488 tWeiQCD->Branch("cos2", &b_cos2, "cos2/F"); 489 tWeiQCD->Branch("MinLep1", &b_MinLep1, "MinLep1/F"); 490 tWeiQCD->Branch("hfor", &b_hfor, "hfor/S"); 491 tWeiQCD->Branch("hasBadJet", &b_hasBadJet, "hasBadJet/S"); 492 tWeiQCD->Branch("isEleEvent", &b_isEleEvent, "isEleEvent/S"); 493 tWeiQCD->Branch("RunNumber", &b_RunNumber, "RunNumber/I"); 494 gROOT->cd(); 495 496 int countB = 0; 497 for (int ifi = 0; ifi < tQCD->GetEntries(); ifi++){ 498 countB++; 499 tQCD->GetEntry(ifi); 500 double mt = tQCD->GetLeaf("mtophad")->GetValue(); 501 double ht = tQCD->GetLeaf("HT")->GetValue(); 502 b_mtophad = mt; 503 b_HT = ht; 504 505 if (mt<250 || ht<620) continue; 506 if (ifi%1000==0) cout << "Reading event " << ifi << " from QCD tree" << endl; 507 508 TString currentFile = tQCD->GetTree()->GetCurrentFile()->GetName(); 491 509 for (int i = 0; i < 78; i++){ 492 510 if (fname[i]==currentFile) 493 b_weiST = Wei[i]; 494 } 495 496 tST->Fill(); 497 tWeiST->Fill(); 498 } 499 500 fSingT->cd(); 501 tST->Write("",TObject::kOverwrite); 502 tWeiST->Write(); 503 for (int i = 0; i < 3; i++){ 504 hnjetSingT[i]->Write(); 505 } 506 fSingT->Close(); 507 508 509 //################################################ 510 //**************** File Zjets ****************** 511 //################################################ 512 513 TFile *fAllZ = new TFile("res_AllZ"+ver+"N.root","RECREATE"); 514 TTree *tWeiZ = new TTree("Tw","Tw"); 515 double b_weiZ = -100; 516 tWeiZ->Branch("wei", &b_weiZ, "wei/D"); 517 TTree *tZ = tAllZ->CloneTree(0); 518 tZ->SetName("T"); 519 tZ->SetAutoSave(); 520 gROOT->cd(); 521 522 int countZ = 0; 523 for (int ifi = 0; ifi < tAllZ->GetEntries(); ifi++){ 524 countZ++; 525 tAllZ->GetEntry(ifi); 526 if (ifi%1000==0) cout << "Reading event " << ifi << " from AllZ tree" << endl; 527 528 TString currentFile = tAllZ->GetTree()->GetCurrentFile()->GetName(); 529 530 for (int i = 0; i < 78; i++){ 531 if (fname[i]==currentFile) 532 b_weiZ = Wei[i]; 533 } 534 535 tZ->Fill(); 536 tWeiZ->Fill(); 537 } 538 539 fAllZ->cd(); 540 tZ->Write("",TObject::kOverwrite); 541 tWeiZ->Write(); 542 for (int i = 0; i < 3; i++){ 543 hnjetAllZ[i]->Write(); 544 } 545 fAllZ->Close(); 546 547 //################################################ 548 //****************** File QCD ******************* 549 //################################################ 550 551 TFile *fQCD = new TFile("res_QCD"+ver+"N.root","RECREATE"); 552 TTree *tWeiQCD = new TTree("Tw","Tw"); 553 double b_weiQCD = -100; 554 tWeiQCD->Branch("wei", &b_weiQCD, "wei/D"); 555 TTree *tqcd = tQCD->CloneTree(0); 556 tqcd->SetName("T"); 557 tqcd->SetAutoSave(); 558 gROOT->cd(); 559 560 int countQCD = 0; 561 for (int ifi = 0; ifi < tQCD->GetEntries(); ifi++){ 562 countQCD++; 563 tQCD->GetEntry(ifi); 564 if (ifi%1000==0) cout << "Reading event " << ifi << " from QCD tree" << endl; 565 566 TString currentFile = tQCD->GetTree()->GetCurrentFile()->GetName(); 567 568 for (int i = 0; i < 78; i++){ 569 if (fname[i]==currentFile) 570 b_weiQCD = Wei[i]; 571 } 572 573 tqcd->Fill(); 511 b_weiS = Wei[i]*(tQCD->GetLeaf("WeiEvent")->GetValue()); 512 } 513 b_cos1 = tQCD->GetLeaf("cos_tlepCMtpair")->GetValue(); 514 b_hfor = (short)tQCD->GetLeaf("hfor")->GetValue(); 515 b_cos2 = tQCD->GetLeaf("cosWqq")->GetValue(); 516 b_MinLep1 = tQCD->GetLeaf("MinLep1")->GetValue(); 517 b_isEleEvent = (short)tQCD->GetLeaf("isEleEvent")->GetValue(); 518 b_hasBadJet = (short)tQCD->GetLeaf("hasBadJet")->GetValue(); 519 b_RunNumber = (int)tQCD->GetLeaf("RunNumber_ana")->GetValue(); 574 520 tWeiQCD->Fill(); 575 521 } 576 522 577 523 fQCD->cd(); 578 tqcd->Write("",TObject::kOverwrite);579 524 tWeiQCD->Write(); 580 for (int i = 0; i < 3; i++){581 hnjetQCD[i]->Write();582 }583 525 fQCD->Close(); 584 526 585 cout << "CountD = " << countD << endl;586 cout << "CountS = " << countS << endl;587 cout << "CountB = " << countB << endl;588 cout << "CountT = " << countT << endl;589 cout << "CountW = " << countW << endl;590 cout << "CountST = " << countST << endl;591 cout << "CountZ = " << countZ << endl;592 cout << "CountQCD = " << countQCD << endl;593 594 527 }
Note: See TracChangeset
for help on using the changeset viewer.