// // To compile: gcc -o find_TMBLCT find_TMBLCT.c // // This program expects the input file name as run[xyzxyz].dat // and xyzxyz will be the input to run this program. // // #include #include #include #include /* sleep function */ #include /* Usual interrupt handler stuff */ #include main(){ int findFlag, tmbLctId; int ierr, num, buf[4]; int bxn_pretrg, pre_bxn, cnt_multimu; FILE *fp,*fpout; char Filename[50]; char RunName[50]; // printf("Input Run Name: "); // scanf("%s",RunName); // sprintf(Filename,"run%s.dat",RunName); scanf("%s",Filename); fp=fopen(Filename,"r"); ierr=1; findFlag = -1; cnt_multimu = 0; pre_bxn = 0; bxn_pretrg = 0; tmbLctId = 0; while(ierr>0){ ierr=fscanf(fp,"%d %04x %04x %04x %04x\n",&num,&buf[3],&buf[2],&buf[1],&buf[0]); if ( findFlag < 0 ) { // check for 1st DMB Header2 (must occur immediately after DDU header!) if( ( ((buf[3]&0xf000)==0xa000)&&((buf[2]&0xf000)==0xa000)&& ((buf[1]&0xf000)==0xa000)&&((buf[0]&0xf000)==0xa000) ) || ( ((buf[3]&0xf000)==0xd000)&&((buf[2]&0xf000)==0xd000)&& ((buf[1]&0xf000)==0xd000)&&((buf[0]&0xf000)==0xd000) ) ) { findFlag++; } } else if ( findFlag == 0 ) { if( (buf[0]&0x0fff)==0x0b0c ) { findFlag++; } else { findFlag = -1; } } else if ( findFlag == 1 ) { // Find BXN. bxn_pretrg = buf[3]&0x0fff ; findFlag++; } else { // if ( findFlag > 1 ) if( findFlag < 3 ) { findFlag++; } else if ( findFlag == 3 ) { if ( (buf[1] & 0xF000) == 0 ) { buf[1] = buf[1] | 0x8000; buf[3] = buf[3] | 0x8000; } tmbLctId++; if ( bxn_pretrg == pre_bxn) { // Find mutiple TMB data. printf("%d %04x %04x %04x %04x %04x",tmbLctId+1000, buf[0]|0x8000, buf[1], buf[2]|0x8000, buf[3], bxn_pretrg ); cnt_multimu++; } else { printf("%d %04x %04x %04x %04x %04x",tmbLctId, buf[0]|0x8000, buf[1], buf[2]|0x8000, buf[3], bxn_pretrg ); } pre_bxn = bxn_pretrg ; findFlag++; } else if ( findFlag == 4 ) { // Find MPC accept latched after delay. printf(" %04x\n", (buf[0]&0x0030) ); findFlag = -1; } else { findFlag = -1; } } } fclose(fp); // printf("# bunch crossings having multiple muons = %d\n", cnt_multimu); }