Twiss parameters output

A. Petrenko (Novosibirsk, 2019)

In [1]:
import numpy as np
import pandas as pd
import holoviews as hv
import os

hv.extension("bokeh")
In [2]:
%opts Curve Spread [width=700 height=300 show_grid=True \
            default_tools=['box_zoom','pan','wheel_zoom','reset']]

Elegant lattice file:

In [3]:
with open("machine.lte", "r") as f:
    print(f.read())
w0: watch,filename="results/w0.sdds",mode=coord
w1: watch,filename="results/w1.sdds",mode=coord
w2: watch,filename="results/w2.sdds",mode=coord
w3: watch,filename="results/w3.sdds",mode=coord

MA26: MAXAMP, X_MAX=13.0e-3, Y_MAX=13.0e-3, ELLIPTICAL=1

MA20: MAXAMP, X_MAX=10.0e-3, Y_MAX=10.0e-3, ELLIPTICAL=1
MA22: MAXAMP, X_MAX=11.0e-3, Y_MAX=11.0e-3, ELLIPTICAL=1

MA30: MAXAMP, X_MAX=15.0e-3, Y_MAX=15.0e-3, ELLIPTICAL=1

MA18: MAXAMP, X_MAX=9.0e-3, Y_MAX=9.0e-3, ELLIPTICAL=1

D05:   DRIFT, L=0.08
COR1:  KICKER, L=0.04, HKICK=-0.0007, VKICK=-0.003
DCOR1: DRIFT, L=0.08

!D10:  DRIFT, L=0.20
D10:  LINE=(D05,COR1,DCOR1)

Q10:  KQUAD,  L=0.10, K1 = +19.0, N_KICKS=10
DQ10: DRIFT, L=0.05

D20:  DRIFT, L=0.05
Q20:  KQUAD,  L=0.10, K1 = -28.0, N_KICKS=10

D25:   DRIFT, L=0.08
COR2:  KICKER, L=0.04, HKICK=+0.0009, VKICK=+0.0025
DCOR2: DRIFT, L=0.08

!DQ20: DRIFT, L=0.20
DQ20: LINE=(D25,COR2,DCOR2)

RF250: RFCA, L=0.250, VOLT=5.0e6, PHASE=90, FREQ=2856e6, change_p0=1

DN200: DRIFT, L=-0.200

Q22:  KQUAD,  L=0.40, K1 = 6.5, N_KICKS=10
Q23:  KQUAD,  L=0.40, K1 =-7.1, N_KICKS=10

Q24:  KQUAD,  L=0.40, K1 = 8.0, N_KICKS=10
Q25:  KQUAD,  L=0.40, K1 =-8.4, N_KICKS=10

Q26:  KQUAD,  L=0.40, K1 = 8.0, N_KICKS=10
Q27:  KQUAD,  L=0.40, K1 =-8.0, N_KICKS=10


D30:  DRIFT, L=0.60
!Q30:  QUAD,  L=0.10, K1 =+25.8

Q30_10:  KQUAD,  L=0.10, K1 =+27, N_KICKS=10
DQ30_10: DRIFT, L=0.15
Q30_15:  KQUAD,  L=0.10, K1 =-25, N_KICKS=10


CHD10: DRIFT, L=0.11

B10: csbend,angle=-0.04,l=0.17,e1=0,e2=-0.04,&
 nonlinear=1,n_kicks=20,integration_order=4
DB10: DRIFT, L=0.10

B20: csbend,angle=0.04,l=0.17,e1=0.04,e2=0,&
 nonlinear=1,n_kicks=20,integration_order=4
DB20: DRIFT, L=0.10

B30: csbend,angle=0.04,l=0.17,e1=0,e2=0.04,&
 nonlinear=1,n_kicks=20,integration_order=4
DB30: DRIFT, L=0.10

B40: csbend,angle=-0.04,l=0.17,e1=-0.04,e2=0,&
 nonlinear=1,n_kicks=20,integration_order=4
DB40: DRIFT, L=0.11

!CHICANE: DRIFT, L=1.20
CHICANE: LINE=(CHD10,B10,DB10,B20,DB20,B30,DB30,B40,DB40)

