/* Analyze L1 Specific Trigger Overlap Revision: 24-AUG-1994 by Daniel Edmunds */ #include /* I/O definitions */ #include #include #define MAXLINE 80 #define CHAROFFSET 19 int counter[40][40]; main() { int fndx, sndx, charndx, sptrgndx, count_events, physics_events; int fired, kndx, lndx; int line_length; extern int counter[40][40]; char line[135]; char outstr[135]; char filename[MAXLINE]; FILE *fpin, *fpout; /* Get the filename of the input and output files */ printf("Enter the filename of the raw overlap data file: "); gets(filename); if ((fpin = fopen(filename, "r")) == NULL) { printf("\nERROR: Can't open input file %s\n", filename); exit (1); } printf("Enter the filename of the output text file: "); gets(filename); if ((fpout = fopen(filename, "w", "rat=cr", "rfm=var")) == NULL) { printf("\nERROR: Can't open output file %s\n", filename); exit (2); } /* Now that we have the filenames we can start the actual work */ for (fndx = 0; fndx <= 32; ++fndx) { for (sndx = 0; sndx <= 32; ++sndx) counter[fndx][sndx] = 0; } count_events = 0; fgets(line, MAXLINE, fpin); while (line[0] != NULL) { ++count_events; first_scan(line); fgets(line, MAXLINE, fpin); } physics_events = count_events - counter[31][31]; sprintf(outstr, "\n Number of Events Processed = %d \n", count_events); fputs(outstr, fpout); sprintf(outstr, " Number of Monitor Data Only Events = %d \n", counter[31][31]); fputs(outstr, fpout); sprintf(outstr, " Number of Physics Events = %d \n", physics_events ); fputs(outstr, fpout); for (sptrgndx = 31; sptrgndx >= 0; --sptrgndx) { fired = counter[sptrgndx][sptrgndx]; sprintf(outstr, "\n\n\n Specific Trigger = %d", sptrgndx); fputs(outstr, fpout); sprintf(outstr, " This Spec Trig Fired %d times. \n", fired); fputs(outstr, fpout); sprintf(outstr, "\n Overlap Counts with Spec Trig's 31:0 \n"); fputs(outstr, fpout); for (lndx = 0; lndx <= 3; ++lndx){ for (kndx = 0; kndx <= 7; ++kndx){ sprintf(outstr, "%6d%c", counter[sptrgndx][31 - kndx - (8 * lndx)], (kndx == 7) ? '\n' : ' '); fputs(outstr, fpout); } } sprintf(outstr, "\n Percentage Overlap with Spec Trig's 31:0 \n"); fputs(outstr, fpout); if (fired == 0) fired = 100000000; for (lndx = 0; lndx <= 3; ++lndx){ for (kndx = 0; kndx <= 7; ++kndx){ sprintf(outstr, "%6d%c", ((100 * counter[sptrgndx] [31 - kndx - (8 * lndx)]) / fired), (kndx == 7) ? '\n' : ' '); fputs(outstr, fpout); } } } fclose(fpin); fclose(fpout); } /* First Scan Routine */ first_scan(myline) char myline[135]; { extern int counter[40][40]; int charndx, bndx; unsigned thischar; for (charndx = 0; charndx <= 7; ++charndx) { thischar = myline[charndx + CHAROFFSET]; for (bndx = 0; bndx <= 3; ++bndx) { if (thischar & 01) search(28 + bndx - (4 * charndx), myline); thischar >>= 1; } } } /* Second Scan and Counter Increment Routine */ search(ndxf, myline) int ndxf; char myline[135]; { extern int counter[40][40]; int charndx, bndx; unsigned thischar; for (charndx = 0; charndx <= 7; ++charndx) { thischar = myline[charndx + CHAROFFSET]; for (bndx = 0; bndx <= 3; ++bndx) { if (thischar & 01) ++counter[ndxf][28 + bndx - (4 * charndx)]; thischar >>= 1; } } } /* Read a line from stdin and put it in the array loc_chars. Terminate the loc_chars array with a \0 null character. Return the number of characters read in this line. */ getline(loc_chars, limit) char loc_chars[]; int limit; { int this_char, indx; for (indx=0; indx < limit-1 && (this_char = getchar()) != EOF && this_char != '\n'; ++indx) loc_chars[indx] = this_char; if (this_char == '\n') { loc_chars[indx] = this_char; ++indx; } loc_chars[indx] = '\0'; return(indx); }