Exemple #1
0
void DrawEmpirical(const char* filename="Empirical.root", 
		   Bool_t fmd=true)
{
  gStyle->SetOptTitle(0);

  TFile* file = TFile::Open(filename, "READ");
  if (!file) return;

  Double_t yr = 0.3;
  TCanvas* c  = new TCanvas("c","c", 1000,1000);
  TPad*    p1 = new TPad("p1","p1",0,0,1,yr);
  TPad*    p2 = new TPad("p2","p2",0,yr,1,1);
  c->cd(); p1->Draw();
  c->cd(); p2->Draw();
  
  gDirectory->cd("Forward");
  THStack* r = DrawOne(p1, yr, false, gDirectory, "ratios");  
  THStack* e = DrawOne(p2, yr, true, gDirectory, "empirical");

  r->SetMinimum(0.945);
  r->SetMaximum(1.055);
  r->GetXaxis()->SetTitle("#it{#eta}");
  r->GetYaxis()->SetTitle("Ratio to mean");
  e->SetMinimum(0.005);
  e->GetYaxis()->SetTitle("#it{E_{c}}(#it{#eta})");
  TIter nextE(e->GetHists());
  TIter nextR(r->GetHists());
  TH1*  hist = 0;
  Color_t cols[]  = { kRed+2, kGreen+2, kBlue+2, kMagenta+2, 0 };
  Color_t *ptr    = cols;
  Style_t stys[]  = { 20, 21, 22, 23 };
  Style_t* sty    = stys;
  while (*ptr) { 
    hist = static_cast<TH1*>(nextE()); 
    hist->SetMarkerColor(*ptr);
    hist->SetMarkerSize(2);
    hist->SetMarkerStyle(*sty);
    hist = static_cast<TH1*>(nextR()); 
    hist->SetMarkerColor(*ptr);
    hist->SetMarkerSize(2);
    hist->SetMarkerStyle(*sty);
    ptr++;
    sty++;
  }


  TLegend* l = p2->BuildLegend(0.35, .2, .65, .8);
  l->SetFillColor(0);
  l->SetFillStyle(0);
  l->SetBorderSize(0);

  c->Modified();
  c->Update();
  c->cd();
  c->Print("empirical.png");
  
}
Exemple #2
0
  //____________________________________________________________________
  void Run(const char* newName,        const char* oldName,
	   const char* newTitle="New", const char* oldTitle="Old")
  {
    TFile* newFile = TFile::Open(newName,"READ");
    TFile* oldFile = TFile::Open(oldName,"READ");
    if (!newFile || !oldFile) return;

    TH1* newCent = GetH1(newFile, "realCent");
    TH1* oldCent = GetH1(oldFile, "realCent");
    if (!newCent || !oldCent) return;

    TString  t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle);
    TCanvas* c     = new TCanvas("c", t, 1200, 800);
    c->SetTopMargin(0.01);
    c->SetRightMargin(0.20);
    fLegend = new TLegend(1-c->GetRightMargin(),
			  c->GetBottomMargin(),
			  1, 1-c->GetTopMargin(),
			  t);
    fLegend->SetFillStyle(0);
    fLegend->SetBorderSize(0);
    THStack* stack = new THStack("ratios","");
			       
    fMin = +1e6;
    fMax = -1e6;
    TH1* one = 0;
    for (Int_t i = newCent->GetNbinsX(); i--;) {
      Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
      Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
      Info("", "c1=%f c2=%f", c1, c2);
      TH1*     r  = One(newFile, oldFile, c1, c2);    
      if (!r) continue;
      if (!one) {
	one = static_cast<TH1*>(r->Clone("one"));
	one->SetDirectory(0);
	one->Reset();
	for (Int_t j = 1; j <= one->GetNbinsX(); j++) {
	  one->SetBinContent(j,1);
	  one->SetBinError  (j,0);
	}
      }
      // r->Add(one, i-1);
      // r->Scale(TMath::Power(10,i));
      stack->Add(r);
    }
    stack->Draw("nostack");
    stack->SetMinimum(0.95*fMin);
    stack->SetMaximum(1.05*fMax);
    stack->GetHistogram()->SetXTitle("#eta");
    stack->GetHistogram()->SetYTitle("#it{R}");
    fLegend->Draw();
    c->Modified();
    c->Update();
    c->cd();
    c->SaveAs(Form("%sover%s.png", newTitle, oldTitle));
  }  
Exemple #3
0
void StackPlots( TFile* f1, vector<string> hist, vector<string> leg, vector<Color_t> color, string xtitle_, string ytitle_, string xunit, string savePath, bool ylog=0, int rebin=1){
	int Bins = 0;
	int x1 = 0;
	int x2 = 0;
	int size = hist.size();
	float binwidth = 0;
	char title[100], xtitle[100], ytitle[100];
	TH1F* h1[size];
	for(int i=0; i<size; i++){
		h1[i] = (TH1F*)f1->Get(hist[i].c_str());
		h1[i]->UseCurrentStyle();
		h1[i]->Rebin(rebin); 
		if( Bins != 0 ){ if( h1[i]->GetXaxis()->GetLast() != Bins ) { cout<<"Error: Exist different bin size( plot: "<<i<<")"<<endl; }}
		Bins = h1[i]->GetXaxis()->GetLast();
		binwidth = h1[i]->GetBinWidth(1);
		x1 = h1[i]->GetXaxis()->GetBinLowEdge(1);
		x2 = h1[i]->GetXaxis()->GetBinUpEdge(Bins);

		h1[i]->SetLineWidth(1);
		h1[i]->SetLineColor(color[i]);
		h1[i]->SetFillColor(color[i]);
	}

	sprintf(xtitle,"%s [%s]",xtitle_.c_str(),xunit.c_str());
	sprintf(ytitle,"%s / [%3.0f%s]",ytitle_.c_str(),binwidth,xunit.c_str());
	sprintf(title,";%s;%s",xtitle,ytitle);
	cout<<Bins<<" "<<x1<<" "<<x2<<endl;
	TH1F* hs_stack = new TH1F("hs_stack",title,Bins,x1,x2);
        THStack *hs = new THStack("hs","");

	TLegend* leg_ = new TLegend(0.65,0.65,0.85,0.85);
	TCanvas* c1 = new TCanvas("c1", "", 850, 700);
        c1->SetGridx();
        c1->SetGridy();
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);
	hs_stack->UseCurrentStyle();
	hs->SetHistogram(hs_stack);	
	for(int i=0; i<size; i++){
		hs->Add(h1[i]);
		leg_->AddEntry(h1[i],leg[i].c_str(),"f");
	}
        leg_->SetFillStyle(0);
        leg_->SetBorderSize(0);
        leg_->SetTextSize(0.042);
	if( ylog ) gPad->SetLogy();
	hs->SetMinimum(1);
	hs->SetMaximum(1e+13);
	hs->Draw();
	leg_->Draw();
	c1->SaveAs(savePath.c_str());
}
Exemple #4
0
THStack *getstack(TTree *nt, TString name, TString var, vector<TString> cuts,int bins = 100, float xmin = 0, float xmax = 200)
{
  THStack *hs = new THStack(name,name);
  int N = cuts.size();
  vector<TH1F *> vh(N);
  for (int i=0;i<N;i++) {
    vh[i] = geth(Form("%s%d",name.Data(),i),bins,xmin,xmax);

    vh[i]->SetFillColor(TColor::GetColorDark(i+2));
    vh[i]->SetFillStyle(1001);
    nt->Project(vh[i]->GetName(),var.Data(),Form("weight*(%s)",cuts[i].Data()),"");//,1000);
    hs->Add(vh[i],"hist");
    cout<<vh[i]->Integral()<<endl;
  }
  hs->SetMinimum(1E-2);

  return hs;
}
Exemple #5
0
void browseStacks( bool makePictures=false, bool wait=true , bool addHistName = false, Double_t maxYScaleF = 1., 
                  bool logScale = false, bool setMinZero = true) {


  gStyle->SetOptTitle(0);

  bool keep2D=false;

  //fix the hNJet histos
  TList *list = gDirectory->GetList();
  TIterator *iter = list->MakeIterator();
  TObject *obj = 0;
  while(obj = iter->Next()) {
  
    if(TString(obj->GetName()).Contains("hnJet") && obj->InheritsFrom(TH1::Class())) {
      
      int nbins = ((TH1F*)obj)->GetNbinsX();
      float overflow = ((TH1F*)obj)->GetBinContent(nbins+1);
      float lastbinval = ((TH1F*)obj)->GetBinContent(nbins);
      ((TH1F*)obj)->SetBinContent(nbins, overflow+lastbinval);
      ((TH1F*)obj)->GetXaxis()->SetBinLabel(nbins, "#geq4");
    }
  }
  
    
    
    
  // Find out what the names of the existing histograms are
  // The histogram names are XX_YY_ZZ, where XX is the sample,
  // eg, "tt", YY is the actual name, ZZ is the final state, eg, "ee"
  TObjArray* myNames = getMyHistosNames("ttdil","ee",keep2D);
    

  // Now loop over histograms, and make stacks
  TCanvas *c = new TCanvas();
  c->Divide(2,2);
  char* suffix[4];
  suffix[0] = "ee";
  suffix[1] = "mm";
  suffix[2] = "em";
  suffix[3] = "all";
  if (makePictures) c->Print("out/stacks.ps[");
  for (int i=0; i<myNames->GetEntries(); i++) {
     
    for (int sample=0; sample<4; sample++) {
       
       
      hist::stack(Form("st_%s_%s",myNames->At(i)->GetName(),suffix[sample]),
		  Form("%s_%s$",myNames->At(i)->GetName(), suffix[sample]));
      THStack* thisStack = (THStack*) gROOT->FindObjectAny(
							   Form("st_%s_%s", myNames->At(i)->GetName(), suffix[sample]));
       
      thisStack->SetMaximum(thisStack->GetMaximum()*maxYScaleF);
      if(TString(myNames->At(i)->GetName()).Contains("hnJet")) {
	TList* histolist = thisStack->GetHists();
	int hatchcount = 0;
	// 	for(int j = 0; j<histolist->GetSize();j++) {
	// 	  if(TString(histolist->At(j)->GetName()).Contains("tt") ||
	// 	     TString(histolist->At(j)->GetName()).Contains("tautau") ||
	// 	     TString(histolist->At(j)->GetName()).Contains("ww") ) continue;
	// 	  hatch(histolist->At(j)->GetName(), FavoriteHatches[hatchcount]);
	// 	  hatchcount++;
	// 	}
      }
	 
	 
      TLegend* thisLeg = hist::legend(thisStack, "lpf", 0, 0, 0.75, 0.65, 0.99, 0.99);
      c->cd(sample+1);
      if (logScale) gPad->SetLogy(); else gPad->SetLogy(0);
      double stackMax = ((TH1*)thisStack->GetHists()->At(0))->GetMaximum();
      double stackMin = ((TH1*)thisStack->GetHists()->At(0))->GetMinimum();
      thisStack->SetMinimum(stackMin);
      if (setMinZero) thisStack->SetMinimum(0);
      if (logScale && stackMin <=0) thisStack->SetMinimum(1e-2*stackMax);
      if (logScale && stackMax == 0) thisStack->SetMinimum(1e-12); 
      thisStack->Draw("hist");
      string xtitle( ((TH1*)gROOT->FindObjectAny(Form("ttdil_%s_%s", myNames->At(i)->GetName(), suffix[sample])))->GetXaxis()->GetTitle());
      string ytitle( ((TH1*)gROOT->FindObjectAny(Form("ttdil_%s_%s", myNames->At(i)->GetName(), suffix[sample])))->GetYaxis()->GetTitle());
      thisStack->GetXaxis()->SetTitle(xtitle.c_str());
      thisStack->GetYaxis()->SetTitle(ytitle.c_str());
      TString hname = thisStack->GetName();
      if(hname.Contains("hnJet")) {
	thisStack->GetXaxis()->SetLabelSize(0.075);
	thisStack->GetYaxis()->SetLabelSize(0.05);
	thisStack->GetXaxis()->SetTitle("N_{jets}");
      }
      thisLeg->Draw();
	
      TPaveText *pt1 = new TPaveText(0.1, 0.95, 0.4, 0.999, "brNDC");
      pt1->SetName("pt1name");
      pt1->SetBorderSize(0);
      pt1->SetFillStyle(0);
	
      TText *blah;
      if (addHistName) blah = pt1->AddText(hname);
      else blah = pt1->AddText("CMS Preliminary");
      blah->SetTextSize(0.05);
      pt1->Draw();
      c->Modified();
	
      c->Update();
    }
    if (makePictures) {
      c->Print("out/stacks.ps");
      //       c->Print(Form("out/stacks_%d.png",i+1));
      //c->Print(Form("out/stacks_%s.png",myNames->At(i)->GetName()));
      c->Print(Form("out/stacks_%s.eps",myNames->At(i)->GetName()));
    }
    if (wait) {
      cout << "Enter carriage return for the next set of plots....q to quit" << endl;
      char in = getchar();
      if (in == 'q') break;
    }
  }
  if (makePictures) c->Print("out/stacks.ps]");
}
void SamMacroMod(){
  TCanvas *c1 = new TCanvas("c1", "c1",1000,700);
  TPad* spectrumPad=0;
  TPad* ratioPad=0;
  //c1->Divide(1,2);
  //gStyle->SetOptStat(111111);
  gStyle->SetOptFit(kFALSE);
  gStyle->SetOptStat(kFALSE);
  gStyle->SetStatX(0.457589);
  gStyle->SetStatY(0.312937);
  gStyle->SetStatW(0.29241/2+0.0185);
  gStyle->SetStatH(0.169580+0.05);
  gStyle->SetStatFontSize(0.0402098);
  gStyle->SetStatFont(0.02);
  gStyle->SetFitFormat("5.2g");
  gStyle->SetStatBorderSize(0);
  gStyle->SetStatFontSize(0.040209);
  gStyle->SetStatFontSize(0.035209);
  c1->Range(1.592761,-5.173913,3.533814,6.006211);
  c1->SetFillColor(0);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->SetLogx(1);
  c1->SetLogy(1);
  c1->SetTickx(1);
  c1->SetTicky(1);
  c1->SetLeftMargin(0.13);
  c1->SetRightMargin(0.07);
  c1->SetFrameBorderMode(0);
  c1->SetFrameBorderMode(0);
  c1->SetTopMargin(0.085);
  c1->SetBottomMargin(0.11);
  // Upper plot will be in pad1
  TPad *pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0);
  pad1->SetBottomMargin(0.002); // Upper and lower plot are joined
  pad1->SetTickx(1);
  pad1->SetTicky(1);
  pad1->SetLogx(1);
  pad1->SetLogy(1);
  pad1->SetGridx(0);
  pad1->SetGridy(0);
  pad1->Draw();             // Draw the upper pad: pad1
  pad1->cd();               // pad1 becomes the current pad
  //========================================================== 
  //                                                              
  //               Get the histograms                                  
  //==========================================================
  TFile *file1 = new TFile("plots/h_ZprimeRecomass_DY_OF.root","READ");
  TH1* zeeHist = (TH1*) file1->Get("ZprimeRecomassBinWidthwtOverFlow");

  TFile *file2 = new TFile("plots/h_ZprimeRecomass_Tlike_OF.root","READ");
  TH1* ttbarHist = (TH1*) file2->Get("ZprimeRecomassBinWidthwtOverFlow");

  TFile *file3 = new TFile("plots/h_ZprimeRecomass_DiBoson_OF.root","READ");
  TH1* dibosonsBkgHist = (TH1*) file3->Get("ZprimeRecomassBinWidthwtOverFlow");

  TFile *file4 = new TFile("plots/h_ZprimeRecomass_data_OF.root","READ");
  TH1* dataHistTempbar = (TH1*) file4->Get("ZprimeRecomassBinWidthwtOverFlow");

  //TFile *file3 = new TFile("Wjets-25nsMC-OS-allbins-2673pb.root","READ");
  TFile *file5 = new TFile("plots/FR-Wjets-25nsMC-OS-BinWidth-2673pb_OF.root","READ");
  TH1* WjetsBkgHist = (TH1*) file5->Get("WjetsHistowtOverFlow");
  std::cout<<"nb.Wjets(MC)  = "<<WjetsBkgHist->Integral()<<endl;

  //TFile *file4 = new TFile("DiJets-Data-OS-2673pb-FR.root","READ");
  TFile *file6 = new TFile("plots/FR-DiJets-Data-OS-BinWidth-2673pb_OF.root","READ");
  TH1* jetBkgHist   = (TH1*) file6->Get("DataSubwtOverFlow");
  std::cout<<"nbQCD(dijets,Data)  = "<<jetBkgHist->Integral()<<endl;

  /*
  zeeHist->Rebin(20);
  ttbarHist->Rebin(20);
  dibosonsBkgHist->Rebin(20);
  dataHistTempbar->Rebin(20);
  WjetsBkgHist->Rebin(20);
  jetBkgHist->Rebin(20);
  */

  float binWidthNorm=-1;
  int zeeColour    =  TColor::GetColor("#99ccff");
  int jetBkgColour = TColor::GetColor("#ffff66"); 
  int ttbarColour  = TColor::GetColor("#ff6666");
  int bosonColour  = TColor::GetColorDark(3);
  int WjetsColour  = TColor::GetColorDark(5);
  int font = 42;
  //float xAxisMin = 60; //72
  //float xAxisMax = 1000.0;
  //float yAxisMin = 1e-4;
  //float yAxisMax = 1e3; 
  
  TGraphAsymmErrors* dataHist = makeDataGraph(dataHistTempbar,binWidthNorm,0);
  normHistToBinWidth(zeeHist,binWidthNorm);
  normHistToBinWidth(ttbarHist,binWidthNorm);
  normHistToBinWidth(dibosonsBkgHist,binWidthNorm);
  normHistToBinWidth(jetBkgHist,binWidthNorm);
  normHistToBinWidth(WjetsBkgHist,binWidthNorm);
  
  

  //gStyle->SetOptStat(111111);
  //PaintOverflow(zeeHist);
  //PaintOverflow(ttbarHist);
  //PaintOverflow(dibosonsBkgHist);
  //PaintOverflow(dataHistTempbar);
  //PaintOverflow(jetBkgHist);
  //PaintOverflow(WjetsBkgHist);
  

  THStack *axisHist = new THStack("axisHist","");

  zeeHist->SetFillColor(zeeColour);
  zeeHist->SetLineWidth(2);
  zeeHist->SetLineColor(1);
  zeeHist->SetTitle("");
  
  
  ttbarHist->SetFillColor(ttbarColour);
  ttbarHist->SetLineWidth(2); 
  ttbarHist->SetLineColor(1);
  
  dibosonsBkgHist->SetFillColor(bosonColour);
  dibosonsBkgHist->SetLineWidth(2); 
  dibosonsBkgHist->SetLineColor(1);
  
  WjetsBkgHist->SetFillColor(WjetsColour);
  //WjetsBkgHist->SetFillColor(jetBkgColour);
  WjetsBkgHist->SetLineWidth(2);
  WjetsBkgHist->SetLineColor(1);

  jetBkgHist->SetFillColor(jetBkgColour);
  jetBkgHist->SetLineWidth(2);
  jetBkgHist->SetLineColor(1);

  
  axisHist->Add(jetBkgHist,"histo");
  axisHist->Add(WjetsBkgHist,"histo");
  axisHist->Add(ttbarHist);
  axisHist->Add(dibosonsBkgHist);
  axisHist->Add(zeeHist);
  axisHist->Draw("histo");
  

  //axisHist->GetXaxis()->SetTitle("M(#mu^{+}#mu^{-}) [GeV]");
  //axisHist->GetYaxis()->SetTitle("Events / 20 GeV");
  axisHist->GetYaxis()->SetTitle("Events/GeV");
  //axisHist->GetXaxis()->SetTitleOffset(1.1);
  //axisHist->GetYaxis()->SetTitleOffset(1.1);
  axisHist->GetXaxis()->SetTitleSize(0.047);
  axisHist->GetYaxis()->SetTitleSize(0.047);
  //axisHist->GetXaxis()->SetLabelSize(0.040);
  axisHist->GetYaxis()->SetLabelSize(0.040);
  //axisHist->GetXaxis()->SetMoreLogLabels();
  //axisHist->GetXaxis()->SetNoExponent();
  axisHist->GetXaxis()->SetRangeUser(60.0,3000.0);
  axisHist->SetMinimum(0.01);
  axisHist->SetMaximum(20000.0);
  //axisHist->SetMaximum(2000.0);
  dataHist->SetMarkerStyle(20);
  dataHist->SetMarkerSize(0.9);
  dataHist->GetXaxis()->SetRange(5,83);
  dataHist->GetXaxis()->SetTitleSize(0.047);
  dataHist->GetXaxis()->SetTitleOffset(0.9);
  dataHist->GetYaxis()->SetTitleSize(0.047);
  dataHist->GetYaxis()->SetTitleOffset(1.2);
  dataHist->Draw("PZ");
  

  //==========================================================
  TLegend *leg = new TLegend(0.56741,0.48671,0.820536,0.83664,NULL,"brNDC"); //for lumi in plot
  leg->AddEntry(dataHist,"Data","PE");
  leg->AddEntry(zeeHist,"#gamma^{*}/Z#rightarrow#mu^{+}#mu^{-}","F");
  leg->AddEntry(ttbarHist,"t#bar{t}, Single Top","F");
  //leg->AddEntry(dibosonsBkgHist,"WW, WZ, ZZ","F");
  leg->AddEntry(dibosonsBkgHist,"Diboson, #tau#tau","F");
  leg->AddEntry(WjetsBkgHist,"W+jets (FR)","F");
  leg->AddEntry(jetBkgHist,"Di-Jets (data)","F");
  //leg->AddEntry(jetBkgHist,"Jets (FR)","F");
  leg->SetBorderSize(0);
  //leg->SetTextFont(62);
  leg->SetLineColor(1);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(19);
  leg->SetFillStyle(0);
  leg->SetTextFont(font);
  leg->SetTextSize(0.04);
  leg->Draw();
  //==========================================================
  TPaveText* tText1 = new TPaveText(0.75, 0.92, 0.87, 0.98, "brNDC");
  tText1->SetBorderSize(0);
  tText1->SetFillColor(0);
  tText1->SetFillStyle(0);
  TText *t1 = tText1->AddText("2.673 fb^{-1} (13 TeV)");
  tText1->SetTextSize(0.04);
  tText1->Draw(); 
  //==========================================================
  TPaveText* tText2 = new TPaveText(0.85, 0.86, 0.88, 0.87, "brNDC");
  tText2->SetBorderSize(0);
  tText2->SetFillColor(0);
  tText2->SetFillStyle(0);
  TText *t2 = tText2->AddText("CMS");
  t2 = tText2->AddText("CMS");
  tText2->SetTextSize(0.04);
  tText2->Draw(); 
  //==========================================================
  TPaveText* tText3 = new TPaveText(0.80, 0.81, 0.85, 0.83, "brNDC");
  tText3->SetBorderSize(0);
  tText3->SetFillColor(0);
  tText3->SetFillStyle(0);
  TText *t3 = tText3->AddText("#it{Preliminary}");
  tText3->SetTextSize(0.04);
  tText3->Draw(); 

  //---------------------------------------------------------------------
  //---------------------------------------------------------------------
  c1->cd();          // Go back to the main canvas before defining pad2
  TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.3);
  pad2->SetTopMargin(0.05);
  pad2->SetBottomMargin(0.3);
  pad2->SetTickx(1);
  pad2->SetTicky(1);
  pad2->SetLogx(1);
  pad2->SetLogy(1);
  pad2->SetGridx(1);
  pad2->SetGridy(1);
  pad2->Draw();
  pad2->cd();       // pad2 becomes the current pad
  //========================================================== 
  //                                                              
  //               Get the histograms                                  
  //==========================================================
  
  TFile *file1000 = new TFile("plots/h_ZprimeRecomass_Total_OF.root","READ");   
  TH1F* totalMC = (TH1*) file1000->Get("ZprimeRecomassBinWidthwtOverFlow");
  TH1F* totaldijet= (TH1*) file1000->Get("DataSubwtOverFlow");
  TH1F* totalwjet= (TH1*) file1000->Get("WjetsHistowtOverFlow");

  /*
  TH1F *total;
  total->Add(totalMC);
  total->Add(totaldijet);
  total->Add(totalwjet);
  */

  TFile *file2000 = new TFile("plots/h_ZprimeRecomass_data_OF.root","READ");
  TH1* dataHistTempbar  = (TH1*) file2000->Get("ZprimeRecomassBinWidthwtOverFlow");

  //dataHistTempbar->Divide(total);
  //dataHistTempbar->Draw();
 
  //TFile *file = new TFile("Data-DY-Dibosons-TTbarandTTbarLike-Wjets-Dijets-MC-OS-2673pb.root","READ");
  //TH1* dataHistTempbar = (TH1*) file1->Get("htotalHistoRatiowtOverFlow");
  
  float binWidthNorm=-1;
  int singletopColour    =  TColor::GetColor("#99ccff");
  int jetBkgColour = TColor::GetColor("#ffff66"); 
  int ttbarColour  = TColor::GetColor("#ff6666");
  int bosonColour  = TColor::GetColorDark(3);
  int wjetsColour  = TColor::GetColorDark(5);
  int DYtautauColour  = TColor::GetColorDark(4);
  int font = 42;
  //TGraphAsymmErrors* dataHist = makeDataGraph(dataHistTempbar,binWidthNorm,0);
  //normHistToBinWidth(singletopHist,binWidthNorm);
  dataHistTempbar->SetMarkerStyle(20);
  dataHistTempbar->SetMarkerColor(1);
  dataHistTempbar->SetMarkerSize(0.9);
  //dataHistTempbar->GetXaxis()->SetRange(5,83);

  dataHistTempbar->GetXaxis()->SetTitleOffset(1.1);
  dataHistTempbar->GetYaxis()->SetTitleOffset(0.4);
 
  dataHistTempbar->GetXaxis()->SetTitleSize(0.14);
  dataHistTempbar->GetYaxis()->SetTitleSize(0.12);
  
  dataHistTempbar->GetXaxis()->SetLabelSize(0.12);
  dataHistTempbar->GetYaxis()->SetLabelSize(0.08);  

  dataHistTempbar->GetXaxis()->SetTitle("M(#mu^{+}#mu^{-}) [GeV]");
  //dataHistTempbar->GetXaxis()->SetTitle("M(e#mu) [GeV]");
  dataHistTempbar->GetYaxis()->SetTitle("Data / MC");
  dataHistTempbar->GetXaxis()->SetMoreLogLabels();
  dataHistTempbar->GetXaxis()->SetNoExponent();
  dataHistTempbar->GetXaxis()->SetRangeUser(60.0,2500.0);
  dataHistTempbar->GetYaxis()->SetRangeUser(-1.0,3.0);
  dataHistTempbar->SetMarkerStyle(20);
  dataHistTempbar->SetMarkerSize(0.9);
  dataHistTempbar->Draw("");

  
  TF1* fn1 = new TF1("fn1","pol0",60,1300);
  fn1->SetLineColor(2);
  dataHistTempbar->Fit("fn1","R,smaes");
  //==========================================================
  TPaveText* tText10 = new TPaveText(0.70, 0.40, 0.88, 0.90, "brNDC");
  tText10->SetBorderSize(0);
  tText10->SetFillColor(0);
  tText10->SetFillStyle(0);
  TText *t1 = tText10->AddText("#chi^{2} / n.d.f = 53.91/54");
  TText *t2 = tText10->AddText("Prob = 0.478");
  TText *t3 = tText10->AddText("p0 = 1.009 #pm 0.005");
  tText10->SetTextSize(0.10);
  tText10->Draw(); 

  
  //=================================================================================== 
  c1->Print("Stack-DY-Spring15MCs-Data2015-mass-spectrum-MuMu-OS-2673pb.png","png");
  //c1->Print("Stack-DY-Spring15MCs-Data2015-mass-spectrum-MuMu-OS-2673pb.pdf","pdf");
  //=========================================================================
  //=========================================================================
  //=========================================================================
  //=========================================================================
  //=========================================================================
  //=========================================================================
  TCanvas *c2 = new TCanvas("c2", "c2",1000,600);
  TPad* spectrumPad=0;
  TPad* ratioPad=0;
  gStyle->SetOptFit(1111);
  gStyle->SetOptStat(0);
  gStyle->SetStatX(0.457589);
  gStyle->SetStatY(0.312937);
  gStyle->SetStatW(0.29241/2+0.0185);
  gStyle->SetStatH(0.169580+0.05);
  gStyle->SetStatFontSize(0.0402098);
  gStyle->SetStatFont(0.03);
  gStyle->SetFitFormat("5.2g");
  gStyle->SetStatBorderSize(0);
  gStyle->SetStatFontSize(0.040209);
  gStyle->SetStatFontSize(0.035209);
  c2->Range(1.592761,-5.173913,3.533814,6.006211);
  c2->SetFillColor(0);
  c2->SetBorderMode(0);
  c2->SetBorderSize(2);
  c2->SetLogx(1);
  c2->SetLogy(1);
  c2->SetTickx(1);
  c2->SetTicky(1);
  c2->SetLeftMargin(0.13);
  c2->SetRightMargin(0.07);
  c2->SetFrameBorderMode(0);
  c2->SetFrameBorderMode(0);
  c2->SetTopMargin(0.085);
  c2->SetBottomMargin(0.11);

  TFile *file1 = new TFile("plots/htotal_root_ZprimeRecomass_OF.root","READ");
  TH1* zeeHist = (TH1*) file1->Get("hfourlepbestmass_4l_afterSel_new_DYwtOverFlow");
 
  //TFile *file2 = new TFile("Data-Dibosons-TTbarandTTbarLike-MC-OS-2673pb.root","READ");
  TH1* ttbarHist = (TH1*) file1->Get("hfourlepbestmass_4l_afterSel_new_TlikewtOverFlow");
  TH1* dibosonsBkgHist = (TH1*) file1->Get("hfourlepbestmass_4l_afterSel_new_diBosonwtOverFlow");
  TH1* dataHistTempbar = (TH1*) file1->Get("htotaldatawtOverFlow");

  //TFile *file3 = new TFile("Wjets-25nsMC-OS-allbins-2673pb.root","READ");
  TH1* WjetsBkgHist = (TH1*) file1->Get("hfourlepbestmass_4l_afterSel_WJetsFromFakeRateFromMCwtOverFlow");
  std::cout<<"nb.Wjets(MC)  = "<<WjetsBkgHist->Integral()<<endl;

  //TFile *file4 = new TFile("DiJets-Data-OS-2673pb-FR.root","READ");
  TH1* jetBkgHist   = (TH1*) file1->Get("hfourlepbestmass_4l_afterSel_DiJetsFromFakeRateFromDatawtOverFlow");
  std::cout<<"nbQCD(dijets,Data)  = "<<jetBkgHist->Integral()<<endl;

  /*
  zeeHist->Rebin(20);
  ttbarHist->Rebin(20);
  dibosonsBkgHist->Rebin(20);
  dataHistTempbar->Rebin(20);
  WjetsBkgHist->Rebin(20);
  jetBkgHist->Rebin(20);
  */

  float binWidthNorm2=-1;
  int zeeColour    =  TColor::GetColor("#99ccff");
  int jetBkgColour = TColor::GetColor("#ffff66"); 
  int ttbarColour  = TColor::GetColor("#ff6666");
  int bosonColour  = TColor::GetColorDark(3);
  int WjetsColour  = TColor::GetColorDark(5);
  int font = 42;
  float xAxisMin = 60; //72
  float xAxisMax = 3000.0;
  float yAxisMin = 1e-4;
  float yAxisMax = 1e4; 

  

  dataHistTempbar = makeIntHist(dataHistTempbar);
  zeeHist         = makeIntHist(zeeHist);
  ttbarHist       = makeIntHist(ttbarHist);
  dibosonsBkgHist = makeIntHist(dibosonsBkgHist);
  jetBkgHist      = makeIntHist(jetBkgHist);
  WjetsBkgHist    = makeIntHist(WjetsBkgHist);
  TGraphAsymmErrors* dataHist = makeDataGraph(dataHistTempbar,binWidthNorm2,0);
  THStack *axisHist2 = new THStack("axisHist2","");
  zeeHist->SetFillColor(zeeColour);
  zeeHist->SetLineWidth(2);
  zeeHist->SetLineColor(1);
  zeeHist->SetTitle("");
    
  ttbarHist->SetFillColor(ttbarColour);
  ttbarHist->SetLineWidth(2); 
  ttbarHist->SetLineColor(1);
    
  dibosonsBkgHist->SetFillColor(bosonColour);
  dibosonsBkgHist->SetLineWidth(2); 
  dibosonsBkgHist->SetLineColor(1);
   
  jetBkgHist->SetFillColor(jetBkgColour);
  jetBkgHist->SetLineWidth(2);
  jetBkgHist->SetLineColor(1);

  WjetsBkgHist->SetFillColor(WjetsColour);
  WjetsBkgHist->SetLineWidth(2);
  WjetsBkgHist->SetLineColor(1);
  
  
  axisHist2->Add(jetBkgHist,"histo");
  axisHist2->Add(WjetsBkgHist,"histo");
  axisHist2->Add(dibosonsBkgHist,"histo");
  axisHist2->Add(ttbarHist,"histo");
  axisHist2->Add(zeeHist,"histo");
  axisHist2->Draw();
  axisHist2->GetXaxis()->SetTitle("M(#mu^{+}#mu^{-}) [GeV]");
  axisHist2->GetYaxis()->SetTitle("Events #geq M(#mu^{+}#mu^{-}) [GeV]");
  axisHist2->GetXaxis()->SetTitleOffset(1.1);
  axisHist2->GetYaxis()->SetTitleOffset(1.1);
  axisHist2->GetXaxis()->SetTitleSize(0.047);
  axisHist2->GetYaxis()->SetTitleSize(0.047);
  axisHist2->GetXaxis()->SetLabelSize(0.040);
  axisHist2->GetYaxis()->SetLabelSize(0.040);
  axisHist2->GetXaxis()->SetMoreLogLabels();
  axisHist2->GetXaxis()->SetNoExponent();
  axisHist2->GetXaxis()->SetRangeUser(60.0,2500.0);
  axisHist2->SetMinimum(0.01);
  axisHist2->SetMaximum(60000.0);
  
  dataHist->SetMarkerStyle(20);
  dataHist->SetMarkerSize(0.9);
  dataHist->Draw("PZsames");
  //==========================================================
  TLegend *leg = new TLegend(0.56741,0.58671,0.820536,0.83664,NULL,"brNDC");
  leg->AddEntry(dataHist,"Data","PE");
  leg->AddEntry(zeeHist,"#gamma^{*}/Z#rightarrow#mu^{+}#mu^{-}","F");
  leg->AddEntry(ttbarHist,"t#bar{t}, Single Top","F");
  //leg->AddEntry(dibosonsBkgHist,"WW, WZ, ZZ","F");
  leg->AddEntry(dibosonsBkgHist,"Diboson, #tau#tau","F");
  leg->AddEntry(WjetsBkgHist,"W+jets (FR)","F");
  leg->AddEntry(jetBkgHist,"Di-Jets (data)","F");
  //leg->AddEntry(jetBkgHist,"Jets (FR)","F");
  leg->SetBorderSize(0);
  //leg->SetTextFont(62);
  leg->SetLineColor(1);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(19);
  leg->SetFillStyle(0);
  leg->SetTextFont(font);
  leg->SetTextSize(0.04);
  leg->Draw();
  //==========================================================
  TPaveText* tText1 = new TPaveText(0.75, 0.92, 0.87, 0.98, "brNDC");
  tText1->SetBorderSize(0);
  tText1->SetFillColor(0);
  tText1->SetFillStyle(0);
  TText *t1 = tText1->AddText("2.673 fb^{-1} (13 TeV)");
  tText1->SetTextSize(0.04);
  tText1->Draw(); 
  //==========================================================
  TPaveText* tText2 = new TPaveText(0.85, 0.86, 0.88, 0.87, "brNDC");
  tText2->SetBorderSize(0);
  tText2->SetFillColor(0);
  tText2->SetFillStyle(0);
  TText *t1 = tText2->AddText("CMS");
  tText2->SetTextSize(0.04);
  tText2->Draw(); 
  //==========================================================
  TPaveText* tText3 = new TPaveText(0.80, 0.81, 0.85, 0.83, "brNDC");
  tText3->SetBorderSize(0);
  tText3->SetFillColor(0);
  tText3->SetFillStyle(0);
  TText *t1 = tText3->AddText("#it{Preliminary}");
  tText3->SetTextSize(0.04);
  tText3->Draw(); 
  //=================================================================================== 
  c2->Print("Stack-DY-Spring15MCs-Data2015-cumulative-spectrum-MuMu-OS-2673pb.png","png");
  //c2->Print("Stack-DY-Spring15MCs-Data2015-cumulative-spectrum-MuMu-OS-2673pb.pdf","pdf");

  

}
Exemple #7
0
void doPlotsBtag_Log(bool logPlot){
setTDRStyle();

double lumi = 5800;
//stuff to choose
//bool logPlot = false; //true for log plot
int rebinFact = 1;

//isolation selection
//TString Isolation = "QCD No Iso/";
TString Isolation = "Ref selection/";
//TString Isolation = "QCD mu+jets PFRelIso/";
//TString Isolation = "QCD non iso mu+jets/";

TString Systematic = "central";

// number of btags
TString Nbtags = "2btags";  //standard  "2btags" , qcd "0btag"

//choose object
TString Obj = "";
//TString Obj = "MET/";

//muon variables
const int N = 2;
TString Variable;
TString Variables[N] = {"N_BJets", "N_BJets_reweighted"};
double MinXs[N] = {-0.5,-0.5};
double MaxXs[N] = {7.5,7.5};
TString XTitles[N] = {"B-tag Multiplicity", "B-tag Multiplicity"};



//loop over variables
for(int i = 0; i<2; i++){
double MinX = MinXs[i];
double MaxX = MaxXs[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("SingleMu", 1, Obj, Variable, Isolation, rebinFact, "central");

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* wjets = getSample("W1Jet", lumi*37509/57708550, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",     lumi*34679.3/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, Obj, Variable, Isolation, rebinFact, Systematic);

//make combined top and single top template
TH1D* sing_top = (TH1D*)top_t->Clone("top");
sing_top->Add(top_tw);sing_top->Add(top_s); sing_top->Add(tbar_t); sing_top->Add(tbar_tw);sing_top->Add(tbar_s);

zjets->Add(z2jets);
zjets->Add(z3jets);
zjets->Add(z4jets);  

wjets->Add(w2jets);
wjets->Add(w3jets);
wjets->Add(w4jets);

//make combined top and single top template
TH1D* qcd_all = (TH1D*)qcd->Clone("qcd_all");
qcd_all->Add(qcd2);
qcd_all->Add(qcd3);
qcd_all->Add(qcd4);
qcd_all->Add(qcd5);
qcd_all->Add(qcd6);
qcd_all->Add(qcd7);
qcd_all->Add(qcd8);
qcd_all->Add(qcd9);
qcd_all->Add(qcd10);
qcd_all->Add(qcd11);
  
THStack *hs = new THStack("hs","test");

qcd_all->SetLineColor(kBlack);
zjets->SetLineColor(kBlack);
wjets->SetLineColor(kBlack);	
sing_top->SetLineColor(kBlack);
tt->SetLineColor(kBlack);	

  hs->Add(qcd_all);
  hs->Add(zjets);
  hs->Add(wjets);
  hs->Add(sing_top);
  hs->Add(tt);

  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);
		
  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.2);
  hs->SetMinimum(1.);
  
  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);

//events:
cout << "ttbar: " << tt->Integral() << endl;
cout << "data: " << data->Integral() << endl;
  
  if(logPlot == true){
  hs->GetXaxis()->SetLimits(MinX, MaxX);
  }else{
  hs->GetXaxis()->SetLimits(MinX, 4.5);
  }
  
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.7,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "f");
	tleg2->AddEntry(sing_top, "single top", "f");
	tleg2->AddEntry(wjets , "w+jets", "f");
	tleg2->AddEntry(zjets , "z+jets", "f");
	tleg2->AddEntry(qcd_all , "QCD", "f");
	
	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	
	
	if(logPlot == true){
  	TText* textPrelim = doPrelim(0.12,0.96, "#geq 0 btags");
	textPrelim->Draw();
  	}else{
	TText* textPrelim = doPrelim(0.2,0.96, "");
	textPrelim->Draw();
	}
	
  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("Plots/TTbarPlusVarAnalysis/Nbtags/");
  
  if(logPlot ==true){
    plotName += Variable+"_Log";  
  }else{
    plotName += Variable;  
  }
 
 
  c1->SaveAs(plotName+".pdf");
  c1->SaveAs(plotName+".png");
  delete c1;
  
  }
  	
}
Exemple #8
0
void draw_from_trees(TString var, TCut other_cuts,
		     TString weights, TString title, int nbinsx, 
		     double xlow, double xup,
		     TString options="plotSig:plotLog:plotData",
		     double cut_low=-1, double cut_high=-1,
		     TString plot_title="default")
{

  bool plotSig = options.Contains("plotSig") && (!options.Contains("!plotSig"));
  bool plotLog = options.Contains("plotLog") && (!options.Contains("!plotLog"));
  bool plotData = options.Contains("plotData") && (!options.Contains("!plotData"));
  bool sigStack = options.Contains("sigStack") && (!options.Contains("!sigStack"));

  // Book histograms
  TH1D * httbar = new TH1D("ttbar" , title, nbinsx, xlow, xup);
  TH1D * hqcd = new TH1D("qcd" , title, nbinsx, xlow, xup);
  TH1D * hznn = new TH1D("znn" , title, nbinsx, xlow, xup);
  TH1D * hwjets = new TH1D("wjets" , title, nbinsx, xlow, xup);
  TH1D * hother = new TH1D("other" , title, nbinsx, xlow, xup);
  TH1D * hmc_exp = new TH1D("mc_exp" , title, nbinsx, xlow, xup);
  TH1D * hsingle_top = new TH1D("single_top" , title, nbinsx, xlow, xup);  
  TH1D * ht1bbbb_1500_100 = new TH1D("t1bbbb_1500_100" , title, nbinsx, xlow, xup);
  TH1D * ht1bbbb_1000_900 = new TH1D("t1bbbb_1000_900" , title, nbinsx, xlow, xup);
  TH1D * ht1tttt_1500_100 = new TH1D("t1tttt_1500_100" , title, nbinsx, xlow, xup);
  TH1D * ht1tttt_1200_800 = new TH1D("t1tttt_1200_800" , title, nbinsx, xlow, xup);
  TH1D * ht1qqqq_1400_100 = new TH1D("t1qqqq_1400_100" , title, nbinsx, xlow, xup);
  TH1D * ht1qqqq_1000_800 = new TH1D("t1qqqq_1000_800" , title, nbinsx, xlow, xup);

  // Format cuts
  TCut cut(other_cuts);

  // TCut ttbar_weight("(weightppb*4000)/top_pt_weight_official");

  TCut ttbar_weight("(3.17760399999999981e-05*4000)");

  cout << "Filling histograms for " << var.Data() << endl;
  ttbar_ch->Project("ttbar",var,(cut)*ttbar_weight);
  qcd_ch->Project("qcd",var,cut*weights);
  znn_ch->Project("znn",var,cut*weights);
  wjets_ch->Project("wjets",var,(cut)*weights);
  other_ch->Project("other",var,cut*weights);
  single_top_ch->Project("single_top",var,cut*weights);
  t1bbbb_1500_100_ch->Project("t1bbbb_1500_100",var,(cut)*weights);
  t1bbbb_1000_900_ch->Project("t1bbbb_1000_900",var,(cut)*weights);
  t1tttt_1500_100_ch->Project("t1tttt_1500_100",var,(cut)*weights);
  t1tttt_1200_800_ch->Project("t1tttt_1200_800",var,(cut)*weights);
  t1qqqq_1400_100_ch->Project("t1qqqq_1400_100",var,(cut)*weights);
  t1qqqq_1000_800_ch->Project("t1qqqq_1000_800",var,(cut)*weights);


  bool addOverflow(true);
  Double_t e_overflow(0.), i_overflow(0.);
  if (addOverflow) {
    i_overflow=httbar->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    httbar->SetBinContent(nbinsx, i_overflow);
    httbar->SetBinError(nbinsx, e_overflow);
    i_overflow=hqcd->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hqcd->SetBinContent(nbinsx, i_overflow);
    hqcd->SetBinError(nbinsx, e_overflow);
    i_overflow=hznn->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hznn->SetBinContent(nbinsx, i_overflow);
    hznn->SetBinError(nbinsx, e_overflow);
    i_overflow=hwjets->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hwjets->SetBinContent(nbinsx, i_overflow);
    hwjets->SetBinError(nbinsx, e_overflow);
    i_overflow=hsingle_top->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hsingle_top->SetBinContent(nbinsx, i_overflow);
    hsingle_top->SetBinError(nbinsx, e_overflow);
    i_overflow=hother->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hother->SetBinContent(nbinsx, i_overflow);
    hother->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1bbbb_1500_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1bbbb_1500_100->SetBinContent(nbinsx, i_overflow);
    ht1bbbb_1500_100->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1bbbb_1000_900->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1bbbb_1000_900->SetBinContent(nbinsx, i_overflow);
    ht1bbbb_1000_900->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1tttt_1500_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1tttt_1500_100->SetBinContent(nbinsx, i_overflow);
    ht1tttt_1500_100->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1tttt_1200_800->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1tttt_1200_800->SetBinContent(nbinsx, i_overflow);
    ht1tttt_1200_800->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1qqqq_1400_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1qqqq_1400_100->SetBinContent(nbinsx, i_overflow);
    ht1qqqq_1400_100->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1qqqq_1000_800->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1qqqq_1000_800->SetBinContent(nbinsx, i_overflow);
    ht1qqqq_1000_800->SetBinError(nbinsx, e_overflow);
  }

  
  // Add up MC histograms
  hmc_exp->Add(httbar);
  hmc_exp->Add(hqcd);
  hmc_exp->Add(hznn);
  hmc_exp->Add(hwjets);
  hmc_exp->Add(hsingle_top);
  hmc_exp->Add(hother);


  double binwidth = (xup - xlow) / nbinsx;
  TString ytitle = Form("Events / %.3f", binwidth);
  hmc_exp->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle());
  hmc_exp->GetYaxis()->SetTitle(ytitle);
  cout << "... DONE: add all backgrounds to mc_exp." << endl;
  
  Double_t ttbar_e(0.), qcd_e(0.), znn_e(0.), wjets_e(0.), other_e(0.), single_top_e(0.), bg_tot_e(0.), t1tttt_1500_100_e(0.);
  double ttbar_n(httbar->IntegralAndError(0,nbinsx+1, ttbar_e));
  double qcd_n(hqcd->IntegralAndError(0,nbinsx+1, qcd_e));
  double znn_n(hznn->IntegralAndError(0,nbinsx+1, znn_e));
  double wjets_n(hwjets->IntegralAndError(0,nbinsx+1, wjets_e));
  double other_n(hother->IntegralAndError(0,nbinsx+1, other_e));
  double single_top_n(hsingle_top->IntegralAndError(0,nbinsx+1, single_top_e));
  double bg_tot(hmc_exp->IntegralAndError(0,nbinsx+1, bg_tot_e));
  double t1tttt_1500_100_n(ht1tttt_1500_100->IntegralAndError(0,nbinsx+1, t1tttt_1500_100_e));


  printf("Counts before cut: %s\n",var.Data());
  printf("&ttbar&qcd&znn&wjets&single top&other&t1bbbb_1500_100\\\\ \n");
  printf("%s & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f \\\\\n",
	 var.Data(),
	 ttbar_n,ttbar_e,
	 qcd_n,qcd_e,
	 znn_n,znn_e,
	 wjets_n,wjets_e,
	 single_top_n,single_top_e,
	 other_n,other_e,
	 //	 hmc_exp->GetBinContent(1), hmc_exp->GetBinError(1),
	 bg_tot,bg_tot_e,
	 t1tttt_1500_100_n,t1tttt_1500_100_e);


  cout << "... DONE: filled histograms." << endl;
 
  if (sigStack) {
    for (int bin(0); bin<nbinsx; bin++) {
      ht1bbbb_1500_100->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1));
      ht1bbbb_1000_900->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1));
      ht1tttt_1500_100->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1));
      ht1tttt_1200_800->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1));
    }
  }
 
  THStack * hs = new THStack("hs", "");
  hs->Add(hother); 
  hs->Add(hsingle_top);
  hs->Add(hwjets);
  hs->Add(hznn);
  if (httbar->Integral()>hqcd->Integral()) {
    hs->Add(hqcd);
    hs->Add(httbar);
  } else {
    hs->Add(httbar);
    hs->Add(hqcd);
  }


  //hs->GetYaxis()->SetTitle("Events / 5 fb^{-1}");
  //hs->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle());

  // Setup histogram styles
  set_style(httbar, "ttbar");
  set_style(hqcd, "qcd");
  set_style(hznn, "znn");
  set_style(hwjets, "wjets");
  set_style(hother, "other");
  set_style(hsingle_top, "single_top");

  // Setup auxiliary histograms (ratios, errors, etc)
  TH1D * staterr = (TH1D *) hmc_exp->Clone("staterr");
  staterr->Sumw2();
  //staterr->SetFillColor(kRed);
  staterr->SetFillColor(kGray+3);
  staterr->SetMarkerSize(0);
  staterr->SetFillStyle(3013);

 
  // Setup legends
  TLegend * leg1 = new TLegend(0.48, 0.6, 0.72, 0.92);
  set_style(leg1,0.025);
  if (plotData) leg1->AddEntry(hsingle_top, "Data", "pel");
  if (plotSig) {
    leg1->AddEntry(ht1bbbb_1500_100, "#splitline{T1bbbb}{(1500,100) GeV}", "l");
    leg1->AddEntry(ht1bbbb_1000_900, "#splitline{T1bbbb}{(1000,900) GeV}", "l");
    leg1->AddEntry(ht1tttt_1500_100, "#splitline{T1tttt}{(1500,100) GeV}", "l");
    leg1->AddEntry(ht1tttt_1200_800, "#splitline{T1tttt}{(1200,800) GeV}", "l");
    leg1->AddEntry(ht1qqqq_1400_100, "#splitline{T1qqqq}{(1400,100) GeV}", "l");
    leg1->AddEntry(ht1qqqq_1000_800, "#splitline{T1qqqq}{(1000,800) GeV}", "l");
  }
 

  TLegend * leg2 = new TLegend(0.72, 0.6, 0.94, 0.92);
  set_style(leg2,0.025);
  if (httbar->Integral()>hqcd->Integral()) {
    leg2->AddEntry(httbar, "t#bar{t}", "f");
    leg2->AddEntry(hqcd, "QCD", "f");
  } else {
    leg2->AddEntry(hqcd, "QCD", "f");
    leg2->AddEntry(httbar, "t#bar{t}", "f");
  }
  leg2->AddEntry(hznn, "Z+jets", "f");
  leg2->AddEntry(hwjets, "W+jets", "f");
  leg2->AddEntry(hsingle_top, "Single Top", "f");
  leg2->AddEntry(hother, "Other", "f");
  leg2->AddEntry(staterr, "MC uncert.", "f");
    
  double ymax = hs->GetMaximum();
  if (ht1tttt_1500_100->GetMaximum()>ymax) ymax=ht1tttt_1500_100->GetMaximum();
  if (ht1bbbb_1500_100->GetMaximum()>ymax) ymax=ht1bbbb_1500_100->GetMaximum();
  if (ht1qqqq_1400_100->GetMaximum()>ymax) ymax=ht1qqqq_1400_100->GetMaximum();


  if(plotLog) {
    hs->SetMaximum(200*ymax);
    hs->SetMinimum(0.1);
  }
  else {
    hs->SetMaximum(2*ymax);
    if (plot_title.Contains("baseline")) hs->SetMaximum(1.3*ymax);
  }
  // Vertical lines for cuts
  TLine* line_low = new TLine(cut_low,0,cut_low,1.5*ymax);
  TLine* line_high = new TLine(cut_high,0,cut_high,1.5*ymax);
  set_style(line_low);
  set_style(line_high);

  // Setup canvas and pads  
  TCanvas * c1 = new TCanvas("c1", "c1", 700, 700);
  TPad * pad1 = new TPad("pad1", "top pad" , 0.0, 0.3, 1.0, 1.0);
  TPad * pad2 = new TPad("pad2", "bottom pad", 0.0, 0.0, 1.0, 0.3);
  if(plotData) {
    pad1->SetBottomMargin(0.0);
    pad1->Draw();
    pad2->SetTopMargin(0.0);
    pad2->SetBottomMargin(0.35);
    pad2->Draw();
    pad1->cd();
    pad1->SetLogy(plotLog);
  }
  else {
    c1->cd();
    c1->SetLogy(plotLog);
  }
  // Draw hists
  hs->Draw("hist");
  hs->SetTitle(hmc_exp->GetTitle());
  hs->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle());
  hs->GetYaxis()->SetTitle(ytitle);
  hs->GetXaxis()->SetLabelSize(0.03);
  hs->GetYaxis()->SetLabelSize(0.03);
  if (plotData) 
    {
      //  hsingle_top->Draw("e1 same");
      hs->GetXaxis()->SetLabelSize(0);
    }
  staterr->Draw("e2 same");
  if (plotSig) {
    ht1bbbb_1500_100->SetLineColor(2);
    ht1bbbb_1500_100->SetLineWidth(4);
    ht1bbbb_1500_100->SetFillColor(0);
    ht1bbbb_1000_900->SetLineColor(2);
    ht1bbbb_1000_900->SetLineWidth(4);
    ht1bbbb_1000_900->SetLineStyle(7);
    ht1bbbb_1000_900->SetFillColor(0);
    ht1tttt_1500_100->SetLineColor(kGreen);
    ht1tttt_1500_100->SetLineWidth(4);
    ht1tttt_1500_100->SetFillColor(0);
    ht1tttt_1200_800->SetLineColor(kGreen);
    ht1tttt_1200_800->SetLineStyle(7);
    ht1tttt_1200_800->SetLineWidth(4);
    ht1tttt_1200_800->SetFillColor(0);
    ht1qqqq_1400_100->SetLineColor(1006);
    ht1qqqq_1400_100->SetLineWidth(4);
    ht1qqqq_1400_100->SetFillColor(0);
    ht1qqqq_1000_800->SetLineColor(1006);
    ht1qqqq_1000_800->SetLineWidth(4);
    ht1qqqq_1000_800->SetLineStyle(7);
    ht1qqqq_1000_800->SetFillColor(0);
    ht1bbbb_1500_100->Draw("hist same");
    ht1bbbb_1000_900->Draw("hist same");
    ht1tttt_1500_100->Draw("hist same");
    ht1tttt_1200_800->Draw("hist same");
    ht1qqqq_1400_100->Draw("hist same");
    ht1qqqq_1000_800->Draw("hist same");
  }
  if (cut_low>0) line_low->Draw("same");
  if (cut_high>0) line_high->Draw("same");


  // Draw legends
  leg1->Draw();
  leg2->Draw();
  TLatex * latex = new TLatex();
  latex->SetNDC();
  latex->SetTextAlign(12);
  latex->SetTextFont(62);
  latex->SetTextSize(0.042);
  latex->DrawLatex(0.19, 0.89, "CMS Simulation");
  latex->SetTextSize(0.03);
  latex->DrawLatex(0.19, 0.84, "#sqrt{s} = 13 TeV, L = 4 fb^{-1}");
  
  // Print
  cout << "MakePlots(): Printing..." << endl;

  c1->cd();
  if (plot_title.EqualTo("default")) plot_title=plotdir+var;
  gPad->Print(plotdir+plot_title+".pdf");


  // Clean up
  delete staterr;
  delete leg1;
  delete leg2;
  delete latex;
  // delete pave;
  delete hs;
  delete pad1;
  delete pad2;
  delete c1;

  delete httbar;
  delete hqcd;
  delete hznn;
  delete hwjets;
  delete hsingle_top;
  delete hother;
  delete hmc_exp;

  delete ht1bbbb_1500_100;
  delete ht1bbbb_1000_900;
  delete ht1tttt_1500_100;
  delete ht1tttt_1200_800;
  delete ht1qqqq_1400_100;
  delete ht1qqqq_1000_800;

  cout << "MakePlots(): DONE!" << endl;

  return;
}
        void Draw(const int &rebin=1) {

	  Color_t _sampleColor[nSamples];
            //_sampleColor[iHWW  ] = kRed+1;
            //_sampleColor[iWW   ] = kAzure-9;
            //_sampleColor[iZJets] = kGreen+2;
            //_sampleColor[iZTau]  = kGreen+2;
            //_sampleColor[iTop  ] = kYellow;
            //_sampleColor[iWZ   ] = kAzure-2;
            //_sampleColor[iWJets] = kGray+1;
            //_sampleColor[iWJets] = kViolet-9;
            //_sampleColor[iWJets] = kCyan;

	    _sampleColor[itH   ] = kRed;
            _sampleColor[iWZ   ] = kAzure-9;
            _sampleColor[iZZ   ] = kAzure-5;
            _sampleColor[iWW   ] = kAzure-1;
            _sampleColor[itt   ] = kGray;
            _sampleColor[ittw  ] = kOrange+7;
            _sampleColor[ittz  ] = kOrange+1;
            _sampleColor[iwww  ] = kSpring+9;
            _sampleColor[iwwz  ] = kSpring+3;
            _sampleColor[iwzz  ] = kSpring-7;
            _sampleColor[idyl  ] = kViolet-1;
            _sampleColor[idy   ] = kViolet-1;
	    
            //setUpStyle();
            if(!gPad) new TCanvas();

            THStack* hstack = new THStack();
            for (int i=0; i<nSamples; i++) {

                // in case the user doesn't set it
                if( !_hist[i] ) continue;

                _hist[i]->Rebin(rebin);
                _hist[i]->SetLineColor(_sampleColor[i]);

                // signal gets overlaid
                if (i == itH) continue;

                _hist[i]->SetFillColor(_sampleColor[i]);
                _hist[i]->SetFillStyle(1001);

                hstack->Add(_hist[i]);
            }

            if(_hist[itH]) _hist[itH]->SetLineWidth(3);
            if(_data) _data->Rebin(rebin);
            if(_data) _data->SetLineColor  (kBlack);
            if(_data) _data->SetMarkerStyle(kFullCircle);

            if(_nostack) {
              for(int ihist=0;ihist<(int)_hist.size();ihist++) {
                _hist[ihist]->SetFillStyle(0);
                _hist[ihist]->SetLineWidth(2);
              }
              hstack->Draw("hist,nostack");
              if(_hist[itH]) _hist[itH]->Draw("hist,same");
              if(_data) _data->Draw("ep,same");
            } else {
              hstack->Draw("hist");
              if(_hist[itH]) _hist[itH]->Draw("hist,same");
              if(_data) _data->Draw("ep,same");
            }
            //hstack->SetTitle("CMS preliminary");

            Float_t theMax = hstack->GetMaximum();
            Float_t theMin = hstack->GetMinimum();

	    theMax = 1.0;
            //Float_t theMin = hstack->GetMinimum();

            if (_hist[itH]) {
                if (_hist[itH]->GetMaximum() > theMax) theMax = _hist[itH]->GetMaximum();
                if (_hist[itH]->GetMinimum() < theMin) theMin = _hist[itH]->GetMinimum();
            }

            if (_data) {

                Float_t dataMax = GetMaximumIncludingErrors(_data);

                if (dataMax > theMax) theMax = dataMax;
            }

            if (gPad->GetLogy()) {
                hstack->SetMaximum(500 * theMax);
                hstack->SetMinimum(0.05);
            } else {
                hstack->SetMaximum(1.55 * theMax);
            }

            if(_breakdown) {
                THStackAxisFonts(hstack, "y", "entries");
                hstack->GetHistogram()->LabelsOption("v");
            } else {
                THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
                if(_units.Sizeof() == 1) {
                    THStackAxisFonts(hstack, "x", _xLabel.Data());
                    THStackAxisFonts(hstack, "y", "entries");
                } else {
                    THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
                    THStackAxisFonts(hstack, "y", TString::Format("entries / %.0f %s", _hist[iWZ]->GetBinWidth(0),_units.Data()));
                }
            }

            // total mess to get it nice, should be redone
            size_t j=0;
            TString higgsLabel = " tH x 100";
            //if(_mass != 0) higgsLabel.Form(" m_{H}=%d",_mass);

	    
            if(_data        ) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _data,         " data",    "lp"); j++; }
            if(_hist[itH   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itH   ], higgsLabel, "l" ); j++; }
            if(_hist[iWZ   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWZ   ], " WZ",      "f" ); j++; }
            if(_hist[iZZ   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iZZ   ], " ZZ",      "f" ); j++; }
            if(_hist[iWW   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWW   ], " WW",      "f" ); j++; }
            if(_hist[itt   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itt   ], " tt",      "f" ); j++; }
            if(_hist[ittw  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittw  ], " ttW",     "f" ); j++; }
            if(_hist[ittz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittz  ], " ttZ",     "f" ); j++; }
            if(_hist[iwww  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwww  ], " WWW",     "f" ); j++; }
            if(_hist[iwwz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwwz  ], " WWZ",     "f" ); j++; }
            if(_hist[iwzz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwzz  ], " WZZ",     "f" ); j++; }
            if(_hist[idy   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[idy   ], " Drell-Yan","f" ); j++; }
	    

            //TLatex* luminosity = new TLatex(0.9, 0.815, TString::Format("L = %.1f fb^{-1}",_lumi));
            TLatex* luminosity = new TLatex(0.9, 0.95, TString::Format("CMS Preliminary \\sqrt{s} = 8 TeV, L = %.1f fb^{-1}",_lumi));
            luminosity->SetNDC();
            luminosity->SetTextAlign(32);
            luminosity->SetTextFont(42);
            luminosity->SetTextSize(_tsize);
            luminosity->Draw("same");
            // if(_extraLabel) _extraLabel->Draw("same");
            // return hstack->GetHistogram();
        }
void Unfold()
{
	// usa gli errori degli istogrammi
	TH1::SetDefaultSumw2();

	int const nSmear=250; // numero di bin nella matrice di migrazione -- dati Smeared
	int const nGen=100; // numero di bin nella matrice di migrazione -- dati Generator (binning meno fine, v. TUnfold)
	double const xminSmear=-3.;
	double const xmaxSmear=3.;
	double const xminGen=-3.; 
	double const xmaxGen=3.; // la generazione avviene tra -3 e 3, ma la "rivelazione" (smearing) tra -2.5 e 2.5 per rimuovere gli effetti del bordo

	// ------------------ istogrammi --------------------------
	// matrice delle migrazioni
	TH2D* migrMatrix = new TH2D ("migrMatrix", "Matrice di migrazione; smeared; generator", nSmear, xminSmear, xmaxSmear, nGen, xminGen, xmaxGen);

	// dati da unfoldare
	TH1D* data_smeared = new TH1D ("data_smeared", "Spettro dopo lo smearing; x; N", nSmear, xminSmear, xmaxSmear);
	TH1D* data_smeared_clone = new TH1D ("data_smeared_clone", "Spettro dopo lo smearing; x; N", nGen, xminGen, xmaxGen); // clone del precedente ma con il binning Gen per un plot sovraimposto

	// dati a livello generatore --> solo per confronto; questo istogramma non è disponibile in una misura reale
	TH1D* data_generator = new TH1D ("data_generator", "Spettro prima dello smearing; x; N", nGen, xminGen, xmaxGen);

	// risultato dell'unfolding
	TH1D* data_unfolded = new TH1D ("data_unfolded", "Spettro dopo l'unfolding; x; N", nGen, xminGen, xmaxGen);

	// ------------------ file di dati -----------------------
	std::ifstream datafile_high_stat ("dati_high_statistics.txt");
	std::ifstream datafile_sample ("dati_sample.txt");


	// ------------------ riempi matrice di migrazione -------------
	double buf;
	int count = 0;
	
	while (1)
	{
		if (count % 100000 == 0)
		{cout << count << endl;}
		
		datafile_high_stat >> buf;
		
		if (datafile_high_stat.eof())
		{break;}

		migrMatrix->Fill(Smear(buf), buf); // x= smeared (detector); y = generator (MC)
		count++;	
	}
	
	// --------------- riempi istogramma di dati --------------------
	while (1)
	{
		if (count % 100000 == 0)
		{cout << count << endl;}		

		datafile_sample >> buf;
		if (datafile_sample.eof())
		{break;}
		
		data_generator -> Fill (buf);
		data_smeared -> Fill (Smear(buf));
		data_smeared_clone -> Fill (Smear(buf));
		
		count++;
	}

	// --------------- setup dell'unfolding ------------------------
	TUnfold unfold(migrMatrix,TUnfold::kHistMapOutputVert, TUnfold::kRegModeCurvature, TUnfold::kEConstraintArea);
	
	if(unfold.SetInput(data_smeared)>=10000)
	{std::cout<<"Possibili errori nei risultati dell'unfold\n";}

	// parametro di regolarizzazione + esecuzione dell'unfold
	double tau = 0.0045;
	double unfold_status;
	unfold_status = unfold.DoUnfold(tau);

	if (unfold_status >= 1.) // do unfold restituisce il max coeficiente di correlazione
	{cout << "\n\n**ATTENZIONE**\n\nErrori durante l'unfold!\nI risultati successivi non sono validi\n\n";}
	
	// ---------------- recupera i risultati dell'unfold ------------

	// binMap mappa linearmente i risultati dell'unfold nei bin dell'istogramma di output, e non salva under/overflow	
	int *binMap=new Int_t[nGen+2];
	for(Int_t i=1;i<=nGen;i++)
	{binMap[i]=i;}

	binMap[0]=-1; // no underflow
	binMap[nGen+1]=-1; // no overflow

	// recupera l'istogramma unfoldato
	unfold.GetOutput(data_unfolded,binMap);


	// ----------- disegna ----------------------------------
	data_generator->SetLineColor(kBlue);
	data_unfolded->SetLineColor(kRed);
	data_smeared_clone->SetLineColor(kGreen+1);

	data_generator->SetLineWidth(1.5);
	data_unfolded->SetLineWidth(1.5);
	data_smeared_clone->SetLineWidth(1.5);

	TLegend* l = new TLegend (0.63, 0.68, 0.89, 0.89);
	l->AddEntry(data_generator, "Pre-smearing", "l");
	l->AddEntry(data_smeared_clone, "Post-smearing (#sigma = 2#Deltax)", "l");
	l->AddEntry(data_unfolded, "Unfolded con #tau = 0.0045", "l");
	l->SetFillColor(kWhite);
	l->SetLineColor(kWhite);

	THStack* stack = new THStack ("stack", ";x;N");
	stack->Add(data_generator);
	stack->Add(data_smeared_clone);
	stack->Add(data_unfolded);

	stack->SetMinimum(0.);

	TCanvas* c1 = new TCanvas;
	stack->Draw("nostack H");
	//stack->GetHistogram()->GetXaxis()->SetTitle("x");
	stack->Draw("nostack H");
	l->Draw();
	

	// stampa aree
	cout << "AREE (no u/o flow) -- (con u/o flow)" << endl;
	cout << "Generator: " << data_generator->Integral() << " " << data_generator->Integral(0, nGen+1) << endl;
	cout << "Smeared: " << data_smeared->Integral() << " " << data_smeared->Integral(0, nSmear+1) << endl;
	cout << "Unfolded: " << data_unfolded->Integral() << " " << data_unfolded->Integral(0, nGen+1) << endl;

	// ------------------- residui dopo unfold ----------------
	
	TH1F *residui = new TH1F("residui","Bias;x;Generator - Unfolded",nGen,xminGen, xmaxGen);
	
	double err1, err2, errtot;
	for (Int_t i=1;i<=nGen;i++)
	{
		double diff = data_generator->GetBinContent(i) - data_unfolded->GetBinContent(i);
		err1 = data_generator->GetBinError(i);
		err2 = data_unfolded->GetBinError(i);
		errtot = err1 + err2;
		residui->SetBinContent(i,diff);
		residui->SetBinError(i, errtot);		
	}

	gStyle->SetOptStat(0);
	TCanvas* c2 = new TCanvas;
	TLine * ll = new TLine (-3, 0, 3, 0);
	ll->SetLineColor(kBlack);
	ll->SetLineStyle(2);
	
	residui->Draw("H");
	ll->Draw("same");
	


}
//void PaintOverflow(THStack *h);
void SamMacroModBinWidth(){
  float value = 2.5;
  TCanvas *c1 = new TCanvas("c1", "c1",800,500);
  TPad* spectrumPad=0;
  TPad* ratioPad=0;
  //c1->Divide(1,2);
  //gStyle->SetOptStat(111111);
  gStyle->SetOptFit(kFALSE);
  gStyle->SetOptStat(kFALSE);
  gStyle->SetStatX(0.457589);
  gStyle->SetStatY(0.312937);
  gStyle->SetStatW(0.29241/2+0.0185);
  gStyle->SetStatH(0.169580+0.05);
  gStyle->SetStatFontSize(0.0402098);
  gStyle->SetStatFont(0.02);
  gStyle->SetFitFormat("5.2g");
  gStyle->SetStatBorderSize(0);
  gStyle->SetStatFontSize(0.040209);
  gStyle->SetStatFontSize(0.035209);
  c1->Range(1.592761,-5.173913,3.533814,6.006211);
  c1->SetFillColor(0);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->SetLogx(1);
  c1->SetLogy(1);
  c1->SetTickx(1);
  c1->SetTicky(1);
  c1->SetLeftMargin(0.13);
  c1->SetRightMargin(0.07);
  c1->SetFrameBorderMode(0);
  c1->SetFrameBorderMode(0);
  c1->SetTopMargin(0.085);
  c1->SetBottomMargin(0.11);
  
  // Build the histo with constant log bin width
  const int NMBINS = 100;
  const double MMIN = 60., MMAX = 3000.;
  double logMbins[NMBINS+1];
  float binNormNr=0.;
  for (int ibin = 0; ibin <= NMBINS; ibin++) {
    logMbins[ibin] = exp(log(MMIN) + (log(MMAX)-log(MMIN))*ibin/NMBINS);
    cout << logMbins[ibin] << endl;
  }
  TH1* hTTbarDiboson   = new TH1F("hTTbarDiboson","",NMBINS, logMbins);
  TH1* hDijetWjets     = new TH1F("hDijetWjets","",NMBINS, logMbins);
  TH1* ttbarHist       = new TH1F("ttbarHist","",NMBINS, logMbins);
  TH1* dibosonsBkgHist = new TH1F("dibosonsBkgHist","",NMBINS, logMbins);
  //========================================================== 
  //                                                              
  //               Get the histograms                                  
  //==========================================================
  //TFile *file1 = new TFile("h_ZprimeRecomass_DYBinWidth.root","READ");
  //TH1* zeeHist = (TH1*) file1->Get("ZprimeRecomassBinWidth");

  TFile *file1 = new TFile("DY-MuMu-MC-OS-allbins-MC-2673pb.root","READ");
  TH1* zeeHist = (TH1*) file1->Get("hMassDYAll6");

  TFile *file2 = new TFile("h_ZprimeRecomass_Tlike.root","READ");
  TH1* ttbarHist = (TH1*) file2->Get("ZprimeRecomassBinWidth");
  TFile *file3 = new TFile("h_ZprimeRecomass_DiBoson.root","READ");
  TH1* dibosonsBkgHist = (TH1*) file3->Get("ZprimeRecomassBinWidth");

  TFile *file4 = new TFile("h_ZprimeRecomass_data.root","READ");
  TH1* dataHistTempbar = (TH1*) file4->Get("ZprimeRecomassBinWidth");

  TFile *file5 = new TFile("FR-DiJets-Data-OS-BinWidth-2673pb.root","READ");
  TH1* jetBkgHist   = (TH1*) file5->Get("DataSub");

  TFile *file6 = new TFile("FR-Wjets-25nsMC-OS-BinWidth-2673pb.root","READ");
  TH1* WjetsBkgHist = (TH1*) file6->Get("WjetsHisto");
  std::cout<<"nbQCD(dijets,Data)  = "<<jetBkgHist->Integral()<<endl;
  std::cout<<"nb.Wjets(MC)  = "<<WjetsBkgHist->Integral()<<endl;

  hTTbarDiboson->Add(ttbarHist,dibosonsBkgHist,1,1);
  hDijetWjets->Add(jetBkgHist,WjetsBkgHist,1,1);

  
  zeeHist->Rebin(value);
  hTTbarDiboson->Rebin(value);
  dibosonsBkgHist->Rebin(value);
  dataHistTempbar->Rebin(value);
  hDijetWjets->Rebin(value);
  WjetsBkgHist->Rebin(value);

  
  float binWidthNorm=1;
  int zeeColour    =  TColor::GetColor("#99ccff");
  int jetBkgColour = TColor::GetColor("#ffff66"); 
  int ttbarColour  = TColor::GetColor("#ff6666");
  int bosonColour  = TColor::GetColorDark(3);
  int WjetsColour  = TColor::GetColorDark(5);
  int font = 42;
  //float xAxisMin = 60; //72
  //float xAxisMax = 1000.0;
  //float yAxisMin = 1e-4;
  //float yAxisMax = 1e3; 
  
  TGraphAsymmErrors* dataHist = makeDataGraph(dataHistTempbar,binWidthNorm,0);
  normHistToBinWidth(zeeHist,binWidthNorm);
  normHistToBinWidth(hTTbarDiboson,binWidthNorm);
  //normHistToBinWidth(dibosonsBkgHist,binWidthNorm);
  normHistToBinWidth(hDijetWjets,binWidthNorm);
  //normHistToBinWidth(WjetsBkgHist,binWidthNorm);
  
  //gStyle->SetOptStat(111111);
  //PaintOverflow(zeeHist);
  //PaintOverflow(ttbarHist);
  //PaintOverflow(dibosonsBkgHist);
  //PaintOverflow(dataHistTempbar);
  //PaintOverflow(jetBkgHist);
  //PaintOverflow(WjetsBkgHist);   
  

  THStack *axisHist = new THStack("axisHist","");
  zeeHist->SetFillColor(zeeColour);
  zeeHist->SetLineWidth(2);
  zeeHist->SetLineColor(1);
  zeeHist->SetTitle("");
  
  hTTbarDiboson->SetFillColor(ttbarColour);
  hTTbarDiboson->SetLineWidth(2); 
  hTTbarDiboson->SetLineColor(1);
  
  //dibosonsBkgHist->SetFillColor(bosonColour);
  //dibosonsBkgHist->SetLineWidth(2); 
  //dibosonsBkgHist->SetLineColor(1);
  
  //WjetsBkgHist->SetFillColor(WjetsColour);
  //WjetsBkgHist->SetFillColor(jetBkgColour);
  //WjetsBkgHist->SetLineWidth(2);
  //WjetsBkgHist->SetLineColor(1);

  hDijetWjets->SetFillColor(jetBkgColour);
  hDijetWjets->SetLineWidth(2);
  hDijetWjets->SetLineColor(1);


  


  axisHist->Add(hDijetWjets,"histo");
  //axisHist->Add(WjetsBkgHist,"histo");
  axisHist->Add(hTTbarDiboson);
  //axisHist->Add(dibosonsBkgHist);
  axisHist->Add(zeeHist);
  axisHist->Draw("histo");

  
  //axisHist->GetYaxis()->SetTitle("Events / 20 GeV");
  axisHist->GetXaxis()->SetTitle("M(#mu^{+}#mu^{-}) [GeV]");
  axisHist->GetYaxis()->SetTitle("Events/GeV");
  //axisHist->GetXaxis()->SetTitleOffset(1.1);
  //axisHist->GetYaxis()->SetTitleOffset(1.1);
  axisHist->GetXaxis()->SetTitleSize(0.047);
  axisHist->GetYaxis()->SetTitleSize(0.047);
  axisHist->GetXaxis()->SetLabelSize(0.050);
  axisHist->GetYaxis()->SetLabelSize(0.050);
  axisHist->GetXaxis()->SetMoreLogLabels();
  axisHist->GetXaxis()->SetNoExponent();
  axisHist->GetXaxis()->SetRangeUser(70.0,2999.0);
  
  //axisHist->SetMinimum(0.01);
  //axisHist->SetMaximum(20000.0);
  axisHist->SetMinimum(0.0001);
  axisHist->SetMaximum(2000.0);
  
  dataHist->SetMarkerStyle(20);
  dataHist->SetMarkerSize(0.9);
  dataHist->GetXaxis()->SetRange(5,83);
  dataHist->GetXaxis()->SetTitleSize(0.047);
  dataHist->GetXaxis()->SetTitleOffset(0.9);
  dataHist->GetYaxis()->SetTitleSize(0.047);
  dataHist->GetYaxis()->SetTitleOffset(1.2);
  dataHist->Draw("PZ");
  
  //==========================================================
  TLegend *leg = new TLegend(0.56741,0.62671,0.820536,0.87664,NULL,"brNDC"); //for lumi in plot
  leg->AddEntry(dataHist,"Data","PE");
  leg->AddEntry(zeeHist,"#gamma^{*}/Z#rightarrow#mu^{+}#mu^{-}","F");
  leg->AddEntry(hTTbarDiboson,"t#bar{t}, tW, WW, WZ, ZZ, #tau^{+}#tau^{-}","F");
  //leg->AddEntry(dibosonsBkgHist,"di-boson, #gamma^{*}/Z#rightarrow#tau^{+}#tau^{-}","F");
  //leg->AddEntry(WjetsBkgHist,"W+jets (FR)","F");
  leg->AddEntry(hDijetWjets,"Jets (data)","F");
  leg->SetBorderSize(0);
  leg->SetLineColor(1);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(19);
  leg->SetFillStyle(0);
  leg->SetTextFont(font);
  leg->SetTextSize(0.04);
  leg->Draw();
  //==========================================================
  TPaveText* tText1 = new TPaveText(0.75, 0.92, 0.87, 0.98, "brNDC");
  tText1->SetBorderSize(0);
  tText1->SetFillColor(0);
  tText1->SetFillStyle(0);
  TText *t1 = tText1->AddText("2.8 fb^{-1} (13 TeV)");
  tText1->SetTextSize(0.04);
  tText1->Draw(); 
  //==========================================================
  TPaveText* tText2 = new TPaveText(0.85, 0.86, 0.88, 0.87, "brNDC");
  tText2->SetBorderSize(0);
  tText2->SetFillColor(0);
  tText2->SetFillStyle(0);
  TText *t1 = tText2->AddText("CMS");
  tText2->SetTextSize(0.04);
  tText2->Draw(); 
  //==========================================================
  TPaveText* tText3 = new TPaveText(0.80, 0.81, 0.85, 0.83, "brNDC");
  tText3->SetBorderSize(0);
  tText3->SetFillColor(0);
  tText3->SetFillStyle(0);
  TText *t1 = tText3->AddText("#it{Preliminary}");
  tText3->SetTextSize(0.04);
  tText3->Draw(); 
  //---------------------------------------------------------------------
  //---------------------------------------------------------------------
  
  //=================================================================================== 
  c1->Print("Stack-DY-Spring15MCs-Data2015-mass-spectrum-MuMu-OS-2800pb_logx.png","png");
  c1->Print("Stack-DY-Spring15MCs-Data2015-mass-spectrum-MuMu-OS-2673pb_logx.pdf","pdf");
  //=========================================================================
  //=========================================================================
  //=========================================================================
  //=========================================================================
  //=========================================================================
  //=========================================================================
  TCanvas *c2 = new TCanvas("c2", "c2",800,500);
  TPad* spectrumPad=0;
  TPad* ratioPad=0;
  // Build the histo with constant log bin width
  const int NMBINS = 100;
  const double MMIN = 60., MMAX = 3000.;
  double logMbins[NMBINS+1];
  float binNormNr=0.;
  for (int ibin = 0; ibin <= NMBINS; ibin++) {
    logMbins[ibin] = exp(log(MMIN) + (log(MMAX)-log(MMIN))*ibin/NMBINS);
    cout << logMbins[ibin] << endl;
  }
  TH1* hTTbarDiboson   = new TH1F("hTTbarDiboson","",NMBINS, logMbins);
  TH1* hDijetWjets     = new TH1F("hDijetWjets","",NMBINS, logMbins);
  TH1* ttbarHist       = new TH1F("ttbarHist","",NMBINS, logMbins);
  TH1* dibosonsBkgHist = new TH1F("dibosonsBkgHist","",NMBINS, logMbins);
  TH1F* hDivideHisto2 = new TH1F("hDivideHisto2","",150,0.0,3000.0);
  //TH1F* hMass1    = new TH1F("hMass1","",150,0.0,3000.0);
  //TH1F* hMass2    = new TH1F("hMass2","",150,0.0,3000.0);
  //TH1F* hMass3    = new TH1F("hMass3","",150,0.0,3000.0);
  //TH1F* hMass5    = new TH1F("hMass5","",150,0.0,3000.0);
  //TH1F* hMass6    = new TH1F("hMass6","",150,0.0,3000.0);
  //TH1F* AllEKWbkg = new TH1F("AllEKWbkg","",150,0.0,3000.0);
  gStyle->SetOptFit(1111);
  gStyle->SetOptStat(0);
  gStyle->SetStatX(0.457589);
  gStyle->SetStatY(0.312937);
  gStyle->SetStatW(0.29241/2+0.0185);
  gStyle->SetStatH(0.169580+0.05);
  gStyle->SetStatFontSize(0.0402098);
  gStyle->SetStatFont(0.03);
  gStyle->SetFitFormat("5.2g");
  gStyle->SetStatBorderSize(0);
  gStyle->SetStatFontSize(0.040209);
  gStyle->SetStatFontSize(0.035209);
  c2->Range(1.592761,-5.173913,3.533814,6.006211);
  c2->SetFillColor(0);
  c2->SetBorderMode(0);
  c2->SetBorderSize(2);
  c2->SetLogx(1);
  c2->SetLogy(1);
  c2->SetTickx(1);
  c2->SetTicky(1);
  c2->SetLeftMargin(0.13);
  c2->SetRightMargin(0.07);
  c2->SetFrameBorderMode(0);
  c2->SetFrameBorderMode(0);
  c2->SetTopMargin(0.085);
  c2->SetBottomMargin(0.11);
   //========================================================== 
  //                                                              
  //               Get the histograms                                  
  //==========================================================
  //TFile *file1 = new TFile("h_ZprimeRecomass_DYBinWidth.root","READ");
  //TH1* zeeHist = (TH1*) file1->Get("ZprimeRecomassBinWidth");

  TFile *file1 = new TFile("DY-MuMu-MC-OS-allbins-MC-2673pb.root","READ");
  TH1* zeeHist = (TH1*) file1->Get("hMassDYAll6");

  TFile *file2 = new TFile("h_ZprimeRecomass_Tlike.root","READ");
  TH1* ttbarHist = (TH1*) file2->Get("ZprimeRecomassBinWidth");

  TFile *file3 = new TFile("h_ZprimeRecomass_DiBoson.root","READ");
  TH1* dibosonsBkgHist = (TH1*) file3->Get("ZprimeRecomassBinWidth");

  TFile *file4 = new TFile("h_ZprimeRecomass_data.root","READ");
  TH1* dataHistTempbar = (TH1*) file4->Get("ZprimeRecomassBinWidth");

  TFile *file5 = new TFile("FR-DiJets-Data-OS-BinWidth-2673pb.root","READ");
  TH1* jetBkgHist   = (TH1*) file5->Get("DataSub");

  TFile *file6 = new TFile("FR-Wjets-25nsMC-OS-BinWidth-2673pb.root","READ");
  TH1* WjetsBkgHist = (TH1*) file6->Get("WjetsHisto");
  std::cout<<"nbQCD(dijets,Data)  = "<<jetBkgHist->Integral()<<endl;
  std::cout<<"nb.Wjets(MC)  = "<<WjetsBkgHist->Integral()<<endl;

  hTTbarDiboson->Add(ttbarHist,dibosonsBkgHist,1,1);
  hDijetWjets->Add(jetBkgHist,WjetsBkgHist,1,1);

  
  //zeeHist->Rebin(value);
  //hTTbarDiboson->Rebin(value);
  //dibosonsBkgHist->Rebin(value);
  //dataHistTempbar->Rebin(value);
  //hDijetWjets->Rebin(value);
  //WjetsBkgHist->Rebin(value);

  float binWidthNorm2=-1;
  int zeeColour    =  TColor::GetColor("#99ccff");
  int jetBkgColour = TColor::GetColor("#ffff66"); 
  int ttbarColour  = TColor::GetColor("#ff6666");
  int bosonColour  = TColor::GetColorDark(3);
  int WjetsColour  = TColor::GetColorDark(5);
  int font = 42;
  float xAxisMin = 60; //72
  float xAxisMax = 1000.0;
  float yAxisMin = 1e-4;
  float yAxisMax = 1e4; 

  dataHistTempbar = makeIntHist(dataHistTempbar);
  zeeHist         = makeIntHist(zeeHist);
  hTTbarDiboson   = makeIntHist(hTTbarDiboson);
  hDijetWjets     = makeIntHist(hDijetWjets);
  TGraphAsymmErrors* dataHist = makeDataGraph(dataHistTempbar,binWidthNorm2,0);
  
  

  THStack *axisHist2 = new THStack("axisHist2","");
  zeeHist->SetFillColor(zeeColour);
  zeeHist->SetLineWidth(2);
  zeeHist->SetLineColor(1);
  zeeHist->SetTitle("");
    
  hTTbarDiboson->SetFillColor(ttbarColour);
  hTTbarDiboson->SetLineWidth(2); 
  hTTbarDiboson->SetLineColor(1);
    
  //dibosonsBkgHist->SetFillColor(bosonColour);
  //dibosonsBkgHist->SetLineWidth(2); 
  //dibosonsBkgHist->SetLineColor(1);
   
  hDijetWjets->SetFillColor(jetBkgColour);
  hDijetWjets->SetLineWidth(2);
  hDijetWjets->SetLineColor(1);

  //WjetsBkgHist->SetFillColor(WjetsColour);
  //WjetsBkgHist->SetLineWidth(2);
  //WjetsBkgHist->SetLineColor(1);
  
  
  axisHist2->Add(hDijetWjets,"histo");
  //axisHist2->Add(WjetsBkgHist,"histo");
  //axisHist2->Add(dibosonsBkgHist,"histo");
  axisHist2->Add(hTTbarDiboson,"histo");
  axisHist2->Add(zeeHist,"histo");
  axisHist2->Draw();
  axisHist2->GetXaxis()->SetTitle("M(#mu^{+}#mu^{-}) [GeV]");
  axisHist2->GetYaxis()->SetTitle("Events #geq M(#mu^{+}#mu^{-}) [GeV]");
  axisHist2->GetXaxis()->SetTitleOffset(1.1);
  axisHist2->GetYaxis()->SetTitleOffset(1.1);
  axisHist2->GetXaxis()->SetTitleSize(0.047);
  axisHist2->GetYaxis()->SetTitleSize(0.047);
  axisHist2->GetXaxis()->SetLabelSize(0.040);
  axisHist2->GetYaxis()->SetLabelSize(0.040);
  axisHist2->GetXaxis()->SetMoreLogLabels();
  axisHist2->GetXaxis()->SetNoExponent();
  axisHist2->GetXaxis()->SetRangeUser(70.0,4000.0);
  axisHist2->SetMinimum(0.01);
  axisHist2->SetMaximum(60000.0);
  
  dataHist->SetMarkerStyle(20);
  dataHist->SetMarkerSize(0.9);
  dataHist->Draw("PZsames");
  //==========================================================
  TLegend *leg = new TLegend(0.56741,0.62671,0.820536,0.87664,NULL,"brNDC"); //for lumi in plot
  leg->AddEntry(dataHist,"Data","PE");
  leg->AddEntry(zeeHist,"#gamma^{*}/Z#rightarrow#mu^{+}#mu^{-}","F");
  leg->AddEntry(hTTbarDiboson,"t#bar{t}, tW, WW, WZ, ZZ, #tau^{+}#tau^{-}","F");
  leg->AddEntry(hDijetWjets,"Jets (data)","F");
  leg->SetBorderSize(0);
  leg->SetLineColor(1);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(19);
  leg->SetFillStyle(0);
  leg->SetTextFont(font);
  leg->SetTextSize(0.04);
  leg->Draw();

  
  //==========================================================
  TPaveText* tText1 = new TPaveText(0.75, 0.92, 0.87, 0.98, "brNDC");
  tText1->SetBorderSize(0);
  tText1->SetFillColor(0);
  tText1->SetFillStyle(0);
  TText *t1 = tText1->AddText("2.8 fb^{-1} (13 TeV)");
  tText1->SetTextSize(0.04);
  tText1->Draw(); 
  //==========================================================
  TPaveText* tText2 = new TPaveText(0.85, 0.86, 0.88, 0.87, "brNDC");
  tText2->SetBorderSize(0);
  tText2->SetFillColor(0);
  tText2->SetFillStyle(0);
  TText *t1 = tText2->AddText("CMS");
  tText2->SetTextSize(0.04);
  tText2->Draw(); 
  //==========================================================
  TPaveText* tText3 = new TPaveText(0.80, 0.81, 0.85, 0.83, "brNDC");
  tText3->SetBorderSize(0);
  tText3->SetFillColor(0);
  tText3->SetFillStyle(0);
  TText *t1 = tText3->AddText("#it{Preliminary}");
  tText3->SetTextSize(0.04);
  tText3->Draw(); 
  //===================================================================================
 
  //=================================================================================== 
  c2->Print("Stack-DY-Spring15MCs-Data2015-cumulative-spectrum-MuMu-OS-2800pb-logx.png","png");
  //c2->Print("Stack-DY-Spring15MCs-Data2015-cumulative-spectrum-MuMu-OS-2673pb-logx.pdf","pdf");

}
Exemple #12
0
void ttbar_nJet()
{
//=========Macro generated from canvas: c1/c1
//=========  (Sun Dec 11 15:16:19 2016) by ROOT version6.06/01
   TCanvas *c1 = new TCanvas("c1", "c1",1,1,1200,1416);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   c1->SetHighLightColor(2);
   c1->Range(0,0,1,1);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   c1->SetTickx(1);
   c1->SetTicky(1);
   c1->SetLeftMargin(0.15);
   c1->SetRightMargin(0.05);
   c1->SetTopMargin(0.07);
   c1->SetBottomMargin(0.13);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
  
// ------------>Primitives in pad: pad1
   TPad *pad1 = new TPad("pad1", "pad1",0,0.3,1,1);
   pad1->Draw();
   pad1->cd();
   pad1->Range(-2.1875,0,9.0625,0.5878968);
   pad1->SetFillColor(0);
   pad1->SetBorderMode(0);
   pad1->SetBorderSize(2);
   pad1->SetTickx(1);
   pad1->SetTicky(1);
   pad1->SetLeftMargin(0.15);
   pad1->SetRightMargin(0.05);
   pad1->SetTopMargin(0.07);
   pad1->SetBottomMargin(0);
   pad1->SetFrameFillStyle(0);
   pad1->SetFrameBorderMode(0);
   pad1->SetFrameFillStyle(0);
   pad1->SetFrameBorderMode(0);
   
   THStack *h = new THStack();
   h->SetName("h");
   h->SetTitle("");
   h->SetMinimum(0);
   h->SetMaximum(0.5207086);
   
   TH1F *h_stack_19 = new TH1F("h_stack_19","",9,-0.5,8.5);
   h_stack_19->SetMinimum(0);
   h_stack_19->SetMaximum(0.546744);
   h_stack_19->SetDirectory(0);
   h_stack_19->SetStats(0);

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha
   ci = TColor::GetColor("#000099");
   h_stack_19->SetLineColor(ci);
   h_stack_19->GetXaxis()->SetLabelFont(42);
   h_stack_19->GetXaxis()->SetLabelOffset(0.007);
   h_stack_19->GetXaxis()->SetTitleSize(0.05);
   h_stack_19->GetXaxis()->SetTickLength(0.025);
   h_stack_19->GetXaxis()->SetTitleFont(42);
   h_stack_19->GetYaxis()->SetTitle("a.u.");
   h_stack_19->GetYaxis()->SetLabelFont(42);
   h_stack_19->GetYaxis()->SetLabelOffset(0.007);
   h_stack_19->GetYaxis()->SetTitleSize(0.05);
   h_stack_19->GetYaxis()->SetTickLength(0.025);
   h_stack_19->GetYaxis()->SetTitleOffset(1.5);
   h_stack_19->GetYaxis()->SetTitleFont(42);
   h_stack_19->GetZaxis()->SetLabelFont(42);
   h_stack_19->GetZaxis()->SetLabelOffset(0.007);
   h_stack_19->GetZaxis()->SetTitleSize(0.05);
   h_stack_19->GetZaxis()->SetTickLength(0.025);
   h_stack_19->GetZaxis()->SetTitleFont(42);
   h->SetHistogram(h_stack_19);
   
   
   TH1D *h_nJet_QCD__217 = new TH1D("h_nJet_QCD__217","",9,-0.5,8.5);
   h_nJet_QCD__217->SetBinContent(2,0.001991738);
   h_nJet_QCD__217->SetBinContent(3,0.0005078625);
   h_nJet_QCD__217->SetBinContent(4,0.006489724);
   h_nJet_QCD__217->SetBinContent(5,0.001899386);
   h_nJet_QCD__217->SetBinContent(6,0.000696849);
   h_nJet_QCD__217->SetBinError(2,0.001424948);
   h_nJet_QCD__217->SetBinError(3,0.0005078625);
   h_nJet_QCD__217->SetBinError(4,0.00246407);
   h_nJet_QCD__217->SetBinError(5,0.001037545);
   h_nJet_QCD__217->SetBinError(6,0.0004566736);
   h_nJet_QCD__217->SetEntries(25);
   h_nJet_QCD__217->SetStats(0);

   ci = TColor::GetColor("#cccccc");
   h_nJet_QCD__217->SetFillColor(ci);
   h_nJet_QCD__217->GetXaxis()->SetTitle("N_{jet}");
   h_nJet_QCD__217->GetXaxis()->SetLabelFont(42);
   h_nJet_QCD__217->GetXaxis()->SetLabelOffset(0.007);
   h_nJet_QCD__217->GetXaxis()->SetTitleSize(0.05);
   h_nJet_QCD__217->GetXaxis()->SetTickLength(0.025);
   h_nJet_QCD__217->GetXaxis()->SetTitleFont(42);
   h_nJet_QCD__217->GetYaxis()->SetTitle("a.u.");
   h_nJet_QCD__217->GetYaxis()->SetLabelFont(42);
   h_nJet_QCD__217->GetYaxis()->SetLabelOffset(0.007);
   h_nJet_QCD__217->GetYaxis()->SetTitleSize(0.05);
   h_nJet_QCD__217->GetYaxis()->SetTickLength(0.025);
   h_nJet_QCD__217->GetYaxis()->SetTitleFont(42);
   h_nJet_QCD__217->GetZaxis()->SetLabelFont(42);
   h_nJet_QCD__217->GetZaxis()->SetLabelOffset(0.007);
   h_nJet_QCD__217->GetZaxis()->SetTitleSize(0.05);
   h_nJet_QCD__217->GetZaxis()->SetTickLength(0.025);
   h_nJet_QCD__217->GetZaxis()->SetTitleFont(42);
   h->Add(h_nJet_QCD,"");
   
   TH1D *h_nJet_Diboson__218 = new TH1D("h_nJet_Diboson__218","",9,-0.5,8.5);
   h_nJet_Diboson__218->SetBinContent(2,0.009906449);
   h_nJet_Diboson__218->SetBinContent(3,0.01358602);
   h_nJet_Diboson__218->SetBinContent(4,0.008915388);
   h_nJet_Diboson__218->SetBinContent(5,0.003026678);
   h_nJet_Diboson__218->SetBinContent(6,0.001043565);
   h_nJet_Diboson__218->SetBinContent(7,0.0001748174);
   h_nJet_Diboson__218->SetBinContent(9,0.0001402611);
   h_nJet_Diboson__218->SetBinError(2,0.001411368);
   h_nJet_Diboson__218->SetBinError(3,0.001644099);
   h_nJet_Diboson__218->SetBinError(4,0.001329375);
   h_nJet_Diboson__218->SetBinError(5,0.0007635958);
   h_nJet_Diboson__218->SetBinError(6,0.0004304521);
   h_nJet_Diboson__218->SetBinError(7,0.0001249106);
   h_nJet_Diboson__218->SetBinError(9,0.0001402611);
   h_nJet_Diboson__218->SetEntries(227);
   h_nJet_Diboson__218->SetStats(0);

   ci = TColor::GetColor("#9966cc");
   h_nJet_Diboson__218->SetFillColor(ci);
   h_nJet_Diboson__218->GetXaxis()->SetTitle("N_{jet}");
   h_nJet_Diboson__218->GetXaxis()->SetLabelFont(42);
   h_nJet_Diboson__218->GetXaxis()->SetLabelOffset(0.007);
   h_nJet_Diboson__218->GetXaxis()->SetTitleSize(0.05);
   h_nJet_Diboson__218->GetXaxis()->SetTickLength(0.025);
   h_nJet_Diboson__218->GetXaxis()->SetTitleFont(42);
   h_nJet_Diboson__218->GetYaxis()->SetTitle("a.u.");
   h_nJet_Diboson__218->GetYaxis()->SetLabelFont(42);
   h_nJet_Diboson__218->GetYaxis()->SetLabelOffset(0.007);
   h_nJet_Diboson__218->GetYaxis()->SetTitleSize(0.05);
   h_nJet_Diboson__218->GetYaxis()->SetTickLength(0.025);
   h_nJet_Diboson__218->GetYaxis()->SetTitleFont(42);
   h_nJet_Diboson__218->GetZaxis()->SetLabelFont(42);
   h_nJet_Diboson__218->GetZaxis()->SetLabelOffset(0.007);
   h_nJet_Diboson__218->GetZaxis()->SetTitleSize(0.05);
   h_nJet_Diboson__218->GetZaxis()->SetTickLength(0.025);
   h_nJet_Diboson__218->GetZaxis()->SetTitleFont(42);
   h->Add(h_nJet_Diboson,"");
   
   TH1D *h_nJet_ZpLjets__219 = new TH1D("h_nJet_ZpLjets__219","",9,-0.5,8.5);
   h_nJet_ZpLjets__219->SetBinContent(2,0.008808307);
   h_nJet_ZpLjets__219->SetBinContent(3,0.01602806);
   h_nJet_ZpLjets__219->SetBinContent(4,0.01236436);
   h_nJet_ZpLjets__219->SetBinContent(5,0.006259341);
   h_nJet_ZpLjets__219->SetBinContent(6,0.002572435);
   h_nJet_ZpLjets__219->SetBinContent(7,0.0009920883);
   h_nJet_ZpLjets__219->SetBinContent(8,0.0002993959);
   h_nJet_ZpLjets__219->SetBinContent(9,8.98201e-05);
   h_nJet_ZpLjets__219->SetBinError(2,0.0003706893);
   h_nJet_ZpLjets__219->SetBinError(3,0.0003944594);
   h_nJet_ZpLjets__219->SetBinError(4,0.0003001856);
   h_nJet_ZpLjets__219->SetBinError(5,0.0001834367);
   h_nJet_ZpLjets__219->SetBinError(6,0.0001013424);
   h_nJet_ZpLjets__219->SetBinError(7,5.882736e-05);
   h_nJet_ZpLjets__219->SetBinError(8,2.500891e-05);
   h_nJet_ZpLjets__219->SetBinError(9,7.251011e-06);
   h_nJet_ZpLjets__219->SetEntries(24915);
   h_nJet_ZpLjets__219->SetStats(0);

   ci = TColor::GetColor("#3399cc");
   h_nJet_ZpLjets__219->SetFillColor(ci);
   h_nJet_ZpLjets__219->GetXaxis()->SetTitle("N_{jet}");
   h_nJet_ZpLjets__219->GetXaxis()->SetLabelFont(42);
   h_nJet_ZpLjets__219->GetXaxis()->SetLabelOffset(0.007);
   h_nJet_ZpLjets__219->GetXaxis()->SetTitleSize(0.05);
   h_nJet_ZpLjets__219->GetXaxis()->SetTickLength(0.025);
   h_nJet_ZpLjets__219->GetXaxis()->SetTitleFont(42);
   h_nJet_ZpLjets__219->GetYaxis()->SetTitle("a.u.");
   h_nJet_ZpLjets__219->GetYaxis()->SetLabelFont(42);
   h_nJet_ZpLjets__219->GetYaxis()->SetLabelOffset(0.007);
   h_nJet_ZpLjets__219->GetYaxis()->SetTitleSize(0.05);
   h_nJet_ZpLjets__219->GetYaxis()->SetTickLength(0.025);
   h_nJet_ZpLjets__219->GetYaxis()->SetTitleFont(42);
   h_nJet_ZpLjets__219->GetZaxis()->SetLabelFont(42);
   h_nJet_ZpLjets__219->GetZaxis()->SetLabelOffset(0.007);
   h_nJet_ZpLjets__219->GetZaxis()->SetTitleSize(0.05);
   h_nJet_ZpLjets__219->GetZaxis()->SetTickLength(0.025);
   h_nJet_ZpLjets__219->GetZaxis()->SetTitleFont(42);
   h->Add(h_nJet_Z+jets,"");
   
   TH1D *h_nJet_WpLjets__220 = new TH1D("h_nJet_WpLjets__220","",9,-0.5,8.5);
   h_nJet_WpLjets__220->SetBinContent(2,0.01228717);
   h_nJet_WpLjets__220->SetBinContent(3,0.01478108);
   h_nJet_WpLjets__220->SetBinContent(4,0.01095229);
   h_nJet_WpLjets__220->SetBinContent(5,0.004774536);
   h_nJet_WpLjets__220->SetBinContent(6,0.00183733);
   h_nJet_WpLjets__220->SetBinContent(7,0.0008017153);
   h_nJet_WpLjets__220->SetBinContent(8,0.0001693615);
   h_nJet_WpLjets__220->SetBinContent(9,7.928654e-05);
   h_nJet_WpLjets__220->SetBinError(2,0.0009957224);
   h_nJet_WpLjets__220->SetBinError(3,0.0009641816);
   h_nJet_WpLjets__220->SetBinError(4,0.0007772887);
   h_nJet_WpLjets__220->SetBinError(5,0.0004513384);
   h_nJet_WpLjets__220->SetBinError(6,0.0002602176);
   h_nJet_WpLjets__220->SetBinError(7,0.0001551598);
   h_nJet_WpLjets__220->SetBinError(8,2.724934e-05);
   h_nJet_WpLjets__220->SetBinError(9,1.806879e-05);
   h_nJet_WpLjets__220->SetEntries(3309);
   h_nJet_WpLjets__220->SetStats(0);

   ci = TColor::GetColor("#66cc66");
   h_nJet_WpLjets__220->SetFillColor(ci);
   h_nJet_WpLjets__220->GetXaxis()->SetTitle("N_{jet}");
   h_nJet_WpLjets__220->GetXaxis()->SetLabelFont(42);
   h_nJet_WpLjets__220->GetXaxis()->SetLabelOffset(0.007);
   h_nJet_WpLjets__220->GetXaxis()->SetTitleSize(0.05);
   h_nJet_WpLjets__220->GetXaxis()->SetTickLength(0.025);
   h_nJet_WpLjets__220->GetXaxis()->SetTitleFont(42);
   h_nJet_WpLjets__220->GetYaxis()->SetTitle("a.u.");
   h_nJet_WpLjets__220->GetYaxis()->SetLabelFont(42);
   h_nJet_WpLjets__220->GetYaxis()->SetLabelOffset(0.007);
   h_nJet_WpLjets__220->GetYaxis()->SetTitleSize(0.05);
   h_nJet_WpLjets__220->GetYaxis()->SetTickLength(0.025);
   h_nJet_WpLjets__220->GetYaxis()->SetTitleFont(42);
   h_nJet_WpLjets__220->GetZaxis()->SetLabelFont(42);
   h_nJet_WpLjets__220->GetZaxis()->SetLabelOffset(0.007);
   h_nJet_WpLjets__220->GetZaxis()->SetTitleSize(0.05);
   h_nJet_WpLjets__220->GetZaxis()->SetTickLength(0.025);
   h_nJet_WpLjets__220->GetZaxis()->SetTitleFont(42);
   h->Add(h_nJet_W+jets,"");
   
   TH1D *h_nJet_TopsPoPLFcP__221 = new TH1D("h_nJet_TopsPoPLFcP__221","",9,-0.5,8.5);
   h_nJet_TopsPoPLFcP__221->SetBinContent(2,0.008309954);
   h_nJet_TopsPoPLFcP__221->SetBinContent(3,0.04226496);
   h_nJet_TopsPoPLFcP__221->SetBinContent(4,0.08832035);
   h_nJet_TopsPoPLFcP__221->SetBinContent(5,0.08533392);
   h_nJet_TopsPoPLFcP__221->SetBinContent(6,0.05734558);
   h_nJet_TopsPoPLFcP__221->SetBinContent(7,0.02841211);
   h_nJet_TopsPoPLFcP__221->SetBinContent(8,0.01180029);
   h_nJet_TopsPoPLFcP__221->SetBinContent(9,0.006291982);
   h_nJet_TopsPoPLFcP__221->SetBinError(2,0.0003851356);
   h_nJet_TopsPoPLFcP__221->SetBinError(3,0.0007306422);
   h_nJet_TopsPoPLFcP__221->SetBinError(4,0.001088888);
   h_nJet_TopsPoPLFcP__221->SetBinError(5,0.0009551542);
   h_nJet_TopsPoPLFcP__221->SetBinError(6,0.0007663072);
   h_nJet_TopsPoPLFcP__221->SetBinError(7,0.0005284013);
   h_nJet_TopsPoPLFcP__221->SetBinError(8,0.0003199885);
   h_nJet_TopsPoPLFcP__221->SetBinError(9,0.0002275074);
   h_nJet_TopsPoPLFcP__221->SetEntries(45754);
   h_nJet_TopsPoPLFcP__221->SetStats(0);

   ci = TColor::GetColor("#cc33cc");
   h_nJet_TopsPoPLFcP__221->SetFillColor(ci);
   h_nJet_TopsPoPLFcP__221->GetXaxis()->SetTitle("N_{jet}");
   h_nJet_TopsPoPLFcP__221->GetXaxis()->SetLabelFont(42);
   h_nJet_TopsPoPLFcP__221->GetXaxis()->SetLabelOffset(0.007);
   h_nJet_TopsPoPLFcP__221->GetXaxis()->SetTitleSize(0.05);
   h_nJet_TopsPoPLFcP__221->GetXaxis()->SetTickLength(0.025);
   h_nJet_TopsPoPLFcP__221->GetXaxis()->SetTitleFont(42);
   h_nJet_TopsPoPLFcP__221->GetYaxis()->SetTitle("a.u.");
   h_nJet_TopsPoPLFcP__221->GetYaxis()->SetLabelFont(42);
   h_nJet_TopsPoPLFcP__221->GetYaxis()->SetLabelOffset(0.007);
   h_nJet_TopsPoPLFcP__221->GetYaxis()->SetTitleSize(0.05);
   h_nJet_TopsPoPLFcP__221->GetYaxis()->SetTickLength(0.025);
   h_nJet_TopsPoPLFcP__221->GetYaxis()->SetTitleFont(42);
   h_nJet_TopsPoPLFcP__221->GetZaxis()->SetLabelFont(42);
   h_nJet_TopsPoPLFcP__221->GetZaxis()->SetLabelOffset(0.007);
   h_nJet_TopsPoPLFcP__221->GetZaxis()->SetTitleSize(0.05);
   h_nJet_TopsPoPLFcP__221->GetZaxis()->SetTickLength(0.025);
   h_nJet_TopsPoPLFcP__221->GetZaxis()->SetTitleFont(42);
   h->Add(h_nJet_Top (LF),"");
   
   TH1D *h_nJet_TopsPoPHFcP__222 = new TH1D("h_nJet_TopsPoPHFcP__222","",9,-0.5,8.5);
   h_nJet_TopsPoPHFcP__222->SetBinContent(2,0.07376031);
   h_nJet_TopsPoPHFcP__222->SetBinContent(3,0.1364258);
   h_nJet_TopsPoPHFcP__222->SetBinContent(4,0.1333122);
   h_nJet_TopsPoPHFcP__222->SetBinContent(5,0.09566011);
   h_nJet_TopsPoPHFcP__222->SetBinContent(6,0.05315604);
   h_nJet_TopsPoPHFcP__222->SetBinContent(7,0.02411419);
   h_nJet_TopsPoPHFcP__222->SetBinContent(8,0.009464359);
   h_nJet_TopsPoPHFcP__222->SetBinContent(9,0.004552595);
   h_nJet_TopsPoPHFcP__222->SetBinError(2,0.00103096);
   h_nJet_TopsPoPHFcP__222->SetBinError(3,0.001340864);
   h_nJet_TopsPoPHFcP__222->SetBinError(4,0.001254557);
   h_nJet_TopsPoPHFcP__222->SetBinError(5,0.001028784);
   h_nJet_TopsPoPHFcP__222->SetBinError(6,0.0007477547);
   h_nJet_TopsPoPHFcP__222->SetBinError(7,0.0004712842);
   h_nJet_TopsPoPHFcP__222->SetBinError(8,0.0003185909);
   h_nJet_TopsPoPHFcP__222->SetBinError(9,0.0001812819);
   h_nJet_TopsPoPHFcP__222->SetEntries(77950);
   h_nJet_TopsPoPHFcP__222->SetStats(0);

   ci = TColor::GetColor("#ff9900");
   h_nJet_TopsPoPHFcP__222->SetFillColor(ci);
   h_nJet_TopsPoPHFcP__222->GetXaxis()->SetTitle("N_{jet}");
   h_nJet_TopsPoPHFcP__222->GetXaxis()->SetLabelFont(42);
   h_nJet_TopsPoPHFcP__222->GetXaxis()->SetLabelOffset(0.007);
   h_nJet_TopsPoPHFcP__222->GetXaxis()->SetTitleSize(0.05);
   h_nJet_TopsPoPHFcP__222->GetXaxis()->SetTickLength(0.025);
   h_nJet_TopsPoPHFcP__222->GetXaxis()->SetTitleFont(42);
   h_nJet_TopsPoPHFcP__222->GetYaxis()->SetTitle("a.u.");
   h_nJet_TopsPoPHFcP__222->GetYaxis()->SetLabelFont(42);
   h_nJet_TopsPoPHFcP__222->GetYaxis()->SetLabelOffset(0.007);
   h_nJet_TopsPoPHFcP__222->GetYaxis()->SetTitleSize(0.05);
   h_nJet_TopsPoPHFcP__222->GetYaxis()->SetTickLength(0.025);
   h_nJet_TopsPoPHFcP__222->GetYaxis()->SetTitleFont(42);
   h_nJet_TopsPoPHFcP__222->GetZaxis()->SetLabelFont(42);
   h_nJet_TopsPoPHFcP__222->GetZaxis()->SetLabelOffset(0.007);
   h_nJet_TopsPoPHFcP__222->GetZaxis()->SetTitleSize(0.05);
   h_nJet_TopsPoPHFcP__222->GetZaxis()->SetTickLength(0.025);
   h_nJet_TopsPoPHFcP__222->GetZaxis()->SetTitleFont(42);
   h->Add(h_nJet_Top (HF),"");
   h->Draw("hist");
   
   TH1D *hsum__223 = new TH1D("hsum__223","",9,-0.5,8.5);
   hsum__223->SetBinContent(2,0.1150639);
   hsum__223->SetBinContent(3,0.2235937);
   hsum__223->SetBinContent(4,0.2603543);
   hsum__223->SetBinContent(5,0.196954);
   hsum__223->SetBinContent(6,0.1166518);
   hsum__223->SetBinContent(7,0.05449491);
   hsum__223->SetBinContent(8,0.0217334);
   hsum__223->SetBinContent(9,0.01115394);
   hsum__223->SetBinError(2,0.002522403);
   hsum__223->SetBinError(3,0.002525467);
   hsum__223->SetBinError(4,0.00336047);
   hsum__223->SetBinError(5,0.001966634);
   hsum__223->SetBinError(6,0.00127208);
   hsum__223->SetBinError(7,0.0007378717);
   hsum__223->SetBinError(8,0.0004530571);
   hsum__223->SetBinError(9,0.0003235352);
   hsum__223->SetEntries(43);
   hsum__223->SetStats(0);

   ci = 1198;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   hsum__223->SetFillColor(ci);
   hsum__223->SetFillStyle(3003);
   hsum__223->SetLineWidth(0);
   hsum__223->GetXaxis()->SetTitle("N_{jet}");
   hsum__223->GetXaxis()->SetLabelFont(42);
   hsum__223->GetXaxis()->SetLabelOffset(0.007);
   hsum__223->GetXaxis()->SetTitleSize(0.05);
   hsum__223->GetXaxis()->SetTickLength(0.025);
   hsum__223->GetXaxis()->SetTitleFont(42);
   hsum__223->GetYaxis()->SetTitle("a.u.");
   hsum__223->GetYaxis()->SetLabelFont(42);
   hsum__223->GetYaxis()->SetLabelOffset(0.007);
   hsum__223->GetYaxis()->SetTitleSize(0.05);
   hsum__223->GetYaxis()->SetTickLength(0.025);
   hsum__223->GetYaxis()->SetTitleFont(42);
   hsum__223->GetZaxis()->SetLabelFont(42);
   hsum__223->GetZaxis()->SetLabelOffset(0.007);
   hsum__223->GetZaxis()->SetTitleSize(0.05);
   hsum__223->GetZaxis()->SetTickLength(0.025);
   hsum__223->GetZaxis()->SetTitleFont(42);
   hsum__223->Draw("e2 same");
   
   TH1D *h_nJet_Data__224 = new TH1D("h_nJet_Data__224","",9,-0.5,8.5);
   h_nJet_Data__224->SetBinContent(2,0.1095355);
   h_nJet_Data__224->SetBinContent(3,0.2408367);
   h_nJet_Data__224->SetBinContent(4,0.2713182);
   h_nJet_Data__224->SetBinContent(5,0.1982945);
   h_nJet_Data__224->SetBinContent(6,0.1091115);
   h_nJet_Data__224->SetBinContent(7,0.04494488);
   h_nJet_Data__224->SetBinContent(8,0.017243);
   h_nJet_Data__224->SetBinContent(9,0.008715726);
   h_nJet_Data__224->SetBinError(2,0.00227166);
   h_nJet_Data__224->SetBinError(3,0.003368428);
   h_nJet_Data__224->SetBinError(4,0.003575241);
   h_nJet_Data__224->SetBinError(5,0.003056478);
   h_nJet_Data__224->SetBinError(6,0.002267259);
   h_nJet_Data__224->SetBinError(7,0.001455144);
   h_nJet_Data__224->SetBinError(8,0.0009013063);
   h_nJet_Data__224->SetBinError(9,0.0006407929);
   h_nJet_Data__224->SetEntries(21226);
   h_nJet_Data__224->SetStats(0);
   h_nJet_Data__224->SetLineWidth(3);
   h_nJet_Data__224->SetMarkerStyle(20);
   h_nJet_Data__224->SetMarkerSize(2);
   h_nJet_Data__224->GetXaxis()->SetTitle("N_{jet}");
   h_nJet_Data__224->GetXaxis()->SetLabelFont(42);
   h_nJet_Data__224->GetXaxis()->SetLabelOffset(0.007);
   h_nJet_Data__224->GetXaxis()->SetTitleSize(0.05);
   h_nJet_Data__224->GetXaxis()->SetTickLength(0.025);
   h_nJet_Data__224->GetXaxis()->SetTitleFont(42);
   h_nJet_Data__224->GetYaxis()->SetTitle("a.u.");
   h_nJet_Data__224->GetYaxis()->SetLabelFont(42);
   h_nJet_Data__224->GetYaxis()->SetLabelOffset(0.007);
   h_nJet_Data__224->GetYaxis()->SetTitleSize(0.05);
   h_nJet_Data__224->GetYaxis()->SetTickLength(0.025);
   h_nJet_Data__224->GetYaxis()->SetTitleFont(42);
   h_nJet_Data__224->GetZaxis()->SetLabelFont(42);
   h_nJet_Data__224->GetZaxis()->SetLabelOffset(0.007);
   h_nJet_Data__224->GetZaxis()->SetTitleSize(0.05);
   h_nJet_Data__224->GetZaxis()->SetTickLength(0.025);
   h_nJet_Data__224->GetZaxis()->SetTitleFont(42);
   h_nJet_Data__224->Draw("elp same");
   
   TLegend *leg = new TLegend(0.6,0.55,0.88,0.9,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   TLegendEntry *entry=leg->AddEntry("h_nJet_Data","Data","ELP");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(3);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(2);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_Top (HF)","Top (HF)","F");

   ci = TColor::GetColor("#ff9900");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_Top (LF)","Top (LF)","F");

   ci = TColor::GetColor("#cc33cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_W+jets","W+jets","F");

   ci = TColor::GetColor("#66cc66");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_Z+jets","Z+jets","F");

   ci = TColor::GetColor("#3399cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_Diboson","Diboson","F");

   ci = TColor::GetColor("#9966cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_QCD","QCD","F");

   ci = TColor::GetColor("#cccccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   
   leg = new TLegend(0.6,0.55,0.88,0.9,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   entry=leg->AddEntry("h_nJet_Data","Data","ELP");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(3);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(2);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_Top (HF)","Top (HF)","F");

   ci = TColor::GetColor("#ff9900");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_Top (LF)","Top (LF)","F");

   ci = TColor::GetColor("#cc33cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_W+jets","W+jets","F");

   ci = TColor::GetColor("#66cc66");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_Z+jets","Z+jets","F");

   ci = TColor::GetColor("#3399cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_Diboson","Diboson","F");

   ci = TColor::GetColor("#9966cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_nJet_QCD","QCD","F");

   ci = TColor::GetColor("#cccccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   TLatex *   tex = new TLatex(0.18,0.85,"CMS");
tex->SetNDC();
   tex->SetTextSize(0.06);
   tex->SetLineWidth(2);
   tex->Draw();
      tex = new TLatex(0.28,0.85,"Preliminary");
tex->SetNDC();
   tex->SetTextFont(52);
   tex->SetTextSize(0.06);
   tex->SetLineWidth(2);
   tex->Draw();
      tex = new TLatex(0.9,0.94,"36.6 fb^{-1} (13 TeV)");
tex->SetNDC();
   tex->SetTextAlign(31);
   tex->SetTextFont(42);
   tex->SetTextSize(0.04);
   tex->SetLineWidth(2);
   tex->Draw();
   pad1->Modified();
   c1->cd();
  
// ------------>Primitives in pad: pad2
   TPad *pad2 = new TPad("pad2", "pad2",0,0.05,1,0.3);
   pad2->Draw();
   pad2->cd();
   pad2->Range(-2.1875,-0.8914286,9.0625,0.48);
   pad2->SetFillColor(0);
   pad2->SetBorderMode(0);
   pad2->SetBorderSize(2);
   pad2->SetGridy();
   pad2->SetTickx(1);
   pad2->SetTicky(1);
   pad2->SetLeftMargin(0.15);
   pad2->SetRightMargin(0.05);
   pad2->SetTopMargin(0);
   pad2->SetBottomMargin(0.3);
   pad2->SetFrameFillStyle(0);
   pad2->SetFrameBorderMode(0);
   pad2->SetFrameFillStyle(0);
   pad2->SetFrameBorderMode(0);
   
   TH1D *ratio__225 = new TH1D("ratio__225","",9,-0.5,8.5);
   ratio__225->SetBinContent(1,-999);
   ratio__225->SetBinContent(2,-0.04804683);
   ratio__225->SetBinContent(3,0.07711744);
   ratio__225->SetBinContent(4,0.0421114);
   ratio__225->SetBinContent(5,0.006806612);
   ratio__225->SetBinContent(6,-0.06463963);
   ratio__225->SetBinContent(7,-0.1752464);
   ratio__225->SetBinContent(8,-0.2066128);
   ratio__225->SetBinContent(9,-0.2185969);
   ratio__225->SetBinError(1,0.0001);
   ratio__225->SetBinError(2,0.0001);
   ratio__225->SetBinError(3,0.0001);
   ratio__225->SetBinError(4,0.0001);
   ratio__225->SetBinError(5,0.0001);
   ratio__225->SetBinError(6,0.0001);
   ratio__225->SetBinError(7,0.0001);
   ratio__225->SetBinError(8,0.0001);
   ratio__225->SetBinError(9,0.0001);
   ratio__225->SetMinimum(-0.48);
   ratio__225->SetMaximum(0.48);
   ratio__225->SetEntries(21235);
   ratio__225->SetStats(0);
   ratio__225->SetLineWidth(3);
   ratio__225->SetMarkerStyle(20);
   ratio__225->SetMarkerSize(2);
   ratio__225->GetXaxis()->SetTitle("N_{jet}");
   ratio__225->GetXaxis()->SetLabelFont(43);
   ratio__225->GetXaxis()->SetLabelOffset(0.007);
   ratio__225->GetXaxis()->SetLabelSize(30);
   ratio__225->GetXaxis()->SetTitleSize(40);
   ratio__225->GetXaxis()->SetTickLength(0.025);
   ratio__225->GetXaxis()->SetTitleOffset(5);
   ratio__225->GetXaxis()->SetTitleFont(43);
   ratio__225->GetYaxis()->SetTitle("#frac{Data-Exp}{Exp}");
   ratio__225->GetYaxis()->SetNdivisions(5);
   ratio__225->GetYaxis()->SetLabelFont(43);
   ratio__225->GetYaxis()->SetLabelOffset(0.007);
   ratio__225->GetYaxis()->SetLabelSize(30);
   ratio__225->GetYaxis()->SetTitleSize(40);
   ratio__225->GetYaxis()->SetTickLength(0.025);
   ratio__225->GetYaxis()->SetTitleOffset(2.5);
   ratio__225->GetYaxis()->SetTitleFont(43);
   ratio__225->GetZaxis()->SetLabelFont(42);
   ratio__225->GetZaxis()->SetLabelOffset(0.007);
   ratio__225->GetZaxis()->SetTitleSize(0.05);
   ratio__225->GetZaxis()->SetTickLength(0.025);
   ratio__225->GetZaxis()->SetTitleFont(42);
   ratio__225->Draw("elp");
   
   TH1D *zero__226 = new TH1D("zero__226","",9,-0.5,8.5);
   zero__226->SetBinError(2,0.00227166);
   zero__226->SetBinError(3,0.003368428);
   zero__226->SetBinError(4,0.003575241);
   zero__226->SetBinError(5,0.003056478);
   zero__226->SetBinError(6,0.002267259);
   zero__226->SetBinError(7,0.001455144);
   zero__226->SetBinError(8,0.0009013063);
   zero__226->SetBinError(9,0.0006407929);
   zero__226->SetEntries(21235);
   zero__226->SetStats(0);
   zero__226->SetLineWidth(3);
   zero__226->SetMarkerStyle(20);
   zero__226->SetMarkerSize(2);
   zero__226->GetXaxis()->SetTitle("N_{jet}");
   zero__226->GetXaxis()->SetLabelFont(42);
   zero__226->GetXaxis()->SetLabelOffset(0.007);
   zero__226->GetXaxis()->SetTitleSize(0.05);
   zero__226->GetXaxis()->SetTickLength(0.025);
   zero__226->GetXaxis()->SetTitleFont(42);
   zero__226->GetYaxis()->SetTitle("a.u.");
   zero__226->GetYaxis()->SetLabelFont(42);
   zero__226->GetYaxis()->SetLabelOffset(0.007);
   zero__226->GetYaxis()->SetTitleSize(0.05);
   zero__226->GetYaxis()->SetTickLength(0.025);
   zero__226->GetYaxis()->SetTitleFont(42);
   zero__226->GetZaxis()->SetLabelFont(42);
   zero__226->GetZaxis()->SetLabelOffset(0.007);
   zero__226->GetZaxis()->SetTitleSize(0.05);
   zero__226->GetZaxis()->SetTickLength(0.025);
   zero__226->GetZaxis()->SetTitleFont(42);
   zero__226->Draw("hist same");
   
   TH1D *sumratioup__227 = new TH1D("sumratioup__227","",9,-0.5,8.5);
   sumratioup__227->SetBinContent(2,0.02192175);
   sumratioup__227->SetBinContent(3,0.01129489);
   sumratioup__227->SetBinContent(4,0.0129073);
   sumratioup__227->SetBinContent(5,0.009985248);
   sumratioup__227->SetBinContent(6,0.01090493);
   sumratioup__227->SetBinContent(7,0.01354019);
   sumratioup__227->SetBinContent(8,0.02084612);
   sumratioup__227->SetBinContent(9,0.02900635);
   sumratioup__227->SetBinError(2,0.002522403);
   sumratioup__227->SetBinError(3,0.002525467);
   sumratioup__227->SetBinError(4,0.00336047);
   sumratioup__227->SetBinError(5,0.001966634);
   sumratioup__227->SetBinError(6,0.00127208);
   sumratioup__227->SetBinError(7,0.0007378717);
   sumratioup__227->SetBinError(8,0.0004530571);
   sumratioup__227->SetBinError(9,0.0003235352);
   sumratioup__227->SetEntries(52);
   sumratioup__227->SetStats(0);

   ci = 1198;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   sumratioup__227->SetFillColor(ci);
   sumratioup__227->SetFillStyle(3003);
   sumratioup__227->GetXaxis()->SetTitle("N_{jet}");
   sumratioup__227->GetXaxis()->SetLabelFont(42);
   sumratioup__227->GetXaxis()->SetLabelOffset(0.007);
   sumratioup__227->GetXaxis()->SetTitleSize(0.05);
   sumratioup__227->GetXaxis()->SetTickLength(0.025);
   sumratioup__227->GetXaxis()->SetTitleFont(42);
   sumratioup__227->GetYaxis()->SetTitle("a.u.");
   sumratioup__227->GetYaxis()->SetLabelFont(42);
   sumratioup__227->GetYaxis()->SetLabelOffset(0.007);
   sumratioup__227->GetYaxis()->SetTitleSize(0.05);
   sumratioup__227->GetYaxis()->SetTickLength(0.025);
   sumratioup__227->GetYaxis()->SetTitleFont(42);
   sumratioup__227->GetZaxis()->SetLabelFont(42);
   sumratioup__227->GetZaxis()->SetLabelOffset(0.007);
   sumratioup__227->GetZaxis()->SetTitleSize(0.05);
   sumratioup__227->GetZaxis()->SetTickLength(0.025);
   sumratioup__227->GetZaxis()->SetTitleFont(42);
   sumratioup__227->Draw("hist same");
   
   TH1D *sumratiodown__228 = new TH1D("sumratiodown__228","",9,-0.5,8.5);
   sumratiodown__228->SetBinContent(2,-0.02192175);
   sumratiodown__228->SetBinContent(3,-0.01129489);
   sumratiodown__228->SetBinContent(4,-0.0129073);
   sumratiodown__228->SetBinContent(5,-0.009985248);
   sumratiodown__228->SetBinContent(6,-0.01090493);
   sumratiodown__228->SetBinContent(7,-0.01354019);
   sumratiodown__228->SetBinContent(8,-0.02084612);
   sumratiodown__228->SetBinContent(9,-0.02900635);
   sumratiodown__228->SetBinError(2,0.002522403);
   sumratiodown__228->SetBinError(3,0.002525467);
   sumratiodown__228->SetBinError(4,0.00336047);
   sumratiodown__228->SetBinError(5,0.001966634);
   sumratiodown__228->SetBinError(6,0.00127208);
   sumratiodown__228->SetBinError(7,0.0007378717);
   sumratiodown__228->SetBinError(8,0.0004530571);
   sumratiodown__228->SetBinError(9,0.0003235352);
   sumratiodown__228->SetEntries(52);
   sumratiodown__228->SetStats(0);

   ci = 1198;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   sumratiodown__228->SetFillColor(ci);
   sumratiodown__228->SetFillStyle(3003);
   sumratiodown__228->GetXaxis()->SetTitle("N_{jet}");
   sumratiodown__228->GetXaxis()->SetLabelFont(42);
   sumratiodown__228->GetXaxis()->SetLabelOffset(0.007);
   sumratiodown__228->GetXaxis()->SetTitleSize(0.05);
   sumratiodown__228->GetXaxis()->SetTickLength(0.025);
   sumratiodown__228->GetXaxis()->SetTitleFont(42);
   sumratiodown__228->GetYaxis()->SetTitle("a.u.");
   sumratiodown__228->GetYaxis()->SetLabelFont(42);
   sumratiodown__228->GetYaxis()->SetLabelOffset(0.007);
   sumratiodown__228->GetYaxis()->SetTitleSize(0.05);
   sumratiodown__228->GetYaxis()->SetTickLength(0.025);
   sumratiodown__228->GetYaxis()->SetTitleFont(42);
   sumratiodown__228->GetZaxis()->SetLabelFont(42);
   sumratiodown__228->GetZaxis()->SetLabelOffset(0.007);
   sumratiodown__228->GetZaxis()->SetTitleSize(0.05);
   sumratiodown__228->GetZaxis()->SetTickLength(0.025);
   sumratiodown__228->GetZaxis()->SetTitleFont(42);
   sumratiodown__228->Draw("hist same");
   
   Double_t Graph0_fx1019[9] = {
   0,
   1,
   2,
   3,
   4,
   5,
   6,
   7,
   8};
   Double_t Graph0_fy1019[9] = {
   -999,
   -0.04804683,
   0.07711744,
   0.0421114,
   0.006806612,
   -0.06463963,
   -0.1752464,
   -0.2066128,
   -0.2185969};
   Double_t Graph0_fex1019[9] = {
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0};
   Double_t Graph0_fey1019[9] = {
   0,
   0.01974259,
   0.01506495,
   0.01373222,
   0.01551874,
   0.01943612,
   0.02670239,
   0.04147102,
   0.0574499};
   TGraphErrors *gre = new TGraphErrors(9,Graph0_fx1019,Graph0_fy1019,Graph0_fex1019,Graph0_fey1019);
   gre->SetName("Graph0");
   gre->SetTitle("Graph");
   gre->SetFillColor(1);
   gre->SetLineWidth(3);
   
   TH1F *Graph_Graph1019 = new TH1F("Graph_Graph1019","Graph",100,0,8.8);
   Graph_Graph1019->SetMinimum(-1098.909);
   Graph_Graph1019->SetMaximum(100.0014);
   Graph_Graph1019->SetDirectory(0);
   Graph_Graph1019->SetStats(0);

   ci = TColor::GetColor("#000099");
   Graph_Graph1019->SetLineColor(ci);
   Graph_Graph1019->GetXaxis()->SetLabelFont(42);
   Graph_Graph1019->GetXaxis()->SetLabelOffset(0.007);
   Graph_Graph1019->GetXaxis()->SetTitleSize(0.05);
   Graph_Graph1019->GetXaxis()->SetTickLength(0.025);
   Graph_Graph1019->GetXaxis()->SetTitleFont(42);
   Graph_Graph1019->GetYaxis()->SetLabelFont(42);
   Graph_Graph1019->GetYaxis()->SetLabelOffset(0.007);
   Graph_Graph1019->GetYaxis()->SetTitleSize(0.05);
   Graph_Graph1019->GetYaxis()->SetTickLength(0.025);
   Graph_Graph1019->GetYaxis()->SetTitleFont(42);
   Graph_Graph1019->GetZaxis()->SetLabelFont(42);
   Graph_Graph1019->GetZaxis()->SetLabelOffset(0.007);
   Graph_Graph1019->GetZaxis()->SetTitleSize(0.05);
   Graph_Graph1019->GetZaxis()->SetTickLength(0.025);
   Graph_Graph1019->GetZaxis()->SetTitleFont(42);
   gre->SetHistogram(Graph_Graph1019);
   
   gre->Draw("pe0");
   pad2->Modified();
   c1->cd();
   c1->Modified();
   c1->cd();
   c1->SetSelected(c1);
}
void macro_MakeQcdClosureTest()
{
  // parameters //////////////////////////////////////////////////////////////
  //TFile input("./emuSpec_19619pb-1.root", "open");
  TFile input("test_19619pb-1.root", "open");
  input.cd();

  TParameter<float> *lumi = (TParameter<float> *)input.Get("lumi");

  const int nBins = 75;
  const bool usePu = 1;
  const bool useWeight = 1;
  const int qcdEst = 1; // estimation method of QCD contribution. none(0), from SS spectrum(1), from fake rate(2)

  int eRegion = 2; // electron region EB(0), EE(1), EB+EE(2)

  bool plotSign[3];
  plotSign[0] = 1;  // all
  plotSign[1] = 1;  // SS same sign
  plotSign[2] = 1;  // OS opposite sign

  bool plotType[2];
  plotType[0] = 1;  // emu spectrum
  plotType[1] = 1;  // cumulative emu spectrum

  const bool plotPull = 0; // plot (data-bkg)/bkg
  const bool plotPullBelowSpec = 0; // plot (data-bkg)/bkg below spectrum
  const bool logPlotX = 0;
  const bool logPlotY = 1;
  const bool prelim = 1;
  const bool groupedPlot = 0;
  const bool overflowBin = 1;

  float xRangeMin = 60.;
  float xRangeMax = 1200.;
  //float xRangeMin = 0.;
  //float xRangeMax = 1500.;
  float yRangeMin[6] = {0.002, 0.002, 0.002, 0.4, 0.4, 0.4};
  float yRangeMax[6] = {30, 10, 30, 3000, 1000, 3000};
  float yRangeMinRatio[3] = {-0.7, -0.7, -0.7};
  float yRangeMaxRatio[3] = {0.7, 0.7, 0.7};
  float fitMin = xRangeMin;
  float fitMax = 1100.; // set to highest bin with a data point
  float xRangeMinRatio = fitMin;
  float xRangeMaxRatio = fitMax;

  // output file formats
  const bool savePull = 0;
  const bool saveSpec = 0;
  const bool saveCumSpec = 0;
  const bool saveAsPdf = 0;
  const bool saveAsPng = 1;
  const bool saveAsRoot = 0;
  const char *fileNameExtra = "";
  //const char *fileNameExtra = "madgraphTTbar_";
  const char *plotDir = "./plottemp/";

  // plot style
  int wjetColour=  TColor::GetColor("#ffd324");
  int jetBkgColour = TColor::GetColor("#ffff66"); 

  int font = 42; //62
  ////////////////////////////////////////////////////////////////////////////

  // systematic errors
  float systErrLumi = ((TParameter<float> *)input.Get("systErrLumi"))->GetVal();
  systErrLumi = 0.; // since we normalize to the Z peak
  float systErrEff = ((TParameter<float> *)input.Get("systErrEff"))->GetVal(); // muon err & ele err
  THashList *systErrMCs = (THashList *)input.Get("systErrMCs");
  vector<float> systErrMC;
  systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcTtbar"))->GetVal());  // NNLO ttbar
  //systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcTtbar700to1000"))->GetVal());  // NLO ttbar700to1000
  //systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcTtbar1000up"))->GetVal());  // NLO ttbar1000up
  systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcDyTauTau"))->GetVal()); //z->tt
  systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcWW"))->GetVal()); //WW
  systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcWZ"))->GetVal()); //WZ
  systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcZZ"))->GetVal()); //ZZ
  systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcTW"))->GetVal()); //tW
  systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcDyMuMu"))->GetVal()); //Z->mm
  systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcDyEE"))->GetVal()); //Z->ee
  if (qcdEst == 2) systErrMC.push_back(0.4); // qcd error
  else systErrMC.push_back(((TParameter<float> *)systErrMCs->FindObject("systErrMcWJets"))->GetVal());  //WJets

  // to keep the histogram when the file is closed
  TH1::AddDirectory(kFALSE);
  TH1::SetDefaultSumw2(kTRUE);

  TString histoSign[3] = {"", "SS_", "OS_"};
  TString xAxisTitle[3] = {"m(e#mu)", "m(e^{#pm}#mu^{#pm})", "m(e^{#pm}#mu^{#mp})"};
  TString nameSuffix[2] = {"", "cumul"};
  TString titleSuffix[2] = {"", " - Cumulative"};

  vector<TH1F *> emuMass_wjets;
  vector<TH1F *> emuMass_qcd;
  vector<TH1F *> emuMass_qcdFromFake;

  // define the binning
  vector<float> binning;
  if (logPlotX) {
    //for (float bin = 0.; bin < 100.; bin += 5.)
    //  binning.push_back(bin);
    for (float bin = 0.; bin < 200.; bin += 10.)
      binning.push_back(bin);
    for (float bin = 200.; bin < 400.; bin += 20.)
      binning.push_back(bin);
    for (float bin = 400.; bin < 500.; bin += 25.)
      binning.push_back(bin);
    for (float bin = 500.; bin <= 620.; bin += 40.)
      binning.push_back(bin);
      binning.push_back(670.);
      binning.push_back(720.);
      binning.push_back(780.);
      binning.push_back(840.);
      binning.push_back(920.);
      binning.push_back(1000.);
      binning.push_back(1100.);
      binning.push_back(1220.);
      binning.push_back(1380.);
      binning.push_back(1500.);
  } else {
    //for (float bin = 0.; bin <= 1500.; bin += 20.)
    //  binning.push_back(bin);
    for (float bin = 0.; bin < 200.; bin += 20.)
      binning.push_back(bin);
    for (float bin = 200.; bin < 400.; bin += 40.)
      binning.push_back(bin);
    for (float bin = 400.; bin < 700.; bin += 50.)
      binning.push_back(bin);
    for (float bin = 700.; bin < 1000.; bin += 75.)
      binning.push_back(bin);
    for (float bin = 1000.; bin < 1200.; bin += 100.)
      binning.push_back(bin);
    for (float bin = 1200.; bin <= 1500.; bin += 150.)
      binning.push_back(bin);
  }

  THashList *mcWeights = (THashList *)input.Get("mcWeights");
  TParameter<float> *mcWeight = (TParameter<float> *)mcWeights->FindObject("ttbar");
  TParameter<float> *mcWeight700to1000 = (TParameter<float> *)mcWeights->FindObject("ttbar700to1000");
  TParameter<float> *mcWeight1000up = (TParameter<float> *)mcWeights->FindObject("ttbar1000up");

  float totMcWeight = 1.;
  // determine qcd contribution
  TH1F *qcdContrib;
  TH1F *ssData = MakeHistoFromBranch(&input, "emuTree_data", "mass", SS, eRegion, "", 0., 0., binning, 0x100);
  TH1F *ssBg = MakeHistoFromBranch(&input, "emuTree_ttbar", "mass", SS, eRegion, "genMTtbar", 0., 700., binning, 0x1DF);
  totMcWeight = 1. / (1 / mcWeight->GetVal() + 1 / mcWeight700to1000->GetVal());
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ttbar", "mass", SS, eRegion, "genMTtbar", 700., 1000., binning, 0x19F), totMcWeight);
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ttbar700to1000", "mass", SS, eRegion, "genMTtbar", 700., 1000., binning, 0x19F), totMcWeight);
  totMcWeight = 1. / (1 / mcWeight->GetVal() + 1 / mcWeight1000up->GetVal());
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ttbar", "mass", SS, eRegion, "genMTtbar", 1000., 1000000000., binning, 0x19F), totMcWeight);
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ttbar1000up", "mass", SS, eRegion, "genMTtbar", 1000., 1000000000., binning, 0x19F), totMcWeight);
  //TH1F *ssBg = MakeHistoFromBranch(&input, "emuTree_ttbar", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF);
  //TH1F *ssBg = MakeHistoFromBranch(&input, "emuTree_ttbarto2l", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF);
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ztautau", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF));
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_ww", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF));
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_wz", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF));
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_zz", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF));
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_tw", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF));
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_zmumu", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF));
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_zee", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF));
  ssBg->Add(MakeHistoFromBranch(&input, "emuTree_wjets", "mass", SS, eRegion, "", 0., 0., binning, 0x1DF));
  qcdContrib = (TH1F *)ssData->Clone("qcdContrib_SS");
  qcdContrib->Add(ssBg, -1);
  for (int i = 0; i < qcdContrib->GetNbinsX() + 2; ++i) {
    if (qcdContrib->GetBinContent(i) < 0) qcdContrib->SetBinContent(i, 0.);
  }
  cout << "expected SS QCD events: " << ssData->Integral() - ssBg->Integral() << endl;
  cout << "derived SS QCD events: " << qcdContrib->Integral() << endl;
  cout << "scale factor: " << (ssData->Integral() - ssBg->Integral()) / qcdContrib->Integral()<< endl;
  qcdContrib->Scale((ssData->Integral() - ssBg->Integral()) / qcdContrib->Integral());

  // loop over full spectrum, SS and OS
  for (int k = 0; k < 3; ++k) {
    // loop to get normal and cumulated spectrum
    for (unsigned int j = 0; j < 2; ++j) {
      input.cd();

      bool normToBin = true;
      if (j > 0) normToBin = false;

      if (k == 2) k = -1;
      // make the histograms
      emuMass_wjets.push_back(MakeHistoFromBranch(&input, "emuTree_wjets", "mass", k, eRegion, "", 0., 0., binning, 0x1DF, normToBin));
      if (k == -1) k = 2;
      emuMass_wjets.back()->SetName("emuMass_" + histoSign[k] + "wjets" + nameSuffix[j]);

      // qcd contribution
      if (k == 2) k = -1;
      emuMass_qcdFromFake.push_back((TH1F *)MakeHistoFromBranch(&input, "frEmuTree_data", "mass", k, eRegion, "", 0., 0., binning, 0x300));
      emuMass_qcd.push_back((TH1F *)qcdContrib->Clone("emuMass_" + histoSign[k] + "qcd"));
      if (k == ALL) emuMass_qcd.back()->Scale(2.);
      // normalize to bin width
      if (j < 1) {
        for (int i = 1; i < emuMass_qcd.back()->GetNbinsX() + 1; ++i) {
          emuMass_qcd.back()->SetBinContent(i, emuMass_qcd.back()->GetBinContent(i) / emuMass_qcd.back()->GetBinWidth(i));
          emuMass_qcd.back()->SetBinError(i, emuMass_qcd.back()->GetBinError(i) / emuMass_qcd.back()->GetBinWidth(i));
          emuMass_qcdFromFake.back()->SetBinContent(i, emuMass_qcdFromFake.back()->GetBinContent(i) / emuMass_qcdFromFake.back()->GetBinWidth(i));
          emuMass_qcdFromFake.back()->SetBinError(i, emuMass_qcdFromFake.back()->GetBinError(i) / emuMass_qcdFromFake.back()->GetBinWidth(i));
        }
      }
      if (k == -1) k = 2;

      // add overflow in last bin
      if (j == 0 && overflowBin) {
        emuMass_wjets.back()->SetBinContent(emuMass_wjets.back()->GetNbinsX(), emuMass_wjets.back()->GetBinContent(emuMass_wjets.back()->GetNbinsX()) + emuMass_wjets.back()->GetBinContent(emuMass_wjets.back()->GetNbinsX() + 1));
        emuMass_qcd.back()->SetBinContent(emuMass_qcd.back()->GetNbinsX(), emuMass_qcd.back()->GetBinContent(emuMass_qcd.back()->GetNbinsX()) + emuMass_qcd.back()->GetBinContent(emuMass_qcd.back()->GetNbinsX() + 1));
        emuMass_qcdFromFake.back()->SetBinContent(emuMass_qcdFromFake.back()->GetNbinsX(), emuMass_qcdFromFake.back()->GetBinContent(emuMass_qcdFromFake.back()->GetNbinsX()) + emuMass_qcdFromFake.back()->GetBinContent(emuMass_qcdFromFake.back()->GetNbinsX() + 1));
      }

      // integrate from the right side
      if (j == 1) { 
        // loop over bins
        double error;
        for (int i = 1; i < nBins + 1; ++i) {
          emuMass_wjets.back()->SetBinContent(i, emuMass_wjets.back()->IntegralAndError(i, nBins, error));
          emuMass_wjets.back()->SetBinError(i, error);
          emuMass_qcd.back()->SetBinContent(i, emuMass_qcd.back()->IntegralAndError(i, nBins, error));
          emuMass_qcd.back()->SetBinError(i, error);
          emuMass_qcdFromFake.back()->SetBinContent(i, emuMass_qcdFromFake.back()->IntegralAndError(i, nBins, error));
          emuMass_qcdFromFake.back()->SetBinError(i, error);
        }     
      }

      if (!plotSign[k]) continue;
      if (!plotType[j]) continue;

      TCanvas *emuPlot;
      TPad *specPad;
      if (plotPullBelowSpec && j == 0) {
        emuPlot = new TCanvas("emuPlot" + histoSign[k] + nameSuffix[j], "emu Spectrum" + titleSuffix[j], 100, 100, 900, 900);
        specPad = new TPad("specPad" + histoSign[k] + nameSuffix[j], "emu Spectrum" + titleSuffix[j], 0., 0.33, 1., 1.);
        specPad->SetBottomMargin(0.06);
      } else {
        emuPlot = new TCanvas("emuPlot" + histoSign[k] + nameSuffix[j], "emu Spectrum" + titleSuffix[j], 100, 100, 900, 600);
        specPad = new TPad("specPad" + histoSign[k] + nameSuffix[j], "emu Spectrum" + titleSuffix[j], 0., 0., 1., 1.);
        specPad->SetBottomMargin(0.12);
      }
      specPad->SetBorderMode(0);
      specPad->SetBorderSize(2);
      specPad->SetFrameBorderMode(0);
      specPad->SetFillColor(0);
      specPad->SetFrameFillColor(0);
      if (logPlotX) specPad->SetLogx();
      if (logPlotY) specPad->SetLogy();
      specPad->SetLeftMargin(0.11);
      specPad->SetRightMargin(0.09);
      specPad->SetTopMargin(0.08);
      specPad->SetTickx(1);
      specPad->SetTicky(1);
      specPad->Draw();
      specPad->cd();
 
      gStyle->SetTitleFont(font);
      gStyle->SetLabelFont(font);
      gStyle->SetLegendFont(font);
      gStyle->SetOptStat(0);
      gStyle->SetOptTitle(0);
      gStyle->SetTitleXOffset(1.);
      gStyle->SetTitleYOffset(1.3);
      gPad->SetTicks(1, 1);

      // make a histogram stack with the bg 
      THStack *bgStack = new THStack("bgStack" + histoSign[k] + nameSuffix[j], "Invariant Mass" + titleSuffix[j]);
      bgStack->Add(emuMass_qcd.back());
      bgStack->Add(emuMass_wjets.back());

      // plot spectrum
      emuMass_wjets.back()->SetFillColor(wjetColour);
      emuMass_wjets.back()->SetMarkerColor(wjetColour);
      emuMass_wjets.back()->SetLineColor(kBlack);
      emuMass_wjets.back()->SetLineWidth(2);
      //emuMass_wjets.back()->Draw("HISTsames");
      emuMass_qcd.back()->SetFillColor(jetBkgColour);
      emuMass_qcd.back()->SetMarkerColor(jetBkgColour);
      emuMass_qcd.back()->SetLineColor(kBlack);
      emuMass_qcd.back()->SetLineWidth(2);
      //emuMass_qcd.back()->Draw("HISTsames");
      bgStack->Draw("hist");
      emuMass_qcdFromFake.back()->SetLineColor(kRed);
      emuMass_qcdFromFake.back()->SetLineWidth(2);
      emuMass_qcdFromFake.back()->Draw("esame");

      if (plotPullBelowSpec && j == 0) {
        bgStack->GetXaxis()->SetTitle("");
      } else {
        bgStack->GetXaxis()->SetTitle(xAxisTitle[k] + " [GeV]");
      }
      bgStack->GetXaxis()->SetTitleFont(font);
      bgStack->GetXaxis()->SetTitleSize(0.047);
      bgStack->GetXaxis()->SetTitleOffset(0.9);
      bgStack->GetXaxis()->SetLabelFont(font);
      bgStack->GetXaxis()->SetLabelSize(0.05);
      bgStack->GetXaxis()->SetMoreLogLabels();
      bgStack->GetXaxis()->SetNoExponent();
      //bgStack->GetXaxis()->SetRangeUser(xRangeMin, xRangeMax); 
      bgStack->GetXaxis()->SetLimits(xRangeMin, xRangeMax); 
      if (j == 1) bgStack->GetYaxis()->SetTitle("Events #geq " + xAxisTitle[k]);
      else bgStack->GetYaxis()->SetTitle("Events / GeV");
      bgStack->GetYaxis()->SetTitleFont(font);
      bgStack->GetYaxis()->SetTitleSize(0.047);
      bgStack->GetYaxis()->SetTitleOffset(1.1);
      bgStack->GetYaxis()->SetLabelFont(font);
      bgStack->GetYaxis()->SetLabelSize(0.05);
      bgStack->SetMinimum(yRangeMin[k + j * 3]); 
      bgStack->SetMaximum(yRangeMax[k + j * 3]); 

      // redraw axis
      emuMass_qcd.back()->Draw("sameaxis");

      // legend and labels
      TLegend legend(0.710, 0.646, 0.901, 0.885);
      legend.SetTextFont(font);
      legend.SetTextSize(0.03);
      legend.SetBorderSize(0);
      legend.SetLineColor(1);
      legend.SetLineStyle(1);
      legend.SetLineWidth(1);
      legend.SetFillColor(19);
      legend.SetFillStyle(0);
      legend.AddEntry(emuMass_wjets.back(), "W+jets (MC)" ,"F");
      legend.AddEntry(emuMass_qcd.back(), "jets (SS data)" ,"F");
      legend.AddEntry(emuMass_qcdFromFake.back(), "jets (Fake Rate)" ,"le");
      legend.DrawClone("sames");
      
      TLatex *tex = new TLatex();
      tex->SetNDC();
      tex->SetTextFont(font);
      tex->SetLineWidth(2);
      tex->SetTextSize(0.042);
      if (prelim) tex->DrawLatex(0.325, 0.853, "CMS Preliminary, 8 TeV, 19.6 fb^{-1}");
      else tex->DrawLatex(0.405, 0.853, "CMS, 8 TeV, 19.6 fb^{-1}");
      if (eRegion == 0) tex->DrawLatex(0.325, 0.775, "e in barrel");
      if (eRegion == 1) tex->DrawLatex(0.325, 0.775, "e in endcap");

      // safe in various file formats
      stringstream sStream;
      if (!plotPullBelowSpec || j > 0) {
        sStream << plotDir << "qcdClosureTestSpec";
        if (k == 0) sStream << "_";
        sStream << histoSign[k];
        if (eRegion == 0) sStream << "EB_";
        if (eRegion == 1) sStream << "EE_";
        sStream << fileNameExtra << nameSuffix[j];
        if (j > 0) sStream << "_";
        if (groupedPlot) sStream << "grouped_";
        if (!logPlotY) sStream << "lin_";
        sStream << lumi->GetVal() << "pb-1";
        TString saveFileName = sStream.str();
        if ((j == 0 && saveSpec) || (j > 0 && saveCumSpec)) {
          if (saveAsPdf) emuPlot->Print(saveFileName + ".pdf", "pdf");
          if (saveAsPng) emuPlot->Print(saveFileName + ".png", "png");
          if (saveAsRoot) emuPlot->Print(saveFileName + ".root", "root");
        }
      }
    } // end loop over normal or cumulated
  } // end loop over full, SS and OS

  // generate one object containing everything
  vector<vector<TH1F *> > emuMasses;
  emuMasses.push_back(emuMass_wjets);
  emuMasses.push_back(emuMass_qcd);

//  // define groups of MC samples
//  vector<bool> ttLikeSamples(6, true);
//  vector<bool> contamSamples(6, false);
//  contamSamples.push_back(true); // Zmm
//  contamSamples.push_back(true); // Zee
//  contamSamples.push_back(true); // WJets or QCD
//  vector<bool> contamSamplesNoQcd(contamSamples);
//  vector<bool> allSamples(9, true);
//  vector<bool> onlyQCD(emuMasses.size() - 1, false);
//  if (qcdEst > 0) {
//    onlyQCD.back() = true;
//    if (qcdEst != 2) {
//      allSamples.push_back(true);
//      contamSamples.push_back(true);
//      contamSamplesNoQcd.push_back(false);
//      systErrMC.push_back(0.); // QCD error will be calculated later
//    } else {
//      contamSamplesNoQcd.back() = false;
//    }
//  }
//  vector<bool> allSamplesNoQcd(allSamples);
//  if (qcdEst > 0) allSamplesNoQcd.back() = false;
//  unsigned int qcdInd = onlyQCD.size();
//  unsigned int qcdErrInd = qcdInd - 1;
//
//  // calculate rate of syst errors
//  float systErrLuEff = sqrt(systErrLumi*systErrLumi + systErrEff*systErrEff);
//  vector<float> systErrMCLuEff;
//  for (unsigned int it = 0; it < systErrMC.size(); ++it)
//     systErrMCLuEff.push_back(sqrt(systErrMC[it]*systErrMC[it] + systErrLuEff*systErrLuEff));
//
//  bool calcQcdErr = false;
//  if (qcdEst == 1) calcQcdErr = true;
//
//  //cout << "qcdInd " << qcdInd << ", emuMasses.size() " << emuMasses.size() << ", systErrMC.size() " << systErrMC.size() 
//  //     << ", systErrMCLuEff.size() " << systErrMCLuEff.size() << ", allSamples.size() " << allSamples.size() 
//  //     << ", allSamplesNoQcd.size() " << allSamplesNoQcd.size() << ", contamSamplesNoQcd.size() " << contamSamplesNoQcd.size() 
//  //     << ", contamSamples.size() " << contamSamples.size() << ", onlyQCD.size() " << onlyQCD.size() << endl;
//  //for (unsigned int sIt = 0; sIt < emuMasses.size() - 1; ++sIt) {
//  //   cout << "allSamples " << allSamples[sIt] << ", allSamplesNoQcd " << allSamplesNoQcd[sIt] 
//  //        << ", contamSamples " << contamSamples[sIt] << ", contamSamplesNoQcd " << contamSamplesNoQcd[sIt] 
//  //        << ", onlyQCD " << onlyQCD[sIt] << ", systErrMC " << systErrMC[sIt] << ", systErrMCLuEff " << systErrMCLuEff[sIt] << endl;
//  //}
//
//  // define special bins corresponding to specific masses
//  int bin60 = emuMass_data.at(ALL)->FindBin(60.);
//  int bin120 = emuMass_data.at(ALL)->FindBin(120.);
//  int bin200 = emuMass_data.at(ALL)->FindBin(200.); 
//  int bin400 = emuMass_data.at(ALL)->FindBin(400.); 
//  int bin500 = emuMass_data.at(ALL)->FindBin(500.); 
//
//  vector<const char *> sampleNames;
//  sampleNames.push_back("data   ");
//  sampleNames.push_back("ttbar  ");
//  sampleNames.push_back("Ztautau");
//  sampleNames.push_back("WW     ");
//  sampleNames.push_back("WZ     ");
//  sampleNames.push_back("ZZ     ");
//  sampleNames.push_back("tW     ");
//  sampleNames.push_back("Zmumu  ");
//  sampleNames.push_back("Zee    ");
//  if (qcdEst != 2) sampleNames.push_back("WJets  ");
//  if (qcdEst > 0) sampleNames.push_back("QCD    ");
//
//  // write numbers
//  cout << endl;
//  cout << "-----------------------------------------------------------------------------------------------------------" << endl;
//  cout << "HEEP - TIGHT MU        Lumi        = " << lumi->GetVal() << "pb-1" << endl;
//  //cout << "                       e pT EB     > " << bar_et << "GeV/c" << endl;
//  //cout << "                       e pT EE     > " << end_et << "GeV/c" << endl;
//  //cout << "                       mu pT       > " << muon_et << "GeV/c" << endl;
//  //cout << "                       mu |eta|    < " << muon_etaMax << endl;
//  cout << endl;
//  cout << "Systematic errors" << endl;
//  cout << " Luminosity:  " << systErrLumi * 100 << "%" << endl;
//  cout << " Efficiency:  " << systErrEff * 100 << "%" << endl;
//  cout << " ttbar:       " << systErrMC[TTBAR-1] * 100 << "%" << endl;
//  cout << " Z->tautau:   " << systErrMC[ZTT-1] * 100 << "%" << endl;
//  cout << " WW:          " << systErrMC[WW-1] * 100 << "%" << endl;
//  cout << " WZ:          " << systErrMC[WZ-1] * 100 << "%" << endl;
//  cout << " ZZ:          " << systErrMC[ZZ-1] * 100 << "%" << endl;
//  cout << " tW, tbarW:   " << systErrMC[TW-1] * 100 << "%" << endl;
//  cout << " Z->mumu:     " << systErrMC[ZMM-1] * 100 << "%" << endl;
//  cout << " Z->ee:       " << systErrMC[ZEE-1] * 100 << "%" << endl;
//  if (qcdEst != 2) cout << " W+Jets:      " << systErrMC[WJET-1] * 100 << "%" << endl;
//  else cout << " QCD:        " << systErrMC.back() * 100 << "%" << endl;
//  cout << "-----------------------------------------------------------------------------------------------------------" << endl;
//  for (unsigned int signIt = 1; signIt < 6; signIt += 2) {
//    if (signIt == 3) cout << "-SS--------------------------------------------------------------------------------------------------------" << endl;
//    if (signIt == 5) cout << "-OS--------------------------------------------------------------------------------------------------------" << endl;
//    cout << "-----------------------------------------------------------------------------------------------------------------------------------------" << endl;
//    cout << "M_emu         |         >  60GeV/c^2          |        > 120GeV/c^2          |        > 200GeV/c^2         |        > 400GeV/c^2          |" << endl;
//    cout << "-----------------------------------------------------------------------------------------------------------------------------------------" << endl;
//  
//    printf("nb data       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       |\n", 
//           emuMass_data.at(signIt)->GetBinContent(bin60), sqrt(emuMass_data.at(signIt)->GetBinContent(bin60)),         
//           emuMass_data.at(signIt)->GetBinContent(bin120), sqrt(emuMass_data.at(signIt)->GetBinContent(bin120)),
//           emuMass_data.at(signIt)->GetBinContent(bin200), sqrt(emuMass_data.at(signIt)->GetBinContent(bin200)),
//           emuMass_data.at(signIt)->GetBinContent(bin400), sqrt(emuMass_data.at(signIt)->GetBinContent(bin400)));
//    cout << "----------------------------------------------------------------------------------------------------------------------------------------" << endl;
//    for (unsigned int sampleIt = 1; sampleIt < sampleNames.size(); ++sampleIt) {
//      if (sampleIt == 7) cout << "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" << endl;
//      if (qcdEst == 1 && sampleIt == sampleNames.size() - 1) {
//        printf("nb %7s    | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", sampleNames[sampleIt],
//               emuMass_qcd.at(signIt)->GetBinContent(bin60), emuMass_qcd.at(signIt)->GetBinContent(bin60) * CalcSSQcdErr(emuMasses, systErrMCLuEff, bin60), 
//               emuMass_qcd.at(signIt)->GetBinContent(bin120), emuMass_qcd.at(signIt)->GetBinContent(bin120) * CalcSSQcdErr(emuMasses, systErrMCLuEff, bin120), 
//               emuMass_qcd.at(signIt)->GetBinContent(bin200), emuMass_qcd.at(signIt)->GetBinContent(bin200) * CalcSSQcdErr(emuMasses, systErrMCLuEff, bin200),
//               emuMass_qcd.at(signIt)->GetBinContent(bin400), emuMass_qcd.at(signIt)->GetBinContent(bin400) * CalcSSQcdErr(emuMasses, systErrMCLuEff, bin400));
//      } else {
//        printf("nb %7s    | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n", sampleNames[sampleIt],
//               emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin60), emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin60) * systErrMCLuEff[sampleIt-1], 
//               emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin120), emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin120) * systErrMCLuEff[sampleIt-1], 
//               emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin200), emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin200) * systErrMCLuEff[sampleIt-1],
//               emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin400), emuMasses.at(sampleIt).at(signIt)->GetBinContent(bin400) * systErrMCLuEff[sampleIt-1]);
//      }
//    }
//    cout << endl;
//    cout << "----------------------------------------------------------------------------------------------------------------------------------------" << endl;
//    printf("TOT ttlike    | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n",
//           CalcBgSum(emuMasses, ttLikeSamples, signIt, bin60), CalcSystErr(emuMasses, systErrMCLuEff, ttLikeSamples, signIt, bin60),
//           CalcBgSum(emuMasses, ttLikeSamples, signIt, bin120), CalcSystErr(emuMasses, systErrMCLuEff, ttLikeSamples, signIt, bin120),
//           CalcBgSum(emuMasses, ttLikeSamples, signIt, bin200), CalcSystErr(emuMasses, systErrMCLuEff, ttLikeSamples, signIt, bin200),
//           CalcBgSum(emuMasses, ttLikeSamples, signIt, bin400), CalcSystErr(emuMasses, systErrMCLuEff, ttLikeSamples, signIt, bin400));
//    printf("TOT contam    | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n",
//           CalcBgSum(emuMasses, contamSamples, signIt, bin60), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, contamSamples, signIt, bin60, -1, calcQcdErr),
//           CalcBgSum(emuMasses, contamSamples, signIt, bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, contamSamples, signIt, bin120, -1, calcQcdErr),
//           CalcBgSum(emuMasses, contamSamples, signIt, bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, contamSamples, signIt, bin200, -1, calcQcdErr),
//           CalcBgSum(emuMasses, contamSamples, signIt, bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, contamSamples, signIt, bin400, -1, calcQcdErr));
//    cout << "----------------------------------------------------------------------------------------------------------------------------------------" << endl;
//  
//    printf("TOT Bkg       | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n",
//           CalcBgSum(emuMasses, allSamples, signIt, bin60), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin60, -1, calcQcdErr),
//           CalcBgSum(emuMasses, allSamples, signIt, bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin120, -1, calcQcdErr),
//           CalcBgSum(emuMasses, allSamples, signIt, bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin200, -1, calcQcdErr),
//           CalcBgSum(emuMasses, allSamples, signIt, bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin400, -1, calcQcdErr));
//    cout << "----------------------------------------------------------------------------------------------------------------------------------------" << endl;
//    cout << endl << endl;
//  }
//  cout << endl;
//
//  cout << "--Without adding QCD contribution:--------------------------------------------------------------------------------------------------------" << endl;
//  cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl;
//  cout << "M_emu         |         > 60GeV/c^2          |        > 120GeV/c^2          |         > 200GeV/c^2         |         > 400GeV/c^2         |" << endl;
//  cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl;
//  for (unsigned int signIt = 1; signIt < 6; signIt += 2) {
//    if (signIt == 3) cout << "-SS-------------------------------------------------------------------------------------------------------------------------------------" << endl;
//    if (signIt == 5) cout << "-OS-------------------------------------------------------------------------------------------------------------------------------------" << endl;
//    printf("nb data       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)        |\n",
//           emuMasses.at(DATA).at(signIt)->GetBinContent(bin60), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin60)),
//           emuMasses.at(DATA).at(signIt)->GetBinContent(bin120), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin120)),
//           emuMasses.at(DATA).at(signIt)->GetBinContent(bin200), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin200)),
//           emuMasses.at(DATA).at(signIt)->GetBinContent(bin400), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin400)));
//    printf("nb MC         | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n",
//           CalcBgSum(emuMasses, allSamplesNoQcd, signIt, bin60), CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, signIt, bin60),
//           CalcBgSum(emuMasses, allSamplesNoQcd, signIt, bin120), CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, signIt, bin120),
//           CalcBgSum(emuMasses, allSamplesNoQcd, signIt, bin200), CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, signIt, bin200),
//           CalcBgSum(emuMasses, allSamplesNoQcd, signIt, bin400), CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, signIt, bin400));
//  }
//  cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl;
//
//  if (qcdEst == 1) {
//    //systErrMC.back() = 2 * sqrt(emuMasses.at(DATA).at(SS)->Integral() + pow(CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, SS, 1), 2)) / emuMasses.at(qcdInd).at(ALL)->Integral();
//    //systErrMC.back() = CalcSystErr(emuMasses, systErrMCLuEff, allSamplesNoQcd, SSCUM, 1) / emuMass_qcd.at(SSCUM)->GetBinContent(1);
//    //systErrMCLuEff.back() = systErrMC[qcdErrInd];
//
//    cout << endl;
//      cout << "---QCD events from SS spectrum:----------------------------------------------------------------------------------------------------------------------------------" << endl;
//      cout << "-----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
//      printf("nb QCD SS+OS  | %9.3f +- %8.3f (%.1f%%) (syst) | %9.3f +- %8.3f (%.1f%%) (syst) | %9.3f +- %8.3f (%.1f%%) (syst) | %9.3f +- %8.3f (%.1f%%) (syst) |\n",
//             emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin60), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin60, -1, calcQcdErr), 
//             100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin60, -1, calcQcdErr) / emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin60),
//             emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin120, -1, calcQcdErr), 
//             100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin120, -1, calcQcdErr) / emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin120),
//             emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin200, -1, calcQcdErr), 
//             100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin200, -1, calcQcdErr) / emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin200),
//             emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin400, -1, calcQcdErr), 
//             100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin400, -1, calcQcdErr) / emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin400));
//      printf("%% of total MC |  %7.3f%% +- %7.3f%% (syst)         |  %7.3f%% +- %7.3f%% (syst)         |  %7.3f%% +- %7.3f%% (syst)         |  %7.3f%% +- %7.3f%% (syst)         |\n",
//             100 * emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin60) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin60), 
//             100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin60, -1, calcQcdErr) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin60),
//             100 * emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin120) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin120), 
//             100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin120, -1, calcQcdErr) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin120),
//             100 * emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin200) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin200), 
//             100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin200, -1, calcQcdErr) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin200),
//             100 * emuMasses.at(qcdInd).at(ALLCUM)->GetBinContent(bin400) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin400), 
//             100 * CalcSystErrWithQCD(emuMasses, systErrMCLuEff, onlyQCD, ALLCUM, bin400, -1, calcQcdErr) / CalcBgSum(emuMasses, allSamplesNoQcd, ALLCUM, bin400));
//      cout << "-----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
//  }
//
//  // top up bg contribution with qcd
//  if (qcdEst > 0) {
//    cout << endl;
//    cout << "--After adding QCD contribution:----------------------------------------------------------------------------------------------------------" << endl;
//    cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl;
//    cout << "M_emu         |         > 60GeV/c^2          |        > 120GeV/c^2          |         > 200GeV/c^2         |         > 400GeV/c^2         |" << endl;
//    cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl;
//    for (unsigned int signIt = 1; signIt < 6; signIt += 2) {
//      if (signIt == 3) cout << "-SS-------------------------------------------------------------------------------------------------------------------------------------" << endl;
//      if (signIt == 5) cout << "-OS-------------------------------------------------------------------------------------------------------------------------------------" << endl;
//      printf("nb data       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)        |\n",
//              emuMasses.at(DATA).at(signIt)->GetBinContent(bin60), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin60)),
//              emuMasses.at(DATA).at(signIt)->GetBinContent(bin120), sqrt((emuMasses.at(DATA).at(signIt))->GetBinContent(bin120)),
//              emuMasses.at(DATA).at(signIt)->GetBinContent(bin200), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin200)),
//              emuMasses.at(DATA).at(signIt)->GetBinContent(bin400), sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin400)));
//      printf("nb MC         | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n",
//              CalcBgSum(emuMasses, allSamples, signIt, bin60), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin60, -1, calcQcdErr),
//              CalcBgSum(emuMasses, allSamples, signIt, bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin120, -1, calcQcdErr),
//              CalcBgSum(emuMasses, allSamples, signIt, bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin200, -1, calcQcdErr),
//              CalcBgSum(emuMasses, allSamples, signIt, bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin400, -1, calcQcdErr));
//    }
//    cout << "------------------------------------------------------------------------------------------------------------------------------------------" << endl;
//  }
//
//  cout << endl;
//  cout << "-----------------------------------------------------------------------------------------------------------" << endl;
//  cout << "M_emu         |        60 - 120GeV/c^2       |      120 - 200GeV/c^2        |       200 - 400GeV/c^2       |" << endl;
//  cout << "-----------------------------------------------------------------------------------------------------------" << endl;
//  for (unsigned int signIt = 1; signIt < 6; signIt += 2) {
//    printf("nb data       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       | %5.0f +- %-.3f (stat)       |\n",
//            emuMasses.at(DATA).at(signIt)->GetBinContent(bin60) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin120), 
//            sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin60) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin120)),
//            emuMasses.at(DATA).at(signIt)->GetBinContent(bin120) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin200), 
//            sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin120) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin200)),
//            emuMasses.at(DATA).at(signIt)->GetBinContent(bin200) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin400), 
//            sqrt(emuMasses.at(DATA).at(signIt)->GetBinContent(bin200) - emuMasses.at(DATA).at(signIt)->GetBinContent(bin400)));
//    printf("nb MC         | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) | %9.3f +- %8.3f (syst) |\n",
//            CalcBgSum(emuMasses, allSamples, signIt, bin60, bin120), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin60, bin120, calcQcdErr),
//            CalcBgSum(emuMasses, allSamples, signIt, bin120, bin200), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin120, bin200, calcQcdErr),
//            CalcBgSum(emuMasses, allSamples, signIt, bin200, bin400), CalcSystErrWithQCD(emuMasses, systErrMCLuEff, allSamples, signIt, bin200, bin400, calcQcdErr));
//    cout << "-----------------------------------------------------------------------------------------------------------" << endl;
//  }
}
void allCutFlow(){
setTDRStyle();
gROOT->SetBatch();

//stuff to choose
bool logPlot = true; //true for log plot

TString Cut = "EventCount/";

TString Nbtags = "";
TString Obj = "";
TString RefSelection = "";
TString Type = "";
TString Next = "";
int RebinFact = 1;

TString Systematic = "central/";

//TString Variable = "TTbarMuMuRefSelection"; 
//TString Variable = "TTbarMuMuRefSelectionUnweighted";
//TString Variable = "TTbarEERefSelection";  
//TString Variable = "TTbarEERefSelectionUnweighted";
TString Variable = "TTbarEMuRefSelection"; 
//TString Variable = "TTbarEMuRefSelectionUnweighted";

 
TString Xtitle = "Cuts";

//if( Variable == "TTbarMuMuRefSelection" || Variable == "TTbarEERefSelection" )
//TString step[10] = {"Skim" ,"Cleaning and HLT","Di-lepton Sel", "m(Z) veto", "#geq 1 jet", "#geq 2 jets", "#slash{E_{T}} cut", "#geq1 CSV b-tag", "#geq1 Good Photon" , "1 Good Photon"};
//TString step_latex[10] = {"Skim" ,"Cleaning and HLT","Di-lepton Sel", "m(Z) veto", "$\\geq$ 1 jets", "$\\geq$ 2 jets", "$\\slash{E_{T}}$ cut", "$\\geq$ 1 CSV b-tag", "$\\geq$ 1 Good Photon" , "1 Good Photon"};
//if( Variable == "TTbarEMuRefSelection" )
TString step[8] = {"Skim" ,"Cleaning and HLT","Di-lepton Sel", "#geq 1 jets", "#geq 2 jets", "#geq1 CSV b-tag", "#geq1 Good Photon", "1 Good Photon" };		
TString step_latex[8] = {"Skim" ,"Cleaning and HLT","Di-lepton Sel", "$\\geq$ 1 jets", "$\\geq$ 2 jets", "$\\geq$ 1 CSV b-tag", "$\\geq$ 1 Good Photon" , "1 Good Photon"};


//Data
if( Variable == "TTbarMuMuRefSelection" || Variable == "TTbarMuMuRefSelectionUnweighted" )
TH1D* data = getSample("DoubleMu", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
if( Variable == "TTbarEERefSelection" || Variable == "TTbarEERefSelectionUnweighted" )
TH1D* data = getSample("DoubleElectron", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
if( Variable == "TTbarEMuRefSelection" || Variable == "TTbarEMuRefSelectionUnweighted" )
TH1D* data = getSample("MuEG", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);

//MC
TH1D* ttgamma = getSample("TTGamma", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* tt = getSample("TTJet", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* wjets = getSample("WJetsToLNu", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* DY1 = getSample("DYJetsToLL_M-10To50", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* DY2 = getSample("DYJetsToLL_M-50", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* T_tW = getSample("T_tW-channel", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* Tbar_tW = getSample("Tbar_tW-channel",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* ZZ = getSample("ZZtoAnything",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* WW = getSample("WWtoAnything",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* WZ = getSample("WZtoAnything",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);

//QCD
TH1D* QCD_Pt_20_30_BCtoE = getSample("QCD_Pt_20_30_BCtoE",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* QCD_Pt_20_30_EMEnriched = getSample("QCD_Pt_20_30_EMEnriched",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* QCD_Pt_20_MuEnrichedPt_15 = getSample("QCD_Pt_20_MuEnrichedPt_15",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* QCD_Pt_30_80_BCtoE = getSample("QCD_Pt_30_80_BCtoE",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* QCD_Pt_30_80_EMEnriched = getSample("QCD_Pt_30_80_EMEnriched",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* QCD_Pt_80_170_BCtoE = getSample("QCD_Pt_80_170_BCtoE",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
TH1D* QCD_Pt_80_170_EMEnriched = getSample("QCD_Pt_80_170_EMEnriched",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);

TH1D* QCD_all = getSample("QCD_Pt_20_MuEnrichedPt_15",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
  QCD_all->Add(QCD_Pt_20_30_BCtoE);
  QCD_all->Add(QCD_Pt_20_30_EMEnriched);
  QCD_all->Add(QCD_Pt_30_80_BCtoE);
  QCD_all->Add(QCD_Pt_30_80_EMEnriched);
  QCD_all->Add(QCD_Pt_80_170_BCtoE);
  QCD_all->Add(QCD_Pt_80_170_EMEnriched);
  
TH1D* DY = getSample("DYJetsToLL_M-10To50", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
  DY->Add(DY2);
  
TH1D* Diboson = getSample("ZZtoAnything",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
  Diboson->Add(WW);
  Diboson->Add(WZ);
  
TH1D* SingleTop = getSample("T_tW-channel", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut);
  SingleTop->Add(Tbar_tW); 
 
cout << "got samples" << endl;

THStack *hs = new THStack("hs","test");

  hs->Add(QCD_all);
  hs->Add(wjets);
  hs->Add(WZ); 
  hs->Add(WW);
  hs->Add(ZZ);
  hs->Add(DY1);
  hs->Add(DY2);
  hs->Add(T_tW); 
  hs->Add(Tbar_tW);
  hs->Add(tt);
  hs->Add(ttgamma);
  

TH1D* allMC = (TH1D*)ttgamma->Clone("ratio");
  allMC->Add(tt);
  allMC->Add(wjets);
  allMC->Add(DY1);
  allMC->Add(DY2);
  allMC->Add(T_tW);
  allMC->Add(Tbar_tW);
  allMC->Add(ZZ);
  allMC->Add(WW);
  allMC->Add(WZ);
  allMC->Add(QCD_all);
  
TH1D* dataEff = new TH1D("data eff","data eff",9,0,9);
TH1D* mcEff = new TH1D("mc eff","mc eff",9,0,9);

mcEff->Sumw2();
dataEff->Sumw2();

for(int q =1; q<ttgamma->GetNbinsX(); q++){
mcEff->GetXaxis()->SetBinLabel(q, step[q]);
dataEff->SetBinContent(q, data->GetBinContent(q+1)/data->GetBinContent(q));
dataEff->SetBinError(q, dataEff->GetBinContent(q)*sqrt(pow(data->GetBinError(q+1)/data->GetBinContent(q+1),2)+pow(data->GetBinError(q)/data->GetBinContent(q),2)));
mcEff->SetBinContent(q, allMC->GetBinContent(q+1)/allMC->GetBinContent(q));

}  

	
	TCanvas *c2 = new TCanvas("cutflow eff","cutflow eff",600, 500);
  	
	mcEff->SetLineColor(kRed);
	mcEff->Draw();
	dataEff->Draw("Esame");
	
	TLegend *tleg3;
	tleg3 = new TLegend(0.7,0.7,0.8,0.9);
	tleg3->SetTextSize(0.04);
	tleg3->SetBorderSize(0);
	tleg3->SetFillColor(10);
	tleg3->AddEntry(dataEff , "data", "l");
	tleg3->AddEntry(mcEff , "mc", "l");
	
	tleg3->Draw("same");
	
	c2->SaveAs("plots/cutFlow/cutEff_"+Variable+".pdf");
	c2->SaveAs("plots/cutFlow/cutEff_"+Variable+".png");
	delete c2;

  //draw histos to files
  TCanvas *c1 = new TCanvas("cutflow","cutflow",900, 600);

  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);
  
  if(logPlot ==true)
  hs->SetMinimum(10.);

  hs->Draw("hist");
  
  for(int q =0; q<ttgamma->GetNbinsX(); q++)
  hs->GetXaxis()->SetBinLabel(q+1, step[q]);
  
  data->Draw("E same");
  data->SetMarkerStyle(20);
  
//  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.7,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(ttgamma , "t#bar{t}+gamma", "lf");
	tleg2->AddEntry(tt , "t#bar{t}", "lf");
	tleg2->AddEntry(T_tW, "single top", "lf");
	tleg2->AddEntry(DY1 , "Drell-Yan", "lf");
	tleg2->AddEntry(ZZ , "Di-boson", "lf");
	tleg2->AddEntry(wjets , "w+jets", "lf");
	tleg2->AddEntry(QCD_all , "QCD", "lf");
	
	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	
	
	TText* textstuff = dostuff(0.22,0.96, Variable);
	textstuff->Draw();
	
  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("plots/cutFlow/");
  
  if(logPlot ==true){
    plotName += Variable+"_Log";
    plotName += Nbtags;
    
  }else{
    plotName += Variable+"";  
    plotName += Nbtags;
  }
 
 
  c1->SaveAs(plotName+".png");
  c1->SaveAs(plotName+".pdf");
  delete c1;
 
 //print out
 
    std::cout.setf(std::ios::fixed);
    std::cout.precision(0);

 cout << "& ttgamma & ttbar & single-t  & wjets & zjets & diboson & qcd & all MC & data  \\\\" << endl; 
 
 for(int q = 0; q < ttgamma->GetNbinsX(); q++){
 cout << step_latex[q] << " & " << ttgamma->GetBinContent(q+1) << " $\\pm$ " << ttgamma->GetBinError(q+1)  << " & " <<
 tt->GetBinContent(q+1) << " $\\pm$ " << tt->GetBinError(q+1)  << " & " << SingleTop->GetBinContent(q+1) << " $\\pm$ " <<
 SingleTop->GetBinError(q+1)  << " & " << DY->GetBinContent(q+1) << " $\\pm$ " << DY->GetBinError(q+1)  << " & " <<
 Diboson->GetBinContent(q+1) << " $\\pm$ " << Diboson->GetBinError(q+1)  << " & "<< wjets->GetBinContent(q+1) << " $\\pm$ "
 << wjets->GetBinError(q+1)  << " & " << QCD_all->GetBinContent(q+1) << " $\\pm$ " << QCD_all->GetBinError(q+1)  << " & " <<
 allMC->GetBinContent(q+1) << " $\\pm$ " << allMC->GetBinError(q+1)  << " & " << data->GetBinContent(q+1) << " $\\pm$ " <<
 data->GetBinError(q+1) << " \\\\ " << endl;
 
 }

// for(int r = 0; r < ttgamma->GetNbinsX(); r++){
// std::cout << ttgamma->GetBinContent(r+1) << std::endl;
// }
  	
}
Exemple #15
0
void ttbar_jet1CSV()
{
//=========Macro generated from canvas: c1/c1
//=========  (Sun Dec 11 15:16:19 2016) by ROOT version6.06/01
   TCanvas *c1 = new TCanvas("c1", "c1",1,1,1200,1416);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   c1->SetHighLightColor(2);
   c1->Range(0,0,1,1);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   c1->SetTickx(1);
   c1->SetTicky(1);
   c1->SetLeftMargin(0.15);
   c1->SetRightMargin(0.05);
   c1->SetTopMargin(0.07);
   c1->SetBottomMargin(0.13);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
  
// ------------>Primitives in pad: pad1
   TPad *pad1 = new TPad("pad1", "pad1",0,0.3,1,1);
   pad1->Draw();
   pad1->cd();
   pad1->Range(-0.1875,0,1.0625,0.5424993);
   pad1->SetFillColor(0);
   pad1->SetBorderMode(0);
   pad1->SetBorderSize(2);
   pad1->SetTickx(1);
   pad1->SetTicky(1);
   pad1->SetLeftMargin(0.15);
   pad1->SetRightMargin(0.05);
   pad1->SetTopMargin(0.07);
   pad1->SetBottomMargin(0);
   pad1->SetFrameFillStyle(0);
   pad1->SetFrameBorderMode(0);
   pad1->SetFrameFillStyle(0);
   pad1->SetFrameBorderMode(0);
   
   THStack *h = new THStack();
   h->SetName("h");
   h->SetTitle("");
   h->SetMinimum(0);
   h->SetMaximum(0.4804993);
   
   TH1F *h_stack_21 = new TH1F("h_stack_21","",10,0,1);
   h_stack_21->SetMinimum(0);
   h_stack_21->SetMaximum(0.5045243);
   h_stack_21->SetDirectory(0);
   h_stack_21->SetStats(0);

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha
   ci = TColor::GetColor("#000099");
   h_stack_21->SetLineColor(ci);
   h_stack_21->GetXaxis()->SetLabelFont(42);
   h_stack_21->GetXaxis()->SetLabelOffset(0.007);
   h_stack_21->GetXaxis()->SetTitleSize(0.05);
   h_stack_21->GetXaxis()->SetTickLength(0.025);
   h_stack_21->GetXaxis()->SetTitleFont(42);
   h_stack_21->GetYaxis()->SetTitle("a.u.");
   h_stack_21->GetYaxis()->SetLabelFont(42);
   h_stack_21->GetYaxis()->SetLabelOffset(0.007);
   h_stack_21->GetYaxis()->SetTitleSize(0.05);
   h_stack_21->GetYaxis()->SetTickLength(0.025);
   h_stack_21->GetYaxis()->SetTitleOffset(1.5);
   h_stack_21->GetYaxis()->SetTitleFont(42);
   h_stack_21->GetZaxis()->SetLabelFont(42);
   h_stack_21->GetZaxis()->SetLabelOffset(0.007);
   h_stack_21->GetZaxis()->SetTitleSize(0.05);
   h_stack_21->GetZaxis()->SetTickLength(0.025);
   h_stack_21->GetZaxis()->SetTitleFont(42);
   h->SetHistogram(h_stack_21);
   
   
   TH1D *h_jet1CSV_QCD__241 = new TH1D("h_jet1CSV_QCD__241","",10,0,1);
   h_jet1CSV_QCD__241->SetBinContent(1,0.001669958);
   h_jet1CSV_QCD__241->SetBinContent(2,0.001297151);
   h_jet1CSV_QCD__241->SetBinContent(3,0.0001985037);
   h_jet1CSV_QCD__241->SetBinContent(4,0.001317617);
   h_jet1CSV_QCD__241->SetBinContent(5,0.001460061);
   h_jet1CSV_QCD__241->SetBinContent(6,0.0005098467);
   h_jet1CSV_QCD__241->SetBinContent(8,9.216642e-05);
   h_jet1CSV_QCD__241->SetBinContent(10,0.005040257);
   h_jet1CSV_QCD__241->SetBinError(1,0.001015339);
   h_jet1CSV_QCD__241->SetBinError(2,0.0006375418);
   h_jet1CSV_QCD__241->SetBinError(3,0.0001985037);
   h_jet1CSV_QCD__241->SetBinError(4,0.0007758122);
   h_jet1CSV_QCD__241->SetBinError(5,0.0009604397);
   h_jet1CSV_QCD__241->SetBinError(6,0.0005098467);
   h_jet1CSV_QCD__241->SetBinError(8,9.216642e-05);
   h_jet1CSV_QCD__241->SetBinError(10,0.002524985);
   h_jet1CSV_QCD__241->SetEntries(25);
   h_jet1CSV_QCD__241->SetStats(0);

   ci = TColor::GetColor("#cccccc");
   h_jet1CSV_QCD__241->SetFillColor(ci);
   h_jet1CSV_QCD__241->GetXaxis()->SetTitle("jet 1 CSV");
   h_jet1CSV_QCD__241->GetXaxis()->SetLabelFont(42);
   h_jet1CSV_QCD__241->GetXaxis()->SetLabelOffset(0.007);
   h_jet1CSV_QCD__241->GetXaxis()->SetTitleSize(0.05);
   h_jet1CSV_QCD__241->GetXaxis()->SetTickLength(0.025);
   h_jet1CSV_QCD__241->GetXaxis()->SetTitleFont(42);
   h_jet1CSV_QCD__241->GetYaxis()->SetTitle("a.u.");
   h_jet1CSV_QCD__241->GetYaxis()->SetLabelFont(42);
   h_jet1CSV_QCD__241->GetYaxis()->SetLabelOffset(0.007);
   h_jet1CSV_QCD__241->GetYaxis()->SetTitleSize(0.05);
   h_jet1CSV_QCD__241->GetYaxis()->SetTickLength(0.025);
   h_jet1CSV_QCD__241->GetYaxis()->SetTitleFont(42);
   h_jet1CSV_QCD__241->GetZaxis()->SetLabelFont(42);
   h_jet1CSV_QCD__241->GetZaxis()->SetLabelOffset(0.007);
   h_jet1CSV_QCD__241->GetZaxis()->SetTitleSize(0.05);
   h_jet1CSV_QCD__241->GetZaxis()->SetTickLength(0.025);
   h_jet1CSV_QCD__241->GetZaxis()->SetTitleFont(42);
   h->Add(h_jet1CSV_QCD,"");
   
   TH1D *h_jet1CSV_Diboson__242 = new TH1D("h_jet1CSV_Diboson__242","",10,0,1);
   h_jet1CSV_Diboson__242->SetBinContent(1,0.007902013);
   h_jet1CSV_Diboson__242->SetBinContent(2,0.01070993);
   h_jet1CSV_Diboson__242->SetBinContent(3,0.004898623);
   h_jet1CSV_Diboson__242->SetBinContent(4,0.00384298);
   h_jet1CSV_Diboson__242->SetBinContent(5,0.002613524);
   h_jet1CSV_Diboson__242->SetBinContent(6,0.002368716);
   h_jet1CSV_Diboson__242->SetBinContent(7,0.001456544);
   h_jet1CSV_Diboson__242->SetBinContent(8,0.001323376);
   h_jet1CSV_Diboson__242->SetBinContent(9,0.0003980073);
   h_jet1CSV_Diboson__242->SetBinContent(10,0.001279463);
   h_jet1CSV_Diboson__242->SetBinError(1,0.001211187);
   h_jet1CSV_Diboson__242->SetBinError(2,0.001421911);
   h_jet1CSV_Diboson__242->SetBinError(3,0.0009606959);
   h_jet1CSV_Diboson__242->SetBinError(4,0.0008875179);
   h_jet1CSV_Diboson__242->SetBinError(5,0.0007683429);
   h_jet1CSV_Diboson__242->SetBinError(6,0.0007114388);
   h_jet1CSV_Diboson__242->SetBinError(7,0.0005740134);
   h_jet1CSV_Diboson__242->SetBinError(8,0.0005780429);
   h_jet1CSV_Diboson__242->SetBinError(9,0.0002452434);
   h_jet1CSV_Diboson__242->SetBinError(10,0.000496194);
   h_jet1CSV_Diboson__242->SetEntries(227);
   h_jet1CSV_Diboson__242->SetStats(0);

   ci = TColor::GetColor("#9966cc");
   h_jet1CSV_Diboson__242->SetFillColor(ci);
   h_jet1CSV_Diboson__242->GetXaxis()->SetTitle("jet 1 CSV");
   h_jet1CSV_Diboson__242->GetXaxis()->SetLabelFont(42);
   h_jet1CSV_Diboson__242->GetXaxis()->SetLabelOffset(0.007);
   h_jet1CSV_Diboson__242->GetXaxis()->SetTitleSize(0.05);
   h_jet1CSV_Diboson__242->GetXaxis()->SetTickLength(0.025);
   h_jet1CSV_Diboson__242->GetXaxis()->SetTitleFont(42);
   h_jet1CSV_Diboson__242->GetYaxis()->SetTitle("a.u.");
   h_jet1CSV_Diboson__242->GetYaxis()->SetLabelFont(42);
   h_jet1CSV_Diboson__242->GetYaxis()->SetLabelOffset(0.007);
   h_jet1CSV_Diboson__242->GetYaxis()->SetTitleSize(0.05);
   h_jet1CSV_Diboson__242->GetYaxis()->SetTickLength(0.025);
   h_jet1CSV_Diboson__242->GetYaxis()->SetTitleFont(42);
   h_jet1CSV_Diboson__242->GetZaxis()->SetLabelFont(42);
   h_jet1CSV_Diboson__242->GetZaxis()->SetLabelOffset(0.007);
   h_jet1CSV_Diboson__242->GetZaxis()->SetTitleSize(0.05);
   h_jet1CSV_Diboson__242->GetZaxis()->SetTickLength(0.025);
   h_jet1CSV_Diboson__242->GetZaxis()->SetTitleFont(42);
   h->Add(h_jet1CSV_Diboson,"");
   
   TH1D *h_jet1CSV_ZpLjets__243 = new TH1D("h_jet1CSV_ZpLjets__243","",10,0,1);
   h_jet1CSV_ZpLjets__243->SetBinContent(1,0.0105581);
   h_jet1CSV_ZpLjets__243->SetBinContent(2,0.0149804);
   h_jet1CSV_ZpLjets__243->SetBinContent(3,0.006136762);
   h_jet1CSV_ZpLjets__243->SetBinContent(4,0.003962296);
   h_jet1CSV_ZpLjets__243->SetBinContent(5,0.003417574);
   h_jet1CSV_ZpLjets__243->SetBinContent(6,0.002305365);
   h_jet1CSV_ZpLjets__243->SetBinContent(7,0.001793532);
   h_jet1CSV_ZpLjets__243->SetBinContent(8,0.001236405);
   h_jet1CSV_ZpLjets__243->SetBinContent(9,0.001335452);
   h_jet1CSV_ZpLjets__243->SetBinContent(10,0.001687921);
   h_jet1CSV_ZpLjets__243->SetBinError(1,0.0002993944);
   h_jet1CSV_ZpLjets__243->SetBinError(2,0.0003673727);
   h_jet1CSV_ZpLjets__243->SetBinError(3,0.0002261915);
   h_jet1CSV_ZpLjets__243->SetBinError(4,0.0001994505);
   h_jet1CSV_ZpLjets__243->SetBinError(5,0.000185805);
   h_jet1CSV_ZpLjets__243->SetBinError(6,0.0001426398);
   h_jet1CSV_ZpLjets__243->SetBinError(7,0.0001285193);
   h_jet1CSV_ZpLjets__243->SetBinError(8,0.0001016587);
   h_jet1CSV_ZpLjets__243->SetBinError(9,0.0001150635);
   h_jet1CSV_ZpLjets__243->SetBinError(10,0.0001437861);
   h_jet1CSV_ZpLjets__243->SetEntries(24915);
   h_jet1CSV_ZpLjets__243->SetStats(0);

   ci = TColor::GetColor("#3399cc");
   h_jet1CSV_ZpLjets__243->SetFillColor(ci);
   h_jet1CSV_ZpLjets__243->GetXaxis()->SetTitle("jet 1 CSV");
   h_jet1CSV_ZpLjets__243->GetXaxis()->SetLabelFont(42);
   h_jet1CSV_ZpLjets__243->GetXaxis()->SetLabelOffset(0.007);
   h_jet1CSV_ZpLjets__243->GetXaxis()->SetTitleSize(0.05);
   h_jet1CSV_ZpLjets__243->GetXaxis()->SetTickLength(0.025);
   h_jet1CSV_ZpLjets__243->GetXaxis()->SetTitleFont(42);
   h_jet1CSV_ZpLjets__243->GetYaxis()->SetTitle("a.u.");
   h_jet1CSV_ZpLjets__243->GetYaxis()->SetLabelFont(42);
   h_jet1CSV_ZpLjets__243->GetYaxis()->SetLabelOffset(0.007);
   h_jet1CSV_ZpLjets__243->GetYaxis()->SetTitleSize(0.05);
   h_jet1CSV_ZpLjets__243->GetYaxis()->SetTickLength(0.025);
   h_jet1CSV_ZpLjets__243->GetYaxis()->SetTitleFont(42);
   h_jet1CSV_ZpLjets__243->GetZaxis()->SetLabelFont(42);
   h_jet1CSV_ZpLjets__243->GetZaxis()->SetLabelOffset(0.007);
   h_jet1CSV_ZpLjets__243->GetZaxis()->SetTitleSize(0.05);
   h_jet1CSV_ZpLjets__243->GetZaxis()->SetTickLength(0.025);
   h_jet1CSV_ZpLjets__243->GetZaxis()->SetTitleFont(42);
   h->Add(h_jet1CSV_Z+jets,"");
   
   TH1D *h_jet1CSV_WpLjets__244 = new TH1D("h_jet1CSV_WpLjets__244","",10,0,1);
   h_jet1CSV_WpLjets__244->SetBinContent(1,0.0105647);
   h_jet1CSV_WpLjets__244->SetBinContent(2,0.01249913);
   h_jet1CSV_WpLjets__244->SetBinContent(3,0.007002216);
   h_jet1CSV_WpLjets__244->SetBinContent(4,0.004496839);
   h_jet1CSV_WpLjets__244->SetBinContent(5,0.003373536);
   h_jet1CSV_WpLjets__244->SetBinContent(6,0.00194438);
   h_jet1CSV_WpLjets__244->SetBinContent(7,0.001499895);
   h_jet1CSV_WpLjets__244->SetBinContent(8,0.001552581);
   h_jet1CSV_WpLjets__244->SetBinContent(9,0.001498434);
   h_jet1CSV_WpLjets__244->SetBinContent(10,0.001251066);
   h_jet1CSV_WpLjets__244->SetBinError(1,0.0007887323);
   h_jet1CSV_WpLjets__244->SetBinError(2,0.0008242009);
   h_jet1CSV_WpLjets__244->SetBinError(3,0.0006456304);
   h_jet1CSV_WpLjets__244->SetBinError(4,0.0005750342);
   h_jet1CSV_WpLjets__244->SetBinError(5,0.0004846149);
   h_jet1CSV_WpLjets__244->SetBinError(6,0.0003336262);
   h_jet1CSV_WpLjets__244->SetBinError(7,0.0003618074);
   h_jet1CSV_WpLjets__244->SetBinError(8,0.000356322);
   h_jet1CSV_WpLjets__244->SetBinError(9,0.000315267);
   h_jet1CSV_WpLjets__244->SetBinError(10,0.0002636669);
   h_jet1CSV_WpLjets__244->SetEntries(3309);
   h_jet1CSV_WpLjets__244->SetStats(0);

   ci = TColor::GetColor("#66cc66");
   h_jet1CSV_WpLjets__244->SetFillColor(ci);
   h_jet1CSV_WpLjets__244->GetXaxis()->SetTitle("jet 1 CSV");
   h_jet1CSV_WpLjets__244->GetXaxis()->SetLabelFont(42);
   h_jet1CSV_WpLjets__244->GetXaxis()->SetLabelOffset(0.007);
   h_jet1CSV_WpLjets__244->GetXaxis()->SetTitleSize(0.05);
   h_jet1CSV_WpLjets__244->GetXaxis()->SetTickLength(0.025);
   h_jet1CSV_WpLjets__244->GetXaxis()->SetTitleFont(42);
   h_jet1CSV_WpLjets__244->GetYaxis()->SetTitle("a.u.");
   h_jet1CSV_WpLjets__244->GetYaxis()->SetLabelFont(42);
   h_jet1CSV_WpLjets__244->GetYaxis()->SetLabelOffset(0.007);
   h_jet1CSV_WpLjets__244->GetYaxis()->SetTitleSize(0.05);
   h_jet1CSV_WpLjets__244->GetYaxis()->SetTickLength(0.025);
   h_jet1CSV_WpLjets__244->GetYaxis()->SetTitleFont(42);
   h_jet1CSV_WpLjets__244->GetZaxis()->SetLabelFont(42);
   h_jet1CSV_WpLjets__244->GetZaxis()->SetLabelOffset(0.007);
   h_jet1CSV_WpLjets__244->GetZaxis()->SetTitleSize(0.05);
   h_jet1CSV_WpLjets__244->GetZaxis()->SetTickLength(0.025);
   h_jet1CSV_WpLjets__244->GetZaxis()->SetTitleFont(42);
   h->Add(h_jet1CSV_W+jets,"");
   
   TH1D *h_jet1CSV_TopsPoPLFcP__245 = new TH1D("h_jet1CSV_TopsPoPLFcP__245","",10,0,1);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(1,0.05724676);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(2,0.09449115);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(3,0.04295219);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(4,0.02886478);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(5,0.02197153);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(6,0.01676184);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(7,0.01344738);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(8,0.01147171);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(9,0.01188168);
   h_jet1CSV_TopsPoPLFcP__245->SetBinContent(10,0.02899011);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(1,0.000729733);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(2,0.0009659214);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(3,0.000703275);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(4,0.0005973511);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(5,0.0005112767);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(6,0.0004554214);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(7,0.000425343);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(8,0.0004081547);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(9,0.0004352084);
   h_jet1CSV_TopsPoPLFcP__245->SetBinError(10,0.0006914391);
   h_jet1CSV_TopsPoPLFcP__245->SetEntries(45754);
   h_jet1CSV_TopsPoPLFcP__245->SetStats(0);

   ci = TColor::GetColor("#cc33cc");
   h_jet1CSV_TopsPoPLFcP__245->SetFillColor(ci);
   h_jet1CSV_TopsPoPLFcP__245->GetXaxis()->SetTitle("jet 1 CSV");
   h_jet1CSV_TopsPoPLFcP__245->GetXaxis()->SetLabelFont(42);
   h_jet1CSV_TopsPoPLFcP__245->GetXaxis()->SetLabelOffset(0.007);
   h_jet1CSV_TopsPoPLFcP__245->GetXaxis()->SetTitleSize(0.05);
   h_jet1CSV_TopsPoPLFcP__245->GetXaxis()->SetTickLength(0.025);
   h_jet1CSV_TopsPoPLFcP__245->GetXaxis()->SetTitleFont(42);
   h_jet1CSV_TopsPoPLFcP__245->GetYaxis()->SetTitle("a.u.");
   h_jet1CSV_TopsPoPLFcP__245->GetYaxis()->SetLabelFont(42);
   h_jet1CSV_TopsPoPLFcP__245->GetYaxis()->SetLabelOffset(0.007);
   h_jet1CSV_TopsPoPLFcP__245->GetYaxis()->SetTitleSize(0.05);
   h_jet1CSV_TopsPoPLFcP__245->GetYaxis()->SetTickLength(0.025);
   h_jet1CSV_TopsPoPLFcP__245->GetYaxis()->SetTitleFont(42);
   h_jet1CSV_TopsPoPLFcP__245->GetZaxis()->SetLabelFont(42);
   h_jet1CSV_TopsPoPLFcP__245->GetZaxis()->SetLabelOffset(0.007);
   h_jet1CSV_TopsPoPLFcP__245->GetZaxis()->SetTitleSize(0.05);
   h_jet1CSV_TopsPoPLFcP__245->GetZaxis()->SetTickLength(0.025);
   h_jet1CSV_TopsPoPLFcP__245->GetZaxis()->SetTitleFont(42);
   h->Add(h_jet1CSV_Top (LF),"");
   
   TH1D *h_jet1CSV_TopsPoPHFcP__246 = new TH1D("h_jet1CSV_TopsPoPHFcP__246","",10,0,1);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(1,0.03716431);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(2,0.06356179);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(3,0.03422285);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(4,0.02759495);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(5,0.02467271);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(6,0.02266566);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(7,0.02783972);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(8,0.03184351);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(9,0.05887917);
   h_jet1CSV_TopsPoPHFcP__246->SetBinContent(10,0.2020009);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(1,0.0006192109);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(2,0.0008097774);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(3,0.0006131987);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(4,0.0005808687);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(5,0.0005375401);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(6,0.0005302149);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(7,0.0006356258);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(8,0.0006542281);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(9,0.0009161931);
   h_jet1CSV_TopsPoPHFcP__246->SetBinError(10,0.001553901);
   h_jet1CSV_TopsPoPHFcP__246->SetEntries(77950);
   h_jet1CSV_TopsPoPHFcP__246->SetStats(0);

   ci = TColor::GetColor("#ff9900");
   h_jet1CSV_TopsPoPHFcP__246->SetFillColor(ci);
   h_jet1CSV_TopsPoPHFcP__246->GetXaxis()->SetTitle("jet 1 CSV");
   h_jet1CSV_TopsPoPHFcP__246->GetXaxis()->SetLabelFont(42);
   h_jet1CSV_TopsPoPHFcP__246->GetXaxis()->SetLabelOffset(0.007);
   h_jet1CSV_TopsPoPHFcP__246->GetXaxis()->SetTitleSize(0.05);
   h_jet1CSV_TopsPoPHFcP__246->GetXaxis()->SetTickLength(0.025);
   h_jet1CSV_TopsPoPHFcP__246->GetXaxis()->SetTitleFont(42);
   h_jet1CSV_TopsPoPHFcP__246->GetYaxis()->SetTitle("a.u.");
   h_jet1CSV_TopsPoPHFcP__246->GetYaxis()->SetLabelFont(42);
   h_jet1CSV_TopsPoPHFcP__246->GetYaxis()->SetLabelOffset(0.007);
   h_jet1CSV_TopsPoPHFcP__246->GetYaxis()->SetTitleSize(0.05);
   h_jet1CSV_TopsPoPHFcP__246->GetYaxis()->SetTickLength(0.025);
   h_jet1CSV_TopsPoPHFcP__246->GetYaxis()->SetTitleFont(42);
   h_jet1CSV_TopsPoPHFcP__246->GetZaxis()->SetLabelFont(42);
   h_jet1CSV_TopsPoPHFcP__246->GetZaxis()->SetLabelOffset(0.007);
   h_jet1CSV_TopsPoPHFcP__246->GetZaxis()->SetTitleSize(0.05);
   h_jet1CSV_TopsPoPHFcP__246->GetZaxis()->SetTickLength(0.025);
   h_jet1CSV_TopsPoPHFcP__246->GetZaxis()->SetTitleFont(42);
   h->Add(h_jet1CSV_Top (HF),"");
   h->Draw("hist");
   
   TH1D *hsum__247 = new TH1D("hsum__247","",10,0,1);
   hsum__247->SetBinContent(1,0.1251058);
   hsum__247->SetBinContent(2,0.1975396);
   hsum__247->SetBinContent(3,0.09541114);
   hsum__247->SetBinContent(4,0.07007946);
   hsum__247->SetBinContent(5,0.05750894);
   hsum__247->SetBinContent(6,0.04655581);
   hsum__247->SetBinContent(7,0.04603708);
   hsum__247->SetBinContent(8,0.04751975);
   hsum__247->SetBinContent(9,0.07399275);
   hsum__247->SetBinContent(10,0.2402497);
   hsum__247->SetBinError(1,0.002031146);
   hsum__247->SetBinError(2,0.002198023);
   hsum__247->SetBinError(3,0.001516888);
   hsum__247->SetBinError(4,0.001566606);
   hsum__247->SetBinError(5,0.00152726);
   hsum__247->SetBinError(6,0.001177403);
   hsum__247->SetBinError(7,0.001030461);
   hsum__247->SetBinError(8,0.001036597);
   hsum__247->SetBinError(9,0.001096172);
   hsum__247->SetBinError(10,0.003099137);
   hsum__247->SetEntries(45);
   hsum__247->SetStats(0);

   ci = 1200;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   hsum__247->SetFillColor(ci);
   hsum__247->SetFillStyle(3003);
   hsum__247->SetLineWidth(0);
   hsum__247->GetXaxis()->SetTitle("jet 1 CSV");
   hsum__247->GetXaxis()->SetLabelFont(42);
   hsum__247->GetXaxis()->SetLabelOffset(0.007);
   hsum__247->GetXaxis()->SetTitleSize(0.05);
   hsum__247->GetXaxis()->SetTickLength(0.025);
   hsum__247->GetXaxis()->SetTitleFont(42);
   hsum__247->GetYaxis()->SetTitle("a.u.");
   hsum__247->GetYaxis()->SetLabelFont(42);
   hsum__247->GetYaxis()->SetLabelOffset(0.007);
   hsum__247->GetYaxis()->SetTitleSize(0.05);
   hsum__247->GetYaxis()->SetTickLength(0.025);
   hsum__247->GetYaxis()->SetTitleFont(42);
   hsum__247->GetZaxis()->SetLabelFont(42);
   hsum__247->GetZaxis()->SetLabelOffset(0.007);
   hsum__247->GetZaxis()->SetTitleSize(0.05);
   hsum__247->GetZaxis()->SetTickLength(0.025);
   hsum__247->GetZaxis()->SetTitleFont(42);
   hsum__247->Draw("e2 same");
   
   TH1D *h_jet1CSV_Data__248 = new TH1D("h_jet1CSV_Data__248","",10,0,1);
   h_jet1CSV_Data__248->SetBinContent(1,0.1217846);
   h_jet1CSV_Data__248->SetBinContent(2,0.2002261);
   h_jet1CSV_Data__248->SetBinContent(3,0.09935928);
   h_jet1CSV_Data__248->SetBinContent(4,0.07382455);
   h_jet1CSV_Data__248->SetBinContent(5,0.06336568);
   h_jet1CSV_Data__248->SetBinContent(6,0.04781871);
   h_jet1CSV_Data__248->SetBinContent(7,0.04861962);
   h_jet1CSV_Data__248->SetBinContent(8,0.04786582);
   h_jet1CSV_Data__248->SetBinContent(9,0.07109206);
   h_jet1CSV_Data__248->SetBinContent(10,0.2260435);
   h_jet1CSV_Data__248->SetBinError(1,0.002395312);
   h_jet1CSV_Data__248->SetBinError(2,0.003071329);
   h_jet1CSV_Data__248->SetBinError(3,0.002163566);
   h_jet1CSV_Data__248->SetBinError(4,0.001864946);
   h_jet1CSV_Data__248->SetBinError(5,0.001727798);
   h_jet1CSV_Data__248->SetBinError(6,0.001500945);
   h_jet1CSV_Data__248->SetBinError(7,0.001513463);
   h_jet1CSV_Data__248->SetBinError(8,0.001501684);
   h_jet1CSV_Data__248->SetBinError(9,0.001830107);
   h_jet1CSV_Data__248->SetBinError(10,0.003263337);
   h_jet1CSV_Data__248->SetEntries(21226);
   h_jet1CSV_Data__248->SetStats(0);
   h_jet1CSV_Data__248->SetLineWidth(3);
   h_jet1CSV_Data__248->SetMarkerStyle(20);
   h_jet1CSV_Data__248->SetMarkerSize(2);
   h_jet1CSV_Data__248->GetXaxis()->SetTitle("jet 1 CSV");
   h_jet1CSV_Data__248->GetXaxis()->SetLabelFont(42);
   h_jet1CSV_Data__248->GetXaxis()->SetLabelOffset(0.007);
   h_jet1CSV_Data__248->GetXaxis()->SetTitleSize(0.05);
   h_jet1CSV_Data__248->GetXaxis()->SetTickLength(0.025);
   h_jet1CSV_Data__248->GetXaxis()->SetTitleFont(42);
   h_jet1CSV_Data__248->GetYaxis()->SetTitle("a.u.");
   h_jet1CSV_Data__248->GetYaxis()->SetLabelFont(42);
   h_jet1CSV_Data__248->GetYaxis()->SetLabelOffset(0.007);
   h_jet1CSV_Data__248->GetYaxis()->SetTitleSize(0.05);
   h_jet1CSV_Data__248->GetYaxis()->SetTickLength(0.025);
   h_jet1CSV_Data__248->GetYaxis()->SetTitleFont(42);
   h_jet1CSV_Data__248->GetZaxis()->SetLabelFont(42);
   h_jet1CSV_Data__248->GetZaxis()->SetLabelOffset(0.007);
   h_jet1CSV_Data__248->GetZaxis()->SetTitleSize(0.05);
   h_jet1CSV_Data__248->GetZaxis()->SetTickLength(0.025);
   h_jet1CSV_Data__248->GetZaxis()->SetTitleFont(42);
   h_jet1CSV_Data__248->Draw("elp same");
   
   TLegend *leg = new TLegend(0.6,0.55,0.88,0.9,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   TLegendEntry *entry=leg->AddEntry("h_jet1CSV_Data","Data","ELP");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(3);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(2);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_Top (HF)","Top (HF)","F");

   ci = TColor::GetColor("#ff9900");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_Top (LF)","Top (LF)","F");

   ci = TColor::GetColor("#cc33cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_W+jets","W+jets","F");

   ci = TColor::GetColor("#66cc66");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_Z+jets","Z+jets","F");

   ci = TColor::GetColor("#3399cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_Diboson","Diboson","F");

   ci = TColor::GetColor("#9966cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_QCD","QCD","F");

   ci = TColor::GetColor("#cccccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   
   leg = new TLegend(0.6,0.55,0.88,0.9,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   entry=leg->AddEntry("h_jet1CSV_Data","Data","ELP");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(3);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(2);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_Top (HF)","Top (HF)","F");

   ci = TColor::GetColor("#ff9900");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_Top (LF)","Top (LF)","F");

   ci = TColor::GetColor("#cc33cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_W+jets","W+jets","F");

   ci = TColor::GetColor("#66cc66");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_Z+jets","Z+jets","F");

   ci = TColor::GetColor("#3399cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_Diboson","Diboson","F");

   ci = TColor::GetColor("#9966cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_jet1CSV_QCD","QCD","F");

   ci = TColor::GetColor("#cccccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   TLatex *   tex = new TLatex(0.18,0.85,"CMS");
tex->SetNDC();
   tex->SetTextSize(0.06);
   tex->SetLineWidth(2);
   tex->Draw();
      tex = new TLatex(0.28,0.85,"Preliminary");
tex->SetNDC();
   tex->SetTextFont(52);
   tex->SetTextSize(0.06);
   tex->SetLineWidth(2);
   tex->Draw();
      tex = new TLatex(0.9,0.94,"36.6 fb^{-1} (13 TeV)");
tex->SetNDC();
   tex->SetTextAlign(31);
   tex->SetTextFont(42);
   tex->SetTextSize(0.04);
   tex->SetLineWidth(2);
   tex->Draw();
   pad1->Modified();
   c1->cd();
  
// ------------>Primitives in pad: pad2
   TPad *pad2 = new TPad("pad2", "pad2",0,0.05,1,0.3);
   pad2->Draw();
   pad2->cd();
   pad2->Range(-0.1875,-0.8914286,1.0625,0.48);
   pad2->SetFillColor(0);
   pad2->SetBorderMode(0);
   pad2->SetBorderSize(2);
   pad2->SetGridy();
   pad2->SetTickx(1);
   pad2->SetTicky(1);
   pad2->SetLeftMargin(0.15);
   pad2->SetRightMargin(0.05);
   pad2->SetTopMargin(0);
   pad2->SetBottomMargin(0.3);
   pad2->SetFrameFillStyle(0);
   pad2->SetFrameBorderMode(0);
   pad2->SetFrameFillStyle(0);
   pad2->SetFrameBorderMode(0);
   
   TH1D *ratio__249 = new TH1D("ratio__249","",10,0,1);
   ratio__249->SetBinContent(1,-0.02654743);
   ratio__249->SetBinContent(2,0.01360023);
   ratio__249->SetBinContent(3,0.04138029);
   ratio__249->SetBinContent(4,0.05344069);
   ratio__249->SetBinContent(5,0.1018405);
   ratio__249->SetBinContent(6,0.02712655);
   ratio__249->SetBinContent(7,0.05609691);
   ratio__249->SetBinContent(8,0.007282734);
   ratio__249->SetBinContent(9,-0.03920245);
   ratio__249->SetBinContent(10,-0.05913073);
   ratio__249->SetBinError(1,0.0001);
   ratio__249->SetBinError(2,0.0001);
   ratio__249->SetBinError(3,0.0001);
   ratio__249->SetBinError(4,0.0001);
   ratio__249->SetBinError(5,0.0001);
   ratio__249->SetBinError(6,0.0001);
   ratio__249->SetBinError(7,0.0001);
   ratio__249->SetBinError(8,0.0001);
   ratio__249->SetBinError(9,0.0001);
   ratio__249->SetBinError(10,0.0001);
   ratio__249->SetMinimum(-0.48);
   ratio__249->SetMaximum(0.48);
   ratio__249->SetEntries(21236);
   ratio__249->SetStats(0);
   ratio__249->SetLineWidth(3);
   ratio__249->SetMarkerStyle(20);
   ratio__249->SetMarkerSize(2);
   ratio__249->GetXaxis()->SetTitle("jet 1 CSV");
   ratio__249->GetXaxis()->SetLabelFont(43);
   ratio__249->GetXaxis()->SetLabelOffset(0.007);
   ratio__249->GetXaxis()->SetLabelSize(30);
   ratio__249->GetXaxis()->SetTitleSize(40);
   ratio__249->GetXaxis()->SetTickLength(0.025);
   ratio__249->GetXaxis()->SetTitleOffset(5);
   ratio__249->GetXaxis()->SetTitleFont(43);
   ratio__249->GetYaxis()->SetTitle("#frac{Data-Exp}{Exp}");
   ratio__249->GetYaxis()->SetNdivisions(5);
   ratio__249->GetYaxis()->SetLabelFont(43);
   ratio__249->GetYaxis()->SetLabelOffset(0.007);
   ratio__249->GetYaxis()->SetLabelSize(30);
   ratio__249->GetYaxis()->SetTitleSize(40);
   ratio__249->GetYaxis()->SetTickLength(0.025);
   ratio__249->GetYaxis()->SetTitleOffset(2.5);
   ratio__249->GetYaxis()->SetTitleFont(43);
   ratio__249->GetZaxis()->SetLabelFont(42);
   ratio__249->GetZaxis()->SetLabelOffset(0.007);
   ratio__249->GetZaxis()->SetTitleSize(0.05);
   ratio__249->GetZaxis()->SetTickLength(0.025);
   ratio__249->GetZaxis()->SetTitleFont(42);
   ratio__249->Draw("elp");
   
   TH1D *zero__250 = new TH1D("zero__250","",10,0,1);
   zero__250->SetBinError(1,0.002395312);
   zero__250->SetBinError(2,0.003071329);
   zero__250->SetBinError(3,0.002163566);
   zero__250->SetBinError(4,0.001864946);
   zero__250->SetBinError(5,0.001727798);
   zero__250->SetBinError(6,0.001500945);
   zero__250->SetBinError(7,0.001513463);
   zero__250->SetBinError(8,0.001501684);
   zero__250->SetBinError(9,0.001830107);
   zero__250->SetBinError(10,0.003263337);
   zero__250->SetEntries(21236);
   zero__250->SetStats(0);
   zero__250->SetLineWidth(3);
   zero__250->SetMarkerStyle(20);
   zero__250->SetMarkerSize(2);
   zero__250->GetXaxis()->SetTitle("jet 1 CSV");
   zero__250->GetXaxis()->SetLabelFont(42);
   zero__250->GetXaxis()->SetLabelOffset(0.007);
   zero__250->GetXaxis()->SetTitleSize(0.05);
   zero__250->GetXaxis()->SetTickLength(0.025);
   zero__250->GetXaxis()->SetTitleFont(42);
   zero__250->GetYaxis()->SetTitle("a.u.");
   zero__250->GetYaxis()->SetLabelFont(42);
   zero__250->GetYaxis()->SetLabelOffset(0.007);
   zero__250->GetYaxis()->SetTitleSize(0.05);
   zero__250->GetYaxis()->SetTickLength(0.025);
   zero__250->GetYaxis()->SetTitleFont(42);
   zero__250->GetZaxis()->SetLabelFont(42);
   zero__250->GetZaxis()->SetLabelOffset(0.007);
   zero__250->GetZaxis()->SetTitleSize(0.05);
   zero__250->GetZaxis()->SetTickLength(0.025);
   zero__250->GetZaxis()->SetTitleFont(42);
   zero__250->Draw("hist same");
   
   TH1D *sumratioup__251 = new TH1D("sumratioup__251","",10,0,1);
   sumratioup__251->SetBinContent(1,0.01623542);
   sumratioup__251->SetBinContent(2,0.011127);
   sumratioup__251->SetBinContent(3,0.01589844);
   sumratioup__251->SetBinContent(4,0.02235471);
   sumratioup__251->SetBinContent(5,0.02655692);
   sumratioup__251->SetBinContent(6,0.02529014);
   sumratioup__251->SetBinContent(7,0.02238329);
   sumratioup__251->SetBinContent(8,0.02181402);
   sumratioup__251->SetBinContent(9,0.01481459);
   sumratioup__251->SetBinContent(10,0.01289965);
   sumratioup__251->SetBinError(1,0.002031146);
   sumratioup__251->SetBinError(2,0.002198023);
   sumratioup__251->SetBinError(3,0.001516888);
   sumratioup__251->SetBinError(4,0.001566606);
   sumratioup__251->SetBinError(5,0.00152726);
   sumratioup__251->SetBinError(6,0.001177403);
   sumratioup__251->SetBinError(7,0.001030461);
   sumratioup__251->SetBinError(8,0.001036597);
   sumratioup__251->SetBinError(9,0.001096172);
   sumratioup__251->SetBinError(10,0.003099137);
   sumratioup__251->SetEntries(55);
   sumratioup__251->SetStats(0);

   ci = 1200;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   sumratioup__251->SetFillColor(ci);
   sumratioup__251->SetFillStyle(3003);
   sumratioup__251->GetXaxis()->SetTitle("jet 1 CSV");
   sumratioup__251->GetXaxis()->SetLabelFont(42);
   sumratioup__251->GetXaxis()->SetLabelOffset(0.007);
   sumratioup__251->GetXaxis()->SetTitleSize(0.05);
   sumratioup__251->GetXaxis()->SetTickLength(0.025);
   sumratioup__251->GetXaxis()->SetTitleFont(42);
   sumratioup__251->GetYaxis()->SetTitle("a.u.");
   sumratioup__251->GetYaxis()->SetLabelFont(42);
   sumratioup__251->GetYaxis()->SetLabelOffset(0.007);
   sumratioup__251->GetYaxis()->SetTitleSize(0.05);
   sumratioup__251->GetYaxis()->SetTickLength(0.025);
   sumratioup__251->GetYaxis()->SetTitleFont(42);
   sumratioup__251->GetZaxis()->SetLabelFont(42);
   sumratioup__251->GetZaxis()->SetLabelOffset(0.007);
   sumratioup__251->GetZaxis()->SetTitleSize(0.05);
   sumratioup__251->GetZaxis()->SetTickLength(0.025);
   sumratioup__251->GetZaxis()->SetTitleFont(42);
   sumratioup__251->Draw("hist same");
   
   TH1D *sumratiodown__252 = new TH1D("sumratiodown__252","",10,0,1);
   sumratiodown__252->SetBinContent(1,-0.01623542);
   sumratiodown__252->SetBinContent(2,-0.011127);
   sumratiodown__252->SetBinContent(3,-0.01589844);
   sumratiodown__252->SetBinContent(4,-0.02235471);
   sumratiodown__252->SetBinContent(5,-0.02655692);
   sumratiodown__252->SetBinContent(6,-0.02529014);
   sumratiodown__252->SetBinContent(7,-0.02238329);
   sumratiodown__252->SetBinContent(8,-0.02181402);
   sumratiodown__252->SetBinContent(9,-0.01481459);
   sumratiodown__252->SetBinContent(10,-0.01289965);
   sumratiodown__252->SetBinError(1,0.002031146);
   sumratiodown__252->SetBinError(2,0.002198023);
   sumratiodown__252->SetBinError(3,0.001516888);
   sumratiodown__252->SetBinError(4,0.001566606);
   sumratiodown__252->SetBinError(5,0.00152726);
   sumratiodown__252->SetBinError(6,0.001177403);
   sumratiodown__252->SetBinError(7,0.001030461);
   sumratiodown__252->SetBinError(8,0.001036597);
   sumratiodown__252->SetBinError(9,0.001096172);
   sumratiodown__252->SetBinError(10,0.003099137);
   sumratiodown__252->SetEntries(55);
   sumratiodown__252->SetStats(0);

   ci = 1200;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   sumratiodown__252->SetFillColor(ci);
   sumratiodown__252->SetFillStyle(3003);
   sumratiodown__252->GetXaxis()->SetTitle("jet 1 CSV");
   sumratiodown__252->GetXaxis()->SetLabelFont(42);
   sumratiodown__252->GetXaxis()->SetLabelOffset(0.007);
   sumratiodown__252->GetXaxis()->SetTitleSize(0.05);
   sumratiodown__252->GetXaxis()->SetTickLength(0.025);
   sumratiodown__252->GetXaxis()->SetTitleFont(42);
   sumratiodown__252->GetYaxis()->SetTitle("a.u.");
   sumratiodown__252->GetYaxis()->SetLabelFont(42);
   sumratiodown__252->GetYaxis()->SetLabelOffset(0.007);
   sumratiodown__252->GetYaxis()->SetTitleSize(0.05);
   sumratiodown__252->GetYaxis()->SetTickLength(0.025);
   sumratiodown__252->GetYaxis()->SetTitleFont(42);
   sumratiodown__252->GetZaxis()->SetLabelFont(42);
   sumratiodown__252->GetZaxis()->SetLabelOffset(0.007);
   sumratiodown__252->GetZaxis()->SetTitleSize(0.05);
   sumratiodown__252->GetZaxis()->SetTickLength(0.025);
   sumratiodown__252->GetZaxis()->SetTitleFont(42);
   sumratiodown__252->Draw("hist same");
   
   Double_t Graph0_fx1021[10] = {
   0.05,
   0.15,
   0.25,
   0.35,
   0.45,
   0.55,
   0.65,
   0.75,
   0.85,
   0.95};
   Double_t Graph0_fy1021[10] = {
   -0.02654743,
   0.01360023,
   0.04138029,
   0.05344069,
   0.1018405,
   0.02712655,
   0.05609691,
   0.007282734,
   -0.03920245,
   -0.05913073};
   Double_t Graph0_fex1021[10] = {
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0};
   Double_t Graph0_fey1021[10] = {
   0.01914628,
   0.01554792,
   0.02267624,
   0.02661188,
   0.03004399,
   0.0322397,
   0.03287486,
   0.03160127,
   0.0247336,
   0.01358311};
   TGraphErrors *gre = new TGraphErrors(10,Graph0_fx1021,Graph0_fy1021,Graph0_fex1021,Graph0_fey1021);
   gre->SetName("Graph0");
   gre->SetTitle("Graph");
   gre->SetFillColor(1);
   gre->SetLineWidth(3);
   
   TH1F *Graph_Graph1021 = new TH1F("Graph_Graph1021","Graph",100,0,1.04);
   Graph_Graph1021->SetMinimum(-0.09317367);
   Graph_Graph1021->SetMaximum(0.1523443);
   Graph_Graph1021->SetDirectory(0);
   Graph_Graph1021->SetStats(0);

   ci = TColor::GetColor("#000099");
   Graph_Graph1021->SetLineColor(ci);
   Graph_Graph1021->GetXaxis()->SetLabelFont(42);
   Graph_Graph1021->GetXaxis()->SetLabelOffset(0.007);
   Graph_Graph1021->GetXaxis()->SetTitleSize(0.05);
   Graph_Graph1021->GetXaxis()->SetTickLength(0.025);
   Graph_Graph1021->GetXaxis()->SetTitleFont(42);
   Graph_Graph1021->GetYaxis()->SetLabelFont(42);
   Graph_Graph1021->GetYaxis()->SetLabelOffset(0.007);
   Graph_Graph1021->GetYaxis()->SetTitleSize(0.05);
   Graph_Graph1021->GetYaxis()->SetTickLength(0.025);
   Graph_Graph1021->GetYaxis()->SetTitleFont(42);
   Graph_Graph1021->GetZaxis()->SetLabelFont(42);
   Graph_Graph1021->GetZaxis()->SetLabelOffset(0.007);
   Graph_Graph1021->GetZaxis()->SetTitleSize(0.05);
   Graph_Graph1021->GetZaxis()->SetTickLength(0.025);
   Graph_Graph1021->GetZaxis()->SetTitleFont(42);
   gre->SetHistogram(Graph_Graph1021);
   
   gre->Draw("pe0");
   pad2->Modified();
   c1->cd();
   c1->Modified();
   c1->cd();
   c1->SetSelected(c1);
}
Exemple #16
0
void allCutFlow(){
setTDRStyle();

//loop over variables
for(int i = 0; i<1; i++){
double MinX = MinXs[i];
double MaxX = MaxXs[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("SingleMu", 1);

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475);

//TH1D* wjets = getSample("W1Jet", lumi*37509/57708550);
TH1D* wjets = getSample("W1Jet", lumi*5400.0/23140779);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904);

//TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954);
TH1D* zjets = getSample("DY1JetsToLL", lumi*561.0/24042904);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785);

//TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",     lumi*34679.3/8500505);
TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",   lumi*7.022e8 * 0.0039/1722678);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263);

TH1D* single_t = getSample("T_t-channel", lumi*56.4/3757707);
TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948);

TH1D* all_MC = getSample("TTJet", lumi*225.2/6920475);

THStack *hs = new THStack("hs","test");

  qcd->Add(qcd2);
  qcd->Add(qcd3);
  qcd->Add(qcd4);
  qcd->Add(qcd5);
  qcd->Add(qcd6);
  qcd->Add(qcd7);
  qcd->Add(qcd8);
  qcd->Add(qcd9);
  qcd->Add(qcd10);
  qcd->Add(qcd11);

  hs->Add(qcd);  

  zjets->Add(z2jets);
  zjets->Add(z3jets);
  zjets->Add(z4jets);  
    
  hs->Add(zjets);


  wjets->Add(w2jets);
  wjets->Add(w3jets);
  wjets->Add(w4jets);  

  hs->Add(wjets);
      
  hs->Add(top_t);
  hs->Add(top_tw);
  hs->Add(top_s);
  hs->Add(tbar_t);
  hs->Add(tbar_tw);
  hs->Add(tbar_s);
  
  single_t->Add(top_tw);
  single_t->Add(top_s);
  single_t->Add(tbar_t);
  single_t->Add(tbar_tw);
  single_t->Add(tbar_s);
  
  hs->Add(tt);

TH1D * allMC = (TH1D*) tt->Clone("all");
allMC->Add(wjets);allMC->Add(zjets);allMC->Add(single_t);allMC->Add(qcd);

TH1D* dataEff = new TH1D("cut eff","cut eff",10,0,10);
TH1D* mcEff = new TH1D("cut eff","cut eff",10,0,10);


 TString step[11] = {"Skim" ,"Cleaning and HLT","one isolated #mu", "loose #mu veto", "loose e veto", "#geq 1 jets", "#geq 2 jets","#geq 3 jets", "#geq 4 jets", "#geq1 CSV b-tag", "#geq2 CSV b-tag" };
 		
dataEff->Sumw2();
for(int i =1; i<11; i++){
mcEff->GetXaxis()->SetBinLabel(i, step[i]);
dataEff->SetBinContent(i, data->GetBinContent(i+1)/data->GetBinContent(i));
dataEff->SetBinError(i, sqrt(pow(data->GetBinContent(i+1),2)+pow(data->GetBinContent(i),2)));
mcEff->SetBinContent(i, allMC->GetBinContent(i+1)/allMC->GetBinContent(i));

}  

	
	TCanvas *c2 = new TCanvas("cutflow eff","cutflow eff",600, 500);
  	
	mcEff->SetLineColor(kRed);
	mcEff->Draw();
	dataEff->Draw("Esame");
	
	TLegend *tleg3;
	tleg3 = new TLegend(0.7,0.7,0.8,0.9);
	tleg3->SetTextSize(0.04);
	tleg3->SetBorderSize(0);
	tleg3->SetFillColor(10);
	tleg3->AddEntry(dataEff , "data", "l");
	tleg3->AddEntry(mcEff , "mc", "l");
	
	tleg3->Draw("same");
	
	c2->SaveAs("plots/cutFlow/cutEff_data.png");
	delete c2;

  //draw histos to files
  TCanvas *c1 = new TCanvas("cutflow","cutflow",900, 600);

  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);
  
  if(logPlot ==true)
  hs->SetMinimum(10000.);

  hs->Draw();
  for(int i =0; i<tt->GetNbinsX(); i++)
  hs->GetXaxis()->SetBinLabel(i+1, step[i]);
  
  data->Draw("E same");
  data->SetMarkerStyle(20);
  
//  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.7,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "lf");
	tleg2->AddEntry(top_t, "single top", "lf");
	tleg2->AddEntry(wjets , "w+jets", "lf");
	tleg2->AddEntry(zjets , "z+jets", "lf");
	tleg2->AddEntry(qcd , "QCD", "lf");
	
	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	
	
	TText* textPrelim = doPrelim(0.17,0.96);
	textPrelim->Draw();
	
  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("plots/cutFlow/");
  
  if(logPlot ==true){
    plotName += Variable+"_Log";
    plotName += Nbtags+".png";
    
  }else{
    plotName += Variable+"";  
    plotName += Nbtags+".png";
  }
 
 
  c1->SaveAs(plotName);
  delete c1;
 
 //print out
 
    std::cout.setf(std::ios::fixed);
    std::cout.precision(0);

 cout << " & ttbar & wjets & zjets & single-t & qcd & all MC & data " << endl; 
 
 for(int i = 0; i < tt->GetNbinsX(); i++){
 cout << step[i] << " & " << tt->GetBinContent(i+1) << " $\\pm$ " << tt->GetBinError(i+1)  << " & " << wjets->GetBinContent(i+1) << " $\\pm$ " << wjets->GetBinError(i+1)  << " & " << zjets->GetBinContent(i+1) << " $\\pm$ " << zjets->GetBinError(i+1)  << " & " << single_t->GetBinContent(i+1) << " $\\pm$ " << single_t->GetBinError(i+1)  << " & " << qcd->GetBinContent(i+1) << " $\\pm$ " << qcd->GetBinError(i+1)  << " & " << allMC->GetBinContent(i+1) << " $\\pm$ " << allMC->GetBinError(i+1)  << " & " << data->GetBinContent(i+1) << " $\\pm$ " << data->GetBinError(i+1)  << endl;
 
 }
 
  
  }
  	
}
Exemple #17
0
//void VHPlotter(string title="", int plot=0) {
void VHPlotter(string title="", int plot=0,   TCanvas* c1=0 ) {


    string subdir="0";
    string postfix="";
    string dirbSel="";

    double norm11 = ((Lumi2016_ele * Xsec_dy_amc1) / Ngen_dy_amc1);
    double norm12 = ((Lumi2016_ele * Xsec_dy_amc2) / Ngen_dy_amc2);
    double norm13 = ((Lumi2016_ele * Xsec_dy_amc3) / Ngen_dy_amc3);
    double norm14 = ((Lumi2016_ele * Xsec_dy_amc4) / Ngen_dy_amc4);

    double norm2 = ((Lumi2016_ele * Xsec_tt) / Ngen_tt);
    double norm3 = ((Lumi2016_ele * Xsec_zz) / Ngen_zz);
    double norm4 = ((Lumi2016_ele * Xsec_wz) / Ngen_wz);
    double norm6 = ((Lumi2016_ele * Xsec_ww) / Ngen_ww);
    double norm7 = ((Lumi2016_ele * Xsec_zhm) / Ngen_zhm);
    double norm8 = ((Lumi2016_ele * Xsec_zhp) / Ngen_zhp);

//if (ilepton==1) Lumi2016 = Lumi2016_ele;

    /*double enorm1 = ((Lumi2012 * eXsec_dy) / Ngen_dy);
    double enorm1_amc = ((Lumi2012 * eXsec_dy_amc) / Ngen_dy_amc);
    double enorm1_1 = ((Lumi2012 * eXsec_dy_1) / Ngen_dy_1);
    double enorm1_2=0;
    double enorm2 = ((Lumi2012 * eXsec_tt) / Ngen_tt);
    double enorm4 = ((Lumi2012 * eXsec_wz) / Ngen_wz);
    double enorm5 = ((Lumi2012 * eXsec_qcd) / Ngen_qcd);
    double enorm6 = ((Lumi2012 * eXsec_ww) / Ngen_ww);
    double enorm7 = ((Lumi2012 * eXsec_wj) / Ngen_wj);
    double enorm8 = ((Lumi2012 * eXsec_tS) / Ngen_tS);
    double enorm9 = ((Lumi2012 * eXsec_tT) / Ngen_tT);
    double enorm10 = ((Lumi2012 * eXsec_tW) / Ngen_tW);
    double enorm11 = ((Lumi2012 * eXsec_tSb) / Ngen_tSb);
    double enorm12 = ((Lumi2012 * eXsec_tTb) / Ngen_tTb);
    double enorm13 = ((Lumi2012 * eXsec_tWb) / Ngen_tWb);
    */

    TFile* mc11 = TFile::Open((path + "DYJetsToLL_M-50_HT-100to200_13TeV.root").c_str());
    TH1F* h_mc11 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc12 = TFile::Open((path + "DYJetsToLL_M-50_HT-200to400_13TeV.root").c_str());
    TH1F* h_mc12 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc13 = TFile::Open((path + "DYJetsToLL_M-50_HT-400to600_13TeV.root").c_str());
    TH1F* h_mc13 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc14 = TFile::Open((path + "DYJetsToLL_M-50_HT-600toInf_13TeV.root").c_str());
    TH1F* h_mc14 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc2 = TFile::Open((path + "TT_TuneCUETP8M1_13TeV.root").c_str());
    TH1F* h_mc2 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc3 = TFile::Open((path + "ZZ_TuneCUETP8M1_13TeV.root").c_str());
    TH1F* h_mc3 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc4 = TFile::Open((path + "WZ_TuneCUETP8M1_13TeV.root").c_str());
    TH1F* h_mc4 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc6 = TFile::Open((path + "WW_TuneCUETP8M1_13TeV.root").c_str());
    TH1F* h_mc6 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc7 = TFile::Open((path + "ZH_HToBB_ZToLL_M125_13TeV_amcatnlo.root").c_str());
    TH1F* h_mc7 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc8 = TFile::Open((path + "ZH_HToBB_ZToLL_M125_13TeV_powheg.root").c_str());
    TH1F* h_mc8 = (TH1F*)gDirectory->Get(title.c_str());

//TFile* data = TFile::Open((path + "SingleElectron-Run2016B-v2.root").c_str());;
//TH1F* h_data = (TH1F*)gDirectory->Get(title.c_str());

    TFile* data_runB = TFile::Open((path + "SingleElectron-Run2016B-v2.root").c_str());
    TH1F* h_data_runB = (TH1F*)gDirectory->Get(title.c_str());

    TFile* data_runC = TFile::Open((path + "SingleElectron-Run2016C-v2.root").c_str());
    TH1F* h_data_runC = (TH1F*)gDirectory->Get(title.c_str());

    TFile* data_runD = TFile::Open((path + "SingleElectron-Run2016D-v2.root").c_str());
    TH1F* h_data_runD = (TH1F*)gDirectory->Get(title.c_str());

    TH1F* h_data = (TH1F*)h_data_runB ->Clone("h_data");
    h_data->Reset();
    h_data->Add( h_data_runB );
    h_data->Add( h_data_runC );
    h_data->Add( h_data_runD );

    h_mc2 -> SetLineColor(kBlack);
    h_mc2 -> SetFillColor(kBlue);
//h_mc2 -> SetFillStyle(3004);

    h_mc3 -> SetLineColor(kBlack);
    h_mc3 -> SetFillColor(kGray+2);
//h_mc3 -> SetFillStyle(3004);

//h_mc4 -> SetLineColor(kBlack);
//h_mc4 -> SetFillColor(kGray+3);
//h_mc4 -> SetFillStyle(3004);

//h_mc6 -> SetLineColor(kBlack);
//h_mc6 -> SetFillColor(kRed+2);
//h_mc6 -> SetFillStyle(3004);

    h_mc7 -> SetLineColor(kBlack);
    h_mc7 -> SetFillColor(kMagenta);
//h_mc7 -> SetFillStyle(3004);

    h_mc8 -> SetLineColor(kGreen);
//h_mc8 -> SetLineColor(kBlack);
//h_mc8 -> SetFillColor(kPink);
//h_mc8 -> SetFillStyle(3004);
    h_mc8 ->SetLineWidth(3);

    h_mc11->Scale(norm11);
    h_mc12->Scale(norm12);
    h_mc13->Scale(norm13);
    h_mc14->Scale(norm14);
    h_mc2->Scale(norm2);
    h_mc3->Scale(norm3);
    h_mc4->Scale(norm4);
    h_mc6->Scale(norm6);
    h_mc7->Scale(norm7);
    h_mc8->Scale(norm8);

    TH1F* h_mcDY = (TH1F*)h_mc11->Clone("h_mcDY");
    h_mcDY->Reset();
    h_mcDY->Add(h_mc14);
    h_mcDY->Add(h_mc13);
    h_mcDY->Add(h_mc12);
    h_mcDY->Add(h_mc11);

    h_mcDY -> SetLineColor(kBlack);
    h_mcDY -> SetFillColor(kYellow-4);
//h_mcDY -> SetFillStyle(3004);

    TH1F* h_mcDiboson = (TH1F*)h_mc3->Clone("h_mcDiboson");
    h_mcDiboson->Reset();
    h_mcDiboson->Add(h_mc3);
    h_mcDiboson->Add(h_mc4);
    h_mcDiboson->Add(h_mc6);


    TH1F *ht = (TH1F*)h_mcDY->Clone("ht");
    ht->Reset();
//ht->Add(h_mc8);
    ht->Add(h_mc7);
//ht->Add(h_mc6);
//ht->Add(h_mc4);
//ht->Add(h_mc3);
    ht->Add(h_mcDiboson);
    ht->Add(h_mc2);
    ht->Add(h_mcDY);

    THStack *hs = new THStack("hs","");
//hs->Add(h_mc8); // ZH powheg
    hs->Add(h_mc7);   // ZH madgraph
//hs->Add(h_mc6);
//hs->Add(h_mc4);
//hs->Add(h_mc3);
    hs->Add(h_mcDiboson);
    hs->Add(h_mc2);
    hs->Add(h_mcDY);

//TCanvas* c1 = 0;
//c1 = new TCanvas("c","c",10,10,800,600);
    c1->cd();

    TPad *pad1 = new TPad("pad1","pad1",0.0,0.3,1.0,1.0);
    pad1->SetBottomMargin(0.001);
    pad1->Draw();
    pad1->cd();

    if( title=="FATjetSDmass" || title=="FATjetSDmassCorr" || title=="FATjetPRmass" || title=="FATjetPRmassCorr" || title=="FATnSubjet" || title=="ZHmass" )
    {
        pad1->SetLogy();
    }

    hs->Draw("HIST");
    hs->GetYaxis()->SetTitle("Events");
    hs->GetYaxis()->SetTitleSize(0.05);
    hs->GetYaxis()->SetLabelSize(0.045);
    hs->GetYaxis()->SetTitleOffset(1.0);// 0.7
//hs->SetMinimum(8);
    hs->SetMinimum(0.1);
    hs->SetMaximum(1.2*hs->GetMaximum());
    if (title=="ZHmass") {
        hs->GetXaxis()->SetRangeUser(0, 3000);
    }

    h_mc8->Draw("same hist");


    h_data->Draw("EPX0SAMES");
    h_data->SetMarkerColor(kBlack);
    h_data->SetMarkerStyle(20);
    h_data->SetMarkerSize (1.0);
    h_data->SetStats(0);

    TLegend *leg;

    if (title=="FATjetTau2dvTau1") {
        leg = new TLegend(0.15, 0.547, 0.41, 0.88);
    }
    else {
        leg = new TLegend(0.65, 0.547, 0.91, 0.88);
    }
//leg = new TLegend(0.65, 0.547, 0.91, 0.88);
    leg->SetBorderSize(0);
    leg->SetEntrySeparation(0.01);
    leg->SetFillColor(0);
    leg->SetFillStyle(0);

    leg->AddEntry(h_data,"Data","p");
    leg->AddEntry(h_mcDY,"DY","f");
    leg->AddEntry(h_mc2,"t#bar{t}","f");
//leg->AddEntry(h_mc3,"ZZ","f");
//leg->AddEntry(h_mc4,"WZ","f");
//leg->AddEntry(h_mc6,"WW","f");
    leg->AddEntry(h_mcDiboson,"Diboson","f");
    leg->AddEntry(h_mc7,"ZH madgraph","f");
    leg->AddEntry(h_mc8,"ZH powheg (not in stack)","f");

    leg->Draw();

    TLatex *lar = new TLatex();
    lar->SetNDC(kTRUE);
    lar->SetTextSize(0.04);
    lar->SetLineWidth(5);
    lar->DrawLatex(0.14, 0.94, "CMS #it{#bf{2016}}");
    lar->DrawLatex(0.60, 0.94, "L = 12.7 fb^{-1} at #sqrt{s} = 13 TeV");

    pad1->Update();
    c1->Update();

    c1->cd();

    TH1F *h_ratio = (TH1F*)h_data->Clone("h_ratio");

    TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);// 0.3
    pad2->SetTopMargin(0);
    pad2->SetBottomMargin(0.3);
    pad2->Draw();
    pad2->cd();
    h_ratio->SetTitle("");
    h_ratio->SetStats(0);

    if (title=="Zpt") {
        h_ratio->GetXaxis ()->SetTitle("p_{T}(Z) [GeV/c]");
    } else if (title=="Zmass") {
        h_ratio->GetXaxis ()->SetTitle("M(Z) [GeV/c^{2}]");//
    } else if (title=="ZRapidity") {
        h_ratio->GetXaxis ()->SetTitle("y(Z)");
    } else if (title=="Zeta") {
        h_ratio->GetXaxis ()->SetTitle("#eta(Z)");
    } else if (title=="nVtx") {
        h_ratio->GetXaxis ()->SetTitle("Number of Vertices");
    } else if (title=="leadElePt") {
        h_ratio->GetXaxis ()->SetTitle("Leading Electron p_{T} [GeV/c]");
    } else if (title=="subleadElePt") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading Electron p_{T} [GeV/c]");
    } else if (title=="leadEleEta") {
        h_ratio->GetXaxis ()->SetTitle("Leading Electron #eta");
    } else if (title=="subleadEleEta") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading Electron #eta");
    } else if (title=="FATjetPt") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet p_{T} [GeV/c]");
    } else if (title=="FATjetEta") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet #eta");
    } else if (title=="FATjetCISVV2") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet CSVv2");
    } else if (title=="FATjetSDmass") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet Soft Drop Mass [GeV/c^{2}]");
    } else if (title=="FATjetSDmassCorr") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet Corrected Soft Drop Mass [GeV/c^{2}]");
    }   else if (title=="FATjetPRmass") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet Pruned Mass [GeV/c^{2}]");
    } else if (title=="FATjetPRmassCorr") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet L2L3 Corrected Pruned Mass [GeV/c^{2}]");
    } else if (title=="FATjetTau1") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{1}");
    } else if (title=="FATjetTau2") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{2}");
    } else if (title=="FATjetTau2dvTau1") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{21}");
    } else if (title=="FATnSubjet") {
        h_ratio->GetXaxis ()->SetTitle("Number of Subjets");
    } else if (title=="FATsubjetLeadingPt") {
        h_ratio->GetXaxis ()->SetTitle("Leading SubJet p_{T} [GeV/c]");
    } else if (title=="FATsubjetLeadingEta") {
        h_ratio->GetXaxis ()->SetTitle("Leading SubJet #eta");
    } else if (title=="FATsubjetLeadingSDCSV") {
        h_ratio->GetXaxis ()->SetTitle("Leading SubJet Soft Drop CSV");
    } else if (title=="FATsubjetSubLeadingPt") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet p_{T} [GeV/c]");
    } else if (title=="FATsubjetSubLeadingEta") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet #eta");
    } else if (title=="FATsubjetSubLeadingSDCSV") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet Soft Drop CSV");
    } else if (title=="ADDjet_DoubleSV") {
        h_ratio->GetXaxis ()->SetTitle("ADDjet double b-tagger discriminator");
    }  else if (title=="ZHmass") {
        h_ratio->GetXaxis ()->SetTitle("ZH invariant mass [GeV/c^{2}]");
    }

    if (title=="ZHmass") {
        h_ratio->GetXaxis()->SetRangeUser(0, 3000);
    }
    h_ratio->GetXaxis()->SetTitleSize(0.11);
    h_ratio->GetXaxis()->SetLabelFont(42);
    h_ratio->GetXaxis()->SetLabelSize(0.10);
    h_ratio->GetXaxis()->SetTitleFont(42);
    h_ratio->GetYaxis()->SetTitle("Data/MC");
    h_ratio->GetYaxis()->SetNdivisions(505);
    h_ratio->GetYaxis()->SetTitleSize(0.11);
    h_ratio->GetYaxis()->SetLabelSize(0.10);
    h_ratio->GetYaxis()->SetRangeUser(0.2, 2);
    h_ratio->GetYaxis()->SetTitleOffset(0.33);

    h_ratio->Divide(ht);
    h_ratio->SetMarkerStyle(20);
    h_ratio->Draw("E0PX0");

    TLine *OLine = new TLine(h_ratio->GetXaxis()->GetXmin(),1.,h_ratio->GetXaxis()->GetXmax(),1.);
    OLine->SetLineColor(kRed);
    OLine->SetLineWidth(2);
    OLine->Draw();

    /*
    TLatex *lar = new TLatex();
    lar->SetNDC(kTRUE);
    lar->SetTextSize(0.04);
    lar->SetLineWidth(5);
    lar->DrawLatex(0.14, 0.94, "CMS #it{#bf{2016}}");
    lar->DrawLatex(0.60, 0.94, "L = 4.327 fb^{-1} at #sqrt{s} = 13 TeV");
    */

    c1->cd();
//c1->SaveAs((path + title + ".pdf").c_str());

}
Exemple #18
0
THStack* BasePlot::GetStack(bool isLog)  {
    THStack* hstack = new THStack();

    float binWidth = 0;
    for (int i=0; i<nSamples; i++) if( _hist[i] && i != iHWW) {

        _hist[i]->SetLineColor(sampleColor[i]);
        _hist[i]->SetFillColor(sampleColor[i]);
        _hist[i]->SetFillStyle(1001);
        binWidth = _hist[i]->GetBinWidth(1);

        hstack->Add(_hist[i]);
    }

    for (size_t i=0; i<_autreHists.size(); i++) {

        _autreHists[i].second->SetLineColor(autreColors[i]);
        _autreHists[i].second->SetFillColor(autreColors[i]);
        _autreHists[i].second->SetFillStyle(1001);

        hstack->Add(_autreHists[i].second);
    }


    hstack->Draw("GOFF");
    if(_prelim) hstack->SetTitle("CMS preliminary");
    else        hstack->SetTitle("CMS, #sqrt{s} = 7 TeV");

    Float_t theMax = hstack->GetMaximum();
    Float_t theMin = hstack->GetMinimum();

    if (_hist[iHWW]) {
        if (_hist[iHWW]->GetMaximum() > theMax) theMax = _hist[iHWW]->GetMaximum();
        if (_hist[iHWW]->GetMinimum() < theMin) theMin = _hist[iHWW]->GetMinimum();
    }

    if (_data) {
        Float_t dataMax = GetMaximumIncludingErrors(_data);
        if (dataMax > theMax) theMax = dataMax;
    }

    int sampCount = GetSampCount();
    float scaleBy = 1.35 + 0.2*(sampCount>6) + 0.2*(sampCount>10) + 0.2*(sampCount>14);

    // Min --- only need to change if log
    theMin = theMin==0?0.1:theMin/10;
    if(isLog) hstack->SetMinimum(theMin);

    // Max
    if (_myMax != -1) {
        hstack->SetMaximum(_myMax);
    } else if (isLog) {
        hstack->SetMaximum(pow(10,(log(theMax)/log(10)-log(theMin)/log(10)+1)*scaleBy+log(theMin)/log(10)-1));
    } else {
        hstack->SetMaximum(scaleBy * theMax);
    }


    if(_breakdown) {
        THStackAxisFonts(hstack, "y", "entries");
        hstack->GetHistogram()->LabelsOption("v");
    } else {
        THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
        THStackAxisFonts(hstack, "y", TString::Format("entries / %.1f %s", binWidth,_units.Data()));
        if(_units.Sizeof() == 1) {
            THStackAxisFonts(hstack, "x", _xLabel.Data());
//            THStackAxisFonts(hstack, "y", "entries");
        }
    }
    return hstack;
}
Exemple #19
0
void fake()
{
   gROOT->SetBatch();
   gROOT->SetStyle("Plain");
   
   gStyle->SetOptStat(0);

   SetStyle();
   
   TCanvas *c1 = new TCanvas("c1","c1",0,0,600,500);
   c1->Draw();
   c1->cd();

   TPad *c1_1;
   
   gStyle->SetHistTopMargin(0);

   TLegend *leg = new TLegend(0.65,0.90,0.90,0.70);
   leg->SetFillColor(253);
   leg->SetBorderSize(0);

   std::string fpath = "histTEST_MERGED/QCD_Pt_170to300_TuneCUETP8M1_13TeV_pythia8/data.root";

//   std::string histnameFake = "h_muFake_pt";
//   std::string histnameReal = "h_muReal_pt";

//   std::string histnameFake = "h_muFake_trackerLayersWithMeasurement";
//   std::string histnameReal = "h_muReal_trackerLayersWithMeasurement";

//   std::string histnameFake = "h_muFake_numberOfValidMuonHits";
//   std::string histnameReal = "h_muReal_numberOfValidMuonHits";

//   std::string histnameFake = "h_muFake_numberOfMatches";
//   std::string histnameReal = "h_muReal_numberOfMatches";

//   std::string histnameFake = "h_muFake_numberOfMatchedStations";
//   std::string histnameReal = "h_muReal_numberOfMatchedStations";

//   std::string histnameFake = "h_muFake_numberOfValidHits";
//   std::string histnameReal = "h_muReal_numberOfValidHits";

//   std::string histnameFake = "h_muFake_numberOfValidPixelHits";
//   std::string histnameReal = "h_muReal_numberOfValidPixelHits";

   std::string histnameFake = "h_muFake_numberOfHits";
   std::string histnameReal = "h_muReal_numberOfHits";

//   std::string histnameFake = "h_muFake_normalizedChi2GlobalTrack";
//   std::string histnameReal = "h_muReal_normalizedChi2GlobalTrack";

//   std::string histnameFake = "h_muFake_normalizedChi2InnerTrack";
//   std::string histnameReal = "h_muReal_normalizedChi2InnerTrack";
   
   TFile *f;

   TH1D *hFake;
   TH1D *hReal;
   
   f = TFile::Open(fpath.c_str());
   
     {	
	TH1D *hFake_c = (TH1D*)f->Get(histnameFake.c_str());
	hFake_c->SetMarkerSize(0.0);

	TH1D *hReal_c = (TH1D*)f->Get(histnameReal.c_str());
	hReal_c->SetMarkerSize(0.0);

	hFake = (TH1D*)hFake_c->Clone("hFake");
	hReal = (TH1D*)hReal_c->Clone("hReal");
     }
   
   addbin(hFake);
   addbin(hReal);
   
   std::cout << hReal->Integral() << std::endl;
   std::cout << hFake->Integral() << std::endl;
   
   double iFake = hFake->Integral();
   double iReal = hReal->Integral();
//   double iAll = iFake+iReal;
   
//   hFake->Scale(1./iAll);
//   hReal->Scale(1./iAll);
   
   hFake->SetLineColor(9);
   hFake->SetFillColor(9);
   hReal->SetLineColor(46);
   hReal->SetFillColor(46);
   
   THStack *hst = new THStack();
   hst->Add(hReal);
   hst->Add(hFake);
   
   hst->Draw("hist e1");

   float max = hst->GetMaximum();
   
   hst->SetMaximum(1.3*max);
   hst->SetMinimum(0.);

   if( histnameFake == "h_muFake_pt" ) hst->GetXaxis()->SetTitle("p_{T} [GeV]");
   
   hst->GetYaxis()->SetTitle("Number of muons");
   
   leg->AddEntry(hFake,"Fake","f");
   leg->AddEntry(hReal,"Real","f");
   
   leg->Draw();
   
   c1->Print("pics/fake.eps");
   c1->Clear();

   TH1F *hRealScaled = (TH1F*)hReal->Clone("hRealScaled");
   hRealScaled->Scale(1./iReal);

   TH1F *hFakeScaled = (TH1F*)hFake->Clone("hFakeScaled");
   hFakeScaled->Scale(1./iFake);

   hFakeScaled->SetLineColor(9);
   hFakeScaled->SetFillColor(0);
   hRealScaled->SetLineColor(46);
   hRealScaled->SetFillColor(0);
   
   hRealScaled->Draw("hist e1");
   hFakeScaled->Draw("hist e1 same");

   float max1 = hRealScaled->GetMaximum();
   float max2 = hFakeScaled->GetMaximum();
   max = (max1 > max2) ? max1 : max2;
   
   hRealScaled->SetMaximum(1.3*max);
   hRealScaled->SetMinimum(0.);

   if( histnameFake == "h_muFake_pt" ) hRealScaled->GetXaxis()->SetTitle("p_{T} [GeV]");
   if( histnameFake == "h_muFake_trackerLayersWithMeasurement" ) hRealScaled->GetXaxis()->SetTitle("trackerLayersWithMeasurement");
   if( histnameFake == "h_muFake_numberOfValidMuonHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidMuonHits");
   if( histnameFake == "h_muFake_numberOfMatches" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatches");
   if( histnameFake == "h_muFake_numberOfMatchedStations" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatchedStations");
   if( histnameFake == "h_muFake_numberOfValidHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidHits");
   if( histnameFake == "h_muFake_numberOfValidPixelHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidPixelHits");
   if( histnameFake == "h_muFake_numberOfHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfHits");
   if( histnameFake == "h_muFake_normalizedChi2GlobalTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2GlobalTrack");
   if( histnameFake == "h_muFake_normalizedChi2InnerTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2InnerTrack");
   
   hRealScaled->GetYaxis()->SetTitle("Normalized to unity");
   
   leg->Draw();
   
   c1->Print("pics/fakeComp.eps");
   c1->Clear();
   
   gApplication->Terminate();
}
Exemple #20
0
// *************************************** //
// this is a function that takes a set of  //
// histograms and draws them on a canvas   //
// in a stack, returning the canvas.       //
// It also plots the signal as a dashed    //
// line and the data with a ratio at the   //
// the bottom of data/allBackgrounds       //
// *************************************** //
TCanvas* drawPlots::plotAll(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal, TH1D* data, TH1D* errDown, TH1D* errUp, bool isSignalRegion, bool doLogAxis){
         
   const unsigned int MAINPLOT_WIDTH  = 800;
   const unsigned int MAINPLOT_HEIGHT = 500;
   const unsigned int RATIOPLOT_HEIGHT = 125;
   const unsigned int OFFSET = 10;
   
  //LUKE: Title offset and title size are proportional in 
  //root, so you have to change them together, 
  //this makes me a sad panda 
   const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.4;
   const double RATIOPLOT_YAXIS_TITLE_SIZE   = 0.14;
   const double RATIOPLOT_YAXIS_TICK_LENGTH  = 0.01;
   const double RATIOPLOT_YAXIS_LABEL_SIZE   = 0.15;
  
   const double RATIOPLOT_XAXIS_TITLE_OFFSET = 0.9;
   const double RATIOPLOT_XAXIS_TITLE_SIZE   = 0.2;
   const double RATIOPLOT_XAXIS_TICK_LENGTH  = 0.05;
   const double RATIOPLOT_XAXIS_LABEL_SIZE   = 0.2;
   
   const double CANVAS_HEIGHT = MAINPLOT_HEIGHT+RATIOPLOT_HEIGHT+OFFSET;
   
   TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,CANVAS_HEIGHT);
   
   canvas->SetMargin(0.,0.,0.,0.);
   canvas->Clear();
   canvas->cd();
   
   // create main pad
   const double mainPad_ylow  = (CANVAS_HEIGHT - MAINPLOT_HEIGHT)/CANVAS_HEIGHT;
   const double mainPad_yhigh = 1.;
  
   const double pad_margin_left = 0.15;
   const double pad_margin_right  = 0.05;
   
   double main_y_max = -99;
   double main_y_min = -99;
   double main_x_max = -99;
   double main_x_min = -99;
   for(int a=0; a<histos.size(); a++){
     if(histos[a]){
       if(histos[a]->GetEntries()> 0.){
	 GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max);
       }
     }
   }
   
   if(data){
     int maxBinData = data->GetMaximumBin();
     double dataYmax = data->GetBinContent(maxBinData);
     if(dataYmax > main_y_max) main_y_max = dataYmax;
   }

   // create main pad
   TPad* mainPad = new TPad("main","main",0.,mainPad_ylow,1.,mainPad_yhigh);
   mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top
   mainPad->Draw();
   mainPad->cd();

   SetAtlasStyle();

   if(doLogAxis)mainPad->SetLogy();

   // clone signal or data because one should exist for each plot
   TH1D* allBackgrounds;
   bool gotSomething=false;
   if(signal)
     allBackgrounds = (TH1D*)signal->Clone("all_backgrounds");
   else if(data)
     allBackgrounds = (TH1D*)data->Clone("all_backgrounds");
   else{
     for(int b=0; b<histos.size(); b++){
       if(histos[b] && !gotSomething){
	 allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds");
	 gotSomething=true;
       }
     }  
   }

   // set all bins to zero so that you can add all histograms to it
   for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++)
      allBackgrounds->SetBinContent(i,0);
   
   THStack* Stack = new THStack();
   std::string title = std::string(";") + axisName + ";Events";
   Stack->SetTitle(title.c_str());
   
   for(int b=0; b<histos.size(); b++){
     if(histos[b]){
       if(histos[b]->GetEntries() > 0.){
	 histos[b]->SetLineColor(1);
	 histos[b]->SetFillColor(tools::setColor(names[b]));
	 Stack->Add(histos[b]);
	 for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){
	   double binContent=allBackgrounds->GetBinContent(j)+histos[b]->GetBinContent(j);
	   allBackgrounds->SetBinContent(j,binContent);
	 }
       }
     }
   }

   TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio");
   
   if(doLogAxis){ 
     main_y_max = main_y_max*10;
     if(Stack->GetMinimum()>.1) Stack->SetMinimum(.1);
   }
   else main_y_max = main_y_max*1.4;
   Stack->SetMaximum(main_y_max);
   Stack->Draw("hist");
   errDown->Draw("E2same");
   errUp->Draw("E2Same");
   
   // make error histograms for the ratio plot
   TH1D* ratioErrDown = (TH1D*) errDown->Clone("ratio_error_down");
   TH1D* ratioErrUp = (TH1D*) errUp->Clone("ratio_error_up");

   ratioErrDown->Divide(backgroundsForRatio);
   ratioErrUp->Divide(backgroundsForRatio);

   if(!isSignalRegion && data)
      data->Draw("e same");

   if(signal){
     signal->SetLineStyle(2);
     signal->SetLineColor(kRed);
     signal->SetLineWidth(5);
     signal->Draw("hist same");
   }

   TLegend* leg = new TLegend(0.8,0.65,0.95,0.9);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   
   if(signal)
     leg->AddEntry(signal, "Signal", "l");
   if(!isSignalRegion)
     leg->AddEntry(data, "Data");
   for(int q=0; q<histos.size(); q++){
     if(histos[q]){
       if(histos[q]->GetEntries() > 0.)
	 leg->AddEntry(histos[q], names[q].c_str(), "f");
     }
   }
   leg->Draw("lpe");
   
   ATLAS_LABEL(0.2,0.85,1);
   char text[]="#sqrt{s}=8 TeV";
   myText(0.6,0.75,1,.04, text);
   char text_L[]="#int L dt = 20.3 fb^{-1}";
   myText(0.6, 0.85,1, .04, text_L);
   char inText[100];
   int t;
   if(signal)
     t=sprintf(inText, "N_{Signal} = %.1f", signal->Integral(0,signal->GetNbinsX()+1));
   else
     t=sprintf(inText, "N_{Signal} = %.1f", 0.);
   myText(0.2, 0.75, 1, .04, inText);
   double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1);
   if(back_int > 10000.)
     t=sprintf(inText, "N_{Bkgd} = %.3e", back_int);
   else
     t=sprintf(inText, "N_{Bkgd} = %.1f", back_int);
   myText(0.2, 0.7, 1, .04, inText);
   if(!isSignalRegion){
     if(data)
       t=sprintf(inText, "N_{Data} = %.0f", data->Integral(0,data->GetNbinsX()+1));
     else
       t=sprintf(inText, "N_{Data} = %.0f", 0.);
     myText(0.2, 0.65, 1, .04, inText);
   }
   
   canvas->cd();
   
   // Draw Ratio plot
   double ratio_max = 1.6;
   double ratio_min = 0.4;
  
   const double x_axis_size = 0.4;
   const double ratio_pad_height = RATIOPLOT_HEIGHT/CANVAS_HEIGHT;
   
   double pad_xlow = 0.,pad_xhigh = 1.;
   double pad_ylow = OFFSET/CANVAS_HEIGHT,pad_yhigh = ratio_pad_height;
   
   const char* pad_name = "pad";
   TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh);
   
   pad4ratio->SetMargin(pad_margin_left,pad_margin_right,x_axis_size,0.);
   pad4ratio->Draw();
   pad4ratio->cd();

   TH1D* ratioPlot;
   if(data) ratioPlot = (TH1D*)data->Clone("ratio");
   else if(signal) ratioPlot = (TH1D*)signal->Clone("ratio"); // if there is no data then use signal for axis 
   ratioPlot->SetTitle("");
   ratioPlot->GetYaxis()->SetTitle("Data/MC");
   ratioPlot->GetXaxis()->SetTitle(axisName.c_str());
   if(data){
     ratioPlot->Divide(allBackgrounds);
     // here change ratio_min and ratio_max if the ratio plot is quite flat
     double maxDeviation=0;
     double tempDev=0;
     for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){
       tempDev = std::abs(ratioPlot->GetBinContent(ibin)-1.);
       if(tempDev > maxDeviation) maxDeviation = tempDev;
     }
     if(maxDeviation < 0.1){
       ratio_max = 1.12;
       ratio_min = 0.88;
     }
     else if(maxDeviation < 0.2){
       ratio_max = 1.25;
       ratio_min = .75;
     }
     ratioPlot->SetMinimum(ratio_min);
     ratioPlot->SetMaximum(ratio_max);
   }
   ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE);
   ratioPlot->GetXaxis()->SetTickLength(RATIOPLOT_XAXIS_TICK_LENGTH);
   ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE);
   ratioPlot->GetYaxis()->SetTickLength(RATIOPLOT_YAXIS_TICK_LENGTH);
   ratioPlot->GetYaxis()->SetNdivisions(3);
   ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE);
   ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET);
   ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE);
   ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET);
   
   if(!isSignalRegion && data){
     ratioPlot->Draw();
     // plot horizontal line at y=1
     TF1* horizontal = new TF1("horizontal","pol1",-10000,10000);
     horizontal->SetParameter(0,1.);
     horizontal->SetParameter(1,0.);
     horizontal->SetLineColor(kBlack);
     horizontal->SetLineStyle(2);
     horizontal->SetLineWidth(1);
     horizontal->Draw("same");
     ratioErrDown->Draw("E2same");
     ratioErrUp->Draw("E2same");
   }else if(isSignalRegion){
     ratioPlot->Draw("axis");
     char text[]="DATA IS BLINDED HERE";
     myText(0.4,0.6,1,.2,text);
   }else{ // in this case it is not the signal region but there is no data
     ratioPlot->Draw("axis");
     char text[]="NO DATA";
     myText(0.4,0.6,1,.2,text);
     }
   
   return canvas;
}
//------------------------------------------------------------------------------
// PlotHiggsRes_LP
//------------------------------------------------------------------------------
void RunMakeRazorPlots ( string signalfile, string signalLabel,  vector<string> bkgfiles,vector<string> bkgLabels, int boxOption = 0, int option = -1, string label = "", string latexlabel = "") {

  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //============================================================================================================== 
  double intLumi = 2000; //in units of pb^-1
  string Label = "";
  if (label != "") Label = "_" + label;

  vector<string> inputfiles;
  vector<string> processLabels;

  bool hasSignal = false;
  if (signalfile != "") {
    hasSignal = true;
    inputfiles.push_back(signalfile);
    processLabels.push_back(signalLabel);
  }
  assert(bkgfiles.size() == bkgLabels.size());
  for (int i=0; i < bkgfiles.size(); ++i) {
     inputfiles.push_back(bkgfiles[i]);
     processLabels.push_back(bkgLabels[i]);
  }

  //*******************************************************************************************
  //Define Histograms
  //*******************************************************************************************
  TH1F* histMRAllBkg =  new TH1F( "MRAllBkg",";M_{R} [GeV/c^{2}];Number of Events", 100, 400, 2400);
  TH1F* histRsqAllBkg =  new TH1F( "RsqAllBkg", ";R^{2};Number of Events", 24, 0.25, 1.45);
  histMRAllBkg->SetStats(false);
  histRsqAllBkg->SetStats(false);
  
  vector<TH1F*> histMR;
  vector<TH1F*> histRsq; 

  vector<TH2F*> histMRRsq;
  vector<TH1F*> histUnrolled; 
  vector<TH1F*> histUnrolled2bins; 
  vector<TH1F*> histUnrolledPercentage; 
  vector<TH1F*> histUnrolledPercentage2bins; 

  //  float MRBinLowEdges[] = {500, 600, 700, 900, 1200, 1600, 2500, 4000};
  //  float RsqBinLowEdges[] = {0.25, 0.30, 0.41, 0.52, 0.64, 1.5};

  // float MRBinLowEdges[] = {500, 600, 700, 900, 1200, 1600, 2500, 4000}; // Multijet Bins
  // float RsqBinLowEdges[] = {0.25, 0.30, 0.41, 0.52, 0.64, 1.5}; // Multijet Bins

  float MRBinLowEdges[] = {400, 500, 600, 700, 900, 1200, 1600, 2500, 4000}; // Lepton boxes
  float RsqBinLowEdges[] = {0.15, 0.20, 0.25, 0.30, 0.41, 0.52, 0.64, 1.5};  // Lepton boxes


  const int nMRBins = sizeof(MRBinLowEdges)/sizeof(float)-1;
  const int nRsqBins = sizeof(RsqBinLowEdges)/sizeof(float)-1;

  std::cout<<"AAAAAAA "<<nMRBins<<" "<<nRsqBins<<std::endl;

  assert (inputfiles.size() == processLabels.size());

  for (int i=0; i < inputfiles.size(); ++i) {    
    // histMR.push_back( new TH1F( Form("MR_%s",processLabels[i].c_str()), ";M_{R} [GeV/c^{2}];Number of Events", 100, 400, 2400));
    histMR.push_back( new TH1F( Form("MR_%s",processLabels[i].c_str()), ";M_{R} [GeV/c^{2}];Number of Events", nMRBins, MRBinLowEdges));
    if (!hasSignal || i != 0) histMR[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histMR[i]->SetLineWidth(3);
    histMR[i]->SetLineColor(color[i]);    
    histMR[i]->SetStats(false);    
    histMR[i]->Sumw2();

    // histRsq.push_back( new TH1F( Form("Rsq_%s",processLabels[i].c_str()), ";R^{2} ;Number of Events", 24, 0.25, 1.45));
    histRsq.push_back( new TH1F( Form("Rsq_%s",processLabels[i].c_str()), ";R^{2} ;Number of Events", nRsqBins, RsqBinLowEdges));
    if (!hasSignal || i != 0) histRsq[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histRsq[i]->SetLineWidth(3);
    histRsq[i]->SetLineColor(color[i]);
    histRsq[i]->SetStats(false);

    histMRRsq.push_back( new TH2F( Form("MRRsq_%s",processLabels[i].c_str()), ";M_{R} [GeV/c^{2}]; R^{2}", nMRBins, MRBinLowEdges, nRsqBins, RsqBinLowEdges));
    if (!hasSignal || i != 0) histMRRsq[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histMRRsq[i]->SetLineWidth(3);
    histMRRsq[i]->SetLineColor(color[i]);
    histMRRsq[i]->SetStats(false);
    histMRRsq[i]->Sumw2();

    histUnrolled.push_back( new TH1F( Form("Unrolled_%s",processLabels[i].c_str()), ";Bin Number ;Number of Events", nMRBins*nRsqBins, 0, nMRBins*nRsqBins));
    if (!hasSignal || i != 0) histUnrolled[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolled[i]->SetLineWidth(3);
    histUnrolled[i]->SetLineColor(color[i]);
    histUnrolled[i]->SetStats(false);     

    histUnrolled2bins.push_back( new TH1F( Form("Unrolled2bins_%s",processLabels[i].c_str()), ";Bin Number ;Event Density", 3, 0, 3));
    if (!hasSignal || i != 0) histUnrolled2bins[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolled2bins[i]->SetLineWidth(3);
    histUnrolled2bins[i]->SetLineColor(color[i]);
    histUnrolled2bins[i]->SetStats(false);     

    histUnrolledPercentage2bins.push_back( new TH1F( Form("UnrolledPercentage2bins_%s",processLabels[i].c_str()), ";;Event Density", 3, 0, 3));
    if (!hasSignal || i != 0) histUnrolledPercentage2bins[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolledPercentage2bins[i]->SetLineWidth(3);
    histUnrolledPercentage2bins[i]->SetLineColor(color[i]);
    histUnrolled2bins[i]->SetStats(false);     

    histUnrolledPercentage.push_back( new TH1F( Form("UnrolledPercentage_%s",processLabels[i].c_str()), ";Bin Number ; Fraction of total", nMRBins*nRsqBins, 0, nMRBins*nRsqBins));
    if (!hasSignal || i != 0) histUnrolledPercentage[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolledPercentage[i]->SetLineWidth(3);
    histUnrolledPercentage[i]->SetLineColor(color[i]);
    histUnrolledPercentage[i]->SetStats(false);     
}

  //*******************************************************************************************
  //Define Counts
  //*******************************************************************************************


  //*******************************************************************************************
  //Read files
  //*******************************************************************************************
  for (uint i=0; i < inputfiles.size(); ++i) {

    TFile* inputFile = new TFile(inputfiles[i].c_str(),"READ");
    assert(inputFile);
    TTree* tree = 0;
    tree = (TTree*)inputFile->Get("RazorInclusive");
 
    float weight = 0;
    int box = -1;
    int nBTaggedJets = 0;
    float dPhiRazor = 0;
    float MR = 0;
    float Rsq = 0;
    float mT = 0;
    int nGenMuons = 0;
    int nGenElectrons = 0;
    int nGenTaus = 0;

    // bool Flag_HBHENoiseFilter = false;
    // bool Flag_goodVertices    = false;
    // bool Flag_eeBadScFilter   = false;
    // bool Flag_EcalDeadCellTriggerPrimitiveFilter = false;


    tree->SetBranchAddress("weight",&weight);
    tree->SetBranchAddress("box",&box);
    tree->SetBranchAddress("nBTaggedJets",&nBTaggedJets);
    tree->SetBranchAddress("dPhiRazor",&dPhiRazor);
    tree->SetBranchAddress("MR",&MR);
    tree->SetBranchAddress("Rsq",&Rsq);
    tree->SetBranchAddress("mT",&mT);
    tree->SetBranchAddress("nGenMuons",&nGenMuons);
    tree->SetBranchAddress("nGenElectrons",&nGenElectrons);
    tree->SetBranchAddress("nGenTaus",&nGenTaus);
    // tree->SetBranchAddress("Flag_HBHENoiseFilter",&Flag_HBHENoiseFilter);
    // tree->SetBranchAddress("Flag_goodVertices",&Flag_goodVertices);
    // tree->SetBranchAddress("Flag_eeBadScFilter",&Flag_eeBadScFilter);
    // tree->SetBranchAddress("Flag_EcalDeadCellTriggerPrimitiveFilter",&Flag_EcalDeadCellTriggerPrimitiveFilter);
 

    cout << "Process : " << processLabels[i] << " : Total Events: " << tree->GetEntries() << "\n";
    for (int n=0;n<tree->GetEntries();n++) { 
    // for (int n=0;n<10000;n++) { 
    
      tree->GetEntry(n);
      if (n % 1000000 == 0) cout << "Processing Event " << n << "\n";       

      // if (intLumi*weight > 100) continue;

      //Box Options
      if (option == 0 ) {
	if (nBTaggedJets != 0) continue; 
      }
      if (option == 1 ) {
	if (nBTaggedJets != 1) continue;
      }
      if (option == 2 ) {
	if (nBTaggedJets != 2) continue;
      }
      if (option == 3 ) {
	if (nBTaggedJets < 3) continue;
      }
      if (option == 4 ) {
	if (nBTaggedJets < 0) continue; // all b-tag categories combined
      }

     //Box Options
      if (boxOption == 0) { // Multijet Box for Jamboree
	if( !(box == 11 || box == 12) ) continue;
      }
      if (boxOption == 1) { // MuonMultijet Box for Jamboree
	if( !(box == 3 || box == 4) ) continue;
      } 
      if (boxOption == 2) { // EleMultijet Box for Jamboree
	if( !(box == 6 || box == 7) ) continue;
      }

      // LeptonMultijet Box for Jamboree
      if(boxOption == 1 || boxOption == 2)
	if(mT<120) continue;

      // Multijet Box for Jamboree
      if (boxOption == 0)
	if(fabs(dPhiRazor) > 2.8) continue;

      //apply baseline cuts
      if(boxOption == 1 || boxOption == 2) 
	if (!(MR > 400 && Rsq > 0.15)) continue;
      
      if(boxOption == 0) 
	if (!(MR > 500 && Rsq > 0.25)) continue;

      // if(!Flag_HBHENoiseFilter) continue;
      // if(!Flag_goodVertices) continue;
      // if(!Flag_EcalDeadCellTriggerPrimitiveFilter) continue;
      // if(!Flag_eeBadScFilter) continue;
      
      // fill the histos
      if (!hasSignal || i>0) {
	histMRAllBkg->Fill(MR, intLumi*weight);
	histRsqAllBkg->Fill(Rsq, intLumi*weight);
      }
            
      if(strstr(processLabels[i].c_str(), "TTJets")==NULL && strstr(processLabels[i].c_str(), "T1bbbb")==NULL)
      	histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
      
      // if(strstr(processLabels[i].c_str(), "T1bbbb")!=NULL)
      // 	histMRRsq[i]->Fill(MR, Rsq, intLumi*weight*2.69506e-07);
      
      histMR[i]->Fill(MR, intLumi*weight);
      histRsq[i]->Fill(Rsq, intLumi*weight);
      
      // separate by number of gen leptons for lepton boxes
      if(boxOption==1 || boxOption==2)
	{
	  if(strstr(processLabels[i].c_str(), "TTJets")!=NULL && strstr(bkgLabels[i].c_str(), "2L")!=NULL) {
	    if(nGenMuons+nGenElectrons>=2)
	      histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
	  }
	  else if(strstr(processLabels[i].c_str(), "TTJets")!=NULL && strstr(bkgLabels[i].c_str(), "Tau")!=NULL) {
	    if((nGenMuons+nGenElectrons+nGenTaus>=2) && !(nGenMuons+nGenElectrons>=2))
	      histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
	  }
	  else if(strstr(processLabels[i].c_str(), "TTJets")!=NULL && strstr(bkgLabels[i].c_str(), "1L")!=NULL) {
	    if(!(nGenMuons+nGenElectrons>=2) && !(nGenMuons+nGenElectrons+nGenTaus>=2))
	      histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
	  }
	}
      
	// Multijet box top
      	if(boxOption==0)
	  if(strstr(processLabels[i].c_str(), "TTJets")!=NULL) {
	    histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
	  }
      }

    inputFile->Close();
    delete inputFile;
  }
  
  //*******************************************************************************************
  //Draw Plots
  //*******************************************************************************************
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.7,0.53,0.90,0.88);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }

  THStack *stackUnrolled = new THStack();
  THStack *stackUnrolled2bins = new THStack();
  THStack *stackUnrolledPercentage = new THStack();
  THStack *stackUnrolledPercentage2bins = new THStack();

  float bintotal[nMRBins*nRsqBins] = {0.};

  // fill out the unrolled histograms 
  for (uint i=0; i < histMRRsq.size(); ++i) {
    
    int binN = 0;
    float total_SB = 0.;
    float total_SR = 0.;

    for(int ii = 0; ii<nMRBins; ii++)
      for (int jj = 0; jj<nRsqBins; jj++)      
  	{      
  	  float value = (histMRRsq[i]->GetBinContent(ii+1, jj+1) > 0) ? histMRRsq[i]->GetBinContent(ii+1, jj+1) : 0. ;
	  
	  float Xrange = histMRRsq[i]->GetXaxis()->GetBinLowEdge(ii+2) - histMRRsq[i]->GetXaxis()->GetBinLowEdge(ii+1);
	  float Yrange = histMRRsq[i]->GetYaxis()->GetBinLowEdge(jj+2) - histMRRsq[i]->GetYaxis()->GetBinLowEdge(jj+1);

	  float area =1.;
	  
	  if(density) area = Xrange*Yrange; //normalize each bin by its area

	  histUnrolled[i]->SetBinContent(binN+1, value/area);

	  if(!hasSignal || i>0)
	    bintotal[binN+1] += value/area;	 
	  
	  if(ii<1 || jj<1)
	    total_SB += value/area;
	  else
	    total_SR += value/area;
	  	  
  	  binN++;
  	}

    histUnrolled2bins[i]->SetBinContent(1, total_SB);
    histUnrolled2bins[i]->SetBinContent(2, total_SR);

    histUnrolled[i]->SetMinimum(0.00001);

    if ( histUnrolled[i]->Integral() > 0) {
      if( !hasSignal || i > 0 )
	stackUnrolled->Add(histUnrolled[i]);
    }

    if ( histUnrolled[i]->Integral() > 0) {
      if( !hasSignal || i > 0 )
	stackUnrolled2bins->Add(histUnrolled2bins[i]);
    }

    cout << "Process : " << processLabels[i] << "\n";	  
  }


  // Unroll into two bins for fractions
  float AllBkg_SB = 0;
  float AllBkg_SR = 0;

  for (uint i=0; i < histMRRsq.size(); ++i) {
    if( !hasSignal || i > 0 ){
      AllBkg_SB += histUnrolled2bins[i]->GetBinContent(1);
      AllBkg_SR += histUnrolled2bins[i]->GetBinContent(2);
    }
  }

  for (uint i=0; i < histMRRsq.size(); ++i) {
    if( !hasSignal || i > 0 ){
      histUnrolledPercentage2bins[i]->SetBinContent(1, histUnrolled2bins[i]->GetBinContent(1)/AllBkg_SB);
      histUnrolledPercentage2bins[i]->SetBinContent(2, histUnrolled2bins[i]->GetBinContent(2)/AllBkg_SR);
    }
    
    if ( histUnrolled2bins[i]->Integral() > 0) {
      if( !hasSignal || i > 0 )
	stackUnrolledPercentage2bins->Add(histUnrolledPercentage2bins[i]);
    }
  }
  
  ///
  // fill out the unrolled percentage histograms 
  for (uint i=0; i < histMRRsq.size(); ++i) {
    if( hasSignal && i == 0 ) continue;
      
    int binN = 0;

    for(int ii = 0; ii<nMRBins; ii++)
      for (int jj = 0; jj<nRsqBins; jj++)      
  	{      
  	  float value = (histMRRsq[i]->GetBinContent(ii+1, jj+1) > 0) ? histMRRsq[i]->GetBinContent(ii+1, jj+1) : 0. ;
	  
	  float Xrange = histMRRsq[i]->GetXaxis()->GetBinLowEdge(ii+2) - histMRRsq[i]->GetXaxis()->GetBinLowEdge(ii+1);
	  float Yrange = histMRRsq[i]->GetYaxis()->GetBinLowEdge(jj+2) - histMRRsq[i]->GetYaxis()->GetBinLowEdge(jj+1);

	  float area =1.;
	  
	  if(density) area = Xrange*Yrange; //normalize each bin by its area

	  if(bintotal[binN+1]>0)
	    histUnrolledPercentage[i]->SetBinContent(binN+1, (value/area)/bintotal[binN+1]);

	  binN++;
	}
		
    if ( histUnrolled[i]->Integral() > 0) {
	stackUnrolledPercentage->Add(histUnrolledPercentage[i]);
    }

    cout << "Unrolling Percentage for Process : " << processLabels[i] << "\n";	  
  }

  /// Unrolled plots in bins of R&MR
  TLatex t1(0.1,0.92, "CMS Preliminary");
  TLatex t2(0.6,0.92, "#sqrt{s}=13 TeV, L = 2 fb^{-1}");
  TLatex t3(0.4,0.92, Form("%s",latexlabel.c_str()) );
  t1.SetNDC();
  t2.SetNDC();
  t3.SetNDC();
  t1.SetTextSize(0.05);
  t2.SetTextSize(0.05);
  t3.SetTextSize(0.02);
  t1.SetTextFont(42);
  t2.SetTextFont(42);
  t3.SetTextFont(42);

  stackUnrolled->Draw();
  stackUnrolled->SetMinimum(0.0001);
  // stackUnrolled->SetMaximum(1000);
  cv->SetLogy();
  stackUnrolled->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolled->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackUnrolled->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolled->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackUnrolled->Draw();
  if(hasSignal) histUnrolled[0]->Draw("same hist");
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("Unrolled%s.pdf",Label.c_str()));

  // Unrolled plots in percentages
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.85,0.20,0.95,0.80);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }
  stackUnrolledPercentage->Draw();
  stackUnrolledPercentage->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolledPercentage->GetHists()->At(0)))->GetXaxis()->GetTitle());
  // stackUnrolledPercentage->GetHistogram()->GetXaxis()->SetRangeUser(0, 35);
  stackUnrolledPercentage->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolledPercentage->GetHists()->At(0)))->GetYaxis()->GetTitle());
  if(hasSignal) histUnrolledPercentage[0]->Draw("same hist"); 
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("UnrolledPercentage%s.pdf",Label.c_str()));

  // Unrolled plots in sideband vs signal box
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.85,0.20,0.95,0.80);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }
  stackUnrolled2bins->Draw();
  stackUnrolled2bins->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolled2bins->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackUnrolled2bins->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolled2bins->GetHists()->At(0)))->GetYaxis()->GetTitle());
  if(hasSignal) histUnrolled2bins[0]->Draw("same hist");
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("Unrolled2bins%s.pdf",Label.c_str()));

  // Unrolled plots in sideband vs signal box in fractions
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.7,0.23,0.90,0.88);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }

  stackUnrolledPercentage2bins->Draw();
  stackUnrolledPercentage2bins->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolledPercentage2bins->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackUnrolledPercentage2bins->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolledPercentage2bins->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackUnrolledPercentage2bins->GetHistogram()->GetXaxis()->SetBinLabel(1, "Sideband");
  stackUnrolledPercentage2bins->GetHistogram()->GetXaxis()->SetBinLabel(2, "Signal Sensitive Region");
  if(hasSignal) histUnrolledPercentage2bins[0]->Draw("same hist");
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("UnrolledPercentage2bins%s.pdf",Label.c_str()));


   //--------------------------------------------------------------------------------------------------------------
  // Output
  //==============================================================================================================
  TFile *file = TFile::Open(("RazorPlots"+Label+".root").c_str(), "RECREATE");
  file->cd();

  for(int i=0; i<int(inputfiles.size()); i++) {
    file->WriteTObject(histMR[i], Form("histMR_%s",processLabels[i].c_str()), "WriteDelete");
    file->WriteTObject(histRsq[i], Form("histRsq_%s",processLabels[i].c_str()), "WriteDelete");
    file->WriteTObject(histMRRsq[i], Form("histMRRsq_%s",processLabels[i].c_str()), "WriteDelete");
    histUnrolled[i]->Write();  
    histUnrolled2bins[i]->Write();  
    histUnrolledPercentage[i]->Write();  
    histUnrolledPercentage2bins[i]->Write();  
  }
  
  stackUnrolled->Write();
  stackUnrolled2bins->Write();
  stackUnrolledPercentage->Write();
  stackUnrolledPercentage2bins->Write();
 }
int Plot_tauPt_Stage1_DD() {

  double totalMC =0.0;
  double lumi= 35.865; //20.011 ;  // B->5.882  // C->2.646   D->4.353 ;  // E->4.049 ; F->3.16 ;  G->7.554;  H->5.942  //--inv fb--//

  unsigned long long evt_DYJetsToLL_M50=1;
  unsigned long long evt_DYJetsToLL_M5to50=1;
  unsigned long long evt_TT=1;
 
  TFile *file_DYJetsToLL_M50  = new TFile("../python/crab_projects_March3/crab_DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");             
  double xs_DYJetsToLL_M50=4895000;  //--fb--//                                                                                                                    

  TFile *file_DYJetsToLL_M5to50  = new TFile("../python/crab_projects_March3/crab_DYJetsToLL_M-10to50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");    
  double xs_DYJetsToLL_M5to50=7160000;  //--fb--//                                                                                                                    

  TFile *file_TT              = new TFile("../python/crab_projects_March3/crab_TT_TuneCUETP8M2T4_13TeV-powheg-pythia8/results/hist.root");
  double xs_TT=730000; //--fb--//
  double kfact_TT= 1.139;

  TFile *file_TT_Mtt_700to1000      = new TFile("../python/crab_projects_March3/crab_TT_Mtt-700to1000_TuneCUETP8M1_13TeV-powheg-pythia8/results/hist.root");
  double xs_TT_Mtt_700to1000=730000; //--fb--//
  double kfact_TT_Mtt_700to1000= 0.0921;

  TFile *file_TT_Mtt_1000toInf              = new TFile("../python/crab_projects_March3/crab_TT_Mtt-1000toInf_TuneCUETP8M1_13TeV-powheg-pythia8/results/hist.root");
  double xs_TT_Mtt_1000toInf=730000; //--fb--//
  double kfact_TT_Mtt_1000toInf= 0.02474;


  //TFile *file_WJetsToLNu      = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/results/hist.root");
  //double xs_WJetsToLNu=60290000; //--fb--//

  TFile *file_WJetsToLNu      = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu= 50690000; //--fb--//
  //
  TFile *file_WToTauNu_M100  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-100_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M100 = 165000; //--fb--//
  double kfact_WToTauNu_M100 = 1.0 ; 
  //
  TFile *file_WToTauNu_M200  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-200_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M200 = 6370; //--fb--//
  double kfact_WToTauNu_M200 = 1.0 ; 
  //
  TFile *file_WToTauNu_M500  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-500_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M500 = 224.0; //--fb--//
  double kfact_WToTauNu_M500 = 1.0 ; 
  //
  TFile *file_WToTauNu_M1000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-1000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M1000 = 13.7; //--fb--//
  double kfact_WToTauNu_M1000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M2000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-2000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M2000 = 0.437; //--fb--//
  double kfact_WToTauNu_M2000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M3000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-3000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M3000 = 0.0342; //--fb--//
  double kfact_WToTauNu_M3000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M4000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-4000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M4000 = 0.00292; //--fb--//
  double kfact_WToTauNu_M4000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M5000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-5000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M5000 = 0.000233; //--fb--//
  double kfact_WToTauNu_M5000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M6000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-6000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M6000 = 0.000015; //--fb--//
  double kfact_WToTauNu_M6000 = 1.0 ; 
  //
  TFile *file_WJetsToLNu_HT100To200  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-100To200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT100To200 = 1345000 ; //--fb--//
  double kfact_WJetsToLNu_HT100To200 = 1.0 ; 

  TFile *file_WJetsToLNu_HT200To400  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-200To400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT200To400 = 359700 ; //--fb--//
  double kfact_WJetsToLNu_HT200To400 = 1.0 ;

  TFile *file_WJetsToLNu_HT400To600  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-400To600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT400To600 = 48910 ; //--fb--//
  double kfact_WJetsToLNu_HT400To600 = 1.0 ;

  TFile *file_WJetsToLNu_HT600To800  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-600To800_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT600To800 = 12050 ; //--fb--//
  double kfact_WJetsToLNu_HT600To800 = 1.0 ;

  TFile *file_WJetsToLNu_HT800To1200  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-800To1200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT800To1200 = 5501 ; //--fb--//
  double kfact_WJetsToLNu_HT800To1200 = 1.0 ;

  TFile *file_WJetsToLNu_HT1200To2500  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-1200To2500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT1200To2500 = 1329 ; //--fb--//
  double kfact_WJetsToLNu_HT1200To2500 = 1.0 ;

  TFile *file_WJetsToLNu_HT2500ToInf  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-2500ToInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT2500ToInf = 32.16  ; //--fb--//
  double kfact_WJetsToLNu_HT2500ToInf = 1.0 ;

  TFile *file_ST_tchannel_antitop=new TFile("../python/crab_projects_March3/crab_ST_t-channel_antitop_4f_inclusiveDecays_TuneCUETP8M2T4_13TeV-powhegV2-madspin/results/hist.root");
  double xs_ST_tchannel_antitop = 80950; //--fb--//
  double kfact_ST_tchannel_antitop = 1.0; //0.326;
  //
  TFile *file_ST_tchannel_top=new TFile("../python/crab_projects_March3/crab_ST_t-channel_top_4f_inclusiveDecays_TuneCUETP8M2T4_13TeV-powhegV2-madspin/results/hist.root");
  double xs_ST_tchannel_top =136020; //103200; //--fb--//
  double kfact_ST_tchannel_top = 1.0; //0.43;
  //
  TFile *file_ST_tW_antitop=new TFile("../python/crab_projects_March3/crab_ST_tW_antitop_5f_inclusiveDecays_13TeV-powheg-pythia8_TuneCUETP8M2T4/results/hist.root");
  double xs_ST_tW_antitop = 38090; //--fb--//
  double kfact_ST_tW_antitop =1.0; // 0.94;
  //
  TFile *file_ST_tW_top=new TFile("../python/crab_projects_March3/crab_ST_tW_top_5f_inclusiveDecays_13TeV-powheg-pythia8_TuneCUETP8M2T4/results/hist.root");
  double xs_ST_tW_top = 38090; //--fb--//
  double kfact_ST_tW_top = 1.0; //0.94;
  //
  TFile *file_WW=new TFile("../python/crab_projects_March3/crab_WW_TuneCUETP8M1_13TeV-pythia8/results/hist.root");
  double xs_WW = 63210; //--fb--//
  //
  TFile *file_WZ=new TFile("../python/crab_projects_March3/crab_WZ_TuneCUETP8M1_13TeV-pythia8/results/hist.root");
  double xs_WZ = 22820; //--fb--//
  double kfact_WZ = 2.06; // 47.13/22.82
  //
  TFile *file_ZZ=new TFile("../python/crab_projects_March3/crab_ZZ_TuneCUETP8M1_13TeV-pythia8/results/hist.root");
  double xs_ZZ = 10320; //--fb--//
  double kfact_ZZ = 1.60 ; //16523/10320
  //
  std::cout << "get datadriven root file" << std::endl;
  TFile *file_Datadriven  = new TFile("/net/scratch_cms3a/materok/wprime/qcd/dataDrivenTree15_pt_base_Mar7_fromData.root");


  /// DATA ///
  TFile *file_Tau_Run2016B = new TFile("../python/crab_projects_March3/crab_Tau_Run2016B/results/hist.root");
  TFile *file_Tau_Run2016C = new TFile("../python/crab_projects_March3/crab_Tau_Run2016C/results/hist.root");
  TFile *file_Tau_Run2016D = new TFile("../python/crab_projects_March3/crab_Tau_Run2016D/results/hist.root");
  TFile *file_Tau_Run2016E = new TFile("../python/crab_projects_March3/crab_Tau_Run2016E/results/hist.root");
  TFile *file_Tau_Run2016F = new TFile("../python/crab_projects_March3/crab_Tau_Run2016F/results/hist.root");
  TFile *file_Tau_Run2016G = new TFile("../python/crab_projects_March3/crab_Tau_Run2016G/results/hist.root");
  TFile *file_Tau_Run2016H_v2 = new TFile("../python/crab_projects_March3/crab_Tau_Run2016H_1/results/hist.root");
  TFile *file_Tau_Run2016H_v3 = new TFile("../python/crab_projects_March3/crab_Tau_Run2016H_2/results/hist.root");


  /// Signal ///
  TFile *file_Wprime_M4000 = new TFile("../python/crab_projects_March3/crab_WprimeToTauNu_M-4000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_Wprime_M4000= 2.04; // --fb-- //

  //--//
  TH1D* h1_evt_DYJetsToLL_M50 = (TH1D*)file_DYJetsToLL_M50->Get("demo/histoDir/eventCount");
  evt_DYJetsToLL_M50 = h1_evt_DYJetsToLL_M50->GetEntries(); // Integral();
  double wt_DYJetsToLL_M50 = (xs_DYJetsToLL_M50*lumi)/evt_DYJetsToLL_M50 ;
  TH1D* tauPt_Stage1_DYJetsToLL_M50 = (TH1D*)file_DYJetsToLL_M50->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_DYJetsToLL_M50->Scale(wt_DYJetsToLL_M50);
  std::cout << "DYJetsToLL_M50 weighted nevt=" << tauPt_Stage1_DYJetsToLL_M50->Integral() << std::endl;
  totalMC += tauPt_Stage1_DYJetsToLL_M50->Integral();

  TH1D* h1_evt_DYJetsToLL_M5to50 = (TH1D*)file_DYJetsToLL_M5to50->Get("demo/histoDir/eventCount");
  evt_DYJetsToLL_M5to50 = h1_evt_DYJetsToLL_M5to50->GetEntries(); // Integral();
  double wt_DYJetsToLL_M5to50 = (xs_DYJetsToLL_M5to50*lumi)/evt_DYJetsToLL_M5to50 ;
  TH1D* tauPt_Stage1_DYJetsToLL_M5to50 = (TH1D*)file_DYJetsToLL_M5to50->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_DYJetsToLL_M5to50->Scale(wt_DYJetsToLL_M5to50);
  std::cout << "DYJetsToLL_M5to50 weighted nevt=" << tauPt_Stage1_DYJetsToLL_M5to50->Integral() << std::endl;
  totalMC += tauPt_Stage1_DYJetsToLL_M5to50->Integral() ;
  //
  TH1D* total_DY = (TH1D*)tauPt_Stage1_DYJetsToLL_M50->Clone(); 
  total_DY->Add(tauPt_Stage1_DYJetsToLL_M5to50);
  total_DY->SetFillColorAlpha(kRed,0.5);
  total_DY->SetLineColor(kBlack);
  total_DY->Rebin(10);
  //

  TH1D* h1_evt_TT = (TH1D*)file_TT->Get("demo/histoDir/eventCount");
  evt_TT = h1_evt_TT->GetEntries(); // Integral();
  double wt_TT = (xs_TT*lumi)/evt_TT ;
  TH1D* tauPt_Stage1_TT  = (TH1D*)file_TT->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_TT->Scale(wt_TT);
  tauPt_Stage1_TT->Scale(kfact_TT);
  std::cout << "TTbar weighted nevt=" << tauPt_Stage1_TT->Integral() << std::endl;
  totalMC += tauPt_Stage1_TT->Integral();

  //file_TT_Mtt_700to1000
  TH1D* h1_evt_TT_Mtt_700to1000 = (TH1D*)file_TT_Mtt_700to1000->Get("demo/histoDir/eventCount");
  evt_TT_Mtt_700to1000 = h1_evt_TT_Mtt_700to1000->GetEntries(); // Integral();
  double wt_TT_Mtt_700to1000 = (xs_TT_Mtt_700to1000*lumi)/evt_TT_Mtt_700to1000 ;
  TH1D* tauPt_Stage1_TT_Mtt_700to1000  = (TH1D*)file_TT_Mtt_700to1000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_TT_Mtt_700to1000->Scale(wt_TT_Mtt_700to1000);
  tauPt_Stage1_TT_Mtt_700to1000->Scale(kfact_TT_Mtt_700to1000);
  std::cout << "TT_Mtt_700to1000bar weighted nevt=" << tauPt_Stage1_TT_Mtt_700to1000->Integral() << std::endl;
  totalMC += tauPt_Stage1_TT_Mtt_700to1000->Integral() ;

  //file_TT_Mtt_1000toInf
  TH1D* h1_evt_TT_Mtt_1000toInf = (TH1D*)file_TT_Mtt_1000toInf->Get("demo/histoDir/eventCount");
  evt_TT_Mtt_1000toInf = h1_evt_TT_Mtt_1000toInf->GetEntries(); // Integral();
  double wt_TT_Mtt_1000toInf = (xs_TT_Mtt_1000toInf*lumi)/evt_TT_Mtt_1000toInf ;
  TH1D* tauPt_Stage1_TT_Mtt_1000toInf  = (TH1D*)file_TT_Mtt_1000toInf->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_TT_Mtt_1000toInf->Scale(wt_TT_Mtt_1000toInf);
  tauPt_Stage1_TT_Mtt_1000toInf->Scale(kfact_TT_Mtt_1000toInf);
  std::cout << "TT_Mtt_1000toInfbar weighted nevt=" << tauPt_Stage1_TT_Mtt_1000toInf->Integral() << std::endl;
  totalMC += tauPt_Stage1_TT_Mtt_1000toInf->Integral() ;

  TH1D* total_TT = (TH1D*)tauPt_Stage1_TT->Clone(); 
  total_TT->Add(tauPt_Stage1_TT_Mtt_700to1000);
  total_TT->Add(tauPt_Stage1_TT_Mtt_1000toInf);
  total_TT->SetFillColor(kBlue-7);
  total_TT->SetLineColor(kBlack);
  total_TT->Rebin(10);


  /*
  TH1D* h1_evt_WJetsToLNu = (TH1D*)file_WJetsToLNu->Get("demo/histoDir/eventCount");
  evt_WJetsToLNu = h1_evt_WJetsToLNu->GetEntries(); //Integral();
  std::cout << "evt_WJetsToLNu = " << evt_WJetsToLNu << std::endl;
  double wt_WJetsToLNu = (xs_WJetsToLNu*lumi)/evt_WJetsToLNu ;
  TH1D* tauPt_Stage1_WJetsToLNu  = (TH1D*)file_WJetsToLNu->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //
  tauPt_Stage1_WJetsToLNu->Sumw2(kFALSE);
  tauPt_Stage1_WJetsToLNu->SetBinErrorOption(TH1::kPoisson);
  std::cout << "**WJets** unweighted nevt=" << tauPt_Stage1_WJetsToLNu->Integral() << std::endl;
  std::cout << "wt_WJetsToLNu = " << wt_WJetsToLNu << std::endl;
  tauPt_Stage1_WJetsToLNu->Scale(wt_WJetsToLNu);
  tauPt_Stage1_WJetsToLNu->SetFillColorAlpha(kGreen-7,0.5);
  tauPt_Stage1_WJetsToLNu->SetLineColor(kGreen-7);
  tauPt_Stage1_WJetsToLNu->Rebin(40);
  std::cout << "**WJets** weighted nevt=" << tauPt_Stage1_WJetsToLNu->Integral() << std::endl;
  */

  //file_ST_tchannel_antitop
  TH1D* h1_evt_ST_tchannel_antitop = (TH1D*)file_ST_tchannel_antitop->Get("demo/histoDir/eventCount");
  unsigned long long evt_ST_tchannel_antitop = h1_evt_ST_tchannel_antitop->GetEntries(); //Integral();
  double wt_ST_tchannel_antitop = (xs_ST_tchannel_antitop*lumi)/evt_ST_tchannel_antitop ;
  TH1D* tauPt_Stage1_ST_tchannel_antitop  = (TH1D*)file_ST_tchannel_antitop->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_ST_tchannel_antitop->Scale(wt_ST_tchannel_antitop);
  tauPt_Stage1_ST_tchannel_antitop->Scale(kfact_ST_tchannel_antitop);
  std::cout << "ST_tchannel_antitop weighted nevt=" << tauPt_Stage1_ST_tchannel_antitop->Integral() << std::endl;
  totalMC += tauPt_Stage1_ST_tchannel_antitop->Integral();

  //file_ST_tchannel_top
  TH1D* h1_evt_ST_tchannel_top = (TH1D*)file_ST_tchannel_top->Get("demo/histoDir/eventCount");
  unsigned long long evt_ST_tchannel_top = h1_evt_ST_tchannel_top->GetEntries(); //Integral();
  double wt_ST_tchannel_top = (xs_ST_tchannel_top*lumi)/evt_ST_tchannel_top ;
  TH1D* tauPt_Stage1_ST_tchannel_top  = (TH1D*)file_ST_tchannel_top->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_ST_tchannel_top->Scale(wt_ST_tchannel_top);
  tauPt_Stage1_ST_tchannel_top->Scale(kfact_ST_tchannel_top);
  std::cout << "ST_tchannel_top weighted nevt=" << tauPt_Stage1_ST_tchannel_top->Integral() << std::endl;
  totalMC += tauPt_Stage1_ST_tchannel_top->Integral() ;

  //file_ST_tW_antitop
  TH1D* h1_evt_ST_tW_antitop = (TH1D*)file_ST_tW_antitop->Get("demo/histoDir/eventCount");
  unsigned long long evt_ST_tW_antitop = h1_evt_ST_tW_antitop->GetEntries(); //Integral();
  double wt_ST_tW_antitop = (xs_ST_tW_antitop*lumi)/evt_ST_tW_antitop ;
  TH1D* tauPt_Stage1_ST_tW_antitop  = (TH1D*)file_ST_tW_antitop->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_ST_tW_antitop->Scale(wt_ST_tW_antitop);
  tauPt_Stage1_ST_tW_antitop->Scale(kfact_ST_tW_antitop);
  std::cout << "ST_tW_antitop weighted nevt=" << tauPt_Stage1_ST_tW_antitop->Integral() << std::endl;
  totalMC += tauPt_Stage1_ST_tW_antitop->Integral();

  //file_ST_tW_top
  TH1D* h1_evt_ST_tW_top = (TH1D*)file_ST_tW_top->Get("demo/histoDir/eventCount");
  unsigned long long evt_ST_tW_top = h1_evt_ST_tW_top->GetEntries(); //Integral();
  double wt_ST_tW_top = (xs_ST_tW_top*lumi)/evt_ST_tW_top ;
  TH1D* tauPt_Stage1_ST_tW_top  = (TH1D*)file_ST_tW_top->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_ST_tW_top->Scale(wt_ST_tW_top);
  tauPt_Stage1_ST_tW_top->Scale(kfact_ST_tW_top);
  std::cout << "ST_tW_top weighted nevt=" << tauPt_Stage1_ST_tW_top->Integral() << std::endl;
  totalMC += tauPt_Stage1_ST_tW_top->Integral() ;

  TH1D* total_ST = (TH1D*)tauPt_Stage1_ST_tchannel_antitop->Clone(); 
  total_ST->Add(tauPt_Stage1_ST_tchannel_top);
  total_ST->Add(tauPt_Stage1_ST_tW_antitop);
  total_ST->Add(tauPt_Stage1_ST_tW_top);
  total_ST->SetFillColorAlpha(kCyan,0.5);
  total_ST->SetLineColor(kBlack);
  total_ST->Rebin(10);

  //file_WJetsToLNu_HT100To200
  TH1D* h1_evt_WJetsToLNu_HT100To200 = (TH1D*)file_WJetsToLNu_HT100To200->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT100To200 = h1_evt_WJetsToLNu_HT100To200->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT100To200 = (xs_WJetsToLNu_HT100To200*lumi)/evt_WJetsToLNu_HT100To200 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT100To200  = (TH1D*)file_WJetsToLNu_HT100To200->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                           
  //  tauPt_Stage1_WJetsToLNu_HT100To200->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT100To200->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT100To200->Scale(wt_WJetsToLNu_HT100To200);
  std::cout << "WJetsToLNu_HT100To200 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT100To200->Integral() << std::endl;
  totalMC += tauPt_Stage1_WJetsToLNu_HT100To200->Integral();
  //tauPt_Stage1_WJetsToLNu_HT100To200->Scale(kfact_WJetsToLNu_HT100To200);
  //  std::cout << tauPt_Stage1_WJetsToLNu_HT100To200->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT200To400
  TH1D* h1_evt_WJetsToLNu_HT200To400 = (TH1D*)file_WJetsToLNu_HT200To400->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT200To400 = h1_evt_WJetsToLNu_HT200To400->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT200To400 = (xs_WJetsToLNu_HT200To400*lumi)/evt_WJetsToLNu_HT200To400 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT200To400  = (TH1D*)file_WJetsToLNu_HT200To400->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  // tauPt_Stage1_WJetsToLNu_HT200To400->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT200To400->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT200To400->Scale(wt_WJetsToLNu_HT200To400);
 std::cout << "WJetsToLNu_HT200To400 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT200To400->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu_HT200To400->Integral();
  //tauPt_Stage1_WJetsToLNu_HT200To400->Scale(kfact_WJetsToLNu_HT200To400);
  //std::cout << tauPt_Stage1_WJetsToLNu_HT200To400->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT400To600
  TH1D* h1_evt_WJetsToLNu_HT400To600 = (TH1D*)file_WJetsToLNu_HT400To600->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT400To600 = h1_evt_WJetsToLNu_HT400To600->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT400To600 = (xs_WJetsToLNu_HT400To600*lumi)/evt_WJetsToLNu_HT400To600 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT400To600  = (TH1D*)file_WJetsToLNu_HT400To600->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  // tauPt_Stage1_WJetsToLNu_HT400To600->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT400To600->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT400To600->Scale(wt_WJetsToLNu_HT400To600);
  std::cout << "WJetsToLNu_HT400To600 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT400To600->Integral() << std::endl;
  totalMC += tauPt_Stage1_WJetsToLNu_HT400To600->Integral();
  // tauPt_Stage1_WJetsToLNu_HT400To600->Scale(kfact_WJetsToLNu_HT400To600);
  // std::cout << tauPt_Stage1_WJetsToLNu_HT400To600->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT600To800
  TH1D* h1_evt_WJetsToLNu_HT600To800 = (TH1D*)file_WJetsToLNu_HT600To800->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT600To800 = h1_evt_WJetsToLNu_HT600To800->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT600To800 = (xs_WJetsToLNu_HT600To800*lumi)/evt_WJetsToLNu_HT600To800 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT600To800  = (TH1D*)file_WJetsToLNu_HT600To800->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  //  tauPt_Stage1_WJetsToLNu_HT600To800->Sumw2(kFALSE);
  // tauPt_Stage1_WJetsToLNu_HT600To800->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT600To800->Scale(wt_WJetsToLNu_HT600To800);
  std::cout << "WJetsToLNu_HT600To800 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT600To800->Integral() << std::endl;
  totalMC +=  tauPt_Stage1_WJetsToLNu_HT600To800->Integral();
  // tauPt_Stage1_WJetsToLNu_HT600To800->Scale(kfact_WJetsToLNu_HT600To800);
  // std::cout << tauPt_Stage1_WJetsToLNu_HT600To800->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT800To1200
  TH1D* h1_evt_WJetsToLNu_HT800To1200 = (TH1D*)file_WJetsToLNu_HT800To1200->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT800To1200 = h1_evt_WJetsToLNu_HT800To1200->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT800To1200 = (xs_WJetsToLNu_HT800To1200*lumi)/evt_WJetsToLNu_HT800To1200 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT800To1200  = (TH1D*)file_WJetsToLNu_HT800To1200->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  // tauPt_Stage1_WJetsToLNu_HT800To1200->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT800To1200->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT800To1200->Scale(wt_WJetsToLNu_HT800To1200);
 std::cout << "WJetsToLNu_HT800To1200 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT800To1200->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu_HT800To1200->Integral();
  //tauPt_Stage1_WJetsToLNu_HT800To1200->Scale(kfact_WJetsToLNu_HT800To1200);
  // std::cout << tauPt_Stage1_WJetsToLNu_HT800To1200->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT1200To2500
  TH1D* h1_evt_WJetsToLNu_HT1200To2500 = (TH1D*)file_WJetsToLNu_HT1200To2500->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT1200To2500 = h1_evt_WJetsToLNu_HT1200To2500->GetEntries(); //Integral();                                                             
  double wt_WJetsToLNu_HT1200To2500 = (xs_WJetsToLNu_HT1200To2500*lumi)/evt_WJetsToLNu_HT1200To2500 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT1200To2500  = (TH1D*)file_WJetsToLNu_HT1200To2500->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  // tauPt_Stage1_WJetsToLNu_HT1200To2500->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT1200To2500->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT1200To2500->Scale(wt_WJetsToLNu_HT1200To2500);
 std::cout << "WJetsToLNu_HT1200To2500 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT1200To2500->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu_HT1200To2500->Integral();
  // tauPt_Stage1_WJetsToLNu_HT1200To2500->Scale(kfact_WJetsToLNu_HT1200To2500);
  //std::cout << tauPt_Stage1_WJetsToLNu_HT1200To2500->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT2500ToInf
  TH1D* h1_evt_WJetsToLNu_HT2500ToInf = (TH1D*)file_WJetsToLNu_HT2500ToInf->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT2500ToInf = h1_evt_WJetsToLNu_HT2500ToInf->GetEntries(); //Integral();                                                             
  double wt_WJetsToLNu_HT2500ToInf = (xs_WJetsToLNu_HT2500ToInf*lumi)/evt_WJetsToLNu_HT2500ToInf ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT2500ToInf  = (TH1D*)file_WJetsToLNu_HT2500ToInf->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  //tauPt_Stage1_WJetsToLNu_HT2500ToInf->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT2500ToInf->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT2500ToInf->Scale(wt_WJetsToLNu_HT2500ToInf);
 std::cout << "WJetsToLNu_HT2500ToInf weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT2500ToInf->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu_HT2500ToInf->Integral();
  //tauPt_Stage1_WJetsToLNu_HT2500ToInf->Scale(kfact_WJetsToLNu_HT2500ToInf);
  ///std::cout << tauPt_Stage1_WJetsToLNu_HT2500ToInf->GetBinError(300) << std::endl;

  //file_WToTauNu_M100
  TH1D* h1_evt_WToTauNu_M100 = (TH1D*)file_WToTauNu_M100->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M100 = h1_evt_WToTauNu_M100->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M100 = (xs_WToTauNu_M100*lumi)/evt_WToTauNu_M100 ;
  TH1D* tauPt_Stage1_WToTauNu_M100  = (TH1D*)file_WToTauNu_M100->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M100->Scale(wt_WToTauNu_M100);
 std::cout << "WToTauNu_M100 weighted nevt=" << tauPt_Stage1_WToTauNu_M100->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M100->Integral() ;

  //file_WToTauNu_M200
  TH1D* h1_evt_WToTauNu_M200 = (TH1D*)file_WToTauNu_M200->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M200 = h1_evt_WToTauNu_M200->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M200 = (xs_WToTauNu_M200*lumi)/evt_WToTauNu_M200 ;
  TH1D* tauPt_Stage1_WToTauNu_M200  = (TH1D*)file_WToTauNu_M200->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M200->Scale(wt_WToTauNu_M200);
 std::cout << "WToTauNu_M200 weighted nevt=" << tauPt_Stage1_WToTauNu_M200->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M200->Integral();

  //file_WToTauNu_M500
  TH1D* h1_evt_WToTauNu_M500 = (TH1D*)file_WToTauNu_M500->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M500 = h1_evt_WToTauNu_M500->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M500 = (xs_WToTauNu_M500*lumi)/evt_WToTauNu_M500 ;
  TH1D* tauPt_Stage1_WToTauNu_M500  = (TH1D*)file_WToTauNu_M500->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M500->Scale(wt_WToTauNu_M500);
 std::cout << "WToTauNu_M500 weighted nevt=" << tauPt_Stage1_WToTauNu_M500->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M500->Integral() ;

  //file_WToTauNu_M1000
  TH1D* h1_evt_WToTauNu_M1000 = (TH1D*)file_WToTauNu_M1000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M1000 = h1_evt_WToTauNu_M1000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M1000 = (xs_WToTauNu_M1000*lumi)/evt_WToTauNu_M1000 ;
  TH1D* tauPt_Stage1_WToTauNu_M1000  = (TH1D*)file_WToTauNu_M1000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M1000->Scale(wt_WToTauNu_M1000);
 std::cout << "WToTauNu_M1000 weighted nevt=" << tauPt_Stage1_WToTauNu_M1000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M1000->Integral();

  //file_WToTauNu_M2000
  TH1D* h1_evt_WToTauNu_M2000 = (TH1D*)file_WToTauNu_M2000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M2000 = h1_evt_WToTauNu_M2000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M2000 = (xs_WToTauNu_M2000*lumi)/evt_WToTauNu_M2000 ;
  TH1D* tauPt_Stage1_WToTauNu_M2000  = (TH1D*)file_WToTauNu_M2000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M2000->Scale(wt_WToTauNu_M2000);
 std::cout << "WToTauNu_M2000 weighted nevt=" << tauPt_Stage1_WToTauNu_M2000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M2000->Integral();

  //file_WToTauNu_M3000
  TH1D* h1_evt_WToTauNu_M3000 = (TH1D*)file_WToTauNu_M3000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M3000 = h1_evt_WToTauNu_M3000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M3000 = (xs_WToTauNu_M3000*lumi)/evt_WToTauNu_M3000 ;
  TH1D* tauPt_Stage1_WToTauNu_M3000  = (TH1D*)file_WToTauNu_M3000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M3000->Scale(wt_WToTauNu_M3000);
 std::cout << "WToTauNu_M3000 weighted nevt=" << tauPt_Stage1_WToTauNu_M3000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M3000->Integral();

  //file_WToTauNu_M4000
  TH1D* h1_evt_WToTauNu_M4000 = (TH1D*)file_WToTauNu_M4000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M4000 = h1_evt_WToTauNu_M4000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M4000 = (xs_WToTauNu_M4000*lumi)/evt_WToTauNu_M4000 ;
  TH1D* tauPt_Stage1_WToTauNu_M4000  = (TH1D*)file_WToTauNu_M4000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M4000->Scale(wt_WToTauNu_M4000);
 std::cout << "WToTauNu_M4000 weighted nevt=" << tauPt_Stage1_WToTauNu_M4000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M4000->Integral();

  //file_WToTauNu_M5000
  TH1D* h1_evt_WToTauNu_M5000 = (TH1D*)file_WToTauNu_M5000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M5000 = h1_evt_WToTauNu_M5000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M5000 = (xs_WToTauNu_M5000*lumi)/evt_WToTauNu_M5000 ;
  TH1D* tauPt_Stage1_WToTauNu_M5000  = (TH1D*)file_WToTauNu_M5000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M5000->Scale(wt_WToTauNu_M5000);
 std::cout << "WToTauNu_M5000 weighted nevt=" << tauPt_Stage1_WToTauNu_M5000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M5000->Integral();

  //file_WToTauNu_M6000
  TH1D* h1_evt_WToTauNu_M6000 = (TH1D*)file_WToTauNu_M6000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M6000 = h1_evt_WToTauNu_M6000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M6000 = (xs_WToTauNu_M6000*lumi)/evt_WToTauNu_M6000 ;
  TH1D* tauPt_Stage1_WToTauNu_M6000  = (TH1D*)file_WToTauNu_M6000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M6000->Scale(wt_WToTauNu_M6000);
 std::cout << "WToTauNu_M6000 weighted nevt=" << tauPt_Stage1_WToTauNu_M6000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M6000->Integral();

  //file_WJetsToLNu
  TH1D* h1_evt_WJetsToLNu = (TH1D*)file_WJetsToLNu->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu = h1_evt_WJetsToLNu->GetEntries(); //Integral();                                                             
  double wt_WJetsToLNu = (xs_WJetsToLNu*lumi)/evt_WJetsToLNu ;
  TH1D* tauPt_Stage1_WJetsToLNu  = (TH1D*)file_WJetsToLNu->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WJetsToLNu->Scale(wt_WJetsToLNu);
 std::cout << "WJetsToLNu weighted nevt=" << tauPt_Stage1_WJetsToLNu->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu->Integral();

  TH1D* total_WJets = (TH1D*)tauPt_Stage1_WJetsToLNu_HT100To200->Clone();
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT200To400);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT400To600);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT600To800);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT800To1200);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT1200To2500);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT2500ToInf);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M100);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M200);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M500);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M1000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M2000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M3000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M4000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M5000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M6000);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu);
  total_WJets->SetFillColorAlpha(kGreen-8,0.5);
  total_WJets->SetLineColor(kBlack);
  //std::cout << "Wjets " << total_WJets->GetBinError(300) << std::endl;

  total_WJets->Rebin(10);


  //file_WW
  TH1D* h1_evt_WW = (TH1D*)file_WW->Get("demo/histoDir/eventCount");
  unsigned long long evt_WW = h1_evt_WW->GetEntries(); //Integral();                                                                         
  double wt_WW = (xs_WW*lumi)/evt_WW ;
  TH1D* tauPt_Stage1_WW  = (TH1D*)file_WW->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //
  //tauPt_Stage1_WW->Sumw2(kFALSE);
  //tauPt_Stage1_WW->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WW->Scale(wt_WW);
 std::cout << "WW weighted nevt=" << tauPt_Stage1_WW->Integral() << std::endl;
 totalMC +=tauPt_Stage1_WW->Integral() ;

  //file_WZ
  TH1D* h1_evt_WZ = (TH1D*)file_WZ->Get("demo/histoDir/eventCount");
  unsigned long long evt_WZ = h1_evt_WZ->GetEntries(); //Integral();                                                                         
  double wt_WZ = (xs_WZ*lumi)/evt_WZ ;
  TH1D* tauPt_Stage1_WZ  = (TH1D*)file_WZ->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //
  //tauPt_Stage1_WZ->Sumw2(kFALSE);
  // tauPt_Stage1_WZ->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WZ->Scale(wt_WZ);
  tauPt_Stage1_WZ->Scale(kfact_WZ);
 std::cout << "WZ weighted nevt=" << tauPt_Stage1_WZ->Integral() << std::endl;
 totalMC +=  tauPt_Stage1_WZ->Integral();

  //file_ZZ
  TH1D* h1_evt_ZZ = (TH1D*)file_ZZ->Get("demo/histoDir/eventCount");
  unsigned long long evt_ZZ = h1_evt_ZZ->GetEntries(); //Integral();                                                                         
  double wt_ZZ = (xs_ZZ*lumi)/evt_ZZ ;
  TH1D* tauPt_Stage1_ZZ  = (TH1D*)file_ZZ->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //
  //tauPt_Stage1_ZZ->Sumw2(kFALSE);
  //tauPt_Stage1_ZZ->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_ZZ->Scale(wt_ZZ);
  tauPt_Stage1_ZZ->Scale(kfact_ZZ);
 std::cout << "ZZ weighted nevt=" << tauPt_Stage1_ZZ->Integral() << std::endl;
 totalMC += tauPt_Stage1_ZZ->Integral();

  TH1D* total_diboson = (TH1D*)tauPt_Stage1_WW->Clone();
  total_diboson->Add(tauPt_Stage1_WZ);
  total_diboson->Add(tauPt_Stage1_ZZ);
  total_diboson->SetFillColorAlpha(kOrange+2,0.5);
  total_diboson->SetLineColor(kBlack);
  total_diboson->Rebin(10);


  //datadriven                                                                                                                                                                                                           
  //  double wt_Datadriven = (lumi/33.507) ;                                                                                                                                                                             
  TH1D* total_QCD = (TH1D*)file_Datadriven->Get("demo/histoDir/tauPt_Stage1");
  total_QCD->SetFillStyle(3001);
  total_QCD->SetFillColor(kPink+1);
  total_QCD->SetLineColor(kBlack);
  total_QCD->Rebin(10);  //datadriven                                                                                                                                                                                  

  std::cout << "totalMC(w/o DD) =" << totalMC << std::endl;

   std::cout << "will do data" << std::endl;
  
  //--Data--//
   TH1D* tauPt_Stage1_Run2016F  =  (TH1D*)file_Tau_Run2016F->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016E  =  (TH1D*)file_Tau_Run2016E->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016D  =  (TH1D*)file_Tau_Run2016D->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016C  =  (TH1D*)file_Tau_Run2016C->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016B  =  (TH1D*)file_Tau_Run2016B->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016G  =  (TH1D*)file_Tau_Run2016G->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016H_v2  = (TH1D*)file_Tau_Run2016H_v2->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016H_v3  = (TH1D*)file_Tau_Run2016H_v3->Get("demo/histoDir/tauPt_Stage1");
   
   /*
  std::cout << "Will Clone B" << std::endl;
  TH1D* tauPt_Stage1_Run2016BCD = (TH1D*)tauPt_Stage1_Run2016B->Clone();
 
  std::cout << "Will add C" << std::endl;
  tauPt_Stage1_Run2016BCD->Add(tauPt_Stage1_Run2016C);

  std::cout << "Will add D" << std::endl;
  tauPt_Stage1_Run2016BCD->Add(tauPt_Stage1_Run2016D);

  //  std::cout << "Will add E" << std::endl;
  // tauPt_Stage1_Run2016BCDEF->Add(tauPt_Stage1_Run2016E);

  // std::cout << "Will add F" << std::endl;
  //  tauPt_Stage1_Run2016BCDEF->Add(tauPt_Stage1_Run2016F);
  */

  TH1D* tauPt_Stage1_Run2016all = (TH1D*)tauPt_Stage1_Run2016B->Clone();
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016C);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016D);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016E);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016F);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016G);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016H_v2);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016H_v3);
                                                                                                                                    
  tauPt_Stage1_Run2016all->SetMarkerStyle(20);
  tauPt_Stage1_Run2016all->SetMarkerColor(kBlack);
  tauPt_Stage1_Run2016all->SetLineColor(kBlack);
  tauPt_Stage1_Run2016all->Rebin(10);
  
  std::cout << "will do signal " << std::endl;
  //--Signal--//
  TH1D* h1_evt_Wprime_M4000 = (TH1D*)file_Wprime_M4000->Get("demo/histoDir/eventCount");
  unsigned long long evt_Wprime_M4000 = h1_evt_Wprime_M4000->GetEntries(); //Integral();                                                                          
  // std::cout << "evt_Wprime_M4000 = " << evt_Wprime_M4000 << std::endl;
  double wt_Wprime_M4000 = (xs_Wprime_M4000*lumi)/evt_Wprime_M4000 ;
  TH1D* tauPt_Stage1_Wprime_M4000  = (TH1D*)file_Wprime_M4000->Get("demo/histoDir/tauPt_Stage1");
  std::cout << "Sig Eff W' M4000 : " << ( tauPt_Stage1_Wprime_M4000->GetEntries() / evt_Wprime_M4000 ) << std::endl;
  tauPt_Stage1_Wprime_M4000->Scale(wt_Wprime_M4000);
  //  tauPt_Stage1_Wprime_M4000->SetFillColorAlpha(kGreen-7,0.5);
  tauPt_Stage1_Wprime_M4000->SetLineColor(kMagenta);
  tauPt_Stage1_Wprime_M4000->SetLineWidth(2);
  tauPt_Stage1_Wprime_M4000->SetLineStyle(5);
  tauPt_Stage1_Wprime_M4000->Rebin(10) ;
 
  //--Plotting Styles//
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetPadRightMargin(0.05);
  gStyle->SetPadBottomMargin(0.12);  
  gStyle->SetPadTopMargin(0.05);   
  gStyle->SetTitleXSize(0.05);
  gStyle->SetTitleXOffset(1.05);
  gStyle->SetTitleYSize(0.05);
  gStyle->SetTitleYOffset(1.05);

  //////// Output File /////////
  TFile* outputFile = new TFile("Out_tauPt_Stage1.root","RECREATE");
  outputFile->cd();

  //--//
  THStack *hs = new THStack("hs","");
  // hs->Add(tauPt_Stage1_WJetsToLNu);
  hs->Add(total_diboson);
  hs->Add(total_DY);
  hs->Add(total_ST);
  hs->Add(total_TT);
  //  hs->Add(tauPt_Stage1_DYJetsToLL_M50);
  hs->Add(total_QCD);
  //  hs->Add(total_ZJets);
  hs->Add(total_WJets);
  //tauPt_Stage1_->SetTitle("");
    /*
  eff1->GetYaxis()->SetTitle("Events");
  //eff1->SetMarkerStyle(0);
  //eff1->SetMarkerColor(kBlack);
  eff1->SetLineColor(kBlack);
  eff1->SetLineWidth(2);
  */
  TCanvas* my_canvas = new TCanvas("canvas","canvas",800,600);
  my_canvas->cd();
  //  hs->Draw();
  gPad->SetLogy();
  hs->Draw("HIST");                                                                                                                                        
  hs->SetMaximum(100000);
  hs->SetMinimum(0.1);
  hs->GetXaxis()->SetRangeUser(0, 1000);
  //  hs->GetXaxis()->SetLimits(40, 3200);
  hs->GetXaxis()->SetTitle("#tau pT [GeV]");
  hs->GetYaxis()->SetTitle("Events");

  TH1F* total =  (TH1F*)hs->GetStack()->Last()->Clone();
  // total->SetFillStyle(3004);                                                                                                                                      
  // total->SetFillColor(kGray+1); 
  //  total->SetMarkerColor(0);
  // total->Draw("SAME E2");
  //hs->GetStack()->Last()->Draw("same E");
  // hs->Draw("SAME HIST");

  //  tauPt_Stage1_Run2016E->Draw("SAME E0");
  tauPt_Stage1_Run2016all->Draw("SAME E0");
  TH1F* mydata =  (TH1F*)tauPt_Stage1_Run2016all->Clone();

  //tauPt_Stage1_Run2016C->Draw("SAME E0");
  //tauPt_Stage1_Run2016CDE->Draw("SAME E0");
  //
  tauPt_Stage1_Wprime_M4000->Draw("SAME HIST");
  //  hs->SetOption("HIST L");
  
  TLatex* CMS_text = new TLatex(0.20,0.90,"CMS");
  CMS_text->SetNDC();
  CMS_text->SetTextSize(0.05);
  CMS_text->SetTextAngle(0);
  CMS_text->Draw("same");
  TLatex* CMS_text_2 = new TLatex(0.20,0.85,"Preliminary");
  CMS_text_2->SetNDC();
  CMS_text_2->SetTextFont(42);
  CMS_text_2->SetTextSize(0.05);
  CMS_text_2->SetTextAngle(0);
  CMS_text_2->Draw("same");    

  TLatex* lumiText = new TLatex(0.92,0.975,"35.9 fb^{-1} (13 TeV)");
  lumiText->SetNDC();
  lumiText->SetTextFont(42);
  lumiText->SetTextSize(0.04);
  lumiText->SetTextAlign(32);
  lumiText->Draw("same");     

  TLegend *leg_example = new TLegend(0.75,0.50,0.94,0.94);
  leg_example->SetFillColor(0);
  leg_example->SetTextFont(42);
  leg_example->SetBorderSize(0);
  leg_example->AddEntry(total_WJets, "Wjets","f");
  leg_example->AddEntry(total_DY, "DY","f");
  leg_example->AddEntry(total_TT, "TT","f");
  //leg_example->AddEntry(tauPt_Stage1_WJetsToLNu, "Wjets","f");
  leg_example->AddEntry(total_ST, "Single Top", "f");
  leg_example->AddEntry(total_diboson, "Diboson", "f");
  leg_example->AddEntry(total_QCD, "QCD datadriven", "f");
  // leg_example->AddEntry(total_ZJets, "Z", "f");
  leg_example->AddEntry(tauPt_Stage1_Wprime_M4000, "SSM W' 4 TeV", "l");
  leg_example->AddEntry(tauPt_Stage1_Run2016all, "Data", "pl" );
  // leg_example->AddEntry(tauPt_Stage1_Run2016E, "Data", "pl" );
  // leg_example->AddEntry(tauPt_Stage1_Run2016D, "Data", "pl" );
  leg_example->Draw("same");
  
  my_canvas->Write();
  my_canvas->Print("tauPt_Stage1_DD.pdf");


  /*

  TCanvas* my_canvas2 = new TCanvas("canvas2","canvas2");
  my_canvas2->cd();
  gPad->SetLogy();
  total->SetMaximum(1000);
  total->SetMarkerStyle(20);
  total->Draw("E");
  my_canvas2->Write();
  */
  TCanvas* ratio_c = new TCanvas("ratio","ratio_canvas",800,700);
  ratio_c->SetTopMargin(0.); 
  ratio_c->SetBottomMargin(0.); 
  ratio_c->Update();
  ratio_c->Divide(1, 2);
  ratio_c->cd(1);

  gPad->SetPad(.005, .30, .995, .995);
  TPad* pad1 = (TPad*)ratio_c->GetPad(1); 
  pad1->SetTopMargin(0.05);
  pad1->SetBottomMargin(0.05); 
  
  ratio_c->Update();
  gPad->SetLogy();
  
  hs->Draw("HIST");                                                                                                                                        
  hs->SetMaximum(100000);
  hs->SetMinimum(0.01);
  //  hs->GetXaxis()->SetLimits(40, 3200);
  hs->GetXaxis()->SetRangeUser(0, 1000);
  hs->GetXaxis()->SetTitle("");
  // total->Draw("SAME E2");
  mydata->Draw("SAME E1");
  tauPt_Stage1_Wprime_M4000->Draw("SAME HIST");
  CMS_text->Draw("same");
  CMS_text_2->Draw("same");
  lumiText->Draw("same");
  leg_example->Draw("same");
  ratio_c->cd(2);

  gPad->SetPad(.005, .08, .995, .28); 
  gStyle->SetOptStat(false);
  ratio_c->Update();
  TPad* pad2 = (TPad*)ratio_c->GetPad(2);
  pad2->SetTopMargin(0.04); 
  pad2->SetBottomMargin(0.30); 
  pad2->SetGridx();
  pad2->SetGridy();

  std::cout << "data bins = " << mydata->GetNbinsX() << " width=" << mydata->GetBinWidth(2);
  std::cout << " MC bins = " << total->GetNbinsX() << " width=" << total->GetBinWidth(2) << std::endl;

  int nbin=mydata->GetNbinsX() ;
  float width=mydata->GetBinWidth(2);
  TH1F *data_by_MC = new TH1F("h1", "ratio", nbin, 0, 4000);
  std::cout << "before D/MC bins=" << data_by_MC->GetNbinsX() << " width=" << data_by_MC->GetBinWidth(2) << std::endl;

  for (int i=0; i<nbin; i++) {
    float data = mydata->GetBinContent(i);
    float MC = total->GetBinContent(i);
    float ratio=0;
    if (MC>0) ratio=data/MC ;
    data_by_MC->SetBinContent(i,ratio);
    if (data>0) {
      float stat_err = sqrt(data)/data ;  
      data_by_MC->SetBinError(i,stat_err);
    }

    // data_by_MC->SetBinWidth(i,width);  
  }

  //  TH1F* data_by_MC = (TH1F*)mydata->Clone();
  // data_by_MC->Divide(total);
  data_by_MC->SetMarkerStyle(20);
  data_by_MC->Draw("E");
  data_by_MC->GetXaxis()->SetTitle("#tau pT [GeV]");
  data_by_MC->GetYaxis()->SetTitle("#frac{DATA}{MC}");
  data_by_MC->GetYaxis()->SetLabelSize(0.12);
  data_by_MC->GetXaxis()->SetLabelSize(0.12);
  data_by_MC->GetYaxis()->SetTitleSize(0.18);
  data_by_MC->GetXaxis()->SetTitleSize(0.18);
  data_by_MC->GetYaxis()->SetTitleOffset(0.20);
  data_by_MC->GetXaxis()->SetTitleOffset(0.75);
  data_by_MC->SetTitle("");
  data_by_MC->GetXaxis()->SetRangeUser(0, 1000);
  data_by_MC->SetMaximum(4);
  data_by_MC->SetMinimum(0);
  data_by_MC->GetYaxis()->SetNdivisions(4);



  TLine *l=new TLine(0,1,1000,1);
  l->SetLineColor(kRed);
  l->Draw("same");

  std::cout << "D/MC bins=" << data_by_MC->GetNbinsX() << " width=" << data_by_MC->GetBinWidth(2) << std::endl;
  ratio_c->Write();
  ratio_c->Print("tauPt_Stage1_ratio_DD.pdf");

 
  return 0;

}
void ttbar_looseLep2Pt_logy()
{
//=========Macro generated from canvas: c1/c1
//=========  (Sun Dec 11 15:16:17 2016) by ROOT version6.06/01
   TCanvas *c1 = new TCanvas("c1", "c1",1,1,1200,1416);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   c1->SetHighLightColor(2);
   c1->Range(0,0,1,1);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   c1->SetTickx(1);
   c1->SetTicky(1);
   c1->SetLeftMargin(0.15);
   c1->SetRightMargin(0.05);
   c1->SetTopMargin(0.07);
   c1->SetBottomMargin(0.13);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
  
// ------------>Primitives in pad: pad1
   TPad *pad1 = new TPad("pad1", "pad1",0,0.3,1,1);
   pad1->Draw();
   pad1->cd();
   pad1->Range(-93.75,-6.459411,531.25,2.538922);
   pad1->SetFillColor(0);
   pad1->SetBorderMode(0);
   pad1->SetBorderSize(2);
   pad1->SetLogy();
   pad1->SetTickx(1);
   pad1->SetTicky(1);
   pad1->SetLeftMargin(0.15);
   pad1->SetRightMargin(0.05);
   pad1->SetTopMargin(0.07);
   pad1->SetBottomMargin(0);
   pad1->SetFrameFillStyle(0);
   pad1->SetFrameBorderMode(0);
   pad1->SetFrameFillStyle(0);
   pad1->SetFrameBorderMode(0);
   
   THStack *h = new THStack();
   h->SetName("h");
   h->SetTitle("");
   h->SetMinimum(1.61613e-06);
   h->SetMaximum(32.94396);
   
   TH1F *h_stack_8 = new TH1F("h_stack_8","",20,0,500);
   h_stack_8->SetMinimum(3.472076e-07);
   h_stack_8->SetMaximum(81.10342);
   h_stack_8->SetDirectory(0);
   h_stack_8->SetStats(0);

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha
   ci = TColor::GetColor("#000099");
   h_stack_8->SetLineColor(ci);
   h_stack_8->GetXaxis()->SetLabelFont(42);
   h_stack_8->GetXaxis()->SetLabelOffset(0.007);
   h_stack_8->GetXaxis()->SetTitleSize(0.05);
   h_stack_8->GetXaxis()->SetTickLength(0.025);
   h_stack_8->GetXaxis()->SetTitleFont(42);
   h_stack_8->GetYaxis()->SetTitle("a.u./25 GeV");
   h_stack_8->GetYaxis()->SetLabelFont(42);
   h_stack_8->GetYaxis()->SetLabelOffset(0.007);
   h_stack_8->GetYaxis()->SetTitleSize(0.05);
   h_stack_8->GetYaxis()->SetTickLength(0.025);
   h_stack_8->GetYaxis()->SetTitleOffset(1.5);
   h_stack_8->GetYaxis()->SetTitleFont(42);
   h_stack_8->GetZaxis()->SetLabelFont(42);
   h_stack_8->GetZaxis()->SetLabelOffset(0.007);
   h_stack_8->GetZaxis()->SetTitleSize(0.05);
   h_stack_8->GetZaxis()->SetTickLength(0.025);
   h_stack_8->GetZaxis()->SetTitleFont(42);
   h->SetHistogram(h_stack_8);
   
   
   TH1D *h_looseLep2Pt_QCD__85 = new TH1D("h_looseLep2Pt_QCD__85","",20,0,500);
   h_looseLep2Pt_QCD__85->SetBinContent(1,0.004168645);
   h_looseLep2Pt_QCD__85->SetBinContent(2,0.004299542);
   h_looseLep2Pt_QCD__85->SetBinContent(3,0.001765161);
   h_looseLep2Pt_QCD__85->SetBinContent(4,0.0008868067);
   h_looseLep2Pt_QCD__85->SetBinContent(6,0.0004026872);
   h_looseLep2Pt_QCD__85->SetBinContent(7,6.27175e-05);
   h_looseLep2Pt_QCD__85->SetBinError(1,0.001669574);
   h_looseLep2Pt_QCD__85->SetBinError(2,0.002080688);
   h_looseLep2Pt_QCD__85->SetBinError(3,0.001425843);
   h_looseLep2Pt_QCD__85->SetBinError(4,0.0005754946);
   h_looseLep2Pt_QCD__85->SetBinError(6,0.0004026872);
   h_looseLep2Pt_QCD__85->SetBinError(7,4.443558e-05);
   h_looseLep2Pt_QCD__85->SetEntries(25);
   h_looseLep2Pt_QCD__85->SetStats(0);

   ci = TColor::GetColor("#cccccc");
   h_looseLep2Pt_QCD__85->SetFillColor(ci);
   h_looseLep2Pt_QCD__85->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   h_looseLep2Pt_QCD__85->GetXaxis()->SetLabelFont(42);
   h_looseLep2Pt_QCD__85->GetXaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_QCD__85->GetXaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_QCD__85->GetXaxis()->SetTickLength(0.025);
   h_looseLep2Pt_QCD__85->GetXaxis()->SetTitleFont(42);
   h_looseLep2Pt_QCD__85->GetYaxis()->SetTitle("a.u./25 GeV");
   h_looseLep2Pt_QCD__85->GetYaxis()->SetLabelFont(42);
   h_looseLep2Pt_QCD__85->GetYaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_QCD__85->GetYaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_QCD__85->GetYaxis()->SetTickLength(0.025);
   h_looseLep2Pt_QCD__85->GetYaxis()->SetTitleFont(42);
   h_looseLep2Pt_QCD__85->GetZaxis()->SetLabelFont(42);
   h_looseLep2Pt_QCD__85->GetZaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_QCD__85->GetZaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_QCD__85->GetZaxis()->SetTickLength(0.025);
   h_looseLep2Pt_QCD__85->GetZaxis()->SetTitleFont(42);
   h->Add(h_looseLep2Pt_QCD,"");
   
   TH1D *h_looseLep2Pt_Diboson__86 = new TH1D("h_looseLep2Pt_Diboson__86","",20,0,500);
   h_looseLep2Pt_Diboson__86->SetBinContent(1,0.01174144);
   h_looseLep2Pt_Diboson__86->SetBinContent(2,0.01187664);
   h_looseLep2Pt_Diboson__86->SetBinContent(3,0.004759406);
   h_looseLep2Pt_Diboson__86->SetBinContent(4,0.002930753);
   h_looseLep2Pt_Diboson__86->SetBinContent(5,0.00175143);
   h_looseLep2Pt_Diboson__86->SetBinContent(6,0.0008561466);
   h_looseLep2Pt_Diboson__86->SetBinContent(7,0.000727361);
   h_looseLep2Pt_Diboson__86->SetBinContent(8,0.0006566697);
   h_looseLep2Pt_Diboson__86->SetBinContent(9,0.0001931429);
   h_looseLep2Pt_Diboson__86->SetBinContent(10,0.0004155724);
   h_looseLep2Pt_Diboson__86->SetBinContent(11,0.0002518857);
   h_looseLep2Pt_Diboson__86->SetBinContent(14,0.0002218985);
   h_looseLep2Pt_Diboson__86->SetBinContent(15,0.0002412745);
   h_looseLep2Pt_Diboson__86->SetBinContent(19,0.0001695579);
   h_looseLep2Pt_Diboson__86->SetBinError(1,0.001495699);
   h_looseLep2Pt_Diboson__86->SetBinError(2,0.001560382);
   h_looseLep2Pt_Diboson__86->SetBinError(3,0.0009896295);
   h_looseLep2Pt_Diboson__86->SetBinError(4,0.0007445459);
   h_looseLep2Pt_Diboson__86->SetBinError(5,0.0005817517);
   h_looseLep2Pt_Diboson__86->SetBinError(6,0.00038167);
   h_looseLep2Pt_Diboson__86->SetBinError(7,0.0003371659);
   h_looseLep2Pt_Diboson__86->SetBinError(8,0.0003965161);
   h_looseLep2Pt_Diboson__86->SetBinError(9,0.0001370432);
   h_looseLep2Pt_Diboson__86->SetBinError(10,0.0002946848);
   h_looseLep2Pt_Diboson__86->SetBinError(11,0.0002518857);
   h_looseLep2Pt_Diboson__86->SetBinError(14,0.0002218985);
   h_looseLep2Pt_Diboson__86->SetBinError(15,0.0002412745);
   h_looseLep2Pt_Diboson__86->SetBinError(19,0.0001695579);
   h_looseLep2Pt_Diboson__86->SetEntries(227);
   h_looseLep2Pt_Diboson__86->SetStats(0);

   ci = TColor::GetColor("#9966cc");
   h_looseLep2Pt_Diboson__86->SetFillColor(ci);
   h_looseLep2Pt_Diboson__86->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   h_looseLep2Pt_Diboson__86->GetXaxis()->SetLabelFont(42);
   h_looseLep2Pt_Diboson__86->GetXaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_Diboson__86->GetXaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_Diboson__86->GetXaxis()->SetTickLength(0.025);
   h_looseLep2Pt_Diboson__86->GetXaxis()->SetTitleFont(42);
   h_looseLep2Pt_Diboson__86->GetYaxis()->SetTitle("a.u./25 GeV");
   h_looseLep2Pt_Diboson__86->GetYaxis()->SetLabelFont(42);
   h_looseLep2Pt_Diboson__86->GetYaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_Diboson__86->GetYaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_Diboson__86->GetYaxis()->SetTickLength(0.025);
   h_looseLep2Pt_Diboson__86->GetYaxis()->SetTitleFont(42);
   h_looseLep2Pt_Diboson__86->GetZaxis()->SetLabelFont(42);
   h_looseLep2Pt_Diboson__86->GetZaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_Diboson__86->GetZaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_Diboson__86->GetZaxis()->SetTickLength(0.025);
   h_looseLep2Pt_Diboson__86->GetZaxis()->SetTitleFont(42);
   h->Add(h_looseLep2Pt_Diboson,"");
   
   TH1D *h_looseLep2Pt_ZpLjets__87 = new TH1D("h_looseLep2Pt_ZpLjets__87","",20,0,500);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(1,0.02667925);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(2,0.01473475);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(3,0.003756899);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(4,0.001254256);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(5,0.0004467979);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(6,0.0002317029);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(7,0.0001188745);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(8,5.180996e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(9,3.953698e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(10,5.25799e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(11,8.216096e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(12,1.278228e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(13,9.580175e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(14,1.588075e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(15,1.177547e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(16,1.223887e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(17,7.306459e-07);
   h_looseLep2Pt_ZpLjets__87->SetBinContent(20,1.45491e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinError(1,0.0005258423);
   h_looseLep2Pt_ZpLjets__87->SetBinError(2,0.0003466748);
   h_looseLep2Pt_ZpLjets__87->SetBinError(3,0.0001526343);
   h_looseLep2Pt_ZpLjets__87->SetBinError(4,8.095507e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinError(5,4.333559e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinError(6,3.359842e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinError(7,2.459211e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinError(8,1.436585e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinError(9,1.618837e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinError(10,2.012392e-05);
   h_looseLep2Pt_ZpLjets__87->SetBinError(11,3.870226e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinError(12,6.226944e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinError(13,5.393688e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinError(14,6.993857e-07);
   h_looseLep2Pt_ZpLjets__87->SetBinError(15,7.943273e-06);
   h_looseLep2Pt_ZpLjets__87->SetBinError(16,7.962562e-07);
   h_looseLep2Pt_ZpLjets__87->SetBinError(17,5.208535e-07);
   h_looseLep2Pt_ZpLjets__87->SetBinError(20,1.161384e-06);
   h_looseLep2Pt_ZpLjets__87->SetEntries(24915);
   h_looseLep2Pt_ZpLjets__87->SetStats(0);

   ci = TColor::GetColor("#3399cc");
   h_looseLep2Pt_ZpLjets__87->SetFillColor(ci);
   h_looseLep2Pt_ZpLjets__87->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   h_looseLep2Pt_ZpLjets__87->GetXaxis()->SetLabelFont(42);
   h_looseLep2Pt_ZpLjets__87->GetXaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_ZpLjets__87->GetXaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_ZpLjets__87->GetXaxis()->SetTickLength(0.025);
   h_looseLep2Pt_ZpLjets__87->GetXaxis()->SetTitleFont(42);
   h_looseLep2Pt_ZpLjets__87->GetYaxis()->SetTitle("a.u./25 GeV");
   h_looseLep2Pt_ZpLjets__87->GetYaxis()->SetLabelFont(42);
   h_looseLep2Pt_ZpLjets__87->GetYaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_ZpLjets__87->GetYaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_ZpLjets__87->GetYaxis()->SetTickLength(0.025);
   h_looseLep2Pt_ZpLjets__87->GetYaxis()->SetTitleFont(42);
   h_looseLep2Pt_ZpLjets__87->GetZaxis()->SetLabelFont(42);
   h_looseLep2Pt_ZpLjets__87->GetZaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_ZpLjets__87->GetZaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_ZpLjets__87->GetZaxis()->SetTickLength(0.025);
   h_looseLep2Pt_ZpLjets__87->GetZaxis()->SetTitleFont(42);
   h->Add(h_looseLep2Pt_Z+jets,"");
   
   TH1D *h_looseLep2Pt_WpLjets__88 = new TH1D("h_looseLep2Pt_WpLjets__88","",20,0,500);
   h_looseLep2Pt_WpLjets__88->SetBinContent(1,0.02932453);
   h_looseLep2Pt_WpLjets__88->SetBinContent(2,0.006497682);
   h_looseLep2Pt_WpLjets__88->SetBinContent(3,0.002693998);
   h_looseLep2Pt_WpLjets__88->SetBinContent(4,0.001997142);
   h_looseLep2Pt_WpLjets__88->SetBinContent(5,0.001838293);
   h_looseLep2Pt_WpLjets__88->SetBinContent(6,0.0008665013);
   h_looseLep2Pt_WpLjets__88->SetBinContent(7,0.001024588);
   h_looseLep2Pt_WpLjets__88->SetBinContent(8,0.0007202847);
   h_looseLep2Pt_WpLjets__88->SetBinContent(9,0.0001418163);
   h_looseLep2Pt_WpLjets__88->SetBinContent(10,0.0002837216);
   h_looseLep2Pt_WpLjets__88->SetBinContent(11,0.0001795552);
   h_looseLep2Pt_WpLjets__88->SetBinContent(12,1.395914e-05);
   h_looseLep2Pt_WpLjets__88->SetBinContent(13,1.974067e-05);
   h_looseLep2Pt_WpLjets__88->SetBinContent(14,5.586989e-06);
   h_looseLep2Pt_WpLjets__88->SetBinContent(15,4.838904e-05);
   h_looseLep2Pt_WpLjets__88->SetBinContent(16,8.80718e-06);
   h_looseLep2Pt_WpLjets__88->SetBinContent(17,2.15012e-06);
   h_looseLep2Pt_WpLjets__88->SetBinContent(18,3.517553e-06);
   h_looseLep2Pt_WpLjets__88->SetBinContent(19,3.815246e-07);
   h_looseLep2Pt_WpLjets__88->SetBinContent(20,1.212912e-05);
   h_looseLep2Pt_WpLjets__88->SetBinError(1,0.001351271);
   h_looseLep2Pt_WpLjets__88->SetBinError(2,0.0006213388);
   h_looseLep2Pt_WpLjets__88->SetBinError(3,0.0004390932);
   h_looseLep2Pt_WpLjets__88->SetBinError(4,0.0003469893);
   h_looseLep2Pt_WpLjets__88->SetBinError(5,0.0003545163);
   h_looseLep2Pt_WpLjets__88->SetBinError(6,0.0002163202);
   h_looseLep2Pt_WpLjets__88->SetBinError(7,0.0002255816);
   h_looseLep2Pt_WpLjets__88->SetBinError(8,0.0001927611);
   h_looseLep2Pt_WpLjets__88->SetBinError(9,6.565621e-05);
   h_looseLep2Pt_WpLjets__88->SetBinError(10,0.0001456303);
   h_looseLep2Pt_WpLjets__88->SetBinError(11,9.307131e-05);
   h_looseLep2Pt_WpLjets__88->SetBinError(12,4.209394e-06);
   h_looseLep2Pt_WpLjets__88->SetBinError(13,1.131021e-05);
   h_looseLep2Pt_WpLjets__88->SetBinError(14,3.172661e-06);
   h_looseLep2Pt_WpLjets__88->SetBinError(15,4.146079e-05);
   h_looseLep2Pt_WpLjets__88->SetBinError(16,5.369418e-06);
   h_looseLep2Pt_WpLjets__88->SetBinError(17,8.346041e-07);
   h_looseLep2Pt_WpLjets__88->SetBinError(18,2.861137e-06);
   h_looseLep2Pt_WpLjets__88->SetBinError(19,2.949137e-07);
   h_looseLep2Pt_WpLjets__88->SetBinError(20,6.047119e-06);
   h_looseLep2Pt_WpLjets__88->SetEntries(3309);
   h_looseLep2Pt_WpLjets__88->SetStats(0);

   ci = TColor::GetColor("#66cc66");
   h_looseLep2Pt_WpLjets__88->SetFillColor(ci);
   h_looseLep2Pt_WpLjets__88->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   h_looseLep2Pt_WpLjets__88->GetXaxis()->SetLabelFont(42);
   h_looseLep2Pt_WpLjets__88->GetXaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_WpLjets__88->GetXaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_WpLjets__88->GetXaxis()->SetTickLength(0.025);
   h_looseLep2Pt_WpLjets__88->GetXaxis()->SetTitleFont(42);
   h_looseLep2Pt_WpLjets__88->GetYaxis()->SetTitle("a.u./25 GeV");
   h_looseLep2Pt_WpLjets__88->GetYaxis()->SetLabelFont(42);
   h_looseLep2Pt_WpLjets__88->GetYaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_WpLjets__88->GetYaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_WpLjets__88->GetYaxis()->SetTickLength(0.025);
   h_looseLep2Pt_WpLjets__88->GetYaxis()->SetTitleFont(42);
   h_looseLep2Pt_WpLjets__88->GetZaxis()->SetLabelFont(42);
   h_looseLep2Pt_WpLjets__88->GetZaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_WpLjets__88->GetZaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_WpLjets__88->GetZaxis()->SetTickLength(0.025);
   h_looseLep2Pt_WpLjets__88->GetZaxis()->SetTitleFont(42);
   h->Add(h_looseLep2Pt_W+jets,"");
   
   TH1D *h_looseLep2Pt_TopsPoPLFcP__89 = new TH1D("h_looseLep2Pt_TopsPoPLFcP__89","",20,0,500);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(1,0.09566986);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(2,0.1184424);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(3,0.0578968);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(4,0.02776582);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(5,0.01352875);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(6,0.006884179);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(7,0.003658057);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(8,0.001948227);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(9,0.001021047);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(10,0.000535609);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(11,0.000252071);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(12,0.0001040926);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(13,0.0002597359);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(14,4.685411e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(15,2.316069e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(16,7.098286e-06);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(17,1.098163e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(18,5.405239e-06);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(19,1.254191e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinContent(20,6.416628e-06);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(1,0.001032897);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(2,0.001159746);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(3,0.0008366751);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(4,0.0005883119);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(5,0.0003798421);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(6,0.0002961909);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(7,0.0002252512);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(8,0.0001593319);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(9,9.938102e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(10,9.688184e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(11,3.857011e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(12,2.361438e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(13,0.0001125534);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(14,1.684722e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(15,1.087063e-05);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(16,7.098286e-06);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(17,7.125221e-06);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(18,3.836305e-06);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(19,8.954834e-06);
   h_looseLep2Pt_TopsPoPLFcP__89->SetBinError(20,4.538739e-06);
   h_looseLep2Pt_TopsPoPLFcP__89->SetEntries(45754);
   h_looseLep2Pt_TopsPoPLFcP__89->SetStats(0);

   ci = TColor::GetColor("#cc33cc");
   h_looseLep2Pt_TopsPoPLFcP__89->SetFillColor(ci);
   h_looseLep2Pt_TopsPoPLFcP__89->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   h_looseLep2Pt_TopsPoPLFcP__89->GetXaxis()->SetLabelFont(42);
   h_looseLep2Pt_TopsPoPLFcP__89->GetXaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_TopsPoPLFcP__89->GetXaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_TopsPoPLFcP__89->GetXaxis()->SetTickLength(0.025);
   h_looseLep2Pt_TopsPoPLFcP__89->GetXaxis()->SetTitleFont(42);
   h_looseLep2Pt_TopsPoPLFcP__89->GetYaxis()->SetTitle("a.u./25 GeV");
   h_looseLep2Pt_TopsPoPLFcP__89->GetYaxis()->SetLabelFont(42);
   h_looseLep2Pt_TopsPoPLFcP__89->GetYaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_TopsPoPLFcP__89->GetYaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_TopsPoPLFcP__89->GetYaxis()->SetTickLength(0.025);
   h_looseLep2Pt_TopsPoPLFcP__89->GetYaxis()->SetTitleFont(42);
   h_looseLep2Pt_TopsPoPLFcP__89->GetZaxis()->SetLabelFont(42);
   h_looseLep2Pt_TopsPoPLFcP__89->GetZaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_TopsPoPLFcP__89->GetZaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_TopsPoPLFcP__89->GetZaxis()->SetTickLength(0.025);
   h_looseLep2Pt_TopsPoPLFcP__89->GetZaxis()->SetTitleFont(42);
   h->Add(h_looseLep2Pt_Top (LF),"");
   
   TH1D *h_looseLep2Pt_TopsPoPHFcP__90 = new TH1D("h_looseLep2Pt_TopsPoPHFcP__90","",20,0,500);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(1,0.1041412);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(2,0.1735886);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(3,0.1116258);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(4,0.06454315);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(5,0.03441357);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(6,0.01992067);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(7,0.01014646);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(8,0.005947886);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(9,0.002876054);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(10,0.001475723);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(11,0.0007236292);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(12,0.0004357554);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(13,0.0002249375);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(14,0.0001475853);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(15,0.0001020681);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(16,6.402955e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(17,1.980568e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(18,2.33998e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinContent(20,2.517288e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(1,0.001126128);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(2,0.001474884);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(3,0.001116875);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(4,0.0008934187);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(5,0.0006246887);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(6,0.0005076532);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(7,0.0003555866);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(8,0.000286312);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(9,0.0001737097);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(10,0.0001517557);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(11,6.387877e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(12,5.265571e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(13,3.442087e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(14,2.732865e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(15,2.352865e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(16,1.915664e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(17,1.063003e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(18,1.102394e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetBinError(20,1.216417e-05);
   h_looseLep2Pt_TopsPoPHFcP__90->SetEntries(77950);
   h_looseLep2Pt_TopsPoPHFcP__90->SetStats(0);

   ci = TColor::GetColor("#ff9900");
   h_looseLep2Pt_TopsPoPHFcP__90->SetFillColor(ci);
   h_looseLep2Pt_TopsPoPHFcP__90->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   h_looseLep2Pt_TopsPoPHFcP__90->GetXaxis()->SetLabelFont(42);
   h_looseLep2Pt_TopsPoPHFcP__90->GetXaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_TopsPoPHFcP__90->GetXaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_TopsPoPHFcP__90->GetXaxis()->SetTickLength(0.025);
   h_looseLep2Pt_TopsPoPHFcP__90->GetXaxis()->SetTitleFont(42);
   h_looseLep2Pt_TopsPoPHFcP__90->GetYaxis()->SetTitle("a.u./25 GeV");
   h_looseLep2Pt_TopsPoPHFcP__90->GetYaxis()->SetLabelFont(42);
   h_looseLep2Pt_TopsPoPHFcP__90->GetYaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_TopsPoPHFcP__90->GetYaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_TopsPoPHFcP__90->GetYaxis()->SetTickLength(0.025);
   h_looseLep2Pt_TopsPoPHFcP__90->GetYaxis()->SetTitleFont(42);
   h_looseLep2Pt_TopsPoPHFcP__90->GetZaxis()->SetLabelFont(42);
   h_looseLep2Pt_TopsPoPHFcP__90->GetZaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_TopsPoPHFcP__90->GetZaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_TopsPoPHFcP__90->GetZaxis()->SetTickLength(0.025);
   h_looseLep2Pt_TopsPoPHFcP__90->GetZaxis()->SetTitleFont(42);
   h->Add(h_looseLep2Pt_Top (HF),"");
   h->Draw("hist");
   
   TH1D *hsum__91 = new TH1D("hsum__91","",20,0,500);
   hsum__91->SetBinContent(1,0.271725);
   hsum__91->SetBinContent(2,0.3294396);
   hsum__91->SetBinContent(3,0.1824981);
   hsum__91->SetBinContent(4,0.09937792);
   hsum__91->SetBinContent(5,0.05197885);
   hsum__91->SetBinContent(6,0.02916189);
   hsum__91->SetBinContent(7,0.01573805);
   hsum__91->SetBinContent(8,0.009324878);
   hsum__91->SetBinContent(9,0.004271597);
   hsum__91->SetBinContent(10,0.002763206);
   hsum__91->SetBinContent(11,0.001415357);
   hsum__91->SetBinContent(12,0.0005665895);
   hsum__91->SetBinContent(13,0.0005139942);
   hsum__91->SetBinContent(14,0.000423513);
   hsum__91->SetBinContent(15,0.0004266677);
   hsum__91->SetBinContent(16,8.11589e-05);
   hsum__91->SetBinContent(17,3.366807e-05);
   hsum__91->SetBinContent(18,3.232259e-05);
   hsum__91->SetBinContent(19,0.0001824813);
   hsum__91->SetBinContent(20,4.517354e-05);
   hsum__91->SetBinError(1,0.003076049);
   hsum__91->SetBinError(2,0.003284904);
   hsum__91->SetBinError(3,0.002275067);
   hsum__91->SetBinError(4,0.001468607);
   hsum__91->SetBinError(5,0.001000255);
   hsum__91->SetBinError(6,0.0008373727);
   hsum__91->SetBinError(7,0.0005867939);
   hsum__91->SetBinError(8,0.0005494993);
   hsum__91->SetBinError(9,0.0002518041);
   hsum__91->SetBinError(10,0.0003753241);
   hsum__91->SetBinError(11,0.0002787325);
   hsum__91->SetBinError(12,5.819584e-05);
   hsum__91->SetBinError(13,0.0001183642);
   hsum__91->SetBinError(14,0.0002242324);
   hsum__91->SetBinError(15,0.0002463072);
   hsum__91->SetBinError(16,2.113829e-05);
   hsum__91->SetBinError(17,1.283488e-05);
   hsum__91->SetBinError(18,1.201793e-05);
   hsum__91->SetBinError(19,0.0001697944);
   hsum__91->SetBinError(20,1.436954e-05);
   hsum__91->SetEntries(65);
   hsum__91->SetStats(0);

   ci = 1187;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   hsum__91->SetFillColor(ci);
   hsum__91->SetFillStyle(3003);
   hsum__91->SetLineWidth(0);
   hsum__91->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   hsum__91->GetXaxis()->SetLabelFont(42);
   hsum__91->GetXaxis()->SetLabelOffset(0.007);
   hsum__91->GetXaxis()->SetTitleSize(0.05);
   hsum__91->GetXaxis()->SetTickLength(0.025);
   hsum__91->GetXaxis()->SetTitleFont(42);
   hsum__91->GetYaxis()->SetTitle("a.u./25 GeV");
   hsum__91->GetYaxis()->SetLabelFont(42);
   hsum__91->GetYaxis()->SetLabelOffset(0.007);
   hsum__91->GetYaxis()->SetTitleSize(0.05);
   hsum__91->GetYaxis()->SetTickLength(0.025);
   hsum__91->GetYaxis()->SetTitleFont(42);
   hsum__91->GetZaxis()->SetLabelFont(42);
   hsum__91->GetZaxis()->SetLabelOffset(0.007);
   hsum__91->GetZaxis()->SetTitleSize(0.05);
   hsum__91->GetZaxis()->SetTickLength(0.025);
   hsum__91->GetZaxis()->SetTitleFont(42);
   hsum__91->Draw("e2 same");
   
   TH1D *h_looseLep2Pt_Data__92 = new TH1D("h_looseLep2Pt_Data__92","",20,0,500);
   h_looseLep2Pt_Data__92->SetBinContent(1,0.2915764);
   h_looseLep2Pt_Data__92->SetBinContent(2,0.3247432);
   h_looseLep2Pt_Data__92->SetBinContent(3,0.1760106);
   h_looseLep2Pt_Data__92->SetBinContent(4,0.0916329);
   h_looseLep2Pt_Data__92->SetBinContent(5,0.04946763);
   h_looseLep2Pt_Data__92->SetBinContent(6,0.02920946);
   h_looseLep2Pt_Data__92->SetBinContent(7,0.01620654);
   h_looseLep2Pt_Data__92->SetBinContent(8,0.008904174);
   h_looseLep2Pt_Data__92->SetBinContent(9,0.004805427);
   h_looseLep2Pt_Data__92->SetBinContent(10,0.002732498);
   h_looseLep2Pt_Data__92->SetBinContent(11,0.001837369);
   h_looseLep2Pt_Data__92->SetBinContent(12,0.001177801);
   h_looseLep2Pt_Data__92->SetBinContent(13,0.0008951286);
   h_looseLep2Pt_Data__92->SetBinContent(14,0.0002826722);
   h_looseLep2Pt_Data__92->SetBinContent(15,0.0001413361);
   h_looseLep2Pt_Data__92->SetBinContent(16,0.0001884481);
   h_looseLep2Pt_Data__92->SetBinContent(17,0.0001413361);
   h_looseLep2Pt_Data__92->SetBinContent(20,4.711203e-05);
   h_looseLep2Pt_Data__92->SetBinError(1,0.003706313);
   h_looseLep2Pt_Data__92->SetBinError(2,0.003911434);
   h_looseLep2Pt_Data__92->SetBinError(3,0.002879621);
   h_looseLep2Pt_Data__92->SetBinError(4,0.002077742);
   h_looseLep2Pt_Data__92->SetBinError(5,0.001526604);
   h_looseLep2Pt_Data__92->SetBinError(6,0.00117308);
   h_looseLep2Pt_Data__92->SetBinError(7,0.000873798);
   h_looseLep2Pt_Data__92->SetBinError(8,0.0006476834);
   h_looseLep2Pt_Data__92->SetBinError(9,0.0004758082);
   h_looseLep2Pt_Data__92->SetBinError(10,0.0003587945);
   h_looseLep2Pt_Data__92->SetBinError(11,0.0002942145);
   h_looseLep2Pt_Data__92->SetBinError(12,0.0002355602);
   h_looseLep2Pt_Data__92->SetBinError(13,0.0002053566);
   h_looseLep2Pt_Data__92->SetBinError(14,0.0001154004);
   h_looseLep2Pt_Data__92->SetBinError(15,8.160043e-05);
   h_looseLep2Pt_Data__92->SetBinError(16,9.422406e-05);
   h_looseLep2Pt_Data__92->SetBinError(17,8.160043e-05);
   h_looseLep2Pt_Data__92->SetBinError(20,4.711203e-05);
   h_looseLep2Pt_Data__92->SetEntries(21226);
   h_looseLep2Pt_Data__92->SetStats(0);
   h_looseLep2Pt_Data__92->SetLineWidth(3);
   h_looseLep2Pt_Data__92->SetMarkerStyle(20);
   h_looseLep2Pt_Data__92->SetMarkerSize(2);
   h_looseLep2Pt_Data__92->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   h_looseLep2Pt_Data__92->GetXaxis()->SetLabelFont(42);
   h_looseLep2Pt_Data__92->GetXaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_Data__92->GetXaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_Data__92->GetXaxis()->SetTickLength(0.025);
   h_looseLep2Pt_Data__92->GetXaxis()->SetTitleFont(42);
   h_looseLep2Pt_Data__92->GetYaxis()->SetTitle("a.u./25 GeV");
   h_looseLep2Pt_Data__92->GetYaxis()->SetLabelFont(42);
   h_looseLep2Pt_Data__92->GetYaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_Data__92->GetYaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_Data__92->GetYaxis()->SetTickLength(0.025);
   h_looseLep2Pt_Data__92->GetYaxis()->SetTitleFont(42);
   h_looseLep2Pt_Data__92->GetZaxis()->SetLabelFont(42);
   h_looseLep2Pt_Data__92->GetZaxis()->SetLabelOffset(0.007);
   h_looseLep2Pt_Data__92->GetZaxis()->SetTitleSize(0.05);
   h_looseLep2Pt_Data__92->GetZaxis()->SetTickLength(0.025);
   h_looseLep2Pt_Data__92->GetZaxis()->SetTitleFont(42);
   h_looseLep2Pt_Data__92->Draw("elp same");
   
   TLegend *leg = new TLegend(0.6,0.55,0.88,0.9,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   TLegendEntry *entry=leg->AddEntry("h_looseLep2Pt_Data","Data","ELP");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(3);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(2);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_Top (HF)","Top (HF)","F");

   ci = TColor::GetColor("#ff9900");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_Top (LF)","Top (LF)","F");

   ci = TColor::GetColor("#cc33cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_W+jets","W+jets","F");

   ci = TColor::GetColor("#66cc66");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_Z+jets","Z+jets","F");

   ci = TColor::GetColor("#3399cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_Diboson","Diboson","F");

   ci = TColor::GetColor("#9966cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_QCD","QCD","F");

   ci = TColor::GetColor("#cccccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   
   leg = new TLegend(0.6,0.55,0.88,0.9,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   entry=leg->AddEntry("h_looseLep2Pt_Data","Data","ELP");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(3);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(2);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_Top (HF)","Top (HF)","F");

   ci = TColor::GetColor("#ff9900");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_Top (LF)","Top (LF)","F");

   ci = TColor::GetColor("#cc33cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_W+jets","W+jets","F");

   ci = TColor::GetColor("#66cc66");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_Z+jets","Z+jets","F");

   ci = TColor::GetColor("#3399cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_Diboson","Diboson","F");

   ci = TColor::GetColor("#9966cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_looseLep2Pt_QCD","QCD","F");

   ci = TColor::GetColor("#cccccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   TLatex *   tex = new TLatex(0.18,0.85,"CMS");
tex->SetNDC();
   tex->SetTextSize(0.06);
   tex->SetLineWidth(2);
   tex->Draw();
      tex = new TLatex(0.28,0.85,"Preliminary");
tex->SetNDC();
   tex->SetTextFont(52);
   tex->SetTextSize(0.06);
   tex->SetLineWidth(2);
   tex->Draw();
      tex = new TLatex(0.9,0.94,"36.6 fb^{-1} (13 TeV)");
tex->SetNDC();
   tex->SetTextAlign(31);
   tex->SetTextFont(42);
   tex->SetTextSize(0.04);
   tex->SetLineWidth(2);
   tex->Draw();
   pad1->Modified();
   c1->cd();
  
// ------------>Primitives in pad: pad2
   TPad *pad2 = new TPad("pad2", "pad2",0,0.05,1,0.3);
   pad2->Draw();
   pad2->cd();
   pad2->Range(-93.75,-0.8914286,531.25,0.48);
   pad2->SetFillColor(0);
   pad2->SetBorderMode(0);
   pad2->SetBorderSize(2);
   pad2->SetGridy();
   pad2->SetTickx(1);
   pad2->SetTicky(1);
   pad2->SetLeftMargin(0.15);
   pad2->SetRightMargin(0.05);
   pad2->SetTopMargin(0);
   pad2->SetBottomMargin(0.3);
   pad2->SetFrameFillStyle(0);
   pad2->SetFrameBorderMode(0);
   pad2->SetFrameFillStyle(0);
   pad2->SetFrameBorderMode(0);
   
   TH1D *ratio__93 = new TH1D("ratio__93","",20,0,500);
   ratio__93->SetBinContent(1,0.07305694);
   ratio__93->SetBinContent(2,-0.01425564);
   ratio__93->SetBinContent(3,-0.03554857);
   ratio__93->SetBinContent(4,-0.07793492);
   ratio__93->SetBinContent(5,-0.04831219);
   ratio__93->SetBinContent(6,0.00163126);
   ratio__93->SetBinContent(7,0.02976763);
   ratio__93->SetBinContent(8,-0.04511625);
   ratio__93->SetBinContent(9,0.1249721);
   ratio__93->SetBinContent(10,-0.01111317);
   ratio__93->SetBinContent(11,0.2981665);
   ratio__93->SetBinContent(12,1.078755);
   ratio__93->SetBinContent(13,0.741515);
   ratio__93->SetBinContent(14,-0.3325537);
   ratio__93->SetBinContent(15,-0.6687443);
   ratio__93->SetBinContent(16,1.321965);
   ratio__93->SetBinContent(17,3.197927);
   ratio__93->SetBinContent(18,-999);
   ratio__93->SetBinContent(19,-999);
   ratio__93->SetBinContent(20,0.04291213);
   ratio__93->SetBinError(1,0.0001);
   ratio__93->SetBinError(2,0.0001);
   ratio__93->SetBinError(3,0.0001);
   ratio__93->SetBinError(4,0.0001);
   ratio__93->SetBinError(5,0.0001);
   ratio__93->SetBinError(6,0.0001);
   ratio__93->SetBinError(7,0.0001);
   ratio__93->SetBinError(8,0.0001);
   ratio__93->SetBinError(9,0.0001);
   ratio__93->SetBinError(10,0.0001);
   ratio__93->SetBinError(11,0.0001);
   ratio__93->SetBinError(12,0.0001);
   ratio__93->SetBinError(13,0.0001);
   ratio__93->SetBinError(14,0.0001);
   ratio__93->SetBinError(15,0.0001);
   ratio__93->SetBinError(16,0.0001);
   ratio__93->SetBinError(17,0.0001);
   ratio__93->SetBinError(18,0.0001);
   ratio__93->SetBinError(19,0.0001);
   ratio__93->SetBinError(20,0.0001);
   ratio__93->SetMinimum(-0.48);
   ratio__93->SetMaximum(0.48);
   ratio__93->SetEntries(21246);
   ratio__93->SetStats(0);
   ratio__93->SetLineWidth(3);
   ratio__93->SetMarkerStyle(20);
   ratio__93->SetMarkerSize(2);
   ratio__93->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   ratio__93->GetXaxis()->SetLabelFont(43);
   ratio__93->GetXaxis()->SetLabelOffset(0.007);
   ratio__93->GetXaxis()->SetLabelSize(30);
   ratio__93->GetXaxis()->SetTitleSize(40);
   ratio__93->GetXaxis()->SetTickLength(0.025);
   ratio__93->GetXaxis()->SetTitleOffset(5);
   ratio__93->GetXaxis()->SetTitleFont(43);
   ratio__93->GetYaxis()->SetTitle("#frac{Data-Exp}{Exp}");
   ratio__93->GetYaxis()->SetNdivisions(5);
   ratio__93->GetYaxis()->SetLabelFont(43);
   ratio__93->GetYaxis()->SetLabelOffset(0.007);
   ratio__93->GetYaxis()->SetLabelSize(30);
   ratio__93->GetYaxis()->SetTitleSize(40);
   ratio__93->GetYaxis()->SetTickLength(0.025);
   ratio__93->GetYaxis()->SetTitleOffset(2.5);
   ratio__93->GetYaxis()->SetTitleFont(43);
   ratio__93->GetZaxis()->SetLabelFont(42);
   ratio__93->GetZaxis()->SetLabelOffset(0.007);
   ratio__93->GetZaxis()->SetTitleSize(0.05);
   ratio__93->GetZaxis()->SetTickLength(0.025);
   ratio__93->GetZaxis()->SetTitleFont(42);
   ratio__93->Draw("elp");
   
   TH1D *zero__94 = new TH1D("zero__94","",20,0,500);
   zero__94->SetBinError(1,0.003706313);
   zero__94->SetBinError(2,0.003911434);
   zero__94->SetBinError(3,0.002879621);
   zero__94->SetBinError(4,0.002077742);
   zero__94->SetBinError(5,0.001526604);
   zero__94->SetBinError(6,0.00117308);
   zero__94->SetBinError(7,0.000873798);
   zero__94->SetBinError(8,0.0006476834);
   zero__94->SetBinError(9,0.0004758082);
   zero__94->SetBinError(10,0.0003587945);
   zero__94->SetBinError(11,0.0002942145);
   zero__94->SetBinError(12,0.0002355602);
   zero__94->SetBinError(13,0.0002053566);
   zero__94->SetBinError(14,0.0001154004);
   zero__94->SetBinError(15,8.160043e-05);
   zero__94->SetBinError(16,9.422406e-05);
   zero__94->SetBinError(17,8.160043e-05);
   zero__94->SetBinError(20,4.711203e-05);
   zero__94->SetEntries(21246);
   zero__94->SetStats(0);
   zero__94->SetLineWidth(3);
   zero__94->SetMarkerStyle(20);
   zero__94->SetMarkerSize(2);
   zero__94->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   zero__94->GetXaxis()->SetLabelFont(42);
   zero__94->GetXaxis()->SetLabelOffset(0.007);
   zero__94->GetXaxis()->SetTitleSize(0.05);
   zero__94->GetXaxis()->SetTickLength(0.025);
   zero__94->GetXaxis()->SetTitleFont(42);
   zero__94->GetYaxis()->SetTitle("a.u./25 GeV");
   zero__94->GetYaxis()->SetLabelFont(42);
   zero__94->GetYaxis()->SetLabelOffset(0.007);
   zero__94->GetYaxis()->SetTitleSize(0.05);
   zero__94->GetYaxis()->SetTickLength(0.025);
   zero__94->GetYaxis()->SetTitleFont(42);
   zero__94->GetZaxis()->SetLabelFont(42);
   zero__94->GetZaxis()->SetLabelOffset(0.007);
   zero__94->GetZaxis()->SetTitleSize(0.05);
   zero__94->GetZaxis()->SetTickLength(0.025);
   zero__94->GetZaxis()->SetTitleFont(42);
   zero__94->Draw("hist same");
   
   TH1D *sumratioup__95 = new TH1D("sumratioup__95","",20,0,500);
   sumratioup__95->SetBinContent(1,0.01132045);
   sumratioup__95->SetBinContent(2,0.009971187);
   sumratioup__95->SetBinContent(3,0.01246625);
   sumratioup__95->SetBinContent(4,0.014778);
   sumratioup__95->SetBinContent(5,0.01924351);
   sumratioup__95->SetBinContent(6,0.02871463);
   sumratioup__95->SetBinContent(7,0.03728504);
   sumratioup__95->SetBinContent(8,0.05892831);
   sumratioup__95->SetBinContent(9,0.05894846);
   sumratioup__95->SetBinContent(10,0.1358292);
   sumratioup__95->SetBinContent(11,0.1969344);
   sumratioup__95->SetBinContent(12,0.1027125);
   sumratioup__95->SetBinContent(13,0.2302831);
   sumratioup__95->SetBinContent(14,0.5294582);
   sumratioup__95->SetBinContent(15,0.577281);
   sumratioup__95->SetBinContent(16,0.2604556);
   sumratioup__95->SetBinContent(17,0.3812182);
   sumratioup__95->SetBinContent(18,0.3718119);
   sumratioup__95->SetBinContent(19,0.9304757);
   sumratioup__95->SetBinContent(20,0.3180965);
   sumratioup__95->SetBinError(1,0.003076049);
   sumratioup__95->SetBinError(2,0.003284904);
   sumratioup__95->SetBinError(3,0.002275067);
   sumratioup__95->SetBinError(4,0.001468607);
   sumratioup__95->SetBinError(5,0.001000255);
   sumratioup__95->SetBinError(6,0.0008373727);
   sumratioup__95->SetBinError(7,0.0005867939);
   sumratioup__95->SetBinError(8,0.0005494993);
   sumratioup__95->SetBinError(9,0.0002518041);
   sumratioup__95->SetBinError(10,0.0003753241);
   sumratioup__95->SetBinError(11,0.0002787325);
   sumratioup__95->SetBinError(12,5.819584e-05);
   sumratioup__95->SetBinError(13,0.0001183642);
   sumratioup__95->SetBinError(14,0.0002242324);
   sumratioup__95->SetBinError(15,0.0002463072);
   sumratioup__95->SetBinError(16,2.113829e-05);
   sumratioup__95->SetBinError(17,1.283488e-05);
   sumratioup__95->SetBinError(18,1.201793e-05);
   sumratioup__95->SetBinError(19,0.0001697944);
   sumratioup__95->SetBinError(20,1.436954e-05);
   sumratioup__95->SetEntries(85);
   sumratioup__95->SetStats(0);

   ci = 1187;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   sumratioup__95->SetFillColor(ci);
   sumratioup__95->SetFillStyle(3003);
   sumratioup__95->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   sumratioup__95->GetXaxis()->SetLabelFont(42);
   sumratioup__95->GetXaxis()->SetLabelOffset(0.007);
   sumratioup__95->GetXaxis()->SetTitleSize(0.05);
   sumratioup__95->GetXaxis()->SetTickLength(0.025);
   sumratioup__95->GetXaxis()->SetTitleFont(42);
   sumratioup__95->GetYaxis()->SetTitle("a.u./25 GeV");
   sumratioup__95->GetYaxis()->SetLabelFont(42);
   sumratioup__95->GetYaxis()->SetLabelOffset(0.007);
   sumratioup__95->GetYaxis()->SetTitleSize(0.05);
   sumratioup__95->GetYaxis()->SetTickLength(0.025);
   sumratioup__95->GetYaxis()->SetTitleFont(42);
   sumratioup__95->GetZaxis()->SetLabelFont(42);
   sumratioup__95->GetZaxis()->SetLabelOffset(0.007);
   sumratioup__95->GetZaxis()->SetTitleSize(0.05);
   sumratioup__95->GetZaxis()->SetTickLength(0.025);
   sumratioup__95->GetZaxis()->SetTitleFont(42);
   sumratioup__95->Draw("hist same");
   
   TH1D *sumratiodown__96 = new TH1D("sumratiodown__96","",20,0,500);
   sumratiodown__96->SetBinContent(1,-0.01132045);
   sumratiodown__96->SetBinContent(2,-0.009971187);
   sumratiodown__96->SetBinContent(3,-0.01246625);
   sumratiodown__96->SetBinContent(4,-0.014778);
   sumratiodown__96->SetBinContent(5,-0.01924351);
   sumratiodown__96->SetBinContent(6,-0.02871463);
   sumratiodown__96->SetBinContent(7,-0.03728504);
   sumratiodown__96->SetBinContent(8,-0.05892831);
   sumratiodown__96->SetBinContent(9,-0.05894846);
   sumratiodown__96->SetBinContent(10,-0.1358292);
   sumratiodown__96->SetBinContent(11,-0.1969344);
   sumratiodown__96->SetBinContent(12,-0.1027125);
   sumratiodown__96->SetBinContent(13,-0.2302831);
   sumratiodown__96->SetBinContent(14,-0.5294582);
   sumratiodown__96->SetBinContent(15,-0.577281);
   sumratiodown__96->SetBinContent(16,-0.2604556);
   sumratiodown__96->SetBinContent(17,-0.3812182);
   sumratiodown__96->SetBinContent(18,-0.3718119);
   sumratiodown__96->SetBinContent(19,-0.9304757);
   sumratiodown__96->SetBinContent(20,-0.3180965);
   sumratiodown__96->SetBinError(1,0.003076049);
   sumratiodown__96->SetBinError(2,0.003284904);
   sumratiodown__96->SetBinError(3,0.002275067);
   sumratiodown__96->SetBinError(4,0.001468607);
   sumratiodown__96->SetBinError(5,0.001000255);
   sumratiodown__96->SetBinError(6,0.0008373727);
   sumratiodown__96->SetBinError(7,0.0005867939);
   sumratiodown__96->SetBinError(8,0.0005494993);
   sumratiodown__96->SetBinError(9,0.0002518041);
   sumratiodown__96->SetBinError(10,0.0003753241);
   sumratiodown__96->SetBinError(11,0.0002787325);
   sumratiodown__96->SetBinError(12,5.819584e-05);
   sumratiodown__96->SetBinError(13,0.0001183642);
   sumratiodown__96->SetBinError(14,0.0002242324);
   sumratiodown__96->SetBinError(15,0.0002463072);
   sumratiodown__96->SetBinError(16,2.113829e-05);
   sumratiodown__96->SetBinError(17,1.283488e-05);
   sumratiodown__96->SetBinError(18,1.201793e-05);
   sumratiodown__96->SetBinError(19,0.0001697944);
   sumratiodown__96->SetBinError(20,1.436954e-05);
   sumratiodown__96->SetEntries(85);
   sumratiodown__96->SetStats(0);

   ci = 1187;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   sumratiodown__96->SetFillColor(ci);
   sumratiodown__96->SetFillStyle(3003);
   sumratiodown__96->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
   sumratiodown__96->GetXaxis()->SetLabelFont(42);
   sumratiodown__96->GetXaxis()->SetLabelOffset(0.007);
   sumratiodown__96->GetXaxis()->SetTitleSize(0.05);
   sumratiodown__96->GetXaxis()->SetTickLength(0.025);
   sumratiodown__96->GetXaxis()->SetTitleFont(42);
   sumratiodown__96->GetYaxis()->SetTitle("a.u./25 GeV");
   sumratiodown__96->GetYaxis()->SetLabelFont(42);
   sumratiodown__96->GetYaxis()->SetLabelOffset(0.007);
   sumratiodown__96->GetYaxis()->SetTitleSize(0.05);
   sumratiodown__96->GetYaxis()->SetTickLength(0.025);
   sumratiodown__96->GetYaxis()->SetTitleFont(42);
   sumratiodown__96->GetZaxis()->SetLabelFont(42);
   sumratiodown__96->GetZaxis()->SetLabelOffset(0.007);
   sumratiodown__96->GetZaxis()->SetTitleSize(0.05);
   sumratiodown__96->GetZaxis()->SetTickLength(0.025);
   sumratiodown__96->GetZaxis()->SetTitleFont(42);
   sumratiodown__96->Draw("hist same");
   
   Double_t Graph0_fx1008[20] = {
   12.5,
   37.5,
   62.5,
   87.5,
   112.5,
   137.5,
   162.5,
   187.5,
   212.5,
   237.5,
   262.5,
   287.5,
   312.5,
   337.5,
   362.5,
   387.5,
   412.5,
   437.5,
   462.5,
   487.5};
   Double_t Graph0_fy1008[20] = {
   0.07305694,
   -0.01425564,
   -0.03554857,
   -0.07793492,
   -0.04831219,
   0.00163126,
   0.02976763,
   -0.04511625,
   0.1249721,
   -0.01111317,
   0.2981665,
   1.078755,
   0.741515,
   -0.3325537,
   -0.6687443,
   1.321965,
   3.197927,
   -999,
   -999,
   0.04291213};
   Double_t Graph0_fex1008[20] = {
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0};
   Double_t Graph0_fey1008[20] = {
   0.01363994,
   0.01187299,
   0.01577891,
   0.02090748,
   0.02936972,
   0.04022648,
   0.05552135,
   0.06945757,
   0.1113888,
   0.1298472,
   0.207873,
   0.415751,
   0.3995309,
   0.2724838,
   0.1912505,
   1.160983,
   2.423674,
   0,
   0,
   1.042912};
   TGraphErrors *gre = new TGraphErrors(20,Graph0_fx1008,Graph0_fy1008,Graph0_fex1008,Graph0_fey1008);
   gre->SetName("Graph0");
   gre->SetTitle("Graph");
   gre->SetFillColor(1);
   gre->SetLineWidth(3);
   
   TH1F *Graph_Graph1008 = new TH1F("Graph_Graph1008","Graph",100,0,535);
   Graph_Graph1008->SetMinimum(-1099.462);
   Graph_Graph1008->SetMaximum(106.0838);
   Graph_Graph1008->SetDirectory(0);
   Graph_Graph1008->SetStats(0);

   ci = TColor::GetColor("#000099");
   Graph_Graph1008->SetLineColor(ci);
   Graph_Graph1008->GetXaxis()->SetLabelFont(42);
   Graph_Graph1008->GetXaxis()->SetLabelOffset(0.007);
   Graph_Graph1008->GetXaxis()->SetTitleSize(0.05);
   Graph_Graph1008->GetXaxis()->SetTickLength(0.025);
   Graph_Graph1008->GetXaxis()->SetTitleFont(42);
   Graph_Graph1008->GetYaxis()->SetLabelFont(42);
   Graph_Graph1008->GetYaxis()->SetLabelOffset(0.007);
   Graph_Graph1008->GetYaxis()->SetTitleSize(0.05);
   Graph_Graph1008->GetYaxis()->SetTickLength(0.025);
   Graph_Graph1008->GetYaxis()->SetTitleFont(42);
   Graph_Graph1008->GetZaxis()->SetLabelFont(42);
   Graph_Graph1008->GetZaxis()->SetLabelOffset(0.007);
   Graph_Graph1008->GetZaxis()->SetTitleSize(0.05);
   Graph_Graph1008->GetZaxis()->SetTickLength(0.025);
   Graph_Graph1008->GetZaxis()->SetTitleFont(42);
   gre->SetHistogram(Graph_Graph1008);
   
   gre->Draw("pe0");
   pad2->Modified();
   c1->cd();
   c1->Modified();
   c1->cd();
   c1->SetSelected(c1);
}
//------------------------------------------------------------------------------
// PlotHiggsRes_LP
//------------------------------------------------------------------------------
void RunMakeRazorPlots ( string signalfile, string signalLabel,  vector<string> bkgfiles,vector<string> bkgLabels, int boxOption = 0, int option = -1, string label = "", string latexlabel = "") {

  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //============================================================================================================== 
  double intLumi = 2100; //in units of pb^-1
  string Label = "";
  if (label != "") Label = "_" + label;

  vector<string> inputfiles;
  vector<string> processLabels;

  bool hasSignal = false;
  if (signalfile != "") {
    hasSignal = true;
    inputfiles.push_back(signalfile);
    processLabels.push_back(signalLabel);
  }
  assert(bkgfiles.size() == bkgLabels.size());
  for (int i=0; i < bkgfiles.size(); ++i) {
     inputfiles.push_back(bkgfiles[i]);
     processLabels.push_back(bkgLabels[i]);
  }

  //*******************************************************************************************
  //Define Histograms
  //*******************************************************************************************
  vector<TH1F*> histUnrolled; 
  float MRBinLowEdges[] = {500, 600, 700, 900, 1200, 1600, 2500, 4000}; // Multijet Bins
  float RsqBinLowEdges[] = {0.25, 0.30, 0.41, 0.52, 0.64, 1.5}; // Multijet Bins

  const int nMRBins = 7;
  const int nRsqBins = 5;

  TH1F* histMRAllBkg =  new TH1F( "MRAllBkg",";M_{R} [GeV/c^{2}];Number of Events", nMRBins, MRBinLowEdges);
  TH1F* histRsqAllBkg =  new TH1F( "RsqAllBkg", ";R^{2};Number of Events", nRsqBins, RsqBinLowEdges);
  histMRAllBkg->SetStats(false);
  histRsqAllBkg->SetStats(false);  
  histRsqAllBkg->Sumw2();
  histMRAllBkg->Sumw2();

  TH1F* histMRQCD =  new TH1F( "MRQCD",";M_{R} [GeV/c^{2}];Number of Events", nMRBins, MRBinLowEdges);
  TH1F* histRsqQCD =  new TH1F( "RsqQCD", ";R^{2};Number of Events", nRsqBins, RsqBinLowEdges);
  histMRQCD->SetStats(false);
  histRsqQCD->SetStats(false);  
  histRsqQCD->Sumw2();
  histMRQCD->Sumw2();

  TH1F* histMRData =  new TH1F( "MRData",";M_{R} [GeV/c^{2}];Number of Events", nMRBins, MRBinLowEdges);
  TH1F* histRsqData =  new TH1F( "RsqData", ";R^{2};Number of Events", nRsqBins, RsqBinLowEdges);

  vector<TH1F*> histMR;
  vector<TH1F*> histRsq; 
  vector<TH2F*> histMRRsq;

  histMRQCD->SetFillColor(kAzure+4);
  histMRAllBkg->SetFillColor(kMagenta);
  histMRQCD->SetFillStyle(1001);
  histMRAllBkg->SetFillStyle(1001);

  histMRQCD->SetLineColor(kAzure+4);
  histMRAllBkg->SetLineColor(kMagenta);

  assert (inputfiles.size() == processLabels.size());
  for (int i=0; i < inputfiles.size(); ++i) {    
    histMRRsq.push_back( new TH2F( Form("MRRsq_%s",processLabels[i].c_str()), ";M_{R} [GeV/c^{2}]; R^{2}", nMRBins, MRBinLowEdges, nRsqBins, RsqBinLowEdges));
    if (!hasSignal || i != 0) histMRRsq[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histMRRsq[i]->SetLineWidth(3);
    histMRRsq[i]->SetLineColor(color[i]);
    histMRRsq[i]->SetStats(false);
    histMRRsq[i]->Sumw2();

    histUnrolled.push_back( new TH1F( Form("Unrolled_%s",processLabels[i].c_str()), ";Bin Number ;Number of Events", nMRBins*nRsqBins, 0, nMRBins*nRsqBins));
    if (!hasSignal || i != 0) histUnrolled[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolled[i]->SetLineWidth(3);
    histUnrolled[i]->SetLineColor(color[i]);
    histUnrolled[i]->SetStats(false);     
  }
  THStack *stackUnrolled = new THStack();

  //*******************************************************************************************
  //Define Counts
  //*******************************************************************************************


  //*******************************************************************************************
  //Read files
  //*******************************************************************************************
  for (uint i=0; i < inputfiles.size(); ++i) {

    TFile* inputFile = new TFile(inputfiles[i].c_str(),"READ");
    assert(inputFile);
    TTree* tree = 0;
    tree = (TTree*)inputFile->Get("RazorInclusive");
  // if (box == 0) {
    //   tree = (TTree*)inputFile->Get("MultiJet");
    // } else if (box == 1) {
    //   tree = (TTree*)inputFile->Get("LooseLeptonMultiJet");
    // } else if (box == 2) {
    //   tree = (TTree*)inputFile->Get("MuMultiJet");
    // } else if (box == 3) {
    //   tree = (TTree*)inputFile->Get("EleMultiJet");
    // }
 
    float weight = 0;
    int box = -1;
    int nBTaggedJets = 0;
    float dPhiRazor = 0;
    float MR = 0;
    float Rsq = 0;
    float mT = 0;

    tree->SetBranchAddress("weight",&weight);
    tree->SetBranchAddress("box",&box);
    tree->SetBranchAddress("nBTaggedJets",&nBTaggedJets);
    tree->SetBranchAddress("dPhiRazor",&dPhiRazor);
    tree->SetBranchAddress("MR",&MR);
    tree->SetBranchAddress("Rsq",&Rsq);
    tree->SetBranchAddress("mT",&mT);

    cout << "Process : " << processLabels[i] << " : Total Events: " << tree->GetEntries() << "\n";
    for (int n=0;n<tree->GetEntries();n++) { 
     // for (int n=0;n<1000;n++) { 
   
      tree->GetEntry(n);
      if (n % 1000000 == 0) cout << "Processing Event " << n << "\n";       


      // if (intLumi*weight > 100) continue;

      //Box Options
      if (option == 0 ) {
	if (nBTaggedJets != 0) continue;
      }
      if (option == 1 ) {
	if (nBTaggedJets != 1) continue;
      }
      if (option == 2 ) {
	if (nBTaggedJets != 2) continue;
      }
      if (option == 3 ) {
	if (nBTaggedJets < 3) continue;
      }
      if (option == 4 ) {
	if (nBTaggedJets < 0) continue; // all b-tag categories combined
      }

      if (boxOption == 0) { // Multijet Box for Jamboree
	if( !(box == 11 || box == 12) ) continue;
      } 
      if (boxOption == 1) { // LeptonJet Box for Jamboree
	if( !(box == 3 || box == 4 || box == 6 || box == 7) ) continue;
      } 
      if (boxOption == 2) { // Multijet Box for Jamboree
	if( !(box == 14) ) continue;
      } 

      //apply baseline cuts
      if (!(MR > 400 && Rsq > 0.25)) continue;

      // if (!(MR < 500 )) continue;
      // if (!(Rsq < 0.3)) continue;

      if (!(fabs(dPhiRazor) > 2.8)) continue;

      if (!hasSignal || i>1) {
	histMRAllBkg->Fill(MR, intLumi*weight);
	histRsqAllBkg->Fill(Rsq, intLumi*weight);
	histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
      }

      if(i==1){
	if (intLumi*weight > 30) continue;
	float qcdweight = 1.56841;
	histMRQCD->Fill(MR, intLumi*weight*qcdweight);
	histRsqQCD->Fill(Rsq, intLumi*weight*qcdweight);	
  	histMRRsq[i]->Fill(MR, Rsq, intLumi*weight*qcdweight);
    }

      if (hasSignal && i==0) {
	histMRData->Fill(MR);
	histRsqData->Fill(Rsq);	
	histMRRsq[i]->Fill(MR, Rsq);
      }
    }

    inputFile->Close();
    delete inputFile;
  
  }
  
  std::cout<<"Data: "<<histMRData->Integral()<<", All Backgrounds: "<<histMRAllBkg->Integral()<<" , QCD: "<<histMRQCD->Integral()<<", Data2 "<< histMRRsq[0]->Integral() <<" QCD2 "<<histMRRsq[1]->Integral() <<std::endl;


  //*******************************************************************************************
  //Draw Plots
  //*******************************************************************************************
 // fill out the unrolled histograms 
  std::cout<<"Rsq bins: "<<nRsqBins<<" "<<nMRBins<<std::endl;
  for (uint i=0; i < histMRRsq.size(); ++i) {
    
    int binN = 0;

    for(int ii = 0; ii<nMRBins; ii++)
      for (int jj = 0; jj<nRsqBins; jj++)      
  	{      
  	  float value = (histMRRsq[i]->GetBinContent(ii+1, jj+1) > 0) ? histMRRsq[i]->GetBinContent(ii+1, jj+1) : 0. ;
	  
	  float Xrange = histMRRsq[i]->GetXaxis()->GetBinLowEdge(jj+2) - histMRRsq[i]->GetXaxis()->GetBinLowEdge(jj+1);
	  float Yrange = histMRRsq[i]->GetYaxis()->GetBinLowEdge(ii+2) - histMRRsq[i]->GetYaxis()->GetBinLowEdge(ii+1);

	  float area =1.;
	  
	  if(density) area = Xrange*Yrange; //normalize each bin by its area

	  histUnrolled[i]->SetBinContent(binN+1, value/area);
  	  binN++;
  	}

    histUnrolled[i]->SetMinimum(0.00001);

    if ( histUnrolled[i]->Integral() > 0) {
      if( !hasSignal || i > 0 )
	stackUnrolled->Add(histUnrolled[i]);
    }

    cout << "Process : " << processLabels[i] << "\n";	  
  }

  TCanvas *cv = 0;
  TLegend *legend = 0;
  TLatex *tex = 0;
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.7,0.53,0.90,0.88);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }

  /// Unrolled plots in bins of R&MR
  TLatex t1(0.1,0.92, "CMS Preliminary");
  TLatex t2(0.6,0.92, "#sqrt{s}=13 TeV, L = 2.1 fb^{-1}");
  TLatex t3(0.4,0.92, Form("%s",latexlabel.c_str()) );
  t1.SetNDC();
  t2.SetNDC();
  t3.SetNDC();
  t1.SetTextSize(0.05);
  t2.SetTextSize(0.05);
  t3.SetTextSize(0.02);
  t1.SetTextFont(42);
  t2.SetTextFont(42);
  t3.SetTextFont(42);
  stackUnrolled->Draw();
  stackUnrolled->SetMinimum(0.01);
  stackUnrolled->SetMaximum(1000);
  cv->SetLogy();
  stackUnrolled->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolled->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackUnrolled->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolled->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackUnrolled->Draw();
  if(hasSignal) histUnrolled[0]->Draw("same PE");
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("Unrolled_QCD%s.root",Label.c_str()));
  ////

  //*******************************************************************************************
  //MR
  //*******************************************************************************************
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSize(0.030);
  tex->SetTextFont(42);
  tex->SetTextColor(kBlack);
  tex->DrawLatex(0.2, 0.92, Form("CMS Simulation #sqrt{s} = 13 TeV, #int L = %d fb^{-1}, %s",int(intLumi/1000), latexlabel.c_str()));

  THStack *stackMR = new THStack("stackMR", "");
  THStack *stackRsq = new THStack();

  //*******************************************************************************************
  //MR Before and After DPhi Cut
  //*******************************************************************************************
  //////////////////
  stackMR->Add(histMRAllBkg);
  stackMR->Add(histMRQCD);
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);
  stackMR->Draw();
  stackMR->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackMR->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackMR->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackMR->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackMR->Draw("");
  histMRData->Draw("same PE");
  legend->Draw();
  cv->SetLogy();
  cv->SaveAs(Form("MRStack_QCD_%s.pdf",Label.c_str()));

  ///////////////////////
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  histMRAllBkg->SetLineColor(kRed);
  histMRAllBkg->GetYaxis()->SetTitle("Number of Events");
  histMRAllBkg->GetYaxis()->SetTitleOffset(1.2);
  histMRData->SetMarkerStyle(8);

  legend->AddEntry(histMRAllBkg, "All Backgrounds", "L");
  legend->AddEntry(histMRData, "Data", "L");

  histMRAllBkg->Add(histMRQCD, 1.0);

  histMRAllBkg->Draw("hist");
  histMRData->Draw("PE same");

  legend->Draw();
  cv->SetLogy();
  cv->SaveAs(Form("MR_QCD_%s.pdf",Label.c_str()));


  //////

  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  histRsqAllBkg->SetLineColor(kRed);
  histRsqAllBkg->GetYaxis()->SetTitle("Number of Events");
  histRsqAllBkg->GetYaxis()->SetTitleOffset(1.2);
  histRsqData->SetMarkerStyle(8);

  legend->AddEntry(histRsqAllBkg, "All Backgrounds", "L");
  legend->AddEntry(histRsqData, "Data", "L");

  histRsqAllBkg->Add(histRsqQCD, 1.0);

  histRsqAllBkg->Draw("hist");
  histRsqData->Draw("PE same");

  legend->Draw();
  cv->SetLogy();
  cv->SaveAs(Form("Rsq_QCD_%s.pdf",Label.c_str()));

  //////////////////
  histRsqQCD->SetFillColor(kAzure+4);
  histRsqAllBkg->SetFillColor(kMagenta);

  stackRsq->Add(histRsqAllBkg);
  stackRsq->Add(histRsqQCD);
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);
  stackRsq->Draw();
  stackRsq->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackRsq->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackRsq->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackRsq->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackRsq->Draw();
  histRsqData->Draw("same PE");
  legend->Draw();
  cv->SetLogy();
  cv->SaveAs(Form("RsqStack_QCD_%s.pdf",Label.c_str()));
 
   //--------------------------------------------------------------------------------------------------------------
  // Output
  //==============================================================================================================
  TFile *file = TFile::Open(("RazorPlots"+Label+".root").c_str(), "RECREATE");
  file->cd();

  for(int i=0; i<int(inputfiles.size()); i++) {
    file->WriteTObject(histMRRsq[i], Form("histMRRsq_%s",processLabels[i].c_str()), "WriteDelete");
    histUnrolled[i]->Write();  
  }
  
  stackUnrolled->Write();
 }
Exemple #25
0
void makeStack(TString myVar, TString myCut, TString myName, TString myAxisNameX, TString myAxisNameY, 
               vector<const Sample*>& listOfSignals, vector<const Sample*>& listOfSamples, vector<const Sample*> listOfDatasets, 
               TString inFileName,
               bool isBlind, bool isLog, bool drawSignal, bool drawLegend,
               int nBins, float xLow, float xHigh,
               float* xlowVec)
{
  // prepare the input file
  TFile* infile = new TFile(inFileName, "READ"); 
  infile -> cd();
  
  // prepare the stack
  THStack *hs = new THStack("hs","");
  // prepare the histos pointers
  TH1F*   hist[20];
  // prepare the tree pointers
  TTree*  tree[20];
  // prepare the legend
  TLegend* leg = new TLegend(.7485,.7225,.9597,.9604);
  leg->SetFillColor(0);
  // prepare the colors
  Int_t col[20] = {46,2,12,5,3,4,9,7,47,49,49,50,51,52,53,54,55,56,57,58};
  // prepare the cut
  if (isBlind) myCut += "*(phoMetDeltaPhi < 2.9)";        
  // prepare the Y axis lable
  if (xlowVec != 0) myAxisNameY = "Events/" + myAxisNameY;
  else {
    float binWidth = (xHigh-xLow)/nBins;
    TString tempString;
    tempString.Form("%.2f ",binWidth); 
    myAxisNameY = "Events/" + tempString + myAxisNameY;
  }
  // prepare the legend strings
  vector<TString> theLegends;
  
  // loop through the datasets and produce the plots
  TH1F* hdata;
  TH1F* hsignal;
  //prepare data and signal histos
  if (xlowVec != 0) hdata   = new TH1F("hdata","",nBins,xlowVec);
  else hdata = new TH1F("hdata","",nBins,xLow,xHigh);
  if (xlowVec != 0) hsignal = new TH1F("hsignal","",nBins,xlowVec);
  else hsignal = new TH1F("hsignal","",nBins,xLow,xHigh);

  TTree*  treedata[20];
  for (UInt_t iDatas=0; iDatas < listOfDatasets.size(); iDatas++) {
    //get the tree
    treedata[iDatas] = (TTree*) infile -> Get(listOfDatasets.at(iDatas)->Name()->Data());

    //fill the histogram
    if ( iDatas == 0 ) treedata[iDatas] -> Draw(myVar + " >> hdata","evt_weight*kf_weight*pu_weight" + myCut);
    else treedata[iDatas] -> Draw(myVar + " >>+ hdata","evt_weight*kf_weight*pu_weight" + myCut);
    
    if ( isBlind && iDatas == 0 ) leg -> AddEntry(hdata, "DATA (19.8 fb^{-1})", "pl");    
    
  }//end loop on datasets
  if (xlowVec != 0) {
    for (int iBin = 1; iBin <= nBins; iBin++) hdata->SetBinError  (iBin,hdata->GetBinError(iBin)/hdata->GetBinWidth(iBin));
    for (int iBin = 1; iBin <= nBins; iBin++) hdata->SetBinContent(iBin,hdata->GetBinContent(iBin)/hdata->GetBinWidth(iBin));
  }

  TTree*  treesignal[20];
  for (UInt_t iSignal=0; iSignal < listOfSignals.size(); iSignal++) {
    //get the tree
    treesignal[iSignal] = (TTree*) infile -> Get(listOfSignals.at(iSignal)->Name()->Data());

    //fill the histogram
    TString thisScale = Form("%f *", *(listOfSignals.at(iSignal)->Scale()));
    if ( iSignal == 0 ) treesignal[iSignal] -> Draw(myVar + " >> hsignal",thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    else treesignal[iSignal] -> Draw(myVar + " >>+ hsignal",thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    
    if ( drawSignal && iSignal == 0 ) leg -> AddEntry(hsignal, "Signal", "l");    
    
  }//end loop on signals
  if (xlowVec != 0) {
    for (int iBin = 1; iBin <= nBins; iBin++) hsignal->SetBinError  (iBin,hsignal->GetBinError(iBin)/hsignal->GetBinWidth(iBin));
    for (int iBin = 1; iBin <= nBins; iBin++) hsignal->SetBinContent(iBin,hsignal->GetBinContent(iBin)/hsignal->GetBinWidth(iBin));
  }
  hsignal -> SetLineColor(49);
  hsignal -> SetLineWidth(4.0);
       
  int theHistCounter = 0;
  // loop through the samples and produce the plots
  for (UInt_t iSample=0; iSample < listOfSamples.size(); iSample++) {

    //determine if the histo is first of the series
    bool isFirstOfSerie = (*listOfSamples.at(iSample)->Legend()).CompareTo(" ");
    bool isLastOfSerie = false;
    if (iSample == listOfSamples.size() - 1) isLastOfSerie = true;
    if (iSample < listOfSamples.size() - 1 && (*listOfSamples.at(iSample+1)->Legend()).CompareTo(" ") != 0) isLastOfSerie = true;
    
    //get the tree
    tree[iSample] = (TTree*) infile -> Get(listOfSamples.at(iSample)->Name()->Data());
    //if sample first of the list create a new histogram
    if (isFirstOfSerie) {
       TString thisHistName = "h_" + *(listOfSamples.at(iSample)->Name());
       //variable bin histo
       if (xlowVec != 0) hist[theHistCounter] = new TH1F(thisHistName,thisHistName,nBins,xlowVec);
       //fixed bin histo
       else hist[theHistCounter] = new TH1F(thisHistName,thisHistName,nBins,xLow,xHigh);
       hist[theHistCounter] -> Sumw2();
       hist[theHistCounter] -> SetFillColor(col[theHistCounter]);
       hist[theHistCounter] -> SetFillStyle(1001);
       theLegends.push_back(*listOfSamples.at(iSample)->Legend());
    }

    //fill the histogram
    TString thisScale = Form("%f *", *(listOfSamples.at(iSample)->Scale()));
    if (isFirstOfSerie) tree[iSample] -> Draw(myVar + " >> " + TString(hist[theHistCounter] -> GetName()),thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    else tree[iSample] -> Draw(myVar + " >>+ " + TString(hist[theHistCounter] -> GetName()),thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    
    //add the histogram to the stack if the last of the series:
    //either last sample or ~ sample followed by non ~ sample
    if (isLastOfSerie) {
       if (xlowVec != 0) {
         for (int iBin = 1; iBin <= nBins; iBin++) hist[theHistCounter]->SetBinError  (iBin,hist[theHistCounter]->GetBinError(iBin)/hist[theHistCounter]->GetBinWidth(iBin));
         for (int iBin = 1; iBin <= nBins; iBin++) hist[theHistCounter]->SetBinContent(iBin,hist[theHistCounter]->GetBinContent(iBin)/hist[theHistCounter]->GetBinWidth(iBin));
       }
       hs -> Add(hist[theHistCounter]);
       theHistCounter++;
    }
    
  }//end loop on samples

  //Fix the legend
  for (int iHisto = theHistCounter-1; iHisto >= 0; iHisto--) {
    leg -> AddEntry(hist[iHisto], theLegends[iHisto], "f");   
  }
  
  //get the maximum to properly set the frame
  float theMax = hdata -> GetBinContent(hdata -> GetMaximumBin()) + hdata -> GetBinError(hdata -> GetMaximumBin());
  TH1* theMCSum = (TH1*) hs->GetStack()->Last();
  float theMaxMC = theMCSum->GetBinContent(theMCSum->GetMaximumBin()) + theMCSum->GetBinError(theMCSum->GetMaximumBin());
  if (theMaxMC > theMax) theMax = theMaxMC;
  
  //prepare the ratio band and plot
  TH1* theMCRatioBand = makeRatioBand(theMCSum);
  TH1* theRatioPlot = makeRatioPlot(hdata,theMCSum);
    
  TCanvas* can = new TCanvas();
  can -> SetLogy(isLog);
  
  TPad *pad1 = new TPad("pad1","top pad",0,0.30,1,1);
  pad1->SetBottomMargin(0.02);
  pad1->SetLeftMargin(0.13);
  pad1->Draw();
  TPad *pad2 = new TPad("pad2","bottom pad",0,0.0,1,0.30);
  pad2->SetTopMargin(0.02);
  pad2->SetLeftMargin(0.13);
  pad2->SetBottomMargin(0.4);
  pad2->SetGridy();
  pad2->Draw();
  
  pad1->cd();
  hs->Draw("hist");
  hdata->Draw("same,pe");
  if (drawSignal) hsignal->Draw("same,hist");
  if (drawLegend) leg->Draw("same");
  //hs->GetXaxis()->SetTitle(myAxisNameX);
  hs->GetYaxis()->SetTitle(myAxisNameY);
  hs->GetXaxis()->SetLabelSize(0.04);
  hs->GetYaxis()->SetLabelSize(0.04);
  hs->GetXaxis()->SetLabelOffset(0.025);
  hs->GetYaxis()->SetLabelOffset(0.035);
  //hs->GetXaxis()->SetTitleOffset(1.1);
  hs->GetYaxis()->SetTitleOffset(1.1);
  hs->SetMaximum(theMax);
  if (isLog) hs->SetMinimum(0.01);
  
  pad2->cd();
  theMCRatioBand->GetXaxis()->SetTitle(myAxisNameX);
  theMCRatioBand->GetXaxis()->SetTitleSize(0.16);
  theMCRatioBand->GetXaxis()->SetTitleOffset(1.1);
  theMCRatioBand->GetXaxis()->SetLabelSize(0.12);
  theMCRatioBand->GetXaxis()->SetLabelOffset(0.07);
  theMCRatioBand->GetYaxis()->SetTitle("Data/MC");
  theMCRatioBand->GetYaxis()->SetTitleSize(0.10);
  theMCRatioBand->GetYaxis()->SetTitleOffset(0.6);
  theMCRatioBand->GetYaxis()->SetLabelSize(0.06);
  theMCRatioBand->GetYaxis()->SetLabelOffset(0.03);
  theMCRatioBand->SetFillStyle(3001);
  theMCRatioBand->SetFillColor(kBlue);
  theMCRatioBand->SetLineWidth(1);
  theMCRatioBand->SetLineColor(kBlack);
  theMCRatioBand->SetMarkerSize(0.1);
  theMCRatioBand->SetMaximum(4.);
  theMCRatioBand->SetMinimum(0.);
  theMCRatioBand->Draw("E2");
  TLine *line = new TLine(xLow,1,xHigh,1);
  line->SetLineColor(kBlack);
  line->Draw("same");
  theRatioPlot->Draw("same,pe");
  
  can->cd();
  can->Modified();
  can -> SaveAs(myName + ".pdf","pdf");
  
  //cleanup the memory allocation
  delete theMCSum;
  delete hs;
  delete leg;
  delete hdata;
  delete pad1;
  delete pad2;
  delete can;
  delete theMCRatioBand;
  delete theRatioPlot;
  infile -> Close();
  delete infile;
  
  return;
}
void Draw(TString name, TString histotitle, bool log, int move_legend)

{

 
 TH1F* hist_b;
 TH1F* hist_c;
 TH1F* hist_gsplit;
 TH1F* hist_l;
 TH1F* hist_data;
 
 
 TFile *myFile     = new TFile(filename);
 
 myFile->cd();
 hist_b         = (TH1F*)gROOT->FindObject(name+"_b");
 hist_c         = (TH1F*)gROOT->FindObject(name+"_c");
 hist_gsplit    = (TH1F*)gROOT->FindObject(name+"_bfromg");
 hist_l         = (TH1F*)gROOT->FindObject(name+"_l");
 hist_data      = (TH1F*)gROOT->FindObject(name+"_data");
 

 if (bOverflow && name!="SSV" && name!="SSVHP") {
  OverFlowBinFix(hist_b);
  OverFlowBinFix(hist_c);
  OverFlowBinFix(hist_gsplit);
  OverFlowBinFix(hist_l);
  OverFlowBinFix(hist_data);
 }



 TH1F* histo_tot = (TH1F*) hist_b->Clone();
 histo_tot->Sumw2();
 histo_tot ->Add(hist_c);
 histo_tot ->Add(hist_gsplit);
 histo_tot ->Add(hist_l);  

 

 float scale_f = (hist_data->Integral())/(hist_b->Integral() + hist_c ->Integral()+ hist_gsplit->Integral() + hist_l->Integral());

 hist_b       ->Scale(scale_f);
 hist_c       ->Scale(scale_f);
 hist_gsplit  ->Scale(scale_f);
 hist_l       ->Scale(scale_f);
 histo_tot    ->Scale(scale_f);
  
 double titleoffsety=0.2;
 double titlesizex=0.17;
 double titlesizey=0.2;
 double labelsizex=0.14;
 double labelsizey=0.12; 
  
   
 hist_data  ->GetYaxis()->SetLabelSize(labelsizey);
 hist_data  ->GetYaxis()->SetTitleSize(titlesizey);
 hist_data  ->GetYaxis()->SetTitleOffset(titleoffsety);
  
 hist_b     ->GetYaxis()->SetLabelSize(labelsizey);
 hist_b     ->GetYaxis()->SetTitleSize(titlesizey);
 hist_b     ->GetYaxis()->SetTitleOffset(titleoffsety);
  
 TH1F* histo_ratio;
 histo_ratio = (TH1F*) hist_data->Clone();
 histo_ratio->SetName("histo_ratio");
 histo_ratio->SetTitle("");
  
 histo_ratio->Divide(histo_tot);
  
 hist_data  ->SetLineWidth(2);
 hist_data  ->SetMarkerStyle(20);  
 hist_data  ->SetMarkerSize(0.75); 

 hist_c     ->SetFillColor(8);
 hist_b     ->SetFillColor(2);
 hist_gsplit->SetFillColor(7);
 hist_l     ->SetFillColor(4);
  
 histo_tot  ->SetLineColor(2);
  

 THStack *stack = new THStack("stack","stack");
  
 if (b_ordering){
  stack      ->Add(hist_b);
  stack      ->Add(hist_gsplit);
  stack      ->Add(hist_c);
  stack      ->Add(hist_l);
 }
 else {
  stack      ->Add(hist_l);
  stack      ->Add(hist_c);
  stack      ->Add(hist_gsplit);
  stack      ->Add(hist_b);
 }


 gStyle->SetOptTitle(0);
 gStyle->SetOptStat(0);  
 //gStyle->SetLogy(log);
  
 TCanvas *c1 = new TCanvas("c1", "c1",10,32,782,552);
 c1->SetFillColor(10);
 c1->  cd();   
  

 TPad* canvas_1 = new TPad("canvas_1", "canvas_1",0,0.25,1.0,0.98);
 canvas_1 ->Draw();
 canvas_1 ->cd();
 
 canvas_1->SetLogy(log);
 
 if (hist_data->GetMaximum() > stack->GetMaximum() ) stack->SetMaximum( hist_data->GetMaximum()*1.1) ;

 float xmov=1;
 if (move_legend==2) {
    if (log)  xmov=5;
    else xmov=1.1;
    stack->SetMaximum( xmov*stack->GetMaximum() ) ;
 }
 
 if (stack->GetMinimum()> hist_l->GetMinimum()) {
   if (log && hist_l->GetMinimum()>0.) stack->SetMinimum(hist_l->GetMinimum());
   else if (!log) stack->SetMinimum(hist_l->GetMinimum());
 }

 stack    ->Draw("hist");  
  
 stack    ->GetHistogram()->GetXaxis()->SetTitle(name);
 stack    ->GetHistogram()->GetYaxis()->SetTitle("entries");

 stack    ->GetHistogram()->SetTitleSize(0.08,"Y");
 stack    ->GetHistogram()->SetTitleOffset(0.65,"Y"); 

 hist_data->Draw("same e");

// TLegend* qw =  new TLegend(0.54,0.63,0.88,0.9);
 TLegend* qw;
 if (move_legend==1) {
   qw =  new TLegend(0.35,0.15,0.70,0.42);
 }
 else if (move_legend==3) {
  qw =  new TLegend(0.35,0.63,0.70,0.90);
 }
 else qw =  new TLegend(0.6,0.73,0.95,1.);
  
  //Legend
 qw->AddEntry(hist_data,     "e#mu ttbar data",                       "p");
 qw->AddEntry(hist_b,        "b quark"           ,         "f");
 qw->AddEntry(hist_gsplit,   "b from gluon splitting"     ,"f");
 qw->AddEntry(hist_c,        "c quark"           ,         "f");
 qw->AddEntry(hist_l,        "uds quark or gluon"     ,    "f");

 
 qw->SetFillColor(0);
 qw->Draw();
  
  
 TLatex *latex = new TLatex();
 latex->SetNDC();
 latex->SetTextSize(0.055);
 latex->SetTextFont(42); //22

 latex->SetTextAlign(13);
 latex->DrawLatex(0.08, 0.96, title);


 c1->cd();  
  
 TPad* canvas_2 = new TPad("canvas_2", "canvas_2",0,0.,1.0,0.32);
 canvas_2->Draw();
 canvas_2->cd();
 gPad->SetBottomMargin(0.375);
 gPad->SetGridy();
  
 histo_ratio->SetMarkerStyle(20);
 histo_ratio->SetMarkerSize(0.75);
 histo_ratio->SetLineWidth(2);
 
 histo_ratio->GetYaxis()->SetTitle("Data/MC");
 histo_ratio->GetXaxis()->SetTitle(histotitle);
 histo_ratio->GetYaxis()->SetNdivisions( 505 );

 histo_ratio->GetXaxis()->SetLabelSize( labelsizex);
 histo_ratio->GetXaxis()->SetTitleSize( titlesizex );

 histo_ratio->SetMinimum(0.4);
 histo_ratio->SetMaximum(1.6);
 histo_ratio->Draw("E1X0");

 c1->cd();  
  
 TString name_plot=name+"_Linear"+format; 
 if(log) name_plot=name+"_Log"+format;
 c1->SaveAs("Commissioning_plots/"+name_plot);

 if (log && web) {  // save also _Linear for web
 canvas_1 ->cd();
 canvas_1->SetLogy(false);
 if (xmov==5) {
    stack->SetMaximum( 1.1*stack->GetMaximum() ) ;
 }
 c1->cd();  
 c1->SaveAs("Commissioning_plots/"+name+"_Linear"+format);
   
 }

}
Exemple #27
0
void ttbar_isojet1CSV()
{
//=========Macro generated from canvas: c1/c1
//=========  (Sun Dec 11 15:16:19 2016) by ROOT version6.06/01
   TCanvas *c1 = new TCanvas("c1", "c1",1,1,1200,1416);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   c1->SetHighLightColor(2);
   c1->Range(0,0,1,1);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   c1->SetTickx(1);
   c1->SetTicky(1);
   c1->SetLeftMargin(0.15);
   c1->SetRightMargin(0.05);
   c1->SetTopMargin(0.07);
   c1->SetBottomMargin(0.13);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
  
// ------------>Primitives in pad: pad1
   TPad *pad1 = new TPad("pad1", "pad1",0,0.3,1,1);
   pad1->Draw();
   pad1->cd();
   pad1->Range(-0.1875,0,1.0625,0.6289089);
   pad1->SetFillColor(0);
   pad1->SetBorderMode(0);
   pad1->SetBorderSize(2);
   pad1->SetTickx(1);
   pad1->SetTicky(1);
   pad1->SetLeftMargin(0.15);
   pad1->SetRightMargin(0.05);
   pad1->SetTopMargin(0.07);
   pad1->SetBottomMargin(0);
   pad1->SetFrameFillStyle(0);
   pad1->SetFrameBorderMode(0);
   pad1->SetFrameFillStyle(0);
   pad1->SetFrameBorderMode(0);
   
   THStack *h = new THStack();
   h->SetName("h");
   h->SetTitle("");
   h->SetMinimum(0);
   h->SetMaximum(0.5570336);
   
   TH1F *h_stack_23 = new TH1F("h_stack_23","",10,0,1);
   h_stack_23->SetMinimum(0);
   h_stack_23->SetMaximum(0.5848853);
   h_stack_23->SetDirectory(0);
   h_stack_23->SetStats(0);

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha
   ci = TColor::GetColor("#000099");
   h_stack_23->SetLineColor(ci);
   h_stack_23->GetXaxis()->SetLabelFont(42);
   h_stack_23->GetXaxis()->SetLabelOffset(0.007);
   h_stack_23->GetXaxis()->SetTitleSize(0.05);
   h_stack_23->GetXaxis()->SetTickLength(0.025);
   h_stack_23->GetXaxis()->SetTitleFont(42);
   h_stack_23->GetYaxis()->SetTitle("a.u.");
   h_stack_23->GetYaxis()->SetLabelFont(42);
   h_stack_23->GetYaxis()->SetLabelOffset(0.007);
   h_stack_23->GetYaxis()->SetTitleSize(0.05);
   h_stack_23->GetYaxis()->SetTickLength(0.025);
   h_stack_23->GetYaxis()->SetTitleOffset(1.5);
   h_stack_23->GetYaxis()->SetTitleFont(42);
   h_stack_23->GetZaxis()->SetLabelFont(42);
   h_stack_23->GetZaxis()->SetLabelOffset(0.007);
   h_stack_23->GetZaxis()->SetTitleSize(0.05);
   h_stack_23->GetZaxis()->SetTickLength(0.025);
   h_stack_23->GetZaxis()->SetTitleFont(42);
   h->SetHistogram(h_stack_23);
   
   
   TH1D *h_isojet1CSV_QCD__265 = new TH1D("h_isojet1CSV_QCD__265","",10,0,1);
   h_isojet1CSV_QCD__265->SetBinContent(1,0.002129117);
   h_isojet1CSV_QCD__265->SetBinContent(2,0.001248327);
   h_isojet1CSV_QCD__265->SetBinContent(3,0.0006205357);
   h_isojet1CSV_QCD__265->SetBinContent(4,0.001430306);
   h_isojet1CSV_QCD__265->SetBinContent(5,0.001031553);
   h_isojet1CSV_QCD__265->SetBinContent(6,0.0005098467);
   h_isojet1CSV_QCD__265->SetBinContent(7,0.0002095089);
   h_isojet1CSV_QCD__265->SetBinContent(8,9.216642e-05);
   h_isojet1CSV_QCD__265->SetBinContent(10,0.004314199);
   h_isojet1CSV_QCD__265->SetBinError(1,0.001510477);
   h_isojet1CSV_QCD__265->SetBinError(2,0.0006911766);
   h_isojet1CSV_QCD__265->SetBinError(3,0.0004578373);
   h_isojet1CSV_QCD__265->SetBinError(4,0.0008388365);
   h_isojet1CSV_QCD__265->SetBinError(5,0.0008715622);
   h_isojet1CSV_QCD__265->SetBinError(6,0.0005098467);
   h_isojet1CSV_QCD__265->SetBinError(7,0.0002095089);
   h_isojet1CSV_QCD__265->SetBinError(8,9.216642e-05);
   h_isojet1CSV_QCD__265->SetBinError(10,0.002213733);
   h_isojet1CSV_QCD__265->SetEntries(25);
   h_isojet1CSV_QCD__265->SetStats(0);

   ci = TColor::GetColor("#cccccc");
   h_isojet1CSV_QCD__265->SetFillColor(ci);
   h_isojet1CSV_QCD__265->GetXaxis()->SetTitle("isojet 1 CSV");
   h_isojet1CSV_QCD__265->GetXaxis()->SetLabelFont(42);
   h_isojet1CSV_QCD__265->GetXaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_QCD__265->GetXaxis()->SetTitleSize(0.05);
   h_isojet1CSV_QCD__265->GetXaxis()->SetTickLength(0.025);
   h_isojet1CSV_QCD__265->GetXaxis()->SetTitleFont(42);
   h_isojet1CSV_QCD__265->GetYaxis()->SetTitle("a.u.");
   h_isojet1CSV_QCD__265->GetYaxis()->SetLabelFont(42);
   h_isojet1CSV_QCD__265->GetYaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_QCD__265->GetYaxis()->SetTitleSize(0.05);
   h_isojet1CSV_QCD__265->GetYaxis()->SetTickLength(0.025);
   h_isojet1CSV_QCD__265->GetYaxis()->SetTitleFont(42);
   h_isojet1CSV_QCD__265->GetZaxis()->SetLabelFont(42);
   h_isojet1CSV_QCD__265->GetZaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_QCD__265->GetZaxis()->SetTitleSize(0.05);
   h_isojet1CSV_QCD__265->GetZaxis()->SetTickLength(0.025);
   h_isojet1CSV_QCD__265->GetZaxis()->SetTitleFont(42);
   h->Add(h_isojet1CSV_QCD,"");
   
   TH1D *h_isojet1CSV_Diboson__266 = new TH1D("h_isojet1CSV_Diboson__266","",10,0,1);
   h_isojet1CSV_Diboson__266->SetBinContent(1,0.006910874);
   h_isojet1CSV_Diboson__266->SetBinContent(2,0.01156259);
   h_isojet1CSV_Diboson__266->SetBinContent(3,0.00597142);
   h_isojet1CSV_Diboson__266->SetBinContent(4,0.003397186);
   h_isojet1CSV_Diboson__266->SetBinContent(5,0.003453268);
   h_isojet1CSV_Diboson__266->SetBinContent(6,0.001659304);
   h_isojet1CSV_Diboson__266->SetBinContent(7,0.001617052);
   h_isojet1CSV_Diboson__266->SetBinContent(8,0.001259235);
   h_isojet1CSV_Diboson__266->SetBinContent(9,0.000286628);
   h_isojet1CSV_Diboson__266->SetBinContent(10,0.00067562);
   h_isojet1CSV_Diboson__266->SetBinError(1,0.001086007);
   h_isojet1CSV_Diboson__266->SetBinError(2,0.001467728);
   h_isojet1CSV_Diboson__266->SetBinError(3,0.001077108);
   h_isojet1CSV_Diboson__266->SetBinError(4,0.0008370875);
   h_isojet1CSV_Diboson__266->SetBinError(5,0.0009085276);
   h_isojet1CSV_Diboson__266->SetBinError(6,0.000631351);
   h_isojet1CSV_Diboson__266->SetBinError(7,0.0006254813);
   h_isojet1CSV_Diboson__266->SetBinError(8,0.0005614698);
   h_isojet1CSV_Diboson__266->SetBinError(9,0.0001726014);
   h_isojet1CSV_Diboson__266->SetBinError(10,0.0003333104);
   h_isojet1CSV_Diboson__266->SetEntries(227);
   h_isojet1CSV_Diboson__266->SetStats(0);

   ci = TColor::GetColor("#9966cc");
   h_isojet1CSV_Diboson__266->SetFillColor(ci);
   h_isojet1CSV_Diboson__266->GetXaxis()->SetTitle("isojet 1 CSV");
   h_isojet1CSV_Diboson__266->GetXaxis()->SetLabelFont(42);
   h_isojet1CSV_Diboson__266->GetXaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_Diboson__266->GetXaxis()->SetTitleSize(0.05);
   h_isojet1CSV_Diboson__266->GetXaxis()->SetTickLength(0.025);
   h_isojet1CSV_Diboson__266->GetXaxis()->SetTitleFont(42);
   h_isojet1CSV_Diboson__266->GetYaxis()->SetTitle("a.u.");
   h_isojet1CSV_Diboson__266->GetYaxis()->SetLabelFont(42);
   h_isojet1CSV_Diboson__266->GetYaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_Diboson__266->GetYaxis()->SetTitleSize(0.05);
   h_isojet1CSV_Diboson__266->GetYaxis()->SetTickLength(0.025);
   h_isojet1CSV_Diboson__266->GetYaxis()->SetTitleFont(42);
   h_isojet1CSV_Diboson__266->GetZaxis()->SetLabelFont(42);
   h_isojet1CSV_Diboson__266->GetZaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_Diboson__266->GetZaxis()->SetTitleSize(0.05);
   h_isojet1CSV_Diboson__266->GetZaxis()->SetTickLength(0.025);
   h_isojet1CSV_Diboson__266->GetZaxis()->SetTitleFont(42);
   h->Add(h_isojet1CSV_Diboson,"");
   
   TH1D *h_isojet1CSV_ZpLjets__267 = new TH1D("h_isojet1CSV_ZpLjets__267","",10,0,1);
   h_isojet1CSV_ZpLjets__267->SetBinContent(1,0.00997839);
   h_isojet1CSV_ZpLjets__267->SetBinContent(2,0.01450317);
   h_isojet1CSV_ZpLjets__267->SetBinContent(3,0.006432142);
   h_isojet1CSV_ZpLjets__267->SetBinContent(4,0.004194575);
   h_isojet1CSV_ZpLjets__267->SetBinContent(5,0.003727646);
   h_isojet1CSV_ZpLjets__267->SetBinContent(6,0.002569373);
   h_isojet1CSV_ZpLjets__267->SetBinContent(7,0.001898935);
   h_isojet1CSV_ZpLjets__267->SetBinContent(8,0.001314676);
   h_isojet1CSV_ZpLjets__267->SetBinContent(9,0.001323422);
   h_isojet1CSV_ZpLjets__267->SetBinContent(10,0.001471477);
   h_isojet1CSV_ZpLjets__267->SetBinError(1,0.0002843835);
   h_isojet1CSV_ZpLjets__267->SetBinError(2,0.0003526741);
   h_isojet1CSV_ZpLjets__267->SetBinError(3,0.0002379666);
   h_isojet1CSV_ZpLjets__267->SetBinError(4,0.0002075278);
   h_isojet1CSV_ZpLjets__267->SetBinError(5,0.0001971644);
   h_isojet1CSV_ZpLjets__267->SetBinError(6,0.0001564817);
   h_isojet1CSV_ZpLjets__267->SetBinError(7,0.0001321731);
   h_isojet1CSV_ZpLjets__267->SetBinError(8,0.0001133749);
   h_isojet1CSV_ZpLjets__267->SetBinError(9,0.0001162263);
   h_isojet1CSV_ZpLjets__267->SetBinError(10,0.0001379738);
   h_isojet1CSV_ZpLjets__267->SetEntries(24915);
   h_isojet1CSV_ZpLjets__267->SetStats(0);

   ci = TColor::GetColor("#3399cc");
   h_isojet1CSV_ZpLjets__267->SetFillColor(ci);
   h_isojet1CSV_ZpLjets__267->GetXaxis()->SetTitle("isojet 1 CSV");
   h_isojet1CSV_ZpLjets__267->GetXaxis()->SetLabelFont(42);
   h_isojet1CSV_ZpLjets__267->GetXaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_ZpLjets__267->GetXaxis()->SetTitleSize(0.05);
   h_isojet1CSV_ZpLjets__267->GetXaxis()->SetTickLength(0.025);
   h_isojet1CSV_ZpLjets__267->GetXaxis()->SetTitleFont(42);
   h_isojet1CSV_ZpLjets__267->GetYaxis()->SetTitle("a.u.");
   h_isojet1CSV_ZpLjets__267->GetYaxis()->SetLabelFont(42);
   h_isojet1CSV_ZpLjets__267->GetYaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_ZpLjets__267->GetYaxis()->SetTitleSize(0.05);
   h_isojet1CSV_ZpLjets__267->GetYaxis()->SetTickLength(0.025);
   h_isojet1CSV_ZpLjets__267->GetYaxis()->SetTitleFont(42);
   h_isojet1CSV_ZpLjets__267->GetZaxis()->SetLabelFont(42);
   h_isojet1CSV_ZpLjets__267->GetZaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_ZpLjets__267->GetZaxis()->SetTitleSize(0.05);
   h_isojet1CSV_ZpLjets__267->GetZaxis()->SetTickLength(0.025);
   h_isojet1CSV_ZpLjets__267->GetZaxis()->SetTitleFont(42);
   h->Add(h_isojet1CSV_Z+jets,"");
   
   TH1D *h_isojet1CSV_WpLjets__268 = new TH1D("h_isojet1CSV_WpLjets__268","",10,0,1);
   h_isojet1CSV_WpLjets__268->SetBinContent(1,0.01060448);
   h_isojet1CSV_WpLjets__268->SetBinContent(2,0.01194981);
   h_isojet1CSV_WpLjets__268->SetBinContent(3,0.007295854);
   h_isojet1CSV_WpLjets__268->SetBinContent(4,0.004201536);
   h_isojet1CSV_WpLjets__268->SetBinContent(5,0.003315037);
   h_isojet1CSV_WpLjets__268->SetBinContent(6,0.002154035);
   h_isojet1CSV_WpLjets__268->SetBinContent(7,0.001704806);
   h_isojet1CSV_WpLjets__268->SetBinContent(8,0.001590696);
   h_isojet1CSV_WpLjets__268->SetBinContent(9,0.001506952);
   h_isojet1CSV_WpLjets__268->SetBinContent(10,0.00135957);
   h_isojet1CSV_WpLjets__268->SetBinError(1,0.0007760229);
   h_isojet1CSV_WpLjets__268->SetBinError(2,0.0008063374);
   h_isojet1CSV_WpLjets__268->SetBinError(3,0.0006567409);
   h_isojet1CSV_WpLjets__268->SetBinError(4,0.0005519722);
   h_isojet1CSV_WpLjets__268->SetBinError(5,0.0004860992);
   h_isojet1CSV_WpLjets__268->SetBinError(6,0.0003673486);
   h_isojet1CSV_WpLjets__268->SetBinError(7,0.0003806515);
   h_isojet1CSV_WpLjets__268->SetBinError(8,0.0003677212);
   h_isojet1CSV_WpLjets__268->SetBinError(9,0.0003252218);
   h_isojet1CSV_WpLjets__268->SetBinError(10,0.0002763251);
   h_isojet1CSV_WpLjets__268->SetEntries(3309);
   h_isojet1CSV_WpLjets__268->SetStats(0);

   ci = TColor::GetColor("#66cc66");
   h_isojet1CSV_WpLjets__268->SetFillColor(ci);
   h_isojet1CSV_WpLjets__268->GetXaxis()->SetTitle("isojet 1 CSV");
   h_isojet1CSV_WpLjets__268->GetXaxis()->SetLabelFont(42);
   h_isojet1CSV_WpLjets__268->GetXaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_WpLjets__268->GetXaxis()->SetTitleSize(0.05);
   h_isojet1CSV_WpLjets__268->GetXaxis()->SetTickLength(0.025);
   h_isojet1CSV_WpLjets__268->GetXaxis()->SetTitleFont(42);
   h_isojet1CSV_WpLjets__268->GetYaxis()->SetTitle("a.u.");
   h_isojet1CSV_WpLjets__268->GetYaxis()->SetLabelFont(42);
   h_isojet1CSV_WpLjets__268->GetYaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_WpLjets__268->GetYaxis()->SetTitleSize(0.05);
   h_isojet1CSV_WpLjets__268->GetYaxis()->SetTickLength(0.025);
   h_isojet1CSV_WpLjets__268->GetYaxis()->SetTitleFont(42);
   h_isojet1CSV_WpLjets__268->GetZaxis()->SetLabelFont(42);
   h_isojet1CSV_WpLjets__268->GetZaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_WpLjets__268->GetZaxis()->SetTitleSize(0.05);
   h_isojet1CSV_WpLjets__268->GetZaxis()->SetTickLength(0.025);
   h_isojet1CSV_WpLjets__268->GetZaxis()->SetTitleFont(42);
   h->Add(h_isojet1CSV_W+jets,"");
   
   TH1D *h_isojet1CSV_TopsPoPLFcP__269 = new TH1D("h_isojet1CSV_TopsPoPLFcP__269","",10,0,1);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(1,0.09097508);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(2,0.09232326);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(3,0.04269338);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(4,0.02949662);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(5,0.02281892);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(6,0.01709603);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(7,0.01404044);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(8,0.009499499);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(9,0.006095059);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinContent(10,0.003040849);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(1,0.0009372855);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(2,0.0009857636);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(3,0.0007155424);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(4,0.0005977933);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(5,0.0005373378);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(6,0.0004781073);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(7,0.0004489056);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(8,0.0003875753);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(9,0.0003337873);
   h_isojet1CSV_TopsPoPLFcP__269->SetBinError(10,0.0003173281);
   h_isojet1CSV_TopsPoPLFcP__269->SetEntries(45754);
   h_isojet1CSV_TopsPoPLFcP__269->SetStats(0);

   ci = TColor::GetColor("#cc33cc");
   h_isojet1CSV_TopsPoPLFcP__269->SetFillColor(ci);
   h_isojet1CSV_TopsPoPLFcP__269->GetXaxis()->SetTitle("isojet 1 CSV");
   h_isojet1CSV_TopsPoPLFcP__269->GetXaxis()->SetLabelFont(42);
   h_isojet1CSV_TopsPoPLFcP__269->GetXaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_TopsPoPLFcP__269->GetXaxis()->SetTitleSize(0.05);
   h_isojet1CSV_TopsPoPLFcP__269->GetXaxis()->SetTickLength(0.025);
   h_isojet1CSV_TopsPoPLFcP__269->GetXaxis()->SetTitleFont(42);
   h_isojet1CSV_TopsPoPLFcP__269->GetYaxis()->SetTitle("a.u.");
   h_isojet1CSV_TopsPoPLFcP__269->GetYaxis()->SetLabelFont(42);
   h_isojet1CSV_TopsPoPLFcP__269->GetYaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_TopsPoPLFcP__269->GetYaxis()->SetTitleSize(0.05);
   h_isojet1CSV_TopsPoPLFcP__269->GetYaxis()->SetTickLength(0.025);
   h_isojet1CSV_TopsPoPLFcP__269->GetYaxis()->SetTitleFont(42);
   h_isojet1CSV_TopsPoPLFcP__269->GetZaxis()->SetLabelFont(42);
   h_isojet1CSV_TopsPoPLFcP__269->GetZaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_TopsPoPLFcP__269->GetZaxis()->SetTitleSize(0.05);
   h_isojet1CSV_TopsPoPLFcP__269->GetZaxis()->SetTickLength(0.025);
   h_isojet1CSV_TopsPoPLFcP__269->GetZaxis()->SetTitleFont(42);
   h->Add(h_isojet1CSV_Top (LF),"");
   
   TH1D *h_isojet1CSV_TopsPoPHFcP__270 = new TH1D("h_isojet1CSV_TopsPoPHFcP__270","",10,0,1);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(1,0.01878166);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(2,0.02708098);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(3,0.01896531);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(4,0.01870601);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(5,0.01924485);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(6,0.02077131);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(7,0.02899544);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(8,0.03698897);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(9,0.07325594);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinContent(10,0.2676551);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(1,0.0004640739);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(2,0.0005643558);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(3,0.0004957084);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(4,0.0004766015);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(5,0.0004665302);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(6,0.0005070097);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(7,0.0006476121);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(8,0.0007056579);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(9,0.0009826258);
   h_isojet1CSV_TopsPoPHFcP__270->SetBinError(10,0.001744809);
   h_isojet1CSV_TopsPoPHFcP__270->SetEntries(77950);
   h_isojet1CSV_TopsPoPHFcP__270->SetStats(0);

   ci = TColor::GetColor("#ff9900");
   h_isojet1CSV_TopsPoPHFcP__270->SetFillColor(ci);
   h_isojet1CSV_TopsPoPHFcP__270->GetXaxis()->SetTitle("isojet 1 CSV");
   h_isojet1CSV_TopsPoPHFcP__270->GetXaxis()->SetLabelFont(42);
   h_isojet1CSV_TopsPoPHFcP__270->GetXaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_TopsPoPHFcP__270->GetXaxis()->SetTitleSize(0.05);
   h_isojet1CSV_TopsPoPHFcP__270->GetXaxis()->SetTickLength(0.025);
   h_isojet1CSV_TopsPoPHFcP__270->GetXaxis()->SetTitleFont(42);
   h_isojet1CSV_TopsPoPHFcP__270->GetYaxis()->SetTitle("a.u.");
   h_isojet1CSV_TopsPoPHFcP__270->GetYaxis()->SetLabelFont(42);
   h_isojet1CSV_TopsPoPHFcP__270->GetYaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_TopsPoPHFcP__270->GetYaxis()->SetTitleSize(0.05);
   h_isojet1CSV_TopsPoPHFcP__270->GetYaxis()->SetTickLength(0.025);
   h_isojet1CSV_TopsPoPHFcP__270->GetYaxis()->SetTitleFont(42);
   h_isojet1CSV_TopsPoPHFcP__270->GetZaxis()->SetLabelFont(42);
   h_isojet1CSV_TopsPoPHFcP__270->GetZaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_TopsPoPHFcP__270->GetZaxis()->SetTitleSize(0.05);
   h_isojet1CSV_TopsPoPHFcP__270->GetZaxis()->SetTickLength(0.025);
   h_isojet1CSV_TopsPoPHFcP__270->GetZaxis()->SetTitleFont(42);
   h->Add(h_isojet1CSV_Top (HF),"");
   h->Draw("hist");
   
   TH1D *hsum__271 = new TH1D("hsum__271","",10,0,1);
   hsum__271->SetBinContent(1,0.1393796);
   hsum__271->SetBinContent(2,0.1586681);
   hsum__271->SetBinContent(3,0.08197864);
   hsum__271->SetBinContent(4,0.06142623);
   hsum__271->SetBinContent(5,0.05359128);
   hsum__271->SetBinContent(6,0.0447599);
   hsum__271->SetBinContent(7,0.04846618);
   hsum__271->SetBinContent(8,0.05074524);
   hsum__271->SetBinContent(9,0.082468);
   hsum__271->SetBinContent(10,0.2785168);
   hsum__271->SetBinError(1,0.002288647);
   hsum__271->SetBinError(2,0.002167196);
   hsum__271->SetBinError(3,0.001617233);
   hsum__271->SetBinError(4,0.001528597);
   hsum__271->SetBinError(5,0.001538373);
   hsum__271->SetBinError(6,0.001141764);
   hsum__271->SetBinError(7,0.001103813);
   hsum__271->SetBinError(8,0.001058293);
   hsum__271->SetBinError(9,0.001107265);
   hsum__271->SetBinError(10,0.002872657);
   hsum__271->SetEntries(45);
   hsum__271->SetStats(0);

   ci = 1202;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   hsum__271->SetFillColor(ci);
   hsum__271->SetFillStyle(3003);
   hsum__271->SetLineWidth(0);
   hsum__271->GetXaxis()->SetTitle("isojet 1 CSV");
   hsum__271->GetXaxis()->SetLabelFont(42);
   hsum__271->GetXaxis()->SetLabelOffset(0.007);
   hsum__271->GetXaxis()->SetTitleSize(0.05);
   hsum__271->GetXaxis()->SetTickLength(0.025);
   hsum__271->GetXaxis()->SetTitleFont(42);
   hsum__271->GetYaxis()->SetTitle("a.u.");
   hsum__271->GetYaxis()->SetLabelFont(42);
   hsum__271->GetYaxis()->SetLabelOffset(0.007);
   hsum__271->GetYaxis()->SetTitleSize(0.05);
   hsum__271->GetYaxis()->SetTickLength(0.025);
   hsum__271->GetYaxis()->SetTitleFont(42);
   hsum__271->GetZaxis()->SetLabelFont(42);
   hsum__271->GetZaxis()->SetLabelOffset(0.007);
   hsum__271->GetZaxis()->SetTitleSize(0.05);
   hsum__271->GetZaxis()->SetTickLength(0.025);
   hsum__271->GetZaxis()->SetTitleFont(42);
   hsum__271->Draw("e2 same");
   
   TH1D *h_isojet1CSV_Data__272 = new TH1D("h_isojet1CSV_Data__272","",10,0,1);
   h_isojet1CSV_Data__272->SetBinContent(1,0.138368);
   h_isojet1CSV_Data__272->SetBinContent(2,0.1592858);
   h_isojet1CSV_Data__272->SetBinContent(3,0.08381231);
   h_isojet1CSV_Data__272->SetBinContent(4,0.06152831);
   h_isojet1CSV_Data__272->SetBinContent(5,0.05196457);
   h_isojet1CSV_Data__272->SetBinContent(6,0.04475643);
   h_isojet1CSV_Data__272->SetBinContent(7,0.04833695);
   h_isojet1CSV_Data__272->SetBinContent(8,0.05059832);
   h_isojet1CSV_Data__272->SetBinContent(9,0.08235183);
   h_isojet1CSV_Data__272->SetBinContent(10,0.2789975);
   h_isojet1CSV_Data__272->SetBinError(1,0.002553194);
   h_isojet1CSV_Data__272->SetBinError(2,0.002739394);
   h_isojet1CSV_Data__272->SetBinError(3,0.0019871);
   h_isojet1CSV_Data__272->SetBinError(4,0.001702564);
   h_isojet1CSV_Data__272->SetBinError(5,0.001564659);
   h_isojet1CSV_Data__272->SetBinError(6,0.00145209);
   h_isojet1CSV_Data__272->SetBinError(7,0.001509057);
   h_isojet1CSV_Data__272->SetBinError(8,0.001543953);
   h_isojet1CSV_Data__272->SetBinError(9,0.001969711);
   h_isojet1CSV_Data__272->SetBinError(10,0.003625484);
   h_isojet1CSV_Data__272->SetEntries(21226);
   h_isojet1CSV_Data__272->SetStats(0);
   h_isojet1CSV_Data__272->SetLineWidth(3);
   h_isojet1CSV_Data__272->SetMarkerStyle(20);
   h_isojet1CSV_Data__272->SetMarkerSize(2);
   h_isojet1CSV_Data__272->GetXaxis()->SetTitle("isojet 1 CSV");
   h_isojet1CSV_Data__272->GetXaxis()->SetLabelFont(42);
   h_isojet1CSV_Data__272->GetXaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_Data__272->GetXaxis()->SetTitleSize(0.05);
   h_isojet1CSV_Data__272->GetXaxis()->SetTickLength(0.025);
   h_isojet1CSV_Data__272->GetXaxis()->SetTitleFont(42);
   h_isojet1CSV_Data__272->GetYaxis()->SetTitle("a.u.");
   h_isojet1CSV_Data__272->GetYaxis()->SetLabelFont(42);
   h_isojet1CSV_Data__272->GetYaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_Data__272->GetYaxis()->SetTitleSize(0.05);
   h_isojet1CSV_Data__272->GetYaxis()->SetTickLength(0.025);
   h_isojet1CSV_Data__272->GetYaxis()->SetTitleFont(42);
   h_isojet1CSV_Data__272->GetZaxis()->SetLabelFont(42);
   h_isojet1CSV_Data__272->GetZaxis()->SetLabelOffset(0.007);
   h_isojet1CSV_Data__272->GetZaxis()->SetTitleSize(0.05);
   h_isojet1CSV_Data__272->GetZaxis()->SetTickLength(0.025);
   h_isojet1CSV_Data__272->GetZaxis()->SetTitleFont(42);
   h_isojet1CSV_Data__272->Draw("elp same");
   
   TLegend *leg = new TLegend(0.6,0.55,0.88,0.9,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   TLegendEntry *entry=leg->AddEntry("h_isojet1CSV_Data","Data","ELP");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(3);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(2);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_Top (HF)","Top (HF)","F");

   ci = TColor::GetColor("#ff9900");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_Top (LF)","Top (LF)","F");

   ci = TColor::GetColor("#cc33cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_W+jets","W+jets","F");

   ci = TColor::GetColor("#66cc66");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_Z+jets","Z+jets","F");

   ci = TColor::GetColor("#3399cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_Diboson","Diboson","F");

   ci = TColor::GetColor("#9966cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_QCD","QCD","F");

   ci = TColor::GetColor("#cccccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   
   leg = new TLegend(0.6,0.55,0.88,0.9,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   entry=leg->AddEntry("h_isojet1CSV_Data","Data","ELP");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(3);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(2);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_Top (HF)","Top (HF)","F");

   ci = TColor::GetColor("#ff9900");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_Top (LF)","Top (LF)","F");

   ci = TColor::GetColor("#cc33cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_W+jets","W+jets","F");

   ci = TColor::GetColor("#66cc66");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_Z+jets","Z+jets","F");

   ci = TColor::GetColor("#3399cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_Diboson","Diboson","F");

   ci = TColor::GetColor("#9966cc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("h_isojet1CSV_QCD","QCD","F");

   ci = TColor::GetColor("#cccccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   TLatex *   tex = new TLatex(0.18,0.85,"CMS");
tex->SetNDC();
   tex->SetTextSize(0.06);
   tex->SetLineWidth(2);
   tex->Draw();
      tex = new TLatex(0.28,0.85,"Preliminary");
tex->SetNDC();
   tex->SetTextFont(52);
   tex->SetTextSize(0.06);
   tex->SetLineWidth(2);
   tex->Draw();
      tex = new TLatex(0.9,0.94,"36.6 fb^{-1} (13 TeV)");
tex->SetNDC();
   tex->SetTextAlign(31);
   tex->SetTextFont(42);
   tex->SetTextSize(0.04);
   tex->SetLineWidth(2);
   tex->Draw();
   pad1->Modified();
   c1->cd();
  
// ------------>Primitives in pad: pad2
   TPad *pad2 = new TPad("pad2", "pad2",0,0.05,1,0.3);
   pad2->Draw();
   pad2->cd();
   pad2->Range(-0.1875,-0.8914286,1.0625,0.48);
   pad2->SetFillColor(0);
   pad2->SetBorderMode(0);
   pad2->SetBorderSize(2);
   pad2->SetGridy();
   pad2->SetTickx(1);
   pad2->SetTicky(1);
   pad2->SetLeftMargin(0.15);
   pad2->SetRightMargin(0.05);
   pad2->SetTopMargin(0);
   pad2->SetBottomMargin(0.3);
   pad2->SetFrameFillStyle(0);
   pad2->SetFrameBorderMode(0);
   pad2->SetFrameFillStyle(0);
   pad2->SetFrameBorderMode(0);
   
   TH1D *ratio__273 = new TH1D("ratio__273","",10,0,1);
   ratio__273->SetBinContent(1,-0.00725764);
   ratio__273->SetBinContent(2,0.003892779);
   ratio__273->SetBinContent(3,0.0223676);
   ratio__273->SetBinContent(4,0.001661897);
   ratio__273->SetBinContent(5,-0.0303539);
   ratio__273->SetBinContent(6,-7.754564e-05);
   ratio__273->SetBinContent(7,-0.002666473);
   ratio__273->SetBinContent(8,-0.002895236);
   ratio__273->SetBinContent(9,-0.001408637);
   ratio__273->SetBinContent(10,0.001725793);
   ratio__273->SetBinError(1,0.0001);
   ratio__273->SetBinError(2,0.0001);
   ratio__273->SetBinError(3,0.0001);
   ratio__273->SetBinError(4,0.0001);
   ratio__273->SetBinError(5,0.0001);
   ratio__273->SetBinError(6,0.0001);
   ratio__273->SetBinError(7,0.0001);
   ratio__273->SetBinError(8,0.0001);
   ratio__273->SetBinError(9,0.0001);
   ratio__273->SetBinError(10,0.0001);
   ratio__273->SetMinimum(-0.48);
   ratio__273->SetMaximum(0.48);
   ratio__273->SetEntries(21236);
   ratio__273->SetStats(0);
   ratio__273->SetLineWidth(3);
   ratio__273->SetMarkerStyle(20);
   ratio__273->SetMarkerSize(2);
   ratio__273->GetXaxis()->SetTitle("isojet 1 CSV");
   ratio__273->GetXaxis()->SetLabelFont(43);
   ratio__273->GetXaxis()->SetLabelOffset(0.007);
   ratio__273->GetXaxis()->SetLabelSize(30);
   ratio__273->GetXaxis()->SetTitleSize(40);
   ratio__273->GetXaxis()->SetTickLength(0.025);
   ratio__273->GetXaxis()->SetTitleOffset(5);
   ratio__273->GetXaxis()->SetTitleFont(43);
   ratio__273->GetYaxis()->SetTitle("#frac{Data-Exp}{Exp}");
   ratio__273->GetYaxis()->SetNdivisions(5);
   ratio__273->GetYaxis()->SetLabelFont(43);
   ratio__273->GetYaxis()->SetLabelOffset(0.007);
   ratio__273->GetYaxis()->SetLabelSize(30);
   ratio__273->GetYaxis()->SetTitleSize(40);
   ratio__273->GetYaxis()->SetTickLength(0.025);
   ratio__273->GetYaxis()->SetTitleOffset(2.5);
   ratio__273->GetYaxis()->SetTitleFont(43);
   ratio__273->GetZaxis()->SetLabelFont(42);
   ratio__273->GetZaxis()->SetLabelOffset(0.007);
   ratio__273->GetZaxis()->SetTitleSize(0.05);
   ratio__273->GetZaxis()->SetTickLength(0.025);
   ratio__273->GetZaxis()->SetTitleFont(42);
   ratio__273->Draw("elp");
   
   TH1D *zero__274 = new TH1D("zero__274","",10,0,1);
   zero__274->SetBinError(1,0.002553194);
   zero__274->SetBinError(2,0.002739394);
   zero__274->SetBinError(3,0.0019871);
   zero__274->SetBinError(4,0.001702564);
   zero__274->SetBinError(5,0.001564659);
   zero__274->SetBinError(6,0.00145209);
   zero__274->SetBinError(7,0.001509057);
   zero__274->SetBinError(8,0.001543953);
   zero__274->SetBinError(9,0.001969711);
   zero__274->SetBinError(10,0.003625484);
   zero__274->SetEntries(21236);
   zero__274->SetStats(0);
   zero__274->SetLineWidth(3);
   zero__274->SetMarkerStyle(20);
   zero__274->SetMarkerSize(2);
   zero__274->GetXaxis()->SetTitle("isojet 1 CSV");
   zero__274->GetXaxis()->SetLabelFont(42);
   zero__274->GetXaxis()->SetLabelOffset(0.007);
   zero__274->GetXaxis()->SetTitleSize(0.05);
   zero__274->GetXaxis()->SetTickLength(0.025);
   zero__274->GetXaxis()->SetTitleFont(42);
   zero__274->GetYaxis()->SetTitle("a.u.");
   zero__274->GetYaxis()->SetLabelFont(42);
   zero__274->GetYaxis()->SetLabelOffset(0.007);
   zero__274->GetYaxis()->SetTitleSize(0.05);
   zero__274->GetYaxis()->SetTickLength(0.025);
   zero__274->GetYaxis()->SetTitleFont(42);
   zero__274->GetZaxis()->SetLabelFont(42);
   zero__274->GetZaxis()->SetLabelOffset(0.007);
   zero__274->GetZaxis()->SetTitleSize(0.05);
   zero__274->GetZaxis()->SetTickLength(0.025);
   zero__274->GetZaxis()->SetTitleFont(42);
   zero__274->Draw("hist same");
   
   TH1D *sumratioup__275 = new TH1D("sumratioup__275","",10,0,1);
   sumratioup__275->SetBinContent(1,0.01642024);
   sumratioup__275->SetBinContent(2,0.01365867);
   sumratioup__275->SetBinContent(3,0.01972749);
   sumratioup__275->SetBinContent(4,0.02488509);
   sumratioup__275->SetBinContent(5,0.02870566);
   sumratioup__275->SetBinContent(6,0.02550863);
   sumratioup__275->SetBinContent(7,0.02277492);
   sumratioup__275->SetBinContent(8,0.02085501);
   sumratioup__275->SetBinContent(9,0.01342661);
   sumratioup__275->SetBinContent(10,0.01031412);
   sumratioup__275->SetBinError(1,0.002288647);
   sumratioup__275->SetBinError(2,0.002167196);
   sumratioup__275->SetBinError(3,0.001617233);
   sumratioup__275->SetBinError(4,0.001528597);
   sumratioup__275->SetBinError(5,0.001538373);
   sumratioup__275->SetBinError(6,0.001141764);
   sumratioup__275->SetBinError(7,0.001103813);
   sumratioup__275->SetBinError(8,0.001058293);
   sumratioup__275->SetBinError(9,0.001107265);
   sumratioup__275->SetBinError(10,0.002872657);
   sumratioup__275->SetEntries(55);
   sumratioup__275->SetStats(0);

   ci = 1202;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   sumratioup__275->SetFillColor(ci);
   sumratioup__275->SetFillStyle(3003);
   sumratioup__275->GetXaxis()->SetTitle("isojet 1 CSV");
   sumratioup__275->GetXaxis()->SetLabelFont(42);
   sumratioup__275->GetXaxis()->SetLabelOffset(0.007);
   sumratioup__275->GetXaxis()->SetTitleSize(0.05);
   sumratioup__275->GetXaxis()->SetTickLength(0.025);
   sumratioup__275->GetXaxis()->SetTitleFont(42);
   sumratioup__275->GetYaxis()->SetTitle("a.u.");
   sumratioup__275->GetYaxis()->SetLabelFont(42);
   sumratioup__275->GetYaxis()->SetLabelOffset(0.007);
   sumratioup__275->GetYaxis()->SetTitleSize(0.05);
   sumratioup__275->GetYaxis()->SetTickLength(0.025);
   sumratioup__275->GetYaxis()->SetTitleFont(42);
   sumratioup__275->GetZaxis()->SetLabelFont(42);
   sumratioup__275->GetZaxis()->SetLabelOffset(0.007);
   sumratioup__275->GetZaxis()->SetTitleSize(0.05);
   sumratioup__275->GetZaxis()->SetTickLength(0.025);
   sumratioup__275->GetZaxis()->SetTitleFont(42);
   sumratioup__275->Draw("hist same");
   
   TH1D *sumratiodown__276 = new TH1D("sumratiodown__276","",10,0,1);
   sumratiodown__276->SetBinContent(1,-0.01642024);
   sumratiodown__276->SetBinContent(2,-0.01365867);
   sumratiodown__276->SetBinContent(3,-0.01972749);
   sumratiodown__276->SetBinContent(4,-0.02488509);
   sumratiodown__276->SetBinContent(5,-0.02870566);
   sumratiodown__276->SetBinContent(6,-0.02550863);
   sumratiodown__276->SetBinContent(7,-0.02277492);
   sumratiodown__276->SetBinContent(8,-0.02085501);
   sumratiodown__276->SetBinContent(9,-0.01342661);
   sumratiodown__276->SetBinContent(10,-0.01031412);
   sumratiodown__276->SetBinError(1,0.002288647);
   sumratiodown__276->SetBinError(2,0.002167196);
   sumratiodown__276->SetBinError(3,0.001617233);
   sumratiodown__276->SetBinError(4,0.001528597);
   sumratiodown__276->SetBinError(5,0.001538373);
   sumratiodown__276->SetBinError(6,0.001141764);
   sumratiodown__276->SetBinError(7,0.001103813);
   sumratiodown__276->SetBinError(8,0.001058293);
   sumratiodown__276->SetBinError(9,0.001107265);
   sumratiodown__276->SetBinError(10,0.002872657);
   sumratiodown__276->SetEntries(55);
   sumratiodown__276->SetStats(0);

   ci = 1202;
   color = new TColor(ci, 0, 0, 0, " ", 0.99);
   sumratiodown__276->SetFillColor(ci);
   sumratiodown__276->SetFillStyle(3003);
   sumratiodown__276->GetXaxis()->SetTitle("isojet 1 CSV");
   sumratiodown__276->GetXaxis()->SetLabelFont(42);
   sumratiodown__276->GetXaxis()->SetLabelOffset(0.007);
   sumratiodown__276->GetXaxis()->SetTitleSize(0.05);
   sumratiodown__276->GetXaxis()->SetTickLength(0.025);
   sumratiodown__276->GetXaxis()->SetTitleFont(42);
   sumratiodown__276->GetYaxis()->SetTitle("a.u.");
   sumratiodown__276->GetYaxis()->SetLabelFont(42);
   sumratiodown__276->GetYaxis()->SetLabelOffset(0.007);
   sumratiodown__276->GetYaxis()->SetTitleSize(0.05);
   sumratiodown__276->GetYaxis()->SetTickLength(0.025);
   sumratiodown__276->GetYaxis()->SetTitleFont(42);
   sumratiodown__276->GetZaxis()->SetLabelFont(42);
   sumratiodown__276->GetZaxis()->SetLabelOffset(0.007);
   sumratiodown__276->GetZaxis()->SetTitleSize(0.05);
   sumratiodown__276->GetZaxis()->SetTickLength(0.025);
   sumratiodown__276->GetZaxis()->SetTitleFont(42);
   sumratiodown__276->Draw("hist same");
   
   Double_t Graph0_fx1023[10] = {
   0.05,
   0.15,
   0.25,
   0.35,
   0.45,
   0.55,
   0.65,
   0.75,
   0.85,
   0.95};
   Double_t Graph0_fy1023[10] = {
   -0.00725764,
   0.003892779,
   0.0223676,
   0.001661897,
   -0.0303539,
   -7.754564e-05,
   -0.002666473,
   -0.002895236,
   -0.001408637,
   0.001725793};
   Double_t Graph0_fex1023[10] = {
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0,
   0};
   Double_t Graph0_fey1023[10] = {
   0.01831827,
   0.01726493,
   0.02423924,
   0.02771721,
   0.02919614,
   0.03244177,
   0.03113628,
   0.03042557,
   0.02388455,
   0.01301711};
   TGraphErrors *gre = new TGraphErrors(10,Graph0_fx1023,Graph0_fy1023,Graph0_fex1023,Graph0_fey1023);
   gre->SetName("Graph0");
   gre->SetTitle("Graph");
   gre->SetFillColor(1);
   gre->SetLineWidth(3);
   
   TH1F *Graph_Graph1023 = new TH1F("Graph_Graph1023","Graph",100,0,1.04);
   Graph_Graph1023->SetMinimum(-0.07016574);
   Graph_Graph1023->SetMaximum(0.05722253);
   Graph_Graph1023->SetDirectory(0);
   Graph_Graph1023->SetStats(0);

   ci = TColor::GetColor("#000099");
   Graph_Graph1023->SetLineColor(ci);
   Graph_Graph1023->GetXaxis()->SetLabelFont(42);
   Graph_Graph1023->GetXaxis()->SetLabelOffset(0.007);
   Graph_Graph1023->GetXaxis()->SetTitleSize(0.05);
   Graph_Graph1023->GetXaxis()->SetTickLength(0.025);
   Graph_Graph1023->GetXaxis()->SetTitleFont(42);
   Graph_Graph1023->GetYaxis()->SetLabelFont(42);
   Graph_Graph1023->GetYaxis()->SetLabelOffset(0.007);
   Graph_Graph1023->GetYaxis()->SetTitleSize(0.05);
   Graph_Graph1023->GetYaxis()->SetTickLength(0.025);
   Graph_Graph1023->GetYaxis()->SetTitleFont(42);
   Graph_Graph1023->GetZaxis()->SetLabelFont(42);
   Graph_Graph1023->GetZaxis()->SetLabelOffset(0.007);
   Graph_Graph1023->GetZaxis()->SetTitleSize(0.05);
   Graph_Graph1023->GetZaxis()->SetTickLength(0.025);
   Graph_Graph1023->GetZaxis()->SetTitleFont(42);
   gre->SetHistogram(Graph_Graph1023);
   
   gre->Draw("pe0");
   pad2->Modified();
   c1->cd();
   c1->Modified();
   c1->cd();
   c1->SetSelected(c1);
}
Exemple #28
0
void controlplots(int mode = 0){
 
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  gStyle->SetErrorX(0);
  setTDRStyle();
  gROOT->SetBatch(1);

  labelcms  = new TPaveText(0.12,0.88,0.5,0.94,"NDCBR");
  labelcms->SetTextAlign(12);
  labelcms->SetTextSize(0.045);
  labelcms->SetFillColor(kWhite);
  labelcms->AddText("CMS Preliminary, #sqrt{s} = 7 TeV");
  labelcms->SetBorderSize(0);
  
  labelcms2  = new TPaveText(0.12,0.85,0.5,0.88,"NDCBR");
  labelcms2->SetTextAlign(12);
  labelcms2->SetTextSize(0.045);
  labelcms2->SetFillColor(kWhite);
  
  if (mode == 0) labelcms2->AddText("4.9 fb^{-1}, e#mu channel  ");
  if (mode == 1) labelcms2->AddText("4.9 fb^{-1}, #mu#mu channel  ");
  if (mode == 2) labelcms2->AddText("4.9 fb^{-1}, ee channel  ");
  labelcms2->SetBorderSize(0);
  
  gStyle->SetOptStat(0);
  gStyle->SetPalette(1);
  
  gStyle->SetCanvasBorderMode(0);
  gStyle->SetCanvasColor(kWhite);
  gStyle->SetCanvasDefH(600);
  gStyle->SetCanvasDefW(600);
  gStyle->SetLabelFont(18,"");

  gStyle->SetTitleXOffset(1.2);//1.5
  gStyle->SetTitleYOffset(1.2);//1.7
  
  char myRootFile[300];
  double lumi = 0;
  
  if (mode == 0 )        lumi = 4904.338;
  else if ( mode == 1)   lumi = 4919.924;
  else if ( mode == 2)   lumi = 4895.249;

  sprintf(myRootFile,"results/sf_an_%dpb_%d.root", lumi, mode);
  
  
  TFile *_file0 = TFile::Open(myRootFile);
  cout << myRootFile << endl;

  const int nProcess = 8;
  TString processName[nProcess] =  { "twdr", "st", "tt","di", "zjets", "wjets",  "qcd_mu", "data"};
  TString processTitle[nProcess] = { "tW", "t/s-channel", "t#bar{t}", "WW/WZ/ZZ", "Z/#gamma*+jets", "W+jets",  "QCD", "data"};
  Color_t color[nProcess] =        {kWhite, kMagenta-10, kRed+1, kYellow-10,  kAzure-2, kGreen-3, 40, kBlack};
  TString modeString[3] = {"0", "1", "2"};

  TString cutLabel = "R";
 
  
  TH1F*  h [nProcess];
  TH1F*  histo[nProcess];
  THStack* hStack;
  
  leg = new TLegend(0.7,0.7,0.94,0.94);
  leg ->SetFillStyle(1);
  leg ->SetFillColor(kWhite);
  leg ->SetBorderSize(1);
  leg ->SetTextSize(0.03);
  hStack = new THStack();
  hStack2 = new THStack();
  for (int iProcess = 0; iProcess < 8; iProcess++){
    h[iProcess] = (TH1F*) _file0->Get("R_" + processName[iProcess]);
    
    h[iProcess]->SetFillColor(color[iProcess]);
    h[iProcess]->SetLineColor(kBlack);
    
    histo[iProcess] = new TH1F("histo"+processName[iProcess], "", 3, 0, 3);
    histo[iProcess]->SetLineColor(kBlack);
    histo[iProcess]->SetLineWidth(1);
    histo[iProcess]->SetFillColor(color[iProcess]);
    histo[iProcess]->SetBinContent(1, h[iProcess]->GetBinContent(28));
    histo[iProcess]->SetBinContent(2, h[iProcess]->GetBinContent(30));
    histo[iProcess]->SetBinContent(3, h[iProcess]->GetBinContent(31));
    histo[iProcess]->SetBinError(1, h[iProcess]->GetBinError(28));
    histo[iProcess]->SetBinError(2, h[iProcess]->GetBinError(30));
    histo[iProcess]->SetBinError(3, h[iProcess]->GetBinError(31));
    
    if (iProcess == 0){
      h[iProcess]->SetLineColor(kBlack);
      histo[iProcess]->SetLineColor(kBlack);
    }
   
  }  
  
  histo[5]->Add(histo[1]);
  histo[5]->Add(histo[3]);
  histo[5]->Add(histo[6]);
  
  hStack->Add(histo[5]);
  hStack->Add(histo[4]);
  hStack->Add(histo[2]);
  hStack->Add(histo[0]);
  
  if (mode == 0) leg->AddEntry(histo[7], processTitle[7], "p");
  if (mode == 1) leg->AddEntry(histo[7], processTitle[7], "p");
  if (mode == 2) leg->AddEntry(histo[7], processTitle[7], "p");
  
  leg->AddEntry(histo[0], processTitle[0], "f");
  leg->AddEntry(histo[2], processTitle[2], "f");
  leg->AddEntry(histo[4], processTitle[4], "f");
  leg->AddEntry(histo[5], "Other", "f");
 
  
  histo[7]->SetMarkerStyle(20);
  histo[7]->SetMarkerSize(1.2);
  histo[7]->SetMarkerColor(kBlack);
  histo[7]->SetLineColor(kBlack);
  histo[7]->SetLineWidth(1);
  
  double max = TMath::Max(hStack->GetMaximum(), histo[7]->GetMaximum());
  TCanvas *c1 = new TCanvas();
  hStack->Draw("histo");
  hStack->SetMaximum(max * 1.25);
  hStack->SetMinimum(1);
  hStack->GetYaxis()->SetTitle("events / 4.9 fb^{-1}");
  hStack->GetYaxis()->SetTitleOffset(1.4);
  hStack->GetYaxis()->CenterTitle(); 
  
  hStack->GetYaxis()->SetTitleOffset(1.4);
  hStack->GetYaxis()->CenterTitle(); 
  hStack->GetXaxis()->SetBinLabel(1,"1 jet 1 tag");
  hStack->GetXaxis()->SetBinLabel(2,"2 jet 1 tag");
  hStack->GetXaxis()->SetBinLabel(3,"2 jet 2 tag");
  
  histo[7]->Draw("e, sames");
  leg->Draw();
  labelcms->Draw();
  labelcms2->Draw();
  
  c1->SaveAs("plots/sf_control_summer_tt_" + modeString[mode] + "_" + cutLabel + ".png");
  c1->SaveAs("plots/pdf/sf_control_summer_tt_" + modeString[mode] + "_" + cutLabel + ".pdf");
  c1->SetLogy();
  hStack->SetMaximum(max * 10);
  c1->SaveAs("plots/sf_control_summer_tt_" + modeString[mode] + "_" + cutLabel + "_log.png");
  c1->SaveAs("plots/pdf/sf_control_summer_tt_" + modeString[mode] + "_" + cutLabel + "_log.pdf");
  
}