From 5b7cc5717fb38cf834524347040fe74909ff4532 Mon Sep 17 00:00:00 2001
From: Chao Peng <cpeng@anl.gov>
Date: Thu, 23 Apr 2020 15:20:14 -0500
Subject: [PATCH] update analysis script

---
 scripts/analyze_waveform.py | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/scripts/analyze_waveform.py b/scripts/analyze_waveform.py
index 1597b4e..c45fdff 100644
--- a/scripts/analyze_waveform.py
+++ b/scripts/analyze_waveform.py
@@ -58,9 +58,8 @@ f = ROOT.TFile.Open(args.root_file, 'read')
 tree = f.EvTree
 
 trg_ch = np.ndarray(shape=(tree.GetEntries(), ), dtype=object)
-trg_val = np.ndarray(shape=(tree.GetEntries(), 2), dtype='float64')
+trg_val = np.ndarray(shape=(tree.GetEntries(), 3), dtype='float64')
 ch_val = np.ndarray(shape=(tree.GetEntries(), len(ch)*2), dtype='float64')
-props = {c: [np.array([]), np.array([])] for c in ch}
 
 for iev in np.arange(0, tree.GetEntries()):
     tree.GetEntry(iev)
@@ -87,20 +86,18 @@ for iev in np.arange(0, tree.GetEntries()):
     # get the maximum peak from all trigger channels
     ich = np.argmax(ev_trg_peaks)
     trg_ch[iev] = tr[ich]
-    trg_val[iev] = (ev_trg_peaks[ich], ev_trg_poses[ich])
+    trg_val[iev] = (ev_trg_peaks[ich], ev_trg_poses[ich], len(ev_trg_peaks))
 
     # channels
     for i, c in enumerate(ch):
         peaks = branch_to_array1d(tree.__getattr__(c + '_Ppeak'), np.float32)
         poses = branch_to_array1d(tree.__getattr__(c + '_Ptime'), np.float32)
-        props[c][0] = np.concatenate((props[c][0], peaks))
-        props[c][1] = np.concatenate((props[c][1], poses - ev_trg_poses[ich]))
 
         # check timing
         cpeak, cpos = 0, 0
         for peak, pos in zip(peaks, poses):
             pos -= ev_trg_poses[ich]
-            if pos <= ch_pos[i] + pos_width and pos >= ch_pos[i] - pos_width and peak > cpeak:
+            if pos <= (ch_pos[i] + pos_width) and pos >= (ch_pos[i] - pos_width) and peak > cpeak:
                 cpeak = peak
                 cpos = pos
         ch_val[iev][[i, len(ch) + i]] = (cpeak, cpos)
@@ -109,16 +106,8 @@ print('processed {}'.format(iev))
 
 
 result = pd.DataFrame(index=np.arange(0, tree.GetEntries()),
-                      columns=['trg_peak', 'trg_pos'] + [c + '_peak' for c in ch] + [c + '_pos' for c in ch],
+                      columns=['trg_peak', 'trg_pos', 'trg_nhits'] + [c + '_peak' for c in ch] + [c + '_pos' for c in ch],
                       data=np.concatenate((trg_val, ch_val), axis=1))
 result.loc[:, 'trg_ch'] = trg_ch
 result.to_csv(args.output)
 
-bins = np.arange(0, 5000, step=1)
-indices = (bins[1:] + bins[:-1])/2.
-pd.DataFrame(index=indices, data={c: np.histogram(prop[0], bins)[0] for c, prop in props.items()}).to_csv('peaks.csv')
-
-bins = np.arange(-64, 64, step=1)
-indices = (bins[1:] + bins[:-1])/2.
-pd.DataFrame(index=indices, data={c: np.histogram(prop[1], bins)[0] for c, prop in props.items()}).to_csv('timings.csv')
-
-- 
GitLab