Plotting Beam Emittance with MATLAB Code

Click For Summary

Discussion Overview

The discussion revolves around a MATLAB code intended to plot beam emittance based on particle parameters (x, y, z, vx, vy, vz). Participants are troubleshooting issues with the code's output, specifically focusing on the distribution of particles in the plots generated.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks assistance with a MATLAB code for plotting beam emittance, describing the parameters and the expected output.
  • Another participant questions the validity of the variables used, suggesting that the protons may be treated as non-relativistic and asking for clarification on the variable A.
  • Concerns are raised about the use of the sine function, with a suggestion that arcsin might be more appropriate, although the original poster notes that the angles are small.
  • A participant observes that the particle distribution appears odd and may not be related to the code itself, indicating that the code merely scales the data in A.
  • Another participant expresses confusion about the expected distribution, noting that the particles should cluster around a circle, while the original poster reports a straight line in one of the plots.
  • Further discussion highlights that a line in the v_x,x distribution could indicate a lack of phase space volume, suggesting a need for refocusing in that direction.
  • One participant emphasizes that the v_x,x distribution is not merely stretched but is represented as a line, raising concerns about the implications for the data.

Areas of Agreement / Disagreement

Participants express differing views on the nature of the particle distribution and the implications of the plots generated by the code. There is no consensus on the underlying issues or the proper interpretation of the results.

Contextual Notes

Participants mention the potential for non-relativistic calculations and the need to consider the scaling of variables, but these aspects remain unresolved within the discussion.

1Keenan
Messages
99
Reaction score
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
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   Reactions: 1 person
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 have very small angles...
 

Attachments

  • untitled.jpg
    untitled.jpg
    33.1 KB · Views: 512
Looks like an odd distribution of your particles, unrelated to your code.
Your code just scales everything in A.
 
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
 
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.
 
The v_x,x distribution is not stretched, it is a line in my plot... that's why I'm concerned...
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
6K
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K