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 58 forks source link

Loading electron beam information from file #171

Closed hnakahara79 closed 1 year ago

hnakahara79 commented 1 year ago

Dear Developers,

I have run most of the tutorials and partially understanding how Ocelot can be used for different purposes. Although, most of the tutorials were done with particular beam format, they were very useful to understand many applications of the Ocelot.

Now, I would like to come back to my problem. I have an electron beam with informations of:

(1) x-position (2) y-position (3) z-position (4) Px, x-momentum (5) Py, y-momentum (6) Pz, z-momentum (7) Particles weight

The electron beam information is in the text-file with 7 columns.

I have to study the transportation of this beam with beam-optics (Quadrupoles).

Please, could you guide me how I can load such file and make some test.

Thank you very much.

st-walker commented 1 year ago

Well done for making it through the tutorials.

I have to study the transportation of this beam with beam-optics (Quadrupoles).

OK but do you, for example, need collective effects or are only interested in tracking without collective effects? And when you say study: what do you mean? What are you trying to learn? Are you trying to optimise the beamline in some way? What is the beam energy? Where did you get the particle file from, is it Astra? We have loaders for a range of different file formats but not all of them, you might have to write your own loader, because we can only support file formats that we know about. Look in ocelot/adaptors and maybe the loader you want will be there. If it's not you will have to write your own file loader, in which case look at the definition of the ParticleArray class in ocelot/cpbd/beam.py. You can see the class definition inside and what the coordinate convention used is. This should ultimately be enough using np.loadtxt to make progress.

hnakahara79 commented 1 year ago

Dear @st-walker, thank you for your reply. I will need collective effects in my study.

When I say study this means that I have an electron bunch with certain distribution in space (or phase-space) and I need to transport this electron bunch up to the undulator. We are generating electron beam via laser wakefield acceleration mechanism and trying to send it through the undulator.

In the experiments, we generate electron beams via LWFA mechanism. We did several PIC simulations (using the experimental interaction conditions) and can reproduce similar electron beams (energy, energy spread and divergence all are in quite good agreement with experimental results).

Now, using the electron beams parameters from the simulation, we want to design a beam line.

I am very happy to write my own loader, but this may require some initial help from you. I am also checking the definition of the ParticleArray class in ocelot/cpbd/beam.py, as you suggested.

Besides, in tutorial N3 Space charge, I noticed that txt file format can be loaded

sa, bx_sc, by_sc, bx_wo_sc, by_wo_sc = np.loadtxt("astra_sim.txt", ............. )

My question is:

(1) What kind of information of an electron beam is required for Ocelot and in which units (SI, CGS or normalized).

I am trying to understand ParticleArray class in ocelot/cpbd/beam.py, but may require time to fully understand it.

Thank you very much.

st-walker commented 1 year ago

What kind of information of an electron beam is required for Ocelot and in which units (SI, CGS or normalized).

information of an electron beam is required for Ocelot

look in beam.py, the class ParticleArray, you can see there.

Or also look in this demo for more about units:

https://nbviewer.org/github/ocelot-collab/ocelot/blob/master/demos/ipython_tutorials/2_tracking.ipynb

x and y are in metres, they are in the normal accelerator curvilinear coordinate system that we all enjoy

I am trying to understand ParticleArray class in ocelot/cpbd/beam.py, but may require time to fully understand it.

How much experience with Python do you have?

hnakahara79 commented 1 year ago

Thank you @st-walker. Your suggestions are very helpful.

I am comfortable with python. Although I am not a very heavy user of it, but I am gradually shifting from c++ and Matlab to python.

I will follow your suggestions and will let you know if I will get stuck somewhere.

Thank you once again.

alexanatoly commented 1 year ago

Dear @st-walker ,

I tried to load an electron beam in Ocelot from a text file.

I believe I can load the file, but now I will need your help to check and to learn how I can proceed further.

Please, could you check the attached file and suggest me how I can proceed further.

Thank you for kind help.

alexanatoly commented 1 year ago

Dear @st-walker ,

I am colleague of @hnakahara79 and we are trying together to try to load an electron beam from text file.

Therefore, I sent the above message so that I can also get into the discussion loop.

Please, could you check the above script file and let us know if we are on the right track or not ?

Thanks Alex

st-walker commented 1 year ago

I don't know what to say exactly. There is no text file in the zip.

Personally I would convert to ASTRA file format (from whatever you have) and load into ocelot using astraBeam2particleArray in ocelot.adaptors.astra2ocelot.

The file format is described in great details in the manual on page 2:

https://www.desy.de/~mpyflo/Astra_manual/Astra-Manual_V3.2.pdf

That is what I would do if I didn't know anything about OCELOT, but can read the ASTRA manual.

alexanatoly commented 1 year ago

Dear @st-walker ,

I am sending you the script file once again. Please, see the attachment. (Python file can not be uploaded, therefore, I am sending in the .txt file).

The beam data file size is 28 MB but only up to 25 MB can be upload in GitHub. If you don't mind I can send you the data file by email. Please, could you send me your email id.

Please, let us know.

Thanks, Alex

Load_txt_file_test.txt

st-walker commented 1 year ago

I am not going to load some random file from someone on the internet that I don't know.

Is it correct? Not sure. I don't know what you expect or what your beam is supposed to be. Nothing bad stands out to me in the code that is "obviously wrong", but also it's not easy to just look at a large script and go "yes this is correct". I would, as I say before, just convert it to ASTRA format, where the beam average direction should point along the z-axis:

Screenshot 2023-09-02 at 19 16 51

The manual:

https://www.desy.de/~mpyflo/Astra_manual/Astra-Manual_V3.2.pdf

This is very easy to do. At worst you may have to rotate your beam so it points along z.

Then use the function astraBeam2particleArray in ocelot.adaptors.astra2ocelot.

Then you will have a ParticleArray instance that is correct.

st-walker commented 1 year ago

Perhaps @sergey-tomin can chip in with some expertise, he is the main author of OCELOT.

alexanatoly commented 1 year ago

Hi @st-walker ,

Thanks for your frank opinion and also thanks a lot for suggesting ASTRA file format.

We work on your suggestion, and it looks quite straight forward to load the electron beam in Ocelot.

We have uploaded the input beam and the beam parameters (or results) obtained from Ocelot (please see the attachment).

Now, we are exploring more plotting option (or functions) in Ocelot to proceed further.

Thanks for all your kind discussions.

Alex and @hnakahara79

Astra2Ocelot_result.pdf

st-walker commented 1 year ago

OK looks reasonable. All I would say is that if indeed you exactly create a file in ASTRA file format, then you will be OK. The ASTRA file loade is used every day for EuXFEL OCELOT simulations so it is certainly correct. I hope I have been able to help you.