OPTION, ECHO=FALSE;
OPTION, INFO=TRUE;
OPTION, VERSION=10900;
OPTION, STATDUMPFREQ=1;
OPTION, PSDUMPFREQ=1000000;

REAL NProt = 1000000;

REAL DT_ = 1e-12;

REAL Edes = 0.07381;
REAL gamma = (Edes+PMASS)/PMASS;
REAL beta = sqrt(1-(1/gamma^2));
REAL gambet = gamma*beta;
REAL P0 = gamma*beta*PMASS;

VALUE,{gamma,Edes,beta,gambet};
REAL rf = 50.6328e6;


REAL fact_x  =1.400;
REAL fact_xd =1.40;
REAL fact_y  =1.400;
REAL fact_yd =1.40;
REAL fact_delp=2.30;


//--------------------------------------------------------------------------------
//Input beam parameters    AT STEP 474, SPOS 31.5926
//--------------------------------------------------------------------------------
DISTRIB1: DISTRIBUTION,
	TYPE=GAUSS,
//Energy MeV =  73.6503
	SIGMAX = 0.00253256*fact_x,     SIGMAPX = 0.00231138*gambet*fact_xd  ,
	SIGMAY = 0.00938593*fact_y,     SIGMAPY = 0.00161825*gambet*fact_yd ,
	SIGMAZ = 0.00970918*0.000001,      SIGMAPZ = 0.00171298*gambet*fact_delp  ,
	CORRX =  0.858145,       CORRY =  0.967638,      CORRZ =  0.999981,
	R51 =  -0.00957565,      R52 =  0.103166,        R61 =  -0.0074746,      R62 =  0.105198,

	CUTOFFX = 5, CUTOFFPX = 5, CUTOFFY = 5,
	CUTOFFPY = 5, CUTOFFLONG = 5, CUTOFFPZ = 5,
	OFFSETX = 0, OFFSETY =0, OFFSETZ = 0,
	INPUTMOUNITS = NONE;


//--------------------------------------------------------------------------------
// Beamline elements
//--------------------------------------------------------------------------------
MMBHL02: FLEXIBLECOLLIMATOR, FNAME="test2.txt", L=0.04, ELEMEDGE=32.432;
MON1: MONITOR, ELEMEDGE=32.472;

//--------------------------------------------------------------------------------
// Define Beamline
//--------------------------------------------------------------------------------
BEAMLINE_: LINE=(
MMBHL02,
MON1
);



//--------------------------------------------------------------------------------
FS1:FIELDSOLVER, FSTYPE=NONE,
                 MX=64, MY=64, MT=64,
                 PARFFTX=true, PARFFTY=false, PARFFTT=false,
                 BCFFTX=open, BCFFTY=open, BCFFTT=open,
                 BBOXINCR=1, GREENSF=STANDARD;

BEAM_: BEAM, PARTICLE=PROTON, PC=P0, NPART=NProt, BCURRENT=NProt*1.6e-19*rf, BFREQ=rf,  CHARGE=1;


REAL STEP02= 100./(beta*CLIGHT*DT_);
SELECT, LINE=BEAMLINE_;
TRACK, LINE=BEAMLINE_, BEAM=BEAM_, MAXSTEPS= STEP02, DT=DT_, ZSTART=32.0, ZSTOP=33.20;

RUN, METHOD = "Parallel-T", BEAM=BEAM_, FIELDSOLVER=FS1, DISTRIBUTION=DISTRIB1;
ENDTRACK;



STOP;