def get_effhist(ax1,image,name=None): colors = plot.colors get_effhist.color_index+=1 data = image.imdata[~np.isnan(image.imdata)].flatten() if np.nanmin(data) == 0: binn = np.logspace(1,np.log10(np.nanmax(data))) label = plot.sn_mag(image.nprim)+" primaries\nMin: "+str(0)+"\nMax: "+plot.sn(np.nanmax(data)) else: binn = np.logspace(np.log10(np.nanmin(data)),np.log10(np.nanmax(data))) label = plot.sn_mag(image.nprim)+" primaries\nMin: "+plot.sn(np.nanmin(data))+"\nMax: "+plot.sn(np.nanmax(data)) hist,bins = np.histogram(data, bins=binn) center = (bins[:-1] + bins[1:]) / 2 bins=center # hist[0] = 0 # hist[-1] = 0 if name is None: ax1.plot(bins,hist/float(hist.max()),label=label,color=colors[get_effhist.color_index],drawstyle='steps') else: ax1.plot(bins,hist/float(hist.max()),label=name+'\nMedian gain: '+plot.sn(np.median(data)),color=colors[get_effhist.color_index],drawstyle='steps') ax1.semilogx() plot.texax(ax1) # print 'Median of efficiency:',np.median(data) # print 'Mean of efficiency:',np.mean(data) return [np.nanmin(data),np.median(data),np.nanmax(data),np.mean(data)]
def plot_all_ranges(ax1,ct): for i in range(len(ct['ct']['data'])): x,y,fo=ct['ct']['x'],ct['ct']['data'][i],ct['ct']['falloff'][i] ax1.step(x, y, label=ct['name']+'ct', color='steelblue', lw=1, where='mid',clip_on=False, alpha=0.5) ax1.axvline(fo, color='steelblue', ls='-',lw=1, alpha=0.5) ax1.set_xlabel('Depth [mm]', fontsize=FONTSIZE) ax1.set_ylabel('PG detected [counts]', fontsize=FONTSIZE) ax1.set_title(plot.sn(ct['nprim'],0)+' primaries', fontsize=Fontsize) plot.texax(ax1) for i in range(len(ct['rpct']['data'])): x,y,fo=ct['rpct']['x'],ct['rpct']['data'][i],ct['rpct']['falloff'][i] ax1.step(x, y, label=ct['name']+'ct', color='indianred', lw=1, where='mid',clip_on=False, alpha=0.5) ax1.axvline(fo, color='indianred', ls='-',lw=1, alpha=0.5) if str(ct['nprim'])[1] == '0': ax1.set_title('PG detection for '+plot.sn_mag(ct['nprim'])+' primaries', fontsize=Fontsize) else: ax1.set_title('PG detection for '+plot.sn(ct['nprim'])+' primaries', fontsize=Fontsize) ax1.set_ylim(bottom=0) ct_labelextra = '' rpct_labelextra = '' if True: ct_labelextra += 'CT DE: '+plot.sn(ct['ct']['detyieldmu']) #yield per prot rpct_labelextra += 'RPCT DE: '+plot.sn(ct['rpct']['detyieldmu']) ax1.text(0.05, 0.95, ct_labelextra , ha='left', va='center', fontsize=Fontsize, transform=ax1.transAxes) ax1.text(0.05, 0.8, rpct_labelextra , ha='left', va='center', fontsize=Fontsize, transform=ax1.transAxes) plot.texax(ax1)
def get_unc(ax1,dataset,refdata,ax,typ='parodi'): colors = plot.colors color_index=0 #asume voxels are 2mm if 'Z' in ax and 'parodi' in typ: x_axis = np.linspace(0,222,111) if 'Y' in ax and 'head' in typ: x_axis = np.linspace(0,170,85) if 'E' in ax: x_axis = np.linspace(0,10,250) for key, valuee in iter(sorted(dataset.iteritems())): value = valuee[ax] ax1.step(x_axis,[x*100. for x in value['unc']], label=plot.sn_mag(key)+' primaries', color=colors[color_index]) color_index+=1 refdata = refdata[ax] ax1.step(x_axis,[x*100. for x in refdata['unc']], label='Reference', color='k') ax1.semilogy() ax1.autoscale(axis='x',tight=True) #ax1.yaxis.set_major_formatter(mpl.ticker.FormatStrFormatter('%.0f%%')) #PG falloff line spectcutoff = [1,8] if ax == 'E': ax1.set_xlim(spectcutoff) # if ax == 'E': # ax1.axvline(spectcutoff[0], color='#999999', ls='--') # ax1.axvline(spectcutoff[1], color='#999999', ls='--') plot.texax(ax1)
def get_yield(ax1,dataset,refdata,ax,typ='parodi'): colors = plot.colors color_index=0 #asume voxels are 2mm if 'Z' in ax and 'parodi' in typ: x_axis = np.linspace(0,222,111) if 'Y' in ax and 'head' in typ: x_axis = np.linspace(0,170,85) if 'E' in ax: x_axis = np.linspace(0,10,250) for key, valuee in iter(sorted(dataset.iteritems())): # if TLE value = valuee[ax] # print ax, len(value['yield']) ax1.step(x_axis,value['yield'], label=plot.sn_mag(key)+' primaries', color=colors[color_index], lw=0.5) plot.fill_between_steps(ax1, x_axis, value['yield-unc'], value['yield+unc'], alpha=0.5, color=colors[color_index], lw=0.5) color_index+=1 #analog reference refdata = refdata[ax] ax1.step(x_axis,refdata['yield'], label='Reference', color='k', lw=0.5) plot.fill_between_steps(ax1, x_axis, refdata['yield-unc'], refdata['yield+unc'], alpha=0.5, color='k', lw=0.5) ax1.ticklabel_format(style='sci', axis='y', scilimits=(0,0)) ax1.autoscale(axis='x',tight=True) # #PG falloff line parodi spectcutoff = [1,8] if ax == 'E': ax1.set_xlim(spectcutoff) plot.texax(ax1)
def get_effhist(ax1, image, name=None): colors = plot.colors get_effhist.color_index += 1 data = image.imdata[~np.isnan(image.imdata)].flatten() if np.nanmin(data) == 0: binn = np.logspace(1, np.log10(np.nanmax(data))) label = plot.sn_mag( image.nprim) + " primaries\nMin: " + str(0) + "\nMax: " + plot.sn( np.nanmax(data)) else: binn = np.logspace(np.log10(np.nanmin(data)), np.log10(np.nanmax(data))) label = plot.sn_mag(image.nprim) + " primaries\nMin: " + plot.sn( np.nanmin(data)) + "\nMax: " + plot.sn(np.nanmax(data)) hist, bins = np.histogram(data, bins=binn) center = (bins[:-1] + bins[1:]) / 2 bins = center # hist[0] = 0 # hist[-1] = 0 if name is None: ax1.plot(bins, hist / float(hist.max()), label=label, color=colors[get_effhist.color_index], drawstyle='steps') else: ax1.plot(bins, hist / float(hist.max()), label=name + '\nMedian gain: ' + plot.sn(np.median(data)), color=colors[get_effhist.color_index], drawstyle='steps') ax1.semilogx() plot.texax(ax1) # print 'Median of efficiency:',np.median(data) # print 'Mean of efficiency:',np.mean(data) return [np.nanmin(data), np.median(data), np.nanmax(data), np.mean(data)]
def get_effhist_oud(ax1, image, name=None): colors = plot.colors get_effhist.color_index += 1 data = image.imdata[~np.isnan(image.imdata)].flatten() # data=data/np.nanmax(data) # with np.errstate(divide='ignore', invalid='ignore'): # data = np.true_divide(data,np.nanmax(data)) #data = np.nonzero(data)] #print image.nprim,np.nanmin(data),np.nanmax(data) if np.nanmin(data) == 0: label = plot.sn_mag( image.nprim) + " primaries\nMin: " + str(0) + "\nMax: " + plot.sn( np.nanmax(data)) y, x, _ = ax1.hist(data, bins=np.logspace(1, np.log10(np.nanmax(data))), label=label, color=colors[get_effhist.color_index], histtype='step', lw=1) else: label = plot.sn_mag(image.nprim) + " primaries\nMin: " + plot.sn( np.nanmin(data)) + "\nMax: " + plot.sn(np.nanmax(data)) y, x, _ = ax1.hist(data, bins=np.logspace(np.log10(np.nanmin(data)), np.log10(np.nanmax(data))), label=label, color=colors[get_effhist.color_index], histtype='step', lw=1) print y.max() # label=str(image.nprim)+" primaries\nMin: "+str(np.nanmin(data))+"\nMax: "+str(np.nanmax(data)) # ax1.hist(data, bins = np.linspace(np.nanmin(data),np.nanmax(data)) ,label=label,color=colors[get_effhist.color_index],histtype='step', lw=1) ax1.semilogx() plot.texax(ax1) # print 'Median of efficiency:',np.median(data) # print 'Mean of efficiency:',np.mean(data) return [np.nanmin(data), np.median(data), np.nanmax(data), np.mean(data)]
def get_yield(ax1, dataset, refdata, ax, typ='parodi'): colors = plot.colors color_index = 0 #asume voxels are 2mm if 'Z' in ax and 'parodi' in typ: x_axis = np.linspace(0, 222, 111) if 'Y' in ax and 'head' in typ: x_axis = np.linspace(0, 170, 85) if 'E' in ax: x_axis = np.linspace(0, 10, 250) for key, valuee in iter(sorted(dataset.iteritems())): # if TLE value = valuee[ax] # print ax, len(value['yield']) ax1.step(x_axis, value['yield'], label=plot.sn_mag(key) + ' primaries', color=colors[color_index], lw=0.5) plot.fill_between_steps(ax1, x_axis, value['yield-unc'], value['yield+unc'], alpha=0.5, color=colors[color_index], lw=0.5) color_index += 1 #analog reference refdata = refdata[ax] ax1.step(x_axis, refdata['yield'], label='Reference', color='k', lw=0.5) plot.fill_between_steps(ax1, x_axis, refdata['yield-unc'], refdata['yield+unc'], alpha=0.5, color='k', lw=0.5) ax1.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) ax1.autoscale(axis='x', tight=True) # #PG falloff line parodi spectcutoff = [1, 8] if ax == 'E': ax1.set_xlim(spectcutoff) plot.texax(ax1)
def get_effhist_oud(ax1,image,name=None): colors = plot.colors get_effhist.color_index+=1 data = image.imdata[~np.isnan(image.imdata)].flatten() # data=data/np.nanmax(data) # with np.errstate(divide='ignore', invalid='ignore'): # data = np.true_divide(data,np.nanmax(data)) #data = np.nonzero(data)] #print image.nprim,np.nanmin(data),np.nanmax(data) if np.nanmin(data) == 0: label=plot.sn_mag(image.nprim)+" primaries\nMin: "+str(0)+"\nMax: "+plot.sn(np.nanmax(data)) y, x, _=ax1.hist(data, bins = np.logspace(1,np.log10(np.nanmax(data))) ,label=label,color=colors[get_effhist.color_index],histtype='step', lw=1) else: label=plot.sn_mag(image.nprim)+" primaries\nMin: "+plot.sn(np.nanmin(data))+"\nMax: "+plot.sn(np.nanmax(data)) y, x, _=ax1.hist(data, bins = np.logspace(np.log10(np.nanmin(data)),np.log10(np.nanmax(data))) ,label=label,color=colors[get_effhist.color_index],histtype='step', lw=1) print y.max() # label=str(image.nprim)+" primaries\nMin: "+str(np.nanmin(data))+"\nMax: "+str(np.nanmax(data)) # ax1.hist(data, bins = np.linspace(np.nanmin(data),np.nanmax(data)) ,label=label,color=colors[get_effhist.color_index],histtype='step', lw=1) ax1.semilogx() plot.texax(ax1) # print 'Median of efficiency:',np.median(data) # print 'Mean of efficiency:',np.mean(data) return [np.nanmin(data),np.median(data),np.nanmax(data),np.mean(data)]
def get_relunc(ax1, dataset, refdata, ax, typ='parodi'): colors = plot.colors color_index = 0 #asume voxels are 2mm if 'Z' in ax and 'parodi' in typ: x_axis = np.linspace(0, 222, 111) if 'Y' in ax and 'head' in typ: x_axis = np.linspace(0, 170, 85) if 'E' in ax: x_axis = np.linspace(0, 10, 250) for key, valuee in iter(sorted(dataset.iteritems())): value = valuee[ax] try: ax1.step(x_axis, [x * 100. for x in value['relunc']], label=plot.sn_mag(key) + ' primaries', color=colors[color_index]) except TypeError: ax1.step(x_axis, [x * 100. for x in value['relunc']], label=key, color=colors[color_index]) color_index += 1 if refdata is not None: refdata = refdata[ax] ax1.step(x_axis, [x * 100. for x in refdata['relunc']], label='Reference', color='k') ax1.semilogy() ax1.autoscale(axis='x', tight=True) #ax1.yaxis.set_major_formatter(mpl.ticker.FormatStrFormatter('%.0f%%')) #PG falloff line spectcutoff = [1, 8] if ax == 'E': ax1.set_xlim(spectcutoff) # if ax == 'E': # ax1.axvline(spectcutoff[0], color='#999999', ls='--') # ax1.axvline(spectcutoff[1], color='#999999', ls='--') plot.texax(ax1)
def get_reldiff(ax1, dataset, ax, typ='parodi'): colors = plot.colors color_index = 0 #asume voxels are 2mm if 'Z' in ax and 'parodi' in typ: x_axis = np.linspace(0, 222, 111) if 'Y' in ax and 'head' in typ: x_axis = np.linspace(0, 170, 85) if 'E' in ax: x_axis = np.linspace(0, 10, 250) for key, valuee in iter(sorted(dataset.iteritems())): value = valuee[ax] ax1.step(x_axis, [x * 100. for x in value['reldiff']], label=plot.sn_mag(key) + ' primaries', color=colors[color_index], lw=0.5) print key, __withinsigma(value) plot.fill_between_steps(ax1, x_axis, [x * 100. for x in value['reldiff-2sigma']], [x * 100. for x in value['reldiff+2sigma']], alpha=0.25, color=colors[color_index], lw=0.01) color_index += 1 ax1.autoscale(axis='x', tight=True) #ax1.set_ylim([-4,4]) # #PG falloff line parodi spectcutoff = [1, 8] if ax == 'E': ax1.set_xlim(spectcutoff) # if ax == 'E': # ax1.axvline(spectcutoff[0], color='#999999', ls='--') # ax1.axvline(spectcutoff[1], color='#999999', ls='--') plot.texax(ax1)
def plot1d(ax1,dataset): colors = plot.colors color_index=0 #asume voxels are 2mm x_axis = np.linspace(0,10,250) key = 1e4 ax1.step(x_axis,[x*100. for x in dataset], label=plot.sn_mag(key)+' primaries', color=colors[color_index]) color_index+=1 ax1.semilogy() ax1.autoscale(axis='x',tight=True) #ax1.yaxis.set_major_formatter(mpl.ticker.FormatStrFormatter('%.0f%%')) #PG falloff line spectcutoff = [1,8] ax1.set_xlim(spectcutoff) plot.texax(ax1)
def plot_single_range(ax1,ct): for i in range(len(ct['ct']['data'])): x,y,fo=ct['ct']['x'],ct['ct']['data'][i],ct['ct']['falloff'][i] ax1.step(x, y, label=ct['name']+'ct', color='steelblue', lw=1, where='mid',clip_on=False, alpha=0.5) ax1.axvline(fo, color='steelblue', ls='-',lw=1, alpha=0.5) break ax1.set_xlabel('Depth [mm]', fontsize=FONTSIZE) ax1.set_ylabel('PG detected [counts]', fontsize=FONTSIZE) ax1.set_title(plot.sn(ct['nprim'],0)+' primaries', fontsize=FONTSIZE) plot.texax(ax1) for i in range(len(ct['rpct']['data'])): x,y,fo=ct['rpct']['x'],ct['rpct']['data'][i],ct['rpct']['falloff'][i] ax1.step(x, y, label=ct['name']+'ct', color='indianred', lw=1, where='mid',clip_on=False, alpha=0.5) ax1.axvline(fo, color='indianred', ls='-',lw=1, alpha=0.5) break ax1.set_title('PG detection for '+plot.sn_mag(ct['nprim'])+'primaries', fontsize=FONTSIZE) ax1.set_ylim(bottom=0) plot.texax(ax1)
def get_reldiff(ax1,dataset,ax,typ='parodi'): colors = plot.colors color_index=0 #asume voxels are 2mm if 'Z' in ax and 'parodi' in typ: x_axis = np.linspace(0,222,111) if 'Y' in ax and 'head' in typ: x_axis = np.linspace(0,170,85) if 'E' in ax: x_axis = np.linspace(0,10,250) for key, valuee in iter(sorted(dataset.iteritems())): value = valuee[ax] ax1.step(x_axis, [x*100. for x in value['reldiff']], label=plot.sn_mag(key) +' primaries', color=colors[color_index], lw=0.5) print key, __withinsigma(value) plot.fill_between_steps(ax1, x_axis, [x*100. for x in value['reldiff-2sigma']], [x*100. for x in value['reldiff+2sigma']], alpha=0.25, color=colors[color_index], lw=0.01) color_index+=1 ax1.autoscale(axis='x',tight=True) #ax1.set_ylim([-4,4]) # #PG falloff line parodi spectcutoff = [1,8] if ax == 'E': ax1.set_xlim(spectcutoff) # if ax == 'E': # ax1.axvline(spectcutoff[0], color='#999999', ls='--') # ax1.axvline(spectcutoff[1], color='#999999', ls='--') plot.texax(ax1)
def plot1d(ax1, dataset): colors = plot.colors color_index = 0 #asume voxels are 2mm x_axis = np.linspace(0, 10, 250) key = 1e4 ax1.step(x_axis, [x * 100. for x in dataset], label=plot.sn_mag(key) + ' primaries', color=colors[color_index]) color_index += 1 ax1.semilogy() ax1.autoscale(axis='x', tight=True) #ax1.yaxis.set_major_formatter(mpl.ticker.FormatStrFormatter('%.0f%%')) #PG falloff line spectcutoff = [1, 8] ax1.set_xlim(spectcutoff) plot.texax(ax1)
### Make efficiency histo tleeff = copy.deepcopy(tle3d) aneff = copy.deepcopy(an3d) tle.seteff(tleeff) tle.seteff(aneff) tle.seteffratio(tleeff,aneff[max(aneff.keys())]['var']) f, ((tl,tr),(bl,br)) = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True) lab1=tle.get_effhist(tl,tleeff[1e3]['var']) lab2=tle.get_effhist(tr,tleeff[1e4]['var']) lab3=tle.get_effhist(bl,tleeff[1e5]['var']) lab4=tle.get_effhist(br,tleeff[1e6]['var']) tl.set_title("TLE "+plot.sn_mag(1e3)).set_fontsize(8) tl.text(0.05, 0.9,"Min: "+plot.sn(lab1[0])+"\nMedian: "+plot.sn(lab1[1])+"\nMax: "+plot.sn(lab1[2]), ha='left', va='center', transform=tl.transAxes, fontsize=6) tr.set_title("TLE "+plot.sn_mag(1e4)).set_fontsize(8) tr.text(0.05, 0.9,"Min: "+plot.sn(lab2[0])+"\nMedian: "+plot.sn(lab2[1])+"\nMax: "+plot.sn(lab2[2]), ha='left', va='center', transform=tr.transAxes, fontsize=6) bl.set_title("TLE "+plot.sn_mag(1e5)).set_fontsize(8) bl.text(0.05, 0.9,"Min: "+plot.sn(lab3[0])+"\nMedian: "+plot.sn(lab3[1])+"\nMax: "+plot.sn(lab3[2]), ha='left', va='center', transform=bl.transAxes, fontsize=6) br.set_title("TLE "+plot.sn_mag(1e6)).set_fontsize(8) br.text(0.05, 0.9,"Min: "+plot.sn(lab4[0])+"\nMedian: "+plot.sn(lab4[1])+"\nMax: "+plot.sn(lab4[2]), ha='left', va='center', transform=br.transAxes, fontsize=6) tl.set_ylabel('Number of voxels (scaled)') tl.yaxis.set_label_coords(-0.2, 0.) bl.set_xlabel('Gain factor w.r.t. Reference') bl.xaxis.set_label_coords(1.1,-0.2) #f.savefig('eff-histo.pdf', bbox_inches='tight') plt.close('all')
aneff = copy.deepcopy(an3d) tle.seteff(tleeff) tle.seteff(aneff) tle.seteffratio(tleeff, aneff[max(aneff.keys())]['var']) f, ((tl, tr), (bl, br)) = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True) lab1 = tle.get_effhist(tl, tleeff[1e3]['var']) lab2 = tle.get_effhist(tr, tleeff[1e4]['var']) lab3 = tle.get_effhist(bl, tleeff[1e5]['var']) lab4 = tle.get_effhist(br, tleeff[1e6]['var']) tl.set_title("TLE " + plot.sn_mag(1e3)).set_fontsize(8) tl.text(0.05, 0.9, "Min: " + plot.sn(lab1[0]) + "\nMedian: " + plot.sn(lab1[1]) + "\nMax: " + plot.sn(lab1[2]), ha='left', va='center', transform=tl.transAxes, fontsize=6) tr.set_title("TLE " + plot.sn_mag(1e4)).set_fontsize(8) tr.text(0.05, 0.9, "Min: " + plot.sn(lab2[0]) + "\nMedian: " + plot.sn(lab2[1]) + "\nMax: " + plot.sn(lab2[2]), ha='left', va='center',