aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/peaks.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2012-06-20 16:00:17 +0200
committerThomas White <taw@physics.org>2012-06-20 16:00:17 +0200
commit469518a4cc84348e859e226a8b4d9ef7d7a1479b (patch)
treef4396fc6662d64d0df93daecaa7af00a8ae3ef15 /libcrystfel/src/peaks.c
parentdca1938a5de0a3b22ede39c978da3f664d05b6b4 (diff)
Fussiness
Diffstat (limited to 'libcrystfel/src/peaks.c')
-rw-r--r--libcrystfel/src/peaks.c75
1 files changed, 42 insertions, 33 deletions
diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c
index 35cc1f96..e541ec47 100644
--- a/libcrystfel/src/peaks.c
+++ b/libcrystfel/src/peaks.c
@@ -145,53 +145,62 @@ static int cull_peaks(struct image *image)
return nelim;
}
-static void make_BgMask(struct image *image, unsigned char *mask,
- double ir_out, int cfs, int css, double ir_in,
- struct panel *p)
+static unsigned char *make_BgMask(struct image *image, struct panel *p,
+ double ir_out, int cfs, int css, double ir_in)
{
- signed int fs, ss;
- RefList *list = image->reflections;
Reflection *refl;
RefListIterator *iter;
- double pk2_fs, pk2_ss;
- double d_fs, d_ss, distSq;
- double limSq = ir_in*ir_in;
- struct panel *p2;
+ unsigned char *mask;
- if (num_reflections(list)==0) return;
+ mask = calloc(4*ir_out*ir_out, sizeof(unsigned char));
+ if ( mask == NULL ) return NULL;
/* Loop over all reflections */
- for ( refl = first_refl(list, &iter);
- refl != NULL;
- refl = next_refl(refl, iter) )
+ for ( refl = first_refl(image->reflections, &iter);
+ refl != NULL;
+ refl = next_refl(refl, iter) )
{
+ struct panel *p2;
+ double pk2_fs, pk2_ss;
+
+ get_detector_pos(refl, &pk2_fs, &pk2_ss);
+
+ /* Determine if reflection is in the same panel */
+ p2 = find_panel(image->det, pk2_fs, pk2_ss);
+ if ( p2 != p ) continue;
+
+ /* If other peak area overlaps larger bg area, set mask */
+ if ( (fabs(pk2_fs-cfs)<ir_out+ir_in)
+ && (fabs(pk2_ss-css)<ir_out+ir_in) ) {
+
+ signed int fs, ss;
- get_detector_pos(refl, &pk2_fs, &pk2_ss);
+ for ( fs=-ir_out; fs<=ir_out; fs++ ) {
+ for ( ss=-ir_out; ss<=ir_out; ss++ ) {
- /*Determine if reflection is in the same panel */
- p2 = find_panel(image->det, pk2_fs, pk2_ss);
- if ( p2 != p ) continue;
+ double d_fs, d_ss, distSq;
- /* If other peak area overlaps larger bg area, color in the mask */
- if (fabs(pk2_fs-cfs)<ir_out+ir_in &&
- fabs(pk2_ss-css)<ir_out+ir_in){
+ d_fs = cfs + fs - pk2_fs;
+ d_ss = css + ss - pk2_ss;
+ distSq = d_fs*d_fs + d_ss*d_ss;
- for (fs=-ir_out; fs<ir_out; fs++){
- for (ss=-ir_out; ss<ir_out; ss++){
- d_fs = cfs + fs - pk2_fs;
- d_ss = css + ss - pk2_ss;
- distSq = d_fs*d_fs + d_ss*d_ss;
- if (distSq < limSq){
- mask[(int)(fs+ir_out+2*ir_out*(ss+ir_out))] = 1;
+ if ( distSq < ir_in*ir_in ) {
+
+ int idx;
+ idx = fs+ir_out+2*ir_out*(ss+ir_out);
+ mask[idx] = 1;
+ }
}
- }
+ }
+
}
}
- }
+ return mask;
}
+
/* Returns non-zero if peak has been vetoed.
* i.e. don't use result if return value is not zero. */
static int integrate_peak(struct image *image, int cfs, int css,
@@ -212,16 +221,16 @@ static int integrate_peak(struct image *image, int cfs, int css,
double bg_tot_sq = 0.0;
double var;
double aduph;
-
- unsigned char *bgPkMask = calloc((int)(pow(2*ir_out,2.0)), sizeof(unsigned char));
+ unsigned char *bgPkMask;
p = find_panel(image->det, cfs, css);
if ( p == NULL ) return 1;
if ( p->no_index ) return 1;
- /* Call function to block regions where there is expected to be a peak */
- make_BgMask(image, bgPkMask, ir_out, cfs, css, ir_inn, p);
+ /* Determine regions where there is expected to be a peak */
+ bgPkMask = make_BgMask(image, p, ir_out, cfs, css, ir_inn);
+ if ( bgPkMask == NULL ) return 1;
aduph = p->adu_per_eV * ph_lambda_to_eV(image->lambda);