ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
table_smear.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 <unistd.h> // getopt in Macs
9 
10 #include "TChain.h"
11 #include "TFile.h"
12 #include "TString.h"
13 #include "TH1D.h"
14 #include "TMath.h"
15 #include "RooStats/NumberCountingUtils.h"
16 
17 #include "styles.hpp"
18 #include "utilities.hpp"
19 #include "utilities_macros.hpp"
20 
21 namespace {
22  TString ntuple_date("2015_10_19");
23  TString luminosity="3";
24  TString tag = "";
25  bool do_1b=false;
26  bool do_2l=false;
27  bool do_ttbaronly = false;
28  bool do_note=true;
29  bool do_zbi=false;
30  bool do_soverb=false;
31  bool print_full(true);
32 
33  int method = 0; // Only methods 1 and 2 currently supported
34 
35  TString minjets("6");
36  TString highjets("9");
37  TString mjthresh("400");
38  TString highmet("400");
39  int do_nb_binning=0; // 0 = No Nb binning. 1 = Nb binning at low MET. 2 = Nb binning at all MET.
40 }
41 
42 using namespace std;
43 using std::cout;
44 using std::endl;
45 
46 TString YieldsCut(TString title, TString cuts, vector<TChain*> chain, vector<sfeats> Samples, int nsig);
47 
48 int main(int argc, char *argv[]){
49 
50  int c(0);
51  while((c=getopt(argc, argv, "m:oz:t:j:h:f:e:b:p:"))!=-1){
52  switch(c){
53  case 'm':
54  method=atoi(optarg);
55  break;
56  case 'o':
57  do_ttbaronly = true;
58  break;
59  case 'z':
60  if(0==atoi(optarg)) do_zbi=false;
61  if(1==atoi(optarg)) do_zbi=true;
62  break;
63  case 'j':
64  minjets = optarg;
65  break;
66  case 'h':
67  highjets = optarg;
68  break;
69  case 'f':
70  mjthresh = optarg;
71  break;
72  case 'e':
73  highmet = optarg;
74  break;
75  case 'b':
76  do_nb_binning = atoi(optarg);
77  break;
78  case 't':
79  tag = optarg;
80  break;
81  case 'p':
82  print_full = true;
83  break;
84  default:
85  break;
86  }
87  }
88 
89  // Reading ntuples
90  TString folder ="/afs/cern.ch/work/m/manuelf/public/babies/2015_10_19/mc/skim_1lht500met200/";
91  // TString folder_ttv = "~manuelf/work/babies/2015_10_19/mc/skim_1lht400/";
92  TString folder_other="/afs/cern.ch/user/a/ana/public/151028_230803/";
93  // folder = "archive/2015_10_19/mc/skim_1lht500met200/";
94 
95  vector<TString> s_tt;
96  s_tt.push_back(folder+"*_TTJets*Lept*");
97  s_tt.push_back(folder+"*_TTJets_HT*");
98  vector<TString> s_other;
99  s_other.push_back(folder_other+"*_TTJets*Lept*");
100  s_other.push_back(folder_other+"*_TTJets_HT*");
101  // vector<TString> s_wjets;
102  // s_wjets.push_back(folder+"*_WJetsToLNu*");
103  // vector<TString> s_ttv;
104  // s_ttv.push_back(folder_ttv+"*_TTWJets*");
105  // s_ttv.push_back(folder_ttv+"*_TTZTo*");
106  // vector<TString> s_single;
107  // s_single.push_back(folder+"*_ST_*");
108  // vector<TString> s_other;
109  // s_other.push_back(folder+"*DYJetsToLL*");
110  // s_other.push_back(folder+"*_QCD_HT*");
111  // s_other.push_back(folder+"*_ZJet*");
112  // s_other.push_back(folder+"*_WWTo*");
113  // s_other.push_back(folder+"*ggZH_HToBB*");
114  // s_other.push_back(folder+"*ttHJetTobb*");
115  // s_other.push_back(folder_ttv+"*_TTWJets*");
116  // s_other.push_back(folder_ttv+"*_TTZTo*");
117  // s_other.push_back(folder+"*_WJetsToLNu*");
118  vector<TString> s_t1t;
119  s_t1t.push_back(folder+"*T1tttt*1500_*");
120  vector<TString> s_t1tc;
121  s_t1tc.push_back(folder+"*T1tttt*1200_*");
122 
123  vector<TChain *> chain;
124  vector<sfeats> Samples;
125  if(!do_ttbaronly){
126  // Samples.push_back(sfeats(s_other, "Smeared $t\\bar{t}$ (1$\\ell$)", 1001,1,"(ntruleps==1)*(1+0.5*((Max$(jets_pt_res)>1.276)||(Min$(jets_pt_res)<0.824)))"));
127  // Samples.push_back(sfeats(s_other, "Smeared $t\\bar{t}$ (2$\\ell$)", 1001,1,"(ntruleps==2)*(1+0.5*((Max$(jets_pt_res)>1.276)||(Min$(jets_pt_res)<0.824)))"));
128  Samples.push_back(sfeats(s_other, "Smeared $t\\bar{t}$ (1$\\ell$)", 1001,1,"ntruleps==1"));
129  Samples.push_back(sfeats(s_other, "Smeared $t\\bar{t}$ (2$\\ell$)", 1001,1,"ntruleps==2"));
130  // Samples.push_back(sfeats(s_ttv, "$t\\bar{t}V$", 1002));
131  // Samples.push_back(sfeats(s_single, "Single $t$", 1005));
132  // Samples.push_back(sfeats(s_wjets, "W+jets", 1004));
133  }
134  Samples.push_back(sfeats(s_tt, "$t\\bar{t}$ (1$\\ell$)", 1000,1,
135  "ntruleps<=1"));
136  Samples.push_back(sfeats(s_tt, "$t\\bar{t}$ ($2\\ell$)", 1006,1,
137  "ntruleps>=2"));
138  int nsig(2);
139  Samples.push_back(sfeats(s_t1t, "T1tttt NC", 2));
140  Samples.push_back(sfeats(s_t1tc, "T1tttt C", 2,2));
141 
142  for(unsigned sam(0); sam < Samples.size(); sam++){
143  chain.push_back(new TChain("tree"));
144  for(unsigned insam(0); insam < Samples[sam].file.size(); insam++)
145  chain[sam]->Add(Samples[sam].file[insam]);
146  }
147 
148  if(method==1) { minjets = "6"; highjets="9"; mjthresh="600"; highmet="400"; do_nb_binning=0; }
149  if(method==2) { minjets ="6"; highjets="9"; mjthresh="400"; highmet="400"; do_nb_binning=1; }
150 
151 
152  TString midjets(""); midjets += (highjets.Atoi()-1);
153  TString minjets_2l(""), midjets_2l("");
154  minjets_2l += (minjets.Atoi()-1); midjets_2l += (midjets.Atoi()-1);
155  TString fom("$Z_{\\rm bi}$");
156  if(do_soverb) fom = "S/B";
157  TString lumi_s(luminosity); lumi_s.ReplaceAll(".","p");
158  TString outname = "txt/yields_mj"+mjthresh+"_met"+highmet+"_njets"+minjets+highjets+"_lumi"+lumi_s+"_"+ntuple_date+tag+".tex";
159  if(do_1b) outname.ReplaceAll("yields","yields_1b");
160  if(do_2l) outname.ReplaceAll("yields","yields_2l");
161  if(do_zbi) outname.ReplaceAll("yields","yields_zbi");
162 
163  TString baseline("ht>500&&met>200");
164  TString cuts_1l(baseline+"&&(nmus+nels)==1&&nbm>=1&&njets>="+minjets+"");
165  TString cuts_1l1b(baseline+"&&(nmus+nels)==1&&nbm==1&&njets>="+minjets+"");
166  TString cuts_2l(baseline+"&&(nmus+nels)==2&&nbm==1&&njets>="+minjets_2l+"");
167  TString cuts_2lbb(baseline+"&&(nmus+nels)==2&&nbm==2&&njets>="+minjets_2l+"");
168  TString cuts_1ltex("$H_T>500, \\mathrm{MET}>200, n_{\\rm jets}\\geq "+minjets+", n_b\\geq 1, n_{\\rm lep}=1$");
169  TString cuts_1l1btex("$H_T>500, \\mathrm{MET}>200, n_{\\rm jets}\\geq "+minjets+", n_b=1, n_{\\rm lep}=1$");
170  TString cuts_2ltex("$H_T>500, \\mathrm{MET}>200, n_{\\rm jets}\\geq "+minjets_2l+", n_b=1, n_{\\rm lep}=2$");
171  TString cuts_2lbbtex("$H_T>500, \\mathrm{MET}>200, n_{\\rm jets}\\geq "+minjets_2l+", n_b=2, n_{\\rm lep}=2$");
172  if(do_1b) {
173  cuts_1l.ReplaceAll("nbm>=2","nbm==1");
174  cuts_1ltex.ReplaceAll("n_b\\geq 2", "n_b=1");
175  }
176  ifstream header("txt/header.tex");
177  ifstream footer("txt/footer.tex");
178  ofstream file(outname);
179  file<<header.rdbuf();
180  file<<"\\vspace{80 mm}\n";
181  file << "\n\\begin{tabular}[tbp!]{ l | ";
182  for(unsigned sam(0); sam < Samples.size()-nsig; sam++) file << "r";
183  file<<" | r ";
184  for(int sam(0); sam < nsig; sam++) {
185  if (do_zbi || do_soverb) file<<"| r | r";
186  else file<<"| r ";
187  }
188  file<<"}\\hline\\hline\n";
189  file << " \\multicolumn{1}{c|}{${\\cal L} = "<<luminosity<<"$ fb$^{-1}$} ";
190  for(unsigned sam(0); sam < Samples.size()-nsig; sam++)
191  file << " & "<<Samples[sam].label;
192  file<< " & SM bkg. ";
193  for(unsigned sam(Samples.size()-nsig); sam < Samples.size(); sam++) {
194  file << " & "<<Samples[sam].label;
195  if (do_zbi || do_soverb) file << " & "+fom;
196  }
197  file << "\\\\ \\hline \n ";
198 
199  TString mtcut, mjcut;
200  TString indent("\\hspace{5 mm} ");
201  if(do_note) indent = "";
202  vector<TString> binnames;
203  for(unsigned bin(1); bin <= 6; bin++)
204  if(do_note) binnames.push_back("");
205  else {
206  TString name("Bin "); name += bin; name += ": ";
207  binnames.push_back(name);
208  }
209  TString lownj("$n_j\\leq "+midjets+"$");
210  TString hignj("$n_j\\geq "+highjets+"$");
211  TString lownj_2l("$n_j\\leq "+midjets_2l+"$");
212  TString highjets_2l(""); highjets_2l += (midjets_2l.Atoi()+1);
213  TString hignj_2l("$n_j\\geq "+highjets_2l+"$");
214  TString lowmet("$\\text{MET}\\leq "+highmet+"$");
215  TString higmet("$\\text{MET}> "+highmet+"$");
216  TString letter("R");
217  if(do_1b) letter = "B";
218  if(do_2l) letter = "D";
219  TString regions[4];
220  for(int ind(0); ind<4; ind++) {regions[ind] = letter; regions[ind] += (ind+1);}
222  if(!do_2l){
223  file << " \\multicolumn{"<< Samples.size()+1<<"}{c}{"<< cuts_1ltex <<"} \\\\ \\hline \\hline\n";
224 
225  // R1 region
226  mjcut="mj<="+mjthresh; mtcut="mt<=140";
227  file << YieldsCut(regions[0]+": $m_T \\leq 140,M_J\\leq "+mjthresh+"$", mjcut+"&&"+mtcut+"&&"+cuts_1l, chain, Samples, nsig);
228  file <<"\\hline\n";
229  if(print_full){
230  if(do_nb_binning==0){
231  file << YieldsCut(indent+lownj+", "+lowmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&"+cuts_1l, chain, Samples, nsig);
232  file << YieldsCut(indent+lownj+", "+higmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
233  file << YieldsCut(indent+hignj+", "+lowmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&" +cuts_1l, chain, Samples, nsig);
234  file << YieldsCut(indent+hignj+", "+higmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
235  }
236  else if(do_nb_binning==1) {
237  file << YieldsCut(indent+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&met<="+highmet+"&&nbm==2&&"+cuts_1l, chain, Samples, nsig);
238  file << YieldsCut(indent+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&met<="+highmet+"&&nbm>=3&&"+cuts_1l, chain, Samples, nsig);
239  file << YieldsCut(indent+higmet, mjcut+"&&"+mtcut+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
240  }
241  else if(do_nb_binning==2) {
242  file << YieldsCut(indent+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&met<="+highmet+"&&nbm==2&&"+cuts_1l, chain, Samples, nsig);
243  file << YieldsCut(indent+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&met<="+highmet+"&&nbm>=3&&"+cuts_1l, chain, Samples, nsig);
244  file << YieldsCut(indent+higmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&met>"+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
245  file << YieldsCut(indent+higmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&met>"+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
246  }
247  file <<"\\hline\n";
248  } // if(print_full)
249 
250  // R2 region
251  mjcut="mj>"+mjthresh; mtcut="mt<=140";
252  file << YieldsCut(regions[1]+": $m_T \\leq 140,M_J> "+mjthresh+"$", mjcut+"&&"+mtcut+"&&"+cuts_1l, chain, Samples, nsig);
253  file <<"\\hline\n";
254 
255  if(print_full){
256  if(do_nb_binning==0){
257  file << YieldsCut(indent+lownj+", "+lowmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&"+cuts_1l, chain, Samples, nsig);
258  file << YieldsCut(indent+lownj+", "+higmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
259  file << YieldsCut(indent+hignj+", "+lowmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&" +cuts_1l, chain, Samples, nsig);
260  file << YieldsCut(indent+hignj+", "+higmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
261  }
262  else if(do_nb_binning==1) {
263  file << YieldsCut(indent+lownj+", "+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&nbm==2&&"+cuts_1l, chain, Samples, nsig);
264  file << YieldsCut(indent+lownj+", "+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&nbm>=3&&"+cuts_1l, chain, Samples, nsig);
265  file << YieldsCut(indent+lownj+", "+higmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
266  file << YieldsCut(indent+hignj+", "+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
267  file << YieldsCut(indent+hignj+", "+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
268  file << YieldsCut(indent+hignj+", "+higmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
269  }
270  else if(do_nb_binning==2) {
271  file << YieldsCut(indent+lownj+", "+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&nbm==2&&"+cuts_1l, chain, Samples, nsig);
272  file << YieldsCut(indent+lownj+", "+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&nbm>=3&&"+cuts_1l, chain, Samples, nsig);
273  file << YieldsCut(indent+lownj+", "+higmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
274  file << YieldsCut(indent+lownj+", "+higmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
275  file << YieldsCut(indent+hignj+", "+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
276  file << YieldsCut(indent+hignj+", "+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
277  file << YieldsCut(indent+hignj+", "+higmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
278  file << YieldsCut(indent+hignj+", "+higmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
279  }
280 
281  file <<"\\hline\n";
282  } // if(print_full)
283 
284  // R3 region
285  mjcut="mj<="+mjthresh; mtcut="mt>140";
286  file << YieldsCut(regions[2]+": $m_T > 140,M_J \\leq "+mjthresh+"$", mjcut+"&&"+mtcut+"&&"+cuts_1l, chain, Samples, nsig);
287  file <<"\\hline\n";
288 
289  if(do_nb_binning==0){
290  file << YieldsCut(indent+lownj+", "+lowmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&"+cuts_1l, chain, Samples, nsig);
291  file << YieldsCut(indent+lownj+", "+higmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
292  file << YieldsCut(indent+hignj+", "+lowmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&" +cuts_1l, chain, Samples, nsig);
293  file << YieldsCut(indent+hignj+", "+higmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
294  }
295  else if(do_nb_binning==1) {
296  file << YieldsCut(indent+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&met<="+highmet+"&&nbm==2&&"+cuts_1l, chain, Samples, nsig);
297  file << YieldsCut(indent+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&met<="+highmet+"&&nbm>=3&&"+cuts_1l, chain, Samples, nsig);
298  file << YieldsCut(indent+higmet, mjcut+"&&"+mtcut+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
299  }
300  else if(do_nb_binning==2) {
301  file << YieldsCut(indent+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&met<="+highmet+"&&nbm==2&&"+cuts_1l, chain, Samples, nsig);
302  file << YieldsCut(indent+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&met<="+highmet+"&&nbm>=3&&"+cuts_1l, chain, Samples, nsig);
303  file << YieldsCut(indent+higmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&met>"+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
304  file << YieldsCut(indent+higmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&met>"+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
305  }
306 
307  file <<"\\hline\n";
308  file <<"\\hline\n";
309 
310 
311  // R4 region
312  mjcut="mj>"+mjthresh; mtcut="mt>140";
313  file << YieldsCut(regions[3]+": $m_T > 140,M_J > "+mjthresh+"$", mjcut+"&&"+mtcut+"&&"+cuts_1l, chain, Samples, nsig);
314  file <<"\\hline\n";
315 
316  if(do_nb_binning==0){
317  file << YieldsCut(binnames[0]+lownj+", "+lowmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&"+cuts_1l, chain, Samples, nsig);
318  file << YieldsCut(binnames[1]+lownj+", "+higmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
319  file << YieldsCut(binnames[2]+hignj+", "+lowmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&" +cuts_1l, chain, Samples, nsig);
320  file << YieldsCut(binnames[3]+hignj+", "+higmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
321  }
322  else if(do_nb_binning==1){
323  file << YieldsCut(binnames[0]+lownj+", "+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&nbm==2&&"+cuts_1l, chain, Samples, nsig);
324  file << YieldsCut(binnames[1]+lownj+", "+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&nbm>=3&&"+cuts_1l, chain, Samples, nsig);
325  file << YieldsCut(binnames[2]+lownj+", "+higmet, mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
326  file << YieldsCut(binnames[3]+hignj+", "+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
327  file << YieldsCut(binnames[4]+hignj+", "+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
328  file << YieldsCut(binnames[5]+hignj+", "+higmet, mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&" +cuts_1l, chain, Samples, nsig);
329  }
330  else if(do_nb_binning==2){
331  file << YieldsCut(binnames[0]+lownj+", "+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&nbm==2&&"+cuts_1l, chain, Samples, nsig);
332  file << YieldsCut(binnames[1]+lownj+", "+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met<="+highmet+"&&nbm>=3&&"+cuts_1l, chain, Samples, nsig);
333  file << YieldsCut(binnames[2]+lownj+", "+higmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
334  file << YieldsCut(binnames[2]+lownj+", "+higmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets<="+midjets+"&&met>"+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
335  file << YieldsCut(binnames[3]+hignj+", "+lowmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
336  file << YieldsCut(binnames[4]+hignj+", "+lowmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met<="+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
337  file << YieldsCut(binnames[5]+hignj+", "+higmet+", $n_b=2$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&nbm==2&&" +cuts_1l, chain, Samples, nsig);
338  file << YieldsCut(binnames[5]+hignj+", "+higmet+", $n_b\\geq 3$", mjcut+"&&"+mtcut+"&&njets>"+midjets+"&&met>"+highmet+"&&nbm>=3&&" +cuts_1l, chain, Samples, nsig);
339 
340  }
341 
342  file <<"\\hline\n";
343 
344  } else {
345  file << "\\hline \\hline\\multicolumn{"<< Samples.size()+1<<"}{c}{"
346  <<cuts_2ltex <<"} \\\\ \\hline \\hline\n";
347 
348  mjcut="mj<="+mjthresh;
349  file << YieldsCut(regions[2]+": $M_J \\leq "+mjthresh+"$", "mj <= "+mjthresh+"&&"+cuts_2l, chain, Samples, nsig);
350  file <<"\\hline\n";
351  file << YieldsCut(indent+lownj_2l+", "+lowmet, mjcut+"&&njets<="+midjets_2l+"&&met<="+highmet+"&&"+cuts_2l, chain, Samples, nsig);
352  file << YieldsCut(indent+lownj_2l+", "+higmet, mjcut+"&&njets<="+midjets_2l+"&&met>"+highmet+"&&" +cuts_2l, chain, Samples, nsig);
353  file << YieldsCut(indent+hignj_2l+", "+lowmet, mjcut+"&&njets>"+midjets_2l+"&&met<="+highmet+"&&" +cuts_2l, chain, Samples, nsig);
354  file << YieldsCut(indent+hignj_2l+", "+higmet, mjcut+"&&njets>"+midjets_2l+"&&met>"+highmet+"&&" +cuts_2l, chain, Samples, nsig);
355  file <<"\\hline\n";
356 
357 
358  mjcut="mj>"+mjthresh;
359  file << YieldsCut(regions[3]+": $M_J > "+mjthresh+"$", "mj>"+mjthresh+"&&"+cuts_2l, chain, Samples, nsig);
360  file <<"\\hline\n";
361  file << YieldsCut(indent+lownj_2l+", "+lowmet, mjcut+"&&njets<="+midjets_2l+"&&met<="+highmet+"&&"+cuts_2l, chain, Samples, nsig);
362  file << YieldsCut(indent+lownj_2l+", "+higmet, mjcut+"&&njets<="+midjets_2l+"&&met>"+highmet+"&&" +cuts_2l, chain, Samples, nsig);
363  file << YieldsCut(indent+hignj_2l+", "+lowmet, mjcut+"&&njets>"+midjets_2l+"&&met<="+highmet+"&&" +cuts_2l, chain, Samples, nsig);
364  file << YieldsCut(indent+hignj_2l+", "+higmet, mjcut+"&&njets>"+midjets_2l+"&&met>"+highmet+"&&" +cuts_2l, chain, Samples, nsig);
365 
366  file << "\\hline \\hline\\multicolumn{"<< Samples.size()+1<<"}{c}{"
367  << cuts_2lbbtex<<"} \\\\ \\hline \\hline\n";
368 
369  mjcut="mj<="+mjthresh;
370  file << YieldsCut(regions[2]+": $M_J \\leq "+mjthresh+"$", "mj<="+mjthresh+"&&"+cuts_2lbb, chain, Samples, nsig);
371  file <<"\\hline\n";
372  file << YieldsCut(indent+lownj_2l+", "+lowmet, mjcut+"&&njets<="+midjets_2l+"&&met<="+highmet+"&&"+cuts_2lbb, chain, Samples, nsig);
373  file << YieldsCut(indent+lownj_2l+", "+higmet, mjcut+"&&njets<="+midjets_2l+"&&met>"+highmet+"&&" +cuts_2lbb, chain, Samples, nsig);
374  file << YieldsCut(indent+hignj_2l+", "+lowmet, mjcut+"&&njets>"+midjets_2l+"&&met<="+highmet+"&&" +cuts_2lbb, chain, Samples, nsig);
375  file << YieldsCut(indent+hignj_2l+", "+higmet, mjcut+"&&njets>"+midjets_2l+"&&met>"+highmet+"&&" +cuts_2lbb, chain, Samples, nsig);
376  file <<"\\hline\n";
377 
378  mjcut="mj>"+mjthresh;
379  file << YieldsCut(regions[3]+": $M_J > "+mjthresh+"$", "mj>"+mjthresh+"&&"+cuts_2lbb, chain, Samples, nsig);
380  file <<"\\hline\n";
381  file << YieldsCut(indent+lownj_2l+", "+lowmet, mjcut+"&&njets<="+midjets_2l+"&&met<="+highmet+"&&"+cuts_2lbb, chain, Samples, nsig);
382  file << YieldsCut(indent+lownj_2l+", "+higmet, mjcut+"&&njets<="+midjets_2l+"&&met>"+highmet+"&&" +cuts_2lbb, chain, Samples, nsig);
383  file << YieldsCut(indent+hignj_2l+", "+lowmet, mjcut+"&&njets>"+midjets_2l+"&&met<="+highmet+"&&" +cuts_2lbb, chain, Samples, nsig);
384  file << YieldsCut(indent+hignj_2l+", "+higmet, mjcut+"&&njets>"+midjets_2l+"&&met>"+highmet+"&&" +cuts_2lbb, chain, Samples, nsig);
385  }
386 
387  file << "\\hline\\multicolumn{1}{c|}{} ";
388  for(unsigned sam(0); sam < Samples.size()-nsig; sam++)
389  file << " & "<<Samples[sam].label;
390  file<< " & SM bkg. ";
391  for(unsigned sam(Samples.size()-nsig); sam < Samples.size(); sam++)
392  file << " & "<<Samples[sam].label;
393  if (do_zbi || do_soverb) file << " & "+fom;
394  file << "\\\\ \n ";
395 
396  file<< "\\hline\\hline\n\\end{tabular}"<<endl<<endl;
397  file<<footer.rdbuf();
398  file.close();
399  cout<<endl<<" pdflatex "<<outname<<endl<<endl;
400 }
401 
402 TString YieldsCut(TString title, TString cuts, vector<TChain*> chain, vector<sfeats> Samples, int nsig){
403  TString totCut, Hname = "histo", out;
404  vector<double> yield, error;
405  double bkg(0), bkg_err(0), err, yield_sam;
406  int nsam(chain.size()), entries(0);
407  cout<<entries<<endl; // So it compiles
408  for(int sam(0); sam < nsam; sam++){
409  if (Samples[sam].label.Contains("Smeared"))
410  totCut = luminosity+"*(1/1.0287)*weight*(1+0.5*((Max$(jets_pt_res)>1.391)||Min$(jets_pt_res)<0.675))*("+cuts+"&&"+Samples[sam].cut+")";
411  //totCut = luminosity+"*weight*(1+0.5*((Max$(jets_pt_res)>1.334)||Min$(jets_pt_res)<0.777))*("+cuts+"&&"+Samples[sam].cut+")";
412  //totCut = luminosity+"*weight*("+cuts+"&&"+Samples[sam].cut+")";
413  else
414  totCut = luminosity+"*weight*("+cuts+"&&"+Samples[sam].cut+")";
415  entries = getYieldErr(*chain[sam], totCut, yield_sam, err);
416  yield.push_back(yield_sam);
417  error.push_back(err);
418  if(sam<nsam-nsig) {
419  if(yield[sam]>0) bkg += yield[sam];
420  bkg_err = sqrt(pow(bkg_err,2)+pow(err,2));
421  }
422  // cout<<sam<<": yield "<<Samples[sam].label<<" "<<yield[sam]<<", n "<<entries<<" \t "<<totCut<<endl;
423  }
424 
425  int digits(1);
426  cout<<title<<": B = "<<(RoundNumber(bkg,digits)+" +- "+RoundNumber(bkg_err,digits));
427  out = title;
428  for(int sam(0); sam < nsam-nsig; sam++) out += (" \t & " + RoundNumber(yield[sam],digits));
429  out += (" \t & $"+RoundNumber(bkg,digits))+" \\pm "+RoundNumber(bkg_err,digits)+"$";
430  for(int sam(nsam-nsig); sam < nsam; sam++) {
431  float fracerr(sqrt(pow(bkg_err/bkg,2)+0.3*0.3+0.24*0.24));
432  out += (" \t& $" + RoundNumber(yield[sam],digits)+" \\pm "+RoundNumber(error[sam],digits) + "$");
433  if(do_zbi) out += " \t& " + RoundNumber(RooStats::NumberCountingUtils::BinomialExpZ(yield[sam], bkg, fracerr),2);
434  else if (do_soverb) out += " \t& " + RoundNumber(yield[sam],2,bkg);
435 
436  cout<<", S = "<<RoundNumber(yield[sam],digits)+" +- "+RoundNumber(error[sam],digits)<<" with Zbi = ";
437  cout<<RoundNumber(RooStats::NumberCountingUtils::BinomialExpZ(yield[sam], bkg, fracerr),2);
438  }
439  out += " \\\\ \n";
440  cout<<endl;
441  return out;
442 }
long getYieldErr(TChain &tree, TString cut, double &yield, double &uncertainty)
STL namespace.
TString YieldsCut(TString title, TString cuts, vector< TChain * > chain, vector< sfeats > Samples, int nsig)
TString ntuple_date("2015_10_19")
TString RoundNumber(double num, int decimals, double denom=1.)
Definition: utilities.cpp:191
tuple file
Definition: parse_card.py:238
int main(int argc, char *argv[])
Definition: table_smear.cxx:48