Example #1
0
def main(): 
  
  JetPtBins = [5,10,20,30,40,60,80,100,150,500]
  jetPt = [(JetPtBins[i],JetPtBins[i+1]) for i in range(8)]
  print(jetPt)
  #JetPtCenter = [7.5,15,25,35,50,70,90,125,325]
  JetPtCenter = [6.5,12.45,23.34,33.83,46.75,67.73,88.01,116.11,194.61]
  LeadPtMode = [2.0,3.0,5.6,8.9,9.9,14.8,20.7,26.0,34.6]
  LeadPtMean = [2.35,3.72,6.66,9.59,13.58,17.98,23.27,27.55,31.68]
  LeadPtError = [0.93,1.69,3.18,4.43,6.74,8.34,9.68,10.27,10.55]
  JetPtError = [2.5,5,5,5,10,10,10,25,175]
  JetPtLeadPtG = Graph(len(JetPtCenter)) #Gives jet pT as a function of leading pT
  JetPtLeadPtGerr = Graph(len(JetPtCenter))
  LeadPtJetPtG = Graph(len(JetPtCenter))
  LeadPtJetPtGerr = Graph(len(JetPtCenter))
  for i,(x,y,e) in enumerate(zip(LeadPtMean,JetPtCenter,JetPtError)):
    JetPtLeadPtG.SetPoint(i,x,y)
    JetPtLeadPtGerr.SetPoint(i,x,e)
  for i,(x,y,e) in enumerate(zip(JetPtCenter,LeadPtMean,LeadPtError)):
    LeadPtJetPtG.SetPoint(i,x,y)
    LeadPtJetPtGerr.SetPoint(i,x,e)
  
  Njets = 8
  

  
  
  topcomment = "_systematics_Triggered"
  
  finderName = ["Full jets, Anti-k_\mathrm{T} R = 0.4","Charged Jets, Anti-k_\mathrm{T} R = 0.4"]
  finderType = ["Full","Charged"]
  setTitle = ["0","1","2","3","4","5"]
  finderR = {4,4}
  
  iC = 0
  logx = 1
  doWeight = 1
  iS = 0

  f = root_open("errors_test.root", 'read')

  gGausRMS = f.Get("gGausRMS{:02d}".format(iS))
  gGausRMSerr = f.Get("gGausRMS{:02d}_Systematics".format(iS))
  gGausYield = f.Get("gGausYield{:02d}".format(iS))
  gGausYielderr = f.Get("gGausYield{:02d}_Systematics".format(iS))
  gGammaRMS = f.Get("gGammaRMS{:02d}".format(iS))
  gGammaRMSerr = f.Get("gGammaRMS{:02d}_Systematics".format(iS))
  gGammaYield = f.Get("gGammaYield{:02d}".format(iS))
  gGammaYielderr = f.Get("gGammaYield{:02d}_Systematics".format(iS))
  
  start = 4
  iS = 0
  stats = [None if ij < start else f.Get("JetConeJtWeightBinNFin{:02d}JetPt{:02d}_Statistics".format(iS,ij)) for ij in range(8)]
  fits = [None if ij < start else f.Get("JetConeJtWeightBinNFin{:02d}JetPt{:02d}_FitFunction".format(iS,ij)) for ij in range(8)]
  print(fits)


  print(stats)

  n_figs = 2
  
  
  
