StatMonitor
StatMonitor records each bunch’s centroid, standard deviations, RMS emittances, derived Twiss parameters and particle losses once per turn at a specified lattice position. Moments use live particles (tag > 0). Each monitor writes a per-bunch history in HDF5 during tracking. TFS output additionally exports that history at finalization. No CSV file is generated.
Configuration example
from PASS.para.schema.monitors import StatMonitorItem
from PASS.para.schema.sequence import Sequence
sequence = Sequence()
sequence.add("stat1", StatMonitorItem(s=0.0, write_interval_turns=100))
Add this item to the complete sequence. write_interval_turns controls disk writes; statistics are still recorded on every turn. The command name comes from the sequence key.
Interface Parameters
Python field |
JSON key |
Type |
Default |
Description |
|---|---|---|---|---|
|
|
float |
Required |
Longitudinal position of the monitor in the beamline |
|
|
str |
|
Command type identifier |
|
|
str |
|
|
|
|
positive int |
100 |
Batch write interval in turns; all intervening rows are retained |
Note
The statistics target all surviving particles in the bunch at that position (tag > 0); no particle indices need to be specified.
Output Files
Each bunch and monitor command writes an HDF5 history. Selecting TFS also generates a text export at finalization; the HDF5 file is retained:
HDF5 (appended in batches; uncompressed when TFS is selected):
{hms}_stat_beam{beam}_bunch{bunch}_Np_{Np}_cmd_{encoded_command_name}_s_{s:.4f}.h5TFS (when selected, generated from HDF5 at finalization):
{hms}_stat_beam{beam}_bunch{bunch}_Np_{Np}_cmd_{encoded_command_name}_s_{s:.4f}.tfs
The output directory is output_dir_stat.
encoded_command_name omits the imported numeric MAD-X occurrence suffix
and trailing position label. For example, either bpm:1_s422.094 or
bpm_s422.094 produces _cmd_bpm_s_422.0937 when the current position is
422.0936762 m. The filename contains the position once, using the current
S (m) value even if the command has moved since import. Other special
characters remain percent-escaped, such as / as %2F.
Only an actual filename collision within the same beam, monitor type and
formatted position adds _2, _3, etc. Case-only differences also count
as collisions so files remain safe on Windows. The HDF5/TFS Monitor
metadata retains the complete unescaped runtime name, and S retains the
full position value. Existing output files keep their names; readers using
exact stems must account for the simplified names in newly written files.
Example metadata (HDF5 attributes, or TFS headers in text mode):
@ Name PASS Statistic Data
@ Monitor stat1
@ Time 2026-07-14 00:11:03
Output columns:
Column name |
Group |
Description |
|---|---|---|
|
Basic |
Turn number |
|
Centroid |
Horizontal position mean \(\langle x \rangle\) |
|
Centroid |
Horizontal momentum mean \(\langle p_x \rangle\) |
|
Beam size |
Horizontal position standard deviation \(\sigma_x\) |
|
Beam size |
Horizontal momentum standard deviation \(\sigma_{p_x}\) |
|
Centroid |
Vertical position mean |
|
Centroid |
Vertical momentum mean |
|
Beam size |
Vertical position standard deviation |
|
Beam size |
Vertical momentum standard deviation |
|
Centroid |
Mean of the folded bunch-relative coordinate \(\langle z_{\mathrm{rel}}\rangle\) |
|
Centroid |
Momentum deviation mean |
|
Beam size |
Standard deviation of the folded bunch-relative coordinate |
|
Beam size |
Momentum deviation standard deviation |
|
Emittance |
Horizontal 2D emittance \(\varepsilon_x\) |
|
Emittance |
Vertical 2D emittance \(\varepsilon_y\) |
|
Twiss |
Horizontal beta function |
|
Twiss |
Vertical beta function |
|
Twiss |
Horizontal alpha function |
|
Twiss |
Vertical alpha function |
|
Twiss |
Horizontal gamma function |
|
Twiss |
Vertical gamma function |
|
Verification |
Horizontal invariant \(\gamma_x \beta_x - \alpha_x^2\) (should equal 1) |
|
Verification |
Vertical invariant (should equal 1) |
|
Longitudinal reference |
Nominal bunch-grouping slot (not the physical centroid), \(z_{\mathrm{center}}\) |
|
Reference |
Reference passage time at this observation (s) |
|
Reference |
Reference velocity divided by c at this observation |
|
Reference |
Reference mechanical momentum at this observation (eV/c per nucleon for ions) |
|
Beam size |
Passage-time standard deviation from continuous z (s) |
|
Correlation |
\(\langle x \, z \rangle\) |
|
Correlation |
\(\langle x \, y \rangle\) |
|
Correlation |
\(\langle y \, z \rangle\) |
|
Correlation |
\(\langle x \, z \rangle / (\sigma_x \, \sigma_z)\) normalized raw cross moment, not a centered Pearson coefficient |
|
Loss |
Number of lost particles |
|
Loss |
Loss percentage |
|
Higher-order moments |
Horizontal skewness |
|
Higher-order moments |
Horizontal kurtosis |
|
Higher-order moments |
Vertical skewness |
|
Higher-order moments |
Vertical kurtosis |
|
Energy |
Bunch kinetic energy |
Longitudinal coordinate in output
Longitudinal moments use a temporary full-ring representative of bunch-relative
z in [-C/2,C/2) on both CPU and GPU. This never changes stored particle z.
HDF5 attributes and TFS headers record ZCoordinate=z_rel_folded_by_ring and ZInterval.
These are moments of the chosen representative, not unwrapped slip statistics
or circular moments; a distribution crossing the interval cut can have a large
reported width. ParticleMonitor and Distribution retain the continuous z_rel
for analyses that need accumulated longitudinal slip.
Injection populations
numAlive, numInjected and numPending record live, born (live plus lost), and reserved macro-particle counts. beamLossTotal excludes pending slots; lossPercent uses the injected population as its denominator. An allocated population with no survivors produces zero moments and explicit zero-survival counts on both CPU and GPU; an empty declared bunch retains the previous no-row behavior.
Batching, final partial batches, live inspection and HDF5 layout are described in Table output formats. Working Principle —————–
Statistics Computation
For \(N\) surviving particles in the bunch (\(\text{tag} > 0\)), the moments of each order are defined as:
First-order moment (centroid):
Second-order moment:
Uncentered cross moment:
Beam size (standard deviation):
Similarly, \(\sigma_{p_x}\), \(\sigma_y\), \(\sigma_{p_y}\), \(\sigma_z\), \(\sigma_{\delta}\) are computed.
The implementation evaluates the equivalent centered moments instead of subtracting large raw moments. CPU and GPU use FP64 accumulators for both FP32 and FP64 particles: first find the centroid relative to a surviving particle, then accumulate moments about that centroid. This also stabilizes covariance, emittance, skewness and kurtosis for narrow or displaced bunches. Particle storage precision is unchanged. The temporary ring projection for z statistics is evaluated in FP64.
sigmaZ and z moments retain a temporary ring-period projection, without changing stored continuous z. sigmaTime uses the standard deviation of unwrapped z divided by \(\beta_b c\), giving the physical passage-time spread. Rows include referenceTime, referenceBeta and referenceMomentum. Nominal zCenter cannot reconstruct a laboratory centroid.
Emittance and Twiss Parameters
The 2D emittance is derived from second-order moments:
where \(\sigma_{x,p_x} = \langle x \, p_x \rangle - \langle x \rangle \langle p_x \rangle\) is the covariance.
Twiss parameters:
Invariant verification:
The formulas for the vertical direction (y) are identical in form; simply replace the subscript x with y.
Higher-Order Moments
Skewness (third standardized moment):
Kurtosis (fourth standardized moment):
Beam Loss
where \(N_{\text{injected}}\) is the number of already injected macro particles (live plus lost), and \(N_{\text{alive}}\) is the current number of surviving particles.
Numerical precision and interpretation
CPU and GPU accumulate centered moments in float64, including for float32 particle storage. The stored particle coordinates retain their configured precision. This reduces cancellation in narrow or displaced bunches, but does not eliminate finite-sampling or tracking errors. GPU records are transferred in batches at the configured write interval.
When an emittance is zero, the corresponding derived Twiss parameters and invariant are reported as zero. For nonzero emittance the identity gamma*beta-alpha²=1 follows from the definitions; it is not an independent validation of tracking. Skewness and kurtosis are centered standardized moments; kurtosis is not excess kurtosis. A nonzero centroid contributes to xzAverage and its normalized output, so neither is a centered covariance by itself.
Reference time and z definitions follow Longitudinal coordinate and reference time. Batch finalization and live inspection are described in Table output formats.