{Derived from Vadim's Dec 9th 2013 e-mail, optimal lattices doubled in energy for 20GeV
Combined function magnets implemented as offset quads.}

#QLF=1.1;
#BLD=0.9;

#RADQF=293.945;
#RADBD=298.569;
#RIGIDITY1=3e9/299792458; // Rigidity at 3GeV (FFAG1)
#RIGIDITY2=8.2e9/299792458; // Rigidity at 8.2GeV (FFAG2)

{Multipole Length Angle Quad Xhere Fringe AlignMode}
QF1 #QLF# #QLF/RADQF# #2*-6# #RIGIDITY1/RADQF/-6# 3cm Integral
BD1 #BLD# #BLD/RADBD# #2*6.5# #RIGIDITY1/RADBD/6.5# 3cm Integral
QF2 #QLF# #QLF/RADQF# #2*-29.3# #RIGIDITY2/RADQF/-29.3# 3cm Integral
BD2 #BLD# #BLD/RADBD# #2*28.1# #RIGIDITY2/RADBD/28.1# 3cm Integral

{Drift Length Angle}
D 0.290943623
HD #D.Length/2#

ArcCell1: HD,BD1,D,QF1,HD;
ArcCell2: HD,BD2,D,QF2,HD;

{MatchScan Estart Egoal Estep Species FOM SR_TopEnergy SR_Current SR_Length}
Match1 #2*3.644#GeV #2*0.92#GeV #2*0.908#GeV Electron SR 20GeV -50mA #6*356.30044#m
Match2 #2*10#GeV #2*4.552#GeV #2*0.908#GeV Electron SR 20GeV -50mA #6*356.30044#m

{Match-Aperture} 
MatchEnd  

{Particle Species Energy X vx vz Trail}
P20000 Electron 20000MeV -0.00274306664 0.00117871615 1 -1	   
P18184 Electron 18184MeV -0.00128023755 0.000605727602 1 -1	   
P16368 Electron 16368MeV 0.0000409510892 -0.0000215758938 1 -1	   
P14552 Electron 14552MeV 0.00119914928 -0.000711253586 1 -1	   
P12736 Electron 12736MeV 0.002168426 -0.00147300143 1 -1	   
P10920 Electron 10920MeV 0.00291692189 -0.00231854823 1 -1	   
P9104 Electron 9104MeV 0.00340492711 -0.00326210576 1 -1	 
ArcCell2Particles:P20000,P18184,P16368,P14552,P12736,P10920,P9104;
P7288 Electron 7288MeV -0.00833026607 0.00212054021 1 -1	   
P5472 Electron 5472MeV 0.00289261202 -0.000981800053 1 -1	   
P3656 Electron 3656MeV 0.00970162073 -0.00493235813 1 -1	   
P1840 Electron 1840MeV 0.00996473337 -0.0101196216 1 -1	 
ArcCell1Particles:P7288,P5472,P3656,P1840;

global_bore=100km #// Because of V3 element
{Drift Length Angle Twist}
V1 0 0 90
V2 0 -90
V3 20cm
V4 0 90
V5 0 0 -90

VerticalSeparation:V1,V2,V3,V4,V5;

#//Match1,ArcCell1,MatchEnd,Match2,ArcCell2,MatchEnd;
#//ArcCell1Particles,ArcCell1,MatchEnd,HD,ArcCell2Particles,ArcCell2,MatchEnd;
Match2,ArcCell2,MatchEnd;