Skip to content

Commit

Permalink
Merge pull request #30 from ALPHA-g-Experiment/plots
Browse files Browse the repository at this point in the history
Fix plot axis limits
  • Loading branch information
DJDuque authored Sep 10, 2024
2 parents 07c60bc + 3772bf3 commit d57d202
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
13 changes: 7 additions & 6 deletions bin/chronobox_timestamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import matplotlib.pyplot as plt
import numpy as np
import polars as pl

parser = argparse.ArgumentParser(
Expand All @@ -26,18 +27,18 @@
pl.col("leading_edge"),
)

_, t_edges, _ = plt.hist(df["chronobox_time"], bins=args.t_bins)
t_bin_width = t_edges[1] - t_edges[0]

plt.xlabel("Chronobox time [s]")
plt.ylabel("Counts")

t_max = args.t_max if args.t_max < float("inf") else df["chronobox_time"].max()
t_edges, t_bin_width = np.linspace(args.t_min, t_max, args.t_bins + 1, retstep=True)
text = "\n".join(
[
r"$\bf{Bin\ width:}$" + f" {t_bin_width:.2E} s",
r"$\bf{Number\ of\ hits:}$" + f" {len(df)}",
]
)

plt.hist(df["chronobox_time"], bins=t_edges)
plt.xlabel("Chronobox time [s]")
plt.ylabel("Counts")
plt.figtext(0.005, 0.01, text, fontsize=6)
plt.tight_layout()

Expand Down
5 changes: 2 additions & 3 deletions bin/trg_scalers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
df = pl.read_csv(args.trg_scalers_csv, comment_prefix="#").filter(
pl.col("trg_time").is_between(args.t_min, args.t_max)
)
# All histograms should have the same binning
_, t_edges = np.histogram(df["trg_time"], bins=args.t_bins)
t_bin_width = t_edges[1] - t_edges[0]

t_max = args.t_max if args.t_max < float("inf") else df["trg_time"].max()
t_edges, t_bin_width = np.linspace(args.t_min, t_max, args.t_bins + 1, retstep=True)
text = r"$\bf{Bin\ width:}$" + f" {t_bin_width:.2E} s"
plt.figtext(0.005, 0.01, text, fontsize=8)

Expand Down
33 changes: 19 additions & 14 deletions bin/vertices.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,32 @@
fig = plt.figure(figsize=(19, 10), dpi=100)

ax = fig.add_subplot(231)
z_edges, z_bin_width = np.linspace(
args.z_min, args.z_max, args.z_bins + 1, retstep=True
)
ax.hist(df["reconstructed_z"], bins=z_edges)
ax.set(xlabel="z [m]", ylabel="Number of vertices")
ax.hist(df["reconstructed_z"], bins=args.z_bins)

ax = fig.add_subplot(232)
t_max = args.t_max if args.t_max < float("inf") else df["trg_time"].max()
t_edges, t_bin_width = np.linspace(args.t_min, t_max, args.t_bins + 1, retstep=True)
ax.hist(df["trg_time"], bins=t_edges)
ax.set(xlabel="TRG time [s]", ylabel="Number of vertices")
ax.hist(df["trg_time"], bins=args.t_bins)

ax = fig.add_subplot(233)
ax.set(xlabel="TRG time [s]", ylabel="z [m]")
_, t_edges, z_edges, mesh = ax.hist2d(
df["trg_time"], df["reconstructed_z"], bins=[args.t_bins, args.z_bins], cmin=1
_, _, _, mesh = ax.hist2d(
df["trg_time"], df["reconstructed_z"], bins=[t_edges, z_edges], cmin=1
)
t_bin_width = t_edges[1] - t_edges[0]
z_bin_width = z_edges[1] - z_edges[0]
ax.set(xlabel="TRG time [s]", ylabel="z [m]")
cbar = fig.colorbar(mesh)
cbar.set_label("Number of vertices", rotation=270, labelpad=15)

ax = fig.add_subplot(234)
r_edges, r_bin_width = np.linspace(
args.r_min, args.r_max, args.r_bins + 1, retstep=True
)
hist, _, _ = ax.hist(df["r"], bins=r_edges)
ax.set(xlabel="r [m]", ylabel="Number of vertices")
hist, r_edges, _ = ax.hist(df["r"], bins=args.r_bins)
ax = ax.twinx()
ax.set(yticklabels=[])
norm = hist / (math.pi * (r_edges[1:] ** 2 - r_edges[:-1] ** 2))
Expand All @@ -97,18 +103,17 @@
)

ax = fig.add_subplot(235)
phi_edges, phi_bin_width = np.linspace(
args.phi_min, args.phi_max, args.phi_bins + 1, retstep=True
)
ax.hist(df["phi"], bins=phi_edges)
ax.set(xlabel="phi [rad]", ylabel="Number of vertices")
ax.hist(df["phi"], bins=args.phi_bins)

axc = fig.add_subplot(236)
axc.set(xlabel="x [m]", ylabel="y [m]")
axc.set_aspect("equal")
hist, phi_edges, r_edges = np.histogram2d(
df["phi"], df["r"], bins=[args.phi_bins, args.r_bins]
)
hist, _, _ = np.histogram2d(df["phi"], df["r"], bins=[phi_edges, r_edges])
hist[hist < 1] = np.nan
phi_bin_width = phi_edges[1] - phi_edges[0]
r_bin_width = r_edges[1] - r_edges[0]
axc.set_xlim(-r_edges[-1], r_edges[-1])
axc.set_ylim(-r_edges[-1], r_edges[-1])
ax = fig.add_subplot(236, projection="polar")
Expand Down

0 comments on commit d57d202

Please sign in to comment.