diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 6c3fc8fe..11eabe01 100755 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -648,6 +648,11 @@ def save_results(event_times, is_first_batch, results, i_trig, i_mod=-1, light_o segment_ids = all_mod_segment_ids[module_tracks_mask] RangePop() + # find the module that triggers + io_groups = np.array(list(consts.detector.MODULE_TO_IO_GROUPS.values())) + if light.LIGHT_TRIG_MODE == 0 or light.LIGHT_TRIG_MODE == 1: + trig_module = np.argwhere(io_groups==fee.get_trig_io())[0][0] + 1 # module id (i_mod) counts from 1 + RangePush("run_simulation") TPB = 256 BPG = max(ceil(tracks.shape[0] / TPB),1) @@ -786,7 +791,7 @@ def save_results(event_times, is_first_batch, results, i_trig, i_mod=-1, light_o 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: + if (light.LIGHT_TRIG_MODE == 0 or light.LIGHT_TRIG_MODE == 1) and (i_mod == trig_module or i_mod == -1): fee.export_timestamp_trigger_to_hdf5(output_filename, this_event_time, i_mod) # generate light waveforms for null signal in the module diff --git a/larndsim/fee.py b/larndsim/fee.py index fd505656..e1facfa8 100644 --- a/larndsim/fee.py +++ b/larndsim/fee.py @@ -67,10 +67,6 @@ DISCRIMINATOR_NOISE = 650 * e #: Average time between events in microseconds EVENT_RATE = 100000 # 10Hz -#: Beam trig io group -BEAM_TRIG_IO = 1 -#: Threshold/LRS trig io group -THRES_TRIG_IO = 2 import logging logging.basicConfig() @@ -78,6 +74,16 @@ logger.setLevel(logging.WARNING) logger.info("ELECTRONICS SIMULATION") +def get_trig_io(): + """ + Returns the io_group if the trigger is only forwarded to one pacman + """ + if light.LIGHT_TRIG_MODE == 0: #: Threshold/LRS trigger + trig_io = 2 + elif light.LIGHT_TRIG_MODE == 1: #: Beam trigger + trig_io = 1 + return trig_io + def rotate_tile(pixel_id, tile_id): """ Returns the pixel ID of the rotated tile. @@ -265,10 +271,8 @@ def export_to_hdf5(event_id_list, packets_frac.append([0] * current_fractions.shape[2]) # redundant here elif light.LIGHT_TRIG_MODE == 1: - if module_trig == 1: #beam trigger - io_group = BEAM_TRIG_IO - elif module_trig == 0: #threshold trigger - io_group = THRES_TRIG_IO + if module_trig == 1 or module_trig == 0: #1, beam trigger; 2, threshold trigger + io_group = get_trig_io() packets.append(TriggerPacket(io_group=io_group, trigger_type=b'\x02', timestamp=t_trig)) packets_mc_evt.append([-1]) packets_mc_trk.append([-1] * track_ids.shape[1]) @@ -450,10 +454,7 @@ def export_timestamp_trigger_to_hdf5(filename, event_start_times, i_mod=-1): t_trig = int(np.floor(evt_time / CLOCK_CYCLE)) % CLOCK_RESET_PERIOD # tick - if light.LIGHT_TRIG_MODE == 0: - io_group = THRES_TRIG_IO - if light.LIGHT_TRIG_MODE == 1: - io_group = BEAM_TRIG_IO + io_group = get_trig_io() # timestamp packets packets.append(TimestampPacket(timestamp=evt_time*units.mus/units.s)) # s