ocelot-collab / ocelot

OCELOT is a multiphysics simulation toolkit designed for studying FEL and storage ring-based light sources.
GNU General Public License v3.0
84 stars 56 forks source link

Angular coordinate inconsistency? #143

Open jonasbjorklundsvensson opened 2 years ago

jonasbjorklundsvensson commented 2 years ago

Hi,

I have some trouble working out the angular coordinates in the code. On the one hand, it is stated literally in various placed in the documentation that it is the angles x' and y' that are being used, but both the input of generate_parray and the output p_array from tracking have the coordinates px and py, implying the normalized momenta.

When I use the p_array.px and p_array.py output and calculate for example the slice normalized emittance, assuming that these coordinates are the angles x' and y', it matches (more or less) what I see when plotting with show_e_beam(). If I use them as normalized momenta, I get completely wonky values.

I have a similar (and probably related) problem with the bunch generation - I specify transverse coordinates and Twiss functions, but can never seem to achieve the same normalized emittance that I specify my bunch to have when calculating the rms values using the nominal input Twiss parameters. I tried various combinations of angles and momenta and the closest I can get is within a factor of 4, which seems quite random.

Would much appreciate some input in this matter! Best regards, Jonas

sergey-tomin commented 2 years ago

HI Jonas,

Ocelot uses almost the same coordinate system as MAD8, except for the sign in the 5th coordinate. Thus: x' = px/p0 and y' = py/p0. A description of the coordinate system can be found in tutorial N2
https://nbviewer.org/github/ocelot-collab/ocelot/blob/master/demos/ipython_tutorials/2_tracking.ipynb

I think we need to move it to a more prominent place. Cheers, Sergey.

jonasbjorklundsvensson commented 2 years ago

Hi Sergey, and thanks for the quick reply!

This is indeed one of the locations I am referring to and the one that I was using originally. I realized that I could attach some figures to make myself more clear. Here is a screenshot of what I can see in Spyder when I look at the generate_parray function - the "angular" coordinate px is literally referred to as canonical momentum (i.e., not an angle).

image

And when similarly taking a look at how one of the output p_arrays look, one can see the field px, for example.

image

In the p_array description it says the same, usual definition that you give here as well, using px and py as transverse normalized momenta. However, the fields in p_array are still called for example p_array.px, but I take it that this is not actually px but "xp"? How should I interpret the px in the generate_parray function?

And with respect to your last remark - as a newcomer to the code I can vouch that some more documentation and/or consolidation of information would help a lot. Best regards, Jonas

sergey-tomin commented 2 years ago

Ocelot uses canonical momentums. So everywhere it should be px and py. in description I wrote x'=px/p0 just to describe second variable of the canonical pair. But I agree it should be written more transparent maybe like px = Px/P0. I will change it in future.