source: huonglan/SPLOT/NEWREALEASE/MERGEFILES/MakeFakeData.C @ 22

Last change on this file since 22 was 22, checked in by huonglan, 13 years ago

sPlots_NewRel improved

File size: 22.5 KB
Line 
1#include "WJetSF_EPS_ttbar_withLF.h"
2
3void MakeFakeData(TString TheTreeName = "T") {
4  TChain *tdn = new TChain(TheTreeName);
5
6  //Signal :
7  //200 GeV/c2 : 115411
8  //250 GeV/c2 : 115414
9  //300 GeV/c2 : 115417
10  //350 GeV/c2 : 115420
11  //400 GeV/c2 : 115423
12  //450 GeV/c2 : 115426
13  //500 GeV/c2 : 115429
14
15  //MC@NLO   : 105200
16  //Top PoPy : 105861
17  //Top PoJi : 105860
18  TString s1 = "/data/atlas/huonglan/FROMLYON/MC/VER3/res";
19  TString s2[78] = {"115423","105200",
20                    "107680","107681","107682","107683","107684","107685",
21                    "107690","107691","107692","107693","107694","107695",
22                    "107700","107701","107702","107703","107704","107705",
23                    "107280","107281","107282","107283","117284","117285",
24                    "117286","117287","117293","117294","117295","117296","117297",
25                    "108340","108341","108342","108343","108344","108345","108346",
26                    "107650","107651","107652","107653","107654","107655",
27                    "107660","107661","107662","107663","107664","107665",
28                    "107670","107671","107672","107673","107674","107675",
29                    "109300","109301","109302","109303","109305","109306",
30                    "109307","109308","109310","109311","109312","109313",
31                    "105010","105011","105012","105013","105014","105015","105016","105017"};
32  //Signal, TTbar : 0,1
33  //Wjets    (3 lines) : From 2 to 19
34  //W+heavy  (2 lines) : From 20 to 32
35  //SingT    (1 line)  : From 33 to 39
36  //Zjets    (3 lines) : From 40 to 57
37  //Z+heavy  (2 lines) : From 58 to 69
38  //QCD      (1 line)  : From 70 to 77         
39
40  TString s3 = "v3.root";
41  TString ver = "v3";
42
43  //set the name of 78 files
44  TString fname[78];
45  for (int i = 0; i < 78; i++){
46    fname[i] = s1;
47    fname[i] += s2[i];
48    fname[i] += s3;
49  }
50
51  float cx[78] = {1.43,   164.6,
52                  6922,   1034,   378,    101.4,   25.9,    7.0,
53                  6920,   1304,   377.8,  101.9,   25.7,    6.9,
54                  6919,   1303,   378,    101.5,   25.6,    7.0,
55                  47.345, 35.777, 17.381, 7.6129, 127.80, 104.67, 52.180,
56                  20.514, 644.36, 204.99, 50.877, 11.415, 2.773,
57                  7.1168, 7.1084, 7.1044, 0.46927, 0.46890, 0.46886, 14.593,
58                  669.67, 134.41, 40.724, 11.298,  2.8570,  0.75883,
59                  669.68, 134.64, 40.749, 11.274,  2.8462,  0.76319,
60                  669.56, 134.65, 40.762, 11.274,  2.8390,  0.76125,
61                  6.5682, 2.4752, 0.88544, 0.39202, 6.5639, 2.4739,
62                  0.88713, 0.39008, 6.5745, 2.4878, 0.89293, 0.38872,
63                  6.7818e8, 4.0982e7, 2.1929e6, 8.7701e4, 2.3501e3, 33.614, 0.13744, 6.2099e-6};
64
65  float effFilt[78] = {0.68467,0.55551,
66                       1, 1, 1, 1, 1, 1,
67                       1, 1, 1, 1, 1, 1,
68                       1, 1, 1, 1, 1, 1,
69                       0.3500, 0.5086, 0.5323, 0.5525, 0.3018, 0.4910, 
70                       0.5223, 0.5424, 0.4236, 0.5455, 0.5794, 0.5934, 0.6019,
71                       1.,1.,1.,1.,1.,1.,1.,
72                       0.6776, 0.8453, 0.8739, 0.8906, 0.8989, 1.,
73                       0.4683, 0.8499, 0.8982, 0.9169, 0.9262, 0.9318,
74                       0.1546, 0.2441, 0.2805, 0.3095, 0.3290, 0.3560,
75                       0.8508, 0.8965, 0.9039, 0.9114, 0.6959, 0.9070,
76                       0.9242, 0.9336, 0.2221, 0.2889, 0.3206, 0.3547,
77                       1, 1, 1, 1, 1, 1, 1, 1};
78
79
80  //compute the weights corresponding
81  float Wei[78];
82  for (int i = 0; i < 78; i++){
83    TFile *f = TFile::Open(fname[i]);
84    TTree *t = (TTree*)f->Get("T");
85    TH1F *hloose = (TH1F*)f->Get("loose");
86
87    double nevtIn  = 0.;
88    double nevtOut = 0.;
89    int nbin = hloose->GetNbinsX();
90    for (int ib = 1; ib < 21; ib++){
91      double bv = hloose->GetBinContent(ib);
92      double bc = hloose->GetBinCenter(ib) - 0.5;
93      if (bc==0)
94        nevtIn = bv;
95      if (bc==17)
96        nevtOut = bv;
97    }
98    Wei[i]   = cx[i]*1035*effFilt[i]/nevtIn;
99  }
100
101  TChain *tData   = new TChain(TheTreeName);
102  TChain *tSig    = new TChain(TheTreeName);
103  TChain *tAllBkg = new TChain(TheTreeName);
104  TChain *tTop    = new TChain(TheTreeName);
105  TChain *tAllW   = new TChain(TheTreeName);
106  TChain *tSingT  = new TChain(TheTreeName);
107  TChain *tAllZ   = new TChain(TheTreeName);
108  TChain *tQCD    = new TChain(TheTreeName);
109 
110  //Add files to TChain
111  for (int i = 0; i < 78; i++){
112    cout << "Copying file " << fname[i] << endl;
113    TFile *f = TFile::Open(fname[i]);
114    TTree *t = (TTree*)f->Get("T");
115    cout << "Entries number of " << fname[i] << " = " << t->GetEntries() << endl;
116    tData->Add(fname[i]);
117    if (i==0)
118      tSig->Add(fname[i]);
119    if (i==1)
120      tTop->Add(fname[i]);
121    if (i>=1 && i<=69)//i don't want to add the QCD into background file
122      tAllBkg->Add(fname[i]);
123    if (i>=2 && i<=32)
124      tAllW->Add(fname[i]);
125    if (i>=33 && i<=39)
126      tSingT->Add(fname[i]);
127    if (i>=40 && i<=69)
128      tAllZ->Add(fname[i]);
129    if (i>=70 && i<=77)
130      tQCD->Add(fname[i]);
131  }
132
133  cout << "Entries of Data file   = " << tData->GetEntries() << endl;
134  cout << "Entries of Sig  file   = " << tSig->GetEntries() << endl;
135  cout << "Entries of AllBkg file = " << tAllBkg->GetEntries() << endl;
136  cout << "Entries of Top file    = " << tTop->GetEntries() << endl;
137  cout << "Entries of AllW file   = " << tAllW->GetEntries() << endl;
138  cout << "Entries of SingT file  = " << tSingT->GetEntries() << endl;
139  cout << "Entries of AllZ file   = " << tAllZ->GetEntries() << endl;
140  cout << "Entries of QCD file    = " << tQCD->GetEntries() << endl;
141
142  //###################################
143  //************ File Data  ***********
144  //###################################
145
146  TFile *fData   = new TFile("res_FakeData"+ver+".root","RECREATE");
147  TTree *tWeiD   = new TTree("T","T");
148  float b_wei        = -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  tWeiD->Branch("wei",        &b_wei,                "wei/F");
159  tWeiD->Branch("mtophad",    &b_mtophad,        "mtophad/F");
160  tWeiD->Branch("HT",         &b_HT,                  "HT/F");
161  tWeiD->Branch("cos1",       &b_cos1,              "cos1/F");
162  tWeiD->Branch("cos2",       &b_cos2,              "cos2/F");
163  tWeiD->Branch("MinLep1",    &b_MinLep1,        "MinLep1/F");
164  tWeiD->Branch("hfor",       &b_hfor,              "hfor/S");
165  tWeiD->Branch("hasBadJet",  &b_hasBadJet,    "hasBadJet/S");
166  tWeiD->Branch("isEleEvent", &b_isEleEvent,  "isEleEvent/S");
167  tWeiD->Branch("RunNumber",  &b_RunNumber,    "RunNumber/I");
168  gROOT->cd();
169 
170  int countD = 0;
171  for (int ifi = 0; ifi < tData->GetEntries(); ifi++){
172    countD++;
173    tData->GetEntry(ifi);
174    b_mtophad = tData->GetLeaf("mtophad")->GetValue();
175    b_HT      = tData->GetLeaf("HT")->GetValue();
176
177    //if (b_mtophad<250 || b_HT<620) continue;
178    if (ifi%1000==0) cout << "Reading event " << ifi << " from Data tree" << endl;
179
180    TString currentFile = tData->GetTree()->GetCurrentFile()->GetName();
181
182    b_hfor       = (short)tData->GetLeaf("hfor")->GetValue();
183    for (int i = 0; i < 78; i++){
184      double kfac = 1, ksE = 1, ksM = 1;
185      if (i>=2 && i<=32)  {kfac = 1.2; ksE = 0.906; ksM = 0.814;}//k factor for W+jets
186      if (i>=40 && i<=69) {kfac = 1.25;}//Zjets
187
188      if (fname[i]==currentFile)
189        b_wei = Wei[i]*(tData->GetLeaf("WeiEvent")->GetValue())*WJet_SF(b_hfor)*kfac*ksE*ksM;
190    }
191    b_cos1       = tData->GetLeaf("cos_tlepCMtpair")->GetValue();
192    b_cos2       = tData->GetLeaf("cosWqq")->GetValue();
193    b_MinLep1    = tData->GetLeaf("MinLep1")->GetValue();           
194    b_hfor       = (short)tData->GetLeaf("hfor")->GetValue();
195    b_isEleEvent = (short)tData->GetLeaf("isEleEvent")->GetValue();
196    b_hasBadJet  = (short)tData->GetLeaf("hasBadJet")->GetValue();
197    b_RunNumber  = (int)tData->GetLeaf("RunNumber_ana")->GetValue();
198
199    tWeiD->Fill();
200  }
201
202  fData->cd();
203  tWeiD->Write();
204  fData->Close();
205
206  //###################################
207  //********** File Signal  ***********
208  //###################################
209
210  TFile *fSig    = new TFile("res_Signal"+s2[0]+ver+".root","RECREATE");
211
212  TTree *tWeiS   = new TTree("T","T");
213  tWeiS->Branch("wei",        &b_wei,                "wei/F");
214  tWeiS->Branch("mtophad",    &b_mtophad,        "mtophad/F");
215  tWeiS->Branch("HT",         &b_HT,                  "HT/F");
216  tWeiS->Branch("cos1",       &b_cos1,              "cos1/F");
217  tWeiS->Branch("cos2",       &b_cos2,              "cos2/F");
218  tWeiS->Branch("MinLep1",    &b_MinLep1,        "MinLep1/F");
219  tWeiS->Branch("hfor",       &b_hfor,              "hfor/S");
220  tWeiS->Branch("hasBadJet",  &b_hasBadJet,    "hasBadJet/S");
221  tWeiS->Branch("isEleEvent", &b_isEleEvent,  "isEleEvent/S");
222  tWeiS->Branch("RunNumber",  &b_RunNumber,    "RunNumber/I");
223  gROOT->cd();
224 
225  int countS = 0;
226  for (int ifi = 0; ifi < tSig->GetEntries(); ifi++){
227    countS++;
228    tSig->GetEntry(ifi);
229    b_mtophad = tSig->GetLeaf("mtophad")->GetValue();
230    b_HT      = tSig->GetLeaf("HT")->GetValue();
231
232    //if (b_mtophad<250 || b_HT<620) continue;
233    if (ifi%1000==0) cout << "Reading event " << ifi << " from Signal tree" << endl;
234
235    //TString currentFile = tSig->GetTree()->GetCurrentFile()->GetName();
236
237    b_wei        = Wei[0]*tSig->GetLeaf("WeiEvent")->GetValue();
238    b_cos1       = tSig->GetLeaf("cos_tlepCMtpair")->GetValue();
239    b_cos2       = tSig->GetLeaf("cosWqq")->GetValue();
240    b_MinLep1    = tSig->GetLeaf("MinLep1")->GetValue();           
241    b_hfor       = (short)tSig->GetLeaf("hfor")->GetValue();
242    b_isEleEvent = (short)tSig->GetLeaf("isEleEvent")->GetValue();
243    b_hasBadJet  = (short)tSig->GetLeaf("hasBadJet")->GetValue();
244    b_RunNumber  = (int)tSig->GetLeaf("RunNumber_ana")->GetValue();
245
246    tWeiS->Fill();
247  }
248
249  fSig->cd();
250  tWeiS->Write();
251  fSig->Close();
252
253  //##############################################
254  //*************** File AllBkg  *****************
255  //##############################################
256  TFile *fAllBkg; 
257  if (s2[1]=="105200"){
258    fAllBkg   = new TFile("res_AllBkgTopMCAtNLO"+ver+".root","RECREATE");
259  }
260  else if (s2[1]=="105861"){
261    fAllBkg   = new TFile("res_AllBkgTopPoPy"+ver+".root","RECREATE");
262  }
263  else if (s2[1]=="105860"){
264    fAllBkg   = new TFile("res_AllBkgTopPoJi"+ver+".root","RECREATE");
265  } else {
266    cout << "Wrong top sample ! Put T1 as default" << endl;
267    fAllBkg   = new TFile("res_AllBkgTopMCAtNLO"+ver+".root","RECREATE");
268  }
269
270  TTree *tWeiB   = new TTree("T","T");
271  tWeiB->Branch("wei",        &b_wei,               "wei/F");
272  tWeiB->Branch("mtophad",    &b_mtophad,        "mtophad/F");
273  tWeiB->Branch("HT",         &b_HT,                  "HT/F");
274  tWeiB->Branch("cos1",       &b_cos1,              "cos1/F");
275  tWeiB->Branch("cos2",       &b_cos2,              "cos2/F");
276  tWeiB->Branch("MinLep1",    &b_MinLep1,        "MinLep1/F");
277  tWeiB->Branch("hfor",       &b_hfor,              "hfor/S");
278  tWeiB->Branch("hasBadJet",  &b_hasBadJet,    "hasBadJet/S");
279  tWeiB->Branch("isEleEvent", &b_isEleEvent,  "isEleEvent/S");
280  tWeiB->Branch("RunNumber",  &b_RunNumber,    "RunNumber/I");
281  gROOT->cd();
282
283  int countB = 0;
284  for (int ifi = 0; ifi < tAllBkg->GetEntries(); ifi++){
285    countB++;
286    tAllBkg->GetEntry(ifi);
287    double mt = tAllBkg->GetLeaf("mtophad")->GetValue();
288    double ht = tAllBkg->GetLeaf("HT")->GetValue();
289    b_mtophad = mt;
290    b_HT = ht;
291
292    //if (mt<250 || ht<620) continue;
293    if (ifi%1000==0) cout << "Reading event " << ifi << " from AllBkg tree" << endl;
294
295    TString currentFile = tAllBkg->GetTree()->GetCurrentFile()->GetName();
296    b_hfor       = (short)tAllBkg->GetLeaf("hfor")->GetValue();
297    for (int i = 0; i < 78; i++){
298      double kfac = 1, ksE = 1, ksM = 1;
299      if (i>=2 && i<=32)  {kfac = 1.2; ksE = 0.906; ksM = 0.814;}//k factor for W+jets
300      if (i>=40 && i<=69) {kfac = 1.25;}//Zjets
301
302      if (fname[i]==currentFile)
303        b_wei = Wei[i]*(tAllBkg->GetLeaf("WeiEvent")->GetValue())*WJet_SF(b_hfor)*kfac*ksE*ksM;
304    }
305    b_cos1       = tAllBkg->GetLeaf("cos_tlepCMtpair")->GetValue();
306    b_cos2       = tAllBkg->GetLeaf("cosWqq")->GetValue();
307    b_MinLep1    = tAllBkg->GetLeaf("MinLep1")->GetValue();           
308    b_isEleEvent = (short)tAllBkg->GetLeaf("isEleEvent")->GetValue();
309    b_hasBadJet  = (short)tAllBkg->GetLeaf("hasBadJet")->GetValue();
310    b_RunNumber  = (int)tAllBkg->GetLeaf("RunNumber_ana")->GetValue();
311    tWeiB->Fill();
312  }
313
314  fAllBkg->cd();
315  tWeiB->Write();
316  fAllBkg->Close();
317
318
319  //##############################################
320  //***************** File Top  ******************
321  //##############################################
322  TFile *fTop; 
323  if (s2[1]=="105200"){
324    fTop   = new TFile("res_TopMCAtNLO"+ver+".root","RECREATE");
325  }
326  else if (s2[1]=="105861"){
327    fTop   = new TFile("res_TopPoPy"+ver+".root","RECREATE");
328  }
329  else if (s2[1]=="105860"){
330    fTop   = new TFile("res_TopPoJi"+ver+".root","RECREATE");
331  } else {
332    cout << "Wrong top sample ! Put T1 as default" << endl;
333    fTop   = new TFile("res_TopMCAtNLO"+ver+".root","RECREATE");
334  }
335
336  TTree *tWeiT   = new TTree("T","T");
337  tWeiT->Branch("wei",        &b_wei,               "wei/F");
338  tWeiT->Branch("mtophad",    &b_mtophad,        "mtophad/F");
339  tWeiT->Branch("HT",         &b_HT,                  "HT/F");
340  tWeiT->Branch("cos1",       &b_cos1,              "cos1/F");
341  tWeiT->Branch("cos2",       &b_cos2,              "cos2/F");
342  tWeiT->Branch("MinLep1",    &b_MinLep1,        "MinLep1/F");
343  tWeiT->Branch("hfor",       &b_hfor,              "hfor/S");
344  tWeiT->Branch("hasBadJet",  &b_hasBadJet,    "hasBadJet/S");
345  tWeiT->Branch("isEleEvent", &b_isEleEvent,  "isEleEvent/S");
346  tWeiT->Branch("RunNumber",  &b_RunNumber,    "RunNumber/I");
347  gROOT->cd();
348
349  int countB = 0;
350  for (int ifi = 0; ifi < tTop->GetEntries(); ifi++){
351    countB++;
352    tTop->GetEntry(ifi);
353    double mt = tTop->GetLeaf("mtophad")->GetValue();
354    double ht = tTop->GetLeaf("HT")->GetValue();
355    b_mtophad = mt;
356    b_HT = ht;
357
358    //if (mt<250 || ht<620) continue;
359    if (ifi%1000==0) cout << "Reading event " << ifi << " from Top tree" << endl;
360
361    TString currentFile = tTop->GetTree()->GetCurrentFile()->GetName();
362    for (int i = 0; i < 78; i++){
363      if (fname[i]==currentFile)
364        b_wei = Wei[i]*(tTop->GetLeaf("WeiEvent")->GetValue());
365    }
366    b_cos1       = tTop->GetLeaf("cos_tlepCMtpair")->GetValue();
367    b_hfor       = (short)tTop->GetLeaf("hfor")->GetValue();
368    b_cos2       = tTop->GetLeaf("cosWqq")->GetValue();
369    b_MinLep1    = tTop->GetLeaf("MinLep1")->GetValue();           
370    b_isEleEvent = (short)tTop->GetLeaf("isEleEvent")->GetValue();
371    b_hasBadJet  = (short)tTop->GetLeaf("hasBadJet")->GetValue();
372    b_RunNumber  = (int)tTop->GetLeaf("RunNumber_ana")->GetValue();
373    tWeiT->Fill();
374  }
375
376  fTop->cd();
377  tWeiT->Write();
378  fTop->Close();
379
380  //##############################################
381  //*************** File AllW    *****************
382  //##############################################
383  TFile *fAllW = new TFile("res_AllW"+ver+".root","RECREATE");
384
385  TTree *tWeiW   = new TTree("T","T");
386  tWeiW->Branch("wei",        &b_wei,               "wei/F");
387  tWeiW->Branch("mtophad",    &b_mtophad,        "mtophad/F");
388  tWeiW->Branch("HT",         &b_HT,                  "HT/F");
389  tWeiW->Branch("cos1",       &b_cos1,              "cos1/F");
390  tWeiW->Branch("cos2",       &b_cos2,              "cos2/F");
391  tWeiW->Branch("MinLep1",    &b_MinLep1,        "MinLep1/F");
392  tWeiW->Branch("hfor",       &b_hfor,              "hfor/S");
393  tWeiW->Branch("hasBadJet",  &b_hasBadJet,    "hasBadJet/S");
394  tWeiW->Branch("isEleEvent", &b_isEleEvent,  "isEleEvent/S");
395  tWeiW->Branch("RunNumber",  &b_RunNumber,    "RunNumber/I");
396  gROOT->cd();
397
398  int countB = 0;
399  for (int ifi = 0; ifi < tAllW->GetEntries(); ifi++){
400    countB++;
401    tAllW->GetEntry(ifi);
402    double mt = tAllW->GetLeaf("mtophad")->GetValue();
403    double ht = tAllW->GetLeaf("HT")->GetValue();
404    b_mtophad = mt;
405    b_HT = ht;
406
407    //if (mt<250 || ht<620) continue;
408    if (ifi%1000==0) cout << "Reading event " << ifi << " from AllW tree" << endl;
409
410    TString currentFile = tAllW->GetTree()->GetCurrentFile()->GetName();
411    b_hfor       = (short)tAllW->GetLeaf("hfor")->GetValue();
412    for (int i = 0; i < 78; i++){
413      double kfac = 1, ksE = 1, ksM = 1;
414      if (i>=2 && i<=32)  {kfac = 1.2; ksE = 0.906; ksM = 0.814;}//k factor for W+jets
415
416      if (fname[i]==currentFile)
417        b_wei = Wei[i]*(tAllW->GetLeaf("WeiEvent")->GetValue())*WJet_SF(b_hfor)*kfac*ksE*ksM;
418    }
419    b_cos1       = tAllW->GetLeaf("cos_tlepCMtpair")->GetValue();
420    b_cos2       = tAllW->GetLeaf("cosWqq")->GetValue();
421    b_MinLep1    = tAllW->GetLeaf("MinLep1")->GetValue();           
422    b_isEleEvent = (short)tAllW->GetLeaf("isEleEvent")->GetValue();
423    b_hasBadJet  = (short)tAllW->GetLeaf("hasBadJet")->GetValue();
424    b_RunNumber  = (int)tAllW->GetLeaf("RunNumber_ana")->GetValue();
425    tWeiW->Fill();
426  }
427
428  fAllW->cd();
429  tWeiW->Write();
430  fAllW->Close();
431
432  //##############################################
433  //*********** File Single Top  *****************
434  //##############################################
435  TFile *fSingT   = new TFile("res_SingT"+ver+".root","RECREATE");
436
437  TTree *tWeiST   = new TTree("T","T");
438  tWeiST->Branch("wei",        &b_wei,               "wei/F");
439  tWeiST->Branch("mtophad",    &b_mtophad,        "mtophad/F");
440  tWeiST->Branch("HT",         &b_HT,                  "HT/F");
441  tWeiST->Branch("cos1",       &b_cos1,              "cos1/F");
442  tWeiST->Branch("cos2",       &b_cos2,              "cos2/F");
443  tWeiST->Branch("MinLep1",    &b_MinLep1,        "MinLep1/F");
444  tWeiST->Branch("hfor",       &b_hfor,              "hfor/S");
445  tWeiST->Branch("hasBadJet",  &b_hasBadJet,    "hasBadJet/S");
446  tWeiST->Branch("isEleEvent", &b_isEleEvent,  "isEleEvent/S");
447  tWeiST->Branch("RunNumber",  &b_RunNumber,    "RunNumber/I");
448  gROOT->cd();
449
450  int countB = 0;
451  for (int ifi = 0; ifi < tSingT->GetEntries(); ifi++){
452    countB++;
453    tSingT->GetEntry(ifi);
454    double mt = tSingT->GetLeaf("mtophad")->GetValue();
455    double ht = tSingT->GetLeaf("HT")->GetValue();
456    b_mtophad = mt;
457    b_HT = ht;
458
459    //if (mt<250 || ht<620) continue;
460    if (ifi%1000==0) cout << "Reading event " << ifi << " from SingT tree" << endl;
461
462    TString currentFile = tSingT->GetTree()->GetCurrentFile()->GetName();
463    for (int i = 0; i < 78; i++){
464      if (fname[i]==currentFile)
465        b_wei = Wei[i]*(tSingT->GetLeaf("WeiEvent")->GetValue());
466    }
467    b_hfor       = (short)tSingT->GetLeaf("hfor")->GetValue();
468    b_cos1       = tSingT->GetLeaf("cos_tlepCMtpair")->GetValue();
469    b_cos2       = tSingT->GetLeaf("cosWqq")->GetValue();
470    b_MinLep1    = tSingT->GetLeaf("MinLep1")->GetValue();           
471    b_isEleEvent = (short)tSingT->GetLeaf("isEleEvent")->GetValue();
472    b_hasBadJet  = (short)tSingT->GetLeaf("hasBadJet")->GetValue();
473    b_RunNumber  = (int)tSingT->GetLeaf("RunNumber_ana")->GetValue();
474    tWeiST->Fill();
475  }
476
477  fSingT->cd();
478  tWeiST->Write();
479  fSingT->Close();
480
481  //##############################################
482  //*************** File AllZ    *****************
483  //##############################################
484  TFile *fAllZ = new TFile("res_AllZ"+ver+".root","RECREATE");
485
486  TTree *tWeiZ   = new TTree("T","T");
487  tWeiZ->Branch("wei",        &b_wei,               "wei/F");
488  tWeiZ->Branch("mtophad",    &b_mtophad,        "mtophad/F");
489  tWeiZ->Branch("HT",         &b_HT,                  "HT/F");
490  tWeiZ->Branch("cos1",       &b_cos1,              "cos1/F");
491  tWeiZ->Branch("cos2",       &b_cos2,              "cos2/F");
492  tWeiZ->Branch("MinLep1",    &b_MinLep1,        "MinLep1/F");
493  tWeiZ->Branch("hfor",       &b_hfor,              "hfor/S");
494  tWeiZ->Branch("hasBadJet",  &b_hasBadJet,    "hasBadJet/S");
495  tWeiZ->Branch("isEleEvent", &b_isEleEvent,  "isEleEvent/S");
496  tWeiZ->Branch("RunNumber",  &b_RunNumber,    "RunNumber/I");
497  gROOT->cd();
498
499  int countB = 0;
500  for (int ifi = 0; ifi < tAllZ->GetEntries(); ifi++){
501    countB++;
502    tAllZ->GetEntry(ifi);
503    double mt = tAllZ->GetLeaf("mtophad")->GetValue();
504    double ht = tAllZ->GetLeaf("HT")->GetValue();
505    b_mtophad = mt;
506    b_HT = ht;
507
508    //if (mt<250 || ht<620) continue;
509    if (ifi%1000==0) cout << "Reading event " << ifi << " from AllZ tree" << endl;
510
511    TString currentFile = tAllZ->GetTree()->GetCurrentFile()->GetName();
512    b_hfor       = (short)tAllZ->GetLeaf("hfor")->GetValue();
513    for (int i = 0; i < 78; i++){
514      double kfac = 1, ksE = 1, ksM = 1;
515      if (i>=40 && i<=69) {kfac = 1.25;}//Zjets
516
517      if (fname[i]==currentFile)
518        b_wei = Wei[i]*(tAllZ->GetLeaf("WeiEvent")->GetValue())*WJet_SF(b_hfor)*kfac*ksE*ksM;
519    }
520    b_cos1       = tAllZ->GetLeaf("cos_tlepCMtpair")->GetValue();
521    b_cos2       = tAllZ->GetLeaf("cosWqq")->GetValue();
522    b_MinLep1    = tAllZ->GetLeaf("MinLep1")->GetValue();           
523    b_isEleEvent = (short)tAllZ->GetLeaf("isEleEvent")->GetValue();
524    b_hasBadJet  = (short)tAllZ->GetLeaf("hasBadJet")->GetValue();
525    b_RunNumber  = (int)tAllZ->GetLeaf("RunNumber_ana")->GetValue();
526    tWeiZ->Fill();
527  }
528
529  fAllZ->cd();
530  tWeiZ->Write();
531  fAllZ->Close();
532
533  //##############################################
534  //**************** File QCD  *******************
535  //##############################################
536  TFile *fQCD   = new TFile("res_QCD"+ver+".root","RECREATE");
537
538  TTree *tWeiQCD   = new TTree("T","T");
539  tWeiQCD->Branch("wei",        &b_wei,               "wei/F");
540  tWeiQCD->Branch("mtophad",    &b_mtophad,        "mtophad/F");
541  tWeiQCD->Branch("HT",         &b_HT,                  "HT/F");
542  tWeiQCD->Branch("cos1",       &b_cos1,              "cos1/F");
543  tWeiQCD->Branch("cos2",       &b_cos2,              "cos2/F");
544  tWeiQCD->Branch("MinLep1",    &b_MinLep1,        "MinLep1/F");
545  tWeiQCD->Branch("hfor",       &b_hfor,              "hfor/S");
546  tWeiQCD->Branch("hasBadJet",  &b_hasBadJet,    "hasBadJet/S");
547  tWeiQCD->Branch("isEleEvent", &b_isEleEvent,  "isEleEvent/S");
548  tWeiQCD->Branch("RunNumber",  &b_RunNumber,    "RunNumber/I");
549  gROOT->cd();
550
551  int countB = 0;
552  for (int ifi = 0; ifi < tQCD->GetEntries(); ifi++){
553    countB++;
554    tQCD->GetEntry(ifi);
555    double mt = tQCD->GetLeaf("mtophad")->GetValue();
556    double ht = tQCD->GetLeaf("HT")->GetValue();
557    b_mtophad = mt;
558    b_HT = ht;
559
560    //if (mt<250 || ht<620) continue;
561    if (ifi%1000==0) cout << "Reading event " << ifi << " from QCD tree" << endl;
562
563    TString currentFile = tQCD->GetTree()->GetCurrentFile()->GetName();
564    for (int i = 0; i < 78; i++){
565      if (fname[i]==currentFile)
566        b_wei = Wei[i]*(tQCD->GetLeaf("WeiEvent")->GetValue());
567    }
568    b_cos1       = tQCD->GetLeaf("cos_tlepCMtpair")->GetValue();
569    b_hfor       = (short)tQCD->GetLeaf("hfor")->GetValue();
570    b_cos2       = tQCD->GetLeaf("cosWqq")->GetValue();
571    b_MinLep1    = tQCD->GetLeaf("MinLep1")->GetValue();           
572    b_isEleEvent = (short)tQCD->GetLeaf("isEleEvent")->GetValue();
573    b_hasBadJet  = (short)tQCD->GetLeaf("hasBadJet")->GetValue();
574    b_RunNumber  = (int)tQCD->GetLeaf("RunNumber_ana")->GetValue();
575    tWeiQCD->Fill();
576  }
577
578  fQCD->cd();
579  tWeiQCD->Write();
580  fQCD->Close();
581
582}
Note: See TracBrowser for help on using the repository browser.