ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
plot_trigger_note.cxx
Go to the documentation of this file.
1 // plot_trigger: Plots for the trigger section of the RA4 note
2 
3 #include <iostream>
4 #include <vector>
5 
6 #include "TChain.h"
7 #include "TH1D.h"
8 #include "TCanvas.h"
9 #include "TLegend.h"
10 #include "TLine.h"
11 #include "TString.h"
12 #include "TGraphAsymmErrors.h"
13 
14 #include "styles.hpp"
15 #include "utilities.hpp"
16 #include "utilities_macros.hpp"
17 
18 using namespace std;
19 using std::cout;
20 using std::endl;
21 
22 int main(){
23 
24  TString folders[] ={"/net/cms2/cms2r0/manuelf/root/small/hlt/15-04-01/el15/",
25  "/net/cms2/cms2r0/manuelf/root/small/hlt/15-04-01/mu15/"};
26  TString folder_offline="/cms5r0/ald77/archive/2015_05_10/";
27  TString leptag[] = {"electron", "muon"};
28  vector<TString> s_t1t[2], s_t1tc[2], s_tt[2], s_qcd[2], s_wjets[2];
29  vector<TString> s_t1t_offline;
30  s_t1t_offline.push_back(folder_offline+"*T1tttt*1500_*PU20*");
31  vector<TString> s_t1tc_offline;
32  s_t1tc_offline.push_back(folder_offline+"*T1tttt*1200_*PU20*");
33  vector<TString> s_tt_offline;
34  s_tt_offline.push_back(folder_offline+"*_TTJet*12.root");
35  s_tt_offline.push_back(folder_offline+"*_TTJet*11.root");
36 
37  vector<sfeats> Samples;
38  unsigned Nsam(0);
39  for(int lep(0); lep<2; lep++){
40  s_t1t[lep].push_back(folders[lep]+"*T1tttt*1500_*PU20*root");
41  s_t1tc[lep].push_back(folders[lep]+"*T1tttt*1200_*PU20*");
42  s_tt[lep].push_back(folders[lep]+"*TT_Tune*");
43  s_wjets[lep].push_back(folders[lep]+"*WTo*");
44  s_qcd[lep].push_back(folders[lep]+"*QCD_Pt*");
45 
46  Samples.push_back(sfeats(s_t1t[lep], "T1tttt(1500,100)", ra4::c_t1tttt));
47  Samples.push_back(sfeats(s_t1tc[lep], "T1tttt(1200,800)", ra4::c_t1tttt,2));
48  Samples.push_back(sfeats(s_tt[lep], "t#bar{t}", ra4::c_tt_1l));
49  //Samples.push_back(sfeats(s_wjets[lep], "W+jets", ra4::c_singlet));
50  Samples.push_back(sfeats(s_qcd[lep], "QCD", 1));
51  if(lep==0) Nsam = Samples.size();
52  }
53  Samples.push_back(sfeats(s_t1t_offline, "T1tttt(1500,100)", ra4::c_t1tttt));
54  Samples.push_back(sfeats(s_t1tc_offline, "T1tttt(1200,800)", ra4::c_t1tttt,2));
55  Samples.push_back(sfeats(s_tt_offline, "t#bar{t}", ra4::c_tt_1l,1));
56 
57  vector<int> all_sam[2], tt_t1[2], tt_t1_offline;
58  for(unsigned lep(0); lep<2; lep++){
59  for(unsigned iall(0); iall<Nsam; iall++) all_sam[lep].push_back(iall+lep*Nsam);
60  tt_t1[lep].push_back(0+lep*Nsam);
61  tt_t1[lep].push_back(1+lep*Nsam);
62  tt_t1[lep].push_back(2+lep*Nsam);
63  }
64  tt_t1_offline.push_back(2*Nsam+0);
65  tt_t1_offline.push_back(2*Nsam+1);
66  tt_t1_offline.push_back(2*Nsam+2);
67 
69  vector<hfeats> std_varis;
70  std_varis.push_back(hfeats("Max$(mus_pt)",60,0,300, tt_t1[1], "Leading #mu HLT p_{T} [GeV]",
71  "onht>350&&Sum$(genmus_pt>0)>=1",20,"muon"));
72  std_varis.push_back(hfeats("Max$(els_pt)",60,0,300, tt_t1[0], "Leading e HLT p_{T} [GeV]",
73  "onht>350&&Sum$(genels_pt>0)>=1",20,"electron"));
74  for(unsigned lep(0); lep<2; lep++){
75  std_varis.push_back(hfeats("onht",75,0,2500, all_sam[lep], "HLT H_{T} [GeV]",
76  "1",350,leptag[lep]));
77  std_varis.push_back(hfeats("onmet",65,0,650, all_sam[lep], "HLT MET [GeV]",
78  "1",-1,leptag[lep]));
79  }
80 
81  std_varis.push_back(hfeats("Max$(mc_pt*(abs(mc_id)==13))",60,0,300, tt_t1_offline, "Leading gen #mu p_{T} (GeV)",
82  "ht>350&&Sum$(abs(mc_id)==13)>=1",20,"muon"));
83  std_varis.push_back(hfeats("Max$(mc_pt*(abs(mc_id)==11))",60,0,300, tt_t1_offline, "Leading gen e p_{T} (GeV)",
84  "ht>350&&Sum$(abs(mc_id)==11)>=1",20,"electron"));
85 
86  TString filetype(".png"), namestyle("RA4");
87  bool do_mu(true);
88  //plot_distributions(Samples, std_varis, "10", filetype, namestyle);
89 
90 
92  styles style(namestyle); style.yTitleOffset = 1.;
93  style.setDefaultStyle();
94  TCanvas can;
95  TChain *chain[2];
96  TH1D* histo[2][20];
97  TString title, hname, totCut, pname;
98  for(unsigned lep(0); lep<2; lep++) {
99  chain[lep] = new TChain("tree");
100  chain[lep]->Add(s_t1tc[lep][0]);
101  }
102  vector<hfeats> vars;
103  // vars.push_back(hfeats("Max$(genmus_pt)",20,25,35, tt_t1[1], "True muon max p_{T} [GeV]",
104  // "Sum$(genmus_pt>0)>=1",30,"Max$(mus_pt)"));
105  vars.push_back(hfeats("genmet",40,0,400, tt_t1[1], "True MET [GeV]", "1",70,"onmet"));
106  vars.push_back(hfeats("genmet",40,0,400, tt_t1[1], "True MET [GeV]", "1",100,"onmet"));
107  vars.push_back(hfeats("genmet",40,0,400, tt_t1[1], "True MET [GeV]", "1",170,"onmet"));
108  vars.push_back(hfeats("genht",85,200,1050, tt_t1[1], "True H_{T} [GeV]", "1",350,"onht"));
109  vars.push_back(hfeats("genht",85,200,1050, tt_t1[1], "True H_{T} [GeV]", "1",400,"onht"));
110  vars.push_back(hfeats("genht",85,200,1050, tt_t1[1], "True H_{T} [GeV]", "1",600,"onht"));
111  for(unsigned var(0); var<vars.size(); var++){
112  title = cuts2title(vars[var].cuts);
113  for(unsigned his(0); his < 2; his++){
114  hname = "histo"; hname += var; hname += his;
115  totCut = vars[var].cuts;
116  if(his==1) {
117  totCut += ("&&"+vars[var].tagname+">");
118  totCut += vars[var].cut;
119  }
120  histo[his][var] = new TH1D(hname, title, vars[var].nbins, vars[var].minx, vars[var].maxx);
121  //cout<<var<<": hname "<<hname<<", cuts "<<totCut<<endl;
122  if(do_mu) chain[1]->Project(hname, vars[var].varname, totCut);
123  else chain[0]->Project(hname, vars[var].varname, totCut);
124  }
125  }
126 
127  unsigned Ncurves(3);
128  double legY(style.PadBottomMargin+0.02), legSingle = 0.06;
129  double legW = 0.13, legH = legSingle*Ncurves;
130  double legX1 = 0.58;
131  TLegend leg[2]; int nLegs(2);
132  for(int ileg(0); ileg<nLegs; ileg++){
133  leg[ileg].SetX1NDC(legX1); leg[ileg].SetX2NDC(legX1+legW);
134  leg[ileg].SetY1NDC(legY); leg[ileg].SetY2NDC(legY+legH);
135  leg[ileg].SetTextSize(style.LegendSize); leg[ileg].SetFillColor(0);
136  leg[ileg].SetFillStyle(0); leg[ileg].SetBorderSize(0);
137  leg[ileg].SetTextFont(style.nFont);
138  }
139  int colors[] = {1,4,2};
140  TString labtag[] = {"HLT MET > ", "HLT H_{T} > "}, label;
141  TGraphAsymmErrors heff[20];
142  for(unsigned type(0); type<2; type++){
143  for(unsigned ivar(0); ivar<Ncurves; ivar++){
144  unsigned var = ivar+Ncurves*type;
145  heff[var] = TGraphAsymmErrors(histo[1][var], histo[0][var]);
146  heff[var].SetMarkerStyle(20); heff[var].SetMarkerSize(0.9);
147  heff[var].SetMarkerColor(colors[ivar]); heff[var].SetLineColor(colors[ivar]);
148  if(ivar==0) {
149  heff[var].GetXaxis()->SetTitle(vars[var].title);
150  heff[var].GetYaxis()->SetTitle("Efficiency");
151  if(do_mu) heff[var].SetTitle("15 GeV #mu trigger");
152  else heff[var].SetTitle("15 GeV e trigger");
153  heff[var].Draw("ap");
154  } else heff[var].Draw("p same");
155  label = labtag[type]; label += vars[var].cut; label += " GeV";
156  leg[type].AddEntry(&heff[var],label,"pl");
157  } // Loop over curves in a plot
158  leg[type].Draw();
159  pname = "plots/1d/turnon_"+vars[Ncurves*type].varname+(do_mu?"_mu":"_el")+filetype;
160  can.SaveAs(pname);
161  }
162 
163 }
164 
void setDefaultStyle()
Definition: styles.cpp:36
TString cuts2title(TString title)
STL namespace.
float LegendSize
Definition: styles.hpp:35
int main()
float yTitleOffset
Definition: styles.hpp:35
int nFont
Definition: styles.hpp:33
float PadBottomMargin
Definition: styles.hpp:36