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

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

MakeFakeData with weight for trees contains scale factor for flavour fractions

File size: 20.3 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 = "NEW";
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 Signal  ***********
144  //###################################
145
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");
168  gROOT->cd();
169 
170  int countS = 0;
171  for (int ifi = 0; ifi < tSig->GetEntries(); ifi++){
172    countS++;
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; 
178    if (ifi%1000==0) cout << "Reading event " << ifi << " from Signal tree" << endl;
179
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
191    tWeiS->Fill();
192  }
193
194  fSig->cd();
195  tWeiS->Write();
196  fSig->Close();
197
198  //##############################################
199  //*************** File AllBkg  *****************
200  //##############################################
201  TFile *fAllBkg; 
202  if (s2[1]=="105200"){
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");
226  gROOT->cd();
227
228  int countB = 0;
229  for (int ifi = 0; ifi < tAllBkg->GetEntries(); ifi++){
230    countB++;
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; 
238    if (ifi%1000==0) cout << "Reading event " << ifi << " from AllBkg tree" << endl;
239
240    TString currentFile = tAllBkg->GetTree()->GetCurrentFile()->GetName();
241    b_hfor       = (short)tAllBkg->GetLeaf("hfor")->GetValue();
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
247      if (fname[i]==currentFile)
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();
256    tWeiB->Fill();
257  }
258
259  fAllBkg->cd();
260  tWeiB->Write();
261  fAllBkg->Close();
262
263
264  //##############################################
265  //***************** File Top  ******************
266  //##############################################
267  TFile *fTop; 
268  if (s2[1]=="105200"){
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;
295  for (int ifi = 0; ifi < tTop->GetEntries(); ifi++){
296    countB++;
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; 
304    if (ifi%1000==0) cout << "Reading event " << ifi << " from Top tree" << endl;
305
306    TString currentFile = tTop->GetTree()->GetCurrentFile()->GetName();
307    for (int i = 0; i < 78; i++){
308      if (fname[i]==currentFile)
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();
318    tWeiT->Fill();
319  }
320
321  fTop->cd();
322  tWeiT->Write();
323  fTop->Close();
324
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;
344  for (int ifi = 0; ifi < tAllW->GetEntries(); ifi++){
345    countB++;
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; 
353    if (ifi%1000==0) cout << "Reading event " << ifi << " from AllW tree" << endl;
354
355    TString currentFile = tAllW->GetTree()->GetCurrentFile()->GetName();
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();
408    for (int i = 0; i < 78; i++){
409      if (fname[i]==currentFile)
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();
509    for (int i = 0; i < 78; i++){
510      if (fname[i]==currentFile)
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();
520    tWeiQCD->Fill();
521  }
522
523  fQCD->cd();
524  tWeiQCD->Write();
525  fQCD->Close();
526
527}
Note: See TracBrowser for help on using the repository browser.