
! *** OPTICS=AD_ACCEL_HE-28APR21 ***

! ------------------------------------------------------------------------------
! constants and global parameters
! ------------------------------------------------------------------------------

! constants

  Cb      : CONSTANT=1.0E10/CLIGHT !energy to magnetic rigidity
  GeV2MeV : CONSTANT=1000.0        !GeV to MeV
  in2m    : CONSTANT=0.0254        !inches to meters
  mc2     : CONSTANT=510.99906E-6  !e- rest mass [GeV]

! SURVEY stuff

  injdeg  := -35.0        !injector bend angle w.r.t. linac [degrees]
  ZOFFINJ :=   0.012100   !moves entire injector in main-linac z-direction by this amount (+12.100 mm Nov. 17, 2004)
  XOFF    := -25.610*in2m !x-offset of bypass line (old PEP-II 9-GeV) w.r.t. old linac axis (<0 is south)
  YOFF    :=  25.570*in2m !y-offset of bypass line (old PEP-II 9-GeV) w.r.t. old linac axis(>0 is up)

! initial conditions (exit of L0)

  EMITXN := 1.00E-06 !normalized horizontal emittance (m)
  EMITYN := 1.00E-06 !normalized vertical emittance (m)
  BLENG  := 0.83E-03 !bunch length (m)
  ESPRD  := 2.00E-05 !slice rms energy spread at 135 MeV (1)

! energy profile

  E00  := 0.006 !beam energy after gun (GeV)
  E0i  := 0.064 !beam energy between L0a and L0b sections (GeV)
  Ei   := 0.135 !initial beam energy (GeV) (150->135 MeV on July 9, 2003)
  EBC1 := 0.220 !BC1 energy (GeV)
  EBC2 := 5.000 !BC2 energy (GeV)
  Ef   := 8.000 !final beam energy (GeV)
  Eu   := 8.000 !energy in undulator (GeV)

  Brho00 := Cb*E00
  Brho0i := Cb*E0i
  Brhoi  := Cb*Ei
  Brho1  := Cb*EBC1
  Brho2  := Cb*EBC2
  Brhof  := Cb*Ef
  Brhou  := Cb*Eu

! compression

  R56HTR := 0.0079 !dX= 0.035000 m
  R56BC1 := 0.0455 !dX= 0.247383 m
  R56BC2 := 0.028  !dX= 0.385010 m

! ------------------------------------------------------------------------------
! twiss parameter definitions
! ------------------------------------------------------------------------------

! twiss parameters at L0a-exit:

  TBETX :=  1.410  !twiss beta x (m)  ! back-tracked from measured/matched OTR2 through post Aug. 11, 2008 QA01-QE04 real BDES settings
  TALFX := -2.613  !twiss alpha x
  TBETY :=  6.706  !twiss beta y (m)
  TALFY :=  0.506  !twiss alpha y

! Dummy, fitted twiss parameters at cathode which yield the above twiss parameters at
! L0a-exit from TWISS, COUPLE (for plotting purposes only - assumes only drift between cathode and L0a-exit)

  CBETX :=  15.574222415628    ! consistent with back-tracked from matched OTR2 through post Aug. 11, 2008 QA01-QE04 real BDES
  CALFX :=  -3.081460679784
  CBETY :=   0.39093003939
  CALFY :=   0.551431596242E-2

! Twiss at the beginning of L3 linac

  ENBEGL3 :=  5.0
  BXBEGL3 := 11.063556098154
  AXBEGL3 := -0.94968706938
  BYBEGL3 := 70.645797110343
  AYBEGL3 :=  2.189962742982

! Twiss at the end of L3 linac (L3END)

  ENENDL3 :=  8.0
  BXENDL3 := 33.223271647513
  AXENDL3 :=  1.179788571596
  BYENDL3 := 62.179034958969
  AYENDL3 := -1.656755986924

! initial Twiss at BEGCLTS (see CUSXR.xsif)

! periodic Twiss in HXR dogleg cells (copy from LCLS2sc_master.xsif)

  MBETXH := 48.911502413792
  MALFXH :=  3.141736059434
  MBETYH := 92.803659415654
  MALFYH :=  3.519158552438

! match into HXR LTU emittance diagnostic section

  BXEDh := 46.225914290403
  AXEDh := -1.084608326581
  BYEDh := 46.225914290403
  AYEDh :=  1.084608326581

! matched Twiss at center of QDL12

  MBETXS :=  7.486735820504    ! 6.841330859726
  MALFXS :=  0.990107252178E-4 !-0.28404741292
  MBETYS := 43.429233779422    !47.120432391261
  MALFYS := -0.419297807308E-4 ! 2.555848494222

! for matching ...

  BET11 := 10.090395936353
  BET12 := 2.470673595371
  BET21 := 43.876719659503
  BET22 := 16.019619746515
 !BET31 := 53.481287866029
 !BET32 := 35.468087644847
 !BET33 := 29.55797372867
 !BET34 := 63.601589300188
  BET31 := 61.868125327071
  BET32 := 36.40742728964
  BET33 := 36.353377790534
  BET34 := 61.956709274457
 !BET31 := 69.818359882868  ! for WS28 45 deg/wire
 !BET32 := 37.0062095289
 !BET33 := 42.5680425597
 !BET34 := 60.952049693321

! linac phase advances

  MU_L1  := 75/360
  MU_L2  := 55.500/360
  MUX_L3 := 30.175/360 !July 13, 2008 - set for best WS28 45-deg mux phase advances
  MUY_L3 := 30.130/360 !July 13, 2005 - set for 3*90 deg TCAV3[1] to OTR30 (TCAV3 -> 25-2d)

! ------------------------------------------------------------------------------
! beam definitions
! ------------------------------------------------------------------------------

! input beam definition (at L0a-exit)

  EMITX :=  EMITXN/(E0i/EMASS)
  EMITY :=  EMITYN/(E0i/EMASS)
  TGAMX :=  (1+TALFX*TALFX)/TBETX
  TGAMY :=  (1+TALFY*TALFY)/TBETY
  SIG11 :=  EMITX*TBETX
  SIG21 := -EMITX*TALFX
  SIG22 :=  EMITX*TGAMX
  SIG33 :=  EMITY*TBETY
  SIG43 := -EMITY*TALFY
  SIG44 :=  EMITY*TGAMY
  C21   :=  SIG21/SQRT(SIG11*SIG22)
  C43   :=  SIG43/SQRT(SIG33*SIG44)

! input beam definition (at cathode)

  CGAMX  :=  (1+CALFX*CALFX)/CBETX
  CGAMY  :=  (1+CALFY*CALFY)/CBETY
  SIG11C :=  EMITX*CBETX
  SIG21C := -EMITX*CALFX
  SIG22C :=  EMITX*CGAMX
  SIG33C :=  EMITY*CBETY
  SIG43C := -EMITY*CALFY
  SIG44C :=  EMITY*CGAMY
  C21C   :=  SIG21C/SQRT(SIG11C*SIG22C)
  C43C   :=  SIG43C/SQRT(SIG33C*SIG44C)

! ------------------------------------------------------------------------------
! Database MARKer point definitions
! ------------------------------------------------------------------------------

  DBMARK80 : MARK !(LCLS GUN) RF gun cathode
  DBMARK81 : MARK !(BXG_entr) entrance of BXG
  DBMARK97 : MARK !(GUNSPECT) 6 MeV gun spectrometer dump
  DBMARK82 : MARK !(BX01entr) entrance of BX01
  DBMARK98 : MARK !(135SPECT) 135-MeV spect. dump
  DBMARK83 : MARK !(BX02exit) exit of BX02 ... LCLS injection point
  DBMARK28 : MARK !(QM15exit) exit of QM15 ... just after TD11
  DBMARK29 : MARK !(IV30-9  ) LI30 isolation valve ... start of BSY

! ------------------------------------------------------------------------------
! load lattice definitions
! ------------------------------------------------------------------------------

