ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
plot_mj_2d_met.cxx
Go to the documentation of this file.
1 // plot_mj_met: Macro that plots signal and bkg in the MJ-MET plane
2 
3 #include <iostream>
4 #include <vector>
5 
6 #include "TChain.h"
7 #include "TH2D.h"
8 #include "TCanvas.h"
9 #include "TLegend.h"
10 #include "TLine.h"
11 #include "TString.h"
12 #include "TColor.h"
13 #include "TMath.h"
14 #include "TStyle.h"
15 
16 #include "styles.hpp"
17 #include "utilities.hpp"
18 #include "utilities_macros.hpp"
19 
20 using namespace std;
21 using std::cout;
22 using std::endl;
23 
24 
25 int main(){
26  styles style("LargeLabels"); style.setDefaultStyle();
27  TCanvas can;
28 
29  TString folder="archive/15-03-17/skims/";
30  vector<TString> bkgfiles;
31  bkgfiles.push_back(folder+"*_TTJet*");
32  bkgfiles.push_back(folder+"*_WJets*");
33  bkgfiles.push_back(folder+"*_T*channel*");
34  bkgfiles.push_back(folder+"*TTW*");
35  bkgfiles.push_back(folder+"*TTZ*");
36  bkgfiles.push_back(folder+"*QCD_HT*");
37  bkgfiles.push_back(folder+"*_ZJet*");
38  bkgfiles.push_back(folder+"*DY*");
39  bkgfiles.push_back(folder+"*WH_HToBB*");
40 
41  bool do_t1t(true), do_2b(true);
42  int colors[] = {4,kGreen+2};
43  TString leglab[] = {"Total bkg.", "T1tttt(1500,100)"}, sigfile("*T1tttt*1500_*PU20*"), sigtag("t1t");
44  if(!do_t1t){
45  leglab[1] = "T1tttt(1200,800)";
46  sigfile = "*T1tttt*1200_*PU20*";
47  sigtag = "t1tc";
48  colors[1] = kMagenta+1;
49  }
50 
51  vector<TChain *> chain;
52  for(unsigned icha(0); icha<2; icha++){
53  chain.push_back(new TChain("tree"));
54  if(icha==0){
55  for(unsigned sam(0); sam < bkgfiles.size(); sam++)
56  chain[icha]->Add(bkgfiles[sam]);
57  } else chain[icha]->Add(folder+sigfile);
58  }
59 
60  double legX = 0.15, legY = 0.87, legSingle = 0.06;
61  double legW = 0.3, legH = legSingle*chain.size();
62  TLegend leg(legX, legY-legH, legX+legW, legY);
63  leg.SetTextSize(0.052); //leg.SetFillColor(0); leg.SetFillStyle(0); leg.SetBorderSize(0);
64  leg.SetTextFont(132);
65 
66  TLine line; line.SetLineColor(28); line.SetLineWidth(4); line.SetLineStyle(2);
67  TString luminosity="4", totCut, title;
68  TString cuts("ht>500&&met>200&&mt>=150&&nbm>=2&&njets>=6&&(nmus+nels)==1"), hname;
69  if(!do_2b) cuts.ReplaceAll("nbm>=2","nbm==1");
70  int mj_scat_nbins(20), met_scat_nbins(10), mj_nrebin(2), met_nrebin(1);
71  // int mj_nbins(6), met_nbins(5);
72  // float mj_binning[] = {0,200,300,400,500,600,1500};
73  // float met_binning[] = {200,300,400,500,600,1500};
74  float limits[2][2] = {{0,1000},{200,700}};
75  vector<TH2D *>hscat, hsb;
76  for(unsigned icha(0); icha<2; icha++){
77  hname = "hscatter"; hname += icha;
78  hscat.push_back(new TH2D(hname,"",mj_scat_nbins,limits[0][0],limits[0][1],
79  met_scat_nbins,limits[1][0],limits[1][1]));
80  totCut = luminosity+"*weight*("+cuts+")";
81  chain[icha]->Project(hname, "met:mj",totCut);
82 
83  //cout<<icha<<": Integral "<< RoundNumber(hscat[icha]->Integral(),2)<<endl;
84  title = cuts; if(title=="1") title = "";
85  title.ReplaceAll("nvmus==1&&nmus==1&&nvels==0","1 #mu");
86  title.ReplaceAll("(nmus+nels)","n_{lep}");
87  title.ReplaceAll("nvmus10==0&&nvels10==0", "0 leptons");
88  title.ReplaceAll("njets30","n_{jets}^{30}");
89  title.ReplaceAll("els_pt","p^{e}_{T}");title.ReplaceAll("mus_pt","p^{#mu}_{T}");
90  title.ReplaceAll("njets","n_{jets}"); title.ReplaceAll("<", " < ");
91  title.ReplaceAll(">=", " #geq "); title.ReplaceAll(">", " > "); title.ReplaceAll("&&", ", ");
92  title.ReplaceAll("met", "MET"); title.ReplaceAll("ht", "H_{T}"); title.ReplaceAll("mt", "m_{T}");
93  title.ReplaceAll("nleps==1", "1 lepton"); title.ReplaceAll("nbm","n_{b}"); title.ReplaceAll("==", " = ");
94  hscat[icha]->SetTitle(title);
95  hscat[icha]->SetXTitle("M_{J} (GeV)");
96  hscat[icha]->SetYTitle("MET (GeV)");
97  hscat[icha]->SetMarkerColor(colors[icha]);
98  hscat[icha]->SetLineColor(colors[icha]);
99  hscat[icha]->SetMarkerStyle(20);
100  hscat[icha]->SetMarkerSize(0.7);
101  if(icha==0) hscat[icha]->Draw("scat=40");
102  else hscat[icha]->Draw("scat=40 same");
103  line.DrawLine(400,200,400,700); line.DrawLine(0,350,1000,350);
104 
105  hname = "hsb"; hname += icha;
106  hsb.push_back(static_cast<TH2D*>(hscat[icha]->Rebin2D(mj_nrebin,met_nrebin,hname)));
107  leg.AddEntry(hscat[icha],leglab[icha]);
108 
109  } // Loop over bkg and signal
110  leg.Draw();
111  TString pname("plots/scatter_"+sigtag+(do_2b?"2b":"1b")); pname += ".eps";
112  can.SaveAs(pname);
113 
114  const unsigned num_conts = 50;
115  const unsigned num_stops = 2;
116  double stops[num_stops] = {0., 1.};
117  double red[num_stops] = {1., 0.23};
118  double green[num_stops] = {1., 0.72};
119  double blue[num_stops] = {1., 0.52};
120  if(!do_t1t){
121  red[1] = 0.78;
122  green[1] = 0.47;
123  blue[1] = 0.63;
124  }
125  gStyle->SetNumberContours(num_conts); gStyle->SetPaintTextFormat("4.2f");
126  TColor::CreateGradientColorTable(num_stops, stops, red, green, blue, num_conts);
127 
128  can.SetRightMargin(0.13);
129  //hsb[1]->Divide(hsb[0]);
130  for(int xbin(1); xbin <= hsb[1]->GetNbinsX(); xbin++){
131  for(int ybin(1); ybin <= hsb[1]->GetNbinsY(); ybin++){
132  double num(hsb[1]->GetBinContent(xbin,ybin)), den(hsb[0]->GetBinContent(xbin,ybin));
133  double val(0);
134  if(den==0){
135  if(num>0) val = 9.99;
136  else val = 0.;
137  } else val = num/den;
138  hsb[1]->SetBinContent(xbin,ybin,val);
139  } // Loop over ybins
140  } // Loop over xbins
141  hsb[1]->SetMinimum(0);
142  hsb[1]->SetMaximum(1);
143  hsb[1]->SetMarkerSize(2.5);
144  hsb[1]->SetMarkerColor(1);
145  hsb[1]->SetZTitle("S/B");
146  hsb[1]->SetTitleOffset(0.56,"Z");
147  hsb[1]->Draw("colz");
148  hsb[1]->Draw("text same");
149  line.DrawLine(400,200,400,700); line.DrawLine(0,350,1000,350);
150  pname.ReplaceAll("scatter","s_over_b");
151  can.SaveAs(pname);
152 
153 
154  for(unsigned icha(0); icha<2; icha++){
155  hscat[icha]->Delete();
156  hsb[icha]->Delete();
157  chain[icha]->Delete();
158  }
159 }
160 
int main()
void setDefaultStyle()
Definition: styles.cpp:36
STL namespace.
bool do_2b
TString luminosity
TColor red(2015, 250/255., 96/255., 1/255.)