From 1440b2b897845b713450ef1bc8460d2d6d7bb337 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 25 Mar 2021 15:23:11 +0100 Subject: Add detgeom_mean_camera_length --- libcrystfel/src/detgeom.c | 36 ++++++++++++++++++++++++++++++++++++ libcrystfel/src/detgeom.h | 2 ++ 2 files changed, 38 insertions(+) (limited to 'libcrystfel/src') 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; in_panels; i++ ) { + total += clen(dg, i); + } + mean = total / dg->n_panels; + + for ( i=0; in_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 -- cgit v1.2.3