diff --git a/config/production_cubic_pixel_doraemon_100micro.yaml b/config/production_cubic_pixel_doraemon_100micro.yaml deleted file mode 100644 index 2ed647f..0000000 --- a/config/production_cubic_pixel_doraemon_100micro.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# JAXTPC production config — cubic_pixel on doraemon data -# Sized 2026-05-25 from actual-sim validation on the doraemon dataset -# (top-500 densest events ranked by max-volume segment count). -# -# Pixel structure note: pixel readout uses NO bucketed accumulation. A single -# track_hits pass produces both the hits and the group-collapsed signal, so: -# - hits_chunk = the per-pass fori_loop chunk -> the speed lever (266->20 iters) -# - max_keys = size of that merge -> the sizing parameter -# - response_chunk = unused in the pixel compute path, but must divide total_pad -# - max_buckets = unused for pixel (no bucketed accumulation) -# -# UNITS: pixel hits AND sensor signal are in ADC (the pixel kernel bakes in the -# chip's ADC/electron gain; pixel skips electronics/noise/digitize entirely). -# So inter_thresh, threshold_adc, and corr_threshold below are ALL in ADC. -# Contrast with wire, where hits are in ENC and only the sensor signal is ADC -# (post-digitize). See CLAUDE.md "Units convention". -detector_config: config/cubic_pixel_config.yaml -total_pad: 1330000 # max per-volume deposits in dataset = 1,327,898; 970k CRASHED on dense events -response_chunk: 66500 # unused for pixel; kept as a divisor of total_pad (1,330,000 / 20) -hits_chunk: 66500 # SPEED LEVER: 1,330,000 / 20; ~3.6x faster than 5000 (266 -> 20 iters) -max_keys: 14000000 # matches documented true dataset max ~14.0M -> ~0 max_keys skips (was 8M, skipped ~0.4-0.8%). Box mode: output-buffer size only, no merge-sort penalty (sweep: ~3% slower vs 8M) -maxg: 240000 # box group capacity; readout-independent p99.95 over 100k events (233,108), 0.034% overflow -> reprocess -maxg_medium: 180000 # tiered mode: p99 of n_groups; 99% of events route here (smaller box, ~24% faster) -inter_thresh: 1.0 # ADC (pixel): in-JIT box compaction filter, |sig| > 1.0 ADC -threshold_adc: 7.0 # ADC (pixel sensor sparse output) — carried over from generic pixel config, NOT re-tuned for doraemon -corr_threshold: 1.0 # ADC (pixel hits CSR encode), |chs| > 1.0 ADC — carried over, NOT re-tuned for doraemon -max_buckets: 1000 # unused for pixel (no bucketed accumulation) diff --git a/config/production_cubic_pixel_doraemon_v2_100micro.yaml b/config/production_cubic_pixel_doraemon_v2_100micro.yaml deleted file mode 100644 index dc2d32b..0000000 --- a/config/production_cubic_pixel_doraemon_v2_100micro.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# JAXTPC production config — cubic_pixel on doraemon data -# Profiled from 100 files (20k events, run_0026628546). -# max_keys from prior full-dataset validation (14M, zero overflows). -# total_pad bumped to 1,330,000 for unseen tail in remaining 400 files. -# -# UNITS: pixel hits AND sensor signal are in ADC. -detector_config: config/cubic_pixel_config.yaml -total_pad: 1330000 -response_chunk: 38000 -hits_chunk: 66500 -max_keys: 14000000 -maxg: 280000 -maxg_medium: 130000 -inter_thresh: 1.0 -threshold_adc: 7.0 -corr_threshold: 1.0 -max_buckets: 1000 diff --git a/config/production_cubic_wireplane_doraemon_100micro.yaml b/config/production_cubic_wireplane_doraemon_100micro.yaml deleted file mode 100644 index 7726150..0000000 --- a/config/production_cubic_wireplane_doraemon_100micro.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# JAXTPC production config — generated by profiler -# -# UNITS: wire hits are in ENC (electrons) by design — wire response is applied -# pre-electronics, so the kernel is dimensionless and intensity (e-) × kernel -# → ENC. The sensor signal becomes ADC only after the electronics → noise → -# digitize chain. So: -# - inter_thresh and corr_threshold are in ENC (filter hits charge in e-) -# - threshold_adc is in ADC (filters the post-digitize sensor signal) -# Contrast with pixel (config/production_cubic_pixel_doraemon.yaml), where -# both hits and signal are in ADC. See CLAUDE.md "Units convention". -detector_config: config/cubic_wireplane_config.yaml -generated: '2026-05-22T21:02:38.008149' -total_pad: 1330000 -response_chunk: 33250 -hits_chunk: 133000 -max_keys: 7000000 -maxg: 240000 # box track-hits group capacity; p99.95 over 100k events (233,108), 0.034% overflow -> reprocess -maxg_medium: 180000 # tiered mode: p99 of n_groups; 99% of events route here (smaller box, ~24% faster) -inter_thresh: 1.0 # ENC (wire): in-JIT box compaction filter, |sig| > 1.0 e- -threshold_adc: 2.0 # ADC (wire sensor sparse output, post-digitize) -corr_threshold: 25.0 # ENC (wire hits CSR encode), chs > 25 e- (signed, wire is positive) -max_buckets: 1000 diff --git a/config/production_cubic_wireplane_doraemon_300micro.yaml b/config/production_cubic_wireplane_doraemon_300micro.yaml index 623e80d..0e630cd 100644 --- a/config/production_cubic_wireplane_doraemon_300micro.yaml +++ b/config/production_cubic_wireplane_doraemon_300micro.yaml @@ -5,7 +5,7 @@ total_pad: 450000 response_chunk: 28125 hits_chunk: 28125 max_keys: 3500000 -maxg: 125000 +maxg: 140000 maxg_medium: 50000 inter_thresh: 1.0 threshold_adc: 2.0 diff --git a/profiler/README.md b/profiler/README.md index 5f89f83..73d161e 100644 --- a/profiler/README.md +++ b/profiler/README.md @@ -23,6 +23,52 @@ python3 production/run_batch.py --data events.h5 \ `--data` accepts files, directories (globbed `*.h5`), or several of each. +## Profiling your own edep-sim / Geant4 setup + +A production config is only valid for the sample it was profiled on. Re-profile +when any of these change: + +| You changed | What moves | +|---|---| +| Step length or voxel size | `total_pad`, `maxg`, `max_keys`, and the `max_keys` overlap knobs | +| Energy, generator, pile-up per event | `total_pad`, `maxg`, `max_keys`, `maxg_medium` | +| Detector YAML (pitch, drift, readout window, response) | `max_keys`, box dims, chunks | +| Group definition (`--group-size`, `--gap-threshold`) | `maxg`, box dims; pass the same values to `run_batch` | + +The input is the edep-sim HDF5 schema read by `tools/loader.py` +(`pstep/lar_vol`, one entry per event). Convert other Geant4 output to it first; +`x`/`y`/`z` (or `position`) and `dx` in mm, `de` in MeV, `t` in ns, plus `theta`, +`phi`, `track_id`, `pdg` and `ancestor_track_id`. A missing field is filled with a +default (zeros; ones for `track_id`), not reported. Positions must be in the detector YAML's frame: deposits +outside every volume are dropped without a message. + +1. **Scan and benchmark** on files spread over the whole sample, not the first + few (capacities are set by rare large events): + ```bash + python3 -m profiler.setup_production --data fileA.h5 fileB.h5 ... \ + --config config/my_detector.yaml -o config/production_my_sample.yaml \ + --workers 24 --headroom 1.1 + ``` +2. **Check `max_keys` with the real simulation.** The overlap knobs (pixel + `c*=2.5`, wire `/3.79`) were calibrated on doraemon and depend on step length: + ```bash + python3 -m profiler.compare_max_keys --data fileA.h5 fileB.h5 ... \ + --config config/my_detector.yaml --rank-validate --rank-by estimate --top-k 25 \ + --maxg --total-pad --hits-chunk \ + --response-chunk --probe-max-keys <2x estimate> + ``` + Pass the box dims the simulator prints at start-up (`--box-bpy/-bpz/-bt` or + `--box-bw/-btw`). Set `max_keys` from the largest ACTUAL plus margin. If + EST/ACTUAL is far from the knob's value, rerun step 1 with `--cstar`/`--divisor`. +3. **Set `maxg` from the largest group count seen (p100) plus margin.** The + suggestion is p99.95, so it skips the tail. `maxg_medium` makes this cheap: + events at or below it run in the smaller simulator. +4. **Check the memory.** Pixel needs `maxg x box_bpy x box_bpz x box_bt x 4` + bytes, and the cell count must stay below 2^31 (the simulator refuses it + otherwise). +5. **Review the thresholds.** `--run-thresholds` values are a data-volume choice, + not a capacity. + ## The pipeline (`setup_production`) | Step | Output | Cost | diff --git a/profiler/compare_max_keys.py b/profiler/compare_max_keys.py index cddd028..e0eb402 100644 --- a/profiler/compare_max_keys.py +++ b/profiler/compare_max_keys.py @@ -221,7 +221,8 @@ def run_rank_validate(args): except RuntimeError as e: # sim raises on track_hits overflow; record as >= probe, continue act_max = args.probe_max_keys - over = f' *** OVERFLOW >= probe ({str(e)[-40:].strip()}) ***' + kind = 'MAXG' if 'maxg overflow' in str(e) else 'MAX_KEYS >= probe' + over = f' *** {kind} OVERFLOW ({str(e)[:90].strip()}) ***' n_overflow += 1 with h5py.File(fp, 'r') as _f: pstep = _f['pstep/lar_vol'][idx] diff --git a/profiler/find_optimal_chunks.py b/profiler/find_optimal_chunks.py index 0b95675..802824c 100644 --- a/profiler/find_optimal_chunks.py +++ b/profiler/find_optimal_chunks.py @@ -78,6 +78,13 @@ def bench_one(detector_config, data_path, event_idx, total_pad, track_config = create_track_hits_config( max_keys=max_keys, hits_chunk_size=hits_chunk, inter_thresh=inter_thresh, box_enabled=True, maxg=maxg) + elif any(v.get('readout', {}).get('type') == 'pixel' + for v in detector_config['volumes']): + # The pixel sensor comes from the hits pass even with track hits off, so + # it needs the estimated max_keys, not TrackHitsConfig's 4M default. + track_config = create_track_hits_config( + max_keys=max_keys, hits_chunk_size=response_chunk, + inter_thresh=inter_thresh, box_enabled=False) sim = DetectorSimulator( detector_config, diff --git a/profiler/scan_values.py b/profiler/scan_values.py index 2ddda60..7533b70 100644 --- a/profiler/scan_values.py +++ b/profiler/scan_values.py @@ -6,7 +6,7 @@ optimization does. Saves distribution plots. """ import sys, glob, yaml, math, os, argparse -sys.path.insert(0, '/sdf/group/neutrino/omara/JAXTPC') +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import numpy as np