ULB-Metronu / georges

Opinionated particle accelerator modeling Python package.
https://ulb-metronu.github.io/georges/
GNU General Public License v3.0
7 stars 8 forks source link

Some usage issues related to Georges. #75

Closed cy1034429432 closed 5 months ago

cy1034429432 commented 6 months ago

I haven't used the relevant software yet, I just skimmed through the tutorials and related papers. I have a few questions about Georges:

  1. Can this software fully seamlessly simulate particle dynamics, including energy reduction? I found that energy degradation and particle motion in a magnetic field are separated in the tutorial.
  2. Is the edge field of the bend still the same as Madx and transport at present? Can't Georges use the Enge function like cosy infinite?
chernals commented 6 months ago

Hi,

Could you share a bit more what you are trying to achieve ?

Regarding your questions:

  1. If you are referring to a case where the particles travel through matter (not vacuum) inside a magnetic field, no this is not supported. I imagine that for these use cases something like Fluka, Geant4/BDsim would be needed.
  2. Yes, there is very limited support for fringe fields. The models are extremely simple (our typical use case is proton therapy beam lines) and we don't support Enge functions. For this you could indeed use cosy infinity or look at Zgoubi (or our Python interface to Zgoubi : Zgoubidoo, also on our Github)
cy1034429432 commented 6 months ago

Hi! Thank you for replying to my message. I am currently building a seamless model for a proton therapy facility, and we have successfully established it using BDSIM. However, due to particle tracking, BDSIM has a slow calculation speed. We would like to replace it with a faster code. Regarding question 1, we only control the energy and quality by controlling the thickness of the graphite block and distance of the energy slit in the vacuum (energy selection system), and then particles reach the treatment nozzle through the beamline. Can this process be fully modeled in Georges?

chernals commented 6 months ago

This was exactly our approach. We have a very detailed model with BDSIM and we used (and developed) Georges for faster tracking and optimisation of the beam line.

Yes, you can insert a "degrader" element for your graphite blocks, the energy will be reduced and the multiple coulomb scattering is modelled in some way. The slits will "kill" particles and you can have the rest of the magnetic elements.

