Skip to content

Commit

Permalink
2x2 CL matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Karolina Wresilo committed Dec 15, 2023
1 parent d35071f commit 7c45546
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
41 changes: 41 additions & 0 deletions scripts/proto_nd_scripts/run_CL_matching.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# Runs proto_nd_flow on an example file.
# Before using this script, use
# >> source get_proto_nd_input.sh
# to download all the necessary inputs into the correct directories
#

INPUT_FILE=$1

OUTPUT_DIR='/global/cfs/cdirs/dune/users/kwresilo/data/MiniRun4'
OUTPUT_NAME=(${INPUT_FILE//"/"/ })
OUTPUT_NAME=${OUTPUT_NAME[-1]}
OUTPUT_FILE="${OUTPUT_DIR}/${OUTPUT_NAME}"
OUTPUT_FILE=${OUTPUT_FILE//.h5/.matched_taco.h5}
echo ${OUTPUT_FILE}

# for running on a login node
H5FLOW_CMD='h5flow'
# for running on a single compute node with 32 cores
#H5FLOW_CMD='srun -n32 h5flow'

# run all stages
WORKFLOW1='yamls/proto_nd_flow/workflows/charge/charge_light_assoc.yaml'
HERE=`pwd`
#cd ndlar_flow
# assumes this is being run from ndlar_flow/scripts/proto_nd_flow:
cd ../../

# avoid being asked if we want to overwrite the file if it exists.
# this is us answering "yes".
if [ -e $OUTPUT_FILE ]; then
rm $OUTPUT_FILE
fi

$H5FLOW_CMD -c $WORKFLOW1 -i $INPUT_FILE -o $OUTPUT_FILE

echo "Done!"
echo "Output can be found at $OUTPUT_FILE"

cd ${HERE}

9 changes: 3 additions & 6 deletions src/proto_nd_flow/reco/charge/charge2light.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,20 @@ def finish(self, source_name):

def match_on_timestamp(self, charge_unix_ts, charge_pps_ts):
unix_ts_start = charge_unix_ts.min()
unix_ts_end = charge_unix_ts.max()

unix_ts_end = charge_unix_ts.max()
if self.light_unix_ts_start >= unix_ts_end + self.unix_ts_window or \
self.light_unix_ts_end <= unix_ts_start - self.unix_ts_window:
# no overlap, short circuit
return np.empty((0, 2), dtype=int)

# subselect only portion of light events that overlaps with unix timestamps
i_min = np.argmax((self.light_unix_ts >= unix_ts_start - self.unix_ts_window))
i_max = len(self.light_unix_ts) - 1 - np.argmax((self.light_unix_ts <= unix_ts_end + self.unix_ts_window)[::-1])
i_max = len(self.light_unix_ts) - np.argmax((self.light_unix_ts <= unix_ts_end + self.unix_ts_window)[::-1])
sl = slice(i_min, i_max)

assoc_mat = (np.abs(self.light_unix_ts[sl].reshape(1, -1) - charge_unix_ts.reshape(-1, 1)) <= self.unix_ts_window) \
& (np.abs(self.light_ts[sl].reshape(1, -1) - charge_pps_ts.reshape(-1, 1)) <= self.ts_window)
idcs = np.argwhere(assoc_mat)
#idcs = 1000
if len(idcs):
idcs[:, 1] = self.light_event_id[sl][idcs[:, 1]] # idcs now contains ext trigger index <-> global light event id
else:
Expand All @@ -161,7 +159,6 @@ def run(self, source_name, source_slice, cache):
ext_trigs_mask = ~rfn.structured_to_unstructured(ext_trigs_data.mask).any(axis=-1)

nevents = len(event_data)
print('nevents')
ev_id = np.arange(source_slice.start, source_slice.stop, dtype=int)
ext_trig_ref = np.empty((0, 2), dtype=int)
ev_ref = np.empty((0, 2), dtype=int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ params:

# configuration parameters
unix_ts_window: 1
ts_window: 1000
ts_window: 1000000

0 comments on commit 7c45546

Please sign in to comment.