Example #1
0
void drawLabels(){

  // "Hadron Gas"
  TLatex *xHad1 = new TLatex(0.11, 0.13, "Hadron");
  TLatex *xHad2 = new TLatex(0.15, 0.085, "Gas");
  xHad1->SetTextSize(0.04);
  xHad2->SetTextSize(0.04);
  if(iColor)xHad1->SetTextColor(4);
  if(iColor)xHad2->SetTextColor(4);
  xHad1->Draw();
  xHad2->Draw();

  //"Quark Gloun Plasma"
  TLatex *xQGP1 = new TLatex(0.55, 0.8, "Quark Gluon");
  TLatex *xQGP2 = new TLatex(0.62, 0.755, "Plasma");
  xQGP1->SetTextSize(0.04);
  xQGP2->SetTextSize(0.04);
  if(iColor)xQGP1->SetTextColor(4);
  if(iColor)xQGP2->SetTextColor(4);
  xQGP1->Draw();
  xQGP2->Draw();

  //"Early Universe"
  TArrow *aUniv = new TArrow(.025, 0.95,.025, 0.45,0.03,"|>");
  aUniv->SetLineWidth(2);
  if(iColor)aUniv->SetLineColor(2);
  if(iColor)aUniv->SetFillColor(2);
  aUniv->Draw();
  TLatex *xUniv = new TLatex(0.075, 0.58, "Early Universe");
  xUniv->SetTextSize(0.04);
  xUniv->SetTextAngle(90);
  if(iColor)xUniv->SetTextColor(2);
  xUniv->Draw();
  
  //"Neutron Stars"
  TArrow *aNeut = new TArrow(.65, .05 ,.99, 0.075,0.03,"|>");
  aNeut->SetLineWidth(2);
  if(iColor)aNeut->SetLineColor(8);
  if(iColor)aNeut->SetFillColor(8);
  aNeut->Draw();
  TLatex *xNeut = new TLatex(0.735, 0.08, "Neutron Stars");
  xNeut->SetTextSize(0.04);
  xNeut->SetTextAngle(5);
  if(iColor)xNeut->SetTextColor(8);
  xNeut->Draw();

  //"Critical Point"
  TLatex *xCrit1 = new TLatex(0.2, 0.585, "Critical");
  TLatex *xCrit2 = new TLatex(0.225, 0.54, "Point");
  xCrit1->SetTextSize(0.04);
  xCrit2->SetTextSize(0.04);
  xCrit1->Draw();
  xCrit2->Draw();
}
Example #2
0
void PlotTLHisto(TH1F* histo)
{
  histo->SetStats(kFALSE);

  //   Int_t cullay[13]={0,9,15,18,22,24,27,30,32,36,39,45,54};
  Int_t cullay[13]={-27,-18,-12,-9,-5,-3,0,3,5,9,12,18,27};
     TString modname[12]={"TEC-","TOB-","TID-","TIB-","PBwd","PBar-",
                        "PBar+","PFwd","TIB+","TID+","TOB+","TEC+"};

   histo->Draw("");
   gPad->Update();
   Float_t ymax=gPad->GetUymax();
   Float_t ymin=gPad->GetUymin();
   for(Int_t k=0;k<12;k++){
     TLine *lin= new TLine(cullay[k],ymin,cullay[k],ymax);
    lin->SetLineWidth(1);
     lin->SetLineStyle(3);
     lin->SetLineColor(4);
     if (k>0) lin->Draw();

     TLatex t;
     t.SetTextSize(0.04);
     t.SetTextAngle(90);
     Float_t tpos=cullay[k]+0.75*(cullay[k+1]-cullay[k]);
     t.DrawLatex(tpos,ymin+0.025*(ymax-ymin),modname[k]);
   }

}
Example #3
0
File: xyplot.C Project: Y--/root
void xyplot()
{
   TCanvas *c = new TCanvas("c","XY plot",200,10,700,500);

   // Remove the frame
   c->SetFillColor(kWhite);
   c->SetFrameLineColor(kWhite);
   c->SetFrameBorderMode(0);

   // Define and draw a curve the frame
   const Int_t n = 4;
   Double_t x[n] = {-1, -3, -9, 3};
   Double_t y[n] = {-1000,  900,  300, 300};
   gr = new TGraph(n,x,y);
   gr->SetTitle("XY plot");
   gr->SetMinimum(-1080);
   gr->SetMaximum(1080);
   gr->SetLineColor(kRed);
   gr->Draw("AC*");

   // Remove the frame's axis
   gr->GetHistogram()->GetYaxis()->SetTickLength(0);
   gr->GetHistogram()->GetXaxis()->SetTickLength(0);
   gr->GetHistogram()->GetYaxis()->SetLabelSize(0);
   gr->GetHistogram()->GetXaxis()->SetLabelSize(0);
   gr->GetHistogram()->GetXaxis()->SetAxisColor(0);
   gr->GetHistogram()->GetYaxis()->SetAxisColor(0);

   gPad->Update();

   // Draw orthogonal axis system centered at (0,0).
   // Draw the Y axis. Note the 4th label is erased with SetLabelAttributes
   TGaxis *yaxis = new TGaxis(0, gPad->GetUymin(),
                              0, gPad->GetUymax(),
                              gPad->GetUymin(),gPad->GetUymax(),6,"+LN");
   yaxis->ChangeLabel(4,-1,0.);
   yaxis->Draw();

   // Draw the Y-axis title.
   TLatex *ytitle = new TLatex(-0.5,gPad->GetUymax(),"Y axis");
   ytitle->Draw();
   ytitle->SetTextSize(0.03);
   ytitle->SetTextAngle(90.);
   ytitle->SetTextAlign(31);

   // Draw the X axis
   TGaxis *xaxis = new TGaxis(gPad->GetUxmin(), 0,
                              gPad->GetUxmax(), 0,
                              gPad->GetUxmin(),gPad->GetUxmax(),510,"+L");
   xaxis->Draw();

   // Draw the X axis title.
   TLatex *xtitle = new TLatex(gPad->GetUxmax(),-200.,"X axis");
   xtitle->Draw();
   xtitle->SetTextAlign(31);
   xtitle->SetTextSize(0.03);
}
Example #4
0
void PlotPoints(){
	GetAllMasses();
  TCanvas *c1 = new TCanvas("c1","MassPlot",200,10,700,500);
  c1 -> DrawFrame(0, 0, 850, 600);
	TGraph *MassPlot = new TGraph(StopMass.size(), (float*) &StopMass[0], (float*) &NeutralinoMass[0]);
  MassPlot->SetMarkerStyle(20);
  MassPlot->SetMarkerSize(1.1);
  MassPlot->SetMarkerColor(2);
  MassPlot->Draw("P");
  TLatex Title = TLatex(); Title.DrawLatexNDC(.40, .94, "Mass Points");
  TLatex Xaxis = TLatex(); Xaxis.DrawLatexNDC(0.65, 0.03, "Stop Mass [GeV]");
  TLatex Yaxis = TLatex(); Yaxis.SetTextAngle(90); Yaxis.DrawLatexNDC(0.03, 0.31, "Neutralino Mass [GeV]");
  c1 -> Print(outputdir + "MassPoints.pdf", "pdf");
  c1 -> Print(outputdir + "MassPoints.png", "png");
}
Example #5
0
void drawCanvas()
{
  cPhase = new TCanvas("cPhase","cPhase",0,0,500,500);
  cPhase->SetLeftMargin(0.2);
  cPhase->SetBottomMargin(0.2);
  
  cPhase->Range(-0.2,-0.2,1.1,1.1);
  TLatex *latex = new TLatex(1.0,-0.1,"#mu_{B}");
  latex->SetTextAlign(31);
  latex->Draw();
  latex = new TLatex(-0.1,1.0,"T");
  latex->SetTextAlign(31);
  latex->SetTextAngle(90);
  latex->Draw();
}
Example #6
0
void transparency()
{
   TCanvas *c1 = new TCanvas("c1", "c1",224,330,700,527);
   c1->Range(-0.125,-0.125,1.125,1.125);

   TLatex *tex = new TLatex(0.06303724,0.0194223,"This text is opaque and this line is transparent");
   tex->SetLineWidth(2);
   tex->Draw();

   TArrow *arrow = new TArrow(0.5555158,0.07171314,0.8939828,0.6195219,0.05,"|>");
   arrow->SetLineWidth(4);
   arrow->SetAngle(30);
   arrow->Draw();

   // Draw a transparent graph.
   Double_t x[10] = {
   0.5232808, 0.8724928, 0.9280086, 0.7059456, 0.7399714,
   0.4659742, 0.8241404, 0.4838825, 0.7936963, 0.743553};
   Double_t y[10] = {
   0.7290837, 0.9631474, 0.4775896, 0.6494024, 0.3555777,
   0.622012, 0.7938247, 0.9482072, 0.3904382, 0.2410359};
   TGraph *graph = new TGraph(10,x,y);
   graph->SetLineColorAlpha(46, 0.1);
   graph->SetLineWidth(7);
   graph->Draw("l");

   // Draw an ellipse with opaque colors.
   TEllipse *ellipse = new TEllipse(0.1740688,0.8352632,0.1518625,0.1010526,0,360,0);
   ellipse->SetFillColor(30);
   ellipse->SetLineColor(51);
   ellipse->SetLineWidth(3);
   ellipse->Draw();

   // Draw an ellipse with transparent colors, above the previous one.
   ellipse = new TEllipse(0.2985315,0.7092105,0.1566977,0.1868421,0,360,0);
   ellipse->SetFillColorAlpha(9, 0.571);
   ellipse->SetLineColorAlpha(8, 0.464);
   ellipse->SetLineWidth(3);
   ellipse->Draw();

   // Draw a transparent blue text.
   tex = new TLatex(0.04871059,0.1837649,"This text is transparent");
   tex->SetTextColorAlpha(9, 0.476);
   tex->SetTextSize(0.125);
   tex->SetTextAngle(26.0);
   tex->Draw();
}
Example #7
0
void drawP1D(){
    
    gStyle->SetOptStat(0);
    gStyle->SetOptTitle(0);
    
    text.SetNDC(1);
    text.SetTextFont(43);
    text.SetTextSize(16);
    text1.SetNDC(1);
    text1.SetTextFont(43);
    text1.SetTextSize(18);
    text2.SetNDC(1);
    text2.SetTextFont(43);
    text2.SetTextSize(20);
    txt.SetNDC(1);//internal symbol
    txt.SetTextFont(43);
    txt.SetTextSize(21);
    txt.SetTextColor(16);
    txt.SetTextAngle(40);
    lab1.SetNDC(1);
    lab2.SetNDC(1);
    lab3.SetNDC(1);
    lab4.SetNDC(1);
    lab1.SetTextSize(17);
    lab2.SetTextSize(16);
    lab3.SetTextSize(16);
    lab4.SetTextSize(15);
    
    lab1.SetTextFont(73);
    lab2.SetTextFont(43);
    lab3.SetTextFont(43);
    lab4.SetTextFont(43);
    line.SetLineStyle(3);
    
   
    readin(0);
    readin(1);
    
    for (int ipt=0; ipt<1; ipt++) {
        int ic = 0;
        drawplot(ipt, ic);
      //  drawcorr(ipt, ic);
    }

    
}
Example #8
0
    void DrawCMSLogoTest(TPad* pad, TString cmsText, TString extraText, int iPosX,
		   float relPosX, float relPosY, float relExtraDY) {
    TVirtualPad *pad_backup = gPad;
    pad->cd();
    float cmsTextFont = 61;  // default is helvetic-bold

    bool writeExtraText = extraText.Length() > 0;
    float extraTextFont = 52;  // default is helvetica-italics

    // text sizes and text offsets with respect to the top frame
    // in unit of the top margin size
    TString lumiText;
    float lumiTextOffset = 0.2;
    float cmsTextSize = 0.8;
    float lumiTextSize = 0.6;
    // float cmsTextOffset    = 0.1;  // only used in outOfFrame version

    // ratio of "CMS" and extra text size
    float extraOverCmsTextSize = 0.76;

    //!!MAKE CHOICE CONFIGURABLE
    TString lumi_13TeV = "20.1 fb^{-1}";
    TString lumi_8TeV = "18.9-19.7 fb^{-1}";
    TString lumi_7TeV = "0-4.9 fb^{-1}";

    lumiText +=lumi_8TeV;
    lumiText +=" (8 TeV) + ";
    lumiText +=lumi_7TeV;
    lumiText +=" (7 TeV)";



    bool outOfFrame = false;
    if (iPosX / 10 == 0) {
      outOfFrame = true;
    }
    int alignY_ = 3;
    int alignX_ = 2;
    if (iPosX / 10 == 0) alignX_ = 1;
    if (iPosX == 0) alignX_ = 1;
    if (iPosX == 0) alignY_ = 1;
    if (iPosX / 10 == 1) alignX_ = 1;
    if (iPosX / 10 == 2) alignX_ = 2;
    if (iPosX / 10 == 3) alignX_ = 3;
    if (iPosX == 0) relPosX = 0.14;
    int align_ = 10 * alignX_ + alignY_;

    float l = pad->GetLeftMargin();
    float t = pad->GetTopMargin();
    float r = pad->GetRightMargin();
    float b = pad->GetBottomMargin();

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

    float extraTextSize = extraOverCmsTextSize * cmsTextSize;
    float pad_ratio = (static_cast<float>(pad->GetWh()) * pad->GetAbsHNDC()) /
      (static_cast<float>(pad->GetWw()) * pad->GetAbsWNDC());
    if (pad_ratio < 1.) pad_ratio = 1.;

    latex.SetTextFont(42);
    latex.SetTextAlign(31); 
    latex.SetTextSize(lumiTextSize*t*pad_ratio);    
    latex.DrawLatex(1-r,1-t+lumiTextOffset*t,lumiText);

    if (outOfFrame) {
      latex.SetTextFont(cmsTextFont);
      latex.SetTextAlign(11);
      latex.SetTextSize(cmsTextSize * t * pad_ratio);
      latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText);
    }


    float posX_ = 0;
    if (iPosX % 10 <= 1) {
      posX_ = l + relPosX * (1 - l - r);
    } else if (iPosX % 10 == 2) {
      posX_ = l + 0.5 * (1 - l - r);
    } else if (iPosX % 10 == 3) {
      posX_ = 1 - r - relPosX * (1 - l - r);
    }
    float posY_ = 1 - t - relPosY * (1 - t - b);
    if (!outOfFrame) {
      latex.SetTextFont(cmsTextFont);
      latex.SetTextSize(cmsTextSize * t * pad_ratio);
      latex.SetTextAlign(align_);
      latex.DrawLatex(posX_, posY_, cmsText);
      if (writeExtraText) {
	latex.SetTextFont(extraTextFont);
	latex.SetTextAlign(align_);
	latex.SetTextSize(extraTextSize * t * pad_ratio);
	latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText);
      }
    } else if (writeExtraText) {
      if (iPosX == 0) {
	posX_ = l + relPosX * (1 - l - r);
	posY_ = 1 - t + lumiTextOffset * t;
      }
      latex.SetTextFont(extraTextFont);
      latex.SetTextSize(extraTextSize * t * pad_ratio);
      latex.SetTextAlign(align_);
      latex.DrawLatex(posX_, posY_, extraText);
    }
    pad_backup->cd();
  }
