mm = 1e-3;
MHz = 1e6;

#========================================================
#  difinition: initial condition of electorn beam
#========================================================
Energy=100e+3;         # beam energy [MeV]

G=1-qe*Energy/(me*c^2);

setparticles("beam",50000,me,qe,-1e-9);
setrxydist("beam","u", 1.25*mm, 2.5*mm);
setphidist("beam","u", 0, 2*pi);
setzdist("beam","u", -287*mm/2, 287*mm);
setGBrxydist("beam","u",0, 0);
setGBphidist("beam","u",0, 0);
setGdist("beam","u",G, 0);


#=========================================================
# TW Acelerating Structure 
#       2013.8.15  23:11:4
#       data dir   : ./
#       input data : TW_structure.dat
#==========================================================

facc  = 2856*MHz;                      # Operating freq. [Hz]
omega = 2*pi*facc;
StrZ  = 100;                           # start point [mm]
StrP  = 30;                            # initial phase [deg]

#----- SW region -------
map25D_TM("wcs", "z", (StrZ-39.746)*mm, "../TW/TW_structure_inSW.gdf", "R", "Z", "Er", "Ez", "H", -3.730944e+000, 0, (StrP+0.00)/deg, omega);
rmax("wcs", "z", (StrZ-24.746)*mm, 10.000*mm, 30.000*mm);
#----- cell #01 -------
map25D_TM("wcs", "z", (StrZ+0.000)*mm, "../TW/TW_structure_01_SS.gdf", "R", "Z", "Er", "Ez", "H", 6.132265e+000, 0, (StrP+0.00)/deg, omega);
map25D_TM("wcs", "z", (StrZ+0.000)*mm, "../TW/TW_structure_01_OO.gdf", "R", "Z", "Er", "Ez", "H", -5.796206e+000, 0, (StrP-90.00)/deg, omega);
rmax("wcs", "z", (StrZ+12.246)*mm, 11.000*mm, 5.000*mm);
#----- cell #02 -------
map25D_TM("wcs", "z", (StrZ+24.493)*mm, "../TW/TW_structure_02_SS.gdf", "R", "Z", "Er", "Ez", "H", 6.577072e+000, 0, (StrP-120.00)/deg, omega);
map25D_TM("wcs", "z", (StrZ+24.493)*mm, "../TW/TW_structure_02_OO.gdf", "R", "Z", "Er", "Ez", "H", -6.156720e+000, 0, (StrP-210.00)/deg, omega);
rmax("wcs", "z", (StrZ+38.489)*mm, 10.950*mm, 5.000*mm);
#----- cell #03 -------
map25D_TM("wcs", "z", (StrZ+52.485)*mm, "../TW/TW_structure_03_SS.gdf", "R", "Z", "Er", "Ez", "H", 6.953617e+000, 0, (StrP-240.00)/deg, omega);
map25D_TM("wcs", "z", (StrZ+52.485)*mm, "../TW/TW_structure_03_OO.gdf", "R", "Z", "Er", "Ez", "H", -6.456409e+000, 0, (StrP-330.00)/deg, omega);
rmax("wcs", "z", (StrZ+68.231)*mm, 10.900*mm, 5.000*mm);
#----- cell #04 -------
map25D_TM("wcs", "z", (StrZ+83.976)*mm, "../TW/TW_structure_04_SS.gdf", "R", "Z", "Er", "Ez", "H", 7.275100e+000, 0, (StrP-360.00)/deg, omega);
map25D_TM("wcs", "z", (StrZ+83.976)*mm, "../TW/TW_structure_04_OO.gdf", "R", "Z", "Er", "Ez", "H", -6.706165e+000, 0, (StrP-450.00)/deg, omega);
rmax("wcs", "z", (StrZ+101.471)*mm, 10.850*mm, 5.000*mm);
#----- cell #05 -------
map25D_TM("wcs", "z", (StrZ+118.966)*mm, "../TW/TW_structure_05_SS.gdf", "R", "Z", "Er", "Ez", "H", 7.297176e+000, 0, (StrP-480.00)/deg, omega);
map25D_TM("wcs", "z", (StrZ+118.966)*mm, "../TW/TW_structure_05_OO.gdf", "R", "Z", "Er", "Ez", "H", -6.726994e+000, 0, (StrP-570.00)/deg, omega);
rmax("wcs", "z", (StrZ+136.461)*mm, 10.800*mm, 5.000*mm);
#----- cell #06 -------
map25D_TM("wcs", "z", (StrZ+153.956)*mm, "../TW/TW_structure_06_SS.gdf", "R", "Z", "Er", "Ez", "H", 7.318745e+000, 0, (StrP-600.00)/deg, omega);
map25D_TM("wcs", "z", (StrZ+153.956)*mm, "../TW/TW_structure_06_OO.gdf", "R", "Z", "Er", "Ez", "H", -6.744383e+000, 0, (StrP-690.00)/deg, omega);
rmax("wcs", "z", (StrZ+171.451)*mm, 10.750*mm, 5.000*mm);
#----- cell #07 -------
map25D_TM("wcs", "z", (StrZ+188.946)*mm, "../TW/TW_structure_07_SS.gdf", "R", "Z", "Er", "Ez", "H", 8.480126e+000, 0, (StrP-720.00)/deg, omega);
map25D_TM("wcs", "z", (StrZ+188.946)*mm, "../TW/TW_structure_07_OO.gdf", "R", "Z", "Er", "Ez", "H", -7.771091e+000, 0, (StrP-810.00)/deg, omega);
rmax("wcs", "z", (StrZ+206.441)*mm, 10.000*mm, 5.000*mm);
#----- SW region -------
map25D_TM("wcs", "z", (StrZ+223.936)*mm, "../TW/TW_structure_outSW.gdf", "R", "Z", "Er", "Ez", "H", -5.989323e+000, 0, (StrP-840.00)/deg, omega);
rmax("wcs", "z", (StrZ+253.931)*mm, 10.000*mm, 30.000*mm);


#========================================================
# beam control
#========================================================
zminmax("wcs", "I", -300*mm, 410*mm);
rmax("wcs","I", 30*mm);
screen("wcs", "I", 0.5*mm, 400*mm, 1*mm);
