AC dipole

xtrack_tools.acd.state_marker_names(acd_marker)[source]

Return the (before, after) state-marker names for an AC-dipole marker.

Parameters:

acd_marker (str)

Return type:

tuple[str, str]

xtrack_tools.acd.insert_ac_dipole(line, tws, acd_marker, acd_ramp, total_turns, driven_tunes, horizontal_excitation, vertical_excitation, lag=0.0, insert_state_markers=False, placement_s=None)[source]

Insert horizontal and vertical AC dipoles at the AC dipole marker.

Parameters:
  • line (Line) – Base line to copy and modify.

  • tws (TwissTable) – Twiss table used for beta functions at the AC dipole.

  • acd_marker (str) – Name of the marker element at which to place the AC dipoles.

  • acd_ramp (int) – Number of ramp turns.

  • total_turns (int) – Total tracking turns at flat top.

  • driven_tunes (list[float]) – Driven tunes (horizontal, vertical).

  • horizontal_excitation (float) – Horizontal excitation scale.

  • vertical_excitation (float) – Vertical excitation scale.

  • lag (float) – Phase lag for the AC dipoles.

  • insert_state_markers (bool) – If True, also insert zero-length markers {acd_marker}_before and {acd_marker}_after a tiny step (1e-8 m) up- and downstream of the AC-dipole kicks, so they unambiguously record the true pre-kick and post-kick momenta.

  • placement_s (float | None)

Returns:

A new line with AC dipole elements inserted.

Return type:

Line

xtrack_tools.acd.prepare_acd_line_with_monitors(line, tws, acd_marker, ramp_turns, flattop_turns, driven_tunes, horizontal_excitation, vertical_excitation, lag, bpm_pattern, insert_state_markers=False, placement_s=None)[source]

Insert AC dipole and prepare multi-element BPM monitoring.

Parameters:
  • line (Line) – Base line to copy and modify.

  • tws (TwissTable | None) – Optional twiss table; computed if not provided.

  • acd_marker (str) – Name of the marker element at which to place the AC dipoles.

  • ramp_turns (int) – Number of ramp turns.

  • flattop_turns (int) – Number of flat-top turns.

  • driven_tunes (list[float]) – Driven tunes (horizontal, vertical).

  • horizontal_excitation (float) – Horizontal excitation scale.

  • vertical_excitation (float) – Vertical excitation scale.

  • lag (float) – Phase lag for the AC dipoles.

  • bpm_pattern (str) – Regex pattern for BPM locations.

  • insert_state_markers (bool)

  • placement_s (float | None)

Returns:

A tuple of (tracked_line, total_turns, monitor_names).

Return type:

tuple[Line, int, list[str]]

xtrack_tools.acd.run_acd_twiss(line, acd_marker, dpp, driven_tunes)[source]

Run a twiss calculation with AC dipole elements inserted.

Parameters:
  • line (Line) – Base line to copy and modify.

  • acd_marker (str) – Name of the marker element at which to place the AC dipoles.

  • dpp (float) – Momentum deviation for twiss calculation.

  • driven_tunes (list[float]) – Driven tunes (horizontal, vertical).

Returns:

A Twiss table including AC dipole elements.

Raises:

ValueError – If the AC dipole marker is not found.

Return type:

TwissTable

xtrack_tools.acd.run_acd_track(sequence_file, acd_marker, sequence_name, kinetic_energy=6800, delta_p=0.0, ramp_turns=1000, flattop_turns=100, driven_tunes=None, bpm_pattern='(?i)bpm.*', json_path=None, add_variance_columns=True, replace_thick_monitors_with_thin=True, state_markers=False, *, horizontal_excitation, vertical_excitation)[source]

Run AC dipole tracking for a sequence file and return tracking data.

Parameters:
  • sequence_file (Path) – Path to the MAD-X sequence file.

  • acd_marker (str) – Marker name for the AC dipole element.

  • sequence_name (str) – Name of the sequence in the environment.

  • kinetic_energy (float) – Kinetic energy of the particle in GeV.

  • delta_p (float) – Momentum deviation for the tracked particle.

  • kinetic_energy – Beam kinetic energy in GeV used to set the particle reference.

  • ramp_turns (int) – Number of ramp turns.

  • flattop_turns (int) – Number of flat-top turns.

  • driven_tunes (list[float] | None) – Driven tunes (horizontal, vertical). Defaults to a typical pair.

  • horizontal_excitation (float) – Horizontal excitation scale.

  • vertical_excitation (float) – Vertical excitation scale.

  • bpm_pattern (str) – Regex pattern for BPM locations.

  • json_path (Path | None) – Optional JSON cache path.

  • add_variance_columns (bool) – Whether to add default variance columns to the output.

  • replace_thick_monitors_with_thin (bool) – If True, replace thick monitored elements with thin monitor points before tracking. Thin monitors are left unchanged.

  • state_markers (bool) – If True, insert and monitor {acd_marker}_before and {acd_marker}_after markers bracketing the AC-dipole kicks, so the tracked data carries the true pre-kick and post-kick momenta.

Returns:

Tuple of (tracking_df, twiss_table, monitored_line).

Return type:

tuple[pd.DataFrame, xt.TwissTable, xt.Line]

xtrack_tools.acd.run_ac_dipole_tracking(line, acd_marker, sequence_name, driven_tunes=None, tws=None, ramp_turns=1000, flattop_turns=100, lag=0.0, bpm_pattern='bpm.*[^k]', start_marker=None, deltap=0.0, replace_thick_monitors_with_thin=True, state_markers=False, *, horizontal_excitation, vertical_excitation)[source]

Track one closed-orbit particle with an AC dipole.

Parameters:
  • line (Line) – Base line to copy and modify.

  • acd_marker (str) – Marker name for the AC dipole element.

  • sequence_name (str) – Name of the sequence in the environment.

  • driven_tunes (list[float] | tuple[float, float] | None) – Driven tunes (horizontal, vertical). Defaults to a typical pair.

  • horizontal_excitation (float) – Horizontal excitation scale.

  • vertical_excitation (float) – Vertical excitation scale.

  • tws (TwissTable | None) – Optional Twiss table; computed if not provided.

  • ramp_turns (int) – Number of ramp turns.

  • flattop_turns (int) – Number of flat-top turns.

  • lag (float) – Phase lag for the AC dipoles.

  • bpm_pattern (str) – Regex pattern for BPM locations.

  • start_marker (str | None) – Optional marker name to set as the first element.

  • deltap (float) – Momentum deviation for the tracked particle.

  • replace_thick_monitors_with_thin (bool) – If True, replace thick monitored elements with thin monitor points before tracking. Thin monitors are left unchanged.

  • state_markers (bool) – If True, insert and monitor {acd_marker}_before and {acd_marker}_after markers bracketing the AC-dipole kicks, so the tracked data carries the true pre-kick and post-kick momenta.

Returns:

The monitored line after tracking.

Raises:

ValueError – If the provided Twiss table was not computed at deltap.

Return type:

Line