! LCLS2scH and LCLS1 optics

  CALL, FILENAME="common.xsif"
  CALL, FILENAME="SPRD.xsif"
  CALL, FILENAME="CUSXR.xsif"
  CALL, FILENAME="ALINE.xsif"
  CALL, FILENAME="BYP.xsif"
  CALL, FILENAME="LTU.xsif"
  CALL, FILENAME="UND.xsif"
  CALL, FILENAME="SFT.xsif"
  CALL, FILENAME="HXTES.xsif"
  CALL, FILENAME="LCLS2cu.xsif"

! design L1, L2, and L3 lattices ...

  CALL, FILENAME="LCLS_L1.xsif"
  CALL, FILENAME="LCLS_L2.xsif"
  CALL, FILENAME="LCLS_L3.xsif"

! ... or simplified L1, L2, and L3 lattices (for ELEGANT)

 !CALL, FILENAME="LCLS_L1e.xsif"
 !CALL, FILENAME="LCLS_L2e.xsif"
 !CALL, FILENAME="LCLS_L3e.xsif"

! new BSY area definitions

  CALL, FILENAME="BSYcu.xsif"

! beam paths

 !CU_HXR   : copper linac to e- HXR dump
 !CU_SFTH  : copper linac to e- HXR safety dump
 !CU_HXTES : copper linac to HXR XTES system (photon)
 !CU_HTXI  : copper linac to HXR TXI system (photon)
 !CU_SXR   : copper linac to e- SXR dump
 !CU_ALINE : copper linac to End Station A
 !CU_GSPEC : copper linac to gun spectrometer
 !CU_SPEC  : copper linac to 135 MeV spectrometer

  CU_HXR   : LINE=(GUNL0a,L0aL0b,LCLS2cuH)
  CU_SFTH  : LINE=(GUNL0a,L0aL0b,LCLS2cuHS)
  CU_HXTES : LINE=(GUNL0a,L0aL0b,LCLS2cuHXTES)
  CU_HTXI  : LINE=(GUNL0a,L0aL0b,LCLS2cuHTXI)
  CU_SXR   : LINE=(GUNL0a,L0aL0b,LCLS2cuS)
  CU_ALINE : LINE=(GUNL0a,L0aL0b,LCLS2cuA)
  CU_GSPEC : LINE=(GUNBXG,GSPEC)
  CU_SPEC  : LINE=(GUNL0a,L0aL0b,DL1_1,SPECBL)

! ------------------------------------------------------------------------------
! initial SURVEY coordinates
! ------------------------------------------------------------------------------

! set initial linac survey coordinates
! (NOTE: pitch is not included here for simplicity - for linac coordinates,
!        read in pitched plane of linac)

  XLL := 10.9474                   !X at loadlock start [m]
  ZLL := 2032.0-14.8125+ZOFFINJ    !Z at loadlock start (move injector ~12 mm dnstr. - Nov. 17, 2004, -PE) [m]
  Xi  := XLL+LOADLOCK[L]*SIN(ADL1) !subtract from upbeam side of loadlock to get to cathode [m]
  Zi  := ZLL+LOADLOCK[L]*COS(ADL1) !subtract from upbeam side of loadlock to get to cathode [m]

 !VALUE, ADL1,Xi,Zi

! initial BSY survey coordinates at BSYbeg

  Xf     :=  0           !hor. position is on linac axis, which is zero here [m]
  Yf     :=  0.027987637 !at BSYbeg (~6 m upbeam S100) in undulator coordinates (for LTU engineers)
  Zf     := -5.99493367  !at BSYbeg (~6 m upbeam S100) in undulator coordinates (for LTU engineers)
  THETAf :=  0           !no yaw at S100
  PSIf   :=  0           !no roll at S100
  PHIf   := 2*AVB        !S100 pitch in undulator coordinates (for LTU engineers)

 !VALUE, Xf,Yf,Zf,THETAf,PHIf,PSIf,AVB
  
! linac survey coordinates at BSY1BEG (not used)

 !XBSY1  := -3.309620550E-07
 !ZBSY1  :=  3042.005
 !THBSY1 := -2.000049721E-12

! ------------------------------------------------------------------------------

  RETURN