Q30_20:  KQUAD,  L=0.10, K1 =-25, N_KICKS=10
DQ30_20: DRIFT, L=0.15
Q30_25:  KQUAD,  L=0.10, K1 =+27, N_KICKS=10

EP_SEP:  LINE=(Q30_10,DQ30_10,Q30_15,CHICANE,Q30_20,DQ30_20,Q30_25)


DQ30: DRIFT, L=0.60



Q32:  QUAD,  L=0.40, K1 =-7.7
Q33:  QUAD,  L=0.40, K1 = 7.7

Q34:  QUAD,  L=0.40, K1 =-7.7
Q35:  QUAD,  L=0.40, K1 = 7.7

Q36:  QUAD,  L=0.40, K1 =-7.7
Q37:  QUAD,  L=0.40, K1 = 7.7

D40:  DRIFT, L=0.25
Q40:  QUAD,  L=0.10, K1 =-25.8
DQ40: DRIFT, L=0.25


Q42:  QUAD,  L=0.40, K1 = 7.7
Q43:  QUAD,  L=0.40, K1 =-7.7

Q44:  QUAD,  L=0.40, K1 = 7.7
Q45:  QUAD,  L=0.40, K1 =-7.7

Q46:  QUAD,  L=0.40, K1 = 7.7
Q47:  QUAD,  L=0.40, K1 =-7.7


D50:  DRIFT, L=0.25
Q50:  QUAD,  L=0.10, K1 =+25.8
DQ50: DRIFT, L=0.25


D60:  DRIFT, L=0.25
Q60:  QUAD,  L=0.10, K1 =-17.5
DQ60: DRIFT, L=0.25

Q63:  QUAD,  L=0.40, K1 =+4.0
Q65:  QUAD,  L=0.40, K1 =-4.0
Q67:  QUAD,  L=0.40, K1 =+4.0

D70:  DRIFT, L=0.25
Q70:  QUAD,  L=0.10, K1 =-14.2
DQ70: DRIFT, L=0.25

Q73:  QUAD,  L=0.40, K1 =+4.0
Q75:  QUAD,  L=0.40, K1 =-4.0
Q77:  QUAD,  L=0.40, K1 =+4.0

D80:  DRIFT, L=0.25
Q80:  QUAD,  L=0.10, K1 =-14.2
DQ80: DRIFT, L=0.25


FODO10: LINE=(&
    MA26,D10,Q10,DQ10,&
    D20,Q20,DQ20,MA20,w1,&
          RF250,DN200,Q22,DN200,&
    RF250,RF250,DN200,Q23,DN200,&
    RF250,RF250,DN200,Q24,DN200,&
    RF250,RF250,DN200,Q25,DN200,&
    RF250,RF250,DN200,Q26,DN200,&
    RF250,RF250,DN200,Q27,DN200,&
    RF250)


RF_WITH_QUADS10: LINE=(MA20,&
          RF250,DN200,Q32,DN200,&
    RF250,RF250,DN200,Q33,DN200,&
    RF250,RF250,DN200,Q34,DN200,&
    RF250,RF250,DN200,Q35,DN200,&
    RF250,RF250,DN200,Q36,DN200,&
    RF250,RF250,DN200,Q37,DN200,&
    RF250)



RF_WITH_QUADS20: LINE=(MA20,&
          RF250,DN200,Q42,DN200,&
    RF250,RF250,DN200,Q43,DN200,&
    RF250,RF250,DN200,Q44,DN200,&
    RF250,RF250,DN200,Q45,DN200,&
    RF250,RF250,DN200,Q46,DN200,&
    RF250,RF250,DN200,Q47,DN200,&
    RF250)


Q34_2:  QUAD,  L=0.40, K1 =-7.7
Q35_2:  QUAD,  L=0.40, K1 = 6.8

Q36_2:  QUAD,  L=0.40, K1 =-5.7
Q37_2:  QUAD,  L=0.40, K1 = 5.4


