From db8eb661796893f25ac22a6133df0edd798b723c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Le=20Guyader?= <loic.le.guyader@xfel.eu>
Date: Fri, 12 Mar 2021 10:07:36 +0100
Subject: [PATCH] Fix outer zone width calculation

---
 TZPGcalc.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/TZPGcalc.py b/TZPGcalc.py
index 4b0688f..27782c7 100644
--- a/TZPGcalc.py
+++ b/TZPGcalc.py
@@ -17,7 +17,7 @@ from ipywidgets import HBox, VBox, Layout
 from IPython.display import display
 
 # zone plate focal length
-F = 250*1e-3 # [m]
+F0 = 250*1e-3 # [m]
 
 # Z position of the zone plate optic from the first interaction point (sample Z stage at 0 mm)
 Z0 = 230*1e-3 # [m]
@@ -25,7 +25,7 @@ Z0 = 230*1e-3 # [m]
 # zone plate nominal focal sorthened by the KBS focusing
 d = 3.3 - Z0 # distance between HFM and TZPG
 f1 = 7.3 # HFM focus 2 m behind second interaction point
-F = F*(d-f1)/(d-f1-F)
+F = F0*(d-f1)/(d-f1-F0)
 KBS_F = f1 - d # KBS focus distance from TZPG
 
 # number of membrane to show
@@ -363,14 +363,18 @@ class TZPGcalc():
         self.d_label.value = f'Grating Pitch:{int(np.round(d_nominal*1e9))} nm'
 
         rn = TZPGwV + TZPGo
-        dr_nominal = wl * F / (2*rn)
+        dr_nominal = wl * F0 / (2*np.sqrt(rn**2 + (TZPGwV/2)**2))
         self.dr_label.value = f'Outer Zone Plate width dr:{int(np.round(dr_nominal*1e9))} nm'
 
         # configuration for the low energy and high energy photon
-        confL = {'F':(2*rn)*dr_nominal/wlL,
+        F0_temp = (2*np.sqrt(rn**2 + (TZPGwV/2)**2))*dr_nominal/wlL
+        F_temp = F0_temp*(d-f1)/(d-f1-F0_temp)
+        confL = {'F':F_temp,
                  'theta_grating':np.arcsin(wlL/d_nominal),
                  'TZPGwH':TZPGwH, 'TZPGwV':TZPGwV,  'TZPGo':TZPGo}
-        confH = {'F':(2*rn)*dr_nominal/wlH,
+        F0_temp = (2*np.sqrt(rn**2 + (TZPGwV/2)**2))*dr_nominal/wlH
+        F_temp = F0_temp*(d-f1)/(d-f1-F0_temp)
+        confH = {'F':F_temp,
                  'theta_grating':np.arcsin(wlH/d_nominal),
                  'TZPGwH':TZPGwH, 'TZPGwV':TZPGwV,  'TZPGo':TZPGo}
 
-- 
GitLab