aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
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
parentaab8403884c4731f7365796de8f53315f4a61616 (diff)
Convert estimate_peak_resolution to detgeom
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/CMakeLists.txt1
-rw-r--r--libcrystfel/src/detgeom.c64
-rw-r--r--libcrystfel/src/detgeom.h5
-rw-r--r--libcrystfel/src/peaks.c11
-rw-r--r--libcrystfel/src/peaks.h3
5 files changed, 78 insertions, 6 deletions
diff --git a/libcrystfel/CMakeLists.txt b/libcrystfel/CMakeLists.txt
index 06e7dfa3..026689ca 100644
--- a/libcrystfel/CMakeLists.txt
+++ b/libcrystfel/CMakeLists.txt
@@ -64,6 +64,7 @@ set(LIBCRYSTFEL_SOURCES
src/spectrum.c
src/datatemplate.c
src/colscale.c
+ src/detgeom.c
${BISON_symopp_OUTPUTS}
${FLEX_symopl_OUTPUTS}
)
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;
+}
diff --git a/libcrystfel/src/detgeom.h b/libcrystfel/src/detgeom.h
index 0c924f36..4d80df6b 100644
--- a/libcrystfel/src/detgeom.h
+++ b/libcrystfel/src/detgeom.h
@@ -96,6 +96,11 @@ struct detgeom
int n_panels;
};
+extern void detgeom_transform_coords(struct detgeom_panel *p,
+ double fs, double ss,
+ double wavelength,
+ double *r);
+
#ifdef __cplusplus
}
#endif
diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c
index 25697c43..de024b0d 100644
--- a/libcrystfel/src/peaks.c
+++ b/libcrystfel/src/peaks.c
@@ -733,7 +733,7 @@ static int compare_double(const void *av, const void *bv)
double estimate_peak_resolution(ImageFeatureList *peaks, double lambda,
- struct detector *det)
+ struct detgeom *det)
{
int i, npk, ncut;
double *rns;
@@ -751,13 +751,14 @@ double estimate_peak_resolution(ImageFeatureList *peaks, double lambda,
for ( i=0; i<npk; i++ ) {
struct imagefeature *f;
- struct rvec r;
+ double r[3];
f = image_get_feature(peaks, i);
- r = get_q_for_panel(&det->panels[f->pn],
- f->fs, f->ss, NULL, 1.0/lambda);
- rns[i] = modulus(r.u, r.v, r.w);
+ detgeom_transform_coords(&det->panels[f->pn],
+ f->fs, f->ss,
+ lambda, r);
+ rns[i] = modulus(r[0], r[1], r[2]);
}
diff --git a/libcrystfel/src/peaks.h b/libcrystfel/src/peaks.h
index c60bbe1e..e4dbed40 100644
--- a/libcrystfel/src/peaks.h
+++ b/libcrystfel/src/peaks.h
@@ -40,6 +40,7 @@
#include "reflist.h"
#include "crystal.h"
#include "image.h"
+#include "detgeom.h"
#ifdef __cplusplus
extern "C" {
@@ -96,7 +97,7 @@ extern void validate_peaks(struct image *image, double min_snr,
extern double estimate_peak_resolution(ImageFeatureList *peaks,
double lambda,
- struct detector *det);
+ struct detgeom *det);
#ifdef __cplusplus
}