aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/utils.h
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-07-09 12:01:43 +0200
committerThomas White <taw@physics.org>2020-07-29 18:53:45 +0200
commitfbef32528d3b4b2b2f694aa16d60c53511b1d402 (patch)
tree73fce3701cfc50f2a519fcb0a62de9e9db5f4be7 /libcrystfel/src/utils.h
parente19507ae14b5b9456d6c3379b43ba1ad1b2cc527 (diff)
Add wavelength and electron_voltage, plus units, to geometry file
Diffstat (limited to 'libcrystfel/src/utils.h')
-rw-r--r--libcrystfel/src/utils.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/libcrystfel/src/utils.h b/libcrystfel/src/utils.h
index a43263e0..04208530 100644
--- a/libcrystfel/src/utils.h
+++ b/libcrystfel/src/utils.h
@@ -54,9 +54,12 @@
/* -------------------------- Fundamental constants ------------------------ */
-/* Electron charge in C */
+/* Electron charge (Coulombs) */
#define ELECTRON_CHARGE (1.6021773e-19)
+/* Electron rest mass (kg) */
+#define ELECTRON_MASS (9.1093837015e-31)
+
/* Planck's constant (Js) */
#define PLANCK (6.62606896e-34)
@@ -194,6 +197,17 @@ static inline int within_tolerance(double a, double b, double percent)
/* Photon energy (eV) to k (1/m) */
#define ph_eV_to_k(a) ((a)*ELECTRON_CHARGE/PLANCK/C_VACUO)
+/* Electron accelerating voltage (V) to wavelength (m) */
+static inline double el_V_to_lambda(double E)
+{
+ double Estar;
+
+ /* Relativistically corrected accelerating voltage */
+ Estar = E * (1.0 + E * ELECTRON_CHARGE/(2.0*ELECTRON_MASS*C_VACUO*C_VACUO));
+
+ return PLANCK / sqrt(2.0*ELECTRON_MASS*ELECTRON_CHARGE*Estar);
+}
+
/* ------------------------------ Message logging ---------------------------- */