#include "module.c" #include #include #include #include #include const char *CHANNEL_NAMES[] = {"EVENT_NUM", "EVENT_I", "EVENT_J", "EVENT_CHARGE", "EVENT_ETA_X", "EVENT_ETA_Y", "EVENT_I_INTERP", "EVENT_J_INTERP"}; // max number of events per frame #define MAX_NUM_EVENTS 100 #define EVENT_CHANNELS 7 double evt_p[EVENT_CHANNELS][MAX_NUM_EVENTS]; int func_ph_1d_double( double *frame, int i_dim, int j_dim, double *th_m); void setArrayToValue(double array[], int size, double value) { for (int i = 0; i < size; i++) { array[i] = value; } } //Initialization: Threshold & background initialized = 0; //const char *THRESHOLD_FILE = "/configuration/user_scripts/lib/Thresh_2D_start600_size800.npy"; const char *THRESHOLD_FILE = "/configuration/user_scripts/lib/threshold_2d_start600_800.txt"; int threshold_num_elements=-1; double *threshold= NULL; double *background= NULL; const int MAX_LINE_LENGTH = 50000; int initialize(int size_x, int size_y, PyObject *pars){ //background (all matrices are indexed in 1d) background = malloc(size_x*size_y*sizeof(double)); for(int i=0; idescr->elsize; int dims = image->nd; int size_x = image->dimensions[1]; int size_y = image->dimensions[0]; unsigned short* img_data = (unsigned short*)image->data; //Initialization if (initialized==0){ initialized = initialize(size_x, size_y, pars); } int i,j,l; int i_dim=size_y; int j_dim=size_x; double *frameBKsub = malloc(i_dim*j_dim*sizeof(double)); for(i=0; i=MAX_NUM_EVENTS){ break; } for(j=0;j=MAX_NUM_EVENTS){ break; } // 2x2 version charge = frame[i*j_dim+j]+frame[(i+1)*j_dim+j] + frame[i*j_dim+(j+1)]+frame[(i+1)*j_dim+j+1]; //pixel by pixel threshold th = th_m[i*j_dim +j]; //check if charge above threshold if(charge>th) { eta_x = (frame[(i+1)*j_dim + j ]+frame[(i+1)*j_dim + (j+1)])/charge; eta_y = (frame[ i*j_dim + (j+1)]+frame[(i+1)*j_dim + (j+1)])/charge; i_interp = i + (C[0] + C[1]*eta_x+ C[2]*pow(eta_x,2) + C[3]*pow(eta_x,3) + C[4]*pow(eta_x,4)+ C[5]*pow(eta_x,5) + C[6]*pow(eta_x,6) + C[7]*pow(eta_x,7)); j_interp = j + (D[0] + D[1]*eta_y+ D[2]*pow(eta_y,2) + D[3]*pow(eta_y,3) + D[4]*pow(eta_y,4)+ D[5]*pow(eta_y,5) + D[6]*pow(eta_y,6) + D[7]*pow(eta_y,7)); // 1st case: first event if(evt_i==0){ evt_p[0][evt_i] = i; evt_p[1][evt_i] = j; evt_p[2][evt_i] = charge; evt_p[3][evt_i] = eta_x; evt_p[4][evt_i] = eta_y; evt_p[5][evt_i] = i_interp; // evt_p[6][evt_i] = j_interp; // evt_i++; } else { // 2nd case: not 1st event. we check if it is a neighbourg of the previos events and if charge is larger n=0; evt_m_i = evt_i; for(m=0; m