/* * estimate-background.c * * Like 'process_hkl', but for signal/noise ratios * * (c) 2006-2010 Thomas White * * Part of CrystFEL - crystallography with a FEL * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include "utils.h" #include "statistics.h" #include "sfac.h" #include "reflections.h" #include "symmetry.h" #include "stream.h" /* Number of bins for plot of resolution shells */ #define NBINS (10) static void show_help(const char *s) { printf("Syntax: %s [options]\n\n", s); printf( "Estimate peak SNR from FEL Bragg intensities.\n" "\n" " -h, --help Display this help message.\n" " -i, --input= Specify input filename (\"-\" for stdin).\n" ); } int main(int argc, char *argv[]) { int c; char *filename = NULL; FILE *fh; int rval; double total_vol, vol_per_shell; double rmin, rmax; double rmins[NBINS]; double rmaxs[NBINS]; double snrs[NBINS]; unsigned int counts[NBINS]; UnitCell *real_cell; double overall_snr; unsigned int overall_counts; int i; /* Long options */ const struct option longopts[] = { {"help", 0, NULL, 'h'}, {"input", 1, NULL, 'i'}, {0, 0, NULL, 0} }; /* Short options */ while ((c = getopt_long(argc, argv, "hi:", longopts, NULL)) != -1) { switch (c) { case 'h' : show_help(argv[0]); return 0; case 'i' : filename = strdup(optarg); break; case 0 : break; default : return 1; } } if ( filename == NULL ) { ERROR("Please specify filename using the -i option\n"); return 1; } /* Open the data stream */ if ( strcmp(filename, "-") == 0 ) { fh = stdin; } else { fh = fopen(filename, "r"); } free(filename); if ( fh == NULL ) { ERROR("Failed to open input file\n"); return 1; } /* FIXME: Fixed resolution shells */ rmin = 0.120e9; rmax = 1.172e9; for ( i=0; i %i %i %i %f\n", h, k, l, d/1e9); bin = -1; for ( j=0; jrmins[j]) && (d<=rmaxs[j]) ) { bin = j; break; } } if ( bin == -1 ) { ERROR("Warnung! %i %i %i %f\n", h, k, l, d/1e9); continue; } snr = max/bg; snrs[bin] += snr; counts[bin]++; } while ( !done ); } while ( !rval ); /* Print out results */ overall_snr = 0.0; overall_counts = 0; for ( i=0; i0 ) { overall_snr += snrs[i]; overall_counts += counts[i]; } } printf("Overall: %f (%f / %i)\n", overall_snr/(double)overall_counts, overall_snr, overall_counts); fclose(fh); return 0; }