susy_cfa  b611ccad937ea179f86a1f5663960264616c0a20
lepton_study.cxx
Go to the documentation of this file.
1 #include "lepton_study.hpp"
2 
3 #include <vector>
4 #include <string>
5 #include <stdexcept>
6 
7 #include "TH2D.h"
8 #include "TH1D.h"
9 #include "TFile.h"
10 #include "TChain.h"
11 #include "TCanvas.h"
12 #include "TLegend.h"
13 #include "TMarker.h"
14 
15 #include "utilities.hpp"
16 #include "styles.hpp"
17 
18 using namespace std;
19 
20 int main(){
21  styles style("Standard");
22  style.setDefaultStyle();
23 
24  TChain ttbar("tree");
25  ttbar.Add("archive/ra4skim/small_TT_*.root");
26  TChain t1tttt("tree");
27  t1tttt.Add("archive/ra4skim/small*SMS*T1tttt*PU20*.root");
28 
29 
30  DrawROC(ttbar, t1tttt, "el");
31  DrawROC(ttbar, t1tttt, "el",1);
32  DrawROC(ttbar, t1tttt, "el",2);
33  DrawROC(ttbar, t1tttt, "el",3);
34  DrawROC(ttbar, t1tttt, "el",4);
35 
36  DrawROC(ttbar, t1tttt, "mu");
37  DrawROC(ttbar, t1tttt, "mu",1);
38  DrawROC(ttbar, t1tttt, "mu",2);
39  DrawROC(ttbar, t1tttt, "mu",3);
40  DrawROC(ttbar, t1tttt, "mu",4);
41 
42  //DrawScat(chain, "ttbar", "el", true);
43  //DrawScat(chain, "ttbar", "el", false);
44  //DrawScat(chain, "ttbar", "mu", true);
45  //DrawScat(chain, "ttbar", "mu", false);
46 }
47 
48 void DrawROC(TChain &ttbar, TChain &t1tttt, const string &lep, int pt_bin){
49  const unsigned nbins = 1000;
50  const double reliso_low = 0.0, reliso_high = 1.0;
51  const double ptrel_low = 0.0, ptrel_high = 100.0;
52  const double ptrel_25_low = 0.0, ptrel_25_high = 100.0;
53 
54  TH1D reliso_good("reliso_good","", nbins, reliso_low, reliso_high);
55  TH1D reliso_bad("reliso_bad","", nbins, reliso_low, reliso_high);
56  TH1D ptrel_good("ptrel_good","",nbins, ptrel_low, ptrel_high);
57  TH1D ptrel_bad("ptrel_bad","",nbins, ptrel_low, ptrel_high);
58  TH1D ptrel_25_good("ptrel_25_good","",nbins, ptrel_25_low, ptrel_25_high);
59  TH1D ptrel_25_bad("ptrel_25_bad","",nbins, ptrel_25_low, ptrel_25_high);
60  TH1D miniso_good("miniso_good","",nbins, reliso_low, reliso_high);
61  TH1D miniso_bad("miniso_bad","",nbins, reliso_low, reliso_high);
62  TH1D miniso_ch_good("miniso_ch_good","",nbins, reliso_low, reliso_high);
63  TH1D miniso_ch_bad("miniso_ch_bad","",nbins, reliso_low, reliso_high);
64 
65  string full_lep = "Lepton";
66  if(lep=="mu"){
67  full_lep = "Muon";
68  }else if(lep=="el"){
69  full_lep = "Electron";
70  }
71 
72  string pt_cut, pt_title, pt_file;
73  switch(pt_bin){
74  default:
75  case 0:
76  pt_cut = lep+"s_pt>20";
77  pt_title = "p_{T}^{"+lep+"}>20";
78  pt_file = "20_inf";
79  break;
80  case 1:
81  pt_cut = lep+"s_pt>20&&"+lep+"s_pt<50";
82  pt_title = "20<p_{T}^{"+lep+"}<50";
83  pt_file = "20_50";
84  break;
85  case 2:
86  pt_cut = lep+"s_pt>50&&"+lep+"s_pt<100";
87  pt_title = "50<p_{T}^{"+lep+"}<100";
88  pt_file = "50_100";
89  break;
90  case 3:
91  pt_cut = lep+"s_pt>100&&"+lep+"s_pt<200";
92  pt_title = "100<p_{T}^{"+lep+"}<200";
93  pt_file = "100_200";
94  break;
95  case 4:
96  pt_cut = lep+"s_pt>200";
97  pt_title = "p_{T}^{"+lep+"}>200";
98  pt_file = "200_inf";
99  break;
100  }
101 
102  string good_denom_cut = lep+"s_tru_tm&&"+lep+"s_sigid&&"+pt_cut;
103  if(lep=="el") good_denom_cut += "&&els_ispf";
104  string bad_denom_cut = "!"+good_denom_cut;
105  t1tttt.Project("reliso_good",
106  (lep+"s_reliso").c_str(),
107  good_denom_cut.c_str());
108  ttbar.Project("reliso_bad",
109  (lep+"s_reliso").c_str(),
110  bad_denom_cut.c_str());
111  t1tttt.Project("ptrel_good",
112  (lep+"s_ptrel_0").c_str(),
113  good_denom_cut.c_str());
114  ttbar.Project("ptrel_bad",
115  (lep+"s_ptrel_0").c_str(),
116  bad_denom_cut.c_str());
117  t1tttt.Project("ptrel_25_good",
118  (lep+"s_ptrel_rem_0+("+lep+"s_ptrel_rem_0<0)*9999.").c_str(),
119  good_denom_cut.c_str());
120  ttbar.Project("ptrel_25_bad",
121  (lep+"s_ptrel_rem_0+("+lep+"s_ptrel_rem_0<0)*9999.").c_str(),
122  bad_denom_cut.c_str());
123  t1tttt.Project("miniso_good",
124  (lep+"s_miniso_tr07").c_str(),
125  good_denom_cut.c_str());
126  ttbar.Project("miniso_bad",
127  (lep+"s_miniso_tr07").c_str(),
128  bad_denom_cut.c_str());
129  t1tttt.Project("miniso_ch_good",
130  (lep+"s_miniso_tr07_ch").c_str(),
131  good_denom_cut.c_str());
132  ttbar.Project("miniso_ch_bad",
133  (lep+"s_miniso_tr07_ch").c_str(),
134  bad_denom_cut.c_str());
135 
136  double good_count, bad_count ,junk;
137  get_count_and_uncertainty(t1tttt, good_denom_cut, good_count, junk);
138  get_count_and_uncertainty(ttbar, bad_denom_cut, bad_count, junk);
139 
140  double good_num, bad_num;
141  if(lep=="el"){
143  (good_denom_cut+"&&((abs(els_eta)<=1.479&&els_reliso<0.2179)||abs(els_eta)>1.479&&els_reliso<0.254)"),
144  good_num, junk);
146  (bad_denom_cut+"&&!((abs(els_eta)<=1.479&&els_reliso<0.2179)||abs(els_eta)>1.479&&els_reliso<0.254)"),
147  bad_num, junk);
148  }else{
150  (good_denom_cut+"&&(mus_reliso<0.12)"),
151  good_num, junk);
153  (bad_denom_cut+"&&!(mus_reliso<0.12)"),
154  bad_num, junk);
155  }
156  TMarker marker(good_num/good_count, bad_num/bad_count, 29);
157  marker.SetMarkerSize(5);
158 
159  TGraph reliso = MakeROC(reliso_good, reliso_bad, true, good_count, bad_count);
160  TGraph ptrel = MakeROC(ptrel_good, ptrel_bad, false, good_count, bad_count);
161  TGraph ptrel_25 = MakeROC(ptrel_25_good, ptrel_25_bad, false, good_count, bad_count);
162  TGraph miniso = MakeROC(miniso_good, miniso_bad, true, good_count, bad_count);
163  TGraph miniso_ch = MakeROC(miniso_ch_good, miniso_ch_bad, true, good_count, bad_count);
164 
165  reliso.SetLineColor(1); reliso.SetLineWidth(4);
166  ptrel.SetLineColor(2); ptrel.SetLineWidth(4);
167  ptrel_25.SetLineColor(3); ptrel_25.SetLineWidth(4);
168  miniso.SetLineColor(4); miniso.SetLineWidth(4);
169  miniso_ch.SetLineColor(6); miniso_ch.SetLineWidth(4);
170 
171  TH1D dumb("","",1,0.5,1.0);
172  dumb.SetTitle((pt_title+";Truth Matched Prompt "
173  +full_lep
174  +" Efficiency;Non-Prompt "
175  +full_lep
176  +" Rejection Rate").c_str());
177  dumb.SetMinimum(0.0);
178  dumb.SetMaximum(1.0);
179 
180  TCanvas canvas;
181  dumb.Draw();
182  reliso.Draw("lsame");
183  ptrel.Draw("lsame");
184  ptrel_25.Draw("lsame");
185  miniso.Draw("lsame");
186  miniso_ch.Draw("lsame");
187  marker.Draw("same");
188 
189  TLegend leg(0.1,0.12,0.25,0.62);
190  leg.SetFillStyle(0);
191  leg.SetFillColor(0);
192  leg.SetBorderSize(0);
193  leg.SetTextSize(0.05);
194  leg.AddEntry(&reliso, "Rel. Iso.", "l");
195  leg.AddEntry(&miniso, "Mini Iso. Tr., kt = 15 GeV", "l");
196  leg.AddEntry(&miniso_ch, "Mini Iso. Tr., kt = 15 GeV (ch. only)", "l");
197  leg.AddEntry(&ptrel, "p_{T}^{rel}", "l");
198  leg.AddEntry(&ptrel_25, "p_{T}^{rel} || Isolated", "l");
199  leg.Draw("same");
200  canvas.Print(("eps/roc_"+lep+"_"+pt_file+".eps").c_str());
201 }
202 
203 TGraph MakeROC(TH1D &good, TH1D &bad, const bool less_is_better,
204  double good_count, double bad_count){
205  const int nbins = good.GetNbinsX();
206  if(bad.GetNbinsX() != nbins) throw logic_error("Mismatched number of bins");
207 
208  TGraph graph(0);
209  const double good_tot = (good_count<=0.0)?good.Integral(0, nbins+1):good_count;
210  const double bad_tot = (bad_count<=0.0)?bad.Integral(0, nbins+1):bad_count;
211  if(less_is_better){
212  for(int bin = nbins+1; bin>=0; --bin){
213  const double good_pass = good.Integral(0, bin);
214  const double bad_pass = bad.Integral(0, bin);
215  const double x = good_pass/good_tot;
216  const double y = 1.0-bad_pass/bad_tot;
217  AddPoint(graph, x, y);
218  }
219  }else{
220  for(int bin = 0; bin<=nbins+1; ++bin){
221  const double good_pass = good.Integral(bin,nbins+1);
222  const double bad_pass = bad.Integral(bin, nbins+1);
223  const double x = good_pass/good_tot;
224  const double y = 1.0-bad_pass/bad_tot;
225  AddPoint(graph, x, y);
226  }
227  }
228 
229  return graph;
230 }
231 
232 void DrawScat(TChain &chain, const string &sample,
233  const string &lep, const bool truth_match){
234  const unsigned reliso_nbins = 100, ptrel_nbins = 100;
235  const double reliso_low = 0.0, reliso_high = 2.0;
236  const double ptrel_low = 0.0, ptrel_high = 50.0;
237 
238  string title_samp = "";
239  if(sample=="susy") title_samp = "T1tttt(1200,800)";
240  else if(sample=="ttbar") title_samp = "ttbar";
241 
242  string title_lep = "Lepton";
243  if(lep=="mu") title_lep = "Muon";
244  else if(lep=="el") title_lep = "Electron";
245 
246  string title_truth_match = truth_match?"Truth-Matched":"Anti-Truth-Matched";
247 
248  string title = title_samp+" "+title_truth_match+" "+title_lep;
249 
250  TH2D scat("scat", (title+";Rel. Iso.;p_{T}^{rel}").c_str(),
251  reliso_nbins, reliso_low, reliso_high,
252  ptrel_nbins, ptrel_low, ptrel_high);
253 
254  chain.Project("scat", (lep+"s_ptrel:"+lep+"s_reliso").c_str(),
255  ((truth_match?"":"!")+lep+"s_tru_tm").c_str());
256 
257  TCanvas canvas;
258  scat.Draw();
259  canvas.Print(("eps/scat_"
260  +sample+"_"+lep+"_"+(truth_match?"good":"bad")
261  +"_ptrel_vs_reliso.eps").c_str());
262 }
int main()
void AddPoint(TGraph &graph, const double x, const double y)
Definition: utilities.cpp:330
void setDefaultStyle()
Definition: styles.cpp:36
void get_count_and_uncertainty(TTree &tree, const std::string &cut, double &count, double &uncertainty)
Definition: utilities.cpp:320
STL namespace.
void DrawROC(TChain &ttbar, TChain &t1tttt, const string &lep, int pt_bin)
void DrawScat(TChain &chain, const string &sample, const string &lep, const bool truth_match)
TGraph MakeROC(TH1D &good, TH1D &bad, const bool less_is_better, double good_count, double bad_count)