ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
plot_eff_pu.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 
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 
13 #include "styles.hpp"
14 #include "utilities.hpp"
15 #include "utilities_macros.hpp"
16 
17 using namespace std;
18 
19 void makePlot(vector<sfeats> Samples, vector<TChain *> chain, TString cuts);
20 
21 int main(){
22 
23  styles style("RA4"); style.setDefaultStyle();
24 
25  TString bfolder("");
26  string hostname = execute("echo $HOSTNAME");
27  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
28  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
29 
30  TString foldermc(bfolder+"/cms2r0/babymaker/babies/2016_06_14/mc/unskimmed/");
31  TString folderscan(bfolder+"/cms2r0/babymaker/babies/2016_06_21/mc/T1tttt/");
32 
33  vector<TString> s_t1t;
34  s_t1t.push_back(folderscan+"*T1tttt*1400_mLSP-1*");
35  s_t1t.push_back(folderscan+"*T1tttt*1450_mLSP-1*");
36  s_t1t.push_back(folderscan+"*T1tttt*1500_mLSP-1*");
37  s_t1t.push_back(folderscan+"*T1tttt*1550_mLSP-1*");
38  s_t1t.push_back(folderscan+"*T1tttt*1600_mLSP-1*");
39  s_t1t.push_back(folderscan+"*T1tttt*1650_mLSP-1*");
40  s_t1t.push_back(folderscan+"*T1tttt*1700_mLSP-1*");
41  s_t1t.push_back(folderscan+"*T1tttt*1750_mLSP-1*");
42  s_t1t.push_back(folderscan+"*T1tttt*1800_mLSP-1*");
43  s_t1t.push_back(folderscan+"*T1tttt*1850_mLSP-1*");
44  s_t1t.push_back(folderscan+"*T1tttt*1900_mLSP-1*");
45  vector<TString> s_t1tc;
46  s_t1tc.push_back(folderscan+"*T1tttt*1200_mLSP-800*");
47  s_t1tc.push_back(folderscan+"*T1tttt*1250_mLSP-850*");
48  s_t1tc.push_back(folderscan+"*T1tttt*1300_mLSP-900*");
49  s_t1tc.push_back(folderscan+"*T1tttt*1350_mLSP-950*");
50  s_t1tc.push_back(folderscan+"*T1tttt*1400_mLSP-1000*");
51  s_t1tc.push_back(folderscan+"*T1tttt*1450_mLSP-1050*");
52  s_t1tc.push_back(folderscan+"*T1tttt*1500_mLSP-1100*");
53  s_t1tc.push_back(folderscan+"*T1tttt*1550_mLSP-1150*");
54  s_t1tc.push_back(folderscan+"*T1tttt*1600_mLSP-1200*");
55  s_t1tc.push_back(folderscan+"*T1tttt*1650_mLSP-1250*");
56  s_t1tc.push_back(folderscan+"*T1tttt*1700_mLSP-1300*");
57  vector<TString> s_tt_1l;
58  s_tt_1l.push_back(foldermc+"*_TTJets*SingleLeptFromTbar*");
59  s_tt_1l.push_back(foldermc+"*_TTJets*SingleLeptFromT_*");
60  vector<TString> s_tt_2l;
61  s_tt_2l.push_back(foldermc+"*_TTJets*DiLept*");
62 
63  vector<TString> s_other;
64  s_other.push_back(foldermc+"*_WJetsToLNu*.root");
65  s_other.push_back(foldermc+"*_TTWJets*.root");
66  s_other.push_back(foldermc+"*_TTZTo*.root");
67  s_other.push_back(foldermc+"*_ST_*.root");
68  s_other.push_back(foldermc+"*QCD_HT*.root");
69  s_other.push_back(foldermc+"*DYJetsToLL*.root");
70  s_other.push_back(foldermc+"*_ZJet*.root");
71  s_other.push_back(foldermc+"*ggZH_HToBB*.root");
72  s_other.push_back(foldermc+"*ttHJetTobb*.root");
73  s_other.push_back(foldermc+"*_TTGJets*.root");
74  s_other.push_back(foldermc+"*_TTTT*.root");
75  s_other.push_back(foldermc+"*_WH_HToBB*.root");
76  s_other.push_back(foldermc+"*_ZH_HToBB*.root");
77  s_other.push_back(foldermc+"*_WWTo*.root");
78  s_other.push_back(foldermc+"*_WZTo*.root");
79  s_other.push_back(foldermc+"*_ZZ_*.root");
80 
81  // Reading ntuples
82  vector<sfeats> Samples;
83  // Samples.push_back(sfeats(s_t1t, "T1tttt(1400-1900,1)", 2));
84  // Samples.push_back(sfeats(s_t1tc, "T1tttt(1200-1700,800-1300)", 42));
85  Samples.push_back(sfeats(s_tt_1l, "t#bar{t}, 1 true lepton", dps::c_tt_1l));
86  Samples.push_back(sfeats(s_tt_2l, "t#bar{t}, 2 true leptons", dps::c_wjets));
87  // Samples.push_back(sfeats(s_other, "Other", 2001));
88 
89  // Reading ntuples
90  vector<TChain *> chain;
91  for(unsigned sam(0); sam < Samples.size(); sam++){
92  chain.push_back(new TChain("tree"));
93  for(unsigned insam(0); insam < Samples[sam].file.size(); insam++){
94  chain[sam]->Add(Samples[sam].file[insam]);
95  }
96  }
97 
98  vector<TString> cuts = {"nleps==1", "ht>500", "met>200", "njets>=6", "nbm>=2", "mj14>=400","met>400","mt>140",
99  "nleps==1&&ht>500&&met>200&&njets>=6&&nbm>=1",
100  "nleps==1&&ht>500&&met>200&&njets>=6&&nbm>=1&&mj14>=400",
101  "nleps==1&&ht>500&&met>200&&njets>=6&&nbm>=1&&mj14>=400&&mt>140"};
102 
103  for(size_t ind(0); ind<cuts.size(); ind++)
104  makePlot(Samples, chain, cuts[ind]);
105 }
106 
107 void makePlot(vector<sfeats> Samples, vector<TChain *> chain, TString cuts){
108  // Finding histograms
109  TCanvas can;
110  double legSingle = 0.08;
111  double legX=0.22, legY=0.18, legW=0.1, legH=legSingle*Samples.size();
112  TLegend leg(legX,legY, legX+legW, legY+legH);
113  leg.SetTextSize(0.05); leg.SetFillColor(0); leg.SetBorderSize(0); leg.SetFillStyle(0);
114  float minh = 0, maxh = 50;
115  int nbins = (maxh-minh)/5;
116  TString hname;
117  vector<TH1D*> histo[2];
118  for(unsigned sam(0); sam < Samples.size(); sam++){
119  for(size_t ind(0); ind<2; ind++){
120  hname = "histo"; hname += sam; hname += ind;
121  histo[ind].push_back(new TH1D(hname, cuts2title(cuts), nbins, minh, maxh));
122  //histo[ind][sam]->Sumw2();
123  histo[ind][sam]->SetBinErrorOption(TH1::kPoisson);
124  histo[ind][sam]->SetLineColor(Samples[sam].color);
125  histo[ind][sam]->SetLineWidth(3);
126  histo[ind][sam]->SetXTitle("True n_{PV}");
127  histo[ind][sam]->SetYTitle("#epsilon normalized to [15 #leq n_{PV} < 20]");
128  histo[ind][sam]->SetBinContent(nbins, histo[ind][sam]->GetBinContent(nbins)+
129  histo[ind][sam]->GetBinContent(nbins+1));
130  }
131  chain[sam]->Project(histo[0][sam]->GetName(), "ntrupv", "weight*("+cuts+")");
132  chain[sam]->Project(histo[1][sam]->GetName(), "ntrupv", "weight");
133  histo[0][sam]->Divide(histo[1][sam]);
134  histo[0][sam]->Scale(1/histo[0][sam]->GetBinContent(4));
135  histo[0][sam]->SetMinimum(0.55);
136  histo[0][sam]->SetMaximum(1.3);
137  leg.AddEntry(histo[0][sam], Samples[sam].label);
138  if(sam==0){
139  histo[0][sam]->Draw("");
140  TLine line; line.SetLineStyle(2);
141  line.DrawLine(minh, 1, maxh, 1);
142  } else histo[0][sam]->Draw("same");
143  } // Loop over samples
144  leg.Draw();
145  TString pname = "eff_pu_"+format_tag(cuts)+".pdf";
146  can.SaveAs("plots/eff_pu/"+pname);
147 
148  for(unsigned sam(0); sam < Samples.size(); sam++)
149  for(size_t ind(0); ind<2; ind++)
150  histo[ind][sam]->Delete();
151 }
void makePlot(vector< sfeats > Samples, vector< TChain * > chain, TString cuts)
void setDefaultStyle()
Definition: styles.cpp:36
bool Contains(const std::string &text, const std::string &pattern)
TString cuts2title(TString title)
STL namespace.
std::string execute(const std::string &cmd)
TString format_tag(TString tag)
tuple file
Definition: parse_card.py:238
int main()
Definition: plot_eff_pu.cxx:21