Closed dmargarone closed 4 months ago
Hi,
I did not use plt.scatter for awhile but I think it is correct. you can also use function show_density(x, y) function in from ocelot.gui.accelrator (https://github.com/ocelot-collab/ocelot/blob/master/ocelot/gui/accelerator.py)
Cheers, Sergey.
Hi @sergey-tomin
show density gave me different result than the expected one
Do you expect them to be the same? Look at the code of show_density
, it is very basic matplotlib stuff. There's not much room for error unless it is somehow related to comparing histograms to scatter plots (one is binning the other is not). otherwise the problem cannot be in plotting.
Hi @st-walker,
Thanks a lot for your kind reply. Even scatter plot
gives the same result as obtained with show_density
.
I made plot with
X = p_array_init.x()
Px = p_array_init.px()
plt.scatter(X, Px, c=Px, s=3)
I am expecting that the x-Px plot should show a tilt. I used the following electron beam distribution:
p_array_init = generate_parray(sigma_x=20.0e-6, sigma_y=20.0e-6, sigma_tau=0.6e-3,
sigma_px=5.1e-4, energy=0.055, sigma_p=3.0e-3, chirp=0.008,
nparticles=20000, charge=500.0e-12)
Hi, why you are expecting tilt? scatter and show_density show the same result. There is no correlation between x and px. Function generate_parra() would introduce correlation in transverse plane if Twiss parameters are defined. But if chirp is not zero you can see correlation in longitudinal phase space (tau-p).
Hi @st-walker,
Here is the reason why I was expecting a tilt in the x-px plot. I found a literature about beam compression and I was trying to see if I can reproduce some of the results or not. I have attached the literature file. I was trying to make similar figures like Fig. 2.22, Fig. 2.23, Fig. 2.24 and Fig. 2.25.
Hi @st-walker,
did you see anything wrong in Fig. 2.22, Fig. 2.23, Fig. 2.24 and Fig. 2.25. in the beamcompression.pdf file. All these plots are generated with ELEGANT code. I tried to reproduce these figures.
OK but where is the data for the plot coming from? Do you have the beam data file for the same plot as 2.22?
you say you are trying to reproduce a result, but the plot is just an "initial phase space"? So there is no result, it is the input, nothing has happened yet I would imagine. I did not look at the pdf very closely though.
I don't understand why you expect your plot to match the 2.22 of the pdf, unless you have the same data file.
Hi @st-walker ,
the initial parameters are given in Table 2.6 (energy and charge are same through out the simulation: E = 55 MeV and charge 0.5 nC, as given in Table 2.2).
The momentum chirp for figures 2.22-2.30 is 10 per meter.
Then your problem is that you are somehow not generating the bunch properly from Table 2.6.
Is this the code you are using? If so, it is clear to me that it will not do it correctly:
p_array_init = generate_parray(sigma_x=20.0e-6, sigma_y=20.0e-6, sigma_tau=0.6e-3,
sigma_px=5.1e-4, energy=0.055, sigma_p=3.0e-4, chirp=0.008,
nparticles=20000, charge=500.0e-12)
You need to set the tws
kwarg to make sure that the correlations are computed correctly when generating the beam from the Twiss parameters.
Alternatively use cov_matrix_from_twiss
and cov_matrix_to_parray
from the cpbd.beam module together (I wrote these two functions so I am confident that they work).
Hi @st-walker,
thank you so so much for helping. I am trying to understand these ,but I received an error: name 'ex' is not defined
. Please, could you suggest me how to fix this error.
yeah you need to define ex, which is the geometric emittance. eg is the geometric emittance.
just write ex = ey = eg underneath the eg definition and itll work i guess or at least crash later on
Hi @st-walker,
Thank you. I will proceed as you suggested. Hope I can learn something today.
Hi @st-walker,
does parray0s
is the initial beam distribution ?
If I want to see into it with print(parray0s)
it gives <ocelot.cpbd.beam.ParticleArray object at 0x1360d1810
.
ok but what is in the interesting_bunch_lengths?
parray0s is a list, it cnanot give what it says you give.
you can plot each one, you can track each one.. it is up to you. if you only want one remove the list comprehension and just pick a single constant sigma_tau.
Hi @st-walker
I want to creat a particle array from twiss parameters given above. If I do print(np.size(parray0s))
it gives me the correct value equal to nparticles
.
When I used the p_array_init = generate_parray( ...... )
I can directly print the p_array_init
values. And can use the p_array_init
for further analysis.
But here, I got stuck after that.
yes in Python [x for x in Y]
notation is a list comprehension, so here parray0s
is a list.
Hi @st-walker
I couldn't get it well. But let me try, if I fail I will return back to you.
good luck, to be honest, it seems some of these questions are not ocelot questions but rather Python questions. if you sit with repl (i recommend ipython) all day and go line by line I am sure you will figure it all out and learn a lot.
Hi @st-walker
I think I have a good news to share with you. Finally, I am able to reproduce the tilted figures.
All credit goes to you. You are so helpful and kind. A very big thanks to you.
Now, only one thing is remaining. How to include energy or momentum chirp
?
How to include energy or momentum chirp
You have the particle array, you have the longitudinal positions of the particles parray.tau()
and you have the momentum offsets of the particles parray.p()
so you need to just modulate the last row (the momentum) of the parray.rparticles
array based on each particle's longitudinal position (the second from last row of parray.rparticles
).
Hi @st-walker,
although the concept is simple (p = p0 + chirp*tau), this part looks confusing to me. Anyways, I will try and if I get completely messed up, I may need your advice again.
Hi @st-walker,
Maybe now I could follow your suggestion. I could make the figures as expected. Also, this means p_array_init.rparticles re-present total phase space (x, px , y, py, tau, p) .. is it right ?
Hi @st-walker @sergey-tomin ,
Thank you so much to both of you for being so kind and helpful every time.
with lots of best wishes, Daniela
Dear All,
I want to make a plot of x-px.
Do you think the commands below is correct for making such plots ?
Thank you. Daniela