ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
(Generate patch)

Comparing UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C (file contents):
Revision 1.75 by buchmann, Tue Dec 4 12:31:52 2012 UTC vs.
Revision 1.89 by buchmann, Mon Apr 8 14:14:42 2013 UTC

# Line 87 | Line 87 | void find_one_peak_combination(TCut spec
87    delete tempcan;
88   }
89  
90 + void DoPeakVsPU() {
91 +  cout << "Trying to find peak position as a function of PU" << endl;
92 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
93 +  stringstream result, datajzb, mcjzb;
94 +  bool doPUreweighting=true;
95 +  bool SwitchOffNJetsCut=false;
96 +  
97 +  
98 +  TCanvas *can = new TCanvas("can","can");
99 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
100 +  
101 +  float NumVtxBin[6] = {0,5,10,15,20,30};
102 +  
103 +  stringstream NowCut;
104 +  
105 +  TGraphErrors *gMCPeak = new TGraphErrors();
106 +  gMCPeak->SetTitle("gMCPeak");
107 +  gMCPeak->SetName("gMCPeak");
108 +  TGraphErrors *gDataPeak = new TGraphErrors();
109 +  gDataPeak->SetTitle("gDataPeak");
110 +  gDataPeak->SetName("gDataPeak");
111 +  TGraphErrors *gMCWidth = new TGraphErrors();
112 +  gMCWidth->SetTitle("gMCWidth");
113 +  gMCWidth->SetName("gMCWidth");
114 +  TGraphErrors *gDataWidth = new TGraphErrors();
115 +  gDataWidth->SetTitle("gDataWidth");
116 +  gDataWidth->SetName("gDataWidth");
117 +  
118 +  for(int i=0;i<5;i++) {
119 +    NowCut.str("");
120 +    NowCut << "numVtx>=" << NumVtxBin[i] << "&&numVtx<" << NumVtxBin[i+1];
121 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
122 +    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
123 +    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
124 +    
125 +    gMCPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),MCPeak);
126 +    gMCPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),MCPeakError);
127 +    
128 +    gDataPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),DataPeak);
129 +    gDataPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),DataPeakError);
130 +    
131 +    gMCWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),mcSigma);
132 +    gMCWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),mcSigmaError);
133 +    
134 +    gDataWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),dataSigma);
135 +    gDataWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),dataSigmaError);
136 +  }
137 +  
138 +  can->cd();
139 +  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
140 +  gMCPeak->GetYaxis()->SetTitle("Peak position");
141 +  gMCPeak->GetXaxis()->CenterTitle();
142 +  gMCPeak->GetYaxis()->CenterTitle();
143 +  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
144 +  gDataPeak->GetYaxis()->SetTitle("Peak position");
145 +  gDataPeak->GetXaxis()->CenterTitle();
146 +  gDataPeak->GetYaxis()->CenterTitle();
147 +  
148 +  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
149 +  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
150 +  gDataWidth->GetXaxis()->CenterTitle();
151 +  gDataWidth->GetYaxis()->CenterTitle();
152 +  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
153 +  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
154 +  gMCWidth->GetXaxis()->CenterTitle();
155 +  gMCWidth->GetYaxis()->CenterTitle();
156 +  
157 +  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
158 +  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
159 +  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
160 +  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
161 +  
162 +  gMCPeak->Draw("A2");
163 +  DrawMCPrelim();
164 +  CompleteSave(can,"PUStudy/MCPeak");
165 +  can->cd();
166 +  gMCWidth->Draw("A2");
167 +  DrawMCPrelim();
168 +  CompleteSave(can,"PUStudy/MCWidth");
169 +  can->cd();
170 +  
171 +  gDataPeak->Draw("A2");
172 +  DrawPrelim();
173 +  CompleteSave(can,"PUStudy/DataPeak");
174 +  can->cd();
175 +  gDataWidth->Draw("A2");
176 +  DrawPrelim();
177 +  CompleteSave(can,"PUStudy/DataWidth");
178 +  
179 +  
180 +  
181 +  delete can;
182 +  
183 + }
184 +
185   void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb, string sSpecialCut="", bool SwitchOffNJetsCut=false)
186   {
187    bool overunderflowstatus=addoverunderflowbins;
# Line 228 | Line 323 | void make_special_obs_pred_mll_plot(stri
323    
324    RcorrJZBeemm->SetTitleOffset(1.3,"y");
325    RcorrJZBeemm->Draw();
326 <  mcRcorrJZBeemm.Draw("same");
326 >  mcRcorrJZBeemm.Draw("histo,same");
327    Bpred->Draw("histo,same");
328    RcorrJZBeemm->Draw("same");
329    
330    TLegend *leg = allsamples.allbglegend();
331    leg->SetX1(0.58);
332 <  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
332 > //  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
333    leg->AddEntry(Bpred,"predicted (data)","l");
334    leg->Draw("same");
335    
# Line 262 | Line 357 | void make_special_obs_pred_mll_plot(stri
357    RcorrJZBeemm->Draw("same");
358    
359    TLegend *leg2 = make_legend("",0.52,0.7);
360 <  leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
360 > //  leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
361    leg2->AddEntry(Bpred,"predicted (data)","l");
362    leg2->AddEntry(SFN,  "  SF JZB<0","l");
363    leg2->AddEntry(OFN,  "  OF JZB<0","l");
# Line 285 | Line 380 | void make_special_obs_pred_mll_plot(stri
380    }
381    delete Bpred;
382    delete ckin;
383 +  CleanLegends();
384   }
385  
386   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
# Line 331 | Line 427 | void make_special_mll_plot(int nbins, fl
427    delete datahistoOSOF;
428    delete datahistoOSSF;
429    delete ckin;
430 +  CleanLegends();
431   }
432    
433  
# Line 384 | Line 481 | float make_one_OFSF_plot(string variable
481  
482    cutOF = cutOSOF&&cutnJets&&ibasiccut;
483    cutSF = cutOSSF&&cutnJets&&ibasiccut;
484 +  
485 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
486  
388  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
487    TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
488    rcan->SetLogy(logscale);
489    rcan->cd();
# Line 410 | Line 508 | float make_one_OFSF_plot(string variable
508    }
509    if (ymax<0) {
510      if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
511 <    else datahistoSF->SetMaximum(1.8*datahistoSF->GetMaximum());
511 >    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
512    } else {
513      datahistoSF->SetMaximum(ymax);
514    }
# Line 437 | Line 535 | float make_one_OFSF_plot(string variable
535    mleg->Draw();
536    DrawPrelim();
537    if (datahistoOF->Integral()>0) {
538 <    save_with_ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
538 >    Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
539    } else {
540      CompleteSave(rcan, "SFOF/" + filename);
443    delete rcan;
541    }
542  
543    datahistoSF->Delete();
544    datahistoOF->Delete();
545    //signalhisto->Delete();
546    delete mleg;
547 <  delete ckin;
547 >  delete rcan;
548 >  delete ofsf_can;
549  
550    return ymaxSet;
551  
# Line 500 | Line 598 | float make_data_comparison_plot(string v
598    data2->Draw("HIST,SAMES");
599    mleg->Draw();
600    DrawPrelim();
601 <  save_with_ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
601 >  Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
602  
603    data1->Delete();
604    data2->Delete();
605    delete mleg;
606 +  delete rcan;
607    delete ckin;
608  
609   }
# Line 537 | Line 636 | void make_OFSF_plots(string variable, st
636  
637   }
638  
639 + TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
640 +  string scut=(string)(const char*)cut;
641 +  string acut=ReplaceAll(scut,replacethis,withthis);
642 +  return TCut(acut.c_str());
643 + }
644 +
645 + void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
646 +  TCut cut=addcut&&basiccut;
647 +
648 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
649 +  ckin->SetLogy(dolog);
650 +  cout << "\r Creating " << filename << " : data   (1/6)" << std::flush;
651 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
652 +  datahisto->SetMarkerSize(DataMarkerSize);
653 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
654 +  else datahisto->SetMinimum(0.5);
655 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
656 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
657 +  cout << "\r Creating " << filename << " : MC central   (2/6)" << std::flush;
658 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
659 +  TH1F *MCcentral = CollapseStack(mcstack);
660 +
661 +  TCut bkpcut = cut;
662 +  cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
663 +  cout << "\r Creating " << filename << " : MC JES up   (3/6)" << std::flush;
664 +  TH1F *MCJESup   = allsamples.Draw("MCJESup",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
665 +
666 +  cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
667 +  cout << "\r Creating " << filename << " : MC JES down   (4/6)" << std::flush;
668 +  TH1F *MCJESdn   = allsamples.Draw("MCJESdn",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
669 +  
670 +  cut=bkpcut;
671 +  TCut bkpweight = cutWeight;
672 +  cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
673 +  cout << "\r Creating " << filename << " : MC PU up   (5/6)" << std::flush;
674 +  TH1F *MCPUup    = allsamples.Draw("MCPUup",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
675 +  
676 +  cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
677 +  cout << "\r Creating " << filename << " : MC PU down   (6/6)" << std::flush;
678 +  TH1F *MCPUdn    = allsamples.Draw("MCPUdn",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
679 +  cutWeight=bkpweight;
680 +  cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
681 +  TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
682 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
683 +    float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
684 +    float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
685 +    float jes   = jesdn>jesup?jesdn:jesup;
686 +    
687 +    float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
688 +    float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
689 +    float pu   = PUdn>PUup?PUdn:PUup;
690 +    
691 +    float sys=sqrt(jes*jes+pu*pu);
692 +    sys/=MCcentral->GetBinContent(i);
693 +    if(MCcentral->GetBinContent(i)==0) sys=0;
694 +    Systematic->SetBinContent(i,sys);
695 +  }
696 +  
697 +  datahisto->Draw("e1");
698 +  ckin->Update();
699 +  mcstack.Draw("histo,same");
700 +  
701 +  datahisto->Draw("same,e1");
702 +  TLegend *kinleg = allsamples.allbglegend();
703 +  kinleg->Draw();
704 +
705 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
706 +  kinpad->SetLogy(dolog);
707 +  kinpad->cd();
708 +  datahisto->Draw("e1");
709 +  mcstack.Draw("histo,same");
710 +  datahisto->Draw("same,e1");
711 +  datahisto->Draw("same,axis");
712 +  
713 +  kinleg->Draw("same");
714 +  DrawPrelim();
715 +  string saveas="kin/"+filename;
716 +  
717 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
718 +  save_with_ratio_and_sys_band( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
719 +  
720 +  ckin->cd();
721 +  MCcentral->SetFillColor(kWhite);
722 +  MCcentral->SetLineColor(kBlack);
723 +  MCcentral->SetLineWidth(2);
724 +  MCPUdn->SetLineColor(kRed);
725 +  MCPUup->SetLineColor(kYellow);
726 +  MCJESdn->SetLineColor(kBlue);
727 +  MCJESup->SetLineColor(kGreen);
728 +  
729 +  TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
730 +  legsmall->SetNColumns(5);
731 +  legsmall->AddEntry(MCcentral,"central","L");
732 +  legsmall->AddEntry(MCPUdn,"PU down","L");
733 +  legsmall->AddEntry(MCPUup,"PU up","L");
734 +  legsmall->AddEntry(MCJESdn,"JES down","L");
735 +  legsmall->AddEntry(MCJESup,"JES up","L");
736 +  legsmall->SetFillColor(kWhite);
737 +  legsmall->SetBorderSize(0);
738 +  
739 +  datahisto->Draw("e1");
740 +  MCcentral->Draw("histo,same");
741 +  MCPUdn->Draw("histo,same");
742 +  MCPUup->Draw("histo,same");
743 +  MCJESdn->Draw("histo,same");
744 +  MCJESup->Draw("histo,same");
745 +  datahisto->Draw("e1,same");
746 +  legsmall->Draw();
747 +  CompleteSave(ckin,saveas+"___AllLines");
748 +  
749 +  delete datahisto;
750 +  delete MCcentral;
751 +  delete MCPUdn;
752 +  delete MCPUup;
753 +  delete MCJESdn;
754 +  delete MCJESup;
755 +  delete ckin;
756 + }
757  
758 + void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
759 +  DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
760 + }
761 +  
762   float lastrange_min=0;
763   float lastrange_max=0;
764  
# Line 688 | Line 909 | void make_kin_plot(string variable, stri
909          DrawPrelim();
910          string saveas="kin/"+filename;
911          if(isPF) saveas="kin/"+filename+"__PF";
912 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
912 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
913   //      if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
914   //      else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
915   //      delete with_ratio;
# Line 751 | Line 972 | void make_plain_kin_plot(string variable
972          DrawPrelim();
973          string saveas="kin/"+filename;
974          if(isPF) saveas="kin/"+filename+"__PF";
975 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
975 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
976    } else {
977          if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
978          else CompleteSave(ckin,"kin/"+filename);
# Line 803 | Line 1024 | void make_JES_plot(TCut cut, string name
1024    CompleteSave(ckin,"Systematics/JES"+name);
1025    datahisto->Delete();
1026    delete ckin;
1027 <
1027 >  delete JESunc;
1028 >  delete JESup;
1029 >  delete JESdn;
1030 >  CleanLegends();
1031   }
1032  
1033   string Cut2Str(TCut cut) {
# Line 843 | Line 1067 | void MakeElegantTwoThreeComparisons() {
1067      leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1068      leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1069      leg_SFOF_Two->Draw();
1070 <    save_with_ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1070 >    Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1071      
1072      TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1073      kin4->cd();
# Line 854 | Line 1078 | void MakeElegantTwoThreeComparisons() {
1078      leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1079      leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1080      leg_SFOF_Three->Draw();
1081 <    save_with_ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1081 >    Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1082      
1083      
1084      TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
# Line 867 | Line 1091 | void MakeElegantTwoThreeComparisons() {
1091      leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1092      leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1093      leg_SF_Two_Three->Draw();
1094 <    save_with_ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1094 >    Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1095      
1096      TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1097      TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
# Line 879 | Line 1103 | void MakeElegantTwoThreeComparisons() {
1103      leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1104      leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1105      leg_OF_Two_Three->Draw();
1106 <    save_with_ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1106 >    Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1107 >    
1108 > }
1109 >
1110 > void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1111 >  pad->cd();
1112 >  TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1113 >  for(int i=1;i<=Down->GetNbinsX();i++) {
1114 >    float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1115 >    float error=abs(Down->GetBinContent(i)-average);
1116 >    gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1117 >    gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1118 >  }
1119 >  gr->SetFillColor(TColor::GetColor("#F79F81"));
1120 >  gr->GetYaxis()->SetRangeUser(0,2);
1121 >  gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1122 >  gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1123 >  gr->GetXaxis()->CenterTitle();
1124 >  gr->GetYaxis()->CenterTitle();
1125 >  
1126 >  gr->Draw("A2");
1127 >  central->Draw("e1,same");
1128 >  DrawMCPrelim();
1129 >  TText *rtitle = write_text(0.8,0.8,title);
1130 >  TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1131 >  line->SetLineColor(kBlue);
1132 >  line->SetLineStyle(2);
1133 >  line->Draw("same");
1134 >  rtitle->Draw("same");
1135 > }
1136 >
1137 > TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1138 >  TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1139 >  basehisto->Add(originalttbar,-1);
1140 >  basehisto->Add(httbar);
1141 >  
1142 >  string sname=httbar->GetName();
1143 >  sname="R"+sname.substr(1,sname.length());
1144 >  TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1145 >  ratio->Divide(basehisto);
1146 >  delete basehisto;
1147 >  return ratio;
1148 > }
1149 >  
1150 > void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1151 >  
1152 >  TCut cut=addcut&&basiccut;
1153 >  
1154 >  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1155 >  ckin->SetLogy(dolog);
1156 >  cout << "\r Creating " << filename << " : data   (1/7)" << std::flush;
1157 >  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1158 >  datahisto->SetMarkerSize(DataMarkerSize);
1159 >  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1160 >  else datahisto->SetMinimum(0.5);
1161 >  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1162 >  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1163 >  cout << "\r Creating " << filename << " : MC central  (stack) (2/7)" << std::flush;
1164 >  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1165 >  TH1F *MCcentral = CollapseStack(mcstack);
1166 >
1167 >  cout << "\r Creating " << filename << " : MC central (histo)   (3/7)" << std::flush;
1168 >  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("TTJets_"));
1169 >  TH1F *RCentral        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1170 >  
1171 >  cout << "\r Creating " << filename << " : MC Matching up   (4/7)" << std::flush;
1172 >  TH1F *TMatchingUp     = systsamples.Draw("TMatchingUp",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1173 >  TH1F *RMatchingUp     = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1174 >  
1175 >  cout << "\r Creating " << filename << " : MC Matching down   (5/7)" << std::flush;
1176 >  TH1F *TMatchingDown   = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1177 >  TH1F *RMatchingDown   = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1178 >  
1179 >  cout << "\r Creating " << filename << " : MC Scale up   (6/7)" << std::flush;
1180 >  TH1F *TScaleUp        = systsamples.Draw("TScaleUp",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1181 >  TH1F *RScaleUp        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1182 >  
1183 >  cout << "\r Creating " << filename << " : MC Scale down   (7/7)" << std::flush;
1184 >  TH1F *TScaleDown      = systsamples.Draw("TScaleDown",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1185 >  TH1F *RScaleDown      = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1186 >  
1187 >  datahisto->Draw("e1");
1188 >  ckin->Update();
1189 >  mcstack.Draw("histo,same");
1190 >  
1191 >  datahisto->Draw("same,e1");
1192 >  TLegend *kinleg = allsamples.allbglegend();
1193 >  kinleg->Draw();
1194 >
1195 >  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1196 >  kinpad->SetLogy(dolog);
1197 >  kinpad->cd();
1198 >  datahisto->Draw("e1");
1199 >  mcstack.Draw("histo,same");
1200 >  datahisto->Draw("same,e1");
1201 >  datahisto->Draw("same,axis");
1202 >  
1203 >  kinleg->Draw("same");
1204 >  DrawPrelim();
1205 >  string saveas="kin/"+filename;
1206 >  
1207 >  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1208 >  Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1209 >  delete kinpad;
1210 >  
1211 >  ckin->cd();
1212 >  TCentral->SetLineColor(kBlack);
1213 >  
1214 >  TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1215 >  TMatchingUp->SetLineStyle(2);//dashed
1216 >  TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1217 >  TMatchingDown->SetLineStyle(3);//dotted
1218 >  
1219 >  TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1220 >  TScaleUp->SetLineStyle(2);//dashed
1221 >  TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1222 >  TScaleDown->SetLineStyle(3);//dotted
1223 >  
1224 >  MCcentral->SetLineStyle(3);
1225 >  MCcentral->SetLineColor(kRed);
1226 >  
1227 >  TCentral->Draw("e1,same");
1228 >  TCentral->Draw("histo,same");
1229 >  TMatchingUp->Draw("histo,same");
1230 >  TMatchingDown->Draw("histo,same");
1231 >  TScaleUp->Draw("histo,same");
1232 >  TScaleDown->Draw("histo,same");
1233 >  
1234 >  TLegend *sleg = make_legend();
1235 >  sleg->AddEntry(TCentral,"Central","L");
1236 >  sleg->AddEntry(TMatchingUp,"matching up","L");
1237 >  sleg->AddEntry(TMatchingDown,"matching down","L");
1238 >  sleg->AddEntry(TScaleUp,"scale up","L");
1239 >  sleg->AddEntry(TScaleDown,"scale down","L");
1240 >  sleg->Draw();
1241 >  
1242 >  CompleteSave(ckin,saveas+"___AllLines");
1243 >  ckin->cd();
1244 >  ckin->SetLogy(0);
1245 >  
1246 >  RCentral->SetLineColor(kBlack);
1247 >  
1248 >  RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1249 >  RMatchingUp->SetLineStyle(2);//dashed
1250 >  RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1251 >  RMatchingDown->SetLineStyle(3);//dotted
1252 >  
1253 >  RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1254 >  RScaleUp->SetLineStyle(2);//dashed
1255 >  RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1256 >  RScaleDown->SetLineStyle(3);//dotted
1257 >  
1258 >  RCentral->GetYaxis()->SetRangeUser(0,2);
1259 >  RCentral->Draw("e1");
1260 >  RMatchingUp->Draw("histo,same");
1261 >  RMatchingDown->Draw("histo,same");
1262 >  RScaleUp->Draw("histo,same");
1263 >  RScaleDown->Draw("histo,same");
1264 >  
1265 >  CompleteSave(ckin,saveas+"___AllRatios");
1266 >
1267 >  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1268 >  multicanvas->Divide(2,1);
1269 >  PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1270 >  PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1271 >  CompleteSave(multicanvas,saveas+"___RangeIllustration");
1272 >  
1273 >  
1274 >  delete datahisto;
1275 >  delete   TCentral;
1276 >  delete   TMatchingUp;
1277 >  delete   TMatchingDown;
1278 >  delete   TScaleUp;
1279 >  delete   TScaleDown;
1280 > //   delete   Ttmass166;
1281 > //   delete   Ttmass169;
1282 > //   delete   Ttmass175;
1283 > //   delete   Ttmass178;
1284 >  
1285 >  delete ckin;
1286 >  
1287 > }
1288 >  
1289 > void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1290 >  make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1291 > }
1292 >
1293 > void ProduceJanPlots() {
1294 >  TCanvas *c1 = new TCanvas("c1","c1");
1295 >  TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1296 >  TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1297 >  
1298 >  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1299 >  rcan->cd();
1300 >
1301 >  metOF->SetLineColor(kRed);
1302 >  metSF->Draw("e1");
1303 >  metOF->Draw("histo,same");
1304 >  metSF->Draw("e1,same");
1305 >  
1306 >  TLegend *leg = make_legend();
1307 >  
1308 >  leg->AddEntry(metSF,"Data SF","p");
1309 >  leg->AddEntry(metOF,"Data OF","l");
1310 >  leg->Draw();
1311 >  
1312 >  DrawPrelim();
1313 >  
1314 >  Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1315 >  
1316 >  delete rcan;
1317 >  delete metSF;
1318 >  delete metOF;
1319 >  delete c1;
1320 > }
1321 >
1322 > THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1323 >  THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1324 >  
1325 >  //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1326 >  if(variation!="Central") {
1327 >    TH1F *varttbar;
1328 >    if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1329 >    if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1330 >    if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1331 >    if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1332 >    assert(varttbar);
1333 >    
1334 >    TIter nextHisto(SystPlot.GetHists());
1335 >    TH1F* h;
1336 >    while ( h = (TH1F*)nextHisto() ) {
1337 >      if(Contains(h->GetName(),"t_bar_t")) {
1338 >        varttbar->Scale(h->Integral()/varttbar->Integral());
1339 >        for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1340 >          h->SetBinContent(i,varttbar->GetBinContent(i));
1341 >          h->SetBinError(i,varttbar->GetBinError(i));
1342 >        }
1343 >        thisto=(TH1F*)varttbar->Clone(variation.c_str());
1344 >        SystPlot.Modified();
1345 >      }
1346 >    }
1347 >    delete varttbar;
1348 >  } else {
1349 >    TIter nextHisto(SystPlot.GetHists());
1350 >    TH1F* h;
1351 >    while ( h = (TH1F*)nextHisto() ) {
1352 >      if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1353 >    }
1354 >  }
1355 >    
1356 >  TLegend *fullleg = allsamples.allbglegend();
1357 >  fullleg->SetHeader(variation.c_str());
1358 >  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1359 >  kinpad->SetLogy(1);
1360 >  kinpad->cd();
1361 >  
1362 >  hdata->Draw("e1");
1363 >  SystPlot.Draw("histo,same");
1364 >  hdata->Draw("e1,same");
1365 >  fullleg->Draw();
1366 >  DrawPrelim();
1367 >  
1368 >  Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1369 >  CleanLegends();
1370 >  
1371 >  delete kinpad;
1372 >  return SystPlot;
1373 > }
1374 >  
1375 >
1376 >
1377 > void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1378 >  TCanvas *ca = new TCanvas("ca","ca");
1379 >  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1380 >  
1381 >  TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1382 >  
1383 >  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1384 >  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1385 >  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1386 >  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1387 >  
1388 >  TH1F *HScaleUp = CollapseStack(ScaleUp);
1389 >  TH1F *HScaleDown = CollapseStack(ScaleDown);
1390 >  TH1F *HMatchingUp = CollapseStack(MatchingUp);
1391 >  TH1F *HMatchingDown = CollapseStack(MatchingDown);
1392 >  
1393 >  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1394 >  TH1F *HCentral = CollapseStack(Central);
1395 >  
1396 >  TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1397 >  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1398 >    float matchingup   = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1399 >    float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1400 >    float scaleup   = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1401 >    float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1402 >    
1403 >    float matching = matchingup>matchingdown?matchingup:matchingdown;
1404 >    float scale    = scaleup>scaledown?scaleup:scaledown;
1405 >    
1406 >    float sys=sqrt(matching*matching+scale*scale);
1407 >    sys/=HCentral->GetBinContent(i);
1408 >    if(HCentral->GetBinContent(i)==0) sys=0;
1409 >    Systematic->SetBinContent(i,sys);
1410 >  }
1411 >  
1412 >  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1413 >  kinpad->SetLogy(1);
1414 >  kinpad->cd();
1415 >  if(variable=="genMET") {
1416 >    Central.Draw("histo");
1417 >  } else {
1418 >    hdata->Draw("e1");
1419 >    Central.Draw("histo,same");
1420 >    hdata->Draw("e1,same");
1421 >  }
1422 >  
1423 >  DrawPrelim();
1424 >  
1425 >  save_with_ratio_and_sys_band( hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1426 >  
1427 >  kinpad->cd();
1428 >  tCentral->SetFillColor(kWhite);
1429 >  tCentral->SetLineColor(kBlack);
1430 >  tScaleUp->SetLineColor(kRed);
1431 >  tScaleDown->SetLineColor(kRed);
1432 >  tMatchingUp->SetLineColor(kBlue);
1433 >  tMatchingDown->SetLineColor(kBlue);
1434 >  tScaleUp->SetLineStyle(2);
1435 >  tScaleDown->SetLineStyle(3);
1436 >  tMatchingUp->SetLineStyle(2);
1437 >  tMatchingDown->SetLineStyle(3);
1438 >  
1439 >  TLegend *leg2 = make_legend();
1440 >  leg2->AddEntry(hdata,"Data","p");
1441 >  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1442 >  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1443 >  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1444 >  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1445 >  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1446 >  if(variable=="genMET") {
1447 >    Central.Draw("histo");
1448 >  }else {
1449 >    hdata->Draw("e1");
1450 >    Central.Draw("histo,same");
1451 >    hdata->Draw("e1,same");
1452 >  }
1453 >  tCentral->Draw("histo,same");
1454 >  tScaleUp->Draw("histo,same");
1455 >  tScaleDown->Draw("histo,same");
1456 >  tMatchingUp->Draw("histo,same");
1457 >  tMatchingDown->Draw("histo,same");
1458 >  leg2->Draw();
1459 >  
1460 >  CompleteSave(kinpad,saveas+"__TTbarComparison");
1461 >  
1462 >  gStyle->SetOptFit(0);
1463 >  
1464 >  kinpad->cd();
1465 >  kinpad->SetLogy(0);
1466 >  TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1467 >  MatchingRatio->Divide(tMatchingDown);
1468 >  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1469 >  lone->SetLineColor(TColor::GetColor("#01DF01"));
1470 >  lone->SetLineStyle(2);
1471 >  TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1472 >  ScaleRatio->Divide(tScaleDown);
1473 >  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1474 >  MatchingRatio->Draw("e1");
1475 >  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1476 >  MatchingRatio->Fit("QP1","R");
1477 >  lone->Draw();
1478 >  stringstream summary;
1479 >  summary << " #splitline{Fit result for f(x) = a+bx :}{#splitline{a=" << DigitsAfterComma(QP1->GetParameter(0),4) << " +/- " << DigitsAfterComma(QP1->GetParError(0),4) << "}{b=" << DigitsAfterComma(QP1->GetParameter(1),4);
1480 >  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1481 >  TText *infobox = write_title(summary.str());
1482 >  infobox->SetX(0.75);
1483 >  infobox->SetTextSize(0.03);
1484 >  infobox->SetY(0.75);
1485 >  infobox->Draw();
1486 >  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1487 >  kinpad->cd();
1488 >  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1489 >  ScaleRatio->Draw("e1");
1490 >  ScaleRatio->Fit("QP1","R");
1491 >  summary.str("");
1492 >  summary << " #splitline{Fit result for f(x) = a+bx :}{#splitline{a=" << DigitsAfterComma(QP1->GetParameter(0),4) << " +/- " << DigitsAfterComma(QP1->GetParError(0),4) << "}{b=" << DigitsAfterComma(QP1->GetParameter(1),4);
1493 >  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1494 >  TText *infobox2 = write_title(summary.str());
1495 >  infobox2->SetX(0.75);
1496 >  infobox2->SetTextSize(0.03);
1497 >  infobox2->SetY(0.75);
1498 >  infobox2->Draw();
1499 >
1500 >  lone->Draw();
1501 >  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1502 >  
1503 >  
1504 >  delete QP1;
1505 >  delete infobox;
1506 >  delete infobox2;
1507 >  delete MatchingRatio;
1508 >  delete ScaleRatio;
1509 >  DeleteStack(ScaleUp);
1510 >  DeleteStack(ScaleDown);
1511 >  DeleteStack(MatchingUp);
1512 >  DeleteStack(MatchingDown);
1513 >  delete leg2;
1514 >  CleanLegends();
1515 >  DeleteStack(Central);
1516 >  delete Systematic;
1517 >  delete HScaleUp;
1518 >  delete HScaleDown;
1519 >  delete HMatchingUp;
1520 >  delete HMatchingDown;
1521 >  delete hdata;
1522 >  delete HCentral;
1523 >  delete ca;
1524 > }
1525 >
1526 > TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1527 >  float val=0,err=0;
1528 >  vector<float> bins;
1529 >  vector<float> vals;
1530 >  vector<float> errs;
1531 >  
1532 >  bins.push_back(binninghisto->GetBinLowEdge(1));
1533 >  int iBin=1;
1534 >  
1535 >  for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1536 >    if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1537 >      bins.push_back(histo->GetBinLowEdge(i));
1538 >      vals.push_back(val);val=0;
1539 >      errs.push_back(err);err=0;
1540 >      iBin++;
1541 >    }
1542 >    val+=histo->GetBinContent(i);
1543 >    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1544 >  }
1545 >  bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1546 >  vals.push_back(val);val=0;
1547 >  errs.push_back(err);err=0;
1548 >  
1549 >  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1550 >  for(unsigned int i=0;i<vals.size();i++) {
1551 >    h->SetBinContent(i+1,vals[i]);
1552 >    h->SetBinError(i+1,errs[i]);
1553 >  }
1554 >  
1555 >  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1556 >  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1557 >  
1558 >  h->GetXaxis()->CenterTitle();
1559 >  h->GetYaxis()->CenterTitle();
1560 >
1561 >  return h;
1562 > }
1563 >
1564 >
1565 > TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1566 >  float statsperbin = (1/(float)nbins) * histo->Integral();
1567 >  float val=0,err=0;
1568 >  vector<float> bins;
1569 >  vector<float> vals;
1570 >  vector<float> errs;
1571 >  
1572 >  bins.push_back(histo->GetBinLowEdge(1));
1573 >  for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
1574 >    val+=histo->GetBinContent(i);
1575 >    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1576 >    if( val/statsperbin > 0.85) {
1577 >      if(bins.size()<nbins) {
1578 >        bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1579 >        vals.push_back(val);val=0;
1580 >        errs.push_back(err);err=0;
1581 >      }
1582 >    }
1583 >    if(i==histo->GetNbinsX()) {
1584 >      bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1585 >      vals.push_back(val);val=0;
1586 >      errs.push_back(err);err=0;
1587 >    }
1588 >  }
1589 >  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1590 >  
1591 >  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1592 >  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1593 >  
1594 >  h->GetXaxis()->CenterTitle();
1595 >  h->GetYaxis()->CenterTitle();
1596 >  
1597 >  for(unsigned int i=0;i<vals.size();i++) {
1598 >    h->SetBinContent(i+1,vals[i]);
1599 >    h->SetBinError(i+1,errs[i]);
1600 >  }
1601 >  
1602 >  return h;
1603 > }
1604 >
1605 >
1606 >  
1607 > void ShowBinning(TH1F *histo) {
1608 >  cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
1609 >  for(unsigned int i=1;i<=histo->GetNbinsX();i++) cout << "   Bin " << i << " : " << histo->GetBinLowEdge(i) << " , " << histo->GetBinLowEdge(i) + histo->GetBinWidth(i) << "  : " << histo->GetBinContent(i) << endl;
1610 > }
1611 >  
1612 > void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1613 >  TCanvas *ca = new TCanvas("ca","ca");
1614 >  TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
1615 >  TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
1616 >  TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
1617 >  TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
1618 >  TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
1619 >  
1620 >  tScaleUp->Scale(1.0/tScaleUp->Integral());
1621 >  tScaleDown->Scale(1.0/tScaleDown->Integral());
1622 >  tMatchingDown->Scale(1.0/tMatchingDown->Integral());
1623 >  tMatchingUp->Scale(1.0/tMatchingUp->Integral());
1624 >  tCentral->Scale(1.0/tCentral->Integral());
1625 >  
1626 >  cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
1627 >  
1628 >  
1629 >  TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
1630 >  TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
1631 >  TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
1632 >  TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
1633 >  TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
1634 >  
1635 >  float min=rtScaleUp->GetMinimum();
1636 >  float max=rtScaleUp->GetMaximum();
1637 >  
1638 >  if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
1639 >  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1640 >  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1641 >  if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
1642 >  if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
1643 >  
1644 >  if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
1645 >  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1646 >  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1647 >  if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
1648 >  if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
1649 >  
1650 >  rtCentral->SetMaximum(1.2*max);
1651 >  rtCentral->SetMinimum(0.8*min);
1652 >  
1653 > /*  tScaleUp->Rebin(40);
1654 >  tScaleDown->Rebin(40);
1655 >  tMatchingDown->Rebin(40);
1656 >  tMatchingUp->Rebin(40);
1657 >  tCentral->Rebin(40);*/
1658 >  
1659 >  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1660 >  kinpad->SetLogy(1);
1661 >  kinpad->cd();
1662 >  tCentral->SetFillColor(kWhite);
1663 >  tCentral->SetLineColor(kBlack);
1664 >  tScaleUp->SetLineColor(kRed);
1665 >  tScaleDown->SetLineColor(kRed);
1666 >  tMatchingUp->SetLineColor(kBlue);
1667 >  tMatchingDown->SetLineColor(kBlue);
1668 >  tScaleUp->SetLineStyle(2);
1669 >  tScaleDown->SetLineStyle(3);
1670 >  tMatchingUp->SetLineStyle(2);
1671 >  tMatchingDown->SetLineStyle(3);
1672 >  
1673 >  rtScaleDown->SetLineColor(kRed);
1674 >  rtMatchingUp->SetLineColor(kBlue);
1675 >  rtMatchingDown->SetLineColor(kBlue);
1676 >  rtScaleUp->SetLineStyle(2);
1677 >  rtScaleDown->SetLineStyle(3);
1678 >  rtMatchingUp->SetLineStyle(2);
1679 >  rtMatchingDown->SetLineStyle(3);
1680 >  
1681 >  TLegend *leg2 = make_legend();
1682 >  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1683 >  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1684 >  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1685 >  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1686 >  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1687 >  
1688 >  tCentral->Draw("histo");
1689 >  tScaleUp->Draw("histo,same");
1690 >  tScaleDown->Draw("histo,same");
1691 >  tMatchingUp->Draw("histo,same");
1692 >  tMatchingDown->Draw("histo,same");
1693 >  leg2->Draw();
1694 >  DrawMCPrelim();
1695 >  CompleteSave(kinpad,saveas+"__TTbarComparison");
1696 >  kinpad->cd();
1697 >  kinpad->SetLogy(0);
1698 >  rtCentral->Draw("histo");
1699 >  rtScaleUp->Draw("histo,same");
1700 >  rtScaleDown->Draw("histo,same");
1701 >  rtMatchingUp->Draw("histo,same");
1702 >  rtMatchingDown->Draw("histo,same");
1703 >  leg2->Draw();
1704 >  DrawMCPrelim();
1705 >  CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
1706 >  
1707 >  
1708 >  gStyle->SetOptFit(0);
1709 >
1710 >  kinpad->cd();
1711 >  kinpad->SetLogy(0);
1712 >  TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
1713 >  MatchingRatio->Divide(rtMatchingDown);
1714 >  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1715 >  lone->SetLineColor(TColor::GetColor("#01DF01"));
1716 >  lone->SetLineStyle(2);
1717 >  TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
1718 >  ScaleRatio->Divide(rtScaleDown);
1719 >  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1720 >  MatchingRatio->Draw("e1");
1721 >  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1722 >  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
1723 >  lone->Draw();
1724 >  stringstream summary;
1725 >  summary << " #splitline{Fit result for f(x) = a+bx :}{#splitline{a=" << DigitsAfterComma(QP1->GetParameter(0),4) << " +/- " << DigitsAfterComma(QP1->GetParError(0),4) << "}{b=" << DigitsAfterComma(QP1->GetParameter(1),4);
1726 >  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1727 >  TText *infobox = write_title(summary.str());
1728 >  infobox->SetX(0.75);
1729 >  infobox->SetTextSize(0.03);
1730 >  infobox->SetY(0.75);
1731 >  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
1732 >  DrawMCPrelim();
1733 >  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1734 >  kinpad->cd();
1735 >  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1736 >  ScaleRatio->Draw("e1");
1737 >  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
1738 >  summary.str("");
1739 >  summary << " #splitline{Fit result for f(x) = a+bx :}{#splitline{a=" << DigitsAfterComma(QP1->GetParameter(0),4) << " +/- " << DigitsAfterComma(QP1->GetParError(0),4) << "}{b=" << DigitsAfterComma(QP1->GetParameter(1),4);
1740 >  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1741 >  TText *infobox2 = write_title(summary.str());
1742 >  infobox2->SetX(0.75);
1743 >  infobox2->SetTextSize(0.03);
1744 >  infobox2->SetY(0.75);
1745 >  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
1746 >
1747 >  lone->Draw();
1748 >  DrawMCPrelim();
1749 >  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1750 >  
1751 >  kinpad->cd();
1752 >  TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
1753 >  TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
1754 >  TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
1755 >  
1756 >  for(int i=1;i<=SysScale->GetNbinsX();i++) {
1757 >    float matching, scale;
1758 >    bool AssumeFactor=false;
1759 >    if(AssumeFactor) {
1760 >      // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
1761 >      matching=0.;
1762 >      scale=0.;
1763 >    } else {
1764 >      // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
1765 >      matching = fabs(    ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
1766 >      scale    = fabs(    ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
1767 >    }
1768      
1769 +    SysMatching->SetBinContent(i,1+matching);
1770 +    SysScale->SetBinContent(i,1+scale);
1771 +    SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
1772 +  }
1773 +  
1774 +  SysHisto->SetLineColor(kGreen);
1775 +  
1776 +  SysMatching->SetMaximum(3.0);
1777 +  SysMatching->SetMinimum(0.0);
1778 +  SysMatching->Draw("histo");
1779 +  SysScale->Draw("histo,same");
1780 +  SysHisto->Draw("histo,same");
1781 +  CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
1782 +  
1783 +  delete SysMatching;
1784 +  delete SysScale;
1785 +  
1786 +  if(!Contains(variable,"gen")) {
1787 +    TH1F *hdata  = allsamples.Draw("hdata",   variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1788 +    THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
1789 +    
1790 +    TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1791 +    
1792 +    for(int i=1;i<=Systematic->GetNbinsX();i++) {
1793 +      int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
1794 +      if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
1795 +      float sys = SysHisto->GetBinContent(iBin)-1;
1796 +      Systematic->SetBinContent(i,sys);
1797 +    }
1798 +    
1799 +    kinpad->cd();
1800 +    TLegend *leg = allsamples.allbglegend();
1801 +    hdata->Draw();
1802 +    smc.Draw("histo,same");
1803 +    hdata->Draw("same");
1804 +    leg->Draw();
1805 +    DrawPrelim();
1806 +    save_with_ratio_and_sys_band( hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
1807 +    
1808 +    delete Systematic;
1809 +    delete hdata;
1810 +  }
1811 +  
1812 +  
1813 +  delete SysHisto;
1814 +  delete tScaleUp;
1815 +  delete tScaleDown;
1816 +  delete tCentral;
1817 +  delete tMatchingUp;
1818 +  delete tMatchingDown;
1819 +  delete rtScaleUp;
1820 +  delete rtScaleDown;
1821 +  delete rtCentral;
1822 +  delete rtMatchingUp;
1823 +  delete rtMatchingDown;
1824 +  delete QP1;
1825 +  delete infobox;
1826 +  delete infobox2;
1827 +  delete MatchingRatio;
1828 +  delete ScaleRatio;
1829 +  delete leg2;
1830 +  CleanLegends();
1831 +  delete ca;
1832 + }
1833 +
1834 + void ProduceMCSystematicPlots() {
1835 +  cout << "Getting ready to produce systematic plots " << endl;
1836 +  TCut cutweightBKP = cutWeight;
1837 +  
1838 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
1839 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
1840 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
1841 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
1842 +  
1843 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
1844 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
1845 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
1846 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
1847 +  
1848 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
1849 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
1850 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
1851 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
1852 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
1853 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
1854 +  
1855 +  
1856 +  
1857 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
1858 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1859 +  cutWeight="1.0";
1860 +  
1861 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1862 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
1863 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1864 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1865 +  
1866 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1867 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
1868 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1869 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1870 +  
1871 +  
1872 +  // --------------------------------------    ***** AACHEN *****      --------------------------------------    
1873 +  
1874 +  /*
1875 +  cutWeight=cutweightBKP;
1876 +  TCut essentialcutBKP = essentialcut;
1877 +  cout << (const char*) essentialcut << endl;
1878 +  
1879 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
1880 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1881 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1882 +  
1883 +  TCut cutnJetsBKP = cutnJets;
1884 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
1885 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
1886 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1887 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1888 +  
1889 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
1890 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
1891 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
1892 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
1893 +  
1894 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
1895 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
1896 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1897 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
1898 +  
1899 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
1900 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
1901 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1902 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
1903 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
1904 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
1905 +  
1906 +  
1907 +  
1908 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
1909 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1910 +  cutWeight="1.0";
1911 +  
1912 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1913 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
1914 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1915 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1916 +  
1917 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1918 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
1919 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1920 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1921 +  
1922 +  cutnJets  = cutnJetsBKP;
1923 +  cutWeight = cutweightBKP;
1924 +  essentialcut = essentialcutBKP;
1925 +  */
1926 +  write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
1927 + }
1928 +
1929 + void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
1930 +  TCut cut=pcut&&basiccut;
1931 +  string variable="mll";
1932 +  string xlabel="m_{ll} [GeV]";
1933 +  int nbins=40;
1934 +  float min=0;
1935 +  float max=200;
1936 +
1937 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1938 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
1939 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
1940 +  TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1941 +  TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1942 +  datahistoSF->SetMarkerSize(DataMarkerSize);
1943 +  datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
1944 +  datahistoOF->SetMarkerSize(DataMarkerSize);
1945 +  datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
1946 +
1947 +  THStack mcstackSF   = allsamples.DrawStack("mcstackSF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
1948 +  THStack mcstackOF   = allsamples.DrawStack("mcstackOF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
1949 +  datahistoSF->Draw("e1");
1950 +  ckin->Update();
1951 +  mcstackSF.Draw("histo,same");
1952 +  
1953 +  datahistoSF->Draw("same,e1");
1954 +  TLegend *kinleg = allsamples.allbglegend();
1955 +  kinleg->Draw();
1956 +  
1957 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1958 +  kinpad->cd();
1959 +  datahistoSF->Draw("e1");
1960 +  mcstackSF.Draw("histo,same");
1961 +  datahistoSF->Draw("same,e1");
1962 +  datahistoSF->Draw("same,axis");
1963 +  kinleg->Draw();
1964 +  DrawPrelim();
1965 +  Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
1966 +  
1967 +  kinpad->cd();
1968 +  datahistoOF->Draw("e1");
1969 +  mcstackOF.Draw("histo,same");
1970 +  datahistoOF->Draw("same,e1");
1971 +  datahistoOF->Draw("same,axis");
1972 +  kinleg->Draw();
1973 +  DrawPrelim();
1974 +  Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
1975 +  
1976 +  kinpad->cd();
1977 +  tauSF->Draw("e1");
1978 +  tauOF->Draw("histo,same");
1979 +  tauSF->Draw("e1,same");
1980 +  TLegend *legtau = make_legend();
1981 +  legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
1982 +  legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
1983 +  legtau->Draw();
1984 +  DrawPrelim();
1985 +  Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
1986 +  
1987 +  delete datahistoSF;
1988 +  delete datahistoOF;
1989 +  delete tauSF;
1990 +  delete tauOF;
1991 +  delete kinpad;
1992 +  delete ckin;
1993 +  CleanLegends();
1994   }
1995 +  
1996  
1997 + void TauQuestion() {
1998 + //   MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
1999 + //   MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
2000 + //   MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
2001 +  MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
2002 + }
2003  
2004   void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
2005   {
# Line 890 | Line 2007 | void do_kinematic_plots(string mcjzb, st
2007    bool dolog=true;
2008    bool nolog=false;
2009  
2010 <  bool doOFSF = false;
2011 <  bool doKin  = true;
2010 >  bool doOFSF = true;
2011 >  bool doKin  = false;
2012    bool doDataComp = false;
2013    bool MakeTwoThreeJetComparison = false;
2014    
# Line 905 | Line 2022 | void do_kinematic_plots(string mcjzb, st
2022    }
2023    
2024    if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2025 +  
2026 +  //TauQuestion();
2027  
2028 +  //ProduceJanPlots();
2029 +  //ProduceMCSystematicPlots();
2030 +  //assert(0);
2031 + //  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
2032 +  
2033    if ( doOFSF ) {
2034 <     make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2034 >      //make_OFSF_plots("st", "met[4]>100&&pfJetGoodNum40>=3", 20, 0, 2000., false, "S_{T}", "FrankT");
2035 >      make_OFSF_plots("pt1+pt2+met[4]+Sum$(pfJetGoodPt)", "met[4]>100&&pfJetGoodNum40>=3", 20, 0, 2000., false, "#tilde{S}_{T}", "FrankT");
2036 >      assert(0);
2037 >      
2038 > //      make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2039 > //      make_OFSF_plots("leptonNum", "met[4]>100", 3, 2, 5., false, "N(leptons)", "NLeptons");
2040  
2041   //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100",                        7, 3, 10, true, "#(jets)", "njets");
2042   //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
2043   //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
2044  
2045 < //      make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
2045 > //      make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, -0, 4.5, true, "#(b-jets)", "nbjets");
2046   //      make_OFSF_plots("pfJetGoodPtBtag[0]", "met[4]>100&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", "ptb1");
2047  
2048 < //     make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
2049 < //     make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
2050 <    //  make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
2051 <    //  make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
2052 < //     make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
2053 < //     make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
2054 <    //  make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
2055 <    //  make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
2056 < //     make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
2057 <    make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
2058 < //    make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
2059 < //    make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
2060 < //    make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
2061 < //    make_OFSF_plots("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", "met[4]>100", 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", "dphilc");
2062 < //    make_OFSF_plots("TMath::Min(TMath::Abs(pfJetDphiMet[0]), TMath::Min(TMath::Abs(pfJetDphiMet[1]), TMath::Abs(pfJetDphiMet[2])))", "met[4]>100", 16, 0, 3.2, false, "Min(|#Delta#phi(jet,MET)|)", "dphijc");
2063 < //    make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(dphiMet1)), (TMath::Pi() - TMath::Abs(dphiMet2)))", "met[4]>100", 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(l,MET)|)", "dphilco");
2064 < //    make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(pfJetDphiMet[0])), TMath::Min( (TMath::Pi()-TMath::Abs(pfJetDphiMet[1])), (TMath::Pi() - TMath::Abs(pfJetDphiMet[2]))))", "met[4]>100", 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(jet,MET)|)", "dphijco");
2048 > //      make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
2049 > //      make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
2050 > //      make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
2051 >     make_OFSF_plots("pt",  "met[4]>100", 30, 0., 300., true, "p_{ll}", "pt");
2052 > //      make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
2053 > //      make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
2054 > //      make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
2055 > //      make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
2056 > //      make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
2057 > //      make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
2058 > //      make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
2059 >    
2060 > //     make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
2061 > //     make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
2062 > //     make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
2063 > //     make_OFSF_plots("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", "met[4]>100", 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", "dphilc");
2064 > //     make_OFSF_plots("TMath::Min(TMath::Abs(pfJetDphiMet[0]), TMath::Min(TMath::Abs(pfJetDphiMet[1]), TMath::Abs(pfJetDphiMet[2])))", "met[4]>100", 16, 0, 3.2, false, "Min(|#Delta#phi(jet,MET)|)", "dphijc");
2065 > //     make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(dphiMet1)), (TMath::Pi() - TMath::Abs(dphiMet2)))", "met[4]>100", 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(l,MET)|)", "dphilco");
2066 > //     make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(pfJetDphiMet[0])), TMath::Min( (TMath::Pi()-TMath::Abs(pfJetDphiMet[1])), (TMath::Pi() - TMath::Abs(pfJetDphiMet[2]))))", "met[4]>100", 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(jet,MET)|)", "dphijco");
2067    }
2068  
2069    if ( doDataComp) {
# Line 949 | Line 2080 | void do_kinematic_plots(string mcjzb, st
2080  
2081      TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2082      
2083 < /*    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2083 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2084      make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2085      
2086      
# Line 960 | Line 2091 | void do_kinematic_plots(string mcjzb, st
2091      make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2092      
2093      make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2094 < //    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2094 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2095      make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2096 < //    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2097 < */
2096 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2097 >
2098    
2099      string basiccutsaved = (const char*)basiccut;
2100      
# Line 975 | Line 2106 | void do_kinematic_plots(string mcjzb, st
2106        newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2107        found = newbasiccut.find( "pt2>20" );
2108      }
2109 < //    basiccut=TCut(newbasiccut.c_str());
2110 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2111 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2112 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2113 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2114 < //    basiccut=TCut(basiccutsaved.c_str());
2115 <    
2116 < //     make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2117 < //     make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2118 <    
2119 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2120 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2121 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2122 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2123 <
2124 <    
2125 < /*     make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2126 <     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2127 <     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2128 <     make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2109 >    basiccut=TCut(newbasiccut.c_str());
2110 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2111 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2112 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2113 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2114 >    basiccut=TCut(basiccutsaved.c_str());
2115 >    
2116 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2117 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2118 >    
2119 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2120 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2121 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2122 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2123 >
2124 >    
2125 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2126 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2127 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2128 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2129      make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2130      make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2131      make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2132      make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2133 < */
2133 >
2134      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2135      make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2136      
# Line 1012 | Line 2143 | void do_kinematic_plots(string mcjzb, st
2143      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2144      make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2145  
2146 < /*
2146 >
2147      make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2148      make_data_comparison_plot("mll", cutmass&&cutOSSF&&"met[4]>100&&met[4]<150&&pfJetGoodNum40==2", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_CR");
2149      make_data_comparison_plot("mll", cutmass&&cutOSOF&&"met[4]>100&&met[4]<150&&pfJetGoodNum40==2", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_CR");
# Line 1021 | Line 2152 | void do_kinematic_plots(string mcjzb, st
2152      make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2153      make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2154      make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2155 <  */
2155 >
2156    }
2157  
2158  
2159    if ( doKin ) {
2160      string mllCut("");
2161 < /*  
2161 >    
2162 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_SF",doPF,true);
2163 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_OF",doPF,true);
2164 >    assert(0);
2165 >  
2166      make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),40,0,400,dolog,"PFMET","Debunking/MET_OF_30to70_0j",doPF,true);
2167      make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),40,0,400,dolog,"PFMET","Debunking/MET_OF_30to70_1j",doPF,true);
2168      make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),40,0,400,dolog,"PFMET","Debunking/MET_OF_30to70_2j",doPF,true);
# Line 1037 | Line 2172 | void do_kinematic_plots(string mcjzb, st
2172      make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),40,0,400,dolog,"PFMET","Debunking/MET_OF_Z_1j",doPF,true);
2173      make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),40,0,400,dolog,"PFMET","Debunking/MET_OF_Z_2j",doPF,true);
2174      make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),40,0,400,dolog,"PFMET","Debunking/MET_OF_Z_3j",doPF,true);
2175 < */
2175 >
2176  
2177      make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2178      make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
# Line 1055 | Line 2190 | void do_kinematic_plots(string mcjzb, st
2190      make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_Z_2j",doPF,true);
2191      make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_Z_3j",doPF,true);
2192  
2193 <     /*make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2194 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
1060 <    
1061 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
1062 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);*/
1063 <    
1064 < /*     make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("pfJetGoodNum40==2")&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70___2jetsonly",doPF,true);
1065 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("pfJetGoodNum40==2")&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70___2jetsonly",doPF,true);
1066 <    
1067 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("pfJetGoodNum40==2")&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120___2jetsonly",doPF,true);
1068 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("pfJetGoodNum40==2")&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120___2jetsonly",doPF,true);
1069 < */
1070 <    write_info(__FUNCTION__,"Last plot");
2193 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2194 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2195      
2196 +    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2197 +    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2198      
2199 +    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("pfJetGoodNum40==2")&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70___2jetsonly",doPF,true);
2200 +    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("pfJetGoodNum40==2")&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70___2jetsonly",doPF,true);
2201      
2202 +    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("pfJetGoodNum40==2")&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120___2jetsonly",doPF,true);
2203 +    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("pfJetGoodNum40==2")&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120___2jetsonly",doPF,true);
2204 +
2205      
2206 +    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2207 +    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2208 +    // Plots in signal region
2209 +    make_kin_plot("met[4]","",70,0,350,dolog,"#slash{E}_{T} [GeV]","met",doPF,true);
2210 +
2211 +
2212 +    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2213      
2214 +    make_ttbar_comparison("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j__ALLMCSAMPLES");
2215 +    /*
2216 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2217 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2218 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2219 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2220 +
2221 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2222 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2223 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2224 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2225 +
2226 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2227 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2228 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2229 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2230 +
2231 +    
2232 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2233 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2234 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2235 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2236 +
2237 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2238 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2239 +
2240 +    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2241 +    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2242      
2243 <    
2244 <    
2245 <     return;
2246 <    
2247 <    
2248 <    
2249 <     make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2250 <     make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2251 <    // Plots in signal region
2252 < //     make_kin_plot("met[4]","",70,0,350,dolog,"MET [GeV]","met",doPF,true);
2253 <     make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2254 <     make_kin_plot("mll","mll>20",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
2255 <     make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
2256 <     make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
2257 <    
2258 <     make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2259 <     make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
1094 <    
1095 < //     make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_met100",doPF,true);
1096 < //     make_kin_plot("mll","mll>20&&met[4]>100",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_met100",doPF,true,true);
1097 < //     make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee_met100",doPF,true);
1098 < //     make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm_met100",doPF,true);
2243 >    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2244 >    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2245 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2246 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2247 >
2248 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2249 >    make_kin_plot("mll","mll>20",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
2250 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
2251 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
2252 >    
2253 >    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2254 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2255 >    
2256 >    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_met100",doPF,true);
2257 >    make_kin_plot("mll","mll>20&&met[4]>100",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_met100",doPF,true,true);
2258 >    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee_met100",doPF,true);
2259 >    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm_met100",doPF,true);
2260      
2261      
2262 < //     make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2263 < //     make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2262 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2263 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2264  
2265      // Further inclusive invariant mass plots
2266      make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2267 < //     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2268 < //     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2267 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2268 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2269      make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2270      
2271 <    //make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2271 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2272      //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2273      
2274      
2275      // Number of jets
2276      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2277      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2278 <    //make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2278 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2279      
2280      // Others
2281      make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
# Line 1146 | Line 2307 | void do_kinematic_plots(string mcjzb, st
2307      
2308      //   make_kin_plot("mll","met[4]>100",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV] (MET>100GeV)","mll_met100_ll",doPF,true);
2309      //make_kin_plot("mll","met[4]>150&&id1==0",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ee} [GeV] (MET>150GeV)","mll_met150_ee",doPF,true);
2310 <    //make_kin_plot("mll","met[4]>150&&id1==1",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{#mu#mu} [GeV] (MET>150GeV)","mll_met150_mm",doPF,true);
2310 >    //make_kin_plot("mll","met[4]>150&&id1==1",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{#mu#mu} [GeV] (MET>150GeV)","mll_met150_mm",doPF,true);*/
2311    }
2312      
2313 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2314 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2315 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2313 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2314 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2315 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2316     make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2317 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2318 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2319 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2320 <
2321 < //   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2322 < //   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2323 <
2317 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2318 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2319 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2320 > /*
2321 >   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2322 >   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2323 > */
2324    switch_overunderflow(false);
2325   }
2326  
# Line 1243 | Line 2404 | void region_comparison_plots(string mcjz
2404      make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
2405  
2406      make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
2407 <    make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2407 >    make_comp_plot("met[4]","pf#slash{E}_{T} [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2408      make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2409      make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2410      make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
# Line 1776 | Line 2937 | void do_prediction_plot(string jzb, TCan
2937   //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
2938   //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2939      speciallegBpred->Draw();
2940 <    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
2940 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
2941 >    delete predcomppad;
2942      
2943      TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
2944      specialcanv->SetLogy(1);
# Line 1859 | Line 3021 | void do_prediction_plot(string jzb, TCan
3021    string ytitle("ratio");
3022    if ( use_data==1 ) ytitle = "data/pred";
3023    //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3024 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3024 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3025 >  
3026 >  delete kinpad;
3027  
3028  
3029    
# Line 2056 | Line 3220 | void lepton_comparison_plots() {
3220    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3221    eemmlegend->Draw();
3222    DrawPrelim();
3223 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3223 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3224    
3225    TH1F *zjeed = allsamples.Draw("zjeed",jzbvariablemc,    int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==0)",mc,  luminosity,allsamples.FindSample("/DY"));
3226    TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc,    int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc,  luminosity,allsamples.FindSample("/DY"));
# Line 2179 | Line 3343 | void draw_pure_jzb_histo(TCut cut,string
3343    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3344    writeline1->SetTextSize(0.035);
3345    writeline1->Draw();
3346 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3347 <  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
3346 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3347 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3348    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3349    jzbpad2->cd();
3350    jzbpad2->SetLogy(1);
# Line 2195 | Line 3359 | void draw_pure_jzb_histo(TCut cut,string
3359    writeline1->SetTextSize(0.035);
3360    writeline1->Draw();
3361    DrawPrelim();
3362 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3363 <  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3362 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3363 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3364    datahisto->Delete();
3365    mcstack.Delete();
3366   }
# Line 2304 | Line 3468 | void draw_normalized_data_vs_data_histo(
3468    leg->AddEntry(datahisto2,legentry2.c_str());
3469    leg->Draw();
3470    
3471 <  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3471 >  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3472    
3473    datahisto1->Delete();
3474    datahisto2->Delete();
# Line 2798 | Line 3962 | void find_correction_factors(string &jzb
3962    
3963   }
3964  
3965 < void pick_up_events(string cut) {
3966 <  dout << "Picking up events with cut " << cut << endl;
2803 <  allsamples.PickUpEvents(cut);
3965 > void pick_up_events(string cut, string filename, bool QuietMode=false) {
3966 >  allsamples.PickUpEvents(cut,filename,QuietMode);
3967   }
3968  
3969   void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
# Line 2912 | Line 4075 | void ttbar_sidebands_comparison(string m
4075        
4076    float simulatedlumi = luminosity; //in pb please - adjust to your likings
4077  
4078 <  TH1F *TZem  = systsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4079 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4078 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4079 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4080    TH1F *TSem;
4081    TH1F *nTSem;
4082 <  TH1F *TZeemm  = systsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4083 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4082 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4083 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4084    TH1F *TSeemm;
4085    TH1F *nTSeemm;
4086    
4087    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4088 <    TSem    = systsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4089 <    nTSem   = systsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4090 <    TSeemm  = systsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4091 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4088 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4089 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4090 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4091 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4092    }
4093  
4094    TCanvas *tcan = new TCanvas("tcan","tcan");
# Line 3271 | Line 4434 | void zjets_prediction_comparison(string
4434    TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
4435    
4436  
3274  cout << __LINE__ << endl;
4437    top->SetLineColor(kBlue);top->SetLineStyle(2);
4438    bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
4439    center->SetLineColor(kBlue);
# Line 3294 | Line 4456 | void zjets_prediction_comparison(string
4456    TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4457    TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4458  
3297  cout << __LINE__ << endl;
4459    TH1F *RcorrJZBSBem;
4460    TH1F *LcorrJZBSBem;
4461    TH1F *RcorrJZBSBeemm;
4462    TH1F *LcorrJZBSBeemm;
4463  
3303  cout << __LINE__ << endl;
4464    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4465      RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4466      LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
# Line 3323 | Line 4483 | void zjets_prediction_comparison(string
4483    
4484    Bpred->SetLineColor(kRed);
4485  
3326  cout << __LINE__ << endl;
4486    TAUhJZBpos->SetLineColor(kBlack);
4487    Bpred->SetLineColor(kRed);
4488    
# Line 3380 | Line 4539 | void zjets_prediction_comparison(string
4539    
4540    delete zcan;
4541    cutWeight=weightbackup;
3383
3384  cout << __LINE__ << endl;
4542   }
4543  
4544  
# Line 3499 | Line 4656 | void make_table(samplecollection &coll,
4656   }
4657  
4658   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
4659 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
4660 +  assert(0);
4661    /*we want a table like this:
4662      __________________     50   |   100  | ...
4663      | Data prediction |  a vs b | a vs b | ...
# Line 3732 | Line 4891 | void qcd_plots(string datajzb, string mc
4891    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
4892    string ytitle("ratio");
4893    if ( use_data==1 ) ytitle = "data/pred";
4894 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
4894 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
4895 >  delete kinpad;
4896    
4897    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
4898    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 3940 | Line 5100 | void met_vs_jzb_plots(string datajzb, st
5100    sRIGHT << "((" << mcjzb << ")>0)";
5101    TCut RIGHT(sRIGHT.str().c_str());
5102    
5103 <  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5104 <  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5105 <  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5106 <  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5103 >  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5104 >  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5105 >  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5106 >  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5107    
5108    
5109    TH1F *Bpred =  (TH1F*)metleft->Clone("Bpred");
# Line 3969 | Line 5129 | void met_vs_jzb_plots(string datajzb, st
5129    lg->SetHeader("DY");
5130    
5131    lg->Draw();
5132 <  save_with_ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5132 >  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5133    
5134    TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5135    metpad3->cd();
# Line 3987 | Line 5147 | void met_vs_jzb_plots(string datajzb, st
5147  
5148    lg2->Draw();
5149    
5150 <  save_with_ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5150 >  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5151    
5152    TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5153    metpad2->cd();
5154    metpad2->SetLogy(1);
5155    
5156 <  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5157 <  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5158 <  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5159 <  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5156 >  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5157 >  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5158 >  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5159 >  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5160    
5161    metlefta->Add(metleftOa,-1);
5162    metrighta->Add(metrightOa,-1);
# Line 4006 | Line 5166 | void met_vs_jzb_plots(string datajzb, st
5166    metlefta->Draw("histo");
5167    metrighta->Draw("same");
5168    lg->Draw();
5169 <  save_with_ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5169 >  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5170    
5171    delete Bpred;
5172    delete obs;
# Line 4015 | Line 5175 | void met_vs_jzb_plots(string datajzb, st
5175    int newNBins=30;
5176    
5177    TPad *metpad4 = new TPad("metpad4","metpad4",0,0,1,1);
5178 <  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5179 <  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5180 <  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5181 <  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5178 >  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5179 >  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5180 >  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5181 >  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5182    
5183    TH1F *aBpred = (TH1F*)Ametleft->Clone("aBpred");
5184    aBpred->Add(AmetleftO,-1);
# Line 4033 | Line 5193 | void met_vs_jzb_plots(string datajzb, st
5193    aobs->Draw("same");
5194    lg->SetHeader("All MC");
5195    lg->Draw();
5196 <  save_with_ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5196 >  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5197    
5198    
5199    delete lg;
# Line 4043 | Line 5203 | void met_vs_jzb_plots(string datajzb, st
5203    delete metright;
5204    delete metrightO;
5205   }
5206 +
5207 +
5208 + void do_one_ttbar_test(TH1F* &observed, TH1F* &predicted, TH1F* &ratio, TH1F* &ratio2, string mcjzb, string prestring) {
5209 +  
5210 +  if(PlottingSetup::RestrictToMassPeak) {
5211 +    write_error(__FUNCTION__,"This function (ttbar_tests) was not written for on-peak studies - sorry.");
5212 +    assert(!PlottingSetup::RestrictToMassPeak);
5213 +  }
5214 +  
5215 +  vector<float> binning;
5216 +  
5217 +  binning.push_back(-200);
5218 +  binning.push_back(-150);
5219 +  binning.push_back(-125);
5220 +  binning.push_back(-100);
5221 +  binning.push_back(-75);
5222 +  binning.push_back(-50);
5223 +  binning.push_back(-25);
5224 +  binning.push_back(0);
5225 +  binning.push_back(25);
5226 +  binning.push_back(50);
5227 +  binning.push_back(75);
5228 +  binning.push_back(100);
5229 +  binning.push_back(125);
5230 +  binning.push_back(150);
5231 +  binning.push_back(200);
5232 +  
5233 +  switch_overunderflow(true);
5234 +  
5235 +  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5236 +  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5237 +  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5238 +  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5239 +  
5240 +  TCanvas *tcan = new TCanvas("tcan","tcan");
5241 +  tcan->SetLogy(1);
5242 +  
5243 +  TZeemm->SetLineColor(kBlack);
5244 +  TZem->SetLineColor(kRed);
5245 +  TZeemm->SetMarkerColor(kBlack);
5246 +  TZem->SetMarkerColor(kRed);
5247 +  
5248 +  vector<TH1F*> histos;
5249 + //  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5250 + //  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5251 +  histos.push_back(TZem);
5252 +  histos.push_back(TZeemm);
5253 +  draw_all_ttbar_histos(tcan,histos,"histo",8);
5254 +  
5255 +  TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
5256 +  leg->AddEntry(TZeemm,"SFZP","l");
5257 +  leg->AddEntry(TZem,"OFZP","l");
5258 +  leg->Draw("same");
5259 +  DrawMCPrelim();
5260 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison");
5261 +  
5262 +  TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
5263 +  TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
5264 +  TH1F *TSeemmcopy;
5265 +  TH1F *TSemcopy;
5266 +  
5267 +  predicted=(TH1F*)TZem->Clone(((string)"predicted_"+prestring).c_str());
5268 +  observed=(TH1F*)TZeemm->Clone(((string)"observed_"+prestring).c_str());
5269 +  
5270 +  vector<float> posbinning;
5271 +  for(unsigned int i=0;i<binning.size();i++) {
5272 +    if(binning[i]<0) continue;
5273 +    posbinning.push_back(binning[i]);
5274 +  }
5275 +  
5276 +  TH1F *pred2 = new TH1F("pred2","pred2",posbinning.size()-1,&posbinning[0]);pred2->Sumw2();
5277 +  TH1F *obs2 = new TH1F("obs2","obs2",posbinning.size()-1,&posbinning[0]);obs2->Sumw2();
5278 +  
5279 +  for(unsigned int i=1;i<=predicted->GetNbinsX();i++) {
5280 +    int index=pred2->FindBin(abs(TZem->GetBinCenter(i)));
5281 +    if(TZem->GetBinCenter(i)<0) {
5282 +      //we're on the left: subtract em!
5283 +      pred2->SetBinContent(index,pred2->GetBinContent(index)-TZem->GetBinContent(i));
5284 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5285 +      //we're on the left: add eemm!
5286 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZeemm->GetBinContent(i));
5287 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5288 +    } else {
5289 +      //we're on the right: add em!
5290 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZem->GetBinContent(i));
5291 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5292 +      //we're on the left: add eemm!
5293 +      obs2->SetBinContent(index,obs2->GetBinContent(index)+TZeemm->GetBinContent(i));
5294 +      obs2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5295 +    }
5296 +  }
5297 +  
5298 +  ratio2 = (TH1F*)pred2->Clone(((string)"ratio2_"+prestring).c_str());
5299 +  ratio2->Divide(obs2);
5300 +
5301 +  TZem->Divide(TZeemm);
5302 +  TZem->SetMarkerStyle(21);
5303 +
5304 +  TZem->SetTitle("OF / SF");
5305 +  ratio = (TH1F*)TZem->Clone(((string)"ratio_"+prestring).c_str());
5306 +  
5307 +  tcan->SetLogy(0);
5308 +  TZem->GetYaxis()->SetRangeUser(0,2.5);
5309 +  TZem->GetYaxis()->SetTitle("ratio");
5310 +  TZem->Draw();
5311 +  
5312 +  float linepos=emuncertOFFPEAK;
5313 +  
5314 +  TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
5315 +  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5316 +  TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
5317 +  
5318 +  top->SetLineColor(kBlue);top->SetLineStyle(2);
5319 +  bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
5320 +  center->SetLineColor(kBlue);
5321 +  
5322 +  top->Draw("same");
5323 +  center->Draw("same");
5324 +  bottom->Draw("same");
5325 +  
5326 +  TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
5327 +  leg2->AddEntry(TZem,"OFZP / SFZP","ple");
5328 +  leg2->AddEntry(bottom,"syst. envelope","l");
5329 +  leg2->SetX1(0.25);leg2->SetX2(0.6);
5330 +  leg2->SetY1(0.65);
5331 +  
5332 +  leg2->Draw("same");
5333 +  
5334 +  DrawMCPrelim();
5335 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_ratio");
5336 +  
5337 +  ratio2->SetLineColor(TZem->GetLineColor());
5338 +  ratio2->SetMarkerColor(TZem->GetMarkerColor());
5339 +  ratio2->GetYaxis()->SetRangeUser(0,2.5);
5340 +  ratio2->GetYaxis()->SetTitle("ratio");
5341 +  ratio2->Draw();
5342 +  
5343 +  TLine *top2 = new TLine(0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
5344 +  TLine *center2 = new TLine(0,1.0,binning[binning.size()-1],1.0);
5345 +  TLine *bottom2 = new TLine(0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
5346 +  
5347 +  top2->SetLineColor(kBlue);top->SetLineStyle(2);
5348 +  bottom2->SetLineColor(kBlue);bottom->SetLineStyle(2);
5349 +  center2->SetLineColor(kBlue);
5350 +  
5351 +  top2->Draw("same");
5352 +  center2->Draw("same");
5353 +  bottom2->Draw("same");
5354 +  
5355 +  leg2->Draw("same");
5356 +  
5357 +  DrawMCPrelim();
5358 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_FINALratio");
5359 +  
5360 +  delete TZem;
5361 +  delete nTZem;
5362 +  delete TZeemm;
5363 +  delete nTZeemm;
5364 +  delete obs2;
5365 +  delete pred2;
5366 +  delete tcan;
5367 +  switch_overunderflow(false);
5368 + }
5369 +
5370 + void IllustrateVariation(TH1F *vanilla_ratio, TH1F *response_only_up_ratio, TH1F *response_only_down_ratio, TH1F *reponse_plus_peak_up_ratio, TH1F *reponse_plus_peak_down_ratio, string PostString) {
5371 +    
5372 +  
5373 +  TCanvas *ttcan2 = new TCanvas("ttcan2","ttcan2");
5374 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5375 +  vanilla_ratio->SetFillColor(kGreen);
5376 +  vanilla_ratio->SetLineColor(kGreen);
5377 +  vanilla_ratio->SetMarkerColor(kGreen);
5378 +  vanilla_ratio->SetFillStyle(3001);
5379 +  vanilla_ratio->Draw("e3");
5380 +  
5381 +  response_only_up_ratio->SetFillColor(kRed);
5382 +  response_only_up_ratio->SetMarkerColor(kRed);
5383 +  response_only_up_ratio->SetLineColor(kRed);
5384 +  response_only_up_ratio->SetFillStyle(3003);
5385 +  response_only_up_ratio->Draw("e3,same");
5386 +  
5387 +  response_only_down_ratio->SetFillColor(kOrange);
5388 +  response_only_down_ratio->SetMarkerColor(kOrange);
5389 +  response_only_down_ratio->SetLineColor(kOrange);
5390 +  response_only_down_ratio->SetFillStyle(3004);
5391 +  response_only_down_ratio->Draw("e3,same");
5392 +  
5393 +  reponse_plus_peak_up_ratio->SetFillColor(TColor::GetColor("#BDBDBD"));
5394 +  reponse_plus_peak_up_ratio->SetMarkerColor(TColor::GetColor("#BDBDBD"));
5395 +  reponse_plus_peak_up_ratio->SetLineColor(TColor::GetColor("#BDBDBD"));
5396 +  reponse_plus_peak_up_ratio->SetFillStyle(3005);
5397 +  reponse_plus_peak_up_ratio->Draw("e3,same");
5398 +  
5399 +  reponse_plus_peak_down_ratio->SetFillColor(kBlue);
5400 +  reponse_plus_peak_down_ratio->SetMarkerColor(kBlue);
5401 +  reponse_plus_peak_down_ratio->SetLineColor(kBlue);
5402 +  reponse_plus_peak_down_ratio->SetFillStyle(3006);
5403 +  reponse_plus_peak_down_ratio->Draw("e3,same");
5404 +  
5405 +  TLine *llow = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0-emuncertOFFPEAK,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0-emuncertOFFPEAK);
5406 +  TLine *lhi = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0+emuncertOFFPEAK,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0+emuncertOFFPEAK);
5407 +  TLine *lOne = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0);
5408 +  
5409 +  TLine *llowA = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0-0.07,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0-0.07);
5410 +  TLine *lhiA = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0+0.07,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0+0.07);
5411 +  
5412 +  lhiA->SetLineColor(kRed);
5413 +  lhiA->SetLineStyle(2);
5414 +  llowA->SetLineColor(kRed);
5415 +  llowA->SetLineStyle(2);
5416 +  
5417 +  llow->SetLineColor(kBlue);
5418 +  llow->SetLineStyle(2);
5419 +  lhi->SetLineColor(kBlue);
5420 +  lhi->SetLineStyle(2);
5421 +  lOne->SetLineColor(kBlue);
5422 +  
5423 +  llow->Draw();
5424 +  lhi->Draw();
5425 +  lOne->Draw();
5426 +  
5427 +  llowA->Draw();
5428 +  lhiA->Draw();
5429 +  
5430 +  TLegend *leg = make_legend();
5431 +  leg->SetX1(0.15);
5432 +  leg->SetY1(0.7);
5433 +  leg->AddEntry(vanilla_ratio,"Raw JZB","pf");
5434 +  leg->AddEntry(response_only_up_ratio,"With response correction","pf");
5435 +  leg->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
5436 +  leg->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
5437 +  leg->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
5438 +  leg->AddEntry(lhi,"Systematic envelope","l");
5439 + //  leg->SetNColumns(2);
5440 +  leg->Draw();
5441 +  
5442 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison"+PostString);
5443 +  
5444 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5445 +  vanilla_ratio->Draw("e3");
5446 +  response_only_up_ratio->Draw("e3 same");
5447 +  response_only_down_ratio->Draw("e3 same");
5448 +  TLegend *leg2 = make_legend();
5449 +  leg2->SetX1(0.15);
5450 +  leg2->SetY1(0.7);
5451 +  leg2->AddEntry(vanilla_ratio,"Raw JZB","pf");
5452 +  leg2->AddEntry(response_only_up_ratio,"With response correction","pf");
5453 +  leg2->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
5454 +  leg2->AddEntry(lhi,"Systematic envelope","l");
5455 +  leg2->Draw();
5456 +  llow->Draw();
5457 +  lOne->Draw();
5458 +  llowA->Draw();
5459 +  lhiA->Draw();
5460 +  
5461 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Response"+PostString);
5462 +  
5463 +  response_only_up_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5464 +  response_only_up_ratio->Draw("e3");
5465 +  reponse_plus_peak_up_ratio->Draw("e3 same");
5466 +  reponse_plus_peak_down_ratio->Draw("e3 same");
5467 +  TLegend *leg3 = make_legend();
5468 +  leg3->SetX1(0.15);
5469 +  leg3->SetY1(0.7);
5470 +  leg3->AddEntry(response_only_up_ratio,"With response correction","pf");
5471 +  leg3->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
5472 +  leg3->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
5473 +  leg3->AddEntry(lhi,"Systematic envelope","l");
5474 +  leg3->Draw();
5475 +  llow->Draw();
5476 +  lOne->Draw();
5477 +  llowA->Draw();
5478 +  lhiA->Draw();
5479 +  
5480 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Peak"+PostString);
5481 +  
5482 +  delete ttcan2;
5483 + }
5484 +
5485 + void ttbar_correction_tests() {
5486 +  TCanvas *ttcan = new TCanvas("ttcan","ttcan");
5487 +    
5488 +  TH1F *vanilla_observed, *response_only_up_observed, *response_only_down_observed, *reponse_plus_peak_up_observed, *reponse_plus_peak_down_observed;
5489 +  
5490 +  TH1F *vanilla_predicted, *response_only_up_predicted, *response_only_down_predicted, *reponse_plus_peak_up_predicted, *reponse_plus_peak_down_predicted;
5491 +  
5492 +  TH1F *vanilla_ratio, *response_only_up_ratio, *response_only_down_ratio, *reponse_plus_peak_up_ratio, *reponse_plus_peak_down_ratio;
5493 +  
5494 +  TH1F *vanilla_ratio2, *response_only_up_ratio2, *response_only_down_ratio2, *reponse_plus_peak_up_ratio2, *reponse_plus_peak_down_ratio2;
5495 +  
5496 +  string vanilla="jzb[1]";
5497 +  string response_only_up="((jzb[1]+0.034665*pt))";
5498 +  string response_only_down="((jzb[1]-0.034665*pt))";
5499 +  string reponse_plus_peak_up="((jzb[1]+0.034665*pt)- 3.58273 )";
5500 +  string reponse_plus_peak_down="((jzb[1]+0.034665*pt)+ 3.58273 )";
5501 +
5502 +  do_one_ttbar_test(vanilla_observed,vanilla_predicted,vanilla_ratio,vanilla_ratio2,vanilla,"vanilla");
5503 +  do_one_ttbar_test(response_only_up_observed,response_only_up_predicted,response_only_up_ratio,response_only_up_ratio2,response_only_up,"response_only_up");
5504 +  do_one_ttbar_test(response_only_down_observed,response_only_down_predicted,response_only_down_ratio,response_only_down_ratio2,response_only_down,"response_only_down");
5505 +  do_one_ttbar_test(reponse_plus_peak_up_observed,reponse_plus_peak_up_predicted,reponse_plus_peak_up_ratio,reponse_plus_peak_up_ratio2,reponse_plus_peak_up,"reponse_plus_peak_up");
5506 +  do_one_ttbar_test(reponse_plus_peak_down_observed,reponse_plus_peak_down_predicted,reponse_plus_peak_down_ratio,reponse_plus_peak_down_ratio2,reponse_plus_peak_down,"reponse_plus_peak_down");
5507 +  
5508 +  ttcan->cd();
5509 +  
5510 +  IllustrateVariation(vanilla_ratio,response_only_up_ratio,response_only_down_ratio,reponse_plus_peak_up_ratio,reponse_plus_peak_down_ratio,"PartialRatio");
5511 +  IllustrateVariation(vanilla_ratio2,response_only_up_ratio2,response_only_down_ratio2,reponse_plus_peak_up_ratio2,reponse_plus_peak_down_ratio2,"FullRatio");
5512 +  
5513 +  delete vanilla_observed;
5514 +  delete response_only_up_observed;
5515 +  delete response_only_down_observed;
5516 +  delete reponse_plus_peak_up_observed;
5517 +  delete reponse_plus_peak_down_observed;
5518 +  
5519 +  delete vanilla_predicted;
5520 +  delete response_only_up_predicted;
5521 +  delete response_only_down_predicted;
5522 +  delete reponse_plus_peak_up_predicted;
5523 +  delete reponse_plus_peak_down_predicted;
5524 +  
5525 +  delete vanilla_ratio;
5526 +  delete response_only_up_ratio;
5527 +  delete response_only_down_ratio;
5528 +  delete reponse_plus_peak_up_ratio;
5529 +  delete reponse_plus_peak_down_ratio;
5530 +  
5531 +  delete ttcan;
5532 + }
5533 +
5534 + void ttbar_region_search(string mcjzb) {
5535 +  cout << "Looking for a nice control region" << endl;
5536 +  TCanvas *can = new TCanvas("can","can",1200,1200);
5537 +  can->Divide(2,2);
5538 +  can->cd(1);
5539 +  can->cd(1)->SetLogy(1);
5540 +  
5541 +  THStack JZBdistSF = allsamples.DrawStack("JZBdistSF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
5542 +  THStack JZBdistOF = allsamples.DrawStack("JZBdistOF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
5543 +  
5544 +  JZBdistSF.Draw("histo");
5545 +  JZBdistSF.SetMaximum(1000);
5546 +  JZBdistSF.SetMinimum(0.1);
5547 +  JZBdistSF.Draw("histo");
5548 +  DrawMCPrelim();
5549 +  
5550 +  can->cd(2);
5551 +  can->cd(2)->SetLogy(1);
5552 +  JZBdistOF.Draw("histo");
5553 +  JZBdistOF.SetMaximum(1000);
5554 +  JZBdistOF.SetMinimum(0.1);
5555 +  JZBdistOF.Draw("histo");
5556 +  DrawMCPrelim();
5557 +  
5558 +  can->cd(3);
5559 +  
5560 +  
5561 +  write_warning(__FUNCTION__,"Missing negative JZB subtraction  ");
5562 +  
5563 +  DrawMCPrelim();
5564 +  
5565 +  /*
5566 +  THStack *Subtracted = new THStack();
5567 +  
5568 +  TIter nextSF(JZBdistSF.GetHists());
5569 +  TIter nextOF(JZBdistOF.GetHists());
5570 +  TObject* SFobj;
5571 +  TObject* OFobj;
5572 +  
5573 +  TH1* sfh = NULL;
5574 +  TH1* ofh = NULL;
5575 +  
5576 +  while ( (SFobj = nextSF()) && (OFobj = nextOF()) ) {
5577 +    TH1F *sfstart = (TH1*)SFobj->Clone();
5578 +    TH1F *ofstart = (TH1*)OFobj->Clone();
5579 +    TH1F *obs, *pred;
5580 +    MakeObservationPrediction(obs,pred,sfstart,ofstart);
5581 +    
5582 +    if ( !hratio ) {
5583 +      hratio = (TH1*)obj->Clone();
5584 +      hratio->SetName("hratio");
5585 +    } else hratio->Add( (TH1*)obj );
5586      
5587 +  }
5588 +  hratio->Divide(hdata);
5589 +  */
5590 +  
5591 +  
5592 +  can->cd(4);
5593 +  JZBdistOF.Draw("histo");
5594 +  DrawMCPrelim();
5595 +  
5596 +  
5597 +  
5598 +  CompleteSave(can,"Systematics/TtbarTests/ControlRegion");
5599 +  
5600 +  CleanLegends();
5601 +  delete can;
5602 + }
5603 +
5604 + void ttbar_tests(string mcjzb) {
5605 +  //ttbar_correction_tests();
5606 +  ttbar_region_search(mcjzb);
5607 + }
5608  
5609   void test() {
5610    
# Line 4051 | Line 5612 | void test() {
5612    testcanv->cd();
5613   //  switch_overunderflow(true);
5614    TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
5615 <  switch_overunderflow(false);
5615 > //  switch_overunderflow(false);
5616    ptdistr->Draw();
5617    testcanv->SaveAs("test.png");
5618    dout << "HELLO there!" << endl;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines