Repository navigation
fix: Fix pixel kernel sub-tick timing when the tick is coarser than the response table - #5
Open
pgranger23 wants to merge 1 commit into
Open
pgranger23 wants to merge 1 commit into
pgranger23 wants to merge 1 commit into
Conversation
interpolate_pixel_response_kernel delays the fine (NPZ-resolution) trace by the sub-bin fraction, then applied jnp.roll(-t_sub_bin), which moves it EARLIER by the whole-bin part of the offset. With rebin_factor > 1 (any tick coarser than the 0.1 us NPZ bin, e.g. the default 0.5 us) the signal time is a sawtooth in the deposit's arrival time: 0.85 us peak-to-peak on the ND-LAr preset. rebin_factor = 1 (0.1 us tick) is unaffected. - Delay by +t_sub_bin with zero fill (no wrap-around of the tail). - Align the rebin groups with the simulation ticks: prepend (1 - time_zero_bin_npz) % rebin_factor zero time bins so that the arrival bin minus one is a multiple of rebin_factor. Without this the arrival lands ((time_zero_bin_npz - 1) % rebin_factor) NPZ bins late (0.4 us for the shipped response at 0.5 us). The placed kernel output now equals the tick average of the response arriving at the true time. kernel_time grows by one tick when padding is needed (69 -> 70 for the shipped response at 0.5 us). tests: test_pixel_kernel_timing.py (exact comparison with the delayed response at rebin 1 and 5, centroid linearity, d/d(arrival) continuity and finite differences across tick and NPZ-bin boundaries).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix pixel kernel sub-tick timing when the tick is coarser than the response table
Summary
With a simulation tick coarser than the 0.1 µs pixel response table (
rebin_factor > 1, so every pixel preset at the default 2 MHz), the time of a pixel signal depends on where inside the tick the charge arrives. The signal time is a sawtooth in the arrival time, 0.85 µs peak to peak on the ND-LAr preset (±0.65 mm in drift). At a 0.1 µs tick (rebin_factor = 1) nothing is wrong and this PR changes nothing.After the fix the kernel output equals the tick average of the response arriving at the true time, and the signal is continuous in the arrival time.
Cause
interpolate_pixel_response_kernelsplits the sub-tick offset into whole 0.1 µs binst_sub_binand a fractiont_alpha:time_zero_bin = (time_zero_bin_npz - 1) // rebin_factordrops the remainder, so the rebin groups do not start on a tick boundary relative to the arrival. With the roll sign corrected alone, every signal would be a constant 0.4 µs late for the shipped response at 0.5 µs.Reproduction
Public functions only, shipped
config/pixel_response.npz, run from the repository root:Signal centroid minus expected, in µs, for arrivals 100.0, 100.1, … 101.0 µs:
mainThe same through
DetectorSimulatorend to end (ND-LAr preset, one volume, point deposits at pixel centres):Centre-pixel signal centroid minus (true arrival + response centroid) against the true arrival time. Orange:
main. Blue: this PR. Solid: no diffusion. Dashed: default diffusion.The fix
interpolate_pixel_response_kernel: delay the fine trace by+t_sub_binbins, zero-filled, so nothing wraps around from the tail.load_pixel_response_kernel: prepend(1 - time_zero_bin_npz) % rebin_factorzero time bins to the response before the table is built, so thattime_zero_bin_npz - 1is a multiple ofrebin_factorand the rebin groups line up with the simulation ticks.Linear interpolation between adjacent 0.1 µs bins is the exact bin average of a current that is constant within each bin, and the mean over
rebin_factorsuch bins is the exact tick average. So the output is now exact for the table as stored, not an approximation.The padding is lossless (zeros in front).
kernel_timegrows by one tick when padding is needed: 69 → 70 for the shipped response at 0.5 µs, unchanged at 0.1 µs.Effect on derivatives
On
mainthe derivative with respect to the arrival time is locally correct, but the signal jumps at every 0.1 µs of arrival time, so that derivative cannot be used to fit a time. After the fix the signal is continuous.One deposit through the ND-LAr pixel kernel at a 0.5 µs tick. Left: signal centroid minus arrival time. Middle: squared difference to the signal of a deposit arriving at 35.63 µs, against the trial arrival time; triangles show where 15 gradient-descent fits end (
main: 1 of 15 reaches the true time; this PR: 15 of 15). Right: derivative of that loss byjax.grad(lines) and by finite differences (circles); shaded where the derivative onmainpoints away from the true time.Tests
New
tests/test_pixel_kernel_timing.py(7 tests, synthetic response written totmp_path, CPU, about 6 s):rebin_factor1 and 5 and for both phases of the table's time origin (tolerance 1e-5 of the peak);jax.gradwith respect to the arrival time matches finite differences on either side of a tick boundary and of a 0.1 µs bin boundary.main-m "not slow")The four failures on
mainare the tworebin_factor = 5comparisons, the centroid test and the continuity test.Other checks
jax.gradagainst finite differences, 300 random points on the ND-LAr kernelRun times are the best of three alternating runs on a shared CPU machine; not measured on GPU. The cost matches the one extra output tick.
What remains in Figure 1 after the fix
mainat a 0.1 µs tick. Longitudinal diffusion alone gives 0.0000 µs; transverse diffusion alone gives +0.1015 µs. In the table the centre-pixel pulse comes later when the charge lands away from the pixel centre (centroid −0.355 µs at the centre, +0.048 µs at the edge); a calculation from the table alone predicts +0.105 µs for this drift.Impact on existing users
kernel_timeis one tick longer at 0.5 µs (per-deposit kernel memory +1.4 %). The analytic box size fromcompute_box_dimsfollows automatically.