Skip to content

Commit d65540e

Browse files
committed
feat: updatad analysis script, thanks to Bhawani
1 parent 24a4b29 commit d65540e

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

qa-physics/charge_analysis/analyze.py

100755100644
Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ def main():
115115
chunk_size = 2000
116116
num_chunks = len(timestamps) // chunk_size
117117

118-
chunk_caseA, chunk_caseB, chunk_caseC, chunk_default = [], [], [], []
119-
cum_caseA, cum_caseB, cum_caseC, cum_default = [], [], [], []
118+
119+
chunk_caseA, chunk_caseB, chunk_caseC, chunk_default, chunk_default_ungated = [], [], [], [], []
120+
cum_caseA, cum_caseB, cum_caseC, cum_default, cum_default_ungated = [], [], [], [], []
120121
chunk_indices, skipped_counts = [], []
121122

122-
runA, runB, runC, runDef = 0, 0, 0, 0
123+
runA, runB, runC, runDef, runDefUng = 0, 0, 0, 0, 0
123124
total_skipped = 0
124125

125126
corrected_livetimes_A = []
@@ -137,7 +138,7 @@ def main():
137138
fcupgated_diff = np.diff(fcupgateds[start:end])
138139
live_sub = live_times[start+1:end]
139140

140-
sumA, sumB, sumC, sumDef = 0, 0, 0, 0
141+
sumA, sumB, sumC, sumDef, sumDefUng = 0, 0, 0, 0, 0
141142
skipped_in_chunk = 0
142143

143144
for j, lt in enumerate(live_sub):
@@ -153,6 +154,8 @@ def main():
153154
corrected_livetimes_C.append(lt)
154155
# Default
155156
sumDef += fcupgated_diff[j]
157+
# Default ungated
158+
sumDefUng += fcup_diff[j]
156159
else:
157160
# ----- Case A/B nearest-neighbor substitution -----
158161
idx_candidates = []
@@ -178,6 +181,9 @@ def main():
178181

179182
# Default
180183
sumDef += fcupgated_diff[j]
184+
185+
# Default ungated
186+
sumDefUng += fcup_diff[j]
181187
else:
182188
skipped_in_chunk += 1
183189
total_skipped += 1
@@ -199,25 +205,28 @@ def main():
199205
runB += sumB
200206
runC += sumC
201207
runDef += sumDef
208+
runDefUng += sumDefUng
202209

203210
chunk_caseA.append(sumA)
204211
chunk_caseB.append(sumB)
205212
chunk_caseC.append(sumC)
206213
chunk_default.append(sumDef)
214+
chunk_default_ungated.append(sumDefUng)
207215
cum_caseA.append(runA)
208216
cum_caseB.append(runB)
209217
cum_caseC.append(runC)
210218
cum_default.append(runDef)
219+
cum_default_ungated.append(runDefUng)
211220
chunk_indices.append(i)
212221
skipped_counts.append(skipped_in_chunk)
213222

214223
logger.info(f"Computed chunked FCUP Gated values with neighbor handling (Cases A, B, C).")
215224
logger.info(f"Total skipped events (no valid LT neighbor): {total_skipped}")
216225

217226
# ---------- Plot 2: Chunked FCUP Gated + Ratios + Skips + LT Distribution ----------
218-
fig2, (ax_top, ax_mid, ax_bottom, ax_ltdist) = plt.subplots(
219-
4, 1, figsize=(12, 14), sharex=False,
220-
gridspec_kw={'height_ratios': [3, 1, 1, 2]}
227+
fig2, (ax_top, ax_mid, ax_gatedrat, ax_bottom, ax_ltdist) = plt.subplots(
228+
5, 1, figsize=(12, 17), sharex=False,
229+
gridspec_kw={'height_ratios': [3, 1, 1, 1, 2]}
221230
)
222231
fig2.suptitle(f'Run {run_number} - Chunked FCUP Gated (Neighbor Handling)', fontsize=16)
223232

@@ -226,6 +235,7 @@ def main():
226235
#ax_top.plot(chunk_indices, cum_caseB, label='Cumulative Case B (LT_nn × FCUPungated_nn)', color='darkgreen', marker='s')
227236
ax_top.plot(chunk_indices, cum_caseC, label='Cumulative Case C (20-NN mean × FCUPungated)', color='darkorange', marker='d')
228237
ax_top.plot(chunk_indices, cum_default, label='Cumulative Default (FCUPgated)', color='blue', marker='^')
238+
ax_top.plot(chunk_indices, cum_default_ungated, label='Cumulative Default Ungated (FCUPungated)', color='teal', marker='x',linestyle='--')
229239
ax_top.set_ylabel('Cumulative Σ', fontsize=11)
230240
ax_top.grid(True, linestyle='--', alpha=0.6)
231241
ax_top.legend(fontsize=10)
@@ -235,16 +245,27 @@ def main():
235245
ratioA = np.divide(cum_caseA, cum_default, out=np.full_like(cum_caseA, np.nan, dtype=float), where=np.array(cum_default) != 0)
236246
#ratioB = np.divide(cum_caseB, cum_default, out=np.full_like(cum_caseB, np.nan, dtype=float), where=np.array(cum_default) != 0)
237247
ratioC = np.divide(cum_caseC, cum_default, out=np.full_like(cum_caseC, np.nan, dtype=float), where=np.array(cum_default) != 0)
248+
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)
238249

239250
ax_mid.plot(chunk_indices, ratioA, label='Case A / Default', color='darkred', marker='o')
240251
#ax_mid.plot(chunk_indices, ratioB, label='Case B / Default', color='darkgreen', marker='s')
241252
ax_mid.plot(chunk_indices, ratioC, label='Case C / Default', color='darkorange', marker='d')
253+
ax_mid.plot(chunk_indices, ratioDefUng, label='Default FCUP Ungated / Default FCUP gated', color='teal', marker='x',linestyle='--')
242254
ax_mid.axhline(1.0, color='black', linestyle='--', linewidth=1)
243255
ax_mid.set_ylabel('Ratio', fontsize=11)
244256
ax_mid.grid(True, linestyle='--', alpha=0.6)
245257
ax_mid.legend(fontsize=10)
246258
ax_mid.tick_params(axis='both', labelsize=10)
247259

260+
# Gated / Ungated ratio panel
261+
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)
262+
ax_gatedrat.plot(chunk_indices, ratio_gated_ung, label='FCUPgated / FCUPungated', color='navy', marker='o')
263+
ax_gatedrat.axhline(1.0, color='black', linestyle='--', linewidth=1)
264+
ax_gatedrat.set_ylabel('Gated / Ungated', fontsize=11)
265+
ax_gatedrat.grid(True, linestyle='--', alpha=0.6)
266+
ax_gatedrat.legend(fontsize=10)
267+
ax_gatedrat.tick_params(axis='both', labelsize=10)
268+
248269
# Bottom-1: skipped events count
249270
ax_bottom.bar(chunk_indices, skipped_counts, color='gray', alpha=0.7)
250271
ax_bottom.set_xlabel(f'Chunk Index (Each = {chunk_size} events)', fontsize=11)

0 commit comments

Comments
 (0)