aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/detgeom.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-05-27 11:35:56 +0200
committerThomas White <taw@physics.org>2020-07-29 18:42:57 +0200
commit199f01b01f65d254fcb514516eaaf67866b66bcb (patch)
tree95e284871a65a2bc6208c846267c72043a24dfa0 /libcrystfel/src/detgeom.c
parentaab8403884c4731f7365796de8f53315f4a61616 (diff)
Convert estimate_peak_resolution to detgeom
Diffstat (limited to 'libcrystfel/src/detgeom.c')
-rw-r--r--libcrystfel/src/detgeom.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libcrystfel/src/detgeom.c b/libcrystfel/src/detgeom.c
new file mode 100644
index 00000000..18fbd220
--- /dev/null
+++ b/libcrystfel/src/detgeom.c
@@ -0,0 +1,64 @@
+/*
+ * detgeom.c
+ *
+ * Utility functions for detgeom structure
+ *
+ * Copyright © 2019-2020 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
+ *
+ * Authors:
+ * 2020 Thomas White <taw@physics.org>
+ *
+ * This file is part of CrystFEL.
+ *
+ * CrystFEL is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CrystFEL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CrystFEL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <math.h>
+
+#include "detgeom.h"
+
+
+/**
+ * \file detgeom.h
+ */
+
+
+void detgeom_transform_coords(struct detgeom_panel *p,
+ double fs, double ss,
+ double wavelength,
+ double *r)
+{
+ double ctt, twotheta;
+ double xs, ys, zs;
+ double az;
+
+ /* Calculate 3D position of given position, in m */
+ xs = (p->cnx + fs*p->fsx + ss*p->ssx) * p->pixel_pitch;
+ ys = (p->cny + fs*p->fsy + ss*p->ssy) * p->pixel_pitch;
+ zs = (p->cnz + fs*p->fsz + ss*p->ssz) * p->pixel_pitch;
+
+ ctt = zs/sqrt(xs*xs + ys*ys + zs*zs);
+ twotheta = acos(ctt);
+ az = atan2(ys, xs);
+
+ r[0] = sin(twotheta)*cos(az) / wavelength;
+ r[1] = sin(twotheta)*sin(az) / wavelength;
+ r[2] = (ctt - 1.0) / wavelength;
+}