diff --git a/amstrax/analyses/plotting.py b/amstrax/analyses/plotting.py index 0a122882..981c382f 100644 --- a/amstrax/analyses/plotting.py +++ b/amstrax/analyses/plotting.py @@ -222,6 +222,9 @@ def plot_area_per_channel(context, run_id, peaks, **kwargs): # Get the peaks area_per_channel = peak["area_per_channel"] + vmin = min(area_per_channel) + vmax = max(area_per_channel) + # Plot the area per channel # Four quadrants for channels 1 2 3 4 # imshow with 4 quadrants @@ -235,7 +238,9 @@ def plot_area_per_channel(context, run_id, peaks, **kwargs): -top_quadrant_length, top_quadrant_length, ], - origin="upper", + origin="lower", + vmin=vmin, + vmax=vmax, ) axes[1].imshow( area_per_channel[0].reshape(1, 1), @@ -246,6 +251,8 @@ def plot_area_per_channel(context, run_id, peaks, **kwargs): -bottom_quadrant_length, bottom_quadrant_length, ], + vmin=vmin, + vmax=vmax, ) # Write the number of the channel in every element of imshow of axes[0] @@ -305,6 +312,22 @@ def plot_area_per_channel(context, run_id, peaks, **kwargs): @amstrax.mini_analysis(requires=("records_led",)) def plot_led_records(context, run_id, records_led, n_records=100, **kwargs): + """ + Plots the LED records for a given run ID. + + Args: + context (unknown): Unknown. + run_id (int): The ID of the run to plot. + records_led (unknown): Unknown. + n_records (int, optional): The number of records to plot. Defaults to 100. + **kwargs: Unknown. + + Raises: + ValueError: If the run ID is not found in the database or if the run is not an external trigger run. + + Returns: + None + """ db = amstrax.get_mongo_collection() rd = db.find_one({"number": int(run_id)}) diff --git a/amstrax/analyses/quick_checks.py b/amstrax/analyses/quick_checks.py index 0b4ea616..ce05739b 100644 --- a/amstrax/analyses/quick_checks.py +++ b/amstrax/analyses/quick_checks.py @@ -81,6 +81,63 @@ def std_axes(): std_axes() plt.tight_layout() + + +@amstrax.mini_analysis(requires=('peak_basics',)) +def plot_peaks_area_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 = get_livetime_sec(context, run_id, peaks) + + mh = Histdd(peaks, + dimensions=( + ('area', pe_bins), + ('area_fraction_top', np.linspace(0, 1, 100)), + ('range_50p_area', rt_bins), + )) + + f, axes = plt.subplots(1, 2, figsize=figsize) + + def std_axes(): + plt.gca().set_facecolor('k') + plt.xscale('log') + plt.xlabel("Area [PE]") + plt.ylabel("Area Fraction Top") + # plt.ylabel("Range 50% area [ns]") + + plt.sca(axes[0]) + (mh / livetime_sec).sum(axis=2).plot( + norm=LogNorm(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( + norm=LogNorm(vmin=rt_bins[0], vmax=rt_bins[-1]), + colorbar_kwargs=dict(extend='max'), + cmap=plt.cm.jet, + cblabel='Range 50% area [ns]') + + std_axes() + plt.tight_layout() + @amstrax.mini_analysis(requires=['event_info']) def event_scatter(context, run_id, events, show_single=True, diff --git a/amstrax/contexts.py b/amstrax/contexts.py index e45375f4..b0d26177 100644 --- a/amstrax/contexts.py +++ b/amstrax/contexts.py @@ -14,7 +14,7 @@ 'DEFAULT_COLLECTION': 'runs_gas' } -PROCESSED_DATA_FOLDER = 'home/xams/data/processed' +PROCESSED_DATA_FOLDER = '/home/xams/data/xams_processed' COMMON_OPT_XAMS = dict( register_all=[], diff --git a/amstrax/plugins/peaks/peak_basics.py b/amstrax/plugins/peaks/peak_basics.py index fe25f839..e6f3be16 100644 --- a/amstrax/plugins/peaks/peak_basics.py +++ b/amstrax/plugins/peaks/peak_basics.py @@ -97,7 +97,7 @@ def compute(self, peaks): r['n_saturated_channels'] = p['n_saturated_channels'] n_top = self.config["n_top_pmts"] - area_top = p['area_per_channel'][:, :n_top].sum(axis=1) + area_top = p['area_per_channel'][:, n_top:].sum(axis=1) # Recalculate to prevent numerical inaccuracy #442 area_total = p['area_per_channel'].sum(axis=1) # Negative-area peaks get NaN AFT