コード例 #1
0
ファイル: BasePlot.C プロジェクト: HuguesBrun/WWAnalysis
void BasePlot::THStackAxisFonts(THStack* h, TString  coordinate, TString  title) {
    TAxis* axis = NULL;

    if (coordinate.Contains("x")) axis = h->GetHistogram()->GetXaxis();
    if (coordinate.Contains("y")) axis = h->GetHistogram()->GetYaxis();

    AxisFonts(axis, coordinate, title);
}
コード例 #2
0
ファイル: drawScaleFactors.C プロジェクト: piedraj/usercode
//------------------------------------------------------------------------------
// TH2FAxisFonts
//------------------------------------------------------------------------------
void TH2FAxisFonts(TH2F*   h,
		   TString coordinate,
		   TString title)
{
  TAxis* axis = NULL;

  if (coordinate.Contains("x")) axis = h->GetXaxis();
  if (coordinate.Contains("y")) axis = h->GetYaxis();

  AxisFonts(axis, title);
}
コード例 #3
0
ファイル: drawFigure4a.C プロジェクト: ltikvica/WZanalysis
void drawFigure4a(TString var="Njets") 
{
  gInterpreter->ExecuteMacro("GoodStyle.C");
  gROOT->LoadMacro("tdrstyle.C");                                                                                                                           
  setTDRStyle();    

  TString variable = "p_{T,max}^{#font[12]{l}}";
  std::ostringstream filename, madname;
  filename<<"rootfiles/all_unfolding_"<<var<<".root";
  TFile* file = new TFile(filename.str().c_str(), "read");
  madname<<"hGenXs"<<var<<"_1";
  std::cout<<madname.str().c_str()<<std::endl;
  TH1F* xsValue          = (TH1F*)(file->Get("hComb_diff")->Clone("xsValue"));
  TH1F* xsValue_Madgraph = (TH1F*)(file->Get(madname.str().c_str())->Clone("xsValue_Madgraph"));
  TH1F* xsValue_MCnlo    = (TH1F*)(file->Get("mcfm_tot")->Clone("xsValue_MCnlo"));

  // Set the data errors- I don't need this because I already have complete error in my plot
  //----------------------------------------------------------------------------
  
  // Data cosmetics
  //----------------------------------------------------------------------------
  xsValue->SetLineWidth(1);
  xsValue->SetMarkerSize(_msize);
  xsValue->SetMarkerStyle(kFullCircle);
  xsValue->SetMarkerColor(kBlack);
  xsValue->SetLineColor(kBlack);
  xsValue->SetFillStyle(1001);
  xsValue->SetFillColor(kWhite);
  // Madgraph cosmetics
  //----------------------------------------------------------------------------
  xsValue_Madgraph->SetFillColor(kOrange);
  //xsValue_Madgraph->SetFillColor(kWhite);
  xsValue_Madgraph->SetFillStyle(1001);
  xsValue_Madgraph->SetLineColor(kOrange+7);
  xsValue_Madgraph->SetLineWidth(1);
  xsValue_Madgraph->SetMarkerColor(kOrange+7);
  xsValue_Madgraph->SetMarkerSize(_msize);
  xsValue_Madgraph->SetMarkerStyle(21);


  // MCNLO cosmetics
  //----------------------------------------------------------------------------
  xsValue_MCnlo->SetFillColor(kAzure-9);
   //xsValue_MCnlo->SetFillColor(kWhite);
  xsValue_MCnlo->SetFillStyle(1001);
  xsValue_MCnlo->SetLineColor(kAzure);
  xsValue_MCnlo->SetLineWidth(1);
  xsValue_MCnlo->SetMarkerColor(kAzure);
  xsValue_MCnlo->SetMarkerSize(_msize);
  //  xsValue_MCnlo->SetMarkerStyle(21);
  xsValue_MCnlo->SetMarkerStyle(24);

  //  TCanvas * c1=new TCanvas("c1", "c1");
  
//xsValue_MCnlo->Draw("pey0");
   

  // Set the canvas and pads
  //----------------------------------------------------------------------------
  TCanvas* canvas = new TCanvas("wwxs", "wwxs", 600, 600);
  //  TCanvas* canvas = new TCanvas("wwxs", "wwxs"); 

  //defalut
  //TCanvas* canvas = new TCanvas("wwxs", "wwxs", 600, 850);
  //  TPad* pad1 = new TPad("pad1", "pad1", 0, 0.55, 1, 1.000);
  //TPad* pad2 = new TPad("pad2", "pad2", 0, 0.39, 1, 0.552);
  //TPad* pad3 = new TPad("pad3", "pad3", 0, 0.23, 1, 0.392);

  TPad* pad1 = new TPad("pad1", "pad1", 0, 0.49, 1, 1.000);
  TPad* pad2 = new TPad("pad2", "pad2", 0, 0.33, 1, 0.492);
  TPad* pad3 = new TPad("pad3", "pad3", 0, 0, 1, 0.332);
  
  pad1->SetTopMargin(0.09);
  pad2->SetTopMargin(0);
  pad3->SetTopMargin(0);

  pad1->SetBottomMargin(0);
  pad2->SetBottomMargin(0);
  //  pad3->SetBottomMargin(0.15);
  pad3->SetBottomMargin(0.45);

  pad1->SetLeftMargin(0.16);
  pad2->SetLeftMargin(0.16);
  pad3->SetLeftMargin(0.16);

  pad1->SetRightMargin(0.06);
  pad2->SetRightMargin(0.06);
  pad3->SetRightMargin(0.06);



  // pad1
  //----------------------------------------------------------------------------
  pad1->Draw();
  pad1->cd();
  pad1->SetLogy();


  // Draw
  //----------------------------------------------------------------------------
  AxisFonts(xsValue->GetXaxis(), variable + " (GeV)");
  if (var=="Zpt")
    AxisFonts(xsValue->GetYaxis(), "d#sigma(WZ#rightarrow3l#nu)/dp_{T}^{Z}");
  if (var=="LeadingJetPt")
    AxisFonts(xsValue->GetYaxis(), "d#sigma(WZ#rightarrow3l#nu)/dp_{T}^{LeadingJet}");
  
  //TH1F* hpowError = (TH1F*)xsValue_Powheg->Clone();
  //  TH1F* hmadError = (TH1F*)xsValue_Madgraph->Clone();
  //TH1F* hmcError  = (TH1F*)xsValue_MCnlo->Clone();

  xsValue         ->Draw("pe");
  xsValue_Madgraph->Draw("p,same");
  xsValue_MCnlo   ->Draw("p,same");

  xsValue->SetMinimum(1.1e-4);

 
  // Legend
  //----------------------------------------------------------------------------
  DrawLegend(0.718, 0.80, xsValue,   " Data",     "lp");
  DrawLegend(0.718, 0.74, xsValue_Madgraph, " Madgraph", "flp");  
  DrawLegend(0.718, 0.68, xsValue_MCnlo,  " MCFM",   "flp");


  // Draw text 
  //----------------------------------------------------------------------------
  DrawLatex(_cmsTextFont,   0.173, 0.935, 0.065, 11, "CMS");
  DrawLatex(_extraTextFont, 0.268, 0.935, 0.035, 11, "Preliminary");
  DrawLatex(_lumiTextFont,  0.940, 0.935, 0.050, 31, "19.6 fb^{-1} (8 TeV)");


  // Prepare the ratios
  //----------------------------------------------------------------------------
  TH1F* ratio_mad    = xsValue_Madgraph->Clone("ratio");
  TH1F* ratio_mcnlo  = xsValue_Madgraph->Clone("ratio");
  //  TH1F* ratio_mcnlo  = xsValue_MCnlo->Clone("ratio");
  TH1F* hratio_mad   = xsValue_Madgraph->Clone("ratio");
  TH1F* hratio_mcnlo = xsValue_MCnlo->Clone("ratio");
  TH1F* ratioErr     = xsValue->Clone("ratio");


  ratioErr->SetFillColor  (kGray+2);
  ratioErr->SetFillStyle  (   3004);
  ratioErr->SetLineColor  (kGray+2);
  ratioErr->SetMarkerColor(kGray+2);
  ratioErr->SetMarkerSize (      0);


  // Set the bin content
  //----------------------------------------------------------------------------
  for (UInt_t ibin=1; ibin<=ratio->GetNbinsX(); ibin++) {
   
    Double_t madValue = xsValue_Madgraph->GetBinContent(ibin);
    //Double_t madError = xsValue_Madgraph->GetBinError  (ibin);
   
    Double_t mcnloValue = xsValue_MCnlo->GetBinContent(ibin);
    //Double_t mcnloError = xsValue_MCnlo->GetBinError  (ibin);
   
    Double_t dataValue = xsValue->GetBinContent(ibin);
    
    Double_t dataError = xsValue->GetBinError(ibin);
   
    Double_t ratioValue_mad = (madValue > 0) ? madValue / dataValue : 0.0;
    //Double_t ratioError_mad = (madValue > 0) ? madError / dataValue : 0.0;
    Double_t ratioError_mad = madValue/pow(dataValue,2)*dataError;
    Double_t ratioValue_mcnlo = (mcnloValue > 0) ? mcnloValue / dataValue : 0.0;
    // Double_t ratioError_mcnlo = (mcnloValue > 0) ? mcnloError / dataValue : 0.0;
    Double_t ratioError_mcnlo = mcnloValue/pow(dataValue,2)*dataError;
   
    Double_t uncertaintyError = (dataValue > 0) ? dataError / dataValue : 0.0;
   
    ratio_mad ->SetBinContent(ibin, ratioValue_mad);
    hratio_mad->SetBinContent(ibin, ratioValue_mad);
    hratio_mad->SetBinError  (ibin, ratioError_mad);
   
    ratio_mcnlo ->SetBinContent(ibin, ratioValue_mcnlo);
    hratio_mcnlo->SetBinContent(ibin, ratioValue_mcnlo);
    hratio_mcnlo->SetBinError  (ibin, ratioError_mcnlo);
   
    ratioErr->SetBinContent(ibin, 1.0);
    ratioErr->SetBinError  (ibin, uncertaintyError);  //??? ovo nije bas jasno sto je
  }


  //  AxisFontsRatio(ratioErr->GetYaxis(), "y", "Theory / Data");
  //AxisFontsRatio(ratioErr->GetXaxis(), "x", variable + " (GeV)");
  AxisFontsRatio(ratio_mad->GetYaxis(), "y", "Theory / Data");
  //AxisFontsRatio(ratio_mad->GetXaxis(), "x", variable + " (GeV)");

  AxisFontsRatio(ratio_mcnlo->GetYaxis(), "y", "Theory / Data");

  if (var=="Zpt")
    AxisFontsRatio(ratio_mcnlo->GetXaxis(), "x", "p_{T}^{Z} (GeV)");
  if (var=="LeadingJetPt")
    AxisFontsRatio(ratio_mcnlo->GetXaxis(), "x", "p_{T}^{LeadingJet} (GeV)");
  ratio_mcnlo->SetFillColor(kAzure-9);
   //xsValue_MCnlo->SetFillColor(kWhite);
  ratio_mcnlo->SetFillStyle(1001);
  ratio_mcnlo->SetLineColor(kAzure);
  ratio_mcnlo->SetLineWidth(1);
  ratio_mcnlo->SetMarkerColor(kAzure);
  ratio_mcnlo->SetMarkerSize(_msize);
  //  xsValue_MCnlo->SetMarkerStyle(21);
  ratio_mcnlo->SetMarkerStyle(24);

  // Draw pad2
  //----------------------------------------------------------------------------
  canvas->cd();
  pad2->Draw();
  pad2->cd();
  
  //ratioErr  ->Draw("e2");
  
  ratio_mad ->Draw("pz");
  hratio_mad->Draw("e2,same");
  ratio_mad ->Draw("p, same");
  ratio_mad->GetYaxis()->SetRangeUser(0.1, 2.3);  

  pad2->Modified();
  
  DrawLatex(43, 0.2, 0.79, 15.0, 11, "Madgraph+Pythia normalized to #sigma_{NLO}");
  

  // Draw pad3
  //----------------------------------------------------------------------------
  canvas->cd();
  pad3->Draw();
  pad3->cd();
  std::cout<<"Default option: "<<ratio_mcnlo->GetOption()<<std::endl;
  
  //ratioErr    ->Draw("e2");
  ratio_mcnlo->Draw("pz");
  hratio_mcnlo->Draw("e2,same");

  ratio_mcnlo ->Draw("pz, same");
  ratio_mcnlo->GetYaxis()->SetRangeUser(0.1, 2.3);  
  //ratio_mcnlo->GetYaxis()->SetRangeUser(0.0, 0.5);  
  
  pad3->Modified();

  DrawLatex(43, 0.2, 0.89, 15.0, 11, "MCFM");
  
    

  // Save
  //----------------------------------------------------------------------------
  pad1->cd(); pad1->GetFrame()->DrawClone();
  pad2->cd(); pad2->GetFrame()->DrawClone();
  pad3->cd(); pad3->GetFrame()->DrawClone();

  canvas->cd();

  std::ostringstream saveName, saveName2;
  saveName  << "pdf/unfolded_"<<var<<".pdf";
  saveName2 << "png/unfolded_"<<var<<".png";
  canvas->SaveAs(saveName.str().c_str());
  canvas->SaveAs(saveName2.str().c_str());
}
コード例 #4
0
ファイル: Unfolded.C プロジェクト: latinos/LatinoPlotTools
void 
Unfolded  (
     bool drawRatio = 1,
     int differential = 0,
     int nsel = 0,
     int ReBin = 1,
     TString XTitle = "p_{T,max}^{l} (GeV)",
     TString units = "", 
     TString plotName = "data/XSLeadingPt_AN.root", 
     TString outputName = "WW_LeadingPt_final",
     bool isLogY = false,
     double lumi = 19.5
 )
{  
 
 gInterpreter->ExecuteMacro("GoodStyle.C");
 
 std::cout << "reading " << plotName << std::endl ;
 TFile* file = new TFile(plotName, "read");
 
 //---- prepare the object that is making the plots
 //---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 
 std::cout << "setting up the plot object " << std::endl ;

 
 TH1F* xsValue = (TH1F*) xsValue->Clone();
 TH1F* xsValue_Powheg =  (TH1F*) xsValue_Powheg->Clone();
 TH1F* xsValue_Madgraph = (TH1F*) xsValue_Madgraph->Clone();
 TH1F* xsValue_MCnlo = (TH1F*) xsValue_MCnlo->Clone();
 TH1F* systHisto = (TH1F*) systHisto->Clone();
 
 
 TCanvas* canvas ;
 TPad *pad1, *pad2, *pad3, *pad4;
 
 if (drawRatio) {
  canvas = new TCanvas("wwxs", "wwxs", 600, 850);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  canvas->SetHighLightColor(2);
  canvas->Range(0,0,1,1);
  canvas->SetFillColor(0);
  canvas->SetBorderMode(0);
  canvas->SetBorderSize(2);
  canvas->SetTickx(1);
  canvas->SetTicky(1);
  canvas->SetLeftMargin(0.16);
  canvas->SetRightMargin(0.02);
  canvas->SetTopMargin(0.05);
  canvas->SetBottomMargin(0.13);
  canvas->SetFrameFillStyle(0);
  canvas->SetFrameBorderMode(0);
  
  
  
  pad1 = new TPad("pad1", "pad1",0.01,0.55,0.99,0.99);
  pad1->Draw();
  pad1->cd();
  pad1->Range(-147.2973,-5.811723,960.8108,2.535539);
  pad1->SetFillColor(0);
  pad1->SetBorderMode(0);
  pad1->SetBorderSize(2);
  pad1->SetLogy();
  pad1->SetTickx(1);
  pad1->SetTicky(1);
  pad1->SetLeftMargin(0.16);
  pad1->SetBottomMargin(0);
  pad1->SetFrameFillStyle(0);
  pad1->SetFrameBorderMode(0);
  pad1->SetFrameFillStyle(0);
  pad1->SetFrameBorderMode(0);
   
 }
 else { 
  canvas = new TCanvas("wwxs", "wwxs", 550, 550);
 }
 
 if (drawRatio) pad1->cd();
 
 std::cout << " now plot " << std::endl;
 
 //Plot Data
 xsValue->SetLineWidth(1);
 xsValue->SetMarkerSize(1.0);
 
 int NBins = xsValue->GetNbinsX();
 
 for(int i=1; i <NBins; i++) {
  
  float err_stat = xsValue->GetBinError(i);
  float err_syst = systHisto->GetBinError(i);
  float err_total = sqrt(err_stat*err_stat + err_syst*err_syst);
  
  xsValue->SetBinError(i, err_total);
 }
 
 
 //-- Plot Powheg
 
 TH1F *hpowError  = (TH1F*) xsValue_Powheg->Clone();
 
 xsValue_Powheg->SetMarkerColor(kGreen+2);
 xsValue_Powheg->SetLineWidth(1);
 xsValue_Powheg->SetLineColor(kGreen+2);
 xsValue_Powheg->SetMarkerStyle(22);
 xsValue_Powheg->SetMarkerSize(1.2);
 
 
 hpowError->SetLineWidth(0);
 hpowError->SetMarkerSize (      0);  
 hpowError->SetFillColor  (kGreen-7);
 
 
 //-- Plot Madgraph
 
 TH1F *hmadError  = (TH1F*) xsValue_Madgraph->Clone();
 
 xsValue_Madgraph->SetMarkerColor(kMagenta);
 xsValue_Madgraph->SetLineWidth(1);
 xsValue_Madgraph->SetLineStyle(1);
 xsValue_Madgraph->SetMarkerStyle(21);
 xsValue_Madgraph->SetMarkerSize(1.0);
 
 hmadError->SetLineWidth(0);
 hmadError->SetMarkerSize (      0); 
 hmadError->SetFillColor  (kMagenta-10);
 
 
 //-- Plot MCNLO
 
 TH1F *hmcError  = (TH1F*) xsValue_MCnlo->Clone();
 
 xsValue_MCnlo->SetMarkerColor(kRed);
 xsValue_MCnlo->SetLineColor(kRed);
 xsValue_MCnlo->SetLineWidth(1);
 xsValue_MCnlo->SetLineStyle(1);
 xsValue_MCnlo->SetMarkerStyle(24);
 xsValue_MCnlo->SetMarkerSize(1.0);
 
 hmcError->SetLineWidth(0);
 hmcError->SetMarkerSize (      0); 
 hmcError->SetFillColor  (kOrange);
 
 
 
 
 //-- Plot Data
 
 xsValue->SetMarkerStyle(kFullCircle);
 
 if (differential == 0) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} d#sigma(WW#rightarrow#mu#nue#nu + < 1 jet)/dp_{T,max}^{l}");
 if (differential == 1) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} d#sigma(WW#rightarrow#mu#nue#nu + < 1 jet)/dp_{T}(ll)}");
 if (differential == 2) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} d#sigma(WW#rightarrow#mu#nue#nu + < 1 jet)/dm_{#font[12]{ll}}");
 if (differential == 3) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} d#sigma(WW#rightarrow#mu#nue#nu + < 1 jet)/d#Delta#phi_{ll}");

 
