9 #define LOG(x,a,v1,v2,v3,v4,v5)
15 #include <fcfClass.hh>
17 #include <TPC/padfinder.h>
32 fcfAfterburner::fcfAfterburner()
34 last_n = last_count = last_i = last_stage = 0;
36 do_merge = do_cuts = 1 ;
49 void fcfAfterburner::print_hit(
const char *str,
struct fcfHit *h)
52 fprintf(stdout,
"%s: ",str) ;
55 fprintf(stdout,
"%d %f %f %d %d %d %d %d %d %d %d %d\n",
56 row,(
double)h->pad/64.0+0.5,(
double)h->tm/64.0+0.5,h->c,h->f,
57 h->p1,h->p2,h->t1,h->t2,h->cl_id,h->id_simtrk,h->id_quality) ;
67 int fcfAfterburner::output(
struct fcfHit *
hit)
73 if(hit->f & (FCF_ONEPAD | FCF_ROW_EDGE | FCF_DEAD_EDGE)) ret = 0 ;
74 else if((hit->t2 - hit->t1) <= 3) ret = 0 ;
75 else if(hit->t1 == 0) ret = 0 ;
76 else if(hit->c < 40) ret = 0 ;
101 void fcfAfterburner::decode(u_int *ptr,
struct fcfHit *hit, u_int *sim)
106 u_short p1,p2,t1,t2 ;
116 hit->id_simtrk = s->id_simtrk ;
117 hit->id_quality = s->id_quality ;
118 hit->cl_id = s->cl_id ;
123 hit->id_quality = 100 ;
137 tm = (pt >> 16) & 0x7FFF ;
143 if(pt & 0x8000) flags |= FCF_DOUBLE_PAD ;
144 if(pt & 0x4000) flags |= FCF_DEAD_EDGE ;
145 if(pt & (0x8000 << 16)) flags |= FCF_ONEPAD ;
146 if(fl & 0x8000) flags |= FCF_ROW_EDGE ;
147 if(fl & 0x4000) flags |= FCF_BROKEN_EDGE ;
149 t2 = (fl & 0x00F0) >> 4 ;
152 t2 = (tm >> 6) + t2 ;
153 t1 = (tm >> 6) - t1 ;
155 p2 = (fl & 0x3800) >> 11 ;
156 p1 = (fl & 0x0700) >> 8 ;
158 p2 = (pad >> 6) + p2 ;
159 p1 = (pad >> 6) - p1 ;
179 int fcfAfterburner::check_merge(
struct fcfHit *hit_l,
struct fcfHit *hit_r)
184 tm[0] = (double)hit_l->tm ;
185 tm[1] = (
double)hit_r->tm ;
187 if(fabs(tm[0]/64.0-tm[1]/64.0)<2.0) {
191 charge = hit_r->c + hit_l->c ;
192 if(charge & 0xFFFF0000) {
193 LOG(ERR,
"Merge: charge too big %d %d",hit_r->c, hit_l->c,0,0,0) ;
194 hit_l->c = hit_r->c = 0 ;
199 if(hit_r->id_simtrk != hit_l->id_simtrk) {
201 if(hit_r->c > hit_l->c) {
202 hit_l->id_simtrk = hit_r->id_simtrk ;
208 hit_l->id_quality = (hit_l->id_quality * hit_l->c + hit_r->id_quality * hit_r->c) / charge ;
212 if(hit_r->cl_id != hit_l->cl_id) {
213 hit_l->cl_id = 0xFFFF ;
216 hit_l->tm = (short)((tm[0]*(
double)hit_l->c + tm[1]*(double)hit_r->c)/(double)charge) ;
218 tm[0] = (double)hit_l->pad ;
219 tm[1] = (
double)hit_r->pad ;
220 hit_l->pad = (short)((tm[0]*(
double)hit_l->c + tm[1]*(double)hit_r->c)/(double)charge) ;
225 hit_l->f |= hit_r->f ;
226 hit_l->f &= ~FCF_ONEPAD ;
229 hit_l->p2 = hit_r->p2 ;
232 if(hit_r->t2 > hit_l->t2) hit_l->t2 = hit_r->t2 ;
233 if(hit_r->t1 < hit_l->t1) hit_l->t1 = hit_r->t1 ;
245 int fcfAfterburner::burn(u_int *ptr_res[3], u_int *ptr_simu_res[3])
249 last_i = last_n = last_count = last_stage = 0 ;
252 ptr_simu = ptr_simu_res ;
258 if(row < 123) do_swap = 0 ;
274 if(row == 123) row = do_swap ? swap32(*ptr[i]) : (*ptr[i]) ;
275 else if(row != (do_swap ? swap32(*ptr[i]) : (*ptr[i]))) {
277 LOG(ERR,
"Corrupted row data pointer %d: is %d expect %d",i,*ptr[i],row,0,0) ;
286 edge[0] = padfinder[row-1][0].maxpad ;
287 edge[1] = padfinder[row-1][1].minpad ;
288 edge[2] = padfinder[row-1][1].maxpad ;
289 edge[3] = padfinder[row-1][2].minpad ;
291 memset(cou_broken,0,
sizeof(cou_broken)) ;
296 int fcfAfterburner::next(
fcfHit *h)
331 res_sim = ptr_simu[last_n] ;
344 u_int irow = *res++ ;
345 last_count = *res++ ;
348 if(res_sim) res_sim += 2 ;
351 irow = swap32(irow) ;
352 last_count = swap32(last_count) ;
355 if(irow != row) LOG(ERR,
"Row %d and row %d in data don't match!!!",row,irow,0,0,0) ;
358 res += 2 + 2*last_i ;
359 if(res_sim) res_sim += 2 + (
sizeof(
struct FcfSimOutput)/4)*last_i ;
362 while(last_i < last_count) {
365 decode(res,&hit,res_sim) ;
374 if(do_merge && (hit.f & FCF_BROKEN_EDGE)) {
379 if(hit.p2 == edge[0]) list = 0 ;
380 else if(hit.p1 == edge[1]) list = 1 ;
381 else if(hit.p2 == edge[2]) list = 2 ;
382 else if(hit.p1 == edge[3]) list = 3 ;
384 if(list >= 0 && cou_broken[list]<kMax_fcfHit) {
385 memcpy(&(broken[list][cou_broken[list]]),&hit,
sizeof(hit)) ;
391 LOG(DBG,
"Row %d: incorrect edges are %d:%d, %f???",row,hit.p1,hit.p2,(
double)hit.pad/64.0+0.5,0) ;
392 LOG(DBG,
" %d %d %d %d",edge[0],edge[1],edge[2],edge[3],0) ;
397 memcpy(h,&hit,
sizeof(hit)) ;
411 if(edge[0] == 0)
return 0 ;
416 for(right=0;right<4;right+=2) {
418 for(i=0;i<cou_broken[right];i++) {
420 for(j=0;j<cou_broken[right+1];j++) {
421 if(broken[right+1][j].c == 0) continue ;
424 merged = check_merge(&broken[right][i],&broken[right+1][j]) ;
438 if(last_n >= 4)
return 0 ;
439 while(last_i<cou_broken[last_n]) {
440 if(output(&broken[last_n][last_i])) {
441 memcpy(h,&broken[last_n][last_i],
sizeof(
fcfHit)) ;
461 int fcfAfterburner::compare(u_int *p1[3], u_int *p2[3])
463 u_int matched1, count1, count2 ;
467 static u_char marray[2][10000] ;
470 int save_merge, save_cuts ;
473 save_merge = do_merge ;
474 save_cuts = do_cuts ;
479 do_merge = do_cuts = 0 ;
480 after.do_merge = after.do_cuts = 0 ;
482 memset(marray,0,
sizeof(marray)) ;
485 matched1 = count1 = 0 ;
495 while(after.next(&h2)) {
497 if(marray[1][count2]) {
502 if(memcmp(&h1,&h2,
sizeof(h1))==0) {
503 marray[1][count2] = 1 ;
512 marray[0][count1] = 1 ;
521 if(marray[0][i] == 0) {
528 if(verbose) print_hit(
"UNMATCHED 1",&h1) ;
537 while(after.next(&h1)){
538 if(marray[1][i] == 0) {
545 if(verbose) print_hit(
"UNMATCHED 2",&h1) ;
553 do_cuts = save_cuts ;
554 do_merge = save_merge ;