ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
plot_eff_pu_mj.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 #include "TLatex.h"
13 
14 #include "styles.hpp"
15 #include "utilities.hpp"
16 #include "utilities_macros.hpp"
17 
18 class marker_class {
19 public:
20  marker_class(float icut, float isize, int icolor, int istyle);
21  float cut, size;
22  int color, style;
23 };
24 
25 class var_class {
26 public:
27  var_class(TString ivarname, float iminx, float imaxx, TString ititle, int icolor,
28  int istyle=1, std::vector<marker_class> icuts=std::vector<marker_class>());
29  TString title, varname;
30  float minx, maxx;
31  std::vector<marker_class> cuts;
32  int color, style;
33 };
34 
35 using namespace std;
36 
37 void makePlot(vector<sfeats> Samples, vector<TChain *> chain, TString cuts);
38 
39 int main(){
40 
41  styles style("RA4"); style.setDefaultStyle();
42 
43  TString bfolder("");
44  string hostname = execute("echo $HOSTNAME");
45  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
46  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
47 
48  TString folder=bfolder+"/cms2r0/babymaker/babies/2015_01_30/small_tree/";
49 
50  vector<TString> s_t1t;
51  s_t1t.push_back(folder+"*T1tttt*1500_mLSP-100*");
52  vector<TString> s_t1tc;
53  s_t1tc.push_back(folder+"*T1tttt*1200_mLSP-800*");
54  vector<TString> s_tt;
55  s_tt.push_back(folder+"*_TTJets*");
56 
57 
58  // Reading ntuples
59  TString lsp = "{#lower[-0.1]{#tilde{#chi}}#lower[0.2]{#scale[0.85]{^{0}}}#kern[-1.3]{#scale[0.85]{_{1}}}}";
60  TString t1t_label = "#tilde{g}#kern[0.2]{#tilde{g}}, #tilde{g}#rightarrowt#kern[0.18]{#bar{t}}#kern[0.18]"+lsp;
61  vector<sfeats> Samples;
62  Samples.push_back(sfeats(s_tt, "t#bar{t}", kRed+1));
63  Samples.push_back(sfeats(s_t1t, t1t_label+" (1500,100)", kAzure+2));
64  Samples.push_back(sfeats(s_t1tc, t1t_label+" (1200,800)", kGreen+1));
65 
66  // Reading ntuples
67  vector<TChain *> chain;
68  for(unsigned sam(0); sam < Samples.size(); sam++){
69  chain.push_back(new TChain("tree"));
70  for(unsigned insam(0); insam < Samples[sam].file.size(); insam++){
71  chain[sam]->Add(Samples[sam].file[insam]);
72  }
73  }
74 
75  TString mjcut("400");
76  vector<var_class> mj_vars;
77  mj_vars.push_back(var_class("mj_cands",2200,0,"M_{J} with PFcands",kMagenta,1));
78  mj_vars.push_back(var_class("mj_cands_trim",2200,0,"M_{J} with PFcands trimmed",kRed,1));
79  mj_vars.push_back(var_class("mj_10",2200,0,"M_{J} with 10 GeV jets",kGreen+1,1));
80  mj_vars.push_back(var_class("mj_30", 2200,0,"M_{J} with 30 GeV jets",kAzure+2,1));
81  TLatex label; label.SetNDC(kTRUE);
82  label.SetTextSize(0.052);
83  label.SetTextAlign(31);
84 
85  // Finding histograms
86  TCanvas can;
87  double legSingle = 0.08;
88  double legX=style.PadLeftMargin+0.03, legY=1-style.PadTopMargin-0.02, legW=0.1, legH=legSingle*mj_vars.size();
89  TLegend leg(legX,legY-legH, legX+legW, legY);
90  leg.SetTextSize(0.05); leg.SetFillColor(0); leg.SetBorderSize(0); leg.SetFillStyle(0);
91  float minh = 5, maxh = 40;
92  int nbins = (maxh-minh)/5;
93  TString hname;
94  vector<TH1D*> histo[2];
95  for(unsigned sam(0); sam < Samples.size(); sam++){
96  for(unsigned var(0); var<mj_vars.size(); var++){
97  for(size_t ind(0); ind<2; ind++){
98  hname = "histo"; hname += sam; hname += var; hname += ind;
99  histo[ind].push_back(new TH1D(hname, "", nbins, minh, maxh));
100  histo[ind][var]->Sumw2();
101  //histo[ind][var]->SetBinErrorOption(TH1::kPoisson);
102  histo[ind][var]->SetLineColor(mj_vars[var].color);
103  histo[ind][var]->SetLineWidth(4);
104  style.setTitles(histo[ind][var], "True n_{PV}", "#epsilon^{norm} for M_{J} > "+mjcut+" GeV",
105  "#scale[0.8]{#font[62]{CMS}} #scale[0.6]{#font[52]{Supplementary (Simulation)}}", "#scale[0.8]{13 TeV}");
106  histo[ind][var]->SetBinContent(nbins, histo[ind][var]->GetBinContent(nbins)+
107  histo[ind][var]->GetBinContent(nbins+1));
108  }
109  chain[sam]->Project(histo[0][var]->GetName(), "ntrupv", "1*("+mj_vars[var].varname+">"+mjcut+")");
110  chain[sam]->Project(histo[1][var]->GetName(), "ntrupv", "1");
111  histo[0][var]->Divide(histo[1][var]);
112  histo[0][var]->Scale(1/histo[0][var]->GetBinContent(4));
113  histo[0][var]->SetMinimum(0.15);
114  histo[0][var]->SetMaximum(2.1);
115  leg.AddEntry(histo[0][var], mj_vars[var].title);
116  if(var==0){
117  histo[0][var]->Draw("");
118  TLine line; line.SetLineStyle(2);
119  line.DrawLine(minh, 1, maxh, 1);
120  } else histo[0][var]->Draw("same");
121  } // Loop over MJ types
122  leg.Draw();
123  label.DrawLatex(1-style.PadRightMargin-0.04, style.PadBottomMargin+0.04, "Sample: "+Samples[sam].label);
124 
125  TString pname = "plots/eff_pu_"+format_tag(Samples[sam].label)+".pdf";
126  can.SaveAs(pname);
127  leg.Clear();
128 
129  for(unsigned var(0); var<mj_vars.size(); var++){
130  for(size_t ind(0); ind<2; ind++)
131  histo[ind][var]->Delete();
132  histo[0].clear();
133  histo[1].clear();
134  }
135 
136  } // Loop over samples
137 
138 }
139 
140 var_class::var_class(TString ivarname, float iminx, float imaxx, TString ititle, int icolor,
141  int istyle, vector<marker_class> icuts){
142  varname = ivarname; minx = iminx; maxx = imaxx; title = ititle;
143  cuts = icuts;
144  color = icolor; style = istyle;
145 }
146 
147 marker_class::marker_class(float icut, float isize, int icolor, int istyle){
148  cut=icut; size=isize; color=icolor; style=istyle;
149 }
void setDefaultStyle()
Definition: styles.cpp:36
bool Contains(const std::string &text, const std::string &pattern)
float PadTopMargin
Definition: styles.hpp:36
STL namespace.
std::string execute(const std::string &cmd)
int main()
TString format_tag(TString tag)
void makePlot(vector< sfeats > Samples, vector< TChain * > chain, TString cuts)
void setTitles(TH1 *h, TString xTitle="", TString yTitle="", TString Left="", TString Right="")
Definition: styles.cpp:173
tuple file
Definition: parse_card.py:238
float PadRightMargin
Definition: styles.hpp:36
float PadLeftMargin
Definition: styles.hpp:36
marker_class(float icut, float isize, int icolor, int istyle)
var_class(std::vector< sample_class > samples, TString ivarname, float iminx, float imaxx, TString ititle, int icolor, int istyle=1, std::vector< marker_class > icuts=std::vector< marker_class >())
float PadBottomMargin
Definition: styles.hpp:36