//  if (differential == 0) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} #frac{d#sigma}{dp_{T,max}^{l}}");
//  if (differential == 1) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} #frac{d#sigma}{dp_{T}(ll)}");
//  if (differential == 2) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} #frac{d#sigma}{dm_{#font[12]{ll}}}");
//  if (differential == 3) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} #frac{d#sigma}{d#Delta#phi_{ll}}");

 AxisFonts (xsValue->GetXaxis(), XTitle);
 
 
 
 xsValue->Draw("p");
 hmadError->Draw("e2,same"); 
 xsValue_Madgraph->Draw("pe1,same");
 hmcError->Draw("e2,same");
 xsValue_MCnlo->Draw("pe1,same");
 hpowError->Draw("e2,same");
 xsValue_Powheg->Draw("pe1,same");
 //systHisto->Draw("e2, same");
 xsValue->Draw("pe1,same");
 
 // Legend
 //----------------------------------------------------------------------------
 
 DrawLegend (0.65, 0.85, xsValue, "Data", "P");
 DrawLegend (0.65, 0.80, hpowError,   "", "F");
 DrawLegend (0.65, 0.80, xsValue_Madgraph,   "Madgraph", "PL");  
 DrawLegend (0.65, 0.75, hmadError,   "", "F");
 DrawLegend (0.65, 0.75, xsValue_MCnlo,   "MCNLO", "LP");
 DrawLegend (0.65, 0.70, hmcError,   "", "F");
 DrawLegend (0.65, 0.70, xsValue_Powheg,   "Powheg", "PL");
 
 canvas->GetFrame()->DrawClone();
 
 
 
 // Draw text 
 //----------------------------------------------------------------------------
 TLatex *   tex = new TLatex(0.17,0.96,"CMS             #sqrt{s} = 8 TeV             19.4 fb^{-1}");
 tex->SetNDC();
 tex->SetTextAlign(12);
 tex->SetTextFont(42);
 tex->SetTextSize(0.07);
 tex->SetLineWidth(2);
 tex->Draw();
 
