def drawBackground(background, names, colors, styles): if (n_figs == 2): fig, axs = defs.makeRatio(xlog=True, ylog=True, d=d, shareY=False, figsize=(5, 7.5)) 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) axs[1].text(0.12, 0.002, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=11) for signal, name, color, j in zip(background, names, colors, range(10)): print("Plot {}".format(name)) for jT, pT, ax, i in zip(signal[start:], jetPt[start:], axs[0:n_figs / 2], range(0, 9)): jT.SetMarkerColor(color) jT.SetMarkerStyle(styles[j]) jT.SetLineColor(color) plot = rplt.errorbar(jT, xerr=False, emptybins=False, axes=ax, label=name, fmt='o', fillstyle='none') #Plot jT histogram, line = plot.get_children()[0] line.set_markersize(mSize) if (styles[j] > 23): 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]) ax.text( 0.5, 1e2, r'${:02d}\:\mathrm{{GeV}} < p_{{T,\mathrm{{jet}}}} < {:02d}\:\mathrm{{GeV}}$' .format(pT[0], pT[1])) ax.set_xlim([xlow, 22]) #Set x-axis limits ax.set_ylim([5e-4, 2e3]) #Set y-axis limits #ax.set_xticklabels(ax.get_xticklabels(),horizontalalignment='left') ratios = [] if j > 0: for jT, div in zip(signal, background[0]): h = jT.Clone() h.Divide(div) ratios.append(h) axs[n_figs / 2].set_ylabel( 'Ratio to {}'.format(names[0]), fontsize=18 ) #Add y-axis labels to left- and righmost subfigures if (n_figs > 4): axs[-1].set_ylabel('Ratio to {}'.format(names[0]), fontsize=18) for ratio, pT, ax in zip(ratios[start:], jetPt[start:], axs[n_figs / 2:n_figs + 1]): plot = rplt.errorbar(ratio, xerr=False, emptybins=False, axes=ax, label='Ratio', fmt='o') #Plot ratio histogram, line = plot.get_children()[0] line.set_markersize(mSize) if (styles[j] > 23): line.set_markerfacecolor('none') line.set_color(color) #if(i == 0): ax.set_yscale('linear') ax.set_xlim([xlow, 9]) #Set x-axis limits ax.set_ylim([0, 2.2]) #Set y-axis limits handles, labels = axs[0].get_legend_handles_labels() 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].legend(loc = 'lower left') plt.savefig( "PythonFigures/HighMJetConeJtBackgroundPtFrom{}To{}.pdf".format( start, end), format='pdf') #Save figure plt.show() #Draw figure on screen
def drawInclusive(incs, names, colors, styles): start = 4 end = 8 n_figs = 6 if (end > start + n_figs / 2): end = start + n_figs / 2 n_rows = 2 if (True): if (n_figs == 2): fig, axs = defs.makeRatio(xlog=True, ylog=True, d=d, shareY=False, figsize=(5, 7.5)) 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) axs[1].text(0.12, 0.002, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=11) for inc, name, color, j in zip(incs, names, colors, range(10)): print("Plot {}".format(name)) for jT, pT, ax, i in zip(inc[start:], jetPt[start:], axs[0:n_figs / 2], range(0, 9)): jT.SetMarkerColor(color) jT.SetMarkerStyle(styles[j]) jT.SetLineColor(color) plot = rplt.errorbar(jT, xerr=False, emptybins=False, axes=ax, label=name, fmt='o', fillstyle='none') #Plot jT histogram, line = plot.get_children()[0] line.set_markersize(mSize) if (styles[j] > 23): line.set_markerfacecolor('none') #line.set_markeredgecolor(color) line.set_color(color) 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, 10]) #Set x-axis limits ax.set_ylim([5e-5, 2e3]) #Set y-axis limits #ax.set_xticklabels(ax.get_xticklabels(),horizontalalignment='left') ratios = [] if j > 0: for jT, div in zip(inc, incs[0]): h = jT.Clone() h.Divide(div) ratios.append(h) axs[n_figs / 2].set_ylabel( 'Ratio to {}'.format(names[0]), fontsize=14 ) #Add y-axis labels to left- and righmost subfigures if (n_figs > 4): axs[-1].set_ylabel('Ratio to {}'.format(names[0]), fontsize=18) for ratio, pT, ax in zip(ratios[start:], jetPt[start:], axs[n_figs / 2:n_figs + 1]): plot = rplt.errorbar(ratio, xerr=False, emptybins=False, axes=ax, label='Ratio', fmt='o') #Plot ratio histogram, ax.plot([0, 10], [1, 1], 'k--') line = plot.get_children()[0] line.set_markersize(mSize) if (styles[j] > 23): line.set_markerfacecolor('none') line.set_color(color) #if(i == 0): ax.set_yscale('linear') ax.set_xlim([xlow, 10]) #Set x-axis limits ax.set_ylim([0, 2.2]) #Set y-axis limits axs[0].legend(loc='lower left') plt.savefig( "PythonFigures/HighMJetConeJtInclusivePtFrom{}To{}.pdf".format( start, end), format='pdf') #Save figure plt.show() #Draw figure on screen
def drawSignal(signals, systematics, names, colors, styles, jetPt): if (n_figs == 2): fig, axs = defs.makeRatio(xlog=True, ylog=True, d=d, shareY=False, figsize=(5, 7.5), 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}} < p_{{\mathrm{{T,jet}}}} < {:02d}\:\mathrm{{GeV}}$' .format(pT[0], pT[1]), fontsize=11) else: axs[1].text(0.12, 0.002, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=11) for signal, system, name, color, j in zip(signals, systematics, names, colors, range(10)): print("Plot {}".format(name)) for jT, syst, pT, ax, i in zip(signal[start:], system[start:], jetPt[start:], axs[0:n_figs / 2], range(0, 9)): print(pT) jT.SetMarkerColor(color) jT.SetMarkerStyle(styles[j]) jT.SetLineColor(color) plot = rplt.errorbar(jT, xerr=False, emptybins=False, axes=ax, label=name, fmt='o', fillstyle='none') #Plot jT histogram, line = plot.get_children()[0] line.set_markersize(mSize) if (styles[j] > 23): line.set_markerfacecolor('none') #line.set_markeredgecolor(color) line.set_color(color) 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, 15]) #Set x-axis limits ax.set_ylim([1e-5, 2e3]) #Set y-axis limits errorboxes = [] for box in syst: print(box) x1, x2, y1, y2, yc, error, ratio, ratioerror = box print(x1) print("{} {} {} {}".format(x1, y1, x2 - x1, y2 - y1)) rect = Rectangle((x1, y1), x2 - x1, y2 - y1) errorboxes.append(rect) pc = PatchCollection(errorboxes, facecolor=colorsBox[j], alpha=0.5, edgecolor='None') ax.add_collection(pc) ratios = [] if (j > 0): for syst, sig, div, ax in zip(system[start:], signal[start:], signals[0], axs[n_figs / 2:n_figs + 1]): 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='None') ax.add_collection(pc) if j > 0: for jT, div in zip(signal, signals[0]): h = jT.Clone() h.Divide(div) ratios.append(h) axs[n_figs / 2].set_ylabel( 'Ratio to {}'.format(names[0]), fontsize=12 ) #Add y-axis labels to left- and righmost subfigures if (n_figs > 4): axs[-1].set_ylabel('Ratio to {}'.format(names[0]), fontsize=12) for ratio, pT, ax in zip(ratios[start:], jetPt[start:], axs[n_figs / 2:n_figs + 1]): plot = rplt.errorbar(ratio, xerr=False, emptybins=False, axes=ax, label='Ratio', fmt='o') #Plot ratio histogram, ax.plot([0, 10], [1, 1], 'k--') line = plot.get_children()[0] line.set_markersize(mSize) if (styles[j] > 23): line.set_markerfacecolor('none') line.set_color(color) #if(i == 0): ax.set_yscale('linear') ax.set_xlim([xlow, 15]) #Set x-axis limits ax.set_ylim([0.1, 2.5]) #Set y-axis limits handles, labels = axs[0].get_legend_handles_labels() 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, prop={'family': 'monospace'}) #axs[0].legend(loc = 'lower left') axs[0].text(0.11, 3e2, "ALICE", weight='bold') fig.align_labels() plt.savefig("PythonFigures/HighMJetConeJtSignalPtFrom{}To{}.pdf".format( start, end), format='pdf') #Save figure plt.show() #Draw figure on screen
def drawJetPt(jetpt, names, colors, styles): fig, axs = defs.makeRatio(xlog=True, ylog=True, d=d, shareY=False, figsize=(5, 7.5), xtitle=r"Jet $p_T$", ytitle=r"$\frac{dN}{dp_T}$") axs = axs.reshape(2) axs[1].text(0.12, 0.002, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=11) ratios = [] for pt, name, color, j in zip(jetpt, names, colors, range(10)): print("Plot {}".format(name)) pt.SetMarkerColor(color) pt.SetMarkerStyle(styles[j]) pt.SetLineColor(color) plot = rplt.errorbar(pt, xerr=False, emptybins=False, axes=axs[0], label=name, fmt='o', fillstyle='none') line = plot.get_children()[0] line.set_markersize(mSize) if (styles[j] > 23): line.set_markerfacecolor('none') #line.set_markeredgecolor(color) line.set_color(color) if j > 0: ratio = pt.Clone() ratio.Divide(jetpt[0]) ratios.append(ratio) axs[0].set_xlim([10, 250]) axs[0].set_ylim(0.01, 1e5) axs[1].set_ylabel( 'Ratio to {}'.format(names[0]), fontsize=14) #Add y-axis labels to left- and righmost subfigures for ratio, color, j in zip(ratios, colors, range(10)): plot = rplt.errorbar(ratio, xerr=False, emptybins=False, axes=axs[1], label='Ratio', fmt='o') #Plot ratio histogram, line = plot.get_children()[0] line.set_markersize(mSize) if (styles[j] > 23): line.set_markerfacecolor('none') #axs[1].set_yscale('linear') axs[1].set_xlim([10, 250]) #Set x-axis limits axs[1].set_ylim([0.001, 1]) #Set y-axis limits axs[0].legend(loc='upper right') plt.show() #Draw figure on screen
def drawBackgroundQA(signals, signals_randomBg, names, colors, styles): for sig1, sig2, name in zip(signals, signals_randomBg, names): start = 4 end = 8 n_figs = 6 if (end > start + n_figs / 2): end = start + n_figs / 2 n_rows = 2 if (n_figs == 2): fig, axs = defs.makeRatio(xlog=True, ylog=True, d=d, shareY=False, figsize=(5, 7.5)) 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) axs[1].text(0.12, 0.002, name + '\n' + d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=11) axs[n_figs / 2].set_ylabel( 'Ratio to {}'.format(names[0]), fontsize=14) #Add y-axis labels to left- and righmost subfigures for h1, h2, pT, ax, axRatio, i in zip(sig1[start:], sig2[start:], jetPt[start:], axs[0:n_figs / 2], axs[n_figs / 2:n_figs + 1], range(0, 9)): h1.SetMarkerColor(colors[0]) h1.SetMarkerStyle(styles[0]) h1.SetLineColor(colors[0]) h2.SetMarkerColor(colors[1]) h2.SetMarkerStyle(styles[1]) h2.SetLineColor(colors[1]) plot = rplt.errorbar(h1, xerr=False, emptybins=False, axes=ax, label="Perp. cone", fmt='o', fillstyle='none') #Plot jT histogram, plot = rplt.errorbar(h2, xerr=False, emptybins=False, axes=ax, label="Random bg", fmt='o', fillstyle='none') #Plot jT histogram, 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, 10]) #Set x-axis limits ax.set_ylim([5e-5, 2e3]) #Set y-axis limits #ax.set_xticklabels(ax.get_xticklabels(),horizontalalignment='left') ratio = h1.Clone() ratio.Divide(h2) axRatio.plot([0, 10], [1, 1], 'k--') plot = rplt.errorbar(ratio, xerr=False, emptybins=False, axes=axRatio, label='Ratio', fmt='o') #Plot ratio histogram, axRatio.set_yscale('linear') axRatio.set_xlim([xlow, 10]) #Set x-axis limits axRatio.set_ylim([0, 2.2]) #Set y-axis limits axs[0].legend(loc='lower left') #plt.savefig("PythonFigures/HighMJetConeJtInclusivePtFrom{}To{}_{}.pdf".format(start,end,name),format='pdf') #Save figure plt.show() #Draw figure on screen
def main(): print('Number of arguments: ', len(sys.argv), 'arguments.') print('Argument list:', str(sys.argv)) filename = sys.argv[1] separate = int(sys.argv[2]) if (len(sys.argv) > 3): start = int(sys.argv[3]) end = int(sys.argv[4]) else: start = 1 end = 9 n_figs = end - start print("Number of figs: {}".format(n_figs)) print("Input file: ") print(filename) Mixed_FullJets_R04 = datasetMixed( "Full jets R=0.4", NFIN=0, range=(1, 5), filename=filename, directory='AliJJetJtTask/AliJJetJtHistManager', directory2='AliJJetJtTask_kEMCEJE/AliJJetJtHistManager', color=2, style=24, rebin=2) signal, jetPt = Mixed_FullJets_R04.getSubtracted('JetConeJtWeightBin', 'BgJtWeightBin', jetpt=True) if (False): if (separate > 0): fig = plt.figure(1) ax = fig.add_subplot(1, 1, 1) ax.set_xscale('log') ax.set_yscale('log') ax.text(0.2, 0.0005, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n Jet Cone', fontsize=7) rplt.errorbar(signal[separate], xerr=False, emptybins=False, axes=ax, label=Mixed_FullJets_R04.name(), fmt='o') #Plot jT histogram, ax.text( 0.3, 1e2, r'$p_{{T,\mathrm{{jet}}}}$:' '\n' r' {:02d}-{:02d} GeV'.format(jetPt[separate][0], jetPt[separate][1])) ax.set_xlim([0.1, 12]) ax.set_ylim([5e-6, 1.5e3]) ax.legend(loc='lower left') plt.savefig( "PythonFigures/MixedFullJetsR04JetConeJtSignalJetPt{0}.pdf". format(separate), format='pdf') #Save figure plt.show() #Draw figure on screen else: n_rows = n_figs // 4 print(n_rows) fig, axs = defs.makegrid(4, n_figs // 4, xlog=True, ylog=True, d=d, shareY=True, figsize=(10, 2.5)) axs = axs.reshape(n_figs) axs[1].text(0.12, 0.002, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n Jet Cone', fontsize=7) for jT, pT, ax, i in zip(signal[start:], jetPt[start:], axs, range(0, 9)): plot = rplt.errorbar(jT, xerr=False, emptybins=False, axes=ax, label=Mixed_FullJets_R04.name(), fmt='o', fillstyle='none', ecolor='blue') #Plot jT histogram, line = plot.get_children()[0] #line.set_markerfacecolor('none') #line.set_markeredgecolor('red') ax.text( 0.3, 1e2, r'$p_{{T,\mathrm{{jet}}}}$:' '\n' r' {:02d}-{:02d} GeV'.format(pT[0], pT[1])) ax.set_xlim([0.1, 22]) #Set x-axis limits ax.set_ylim([5e-4, 2e3]) #Set y-axis limits ax.set_xticklabels(ax.get_xticklabels(), horizontalalignment='left') #axs[0].legend(loc = 'lower left') plt.savefig( "PythonFigures/MixedFullJetsR04JetConeJtSignalPtFrom{}To{}.pdf" .format(start, end), format='pdf') #Save figure plt.show() #Draw figure on screen fig, axs = defs.makeRatio(xlog=True, ylog=True, d=d, shareY=False, figsize=(10, 10)) axs = axs.reshape(2) ax = axs[0] for jT, pT, i in zip(signal[start:], jetPt[start:], range(0, 9)): h = jT.Clone() h.Scale(10**i) h.SetMarkerColor(i) label = r'${:02d}\:\mathrm{{GeV}} < p_{{T,\mathrm{{jet}}}} < {:02d}\:\mathrm{{GeV}} \left(\times 10^{:01d}\right)$'.format( pT[0], pT[1], i) plot = rplt.errorbar(h, xerr=False, emptybins=False, axes=ax, label=label, fmt='o', fillstyle='none') #Plot jT histogram, ax.set_xlim([0.1, 22]) ax.set_ylim([5e-4, 2e8]) ax.set_xticklabels(ax.get_xticklabels(), horizontalalignment='left') ax.legend(loc='lower left') plt.show() #Draw figure on screen
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
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