Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions config/production_cubic_pixel_doraemon_100micro.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions config/production_cubic_pixel_doraemon_v2_100micro.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions config/production_cubic_wireplane_doraemon_100micro.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion config/production_cubic_wireplane_doraemon_300micro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions profiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <maxg> --total-pad <total_pad> --hits-chunk <hits_chunk> \
--response-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 |
Expand Down
3 changes: 2 additions & 1 deletion profiler/compare_max_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions profiler/find_optimal_chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion profiler/scan_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Loading