void raaExpOpen_pt(const char* inputDir = "../macro_raa/outRoot", // the place where the input root files, with the histograms are
                   bool bSavePlots      = true,
                   bool bDrawCh         = true,
                   double xMax          = 30 // x-axis range limit (ALICE D has x-range maximum value at 36, CMS has it at 30)
                  )
{
  // set the style
  gSystem->mkdir(Form("./figs/png"), kTRUE);
  gSystem->mkdir(Form("./figs/pdf"), kTRUE);
  setTDRStyle();
  
  // read CMS graphs
  TFile *pgRaaCms_pt   = new TFile(Form("%s/makeRaa_pt.root",inputDir));
  // ##################### HIGH PT ############################
  TGraphErrors *pgCms     = (TGraphErrors *)pgRaaCms_pt->Get("gNonPrJpsi");
  TGraphErrors *pgCmsP    = (TGraphErrors *)pgRaaCms_pt->Get("gNonPrJpsiP");
  TGraphErrors *pgCmsSyst = (TGraphErrors *)pgRaaCms_pt->Get("gNonPrJpsiSyst");
  pgCmsSyst->SetFillColorAlpha(kOrange-9,0.5);
  pgCms->SetName("gNonPrJpsi");

  TBox *lumi = (TBox*)pgRaaCms_pt->Get("lumi");
  lumi->SetFillColor(kOrange-9);
  lumi->SetFillStyle(1001);
  lumi->SetX1(xMax-0.75); lumi->SetX2(xMax);
  TBox *lumi_lowpt = (TBox*)lumi->Clone("lumi_lowpt");
  lumi_lowpt->SetFillColor(kViolet-9);
  lumi_lowpt->SetFillStyle(1001);
  lumi_lowpt->SetX1(xMax-1.5); lumi_lowpt->SetX2(xMax-0.75);

  // ##################### LOW PT ############################
  TGraphErrors *pgCms_lowpt     = (TGraphErrors *)pgRaaCms_pt->Get("gNonPrJpsi_pt365y1624");
  TGraphErrors *pgCmsP_lowpt    = (TGraphErrors *)pgRaaCms_pt->Get("gNonPrJpsiP_pt365y1624");
  TGraphErrors *pgCmsSyst_lowpt = (TGraphErrors *)pgRaaCms_pt->Get("gNonPrJpsiSyst_pt365y1624");
  pgCmsSyst_lowpt->SetFillColorAlpha(kViolet-9,0.5);
  pgCms_lowpt->SetName("gNonPrJpsi_pt365y1624");

  //-------------------------------------------------------------------- 
  // *********** CMS Charged particle RAA
  TGraphAsymmErrors *p8165_d5x1y1 = new TGraphAsymmErrors(p8165_d5x1y1_numpoints, p8165_d5x1y1_xval, p8165_d5x1y1_yval, p8165_d5x1y1_xerrminus, p8165_d5x1y1_xerrplus, p8165_d5x1y1_ystatminus, p8165_d5x1y1_ystatplus);
  TGraphAsymmErrors *p8165_d5x1y1_syst = new TGraphAsymmErrors(p8165_d5x1y1_numpoints, p8165_d5x1y1_xval, p8165_d5x1y1_yval, p8165_d5x1y1_xerrminus, p8165_d5x1y1_xerrplus, p8165_d5x1y1_yerrminus, p8165_d5x1y1_yerrplus);
  p8165_d5x1y1->SetName("cms_ch_raa");
  // X-axis errors will be discarded
  for (int i=0; i<p8165_d5x1y1_numpoints; i++) {
    p8165_d5x1y1->SetPointEXlow(i,0);
    p8165_d5x1y1->SetPointEXhigh(i,0);
    p8165_d5x1y1_syst->SetPointEXlow(i,0.5);
    p8165_d5x1y1_syst->SetPointEXhigh(i,0.5);
  }
   
  // *********** ALICE D RAA vs. pT
  TGraphAsymmErrors *p9059_d15x1y1 = new TGraphAsymmErrors(p9059_d15x1y1_numpoints, p9059_d15x1y1_xval, p9059_d15x1y1_yval, p9059_d15x1y1_xerrminus, p9059_d15x1y1_xerrplus, p9059_d15x1y1_yerrminus, p9059_d15x1y1_yerrplus);
  TGraphAsymmErrors *p9059_d15x1y1_syst = new TGraphAsymmErrors(p9059_d15x1y1_numpoints, p9059_d15x1y1_xval, p9059_d15x1y1_yval, p9059_d15x1y1_xerrminus, p9059_d15x1y1_xerrplus, p9059_d15x1y1_yerrminus, p9059_d15x1y1_yerrplus);
  p9059_d15x1y1->SetName("alice_d_raa");
  // X-axis errors will be discarded
  for (int i=0; i<p9059_d15x1y1_numpoints; i++) {
    p9059_d15x1y1->SetPointEXlow(i,0);
    p9059_d15x1y1->SetPointEXhigh(i,0);
    p9059_d15x1y1_syst->SetPointEXlow(i,0.5);
    p9059_d15x1y1_syst->SetPointEXhigh(i,0.5);
    if (xMax<=30 && (i+1)==p9059_d15x1y1_numpoints) {
      double x,y;
      p9059_d15x1y1->GetPoint(i,x,y);
      p9059_d15x1y1->SetPoint(i,x+5,y);
      p9059_d15x1y1_syst->GetPoint(i,x,y);
      p9059_d15x1y1_syst->SetPoint(i,x+5,y);
    }
  }

  // Style for graphs
  p9059_d15x1y1->SetMarkerStyle(kOpenSquare);
  p9059_d15x1y1->SetMarkerSize(1.3);
  p9059_d15x1y1->SetMarkerColor(kBlack);
  p9059_d15x1y1->SetLineColor(kBlack);
  p9059_d15x1y1_syst->SetFillColorAlpha(kGray+1,0.5);

  p8165_d5x1y1->SetMarkerStyle(20);
  p8165_d5x1y1->SetMarkerSize(1.3);
  p8165_d5x1y1->SetMarkerColor(kTeal+3);
  p8165_d5x1y1->SetLineColor(kTeal+4);
  p8165_d5x1y1_syst->SetFillColorAlpha(kTeal-1,0.5);



  //---------------------------------------------------------
  TLine *line = new TLine(0.,1,xMax,1);
  line->SetLineStyle(1);
  line->SetLineWidth(1);

  TCanvas *pc = new TCanvas("pc","pc");

  TF1 *f4 = new TF1("f4","1",0,xMax);
  f4->SetLineWidth(1);
  f4->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  f4->GetYaxis()->SetTitle("R_{AA}");
  f4->GetXaxis()->SetRangeUser(0.0,xMax);
  f4->GetYaxis()->SetRangeUser(0.0,1.5);
  f4->GetXaxis()->CenterTitle(kTRUE);
 
  f4->Draw();
  lumi->Draw();
  lumi_lowpt->Draw();
  pc->Update();

  pgCmsSyst->Draw("2"); // for drawing x-axis

  p9059_d15x1y1_syst->Draw("2");
  if (bDrawCh) p8165_d5x1y1_syst->Draw("2");
  p9059_d15x1y1->Draw("pz");
  if (bDrawCh) p8165_d5x1y1->Draw("pz");

  pgCmsSyst->Draw("2");
  pgCmsP->Draw("P");
  pgCms->Draw("P");
  pgCmsSyst_lowpt->Draw("2");
  pgCmsP_lowpt->Draw("P");
  pgCms_lowpt->Draw("P");

  // additional info
  CMS_lumi(pc,12003000,0);

  TLegend *leg_cent = new TLegend(0.28,0.77,0.86,0.89,NULL,"brNDC"); // at top center
  leg_cent->SetMargin(0.12);
  leg_cent->SetBorderSize(0);
  leg_cent->SetTextFont(132);
  leg_cent->SetTextSize(0.03);
  leg_cent->SetLineColor(1);
  leg_cent->SetLineStyle(1);
  leg_cent->SetLineWidth(1);
  leg_cent->SetFillColor(19);
  leg_cent->SetFillStyle(0);

  TLegendEntry *entry_cent;
  entry_cent=leg_cent->AddEntry("raab","Open beauty: Nonprompt J/#psi","");
  entry_cent->SetTextFont(132);
  entry_cent->SetTextSize(ltxSetTextSize3);
  entry_cent=leg_cent->AddEntry("gNonPrJpsi_pt365y1624", "1.6 < |y| < 2.4","p");
  entry_cent->SetTextFont(42);
  entry_cent->SetTextSize(entrySize);
  entry_cent=leg_cent->AddEntry("gNonPrJpsi", "|y| < 2.4","p");
  entry_cent->SetTextFont(42);
  entry_cent->SetTextSize(entrySize);

  TLegend *leg_ch = new TLegend(0.28,0.685,0.86,0.765,NULL,"brNDC");
  leg_ch->SetMargin(0.12);
  leg_ch->SetBorderSize(0);
  leg_ch->SetTextFont(132);
  leg_ch->SetTextSize(0.03);
  leg_ch->SetLineColor(1);
  leg_ch->SetLineStyle(1);
  leg_ch->SetLineWidth(1);
  leg_ch->SetFillColor(19);
  leg_ch->SetFillStyle(0);

  if (bDrawCh) {
    TLegendEntry *entry_ch;
    entry_ch=leg_ch->AddEntry("cms_ch","Charged hadron","");
    entry_ch->SetTextSize(ltxSetTextSize3);
    entry_ch->SetTextFont(132);
    entry_ch=leg_ch->AddEntry("cms_ch_raa","|#eta| < 1, Cent. 0-5%","p");
    entry_ch->SetTextSize(entrySize);
    entry_ch->SetTextFont(42);
  }
  
  TLegend *leg_alice;
  if (bDrawCh) {
    leg_alice = new TLegend(0.28,0.60,0.86,0.68,NULL,"brNDC");
  } else {
    leg_alice = new TLegend(0.28,0.685,0.86,0.765,NULL,"brNDC");
  }
  leg_alice->SetMargin(0.12);
  leg_alice->SetBorderSize(0);
  leg_alice->SetTextFont(132);
  leg_alice->SetTextSize(0.03);
  leg_alice->SetLineColor(1);
  leg_alice->SetLineStyle(1);
  leg_alice->SetLineWidth(1);
  leg_alice->SetFillColor(kWhite);
  leg_alice->SetFillStyle(1000);

  TLegendEntry *entry_alice;
  entry_alice=leg_alice->AddEntry("alice_d","Open charm: Prompt D (ALICE)","");
  entry_alice->SetTextSize(ltxSetTextSize3);
  entry_alice->SetTextFont(132);
  entry_alice=leg_alice->AddEntry("alice_d_raa","|y| < 0.5, Cent. 0-10%","p");
  entry_alice->SetTextSize(entrySize);
  entry_alice->SetTextFont(42);

  TLatex *lat = new TLatex();
  lat->SetNDC();
  lat->SetTextFont(42);
  lat->SetTextSize(ltxSetTextSize2);
  if (bDrawCh) lat->DrawLatex(0.63,0.53,"Cent. 0-100%");
  else lat->DrawLatex(0.63,0.58,"Cent. 0-100%");

  line->Draw();
  leg_cent->Draw();
  if (bDrawCh) leg_ch->Draw();
  leg_alice->Draw();
  gPad->RedrawAxis();

  if(bSavePlots)
  {
    pc->SaveAs(Form("figs/pdf/raaExpOpen_pt_RaaCh%d.pdf",bDrawCh));
    pc->SaveAs(Form("figs/png/raaExpOpen_pt_RaaCh%d.png",bDrawCh));
  }
}
void plot_TauTemplate(string Elog="Elog431_",int icomp=0){

  //
  // icomp=0: only show own results
  //       1: show also Koushik's results
  //
  
  //
  ///////////////////////////////////////////////////////////////////////////////////////////
  ////Some cosmetic work for official documents. 
  gROOT->LoadMacro("tdrstyle.C");
  setTDRStyle();
  gStyle->SetPalette(1) ; // for better color output
  gROOT->LoadMacro("CMS_lumi.C");
 writeExtraText = true;       // if extra text
  extraText  = "         Supplementary";  // default extra text is "Preliminary"
  lumi_8TeV  = "19.1 fb^{-1}"; // default is "19.7 fb^{-1}"
  lumi_7TeV  = "4.9 fb^{-1}";  // default is "5.1 fb^{-1}"
  lumi_sqrtS = "13 TeV";       // used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string)

  int iPeriod = 0;    // 1=7TeV, 2=8TeV, 3=7+8TeV, 7=7+8+13TeV, 0=free form (uses lumi_sqrtS)
  // second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot
  // iPos=11 : top-left, left-aligned
  // iPos=33 : top-right, right-aligned
  // iPos=22 : center, centered
  // mode generally : 
  //   iPos = 10*(alignement 1/2/3) + position (1/2/3 = left/center/right)
  int iPos =0;
  
  
  
  char tempname[200];
  char tempname2[200];
  int W = 600;
  int H = 600;
  int H_ref = 600;
  int W_ref = 800;
  float T = 0.08*H_ref;
  float B = 0.12*H_ref;
  float L = 0.12*W_ref;
  float R = 0.04*W_ref;

  TCanvas* c1 = new TCanvas("name","name",10,10,W,H);
  c1->SetFillColor(0);
  c1->SetBorderMode(0);
  c1->SetFrameFillStyle(0);
  c1->SetFrameBorderMode(0);
  c1->SetLeftMargin( L/W );
  c1->SetRightMargin( R/W );
  c1->SetTopMargin( T/H );
  c1->SetBottomMargin( B/H );
  c1->SetTickx(0);
  c1->SetTicky(0);

  gStyle->SetOptStat(000000);
  
  Float_t legendX1 = .60; //.50;
  Float_t legendX2 = .90; //.70;
  Float_t legendY1 = .60; //.65;
  Float_t legendY2 = .90;
  TLegend* catLeg1 = new TLegend(legendX1,legendY1,legendX2,legendY2);
  catLeg1->SetTextSize(0.042);
  catLeg1->SetTextFont(42);
  catLeg1->SetFillColor(0);
  catLeg1->SetLineColor(0);
  catLeg1->SetBorderSize(0);

  //
  sprintf(tempname,"TauHad/Stack/%sHadTau_TauResponseTemplates_stacked.root",Elog.c_str());
  TFile *file_13TeV         = new TFile(tempname,"R"); 
  //TFile *file_13TeV_Koushik = new TFile("HadTau_TauResponseTemplates_PHYS14_13TeV.root","R"); 
  TFile *file_TauGan        = new TFile("TauHad/HadTau_TauResponseTemplates_GenTau_Matching04.root","R"); 

  TH1D * thist;
  catLeg1->SetHeader("p_{T}(#tau^{tau})");

  for(int i=0;i<4;i++){
    sprintf(tempname,"hTauResp_%d",i);
    thist = (TH1D*)file_13TeV->Get(tempname)->Clone();
    sprintf(tempname2,"hTauResp_%d_AB",i);
    thist->SetName(tempname2);
	thist->SetFillColor(0);
    thist->SetLineColor(i+1);
    thist->SetLineWidth(3);
    thist->SetStats(kFALSE);
    thist->SetMaximum(1.5);
    
    if(i==0){
      thist->SetMaximum(1.4);
      thist->GetXaxis()->SetLabelFont(42);
      thist->GetXaxis()->SetLabelOffset(0.007);
      thist->GetXaxis()->SetLabelSize(0.04);
      thist->GetXaxis()->SetTitleSize(0.05);
      thist->GetXaxis()->SetTitleOffset(0.9);
      thist->GetXaxis()->SetTitleFont(42);
      thist->GetYaxis()->SetLabelFont(42);
      thist->GetYaxis()->SetLabelOffset(0.007);
      thist->GetYaxis()->SetLabelSize(0.04);
      thist->GetYaxis()->SetTitleSize(0.05);
      thist->GetYaxis()->SetTitleOffset(1.25);
      thist->GetYaxis()->SetTitleFont(42);
    }

    //KH if (i==0){
    thist->GetYaxis()->SetTitle("Arbitrary unit");
    thist->DrawNormalized("same,hist");
    /*
    if(i==0)sprintf(tempname,"20 - 30: t#bar{t}");
    if(i==1)sprintf(tempname,"30 - 50: t#bar{t}");
    if(i==2)sprintf(tempname,"50 - 100: t#bar{t}");
    if(i==3)sprintf(tempname,">100: t#bar{t}");
    */
    if(i==0)sprintf(tempname,"20 - 30 GeV");
    if(i==1)sprintf(tempname,"30 - 50 GeV");
    if(i==2)sprintf(tempname,"50 - 100 GeV");
    if(i==3)sprintf(tempname,">100 GeV");
    catLeg1->AddEntry(thist,tempname,"l");
    //KH}
    
    }
  catLeg1->Draw();
  /*
   TLatex *   tex = new TLatex(1.5,0.03,"arXiv:1602.06581");
   tex->SetTextColor(4);
   tex->SetTextFont(61);
   tex->SetTextSize(0.0375);
   tex->SetLineColor(4);
   tex->SetLineWidth(2);
   //tex->Draw();
*/  
  TH1D * thist_km;
  if (icomp==1){
  for(int i=0;i<4;i++){
    sprintf(tempname,"hTauResp_%d",i);
    thist_km = (TH1D*)file_TauGan->Get(tempname)->Clone();
    sprintf(tempname2,"hTauResp_%d_KM",i);
    thist_km->SetName(tempname2);
    thist_km->SetLineColor(i+1);
    thist_km->SetLineWidth(3);
    thist_km->SetLineStyle(3);

    if (i==0) {
    thist_km->DrawNormalized("same,hist");
    if(i==0)sprintf(tempname,"20 - 30: TauGan");
    if(i==1)sprintf(tempname,"30 - 50: TauGan");
    if(i==2)sprintf(tempname,"50 - 100: TauGan");
    if(i==3)sprintf(tempname,">100: TauGan");
    catLeg1->AddEntry(thist_km,tempname,"l");
    }
  }
  }
  {
    CMS_lumi( c1, iPeriod, iPos );   // writing the lumi information and the CMS "logo"
  }
  c1->Update();
  c1->RedrawAxis();
  catLeg1->Draw();  

  c1->Print("Plot_TauTemplate_TTbar_Wjets.pdf");
  c1->Print("Plot_TauTemplate_TTbar_Wjets.png");

}
Example #3
0
//void plotTriggerForTDR(char *infname="/data/yjlee/dmeson/2015/trigger/mb.root")
void plotTrigger(string infname="/data/jisun/ppMB2015fullstats/skim_ncand_D0Dntuple_crab_pp_ALLMinimumBias_AOD_D0_tkpt0p5_Ds_01212016.root")
{  
   bool sideband = false;

   infname="/data/jisun/ppMB2015fullstats/skim_ncand_D0Dntuple_crab_pp_ALLMinimumBias_AOD_D0_tkpt0p5_Ds_01212016.root";
   TString outf = "result";
   
   //infname="/data/wangj/Data2015/Dntuple/pp/ntD_EvtBase_20160425_HighPtJet80_DfinderData_pp_20160329_dPt0tkPt0p5_D0Dstar_skim.root";
   //TString outf = "result_ppJet80";
   
   //infname="/data/wangj/Data2015/Dntuple/pp/ntD_EvtBase_20160425_HighPtLowerJets_DfinderData_pp_20160329_dPt0tkPt0p5_D0Dstar_skim.root";
   //TString outf = "result_ppLowerJets";
   
   //infname="/data/jisun/ppMB2015fullstats/skim_ncand_D0Dntuple_crab_pp_ALLMinimumBias_AOD_D0_tkpt0p5_Ds_01212016.root";
   //sideband = true; TString outf = "result_sideband"; 
   
   // ============== Open file and basic settings ===============   
   // Open Dntuple file
   TFile *inf = new TFile(infname.c_str());

   TTree *ntDkpi = (TTree*)inf->Get("ntDkpi");
   TTree *ntHlt = (TTree*)inf->Get("ntHlt");
   TTree *ntSkim = (TTree*)inf->Get("ntSkim");
   ntDkpi->AddFriend(ntHlt);
   ntDkpi->AddFriend(ntSkim);   

   // Define bin size and bin width for trigger turnon curve histograms
   const int nBin = 8;
   Float_t bins[nBin+1]={0,6,8,10,15,20,30,50,80};
   //const int nBin = 12;
   //Float_t bins[nBin+1]={0,5,6,8,10,12,15,20,25,30,35,40,70};

 
   // Templates for plotting  
   TH1D *hTmp2 = new TH1D ("hTmp2","",nBin,bins);
   
   // ============== Selection Criteria ===============

   // This MB sample has all pp MB 
   TCut mbCut = "(HLT_L1MinimumBiasHF1OR_part0_v1||  \
                             HLT_L1MinimumBiasHF1OR_part1_v1||  \
                             HLT_L1MinimumBiasHF1OR_part2_v1||  \
                             HLT_L1MinimumBiasHF1OR_part3_v1||  \
                             HLT_L1MinimumBiasHF1OR_part4_v1||  \
                             HLT_L1MinimumBiasHF1OR_part5_v1||  \
                             HLT_L1MinimumBiasHF1OR_part6_v1||  \
                             HLT_L1MinimumBiasHF1OR_part7_v1||  \
                             HLT_L1MinimumBiasHF1OR_part8_v1||  \
                             HLT_L1MinimumBiasHF1OR_part9_v1||  \
                             HLT_L1MinimumBiasHF1OR_part10_v1||  \
                             HLT_L1MinimumBiasHF1OR_part11_v1||  \
                             HLT_L1MinimumBiasHF1OR_part12_v1||  \
                             HLT_L1MinimumBiasHF1OR_part13_v1|| \
                             HLT_L1MinimumBiasHF1OR_part14_v1|| \
                             HLT_L1MinimumBiasHF1OR_part15_v1|| \
                             HLT_L1MinimumBiasHF1OR_part16_v1|| \
                             HLT_L1MinimumBiasHF1OR_part17_v1|| \
                             HLT_L1MinimumBiasHF1OR_part18_v1|| \
                             HLT_L1MinimumBiasHF1OR_part19_v1)";
   
   // L1 trigger thresholds
   TCut l1Cut16 = "L1_SingleJet16_BptxAND==1";
   TCut l1Cut24 = "L1_SingleJet24_BptxAND==1";
   TCut l1Cut28 = "L1_SingleJet28_BptxAND==1";
   TCut l1Cut40 = "L1_SingleJet40_BptxAND==1";
   TCut l1Cut48 = "L1_SingleJet48_BptxAND==1";

   // D meson selection
   TCut DmassCut             = "(abs(Dmass-1.8696)<0.03)";
   TCut DmesonCut            = "Dy>-1.&&Dy<1&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>2.0&&Dchi2cl>0.05&&Dalpha<0.12";
   TCut DmesonDaughterTrkCut = "Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)";
   if (sideband) DmassCut = "(abs(Dmass-1.8696)>0.06 && abs(Dmass-1.8696)>0.12)";

   // Final selection for D candidates for trigger turnon studies
   TCut DAnaCut = DmassCut && DmesonCut && DmesonDaughterTrkCut;

   // HLT trigger thresholds
   TCut HLTCut8  = "HLT_DmesonPPTrackingGlobal_Dpt8_v1";
   TCut HLTCut15 = "HLT_DmesonPPTrackingGlobal_Dpt15_v1";
   TCut HLTCut20 = "HLT_DmesonPPTrackingGlobal_Dpt20_v1";
   TCut HLTCut30 = "HLT_DmesonPPTrackingGlobal_Dpt30_v1";
   TCut HLTCut50 = "HLT_DmesonPPTrackingGlobal_Dpt50_v1";

   // ============== L1 trigger efficiency study ===============
   
  int W = 600;
  int H = 600;

  int H_ref = 600; 
  int W_ref = 600; 

  // references for T, B, L, R
  float T = 0.08*H_ref;
  float B = 0.14*H_ref; 
  float L = 0.14*W_ref;
  float R = 0.08*W_ref;


  TString canvName = "TRDFigure_Centrality";
  TCanvas* c = new TCanvas(canvName,canvName,50,50,W,H);
  c->cd();
  c->SetFillColor(0);
  c->SetBorderMode(0);
  c->SetFrameFillStyle(0);
  c->SetFrameBorderMode(0);
  c->SetLeftMargin( L/W );
  c->SetRightMargin( R/W );
  c->SetTopMargin( T/H );
  c->SetBottomMargin( B/H );
  
  
    TH2D *hTmp = new TH2D ("hTmp","",100,0,60,100,0,1.4);
    hTmp->GetXaxis()->SetTitle("p_{T} (D^{0}) (GeV)");  
    hTmp->GetYaxis()->SetTitleOffset(1.15);
    hTmp->GetXaxis()->SetTitleOffset(0.95);
    hTmp->GetYaxis()->SetTitle("HLT Efficiency");  
    hTmp->GetYaxis()->CenterTitle();
    hTmp->GetXaxis()->CenterTitle();
    hTmp->SetMaximum(1.4);
    hTmp->GetXaxis()->SetTitleFont(42);
    hTmp->GetXaxis()->SetLabelFont(42);
    hTmp->GetXaxis()->SetTitleSize(0.06);
    hTmp->GetXaxis()->SetLabelSize(0.05);
    hTmp->GetYaxis()->SetTitleFont(42);
    hTmp->GetYaxis()->SetLabelFont(42);
    hTmp->GetYaxis()->SetTitleSize(0.06);
    hTmp->GetYaxis()->SetLabelSize(0.05);
       

//   TGraphAsymmErrors* g8  = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&l1Cut16), HLTCut8, nBin, bins);
//   TGraphAsymmErrors* g15 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&l1Cut24), HLTCut15, nBin, bins);
   TGraphAsymmErrors* g20 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&l1Cut28), HLTCut20, nBin, bins);
   TGraphAsymmErrors* g30 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&l1Cut40), HLTCut30, nBin, bins);
   TGraphAsymmErrors* g50 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&l1Cut48), HLTCut50, nBin, bins);

/*
   TGraphAsymmErrors* g8  = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&l1Cut16), HLTCut8, nBin, bins);
   TGraphAsymmErrors* g15 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&l1Cut24), HLTCut15, nBin, bins);
   TGraphAsymmErrors* g20 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&l1Cut28), HLTCut20, nBin, bins);
   TGraphAsymmErrors* g30 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&l1Cut40), HLTCut30, nBin, bins);
*/
    hTmp->Draw();

//   g8->SetLineColor(1);
//   g8->SetMarkerColor(1);
//   g8->Draw("p same");
   
//   g15->SetLineColor(2);
//   g15->SetMarkerColor(2);
//   g15->Draw("pl same");

   g20->SetLineColor(4);
   g20->SetMarkerColor(4);
   g20->Draw("pl same");
   
   g30->SetLineColor(kGreen+2);
   g30->SetMarkerColor(kGreen+2);
   g30->Draw("pl same");

   g50->SetLineColor(kOrange);
   g50->SetMarkerColor(kOrange);
   g50->Draw("pl same");
   
 TLegend *legend=new TLegend(0.4579866,0.2472028,0.8389262,0.4342657,"");
  legend->SetBorderSize(0);
  legend->SetLineColor(0);
  legend->SetFillColor(0);
  legend->SetFillStyle(1001);
  legend->SetTextFont(42);
  legend->SetTextSize(0.04);

//  TLegendEntry *ent_g8=legend->AddEntry(g8,"HLT D meson p_{T} #geq 8","pl");
//  ent_g8->SetTextFont(42);
//  ent_g8->SetLineColor(1);
//  ent_g8->SetMarkerColor(1);
//  TLegendEntry *ent_g15=legend->AddEntry(g15,"HLT D meson p_{T} #geq15","pl");
//  ent_g15->SetTextFont(42);
//  ent_g15->SetLineColor(1);
//  ent_g15->SetMarkerColor(1);
  TLegendEntry *ent_g20=legend->AddEntry(g20,"HLT D meson p_{T} #geq 20","pl");
  ent_g20->SetTextFont(42);
  ent_g20->SetLineColor(1);
  ent_g20->SetMarkerColor(1);
  TLegendEntry *ent_g30=legend->AddEntry(g30,"HLT D meson p_{T} #geq 30","pl");
  ent_g30->SetTextFont(42);
  ent_g30->SetLineColor(1);
  ent_g30->SetMarkerColor(1);
  TLegendEntry *ent_g50=legend->AddEntry(g50,"HLT D meson p_{T} #geq 50","pl");
  ent_g50->SetTextFont(42);
  ent_g50->SetLineColor(1);
  ent_g50->SetMarkerColor(1);
  legend->Draw("same");
   
   CMS_lumi( c, 1, 11 );
   
   
  TLatex * tlatexeff=new TLatex(0.2079866,0.70,"HLT efficiency with respect to L1 seed");
  tlatexeff->SetNDC();
  tlatexeff->SetTextColor(1);
  tlatexeff->SetTextFont(42);
  tlatexeff->SetTextSize(0.040);
 // tlatexeff->Draw("same");

   c->SaveAs(outf+"/Dmeson-HLTriggerEfficiency.pdf");
   c->SaveAs(outf+"/Dmeson-HLTriggerEfficiency.png");
//   c->SaveAs(outf+"/Dmeson-HLTriggerEfficiency.jpeg");
//   c->SaveAs(outf+"/Dmeson-HLTriggerEfficiency.eps");
   c->SaveAs(outf+"/Dmeson-HLTriggerEfficiency.C");

/*   
   // ============== HLT trigger efficiency study ===============
   TCanvas *c2 = new TCanvas("c2","",600,600);
   
   TGraphAsymmErrors* gL16 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&"L1_SingleJet16_BptxAND_Prescl==1"), l1Cut16, nBin, bins);
   TGraphAsymmErrors* gL24 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&"L1_SingleJet24_BptxAND_Prescl==1"), l1Cut24, nBin, bins);
   TGraphAsymmErrors* gL28 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&"L1_SingleJet28_BptxAND_Prescl==1"), l1Cut28, nBin, bins);
   TGraphAsymmErrors* gL40 = getEfficiency(ntDkpi,Form("Max$(Dpt*(%s))",DAnaCut.GetTitle()), TCut(DAnaCut&&mbCut&&"L1_SingleJet40_BptxAND_Prescl==1"), l1Cut40, nBin, bins);
   
   hTmp2->Draw();
   hTmp2->SetXTitle("p_{T}  (D^{0})(GeV/c)");
   hTmp2->SetYTitle("L1 Trigger Efficiency");
   
   gL16->SetMarkerColor(1);
   gL16->SetLineColor(1);
   gL16->Draw("p same");

   gL24->SetMarkerColor(2);
   gL24->SetLineColor(2);
   gL24->Draw("p same");

   gL28->SetMarkerColor(4);
   gL28->SetLineColor(4);
   gL28->Draw("p same");

   gL40->SetMarkerColor(kGreen+2);
   gL40->SetLineColor(kGreen+2);
   gL40->Draw("p same");

   TLegend *leg2 = new TLegend(0.4916107,0.3059441,0.8322148,0.4912587);
   leg2->SetBorderSize(0);
   leg2->SetFillStyle(0); 
   leg2->AddEntry(gL16,"pp #sqrt{s} = 5.02 TeV","");
   leg2->AddEntry(gL16,"Level 1 Jet 16","pl");
   leg2->AddEntry(gL24,"Level 1 Jet 24","pl");
   leg2->AddEntry(gL28,"Level 1 Jet 28","pl");
   leg2->AddEntry(gL40,"Level 1 Jet 40","pl");
   leg2->Draw();

   c2->SaveAs(outf+"/Dmeson-L1TriggerEfficiency.pdf");
   c2->SaveAs(outf+"/Dmeson-L1TriggerEfficiency.png");
//   c2->SaveAs(outf+"/Dmeson-L1TriggerEfficiency.jpeg");
   c2->SaveAs(outf+"/Dmeson-L1TriggerEfficiency.C");
   
   
   // ============== Plot an example D mass distribution ===============
   TCanvas *c3 = new TCanvas("c3","",600,600);
   ntDkpi->Draw("Dmass>>h(100,1.7696,1.9696)",DmesonCut&&DmesonDaughterTrkCut&&mbCut&&l1Cut16);
   
   // ..done 
*/
}
Example #4
0
void drawCtauFrom2DPlot(RooWorkspace& myws,   // Local workspace
                        string outputDir,     // Output directory
                        struct InputOpt opt,  // Variable with run information (kept for legacy purpose)
                        struct KinCuts cut,   // Variable with current kinematic cuts
                        map<string, string>  parIni,   // Variable containing all initial parameters
                        string plotLabel,     // The label used to define the output file name
                        // Select the type of datasets to fit
                        string DSTAG,         // Specifies the type of datasets: i.e, DATA, MCJPSINP, ...
                        bool isPbPb,          // Define if it is PbPb (True) or PP (False)
                        // Select the type of object to fit
                        bool incJpsi,         // Includes Jpsi model
                        bool incPsi2S,        // Includes Psi(2S) model
                        bool incBkg,          // Includes Background model     
                        // Select the fitting options
                        // Select the drawing options
                        bool setLogScale,     // Draw plot with log scale
                        bool incSS,           // Include Same Sign data
                        double binWidth       // Bin width
                        ) 
{

  RooMsgService::instance().getStream(0).removeTopic(Caching);  
  RooMsgService::instance().getStream(1).removeTopic(Caching);
  RooMsgService::instance().getStream(0).removeTopic(Plotting);
  RooMsgService::instance().getStream(1).removeTopic(Plotting);
  RooMsgService::instance().getStream(0).removeTopic(Integration);
  RooMsgService::instance().getStream(1).removeTopic(Integration);
  RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING) ;

  if (DSTAG.find("_")!=std::string::npos) DSTAG.erase(DSTAG.find("_"));

  string pdfTotName  = Form("pdfCTAUMASS_Tot_%s", (isPbPb?"PbPb":"PP"));
  string dsOSName = Form("dOS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP"));
  string dsOSNameCut = dsOSName+"_CTAUCUT";
  string hOSName = Form("dhCTAUERRTot_Tot_%s", (isPbPb?"PbPb":"PP"));
  string hOSNameBkg  = Form("dhCTAUERR_Bkg_%s", (isPbPb?"PbPb":"PP"));
  string hOSNameJpsi = Form("dhCTAUERR_Jpsi_%s", (isPbPb?"PbPb":"PP"));
  string hOSNamePsi2S = Form("dhCTAUERR_Psi2S_%s", (isPbPb?"PbPb":"PP"));
  string dsSSName = Form("dSS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP"));

  bool isWeighted = myws.data(dsOSName.c_str())->isWeighted();
  vector<double> range; range.push_back(cut.dMuon.ctau.Min); range.push_back(cut.dMuon.ctau.Max);

  double minRange = -4.0;
  double maxRange = 7.0;
  Double_t outTot = myws.data(dsOSName.c_str())->numEntries();
  Double_t outErr = myws.data(dsOSName.c_str())->reduce(Form("(ctau>%.6f || ctau<%.6f)", range[1], range[0]))->numEntries();
  int nBins = min(int( round((maxRange - minRange)/binWidth) ), 1000);

  double normDSTot   = 1.0;  if (myws.data(dsOSNameCut.c_str()))  { normDSTot   = myws.data(dsOSName.c_str())->sumEntries()/myws.data(dsOSNameCut.c_str())->sumEntries();  }
  double normJpsi  = 1.0;  if (myws.data(hOSNameJpsi.c_str()))  { normJpsi  = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNameJpsi.c_str())->sumEntries();  }
  double normPsi2S = 1.0;  if (myws.data(hOSNamePsi2S.c_str())) { normPsi2S = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNamePsi2S.c_str())->sumEntries(); }
  double normBkg   = 1.0;  if (myws.data(hOSNameBkg.c_str()))   { normBkg   = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNameBkg.c_str())->sumEntries();   }
  double normTot   = 1.0;  if (myws.data(hOSName.c_str()))  { normTot   = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSName.c_str())->sumEntries();  }

  // Create the main plot of the fit
  RooPlot*   frame     = myws.var("ctau")->frame(Bins(nBins), Range(minRange, maxRange));
  frame->updateNormVars(RooArgSet(*myws.var("invMass"), *myws.var("ctau"), *myws.var("ctauErr"))) ;
  myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2));
  
  myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PDF"),
                                       ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSNameCut.c_str()), kTRUE),
                                       Normalization(normDSTot, RooAbsReal::NumEvent),
                                       FillStyle(1001), FillColor(kViolet+6), VLines(), DrawOption("LF"), NumCPU(32), LineColor(kBlack)
                                       );
  myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("BKG"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))) )),
                                       ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                       Normalization(normDSTot, RooAbsReal::NumEvent),
                                       FillStyle(1001), FillColor(kAzure-9), VLines(), DrawOption("LF"), NumCPU(32)
                                       );
  if (incJpsi) {
    myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSIPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP"))) )),
                                         ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                         Normalization(normDSTot, RooAbsReal::NumEvent),
                                         LineColor(kRed+3), Precision(1e-5), NumCPU(32)
                                         );
    myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSINOPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP"))) )),
                                         ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                         Normalization(normDSTot, RooAbsReal::NumEvent),
                                         LineColor(kGreen+3), Precision(1e-5), NumCPU(32)
                                         );
  }
  if (incPsi2S) {
    myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP"))) )),
                                         ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                         Normalization(normDSTot, RooAbsReal::NumEvent),
                                         LineColor(kRed+3), Precision(1e-5), NumCPU(32)
                                         );
    myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SNOPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Psi2SNo_%s", (isPbPb?"PbPb":"PP"))) )),
                                         ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE),
                                         Normalization(normDSTot, RooAbsReal::NumEvent),
                                         LineColor(kGreen+3), Precision(1e-5), NumCPU(32)
                                         );
  }  
  if (incSS) { 
    myws.data(dsSSName.c_str())->plotOn(frame, Name("dSS"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); 
  }
  myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2));
  myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PDFLINE"),
                                       ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSNameCut.c_str()), kTRUE),
                                       Normalization(normDSTot, RooAbsReal::NumEvent), 
                                       LineColor(kBlack), NumCPU(32)
                                       );
  
  
  // set the CMS style
  setTDRStyle();

  // Create the pull distribution of the fit 
  RooHist *hpull = frame->pullHist(0, "PDF", true);
  hpull->SetName("hpull");
  RooPlot* frame2 = myws.var("ctau")->frame(Title("Pull Distribution"), Bins(nBins), Range(minRange, maxRange));
  frame2->addPlotable(hpull, "PX"); 
  
  // Create the main canvas
  TCanvas *cFig  = new TCanvas(Form("cCtauFig_%s", (isPbPb?"PbPb":"PP")), "cCtauFig",800,800);
  TPad    *pad1  = new TPad(Form("pad1_%s", (isPbPb?"PbPb":"PP")),"",0,0.23,1,1);
  TPad    *pad2  = new TPad(Form("pad2_%s", (isPbPb?"PbPb":"PP")),"",0,0,1,.228);
  TLine   *pline = new TLine(minRange, 0.0, maxRange, 0.0);
  
  TPad *pad4 = new TPad("pad4","This is pad4",0.55,0.46,0.97,0.87);
  pad4->SetFillStyle(0);
  pad4->SetLeftMargin(0.28);
  pad4->SetRightMargin(0.10);
  pad4->SetBottomMargin(0.21);
  pad4->SetTopMargin(0.072);

  frame->SetTitle("");
  frame->GetXaxis()->SetTitle("");
  frame->GetXaxis()->CenterTitle(kTRUE);
  frame->GetXaxis()->SetTitleSize(0.045);
  frame->GetXaxis()->SetTitleFont(42);
  frame->GetXaxis()->SetTitleOffset(3);
  frame->GetXaxis()->SetLabelOffset(3);
  frame->GetYaxis()->SetLabelSize(0.04);
  frame->GetYaxis()->SetTitleSize(0.04);
  frame->GetYaxis()->SetTitleOffset(1.7);
  frame->GetYaxis()->SetTitleFont(42);
  setCtauFrom2DRange(myws, frame, dsOSNameCut, setLogScale, range, outErr);
 
  cFig->cd();
  pad2->SetTopMargin(0.02);
  pad2->SetBottomMargin(0.4);
  pad2->SetFillStyle(4000); 
  pad2->SetFrameFillStyle(4000); 
  pad1->SetBottomMargin(0.015); 
  //plot fit
  pad1->Draw();
  pad1->cd(); 
  frame->Draw();

  printCtauFrom2DParameters(myws, pad1, isPbPb, pdfTotName, isWeighted);
  pad1->SetLogy(setLogScale);

  // Drawing the text in the plot
  TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.032);
  float dy = 0; 
  
  t->SetTextSize(0.03);
  t->DrawLatex(0.21, 0.86-dy, "2015 HI Soft Muon ID"); dy+=0.045;
  if (isPbPb) {
    t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045;
  } else {
    t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045;
  } 
  t->DrawLatex(0.21, 0.86-dy, Form("%.1f #leq p_{T}^{#mu#mu} < %.1f GeV/c",cut.dMuon.Pt.Min,cut.dMuon.Pt.Max)); dy+=0.045;
  t->DrawLatex(0.21, 0.86-dy, Form("%.1f #leq |y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Min,cut.dMuon.AbsRap.Max)); dy+=0.045;
  if (isPbPb) {t->DrawLatex(0.21, 0.86-dy, Form("Cent. %d-%d%%", (int)(cut.Centrality.Start/2), (int)(cut.Centrality.End/2))); dy+=0.045;}
  if (outErr>0.0) {
    t->DrawLatex(0.21, 0.86-dy, Form("Excl: (%.4f%%) %.0f evts", (outErr*100.0/outTot), outErr)); dy+=1.5*0.045;
  }

  // Drawing the Legend
  double ymin = 0.7602;
  if (incPsi2S && incJpsi && incSS)  { ymin = 0.7202; } 
  if (incPsi2S && incJpsi && !incSS) { ymin = 0.7452; }
  TLegend* leg = new TLegend(0.5175, ymin, 0.7180, 0.8809); leg->SetTextSize(0.03);
  leg->AddEntry(frame->findObject("dOS"), (incSS?"Opposite Charge":"Data"),"pe");
  if (incSS) { leg->AddEntry(frame->findObject("dSS"),"Same Charge","pe"); }
  if(frame->findObject("PDF")) { leg->AddEntry(frame->findObject("PDF"),"Total fit","fl"); }
  if((incBkg && (incJpsi || incPsi2S)) && frame->findObject("BKG")) { leg->AddEntry(frame->findObject("BKG"),"Background","fl");  }
  if(incBkg && incJpsi && frame->findObject("JPSIPR")) { leg->AddEntry(frame->findObject("JPSIPR"),"J/#psi Prompt","l"); }
  if(incBkg && incJpsi && frame->findObject("JPSINOPR")) { leg->AddEntry(frame->findObject("JPSINOPR"),"J/#psi Non-Prompt","l"); }
  if(incBkg && incPsi2S && frame->findObject("PSI2SPR")) { leg->AddEntry(frame->findObject("PSI2SPR"),"#psi(2S) Prompt","l"); }
  if(incBkg && incPsi2S && frame->findObject("PSI2SNOPR")) { leg->AddEntry(frame->findObject("PSI2SNOPR"),"#psi(2S) Non-Prompt","l"); }
  leg->Draw("same");

  //Drawing the title
  TString label;
  if (isPbPb) {
    if (opt.PbPb.RunNb.Start==opt.PbPb.RunNb.End){
      label = Form("PbPb Run %d", opt.PbPb.RunNb.Start);
    } else {
      label = Form("%s [%s %d-%d]", "PbPb", "HIOniaL1DoubleMu0", opt.PbPb.RunNb.Start, opt.PbPb.RunNb.End);
    }
  } else {
    if (opt.pp.RunNb.Start==opt.pp.RunNb.End){
      label = Form("PP Run %d", opt.pp.RunNb.Start);
    } else {
      label = Form("%s [%s %d-%d]", "PP", "DoubleMu0", opt.pp.RunNb.Start, opt.pp.RunNb.End);
    }
  }
  
  //CMS_lumi(pad1, isPbPb ? 105 : 104, 33, label);
  CMS_lumi(pad1, isPbPb ? 108 : 107, 33, "");
  gStyle->SetTitleFontSize(0.05);
  
  pad1->Update();
  cFig->cd(); 

  //---plot pull
  pad2->Draw();
  pad2->cd();
    
  frame2->SetTitle("");
  frame2->GetYaxis()->CenterTitle(kTRUE);
  frame2->GetYaxis()->SetTitleOffset(0.4);
  frame2->GetYaxis()->SetTitleSize(0.1);
  frame2->GetYaxis()->SetLabelSize(0.1);
  frame2->GetYaxis()->SetTitle("Pull");
  frame2->GetXaxis()->CenterTitle(kTRUE);
  frame2->GetXaxis()->SetTitleOffset(1);
  frame2->GetXaxis()->SetTitleSize(0.12);
  frame2->GetXaxis()->SetLabelSize(0.1);
  frame2->GetXaxis()->SetTitle("#font[12]{l}_{J/#psi} (mm)");
  frame2->GetYaxis()->SetRangeUser(-7.0, 7.0);

  frame2->Draw(); 
  
  // *** Print chi2/ndof 
  printChi2(myws, pad2, frame, "ctau", dsOSName.c_str(), pdfTotName.c_str(), nBins, false);
  
  pline->Draw("same");
  pad2->Update();
  
  // Save the plot in different formats
  gSystem->mkdir(Form("%sctauMass/%s/plot/root/", outputDir.c_str(), DSTAG.c_str()), kTRUE); 
  cFig->SaveAs(Form("%sctauMass/%s/plot/root/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  gSystem->mkdir(Form("%sctauMass/%s/plot/png/", outputDir.c_str(), DSTAG.c_str()), kTRUE);
  cFig->SaveAs(Form("%sctauMass/%s/plot/png/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.png", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  gSystem->mkdir(Form("%sctauMass/%s/plot/pdf/", outputDir.c_str(), DSTAG.c_str()), kTRUE);
  cFig->SaveAs(Form("%sctauMass/%s/plot/pdf/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.pdf", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  

  cFig->Clear();
  cFig->Close();

}
void plotScaleFactor(string label) {

  TFile *inf = new TFile(Form("data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root",label.c_str()),"READ");
  inf->ls();
  TH2Poly *ttbarNominal = (TH2Poly*)inf->Get("TTJetsScaleFactors");
  TH2Poly *ttbarUp = (TH2Poly*)inf->Get("TTJetsScaleFactorsUp");
  TH2Poly *ttbarDown = (TH2Poly*)inf->Get("TTJetsScaleFactorsDown");
  TH2Poly *wNominal = (TH2Poly*)inf->Get("WJetsScaleFactors");
  TH2Poly *wUp = (TH2Poly*)inf->Get("WJetsScaleFactorsUp");
  TH2Poly *wDown = (TH2Poly*)inf->Get("WJetsScaleFactorsDown");
  TH2Poly *wInvNominal = (TH2Poly*)inf->Get("WJetsInvScaleFactors");
  TH2Poly *wInvUp = (TH2Poly*)inf->Get("WJetsInvScaleFactorsUp");
  TH2Poly *wInvDown = (TH2Poly*)inf->Get("WJetsInvScaleFactorsDown");
  TH2Poly *GJetInvNominal = (TH2Poly*)inf->Get("GJetsInvScaleFactors");

  TCanvas *cv = 0;
  gStyle->SetPaintTextFormat("4.2f");

  //****************************************************
  //Plot GJetsInv Scale Factors
  //****************************************************
  cv = new TCanvas("cv","cv", 800,600);
  cv->cd();
  gStyle->SetPalette(53);
  GJetInvNominal->Draw("colztexte1");
  cv->SetLogx();
  cv->SetLogy();
  cv->SetRightMargin(0.175);
  cv->SetBottomMargin(0.12);
  GJetInvNominal->GetXaxis()->SetRangeUser(400,4000);
  GJetInvNominal->GetYaxis()->SetRangeUser(0.25,1.5);
  GJetInvNominal->GetZaxis()->SetTitle("Data to MC Correction Factor");
  GJetInvNominal->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]");
  GJetInvNominal->GetYaxis()->SetTitle("R^{2}");
  GJetInvNominal->SetTitle("");
  GJetInvNominal->GetZaxis()->SetLabelSize(0.05);
  GJetInvNominal->GetZaxis()->SetTitleSize(0.05);
  GJetInvNominal->GetXaxis()->SetLabelSize(0.05);
  GJetInvNominal->GetXaxis()->SetTitleSize(0.05);
  GJetInvNominal->GetXaxis()->SetTitleOffset(0.8);
  GJetInvNominal->GetYaxis()->SetLabelSize(0.05);
  GJetInvNominal->GetYaxis()->SetTitleSize(0.05);
  GJetInvNominal->GetYaxis()->SetTitleOffset(0.8);
  GJetInvNominal->SetStats(false);
  GJetInvNominal->SetMaximum(1.8);
  GJetInvNominal->SetMinimum(0.35);

  lumi_13TeV = "35.9 fb^{-1}";
  writeExtraText = true;
  relPosX = 0.13;
  lumiTextSize = 0.5;
  cmsTextSize = 0.6;
  extraOverCmsTextSize = 0.85;
  CMS_lumi(cv,4,0);
  cv->SaveAs(Form("GJetsInvScaleFactor_CorrectedToMultiJet_%s.png",label.c_str()));
  cv->SaveAs(Form("GJetsInvScaleFactor_CorrectedToMultiJet_%s.pdf",label.c_str()));

  TH2Poly *GJetInvUncertainties = (TH2Poly*)GJetInvNominal->Clone("GJetInvUncertainties");
  for (int i=1; i<GJetInvUncertainties->GetNumberOfBins()+1; ++i) {
    GJetInvUncertainties->SetBinContent(i,100*GJetInvNominal->GetBinError(i) / GJetInvNominal->GetBinContent(i));
    cout << i << " : " << GJetInvNominal->GetBinError(i) << " " << GJetInvNominal->GetBinContent(i) << " : " << GJetInvNominal->GetBinError(i) / GJetInvNominal->GetBinContent(i) << "\n";
  }

  cv = new TCanvas("cv","cv", 800,600);
  gStyle->SetPalette(1);
  gStyle->SetPaintTextFormat("4.0f");
  GJetInvUncertainties->Draw("colztext");
  cv->SetLogx();
  cv->SetLogy();
  cv->SetRightMargin(0.175);
  cv->SetBottomMargin(0.12);
  GJetInvUncertainties->SetMarkerSize(2.0);
  GJetInvUncertainties->SetTitle("");
  GJetInvUncertainties->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]");
  GJetInvUncertainties->GetYaxis()->SetTitle("R^{2}");
  GJetInvUncertainties->GetXaxis()->SetRangeUser(400,4000);
  GJetInvUncertainties->GetYaxis()->SetRangeUser(0.25,1.5);
  GJetInvUncertainties->GetZaxis()->SetTitle("Systematic Uncertainty (%)");
  GJetInvUncertainties->GetZaxis()->SetLabelSize(0.05);
  GJetInvUncertainties->GetZaxis()->SetTitleSize(0.05);
  GJetInvUncertainties->GetXaxis()->SetLabelSize(0.05);
  GJetInvUncertainties->GetXaxis()->SetTitleSize(0.05);
  GJetInvUncertainties->GetXaxis()->SetTitleOffset(0.8);
  GJetInvUncertainties->GetYaxis()->SetLabelSize(0.05);
  GJetInvUncertainties->GetYaxis()->SetTitleSize(0.05);
  GJetInvUncertainties->GetYaxis()->SetTitleOffset(0.8);
  GJetInvUncertainties->SetStats(false);
  GJetInvUncertainties->SetMaximum(50);
  GJetInvUncertainties->SetMinimum(0.0);
  lumi_13TeV = "35.9 fb^{-1}";
  writeExtraText = true;
  relPosX = 0.13;
  lumiTextSize = 0.5;
  cmsTextSize = 0.6;
  extraOverCmsTextSize = 0.85;
  CMS_lumi(cv,4,0);
  cv->SaveAs(Form("GJetsInvScaleFactorUncertainty_%s.png",label.c_str()));
  cv->SaveAs(Form("GJetsInvScaleFactorUncertainty_%s.pdf",label.c_str()));



  //****************************************************
  //Plot WJetsInv Scale Factors
  //****************************************************
  cv = new TCanvas("cv","cv", 800,600);
  gStyle->SetPalette(53);
  gStyle->SetPaintTextFormat("4.2f");
  wInvNominal->Draw("colztexte1");
  cv->SetLogx();
  cv->SetLogy();
  cv->SetRightMargin(0.175);
  cv->SetBottomMargin(0.12);
  wInvNominal->GetXaxis()->SetRangeUser(300,4000);
  wInvNominal->GetYaxis()->SetRangeUser(0.15,1.5);
  wInvNominal->GetZaxis()->SetTitle("Data to MC Correction Factor");
  wInvNominal->GetZaxis()->SetLabelSize(0.05);
  wInvNominal->GetZaxis()->SetTitleSize(0.05);
  wInvNominal->GetXaxis()->SetLabelSize(0.05);
  wInvNominal->GetXaxis()->SetTitleSize(0.05);
  wInvNominal->GetXaxis()->SetTitleOffset(0.8);
  wInvNominal->GetYaxis()->SetLabelSize(0.05);
  wInvNominal->GetYaxis()->SetTitleSize(0.05);
  wInvNominal->GetYaxis()->SetTitleOffset(0.8);
  wInvNominal->SetStats(false);
  wInvNominal->SetMaximum(1.8);
  wInvNominal->SetMinimum(0.0);


  lumi_13TeV = "35.9 fb^{-1}";
  writeExtraText = true;
  relPosX = 0.13;
  lumiTextSize = 0.5;
  cmsTextSize = 0.6;
  extraOverCmsTextSize = 0.85;
  CMS_lumi(cv,4,0);
  cv->SaveAs(Form("WJetsInvScaleFactor_CorrectedToMultiJet_%s.png",label.c_str()));
  cv->SaveAs(Form("WJetsInvScaleFactor_CorrectedToMultiJet_%s.pdf",label.c_str()));




 //****************************************************
  //Plot WJets Scale Factors
  //****************************************************
  cv = new TCanvas("cv","cv", 800,600);
  gStyle->SetPalette(53);
  wNominal->Draw("colztexte1");
  cv->SetLogx();
  cv->SetLogy();
  cv->SetRightMargin(0.175);
  cv->SetBottomMargin(0.12);
  wNominal->GetXaxis()->SetRangeUser(300,4000);
  wNominal->GetYaxis()->SetRangeUser(0.15,1.5);
  wNominal->GetZaxis()->SetTitle("Data to MC Correction Factor");
  wNominal->GetZaxis()->SetLabelSize(0.05);
  wNominal->GetZaxis()->SetTitleSize(0.05);
  wNominal->GetXaxis()->SetLabelSize(0.05);
  wNominal->GetXaxis()->SetTitleSize(0.05);
  wNominal->GetXaxis()->SetTitleOffset(0.8);
  wNominal->GetYaxis()->SetLabelSize(0.05);
  wNominal->GetYaxis()->SetTitleSize(0.05);
  wNominal->GetYaxis()->SetTitleOffset(0.8);
  wNominal->SetStats(false);
  wNominal->SetMaximum(1.8);
  wNominal->SetMinimum(0.35);

  lumi_13TeV = "35.9 fb^{-1}";
  writeExtraText = true;
  relPosX = 0.13;
  lumiTextSize = 0.5;
  cmsTextSize = 0.6;
  extraOverCmsTextSize = 0.85;
  CMS_lumi(cv,4,0);
  cv->SaveAs(Form("WJetsScaleFactor_CorrectedToMultiJet_%s.png",label.c_str()));
  cv->SaveAs(Form("WJetsScaleFactor_CorrectedToMultiJet_%s.pdf",label.c_str()));




  TH2Poly *WJetsUncertainties = (TH2Poly*)wNominal->Clone("WJetsUncertainties");
  for (int i=1; i<WJetsUncertainties->GetNumberOfBins()+1; ++i) {
    WJetsUncertainties->SetBinContent(i,100*wNominal->GetBinError(i) / wNominal->GetBinContent(i));
  }

  cv = new TCanvas("cv","cv", 800,600);
  gStyle->SetPalette(1);
  gStyle->SetPaintTextFormat("4.0f");
  WJetsUncertainties->Draw("colztext");
  cv->SetLogx();
  cv->SetLogy();
  cv->SetRightMargin(0.175);
  cv->SetBottomMargin(0.12);
  WJetsUncertainties->SetMarkerSize(2.0);
  WJetsUncertainties->SetTitle("");
  WJetsUncertainties->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]");
  WJetsUncertainties->GetYaxis()->SetTitle("R^{2}");
  WJetsUncertainties->GetXaxis()->SetRangeUser(300,4000);
  WJetsUncertainties->GetYaxis()->SetRangeUser(0.15,1.5);
  WJetsUncertainties->GetZaxis()->SetTitle("Systematic Uncertainty (%)");
  WJetsUncertainties->GetZaxis()->SetLabelSize(0.05);
  WJetsUncertainties->GetZaxis()->SetTitleSize(0.05);
  WJetsUncertainties->GetXaxis()->SetLabelSize(0.05);
  WJetsUncertainties->GetXaxis()->SetTitleSize(0.05);
  WJetsUncertainties->GetXaxis()->SetTitleOffset(0.8);
  WJetsUncertainties->GetYaxis()->SetLabelSize(0.05);
  WJetsUncertainties->GetYaxis()->SetTitleSize(0.05);
  WJetsUncertainties->GetYaxis()->SetTitleOffset(0.8);
  WJetsUncertainties->SetStats(false);
  WJetsUncertainties->SetMaximum(50);
  WJetsUncertainties->SetMinimum(0.0);
  lumi_13TeV = "35.9 fb^{-1}";
  writeExtraText = true;
  relPosX = 0.13;
  lumiTextSize = 0.5;
  cmsTextSize = 0.6;
  extraOverCmsTextSize = 0.85;
  CMS_lumi(cv,4,0);
  cv->SaveAs(Form("WJetsScaleFactorUncertainty_%s.png",label.c_str()));
  cv->SaveAs(Form("WJetsScaleFactorUncertainty_%s.pdf",label.c_str()));




 //****************************************************
  //Plot TTBar Scale Factors
  //****************************************************
  cv = new TCanvas("cv","cv", 800,600);
  gStyle->SetPalette(53);
  gStyle->SetPaintTextFormat("4.2f");
  ttbarNominal->Draw("colztexte1");
  cv->SetLogx();
  cv->SetLogy();
  cv->SetRightMargin(0.175);
  cv->SetBottomMargin(0.12);
  ttbarNominal->GetXaxis()->SetRangeUser(400,4000);
  ttbarNominal->GetYaxis()->SetRangeUser(0.25,1.5);
  ttbarNominal->GetZaxis()->SetTitle("Data to MC Correction Factor");
  ttbarNominal->GetZaxis()->SetLabelSize(0.05);
  ttbarNominal->GetZaxis()->SetTitleSize(0.05);
  ttbarNominal->GetXaxis()->SetLabelSize(0.05);
  ttbarNominal->GetXaxis()->SetTitleSize(0.05);
  ttbarNominal->GetXaxis()->SetTitleOffset(0.8);
  ttbarNominal->GetYaxis()->SetLabelSize(0.05);
  ttbarNominal->GetYaxis()->SetTitleSize(0.05);
  ttbarNominal->GetYaxis()->SetTitleOffset(0.8);
  ttbarNominal->SetStats(false);
  // ttbarNominal->SetMaximum(10000);
  // ttbarNominal->SetMinimum(0.0);
  ttbarNominal->SetMaximum(1.8);
  ttbarNominal->SetMinimum(0.35);

  lumi_13TeV = "35.9 fb^{-1}";
  writeExtraText = true;
  relPosX = 0.13;
  lumiTextSize = 0.5;
  cmsTextSize = 0.6;
  extraOverCmsTextSize = 0.85;
  CMS_lumi(cv,4,0);
  cv->SaveAs(Form("TTBarScaleFactor_CorrectedToMultiJet_%s.png",label.c_str()));
  cv->SaveAs(Form("TTBarScaleFactor_CorrectedToMultiJet_%s.pdf",label.c_str()));





  TH2Poly *TTBarUncertainties = (TH2Poly*)ttbarNominal->Clone("TTBarUncertainties");
  for (int i=1; i<TTBarUncertainties->GetNumberOfBins()+1; ++i) {
    TTBarUncertainties->SetBinContent(i,100*ttbarNominal->GetBinError(i) / ttbarNominal->GetBinContent(i));
  }

  cv = new TCanvas("cv","cv", 800,600);
  gStyle->SetPalette(1);
  gStyle->SetPaintTextFormat("4.0f");
  TTBarUncertainties->Draw("colztext");
  cv->SetLogx();
  cv->SetLogy();
  cv->SetRightMargin(0.175);
  cv->SetBottomMargin(0.12);
  TTBarUncertainties->SetMarkerSize(2.0);
  TTBarUncertainties->SetTitle("");
  TTBarUncertainties->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]");
  TTBarUncertainties->GetYaxis()->SetTitle("R^{2}");
  TTBarUncertainties->GetXaxis()->SetRangeUser(300,4000);
  TTBarUncertainties->GetYaxis()->SetRangeUser(0.15,1.5);
  TTBarUncertainties->GetZaxis()->SetTitle("Systematic Uncertainty (%)");
  TTBarUncertainties->GetZaxis()->SetLabelSize(0.05);
  TTBarUncertainties->GetZaxis()->SetTitleSize(0.05);
  TTBarUncertainties->GetXaxis()->SetLabelSize(0.05);
  TTBarUncertainties->GetXaxis()->SetTitleSize(0.05);
  TTBarUncertainties->GetXaxis()->SetTitleOffset(0.8);
  TTBarUncertainties->GetYaxis()->SetLabelSize(0.05);
  TTBarUncertainties->GetYaxis()->SetTitleSize(0.05);
  TTBarUncertainties->GetYaxis()->SetTitleOffset(0.8);
  TTBarUncertainties->SetStats(false);
  TTBarUncertainties->SetMaximum(50);
  TTBarUncertainties->SetMinimum(0.0);
  lumi_13TeV = "35.9 fb^{-1}";
  writeExtraText = true;
  relPosX = 0.13;
  lumiTextSize = 0.5;
  cmsTextSize = 0.6;
  extraOverCmsTextSize = 0.85;
  CMS_lumi(cv,4,0);
  cv->SaveAs(Form("TTBarScaleFactorUncertainty_%s.png",label.c_str()));
  cv->SaveAs(Form("TTBarScaleFactorUncertainty_%s.pdf",label.c_str()));



  


}
Example #6
0
void makeplot(){
  
  TString path_ttbar = "/home/jalmond/Analysis/LQanalyzer/data/output/ElectronFakes//MC/FakeRateCalculator_El_SKttbar_5_3_14.root";
  
  TString path_qcd= "/home/jalmond/Analysis/LQanalyzer/data/output/ElectronFakes/FakeRateCalculator_El_SKQCD_5_3_14.root";
  TString path_qcd2= "/home/jalmond/Analysis/LQanalyzer/data/output/ElectronFakes/FakeRateCalculator_El_SKQCDEl_5_3_14.root";
  
  TString path_wjet = "/home/jalmond/Analysis/LQanalyzer/data/output/ElectronFakes/MC/FakeRateCalculator_El_SKWjets_5_3_14.root";

  
  setTDRStyle();
  gStyle->SetPalette(1);
  
  TFile * fttbar = new TFile(path_ttbar);
  TFile * fqcd = new TFile(path_qcd);
  TFile * fqcd2 = new TFile(path_qcd2);
  TFile * fwjet = new TFile(path_wjet);
  //  
  TCanvas* c1 = new TCanvas("Plot", "Plot", 1600, 1200);
  
  
  TH1F* h_ttbar= (TH1F*)fttbar->Get("JetPt_fakeobject_sig");
  TH1F* h_qcd = (TH1F*)fqcd->Get("JetPt_fakeobject");
  TH1F* h_qcd2 = (TH1F*)fqcd2->Get("GenJetPt_fakeobject");
  TH1F* h_wjet = (TH1F*)fwjet->Get("JetPt_fakeobject");

  h_ttbar->Rebin(4);
  h_qcd->Rebin(4);
  h_qcd2->Rebin(4);
  h_wjet->Rebin(4);

  TH1F * h_fake_20 = (TH1F*)fqcd->Get("JetPt_fakeobject_fakerateHNTight_relaxedip_allmc_20");
  TH1F * h_fake_40 = (TH1F*)fqcd->Get("JetPt_fakeobject_fakerateHNTight_relaxedip_allmc_40");
  TH1F * h_fake_60 = (TH1F*)fqcd->Get("JetPt_fakeobject_fakerateHNTight_relaxedip_allmc_60");
  h_fake_20->Rebin(4);
  h_fake_40->Rebin(4);
  h_fake_60->Rebin(4);


  cout << h_ttbar << " " << h_wjet << " " << h_qcd << " " << h_qcd2 << endl;

  h_fake_20->SetLineColor(kRed);
  h_fake_40->SetLineColor(kBlue);
  h_fake_60->SetLineColor(kGreen);

  h_fake_20->Scale(1. / h_fake_20->Integral());
  h_fake_40->Scale(1. / h_fake_40->Integral());
  h_fake_60->Scale(1. / h_fake_60->Integral());

  if(h_qcd){
    h_qcd->SetLineColor(kRed);
    h_qcd->SetMarkerColor(kRed);
    h_qcd->SetLineWidth(2.);
    h_qcd->SetFillStyle(3003);
    h_qcd->SetMarkerStyle(21);
    h_qcd->SetMarkerSize(2.);
  }

  if(h_qcd2){
    h_qcd2->SetLineColor(kRed);
    h_qcd2->SetMarkerColor(kRed-5);
    h_qcd2->SetLineWidth(2.);
    h_qcd2->SetFillStyle(3003);
    h_qcd2->SetMarkerStyle(21);
    h_qcd2->SetMarkerSize(2.);
  }


  if(h_ttbar){
    h_ttbar->SetLineColor(kCyan);
    h_ttbar->SetMarkerColor(kCyan);
    h_ttbar->SetLineWidth(2.);
    h_ttbar->SetFillStyle(3004);
    h_ttbar->SetMarkerStyle(21);
    h_ttbar->SetMarkerSize(2.);
  }
  if(h_wjet){
    h_wjet->SetLineColor(kOrange);
    h_wjet->SetMarkerColor(kOrange);
    h_wjet->SetFillStyle(3007);
    h_wjet->SetLineWidth(2.);
    h_wjet->SetMarkerStyle(21);
    h_wjet->SetMarkerSize(2.);
  }
  
  h_qcd->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  h_qcd->GetYaxis()->SetTitle("Events / 8 GeV");
  
  h_qcd->GetYaxis()->SetRangeUser(0.,  h_qcd->GetMaximum()* 2.);
  
  cout << "Integral = " << h_qcd->Integral() << " " << h_ttbar->Integral() << " " << h_wjet->Integral() << endl; 
  h_qcd->Scale(1. / h_qcd->Integral());
  h_qcd2->Scale(1. / h_qcd2->Integral());
  h_ttbar->Scale(1. / h_ttbar->Integral());
  h_wjet->Scale(1. / h_wjet->Integral());
  
  h_qcd->GetYaxis()->SetRangeUser(0.,0.35);
  h_qcd->Draw("p");
  //h_qcd2->Draw("psame");
  h_ttbar->Draw("psame");
  h_wjet->Draw("psame");
  h_fake_20->Draw("histsame");
  h_fake_40->Draw("histsame");
  h_fake_60->Draw("histsame");
  
  
  cout << "Integral = " << h_qcd->Integral() << " " << h_ttbar->Integral() << " " << h_wjet->Integral() << endl; 
  
  TLegend* legendH = new TLegend(0.7, 0.75, 0.9, 0.9);
  legendH->SetFillColor(kWhite);
  legendH->SetTextSize(0.03);
  legendH->SetTextFont(42);
  legendH->AddEntry(h_qcd, "QCD", "p");
  //legendH->AddEntry(h_qcd2, "QCD2", "p");
  legendH->AddEntry(h_ttbar, "t#bar{t}", "p");
  legendH->AddEntry(h_wjet, "W+jet", "p");
  legendH->AddEntry(h_fake_20, "FR 20", "l");
  legendH->AddEntry(h_fake_40, "FR 40", "l");
  legendH->AddEntry(h_fake_60, "FR 60", "l");
  legendH->Draw();
  
  CMS_lumi( c1, 2, 11 );
  c1->Update();
  c1->RedrawAxis();
  
  c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/Fakes/jetpt.pdf"));
  delete c1;
}
Example #7
0
void comp_RpPb_pt_ATLAS(bool isPrompt = true)
{
	gROOT->Macro("./tdrstyle_kyo.C");
	int isPA = 10;
	int iPos=33;
  
  //// BR and lumi info.
  const Double_t br = 0.0593 ;
  const Double_t brErr = 0.0006;
	const Double_t pp_lumi_pb =27.972; // 28.0/pb
	const Double_t pp_lumi_pb_err = 0.643; // 2.3 %
	const Double_t pPb_lumi_nb = 34.622; // 34.6/nb
	const Double_t pPb_lumi_nb_err = 1.211; // 3.5 %
  const Double_t pp_lumi_mub = pp_lumi_pb *1000*1000;
  const Double_t pPb_lumi_mub_err = pp_lumi_pb_err *1000*1000;
 
  double A_pb =208;
  
  //// read our result
	TFile *inFile_pp;
  if (isPrompt) inFile_pp = new TFile("plot_cross/pp_cross_pt_integ_middle_isPrompt1_isLog0_isScale0_maxrap300.root");
  else inFile_pp= new TFile("plot_cross/pp_cross_pt_integ_middle_isPrompt0_isLog0_isScale0_maxrap300.root");
	TGraphAsymmErrors* g_cross_fwrap_pp = (TGraphAsymmErrors*)inFile_pp->Get("g_cross_fwrap"); 
	TGraphAsymmErrors* g_cross_sys_fwrap_pp = (TGraphAsymmErrors*)inFile_pp->Get("g_cross_sys_fwrap"); 

	//// read our result
	TFile *inFile_pA;
  if (isPrompt) inFile_pA = new TFile("plot_cross/pA_cross_pt_integ_middle_isPrompt1_isLog0_isScale0_maxrap300.root");
  else inFile_pA= new TFile("plot_cross/pA_cross_pt_integ_middle_isPrompt0_isLog0_isScale0_maxrap300.root");
	TGraphAsymmErrors* g_cross_fwrap_pA = (TGraphAsymmErrors*)inFile_pA->Get("g_cross_fwrap"); 
	TGraphAsymmErrors* g_cross_sys_fwrap_pA = (TGraphAsymmErrors*)inFile_pA->Get("g_cross_sys_fwrap"); 

  const int nPt = 5;
  double dummy1;
  double pxtmp[nPt];
  double pytmp_pp[nPt]; double pytmp_pA[nPt]; double rppb[nPt];
  double eytmp_pp[nPt]; double eytmp_pA[nPt]; double ey_rppb[nPt];
  double eysystmp_pp[nPt]; double eysystmp_pA[nPt]; double eysys_rppb[nPt];
  for (int ipt=0; ipt<nPt; ipt++) {
    g_cross_fwrap_pp->GetPoint(ipt+4, pxtmp[ipt], pytmp_pp[ipt]); 
    g_cross_fwrap_pA->GetPoint(ipt+4, pxtmp[ipt], pytmp_pA[ipt]); 
    eytmp_pp[ipt] = g_cross_fwrap_pp->GetErrorY(ipt+4); 
    eytmp_pA[ipt] = g_cross_fwrap_pA->GetErrorY(ipt+4);
    eysystmp_pp[ipt] = g_cross_sys_fwrap_pp->GetErrorY(ipt+4); 
    eysystmp_pA[ipt] = g_cross_sys_fwrap_pA->GetErrorY(ipt+4);
  }
  for (int ipt=0; ipt<nPt; ipt++) {
    DivideValue(pytmp_pA[ipt],eytmp_pA[ipt],pytmp_pp[ipt],eytmp_pp[ipt],&rppb[ipt],&ey_rppb[ipt]);  //actual values
    DivideValue(pytmp_pA[ipt],eysystmp_pA[ipt],pytmp_pp[ipt],eysystmp_pp[ipt],&dummy1,&eysys_rppb[ipt]); //syst. 
    rppb[ipt]/=A_pb; 
    ey_rppb[ipt]/=A_pb; 
    eysys_rppb[ipt]/=A_pb; 
    cout << " "<<endl;
    cout << "rppb["<<ipt<<"] ="  << rppb[ipt] << endl;
    cout << "stat.["<<ipt<<"] ="  << ey_rppb[ipt] << endl;
    cout << "syst.["<<ipt<<"] ="  << eysys_rppb[ipt] << endl;
  }
	Double_t exsys[nPt] = {0.4,0.4,0.4,0.4,0.4};
	Double_t exlow[nPt];
	Double_t exhigh[nPt];
	Double_t ptArrNum[nPt+1] = {6.5, 7.5, 8.5, 10., 14., 30.};
	
  //// ex calculation
  for (Int_t ipt=0; ipt<nPt; ipt++) {
    exlow[ipt] = pxtmp[ipt]-ptArrNum[ipt];
    exhigh[ipt] = ptArrNum[ipt+1]-pxtmp[ipt];
  }
	
  ///////////////////////////////////////////////////
	///////////////////// ATLAS ////////////////////////
	///////////////////////////////////////////////////
	TFile *inFileATLAS;
  if (isPrompt) inFileATLAS = new TFile("ATLAS_Jpsi_RpPb/RpPb_PromptJpsi_dpT.root");
  else inFileATLAS= new TFile("ATLAS_Jpsi_RpPb/RpPb_NonPromptJpsi_dpT.root");
  cout << "inFileATLAS = " << inFileATLAS << endl;
	TGraphAsymmErrors* g_RpPb_ATLAS_sys;
	TGraphAsymmErrors* g_RpPb_ATLAS;
  if (isPrompt) { 
     g_RpPb_ATLAS_sys = (TGraphAsymmErrors*)inFileATLAS->Get("RpPb_p_syst"); 
     g_RpPb_ATLAS = (TGraphAsymmErrors*)inFileATLAS->Get("RpPb_p"); 
  }else {
     g_RpPb_ATLAS_sys = (TGraphAsymmErrors*)inFileATLAS->Get("RpPb_np_syst"); 
     g_RpPb_ATLAS = (TGraphAsymmErrors*)inFileATLAS->Get("RpPb_np"); 
  }
  cout << "g_RpPb_ATLAS_sys = " << g_RpPb_ATLAS_sys << endl;
  cout << "g_RpPb_ATLAS = " << g_RpPb_ATLAS << endl;
  
  
  //////////////////////////////////////////////////////////////
  
  TLatex* globtex = new TLatex();
	globtex->SetNDC();
	globtex->SetTextAlign(12); //1:left, 2:vertical center
  //globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
	globtex->SetTextSize(0.04);
  
  TCanvas *c1 = new TCanvas("c1","c1",600,600);
  
  g_RpPb_ATLAS_sys->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  g_RpPb_ATLAS_sys->GetXaxis()->CenterTitle();
  g_RpPb_ATLAS_sys->GetYaxis()->SetTitle("R_{pPb}");
  g_RpPb_ATLAS_sys->GetYaxis()->CenterTitle();
  g_RpPb_ATLAS_sys->GetXaxis()->SetTitleOffset(1.15);
  g_RpPb_ATLAS_sys->GetXaxis()->SetLimits(0.,32.);
  g_RpPb_ATLAS_sys->SetMinimum(0.0);
  g_RpPb_ATLAS_sys->SetMaximum(2.0);
  g_RpPb_ATLAS_sys->SetLineColor(kGray);
  g_RpPb_ATLAS_sys->SetFillColor(kWhite);
  g_RpPb_ATLAS_sys->SetFillStyle(4000);
  g_RpPb_ATLAS_sys->SetLineWidth(3);
  g_RpPb_ATLAS_sys->SetLineStyle(7);
  
  g_RpPb_ATLAS_sys->SetFillColor(kGray);
  
  SetGraphStyleFinal(g_RpPb_ATLAS, 9, 10);
  g_RpPb_ATLAS->SetMarkerSize(1.7);
  
  //TGraphAsymmErrors* g_RpPb_sys = new TGraphAsymmErrors(nPt, pxtmp, rppb, exsys, exsys, eysys_rppb, eysys_rppb);	
  TGraphAsymmErrors* g_RpPb_sys = new TGraphAsymmErrors(nPt, pxtmp, rppb, exlow, exhigh, eysys_rppb, eysys_rppb);	
  TGraphAsymmErrors* g_RpPb = new TGraphAsymmErrors(nPt, pxtmp, rppb, exsys, exsys, ey_rppb, ey_rppb);	
  g_RpPb_sys->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  g_RpPb_sys->GetXaxis()->CenterTitle();
  g_RpPb_sys->GetYaxis()->SetTitle("R_{pPb}");
  g_RpPb_sys->GetYaxis()->CenterTitle();
  g_RpPb_sys->GetXaxis()->SetLimits(0.,30.0);
  g_RpPb_sys->SetMinimum(0.0);
  g_RpPb_sys->SetMaximum(2.0);
  g_RpPb_sys->SetFillColorAlpha(kRed-10,0.5);
  g_RpPb_sys->SetLineColor(kPink-6);

  SetGraphStyleFinal(g_RpPb, 1, 0);
  //g_RpPb->SetMarkerSize(2.1);
  g_RpPb->SetMarkerSize(1.7);
  
  ////// actual draw
  g_RpPb_ATLAS_sys->Draw("A5");
  g_RpPb_sys->Draw("5");
  solidLine(0.,1.,32.,1.,1,1);
  g_RpPb_ATLAS->Draw("p");
  g_RpPb->Draw("p");
  
	
  //TLegend *legBL = new TLegend(0.19,0.18,0.54,0.25);
  TLegend *legBL = new TLegend(0.18,0.18,0.77,0.32);
	SetLegendStyle(legBL);
	legBL->SetTextSize(0.043);
  legBL->SetTextFont(42);
	legBL -> AddEntry(g_RpPb,"-1.5 < y_{CM} < 1.5","lp");
	legBL -> AddEntry(g_RpPb_ATLAS,"ATLAS: -1.5 < y_{CM} < 1.5","lp");
	legBL -> Draw();
  
  globtex->SetTextSize(0.055); 
  globtex->SetTextFont(42);
  if (isPrompt) globtex->DrawLatex(0.21, 0.84, "Prompt J/#psi");
  else globtex->DrawLatex(0.21, 0.84, "Nonprompt J/#psi");
  
  CMS_lumi( c1, isPA, iPos );
  c1->Update();

	c1->SaveAs(Form("plot_otherExp/comp_RpPb_pt_ATLAS_isPrompt%d.pdf",(int)isPrompt));
	c1->SaveAs(Form("plot_otherExp/comp_RpPb_pt_ATLAS_isPrompt%d.png",(int)isPrompt));
  
  return;

}
void plot_trigeff_PFMET170 (const TString& indir = "/nfs-6/userdata/mt2/V00-08-02_json_Cert_271036-274421/") {

  cmsText = "CMS Preliminary";
  cmsTextSize = 0.5;
  lumiTextSize = 0.4;
  writeExtraText = false;
  lumi_13TeV = "2.1 fb^{-1}";
  //lumi_13TeV = "589 pb^{-1}";
  
  gStyle->SetPadTopMargin(0.08);
  gStyle->SetPadBottomMargin(0.12);
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetPadRightMargin(0.05);

  TH1::SetDefaultSumw2();

  TString suffix = "";
  //  TString suffix = "_2j";
  
  TChain* t_jetht = new TChain("mt2");
  TChain* t_muon = new TChain("mt2");
  TChain* t_ele = new TChain("mt2");

  t_jetht->Add(Form("%s/*Run2016*JetHT*.root", indir.Data()));
  t_muon->Add(Form("%s/*Run2016*SingleMuon*.root", indir.Data()));
  t_ele->Add(Form("%s/*Run2016*SingleElectron*.root", indir.Data()));

  TFile* f_out = new TFile(Form("trigeff_PFMET170%s.root",suffix.Data()),"RECREATE");
  
  TH1D* h_met_denom_ht800 = new TH1D("h_met_denom_ht800",";E_{T}^{miss} [GeV]",40,100,500);
  TH1D* h_met_num_ht800 = (TH1D*) h_met_denom_ht800->Clone("h_met_num_ht800");
  TH1D* h_met_denom_mu20 = (TH1D*) h_met_denom_ht800->Clone("h_met_denom_mu20");
  TH1D* h_met_num_mu20 = (TH1D*) h_met_denom_ht800->Clone("h_met_num_mu20");
  TH1D* h_met_denom_ele23 = (TH1D*) h_met_denom_ht800->Clone("h_met_denom_ele23");
  TH1D* h_met_num_ele23 = (TH1D*) h_met_denom_ht800->Clone("h_met_num_ele23");

  TCanvas* c = new TCanvas("c","c");
  c->SetGrid(1,1);
  c->cd();

  TCut base = "nVert > 0 && nJet30 > 1 && Flag_CSCTightHalo2015Filter && Flag_eeBadScFilter && Flag_HBHENoiseFilter && Flag_HBHENoiseIsoFilter && Flag_EcalDeadCellTriggerPrimitiveFilter && Flag_goodVertices && ht > 200.";
  //TCut base = "nVert > 0 && nJet30 > 3 && Flag_CSCTightHaloFilter && Flag_eeBadScFilter && Flag_HBHENoiseFilter && Flag_HBHEIsoNoiseFilter";
  TCut had = base + "nElectrons10+nMuons10==0 && ht > 1000. && deltaPhiMin > 0.3";
  TCut ele = base + "nElectrons10 > 0 && abs(lep_pdgId[0]) == 11 && lep_pt[0] > 25. && lep_tightId[0] > 2 && lep_relIso03[0] < 0.1";
  TCut mu = base + "nMuons10 > 0 && abs(lep_pdgId[0]) == 13 && lep_pt[0] > 25. && lep_tightId[0] > 0 && lep_relIso03[0] < 0.1";

  // t_jetht->Draw("met_pt>>h_met_denom_ht800",had+"HLT_PFHT800");
  // t_jetht->Draw("met_pt>>h_met_num_ht800",had+"HLT_PFHT800 && HLT_PFMET170");

  // t_muon->Draw("met_pt>>h_met_denom_mu20",mu+"HLT_SingleMu");
  // t_muon->Draw("met_pt>>h_met_num_mu20",mu+"HLT_SingleMu && HLT_PFMET170");

  t_ele->Draw("met_pt>>h_met_denom_ele23",ele+"HLT_SingleEl");
  t_ele->Draw("met_pt>>h_met_num_ele23",ele+"HLT_SingleEl && HLT_PFMET170");

  TH2F* h_axis = new TH2F("h_axis",";E_{T}^{miss} [GeV];Eff of HLT_PFMET170",40,100,500,20,0,1);
  h_axis->GetYaxis()->SetTitleOffset(0.98);
  h_axis->Draw();
  
  // TEfficiency* h_met_eff_ht800 = new TEfficiency(*h_met_num_ht800, *h_met_denom_ht800);
  // h_met_eff_ht800->SetLineColor(kRed);
  // h_met_eff_ht800->SetMarkerColor(kRed);
  
  // TEfficiency* h_met_eff_mu20 = new TEfficiency(*h_met_num_mu20, *h_met_denom_mu20);
  // h_met_eff_mu20->SetLineColor(kBlue);
  // h_met_eff_mu20->SetMarkerColor(kBlue);

  TEfficiency* h_met_eff_ele23 = new TEfficiency(*h_met_num_ele23, *h_met_denom_ele23);
  h_met_eff_ele23->SetLineColor(kGreen+2);
  h_met_eff_ele23->SetMarkerColor(kGreen+2);

  int bin_met200 = h_met_denom_ele23->FindBin(200.);
  float num_met200 = h_met_num_ele23->Integral(bin_met200,-1);
  float denom_met200 = h_met_denom_ele23->Integral(bin_met200,-1);
  float eff_met200_ele23 = num_met200/denom_met200;
  float eff_UP_met200_ele23 = TEfficiency::ClopperPearson(denom_met200, num_met200, 0.68, 1);
  float eff_DN_met200_ele23 = TEfficiency::ClopperPearson(denom_met200, num_met200, 0.68, 0);

  std::cout << "efficiency for MET > 200 using Ele23: " << eff_met200_ele23 << " +" << (eff_UP_met200_ele23 - eff_met200_ele23)
	    << " -" << (eff_met200_ele23 - eff_DN_met200_ele23) << std::endl;
  
  //h_met_eff_ht800->Draw("pe same");
  //h_met_eff_mu20->Draw("pe same");
  h_met_eff_ele23->Draw("pe same");

  TLegend* leg = new TLegend(0.55,0.15,0.95,0.45);
  //leg->AddEntry(h_met_eff_ht800,"HLT_PFHT800","pe");
  //leg->AddEntry(h_met_eff_mu20,"HLT_IsoMu20 || HLT_IsoTkMu20","pe");
  leg->AddEntry(h_met_eff_ele23,"HLT_Ele23_WPLoose_Gsf","pe");
  leg->Draw("same");

  CMS_lumi( c, iPeriod, iPos );
  c->SaveAs(Form("trigeff_PFMET170%s.pdf",suffix.Data()));
  c->SaveAs(Form("trigeff_PFMET170%s.eps",suffix.Data()));
  c->SaveAs(Form("trigeff_PFMET170%s.png",suffix.Data()));

  f_out->Write();
  f_out->Close();
  
  return;
}
Example #9
0
TCanvas* example_plot( int iPeriod, int iPos )
{ 
  //  if( iPos==0 ) relPosX = 0.12;

  int W = 800;
  int H = 600;

  int H_ref = 600; 
  int W_ref = 800; 

  // references for T, B, L, R
  float T = 0.08*H_ref;
  float B = 0.12*H_ref; 
  float L = 0.12*W_ref;
  float R = 0.04*W_ref;

  TString canvName = "FigExample_";
  canvName += W;
  canvName += "-";
  canvName += H;
  canvName += "_";  
  canvName += iPeriod;
  if( writeExtraText ) canvName += "-prelim";
  if( iPos%10==0 ) canvName += "-out";
  else if( iPos%10==1 ) canvName += "-left";
  else if( iPos%10==2 )  canvName += "-center";
  else if( iPos%10==3 )  canvName += "-right";

  TCanvas* canv = new TCanvas(canvName,canvName,50,50,W,H);
  canv->SetFillColor(0);
  canv->SetBorderMode(0);
  canv->SetFrameFillStyle(0);
  canv->SetFrameBorderMode(0);
  canv->SetLeftMargin( L/W );
  canv->SetRightMargin( R/W );
  canv->SetTopMargin( T/H );
  canv->SetBottomMargin( B/H );
  canv->SetTickx(0);
  canv->SetTicky(0);


  int histLineColor = kOrange+7;
  int histFillColor = kOrange-2;
  float markerSize  = 1.0;

  {
    TLatex latex;
				
    int n_ = 2;

    float x1_l = 0.92;
    float y1_l = 0.60;

    float dx_l = 0.30;
    float dy_l = 0.18;
    float x0_l = x1_l-dx_l;
    float y0_l = y1_l-dy_l;

    TPad* legend = new TPad("legend_0","legend_0",x0_l,y0_l,x1_l, y1_l );
    //    legend->SetFillColor( kGray );
    legend->Draw();
    legend->cd();
		
    float ar_l = dy_l/dx_l;
		
    float x_l[1];
    float ex_l[1];
    float y_l[1];
    float ey_l[1];
		
    //    float gap_ = 0.09/ar_l;
    float gap_ = 1./(n_+1);
		
    float bwx_ = 0.12;
    float bwy_ = gap_/1.5;
		
    x_l[0] = 1.2*bwx_;
    //    y_l[0] = 1-(1-0.10)/ar_l;
    y_l[0] = 1-gap_;
    ex_l[0] = 0;
    ey_l[0] = 0.04/ar_l;
		
    TGraph* gr_l = new TGraphErrors(1, x_l, y_l, ex_l, ey_l );
		
    gStyle->SetEndErrorSize(0);
    gr_l->SetMarkerSize(0.9);
    gr_l->Draw("0P");
		
    latex.SetTextFont(42);
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);    
    latex.SetTextSize(0.25);    
    latex.SetTextAlign(12); 
		
    TLine line_;
    TBox  box_;
    float xx_ = x_l[0];
    float yy_ = y_l[0];
    latex.DrawLatex(xx_+1.*bwx_,yy_,"Data");
		
    yy_ -= gap_;
    box_.SetLineStyle( kSolid );
    box_.SetLineWidth( 1 );
    //		box_.SetLineColor( kBlack );
    box_.SetLineColor( histLineColor );
    box_.SetFillColor( histFillColor );
    box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 );
    box_.SetFillStyle(0);
    box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 );
    latex.DrawLatex(xx_+1.*bwx_,yy_,"Z #rightarrow e^{+}e^{-} (MC)");

    canv->cd();
  }

  {

   TGraphErrors *gre = new TGraphErrors(12);
   gre->SetName("Graph0");
   gre->SetTitle("");
   gre->SetFillColor(1);

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha
   ci = TColor::GetColor("#0000ff");
   gre->SetLineColor(ci);

   ci = TColor::GetColor("#0000ff");
   gre->SetMarkerColor(ci);
   gre->SetMarkerStyle(21);
   gre->SetPoint(0,0.1428571,0.943962);
   gre->SetPointError(0,0,0.00470259);
   gre->SetPoint(1,0.1714286,0.940484);
   gre->SetPointError(1,0,0.00447348);
   gre->SetPoint(2,0.2,0.935519);
   gre->SetPointError(2,0,0.00484668);
   gre->SetPoint(3,0.2285714,0.928495);
   gre->SetPointError(3,0,0.00504356);
   gre->SetPoint(4,0.2571429,0.931586);
   gre->SetPointError(4,0,0.00551296);
   gre->SetPoint(5,0.2857143,0.924183);
   gre->SetPointError(5,0,0.00521949);
   gre->SetPoint(6,0.3142857,0.925186);
   gre->SetPointError(6,0,0.00541335);
   gre->SetPoint(7,0.3428572,0.918469);
   gre->SetPointError(7,0,0.00520881);
   gre->SetPoint(8,0.3714286,0.926619);
   gre->SetPointError(8,0,0.00524148);
   gre->SetPoint(9,0.4,0.931496);
   gre->SetPointError(9,0,0.00526956);
   gre->SetPoint(10,0.4285714,0.932581);
   gre->SetPointError(10,0,0.00466349);
   gre->SetPoint(11,0.4571429,0.924199);
   gre->SetPointError(11,0,0.00348535);
   
   TH1F *Graph_Graph1 = new TH1F("Graph_Graph1","",100,0.1114286,0.4885714);
   Graph_Graph1->SetMinimum(0);
   Graph_Graph1->SetMaximum(1);
   Graph_Graph1->SetDirectory(0);
   Graph_Graph1->SetStats(0);

   ci = TColor::GetColor("#000099");
   Graph_Graph1->SetLineColor(ci);
   Graph_Graph1->GetXaxis()->SetTitle("Threshold (pC)");
   Graph_Graph1->GetXaxis()->CenterTitle(true);
   Graph_Graph1->GetXaxis()->SetLabelFont(42);
   Graph_Graph1->GetXaxis()->SetLabelSize(0.05);
   Graph_Graph1->GetXaxis()->SetTitleSize(0.05);
   Graph_Graph1->GetXaxis()->SetTitleFont(42);
   Graph_Graph1->GetYaxis()->SetTitle("Efficiency");
   Graph_Graph1->GetYaxis()->SetRange(0,1);
   Graph_Graph1->GetYaxis()->CenterTitle(true);
   Graph_Graph1->GetYaxis()->SetLabelFont(42);
   Graph_Graph1->GetYaxis()->SetLabelSize(0.05);
   Graph_Graph1->GetYaxis()->SetTitleSize(0.05);
   Graph_Graph1->GetYaxis()->SetTitleFont(42);
   Graph_Graph1->GetZaxis()->SetLabelFont(42);
   Graph_Graph1->GetZaxis()->SetLabelSize(0.035);
   Graph_Graph1->GetZaxis()->SetTitleSize(0.035);
   Graph_Graph1->GetZaxis()->SetTitleFont(42);
   gre->SetHistogram(Graph_Graph1);
   
   gre->Draw("ap");

  }

  TLegend *leg = new TLegend(0.55,0.35,0.70,0.50);
  leg->SetTextSize(0.035);
  leg->SetLineColor(1);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(0);
  leg->SetBorderSize(0);
  leg->SetHeader("GIF++ test beams 08.2015");
  leg->AddEntry(gre, "Low Resistivity Glass RPC", "p");
  leg->Draw();

  // writing the lumi information and the CMS "logo"
  CMS_lumi( canv, iPeriod, iPos );

  canv->Update();
  canv->RedrawAxis();
  canv->GetFrame()->Draw();

  canv->Print(canvName+".pdf",".pdf");
  canv->Print(canvName+".png",".png");

  return canv;
}
Example #10
0
plotLimits(string filename, TString name, TString channel, TString lepton){



TGraph * limit_obs = new TGraph();
  TGraph * limit_exp = new TGraph();
  TGraphAsymmErrors * band_exp1 = new TGraphAsymmErrors();
  TGraphAsymmErrors * band_exp2 = new TGraphAsymmErrors();

TGraph *theory = new TGraph();
theory->SetPoint(0, 1000, 1.3*3.02095);
theory->SetPoint(1, 1500, 1.3*0.58069);
theory->SetPoint(2, 2000, 1.3*0.14501);
theory->SetPoint(3, 2500, 1.3*0.04234);
theory->SetPoint(4, 3000, 1.3*0.01384);
theory->SetPoint(5, 4000, 1.3*0.00184);

ifstream infile(filename.c_str());

gROOT->LoadMacro("CMS_lumi.C");

double mass, exp, obs, up1, up2, dn1, dn2;
int point = 0;

while (!infile.eof()){

	infile >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;


        cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;


	limit_obs->SetPoint(point, mass, obs);
    limit_exp->SetPoint(point, mass, exp);
    band_exp1->SetPoint(point, mass, exp);
    band_exp2->SetPoint(point, mass, exp);

    band_exp1->SetPointEYhigh(point, up1 - exp);
    band_exp1->SetPointEYlow(point, exp - dn1);
    band_exp2->SetPointEYhigh(point, up2 - exp);
    band_exp2->SetPointEYlow(point, exp - dn2);
    point++;

}

double max = 200000.0; //band_exp2->GetHistogram()->GetMaximum()*50;

  TCanvas *canvas = new TCanvas(Form("limit set %s",name.Data()),Form("limit set %s",name.Data()), 500,500);

  limit_exp->SetMinimum(0.01);
  limit_exp->Draw("AL");
  limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]");
  limit_exp->GetYaxis()->SetTitle("95 % CL limit on #sigma(Z') [pb]");
  limit_exp->GetYaxis()->SetRangeUser(0.01,2000);

  band_exp2->SetFillColor(5);
  band_exp2->SetLineColor(0);
  //band_exp2->SetFillStyle(4000);
  band_exp2->Draw("3same");

  band_exp1->SetFillColor(3);
  band_exp1->SetLineColor(0);
  //band_exp1->SetFillStyle(4000);
  band_exp1->Draw("3same");

  limit_obs->Draw("Lsame");
  limit_obs->SetLineWidth(2);
  limit_obs->SetMarkerSize(1.0);
  limit_obs->SetMarkerStyle(20);
   
  limit_exp->Draw("Lsame");
  limit_exp->SetLineStyle(2);
  limit_exp->SetLineWidth(2);
  limit_exp->SetMarkerSize(1.0);
  limit_exp->SetMaximum(max);
  limit_exp->SetMinimum(0.001);
  limit_exp->SetMarkerStyle(20);

  double x1 = 595; 
  double y1 = 1.0;
  double x2 = 905;
  double y2 = 1.0;
  TLine * line = new TLine(x1, y1, x2, y2);
  theory->SetLineColor(2);
  theory->SetLineWidth(2);
  theory->Draw("same");

  



  //Legend
  TLegend *l = new TLegend(0.57,0.62,0.88,0.88);
  l->AddEntry(limit_obs,"Observed", "L");
  l->AddEntry(limit_exp,"Expected", "L");
  l->AddEntry(band_exp1,"#pm1 #sigma Exp.", "F");
  l->AddEntry(band_exp2,"#pm2 #sigma Exp.", "F");
  l->AddEntry(theory, " Z', 1% Width", "L");
  l->SetFillColor(0);
  l->SetLineColor(0);
  l->Draw();

  TLatex * label = new TLatex();
  label->SetNDC();
  //label->DrawLatex(0.2,0.86,"CMS Preliminary, 19.7 fb^{-1}");
  //label->DrawLatex(0.2,0.80,"#sqrt{s} = 8 TeV");
  //label->DrawLatex(0.6,0.80, Form("BR(b'#rightarrow %s) = 1", channel.Data()));
  //label->DrawLatex(0.55,0.80, "BR(b'#rightarrow tW) = 0.5");
  //label->DrawLatex(0.55,0.74, "BR(b'#rightarrow bH) = 0.25");
  //label->DrawLatex(0.55,0.68, "BR(b'#rightarrow bZ) = 0.25");
  //label->DrawLatex(0.2,0.74, lepton.Data());

  canvas->SetLogy(1);
  CMS_lumi(canvas, 4, 10);

  canvas->Print(Form("%s_limit.pdf",name.Data()));
  //canvas->Print(Form("%s_limit.png",name.Data()));

}
Example #11
0
void plotsNoFit(bool mine=false,TString name="collMass",TString file="LFV_vbf_collMass_fakeRate_zjetsEmbed_newSignal.root", TString dir="preselectionMetFix_Nov2", TString dirInternal="vbfmutau",double blindA=100, double blindB=160, bool blind=false, TString Xaxis="M_{#mu,#tau}_{coll} [GeV]", TString Yaxis="Events / 20 GeV", TString Tex="#mu#tau_{h} 0 Jet", double xmin=0, double xmax=300, int rebinning=1, bool setLogY=false, double legx1=0.6, double legy1=0.9, double legx2=0.9, double legy2=0.5, double MAX=-1, double MIN=-1, double CORRFR=1., double scaleSignal=100.0, double ymin=-0.95, double ymax=0.95){

  //gROOT->LoadMacro("tdrstyle.C");
  setTDRStyle();
  //gROOT->LoadMacro("CMS_lumi.C");
  writeExtraText = false; 
  int iPeriod = 2; 
  // second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot
  int iPos=11;// : top-left, left-aligned
  // iPos=33 : top-right, right-aligned
  // iPos=22 : center, centered
  // mode generally : 
  //   iPos = 10*(alignement 1/2/3) + position (1/2/3 = left/center/right)
  //  example_plot( iPeriod, 11 );  // left-aligned
  //  example_plot( iPeriod, 33 );  // right-aligned
  //  example_plot( iPeriod, 0 );   // out of frame (in exceptional cases)
  //  example_plot( iPeriod, 11 );  // default: left-aligned
  //  example_plot( iPeriod, 22 );  // centered
  //  example_plot( iPeriod, 33 );  // right-aligned  



  double kForPlotting=1;
  double branchingratioTauTau=0.063;
  double branchingratioTauMu=0.1;
  double Lumi=19717;

 // Get Plots

 // Get Plots

        TFile *_file0= new TFile(dir+"/"+file);
	TString find="/DY";
	if(!mine) find="/zjetsother";
        TH1F *hDY=_file0->Get(dirInternal+find); hDY->SetName("DY");
	find="/VV";
	if(!mine) find="/ww";
        TH1F *hWW=_file0->Get(dirInternal+find); hWW->SetName("WW");
	find="/TOP";
	if(!mine) find="/singlet";
        TH1F *hTOP=_file0->Get(dirInternal+find); hTOP->SetName("TOP");
	find="/TT";
	if(!mine) find="/ttbar";
        TH1F *hTT=_file0->Get(dirInternal+find); hTT->SetName("TT");
	find="/ZTauTau";
	if(!mine) find="/ztautau";
        TH1F *hZTauTau=_file0->Get(dirInternal+find); hZTauTau->SetName("ZTauTau");
	find="/FAKES";
	if(!mine) find="/fakes";
        TH1F *hFAKES=_file0->Get(dirInternal+find); hFAKES->SetName("fakes");
                hFAKES->Scale(CORRFR);
        TH1F *hLFVVBF126=_file0->Get(dirInternal+"/LFVVBF126"); hLFVVBF126->SetName("LFVVBF126");
        TH1F *hSMVBF126=_file0->Get(dirInternal+"/SMVBF126"); hSMVBF126->SetName("SMVBF126");
        TH1F *hLFVGG126=_file0->Get(dirInternal+"/LFVGG126"); hLFVGG126->SetName("LFVGG126");
        TH1F *hSMGG126=_file0->Get(dirInternal+"/SMGG126"); hSMGG126->SetName("SMGG126");

	find="/data_unblind";
	if(!mine) find="/data_obs";
        TH1F* hdata_obsNoErrFix=_file0->Get(dirInternal+find);
        TH1F* hdata_obs = hdata_obsNoErrFix->Clone();
        std::cout << hdata_obsNoErrFix->GetEntries() << std::endl;
        for (i = 1; i <= hdata_obs->GetNbinsX(); i++){
                if (hdata_obs->GetBinContent(i) == 0){
                        hdata_obs->SetBinContent(i,0.0);
                        hdata_obs->SetBinError(i,1.8);
                }
        }

	hdata_obs->SetName("data_obs");


        TH1F* hSMHIGGS=hSMGG126->Clone(); hSMHIGGS->SetName("HIGGSSM");
        hSMHIGGS->Add(hSMVBF126);

        // For the Control plots only we want signal to be scaled to 100% Br
        hLFVVBF126->Scale(scaleSignal);
        hLFVGG126->Scale(scaleSignal);

// From the fit
/*	hDY->Scale(1.122280);
	hWW->Scale(1.254172);
	hTOP->Scale(1.348162);
	hTT->Scale(1.082784);
	hZTauTau->Scale(1.157596);
	hFAKES->Scale(0.901000);
*/
	
 // Daniel's Colors
/*
WGammaStar=kCyan
ZTauTauEmbedded=kOrange-4
ZLL_residual=kAzure+3
TTBar=40
SingleTop=kGreen-2
EWKDiBoson=kRed+2
WJets/QCD Multijets=kMagenta-10
SMHToTauTau=kMagenta
*/
        hFAKES->SetFillColor(kMagenta-10); hFAKES->SetLineColor(kMagenta+4); hFAKES->SetLineWidth(1);
        hZTauTau->SetFillColor(kOrange-4); hZTauTau->SetLineColor(kOrange+4); hZTauTau->SetLineWidth(1);

        hDY->SetFillColor(kAzure+3); hDY->SetLineColor(kAzure+4); hDY->SetLineWidth(1);
        hWW->SetFillColor(kAzure+3); hWW->SetLineColor(kAzure+3); hWW->SetLineWidth(1);

        hTOP->SetFillColor(kGreen-2); hTOP->SetLineColor(kGreen+4); hTOP->SetLineWidth(1);
        hTT->SetFillColor(kGreen-2); hTT->SetLineColor(kGreen-2); hTT->SetLineWidth(1);

        hLFVGG126->SetLineColor(kBlue+1);  hLFVGG126->SetLineWidth(3);
        hLFVVBF126->SetLineColor(kBlue+1); hLFVVBF126->SetLineWidth(3); hLFVVBF126->SetLineStyle(kDashed);
        hSMVBF126->SetLineColor(kMagenta); hSMVBF126->SetLineWidth(3); hSMVBF126->SetLineStyle(kDashed); 
        hSMGG126->SetLineColor(kMagenta); hSMGG126->SetLineWidth(3); 
        hSMHIGGS->SetFillColor(kMagenta); hSMHIGGS->SetLineColor(kMagenta+1); hSMHIGGS->SetLineWidth(1);



	hdata_obs->SetMarkerSize(1); // Closer to Daniel's

 // Rebin

	hFAKES->Rebin(rebinning);
	hZTauTau->Rebin(rebinning);
        hDY->Rebin(rebinning);
        hTOP->Rebin(rebinning);
	hTT->Rebin(rebinning);
	hWW->Rebin(rebinning);
	hLFVGG126->Rebin(rebinning);
	hLFVVBF126->Rebin(rebinning);
	hSMVBF126->Rebin(rebinning);
        hSMGG126->Rebin(rebinning);
	hdata_obs->Rebin(rebinning);
	hSMHIGGS->Rebin(rebinning);

// PLOT

        TCanvas *c1 = new TCanvas("canvas_"+name);
        TPad *Pad1= new TPad("pad1","",0,0.2,1,1); Pad1->Draw(); Pad1->cd();;
        Pad1->SetLeftMargin(0.2147651);
        Pad1->SetRightMargin(0.06543624);
        Pad1->SetTopMargin(0.07);
        Pad1->SetBottomMargin(0.04);


        for (int i=0; i<hFAKES->GetNbinsX()+1; i++){
                double content=hFAKES->GetBinContent(i);
                double contentErr=0;//sqrt(content);//hFAKES->GetBinError(i);
		double err=sqrt(0.3*0.3*content*content+contentErr*contentErr);
                hFAKES->SetBinError(i,err);
        }

        TH1F* fullMC2=hFAKES->Clone();  fullMC2->Add(hZTauTau); fullMC2->Add(hTT); fullMC2->Add(hWW);
        fullMC2->Add(hDY); fullMC2->Add(hTOP);
        fullMC2->SetFillColorAlpha(kGray+2, 0.35); 
        //fullMC2->SetFillStyle(3002); 
        fullMC2->SetMarkerSize(0);
	fullMC2->Draw("hist");

        fullMC2->GetXaxis()->SetTitle("");
        fullMC2->GetYaxis()->SetTitle(Yaxis);
        fullMC2->GetXaxis()->SetRangeUser(xmin,xmax);
        fullMC2->GetYaxis()->SetTitleOffset(1.2);
        fullMC2->GetYaxis()->SetTitleSize(0.05);
        fullMC2->GetXaxis()->SetNdivisions(505);
        fullMC2->GetYaxis()->SetLabelSize(0.04);
	fullMC2->GetXaxis()->SetLabelSize(0);

	THStack* stack = new THStack("stack","");
        stack->Add(hFAKES);
        stack->Add(hWW);
        stack->Add(hDY);
        stack->Add(hTT);
        stack->Add(hTOP);
        stack->Add(hZTauTau);
        stack->Add(hSMHIGGS);

	cout<<"Yields"<<endl;
	cout<<"VV " <<hWW->Integral()<<endl;
        cout<<"TOP " <<hTOP->Integral()<<endl;
        cout<<"TT " <<hTT->Integral()<<endl;
        cout<<"DY " <<hDY->Integral()<<endl;
        cout<<"ZTauTau " <<hZTauTau->Integral()<<endl;
        cout<<"FAKES " <<hFAKES->Integral()<<endl;
        cout<<"LFVGG126 " <<hLFVGG126->Integral()<<endl;
        cout<<"LFVVBF126 " <<hLFVVBF126->Integral()<<endl;

	stack->Draw("samehist");
	fullMC2->Draw("sames,E2");

        hLFVVBF126->Draw("sameshist");
        hLFVGG126->Draw("sameshist");

        double maxData=hdata_obs->GetMaximum();
        double maxMC=stack->GetMaximum()*1.2;
	double maxLFV=hLFVGG126->GetMaximum();
        double maxLFV2=hLFVVBF126->GetMaximum();
        double minMC=stack->GetMinimum();

        if(maxData>maxMC) {maxMC=1.2*maxData;}
	if(maxLFV>maxMC) {maxMC=1.2*maxLFV;}
        if(maxLFV2>maxMC) {maxMC=1.2*maxLFV2;}
	if(MAX!=-1) {maxMC=MAX;}

	stack->SetMaximum(maxMC);
	stack->GetYaxis()->SetRangeUser(minMC,maxMC);
        fullMC2->SetMaximum(maxMC);
        fullMC2->GetYaxis()->SetRangeUser(minMC,maxMC);

	if(setLogY){fullMC2->SetMinimum(0.1); fullMC2->GetYaxis()->SetRangeUser(1,maxMC*1000);}

        TH1F* histoDataUnblindedV4=hdata_obs->Clone(); histoDataUnblindedV4->SetName("data_unblinded");

        if(!blind) hdata_obs->Draw("sames");
        else {
                int findBinA=hdata_obs->FindBin(blindA);
                int findBinB=hdata_obs->FindBin(blindB);
                for (int i=findBinA; i<findBinB; i++) hdata_obs->SetBinContent(i,-1000);
                hdata_obs->Draw("sames");
/*                   TPave *pave = new TPave(blindA,minMC,blindB,maxMC,4,"br");
                   pave->SetFillColor(kGray+1);
                   pave->SetFillStyle(3003);
                   pave->SetDrawOption(0);
                   pave->SetBorderSize(0);
                   pave->Draw();
*/
        }


   TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC");
   leg->SetFillColor(0);
   leg->SetBorderSize(0);
   leg->SetFillStyle(0);
   TLegendEntry *entry;
   entry=leg->AddEntry(hdata_obs,"Data, #mu#tau_{h}","p");
   entry=leg->AddEntry(fullMC2,"Bkgd. uncertainty","f");
   entry=leg->AddEntry(hSMHIGGS,"SM Higgs","f");
   eblindBy=leg->AddEntry(hZTauTau,"Z#rightarrow#tau#tau","f");
        entry=leg->AddEntry(hTOP,"t#bar{t}, t, #bar{t}","f");
        entry=leg->AddEntry(hDY,"Other","f");
   entry=leg->AddEntry(hFAKES,"Misidentified #tau","f");
   entry=leg->AddEntry(hLFVGG126,"LFV GG Higgs (B=100%)","l");
   entry=leg->AddEntry(hLFVVBF126,"LFV VBF Higgs (B=100%)","l");
   


   leg->Draw();


    CMS_lumi( Pad1, iPeriod, iPos );

    TLatex latex;
    latex.SetNDC();
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);

    latex.SetTextFont(42);
    latex.SetTextAlign(31);
    latex.SetTextSize(.05);
    latex.DrawLatex(0.39,0.8,Tex);

   //cmsPrelim(Lumi);
	
        Pad1->SetLogy(setLogY);
	gPad->RedrawAxis();

        c1->cd(); TPad *Pad2= new TPad("pad2","",0,0,1,0.23); Pad2->Draw(); Pad2->cd();  Pad2->SetGridy();
        Pad2->SetLeftMargin(0.2147651);
        Pad2->SetRightMargin(0.06543624);
        Pad2->SetTopMargin(0.0);
        Pad2->SetBottomMargin(0.37);
        Pad2->SetFillStyle(0);



        TH1F * Ratio=hdata_obs->Clone(); Ratio->SetName("Ratio");
        Ratio->Add(fullMC2,-1);

        Ratio->Divide(fullMC2);
        Ratio->GetXaxis()->SetLabelFont(42);
        Ratio->GetXaxis()->SetTitleFont(42);
        Ratio->GetYaxis()->SetNdivisions(505);
        Ratio->GetYaxis()->SetLabelFont(42);
        Ratio->GetYaxis()->SetLabelSize(0.122);
        Ratio->GetYaxis()->SetRangeUser(ymin,ymax);
        Ratio->GetXaxis()->SetRangeUser(xmin,xmax);
        Ratio->GetXaxis()->SetLabelSize(0.12);
        Ratio->GetXaxis()->SetLabelFont(42);
        Ratio->SetYTitle("#frac{Data-Bkgd}{Bkgd}");
        Ratio->SetXTitle(Xaxis);
        Ratio->GetXaxis()->SetNdivisions(505);
        Ratio->GetYaxis()->CenterTitle(true);
        Ratio->GetYaxis()->SetTitleOffset(0.4);
        Ratio->GetYaxis()->SetTitleSize(0.11);
        Ratio->GetXaxis()->SetTitleOffset(0.75);
        Ratio->GetXaxis()->SetTitleSize(0.20);
        Ratio->SetMarkerSize(1.);


        TH1F* RatioError = Ratio->Clone(); RatioError->SetName("RatioError");

        for (int i=0; i<RatioError->GetNbinsX()+1; i++){
                        double error=fullMC2->GetBinError(i)*hdata_obs->GetBinContent(i)/fullMC2->GetBinContent(i)/fullMC2->GetBinContent(i);
                        RatioError->SetBinContent(i,0);
                        RatioError->SetBinError(i,error);
        }
        RatioError->Draw("E2"); //RatioError->SetFillStyle(3002); 
        RatioError->SetFillColorAlpha(kGray+2, 0.35); RatioError->SetMarkerSize(0);
	//Ratio->Draw("samesE0"); //errorbarswithoutdatapoints
        Ratio->Draw("sames");

        if(!blind) Ratio->Draw("sames");
        else {
                int findBinA=Ratio->FindBin(blindA);
                int findBinB=Ratio->FindBin(blindB);
                for (int i=findBinA; i<findBinB; i++) Ratio->SetBinContent(i,-100);
                Ratio->Draw("sames");

                   TPave *pave = new TPave(blindA,-0.5,blindB,0.5,4,"br");
                   pave->SetFillColor(1);
                   pave->SetFillStyle(3003);
                   pave->SetDrawOption(0);
                   pave->SetBorderSize(0);
                   pave->Draw();
        }

       if(!setLogY){	
       	//	c1->SaveAs(name+"ErrorBarsWithoutDataPoints.png");
       	//	c1->SaveAs(name+"ErrorBarsWithoutDataPoints.pdf");
              c1->SaveAs(name+".png");
              c1->SaveAs(name+".pdf");

	}
	else {
       		c1->SaveAs(name+"_log.png");
       		c1->SaveAs(name+"_log.pdf");
        }  

}
void comp_RpPb_rap_Overlay(bool isPoint=true, bool isSmoothened=false)
{
	gROOT->Macro("./tdrstyle_kyo.C");
	int isPA = 10;  // 0:pp, 1:pPb, 10 : pp & pPb together for RpPb plot
	int iPos=33;

  bool isPrompt=true;
	
  const Double_t pp_lumi_relerr = 0.023; // 2.3 %
  const Double_t pPb_lumi_relerr = 0.035; // 3.5 %
  const Double_t glb_err = TMath::Sqrt(pp_lumi_relerr*pp_lumi_relerr+pPb_lumi_relerr*pPb_lumi_relerr);
  //cout << "glb_err = " << glb_err << endl;
  
  ///////////////////////////////////////////////////
  const int nRap = 8; 
  const int nRapTmp = nRap + 1;
	const int nRapRpPb = 7;
	const int nRapRpPbTheory = 6; //Ramona..
	//const int nPtRpPb = 49;
	const int nPtRpPb = 2;
  Double_t theory_px[nPtRpPb][nRapRpPbTheory]; 
	Double_t theory_py[nPtRpPb][nRapRpPbTheory];
	//Double_t theory_exlow_tmp[nPtRpPb][nRapRpPbTheory];
	//Double_t theory_exhigh_tmp[nPtRpPb][nRapRpPbTheory];
  Double_t theory_exlow[nPtRpPb][nRapRpPbTheory];
  Double_t theory_exhigh[nPtRpPb][nRapRpPbTheory];
	Double_t theory_eylow_tmp[nPtRpPb][nRapRpPbTheory];
	Double_t theory_eyhigh_tmp[nPtRpPb][nRapRpPbTheory];
  Double_t theory_eylow[nPtRpPb][nRapRpPbTheory];
	Double_t theory_eyhigh[nPtRpPb][nRapRpPbTheory];
  
  //// 1) y_CM array (from forward to backward)
  Double_t rapArrNumFB[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist.
  //Double_t rapArrNumBF[nRapTmp] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
  //// array string
  TString rapArr[nRap];
  for (Int_t iy=0; iy<nRap; iy++) {
    formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
    cout << iy <<"th rapArr = " << rapArr[iy] << endl;
  }
  
	///////////////////////////////////////////////////
  //////// experimental points	
  TFile *inFile = new TFile("../DrawFinalPlot/plot_RpPb/RpPb_rap_isPrompt1.root");
  
  TGraphAsymmErrors* g_RpPb_sys[nRapRpPb];
  TGraphAsymmErrors* g_RpPb_sys_line[nRapRpPb];
  TGraphAsymmErrors* g_RpPb[nRapRpPb];
  g_RpPb_sys[0] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_sys_lowpt");
  g_RpPb_sys_line[0] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_sys_lowpt_line");
  g_RpPb[0] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_lowpt");
  g_RpPb_sys[1] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_sys_highpt");
  g_RpPb_sys_line[1] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_sys_highpt_line");
  g_RpPb[1] = (TGraphAsymmErrors*)inFile->Get("g_RpPb_highpt");
  g_RpPb_sys[0]->SetName("g_RpPb_sys_lowpt");
  g_RpPb_sys_line[0]->SetName("g_RpPb_sys_lowpt_line");
  g_RpPb_sys[1]->SetName("g_RpPb_sys_highpt");
  g_RpPb_sys_line[1]->SetName("g_RpPb_sys_highpt_line");
  //g_RpPb_sys[0]->SetFillColorAlpha(kRed-10,0.5);
  //g_RpPb_sys_line[0]->SetFillColorAlpha(kRed-10,0.);
  //g_RpPb_sys_line[0]->SetLineColor(kPink-6);
  //g_RpPb_sys[1]->SetFillColorAlpha(kGreen-10,0.5);
  //g_RpPb_sys_line[1]->SetFillColorAlpha(kGreen-10,0.);
  //g_RpPb_sys_line[1]->SetLineColor(kGreen+3);
  g_RpPb_sys_line[0]->SetFillColorAlpha(kRed-10,0.);
  g_RpPb_sys_line[1]->SetFillColorAlpha(kRed-10,0.);
  for (int ipt = 0 ; ipt < nPtRpPb; ipt ++ ) {
    if (isPoint) {
      g_RpPb_sys[ipt]->SetFillColorAlpha(kRed-10,0.5);
      g_RpPb_sys[ipt]->SetLineColor(kPink-6);
    } else {
      g_RpPb_sys[ipt]->SetFillColor(kWhite);
      g_RpPb_sys[ipt]->SetLineColor(kWhite);
    }
    g_RpPb[ipt]->SetMarkerColor(kPink-6);
    g_RpPb[ipt]->SetLineColor(kPink-6);
    g_RpPb[ipt]->SetMarkerStyle(kFullCircle);
    g_RpPb[ipt]->SetMarkerSize(1.4);
  }
  
  ///////////////////////////////////////////////////
  //////// theory curves	
//  const int nTheory = 4;
  const int nTheory = 3;
  TFile *inFileTh[nTheory];
  inFileTh[0]= new TFile("./plot_theory/comp_RpPb_rap_isSmoothened0_Vogt.root","READ");
  inFileTh[1]= new TFile("./plot_theory/comp_RpPb_rap_isSmoothened0_Lansberg_EPS09NLO.root","READ");
  inFileTh[2]= new TFile("./plot_theory/comp_RpPb_rap_isSmoothened0_Lansberg_nCTEQ15.root","READ");
  
  TGraphAsymmErrors* g_RpPb_theory[nTheory][nPtRpPb];
  TGraphAsymmErrors* g_RpPb_theory_line[nTheory][nPtRpPb];
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    for (int ipt = 0 ; ipt < nPtRpPb; ipt ++ ) {
      g_RpPb_theory[ith][ipt] = (TGraphAsymmErrors*)inFileTh[ith]->Get(Form("g_RpPb_theory_%d",ipt));
      g_RpPb_theory[ith][ipt]->SetName(Form("g_RpPb_theory_%d_%d",ith,ipt));
      g_RpPb_theory_line[ith][ipt] = (TGraphAsymmErrors*)inFileTh[ith]->Get(Form("g_RpPb_theory_%d",ipt));
      g_RpPb_theory_line[ith][ipt]->SetName(Form("g_RpPb_theory_line_%d_%d",ith,ipt));
    } 
  } 

  //// color
  for (int ipt = 0 ; ipt < nPtRpPb; ipt ++ ) {
    g_RpPb_theory[0][ipt]->SetFillColorAlpha(kAzure+1,0.5);
    g_RpPb_theory[0][ipt]->SetLineColor(kAzure+1);
    g_RpPb_theory[0][ipt]->SetFillStyle(1001);
    g_RpPb_theory_line[0][ipt]->SetFillColorAlpha(kAzure+5,0.0);
    g_RpPb_theory_line[0][ipt]->SetLineColor(kAzure+5);
    g_RpPb_theory_line[0][ipt]->SetFillStyle(1001);
    g_RpPb_theory[1][ipt]->SetFillColor(kOrange+2);
    g_RpPb_theory[1][ipt]->SetLineColor(kOrange+2);
    g_RpPb_theory[1][ipt]->SetFillStyle(3345);
    //g_RpPb_theory[1][ipt]->SetFillStyle(3004);
    g_RpPb_theory_line[1][ipt]->SetFillColorAlpha(kOrange+2,0.);
    g_RpPb_theory_line[1][ipt]->SetLineColor(kOrange+2);
    g_RpPb_theory_line[1][ipt]->SetFillStyle(1001);
    g_RpPb_theory[2][ipt]->SetFillColor(kGreen+2);
    g_RpPb_theory[2][ipt]->SetLineColor(kGreen+2);
    g_RpPb_theory[2][ipt]->SetFillStyle(3454);
    //g_RpPb_theory[2][ipt]->SetFillStyle(3005);
    g_RpPb_theory_line[2][ipt]->SetFillColorAlpha(kGreen+2,0.);
    g_RpPb_theory_line[2][ipt]->SetLineColor(kGreen+2);
    g_RpPb_theory_line[2][ipt]->SetFillStyle(1001);
  } 
	///////////////////////////////////////////////////
	//// Draw
  ///////////////////////////////////////////////////
	
	//TLegend *legBL1 = new TLegend(0.195, 0.168, 0.38, 0.333);
	TLegend *legBL1 = new TLegend(0.195, 0.168, 0.38, 0.388);
	SetLegendStyle(legBL1);
	//legBL1->SetTextSize(0.05);
	legBL1->SetTextSize(0.037);
  
  TLatex* globtex = new TLatex();
	globtex->SetNDC();
	globtex->SetTextAlign(12); //1:left, 2:vertical center
  //globtex->SetTextAlign(32); //3:right 2:vertical center
  globtex->SetTextFont(42);
	globtex->SetTextSize(0.075);
 
  //// global uncertainty from lumi
	TBox * globbox_pp = new TBox(-3.0, 1-pp_lumi_relerr, -2.8, 1+pp_lumi_relerr);
	globbox_pp->SetFillColorAlpha(kGray+2,0.5);
	globbox_pp->SetLineColor(kBlack);
	TBox * globbox_pa = new TBox(-2.8, 1-pPb_lumi_relerr, -2.6, 1+pPb_lumi_relerr);
	globbox_pa->SetFillColorAlpha(kWhite,0.5);
	globbox_pa->SetLineColor(kBlack);
	TBox * globbox_all = new TBox(-2.7, 1-glb_err, -2.5, 1+glb_err);
	globbox_all->SetFillColorAlpha(kGray+2,0.5);
	globbox_all->SetLineColor(kBlack);

  TCanvas* c1 = new TCanvas("c1","c1",600,600);
  c1->cd();
  
  g_RpPb_sys[0]->Draw("A5"); 
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    if (ith==0){
      g_RpPb_theory[ith][0]->Draw("5");
      g_RpPb_theory_line[ith][0]->Draw("5");
    }
  }
//  if (isPoint) { g_RpPb_sys[0]->Draw("5"); }
  globbox_all->Draw("lf");
  solidLine(-2.7,1.,2.1,1.,1,1);
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    if (ith!=0){
      g_RpPb_theory[ith][0]->Draw("5");
    }
    g_RpPb_theory_line[ith][0]->Draw("5");
  }
  if (isPoint) {
    g_RpPb_sys_line[0]->Draw("5");
    g_RpPb[0]->Draw("p");
  }

  globtex->SetTextAlign(12);
	globtex->SetTextSize(0.045);
	globtex->SetTextFont(42);
  globtex->DrawLatex(0.21, 0.84, "6.5 < p_{T} < 10 GeV/c");
  
  TLegendEntry *ent_data=legBL1->AddEntry("ent_data"," Data","pf");
	ent_data->SetFillColorAlpha(kRed-10,0.5);
	ent_data->SetLineColor(kPink-6);
	ent_data->SetMarkerColor(kPink-6);
  ent_data->SetMarkerStyle(kFullCircle);
  ent_data->SetLineWidth(1);
//  ent_data->SetMarkerSize(1.9);
  ent_data->SetFillStyle(1001);
  TLegendEntry *ent1_thr=legBL1->AddEntry("ent1_thr"," EPS09 NLO (Vogt)","f");
	ent1_thr->SetFillColorAlpha(kAzure+1,0.5);
	ent1_thr->SetLineColor(kAzure+5);
  ent1_thr->SetFillStyle(1001);
  TLegendEntry *ent2_thr=legBL1->AddEntry("ent2_thr"," EPS09 NLO (Lansberg-Shao)","f");
	ent2_thr->SetFillColor(kOrange+2);
	ent2_thr->SetLineColor(kOrange+2);
  ent2_thr->SetFillStyle(3345);
  TLegendEntry *ent3_thr=legBL1->AddEntry("ent3_thr"," nCTEQ15 NLO (Lansberg-Shao)","f");
	ent3_thr->SetFillColor(kGreen+2);
	ent3_thr->SetLineColor(kGreen+2);
  ent3_thr->SetFillStyle(3454);
//  TLegendEntry *ent5_thr=legBL1->AddEntry("ent5_thr","(Lansberg-Shao)","f");
//	ent5_thr->SetFillColor(kWhite);
//	ent5_thr->SetLineColor(kWhite);
//  ent5_thr->SetFillStyle(1001);
	legBL1->Draw();

  globtex->SetTextAlign(32); //3:right 2:vertical center	
  globtex->SetTextSize(0.048);
	globtex->SetTextFont(42);
	if (isPrompt) globtex->DrawLatex(0.92, 0.77, "Prompt J/#psi");
	else globtex->DrawLatex(0.92, 0.77, "Non-prompt J/#psi");
	
  CMS_lumi( c1, isPA, iPos );
    
  c1->SaveAs(Form("plot_theory/comp_RpPb_rap_pt1_isSmoothened%d_Overlay.pdf",(int)isSmoothened));
  c1->SaveAs(Form("plot_theory/comp_RpPb_rap_pt1_isSmoothened%d_Overlay.png",(int)isSmoothened));
 
 
  TCanvas* c2 = new TCanvas("c2","c2",600,600);
  c2->cd();
  
  g_RpPb_sys[1]->Draw("A5"); 
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    if (ith==0){
      g_RpPb_theory[ith][1]->Draw("5");
      g_RpPb_theory_line[ith][1]->Draw("5");
    }
  }
//  if (isPoint) { g_RpPb_sys[1]->Draw("5"); }
  globbox_all->Draw("lf");
  solidLine(-2.7,1.,2.1,1.,1,1);
  for (int ith = 0 ; ith < nTheory; ith ++ ) {
    if (ith!=0){
      g_RpPb_theory[ith][1]->Draw("5");
    }
    g_RpPb_theory_line[ith][1]->Draw("5");
  }
  if (isPoint) {
    g_RpPb_sys_line[1]->Draw("5");
    g_RpPb[1]->Draw("p");
  }
  
  globtex->SetTextAlign(12);
	globtex->SetTextSize(0.045);
	globtex->SetTextFont(42);
  globtex->DrawLatex(0.21, 0.84, "10 < p_{T} < 30 GeV/c");
  
  legBL1->Draw();
  
  globtex->SetTextAlign(32); //3:right 2:vertical center	
  globtex->SetTextSize(0.048);
	globtex->SetTextFont(42);
	if (isPrompt) globtex->DrawLatex(0.92, 0.77, "Prompt J/#psi");
	else globtex->DrawLatex(0.92, 0.77, "Non-prompt J/#psi");
	
  CMS_lumi( c2, isPA, iPos );
    
  c2->SaveAs(Form("plot_theory/comp_RpPb_rap_pt2_isSmoothened%d_Overlay.pdf",(int)isSmoothened));
  c2->SaveAs(Form("plot_theory/comp_RpPb_rap_pt2_isSmoothened%d_Overlay.png",(int)isSmoothened));
 
 
 
  
  ///////////////////////////////////////////////////////////////////
  // save as a root file
//  TFile* outFile = new TFile(Form("plot_theory/comp_RpPb_rap_isSmoothened%d_Overlay.root",(int)isSmoothened),"RECREATE");
//  outFile->cd();
//  for (int ipt = 0 ; ipt < nPtRpPb; ipt ++ ) {
//    g_RpPb_theory[ipt]->Write();
//  } 

  return;
}
//// runCode // 0=merged, 1=1stRun, 2=2ndRun
void draw_1D_RFB_ETHF_tworange(char* dirName = "6rap3pt", int runCode=0,  bool isPrompt=false)
{
    gROOT->Macro("./tdrstyle_kyo.C");
    gStyle->SetTitleSize(0.046, "XYZ");
    gStyle->SetEndErrorSize(0);
    gStyle->SetOptTitle(0);
    gStyle->SetPadTopMargin(0.075);
    gStyle->SetPadBottomMargin(0.13); //KYO
    gStyle->SetPadLeftMargin(0.13); //KYO
    gStyle->SetPadRightMargin(0.075);
    gStyle->SetTitleXOffset(1.15);
    gStyle->SetTitleYOffset(1.22);

    writeExtraText = true;
    extraText  = "Preliminary";
    lumi_502TeV  = "34.6 nb^{-1}";
    int iPeriod = 0;
    int iPos=0;

    //double pxshift = 0.5;
    double pxshift = 1.;

    // set info.
    const Double_t br = 0.0593 ;
    const Double_t brErr = 0.0006;
    Double_t lumi_nb;
    Double_t lumi_nb_err;
    Double_t lumi_mub;
    Double_t lumi_mub_err;
    string runstring;
    string lumistring;
    string cmsstring = "CMS preliminary";
    string beamstring = "pPb #sqrt{s_{NN}} = 5.02 TeV";
    if (runCode ==0) {
        runstring = "All";
        lumi_nb =34.622;
        lumi_nb_err=1.2;
    }
    else if (runCode == 1) {
        runstring = "Pbp";    //1stRun
        lumi_nb =20.7;
        lumi_nb_err=0.7;
    }
    else if (runCode == 2) {
        runstring = "pPb";    //2ndRun
        lumi_nb = 14.0;
        lumi_nb_err=0.5;
    }
    else {
        cout << " *** Error!!! choose runCode 0, 1, or 2 " << endl;
        return ;
    }
    lumistring = Form("L_{int} = %.1f nb^{  -1}", lumi_nb);
    lumi_mub = lumi_nb * 1000; // (nb)^{-1} -> {#mub}^{-1}
    lumi_mub_err = lumi_nb_err * 1000; // (nb)^{-1} -> {#mub}^{-1}

    /////////////////////////////////////////////////////////////////////////
    // bin center & systematic uncertainties by hand
    //inh=0 : pT 5-6.5, rap 1.5-1.93
    //inh=1 : pT 6.5-30, rap 1.5-1.93
    //inh=2 : pT 6.5-30, rap 0.9-1.5
    //inh=3 : pT 6.5-30, rap 0.0-0.9
    const int nRap = 6;
    const int nRapTmp = nRap+1;
    const int nPt = 3;
    const int nPtTmp = nPt+1;
    const int nEt = 3;
    const int nEtTmp = nEt+1;
    const int nHist = 4;
    const int nHistTmp = nHist+1;
    Double_t pxtmp[nHist][nEt]; //x point to fill temp
    Double_t pytmp[nHist][nEt]; //y point to fill temp
    Double_t eytmp[nHist][nEt]; //y stat error to fill temp
    Double_t px[nEt] = {9.4, 24.3, 37.2}; // x point
    Double_t ex[nEt] = {0.,0.,0.}; // x stat error
    Double_t exsys[nEt] = {0.5, 0.5, 0.5};; //x sys error
    Double_t eysys[nHist][nEt]; //absolute y sys error
    Double_t eysysrel[nHist][nEt]; //relative y sys error
    Double_t eysysrelPR[nHist][nEt] = {
        {0.05299,0.06155,0.06715}, //1.5-1.93 low
        {0.05088,0.05442,0.05913}, //1.5-1.93
        {0.03741,0.04958,0.04227}, //0.9-1.5
        {0.04425,0.04528,0.05314} //0.0-0.9
    };
    Double_t eysysrelNP[nHist][nEt] = {
        {0.04971,0.06138,0.06459}, // 1.5-1.93 low
        {0.05188,0.05442,0.05999}, //0.5-1.93
        {0.03694,0.04952,0.04221}, //0.9-1.5
        {0.04242,0.04349,0.05162} //0.0-0.9
    };

    for (int inh = 0; inh < nHist; inh++ ) {
        for (int iet = 0; iet < nEt; iet++ ) {
            if (isPrompt) eysysrel[inh][iet] = eysysrelPR[inh][iet];
            else eysysrel[inh][iet] = eysysrelNP[inh][iet];
        }
    }

    //rap array in yCM (from forward to backward)
    Double_t rapArrNumFB[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93};// for pt dist.
    //Double_t rapArrNumBF[nRapTmp] = {-1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
    Double_t rapBinW[nRap];
    for (Int_t iy=0; iy<nRap; iy++) {
        rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1];
        cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl;
    }
    //pt array
    Double_t ptArrNum[nPtTmp] = {5.0, 6.5, 10., 30.}; //6rap3pt
    Double_t ptBinW[nPt];
    for (Int_t ipt=0; ipt<nPt; ipt++) {
        ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt];
        cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl;
    }
    //ethf array
    Double_t etArrNum[nEtTmp] = {0.0, 20.0, 30.0, 120.0};

    // array string
    string rapArr[nRap];
    for (Int_t iy=0; iy<nRap; iy++) {
        formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
        cout << iy <<"th rapArr = " << rapArr[iy] << endl;
    }
    string ptArr[nPt];
    for (Int_t ipt=0; ipt<nPt; ipt++) {
        formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
        cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
    }
    string etArr[nEt];
    for (Int_t i=0; i<nEt; i++) {
        formEtArr(etArrNum[i], etArrNum[i+1], &etArr[i]);
        cout << "etArr["<<i<<"] = "<< etArr[i].c_str() << endl;
    }

    // --- read-in file
    TFile * f2D = new TFile(Form("../fittingResult/total2Dhist_%s.root",dirName));
    cout << "dirName = " << dirName << endl;
    cout << "runCode = " << runCode << ", runstring = " << runstring.c_str() << endl;

    // --- read-in 2D hist for corrected yield
    TH2D* h2D_corrY_Pbp[nEt];
    TH2D* h2D_corrY_pPb[nEt];
    for (int iet=0; iet<nEt; iet++) {
        if (isPrompt) {
            h2D_corrY_Pbp[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_PR_Pbp_%d",iet));
            h2D_corrY_pPb[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_PR_pPb_%d",iet));
        }
        else {
            h2D_corrY_Pbp[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_NP_Pbp_%d",iet));
            h2D_corrY_pPb[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_NP_pPb_%d",iet));
        }
        cout << iet << "th h2D_corrY_Pbp = " << h2D_corrY_Pbp[iet] << endl;
        cout << iet << "th h2D_corrY_pPb = " << h2D_corrY_pPb[iet] << endl;
    }

    const int nbinsX = h2D_corrY_Pbp[0]->GetNbinsX();
    const int nbinsY = h2D_corrY_Pbp[0]->GetNbinsY();
    cout << "nbinsX = " << nbinsX << endl;
    cout << "nbinsY = " << nbinsY << endl;
    if (nbinsX != nRap) {
        cout << " *** Error!!! nbinsX != nRap";
        return;
    };
    if (nbinsY != nPt) {
        cout << " *** Error!!! nbinsY != nPt";
        return;
    };

    // ---  projection to 1D hist
    TH1D* h1D_corrY_Pbp[nEt][nbinsX];
    TH1D* h1D_corrY_pPb[nEt][nbinsX];
    // iy=0 refers to forwards !!! (ordering here)
    for (Int_t iet=0; iet<nEt; iet++) {
        for (Int_t iy = 0; iy < nbinsX; iy++) {
            h1D_corrY_Pbp[iet][iy] = h2D_corrY_Pbp[iet]->ProjectionY(Form("h1D_corrY_Pbp_%d_%d",iet,iy),iy+1,iy+1);
            h1D_corrY_Pbp[iet][iy]->SetName(Form("h1D_corrY_Pbp_%d_%d",iet,iy));
            //for 2nd run
            h1D_corrY_pPb[iet][iy] = h2D_corrY_pPb[iet]->ProjectionY(Form("h1D_corrY_pPb_%d_%d",iet,iy),nbinsX-iy,nbinsX-iy);
            h1D_corrY_pPb[iet][iy]->SetName(Form("h1D_corrY_pPb_%d_%d",iet,iy));
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////
    // 1) merge Pbp+pPb corrected yield
    TH1D* h1D_corrY_tot[nEt][nbinsX];
    for (Int_t iet=0; iet<nEt; iet++) {
        for (Int_t iy = 0; iy < nbinsX; iy++) {
            if (runCode ==0) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_Pbp[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
                h1D_corrY_tot[iet][iy]->Add(h1D_corrY_pPb[iet][iy]);
            }
            else if (runCode ==1) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_Pbp[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
            }
            else if (runCode ==2) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_pPb[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
            }
        }
    }

    //////////////////////////////////////////////////////////////////
    /////////// calculate RFB

    const int nRapRFB = 3;
    TH1D* h1D_RFB_tmp[nEt][nbinsX]; // corrYield with merged pT
    TH1D* h1D_RFB[nEt][nRapRFB]; // actual RFB vs pt

    // bin settingg
    string rapAbsArr[nRap];
    for (Int_t iy=0; iy<nRapRFB; iy++) {
        formAbsRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapAbsArr[iy]);
        cout << iy <<"th rapAbsArr = " << rapAbsArr[iy] << endl;
    }
    Double_t ptArrRFBNum[] = {5.0, 6.5, 30.};
    const Int_t nPtRFB = sizeof(ptArrRFBNum)/sizeof(Double_t)-1;
    cout << "nPtRFB = " << nPtRFB << endl;

    // merging pT bins (KYO - byHand)
    double tmpPRval01, tmpPRerr01, tmpPRval02, tmpPRerr02;
    double actPRval01, actPRerr01, actPRval02, actPRerr02;
    for (int iet=0; iet<nEt; iet++) {
        for (int iy=0; iy<nRapRFB*2; iy++) {
            h1D_RFB_tmp[iet][iy]= new TH1D(Form("h1D_RFB_tmp_%d_%d",iet,iy),Form("h1D_RFB_tmp_%d_%d",iet,iy),nPtRFB,ptArrRFBNum);
            h1D_RFB_tmp[iet][iy]->Sumw2();
            actPRval01=0;
            actPRval02=0;
            actPRerr01=0;
            actPRerr02=0;
            // 1) pT 5-6.5 GeV
            tmpPRval01=0;
            tmpPRval02=0;
            tmpPRerr01=0;
            tmpPRerr02=0;
            if (iy==0 || iy==nRapRFB*2-1) {
                actPRval01=h1D_corrY_tot[iet][iy]->GetBinContent(1);
                actPRerr01=h1D_corrY_tot[iet][iy]->GetBinError(1);
                h1D_RFB_tmp[iet][iy]->SetBinContent(1,actPRval01);
                h1D_RFB_tmp[iet][iy]->SetBinError(1,actPRerr01);
            } else {
                h1D_RFB_tmp[iet][iy]->SetBinContent(1,0.);
                h1D_RFB_tmp[iet][iy]->SetBinError(1,0.);
            }
            // 2) pT 6.5-30. GeV
            tmpPRval01=0;
            tmpPRval02=0;
            tmpPRerr01=0;
            tmpPRerr02=0;
            tmpPRval01=h1D_corrY_tot[iet][iy]->GetBinContent(2);
            tmpPRerr01=h1D_corrY_tot[iet][iy]->GetBinError(2);
            tmpPRval02=h1D_corrY_tot[iet][iy]->GetBinContent(3);
            tmpPRerr02=h1D_corrY_tot[iet][iy]->GetBinError(3);
            actPRval02=tmpPRval01+tmpPRval02;
            actPRerr02=TMath::Sqrt( TMath::Power(tmpPRerr01,2) + TMath::Power(tmpPRerr02,2) );
            h1D_RFB_tmp[iet][iy]->SetBinContent(2,actPRval02);
            h1D_RFB_tmp[iet][iy]->SetBinError(2,actPRerr02);
        }
    }

    // actual RFB calculation	vs pT!!
    for (int iet=0; iet<nEt; iet++) {
        for (int iy=0; iy<nRapRFB; iy++) {
            h1D_RFB[iet][iy] = (TH1D*)h1D_RFB_tmp[iet][iy]->Clone(Form("h1D_RFB_%d_%d",iet,iy));
            h1D_RFB[iet][iy]->Divide(h1D_RFB_tmp[iet][2*nRapRFB-iy-1]);
            cout << iet<<"th, "<<iy<<"th h1D_RFB = "<<h1D_RFB[iet][iy]<<endl;
        }
    }

    ///////////////////////////////////////////////
    //////// --- RFB vs ETHF : 4 histograms
    //inh=0 : pT 5-6.5, rap 1.5-1.93
    //inh=1 : pT 6.5-30, rap 1.5-1.93
    //inh=2 : pT 6.5-30, rap 0.9-1.5
    //inh=3 : pT 6.5-30, rap 0.0-0.9
    double tmpRFBval01, tmpRFBerr01, tmpRFBval02, tmpRFBerr02, tmpRFBval03, tmpRFBerr03;
    TH1D* h1D_RFB_ETHF[nHist];

    for (int inh=0; inh< nHist; inh++) {
        h1D_RFB_ETHF[inh]= new TH1D(Form("h1D_RFB_ETHF_%d",inh),Form("h1D_RFB_ETHF_%d",inh),nEt,etArrNum);
        h1D_RFB_ETHF[inh]->Sumw2();
        tmpRFBval01=0;
        tmpRFBerr01=0;
        tmpRFBval02=0;
        tmpRFBerr02=0;
        tmpRFBval03=0;
        tmpRFBerr03=0;
        for (int iet=0; iet<nEt; iet++) {
            if (inh==0) {
                tmpRFBval01=h1D_RFB[iet][0]->GetBinContent(1);
                tmpRFBerr01=h1D_RFB[iet][0]->GetBinError(1);
                h1D_RFB_ETHF[inh]->SetBinContent(iet+1,tmpRFBval01);
                h1D_RFB_ETHF[inh]->SetBinError(iet+1,tmpRFBerr01);
            }
            else {
                tmpRFBval01=h1D_RFB[iet][inh-1]->GetBinContent(2);
                tmpRFBerr01=h1D_RFB[iet][inh-1]->GetBinError(2);
                h1D_RFB_ETHF[inh]->SetBinContent(iet+1,tmpRFBval01);
                h1D_RFB_ETHF[inh]->SetBinError(iet+1,tmpRFBerr01);
            }
        }
    }

    //////////////////////////////////////////////////////////////////
    /////////// samey
    //////////////////////////////////////////////////////////////////
    TCanvas* c1 = new TCanvas("c1","c1",600,600);
    c1->cd();

//	TLegend *legBL = new TLegend(0.16, 0.16, 0.43, 0.41); //bottom left
    TLegend *legBL = new TLegend(0.16, 0.16, 0.40, 0.36); //bottom left
    TLegend *legBL2 = new TLegend(0.16, 0.16, 0.40, 0.40); //bottom left
//	TLegend *legUR = new TLegend(0.36, 0.77, 0.89, 0.95); //upper left
    TLegend *legUR = new TLegend(0.34, 0.71, 0.89, 0.88); //upper left
    SetLegendStyle(legBL);
    SetLegendStyle(legBL2);
    //legBL->SetTextSize(0.032);
    legBL->SetTextSize(0.037);
    legBL2->SetTextSize(0.037);

    //globtex box for beam, rapidity, pT info
    TLatex* globtex = new TLatex();
    globtex->SetNDC();
    //globtex->SetTextAlign(12); //1:left, 2:vertical center
    globtex->SetTextAlign(32); //3:right 2:vertical center
    globtex->SetTextFont(42);
    globtex->SetTextSize(0.04);

    // convert to TGraphAsymErrors
    //RFB
    TGraphAsymmErrors*gRFB[nHist];
    for (int inh=0; inh< nHist; inh++) {
        gRFB[inh] = new TGraphAsymmErrors(h1D_RFB_ETHF[inh]);
        gRFB[inh]->SetName(Form("gRFB_%d",inh));
        for (int iet=0; iet<nEt; iet++) {
            gRFB[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            eytmp[inh][iet] = gRFB[inh] -> GetErrorY(iet);
//			gRFB[inh]->SetPoint(iet, px[iet], pytmp[inh][iet]);
            gRFB[inh]->SetPoint(iet, px[iet]+pxshift*inh, pytmp[inh][iet]);
            gRFB[inh]->SetPointEXlow(iet, ex[inh]);
            gRFB[inh]->SetPointEXhigh(iet, ex[inh]);
        }
    }

    //sys
    TGraphAsymmErrors* gRFB_sys[nHist];
    for (int inh=0; inh< nHist; inh++) {
        gRFB_sys[inh] = new TGraphAsymmErrors(h1D_RFB_ETHF[inh]);
        gRFB_sys[inh]->SetName(Form("gRFB_sys_%d",inh));
        for (int iet=0; iet<nEt; iet++) {
            gRFB_sys[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            //abs err calcul.
            eysys[inh][iet] = eysysrel[inh][iet]*pytmp[inh][iet];
            //gRFB_sys[inh]->SetPoint(iet, px[iet], pytmp[inh][iet]);
            gRFB_sys[inh]->SetPoint(iet, px[iet]+pxshift*inh, pytmp[inh][iet]);
            gRFB_sys[inh]->SetPointError(iet, exsys[iet], exsys[iet], eysys[inh][iet], eysys[inh][iet]);
            cout << "" << endl;
            cout << "pytmp["<<inh<<"]["<<iet<<"] = " << pytmp[inh][iet]<<endl;
            cout << "eytmp["<<inh<<"]["<<iet<<"] = " << eytmp[inh][iet]<<endl;
            cout << "eysys["<<inh<<"]["<<iet<<"] = " << eysys[inh][iet]<<endl;
        }
    }

    gRFB_sys[0]->GetXaxis()->SetTitle("E_{T}^{HF |#eta|>4} [GeV]");
    gRFB_sys[0]->GetXaxis()->CenterTitle();
    gRFB_sys[0]->GetYaxis()->SetTitle("R_{FB}");
    gRFB_sys[0]->GetXaxis()->SetLimits(0.,50.0);
    gRFB_sys[0]->SetMinimum(0.5);
    gRFB_sys[0]->SetMaximum(1.15);
    gRFB_sys[0]->SetFillColor(kViolet-9);
    gRFB_sys[0]->Draw("A2");
    gRFB_sys[1]->SetFillColor(kTeal-9);
    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->SetFillColor(kRed-9);
//	gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->SetFillColor(kAzure-9);
//	gRFB_sys[3]->Draw("2");

    SetGraphStyle(gRFB[0], 8, 2); //1.5-1.93 low
    SetGraphStyle(gRFB[1], 0, 5); //1.5-1.93
    SetGraphStyle(gRFB[2], 1, 3); //0.9-1.5
    SetGraphStyle(gRFB[3], 2, 0); //0-0.9
    gRFB[0]->SetMarkerSize(1.6);
    gRFB[0]->Draw("P");
    gRFB[1]->SetMarkerSize(2.1);
    gRFB[1]->Draw("P");

    dashedLine(0.,1.,50.,1.,1,1);
    legBL -> SetHeader ("1.5 < |y_{CM}| < 1.93");
    legBL -> AddEntry(gRFB[0],"5 < p_{T} < 6.5 GeV/c","lp");
    legBL -> AddEntry(gRFB[1],"6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[0],"1.5 < |y_{CM}| < 1.93,   5 < p_{T} < 6.5 GeV/c","lp");
//	legBL -> AddEntry(gRFB[1],"1.5 < |y_{CM}| < 1.93,  6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[2],"0.9 < |y_{CM}| < 1.5,   6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[3],"0.0 < |y_{CM}| < 0.9,   6.5 < p_{T} < 30 GeV/c","lp");
    legBL->Draw();
    globtex->SetTextSize(0.045);
    globtex->SetTextFont(62);
    if (isPrompt) globtex->DrawLatex(0.88, 0.86, "Prompt J/#psi");
    else globtex->DrawLatex(0.88, 0.86, "Non-prompt J/#psi");

    CMS_lumi( c1, iPeriod, iPos );
    c1->Update();
    c1->SaveAs(Form("RFB_%s/RFB_ETHF_samey_isPrompt%d_%s.pdf",dirName,(int)isPrompt,runstring.c_str()));
    c1->SaveAs(Form("RFB_%s/RFB_ETHF_samey_isPrompt%d_%s.png",dirName,(int)isPrompt,runstring.c_str()));
    legBL->Clear();


    //////////////////////////////////////////////////////////////////
    /////////// samept
    //////////////////////////////////////////////////////////////////
    TCanvas* c2 = new TCanvas("c2","c2",600,600);
    c2->cd();

    for (int inh=1; inh< nHist; inh++) {
        for (int iet=0; iet<nEt; iet++) {
            gRFB[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            eytmp[inh][iet] = gRFB[inh] -> GetErrorY(iet);
            gRFB[inh]->SetPoint(iet, px[iet]+pxshift*(nHist-1-inh), pytmp[inh][iet]);
            //sys
            gRFB_sys[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            gRFB_sys[inh]->SetPoint(iet, px[iet]+pxshift*(nHist-1-inh), pytmp[inh][iet]);
        }
    }

    gRFB_sys[0]->GetXaxis()->SetTitle("E_{T}^{HF |#eta|>4} [GeV]");
    gRFB_sys[0]->GetXaxis()->CenterTitle();
    gRFB_sys[0]->GetYaxis()->SetTitle("R_{FB}");
    gRFB_sys[0]->GetXaxis()->SetLimits(0.,50.0);
    gRFB_sys[0]->SetMinimum(0.5);
    gRFB_sys[0]->SetMaximum(1.15);
    gRFB_sys[0]->SetFillColor(kViolet-9);
    gRFB_sys[0]->Draw("A2");
    gRFB_sys[1]->SetFillColor(kTeal-9);
    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->SetFillColor(kRed-9);
//	gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->SetFillColor(kAzure-9);
//	gRFB_sys[3]->Draw("2");

    SetGraphStyle(gRFB[0], 8, 2); //1.5-1.93 low
    SetGraphStyle(gRFB[1], 0, 5); //1.5-1.93
    SetGraphStyle(gRFB[2], 1, 3); //0.9-1.5
    SetGraphStyle(gRFB[3], 2, 0); //0-0.9
    gRFB[0]->SetMarkerSize(1.6);
    gRFB[0]->Draw("P");
    gRFB[1]->SetMarkerSize(2.1);
    gRFB[1]->Draw("P");








    // just for drawing
    gRFB_sys[0]->SetFillColor(kWhite);
    gRFB_sys[0]->Draw("A2");

    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->Draw("2");

    gRFB[1]->Draw("P");
    gRFB[2]->Draw("P");
    gRFB[3]->Draw("P");

    dashedLine(0.,1.,50.,1.,1,1);
    legBL2 -> SetHeader ("6.5 < p_{T} < 30 GeV/c");
    legBL2 -> AddEntry(gRFB[3],"0.0 < |y_{CM}| < 0.9","lp");
    legBL2 -> AddEntry(gRFB[2],"0.9 < |y_{CM}| < 1.5","lp");
    legBL2 -> AddEntry(gRFB[1],"1.5 < |y_{CM}| < 1.93","lp");
    legBL2 ->Draw();
    globtex->SetTextSize(0.045);
    globtex->SetTextFont(62);
    if (isPrompt) globtex->DrawLatex(0.88, 0.86, "Prompt J/#psi");
    else globtex->DrawLatex(0.88, 0.86, "Non-prompt J/#psi");

    CMS_lumi( c2, iPeriod, iPos );
    c2->Update();
    c2->SaveAs(Form("RFB_%s/RFB_ETHF_samept_isPrompt%d_%s.pdf",dirName,(int)isPrompt,runstring.c_str()));
    c2->SaveAs(Form("RFB_%s/RFB_ETHF_samept_isPrompt%d_%s.png",dirName,(int)isPrompt,runstring.c_str()));

#if 0
    ///////////////////////////////////////////////////////////////////
    // save as a root file
    TFile *outFile = new TFile(Form("RFB_%s/RFB_ETHF_FWonly_isPrompt%d.root",dirName,(int)isPrompt),"RECREATE");
    outFile->cd();
    for (int inh=0; inh< nHist; inh++) {
        gRFB_sys[inh]->Write();
        gRFB[inh]->Write();
    }
    outFile->Close();
#endif

    return;

} // end of main func.
void postFitPlotsCOMBINEINSERT(TString name="collMass",TString fileDataMuHad0Jet="asdf", TString fileDataMuHad1Jet = "asdf", TString fileDataMuHad2Jet = "asdf", TString fileDataMuEle0Jet = "asdf", TString fileDataMuEle1Jet = "asdf", TString fileDataMuEle2Jet = "asdf", TString file="fit2_signalV5_collMass_type1.root", TString dirInternal="filesBoosted", TString Xaxis="M_{#mu,#tau}_{coll} [GeV]", TString Yaxis="Events / 20 GeV", double xmin=200, double xmax=300, double ymin=-2, double ymax=2, bool setLogY=false, double legx1=0.6, double legy1=0.9, double legx2=0.9, double legy2=0.5, double MAX=-1, double MIN=-1, bool mutau0=true, bool mutau1=true, bool mutau2=true, bool muele0=true, bool muele1=true, bool muele2=true, bool REBIN=true, bool weightSOverSB=true,TString channelName="#mu#tau", double minsubs=-1, double maxsubs=-1){


	gROOT->LoadMacro("tdrstyle.C");
	setTDRStyle();
	double kForPlotting=1;
	double branchingratioTauTau=0.063;
	double branchingratioTauMu=0.1;
	double Lumi=19717;

	gROOT->LoadMacro("CMS_lumi.C");
	writeExtraText = false;
	int iPeriod = 2;
	// second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot
	int iPos=11;// : top-left, left-aligned
	// iPos=33 : top-right, right-aligned
	// iPos=22 : center, centered
	// mode generally :
	//   iPos = 10*(alignement 1/2/3) + position (1/2/3 = left/center/right)
	//  example_plot( iPeriod, 11 );  // left-aligned
	//  example_plot( iPeriod, 33 );  // right-aligned
	//  example_plot( iPeriod, 0 );   // out of frame (in exceptional cases)
	//  example_plot( iPeriod, 11 );  // default: left-aligned
	//  example_plot( iPeriod, 22 );  // centered
	//  example_plot( iPeriod, 33 );  // right-aligned


	bool muonchannels[3]={mutau0,mutau1,mutau2};
	bool elechannels[3]={muele0,muele1,muele2};

	int NBins=30; 
	if(mutau2 || muele2 || REBIN) { REBIN=true; NBins=15;}

	TFile *_fileMC= new TFile("CombinedPlots20PAS/"+file);
	TFile *_fileDataMuHad0Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad0Jet);
        TFile *_fileDataMuHad1Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad1Jet);
        TFile *_fileDataMuHad2Jet= new TFile("CombinedPlots20PAS/"+fileDataMuHad2Jet);
        TFile *_fileDataMuEle0Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle0Jet);
        TFile *_fileDataMuEle1Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle1Jet);
        TFile *_fileDataMuEle2Jet= new TFile("CombinedPlots20PAS/"+fileDataMuEle2Jet);


	//TString dirInternalAllMU[3]={dirInternal+"/datacard_gg0_pfMetFixOldjesNewFakeShape",dirInternal+"/datacard_gg1_pfMetFixOldjesNewFakeShape", dirInternal+"/datacard_vbf20_pfMetFixOldjesNewFakeShape"};
        TString dirInternalAllMU[3]={dirInternal+"/datacard_MuTau_0Jet_new",dirInternal+"/datacard_MuTau_1Jet_new", dirInternal+"/datacard_vbf_PAS20"};
	TString dirInternalAllELE[3]={dirInternal+"/datacard_MuEle_0Jet",dirInternal+"/datacard_MuEle_1Jet", dirInternal+"/datacard_MuEle_2Jet"};

	TString dirInternalSignal="shapes_prefit";

	TH1F* hdata_obs = new TH1F("hdata_obs","",NBins,0,300);
	TH1F* hFAKES = new TH1F("hFAKES","",NBins,0,300);
	TH1F* hFAKESLEPTON = new TH1F("hFAKESLEPTON","",NBins,0,300);
	TH1F* hDY = new TH1F("hDY","",NBins,0,300);
	TH1F* hWW = new TH1F("hWW","",NBins,0,300);
	TH1F* hTOP = new TH1F("hTOP","",NBins,0,300);
	TH1F* hTT = new TH1F("hTT","",NBins,0,300);
	TH1F* hZTauTau = new TH1F("hZTauTau","",NBins,0,300);
	TH1F* hLFVVBF126 = new TH1F("hLFVVBF126","",NBins,0,300);
	TH1F* hSMVBF126 = new TH1F("hSMVBF126","",NBins,0,300);
	TH1F* hSMHWWVBF126 = new TH1F("hSMHWWVBF126","",NBins,0,300);
	TH1F* hLFVGG126 = new TH1F("hLFVGG126","",NBins,0,300);
	TH1F* hSMGG126 = new TH1F("hSMGG126","",NBins,0,300);
	TH1F* hSMHWWGG126 = new TH1F("hSMHWWGG126","",NBins,0,300);
	TH1F* hWGamma = new TH1F("hWGamma","",NBins,0,300);
	TH1F* hWGammaStar = new TH1F("hWGammaStar","",NBins,0,300);

	double weightMuTau[3]={1,1,1};
	double weightMuEle[3]={1,1,1};

	int binA=hdata_obs->FindBin(100);
	int binB=hdata_obs->FindBin(150);

	for (int i=0; i<3; i++){
		cout << "starting" << i <<endl;
		if(muonchannels[i]!=true) continue;
		TH1F *hFAKES_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/fakes");hFAKES_2->SetName("fakesHisto");
		TString Extra="/zjetsother";
		if(i==2) Extra="/fakes"; // in the postfit directory the DY for VBF is not saved, since it has 0 events
		TH1F *hDY_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+Extra); hDY_2->SetName("dyHisto");
		TH1F *hWW_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ww");
		TH1F *hTOP_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/singlet");
		TH1F *hTT_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ttbar");
		TH1F *hZTauTau_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/ztautau");
		TH1F *hLFVVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/LFVVBF");
		TH1F *hLFVGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/LFVGG");
		TH1F *hSMGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/SMGG126");
		TH1F *hSMVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/SMVBF126");
		Extra="/fakes";
		if(i!=0) Extra="/WWGG126";
		TH1F *hSMHWWGG126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+Extra); hSMHWWGG126_2->SetName("smwwgg");
		if(i==0) hSMHWWGG126_2->Scale(0);
		TH1F *hSMHWWVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllMU[i]+"/WWVBF126"); hSMHWWVBF126_2->SetName("wwsm");
		cout << "got histos" << endl;
		if(i!=2 && (REBIN)) {
			hFAKES_2->Rebin(2); hDY_2->Rebin(2); hWW_2->Rebin(2); hTOP_2->Rebin(2); hTT_2->Rebin(2); hZTauTau_2->Rebin(2);
			hLFVVBF126_2->Rebin(2); hLFVGG126_2->Rebin(2); hSMGG126_2->Rebin(2); hSMVBF126_2->Rebin(2);
			hSMHWWVBF126_2->Rebin(2);
			if(i!=0) hSMHWWGG126_2->Rebin(2);
		}

		// WEIGHT	
		double bckg=hWW_2->Integral(binA,binB)+hFAKES_2->Integral(binA,binB) + hTOP_2->Integral(binA,binB) + hTT_2->Integral(binA,binB) + hZTauTau_2->Integral(binA,binB);
		bckg+=hSMVBF126_2->Integral(binA,binB)+hSMGG126_2->Integral(binA,binB)+hSMHWWVBF126_2->Integral(binA,binB);
		if(i!=2) bckg+=hDY_2->Integral(binA,binB);
		else hDY_2->Scale(0);
		if(i!=0) bckg+=hSMHWWGG126_2->Integral(binA,binB);
		else hSMHWWGG126_2->Scale(0);

		double signal=hLFVGG126_2->Integral(binA,binB)+hLFVVBF126_2->Integral(binA,binB);

		weightMuTau[i]=signal/(signal+bckg);
		cout<<"Weighting MuTau Channel  "<<i<<" --> "<<weightMuTau[i]<<endl;

		if(weightSOverSB){
			hFAKES_2->Scale(weightMuTau[i]);
			hDY_2->Scale(weightMuTau[i]);
			hWW_2->Scale(weightMuTau[i]);
			hTOP_2->Scale(weightMuTau[i]);
			hTT_2->Scale(weightMuTau[i]);
			hZTauTau_2->Scale(weightMuTau[i]);
			hLFVVBF126_2->Scale(weightMuTau[i]);
			hLFVGG126_2->Scale(weightMuTau[i]);
			hSMVBF126_2->Scale(weightMuTau[i]);
			hSMGG126_2->Scale(weightMuTau[i]);
			hSMHWWVBF126_2->Scale(weightMuTau[i]);
			hSMHWWGG126_2->Scale(weightMuTau[i]);
		}

		// MERGE

		fillNewHisto(hFAKES,hFAKES_2);
		if(i!=2) fillNewHisto(hDY,hDY_2);
		fillNewHisto(hWW,hWW_2);
		fillNewHisto(hTOP,hTOP_2);
		fillNewHisto(hTT,hTT_2);
		fillNewHisto(hZTauTau,hZTauTau_2);
		fillNewHisto(hLFVVBF126,hLFVVBF126_2);
		fillNewHisto(hLFVGG126,hLFVGG126_2);
		fillNewHisto(hSMVBF126,hSMVBF126_2);
		fillNewHisto(hSMGG126,hSMGG126_2);
		fillNewHisto(hSMHWWVBF126,hSMHWWVBF126_2);
		if(i!=0) fillNewHisto(hSMHWWGG126,hSMHWWGG126_2);

	}

	for (int i=0; i<3; i++){
		if(elechannels[i]!=true) continue;

		TH1F *hFAKESLEPTON_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/Fakes"); hFAKESLEPTON_2->SetName("hFAKESLEPTON_2");
		TString Extra="/DYnoTauTau";
		if(i==2) Extra="/Fakes"; // in the postfit directory the DY for VBF is not saved, since it has 0 events
		TH1F *hDY_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra);
		TH1F *hWW_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/WW");
		Extra="/WG";
		if(i!=1) Extra="/Fakes";
		TH1F *hWGamma_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra); hWGamma_2->SetName("hWGamma_2");
		Extra="/WGStar";
		if(i==2) Extra="/Fakes";
		TH1F *hWGammaStar_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+Extra); hWGammaStar_2->SetName("hWGammaStar_2");
		TH1F *hTOP_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/TOP");
		TH1F *hTT_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/TT");
		TH1F *hZTauTau_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ZTauTau");
		TH1F *hLFVVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/LFVVBF");
		TH1F *hLFVGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/LFVGG");
		TH1F *hSMGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ggHTauTau");
		TH1F *hSMVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/vbfHTauTau");
		TH1F *hSMHWWGG126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/ggHWW");
		TH1F *hSMHWWVBF126_2=(TH1F*)_fileMC->Get(dirInternalAllELE[i]+"/vbfHWW");

		if(i!=2 && (REBIN)) {
			hFAKESLEPTON_2->Rebin(2); hDY_2->Rebin(2); hWW_2->Rebin(2); hTOP_2->Rebin(2); hTT_2->Rebin(2); hZTauTau_2->Rebin(2);
			hLFVVBF126_2->Rebin(2); hLFVGG126_2->Rebin(2); hSMGG126_2->Rebin(2); hSMVBF126_2->Rebin(2);
			hSMHWWGG126_2->Rebin(2); hSMHWWVBF126_2->Rebin(2);
			hWGamma_2->Rebin(2); hWGammaStar_2->Rebin(2);
		}


		// WEIGHT       
		double bckg=hWW_2->Integral(binA,binB)+hFAKESLEPTON_2->Integral(binA,binB) + hTOP_2->Integral(binA,binB) + hTT_2->Integral(binA,binB) + hZTauTau_2->Integral(binA,binB);
		bckg+=hSMVBF126_2->Integral(binA,binB)+hSMGG126_2->Integral(binA,binB)+hSMHWWVBF126_2->Integral(binA,binB)+hSMHWWGG126_2->Integral(binA,binB);
		if(i!=2) {bckg+=hDY_2->Integral(binA,binB)+hWGammaStar_2->Integral(binA,binB);}
		else {hDY_2->Scale(0); hWGammaStar_2->Scale(0);}
		if (i==1) bckg+=hWGamma_2->Integral();
		else hWGamma_2->Scale(0);

		double signal=hLFVGG126_2->Integral()+hLFVVBF126_2->Integral();

		weightMuEle[i]=signal/(signal+bckg);
		cout<<"Weighting MuEle Channel  "<<i<<" --> "<<weightMuEle[i]<<endl;

		if(weightSOverSB){
			hFAKESLEPTON_2->Scale(weightMuEle[i]);
			hDY_2->Scale(weightMuEle[i]);
			hWW_2->Scale(weightMuEle[i]);
			hTOP_2->Scale(weightMuEle[i]);
			hTT_2->Scale(weightMuEle[i]);
			hZTauTau_2->Scale(weightMuEle[i]);
			hWGamma_2->Scale(weightMuEle[i]);
			hWGammaStar_2->Scale(weightMuEle[i]);
			hLFVVBF126_2->Scale(weightMuEle[i]);
			hLFVGG126_2->Scale(weightMuEle[i]);
			hSMVBF126_2->Scale(weightMuEle[i]);
			hSMGG126_2->Scale(weightMuEle[i]);
			hSMHWWVBF126_2->Scale(weightMuEle[i]);
			hSMHWWGG126_2->Scale(weightMuEle[i]);
		}

		fillNewHisto(hFAKESLEPTON,hFAKESLEPTON_2);
		if(i!=2) fillNewHisto(hDY,hDY_2);
		fillNewHisto(hWW,hWW_2);
		if(i!=2) fillNewHisto(hWGammaStar,hWGammaStar_2);
		if(i==1) fillNewHisto(hWGamma,hWGamma_2);
		fillNewHisto(hTOP,hTOP_2);
		fillNewHisto(hTT,hTT_2);
		fillNewHisto(hZTauTau,hZTauTau_2);
		fillNewHisto(hLFVVBF126,hLFVVBF126_2);
		fillNewHisto(hLFVGG126,hLFVGG126_2);
		fillNewHisto(hSMVBF126,hSMVBF126_2);
		fillNewHisto(hSMGG126,hSMGG126_2);
		fillNewHisto(hSMHWWVBF126,hSMHWWVBF126_2);
		fillNewHisto(hSMHWWGG126,hSMHWWGG126_2);



	}



	TString dirInternalDataAllMU[3]={"gg0mutau","boostmutau","vbfmutau"};

	for (int i=0; i<3; i++){
		cout << "starting data" <<endl;
		if(muonchannels[i]!=true) continue;
		if(i == 0){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad0Jet->Get(dirInternalDataAllMU[i]+"/data_obs");
		}
		else if (i  == 1){
		  TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad1Jet->Get(dirInternalDataAllMU[i]+"/data_obs");
		}
		else if (i == 2){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuHad2Jet->Get(dirInternalDataAllMU[i]+"/data_obs");
                }
		cout << "declared histos" << endl;
		//TH1F *hdata_obs_2=(TH1F*)_fileData->Get(dirInternalDataAllMU[i]+"/data_obs");
		hdata_obs_2->SetName("hdata_obs_2");
		if(weightSOverSB) hdata_obs_2->Scale(weightMuTau[i]);
		if(i!=2 && (REBIN)) hdata_obs_2->Rebin(2);
		cout << "filling data histo" << endl;
		fillNewHisto(hdata_obs,hdata_obs_2);
	}

	TString dirInternalDataAllELE[3]={"GGF","Boost","VBF"};

	for (int i=0; i<3; i++){
		if(elechannels[i]!=true) continue;
                if(i == 0){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle0Jet->Get(dirInternalDataAllELE[i]+"/data_obs");
                }
                else if (i  == 1){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle1Jet->Get(dirInternalDataAllELE[i]+"/data_obs");
                }
                else if (i == 2){
                  TH1F *hdata_obs_2=(TH1F*)_fileDataMuEle2Jet->Get(dirInternalDataAllELE[i]+"/data_obs");
                }

		//TH1F *hdata_obs_2=(TH1F*)_fileData->Get(dirInternalDataAllELE[i]+"/data_obs");
		hdata_obs_2->SetName("hdata_obs_2");
		if(weightSOverSB) hdata_obs_2->Scale(weightMuEle[i]);
		if(i!=2 && (REBIN) ) hdata_obs_2->Rebin(2);
		fillNewHisto(hdata_obs,hdata_obs_2);
	}



	TH1F *hSMHIGGS=(TH1F*) hSMVBF126->Clone();hSMHIGGS->SetName("hSMHIGGS");
	hSMHIGGS->Add(hSMGG126);
	TH1F *hSMHWWHIGGS=(TH1F*) hSMHWWVBF126->Clone();hSMHWWHIGGS->SetName("hSMHWWHIGGS");
	hSMHWWHIGGS->Add(hSMHWWGG126);

	hWGamma->Add(hWGammaStar);

	hFAKES->Add(hFAKESLEPTON);
	hFAKES->SetFillColor(kMagenta-10); hFAKES->SetLineColor(kMagenta+3); hFAKES->SetLineWidth(1);
	hFAKESLEPTON->SetFillColor(kMagenta-9); hFAKESLEPTON->SetLineColor(kMagenta+4); hFAKESLEPTON->SetLineWidth(1);

	hZTauTau->SetFillColor(kOrange-4); hZTauTau->SetLineColor(kOrange+4); hZTauTau->SetLineWidth(1);

        hDY->SetFillColor(kAzure+3); hDY->SetLineColor(kAzure+4); hDY->SetLineWidth(1);
        hWW->SetFillColor(kAzure+3); hWW->SetLineColor(kAzure+3); hWW->SetLineWidth(1);
        hWGamma->SetFillColor(kAzure+3); hWGamma->SetLineColor(kAzure+3); hWGamma->SetLineWidth(1);

        hTOP->SetFillColor(kGreen-2); hTOP->SetLineColor(kGreen+4); hTOP->SetLineWidth(1);
        hTT->SetFillColor(kGreen-2); hTT->SetLineColor(kGreen-2); hTT->SetLineWidth(1);



	hSMHIGGS->SetFillColor(kMagenta); hSMHIGGS->SetLineColor(kMagenta+1); hSMHIGGS->SetLineWidth(1);
	hSMHWWHIGGS->SetFillColor(kMagenta); hSMHWWHIGGS->SetLineColor(kMagenta+1); hSMHWWHIGGS->SetLineWidth(1);

	hLFVGG126->SetLineColor(kBlue);  hLFVGG126->SetLineWidth(3);
	hLFVVBF126->SetLineColor(kBlue); hLFVVBF126->SetLineWidth(3); hLFVVBF126->SetLineStyle(kDashed);
	hSMHIGGS->SetLineColor(kMagenta); hSMHIGGS->SetLineWidth(3);
	hSMHWWHIGGS->SetLineColor(kMagenta); hSMHWWHIGGS->SetLineWidth(3);



	hdata_obs->SetMarkerSize(1); // Closer to Daniel's

	// PLOT

	TCanvas *c1 = new TCanvas("canvas_"+name);
	TPad *Pad1= new TPad("pad1","",0,0.2,1,1); Pad1->Draw(); Pad1->cd();;
	Pad1->SetLeftMargin(0.2147651);
	Pad1->SetRightMargin(0.06543624);
	Pad1->SetTopMargin(0.07);
	Pad1->SetBottomMargin(0.04);

	TH1F* fullMC2=hFAKES->Clone();  fullMC2->Add(hZTauTau); fullMC2->Add(hTT); fullMC2->Add(hWW); fullMC2->Add(hWGamma);
	fullMC2->Add(hDY); fullMC2->Add(hTOP); fullMC2->Add(hSMHIGGS);  fullMC2->Add(hSMHWWHIGGS);
	fullMC2->SetFillColor(kGray+2); fullMC2->SetFillStyle(3002); fullMC2->SetMarkerSize(0); fullMC2->SetLineWidth(2);
	fullMC2->Draw("hist");

	fullMC2->GetXaxis()->SetTitle("");
	fullMC2->GetYaxis()->SetTitle(Yaxis);
	fullMC2->GetXaxis()->SetRangeUser(xmin,xmax);
	fullMC2->GetYaxis()->SetTitleOffset(1.2);
	fullMC2->GetYaxis()->SetTitleSize(0.05);
	fullMC2->GetXaxis()->SetNdivisions(0);
	fullMC2->GetYaxis()->SetLabelSize(0.04);


	TH1F* hSignal=hLFVGG126->Clone(); hSignal->SetName("hSignal");
	hSignal->Add(hLFVVBF126);

        hSignal->SetLineColor(kBlue);  hSignal->SetLineWidth(3);
	hSignal->SetLineStyle(2);

	THStack* stack = new THStack("stack","");
	stack->Add(hFAKES);
	stack->Add(hWW);
	stack->Add(hWGamma);
        stack->Add(hDY);
	stack->Add(hTT);
	stack->Add(hTOP);
	stack->Add(hZTauTau);
	stack->Add(hSMHIGGS);;
	stack->Add(hSMHWWHIGGS);
	stack->Add(hSignal);

	int bins=hdata_obs->GetNbinsX()+1;

	/*
	   cout<<"Yields  "<<endl;
	   cout<<"DATA	    \t" <<hdata_obs->Integral()+hdata_obs->GetBinContent(bins)<<endl;
	   cout<<"VV           \t" <<hWW->Integral()+hWW->GetBinContent(bins)<<endl;
	   cout<<"TOP          \t" <<hTOP->Integral()+hTOP->GetBinContent(bins)<<endl;
	   cout<<"TT           \t" <<hTT->Integral()+hTT->GetBinContent(bins)<<endl;
	   cout<<"DY           \t" <<hDY->Integral()+hDY->GetBinContent(bins)<<endl;
	   cout<<"ZTauTau      \t" <<hZTauTau->Integral()+hZTauTau->GetBinContent(bins)<<endl;
	   cout<<"FAKES        \t" <<hFAKES->Integral()+hFAKES->GetBinContent(bins)<<endl;
	   cout<<"hFAKESLEPTON \t" <<hFAKESLEPTON->Integral()+hFAKESLEPTON->GetBinContent(bins)<<endl;
	   cout<<"hSMHIGGS     \t" <<hSMHIGGS->Integral()+hSMHWWHIGGS->Integral()+hSMHIGGS->GetBinContent(bins)+hSMHWWHIGGS->GetBinContent(bins)<<endl;
	   cout<<"LFVGG126     \t" <<hLFVGG126->Integral()+hLFVGG126->GetBinContent(bins)<<endl;
	   cout<<"LFVVBF126    \t" <<hLFVVBF126->Integral()+hLFVVBF126->GetBinContent(bins)<<endl;
	 */
	stack->Draw("samehist");
	fullMC2->Draw("sames,E2");

//	hSignal->Draw("sameshist");

	double maxData=hdata_obs->GetMaximum();
	double maxMC=stack->GetMaximum()*1.2;
	double maxLFV=hSignal->GetMaximum();
	double minMC=stack->GetMinimum();

	if(maxData>maxMC) {maxMC=1.2*maxData;}
	if(maxLFV>maxMC) {maxMC=1.2*maxLFV;}
	if(MAX!=-1) {maxMC=MAX;}
	if(minMC<1) minMC=0;

	stack->SetMaximum(maxMC);
	stack->GetYaxis()->SetRangeUser(minMC,maxMC);
	fullMC2->SetMaximum(maxMC);
	fullMC2->GetYaxis()->SetRangeUser(minMC,maxMC);

	hdata_obs->Draw("sames");


	TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC");
	leg->SetFillColor(0);
	leg->SetBorderSize(0);
	leg->SetFillStyle(0);
	TLegendEntry *entry;
	entry=leg->AddEntry(hdata_obs,"Data","p");
	entry=leg->AddEntry(fullMC2,"Bkgd. uncertainty","f");
	//entry=leg->AddEntry(hSMHWWHIGGS,"SM HWW","f");
	entry=leg->AddEntry(hSMHIGGS,"SM H","f");
	entry=leg->AddEntry(hZTauTau,"Z#rightarrow#tau#tau","f");
        entry=leg->AddEntry(hDY,"Other","f");
        entry=leg->AddEntry(hTOP,"t#bar{t}, t, #bar{t}","f");
	entry=leg->AddEntry(hFAKES,"MisID'd #tau, e, #mu","f");
	entry=leg->AddEntry(hSignal,"LFV Higgs, (B=0.9%)","l");
	//        entry=leg->AddEntry("NULL","Br(h#rightarrow#mu#tau)=1%","");
	//        entry=leg->AddEntry("NULL","Br(h#rightarrow#tau#tau)=6%","");
	leg->Draw();


	/*
	   TLegend *leg = new TLegend(legx1,legy1,legx2,legy2,NULL,"brNDC");
	   leg->SetFillColor(0);
	   leg->SetBorderSize(0);
	   leg->SetFillStyle(0);
	   TLegendEntry *entry;
	   entry=leg->AddEntry(hdata_obs,"observed","p");
	   entry=leg->AddEntry(fullMC2,"bckg. uncertainty","fl");
	//entry=leg->AddEntry(hSMHWWHIGGS,"SM HWW","f");
	entry=leg->AddEntry(hSMHIGGS,"SM H","f");
	eblindBy=leg->AddEntry(hZTauTau,"Z+#tau#tau (embedd.)","f");
	eblindBy=leg->AddEntry(hDY,"EWK","f");
	entry=leg->AddEntry(hFAKES,"Fakes","f");
	entry=leg->AddEntry(hSignal,"LFV Higgs, (B=0.9%)","l");
	//        entry=leg->AddEntry("NULL","Br(h#rightarrow#mu#tau)=1%","");
	//        entry=leg->AddEntry("NULL","Br(h#rightarrow#tau#tau)=6%","");
	 */


	leg->Draw();

	CMS_lumi( Pad1, iPeriod, iPos );
	//cmsPrelim(Lumi);

	Pad1->SetLogy(setLogY);



	c1->cd(); TPad *Pad2= new TPad("pad2","",0,0,1,0.23); Pad2->Draw(); Pad2->cd();  Pad2->SetGridy();
	Pad2->SetLeftMargin(0.2147651);
	Pad2->SetRightMargin(0.06543624);
	Pad2->SetTopMargin(0.0);
	Pad2->SetBottomMargin(0.38);
	Pad2->SetFillStyle(0);

	TH1F * Ratio=hdata_obs->Clone(); Ratio->SetName("Ratio");
	Ratio->Add(fullMC2,-1);
	double dataRatio[16];
	double mcRatio[16];
	double errordataUpRatio[16];
	double errordataDownRatio[16];
	double xbinsRatio[16];
	double xerrorbinsRatio[16];
	Ratio->Divide(fullMC2);

	TH1F* RatioError = Ratio->Clone(); RatioError->SetName("RatioError");

	for (int i=0; i<RatioError->GetNbinsX()+1; i++){
		double error=fullMC2->GetBinError(i)*hdata_obs->GetBinContent(i)/fullMC2->GetBinContent(i)/fullMC2->GetBinContent(i);
		//double error=fullMC2->GetBinError(i)/fullMC2->GetBinContent(i);
		RatioError->SetBinContent(i,0);
		RatioError->SetBinError(i,error);
	}


	for (int j=0; j<16; j++){
		xbinsRatio[j]=300./15*(j-1)+10;
		xerrorbinsRatio[j]=10;
		dataRatio[j]=hdata_obs->GetBinContent(j);
		errordataUpRatio[j]=hdata_obs->GetBinError(j);
		errordataDownRatio[j]=hdata_obs->GetBinError(j);
		if(dataRatio[j]==0) {errordataUpRatio[j]=1.7; errordataDownRatio[j]=0;}
		mcRatio[j]=fullMC2->GetBinContent(j);
		dataRatio[j]-=mcRatio[j];
		if(mcRatio[j]!=0) {
			dataRatio[j]=dataRatio[j]/mcRatio[j];
			errordataUpRatio[j]=errordataUpRatio[j]/mcRatio[j];
			errordataDownRatio[j]=errordataDownRatio[j]/mcRatio[j];
		}else{
			dataRatio[j]=0;
			errordataUpRatio[j]=0;
			errordataDownRatio[j]=0;
		}
		double error=0;
		if(fullMC2->GetBinContent(j)!=0) error=fullMC2->GetBinError(j)*hdata_obs->GetBinContent(j)/fullMC2->GetBinContent(j)/fullMC2->GetBinContent(j);

		cout<<hdata_obs->GetBinContent(j)<<" "<<mcRatio[j]<<"  "<<hdata_obs->GetBinError(j)<<" "<<fullMC2->GetBinError(j)<<"  "<<dataRatio[j]<<"  "<<errordataUpRatio[j]<<"  "<<error<<"  "<<Ratio->GetBinError(j)<<"   "<<sqrt(error*error+errordataUpRatio[j]*errordataUpRatio[j])<<endl;

	}

	TGraphAsymmErrors* dataGraphRatio=new TGraphAsymmErrors(16, xbinsRatio, dataRatio,xerrorbinsRatio,xerrorbinsRatio,errordataDownRatio,errordataUpRatio);

	Ratio->Draw("");

	Ratio->GetXaxis()->SetLabelFont(42);
	Ratio->GetXaxis()->SetTitleFont(42);
	Ratio->GetYaxis()->SetNdivisions(505);
	Ratio->GetYaxis()->SetLabelFont(42);
	Ratio->GetYaxis()->SetLabelSize(0.122);
	Ratio->GetYaxis()->SetRangeUser(ymin,ymax);
	Ratio->GetXaxis()->SetRangeUser(xmin,xmax);
	Ratio->GetXaxis()->SetLabelSize(0.12);
	Ratio->GetXaxis()->SetLabelFont(42);
	Ratio->SetYTitle("#frac{Data-Bkgd (fit)  }{Bkgd (fit)}");
	Ratio->SetXTitle(Xaxis);
	Ratio->GetXaxis()->SetNdivisions(505);
	Ratio->GetYaxis()->CenterTitle(true);
	Ratio->GetYaxis()->SetTitleOffset(0.4);
	Ratio->GetYaxis()->SetTitleSize(0.11);
	Ratio->GetXaxis()->SetTitleOffset(0.8);
	Ratio->GetXaxis()->SetTitleSize(0.20);
	Ratio->SetMarkerSize(1.);


	RatioError->Draw("sames,E2"); RatioError->SetFillStyle(3002); RatioError->SetFillColor(kGray+2); RatioError->SetMarkerSize(0);

	//	dataGraphRatio->Draw("sames,p");

	TCanvas *c2 = new TCanvas("canvas_"+name+"_2","canvas_"+name+"_2");
	TH1F* SUBTRACTEDMCERROR=fullMC2->Clone(); SUBTRACTEDMCERROR->SetName("SUBTRACTEDMCERROR");
	for (int i=0; i<SUBTRACTEDMCERROR->GetNbinsX()+1; i++) SUBTRACTEDMCERROR->SetBinContent(i,0);
	SUBTRACTEDMCERROR->SetFillColor(kYellow+4);
	SUBTRACTEDMCERROR->SetFillStyle(3004);
	SUBTRACTEDMCERROR->SetLineWidth(2);
	TH1F* SUBTRACTED=hdata_obs->Clone(); SUBTRACTED->SetName("SUBTRACTED");

	//	const int entriesD=(const)SUBTRACTEDMCERROR->GetNbinsX();
	double data[16];
	double mc[16];
	double errordataUp[16];
	double errordataDown[16];
	double xbins[16];
	double xerrorbins[16];

	for (int j=0; j<16; j++){
		xbins[j]=300./15*(j-1)+10;
		xerrorbins[j]=10;
		data[j]=SUBTRACTED->GetBinContent(j);
		errordataUp[j]=SUBTRACTED->GetBinError(j);
		errordataDown[j]=SUBTRACTED->GetBinError(j);
		if(data[j]==0) {errordataUp[j]=1.7; errordataDown[j]=0;}
		mc[j]=fullMC2->GetBinContent(j);
		data[j]-=mc[j];
	}

	TGraphAsymmErrors* dataGraph=new TGraphAsymmErrors(16, xbins, data,xerrorbins,xerrorbins,errordataDown,errordataUp);
	//dataGraph->SetMarkerColor(kRed);	

	SUBTRACTED->Add(fullMC2,-1);
	for (int i=0; i<SUBTRACTED->GetNbinsX()+1; i++) SUBTRACTED->SetBinError(i,hdata_obs->GetBinError(i));
	TH1F *hSignalFill=hSignal->Clone(); hSignalFill->SetName("hSignalFill");
	hSignalFill->SetFillColor(kBlue-10);
	hSignalFill->SetFillStyle(1001);
	hSignalFill->SetLineWidth(2);
	hSignalFill->Draw("hist");
        hSignalFill->SetLineStyle(1);

	hSignalFill->SetXTitle(Xaxis);
	SUBTRACTED->SetXTitle(Xaxis);
	SUBTRACTED->SetYTitle(Yaxis);
	hSignalFill->SetYTitle(Yaxis);

	hSignalFill->GetXaxis()->SetRangeUser(xmin,xmax);
	SUBTRACTED->GetXaxis()->SetRangeUser(xmin,xmax);
	SUBTRACTEDMCERROR->GetXaxis()->SetRangeUser(xmin,xmax);
	SUBTRACTEDMCERROR->SetXTitle(Xaxis);
	SUBTRACTEDMCERROR->SetYTitle(Yaxis);
	//hSignalFill->SetYTitle(Yaxis);
	SUBTRACTEDMCERROR->Draw("sames,E2");
	//SUBTRACTED->Draw("sames");
	dataGraph->Draw("sames,p");
	SUBTRACTEDMCERROR->GetXaxis()->SetNdivisions(505);
	SUBTRACTED->GetXaxis()->SetNdivisions(505);
	hSignalFill->GetXaxis()->SetNdivisions(505);
	SUBTRACTEDMCERROR->GetXaxis()->SetLabelSize(0.04);
	SUBTRACTED->GetXaxis()->SetLabelSize(0.04);
	hSignalFill->GetXaxis()->SetLabelSize(0.04);
	SUBTRACTEDMCERROR->GetYaxis()->SetLabelSize(0.04);
	SUBTRACTED->GetYaxis()->SetLabelSize(0.04);
	hSignalFill->GetYaxis()->SetLabelSize(0.04);
	SUBTRACTEDMCERROR->GetYaxis()->SetTitleSize(0.05);
	SUBTRACTED->GetYaxis()->SetTitleSize(0.05);
	hSignalFill->GetYaxis()->SetTitleSize(0.05);

	if(minsubs==-1)
		minsubs=TMath::Min(hSignalFill->GetMinimum(),SUBTRACTED->GetMinimum())*2.5;
	if(maxsubs==-1)
		maxsubs=TMath::Max(hSignalFill->GetMaximum(),SUBTRACTED->GetMaximum())*1.2;
	hSignalFill->SetMaximum(maxsubs);
	hSignalFill->SetMinimum(minsubs);

	if(minsubs==-1)
		minsubs=TMath::Min(SUBTRACTEDMCERROR->GetMinimum(),SUBTRACTED->GetMinimum())*2.5;
	if(maxsubs==-1)
		maxsubs=TMath::Max(SUBTRACTEDMCERROR->GetMaximum(),SUBTRACTED->GetMaximum())*1.2;
	SUBTRACTEDMCERROR->SetMaximum(maxsubs);
	SUBTRACTEDMCERROR->SetMinimum(minsubs);
	SUBTRACTED->SetMaximum(maxsubs);
	SUBTRACTED->SetMinimum(minsubs);




	TLegend *leg2 = new TLegend(0.55,0.93,0.99,0.7,NULL,"brNDC");
	leg2->SetFillColor(0);
	leg2->SetBorderSize(0);
	leg2->SetFillStyle(0);
	TLegendEntry *entry;
	//	entry=leg2->AddEntry("NULL",channelName,"");
	entry=leg2->AddEntry(hSignalFill,"LFV H#rightarrow#mu#tau signal (B=0.9%)","f");
	entry=leg2->AddEntry(SUBTRACTEDMCERROR,"Bkgd. uncertainty","f");
	entry=leg2->AddEntry(SUBTRACTED,"Data-Bkgd","pl");

	leg2->Draw();

        CMS_lumi( c2, iPeriod, iPos );

	c2->SaveAs(name+"_Subtracted.png");
	c2->SaveAs(name+"_Subtracted.pdf");

	if(!setLogY){
		c1->SaveAs(name+".png");
		c1->SaveAs(name+".pdf");
	}
	else {
		c1->SaveAs(name+"_log.png");
		c1->SaveAs(name+"_log.pdf");
	}

}
Example #15
0
// define the generator's information across different ctau models
void Limit_lambda() {

   gROOT->LoadMacro("CMS_lumi.C");

   string hfolder  = "Limit1/" ;

   string ctau = "2000" ;
   string names[4] = {  "1935", "2060", "1945", "2195"  } ;
   const int sz = 4;

   string ld_Str[4] = { "120", "140", "160", "180" } ;
   float x[4] = { 120, 140, 160, 180, } ;
   float Xsec[4] = { 0.133, 0.0574, 0.0277, 0.0145 }  ;

   /*
   string ctau = "6000" ;
   string names[6] = { "6000", "5985", "6000", "5875", "5980", "6000"  } ;
   const int sz = 6;

   string ld_Str[6] = { "100", "120", "140", "160", "180", "220" } ;
   float x[6] = { 100, 120, 140, 160, 180, 220 } ;
   float Xsec[6] = { 0.368, 0.133, 0.0574, 0.0277, 0.0145, 0.0048}  ;

   string ctau = "1000" ;
   string names[4] = {  "1030", "975", "1100", "1000"  } ;
   const int sz = 4;

   string ld_Str[4] = { "140", "160", "180", "220" } ;
   float x[4] = { 140, 160, 180, 220 } ;
   float Xsec[4] = { 0.0574, 0.0277, 0.0145, 0.0048}  ;

   string ctau = "10000" ;
   string names[6] = { "10000", "10000", "10000", "10000", "10000", "10000" } ;
   const int sz = 6;

   string ld_Str[6] = { "100", "120", "140", "160", "180", "220" } ;
   float x[6] = { 100, 120, 140, 160, 180, 220 } ;
   float Xsec[6] = { 0.368, 0.133, 0.0574, 0.0277, 0.0145, 0.0048}  ;

   string ctau = "500" ;
   string names[4] = { "425", "515", "490", "500" } ;
   const int sz = 4;

   string ld_Str[4] = { "100", "140", "160", "220" } ;
   float x[4] = { 100, 140, 160, 220 } ;
   float Xsec[4] = { 0.368, 0.0574, 0.0277, 0.0048}  ;
   */

   /*
   string Lambda = "160" ;
   float Xsec = 0.0277 ;
   string names[7] = { "490", "975", "1945", "2930", "3910", "5875", "10000"  } ;
   const int sz = 7;

   string Lambda = "180" ;
   float Xsec = 0.0145 ;
   string names[8] = { "185", "365", "730", "1100", "2195", "3950", "5980", "10000"  } ;
   const int sz = 8;

   string Lambda = "220" ;
   float Xsec = 0.0048 ;
   string names[5] = { "500", "1000", "3000", "6000", "10000"  } ;
   const int sz = 5;

   string Lambda = "100" ;
   float Xsec = 0.368 ;
   string names[7] = { "215", "425", "1700", "3400", "5100", "6000", "10000"  } ;
   const int sz = 7;

   string Lambda = "120" ;
   float Xsec = 0.133 ;
   string names[8] = { "325", "645", "1290", "1935", "2955", "3870", "5985", "10000"  } ;
   const int sz = 8;

   string Lambda = "140" ;
   float Xsec = 0.0574 ;
   string names[8] = { "130", "515", "1030", "2060", "2920", "3985", "6000", "10000"  } ;
   const int sz = 8;
   */

   TString legTitle = "#tilde{#chi}^{0}_{1} #rightarrow #gamma #tilde{G}, c#tau ="+ ctau + " mm" ;
   string limitPlotName = "limit_ct"+ ctau + ".png" ;

   float yMax = 30. * Xsec[0] ;
   float yMin = 0.1 * Xsec[sz-1] ; 

   char s1[8],s2[8],s3[8],s4[8],s5[8],s6[8],s7[8] ;
   float f1,f2 ;
   int r1 ;
   float md[sz], u1[sz], u2[sz], d1[sz], d2[sz], ob[sz], x[sz], th[sz] ;
   float ex[sz] = { 0. } ;
   FILE* logf ; 

   // Get signal strength
   for (int i=0; i< sz; i++ ) {
       string fileName = hfolder +  "log_" + ld_Str[i] + "_" + names[i] + ".txt"  ;
       printf(" filename : %s \n", fileName.c_str() ) ;
       logf = fopen( fileName.c_str() ,"r");
       th[i] = Xsec[i] ;

       for (int j=0; j< 6; j++ ) {
           r1 = fscanf( logf, "%s %s %s %f %s %f %s %s %s", s1,s2,s3,&f1,s4,&f2,s5,s6,s7  );
	   printf("[%.0f] %s %s %s %f %s %f %s %s %s \n", x[i], s1,s2,s3, f1, s4, f2, s5,s6,s7 ) ;
           if ( j == 0 ) ob[i] = f1 * Xsec[i] ;
           if ( j == 1 ) u2[i] = f1 * Xsec[i] ;
           if ( j == 2 ) u1[i] = f1 * Xsec[i] ;
           if ( j == 3 ) md[i] = f1 * Xsec[i] ;
           if ( j == 4 ) d1[i] = f1 * Xsec[i] ;
           if ( j == 5 ) d2[i] = f1 * Xsec[i] ;
       } 
       u2[i] = u2[i] - md[i] ;
       u1[i] = u1[i] - md[i] ;
       d1[i] = md[i] - d1[i] ;
       d2[i] = md[i] - d2[i] ;

       printf(" -- \n") ;
       fclose( logf ) ;
   }


   // For the frame:
   gStyle->SetFrameBorderMode(0);
   gStyle->SetFrameBorderSize(1);
   gStyle->SetFrameFillColor(0);
   gStyle->SetFrameFillStyle(0);
   gStyle->SetFrameLineColor(1);
   gStyle->SetFrameLineStyle(1);
   gStyle->SetFrameLineWidth(1);

   gStyle->SetLabelOffset(0.007, "XYZ");
   gStyle->SetLabelSize(0.04, "XYZ");

   TCanvas *c1a = new TCanvas("c1a","c1a" ,800,800);
   //c1a->SetGridy() ;
   c1a->SetTopMargin(0.1);
   c1a->SetBottomMargin(0.13);
   c1a->SetLeftMargin(0.16);
   c1a->SetRightMargin(0.05);

   c1a->SetLogy() ;
   TMultiGraph *mg = new TMultiGraph();
   //gStyle->SetTitleW(0.85);
   //mg->SetTitle( "   CMS 19.1 fb^{-1}                                                   #sqrt{s} = 8 TeV" );

   // SetFillStyle ref: http://root.cern.ch/root/html/TAttFill.html
   TGraphAsymmErrors* gbe = new TGraphAsymmErrors(sz, x, md, ex, ex, d2, u2);
   gbe->SetFillStyle(1001);
   gbe->SetFillColor(kYellow);
   //gbe->GetXaxis()->SetLimits(240.,6100.) ;

   TGraphAsymmErrors* gae = new TGraphAsymmErrors(sz, x, md, ex, ex, d1, u1);
   gae->SetFillStyle(1001);
   //gae->SetFillColor(kSpring);
   gae->SetFillColor(kGreen);
   //gae->GetXaxis()->SetRangeUser(1.,5.) ;
   //gae->GetXaxis()->SetLimits(1.,5.) ;

   mg->Add( gbe ) ;
   mg->Add( gae ) ;
   mg->Draw("a3") ;

   // this modify the x-axis range, must set after Draw() ...stupid ROOT 
   gPad->Modified();
   mg->GetXaxis()->SetLimits( x[0] - 1, x[sz-1]+1 ) ;
   mg->SetMaximum( yMax );
   mg->SetMinimum( yMin );
   mg->GetXaxis()->SetTitleOffset(1.1);
   mg->GetYaxis()->SetTitleOffset(1.3);
   mg->GetXaxis()->SetTitleFont(42);
   mg->GetYaxis()->SetTitleFont(42);
   mg->GetXaxis()->SetTitleSize(0.04);
   mg->GetYaxis()->SetTitleSize(0.04);
   mg->GetXaxis()->SetTitle( "SUSY breaking scale (TeV)"  ) ;
   //mg->GetXaxis()->SetTitle( "MET Cut (GeV)" ) ;
   mg->GetYaxis()->SetTitle(" #sigma_{Upper Limit} (pb) at 95% CL") ;

   // expected
   TGraph*  g1  = new TGraph(sz, x, md ) ;
   g1->SetLineColor(2) ;
   g1->SetLineWidth(2) ;
   g1->SetLineStyle(1) ;
   //g1->GetXaxis()->SetLimits(1.,5.) ;
   g1->Draw("LP") ;
   c1a->Update() ;

   // observation
   TGraph*  g0  = new TGraph(sz, x, ob ) ;
   g0->SetLineColor(1) ;
   g0->SetLineWidth(2) ;
   g0->SetLineStyle(1) ;
   //g0->GetXaxis()->SetLimits(1.,5.) ;
   //g0->SetMarkerStyle(20) ;
   g0->Draw("LP") ;
   c1a->Update() ;


   // theoratical suggestion
   TGraph*  gth = new TGraph(sz, x, th ) ;
   gth->SetLineColor(4) ;
   gth->SetLineWidth(2) ;
   gth->SetLineStyle(1) ;
   gth->GetXaxis()->SetLimits( x[0], x[sz-1] ) ;
   gth->Draw("L") ;
   
   TLegend* leg1  = new TLegend(.4, .6, .90, .88 );
   //TLegend* leg1  = new TLegend(.4, .15, .90, .40 );
   leg1->SetHeader( legTitle ); 
   leg1->SetFillStyle(0); 
   leg1->SetBorderSize(0);
   leg1->SetFillColor(0);
   leg1 ->SetTextFont(22);

   leg1->SetFillColor(10) ;
   leg1->SetTextSize(0.030) ;
   leg1->AddEntry( gbe, "#pm 2#sigma Expected" ,  "F");
   leg1->AddEntry( gae, "#pm 1#sigma Expected" ,  "F");
   leg1->AddEntry( g1,  "Expected 95% CL upper limit" , "L");
   leg1->AddEntry( gth, "Theoretical LO cross-section", "L");
   leg1->AddEntry( g0,  "Observed" , "L");
   leg1->Draw("same") ;

   CMS_lumi( c1a, 2, 11 ) ;
   c1a->Update();

   TString gPlotname = hfolder +  limitPlotName  ;
   c1a->Print( gPlotname ) ;
   delete c1a ;

   /*
    // *************************
    // ***  Drawing setup    ***
    // *************************
    gStyle->SetOptStat("");

    gStyle->SetOptStat(kFALSE);
    //gStyle->SetOptFit(111);
    gStyle->SetOptTitle(0);
    //gStyle->SetTitleFontSize(0.05);
 
    // Plots
    TCanvas* c0 = new TCanvas("c0","", 800, 700);
    c0->SetFillColor(10);
    c0->SetFillColor(10);

    c0->SetTopMargin(0.1);
    c0->SetBottomMargin(0.13);
    c0->SetLeftMargin(0.16);
    c0->SetRightMargin(0.05);
    c0->SetLogy();

    //gPad->SetGridx();
    //gPad->SetGridy();
    c0->cd();

    TGraphAsymmErrors* eff[nModel] ;
    leg1->Clear() ;
    for ( int i=0; i< nModel; i++ ) {

        eff[i]= new TGraphAsymmErrors();

        D_ctbgT[i]->Rebin( rbin ) ;
        N_ctbgT[i]->Rebin( rbin ) ;

        eff[i]->Divide( N_ctbgT[i], D_ctbgT[i] );    

        eff[i]->SetMarkerColor( color[i] );
        eff[i]->SetLineColor( color[i] );
        leg1->AddEntry( eff[i], names[i]+" TeV" ,  "L");

        if ( i ==0 ) {
           c0->cd();
           c0->SetLogy(0);

           eff[i]->SetMaximum( ymax );
           eff[i]->SetMinimum( 0.0 );
           eff[i]->SetMarkerStyle(22);
           eff[i]->SetMarkerSize(1);
           eff[i]->SetLineWidth(2);

           eff[i]->GetXaxis()->SetTitleOffset(0.9);
           eff[i]->GetYaxis()->SetTitleOffset(1.25);
	   eff[i]->GetXaxis()->SetTitleSize(0.06);
	   eff[i]->GetYaxis()->SetTitleSize(0.06);
         
           eff[i]->GetXaxis()->SetTitle("Number of Vertices") ;
           eff[i]->GetYaxis()->SetTitle("Efficiency ") ;
           eff[i]->GetXaxis()->SetRangeUser(0, xmax ) ;
           eff[i]->Draw("AP");
        } else {
           eff[i]->Draw("SAMEPS");
        }
    }
    leg1->Draw("sames") ;
    c0->Update();

    CMS_lumi( c0, 2, 11 ) ;
    c0->Update();

    c0->Print( hfolder + plotname );


    delete c0 ;
    */
}
Example #16
0
TCanvas* example_plot( int iPeriod, int iPos )
{ 
  //  if( iPos==0 ) relPosX = 0.12;

  int W = 800;
  int H = 600;

  // 
  // Simple example of macro: plot with CMS name and lumi text
  //  (this script does not pretend to work in all configurations)
  // iPeriod = 1*(0/1 7 TeV) + 2*(0/1 8 TeV)  + 4*(0/1 13 TeV) 
  // For instance: 
  //               iPeriod = 3 means: 7 TeV + 8 TeV
  //               iPeriod = 7 means: 7 TeV + 8 TeV + 13 TeV 
  // Initiated by: Gautier Hamel de Monchenault (Saclay)
  //
  int H_ref = 600; 
  int W_ref = 800; 

  // references for T, B, L, R
  float T = 0.08*H_ref;
  float B = 0.12*H_ref; 
  float L = 0.12*W_ref;
  float R = 0.04*W_ref;

  TString canvName = "FigExample_";
  canvName += W;
  canvName += "-";
  canvName += H;
  canvName += "_";  
  canvName += iPeriod;
  if( writeExtraText ) canvName += "-prelim";
  if( iPos%10==0 ) canvName += "-out";
  else if( iPos%10==1 ) canvName += "-left";
  else if( iPos%10==2 )  canvName += "-center";
  else if( iPos%10==3 )  canvName += "-right";

  TCanvas* canv = new TCanvas(canvName,canvName,50,50,W,H);
  canv->SetFillColor(0);
  canv->SetBorderMode(0);
  canv->SetFrameFillStyle(0);
  canv->SetFrameBorderMode(0);
  canv->SetLeftMargin( L/W );
  canv->SetRightMargin( R/W );
  canv->SetTopMargin( T/H );
  canv->SetBottomMargin( B/H );
  canv->SetTickx(0);
  canv->SetTicky(0);

  TH1* h = new TH1F("h","h",40,70,110);
  h->GetXaxis()->SetNdivisions(6,5,0);
  h->GetXaxis()->SetTitle("m_{e^{+}e^{-}} (GeV)");  
  h->GetYaxis()->SetNdivisions(6,5,0);
  h->GetYaxis()->SetTitleOffset(1);
  h->GetYaxis()->SetTitle("Events / 0.5 GeV");  

  h->SetMaximum( 260 );
  if( iPos==1 ) h->SetMaximum( 300 );
  h->Draw();

  int histLineColor = kOrange+7;
  int histFillColor = kOrange-2;
  float markerSize  = 1.0;

  {
    TLatex latex;
				
    int n_ = 2;

    float x1_l = 0.92;
    float y1_l = 0.60;

    float dx_l = 0.30;
    float dy_l = 0.18;
    float x0_l = x1_l-dx_l;
    float y0_l = y1_l-dy_l;

    TPad* legend = new TPad("legend_0","legend_0",x0_l,y0_l,x1_l, y1_l );
    //    legend->SetFillColor( kGray );
    legend->Draw();
    legend->cd();
		
    float ar_l = dy_l/dx_l;
		
    float x_l[1];
    float ex_l[1];
    float y_l[1];
    float ey_l[1];
		
    //    float gap_ = 0.09/ar_l;
    float gap_ = 1./(n_+1);
		
    float bwx_ = 0.12;
    float bwy_ = gap_/1.5;
		
    x_l[0] = 1.2*bwx_;
    //    y_l[0] = 1-(1-0.10)/ar_l;
    y_l[0] = 1-gap_;
    ex_l[0] = 0;
    ey_l[0] = 0.04/ar_l;
		
    TGraph* gr_l = new TGraphErrors(1, x_l, y_l, ex_l, ey_l );
		
    gStyle->SetEndErrorSize(0);
    gr_l->SetMarkerSize(0.9);
    gr_l->Draw("0P");
		
    latex.SetTextFont(42);
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);    
    latex.SetTextSize(0.25);    
    latex.SetTextAlign(12); 
		
    TLine line_;
    TBox  box_;
    float xx_ = x_l[0];
    float yy_ = y_l[0];
    latex.DrawLatex(xx_+1.*bwx_,yy_,"Data");
		
    yy_ -= gap_;
    box_.SetLineStyle( kSolid );
    box_.SetLineWidth( 1 );
    //		box_.SetLineColor( kBlack );
    box_.SetLineColor( histLineColor );
    box_.SetFillColor( histFillColor );
    box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 );
    box_.SetFillStyle(0);
    box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 );
    latex.DrawLatex(xx_+1.*bwx_,yy_,"Z #rightarrow e^{+}e^{-} (MC)");

    canv->cd();
  }

  {
    // Observed data
    TFile file_("histo.root","READ");

    TH1F *data = (TH1*) (file_.Get("data")->Clone());
    data->SetDirectory(0);
    data->SetMarkerStyle(20);
    data->SetMarkerSize(markerSize);

    TH1F *MC   = (TH1*) (file_.Get("MC")->Clone());
    MC->SetDirectory(0);
    MC->SetLineColor(histLineColor);
    MC->SetFillColor(histFillColor);

    MC->Draw("histsame");
    data->Draw("esamex0");

    file_.Close();
  }

  // writing the lumi information and the CMS "logo"
  CMS_lumi( canv, iPeriod, iPos );

  canv->Update();
  canv->RedrawAxis();
  canv->GetFrame()->Draw();

  canv->Print(canvName+".pdf",".pdf");
  canv->Print(canvName+".png",".png");

  return canv;
}
int postprocessingSysError(){

  cout<<endl<<endl<<endl<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Postproccess all systematic uncertainties! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl;
  gErrorIgnoreLevel = 1001;

  const TString method  = "RMS99";
  const TString type    = "PFCHS";

  const int nEta =4;
  double eta_bins[5] = {0., 0.5, 1.1, 1.7, 2.3};
  // For looking at different systematic uncertainties independently
  const bool QCD    = true;
  const bool JEC    = true;
  const bool flavor = true;
  const bool PU     = true;
  const bool MC     = true;
  

  TString etaString, filename;   

  TString rootFiles, AuxString;  
  TString JetType = "PFCHS";
  TString Method  = "RMS99";   

  double *ratioEtaBinnedX  = new double[nEta];
  double *ratioEtaBinnedY  = new double[nEta];
  double *ratioEtaBinnedEX = new double[nEta];
  double *ratioEtaBinnedEY = new double[nEta];

  double *ratioEtaBinnedQCDUpY   = new double[nEta];
  double *ratioEtaBinnedQCDDownY = new double[nEta];

  TF1 *QCDuncertainty;

  if(QCD){
    rootFiles   = (TString) "scripts/plotsQCD/FinalErrorsQCD_" + type + (TString) "_" + method + (TString) ".root";
    TFile *_file = TFile::Open(rootFiles);    
    _file->GetObject("function",QCDuncertainty);
  }
  
  for(int eta = 0; eta < nEta; eta++){
    
    //cout<< endl<<endl<<endl<<eta+1<<". eta Bin!!"<<endl;

    // Read the MC and data results 
    rootFiles = (TString) "root_files_FINAL_data/Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + JetType + (TString) "_data_" + Method + (TString) ".root";
    TGraphErrors* JERData = readTGraphErrors(rootFiles,"Graph;1","Graph");
    rootFiles = (TString) "root_files_FINAL_mc/Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + JetType + (TString) "_mc_" + Method + (TString) ".root";
    TGraphErrors* JERMC = readTGraphErrors(rootFiles,"Graph","Graph");
    
    if(eta+1 == 1) etaString = Form("JER for |#eta| < %4.1f",etaBins[eta+1]);
    else           etaString = Form("JER for %4.1f <|#eta|< %4.1f",etaBins[eta+1],etaBins[eta+2]);
 
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // 1.) Calculate the ratio w/o systematic Uncertainties  


    int nData    = JERData->GetN();

    double *dataX  = JERData->GetX();
    double *dataY  = JERData->GetY();
    double *dataEX = JERData->GetEX();
    double *dataEY = JERData->GetEY();
    
    double *mcX  = new double[nData];
    double *mcY  = new double[nData];
    double *mcEX = new double[nData];
    double *mcEY = new double[nData];
    
    double *ratioX  = new double[nData];
    double *ratioY  = new double[nData];
    double *ratioEX = new double[nData];
    double *ratioEY = new double[nData];


    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // Initialize some stuff for QCD uncertainty
    double *ratioQCDUpY    = new double[nData];
    double *ratioQCDDownY  = new double[nData];    
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 
    int idx = 0;
    for(int i=0; i<nData; i++){

      JERMC   -> GetPoint(idx,mcX[i],mcY[i]);
      mcEX[i] = JERMC -> GetErrorX(idx);
      mcEY[i] = JERMC -> GetErrorY(idx);

      idx += 1;

      if(TMath::Abs(dataX[i]/mcX[i] - 1.) > 0.1){
	i -= 1;
	continue;
      }
     
      ratioX[i]  = 1./2.*(dataX[i] + mcX[i]);
      ratioY[i]  = dataY[i]/mcY[i];
      ratioEX[i] = 1./2.*TMath::Sqrt(TMath::Power(dataEX[i],2)+TMath::Power(mcEX[i],2));
      ratioEY[i] = TMath::Sqrt(TMath::Power((1./mcY[i]),2)*TMath::Power(dataEY[i],2)+TMath::Power((dataY[i]/(TMath::Power(mcY[i],2))),2)*TMath::Power(mcEY[i],2));
      if(QCD){
	// For QCD
	ratioQCDUpY[i]   = ratioY[i]*(1. + QCDuncertainty->Eval(ratioX[i]));
	ratioQCDDownY[i] = ratioY[i]*(1. - QCDuncertainty->Eval(ratioX[i]));
	//cout<<"QCDuncertainty->Eval(ratioX[i]) = "<<QCDuncertainty->Eval(ratioX[i])<<endl;
      }
    }
    
    TGraphErrors *Ratio = new TGraphErrors(nData,ratioX,ratioY,ratioEX,ratioEY);


    // For QCD
    TGraphErrors *QCDUp   = new TGraphErrors(nData,ratioX,ratioQCDUpY,ratioEX,ratioEY);
    TGraphErrors *QCDDown = new TGraphErrors(nData,ratioX,ratioQCDDownY,ratioEX,ratioEY);
    

    if(eta+1 == 1 ) AuxString = Form("Ratio between Data and MC for |#eta| < %4.1f",etaBins[eta+1]);
    else            AuxString = Form("Ratio between Data and MC for %4.1f <|#eta|<%4.1f",etaBins[eta+1],etaBins[eta+2]);
 
    Ratio -> SetTitle(AuxString); 
    Ratio -> GetXaxis() -> SetTitle("Photon pT");
    Ratio -> GetXaxis() -> SetTitleOffset(1.1); 
    Ratio -> GetYaxis() -> SetTitle("Ratio of JER (DATA/MC)");
    Ratio -> GetYaxis() -> SetTitleOffset(1.2);   
    Ratio -> GetXaxis() -> SetLimits(0,600);
    TF1* f1 = new TF1("name","pol0",0,600);   
    Ratio -> Fit("name","QR");
    

    TF1* fitQCDUp  = new TF1("fitQCDUp","pol0",0,600); 
    TF1* fitQCDDown = new TF1("fitQCDDown","pol0",0,600); 
    if(QCD){
      // For QCD
      QCDUp   -> Fit("fitQCDUp","QR");
      QCDDown -> Fit("fitQCDDown","QR");
    }
    
    TLegend *legend  = 0;
    legend = new TLegend(0.55,0.8,0.9,0.9);
    legend -> SetFillColor(0);

    legend -> SetHeader(Form(" %4.3f #pm %4.3f", f1 -> GetParameter(0), f1->GetParError(0)));
    TCanvas *c11 = new TCanvas("c11",AuxString,200,10,500,500);
    c11 -> cd();
    Ratio -> SetMinimum(0.5);
    Ratio -> SetMaximum(2.0);
  
    Ratio  -> Draw("AP"); 
    legend -> Draw("same");
  
    TLatex*  info   = new TLatex();
    info-> SetNDC();
    info->SetTextSize(0.045); 
    info->DrawLatex(0.22,0.84,Form("#splitline{#chi^{2} = %4.2f}{dof = %i}",f1 -> GetChisquare(),f1 -> GetNDF()));
  
    filename = (TString) "plots/Ratio_Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + type + (TString) "_data_comparison_" + method + (TString) ".pdf";
    c11 -> SaveAs(filename);
    delete c11;
    
    ratioEtaBinnedX[eta]  = (eta_bins[eta+1] + eta_bins[eta])/2.; 
    ratioEtaBinnedY[eta]  = f1 -> GetParameter(0);
    ratioEtaBinnedEX[0]=0.25;
    ratioEtaBinnedEX[1]=0.3;
    ratioEtaBinnedEX[2]=0.3;
    ratioEtaBinnedEX[3]=0.3;
    ratioEtaBinnedEY[eta] = f1->GetParError(0);

    if(QCD){
      ratioEtaBinnedQCDUpY[eta]  = fitQCDUp   -> GetParameter(0);
      ratioEtaBinnedQCDDownY[eta]= fitQCDDown -> GetParameter(0);



      // Some additional stuff for QCD uncertainty
      TCanvas *plotsQCD = new TCanvas("plotsQCD","plotsQCD",200,10,500,500);
      plotsQCD -> cd();

      Ratio -> SetMarkerColor(1);
      Ratio -> SetLineColor(1);
      Ratio -> SetMarkerStyle(20);
      Ratio -> GetFunction("name")->SetLineColor(1);
      QCDUp -> SetMarkerColor(3);
      QCDDown -> SetMarkerColor(3);
      QCDUp  -> SetLineColor(3);
      QCDDown  -> SetLineColor(3);
      QCDUp -> SetMarkerStyle(20);
      QCDDown -> SetMarkerStyle(20);
      QCDUp -> SetMarkerSize(0.8);
      QCDDown -> SetMarkerSize(0.8);
      QCDUp   -> GetFunction("fitQCDUp")->SetLineColor(3);
      QCDDown -> GetFunction("fitQCDDown")->SetLineColor(3);
      Ratio -> Draw("AP");
      QCDUp -> Draw("sameP");
      QCDDown -> Draw("sameP");

      delete legend;
      legend = new TLegend(0.4,0.8,0.9,0.9);
      legend -> SetFillColor(0);
      legend -> SetTextSize(0.045);
      legend -> AddEntry(Ratio,"Central Value","l");
      legend -> AddEntry(QCDUp,Form("Upward variation: + %4.3f",abs(ratioEtaBinnedQCDUpY[eta]/ratioEtaBinnedY[eta]-1.)),"l");
      legend -> AddEntry(QCDDown,Form("Downward variation: - %4.3f",abs(ratioEtaBinnedQCDDownY[eta]/ratioEtaBinnedY[eta]-1.)),"l");
   
      legend -> Draw("same");
      filename = (TString) "plots/plotsQCD_for_" + (long) (eta+1) + (TString) "_bin_"  + type + (TString) "_" + method + (TString) ".pdf";
      plotsQCD -> SaveAs(filename);
      delete plotsQCD;
    }


  }

  TGraphErrors* ratioEtaBinned = new TGraphErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ratioEtaBinnedEX,ratioEtaBinnedEY);
  filename = (TString) "plots/RatioEtaBinned_" + type + (TString) "_" + method + (TString) ".root";
  TFile *f = new TFile(filename,"RECREATE");
  f -> WriteTObject(ratioEtaBinned,"Graph");
  f->Close();
  delete f;

  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 1.) Calculate sys Error from QCD contamination
  //cout<<endl;
    
  double deltaRatioUpQCD[nEta]      = {0.};
  double deltaRatioDownQCD[nEta]    = {0.};
 
  if(QCD){
    
    for(int eta = 0; eta<nEta; eta++){

      deltaRatioUpQCD[eta]     = abs(ratioEtaBinnedQCDUpY[eta]/ratioEtaBinnedY[eta]-1.); 
      deltaRatioDownQCD[eta]   = abs(ratioEtaBinnedQCDDownY[eta]/ratioEtaBinnedY[eta]-1.); 
      
      //cout<<"ratioEtaBinnedQCDDownY[eta]"<<ratioEtaBinnedQCDDownY[eta]<<endl;
      //cout<<"ratioEtaBinnedY[eta]"<<ratioEtaBinnedY[eta]<<endl;
      //cout<<"deltaRatioUpQCD["<<eta<<"] = "<<deltaRatioUpQCD[eta]<<endl;
      //cout<<"deltaRatioDownQCD["<<eta<<"] = "<<deltaRatioDownQCD[eta]<<endl;
    }

  } 
  
  

  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 2.) Calculate sys Error from JEC uncertainty (percentage change of MC result)
  //cout<<endl;

  double deltaRatioUpJEC[nEta]      = {0.};
  double deltaRatioDownJEC[nEta]    = {0.};
    
  if(JEC){

    rootFiles                          = (TString) "scripts/plotsJEC/FinalEtaBinnedErrorsJECUp_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *JECuncertaintyUp  = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelJECUp       = JECuncertaintyUp -> GetY();

    rootFiles                          = (TString) "scripts/plotsJEC/FinalEtaBinnedErrorsJECLow_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *JECuncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelJECLow      = JECuncertaintyLow -> GetY();
      
    for(int eta = 0; eta<nEta; eta++){

      deltaRatioUpJEC[eta]   = sysRelJECUp[eta];
      deltaRatioDownJEC[eta] = sysRelJECLow[eta];

      //cout<<"deltaRatioUpJEC["<<eta<<"] = "<<deltaRatioUpJEC[eta]<<endl;
      //cout<<"deltaRatioDownJEC["<<eta<<"] = "<<deltaRatioDownJEC[eta]<<endl;     

    }

  }
 
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 3.) Calculate sys Error from Flavor uncertainty (percentage change of MC result)
  //cout<<endl;
  
  // Multiply on mc (as symmetric Error)
  // ratioUp  = 1/(1 - delta) * ratio
  // ratioLow = 1/(1 + delta) * ratio

  double deltaRatioUpFlavor[nEta]      = {0.};
  double deltaRatioDownFlavor[nEta]    = {0.};

  if(flavor){

    rootFiles                          = (TString) "scripts/plotsFlavor/FinalEtaBinnedErrorsFlavorUp_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *FlavoruncertaintyUp  = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelFlavorUp       = FlavoruncertaintyUp -> GetY();
    
    rootFiles                          = (TString) "scripts/plotsFlavor/FinalEtaBinnedErrorsFlavorLow_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *FlavoruncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelFlavorLow      = FlavoruncertaintyLow -> GetY();
  
    
    for(int eta = 0; eta<nEta; eta++){

      deltaRatioUpFlavor[eta]   = sysRelFlavorUp[eta];
      deltaRatioDownFlavor[eta] = sysRelFlavorLow[eta];

      //cout<<"deltaRatioUpFlavor["<<eta<<"] = "<<deltaRatioUpFlavor[eta]<<endl;
      //cout<<"deltaRatioDownFlavor["<<eta<<"] = "<<deltaRatioDownFlavor[eta]<<endl;
    }

  }
 
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 4.) Calculate sys Error from PU uncertainty (percentage change of MC result)
  //cout<<endl;

  double deltaRatioUpPU[nEta]      = {0.};
  double deltaRatioDownPU[nEta]    = {0.};
  
  if(PU){
    
    rootFiles                          = (TString) "scripts/plotsPU/FinalEtaBinnedErrorsPUUp_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *PUuncertaintyUp  = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelPUUp       = PUuncertaintyUp -> GetY();

    rootFiles                          = (TString) "scripts/plotsPU/FinalEtaBinnedErrorsPULow_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *PUuncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelPULow      = PUuncertaintyLow -> GetY();
  
    // Multiply on mc (as symmetric Error)
    // ratioUp = 1/(1 - delta) * ratio
    // ratioUp = 1/(1 + delta) * ratio
        
    for(int eta = 0; eta<nEta; eta++){
    
      deltaRatioUpPU[eta]   = sysRelPUUp[eta];
      deltaRatioDownPU[eta] = sysRelPULow[eta];

      //cout<<"deltaRatioUpPU["<<eta<<"] = "<<deltaRatioUpPU[eta]<<endl;
      //cout<<"deltaRatioDownPU["<<eta<<"] = "<<deltaRatioDownPU[eta]<<endl;
    }

  } 
  
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 5.) Calculate sys Error from Out-of Cone showering simulation (percentage change of full ratio result)
  //cout<<endl;
  
  double deltaRatioUpMC[nEta]      = {0.};
  double deltaRatioDownMC[nEta]    = {0.};
  

  if(MC){

    rootFiles                   = (TString) "scripts/plotsMC/FinalErrorsMC_" + type + (TString) "_" + method + (TString) ".root";  
    TGraphErrors *MCuncertainty = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelMC      = MCuncertainty -> GetY();
  
    // Percentage change is only in one direction, to take this into account keep deltaRatioDownMC = 0

    for(int eta = 0; eta<nEta; eta++){

      deltaRatioUpMC[eta]   = sysRelMC[eta];
      deltaRatioDownMC[eta] = sysRelMC[eta];

      //cout<<"deltaRatioUpMC["<<eta<<"] = "<<deltaRatioUpMC[eta]<<endl;
      //cout<<"deltaRatioDownMC["<<eta<<"] = "<<deltaRatioDownMC[eta]<<endl;
    }

  } 
  
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // Take all systematic Uncertainties together and plot
  //cout<<endl;

  double *deltaTotalSysUp   = new double[nEta];
  double *deltaTotalSysDown = new double[nEta];
  double *DeltaTotalSysUp   = new double[nEta];
  double *DeltaTotalSysDown = new double[nEta];
  double *DeltaTotalDown = new double[nEta];
  double *DeltaTotalUp = new double[nEta];
  for(int eta = 0; eta<nEta; eta++){

    // Add all systematic Uncertainties in quadrature (delta is relative Uncertainty)
    deltaTotalSysUp[eta]   = sqrt(TMath::Power(deltaRatioUpJEC[eta],2)   + TMath::Power(deltaRatioUpFlavor[eta],2)   + TMath::Power(deltaRatioUpPU[eta],2)   +                                                               TMath::Power(deltaRatioUpMC[eta],2)    + TMath::Power(deltaRatioUpQCD[eta],2));
    deltaTotalSysDown[eta] = sqrt(TMath::Power(deltaRatioDownJEC[eta],2) + TMath::Power(deltaRatioDownFlavor[eta],2) + TMath::Power(deltaRatioDownPU[eta],2) +                                                               TMath::Power(deltaRatioDownMC[eta],2)  + TMath::Power(deltaRatioDownQCD[eta],2));

    // Calculation of the absolute Uncertainty with Delta = ratio * delta
    DeltaTotalSysUp[eta]   = deltaTotalSysUp[eta] * ratioEtaBinnedY[eta];
    DeltaTotalSysDown[eta] = deltaTotalSysDown[eta] * ratioEtaBinnedY[eta];

    // Calculate Systematic plus staistical Uncertainty
    DeltaTotalUp[eta] = sqrt(pow(DeltaTotalSysUp[eta],2) + pow(ratioEtaBinnedEY[eta],2));
    DeltaTotalDown[eta] = sqrt(pow(DeltaTotalSysDown[eta],2) + pow(ratioEtaBinnedEY[eta],2));

    cout<<endl<<"relative: deltaTotalSysUp["<<eta<<"]   = "<<fixed<<setprecision(3)<<deltaTotalSysUp[eta]<<endl;
    cout<<"relative: deltaTotalSysDown["<<eta<<"] = "<<deltaTotalSysDown[eta]<<endl;

    cout<<endl<<"absolute: DeltaTotalSysUp["<<eta<<"]   = "<<DeltaTotalSysUp[eta]<<endl;
    cout<<"absolute: DeltaTotalSysDown["<<eta<<"] = "<<DeltaTotalSysDown[eta]<<endl;


  }

  double ex[nEta] ={0.25,0.3,0.3,0.3};

  TGraphAsymmErrors* ratioEtaBinnedSys = new TGraphAsymmErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ex,ex,DeltaTotalSysDown,DeltaTotalSysUp);

  double *TotalSysUp   = new double[nEta];
  double *TotalSysDown = new double[nEta];
 

  for(int i=0; i<nEta; i++){
    TotalSysUp[i]   = ratioEtaBinnedY[i]+DeltaTotalSysUp[i];
    TotalSysDown[i] = ratioEtaBinnedY[i]-DeltaTotalSysDown[i];
  }

  TGraph* ratioSysBorderUp   = new TGraph(nEta, ratioEtaBinnedX, TotalSysUp);
  TGraph* ratioSysBorderDown = new TGraph(nEta, ratioEtaBinnedX, TotalSysDown);

  TGraph* ratioRelativeErrorsUp   = new TGraph(nEta,ratioEtaBinnedX,deltaTotalSysUp);
  TGraph* ratioRelativeErrorsDown = new TGraph(nEta,ratioEtaBinnedX,deltaTotalSysDown);


  TGraphErrors* ratioEtaBinnedStat = new TGraphErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ratioEtaBinnedEX,ratioEtaBinnedEY);
  TGraphAsymmErrors* ratioEtaBinnedStatPlusSys = new TGraphAsymmErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ex,ex,DeltaTotalDown,DeltaTotalUp);
  
  TCanvas *cFinal = new TCanvas("cFinal","cFinal",200,10,500,500);
  cFinal -> cd();  
  
  ratioEtaBinnedSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  ratioEtaBinnedSys -> GetXaxis() -> SetTitle("|#eta|");

  if(PU  && flavor  && JEC  && MC && QCD)    etaString  = "All sys. Uncertainties";
  else if(PU  && !flavor && !JEC && !MC && !QCD)  etaString = "Only PU uncert.";
  else if(!PU && flavor  && !JEC && !MC && !QCD)  etaString = "Only flavor uncert.";
  else if(!PU && !flavor && JEC  && !MC && !QCD)  etaString = "Only JEC uncert.";
  else if(!PU && !flavor && !JEC && MC && !QCD)   etaString = "Only Out-of-Cone sim. uncert.";
  else if(!PU && !flavor && !JEC && MC && !QCD)   etaString = "Only Out-of-Cone sim. uncert.";
  else if(!PU && !flavor && !JEC && !MC && QCD)   etaString = "Only QCD uncert.";
  else if(PU && flavor && JEC && !MC && QCD)      etaString = "All besides MC uncertainty.";
  else etaString = "Strange set of systematic uncertainties.";
  cout<<endl<<etaString<<endl<<endl;
  
  ratioEtaBinnedSys -> SetMarkerStyle(20);
  ratioEtaBinnedSys -> SetMarkerSize(1.4);
  ratioEtaBinnedSys -> SetFillColor(kGray);
  ratioEtaBinnedSys -> SetFillStyle(3001);
  ratioEtaBinnedSys -> SetLineColor(kGray);
  ratioEtaBinnedSys -> SetMinimum(0.8);
  ratioEtaBinnedSys -> SetMaximum(1.5);
  ratioEtaBinnedSys -> GetXaxis() -> SetLimits(0., 2.3);
  ratioEtaBinnedSys -> GetXaxis() -> SetNdivisions(6,6,0, "X");
  ratioEtaBinnedSys -> DrawClone("Ae3p");
  
  //ratioEtaBinnedSys -> SetPointError(0, 0., 0., 0., 0.);
  //ratioEtaBinnedSys -> SetPointError(1, 0., 0., 0., 0.);
  //ratioEtaBinnedSys -> SetPointError(2, 0., 0., 0., 0.);
  //ratioEtaBinnedSys -> SetPointError(3, 0., 0., 0., 0.);
  //ratioEtaBinnedSys -> SetPointError(4, 0., 0., 0., 0.);


  ratioEtaBinnedStat -> SetMarkerStyle(20);
  ratioEtaBinnedStat -> SetMarkerSize(1.4);
  ratioEtaBinnedStat -> SetFillColor(kGray);
  ratioEtaBinnedStat -> SetFillStyle(3001);
  ratioEtaBinnedStat -> SetLineColor(1);
  ratioEtaBinnedStat -> Draw("psame");
  
 
  TLatex *infoFinal   = new TLatex();
  infoFinal -> SetTextFont(132);
  infoFinal -> SetNDC();
  infoFinal -> SetTextSize(0.045);
  infoFinal -> DrawLatex(0.2,0.8,etaString);

  filename = (TString) "plots/FinalErrorPlot_" + type + (TString) "_" + method + (TString) ".pdf";
  cFinal -> Print(filename,"pdf");
  filename = (TString) "plots/FinalErrorPlot_" + type + (TString) "_" + method + (TString) ".pdf";
  cFinal -> SaveAs(filename,"pdf");
  delete cFinal;


  filename = (TString) "plots/FinalRelativeErrorsUp_" + type + (TString) "_" + method + (TString) ".root"; 
  f = new TFile(filename,"RECREATE");
  f -> WriteTObject(ratioRelativeErrorsUp,"graph");
  f->Close();
  delete f;
  filename = (TString) "plots/FinalRelativeErrorsLow_" + type + (TString) "_" + method + (TString) ".root"; 
  f = new TFile(filename,"RECREATE");
  f -> WriteTObject(ratioRelativeErrorsDown,"graph");
  f->Close();
  delete f;

  
  ofstream RelativeErrors;
  RelativeErrors.open("plots/Errors.txt");
  
  RelativeErrors<<"Relative Errors: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<fixed<<setprecision(3)<<(deltaTotalSysDown[i]*100)<<"% / +"<<(deltaTotalSysUp[i]*100)<<"%"<<endl;
  }

  RelativeErrors<<endl<<"Absolute Errors: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(DeltaTotalSysDown[i])<<" / +"<<(DeltaTotalSysUp[i])<<endl;
  }

  RelativeErrors<<endl<<endl<<"Relative Errors JEC: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownJEC[i]*100)<<"% / +"<<(deltaRatioUpJEC[i]*100)<<"%"<<endl;
  }
  RelativeErrors<<endl<<endl<<"Relative Errors Flavor: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownFlavor[i]*100)<<"% / +"<<(deltaRatioUpFlavor[i]*100)<<"%"<<endl;
  }
  RelativeErrors<<endl<<endl<<"Relative Errors Out-of-Cone showering simulation: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownMC[i]*100)<<"% / +"<<(deltaRatioUpMC[i]*100)<<"%"<<endl;
  }
  RelativeErrors<<endl<<endl<<"Relative Errors QCD: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownQCD[i]*100)<<"% / +"<<(deltaRatioUpQCD[i]*100)<<"%"<<endl;
  }
  RelativeErrors<<endl<<endl<<"Relative Errors PU reweighing: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownPU[i]*100)<<"% / +"<<(deltaRatioUpPU[i]*100)<<"%"<<endl;
  }

  RelativeErrors<<endl<<endl<<"Central values and statistical Uncertainty: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(ratioEtaBinnedY[i])<<" +/- "<<ratioEtaBinnedEY[i]<<endl;
  }

  RelativeErrors.close();

 
  // Write directly full latex table with systematic and statistical unceratinty

  ofstream latexTable;
  latexTable.open("plots/latexTable.txt");


  latexTable<<"\\renewcommand{\\arraystretch}{2.0}"<<endl;
  latexTable<<"\\begin{center}"<<endl;
  latexTable<<"\\begin{tabular}{ | c | c   c c| }"<<endl;
  latexTable<<"$|\\eta^{\\text{Jet}}|$ & Ratio &  stat.      & sys.  \\\\\\hline"<<endl;
  for(int z=0;z<nEta;z++){
    latexTable<<"$"<<fixed<<setprecision(1)<<etaBins[z]<<" - "<<etaBins[z+1]<<"$ &"<<fixed<<setprecision(3)<<ratioEtaBinnedY[z]<<" & $\\pm "<<ratioEtaBinnedEY[z]<<"$ & $^{+"<<DeltaTotalSysUp[z]<<"}_{-"<<DeltaTotalSysDown[z]<<"}$ \\\\"<<endl;
  }
  latexTable<<"\\hline"<<endl;
  latexTable<<"\\end{tabular}"<<endl;
  latexTable<<"\\end{center}"<<endl<<endl<<endl<<endl<<endl;

 


  
  latexTable<<"\\begin{center}"<<endl;
  latexTable<<"\\begin{tabular}{ l| c | c | c | c |}"<<endl;
  latexTable<<"\\multicolumn{1}{c}{} & \\multicolumn{4}{c}{$|\\eta^{\\text{Jet}}|$}\\\\\\hline"<<endl<<fixed<<setprecision(1);
  for(int z=0;z<nEta;z++) latexTable<<"& \\textbf{"<<etaBins[z]<<" - "<<etaBins[z+1]<<"}";
  latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{Multijet contamination}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpQCD[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaRatioDownQCD[z]*100<<" \\% $ ";
  latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{Flavor uncertainty}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpFlavor[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownFlavor[z]*100<<" \\% $ ";
latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{JEC uncertainty}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpJEC[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownJEC[z]*100<<" \\% $ ";
latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{Out-of-Cone showering simulation}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpMC[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaRatioDownMC[z]*100<<" \\% $ ";
  latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{PU uncertainty}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpPU[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownPU[z]*100<<" \\% $ ";
  latexTable<<"\\\\\\hline\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{Total}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaTotalSysUp[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaTotalSysDown[z]*100<<" \\% $ ";
  latexTable<<"\\\\\\hline"<<endl;

  latexTable<<"\\end{tabular}"<<endl;
  latexTable<<"\\end{center}"<<endl;


 latexTable.close();





  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // Comparison to 2011 Data 
  cout<<endl; 

  gROOT->LoadMacro("tdrstyle_mod14.C");
  setTDRStyle();

  gROOT->LoadMacro("CMS_lumi.C");

  writeExtraText = true;       // if extra text
  extraText  = "Preliminary";  // default extra text is "Preliminary"
  lumi_8TeV  = "19.7 fb^{-1}"; // default is "19.7 fb^{-1}"
  lumi_7TeV  = "4.9 fb^{-1}";  // default is "5.1 fb^{-1}"

  int iPeriod = 2;    // 1=7TeV, 2=8TeV, 3=7+8TeV, 7=7+8+13TeV 
  
  gStyle->SetHatchesLineWidth(1);
  gStyle->SetHatchesSpacing(2.2);   
  //-----------------------------------------------------

  TCanvas *cFinal2 = new TCanvas("cFinal2","cFinal2",200,10,1000,1000);
  cFinal2 -> cd();  

  double x_2011[4];
  x_2011[0]=0.25;
  x_2011[1]=0.80;
  x_2011[2]=1.40;
  x_2011[3]=2.00;
  double y_2011[4];
  y_2011[0]=1.052;
  y_2011[1]=1.057;
  y_2011[2]=1.096;
  y_2011[3]=1.134;
  double yErrStat_2011[4];
  yErrStat_2011[0]=0.012;
  yErrStat_2011[1]=0.012;
  yErrStat_2011[2]=0.017;
  yErrStat_2011[3]=0.035;
  double yErrSysHigh_2011[4];
  yErrSysHigh_2011[0]=0.062;
  yErrSysHigh_2011[1]=0.056;
  yErrSysHigh_2011[2]=0.063;
  yErrSysHigh_2011[3]=0.087;
  double yErrSysLow_2011[4];
  yErrSysLow_2011[0]=0.061;
  yErrSysLow_2011[1]=0.055;
  yErrSysLow_2011[2]=0.062;
  yErrSysLow_2011[3]=0.085;
  double xErrLow_2011[4];
  xErrLow_2011[0]=0.25;
  xErrLow_2011[1]=0.3;
  xErrLow_2011[2]=0.3;
  xErrLow_2011[3]=0.3;
  double xErrHigh_2011[4];
  xErrHigh_2011[0]=0.25;
  xErrHigh_2011[1]=0.3;
  xErrHigh_2011[2]=0.3;
  xErrHigh_2011[3]=0.3;

  double yErrTotalHigh_2011[4];
  double yErrTotalLow_2011[4];

  for(int i=0; i<4; i++){

    yErrTotalHigh_2011[i]=sqrt(pow(yErrStat_2011[i],2) + pow(yErrSysHigh_2011[i],2));
    yErrTotalLow_2011[i]=sqrt(pow(yErrStat_2011[i],2) + pow(yErrSysLow_2011[i],2));


  }

  TGraphAsymmErrors *Res_2011_stat = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrStat_2011,yErrStat_2011);
  Res_2011_stat->SetName("Res_2011_stat");
  TGraphAsymmErrors *Res_2011_sys  = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrSysLow_2011,yErrSysHigh_2011);
  Res_2011_sys->SetName("Res_2011_sys");
  TGraphAsymmErrors *Res_2011_total  = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrTotalLow_2011,yErrTotalHigh_2011);
  Res_2011_sys->SetName("Res_2011_total");
  
  //-----------------------------------------------------
  ratioEtaBinnedStatPlusSys -> GetXaxis() -> SetTitle("|#eta|");
  ratioEtaBinnedStatPlusSys -> GetXaxis() -> SetRangeUser(0., 2.3);
  ratioEtaBinnedStatPlusSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  ratioEtaBinnedSys -> GetXaxis() -> SetTitle("|#eta|");
  ratioEtaBinnedSys -> GetXaxis() -> SetRangeUser(0., 2.3);
  ratioEtaBinnedSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  ratioEtaBinnedStat -> GetXaxis() -> SetTitle("|#eta|");
  ratioEtaBinnedStat -> GetXaxis() -> SetRangeUser(0., 2.3);
  ratioEtaBinnedStat -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  ratioEtaBinnedStat -> GetYaxis() -> SetRangeUser(0.8, 1.6);
  Res_2011_stat -> GetXaxis() -> SetTitle("|#eta|");
  Res_2011_stat -> GetXaxis() -> SetLimits(0., 2.3);
  Res_2011_stat -> GetXaxis() -> SetNdivisions(505, "X");
  Res_2011_stat -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  Res_2011_sys -> GetXaxis() -> SetTitle("|#eta|");
  Res_2011_sys -> GetXaxis() -> SetLimits(0., 2.3);
  Res_2011_sys -> GetXaxis() -> SetNdivisions(505, "X");
  Res_2011_sys -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  Res_2011_total -> GetXaxis() -> SetTitle("|#eta|");
  Res_2011_total -> GetXaxis() -> SetLimits(0., 2.3);
  Res_2011_total -> GetXaxis() -> SetNdivisions(505, "X");
  Res_2011_total -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  Res_2011_total -> GetYaxis() -> SetRangeUser(0.8, 1.5);


  ratioEtaBinnedStatPlusSys -> SetMarkerStyle(20); 
  ratioEtaBinnedStatPlusSys -> SetMarkerSize(2.0);
  ratioEtaBinnedStatPlusSys -> SetLineColor(kPink-8);
  ratioEtaBinnedStatPlusSys -> SetLineWidth(2);
  ratioEtaBinnedStatPlusSys -> SetMarkerColor(kPink-8);
  ratioEtaBinnedStatPlusSys -> SetFillColor(kPink-8);
  ratioEtaBinnedStatPlusSys -> SetName("statPlusSys_2012");
  
  ratioEtaBinnedStat -> SetMarkerStyle(20); 
  ratioEtaBinnedStat -> SetMarkerSize(2.0);
  ratioEtaBinnedStat -> SetLineColor(kPink-8);
  ratioEtaBinnedStat -> SetLineWidth(2);
  ratioEtaBinnedStat -> SetMarkerColor(kPink-8);
  ratioEtaBinnedStat -> SetFillColor(kPink-8);
  ratioEtaBinnedStat -> SetName("Stat_2012");

  ratioEtaBinnedStatPlusSys -> SetFillStyle(3244);
  ratioEtaBinnedStat        -> SetFillStyle(3144);

  Res_2011_stat->SetMarkerStyle(24);
  Res_2011_stat->SetMarkerSize(2.0);
  Res_2011_stat->SetLineColor(kGray+2);
  Res_2011_stat->SetLineWidth(2);
  Res_2011_stat->SetLineWidth(2);
  Res_2011_stat->SetFillStyle(1001);

  Res_2011_total->SetMarkerStyle(24);
  Res_2011_total->SetMarkerSize(2.0);
  Res_2011_total->SetLineColor(1);
  Res_2011_total->SetLineWidth(2);
  Res_2011_total->SetFillColor(kGray);
  Res_2011_total->SetFillStyle(1001);
  Res_2011_total->SetLineColor(kGray+2);

  Res_2011_total->Draw("a2");
  Res_2011_stat->Draw("esame");
  
  ratioEtaBinnedStatPlusSys -> Draw("2same");
  Res_2011_stat->Draw("pXsame");
  Res_2011_stat->SetMarkerSize(1.9);
  Res_2011_stat->Draw("pXsame");
  Res_2011_stat->SetMarkerSize(1.7);
  Res_2011_stat->Draw("pXsame");
  ratioEtaBinnedStatPlusSys -> Draw("pXsame");
  ratioEtaBinnedStat        -> Draw("esame");
  
  TLegend *leg = new TLegend(0.18, 0.60, 0.55, 0.75);
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->SetTextFont(42);
  leg->SetTextSize(0.045);
  
  leg->AddEntry(Res_2011_total,"5/fb (7 TeV)", "pfl");
  leg->AddEntry(ratioEtaBinnedStatPlusSys,"20/fb (8 TeV)", "pfl");
     
  leg->Draw("same");

  TLatex *info = new TLatex();
  info->SetNDC();
  info->DrawLatex(0.67,0.83,"Anti-k_{T} R=0.5");
  info->DrawLatex(0.67,0.77,"PF+CHS");

  CMS_lumi( cFinal2, iPeriod, 11 );
  cFinal2->Print("plots/resultsComparisonFINAL.pdf","pdf");
  cFinal2->SaveAs("plots/resultsComparisonFINAL.C");


  return 0;

}
Example #18
0
void draw_plots(){
	CreateCanvas(Form("Limit_Plot"),"",600,600);
	CName["Limit_Plot"]->cd();
	gPad->SetLogy();
	
	grName["squark_xs"]->SetLineColor(kBlack);
    grName["squark_xs"]->SetLineStyle(kDotted);
    grName["squark_xs"]->SetFillColor(46);

	grName["xs_exp_combined"]->SetLineColor(kBlack);
	grName["xs_obs_combined"]->SetLineColor(kBlack);
	
	grName["xs_exp_combined"]->SetLineStyle(kDashed);
    
	grName["xs_exp_combined_1sigma"]->SetFillStyle(1001);
	grName["xs_exp_combined_2sigma"]->SetFillStyle(1001);
    
	grName["xs_exp_combined_1sigma"]->SetFillColor(3);
	grName["xs_exp_combined_2sigma"]->SetFillColor(5);
	
	grName["xs_exp_combined_1sigma"]->Draw("a3");
    grName["xs_exp_combined_2sigma"]->Draw("a3");
	grName["xs_exp_combined_1sigma"]->GetXaxis()->SetRangeUser(300,900);
    grName["xs_exp_combined_2sigma"]->GetXaxis()->SetRangeUser(300,900);
	grName["xs_exp_combined_1sigma"]->GetYaxis()->SetRangeUser(5,1.5*grName["squark_xs"]->Eval(300));
    grName["xs_exp_combined_2sigma"]->GetYaxis()->SetRangeUser(5,1.5*grName["squark_xs"]->Eval(300));

	grName["xs_exp_combined_1sigma"]->GetXaxis()->SetTitle("M_{#tilde{q}} (GeV)");
	grName["xs_exp_combined_1sigma"]->GetYaxis()->SetTitle("#sigma (fb)");
    
    grName["xs_exp_combined_2sigma"]->GetXaxis()->SetTitle("M_{#tilde{q}} (GeV)");
	grName["xs_exp_combined_2sigma"]->GetYaxis()->SetTitle("#sigma (fb)");
    
	//grName["xs_exp_combined_2sigma"]->Draw("a3 same");
    grName["xs_exp_combined_1sigma"]->Draw("a3");
	grName["xs_exp_combined"]->Draw("l same");
	grName["xs_obs_combined"]->Draw("l same");
    
    grName["squark_xs"]->Draw("3 same");
    grName["squark_xs"]->Draw("cx0 same");

    grName["xs_exp_combined"]->Draw("l same");
	grName["xs_obs_combined"]->Draw("l same");

	TLegend Leg(0.6,0.5,0.85,0.67);
	Leg.SetFillColor(10);
	Leg.SetBorderSize(0);
	Leg.SetLineColor(10);
	
	Leg.AddEntry(grName["xs_exp_combined"],"Expected","L" );
	Leg.AddEntry(grName["xs_obs_combined"],"Observed","L");
	Leg.AddEntry(grName["xs_exp_combined_1sigma"],"#pm 1 #sigma_{ex}","f");
   // Leg.AddEntry(grName["xs_exp_combined_2sigma"],"#pm 2 SD","f");

	Leg.AddEntry(grName["squark_xs"],"#sigma_{#tilde{q}#tilde{q}} #pm 1 #sigma_{th} ","LF");
	Leg.DrawClone();
	
	//TLatex txt(0.4,0.85,"M_{#tilde{#chi}_{1}^{#pm}}=1/2#timesM_{#tilde{q}}, Br(#tilde{#chi}_{1}^{#pm}#rightarrowW^{#pm},#tilde{S})=1");
    TLatex txt(0.6,0.85,"pp #rightarrow #tilde{q}_{L}#tilde{q}_{L}");
    //TLatex txt1(0.2,0.3,"M_{ #tilde{#chi}_{1}^{#pm} }=1/2#timesM_{ #tilde{q} }");
    TLatex txt1(0.2,0.3,"M_{ #tilde{#chi}_{1}^{#pm} }=1/2#timesM_{ #tilde{q} }");
	TLatex txt2(0.2,0.2,"M_{#tilde{S}} = 100 GeV, M_{S} = 90 GeV");

    //, Br(#tilde{#chi}_{1}^{#pm}#rightarrowW^{#pm},#tilde{S})=1");
    txt.SetTextSize(0.045);
	txt.SetNDC(kTRUE);
	txt.DrawClone();
    txt.DrawLatex(0.6,0.77,"#tilde{q}_{L}#rightarrow q #tilde{#chi}_{1}^{#pm}");
    txt.DrawLatex(0.6,0.69,"#tilde{#chi}_{1}^{#pm}#rightarrow W^{#pm} #tilde{S}");
    txt.DrawLatex(0.2,0.4,"#tilde{q}_{L}: #tilde{u}, #tilde{d}, #tilde{s}, #tilde{c}");
    
    txt1.SetTextSize(0.045);
	txt1.SetNDC(kTRUE);
	txt2.SetTextSize(0.045);
	txt2.SetNDC(kTRUE);
	txt1.DrawClone();
	txt2.DrawClone();
    //txt.DrawLatex(0.4,0.75,"M_{#tilde{S}}=100 GeV, M_{S}=90 GeV");
    
    CMS_lumi(CName["Limit_Plot"],2,10);
	//draw_header();
    gPad->RedrawAxis();

    
}
Example #19
0
void v2_cent_plotter(int jpsiCategory      = 2, // 1 : Prompt, 2 : Non-Prompt, 3: Bkg
		     string nDphiBins      = "4",
		     const char* outputDir = "output", 
		     const char* inputDir  = "outputNumbers",// where phi and v2 numbers are (root, and txt format)
		     bool bDoDebug         = true,
		     bool bAddCent010      = false, 
		     bool bSavePlots       = true
		     ) 
{
  gSystem->mkdir(Form("./%s/png",outputDir), kTRUE);
  gSystem->mkdir(Form("./%s/pdf",outputDir), kTRUE);
  
// set the style
  setTDRStyle();
  gStyle->SetOptFit(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(kFALSE);

  // input files: prompt and non-prompt ones
  const char* v2InFileDirs[1] = {"histsV2Yields_20150823_v2W_Lxyz_pTtune_PRMC_dPhiBins4"};
  const char* legend[4]       = {"","Prompt J/#psi","Non-prompt J/#psi","Background"};
  const char* signal[4]       = {"", "Prp","NPrp","Bkg"};
 
  // Reminder for TGraphAssymError: gr = new TGraphAsymmErrors(n,x,y,exl,exh,eyl,eyh);// n,x,y,err_x, err_y
  int nBins                   =  nCentBins_pr; 
  if(jpsiCategory==2) nBins   =  nCentBins_np;
  
  cout<<" !!!!! Number of Y bins: "<< nBins<<endl;
  
  double adXaxis[nBins];//   location on x-axis  

  double adV2[nBins]      ; // v2 values
  double adV2_stat[nBins] ;// stat uncert
  double adV2_syst[nBins] ;// stat uncert
  double adV2_err0[nBins] ;// error  0
  double adWidth_systBox[nBins]; // width of the systm. uncert.

  for(int ib=0; ib<nBins; ib++)
    {
      adWidth_systBox[ib] = 10;
      adV2_syst[ib]       = adV2Cent_pr_syst[ib];
      adXaxis[ib]         = adXaxisCent_pr[ib];

      if(jpsiCategory==2)
	{
	  adV2_syst[ib]    = adV2Cent_np_syst[ib];
	  adXaxis[ib]      = adXaxisCent_np[ib];
	}

      if(bDoDebug) cout<<"Bin "<<ib<<"\t adAxis= "<<adXaxis[ib]<<endl;
    }
  
  // // open the files with yields and do the math
  ifstream in;
  std::string nameVar   = outFilePlot[3]; // cent
  std::string nameSig   = signal[jpsiCategory]; // prompt, non-pro or bkg
  std::string nameDir   = v2InFileDirs[0];
  string inputFile      = nameVar + "_"+ nameSig + "_nphibin" + nDphiBins + ".dat";
  
  cout << "!!!!!! Input file name: "<< inputFile <<endl;
  in.open(Form("%s/%s/data/%s",inputDir,nameDir.c_str(),inputFile.c_str()));
  

  // read the v2 and v2_stat uncert from input file
  string whatBin[3];
  double x[4]={0};
  int iline=0;
  string tmpstring;
  getline(in,tmpstring);
  while ( in.good() && iline<nBins)
    {
      in >> whatBin[0] >> whatBin[1] >> whatBin[2] >> x[0] >> x[1] >> x[2] >> x[3];

      adV2[nBins-iline-1]      = x[2];
      adV2_stat[nBins-iline-1] = x[3];

      cout<< "Bin " << whatBin[0] << "\t"<< whatBin[1] << "\t" << whatBin[2]<<"\t";
      cout <<"v2= "<< x[2] << "\t error= "<< x[3]<<endl;
      iline++;
    }
  in.close();
  if(bDoDebug)
    {
      for(int ib=0; ib<nBins; ib++)
	cout<<"Bin "<<ib<<"\t adXaxis: "<< adXaxis[ib]<<"\t v2= "<<adV2[ib]<<endl;
    }
  // high-pt
  TGraphErrors *pgV2          = new TGraphErrors(nBins, adXaxis, adV2, adV2_stat, adV2_stat);
  TGraphAsymmErrors *pgV2_sys = new TGraphAsymmErrors(nBins, adXaxis, adV2, adWidth_systBox,adWidth_systBox, adV2_syst, adV2_syst);
  TGraphErrors *pgV2_cont     = new TGraphErrors(nBins, adXaxis, adV2, adV2_err0, adV2_err0);
  
    // //-------------------------------------------------- Drawing stuff
  // colors and symbols
  // high-pt
  pgV2->SetMarkerColor(kRed+1);
  pgV2_sys->SetFillColor(kRed-9);

  pgV2->SetMarkerStyle(21);
  pgV2_sys->SetMarkerStyle(21);
  pgV2_cont->SetMarkerStyle(25); 
 
  pgV2->SetMarkerSize(1.1);
  pgV2_cont->SetMarkerSize(1.1);

  if(jpsiCategory==2)
    {
      pgV2->SetMarkerColor(kOrange+2);
      pgV2_sys->SetFillColor(kOrange-9);
    }
  if(jpsiCategory==3)// bkg
    {
      pgV2->SetMarkerColor(1);
      pgV2_sys->SetFillColor(19);
    }
 
  //-------------------------------------------------------
  // general labels 
  TLatex *lt1  = new TLatex();
  lt1->SetNDC();

  TH1F *phAxis = new TH1F("phAxis",";N_{part};v_{2}",10,0,400);
  phAxis->GetYaxis()->SetRangeUser(-0.05,0.25);
  phAxis->GetXaxis()->CenterTitle();
  phAxis->GetYaxis()->CenterTitle();

  TF1 *line    = new TF1("line","0",0,400);
  line->SetLineWidth(1);
 
  TLatex *pre = new TLatex(20.0,0.22,Form("%s",legend[jpsiCategory]));
  pre->SetTextFont(42);
  pre->SetTextSize(0.05);

  TLatex *ly     = new TLatex(20.0,0.18,Form("%s",yBinsLegend[0]));
  ly->SetTextFont(42);
  ly->SetTextSize(0.04);

  TLatex *lpt     = new TLatex(20.0,0.2,Form("%s",ptBinsLegend[0]));
  lpt->SetTextFont(42);
  lpt->SetTextSize(0.04);

  TLatex *lcent = new TLatex(10.0,-0.025,Form("Cent."));
  lcent->SetTextFont(42);
  lcent->SetTextSize(0.04);

 //-------------- Drawing 
  TCanvas *pc = new TCanvas("pc","pc");
  phAxis->Draw();
  CMS_lumi(pc,101,33);
  pre->Draw();
  lpt->Draw();
  ly->Draw();
  lcent->Draw();

 int write2 = nBins;
  if(!bAddCent010) 
    {
      write2 = nBins-1;
      pgV2_sys->RemovePoint(write2);
      pgV2->RemovePoint(write2);
      pgV2_cont->RemovePoint(write2);
    }

  for(int ib=0; ib<write2; ib++)
    {
     if(jpsiCategory==2) lcent->DrawLatex(adXaxis[ib]-30,-0.025,Form("%s",centBinsLegend[nCentBins-1-ib]));
     else lcent->DrawLatex(adXaxis[ib]-30,-0.025,Form("%s",centBinsLegend[nCentBins-nBins-ib]));
    }
  
  pgV2_sys->Draw("2");
  pgV2->Draw("PZ");
  pgV2_cont->Draw("P");
  gPad->RedrawAxis();

 
  if(bSavePlots)
    {
      pc->SaveAs(Form("%s/png/v2_%s_%s_nphi%s.png",outputDir,outFilePlot[2],signal[jpsiCategory],nDphiBins.c_str()));
      pc->SaveAs(Form("%s/pdf/v2_%s_%s_nphi%s.pdf",outputDir,outFilePlot[2],signal[jpsiCategory],nDphiBins.c_str()));
    }

}
void drawCtauPlot(RooWorkspace& myws,   // Local workspace
                  string outputDir,     // Output directory
                  struct InputOpt opt,  // Variable with run information (kept for legacy purpose)
                  struct KinCuts cut,   // Variable with current kinematic cuts
                  string plotLabel,     // The label used to define the output file name
                  // Select the type of datasets to fit
                  string DSTAG,         // Specifies the type of datasets: i.e, DATA, MCJPSINP, ...
                  bool isPbPb,          // Define if it is PbPb (True) or PP (False)
                  // Select the drawing options
                  bool setLogScale,     // Draw plot with log scale
                  bool incSS,           // Include Same Sign data
                  int  nBins,           // Number of bins used for plotting
                  bool paperStyle=false,// if true, print less info
                  bool saveWS=true      // save the workspace into a file
                  ) 
{
  if (DSTAG.find("_")!=std::string::npos) DSTAG.erase(DSTAG.find("_"));
  
  string dsOSName = Form("dOS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP"));
  string dsSSName = Form("dSS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP"));

  
  // Create the main plot of the fit
  // RooPlot*   frame     = myws.var("invMass")->frame(Bins(nBins), Range(cut.dMuon.M.Min, cut.dMuon.M.Max));
  RooPlot*   frame     = myws.var("ctau")->frame(Bins(nBins), Range(-1,3));
  myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2));
  
  if (paperStyle) TGaxis::SetMaxDigits(3); // to display powers of 10
    
  if (incSS) { 
    myws.data(dsSSName.c_str())->plotOn(frame, Name("dSS"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); 
  }
  myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2));

  
  // set the CMS style
  setTDRStyle();
  
  // Create the main canvas
  TCanvas *cFig  = new TCanvas(Form("cMassFig_%s", (isPbPb?"PbPb":"PP")), "cMassFig",800,800);
  TPad    *pad1  = new TPad(Form("pad1_%s", (isPbPb?"PbPb":"PP")),"",0,paperStyle ? 0 : 0.23,1,1);
  TPad    *pad2  = new TPad(Form("pad2_%s", (isPbPb?"PbPb":"PP")),"",0,0,1,.228);
  TLine   *pline = new TLine(cut.dMuon.M.Min, 0.0, cut.dMuon.M.Max, 0.0);
  
  // TPad *pad4 = new TPad("pad4","This is pad4",0.55,0.46,0.97,0.87);
  TPad *pad4 = new TPad("pad4","This is pad4",0.55,paperStyle ? 0.29 : 0.36,0.97,paperStyle ? 0.70 : 0.77);
  pad4->SetFillStyle(0);
  pad4->SetLeftMargin(0.28);
  pad4->SetRightMargin(0.10);
  pad4->SetBottomMargin(0.21);
  pad4->SetTopMargin(0.072);

  frame->SetTitle("");
  frame->GetXaxis()->CenterTitle(kTRUE);
  if (!paperStyle) {
     frame->GetXaxis()->SetTitle("");
     frame->GetXaxis()->SetTitleSize(0.045);
     frame->GetXaxis()->SetTitleFont(42);
     frame->GetXaxis()->SetTitleOffset(3);
     frame->GetXaxis()->SetLabelOffset(3);
     frame->GetYaxis()->SetLabelSize(0.04);
     frame->GetYaxis()->SetTitleSize(0.04);
     frame->GetYaxis()->SetTitleOffset(1.7);
     frame->GetYaxis()->SetTitleFont(42);
  } else {
     frame->GetXaxis()->SetTitle("#font[12]{l}_{J/#psi} (mm)");
     frame->GetXaxis()->SetTitleOffset(1.1);
     frame->GetYaxis()->SetTitleOffset(1.45);
     frame->GetXaxis()->SetTitleSize(0.05);
     frame->GetYaxis()->SetTitleSize(0.05);
  }
  setRange(myws, frame, dsOSName, setLogScale, cut.dMuon.AbsRap.Min);
  if (paperStyle) {
     double Ydown = 0.1;//frame->GetMinimum();
     double Yup = 0.9*frame->GetMaximum();
     frame->GetYaxis()->SetRangeUser(Ydown,Yup);
  }
 
  cFig->cd();
  pad2->SetTopMargin(0.02);
  pad2->SetBottomMargin(0.4);
  pad2->SetFillStyle(4000); 
  pad2->SetFrameFillStyle(4000); 
  if (!paperStyle) pad1->SetBottomMargin(0.015); 
  //plot fit
  pad1->Draw();
  pad1->cd(); 
  frame->Draw();

  pad1->SetLogy(setLogScale);

  // Drawing the text in the plot
  TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.032);
  float dy = 0; 
  
  t->SetTextSize(0.03);
  if (!paperStyle) { // do not print selection details for paper style
     t->DrawLatex(0.21, 0.86-dy, "2015 HI Soft Muon ID"); dy+=0.045;
     if (isPbPb) {
        t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045;
     } else {
        t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045;
     } 
  }
  if (cut.dMuon.AbsRap.Min>0.1) {t->DrawLatex(0.20, 0.86-dy, Form("%.1f < |y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Min,cut.dMuon.AbsRap.Max)); dy+=1.5*0.045;}
  else {t->DrawLatex(0.20, 0.86-dy, Form("|y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Max)); dy+=1.5*0.045;}
  t->DrawLatex(0.20, 0.86-dy, Form("%g < p_{T}^{#mu#mu} < %g GeV/c",cut.dMuon.Pt.Min,cut.dMuon.Pt.Max)); dy+=0.045;
  t->DrawLatex(0.20, 0.86-dy, Form("%g < M^{#mu#mu} < %g GeV/c^{2}",cut.dMuon.M.Min,cut.dMuon.M.Max)); dy+=0.045;
  if (isPbPb) {t->DrawLatex(0.20, 0.86-dy, Form("Cent. %d-%d%%", (int)(cut.Centrality.Start/2), (int)(cut.Centrality.End/2))); dy+=0.045;}
  dy+=0.5*0.045; t->DrawLatex(0.20, 0.86-dy, "#mu in acceptance"); dy+=0.045;

  // Drawing the Legend
  double ymin = 0.7802;
  if (paperStyle) { ymin = 0.72; }
  TLegend* leg = new TLegend(0.5175, ymin, 0.7180, 0.8809); leg->SetTextSize(0.03);
  leg->AddEntry(frame->findObject("dOS"), (incSS?"Opposite Charge":"Data"),"pe");
  if (incSS) { leg->AddEntry(frame->findObject("dSS"),"Same Charge","pe"); }
  leg->Draw("same");

  //Drawing the title
  TString label;
  if (isPbPb) {
    if (opt.PbPb.RunNb.Start==opt.PbPb.RunNb.End){
      label = Form("PbPb Run %d", opt.PbPb.RunNb.Start);
    } else {
      label = Form("%s [%s %d-%d]", "PbPb", "HIOniaL1DoubleMu0", opt.PbPb.RunNb.Start, opt.PbPb.RunNb.End);
    }
  } else {
    if (opt.pp.RunNb.Start==opt.pp.RunNb.End){
      label = Form("PP Run %d", opt.pp.RunNb.Start);
    } else {
      label = Form("%s [%s %d-%d]", "PP", "DoubleMu0", opt.pp.RunNb.Start, opt.pp.RunNb.End);
    }
  }
  
  // CMS_lumi(pad1, isPbPb ? 105 : 104, 33, label);
  CMS_lumi(pad1, isPbPb ? 108 : 107, 33, "");
  if (!paperStyle) gStyle->SetTitleFontSize(0.05);
  
  pad1->Update();
  cFig->cd(); 


  // Save the plot in different formats
  gSystem->mkdir(Form("%splot/%s/root/", outputDir.c_str(), DSTAG.c_str()), kTRUE); 
  cFig->SaveAs(Form("%splot/%s/root/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(),  "Psi2SJpsi", (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  gSystem->mkdir(Form("%splot/%s/png/", outputDir.c_str(), DSTAG.c_str()), kTRUE);
  cFig->SaveAs(Form("%splot/%s/png/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.png", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  gSystem->mkdir(Form("%splot/%s/pdf/", outputDir.c_str(), DSTAG.c_str()), kTRUE);
  cFig->SaveAs(Form("%splot/%s/pdf/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.pdf", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End));
  
  cFig->Clear();
  cFig->Close();
  
  // Save the workspace
  if (saveWS) {
     gSystem->mkdir(Form("%sresult/%s/", outputDir.c_str(), DSTAG.c_str()), kTRUE); 
     TFile *file = NULL;
     file = new TFile(Form("%sresult/%s/FIT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End), "RECREATE");  
     if (!file) { 
        cout << "[ERROR] Output root file with fit results could not be created!" << endl; 
     } else {
        file->cd();    
        myws.Write("workspace"); 
        file->Write(); file->Close(); delete file;
     }
  }
}
Example #21
0
void CheckDataFakes_CR_Bjet(){
  
  TH1::SetDefaultSumw2(true);
  setTDRStyle();
  
  TString param = "BJetCR_fakeparam_";

  TH1F* data_presel_hist = new TH1F("mcclosure","mcclosure", 10,0.,10.);
  data_presel_hist->GetYaxis()->SetTitle("Event");
  float ymax = 250.;
  data_presel_hist->GetYaxis()->SetRangeUser(0., ymax);
  data_presel_hist->GetXaxis()->SetTitle("");
  data_presel_hist->GetXaxis()->SetBinLabel(1,"PtvsEta");
  data_presel_hist->GetXaxis()->SetBinLabel(2,"HtvsEta");
  data_presel_hist->GetXaxis()->SetBinLabel(3,"PtvsEta_nbjet");
  data_presel_hist->GetXaxis()->SetBinLabel(4,"HtvsEta_X");
  data_presel_hist->GetXaxis()->SetBinLabel(5,"PtvsEta_X");
  data_presel_hist->GetXaxis()->SetBinLabel(6,"PtvsEta_nbjet_X");
  data_presel_hist->GetXaxis()->SetBinLabel(7,"PtvsEta_HT_nbjet_X");
  data_presel_hist->GetXaxis()->SetBinLabel(8,"PtvsEta_HT_X");
  data_presel_hist->GetXaxis()->SetBinLabel(9,"PtvsEta_HT");
  
  
  TString path_data= "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_data_5_3_14.root";
  TFile * fdata = new TFile(path_data);
  
  TH1F* h_data_presel= (TH1F*)fdata->Get(param + "20");
  double error_up_data = GetError(h_data_presel , true);
  double error_down_data = GetError(h_data_presel , false);
  
  
  
  TCanvas* c1 = new TCanvas(("Plot"), "Plot", 1600, 1200);
  c1->cd();

  data_presel_hist->GetYaxis()->SetTitle("Event");
  data_presel_hist->Draw();

  
  vector<TString> jetpt;
  jetpt.push_back("20");
  jetpt.push_back("30");
  jetpt.push_back("40");
  jetpt.push_back("60");

  
  TString path_mc= "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_mc_5_3_14.root";
  TFile * fmc = new TFile(path_mc);


  TString path_cf= "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/HNDiElectron_SKchargeflip_dilep_5_3_14.root";
  TFile * fcf = new TFile(path_cf);


  TString path_np= "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/NP/REG2/HNDiElectron_SKnonprompt_dilep_5_3_14.root";
  TFile * fnp = new TFile(path_np);

  TLegend* legendH = new TLegend(0.6,0.6, 0.9,0.9);
  legendH->SetFillColor(kWhite);
  legendH->SetTextFont(42);
  
  //h_data_presel->Draw("histsame");

  double jx[9], jxerr[9];
  double jy[9], jyerrup[9], jyerrdown[9];
  float offset = 0.1; 
  for(unsigned int bin = 0; bin < h_data_presel->GetNbinsX(); bin++){
    
    jx[bin] = bin+ offset;  jxerr[bin] = 0.;
    jy[bin] = h_data_presel->GetBinContent(bin+1);
    jyerrup[bin] = error_up_data;
    jyerrdown[bin] = error_down_data;
  }

  TGraphAsymmErrors * gd = new TGraphAsymmErrors(9, jx, jy, jxerr, jxerr,  jyerrup,jyerrdown);
  gd->SetLineWidth(2.0);
  gd->SetMarkerSize(2.);

  gd->Draw( "9sameP" );
  

  TLine *line = new TLine( data_presel_hist->GetBinLowEdge(data_presel_hist->GetXaxis()->GetFirst()),h_data_presel->GetBinContent(1),data_presel_hist->GetBinLowEdge(data_presel_hist->GetXaxis()->GetLast()+1),h_data_presel->GetBinContent(1));

  line->SetLineColor(kBlack);
  line->SetLineWidth(2);
  line->Draw();
  
  float ymaxlb = ymax * 0.6;
  float ymaxhb = ymax ;
  for(unsigned int b = 1; b < data_presel_hist->GetNbinsX(); b++){
    //Bin dividers
    if( b < 4) ymax = ymaxlb;
    else ymax = ymaxhb;
    TLine *lineb = new TLine( float(b), 0., float(b), ymax);
    lineb->SetLineColor(kRed);
    lineb->SetLineWidth(2);
    lineb->Draw();
  }

  

  legendH->AddEntry(gd, "Observed" , "pl");
  for(unsigned int j= 0 ; j < jetpt.size() ; j++){
    TH1F* h_mc_presel= (TH1F*)fmc->Get(param+jetpt.at(j));
    TH1F* h_np_presel= (TH1F*)fnp->Get(param+jetpt.at(j));
    TH1F* h_cf_presel= (TH1F*)fcf->Get(param+jetpt.at(j));
    
    if(j == 0){
      h_mc_presel->SetLineColor(kOrange);
    }
    if(j ==1){
      h_mc_presel->SetFillColor(870);
    }
    if(j == 2){
      h_mc_presel->SetFillColor(391);
    }
    if(j==3){
      h_mc_presel->SetFillColor(kBlue-2);
    }
    
    for(unsigned int i=1; i < h_mc_presel->GetNbinsX()+1 ; i++){
      float binerror = sqrt( (h_mc_presel->GetBinError(i)*h_mc_presel->GetBinError(i)) + ((h_mc_presel->GetBinContent(i)*0.2)*(h_mc_presel->GetBinContent(i)*0.2)));
      h_mc_presel->SetBinError(i , binerror);
    }
    for(unsigned int i=1 ;i < h_cf_presel->GetNbinsX()+1 ; i++){
      float binerror = sqrt( (h_cf_presel->GetBinError(i)*h_cf_presel->GetBinError(i)) + ((h_cf_presel->GetBinContent(i)*0.2)*(h_cf_presel->GetBinContent(i)*0.2)));
      h_cf_presel->SetBinError(i , binerror);
    }
    for(unsigned int i=1 ;i < h_np_presel->GetNbinsX()+1 ; i++){
      float binerror = sqrt( (h_np_presel->GetBinError(i)*h_np_presel->GetBinError(i)) + ((h_np_presel->GetBinContent(i)*0.4)*(h_np_presel->GetBinContent(i)*0.4)));
      h_np_presel->SetBinError(i , binerror);
    }
    
    h_mc_presel->Add(h_np_presel);
    h_mc_presel->Add(h_cf_presel);
    
    double jx[9], jxerr[9];
    double jy[9], jyerr[9];
    for(unsigned int i=0 ;i < h_mc_presel->GetNbinsX() ; i++){
      jx[i] = i + 0.4 + (0.1*float(j));
      jy[i] = h_mc_presel->GetBinContent(i+1);
      jyerr[i] =  h_mc_presel->GetBinError(i+1);
      jxerr[i] = 0.;
    }
    
    
    TGraphAsymmErrors * g = new TGraphAsymmErrors(9, jx, jy, jxerr, jxerr, jyerr, jyerr);

    if(j ==0){
      g->SetLineColor(kOrange);
      g->SetMarkerColor(kOrange);
      g->SetMarkerStyle(21.);
    }
    if(j ==1){
      g->SetLineColor(870);
      g->SetMarkerColor(870);
      g->SetMarkerStyle(22.);
    }
    if(j ==2){
      g->SetLineColor(kCyan);
      g->SetMarkerColor(kCyan);
      g->SetMarkerStyle(23.);
    }
    if(j ==3){
      g->SetLineColor(kBlue-2);
      g->SetMarkerColor(kBlue-2);
      g->SetMarkerStyle(23.);
    }
   
    g->SetLineWidth(2.);
    g->SetMarkerSize(2.);

    g->Draw( "9sameP" );
    

    legendH->AddEntry(g , "Awayjet pt > " + jetpt.at(j) , "lp");
  }
  legendH->Draw();
  
  CMS_lumi( c1, 2, 11 );
  c1->Update();
  c1->RedrawAxis();

  TLatex latex;
  latex.SetNDC();
  latex.SetTextAngle(0);
  latex.SetTextColor(kBlack);

  latex.SetTextFont(42);
  //  latex.SetTextAlign(31);
  float t = c1->GetTopMargin();
  latex.SetTextSize(lumiTextSize*t);

  TString label = "#bf{Preselection}";
  TString label2 = "#bf{2 Electrons + 2 Jets; Zveto }"; 
  float l = c1->GetLeftMargin()+0.05;
  latex.DrawLatex(l, 0.75 ,label);
  latex.DrawLatex(l, 0.7 ,label2);

  c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/DataFakes/Preselection" + param + "_looseregion2.pdf"));
    
}
void MakeMCClosurePlot_ttbarwithsyst(){

  
  TH1::SetDefaultSumw2(true);
  setTDRStyle();

  TString path_ttbar = "/home/jalmond/Analysis/LQanalyzer/data/output/SSElectron/NP/HNDiElectron_nonprompt_SKttbar_dilep_5_3_14.root";

  TFile * fttbar = new TFile(path_ttbar);

  TH1F* mcclosure_hist = new TH1F("mcclosure","mcclosure", 10,0.,10.);
  mcclosure_hist->GetYaxis()->SetTitle("Event");
  mcclosure_hist->GetYaxis()->SetRangeUser(0., 100.);
  mcclosure_hist->GetXaxis()->SetTitle("");
  mcclosure_hist->GetXaxis()->SetBinLabel(1,"PtvsEta");
  mcclosure_hist->GetXaxis()->SetBinLabel(2,"HtvsEta");
  mcclosure_hist->GetXaxis()->SetBinLabel(3,"PtvsEta_nbjet");
  mcclosure_hist->GetXaxis()->SetBinLabel(4,"HtvsEta_X");
  mcclosure_hist->GetXaxis()->SetBinLabel(5,"PtvsEta_X");
  mcclosure_hist->GetXaxis()->SetBinLabel(6,"PtvsEta_nbjet_X");
  mcclosure_hist->GetXaxis()->SetBinLabel(7,"PtvsEta_HT_nbjet_X");
  mcclosure_hist->GetXaxis()->SetBinLabel(8,"PtvsEta_HT_X");
  mcclosure_hist->GetXaxis()->SetBinLabel(9,"PtvsEta_HT");

  
  TCanvas* c1 = new TCanvas(("Plot"), "Plot", 1600, 1200);
  c1->cd();


  mcclosure_hist->GetYaxis()->SetTitle("Event");
  mcclosure_hist->Draw();


  vector<TString> collection;
  collection.push_back("MCclosure/HNTightregion1MCSSclosure");

  for(unsigned int k = 0 ; k < 1 ; k ++){
    
    TH1F* h_tt_measured= (TH1F*)fttbar->Get((collection.at(k) + "_fake_measured"));
  
    double ttbar_err(0.);
    float ttbar_tt =   h_tt_measured->IntegralAndError(0, h_tt_measured->GetNbinsX(),ttbar_err, "");
    
    
    TLine *line = new TLine( mcclosure_hist->GetBinLowEdge(mcclosure_hist->GetXaxis()->GetFirst()), h_tt_measured->Integral(),mcclosure_hist->GetBinLowEdge(mcclosure_hist->GetXaxis()->GetLast()+1),h_tt_measured->Integral());
    
    line->SetLineStyle(2);
    line->SetLineColor(kRed);
    line->SetLineWidth(2);
    line->Draw();
    
  }
  

    
  vector<TString> list_of_names;
  list_of_names.push_back("pteta");
  list_of_names.push_back("hteta");
  list_of_names.push_back("bteta");
  list_of_names.push_back("pteta_b");
  list_of_names.push_back("pteta_h");
  list_of_names.push_back("pteta_cb");
  list_of_names.push_back("pteta_ht");
  list_of_names.push_back("pteta_pht");
  list_of_names.push_back("pteta_ht_b");
  
  
  vector<TString> jetpt;
  jetpt.push_back("20");
  jetpt.push_back("30");
  jetpt.push_back("40");
  jetpt.push_back("60");
  

  TLegend* legendH = new TLegend(0.6,0.6, 0.9,0.9);
  legendH->SetFillColor(kWhite);
  legendH->SetTextFont(42);
  legendH->AddEntry(line, "Observed" , "l");
  double jx[9], jxerr[9];
  double jy[9], jyerr[9];
  for(unsigned int j = 0; j < jetpt.size(); j++){
    float offset = 0.4 + (0.1* double(j));
    for(unsigned int k = 0 ; k < collection.size() ; k ++){
      for(unsigned int i = 0; i < list_of_names.size(); i++){
	TH1F* h_ttbar_p= (TH1F*)fttbar->Get((collection.at(k) + "_fake_predicted" +jetpt.at(j) + list_of_names.at(i)));
	double ttbar_p_err;
	double int_ttbar_p = h_ttbar_p->IntegralAndError(0, h_ttbar_p->GetNbinsX(), ttbar_p_err, "");
	int bin = -9;
	if(list_of_names.at(i).Contains("pteta_ht_b")) bin = 6;
	else if(list_of_names.at(i).Contains("pteta_pht")) bin= 8;
	else if(list_of_names.at(i).Contains("pteta_ht")) bin= 7;
	else if(list_of_names.at(i).Contains("bteta")) bin= 5;
	else if(list_of_names.at(i).Contains("pteta_cb")) bin= 4;
	else if(list_of_names.at(i).Contains("hteta")) bin= 3;
	else if(list_of_names.at(i).Contains("pteta_b")) bin= 2;
	else if(list_of_names.at(i).Contains("pteta_h")) bin= 1;
	else if(list_of_names.at(i).Contains("pteta")) bin= 0;
	
	jx[bin] = bin+ offset;  jxerr[bin] = 0.;
	jy[bin] = int_ttbar_p; jyerr[bin] = sqrt((ttbar_p_err*ttbar_p_err) + ((0.4*int_ttbar_p)*(0.4*int_ttbar_p))) ;
	cout << int_ttbar_p << " " << ttbar_p_err << endl;
	cout<< (collection.at(k) + "_fake_predicted" + jetpt.at(j) + list_of_names.at(i)) << endl;
      }
    }
    
    TGraphAsymmErrors * g = new TGraphAsymmErrors(9, jx, jy, jxerr, jxerr,  jyerr,jyerr);
    g->SetLineWidth(2.0);
    if(j == 0){
      g->SetMarkerColor(kCyan);
      g->SetLineColor(kCyan);
    }
    if(j == 1){
      g->SetMarkerStyle(21);
      g->SetMarkerColor(kGreen);
      g->SetLineColor(kGreen);
    }
    if(j == 2){
      g->SetMarkerStyle(22);
      g->SetMarkerColor(kOrange);
      g->SetLineColor(kOrange);
    }
    if(j == 3){
      g->SetMarkerStyle(33);
      g->SetMarkerColor(kBlue-2);
      g->SetLineColor(kBlue-2);
    }
    g->SetMarkerSize(2.);
    g->Draw( "9sameP" );
    
    
    legendH->AddEntry(g, "Prediced: AwayJet " + jetpt.at(j) +" GeV" , "pl");
    legendH->Draw();
  }
  CMS_lumi( c1, 2, 11 );
  c1->Update();
  c1->RedrawAxis();

  TLatex latex;
  latex.SetNDC();
  latex.SetTextAngle(0);
  latex.SetTextColor(kBlack);

  latex.SetTextFont(42);
  //  latex.SetTextAlign(31);
  float t = c1->GetTopMargin();
  latex.SetTextSize(lumiTextSize*t*1.1);

  TString label = "#bf{t#bar{t} MC}";
  TString label2 = "#bf{2 Electrons + 2 Jets}";
  TString label3 = "#bf{N(bjet) = 0}";
  float l = c1->GetLeftMargin()+0.05;
  latex.DrawLatex(l, 0.75 ,label);
  latex.DrawLatex(l, 0.7 ,label2);
  latex.DrawLatex(l, 0.65 ,label3);

  c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/MCclosure/TTbarMCclosure_with40percsyst_looseregion1_region1.pdf"));
  

  
}
Example #23
0
void MakeNPunziLowMass_id(){
  
  setTDRStyle();
  gStyle->SetPalette(1);

  TH1F* tight_anal1 = makehist("PreSelection_lowmass");
  TH1F* tight_anal2 = makehist("PreSelection_medium_lowmass");
  TH1F* tight_anal3 = makehist("PreSelection_tight_lowmass");
  TH1F* tight_anal4 = makehist("PreSelection_iso_b10_e10_lowmass");


  TLegend* legendH = new TLegend(0.6, 0.7, 0.9, 0.9);
  legendH->SetFillColor(kWhite);
  legendH->SetTextSize(0.03);

  
  tight_anal1->GetXaxis()->SetTitle("m_{N} GeV");
  tight_anal1->GetYaxis()->SetTitle("ID efficiency");
 
  tight_anal1->SetMarkerColor(kBlue);
  tight_anal1->SetMarkerStyle(20.);
  tight_anal2->SetMarkerColor(kRed);
  tight_anal2->SetMarkerStyle(21.);
  tight_anal3->SetMarkerColor(kRed);
  tight_anal3->SetMarkerStyle(22.);



  tight_anal4->SetMarkerColor(kRed);
  tight_anal4->SetMarkerStyle(23.);
  tight_anal2->SetMarkerColor(kRed);




  legendH->AddEntry(tight_anal1, "Analysis", "p");
  legendH->AddEntry(tight_anal2, "Medium POG", "p");
  legendH->AddEntry(tight_anal3, "Tight POG", "p");
  legendH->AddEntry(tight_anal4, "Tight POG + IP", "p");

  tight_anal4->GetYaxis()->SetRangeUser(0., 0.001);
  tight_anal4->Draw("p");
  tight_anal2->Draw("psame");
  tight_anal3->Draw("psame");
  tight_anal1->Draw("psame");


  legendH->Draw();

  TGraphAsymmErrors * g = new TGraphAsymmErrors(heff);
  g->SetLineWidth(2.0);
  g->SetMarkerSize(2.);
  //  g->Draw( "9pXsame" );
  
  
  CMS_lumi( c1, 2, 11 );
  c1->Update();
  c1->RedrawAxis();
  
  
  c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/SignalPlots/Punzi_presel_id_lowmass.pdf" ));
  return;
  
}
void triggerEfficiency()
{
  //=== General CMS Style ===

  gROOT->ForceStyle();

  //gROOT->LoadMacro("tdrstyle.C");
  setTDRStyle();

  //gROOT->LoadMacro("CMS_lumi.C");
  extraText  = "Preliminary";  // default extra text is "Preliminary"
  writeExtraText = true;       // remove or keep "Preliminary"

  lumi_13TeV  = "2015";  // for trigger
  //lumi_13TeV  = "65 pb^{-1}, 50ns";  // for trigger
  //lumi_13TeV  = "15.5 pb^{-1}, 25ns";  // for trigger

  //lumi_13TeV  = "65 pb^{-1}";  // default is ""
  //lumi_8TeV  = "19.1 fb^{-1}"; // default is "19.7 fb^{-1}"
  //lumi_7TeV  = "4.9 fb^{-1}";  // default is "5.1 fb^{-1}"
  lumi_sqrtS = "13 TeV";       // used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string)

  int iPeriod = 4;    // 1=7TeV, 2=8TeV, 3=7+8TeV, 4=13TeV, 7=7+8+13TeV, 0=free form (uses lumi_sqrtS)
  int iPos = 11;     // 0=out , 11=left, 22=center, 33=right


  //====================================================================================
  // Style

  int W = 600;
  int H = 600;

  // 
  // Simple example of macro: plot with CMS name and lumi text
  //  (this script does not pretend to work in all configurations)
  // iPeriod = 1*(0/1 7 TeV) + 2*(0/1 8 TeV)  + 4*(0/1 13 TeV) 
  // For instance: 
  //               iPeriod = 3 means: 7 TeV + 8 TeV
  //               iPeriod = 7 means: 7 TeV + 8 TeV + 13 TeV 
  // Initiated by: Gautier Hamel de Monchenault (Saclay)
  // Updated by:   Dinko Ferencek (Rutgers)
  //
  int H_ref = 600; 
  int W_ref = 600; 

  // references for T, B, L, R
  float T = 0.08*H_ref;
  float B = 0.12*H_ref; 
  float L = 0.15*W_ref;
  float R = 0.04*W_ref;

  TString canvName = "trigger";
  canvName += W;
  canvName += "-";
  canvName += H;
  canvName += "_";  
  canvName += iPeriod;
  if( writeExtraText ) canvName += "-prelim";
  if( iPos%10==0 ) canvName += "-out";
  else if( iPos%10==1 ) canvName += "-left";
  else if( iPos%10==2 )  canvName += "-center";
  else if( iPos%10==3 )  canvName += "-right";

  TCanvas* canv = new TCanvas(canvName,canvName,50,50,W,H);
  canv->SetFillColor(0);
  canv->SetBorderMode(0);
  canv->SetFrameFillStyle(0);
  canv->SetFrameBorderMode(0);
  canv->SetLeftMargin( L/W );
  canv->SetRightMargin( R/W );
  canv->SetTopMargin( T/H );
  canv->SetBottomMargin( B/H );
  canv->SetTickx(0);
  canv->SetTicky(0);

  canv->SetGridx(true);
  canv->SetGridy(true);

  //====================================================================================
  // Efficiency

  TFile *fileInput = TFile::Open(myinputFile);

  fileInput->ls();

  TEfficiency* h_efficiency = 0;

  TH1F *h_denominator;
  TH1F *h_numerator;
  if(histoFromFile==1)
    {
      //== taking histo from file       
      h_denominator = (TH1F*)fileInput->Get(mydenominator);
      h_numerator   = (TH1F*)fileInput->Get(mynumerator);
    }
  else
    {
      //== creating histo from tree   
      TTree *thistree = (TTree*)fileInput->Get("rootTupleTree/tree");
      thistree->Print();
      TH1F *h_denominator_tmp = (TH1F*)fileInput->Get(mydenominator);
      h_denominator = (TH1F*)h_denominator_tmp->Clone();
      h_numerator = (TH1F*)h_denominator_tmp->Clone();
      h_denominator->Reset();
      h_numerator->Reset();
      h_denominator->SetName("h_denominator");
      h_numerator->SetName("h_numerator");
      //fill histograms
      //--
      //thistree->Draw("mjj >> h_denominator","fabs(deltaETAjj)<1.3 && passHLT_PFHT475==1"); //signal region
      //thistree->Draw("mjj >> h_denominator","fabs(deltaETAjj)<1.3 && passHLT_Mu45==1"); //signal region
      thistree->Draw("mjj >> h_denominator","fabs(deltaETAjj)>1.3 && fabs(deltaETAjj)<2.6 && passHLT_Mu45==1"); //control region
      //--
      //thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)<1.3 && passHLT_PFHT475==1 && passHLT_PFHT800==1");
      //thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)<1.3 && passHLT_Mu45==1 && passHLT_PFHT800==1");
      //thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)<1.3 && passHLT_Mu45==1 && (passHLT_PFHT800==1 || passHLT_PFJET500==1)");
      thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)>1.3 && fabs(deltaETAjj)<2.6 && passHLT_Mu45==1 && (passHLT_PFHT800==1 || passHLT_PFJET500==1)");
      //thistree->Draw("mjj >> h_numerator","fabs(deltaETAjj)>1.3 && fabs(deltaETAjj)<2.6 && passHLT_Mu45==1 && (passHLT_PFHT800==1 || passHLT_PFJET500==1 || passHLT_PFHT650MJJ950==1 || passHLT_PFHT650MJJ900==1 || passHLT_AK8DiPFJet280200TrimMass30Btag==1 || passHLT_AK8PFHT600TriMass50Btag==1 || passHLT_AK8PFHT700TriMass50==1 || passHLT_AK8PFJet360TrimMass50==1 || passHLT_CaloJet500NoJetID==1 || passHLT_DiPFJetAve300HFJEC==1 || passHLT_DiPFJetAve500==1 || passHLT_PFHT400SixJet30Btag==1 || passHLT_PFHT450SixJet40Btag==1 || passHLT_PFHT750FourJetPt50==1 || passHLT_QuadPFJetVBF==1 || passHLT_PFHT650==1 || passHLT_PFHT475==1 || passHLT_PFHT200==1 || passHLT_PFJET450==1)");
      //-- option placeholder 
      //thistree->Draw("mjj >> h_denominator","fabs(deltaETAjj)<1.3 && passHLT_Mu45==1","",10000);
      //--  
    }

  //==========================

  if(TEfficiency::CheckConsistency(*h_numerator,*h_denominator))
    {
      h_efficiency = new TEfficiency(*h_numerator,*h_denominator);    
      //stat option, see https://root.cern.ch/root/html/TEfficiency.html#TEfficiency:SetStatisticOption
      h_efficiency->SetStatisticOption(TEfficiency::kFWilson);  
      //h_efficiency->SetStatisticOption(TEfficiency::kFCP); //default  
      h_efficiency->SetTitle(mytitle);
      h_efficiency->Draw();
      gPad->Update();
      h_efficiency->GetPaintedGraph()->GetXaxis()->SetRangeUser(xmin,xmax);
      h_efficiency->GetPaintedGraph()->GetXaxis()->SetNdivisions(505);
      h_efficiency->GetPaintedGraph()->GetYaxis()->SetRangeUser(ymin,ymax);
      //h_efficiency->GetPaintedGraph()->GetYaxis()->SetTitleOffset(0.9);
      // h_efficiency->GetPaintedGraph()->GetYaxis()->SetLabelSize(0.04);

      for (int bin=0;bin<h_efficiency->GetPaintedGraph()->GetN();bin++)
	{
	  double x=-1; 
	  double y=-1;
	  double eyh=-1;
	  double eyl=-1;

	  h_efficiency->GetPaintedGraph()->GetPoint(bin,x,y);
	  eyh = h_efficiency->GetPaintedGraph()->GetErrorYhigh(bin);
	  eyl = h_efficiency->GetPaintedGraph()->GetErrorYlow(bin);
	  cout << "bin = " << bin << ": x= " << x << " , y = " << y << " + " << eyh << " - " << eyl << endl;       
	}

      // draw the legend
      TLegend *legend=new TLegend(0.35,0.22,0.89,0.32);
      //legend->SetTextFont(72);
      //legend->SetTextSize(0.04);
      legend->SetFillStyle(0);
      legend->SetLineColor(0);
      legend->SetShadowColor(0);
      legend->AddEntry(h_efficiency,mytitlelegend,"lpe");
      legend->Draw();
    }

  //====================================================================================
  //Draw

  //## Trigger Efficiency plot ##
  // writing the lumi information and the CMS "logo"
  CMS_lumi( canv, iPeriod, iPos ); 
  canv->Update();
  canv->RedrawAxis();
  canv->GetFrame()->Draw();
  gPad->SetTickx(1);
  gPad->SetTicky(1);
  canv->Print(myoutputfilename+".pdf",".pdf");
  canv->Print(myoutputfilename+".png",".png");
  canv->Print(myoutputfilename+".root",".root");
  
  //## Trigger Efficiency plot (zoom) ## 
  h_efficiency->GetPaintedGraph()->GetXaxis()->SetRangeUser(xminZoom,xmaxZoom);
  h_efficiency->GetPaintedGraph()->GetYaxis()->SetRangeUser(yminZoom,ymaxZoom);

  CMS_lumi( canv, iPeriod, iPos ); 
  canv->Update();
  canv->RedrawAxis();
  canv->GetFrame()->Draw();
  gPad->SetTickx(1);
  gPad->SetTicky(1);
  canv->Print(myoutputfilename+"_zoom.pdf",".pdf");
  canv->Print(myoutputfilename+"_zoom.png",".png");
  
  //Integral above threshold
  int totalNev =  h_denominator->Integral(h_denominator->FindFixBin(threshold),h_denominator->GetNbinsX());
  int passedNev =  h_numerator->Integral(h_numerator->FindFixBin(threshold),h_numerator->GetNbinsX());
  //int totalNev =  h_denominator->Integral(h_denominator->FindFixBin(threshold),h_denominator->FindFixBin(threshold));
  //int passedNev =  h_numerator->Integral(h_numerator->FindFixBin(threshold),h_numerator->FindFixBin(threshold));
  float effIntegrated = float(passedNev)/float(totalNev);
  cout << "totalNev = " << totalNev <<  " , passedNev=" << passedNev << " , efficiency=" << effIntegrated << endl;       
  TEfficiency* pEff = 0;
  float effIntegrated_errUp = pEff->Wilson(totalNev,passedNev,0.683,true) - effIntegrated;
  float effIntegrated_errDown = pEff->Wilson(totalNev,passedNev,0.683,false) - effIntegrated;
  cout << "efficiency integrated above threshold of "<< threshold <<" = " << effIntegrated << " + " << effIntegrated_errUp << " - " << effIntegrated_errDown << endl;


  //## Mjj Spectra ##
  canv->SetGridx(false);
  canv->SetGridy(false);
  canv->SetLogy(true);
  h_denominator->UseCurrentStyle();  
  h_denominator->SetLineColor(2);
  h_numerator->SetLineColor(1);
  h_denominator->Draw();
  h_numerator->Draw("same");
  h_denominator->GetXaxis()->SetRangeUser(xmin,xmax);
  h_denominator->GetXaxis()->SetTitle(xAxisTitle);
  h_denominator->GetYaxis()->SetTitle(yAxisTitle);
  h_denominator->GetYaxis()->SetTitleOffset(1.3);

  CMS_lumi( canv, iPeriod, iPos ); 
  canv->Update();
  canv->RedrawAxis();
  canv->GetFrame()->Draw();
  gPad->SetTickx(1);
  gPad->SetTicky(1);

  // draw the legend
  TLegend *legend1=new TLegend(0.4,0.65,0.91,0.83);
  //legend->SetTextFont(72);
  //legend->SetTextSize(0.06);
  legend1->SetFillStyle(0);
  legend1->SetLineColor(0);
  legend1->SetShadowColor(0);
  legend1->AddEntry(h_denominator,mytitlelegendDen,"l");
  legend1->AddEntry(h_numerator,mytitlelegendNum,"l");
  legend1->Draw();

  canv->Print(myoutputfilename+"_histo.pdf",".pdf");
  canv->Print(myoutputfilename+"_histo.png",".png");
  



  //-----------------------------------------------------------------------------

}
void plotGJetsScaleFactorSystematics(string label) {

  TFile *inf = new TFile(Form("data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root",label.c_str()),"READ");

  TH2Poly *ttbarNominal = (TH2Poly*)inf->Get("TTJetsScaleFactors");
  TH2Poly *ttbarUp = (TH2Poly*)inf->Get("TTJetsScaleFactorsUp");
  TH2Poly *ttbarDown = (TH2Poly*)inf->Get("TTJetsScaleFactorsDown");
  TH2Poly *wNominal = (TH2Poly*)inf->Get("WJetsScaleFactors");
  TH2Poly *wUp = (TH2Poly*)inf->Get("WJetsScaleFactorsUp");
  TH2Poly *wDown = (TH2Poly*)inf->Get("WJetsScaleFactorsDown");
  TH2Poly *wInvNominal = (TH2Poly*)inf->Get("WJetsInvScaleFactors");
  TH2Poly *wInvUp = (TH2Poly*)inf->Get("WJetsInvScaleFactorsUp");
  TH2Poly *wInvDown = (TH2Poly*)inf->Get("WJetsInvScaleFactorsDown");
  TH2Poly *GJetInvNominal = (TH2Poly*)inf->Get("GJetsInvScaleFactors");

  TCanvas *cv = 0;
  gStyle->SetPaintTextFormat("4.2f");

  //****************************************************
  //Systematic Uncertainty and GJets Down SF Histogram
  //****************************************************
  TH2Poly *GJetsSystematicUnc = (TH2Poly*)GJetInvNominal->Clone("GJetsSystematicUnc");
  TH2Poly *GJetsScaleFactor_Down = (TH2Poly*)GJetInvNominal->Clone("GJetsInvScaleFactors_Down");

  //Get bins of each histogram
  TList *wInvBins = wInvNominal->GetBins();
  TList *gInvBins = GJetInvNominal->GetBins();

  //Loop over GJets bins
  TH2PolyBin *gBin, *wBin; //temp variables to hold bin info
  for (int i = 1; i < GJetsSystematicUnc->GetNumberOfBins()+1; ++i) {

      //Get GJets bin
      gBin = (TH2PolyBin*)gInvBins->At(i-1);

      cout << "In bin " << i << " of GJets histogram" << endl;
      //cout << gBin->GetXMin() << " " << gBin->GetXMax() << " " << gBin->GetYMin() << " " << gBin->GetYMax() << endl;

      //Find out which WJets bin we are in
      int wBinNum = -1;
      for (int j = 1; j < wInvNominal->GetNumberOfBins()+1; ++j) {

          //Get WJets bin
          wBin = (TH2PolyBin*)wInvBins->At(j-1);

          //cout << "In bin " << j << " of WJets histogram" << endl;
          //cout << wBin->GetXMin() << " " << wBin->GetXMax() << " " << wBin->GetYMin() << " " << wBin->GetYMax() << endl;

          //Check if this GJets bin is inside this WJets bin
          if ( gBin->GetXMin() >= wBin->GetXMin() &&
               gBin->GetXMax() <= wBin->GetXMax() &&
               gBin->GetYMin() >= wBin->GetYMin() &&
               gBin->GetYMax() <= wBin->GetYMax() ) {
              cout << "This GJets bin is inside bin " << j << " of WJets histogram" << endl;
              wBinNum = j;
              break;
          }
      }

      double gjet = GJetInvNominal->GetBinContent(i);
      double wjet = wInvNominal->GetBinContent(wBinNum);

      //Set bin content of each histogram
      GJetsSystematicUnc->SetBinContent(i, (gjet - wjet)/gjet );
      GJetsScaleFactor_Down->SetBinContent(i, gjet - (wjet - gjet) );

      cout << "Bin " << i << " : " << gjet << " , " << wjet << " , " <<  gjet - (wjet - gjet) << "\n";
  }

  cv = new TCanvas("cv","cv", 800,600);
  gStyle->SetPalette(1);
  GJetsSystematicUnc->Draw("colztext");
  cv->SetLogx();
  cv->SetLogy();
  cv->SetRightMargin(0.175);
  cv->SetBottomMargin(0.12);
  GJetsSystematicUnc->GetXaxis()->SetRangeUser(400,4000);
  GJetsSystematicUnc->GetYaxis()->SetRangeUser(0.25,1.5);
  GJetsSystematicUnc->GetZaxis()->SetTitle("Systematic Uncertainty");
  GJetsSystematicUnc->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]");
  GJetsSystematicUnc->GetYaxis()->SetTitle("R^{2}");
  GJetsSystematicUnc->SetTitle("");
  GJetsSystematicUnc->GetZaxis()->SetLabelSize(0.05);
  GJetsSystematicUnc->GetZaxis()->SetTitleSize(0.05);
  GJetsSystematicUnc->GetXaxis()->SetLabelSize(0.05);
  GJetsSystematicUnc->GetXaxis()->SetTitleSize(0.05);
  GJetsSystematicUnc->GetXaxis()->SetTitleOffset(0.8);
  GJetsSystematicUnc->GetYaxis()->SetLabelSize(0.05);
  GJetsSystematicUnc->GetYaxis()->SetTitleSize(0.05);
  GJetsSystematicUnc->GetYaxis()->SetTitleOffset(0.8);
  GJetsSystematicUnc->SetStats(false);
  GJetsSystematicUnc->SetMaximum(1.0);
  GJetsSystematicUnc->SetMinimum(-1.0);

  lumi_13TeV = "35.9 fb^{-1}";
  writeExtraText = true;
  relPosX = 0.13;
  lumiTextSize = 0.5;
  cmsTextSize = 0.6;
  extraOverCmsTextSize = 0.85;
  CMS_lumi(cv,4,0);
  cv->SaveAs(Form("GJetsVsWJetsSystematic_%s.png",label.c_str()));
  cv->SaveAs(Form("GJetsVsWJetsSystematic_%s.pdf",label.c_str()));

  TFile *outf = new TFile(Form("data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root",label.c_str()),"UPDATE");
  outf->WriteTObject(GJetsScaleFactor_Down, GJetsScaleFactor_Down->GetName(), "WRITEDELETE");
  outf->Close();

}
Example #26
0
void MakePlotFakeDistMC(){
  
  TString path_ttbar = "/home/jalmond/Analysis/LQanalyzer/data/output/ElectronFakes//MC/FakeRateCalculator_El_SKttbar_5_3_14.root";
  
  TString path_qcd= "/home/jalmond/Analysis/LQanalyzer/data/output/ElectronFakes/FakeRateCalculator_El_SKQCD_5_3_14.root";
  
  TString path_wjet = "/home/jalmond/Analysis/LQanalyzer/data/output/ElectronFakes/MC/FakeRateCalculator_El_SKWjets_5_3_14.root";

  

  setTDRStyle();
  gStyle->SetPalette(1);
  
  TFile * fttbar = new TFile(path_ttbar);
  TFile * fqcd = new TFile(path_qcd);
  TFile * fwjet = new TFile(path_wjet);
  
  vector<TString> list_of_regions;
  list_of_regions.push_back("SingleElFake");
  list_of_regions.push_back("DoubleElFake");
 
  
  vector<TString> list_of_names;
  list_of_names.push_back("HT");
  list_of_names.push_back("eemass");
  list_of_names.push_back("MET");
  list_of_names.push_back("Njets");
  list_of_names.push_back("Nbjets");
  list_of_names.push_back("leadElectrondPhi");
  list_of_names.push_back("ElectronRelIso");


  vector<TString> xaxis_label;
  xaxis_label.push_back("H_{T} GeV");
  xaxis_label.push_back("m(ee) GeV");
  xaxis_label.push_back("MET GeV");
  xaxis_label.push_back("N(jets)");
  xaxis_label.push_back("N(bjets)");
  xaxis_label.push_back("#Delta#phi (ee)");
  xaxis_label.push_back("Iso_{PF} / p_{T}")

  vector<TString> yaxis_label;
  yaxis_label.push_back("Entries");
  yaxis_label.push_back("Entries");
  yaxis_label.push_back("Entries");
  yaxis_label.push_back("Entries");
  yaxis_label.push_back("Entries");
  yaxis_label.push_back("Entries");
  yaxis_label.push_back("Entries");
  
 
  for(unsigned int j = 0; j < list_of_regions.size(); j++){
    for(unsigned int i = 0; i < list_of_names.size(); i++){
      
      
      TCanvas* c1 = new TCanvas((("Plot")+ list_of_regions.at(j )+ "/" + list_of_names.at(i)).Data(), "Plot", 1600, 1200);
      
      cout << "Getting " << ("h_"+list_of_regions.at(j ) + "/"+  list_of_names.at(i) + "_" + list_of_regions.at(j ) ) << endl;
      TH1F* h_ttbar= (TH1F*)fttbar->Get(((list_of_regions.at(j ) + "/h_"+  list_of_names.at(i) + "_" + list_of_regions.at(j ) ).Data()));
      
      
      TH1F* h_qcd= (TH1F*)fqcd->Get(((list_of_regions.at(j ) + "/h_"+  list_of_names.at(i) + "_" + list_of_regions.at(j ) ).Data()));

      
      TH1F* h_wjet= (TH1F*)fwjet->Get(((list_of_regions.at(j ) + "/h_"+  list_of_names.at(i) + "_" + list_of_regions.at(j ) ).Data()));


      cout << h_qcd << endl;
      bool usew = (h_wjet);
      bool usetop = (h_ttbar);
      bool useqcd = (h_qcd);
      
      if(h_qcd){
	h_qcd->SetLineColor(kRed);
	h_qcd->SetFillColor(kRed);
	h_qcd->SetLineWidth(2.);
	h_qcd->SetFillStyle(3003);
      }
      if(usetop){
	h_ttbar->SetLineColor(kCyan);
	h_ttbar->SetFillColor(kCyan);
	h_ttbar->SetLineWidth(2.);
	h_ttbar->SetFillStyle(3004);
      }
      if(usew){
	h_wjet->SetLineColor(kOrange);
	h_wjet->SetFillColor(kOrange);
	h_wjet->SetFillStyle(3007);
	h_wjet->SetLineWidth(2.);
      }
      int nrebin = 1;
      if(list_of_names.at(i).Contains("HT")) nrebin= 1;
      if(list_of_names.at(i).Contains("MET")) nrebin= 2;
      if(list_of_names.at(i).Contains("eemass")) nrebin= 4;
      if(useqcd)h_qcd->Rebin(nrebin);
      if(usetop){
	h_ttbar->Rebin(nrebin);
      }
      if(usew){
	h_wjet->Rebin(nrebin);
      }
      
      if(useqcd){
	h_qcd->GetYaxis()->SetTitle(yaxis_label.at(i));
	h_qcd->GetXaxis()->SetTitle(xaxis_label.at(i));
	
	h_qcd->GetYaxis()->SetRangeUser(0.,  h_qcd->GetMaximum()* 1.1);
	h_qcd->Draw("hist");
	if(usetop)h_ttbar->Draw("histsame");
	if(usew)h_wjet->Draw("histsame");

      }
      else{
	if(usetop){
	  h_ttbar->GetYaxis()->SetTitle(yaxis_label.at(i));
	  h_ttbar->GetXaxis()->SetTitle(xaxis_label.at(i));
	  
	  float max =  h_ttbar->GetMaximum()* 1.1;
	  if(h_wjet->GetMaximum()* 1.1   > max) max = h_wjet->GetMaximum()* 1.1 ;
	  h_ttbar->GetYaxis()->SetRangeUser(0.,  max);
	  h_ttbar->Draw("hist");
	  if(usew)h_wjet->Draw("histsame");

	}
      }

      TLegend* legendH = new TLegend(0.7, 0.75, 0.9, 0.9);
      legendH->SetFillColor(kWhite);
      legendH->SetTextSize(0.03);
      legendH->SetTextFont(42);
      if(useqcd)legendH->AddEntry(h_qcd, "QCD", "f");
      if(usetop)legendH->AddEntry(h_ttbar, "t#bar{t}", "f");
      if(usew)legendH->AddEntry(h_wjet, "W+jet", "f");
      legendH->Draw();
            
      CMS_lumi( c1, 2, 11 );
      c1->Update();
      c1->RedrawAxis();
      
      c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/Fakes/MCFakeDist_all_" + list_of_regions.at(j ) + "_" + list_of_names.at(i) + ".pdf").Data());
    }
  }

}
Example #27
0
void plotLimit(int signal = 0){
//signal: 0 = ZPN, 1 = ZPW, 2 = ZPXW, 3 = RSG  

setTDRStyle();

//gROOT->SetStyle("Plain");
gStyle->SetOptStat(0000000000); //this clears all the boxes and crap
gStyle->SetLegendBorderSize(1);

TGraph * limit_obs = new TGraph(3);
TGraph * limit_exp = new TGraph(3);
TGraphAsymmErrors * band_exp1 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2 = new TGraphAsymmErrors();

TGraph * limit_obs_2 = new TGraph(3);
TGraph * limit_exp_2 = new TGraph(3);
TGraphAsymmErrors * band_exp1_2 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_2 = new TGraphAsymmErrors();
TGraph * limit_obs_3 = new TGraph(3);
TGraph * limit_exp_3 = new TGraph(3);
TGraphAsymmErrors * band_exp1_3 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_3 = new TGraphAsymmErrors();
TGraph * limit_obs_4 = new TGraph(3);
TGraph * limit_exp_4 = new TGraph(3);
TGraphAsymmErrors * band_exp1_4 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_4 = new TGraphAsymmErrors();
TGraph *theory = new TGraph(3);
TGraph *theory2 = new TGraph(3);
TGraph *theory3 = new TGraph(3);
TGraph *theory4 = new TGraph(3);

   theory->SetPoint(0,  0.01, 4.24671);

   theory->SetPoint(1,  0.1, 42.24246);

   theory->SetPoint(2,  0.3, 122.17487);
   theory2->SetPoint(0,  0.01, 0.17980);
   theory2->SetPoint(1,  0.1, 2.00723);
   theory2->SetPoint(2,  0.3, 6.99950);
   theory3->SetPoint(0, 0.01, 0.01659*0.1);
   theory3->SetPoint(1,  0.1, 0.23030*0.1);
   theory3->SetPoint(2,  0.3, 1.03387*0.1);
   theory4->SetPoint(0, 0.01, 0.00203*0.01);
   theory4->SetPoint(1, 0.1, 0.04254*0.01);
   theory4->SetPoint(2, 0.3, 0.25352*0.01); 

 string filename = "Limits/comb_width_1TeV.txt";
 if (signal == 1) filename= "Limits/comb_width_2TeV.txt";
 if (signal == 2) filename= "Limits/comb_width_3TeV.txt";
 if (signal == 3) filename= "Limits/comb_width_4TeV.txt";

ifstream infile(filename);

double mass, exp, obs, up1, up2, dn1, dn2;
int point = 0;

while (!infile.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 1.0;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs->SetPoint(point, mass, obs*sf);
  limit_exp->SetPoint(point, mass, exp*sf);
  band_exp1->SetPoint(point, mass, exp*sf);
  band_exp2->SetPoint(point, mass, exp*sf);
  
  band_exp1->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile2 ("Limits/comb_width_2TeV.txt");
point = 0;
while (!infile2.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile2 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 1.0;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_2->SetPoint(point, mass, obs*sf);
  limit_exp_2->SetPoint(point, mass, exp*sf);
  band_exp1_2->SetPoint(point, mass, exp*sf);
  band_exp2_2->SetPoint(point, mass, exp*sf);
  
  band_exp1_2->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_2->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_2->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_2->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile3 ("Limits/comb_width_3TeV.txt");
point = 0;

while (!infile3.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile3 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 0.1;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_3->SetPoint(point, mass, obs*sf);
  limit_exp_3->SetPoint(point, mass, exp*sf);
  band_exp1_3->SetPoint(point, mass, exp*sf);
  band_exp2_3->SetPoint(point, mass, exp*sf);

  band_exp1_3->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_3->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_3->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_3->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile4 ("Limits/comb_width_4TeV.txt");
point = 0;

while (!infile4.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile4 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 0.01;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_4->SetPoint(point, mass, obs*sf);
  limit_exp_4->SetPoint(point, mass, exp*sf);
  band_exp1_4->SetPoint(point, mass, exp*sf);
  band_exp2_4->SetPoint(point, mass, exp*sf);
  band_exp1_4->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_4->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_4->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_4->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}





double max = 200000.0; //band_exp2->GetHistogram()->GetMaximum()*50;

  TCanvas *canvas = new TCanvas("limit set ZPN","limit set ZPN", 500,500);

  limit_exp->SetMinimum(0.00001);
  limit_exp->GetXaxis()->SetLabelSize(0.05);
  limit_exp->GetYaxis()->SetLabelSize(0.05);
  limit_exp->Draw("AL");
  if (signal == 0){
    limit_exp->GetXaxis()->SetTitle("#Gamma_{Z'} / M_{Z'}");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 1){
    limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 2){
    limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 3){
    limit_exp->GetXaxis()->SetTitle("M_{g_{KK}} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{g_{KK}} #times B(g_{KK}#rightarrowt#bar{t}) [pb]");
  }
  //limit_exp->GetYaxis()->SetTitleOffset(1.2);
  limit_exp->GetYaxis()->SetRangeUser(0.00001,2000);


  band_exp2->SetFillColor(5);
  band_exp2->SetLineColor(0);
  //band_exp2->SetFillStyle(4000);
  band_exp2->Draw("3same");

  band_exp1->SetFillColor(3);
  band_exp1->SetLineColor(0);
  //band_exp1->SetFillStyle(4000);
  band_exp1->Draw("3same");

  limit_obs->Draw("Lsame");
  limit_obs->SetLineWidth(2);
  limit_obs->SetMarkerSize(1.0);
  limit_obs->SetMarkerStyle(20);
   
  limit_exp->Draw("Lsame");
  limit_exp->SetLineStyle(2);
  limit_exp->SetLineWidth(2);
  limit_exp->SetMarkerSize(1.0);
  limit_exp->SetMaximum(max);
  limit_exp->SetMinimum(0.000001);
  limit_exp->SetMarkerStyle(20);
  

  band_exp2_2->SetFillColor(5);
  band_exp2_2->SetLineColor(0);
  band_exp1_2->SetFillColor(3);
  band_exp1_2->SetLineColor(0);
  band_exp2_3->SetFillColor(5);
  band_exp2_3->SetLineColor(0);
  band_exp1_3->SetFillColor(3);
  band_exp1_3->SetLineColor(0);
  band_exp2_4->SetFillColor(5);
  band_exp2_4->SetLineColor(0);
  band_exp1_4->SetFillColor(3);
  band_exp1_4->SetLineColor(0);
  band_exp2_2->Draw("3same");
  band_exp1_2->Draw("3same");
  limit_obs_2->Draw("Lsame");
  limit_obs_2->SetLineWidth(2);
  limit_obs_2->SetMarkerSize(1.0);
  limit_obs_2->SetMarkerStyle(20);
  band_exp2_3->Draw("3same");
  band_exp1_3->Draw("3same");
  limit_obs_3->Draw("Lsame");
  limit_obs_3->SetLineWidth(2);
  limit_obs_3->SetMarkerSize(1.0);
  limit_obs_3->SetMarkerStyle(20);
  band_exp2_4->Draw("3same");
  band_exp1_4->Draw("3same");
  limit_obs_4->Draw("Lsame");
  limit_obs_4->SetLineWidth(2);
  limit_obs_4->SetMarkerSize(1.0);
  limit_obs_4->SetMarkerStyle(20);

  limit_exp_2->Draw("L same");
  limit_exp_2->SetLineStyle(2);
  limit_exp_2->SetLineWidth(2);
  limit_exp_2->SetMarkerSize(1.0);
  limit_exp_3->Draw("L same");
  limit_exp_3->SetLineStyle(2);
  limit_exp_3->SetLineWidth(2);
  limit_exp_3->SetMarkerSize(1.0);
  limit_exp_4->Draw("L same");
  limit_exp_4->SetLineStyle(2);
  limit_exp_4->SetLineWidth(2);
  limit_exp_4->SetMarkerSize(1.0);








    canvas->RedrawAxis();

  double x1 = 595; 
  double y1 = 1.0;
  double x2 = 905;
  double y2 = 1.0;
  TLine * line = new TLine(x1, y1, x2, y2);
  theory->SetLineColor(2);
  theory->SetLineWidth(2);
  theory->Draw("same");
	theory2->SetLineColor(kBlue);
	theory2->SetLineWidth(2);
	theory2->Draw("same");
	theory3->SetLineColor(kMagenta);
	theory3->SetLineWidth(2);
	theory3->Draw("same");
	theory4->SetLineColor(kCyan);
	theory4->SetLineWidth(2);
	theory4->Draw("same");

  CMS_lumi(canvas, 4, 10);

  float t = canvas->GetTopMargin();
  float r = canvas->GetRightMargin();

  //Legend
  TLegend *l = new TLegend(0.51,0.63,0.99-r,0.99-t);
  l->AddEntry(limit_obs,"Observed", "L");
  l->AddEntry(limit_exp,"Expected", "L");
  l->AddEntry(band_exp1,"#pm1 #sigma Exp.", "F");
  l->AddEntry(band_exp2,"#pm2 #sigma Exp.", "F");
    l->AddEntry(theory, "Z' 1 TeV (NLO)", "L");
    l->AddEntry(theory2, "Z' 2 TeV (NLO)", "L");
    l->AddEntry(theory3, "Z' 3 TeV (NLO x 0.1)", "L");
    l->AddEntry(theory4, "Z' 4 TeV (NLO x 0.01)", "L");
  l->SetFillColor(0);
  l->SetLineColor(0);
  l->SetTextSize(0.04);
  l->SetTextFont(42);
  l->Draw();

  //TLatex * label = new TLatex();
  //label->SetNDC();
  //label->DrawLatex(0.2,0.86,"CMS Preliminary, 19.7 fb^{-1}");
  //label->DrawLatex(0.2,0.80,"#sqrt{s} = 8 TeV");
  //label->DrawLatex(0.6,0.80, Form("BR(b'#rightarrow %s) = 1", channel.Data()));
  //label->DrawLatex(0.55,0.80, "BR(b'#rightarrow tW) = 0.5");
  //label->DrawLatex(0.55,0.74, "BR(b'#rightarrow bH) = 0.25");
  //label->DrawLatex(0.55,0.68, "BR(b'#rightarrow bZ) = 0.25");
  //label->DrawLatex(0.2,0.74, lepton.Data());

  canvas->SetLogy(1);
  canvas->SetLogx(1);
  canvas->SetTickx(1);
  canvas->SetTicky(1);


  if (signal == 0){
    canvas->Print("Limits/comb_ZPN_limit.pdf");
    canvas->Print("Limits/comb_ZPN_limit.root");
  }
  else if (signal == 1){
    canvas->Print("Limits/comb_ZPW_limit.pdf");
    canvas->Print("Limits/comb_ZPW_limit.root");
  }
  else if (signal == 2){
    canvas->Print("Limits/comb_ZPXW_limit.pdf");
    canvas->Print("Limits/comb_ZPXW_limit.root");
  }
  else if (signal == 3){
    canvas->Print("Limits/comb_RSG_limit.pdf");
    canvas->Print("Limits/comb_RSG_limit.root");
  }
}
Example #28
0
void fitcorr(){

   setTDRStyle();

   TFile *f = new TFile("rootfiles/fitresults_2D_data.root");
   TTree *t = (TTree*)f->Get("FitResults");

   double mt=0, jsf=0, mcmass=0;
   t->SetBranchAddress("mt", &mt);
   t->SetBranchAddress("jesfactor", &jsf);
   t->SetBranchAddress("mcmass", &mcmass);

   TH2D *h2D = new TH2D("h2D",";M_{t} [GeV];JSF", 20, 170, 173, 20, 0.99, 1.04 );
   TGraph *g = new TGraph();
   for( int i=0; i < t->GetEntries(); i++ ){
      t->GetEntry(i);
      //if( mcmass != 172.5 ) continue;

      h2D->Fill(mt, jsf);
      g->SetPoint(g->GetN(), mt, jsf);

   }

   // uncertainty contour
   double mean_mt = g->GetMean(1);
   double mean_jsf = g->GetMean(2);
   double sigma_mt = g->GetRMS(1);
   double sigma_jsf = g->GetRMS(2);
   double rho = g->GetCorrelationFactor();
   std::cout << "Mean Mt = " << mean_mt << " +- " << sigma_mt << std::endl;
   std::cout << "Mean JSF = " << mean_jsf << " +- " << sigma_jsf << std::endl;
   std::cout << "Correlation = " << rho << std::endl;

   TMatrixDSym m(2);
   m(0,0) = sigma_mt*sigma_mt;
   m(1,1) = sigma_jsf*sigma_jsf;
   m(0,1) = rho*sigma_mt*sigma_jsf;
   m(1,0) = rho*sigma_mt*sigma_jsf;
   TMatrixDSymEigen eigen(m);
   TVectorD eigenval = eigen.GetEigenValues();
   std::cout << eigenval[0] << " " << eigenval[1] << endl;

   // convert to ellipse tilt and radius
   //double phi = 0.5*TMath::ATan( (3/0.03)*(2*rho*sigma_mt*sigma_jsf)/(sigma_mt*sigma_mt-sigma_jsf*sigma_jsf) );
   double phi = (180.0/TMath::Pi())*0.5*TMath::ATan( (2*rho*sigma_mt*sigma_jsf)/(sigma_mt*sigma_mt-sigma_jsf*sigma_jsf) );
   std::cout << "phi = " << phi << std::endl;

   TEllipse *el = new TEllipse(mean_mt, mean_jsf, sqrt(eigenval[0]), sqrt(eigenval[1]), 0, 360, phi);
   TEllipse *el2 = new TEllipse(mean_mt, mean_jsf, 2*sqrt(eigenval[0]), 2*sqrt(eigenval[1]), 0, 360, phi);
   
   /*
   TF2* fell = new TF2("fell","pow((x-[1])*cos([0])+(y-[2])*sin([0]),2)/[3] + pow((x-[1])*sin([0])-(y-[2])*cos([0]),2)/[4]",171,174,0.985,1.015);
   fell->SetParameter(0,phi);
   fell->SetParameter(1,mean_mt);
   fell->SetParameter(2,mean_jsf);
   fell->SetParameter(3,eigenval[0]);
   fell->SetParameter(4,eigenval[1]);

   double cont[1] = {1};
   fell->SetContour(1, cont);
   */
   
   const Int_t Number = 2;
   Double_t Red[Number]    = { 0.90, 0.10};
   Double_t Green[Number]  = { 0.90, 0.10};
   Double_t Blue[Number]   = { 0.90, 0.10};
   Double_t Stops [Number] = {0, 1};
   Double_t Length [Number] = {0, 1};
   Int_t nb=50;
   TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);

   gStyle->SetPadRightMargin(0.16);
   gStyle->SetPadTopMargin(0.08);

   TCanvas *c = new TCanvas("c","c",800,600);
   h2D->Draw("colzC");
   el->SetFillStyle(0);
   el->SetLineColor(2);
   el->SetLineWidth(3);
   el->Draw();
   el2->SetFillStyle(0);
   el2->SetLineColor(2);
   el2->SetLineWidth(3);
   el2->Draw();

   int iPeriod = 2;
   int iPos = 33;
   lumi_sqrtS = "8 TeV";
   writeExtraText = false;
   CMS_lumi( c, iPeriod, iPos );

   c->Update();
   c->RedrawAxis();
   c->GetFrame()->Draw();

   TLatex latex;
   latex.SetNDC();
   latex.SetTextSize(0.06);
   latex.SetTextFont(42);
   latex.DrawLatex(0.2, 0.84, "2D fit");

   c->Print("pdfplots/fitcorr.pdf");

   //delete c;


   return;
}