def legend_yerr(axes, loc='best'): """Makes a legend for the ax object 'axes' at the location 'loc', but only includes the y error errorbars in the legend icons. Parameters ---------- axes : axes.Axes The axes on which we want to create a legend with only y error bars loc : str The location of the legend. """ handles, labels = axes.get_legend_handles_labels() new_handles = [] for _, h in enumerate(handles): #only need to edit the errorbar legend entries if isinstance(h, container.ErrorbarContainer): new_handles.append( container.ErrorbarContainer( h.lines, has_xerr=False, has_yerr=True ) ) else: new_handles.append(h) axes.legend(new_handles, labels, loc=loc)
def main(): JetPtBins = [5, 10, 20, 30, 40, 60, 80, 100, 150, 500] jetPtBins2 = [(JetPtBins[i], JetPtBins[i + 1]) for i in range(8)] 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 mSize = 0.3 iS = 0 f = root_open("errors_test.root", 'read') start = 4 errGraph = [ f.Get('JetConeJtWeightBinNFin{:02d}JetPt{:02d}_Systematics'.format( iS, i)) for i in range(start, Njets) ] #Get jT histograms from file an array hJtSignalGraph = [ f.Get('JetConeJtWeightBinNFin{:02d}JetPt{:02d}_Statistics'.format( iS, i)) for i in range(start, Njets) ] #Get jT histograms from file an array print(hJtSignalGraph) ylow = 5e-6 yhigh = 5e9 xlow = 0.1 xhigh = 10 ax = plt.gca() ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) for ij, h, h_sys, pT in zip(range(start, Njets), hJtSignalGraph, errGraph, jetPtBins2[start:]): print(ij) print("JetPt {}".format(pT)) power = 2 * ij - 8 scale = pow(10, power) h = defs.grrScale(h, scale) h.SetMarkerColor(colors[ij - start]) label = r'${:02d}\:\mathrm{{GeV}} < p_{{\mathrm{{T,jet}}}} < {:02d}\:\mathrm{{GeV}} \times 10^{}$'.format( pT[0], pT[1], power) rplt.errorbar(h, xerr=False, emptybins=False, axes=ax, label=label, fmt='+') #Plot jT histogram, errorboxes = [] n = h_sys.GetN() xs = h_sys.GetX() ys = h_sys.GetY() xerrs = h_sys.GetEX() yerrs = h_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) * scale), xe * 2, ye * 2 * scale) errorboxes.append(rect) pc = PatchCollection(errorboxes, facecolor=colorsBox[ij - 4], alpha=0.5, edgecolor='None') ax.add_collection(pc) #print("({} - {})/9.0 + {} is {}".format(yhigh,ylow,ylow,(yhigh-ylow)/9.0+ylow)) ax.text(1.7, 3e6, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=10) handles, labels = ax.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 ] ax.legend(handles, labels, loc='lower left', numpoints=1) #ax.legend(loc = 'lower left') ax.yaxis.set_ticks_position('both') #Show ticks on left and right side ax.xaxis.set_ticks_position('both') #Show ticks on bottom and top ax.tick_params(which='both', direction='in') #Move ticks from outside to inside ytitle = r'$\frac{1}{N_{jets}}\;\frac{1}{j_\mathrm{T}}\;\frac{\mathrm{d} N}{\mathrm{d} j_\mathrm{T}}$' xtitle = r'$j_\mathrm{T}\left(\mathrm{GeV}/c\right)$' ax.set_ylabel(ytitle, fontsize=16) ax.set_xlabel(xtitle, fontsize=16) ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) ax.set_xscale('log') ax.set_yscale('log') plt.savefig("{}.pdf".format(file), format='pdf') #Save figure plt.show() #Draw figure on screen
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 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 main(): print('Number of arguments: ', len(sys.argv), 'arguments.') print('Argument list:', str(sys.argv)) filename = sys.argv[1] if len(sys.argv) > 2: fileData = sys.argv[2] else: fileData = None print("Input file: ") print(filename) Njets = 9 if fileData is not None: fD = root_open(fileData, 'read') iS = 0 gGausRMSData = fD.Get("gGausRMS{:02d}".format(iS)) gGausRMSerrData = fD.Get("gGausRMS{:02d}_Systematics".format(iS)) gGausYieldData = fD.Get("gGausYield{:02d}".format(iS)) gGausYielderrData = fD.Get("gGausYield{:02d}_Systematics".format(iS)) gGammaRMSData = fD.Get("gGammaRMS{:02d}".format(iS)) gGammaRMSerrData = fD.Get("gGammaRMS{:02d}_Systematics".format(iS)) gGammaYieldData = fD.Get("gGammaYield{:02d}".format(iS)) gGammaYielderrData = fD.Get("gGammaYield{:02d}_Systematics".format(iS)) with root_open(filename, 'read') as f: FullJets_jT = [] colors = (1, 2, 3) for iF, c in zip((8, 6, 7), colors): jT = [ f.get( 'AliJJetJtTask/AliJJetJtHistManager/JetConeJtWeightBin/JetConeJtWeightBinNFin{:02d}JetPt{:02d}' .format(iF, ij)) for ij in range(Njets) ] bgJt = [ f.get( 'AliJJetJtTask/AliJJetJtHistManager/BgJtWeightBin/BgJtWeightBinNFin{:02d}JetPt{:02d}' .format(iF, ij)) for ij in range(Njets) ] jetPtBin = [ f.get( 'AliJJetJtTask/AliJJetJtHistManager/JetPtBin/JetPtBinNFin{:02d}JetPt{:02d}' .format(iF, ij)) for ij in range(Njets) ] nJets = [h.Integral() for h in jetPtBin] nBgs = [ f.get( 'AliJJetJtTask/AliJJetJtHistManager/BgTrkNumberBin/BgTrkNumberBinNFin{:02d}JetPt{:02d}' .format(iF, ij)).Integral() for ij in range(Njets) ] FullJets_jT.append(jT) #FullJets_bgJt.append(bgJt) #FullJets_jetPtBin.append(jetPtBin) for j, b, nj, nb in zip(jT, bgJt, nJets, nBgs): j.Rebin(2) b.Rebin(2) j.Scale(1.0 / nj, "width") b.Scale(1.0 / nb, "width") j.SetMarkerColor(c) b.SetMarkerColor(c) j.Add(b, -1.0) jetPt = [ (int( re.search(r'p_{T,jet} : ([\d]*)\.[\d] - ([\d]*).[\d]*', h.GetTitle(), re.M | re.I).group(1)), int( re.search(r'p_{T,jet} : ([\d]*)\.[\d] - ([\d]*).[\d]*', h.GetTitle(), re.M | re.I).group(2))) for h in FullJets_jT[0] ] #Use regular expressions to extract jet pT range from histogram titles jetPtCenter = array('d', [(a + b) / 2.0 for a, b in jetPt]) jetPtErrors = array('d', [(b - a) / 2.0 for a, b in jetPt]) print(jetPt, type(jetPt)) print(jetPtCenter, type(jetPtCenter)) print(jetPtErrors, type(jetPtErrors)) FullJets_fit = [] FullJets_parameters = [] FullJets_gausRMS = [] FullJets_gammaRMS = [] FullJets_gausYield = [] FullJets_gammaYield = [] for jT in FullJets_jT: gausRMS = [] gammaRMS = [] gausRMSe = [] gammaRMSe = [] gausYield = [] gammaYield = [] gausYielde = [] gammaYielde = [] fits = [] parameters = [] for h, i in zip(jT, range(Njets)): fit, d = fitJtHisto(h, '', 1, i, 8) fits.append(fit) parameters.append(d) gausRMS.append(d['gausRMS']) gausRMSe.append(d['gausRMSe']) gammaRMS.append(d['gammaRMS']) gammaRMSe.append(d['gammaRMSe']) gausYield.append(d['gausYield']) gausYielde.append(d['gausYielde']) gammaYield.append(d['gammaYield']) gammaYielde.append(d['gammaYielde']) gausRMSg = Graph(len(gausRMS) - 2) gammaRMSg = Graph(len(gammaRMS) - 2) gausYieldg = Graph(len(gausYield) - 2) gammaYieldg = Graph(len(gammaYield) - 2) for h, he, g in zip((gausYield, gammaYield), (gausYielde, gammaYielde), (gausYieldg, gammaYieldg)): for x, xe, a, e, i in zip(jetPtCenter[2:], jetPtErrors[2:], h[2:], he[2:], range(len(gausRMS) - 2)): g.SetPoint(i, x, a) g.SetPointError(i, xe, xe, e, e) for a, b, c, d, e, f, i in zip(gausRMS[2:], gammaRMS[2:], gausRMSe[2:], gammaRMSe[2:], jetPtCenter[2:], jetPtErrors[2:], range(len(gausRMS) - 2)): gausRMSg.SetPoint(i, e, a) gausRMSg.SetPointError(i, f, f, c, c) gammaRMSg.SetPoint(i, e, b) gammaRMSg.SetPointError(i, f, f, d, d) FullJets_gausRMS.append(gausRMSg) FullJets_gammaRMS.append(gammaRMSg) FullJets_gausYield.append(gausYieldg) FullJets_gammaYield.append(gammaYieldg) FullJets_fit.append(fits) FullJets_parameters.append(parameters) if fileData is not None: FullJets_gausRMS.append(gGausRMSData) FullJets_gammaRMS.append(gGammaRMSData) FullJets_gausYield.append(gGausYieldData) FullJets_gammaYield.append(gGammaYieldData) fig, axs = plt.subplots(2, 1, figsize=(7, 7)) ax = axs[0] ax.set_xlim([0.1, 15]) ax.set_ylim([5e-6, 2e3]) ax.set_xlabel(r'$j_{T}\left(GeV/c\right)$', fontsize=labelsize) ax.set_ylabel(r'$\frac{1}{N_{jets}}\frac{dN}{j_{T}dj_{T}}$', fontsize=labelsize) ratios = [] ax.set_xscale('log') ax.set_yscale('log') for h, c, R in zip(FullJets_jT, (0, 1, 2, 3), Rs): h[6].SetMarkerColor(colors[c]) h[6].SetMarkerStyle(styles[c]) h[6].SetLineColor(colors[c]) ratio = h[6].Clone() ratio.Divide(FullJets_jT[1][6]) ratios.append(ratio) plot = rplt.errorbar(h[6], xerr=False, emptybins=False, label='R = {:.1f}'.format(R), axes=ax, fmt='+') line = plot.get_children()[0] line.set_markersize(mSize) if (styles[c] > 23): line.set_markerfacecolor('none') #line.set_markeredgecolor(color) line.set_color(colors[c]) ax.text( 0.15, 0.001, 'Pythia \n Full Jets\n' + r'Anti-$k_T$' + '\n' + r'$p_{{T,\mathrm{{jet}}}}$: {:02d}-{:02d} GeV/c'.format(60, 80), fontsize=10) handles, labels = ax.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 ] ax.legend(handles, labels, loc='upper right', numpoints=1, prop={'family': 'monospace'}) #ax.legend(loc = 'upper right') ax.set_xlim([0.1, 15]) ax.set_ylim([5e-6, 2e3]) ax.grid(True) ax = axs[1] ax.grid(True) ax.set_xlabel(r'$j_{T}\left[GeV\right]$', fontsize=labelsize) ax.set_ylabel('Ratio', fontsize=labelsize) #Add x-axis labels for bottom row for ratio, c in zip(ratios, (0, 1, 2, 3)): #ratio.SetMarkerColor(c) #ratio.SetMarkerStyle(24) plot = rplt.errorbar(ratio, xerr=False, emptybins=False, axes=ax) line = plot.get_children()[0] line.set_markersize(mSize) if (styles[c] > 23): line.set_markerfacecolor('none') #line.set_markeredgecolor(color) line.set_color(colors[c]) ax.set_xlim([0.1, 15]) ax.set_ylim([0.1, 3]) ax.set_xscale('log') plt.tight_layout() plt.subplots_adjust(wspace=0, hspace=0) #Set space between subfigures to 0 plt.savefig("PythonFigures/RcomparisonSignalPt6080.pdf".format(file), format='pdf') #Save figure plt.show() #Draw figure on screen drawWithErrors2Combined(FullJets_gausRMS, FullJets_gammaRMS, 15, 500, 1, 0, 1.65, 0, r'jet $p_T (GeV/c)$', r'$\sqrt{\left<j_T^2\right>}$', 'Pythia', 'PythonFigures/RcomparisonRMS', separate=True) return drawWithErrors2Combined( FullJets_gausYield, FullJets_gammaYield, 15, 500, 1, 0, 10, 0, r'jet $p_T$', r'Yield', 'Pythia', 'PythonFigures/RcomparisonYield', ) ratios = [] for hists in FullJets_jT: if hists is not None: ratio = [] for h, true in zip(hists, FullJets_jT[1]): h2 = h.Clone() h2.Divide(true) ratio.append(h2) else: ratio = None ratios.append(ratio) fig, axs = defs.makegrid(4, 2, xlog=True, ylog=False, d=d, shareY=False) axs = axs.reshape(8) axs[4].set_ylabel("Ratio to R = 0.4", fontsize=labelsize) axs[7].set_ylabel("Ratio to R = 0.4", fontsize=labelsize) axs[1].text( 0.02, 0.005, 'Pythia\n' r'pPb $\sqrt{s_{NN}} = 5.02 \mathrm{TeV}$' '\n Full jets \n' r'Anti-$k_T$', fontsize=7 ) #Add text to second subfigure, first parameters are coordinates in the drawn scale/units for hists, R in zip(FullJets_jT, Rs): for jT, ax, i, pT in zip(hists[2:], axs[0:4], range(0, 9), jetPt[2:]): rplt.errorbar(jT, emptybins=False, xerr=False, label="R = {:.1f}".format(R), axes=ax, fmt='o') #Plot jT histogram, ax.text( 0.3, 1e2, r'$p_{{T,\mathrm{{jet}}}}$:' '\n' r' {:02d}-{:02d} GeV'.format(pT[0], pT[1])) ax.set_xlim([0.01, 20]) #Set x-axis limits ax.set_ylim([5e-4, 2e3]) #Set y-axis limits ax.set_yscale('log') ax.grid(True) for ratio in ratios: for r, ax in zip(ratio[2:], axs[4:8]): rplt.errorbar(r, axes=ax, emptybins=False, xerr=False) ax.set_xlim([0.01, 20]) ax.set_ylim([0.1, 3]) ax.grid(True) axs[0].legend(loc='lower left') plt.savefig("PythonFigures/RcomparisonSignal.pdf", 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 = "rootFiles/legotrain_CF_pPb_2305_20190109_LHC13bcde_minimal.root" separate = 0 start = 2 end = 6 n_figs = end - start 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) compareHistsWithRatio( Mixed_FullJets_R04, ['JtWeightBin', 'JtWeightLeadingRefBin', 'JtWeightLeadingRefBin'], [ 'Jet axis ref.', 'leading ref. (xlong 0.0-0.2)', 'leading ref. (xlong 0.2-0.4)' ], step=1, start=1, extras=['', 'Xlong00', 'Xlong01']) plt.savefig("PythonFigures/JetVsLeadingRefConst.pdf", format='pdf') #Save figure plt.show() sets = compareHistsWithRatio( Mixed_FullJets_R04, [ 'JetConeJtWeightBin', 'JetConeJtWeightLeadingRefBin', 'JetConeJtWeightLeadingRefBin', 'JetConeJtWeightLeadingRefBin', 'JetConeJtWeightLeadingRefBin' ], [ 'Jet axis ref.', 'leading ref.(xlong 0.0-0.2)', 'leading ref.(xlong 0.2-0.4)', 'leading ref.(xlong 0.4-0.6)', 'leading ref. (xlong 0.6-1.0)' ], step=1, extras=['', 'Xlong00', 'Xlong01', 'Xlong02', 'Xlong03']) plt.savefig("PythonFigures/JetVsLeadingRefJetCone.pdf", format='pdf') #Save figure plt.show() JtJet = sets[0][0] JtLeadingxlong00 = sets[1][0] JtLeadingxlong01 = sets[2][0] JtLeadingxlong02 = sets[3][0] JtLeadingxlong03 = sets[4][0] JtLeading = [h.clone() for h in sets[1][0]] for h, s, s2, s3 in zip(JtLeading, sets[2][0], sets[3][0], sets[4][0]): h.Add(s, 1) h.Add(s2, 1) h.Add(s3, 1) jetPt = sets[0][1] jetPtCenter = array('d', [(a + b) / 2.0 for a, b in jetPt]) jetPtErrors = array('d', [(b - a) / 2.0 for a, b in jetPt]) FullJets_fit = [] FullJets_parameters = [] FullJets_gausRMS = [] FullJets_gammaRMS = [] FullJets_gausYield = [] FullJets_gammaYield = [] for jT, title in zip( (JtJet, JtLeading, JtLeadingxlong00, JtLeadingxlong01, JtLeadingxlong02), ("Jet ref.", "Leading ref", "Leading ref.(xlong 0.0-0.2)", "Leading ref.(xlong 0.2-0.4)", "Leading ref.(xlong 0.4-0.6)", "Leading ref.(xlong 0.6-1.0)")): gausRMS = [] gammaRMS = [] gausRMSe = [] gammaRMSe = [] gausYield = [] gammaYield = [] gausYielde = [] gammaYielde = [] fits = [] parameters = [] for h, i in zip(jT, range(Njets)): fit, d = defs.fitJtHisto(h, '', 1, i, 8, title, draw=False) fits.append(fit) parameters.append(d) gausRMS.append(d['gausRMS']) gausRMSe.append(d['gausRMSe']) gammaRMS.append(d['gammaRMS']) gammaRMSe.append(d['gammaRMSe']) gausYield.append(d['gausYield']) gausYielde.append(d['gausYielde']) gammaYield.append(d['gammaYield']) gammaYielde.append(d['gammaYielde']) gausRMSg = Graph(len(gausRMS) - 2) gammaRMSg = Graph(len(gammaRMS) - 2) gausYieldg = Graph(len(gausYield) - 2) gammaYieldg = Graph(len(gammaYield) - 2) for h, he, g in zip((gausYield, gammaYield), (gausYielde, gammaYielde), (gausYieldg, gammaYieldg)): for x, xe, a, e, i in zip(jetPtCenter[2:], jetPtErrors[2:], h[2:], he[2:], range(len(gausRMS) - 2)): g.SetPoint(i, x, a) g.SetPointError(i, xe, xe, e, e) for a, b, c, d, e, f, i in zip(gausRMS[2:], gammaRMS[2:], gausRMSe[2:], gammaRMSe[2:], jetPtCenter[2:], jetPtErrors[2:], range(len(gausRMS) - 2)): gausRMSg.SetPoint(i, e, a) gausRMSg.SetPointError(i, f, f, c, c) gammaRMSg.SetPoint(i, e, b) gammaRMSg.SetPointError(i, f, f, d, d) FullJets_gausRMS.append(gausRMSg) FullJets_gammaRMS.append(gammaRMSg) FullJets_gausYield.append(gausYieldg) FullJets_gammaYield.append(gammaYieldg) FullJets_fit.append(fits) FullJets_parameters.append(parameters) print(gausRMS[2:]) print(gammaRMS[2:]) print(jetPtCenter[2:]) drawWithErrors2Combined(FullJets_gausRMS, FullJets_gammaRMS, [ "Jet ref.", "Leading ref.", "Leading ref.(xlong 0.0-0.2)", "Leading ref.(xlong 0.2-0.4)", "Leading ref.(xlong 0.4-0.6)" ], 15, 500, 1, 0, 1.85, 0, r'jet $p_T$', r'$\sqrt{\left<j_T^2\right>}$', 'Pythia', 'PythonFigures/JetVsLeadingRefJetConeFits') 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="Jet axis reference", fmt='o') #Plot jT histogram, rplt.errorbar(signal2[separate], xerr=False, emptybins=False, axes=ax, label="Leading track reference", fmt='o') 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/MixedFullJetsR04JetConeJtLeadingRefJetPt{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, 2, xlog=True, ylog=True, d=d, shareY=False, figsize=(10, 5)) axs = axs.reshape(8) #axs[1].text(0.12,0.002,d['system'] +'\n'+ d['jettype'] +'\n'+ d['jetalg'] + '\n Jet Cone',fontsize = 7) ratios = [] for jT, jT2, pT, ax, i in zip(JtJet[start:], JtLeading[start:], jetPt[start:], axs[0:4], range(0, 9)): jT.SetMarkerColor(1) jT.SetMarkerStyle(24) jT.SetLineColor(1) #jT.SetMarkerSize(mSize) jT2.SetMarkerColor(2) jT2.SetMarkerStyle(25) #jT2.SetMarkerSize(mSize) jT2.SetLineColor(2) ratio = jT2.Clone() ratio.Divide(jT) ratios.append(ratio) plot = rplt.errorbar(jT, xerr=False, emptybins=False, axes=ax, label="Jet axis reference", fmt='o', fillstyle='none', ecolor='black') #Plot jT histogram, line = plot.get_children()[0] line.set_markersize(mSize) line.set_markerfacecolor('none') plot = rplt.errorbar(jT2, xerr=False, emptybins=False, axes=ax, label="Leading track reference", fmt='o', fillstyle='none', ecolor='red') #Plot jT histogram, line = plot.get_children()[0] line.set_markersize(mSize) line.set_markerfacecolor('none') #line.set_color(color) 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-5, 2e3]) #Set y-axis limits ax.set_xticklabels(ax.get_xticklabels(), horizontalalignment='left') for ratio, ax, i in zip(ratios, axs[4:], range(0, 9)): plot = rplt.errorbar(ratio, xerr=False, emptybins=False, axes=ax, fmt='o', fillstyle='none', ecolor='black') #Plot jT histogram, line = plot.get_children()[0] line.set_markersize(mSize) line.set_markerfacecolor('none') ax.set_yscale('linear') ax.set_xlim([0.1, 22]) #Set x-axis limits ax.set_ylim([0, 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) axs[4].set_ylabel('Ratio') axs[7].set_ylabel('Ratio') plt.savefig( "PythonFigures/MixedFullJetsR04JetConeJtLeadingRefPtFrom{}To{}.pdf" .format(start, end), format='pdf') #Save figure plt.show() #Draw figure on screen
def main(): JetPtBins = [5, 10, 20, 30, 40, 60, 80, 100, 150, 500] jetPtBins2 = [(JetPtBins[i], JetPtBins[i + 1]) for i in range(8)] 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 mSize = 0.3 iS = 0 start = 4 if (os.path.exists('RootFiles/Fig1.root')): inFile = "RootFiles/Fig1.root" inF = root_open(inFile, 'r') errGraph = [ inF.Get("jTSignalJetPt_Syst{:02d}".format(ij)) for ij in range(4) ] hJtSignalGraph = [ inF.Get("jTSignalJetPt_Stat{:02d}".format(ij)) for ij in range(4) ] else: f = root_open("errors_test.root", 'read') errGraph = [ f.Get('JetConeJtWeightBinNFin{:02d}JetPt{:02d}_Systematics'.format( iS, i)) for i in range(start, Njets) ] #Get jT histograms from file an array hJtSignalGraph = [ f.Get('JetConeJtWeightBinNFin{:02d}JetPt{:02d}_Statistics'.format( iS, i)) for i in range(start, Njets) ] #Get jT histograms from file an array outFile = "RootFiles/Fig1.root" outF = root_open(outFile, "w+") for err, signal, i in zip(errGraph, hJtSignalGraph, range(10)): err.SetName("jTSignalJetPt_Syst{:02d}".format(i)) err.Write() signal.SetName("jTSignalJetPt_Stat{:02d}".format(i)) signal.Write() outF.Close() scaleInterval = 1 ylow = 5e-6 yhigh = 5e2 * pow(10, 4 * scaleInterval) xlow = 0.1 xhigh = 4.5 #ax = plt.gca() fig = plt.figure(figsize=(6, 8)) ax = plt.axes([0.2, 0.1, 0.75, 0.85]) ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) for ij, h, h_sys, pT in zip(range(start, Njets), hJtSignalGraph[::-1], errGraph[::-1], jetPtBins2[Njets::-1]): print(ij) print("JetPt {}".format(pT)) power = scaleInterval * (7 - ij) scale = pow(10, power) h = defs.grrScale(h, scale) h.SetMarkerColor(colors[ij - start]) h.SetLineColor(colors[ij - start]) h.SetMarkerStyle(styles[ij - start]) label = r'${:02d}\: < p_{{\mathrm{{T,jet}}}} < {:02d}\:\mathrm{{GeV}}/c \left(\times 10^{}\right)$'.format( pT[0], pT[1], power) plot = rplt.errorbar(h, xerr=False, emptybins=False, axes=ax, label=label, fmt='+') #Plot jT histogram, line = plot.get_children()[0] if (styles[ij - 4] > 23): line.set_markerfacecolor('none') errorboxes = [] n = h_sys.GetN() xs = h_sys.GetX() ys = h_sys.GetY() xerrs = h_sys.GetEX() yerrs = h_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) * scale), xe * 2, ye * 2 * scale) errorboxes.append(rect) pc = PatchCollection(errorboxes, facecolor=colorsBox[ij - 4], alpha=0.5, edgecolor='None') ax.add_collection(pc) #print("({} - {})/9.0 + {} is {}".format(yhigh,ylow,ylow,(yhigh-ylow)/9.0+ylow)) ax.text(1.3, 2e5, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=10) handles, labels = ax.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 ] ax.legend(handles, labels, loc='lower left', numpoints=1) #ax.legend(loc = 'lower left') ax.yaxis.set_ticks_position('both') #Show ticks on left and right side ax.xaxis.set_ticks_position('both') #Show ticks on bottom and top ax.tick_params(which='both', direction='in') #Move ticks from outside to inside ytitle = r'$\frac{1}{N_{jets}}\;\frac{1}{j_\mathrm{T}}\;\frac{\mathrm{d} N}{\mathrm{d} j_\mathrm{T}}$' xtitle = r'$j_\mathrm{T}\left(\mathrm{GeV}/c\right)$' ax.set_ylabel(ytitle, fontsize=16) ax.set_xlabel(xtitle, fontsize=16) ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) ax.set_xscale('log') ax.set_yscale('log') plt.savefig("PythonFigures/jTwithSystematics.pdf", format='pdf') #Save figure plt.show() #Draw figure on screen
def legend_darklight(axes, darklabel='Monte Carlo', lightlabel='Analytic', errtype=None, twosigma=False, extralabel=None): """Makes a legend for the ax object 'axes' at the location 'loc', which indicates dark solid lines as 'MC' (or darklabel) and light dotted lines as 'Analytic' (or lightlabel). Parameters ---------- axes : axes.Axes Description of parameter `axes`. darklabel : str Label of the dark objects in the legend. lightlabel : str Label of the light objects in the legend. errtype : str Specifies the plot type of the `dark` data, and thus the corresponding legend icon. None (default): legend for line plot. yerr: legend for a plot with ecolor modstyle: legend for a modstyle errorbar plot twosigma : bool Determines whether to include lighter, two sigma error bars in the legend. Returns ------- type Description of returned object. """ if errtype is None: custom_lines = [Line2D([0], [0], **style_solid, color=compcolors[(-1, 'dark')]), Line2D([0], [0], **style_dashed, color=compcolors[(-1, 'light')])] axes.legend(custom_lines, [darklabel, lightlabel]) elif errtype == 'yerr': _, xmax = axes.get_xlim() axes.errorbar(xmax*50., 0, yerr=1., **style_yerr, color='black', ecolor='gray', label=darklabel) if twosigma: axes.errorbar(xmax*50., 0, yerr=2., **style_yerr, color='black', ecolor='lightgray', label=darklabel) if extralabel is not None: axes.errorbar(xmax*50., 0, yerr=1., **style_yerr_ps, color=compcolors[(-1, 'medium')], ecolor=compcolors[(-1, 'light')], label=extralabel) if twosigma: axes.errorbar(xmax*50., 0, yerr=2., **style_yerr_ps, color=compcolors[(-1, 'medium')], ecolor=compcolors[(-1, 'light')], label=extralabel) handles, _ = axes.get_legend_handles_labels() if twosigma: l = 0 # Setting up containers for both errorbars if extralabel is not None: twosig_extra = container.ErrorbarContainer( handles[-1].lines, has_xerr=False, has_yerr=True) onesig_extra = container.ErrorbarContainer( handles[-2].lines, has_xerr=False, has_yerr=True) l = -2 twosig = container.ErrorbarContainer( handles[l-1].lines, has_xerr=False, has_yerr=True) # Setting up containers for both errorbars onesig = container.ErrorbarContainer( handles[l-2].lines, has_xerr=False, has_yerr=True) if extralabel is not None: custom_handles = [(twosig, onesig), (twosig_extra, onesig_extra)] else: custom_handles = [(twosig, onesig)] else: l = 0 # Setting up containers for both errorbars if extralabel is not None: onesig_extra = container.ErrorbarContainer( handles[-1].lines, has_xerr=False, has_yerr=True) l=-1 onesig = container.ErrorbarContainer( handles[l-1].lines, has_xerr=False, has_yerr=True) if extralabel is not None: custom_handles = [onesig, onesig_extra] else: custom_handles = [onesig] custom_handles.append( Line2D([0], [0], **style_dashed, color=compcolors[(-1, 'light')]) ) if twosigma: if extralabel is not None: axes.legend(custom_handles, [darklabel, extralabel, lightlabel], handler_map={ onesig: HandlerErrorbar(xerr_size=0.37), twosig: HandlerErrorbar(xerr_size=0.65), onesig_extra: HandlerErrorbar(xerr_size=0.37), twosig_extra: HandlerErrorbar(xerr_size=0.65)} ) else: axes.legend(custom_handles, [darklabel, lightlabel], handler_map={ onesig: HandlerErrorbar(xerr_size=0.37), twosig: HandlerErrorbar(xerr_size=0.65)} ) else: if extralabel is not None: axes.legend(custom_handles, [darklabel, extralabel, lightlabel]) else: axes.legend(custom_handles, [darklabel, lightlabel]) elif errtype == 'modstyle': _, xmax = axes.get_xlim() axes.errorbar(xmax*50., 0, yerr=1., **modstyle, color=compcolors[(-1, 'dark')], label=darklabel) if extralabel is not None: axes.errorbar(xmax*50., 0, yerr=1., **modstyle_ps, color=compcolors[(-1, 'medium')], label=extralabel) handles, _ = axes.get_legend_handles_labels() # Setting up containers for errorbars l = 0 if extralabel is not None: onesig_extra = container.ErrorbarContainer( handles[-1].lines, has_xerr=True, has_yerr=True) l=-1 onesig = container.ErrorbarContainer(handles[l-1].lines, has_xerr=True, has_yerr=True) if extralabel is not None: custom_handles = [onesig, onesig_extra] else: custom_handles = [onesig] custom_handles.append( Line2D([0], [0], **style_dashed, color=compcolors[(-1, 'light')]) ) if extralabel is not None: axes.legend(custom_handles, [darklabel, extralabel, lightlabel], prop={'size': 15}, loc='upper left') else: axes.legend(custom_handles, [darklabel, lightlabel])
def drawWithErrors2Combined(h, h_sys, h2, h2_sys, xlow, xhigh, logx, ylow, yhigh, ylog, xTitle, yTitle, title, comment, file, iS, ij, **kwargs): print("DrawWithErrors2Combined") ax = plt.gca() ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) ax.set_xlabel(xTitle, fontsize=labelsize) #Add x-axis labels for bottom row ax.set_ylabel(yTitle, fontsize=labelsize) #Add x-axis labels for bottom row h.SetMarkerColor('black') h.SetLineColor('black') if ('pythiaW' in kwargs): pythiaW = kwargs.get('pythiaW') for x, c, l in zip(pythiaW, ("black", "red", "blue", "green"), ('-', '--', '-.', ':')): hPythiaW = x[0] hPythiaW.SetMarkerColor(c) hPythiaW.SetLineColor(c) hPythiaW.SetMarkerStyle(25) print(x[1]) plot = rplt.errorbar(hPythiaW, xerr=False, yerr=False, emptybins=False, fillstyle='none', axes=ax) line1, = plt.plot([1, 2, 3], label=x[1], linestyle=l, color=c) line = plot.get_children()[0] line.set_markerfacecolor('none') line.set_markeredgecolor('none') line.set_drawstyle('default') line.set_linestyle(l) line.set_color(c) if ('pythiaN' in kwargs): pythiaN = kwargs.get('pythiaN') for x, c, l in zip(pythiaN, ("black", "red", "blue", "green"), ('-', '--', '-.', ':')): hPythiaN = x[0] hPythiaN.SetMarkerColor(c) hPythiaN.SetLineColor(c) hPythiaN.SetMarkerStyle(24) plot = rplt.errorbar(hPythiaN, xerr=False, yerr=False, emptybins=False, fillstyle='none', axes=ax, label="_{}".format(x[1])) line = plot.get_children()[0] line.set_markerfacecolor('none') line.set_markeredgecolor('none') line.set_drawstyle('default') line.set_linestyle(l) line.set_color(c) if ('pythiaN' in kwargs): h2.SetMarkerColor('red') h2.SetLineColor('red') h2.SetMarkerStyle(25) h.SetMarkerStyle(24) plot1 = rplt.errorbar(h2, xerr=False, emptybins=False, axes=ax, label='ALICE wide') plot2 = rplt.errorbar(h, xerr=False, emptybins=False, axes=ax, label='ALICE Narrow') line = plot1.get_children()[0] #line.set_markerfacecolor('none') line.set_markeredgecolor('red') line = plot2.get_children()[0] #line.set_markerfacecolor('none') line.set_markeredgecolor('black') elif ('jussiW' in kwargs): h2.SetMarkerColor('red') h2.SetLineColor('red') h2.SetMarkerStyle(25) h.SetMarkerStyle(24) plot1 = rplt.errorbar(h2, xerr=False, emptybins=False, axes=ax, label=r'Jet $j_\mathrm{T}$ Wide') plot2 = rplt.errorbar(h, xerr=False, emptybins=False, axes=ax, label=r'Jet $j_\mathrm{T}$ Narrow') line = plot1.get_children()[0] #line.set_markerfacecolor('none') line.set_markeredgecolor('red') line = plot2.get_children()[0] #line.set_markerfacecolor('none') line.set_markeredgecolor('black') else: h2.SetMarkerColor('red') h2.SetLineColor('red') h2.SetMarkerStyle(25) h.SetMarkerStyle(24) plot1 = rplt.errorbar(h2, xerr=False, emptybins=False, axes=ax, label='Wide') plot2 = rplt.errorbar(h, xerr=False, emptybins=False, axes=ax, label='Narrow') line = plot1.get_children()[0] #line.set_markerfacecolor('none') line.set_markeredgecolor('red') line = plot2.get_children()[0] #line.set_markerfacecolor('none') line.set_markeredgecolor('black') if ('jussiW' in kwargs): hJussiW = kwargs.get('jussiW') hJussiW.SetMarkerColor('red') hJussiW.SetLineColor('red') hJussiW.SetMarkerStyle(25) plot = rplt.errorbar(hJussiW, xerr=False, emptybins=False, fillstyle='none', axes=ax, label=r'Dihadron $j_\mathrm{T}$ Wide') line = plot.get_children()[0] line.set_markerfacecolor('none') line.set_markeredgecolor('red') if ('jussiN' in kwargs): hJussiN = kwargs.get('jussiN') hJussiN.SetMarkerColor('black') hJussiN.SetLineColor('black') hJussiN.SetMarkerStyle(24) plot = rplt.errorbar(hJussiN, xerr=False, emptybins=False, fillstyle='none', axes=ax, label=r'Dihadron $j_\mathrm{T}$ Narrow') line = plot.get_children()[0] line.set_markerfacecolor('none') line.set_markeredgecolor('black') print("Errorboxes") errorboxes = [] n = h_sys.GetN() xs = h_sys.GetX() ys = h_sys.GetY() xerrs = h_sys.GetEX() yerrs = h_sys.GetEY() for x in (xs, ys, xerrs, yerrs): x.SetSize(n) yeC = kwargs.get('narrowE', 0) for x, y, xe, ye in zip(xs, ys, xerrs, yerrs): if (yeC > 0): ye2 = yeC * y ye = math.sqrt(ye**2 + ye2**2) rect = Rectangle((x - boxwidth, y - ye), boxwidth * 2, ye * 2) errorboxes.append(rect) errorboxes2 = [] n = h2_sys.GetN() xs = h2_sys.GetX() ys = h2_sys.GetY() xerrs = h2_sys.GetEX() yerrs = h2_sys.GetEY() for x in (xs, ys, xerrs, yerrs): x.SetSize(n) yeC = kwargs.get('wideE', 0) for x, y, xe, ye in zip(xs, ys, xerrs, yerrs): if (yeC > 0): ye2 = yeC * y ye = math.sqrt(ye**2 + ye2**2) rect = Rectangle((x - boxwidth, y - ye), boxwidth * 2, ye * 2) errorboxes2.append(rect) pc = PatchCollection(errorboxes, facecolor='0.65', alpha=0.6, edgecolor='None') ax.add_collection(pc) pc2 = PatchCollection(errorboxes2, facecolor='0.65', alpha=0.6, edgecolor='None') ax.add_collection(pc2) print("({} - {})/9.0 + {} is {}".format(yhigh, ylow, ylow, (yhigh - ylow) / 9.0 + ylow)) if ('titleLoc' in kwargs): x_tit, y_tit = kwargs.get('titleLoc') ax.text(x_tit, y_tit, title + '\n' + d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=10) else: if ('jussiW' not in kwargs): ax.text((xhigh - xlow) * 0.1 + xlow, 4 * (yhigh - ylow) / 5.0 + ylow, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=10) else: ax.text((xhigh - xlow) * 0.1 + xlow, 4 * (yhigh - ylow) / 5.0 + ylow, d['system'] + '\n' + d['jettype'] + '\n' + d['jetalg'] + '\n' + d['cut'], fontsize=10) handles, labels = ax.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 ] #ax.legend(handles,labels,loc = 'lower left',numpoints=1) if (len(labels) > 4): ax.legend(np.delete(handles, 4), np.delete(labels, 4), loc='upper left') ax.text((xhigh - xlow) * 0.09 + xlow, 0.57 * (yhigh - ylow) + ylow, "ALICE", weight='bold') else: ax.legend(handles, labels, loc='upper right') if (len(labels) > 2): ax.text((xhigh - xlow) * 0.770 + xlow, 0.66 * (yhigh - ylow) + ylow, "ALICE", weight='bold') else: ax.text((xhigh - xlow) * 0.770 + xlow, 0.80 * (yhigh - ylow) + ylow, "ALICE", weight='bold') #ax.legend(loc = 'upper left') ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) ax.tick_params(which='both', direction='in') #Move ticks from outside to inside plt.savefig("{}.pdf".format(file), 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 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
def main(): Njets = 9 if (os.path.exists('RootFiles/Fig6.root')): inFile = "RootFiles/Fig6.root" inF = root_open(inFile, 'r') FullJets_gausRMS = [ inF.Get("FullJets_gausRMS_R{:02d}".format(int(R * 10))) for R in Rs ] FullJets_gammaRMS = [ inF.Get("FullJets_gammaRMS_R{:02d}".format(int(R * 10))) for R in Rs ] FullJets_jT = [] for R in Rs: h = [ inF.Get("jTSignalJetPt{:02d}_R{:02d}".format(ij, int(R * 10))) for ij in range(8) ] FullJets_jT.append(h) jetPt = [ (int( re.search(r'p_{T,jet} : ([\d]*)\.[\d] - ([\d]*).[\d]*', h.GetTitle(), re.M | re.I).group(1)), int( re.search(r'p_{T,jet} : ([\d]*)\.[\d] - ([\d]*).[\d]*', h.GetTitle(), re.M | re.I).group(2))) for h in FullJets_jT[0] ] #Use regular expressions to extract jet pT range from histogram titles jetPtCenter = array('d', [(a + b) / 2.0 for a, b in jetPt]) jetPtErrors = array('d', [(b - a) / 2.0 for a, b in jetPt]) else: filename = "CF_pPb_MC_legotrain/legotrain_610_20181010-1926_LHCb4_fix_CF_pPb_MC_ptHardMerged.root" f = root_open(filename, 'read') FullJets_jT = [] for iF, c in zip((8, 6, 7), colors): jT = [ f.get( 'AliJJetJtTask/AliJJetJtHistManager/JetConeJtWeightBin/JetConeJtWeightBinNFin{:02d}JetPt{:02d}' .format(iF, ij)) for ij in range(Njets) ] bgJt = [ f.get( 'AliJJetJtTask/AliJJetJtHistManager/BgJtWeightBin/BgJtWeightBinNFin{:02d}JetPt{:02d}' .format(iF, ij)) for ij in range(Njets) ] jetPtBin = [ f.get( 'AliJJetJtTask/AliJJetJtHistManager/JetPtBin/JetPtBinNFin{:02d}JetPt{:02d}' .format(iF, ij)) for ij in range(Njets) ] nJets = [h.Integral() for h in jetPtBin] nBgs = [ f.get( 'AliJJetJtTask/AliJJetJtHistManager/BgTrkNumberBin/BgTrkNumberBinNFin{:02d}JetPt{:02d}' .format(iF, ij)).Integral() for ij in range(Njets) ] FullJets_jT.append(jT) #FullJets_bgJt.append(bgJt) #FullJets_jetPtBin.append(jetPtBin) for j, b, nj, nb in zip(jT, bgJt, nJets, nBgs): j.Rebin(2) b.Rebin(2) j.Scale(1.0 / nj, "width") b.Scale(1.0 / nb, "width") j.SetMarkerColor(c) b.SetMarkerColor(c) j.Add(b, -1.0) jetPt = [ (int( re.search(r'p_{T,jet} : ([\d]*)\.[\d] - ([\d]*).[\d]*', h.GetTitle(), re.M | re.I).group(1)), int( re.search(r'p_{T,jet} : ([\d]*)\.[\d] - ([\d]*).[\d]*', h.GetTitle(), re.M | re.I).group(2))) for h in FullJets_jT[0] ] #Use regular expressions to extract jet pT range from histogram titles jetPtCenter = array('d', [(a + b) / 2.0 for a, b in jetPt]) jetPtErrors = array('d', [(b - a) / 2.0 for a, b in jetPt]) FullJets_fit = [] FullJets_parameters = [] FullJets_gausRMS = [] FullJets_gammaRMS = [] FullJets_gausYield = [] FullJets_gammaYield = [] for jT in FullJets_jT: gausRMS = [] gammaRMS = [] gausRMSe = [] gammaRMSe = [] gausYield = [] gammaYield = [] gausYielde = [] gammaYielde = [] fits = [] parameters = [] for h, i in zip(jT, range(Njets)): fit, d = fitJtHisto(h, '', 1, i, 8) fits.append(fit) parameters.append(d) gausRMS.append(d['gausRMS']) gausRMSe.append(d['gausRMSe']) gammaRMS.append(d['gammaRMS']) gammaRMSe.append(d['gammaRMSe']) gausYield.append(d['gausYield']) gausYielde.append(d['gausYielde']) gammaYield.append(d['gammaYield']) gammaYielde.append(d['gammaYielde']) gausRMSg = Graph(len(gausRMS) - 2) gammaRMSg = Graph(len(gammaRMS) - 2) gausYieldg = Graph(len(gausYield) - 2) gammaYieldg = Graph(len(gammaYield) - 2) for h, he, g in zip((gausYield, gammaYield), (gausYielde, gammaYielde), (gausYieldg, gammaYieldg)): for x, xe, a, e, i in zip(jetPtCenter[2:], jetPtErrors[2:], h[2:], he[2:], range(len(gausRMS) - 2)): g.SetPoint(i, x, a) g.SetPointError(i, xe, xe, e, e) for a, b, c, d, e, f, i in zip(gausRMS[2:], gammaRMS[2:], gausRMSe[2:], gammaRMSe[2:], jetPtCenter[2:], jetPtErrors[2:], range(len(gausRMS) - 2)): gausRMSg.SetPoint(i, e, a) gausRMSg.SetPointError(i, f, f, c, c) gammaRMSg.SetPoint(i, e, b) gammaRMSg.SetPointError(i, f, f, d, d) FullJets_gausRMS.append(gausRMSg) FullJets_gammaRMS.append(gammaRMSg) FullJets_gausYield.append(gausYieldg) FullJets_gammaYield.append(gammaYieldg) FullJets_fit.append(fits) FullJets_parameters.append(parameters) outFile = "Python/RootFiles/Fig6.root" outF = root_open(outFile, "w+") for h1, h2, jT, R in zip(FullJets_gausRMS, FullJets_gammaRMS, FullJets_jT, Rs): h1.SetName("FullJets_gausRMS_R{:02d}".format(int(R * 10))) h1.Write() h2.SetName("FullJets_gammaRMS_R{:02d}".format(int(R * 10))) h2.Write() for h, i in zip(jT, range(10)): h.SetName("jTSignalJetPt{:02d}_R{:02d}".format(i, int(R * 10))) h.Write() outF.Close() fig, axs = plt.subplots(2, 1, figsize=(7, 7)) ax = axs[0] ax.set_xlim([0.1, 15]) ax.set_ylim([5e-6, 2e3]) ax.set_xlabel(r'$j_{T}\left(GeV/c\right)$', fontsize=labelsize) ax.set_ylabel(r'$\frac{1}{N_{jets}}\frac{dN}{j_{T}dj_{T}}$', fontsize=labelsize) ratios = [] ax.set_xscale('log') ax.set_yscale('log') for h, c, R in zip(FullJets_jT, (0, 1, 2, 3), Rs): h[6].SetMarkerColor(colors[c]) h[6].SetMarkerStyle(styles[c]) h[6].SetLineColor(colors[c]) ratio = h[6].Clone() ratio.Divide(FullJets_jT[1][6]) ratios.append(ratio) plot = rplt.errorbar(h[6], xerr=False, emptybins=False, label='R = {:.1f}'.format(R), axes=ax, fmt='+') line = plot.get_children()[0] line.set_markersize(mSize) if (styles[c] > 23): line.set_markerfacecolor('none') #line.set_markeredgecolor(color) line.set_color(colors[c]) ax.text(0.15, 0.001, 'Pythia \n Full Jets\n' + r'Anti-$k_T$' + '\n' + r'$p_{{T,\mathrm{{jet}}}}$: {:02d}-{:02d} GeV/c'.format(60, 80), fontsize=10) handles, labels = ax.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 ] ax.legend(handles, labels, loc='upper right', numpoints=1) #ax.legend(loc = 'upper right') ax.set_xlim([0.1, 15]) ax.set_ylim([5e-6, 2e3]) ax.grid(True) ax = axs[1] ax.grid(True) ax.set_xlabel(r'$j_{T}\left[GeV\right]$', fontsize=labelsize) ax.set_ylabel('Ratio', fontsize=labelsize) #Add x-axis labels for bottom row for ratio, c in zip(ratios, (0, 1, 2, 3)): #ratio.SetMarkerColor(c) #ratio.SetMarkerStyle(24) plot = rplt.errorbar(ratio, xerr=False, emptybins=False, axes=ax) line = plot.get_children()[0] line.set_markersize(mSize) if (styles[c] > 23): line.set_markerfacecolor('none') #line.set_markeredgecolor(color) line.set_color(colors[c]) ax.set_xlim([0.1, 15]) ax.set_ylim([0.1, 3]) ax.set_xscale('log') plt.tight_layout() plt.subplots_adjust(wspace=0, hspace=0) #Set space between subfigures to 0 #plt.savefig("PythonFigures/RcomparisonSignalPt6080.pdf".format(file),format='pdf') #Save figure plt.show() #Draw figure on screen drawWithErrors2Combined(FullJets_gausRMS, FullJets_gammaRMS, 15, 500, 1, 0, 1.65, 0, r'jet $p_T (GeV/c)$', r'$\sqrt{\left<j_T^2\right>}$', 'Pythia', 'PythonFigures/RcomparisonRMS', separate=True)
def drawWithErrors2Combined(hists, hists2, xlow, xhigh, logx, ylow, yhigh, ylog, xTitle, yTitle, title, file, separate=False): #colors = ['white','black','red','green','blue'] if (separate): fig, axs = plt.subplots(2, 2, sharex=True, figsize=(7, 7)) axs = axs.reshape(4) axs[0].grid(True) for ax in axs: ax.yaxis.set_ticks_position('both') ax.tick_params(which='both', direction='in') for ax in axs[1::2]: ax.yaxis.set_label_position('right') ax.yaxis.tick_right() ax.tick_params(which='both', direction='in') else: fig, axs = plt.subplots(2, 1, sharex=True, figsize=(7, 7)) ax = axs[0] ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) ax.set_xlabel(xTitle, fontsize=labelsize) #Add x-axis labels for bottom row ax.set_ylabel(yTitle, fontsize=labelsize) #Add x-axis labels for bottom row if (separate): axs[1].set_ylabel(yTitle, fontsize=labelsize) ax.set_ylabel(yTitle, fontsize=labelsize) #Add x-axis labels for bottom row ratios1 = [] ratios2 = [] if logx: ax.set_xscale('log') for h, h2, c, R in zip(hists, hists2, (0, 1, 2, 3), Rs): ax = axs[0] h.SetMarkerColor(colors[c]) h.SetMarkerStyle(styles[c]) h.SetLineColor(colors[c]) h2.SetMarkerColor(colors[c]) h2.SetMarkerStyle(styles[c]) h2.SetLineColor(colors[c]) ratios1.append(grrDivide(h, hists[1])) ratios2.append(grrDivide(h2, hists2[1])) if (separate): plot = rplt.errorbar(h, xerr=False, emptybins=False, label='R = {:.1f}'.format(R), axes=ax, fmt='+') else: if c == 1: plot = rplt.errorbar(h, xerr=False, emptybins=False, label='Narrow', axes=ax, fmt='+') else: plot = rplt.errorbar(h, xerr=False, emptybins=False, axes=ax, fmt='+') #rplt.errorbar(h,xerr=False,emptybins=False,axes=ax,fmt='+') line = plot.get_children()[0] if (styles[c] > 23): line.set_markerfacecolor('none') line.set_color(colors[c]) if (separate): ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) ax = axs[1] ax.grid(True) ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) if (R > 0): if (separate): plot = rplt.errorbar(h2, xerr=False, yerr=True, emptybins=False, axes=ax, label='R = {:.1f}'.format(R), fmt='+') else: plot = rplt.errorbar(h2, xerr=False, yerr=True, emptybins=False, axes=ax, label='R = {:.1f} Wide'.format(R), fmt='+') line = plot.get_children()[0] if (styles[c] > 23): line.set_markerfacecolor('none') line.set_color(colors[c]) else: rplt.errorbar(h2, xerr=False, emptybins=False, axes=ax, label='R = {:.1f} Data'.format(-R), fmt='+') print("({} - {})/9.0 + {} is {}".format(yhigh, ylow, ylow, (yhigh - ylow) / 9.0 + ylow)) if (separate): axs[1].text(65, 0.2, title + '\n' + d['system'] + '\n' + d['jettype'] + '\n' + r'Anti-$k_T$', fontsize=10) axs[1].text(102, 1.22, "Wide") axs[0].text(102, 1.22, "Narrow") else: axs[0].text(100, (yhigh - ylow) / 3.0 + ylow, title + '\n' + d['system'] + '\n' + d['jettype'] + '\n' + r'Anti-$k_T$', fontsize=10) #axs[0].legend(loc = 'upper left') 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='upper left', numpoints=1) if (separate): for ax in axs[0:2]: ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) ax.grid(True) else: ax.set_xlim([xlow, xhigh]) ax.set_ylim([ylow, yhigh]) if (separate): ax = axs[2] ax2 = axs[3] else: ax = axs[1] ax2 = axs[1] ax.grid(True) ax2.grid(True) ax.set_xlabel(xTitle, fontsize=labelsize) #Add x-axis labels for bottom row ax2.set_xlabel(xTitle, fontsize=labelsize) #Add x-axis labels for bottom row ax.set_ylabel('Ratio', fontsize=labelsize) #Add x-axis labels for bottom row ax2.set_ylabel('Ratio', fontsize=labelsize) #Add x-axis labels for bottom row for ratio, ratio2, c in zip(ratios1, ratios2, (0, 1, 2, 3)): ratio.SetMarkerColor(colors[c]) ratio2.SetMarkerColor(colors[c]) ratio.SetMarkerStyle(styles[c]) ratio2.SetMarkerStyle(styles[c]) ratio.SetLineColor(colors[c]) ratio2.SetLineColor(colors[c]) plot = rplt.errorbar(ratio, xerr=False, yerr=True, emptybins=False, axes=ax) line = plot.get_children()[0] if (styles[c] > 23): line.set_markerfacecolor('none') line.set_color(colors[c]) plot = rplt.errorbar(ratio2, xerr=False, yerr=True, emptybins=False, axes=ax2) line = plot.get_children()[0] if (styles[c] > 23): line.set_markerfacecolor('none') line.set_color(colors[c]) ax.set_xlim([xlow, xhigh]) ax.set_ylim([0.8, 1.22]) if (separate): ax2.set_xlim([xlow, xhigh]) ax2.set_ylim([0.8, 1.22]) ax2.grid(True) if logx: ax.set_xscale('log') if (separate): ax2.set_xscale('log') plt.tight_layout() plt.subplots_adjust(wspace=0, hspace=0) #Set space between subfigures to 0 plt.savefig("{}.pdf".format(file), format='pdf') #Save figure plt.show() #Draw figure on screen