|
| 1 | +# This file is part of gLund by S. Carrazza and F. A. Dreyer |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +from glund.read_data import Jets |
| 4 | +from glund.JetTree import JetTree, LundImage, SoftDropMult |
| 5 | +from mpl_toolkits.axes_grid1 import make_axes_locatable |
| 6 | +from scipy.interpolate import interp2d |
| 7 | +import numpy as np |
| 8 | +import argparse,math |
| 9 | + |
| 10 | +def n_sd(image, xbins, ybins, beta, zcut, thetacut, R0=1.0): |
| 11 | + """The soft drop multiplicity of an image. Assumes y-axis=kappa""" |
| 12 | + nsd=0 |
| 13 | + dx=xbins[1]-xbins[0] |
| 14 | + dy=ybins[1]-ybins[0] |
| 15 | + for ix in range(image.shape[0]): |
| 16 | + for iy in range(image.shape[1]): |
| 17 | + if (image[ix,iy]>0.0): |
| 18 | + delta = np.exp(xbins[ix]+np.random.uniform(-dx/2,dx/2)) |
| 19 | + z = np.exp(ybins[iy]+np.random.uniform(-dy/2,dy/2))/delta |
| 20 | + if (delta > thetacut and z > zcut * ((delta/R0)**beta)): |
| 21 | + nsd+=1 |
| 22 | + return nsd |
| 23 | + |
| 24 | +#---------------------------------------------------------------------- |
| 25 | +def plot_sdmult(filedic, imgs_ref, figname, nsd_ref, npx=24, zcut=0.007, beta=-1, thetacut=0.0): |
| 26 | + """Plot a slice in kt of the lund image for different models and a reference sample.""" |
| 27 | + xvals=np.linspace(LundImage.xval[0], LundImage.xval[1], npx+1) |
| 28 | + yvals=np.linspace(LundImage.yval[0], LundImage.yval[1], npx+1) |
| 29 | + xbins=np.array([0.5*(xvals[i]+xvals[i+1]) for i in range(len(xvals)-1)]) |
| 30 | + ybins=np.array([0.5*(yvals[i]+yvals[i+1]) for i in range(len(yvals)-1)]) |
| 31 | + |
| 32 | + yy=np.linspace(LundImage.yval[0], LundImage.yval[1], 10000) |
| 33 | + xx=np.linspace(LundImage.xval[0], LundImage.xval[1], 10000) |
| 34 | + |
| 35 | + fct= {} |
| 36 | + nsd= {} |
| 37 | + for lab in filedic.keys(): |
| 38 | + ims = np.load(filedic[lab]) |
| 39 | + im = np.average(ims, axis=0) |
| 40 | + f = interp2d(xbins, ybins, im, kind='linear') #linear, cubic, quintic |
| 41 | + fct[lab] = f |
| 42 | + nsd[lab]=[] |
| 43 | + for i in range(ims.shape[0]): |
| 44 | + nsd[lab].append(n_sd(ims[i], xbins, ybins, beta, zcut, thetacut)) |
| 45 | + |
| 46 | + nsd_ref_im = [] |
| 47 | + for i in range(len(imgs_ref)): |
| 48 | + nsd_ref_im.append(n_sd(imgs_ref[i], xbins, ybins, beta, zcut, thetacut)) |
| 49 | + |
| 50 | + fig, ax = plt.subplots(figsize=(5,3.5)) |
| 51 | + bins = np.arange(0, 25, 1) |
| 52 | + for lab in nsd.keys(): |
| 53 | + plt.hist(nsd[lab], bins=bins, histtype='step', density=True, label=lab) |
| 54 | + plt.hist(nsd_ref_im, bins=bins, histtype='step', density=True, label='Pythia 8') |
| 55 | + plt.hist(nsd_ref, bins=bins, histtype='step', color='C3', ls=':', density=True) |
| 56 | + plt.text(0.4,0.275,'$z_\mathrm{cut}=%.3f,\, \\beta=%i,\, \\theta_\mathrm{cut}=%.1f$' % (zcut,beta,thetacut)) |
| 57 | + ax.set_xlim((0,12)) |
| 58 | + ax.set_ylim((0.0,0.30)) |
| 59 | + ax.set_xlabel('$n_\mathrm{SD}$') |
| 60 | + plt.legend() |
| 61 | + ax.grid(linestyle=':') |
| 62 | + plt.savefig(figname, bbox_inches='tight') |
| 63 | + plt.close() |
| 64 | + |
| 65 | +#---------------------------------------------------------------------- |
| 66 | +def main(args): |
| 67 | + zcut=0.007 |
| 68 | + beta=-1 |
| 69 | + thetacut=0.0009 |
| 70 | + if args.data: |
| 71 | + sdmult=SoftDropMult(zcut=zcut, beta=beta, thetacut=thetacut) |
| 72 | + reader=Jets(args.data, args.nev) |
| 73 | + events=reader.values() |
| 74 | + imgs_ref=np.zeros((len(events), args.npx, args.npx)) |
| 75 | + li_gen=LundImage(npxlx = args.npx, y_axis=args.yaxis) |
| 76 | + nsd_ref=[] |
| 77 | + for i, jet in enumerate(events): |
| 78 | + tree = JetTree(jet) |
| 79 | + nsd_ref.append(sdmult(tree)) |
| 80 | + imgs_ref[i]=li_gen(tree) |
| 81 | + imgref=np.average(imgs_ref,axis=0) |
| 82 | + else: |
| 83 | + imgref=None |
| 84 | + folder = args.output.strip('/')+'/' if args.output else '' |
| 85 | + |
| 86 | + assert(len(args.label_data_pairs)%2==0) |
| 87 | + filedic={} |
| 88 | + for i in range(0,len(args.label_data_pairs),2): |
| 89 | + lab=args.label_data_pairs[i] |
| 90 | + filedic[lab] = args.label_data_pairs[i+1] |
| 91 | + |
| 92 | + print('Plotting soft drop multiplicity') |
| 93 | + plot_sdmult(filedic, imgs_ref, folder+'softdropmult.pdf', nsd_ref, npx=args.npx, |
| 94 | + zcut=zcut, beta=beta, thetacut=thetacut) |
| 95 | + |
| 96 | +#---------------------------------------------------------------------- |
| 97 | +if __name__ == "__main__": |
| 98 | + parser = argparse.ArgumentParser(description='Plot a kt and delta slice.') |
| 99 | + parser.add_argument('--data', type=str, help='The reference data file') |
| 100 | + parser.add_argument('--output', type=str, default='', help='Output folder') |
| 101 | + parser.add_argument('--npx',type=int, default=24, help='Pixel number') |
| 102 | + parser.add_argument('--nev',type=int, default=-1, help='Pixel number') |
| 103 | + parser.add_argument('label_data_pairs', type=str, nargs='+', |
| 104 | + help='List of label and generated data files.') |
| 105 | + parser.add_argument('--y-axis', type=str, dest='yaxis', help='Type of y axis') |
| 106 | + args = parser.parse_args() |
| 107 | + main(args) |
0 commit comments