Computed columns
scan --expr adds a derived
column to the projection. It uses the same expression
language as --where, but instead of a yes/no cut it
produces a value per row.
hipoq scan rec.hipo --bank REC::Particle --cols pid --expr p --expr theta_deg
event row pid p theta_deg
0 0 11 2.36 12.4
0 1 2212 1.07 18.9
...
Each --expr is either a NAME=EXPRESSION or a bare preset name.
Repeat the flag for several columns.
Custom expressions
hipoq scan rec.hipo --bank REC::Particle --expr "mt=sqrt(px*px+py*py)"
hipoq scan rec.hipo --bank REC::Particle --expr "logp=log(sqrt(px*px+py*py+pz*pz))"
The scanned bank is the expression's driver, so:
- bare columns (
px,pid) bind to the scanned bank, and - cross-bank references resolve by pindex.
Computed columns are data, so they appear in every output format
(table, csv, ndjson, json) — not just the human table.
Presets
A bare word is looked up as a preset. The physics presets follow CLAS12
REC::Particle conventions (angles in radians unless _deg):
| Preset | Expression |
|---|---|
p | sqrt(px*px+py*py+pz*pz) |
pt | sqrt(px*px+py*py) |
theta | polar angle, radians |
theta_deg | polar angle, degrees |
phi | azimuth, radians |
phi_deg | azimuth, degrees |
e | sqrt(p² + pdg_mass(pid)²) |
sampling_fraction | REC::Calorimeter.energy / p (cross-bank sum) |
total_cal_energy | REC::Calorimeter.energy (cross-bank sum) |
hipoq scan rec.hipo --bank REC::Particle --cols pid \
--expr p --expr theta_deg --expr sampling_fraction
sampling_fraction and total_cal_energy are cross-bank: on a REC::Particle
scan they sum each particle's calorimeter rows via pindex, so they only make
sense when a REC::Calorimeter bank is present.
Reverse gather
Because the scanned bank is the driver, scanning a detector bank lets you pull the associated particle's columns — the gather direction of the pindex link:
# each calorimeter hit annotated with its particle's pid
hipoq scan rec.hipo --bank REC::Calorimeter --cols energy,sector \
--expr "pid=REC::Particle.pid"
Here REC::Particle.pid, evaluated on a calorimeter row, reads the pid of the
particle that row points at — the inverse of the summing you get when scanning
REC::Particle.
An expression that produces NaN or Inf (e.g. log of a negative, or a
divide-by-zero) renders as an empty / null cell rather than aborting the scan.