RF_WITH_QUADS10_2: LINE=(MA20,&
          RF250,DN200,Q32,DN200,&
    RF250,RF250,DN200,Q33,DN200,&
    RF250,RF250,DN200,Q34_2,DN200,&
    RF250,RF250,DN200,Q35_2,DN200,&
    RF250,RF250,DN200,Q36_2,DN200,&
    RF250,RF250,DN200,Q37_2,DN200,&
    RF250)


FODO20: LINE=(&
    RF_WITH_QUADS10,&
    MA22,D40,Q40,DQ40,&
    RF_WITH_QUADS20,&
    MA22,D50,Q50,DQ50)



RF625: RFCA, L=0.625, VOLT="60e6 0.625 3.0 / *", PHASE=90, FREQ=2856e6, change_p0=1
RF875: RFCA, L=0.875, VOLT="60e6 0.875 3.0 / *", PHASE=90, FREQ=2856e6, change_p0=1

RF_WITH_QUADS30: LINE=(MA20,&
    RF625,&
     DN200,Q63,DN200,&
    RF875,&
     DN200,Q65,DN200,&
    RF875,&
     DN200,Q67,DN200,&
    RF625)

RF_WITH_QUADS40: LINE=(MA20,&
    RF625,&
     DN200,Q73,DN200,&
    RF875,&
     DN200,Q75,DN200,&
    RF875,&
     DN200,Q77,DN200,&
    RF625)

FODO30: LINE=(&
    MA18,D70,Q70,DQ70,&
    MA20,RF_WITH_QUADS40)


machine: LINE=(w0,&
      FODO10,w1,&
      MA30,D30,EP_SEP,DQ30,&
    2*FODO20,w2,&
      RF_WITH_QUADS10_2,&
      MA22,D60,Q60,DQ60,&
      MA20,RF_WITH_QUADS30,&
    15*FODO30,&
w3)

In [4]:
with open("twiss.ele", "r") as f:
    print(f.read())
&transmute_elements name=*, type=WATCH, new_type=DRIF &end
&transmute_elements name=*, type=KICKER, new_type=DRIF &end
!&transmute_elements name=*, type=RFCA, new_type=DRIF &end

&divide_elements
    name = *
    maximum_length = 0.05
&end

&run_setup
    lattice = machine.lte
    magnets = results/beamline.mag
    centroid = results/beam.cen
    parameters = results/parameters.sdds
    p_central_mev = 200.0
    use_beamline = machine
    default_order=2
&end

&twiss_output
    filename = results/twiss.twi
    matched = 0
    beta_x = 1.22
    alpha_x = 0.0
    beta_y = 1.22
    alpha_y = 0.0
    eta_x = 0
    eta_y = 0
    etap_x = 0
    etap_y = 0
&end

&floor_coordinates
    filename = results/xyz.sdds
    include_vertices = 0
    vertices_only = 0
    magnet_centers = 0
&end

&run_control &end

&bunched_beam &end


&track &end

Run Elegant

In [5]:
!elegant twiss.ele
Running elegant at Sat May 11 22:45:43 2019

This is elegant 29.1.0, Mar  3 2016, by M. Borland, M. Carla', N. Carmignani, M. Ehrlichman, L. Emery, W. Guo, V. Sajaev, R. Soliday, Y.-P. Sun, C.-X. Wang, Y. Wang, Y. Wu, and A. Xiao.
Link date: Mar  3 2016 21:13:54, SVN revision: 22803M
statistics:    ET:     00:00:00 CP:    0.00 BIO:0 DIO:0 PF:0 MEM:0
&transmute_elements
    name = *,
    type = WATCH,
    exclude = {NULL},
    new_type = DRIF,
    disable = 0,
    clear_all = 0,
&end
statistics:    ET:     00:00:00 CP:    0.00 BIO:0 DIO:0 PF:0 MEM:0
&transmute_elements
    name = *,
    type = KICKER,
    exclude = {NULL},
    new_type = DRIF,
    disable = 0,
    clear_all = 0,
&end
statistics:    ET:     00:00:00 CP:    0.00 BIO:0 DIO:0 PF:0 MEM:0
&divide_elements
    name = *,
    type = {NULL},
    exclude = {NULL},
    divisions = 0,
    maximum_length = 5.000000000000000e-02,
    clear = 0,
&end
statistics:    ET:     00:00:00 CP:    0.00 BIO:0 DIO:0 PF:0 MEM:0
&run_setup
    lattice = machine.lte,
    use_beamline = machine,
    rootname = {NULL},
    output = {NULL},
    centroid = results/beam.cen,
    sigma = {NULL},
    final = {NULL},
    acceptance = {NULL},
    losses = {NULL},
    magnets = results/beamline.mag,
    semaphore_file = {NULL},
    parameters = results/parameters.sdds,
    combine_bunch_statistics = 0,
    wrap_around = 1,
    final_pass = 0,
    default_order = 2,
    concat_order = 0,
    print_statistics = 0,
    show_element_timing = 0,
    monitor_memory_usage = 0,
    random_number_seed = 987654321,
    correction_iterations = 1,
    echo_lattice = 0,
    p_central = 0.000000000000000e+00,
    p_central_mev = 2.000000000000000e+02,
    always_change_p0 = 0,
    load_balancing_on = 0,
    random_sequence_No = 1,
    expand_for = {NULL},
    tracking_updates = 1,
    search_path = {NULL},
    element_divisions = 0,
&end
Seeding random number generators
computed value for RF625.VOLT is 1.250000000000000e+07
computed value for RF875.VOLT is 1.750000000000000e+07
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
warning(1): element DN200 has negative length = -2.000000e-01
Further negative length warnings will be suppressed.
length of beamline MACHINE per pass: 8.179999999999922e+01 m
statistics:    ET:     00:00:00 CP:    0.05 BIO:0 DIO:0 PF:0 MEM:0
&twiss_output
    filename = results/twiss.twi,
    matched = 0,
    output_at_each_step = 0,
    output_before_tune_correction = 0,
    final_values_only = 0,
    statistics = 0,
    radiation_integrals = 0,
    beta_x = 1.220000000000000e+00,
    alpha_x = 0.000000000000000e+00,
    eta_x = 0.000000000000000e+00,
    etap_x = 0.000000000000000e+00,
    beta_y = 1.220000000000000e+00,
    alpha_y = 0.000000000000000e+00,
    eta_y = 0.000000000000000e+00,
    etap_y = 0.000000000000000e+00,
    reference_file = {NULL},
    reference_element = {NULL},
    reference_element_occurrence = 0,
    reflect_reference_values = 0,
    concat_order = 3,
    higher_order_chromaticity = 0,
    higher_order_chromaticity_points = 5,
    higher_order_chromaticity_range = 4.000000000000000e-04,
    quick_higher_order_chromaticity = 0,
    chromatic_tune_spread_half_range = 0.000000000000000e+00,
    cavities_are_drifts_if_matched = 1,
    compute_driving_terms = 0,
    leading_order_driving_terms_only = 0,
    s_dependent_driving_terms_file = {NULL},
    local_dispersion = 1,
    n_periods = 1,
&end
final Twiss parameters (chromaticity valid for fully second-order calculation only!):
         beta          alpha           nu           eta          eta'       dnu/d(dp/p)   dbeta/(dp/p)     accept.
          m                          1/2pi           m                         1/2pi            m          mm-mrad
--------------------------------------------------------------------------------------------------------------------
  x:  1.177900e+00  1.204226e+00  1.094729e+01  8.439624e-19 -5.383236e-19 -1.646827e+00  3.398650e+00  2.764219e+01
  y:  2.237881e+00 -1.814342e+00  1.078300e+01  0.000000e+00  0.000000e+00 -1.864300e+00 -2.211666e+00  2.387110e+01
x acceptance limited to 2.764219e-05 by DN200 ending at 3.077500e+01 m
y acceptance limited to 2.387110e-05 by Q70 ending at 3.170000e+01 m
statistics:    ET:     00:00:01 CP:    0.76 BIO:0 DIO:0 PF:0 MEM:0
&floor_coordinates
    filename = results/xyz.sdds,
    X0 = 0.000000000000000e+00,
    Y0 = 0.000000000000000e+00,
    Z0 = 0.000000000000000e+00,
    theta0 = 0.000000000000000e+00,
    phi0 = 0.000000000000000e+00,
    psi0 = 0.000000000000000e+00,
    include_vertices = 0,
    vertices_only = 0,
    magnet_centers = 0,
    store_vertices = 0,
&end
statistics:    ET:     00:00:01 CP:    0.76 BIO:0 DIO:0 PF:0 MEM:0
&run_control
    n_steps = 1,
    bunch_frequency = 0.000000000000000e+00,
    n_indices = 0,
    n_passes = 1,
    n_passes_fiducial = 0,
    reset_rf_for_each_step = 1,
    first_is_fiducial = 0,
    restrict_fiducialization = 0,
    reset_scattering_seed = 0,
&end
statistics:    ET:     00:00:01 CP:    0.76 BIO:0 DIO:0 PF:0 MEM:0
&bunched_beam
    bunch = {NULL},
    n_particles_per_bunch = 1,
    time_start = 0.000000000000000e+00,
    matched_to_cell = {NULL},
    emit_x = 0.000000000000000e+00,
    emit_nx = 0.000000000000000e+00,
    beta_x = 1.000000000000000e+00,
    alpha_x = 0.000000000000000e+00,
    eta_x = 0.000000000000000e+00,
    etap_x = 0.000000000000000e+00,
    emit_y = 0.000000000000000e+00,
    emit_ny = 0.000000000000000e+00,
    beta_y = 1.000000000000000e+00,
    alpha_y = 0.000000000000000e+00,
    eta_y = 0.000000000000000e+00,
    etap_y = 0.000000000000000e+00,
    use_twiss_command_values = 0,
    Po = 3.913901524593803e+02,
    sigma_dp = 0.000000000000000e+00,
    sigma_s = 0.000000000000000e+00,
    dp_s_coupling = 0.000000000000000e+00,
    emit_z = 0.000000000000000e+00,
    beta_z = 0.000000000000000e+00,
    alpha_z = 0.000000000000000e+00,
    momentum_chirp = 0.000000000000000e+00,
    one_random_bunch = 1,
    save_initial_coordinates = 1,
    limit_invariants = 0,
    symmetrize = 0,
    halton_sequence[0] = 0, 0, 0,
    halton_radix[0] = 0, 0, 0, 0, 0, 0,
    optimized_halton = 0,
    randomize_order[0] = 0, 0, 0,
    limit_in_4d = 0,
    enforce_rms_values[0] = 0, 0, 0,
    distribution_cutoff[0] = 2.000000000000000e+00, 2.000000000000000e+00, 2.000000000000000e+00,
    distribution_type[0] = gaussian, gaussian, gaussian,
    centroid[0] = 0.000000000000000e+00, 0.000000000000000e+00, 0.000000000000000e+00, 0.000000000000000e+00, 
        0.000000000000000e+00, 0.000000000000000e+00,
    first_is_fiducial = 0,
&end
statistics:    ET:     00:00:01 CP:    0.77 BIO:0 DIO:0 PF:0 MEM:0
&track
    center_on_orbit = 0,
    center_momentum_also = 1,
    offset_by_orbit = 0,
    offset_momentum_also = 1,
    soft_failure = 1,
    use_linear_chromatic_matrix = 0,
    longitudinal_ring_only = 0,
    ibs_only = 0,
    stop_tracking_particle_limit = -1,
&end
tracking step 1
generating bunch 1.0
tracking 1 particles
11 May 19 22:45:44: This step establishes energy profile vs s (fiducial beam).
11 May 19 22:45:44: Rf phases/references reset.
1 particles transmitted, total effort of 1 particle-turns
1056 multipole kicks done

Dumping centroid data...done.
Post-tracking output completed.
Tracking step completed   ET:     00:00:01 CP:    0.79 BIO:0 DIO:0 PF:0 MEM:0


Finished tracking.
End of input data encountered.
statistics:    ET:     00:00:01 CP:    0.80 BIO:0 DIO:0 PF:0 MEM:0
=====================================================================================
Thanks for using elegant.  Please cite the following reference in your publications:
  M. Borland, "elegant: A Flexible SDDS-Compliant Code for Accelerator Simulation,"
  Advanced Photon Source LS-287, September 2000.