Example #9
0
void DMplot()
{

    TCanvas *canv = new TCanvas("canv", "limits canvas", 800., 680.);
	gStyle->SetCanvasDefH(600); //Height of canvas
	gStyle->SetCanvasDefW(640); //Width of canvas
	gStyle->SetCanvasDefX(0);   //POsition on screen
	gStyle->SetCanvasDefY(0);

	gStyle->SetPadLeftMargin(0.14);//0.16);
	gStyle->SetPadRightMargin(0.165);//0.02);
	gStyle->SetPadTopMargin(0.085);//0.02);
	gStyle->SetPadBottomMargin(0.12);//0.02);

	  // For g axis titles:
	gStyle->SetTitleColor(1, "XYZ");
	gStyle->SetTitleFont(42, "XYZ");
	gStyle->SetTitleSize(0.045, "Z");
	gStyle->SetTitleSize(0.055, "XY");
	gStyle->SetTitleXOffset(1.0);//0.9);
	gStyle->SetTitleYOffset(1.15); // => 1.15 if exponents

	// For g axis labels:
	gStyle->SetLabelColor(1, "XYZ");
	gStyle->SetLabelFont(42, "XYZ");
	gStyle->SetLabelOffset(0.007, "XYZ");
	gStyle->SetLabelSize(0.04, "XYZ");

	// Legends
	gStyle->SetLegendBorderSize(0);
	gStyle->SetLegendFillColor(kWhite);
	gStyle->SetLegendFont(42);
    TPad* t1d = new TPad();
    t1d = new TPad("t1d","t1d", 0.0, 0.0, 1.0, 1.0);
    t1d->Draw();
    t1d->SetTicky();
    t1d->SetTickx();
    t1d->SetRightMargin(0.03);
    t1d->cd();

    //t1d->SetGridx(1);
    //t1d->SetGridy(1);
    t1d->SetLogy();
    t1d->SetLogx();

    //double const fn = 0.629;//0.326;
    TGraph *h_scalar_min = MakeGraph(0,0.260);
    TGraph *h_scalar_lat = MakeGraph(0,0.326);
    TGraph *h_scalar_max = MakeGraph(0,0.629);
    TGraph *h_fermion_min = MakeGraph(1,0.260);
    TGraph *h_fermion_lat = MakeGraph(1,0.326);
    TGraph *h_fermion_max = MakeGraph(1,0.629);

//////////////////////////////////////////////////

    // Get LUX bound 
    //TGraph *z1 = new TGraph("LUX_90CL.dat","%lg %lg");
    //
    TFile *fi_LUX2015 = TFile::Open("LUX_latest_2015.root");
    TGraph *z12015 =(TGraph*) fi_LUX2015->Get("LUX_2015");
    //TFile *fi_LUX2016 = TFile::Open("LUX_latest_2016.root");
    //TGraph *z12016 =(TGraph*) fi_LUX2016->Get("LUX_2016");
    TFile *fi_LUX2016 = TFile::Open("LUX_2013_2014_2015_combined.root");
    TGraph *z12016 =(TGraph*) fi_LUX2016->Get("LUX_2013_2014_2015_combined");

    z12015->SetLineWidth(3);
    z12015->SetLineColor(kGreen+2);
//    z12015->SetLineStyle(2);
    z12016->SetLineWidth(3);
    //z12016->SetLineStyle(2);
    z12016->SetLineColor(kGreen+2);

//    TLegend *leg2 = new TLegend(0.65, 0.15, 0.93, 0.42);
    TLegend *leg2 = new TLegend(0.70, 0.15, 0.97, 0.42);
    leg2->SetFillColor(0);
    leg2->SetBorderSize(0);
    //leg2->AddEntry(z1,"LUX(90\%CL)","L");
//////////////////////////////////////////////////
//  CDMS/ CRESST TOO
    TFile *CDMS_2016f = TFile::Open("CDMS_2016.root");
    TGraph *SCDMS = (TGraph*)CDMS_2016f->Get("CDMS_2016");

    TFile *CRESST2_2016f = TFile::Open("CRESST_2.root");
    TGraph *CRESST2 = (TGraph*)CRESST2_2016f->Get("CRESST_2_2016");

    TFile *PANDAX_2016f = TFile::Open("PANDAX.root");
    TGraph *PANDAX = (TGraph*)PANDAX_2016f->Get("PANDAX");

    SCDMS->SetLineColor(kAzure+7); SCDMS->SetLineStyle(9); SCDMS->SetLineWidth(3);
    CRESST2->SetLineColor(kMagenta+2); CRESST2->SetLineStyle(7); CRESST2->SetLineWidth(3);
    PANDAX->SetLineColor(kMagenta+2); PANDAX->SetLineStyle(4); PANDAX->SetLineWidth(3);
	
//
//

    h_scalar_min->SetTitle("");
    h_scalar_min->SetMinimum(2.0e-47);
    h_scalar_min->SetMaximum(1.0e-39);
    //h_scalar_min->SetMinimum(0.6e-46);
    //h_scalar_min->SetMaximum(1.0e-42);
    h_scalar_min->SetLineColor(4);
    h_scalar_min->SetLineStyle(2);
    h_scalar_min->SetLineWidth(3);
    h_scalar_min->GetXaxis()->SetTitleOffset(1.03);
    h_scalar_min->GetXaxis()->SetTitle("DM mass [GeV]");
    h_scalar_min->GetYaxis()->SetTitle("DM-nucleon cross section [cm^{2}]");
    h_scalar_lat->SetLineColor(4);
    h_scalar_lat->SetLineStyle(1);
    h_scalar_lat->SetLineWidth(3);
    h_scalar_max->SetLineColor(4);
    h_scalar_max->SetLineStyle(2);
    h_scalar_max->SetLineWidth(3);


    h_fermion_min->SetLineColor(kRed);
    h_fermion_min->SetLineStyle(2);
    h_fermion_min->SetLineWidth(3);
    h_fermion_lat->SetLineColor(kRed);
    h_fermion_lat->SetLineStyle(1);
    h_fermion_lat->SetLineWidth(3);
    h_fermion_max->SetLineColor(kRed);
    h_fermion_max->SetLineStyle(2);
    h_fermion_max->SetLineWidth(3);


    //h_scalar_lat->SetFillStyle(3005);
    //h_scalar_lat->SetLineWidth(-402);

    h_scalar_min->Draw("AL");
    h_scalar_lat->Draw("L");
    h_scalar_max->Draw("L");

    h_fermion_min->Draw("L");
    h_fermion_lat->Draw("L");
    h_fermion_max->Draw("L");
    z12016->Draw("L");
    //z12015->Draw("L");
    //CRESST2->Draw("C");
    SCDMS->Draw("C");
    PANDAX->Draw("C");

    //leg2->Draw();
    TLatex *lat = new TLatex(); lat->SetTextSize(0.025);
    lat->SetTextFont(42);
    lat->SetTextColor(kGreen+2);
    lat->SetTextAngle(15);
    //lat->DrawLatex(130,z1->Eval(130)*1.5,"LUX #it{Phys. Rev. Lett.} #bf{116} (2016)");


    //lat->DrawLatex(130,z12015->Eval(130)*1.5,"LUX (2015)");
    lat->DrawLatex(130,z12016->Eval(130)*0.5,"LUX (2013+2014-16)");
    
    lat->SetTextColor(SCDMS->GetLineColor());
    lat->SetTextAngle(344);
    //lat->SetFillColor(kWhite);
    lat->DrawLatex(5,SCDMS->Eval(5)*1.5,"CDMSlite (2015)");
    
    lat->SetTextColor(kBlue);
    lat->SetTextAngle(330);
    lat->DrawLatex(13,h_scalar_lat->Eval(13)*1.5,"Scalar DM");

    lat->SetTextColor(kRed);
    lat->SetTextAngle(4);
    lat->DrawLatex(5,h_fermion_lat->Eval(5)*1.5,"Fermion DM");


    lat->SetTextColor(kMagenta+2);
    lat->SetTextAngle(15);
    lat->DrawLatex(130,PANDAX->Eval(130)*1.25,"PandaX-II (2016)");

	TLatex * tex = new TLatex();
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetLineWidth(2);
	tex->SetTextSize(0.04);
	tex->SetTextAlign(31);
	tex->DrawLatex(0.93,0.78,"4.9 fb^{-1} (7 TeV) + 19.7 fb^{-1} (8 TeV)");
	tex->DrawLatex(0.93,0.74,"+ 2.3 fb^{-1} (13 TeV)");
	//tex->SetTextAlign(11);
  	tex->SetTextFont(42);
	tex->SetTextSize(0.06);
        TLegend *legBOX; 
	if (isPrelim)	{
   		legBOX = new TLegend(0.16,0.83,0.38,0.89);
		legBOX->SetFillColor(kWhite);
		legBOX->SetLineWidth(0);
		legBOX->Draw();
		tex->DrawLatex(0.17, 0.84, "#bf{CMS} #it{Preliminary}");
	} else {
   		legBOX = new TLegend(0.16,0.83,0.28,0.89);
		legBOX->SetFillColor(kWhite);
		legBOX->SetLineWidth(0);
		//legBOX->Draw();
		tex->DrawLatex(0.93, 0.84, "#bf{CMS}");
	}
  tex->SetTextSize(0.045);
  tex->DrawLatex(0.93,0.68,Form("B(H #rightarrow inv.) < %.2f",BRinv));
  tex->DrawLatex(0.93,0.5,"90% CL limits");
  canv->SetTicky(1);
  canv->SetTickx(1);
  canv->SaveAs("limitsDM.pdf"); 

}
void getMCcorrectionfactors(TString func = "exp"){

  // some parameters
  bool sepLeg=true;
  bool grey=false;
  bool plotsepfit   =true;
  bool plotfiterrors=false;
  TString optD= plotsepfit ? "" : "0";
  double xmax=500;
  TString Txmax=getTStringFromDouble(xmax);

  // colors
  int color7=kRed-4;
  int color8=kBlue+2;
  int ljets7color=color7;//kRed;//kRed+1;
  int dilep7color=color7;//kOrange+7;
  int ljets8color=color8;//kBlue+2;//kBlue;
  int dilep8color=color8;//kGreen+2;//kAzure+6;
  int fit7color=color7;//kMagenta-4;
  int fit8color=color8;//kTeal+3;
  int colorband=kCyan-7;

  // ---
  //    canvas style 
  // ---
  TStyle myStyle("HHStyle","HHStyle");
  setHHStyle(myStyle);
  myStyle.SetErrorX(0.5);
  myStyle.cd();
  gROOT->SetStyle("HHStyle");
  gStyle->SetEndErrorSize(10);
  gStyle->SetOptFit(0);

  // ---
  //    collect all curves
  // ---
  // 7 TeV
  int NbinsLjets7=7;
  TGraphAsymmErrors* SFljets = new TGraphAsymmErrors(NbinsLjets7);
  int NbinsDilep7=5;
  TGraphAsymmErrors* SFdilep = new TGraphAsymmErrors(NbinsDilep7);
  //int Nbins7=NbinsLjets7+NbinsDilep7;
  TGraphAsymmErrors* SF7 = new TGraphAsymmErrors(0);
  // 8 TeV
  int NbinsLjets8=8;
  TGraphAsymmErrors* SFljets8 = new TGraphAsymmErrors(NbinsLjets8);
  int NbinsDilep8=5;
  TGraphAsymmErrors* SFdilep8 = new TGraphAsymmErrors(NbinsDilep8);
  //int Nbins8=NbinsLjets8+NbinsDilep8;
  TGraphAsymmErrors* SF8 = new TGraphAsymmErrors(0);
  // combined
  //int Nbins=NbinsLjets7+NbinsDilep7+NbinsLjets8+NbinsDilep8;
  TGraphAsymmErrors* SF = new TGraphAsymmErrors(0);
  // ---
  //    top Pt data / MC ratio
  // ---
  // a) l+jets 7TeV data points
  //           bin x(BCC)    data  / Madgraph         // BCCNNLO // BCC MG
  SFljets->SetPoint( 0, 28   , 0.004536 / 0.003806 ); //28       // 26.2
  SFljets->SetPoint( 1, 85.6 , 0.006658 / 0.006574 ); //85.6     // 88.8
  SFljets->SetPoint( 2, 125  , 0.004740 / 0.004740 ); //125      // 126.2
  SFljets->SetPoint( 3, 173.6, 0.002501 / 0.002748 ); //173.6    // 173.8
  SFljets->SetPoint( 4, 227.5, 0.001042 / 0.001195 ); //227.5    // 228.8
  SFljets->SetPoint( 5, 287.3, 0.000378 / 0.000454 ); //287.3    // 288.8
  SFljets->SetPoint( 6, 355.8, 0.000120 / 0.000154 ); //355.8    // 356.2
  //                   x errors   rel.err(data) *( data  / Madgraph)
  SFljets->SetPointError( 0, 0., 0., (4.4 /100.)*(0.004536 / 0.003806), (4.4 /100.)*(0.004536 / 0.003806) );
  SFljets->SetPointError( 1, 0., 0., (5.5 /100.)*(0.006658 / 0.006574), (5.5 /100.)*(0.006658 / 0.006574) );
  SFljets->SetPointError( 2, 0., 0., (4.0 /100.)*(0.004740 / 0.004740), (4.0 /100.)*(0.004740 / 0.004740) );
  SFljets->SetPointError( 3, 0., 0., (5.8 /100.)*(0.002501 / 0.002748), (5.8 /100.)*(0.002501 / 0.002748) );
  SFljets->SetPointError( 4, 0., 0., (6.2 /100.)*(0.001042 / 0.001195), (6.2 /100.)*(0.001042 / 0.001195) );
  SFljets->SetPointError( 5, 0., 0., (9.0 /100.)*(0.000378 / 0.000454), (9.0 /100.)*(0.000378 / 0.000454) );
  SFljets->SetPointError( 6, 0., 0., (11.1/100.)*(0.000120 / 0.000154), (11.1/100.)*(0.000120 / 0.000154) );
  //style of ratio
  SFljets->SetLineWidth(3.);
  SFljets->SetMarkerSize(1.5);
  SFljets->SetMarkerStyle(26);
  SFljets->SetMarkerColor(ljets7color);
  SFljets->SetLineColor(ljets7color);

  // b) dilepton 7TeV data points
  //           bin x(BCC)    data  / Madgraph               // BCCNNLO // BCC MG
  SFdilep->SetPoint( 0, 33.7,  (0.00509572 / 0.00453114 )  );// 33.7    // 34 
  SFdilep->SetPoint( 1, 107 ,  (0.00626002 / 0.00600115 )  );// 106     // 107
  SFdilep->SetPoint( 2, 162 ,  (0.00296467 / 0.00321705 )  );// 162     // 163
  SFdilep->SetPoint( 3, 242 ,  (0.000701592/ 0.000931674)  );// 242     // 247
  SFdilep->SetPoint( 4, 343 ,  (0.00012036 / 0.000191065)  );// 343     // 350
  //                   x errors   rel.err(data) *( data  / Madgraph)
  SFdilep->SetPointError( 0, 0., 0., 0.0601381*(0.00509572 / 0.00453114 ), 0.0601381*(0.00509572 / 0.00453114 ) );
  SFdilep->SetPointError( 1, 0., 0., 0.0469906*(0.00626002 / 0.00600115 ), 0.0469906*(0.00626002 / 0.00600115 ) );
  SFdilep->SetPointError( 2, 0., 0., 0.0555114*(0.00296467 / 0.00321705 ), 0.0555114*(0.00296467 / 0.00321705 ) );
  SFdilep->SetPointError( 3, 0., 0., 0.071274* (0.000701592/ 0.000931674), 0.071274* (0.000701592/ 0.000931674) );
  SFdilep->SetPointError( 4, 0., 0., 0.0924826*(0.00012036 / 0.000191065), 0.0924826*(0.00012036 / 0.000191065) );
  //style of ratio
  SFdilep->SetLineWidth(3.);
  SFdilep->SetMarkerSize(1.5);
  SFdilep->SetMarkerStyle(22);
  SFdilep->SetMarkerColor(dilep7color);
  SFdilep->SetLineColor(dilep7color);

  // collect 8 TeV BCC x values for analysis binning
  std::vector<double> xBCCljets_;
  xBCCljets_.push_back( 28  );   //   0.0 ..  60.0
  xBCCljets_.push_back( 86  );   //  60.0 .. 100.0
  xBCCljets_.push_back(125  );   // 100.0 .. 150.0
  xBCCljets_.push_back(173  );   // 150.0 .. 200.0
  xBCCljets_.push_back(227.3);   // 200.0 .. 260.0
  xBCCljets_.push_back(288  );   // 260.0 .. 320.0
  xBCCljets_.push_back(356  );   // 320.0 .. 400.0
  xBCCljets_.push_back(444  );   // 400.0 .. 500.0
  std::vector<double> xBCCdilep_;
  xBCCdilep_.push_back( 29.7);  //   0.0 ..  65.0
  xBCCdilep_.push_back( 99.6);  //  65.0 .. 125.0
  xBCCdilep_.push_back(159.7);  // 125.0 .. 200.0
  xBCCdilep_.push_back(239.1);  // 200.0 .. 290.0
  xBCCdilep_.push_back(336.2);  // 290.0 .. 400.0

  // c) l+jets 8TeV data points
  for(int p=0; p<NbinsLjets8; ++p){
    // get line with all informations
    TString line= readLineFromFile(p+1, groupSpace+"CommonFiles/topPtInputForReweighting/diffXSecTopSemiLepPartontopPt.txt");
    // data value
    TString temp = getStringEntry(line, 3 , "&");
    temp.ReplaceAll(" ","");
    double data=atof(temp.Data());
    temp = getStringEntry(line, 2 , "&");
    temp.ReplaceAll(" ","");
    double MC  =atof(temp.Data());
    SFljets8->SetPoint( p,  xBCCljets_.at(p) , data/MC ); 
    temp = getStringEntry(line, 6 , "&");
    double unc=atof(temp.Data());
    SFljets8->SetPointError( p, 0., 0., (unc/100.)*(data/MC), (unc /100.)*(data/MC) );
  }
  whipEmptyBinsAway(SFljets8, 0);

  //style of ratio
  SFljets8->SetLineWidth(3.);
  SFljets8->SetMarkerSize(1.5);
  SFljets8->SetMarkerStyle(24);
  //SFljets8->SetLineStyle(2);
  SFljets8->SetMarkerColor(ljets8color);
  SFljets8->SetLineColor(ljets8color);

  // d) dilepton 8TeV data points
  // MC prediction point (as not in provided table)
  std::vector<double> MCdilep_;
  MCdilep_.push_back(0.00396076 ); 
  MCdilep_.push_back(0.00620269 ); 
  MCdilep_.push_back(0.00336987 ); 
  MCdilep_.push_back(0.00102834 ); 
  MCdilep_.push_back(0.000228163); 
  for(int p=0; p<NbinsDilep8; ++p){
    // get line with all informations
    TString line= readLineFromFile(p+4, groupSpace+"CommonFiles/topPtInputForReweighting/HypToppTLaTeX.txt");
    // data value
    TString temp = getStringEntry(line, 3 , "&");
    temp.ReplaceAll(" ","");
    double data=atof(temp.Data());
    //temp = getStringEntry(line, 2 , "&");
    //temp.ReplaceAll(" ","");
    double MC  =MCdilep_[p];
    SFdilep8->SetPoint( p,  xBCCdilep_.at(p) , data/MC ); 
    temp = getStringEntry(line, 6 , "&");
    double unc=atof(temp.Data());
    SFdilep8->SetPointError( p, 0., 0., (unc/100.)*(data/MC), (unc /100.)*(data/MC) );
  }

  //style of ratio
  SFdilep8->SetLineWidth(3.);
  SFdilep8->SetMarkerSize(1.5);
  SFdilep8->SetMarkerStyle(20);
  SFdilep8->SetMarkerColor(dilep8color);
  SFdilep8->SetLineColor(dilep8color);

  // e) combined 7 TeV data points
  addTAE(SFdilep , SF7);
  addTAE(SFljets , SF7);
  //style of ratio
  SF7->SetLineWidth(3.);
  SF7->SetMarkerSize(0.1);
  SF7->SetMarkerStyle(20);
  SF7->SetMarkerColor(kWhite);
  SF7->SetLineColor(kWhite);

  // f) combined 8 TeV data points
  addTAE(SFdilep8, SF8);
  addTAE(SFljets8, SF8);
  //style of ratio
  SF8->SetLineWidth(3.);
  SF8->SetMarkerSize(0.1);
  SF8->SetMarkerStyle(20);
  SF8->SetMarkerColor(kWhite);
  SF8->SetLineColor(kWhite);

  // g) combined 7+8TeV data points
  addTAE(SF7, SF);
  addTAE(SF8, SF);
  //style of ratio
  SF->SetLineWidth(3.);
  SF->SetMarkerSize(0.1);
  SF->SetMarkerStyle(20);
  SF->SetMarkerColor(kWhite);
  SF->SetLineColor(kWhite);

  // ---
  //    dummy plots for axis
  // ---
  TH1F* dummy= new TH1F("","",1,0.,xmax);
  histogramStyle(*dummy, kSig);
  dummy->GetXaxis()->SetTitle("p_{T}^{t} [GeV]");
  dummy->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dp_{T}^{t}} Ratio: (Data / Simulation)");
  dummy->GetYaxis()->SetTitleOffset(0.9*dummy->GetYaxis()->GetTitleOffset());
  dummy->SetMaximum(sepLeg? 1.3 : 1.8);
  dummy->SetMinimum(0.5);

  // ---
  //    legends
  // ---
  double x1=sepLeg ? 0.1 : 0.29;
  double x2=sepLeg ? 0.9 : 0.86;

  TLegend *leg0 = new TLegend(x1, sepLeg ? 0.65 : 0.69, x2, sepLeg? 0.92 : 0.87);
  leg0->SetFillStyle(0);
  leg0->SetTextSize(0.035);
  leg0->SetBorderSize(0);
  leg0->SetHeader("#font[22]{Data / MadGraph+PYTHIA(CTEQ6L1)}");

  TLegend *leg1 = new TLegend(x1, sepLeg ? 0.3 : 0.57, x2, sepLeg ? 0.55 : 0.69);
  leg1->SetFillStyle(0);
  leg1->SetTextSize(0.035);
  leg1->SetBorderSize(0);
  leg1->SetHeader("#font[22]{Fit: exp(a+b#upointx)}");

  if(plotsepfit) leg1->SetY1(leg1->GetY1()-0.2);

  // canvas
  std::vector<TCanvas*> plotCanvas_;
  addCanvas(plotCanvas_);
  plotCanvas_[plotCanvas_.size()-1]->cd(0);
  plotCanvas_[plotCanvas_.size()-1]->SetTitle("data/MC top Pt ratio");
  // drawing
  dummy->Draw("axis");
  SF->Draw("p e1 same");
  SF7->Draw("p e1 same");
  SF8->Draw("p e1 same");
  SFljets->Draw("p e1 same");
  SFdilep->Draw("p e1 same");
  SFljets8->Draw("p e1 same");
  SFdilep8->Draw("p e1 same");
  // fit polynomial or exponential function
  TString def = "";
  if(func=="pol2")def="[0]*x*x+[1]*x+[2]";
  if(func=="exp" )def="exp([0]+[1]*x)";
  double fitLowEdge=0.;
  double fitHighEdge=xmax;
  // a) to all 8 and 7 TeV points
