Skip to content

Commit

Permalink
Added more minianalyses (#278)
Browse files Browse the repository at this point in the history
* bug path

* fix plot

* fix plot

* fix plot
  • Loading branch information
cfuselli authored Sep 22, 2023
1 parent 3f06486 commit 177b16a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
25 changes: 24 additions & 1 deletion amstrax/analyses/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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]
Expand Down Expand Up @@ -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)})
Expand Down
57 changes: 57 additions & 0 deletions amstrax/analyses/quick_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion amstrax/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[],
Expand Down
2 changes: 1 addition & 1 deletion amstrax/plugins/peaks/peak_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 177b16a

Please sign in to comment.