diff --git a/tests/TESTS.md b/tests/TESTS.md index fe09a84..791f5cd 100644 --- a/tests/TESTS.md +++ b/tests/TESTS.md @@ -156,7 +156,7 @@ The modules above are documented test-by-test; the remaining suites are listed h | test_electronics.py | 21 | RC⊗RC electronics shaping (`tools/electronics.py`) and ADC digitization | | test_output.py | 8 | Output format conversion (`tools/output.py`): dense ↔ sparse ↔ bucketed, threshold application | | test_pipeline.py | 20 | Production path (`process_event`) on a compact detector: output layout, track-hit charge per track = attenuated charge, `qs_fractions`, velocity response, default SimParams, compile-cache counts, mirror symmetry of the volumes, dense == bucketed; plus hand-placed deposits on the full detector | -| test_pipeline_forward.py | 22 (4 xfail) | Differentiable path: relative L2 against production per plane at uniform pitch, and at mixed pitch (V, Y strict xfail: production uses plane 0's pitch for every plane's transverse diffusion); `forward_segments` == `forward`; XLA compile counts; every EMB SimParams gradient vs float64 finite differences | +| test_pipeline_forward.py | 22 | Differentiable path: relative L2 against production per plane at uniform pitch, at uniform and mixed pitch; `forward_segments` == `forward`; XLA compile counts; every EMB SimParams gradient vs float64 finite differences | | test_pipeline_forward_slow.py | 4 | EMB / Modified Box signal ratio = survival ratio, Modified Box gradients, gradients through deposit positions (marked `slow`) | | test_pixel_post_response_truth.py | 16 | Pixel readout post-response truth (`tools/track_hits.py` pixel path) | | test_production_io.py | 14 | Production HDF5 writers/readers (`production/save.py`, `production/load.py`): CSR + delta encoding round-trips | diff --git a/tests/test_pipeline_forward.py b/tests/test_pipeline_forward.py index 90d5b6a..a94b3ac 100644 --- a/tests/test_pipeline_forward.py +++ b/tests/test_pipeline_forward.py @@ -64,20 +64,13 @@ def test_uniform_pitch(self, uniform, vol, plane): assert np.abs(prod).max() > 1.0 # electrons; not a comparison of zeros assert _rel_l2(prod, diff) < 1e-5 - @pytest.mark.parametrize("vol,plane", [ - pytest.param(v, p, marks=[] if p == 0 else pytest.mark.xfail( - strict=True, raises=AssertionError, - reason="production scales every plane's transverse diffusion by " - "wire_spacings_cm[0] (tools/simulation.py): sigma_T on Y is " - "0.363 cm, analytic 0.180 cm. Relative L2 vs forward() is " - + {1: "0.28-0.31 on V", 2: "0.39-0.42 on Y"}[p])) - for v, p in PLANES]) + @pytest.mark.parametrize("vol,plane", PLANES) def test_mixed_pitch(self, mixed, vol, plane): _, _, sig_prod, sig_diff = mixed prod = np.asarray(sig_prod[(vol, plane)]) diff = np.asarray(sig_diff[PLANES.index((vol, plane))]) - if prod.shape != diff.shape or np.abs(prod).max() <= 1.0: - pytest.fail("unexpected shape or empty plane") # not the known bug + assert prod.shape == diff.shape + assert np.abs(prod).max() > 1.0 assert _rel_l2(prod, diff) < 1e-5 diff --git a/tools/kernels.py b/tools/kernels.py index 4bf69fa..ebcbc09 100644 --- a/tools/kernels.py +++ b/tools/kernels.py @@ -190,6 +190,16 @@ def make_level(s): return vmap(make_level)(s_levels) +def _sigma_for_plane(sigma, plane): + """Transverse sigma of one plane: each plane has its own wire pitch. + + Planes absent from the detector still get a table (never read); any sigma does. + """ + if not isinstance(sigma, dict): + return sigma + return sigma.get(plane, next(iter(sigma.values()))) + + def create_diffusion_kernel_array(planes=['U', 'V', 'Y'], num_s=32, kernel_dir=None, time_spacing=0.5, max_sigma_trans_unitless=None, max_sigma_long_unitless=None): @@ -207,7 +217,7 @@ def create_diffusion_kernel_array(planes=['U', 'V', 'Y'], num_s=32, kernel_dir=N Directory containing kernel files. time_spacing : float Time spacing in us. - max_sigma_trans_unitless : float, optional + max_sigma_trans_unitless : float or dict {plane: float}, optional Maximum transverse diffusion sigma in WIRE-PITCH units (same units as the kernel's wire-axis spacing dx). (Name kept for back-compat; not a dimensionless quantity.) @@ -239,7 +249,7 @@ def create_diffusion_kernel_array(planes=['U', 'V', 'Y'], num_s=32, kernel_dir=N # max_sigma_trans_unitless is in physical units (wire pitches) # max_sigma_long_unitless is in grid bins, convert to us - sigma_trans_max = max_sigma_trans_unitless + sigma_trans_max = _sigma_for_plane(max_sigma_trans_unitless, plane) sigma_long_max = max_sigma_long_unitless * time_spacing DKernel = generate_dkernel_table( @@ -414,7 +424,7 @@ def load_response_kernels(response_path=None, num_s=32, Number of diffusion levels to create. time_spacing : float Simulation time spacing in microseconds. - max_sigma_trans_unitless : float, optional + max_sigma_trans_unitless : float or dict {plane: float}, optional Maximum transverse diffusion sigma in WIRE-PITCH units (same units as the kernel's wire-axis spacing dx). (Name kept for back-compat; not a dimensionless quantity.) @@ -467,7 +477,7 @@ def load_response_kernels(response_path=None, num_s=32, wire_zero_bin_out = wire_zero_bin // bins_per_wire # Compute static conv filter sizes for differentiable path - sigma_w_bins = (max_sigma_trans_unitless * wire_spacing) / dx + sigma_w_bins = (_sigma_for_plane(max_sigma_trans_unitless, plane) * wire_spacing) / dx sigma_t_bins = (max_sigma_long_unitless * time_spacing) / dy ks_w = int(2 * ((sigma_w_bins * 2 * _N_SIGMAS_BLUR) // 2) + 1) ks_t = int(2 * ((sigma_t_bins * 2 * _N_SIGMAS_BLUR) // 2) + 1) diff --git a/tools/simulation.py b/tools/simulation.py index 774659c..e18dbf7 100644 --- a/tools/simulation.py +++ b/tools/simulation.py @@ -251,9 +251,13 @@ def __init__( max_sigma_long_unitless=d.max_sigma_long_unitless, ) else: - _, _, global_sigma_trans, global_sigma_long = calculate_max_diffusion_sigmas( - global_max_drift, d.velocity_cm_us, d.trans_cm2_us, d.long_cm2_us, - vol_geom.wire_spacings_cm[0], cfg.time_step_us) + # Transverse sigma is in wire pitches, so it depends on the plane. + global_sigma_trans = {} + for plane_type, spacing in zip(cfg.plane_names[0], vol_geom.wire_spacings_cm): + _, _, global_sigma_trans[plane_type], global_sigma_long = \ + calculate_max_diffusion_sigmas( + global_max_drift, d.velocity_cm_us, d.trans_cm2_us, + d.long_cm2_us, spacing, cfg.time_step_us) self.response_kernels = load_response_kernels( response_path=response_path, num_s=d.num_s,