bmad-sim / bmad-ecosystem

Bmad simulation ecosystem for simulating high energy storage rings.
https://www.classe.cornell.edu/bmad/
12 stars 13 forks source link

Error using h_misalign for Laue diffraction #1039

Closed luweb closed 3 months ago

luweb commented 3 months ago

Hello, I am trying to implement h_misalign for Laue diffraction and I am getting the following error:   [INFO] bmad_parser: Parsing lattice file(s). This might take a minute or so... [FATAL | 2024-JUL-02 12:07:26] lat_sanity_check: ELEMENT: CRYST1 (3) HAS GRID TYPE H_MISALIGN BUT THIS IS NOT IMPLEMENTED FOR LAUE DIFFRACTION!

I just wanted to double check with you if this is correct and h_misalign is not implemented for Laue diffraction. Is there a workaround?

The reason for using h_misalign is that we think that “b_param” is set to a fixed value for the center photon energy but for a spectrometer it varies with energy. So, perhaps instead it would make sense to set the asymmetry angle, which is fixed for the crystal, if possible.

Thank you for your attention.

DavidSagan commented 3 months ago

@luweb It looks like the problem is that the code was never extended from the Bragg case where the H vector is primarily pointing in the z-direction to the Laue case where the H vector is primarily pointing in the x-direction. I will work on this.

luweb commented 3 months ago

Thank you for looking into this @DavidSagan.

DavidSagan commented 3 months ago

@luweb I modified the code to allow h_misalign with Laue. I also removed the restriction that h_misalign and displacement cannot be used at the same time. Finally, I found and fixed a bug where a surface grid with negative index for the lower bound was not getting handled correctly. This was a substantial modification of the code so I would suggest you make some runs and compare the output of the old code with the new code to make sure no bug has accidentally crept in.

sstoupin commented 2 months ago

Thank you, David. A recipe to calculate rot_y and rot_z can be helpful. We have a reciprocal vector (hx,hy,hz) defined on a crystal surface in local crystal coordinates (origin at center ray). If I use rot_y = arcsin(hz), rot_z = arcsin(hy) to calculate H_Misalign grid and use b_param = 1 I get some sagittal focusing but something is not right: the rays don't cross in the meridional plane where they should (our crystal also has curvature in the meridional plane).

DavidSagan commented 2 months ago

@sstoupin H_misalign misaligns from the H calculated without any misalignment. Also the nominal H is in the negative x-direction so the formula rot_y = -arcsin(hz) is only approximate.