ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
table_track_veto.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/2015_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 
77 
78  TString name = "txt/all_track_veto_lumi_"+luminosity+".tex";
79  TString cuts("(nmus+nels)==1&&ht>500&&met>200&&nbm>=1&&njets>=6&&mt>140&&mj>300");
80 
81  ifstream header("txt/header.tex");
82  ifstream footer("txt/footer.tex");
83  ofstream file(name);
84  file<<header.rdbuf();
85  file << "\n\\begin{tabular}{ l | ";
86  for(unsigned sam(0); sam < Samples.size()-nsig; sam++) file << "r";
87  file<<" | r ";
88  for(int sam(0); sam < nsig; sam++) file<<"| rr ";
89  file<<"}\\hline\\hline\n";
90  file << " \\multicolumn{1}{c|}{${\\cal L} = 10$ fb$^{-1}$} ";
91  for(unsigned sam(0); sam < Samples.size()-nsig; sam++)
92  file << " & "<<Samples[sam].label;
93  file<< " & SM bkg. ";
94  for(unsigned sam(Samples.size()-nsig); sam < Samples.size(); sam++)
95  file << " & "<<Samples[sam].label<<" &";//<< " & $Z_{\\rm bi}$ ";
96  file << "\\\\ \\hline \n ";
97 
98  //only use opposite sign tracks from primary lepton
99  TString os("((tks_id*lep_charge)>0)"); //tks_id and tks_charge are opposite sign for leptons (way to go, Benjamin Franklin)
100  TString os_had("((tks_id*lep_charge)<0)"); //tks_id and tks_charge are same sign for pions
101 
102  //exclude primary lepton
103  TString notp("&&(!tks_is_primary)");
104 
105  //classify flavor
106  TString elec("&&tks_id*tks_id==121");
107  TString muon("&&tks_id*tks_id==169");
108  TString had("&&!(tks_id*tks_id==121||tks_id*tks_id==169)");
109 
110  //abs iso for e (2 options), abs iso for mu (2 options), then charge iso for hadrons (2 options)
111  TString iso[6] = {"&&(tks_pt*(tks_mini_ne+tks_mini_ch))<10","&&(tks_pt*(tks_mini_ne+tks_mini_ch))<20","&&(tks_pt*(tks_mini_ne+tks_mini_ch))<30","&&(tks_pt*(tks_mini_ne+tks_mini_ch))<50","&&(tks_pt*(tks_mini_ch))<2.5","&&tks_mini_ch<0.05"};
112  // absolute iso = pt*(rel iso)
113 
114 
115  TString mtc[3] = {"&&tks_mt<80","&&tks_mt<90","&&tks_mt<100"};
116  // TString dphi[3] = {"&&abs(abs(abs(tks_phi-met_phi)-3.14159)-3.14159)<0.5","&&abs(abs(abs(tks_phi-met_phi)-3.14159)-3.14159)<0.75","&&abs(abs(abs(tks_phi-met_phi)-3.14159)-3.14159)<1.0"};
117 
118 
120  file << " \\multicolumn{"<< Samples.size()+1+nsig<<"}{c}{"
121  << "$H_T>500, $M_J>300, \\mathrm{MET}>200, m_T>140, n_{\\rm jets}\\geq 6, n_b\\geq 1, n_{\\rm lep}=1$"
122  <<"} \\\\ \\hline\n";
123 
124 
125  //Adjust "cuts" to change region definition
126  //study region baseline counts
127  file << YieldsCut("$M_J>300$", cuts,
128  chain, Samples, nsig);
129 
130 
131  //OR of all 3 vetoes
132  file << YieldsCut("removed by had TV, mu TV or e TV, $", cuts+"&&(Sum$("+os_had+had+notp+iso[4]+mtc[1]+")>0||"+"Sum$("+os+muon+notp+iso[2]+mtc[1]+")>0||"+"Sum$("+os+elec+notp+iso[0]+mtc[1]+")>0)",
133  chain, Samples, nsig);
134 
135 
136  /* // HADRONS
137  file << YieldsCut("removed by had TV, $mT_{trk}<90 + abs chg MI<2.5 GeV, $", cuts+"&&Sum$("+os_had+had+notp+iso[4]+mtc[1]+")>0",
138  chain, Samples, nsig);
139  file << YieldsCut("removed by had TV, $mT_{trk}<90 + rel chg MI<0.05, $", cuts+"&&Sum$("+os_had+had+notp+iso[5]+mtc[1]+")>0",
140  chain, Samples, nsig);
141  file << YieldsCut("removed by had TV, $mT_{trk}<100 + abs chg MI<2.5 GeV, $", cuts+"&&Sum$("+os_had+had+notp+iso[4]+mtc[2]+")>0",
142  chain, Samples, nsig);
143  file << YieldsCut("removed by had TV, $mT_{trk}<100 + rel chg MI<0.05, $", cuts+"&&Sum$("+os_had+had+notp+iso[5]+mtc[2]+")>0",
144  chain, Samples, nsig);
145 
146  */
147 
148  /* // MUONS
149  file << YieldsCut("removed by mu TV, $mT_{trk}<90 + abs chg+neu MI<30 GeV, $", cuts+"&&Sum$("+os+muon+notp+iso[2]+mtc[1]+")>0",
150  chain, Samples, nsig);
151  file << YieldsCut("removed by mu TV, $mT_{trk}<90 + abs chg+neu MI<50 GeV, $", cuts+"&&Sum$("+os+muon+notp+iso[3]+mtc[1]+")>0",
152  chain, Samples, nsig);
153  file << YieldsCut("removed by mu TV, $mT_{trk}<100 + abs chg+neu MI<30 GeV, $", cuts+"&&Sum$("+os+muon+notp+iso[2]+mtc[2]+")>0",
154  chain, Samples, nsig);
155  file << YieldsCut("removed by mu TV, $mT_{trk}<100 + abs chg+neu MI<50 GeV, $", cuts+"&&Sum$("+os+muon+notp+iso[3]+mtc[2]+")>0",
156  chain, Samples, nsig);
157 
158  */
159 
160 
161  /* // ELECTRONS
162  file << YieldsCut("removed by e TV, $mT_{trk}<90 + abs chg+neu MI<10 GeV, $", cuts+"&&Sum$("+os+elec+notp+iso[0]+mtc[1]+")>0",
163  chain, Samples, nsig);
164  file << YieldsCut("removed by e TV, $mT_{trk}<90 + abs chg+neu MI<20 GeV, $", cuts+"&&Sum$("+os+elec+notp+iso[1]+mtc[1]+")>0",
165  chain, Samples, nsig);
166  file << YieldsCut("removed by e TV, $mT_{trk}<100 + abs chg+neu MI<10 GeV, $", cuts+"&&Sum$("+os+elec+notp+iso[0]+mtc[2]+")>0",
167  chain, Samples, nsig);
168  file << YieldsCut("removed by e TV, $mT_{trk}<100 + abs chg+neu MI<20 GeV, $", cuts+"&&Sum$("+os+elec+notp+iso[1]+mtc[2]+")>0",
169  chain, Samples, nsig);
170 
171  */
172 
173 
174 
175  file << " \\hline\\multicolumn{1}{c|}{} ";
176  for(unsigned sam(0); sam < Samples.size()-nsig; sam++)
177  file << " & "<<Samples[sam].label;
178  file<< " & SM bkg. ";
179  for(unsigned sam(Samples.size()-nsig); sam < Samples.size(); sam++)
180  file << " & "<<Samples[sam].label<< "&";//<< " & $Z_{\\rm bi}$ ";
181  file << "\\\\ \n ";
182 
183  file<< "\\hline\\hline\n\\end{tabular}"<<endl<<endl;
184  file<<footer.rdbuf();
185  file.close();
186  cout<<"Written "<<name<<endl;
187 }
188 
189 TString YieldsCut(TString title, TString cuts, vector<TChain*> chain, vector<sfeats> Samples, int nsig){
190  TString totCut, Hname = "histo", out;
191  vector<double> yield, error;
192  double bkg(0), bkg_err(0), err;
193  int nsam(chain.size());
194  TH1D histo(Hname, "",100, 0, 10000);
195  histo.Sumw2();
196  for(int sam(0); sam < nsam; sam++){
197  totCut = luminosity+"*weight*("+cuts+"&&"+Samples[sam].cut+")";
198  chain[sam]->Project(Hname, "met", totCut);
199  yield.push_back(histo.IntegralAndError(0,101,err));
200  error.push_back(err);
201  if(sam<nsam-nsig) {
202  bkg += yield[sam];
203  bkg_err = sqrt(pow(bkg_err,2)+pow(err,2));
204  }
205  //cout<<sam<<": yield "<<Samples[sam].label<<" "<<yield[sam]<<" \t "<<totCut<<endl;
206  }
207 
208  cout<<title<<": B = "<<(RoundNumber(bkg,1)+" +- "+RoundNumber(bkg_err,1));
209  out = title;
210  for(int sam(0); sam < nsam-nsig; sam++) out += (" \t & " + RoundNumber(yield[sam],1));
211  out += (" \t & $"+RoundNumber(bkg,1))+" \\pm "+RoundNumber(bkg_err,1)+"$";
212  for(int sam(nsam-nsig); sam < nsam; sam++) {
213  // float fracerr(sqrt(pow(bkg_err/bkg,2)+0.3*0.3+0.24*0.24));
214  out += (" \t& $" + RoundNumber(yield[sam],1)+" \\pm "+RoundNumber(error[sam],1))+"&";// + "$ \t& " +
215  //RoundNumber(yield[sam],2,bkg));
216  // RoundNumber(RooStats::NumberCountingUtils::BinomialExpZ(yield[sam], bkg, fracerr),2));
217  cout<<", S = "<<RoundNumber(yield[sam],1)+" +- "+RoundNumber(error[sam],1);//<<" with Zbi = ";
218  //cout<<RoundNumber(RooStats::NumberCountingUtils::BinomialExpZ(yield[sam], bkg, fracerr),2);
219  }
220  out += " \\\\ \n";
221  cout<<endl;
222  return out;
223 }
STL namespace.
int main()
TString RoundNumber(double num, int decimals, double denom=1.)
Definition: utilities.cpp:191
TString YieldsCut(TString title, TString cuts, vector< TChain * > chain, vector< sfeats > Samples, int nsig)
tuple file
Definition: parse_card.py:238
TString luminosity