Skip to content

Commit 0c9b835

Browse files
committed
style(qadb): improve FC charge analysis plots
1 parent 30f7a5d commit 0c9b835

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

qa-physics/charge_analysis/analyze_charge.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ def main():
8282
fcupgateds = np.array(fcupgateds)
8383
live_times = np.array(live_times)
8484

85-
run_number = os.path.splitext(os.path.basename(hipo_file))[0]
85+
file_basename = os.path.splitext(os.path.basename(hipo_file))[0]
8686

8787
# ---------- Plot 1: Per-event data ----------
8888
# ---------- Plot 1: Per-event data ----------
8989
fig1, axs1 = plt.subplots(2, 2, figsize=(14, 8))
90-
fig1.suptitle(f'Run {run_number} - Event-Level Detector Data', fontsize=16)
90+
fig1.suptitle(f'{file_basename}', fontsize=16)
9191

9292
plots1 = [
9393
(axs1[0, 0], fcups, 'FCUP', 'FCUP vs Timestamp', 'darkgreen', 'line'),
@@ -103,18 +103,19 @@ def main():
103103
ax.scatter(timestamps, data, label=label, color=color, s=10, alpha=0.7)
104104

105105
ax.set_title(title, fontsize=12)
106-
ax.set_xlabel('Timestamp', fontsize=10)
106+
ax.set_xlabel('Timestamp', fontsize=10, loc='center')
107107
ax.set_ylabel(label, fontsize=10)
108108
ax.legend(fontsize=9)
109109
ax.grid(True, linestyle='--', alpha=0.6)
110110
ax.tick_params(axis='both', labelsize=9)
111111

112112
fig1.tight_layout(rect=[0, 0.03, 1, 0.95])
113-
fig1.savefig(f'{output_dir}/fcup_vs_timestamp_{run_number}_{output_suffix}.png', bbox_inches='tight', dpi=300)
113+
fig1.savefig(f'{output_dir}/fcup_vs_timestamp_{file_basename}_{output_suffix}.png', bbox_inches='tight', dpi=300)
114114
plt.close(fig1)
115115
# ---------- Compute Chunked FCUP Gated with neighbor handling ----------
116-
chunk_size = 2000
116+
chunk_size = 100
117117
num_chunks = len(timestamps) // chunk_size
118+
xlabel = f'Bin num. (size={chunk_size} scalers)'
118119

119120

120121
chunk_caseA, chunk_caseB, chunk_caseC, chunk_default, chunk_default_ungated = [], [], [], [], []
@@ -229,15 +230,16 @@ def main():
229230
5, 1, figsize=(12, 17), sharex=False,
230231
gridspec_kw={'height_ratios': [3, 1, 1, 1, 2]}
231232
)
232-
fig2.suptitle(f'Run {run_number} - Chunked FCUP Gated (Neighbor Handling)', fontsize=16)
233+
fig2.suptitle(f'{file_basename}', fontsize=16)
233234

234235
# Top: cumulative sums
235-
ax_top.plot(chunk_indices, cum_caseA, label='Cumulative Case A (LT_nn × FCUPungated)', color='darkred', marker='o')
236-
#ax_top.plot(chunk_indices, cum_caseB, label='Cumulative Case B (LT_nn × FCUPungated_nn)', color='darkgreen', marker='s')
237-
ax_top.plot(chunk_indices, cum_caseC, label='Cumulative Case C (20-NN mean × FCUPungated)', color='darkorange', marker='d')
238-
ax_top.plot(chunk_indices, cum_default, label='Cumulative Default (FCUPgated)', color='blue', marker='^')
239-
ax_top.plot(chunk_indices, cum_default_ungated, label='Cumulative Default Ungated (FCUPungated)', color='teal', marker='x',linestyle='--')
236+
ax_top.plot(chunk_indices, cum_default_ungated, label='U: ungated FC charge', color='black', marker='o', markersize=4, linestyle='--')
237+
ax_top.plot(chunk_indices, cum_default, label='G: gated FC charge', color='red', marker='^', markersize=4)
238+
ax_top.plot(chunk_indices, cum_caseA, label='G\': LiveTime × U', color='deepskyblue', marker='x', markersize=4, linestyle='--')
239+
# ax_top.plot(chunk_indices, cum_caseB, label='Cumulative Case B (LT_nn × FCUPungated_nn)', color='darkgreen', marker='s', markersize=4)
240+
# ax_top.plot(chunk_indices, cum_caseC, label='Cumulative Case C (20-NN mean × U)', color='darkorange', marker='d', markersize=4)
240241
ax_top.set_ylabel('Cumulative Σ', fontsize=11)
242+
ax_top.set_xlabel(xlabel, fontsize=11, loc='right')
241243
ax_top.grid(True, linestyle='--', alpha=0.6)
242244
ax_top.legend(fontsize=10)
243245
ax_top.tick_params(axis='both', labelsize=10)
@@ -248,28 +250,30 @@ def main():
248250
ratioC = np.divide(cum_caseC, cum_default, out=np.full_like(cum_caseC, np.nan, dtype=float), where=np.array(cum_default) != 0)
249251
ratioDefUng = np.divide(cum_default_ungated, cum_default, out=np.full_like(cum_default_ungated, np.nan, dtype=float), where=np.array(cum_default) != 0)
250252

