! Set up the lattice of 3.6m ring with unlimited apertures
! FINT=1.3571,kqt=80,kqrt=-20
! Set the dipole with edge angle
! Use tracking method to calculate tunes and chromaticity
! 2013-02-05

! Drift spaces
dba : drift, l = 0.0001
xdba: drift, l = "0.0001 3.0e-6 -"

!xd1t: line = (4499*dba)
!xd2t: line = (1799*dba)
!xddt: line = (699*dba)
!xdqq: line = (600*dba)
!xd1p: line = (1999*dba)
!xd12: line = (2500*dba)
!
!xd1 : line = (xd1t,xdba)
!xd2 : line = (xd2t,xdba)
!xddq: line = (xddt,xdba)
!xd11: line = (xd1p,xdba)

xd1 : drift, l = "0.45 3.0e-6 -"
xd2: drift, l = "0.18 3.0e-6 -"
xddq: drift, l = "0.07 3.0e-6 -"
xdqq: drift, l = 0.06
xd11: drift, l = "0.20 3.0e-6 -"
xd12: drift, l = 0.25

! Quadrupoles
!qtt : kquad, l = 0.0001, k1 = 83.0, n_kicks = 24
!qtrt: kquad, l = 0.0001, k1 = -30.0, n_kicks = 24
!
!qt : line = (1000*qtt)
!qtr : line = (500*qtrt)

qt : kquad, l = 0.1, k1 = 83.0, n_kicks = 24,synch_rad = 1,&
ISR = 1, ISR1PART = 0
qtr : kquad, l = 0.05, k1 = -30.0, n_kicks = 24,synch_rad = 1,&
ISR = 1, ISR1PART = 0

! Dipoles
bd1 : csbend, l = 0.22, angle = -1.5707963268, e1 = -0.523598775,&
e2 = -0.523598775, hgap = 0.0127, fint = 1.3571, n_kicks = 24, & 
synch_rad = 1, ISR = 1, ISR1PART = 0

! Quadrupole component of the dipole magnet
qdip: kquad, l = 1.0e-6, k1 = 0.0, n_kicks = 24

! Sextupoles
!**** Sextupole component of the dipole magnet ****!
sdi1: ksext, l = 1.0e-6, k2 = -52968328.0, n_kicks = 24,synch_rad=1
sdi2: ksext, l = 1.0e-6, k2 = 5.63602438e7, n_kicks = 24,synch_rad=1
!**** Sextupoles in the straight sections ****!
s1  : ksext, l = 0.05, k2 = -3.063043e3, n_kicks = 24

! Apertures
!  Injection part aperture, horizontal aperture is large
ijqap: maxamp, x_max = 50.0, y_max = 50.00, elliptical = 0
ijdap: maxamp, x_max = 50.0, y_max = 50.0, elliptical = 0
!  Quadrupole aperture (radius) is 5m, round
qap : maxamp, x_max = 50.00, y_max = 50.00, elliptical = 1
!  Drift aperture (radius) is 20mm, round
dap : maxamp, x_max = 50.00, y_max = 50.00, elliptical = 1
!  Dipole aperture is 80mm by 20mm, rectangular
diap: maxamp, x_max = 50.0, y_max = 50.0, elliptical = 0

! RF cavity
rf : rfca, freq = "c_mks 49.9973887 mev / beta.p * 3.6 / 6 *", volt = 15e3, phase ="3.947518269e-03 15 / dasin"

! Scan the energy of the beam
mal : malign,on_pass=0, force_modify_matrix=1

! Watch
w1: watch, filename = "%s-%03ld.w1",mode="centroid"

! Include Synchrotron Motion
! sr: sreffects, qexcitation=0
sr: mark

! Sequence
x1 : line = (dap,xd12,xd11,diap,w1,sdi2,w1,qdip,w1,sdi1,w1,bd1,w1,sdi1,w1,qdip,sdi2,dap,xddq,qap,qtr,dap,xdqq)
x2 : line = (qap,qt,dap,xdqq,s1,xddq,diap,sdi2,qdip,sdi1,bd1,sdi1,qdip,sdi2,dap,xd1)
x3 : line = (xd1,diap,sdi2,qdip,sdi1,bd1,sdi1,qdip,sdi2,dap,xddq,qap,qtr,dap,xdqq)
x4 : line = (qap,qt,dap,xdqq,s1,xddq,ijdap,sdi2,qdip,sdi1,bd1,sdi1,qdip,sdi2,ijqap,xd1)
!ring : line = (x1,x2,rf,x3,x4)
!ring : line = (mal,x1,x2,rf,x3,x4)
ring : line = (w1,x1,x2,x3,x4,rf,sr)
