Beispiel #1
0
void makeNiceHisto(TH1D * &histo, TFile * file, TString name){
    
    if(!file->IsOpen()){
        cout << "cannot open file " << name << endl; return;
    }
    
    TCanvas * c = (TCanvas*)file->Get("DeltaPhiCorr");
    if(!c){
        cout << "cannot open canvas " << endl;
        file->ls();
    }
 //   c->ls();
    TH1D *histo_dummy = (TH1D*)c->FindObject("DphiSubtr")->Clone(name);
    if(!histo_dummy){
        c->ls();
    }
    
    
    histo = ReflectHisto(histo_dummy,0.5);
    
    TString yaxisTitle = "#frac{1}{N_{D}}#frac{dN^{assoc}}{d#Delta#varphi} (rad^{-1})";
    histo->SetTitle(Form("; #Delta#varphi (rad); %s", yaxisTitle.Data()));
    histo->GetYaxis()->SetTitleOffset(1.3);
    histo->GetYaxis()->SetRangeUser(0,20);
    histo->SetLineColor(1);
    histo->SetMarkerColor(1);
    histo->SetMarkerStyle(20);
    delete c;
    
    
}
//_______________________________________________________________________
TH1D * GetHisto(TString path, TString hname){
    
  Printf("Opening file: %s",path.Data());
  TFile *file=TFile::Open(path.Data(),"READ");

  TH1D * histo=0x0;
  histo=(TH1D*)file->Get(hname.Data());
  if(!histo){
    TCanvas * c = (TCanvas*)file->Get("cDeltaPhi");
    c->cd();
    histo = (TH1D*)c->FindObject(hname.Data());
  }
  return histo;
    
}
void macroComparison(string sfileA,string sfileB,string sfileC, string fname){

  TFile * fileA = new TFile(TString(sfileA), "READ");
  TFile * fileB = new TFile(TString(sfileB), "READ");
  TFile * fileC = new TFile(TString(sfileC), "READ");

  // get canvas name
  TList *listA = fileA->GetListOfKeys();  
  TString canvasnameA = listA->At(0)->GetName();
 
  TList *listB = fileB->GetListOfKeys();  
  TString canvasnameB = listB->At(0)->GetName();

  TList *listC = fileC->GetListOfKeys();  
  TString canvasnameC = listC->At(0)->GetName();

  // make histogram name out of canvas name
  TString histonameA = canvasnameA;
  Ssiz_t objIndexA = histonameA.Index("canvas");
  histonameA.Resize(objIndexA);
  histonameA+= "_data_hist";

  TString histonameB = canvasnameB;
  Ssiz_t objIndexB = histonameB.Index("canvas");
  histonameB.Resize(objIndexB);
  histonameB+= "_data_hist";

  TString histonameC = canvasnameC;
  Ssiz_t objIndexC = histonameC.Index("canvas");
  histonameC.Resize(objIndexC);
  histonameC+= "_data_hist";

  // get canvas from files
  // get histograms from canvases
  
  TCanvas *cvA = (TCanvas*) fileA->Get(canvasnameA);
  TH1D * histoA = (TH1D*) cvA->FindObject(histonameA)->Clone();
  // set name to different value
  cvA->SetName("dummy");
  
  TCanvas *cvB = (TCanvas*) fileB->Get(canvasnameB);
  TH1D * histoB = (TH1D*) cvB->FindObject(histonameB)->Clone();
  cvB->SetName("dummy2");

  TCanvas *cvC = (TCanvas*) fileC->Get(canvasnameC);
  TH1D * histoC = (TH1D*) cvC->FindObject(histonameC)->Clone();


  // ratio plots
  TH1D * histoAoverBRatio =  (TH1D*) histoA->Clone();
  TH1D * histoAoverCRatio =  (TH1D*) histoA->Clone();
  TH1D * histoBoverCRatio =  (TH1D*) histoB->Clone();

  histoAoverBRatio->Divide(histoB);
  histoAoverCRatio->Divide(histoC);
  histoBoverCRatio->Divide(histoC);

  // make new Canvas for plotting
  TCanvas *cv1 = new TCanvas(histonameA, histonameA, 1024,1024);
  cv1->cd();
  cv1->Clear();
  cv1->Divide(1,2,0.01,0.0);
  

  cv1->cd(1);
  cv1->SetFillColor(0); 
  gStyle->SetOptTitle(0);
  gPad->SetFillColor(0);
  gPad->SetPad( 0.0, 0.25, 1.0, 1.0 );
  gPad->SetTopMargin(0.1);
  gPad->SetLeftMargin(0.16);
  gPad->SetRightMargin(0.04);

  cv1->cd(2);
  cv1->SetFillColor(0);
  gStyle->SetOptTitle(0);
  gPad->SetFillColor(0);
  gPad->SetPad( 0.0, 0.0,  1.0, 0.25 );
  gPad->SetBottomMargin(0.375);
  gPad->SetLeftMargin(0.16);
  gPad->SetRightMargin(0.04);
  gPad->SetGridy();

  cv1->cd(1);

  histoA->SetMarkerStyle(20);
  histoA->SetMarkerSize(2);
  histoA->SetMarkerColor(1);
  histoA->Draw("E1X0");
  //  histoA->DrawNormalized("E1X0");

  histoB->SetMarkerStyle(21);
  histoB->SetMarkerSize(2);
  histoB->SetMarkerColor(2);
  histoB->Draw("E1X0SAME");
  //  histoB->DrawNormalized("E1X0SAME");

  histoC->SetMarkerStyle(22);
  histoC->SetMarkerSize(2);
  histoC->SetMarkerColor(3);
  histoC->Draw("E1X0SAME");
  //  histoC->DrawNormalized("E1X0SAME");

  TLegend *leg = new TLegend(0.685, 0.575, 0.8, 0.875); 
  leg->AddEntry(histoA,"A");
  leg->AddEntry(histoB,"B");
  leg->AddEntry(histoC,"C");

  leg->Draw("SAME");


  // set style for ratio plots

  histoAoverBRatio->SetMarkerStyle(20);
  histoAoverCRatio->SetMarkerStyle(21);
  histoBoverCRatio->SetMarkerStyle(22);
  histoAoverBRatio->SetMarkerSize(1);
  histoAoverCRatio->SetMarkerSize(1);
  histoBoverCRatio->SetMarkerSize(1);
  histoAoverBRatio->SetMarkerColor(1);
  histoAoverCRatio->SetMarkerColor(2);
  histoBoverCRatio->SetMarkerColor(3);
  histoAoverBRatio->SetLineColor(1);
  histoAoverCRatio->SetLineColor(2);
  histoBoverCRatio->SetLineColor(3);

  cv1->cd(2);
  histoAoverBRatio->GetYaxis()->SetRangeUser(0.9,1.1);
  histoAoverBRatio->GetYaxis()->CenterTitle(1);
  histoAoverBRatio->GetYaxis()->SetTitleSize( 0.16 );
  histoAoverBRatio->GetYaxis()->SetTitleOffset( 0.425 );
  histoAoverBRatio->GetYaxis()->SetLabelSize( 0.16 );
  histoAoverBRatio->GetYaxis()->SetNdivisions( 505 );

  histoAoverBRatio->GetXaxis()->SetTitleSize( 0.16 );
  histoAoverBRatio->GetXaxis()->SetLabelSize( 0.16 );
  histoAoverBRatio->GetXaxis()->SetTitleOffset( 1 );
  histoAoverBRatio->GetXaxis()->SetLabelOffset( 0.006 );
  histoAoverBRatio->GetXaxis()->SetNdivisions( 510 );
  histoAoverBRatio->GetXaxis()->SetTickLength( histoAoverBRatio->GetXaxis()->GetTickLength() * 3.0 );
  histoAoverBRatio->SetYTitle("Data/Data"); 

  histoAoverBRatio->Draw("E1X0");
  histoAoverCRatio->Draw("E1X0SAME");
  histoBoverCRatio->Draw("E1X0SAME");

  cv1->Update();
  cv1->Print(TString(fname)+TString("_Linear.png"));


  /// the same with log scale

 // make new Canvas for plotting
  TCanvas *cv2 = new TCanvas(histonameA+"log", histonameA+"log", 1024,1024);
  cv2->cd();
  cv2->Clear();
  cv2->Divide(1,2,0.01,0.0);
  

  cv2->cd(1);
  cv2->SetFillColor(0); 
  gStyle->SetOptTitle(0);
  gPad->SetLogy();
  gPad->SetFillColor(0);
  gPad->SetPad( 0.0, 0.25, 1.0, 1.0 );
  gPad->SetTopMargin(0.1);
  gPad->SetLeftMargin(0.16);
  gPad->SetRightMargin(0.04);

  cv2->cd(2);
  cv2->SetFillColor(0);
  gStyle->SetOptTitle(0);
  gPad->SetFillColor(0);
  gPad->SetPad( 0.0, 0.0,  1.0, 0.25 );
  gPad->SetBottomMargin(0.375);
  gPad->SetLeftMargin(0.16);
  gPad->SetRightMargin(0.04);
  gPad->SetGridy();

  cv2->cd(1);

 
  histoA->Draw("E1X0");
  histoB->Draw("E1X0SAME");
  histoC->Draw("E1X0SAME");

  TLegend *leg2 = new TLegend(0.685, 0.575, 0.8, 0.875); 
  leg2->AddEntry(histoA,"A");
  leg2->AddEntry(histoB,"B");
  leg2->AddEntry(histoC,"C");

  leg2->Draw("SAME");



  cv2->cd(2);
 
  histoAoverBRatio->Draw("E1X0");
  histoAoverCRatio->Draw("E1X0SAME");
  histoBoverCRatio->Draw("E1X0SAME");

  cv2->Update();
  cv2->Print(TString(fname)+TString("_Log.png"));


}
void grabDataSubtractedHistograms(int nJet, int massRange) {
  TFile f("Histograms_data_and_template.root", "update");


  // Figure out the plot directory name first
  TString dir2jet = "./plots_10172011_2jetsample";
  TString dir3jet = "./plots_10172011_3jetsample";
  TString dirName = "";
  if(nJet==2) dirName = dir2jet;
  if(nJet==3) dirName = dir3jet;

  TString massStr = "";
  if(nJet==2 && massRange==1) massStr = "150-230";
  else if(nJet==2 && massRange==2) massStr = "200-400";
  else if(nJet==2 && massRange==3) massStr = "360-500";
  else if(nJet==2 && massRange==4) massStr = "450-800";
  else if(nJet==3 && massRange==1) massStr = "150-230";
  else if(nJet==3 && massRange==2) massStr = "200-400";
  else if(nJet==3 && massRange==3) massStr = "360-800";

  TString ConnectorStr = "";
  if( !(massStr=="") ) ConnectorStr = "-";
  TString fitFileName = TString("mLnuJJ-") + massStr + ConnectorStr + TString("combined-fit");


  TFile* fitFile = new TFile( dirName + TString("/") + fitFileName+".root", "read");
  TCanvas* fitCan = (TCanvas*) fitFile->Get( fitFileName );
  RooHist* data = (RooHist*) fitCan->FindObject( "h_data" );
  RooCurve* fit = (RooCurve*) fitCan->FindObject( "h_total" );
  RooCurve* fit_wjj = (RooCurve*) fitCan->FindObject( "h_Wjets" );
  RooCurve* fit_diboson = (RooCurve*) fitCan->FindObject( "h_diboson" );
  RooCurve* fit_Top = (RooCurve*) fitCan->FindObject( "h_Top" );
  RooCurve* fit_QCD = (RooCurve*) fitCan->FindObject( "h_QCD" );
  RooCurve* fit_Zjets = (RooCurve*) fitCan->FindObject( "h_Zjets" );


  TFile* systFileUp = new TFile( dirName + TString("SystUp/") + fitFileName+".root", "read");
  TCanvas* systFileUpCan = (TCanvas*) systFileUp->Get( fitFileName );
  RooCurve* fit_wjj_systUp = (RooCurve*) systFileUpCan->FindObject( "h_Wjets" );
  RooCurve* fit_systUp = (RooCurve*) systFileUpCan->FindObject( "h_total" );

  TFile* systFileDown = new TFile( dirName + TString("SystDown/") + fitFileName+".root", "read");
  TCanvas* systFileDownCan = (TCanvas*) systFileDown->Get( fitFileName );
  RooCurve* fit_wjj_systDown = (RooCurve*) systFileDownCan->FindObject( "h_Wjets" );
  RooCurve* fit_systDown = (RooCurve*) systFileDownCan->FindObject("h_total");


  ///// Now save everything ///////////////
  TString outPrefix = TString("2jet_MassRange_") + massStr + TString("_");
  if(nJet==3) outPrefix = TString("3jet_MassRange_") + massStr + TString("_");


  data->SetName( outPrefix+"hist_data" );
  fit->SetName( outPrefix+"curve_fitTotal" );
  fit_wjj->SetName( outPrefix+"curve_WJets" );
  fit_diboson->SetName( outPrefix+"curve_diboson" );
  fit_Top->SetName(  outPrefix+"curve_Top" );
  fit_QCD->SetName(  outPrefix+"curve_QCD" );
  fit_Zjets->SetName(  outPrefix+"curve_Zjets" );
  fit_wjj_systUp->SetName( outPrefix+"curve_WJets_SystUp" );
  fit_wjj_systDown->SetName( outPrefix+"curve_WJets_SystDown" );
  fit_systUp->SetName( outPrefix+"curve_fitTotal_SystUp" );
  fit_systDown->SetName( outPrefix+"curve_fitTotal_SystDown" );

  
  f.cd();
  data->Write();
  fit->Write();
  fit_wjj->Write();
  fit_diboson->Write();
  fit_Top->Write();
  fit_QCD->Write();
  fit_Zjets->Write();
  fit_wjj_systUp->Write();
  fit_wjj_systDown->Write();
  fit_systUp->Write();
  fit_systDown->Write();

  f.Close();
  delete fitFile;
  delete systFileUp;
  delete systFileDown;
}
Beispiel #5
0
void makeplot(){

    
    gStyle->SetOptStat(0);
    TFile * file_1 = TFile::Open("CorrelationPlotsPerugia0PtDstarfromB5To8_ptAssall1.0to99.0_DeltaEta10.root");//file->ls();
    
    TCanvas * c = (TCanvas*)file_1->Get("cDeltaPhi");
    TH1D * h_Perugia0 = (TH1D*)c->FindObject("hCorrDeltaPhi");
    h_Perugia0->SetName("h_Perugia0");
    
    
    TFile * file_2 = TFile::Open("CorrelationPlotsPerugia2010PtDstarfromB5To8_ptAssall1.0to99.0_DeltaEta10.root");//file->ls();
    
    c = (TCanvas*)file_2->Get("cDeltaPhi");
    TH1D * h_Perugia2010 = (TH1D*)c->FindObject("hCorrDeltaPhi");
    h_Perugia2010->SetName("h_Perugia2010");
    
    
    TFile * file_3 = TFile::Open("CorrelationPlotsPerugia2011PtDstarfromB5To8_ptAssall1.0to99.0_DeltaEta10.root");//file->ls();
    
    c = (TCanvas*)file_3->Get("cDeltaPhi");
    TH1D * h_Perugia2011 = (TH1D*)c->FindObject("hCorrDeltaPhi");
    h_Perugia2011->SetName("h_Perugia2011");
    
    
    TPaveText * PaveText = new TPaveText(0.5,0.55,0.8,0.85,"NDC");
    PaveText->SetBorderSize(0);
    PaveText->SetFillColor(0);
    PaveText->SetName("pave");
    PaveText->AddText("THIS THESIS");
    PaveText->AddText(" ");
    PaveText->AddText("Comparison of Pythia templates, pp #sqrt{s} = 7 TeV");
    PaveText->AddText(" ");
    PaveText->AddText("(B #rightarrow D*^{+}) - charged particle correlations");
    
    
    
    h_Perugia0->SetMarkerStyle(20); h_Perugia2010->SetMarkerStyle(20); h_Perugia2011->SetMarkerStyle(20);
    h_Perugia0->SetMarkerColor(1); h_Perugia2010->SetMarkerColor(2); h_Perugia2011->SetMarkerColor(4);
    h_Perugia0->SetLineColor(1); h_Perugia2010->SetLineColor(2); h_Perugia2011->SetLineColor(4);
    
    
    
    TCanvas * c = new TCanvas("c","c",0,0,1000,1000);
    c->cd();
    h_Perugia0->SetTitle(";#Delta#varphi;#frac{1}{N_{D}}#frac{dN}{d#Delta#varphi}");
    h_Perugia0->GetYaxis()->SetRangeUser(0,4);
    h_Perugia0->Draw("ep");
    h_Perugia2010->Draw("sameep");
    h_Perugia2011->Draw("sameep");
    
    TLegend * legend = new TLegend(0.1,0.6,0.4,0.85);
    //  TLegend * legend = new TLegend(0.1, 1.2*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin()),0.4, 1.6*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin()));
    legend->SetFillColor(0);
    legend->SetTextSize(0.02);
    legend->AddEntry(h_Perugia0,"Pythia, Perugia 0 tune","lep");
    legend->AddEntry(h_Perugia2010,"Pythia, Perugia 2010 tune","lep");
    legend->AddEntry(h_Perugia2011,"Pythia, Perugia 2011 tune","lep");
    
    legend->Draw("same");
    PaveText->Draw("same");
    
    
    return;
    c->SaveAs("templates_pp.png");
   
}
void grabDataSubtractedHistograms() {
  TFile f("Histograms_Mjj_data_and_template.root", "update");


  TFile* fitFile = new TFile( plots_dir + "/mJJ-combined-fit.root", "read");
  TCanvas* fitCan = (TCanvas*) fitFile->Get( "mJJ-combined-fit" );
  RooHist* data = (RooHist*) fitCan->FindObject( "h_data" );
  RooCurve* fit_total = (RooCurve*) fitCan->FindObject( "h_total" );
  RooCurve* fit_diboson = (RooCurve*) fitCan->FindObject( "h_diboson" );
  RooCurve* fit_Wjets = (RooCurve*) fitCan->FindObject( "h_Wjets" );

  RooCurve* fit_Top = (RooCurve*) fitCan->FindObject( "h_Top" );
  RooCurve* fit_QCD = (RooCurve*) fitCan->FindObject( "h_QCD" );
  RooCurve* fit_Zjets = (RooCurve*) fitCan->FindObject( "h_Zjets" );
//   RooCurve* fit_Ztautau = (RooCurve*) fitCan->FindObject( "h_Ztautau" );

  TFile* subtrFile = new TFile( plots_dir + "/mJJ-combined-fit-subtracted.root", "read");
  TCanvas* subtrCan = (TCanvas*) subtrFile->Get( "mJJ-combined-fit-subtracted" );
  RooHist* subtrHist = (RooHist*) subtrCan->FindObject( "resid_h_data_h_Background" );
  RooCurve* Diboson = (RooCurve*) subtrCan->FindObject( "h_diboson" );



//   TFile* fitFile1 = new TFile( plots_dir + "/mJJ-mu-fit.root", "read");
//   TCanvas* fitCan1 = (TCanvas*) fitFile1->Get( "mJJ-mu-fit" );
//   RooHist* data1 = (RooHist*) fitCan1->FindObject( "h_data" );
//   RooCurve* fit1 = (RooCurve*) fitCan1->FindObject( "h_total" );

//   TFile* subtrFile1 = new TFile( plots_dir + "/mJJ-mu-fit-subtracted.root", "read");
//   TCanvas* subtrCan1 = (TCanvas*) subtrFile1->Get( "mJJ-mu-fit-subtracted" );
//   RooHist* subtrHist1 = (RooHist*) subtrCan1->FindObject( "resid_h_data_h_Background" );
//   RooCurve* Diboson1 = (RooCurve*) subtrCan1->FindObject( "h_diboson" );



//   TFile* fitFile2 = new TFile( plots_dir + "/mJJ-ele-fit.root", "read");
//   TCanvas* fitCan2 = (TCanvas*) fitFile2->Get( "mJJ-ele-fit" );
//   RooHist* data2 = (RooHist*) fitCan2->FindObject( "h_data" );
//   RooCurve* fit2 = (RooCurve*) fitCan2->FindObject( "h_total" );

//   TFile* subtrFile2 = new TFile( plots_dir + "/mJJ-ele-fit-subtracted.root", "read");
//   TCanvas* subtrCan2 = (TCanvas*) subtrFile2->Get( "mJJ-ele-fit-subtracted" );
//   RooHist* subtrHist2 = (RooHist*) subtrCan2->FindObject( "resid_h_data_h_Background" );
//   RooCurve* Diboson2 = (RooCurve*) subtrCan2->FindObject( "h_diboson" );


  // --------- Now save everything in the output file -------
 f.cd();
 data->Write("hist_data");
 fit_total->Write("fit_total");
 fit_diboson->Write("fit_diboson");
 fit_Wjets->Write("fit_Wjets");
 fit_Top->Write("fit_Top");
 fit_QCD->Write("fit_QCD");
 fit_Zjets->Write("fit_Zjets");
//  fit_Ztautau->Write("fit_Ztautau");

 subtrHist->Write("hist_data_subtracted");
 Diboson->Write("curve_diboson");

//  data1->Write("hist_data_muon");
//  fit1->Write("curve_fit_muon");
//  subtrHist1->Write("hist_data_subtracted_muon");
//  Diboson1->Write("curve_diboson_muon");

//  data2->Write("hist_data_electron");
//  fit2->Write("curve_fit_electron");
//  subtrHist2->Write("hist_data_subtracted_electron");
//  Diboson2->Write("curve_diboson_electron");

 f.Close();
}
Beispiel #7
0
void plotSyst(){

   TFile* fsmeared = new TFile("plots20131010/plotsWenu.root");

   TFile* fcent = new TFile("plots20131010/plotsWenu_nosmear.root");
   TFile* fup = new TFile("plots20131010/plotsWenu_nosmear_up.root");
   TFile* fdown = new TFile("plots20131010/plotsWenu_nosmear_down.root");

   TFile* fout = new TFile("plots20131010/plotsWenuJEC.root","RECREATE");
   fout->cd();

   // loop through objects in file
   TIter nextkey(fcent->GetListOfKeys());
   TKey *key;
   while( (key = (TKey*)nextkey()) ){
      string name = key->GetName();
      string classname = key->GetClassName();

      cout << "Adding " << classname << " " << name << endl;
      if( classname.compare("TCanvas") != 0 ) continue;
      if( name.compare("pchi2_old") == 0 ) continue;

      // get canvases
      TCanvas* cmet = (TCanvas*)fcent->Get( name.c_str() );
      TCanvas* cmet_up = (TCanvas*)fup->Get( name.c_str() );
      TCanvas* cmet_down = (TCanvas*)fdown->Get( name.c_str() );
      TCanvas* cmet_smeared = (TCanvas*)fsmeared->Get( name.c_str() );

      bool containsratio = cmet->GetListOfPrimitives()->Contains("pad2");
      if( !containsratio ) continue;
      string objclass = cmet->FindObject( (name+"_MC").c_str() )->ClassName();
      if( objclass.compare("TH1D") != 0 ) continue;

      // get histograms
      TH1D* hmet_mc = (TH1D*)cmet->FindObject( (name+"_MC").c_str() );
      TH1D* hmet_data = (TH1D*)cmet->FindObject( (name+"_Data").c_str() );
      TH1D* hmet_mc_up = (TH1D*)cmet_up->FindObject( (name+"_MC").c_str() );
      TH1D* hmet_mc_down = (TH1D*)cmet_down->FindObject( (name+"_MC").c_str() );
      TH1D* hmet_mc_smeared = (TH1D*)cmet_smeared->FindObject( (name+"_MC").c_str() );

      TH1D* hmetratio = (TH1D*)cmet->FindObject("hratio");
      TH1D* hmetratio_up = (TH1D*)cmet_up->FindObject("hratio");
      TH1D* hmetratio_down = (TH1D*)cmet_down->FindObject("hratio");
      TH1D* hmetratio_smeared = (TH1D*)cmet_smeared->FindObject("hratio");

      // compute error bands
      TGraphAsymmErrors* gmet = new TGraphAsymmErrors();
      for(int i=1; i <= hmet_mc->GetNbinsX(); i++){

         double maxvar = max(max(hmet_mc_up->GetBinContent(i),hmet_mc_down->GetBinContent(i)),
               hmet_mc->GetBinContent(i));
         double minvar = min(min(hmet_mc_up->GetBinContent(i),hmet_mc_down->GetBinContent(i)),
               hmet_mc->GetBinContent(i));
         double ehigh = maxvar - hmet_mc->GetBinContent(i);
         double elow = hmet_mc->GetBinContent(i) - minvar;
         double w = hmet_mc->GetBinWidth(i)/2;

         gmet->SetPoint(i-1, hmet_mc_smeared->GetBinCenter(i), hmet_mc_smeared->GetBinContent(i));
         gmet->SetPointError(i-1, w, w, elow, ehigh);

      }

      TGraphAsymmErrors* gmetratio = new TGraphAsymmErrors();
      for(int i=1; i <= hmetratio->GetNbinsX(); i++){

         double maxvar = max(max(hmetratio_up->GetBinContent(i),hmetratio_down->GetBinContent(i)),
               hmetratio->GetBinContent(i));
         double minvar = min(min(hmetratio_up->GetBinContent(i),hmetratio_down->GetBinContent(i)),
               hmetratio->GetBinContent(i));
         double ehigh = maxvar - hmetratio->GetBinContent(i);
         double elow = hmetratio->GetBinContent(i) - minvar;

         gmetratio->SetPoint(i-1,
               hmetratio_smeared->GetBinCenter(i), 1.0/*hmetratio_smeared->GetBinContent(i)*/);
         gmetratio->SetPointError(i-1, 0, 0, elow, ehigh);

      }

      // add bands to plot, print to file
      TPad* p1 = (TPad*)cmet_smeared->FindObject("pad1");
      p1->cd();
      gmet->SetFillColor(17);
      gmet->SetFillStyle(3001);
      gmet->Draw("2");
      hmet_data->Draw("same");

      TH1D* hmc_error = (TH1D*)cmet_smeared->FindObject( "histMCerror" );
      p1->GetListOfPrimitives()->Remove(hmc_error);

      // legend
      TLegend *leg = (TLegend*)cmet_smeared->FindObject("TPave");
      leg->AddEntry(gmet, "uncertainties", "f");
      leg->Draw();

      TPad* p2 = (TPad*)cmet_smeared->FindObject("pad2");
      p2->cd();
      gmetratio->SetFillColor(17);
      gmetratio->SetFillStyle(3001);
      gmetratio->Draw("3");
      hmetratio_smeared->Draw("same");

      cmet_smeared->cd();
      cmet_smeared->Write();

   }

   return;
}