ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
plot_mj_pu_aux.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 #include "TF1.h"
14 
15 #include "styles.hpp"
16 #include "utilities.hpp"
17 #include "utilities_macros.hpp"
18 
19 class marker_class {
20 public:
21  marker_class(float icut, float isize, int icolor, int istyle);
22  float cut, size;
23  int color, style;
24 };
25 
26 class var_class {
27 public:
28  var_class(TString ivarname, float iminx, float imaxx, TString ititle, int icolor,
29  int istyle=1, std::vector<marker_class> icuts=std::vector<marker_class>());
30  TString title, varname;
31  float minx, maxx;
32  std::vector<marker_class> cuts;
33  int color, style;
34 };
35 
36 using namespace std;
37 
38 int main(){
39 
40  styles style("RA4"); style.setDefaultStyle();
41 
42  TString bfolder("");
43  string hostname = execute("echo $HOSTNAME");
44  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
45  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
46 
47  TString folder=bfolder+"/cms2r0/babymaker/babies/2015_01_30/small_tree/";
48 
49  vector<TString> s_t1t;
50  s_t1t.push_back(folder+"*T1tttt*1500_mLSP-100*");
51  vector<TString> s_t1tc;
52  s_t1tc.push_back(folder+"*T1tttt*1200_mLSP-800*");
53  vector<TString> s_tt;
54  s_tt.push_back(folder+"*_TTJets*");
55 
56 
57  // Reading ntuples
58  TString lsp = "{#lower[-0.1]{#tilde{#chi}}#lower[0.2]{#scale[0.85]{^{0}}}#kern[-1.3]{#scale[0.85]{_{1}}}}";
59  TString t1t_label = "#tilde{g}#kern[0.2]{#tilde{g}}, #tilde{g}#rightarrowt#kern[0.18]{#bar{t}}#kern[0.18]"+lsp;
60  vector<sfeats> Samples;
61  //Samples.push_back(sfeats(s_t1t, t1t_label+" (1500,100)", kAzure+2));
62  Samples.push_back(sfeats(s_t1tc, t1t_label+" (1200,800)", kGreen+1));
63  Samples.push_back(sfeats(s_tt, "t#bar{t}", kRed+1));
64 
65  // Reading ntuples
66  vector<TChain *> chain;
67  for(unsigned sam(0); sam < Samples.size(); sam++){
68  chain.push_back(new TChain("tree"));
69  for(unsigned insam(0); insam < Samples[sam].file.size(); insam++){
70  chain[sam]->Add(Samples[sam].file[insam]);
71  }
72  }
73  TString mj_s("M#lower[-.1]{_{J}}");
74  vector<var_class> mj_vars;
75  mj_vars.push_back(var_class("mj_cands",2200,0,mj_s+" with PFcands",kMagenta+1,1));
76  mj_vars.push_back(var_class("mj_cands_trim",2200,0,mj_s+" with PFcands trim",kRed,1));
77  mj_vars.push_back(var_class("mj_10",2200,0,mj_s+" with 10 GeV jets",kGreen+1,1));
78  mj_vars.push_back(var_class("mj_30", 2200,0,mj_s+" with 30 GeV jets",kAzure+2,1));
79  TLatex label; label.SetNDC(kTRUE);
80  label.SetTextSize(0.052);
81  label.SetTextAlign(31);
82 
83  // Finding histograms
84  TCanvas can;
85  double legSingle = 0.06;
86  double legX=style.PadLeftMargin+0.03, legY=1-style.PadTopMargin-0.02, legW=0.1, legH=legSingle*mj_vars.size();
87  TLegend leg(legX,legY-legH, legX+legW, legY);
88  leg.SetTextSize(0.045); leg.SetFillColor(0); leg.SetBorderSize(0); leg.SetFillStyle(0);
89  float binw=5., minh[] = {5,0}, maxh[] = {40,1000}; // 0 for ntrupv, 1 for MJ
90  int nbins[] = {static_cast<int>((maxh[0]-minh[0])/binw), 400};
91  TF1 linFit("linFit","[0]+[1]*x", minh[0], maxh[0]);
92 
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[ind], minh[ind], maxh[ind]));
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  }
105  for(int bin=1; bin<=nbins[0]; bin++){
106  TString cuts = "weight*(ntrupv>="+RoundNumber(minh[0]+(bin-1)*binw,1)+"&&ntrupv<"+RoundNumber(minh[0]+bin*binw,1)+")";
107  chain[sam]->Project(histo[1][var]->GetName(), mj_vars[var].varname, cuts);
108  histo[0][var]->SetBinContent(bin, histo[1][var]->GetMean());
109  histo[0][var]->SetBinError(bin, histo[1][var]->GetMeanError());
110  } // Loop over PV bins
111  histo[0][var]->SetMinimum(0);
112  histo[0][var]->SetMaximum(histo[0][var]->GetMaximum()*1.6);
113  histo[0][var]->Fit(&linFit, "QEMN+");
114  TString mean0 = RoundNumber(linFit.GetParameter(0),1), slope = RoundNumber(linFit.GetParameter(1),1);
115  leg.AddEntry(histo[0][var], mj_vars[var].title+" (<"+mj_s+"#kern[0.3]{>} = "+mean0+" + "+slope+"n_{PV})");
116  if(var==0){
117  histo[0][var]->Draw("");
118  style.setTitles(histo[0][var], "True n_{PV}", "Average "+mj_s+" [GeV]",
119  "#scale[0.8]{#font[62]{CMS}} #scale[0.6]{#font[52]{Supplementary (Simulation)}}", "#scale[0.8]{13 TeV}");
120  TLine line; line.SetLineStyle(2);
121  line.DrawLine(minh[0], 1, maxh[0], 1);
122  } else histo[0][var]->Draw("same");
123  } // Loop over MJ types
124  leg.Draw();
125  label.DrawLatex(1-style.PadRightMargin-0.03, style.PadBottomMargin+0.05, "Sample: "+Samples[sam].label);
126  Samples[sam].label.ReplaceAll(t1t_label, "T1tttt");
127  TString pname = "plots/mj_pu_"+format_tag(Samples[sam].label)+".pdf";
128  can.Print(pname);
129  leg.Clear();
130 
131  for(unsigned var(0); var<mj_vars.size(); var++){
132  for(size_t ind(0); ind<2; ind++)
133  histo[ind][var]->Delete();
134  histo[0].clear();
135  histo[1].clear();
136  }
137 
138  } // Loop over samples
139 
140 }
141 
142 var_class::var_class(TString ivarname, float iminx, float imaxx, TString ititle, int icolor,
143  int istyle, vector<marker_class> icuts){
144  varname = ivarname; minx = iminx; maxx = imaxx; title = ititle;
145  cuts = icuts;
146  color = icolor; style = istyle;
147 }
148 
149 marker_class::marker_class(float icut, float isize, int icolor, int istyle){
150  cut=icut; size=isize; color=icolor; style=istyle;
151 }
int main()
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)
TString format_tag(TString tag)
TString RoundNumber(double num, int decimals, double denom=1.)
Definition: utilities.cpp:191
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