10 #include "TTreeFormula.h" 11 #include "TGraphErrors.h" 35 int main(
int argc,
char *argv[]){
38 string folder_other=
"/net/cms5/cms5r0/ald77/archive/"+
ntuple_date+
"/skim/";
41 string folder =
"/net/cms29/cms29r0/heller/ra4_macros/rohanskim/";
43 string lumi_string =
"10";
46 lumi = strtod(argv[1], NULL);
47 lumi_string = argv[1];
48 if(argc>2 &&
string(
"1200")==argv[2]) compressed =
true;
58 other.
Add(folder_other+
"*TTWJets*");
59 other.
Add(folder_other+
"*TTZJets*");
60 other.
Add(folder_other+
"*_T*-channel*");
61 other.
Add(folder_other+
"*WJetsToLNu_HT*");
62 other.
Add(folder_other+
"*ZJetsToLNu_HT*");
63 other.
Add(folder_other+
"*DYJets*");
64 other.
Add(folder_other+
"*H_HToBB*");
65 small_tree_quick sig(compressed ? folder_other+
"*T1tttt*1200*800*" : folder_other+
"*T1tttt*1500*100*");
68 vector< vector<TString> > bins_by_region2;
70 vector<TString> region1;
71 region1.push_back(
"met<=400");
72 region1.push_back(
"met>400");
74 vector<TString> region2;
75 region2.push_back(
"njets<=8&&met<=400");
76 region2.push_back(
"njets<=8&&met>400");
77 region2.push_back(
"njets>8&&met<=400");
78 region2.push_back(
"njets>8&&met>400");
80 vector<TString> region3;
83 region3.push_back(
"met<=400");
84 region3.push_back(
"met>400");
86 vector<TString> region4;
87 region4.push_back(
"njets<=8&&met<=400");
88 region4.push_back(
"njets<=8&&met>400");
89 region4.push_back(
"njets>8&&met<=400");
90 region4.push_back(
"njets>8&&met>400");
92 bins_by_region2.push_back(region1);
93 bins_by_region2.push_back(region2);
94 bins_by_region2.push_back(region3);
95 bins_by_region2.push_back(region4);
99 vector< vector<TString> > bins_by_region1;
100 vector<TString> method1_region;
101 method1_region.push_back(
"njets<=8&&met<=400");
102 method1_region.push_back(
"njets<=8&&met>400");
103 method1_region.push_back(
"njets>8&&met<=400");
104 method1_region.push_back(
"njets>8&&met>400");
106 bins_by_region1.push_back(method1_region);
107 bins_by_region1.push_back(method1_region);
108 bins_by_region1.push_back(method1_region);
109 bins_by_region1.push_back(method1_region);
111 TString baseline =
"njets>=7&&nbm>=1&&(nels+nmus)==1";
112 TString dilepton =
"njets>=6&&nbm>=1&&(nels+nmus)==2";
116 vector< vector<TString> > bins_by_region = bins_by_region1;
117 TString
method =
"method2";
119 vector< TString> sysnames;
120 sysnames.push_back(
"nominal");
121 sysnames.push_back(
"nISR");
122 sysnames.push_back(
"ISRpT");
123 sysnames.push_back(
"ISRpTx150");
124 sysnames.push_back(
"toppT");
125 sysnames.push_back(
"1lep_frac");
129 int nsys=
static_cast<int>(sysnames.size());
132 vector< vector< vector<double> > > ttbar_counts, ttbar_errors;
133 vector< vector< vector<double> > > ttbar_counts_dilep, ttbar_errors_dilep;
134 vector< vector< vector<double> > > other_counts, other_errors;
135 vector< vector< vector<double> > > other_counts_dilep, other_errors_dilep;
136 vector< vector< vector<double> > > sig_counts, sig_errors;
138 vector<int> emptysamples;
139 vector<hfeats> hists, emptyhists;
141 vector< vector<TH1F*> > h, h_dilep,emptyh;
145 hists.push_back(
hfeats(
"ISRpT",20,0,1000, emptysamples,
"ISR pT",
"ht>500"));
146 hists.push_back(
hfeats(
"ntrumeisr",4,-0.5,3.5, emptysamples,
"n ME ISR",
"ht>500"));
147 hists.push_back(
hfeats(
"mj",20,0,1000, emptysamples,
"M_{J} [GeV]",
"mt>140"));
148 hists.push_back(
hfeats(
"mj",20,0,1000, emptysamples,
"M_{J} [GeV]",
"mt<=140"));
149 hists.push_back(
hfeats(
"mj",10,0,1000, emptysamples,
"M_{J} [GeV]",
"mt>140&&met>400"));
150 hists.push_back(
hfeats(
"mj",10,0,1000, emptysamples,
"M_{J} [GeV]",
"mt<=140&&met>400"));
152 hists.push_back(
hfeats(
"met",30,0,600, emptysamples,
"MET [GeV]",
"ht>500"));
153 hists.push_back(
hfeats(
"mt",20,0,280, emptysamples,
"m_{T} [GeV]",
"ht>500"));
154 hists.push_back(
hfeats(
"mt",2,0,280, emptysamples,
"m_{T} [GeV]",
"met>200"));
155 hists.push_back(
hfeats(
"mt",20,0,280, emptysamples,
"m_{T} [GeV]",
"mj>400"));
156 hists.push_back(
hfeats(
"mt",2,0,280, emptysamples,
"m_{T} [GeV]",
"mj>400&&met>200"));
157 hists.push_back(
hfeats(
"mt",2,0,280, emptysamples,
"m_{T} [GeV]",
"ntruleps==1"));
158 hists.push_back(
hfeats(
"trutop1_pt",25,0,800, emptysamples,
"top pT [GeV]",
"ht>500"));
159 hists.push_back(
hfeats(
"trutop1_pt+trutop2_pt",32,0,1600, emptysamples,
"top pT + antitop pT [GeV]",
"ht>500"));
162 int nhists =
static_cast<int>(hists.size());
165 GetCounts(lumi,sysnames, method, baseline, ttbar, ttbar_counts, ttbar_errors, bins_by_region, hists, h);
166 GetCounts(lumi,sysnames, method, dilepton, ttbar, ttbar_counts_dilep, ttbar_errors_dilep, bins_by_region, hists, h_dilep);
169 vector< TString> othersys;
170 for(
int i=0;i<nsys; i++){
171 othersys.push_back(
"nominal");
174 GetCounts(lumi,othersys, method, baseline, other, other_counts, other_errors, bins_by_region, emptyhists, emptyh);
175 GetCounts(lumi,othersys, method, dilepton, other, other_counts_dilep, other_errors_dilep, bins_by_region, emptyhists, emptyh);
177 cout<<
"got counts"<<endl;
179 ttbar_counts_dilep.at(0) = ttbar_counts.at(0);
180 ttbar_counts_dilep.at(1) = ttbar_counts.at(1);
181 ttbar_errors_dilep.at(0) = ttbar_errors.at(0);
182 ttbar_errors_dilep.at(1) = ttbar_errors.at(1);
193 vector< vector<double> > delkappas(nsys,vector<double>(4,0.0));
194 vector< vector<double> > delkappas_dilep(nsys,vector<double>(4,0.0));
195 cout<<
"initialized delkappas"<<endl;
199 vector<int> RMJ_nums; RMJ_nums.push_back(3); RMJ_nums.push_back(1);
200 vector<int> RMJ_dens; RMJ_dens.push_back(2); RMJ_dens.push_back(0);
201 vector<int> RmT_nums; RmT_nums.push_back(3); RmT_nums.push_back(2);
202 vector<int> RmT_dens; RmT_dens.push_back(1); RmT_dens.push_back(0);
203 cout<<
"making plots"<<endl;
204 for(
int is=1;is<nsys; is++){
205 cout<<
"is = "<<is<<endl;
206 MakePlots(
"R_{MJ}", RMJ_nums, RMJ_dens, ttbar_counts, ttbar_errors, bins_by_region, baseline, method, sysnames,is,delkappas[is]);
207 MakePlots(
"R_{mT}", RmT_nums, RmT_dens, ttbar_counts, ttbar_errors, bins_by_region, baseline, method, sysnames,is,delkappas[is]);
208 MakePlots(
"R_{MJ}", RMJ_nums, RMJ_dens, ttbar_counts_dilep, ttbar_errors_dilep, bins_by_region, dilepton, method, sysnames,is,delkappas_dilep[is]);
209 MakePlots(
"R_{mT}", RmT_nums, RmT_dens, ttbar_counts_dilep, ttbar_errors_dilep, bins_by_region, dilepton, method, sysnames,is,delkappas_dilep[is]);
212 PrintTable(method,ttbar_counts,ttbar_errors,ttbar_counts_dilep, other_counts, other_counts_dilep, delkappas, bins_by_region);
214 for(
int ihist=0;ihist<nhists;ihist++){
215 if(ihist==2 || ihist==3 || ihist==4 || ihist==5)
continue;
216 for(
int isy=1;isy<nsys; isy++){
218 temp.push_back(static_cast<TH1F*>(h[ihist][0]->Clone(Form(
"%i_%i",isy,ihist))));
219 temp.push_back(h[ihist][isy]);
220 OverlayHists(temp,hists[ihist],method,sysnames[isy],baseline);
224 for(
int isy=1;isy<nsys; isy++){
226 temp.push_back(static_cast<TH1F*>(h[2][0]->Clone(Form(
"%i_%i",isy,2))));
227 temp.push_back(h[2][isy]);
228 temp.push_back(static_cast<TH1F*>(h[3][0]->Clone(Form(
"%i_%i",isy,3))));
229 temp.push_back(h[3][isy]);
233 for(
int isy=1;isy<nsys; isy++){
235 temp.push_back(static_cast<TH1F*>(h[4][0]->Clone(Form(
"%i_%i",isy,4))));
236 temp.push_back(h[4][isy]);
237 temp.push_back(static_cast<TH1F*>(h[5][0]->Clone(Form(
"%i_%i",isy,5))));
238 temp.push_back(h[5][isy]);
247 void PrintTable(TString
method, vector< vector< vector<double> > > ttbar_counts, vector< vector< vector<double> > > ttbar_errors, vector< vector< vector<double> > > ttbar_counts_dilep, vector< vector< vector<double> > > other_counts,vector< vector< vector<double> > > other_counts_dilep, vector< vector<double> > delkappas, vector< vector<TString> > bins_by_region){
248 ofstream
file(
"txt/newtable_1b_"+method+
".csv");
249 for(
unsigned int ibin=0;ibin<bins_by_region.at(3).size(); ibin++){
250 int bin2 =
FindSuperBin(bins_by_region.at(3).at(ibin),bins_by_region.at(2));
251 int bin1 =
FindSuperBin(bins_by_region.at(3).at(ibin),bins_by_region.at(1));
252 int bin0 =
FindSuperBin(bins_by_region.at(3).at(ibin),bins_by_region.at(0));
254 double statabcd = sqrt(1.0/(other_counts.at(0).at(bin0).at(0)+ttbar_counts.at(0).at(bin0).at(0)) + 1.0/(other_counts.at(1).at(bin1).at(0)+ttbar_counts.at(1).at(bin1).at(0)) + 1.0/(other_counts.at(2).at(bin2).at(0)+ttbar_counts.at(2).at(bin2).at(0)));
255 double mcstat = sqrt(
sqr(ttbar_errors.at(3).at(ibin).at(0)/ttbar_counts.at(3).at(ibin).at(0))+
sqr(ttbar_errors.at(0).at(bin0).at(0)/ttbar_counts.at(0).at(bin0).at(0)) +
sqr(ttbar_errors.at(1).at(bin1).at(0)/ttbar_counts.at(1).at(bin1).at(0)) +
sqr(ttbar_errors.at(2).at(bin2).at(0)/ttbar_counts.at(2).at(bin2).at(0)));
256 double closure = sqrt(1.0/(other_counts_dilep.at(3).at(ibin).at(0)+ ttbar_counts_dilep.at(3).at(ibin).at(0)));
258 file << bins_by_region.at(3).at(ibin) <<
","<< (other_counts.at(3).at(ibin).at(0)+ttbar_counts.at(3).at(ibin).at(0))<<
","<<
sqr(1.0/closure)<<
","<<closure<<
","<<statabcd<<
","<<mcstat;
259 for(
unsigned int is=1; is< delkappas.size();is++){
260 file <<
"," <<delkappas.at(is).at(ibin);
269 if(ivar==0)
return 1.;
270 if(sysname.Contains(
"not_ttbar") )
return 1.;
271 if(sysname.Contains(
"nominal") )
return 1.;
272 if(sysname.Contains(
"Nominal") )
return 1.;
275 if(sysname.Contains(
"1lep_frac")){
281 if(sysname.Contains(
"toppT")){
291 float weight_top1pT = TMath::Exp(0.156-0.00137*t1pT);
292 float weight_top2pT = TMath::Exp(0.156-0.00137*t2pT);
293 weight = TMath::Sqrt(weight_top1pT*weight_top2pT);
296 if(sysname.Contains(
"nISR")){
297 if(tree.
ntrumeisr()>3) {cout<<
"ERROR: n ISR = "<<tree.
ntrumeisr()<<endl; weight = 1.0;}
298 else if(tree.
ntrumeisr()==3) weight = 1.5;
299 else if(tree.
ntrumeisr()==2) weight = 1.25;
300 else if(tree.
ntrumeisr()==1) weight = 1.0;
318 if(sysname.Contains(
"ISRpT")){
322 ISRpT = TMath::Sqrt(ISRpx*ISRpx+ISRpy*ISRpy);
324 if( ISRpT>800) weight = 0.2;
325 else if( ISRpT>650) weight = 0.4;
326 else if( ISRpT>500) weight = 0.6;
327 else if( ISRpT>300 ) weight = 0.8;
328 else if( ISRpT>200 ) weight = 0.9;
329 else if( ISRpT>120) weight = 0.95;
334 if(sysname.Contains(
"ISRpTx150")){
338 ISRpT = TMath::Sqrt(ISRpx*ISRpx+ISRpy*ISRpy);
340 if( ISRpT>800) weight = 0.;
341 else if( ISRpT>650) weight = 0.1;
342 else if( ISRpT>500) weight = 0.4;
343 else if( ISRpT>300 ) weight = 0.7;
344 else if( ISRpT>200 ) weight = 0.85;
345 else if( ISRpT>120) weight = 0.925;
357 vector< vector< vector<double> > > &finalcounts,
358 vector< vector< vector<double> > > &errors, vector< vector<TString> > bins_by_region, vector<hfeats> hists, vector< vector<TH1F*> > &h){
360 int nvar=sysnames.size();
362 if(baseline.Contains(
"(nels+nmus)==2")){
363 for(
unsigned int ir=0;ir<bins_by_region.size(); ir++){
364 for(
unsigned int ib=0; ib<bins_by_region[ir].size(); ib++){
365 bins_by_region[ir][ib].ReplaceAll(
"8&&",
"7&&");
375 for(
unsigned int ihist=0;ihist<hists.size();ihist++){
377 for(
int is=0;is<nvar;is++){
378 TH1F * h1 =
new TH1F(hists[ihist].varname+
"_"+sysnames[is]+baseline+
"_"+Form(
"%i",ihist),baseline+
"&&"+hists[ihist].cuts,hists[ihist].
nbins,hists[ihist].minx,hists[ihist].maxx);
386 vector< vector< vector<double> > > counts;
388 for(
int ireg=0;ireg<4;ireg++){
389 counts.push_back(vector<vector<double> >(bins_by_region.at(ireg).size(),vector<double>(nvar,0.)));
391 vector< vector< vector<double> > > squares = counts;
392 finalcounts = counts;
395 double sumw = 0., sumw2 = 0.;
399 Timer timer(num_entries, 1.);
402 for(
int entry = 0; entry < num_entries; ++entry){
411 || tree.
ht()<=500.)
continue;
415 double weight = lumi*tree.
weight();
417 float ISRpT(0);
float ISRpx(0);
float ISRpy(0);
421 ISRpT = TMath::Sqrt(ISRpx*ISRpx+ISRpy*ISRpy);
422 if(ISRpT > hists[0].maxx) ISRpT = hists[0].maxx - 0.01;
423 if(ISRpT < hists[0].minx) ISRpT = hists[0].minx + 0.01;
429 int bin =
LookUpBin(tree,region,bins_by_region);
433 for(
int ivar=0; ivar<nvar; ivar++){
435 varweight = weight*
GetWeight(tree,sysnames.at(ivar), ivar);
436 counts.at(region).at(bin).at(ivar) += varweight;
437 squares.at(region).at(bin).at(ivar) += varweight*varweight;
444 h[0][ivar]->Fill(ISRpT,varweight);
446 for(
unsigned int ih=1;ih < hists.size();ih++){
450 if(val > hists[ih].maxx) val = hists[ih].maxx - 0.01;
451 if(val < hists[ih].minx) val = hists[ih].minx + 0.01;
452 h[ih][ivar]->Fill(val,varweight);
460 sumw2 += weight*weight;
466 for(
unsigned int ireg = 0; ireg< counts.size(); ireg++){
467 for(
unsigned int ibin = 0; ibin < counts.at(ireg).size(); ++ibin){
468 for(
int ifill = 0; ifill< nvar; ifill++){
470 if(sysnames[ifill].
Contains(
"1lep_frac") && ireg==3&&ibin==3){ counts.at(ireg).at(ibin).at(ifill) += sumw2/sumw; squares.at(ireg).at(ibin).at(ifill) +=
sqr(sumw2/sumw); }
472 if(squares.at(ireg).at(ibin).at(ifill) == 0.){
474 finalcounts.at(ireg).at(ibin).at(ifill) = 0;
475 errors.at(ireg).at(ibin).at(ifill) = sumw2/sumw;
476 }
else if(counts.at(ireg).at(ibin).at(ifill) <= 0.){
478 finalcounts.at(ireg).at(ibin).at(ifill) = 0;
479 errors.at(ireg).at(ibin).at(ifill) = sqrt(squares.at(ireg).at(ibin).at(ifill)+
sqr(counts.at(ireg).at(ibin).at(ifill)));
483 finalcounts.at(ireg).at(ibin).at(ifill) = counts.at(ireg).at(ibin).at(ifill);
484 errors.at(ireg).at(ibin).at(ifill) = sqrt(squares.at(ireg).at(ibin).at(ifill));
496 TString pname =
"plots/systematics/1d/"+
format_tag(hist.
varname+baseline+hist.
cuts+
"_"+method+
"_"+sysname)+
".pdf";
497 if(sysname==
"toppT") sysname =
"top p_{T}";
502 for(
unsigned int ih=0;ih < h.size();ih++){
503 if(h[ih]->GetMaximum() > max) max = h[ih]->GetMaximum();
505 double legX = 0.6, legY = 0.89, legSingle = 0.17;
506 double legW = 0.22, legH = legSingle;
507 TLegend
leg(legX, legY-legH, legX+legW, legY);
508 leg.SetTextSize(0.057); leg.SetFillColor(0); leg.SetFillStyle(0); leg.SetBorderSize(0);
509 leg.SetTextFont(132);
511 for(
unsigned int ih=0;ih < h.size();ih++){
512 h[ih]->GetXaxis()->SetLabelSize(0.05);
513 h[ih]->GetYaxis()->SetLabelSize(0.05);
515 h[ih]->GetXaxis()->SetTitleOffset(1.15);
516 h[ih]->GetXaxis()->SetTitleSize(0.06);
518 h[ih]->GetYaxis()->SetTitle(
"Entries for 3 fb^{-1}");
520 h[ih]->GetYaxis()->SetTitleSize(0.06);
521 h[ih]->SetLineWidth(3);
522 h[ih]->SetMaximum(1.35*max);
524 if(ih==1) h[ih]->SetLineColor(kRed);
525 else h[ih]->SetLineColor(kBlack);
527 if(ih==0) leg.AddEntry(h[ih],
"Nominal t#bar{t}",
"l");
528 if(ih==1) leg.AddEntry(h[ih],sysname+
" Variation",
"l");
531 if(ih==0) h[ih]->Draw(
"hist");
532 else h[ih]->Draw(
"hist same");
544 TString pname =
"plots/systematics/1d/mt_"+
format_tag(hist.
varname+baseline+hist.
cuts+
"_"+method+
"_"+sysname)+
".pdf";
545 if(sysname==
"toppT") sysname =
"top p_{T}";
550 for(
unsigned int ih=0;ih < h.size();ih++){
551 float integral = h[ih]->Integral();
552 if(integral>0.0001) h[ih]->Scale(100./integral);
553 if(h[ih]->GetMaximum() > max) max = h[ih]->GetMaximum();
558 double legX = 0.45, legY = 0.89, legSingle = 0.25;
559 double legW = 0.22, legH = legSingle;
560 TLegend
leg(legX, legY-legH, legX+legW, legY);
561 leg.SetTextSize(0.057); leg.SetFillColor(0); leg.SetFillStyle(0); leg.SetBorderSize(0);
562 leg.SetTextFont(132);
565 for(
unsigned int ih=0;ih < h.size();ih++){
567 h[ih]->GetXaxis()->SetLabelSize(0.05);
568 h[ih]->GetYaxis()->SetLabelSize(0.05);
570 h[ih]->GetXaxis()->SetTitleOffset(1.15);
571 h[ih]->GetXaxis()->SetTitleSize(0.06);
574 h[ih]->GetYaxis()->SetTitleSize(0.06);
575 h[ih]->SetLineWidth(3);
576 h[ih]->SetMaximum(1.5*max);
577 TString title =
static_cast<TString
>(h[ih]->GetTitle());
578 if(title.Contains(
"mt>140") || ih==0 || ih==1) h[ih]->SetLineColor(kRed);
579 else h[ih]->SetLineColor(9);
581 title.ReplaceAll(
"&&mt>140",
""); title.ReplaceAll(
"&&mt<=140",
"");
583 if(ih==1 || ih==3) h[ih]->SetLineStyle(2);
585 h[ih]->GetYaxis()->SetTitle(
"Entries (%)");
587 if(ih<2) lege=
"High m_{T} t#bar{t}, ";
588 else lege=
"Low m_{T} t#bar{t}, ";
590 if(ih==1 || ih ==3) {lege+= sysname;
591 lege+=
" variation";}
592 else lege+=
"nominal";
595 leg.AddEntry(h[ih], lege,
"l");
596 if(ih==0) h[ih]->Draw(
"hist");
597 else h[ih]->Draw(
"hist same");
615 vector<int> score(other_region.size(),0);
616 int min_score=9999;
int min_bin=-1;
618 for(
unsigned int ibin=0;ibin<score.size();ibin++){
619 TObjArray * this_bin_tokens = other_region.at(ibin).Tokenize(
"&&");
620 TIter this_bin_iter(this_bin_tokens);
622 while ((os=static_cast<TObjString *>(this_bin_iter()))) {
623 if(!cut.Contains(os->GetString())) score.at(ibin)++;
625 this_bin_tokens->Delete();
626 if(score.at(ibin)<min_score){min_score=score.at(ibin); min_bin=ibin;}
628 cout<<
"Signal cut: "<<cut<<
", Closest match: "<<other_region.at(min_bin)<<
", Score: "<<min_score<<endl;
635 double mt_thresh = 140.;
637 if(method.Contains(
"method1")) mj_thresh+=200;
642 if(tree.
mt()<=mt_thresh && (tree.
nmus()+tree.
nels())==1){
643 if(tree.
mj()<=mj_thresh) reg=0;
647 if(tree.
mj()<=mj_thresh) reg=2;
657 for(
unsigned int ibin=0;ibin<bins_by_region.at(region).size();ibin++){
659 if(tree.
PassString(bins_by_region.at(region).at(ibin))) {
660 if(bin!= -1) {cout<<
"non-orthogonal bins"<<endl;}
671 void MakePlots(TString axisname, vector<int> numerator_regions, vector<int> denominator_regions, vector< vector< vector<double> > > counts,
672 vector< vector< vector<double> > > errors, vector< vector<TString> > bins_by_region, TString baseline, TString
method, vector<TString> sysnames,
int sysnum, vector<double> &delkappas ){
675 TString sysname = sysnames.at(sysnum);
676 vector<int> sysindices;
677 sysindices.push_back(0);
678 sysindices.push_back(sysnum);
679 vector< vector<int> > nums_reg_bin;
680 vector< vector<int> > dens_reg_bin;
681 cout<<
"Make Plots: sysnum, syname = "<<sysnum<<
" "<<sysname<<endl;
683 bool make_kappa=
false;
684 if(bins_by_region.at(numerator_regions.at(0)).size() ==bins_by_region.at(numerator_regions.at(1)).size()) make_kappa=
true;
686 for(
unsigned int inum=0;inum<numerator_regions.size(); inum++){
687 for(
unsigned int ibin=0; ibin< bins_by_region.at(numerator_regions.at(inum)).size(); ibin++){
689 num.push_back(numerator_regions.at(inum));
691 nums_reg_bin.push_back(num);
694 den.push_back(denominator_regions.at(inum));
695 int denbin =
FindSuperBin(bins_by_region.at(numerator_regions.at(inum)).at(ibin),bins_by_region.at(denominator_regions.at(inum)));
696 if(denbin<0) cout<<
"failed to find denominator bin"<<endl;
697 den.push_back(denbin);
698 dens_reg_bin.push_back(den);
702 int npoints =
static_cast<int>(nums_reg_bin.size());
703 vector<TGraphErrors*> g_Rs;
704 vector<TGraphErrors*> g_kappas;
705 int npoints_kappa =
static_cast<int>(bins_by_region.at(numerator_regions.at(0)).size());
708 for(
unsigned int is=0;is<sysindices.size();is++){
709 int isys = sysindices.at(is);
711 vector<double> R(npoints,0.);
712 vector<double> eR(npoints,0.);
713 vector<double> x(npoints,0.);
714 vector<double> ex(npoints,0.);
716 vector<double>
kappa(npoints_kappa,0.);
717 vector<double> ekappa(npoints_kappa,0.);
718 vector<double> xkappa(npoints_kappa,0.);
719 vector<double> exkappa(npoints_kappa,0.);
722 cout<<
"inside MakePlots loop: isys = "<<isys<<endl;
723 for(
int ipoint = 0; ipoint <
npoints; ipoint++){
725 double numerator(0), denominator(0), enumer(0), edenom(0);
727 numerator = counts.at(nums_reg_bin[ipoint][0]).at(nums_reg_bin[ipoint][1]).at(isys);
728 enumer = errors.at(nums_reg_bin[ipoint][0]).at(nums_reg_bin[ipoint][1]).at(isys);
729 denominator = counts.at(dens_reg_bin[ipoint][0]).at(dens_reg_bin[ipoint][1]).at(isys);
730 edenom = errors.at(dens_reg_bin[ipoint][0]).at(dens_reg_bin[ipoint][1]).at(isys);
733 if(denominator<=0) denominator = edenom;
735 R[ipoint] = numerator/denominator;
736 if(R[ipoint]>max) max = R[ipoint];
739 if(numerator<=0) numerator = enumer;
740 eR[ipoint] = R[ipoint] * sqrt(
sqr(enumer/numerator)+
sqr(edenom/denominator));
742 if(make_kappa && ipoint >= npoints_kappa){
743 cout<<
"making kappa"<<endl;
744 double knum = R[ipoint - npoints_kappa];
745 double kden = numerator/denominator;
746 double eknum = eR[ipoint - npoints_kappa];
747 double ekden = eR[ipoint];
749 kappa[ipoint - npoints_kappa] = knum/kden;
750 if(kappa[ipoint - npoints_kappa]>maxkappa) maxkappa = kappa[ipoint - npoints_kappa];
751 if(knum==0) ekappa[ipoint - npoints_kappa]= 0.0;
752 else ekappa[ipoint - npoints_kappa] = kappa[ipoint - npoints_kappa]*sqrt(
sqr(eknum/knum)+
sqr(ekden/kden));
754 xkappa[ipoint - npoints_kappa]= ipoint - npoints_kappa + 0.1*is;
755 exkappa[ipoint - npoints_kappa]=0;
760 x[ipoint]=ipoint+0.1*is;
765 TGraphErrors *g1 =
new TGraphErrors(npoints,&x[0],&R[0],&ex[0],&eR[0]);
768 TGraphErrors *gkappa =
new TGraphErrors(npoints_kappa,&xkappa[0],&kappa[0],&exkappa[0],&ekappa[0]);
769 g_kappas.push_back(gkappa);
775 delkappas.resize(npoints_kappa);
776 if(g_kappas.size() ==2){
777 for(
int ibin=0;ibin<npoints_kappa;ibin++){
778 cout<<
"kappa loop ibin = "<<ibin<<endl;
779 double x1(0),y1(0),x2(0),y2(0);
780 g_kappas.at(0)->GetPoint(ibin,x1,y1);
781 g_kappas.at(1)->GetPoint(ibin,x2,y2);
782 delkappas.at(ibin) = fabs(y1-y2)/y1;
783 cout<<Form(
"delkappa %i = %.3f", ibin+1, delkappas.at(ibin))<<endl;
789 styles style(
"RA4"); style.setDefaultStyle();
792 h =
new TH1F(
"for_axis_label",
cuts2title(baseline),npoints,-0.5,npoints-0.5);
794 for (
int ih=1;ih<=
npoints;ih++){
796 h->GetXaxis()->SetBinLabel(ih,
cuts2title(bins_by_region.at(nums_reg_bin[ipoint][0]).at(nums_reg_bin[ipoint][1])));
799 h->SetMaximum(1.5*max);
801 h->GetXaxis()->SetLabelSize(0.04);
802 h->GetYaxis()->SetTitle(axisname);
805 double legX = 0.65, legY = 0.89, legSingle = 0.14;
806 double legW = 0.22, legH = legSingle;
807 TLegend
leg(legX, legY-legH, legX+legW, legY);
808 leg.SetTextSize(0.057); leg.SetFillColor(0); leg.SetFillStyle(0); leg.SetBorderSize(0);
809 leg.SetTextFont(132);
814 vector<TString> labels;
815 labels.push_back(
"Nominal");
816 for(
unsigned int i=1;i<sysnames.size();i++){
817 if(i!=4) labels.push_back(sysnames[i]+
" Variation");
818 if(i==4) labels.push_back(
"top p_{T} Variation");
820 for(
unsigned int ivar=0; ivar<sysindices.size(); ivar++){
821 int isys = sysindices.at(ivar);
827 g_Rs.at(ivar)->SetMarkerStyle(22);
828 g_Rs.at(ivar)->SetMarkerColor(9);
829 g_Rs.at(ivar)->SetLineColor(9);
833 g_Rs.at(ivar)->SetMarkerStyle(20);
834 g_Rs.at(ivar)->SetMarkerColor(8);
835 g_Rs.at(ivar)->SetLineColor(8);
837 g_Rs.at(ivar)->SetMarkerSize(2);
838 g_Rs.at(ivar)->Draw(
"PZ");
839 leg.AddEntry(g_Rs.at(ivar), labels[isys],
"p");
843 TLine line; line.SetLineColor(28); line.SetLineWidth(4); line.SetLineStyle(2);
844 line.DrawLine(3.5, 0, 3.5, 1.5*max);
847 TString external_cut=
"";
848 if(axisname.Contains(
"{MJ}")) external_cut=
"m_{T}";
849 if(axisname.Contains(
"{mT}")) external_cut=
"M_{J}";
851 TLatex *text1 =
new TLatex(0.35,0.03,
"high "+external_cut);
853 text1->SetTextSize(0.04);
854 text1->SetLineWidth(2);
856 TLatex *text2 =
new TLatex(0.7,0.03,
"low "+external_cut);
858 text2->SetTextSize(0.04);
859 text2->SetLineWidth(2);
862 TString pname =
"plots/systematics/"+
format_tag(axisname+
"_"+method+
"_"+sysname+baseline)+
".pdf";
865 for(
unsigned int ivar=0; ivar<g_Rs.size(); ivar++){
866 g_Rs.at(ivar)->Delete();
873 TH1F *h3 =
new TH1F(
"for_axis_label2",
cuts2title(baseline),npoints_kappa,-0.5,npoints_kappa-0.5);
874 for (
unsigned int ih=1;ih<=bins_by_region.at(3).size();ih++){
875 h3->GetXaxis()->SetBinLabel(ih,
cuts2title(bins_by_region.at(3).at(ih-1)));
878 h3->SetMaximum(1.5*maxkappa);
880 h3->GetXaxis()->SetLabelSize(0.05);
881 h3->GetYaxis()->SetTitle(
"Kappa");
884 TLegend leg3(legX, legY-legH, legX+legW, legY);
885 leg3.SetTextSize(0.057); leg3.SetFillColor(0); leg3.SetFillStyle(0); leg3.SetBorderSize(0);
886 leg3.SetTextFont(132);
888 for(
unsigned int ivar=0; ivar<sysindices.size(); ivar++){
889 int isys = sysindices.at(ivar);
890 if(isys>1) cout<<
"need more colors"<<endl;
897 g_kappas.at(ivar)->SetMarkerStyle(22);
898 g_kappas.at(ivar)->SetMarkerColor(9);
899 g_kappas.at(ivar)->SetLineColor(9);
903 g_kappas.at(ivar)->SetMarkerStyle(20);
904 g_kappas.at(ivar)->SetMarkerColor(8);
905 g_kappas.at(ivar)->SetLineColor(8);
908 g_kappas.at(ivar)->SetMarkerSize(2);
909 g_kappas.at(ivar)->Draw(
"PZ");
910 leg3.AddEntry(g_kappas.at(ivar), labels[isys],
"p");
914 TString pname3 =
"plots/systematics/kappas_"+
format_tag(method+
"_"+sysname+baseline)+
".pdf";
917 for(
unsigned int ivar=0; ivar<g_kappas.size(); ivar++){
918 g_kappas.at(ivar)->Delete();
virtual int const & ntruleps() const
void GetCounts(double lumi, vector< TString > sysnames, TString method, TString baseline, small_tree_quick &tree, vector< vector< vector< double > > > &finalcounts, vector< vector< vector< double > > > &errors, vector< vector< TString > > bins_by_region, vector< hfeats > hists, vector< vector< TH1F * > > &h)
float const & weight() const
bool Contains(const std::string &text, const std::string &pattern)
virtual float const & trutop1_phi() const
std::string ntuple_date("2015_06_05")
TString cuts2title(TString title)
int LookUpRegion(small_tree_quick &tree, TString method)
virtual float const & trutop2_pt() const
int LookUpBin(small_tree_quick &tree, int region, vector< vector< TString > > bins_by_region)
virtual float const & trutop1_pt() const
virtual int const & ntrumeisr() const
void OverlayHistsmT(vector< TH1F * > h, hfeats hist, TString method, TString sysname, TString baseline)
float const & met() const
TString format_tag(TString tag)
float GetBranchValue(TString branch)
virtual float const & mj() const
void OverlayHists(vector< TH1F * > h, hfeats hist, TString method, TString sysname, TString baseline)
void MakePlots(TString axisname, vector< int > numerator_regions, vector< int > denominator_regions, vector< vector< vector< double > > > counts, vector< vector< vector< double > > > errors, vector< vector< TString > > bins_by_region, TString baseline, TString method, vector< TString > sysnames, int sysnum, vector< double > &delkappas)
int FindSuperBin(TString cut, vector< TString > other_region)
int main(int argc, char *argv[])
int const & njets() const
virtual void GetEntry(const long entry)
double GetWeight(small_tree_quick &tree, TString sysname, int ivar)
void PrintTable(TString method, vector< vector< vector< double > > > ttbar_counts, vector< vector< vector< double > > > ttbar_errors, vector< vector< vector< double > > > ttbar_counts_dilep, vector< vector< vector< double > > > other_counts, vector< vector< vector< double > > > other_counts_dilep, vector< vector< double > > delkappas, vector< vector< TString > > bins_by_region)
virtual float const & trutop2_phi() const
int Add(const std::string &filename)
bool PassString(TString cut)