#   if(n_figs == 2):
#     fig,axs = defs.makeRatio(xlog=True,ylog=True,d=d,shareY=False,figsize = (5,6),grid=False)
#   else:
#     fig, axs = defs.makegrid(n_figs/2,2,xlog=True,ylog=True,d=d,shareY=False,figsize= (10,7.5) if n_figs == 4 else (n_figs*15/8,7.5) )
#   axs = axs.reshape(n_figs)
#   if(n_figs == 2):
#     pT = jetPt[start]
#     print(pT)
#     axs[0].text(0.8,7,d['system'] +'\n'+  d['jettype'] +'\n'+ d['jetalg'] + '\n' + d['cut'] + '\n' + r'${:02d}\:\mathrm{{GeV}}/c < p_{{\mathrm{{T,jet}}}} < {:02d}\:\mathrm{{GeV}}/c$'.format(pT[0],pT[1]),fontsize = 10)
#   else:
#     axs[1].text(0.12,0.002,d['system'] +'\n'+  d['jettype'] +'\n'+ d['jetalg'] + '\n' + d['cut'],fontsize = 11)
#   
  ratios = []
  xs2 = []

  for jT,pT,ij,fit in zip(stats[start:],jetPt[start:],range(start,9),fits[start:]):
    color = colors[1]
    fig,axs = defs.makeRatio(xlog=True,ylog=True,d=d,shareY=False,figsize = (5,6),grid=False)
    axs = axs.reshape(n_figs)
    axs[0].text(0.8,7,d['system'] +'\n'+  d['jettype'] +'\n'+ d['jetalg'] + '\n' + d['cut'] + '\n' + r'${:02d}\:\mathrm{{GeV}}/c < p_{{\mathrm{{T,jet}}}} < {:02d}\:\mathrm{{GeV}}/c$'.format(pT[0],pT[1]),fontsize = 10)
    ax = axs[0]
    xs = np.arange(0,xhigh,0.01).tolist()
    for ii in range(6):
      print(fit.GetParameter(ii))
    #B2 is Gauss normalization
    #B3 is Gamma normalization
    gauss = fit.Clone()
    gauss.SetParameter(3,0)
    gamma = fit.Clone()
    gamma.SetParameter(0,0)
    ys = [fit.Eval(x) for x in xs]
    ys2 = [gauss.Eval(x) for x in xs]
    ys3 = [gamma.Eval(x) for x in xs]
    ax.plot(xs,ys2,'b:',label="Narrow")
    ax.plot(xs,ys3,'r--',label="Wide")
    ax.plot(xs,ys,'k',label="Total")

    jT.SetMarkerColor(color)
    jT.SetMarkerStyle(24)
    jT.SetLineColor(color)
    jT.SetMarkerSize(mSize)
    plot = rplt.errorbar(jT,xerr=False,emptybins=False,axes=ax,label="ALICE",fmt='o',fillstyle='none') #Plot jT histogram, 
    line = plot.get_children()[0]
    line.set_markersize(mSize)
    if(True):
      line.set_markerfacecolor('none')
      #line.set_markeredgecolor(color)
      line.set_color(color)