If you use a modified version, please indicate this in all publications.
=====================================================================================
In [6]:
os.listdir("results")
Out[6]:
['beam.cen',
 'beamline.mag',
 'image.png',
 'parameters.sdds',
 'track.cen',
 'track.sig',
 'twiss.twi',
 'w0.sdds',
 'w1.sdds',
 'w2.sdds',
 'w3.sdds',
 'xyz.sdds']

Reading beamline.mag

In [7]:
out = !sdds2stream results/beamline.mag -col=ElementName,s,Profile -pipe=out
In [8]:
out[:3]
Out[8]:
['_BEGIN_ 0.000000000000000e+00 0.000000000000000e+00',
 'W0 0.000000000000000e+00 0.000000000000000e+00',
 'W0 0.000000000000000e+00 0.000000000000000e+00']
In [9]:
print("\n".join(out[:3]))
_BEGIN_ 0.000000000000000e+00 0.000000000000000e+00
W0 0.000000000000000e+00 0.000000000000000e+00
W0 0.000000000000000e+00 0.000000000000000e+00
In [10]:
from io import StringIO
In [11]:
DATA = StringIO("\n".join(out))
In [12]:
df = pd.read_csv(DATA, names=['ElementName', 's', 'Profile'], delim_whitespace=True)
In [13]:
df.head(3)
Out[13]:
ElementName s Profile
0 _BEGIN_ 0.0 0.0
1 W0 0.0 0.0
2 W0 0.0 0.0
In [14]:
df.tail(3)
Out[14]:
ElementName s Profile
18856 RF625 81.8 -1.224647e-16
18857 W3 81.8 0.000000e+00
18858 W3 81.8 0.000000e+00
In [15]:
dim_s = hv.Dimension('s', unit='m', label="s") # range=(-80,0))
In [16]:
#hv.help(hv.Curve)
In [17]:
from bokeh.models import HoverTool
#hover = HoverTool(tooltips=[("Name", "@ElementName")])
hover = HoverTool(tooltips="@ElementName")

%opts Curve.mag [height=70 show_frame=False show_title=False \
                 xaxis=None yaxis=None tools=['xbox_zoom, xpan', hover]] (color='black', alpha=0.3)

mag = hv.Curve(df, kdims=dim_s, vdims=['Profile', 'ElementName'], group='mag')
mag
Out[17]:

Reading Twiss parameters file

In [18]:
#!sddsquery results/twiss.twi
In [19]:
out = !sdds2stream results/twiss.twi \
    -col=ElementName,s,betax,betay,alphax,alphay,etax,etay,pCentral0,xAperture,yAperture -pipe=out
DATA = StringIO("\n".join(out))
df = pd.read_csv(DATA, names=['ElementName','s','betax','betay','alphax','alphay',
                              'etax','etay','p','xAperture','yAperture'],
                   delim_whitespace=True)
In [20]:
df.tail(3)
Out[20]:
ElementName s betax betay alphax alphay etax etay p xAperture yAperture
2571 RF625 81.751923 1.297717 2.066498 1.304263 -1.722110 8.698515e-19 0.0 2972.684585 0.01 0.01
2572 RF625 81.800000 1.177900 2.237881 1.204226 -1.814342 8.439624e-19 0.0 2974.566268 0.01 0.01
2573 W3 81.800000 1.177900 2.237881 1.204226 -1.814342 8.439624e-19 0.0 2974.566268 0.01 0.01
In [21]:
mc = 0.511 # MeV/c
In [22]:
df['p'] = mc*df['p'] # MeV/c
df['xAperture'] = 1e3*df['xAperture'] # mm
df['yAperture'] = 1e3*df['yAperture'] # mm
In [23]:
%opts Curve.fx (color='red', alpha=0.7, line_width=3)
%opts Curve.fy (color='blue', alpha=0.7, line_width=3)
dim_p    = hv.Dimension('p', unit='MeV/c', range=(0,None))
dim_beta = hv.Dimension('beta', unit='m', label="β", range=(0,None))

