/* * rejection.c * * Crystal rejection for scaling * * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: * 2010-2015 Thomas White * * 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 . * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include "crystal.h" #include "reflist.h" #include "rejection.h" #include "cell-utils.h" #include "post-refinement.h" static double mean_intensity(RefList *list) { Reflection *refl; RefListIterator *iter; double total = 0.0; int n = 0; for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { total += get_intensity(refl); n++; } return total/n; } /* Reject really obvious outliers */ void early_rejection(Crystal **crystals, int n) { int i; double m = 0.0; double mean_m; FILE *fh = fopen("reject.dat", "w"); int n_flag = 0; for ( i=0; in_contrib; j++ ) { double Ii; if ( c->contrib_crystals[j] == exclude ) { continue; } /* FIXME: Apply corrections */ Ii = get_intensity(c->contribs[j]); refl_sum += Ii; refl_sumsq += Ii * Ii; nc++; } if ( nc < 2 ) continue; refl_mean = refl_sum / nc; refl_var = (refl_sumsq/nc - refl_mean*refl_mean); refl_var *= nc/(nc-1.0); all_sum_mean += refl_mean; all_sumsq_mean += refl_mean*refl_mean; all_sum_var += refl_var; n++; } hsig2E = all_sum_var / n; sig2Y = (all_sumsq_mean/n - all_sum_mean*all_sum_mean/(n*n)); sig2Y *= n/(n-1.0); if ( pnref != NULL ) { *pnref = n; } return (sig2Y - hsig2E) / (sig2Y + hsig2E); } static void check_deltacchalf(Crystal **crystals, int n, RefList *full) { double cchalf; int i; int nref; cchalf = calculate_cchalf(full, full, NULL, &nref); STATUS("Overall CChalf = %f (%i reflections)\n", cchalf*100.0, nref); for ( i=0; i max_B ) { crystal_set_user_flag(crystals[i], PRFLAG_BIGB); } if ( crystal_get_user_flag(crystals[i]) == 0 ) n_acc++; } show_duds(crystals, n); if ( n_acc < 2 ) { ERROR("Not enough crystals left to proceed (%i). Sorry.\n", n_acc); exit(1); } }