ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
table_vetoes.cxx
Go to the documentation of this file.
1 // table_yields: Generates a LaTeX file with a cutflow table for RA4
2 
3 #include <fstream>
4 #include <iostream>
5 #include <cmath>
6 #include <string>
7 #include <sstream>
8 #include "TChain.h"
9 #include "TFile.h"
10 #include "TString.h"
11 #include "TH1D.h"
12 #include "TMath.h"
13 #include "RooStats/NumberCountingUtils.h"
14 
15 #include "styles.hpp"
16 #include "utilities.hpp"
17 #include "utilities_macros.hpp"
18 
19 namespace localnames {
20  TString luminosity="10";
21 }
22 
23 using namespace localnames;
24 
25 using namespace std;
26 using std::cout;
27 using std::endl;
28 
29 TString YieldsCut(TString title, TString cuts, vector<TChain*> chain, vector<sfeats> Samples, int nsig);
30 
31 int main(){
32 
33  // Reading ntuples
34  TString folder="archive/15-05-02/skim/";
35  vector<TString> s_tt;
36  s_tt.push_back(folder+"*_TTJet*");
37  vector<TString> s_wjets;
38  s_wjets.push_back(folder+"*_WJets*");
39  vector<TString> s_single;
40  s_single.push_back(folder+"*_T*channel*");
41  vector<TString> s_ttv;
42  s_ttv.push_back(folder+"*TTW*");
43  s_ttv.push_back(folder+"*TTZ*");
44  vector<TString> s_other;
45  s_other.push_back(folder+"*QCD_HT*");
46  s_other.push_back(folder+"*_ZJet*");
47  s_other.push_back(folder+"*DY*");
48  s_other.push_back(folder+"*WH_HToBB*");
49  vector<TString> s_t1t;
50  s_t1t.push_back(folder+"*T1tttt*1500_*PU20*");
51  vector<TString> s_t1tc;
52  s_t1tc.push_back(folder+"*T1tttt*1200_*PU20*");
53 
54  vector<TChain *> chain;
55  vector<sfeats> Samples;
56  Samples.push_back(sfeats(s_other, "Other", 1001));
57  Samples.push_back(sfeats(s_ttv, "$t\\bar{t}V$", 1002));
58  Samples.push_back(sfeats(s_single, "Single $t$", 1005));
59  Samples.push_back(sfeats(s_wjets, "W+jets", 1004));
60  Samples.push_back(sfeats(s_tt, "$t\\bar{t}$ (1$\\ell$)", 1000,1,
61  "((mc_type&0x0F00)/0x100+(mc_type&0x000F)-(mc_type&0x00F0)/0x10)<=1"));
62  Samples.push_back(sfeats(s_tt, "$t\\bar{t}$ ($2\\ell$)", 1006,1,
63  "((mc_type&0x0F00)/0x100+(mc_type&0x000F)-(mc_type&0x00F0)/0x10)>=2"));
64  int nsig(3);
65  Samples.push_back(sfeats(s_t1t, "T1tttt NC", 2));
66  Samples.push_back(sfeats(s_t1t, "T1tttt NC, $1\\ell$", 2, 1,
67  "((mc_type&0x0F00)/0x100+(mc_type&0x000F)-(mc_type&0x00F0)/0x10)<=1"));
68  Samples.push_back(sfeats(s_t1tc, "T1tttt C", 2,2));
69 
70  for(unsigned sam(0); sam < Samples.size(); sam++){
71  chain.push_back(new TChain("tree"));
72  for(unsigned insam(0); insam < Samples[sam].file.size(); insam++)
73  chain[sam]->Add(Samples[sam].file[insam]);
74  }
75 
76  int veto_type(0);
77 
78  TString name = "txt/ra4_lepton_veto_lumi"+luminosity+".tex";
79  TString cuts("(nmus+nels)==1&&ht>500&&met>200&&nbm>=2&&njets>=6&&mt>150");
80  TString vetocut("(nvels+nvmus)==1"), tagcut("LV");
81  if(veto_type==1) {
82  name.ReplaceAll("lepton","track");
83  vetocut = "ntks==1";
84  tagcut = "TV";
85  }else if(veto_type==2){
86  name.ReplaceAll("lepton","track_chg");
87  vetocut = "ntks_chg==0";
88  tagcut = "TV\\_chg";
89  }
90  ifstream header("txt/header.tex");
91  ifstream footer("txt/footer.tex");
92  ofstream file(name);
93  file<<header.rdbuf();
94  file << "\n\\begin{tabular}{ l | ";
95  for(unsigned sam(0); sam < Samples.size()-nsig; sam++) file << "r";
96  file<<" | r ";
97  for(int sam(0); sam < nsig; sam++) file<<"| rr ";
98  file<<"}\\hline\\hline\n";
99  file << " \\multicolumn{1}{c|}{${\\cal L} = 10$ fb$^{-1}$} ";
100  for(unsigned sam(0); sam < Samples.size()-nsig; sam++)
101  file << " & "<<Samples[sam].label;
102  file<< " & SM bkg. ";
103  for(unsigned sam(Samples.size()-nsig); sam < Samples.size(); sam++)
104  file << " & "<<Samples[sam].label<< " & $Z_{\\rm bi}$ ";
105  file << "\\\\ \\hline \n ";
106 
108  file << " \\multicolumn{"<< Samples.size()+1+nsig<<"}{c}{"
109  << "$H_T>500, \\mathrm{MET}>200, m_T>150, n_{\\rm jets}\\geq 6, n_b\\geq 2, n_{\\rm lep}=1$"
110  <<"} \\\\ \\hline\n";
111  file << YieldsCut("$M_J > 400$", cuts+"&&mj>400",
112  chain, Samples, nsig);
113  file << YieldsCut("$M_J > 400$, "+tagcut, cuts+"&&mj>400&&"+vetocut,
114  chain, Samples, nsig);
115  file << YieldsCut("$M_J > 400$, MET$ > 400$", cuts+"&&mj>400&&met>400",
116  chain, Samples, nsig);
117  file << YieldsCut("$M_J > 400$, MET$ > 400$, "+tagcut, cuts+"&&mj>400&&met>400&&"+vetocut,
118  chain, Samples, nsig);
119  file << YieldsCut("$M_J > 400$, MET$ > 400$, $n_{\\rm jets} \\geq 8$", cuts+"&&mj>400&&met>400&&njets>=8",
120  chain, Samples, nsig);
121  file << YieldsCut("$M_J > 400$, MET$ > 400$, $n_{\\rm jets} \\geq 8$, "+tagcut, cuts+"&&mj>400&&met>400&&njets>=8&&"+vetocut,
122  chain, Samples, nsig);
123  file << YieldsCut("$M_J > 600$, MET$ > 400$", cuts+"&&mj>600&&met>400",
124  chain, Samples, nsig);
125  file << YieldsCut("$M_J > 600$, MET$ > 400$, "+tagcut, cuts+"&&mj>600&&met>400&&"+vetocut,
126  chain, Samples, nsig);
127 
128 
129 
130 
131  file << " \\hline\\multicolumn{1}{c|}{} ";
132  for(unsigned sam(0); sam < Samples.size()-nsig; sam++)
133  file << " & "<<Samples[sam].label;
134  file<< " & SM bkg. ";
135  for(unsigned sam(Samples.size()-nsig); sam < Samples.size(); sam++)
136  file << " & "<<Samples[sam].label<< " & $Z_{\\rm bi}$ ";
137  file << "\\\\ \n ";
138 
139  file<< "\\hline\\hline\n\\end{tabular}"<<endl<<endl;
140  file<<footer.rdbuf();
141  file.close();
142  cout<<"Written "<<name<<endl;
143 }
144 
145 TString YieldsCut(TString title, TString cuts, vector<TChain*> chain, vector<sfeats> Samples, int nsig){
146  TString totCut, Hname = "histo", out;
147  vector<double> yield, error;
148  double bkg(0), bkg_err(0), err;
149  int nsam(chain.size());
150  TH1D histo(Hname, "",100, 0, 10000);
151  histo.Sumw2();
152  for(int sam(0); sam < nsam; sam++){
153  totCut = luminosity+"*weight*("+cuts+"&&"+Samples[sam].cut+")";
154  chain[sam]->Project(Hname, "met", totCut);
155  yield.push_back(histo.IntegralAndError(0,101,err));
156  error.push_back(err);
157  if(sam<nsam-nsig) {
158  bkg += yield[sam];
159  bkg_err = sqrt(pow(bkg_err,2)+pow(err,2));
160  }
161  //cout<<sam<<": yield "<<Samples[sam].label<<" "<<yield[sam]<<" \t "<<totCut<<endl;
162  }
163 
164  cout<<title<<": B = "<<(RoundNumber(bkg,1)+" +- "+RoundNumber(bkg_err,1));
165  out = title;
166  for(int sam(0); sam < nsam-nsig; sam++) out += (" \t & " + RoundNumber(yield[sam],1));
167  out += (" \t & $"+RoundNumber(bkg,1))+" \\pm "+RoundNumber(bkg_err,1)+"$";
168  for(int sam(nsam-nsig); sam < nsam; sam++) {
169  float fracerr(sqrt(pow(bkg_err/bkg,2)+0.3*0.3+0.24*0.24));
170  out += (" \t& $" + RoundNumber(yield[sam],1)+" \\pm "+RoundNumber(error[sam],1) + "$ \t& " +
171  //RoundNumber(yield[sam],2,bkg));
172  RoundNumber(RooStats::NumberCountingUtils::BinomialExpZ(yield[sam], bkg, fracerr),2));
173  cout<<", S = "<<RoundNumber(yield[sam],1)+" +- "+RoundNumber(error[sam],1)<<" with Zbi = ";
174  cout<<RoundNumber(RooStats::NumberCountingUtils::BinomialExpZ(yield[sam], bkg, fracerr),2);
175  }
176  out += " \\\\ \n";
177  cout<<endl;
178  return out;
179 }
int main()
TString YieldsCut(TString title, TString cuts, vector< TChain * > chain, vector< sfeats > Samples, int nsig)
STL namespace.
TString RoundNumber(double num, int decimals, double denom=1.)
Definition: utilities.cpp:191
tuple file
Definition: parse_card.py:238
TString luminosity