
! *** OPTICS=AD_ACCEL_HE-07FEB22 ***

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

! constants

  Cb    : CONSTANT=1.0E10/CLIGHT   !kG-m/GeV
  mc2   : CONSTANT=0.51099906E-3   !GeV
  QELEC : CONSTANT=1.602176462E-19 !C
  in2m  : CONSTANT=0.0254          !m/inch

! kinetic energy profile

  E0    := MC2+0.750E-3      !NGLS/APEX gun energy (GeV) ... 750 kV gun
  Ei    := 0.1               !energy at end of L0B (GeV)
  E1    := 0.23              !BC1 energy (GeV)
  E2    := 1.675             !BC2 energy (GeV)
  E3    := 4.25038515114     !L3 final energy (GeV) ... not defined
  Ef    := 8.0               !final beam energy (GeV)
  Eu    := 8.0               !energy in undulator (GeV)
  Emax  := 10.0              !maximum beam energy
  E0LEI := 2.790915293401E-3 !LEI gun energy (GeV)

  Brho0 := Cb*E0
  Brhoi := Cb*Ei
  Brho1 := Cb*E1
  Brho2 := Cb*E2
  Brho3 := Cb*E3
  Brhof := Cb*Ef
  Brhou := Cb*Eu

! compression

  R56HTR := 0.0035 !DXmax = 75 cm
  R56BC1 := 0.05285
  R56BC2 := 0.03955

  R56CCDLU := 9.99E-5
  R56CCDLD := 9.99E-5

! ==============================================================================
! input beam definitions: C. Mayes (100 pC)
! ------------------------------------------------------------------------------

! Twiss at gun

  BX0 := 54.70910663424
  AX0 := 24.927276694193
  BY0 := 54.64124177612
  AY0 := 24.896728669354

! Twiss at S= 15.0 m (ASTRA MARKER)

  BXa := 13.325594260686
  AXa := -2.125811087318
  BYa := 13.315541277702
  AYa := -2.123153832086

! Twiss at BEAM0 MARKER (specified)

  BXi :=  9.3480
  AXi := -1.6946
  BYi :=  9.3429
  AYi := -1.6925

! Twiss at LEI BEAM0

  BXiLEI := 21.8
  AXiLEI := -1.0
  BYiLEI := 21.8
  AYiLEI := -1.0

! Twiss at LEI gun

  BX0LEI := 6.929203022559 !1.443432464726
  AX0LEI := 0.180320556147 !0.631436714755
  BY0LEI := 6.929203022559 !1.443432464726
  AY0LEI := 0.180320556147 !0.631436714755

! Twiss at entrance to LEI dogleg

  BXDLI := 0.640445839243
  AXDLI := 0.796391866711
  BYDLI := 4.37274076366
  AYDLI := 0.84368881084

! max beta u/s of WS0H04

  Bmax := 50

! beta at WS0H04 waist

  B0H04w := 5.0

! "treaty" Twiss at center of laser heater undulator

  BXlh := 10.0
  AXlh := 0
  BYlh := 10.0
  AYlh := 0

! beam parameters

  QBNCH  := 100.0E-12 !C
  EMITXn := 0.15E-06  !m
  EMITYn := 0.15E-06  !m
  sig_z  := 1.0E-03   !m
  sig_dp := 1.0E-04   !1

! ==============================================================================
! input beam definition (at BEAM0)
! ------------------------------------------------------------------------------

  EMITX := EMITXn/(Ei/EMASS)
  EMITY := EMITYn/(Ei/EMASS)

  GXi   := (1+AXi*AXi)/BXi
  SIG11 := EMITX*BXi
  SIG21 := -EMITX*AXi
  SIG22 := EMITX*GXi
  C21   := SIG21/SQRT(SIG11*SIG22)
  GYi   := (1+AYi*AYi)/BYi
  SIG33 := EMITY*BYi
  SIG43 := -EMITY*AYi
  SIG44 := EMITY*GYi
  C43   := SIG43/SQRT(SIG33*SIG44)

 !SIGX = SQRT(SIG11)
 !SIGPX= SQRT(SIG22)
 !R21  = C21
 !SIGY = SQRT(SIG33)
 !SIGPY= SQRT(SIG44)
 !R43  = C43
 !SIGT = sig_z
 !SIGPT= sig_dp

