aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-03-25 15:23:11 +0100
committerThomas White <taw@physics.org>2021-03-25 16:16:01 +0100
commit1440b2b897845b713450ef1bc8460d2d6d7bb337 (patch)
treea6d1770cdc171a11a564f511244154fdb74371e0 /libcrystfel
parent42fc18c3ce4af1dccdf511b1da8ab4b0860e3b96 (diff)
Add detgeom_mean_camera_length
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/detgeom.c36
-rw-r--r--libcrystfel/src/detgeom.h2
2 files changed, 38 insertions, 0 deletions
diff --git a/libcrystfel/src/detgeom.c b/libcrystfel/src/detgeom.c
index 5612a225..fe247ba6 100644
--- a/libcrystfel/src/detgeom.c
+++ b/libcrystfel/src/detgeom.c
@@ -139,3 +139,39 @@ void show_panel(struct detgeom_panel *p)
STATUS(" %f adu/photon, max %f adu\n",
p->adu_per_photon, p->max_adu);
}
+
+
+static double clen(struct detgeom *dg, int i)
+{
+ return dg->panels[i].cnz * dg->panels[i].pixel_pitch;
+}
+
+
+static double far_corner_clen(struct detgeom *dg, int i)
+{
+ struct detgeom_panel *p = &dg->panels[i];
+ return (p->cnz + p->fsz*p->w + p->ssz*p->h) * p->pixel_pitch;
+}
+
+
+/* Return mean clen in m, or NAN in the following circumstances:
+ * 1. If the individual panel distances vary by more than 10% of the average
+ * 2. If the tilt of the panel creates a distance variation of more than 10%
+ * of the corner value over the extent of the panel */
+double detgeom_mean_camera_length(struct detgeom *dg)
+{
+ int i;
+ double mean;
+ double total = 0.0;
+ for ( i=0; i<dg->n_panels; i++ ) {
+ total += clen(dg, i);
+ }
+ mean = total / dg->n_panels;
+
+ for ( i=0; i<dg->n_panels; i++ ) {
+ if ( !within_tolerance(clen(dg, i), mean, 10.0) ) return NAN;
+ if ( !within_tolerance(clen(dg, i), far_corner_clen(dg, i), 10.0) ) return NAN;
+ }
+
+ return mean;
+}
diff --git a/libcrystfel/src/detgeom.h b/libcrystfel/src/detgeom.h
index 5e3815ac..7f291a7a 100644
--- a/libcrystfel/src/detgeom.h
+++ b/libcrystfel/src/detgeom.h
@@ -105,6 +105,8 @@ extern double detgeom_max_resolution(struct detgeom *detgeom,
extern void show_panel(struct detgeom_panel *p);
+extern double detgeom_mean_camera_length(struct detgeom *dg);
+
#ifdef __cplusplus
}
#endif