Main Page   Modules   Namespace List   Class Hierarchy   Data Structures   File List   Namespace Members   Data Fields   Globals   Related Pages  

DispHistogram.cpp

Go to the documentation of this file.
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   // Read two bytes
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   // Swap bytes to form 16 bit word
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   // Read four bytes
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   // Swap bytes to form 16 bit word
00049   word = (hi_char2<<24)+(lo_char2<<16) + (hi_char<<8)+lo_char;
00050 
00051   return word;
00052 }
00053 
00054 void DispHistogram(char* infname) { // , float start, float step, int bursts) {
00055 
00056   // Convert ROD histograms to SCTDAQ format
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   TH2F* h_scan0;
00069   TH2F* h_scan1;
00070 
00071   FILE* infile;
00072   TFile* outfile;
00073 
00074   infile = fopen(infname,"rb");
00075 
00076   if(infile==NULL) {
00077     printf("Could not open file %s\n",infname);
00078     return;
00079   }  
00080 
00081   int dontSkip = 0;
00082 
00083   short version = GetWord(infile);          // version
00084   short length = GetWord(infile);
00085   dontSkip += 1;
00086 
00087   int run = GetLWord(infile);
00088   int scan = GetLWord(infile);
00089   dontSkip += 2;
00090 
00091   char moduleName[16];
00092   for(int i=0; i<16; i++) {
00093     moduleName[i] = fgetc(infile);
00094   }
00095   dontSkip +=4;
00096 
00097   short scanType = GetWord(infile);           // scanType
00098   short nBins = GetWord(infile);
00099   dontSkip ++;
00100 
00101   int size = GetLWord(infile);
00102   dontSkip ++;
00103   short type = GetWord(infile);
00104   short width = GetWord(infile);
00105   dontSkip ++;
00106 
00107   int bursts = nBins;
00108 
00109   dontSkip +=4;            // Dont skip pointers
00110 
00111   for(int i=0; i<length/4-dontSkip; i++) {
00112     unsigned long dummy = GetLWord(infile);
00113   }
00114 
00115   unsigned long pointer = GetLWord(infile);     // Pointer to thresholds
00116   unsigned long pEvents = GetLWord(infile);
00117   unsigned long pErrors = GetLWord(infile);
00118   unsigned long pData = GetLWord(infile);       // Pointer to data
00119 
00120   for(int i=0; i<(pointer-length)/4; i++) {   // Presumably 0
00121     unsigned long dummy = GetLWord(infile);
00122   }
00123 
00124   printf("nbins = %d\n", nBins);
00125   float *threshold = new float[bursts];
00126 
00127   for(int i=0; i<bursts; i++) {
00128     unsigned long word = GetLWord(infile);
00129     threshold[i] = *((float*)(&word));
00130   }
00131 
00132   for(int i=0; i<bursts; i++) {
00133     unsigned long events = GetLWord(infile);
00134   }
00135 
00136   for(int i=0; i<bursts; i++) {
00137     unsigned long errors = GetLWord(infile);
00138   }
00139 
00140   double hist_start;
00141   double hist_stop;
00142   float fist_start;
00143   float fist_stop;
00144 
00145   //  hist_start = start-(step/2);
00146   //  hist_stop =  start+(112*step)+(step/2);
00147   float step = threshold[1] - threshold[0];
00148   if(threshold[0] < threshold[bursts-1]) {
00149     hist_start = threshold[0]; // start;
00150     hist_stop =  threshold[bursts-1] + step; // start+(bursts*step);
00151   } else {
00152     hist_start =  threshold[bursts-1] + step; // start+(bursts*step);
00153     hist_stop = threshold[0]; // start;
00154   }
00155   printf("start %3.2f stop %3.2f\n",hist_start, hist_stop);
00156 
00157   fist_start = hist_start;
00158   fist_stop =  hist_stop;
00159   printf("start %3.2f stop %3.2f\n",fist_start, fist_stop);
00160 
00161   sprintf(htitle,"ROD Events Requested");
00162   sprintf(hname,"h_scan_evcnt");
00163   h_scan_evcnt = new TH1F(hname, htitle, bursts, hist_start, hist_stop);
00164   h_scan_evcnt->SetFillColor(46);
00165 
00166   sprintf(htitle, "%s Stream 0 THRESHOLD Scan", moduleName);
00167   sprintf(hname,"h_scan0_0");
00168   h_scan0 = new TH2F(hname,htitle, 768,0.5,768.5, bursts, hist_start, hist_stop);
00169   h_scan0->SetXTitle("Channel Number");
00170   h_scan0->SetYTitle("THRESHOLD (mV)");
00171 
00172   sprintf(htitle, "%s Stream 1 THRESHOLD Scan", moduleName);
00173   sprintf(hname,"h_scan1_0");
00174   h_scan1 = new TH2F(hname,htitle, 768,0.5,768.5, bursts, hist_start, hist_stop);
00175   h_scan1->SetXTitle("Channel Number");
00176   h_scan1->SetYTitle("THRESHOLD (mV)");
00177 
00178   for(j=0;j<bursts;j++) {
00179     h_scan_evcnt->Fill(threshold[j],50);  // hardcoded to 50 events
00180   }
00181 
00182   int slice = 1;
00183   if(slice) {
00184     for(j=0;j<bursts;j++){
00185       int words, skip;
00186       if(type == 16 || type == 6) {
00187         words = 768*2; skip = 0;
00188       } else {
00189         words = 1024*2; skip = 1024-768;
00190       }
00191       for(i=0;i<words;i++){
00192         // data
00193         data[i]=GetLWord(infile);
00194 
00195         if(i>0    && i<768)
00196           h_scan0->Fill(i,threshold[j],data[i]);
00197         if(i>(768 + skip) && i<(words-skip))
00198           h_scan1->Fill(i-(768 + skip),threshold[j],data[i]);
00199       }
00200 //      printf("%s\n", (char *)&data[i-8]);
00201     }
00202   } else {
00203     for(i=0;i<512;i++){
00204 
00205       // For each channel we get 100 hex data words:
00206       //    
00207       // Event format
00208       // Header - 8 16 bit words
00209       // 00 - Chan Chip
00210       // 04 - 0000 0000
00211       // 08 - BBBB BBBB
00212       // 0C - BBBB BBBB
00213       //
00214       // Now the real data
00215       //
00216       // Trailer - 8 16 bit words
00217       // F0 - FFFF FFFF 
00218       // F4 - FFFF FFFF 
00219       // F8 - FFFF FFFF 
00220       // FC - FFFF FFFF
00221 
00222       // header
00223       for(j=0;j<8;j++){
00224         header[j]=GetWord(infile);
00225       }
00226 
00227       // data
00228       for(j=0;j<bursts;j++){
00229         data[j]=GetWord(infile);
00230       }
00231 
00232       // trailer
00233       for(j=0;j<8;j++){
00234         trailer[j]=GetWord(infile);
00235       }
00236 
00237       // Fill SCTDAQ scan Histogram
00238       chan = (header[1]*128)+header[0];
00239 
00240       for(j=0;j<bursts;j++){
00241         h_scan0->Fill(chan,threshold[j],data[j]);
00242       }
00243     
00244     } 
00245 
00246   }
00247 
00248   fclose(infile);
00249 
00250   outfile = new TFile("rod.root","RECREATE");
00251 
00252   h_scan0->Write("h_scan0");
00253   h_scan1->Write("h_scan1");
00254   h_scan_evcnt->Write("h_scan_evcnt");
00255 
00256   outfile->Close();
00257 
00258   TCanvas *c1 = new TCanvas;
00259   h_scan_evcnt->Print();
00260   h_scan0->Print();
00261   h_scan0->Draw("colz");
00262 
00263   TCanvas *c2 = new TCanvas;
00264   h_scan1->Print();
00265   h_scan1->Draw("colz");
00266 }

Generated on Mon Dec 15 19:36:00 2003 for SCT DAQ/DCS Software by doxygen1.3-rc3