47 void cdc_hit(Int_t&, Int_t&, Int_t&, Int_t[], Int_t, Int_t, Int_t, Int_t, Int_t, Int_t);
48 void cdc_time(Int_t&, Int_t&, Int_t[], Int_t, Int_t, Int_t, Int_t);
49 void cdc_integral(Long_t&, Int_t&, Int_t, Int_t[], Int_t, Int_t);
50 void cdc_max(Int_t&, Int_t&, Int_t, Int_t[], Int_t);
51 void upsamplei(Int_t[], Int_t, Int_t[], Int_t);
55 void cdc_hit(Int_t &hitfound, Int_t &hitsample, Int_t &
pedestal, Int_t adc[], Int_t WINDOW_START, Int_t WINDOW_END, Int_t HIT_THRES, Int_t NPED, Int_t NPED2, Int_t PG) {
64 for (i=0; i<NPED; i++) {
65 pedestal += adc[WINDOW_START-NPED+i];
68 pedestal = ( NPED==0 ? 0:(pedestal/NPED) );
70 threshold = pedestal + HIT_THRES;
73 i = WINDOW_START - 1 + PG;
76 while ((hitfound==0) && (i<WINDOW_END-1)) {
80 if (adc[i] >= threshold) {
81 if (adc[i+1] >= threshold) {
94 for (i=0; i<NPED2; i++) {
95 pedestal += adc[hitsample-PG-i];
98 pedestal = ( NPED2==0 ? 0:(pedestal/NPED2) );
107 void cdc_integral(Long_t& integral, Int_t& overflows, Int_t timesample, Int_t adc[], Int_t WINDOW_END, Int_t INT_END) {
114 if (timesample <= WINDOW_END) {
116 Int_t lastsample = timesample + INT_END - 1;
118 if (lastsample > WINDOW_END) lastsample = WINDOW_END;
120 for (i = timesample; i <= lastsample; i++ ) {
122 integral += (Long_t)adc[i];
123 if (adc[i]==(Long_t)4095) overflows++;
135 void cdc_max(Int_t& maxamp, Int_t &maxsample, Int_t hitsample, Int_t adc[], Int_t WINDOW_END) {
142 while ((adc[hitsample] <= adc[hitsample-1]) && (hitsample <= WINDOW_END)) hitsample++;
145 maxamp = adc[hitsample];
146 maxsample = hitsample;
149 for (i=hitsample; i<=WINDOW_END; i++) {
151 if (adc[i] > adc[i-1]) {
157 if (adc[i] <= adc[i-1]) ndec++;
162 if (hitsample >= WINDOW_END) {
163 maxamp = adc[WINDOW_END];
164 maxsample = WINDOW_END;
172 void cdc_time(Int_t &le_time, Int_t &q_code, Int_t adc[], Int_t NU, Int_t PG, Int_t THRES_HIGH, Int_t THRES_LOW) {
196 const Int_t NUPSAMPLED = 6;
197 const Int_t SET_ADC_MIN = 20;
198 const Int_t LIMIT_PED_MAX = 511;
201 const Int_t START_SEARCH = PED+1;
203 const Int_t
X = PED + PG;
204 const Int_t ROUGH_TIME = (X*10)-30;
206 Int_t iubuf[NUPSAMPLED] = {0};
208 Int_t adc_thres_hi = 0;
209 Int_t adc_thres_lo = 0;
217 Int_t adc_sample_hi = 0;
218 Int_t adc_sample_lo = 0;
219 Int_t adc_sample_lo2 = 0;
221 Bool_t over_threshold = kFALSE;
222 Bool_t below_threshold = kFALSE;
226 Int_t ups_adjust = 0;
241 le_time = ROUGH_TIME + 1;
245 if ((i < PED+1) && (adc[i] > LIMIT_PED_MAX)) {
246 le_time = ROUGH_TIME + 2;
252 if (q_code>0)
return;
264 if (adc[i] < adcmin) {
271 Int_t adcoffset = SET_ADC_MIN - adcmin;
276 adc[i] = adc[i] + adcoffset;
288 adc_thres_hi = adc[PED] + THRES_HIGH;
289 adc_thres_lo = adc[PED] + THRES_LOW;
293 over_threshold = kFALSE;
296 while ((!over_threshold)&&(i<NU)) {
298 if (adc[i] >= adc_thres_hi) {
300 over_threshold = kTRUE;
307 if (!over_threshold) {
309 le_time = ROUGH_TIME + 3;
318 below_threshold = kFALSE;
321 while ((!below_threshold) && (i>=PED)) {
323 if (adc[i] <= adc_thres_lo) {
326 below_threshold = kTRUE;
334 if (adc[adc_sample_lo] == adc_thres_lo) {
343 if (adc_sample_lo > NU-7) {
345 le_time = itime1 + 4;
355 upsamplei(adc, adc_sample_lo, iubuf, NUPSAMPLED);
361 Bool_t negups = kFALSE;
364 while ((!negups)&&(i<NUPSAMPLED)) {
376 le_time = itime1 + 5;
388 ups_adjust = iubuf[0] - adc[adc_sample_lo];
392 adc_thres_lo = adc_thres_lo + ups_adjust;
396 if (iubuf[NUPSAMPLED-1]<= adc_thres_lo) {
398 le_time = itime1 + 9;
408 below_threshold = kFALSE;
411 while ((!below_threshold) && (i>=0)) {
413 if (iubuf[i] <= adc_thres_lo) {
415 below_threshold = kTRUE;
423 if (!below_threshold) {
425 printf(
"upsampled points did not go below threshold - should be impossible\n");
434 itime2 = adc_sample_lo2*2;
443 if (iubuf[adc_sample_lo2] != adc_thres_lo) {
445 if (2*adc_thres_lo >= iubuf[adc_sample_lo2] + iubuf[adc_sample_lo2+1]) itime3 = 1;
450 le_time = itime1 + itime2 + itime3;
457 void cdc_time2(Double_t &le_time, Int_t &q_code, Int_t
pedestal, Int_t adc[], Int_t NU, Int_t PG, Int_t THRES_HIGH, Int_t THRES_LOW) {
482 const Int_t NUPSAMPLED = 6;
483 const Int_t SET_ADC_MIN = 20;
484 const Int_t LIMIT_PED_MAX = 511;
487 const Int_t START_SEARCH = PED+1;
489 const Int_t
X = PED + PG;
490 const Int_t ROUGH_TIME = (X*10)-30;
492 Int_t iubuf[NUPSAMPLED] = {0};
494 Int_t adc_thres_hi = 0;
495 Int_t adc_thres_lo = 0;
503 Int_t adc_sample_hi = 0;
504 Int_t adc_sample_hi2 = 0;
505 Int_t adc_sample_lo = 0;
506 Int_t adc_sample_lo2 = 0;
508 Bool_t over_threshold = kFALSE;
509 Bool_t below_threshold = kFALSE;
513 Int_t ups_adjust = 0;
532 le_time = ROUGH_TIME + 1;
536 if ((i < PED+1) && (adc[i] > LIMIT_PED_MAX)) {
537 le_time = ROUGH_TIME + 2;
543 if (q_code>0)
return;
555 if (adc[i] < adcmin) {
562 Int_t adcoffset = SET_ADC_MIN - adcmin;
567 adc[i] = adc[i] + adcoffset;
568 if (adc[i] > 4095) adc[i] = 4095;
581 if (adc[i]>maxamp) maxamp = adc[i];
587 if (VERBOSE)
printf(
"\nfound maxamp %i\n",maxamp);
597 adc_thres_hi = pedestal + THRES_HIGH;
598 adc_thres_lo = pedestal + THRES_LOW;
608 if (VERBOSE)
printf(
"thresholds %i %i\n",adc_thres_hi,adc_thres_lo);
612 over_threshold = kFALSE;
615 while ((!over_threshold)&&(i<NU)) {
617 if (adc[i] >= adc_thres_hi) {
619 over_threshold = kTRUE;
626 if (!over_threshold) {
628 le_time = ROUGH_TIME + 3;
634 if (VERBOSE)
printf(
"found high threshold upward xing in sample %i val %i\n",adc_sample_hi,adc[adc_sample_hi]);
638 below_threshold = kFALSE;
641 while ((!below_threshold) && (i>=PED)) {
643 if (adc[i] <= adc_thres_lo) {
646 below_threshold = kTRUE;
652 if (VERBOSE)
printf(
"found low threshold downward xing in sample %i val %i\n",adc_sample_lo,adc[adc_sample_lo]);
655 if (adc[adc_sample_lo] == adc_thres_lo) {
664 if (adc_sample_lo > NU-7) {
666 le_time = itime1 + 4;
678 if (VERBOSE)
printf(
"upsampling sample %i val %i to next val %i \n",adc_sample_lo,adc[adc_sample_lo],adc[adc_sample_lo+1]);
680 upsamplei(adc, adc_sample_lo, iubuf, NUPSAMPLED);
682 for (i=0;i<NUPSAMPLED; i++)
if (VERBOSE)
printf(
"iubuf %i\n",iubuf[i]);
687 Bool_t negups = kFALSE;
690 while ((!negups)&&(i<NUPSAMPLED)) {
702 le_time = itime1 + 5;
714 ups_adjust = iubuf[0] - adc[adc_sample_lo];
718 adc_thres_lo = adc_thres_lo + ups_adjust;
722 if (iubuf[NUPSAMPLED-1]<= adc_thres_lo) {
723 le_time = itime1 + 9;
730 below_threshold = kFALSE;
733 while ((!below_threshold) && (i>=0)) {
735 if (iubuf[i] <= adc_thres_lo) {
737 below_threshold = kTRUE;
743 if (!below_threshold) {
744 if (VERBOSE)
printf(
"upsampled points did not go below threshold - should be impossible\n");
750 itime2 = adc_sample_lo2*2;
758 if (iubuf[adc_sample_lo2] != adc_thres_lo) {
759 if (2*adc_thres_lo >= iubuf[adc_sample_lo2] + iubuf[adc_sample_lo2+1]) itime3 = 1;
763 le_time = itime1 + itime2 + itime3;
772 double tl_time = adc_sample_lo*10 + adc_sample_lo2*2;
774 if ( adc_thres_lo > iubuf[adc_sample_lo2] ) {
776 if ( iubuf[adc_sample_lo2] == iubuf[adc_sample_lo2 + 1] ) {
777 if (VERBOSE)
printf(
"iubuf plateau \n");
779 tl_time += 2*(adc_thres_lo - iubuf[adc_sample_lo2])/
double(iubuf[adc_sample_lo2 + 1] - iubuf[adc_sample_lo2]);
782 if (VERBOSE)
printf(
"adc_thres_lo %i = iubuf[adc_sample_lo2]\n",adc_thres_lo);
785 if (VERBOSE)
printf(
"le_time %.0f tl_time %.1f \n",le_time,tl_time);
795 if (VERBOSE)
printf(
"upsampling sample %i val %i to next val %i \n",adc_sample_hi,adc[adc_sample_hi],adc[adc_sample_hi+1]);
797 upsamplei(adc, adc_sample_hi, iubuf, NUPSAMPLED);
799 for (i=0;i<NUPSAMPLED; i++)
if (VERBOSE)
printf(
"iubuf %i\n",iubuf[i]);
801 ups_adjust = iubuf[0] - adc[adc_sample_hi];
805 adc_thres_hi = adc_thres_hi + ups_adjust;
809 if (iubuf[NUPSAMPLED-1]<= adc_thres_hi) {
810 if (VERBOSE)
printf(
"bad upsampling\n");
819 below_threshold = kFALSE;
822 while ((!below_threshold) && (i>=0)) {
824 if (iubuf[i] <= adc_thres_hi) {
826 below_threshold = kTRUE;
834 if (!below_threshold) {
835 if (VERBOSE)
printf(
"upsampled points did not go below threshold - should be impossible\n");
844 itime2 = adc_sample_hi2*2;
847 th_time = adc_sample_hi*10 + adc_sample_hi2*2;
849 th_time += 2*(adc_thres_hi - iubuf[adc_sample_hi2])/
double(iubuf[adc_sample_hi2 + 1] - iubuf[adc_sample_hi2]);
851 if (VERBOSE)
printf(
"th_time %.1f \n",th_time);
859 adc_thres_hi = pedestal + THRES_HIGH;
860 adc_thres_lo = pedestal + THRES_LOW;
869 le_time = th_time - (th_time - tl_time)*THRES_HIGH/(THRES_HIGH-THRES_LOW);
871 if (VERBOSE)
printf(
"new le_time %.1f\n",le_time);
884 void upsamplei(Int_t
x[], Int_t startpos, Int_t z[],
const Int_t NUPSAMPLED) {
891 const Int_t nz = NUPSAMPLED;
899 const Int_t Kscale = 16384;
900 const Int_t K[43] = {-4, -9, -13, -10, 5, 37, 82, 124, 139, 102, -1, -161, -336, -455, -436, -212, 241, 886, 1623, 2309, 2795, 2971, 2795, 2309, 1623, 886, 241, -212, -436, -455, -336, -161, -1, 102, 139, 124, 82, 37, 5, -10, -13, -9, -4};
917 Int_t firstk = 41 + (startpos-4)*5;
920 for (k=firstk; k<firstk+nz; k++) {
926 for (j=k%5;j<43;j+=5) {
928 z[dk] += x[(k-j)/5]*K[j];
934 z[dk] = (Int_t)(5*z[dk])/Kscale;
void cdc_max(Int_t &, Int_t &, Int_t, Int_t[], Int_t)
void cdc_time(Int_t &, Int_t &, Int_t[], Int_t, Int_t, Int_t, Int_t)
void upsamplei(Int_t[], Int_t, Int_t[], Int_t)
void cdc_time2(Double_t &le_time, Int_t &q_code, Int_t pedestal, Int_t adc[], Int_t NU, Int_t PG, Int_t THRES_HIGH, Int_t THRES_LOW)
void cdc_hit(Int_t &, Int_t &, Int_t &, Int_t[], Int_t, Int_t, Int_t, Int_t, Int_t, Int_t)
static TH1I * pedestal[nChan]
printf("string=%s", string)
void cdc_integral(Long_t &, Int_t &, Int_t, Int_t[], Int_t, Int_t)