From 39a534bcdbdf0f03a582701950b650c9deb3c4f8 Mon Sep 17 00:00:00 2001 From: madantimalsina Date: Tue, 17 Nov 2026 11:42:55 -0800 Subject: [PATCH] Bound the LUT-smearing profile loop instead of scanning it In sum_light_signals the ENABLE_LUT_SMEARING branch iterated over every bin of the LUT time profile to find the bins landing inside the current time tick. The acceptance window is one tick wide (LIGHT_TICK_SIZE = 0.001 us = 1 ns) and profile bins are spaced 1 ns apart, so at most one bin can qualify: the loop ran ~100 iterations per surviving (detector, tick, track) to locate a single contributing bin. Solve the acceptance condition for iprof and iterate only that range. The original predicate is retained inside the narrowed loop, so the bounds can only skip iterations the previous code already rejected and the selected bins are unchanged. Bounds are padded by one bin on each side so rounding in the division cannot clip an edge bin. --- larndsim/light_sim.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/larndsim/light_sim.py b/larndsim/light_sim.py index d6d96fa1..76b126b6 100644 --- a/larndsim/light_sim.py +++ b/larndsim/light_sim.py @@ -97,9 +97,19 @@ def sum_light_signals(segments, segment_voxel, segment_track_id, light_inc, op_c if light.ENABLE_LUT_SMEARING: time_profile = lut[voxel[0],voxel[1],voxel[2],idet_lut]['time_dist'] # normalised + # Narrow iprof to bins that can fall in (start_tick_time, end_tick_time), + # padded by +/-1 bin so float rounding cannot clip an edge bin. + prof_bin = units.ns / units.mus # FIXME: assumes light LUT time profile bins are 1ns (might not be true in general) + iprof_lo = int(floor((start_tick_time - track_time) / prof_bin)) - 1 + iprof_hi = int(ceil((end_tick_time - track_time) / prof_bin)) + 1 + if iprof_lo < 0: + iprof_lo = 0 + if iprof_hi > time_profile.shape[0]: + iprof_hi = time_profile.shape[0] + # add photons to time tick - for iprof in range(time_profile.shape[0]): - profile_time = track_time + iprof * units.ns / units.mus # FIXME: assumes light LUT time profile bins are 1ns (might not be true in general) + for iprof in range(iprof_lo, iprof_hi): + profile_time = track_time + iprof * prof_bin if profile_time < end_tick_time and profile_time > start_tick_time: photons = light_inc['n_photons_det'][itrk,op_channel[idet]] * float32(time_profile[iprof]) / light.LIGHT_TICK_SIZE light_sample_inc[idet,itick] += photons