251-
ax_mid.plot(chunk_indices, ratioA, label='Case A / Default', color='darkred', marker='o')
252-
#ax_mid.plot(chunk_indices, ratioB, label='Case B / Default', color='darkgreen', marker='s')
253-
ax_mid.plot(chunk_indices, ratioC, label='Case C / Default', color='darkorange', marker='d')
254-
ax_mid.plot(chunk_indices, ratioDefUng, label='Default FCUP Ungated / Default FCUP gated', color='teal', marker='x',linestyle='--')
253+
ax_mid.plot(chunk_indices, ratioA, label='G\' / G', color='magenta', marker='x', markersize=4, linestyle='--')
254+
#ax_mid.plot(chunk_indices, ratioB, label='Case B / G', color='darkgreen', marker='s', markersize=4)
255+
# ax_mid.plot(chunk_indices, ratioC, label='Case C / G', color='darkorange', marker='d', markersize=4)
256+
# ax_mid.plot(chunk_indices, ratioDefUng, label='U / G', color='teal', marker='x', markersize=4, linestyle='--')
255257
ax_mid.axhline(1.0, color='black', linestyle='--', linewidth=1)
256258
ax_mid.set_ylabel('Ratio', fontsize=11)
259+
ax_mid.set_xlabel(xlabel, fontsize=11, loc='right')
257260
ax_mid.grid(True, linestyle='--', alpha=0.6)
258261
ax_mid.legend(fontsize=10)
259262
ax_mid.tick_params(axis='both', labelsize=10)
260263

261264
# Gated / Ungated ratio panel
262265
ratio_gated_ung = np.divide(cum_default, cum_default_ungated, out=np.full_like(cum_default, np.nan, dtype=float), where=np.array(cum_default_ungated) != 0)
263-
ax_gatedrat.plot(chunk_indices, ratio_gated_ung, label='FCUPgated / FCUPungated', color='navy', marker='o')
266+
ax_gatedrat.plot(chunk_indices, ratio_gated_ung, label='G / U', color='orange', marker='o', markersize=4)
264267
ax_gatedrat.axhline(1.0, color='black', linestyle='--', linewidth=1)
265268
ax_gatedrat.set_ylabel('Gated / Ungated', fontsize=11)
269+
ax_gatedrat.set_xlabel(xlabel, fontsize=11, loc='right')
266270
ax_gatedrat.grid(True, linestyle='--', alpha=0.6)
267271
ax_gatedrat.legend(fontsize=10)
268272
ax_gatedrat.tick_params(axis='both', labelsize=10)
269273

270274
# Bottom-1: skipped events count
271275
ax_bottom.bar(chunk_indices, skipped_counts, color='gray', alpha=0.7)
272-
ax_bottom.set_xlabel(f'Chunk Index (Each = {chunk_size} events)', fontsize=11)
276+
ax_bottom.set_xlabel(xlabel, fontsize=11, loc='right')
273277
ax_bottom.set_ylabel('# Skipped', fontsize=11)
274278
ax_bottom.grid(True, linestyle='--', alpha=0.6)
275279
ax_bottom.tick_params(axis='both', labelsize=10)
@@ -286,18 +290,18 @@ def main():
286290
ax_ltdist.hist(corrected_livetimes_A, bins=bins, alpha=0.4,
287291
label=f'Case A LT (μ={mean_A:.3f}, σ={sigma_A:.3f})', color='red')
288292
#ax_ltdist.hist(corrected_livetimes_B, bins=bins, alpha=0.4,
289-
# label=f'Case B LT (μ={mean_B:.3f}, σ={sigma_B:.3f})', color='green')
290-
ax_ltdist.hist(corrected_livetimes_C, bins=bins, alpha=0.4,
291-
label=f'Case C LT (μ={mean_C:.3f}, σ={sigma_C:.3f})', color='orange')
293+
# label=f'Case B LT (μ={mean_B:.3f}, σ={sigma_B:.3f})', color='green')
294+
# ax_ltdist.hist(corrected_livetimes_C, bins=bins, alpha=0.4,
295+
# label=f'Case C LT (μ={mean_C:.3f}, σ={sigma_C:.3f})', color='orange')
292296

293-
ax_ltdist.set_xlabel('Live Time', fontsize=11)
297+
ax_ltdist.set_xlabel('Live Time', fontsize=11, loc='right')
294298
ax_ltdist.set_ylabel('Counts', fontsize=11)
295299
ax_ltdist.legend(fontsize=9)
296300
ax_ltdist.grid(True, linestyle='--', alpha=0.6)
297301
ax_ltdist.tick_params(axis='both', labelsize=10)
298302

299303
fig2.tight_layout(rect=[0, 0.03, 1, 0.95])
300-
fig2.savefig(f'{output_dir}/chunked_fcupgated_comparison_{run_number}_{output_suffix}.png', bbox_inches='tight', dpi=300)
304+
fig2.savefig(f'{output_dir}/chunked_fcupgated_comparison_{file_basename}_{output_suffix}.png', bbox_inches='tight', dpi=300)
301305
plt.close(fig2)
302306

303307
print(f'TOTAL UNGATED CHARGE = {fcups[-1]-fcups[0]}')

0 commit comments

Comments
 (0)