//   TF1* function=new TF1("function",def,fitLowEdge, fitHighEdge);
//   function->SetLineColor(kMagenta+2);
//   SF->Fit(function,"R","same",fitLowEdge, fitHighEdge);
//   for(int i=0; i<function->GetNumberFreeParameters(); i++){
//     function->SetParameter(i,round(function->GetParameter(i),3));
//   }
//   TString fitEntry="#splitline{}{#splitline{}{#splitline{}{#splitline{combined fit: ";
//   fitEntry+=function->GetExpFormula("p")+",}{                          #chi^{2}/ndof=";
//   fitEntry+=getTStringFromDouble(function->GetChisquare())+"/"+getTStringFromInt(function->GetNDF())+"}}}}";
//   fitEntry.ReplaceAll("+(","");
//   fitEntry.ReplaceAll("))",")");
//   leg0->AddEntry( function, fitEntry, "L");
  // b) to all 7 TeV points
  TF1* function7=new TF1("function7",def,fitLowEdge, fitHighEdge);
  function7->SetLineColor(fit7color);
  function7->SetLineWidth(6);
  function7->SetLineStyle(2);
  SF7->Fit(function7,"R","same",fitLowEdge, fitHighEdge);
  for(int i=0; i<function7->GetNumberFreeParameters(); i++){
    function7->SetParameter(i,round(function7->GetParameter(i),3));
  }
  //TString fitEntry7="fit 7 TeV: ";
  //fitEntry7+=function7->GetExpFormula("p");
  //fitEntry7+=",  #chi^{2}/ndof=";
  //fitEntry7+=getTStringFromDouble(function7->GetChisquare())+"/"+getTStringFromInt(function7->GetNDF());
  //fitEntry7.ReplaceAll("+(","");
  //fitEntry7.ReplaceAll("))",")");
  TString fitEntry7="7 TeV: ";
  if(plotfiterrors) fitEntry7+="              ";
  fitEntry7+="a=";
  fitEntry7+=getTStringFromDouble(function7->GetParameter(0), 3);
  if(plotfiterrors){
    fitEntry7+="#pm";
    fitEntry7+=getTStringFromDouble(function7->GetParError(0) , 3);
  }
  fitEntry7+=", b=";
  fitEntry7+=getTStringFromDouble(function7->GetParameter(1), 5);
  if(plotfiterrors){
    fitEntry7+="#pm";
    fitEntry7+=getTStringFromDouble(function7->GetParError(1) , 5);
  }

  // b1) to l+jets 7 TeV points
  TF1* functionljets7=new TF1("functionljets7",def,fitLowEdge, fitHighEdge);
  functionljets7->SetLineColor(kRed+1);
  functionljets7->SetLineWidth(2);
  SFljets->Fit(functionljets7,"R"+optD,"same",fitLowEdge, fitHighEdge);
  for(int i=0; i<functionljets7->GetNumberFreeParameters(); i++){
    functionljets7->SetParameter(i,round(functionljets7->GetParameter(i),3));
  }
  //TString fitEntryljets7="fit 7 TeV l+jets: ";
  //fitEntryljets7+=functionljets7->GetExpFormula("p");
  //fitEntryljets7+=",  #chi^{2}/ndof=";
  //fitEntryljets7+=getTStringFromDouble(functionljets7->GetChisquare())+"/"+getTStringFromInt(functionljets7->GetNDF());
  //fitEntryljets7.ReplaceAll("+(","");
  //fitEntryljets7.ReplaceAll("))",")");
  TString fitEntryljets7="7 TeV l+jets:     ";
  fitEntryljets7+="a=";
  fitEntryljets7+=getTStringFromDouble(functionljets7->GetParameter(0), 3);
  if(plotfiterrors){
    fitEntryljets7+="#pm";
    fitEntryljets7+=getTStringFromDouble(functionljets7->GetParError(0) , 3);
  }
  fitEntryljets7+=", b=";
  fitEntryljets7+=getTStringFromDouble(functionljets7->GetParameter(1), 5);
  if(plotfiterrors){
    fitEntryljets7+="#pm";
    fitEntryljets7+=getTStringFromDouble(functionljets7->GetParError(1) , 5);
  }

  // b2) to dilepton 7 TeV points
  TF1* functiondilep7=new TF1("functiondilep7",def,fitLowEdge, fitHighEdge);
  functiondilep7->SetLineColor(kOrange+7);
  functiondilep7->SetLineWidth(2);
  SFdilep->Fit(functiondilep7,"R"+optD,"same",fitLowEdge, fitHighEdge);
  for(int i=0; i<functiondilep7->GetNumberFreeParameters(); i++){
    functiondilep7->SetParameter(i,round(functiondilep7->GetParameter(i),3));
  }
  //TString fitEntrydilep7="fit 7 TeV dilepton: ";
  //fitEntrydilep7+=functiondilep7->GetExpFormula("p");
  //fitEntrydilep7+=",  #chi^{2}/ndof=";
  //fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetChisquare())+"/"+getTStringFromInt(functiondilep7->GetNDF());
  //fitEntrydilep7.ReplaceAll("+(","");
  //fitEntrydilep7.ReplaceAll("))",")");
  TString fitEntrydilep7="7 TeV dilepton: ";
  fitEntrydilep7+="a=";
  fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetParameter(0), 3);
  if(plotfiterrors){
    fitEntrydilep7+="#pm";
    fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetParError(0) , 3);
  }
  fitEntrydilep7+=", b=";
  if(plotfiterrors){
    fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetParameter(1), 5);
    fitEntrydilep7+="#pm";
  }
  fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetParError(1) , 5);

  // c) to all 8 TeV points
  TF1* function8=new TF1("function8",def,fitLowEdge, fitHighEdge);
  function8->SetLineWidth(6);
  function8->SetLineColor(fit8color);
  function8->SetLineStyle(2);
  SF8->Fit(function8,"R","same",fitLowEdge, fitHighEdge);
  for(int i=0; i<function8->GetNumberFreeParameters(); i++){
    function8->SetParameter(i,round(function8->GetParameter(i),3));
  }
  //TString fitEntry8="fit 8 TeV: ";
  //fitEntry8+=function8->GetExpFormula("p");
  //fitEntry8+=",  #chi^{2}/ndof=";
  //fitEntry8+=getTStringFromDouble(function8->GetChisquare())+"/"+getTStringFromInt(function8->GetNDF());
  //fitEntry8.ReplaceAll("+(","");
  //fitEntry8.ReplaceAll("))",")");
  TString fitEntry8="8 TeV: ";
  if(plotfiterrors) fitEntry8+="              ";
  fitEntry8+="a=";
  fitEntry8+=getTStringFromDouble(function8->GetParameter(0), 3);
  if(plotfiterrors){
    fitEntry8+="#pm";
    fitEntry8+=getTStringFromDouble(function8->GetParError(0) , 3);
  }
  fitEntry8+=", b=";
  fitEntry8+=getTStringFromDouble(function8->GetParameter(1), 5);
  if(plotfiterrors){
    fitEntry8+="#pm";
    fitEntry8+=getTStringFromDouble(function8->GetParError(1) , 5);
  }

  // c1) to l+jets 8 TeV points
  TF1* functionljets8=new TF1("functionljets8",def,fitLowEdge, fitHighEdge);
  functionljets8->SetLineColor(kBlue);
  functionljets8->SetLineWidth(2);
  SFljets8->Fit(functionljets8,"R"+optD,"same",fitLowEdge, fitHighEdge);
  for(int i=0; i<functionljets8->GetNumberFreeParameters(); i++){
    functionljets8->SetParameter(i,round(functionljets8->GetParameter(i),3));
  }
  //TString fitEntryljets8="fit 8 TeV l+jets: ";
  //fitEntryljets8+=functionljets8->GetExpFormula("p");
  //fitEntryljets8+=",  #chi^{2}/ndof=";
  //fitEntryljets8+=getTStringFromDouble(functionljets8->GetChisquare())+"/"+getTStringFromInt(functionljets8->GetNDF());
  //fitEntryljets8.ReplaceAll("+(","");
  //fitEntryljets8.ReplaceAll("))",")");
  TString fitEntryljets8="8 TeV l+jets:     ";
  fitEntryljets8+="a=";
  fitEntryljets8+=getTStringFromDouble(functionljets8->GetParameter(0), 3);
  if(plotfiterrors){
    fitEntryljets8+="#pm";
    fitEntryljets8+=getTStringFromDouble(functionljets8->GetParError(0) , 3);
  }
  fitEntryljets8+=", b=";
  fitEntryljets8+=getTStringFromDouble(functionljets8->GetParameter(1), 5);
  if(plotfiterrors){
    fitEntryljets8+="#pm";
    fitEntryljets8+=getTStringFromDouble(functionljets8->GetParError(1) , 5);
  }

  // c2) to dilepton 8 TeV points
  TF1* functiondilep8=new TF1("functiondilep8",def,fitLowEdge, fitHighEdge);
  functiondilep8->SetLineColor(kAzure+6);
  functiondilep8->SetLineWidth(2);
  
  SFdilep8->Fit(functiondilep8,"R"+optD,"same",fitLowEdge, fitHighEdge);
  for(int i=0; i<functiondilep8->GetNumberFreeParameters(); i++){
    functiondilep8->SetParameter(i,round(functiondilep8->GetParameter(i),3));
  }
  //TString fitEntrydilep8="fit 8 TeV dilepton: ";
  //fitEntrydilep8+=functiondilep8->GetExpFormula("p");
  //fitEntrydilep8+=",  #chi^{2}/ndof=";
  //fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetChisquare())+"/"+getTStringFromInt(functiondilep8->GetNDF());
  //fitEntrydilep8.ReplaceAll("+(","");
  //fitEntrydilep8.ReplaceAll("))",")");
  TString fitEntrydilep8="8 TeV dilepton: ";
  fitEntrydilep8+="a=";
  fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetParameter(0), 3);
  if(plotfiterrors){
    fitEntrydilep8+="#pm";
    fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetParError(0) , 3);
  }
  fitEntrydilep8+=", b=";
  fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetParameter(1), 5);
  if(plotfiterrors){
    fitEntrydilep8+="#pm";
    fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetParError(1) , 5);
  }

  // Draw legend
  leg0->AddEntry(SFljets, "7 TeV e/#mu+jets  (TOP-11-013)"   , "P");
  leg0->AddEntry(SFdilep, "7 TeV ee/e#mu/#mu#mu (TOP-11-013)", "P");
  leg0->AddEntry(SFljets8,"8 TeV e/#mu+jets  (TOP-12-028)"   , "P");
  leg0->AddEntry(SFdilep8,"8 TeV ee/e#mu/#mu#mu (TOP-12-028)", "P");
  if(!sepLeg) leg0->Draw("same");
  leg1->AddEntry( function7, fitEntry7, "L");
  if(plotsepfit) leg1->AddEntry( functiondilep7, fitEntrydilep7, "L");
  if(plotsepfit) leg1->AddEntry( functionljets7, fitEntryljets7, "L");
  leg1->AddEntry( function8, fitEntry8, "L");
  if(plotsepfit) leg1->AddEntry( functiondilep8, fitEntrydilep8, "L");
  if(plotsepfit) leg1->AddEntry( functionljets8, fitEntryljets8, "L");
  if(!sepLeg) leg1->Draw("same");
  // Draw cms label
  TPaveText *label = new TPaveText();
  label -> SetX1NDC(gStyle->GetPadLeftMargin());
  label -> SetY1NDC(1.0-gStyle->GetPadTopMargin());
  label -> SetX2NDC(1.0-gStyle->GetPadRightMargin());
  label -> SetY2NDC(1.0);
  label -> SetTextFont(42);
  TString CMSlab="";
  if(!PHD) CMSlab+="CMS Preliminary, ";  
  CMSlab+="5.0/19.7 fb^{-1} at #sqrt{s} = 7/8 TeV";
  label -> AddText(CMSlab);
  label->SetFillStyle(0);
  label->SetBorderSize(0);
  label->SetTextSize(0.04);
  label->SetTextAlign(32);
  label-> Draw("same");
  // BCC label
  double positionX=xmax+0.045*xmax*(gStyle->GetCanvasDefW()/600.);
  double positionY=0.5;
  TLatex *bcclabel = new TLatex(positionX,positionY, " (horizontal BCC wrt. NNLO^{approx}, arXiv:1205.3453)");
  bcclabel->SetTextAlign(11);
  bcclabel->SetTextAngle(90);
  bcclabel->SetTextSize(0.035);
  bcclabel->Draw("same");
  if(grey) plotCanvas_[0]->SetGrayscale();
  //saving
  plotCanvas_[0]->Print("diffXSecFromSignal/plots/combined/2012/xSec/dataVsMadgraph7and8TeV.eps");
  plotCanvas_[0]->Print("diffXSecFromSignal/plots/combined/2012/xSec/dataVsMadgraph7and8TeV.png");

  // ---
  // ERROR band plot
  // ---
  addCanvas(plotCanvas_);
  plotCanvas_[plotCanvas_.size()-1]->cd(0);
  plotCanvas_[plotCanvas_.size()-1]->SetTitle("data/MC top Pt errorband");
  // drawing
  dummy->GetYaxis()->SetTitle("(Data / Simulation) SF (#sqrt{s}=8 TeV)");
  dummy->GetYaxis()->SetRangeUser(0.35, 1.65);
  dummy->SetFillColor(10);
  dummy->SetLineColor(10);
  dummy->Draw("axis");
  // extract parameters
  double a=function8->GetParameter(0);
  double b=function8->GetParameter(1);
  // turning point
  double min=0;
  double max=500;
  double TP=-a/b;
  // get functions for high, low and central
  TF1* centralErr=new TF1("centralErr",def,min, max);
  centralErr->SetParameter(0, a);
  centralErr->SetParameter(1, b);
  TF1* upErr=new TF1("upErr",def,min, max);
  upErr->SetParameter(0, 2*a);
  upErr->SetParameter(1, 2*b);
  TF1* dnErr=new TF1("upErr",def,min, max);
  dnErr->SetParameter(0, 0.);
  dnErr->SetParameter(1, 0.);
  // draw errorbands
  upErr->SetFillStyle(1001);
  dnErr->SetFillStyle(1001);
  upErr->SetLineColor(10);
  dnErr->SetLineColor(10);
  upErr->SetFillColor(colorband);
  upErr->SetRange(min,TP);
  upErr->DrawClone("hist same");
  dnErr->SetFillColor(10);
  dnErr->SetLineColor(10);
  dnErr->SetRange(min,TP);
  dnErr->DrawClone("hist same");
  dnErr->SetFillColor(colorband);
  dnErr->SetLineColor(colorband);
  dnErr->SetRange(TP, max);
  dnErr->DrawClone("hist same");
  upErr->SetFillColor(10);
  upErr->SetLineColor(10);
  upErr->SetRange(TP, max);
  upErr->DrawClone("hist same");
  drawLine(TP, 0.35, TP, 1.05, 10, 2, 1);
  // draw central prediction
  centralErr->SetFillStyle(0);
  centralErr->SetFillColor(0);
  centralErr->SetLineColor(kBlue);
  centralErr->SetLineWidth(6);
  centralErr->SetLineColor(fit8color);
  centralErr->SetLineStyle(2);
  centralErr->Draw("hist same");
  // legend and labels
  dummy->Draw("axis same");
  TPaveText *label2 = new TPaveText();
  label2 -> SetX1NDC(gStyle->GetPadLeftMargin());
  label2 -> SetY1NDC(1.0-gStyle->GetPadTopMargin());
  label2 -> SetX2NDC(1.0-gStyle->GetPadRightMargin());
  label2 -> SetY2NDC(1.0);
  label2 -> SetTextFont(42);
  TString CMSlab2="";
  if(!PHD) CMSlab2+="CMS Preliminary, ";  
  CMSlab2+="19.7 fb^{-1} at #sqrt{s} = 8 TeV";
  label2->AddText(CMSlab2);
  label2->SetFillStyle(0);
  label2->SetBorderSize(0);
  label2->SetTextSize(0.04);
  label2->SetTextAlign(32);  
  double x12= 0.29;
  double x22= 0.86;
  label2->Draw("same");
  TLegend *leg3 = new TLegend(x12+0.05, 0.7, x22+0.05, 0.85);
  leg3->SetFillStyle(0);
  leg3->SetTextSize(0.035);
  leg3->SetBorderSize(0);
  leg3->SetHeader("#font[22]{Parametrisation: exp(a+b#upointx)}");
  TString entryErr=fitEntry8;
  entryErr.ReplaceAll("8 TeV: ", "");
  leg3->AddEntry(centralErr, entryErr , "L");
  leg3->AddEntry(dnErr     , "a,b #pm 100%", "F");
  leg3->Draw("same");
  //saving
  if(grey) plotCanvas_[1]->SetGrayscale();
  plotCanvas_[1]->Print("diffXSecFromSignal/plots/combined/2012/xSec/topPtReweighting8TeVunc.eps");
  plotCanvas_[1]->Print("diffXSecFromSignal/plots/combined/2012/xSec/topPtReweighting8TeVunc.png");
  
  // ratio legend
  if(sepLeg){
    addCanvas(plotCanvas_);
    plotCanvas_[plotCanvas_.size()-1]->cd(0);
    plotCanvas_[plotCanvas_.size()-1]->SetTitle("legend");
    leg0->Draw("same");
    leg1->Draw("same");
    if(grey) plotCanvas_[2]->SetGrayscale();
    plotCanvas_[2]->Print("diffXSecFromSignal/plots/combined/2012/xSec/topPtReweightingLegend.eps");
    plotCanvas_[2]->Print("diffXSecFromSignal/plots/combined/2012/xSec/topPtReweightingLegend.png");
  }
}
Example #11
0
void
CalcFakeRate(string infile, bool useData=true, bool doSystematics=false){  
  cout<<" UseData="<<useData<<" dosystematics="<<doSystematics<<endl;

  TFile *f = TFile::Open(infile.c_str(), "read"); assert(f);
  TH2F* hFakeRateNum = NULL;
  TH2F* hFakeRateAll = NULL;
  gStyle->SetOptStat(0);
  gStyle->SetPalette(1);
  gStyle->SetTextFont(132);
  gStyle->SetTextSize(1.2);
  //gROOT->ForceStyle();

  bool useElectrons = infile.find("Muon") == string::npos;
  bool doWLep = infile.find("-TT") == string::npos;

  vector<string> allsamples;
  if(!useData){
    allsamples.push_back("WJetsToLNu");
    if(!doSystematics){
    allsamples.push_back("TTJets");
    allsamples.push_back("ZZ");
    allsamples.push_back("GVJets");
    allsamples.push_back("WWTo2L2Nu");
    allsamples.push_back("WZJetsTo3LNu");
    allsamples.push_back("DYJetsToLL");
    }
  }else{
    allsamples.push_back("data");
  }
  
  float offset = 0.01;
  float eta[] = {0., 1.5, 2.5}; int neta = 3;
  if(!useElectrons){
    eta[1] = 2.4;
    neta = 2;//eta[2] = 2.4;
  }

  //float pt [] = {0., 20., 40., 1000}; const int npt  = 4;
  //float pt [] = {0., 10., 20., 30., 1000}; const int npt  = 5;

  //float pt [] = {0., 10., 15., 25., 1000}; const int npt  = 5;
  //float pt [] = {0., 10., 15., 20., 30., 1000}; const int npt  = 6;
  float pt [] = {10., 15., 20., 30., 40., 100}; const int npt  = 6;

  //float pt [] = {0., 20., 25., 30., 50., 1000}; const int npt  = 6;
  hFakeRateNum = new TH2F("hFakeRateNum", "hFakeRateNum;p_{T} (GeV);#eta", npt-1, pt, neta-1, eta);
  hFakeRateAll = new TH2F("hFakeRateAll", "hFakeRateAll;p_{T} (GeV);#eta", npt-1, pt, neta-1, eta);
  string title = useElectrons ? "Electron Fake Rate" : "Muon Fake Rate";
  title += useData ? " from Data" : " from MC";
  title += !useData && doSystematics ? " Systematics" : "";
  title += " using W+Jets method";
  title += doWLep ? " on W lepton" : " on Z lepton";
  hFakeRateNum->SetTitle(title.c_str());

/////////This is for eta, pt agnotistic Fake Rate Calc
  float in_tot(0), out_tot(0);
  for(unsigned i=0; i<allsamples.size(); ++i){
    string hist_name = allsamples[i] + "/hNumEvts";
    TH1F* hist = (TH1F*) f->Get(hist_name.c_str()); assert(hist);
    int lastbin = hist->GetNbinsX();
    float in(0), out(0);

    in  = hist->GetBinContent(lastbin);
    out = hist->GetBinContent(lastbin-1);

    in_tot += in;
    out_tot += out;

    //cout<<"Sample: "<<allsamples[i]<<" = "<<in/out<<" = pass/total = "<<in<<"/"<<out<<endl;
    printf("  Sample: %s = %.2f%% : pass/total = %.2f / %.2f \n",allsamples[i].c_str(), in/out*100, in, out);
  }
  float  eff = in_tot/out_tot;
  float deff = TMath::Sqrt(eff * (1-eff)/out_tot);
  //cout<<"Total: "<<eff*100<<"% +/- "<<deff*100<<"% = in_tot/out_tot*100% = "<<in_tot<<"/"<<out_tot<<"*100%\n";
  printf("Total: %.2f%% +/- %.2f%% = in_tot/out_tot*100%% = %.2f/%.2f\n", eff*100, deff*100, in_tot, out_tot);


/////////This is for 2D Fake Rate Calc
  for(unsigned i=0; i<allsamples.size(); ++i){
    string hist_name = allsamples[i] + "/hNumEvts";
    TH1F* hist = (TH1F*) f->Get(hist_name.c_str()); assert(hist);
    int lastbin = hist->GetNbinsX();
    float in(0), out(0);
    string binNameNum   = hist->GetXaxis()->GetBinLabel(lastbin);
    string binNameDenom = hist->GetXaxis()->GetBinLabel(lastbin-1);
      
    string hist_nameNum = allsamples[i] + "/hEtaVsPt_" + binNameNum;
    TH2F* histNum = (TH2F*) f->Get(hist_nameNum.c_str()); assert(histNum);
      
    string hist_nameDenom = allsamples[i] + "/hEtaVsPt_" + binNameDenom;
    TH2F* histDenom = (TH2F*) f->Get(hist_nameDenom.c_str()); assert(histDenom);
/*
    cout<<" Total from 2D Plot is "<<histNum->Integral()<<" / "<<histDenom->Integral()<<endl; //By default, integral doesn't count over/underflow
    cout<<" Total from 2D Plot is "<<histNum->GetEntries()<<" / "<<histDenom->GetEntries()<<endl;

    float sUnder(0), sOver(0);
    for(int ybin = 0; ybin<= histDenom->GetYaxis()->GetNbins() + 1; ++ybin){
      for(int xbin = 0; xbin<= histDenom->GetXaxis()->GetNbins() +1; ++xbin){
        int bin = histDenom->GetBin(xbin, ybin);
        if(histDenom->IsBinOverflow(bin)) sOver += histDenom->GetBinContent(bin);
        if(histDenom->IsBinUnderflow(bin)) sUnder += histDenom->GetBinContent(bin);
      }
    }
    printf("Total overflow, underflow in denom histo is %.2f , %.2f\n", sOver, sUnder);
*/
    for(int ieta=0; ieta<neta-1; ++ieta){
      float ymin = eta[ieta]; 
      float ymax = eta[ieta+1]-offset;
      for(int ipt=0; ipt<npt-1; ++ipt){
        float xmin = pt[ipt]; 
        float xmax = pt[ipt+1];
          
        int xminbin,xmaxbin,yminbin,ymaxbin;
        xminbin = histNum->GetXaxis()->FindBin(xmin); //+ (ipt!=0);//Avoid overlap except for first bin
        xmaxbin = histNum->GetXaxis()->FindBin(xmax)-1 + (ipt == npt-1-1);
        yminbin = histNum->GetYaxis()->FindBin(ymin);
        ymaxbin = histNum->GetYaxis()->FindBin(ymax);
        
        /*
        cout<<"("<<pt[ipt]<<", "<<eta[ieta]<<")\t"
            <<xmin<<"-"<<xmax<<":"
            <<ymin<<"-"<<ymax<<":"
            <<"\t";
        cout<<"("<<ipt<<", "<<ieta<<")\t"
            <<xminbin<<"-"<<xmaxbin<<":"
            <<yminbin<<"-"<<ymaxbin
            <<endl;
        */      
        in  = histNum  ->Integral(xminbin, xmaxbin, yminbin, ymaxbin);
        out = histDenom->Integral(xminbin, xmaxbin, yminbin, ymaxbin);
          
        //Cory: Deal with negative eta (Y axis)
        yminbin = histNum->GetYaxis()->FindBin(-1*ymax);
        ymaxbin = histNum->GetYaxis()->FindBin(-1*ymin)-1;//avoid overlap
        /*
        cout<<"("<<pt[ipt]<<", "<<eta[ieta]<<")\t"
            <<xmin<<"-"<<xmax<<":"
            <<ymin<<"-"<<ymax<<":"
            <<"\t";
        cout<<"("<<ipt<<", "<<ieta<<")\t"
            <<xminbin<<"-"<<xmaxbin<<":"
            <<yminbin<<"-"<<ymaxbin
            <<endl;
        */
        in  += histNum  ->Integral(xminbin, xmaxbin, yminbin, ymaxbin);
        out += histDenom->Integral(xminbin, xmaxbin, yminbin, ymaxbin);

        //cout<<"("<<pt[ipt]<<","<<eta[ieta]<<") "<<in<<"/"<<out<<endl;
        //cout<<"("<<(pt[ipt]+pt[ipt+1])/2<<","<<(eta[ieta]+eta[ieta+1])/2<<") "<<in<<"/"<<out<<endl;
        hFakeRateNum   ->Fill( (pt[ipt]+pt[ipt+1])/2, (eta[ieta]+eta[ieta+1])/2, in);
        hFakeRateAll->Fill( (pt[ipt]+pt[ipt+1])/2, (eta[ieta]+eta[ieta+1])/2, out);

      }
    }

  }

  if(hFakeRateNum){
    //TGraphAsymmErrors* hFakeRateEff = new TGraphAsymmErrors(hFakeRateNum->GetArray(), hFakeRateAll->GetArray(), "");
    //TGraphAsymmErrors* hFakeRateEff = new TGraphAsymmErrors(hFakeRateNum, hFakeRateAll, "");
    TH2F* hFakeRate = (TH2F*) hFakeRateNum->Clone("hFakeRate");
    //hFakeRate->Divide(hFakeRateAll);
    //hFakeRate->Scale(100.); //make is a percent
    TCanvas c1;
    c1.SetLogx(1);


    //gStyle->SetTextFont(132);
    //gStyle->SetTextSize(1.2);
    hFakeRate->SetMarkerSize(3);
    //gStyle->SetPaintTextFormat("3.0f m");
    gStyle->SetPaintTextFormat("4.0f");
    hFakeRate->Draw("colz");

    TLatex latexLabel;
    latexLabel.SetNDC();
    latexLabel.SetTextSize(0.04);
    latexLabel.SetTextFont(42);
    latexLabel.SetTextAngle(90);
    latexLabel.SetTextAlign(22);
    for(int ybin = 1; ybin<= hFakeRate->GetYaxis()->GetNbins(); ++ybin){
      int nx = hFakeRate->GetXaxis()->GetNbins();
      TGraphAsymmErrors* gFakeRatePt = new TGraphAsymmErrors(nx);
      gFakeRatePt->SetMaximum(1.1);
      gFakeRatePt->SetMinimum(0.);
      gFakeRatePt->SetTitle((title + ";p_{T} (GeV);Rate").c_str());
      for(int xbin = nx; xbin >= 1; --xbin){
        float xcen = hFakeRate->GetXaxis()->GetBinCenter(xbin);
        float ycen = hFakeRate->GetYaxis()->GetBinCenter(ybin);
        
        double xpos, ypos;
        GetNDC(c1, xcen, ycen, xpos, ypos);
        int bin = hFakeRate->GetBin(xbin, ybin);
        float pass = hFakeRateNum->GetBinContent(bin);
        float tot  = hFakeRateAll->GetBinContent(bin);
        float mean    = tot>0 ? pass / tot : 0.;
        float errUp   = TEfficiency::ClopperPearson(tot, pass, 0.68, true) - mean;//hFakeRateEff->GetErrorYhigh(bin-1);
        float errDown = mean - TEfficiency::ClopperPearson(tot, pass, 0.68, false);//hFakeRateEff->GetErrorYlow(bin-1);
        errDown = max(errDown, (float) 0.);
        hFakeRate->SetBinContent(bin, mean);
        //hFakeRate->SetBinError(bin, err);
        float err = (errUp + errDown)/2;
        printf("if(pt > %.0f) return Value(%.4f, %.4f); //pt %3.0f eta %.1f, bin %2i, (mean, err)= (%.4f, %.4f) (%.2f / %.2f) +%.4f -%.4f\n", 
               hFakeRate->GetXaxis()->GetBinLowEdge(xbin), mean, err, 
               hFakeRate->GetXaxis()->GetBinLowEdge(xbin), hFakeRate->GetYaxis()->GetBinLowEdge(ybin), bin, mean, err, pass, tot, errUp, errDown);
        if(xbin != 1) latexLabel.DrawLatex(xpos, ypos, Form("%.0f^{+%.0f}_{-%.0f}%% (%.0f/%.0f)(%.f-%.f)GeV",mean*100, errUp*100, errDown*100, pass, tot, pt[xbin-1],pt[xbin]));
        

        gFakeRatePt->SetPoint      (xbin-1, xcen, mean);
        gFakeRatePt->SetPointEYhigh(xbin-1, errUp);
        gFakeRatePt->SetPointEYlow (xbin-1, errDown);
        gFakeRatePt->SetPointEXhigh(xbin-1, hFakeRate->GetXaxis()->GetBinLowEdge(xbin+1) - xcen);
        gFakeRatePt->SetPointEXlow (xbin-1, xcen - hFakeRate->GetXaxis()->GetBinLowEdge(xbin));

      }//pt loop
      c1.Clear();
      c1.SetLogx(1);
      //c1.SetGrid();
      gFakeRatePt->Draw("ap*");
      string outName = Form("WJetsFakeRatePt-Eta%.1fto%.1f-", hFakeRate->GetYaxis()->GetBinLowEdge(ybin), hFakeRate->GetYaxis()->GetBinLowEdge(ybin+1));
      replace(outName.begin(), outName.end(), '.', 'p');
      outName += useElectrons ? "Elec" : "Muon";
      outName += useData ? "Data" : "MC";
      outName += !useData && doSystematics ? "Sys" : "";
      outName += doWLep ? "WLep" : "ZLep";
      outName += ".pdf";
      c1.Print(outName.c_str());
      
    }//eta loop
    
    c1.Clear();
    c1.SetLogx(1);
    string outName = "FakeRate";
    outName += useElectrons ? "Elec" : "Muon";
    outName += useData ? "Data" : "MC";
    outName += !useData && doSystematics ? "Sys" : "";
    outName += doWLep ? "WLep" : "ZLep";
    outName += ".pdf";
    c1.Print(outName.c_str());

    //Now make profiles
    c1.Clear();
    c1.SetLogx(0);
    //c1.SetGrid();

    TH1D* hFakeRateNumEta = hFakeRateNum->ProjectionY("hFakeRateNumEta", 0, -1, "e");
    TH1D* hFakeRateAllEta = hFakeRateAll->ProjectionY("hFakeRateAllEta", 0, -1, "e");
    //TH1D* hFakeRateEta = (TH1D*) hFakeRateNumEta->Clone("hFakeRateEta");

    int n = hFakeRateAllEta->GetXaxis()->GetNbins();
    TGraphAsymmErrors* hFakeRateEta = new TGraphAsymmErrors(n);//hFakeRateNumEta, hFakeRateAllEta);
    hFakeRateEta->SetMaximum(1.);
    hFakeRateEta->SetMinimum(0.);
    hFakeRateEta->SetTitle((title + ";#eta;Rate").c_str());

    //hFakeRateEta->SetMarkerStyle(21);    
    for(int xbin = 1; xbin <= n; ++xbin){
      float x = hFakeRateAllEta->GetXaxis()->GetBinCenter(xbin);
      float pass = hFakeRateNumEta->GetBinContent(xbin);
      float tot  = hFakeRateAllEta->GetBinContent(xbin);
      float mean    = tot>0 ? pass / tot : 0.;
      float errUp   = TEfficiency::ClopperPearson(tot, pass, 0.68, true) - mean;//hFakeRateEff->GetErrorYhigh(bin-1);
      float errDown = mean - TEfficiency::ClopperPearson(tot, pass, 0.68, false);//hFakeRateEff->GetErrorYlow(bin-1);
      errDown = max(errDown, (float) 0.);
      hFakeRateEta->SetPoint      (xbin, x, mean);
      hFakeRateEta->SetPointEYhigh(xbin, errUp);
      hFakeRateEta->SetPointEYlow (xbin, errDown);
      //printf("bin: %i, x=%.0f, %.0f/%.0f = %.0f +%.0f -%.0f\n", xbin, x, pass, tot, mean*100, errUp*100, errDown*100);
    }
    
    //hFakeRateEta->Divide(hFakeRateAllEta);
    //hFakeRateEta->Scale(100.);
    hFakeRateEta->Draw("ap*");
    outName = "FakeRateEta";
    outName += useElectrons ? "Elec" : "Muon";
    outName += useData ? "Data" : "MC";
    outName += !useData && doSystematics ? "Sys" : "";
    outName += doWLep ? "WLep" : "ZLep";
    outName += ".pdf";
    c1.Print(outName.c_str());

    //Pt projections (split these by eta?)
    c1.Clear();
    c1.SetLogx(1);
    //c1.SetGrid();

    TH1D* hFakeRateNumPt = hFakeRateNum->ProjectionX("hFakeRateNumPt", 0, -1, "e");
    TH1D* hFakeRateAllPt = hFakeRateAll->ProjectionX("hFakeRateAllPt", 0, -1, "e");
    //TH1D* hFakeRatePt = (TH1D*) hFakeRateNumPt->Clone("hFakeRatePt");

    n = hFakeRateAllPt->GetXaxis()->GetNbins();
    TGraphAsymmErrors* hFakeRatePt = new TGraphAsymmErrors(n);//hFakeRateNumPt, hFakeRateAllPt);
    hFakeRatePt->SetMaximum(1.);
    hFakeRatePt->SetMinimum(0.);
    hFakeRatePt->SetTitle((title + ";p_{T} (GeV);Rate").c_str());

    for(int xbin = 1; xbin <= n; ++xbin){
      float x = hFakeRateAllPt->GetXaxis()->GetBinCenter(xbin);
      float pass = hFakeRateNumPt->GetBinContent(xbin);
      float tot  = hFakeRateAllPt->GetBinContent(xbin);
      float mean    = tot>0 ? pass / tot : 0.;
      float errUp   = TEfficiency::ClopperPearson(tot, pass, 0.68, true) - mean;//hFakeRateEff->GetErrorYhigh(bin-1);
      float errDown = mean - TEfficiency::ClopperPearson(tot, pass, 0.68, false);//hFakeRateEff->GetErrorYlow(bin-1);
      errDown = max(errDown, (float) 0.);
      hFakeRatePt->SetPoint      (xbin, x, mean);
      hFakeRatePt->SetPointEYhigh(xbin, errUp);
      hFakeRatePt->SetPointEYlow (xbin, errDown);
      //cout<<"low edge is "<<hFakeRateAllPt->GetXaxis()->GetBinLowEdge(xbin)<<" up edge is "
      //    <<hFakeRateAllPt->GetXaxis()->GetBinLowEdge(xbin+1)<<endl;
      hFakeRatePt->SetPointEXhigh(xbin, hFakeRateAllPt->GetXaxis()->GetBinLowEdge(xbin+1) - x);
      hFakeRatePt->SetPointEXlow (xbin, x - hFakeRateAllPt->GetXaxis()->GetBinLowEdge(xbin));
      printf("bin: %i, x=%.0f, %.0f/%.0f = %.0f +%.0f -%.0f\n", xbin, x, pass, tot, mean*100, errUp*100, errDown*100);
    }
    


    //hFakeRatePt->Divide(hFakeRateAllPt);
    //hFakeRatePt->Scale(100.);
    hFakeRatePt->Draw("ap*");
    outName = "FakeRatePt";
    outName += useElectrons ? "Elec" : "Muon";
    outName += useData ? "Data" : "MC";
    outName += !useData && doSystematics ? "Sys" : "";
    outName += doWLep ? "WLep" : "ZLep";
    outName += ".pdf";
    c1.Print(outName.c_str());

    
  }


}
Example #12
0
void CheckDataFakes(){
  
  TH1::SetDefaultSumw2(true);
  setTDRStyle();


  TH1F* data_presel_hist = new TH1F("mcclosure","mcclosure", 10,0.,10.);
  data_presel_hist->GetYaxis()->SetTitle("Event");
  data_presel_hist->GetYaxis()->SetRangeUser(0., 600.);
  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("Presel_fakeparam_40");
  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/REG1/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 ymax = 600.;
  
  for(unsigned int b = 1; b < data_presel_hist->GetNbinsX(); b++){
    //Bin dividers
    if( b < 4) ymax = 400.;
    else ymax = 600.;
    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("Presel_fakeparam_"+jetpt.at(j));
    TH1F* h_np_presel= (TH1F*)fnp->Get("Presel_fakeparam_"+jetpt.at(j));
    TH1F* h_cf_presel= (TH1F*)fcf->Get("Presel_fakeparam_"+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_looseregion1.pdf"));
    
}
void drawclosureffgamma(int phoetmin, int phoetmax) {
  const int yaxismax = 4;
  const int yaxismax2 = 3;
  TFile *_file0 = TFile::Open(Form("closure_%d_%d.root",phoetmin,phoetmax));
  int save = 1;
  const static int ncentbins = 5;
  float binwidth = 5.000000e-01;
  int centmins[] = {0,20,60,100,140};
  int centmaxs[] = {20,60,100,140,200};
  string cents[] = {"0-10%","10-30%","30-50%","50-70%","70-100%"};
  TCanvas * c1_pbpbmc_gen[ncentbins]; // ncentbins
  TH1D * hgammaffxi_pbpbmc_gen_[ncentbins];
  TH1D * hjetpt_pbpbmc_gen_[ncentbins];
  TH1D * hgammaffxi_refcone_pbpbmc_gen_[ncentbins];
  float njets_pbpbmc_gen[ncentbins];

  TCanvas * c1_pbpbmc[ncentbins];
  TH1D * hgammaffxi_pbpbmc_[ncentbins];
  TH1D * hjetpt_pbpbmc_[ncentbins];
  TH1D * hgammaffxi_refcone_pbpbmc_[ncentbins];
  float njets_pbpbmc[ncentbins];

  TCanvas * c1_subpbpb[ncentbins];
  TH2D * dummy_pbpbsub[ncentbins];
  TH2D * dummy2_pbpbsub[ncentbins];
  TH1D * clone_hgammaffxi_refcone_pbpbmc_gen_[ncentbins];
  TH1D * clone_hgammaffxi_pbpbmc_gen_[ncentbins];
  TH1D * clone_hgammaffxi_refcone_pbpbmc_[ncentbins];
  TH1D * clone_hgammaffxi_pbpbmc_[ncentbins];
  TH2D * clone2_hgammaffxi_pbpbmc_gen_[ncentbins];
  TH2D * clone2_hgammaffxi_pbpbmc_[ncentbins];
  TLegend * leg_ff_pbpbsub[ncentbins];
  TLegend * leg_ff_pbpbsub2[ncentbins];

  TCanvas * call = new TCanvas("call","",1600,500);
  // makeMultiPanelCanvas(call,5,1,0,0,0.2,0.2,0.04);
  makeMultiPanelCanvas(call,6,1,0.02,0.0,-6,0.2,0.04);
  for (int icent = 0; icent < 5; icent++) {
    // Raw FF pbpdata
    hgammaffxi_pbpbmc_gen_[icent] = (TH1D*) _file0->Get(Form("hgammaffxi_pbpbmc_gen_%d_%d",centmins[icent],centmaxs[icent]));
    hjetpt_pbpbmc_gen_[icent] = (TH1D*) _file0->Get(Form("hjetpt_pbpbmc_gen_%d_%d",centmins[icent],centmaxs[icent]));
    hgammaffxi_refcone_pbpbmc_gen_[icent] = (TH1D*) _file0->Get(Form("hgammaffxi_refcone_pbpbmc_gen_%d_%d",centmins[icent],centmaxs[icent]));
    njets_pbpbmc_gen[icent] = hjetpt_pbpbmc_gen_[icent]->Integral();
    hgammaffxi_pbpbmc_gen_[icent]->Sumw2();
    hgammaffxi_refcone_pbpbmc_gen_[icent]->Sumw2();
    hgammaffxi_pbpbmc_gen_[icent]->Scale(1.0/njets_pbpbmc_gen[icent]/binwidth);
    hgammaffxi_refcone_pbpbmc_gen_[icent]->Scale(1.0/njets_pbpbmc_gen[icent]/binwidth);
    // cout<<njets_pbpbmc_gen[icent]<<endl;
    hgammaffxi_pbpbmc_gen_[icent]->GetXaxis()->CenterTitle();
    hgammaffxi_pbpbmc_gen_[icent]->SetYTitle("dN/d#xi");
    hgammaffxi_pbpbmc_gen_[icent]->GetYaxis()->CenterTitle();
    hgammaffxi_refcone_pbpbmc_gen_[icent]->SetMarkerStyle(24);
    // Raw FF pbpdata


    // Raw FF pbmc
    hgammaffxi_pbpbmc_[icent] = (TH1D*) _file0->Get(Form("hgammaffxi_pbpbmc__%d_%d",centmins[icent],centmaxs[icent]));
    hjetpt_pbpbmc_[icent] = (TH1D*) _file0->Get(Form("hjetpt_pbpbmc__%d_%d",centmins[icent],centmaxs[icent]));
    hgammaffxi_refcone_pbpbmc_[icent] = (TH1D*) _file0->Get(Form("hgammaffxi_refcone_pbpbmc__%d_%d",centmins[icent],centmaxs[icent]));
    njets_pbpbmc[icent] = hjetpt_pbpbmc_[icent]->Integral();
    hgammaffxi_pbpbmc_[icent]->Sumw2();
    hgammaffxi_refcone_pbpbmc_[icent]->Sumw2();
    hgammaffxi_pbpbmc_[icent]->Scale(1.0/njets_pbpbmc[icent]/binwidth);
    hgammaffxi_refcone_pbpbmc_[icent]->Scale(1.0/njets_pbpbmc[icent]/binwidth);
    hgammaffxi_pbpbmc_[icent]->GetXaxis()->CenterTitle();
    hgammaffxi_pbpbmc_[icent]->SetYTitle("dN/d#xi");
    hgammaffxi_pbpbmc_[icent]->GetYaxis()->CenterTitle();
    hgammaffxi_refcone_pbpbmc_[icent]->SetMarkerStyle(24);
    // Raw FF pbpbmc


    // Eta cone subtracted FF pbpbmc_gen and pbpbmc
    call->cd(icent+2);
    dummy_pbpbsub[icent] = new TH2D(Form("dummy_pbpbsub_%d_%d",centmins[icent],centmaxs[icent]),";#xi;dN/d#xi",1,0.01,4.99,1,0,yaxismax);
    dummy_pbpbsub[icent]->GetXaxis()->SetTitleOffset(0.8);
    dummy_pbpbsub[icent]->GetXaxis()->CenterTitle();
    dummy_pbpbsub[icent]->GetYaxis()->CenterTitle();
    dummy_pbpbsub[icent]->GetXaxis()->SetTitleSize(dummy_pbpbsub[icent]->GetXaxis()->GetTitleSize()*1.4);

    clone_hgammaffxi_refcone_pbpbmc_gen_[icent] = (TH1D*) hgammaffxi_refcone_pbpbmc_gen_[icent]->Clone(Form("clone_hgammaffxi_refcone_pbpbmc_gen_%d_%d",centmins[icent],centmaxs[icent]));
    clone_hgammaffxi_refcone_pbpbmc_gen_[icent]->Scale(-1);
    clone_hgammaffxi_pbpbmc_gen_[icent] = (TH1D*) hgammaffxi_pbpbmc_gen_[icent]->Clone(Form("clone_hgammaffxi_pbpbmc_gen_%d_%d",centmins[icent],centmaxs[icent]));
    clone_hgammaffxi_pbpbmc_gen_[icent]->Add(clone_hgammaffxi_refcone_pbpbmc_gen_[icent]); // no longer needed when using sube == 0

    clone_hgammaffxi_refcone_pbpbmc_[icent] = (TH1D*) hgammaffxi_refcone_pbpbmc_[icent]->Clone(Form("clone_hgammaffxi_refcone_pbpbmc__%d_%d",centmins[icent],centmaxs[icent]));
    clone_hgammaffxi_refcone_pbpbmc_[icent]->Scale(-1);
    clone_hgammaffxi_pbpbmc_[icent] = (TH1D*) hgammaffxi_pbpbmc_[icent]->Clone(Form("clone_hgammaffxi_pbpbmc__%d_%d",centmins[icent],centmaxs[icent]));
    clone_hgammaffxi_pbpbmc_[icent]->Add(clone_hgammaffxi_refcone_pbpbmc_[icent]);
    clone_hgammaffxi_pbpbmc_[icent]->SetMarkerColor(kRed);
    clone_hgammaffxi_pbpbmc_gen_[icent]->SetMarkerColor(kBlue);
    // fixedFontHist(dummy_pbpbsub[icent]);
    dummy_pbpbsub[icent]->Draw();
    clone_hgammaffxi_pbpbmc_gen_[icent]->Draw("same");
    // hgammaffxi_pbpbmc_[icent]->Draw("same");
    // hgammaffxi_refcone_pbpbmc_[icent]->Draw("same");
    clone_hgammaffxi_pbpbmc_[icent]->Draw("same");
    if(icent==0)
    {
      leg_ff_pbpbsub[icent] = new TLegend(0.03,0.697,0.3,0.92);
    }
    else
    {
      leg_ff_pbpbsub[icent] = new TLegend(0,0.697,0.27,0.92);
    }
    leg_ff_pbpbsub[icent]->SetTextSize(0.05*1.3);
    leg_ff_pbpbsub[icent]->SetFillColor(0);
    leg_ff_pbpbsub[icent]->SetFillStyle(0);
    leg_ff_pbpbsub[icent]->SetTextFont(42);
    if(icent==0)
    {
      leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_gen_[icent],"Mixed event","p");
      leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],"Reflected cone","p");
    }
    else if(icent==1)
    {
      // leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],"#eta cone sub","");
      leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],"trk p_{T}>1 GeV, R < 0.3","");
      leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],Form("%d>#gamma p_{T}>%d GeV",phoetmin,phoetmax),"");
    }
    else if(icent==2)
    {
      leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],"0.3 < |#eta^{jet}| < 1.6","");
      leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],"p_{T}^{jet} > 40 GeV","");
    }
    else
    {
      leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],"Pythia+Hydjet","");
      leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],"","");
    }
    leg_ff_pbpbsub[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],Form("%s",cents[icent].data()),"");
    leg_ff_pbpbsub[icent]->Draw();
    // c1_subpbpb[icent]->SaveAs("pbpbmc_gen_pbpbmc_etaconesubtracted_45_gamma_100.png");
    // Eta cone subtracted FF pbpbmc_gen and pbpbmc

  }
  call->cd(1);

  TH2D * axis_dummy = new TH2D("axis_dummy","",1,0.01,4.99,1,0,yaxismax);
  gStyle->SetFrameLineColor(0);
  axis_dummy->UseCurrentStyle();
  axis_dummy->Draw("FB BB A");

  TLatex * ldndxi = new TLatex(0.4,0.5,"dN/d#xi");
  ldndxi->SetTextSize(ldndxi->GetTextSize()*1.2);
  ldndxi->SetNDC();
  ldndxi->SetTextAngle(90);

  TLatex * laxis[yaxismax];
  for (int ilatex = 0; ilatex < yaxismax; ilatex++) {
    laxis[ilatex] = new TLatex(3.,ilatex-0.1,Form("%d",ilatex));
    laxis[ilatex]->SetTextSize(laxis[ilatex]->GetTextSize()*1.2);
    laxis[ilatex]->Draw();
  }
  ldndxi->Draw();

  TCanvas * callratio = new TCanvas("callratio","",1600,500);
  makeMultiPanelCanvas(callratio,6,1,0.02,0.0,-6,0.2,0.04);
  for (int icent = 0; icent < 5; icent++) {
    callratio->cd(icent+2);
    clone2_hgammaffxi_pbpbmc_gen_[icent] = (TH2D*) clone_hgammaffxi_pbpbmc_gen_[icent]->Clone(Form("clone2_hgammaffxi_pbpbmc_gen_%d_%d",centmins[icent],centmaxs[icent]));
    clone2_hgammaffxi_pbpbmc_[icent] = (TH2D*) clone_hgammaffxi_pbpbmc_[icent]->Clone(Form("clone2_hgammaffxi_pbpbmc_%d_%d",centmins[icent],centmaxs[icent]));
    clone2_hgammaffxi_pbpbmc_gen_[icent]->Divide(clone2_hgammaffxi_pbpbmc_[icent]);

    dummy2_pbpbsub[icent] = new TH2D(Form("dummy2_pbpbsub_%d_%d",centmins[icent],centmaxs[icent]),";#xi;dN/d#xi",1,0.01,4.99,1,0,yaxismax2);
    dummy2_pbpbsub[icent]->GetXaxis()->SetTitleOffset(0.8);
    dummy2_pbpbsub[icent]->GetXaxis()->CenterTitle();
    dummy2_pbpbsub[icent]->GetYaxis()->CenterTitle();
    dummy2_pbpbsub[icent]->GetXaxis()->SetTitleSize(dummy2_pbpbsub[icent]->GetXaxis()->GetTitleSize()*1.4);
    dummy2_pbpbsub[icent]->Draw();
    // clone2_hgammaffxi_pbpbmc_gen_[icent]->SetMarkerColor(kViolet);
    clone2_hgammaffxi_pbpbmc_gen_[icent]->SetMarkerColor(kBlack);
    clone2_hgammaffxi_pbpbmc_gen_[icent]->Draw("same");
    TLine * lone = new TLine(0,1,5,1);
    lone->SetLineStyle(9);
    lone->Draw();

    if(icent==0)
    {
      leg_ff_pbpbsub2[icent] = new TLegend(0.03,0.697,0.3,0.92);
    }
    else
    {
      leg_ff_pbpbsub2[icent] = new TLegend(0,0.697,0.27,0.92);
    }
    leg_ff_pbpbsub2[icent]->SetTextSize(0.05*1.3);
    leg_ff_pbpbsub2[icent]->SetFillColor(0);
    leg_ff_pbpbsub2[icent]->SetFillStyle(0);
    leg_ff_pbpbsub2[icent]->SetTextFont(42);
    if(icent==0)
    {
      leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],"Mixed Event/Reflected Cone","p");
      leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],"","");
    }
    else if(icent==1)
    {
      // leg_ff_pbpbsub2[icent]->AddEntry(clone_hgammaffxi_pbpbmc_[icent],"#eta cone sub","");
      leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],"trk p_{T}>1 GeV, R < 0.3","");
      leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],Form("%d>#gamma p_{T}>%d GeV",phoetmin,phoetmax),"");
    }
    else if(icent==2)
    {
      leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],"0.3 < |#eta^{jet}| < 1.6","");
      leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],"p_{T}^{jet} > 40 GeV","");
    }
    else
    {
      leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],"Pythia+Hydjet","");
      leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],"","");
    }
    leg_ff_pbpbsub2[icent]->AddEntry(clone2_hgammaffxi_pbpbmc_gen_[icent],Form("%s",cents[icent].data()),"");
    leg_ff_pbpbsub2[icent]->Draw();

  }
  callratio->cd(1);

  TH2D * axis_dummy_ratio = new TH2D("axis_dummy_ratio","",1,0.01,4.99,1,0,yaxismax2);
  gStyle->SetFrameLineColor(0);
  axis_dummy_ratio->UseCurrentStyle();
  axis_dummy_ratio->Draw("FB BB A");

  TLatex * ldndxi2 = new TLatex(0.4,0.4,"dN/d#xi Gen/Reco");
  ldndxi2->SetTextSize(ldndxi2->GetTextSize()*1.2);
  ldndxi2->SetNDC();
  ldndxi2->SetTextAngle(90);

  TLatex * laxis2[yaxismax2];
  for (int ilatex = 0; ilatex < yaxismax2; ilatex++) {
    laxis2[ilatex] = new TLatex(3.,ilatex-0.1,Form("%d",ilatex));
    laxis2[ilatex]->SetTextSize(laxis2[ilatex]->GetTextSize()*1.2);
    laxis2[ilatex]->Draw();
  }
  ldndxi2->Draw();

  call->SaveAs(Form("mixed_event_closure_mc_%d_%d.png",phoetmin,phoetmax));
  callratio->SaveAs(Form("mixed_event_ratio_mc_%d_%d.png",phoetmin,phoetmax));
}
Example #14
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)
  // Updated by:   Dinko Ferencek (Rutgers)
  //
  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 = static_cast<TH1F*>(file_.Get("data")->Clone());
    data->SetDirectory(0);
    data->SetMarkerStyle(20);
    data->SetMarkerSize(markerSize);

    TH1F *MC   = static_cast<TH1F*>(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;
}
void plotTree(TTree *tree_, std::string whichfit, std::string selectString){

	// Create a map for plotting the pullsummaries:
	std::map < const char*, std::pair <double,double> > pullSummaryMap;
	int nPulls=0;

	TObjArray *l_branches = tree_->GetListOfBranches();
	int nBranches = l_branches->GetEntries();

	gStyle->SetPadTopMargin(0.01);

	TCanvas *c = new TCanvas("c","",960,800);

	std::string treename = tree_->GetName();
	c->SaveAs(Form("%s.pdf[",treename.c_str()));
	// File to store plots in 
	TFile *fOut = new TFile(Form("%s.root",treename.c_str()),"RECREATE");

	for (int iobj=0;iobj<nBranches;iobj++){

		TBranch *br =(TBranch*) l_branches->At(iobj);

		// Draw the normal histogram
		const char* name = br->GetName();

                // names with - are not allowed
                string namestr(name);
                if(namestr.find("-")!=string::npos) {
                  std::cout << "Variable " << name << " contains a bad character: -. Skipping. " << std::endl;
                  continue;
                }
		bool fitPull=false;
		bool fitPullf=false;

		bool plotLH=false;

		TGraph *gr=NULL;
		double p_mean =0;
		double p_err  =0;

		int nToysInTree = tree_->GetEntries();
		// Find out if paramter is fitted value or constraint term
		bool isFitted = findNuisancePre(name);
		if (doPull && isFitted){
			
			p_mean = bfvals_[name].first;	// toy constrainits thrown about best fit to data
			if(namestr.find("n_exp")==string::npos) p_err  = prevals_[name].second; // uncertainties taken from card
			std::cout << "******* "<< name << " *******"<<std::endl;
			std::cout << p_mean <<  " " << p_err << std::endl;
			std::cout << "******************************" <<std::endl;

			const char* drawInput;
                        // if the parameter is a normalization, the error is not available. Do the residual instead of the pull
                        if(namestr.find("n_exp")!=string::npos) drawInput = Form("(%s-%f)/%f",name,p_mean,p_mean);
                        else drawInput = Form("(%s-%f)/%f",name,p_mean,p_err);
			tree_->Draw(Form("%s>>%s",drawInput,name),"");
			tree_->Draw(Form("%s>>%s_fail",drawInput,name),selectString.c_str(),"same");
			fitPull  = true;
			fitPullf = true;
			if (doLH) {
			  gr = graphLH(name,p_err,whichfit);
			  if (gr) plotLH=true;
			}
			
		}

		else{
			tree_->Draw(Form("%s>>%s",name,name),"");
			tree_->Draw(Form("%s>>%s_fail",name,name),selectString.c_str(),"same");
		}
		

		TH1F* bH  = (TH1F*) gROOT->FindObject(Form("%s",name))->Clone();
		TH1F* bHf = (TH1F*) gROOT->FindObject(Form("%s_fail",name))->Clone();
		bHf->SetLineColor(2);
		bH->GetXaxis()->SetTitle(bH->GetTitle());
		bH->GetYaxis()->SetTitle(Form("no toys (%d total)",nToysInTree));
		bH->GetYaxis()->SetTitleOffset(1.05);
		bH->GetXaxis()->SetTitleOffset(0.9);
		bH->GetYaxis()->SetTitleSize(0.05);
		bH->GetXaxis()->SetTitleSize(0.05);
		if (isFitted) {bH->GetXaxis()->SetTitle(Form("(%s-#theta_{B})/#sigma_{#theta}",name));}
		else {bH->GetXaxis()->SetTitle(Form("%s",name));}
		
		bH->SetTitle("");	

		if ( bH->Integral() <=0 )  fitPull = false;
		if (fitPull) {bH->Fit("gaus"); bH->GetFunction("gaus")->SetLineColor(4);}
		
		if ( bHf->Integral() <=0 )  fitPullf = false;
		if (fitPullf) {bHf->Fit("gaus"); bHf->GetFunction("gaus")->SetLineColor(2);}

		c->Clear();
		//TPad pad1("t1","",0.01,0.02,0.59,0.98);
		// Pad 1 sizes depend on the parameter type ...
		double pad1_x1,pad1_x2,pad1_y1,pad1_y2;
		if ( !isFitted ) {
			 pad1_x1 = 0.01; 
			 pad1_x2 = 0.98; 
			 pad1_y1 = 0.045; 
			 pad1_y2 = 0.98; 
		} else {
			 pad1_x1 = 0.01; 
			 pad1_x2 = 0.59; 
			 pad1_y1 = 0.56; 
			 pad1_y2 = 0.98; 
		}
		
		TPad pad1("t1","",pad1_x1,pad1_y1,pad1_x2,pad1_y2);
		TPad pad1a("t1a","",0.01,0.045,0.59,0.522);
		TPad pad2("t2","",0.59,0.04,0.98,0.62);
		TPad pad3("t3","",0.55,0.64,0.96,0.95);

		pad1.SetNumber(1); pad2.SetNumber(2); pad3.SetNumber(3); pad1a.SetNumber(4);

		if ( isFitted ) {pad1a.Draw();pad2.Draw();pad3.Draw();}

		pad1.Draw();
		pad2.SetGrid(true);


		TLatex *titletext = new TLatex();titletext->SetNDC();

		if ( isFitted ){
			c->cd(4); 
			tree_->Draw(Form("%s:%s_In>>%s_%s_2d",name,name,name,tree_->GetName()),""); 
			//TH2D *h2d_corr = (TH2D*)gROOT->FindObject(Form("%s_2d",name));
			//h2d_corr->SetMarkerColor(4);
			//h2d_corr->SetTitle("");
			//h2d_corr->GetXaxis()->SetTitle(Form("%s_In",name));
			//h2d_corr->GetYaxis()->SetTitle(Form("%s",name));
			titletext->SetTextAlign(11);
			titletext->SetTextSize(0.05);
			titletext->DrawLatex(0.05,0.02,Form("%s_In",name));
			titletext->SetTextAngle(90);
			titletext->DrawLatex(0.04,0.06,Form("%s",name));
			titletext->SetTextAngle(0);
		}

		
		c->cd(1); bH->Draw(); bHf->Draw("same");
		TLegend *legend = new TLegend(0.6,0.8,0.9,0.89);
		legend->SetFillColor(0);
		legend->AddEntry(bH,"All Toys","L");
		legend->AddEntry(bHf,selectString.c_str(),"L");
		legend->Draw();

		if (doPull && plotLH) {
			c->cd(2); gr->Draw("ALP");
		}

		if (fitPull){
			c->cd(3);
			double gap;
			TLatex *tlatex = new TLatex(); tlatex->SetNDC(); 
			if (fitPullf) {tlatex->SetTextSize(0.09); gap=0.12;}
			else  {tlatex->SetTextSize(0.11);gap=0.14;}

			tlatex->SetTextColor(4);
			tlatex->DrawLatex(0.11,0.80,Form("Mean    : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParError(1)));
			tlatex->DrawLatex(0.11,0.80-gap,Form("Sigma   : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(2),bH->GetFunction("gaus")->GetParError(2)));

			if (fitPullf){ 
				tlatex->SetTextColor(2);
				tlatex->DrawLatex(0.11,0.60,Form("Mean    : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(1),bHf->GetFunction("gaus")->GetParError(1)));
				tlatex->DrawLatex(0.11,0.60-gap,Form("Sigma   : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(2),bHf->GetFunction("gaus")->GetParError(2)));
			}

			tlatex->SetTextSize(0.10);
			tlatex->SetTextColor(1);
				
                        if(namestr.find("n_exp")!=string::npos) tlatex->DrawLatex(0.11,0.33,Form("Pre-fit: %.3f",prevals_[name].first));
			else tlatex->DrawLatex(0.11,0.33,Form("Pre-fit #pm #sigma_{#theta}: %.3f #pm %.3f",prevals_[name].first, p_err));
			tlatex->DrawLatex(0.11,0.18,Form("Best-fit (#theta_{B})  : %.3f ",p_mean));
			tlatex->DrawLatex(0.11,0.03,Form("Best-fit (#theta_{S+B}): %.3f ",bfvals_sb_[name].first));
			
			pullSummaryMap[name]=std::make_pair<double,double>(bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParameter(2));
			nPulls++;

		}

		double titleSize = isFitted ? 0.1 : 0.028;
		titletext->SetTextSize(titleSize);titletext->SetTextAlign(21); titletext->DrawLatex(0.55,0.92,name);
		c->SaveAs(Form("%s.pdf",treename.c_str()));
		fOut->WriteObject(c,Form("%s_%s",treename.c_str(),name));
		//c->SaveAs(Form("%s_%s.pdf",treename.c_str(),name));
	}
	
	if (doPull && nPulls>0){
	  
	    std::cout << "Generating Pull Summaries" <<std::endl; 
	    int nRemainingPulls = nPulls;
	    TCanvas *hc = new TCanvas("hc","",3000,2000); hc->SetGrid(0);
	    std::map < const char*, std::pair <double,double> >::iterator pull_it = pullSummaryMap.begin();
	    std::map < const char*, std::pair <double,double> >::iterator pull_end = pullSummaryMap.end();

	    int pullPlots = 1;
	    while (nRemainingPulls > 0){

		int nThisPulls = min(maxPullsPerPlot,nRemainingPulls);

		TH1F pullSummaryHist("pullSummary","",nThisPulls,0,nThisPulls);
		for (int pi=1;pull_it!=pull_end && pi<=nThisPulls ;pull_it++,pi++){
			pullSummaryHist.GetXaxis()->SetBinLabel(pi,(*pull_it).first);
			pullSummaryHist.SetBinContent(pi,((*pull_it).second).first);
			pullSummaryHist.SetBinError(pi,((*pull_it).second).second);
			nRemainingPulls--;
		}		

		pullSummaryHist.SetMarkerStyle(21);pullSummaryHist.SetMarkerSize(1.5);pullSummaryHist.SetMarkerColor(2);pullSummaryHist.SetLabelSize(pullLabelSize);
		pullSummaryHist.GetYaxis()->SetRangeUser(-3,3);pullSummaryHist.GetYaxis()->SetTitle("pull summary (n#sigma)");pullSummaryHist.Draw("E1");
		hc->SaveAs(Form("%s.pdf",treename.c_str()));
		fOut->WriteObject(hc,Form("comb_pulls_%s_%d",treename.c_str(),pullPlots));
	//	hc->SaveAs(Form("comb_pulls_%s_%d.pdf",treename.c_str(),pullPlots));
		pullPlots++;
	   }

	    delete hc;
	}

	c->SaveAs(Form("%s.pdf]",treename.c_str()));
	fOut->Close();
	delete c;
	return;


}
Example #16
0
void PlotRakeInjection( const TString &sim, Int_t zoom=2, Int_t Nbins=2, const TString &options="") {
  
#ifdef __CINT__  
  gSystem->Load("libplasma.so");
#endif

  PlasmaGlob::Initialize();

  // Palettes!
  gROOT->Macro("PlasmaPalettes.C");

  // Init Units table
  PUnits::UnitsTable::Get();
  
  TString opt = options;
  
  // More makeup
  gStyle->SetPadGridY(0);
  if(opt.Contains("grid")) {
    gStyle->SetPadGridX(1);
    gStyle->SetPadGridY(1);
  }
  
  Bool_t CYL = kFALSE;
  if(sim.Contains("cyl")) { CYL = kTRUE; opt += "cyl"; } 
  
  Bool_t ThreeD = kFALSE;
  if(sim.Contains("3D")) ThreeD = kTRUE; 
  
  // Load PData
  PData *pData = PData::Get(sim.Data());

  // Create the canvas and the pads before the Frame loop
  // Resolution:
  Int_t sizex = 600;
  Int_t sizey = 640;
  if(opt.Contains("hres")) {
    Int_t sizex = 1200;
    Int_t sizey = 1280;    
  }
  
  TCanvas *C1 = new TCanvas("C1","Evolution of Injection",sizex,sizey);
  C1->cd();
  
  // Palettes
  TExec *exPlasma = new TExec("exPlasma","plasmaPalette->cd();");
  TExec *exElec   = new TExec("exElec","electronPalette->cd();");
  TExec *exHot    = new TExec("exHot","hotPalette->cd();");
  
  const Int_t NFrames = 4;
  // Int_t timestep[NFrames] = {18,22,26,34};
  // TString sLabels[NFrames] = {"(a)","(b)","(c)","(d)"};
  //  Int_t timestep[NFrames] = {34,26,22,18};
  Int_t timestep[NFrames] = {500,60,36,31};
  TString sLabels[NFrames] = {"(d)","(c)","(b)","(a)"};
  Float_t Time[NFrames] = {0.0};
  TH2F ***hDen2D = new TH2F**[NFrames];
  Float_t **zDenMax = new Float_t*[NFrames];
  Float_t *zDenMaxTotal = NULL;

  // Text objects
  TPaveText **textTime  = new TPaveText*[NFrames];
  TPaveText **textLabel = new TPaveText*[NFrames];

  TPad **pad = new TPad*[NFrames];
  TH2F *hFrame[NFrames];
 
  //  C1->Divide(1,NFrames);

  // Setup Pad layout:
  Double_t lMargin = 0.15;
  Double_t rMargin = 0.18;
  Double_t bMargin = 0.10;
  Double_t tMargin = 0.04;
  Double_t vSpacing = 0.00; 
  Double_t hStep = (1.-lMargin-rMargin);
  Double_t vStep = (1.- bMargin - tMargin - (NFrames-1) * vSpacing) / NFrames;
  
  Float_t vposd = 0.0;
  Float_t vposu = 0.0;
  Float_t vmard = 0.0;
  Float_t vmaru = 0.0;
  Float_t vfactor = 0.0;
  Float_t hposl = 0.0;
  Float_t hposr = 1.0;
  Float_t hmarl = lMargin;
  Float_t hmarr = rMargin;
  Float_t hfactor = 1.0;

  Double_t n0,kp,skindepth,E0;
  Int_t Nspecies;
  
  for(Int_t k=0;k<NFrames;k++) {
    
    pData->LoadFileNames(timestep[k]);
    if(!pData->IsInit()) continue;
    
    // Some plasma constants
    n0 = pData->GetPlasmaDensity();
    kp = pData->GetPlasmaK();
    skindepth = 1.;
    if(kp!=0.0) skindepth = 1/kp;
    E0 = pData->GetPlasmaE0();
    
    // Time in OU
    Time[k] = pData->GetRealTime();
    // z start of the plasma in normalized units.
    Float_t zStartPlasma = pData->GetPlasmaStart()*kp;
    // z start of the beam in normalized units.
    Float_t zStartBeam = pData->GetBeamStart()*kp;
    
    if(opt.Contains("center")) {
      Time[k] -= zStartPlasma;
      if(opt.Contains("comov"))      // Centers on the head of the beam.
	Time[k] += zStartBeam;
    }
    
    // Get charge density histos
    Nspecies = pData->NSpecies();
    hDen2D[k] = new TH2F*[Nspecies];
    zDenMax[k] = new Float_t[Nspecies];
    
    if(k==0) zDenMaxTotal = new Float_t[Nspecies];
   
    for(Int_t i=0;i<Nspecies;i++) {
      hDen2D[k][i] = NULL;
      if(k==0) zDenMaxTotal[i] = -999.;
      if(!pData->GetChargeFileName(i)) 
	continue;
      
      char hName[24];
      sprintf(hName,"hDen_%i_%i",k,i);
      hDen2D[k][i] = (TH2F*) gROOT->FindObject(hName);
      if(hDen2D[k][i]) delete hDen2D[k][i];
      
      if(!ThreeD)
	hDen2D[k][i] = pData->GetCharge(i,opt);
      else
	hDen2D[k][i] = pData->GetCharge2DSliceZY(i,-1,Nbins,opt+"avg");
      
      hDen2D[k][i]->SetName(hName);
      hDen2D[k][i]->GetXaxis()->CenterTitle();
      hDen2D[k][i]->GetYaxis()->CenterTitle();
      hDen2D[k][i]->GetZaxis()->CenterTitle();

      zDenMax[k][i] = hDen2D[k][i]->GetMaximum();
      if(zDenMax[k][i]>zDenMaxTotal[i])
	zDenMaxTotal[i] = zDenMax[k][i]; 
            
      // Changing to user units: 
      // --------------------------
      if(opt.Contains("units") && n0) {
	Int_t NbinsX = hDen2D[k][i]->GetNbinsX();
	Float_t xMin = skindepth * hDen2D[k][i]->GetXaxis()->GetXmin() / PUnits::um;
	Float_t xMax = skindepth * hDen2D[k][i]->GetXaxis()->GetXmax() / PUnits::um;
	Int_t NbinsY = hDen2D[k][i]->GetNbinsY();
	Float_t yMin = skindepth * hDen2D[k][i]->GetYaxis()->GetXmin() / PUnits::um;
	Float_t yMax = skindepth * hDen2D[k][i]->GetYaxis()->GetXmax() / PUnits::um;
	hDen2D[k][i]->SetBins(NbinsX,xMin,xMax,NbinsY,yMin,yMax);
	
	hDen2D[k][i]->GetXaxis()->SetTitle("#zeta [#mum]");
      } else {
	hDen2D[k][i]->GetXaxis()->SetTitle("k_{p} #zeta");
      }

      // Zoom
      Float_t range    = (hDen2D[k][i]->GetYaxis()->GetXmax() - hDen2D[k][i]->GetYaxis()->GetXmin())/zoom;
      Float_t midPoint = (hDen2D[k][i]->GetYaxis()->GetXmax() + hDen2D[k][i]->GetYaxis()->GetXmin())/2.;
      
      Float_t yMin,yMax;
      if(!CYL) {
	yMin = midPoint-range/2;
	yMax = midPoint+range/2;
      } else {
	yMin = 0.;
	yMax = range;
      }
      hDen2D[k][i]->GetYaxis()->SetRangeUser(yMin,yMax);
      

    }
  }

  Float_t density = 1;
  Float_t Base = density;

  Float_t *Max = new Float_t[Nspecies];
  Float_t *Min = new Float_t[Nspecies];
  
  for(Int_t k=0;k<NFrames;k++) {
    
    // Set Z ranges:
    for(Int_t i=0;i<Nspecies;i++) {
  
      Max[i] = zDenMaxTotal[i];
      Min[i] =  1.01E-1 * Base;
      if(i==2) {
	Min[i] = 1.01E-3 * Base;
	Max[i] = zDenMax[k][i];
      }
      
      hDen2D[k][i]->GetZaxis()->SetRangeUser(Min[i],Max[i]);
      
      
      if(i==0 && k==0) {
	// Dynamic plasma palette
	const Int_t plasmaDNRGBs = 3;
	const Int_t plasmaDNCont = 128;
	Double_t basePos = 0.5;
	if(Max[i]!=Min[i]) {
	  if(opt.Contains("logz")) {
	    Float_t a = 1.0/(TMath::Log10(Max[i])-TMath::Log10(Min[i]));
	    Float_t b = TMath::Log10(Min[i]);
	    basePos = a*(TMath::Log10(Base) - b);
	    //  cout << Form("Min = %f Base = %f Max = %f",a*(TMath::Log10(Min) - b),basePos,a*(TMath::Log10(Max) - b)) << endl;     
	  } else {
	    basePos = (1.0/(Max[i]-Min[i]))*(Base - Min[i]);
	  }
	}
	
	Double_t plasmaDStops[plasmaDNRGBs] = { 0.00, basePos, 1.00 };
	Double_t plasmaDRed[plasmaDNRGBs]   = { 0.99, 0.90, 0.00 };
	Double_t plasmaDGreen[plasmaDNRGBs] = { 0.99, 0.90, 0.00 };
	Double_t plasmaDBlue[plasmaDNRGBs]  = { 0.99, 0.90, 0.00 };
	
	PPalette * plasmaPalette = (PPalette*) gROOT->FindObject("plasma");
	plasmaPalette->CreateGradientColorTable(plasmaDNRGBs, plasmaDStops, 
						plasmaDRed, plasmaDGreen, plasmaDBlue, plasmaDNCont);
      }
    }
    
    // PLOTTING!
    if(k==0) {
      vposd = 0.0;
      vposu = bMargin + vStep;
      vfactor = vposu-vposd;  
      vmard = bMargin / vfactor;
      vmaru = 0.0;
    } else if(k == NFrames-1) {
      vposd = vposu + vSpacing;
      vposu = vposd + vStep + tMargin;
      vfactor = vposu-vposd;   
      vmard = 0.0;
      vmaru = tMargin / (vposu-vposd);
    } else {
      vposd = vposu + vSpacing;
      vposu = vposd + vStep; 
      vfactor = vposu-vposd;
      vmard = 0.0;
      vmaru = 0.0;
    } 
    hfactor = hposl-hposr;
  
    C1->cd();
    
    char name[16];
    sprintf(name,"pad_%i",k);
    pad[k] = new TPad(name,"",hposl,vposd,hposr,vposu);
    // // cout << Form("%f %f %f %f",hposl,vposd,hposr,vposu) << endl;
    // // cout << Form("%f %f %f %f",hmarl,vmard,hmarr,vmaru) << endl;
    pad[k]->SetLeftMargin(hmarl);
    pad[k]->SetRightMargin(hmarr);  
    pad[k]->SetBottomMargin(vmard);
    pad[k]->SetTopMargin(vmaru);
  
    pad[k]->SetFrameLineWidth(3);  
    if(opt.Contains("logz")) {
      pad[k]->SetLogz(1);
    } else {
      pad[k]->SetLogz(0);
    }
    pad[k]->Draw();
    pad[k]->cd();
    
    sprintf(name,"hFrame_%i",k);  
    hFrame[k] = (TH2F*) gROOT->FindObject(name);
    if(hFrame[k]) delete hFrame[k];
    hFrame[k] = (TH2F*) hDen2D[k][0]->Clone(name);
    hFrame[k]->Reset();
  
    hFrame[k]->GetXaxis()->CenterTitle();
    hFrame[k]->GetYaxis()->CenterTitle();
    hFrame[k]->GetZaxis()->CenterTitle();

    hFrame[k]->SetLabelFont(42,"xyz");
    hFrame[k]->SetTitleFont(42,"xyz");
  
    hFrame[k]->SetNdivisions(505,"xyz");
  
    hFrame[k]->SetTickLength(0.04,"xyz");
    hFrame[k]->SetTickLength(0.04*vfactor,"y");
  
    hFrame[k]->GetYaxis()->SetLabelSize(0.03/vfactor);
    hFrame[k]->GetYaxis()->SetLabelOffset(0.02);
  
    hFrame[k]->GetYaxis()->SetTitleSize(0.03/vfactor);
    hFrame[k]->GetYaxis()->SetTitleOffset(999.0*vfactor);
  
    if(k==0) {  
      hFrame[k]->GetXaxis()->SetLabelSize(0.10);
      hFrame[k]->GetXaxis()->SetLabelOffset(0.02);
      hFrame[k]->GetXaxis()->SetTitleSize(0.14);
      hFrame[k]->GetXaxis()->SetTitleOffset(1.0);
    } else {
      hFrame[k]->GetXaxis()->SetLabelSize(0.0);
      hFrame[k]->GetXaxis()->SetTitleSize(0.0);
    }
  
    hFrame[k]->Draw("axis");    
  


    exPlasma->Draw();

    // Sum of histograms!
    hDen2D[k][0]->Add(hDen2D[k][1]);
        
    //    hDen2D[k][0]->GetZaxis()->SetRangeUser(Min[1],Max[1]);
 
    hDen2D[k][0]->Draw("colz same");
    
    pad[k]->Update();
    TPaletteAxis *palette = (TPaletteAxis*)hDen2D[k][0]->GetListOfFunctions()->FindObject("palette");
    
    Float_t y1 = pad[k]->GetBottomMargin();
    Float_t y2 = 1 - pad[k]->GetTopMargin();
    Float_t x1 = pad[k]->GetLeftMargin();
    Float_t x2 = 1 - pad[k]->GetRightMargin();
    palette->SetY2NDC(y2 - 1*(y2-y1)/2.0 - 0.00);
    palette->SetY1NDC(y1 + 0*(y2-y1)/2.0 + 0.00);
    palette->SetX1NDC(x2 + 0.005);
    palette->SetX2NDC(x2 + 0.03);

    palette->SetLabelFont(42);

    palette->SetLabelSize(0.03/vfactor);
    palette->SetLabelOffset(-0.004);
    palette->SetTitleSize(0.03/vfactor);
    palette->SetTitleOffset(9999.0*vfactor);
  
    palette->SetBorderSize(2);
    palette->SetLineColor(1);
  
    exHot->Draw();
    hDen2D[k][2]->Draw("colz same");

    pad[k]->Update();
    palette = (TPaletteAxis*)hDen2D[k][2]->GetListOfFunctions()->FindObject("palette");
    
    palette->SetY2NDC(y2 - 0*(y2-y1)/2.0 - 0.00);
    palette->SetY1NDC(y1 + 1*(y2-y1)/2.0 + 0.00);
    palette->SetX1NDC(x2 + 0.005);
    palette->SetX2NDC(x2 + 0.03);

    palette->SetLabelFont(42);

    palette->SetLabelSize(0.03/vfactor);
    palette->SetLabelOffset(-0.004);
    palette->SetTitleSize(0.03/vfactor);
    palette->SetTitleOffset(9999.0*vfactor);

    palette->SetBorderSize(2);
    palette->SetLineColor(1);

    textTime[k] = new TPaveText(x2-0.17,y2-(0.05/vfactor),x2-0.02,y2-0.04,"NDC"); 
    PlasmaGlob::SetPaveTextStyle(textTime[k],32); 
    char ctext[128];
    if(opt.Contains("units")) 
      sprintf(ctext,"z = %5.0f #mum", skindepth * Time[k] / PUnits::um);
    else
      sprintf(ctext,"z = %5.1f #omega_{p}^{-1}",Time[k]);
    textTime[k]->AddText(ctext);
    textTime[k]->Draw();

    textLabel[k] = new TPaveText(x1+0.02,y1+(0.02/vfactor),x1+0.07,y1+(0.06/vfactor),"NDC"); 
    PlasmaGlob::SetPaveTextStyle(textLabel[k],32); 
    textLabel[k]->SetTextFont(42);
    textLabel[k]->AddText(sLabels[k]);
    textLabel[k]->Draw();
    

    pad[k]->RedrawAxis(); 

  }
    
  C1->cd();

  // PlasmaGlob::SetPaveTextStyle(textYaxis,11); 
  char ctext[128];
  if(opt.Contains("units")) 
    sprintf(ctext,"y [#mum]");
  else
    sprintf(ctext,"k_{p} y");
  TLatex *textYaxis = new TLatex(0.05,0.6,ctext);
  textYaxis->SetTextAlign(22);
  textYaxis->SetTextFont(42);
  textYaxis->SetTextAngle(90);
  textYaxis->Draw();
  
  sprintf(ctext,"n [n_{0}]");
  TLatex *textZaxis = new TLatex(0.95,0.6,ctext);
  textZaxis->SetTextAlign(22);
  textZaxis->SetTextFont(42);
  textZaxis->SetTextAngle(90);
  textZaxis->Draw();

  
  // Output file
  TString fOutName = Form("./%s/Plots/RakeInjection/RakeInjection",pData->GetPath().c_str());
  fOutName += Form("-%s",pData->GetName());
  
  // Print to a file
  PlasmaGlob::imgconv(C1,fOutName,opt);
  // ---------------------------------------------------------

}
//____________________________________________________________________________________
// Plot overlay mH scan (SM + mSugra)
int plotOverlay( TString fileName = "output/msugra-noMH-cut20-v5.root", int index = 68, TString drawOpt = "C" )
{

  // Styles
  gROOT->SetStyle("Pub");
  gStyle->SetCanvasColor(0);
  gStyle->SetCanvasDefH( 500 );
  gStyle->SetCanvasDefW( 600 );
  

  double chi2min = -0., chi2max = 4;  // Delta-chi2 range
  double mHmin   = 30, mHmax = 200;
  double threshold = 1e-4;

  TCanvas* myCanvas = new TCanvas("myCanvas","Pseudo-exps contour",10,10,600,600);
  myCanvas->SetTopMargin(0.02);
  myCanvas->SetLogx(1);
  
  // Retrieve and correct graph
  TFile* file = new TFile(fileName);
  if ( !file->IsOpen() ) {
    std::cerr << "*** Couldn't open " << fileName << std::endl;
    return -1;
  }
  TString gName("graph1d");
  gName += index;
  TGraph* gChi2 = file->Get( gName );
  if ( !gChi2 ) {
    std::cerr << "*** Couldn't find graph \"" << gName << "\"" << std::endl;
    return -1;
  }
  zeroSuppress( gChi2 );

  // Set plot range
  TH2F* range = new TH2F("range","#chi^{2} fit of lightest Higgs mass",
                         2,mHmin,mHmax,2,chi2min,chi2max);
  if ( !doPub ) {
    range->GetXaxis()->SetTitle("M_{h} [GeV/c^{2}]");
    range->GetYaxis()->SetTitle("#Delta#chi^{2}");
    range->GetYaxis()->SetTitleOffset(1.1);
  }
  range->GetXaxis()->SetNoExponent();
  range->GetXaxis()->SetMoreLogLabels(1);
  range->Draw();

  // Find preferred value
  double mHfavour = findMh( gChi2, 0., 100. );
  double negError = mHfavour-findMh( gChi2, 1., 100. );
  double posError = findMh( gChi2, 1., mHfavour )-mHfavour;
  std::cout << "Favoured value: " << mHfavour << "+" << posError << "-" << negError << std::endl;

  
  // Include LEP limit
  int LepColor = 5;
  TBox* bLepLimit = new TBox( mHmin, chi2min+0.01, LEPLIMIT, chi2max-0.01 );
  bLepLimit->SetFillColor( LepColor );
  bLepLimit->Draw();

  TLatex tt;
  if (doPub) tt.SetTextFont(133);
  tt.SetTextSize(14);

  // Blue band
  blueBand();

  // Plot red band (1.5 GeV)
  if ( doBands ) {
    redBand2( gChi2, 1.5, mHfavour, 0.005 );
    gChi2->SetLineColor(4);
    gChi2->SetLineWidth(3);
  } else {
    gChi2->SetLineColor(kMagenta);
    gChi2->SetLineWidth(5);
  }


  // Plot scan
  gChi2->SetMarkerStyle(2);
  gChi2->Draw(drawOpt);
  TMultiGraph* mg = new TMultiGraph();

  // Forbidden regions
  tt.SetTextSize(18);
  tt.SetTextAlign(12);
  tt.DrawLatex( mHmin+4, chi2min+0.4, "#splitline{LEP}{excluded}" );
  tt.SetTextAngle(0);


  // Printout
  // hep-ph number
  TLatex tt;
  tt.SetTextFont(83);
  tt.SetTextSize(18);
  tt.SetTextAlign(32);
  //  tt.DrawTextNDC( 0.89, 0.88, "arXiv:0707.3447" );

//   TString name = "mh-scan-overlay";
//   if ( !doPub ) name += "_label";
//   myCanvas->Print(name+".eps");

  
  return 0;
  
}
Example #18
0
TCanvas* example_plot( int iPeriod, int iPos, bool t, int nt,double miPt, double maPt,string c,string hname, string lbl1, string lbl2,string lbl3 )
{ 
  //  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 = "FigMass_";
  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);
 
  fit(4,t,nt,miPt,maPt,c);
//  fit(4,1,32,"Mass>8.6 && Mass<11.0 && TMath::Abs(EtaMuP)<1.2 && TMath::Abs(EtaMuM)<1.2 && Rapidity<1.2 ");
  
    {
    TLatex latex;

    int n_ = 3;
    float x1_l = 0.95;
    float y1_l = 0.70;

    float dx_l = 0.37;
    float dy_l = 0.23;
    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 gap_ = 1./(n_+1);
    float bwx_ = 0.12;

    x_l[0] = 1.2*bwx_;
    y_l[0] = 1-gap_;

    latex.SetTextFont(42);
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);
    latex.SetTextSize(0.20);
    latex.SetTextAlign(12);

    float xx_ = x_l[0];
    float yy_ = y_l[0];
    //latex.DrawLatex(xx_+1.*bwx_,yy_,"#sigma = 26.5 #pm 2.2 MeV");
    //latex.DrawLatex(xx_+1.*bwx_,yy_,"#sigma = 13 MeV");
//    latex.DrawLatex(xx_+0.5*bwx_,yy_,"#sqrt{f_{1}#sigma_{1}^{2}+f_{2}#sigma_{2}^{2}} = 110 MeV");
   latex.DrawLatex(xx_+0.5*bwx_,yy_,lbl1.c_str());
    yy_ -= gap_;
//    latex.DrawLatex(xx_+0.5*bwx_,yy_,"p_{T}^{#mu^{+}#mu^{-}} > 13 GeV");
    latex.DrawLatex(xx_+0.5*bwx_,yy_,lbl2.c_str());
    yy_ -= gap_;
    latex.DrawLatex(xx_+0.5*bwx_,yy_,lbl3.c_str());
   // latex.DrawLatex(xx_+1.*bwx_,yy_,"|#eta_{#mu}| < 0.5");

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

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

  string hn="Plots/"+hname+".pdf";
  string hnpng ="Plots/"+hname+".png";
  canv->SaveAs(hn.c_str());
  canv->SaveAs(hnpng.c_str());
//  canv->Print(hname+".png",".png");

  return canv;
}
Example #19
0
void draw_putrkextcomp_TChiWH(TString infile = "contours_TChiWH.root") {

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

  cmsText     = "CMS Phase II Delphes Simulation";
  extraText = ""; // remove Preliminary
  writeExtraText = false;       // if extra text
  lumi_14TeV = "PU = 140/200"; // default is "3000 fb^{-1}"

  TCanvas* c1 = new TCanvas("c1","c1",800,600);
  c1->cd();
  gPad->SetTopMargin(0.08);
  gPad->SetRightMargin(0.05);

  TFile* f = new TFile(infile);
  TH2F* h_base = new TH2F("h_base",";m_{#tilde{#chi}_{1}^{#pm}} = m_{#tilde{#chi}_{2}^{0}} (GeV); m_{#tilde{#chi}_{1}^{0}} (GeV)", 90, 100, 1000, 100, 0, 1000);
  h_base->GetXaxis()->SetNdivisions(8,5,0);
  h_base->GetYaxis()->SetNdivisions(8,5,0);
  h_base->SetLabelSize(0.05, "XYZ");
  h_base->SetTitleSize(0.06,"Y");
  h_base->Draw();

  g_signif_PhaseII_3000fb->SetLineWidth(3);
  g_signif_PhaseII_3000fb->SetLineStyle(1);
  g_signif_PhaseII_3000fb->SetLineColor(kRed);
  g_signif_PhaseII_3000fb->Draw("l same");

  // g_signif_PhaseII_PU200_3000fb->SetLineWidth(3);
  // g_signif_PhaseII_PU200_3000fb->SetLineStyle(1);
  // g_signif_PhaseII_PU200_3000fb->SetLineColor(kGreen-2);
  // g_signif_PhaseII_PU200_3000fb->Draw("l same");

  g_signif_PhaseII_PU200_4000fb->SetLineWidth(3);
  g_signif_PhaseII_PU200_4000fb->SetLineStyle(1);
  g_signif_PhaseII_PU200_4000fb->SetLineColor(kMagenta);
  g_signif_PhaseII_PU200_4000fb->Draw("l same");

  g_signif_PhaseII_NoTrkExt_3000fb->SetLineWidth(3);
  g_signif_PhaseII_NoTrkExt_3000fb->SetLineStyle(1);
  g_signif_PhaseII_NoTrkExt_3000fb->SetLineColor(kBlue);
  g_signif_PhaseII_NoTrkExt_3000fb->Draw("l same");

  TLine* diag = new TLine(125.,0.,675.,550.);
  diag->SetLineWidth(3);
  diag->SetLineStyle(2);
  diag->SetLineColor(kBlack);

  diag->Draw("same");

  //  TLegend* leg = new TLegend(0.19,0.68,0.54,0.92);
  //TLegend* leg = new TLegend(0.19,0.68,0.54,0.85);
  TLegend* leg = new TLegend(0.19,0.56,0.54,0.84,"5#sigma Discovery Reach");
  leg->SetFillColor(0);
  leg->SetTextSize(0.04);
  leg->AddEntry(g_signif_PhaseII_3000fb,"3000 fb^{-1} Phase II, 140PU","l");
  //  leg->AddEntry(g_signif_PhaseII_PU200_3000fb,"3000 fb^{-1} Phase II, 200PU","l");
  leg->AddEntry(g_signif_PhaseII_PU200_4000fb,"4000 fb^{-1} Phase II, 200PU","l");
  leg->AddEntry(g_signif_PhaseII_NoTrkExt_3000fb,"3000 fb^{-1} Phase II, 140PU, No Tracker Extension","l");

  leg->Draw("same");

  CMS_lumi_v2( c1, iPeriod, iPos );

  TLatex latex;
  latex.SetNDC();
  latex.SetTextAngle(0);
  latex.SetTextColor(kBlack);    
  latex.SetTextFont(42);
  latex.SetTextAlign(11); 
  latex.SetTextSize(0.05);    
  latex.DrawLatex(0.22,0.5,"#tilde{#chi}_{1}^{#pm}#tilde{#chi}_{2}^{0} #rightarrow W#tilde{#chi}_{1}^{0} H#tilde{#chi}_{1}^{0}");

  gPad->Modified();

  c1->SaveAs("contours_putrkextcomp_4000fb.eps");
  c1->SaveAs("contours_putrkextcomp_4000fb.pdf");
}
Example #20
0
void plotsNoFitETau(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=1.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="DYrightarrowlljets";
	if(!mine) find="zjetsother";
        TH1F *hDY=_file0->Get(dirInternal+find); hDY->SetName("DY");
	find="Diboson";
	if(!mine) find="ww";
        TH1F *hWW=_file0->Get(dirInternal+find); hWW->SetName("WW");
	find="SingleTop";
	if(!mine) find="singlet";
        TH1F *hTOP=_file0->Get(dirInternal+find); hTOP->SetName("TOP");
	find="tbart";
	if(!mine) find="ttbar";
        TH1F *hTT=_file0->Get(dirInternal+find); hTT->SetName("TT");
	find="Zrightarrowtautauembedded";
	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+"LFVvbfHiggsBR=1"); hLFVVBF126->SetName("LFVVBF126");
        TH1F *hSMVBF126=_file0->Get(dirInternal+"SMvbfHiggs"); hSMVBF126->SetName("SMVBF126");
        TH1F *hLFVGG126=_file0->Get(dirInternal+"LFVggHiggsBR=1"); hLFVGG126->SetName("LFVGG126");
        TH1F *hSMGG126=_file0->Get(dirInternal+"SMHiggs"); hSMGG126->SetName("SMGG126");

	find="Observed";
	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=hZTauTau->Clone();  fullMC2->Add(hFAKES); 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->SetFillColorAlpha(kGray+3,0.35);
		   pave->SetFillColor(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, e#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,"MisID'd #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=fullMC2->Clone(); Ratio->SetName("Ratio");
	Ratio->Scale(-1);
	Ratio->Add(hdata_obs,1);
	Ratio->Divide(fullMC2);
	Ratio->SetLineColor(kBlack);

        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->SetFillStyle(3002); 
        RatioError->SetFillColorAlpha(kGray+2,0.35); RatioError->SetMarkerSize(0);  
        RatioError->Draw("E2");
	//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,-1.0,blindB,1.0,4,"br");
                   pave->SetFillColor(1);
                   pave->SetFillStyle(3003);
		   //pave->SetFillColorAlpha(kGray+3,0.35);
                   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");
        }  

}
Example #21
0
void Test_UnfoldQ2(int Type = 0){
  TString TypeName[] = {"Efficiency", "Unfold"};
  if(Type==-1) {
    for(int type=0; type<nType; type++)
      cout<<type<<" "<<TypeName[type]<<", "; 
    cout<<endl; 
    return;
  }
  BToDtaunu Dtaunu; BToDstaunu Dstaunu;
  int nBins = 18, nValues = 50, nBinsRes = 80;
  double limQ2[] = {3.5, 12.5}, limRes = 2, ml[] = {Dtaunu.mTau, Dtaunu.mTau, Dtaunu.mMu};
  if(Type==0){limQ2[0] = 4; nBins = 17;}

  TString mcCuts[3][6] = {{"weight*((MCType==5&&candType==1||MCType==11&&candType==3)&&candM2>1.5)",
			   "weight*((MCType==6&&candType==2||MCType==12&&candType==4)&&candM2>1.5)" ,
			   "weight*((MCType==5&&candType==1||MCType==11&&candType==3))",
			   "weight*((MCType==6&&candType==2||MCType==12&&candType==4))",
			   "weight*(((MCType==1||MCType==3)&&candType==1||(MCType==7||MCType==9)&&candType==3))",
			   "weight*(((MCType==2||MCType==4)&&candType==2||(MCType==8||MCType==10)&&candType==4))"},
			  {"weight*((MCType==11&&candType==3)&&candM2>1.5)",
			   "weight*((MCType==12&&candType==4)&&candM2>1.5)" ,
			   "weight*((MCType==11&&candType==3))",
			   "weight*((MCType==12&&candType==4))",
			   "weight*(((MCType==7||MCType==9)&&candType==3))",
			   "weight*(((MCType==8||MCType==10)&&candType==4))"},
			  {"weight*((MCType==5&&candType==1)&&candM2>1.5)",
			   "weight*((MCType==6&&candType==2)&&candM2>1.5)" ,
			   "weight*((MCType==5&&candType==1))",
			   "weight*((MCType==6&&candType==2))",
			   "weight*(((MCType==1||MCType==3)&&candType==1))",
			   "weight*(((MCType==2||MCType==4)&&candType==2))"}};

  TString PadLabel[] = {"a", "b", "x", "d", "e", "f", "(g)", "(h)", "(i)"};
  TString Units[] = {" GeV^{2})", "0.35 GeV^{2})"}, hName;
  TString xTitle[] = {"Q", "R"};
  TBox box; box.SetLineColor(10);box.SetFillColor(10);

  gStyle->SetOptStat(0);
  int nRows = 2, nCols = 3;
  int Colors[] = {8,4,2}, ColorP[] = {4,1,2,8};
  TLatex label; label.SetTextFont(132); label.SetNDC(kTRUE);
  TCanvas can("dataMC","data Vs MC",700,150*nRows); 
  TPad *Pads[nPads][2];
  TH1D *hbini[nPads], *hxini[nPads][3], *hQ2[nPads][3], *hEff[nPads][3], *hRes[nPads], *hRes2[nPads];
  TH1D *hP[2][4], hTemp("hTemp","",100,0,3.4);
  TChain MC("ntp1");
  MC.Add("AWG82/ntuples/small/FitRAllNewx100_RunAll.root");

  TLegend *leg1[3];
  double scaleEff = 1;
  double dRows = (double)nRows, dCols = (double) nCols;
  double bMargin = 0.12, padH = (1-bMargin)/dRows, padW = 1/dCols, LeftMargin = 0.2;
  for(int col=0; col<nCols; col++){
    for(int row=0; row<nRows; row++){
      can.cd(0);
      int pad = nRows*col+row;
      double TextSize = 0.08;
      double RightMargin = 0.04, TopMargin=0, BottomMargin=bMargin/(bMargin+padH)*row;
      double PadXY[2][2] = {{padW*col, padW*(col+1)},{(padH+bMargin)*(dRows-1-row), bMargin+padH*(2-row)}};
      if(row==0) TextSize *= (bMargin+padH)/padH;
      hName = "Pad0_"; hName += pad;
      //cout<<hName<<": "<<PadXY[0][0]<<", "<<PadXY[1][0]<<", "<<PadXY[0][1]<<", "<<PadXY[1][1]<<endl;
      Pads[pad][0] = new TPad(hName,"",PadXY[0][0], PadXY[1][0], PadXY[0][1], PadXY[1][1]);
      Pads[pad][0]->SetLeftMargin(LeftMargin);     Pads[pad][0]->SetRightMargin(RightMargin); 
      Pads[pad][0]->SetBottomMargin(BottomMargin); Pads[pad][0]->SetTopMargin(TopMargin); 
      Pads[pad][0]->Draw(); Pads[pad][0]->cd();

      if(Type==0){
	for(int isNorm=2; isNorm>=0; isNorm--){
	  hName = "xini"; hName += pad; hName += isNorm;
	  hxini[pad][isNorm] = new TH1D(hName,"",nBins, limQ2[0], limQ2[1]);
	  formatHisto(hxini[pad][isNorm], Colors[isNorm], TextSize);
	  MC.Project(hName,"candQ2",mcCuts[col][row+2*isNorm]);
	  if(row==1) hxini[pad][isNorm]->SetXTitle(xTitle[0]);

	  //cout<<pad<<" Calculating q2"<<isNorm<<endl;
	  hName = "hQ2"; hName += pad; hName += isNorm;
	  hQ2[pad][isNorm] = new TH1D(hName,"",nBins, limQ2[0], limQ2[1]);
	  hQ2[pad][isNorm]->SetLineColor(Colors[isNorm]);
	  for(int bin=1; bin<=nBins; bin++){
	    double q2 = hQ2[pad][isNorm]->GetBinLowEdge(bin), val=0;
	    double dq2 = (hQ2[pad][isNorm]->GetBinLowEdge(bin)-q2)/(double)nValues;
	    q2 += dq2/2.;
	    for(int ival=0; ival<nValues; ival++) {
	      if(row==0) val += 1e16*Dtaunu.Compute(q2,1, ml[isNorm]);
	      else       val += 1e16*Dstaunu.Compute(q2,1, ml[isNorm]);
	      q2 += dq2;
	    }
	    hQ2[pad][isNorm]->SetBinContent(bin,val); hQ2[pad][isNorm]->SetBinError(bin,0);
	  }
	  hEff[pad][isNorm] = (TH1D*)hxini[pad][isNorm]->Clone(); 
	  hEff[pad][isNorm]->Divide(hQ2[pad][isNorm]);
	  if(isNorm==2) scaleEff = 1/hEff[pad][isNorm]->GetMaximum();
	  if(isNorm==1) scaleEff = hEff[pad][2]->Integral(nBins/3,nBins/3*2)/
	    hEff[pad][1]->Integral(nBins/3,nBins/3*2);
	  hEff[pad][isNorm]->Scale(scaleEff);
	  hEff[pad][isNorm]->SetMinimum(0);
	  if(row==1) hEff[pad][isNorm]->SetMaximum(1.72);
	}
	//cout<<pad<<" Drawing"<<endl;
	hEff[pad][1]->Draw();
	if(col==0) hEff[pad][0]->Draw("same"); 
	hEff[pad][2]->Draw("same"); hEff[pad][1]->Draw("same");
	//hQ2[pad][2]->Draw(); hQ2[pad][1]->Draw("same"); 

	// Labels
	label.SetTextAngle(0); label.SetTextSize(TextSize/0.93); 
	TString chanLabel = PadLabel[pad]; 
	double Xchan = 0.92, Ychan = 0.89;
	if(Type>2)  Xchan = LeftMargin+0.06;
	label.SetTextAlign(22); label.DrawLatex(Xchan, Ychan, chanLabel);
      }
      if(Type==1){
	int isNorm=1;
	switch(col){
	case 0:
	  hName = "xini"; hName += pad; hName += isNorm;
	  hxini[pad][isNorm] = new TH1D(hName,"",nBins, limQ2[0], limQ2[1]);
	  formatHisto(hxini[pad][isNorm], Colors[isNorm], TextSize);
	  MC.Project(hName,"trueQ2",mcCuts[col][row+2*isNorm]);
	  if(row==1) hxini[pad][isNorm]->SetXTitle(xTitle[0]);
	  hName = "bini"; hName += pad; hName += isNorm;
	  hbini[pad] = new TH1D(hName,"",nBins, limQ2[0], limQ2[1]);
	  formatHisto(hbini[pad], 1, TextSize);
	  MC.Project(hName,"candQ2",mcCuts[col][row+2*isNorm]);
	  hxini[pad][isNorm]->SetMarkerSize(0.); 
	  hxini[pad][isNorm]->SetMaximum(hxini[pad][isNorm]->GetMaximum()*1.2);
	  hxini[pad][isNorm]->Draw("hist");
	  hbini[pad]->Draw("same");
	  if(row==0){
	    double legXY[2][2] = {{0.78, 0.98}, {0.67, 0.95}};
	    leg1[col] = new TLegend(legXY[0][0], legXY[1][0], legXY[0][1], legXY[1][1]);
	    leg1[col]->SetTextSize(TextSize); leg1[col]->SetFillStyle(0); 
	    leg1[col]->SetTextFont(132); leg1[col]->SetBorderSize(0);
	    leg1[col]->AddEntry(hxini[pad][isNorm],"t");
	    leg1[col]->AddEntry(hbini[pad],"d");
	    leg1[col]->Draw();
	  }
	  break;
	case 1:
	  isNorm=1;
	  hName = "Res"; hName += row;
	  hRes[row] = new TH1D(hName,"",nBinsRes, -limRes, limRes);
	  formatHisto(hRes[row], Colors[isNorm], TextSize);
	  MC.Project(hName,"candQ2-trueQ2", mcCuts[0][row+2*isNorm]);
	  isNorm=2;
	  hName = "Res2"; hName += row;
	  hRes2[row] = new TH1D(hName,"",nBinsRes, -limRes, limRes);
	  formatHisto(hRes2[row], Colors[isNorm], TextSize);
	  hRes[row]->SetMarkerSize(0.3); hRes2[row]->SetMarkerSize(0.); 
	  MC.Project(hName,"candQ2-trueQ2", mcCuts[0][row+2*isNorm]);
	  hRes2[row]->Scale(hRes[row]->Integral()/hRes2[row]->Integral());
	  hRes2[row]->SetMaximum(hRes2[row]->GetMaximum()*1.15);
	  hRes2[row]->Draw("hist"); hRes[row]->Draw("same");
	  if(row==1) hRes2[row]->SetXTitle(xTitle[1]);
	  hName = "#splitline{#mu_{sig} = "; 
	  hName += RoundNumber(hRes[row]->GetMean(),2); hName += "}{#mu_{nor} = ";
	  hName += RoundNumber(hRes2[row]->GetMean(),2); hName += "}";
	  label.SetTextAlign(33); label.SetTextAngle(0); label.SetTextSize(TextSize);
	  label.DrawLatex(1-RightMargin-0.05, 1-0.05, hName);
	  hName = "#splitline{#sigma_{sig} = ";
	  hName += RoundNumber(hRes[row]->GetRMS(),2); hName += "}{#sigma_{nor} = ";
	  hName += RoundNumber(hRes2[row]->GetRMS(),2); hName += "}";
	  label.DrawLatex(1-RightMargin-0.05, 1-0.37-0.06*(row==0), hName);
	  if(row==0){
	    double legXY[2][2] = {{LeftMargin+0.05, LeftMargin+0.25}, {0.67, 0.95}};
	    leg1[col] = new TLegend(legXY[0][0], legXY[1][0], legXY[0][1], legXY[1][1]);
	    leg1[col]->SetTextSize(TextSize); leg1[col]->SetFillStyle(0); 
	    leg1[col]->SetTextFont(132); leg1[col]->SetBorderSize(0);
	    leg1[col]->AddEntry(hRes2[row],"Norm.");
	    leg1[col]->AddEntry(hRes[row],"Signal");
	    leg1[col]->Draw();
	  }
	  break;
	case 2:
	  double maxH = 0;
	  for(isNorm=0; isNorm<3; isNorm++){
	    hName = "hP"; hName += pad;  hName += isNorm;
	    hP[pad][isNorm] = new TH1D(hName,"",nBins, limQ2[0], limQ2[1]);
	    formatHisto(hP[pad][isNorm], ColorP[isNorm], TextSize);
	    double q2 = limQ2[0], dq2 = (limQ2[1]-limQ2[0])/(double)nBins;
	    for(int bin=1; bin<=nBins; bin++){
	      hName = "weight*(trueQ2>="; hName += q2;
	      hName += "&&trueQ2<"; hName += q2+dq2; hName += "&&";
	      TString Cuts = mcCuts[0][2+row+2*(isNorm>1)];
	      Cuts.ReplaceAll("weight*(", hName);
	      TString var = "candPLep"; if(isNorm%2==1) var = "candPstarD";
	      double entries = MC.Project("hTemp",var, Cuts);
	      //cout<<hTemp.GetMean()<<", "<<Cuts<<endl;
	      hP[pad][isNorm]->SetBinContent(bin, hTemp.GetMean());
	      if(entries>1) hP[pad][isNorm]->SetBinError(bin, hTemp.GetRMS()/sqrt(entries));
	      else hP[pad][isNorm]->SetBinError(bin, hTemp.GetMean());
	      
	      q2 += dq2;
	    }
	    if(hP[pad][isNorm]->GetMaximum()>maxH) maxH = hP[pad][isNorm]->GetMaximum();
	  }
	  for(isNorm=0; isNorm<3; isNorm++){
	    if(isNorm==0) {
	      hP[pad][isNorm]->SetMaximum(maxH*1.17);
	      hP[pad][isNorm]->Draw();
	      if(row==1) hP[pad][isNorm]->SetXTitle(xTitle[0]);
	    } else{
	      //hP[pad][isNorm]->Scale(hP[pad][0]->Integral()/hP[pad][isNorm]->Integral());
	      hP[pad][isNorm]->Draw("same");
	    }
	  }
	  if(row==1){
	    double legXY[2][2] = {{LeftMargin+0.05, LeftMargin+0.25}, {0.25, 0.5}};
	    leg1[col] = new TLegend(legXY[0][0], legXY[1][0], legXY[0][1], legXY[1][1]);
	    leg1[col]->SetTextSize(TextSize); leg1[col]->SetFillStyle(0); 
	    leg1[col]->SetTextFont(132); leg1[col]->SetBorderSize(0);
	    leg1[col]->AddEntry(hP[pad][0],"ls");
	    leg1[col]->AddEntry(hP[pad][2],"ln");
	    leg1[col]->AddEntry(hP[pad][1],"D");
	    leg1[col]->Draw();
	  }

	  break;
	}
      }
    }
    can.cd(0);
    hName = "Normalized efficiency/("; 
    if(Type==1) hName = "Events/("; 
    if(Type==1&&col==1) hName += RoundNumber(2*limRes,2,nBinsRes);
    else hName += RoundNumber((limQ2[1]-limQ2[0]),2,nBins);
    hName += Units[0];
    if(Type==1&&col==2) hName = "Momentum (GeV)";
    label.SetTextAlign(23); label.SetTextAngle(90); label.SetTextSize(0.055);
    label.DrawLatex(0.01+col/dCols, 0.56, hName);
    if(Type==0 || Type==1) {
      box.DrawBox(padW*(LeftMargin+col)-0.02, bMargin+padH, padW*(LeftMargin+col)-0.002, bMargin+padH+0.02);
      label.SetTextAlign(32); label.SetTextAngle(0); label.SetTextSize(0.044);
      label.DrawLatex(padW*(LeftMargin+col)-0.0025, bMargin+padH+0.003, "0");
    }

  }



  TString pName = "public_html/Test_Q2_"; pName += TypeName[Type]; pName += ".eps"; 
  can.SaveAs(pName);
  for(int row=0; row<nRows; row++){
    if(Type==1){
      if(hRes[row]) hRes[row]->Delete();
      if(hRes2[row]) hRes2[row]->Delete();
    }
    for(int col=0; col<nCols; col++){
      int pad = nRows*col+row;
      //if(Type==1 && hbini[pad]) hbini[pad]->Delete();
      for(int isNorm=0; isNorm<3; isNorm++){
	if(Type==0){
	  if(hEff[pad][isNorm]) hEff[pad][isNorm]->Delete();
	  if(hQ2[pad][isNorm]) hQ2[pad][isNorm]->Delete();
	  if(hxini[pad][isNorm]) hxini[pad][isNorm]->Delete();
	}
      }
    }
  }
}
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
// ===  FUNCTION  ============================================================
//         Name:  TPlot::CMS_lumi_v2
//  Description:  
// ===========================================================================
void TPlot::CMS_lumi_v2( TPad* pad, int iPeriod, int iPosX )
{
  //
  // Global variables
  //
  TString cmsText     = "CMS Simulation";
  float cmsTextFont   = 61;  // default is helvetic-bold

  bool writeExtraText = true;
  TString extraText   = "Preliminary";
  float extraTextFont = 52;  // default is helvetica-italics

  // text sizes and text offsets with respect to the top frame
  // in unit of the top margin size
  float lumiTextSize     = 0.6;
  float lumiTextOffset   = 0.2;
  float cmsTextSize      = 0.75;
  float cmsTextOffset    = 0.1;  // only used in outOfFrame version

  float relPosX    = 0.045;
  float relPosY    = 0.035;
  float relExtraDY = 1.2;

  // ratio of "CMS" and extra text size
  float extraOverCmsTextSize  = 0.76;

  TString lumi_13TeV = "20.1 fb^{-1}";
  TString lumi_8TeV  = "19.7 fb^{-1}";
  TString lumi_7TeV  = "5.1 fb^{-1}";
  TString lumi_14TeV = "3000 fb^{-1}, PU = 140";

  bool drawLogo      = false;

  bool outOfFrame    = false;
  if( iPosX/10==0 ) 
  {
    outOfFrame = true;
  }
  int alignY_=3;
  int alignX_=2;
  if( iPosX/10==0 ) alignX_=1;
  if( iPosX==0    ) alignY_=1;
  if( iPosX/10==1 ) alignX_=1;
  if( iPosX/10==2 ) alignX_=2;
  if( iPosX/10==3 ) alignX_=3;
  int align_ = 10*alignX_ + alignY_;

  float H = pad->GetWh();
  float W = pad->GetWw();
  float l = pad->GetLeftMargin();
  float t = pad->GetTopMargin();
  float r = pad->GetRightMargin();
  float b = pad->GetBottomMargin();
  float e = 0.025;

  pad->cd();

  TString lumiText;
  if( iPeriod==1 )
  {
    lumiText += lumi_7TeV;
    lumiText += " (7 TeV)";
  }
  else if ( iPeriod==2 )
  {
    lumiText += lumi_8TeV;
    lumiText += " (8 TeV)";
  }
  else if( iPeriod==3 ) 
  {
    lumiText = lumi_8TeV; 
    lumiText += " (8 TeV)";
    lumiText += " + ";
    lumiText += lumi_7TeV;
    lumiText += " (7 TeV)";
  }
  else if ( iPeriod==4 )
  {
    lumiText += lumi_13TeV;
    lumiText += " (13 TeV)";
  }
  else if ( iPeriod==7 )
  { 
    if( outOfFrame ) lumiText += "#scale[0.85]{";
    lumiText += lumi_13TeV; 
    lumiText += " (13 TeV)";
    lumiText += " + ";
    lumiText += lumi_8TeV; 
    lumiText += " (8 TeV)";
    lumiText += " + ";
    lumiText += lumi_7TeV;
    lumiText += " (7 TeV)";
    if( outOfFrame) lumiText += "}";
  }
  else if ( iPeriod==12 )
  {
    lumiText += "8 TeV";
  }
  else if ( iPeriod==14 )
  {
    lumiText += "14 TeV";  
    //lumiText += lumi_14TeV;
  }


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

  float extraTextSize = extraOverCmsTextSize*cmsTextSize;

  latex.SetTextFont(42);
  latex.SetTextAlign(31); 
  latex.SetTextSize(lumiTextSize*t);    
  latex.DrawLatex(1-r,1-t+lumiTextOffset*t,lumiText);

  if( outOfFrame )
  {
    latex.SetTextFont(cmsTextFont);
    latex.SetTextAlign(11); 
    latex.SetTextSize(cmsTextSize*t);    
    latex.DrawLatex(l,1-t+lumiTextOffset*t,cmsText);
  }

  pad->cd();

  float posX_;
  if( iPosX%10<=1 )
  {
    posX_ =   l + relPosX*(1-l-r);
  }
  else if( iPosX%10==2 )
  {
    posX_ =  l + 0.5*(1-l-r);
  }
  else if( iPosX%10==3 )
  {
    posX_ =  1-r - relPosX*(1-l-r);
  }
  float posY_ = 1-t - relPosY*(1-t-b);
  if( !outOfFrame )
  {
    if( drawLogo )
    {
      posX_ =   l + 0.045*(1-l-r)*W/H;
      posY_ = 1-t - 0.045*(1-t-b);
      float xl_0 = posX_;
      float yl_0 = posY_ - 0.15;
      float xl_1 = posX_ + 0.15*H/W;
      float yl_1 = posY_;
      /*TASImage* CMS_logo = new TASImage("CMS-BW-label.png");*/
      TPad* pad_logo = new TPad("logo","logo", xl_0, yl_0, xl_1, yl_1 );
      pad_logo->Draw();
      pad_logo->cd();
      /*CMS_logo->Draw("X");*/
      pad_logo->Modified();
      pad->cd();
    }
    else
    {
      latex.SetTextFont(cmsTextFont);
      latex.SetTextSize(cmsTextSize*t);
      latex.SetTextAlign(align_);
      latex.DrawLatex(posX_, posY_, cmsText);
      if( writeExtraText ) 
      {
        latex.SetTextFont(extraTextFont);
        latex.SetTextAlign(align_);
        latex.SetTextSize(extraTextSize*t);
        latex.DrawLatex(posX_, posY_- relExtraDY*cmsTextSize*t, extraText);
      }
    }
  }
  else if( writeExtraText )
  {
    if( iPosX==0) 
    {
      posX_ =   l +  relPosX*(1-l-r);
      posY_ =   1-t+lumiTextOffset*t;
    }
    latex.SetTextFont(extraTextFont);
    latex.SetTextSize(extraTextSize*t);
    latex.SetTextAlign(align_);
    latex.DrawLatex(posX_, posY_, extraText);      
  }

  return ;
}       // -----  end of function TPlot::CMS_lumi_v2  -----
Example #24
0
int runPFSortedJets(std::string fileName) {

    // Create file on which histogram(s) can be saved.
    TFile *inFile = new TFile(fileName.c_str(), "READ");
    THStack* partFracs = new THStack("particlestacks", "");

    // Read histograms.
    vector<TProfile*> fractionProfiles;
    for (int idx = 0; idx != 16; ++idx){
        std::stringstream tmpString("");
        tmpString << "a" << idx; 
        // a = all, g = gluonjets, q = quarkjets, lq = low pt quarks, hq = high pt quarks
        fractionProfiles.push_back( (TProfile*) inFile->Get( tmpString.str().c_str()) );
    }
    cout << fractionProfiles.size();

    vector<TH1D*> fractionHists;
    for (int idx = 0; idx != 16; ++idx){
        fractionHists.push_back( fractionProfiles[idx]->ProjectionX("","") );
    }
    vector<TH1D*> PFfracs;
    PFfracs.push_back( (TH1D*) fractionHists[0]->Clone("chf") );
    PFfracs[0]->Add( fractionHists[1] );
    PFfracs[0]->Add( fractionHists[3] );
    PFfracs[0]->Add( fractionHists[4] );
    PFfracs[0]->Add( fractionHists[7] );
    PFfracs[0]->Add( fractionHists[8] );
    PFfracs[0]->Add( fractionHists[13] );
    PFfracs.push_back( (TH1D*) fractionHists[2]->Clone("phf") );
    PFfracs[1]->Add( fractionHists[11] );
    PFfracs.push_back( (TH1D*) fractionHists[5]->Clone("nhf") );
    PFfracs[2]->Add( fractionHists[6] );
    PFfracs[2]->Add( fractionHists[9] );
    PFfracs[2]->Add( fractionHists[10] );
    PFfracs[2]->Add( fractionHists[12] );
    PFfracs.push_back( (TH1D*) fractionHists[14]->Clone("elf+muf") );
    PFfracs.push_back( (TH1D*) fractionHists[15]->Clone("others") );

    PFfracs[0]->SetFillColor(kRed);
    PFfracs[1]->SetFillColor(kBlue);
    PFfracs[2]->SetFillColor(kGreen);
    PFfracs[3]->SetFillColor(kYellow);
    PFfracs[4]->SetFillColor(kCyan);

    for (unsigned i = 0; i != PFfracs.size(); ++i){
        partFracs->Add( PFfracs[i] );
    }

    TCanvas *canv = tdrCanvas("c1",fractionHists[0],12,0,1);//new TCanvas("c1","c1",600,600);

    stackModify(fractionHists[0]);
    partFracs->SetHistogram( fractionHists[0] );
    partFracs->GetHistogram()->SetMaximum(1.01);
    partFracs->GetHistogram()->SetMinimum(-0.01);
    //partFracs->SetFillStyle(4000);

    TLegend *leg = tdrLeg(0.83,0.1,0.98,0.93);
    leg->AddEntry( PFfracs[4], "rest", "f" );
    leg->AddEntry( PFfracs[3], "elf+muf", "f" );
    leg->AddEntry( PFfracs[2], "nhf", "f" );
    leg->AddEntry( PFfracs[1], "phf", "f" );
    leg->AddEntry( PFfracs[0], "chf", "f" );
    leg->SetTextSize(0.045);

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

    latex.SetTextFont(42);
    latex.SetTextAlign(31);
    latex.SetTextSize(0.6*0.07);

    partFracs->Draw("same");
    latex.DrawLatex(0.77,0.85,"Pythia 6 Z2*");

    //fixOverlay();
    //canv->Print("efracs.pdf"); 
    // Done.
    return 0;
}
Example #25
0
void draw1step(int phoetmin, int phoetmax, int jetptmin = 30, int trkptcut = 4) {
  TFile *_file0 = TFile::Open(Form("closure_pbpb_%d_%d_%d.root",phoetmin,phoetmax,jetptmin));
  const static int ncentbins = 4;
  const int yaxismax = 20000;
  float binwidth = 5.000000e-01;
  int centmins[] = {0,20,60,100,140};
  int centmaxs[] = {20,60,100,200,200};
  string cents[] = {"0-10%","10-30%","30-50%","50-100%","70-100%"};
  TH1D * rawff_pbpbmc_recoreco[ncentbins];
  TH1D * rawffue_pbpbmc_recoreco[ncentbins];
  TH1D * rawffjetmix_pbpbmc_recoreco[ncentbins];
  TH1D * rawffjetmixue_pbpbmc_recoreco[ncentbins];
  TH2D * dummy_pbpbsub[ncentbins];
  TLegend * leg_ff_pbpbsub[ncentbins];

  TCanvas * call = new TCanvas("call","",1600,500);
  makeMultiPanelCanvas(call,ncentbins+1,1,0.02,0.0,-6,0.2,0.04);

  for (int icent = 0; icent < ncentbins; icent++) {
    call->cd(2+icent);
    dummy_pbpbsub[icent] = new TH2D(Form("dummy_pbpbsub_%d_%d",centmins[icent],centmaxs[icent]),";#xi;dN/d#xi",1,0.01,4.99,1,0,yaxismax);
    dummy_pbpbsub[icent]->GetXaxis()->SetTitleOffset(0.8);
    dummy_pbpbsub[icent]->GetXaxis()->CenterTitle();
    dummy_pbpbsub[icent]->GetYaxis()->CenterTitle();
    dummy_pbpbsub[icent]->GetXaxis()->SetTitleSize(dummy_pbpbsub[icent]->GetXaxis()->GetTitleSize()*1.4);
    dummy_pbpbsub[icent]->Draw();
    rawff_pbpbmc_recoreco[icent] = (TH1D*)_file0->Get(Form("hgammaffxi_pbpbmc_recoreco_%d_%d",centmins[icent],centmaxs[icent]));
    rawffue_pbpbmc_recoreco[icent] = (TH1D*)_file0->Get(Form("hgammaffxiuemix_pbpbmc_recoreco_%d_%d",centmins[icent],centmaxs[icent]));
    rawffjetmix_pbpbmc_recoreco[icent] = (TH1D*)_file0->Get(Form("hgammaffxijetmix_pbpbmc_recoreco_%d_%d",centmins[icent],centmaxs[icent]));
    rawffjetmixue_pbpbmc_recoreco[icent] = (TH1D*)_file0->Get(Form("hgammaffxijetmixue_pbpbmc_recoreco_%d_%d",centmins[icent],centmaxs[icent]));
    rawffjetmix_pbpbmc_recoreco[icent]->SetMarkerColor(kBlue);
    rawffue_pbpbmc_recoreco[icent]->SetMarkerStyle(24);
    rawffjetmixue_pbpbmc_recoreco[icent]->SetMarkerColor(kBlue);
    rawffjetmixue_pbpbmc_recoreco[icent]->SetMarkerStyle(24);
    rawff_pbpbmc_recoreco[icent]->Draw("same");
    rawffjetmix_pbpbmc_recoreco[icent]->Draw("same");
    rawffue_pbpbmc_recoreco[icent]->Draw("same");
    rawffjetmixue_pbpbmc_recoreco[icent]->Draw("same");


    if(icent==0)
    {
      leg_ff_pbpbsub[icent] = new TLegend(0.03,0.52,0.3,0.92);
    }
    else
    {
      leg_ff_pbpbsub[icent] = new TLegend(0,0.697,0.27,0.92);
    }
    leg_ff_pbpbsub[icent]->SetTextSize(0.05*1.3);
    leg_ff_pbpbsub[icent]->SetFillColor(0);
    leg_ff_pbpbsub[icent]->SetFillStyle(0);
    leg_ff_pbpbsub[icent]->SetTextFont(42);
    if(icent==0)
    {
      leg_ff_pbpbsub[icent]->AddEntry(rawff_pbpbmc_recoreco[icent],"Raw FF","p");
      leg_ff_pbpbsub[icent]->AddEntry(rawffjetmix_pbpbmc_recoreco[icent],"Jet Mix FF","p");
      leg_ff_pbpbsub[icent]->AddEntry(rawffue_pbpbmc_recoreco[icent],"Raw UE FF","p");
      leg_ff_pbpbsub[icent]->AddEntry(rawffjetmixue_pbpbmc_recoreco[icent],"Jet Mix UE FF","p");
    }
    else if(icent==1)
    {
      leg_ff_pbpbsub[icent]->AddEntry(rawff_pbpbmc_recoreco[icent],Form("trk p_{T}>%d GeV, R < 0.3",trkptcut),"");
      leg_ff_pbpbsub[icent]->AddEntry(rawff_pbpbmc_recoreco[icent],Form("%d>#gamma p_{T}>%d GeV",phoetmin,phoetmax),"");
    }
    else if(icent==2)
    {
      leg_ff_pbpbsub[icent]->AddEntry(rawff_pbpbmc_recoreco[icent],"0.3 < |#eta^{jet}| < 1.6","");
      leg_ff_pbpbsub[icent]->AddEntry(rawff_pbpbmc_recoreco[icent],Form("p_{T}^{jet} > %d GeV",jetptmin),"");
    }
    else if(icent==3)
    {
      leg_ff_pbpbsub[icent]->AddEntry(rawff_pbpbmc_recoreco[icent],"Pythia+Hydjet","");
      leg_ff_pbpbsub[icent]->AddEntry(rawff_pbpbmc_recoreco[icent],"#sigma_{i#eta#eta}<0.10","");
    }
    leg_ff_pbpbsub[icent]->AddEntry(rawff_pbpbmc_recoreco[icent],Form("%s",cents[icent].data()),"");
    leg_ff_pbpbsub[icent]->Draw();
  }

  call->cd(1);
  TH2D * axis_dummy = new TH2D("axis_dummy","",1,0.01,4.99,1,0,yaxismax);
  gStyle->SetFrameLineColor(0);
  axis_dummy->UseCurrentStyle();
  axis_dummy->Draw("FB BB A");

  TLatex * ldndxi = new TLatex(0.4,0.5,"dN/d#xi Raw");
  ldndxi->SetTextSize(ldndxi->GetTextSize()*1.2);
  ldndxi->SetNDC();
  ldndxi->SetTextAngle(90);

  int labelspace = yaxismax / 4;
  const int nlabels = yaxismax/labelspace;
  TLatex * laxis[nlabels];
  for (int ilatex = 0; ilatex < nlabels; ilatex++) {
    laxis[ilatex] = new TLatex(2.,ilatex*labelspace-0.1,Form("%d",ilatex*labelspace));
    laxis[ilatex]->SetTextSize(laxis[ilatex]->GetTextSize()*1.2);
    laxis[ilatex]->Draw();
  }
  ldndxi->Draw();
  call->SaveAs(Form("rawff_%d_%d_jetmixff_jetpt%d_pbpbmc_recoreco.png",phoetmin,phoetmax,jetptmin));
}
void make1DLimit(TString combine_dir,TString type= "WH",bool blind=true){
  //TString combine_dir = "test_runSusyHgg/signalInj_sms_ChiWH_0_175/";
  //WH
  wh_limits.push_back(wh_125);
  wh_limits.push_back(wh_150);
  wh_limits.push_back(wh_175);
  wh_limits.push_back(wh_200);
  //HH
  hh_limits.push_back(hh_125);
  hh_limits.push_back(hh_150);
  hh_limits.push_back(hh_175);
  hh_limits.push_back(hh_200);

  TGraph obser( (200-125)/25 );
  TGraph graph( (200-125)/25 );
  TGraphAsymmErrors error( (200-125)/25 );
  TGraphAsymmErrors error2S( (200-125)/25 );

  TGraph obser_r( (200-125)/25 );
  TGraph graph_r( (200-125)/25 );
  TGraphAsymmErrors error_r( (200-125)/25 );
  TGraphAsymmErrors error_r2S( (200-125)/25 );
  
  TGraphErrors* theo = 0;
  if(type=="WH") theo = getTheoXSec("xsecs/CharginoNeutralino.txt");
  else theo = getTheoXSec("xsecs/Higgsino_ElectroHiggs.txt");
  //else theo = getTheoXSec("/home/amott/HggApp/SusyHgg/xsecs/Higgsino.txt");

  for(int m=125;m<=200;m+=25) {
    int i=(m-125)/25;
    TFile limit_file(Form("%s/higgsCombineChi%s_0_%d.Asymptotic.mH120.root",combine_dir.Data(),type.Data(),m) );
    TTree *limit_tree = (TTree*)limit_file.Get("limit");
    TTreeFormula limit_form("get_limit","limit",limit_tree);
    
    float down_2s = -1;
    float down = -1;
    float exp = -1;
    float up = -1;
    float up_2s = -1;
    float obs = -1;

    if( type == "WH" )
      {
	down_2s = wh_limits.at(i)[0];
	down = wh_limits.at(i)[1];
	exp = wh_limits.at(i)[2];
	up = wh_limits.at(i)[3];
	up_2s = wh_limits.at(i)[4];
	obs = wh_limits.at(i)[5];
      }
    else if ( type == "HH")
      {
	down_2s = hh_limits.at(i)[0];
	down = hh_limits.at(i)[1];
	exp = hh_limits.at(i)[2];
	up = hh_limits.at(i)[3];
	up_2s = hh_limits.at(i)[4];
	obs = hh_limits.at(i)[5];
      }
    else
      {
	std::cerr << "UNRECOGNIZED OPTION!!! QUITTING" << std::endl;
      }
    
    if(i==0) m+=5; //first point is actually at m=130
    graph.SetPoint(i,float(m), exp);
    error.SetPoint(i,float(m), exp);
    error2S.SetPoint(i, float(m), exp);
    error.SetPointError(i, 0, 0, exp-down, up-exp);
    error2S.SetPointError(i, 0 , 0 , exp-down_2s, up_2s-exp);
  
    graph_r.SetPoint(i,float(m),exp/theo->Eval(m));
    error_r.SetPoint(i,float(m),exp/theo->Eval(m));
    error_r2S.SetPoint(i,float(m),exp/theo->Eval(m));
    error_r.SetPointError(i,0,0,(exp-down)/theo->Eval(m),(up-exp)/theo->Eval(m));
    error_r2S.SetPointError(i, 0, 0, (exp-down_2s)/theo->Eval(m), (up_2s-exp)/theo->Eval(m) );
    
  
    obser.SetPoint(i,float(m),obs);
    obser_r.SetPoint(i,float(m),obs/theo->Eval(m));
    if(i==0) m-=5;
  }


    TCanvas cv;
    cv.SetLogy();
    cv.SetGrid(1,1);
    theo->SetMaximum(1e2);
    theo->SetMinimum(1e-2);
    theo->GetYaxis()->SetLabelSize(0.05);
    theo->GetYaxis()->SetTitleSize(0.06);
    theo->GetYaxis()->SetTitleOffset(0.8);
    theo->GetYaxis()->SetTitle("95% CL #sigma upper limit (pb)");
    theo->GetXaxis()->SetTitle("m_{chargino} (GeV)");
    if(type=="HH") theo->GetXaxis()->SetTitle("m_{neutralino} (GeV)");
    theo->SetFillColor(kBlue);
    theo->SetLineStyle(kDotted);
    theo->SetLineWidth(2);
    
    error.SetMaximum(1e2);
    error.SetMinimum(1e-2);
    error.GetYaxis()->SetLabelSize(0.04);
    error.GetYaxis()->SetTitleSize(0.06);
    error.GetYaxis()->SetTitleOffset(0.8);
    error.GetXaxis()->SetLabelSize(0.04);
    error.GetXaxis()->SetTitleSize(0.05);
    error.GetXaxis()->SetTitleOffset(0.9);
    error.GetYaxis()->SetTitle("95% CL #sigma upper limit (pb)");
    error.GetXaxis()->SetTitle("m_{chargino} (GeV)");
    if(type=="HH") error.GetXaxis()->SetTitle("m_{neutralino} (GeV)");
    error.SetFillColor(kGreen);
    error2S.SetFillColor(kYellow);
    error2S.SetTitle("");
    error.SetTitle("");
    error.Draw("A3");
    error2S.Draw("3SAME");
    error.Draw("3");
    
    theo->SetTitle("");
    theo->Draw("3C");

    graph.SetLineStyle(kDashed);
    graph.SetLineWidth(2.0);
    graph.SetTitle("");
    graph.Draw("C");

    obser.SetLineStyle(1);
    obser.SetLineWidth(2.0);
    obser.SetTitle("");
    if(!blind) obser.Draw("C");

    TLegend leg(0.65,0.65,0.89,0.89);
    leg.SetFillColor(0);
    leg.SetBorderSize(0);
    leg.AddEntry(&graph,"expected","l");
    leg.AddEntry(&error,"expected #pm1#sigma","F");
    leg.AddEntry(&error2S,"expected #pm2#sigma","F");
    leg.AddEntry(theo,"theoretical","f");
    if(!blind)     leg.AddEntry(&obser,"observed","l");

    leg.Draw("SAME");

    TLatex latex;
    latex.SetNDC();
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);    
    float extraTextSize = extraOverCmsTextSize*cmsSize;
    latex.SetTextFont(lumifont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(cmsSize);    
    latex.DrawLatex(lumix, lumiy,lumiText);
    
    latex.SetTextFont(cmsTextFont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(cmsSize);
    latex.DrawLatex(cmsx, cmsy, CMSText);
    
    latex.SetTextFont(extraTextFont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(extraTextSize);
    latex.DrawLatex(extrax, extray, extraText);

    TString infix=(blind ? "" : "_OBS");
    cv.SaveAs(combine_dir+"/expected_exclusion_"+type+"_1D"+infix+"_v2.png");
    cv.SaveAs(combine_dir+"/expected_exclusion_"+type+"_1D"+infix+"_v2.pdf");
    cv.SaveAs(combine_dir+"/expected_exclusion_"+type+"_1D"+infix+"_v2.C");

    error_r.SetMaximum(1e2);
    error_r.SetMinimum(1e-2);

    error_r.SetTitle("");
    error_r.GetYaxis()->SetLabelSize(0.04);
    error_r.GetYaxis()->SetTitleSize(0.06);
    error_r.GetYaxis()->SetTitleOffset(0.8);
    error_r.GetXaxis()->SetLabelSize(0.04);
    error_r.GetXaxis()->SetTitleSize(0.05);
    error_r.GetXaxis()->SetTitleOffset(0.9);
    error_r.GetYaxis()->SetTitle("#sigma_{95%}/#sigma_{NLO}");
    if(type=="HH") error_r.GetXaxis()->SetTitle("m_{neutralino} (GeV)");
    else error_r.GetXaxis()->SetTitle("m_{chargino} (GeV)");
    error_r.SetFillColor(kGreen);
    error_r2S.SetFillColor(kYellow);
    error_r2S.SetTitle("");
    error_r.Draw("A3");
    error_r2S.Draw("3SAME");
    error_r.Draw("3SAME");

    graph_r.SetLineStyle(kDashed);
    graph_r.SetLineWidth(2);
    graph_r.SetTitle("");
    graph_r.Draw("C");

    TLine l(125,1,205,1);
    l.SetLineWidth(3);
    l.SetLineColor(kBlue);
    //l.Draw("SAME");

    obser_r.SetLineWidth(2);
    if(!blind) obser_r.Draw("C");
    leg.Draw("SAME");

    //lbl.SetY(0.20);
    //leg.SetY1NDC(0.28);
    //leg.SetY2NDC(0.43);

    //prelim.Draw();
    //lbl.Draw();
    latex.SetTextFont(lumifont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(cmsSize);    
    latex.DrawLatex(lumix, lumiy,lumiText);
    
    latex.SetTextFont(cmsTextFont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(cmsSize);
    latex.DrawLatex(cmsx, cmsy, CMSText);
    
    latex.SetTextFont(extraTextFont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(extraTextSize);
    latex.DrawLatex(extrax, extray, extraText);
    
    cv.SaveAs(combine_dir+"/expected_exclusion_ratio_"+type+"_1D"+infix+"_v2.png");
    cv.SaveAs(combine_dir+"/expected_exclusion_ratio_"+type+"_1D"+infix+"_v2.pdf");
    cv.SaveAs(combine_dir+"/expected_exclusion_ratio_"+type+"_1D"+infix+"_v2.C");
}
Example #27
0
void CMS_lumi( TPad* pad, int iPeriod, int iPosX )
{            
  bool outOfFrame    = false;
  if( iPosX/10==0 ) 
    {
      outOfFrame = true;
    }
  int alignY_=3;
  int alignX_=2;
  if( iPosX/10==0 ) alignX_=1;
  if( iPosX==0    ) alignX_=1;
  if( iPosX==0    ) alignY_=1;
  if( iPosX/10==1 ) alignX_=1;
  if( iPosX/10==2 ) alignX_=2;
  if( iPosX/10==3 ) alignX_=3;
  //if( iPosX == 0  ) relPosX = 0.12;
  if( iPosX == 0  ) relPosX = 0.15; // KYO
  int align_ = 10*alignX_ + alignY_;

  float H = pad->GetWh();
  float W = pad->GetWw();
  float l = pad->GetLeftMargin();
  float t = pad->GetTopMargin();
  float r = pad->GetRightMargin();
  float b = pad->GetBottomMargin();
  //  float e = 0.025;

  pad->cd();

  TString lumiText;
  if( iPeriod==0 )
    {
      lumiText += lumi_502TeV;
      lumiText += " (pPb 5.02 TeV)";
    }
   
  cout << lumiText << endl;

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

  float extraTextSize = extraOverCmsTextSize*cmsTextSize;

  latex.SetTextFont(42);
  latex.SetTextAlign(31); 
  latex.SetTextSize(lumiTextSize*t);    
  latex.DrawLatex(1-r,1-t+lumiTextOffset*t,lumiText);

  if( outOfFrame )
    {
      latex.SetTextFont(cmsTextFont);
      latex.SetTextAlign(11); 
      latex.SetTextSize(cmsTextSize*t);    
      latex.DrawLatex(l,1-t+lumiTextOffset*t,cmsText);
    }
  
  pad->cd();

  float posX_=0;
  if( iPosX%10<=1 )
    {
      posX_ =   l + relPosX*(1-l-r);
    }
  else if( iPosX%10==2 )
    {
      posX_ =  l + 0.5*(1-l-r);
    }
  else if( iPosX%10==3 )
    {
      posX_ =  1-r - relPosX*(1-l-r);
    }
  float posY_ = 1-t - relPosY*(1-t-b);
  if( !outOfFrame )
    {
      if( drawLogo )
	{
	  posX_ =   l + 0.045*(1-l-r)*W/H;
	  posY_ = 1-t - 0.045*(1-t-b);
	  float xl_0 = posX_;
	  float yl_0 = posY_ - 0.15;
	  float xl_1 = posX_ + 0.15*H/W;
	  float yl_1 = posY_;
	  TASImage* CMS_logo = new TASImage("CMS-BW-label.png");
	  TPad* pad_logo = new TPad("logo","logo", xl_0, yl_0, xl_1, yl_1 );
	  pad_logo->Draw();
	  pad_logo->cd();
	  CMS_logo->Draw("X");
	  pad_logo->Modified();
	  pad->cd();
	}
      else
	{
	  latex.SetTextFont(cmsTextFont);
	  latex.SetTextSize(cmsTextSize*t);
	  latex.SetTextAlign(align_);
	  latex.DrawLatex(posX_, posY_, cmsText);
	  if( writeExtraText ) 
	    {
	      latex.SetTextFont(extraTextFont);
	      latex.SetTextAlign(align_);
	      latex.SetTextSize(extraTextSize*t);
	      latex.DrawLatex(posX_, posY_- relExtraDY*cmsTextSize*t, extraText);
	    }
	}
    }
  else if( writeExtraText )
    {
      if( iPosX==0) 
	{
	  posX_ =   l +  relPosX*(1-l-r);
	  posY_ =   1-t+lumiTextOffset*t;
	}
      latex.SetTextFont(extraTextFont);
      latex.SetTextSize(extraTextSize*t);
      latex.SetTextAlign(align_);
      latex.DrawLatex(posX_, posY_, extraText);      
    }
  return;
}
Example #28
0
void CMSLumi(TCanvas *& canvas, const Int_t iPosX, const Double_t inlumi){
  canvas->cd();
  
  TString cmsText      = "CMS";
  Double_t cmsTextFont = 61;  // default is helvetic-bold
  
  Bool_t writeExtraText  = true;
  TString extraText      = "Preliminary";
  Double_t extraTextFont = 52;  // default is helvetica-italics

  TString lumiText = Form("%1.1f fb^{-1} (13 TeV)", inlumi);
  
  // text sizes and text offsets with respect to the top frame
  // in unit of the top margin size
  Double_t lumiTextSize     = 0.6;
  Double_t lumiTextOffset   = 0.1;
  Double_t cmsTextSize      = 0.75;
  Double_t cmsTextOffset    = 0.05;  // only used in outOfFrame version

  Double_t relPosX    = 0.003;//0.045;
  Double_t relPosY    = 0.035;
  Double_t relExtraDY = 1.2;
 
  // ratio of "CMS" and extra text size
  Double_t extraOverCmsTextSize  = 0.76;
 
  Bool_t outOfFrame    = false;
  if ( iPosX/10 == 0 ) {
    outOfFrame = true;
  }

  Int_t alignY_=3;
  Int_t alignX_=2;
  if (iPosX/10 == 0) {alignX_ = 1;}
  if (iPosX == 0)    {alignY_ = 1;}
  if (iPosX/10 == 1) {alignX_ = 1;}
  if (iPosX/10 == 2) {alignX_ = 2;}
  if (iPosX/10 == 3) {alignX_ = 3;}
  Int_t align_ = 10*alignX_ + alignY_;

  Double_t H = canvas->GetWh();
  Double_t W = canvas->GetWw();
  Double_t l = canvas->GetLeftMargin();
  Double_t t = canvas->GetTopMargin();
  Double_t r = canvas->GetRightMargin();
  Double_t b = canvas->GetBottomMargin();
  Double_t e = 0.025;

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

  Double_t extraTextSize = extraOverCmsTextSize*cmsTextSize;

  latex.SetTextFont(42);
  latex.SetTextAlign(31); 
  latex.SetTextSize(lumiTextSize*t);    
  latex.DrawLatex(1-r+0.08,1-t+lumiTextOffset*t+0.01,lumiText);

  if (outOfFrame) {
    latex.SetTextFont(cmsTextFont);
    latex.SetTextAlign(11); 
    latex.SetTextSize(cmsTextSize*t);    
    latex.DrawLatex(l,1-t+cmsTextOffset*t,cmsText);
  }
  
  Double_t posX_;
  if (iPosX%10 <= 1) {
    posX_ =   l + relPosX*(1-l-r);
  }
  else if (iPosX%10 == 2) {
    posX_ =  l + 0.5*(1-l-r);
  }
  else if (iPosX%10 == 3) {
    posX_ =  1-r - relPosX*(1-l-r);
  }

  Double_t posY_ = 1-t - relPosY*(1-t-b);

  if (!outOfFrame) {
    latex.SetTextFont(cmsTextFont);
    latex.SetTextSize(cmsTextSize*t);
    latex.SetTextAlign(align_);
    latex.DrawLatex(posX_, posY_, cmsText);
    
    if (writeExtraText) {
      latex.SetTextFont(extraTextFont);
      latex.SetTextAlign(align_);
      latex.SetTextSize(extraTextSize*t);
      latex.DrawLatex(posX_, posY_- relExtraDY*cmsTextSize*t, extraText);
    }
  }
  
  else if (outOfFrame && writeExtraText){
    if (iPosX == 0) {
	posX_ = l +  relPosX*(1-l-r)+0.05;
	posY_ = 1-t+lumiTextOffset*t;
    }
    latex.SetTextFont(extraTextFont);
    latex.SetTextSize(extraTextSize*t);
    latex.SetTextAlign(align_);
    latex.DrawLatex(posX_, posY_, extraText);      
  } 
}// end Style::CMSLumi
Example #29
0
void 
CMS_lumi( TPad* pad, bool isSIM, int iPosX )
{   
  int iPeriod=4;
  lumi_8TeV="19.7 fb^{-1}";
  //lumi_8TeV="";
  if(isSIM==true) extraText="Simulation";
  if(isSIM==false)extraText="Preliminary";
  writeExtraText=true;         
  bool outOfFrame    = false;
  if( iPosX/10==0 ) 
    {
      outOfFrame = true;
    }
  int alignY_=3;
  int alignX_=2;
  if( iPosX/10==0 ) alignX_=1;
  if( iPosX==0    ) alignY_=1;
  if( iPosX/10==1 ) alignX_=1;
  if( iPosX/10==2 ) alignX_=2;
  if( iPosX/10==3 ) alignX_=3;
  int align_ = 10*alignX_ + alignY_;

  float H = pad->GetWh();
  float W = pad->GetWw();
  float l = pad->GetLeftMargin();
  float t = pad->GetTopMargin();
  float r = pad->GetRightMargin();
  float b = pad->GetBottomMargin();
  float e = 0.025;

  pad->cd();

  TString lumiText;
  if( iPeriod==1 )
    {
      lumiText += lumi_7TeV;
      lumiText += " (7 TeV)";
    }
  else if ( iPeriod==12 )
    {
      lumiText += lumi_8TeV;
      lumiText += " (8 TeV)";
    }
  else if( iPeriod==3 ) 
    {
      lumiText = lumi_8TeV; 
      lumiText += " (8 TeV)";
      lumiText += " + ";
      lumiText += lumi_7TeV;
      lumiText += " (7 TeV)";
    }
  else if ( iPeriod==4 )
    {
      lumiText += lumi_13TeV;
      lumiText += "13 TeV";
      //lumiText += " (13 TeV)";
    }
  else if ( iPeriod==7 )
    { 
      if( outOfFrame ) lumiText += "#scale[0.85]{";
      lumiText += lumi_13TeV; 
      lumiText += " (13 TeV)";
      lumiText += " + ";
      lumiText += lumi_8TeV; 
      lumiText += " (8 TeV)";
      lumiText += " + ";
      lumiText += lumi_7TeV;
      lumiText += " (7 TeV)";
      if( outOfFrame) lumiText += "}";
    }
  else if ( iPeriod==12 )
    {
      lumiText += "8 TeV";
    }
   
  std::cout << lumiText << std::endl;

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

  float extraTextSize = extraOverCmsTextSize*cmsTextSize;

  latex.SetTextFont(42);
  latex.SetTextAlign(31); 
  latex.SetTextSize(lumiTextSize*t);    
  latex.DrawLatex(1-r,1-t+lumiTextOffset*t,lumiText);

  if( outOfFrame )
    {
      latex.SetTextFont(cmsTextFont);
      latex.SetTextAlign(11); 
      latex.SetTextSize(cmsTextSize*t);    
      latex.DrawLatex(l,1-t+lumiTextOffset*t,cmsText);
    }
  
  pad->cd();

  float posX_;
  if( iPosX%10<=1 )
    {
      posX_ =   l + relPosX*(1-l-r);
    }
  else if( iPosX%10==2 )
    {
      posX_ =  l + 0.5*(1-l-r);
    }
  else if( iPosX%10==3 )
    {
      posX_ =  1-r - relPosX*(1-l-r);
    }
  float posY_ = 1-t - relPosY*(1-t-b);
  if( !outOfFrame )
    {
      if( drawLogo )
	{
	  posX_ =   l + 0.045*(1-l-r)*W/H;
	  posY_ = 1-t - 0.045*(1-t-b);
	  float xl_0 = posX_;
	  float yl_0 = posY_ - 0.15;
	  float xl_1 = posX_ + 0.15*H/W;
	  float yl_1 = posY_;
	  //TASImage* CMS_logo = new TASImage("CMS-BW-label.png");
	  TPad* pad_logo = new TPad("logo","logo", xl_0, yl_0, xl_1, yl_1 );
	  pad_logo->Draw();
	  pad_logo->cd();
	  //CMS_logo->Draw("X");
	  pad_logo->Modified();
	  pad->cd();
	}
      else
	{
	  latex.SetTextFont(cmsTextFont);
	  latex.SetTextSize(cmsTextSize*t);
	  latex.SetTextAlign(align_);
	  latex.DrawLatex(posX_, posY_, cmsText);
	  if( writeExtraText ) 
	    {
	      latex.SetTextFont(extraTextFont);
	      latex.SetTextAlign(align_);
	      latex.SetTextSize(extraTextSize*t);
	      latex.DrawLatex(posX_, posY_- relExtraDY*cmsTextSize*t, extraText);
	    }
	}
    }
  else if( writeExtraText )
    {
      if( iPosX==0) 
	{
	  posX_ =   l +  relPosX*(1-l-r)+0.05;
	  posY_ =   1-t+lumiTextOffset*t;
	}
      latex.SetTextFont(extraTextFont);
      latex.SetTextSize(extraTextSize*t);
      latex.SetTextAlign(align_);
      latex.DrawLatex(posX_, posY_, extraText);      
    }
  return;
}
void MakeSignificancePlot( int option = 0) {

  int NBins = 15;
  if (option == 1) NBins = 20;

  Double_t x[NBins];  
  Double_t y[NBins];
  x[0] = -0.5;
  for (int i=1; i<NBins; ++i)  x[i] = i-1;

  if (option == 0) {
    //use significance computed from log likelihood
    
    // //**************************
    // //2.3+4.0 dataset
    // //**************************
    // //highPt Category
    // y[0] = -1000;
    // y[1] = 1.1;
    // y[2] = 0.9;
    // y[3] = 0;
    // y[4] = -0.7;
    // y[5] = 0.8;
    // y[6] = 1.3;
    // y[7] = 0.8;
    // y[8] = 0.7;
    // //hbb category  
    // y[9] = 0.6;
    // //highres category
    // y[10] = -0.4;
    // y[11] = 1.1;
    // y[12] = 0.8;
    // y[13] = 1.7;
    // y[14] = 0.7;

   // //**************************
   //  //2.3+12.9 dataset
   //  //**************************
   //  //highPt Category
   //  y[0] = -1000;
   //  y[1] = 2.5;
   //  y[2] = 0.2;
   //  y[3] = -1.4;
   //  y[4] = -0.4;
   //  y[5] = -1.6;
   //  y[6] = 1.9;
   //  y[7] = 0.6;
   //  y[8] = 0.8;
   //  //hbb category  
   //  y[9] = 1.0;
   //  //highres category
   //  y[10] = -0.2;
   //  y[11] = 1.7;
   //  y[12] = 0.0;
   //  y[13] = 0.5;
   //  y[14] = 0.2;

    //*********************************************
    //full 2016 dataset: 36.8 /fb dataset
    //*********************************************
    //highPt Category
    y[0] = -1000;
    y[1] = 0.7;
    y[2] = -1.4;
    y[3] = -0.9;
    y[4] = 0.4;
    y[5] = 0.6;
    y[6] = 1.6;
    y[7] = 0.1;
    y[8] = -0.0;
    //hbb category  
    y[9] = 1.0;
    //highres category
    y[10] = -0.2;
    y[11] = 0.1;
    y[12] = -0.6;
    y[13] = 0.2;
    y[14] = 0.2;

  } else if (option == 1) {
    //use fitted signal yield / uncertainty
    
    //highPt Category
    y[0] = -1000;
    y[1] = 2.0/2.2;
    y[2] = 2.0/2.5;
    y[3] = 0;
    y[4] = -8.6/11.4;
    y[5] = 3.9/5.3;
    y[6] = 4.3/3.5;
    y[7] = 3.9/4.8;
    y[8] = 1.9/2.7;
    //hbb category  
    y[9] = 1.9/3.3;
    //highres category
    y[10] = -8.8/20.3;
    y[11] = 2.7/2.3;
    y[12] = 2.7/3.7;
    y[13] = 21.3/12.2;
    y[14] = 3.5/4.4;
    //low res category
    y[15] = -3.6/8.6;
    y[16] = 0.5/0.5;
    y[17] = 0.9/1.3;
    y[18] = 7.2/4.6;
    y[19] = 1.4/1.9;
  }


  TCanvas *cv = new TCanvas("cv","cv",800,600);
  cv->SetBottomMargin(0.115);
  TH1F *hist = 0;
  if (option == 0) hist = new TH1F("hist",";Bin Number; Observed Significance;", 14, -0.5, 13.5);
  else if (option == 1) hist = new TH1F("hist",";Bin Number; Fitted Signal Yield / Uncertainty;", 19, -0.5, 18.5);
  // else if (option == 1) hist = new TH1F("hist",";Bin Number; Fitted N_{signal} / #sigma_{N_{signal}};", 19, -0.5, 18.5);
  
  hist->GetXaxis()->SetBinLabel(1, "Bin 0");
  hist->GetXaxis()->SetBinLabel(2, "Bin 1");
  hist->GetXaxis()->SetBinLabel(3, "Bin 2");
  hist->GetXaxis()->SetBinLabel(4, "Bin 3");
  hist->GetXaxis()->SetBinLabel(5, "Bin 4");
  hist->GetXaxis()->SetBinLabel(6, "Bin 5");
  hist->GetXaxis()->SetBinLabel(7, "Bin 6");
  hist->GetXaxis()->SetBinLabel(8, "Bin 7");
  hist->GetXaxis()->SetBinLabel(9, "Bin 8");
  hist->GetXaxis()->SetBinLabel(10, "Bin 9");
  hist->GetXaxis()->SetBinLabel(11, "Bin 10");
  hist->GetXaxis()->SetBinLabel(12, "Bin 11");
  hist->GetXaxis()->SetBinLabel(13, "Bin 12");
  hist->GetXaxis()->SetBinLabel(14, "Bin 13");
  hist->GetXaxis()->LabelsOption("v");
  hist->SetStats(0);
  hist->SetMaximum(5);
  hist->SetMinimum(-8.0);
  hist->GetYaxis()->SetTitleSize(0.05);
  hist->GetYaxis()->SetTitleOffset(0.85);
  hist->GetYaxis()->SetLabelSize(0.045);
  hist->GetXaxis()->SetTitle("");
  hist->GetXaxis()->SetTitleSize(0.05);
  hist->GetXaxis()->SetTitleOffset(0.85);
  hist->GetXaxis()->SetLabelSize(0.05);
  hist->Draw();


  TGraph *gr =0;
  gr = new TGraphAsymmErrors(NBins,x,y);
  gr->SetTitle("");
  //gr->Draw("psame");
  gr->SetLineWidth(2);
  gr->SetMarkerStyle(20);
  gr->SetMarkerSize(1.5);
  // gr->GetXaxis()->SetTitle("Bin Number");
  // gr->GetYaxis()->SetTitle("Observed Significance");
  // gr->GetXaxis()->SetTitleSize(0.05);
  // gr->GetXaxis()->SetTitleOffset(0.8);
  // gr->GetYaxis()->SetTitleSize(0.05);
  // gr->GetYaxis()->SetTitleOffset(0.8);
  // gr->GetYaxis()->SetRangeUser(-7,5);

  TBox *TwoSigmaBand = 0;
  TBox *OneSigmaBand = 0;
  TLine *l = 0;

  if (option == 0) {
    TwoSigmaBand = new TBox(-0.48, -2, 13.5, 2);
    OneSigmaBand = new TBox(-0.48, -1, 13.5, 1);
    l = new TLine(-0.48,0,13.5,0);
  } else if (option == 1) {
    TwoSigmaBand = new TBox(-0.48, -2, 18.5, 2);
    OneSigmaBand = new TBox(-0.48, -1, 18.5, 1);
    l = new TLine(-0.48,0,18.5,0);
  }

  TwoSigmaBand->SetFillColor(kYellow);
  //box->SetFillStyle(3001);
  TwoSigmaBand->Draw("same");   
  OneSigmaBand->SetFillColor(kGreen);
  //box->SetFillStyle(3001);
  OneSigmaBand->Draw("same");
  
  l->SetLineWidth(2);
  l->SetLineColor(kBlue);
  l->Draw();

  gr->Draw("P");
  gPad->Update();
  gPad->RedrawAxis();

  TLine ll;
  ll.DrawLine(gPad->GetUxmin(), gPad->GetUymax(), gPad->GetUxmax(), gPad->GetUymax());
  ll.DrawLine(gPad->GetUxmax(), gPad->GetUymin(), gPad->GetUxmax(), gPad->GetUymax());

  TLatex *tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSize(0.040);
  tex->SetTextFont(42);
  tex->SetTextColor(kBlack);
  tex->DrawLatex(0.7, 0.92, "35.9 fb^{-1} (13 TeV)");
  //tex->DrawLatex(0.4, 0.92, "Razor H#rightarrow#gamma#gamma Search");
  tex->Draw();
  
  TLatex *CMSLabel = new TLatex();
  CMSLabel->SetNDC();
  CMSLabel->SetTextSize(0.050);
  CMSLabel->SetTextFont(42);
  CMSLabel->SetTextColor(kBlack);
  CMSLabel->DrawLatex(0.1,0.92,"#bf{CMS}");
  CMSLabel->SetTextSize(0.045);
  //CMSLabel->DrawLatex(0.19,0.92,"Preliminary");
  CMSLabel->Draw();


  TLine *l1 = new TLine(7.5,-8,7.5,5);
  l1->SetLineWidth(2);
  l1->SetLineStyle(2);
  l1->SetLineColor(kBlack);
  l1->Draw();

  TLine *l2 = new TLine(8.5,-8,8.5,5);
  l2->SetLineWidth(2);
  l2->SetLineStyle(2);
  l2->SetLineColor(kBlack);
  l2->Draw();

  if (option == 1) {
    TLine *l3 = new TLine(13.5,-8,13.5,5);
    l3->SetLineWidth(2);
    l3->SetLineStyle(2);
    l3->SetLineColor(kBlack);
    l3->Draw();
  }

  TLatex *HighPtLabel = new TLatex();
  HighPtLabel->SetNDC();
  HighPtLabel->SetTextAngle(90);
  HighPtLabel->SetTextSize(0.035);
  HighPtLabel->SetTextFont(42);
  HighPtLabel->SetTextColor(kBlack);
  HighPtLabel->DrawLatex(0.34,0.13,"#bf{HighPt Category}");
  HighPtLabel->Draw();

  TLatex *HbbLabel = new TLatex();
  HbbLabel->SetNDC();
  HbbLabel->SetTextAngle(90);
  HbbLabel->SetTextSize(0.035);
  HbbLabel->SetTextFont(42);
  HbbLabel->SetTextColor(kBlack);
  if (option == 0) HbbLabel->DrawLatex(0.59,0.13,"#bf{H(#gamma#gamma)-HZ(bb) Category}");
  else if (option ==1) HbbLabel->DrawLatex(0.465,0.13,"#bf{H(#gamma#gamma)-Z(bb) Category}");
  HbbLabel->Draw();

  if (option == 0) {
    TLatex *HighResLowResLabel = new TLatex();
    HighResLowResLabel->SetNDC();
    HighResLowResLabel->SetTextAngle(90);
    HighResLowResLabel->SetTextSize(0.035);
    HighResLowResLabel->SetTextFont(42);
    HighResLowResLabel->SetTextColor(kBlack);
    HighResLowResLabel->DrawLatex(0.730,0.13,"#bf{HighRes/LowRes}");
    HighResLowResLabel->DrawLatex(0.760,0.20,"#bf{Category}");
    HighResLowResLabel->Draw();
  
  } else if (option == 1) {
    TLatex *HighResLabel = new TLatex();
    HighResLabel->SetNDC();
    HighResLabel->SetTextAngle(90);
    HighResLabel->SetTextSize(0.035);
    HighResLabel->SetTextFont(42);
    HighResLabel->SetTextColor(kBlack);
    HighResLabel->DrawLatex(0.60,0.13,"#bf{HighRes Category}");
    HighResLabel->Draw();
    
    TLatex *LowResLabel = new TLatex();
    LowResLabel->SetNDC();
    LowResLabel->SetTextAngle(90);
    LowResLabel->SetTextSize(0.035);
    LowResLabel->SetTextFont(42);
    LowResLabel->SetTextColor(kBlack);
    LowResLabel->DrawLatex(0.80,0.13,"#bf{LowRes Category}");
    LowResLabel->Draw();
  }
    

  cv->SaveAs("SignificanceVsBin.png");
  cv->SaveAs("SignificanceVsBin.pdf");


}