#     line.set_markerfacecolor('none')
#     line.set_markeredgecolor(colors[c])
#     line.set_markerfacecolor('none')
#     line.set_markeredgecolor('none')
#     line.set_drawstyle('default')
#     line.set_linestyle('dashed')  
#     line.set_color(colors[c])
    if(n_figs > 2):
      ax.text(0.5,1e2,r'${:02d}\:\mathrm{{GeV}} < p_{{\mathrm{{T,jet}}}} < {:02d}\:\mathrm{{GeV}}$'.format(pT[0],pT[1])) 
    ax.set_xlim([xlow,xhigh]) #Set x-axis limits
    ax.set_ylim([1e-6,2e3]) #Set y-axis limits
    #ax.set_xticklabels(ax.get_xticklabels(),horizontalalignment='left')
    x_ = Double()
    y1 = Double()
    xe = Double()
    ye = Double()
    NC = jT.GetN()
    y2 = []
    y2e = []
    xs=[]
    ex = []
    for ii in range(NC):
      jT.GetPoint(ii,x_,y1)
      xe = jT.GetErrorX(ii)
      ye = jT.GetErrorY(ii)
      x1 = x_*1.0
      xs.append(x1)
      ex.append(xe)
      if(y1 > 0):
        y2.append(y1/fit.Eval(x1))
        y2e.append(ye/fit.Eval(x1))
      else:
        y2.append(0)
        y2e.append(0)
    #ratio = jT.Clone()
    ratio= Graph(NC)

    print(xs[::5])
    print(y2[::5])
    print(ex[::5])
    print(y2e[::5])
    for x0,y0,x0e,y0e,i in zip(xs,y2,ex,y2e,range(NC)):
      ratio.SetPoint(i,x0,y0)
      ratio.SetPointError(i,x0e,x0e,y0e,y0e)
    ratios.append(ratio)
    print(ratio)
    ax = axs[1]
  #for ratio,pT,ax,color in zip(ratios,jetPt[start:],axs[n_figs/2:n_figs+1],colors[1:]):
    
    print("Debug")
    ratio.SetMarkerColor(color)
    ratio.SetLineColor(color)
    ratio.SetMarkerStyle(24)
    ax.plot([0,20],[1,1],'k--')
    #ratio.SetMarkerSize(mSize)
    plot = rplt.errorbar(ratio,xerr=False,emptybins=False,axes=ax,label=r"Ratio",fmt='o',fillstyle='none') #Plot jT histogram, 
    line = plot.get_children()[0]
    line.set_markersize(mSize)
    if(True):
      line.set_markerfacecolor('none')
      #line.set_markeredgecolor(color)
      line.set_color(color)
    #ax.plot(xs2,ratio)
    ax.set_yscale('linear')
    ax.set_xlim([xlow,xhigh]) #Set x-axis limits
    ax.set_ylim([0,2.75]) #Set y-axis limits  
    ax.set_ylabel('Signal/Fit',fontsize=14) #Add y-axis labels to left- and righmost subfigures

    
    handles, labels = axs[0].get_legend_handles_labels()
    handles = [handles[3],handles[2],handles[0],handles[1]]
    labels = [labels[3],labels[2],labels[0],labels[1]]
  
    handles = [container.ErrorbarContainer(h,has_xerr=False,has_yerr=True) if isinstance(h, container.ErrorbarContainer) else h for h in handles]
    axs[0].legend(handles,labels,loc = 'lower left',numpoints=1)
  
    axs[0].text(0.11,3e2,"ALICE",weight='bold')
  
    fig.align_labels()
    print("Save PythonFigures/JtSignalFinalFitJetPt{}.pdf".format(ij))
    plt.savefig("PythonFigures/JtSignalFinalFitJetPt{}.pdf".format(ij),format='pdf') #Save figure
    plt.show() #Draw figure on screen
Example #2
0
        g_truth_new.SetPoint(i, x, y / width)
        error = h_truth.GetBinError(i + 1)
        g_truth_new.SetPointError(i, 0, 0, error, error)

    for bin_i in range(len(data)):
        h_truth_new.SetBinContent(bin_i + 1, data[bin_i] / bin_widths[bin_i])
        h_truth.SetBinContent(bin_i + 1, data[bin_i] / bin_widths[bin_i])

    h_truth_finebinned.SetFillStyle(0)
    h_truth_finebinned.Smooth(500)
    x, y = list(h_truth_finebinned.x()), list(h_truth_finebinned.y())
    bin_edges = np.array(list(h_truth_finebinned.xedges()))
    bincenters = 0.5 * (bin_edges[1:] + bin_edges[:-1])
    g_truth = Graph(h_truth)
    #    g_truth_new = Graph(len(h_truth), h_truth_new)
    g_truth_new.SetLineColor('red')
    g_truth_new.SetMarkerColor('red')
    h_truth_finebinned.axis().SetRange(0, 1000)
    h_truth_finebinned.linecolor = 'orange'
    plt.figure(figsize=(16, 10), dpi=100)
    axes = plt.axes()
    rplt.errorbar(g_truth_new, label=r'corrected', emptybins=False)
    rplt.errorbar(g_truth, label=r'bin centre', emptybins=False)
    # rplt.hist(h_truth_finebinned, label=r'MC', stacked=False)
    plt.plot(bincenters, y, '-')
    axes.set_xlim([0, 300])
    plt.xlabel('$E_{\mathrm{T}}^{miss}$')
    plt.ylabel('Events')
    plt.title('Unfolding')
    plt.legend()
    plt.savefig('plots/Bin_Centers.png')
