Hi,
I want to write a very simple code to plot the beam emittance knowing x,y,z and vx,vy,vz of each particle.
I have generated with a tracking code a very simple beam (cone distribution with 1° divergence) and I want to compare the emittance of this beam with the one calculated by a different code.
I'm using matlab and this is the code I have written. It's not working properly, but I'm not able to spot the error. COuld you please help me?
I want to write a very simple code to plot the beam emittance knowing x,y,z and vx,vy,vz of each particle.
I have generated with a tracking code a very simple beam (cone distribution with 1° divergence) and I want to compare the emittance of this beam with the one calculated by a different code.
I'm using matlab and this is the code I have written. It's not working properly, but I'm not able to spot the error. COuld you please help me?
Code:
A= Vel ; %%%Vel is a matrix of n rows and columns: [x,y,z,vx,vy,vz]
%%%%% evaluate the momentum of the reference particle
c=3e8; %[m/s] light speed
e=1.602176e-19; %[C] electron charge
E0=938.27; %[MeV] proton rest energy
M0=E0/c^2; %[MeV/c^2] proton rest mass
mkg=M0*10^6*e; %[kg] mass in kg e
T=5; %[MeV] Kinetic energy (it is a monochromatic beam)
Etot= E0+T; %Total Energy
gamma = Etot/E0; %gamma relativistic
beta= sqrt( 1 - (1/gamma^2)); %beta relativistic = v/c
v=beta*c;
%%%%% momentum (not taking in account particle mass%%%%
V0=v*gamma;
angX=sin(A(:,4)./V0); %%%angle in radians
angX=angX.*10^3; %%% angle in mradians
figure()
plot(A(:,1),angX,'.')
angY=sin(A(:,5)./V0); %%%angle in radians
angY=angY.*10^3; %%% angle in mradians
figure()
plot(A(:,2),angY,'.')