Feel free to share more if you want some support (possibly by email through this paper https://www.sciencedirect.com/science/article/pii/S2352711023002753 )

cy1034429432 commented 6 months ago

Thank you for your answer. I have carefully read the literature you provided. If possible, we hope Georges can add features similar to the Enge function in the future. BDSIM has some inconveniences in importing dipole fields, and we hope to establish a more realistic physical model (considering fringe fields, over-talk effect, and particle-matter collision processes). Also, is it possible to provide a seamless example on the website that includes the energy degradation process and particle transport? Special thanks.

cy1034429432 commented 6 months ago

@chernals Hi, After trying to use Georges, there were a few questions that puzzled me:

  1. According to the example on the relevant website (degrader_properties. gmad, as shown in the below figures), it seems that it cannot be input into BDSIM. Is the uploaded file incomplete? image image
  2. I am puzzled by APERTURE, whether this parameter refers to half the length or the full length.
  3. I checked Georges' online website for the definition of HGAP ([m]), but there are still some issues after entering the unit. image
  4. I can't find an option to set sigmaE.
rtesse commented 6 months ago

Hello, thanks for all the comments. I opened some issues to treat each point separately.

  1. See #76
  2. See #77
  3. I tried your example but I am not able to reproduce the bug. Could you tell me how did you install georges and give me the version of Georges you used ?
  4. This option is currently not available as sigmaP can be computed from sigmaE using the following relation: image

However, this is not a huge amount of work to create a distribution given sigmaE.

I will try to resolve the issues this week. I will also provide an example that includes the energy degradation process and particle transport.

cy1034429432 commented 6 months ago

@rtesse Hi, Thank you for responding to my questions.

  1. I am using pip install georges in the Anaconda environment. image
  2. Does the georges has the ability to set SigmaP(SigmaE or SigmaEk)of initial beam distribution?
rtesse commented 6 months ago

Hello, I created a new release for Georges (2024.1) which is also available on Pypi. I improved the documentation for the aperture and the parameters of (almost) each element. Regarding your issue with the HGAP, could you try your example in a fresh conda environment ?

cy1034429432 commented 6 months ago

@rtesse Hi. I followed your suggestion and downloaded the latest version of Georges in a new Conda environment, but there is still an issue with HGAP. I still had the relevant installation on another computer, and this issue also exists. image S {WDBBY_A6V~%DCY11JJP Also, I have looked over the examples you gave about the energy degrader. I have a question. When the energy of particles changes after the energy degradation, there is a scaling option in BDSIM to adjust the magnets’ parameters downstream of the energy degrader, but it is not available in Georges. Shall we need to manually adjust the magnets’ parameters downstream of the energy degrader?

rtesse commented 6 months ago

Hello, Ok this is strange as I am not able to reproduce the bug. Could you try this MWE and tell me if you still have the issue ? If not, could you post the code as I can debug it on my side ?

import georges
from georges import Element
from georges import ureg as _ureg
B3G2 = Element.SBend('A', L=1*_ureg.m,
                     HGAP=5*_ureg.cm,
                     E1=-0.4346,
                     E2=-0.2889)

Regarding the energy degradation, I have to check but if I remember correctly, you have to manually adapt the magnet's parameters.

cy1034429432 commented 6 months ago

@rtesse Hello, I have sent the simplified code to your email. Regarding the energy degradation, I can adjust the K value of the quadrupole based on the momentum ratio, but the downstream dipole cannot adjust the B value according to the currently provided parameter settings. Bend: {'NAME': 'B1', 'AT_ENTRY': <Quantity(0, 'meter')>, 'AT_CENTER': <Quantity(0, 'meter')>, 'AT_EXIT': <Quantity(0, 'meter')>, 'APERTYPE': None, 'APERTURE': [], 'KINEMATICS': None, 'ANGLE': <Quantity(30, 'degree')>, 'K0': <Quantity(0.0, '1 / meter')>, 'K1': <Quantity(3, '1 / meter 2')>, 'K2': <Quantity(0.0, '1 / meter 3')>, 'L': <Quantity(1, 'meter')>, 'E1': <Quantity(5, 'degree')>, 'E2': <Quantity(0.0, 'radian')>, 'TILT': <Quantity(0.0, 'radian')>, 'HGAP': <Quantity(2, 'centimeter')>, 'FINT': 0.0, 'FINTX': 0.0}

rtesse commented 6 months ago

Hello, I have fixed the bug in the 'develop' branch. As it is an important issue, I will make a new release of Georges once everything is in order. Concerning the energy degradation, you can adjust the strength of the magnet with the parameter $K0 = (1/B\rho) * B_y$

To verify the behavior of the beam, you can use a MeanObserver. You can find below an example with a screenshot of the mean position of the beam along the beamline. As you can see, I have slightly adjusted the default K0 value and the beam is completely offseted.

import georges
from georges import ureg as _ureg
from georges.manzoni.beam import MadXBeam
import matplotlib.pyplot as plt
from georges import vis
from georges.manzoni import Input, observers

d1 = georges.Element.Drift(
 NAME="D1",
 L=2.145 * _ureg.m,
 APERTYPE="CIRCULAR",
 APERTURE=[3.645 * _ureg.cm, 3.645 * _ureg.cm],
)

B3G2 = georges.Element.SBend(
   NAME="B2G2",
   L=1.492 * _ureg.m,
   ANGLE=-90 * _ureg.degrees,
   K1=0 * _ureg.m**-2,
   APERTYPE="RECTANGULAR",
   APERTURE=[5 * _ureg.cm, 2.8 * _ureg.cm],
   HGAP=0.0315 * _ureg.m,
   E1=-0.4346*_ureg.radians,
   E2=-0.2889*_ureg.radians,
   K0 = -0.97*1.0528125514711102/_ureg.m,
   FINT=0.5,
   FINTX=0.5
)

sequence = georges.PlacementSequence(name="Sequence")
sequence.place(d1, at_entry=0 * _ureg.m)
sequence.place_after_last(B3G2)

kin = georges.Kinematics(250 * _ureg.MeV, particle=georges.particles.Proton, kinetic=True)
sequence.metadata.kinematics = kin

beam = MadXBeam(
   kinematics=kin,
   distribution=georges.Distribution.from_twiss_parameters(
      n=1000, x = 2.5 * _ureg.mm,  y=2.5 * _ureg.mm,  emitx=7 * _ureg.mm * _ureg.mradians, emity=7 * _ureg.mm* _ureg.mradians
   ).distribution.values,
)

mi = Input.from_sequence(sequence=sequence)
mi.freeze()
beam_observer_mean = mi.track(beam=beam, observers=observers.MeanObserver())

fig = plt.figure(figsize=(10,4))
ax = fig.add_subplot(111)
manzoni_plot = vis.ManzoniMatplotlibArtist(ax=ax)
manzoni_plot.plot_beamline(sequence.df, with_cartouche=True, print_label=True, with_aperture=True)
manzoni_plot.tracking(beam_observer_mean, plane="X")

plt.show()
image

Another point for the definition of a SBend, you have to set units to the edge angles as follows:

import georges
from georges import Element
from georges import ureg as _ureg
B3G2 = Element.SBend('A', L=1*_ureg.m,
                     HGAP=5*_ureg.cm,
                     E1=-0.4346 * _ureg.radians,
                     E2=-0.2889 * _ureg.radians)
cy1034429432 commented 6 months ago

@rtesse Hello, Thank you for patiently resolving my issue patiently and quickly. If Georges has made any relevant updates, please remind me. I will use some ML technologies combined with the beamline constructed by Georges.

rtesse commented 5 months ago

Hello, I made a new release of georges (2024.2). It fixes the bug you mentioned about the HGAP. I also improve the documentation. Could you tell me if everything goes well ? Is so, could you please close this issue ? Regards. Robin

cy1034429432 commented 5 months ago

@rtesse Hi! I tried the latest version and all the previous bugs were resolved. Thank you so much!!!