//  TLatex * CMSLabel = new TLatex (0.18, 0.96, "#bf{CMS}");
//  CMSLabel->SetNDC ();
//  CMSLabel->SetTextAlign (10);
//  CMSLabel->SetTextFont (42);
//  CMSLabel->SetTextSize (_tsize);
//  CMSLabel->Draw ("same") ;
//  
//  
//  TLatex * _lumiLabel = new TLatex (0.95, 0.96, "19.4fb#lower[0.3]{^{-1}} (8 TeV)");
//  _lumiLabel->SetNDC ();
//  _lumiLabel->SetTextAlign (30);
//  _lumiLabel->SetTextFont (42);
//  _lumiLabel->SetTextSize (_tsize);
//  _lumiLabel->Draw ("same") ;
 
 
 // Draw also ratio
 //----------------------------------------------------------------------------
 if (drawRatio) {
  
  //---- prepare the distributions

  TH1F* ratio_pow       = xsValue_Powheg->Clone("ratio");
  TH1F* ratio_mad       = xsValue_Madgraph->Clone("ratio");
  TH1F* ratio_mcnlo     = xsValue_MCnlo->Clone("ratio");
  TH1F* hratio_pow      = xsValue_Powheg->Clone("ratio");
  TH1F* hratio_mad      = xsValue_Madgraph->Clone("ratio");
  TH1F* hratio_mcnlo    = xsValue_MCnlo->Clone("ratio");
  TH1F* ratioErr        = xsValue->Clone("ratio");
  
  
  for (UInt_t ibin=1; ibin<=ratio->GetNbinsX(); ibin++) {
   
   Double_t powValue = xsValue_Powheg->GetBinContent(ibin);
   Double_t powError = xsValue_Powheg->GetBinError  (ibin);
   
   Double_t madValue = xsValue_Madgraph->GetBinContent(ibin);
   Double_t madError = xsValue_Madgraph->GetBinError  (ibin);
   
   Double_t mcnloValue = xsValue_MCnlo->GetBinContent(ibin);
   Double_t mcnloError = xsValue_MCnlo->GetBinError  (ibin);
   
   Double_t dataValue = xsValue->GetBinContent(ibin);
   Double_t statError = xsValue->GetBinError  (ibin);
   Double_t systError = systHisto->GetBinError(ibin);
   
   Double_t dataError = systError;
   
   Double_t ratioValue_pow           = (powValue > 0) ? powValue/dataValue : 0.0;
   Double_t ratioError_pow           = (powValue > 0) ? powError / dataValue : 0.0;
   
   Double_t ratioValue_mad           = (madValue > 0) ? madValue/dataValue : 0.0;
   Double_t ratioError_mad           = (madValue > 0) ? madError/dataValue : 0.0;
   
   Double_t ratioValue_mcnlo         = (mcnloValue > 0) ? mcnloValue/dataValue : 0.0;
   Double_t ratioError_mcnlo         = (mcnloValue > 0) ? mcnloError/dataValue : 0.0;
   
   Double_t uncertaintyError         = (dataValue > 0) ? dataError/dataValue : 0.0;
   
   
   //dataError/dataValue 
   ratio_pow->SetBinContent(ibin, ratioValue_pow);
   hratio_pow->SetBinContent(ibin, ratioValue_pow);
   hratio_pow->SetBinError  (ibin, ratioError_pow);
   
   ratio_mad->SetBinContent(ibin, ratioValue_mad);
   hratio_mad->SetBinContent(ibin, ratioValue_mad);
   hratio_mad->SetBinError  (ibin, ratioError_mad);
   
   ratio_mcnlo->SetBinContent(ibin, ratioValue_mcnlo);
   hratio_mcnlo->SetBinContent(ibin, ratioValue_mcnlo);
   hratio_mcnlo->SetBinError  (ibin, ratioError_mcnlo);
   
   ratioErr->SetBinContent(ibin, 1.0);
   ratioErr->SetBinError  (ibin, uncertaintyError);
  }
  
  ratioErr->SetTitle("");

  ratioErr->SetFillColor  (kGray+2);
  ratioErr->SetFillStyle  (   3004);
//   ratioErr->SetFillStyle  (   3345);
  ratioErr->SetLineColor  (kGray+2);
  ratioErr->SetMarkerColor(kGray+2);
  ratioErr->SetMarkerSize (      0);
  
  
  
  //---- now draw
  
  canvas->cd();
  pad2 = new TPad("pad2", "pad2",0.01,0.39,0.99,0.55);
  pad2->Draw();
  pad2->cd();
  pad2->Range(-147.2973,0.2,960.8108,1.8);
  pad2->SetFillColor(0);
  pad2->SetBorderMode(0);
  pad2->SetBorderSize(2);
  pad2->SetTickx(1);
  pad2->SetTicky(1);
  pad2->SetLeftMargin(0.16);
  pad2->SetTopMargin(0);
  pad2->SetBottomMargin(0);
  pad2->SetFrameFillStyle(0);
  pad2->SetFrameBorderMode(0);
  pad2->SetFrameFillStyle(0);
  pad2->SetFrameBorderMode(0);
  
  
  ratioErr  ->Draw("e2");
  ratio_mad      ->SetLineColor(kMagenta);
  ratio_mad      ->SetMarkerSize(1.0);
  ratio_mad      ->SetLineWidth(1);
  ratio_mad      ->SetMarkerStyle(21);
  hratio_mad     ->SetLineWidth(0);
  hratio_mad     ->SetMarkerSize (      0);  
  hratio_mad     ->SetFillColor  (kMagenta-10);
  hratio_mad     ->SetFillStyle  (1001);
  hratio_mad     ->Draw("e2,same");
  ratio_mad      ->Draw("e1p,same");
  AxisFontsRatio (ratioErr->GetYaxis(), "y", "Theory/data");
  AxisFontsRatio (ratioErr->GetXaxis(), "x", XTitle);
  ratioErr->Draw("sameaxis");
  ratioErr->GetYaxis()->SetRangeUser(0.4, 1.6);  
  pad2->Modified();
  
  TLatex* tex_mad = new TLatex(0.2,0.1,"Madgraph+Pythia, normalized to #sigma_{NNLO}");
  tex_mad->SetNDC();
  tex_mad->SetTextAlign(12);
  tex_mad->SetTextFont(42);
  tex_mad->SetTextSize(0.1);
  tex_mad->SetLineWidth(2);
  tex_mad->Draw();
  
  
  
  canvas->cd();
  pad3 = new TPad("pad3", "pad3",0.01,0.23,0.99,0.39);
  pad3->Draw();
  pad3->cd();
  pad3->Range(-147.2973,0.2,960.8108,1.8);
  pad3->SetFillColor(0);
  pad3->SetBorderMode(0);
  pad3->SetBorderSize(2);
  pad3->SetTickx(1);
  pad3->SetTicky(1);
  pad3->SetLeftMargin(0.16);
  pad3->SetTopMargin(0);
  pad3->SetBottomMargin(0);
  pad3->SetFrameFillStyle(0);
  pad3->SetFrameBorderMode(0);
  pad3->SetFrameFillStyle(0);
  pad3->SetFrameBorderMode(0);
  
  ratioErr  ->Draw("e2");
  ratio_mcnlo     ->SetLineColor(kRed);
  ratio_mcnlo     ->SetMarkerSize(1.0);
  ratio_mcnlo      ->SetLineWidth(1);
  ratio_mcnlo     ->SetMarkerStyle(24);
  hratio_mcnlo    ->SetLineWidth(0);
  hratio_mcnlo    ->SetMarkerSize (      0);  
  hratio_mcnlo    ->SetFillColor  (kOrange);
  hratio_mcnlo     ->SetFillStyle  (1001);
  hratio_mcnlo    ->Draw("e2,same");
  ratio_mcnlo     ->Draw("ep,same");
//   AxisFontsRatio (ratioErr->GetYaxis(), "y", "Theory/data");
//   AxisFontsRatio (ratioErr->GetXaxis(), "x", XTitle);
  ratioErr->Draw("sameaxis");
  ratioErr->GetYaxis()->SetRangeUser(0.4, 1.6);  
  pad3->Modified();
  
  TLatex* tex_mcnlo = new TLatex(0.2,0.1,"MC@NLO+Herwig, normalized to #sigma_{NNLO}");
  tex_mcnlo->SetNDC();
  tex_mcnlo->SetTextAlign(12);
  tex_mcnlo->SetTextFont(42);
  tex_mcnlo->SetTextSize(0.1);
  tex_mcnlo->SetLineWidth(2);
  tex_mcnlo->Draw();
  
  
  
  
  canvas->cd();
  pad4 = new TPad("pad4", "pad4",0.01,0.01,0.99,0.23);
  pad4->Draw();
  pad4->cd();
  pad4->Range(-147.2973,-0.4857143,960.8108,1.8);
  pad4->SetFillColor(0);
  pad4->SetBorderMode(0);
  pad4->SetBorderSize(2);
  pad4->SetTickx(1);
  pad4->SetTicky(1);
  pad4->SetLeftMargin(0.16);
  pad4->SetTopMargin(0);
  pad4->SetBottomMargin(0.3);
  pad4->SetFrameFillStyle(0);
  pad4->SetFrameBorderMode(0);
  pad4->SetFrameFillStyle(0);
  pad4->SetFrameBorderMode(0);
  
  ratioErr  ->Draw("e2");
  ratio_pow      ->SetLineColor(kGreen+2);
  ratio_pow      ->SetMarkerSize(1.2);
  ratio_pow      ->SetLineWidth(1);
  ratio_pow      ->SetMarkerStyle(22);
  hratio_pow     ->SetLineWidth(0);
  hratio_pow     ->SetMarkerSize (      0);  
  hratio_pow     ->SetFillColor  (kGreen-7);
  hratio_pow     ->SetFillStyle  (1001);
  hratio_pow     ->Draw("e2,same");
  ratio_pow      ->Draw("e1p,same");
//   AxisFontsRatio (ratioErr->GetYaxis(), "y", "Theory/data", 1);
//   AxisFontsRatio (ratioErr->GetXaxis(), "x", XTitle);
  ratioErr->Draw("sameaxis");
  ratioErr->GetYaxis()->SetRangeUser(0.4, 1.6);  
  pad4->Modified();
  
  TLatex* tex_pow = new TLatex(0.2,0.39,"Powheg+Pythia, normalized to #sigma_{NNLO}");
  tex_pow->SetNDC();
  tex_pow->SetTextAlign(12);
  tex_pow->SetTextFont(42);
  tex_pow->SetTextSize(0.1);
  tex_pow->SetLineWidth(2);
  tex_pow->Draw();
  
  canvas->cd();
  
  
 }
 
 
}
コード例 #5
0
ファイル: drawFigures4and5.C プロジェクト: piedraj/usercode
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// drawFigures4and5
//
// Zpt
// LeadingJetPt
// Njets
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void drawFigures4and5(TString var = "Zpt") 
{
  gSystem->mkdir("pdf", kTRUE);
  gSystem->mkdir("png", kTRUE);

  gInterpreter->ExecuteMacro("WZPaperStyle.C");

  Bool_t drawMcfm = (var.EqualTo("Zpt")) ? true : false;

  TString variable;
  TString xtitle;
  TString ytitle;

  if (var.EqualTo("Zpt"))          variable = "Z";
  if (var.EqualTo("LeadingJetPt")) variable = "leading jet";
  if (var.EqualTo("Njets"))        variable = "N_{jets}";

  if (var.EqualTo("Njets"))
    {
      xtitle = variable;
      ytitle = "d#sigma(WZ#rightarrow3l#nu)/d" + variable + " (pb)";
    }
  else
    {
      xtitle = "p_{T}^{" + variable + "} (GeV)";
      ytitle = "d#sigma(WZ#rightarrow3l#nu)/dp_{T}^{" + variable + "} (pb/GeV)";
    }

  TFile* file = new TFile("rootfiles/all_unfolding_" + var + ".root", "read");

  TH1D* xsValue          = (TH1D*)file->Get("hComb_diff");
  TH1D* xsValue_Madgraph = (TH1D*)file->Get("hGenXs" + var + "_1");
  TH1D* xsValue_MCnlo;

  if (drawMcfm) xsValue_MCnlo = (TH1D*)file->Get("mcfm_tot");


  // Data cosmetics
  //----------------------------------------------------------------------------
  xsValue->SetFillColor  (     kWhite);
  xsValue->SetFillStyle  (       1001);
  xsValue->SetLineColor  (     kBlack);
  xsValue->SetLineWidth  (          1);
  xsValue->SetMarkerColor(     kBlack);
  xsValue->SetMarkerSize (     _msize);
  xsValue->SetMarkerStyle(kFullCircle);


  // Madgraph cosmetics
  //----------------------------------------------------------------------------
  xsValue_Madgraph->SetFillColor  (    kOrange);
  xsValue_Madgraph->SetFillStyle  (       1001);
  xsValue_Madgraph->SetLineColor  (  kOrange+7);
  xsValue_Madgraph->SetLineWidth  (          1);
  xsValue_Madgraph->SetMarkerColor(  kOrange+7);
  xsValue_Madgraph->SetMarkerSize (     _msize);
  xsValue_Madgraph->SetMarkerStyle(kFullSquare);


  // MCNLO cosmetics
  //----------------------------------------------------------------------------
  if (drawMcfm)
    {
      xsValue_MCnlo->SetFillColor  (   kAzure-9);
      xsValue_MCnlo->SetFillStyle  (       1001);
      xsValue_MCnlo->SetLineColor  (     kAzure);
      xsValue_MCnlo->SetLineWidth  (          1);
      xsValue_MCnlo->SetMarkerColor(     kAzure);
      xsValue_MCnlo->SetMarkerSize (     _msize);
      xsValue_MCnlo->SetMarkerStyle(kOpenCircle);
    }


  // Set the canvas and pads
  //----------------------------------------------------------------------------
  TCanvas* canvas = new TCanvas(var, var);

  TPad* pad1;
  TPad* pad2;
  TPad* pad3;

  if (drawMcfm)
    {
      pad1 = new TPad("pad1" + var, "pad1" + var, 0, 0.49, 1, 1.000);
      pad2 = new TPad("pad2" + var, "pad2" + var, 0, 0.33, 1, 0.492);
      pad3 = new TPad("pad3" + var, "pad3" + var, 0, 0.00, 1, 0.332);
  
      pad1->SetTopMargin(0.09);
      pad2->SetTopMargin(0);
      pad3->SetTopMargin(0);

      pad1->SetBottomMargin(0);
      pad2->SetBottomMargin(0);
      pad3->SetBottomMargin(0.45);

      pad1->SetLeftMargin(0.16);
      pad2->SetLeftMargin(0.16);
      pad3->SetLeftMargin(0.16);
      
      pad1->SetRightMargin(0.06);
      pad2->SetRightMargin(0.06);
      pad3->SetRightMargin(0.06);
    }
  else
    {
      pad1 = new TPad("pad1" + var, "pad1" + var, 0, 0.33, 1, 1.000);
      pad2 = new TPad("pad2" + var, "pad2" + var, 0, 0.00, 1, 0.332);
  
      pad1->SetTopMargin(0.09);
      pad2->SetTopMargin(0);

      pad1->SetBottomMargin(0);
      pad2->SetBottomMargin(0.45);

      pad1->SetLeftMargin(0.16);
      pad2->SetLeftMargin(0.16);

      pad1->SetRightMargin(0.06);
      pad2->SetRightMargin(0.06);
    }


  // Draw pad1
  //----------------------------------------------------------------------------
  pad1->Draw();
  pad1->cd();
  pad1->SetLogy();

  AxisFonts(xsValue->GetXaxis(), xtitle);
  AxisFonts(xsValue->GetYaxis(), ytitle);
  
  xsValue->SetTitle("");

  xsValue->Draw("pe");

  xsValue_Madgraph->Draw("p,same");

  if (drawMcfm) xsValue_MCnlo->Draw("p,same");

  xsValue->Draw("pe,same");

  if (var.EqualTo("Zpt"))          xsValue->SetMinimum(1.1e-4);
  if (var.EqualTo("LeadingJetPt")) xsValue->SetMinimum(5e-4);
  if (var.EqualTo("Njets"))        xsValue->SetMinimum(2e-2);

  DrawLatex(_cmsTextFont,   0.173, 0.935, 0.065, 11, "CMS");
  DrawLatex(_lumiTextFont,  0.940, 0.935, 0.050, 31, "19.6 fb^{-1} (8 TeV)");


  // Legend
  //----------------------------------------------------------------------------
  if (drawMcfm)
    {
      DrawLegend(0.72, 0.80, xsValue,          " Data",     "lp");
      DrawLegend(0.72, 0.73, xsValue_Madgraph, " MadGraph", "flp");
      DrawLegend(0.72, 0.66, xsValue_MCnlo,    " MCFM",     "flp");
    }
  else
    {
      DrawLegend(0.68, 0.81, xsValue,          " Data",     "lp");
      DrawLegend(0.68, 0.74, xsValue_Madgraph, " MadGraph", "flp");
    }


  // Prepare the ratios
  //----------------------------------------------------------------------------
  TH1D* ratio_mad  = (TH1D*)xsValue_Madgraph->Clone("ratio_mad");
  TH1D* hratio_mad = (TH1D*)xsValue_Madgraph->Clone("hratio_mad");

  TH1D* ratio_mcnlo;
  TH1D* hratio_mcnlo;

  if (drawMcfm)
    {
      ratio_mcnlo  = (TH1D*)xsValue_MCnlo->Clone("ratio_mcnlo");
      hratio_mcnlo = (TH1D*)xsValue_MCnlo->Clone("hratio_mcnlo");
    }


  // Set the bin content
  //----------------------------------------------------------------------------
  for (UInt_t ibin=1; ibin<=ratio_mad->GetNbinsX(); ibin++) {
   
    Double_t madValue   = xsValue_Madgraph->GetBinContent(ibin);
    Double_t dataValue  = xsValue->GetBinContent(ibin);
    Double_t dataError  = xsValue->GetBinError(ibin);
   
    Double_t ratioValue_mad = (madValue > 0) ? madValue / dataValue : 0.0;
    Double_t ratioError_mad = madValue / pow(dataValue,2)*dataError;
   
    ratio_mad->SetBinContent(ibin, ratioValue_mad);
    ratio_mad->SetBinError  (ibin, 1e-9);

    hratio_mad->SetBinContent(ibin, ratioValue_mad);
    hratio_mad->SetBinError  (ibin, ratioError_mad);
   

    if (drawMcfm)
      {
	Double_t mcnloValue       = xsValue_MCnlo->GetBinContent(ibin);
	Double_t ratioValue_mcnlo = (mcnloValue > 0) ? mcnloValue / dataValue : 0.0;
	Double_t ratioError_mcnlo = mcnloValue / pow(dataValue,2)*dataError;

	ratio_mcnlo->SetBinContent(ibin, ratioValue_mcnlo);
	ratio_mcnlo->SetBinError  (ibin, 1e-9);

	hratio_mcnlo->SetBinContent(ibin, ratioValue_mcnlo);
	hratio_mcnlo->SetBinError  (ibin, ratioError_mcnlo);
      }
  }


  // Draw pad2
  //----------------------------------------------------------------------------
  AxisFontsRatio(ratio_mad->GetYaxis(), "y", "#frac{Theory}{Data}");
  AxisFontsRatio(ratio_mad->GetXaxis(), "x", xtitle);

  canvas->cd();
  pad2->Draw();
  pad2->cd();

  ratio_mad->SetTitle("");
  
  ratio_mad ->Draw("ep");
  hratio_mad->Draw("e2,same");
  ratio_mad ->Draw("ep,same");

  TLine* line2 = new TLine(ratio_mad->GetXaxis()->GetXmin(), 1.0, ratio_mad->GetXaxis()->GetXmax(), 1.0);
  line2->SetLineStyle(3);
  line2->Draw("same");

  ratio_mad->GetYaxis()->SetRangeUser(0.01, 2.3);  

  if (drawMcfm) DrawLatex(43, 0.20, 0.785, 15.0, 11, "MadGraph+Pythia normalized to #sigma_{NLO}");
  else          DrawLatex(43, 0.19, 0.845, 15.0, 11, "MadGraph+Pythia normalized to #sigma_{NLO}");


  // Draw pad3
  //----------------------------------------------------------------------------
  if (drawMcfm)
    {
      AxisFontsRatio(ratio_mcnlo->GetYaxis(), "y", "#frac{Theory}{Data}");
      AxisFontsRatio(ratio_mcnlo->GetXaxis(), "x", xtitle);

      canvas->cd();
      pad3->Draw();
      pad3->cd();
  
      ratio_mcnlo->SetTitle("");

      ratio_mcnlo ->Draw("ep");
      hratio_mcnlo->Draw("e2,same");
      ratio_mcnlo ->Draw("ep,same");

      TLine* line3 = new TLine(ratio_mcnlo->GetXaxis()->GetXmin(), 1.0, ratio_mcnlo->GetXaxis()->GetXmax(), 1.0);
      line3->SetLineStyle(3);
      line3->Draw("same");

      ratio_mcnlo->GetYaxis()->SetRangeUser(0.1, 2.3);  

      pad3->Modified();

      DrawLatex(43, 0.2, 0.885, 15.0, 11, "MCFM");
    }


  // Save
  //----------------------------------------------------------------------------
  pad1->cd();
  pad1->RedrawAxis();
  pad1->GetFrame()->DrawClone();
  
  pad2->cd();
  pad2->RedrawAxis();
  pad2->GetFrame()->DrawClone();

  if (drawMcfm)
    {
      pad3->cd();
      pad3->RedrawAxis();
      pad3->GetFrame()->DrawClone();
    }

  canvas->cd();
  canvas->Update();

  canvas->SaveAs("pdf/unfolded_" + var + ".pdf");
  canvas->SaveAs("png/unfolded_" + var + ".png");
}
コード例 #6
0
ファイル: finalPlot.C プロジェクト: calderona/RooUnfold
void finalPlot(bool drawRatio = 1, int differential = 0, int nsel = 0, int ReBin = 1, TString XTitle = "p_{T,max}^{l} (GeV)", TString units = "", TString plotName = "XSLeadingPt_AN.root", TString outputName = "WW_LeadingPt_final", bool isLogY = false,  double lumi = 19.5) {

  gInterpreter->ExecuteMacro("GoodStyle.C");

  TFile* file = new TFile(plotName.Data(), "read");
 
  TH1F* xsValue = (TH1F*) xsValue->Clone();
  TH1F* xsValue_Powheg =  (TH1F*) xsValue_Powheg->Clone();
  TH1F* xsValue_Madgraph = (TH1F*) xsValue_Madgraph->Clone();
  TH1F* xsValue_MCnlo = (TH1F*) xsValue_MCnlo->Clone();
  TH1F* systHisto = (TH1F*) systHisto->Clone();

 
  TCanvas* canvas ;
  TPad *pad1, *pad2;
 
   if (drawRatio) {
    canvas = new TCanvas("wwxs", "wwxs", 550, 1.2*600);
    
    pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1);
    pad1->SetTopMargin   (0.05);
    pad1->SetBottomMargin(0.02);
    pad1->Draw();
    
    pad2 = new TPad("pad2", "pad2", 0, 0, 1, 0.31); 
    pad2->SetTopMargin   (0.08);
    pad2->SetBottomMargin(0.35);
    pad2->Draw();
  
  }       else { 
    canvas = new TCanvas("wwxs", "wwxs", 550, 550);
    }

   if (drawRatio) pad1->cd();


   //Plot Data
   xsValue->SetLineWidth(1);
   xsValue->SetMarkerSize(1.0);

   int NBins = xsValue->GetNbinsX();

   for(int i=1; i <NBins; i++) {

     float err_stat = xsValue->GetBinError(i);
     float err_syst = systHisto->GetBinError(i);
     float err_total = sqrt(err_stat*err_stat + err_syst*err_syst);

     xsValue->SetBinError(i, err_total);
   }


  //-- Plot Powheg

   TH1F *hpowError  = (TH1F*) xsValue_Powheg->Clone();

   xsValue_Powheg->SetMarkerColor(kAzure-3);
   xsValue_Powheg->SetLineWidth(1);
   xsValue_Powheg->SetLineColor(kBlue+2);
   xsValue_Powheg->SetMarkerStyle(22);
   xsValue_Powheg->SetMarkerSize(1.2);
  

   hpowError->SetLineWidth(0);
   hpowError->SetMarkerSize (      0);  
   hpowError->SetFillColor  (kAzure-9);


  //-- Plot Madgraph

  TH1F *hmadError  = (TH1F*) xsValue_Madgraph->Clone();

  xsValue_Madgraph->SetMarkerColor(kPink-9);
  xsValue_Madgraph->SetLineWidth(1);
  xsValue_Madgraph->SetLineStyle(1);
  xsValue_Madgraph->SetMarkerStyle(21);
  xsValue_Madgraph->SetMarkerSize(1.0);

  hmadError->SetLineWidth(0);
  hmadError->SetMarkerSize (      0); 
  hmadError->SetFillColor  (kPink+1);


  //-- Plot MCNLO

  TH1F *hmcError  = (TH1F*) xsValue_MCnlo->Clone();

  xsValue_MCnlo->SetMarkerColor(kRed);
  xsValue_MCnlo->SetLineColor(kRed);
  xsValue_MCnlo->SetLineWidth(1);
  xsValue_MCnlo->SetLineStyle(1);
  xsValue_MCnlo->SetMarkerStyle(24);
  xsValue_MCnlo->SetMarkerSize(1.0);

  hmcError->SetLineWidth(0);
  hmcError->SetMarkerSize (      0); 
  hmcError->SetFillColor  (kOrange);
 



  //-- Plot Data

  xsValue->SetMarkerStyle(kFullCircle);
      
  if (differential == 0) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} #frac{d#sigma}{dp_{T,max}^{l}}");
  if (differential == 1) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} #frac{d#sigma}{dp_{T}(ll)}");
  if (differential == 2) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} #frac{d#sigma}{dm_{#font[12]{ll}}}");
  if (differential == 3) AxisFonts (xsValue->GetYaxis(), "#frac{1}{#sigma} #frac{d#sigma}{d#Delta#phi_{ll}}");

  AxisFonts (xsValue->GetXaxis(), XTitle);
 



  xsValue->Draw("p");
  hmadError->Draw("e2,same"); 
  xsValue_Madgraph->Draw("pe1,same");
  hmcError->Draw("e2,same");
  xsValue_MCnlo->Draw("pe1,same");
  hpowError->Draw("e2,same");
  xsValue_Powheg->Draw("pe1,same");
  //systHisto->Draw("e2, same");
  xsValue->Draw("pe1,same");
      
  // Legend
  //----------------------------------------------------------------------------
  
  DrawLegend (0.65, 0.85, xsValue, "Data", "P");
  DrawLegend (0.65, 0.80, hpowError,   "", "F");
  DrawLegend (0.65, 0.80, xsValue_Powheg,   "Powheg", "PL");
  DrawLegend (0.65, 0.75, hmadError,   "", "F");
  DrawLegend (0.65, 0.75, xsValue_Madgraph,   "Madgraph", "PL");  
  DrawLegend (0.65, 0.70, hmcError,   "", "F");
  DrawLegend (0.65, 0.70, xsValue_MCnlo,   "MCNLO", "LP");

  canvas->GetFrame()->DrawClone();



  // Draw text 
  //----------------------------------------------------------------------------
  TLatex * CMSLabel = new TLatex (0.18, 0.96, "#bf{CMS}");
  CMSLabel->SetNDC ();
  CMSLabel->SetTextAlign (10);
  CMSLabel->SetTextFont (42);
  CMSLabel->SetTextSize (_tsize);
  CMSLabel->Draw ("same") ;


  TLatex * _lumiLabel = new TLatex (0.95, 0.96, "19.4fb#lower[0.3]{^{-1}} (8 TeV)");
  _lumiLabel->SetNDC ();
  _lumiLabel->SetTextAlign (30);
  _lumiLabel->SetTextFont (42);
  _lumiLabel->SetTextSize (_tsize);
  _lumiLabel->Draw ("same") ;


  // Draw also ratio
  //----------------------------------------------------------------------------
  if (drawRatio) {

     pad2->cd();
	
    TH1F* ratio_pow       = xsValue_Powheg->Clone("ratio");
    TH1F* ratio_mad       = xsValue_Madgraph->Clone("ratio");
    TH1F* ratio_mcnlo     = xsValue_MCnlo->Clone("ratio");
    TH1F* hratio_pow       = xsValue_Powheg->Clone("ratio");
    TH1F* hratio_mad       = xsValue_Madgraph->Clone("ratio");
    TH1F* hratio_mcnlo     = xsValue_MCnlo->Clone("ratio");
    TH1F* ratioErr        = xsValue->Clone("ratio");
    

    for (UInt_t ibin=1; ibin<=ratio->GetNbinsX(); ibin++) {

      Double_t powValue = xsValue_Powheg->GetBinContent(ibin);
      Double_t powError = xsValue_Powheg->GetBinError  (ibin);
      
      Double_t madValue = xsValue_Madgraph->GetBinContent(ibin);
      Double_t madError = xsValue_Madgraph->GetBinError  (ibin);
      
      Double_t mcnloValue = xsValue_MCnlo->GetBinContent(ibin);
      Double_t mcnloError = xsValue_MCnlo->GetBinError  (ibin);
      
      Double_t dataValue = xsValue->GetBinContent(ibin);
      Double_t statError = xsValue->GetBinError  (ibin);
      Double_t systError = systHisto->GetBinError(ibin);
      
      Double_t dataError = systError;
      
      Double_t ratioValue_pow           = (powValue > 0) ? powValue/dataValue : 0.0;
      Double_t ratioError_pow           = (powValue > 0) ? powError / dataValue : 0.0;
      
      Double_t ratioValue_mad           = (madValue > 0) ? madValue/dataValue : 0.0;
      Double_t ratioError_mad           = (madValue > 0) ? madError/dataValue : 0.0;
      
      Double_t ratioValue_mcnlo         = (mcnloValue > 0) ? mcnloValue/dataValue : 0.0;
      Double_t ratioError_mcnlo         = (mcnloValue > 0) ? mcnloError/dataValue : 0.0;
      
      Double_t uncertaintyError         = (dataValue > 0) ? dataError/dataValue : 0.0;
      

      //dataError/dataValue 
      ratio_pow->SetBinContent(ibin, ratioValue_pow);
      hratio_pow->SetBinContent(ibin, ratioValue_pow);
      hratio_pow->SetBinError  (ibin, ratioError_pow);
      
      ratio_mad->SetBinContent(ibin, ratioValue_mad);
      hratio_mad->SetBinContent(ibin, ratioValue_mad);
      hratio_mad->SetBinError  (ibin, ratioError_mad);
      
      ratio_mcnlo->SetBinContent(ibin, ratioValue_mcnlo);
      hratio_mcnlo->SetBinContent(ibin, ratioValue_mcnlo);
      hratio_mcnlo->SetBinError  (ibin, ratioError_mcnlo);
      
      ratioErr->SetBinContent(ibin, 1.0);
      ratioErr->SetBinError  (ibin, uncertaintyError);
    }

    ratioErr->SetTitle("");
    ratioErr  ->Draw("e2");
    
   
    
    ratio_mad      ->SetLineColor(kPink-9);
    ratio_mad      ->SetMarkerSize(1.0);
    ratio_mad      ->SetLineWidth(1);
    ratio_mad      ->SetMarkerStyle(21);
    hratio_mad     ->SetLineWidth(0);
    hratio_mad     ->SetMarkerSize (      0);  
    hratio_mad     ->SetFillColor  (kPink+1);
    hratio_mad     ->SetFillStyle  (1001);
    hratio_mad     ->Draw("e2,same");
    ratio_mad      ->Draw("e1p,same");
    
    
    ratio_mcnlo     ->SetLineColor(kRed);
    ratio_mcnlo     ->SetMarkerSize(1.0);
    ratio_mcnlo      ->SetLineWidth(1);
    ratio_mcnlo     ->SetMarkerStyle(24);
    hratio_mcnlo    ->SetLineWidth(0);
    hratio_mcnlo    ->SetMarkerSize (      0);  
    hratio_mcnlo    ->SetFillColor  (kOrange);
    hratio_mcnlo     ->SetFillStyle  (1001);
    hratio_mcnlo    ->Draw("e2,same");
    ratio_mcnlo     ->Draw("ep,same");

    ratio_pow      ->SetLineColor(kAzure-3);
    ratio_pow      ->SetMarkerSize(1.2);
    ratio_pow      ->SetLineWidth(1);
    ratio_pow      ->SetMarkerStyle(22);
    hratio_pow     ->SetLineWidth(0);
    hratio_pow     ->SetMarkerSize (      0);  
    hratio_pow     ->SetFillColor  (kAzure-9);
    hratio_pow     ->SetFillStyle  (1001);
    hratio_pow     ->Draw("e2,same");
    ratio_pow      ->Draw("e1p,same");
    
  
    
    ratioErr->SetFillColor  (kGray+2);
    ratioErr->SetFillStyle  (   3345);
    ratioErr->SetLineColor  (kGray+2);
    ratioErr->SetMarkerColor(kGray+2);
    ratioErr->SetMarkerSize (      0);

    ratioErr->Draw("sameaxis");

    ratioErr->GetYaxis()->SetRangeUser(0.4, 1.6);

   
    AxisFontsRatio (ratioErr->GetYaxis(), "y", "MC/data");
    AxisFontsRatio (ratioErr->GetXaxis(), "x", XTitle);

  }
      

}
コード例 #7
0
ファイル: DivPlot.C プロジェクト: HuguesBrun/WWAnalysis
        void Draw(TCanvas *c1, const int &rebin=1, const bool &showErr=true) {

            gStyle->SetOptStat(0);
            c1->cd();
            c1->Clear();

            TPad *pad1;
            pad1 = new TPad("pad1","pad1",0,1-0.614609572,1,1);
            pad1->SetTopMargin(0.0983606557);
            pad1->SetBottomMargin(0.025);
            pad1->Draw();
            pad1->cd();

            RebinHists(rebin);
            THStack *hstack = GetStack(c1->GetLogy());
            TH1F *signal = GetSignalHist();
            TH1F *data   = GetDataHist();

            if(c1->GetLogy()) gPad->SetLogy();
            hstack->GetHistogram()->SetLabelSize(0.00,"X");
            hstack->GetHistogram()->SetLabelSize(0.06,"Y");
            hstack->GetHistogram()->SetTitleSize(0.06,"XY");
            hstack->Draw("hist");
            if(signal && ! _stackSignal) signal->Draw("hist,same");
            if(data)     data->Draw("ep,same");
            DrawLabels();
            pad1->GetFrame()->DrawClone();


            TH1F *summed = GetSummedMCHist();

            TH1F *rdat = (TH1F*)data->Clone("rdat");   
            if(gROOT->FindObject("rref")) gROOT->FindObject("rref")->Delete();
            TH1F *rref = new TH1F("rref","rref",
                summed->GetNbinsX(),
                summed->GetBinLowEdge(1),
                summed->GetBinLowEdge(summed->GetNbinsX()+1)
            );
            for (int i = 1, n = rref->GetNbinsX(); i <= n+1; ++i) {
                rref->SetBinContent(i,summed->GetBinContent(i));
                rref->SetBinError(i,summed->GetBinError(i));
            }
            rref->SetTitle("");
            rref->SetLineWidth(0);
            rref->SetFillColor(kGray+1);
            rref->SetFillStyle(1001);
            double absmax = 0;
            for (int i = 0, n = rdat->GetNbinsX(); i <= n+1; ++i) {
                double scale = rref->GetBinContent(i);
                if (scale == 0) {
                    rdat->SetBinContent(i, 0);
                    rref->SetBinContent(i, 10000);
                    rdat->SetBinError(i, 0);
                    rref->SetBinError(i, 0);
                } else {
                    rdat->SetBinContent(i, rdat->GetBinContent(i)/scale);
                    rref->SetBinContent(i, rref->GetBinContent(i)/scale);
                    rdat->SetBinError(i, rdat->GetBinError(i)/scale);
                    rref->SetBinError(i, rref->GetBinError(i)/scale);
                    double mymax = TMath::Max(1.2*fabs(rdat->GetBinContent(i)-1)+1.4*rdat->GetBinError(i), 2.0*rref->GetBinError(i));
                    absmax = TMath::Max(mymax, absmax);
                }
            }

            c1->cd();
            TPad *pad2 = new TPad("pad2","pad2",0,0,1,1-0.614609572);
            pad2->SetTopMargin(0.0261437908);
            pad2->SetBottomMargin(0.392156863);
            pad2->Draw();
            pad2->cd();

            TLine *line = new TLine(rref->GetXaxis()->GetXmin(), 1.0, rref->GetXaxis()->GetXmax(), 1.0);
            line->SetLineColor(kBlack);
            line->SetLineWidth(1);
            line->SetLineStyle(1);

            if(showErr) {
                rref->GetYaxis()->SetRangeUser(TMath::Max(-1.,1.-absmax), TMath::Min(3.,absmax+1.));
                AxisFonts(rref->GetXaxis(), "x", hstack->GetXaxis()->GetTitle());
                rref->GetYaxis()->SetTitle("data/mc");
                rref->GetYaxis()->SetLabelSize(0.10);
                rref->GetYaxis()->SetTitleSize(0.10);
                rref->GetYaxis()->SetTitleOffset(0.85);
                rref->GetXaxis()->SetLabelSize(0.10);
                rref->GetXaxis()->SetTitleSize(0.10);
                rref->GetXaxis()->SetTitleOffset(1.5);
                rref->Draw("E2"); 
                rdat->SetMarkerStyle(20);
                rdat->Draw("E SAME p");
                line->Draw("SAME"); 
                c1->Update();
                pad2->GetFrame()->DrawClone();

            } else {
                rdat->GetYaxis()->SetRangeUser(TMath::Max(-1.,1.-absmax), TMath::Min(3.,absmax+1.));
                rdat->GetYaxis()->SetTitle("data/mc");
                rdat->GetYaxis()->SetLabelSize(0.10);
                rdat->GetYaxis()->SetTitleSize(0.10);
                rdat->GetYaxis()->SetTitleOffset(0.85);
                AxisFonts(rdat->GetXaxis(), "x", hstack->GetXaxis()->GetTitle());
                rdat->GetXaxis()->SetLabelSize(0.10);
                rdat->GetXaxis()->SetTitleSize(0.10);
                rdat->GetXaxis()->SetTitleOffset(1.5);
                rdat->SetTitle("");
                rdat->SetMarkerStyle(20);
                rdat->Draw("E p");
                line->Draw("SAME"); 
                c1->Update();
                pad2->GetFrame()->DrawClone();
            }

        }