ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
plot_twiki.cxx
Go to the documentation of this file.
1 // plot_dps: Macro that plots variables both for comissioning DPS
2 
3 #include <iostream>
4 #include <vector>
5 #include <ctime>
6 
7 #include "TChain.h"
8 #include "TH1D.h"
9 #include "TCanvas.h"
10 #include "TLegend.h"
11 #include "TLine.h"
12 #include "TString.h"
13 #include "TColor.h"
14 
15 #include "styles.hpp"
16 #include "utilities.hpp"
17 #include "utilities_macros.hpp"
18 
19 namespace {
20  TString minjets("6");
21  TString metcut("met>200");
22  TString minht("500");
23  TString luminosity="2.1"; // in ifb
24  TString plot_type=".pdf";
25  TString plot_style="CMSPaper";
26 }
27 
28 using namespace std;
29 
30 int main(){
31  time_t begtime, endtime;
32  time(&begtime);
33 
34  TString skim_1l = "skim_1lht500met200/", skim_dy = "skim_dy_ht300/";
35  TString skim_tt = "skim_ttdilep_ht300/", skim_had = "skim_qcd_njet10/";
36  TString foldermc = "/cms2r0/babymaker/babies/2015_11_28/mc/";
37  TString folderdata = "/cms2r0/babymaker/babies/2015_11_20/data/";
38 
39  TString foldermc_1l = foldermc+skim_1l;
40  TString folderdata_1l = folderdata+"singlelep/combined/"+skim_1l;
41  TString foldermc_dy = foldermc+skim_dy;
42  TString folderdata_dy = folderdata+"singlelep/combined/"+skim_dy;
43  TString foldermc_tt = foldermc+skim_tt;
44  TString folderdata_tt = folderdata+"singlelep/combined/"+skim_tt;
45  TString foldermc_had = foldermc+skim_had;
46  TString folderdata_had = folderdata+"hadronic/"+skim_had;
47 
49  vector<TString> s_trig_1l;
50  s_trig_1l.push_back(folderdata_1l+"/*Single*.root");
51 
52  vector<TString> s_tt_1l;
53  s_tt_1l.push_back(foldermc_1l+"*_TTJets*Lept*");
54  s_tt_1l.push_back(foldermc_1l+"*_TTJets_HT*");
55  vector<TString> s_wjets_1l;
56  s_wjets_1l.push_back(foldermc_1l+"*_WJetsToLNu*");
57  vector<TString> s_ttv_1l;
58  s_ttv_1l.push_back(foldermc_1l+"*_TTWJets*");
59  s_ttv_1l.push_back(foldermc_1l+"*_TTZTo*");
60  vector<TString> s_single_1l;
61  s_single_1l.push_back(foldermc_1l+"*_ST_*");
62  vector<TString> s_other_1l;
63  s_other_1l.push_back(foldermc_1l+"*DYJetsToLL*");
64  s_other_1l.push_back(foldermc_1l+"*_QCD_HT*");
65  s_other_1l.push_back(foldermc_1l+"*_ZJet*");
66  s_other_1l.push_back(foldermc_1l+"*_WWTo*");
67  s_other_1l.push_back(foldermc_1l+"*ggZH_HToBB*");
68  s_other_1l.push_back(foldermc_1l+"*ttHJetTobb*");
69  vector<TString> s_t1t_1l;
70  s_t1t_1l.push_back(foldermc_1l+"*T1tttt*1500_*");
71  vector<TString> s_t1tc_1l;
72  s_t1tc_1l.push_back(foldermc_1l+"*T1tttt*1200_*");
73 
75  vector<TString> s_trig_tt;
76  s_trig_tt.push_back(folderdata_tt+"/*Single*.root");
77 
78  vector<TString> s_tt_tt;
79  s_tt_tt.push_back(foldermc_tt+"*_TTJets*Lept*");
80  s_tt_tt.push_back(foldermc_tt+"*_TTJets_HT*");
81  vector<TString> s_wjets_tt;
82  s_wjets_tt.push_back(foldermc_tt+"*_WJetsToLNu*");
83  vector<TString> s_ttv_tt;
84  s_ttv_tt.push_back(foldermc_tt+"*_TTWJets*");
85  s_ttv_tt.push_back(foldermc_tt+"*_TTZTo*");
86  vector<TString> s_single_tt;
87  s_single_tt.push_back(foldermc_tt+"*_ST_*");
88  vector<TString> s_other_tt;
89  s_other_tt.push_back(foldermc_tt+"*DYJetsToLL*");
90  s_other_tt.push_back(foldermc_tt+"*_QCD_HT*");
91  s_other_tt.push_back(foldermc_tt+"*_ZJet*");
92  s_other_tt.push_back(foldermc_tt+"*_WWTo*");
93  s_other_tt.push_back(foldermc_tt+"*ggZH_HToBB*");
94  s_other_tt.push_back(foldermc_tt+"*ttHJetTobb*");
95  vector<TString> s_t1t_tt;
96  s_t1t_tt.push_back(foldermc_tt+"*T1tttt*1500_*");
97  vector<TString> s_t1tc_tt;
98  s_t1tc_tt.push_back(foldermc_tt+"*T1tttt*1200_*");
99 
101  vector<TString> s_trig_dy;
102  s_trig_dy.push_back(folderdata_dy+"/*Single*.root");
103 
104  vector<TString> s_DY;
105  s_DY.push_back(foldermc_dy+"*DYJetsToLL*");
106  vector<TString> s_tt_dl;
107  s_tt_dl.push_back(foldermc_dy+"*_TTJets*Lept*");
108  s_tt_dl.push_back(foldermc_dy+"*_TTJets_HT*");
109  vector<TString> s_singleDY;
110  s_singleDY.push_back(foldermc_dy+"*ST_*");
111  vector<TString> s_ttvDY; //negligible
112  s_ttvDY.push_back(foldermc_dy+"*_TTWJets*");
113  s_ttvDY.push_back(foldermc_dy+"*_TTZTo*");
114  vector<TString> s_otherDY;
115  s_otherDY.push_back(foldermc_dy+"*_ZJet*");
116  s_otherDY.push_back(foldermc_dy+"*QCD_HT*");
117  s_otherDY.push_back(foldermc_dy+"*_WJetsToLNu*");
118  s_otherDY.push_back(foldermc_dy+"*_WWTo*");
119  s_otherDY.push_back(foldermc_dy+"*ggZH_HToBB*");
120  s_otherDY.push_back(foldermc_dy+"*ttHJetTobb*");
121 
122 
124  vector<TString> s_trig_had;
125  s_trig_had.push_back(folderdata_had+"/*JetHT*.root");
126 
127  vector<TString> s_qcd;
128  s_qcd.push_back(foldermc_had+"*QCD_HT*");
129  vector<TString> s_ttQCD;
130  s_ttQCD.push_back(foldermc_had+"*_TTJets*Lept*");
131  s_ttQCD.push_back(foldermc_had+"*_TTJets_HT*");
132  vector<TString> s_singleQCD;
133  s_singleQCD.push_back(foldermc_had+"*ST*");
134  vector<TString> s_otherQCD;
135  s_otherQCD.push_back(foldermc_had+"*_TTWJets*");
136  s_otherQCD.push_back(foldermc_had+"*_TTZTo*");
137  s_otherQCD.push_back(foldermc_had+"*_ZJet*");
138  s_otherQCD.push_back(foldermc_had+"*DY*");
139  s_otherQCD.push_back(foldermc_had+"*_WJetsToLNu*");
140  s_otherQCD.push_back(foldermc_had+"*_WWTo*");
141  s_otherQCD.push_back(foldermc_had+"*ggZH_HToBB*");
142  s_otherQCD.push_back(foldermc_had+"*ttHJetTobb*");
143 
144 
145  // Reading 1l ntuples
146  vector<sfeats> Samples;
147  Samples.push_back(sfeats(s_trig_1l, "Data",kBlack,1,"(trig[4]||trig[8])&&pass")); Samples.back().isData = true;
148  Samples.push_back(sfeats(s_tt_1l, "t#bar{t}, 1 true lepton", dps::c_tt_1l, 1,"ntruleps<=1&&stitch"));
149  Samples.push_back(sfeats(s_tt_1l, "t#bar{t}, 2 true leptons", dps::c_tt_2l,1,"ntruleps>=2&&stitch"));
150  Samples.push_back(sfeats(s_wjets_1l, "W+jets", dps::c_wjets,1));
151  Samples.push_back(sfeats(s_single_1l, "Single top", dps::c_singlet));
152  Samples.push_back(sfeats(s_ttv_1l, "ttV", ra4::c_ttv));
153  Samples.push_back(sfeats(s_other_1l, "Other", dps::c_qcd, 1, "stitch"));
154 
155  vector<int> ra4_sam;
156  unsigned nsam(Samples.size());
157  for(unsigned sam(0); sam < nsam; sam++)
158  ra4_sam.push_back(sam);
159 
160  // Reading 2l tt ntuples
161  int itt(Samples.size());
162  Samples.push_back(sfeats(s_trig_tt, "Data",kBlack,1,"(trig[4]||trig[8])&&pass")); Samples.back().isData = true;
163  Samples.push_back(sfeats(s_tt_tt, "t#bar{t}, 1 true lepton", dps::c_tt_1l, 1,"ntruleps<=1&&stitch"));
164  Samples.push_back(sfeats(s_tt_tt, "t#bar{t}, 2 true leptons", dps::c_tt_2l,1,"ntruleps>=2&&stitch"));
165  Samples.push_back(sfeats(s_wjets_tt, "W+jets", dps::c_wjets,1));
166  Samples.push_back(sfeats(s_single_tt, "Single top", dps::c_singlet));
167  Samples.push_back(sfeats(s_ttv_tt, "ttV", ra4::c_ttv));
168  Samples.push_back(sfeats(s_other_tt, "Other", dps::c_qcd, 1, "stitch"));
169 
170  vector<int> tt_sam;
171  for(unsigned sam(itt); sam < Samples.size(); sam++)
172  tt_sam.push_back(sam);
173 
174 
175  // Reading dy ntuples
176  int idl(Samples.size());
177  Samples.push_back(sfeats(s_trig_dy, "Data",kBlack,1,
178  "(trig[4]||trig[8])&&pass")); Samples.back().isData = true;
179  Samples.push_back(sfeats(s_tt_dl, "t#bar{t}, 2 true leptons", dps::c_tt_2l,1,"ntruleps>=2&&stitch"));
180  Samples.push_back(sfeats(s_tt_dl, "t#bar{t}, 1 true lepton", dps::c_tt_1l, 1,"ntruleps==1&&stitch"));
181  Samples.push_back(sfeats(s_DY, "Z+jets", dps::c_qcd, 1, "stitch"));//12
182  Samples.push_back(sfeats(s_singleDY, "QCD", dps::c_singlet));
183  Samples.push_back(sfeats(s_ttvDY, "ttV", ra4::c_ttv));
184  Samples.push_back(sfeats(s_otherDY, "Other", dps::c_other));
185  vector<int> dl_sam;
186  for(unsigned sam(idl); sam < Samples.size(); sam++) {
187  dl_sam.push_back(sam);
188  }
189 
190  // 0-lepton
191  int iqcd(Samples.size());
192  Samples.push_back(sfeats(s_trig_had, "Data", 1, -1, "trig[12]&&pass")); Samples.back().isData = true;
193  Samples.push_back(sfeats(s_qcd, "QCD", dps::c_qcd));
194  Samples.push_back(sfeats(s_ttQCD, "t#bar{t}", dps::c_tt_1l, 1, "stitch"));
195  Samples.push_back(sfeats(s_singleQCD, "Single top", dps::c_singlet));
196  Samples.push_back(sfeats(s_otherQCD, "Other", dps::c_other, 1, "stitch"));
197 
198  vector<int> qcd_sam;
199  for(unsigned sam(iqcd); sam < Samples.size(); sam++) {
200  qcd_sam.push_back(sam);
201  }
202 
203  vector<hfeats> vars;
204 
205  // Invariant masses
206  TString mll("(mumu_m*(mumu_m>0&&mumu_pt1>30)+elel_m*(elel_m>0&&elel_pt1>30))>80&&(mumu_m*(mumu_m>0&&mumu_pt1>30)+elel_m*(elel_m>0&&elel_pt1>30))<100");
207 
208 
210 
211  // nleps==1
212  vars.push_back(hfeats("fjets_m[0]",20,0,500, ra4_sam, "m(J_{1}) [GeV]",
213  "(nels+nmus)==1&&ht>"+minht+"&&"+metcut+"&&njets>="+minjets+"&&nbm>=1"));
214  vars.back().whichPlots = "2"; vars.back().normalize = true;
215 
216  vars.push_back(hfeats("fjets_m[0]",40,0,400, ra4_sam, "m(J_{1}) [GeV]",
217  "(nels+nmus)==1&&ht>"+minht+"&&"+metcut+"&&njets<"+minjets+"&&nbm>=1"));
218  vars.back().whichPlots = "2"; vars.back().normalize = true;
219 
220  vars.push_back(hfeats("mj", 16,0,800, ra4_sam, "M_{J} [GeV]",
221  "(nels+nmus)==1&&ht>"+minht+"&&"+metcut+"&&njets>="+minjets+"&&nbm>=1"));
222  vars.back().whichPlots = "2"; vars.back().normalize = true;
223 
224  // nleps==2 dilepton ttbar
225  vars.push_back(hfeats("mj",12,0,600, tt_sam, "M_{J} [GeV]",
226  "nels==1&&nmus==1&&ht>300&&met>100&&nbm>=1&&Sum$(leps_pt>30)>=1"));
227  vars.back().whichPlots = "2"; vars.back().normalize = true;
228 
229  // nleps==2 DY
230  vars.push_back(hfeats("mj",24,0,600, dl_sam, "M_{J} [GeV]",
231  "ht>350&&(nmus>=2||nels>=2)&&njets>=4&&"+mll));
232  vars.back().whichPlots = "2"; vars.back().normalize = true;
233 
234  // nleps==2 QCD
235  vars.push_back(hfeats("mj",50,0,1500, qcd_sam, "M_{J} [GeV]",
236  "ht>1000&&met<50&&(nvmus+nvels)==0&&njets>=10",0));
237  vars.back().whichPlots = "1"; vars.back().normalize = true;
238 
239  //
240  plot_distributions(Samples, vars, luminosity, plot_type, plot_style, "1d_twiki",true);
241 
242  time(&endtime);
243  cout<<"Plots took "<<difftime(endtime, begtime)<<" seconds to draw "
244  <<vars.size()<<" plots."<<endl<<endl;
245 }
void plot_distributions(std::vector< sfeats > Samples, std::vector< hfeats > vars, TString luminosity="10", TString filetype=".eps", TString namestyle="LargeLabels", TString dir="1d", bool doRatio=false, bool showcuts=false)
STL namespace.
int main()
Definition: plot_twiki.cxx:30