From deeb74de4bf73cb63e124c68a2fc99eef8a35ed0 Mon Sep 17 00:00:00 2001 From: Stephen Elliott Greenberg Date: Sat, 13 Jan 2024 10:43:55 -0800 Subject: [PATCH 1/4] fix sync issue frequency to match rollover --- cli/simulate_pixels.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 20aea0dd..0176a4ea 100755 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -778,7 +778,7 @@ def save_results(event_times, is_first_batch, results, i_mod=-1, light_only=Fals sync_times = cp.arange(sync_start, this_event_time[0], fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) #us if len(sync_times) > 0: fee.export_sync_to_hdf5(output_filename, sync_times, i_mod) - sync_start = sync_times[-1] + fee.CLOCK_RESET_PERIOD + sync_start = sync_times[-1] + fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE # beam trigger is only forwarded to one specific pacman (defined in fee) if (light.LIGHT_TRIG_MODE == 0 or light.LIGHT_TRIG_MODE == 1) and i_mod == 1: fee.export_timestamp_trigger_to_hdf5(output_filename, this_event_time, i_mod) @@ -790,8 +790,11 @@ def save_results(event_times, is_first_batch, results, i_mod=-1, light_only=Fals null_light_results_acc['light_event_id'].append(cp.full(1, ievd)) # one event save_results(event_times, is_first_batch, null_light_results_acc, i_mod, light_only=True) del null_light_results_acc['light_event_id'] + # Nothing to simulate for charge readout? continue + + for itrk in tqdm(range(0, evt_tracks.shape[0], sim.BATCH_SIZE), delay=1, desc=' Simulating event %i batches...' % ievd, leave=False, ncols=80): if itrk > 0: From e6e27dd8a3062d60a84077c6cdd85174f5d92991 Mon Sep 17 00:00:00 2001 From: Stephen Elliott Greenberg Date: Sun, 14 Jan 2024 12:19:30 -0800 Subject: [PATCH 2/4] updates to timestamp packets and fix pps sync issuing --- cli/simulate_pixels.py | 6 +++--- larndsim/fee.py | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 0176a4ea..a730f85b 100755 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -760,7 +760,7 @@ def save_results(event_times, is_first_batch, results, i_mod=-1, light_only=Fals logger.start() logger.take_snapshot([0]) i_batch = 0 - sync_start = event_times[0] // (fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) * (fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) + sync_start = event_times[0] // (fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) * (fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) + (fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) det_borders = module_borders if mod2mod_variation else detector.TPC_BORDERS for batch_mask in tqdm(batching.TPCBatcher(all_mod_tracks, tracks, sim.EVENT_SEPARATOR, tpc_batch_size=sim.EVENT_BATCH_SIZE, tpc_borders=det_borders), desc='Simulating batches...', ncols=80, smoothing=0): @@ -774,8 +774,8 @@ def save_results(event_times, is_first_batch, results, i_mod=-1, light_only=Fals this_event_time = [event_times[ievd % sim.MAX_EVENTS_PER_FILE]] # forward sync packets - if this_event_time[0] - sync_start > 0: - sync_times = cp.arange(sync_start, this_event_time[0], fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) #us + if this_event_time[0] - sync_start >= 0: + sync_times = cp.arange(sync_start, this_event_time[0]+1, fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) #us if len(sync_times) > 0: fee.export_sync_to_hdf5(output_filename, sync_times, i_mod) sync_start = sync_times[-1] + fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE diff --git a/larndsim/fee.py b/larndsim/fee.py index a4b9d89b..a8c578ee 100644 --- a/larndsim/fee.py +++ b/larndsim/fee.py @@ -189,11 +189,11 @@ def export_to_hdf5(event_id_list, unique_events, unique_events_inv = np.unique(event_id_list[...,0], return_inverse=True) event_start_time_list = (event_start_times[unique_events_inv] / CLOCK_CYCLE).astype(int) - light_trigger_times = np.empty((0,)) if light_trigger_times is None else light_trigger_times light_trigger_event_id = np.empty((0,), dtype=int) if light_trigger_event_id is None else light_trigger_event_id rollover_count = 0 + last_time_tick = -1 for itick, adcs in enumerate(adc_list): ts = adc_ticks_list[itick] pixel_id = unique_pix[itick] @@ -311,17 +311,29 @@ def export_to_hdf5(event_id_list, p.first_packet = 1 p.assign_parity() + if not time_tick==last_time_tick: + # timestamp packet every time there is a new "message" + # the logic in real data for when a timestamp packet is complicated and depends on pacman CPU speed, packet creation rate + # best simple approximation is that any group of packets with the same timestamp get a single timestamp packet + last_time_tick = time_tick + packets.append(TimestampPacket(timestamp=np.floor(event_start_time_list[0] * CLOCK_CYCLE * units.mus/units.s)) ) # s + packets[-1].chip_key = Key(io_group,0,0) + packets_mc_evt.append([-1]) + packets_mc_trk.append([-1] * (ASSOCIATION_COUNT_TO_STORE * 2)) + packets_frac.append([0] * (ASSOCIATION_COUNT_TO_STORE*2)) + packets_mc_evt.append([event]) packets_mc_trk.append(track_ids[itick]) packets_frac.append(current_fractions[itick][iadc]) packets.append(p) + + else: break if packets: packet_list = PacketCollection(packets, read_id=0, message='') hdf5format.to_file(filename, packet_list, workers=1) - dtype = np.dtype([('event_ids',f'(1,)i8'), ('segment_ids',f'({ASSOCIATION_COUNT_TO_STORE},)i8'), ('fraction', f'({ASSOCIATION_COUNT_TO_STORE},)f8')]) From 01ac7a4166dce897ab5d424c86749e46ab0e1518 Mon Sep 17 00:00:00 2001 From: Stephen Elliott Greenberg Date: Mon, 15 Jan 2024 19:38:17 -0800 Subject: [PATCH 3/4] fix packet-->segment backtracking --- cli/simulate_pixels.py | 4 ++-- larndsim/fee.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index a730f85b..dc9db565 100755 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -754,7 +754,7 @@ def save_results(event_times, is_first_batch, results, i_mod=-1, light_only=Fals logger.take_snapshot() track_ids = cp.asarray(np.arange(segment_ids.shape[0], dtype=int)) - + segment_ids_arr = cp.asarray(segment_ids) # We divide the sample in portions that can be processed by the GPU is_first_batch = True logger.start() @@ -954,7 +954,7 @@ def save_results(event_times, is_first_batch, results, i_mod=-1, light_only=Fals results_acc['unique_pix'].append(unique_pix) results_acc['current_fractions'].append(current_fractions) #track_pixel_map[track_pixel_map != -1] += first_trk_id + itrk - track_pixel_map[track_pixel_map != -1] = track_ids[batch_mask][track_pixel_map[track_pixel_map != -1] + itrk] + track_pixel_map[track_pixel_map != -1] = segment_ids_arr[batch_mask][track_pixel_map[track_pixel_map != -1] + itrk] results_acc['track_pixel_map'].append(track_pixel_map) # ~~~ Light detector response simulation ~~~ diff --git a/larndsim/fee.py b/larndsim/fee.py index a8c578ee..fd505656 100644 --- a/larndsim/fee.py +++ b/larndsim/fee.py @@ -321,7 +321,6 @@ def export_to_hdf5(event_id_list, packets_mc_evt.append([-1]) packets_mc_trk.append([-1] * (ASSOCIATION_COUNT_TO_STORE * 2)) packets_frac.append([0] * (ASSOCIATION_COUNT_TO_STORE*2)) - packets_mc_evt.append([event]) packets_mc_trk.append(track_ids[itick]) packets_frac.append(current_fractions[itick][iadc]) From f83a6234e99c3517241a00d3211cf0a2c94a33fb Mon Sep 17 00:00:00 2001 From: Stephen Elliott Greenberg Date: Tue, 16 Jan 2024 09:32:25 -0800 Subject: [PATCH 4/4] fixed timestamp in sync packets --- cli/simulate_pixels.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index dc9db565..da9efa2b 100755 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -776,8 +776,10 @@ def save_results(event_times, is_first_batch, results, i_mod=-1, light_only=Fals # forward sync packets if this_event_time[0] - sync_start >= 0: sync_times = cp.arange(sync_start, this_event_time[0]+1, fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) #us + #PSS Sync also resets the timestamp in the PACMAN controller, so all of the timestamps in the packs should read 1e7 (for PPS) + sync_times_export = cp.full( sync_times.shape, fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE) if len(sync_times) > 0: - fee.export_sync_to_hdf5(output_filename, sync_times, i_mod) + fee.export_sync_to_hdf5(output_filename, sync_times_export, i_mod) sync_start = sync_times[-1] + fee.CLOCK_RESET_PERIOD * fee.CLOCK_CYCLE # beam trigger is only forwarded to one specific pacman (defined in fee) if (light.LIGHT_TRIG_MODE == 0 or light.LIGHT_TRIG_MODE == 1) and i_mod == 1: