! Started with MAD file from Slava 29Oct04. Gaol is to generate global coords. 
! Not sure about K1 parameter in bend definitions, so may not give good optics. 
! Although the HEBT arc magnets are rectangular, will treat as sector bends, since these
! bends are parameterized by path length and therefore easier to split. Also 
! Transport assumes sector magnets. The polarity of the pole face rotations were chosen to duplicate the Transport output.
! Also note that all the bend angles have opposite polarity from the Transport file. 
! This change was needed to get the global coordinates.   
! -- MAP 1Nov04.
!
! Revised 16/Feb/05 to also split the last two bend magnets. -- MAP 16/Feb/05
!
! Corrected L48 drift -- added 0.0001 m. Drift upstream of Q14. -- MAP 17/Feb/05
!
! Modified to make diagnostics positions same as Deepak's on-line Transport file version sns_hebt_040202.in. -- MAP 17/Feb/05
!
! Survey output agrees with official global coords SNS/AD doc. transmittal #135 -- MAP 18/Feb/05
!

 Title, "SNS HEBT Line "


 E0    := 0.938272310   !proton mass [GeV]
  C     := 2.99792458e8  !speed of light [m/sec]

  DTR   := PI/180.

  EK    := 1.00          ![GeV] injection kinetic Energy

  PC    := -sqrt(EK*(EK+2*E0))       ;  Value PC
  BRHO  := 1.e9*PC/C                ;  Value BRHO
  GAMMA := 1+EK/E0                  ;  Value GAMMA    
  BETA  := sqrt(1-1/(GAMMA*GAMMA))  ;  Value BETA

QL1:=0.2525
QLL1:=0.25 
QL2:=0.5050
QLL2:=0.5 
QAR:=1.000  ! 1 DM aperture for quads
DL:=0.0001
LDB1:=0.44618909
LDB2:=0.94618909
LBND:=2.72041792
LDB1A:=LDB1-0.0025
DR1:=3.4950
BANG:=-5.625
GRAD:=-0.27164
KB1:=GRAD*BANG*BANG*PI*PI/180./180./LBND/LBND
P1ERR:=-2.20890*.00/QAR/BRHO 
P2ERR:=+2.16399*.00/QAR/BRHO

P3ERR:=-3.39917*0.0/QAR/BRHO 
P4ERR:=+3.38761*0.00/QAR/BRHO

!BM: BEAM.0000,BETAY=1.3453,ALPHAX=-0.0,BETAX=0.2377,ALPHAY=-0.0,P0=-1.6960 ;
!BEAM, MASS=E0+2*0.000511,CHARGE=-1,GAMMA=1+EK/E0, SIGT=0.01,   

Q01:  QUAD, L=QL1, K1=4.13939/QAR/BRHO

BLM01:  MARKER  ; ! (BLM)
D01A:  DRIFT,   L= 0.1306971 ;
BPM01:  MARKER  ; ! (Center of BPM)
D01B:  DRIFT,   L=0.6168029 ;! (end of Q1 chamber)
D01C:  DRIFT,   L=0.362458 ; ! (dwg 5104094 14.27*0.254)
WS01:  MARKER   ; ! (WS)
D01D:   DRIFT,  L=1.387542 ; ! (1.75-0.362458 end of ws/bcm chamber with bellow)
BCM01:  MARKER  ; ! (BCM)
D01E:   DRIFT,  L= 0.9975  ; ! (end of drift pipe)

CELL1: LINE=(Q01,d01A,BPM01,D01B,D01C,WS01,D01D,BCM01,D01E) 

Q02:  QUAD, L=QL2, K1=-4.13939/QAR/BRHO
Q02S:  QUAD, L=QL2/2., K1=-4.13939/QAR/BRHO

BLM02A: MARKER  ; ! (BLM)
D02A:   DRIFT,  L= 0.1306971 ;
BPM02:  MARKER ; ! ( Center of BPM)
D02B:   DRIFT,  L=0.6168029 ; ! (end of Q2 chamber)
D02C:   DRIFT,  L=0.27305   ; ! (dwg 5104095 10.75*.0254)
WS02:  MARKER ; ! (WS)
D02D:   DRIFT,  L=0.72695   ; ! (1.-0.27305 end of ws chamber with bellow)
D02E:   DRIFT,  L=1.7475 ; ! (end of drift pipe)

CELL2: LINE=(Q02S,Q02S,BLM02A,D02A,BPM02,D02B,D02C,WS02,D02D,D02E,BLM02A)

Q03:  QUAD, L=QL2, K1=4.13939/QAR/BRHO
Q03S:  QUAD, L=QL2/2., K1=4.13939/QAR/BRHO

BLM03: MARKER  ; ! (BLM)
D03A:   DRIFT,   L= 0.1306971 ;
BPM03:  MARKER ; ! (center of BPM)
D03B:  DRIFT,   L=0.6168029; ! (END OF Q3 CHAMBER)
D03C:  DRIFT,   L=0.27305   ; ! (dwg 5104095 10.75*.0254)
WS03:  MARKER  ; ! (WS)
D03D:  DRIFT,   L=0.72695   ; ! (1.-0.27305 end of ws chamber with bellow)
D03E:  DRIFT,   L=1.643 ; ! (END OF DRIFT PIPE)
D03F:  DRIFT,   L=0.0535 ; 
SCRP01L: MARKER ; ! (Collimator foil H)
SCRP01R: MARKER ; ! (Collimator foil H)
D03G:  DRIFT,   L=0.0510;

CELL3: LINE=(Q03S,Q03S,BLM03,D03A,BPM03,D03B,D03C,WS03,D03D, & 
D03E,D03F,SCRP01L,SCRP01R,D03G)

Q04:  QUAD , L=QL2, K1=-4.13939/QAR/BRHO
Q04S:  QUAD , L=QL2/2., K1=-4.13939/QAR/BRHO

BLM04A: MARKER ; ! BLM)
D04A:  DRIFT,   L= 0.1306971 ;
BPM04:  MARKER; ! center of BPM)
D04B:  DRIFT, L=0.6168029 ; ! END OF Q4 CHAMBER)
D04C:  DRIFT, L=0.27305   ; ! dwg 5104095 10.75*.0254)
WS04: MARKER ; ! WS)
D04D:  DRIFT, L=0.72695   ; ! 1.-0.27305 end of ws chamber with bellow)
BLM04B: MARKER ; ! BLM)
D04E:  DRIFT, L=1.646 ; ! END OF DRIFT PIPE)
D04F:  DRIFT, L=0.0520 ;
SCRP01U: MARKER ; ! Collimator foil V)
SCRP01D: MARKER ; ! Collimator foil V)
D04G:  DRIFT,   L=0.0495;

CELL4: LINE=(Q04S,Q04S,BLM04A,D04A,BPM04,D04B,D04C,WS04,D04D, & 
BLM04B,D04E,D04F,SCRP01U,SCRP01D,D04G)


Q05:  QUAD , L=QL2, K1=4.13939/QAR/BRHO
Q05S:  QUAD , L=QL2/2., K1=4.13939/QAR/BRHO

BLM05:  MARKER ; ! FBLM)
D05A0:  DRIFT,   L= 0.1306971 ;
BPM05:  MARKER; ! Center of BPM)
D05A1:  DRIFT, L=.1369949 ;
DCV05:  VKICK, L=0.0 ; ! V center of corrector)
D05A:   DRIFT, L=0.479808; ! END OF Q5 CHAMBER)
COLL01: DRIFT, L=2.572 ; ! Absorber Collimator)
D05B:   DRIFT, L=0.089 ;
SCRP02L:  MARKER; ! Collimator Foil H)
SCRP02R:  MARKER; ! Collimator Foil H)
D05C:   DRIFT, L= 0.0865;

CELL5: LINE=(Q05S,Q05S,BLM05,D05A0,BPM05,D05A1,DCV05,D05A, & 
COLL01,D05B,SCRP02L,SCRP02R,D05C)

Q06:  QUAD , L=QL2, K1=-4.13939/QAR/BRHO
Q06S:  QUAD , L=QL2/2., K1=-4.13939/QAR/BRHO

BLM06A: MARKER ; ! (BLM)
D06A0:  DRIFT,   L= 0.1306971 ;
BPM06:  MARKER ; ! (Center of BPM)
D06A1:  DRIFT, L=.1369949 ;
DCH06:  HKICK,   L=0.0 ; ! (H Corrector center)
D06A:   DRIFT, L=0.479808 ; ! (END OF Q6 CHAMBER)
D06B:   DRIFT, L=2.646; 
D06C:   DRIFT, L=0.0520;
SCRP02U: MARKER ; ! (Collimator Foil V)
SCRP02D: MARKER ; ! (Collimator Foil V)
BLM06B: MARKER ; ! (BLM)
D06D:  DRIFT,   L=0.0495;

CELL6: LINE=(Q06S,Q06S,BLM06A,D06A0,BPM06,D06A1,DCH06, &
D06A,D06B,D06C,SCRP02U,SCRP02D,BLM06B,D06D)

Q07:  QUAD , L=QL2, K1=4.13939/QAR/BRHO
Q07S:  QUAD , L=QL2/2., K1=4.13939/QAR/BRHO
BLM07: MARKER ; ! (BLM)
D07A0:  DRIFT,   L= 0.1306971 ;
BPM07: MARKER ; ! (Center of BPM)
D07A1: DRIFT, L=0.1369949 ;
DCV07:  VKICK,   L=0.0 ; ! (center Corrector V)
D07A:  DRIFT, L=0.479808 ; ! (END OF Q7 CHAMBER)
COLL02:  DRIFT, L=2.572 ; ! (Collimator Absorber)
D07B:  DRIFT,   L=0.1755 ;

CELL7: LINE=(Q07S,Q07S,BLM07,D07A0,BPM07,D07A1,DCV07, &
D07A,COLL02,D07B)

Q08:  QUAD , L=QL2, K1=-3.54599/QAR/BRHO
Q08S:  QUAD , L=QL2/2., K1=-3.54599/QAR/BRHO
BLM08A: MARKER ; ! (BLM)
D08A0:  DRIFT,   L= 0.1306971 ;
BPM08:  MARKER;  ! (Center of BPM)
D08A1:  DRIFT, L=0.1369949 ;
DCH08:  HKICK,   L=0.0 ; ! (center Corrector H)
D08A:   DRIFT, L=0.479808 ; ! (END OF Q8 CHAMBER)
D08B:   DRIFT, L=2.7475 ; ! (END OF BEAM PIPE)
BLM08B: MARKER ; ! (BLM)

CELL8: LINE=(Q08S,Q08S,BLM08A,D08A0,BPM08,D08A1,DCH08,& 
D08A,D08B,BLM08B)

Q09:  QUAD , L=QL2, K1=3.15906/QAR/BRHO
Q09S:  QUAD , L=QL2/2., K1=3.15906/QAR/BRHO
BLM09: MARKER ; ! (BLM)
D09A0:  DRIFT,   L= 0.1306971 ;
BPM09:  MARKER ; ! ( Center of BPM)
D09A:  DRIFT, L=0.6168029 ; ! (END OF Q9 CHAMBER)
D09B:  DRIFT, L=0.362458 ; ! (dwg 5104094 14.27*0.254)
WS09:  MARKER  ; ! (WS)
D09C:  DRIFT,  L=1.387542 ; ! (1.75-0.362458 end of ws/bcm chamber with bellow)
BCM09: MARKER  ; ! (BCM)
D09D:  DRIFT,  L=0.9975 ;

CELL9: LINE=(Q09S,Q09S,BLM09,D09A0,BPM09,D09A,D09B,WS09,D09C,BCM09,D09D)

Q10:  QUAD , L=QL2, K1=-2.94351/QAR/BRHO
Q10S:  QUAD , L=QL2/2., K1=-2.94351/QAR/BRHO;
BLM10A: MARKER ; ! (BLM)
D10A0:  DRIFT,   L= 0.1306971 ;
BPM10:  MARKER ; ! (center of BPM)
D10A:   DRIFT, L=0.6168029 ; ! (END OF Q10 CHAMBER)
CAV10:  DRIFT, L=1.822 ; ! (ECC)
D10B:   DRIFT,   L=1.2948029;
BPM11: MARKER ; ! (BPM)
D11A0:  DRIFT,   L= 0.1306971 ;
BLM10B: MARKER ; ! (BLM)

CELL10: LINE=(Q10S,Q10S,BLM10A,D10A0,BPM10,D10A,CAV10, &
D10B,BPM11,D11A0,BLM10B)

Q11A:  QUAD , L=QL1, K1=2.78921/QAR/BRHO
Q11B:  QUAD , L=QL1, K1=2.16399/QAR/BRHO
Q11M:  QUAD , L=QL2, K1=2.4766/QAR/BRHO
Q11S:  QUAD , L=QL2/2., K1=2.4639/QAR/BRHO
M32:  DRIFT,   L=0.0 ; !(BLM)
M33:  DRIFT,   L=0.0 ; !(BPM)
L41:  DRIFT,   L=LDB1A;
!DR3:  ROTAT,  ANGLE=5.625 ;
DD1:  SBEND,   L=2.*LBND, ANGLE=2.*BANG*PI/180.,K1=-KB1;
DD1S1:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=-5.625*PI/180., E2=0.,K1=-KB1;
DD1S2:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=0., E2=-5.625*PI/180.,K1=-KB1;
!DR4:  ROTAT,  ANGLE=5.625 ;
L42:  DRIFT,   L=0.32471507;
WS11: MONITOR, L=0.; !  (WS) 
L43: DRIFT,   L=0.621474;

CELL11: LINE=(Q11S,Q11S,M32,M33,L41,DD1S1,DD1S2,L42,WS11,L43)


Q12:  QUAD , L=QLL2, K1=-2.20890/QAR/BRHO + P1ERR
Q12S:  QUAD , L=QLL2/2., K1=-2.20890/QAR/BRHO
M34:  DRIFT,   L=0.0 ; !(BLM)
L44:  DRIFT,   L=LDB1;
!DR3:  ROTAT,  ANGLE=5.626 ;
DD2:  RBEND,   L=2.*LBND, ANGLE=2.*BANG*PI/180.,TYPE=BND,K1=-KB1;
DD2S1:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=-5.625*PI/180., E2=0.,K1=-KB1;
DD2S2:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=0., E2=-5.625*PI/180.,K1=-KB1;
!DR4:  ROTAT,  ANGLE=5.625 ;
M35:  DRIFT,   L=0.0 ; !(BLM)
L45:  DRIFT,   L=LDB2;

CELL12: LINE=(Q12S,Q12S,M34,L44,DD2S1,DD2S2,M35,L45)

!Q13:  QUAD , L=QL1, K1=2.14435/QAR/BRHO
!Q13A:  QUAD , L=QL1, K1=2.14435/QAR/BRHO
Q13M:  QUAD , L=QLL2, K1=2.16399/QAR/BRHO+ P2ERR
Q13S:  QUAD , L=QLL2/2., K1=2.16399/QAR/BRHO
L46A:  DRIFT,   L=LDB1;
!DR3:  ROTAT,  ANGLE=5.625 ;
DD3:  RBEND,   L=2.*LBND, ANGLE=2.*BANG*PI/180.,K1=-KB1;
DD3S1:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=-5.625*PI/180., E2=0.,K1=-KB1;
DD3S2:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=0., E2=-5.625*PI/180.,K1=-KB1;
L47:   DRIFT,   L=0.32488909;
SCRP03L:  MONITOR,   L=0.0 ; !(Momentom collimator foil)
SCRP03R:  MONITOR,   L=0.0 ; !(Momentom collimator foil)
L48:  DRIFT,   L=0.318088 ; 
DCH14:  HKICKER,  KICK= 0.,  L=0.0 ; !(Corrector H)
L49:  DRIFT,   L=0.303212 ; 

CELL13: LINE=(Q13S,Q13S,L46A,DD3S1,DD3S2,L47,SCRP03L,SCRP03R,L48,DCH14,L49)

Q14:  QUAD , L=QLL2, K1=-2.20870/QAR/BRHO + P1ERR
Q14S:  QUAD , L=QLL2/2., K1=-2.20870/QAR/BRHO
BLM14A: MARKER ; ! (BLM)
L46B:  DRIFT,   L=LDB1;
!DR3:  ROTAT,  ANGLE=5.625 ;
DD4:  RBEND,   L=2.*LBND, ANGLE=2.*BANG*PI/180.,K1=-KB1;
DD4S1:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=-5.625*PI/180., E2=0.,K1=-KB1;
DD4S2:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=0., E2=-5.625*PI/180.,K1=-KB1;
M46:  MONITOR,   L=0.0 ; !(FBLM)
L50:   DRIFT,   L=0.64297709;
DCV15:  VKICKER,  KICK= 0.,  L=0.0 ; !(Corrector V)
L51:  DRIFT,   L=0.303212 ; 

CELL14: LINE=(Q14S,Q14S,L46B,DD4S1,DD4S2,M46,L50,DCV15,L51)

!Q15:  QUAD , L=QL1, K1=2.14435/QAR/BRHO+ P2ERR
!Q15A:  QUAD , L=QL1, K1=2.14435/QAR/BRHO
Q15M:  QUAD , L=QLL2, K1=2.16399/QAR/BRHO+ P2ERR
Q15S:  QUAD , L=QLL2/2., K1=2.16399/QAR/BRHO
BLM15: MARKER ; ! (BLM)
L52:  DRIFT,   L=LDB1;
!DR3:  ROTAT,  ANGLE=5.625 ;
DD5:  RBEND,   L=2.*LBND, ANGLE=2.*BANG*PI/180.,K1=-KB1;
DD5S1:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=-5.625*PI/180., E2=0,K1=-KB1.;
DD5S2:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=0., E2=-5.625*PI/180.,K1=-KB1;
L53:   DRIFT,   L=0.64297709;
DCH16:  HKICKER,  KICK= 0.,  L=0.0 ; !(Corrector H)
D16B:  DRIFT, L=0.1973072 ;
M47: MONITOR,   L=0.0 ; !(BPM)
D16C:  DRIFT, L=0.1059048 ;

CELL15: LINE=(Q15S,Q15S,L52,DD5S1,DD5S2,L53,DCH16,D16B,M47,D16C)

Q16:  QUAD , L=QLL2, K1=-2.2089/QAR/BRHO+ P1ERR
Q16S:  QUAD , L=QLL2/2., K1=-2.2089/QAR/BRHO
M48:  MONITOR,   L=0.0;! (BLM)
L55:  DRIFT,   L=LDB1;
!DR3:  ROTAT,  ANGLE=5.625 ;
DD6:  RBEND,   L=2.*LBND, ANGLE=2.*BANG*PI/180.,K1=-KB1;
DD6S1:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=-5.625*PI/180., E2=0.,K1=-KB1;
DD6S2:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=0., E2=-5.625*PI/180.,K1=-KB1;
L56:   DRIFT,   L=0.64297709;
DCV17:  VKICKER,  KICK= 0.,  L=0.0 ; !(Corrector V)
D17B:   DRIFT, L=0.1973072 ;
M49: MONITOR,   L=0.0 ; !(BPM)
D17C:  DRIFT, L=0.1059048 ;

CELL16: LINE=(Q16S,Q16S,M48,L55,DD6S1,DD6S2,L56,DCV17,D17B,M49,D17C)

!Q17:  QUAD , L=QL1, K1=2.14435/QAR/BRHO+ P2ERR
!Q17A:  QUAD , L=QL1, K1=2.14435/QAR/BRHO
Q17M:  QUAD , L=QLL2, K1=2.16399/QAR/BRHO+ P2ERR
Q17S:  QUAD , L=QLL2/2., K1=2.16399/QAR/BRHO
M50: MONITOR,   L=0.0 ; !(BLM)
L58:  DRIFT,   L=LDB1;
!DR3:  ROTAT,  ANGLE=5.625 ;
DD7:  RBEND,   L=2.*LBND, ANGLE=2.*BANG*PI/180.,K1=-KB1;
DD7S1:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=-5.625*PI/180., E2=0.,K1=-KB1;
DD7S2:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=0., E2=-5.625*PI/180.,K1=-KB1;
D18B:  DRIFT,   L=LDB2-0.1059048;
M51: MONITOR,   L=0.0 ; !(BPM)
D18C:  DRIFT, L=0.1059048 ;

CELL17: LINE=(Q17S,Q17S,M50,L58,DD7S1,DD7S2,D18B,M51,D18C)

Q18:  QUAD , L=QLL2, K1=-2.20890/QAR/BRHO + P1ERR
Q18S:  QUAD , L=QLL2/2., K1=-2.20890/QAR/BRHO 
M52: MONITOR,   L=0.0 ; !(BLM)
L60:  DRIFT,   L=LDB1;
!DR3:  ROTAT,  ANGLE=5.625 ;
DD8:  RBEND,   L=2.*LBND, ANGLE=2.*BANG*PI/180.,K1=-KB1;
DD8S1:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=-5.625*PI/180., E2=0.,K1=-KB1;
DD8S2:  SBEND,   L=LBND, ANGLE=BANG*PI/180., E1=0., E2=-5.625*PI/180.,K1=-KB1;
M53: MONITOR,   L=0.0 ; !(BLM)
D19B:   DRIFT,   L=LDB2-0.1059048;
M54: MONITOR,   L=0.0 ; !(BPM)
D19C:  DRIFT, L=0.1059048 ;

CELL18: LINE=(Q18S,Q18S,M52,L60,DD8S1,DD8S2,M53,D19B,M54,D19C)

!Q19:  QUAD , L=QL1, K1=2.14435/QAR/BRHO
!Q19A:  QUAD , L=QL1, K1=2.14435/QAR/BRHO
Q19M:  QUAD , L=QLL2, K1=2.16399/QAR/BRHO + P2ERR
Q19S:  QUAD , L=QLL2/2., K1=2.16399/QAR/BRHO
M55:  MONITOR,   L=0.0 ; !(BLM)
L62:  DRIFT, L=0.25 ; !(end of Q19 chamber)
L63:  DRIFT, L=0.08 ; !(SGV-Q mounted on Q19 chamber)
L64: DRIFT, L=0.025 ; !(thin flange)
CAV19: DRIFT, L=1.822; ! (energy spreader)
L65: DRIFT, L=2.8205 ;

CELL19: LINE=(Q19S,Q19S,M55,L62,L63,L64,CAV19,L65)


Q20:  QUAD , L=QL2, K1=-2.559946/QAR/BRHO
Q20S:  QUAD , L=QL2/2., K1=-2.559946/QAR/BRHO
M56:  MONITOR,   L=0.0 ; !(BLM)
D20A0: DRIFT, L=0.1306971 ;
M57:  MONITOR,   L=0.0 ; !(BPM)
L66:  DRIFT, L=0.3668029  ; ! (end of Q20 chamber)
L67:  DRIFT, L=0.362458 ; ! (dwg 5104094 14.27*0.254)
WS20:  MONITOR,   L=0.0 ; !(WS)
L68:  DRIFT, L=1.387542 ; ! (1.75-0.362458 end of ws/bcm chamber with bellow)
BCM20: MARKER ; ! (BCM)
L69:  DRIFT, L=2.0;
L70:  DRIFT, L=0.2475;
M58:  MONITOR,   L=0.0 ; !(BLM)

CELL20: LINE=(Q20S,Q20S,M56,D20A0,M57,L66,L67,WS20,L68,BCM20,L69,L70,M58)

Q21:  QUAD ,  L=QL2, K1=2.6968220/QAR/BRHO
Q21S:  QUAD ,  L=QL2/2., K1=2.6968220/QAR/BRHO
M59:  MONITOR,   L=0.0 ; ! (BLM)
D21A0: DRIFT, L=0.1306971 ;
M60:  MONITOR,   L=0.0 ; ! (BPM)
D21A:  DRIFT, L=0.1369949 ;
DCV21:  VKICKER,  KICK= 0.,  L=0.0 ; ! (Corrector V)
L72:  DRIFT, L=0.229808 ; ! (end of Q21 chamber)
D21B:   DRIFT, L=0.27305   ; ! (dwg 5104095 10.75*.0254)
WS21:  MONITOR,   L=0.0 ; !(WS)
D21C:   DRIFT, L=0.72695   ; ! (1.-0.27305 end of ws chamber with bellow)
D21D:  DRIFT, L=2.25;
D21E:  DRIFT, L=0.2475;

CELL21: LINE=(Q21S,Q21S,M59,D21A0,M60,D21A,DCV21,L72,D21B, &
WS21,D21C,D21D,D21E)

Q22:  QUAD   L=QL2, K1=-3.107763/QAR/BRHO
Q22S:  QUAD   L=QL2/2., K1=-3.107763/QAR/BRHO
BLM22A: MARKER ; ! (BLM)
D22A0: DRIFT, L=0.1306971 ;
BPM22:  MARKER ; ! (BPM)
D22A:   DRIFT, L=0.1369949 ;
DCH22:  HKICK,   L=0.0 ; ! (Corrector H)
D22B:   DRIFT, L=0.229808; ! (END OF Q22 CHAMBER)
D22C:   DRIFT, L=0.27305   ; ! (dwg 5104095 10.75*.0254)
WS22:  MARKER; ! (WS)
D22D:   DRIFT, L=0.72695   ; ! (1.-0.27305 end of ws chamber with bellow)
D22E:   DRIFT, L=2.25 ;
D22F:   DRIFT, L=0.2475 ;
BLM22B: MARKER ; ! (BLM)

CELL22: LINE=(Q22S,Q22S,BLM22A,D22A0,BPM22,D22A, &
DCH22,D22B,D22C,WS22,D22D,D22E,D22F,BLM22B)

Q23:  QUAD   L=QL2, K1=2.930897/QAR/BRHO
Q23S:  QUAD   L=QL2/2., K1=2.930897/QAR/BRHO

BLM23: MARKER ; ! (BLM)
D23A0: DRIFT, L=0.1306971 ;
BPM23:  MARKER ; ! (BPM)
D23A:  DRIFT, L=.1369949 ;
DCV23: VKICK,  L=0.0 ; ! (Corrector V)
D23B:  DRIFT, L=0.229808 ; ! (END OF Q23 CHAMBER)
D23C:  DRIFT, L=0.27305   ; ! (dwg 5104095 10.75*.0254)
WS23:  MARKER; ! (WS)
D23D:  DRIFT, L=0.72695   ; ! (1.-0.27305 end of ws chamber with bellow)
D23E:  DRIFT, L=2.25 ;
D23F:  DRIFT, L=0.2475 ;

CELL23: LINE=(Q23S,Q23S,BLM23,D23A0,BPM23,D23A, & 
DCV23,D23B,D23C,WS23,D23D,D23E,D23F)

Q24:  QUAD   L=QL2, K1=-3.603289/QAR/BRHO
Q24S:  QUAD   L=QL2/2., K1=-3.603289/QAR/BRHO
BLM24A:  MARKER ; ! (BLM)
D24A0: DRIFT, L=0.1306971 ;
BPM24:  MARKER ; ! (BPM)
D24A:   DRIFT, L=0.1369949 ;
DCH24:  HKICK,   L=0.0 ; ! (Corrector H)
D24B:   DRIFT, L=0.229808 ; ! (END OF Q24 CHAMBER)
D24C:   DRIFT, L=2.75 ;
D24D:   DRIFT, L=0.2475 ;
BLM24B: MARKER ; ! (BLM)

CELL24: LINE=(Q24S,Q24S,BLM24A,D24A0,BPM24,D24A,DCH24,D24B,D24C,D24D,BLM24B)

Q25:  QUAD,  L=QL2, K1=3.38761/QAR/BRHO + P4ERR
Q25S:  QUAD,  L=QL2/2., K1=3.38761/QAR/BRHO
BLM25: MARKER ; ! (BLM)
D25A0: DRIFT, L=0.1306971 ;
BPM25: MARKER ; ! (BPM)
D25A:  DRIFT, L=0.87430228 ;
D25B: DRIFT, L=-0.0025
!DRP:  ROTAT,  ANGLE=0.0 ;
!DD9: RBEND, L=4.1340207, ANGLE=8.754868*PI/180. ;
DH25S1: SBEND, L=4.1340207/2., ANGLE=8.754868*PI/180./2., & 
E1= 8.754868*PI/180./2., E2=0.; ! Added another signficant digit to bend angle to get agreement with existing global coords sheet. 
DH25S2: SBEND, L=4.1340207/2., ANGLE=8.754868*PI/180./2., &
 E1= 0., E2=8.754868*PI/180./2.; ! Not sure about E1 and E2 here...
!DRQ:  ROTAT,  ANGLE=0.0 ;
L96:  DRIFT, L=0.50499938 ;
L97:  DRIFT, L=-0.0025 ;

CELL25: LINE=(Q25S,Q25S,BLM25,D25A0,BPM25,D25A,D25B &
DH25S1, DH25S2,L96,L97)

Q26:  QUAD , L=QL2, K1=-3.39917/QAR/BRHO+P3ERR
Q26S:  QUAD , L=QL2/2., K1=-3.39917/QAR/BRHO
BLM26A: MARKER ; ! (BLM)
D26A0: DRIFT, L=0.1306971 ;
BPM26:  MARKER ; ! (BPM)
D26A:   DRIFT, L=0.3668029; ! (END OF Q26 CHAMBER)
D26B:   DRIFT, L=2.75 ;
D26C:   DRIFT, L=0.2475 ;
BLM26B: MARKER ; ! (BLM)

CELL26: LINE=(Q26S,Q26S,BLM26A,D26A0,BPM26,D26A,D26B,D26C,BLM26B)

Q27:  QUAD,   L=QL2, K1=3.38761/QAR/BRHO + P4ERR
Q27S:  QUAD,   L=QL2/2., K1=3.38761/QAR/BRHO
BLM27: MARKER ; ! (BLM)
D27A0: DRIFT, L=0.1306971 ;
BPM27:  MARKER ; ! (BPM)
D27A:   DRIFT, L=0.3668029; ! (END OF Q27 CHAMBER)
D27B:   DRIFT, L=2.75 ;
D27C:   DRIFT, L=0.2475 ;

CELL27: LINE=(Q27S,Q27S,BLM27,D27A0,BPM27,D27A,D27B,D27C)

Q28:  QUAD , L=QL2, K1=-3.39917/QAR/BRHO+P3ERR
Q28S:  QUAD , L=QL2/2., K1=-3.39917/QAR/BRHO
BLM28A: MARKER ; ! (BLM)
D28A0: DRIFT, L=0.1306971 ;
BPM28:  MARKER ; ! (BPM)
D28A:   DRIFT, L=0.1369949 ;
DCH28:  HKICK,   L=0.0 ; ! (Corrector H)
D28B:   DRIFT, L=0.229808; ! (END OF Q28 CHAMBER)
D28C:   DRIFT, L=2.75 ;
D28D:   DRIFT, L=0.2475 ;
BLM28B: MARKER ; ! (BLM)

CELL28: LINE=(Q28S,Q28S,BLM28A,D28A0,BPM28, &
D28A,DCH28,D28B,D28C,D28D,BLM28B)

Q29:  QUAD,   L=QL2, K1=3.38761/QAR/BRHO + P4ERR
Q29S:  QUAD,   L=QL2/2., K1=3.38761/QAR/BRHO
M78:  MONITOR,   L=0.0 ; !(BLM)
D29A0: DRIFT, L=0.1306971 ;
M79:  MONITOR,   L=0.0 ; !(BPM)
D29A:  DRIFT, L=0.1369949 ;
DCV29: HKICK, L=0.0 ; ! (kicker V)
L109:  DRIFT, L=0.229808 ; ! (end of Q29 chamber)
L110:  DRIFT, L=2.25 ;
L111: DRIFT, L=0.2475 ; 

CELL29: LINE=(Q29S,Q29S,M78,D29A0,M79,D29A,DCV29,L109,L110,L111)

Q30:  QUAD, L=QL2, K1=-4.25811/QAR/BRHO
Q30S:  QUAD, L=QL2/2., K1=-4.25811/QAR/BRHO
M80:  MONITOR,   L=0.0 ; !(BLM)
D30A0: DRIFT, L=0.1306971 ;
M81:  MONITOR,   L=0.0 ; !(BPM)
D30A:   DRIFT, L=0.1369949 ;
DCH30: HKICK, L=0.0 ; ! (kicker H)
L113:  DRIFT, L=0.229808 ; ! (end of Q30 chamber)
L114:  DRIFT, L=2.75 ;
L115: DRIFT, L=0.2475 ; 
M82:  MONITOR,   L=0.0 ; !(BLM)

CELL30: LINE=(Q30S,Q30S,M80,D30A0,M81,D30A,DCH30,L113,L114,L115,M82)

Q31:  QUAD,  L=QL2,K1=3.38761/QAR/BRHO + P4ERR
Q31S:  QUAD,  L=QL2/2.,K1=3.38761/QAR/BRHO
M83:  MONITOR,   L=0.0 ; !(BLM)
D31A0: DRIFT, L=0.1306971 ;
BPM31:  MONITOR,   L=0.0 ; !(BPM)
D31A:   DRIFT, L=0.1369949 ;
DCV31: HKICK, L=0.0 ; ! (kicker V)
L117:  DRIFT, L=0.229808 ; ! (end of Q31 chamber)
L118:  DRIFT, L=2.75 ;
L119: DRIFT, L=0.2475 ; 

CELL31: LINE=(Q31S,Q31S,M83,D31A0,BPM31,D31A,DCV31,L117,L118,L119)

Q32:  QUAD , L=QL2, K1=-3.39917/QAR/BRHO+P3ERR
Q32S:  QUAD , L=QL2/2., K1=-3.39917/QAR/BRHO
BLM32A:  MONITOR,   L=0.0 ; ! (BLM)
D32A0: DRIFT, L=0.1306971 ;
BPM32:   MONITOR,   L=0.0 ; ! (BPM)
D32A:   DRIFT, L=0.3668029; ! (END OF Q32 CHAMBER)
D32B:   DRIFT, L=0.362458 ; ! (dwg 5104094 14.27*0.254)
WS32:    MONITOR,   L=0.0; ! (WS)
D32C:   DRIFT, L=1.387542 ; ! (1.75-0.362458 end of ws/bcm chamber with bellow)
BCM32: MARKER ; ! (BCM)
D32D:   DRIFT, L=3.27 ;
D32E:   DRIFT, L=0.10 ;
D32F:   DRIFT, L=0.3618029 ;
BPM33:   MONITOR,   L=0.0; ! (BPM)
BLM32B:  MONITOR,   L=0.0 ; ! (BLM)
D33A0: DRIFT, L=0.1306971 ;

CELL32: LINE=(Q32S,Q32S,BLM32A,D32A0,BPM32,D32A, &
D32B,WS32,D32C,BCM32,D32D,D32E,D32F,BPM33,BLM32B,D33A0)

Q33:  QUAD, L=QL2, K1=5.53510/QAR/BRHO
Q33S:  QUAD, L=QL2/2., K1=5.53510/QAR/BRHO
M90:  MONITOR,   L=0.0 ; !(BLM)
L126:  DRIFT, L=0.355 ;

CELL33: LINE=(Q33S,Q33S,M90,L126)

Q34:  QUAD, L=QL2, K1=-5.00592/QAR/BRHO
Q34S:  QUAD, L=QL2/2., K1=-5.00592/QAR/BRHO
L127:  DRIFT, L=1.2475 ;
!DRT:  ROTAT,  ANGLE=0.0 ;
DDF: SBEND, L=3.0635682, ANGLE=-6.351*PI/180. ; ! (Injection septum)
DDFS: SBEND, L=3.0635682/2, ANGLE=-6.351*PI/180./2. ; ! (Injection septum)
!DRU:  ROTAT,  ANGLE=0.0 ;
L128:  DRIFT, L=2.38416 ;
!DRV:  ROTAT,  ANGLE=0.0 ;
DDG: RBEND, L=0.79439, ANGLE=-2.404*PI/180. ; ! (Chicane magnet #2 w/ strip foil at dnstream end)
DDGS: SBEND, L=0.79439/2., ANGLE=-2.404*PI/180./2. ; ! (Chicane magnet #2 w/ strip foil at dnstream end)
!DRW:  ROTAT,  ANGLE=0.0 ;
L129:  DRIFT, L=0.0

CELL34: LINE=(Q34S,Q34S,L127,DDFS,DDFS,L128,DDGS,DDGS,L129) 



SCELL1: LINE=(CELL1,CELL2,CELL3,CELL4,CELL5)
SCELL2: LINE=(CELL6,CELL7,CELL8,CELL9,CELL10)
SCELL3: LINE=(CELL11,CELL12,CELL13,CELL14,CELL15)
SCELL4: LINE=(CELL16,CELL17,CELL18,CELL19,CELL20)
SCELL5: LINE=(CELL21,CELL22,CELL23,CELL24,CELL25)
SCELL6: LINE=(CELL26,CELL27,CELL28,CELL29,CELL30)
SCELL7: LINE=(CELL31,CELL32,CELL33,CELL34)

FCELL: LINE=(SCELL1, SCELL2, SCELL3, SCELL4, SCELL5, SCELL6, SCELL7)



USE, FCELL
!SELECT, FLAG=ERROR,CLASS=QUADRUPOLE
!EFIELD,DKLR=0.00*GAUSS()
SELECT, FLAG=ERROR, CLEAR
!SELECT, FLAG=ERROR,CLASS=RBEND
!EFIELD,DBLR=0.001*TGAUSS(2.5)



SURVEY, TAPE, X0=10000.000000, Y0=2000.046000, Z0=19881.174844, & 
THETA0=0.0, PHI0=0.0


SELECT, OPTICS,CLASS=RBEND ! RANGE=#S/#E
OPTICS,FILENAME="optics",BETX=2.377, ALFX=-0.0,MUX=0.0,&
BETY=13.453,ALFY=-0.0,X=0.00,Y=-0.00, &
COLUMNS=NAME,KEYWORD,S,L,BETX,MUX,DX,DPX,X,PX

SELECT, OPTICS, CLEAR
SELECT, OPTICS,CLASS=MONITOR ! RANGE=#S/#E
OPTICS,FILENAME="bpm.dat",BETX=2.377, ALFX=-0.0,MUX=0.0,&
BETY=13.453,ALFY=-0.0,X=.001,Y=-0.001, &
COLUMNS=NAME,KEYWORD,S,BETX,ALFX,MUX,X, BETY,ALFY,MUY,Y

SELECT, OPTICS, CLEAR
SELECT, OPTICS,CLASS=HKICKER ! RANGE=#S/#E
OPTICS,FILENAME="dxcorrectors.dat",BETX=2.377, ALFX=-0.0,MUX=0.0,&
BETY=13.453,ALFY=-0.0,X=.001,Y=-0.001, &
COLUMNS=NAME,KEYWORD,S,BETX,ALFX,MUX,X, BETY,ALFY,MUY,Y

SELECT, OPTICS, CLEAR
SELECT, OPTICS,CLASS=VKICKER ! RANGE=#S/#E
OPTICS,FILENAME="dycorrectors.dat",BETX=2.377, ALFX=-0.0,MUX=0.0,&
BETY=13.453,ALFY=-0.0,X=.001,Y=-0.001, &
COLUMNS=NAME,KEYWORD,S,BETX,ALFX,MUX,X, BETY,ALFY,MUY,Y




TWISS,BETX=2.377, ALFX=-0.0,BETY=13.453,ALFY=-0.0,&
X=0.00,Y=-0.00,TAPE,SAVE

setplot post=2 xsize=24 ysize=16 ascale=1.5 rscale=1.5
PLOT, HAXIS=S, VAXIS1=BETX, BETY, RANGE=#S/#E, STYLE=100
PLOT, HAXIS=S, VAXIS1=DX,DY,   RANGE=#S/#E, STYLE=100
PLOT, HAXIS=S, VAXIS1=X,Y,   RANGE=#S/#E, STYLE=100




STOP