Example #3
0
def main():

    JetPtBins = [5, 10, 20, 30, 40, 60, 80, 100, 150, 500]
    jetPt = [(JetPtBins[i], JetPtBins[i + 1]) for i in range(8)]
    print(jetPt)
    #JetPtCenter = [7.5,15,25,35,50,70,90,125,325]
    JetPtCenter = [
        6.5, 12.45, 23.34, 33.83, 46.75, 67.73, 88.01, 116.11, 194.61
    ]
    LeadPtMode = [2.0, 3.0, 5.6, 8.9, 9.9, 14.8, 20.7, 26.0, 34.6]
    LeadPtMean = [2.35, 3.72, 6.66, 9.59, 13.58, 17.98, 23.27, 27.55, 31.68]
    LeadPtError = [0.93, 1.69, 3.18, 4.43, 6.74, 8.34, 9.68, 10.27, 10.55]
    JetPtError = [2.5, 5, 5, 5, 10, 10, 10, 25, 175]
    JetPtLeadPtG = Graph(
        len(JetPtCenter))  #Gives jet pT as a function of leading pT
    JetPtLeadPtGerr = Graph(len(JetPtCenter))
    LeadPtJetPtG = Graph(len(JetPtCenter))
    LeadPtJetPtGerr = Graph(len(JetPtCenter))
    for i, (x, y, e) in enumerate(zip(LeadPtMean, JetPtCenter, JetPtError)):
        JetPtLeadPtG.SetPoint(i, x, y)
        JetPtLeadPtGerr.SetPoint(i, x, e)
    for i, (x, y, e) in enumerate(zip(JetPtCenter, LeadPtMean, LeadPtError)):
        LeadPtJetPtG.SetPoint(i, x, y)
        LeadPtJetPtGerr.SetPoint(i, x, e)

    Njets = 8

    topcomment = "_systematics_Triggered"

    finderName = [
        "Full jets, Anti-k_\mathrm{T} R = 0.4",
        "Charged Jets, Anti-k_\mathrm{T} R = 0.4"
    ]
    finderType = ["Full", "Charged"]
    setTitle = ["0", "1", "2", "3", "4", "5"]
    finderR = {4, 4}

    iC = 0
    logx = 1
    doWeight = 1
    iS = 0
    start = 5
    iS = 0

    if (os.path.exists('RootFiles/Fig2.root')):
        inFile = "RootFiles/Fig2.root"
        inF = root_open(inFile, 'r')
        stats = [
            None
            if ij < start else inF.Get("jTSignalJetPt_Stat{:02d}".format(ij))
            for ij in range(8)
        ]
        fits = [
            None
            if ij < start else inF.Get("jTSignalJetPt_fit{:02d}".format(ij))
            for ij in range(8)
        ]
        errGraph = [
            None
            if ij < start else inF.Get("jTSignalJetPt_syst{:02d}".format(ij))
            for ij in range(8)
        ]

    else:
        f = root_open("RootFiles/jtSystematics.root", 'read')

        stats = [
            None if ij < start else f.Get(
                "JetConeJtWeightBinNFin{:02d}JetPt{:02d}_Statistics".format(
                    iS, ij)) for ij in range(8)
        ]
        fits = [
            None if ij < start else f.Get(
                "JetConeJtWeightBinNFin{:02d}JetPt{:02d}_FitFunction".format(
                    iS, ij)) for ij in range(8)
        ]
        errGraph = [
            None if ij < start else f.Get(
                'JetConeJtWeightBinNFin{:02d}JetPt{:02d}_Systematics'.format(
                    iS, ij)) for ij in range(8)
        ]  #Get jT histograms from file an array

        outFile = "RootFiles/Fig2.root"
        outF = root_open(outFile, "w+")
        for s, f, e, i in zip(stats, fits, errGraph, range(10)):
            if (s):
                s.SetName("jTSignalJetPt_Stat{:02d}".format(i))
                s.Write()
                f.SetName("jTSignalJetPt_fit{:02d}".format(i))
                f.Write()
                e.SetName("jTSignalJetPt_syst{:02d}".format(i))
                e.Write()
        outF.Close()

    n_figs = 2

    ratios = []
    xs2 = []

    for jT, pT, ij, fit, jT_sys in zip(stats[start:], jetPt[start:],
                                       range(start, 9), fits[start:],
                                       errGraph[start:]):
        color = colors[1]
        fig, axs = defs.makeRatio(xlog=True,
                                  ylog=True,
                                  d=d,
                                  shareY=False,
                                  figsize=(5, 6),
                                  grid=False)
        axs = axs.reshape(n_figs)
        axs[0].text(
            0.6,
            40,
            d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' +
            d['cut'] + '\n' +
            r'${:02d}\: < p_{{\mathrm{{T,jet}}}} < {:02d}\:\mathrm{{GeV}}/c$'.
            format(pT[0], pT[1]),
            fontsize=10)
        ax = axs[0]
        xs = np.arange(0, xhigh, 0.01).tolist()
        for ii in range(6):
            print(fit.GetParameter(ii))

        gauss = fit.Clone()
        gauss.SetParameter(3, 0)
        gamma = fit.Clone()
        gamma.SetParameter(0, 0)
        ys = [fit.Eval(x) for x in xs]
        ys2 = [gauss.Eval(x) for x in xs]
        ys3 = [gamma.Eval(x) for x in xs]
        ax.plot(xs, ys2, 'b:', label="Narrow")
        ax.plot(xs, ys3, 'r--', label="Wide")
        ax.plot(xs, ys, 'k', label="Total")

        jT.SetMarkerColor(color)
        jT.SetMarkerStyle(24)
        jT.SetLineColor(color)
        jT.SetMarkerSize(mSize)
        plot = rplt.errorbar(jT,
                             xerr=False,
                             emptybins=False,
                             axes=ax,
                             label="ALICE",
                             fmt='o',
                             fillstyle='none')  #Plot jT histogram,
        line = plot.get_children()[0]
        line.set_markersize(mSize)
        line.set_markerfacecolor('none')
        line.set_color(color)

        errorboxes = []
        ratioBoxes = []

        n = jT_sys.GetN()
        xs = jT_sys.GetX()
        ys = jT_sys.GetY()
        xerrs = jT_sys.GetEX()
        yerrs = jT_sys.GetEY()
        for x in (xs, ys, xerrs, yerrs):
            x.SetSize(n)
        for x, y, xe, ye in zip(xs, ys, xerrs, yerrs):
            rect = Rectangle((x - xe, (y - ye)), xe * 2, ye * 2)
            errorboxes.append(rect)
            rect2 = Rectangle((x - xe, (y - ye) / fit.Eval(x)), xe * 2,
                              ye / fit.Eval(x) * 2)
            ratioBoxes.append(rect2)
        pc = PatchCollection(errorboxes,
                             facecolor='r',
                             alpha=0.5,
                             edgecolor='None')
        ax.add_collection(pc)

        if (n_figs > 2):
            ax.text(
                0.5, 1e2,
                r'${:02d}\:\mathrm{{GeV}} < p_{{\mathrm{{T,jet}}}} < {:02d}\:\mathrm{{GeV}}$'
                .format(pT[0], pT[1]))
        ax.set_xlim([xlow, xhigh])  #Set x-axis limits
        ax.set_ylim([1e-3, 5e3])  #Set y-axis limits
        x_ = Double()
        y1 = Double()
        xe = Double()
        ye = Double()
        NC = jT.GetN()
        y2 = []
        y2e = []
        xs = []
        ex = []

        for ii in range(NC):
            jT.GetPoint(ii, x_, y1)
            xe = jT.GetErrorX(ii)
            ye = jT.GetErrorY(ii)
            x1 = x_ * 1.0
            xs.append(x1)
            ex.append(xe)
            if (y1 > 0):
                y2.append(y1 / fit.Eval(x1))
                y2e.append(ye / fit.Eval(x1))
            else:
                y2.append(0)
                y2e.append(0)
        #ratio = jT.Clone()
        ratio = Graph(NC)
        """
           ratioBoxes = []
        N = div.GetNbinsX()
        for box,i in zip(syst,range(1,N)):
          y = div.GetBinContent(i)
          x1,x2,y1,y2,yc,error,ratio,ratioerror = box
          rect = Rectangle((x1,ratio-ratioerror),x2-x1,ratioerror*2)
          ratioBoxes.append(rect)
        
        pc = PatchCollection(ratioBoxes, facecolor=colorsBox[j], alpha=0.5,edgecolor=colorsBox[j])
        ax.add_collection(pc)
    
    """

        print(xs[::5])
        print(y2[::5])
        print(ex[::5])
        print(y2e[::5])
        for x0, y0, x0e, y0e, i in zip(xs, y2, ex, y2e, range(NC)):
            ratio.SetPoint(i, x0, y0)
            ratio.SetPointError(i, x0e, x0e, y0e, y0e)
        ratios.append(ratio)
        print(ratio)
        ax = axs[1]
        pc2 = PatchCollection(ratioBoxes,
                              facecolor='r',
                              alpha=0.5,
                              edgecolor='None')
        ax.add_collection(pc2)
        #for ratio,pT,ax,color in zip(ratios,jetPt[start:],axs[n_figs/2:n_figs+1],colors[1:]):

        ratio.SetMarkerColor(color)
        ratio.SetLineColor(color)
        ratio.SetMarkerStyle(24)
        ax.plot([0, 20], [1, 1], 'k--')
        #ratio.SetMarkerSize(mSize)
        plot = rplt.errorbar(ratio,
                             xerr=False,
                             emptybins=False,
                             axes=ax,
                             label=r"Ratio",
                             fmt='o',
                             fillstyle='none')  #Plot jT histogram,
        line = plot.get_children()[0]
        line.set_markersize(mSize)
        if (True):
            line.set_markerfacecolor('none')
            #line.set_markeredgecolor(color)
            line.set_color(color)
        #ax.plot(xs2,ratio)
        ax.set_yscale('linear')
        ax.set_xlim([xlow, xhigh])  #Set x-axis limits
        ax.set_ylim([0, 2.75])  #Set y-axis limits
        ax.set_ylabel(
            'Signal/Fit',
            fontsize=14)  #Add y-axis labels to left- and righmost subfigures

        handles, labels = axs[0].get_legend_handles_labels()
        handles = [handles[3], handles[2], handles[0], handles[1]]
        labels = [labels[3], labels[2], labels[0], labels[1]]

        handles = [
            container.ErrorbarContainer(h, has_xerr=False, has_yerr=True)
            if isinstance(h, container.ErrorbarContainer) else h
            for h in handles
        ]
        axs[0].legend(handles, labels, loc='lower left', numpoints=1)

        #axs[0].text(0.11,1e3,"ALICE",weight='bold')
        axs[0].text(0.12, 7e2, "ALICE", fontsize=20)

        fig.align_labels()
        print("Save PythonFigures/JtSignalFinalFitJetPt{}.pdf".format(ij))
        plt.savefig("PythonFigures/JtSignalFinalFitJetPt{}.pdf".format(ij),
                    format='pdf')  #Save figure
        plt.show()  #Draw figure on screen