def plot_peaks_aft_histogram( context, run_id, peaks, pe_bins=np.logspace(0, 7, 120), rt_bins=np.geomspace(2, 1e5, 120), extra_labels=tuple(), rate_range=(1e-4, 1), aft_range=(0, .85), figsize=(14, 5)): """Plot side-by-side (area, width) histograms of the peak rate and mean area fraction top. :param pe_bins: Array of bin edges for the peak area dimension [PE] :param rt_bins: array of bin edges for the rise time dimension [ns] :param extra_labels: List of (area, risetime, text, color) extra labels to put on the plot :param rate_range: Range of rates to show [peaks/(bin*s)] :param aft_range: Range of mean S1 area fraction top / bin to show :param figsize: Figure size to use """ livetime_sec = straxen.get_livetime_sec(context, run_id, peaks) mh = Histdd(peaks, dimensions=( ('area', pe_bins), ('range_50p_area', rt_bins), ('area_fraction_top', np.linspace(0, 1, 100)) )) f, axes = plt.subplots(1, 2, figsize=figsize) def std_axes(): plt.gca().set_facecolor('k') plt.yscale('log') plt.xscale('log') plt.xlabel("Area [PE]") plt.ylabel("Range 50% area [ns]") labels = [ (12, 8, "AP?", 'white'), (3, 150, "1PE\npileup", 'gray'), (30, 200, "1e", 'gray'), (100, 1000, "n-e", 'w'), (2000, 2e4, "Train", 'gray'), (1200, 50, "S1", 'w'), (45e3, 60, "αS1", 'w'), (2e5, 800, "S2", 'w'), ] + list(extra_labels) for x, w, text, color in labels: plt.text(x, w, text, color=color, verticalalignment='center', horizontalalignment='center') plt.sca(axes[0]) (mh / livetime_sec).sum(axis=2).plot( log_scale=True, vmin=rate_range[0], vmax=rate_range[1], colorbar_kwargs=dict(extend='both'), cblabel='Peaks / (bin * s)') std_axes() plt.sca(axes[1]) mh.average(axis=2).plot( vmin=aft_range[0], vmax=aft_range[1], colorbar_kwargs=dict(extend='max'), cmap=plt.cm.jet, cblabel='Mean area fraction top') std_axes() plt.tight_layout()
def plot_peaks_aft_histogram(context, run_id, peaks, pe_bins=np.logspace(0, 7, 120), width_bins=np.geomspace(2, 1e5, 120), extra_labels=tuple(), rate_range=(1e-4, 1), aft_range=(0, .85), figsize=(14, 5)): """Plot side-by-side (area, width) histograms of the peak rate and mean area fraction top.""" try: md = context.run_metadata(run_id, projection=('start', 'end')) livetime_sec = (md['end'] - md['start']).total_seconds() except strax.RunMetadataNotAvailable: livetime_sec = (strax.endtime(peaks)[-1] - peaks[0]['time']) / 1e9 mh = Histdd(peaks, dimensions=(('area', pe_bins), ('range_50p_area', width_bins), ('area_fraction_top', np.linspace(0, 1, 100)))) f, axes = plt.subplots(1, 2, figsize=figsize) def std_axes(): plt.gca().set_facecolor('k') plt.yscale('log') plt.xscale('log') plt.xlabel("Area [PE]") plt.ylabel("Range 50% area [ns]") labels = [ (12, 8, "AP?", 'white'), (3, 150, "1PE\npileup", 'gray'), (30, 200, "1e", 'gray'), (100, 1000, "n-e", 'w'), (2000, 2e4, "Train", 'gray'), (1200, 50, "S1", 'w'), (45e3, 60, "αS1", 'w'), (2e5, 800, "S2", 'w'), ] + list(extra_labels) for x, w, text, color in labels: plt.text(x, w, text, color=color, verticalalignment='center', horizontalalignment='center') plt.sca(axes[0]) (mh / livetime_sec).sum(axis=2).plot(log_scale=True, vmin=rate_range[0], vmax=rate_range[1], colorbar_kwargs=dict(extend='both'), cblabel='Peaks / (bin * hour)') std_axes() plt.sca(axes[1]) mh.average(axis=2).plot(vmin=aft_range[0], vmax=aft_range[1], colorbar_kwargs=dict(extend='max'), cmap=plt.cm.jet, cblabel='Mean area fraction top') std_axes() plt.tight_layout()