// // Quick parser for ICRR waveform data // // J. Kelley // 24 Oct 2007 // // Global waveform storage Short_t dis_lab3_a[9][256]; Short_t dis_lab3_a_xtra[9][4]; Short_t dis_lab3_b[9][256]; Short_t dis_lab3_b_xtra[9][4]; Short_t bat_lab3_c[9][256]; Short_t bat_lab3_c_xtra[9][4]; //------------------------------------------------------------- void setPlotStyle(void) { gStyle->SetPalette(1,0); gStyle->SetPadBorderMode(0); gStyle->SetPadColor(0); gStyle->SetCanvasColor(0); gStyle->SetTitleColor(1); gStyle->SetStatColor(0); gStyle->SetFillColor(0); } //------------------------------------------------------------- // // Loads binary event files generated by IceRay.py // with prefix as specified. Plots an averaged FFT for BAT // channel (1-9). // void plotAllWF(Char_t *prefix, Int_t nFiles, Int_t ch) { Char_t titleStr[100]; setPlotStyle(); // Bin size for BAT channels Float_t nsPerBin = 1.0; // Plot time domain, BAT Int_t nBins = 256-4; // FFT coadd histogram // Conversion to MHz Float_t MHzPerBin = 1000/(nBins*nsPerBin); TH1F *hFreq = new TH1F("hFreq", "hFreq", nBins/2, 0, (nBins/2)*MHzPerBin); // Loop over files for (Int_t fN = 1; fN <= nFiles; fN++) { Char_t filename[100]; sprintf(filename, "%s.%d.bin", prefix, fN); // Parse the binary data file readWF(filename); // Find the hitBus 4 samples and ignore them Int_t hitBin = 0; for (Int_t i = 1; i < 256; i++) { if ((bat_lab3_c[ch-1][i] & 0x1000) > 0) { hitBin = i; break; } } // Very crude "pedestal" calculation Double_t pedestal = 0.0; for (Int_t i = 1; i <= 50; i++) { pedestal += bat_lab3_c[ch-1][i] & 0xfff; } pedestal /= 50.0; // Plot time domain, BAT TH1F *hTime = new TH1F("hTime", "hTime", nBins, 0, nBins); Int_t bin = 1; for (Int_t samp = 0; samp < 256; samp++) { if ((samp < hitBin) || (samp >= hitBin+4)) { hTime->SetBinContent(bin, (bat_lab3_c[ch-1][samp] & 0xfff)-pedestal); bin++; } } //hTime->Draw(); TH1F *hRawFreq = new TH1F("hRawFreq", "hRawFreq", nBins, 0, nBins); hTime->FFT(hRawFreq, "Mag R2C M"); for (Int_t i = 1; i <= nBins/2; i++) { Double_t f = hRawFreq->GetBinCenter(i)*MHzPerBin; hFreq->Fill(f,hRawFreq->GetBinContent(i)); } hTime->Delete(); hRawFreq->Delete(); } // End file loop hFreq->Scale(1.0/nFiles); hFreq->Rebin(1); hFreq->GetXaxis()->SetTitle("Freq. (MHz)"); sprintf(titleStr, "BAT%d FFT, %d waveforms", ch, nFiles); hFreq->SetTitle(titleStr); hFreq->SetLineColor(kBlue); hFreq->Draw(); } //------------------------------------------------------------- // // Loads a single binary event file as generated from IceRay.py // and specified by and plots the waveform for a single BAT // channel (1-9) and its FFT. Typically one would start with // = 0. // void plotWF(Char_t *filename, Int_t startBin, Int_t ch) { setPlotStyle(); TCanvas *myc = new TCanvas("myc", "Waveform and FFT", 800, 600); TPad *c1_1 = new TPad("c1_1", "c1_1",0.01,0.51,0.99,0.99); TPad *c1_2 = new TPad("c1_2", "c1_2",0.01,0.01,0.99,0.49); c1_1->Draw(); c1_2->Draw(); // Parse the binary data file readWF(filename); Double_t pedestal = 0.0; // Offset here is for historical reasons :) for (Int_t i = 2; i <= 51; i++) { pedestal += bat_lab3_c[ch-1][i] & 0xfff; } pedestal /= 50; // Bin size for BAT channels Float_t nsPerBin = 1.0; // Plot time domain, BAT Int_t nBins = 256-4; TH1F *hTime = new TH1F("hTime", "hTime", nBins, 0, nBins); for (Int_t samp = 0; samp < 256; samp++) { if (samp >= startBin) { hTime->SetBinContent(samp-startBin+1, (bat_lab3_c[ch-1][samp] & 0xfff)-pedestal); //hTime->SetBinContent(samp-startBin+1, sin(2*3.14*(samp-startBin+1)*0.1)); } } Char_t titleStr[100]; sprintf(titleStr, "BAT%d Forced Trigger", ch); hTime->SetTitle(titleStr); hTime->GetYaxis()->SetTitle("LAB3_C"); hTime->GetXaxis()->SetTitle("Time (ns)"); hTime->SetLineWidth(1.0); hTime->SetLineColor(kRed); c1_1->cd(); hTime->Draw(); TH1F *hRawFreq = new TH1F("hRawFreq", "hRawFreq", nBins, 0, nBins); hTime->FFT(hRawFreq, "Mag R2C M"); // Conversion to MHz Float_t MHzPerBin = 1000/(nBins*nsPerBin); TH1F *hFreq = new TH1F("hFreq", "hFreq", nBins/2, 0, (nBins/2)*MHzPerBin); for (Int_t i = 1; i <= nBins/2; i++) { Double_t f = hRawFreq->GetBinCenter(i)*MHzPerBin; hFreq->Fill(f,hRawFreq->GetBinContent(i)); } hFreq->GetXaxis()->SetTitle("Freq. (MHz)"); sprintf(titleStr, "BAT%d FFT", ch); hFreq->SetTitle(titleStr); hFreq->SetLineColor(kBlue); c1_2->cd(); hFreq->Rebin(3); hFreq->Draw(); } //------------------------------------------------------------- // // Read a single event binary file (14240K) into the global // waveform storage arrays. No checking is performed! // void readWF(Char_t *filename) { ifstream in; in.open(filename, ios::binary); // Skip header business Char_t header[6]; in.read(header, 6); // Should be "12 34" // printf("Check %x %x\n", header[2], header[3]); // LAB3_A for (Int_t ch = 0; ch < 9; ch++) in.read((char *)(dis_lab3_a[ch]), 256*sizeof(Short_t)); for (Int_t ch = 0; ch < 9; ch++) in.read((char *)(dis_lab3_a_xtra[ch]), 4*sizeof(Short_t)); // LAB3_B for (Int_t ch = 0; ch < 9; ch++) in.read((char *)(dis_lab3_b[ch]), 256*sizeof(Short_t)); for (Int_t ch = 0; ch < 9; ch++) in.read((char *)(dis_lab3_b_xtra[ch]), 4*sizeof(Short_t)); // LAB3_C for (Int_t ch = 0; ch < 9; ch++) in.read((char *)(bat_lab3_c[ch]), 256*sizeof(Short_t)); for (Int_t ch = 0; ch < 9; ch++) in.read((char *)(bat_lab3_c_xtra[ch]), 4*sizeof(Short_t)); in.close(); }