From 80620d1f143d1c7a16529da5fb0057af48e14bdd Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Fri, 22 Mar 2024 17:29:35 +0100 Subject: [PATCH] more consistent whitespace/aligment --- peakfinder8/cheetahmodules.h | 34 +-- peakfinder8/cython/peakfinder8_extension.pyx | 110 +++++---- peakfinder8/peakfinders.cpp | 223 +++++++++---------- peakfinder8/peakfinders.h | 4 +- 4 files changed, 198 insertions(+), 173 deletions(-) diff --git a/peakfinder8/cheetahmodules.h b/peakfinder8/cheetahmodules.h index ef28cda..4d0ee74 100644 --- a/peakfinder8/cheetahmodules.h +++ b/peakfinder8/cheetahmodules.h @@ -24,23 +24,23 @@ int killNearbyPeaks(tPeakList*, float ); * - All options are dominantly inherited during assembly and pixel integration (see assembleImage.cpp) * - The default value for all options is "false" * */ -static const uint16_t PIXEL_IS_PERFECT = 0; // Remember to change this value if necessary after adding a new option -static const uint16_t PIXEL_IS_INVALID = 1; // bit 0 -static const uint16_t PIXEL_IS_SATURATED = 2; // bit 1 -static const uint16_t PIXEL_IS_HOT = 4; // bit 2 -static const uint16_t PIXEL_IS_DEAD = 8; // bit 3 -static const uint16_t PIXEL_IS_SHADOWED = 16; // bit 4 -static const uint16_t PIXEL_IS_IN_PEAKMASK = 32; // bit 5 -static const uint16_t PIXEL_IS_TO_BE_IGNORED = 64; // bit 6 -static const uint16_t PIXEL_IS_BAD = 128; // bit 7 -static const uint16_t PIXEL_IS_OUT_OF_RESOLUTION_LIMITS = 256; // bit 8 -static const uint16_t PIXEL_IS_MISSING = 512; // bit 9 -static const uint16_t PIXEL_IS_NOISY = 1024; // bit 10 -static const uint16_t PIXEL_IS_ARTIFACT_CORRECTED = 2048; // bit 11 -static const uint16_t PIXEL_FAILED_ARTIFACT_CORRECTION = 4096; // bit 12 -static const uint16_t PIXEL_IS_PEAK_FOR_HITFINDER = 8192; // bit 13 -static const uint16_t PIXEL_IS_PHOTON_BACKGROUND_CORRECTED = 16384; // bit 14 -static const uint16_t PIXEL_IS_ALL = PIXEL_IS_INVALID | PIXEL_IS_SATURATED | PIXEL_IS_HOT | PIXEL_IS_DEAD | PIXEL_IS_SHADOWED | PIXEL_IS_IN_PEAKMASK | PIXEL_IS_TO_BE_IGNORED | PIXEL_IS_BAD | PIXEL_IS_OUT_OF_RESOLUTION_LIMITS | PIXEL_IS_MISSING | PIXEL_IS_NOISY | PIXEL_IS_ARTIFACT_CORRECTED | PIXEL_FAILED_ARTIFACT_CORRECTION | PIXEL_IS_PEAK_FOR_HITFINDER | PIXEL_IS_PHOTON_BACKGROUND_CORRECTED; // all bits +static const uint16_t PIXEL_IS_PERFECT = 0; // Remember to change this value if necessary after adding a new option +static const uint16_t PIXEL_IS_INVALID = 1; // bit 0 +static const uint16_t PIXEL_IS_SATURATED = 2; // bit 1 +static const uint16_t PIXEL_IS_HOT = 4; // bit 2 +static const uint16_t PIXEL_IS_DEAD = 8; // bit 3 +static const uint16_t PIXEL_IS_SHADOWED = 16; // bit 4 +static const uint16_t PIXEL_IS_IN_PEAKMASK = 32; // bit 5 +static const uint16_t PIXEL_IS_TO_BE_IGNORED = 64; // bit 6 +static const uint16_t PIXEL_IS_BAD = 128; // bit 7 +static const uint16_t PIXEL_IS_OUT_OF_RESOLUTION_LIMITS = 256; // bit 8 +static const uint16_t PIXEL_IS_MISSING = 512; // bit 9 +static const uint16_t PIXEL_IS_NOISY = 1024; // bit 10 +static const uint16_t PIXEL_IS_ARTIFACT_CORRECTED = 2048; // bit 11 +static const uint16_t PIXEL_FAILED_ARTIFACT_CORRECTION = 4096; // bit 12 +static const uint16_t PIXEL_IS_PEAK_FOR_HITFINDER = 8192; // bit 13 +static const uint16_t PIXEL_IS_PHOTON_BACKGROUND_CORRECTED = 16384; // bit 14 +static const uint16_t PIXEL_IS_ALL = PIXEL_IS_INVALID | PIXEL_IS_SATURATED | PIXEL_IS_HOT | PIXEL_IS_DEAD | PIXEL_IS_SHADOWED | PIXEL_IS_IN_PEAKMASK | PIXEL_IS_TO_BE_IGNORED | PIXEL_IS_BAD | PIXEL_IS_OUT_OF_RESOLUTION_LIMITS | PIXEL_IS_MISSING | PIXEL_IS_NOISY | PIXEL_IS_ARTIFACT_CORRECTED | PIXEL_FAILED_ARTIFACT_CORRECTION | PIXEL_IS_PEAK_FOR_HITFINDER | PIXEL_IS_PHOTON_BACKGROUND_CORRECTED; // all bits // inline bool isAnyOfBitOptionsSet(uint16_t value, uint16_t option) {return ((value & option)!=0);} //-------------------------------------------------------------------------------------------------------------------- diff --git a/peakfinder8/cython/peakfinder8_extension.pyx b/peakfinder8/cython/peakfinder8_extension.pyx index e9071d3..bdb52b1 100644 --- a/peakfinder8/cython/peakfinder8_extension.pyx +++ b/peakfinder8/cython/peakfinder8_extension.pyx @@ -9,49 +9,66 @@ from libc.stdlib cimport malloc, free cdef extern from "peakfinders.h": ctypedef struct tPeakList: - long nPeaks - long nHot - float peakResolution - float peakResolutionA - float peakDensity - float peakNpix - float peakTotal - int memoryAllocated - long nPeaks_max + long nPeaks + long nHot + float peakResolution + float peakResolutionA + float peakDensity + float peakNpix + float peakTotal + int memoryAllocated + long nPeaks_max - float *peak_maxintensity - float *peak_totalintensity - float *peak_sigma - float *peak_snr - float *peak_npix - float *peak_com_x - float *peak_com_y - long *peak_com_index - float *peak_com_x_assembled - float *peak_com_y_assembled - float *peak_com_r_assembled - float *peak_com_q - float *peak_com_res + float *peak_maxintensity + float *peak_totalintensity + float *peak_sigma + float *peak_snr + float *peak_npix + float *peak_com_x + float *peak_com_y + long *peak_com_index + float *peak_com_x_assembled + float *peak_com_y_assembled + float *peak_com_r_assembled + float *peak_com_q + float *peak_com_res void allocatePeakList(tPeakList* peak_list, long max_num_peaks) void freePeakList(tPeakList peak_list) cdef extern from "peakfinder8.hh": - int peakfinder8(tPeakList *peaklist, - float *data, char *mask, float *pix_r, long asic_nx, long asic_ny, - long nasics_x, long nasics_y, float ADCthresh, float hitfinderMinSNR, - long hitfinderMinPixCount, long hitfinderMaxPixCount, - long hitfinderLocalBGRadius) + int peakfinder8( + tPeakList *peaklist, + float *data, + char *mask, + float *pix_r, + long asic_nx, + long asic_ny, + long nasics_x, + long nasics_y, + float ADCthresh, + float hitfinderMinSNR, + long hitfinderMinPixCount, + long hitfinderMaxPixCount, + long hitfinderLocalBGRadius + ) -def peakfinder_8(int max_num_peaks, - numpy.ndarray[numpy.float32_t, ndim=2, mode="c"] data, - numpy.ndarray[numpy.int8_t, ndim=2, mode="c"] mask, - numpy.ndarray[numpy.float32_t, ndim=2, mode="c"] pix_r, - long asic_nx, long asic_ny, - long nasics_x, long nasics_y, float adc_thresh, float hitfinder_min_snr, - long hitfinder_min_pix_count, long hitfinder_max_pix_count, - long hitfinder_local_bg_radius): +def peakfinder_8( + int max_num_peaks, + numpy.ndarray[numpy.float32_t, ndim=2, mode="c"] data, + numpy.ndarray[numpy.int8_t, ndim=2, mode="c"] mask, + numpy.ndarray[numpy.float32_t, ndim=2, mode="c"] pix_r, + long asic_nx, + long asic_ny, + long nasics_x, + long nasics_y, + float adc_thresh, + float hitfinder_min_snr, + long hitfinder_min_pix_count, + long hitfinder_max_pix_count, + long hitfinder_local_bg_radius + ): cdef numpy.int8_t *mask_pointer = &mask[0,0] cdef char *mask_char_pointer = mask_pointer @@ -59,10 +76,21 @@ def peakfinder_8(int max_num_peaks, cdef tPeakList peak_list allocatePeakList(&peak_list, max_num_peaks) - peakfinder8(&peak_list, &data[0,0], mask_char_pointer, &pix_r[0,0], - asic_nx, asic_ny, nasics_x, nasics_y, - adc_thresh, hitfinder_min_snr, hitfinder_min_pix_count, - hitfinder_max_pix_count, hitfinder_local_bg_radius) + peakfinder8( + &peak_list, + &data[0,0], + mask_char_pointer, + &pix_r[0,0], + asic_nx, + asic_ny, + nasics_x, + nasics_y, + adc_thresh, + hitfinder_min_snr, + hitfinder_min_pix_count, + hitfinder_max_pix_count, + hitfinder_local_bg_radius + ) cdef int i cdef float peak_x, peak_y, peak_value @@ -71,10 +99,10 @@ def peakfinder_8(int max_num_peaks, cdef vector[double] peak_list_value num_peaks = peak_list.nPeaks - + if num_peaks > max_num_peaks: num_peaks = max_num_peaks - + for i in range(0, num_peaks): peak_x = peak_list.peak_com_x[i] diff --git a/peakfinder8/peakfinders.cpp b/peakfinder8/peakfinders.cpp index d6b64ec..55145a8 100644 --- a/peakfinder8/peakfinders.cpp +++ b/peakfinder8/peakfinders.cpp @@ -20,54 +20,53 @@ * Create arrays for remembering Bragg peak data */ void allocatePeakList(tPeakList *peak, long NpeaksMax) { - peak->nPeaks = 0; - peak->nPeaks_max = NpeaksMax; - peak->nHot = 0; - peak->peakResolution = 0; - peak->peakResolutionA = 0; - peak->peakDensity = 0; - peak->peakNpix = 0; - peak->peakTotal = 0; + peak->nPeaks = 0; + peak->nPeaks_max = NpeaksMax; + peak->nHot = 0; + peak->peakResolution = 0; + peak->peakResolutionA = 0; + peak->peakDensity = 0; + peak->peakNpix = 0; + peak->peakTotal = 0; - peak->peak_maxintensity = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_totalintensity = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_sigma = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_snr = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_npix = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_com_x = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_com_y = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_com_index = (long *) calloc(NpeaksMax, sizeof(long)); - peak->peak_com_x_assembled = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_com_y_assembled = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_com_r_assembled = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_com_q = (float *) calloc(NpeaksMax, sizeof(float)); - peak->peak_com_res = (float *) calloc(NpeaksMax, sizeof(float)); - peak->memoryAllocated = 1; + peak->peak_maxintensity = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_totalintensity = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_sigma = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_snr = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_npix = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_com_x = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_com_y = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_com_index = (long *) calloc(NpeaksMax, sizeof(long)); + peak->peak_com_x_assembled = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_com_y_assembled = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_com_r_assembled = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_com_q = (float *) calloc(NpeaksMax, sizeof(float)); + peak->peak_com_res = (float *) calloc(NpeaksMax, sizeof(float)); + peak->memoryAllocated = 1; } + /* * Clean up Bragg peak arrays */ void freePeakList(tPeakList peak) { - free(peak.peak_maxintensity); - free(peak.peak_totalintensity); - free(peak.peak_sigma); - free(peak.peak_snr); - free(peak.peak_npix); - free(peak.peak_com_x); - free(peak.peak_com_y); - free(peak.peak_com_index); - free(peak.peak_com_x_assembled); - free(peak.peak_com_y_assembled); - free(peak.peak_com_r_assembled); - free(peak.peak_com_q); - free(peak.peak_com_res); - peak.memoryAllocated = 0; + free(peak.peak_maxintensity); + free(peak.peak_totalintensity); + free(peak.peak_sigma); + free(peak.peak_snr); + free(peak.peak_npix); + free(peak.peak_com_x); + free(peak.peak_com_y); + free(peak.peak_com_index); + free(peak.peak_com_x_assembled); + free(peak.peak_com_y_assembled); + free(peak.peak_com_r_assembled); + free(peak.peak_com_q); + free(peak.peak_com_res); + peak.memoryAllocated = 0; } - - /* * Peakfinder 8 * Version before modifications during Cherezov December 2014 LE80 @@ -100,7 +99,7 @@ int peakfinder8(tPeakList *peaklist, float *data, char *mask, float *pix_r, long long e; long *inx = (long *) calloc(pix_nn, sizeof(long)); long *iny = (long *) calloc(pix_nn, sizeof(long)); - float thisI, thisIraw; + float thisI, thisIraw; float totI,totIraw; float maxI, maxIraw; float snr; @@ -160,100 +159,100 @@ int peakfinder8(tPeakList *peaklist, float *data, char *mask, float *pix_r, long long *peakpixels = (long *) calloc(hitfinderMaxPixCount, sizeof(long)); char *peakpixel = (char *) calloc(pix_nn, sizeof(char)); - char *rthreshold_changed = (char *) malloc(lmaxr*sizeof(char)); + char *rthreshold_changed = (char *) malloc(lmaxr*sizeof(char)); - int *pix_rint = (int *) malloc(pix_nn*sizeof(int)); - long *pixels_check = (long *) malloc(pix_nn*sizeof(long)); + int *pix_rint = (int *) malloc(pix_nn*sizeof(int)); + long *pixels_check = (long *) malloc(pix_nn*sizeof(long)); - long peakCounter = 0; + long peakCounter = 0; for(long i=0; i 0.1*rsigma[i] ) { - rthreshold_changed[i] = 1; - rthreshold_converged = false; - } - rthreshold[i] = thisthreshold; - } + if ( rthreshold_changed[i] == 1 ) { + if(rcount[i] == 0) { + roffset[i] = 0; + rsigma[i] = 0; + thisthreshold = 1e9; + //rthreshold[i] = ADCthresh; // For testing + } + else { + thisoffset = roffset[i]/rcount[i]; + thissigma = sqrt(rsigma[i]/rcount[i] - (thisoffset)*(thisoffset)); + roffset[i] = thisoffset; + rsigma[i] = thissigma; + thisthreshold = roffset[i] + hitfinderMinSNR*rsigma[i]; + if(thisthreshold < ADCthresh) + thisthreshold = ADCthresh; + //rthreshold[i] = ADCthresh; // For testing + } + rthreshold_changed[i] = 0; + if ( fabs(thisthreshold-rthreshold[i]) > 0.1*rsigma[i] ) { + rthreshold_changed[i] = 1; + rthreshold_converged = false; + } + rthreshold[i] = thisthreshold; + } } } com_x=0; com_y=0; - //goto END; + //goto END; for(long mj=0; mjnPeaks = peakCounter; return(peaklist->nPeaks); /*************************************************/ - - } + diff --git a/peakfinder8/peakfinders.h b/peakfinder8/peakfinders.h index 7d3a371..adb36e3 100644 --- a/peakfinder8/peakfinders.h +++ b/peakfinder8/peakfinders.h @@ -13,8 +13,8 @@ typedef struct { public: - long nPeaks; - long nHot; + long nPeaks; + long nHot; float peakResolution; // Radius of 80% of peaks float peakResolutionA; // Radius of 80% of peaks float peakDensity; // Density of peaks within this 80% figure