! ==============================================================================
! survey (Z values are w.r.t. start of LI01 where Z=0)
! ------------------------------------------------------------------------------

  Xgun  :=    0.28     !beam axis (w.r.t. original linac axis)
  Ygun  :=   -0.99     !beam axis (w.r.t. original linac axis)
  Zgun  :=  -10.044667 !10.0 m d/s of location of CID gun
  Z0beg :=   -7.992090 !start of L0 (12.0 m d/s of location of CID gun)
  Zi    :=    3.914190 !BEAM0 point (~3.9 m into LI01)
  Za    :=   Zgun+15.0 !ASTRA treaty point (~4.8 m into LI01)
  Z0end :=    8.130200 !end of L0 (~8.0 m into LI01)
  Zhtr  :=   18.202600 !start of laser heater chicane (~18.2 m into LI01)
  Zdg0  :=   32.183970 !start of DIAG0 (~32.2 m into LI01)
  Z1beg :=   73.383640 !start of L1 (~73.4 m into LI01)
  Z1loc :=  104.194330 !center of CAVC011 (should be 104.0 m)
  Z1end :=  121.344620 !end of L1 (~19.7 m into LI02)
  Z2beg :=  174.885202 !start of L2 (~73.3 m into LI02)
  Z2end :=  331.562942 !end of L2 (~26.8 m into LI04)
  Z3beg :=  385.847300 !start of L3 (~81.0 m into LI04)
  Z3end :=  555.330530 !end of L3 (~47.3 m into LI06)
  Z4beg :=  561.805020 !start of L4 (~53.8 m into LI06)
  Z4end :=  901.988060 !end of L4 (~89.2 m into LI09)
  Zdog0 :=  954.347000 !sector 10 adit "crotch" (~39.9 m into LI10)
  Zdog  :=  956.847000 !entrance first dogleg bend, BRB1 (~42.4 m into LI10)
  Xbyp  :=   -0.650494 !QBP13 X is |Xbyp| to the south of linac axis
  Ybyp  :=    0.649478 !QBP13 Y is Ybyp above linac axis
  Zbyp  := 1254.531303 !QBP13 centerline (~35.3 m into LI13)

  Xgun2    :=   6.28          !LEI beam axis (w.r.t. original linac axis)
  Ygun2    :=  -0.99          !LEI beam axis (w.r.t. original linac axis)
  Zgun2    := -23.94397537046 !LEI cathode
  Z0LEIbeg :=  -18.734225     !start of L0LEI
  ZiLEI    :=   -6.827945     !BEAM0LEI point

! ==============================================================================
! twiss parameter definitions (for matching, etc.)
! ------------------------------------------------------------------------------

! matched Twiss for coasting linac FODOs

  BXCMfodo1 := 47.734300019352 !L1: 45 degrees per cell
  BYCMfodo1 := 21.362810104773 !L1: 45 degrees per cell
  BXCMfodo2 := 61.483042301615 !L2: 30 degrees per cell
  BYCMfodo2 := 36.259471142003 !L2: 30 degrees per cell
  BXCMfodo3 := 61.483042301615 !L3: 30 degrees per cell
  BYCMfodo3 := 36.259471142003 !L3: 30 degrees per cell
  BXCMfodo4 := 61.483042301615 !L4: 30 degrees per cell
  BYCMfodo4 := 36.259471142003 !L4: 30 degrees per cell

! match into bypass dogleg

  BXDLm := 13.103975995473
  AXDLm := -1.328121315284
  BYDLm := 15.962707890972
  AYDLm :=  1.529775364964

! matched Twiss at DBMARK34B

  MBETXS :=  6.841330859726
  MALFXS := -0.28404741292
  MBETYS := 47.12043239127
  MALFYS :=  2.555848494223

! periodic Twiss in HXR dogleg cells

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

! match into SXR LTU emittance diagnostic section

  BXEDs := 46.225914318019
  AXEDs := -1.084608326468
  BYEDs := 46.225914318019
  AYEDs :=  1.084608326468

! match into HXR LTU emittance diagnostic section

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

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

  CALL, FILENAME="common.xsif"
  CALL, FILENAME="CM.xsif"
  CALL, FILENAME="DIAG0.xsif" !must come before INJ.xsif
  CALL, FILENAME="INJ.xsif"
  CALL, FILENAME="INJ2.xsif"
  CALL, FILENAME="DIAGI.xsif"
  CALL, FILENAME="BC1.xsif"
  CALL, FILENAME="BC2.xsif"
  CALL, FILENAME="DLBM.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="SXTES.xsif"
  CALL, FILENAME="DASEL.xsif"
 !CALL, FILENAME="BLINE.xsif"

  LCLS2scI : LINE=(BEAM0,DCM4b,QCM01_full,DCM5,CM01END,&
    DCMCM1,HOMCM,DCAP0da,ASTRA,DCAP0db,FC1,DMSC0da,BLF1,DMSC0db,&
    VG0H00,DMSC0dc,VP0H00,DMSC0dd,VV0H00,DMSC0de,MSC0d,&
    ENDL0B)
  LCLS2scC : LINE=(HTR,COL0,L1,BC1,COL1,L2,BC2,EMIT2,L3,SLOT36,L4,EXT,DLBM)

  LCLS2scI2 : LINE=(BEAM0LEI,DCM4b,QCM00_full,DCM5,CM00END,&
    DCMCM1,HOMCM,DCAP0d2,FCLEI,DMSC0da,BLFLEI,&
    DMSC0db,VG0D00,DMSC0dc,VP0D00,DMSC0dd,VV0D00,DMSC0de,MSC0d,&
    ENDL0LEI,LEI_1)
  LCLS2scC2 : LINE=(LEI_2,HTR_2,COL0,L1,BC1,COL1,L2,BC2,EMIT2,&
    L3,SLOT36,L4,EXT,DLBM)

! new BSY area definitions

  CALL, FILENAME="BSYsc.xsif"

! ==============================================================================
! beam path definitions: beam from LCLS-II gun
! ------------------------------------------------------------------------------

 !SC_EIC   : Early Injector Commissioning
 !SC_DIAG0 : superconducting linac to DIAG0
 !SC_SXR   : superconducting linac to e- SXR dump
 !SC_SFTS  : superconducting linac to e- SXR safety dump
 !SC_S2_X  : superconducting linac to SXR "2.X" system
 !SC_STXI  : superconducting linac to SXR TXI system
 !SC_STMO  : superconducting linac to SXR TMO system
 !SC_HXR   : superconducting linac to e- HXR dump
 !SC_BSYD  : superconducting linac to BSY dump
 !SC_DASEL : superconducting linac to End Station A (DASEL)
 !SC_BSYB  : superconducting linac to B-line

  SC_EIC   : LINE=(EIC)
  SC_DIAG0 : LINE=(GUN,L0,HTR,DIAG0)
  SC_SXR   : LINE=(GUN,L0,LCLS2scC,LCLS2scS)
  SC_SFTS  : LINE=(GUN,L0,LCLS2scC,LCLS2scSS)
  SC_S2_X  : LINE=(GUN,L0,LCLS2scC,LCLS2scS2_X)
  SC_STXI  : LINE=(GUN,L0,LCLS2scC,LCLS2scSTXI)
  SC_STMO  : LINE=(GUN,L0,LCLS2scC,LCLS2scSTMO)
  SC_HXR   : LINE=(GUN,L0,LCLS2scC,LCLS2scH)
  SC_BSYD  : LINE=(GUN,L0,LCLS2scC,LCLS2scD)
  SC_DASEL : LINE=(GUN,L0,LCLS2scC,LCLS2scDA)
 !SC_BSYB  : LINE=(GUN,L0,LCLS2scC,LCLS2scB)

! for Twiss starting at BEAM0

  SC_DIAG0i : LINE=(LCLS2scI,HTR,DIAG0)
  SC_SXRi   : LINE=(LCLS2scI,LCLS2scC,LCLS2scS)
  SC_SFTSi  : LINE=(LCLS2scI,LCLS2scC,LCLS2scSS)
  SC_S2_Xi  : LINE=(LCLS2scI,LCLS2scC,LCLS2scS2_X)
  SC_STXIi  : LINE=(LCLS2scI,LCLS2scC,LCLS2scSTXI)
  SC_STMOi  : LINE=(LCLS2scI,LCLS2scC,LCLS2scSTMO)
  SC_HXRi   : LINE=(LCLS2scI,LCLS2scC,LCLS2scH)
  SC_BSYDi  : LINE=(LCLS2scI,LCLS2scC,LCLS2scD)
  SC_DASELi : LINE=(LCLS2scI,LCLS2scC,LCLS2scDA)
 !SC_BSYBi  : LINE=(LCLS2scI,LCLS2scC,LCLS2scB)

! ==============================================================================
! beam path definitions: beam from LEI gun
! ------------------------------------------------------------------------------

 !SC_DIAGIS : superconducting linac to DIAGI spectrometer
 !SC_DIAG02 : superconducting linac to DIAG0
 !SC_SXR2   : superconducting linac to e- SXR dump
 !SC_SFTS2  : superconducting linac to e- SXR safety dump
 !SC_S2_X2  : superconducting linac to SXR "2.X" system
 !SC_STXI2  : superconducting linac to SXR TXI system
 !SC_STMO2  : superconducting linac to SXR TMO system
 !SC_HXR2   : superconducting linac to e- HXR dump
 !SC_BSYD2  : superconducting linac to BSY dump
 !SC_DASEL2 : superconducting linac to End Station A (DASEL)

  SC_DIAGIS : LINE=(GUNLEI,L0LEI,LEI_1,DIAGIS)
  SC_DIAG02 : LINE=(GUNLEI,L0LEI,LEI,HTR_2,DIAG0)
  SC_SXR2   : LINE=(GUNLEI,L0LEI,LEI_1,LCLS2scC2,LCLS2scS)
  SC_SFTS2  : LINE=(GUNLEI,L0LEI,LEI_1,LCLS2scC2,LCLS2scSS)
  SC_S2_X2  : LINE=(GUNLEI,L0LEI,LEI_1,LCLS2scC2,LCLS2scS2_X)
  SC_STXI2  : LINE=(GUNLEI,L0LEI,LEI_1,LCLS2scC2,LCLS2scSTXI)
  SC_STMO2  : LINE=(GUNLEI,L0LEI,LEI_1,LCLS2scC2,LCLS2scSTMO)
  SC_HXR2   : LINE=(GUNLEI,L0LEI,LEI_1,LCLS2scC2,LCLS2scH)
  SC_BSYD2  : LINE=(GUNLEI,L0LEI,LEI_1,LCLS2scC2,LCLS2scD)
  SC_DASEL2 : LINE=(GUNLEI,L0LEI,LEI_1,LCLS2scC2,LCLS2scDA)

! for Twiss starting at BEAM0LEI

  SC_DIAGISi : LINE=(LCLS2scI2,DIAGIS)
  SC_DIAG02i : LINE=(LCLS2scI2,LEI_2,HTR_2,DIAG0)
  SC_SXR2i   : LINE=(LCLS2scI2,LCLS2scC2,LCLS2scS)
  SC_SFTS2i  : LINE=(LCLS2scI2,LCLS2scC2,LCLS2scSS)
  SC_S2_X2i  : LINE=(LCLS2scI2,LCLS2scC2,LCLS2scS2_X)
  SC_STXI2i  : LINE=(LCLS2scI2,LCLS2scC2,LCLS2scSTXI)
  SC_STMO2i  : LINE=(LCLS2scI2,LCLS2scC2,LCLS2scSTMO)
  SC_HXR2i   : LINE=(LCLS2scI2,LCLS2scC2,LCLS2scH)
  SC_BSYD2i  : LINE=(LCLS2scI2,LCLS2scC2,LCLS2scD)
  SC_DASEL2i : LINE=(LCLS2scI2,LCLS2scC2,LCLS2scDA)

! ==============================================================================
! initial BSY coordinates at BEGSP (LTUSPLIT)
! ------------------------------------------------------------------------------

  Xf     :=  XOFF
  Yf     :=  1.899339708719 !1.897939159495 -0.3*SIN(2*AVB)
  Zf     := -267.7180471432 !-267.4180504124 -0.3*COS(2*AVB)
  THETAf :=  0
  PHIf   :=  2*AVB
  PSIf   :=  0

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

  RETURN