s_p    = hv.Curve((df.s, df.p), kdims=dim_s, vdims=dim_p)
beta_x = hv.Curve((df.s, df.betax), label='βx', kdims=dim_s, vdims=dim_beta, group='fx')
beta_y = hv.Curve((df.s, df.betay), label='βy', kdims=dim_s, vdims=dim_beta, group='fy')
In [24]:
(s_p + beta_x*beta_y + mag).cols(1)
Out[24]:
In [25]:
#Dx = hv.Curve((df.s, df.etax), label='Dx', kdims='s (m)', vdims='D (m)', group='fx')
#Dy = hv.Curve((df.s, df.etay), label='Dy', group='fy')

#(Dx*Dy + mag).cols(1)
In [26]:
e_nx = 5300.0 # normalized emittance [mm*mrad]
e_ny = 5300.0 # normalized emittance [mm*mrad]

#e_x = e_nx * 1e-6 / gamma # geometric emittance [m]

df['e_x'] = e_nx * 1e-6 / (df['p']/mc) # geometric emittance [m]
df['e_y'] = e_ny * 1e-6 / (df['p']/mc) # geometric emittance [m]
df['dp/p'] = 0
In [27]:
df['sigma_x'] = 1e3*np.sqrt(df['betax']*df['e_x'] + df['etax']*df['etax']*df['dp/p']*df['dp/p']) # mm
df['sigma_y'] = 1e3*np.sqrt(df['betay']*df['e_y'] + df['etay']*df['etay']*df['dp/p']*df['dp/p']) # mm
df.tail(3)
Out[27]:
ElementName s betax betay alphax alphay etax etay p xAperture yAperture e_x e_y dp/p sigma_x sigma_y
2571 RF625 81.751923 1.297717 2.066498 1.304263 -1.722110 8.698515e-19 0.0 1519.041823 10.0 10.0 0.000002 0.000002 0 1.521085 1.919468
2572 RF625 81.800000 1.177900 2.237881 1.204226 -1.814342 8.439624e-19 0.0 1520.003363 10.0 10.0 0.000002 0.000002 0 1.448706 1.996846
2573 W3 81.800000 1.177900 2.237881 1.204226 -1.814342 8.439624e-19 0.0 1520.003363 10.0 10.0 0.000002 0.000002 0 1.448706 1.996846
In [28]:
%opts Curve.Aper (color='gray', alpha=0.5, line_width=3)

dim_sigma = hv.Dimension('sigma', unit='mm', label="2σ", range=(0,None))
dim_aper  = hv.Dimension('aper', unit='mm', label="Aperture", range=(0,None))

Ax =     hv.Curve((df.s,  df.xAperture), label='Aperture', kdims=dim_s, vdims=dim_sigma, group='Aper')
Ax_pos = Ax
Ax_neg = hv.Curve((df.s, -df.xAperture), label='Aperture', kdims=dim_s, vdims=dim_sigma, group='Aper')

Sx = hv.Curve((df.s, 2*df.sigma_x), label='2σx', kdims=dim_s, vdims=dim_sigma, group='fx')
Sy = hv.Curve((df.s, 2*df.sigma_y), label='2σy', kdims=dim_s, vdims=dim_sigma, group='fy')
In [29]:
(Sx*Sy*Ax + mag).cols(1)
Out[29]:

Beam centroid:

In [30]:
!sddsquery results/beam.cen
file results/beam.cen is in SDDS protocol version 1
description: centroid output--input: twiss.ele  lattice: machine.lte
contents: centroid output
data is little-endian binary

13 columns of data:
NAME            UNITS           SYMBOL          FORMAT          TYPE    FIELD  DESCRIPTION
                                                                        LENGTH
s               m               NULL            NULL            double  0       Distance
ElementName     NULL            NULL            %10s            string  0       Element name
ElementOccurence NULL            NULL            %6ld            long    0       Occurence of element
ElementType     NULL            NULL            %10s            string  0       Element-type name
Cx              m               <x>             NULL            double  0       x centroid
Cxp             NULL            <x'>            NULL            double  0       x' centroid
Cy              m               <y>             NULL            double  0       y centroid
Cyp             NULL            <y'>            NULL            double  0       y' centroid
Cs              m               <s>             NULL            double  0       mean distance traveled
Cdelta          NULL            <$gd$r>         NULL            double  0       delta centroid
Particles       NULL            NULL            NULL            long    0       Number of particles
pCentral        m$be$nc         p$bcen$n        NULL            double  0       Reference beta*gamma
Charge          C               NULL            NULL            double  0       Charge in the beam

