16 #include <I386/i386Lib.h>
18 #include <TPC/rowlen.h>
23 #include <DAQ_READER/daq_dta_structs.h>
25 #define likely(x) __builtin_expect((x),1)
26 #define unlikely(x) __builtin_expect((x),0)
28 char *tpxFCF::fcf_flags(u_char flags)
30 static char c_flags[32] ;
34 if(flags & FCF_IN_DOUBLE) strcat(c_flags,
"?") ;
36 if(flags & FCF_DEAD_EDGE) strcat(c_flags,
"D") ;
37 if(flags & FCF_BROKEN_EDGE) strcat(c_flags,
"B") ;
38 if(flags & FCF_ROW_EDGE) strcat(c_flags,
"E") ;
40 if(flags & FCF_BIG_CHARGE) strcat(c_flags,
"c") ;
41 if(flags & FCF_DOUBLE_T) strcat(c_flags,
"!") ;
42 if(flags & FCF_MERGED) strcat(c_flags,
"m") ;
43 if(flags & FCF_ONEPAD) strcat(c_flags,
"1") ;
45 if(c_flags[0] == 0) strcpy(c_flags,
"0") ;
51 int tpxFCF::afterburner(
int cou,
daq_cld *store[])
55 if(likely(cou == 0))
return 0 ;
61 for(
int i=0;i<cou;i++) {
67 if(l->charge == 0) continue ;
68 if(l->flags & FCF_BROKEN_EDGE) ;
73 for(
int j=0;j<cou;j++) {
81 if(r->charge == 0) continue ;
82 if(r->flags & FCF_BROKEN_EDGE) ;
86 if(l->p2 != 12) continue ;
90 if(l->p1 != 13) continue ;
94 if(l->p2 != 130) continue ;
98 if(l->p1 != 131) continue ;
106 if((r->t1 >= l->t1) && (r->t1 <= l->t2)) ok = 1 ;
107 if((r->t2 >= l->t1) && (r->t2 <= l->t2)) ok = 1 ;
127 double charge = l->charge + r->charge ;
136 l->tb = (l->tb * l->charge + r->tb * r->charge) / charge ;
137 l->pad = (l->pad * l->charge + r->pad * r->charge) / charge ;
139 if(r->t1 < l->t1) l->t1 = r->t1 ;
140 if(r->t2 > l->t2) l->t2 = r->t2 ;
142 if(r->p1 < l->p1) l->p1 = r->p1 ;
143 if(r->p2 > l->p2) l->p2 = r->p2 ;
145 l->flags |= r->flags ;
146 l->flags &= ~FCF_ONEPAD ;
149 if(charge > (
double)0x7FFF) {
151 int ch = (int) (charge+1) ;
155 l->charge = (u_short) ch * 1024 ;
156 l->flags |= FCF_BIG_CHARGE ;
159 l->charge = (u_short) charge ;
162 l->flags &= ~FCF_BROKEN_EDGE ;
165 r->flags |= FCF_DEAD_EDGE ;
174 for(
int i=0;i<cou;i++) {
179 if(l->flags & (FCF_ONEPAD | FCF_DEAD_EDGE | FCF_ROW_EDGE)) {
180 l->flags |= FCF_DEAD_EDGE ;
184 l->flags &= ~FCF_BROKEN_EDGE ;
192 int tpxFCF::fcf_decode(u_int *p_buff,
daq_cld *dc, u_short version)
195 int p1,p2,t1,t2,cha,fla ;
199 p_tmp = *p_buff & 0xFFFF ;
202 t_tmp = *p_buff >> 16 ;
205 if(version==FCF_V_FY08) {
206 p = (double)(p_tmp & 0x3FFF) / 32.0 ;
207 t = (double)(t_tmp & 0x7FFF) / 32.0 ;
210 p = (double)(p_tmp & 0x3FFF) / 64.0 ;
211 t = (double)(t_tmp & 0x7FFF) / 64.0 ;
215 if(p_tmp & 0x8000) fla |= FCF_MERGED ;
216 if(p_tmp & 0x4000) fla |= FCF_DEAD_EDGE ;
217 if(t_tmp & 0x8000) fla |= FCF_ONEPAD ;
221 cha = *p_buff >> 16 ;
226 fla |= FCF_BIG_CHARGE ;
227 cha = (cha & 0x7FFF) * 1024 ;
233 if(cha > 0xFFFF) cha = 0xFFFF ;
237 p_tmp = *p_buff & 0xFFFF ;
239 if(p_tmp & 0x8000) fla |= FCF_ROW_EDGE ;
240 if(p_tmp & 0x4000) fla |= FCF_BROKEN_EDGE ;
243 t2 = (p_tmp >> 4) & 0xF ;
246 p1 = (p_tmp >> 8) & 0x7 ;
247 p2 = (p_tmp >> 11) & 0x7 ;
271 int tpxFCF::fcf_decode(u_int *p_buff,
daq_sim_cld *sdc, u_short version)
273 int skip = fcf_decode(p_buff,&(sdc->cld), version) ;
282 sdc->quality = (*p_buff) >> 16 ;
283 sdc->track_id = (*p_buff) & 0xFFFF ;
308 memset(working_storage,0,
sizeof(working_storage)) ;
313 run_compatibility = 9 ;
318 tpx_rowlen = tpc_rowlen ;
321 memset(row_ix,0xFF,
sizeof(row_ix)) ;
326 do_version = FCF_V_FY09 ;
339 for(
int s=0;s<24;s++) {
340 for(
int r=0;r<256;r++) {
341 if(working_storage[s][r]) {
342 free(working_storage[s][r]) ;
343 working_storage[s][r] = 0 ;
345 if(gain_storage[s][r]) {
346 free(gain_storage[s][r]) ;
347 gain_storage[s][r] = 0;
358 void tpxFCF::config2(
int sec1,
int rdo1,
int mode,
int rows,
unsigned char *rowlen)
360 int rdo0 = rdo1 - 1 ;
361 int sec0 = sec1 - 1 ;
368 if((rowlen==0) || (rows<=0)) {
369 tpx_rowlen = tpc_rowlen ;
374 tpx_rowlen = rowlen ;
382 for(
int a=0;a<256;a++) {
383 for(
int ch=0;ch<16;ch++) {
386 tpx_from_altro(rdo0,a,ch,row,pad) ;
388 if(row > 250) continue ;
389 if(row == 0) continue ;
391 int bytes = tpx_rowlen[row] *
sizeof(s_static_storage) ;
394 if(gain_storage[sec0][row]) ;
398 gain_storage[sec0][row] = (s_static_storage *)valloc(bytes) ;
400 memset(gain_storage[sec0][row],0, bytes) ;
402 tot_count += tpx_rowlen[row] ;
408 s_static_storage *ss = get_static(row,pad) ;
410 ss->f = FCF_NEED_PAD | FCF_ONEPAD ;
416 LOG(TERR,
"config2: S%2d, RDO %d: %d pads",sec1,rdo1,tot_count) ;
420 void tpxFCF::config(u_int mask,
int mode,
int rows,
unsigned char *rowlen)
429 memset(row_ix,0,
sizeof(row_ix)) ;
431 if((rowlen==0) || (rows<=0)) {
432 tpx_rowlen = tpc_rowlen ;
437 tpx_rowlen = rowlen ;
449 for(row=1;row<=row_count;row++) row_ix[row] = 1 ;
456 for(ch=0;ch<16;ch++) {
457 tpx_from_altro(r,a,ch,row,pad) ;
459 if(row > 250) continue ;
460 if(row == 0) continue ;
470 for(row=0;row<=row_count;row++) {
472 tot_count += tpx_rowlen[row] ;
476 LOG(NOTE,
"fcfconfig: RDO mask 0x%03X: allocated %d pads (%d bytes)",rbs,tot_count,tot_count *
sizeof(
struct stage1)) ;
480 LOG(WARN,
"Whoa! Storage already allocated!") ;
484 storage = (
struct stage1 *) valloc(tot_count *
sizeof(
struct stage1)) ;
486 LOG(NOTE,
"FCF for mask 0x%02X: alloced %d bytes for %d tot_count X %d; cleared gains",mask,
487 tot_count *
sizeof(
struct stage1),
489 sizeof(
struct stage1)) ;
492 memset(storage,0,tot_count *
sizeof(
struct stage1)) ;
498 for(row=0;row<=row_count;row++) {
499 if(row_ix[row] == 0) {
504 row_ix[row] = tot_count ;
506 tot_count += tpx_rowlen[row] ;
513 for(row=1;row<=row_count;row++) {
514 for(pad=1;pad<=tpx_rowlen[row];pad++) {
515 get_stage1(row,pad)->f = FCF_NEED_PAD | FCF_ONEPAD ;
516 get_stage1(row,pad)->g = 1.0 ;
517 get_stage1(row,pad)->t0 = 0.0 ;
526 for(ch=0;ch<16;ch++) {
527 tpx_from_altro(r,a,ch,row,pad) ;
529 if(row > 250) continue ;
530 if(row == 0) continue ;
532 get_stage1(row, pad)->f = FCF_NEED_PAD | FCF_ONEPAD ;
533 get_stage1(row, pad)->g = 1.0 ;
534 get_stage1(row, pad)->t0 = 0.0 ;
548 void tpxFCF::apply_gains2(
tpxGain *gain)
552 if(tpx_padplane) gain = 0 ;
555 LOG(WARN,
"Sector %2d, gains NULL",sector) ;
558 LOG(NOTE,
"Applying gains to sector %d [%p ?]",sector,gain) ;
562 for(
int s=0;s<24;s++) {
563 for(
int r=0;r<256;r++) {
564 if(gain_storage[s][r] == 0) continue ;
569 for(
int row=1;row<=row_count;row++) {
570 for(
int pad=1;pad<=tpx_rowlen[row];pad++) {
571 s_static_storage *ss = get_static(row,pad) ;
582 for(
int s=0;s<24;s++) {
583 for(
int r=0;r<256;r++) {
584 if(gain_storage[s][r] == 0) continue ;
589 for(
int row=1;row<=row_count;row++) {
590 for(
int pad=1;pad<=tpx_rowlen[row];pad++) {
591 s_static_storage *ss = get_static(row,pad) ;
597 ss->g = gain->get_gains(sector,row,pad)->g ;
598 ss->t0 = gain->get_gains(sector,row,pad)->t0 ;
607 if(tpx_fy16_map==0) {
608 if(!(ss->f & FCF_NEED_PAD)) {
609 fl |= FCF_BROKEN_EDGE ;
610 LOG(TERR,
"Broken edge in RDO %d: RP %d:%d",rdo,row,pad) ;
615 fl |= FCF_DEAD_EDGE ;
616 kill |= FCF_KILLED_PAD ;
621 get_static(row,pad-1)->f |= fl ;
623 if(pad < tpx_rowlen[row]) {
624 get_static(row,pad+1)->f |= fl ;
629 if((pad==1) || (pad==tpx_rowlen[row])) {
633 ss->f |= fl | FCF_ONEPAD | kill ;
650 void tpxFCF::apply_gains(
int sec,
tpxGain *gain)
657 if(tpx_padplane) gain = 0 ;
659 LOG(WARN,
"apply_gains, sec %d",sec) ;
662 LOG(WARN,
"Sector %2d, gains NULL",sector) ;
665 LOG(NOTE,
"Applying gains to sector %d [%p ?]",sector,gain) ;
669 for(row=1;row<=row_count;row++) {
670 if(row_ix[row] < 0) continue ;
672 for(pad=1;pad <= tpx_rowlen[row]; pad++) {
674 get_stage1(row, pad)->f &= 0xFF00 ;
680 for(row=1;row<=row_count;row++) {
681 if(row_ix[row] < 0) continue ;
683 for(pad=1;pad<=tpx_rowlen[row];pad++) {
684 stage1 *s = get_stage1(row, pad) ;
687 s->g = gain->get_gains(sector,row,pad)->g ;
688 s->t0 = gain->get_gains(sector,row,pad)->t0 ;
697 if(!(s->f & FCF_NEED_PAD)) {
699 fl |= FCF_BROKEN_EDGE ;
703 fl |= FCF_DEAD_EDGE ;
710 get_stage1(row,pad-1)->f |= fl ;
712 if(pad < tpx_rowlen[row]) {
713 get_stage1(row,pad+1)->f |= fl ;
719 if((pad==1) || (pad==tpx_rowlen[row])) {
723 s->f |= fl | FCF_ONEPAD ;
725 LOG(DBG,
"FCF gains: row %2d, pad %3d: gain %f, flags 0x%04X",row,pad,s->g,s->f) ;
736 void tpxFCF::start_evt2(
int sec1,
int rdo1)
746 for(
int r=1;r<=row_count;r++) {
747 if(gain_storage[sector-1][r] == 0) continue ;
749 for(
int p=1;p<=tpx_rowlen[r];p++) {
751 w = get_working(r, p) ;
753 LOG(ERR,
"[%d] S%02d:%d: no row pad %d:%d???",my_id,sector,rdo,r,p) ;
768 void tpxFCF::start_evt()
773 for(
int r=1;r<=row_count;r++) {
774 if(row_ix[r] < 0) continue ;
776 for(
int p=1;p<=tpx_rowlen[r];p++) {
778 o = get_stage1(r, p) ;
780 LOG(ERR,
"No row pad %d:%d???",r,p) ;
798 if(unlikely(a->row > 250))
return 0 ;
799 if(unlikely(a->row == 0))
return 0 ;
800 if(unlikely(a->pad > tpx_rowlen[a->row]))
return 0 ;
803 s = get_working(a->row,a->pad) ;
806 s = get_stage1(a->row, a->pad) ;
812 LOG(ERR,
"[%d] Whoa -- no row:pad %d:%d???",my_id,a->row,a->pad) ;
818 if(unlikely(a->count<=1))
return 0 ;
827 if(unlikely(a->count >= 400)) {
836 struct s_static_storage *ss ;
838 ss = get_static(a->row,a->pad) ;
839 if(unlikely(ss->g <= 0.001)) {
844 orig_flags = flags = ss->f & 0xFF ;
849 if(unlikely(s->g <= 0.001)) {
854 orig_flags = flags = s->f & 0xFF ;
862 u_int t_ave, charge ;
864 u_int last_falling, last_adc ;
873 cl_max = &(s->cl[FCF_MAX_CL]) ;
878 last_falling = last_adc = 0 ;
881 tb_prev = tb_start = a->tb[0] ;
887 for(
int i=0;likely( i < a->count );i++) {
896 if(unlikely( adc <= 1 )) {
900 if(unlikely( tb < (tb_prev - 1) )) {
901 new_cluster |= FCF_ONEPAD ;
904 if(unlikely( last_falling )) {
905 if(unlikely( last_falling > FCF_MIN_WIDTH )) {
906 if(unlikely( adc > (last_adc + FCF_ADC_NOISE) )) {
907 flags |= FCF_DOUBLE_T ;
908 new_cluster |= FCF_DOUBLE_T ;
918 if(unlikely( (adc + FCF_ADC_NOISE) < last_adc )) {
924 if(unlikely( new_cluster )) {
925 if(likely(max_adc >= FCF_ADC_MIN)) {
927 cl->charge = charge ;
938 if(unlikely( cl >= cl_max ))
goto pad_done ;
942 if(unlikely( new_cluster & FCF_DOUBLE_T )) ;
944 else flags = orig_flags & 0xFF ;
955 if(unlikely( adc > max_adc )) {
969 if(likely(max_adc >= FCF_ADC_MIN)) {
975 cl->charge = charge ;
985 s->count = cl - s->cl ;
988 if(unlikely( s->count == 0 )) {
992 if(unlikely( s->count >= FCF_MAX_CL )) {
993 LOG(NOTE,
"Row %d:%d, %d clusters [max!]",a->row,a->pad,s->count) ;
1003 for(
int j=0;j<s->count;j++) {
1004 LOG(DBG,
"C: %d:%d\t %3d %3d, ch %5d, fl 0x%X",a->row,a->pad,cl->t1,cl->t2,cl->charge,cl->flags) ;
1010 if(unlikely(sim_adc && modes)) {
1013 for(
int j=0;j<s->count;j++) {
1026 int i_min = 0xFFFFFF ;
1028 cl->sim_length = 0 ;
1029 for(
int i=0;i<a->count;i++) {
1030 if((a->tb[i] >= t_lo) && (a->tb[i]<=t_hi)) {
1031 if(i < i_min) i_min = i ;
1035 if(sim_adc[i].track_id == 0xFFFF) {
1037 sim_adc[i].track_id = cl_marker ;
1041 cl->sim = sim_adc + i_min ;
1045 for(
int i=0;i<a->count;i++) {
1046 if((a->tb[i] >= t_lo) && (a->tb[i]<=t_hi)) {
1047 adc_sum += a->adc[i] ;
1049 if(a->adc[i] >= adc_min) {
1050 adc_min = a->adc[i] ;
1051 cl->track_id = sim_adc[i].track_id ;
1057 for(
int i=0;i<a->count;i++) {
1058 if((a->tb[i] >= t_lo) && (a->tb[i]<=t_hi)) {
1060 if(cl->track_id == sim_adc[i].track_id) {
1061 t_sum += a->adc[i] ;
1067 cl->quality = (t_sum * 100) / adc_sum ;
1089 int tpxFCF::stage2(u_int *outbuff,
int max_bytes)
1092 struct stage1 *old1, *cur1 ;
1095 tpxFCF_cl *old, *cur, *old_end, *cur_end ;
1097 loc_buff = outbuff ;
1100 for(r=1;r<=row_count;r++) {
1102 if(gain_storage[sector-1][r] == 0) continue ;
1105 if(row_ix[r] < 0) continue ;
1114 int bytes_so_far = (loc_buff - outbuff)*4 ;
1115 if(bytes_so_far > (max_bytes-1024)) {
1116 LOG(WARN,
"row %d: approaching limit: is %d, max %d",cur_row,bytes_so_far,max_bytes) ;
1120 u_int *row_cache = loc_buff++ ;
1121 u_int *clust_count_cache = loc_buff++ ;
1124 cur_row_clusters = 0 ;
1129 for(p=1;p<tpx_rowlen[r];p++) {
1132 struct s_static_storage *old_ss, *cur_ss ;
1134 old1 = get_working(r,p) ;
1136 if(old1->count == 0) continue ;
1138 cur1 = get_working(r,p+1) ;
1140 old_ss = get_static(r,p) ;
1141 cur_ss = get_static(r,p+1) ;
1145 old1->g = old_ss->g ;
1146 old1->t0 = old_ss->t0 ;
1149 cur1->g = cur_ss->g ;
1150 cur1->t0 = cur_ss->t0 ;
1157 old1 = get_stage1(r,p) ;
1158 cur1 = get_stage1(r,p+1) ;
1174 cur_end = cur + cur1->count ;
1175 old_end = old + old1->count ;
1178 while(old<old_end) {
1185 while(likely(cur<cur_end)) {
1191 if(cur->flags & FCF_ONEPAD) ;
1193 LOG(WARN,
"Can;t be without ONEPAD %d:%d 0x%X?! %d..%d",r,p+1,cur->flags,cur->p1,cur->p2) ;
1199 if(unlikely((old->t1 - cur->t2) >= 1)) {
1208 else if(unlikely((cur->t1 - old->t2) > 1)) {
1222 if(unlikely(cur->flags & FCF_IN_DOUBLE)) {
1226 cur->flags |= FCF_IN_DOUBLE ;
1228 cur->f_charge = cur->charge * cur1->g ;
1229 cur->scharge = cur->f_charge ;
1231 cur->f_t_ave = cur->t_ave * cur1->g ;
1234 cur->f_t_ave += cur->f_charge * cur1->t0 ;
1236 cur->p_ave = (p+1) * cur->f_charge ;
1239 cur->t_min = cur->t1 ;
1240 cur->t_max = cur->t2 ;
1246 if(likely(old->flags & FCF_IN_DOUBLE)) {
1251 old->flags |= FCF_IN_DOUBLE ;
1253 old->f_charge = old->charge * old1->g ;
1254 old->scharge = old->f_charge ;
1256 old->f_t_ave = old->t_ave * old1->g ;
1259 old->f_t_ave += old->f_charge * old1->t0 ;
1261 old->t_min = old->t1 ;
1262 old->t_max = old->t2 ;
1265 old->p_ave = p * old->f_charge ;
1270 if(unlikely(old->flags & FCF_FALLING)) {
1272 if(unlikely(old->flags & FCF_ONEPAD)) {
1273 LOG(ERR,
"Can't be on a merge!") ;
1275 if(unlikely(!(old->flags & FCF_IN_DOUBLE))) {
1276 LOG(ERR,
"Can't be on a merge!!!") ;
1280 if(unlikely(cur->scharge > (old->scharge + FCF_MIN_ADC_PAD_C))) {
1283 double sc_tmp, sc_p_tmp ;
1287 sc_tmp = old->scharge * 0.5 ;
1288 sc_p_tmp = sc_tmp * (p+1) ;
1291 cur->flags |= FCF_DOUBLE_PAD ;
1292 cur->f_charge += sc_tmp ;
1293 cur->p_ave += sc_p_tmp ;
1294 cur->f_t_ave += ((cur->t1 + cur->t2) * sc_tmp) * 0.5 ;
1297 old->flags |= FCF_DOUBLE_PAD ;
1298 old->f_charge -= sc_tmp ;
1299 old->p_ave -= sc_p_tmp ;
1300 old->f_t_ave -= ((old->t1 + old->t2) * sc_tmp) * 0.5 ;
1312 cur->flags |= FCF_FALLING ;
1315 if(unlikely(cur->scharge < (old->scharge - FCF_MIN_ADC_PAD_C))) {
1316 cur->flags |= FCF_FALLING ;
1327 if(unlikely(!(cur->flags & FCF_ONEPAD))) {
1328 LOG(ERR,
"Can;t be -- here I can have only ONEPADS!!") ;
1330 if(unlikely(!(cur->flags & FCF_IN_DOUBLE))) {
1331 LOG(ERR,
"Can't be -- I must be in double here!") ;
1336 cur->flags |= old->flags ;
1337 cur->flags &= ~FCF_ONEPAD ;
1339 if(unlikely(modes)) {
1342 if(cur->track_id == old->track_id) {
1343 qua = cur->quality * cur->f_charge + old->quality * old->f_charge ;
1345 else if(cur->f_charge < old->f_charge) {
1346 cur->track_id = old->track_id ;
1348 qua = old->quality * old->f_charge ;
1352 qua = cur->quality * cur->f_charge ;
1354 if (cur->f_charge + old->f_charge > 0)
1355 qua /= (cur->f_charge + old->f_charge) ;
1357 cur->quality = (u_int )qua ;
1361 cur->track_id = old->track_id ;
1362 for(
int i=0;i<cur->sim_length;i++) {
1363 cur->sim[i].track_id = old->track_id ;
1370 cur->f_charge += old->f_charge ;
1371 cur->f_t_ave += old->f_t_ave ;
1372 cur->p_ave += old->p_ave ;
1376 if(cur->t1 > old->t_min) {
1377 cur->t_min = old->t_min ;
1380 cur->t_min = cur->t1 ;
1383 if(cur->t2 < old->t_max) {
1384 cur->t_max = old->t_max ;
1387 cur->t_max = cur->t2 ;
1406 if(old->flags & FCF_ONEPAD) {
1408 LOG(ERR,
"Can;t be!") ;
1435 old1 = get_working(r,p) ;
1438 old1 = get_stage1(r,p) ;
1448 for(c=0;c<old1->count;c++) {
1460 if(cur_row_clusters) {
1461 *row_cache = (do_version<<16) | r ;
1462 *clust_count_cache = cur_row_clusters ;
1473 return loc_buff - (u_int *)outbuff ;
1477 void tpxFCF::dump(
tpxFCF_cl *cl,
int row)
1479 u_int fla = cl->flags ;
1480 u_int tmp_p, tmp_fl ;
1490 switch(run_compatibility) {
1494 if(likely(do_cuts)) {
1495 if(unlikely(fla & FCF_BROKEN_EDGE)) ;
1496 else if((do_cuts == 1) && (fla & (FCF_ROW_EDGE | FCF_DEAD_EDGE))) return ;
1501 if((fla & FCF_ONEPAD) && (cl->t1 < 15)) {
1502 if((cl->t2 - cl->t1)<=1) return ;
1503 if(cl->t2 > 30) return ;
1509 else if(likely(do_cuts)) {
1511 if(fla & FCF_BROKEN_EDGE) {
1514 else if(fla & FCF_ONEPAD) return ;
1515 else if((cl->t_max - cl->t_min) <= 2) return ;
1525 if(!(fla & FCF_IN_DOUBLE)) {
1526 if(fla & FCF_ONEPAD) {
1532 cl->f_charge = (float)cl->charge * 1.0 ;
1533 cl->p_ave = cl->p1 * cl->f_charge ;
1534 cl->f_t_ave = (
float)cl->t_ave * 1.0 ;
1538 LOG(WARN,
"WTF? not double: row %d: %d-%d, %d-%d (%d-%d): charge %d (%.3f): 0x%X",cur_row,cl->p1,cl->p2,cl->t1,cl->t2,cl->t_min,cl->t_max,cl->charge,cl->f_charge,cl->flags) ;
1543 if(cl->f_charge < 1.0) {
1544 if(!(fla & FCF_DEAD_EDGE)) LOG(WARN,
"WTF? no charge: row %d: %d-%d, %d-%d (%d-%d): charge %d (%.3f): 0x%X",cur_row,cl->p1,cl->p2,cl->t1,cl->t2,cl->t_min,cl->t_max,cl->charge,cl->f_charge,cl->flags) ;
1551 if(unlikely(fla & FCF_BROKEN_EDGE))
goto keep ;
1553 if(unlikely(do_cuts == 0))
goto keep ;
1555 if(likely(do_cuts != 2)) {
1556 if(fla & (FCF_DEAD_EDGE | FCF_ROW_EDGE)) return ;
1559 if(likely(fla & FCF_IN_DOUBLE)) {
1560 if((cl->t_max - cl->t_min)<=2) return ;
1561 if(cl->f_charge < 10.0) return ;
1565 if(likely(fla & FCF_ONEPAD)) ;
1567 LOG(WARN,
"WTF? not onebad but not in double!?") ;
1570 if((cl->t2 - cl->t1)<=2) return ;
1571 if(cl->charge < 10) return ;
1578 if(likely(fla & FCF_IN_DOUBLE)) ;
1580 struct stage1 ggg, *gain ;
1582 if(likely(fla & FCF_ONEPAD)) ;
1584 LOG(WARN,
"WTF? not onebad but not in double!?") ;
1594 gain->g = get_static(row, cl->p2)->g ;
1595 gain->t0 = get_static(row, cl->p2)->t0 ;
1600 gain = get_stage1(row, cl->p2) ;
1605 cl->f_charge = cl->charge * gain->g ;
1608 cl->f_t_ave = cl->t_ave * gain->g ;
1611 cl->f_t_ave += cl->f_charge * gain->t0 ;
1613 cl->p_ave = cl->p2 * cl->f_charge ;
1615 cl->t_min = cl->t1 ;
1616 cl->t_max = cl->t2 ;
1620 if(do_cuts==1 && run_compatibility >= 22) {
1622 if((cl->t_max > 20) && (fla & FCF_ONEPAD)) return ;
1628 int cha = (int) (cl->f_charge + 0.5) ;
1631 fla &= (~FCF_FALLING) ;
1633 dt = cl->f_t_ave / cl->f_charge ;
1634 dp = cl->p_ave / cl->f_charge ;
1637 if(do_version == FCF_V_FY08) {
1646 time_c = (u_int) (dt * div_fact + 0.5) ;
1647 pad_c = (u_int) (dp * div_fact + 0.5) ;
1650 tmp_p = pad_c / div_fact ;
1652 p1 = tmp_p - cl->p1 ;
1653 p2 = cl->p2 - tmp_p ;
1658 tmp_fl = (p1 << 8) | (p2 << 11) ;
1662 tmp_p = time_c / div_fact ;
1664 p1 = tmp_p - cl->t_min ;
1665 p2 = cl->t_max - tmp_p ;
1667 if(p1 > 15) p1 = 15 ;
1668 if(p2 > 15) p2 = 15 ;
1671 tmp_fl |= (p2 << 4) | p1 ;
1674 if(fla & FCF_ONEPAD) time_c |= 0x8000 ;
1676 if(fla & (FCF_DOUBLE_T | FCF_DOUBLE_PAD)) pad_c |= 0x8000 ;
1677 if(fla & FCF_DEAD_EDGE) pad_c |= 0x4000 ;
1679 if(fla & FCF_ROW_EDGE) tmp_fl |= 0x8000 ;
1680 if(fla & FCF_BROKEN_EDGE) tmp_fl |= 0x4000 ;
1682 if(cha > 0x7FFF) cha = 0x8000 | (cha/1024) ;
1685 *loc_buff++ = (time_c << 16) | pad_c ;
1686 *loc_buff++ = (cha << 16) | tmp_fl ;
1690 *loc_buff++ = (cl->quality << 16) | cl->track_id ;
1694 cur_row_clusters++ ;