Kicker

xtrack_tools.kicker.plot_kicker_tracking(df, tws, s_kicker, kick_turn, save_path='kicker_test.png')[source]

Plot x and y at each BPM as one continuous unrolled line across all turns.

The x-axis is the unrolled longitudinal position: BPM s-coordinate plus (turn - 1) * circumference. Before the kick the particle rides the closed orbit; after the kick it oscillates. The kick event is shown as a red dashed vertical line at the kicker s-position on the turn it fires.

Parameters:
  • df (pd.DataFrame) – Tracking DataFrame with columns name, turn, x, y.

  • tws (xt.TwissTable) – Twiss table providing element s-positions, circumference, and closed orbit.

  • s_kicker (float) – s-position of the kicker [m].

  • kick_turn (int) – Turn index (0-based, matching xtrack convention) on which the kick fires, used to position the red vertical line.

  • save_path (str | None) – File path to save the figure, or None to skip saving.

Return type:

None

xtrack_tools.kicker.run_kicker_track(sequence_file, nturns, tkicker_name, kick_strength, plane, kick_turn=0, exciter_name='single_turn_kicker', delta_p=0.0, bpm_pattern='(?i)bpm.*', kinetic_energy=6800, seq_name=None, json_path=None, add_variance_columns=False, replace_thick_monitors_with_thin=True)[source]

Track a single particle with a single-turn kicker placed at a named tkicker.

An xt.Exciter is inserted at the s-position of tkicker_name and fires a single kick on kick_turn (0-based xtrack turn counter). The particle rides the closed orbit for all turns before kick_turn and then oscillates freely afterwards. The line is not cycled; tracking starts from the natural first element of the sequence.

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

  • nturns (int) – Total number of turns to track.

  • tkicker_name (str) – Name of the tkicker element in the sequence that sets the insertion point for the exciter.

  • kick_strength (float) – Kick strength in rad (scaled by the active plane).

  • plane (KickPlane) – Kick plane — "horizontal", "vertical", or "diagonal".

  • kick_turn (int) – 0-based turn on which the exciter fires (default 0 = first turn). Set this to e.g. 5 to see 5 turns on the closed orbit before the kick.

  • exciter_name (str) – Name given to the inserted xt.Exciter element.

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

  • bpm_pattern (str) – Regex pattern selecting monitor elements.

  • kinetic_energy (float) – Beam kinetic energy in GeV.

  • seq_name (str | None) – Sequence name inside the environment; defaults to the file stem.

  • json_path (Path | None) – Optional path for the cached JSON environment.

  • 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 marker points before tracking.

Returns:

Tuple of (tracking_df, twiss_table, baseline_line, s_kicker, kick_turn). The tkicker is collapsed to a zero-length marker at its centre before twissing, so its Twiss row (and s_kicker) sit exactly where the exciter fires.

Raises:

ValueError – If tkicker_name is not found in the line.

Return type:

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

xtrack_tools.kicker.run_free_track_from_kick(baseline_line, tws, kick_df, ref_bpm, s_kicker, kick_turn, bpm_pattern='(?i)bpm.*', replace_thick_monitors_with_thin=True)[source]

Re-track freely from the particle state captured right after the kick.

Extracts x, px, y, py at the first BPM downstream of the kicker on the turn immediately after the kick fires (DataFrame turn kick_turn + 2), cycles the baseline line to start at that BPM, and tracks for the remaining turns without any kicker element.

Comparing this output with the post-kick portion of the original kicker-track DataFrame verifies whether the exciter fired exactly once: if the trajectories are identical the kick did not repeat; if they diverge it fired again.

Parameters:
  • baseline_line (xt.Line) – The unmodified line (no exciter) used for free tracking.

  • tws (xt.TwissTable) – Twiss table of the baseline line.

  • kick_df (pd.DataFrame) – Tracking DataFrame returned by run_kicker_track.

  • s_kicker (float) – s-position of the kicker [m].

  • kick_turn (int) – 0-based xtrack turn on which the kick fired.

  • bpm_pattern (str) – Regex pattern selecting monitor elements.

  • replace_thick_monitors_with_thin (bool) – Passed through to run_tracking.

  • ref_bpm (str)

Returns:

Tracking DataFrame for the free-tracking segment, with turn column renumbered starting from 1.

Return type:

pd.DataFrame