Monitors and Twiss conversion¶
- xtrack_tools.monitors.get_monitor_names_at_pattern(line, pattern)[source]¶
Return line element names matching a regex pattern.
- Parameters:
line (xt.Line) – Line whose element names should be searched.
pattern (str) – Regular expression matched against each element name.
- Returns:
Matching element names in line order.
- Raises:
ValueError – If the pattern matches no elements.
- Return type:
- xtrack_tools.monitors.replace_thick_monitors_with_thin_markers(line, monitor_names, length_tol=1e-12)[source]¶
Insert thin markers at the centers of thick monitor elements.
- Parameters:
- Returns:
A tuple
(thin_monitor_names, alias_map)wherethin_monitor_namescan be passed directly tomulti_element_monitor_atandalias_mapmaps any inserted thin-marker names back to the original monitor names.- Raises:
ValueError – If any requested monitor name is not present in the line.
- Return type:
- xtrack_tools.monitors.tbt_data_to_dataframes(tbt_data, tracked_line)[source]¶
Convert
TbtDatainto per-particle tracking DataFrames.Each returned DataFrame contains the monitor name, turn index (1-based), and transverse coordinates for a single particle.
- Parameters:
tbt_data (TbtData) – Turn-by-turn data, one matrix per tracked particle.
tracked_line (xt.Line) – Tracked line containing multi-element monitor data for
px/py.
- Returns:
A list of DataFrames, one per particle.
- Return type:
list[pd.DataFrame]
- xtrack_tools.monitors.line_to_dataframes(tracked_line)[source]¶
Convert tracked multi-element monitor data into per-particle DataFrames.
- Parameters:
tracked_line (xt.Line) – Line containing recorded multi-element monitor data.
- Returns:
A list of DataFrames, one per tracked particle.
- Raises:
ValueError – If the line has no recorded multi-element monitor data.
- Return type:
list[pd.DataFrame]
- xtrack_tools.monitors.process_tracking_data(monitored_line, ramp_turns=1000, flattop_turns=100, add_variance_columns=True)[source]¶
Trim ramp turns from tracking data and optionally add variance columns.
- Parameters:
- Returns:
A single DataFrame containing processed tracking data for the first particle.
- Return type:
pd.DataFrame
- xtrack_tools.monitors.xsuite_tws_to_ng(tws, *, momentum='pt')[source]¶
Convert an xsuite Twiss object to an NG-compatible
tfsDataFrame.Besides renaming the optics columns this puts the dispersion columns into MAD-NG’s convention, which differs from xsuite’s in two ways:
xsuite’s
ddx/ddpx/ddy/ddpyare plain second derivatives, while MAD-NG’schrom=truetwiss folds the Taylor \(1/2\) into them.xsuite differentiates with respect to
delta = dp/p, MAD-NG with respect to the energy coordinatept. The two differ by factors of the relativisticbeta0(~0.52 on the PSB at 160 MeV, i.e. nowhere near 1).
With \(\delta = \delta(p_t) = p_t/\beta_0 - p_t^2/(2\beta_0^2\gamma_0^2)\) the returned columns satisfy, for
momentum="pt",\[x(p_t) = x_{co} + p_t\,D_x + p_t^2\,D_x^{(2)},\]i.e. exactly the form the consumers evaluate (no extra factors), with
\[D_x = \frac{d_x}{\beta_0}, \qquad D_x^{(2)} = \frac{dd_x}{2\beta_0^2} - \frac{d_x}{2\beta_0^2\gamma_0^2}.\]- Parameters:
tws – xsuite Twiss object.
momentum (str) – Conjugate variable of the returned dispersion columns.
"pt"(default) gives full MAD-NG conventions:dx/dpx/dy/dpyare derivatives w.r.t.ptandddx/ddpx/ddy/ddpyare the second-order coefficients w.r.t.pt(Taylor 1/2 already folded in)."delta"keeps xsuite’sdelta = dp/pas the conjugate variable — first-order columns are passed through unchanged and the second-order ones are still turned into coefficients (ddx/2), so the same consumer formula applies withdeltasubstituted forpt. Use it only for pipelines that stay indeltaend to end.
- Returns:
A
tfs.TfsDataFramewith NG-compatible column names and headers.- Return type: