source: huonglan/SPLOT/NEWREALEASE/EFFICIENCY/EfficiencyDependOnCut_saved.C @ 21

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

Add efficiency test folder

File size: 9.2 KB
Line 
1#include <TFile.h>
2#include <TH2F.h>
3#include <TTree.h>
4#include <TLeaf.h>
5#include <TChain.h>
6#include <TString.h>
7#include <TGraphErrors.h>
8#include <TGraph.h>
9#include <TCanvas.h>
10#include <TLegend.h>
11#include <TROOT.h>
12
13#include <iostream>
14
15using namespace std;
16
17void EfficiencyDependOnCut(){
18  TTree *t[3];
19
20  TFile *fB = TFile::Open("./MERGEFILES/TESTEFFICIENCY/res_AllBkg.root");
21  t[0] = (TTree*)fB->Get("T");
22
23  TFile *fS = TFile::Open("./MERGEFILES/TESTEFFICIENCY/res_Signal.root");
24  t[1] = (TTree*)fS->Get("T");
25
26  TFile *fD = TFile::Open("/exp/atlas/huonglan/DATA2011/resData.root");
27  t[2] = (TTree*)fD->Get("T");
28
29  double Cut1 = 0.7;
30  double Cut2 = 0.7;
31  double Cut3 = 48;
32
33  double   e1[3][3][31];   double   e1B[3][31],  e1S[3][31], e1D[3][31]; 
34  double   e2[3][3][31];   double   e2B[3][31],  e2S[3][31], e2D[3][31]; 
35  double   e3[3][3][31];   double   e3B[3][31],  e3S[3][31], e3D[3][31]; 
36  double   e4[3][3][31];   double   e4B[3][31],  e4S[3][31], e4D[3][31]; 
37  double   e5[3][3][31];   double   e5B[3][31],  e5S[3][31], e5D[3][31]; 
38  double   e6[3][3][31];   double   e6B[3][31],  e6S[3][31], e6D[3][31]; 
39  double iTot[3][3][31];
40
41  for (int k = 0; k < 3; k++){
42    for (int i = 0; i < 3; i++){
43      for (int j = 0; j < 31; j++){
44        iTot[k][i][j] =0 ;
45        e1[k][i][j] = 0;
46        e2[k][i][j] = 0;
47        e3[k][i][j] = 0;
48        e4[k][i][j] = 0;
49        e5[k][i][j] = 0;
50        e6[k][i][j] = 0;
51      }
52    }
53  }
54
55  double mjjj[31]; for (int i = 0; i < 31; i++) { mjjj[i] = 200 + i*10;}
56  double mjjjErr[31]; for (int i = 0; i < 31; i++) { mjjjErr[i] = 0;}
57
58  for (int i = 0; i < 3; i++){
59    int nevt = t[i]->GetEntries();
60    for (int iev = 0; iev < nevt; iev++) {
61      t[i]->GetEntry(iev);
62
63      //cout << "iev " << iev << endl;
64      double wei = 1;
65      double cos1 = 1, cos2 = 1;
66
67      double mt   = t[i]->GetLeaf("mtophad")->GetValue();
68      double ht   = t[i]->GetLeaf("HT")->GetValue();
69      if (i==0||i==1) {
70        wei  = t[i]->GetLeaf("wei")->GetValue();
71        cos1 = fabs(t[i]->GetLeaf("cos1")->GetValue());
72        cos2 = fabs(t[i]->GetLeaf("cos2")->GetValue());
73      } else if (i==2){
74        cos1 = fabs(t[i]->GetLeaf("cos_tlepCMtpair")->GetValue());
75        cos2 = fabs(t[i]->GetLeaf("cosWqq")->GetValue());
76      }
77      double dM   = t[i]->GetLeaf("MinLep1")->GetValue();
78
79      int it = -1;
80      if (ht>620 && mt>200)           it = 0;
81      if (ht>500 && ht<620 && mt>200) it = 1;
82      if (ht>620 && mt>200 && mt<250) it = 2;
83
84      if (it==-1) continue;
85      //cout << "mt " << mt << " ht " << ht << " it " << it << endl;
86
87      for (int j = 0; j < 31; j++){
88        double mtCut = mjjj[j];
89
90        //cout << "mtCut " << mtCut << endl;
91         
92        if (mt>mtCut){
93          iTot[it][i][j] += wei;
94         
95          if (cos1<Cut1 && cos2<Cut2){
96            if (dM<Cut3) e1[it][i][j] += wei;
97            if (dM>Cut3) e2[it][i][j] += wei;
98          }
99          else if (cos1>Cut1 && cos2>Cut2){
100            if (dM<Cut3) e3[it][i][j] += wei;
101            if (dM>Cut3) e4[it][i][j] += wei;
102          }
103          else if ((cos1>Cut1 && cos2<Cut2) || (cos1<Cut1 && cos2>Cut2)){
104            if (dM<Cut3) e5[it][i][j] += wei;
105            if (dM>Cut3) e6[it][i][j] += wei;
106          }
107        }
108      }
109    }
110  }
111
112  double   e1BErr[3][31];    double   e1DErr[3][31]; 
113  double   e2BErr[3][31];    double   e2DErr[3][31]; 
114  double   e3BErr[3][31];    double   e3DErr[3][31]; 
115  double   e4BErr[3][31];    double   e4DErr[3][31]; 
116  double   e5BErr[3][31];    double   e5DErr[3][31]; 
117  double   e6BErr[3][31];    double   e6DErr[3][31]; 
118
119  for (int i = 0; i < 3; i++){
120    for (int j = 0; j < 31; j++){
121      //cout << "e1[" << i << "][0][" << j << "] " << e1[i][0][j];
122      //cout << " iTot[" << i << "][0][" << j << "] " << iTot[i][0][j] << endl;
123     
124      e1B[i][j] = e1[i][0][j]/iTot[i][0][j];
125      e2B[i][j] = e2[i][0][j]/iTot[i][0][j];
126      e3B[i][j] = e3[i][0][j]/iTot[i][0][j];
127      e4B[i][j] = e4[i][0][j]/iTot[i][0][j];
128      e5B[i][j] = e5[i][0][j]/iTot[i][0][j];
129      e6B[i][j] = e6[i][0][j]/iTot[i][0][j];
130
131      if (iTot[i][0][j]==0) { e1B[i][j] = 0; e2B[i][j] = 0; e3B[i][j] = 0; e4B[i][j] = 0; e5B[i][j] = 0; e6B[i][j] = 0; }
132
133      e1S[i][j] = e1[i][1][j]/iTot[i][1][j];
134      e2S[i][j] = e2[i][1][j]/iTot[i][1][j];
135      e3S[i][j] = e3[i][1][j]/iTot[i][1][j];
136      e4S[i][j] = e4[i][1][j]/iTot[i][1][j];
137      e5S[i][j] = e5[i][1][j]/iTot[i][1][j];
138      e6S[i][j] = e6[i][1][j]/iTot[i][1][j];
139
140      if (iTot[i][1][j]==0) { e1S[i][j] = 0; e2S[i][j] = 0; e3S[i][j] = 0; e4S[i][j] = 0; e5S[i][j] = 0; e6S[i][j] = 0; }
141     
142      e1D[i][j] = e1[i][2][j]/iTot[i][2][j]; 
143      e2D[i][j] = e2[i][2][j]/iTot[i][2][j]; 
144      e3D[i][j] = e3[i][2][j]/iTot[i][2][j]; 
145      e4D[i][j] = e4[i][2][j]/iTot[i][2][j]; 
146      e5D[i][j] = e5[i][2][j]/iTot[i][2][j]; 
147      e6D[i][j] = e6[i][2][j]/iTot[i][2][j]; 
148
149      if (iTot[i][2][j]==0) { e1D[i][j] = 0; e2D[i][j] = 0; e3D[i][j] = 0; e4D[i][j] = 0; e5D[i][j] = 0; e6D[i][j] = 0; }
150     
151      //cout << "e1S[" << i << "][" << j << "] = " << e1S[i][j];
152      //cout << " iTot[" << i << "][1][" << j << "] = " << iTot[i][1][j] << endl;
153    }
154  }
155 
156  //double N0[31]; for (int i = 0; i < 31; i++) {N0[i] = iTot[0][i];}
157  //double N1[31]; for (int i = 0; i < 31; i++) {N1[i] = iTot[1][i];}
158
159  TH2F *frame =  new TH2F("Frame", "", 31, 200, 500, 1000, 0.001, 1);
160  frame->SetStats(0);
161
162  TLegend *legend = new TLegend(0.3,0.6,0.7,0.75);
163  legend->SetBorderSize(0);
164  legend->SetFillColor(0);
165
166  TString name = "";
167  TString type[3] = {"region1","region2","region3"};
168
169  TGraph *heff1B[3], *heff2B[3], *heff3B[3], *heff4B[3], *heff5B[3], *heff6B[3];
170  TGraph *heff1S[3], *heff2S[3], *heff3S[3], *heff4S[3], *heff5S[3], *heff6S[3];
171  TGraph *heff1D[3], *heff2D[3], *heff3D[3], *heff4D[3], *heff5D[3], *heff6D[3];
172
173  for (int i = 0; i < 3; i++){
174    double eff[31]; 
175
176    //Cat1
177    name = "heff1B"; name += type[i];
178    for (int j = 0; j < 31; j++) { eff[j] = e1B[i][j];}
179    heff1B[i] = new TGraph(31, mjjj, eff);
180    heff1B[i]->SetLineColor(4);
181
182    name = "heff1S"; name += type[i];
183    for (int j = 0; j < 31; j++) { eff[j] = e1S[i][j];}
184    heff1S[i] = new TGraph(31, mjjj, eff);
185    heff1S[i]->SetLineColor(2);
186
187    name = "heff1D"; name += type[i];
188    for (int j = 0; j < 31; j++) { eff[j] = e1D[i][j];}
189    heff1D[i] = new TGraph(31, mjjj, eff);
190
191    //Cat2
192    name = "heff2B"; name += type[i];
193    for (int j = 0; j < 31; j++) { eff[j] = e2B[i][j];}
194    heff2B[i] = new TGraph(31, mjjj, eff);
195    heff2B[i]->SetLineColor(4);
196
197    name = "heff2S"; name += type[i];
198    for (int j = 0; j < 31; j++) { eff[j] = e2S[i][j];}
199    heff2S[i] = new TGraph(31, mjjj, eff);
200    heff2S[i]->SetLineColor(2);
201
202    name = "heff2D"; name += type[i];
203    for (int j = 0; j < 31; j++) { eff[j] = e2D[i][j];}
204    heff2D[i] = new TGraph(31, mjjj, eff);
205
206    //Cat3
207    name = "heff3B"; name += type[i];
208    for (int j = 0; j < 31; j++) { eff[j] = e3B[i][j];}
209    heff3B[i] = new TGraph(31, mjjj, eff);
210    heff3B[i]->SetLineColor(4);
211
212    name = "heff3S"; name += type[i];
213    for (int j = 0; j < 31; j++) { eff[j] = e3S[i][j];}
214    heff3S[i] = new TGraph(31, mjjj, eff);
215    heff3S[i]->SetLineColor(2);
216
217    name = "heff3D"; name += type[i];
218    for (int j = 0; j < 31; j++) { eff[j] = e3D[i][j];}
219    heff3D[i] = new TGraph(31, mjjj, eff);
220
221    //Cat4
222    name = "heff4B"; name += type[i];
223    for (int j = 0; j < 31; j++) { eff[j] = e4B[i][j];}
224    heff4B[i] = new TGraph(31, mjjj, eff);
225    heff4B[i]->SetLineColor(4);
226
227    name = "heff4S"; name += type[i];
228    for (int j = 0; j < 31; j++) { eff[j] = e4S[i][j];}
229    heff4S[i] = new TGraph(31, mjjj, eff);
230    heff4S[i]->SetLineColor(2);
231
232    name = "heff4D"; name += type[i];
233    for (int j = 0; j < 31; j++) { eff[j] = e4D[i][j];}
234    heff4D[i] = new TGraph(31, mjjj, eff);
235
236    //Cat5
237    name = "heff5B"; name += type[i];
238    for (int j = 0; j < 31; j++) { eff[j] = e5B[i][j];}
239    heff5B[i] = new TGraph(31, mjjj, eff);
240    heff5B[i]->SetLineColor(4);
241
242    name = "heff5S"; name += type[i];
243    for (int j = 0; j < 31; j++) { eff[j] = e5S[i][j];}
244    heff5S[i] = new TGraph(31, mjjj, eff);
245    heff5S[i]->SetLineColor(2);
246
247    name = "heff5D"; name += type[i];
248    for (int j = 0; j < 31; j++) { eff[j] = e5D[i][j];}
249    heff5D[i] = new TGraph(31, mjjj, eff);
250
251    //Cat6
252    name = "heff6B"; name += type[i];
253    for (int j = 0; j < 31; j++) { eff[j] = e6B[i][j];}
254    heff6B[i] = new TGraph(31, mjjj, eff);
255    heff6B[i]->SetLineColor(4);
256
257    name = "heff6S"; name += type[i];
258    for (int j = 0; j < 31; j++) { eff[j] = e6S[i][j];}
259    heff6S[i] = new TGraph(31, mjjj, eff);
260    heff6S[i]->SetLineColor(2);
261
262    name = "heff6D"; name += type[i];
263    for (int j = 0; j < 31; j++) { eff[j] = e6D[i][j];}
264    heff6D[i] = new TGraph(31, mjjj, eff);
265  }
266
267  legend->AddEntry(heff1B[0],"BkgMC");
268  legend->AddEntry(heff1S[0],"SigMC");
269  legend->AddEntry(heff1D[0],"Data");
270
271  TCanvas *c[6];
272  for (int i = 0; i < 6; i++){
273    name = "c"; name += (i+1);
274    c[i] = new TCanvas(name, "", 1000, 400);
275    c[i]->Divide(3);
276
277    c[i]->cd(1);
278    frame->Draw();
279    heff1B[0]->Draw("LP");
280    heff1S[0]->Draw();
281    heff1D[0]->Draw();
282    legend->Draw("same");
283
284    c[i]->cd(2);
285    frame->Draw();
286    heff1B[1]->Draw("LP");
287    heff1S[1]->Draw();
288    heff1D[1]->Draw();
289    legend->Draw("same");
290
291    c[i]->cd(3);
292    frame->Draw();
293    heff1B[2]->Draw("LP");
294    heff1S[2]->Draw();
295    heff1D[2]->Draw();
296    legend->Draw("same");
297  }
298
299  //********************************************
300
301  //TCanvas *cN = new TCanvas("cN", "", 500, 400);
302  //TGraph *hB = new TGraph(31, mjjj, N1);
303  //hB->Draw("ALP");
304}
Note: See TracBrowser for help on using the repository browser.