# Program to plot longitudinal phase space motion # through a system of cavities (just an example...) Nturns = 100 # Some Parameters Ws = 1.0 # MeV/u phis = 30*pi/180 # synchronous phase angle eV = 0.2 # MeV/u QonA = 0.25 gamma = (931+Ws)/931 beta = sqrt(1-1/gamma^2) eta = -1/gamma^2 h = 1/(beta*3e8/80.5e6) k = 2*pi*h*eta/beta^2*(gamma-1)/gamma/Ws # initialize the phase space plot phi = 0 dW = 0 plot(phi, dW, xlim=c(-180,180), ylim=c(-0.1,0.1), typ="n") trk = 1 while (trk < 16) { # initialize particle positions in phase space u0 <- locator(1) phi <- u0$x/180*pi dW <- u0$y # track the particle... i = 1 while (i < Nturns+1) { phi = phi + k*dW dW = dW + QonA*eV*(sin(phi)-sin(phis)) points(phi*360/2/pi, dW, pch=21,col="red") i = i + 1 } trk = trk + 1 }