#ifndef __AQUISITION_C__ #define __AQUISITION_C__ #endif #include #include #include #include #include #include #include #include #include #include #include #include "camac.h" #include "dc_int.h" #include "daq.h" #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define MIN(a,b) (((a) < (b)) ? (a) : (b)) short int read_limit[2]; short int threshold[2]; void daq_camac_fadc_read(struct io_control *i_cntl, short int fadc_channel) { DCCycle dcc; div_t d_naf; short int n; int k = 0, l =0; int hit = 0; int range = 100; int s[50], e[50]; int f_th, f_re; int buf; /* * Fadc_Station Number of FADC */ #include "station.h" d_naf = div(fadc_channel, 2); n = d_naf.quot; dcc.n = fadc_station[n]; dcc.a = d_naf.rem; dcc.f = 0; i_cntl->f_adc[n].n_hit[(int)dcc.a] = 0; s[0] = 0; e[0] = 0; f_th = 0; f_re = 0; #ifdef LOAD_FILE fp = fopen("fadc_test_data","r"); read_limit[1] = 180; #endif /* * Start buf loop */ for (buf = 0; buf < read_limit[1]; buf++) { #ifdef LOAD_FILE fscanf(fp,"%d", &dcc.data); #else ioctl(i_cntl->CC_fd, DC_CYCLE, &dcc); #endif i_cntl->f_adc[n].data[buf+threshold[(int)dcc.a]] = dcc.data; f_th = (dcc.data < i_cntl->f_adc[n].thred[(int)dcc.a]); f_re = (s[hit] < buf && buf < e[hit] + range); /* printf("buf == %d\n",buf); printf("FADC == %d\n",dcc.data); sleep(0.5);*/ if (f_th && !f_re) { hit ++; s[hit] = buf - range; e[hit] = MIN(read_limit[1], buf + range); } else if (f_th && f_re) { if (hit == 0) hit++; s[hit] = MAX(0, (MIN(s[hit], buf - range))); e[hit] = MIN(read_limit[1], buf + range); } } /* end buf loop */ #ifdef LOAD_FILE fclose(fp); #endif if (dcc.a == 0) /* over 4096 */ for (buf = read_limit[1]; buf < read_limit[0]; buf++) ioctl(i_cntl->CC_fd, DC_CYCLE, &dcc); /* for display */ i_cntl->f_adc[n].n_hit[(int)dcc.a] = hit; if (hit) { for (l = 0; l < hit; l++) { i_cntl->f_adc[n].w_start[(int)dcc.a][l] = s[l+1]; i_cntl->f_adc[n].w_stop[(int)dcc.a][l] = e[l+1]; } } /* write # of peak */ i_cntl->word[++i_cntl->word_point] = fadc_channel; i_cntl->word[++i_cntl->word_point] = hit; if (hit) { for (l = 1; l < hit + 1; l++) { i_cntl->word[++i_cntl->word_point] = s[l]; i_cntl->word[++i_cntl->word_point] = e[l]; for (k = s[l]; k < e[l] + 1; k++) i_cntl->word[++i_cntl->word_point] = i_cntl->f_adc[n].data[k+threshold[(int)dcc.a]]; } } }