2 parameters:
NAME                UNITS               SYMBOL              TYPE                DESCRIPTION
Step                NULL                NULL                long                Simulation step
SVNVersion          NULL                NULL                string              SVN version number
In [31]:
out = !sdds2stream results/beam.cen -col=ElementName,s,Cx,Cy,pCentral -pipe=out
DATA = StringIO("\n".join(out))
df_cen = pd.read_csv(DATA, names=['ElementName','s','Cx','Cy','p'],
                   delim_whitespace=True)
In [32]:
df_cen.tail(3)
Out[32]:
ElementName s Cx Cy p
2571 RF625 81.751923 -1.821171e-18 0.0 2972.684585
2572 RF625 81.800000 -1.446227e-18 0.0 2974.566268
2573 W3 81.800000 -1.446227e-18 0.0 2974.566268
In [33]:
df_cen['Cx'] = df_cen['Cx']*1e3 # m -> mm
df_cen['Cy'] = df_cen['Cy']*1e3 # m -> mm
df_cen['p']  = df_cen['p']*0.511 # gamma*beta -> MeV/c
In [34]:
dim_x = hv.Dimension('x', unit='mm', label="x", range=(-16,+16))
dim_y = hv.Dimension('y', unit='mm', label="y", range=(-16,+16))
dim_p = hv.Dimension('p', unit='MeV/c', label="p", range=(0,None))
In [35]:
s_p = hv.Curve((df_cen.s, df_cen.p), kdims=dim_s, vdims=dim_p)

Cx  = hv.Spread((df_cen.s, df_cen.Cx, 2*df.sigma_x), label='x', \
               kdims=dim_s, vdims=[dim_x,dim_aper])
Cy  = hv.Spread((df_cen.s, df_cen.Cy, 2*df.sigma_y), label='y', \
               kdims=dim_s, vdims=[dim_y,dim_aper])
In [36]:
(s_p + Ax_pos*Ax_neg*Cx*Cy + mag).cols(1)
Out[36]:

Reading xyz.sdds file

In [37]:
out = !sdds2stream results/xyz.sdds \
    -col=ElementName,s,X,Y,Z -pipe=out
DATA = StringIO("\n".join(out))
df_xyz = pd.read_csv(DATA, names=['ElementName','s','X','Y','Z'],
                   delim_whitespace=True)
In [38]:
df_xyz.tail(3)
Out[38]:
ElementName s X Y Z
2571 RF625 81.751923 1.390696e-16 0.0 81.751582
2572 RF625 81.800000 1.391530e-16 0.0 81.799659
2573 W3 81.800000 1.391530e-16 0.0 81.799659
In [39]:
df_cen['Cx'] = df_cen['Cx'] + 1e3*df_xyz['X'] # mm

df['xAperture_neg'] = -df['xAperture'] + 1e3*df_xyz['X'] # mm
df['xAperture'] = df['xAperture'] + 1e3*df_xyz['X'] # mm
In [40]:
dim_x = hv.Dimension('x', unit='mm', label="x", range=(-16,+27))
In [41]:
Cx  = hv.Spread((df_cen.s, df_cen.Cx, 2*df.sigma_x), label='x', \
               kdims=dim_s, vdims=[dim_x,dim_aper])

Ax =     hv.Curve((df.s,  df.xAperture), label='x Aperture', kdims=dim_s, vdims=dim_sigma, group='Aper')
Ax_pos = Ax
Ax_neg = hv.Curve((df.s,  df.xAperture_neg), label='x Aperture', kdims=dim_s, vdims=dim_sigma, group='Aper')
In [42]:
(s_p + Ax_pos*Ax_neg*Cx*Cy + mag).cols(1)
Out[42]:

Misc tests