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

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

Add efficiency test folder

File size: 7.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];
34  double   e2[3][3][31];   
35  double   e3[3][3][31];   
36  double   e4[3][3][31];   
37  double   e5[3][3][31];   
38  double   e6[3][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    eB[3][31][6],    eS[3][31][6],    eD[3][31][6]; 
113  double eBErr[3][31][6], eSErr[3][31][6], eDErr[3][31][6]; 
114
115  for (int i = 0; i < 3; i++){
116    for (int j = 0; j < 31; j++){
117      //cout << "e1[" << i << "][0][" << j << "] " << e1[i][0][j];
118      //cout << " iTot[" << i << "][0][" << j << "] " << iTot[i][0][j] << endl;
119     
120      eB[i][j][0] = e1[i][0][j]/iTot[i][0][j];
121      eB[i][j][1] = e2[i][0][j]/iTot[i][0][j];
122      eB[i][j][2] = e3[i][0][j]/iTot[i][0][j];
123      eB[i][j][3] = e4[i][0][j]/iTot[i][0][j];
124      eB[i][j][4] = e5[i][0][j]/iTot[i][0][j];
125      eB[i][j][5] = e6[i][0][j]/iTot[i][0][j];
126
127      if (iTot[i][0][j]==0) { for (int k = 0; k < 6; k++) { eB[i][j][k] = 0; } }
128
129      eS[i][j][0] = e1[i][1][j]/iTot[i][1][j];
130      eS[i][j][1] = e2[i][1][j]/iTot[i][1][j];
131      eS[i][j][2] = e3[i][1][j]/iTot[i][1][j];
132      eS[i][j][3] = e4[i][1][j]/iTot[i][1][j];
133      eS[i][j][4] = e5[i][1][j]/iTot[i][1][j];
134      eS[i][j][5] = e6[i][1][j]/iTot[i][1][j];
135
136      if (iTot[i][1][j]==0) { for (int k = 0; k < 6; k++) { eS[i][j][k] = 0; } }
137     
138      eD[i][j][0] = e1[i][2][j]/iTot[i][2][j]; 
139      eD[i][j][1] = e2[i][2][j]/iTot[i][2][j]; 
140      eD[i][j][2] = e3[i][2][j]/iTot[i][2][j]; 
141      eD[i][j][3] = e4[i][2][j]/iTot[i][2][j]; 
142      eD[i][j][4] = e5[i][2][j]/iTot[i][2][j]; 
143      eD[i][j][5] = e6[i][2][j]/iTot[i][2][j]; 
144
145      if (iTot[i][2][j]==0) { for (int k = 0; k < 6; k++) { eD[i][j][k] = 0; } }
146     
147      //cout << "e1S[" << i << "][" << j << "] = " << e1S[i][j];
148      //cout << " iTot[" << i << "][1][" << j << "] = " << iTot[i][1][j] << endl;
149    }
150  }
151 
152  for (int i = 0; i < 3; i++){
153    for (int j = 0; j < 31; j++){
154      for (int k = 0; k < 6; k++){
155        eBErr[i][j][k] = sqrt(eB[i][j][k]*(1-eB[i][j][k])/iTot[i][0][j]);
156        eSErr[i][j][k] = sqrt(eS[i][j][k]*(1-eS[i][j][k])/iTot[i][1][j]);
157        eDErr[i][j][k] = sqrt(eD[i][j][k]*(1-eD[i][j][k])/iTot[i][2][j]);
158      }
159    }
160  }
161
162  TH2F *frame1 =  new TH2F("Frame1", "", 31, 200, 500, 1000, 0.001, 1);
163  frame1->SetStats(0);
164  TH2F *frame2 =  new TH2F("Frame2", "", 31, 200, 500, 1000, 0.001, 1);
165  frame2->SetStats(0);
166  TH2F *frame3 =  new TH2F("Frame3", "", 31, 200, 500, 1000, 0.001, 1);
167  frame3->SetStats(0);
168
169  TLegend *legend = new TLegend(0.3,0.6,0.7,0.75);
170  legend->SetBorderSize(0);
171  legend->SetFillColor(0);
172
173  TString name = "";
174  TString region[3] = {"region1","region2","region3"};
175  TString cat[6] = {"cat1","cat2","cat3","cat4","cat5","cat6"};
176
177  TGraphErrors *heffB[3][6];
178  TGraphErrors *heffS[3][6];
179  TGraphErrors *heffD[3][6];
180
181  for (int i = 0; i < 3; i++){
182    for (int j = 0; j < 6; j++){
183      double eff[31]; 
184      double effErr[31];
185
186      name = "heffB"; name += region[i]; name += cat[j];
187      for (int ic = 0; ic < 31; ic++) { 
188        eff[ic]    = eB[i][ic][j];
189        effErr[ic] = eBErr[i][ic][j];
190      }
191      heffB[i][j] = new TGraphErrors(31, mjjj, eff, mjjjErr, effErr);
192      heffB[i][j]->SetLineColor(4);
193     
194      name = "heffS"; name += region[i]; name += cat[j];
195      for (int ic = 0; ic < 31; ic++) { 
196        eff[ic]    = eS[i][ic][j];
197        effErr[ic] = eSErr[i][ic][j];
198      }
199      heffS[i][j] = new TGraphErrors(31, mjjj, eff, mjjjErr, effErr);
200      heffS[i][j]->SetLineColor(2);
201     
202      name = "heffD"; name += region[i]; name += cat[j];
203      for (int ic = 0; ic < 31; ic++) { 
204        eff[ic]    = eD[i][ic][j];
205        effErr[ic] = eDErr[i][ic][j];
206      }
207      heffD[i][j] = new TGraphErrors(31, mjjj, eff, mjjjErr, effErr);
208    }
209  }
210
211  legend->AddEntry(heffB[0][1],"BkgMC");
212  legend->AddEntry(heffS[0][1],"SigMC");
213  legend->AddEntry(heffD[0][1],"Data");
214
215  TCanvas *c[6];
216  for (int i = 0; i < 6; i++){
217    name = "Cat"; name += (i+1);
218    c[i] = new TCanvas(name, name, 1000, 400);
219    c[i]->Divide(3);
220
221    c[i]->cd(1);
222    name += ": mt>250 && HT>620";
223    frame1->SetTitle(name);
224    frame1->Draw();
225    heffB[0][i]->Draw("LP");
226    heffS[0][i]->Draw();
227    heffD[0][i]->Draw();
228    legend->Draw("same");
229
230    c[i]->cd(2);
231    name = "mt>200 && HT>500 && HT<620";
232    frame2->SetTitle(name);
233    frame2->Draw();
234    heffB[1][i]->Draw("LP");
235    heffS[1][i]->Draw();
236    heffD[1][i]->Draw();
237    legend->Draw("same");
238
239    c[i]->cd(3);
240    name = "mt>200 && mt<250 && HT>620";
241    frame3->SetTitle(name);
242    frame3->Draw();
243    heffB[2][i]->Draw("LP");
244    heffS[2][i]->Draw();
245    heffD[2][i]->Draw();
246    legend->Draw("same");
247
248    name = "Cat"; name += (i+1); name += ".eps";
249    c[i]->Print(name);
250  }
251
252  //********************************************
253
254  //TCanvas *cN = new TCanvas("cN", "", 500, 400);
255  //TGraph *hB = new TGraph(31, mjjj, N1);
256  //hB->Draw("ALP");
257}
Note: See TracBrowser for help on using the repository browser.