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.57 by buchmann, Thu Sep 6 10:19:18 2012 UTC vs.
Revision 1.86 by buchmann, Mon Feb 25 15:39:12 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 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
98 +  
99 +  float NumVtxBin[6] = {0,5,10,15,20,100};
100 +  
101 +  stringstream NowCut;
102 +  
103 +  TGraphErrors *gMCPeak = new TGraphErrors();
104 +  gMCPeak->SetTitle("gMCPeak");
105 +  TGraphErrors *gDataPeak = new TGraphErrors();
106 +  gDataPeak->SetTitle("gDataPeak");
107 +  TGraphErrors *gMCWidth = new TGraphErrors();
108 +  gMCWidth->SetTitle("gMCWidth");
109 +  TGraphErrors *gDataWidth = new TGraphErrors();
110 +  gDataWidth->SetTitle("gDataWidth");
111 +  
112 +  
113 +  for(int i=0;i<5;i++) {
114 +    NowCut.str("");
115 +    NowCut << "numVtx>=" << NumVtxBin[i] << "&&numVtx<" << NumVtxBin[i+1];
116 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
117 +    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
118 +    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
119 +    
120 +    gMCPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),MCPeak);
121 +    gMCPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),MCPeakError);
122 +    
123 +    gDataPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),DataPeak);
124 +    gDataPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),DataPeakError);
125 +    
126 +    gMCWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),mcSigma);
127 +    gMCWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),mcSigmaError);
128 +    
129 +    gDataWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),dataSigma);
130 +    gDataWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),dataSigmaError);
131 +  }
132 +  
133 +  TFile *fo = new TFile("fout.root","RECREATE");
134 +  gMCPeak->Write();
135 +  gDataPeak->Write();
136 +  gMCWidth->Write();
137 +  gDataWidth->Write();
138 +  fo->Close();
139 +  
140 + }
141 +
142   void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb, string sSpecialCut="", bool SwitchOffNJetsCut=false)
143   {
144 +  bool overunderflowstatus=addoverunderflowbins;
145    switch_overunderflow(false);
146    
147    TCut SpecialCut("mll>=0");
# Line 160 | Line 213 | void find_peaks(float &MCPeak,float &MCP
213      MCPeakError=mcpeakerr;
214      DataPeak=datapeak;
215      DataPeakError=datapeakerr;
216 <    
164 <    switch_overunderflow(true);
165 <  
216 >    switch_overunderflow(overunderflowstatus);
217   }
218  
219   void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
# Line 229 | Line 280 | void make_special_obs_pred_mll_plot(stri
280    
281    RcorrJZBeemm->SetTitleOffset(1.3,"y");
282    RcorrJZBeemm->Draw();
283 <  mcRcorrJZBeemm.Draw("same");
283 >  mcRcorrJZBeemm.Draw("histo,same");
284    Bpred->Draw("histo,same");
285    RcorrJZBeemm->Draw("same");
286    
# Line 286 | Line 337 | void make_special_obs_pred_mll_plot(stri
337    }
338    delete Bpred;
339    delete ckin;
340 +  CleanLegends();
341   }
342  
343   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
# Line 306 | Line 358 | void make_special_mll_plot(int nbins, fl
358    datahistoOSSF->SetMarkerSize(DataMarkerSize);
359    datahistoOSSF->Draw();
360  
361 <  mcstackOSSF.Draw("same");
361 >  mcstackOSSF.Draw("histo,same");
362    datahistoOSSF->Draw("same");
363  
364    datahistoOSOF->SetMarkerColor(TColor::GetColor("#FE642E"));
# Line 332 | Line 384 | void make_special_mll_plot(int nbins, fl
384    delete datahistoOSOF;
385    delete datahistoOSSF;
386    delete ckin;
387 +  CleanLegends();
388   }
389    
390  
# Line 373 | Line 426 | void draw_ratio_plot(TH1* hdata, THStack
426   }
427  
428   float make_one_OFSF_plot(string variable, string addcut, string legendTitle, int nbins, float min, float max, float ymax, bool logscale,
429 <                        string xlabel, string filename, bool plotratio=true, bool loadlastminmax=false, float legendPosition=0.55) {
429 >                        string xlabel, string filename, float legendPosition=0.55) {
430  
431    TCut ibasiccut=basiccut;
432    bool draw_separation_lines=false;
# Line 385 | Line 438 | float make_one_OFSF_plot(string variable
438  
439    cutOF = cutOSOF&&cutnJets&&ibasiccut;
440    cutSF = cutOSSF&&cutnJets&&ibasiccut;
441 +  
442 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
443  
389  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
444    TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
445    rcan->SetLogy(logscale);
446    rcan->cd();
447  
448 +  std::cout << "OF/SF comparison: variable = " << variable << ", cut = " << cutSF.GetTitle() << std::endl;
449    TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,data,luminosity);
450    TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,data,luminosity);
451 <  string signal("LM3");
452 <  TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
453 <  int idx = signalsamples.FindSample(signal)[0];
454 <  (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
455 <  signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
456 <  signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
457 <  signalhisto->SetLineStyle(2);
451 > //   string signal("LM3");
452 > //   TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
453 > //   int idx = signalsamples.FindSample(signal)[0];
454 > //   (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
455 > //   signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
456 > //   signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
457 > //   signalhisto->SetLineStyle(2);
458    datahistoSF->SetMarkerSize(DataMarkerSize);
459    datahistoOF->SetLineColor(kRed);
460  
# Line 410 | Line 465 | float make_one_OFSF_plot(string variable
465    }
466    if (ymax<0) {
467      if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
468 <    else datahistoSF->SetMaximum(1.5*datahistoSF->GetMaximum());
468 >    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
469    } else {
470      datahistoSF->SetMaximum(ymax);
471    }
# Line 429 | Line 484 | float make_one_OFSF_plot(string variable
484    } else {
485      mleg->AddEntry((TObject*)0, "", "");
486    }
487 <  mleg->AddEntry(signalhisto, "LM3", "L");
487 >  //mleg->AddEntry(signalhisto, "LM3", "L");
488  
489    datahistoSF->Draw("E1");
490    if (datahistoOF->Integral()>0) datahistoOF->Draw("HIST,SAMES");
491 <  signalhisto->Draw("HIST,SAMES");
491 >  //signalhisto->Draw("HIST,SAMES");
492    mleg->Draw();
493    DrawPrelim();
494 <  if (datahistoOF->Integral()>0) save_with_ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
495 <  else CompleteSave(ckin, "SFOF/" + filename);
494 >  if (datahistoOF->Integral()>0) {
495 >    Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
496 >  } else {
497 >    CompleteSave(rcan, "SFOF/" + filename);
498 >  }
499  
500    datahistoSF->Delete();
501    datahistoOF->Delete();
502 <  signalhisto->Delete();
502 >  //signalhisto->Delete();
503    delete mleg;
504 <  delete ckin;
504 >  delete rcan;
505 >  delete ofsf_can;
506  
507    return ymaxSet;
508  
# Line 464 | Line 523 | float make_data_comparison_plot(string v
523  
524    TH1F *data1 = allsamples.Draw("data1",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
525    TH1F *data2 = comparesamples.Draw("data2",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
526 +  data1->Scale(5.0/9.2);
527  
528    data1->SetMarkerSize(DataMarkerSize);
529    data2->SetLineColor(kRed);
# Line 488 | Line 548 | float make_data_comparison_plot(string v
548    data1->GetYaxis()->CenterTitle();
549  
550    TLegend *mleg = make_legend("",legendPosition,0.7,false,legendPosition+0.2);
551 <  mleg->AddEntry(data1, "Old 5/fb", "PL");
552 <  mleg->AddEntry(data2, "New x/fb", "L");
551 >  mleg->AddEntry(data1, "2012 data (scaled)", "PL");
552 >  mleg->AddEntry(data2, "2011 data", "L");
553  
554    data1->Draw("E1");
555    data2->Draw("HIST,SAMES");
556    mleg->Draw();
557    DrawPrelim();
558 <  save_with_ratio( data1, data2, rcan, "compareData/" + filename, false, false, "old/new" );
558 >  Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
559  
560    data1->Delete();
561    data2->Delete();
562    delete mleg;
563 +  delete rcan;
564    delete ckin;
565  
566   }
# Line 507 | Line 568 | float make_data_comparison_plot(string v
568   void make_OFSF_plots(string variable, string addcut, int nbins, float min, float max, bool logscale,
569                       string xlabel, string filename, float legendPosition=0.55) {
570  
571 <  string mllcuts[] = { "mll>20","mll>20&&mll<70", "mll>75&&mll<105", "mll>120" };
572 <  string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "75 < m_{ll} < 105 GeV", "m_{ll} > 120 GeV" };
571 >  string mllcuts[] = { "mll>20","mll>15&&mll<70", "mll>75&&mll<105", "mll>120" };
572 >  string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "70 < m_{ll} < 110 GeV", "m_{ll} > 120 GeV" };
573    string plotname[] = {"_all","_low","_peak","_high"};
574    float ymax;
575  
# Line 518 | Line 579 | void make_OFSF_plots(string variable, st
579    for ( int i=start; i<4; ++i ) {
580      if ( addcut != "" ) mllcuts[i] += "&&"+addcut;
581      if ( i==start ) {
582 <      ymax = make_one_OFSF_plot(variable, mllcuts[i],            mllcutname[i], nbins, min, max, -1, logscale, xlabel,
582 >      ymax = make_one_OFSF_plot(variable, mllcuts[i], mllcutname[i], nbins, min, max, -1, logscale, xlabel,
583                           filename+plotname[i], legendPosition );
584      } else {
585 <      make_one_OFSF_plot(variable, mllcuts[i],            mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
585 >      make_one_OFSF_plot(variable, mllcuts[i],        mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
586                           filename+plotname[i], legendPosition );
587      }
588      make_one_OFSF_plot(variable, "id1==1&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
# Line 532 | Line 593 | void make_OFSF_plots(string variable, st
593  
594   }
595  
596 + TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
597 +  string scut=(string)(const char*)cut;
598 +  string acut=ReplaceAll(scut,replacethis,withthis);
599 +  return TCut(acut.c_str());
600 + }
601 +
602 + void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
603 +  TCut cut=addcut&&basiccut;
604 +
605 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
606 +  ckin->SetLogy(dolog);
607 +  cout << "\r Creating " << filename << " : data   (1/6)" << std::flush;
608 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
609 +  datahisto->SetMarkerSize(DataMarkerSize);
610 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
611 +  else datahisto->SetMinimum(0.5);
612 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
613 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
614 +  cout << "\r Creating " << filename << " : MC central   (2/6)" << std::flush;
615 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
616 +  TH1F *MCcentral = CollapseStack(mcstack);
617 +
618 +  TCut bkpcut = cut;
619 +  cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
620 +  cout << "\r Creating " << filename << " : MC JES up   (3/6)" << std::flush;
621 +  TH1F *MCJESup   = allsamples.Draw("MCJESup",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
622 +
623 +  cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
624 +  cout << "\r Creating " << filename << " : MC JES down   (4/6)" << std::flush;
625 +  TH1F *MCJESdn   = allsamples.Draw("MCJESdn",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
626 +  
627 +  cut=bkpcut;
628 +  TCut bkpweight = cutWeight;
629 +  cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
630 +  cout << "\r Creating " << filename << " : MC PU up   (5/6)" << std::flush;
631 +  TH1F *MCPUup    = allsamples.Draw("MCPUup",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
632 +  
633 +  cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
634 +  cout << "\r Creating " << filename << " : MC PU down   (6/6)" << std::flush;
635 +  TH1F *MCPUdn    = allsamples.Draw("MCPUdn",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
636 +  cutWeight=bkpweight;
637 +  cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
638 +  TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
639 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
640 +    float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
641 +    float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
642 +    float jes   = jesdn>jesup?jesdn:jesup;
643 +    
644 +    float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
645 +    float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
646 +    float pu   = PUdn>PUup?PUdn:PUup;
647 +    
648 +    float sys=sqrt(jes*jes+pu*pu);
649 +    sys/=MCcentral->GetBinContent(i);
650 +    if(MCcentral->GetBinContent(i)==0) sys=0;
651 +    Systematic->SetBinContent(i,sys);
652 +  }
653 +  
654 +  datahisto->Draw("e1");
655 +  ckin->Update();
656 +  mcstack.Draw("histo,same");
657 +  
658 +  datahisto->Draw("same,e1");
659 +  TLegend *kinleg = allsamples.allbglegend();
660 +  kinleg->Draw();
661 +
662 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
663 +  kinpad->SetLogy(dolog);
664 +  kinpad->cd();
665 +  datahisto->Draw("e1");
666 +  mcstack.Draw("histo,same");
667 +  datahisto->Draw("same,e1");
668 +  datahisto->Draw("same,axis");
669 +  
670 +  kinleg->Draw("same");
671 +  DrawPrelim();
672 +  string saveas="kin/"+filename;
673 +  
674 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
675 +  save_with_ratio_and_sys_band( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
676 +  
677 +  ckin->cd();
678 +  MCcentral->SetFillColor(kWhite);
679 +  MCcentral->SetLineColor(kBlack);
680 +  MCcentral->SetLineWidth(2);
681 +  MCPUdn->SetLineColor(kRed);
682 +  MCPUup->SetLineColor(kYellow);
683 +  MCJESdn->SetLineColor(kBlue);
684 +  MCJESup->SetLineColor(kGreen);
685 +  
686 +  TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
687 +  legsmall->SetNColumns(5);
688 +  legsmall->AddEntry(MCcentral,"central","L");
689 +  legsmall->AddEntry(MCPUdn,"PU down","L");
690 +  legsmall->AddEntry(MCPUup,"PU up","L");
691 +  legsmall->AddEntry(MCJESdn,"JES down","L");
692 +  legsmall->AddEntry(MCJESup,"JES up","L");
693 +  legsmall->SetFillColor(kWhite);
694 +  legsmall->SetBorderSize(0);
695 +  
696 +  datahisto->Draw("e1");
697 +  MCcentral->Draw("histo,same");
698 +  MCPUdn->Draw("histo,same");
699 +  MCPUup->Draw("histo,same");
700 +  MCJESdn->Draw("histo,same");
701 +  MCJESup->Draw("histo,same");
702 +  datahisto->Draw("e1,same");
703 +  legsmall->Draw();
704 +  CompleteSave(ckin,saveas+"___AllLines");
705 +  
706 +  delete datahisto;
707 +  delete MCcentral;
708 +  delete MCPUdn;
709 +  delete MCPUup;
710 +  delete MCJESdn;
711 +  delete MCJESup;
712 +  delete ckin;
713 + }
714  
715 + void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
716 +  DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
717 + }
718 +  
719   float lastrange_min=0;
720   float lastrange_max=0;
721  
# Line 541 | Line 724 | void make_kin_plot(string variable, stri
724   //  TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
725    TCut ibasiccut=basiccut;
726    bool draw_separation_lines=false;
727 +  bool drawsignal = false;
728    
729    if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
730  
# Line 562 | Line 746 | void make_kin_plot(string variable, stri
746    //Step 2: Refine the cut
747    TCut cut;
748    cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
749 <  if(filename=="nJets" || filename=="nJets_inclusive") cut=cutmass&&cutOSSF&&ibasiccut;
750 <  if(filename=="nJets_osof" || filename=="nJets_osof_inclusive") cut=cutmass&&cutOSOF&&ibasiccut;
749 >  if(filename=="nJets" || filename=="nJets_inclusive" || filename=="nJets_met100" || filename=="nJets_inclusive_met100") cut=cutmass&&cutOSSF&&ibasiccut;
750 >  if(filename=="nJets_osof" || filename=="nJets_osof_inclusive" || filename=="nJets_osof_met100" || filename=="nJets_osof_inclusive_met100") cut=cutmass&&cutOSOF&&ibasiccut;
751    if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
752 <  if(filename=="mll") {
752 >  if(filename=="mll"||filename=="mll_met100") {
753          cut=cutOSSF&&cutnJets&&ibasiccut;
754          draw_separation_lines=true;
755    }
756 <  if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
757 <  if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
758 <  if(filename=="mll_osof") {
756 >  if(filename=="mll_ee"||filename=="mll_ee_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
757 >  if(filename=="mll_mm"||filename=="mll_mm_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
758 >  if(filename=="mll_osof"||filename=="mll_osof_met100") {
759          cut=cutOSOF&&cutnJets&&ibasiccut;
760          draw_separation_lines=true;
761    }
# Line 579 | Line 763 | void make_kin_plot(string variable, stri
763    if(Contains(filename,"mll_ee_above")) cut=cut&&"id1==0";
764    if(Contains(filename,"mll_mm_above")) cut=cut&&"id1==1";
765    if(Contains(filename,"mll_osof_aboveJZB")) cut=cutOSOF&&cutnJets&&ibasiccut;
766 <  if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutmass&&cutOSSF;
767 <  if(filename=="mll_inclusive_osof") cut=cutmass&&cutOSOF;
768 <  if(filename=="mll_inclusive_ee") cut=cutmass&&cutOSSF&&"id1==0";
769 <  if(filename=="mll_inclusive_mm") cut=cutmass&&cutOSSF&&"id1==1";
766 >  if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
767 >  if(filename=="mll_inclusive_osof") cut=cutOSOF;
768 >  if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
769 >  if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
770    if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
771    if(filename=="pfJetGoodPt_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
772    if(filename=="numVtx") cut=cutmass&&ibasiccut;
# Line 603 | Line 787 | void make_kin_plot(string variable, stri
787    if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
788    else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
789  
790 <  cout << "******** Cut used : " << (const char*) cut << endl;
790 >  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
791    if(loadlastminmax) {
792          datahisto->SetMinimum(lastrange_min);
793          datahisto->SetMaximum(lastrange_max);
# Line 617 | Line 801 | void make_kin_plot(string variable, stri
801    string signal("LM3");
802    TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
803    int idx = signalsamples.FindSample(signal)[0];
804 <  (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
805 <  signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
806 <  signalhisto->SetLineColor(kOrange);
804 >  if(drawsignal) (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
805 >  if(drawsignal) signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
806 >  if(drawsignal) signalhisto->SetLineColor(kOrange);
807  
808    THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
809    datahisto->Draw("e1");
810    ckin->Update();
811 <  mcstack.Draw("same");
811 >  mcstack.Draw("histo,same");
812    
813    datahisto->Draw("same,e1");
814    TLegend *kinleg = allsamples.allbglegend();
# Line 667 | Line 851 | void make_kin_plot(string variable, stri
851          kinpad->cd();
852          kinpad->SetLogy(logscale);
853          datahisto->Draw("e1");
854 <        mcstack.Draw("same");
855 <        signalhisto->Draw("same");
854 >        mcstack.Draw("histo,same");
855 >        if(drawsignal) signalhisto->Draw("same");
856          datahisto->Draw("same,e1");
857          datahisto->Draw("same,axis");
858          if(RestrictToMassPeak&&draw_separation_lines) {
# Line 676 | Line 860 | void make_kin_plot(string variable, stri
860            upperboundary->Draw("same");
861          }
862            
863 <        kinleg->AddEntry("signalhisto",signal.c_str(),"l");
863 >        if(drawsignal) kinleg->AddEntry("signalhisto",signal.c_str(),"l");
864          kinleg->Draw();
865          write_cut->Draw();
866          DrawPrelim();
867          string saveas="kin/"+filename;
868          if(isPF) saveas="kin/"+filename+"__PF";
869 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
869 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
870   //      if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
871   //      else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
872   //      delete with_ratio;
# Line 691 | Line 875 | void make_kin_plot(string variable, stri
875          else CompleteSave(ckin,"kin/"+filename);
876    }
877    datahisto->Delete();
878 +  delete signalhisto;
879    delete ckin;
880   }
881  
882 +
883 + void make_plain_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
884 +                   string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
885 +  TCut cut=TCut(addcut.c_str())&&basiccut;
886 +
887 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
888 +  ckin->SetLogy(logscale);
889 +  TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
890 +  datahisto->SetMarkerSize(DataMarkerSize);
891 +  if ( !logscale ) datahisto->SetMinimum(0); // Defaults
892 +  else datahisto->SetMinimum(0.5);
893 +  // Custom max.
894 +  if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
895 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
896 +
897 +  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
898 +  if(loadlastminmax) {
899 +        datahisto->SetMinimum(lastrange_min);
900 +        datahisto->SetMaximum(lastrange_max);
901 +        if(logscale) {
902 +                datahisto->SetMinimum(pow(10,lastrange_min));
903 +                datahisto->SetMaximum(pow(10,lastrange_max));
904 +        }              
905 +  }
906 +
907 +  THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
908 +  datahisto->Draw("e1");
909 +  ckin->Update();
910 +  mcstack.Draw("histo,same");
911 +  
912 +  datahisto->Draw("same,e1");
913 +  TLegend *kinleg = allsamples.allbglegend();
914 +  kinleg->Draw();
915 +
916 +  lastrange_min=ckin->GetUymin();
917 +  lastrange_max=ckin->GetUymax();
918 +
919 +  if ( plotratio ) {
920 +        TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
921 +        kinpad->cd();
922 +        kinpad->SetLogy(logscale);
923 +        datahisto->Draw("e1");
924 +        mcstack.Draw("histo,same");
925 +        datahisto->Draw("same,e1");
926 +        datahisto->Draw("same,axis");
927 +          
928 +        kinleg->Draw();
929 +        DrawPrelim();
930 +        string saveas="kin/"+filename;
931 +        if(isPF) saveas="kin/"+filename+"__PF";
932 +        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
933 +  } else {
934 +        if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
935 +        else CompleteSave(ckin,"kin/"+filename);
936 +  }
937 +  datahisto->Delete();
938 +  delete ckin;
939 + }
940 +
941 +
942   void make_JES_plot(TCut cut, string name) {
943  
944    int nbins=10;
# Line 727 | Line 972 | void make_JES_plot(TCut cut, string name
972    JESunc->SetFillColor(TColor::GetColor("#00ADE1"));
973    JESunc->SetFillStyle(3002);
974    datahisto->Draw("e1");
975 <  mcstack.Draw("same");
975 >  mcstack.Draw("histo,same");
976    JESunc->Draw("2");
977    datahisto->Draw("same,e1");
978    TLegend *kinleg = allsamples.allbglegend();
# Line 736 | Line 981 | void make_JES_plot(TCut cut, string name
981    CompleteSave(ckin,"Systematics/JES"+name);
982    datahisto->Delete();
983    delete ckin;
984 +  delete JESunc;
985 +  delete JESup;
986 +  delete JESdn;
987 +  CleanLegends();
988 + }
989 +
990 + string Cut2Str(TCut cut) {
991 +  return ((string)(const char*)cut);
992 + }
993 +
994 + void MakeElegantTwoThreeComparisons() {
995 +    
996 +    TCut signal("met[4]>100&&met[4]<150&&mll>20"&&PlottingSetup::basicqualitycut);
997 +    TCut TwoJets("pfJetGoodNum40==2");
998 +    TCut ThreeJets("pfJetGoodNum40>=3");
999 +    
1000 +    float min=20;
1001 +    float max=300;
1002 +    int nbins=int((max-min)/5.0);
1003 +    string xlabel="m_{ll} [GeV]";
1004 +    
1005 +    TCanvas *can2 = new TCanvas("can2","can2");
1006 +    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1007 +    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1008 +    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1009 +    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1010 +    
1011 +    can2->cd(1);
1012 +    
1013 +    TwoSF->SetFillColor(kWhite);
1014 +    TwoOF->SetFillColor(kWhite);
1015 +    ThreeSF->SetFillColor(kWhite);
1016 +    ThreeOF->SetFillColor(kWhite);
1017 +    
1018 +    TPad *kin3 = new TPad("kin3","kin3",0,0,1,1);
1019 +    kin3->cd();
1020 +    TwoOF->Draw("histo");
1021 +    TwoSF->Draw("e1,same");
1022 +    TLegend *leg_SFOF_Two = make_legend();
1023 +    leg_SFOF_Two->SetHeader("t#bar{t} MC:");
1024 +    leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1025 +    leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1026 +    leg_SFOF_Two->Draw();
1027 +    Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1028 +    
1029 +    TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1030 +    kin4->cd();
1031 +    ThreeOF->Draw("histo");
1032 +    ThreeSF->Draw("e1,same");
1033 +    TLegend *leg_SFOF_Three = make_legend();
1034 +    leg_SFOF_Three->SetHeader("t#bar{t} MC:");
1035 +    leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1036 +    leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1037 +    leg_SFOF_Three->Draw();
1038 +    Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1039 +    
1040 +    
1041 +    TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
1042 +    TPad *kin = new TPad("kin","kin",0,0,1,1);
1043 +    kin->cd();
1044 +    TwoSF->Draw("histo");
1045 +    ThreeSF->Draw("e1,same");
1046 +    TLegend *leg_SF_Two_Three = make_legend();
1047 +    leg_SF_Two_Three->SetHeader("t#bar{t} MC:");
1048 +    leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1049 +    leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1050 +    leg_SF_Two_Three->Draw();
1051 +    Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1052 +    
1053 +    TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1054 +    TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
1055 +    kin2->cd();
1056 +    TwoOF->Draw("histo");
1057 +    ThreeOF->Draw("e1,same");
1058 +    TLegend *leg_OF_Two_Three = make_legend();
1059 +    leg_OF_Two_Three->SetHeader("t#bar{t} MC:");
1060 +    leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1061 +    leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1062 +    leg_OF_Two_Three->Draw();
1063 +    Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1064 +    
1065 + }
1066 +
1067 + void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1068 +  pad->cd();
1069 +  TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1070 +  for(int i=1;i<=Down->GetNbinsX();i++) {
1071 +    float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1072 +    float error=abs(Down->GetBinContent(i)-average);
1073 +    gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1074 +    gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1075 +  }
1076 +  gr->SetFillColor(TColor::GetColor("#F79F81"));
1077 +  gr->GetYaxis()->SetRangeUser(0,2);
1078 +  gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1079 +  gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1080 +  gr->GetXaxis()->CenterTitle();
1081 +  gr->GetYaxis()->CenterTitle();
1082 +  
1083 +  gr->Draw("A2");
1084 +  central->Draw("e1,same");
1085 +  DrawMCPrelim();
1086 +  TText *rtitle = write_text(0.8,0.8,title);
1087 +  TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1088 +  line->SetLineColor(kBlue);
1089 +  line->SetLineStyle(2);
1090 +  line->Draw("same");
1091 +  rtitle->Draw("same");
1092 + }
1093 +
1094 + TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1095 +  TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1096 +  basehisto->Add(originalttbar,-1);
1097 +  basehisto->Add(httbar);
1098 +  
1099 +  string sname=httbar->GetName();
1100 +  sname="R"+sname.substr(1,sname.length());
1101 +  TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1102 +  ratio->Divide(basehisto);
1103 +  delete basehisto;
1104 +  return ratio;
1105 + }
1106 +  
1107 + void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1108 +  
1109 +  TCut cut=addcut&&basiccut;
1110 +  
1111 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1112 +  ckin->SetLogy(dolog);
1113 +  cout << "\r Creating " << filename << " : data   (1/7)" << std::flush;
1114 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1115 +  datahisto->SetMarkerSize(DataMarkerSize);
1116 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1117 +  else datahisto->SetMinimum(0.5);
1118 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1119 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1120 +  cout << "\r Creating " << filename << " : MC central  (stack) (2/7)" << std::flush;
1121 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1122 +  TH1F *MCcentral = CollapseStack(mcstack);
1123 +
1124 +  cout << "\r Creating " << filename << " : MC central (histo)   (3/7)" << std::flush;
1125 +  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("TTJets_"));
1126 +  TH1F *RCentral        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1127 +  
1128 +  cout << "\r Creating " << filename << " : MC Matching up   (4/7)" << std::flush;
1129 +  TH1F *TMatchingUp     = systsamples.Draw("TMatchingUp",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1130 +  TH1F *RMatchingUp     = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1131 +  
1132 +  cout << "\r Creating " << filename << " : MC Matching down   (5/7)" << std::flush;
1133 +  TH1F *TMatchingDown   = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1134 +  TH1F *RMatchingDown   = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1135 +  
1136 +  cout << "\r Creating " << filename << " : MC Scale up   (6/7)" << std::flush;
1137 +  TH1F *TScaleUp        = systsamples.Draw("TScaleUp",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1138 +  TH1F *RScaleUp        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1139 +  
1140 +  cout << "\r Creating " << filename << " : MC Scale down   (7/7)" << std::flush;
1141 +  TH1F *TScaleDown      = systsamples.Draw("TScaleDown",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1142 +  TH1F *RScaleDown      = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1143 +  
1144 +  datahisto->Draw("e1");
1145 +  ckin->Update();
1146 +  mcstack.Draw("histo,same");
1147 +  
1148 +  datahisto->Draw("same,e1");
1149 +  TLegend *kinleg = allsamples.allbglegend();
1150 +  kinleg->Draw();
1151  
1152 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1153 +  kinpad->SetLogy(dolog);
1154 +  kinpad->cd();
1155 +  datahisto->Draw("e1");
1156 +  mcstack.Draw("histo,same");
1157 +  datahisto->Draw("same,e1");
1158 +  datahisto->Draw("same,axis");
1159 +  
1160 +  kinleg->Draw("same");
1161 +  DrawPrelim();
1162 +  string saveas="kin/"+filename;
1163 +  
1164 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1165 +  Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1166 +  delete kinpad;
1167 +  
1168 +  ckin->cd();
1169 +  TCentral->SetLineColor(kBlack);
1170 +  
1171 +  TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1172 +  TMatchingUp->SetLineStyle(2);//dashed
1173 +  TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1174 +  TMatchingDown->SetLineStyle(3);//dotted
1175 +  
1176 +  TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1177 +  TScaleUp->SetLineStyle(2);//dashed
1178 +  TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1179 +  TScaleDown->SetLineStyle(3);//dotted
1180 +  
1181 +  MCcentral->SetLineStyle(3);
1182 +  MCcentral->SetLineColor(kRed);
1183 +  
1184 +  TCentral->Draw("e1,same");
1185 +  TCentral->Draw("histo,same");
1186 +  TMatchingUp->Draw("histo,same");
1187 +  TMatchingDown->Draw("histo,same");
1188 +  TScaleUp->Draw("histo,same");
1189 +  TScaleDown->Draw("histo,same");
1190 +  
1191 +  TLegend *sleg = make_legend();
1192 +  sleg->AddEntry(TCentral,"Central","L");
1193 +  sleg->AddEntry(TMatchingUp,"matching up","L");
1194 +  sleg->AddEntry(TMatchingDown,"matching down","L");
1195 +  sleg->AddEntry(TScaleUp,"scale up","L");
1196 +  sleg->AddEntry(TScaleDown,"scale down","L");
1197 +  sleg->Draw();
1198 +  
1199 +  CompleteSave(ckin,saveas+"___AllLines");
1200 +  ckin->cd();
1201 +  ckin->SetLogy(0);
1202 +  
1203 +  RCentral->SetLineColor(kBlack);
1204 +  
1205 +  RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1206 +  RMatchingUp->SetLineStyle(2);//dashed
1207 +  RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1208 +  RMatchingDown->SetLineStyle(3);//dotted
1209 +  
1210 +  RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1211 +  RScaleUp->SetLineStyle(2);//dashed
1212 +  RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1213 +  RScaleDown->SetLineStyle(3);//dotted
1214 +  
1215 +  RCentral->GetYaxis()->SetRangeUser(0,2);
1216 +  RCentral->Draw("e1");
1217 +  RMatchingUp->Draw("histo,same");
1218 +  RMatchingDown->Draw("histo,same");
1219 +  RScaleUp->Draw("histo,same");
1220 +  RScaleDown->Draw("histo,same");
1221 +  
1222 +  CompleteSave(ckin,saveas+"___AllRatios");
1223 +
1224 +  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1225 +  multicanvas->Divide(2,1);
1226 +  PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1227 +  PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1228 +  CompleteSave(multicanvas,saveas+"___RangeIllustration");
1229 +  
1230 +  
1231 +  delete datahisto;
1232 +  delete   TCentral;
1233 +  delete   TMatchingUp;
1234 +  delete   TMatchingDown;
1235 +  delete   TScaleUp;
1236 +  delete   TScaleDown;
1237 + //   delete   Ttmass166;
1238 + //   delete   Ttmass169;
1239 + //   delete   Ttmass175;
1240 + //   delete   Ttmass178;
1241 +  
1242 +  delete ckin;
1243 +  
1244 + }
1245 +  
1246 + void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1247 +  make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1248 + }
1249 +
1250 + void ProduceJanPlots() {
1251 +  TCanvas *c1 = new TCanvas("c1","c1");
1252 +  TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1253 +  TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1254 +  
1255 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1256 +  rcan->cd();
1257 +
1258 +  metOF->SetLineColor(kRed);
1259 +  metSF->Draw("e1");
1260 +  metOF->Draw("histo,same");
1261 +  metSF->Draw("e1,same");
1262 +  
1263 +  TLegend *leg = make_legend();
1264 +  
1265 +  leg->AddEntry(metSF,"Data SF","p");
1266 +  leg->AddEntry(metOF,"Data OF","l");
1267 +  leg->Draw();
1268 +  
1269 +  DrawPrelim();
1270 +  
1271 +  Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1272 +  
1273 +  delete rcan;
1274 +  delete metSF;
1275 +  delete metOF;
1276 +  delete c1;
1277 + }
1278 +
1279 + THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1280 +  THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1281 +  
1282 +  //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1283 +  if(variation!="Central") {
1284 +    TH1F *varttbar;
1285 +    if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1286 +    if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1287 +    if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1288 +    if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1289 +    assert(varttbar);
1290 +    
1291 +    TIter nextHisto(SystPlot.GetHists());
1292 +    TH1F* h;
1293 +    while ( h = (TH1F*)nextHisto() ) {
1294 +      if(Contains(h->GetName(),"t_bar_t")) {
1295 +        varttbar->Scale(h->Integral()/varttbar->Integral());
1296 +        for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1297 +          h->SetBinContent(i,varttbar->GetBinContent(i));
1298 +          h->SetBinError(i,varttbar->GetBinError(i));
1299 +        }
1300 +        thisto=(TH1F*)varttbar->Clone(variation.c_str());
1301 +        SystPlot.Modified();
1302 +      }
1303 +    }
1304 +    delete varttbar;
1305 +  } else {
1306 +    TIter nextHisto(SystPlot.GetHists());
1307 +    TH1F* h;
1308 +    while ( h = (TH1F*)nextHisto() ) {
1309 +      if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1310 +    }
1311 +  }
1312 +    
1313 +  TLegend *fullleg = allsamples.allbglegend();
1314 +  fullleg->SetHeader(variation.c_str());
1315 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1316 +  kinpad->SetLogy(1);
1317 +  kinpad->cd();
1318 +  
1319 +  hdata->Draw("e1");
1320 +  SystPlot.Draw("histo,same");
1321 +  hdata->Draw("e1,same");
1322 +  fullleg->Draw();
1323 +  DrawPrelim();
1324 +  
1325 +  Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1326 +  CleanLegends();
1327 +  
1328 +  delete kinpad;
1329 +  return SystPlot;
1330 + }
1331 +  
1332 +
1333 +
1334 + void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1335 +  TCanvas *ca = new TCanvas("ca","ca");
1336 +  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1337 +  
1338 +  TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1339 +  
1340 +  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1341 +  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1342 +  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1343 +  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1344 +  
1345 +  TH1F *HScaleUp = CollapseStack(ScaleUp);
1346 +  TH1F *HScaleDown = CollapseStack(ScaleDown);
1347 +  TH1F *HMatchingUp = CollapseStack(MatchingUp);
1348 +  TH1F *HMatchingDown = CollapseStack(MatchingDown);
1349 +  
1350 +  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1351 +  TH1F *HCentral = CollapseStack(Central);
1352 +  
1353 +  TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1354 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1355 +    float matchingup   = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1356 +    float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1357 +    float scaleup   = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1358 +    float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1359 +    
1360 +    float matching = matchingup>matchingdown?matchingup:matchingdown;
1361 +    float scale    = scaleup>scaledown?scaleup:scaledown;
1362 +    
1363 +    float sys=sqrt(matching*matching+scale*scale);
1364 +    sys/=HCentral->GetBinContent(i);
1365 +    if(HCentral->GetBinContent(i)==0) sys=0;
1366 +    Systematic->SetBinContent(i,sys);
1367 +  }
1368 +  
1369 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1370 +  kinpad->SetLogy(1);
1371 +  kinpad->cd();
1372 +  if(variable=="genMET") {
1373 +    Central.Draw("histo");
1374 +  } else {
1375 +    hdata->Draw("e1");
1376 +    Central.Draw("histo,same");
1377 +    hdata->Draw("e1,same");
1378 +  }
1379 +  
1380 +  DrawPrelim();
1381 +  
1382 +  save_with_ratio_and_sys_band( hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1383 +  
1384 +  kinpad->cd();
1385 +  tCentral->SetFillColor(kWhite);
1386 +  tCentral->SetLineColor(kBlack);
1387 +  tScaleUp->SetLineColor(kRed);
1388 +  tScaleDown->SetLineColor(kRed);
1389 +  tMatchingUp->SetLineColor(kBlue);
1390 +  tMatchingDown->SetLineColor(kBlue);
1391 +  tScaleUp->SetLineStyle(2);
1392 +  tScaleDown->SetLineStyle(3);
1393 +  tMatchingUp->SetLineStyle(2);
1394 +  tMatchingDown->SetLineStyle(3);
1395 +  
1396 +  TLegend *leg2 = make_legend();
1397 +  leg2->AddEntry(hdata,"Data","p");
1398 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1399 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1400 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1401 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1402 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1403 +  if(variable=="genMET") {
1404 +    Central.Draw("histo");
1405 +  }else {
1406 +    hdata->Draw("e1");
1407 +    Central.Draw("histo,same");
1408 +    hdata->Draw("e1,same");
1409 +  }
1410 +  tCentral->Draw("histo,same");
1411 +  tScaleUp->Draw("histo,same");
1412 +  tScaleDown->Draw("histo,same");
1413 +  tMatchingUp->Draw("histo,same");
1414 +  tMatchingDown->Draw("histo,same");
1415 +  leg2->Draw();
1416 +  
1417 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1418 +  
1419 +  gStyle->SetOptFit(0);
1420 +  
1421 +  kinpad->cd();
1422 +  kinpad->SetLogy(0);
1423 +  TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1424 +  MatchingRatio->Divide(tMatchingDown);
1425 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1426 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1427 +  lone->SetLineStyle(2);
1428 +  TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1429 +  ScaleRatio->Divide(tScaleDown);
1430 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1431 +  MatchingRatio->Draw("e1");
1432 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1433 +  MatchingRatio->Fit("QP1","R");
1434 +  lone->Draw();
1435 +  stringstream summary;
1436 +  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);
1437 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1438 +  TText *infobox = write_title(summary.str());
1439 +  infobox->SetX(0.75);
1440 +  infobox->SetTextSize(0.03);
1441 +  infobox->SetY(0.75);
1442 +  infobox->Draw();
1443 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1444 +  kinpad->cd();
1445 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1446 +  ScaleRatio->Draw("e1");
1447 +  ScaleRatio->Fit("QP1","R");
1448 +  summary.str("");
1449 +  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);
1450 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1451 +  TText *infobox2 = write_title(summary.str());
1452 +  infobox2->SetX(0.75);
1453 +  infobox2->SetTextSize(0.03);
1454 +  infobox2->SetY(0.75);
1455 +  infobox2->Draw();
1456 +
1457 +  lone->Draw();
1458 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1459 +  
1460 +  
1461 +  delete QP1;
1462 +  delete infobox;
1463 +  delete infobox2;
1464 +  delete MatchingRatio;
1465 +  delete ScaleRatio;
1466 +  DeleteStack(ScaleUp);
1467 +  DeleteStack(ScaleDown);
1468 +  DeleteStack(MatchingUp);
1469 +  DeleteStack(MatchingDown);
1470 +  delete leg2;
1471 +  CleanLegends();
1472 +  DeleteStack(Central);
1473 +  delete Systematic;
1474 +  delete HScaleUp;
1475 +  delete HScaleDown;
1476 +  delete HMatchingUp;
1477 +  delete HMatchingDown;
1478 +  delete hdata;
1479 +  delete HCentral;
1480 +  delete ca;
1481 + }
1482 +
1483 + TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1484 +  float val=0,err=0;
1485 +  vector<float> bins;
1486 +  vector<float> vals;
1487 +  vector<float> errs;
1488 +  
1489 +  bins.push_back(binninghisto->GetBinLowEdge(1));
1490 +  int iBin=1;
1491 +  
1492 +  for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1493 +    if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1494 +      bins.push_back(histo->GetBinLowEdge(i));
1495 +      vals.push_back(val);val=0;
1496 +      errs.push_back(err);err=0;
1497 +      iBin++;
1498 +    }
1499 +    val+=histo->GetBinContent(i);
1500 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1501 +  }
1502 +  bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1503 +  vals.push_back(val);val=0;
1504 +  errs.push_back(err);err=0;
1505 +  
1506 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1507 +  for(unsigned int i=0;i<vals.size();i++) {
1508 +    h->SetBinContent(i+1,vals[i]);
1509 +    h->SetBinError(i+1,errs[i]);
1510 +  }
1511 +  
1512 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1513 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1514 +  
1515 +  h->GetXaxis()->CenterTitle();
1516 +  h->GetYaxis()->CenterTitle();
1517 +
1518 +  return h;
1519 + }
1520 +
1521 +
1522 + TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1523 +  float statsperbin = (1/(float)nbins) * histo->Integral();
1524 +  float val=0,err=0;
1525 +  vector<float> bins;
1526 +  vector<float> vals;
1527 +  vector<float> errs;
1528 +  
1529 +  bins.push_back(histo->GetBinLowEdge(1));
1530 +  for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
1531 +    val+=histo->GetBinContent(i);
1532 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1533 +    if( val/statsperbin > 0.85) {
1534 +      if(bins.size()<nbins) {
1535 +        bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1536 +        vals.push_back(val);val=0;
1537 +        errs.push_back(err);err=0;
1538 +      }
1539 +    }
1540 +    if(i==histo->GetNbinsX()) {
1541 +      bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1542 +      vals.push_back(val);val=0;
1543 +      errs.push_back(err);err=0;
1544 +    }
1545 +  }
1546 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1547 +  
1548 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1549 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1550 +  
1551 +  h->GetXaxis()->CenterTitle();
1552 +  h->GetYaxis()->CenterTitle();
1553 +  
1554 +  for(unsigned int i=0;i<vals.size();i++) {
1555 +    h->SetBinContent(i+1,vals[i]);
1556 +    h->SetBinError(i+1,errs[i]);
1557 +  }
1558 +  
1559 +  return h;
1560 + }
1561 +
1562 +
1563 +  
1564 + void ShowBinning(TH1F *histo) {
1565 +  cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
1566 +  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;
1567 + }
1568 +  
1569 + void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1570 +  TCanvas *ca = new TCanvas("ca","ca");
1571 +  TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
1572 +  TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
1573 +  TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
1574 +  TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
1575 +  TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
1576 +  
1577 +  tScaleUp->Scale(1.0/tScaleUp->Integral());
1578 +  tScaleDown->Scale(1.0/tScaleDown->Integral());
1579 +  tMatchingDown->Scale(1.0/tMatchingDown->Integral());
1580 +  tMatchingUp->Scale(1.0/tMatchingUp->Integral());
1581 +  tCentral->Scale(1.0/tCentral->Integral());
1582 +  
1583 +  cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
1584 +  
1585 +  
1586 +  TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
1587 +  TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
1588 +  TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
1589 +  TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
1590 +  TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
1591 +  
1592 +  float min=rtScaleUp->GetMinimum();
1593 +  float max=rtScaleUp->GetMaximum();
1594 +  
1595 +  if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
1596 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1597 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1598 +  if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
1599 +  if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
1600 +  
1601 +  if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
1602 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1603 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1604 +  if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
1605 +  if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
1606 +  
1607 +  rtCentral->SetMaximum(1.2*max);
1608 +  rtCentral->SetMinimum(0.8*min);
1609 +  
1610 + /*  tScaleUp->Rebin(40);
1611 +  tScaleDown->Rebin(40);
1612 +  tMatchingDown->Rebin(40);
1613 +  tMatchingUp->Rebin(40);
1614 +  tCentral->Rebin(40);*/
1615 +  
1616 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1617 +  kinpad->SetLogy(1);
1618 +  kinpad->cd();
1619 +  tCentral->SetFillColor(kWhite);
1620 +  tCentral->SetLineColor(kBlack);
1621 +  tScaleUp->SetLineColor(kRed);
1622 +  tScaleDown->SetLineColor(kRed);
1623 +  tMatchingUp->SetLineColor(kBlue);
1624 +  tMatchingDown->SetLineColor(kBlue);
1625 +  tScaleUp->SetLineStyle(2);
1626 +  tScaleDown->SetLineStyle(3);
1627 +  tMatchingUp->SetLineStyle(2);
1628 +  tMatchingDown->SetLineStyle(3);
1629 +  
1630 +  rtScaleDown->SetLineColor(kRed);
1631 +  rtMatchingUp->SetLineColor(kBlue);
1632 +  rtMatchingDown->SetLineColor(kBlue);
1633 +  rtScaleUp->SetLineStyle(2);
1634 +  rtScaleDown->SetLineStyle(3);
1635 +  rtMatchingUp->SetLineStyle(2);
1636 +  rtMatchingDown->SetLineStyle(3);
1637 +  
1638 +  TLegend *leg2 = make_legend();
1639 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1640 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1641 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1642 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1643 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1644 +  
1645 +  tCentral->Draw("histo");
1646 +  tScaleUp->Draw("histo,same");
1647 +  tScaleDown->Draw("histo,same");
1648 +  tMatchingUp->Draw("histo,same");
1649 +  tMatchingDown->Draw("histo,same");
1650 +  leg2->Draw();
1651 +  DrawMCPrelim();
1652 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1653 +  kinpad->cd();
1654 +  kinpad->SetLogy(0);
1655 +  rtCentral->Draw("histo");
1656 +  rtScaleUp->Draw("histo,same");
1657 +  rtScaleDown->Draw("histo,same");
1658 +  rtMatchingUp->Draw("histo,same");
1659 +  rtMatchingDown->Draw("histo,same");
1660 +  leg2->Draw();
1661 +  DrawMCPrelim();
1662 +  CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
1663 +  
1664 +  
1665 +  gStyle->SetOptFit(0);
1666 +
1667 +  kinpad->cd();
1668 +  kinpad->SetLogy(0);
1669 +  TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
1670 +  MatchingRatio->Divide(rtMatchingDown);
1671 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1672 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1673 +  lone->SetLineStyle(2);
1674 +  TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
1675 +  ScaleRatio->Divide(rtScaleDown);
1676 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1677 +  MatchingRatio->Draw("e1");
1678 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1679 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
1680 +  lone->Draw();
1681 +  stringstream summary;
1682 +  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);
1683 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1684 +  TText *infobox = write_title(summary.str());
1685 +  infobox->SetX(0.75);
1686 +  infobox->SetTextSize(0.03);
1687 +  infobox->SetY(0.75);
1688 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
1689 +  DrawMCPrelim();
1690 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1691 +  kinpad->cd();
1692 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1693 +  ScaleRatio->Draw("e1");
1694 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
1695 +  summary.str("");
1696 +  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);
1697 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1698 +  TText *infobox2 = write_title(summary.str());
1699 +  infobox2->SetX(0.75);
1700 +  infobox2->SetTextSize(0.03);
1701 +  infobox2->SetY(0.75);
1702 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
1703 +
1704 +  lone->Draw();
1705 +  DrawMCPrelim();
1706 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1707 +  
1708 +  kinpad->cd();
1709 +  TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
1710 +  TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
1711 +  TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
1712 +  
1713 +  for(int i=1;i<=SysScale->GetNbinsX();i++) {
1714 +    float matching, scale;
1715 +    bool AssumeFactor=false;
1716 +    if(AssumeFactor) {
1717 +      // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
1718 +      matching=0.;
1719 +      scale=0.;
1720 +    } else {
1721 +      // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
1722 +      matching = fabs(    ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
1723 +      scale    = fabs(    ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
1724 +    }
1725 +    
1726 +    SysMatching->SetBinContent(i,1+matching);
1727 +    SysScale->SetBinContent(i,1+scale);
1728 +    SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
1729 +  }
1730 +  
1731 +  SysHisto->SetLineColor(kGreen);
1732 +  
1733 +  SysMatching->SetMaximum(3.0);
1734 +  SysMatching->SetMinimum(0.0);
1735 +  SysMatching->Draw("histo");
1736 +  SysScale->Draw("histo,same");
1737 +  SysHisto->Draw("histo,same");
1738 +  CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
1739 +  
1740 +  delete SysMatching;
1741 +  delete SysScale;
1742 +  
1743 +  if(!Contains(variable,"gen")) {
1744 +    TH1F *hdata  = allsamples.Draw("hdata",   variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1745 +    THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
1746 +    
1747 +    TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1748 +    
1749 +    for(int i=1;i<=Systematic->GetNbinsX();i++) {
1750 +      int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
1751 +      if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
1752 +      float sys = SysHisto->GetBinContent(iBin)-1;
1753 +      Systematic->SetBinContent(i,sys);
1754 +    }
1755 +    
1756 +    kinpad->cd();
1757 +    TLegend *leg = allsamples.allbglegend();
1758 +    hdata->Draw();
1759 +    smc.Draw("histo,same");
1760 +    hdata->Draw("same");
1761 +    leg->Draw();
1762 +    DrawPrelim();
1763 +    save_with_ratio_and_sys_band( hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
1764 +    
1765 +    delete Systematic;
1766 +    delete hdata;
1767 +  }
1768 +  
1769 +  
1770 +  delete SysHisto;
1771 +  delete tScaleUp;
1772 +  delete tScaleDown;
1773 +  delete tCentral;
1774 +  delete tMatchingUp;
1775 +  delete tMatchingDown;
1776 +  delete rtScaleUp;
1777 +  delete rtScaleDown;
1778 +  delete rtCentral;
1779 +  delete rtMatchingUp;
1780 +  delete rtMatchingDown;
1781 +  delete QP1;
1782 +  delete infobox;
1783 +  delete infobox2;
1784 +  delete MatchingRatio;
1785 +  delete ScaleRatio;
1786 +  delete leg2;
1787 +  CleanLegends();
1788 +  delete ca;
1789 + }
1790 +
1791 + void ProduceMCSystematicPlots() {
1792 +  cout << "Getting ready to produce systematic plots " << endl;
1793 +  TCut cutweightBKP = cutWeight;
1794 +  
1795 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
1796 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
1797 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
1798 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
1799 +  
1800 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
1801 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
1802 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
1803 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
1804 +  
1805 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
1806 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
1807 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
1808 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
1809 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
1810 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
1811 +  
1812 +  
1813 +  
1814 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
1815 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1816 +  cutWeight="1.0";
1817 +  
1818 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1819 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
1820 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1821 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1822 +  
1823 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1824 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
1825 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1826 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1827 +  
1828 +  
1829 +  // --------------------------------------    ***** AACHEN *****      --------------------------------------    
1830 +  
1831 +  /*
1832 +  cutWeight=cutweightBKP;
1833 +  TCut essentialcutBKP = essentialcut;
1834 +  cout << (const char*) essentialcut << endl;
1835 +  
1836 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
1837 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1838 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1839 +  
1840 +  TCut cutnJetsBKP = cutnJets;
1841 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
1842 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
1843 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1844 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1845 +  
1846 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
1847 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
1848 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
1849 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
1850 +  
1851 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
1852 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
1853 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1854 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
1855 +  
1856 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
1857 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
1858 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1859 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
1860 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
1861 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
1862 +  
1863 +  
1864 +  
1865 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
1866 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1867 +  cutWeight="1.0";
1868 +  
1869 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1870 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
1871 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1872 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1873 +  
1874 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1875 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
1876 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1877 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1878 +  
1879 +  cutnJets  = cutnJetsBKP;
1880 +  cutWeight = cutweightBKP;
1881 +  essentialcut = essentialcutBKP;
1882 +  */
1883 +  write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
1884 + }
1885 +
1886 + void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
1887 +  TCut cut=pcut&&basiccut;
1888 +  string variable="mll";
1889 +  string xlabel="m_{ll} [GeV]";
1890 +  int nbins=40;
1891 +  float min=0;
1892 +  float max=200;
1893 +
1894 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1895 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
1896 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
1897 +  TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1898 +  TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1899 +  datahistoSF->SetMarkerSize(DataMarkerSize);
1900 +  datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
1901 +  datahistoOF->SetMarkerSize(DataMarkerSize);
1902 +  datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
1903 +
1904 +  THStack mcstackSF   = allsamples.DrawStack("mcstackSF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
1905 +  THStack mcstackOF   = allsamples.DrawStack("mcstackOF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
1906 +  datahistoSF->Draw("e1");
1907 +  ckin->Update();
1908 +  mcstackSF.Draw("histo,same");
1909 +  
1910 +  datahistoSF->Draw("same,e1");
1911 +  TLegend *kinleg = allsamples.allbglegend();
1912 +  kinleg->Draw();
1913 +  
1914 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1915 +  kinpad->cd();
1916 +  datahistoSF->Draw("e1");
1917 +  mcstackSF.Draw("histo,same");
1918 +  datahistoSF->Draw("same,e1");
1919 +  datahistoSF->Draw("same,axis");
1920 +  kinleg->Draw();
1921 +  DrawPrelim();
1922 +  Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
1923 +  
1924 +  kinpad->cd();
1925 +  datahistoOF->Draw("e1");
1926 +  mcstackOF.Draw("histo,same");
1927 +  datahistoOF->Draw("same,e1");
1928 +  datahistoOF->Draw("same,axis");
1929 +  kinleg->Draw();
1930 +  DrawPrelim();
1931 +  Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
1932 +  
1933 +  kinpad->cd();
1934 +  tauSF->Draw("e1");
1935 +  tauOF->Draw("histo,same");
1936 +  tauSF->Draw("e1,same");
1937 +  TLegend *legtau = make_legend();
1938 +  legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
1939 +  legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
1940 +  legtau->Draw();
1941 +  DrawPrelim();
1942 +  Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
1943 +  
1944 +  delete datahistoSF;
1945 +  delete datahistoOF;
1946 +  delete tauSF;
1947 +  delete tauOF;
1948 +  delete kinpad;
1949 +  delete ckin;
1950 +  CleanLegends();
1951 + }
1952 +  
1953 +
1954 + void TauQuestion() {
1955 + //   MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
1956 + //   MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
1957 + //   MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
1958 +  MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
1959   }
1960  
1961   void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
1962   {
1963 + //  switch_overunderflow(true);
1964    bool dolog=true;
1965    bool nolog=false;
1966  
1967    bool doOFSF = false;
1968 <  bool doKin  = false;
1969 <  bool doDataComp = true;
1968 >  bool doKin  = true;
1969 >  bool doDataComp = false;
1970 >  bool MakeTwoThreeJetComparison = false;
1971    
1972  
1973    if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
# Line 756 | Line 1977 | void do_kinematic_plots(string mcjzb, st
1977          mll_low=20;
1978          mll_hi=320;
1979    }
1980 +  
1981 +  if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
1982 +  
1983 +  //TauQuestion();
1984  
1985 +  //ProduceJanPlots();
1986 +  ProduceMCSystematicPlots();
1987 +  assert(0);
1988 + //  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
1989 +  
1990    if ( doOFSF ) {
1991 <    make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
1992 <
1993 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100", 7, 3, 10, true, "#(jets)", "njets");
1994 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
1995 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100&&pfJetGoodNumBtag30>0", 7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
1996 <
1997 <    make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
1998 <    make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
1999 <    make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
2000 <    //  make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
2001 <    //  make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
2002 <    make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
2003 <    make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
2004 <    //  make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
2005 <    //  make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
2006 <    //  make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
2007 <    make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
1991 >     make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
1992 >     make_OFSF_plots("met[4]", "met[4]>100", 30, 100., 400., false, "PFMET", "met");
1993 >     make_OFSF_plots("leptonNum", "met[4]>100", 3, 2, 5., false, "N(leptons)", "NLeptons");
1994 >
1995 >     make_OFSF_plots("pfJetGoodNum40", "met[4]>100",                        7, 3, 10, true, "#(jets)", "njets");
1996 >     make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
1997 >     make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
1998 >
1999 >     make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
2000 >     make_OFSF_plots("pfJetGoodPtBtag[0]", "met[4]>100&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", "ptb1");
2001 >
2002 >     make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
2003 >     make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
2004 >     make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
2005 >     make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
2006 >     make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
2007 >     make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
2008 >     make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
2009 >     make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
2010 >     make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
2011 >     make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
2012      make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
2013 <    //  make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
2014 <    //  make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
2013 >    make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
2014 >    make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
2015      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");
2016      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");
2017      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");
2018      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");
2019    }
2020  
2021 <  if ( doDataComp && !PlottingSetup::openBox ) {
2021 >  if ( doDataComp) {
2022      TCut mllCut("");
2023 <    if ( !PlottingSetup::openBox ) mllCut = "mll>120";
2023 >    float massmin = 15.;
2024 >    float massmax = 315;
2025 >    int massnbins = 60;
2026 > /*    if ( !PlottingSetup::openBox ) {
2027 >      mllCut = "mll>70";
2028 >      massmin = 120;
2029 >      massmax = 360;
2030 >      massnbins = 14;
2031 >    }*/
2032  
2033      TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2034 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig");
2035 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee");
2036 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm");
2037 <
2038 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0",           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2039 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0&&pfJetGoodNumBtag30==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee_btagVeto");
2040 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1&&pfJetGoodNumBtag30==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm_btagVeto");
2041 <
2042 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2043 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0&&pfJetGoodNumBtag30>0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee_AtLeastOneBJet");
2044 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1&&pfJetGoodNumBtag30>0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm_AtLeastOneBJet");
2034 >    
2035 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2036 >    make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2037 >    
2038 >    
2039 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF,10, -0.5, 9.5,-1., true, "N(Jets)", "njets_OF");
2040 >    make_data_comparison_plot("met[4]", cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_inclusive");
2041 >    make_data_comparison_plot("met[1]", cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_inclusive");
2042 >    make_data_comparison_plot("met[4]", cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_inclusive");
2043 >    make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2044 >    
2045 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2046 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2047 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2048 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2049 >
2050 >  
2051 >    string basiccutsaved = (const char*)basiccut;
2052 >    
2053 >    string newbasiccut=basiccutsaved;
2054 >    
2055 >    size_t found;
2056 >    found = newbasiccut.find( "pt2>20" );
2057 >    while (found!=string::npos){
2058 >      newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2059 >      found = newbasiccut.find( "pt2>20" );
2060 >    }
2061 >    basiccut=TCut(newbasiccut.c_str());
2062 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2063 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2064 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2065 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2066 >    basiccut=TCut(basiccutsaved.c_str());
2067 >    
2068 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2069 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2070 >    
2071 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2072 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2073 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2074 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2075 >
2076 >    
2077 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2078 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2079 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2080 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2081 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2082 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2083 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2084 >    make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2085 >
2086 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2087 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2088 >    
2089 >    make_data_comparison_plot("mll", TCut("abs(eta1)<1.4&&abs(eta2)<1.4") && cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_central");
2090 >    make_data_comparison_plot("mll", TCut("abs(eta1)<1.4&&abs(eta2)<1.4") && cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_central");
2091 >    
2092 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2093 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_btagVeto");
2094 >    
2095 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2096 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2097 >
2098 >
2099 >    make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2100 >    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");
2101 >    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");
2102 >
2103 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_SF_sig");
2104 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2105 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2106 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2107  
804    make_data_comparison_plot("mll", cutOSOF&&cutSignal, 60, 20., 320.,-1., false, "m_{ll}", "mll_OF_sig");
805    make_data_comparison_plot("mll", cutmass&&"met[4]>100&&met[4]<150&&pfJetGoodNum40<3", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_CR");
2108    }
2109  
2110  
2111    if ( doKin ) {
2112      string mllCut("");
2113 <    if ( !PlottingSetup::openBox ) mllCut = "&&mll>120";
2114 <
2113 >    
2114 >    
2115 >  
2116 >    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);
2117 >    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);
2118 >    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);
2119 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),40,0,400,dolog,"PFMET","Debunking/MET_OF_30to70_3j",doPF,true);
2120 >
2121 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),40,0,400,dolog,"PFMET","Debunking/MET_OF_Z_0j",doPF,true);
2122 >    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);
2123 >    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);
2124 >    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);
2125 >
2126 >
2127 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2128 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2129 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2130 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2131 >
2132 >    
2133 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_30to70_0j",doPF,true);
2134 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_30to70_1j",doPF,true);
2135 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_30to70_2j",doPF,true);
2136 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_30to70_3j",doPF,true);
2137 >
2138 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_Z_0j",doPF,true);
2139 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_Z_1j",doPF,true);
2140 >    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);
2141 >    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);
2142 >
2143 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2144 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2145 >    
2146 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2147 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2148 >    
2149 >    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);
2150 >    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);
2151 >    
2152 >    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);
2153 >    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);
2154 >
2155 >    
2156 >    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2157 >    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2158      // Plots in signal region
2159      make_kin_plot("met[4]","",70,0,350,dolog,"MET [GeV]","met",doPF,true);
2160 <    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",doPF,true);
2161 <    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",doPF,true,true);
2162 <    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",doPF,true);
2163 <    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",doPF,true);
2160 >
2161 >
2162 >    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2163 >    
2164 >    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");
2165 >    /*
2166 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2167 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2168 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2169 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2170 >
2171 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2172 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2173 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2174 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2175 >
2176 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2177 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2178 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2179 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2180 >
2181 >    
2182 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2183 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2184 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2185 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2186 >
2187 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2188 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2189 >
2190 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2191 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2192 >    
2193 >    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2194 >    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2195 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2196 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2197 >
2198 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2199 >    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);
2200 >    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);
2201 >    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);
2202 >    
2203 >    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2204 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2205 >    
2206 >    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);
2207 >    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);
2208 >    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);
2209 >    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);
2210 >    
2211      
2212 <    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2213 <    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2212 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2213 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2214  
2215      // Further inclusive invariant mass plots
2216 <    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2216 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2217      make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2218      make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2219 <    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2219 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2220      
2221 <    //make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2221 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2222      //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2223      
832    //make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
833    //make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2224      
2225      // Number of jets
2226      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2227      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2228 <    //make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2228 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2229      
2230      // Others
2231      make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
# Line 867 | Line 2257 | void do_kinematic_plots(string mcjzb, st
2257      
2258      //   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);
2259      //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);
2260 <    //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);
2260 >    //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);*/
2261    }
2262 <    
2263 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2264 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2265 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2266 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2267 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2268 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2269 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
880 <
881 < //   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
882 < //   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2262 >    /*
2263 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2264 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2265 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2266 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2267 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2268 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2269 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2270  
2271 +   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2272 +   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2273 + */
2274 +  switch_overunderflow(false);
2275   }
2276  
2277   void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
# Line 920 | Line 2311 | void make_comp_plot( string var, string
2311        if (ymax>ymin) datahisto->SetMaximum(ymax);
2312        lm3histo->SetLineStyle(2);
2313        datahisto->Draw("e1");
2314 <      mcstack.Draw("same");
2314 >      mcstack.Draw("histo,same");
2315        datahisto->Draw("same,e1");
2316        lm3histo->Draw("hist,same");
2317        TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
# Line 950 | Line 2341 | void region_comparison_plots(string mcjz
2341  
2342   //  switch_overunderflow(true);  // switching overflow/underflow bins on
2343      
2344 <  
2344 >  switch_overunderflow(true);
2345      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
2346    for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
2347      float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
# Line 1267 | Line 2658 | if you want to start from scratch (witho
2658  
2659   void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
2660   {
2661 < //  switch_overunderflow(true);
2661 >  
2662    bool is_data=false;
2663    bool use_signal=false;
2664    if(use_data==1) is_data=true;
2665    if(use_data==2) use_signal=true;
2666 <  int nbins=50;//100;
2667 <  if(is_data) nbins=50;
2666 >  int nbins=int(high/10);//100;
2667 >  if(is_data) nbins=int(high/10);
2668    float low=0;
2669 <  float hi=500;
2669 >  float hi=high;
2670 >  
2671 >  stringstream cutpositiveS;
2672 >  cutpositiveS << "(" << jzb << ">0)";
2673 >  TCut cutpositive(cutpositiveS.str().c_str());
2674 >  stringstream cutnegativeS;
2675 >  cutnegativeS << "(" << jzb << "<0)";
2676 >  TCut cutnegative(cutnegativeS.str().c_str());
2677 >  
2678    
2679    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
2680 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2681 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2682 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2683 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2680 >  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2681 >  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2682 >  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2683 >  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2684  
2685    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
2686    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
# Line 1296 | Line 2695 | void do_prediction_plot(string jzb, TCan
2695    
2696    TH1F *RcorrJZBeemmNoS;
2697  
2698 <    //these are for the ratio
2699 <  
2700 <  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2701 <  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2702 <  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1304 <  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2698 >  //these are for the ratio
2699 >  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2700 >  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2701 >  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2702 >  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2703    
2704    TH1F *JRcorrJZBSBem;
2705    TH1F *JLcorrJZBSBem;
2706    TH1F *JRcorrJZBSBeemm;
2707    TH1F *JLcorrJZBSBeemm;
2708    
2709 <  if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
2709 >  if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
2710  
2711    
2712    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2713 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2714 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2715 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2716 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2713 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2714 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2715 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2716 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2717      
2718      //these are for the ratio
2719 <    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2720 <    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2721 <    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2722 <    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2719 >    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2720 >    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2721 >    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2722 >    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2723    }
2724    
2725    TH1F *lm4RcorrJZBeemm;
2726 <  if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM"));
2726 >  if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM"));
2727    
2728    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
2729    
# Line 1389 | Line 2787 | void do_prediction_plot(string jzb, TCan
2787    SQRT(BpredSys);
2788    BpredSys->Divide(JBpred);
2789  
1392  
2790    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
2791    TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
2792    Tpred->Add(LcorrJZBem,-1.0);
# Line 1442 | Line 2839 | void do_prediction_plot(string jzb, TCan
2839      Bpred->Draw("hist,same");
2840      //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2841      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2842 <    lm4RcorrJZBeemm->Draw("hist,same");
2842 >    //lm4RcorrJZBeemm->Draw("hist,same");
2843      legBpred->AddEntry(RcorrJZBeemm,"observed","p");
2844      legBpred->AddEntry(Bpred,"predicted","l");
2845   //    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
2846   //    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
2847 <    legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
2847 > //     legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
2848      legBpred->Draw();
2849      DrawPrelim();
2850  
# Line 1457 | Line 2854 | void do_prediction_plot(string jzb, TCan
2854      Bpred->SetLineWidth(2);
2855      predcomppad->cd();
2856      predcomppad->SetLogy(1);
1460    
2857      TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
2858      TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
2859      sidebandsemu->Add(jzbnegative,-1);
# Line 1479 | Line 2875 | void do_prediction_plot(string jzb, TCan
2875   //    lm4RcorrJZBeemm->SetLineColor(kOrange+1);
2876      lm4RcorrJZBeemm->SetLineWidth(2);
2877      //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
2878 <    lm4RcorrJZBeemm->Draw("histo,same");
2878 > //     lm4RcorrJZBeemm->Draw("histo,same");
2879      DrawPrelim();
2880      TLegend *speciallegBpred = make_legend("",0.45,0.55);
2881      //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
# Line 1489 | Line 2885 | void do_prediction_plot(string jzb, TCan
2885      if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
2886      else speciallegBpred->AddEntry(sidebandsemu,"e#mu (data)","f");
2887   //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
2888 <    speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2888 > //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2889      speciallegBpred->Draw();
2890 <    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
2890 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
2891 >    delete predcomppad;
2892      
2893      TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
2894      specialcanv->SetLogy(1);
2895   //    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
2896      blankback->Draw();
2897   //    kostack.Draw("same");
2898 <    predcomposition.Draw();
2898 >    predcomposition.Draw("hist");
2899      Bpred->Draw("hist,same");
2900      //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2901      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
# Line 1525 | Line 2922 | void do_prediction_plot(string jzb, TCan
2922      legBpred->AddEntry(Bpred,"MC predicted","l");    
2923      if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
2924      if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
2925 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2925 > //     if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2926      legBpred->Draw();
2927      DrawMCPrelim();
2928      Bpredsaveas="Bpred_MC";
# Line 1557 | Line 2954 | void do_prediction_plot(string jzb, TCan
2954        
2955        RcorrJZBeemmNoS->SetLineStyle(2);
2956        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
2957 <      legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
2957 > //       legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
2958        legBpred2->Draw();
2959        RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
2960        RcorrJZBeemmNoS->Draw("histo,same");
# Line 1574 | Line 2971 | void do_prediction_plot(string jzb, TCan
2971    string ytitle("ratio");
2972    if ( use_data==1 ) ytitle = "data/pred";
2973    //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
2974 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
2974 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
2975 >  
2976 >  delete kinpad;
2977 >
2978  
2979    
2980    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
# Line 1634 | Line 3034 | void do_prediction_plot(string jzb, TCan
3034        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3035        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3036        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3037 <      if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3037 > //       if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3038        legBpredc->Draw();
3039        CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3040      }
# Line 1670 | Line 3070 | void do_prediction_plot(string jzb, TCan
3070      delete JLcorrJZBSBeemm;
3071    }
3072    if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
1673  switch_overunderflow(false);
3073   }
3074  
3075   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3076 +  switch_overunderflow(true);
3077    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3078    do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3079    if ( !PlottingSetup::Approved ) {
# Line 1682 | Line 3082 | void do_prediction_plots(string mcjzb, s
3082    } else {
3083      write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3084    }
3085 < }
3086 <
1687 < void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
1688 <  bool do_data=0;
1689 <  bool dosignal=0;
1690 <  if(is_data==1) do_data=1;
1691 <  if(is_data==2) dosignal=1;
1692 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1693 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1694 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1695 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1696 <  
1697 <  TH1F *RcorrJZBSBem;
1698 <  TH1F *LcorrJZBSBem;
1699 <  TH1F *RcorrJZBSBeemm;
1700 <  TH1F *LcorrJZBSbeemm;
1701 <  
1702 <  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
1703 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1704 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1705 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1706 <    LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1707 <  }
1708 <  
1709 <
1710 <
1711 <
1712 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1713 <  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1714 <  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
1715 <    Bpred->Add(RcorrJZBem,1.0/3);
1716 <    Bpred->Add(LcorrJZBem,-1.0/3);
1717 <    Bpred->Add(RcorrJZBSBem,1.0/3);
1718 <    Bpred->Add(LcorrJZBSBem,-1.0/3);
1719 <    Bpred->Add(RcorrJZBSBeemm,1.0/3);
1720 <    Bpred->Add(LcorrJZBSbeemm,-1.0/3);
1721 <  } else {
1722 <    Bpred->Add(RcorrJZBem,1.0);
1723 <    Bpred->Add(LcorrJZBem,-1.0);
1724 <  }
1725 <
1726 <  can->cd();
1727 <  can->SetLogy(0);
1728 <  Bpred->SetLineColor(kRed);
1729 <  Bpred->SetStats(0);
1730 <  if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
1731 <  TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
1732 <  JZBratioforfitting->Divide(Bpred);
1733 <  TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
1734 <  
1735 <  
1736 <  JZBratio->SetTitle("");
1737 <  JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
1738 < //  if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
1739 <  
1740 <  TF1 *pol0 = new TF1("pol0","[0]",0,1000);
1741 <  TF1 *pol0d = new TF1("pol0","[0]",0,1000);
1742 < //  straightline_fit->SetParameter(0,1);
1743 <  JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
1744 <  pol0d->SetParameter(0,pol0->GetParameter(0));
1745 <  
1746 <  JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
1747 <  JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
1748 <  if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
1749 <  JZBratio->GetYaxis()->SetNdivisions(519);
1750 <  JZBratio->GetYaxis()->SetRangeUser(0.0,4.0);
1751 <  JZBratio->GetYaxis()->CenterTitle();
1752 <  JZBratio->GetXaxis()->CenterTitle();
1753 <  JZBratio->SetMarkerSize(DataMarkerSize);
1754 <  JZBratio->Draw("AP");
1755 <  /////----------------------------
1756 <  TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
1757 <  writeresult->SetFillStyle(4000);
1758 <  writeresult->SetFillColor(kWhite);
1759 <  writeresult->SetTextFont(42);
1760 <  writeresult->SetTextSize(0.03);
1761 <  writeresult->SetTextAlign(12);
1762 <  ostringstream jzb_agreement_data_text;
1763 <  jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) <<  pol0->GetParError(0);
1764 <  if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
1765 <  if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
1766 < /*  if(is_data) writeresult->AddText("Data closure test");
1767 <  else writeresult->AddText("MC closure test");
1768 <  */
1769 <  writeresult->AddText(jzb_agreement_data_text.str().c_str());
1770 < //  writeresult->Draw("same");
1771 < //  pol0d->Draw("same");
1772 <  TF1 *topline =  new TF1("","1.5",0,1000);
1773 <  TF1 *bottomline =  new TF1("","0.5",0,1000);
1774 <  topline->SetLineColor(kBlue);
1775 <  topline->SetLineStyle(2);
1776 <  bottomline->SetLineColor(kBlue);
1777 <  bottomline->SetLineStyle(2);
1778 < //  topline->Draw("same");
1779 < //  bottomline->Draw("same");
1780 <  TF1 *oneline = new TF1("","1.0",0,1000);
1781 <  oneline->SetLineColor(kBlue);
1782 <  oneline->SetLineStyle(1);
1783 <  oneline->Draw("same");
1784 <  TLegend *phony_leg = make_legend("ratio",0.6,0.55,false);//this line is just to have the default CMS Preliminary (...) on the canvas as well.
1785 <  if(is_data==1) DrawPrelim();
1786 <  else DrawMCPrelim();
1787 <  TLegend *leg = new TLegend(0.55,0.75,0.89,0.89);
1788 <  leg->SetTextFont(42);
1789 <  leg->SetTextSize(0.04);
1790 < //   if(is_data==1) leg->SetHeader("Ratio (data)");
1791 < //   else leg->SetHeader("Ratio (MC)");
1792 <
1793 <  TString MCtitle("MC ");
1794 <  if (is_data==1) MCtitle = "";
1795 <
1796 <  leg->SetFillStyle(4000);
1797 <  leg->SetFillColor(kWhite);
1798 <  leg->SetTextFont(42);
1799 < //  leg->AddEntry(topline,"+20\% sys envelope","l");
1800 <  leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
1801 <  leg->AddEntry(oneline,"ratio = 1","l");
1802 < //  leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
1803 < //  leg->AddEntry(bottomline,"#pm50% envelope","l");
1804 <
1805 <
1806 <  //leg->Draw("same"); // no longer drawing legend
1807 <
1808 <  if(is_data==1) CompleteSave(can, "jzb_ratio_data");
1809 <  if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
1810 <  if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
1811 <  
1812 <  delete RcorrJZBeemm;
1813 <  delete LcorrJZBeemm;
1814 <  delete RcorrJZBem;
1815 <  delete LcorrJZBem;
1816 <  
1817 <  delete RcorrJZBSBem;
1818 <  delete LcorrJZBSBem;
1819 <  delete RcorrJZBSBeemm;
1820 <  delete LcorrJZBSbeemm;
1821 < }
1822 <
1823 < void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
1824 <  TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
1825 <  globalc->SetLogy(0);
1826 <  
1827 <  do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh  );
1828 <  do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh  );
1829 <  do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh  );
3085 >  delete globalcanvas;
3086 >  switch_overunderflow(false);
3087   }
3088  
3089   string give_jzb_expression(float peak, int type) {
# Line 1913 | Line 3170 | void lepton_comparison_plots() {
3170    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3171    eemmlegend->Draw();
3172    DrawPrelim();
3173 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3173 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3174    
3175    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"));
3176    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 2014 | Line 3271 | void draw_pure_jzb_histo(TCut cut,string
3271    datahisto->SetMinimum(0.1);
3272    datahisto->SetMarkerSize(DataMarkerSize);
3273    datahisto->Draw("e1");
3274 <  mcstack.Draw("same");
3274 >  mcstack.Draw("histo,same");
3275    datahisto->Draw("same,e1");
3276    
3277    TLegend *leg;
# Line 2036 | Line 3293 | void draw_pure_jzb_histo(TCut cut,string
3293    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3294    writeline1->SetTextSize(0.035);
3295    writeline1->Draw();
3296 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3297 <  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
3296 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3297 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3298    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3299    jzbpad2->cd();
3300    jzbpad2->SetLogy(1);
# Line 2045 | Line 3302 | void draw_pure_jzb_histo(TCut cut,string
3302    datahisto->SetMinimum(0.1);
3303    datahisto->SetMarkerSize(DataMarkerSize);
3304    datahisto->Draw("e1");
3305 <  mcstack.Draw("same");
3305 >  mcstack.Draw("histo,same");
3306    datahisto->Draw("same,e1");
3307    leg->SetHeader("");
3308    leg->Draw();
3309    writeline1->SetTextSize(0.035);
3310    writeline1->Draw();
3311    DrawPrelim();
3312 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3313 <  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3312 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3313 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3314    datahisto->Delete();
3315    mcstack.Delete();
3316   }
# Line 2094 | Line 3351 | void produce_stretched_jzb_plots(string
3351    
3352  
3353   void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3354 +  switch_overunderflow(true);
3355    vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
3356    
3357    if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
# Line 2133 | Line 3391 | void diboson_plots(string mcjzb, string
3391      dout << "     Reset xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].samplename << " from " << Upxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ") and reset the correct name (from " << Upname << ")" << endl;
3392      
3393    }
3394 <  
3394 > //   switch_overunderflow(false);
3395   }
3396  
3397  
# Line 2160 | Line 3418 | void draw_normalized_data_vs_data_histo(
3418    leg->AddEntry(datahisto2,legentry2.c_str());
3419    leg->Draw();
3420    
3421 <  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3421 >  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3422    
3423    datahisto1->Delete();
3424    datahisto2->Delete();
# Line 2168 | Line 3426 | void draw_normalized_data_vs_data_histo(
3426  
3427  
3428   void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3429 +  switch_overunderflow(true);
3430    TCanvas *can = new TCanvas("can","JZB Plots Canvas");
3431    float max=jzbHigh ;
3432    float min=-120;
# Line 2204 | Line 3463 | void jzb_plots(string mcjzb, string data
3463      if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
3464    }
3465    delete can;
3466 +  switch_overunderflow(false);
3467   }
3468  
3469  
# Line 2652 | Line 3912 | void find_correction_factors(string &jzb
3912    
3913   }
3914  
3915 < void pick_up_events(string cut) {
3916 <  dout << "Picking up events with cut " << cut << endl;
2657 <  allsamples.PickUpEvents(cut);
3915 > void pick_up_events(string cut, string filename) {
3916 >  allsamples.PickUpEvents(cut,filename);
3917   }
3918  
3919   void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
# Line 2744 | Line 4003 | void ttbar_sidebands_comparison(string m
4003    //in the case of the on peak analysis, we compare the 3 control regions to the real value
4004    //in the case of the OFF peak analysis, we compare our control region to the real value
4005    TCut weightbackup=cutWeight;
4006 +  switch_overunderflow(true);
4007    
4008    bool doPURW=false;
4009    
# Line 2765 | Line 4025 | void ttbar_sidebands_comparison(string m
4025        
4026    float simulatedlumi = luminosity; //in pb please - adjust to your likings
4027  
4028 <  TH1F *TZem  = systsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4029 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4028 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4029 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4030    TH1F *TSem;
4031    TH1F *nTSem;
4032 <  TH1F *TZeemm  = systsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4033 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4032 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4033 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4034    TH1F *TSeemm;
4035    TH1F *nTSeemm;
4036    
4037    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4038 <    TSem    = systsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4039 <    nTSem   = systsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4040 <    TSeemm  = systsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4041 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4038 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4039 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4040 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4041 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4042    }
4043  
4044    TCanvas *tcan = new TCanvas("tcan","tcan");
# Line 2810 | Line 4070 | void ttbar_sidebands_comparison(string m
4070      histos.push_back(TSem);
4071      histos.push_back(TSeemm);
4072    }
4073 <  draw_all_ttbar_histos(tcan,histos,"histo",1);
4073 >  draw_all_ttbar_histos(tcan,histos,"histo",8);
4074    
4075    TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
4076    leg->AddEntry(TZeemm,"SFZP","l");
# Line 2822 | Line 4082 | void ttbar_sidebands_comparison(string m
4082    leg->Draw("same");
4083    DrawMCPrelim(simulatedlumi);
4084    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
4085 +  
4086    TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
4087    TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
4088    TH1F *TSeemmcopy;
# Line 2887 | Line 4148 | void ttbar_sidebands_comparison(string m
4148    DrawMCPrelim(simulatedlumi);
4149    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
4150    
4151 +  
4152    if (0) { // Turn this off: we don't need this
4153  
4154      ///-------------- second part: only look at the quantity we actually care about!
# Line 2992 | Line 4254 | void ttbar_sidebands_comparison(string m
4254  
4255    delete tcan;
4256    cutWeight=weightbackup;
4257 +  switch_overunderflow(false);
4258   }
4259  
4260   void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
# Line 3026 | Line 4289 | void ttbar_sidebands_comparison(string m
4289    nicer_binning.push_back(150);
4290    //nicer_binning.push_back(175);
4291    nicer_binning.push_back(200);
4292 <  nicer_binning.push_back(250);
4293 <  nicer_binning.push_back(300);
4294 <  nicer_binning.push_back(400);
4292 > //  nicer_binning.push_back(250);
4293 > //  nicer_binning.push_back(300);
4294 > //  nicer_binning.push_back(400);
4295    
4296    ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
4297   }
4298  
4299  
4300 < void zjets_prediction_comparison(string mcjzbWithPUa) {
4300 > void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4301 >  cout << "****************************************************************************************************************************************************************" << endl;
4302    TCanvas *zcan = new TCanvas("zcan","zcan");  
4303   //  zcan->SetLogy(1);
4304    TCut weightbackup=cutWeight;
4305    
4306 <  bool UsePURW=false;
4306 >  bool UsePURW=true;
4307    
4308    
4309    string mcjzb;
4310    if(UsePURW) {
4311      mcjzb=mcjzbWithPUa;
4312 +    cout << "Using PURW peak positions" << endl;
4313    } else {
4314      // Do it without PU re-weighting
4315 +    cutWeight="1.0";
4316      float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4317      stringstream resultsNoPU;
4318      stringstream noPUdatajzb;
# Line 3057 | Line 4323 | void zjets_prediction_comparison(string
4323      
4324      mcjzb = noPUmcjzb.str();
4325      
3060    cutWeight="1.0";
4326    }
4327  
4328    
# Line 3081 | Line 4346 | void zjets_prediction_comparison(string
4346    string var( "abs("+mcjzb+")" );
4347    
4348    TCut notTau("abs(genMID1)!=15");
4349 <  TCut ONLYTau("mll>20");
4349 >  TCut ee_mm_tautau("mll>0");
4350    
4351  
4352 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4353 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4352 >  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4353 >  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4354    
4355    hJZBpos->SetLineColor(kBlack);
4356    hJZBneg->SetLineColor(kRed);
# Line 3100 | Line 4365 | void zjets_prediction_comparison(string
4365    leg->AddEntry(hJZBneg,"Predicted","l");
4366    leg->Draw("same");
4367    DrawMCPrelim(simulatedlumi);
4368 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction");
4368 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction"+any2string(massregionname));
4369    
4370    TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
4371    hratio->Divide(hJZBneg);
# Line 3109 | Line 4374 | void zjets_prediction_comparison(string
4374      cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
4375    }
4376    
4377 <  zcan->SetLogy(0);
4378 <  hratio->GetYaxis()->SetRangeUser(0,2.0);
4377 > //  zcan->SetLogy(0);
4378 >  hratio->GetYaxis()->SetRangeUser(0,2.5);
4379    hratio->GetYaxis()->SetTitle("Observed/Predicted");
4380    hratio->Draw("e1");
4381    
# Line 3132 | Line 4397 | void zjets_prediction_comparison(string
4397    leg2->AddEntry(bottom,"syst. envelope","l");
4398    leg2->Draw("same");
4399    DrawMCPrelim(simulatedlumi);
4400 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio");
4400 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
4401    
4402    TCut reducedNJets(cutnJets);
4403    
4404 <  TH1F *TAUhJZBpos = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4405 <  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4406 <  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4407 <  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4404 >  TH1F *TAUhJZBpos       = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4405 >  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4406 >  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4407 >  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4408  
4409    TH1F *RcorrJZBSBem;
4410    TH1F *LcorrJZBSBem;
# Line 3147 | Line 4412 | void zjets_prediction_comparison(string
4412    TH1F *LcorrJZBSBeemm;
4413  
4414    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4415 <    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4416 <    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4417 <    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4418 <    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4415 >    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4416 >    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4417 >    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4418 >    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4419    }
4420    
4421    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
# Line 3181 | Line 4446 | void zjets_prediction_comparison(string
4446    TAUleg->AddEntry(Bpred,"Predicted","l");
4447    TAUleg->Draw("same");
4448    DrawMCPrelim(simulatedlumi);
4449 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction");
4449 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction__"+any2string(massregionname));
4450    
4451    TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
4452    TAUhratio->Divide(Bpred);
# Line 3199 | Line 4464 | void zjets_prediction_comparison(string
4464    center->Draw("same");
4465    bottom->Draw("same");
4466    
4467 <  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow #tau#tau",0.25,0.75,false);
4467 >  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4468    TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
4469    TAUleg2->AddEntry(bottom,"syst. envelope","l");
4470    TAUleg2->Draw("same");
4471    DrawMCPrelim(simulatedlumi);
4472 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio");
4472 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio"+any2string(massregionname));
4473    
4474    delete Bpred;
4475    delete TAUhJZBpos;
4476    delete LcorrJZBeemm;
4477    delete RcorrJZBem;
4478    delete LcorrJZBem;
4479 +  delete hJZBpos;
4480 +  delete hJZBneg;
4481    
4482    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4483      delete RcorrJZBSBem;
# Line 3222 | Line 4489 | void zjets_prediction_comparison(string
4489    
4490    delete zcan;
4491    cutWeight=weightbackup;
3225
4492   }
4493  
4494  
4495 <
4495 > void zjets_prediction_comparison(string mcjzbWithPUa) {
4496 >  zjets_prediction_comparison(mcjzbWithPUa, TCut(""), "nomasscut");
4497 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<20"), "Zwindow_20");
4498 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
4499 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
4500 > }
4501 >  
4502   void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
4503    tout << endl << endl;
4504    stringstream bordercut;
# Line 3334 | Line 4606 | void make_table(samplecollection &coll,
4606   }
4607  
4608   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
4609 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
4610 +  assert(0);
4611    /*we want a table like this:
4612      __________________     50   |   100  | ...
4613      | Data prediction |  a vs b | a vs b | ...
# Line 3567 | Line 4841 | void qcd_plots(string datajzb, string mc
4841    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
4842    string ytitle("ratio");
4843    if ( use_data==1 ) ytitle = "data/pred";
4844 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
4844 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
4845 >  delete kinpad;
4846    
4847    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
4848    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 3804 | Line 5079 | void met_vs_jzb_plots(string datajzb, st
5079    lg->SetHeader("DY");
5080    
5081    lg->Draw();
5082 <  save_with_ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5082 >  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5083    
5084    TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5085    metpad3->cd();
# Line 3822 | Line 5097 | void met_vs_jzb_plots(string datajzb, st
5097  
5098    lg2->Draw();
5099    
5100 <  save_with_ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5100 >  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5101    
5102    TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5103    metpad2->cd();
# Line 3841 | Line 5116 | void met_vs_jzb_plots(string datajzb, st
5116    metlefta->Draw("histo");
5117    metrighta->Draw("same");
5118    lg->Draw();
5119 <  save_with_ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5119 >  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5120    
5121    delete Bpred;
5122    delete obs;
# Line 3868 | Line 5143 | void met_vs_jzb_plots(string datajzb, st
5143    aobs->Draw("same");
5144    lg->SetHeader("All MC");
5145    lg->Draw();
5146 <  save_with_ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5146 >  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5147    
5148    
5149    delete lg;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines