00001 unsigned short GetWord(FILE* file){
00002
00003 unsigned char lo_char, hi_char;
00004 unsigned short word;
00005
00006 if(file==NULL){
00007 printf("bad file\n");
00008 return 0;
00009 }
00010
00011
00012 lo_char = fgetc(file);
00013 hi_char = fgetc(file);
00014
00015 if(lo_char == EOF || hi_char == EOF) {
00016 printf("end of file\n");
00017 return 0;
00018 }
00019
00020
00021 word = (hi_char<<8)+lo_char;
00022
00023 return word;
00024 }
00025
00026 unsigned long GetLWord(FILE* file){
00027
00028 unsigned char lo_char, hi_char;
00029 unsigned char lo_char2, hi_char2;
00030 unsigned long word;
00031
00032 if(file==NULL){
00033 printf("bad file\n");
00034 return 0;
00035 }
00036
00037
00038 lo_char = fgetc(file);
00039 hi_char = fgetc(file);
00040 lo_char2 = fgetc(file);
00041 hi_char2 = fgetc(file);
00042
00043 if(lo_char == EOF || hi_char == EOF) {
00044 printf("end of file\n");
00045 return 0;
00046 }
00047
00048
00049 word = (hi_char2<<24)+(lo_char2<<16) + (hi_char<<8)+lo_char;
00050
00051 return word;
00052 }
00053
00054 void DispHistogram(char* infname, int occ=0) {
00055
00056
00057
00058 char htitle[128];
00059 char hname[32];
00060
00061 int i,j;
00062 unsigned short header[8];
00063 unsigned short trailer[8];
00064 unsigned long data[1024*2];
00065 unsigned short chan,chip;
00066
00067 TH1F* h_scan_evcnt;
00068 TH1F* h_scan_errcnt;
00069 TH2F* h_scan0;
00070 TH2F* h_scan1;
00071
00072 TH2F* h_occCount[12];
00073
00074 FILE* infile;
00075
00076
00077 infile = fopen(infname,"rb");
00078
00079 if(infile==NULL) {
00080 printf("Could not open file %s\n",infname);
00081 return;
00082 }
00083
00084 int dontSkip = 0;
00085
00086 short version = GetWord(infile);
00087 short length = GetWord(infile);
00088 dontSkip += 1;
00089
00090 int run = GetLWord(infile);
00091 int scan = GetLWord(infile);
00092 dontSkip += 2;
00093
00094 char moduleName[16];
00095 for(int i=0; i<16; i++) {
00096 moduleName[i] = fgetc(infile);
00097 }
00098 dontSkip +=4;
00099
00100 if(version == 1) {
00101 char startTime[16];
00102 for(int i=0; i<16; i++) {
00103 startTime[i] = fgetc(infile);
00104 }
00105 dontSkip +=4;
00106 printf("Started: %s\n", startTime);
00107
00108 char endTime[16];
00109 for(int i=0; i<16; i++) {
00110 endTime[i] = fgetc(infile);
00111 }
00112 dontSkip +=4;
00113
00114 printf("Finished: %s\n", endTime);
00115 }
00116
00117 short scanType = GetWord(infile);
00118 short nBins = GetWord(infile);
00119 dontSkip ++;
00120
00121 int size = GetLWord(infile);
00122 dontSkip ++;
00123 short type = GetWord(infile);
00124 short width = GetWord(infile);
00125
00126 if(!(width == 32 || width == 16)) {
00127 cout << "Bad data width: " << width << endl;
00128 return;
00129 } else {
00130 cout << "Data width: " << width << endl;
00131 }
00132
00133 dontSkip ++;
00134
00135 int bursts = nBins;
00136
00137 dontSkip +=4;
00138
00139 for(int i=0; i<length/4-dontSkip; i++) {
00140 unsigned long dummy = GetLWord(infile);
00141 }
00142
00143 unsigned long pointer = GetLWord(infile);
00144 unsigned long pEvents = GetLWord(infile);
00145 unsigned long pErrors = GetLWord(infile);
00146 unsigned long pData = GetLWord(infile);
00147
00148 for(int i=0; i<(pointer-length)/4; i++) {
00149 unsigned long dummy = GetLWord(infile);
00150 }
00151
00152 printf("nbins = %d\n", nBins);
00153 float *threshold = new float[bursts];
00154 unsigned long *eventCount = new unsigned long[bursts];
00155 unsigned long *errorCount = new unsigned long[bursts];
00156
00157
00158 for(int i=0; i<bursts; i++) {
00159 unsigned long word = GetLWord(infile);
00160 threshold[i] = *((float*)(&word));
00161 }
00162
00163
00164 for(int i=0; i<bursts; i++) {
00165 unsigned long events = GetLWord(infile);
00166 eventCount[i] = events;
00167 }
00168
00169
00170 for(int i=0; i<bursts; i++) {
00171 unsigned long errors = GetLWord(infile);
00172 errorCount[i] = errors;
00173 }
00174
00175 double hist_start;
00176 double hist_stop;
00177
00178
00179
00180 float step = threshold[1] - threshold[0];
00181 if(threshold[0] < threshold[bursts-1]) {
00182 hist_start = threshold[0];
00183 hist_stop = threshold[bursts-1] + step;
00184 } else {
00185 hist_start = threshold[bursts-1];
00186 hist_stop = threshold[0] - step;
00187 }
00188 printf("start %3.2f stop %3.2f\n",hist_start, hist_stop);
00189
00190 sprintf(htitle,"ROD Events Requested");
00191 sprintf(hname,"h_scan_evcnt");
00192 h_scan_evcnt = new TH1F(hname, htitle, bursts, hist_start, hist_stop);
00193 h_scan_evcnt->SetFillColor(46);
00194
00195 sprintf(htitle,"ROD Errors Counted");
00196 sprintf(hname,"h_scan_errcnt");
00197 h_scan_errcnt = new TH1F(hname, htitle, bursts, hist_start, hist_stop);
00198 h_scan_errcnt->SetFillColor(46);
00199
00200 sprintf(htitle, "%s Stream 0 THRESHOLD Scan", moduleName);
00201 sprintf(hname,"h_scan0_0");
00202 h_scan0 = new TH2F(hname,htitle, 768,0.5,768.5, bursts, hist_start, hist_stop);
00203 h_scan0->SetXTitle("Channel Number");
00204 h_scan0->SetYTitle("THRESHOLD (mV)");
00205
00206 sprintf(htitle, "%s Stream 1 THRESHOLD Scan", moduleName);
00207 sprintf(hname,"h_scan1_0");
00208 h_scan1 = new TH2F(hname,htitle, 768,0.5,768.5, bursts, hist_start, hist_stop);
00209 h_scan1->SetXTitle("Channel Number");
00210 h_scan1->SetYTitle("THRESHOLD (mV)");
00211
00212 printf("Creating chip occupancy histos\n");
00213
00214 Double_t xBins[1+128/4 + 1];
00215 xBins[0] = 0;
00216 for(int i=0; i<128/4 + 1; i++) {
00217 xBins[i+1] = i*4+1.0;
00218 }
00219
00220 for(int c=0; c<12; c++) {
00221 sprintf(htitle, "%s Chip %d Occupancy counts", moduleName, c);
00222 sprintf(hname,"h_occCount_%d", c);
00223
00224 h_occCount[c] = new TH2F(hname,htitle, 33, xBins, bursts, hist_start, hist_stop);
00225 h_occCount[c]->SetXTitle("Channel count");
00226 h_occCount[c]->SetYTitle("THRESHOLD (mV)");
00227 }
00228
00229 printf("Filling event counts...\n");
00230
00231 for(j=0;j<bursts;j++) {
00232 h_scan_evcnt->Fill(threshold[j],eventCount[j]);
00233 h_scan_errcnt->Fill(threshold[j],errorCount[j]);
00234 }
00235
00236 int slice = 1;
00237 int chipNumber;
00238 Axis_t channelAxis;
00239 int value;
00240 if(slice) {
00241 printf("Building slice histogram...\n");
00242
00243 for(j=0;j<bursts;j++){
00244 int words, skip;
00245 if(type == 16 || type == 6) {
00246 words = 768*2; skip = 0;
00247 } else {
00248 words = 1024*2; skip = 1024-768;
00249 }
00250 for(i=0;i<words;i++){
00251
00252 if(width == 32) {
00253 data[i]=GetLWord(infile);
00254 } else if(width == 16) {
00255 data[i]=GetWord(infile);
00256 }
00257
00258 if(i>0 && i<768)
00259 h_scan0->Fill(i,threshold[j],data[i]);
00260
00261 if(i>(768 + skip) && i<(words-skip))
00262 h_scan1->Fill(i-(768 + skip),threshold[j],data[i]);
00263
00264 if(occ && !(type == 16 || type == 6)) {
00265 if((i>=768 && i<768 + 32 * 6) || (i>=(768 + 1024) && i<1024 + 768 + 32 * 6)) {
00266
00267
00268 if(i<1024) {
00269 chipNumber = (i-768)/32;
00270 channelAxis = (i-768) - 32*chipNumber;
00271 channelAxis = channelAxis * 4 + 2;
00272 } else {
00273 chipNumber = 6+(i-(1024+768))/32;
00274
00275 channelAxis = (i-(1024+768)) - 32*(chipNumber-6);
00276 channelAxis = channelAxis * 4 + 2;
00277 }
00278
00279 value = data[i];
00280 h_occCount[chipNumber]->Fill(channelAxis, threshold[j], value);
00281 }
00282 }
00283 }
00284
00285 }
00286 } else {
00287 for(i=0;i<512;i++){
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 for(j=0;j<8;j++){
00308 header[j]=GetWord(infile);
00309 }
00310
00311
00312 for(j=0;j<bursts;j++){
00313 data[j]=GetWord(infile);
00314 }
00315
00316
00317 for(j=0;j<8;j++){
00318 trailer[j]=GetWord(infile);
00319 }
00320
00321
00322 chan = (header[1]*128)+header[0];
00323
00324 for(j=0;j<bursts;j++){
00325 h_scan0->Fill(chan,threshold[j],data[j]);
00326 }
00327
00328 }
00329
00330 }
00331
00332 fclose(infile);
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 printf("Draw scan0\n");
00343
00344 TCanvas *c1 = new TCanvas;
00345 h_scan_evcnt->Print();
00346 h_scan0->Print();
00347 h_scan0->Draw("colz");
00348
00349 printf("Draw evcnt\n");
00350 TCanvas *cev = new TCanvas;
00351 h_scan_evcnt->Draw();
00352
00353 printf("Draw scan0\n");
00354
00355 TCanvas *c2 = new TCanvas;
00356 h_scan1->Print();
00357 h_scan1->Draw("colz");
00358
00359 if(occ) {
00360 TCanvas *c3 = new TCanvas;
00361 c3->Divide(4, 3);
00362 for(int c=0; c<12; c++) {
00363 c3->cd(c+1);
00364
00365
00366 h_occCount[c]->Draw("colz");
00367 }
00368 }
00369 }