Plotting Beam Emittance with MATLAB Code

In summary, The conversation is about writing a simple code to plot the beam emittance using MATLAB. The code is not working properly and the individual is seeking help to identify the error. The code involves calculating the momentum of the reference particle and plotting the distribution of particles in velocity and position. Some variables, such as v and A, are checked but the plot is not as expected. The individual is concerned about a straight line in the x-vx plot and is seeking further assistance.
  • #1
1Keenan
101
4
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?

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,'.')
 
Physics news on Phys.org
  • #2
It's not working properly
What is wrong?

Did you check variables like v? Your protons are non-relativistic, you can check their speed with a non-relativistic calculation.
What is A?
The sin of something will never give you an angle. Do you mean the arcsin there?
 
  • Like
Likes 1 person
  • #3
I check variables and their dimensions. I try with classic and relativistic formulas... what is wrong is the plot. Only the Vx-Vy plot seems to be ok.

The sin was wrong, you are right, but actually nothing change as I hav very small angles...
 

Attachments

  • untitled.jpg
    untitled.jpg
    33.1 KB · Views: 433
  • #4
Looks like an odd distribution of your particles, unrelated to your code.
Your code just scales everything in A.
 
  • #5
I don't know, the particles should be distributed around a circle.
I have the right prifile in xy ad vx-vy, but in the x-vx I have a straight line.
What I sent you is what I get in the focal point of a quadrupole
 
  • #6
I would not expect lines at all - you should have a 2D-distribution, otherwise your phase space volume is zero.
There is nothing fundamentally wrong with a v_x,x-distribution that is very stretched. It just means you have to focus in that direction again.
 
  • #7
The v_x,x distribution is not stretched, it is a line in my plot... that's why I'm concerned...
 

1. What is "Plotting Beam Emittance with MATLAB Code"?

"Plotting Beam Emittance with MATLAB Code" is a method used by scientists to visualize the emittance of a charged particle beam. Emittance is a measure of the spread of particles in a beam, and plotting it can help researchers understand the properties and behavior of the beam.

2. How is "Plotting Beam Emittance with MATLAB Code" useful in scientific research?

By plotting beam emittance with MATLAB code, scientists can analyze the properties of a particle beam and make informed decisions about how to optimize its performance. This can lead to more accurate and efficient experiments, as well as a better understanding of the underlying physical processes.

3. What is MATLAB code and why is it used for plotting beam emittance?

MATLAB (MATrix LABoratory) is a high-level programming language and interactive environment commonly used in scientific research. It offers powerful tools for data analysis and visualization, making it well-suited for plotting beam emittance. Its user-friendly interface and extensive library of functions make it a popular choice among scientists.

4. How do scientists obtain the data needed for "Plotting Beam Emittance with MATLAB Code"?

The data for plotting beam emittance can be obtained through various methods, depending on the experiment. One common method is through the use of sensors that measure the position and energy of particles in a beam. This data is then processed and input into MATLAB code for visualization.

5. Are there any limitations to "Plotting Beam Emittance with MATLAB Code"?

While plotting beam emittance with MATLAB code can provide valuable insights, it is important to note that the accuracy of the results depends on the quality of the data and the assumptions made in the analysis. Additionally, the code may need to be modified for different experimental setups, making it a time-consuming process.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • Advanced Physics Homework Help
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • Introductory Physics Homework Help
Replies
8
Views
1K
Back
Top