diff --git a/CLAUDE.md b/CLAUDE.md index ea89dd7..8624d27 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -48,7 +48,7 @@ JAXTPC/ │ ├── scan_values.py # CPU-only values + config patch + plots │ ├── find_optimal_chunks.py # Two-pass timing → response_chunk, hits_chunk │ └── threshold_analysis.py # Post-sim sweep → threshold_adc, corr_threshold -├── tests/ # Pytest suite (264 tests, CPU-only, synthetic data) +├── tests/ # Pytest suite (299 tests, CPU-only, synthetic data) │ └── conftest.py # Fixtures: jax_key, minimal_detector_config, ... ├── viewer/ # Interactive 3D/2D HTML viewer + GIF export │ ├── serve_viewer.py # Local HTTP server with byte-range HDF5 support @@ -100,7 +100,7 @@ Deposits are split by x-position into volumes during loading (`build_deposit_dat Two parameter bundles control the simulation: - **`SimConfig`** (static, closure-captured) — Array dimensions, mode flags, volume geometry, plane names. Changing any value requires JIT recompilation. -- **`SimParams`** (dynamic, JIT argument) — Physics scalars (velocity, lifetime, diffusion coefficients, recombination parameters) and optional NN/SCE models. Can be changed without recompilation. +- **`SimParams`** (dynamic, JIT argument) — Physics scalars (velocity, lifetime, diffusion coefficients, recombination parameters) and optional NN/SCE models. Can be changed without recompilation. In the production path (`process_event`) the diffusion table is built at construction from the config, so changing the diffusion coefficients or velocity in `SimParams` does not change the diffusion blur there; build a new simulator. `forward` recomputes it. Detector geometry is defined in YAML (`config/cubic_wireplane_config.yaml`): ```yaml @@ -221,10 +221,12 @@ The profiler scans data (CPU) and benchmarks the sim (GPU, chunks + maxg_medium Produces three HDF5 file types per batch: - `{dataset}_sensor_{NNNN}.h5` — sparse thresholded raw readout (delta-encoded, uint16 if digitized) - `{dataset}_step_{NNNN}.h5` — 3D truth deposits (pure physics: positions + de/dx/theta/phi/t0_us + charge/photons; no instance or track info) -- `{dataset}_hits_{NNNN}.h5` — per-particle sensor decomposition + group machinery (deposit_to_group, qs_fractions, group_to_track per volume; per-plane CSR-encoded pixel entries) +- `{dataset}_hits_{NNNN}.h5` — per-particle charge per wire/pixel cell (wire: drifted charge with diffusion, *before* the detector response, so it does not sum to the sensor; pixel: the sensor signal itself) + group machinery (deposit_to_group, qs_fractions, group_to_track per volume; per-plane CSR-encoded pixel entries) A fourth file, `{dataset}_labl_{NNNN}.h5`, carries per-track labels and the per-deposit → track_id foreign key. It is produced separately via `production/make_labl.py` (temp stand-in; reads hits + edepsim). See `production/README.md` for the labl schema and workflow. +Events are stored as `entry_NNNNNN` groups (`/config` attr `format_version = 2`; older files use `event_NNN`). Use `production/entries.py` rather than building names; `production/load.py` reads both. + Threaded save architecture: reader prefetch thread loads the next event's HDF5 while GPU sim runs; main thread dispatches sim; save worker threads (default 2) encode CSR + write HDF5 in parallel with per-file locks (`sen_lock`, `step_lock`, `hits_lock`) so sensor/step/hits writes overlap across workers. Enable `JAXTPC_PROFILE_SAVE=1` to see per-phase timings (encode/lockwait/write-sensor/write-step/write-hits) in the save log. **Output compression** (`--codec`, default `blosc-zstd`): all datasets are compressed with the codec set via `production/save.py:set_codec`. blosc-zstd is smaller than gzip *and* faster on both read and write (gzip is Pareto-dominated). Alternatives: `blosc-lz4hc` (gzip's size, ~4× faster reads), `blosc-lz4` (fastest read+write, +19% size), `gzip`, `lzf`. **Reading non-gzip output requires `import hdf5plugin`** — `production/load.py` and pimm-data's readers register it automatically; ad-hoc `h5py` consumers must import it themselves. Re-encode existing files between codecs with `pimm-data/scripts/transcode_codec.py`. @@ -236,7 +238,7 @@ from production.load import build_viz_config, load_event_sensor, load_event_step viz_config = build_viz_config('output/sensor/sim_sensor_0000.h5') dense_signals, attrs, pedestals = load_event_sensor(sensor_path, event_idx=0) volumes = load_event_step(step_path, event_idx=0) -track_hits, truth_dense, g2t = load_event_hits(hits_path, event_idx=0, num_time_steps=2701) +track_hits, truth_dense, g2t, d2g, qs = load_event_hits(hits_path, event_idx=0) ``` ### Tests diff --git a/docs/architecture/config-vs-params.md b/docs/architecture/config-vs-params.md index de12fa6..27cd012 100644 --- a/docs/architecture/config-vs-params.md +++ b/docs/architecture/config-vs-params.md @@ -110,6 +110,12 @@ compiled function runs. In the differentiable path ([`forward`](execution-paths.md)), these scalars are exactly the parameters that carry gradients. +!!! warning "Production diffusion is fixed at construction" + The production path (`process_event`) builds its diffusion table once, from + the detector config. Changing the diffusion coefficients or velocity in + `SimParams` does not change the diffusion blur there: build a new simulator. + `forward` recomputes the table from `SimParams`. + !!! note "Rule of thumb" If a value changes an **array shape or a code branch**, it belongs in `SimConfig` (and costs a recompile). If it is a **physics number** the model diff --git a/docs/architecture/simulator.md b/docs/architecture/simulator.md index 3cc42cc..6495b47 100644 --- a/docs/architecture/simulator.md +++ b/docs/architecture/simulator.md @@ -124,7 +124,8 @@ The construction/call split maps exactly onto two NamedTuples: | **Changing it** | Requires a new closure → **JIT recompile** | Free — **no recompile** | Because `SimParams` is the sole traced argument, you can sweep velocity, -lifetime, diffusion, or recombination values across events without recompiling. +lifetime, or recombination values across events without recompiling. Diffusion is +the exception in the production path: its table is fixed at construction. Changing anything structural (a mode flag, `total_pad`, geometry) means building a new `DetectorSimulator`. See [config vs params](config-vs-params.md). diff --git a/docs/contributing/development.md b/docs/contributing/development.md index 02ffb22..a0dc486 100644 --- a/docs/contributing/development.md +++ b/docs/contributing/development.md @@ -30,7 +30,7 @@ is deferred, so a non-editable wheel is not yet the supported path. ## Running the tests -The suite is **264 tests**, all CPU-only on synthetic data (no external files, +The suite is **299 tests**, all CPU-only on synthetic data (no external files, no kernels required for the fast tier). `pytest.ini` puts the repo root on `sys.path`, so bare `pytest` works from the repo root without any install step. @@ -70,7 +70,7 @@ Shared fixtures live in `tests/conftest.py` — `jax_key`, a also forces `JAX_PLATFORM_NAME=cpu` at collection time, so a plain `pytest` invocation still runs on CPU. -For the full module-by-module breakdown (what each of the 264 tests checks), see +For the full module-by-module breakdown (what each of the 299 tests checks), see [`tests/TESTS.md`](https://github.com/DeepLearnPhysics/JAXTPC/blob/main/tests/TESTS.md). ## Notebooks: keep diffs clean diff --git a/docs/detector/config-schema.md b/docs/detector/config-schema.md index 336aa8f..f6e5a2e 100644 --- a/docs/detector/config-schema.md +++ b/docs/detector/config-schema.md @@ -150,6 +150,7 @@ A volume becomes a pixel volume when its `readout.type` is `pixel`. It then has |---|---|---|---| | `type` | **yes** | `pixel` | Selects pixel readout for this volume. | | `pixel_pitch` | **yes** | cm | Square pixel pitch; used as the transverse spatial reference for diffusion. | +| `response_pixel_bin` | no (default: the NPZ's bin) | cm | Bin size at which to read the response table. Set it to `pixel_pitch / 10` when the pitch differs from the one the table was computed for (3.72 mm). Scales the transverse axes only. | | `pixel_shape` | **yes** | `[num_py, num_pz]` | Pixel grid dimensions in (y, z). | The pixel-grid origin is derived in the **local, yz-centered** frame diff --git a/docs/detector/presets.md b/docs/detector/presets.md index 4320534..ecdd770 100644 --- a/docs/detector/presets.md +++ b/docs/detector/presets.md @@ -51,8 +51,10 @@ continuous rectangular model does not capture per-APA wire segmentation. **`cubic_pixel_config.yaml`** — the same dual-cube geometry as `cubic_wireplane_config`, but each volume uses pixel readout: 4.32 mm pitch, -1000×1000 pixels covering the 432 cm y/z span. The direct wire↔pixel comparison -config. +1000×1000 pixels covering the 432 cm y/z span, and the same readout window as wire +(0.3/0.3 of the max drift time, 4321 ticks). The response table was computed for +3.72 mm pads; `response_pixel_bin: 0.0432` scales it to this pitch. The direct +wire↔pixel comparison config. **`dune_ndlar_config.yaml`** — DUNE ND-LAr / ArgonCube, the largest preset. 35 modules in a 5×7 grid, each dual-drift → **70** pixel volumes. LArPix readout at diff --git a/docs/detector/wire-vs-pixel.md b/docs/detector/wire-vs-pixel.md index af20cb7..fde561a 100644 --- a/docs/detector/wire-vs-pixel.md +++ b/docs/detector/wire-vs-pixel.md @@ -11,7 +11,7 @@ shapes, and which post-processing stages run. | | **Wire** | **Pixel** | |---|---|---| | Sensor geometry | 3 angled 1-D wire planes (U/V/Y) | Single 2-D pixel grid (y×z) | -| Config | `planes[]` list (`angle`, `wire_spacing`, `distance_from_anode`) | `readout: {type: pixel, pixel_pitch, pixel_shape}` | +| Config | `planes[]` list (`angle`, `wire_spacing`, `distance_from_anode`) | `readout: {type: pixel, pixel_pitch, pixel_shape}`, optional `response_pixel_bin` | | Kernel | Dimensionless field-impulse fraction | Chip gain (ADC/e⁻) baked in | | Hits-stage units | **ENC** (electrons) | **ADC** | | Sensor-signal units | **ADC** (post-digitize) | **ADC** (same pass) | diff --git a/docs/physics/drift-diffusion.md b/docs/physics/drift-diffusion.md index c8c4a71..36c3d5c 100644 --- a/docs/physics/drift-diffusion.md +++ b/docs/physics/drift-diffusion.md @@ -84,7 +84,8 @@ as `√t`: `D_trans` and `D_long` are the transverse/longitudinal diffusion coefficients (YAML `transverse_diffusion` / `longitudinal_diffusion`, converted to cm²/µs and carried in `SimParams` and `DiffusionConfig`). Because `t ∝` drift distance, the -spread grows with how far a deposit drifts. +spread grows with how far a deposit drifts. The transverse spread is converted to +wire pitches with **each plane's own** spacing. ### Kernel-based diffusion (the production path) diff --git a/docs/physics/response-kernels.md b/docs/physics/response-kernels.md index b9a0e6e..eac922d 100644 --- a/docs/physics/response-kernels.md +++ b/docs/physics/response-kernels.md @@ -134,5 +134,16 @@ at 0; within half a bin of the centre the mirror neighbour of bin 0 is bin 0 itself. For the same reason the 3-D table builder pads the spatial axes with `mode='symmetric'`, which repeats bin 0 when it mirrors the table about the centre. +### Using the table at another pixel pitch + +The shipped table has 0.0372 cm bins: 10 per 3.72 mm pixel, with the pad filling the +cell. At another pitch those bins no longer tile the cell, and charge between pads is +lost. `response_pixel_bin` in the volume's `readout` block sets the bin size instead; +`pitch / 10` scales the pad with the cell (`cubic_pixel_config`: 0.0432 cm). Time is +not scaled: the pulse length follows from the depth in front of the pads and the drift +speed, which a change of pitch does not set. This is a scaling of a 3.72 mm +calculation, not a field calculation for the new pitch: charge is exact, pulse shapes +near pad edges are approximate. + For the full unit accounting and threshold semantics, see [units](units.md). For the readout-path differences, see [wire vs pixel](../detector/wire-vs-pixel.md). diff --git a/docs/production/data-formats.md b/docs/production/data-formats.md index d20854c..62fdde3 100644 --- a/docs/production/data-formats.md +++ b/docs/production/data-formats.md @@ -28,7 +28,7 @@ events of **all** inputs, in input order, go into one file set instead: |---|---|---|---| | **sensor** | `_sensor_` | Sparse thresholded raw readout after full detector sim; delta-encoded, `uint16` if digitized | `run_batch.py` | | **step** | `_step_` | 3D truth deposits — positions + `de`/`dx`/`theta`/`phi`/`t0_us` + `charge`/`photons`; pure physics, no track or instance info | `run_batch.py` | -| **hits** | `_hits_` | Per-particle sensor decomposition + group machinery — `deposit_to_group`, `qs_fractions`, `group_to_track` per volume, per-plane CSR-encoded entries | `run_batch.py` (with track-hits on) | +| **hits** | `_hits_` | Per-particle charge per readout cell (wire: before the detector response, so it does not sum to the sensor; pixel: the sensor signal) + group machinery — `deposit_to_group`, `qs_fractions`, `group_to_track` per volume, per-plane CSR-encoded entries | `run_batch.py` (with track-hits on) | | **labl** | `_labl_` | Per-track labels + per-deposit → `track_id` foreign key | `production/make_labl.py` (separate, temporary stand-in) | Every event lives under an `entry_{NNNNNN}` group, and every event is split by diff --git a/docs/reference/glossary.md b/docs/reference/glossary.md index 16e1a2f..e6330e2 100644 --- a/docs/reference/glossary.md +++ b/docs/reference/glossary.md @@ -143,7 +143,8 @@ recompilation. Contrast `SimParams`. See **`SimParams`** — The **dynamic** physics parameters passed as a JIT argument (velocity, lifetime, diffusion, recombination scalars, optional NN/SCE models). -Changeable without recompiling. See +Changeable without recompiling (the production path fixes its diffusion table at +construction). See [config vs params](../architecture/config-vs-params.md). ## T diff --git a/mkdocs.yml b/mkdocs.yml index baea9b9..84e0dcc 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -93,6 +93,7 @@ nav: - Recombination: physics/recombination.md - Drift & diffusion: physics/drift-diffusion.md - Response kernels: physics/response-kernels.md + - Response representation: physics/response_representation.md - Electronics & noise: physics/electronics-noise.md - Space charge (SCE): physics/sce.md - Units (ENC vs ADC): physics/units.md diff --git a/production/README.md b/production/README.md index c3e2e44..cb1be2e 100644 --- a/production/README.md +++ b/production/README.md @@ -138,7 +138,7 @@ For each event, `run_batch.py` performs: 4. **Save** to three HDF5 file types (offloaded to worker threads): - `sensor/`: sparse thresholded raw readout - `step/`: compact 3D truth deposits - - `hits/`: per-particle sensor decomposition (group-level 3D-to-2D mapping) + - `hits/`: per-particle charge per readout cell (wire: pre-response charge; pixel: the sensor signal) The canonical layout in ``docs/DATASET_DESIGN.md`` (in ``particle-imaging-models/``) defines a fourth directory, ``labl/``, @@ -179,7 +179,7 @@ dense_signals, attrs, pedestals = load_event_sensor(sensor_path, event_idx=0) # To get signed ADC: signal = dense_signals[(v,p)].astype(int) - pedestals[(v,p)] step = load_event_step(step_path, event_idx=0) # list of per-volume dicts track_hits, truth_dense, g2t, d2g, qs = load_event_hits( - hits_path, event_idx=0, num_time_steps=2701) + hits_path, event_idx=0) # g2t, d2g, qs are lists of per-volume arrays (deposit_to_group is the # per-deposit group id, qs_fractions is the per-deposit charge weight). ``` @@ -193,7 +193,7 @@ Three file types per batch, split by `events_per_file`: ``` {dataset}_sensor_{NNNN}.h5 — raw sensor readout (sparse wire/pixel signals) {dataset}_step_{NNNN}.h5 — 3D truth deposits (energy deposit data) -{dataset}_hits_{NNNN}.h5 — per-particle sensor decomposition +{dataset}_hits_{NNNN}.h5 — per-particle charge per readout cell ``` ### 1. Sensor File (`_sensor_`) diff --git a/profiler/README.md b/profiler/README.md index 73d161e..d0c42e6 100644 --- a/profiler/README.md +++ b/profiler/README.md @@ -4,7 +4,7 @@ Tools for sizing simulation capacities and generating production configs. The production sim's capacities (`total_pad`, `max_keys`, `maxg`, box dims, chunk sizes, thresholds) must be sized for the data — otherwise the sim raises -`RuntimeError` (`total_pad`), reprocesses (`maxg`), or truncates+logs (`max_keys`) +`RuntimeError` (`total_pad`), reprocesses (`maxg`), or refuses the event (`max_keys`) at runtime. The profiler scans the data and benchmarks the sim to set them. ## Quick start @@ -193,8 +193,8 @@ See `CLAUDE.md` "Units convention". - **`total_pad`** — deposits exceed capacity → `RuntimeError` at load. - **`maxg`** — n_groups exceeds capacity → logged; sized at p99.95 so reprocess the rare tail. -- **`max_keys`** — box-cell count exceeds capacity → the count is still correct but stored - keys truncate + log. Size with `compare_max_keys` on the tail. +- **`max_keys`** — box-cell count exceeds capacity → `RuntimeError`; `run_batch` logs and + skips the event. Size with `compare_max_keys` on the tail. ## Contents