Compensate radiation energy loss (tapering)

Xtrack Tracker provides a method to compensate the energy loss due to the synchrotron radiation. This is done by configuring the phase of the RF cavities to compensate for the energy loss, and adapting the strength of the magnets to the local momentum of the particle on the closed orbit. This is illustrated in the following example:

import json
import numpy as np
import xtrack as xt

#########################################
# Load line and twiss with no radiation #
#########################################

filename = '../../test_data/clic_dr/line_for_taper.json'

with open(filename, 'r') as f:
    line = xt.Line.from_dict(json.load(f))
tracker = line.build_tracker()

tracker.configure_radiation(model=None)
tw_no_rad = tracker.twiss(method='4d', freeze_longitudinal=True)

###############################################
# Enable radiation and compensate energy loss #
###############################################

tracker.configure_radiation(model='mean')

# - Set cavity lags to compensate energy loss
# - Taper magnet strengths to avoid optics and orbit distortions
tracker.compensate_radiation_energy_loss()

##############################
# Twiss to check the results #
##############################

tw = tracker.twiss(method='6d')

tw.delta # contains the momentum deviation along the ring