kklmn / xrt

Package xrt (XRayTracer) is a python software library for ray tracing and wave propagation in x-ray regime. It is primarily meant for modeling synchrotron sources, beamlines and beamline elements.
MIT License
84 stars 30 forks source link

isotropic geometric point source #104

Closed leahwang1962 closed 2 years ago

leahwang1962 commented 2 years ago

Hi, Is it possible to build a isotropic point source, which means the point source's projection on a screen will have a flat profile distribution. Thanks.

kklmn commented 2 years ago

Hi, assign ‘flat’ or ‘annulus’ to distxprime and distzprime of GeometricSource.

leahwang1962 commented 2 years ago

Great, it works. Can we display 3 dimensional images, as z will present intensity? Thanks.

kklmn commented 2 years ago

not within xrt. Why intensity as z position is better than brightness?

leahwang1962 commented 2 years ago

Attached are 2 images for similar ray tracing results. The 3D with z as intensity provides subtle details about the beam distribution which can't be clearly shown in xrt's image.

image FSM_Focus

kklmn commented 2 years ago

If you zoom those tiny purple flakes up to the size of the upper 3D surface, you would also see subtle details, wouldn't you? I would make the ranges smaller, increase the number of bins and set ppb=1 (pixel per bin).

leahwang1962 commented 2 years ago

Helped a bit. Thanks

leahwang1962 commented 2 years ago

I need more help for this montel optics. The footprint are not right and I can't correct it. Can you help to find the reason. Thanks Hori _Mirror_Footprint Vert _Mirror_Footprint Colorst_CMF18.5-11.5Cu15.zip .

kklmn commented 2 years ago

Do you see it also wrong in the supplied example?

leahwang1962 commented 2 years ago

The supplied example looks good to me. My optics has much much smaller p and q, I am not sure if it is the reason to cause the problem. In the xrtglow 3D graph, it clearly shows at the mirror entrance there are some "stray" lights from source pass through HVM and reflected by nothing, then pass through VHM and they are counted as double reflection beam to join the focus point; there are some similar "stray" light at mirror exit, and also lights reflected from HMF without incident beam go to screen. I suspect there are also lots of these "stray" lights in the middle part of the mirror and all of them cause the strange footprint on mirrors. I highlighted some "stray" light in the attached images. You can play with the attached mtl file to see the "stray" lights more clearly. Please note, in my mtl, the VMF receives incident beam from point source, HMF only accepts beam reflected by VHM, and then reflect them to screen as the focus point. As the xrtglow has some bugs, I can't add the double reflection to both mirrors, however my simple example can display the error clearly enough. The double reflection effect has been added to both VHM and HMF mirrors footprint as shown in the py file. Thank a lot for help.

Stray light at mirror exit Stray light at mirror entrace Hori _Mirror_Footprint_pitch0 004318_nogap between mirror Vert _Mirror_Footprint_pinth0 004318_no gap between mirror CMF18.5-11.5Cu15_VertFirst_show stry light.zip Colorst_CMF18.5-11.5Cu15 (2).zip

leahwang1962 commented 2 years ago

The below graph clearly shows 4 rays that should not behave like this way for a reflection mirror. Greatly appreciate your help. 4 stray lights

kklmn commented 2 years ago

To debug, I would

kklmn commented 2 years ago

Do you really want the focus position to be inside the Montel mirror, not downstream of it?

leahwang1962 commented 2 years ago

Because the mirror length is 150mm, the focus position is out of Montel mirror. The distance from mirror end to focus is 110-L/2=45mm, with p=185mm,q=110mm,b(elliptical minor radius)=2.7. Thanks.

kklmn commented 2 years ago

Right! I added L, not L/2, to 185. And got it more than the focus position...

leahwang1962 commented 2 years ago

After some study of the reflection sequence, I think one of the method to avoid stray lights is to make 2 mirrors having no overlapping, just like Montel mirror example. And therefore the correct footprint can be achieved. However my optic of p=185mm q=115 and minor radius=2.7 can't eliminate the extended physical X beyond the intersection points below and behind the mirrors. Otherwise there will be huge gap between 2 mirrors at the beam entrance, and the efficiency of double reflection will be greatly reduced. Do you know if there are any methods I can use to make the 2 mirrors' length exactly stops along the 2 mirror's intersection line?(it means different limPhysX at each y) Or maybe I can use surface parameters or material to eliminate the rays of below and behind ? To clearly show the stray rays and extended mirror length beyond intersection points I used a big limPhysX number in the attached files. Appreciate any helps.

How to remove stray rays CMF18.5-11.5Cu15_VertFirst_showstrayLight.zip

kklmn commented 2 years ago

Look at backends/raycing/oes_base.py to OE.rays_good() and modify it in a more complex way than just comparing the local x and y arrays with the optical or physical limits. There you can make the good condition dependent on y.

leahwang1962 commented 2 years ago

Thanks for the suggestion, and sorry I need more help. I modified the ray_good() as attached here. I need local_to_Global function to get intersection points in global coordination to decide if they are the good rays by complex condition. However, I can't figure out how to use Local_to_Global function for the intersection points array(x,y,z). Can you help? Thanks. Mofified_Rays_good.zip

kklmn commented 2 years ago

Both the code and your idea are not understandable.

leahwang1962 commented 2 years ago

Base on optic surface equation in global coordinate system, I can use criteria like Xming<Xg<Xmaxg & Yming<Zg<Ymaxg & Zming<Zg<Zmaxg to decide if the intersection point of incident ray on optic surface (Xg,Yg,Zg) is inside optic working area. All of these variables are in global coordinate system. The minim and maximum values for criteria are not constant, they are calculated for each points. However in OE.rays_good(self, x, y,z, is2ndXtal=False), (x,y,z) is in local coordinate system. This is why I need Local_to Global function to convert (x,y,z) to (Xg,Yg,Zg), then I can use criteria in global coordinate Xming<Xg<Xmaxg & Yming<Zg<Ymaxg & Zming<Zg<Zmaxg to see if the intersection point is inside working area. The other alternative way is to convert the minim and maximum criterial values from Global coordinate to local coordinate. But I can't find Global_to_local function. I am pretty new to XRT. Maybe my understanding and idea are not correct. Please correct me or provide other way to solve this problem. Thanks a lot for help.

kklmn commented 2 years ago

Most typically, surfaces are defined in local coordinates. Why you want it in global coordinates?

leahwang1962 commented 2 years ago

Below is an example equation I used to calculate zmax limit to define optic working area in Global coordinates. I don't know how to get such equation in local coordinates without knowing transformation matrix from Global coordinates to Local coordinates, and such transformation matrix is hard to define. That is why I think using Local_to Global function is an easy way. Thanks.

zMaxg = minorRadius(1) * Math.Sqrt(1 - (Yg- ch) ^ 2 / majorRadius(1) ^ 2)

kklmn commented 2 years ago

When you translate or rotate a physical mirror, its shape and size do not change. Do you agree?

kklmn commented 2 years ago

Consider the horizontal mirror (vertically deflecting) of the Montel pair. Let the other mirror be on the left, i.e. at x<0 of the horizontal mirror. The bisector plane of the Montel pair is locally defined as x + w/2 = z, where w/2 is the mirror's half-width. With x + w/2 > z the reflection points are good for the horizontal mirror.

x you get from the rays_good() arguments. z is not in the arguments although it is known in _reflect_local() before calling rays_good(). I am going to add z to the method parameters. Presently, you can get z in rays_good() as local_z(x, y) only for a Cartesian OE but not for a parametric OE such as EllipticalMirrorParam.

So this idea will work in the near future. For now, I still recommend to find an equation for the border in local xy coordinates.

kklmn commented 2 years ago

I've added local z to the arguments of rays_good(). Get the new version from GH. You can now redefine rays_good() in your class and analyze, for example, x + w/2 > z to define good rays that belong to the inner surface of one Montel mirror.

leahwang1962 commented 2 years ago

I used tX, tY, tZ = gb.x[good], gb.y[good], gb.z[good] before calling rays_good function and solved the problem. Thank you for all helps.

leahwang1962 commented 2 years ago

Here is the new footprint, exactly the anticipated. Thanks for the great modeling. Vert _Mirror_Footprint .

kklmn commented 2 years ago

great!