#include int plotTOF_waveform(std::string infilename = "", Int_t MAX = 100, Bool_t figs = false){ if(infilename == ""){ cout << " Usage plotTOF_waveform( [infile name] )" << endl; abort(); } TFile *infile = new TFile(infilename.c_str()); TTree *intree = (TTree*)infile->Get("timingTree"); const Int_t NMAX = 500; const Double_t ADC_SCALE = 0.0625; // 62.5 ps/count Int_t nTOF; Int_t nTOF_TDC; UShort_t waveform_tof_adc[NMAX][100]; Float_t tof_adc_time[NMAX]; Float_t tof_tdc_time[NMAX]; Float_t tof_adc_pulse_integral[NMAX]; Float_t tof_adc_pedestal[NMAX]; Int_t tof_adc_nsamples_integral[NMAX]; Int_t tof_adc_nsamples_pedestal[NMAX]; Int_t tof_adc_QF[NMAX]; Float_t tof_adc_signal[NMAX]; // TOF channel info Int_t tof_adc_plane[NMAX]; Int_t tof_tdc_plane[NMAX]; Int_t tof_adc_bar[NMAX]; Int_t tof_tdc_bar[NMAX]; Int_t tof_adc_end[NMAX]; Int_t tof_tdc_end[NMAX]; // ADC hit info intree->SetBranchAddress("nTOF",&nTOF); intree->SetBranchAddress("tof_adc_time",tof_adc_time); intree->SetBranchAddress("tof_adc_pulse_integral",tof_adc_pulse_integral); intree->SetBranchAddress("tof_adc_pedestal",tof_adc_pedestal); intree->SetBranchAddress("tof_adc_nsamples_integral",tof_adc_nsamples_integral); intree->SetBranchAddress("tof_adc_nsamples_pedestal",tof_adc_nsamples_pedestal); intree->SetBranchAddress("tof_adc_QF",tof_adc_QF); if(figs) intree->SetBranchAddress("waveform_tof_adc",waveform_tof_adc); // TDC hit time intree->SetBranchAddress("tof_tdc_time",tof_tdc_time); // TOF channel info intree->SetBranchAddress("tof_adc_plane",tof_adc_plane); intree->SetBranchAddress("tof_tdc_plane",tof_tdc_plane); intree->SetBranchAddress("tof_adc_bar",tof_adc_bar); intree->SetBranchAddress("tof_tdc_bar",tof_tdc_bar); intree->SetBranchAddress("tof_adc_end",tof_adc_end); intree->SetBranchAddress("tof_tdc_end",tof_tdc_end); TFile *outfile = new TFile("results.root","recreate"); TGraph *gwaveform = new TGraph(100); gwaveform->SetName("gwaveform"); gwaveform->SetTitle(""); gwaveform->GetXaxis()->SetTitle("sample #"); gwaveform->GetXaxis()->CenterTitle(); gwaveform->GetYaxis()->SetTitle("ADC counts"); gwaveform->GetYaxis()->CenterTitle(); gwaveform->SetMarkerColor(kRed); gwaveform->SetMarkerStyle(20); gwaveform->SetMarkerSize(0.8); gwaveform->SetLineColor(kRed); gwaveform->SetLineStyle(1); gwaveform->SetLineWidth(1); TH1F *htof_adc_time = new TH1F("htof_adc_time",";tof_adc_time",800,0,400); TH1F *htof_adc_pulse_integral = new TH1F("htof_adc_pulse_integral",";tof_adc_pulse_integral",250,0,50000); TH1F *htof_adc_pedestal = new TH1F("htof_adc_pedestal",";tof_adc_pedestal",250,-0.5,249.5); TH1F *htof_adc_nsamples_pedestal = new TH1F("htof_adc_nsamples_pedestal",";tof_adc_nsamples_pedestal",20,-0.5,19.5); TH1F *htof_adc_nsamples_integral = new TH1F("htof_adc_nsamples_integral",";tof_adc_nsamples_integral",70,-0.5,69.5); TH1F *htof_adc_QF = new TH1F("htof_adc_QF",";tof_adc_QF",20,-0.5,19.5); TH1F *htof_adc_signal = new TH1F("htof_adc_signal",";tof_adc_signal",250,0,50000); TH2F *htof_adc_time_integral = new TH2F("htof_adc_time_integral",";tof_adc_pulse_integral;tof_adc_time",250,0,50000,800,0,400); TH2F *htof_adc_time_signal = new TH2F("htof_adc_time_signal",";tof_adc_signal;tof_adc_time",250,0,50000,800,0,400); TH2F *htof_adc_integral_signal = new TH2F("htof_adc_integral_signal",";tof_adc_signal;tof_adc_integral",250,0,50000,250,0,50000); // adc_time = 0 TH1F *htof_adc_time___adc_time_zero = new TH1F("htof_adc_time___adc_time_zero",";tof_adc_time",800,0,400); TH1F *htof_adc_pulse_integral___adc_time_zero = new TH1F("htof_adc_pulse_integral___adc_time_zero",";tof_adc_pulse_integral",250,0,50000); TH1F *htof_adc_pedestal___adc_time_zero = new TH1F("htof_adc_pedestal___adc_time_zero",";tof_adc_pedestal",250,-0.5,249.5); TH1F *htof_adc_nsamples_pedestal___adc_time_zero = new TH1F("htof_adc_nsamples_pedestal___adc_time_zero",";tof_adc_nsamples_pedestal",20,-0.5,19.5); TH1F *htof_adc_nsamples_integral___adc_time_zero = new TH1F("htof_adc_nsamples_integral___adc_time_zero",";tof_adc_nsamples_integral",70,-0.5,69.5); TH1F *htof_adc_QF___adc_time_zero = new TH1F("htof_adc_QF___adc_time_zero",";tof_adc_QF",20,-0.5,19.5); TH1F *htof_adc_signal___adc_time_zero = new TH1F("htof_adc_signal___adc_time_zero",";tof_adc_signal",250,0,50000); TH2F *htof_adc_time_integral___adc_time_zero = new TH2F("htof_adc_time_integral___adc_time_zero",";tof_adc_pulse_integral;tof_adc_time",250,0,50000,800,0,400); TH2F *htof_adc_time_signal___adc_time_zero = new TH2F("htof_adc_time_signal___adc_time_zero",";tof_adc_signal;tof_adc_time",250,0,50000,800,0,400); TH2F *htof_adc_integral_signal___adc_time_zero = new TH2F("htof_adc_integral_signal___adc_time_zero",";tof_adc_signal;tof_adc_integral",250,0,50000,250,0,50000); // adc_time != 0 TH1F *htof_adc_time___adc_time_nonzero = new TH1F("htof_adc_time___adc_time_nonzero",";tof_adc_time",800,0,400); TH1F *htof_adc_pulse_integral___adc_time_nonzero = new TH1F("htof_adc_pulse_integral___adc_time_nonzero",";tof_adc_pulse_integral",250,0,50000); TH1F *htof_adc_pedestal___adc_time_nonzero = new TH1F("htof_adc_pedestal___adc_time_nonzero",";tof_adc_pedestal",250,-0.5,249.5); TH1F *htof_adc_nsamples_pedestal___adc_time_nonzero = new TH1F("htof_adc_nsamples_pedestal___adc_time_nonzero",";tof_adc_nsamples_pedestal",20,-0.5,19.5); TH1F *htof_adc_nsamples_integral___adc_time_nonzero = new TH1F("htof_adc_nsamples_integral___adc_time_nonzero",";tof_adc_nsamples_integral",70,-0.5,69.5); TH1F *htof_adc_QF___adc_time_nonzero = new TH1F("htof_adc_QF___adc_time_nonzero",";tof_adc_QF",20,-0.5,19.5); TH1F *htof_adc_signal___adc_time_nonzero = new TH1F("htof_adc_signal___adc_time_nonzero",";tof_adc_signal",250,0,50000); TH2F *htof_adc_time_integral___adc_time_nonzero = new TH2F("htof_adc_time_integral___adc_time_nonzero",";tof_adc_pulse_integral;tof_adc_time",250,0,50000,800,0,400); TH2F *htof_adc_time_signal___adc_time_nonzero = new TH2F("htof_adc_time_signal___adc_time_nonzero",";tof_adc_signal;tof_adc_time",250,0,50000,800,0,400); TH2F *htof_adc_integral_signal___adc_time_nonzero = new TH2F("htof_adc_integral_signal___adc_time_nonzero",";tof_adc_signal;tof_adc_integral",250,0,50000,250,0,50000); TCanvas *canvas = new TCanvas("canvas","canvas",1200,600); canvas->SetRightMargin(0.02); canvas->SetTopMargin(0.02); canvas->SetLeftMargin(0.10); canvas->SetBottomMargin(0.10); TLatex *latex = new TLatex(); latex->SetTextColor(kBlack); latex->SetTextAlign(12); latex->SetTextFont(132); latex->SetTextSize(0.060); latex->SetNDC(1); char text[200]; TLine *line_adc_time = new TLine(); line_adc_time->SetLineColor(kGreen+2); line_adc_time->SetLineWidth(1); line_adc_time->SetLineStyle(2); TLine *line_adc_pedestal = new TLine(); line_adc_pedestal->SetLineColor(kMagenta); line_adc_pedestal->SetLineWidth(1); line_adc_pedestal->SetLineStyle(2); for(Int_t n=0;nGetEntries() && n < MAX;n++){ intree->GetEntry(n); assert(nTOF < NMAX); if(n % 2000 == 0) cout << "entry " << n << " / " << intree->GetEntries() << endl; for(Int_t i=0;iSetPoint(sample,0,0); } // Fill in waveform for(Int_t sample=0;sample<100;sample++){ // cout << "sample = " << sample << " waveform = " << waveform_tof_adc[i][sample] << endl; gwaveform->SetPoint(sample,4. * (sample + 1),waveform_tof_adc[i][sample]); } tof_adc_signal[i] = tof_adc_pulse_integral[i] - tof_adc_pedestal[i] * tof_adc_nsamples_integral[i]; // histograms htof_adc_time->Fill(tof_adc_time[i] * ADC_SCALE); htof_adc_pedestal->Fill(tof_adc_pedestal[i]); htof_adc_nsamples_pedestal->Fill(tof_adc_nsamples_pedestal[i]); htof_adc_pulse_integral->Fill(tof_adc_pulse_integral[i]); htof_adc_nsamples_integral->Fill(tof_adc_nsamples_integral[i]); htof_adc_QF->Fill(tof_adc_QF[i]); htof_adc_signal->Fill(tof_adc_signal[i]); htof_adc_time_integral->Fill(tof_adc_pulse_integral[i],tof_adc_time[i] * ADC_SCALE); htof_adc_time_signal->Fill(tof_adc_signal[i],tof_adc_time[i] * ADC_SCALE); htof_adc_integral_signal->Fill(tof_adc_signal[i],tof_adc_pulse_integral[i]); // see which events have adc_time = 0 if(tof_adc_time[i] == 0){ htof_adc_time___adc_time_zero->Fill(tof_adc_time[i] * ADC_SCALE); htof_adc_pedestal___adc_time_zero->Fill(tof_adc_pedestal[i]); htof_adc_nsamples_pedestal___adc_time_zero->Fill(tof_adc_nsamples_pedestal[i]); htof_adc_pulse_integral___adc_time_zero->Fill(tof_adc_pulse_integral[i]); htof_adc_nsamples_integral___adc_time_zero->Fill(tof_adc_nsamples_integral[i]); htof_adc_QF___adc_time_zero->Fill(tof_adc_QF[i]); htof_adc_signal___adc_time_zero->Fill(tof_adc_signal[i]); htof_adc_time_integral___adc_time_zero->Fill(tof_adc_pulse_integral[i],tof_adc_time[i] * ADC_SCALE); htof_adc_time_signal___adc_time_zero->Fill(tof_adc_signal[i],tof_adc_time[i] * ADC_SCALE); htof_adc_integral_signal___adc_time_zero->Fill(tof_adc_signal[i],tof_adc_pulse_integral[i]); }else{ htof_adc_time___adc_time_nonzero->Fill(tof_adc_time[i] * ADC_SCALE); htof_adc_pedestal___adc_time_nonzero->Fill(tof_adc_pedestal[i]); htof_adc_nsamples_pedestal___adc_time_nonzero->Fill(tof_adc_nsamples_pedestal[i]); htof_adc_pulse_integral___adc_time_nonzero->Fill(tof_adc_pulse_integral[i]); htof_adc_nsamples_integral___adc_time_nonzero->Fill(tof_adc_nsamples_integral[i]); htof_adc_QF___adc_time_nonzero->Fill(tof_adc_QF[i]); htof_adc_signal___adc_time_nonzero->Fill(tof_adc_pulse_integral[i] - tof_adc_pedestal[i] * tof_adc_nsamples_integral[i]); htof_adc_time_integral___adc_time_nonzero->Fill(tof_adc_pulse_integral[i],tof_adc_time[i] * ADC_SCALE); htof_adc_time_signal___adc_time_nonzero->Fill(tof_adc_signal[i],tof_adc_time[i] * ADC_SCALE); htof_adc_integral_signal___adc_time_nonzero->Fill(tof_adc_signal[i],tof_adc_pulse_integral[i]); } if(tof_adc_pedestal[i] == 0 && tof_adc_time[i] != 0){ cout << tof_adc_pedestal[i] << " " << tof_adc_time[i] << endl; abort(); } // Draw // canvas->Update(); if(figs == true && tof_adc_time[i] < 200 && 15000. < tof_adc_pulse_integral[i]){ gwaveform->SetMinimum(0); gwaveform->SetMaximum(4200); gwaveform->GetXaxis()->SetLimits(0,400); gwaveform->Draw("ALP"); sprintf(text,"entry %d, nTOF = %d",n,i); latex->DrawLatex(0.20,0.95,text); sprintf(text,"tof_adc_time[i] = %5.2f", tof_adc_time[i]); latex->DrawLatex(0.20,0.85,text); sprintf(text,"tof_adc_pedestal[i] = %d", tof_adc_pedestal[i]); latex->DrawLatex(0.20,0.80,text); sprintf(text,"tof_adc_nsamples_pedestal[i] = %d", tof_adc_nsamples_pedestal[i]); latex->DrawLatex(0.20,0.75,text); sprintf(text,"tof_adc_pulse_integral[i] = %5.2f", tof_adc_pulse_integral[i]); latex->DrawLatex(0.20,0.70,text); sprintf(text,"tof_adc_nsamples_integral[i] = %d", tof_adc_nsamples_integral[i]); latex->DrawLatex(0.20,0.65,text); sprintf(text,"tof_adc_QF[i] = %d", tof_adc_QF[i]); latex->DrawLatex(0.20,0.60,text); // ADC time line_adc_time->SetX1(tof_adc_time[i] * ADC_SCALE); line_adc_time->SetX2(tof_adc_time[i] * ADC_SCALE); line_adc_time->SetY1(0); line_adc_time->SetY2(4200); line_adc_time->Draw("same"); // pedestal line_adc_pedestal->SetX1(0); line_adc_pedestal->SetX2(400); line_adc_pedestal->SetY1(tof_adc_pedestal[i]); line_adc_pedestal->SetY2(tof_adc_pedestal[i]); line_adc_pedestal->Draw("same"); sprintf(text,"figures/%6.6d___%3.3d_waveform.pdf",n,i); canvas->SaveAs(text); } // continue? // std::string command; // cin >> command; // if(command == "q") exit(); } // end of loop over nTOF } // end of loop over tree entries // Save final one gwaveform->Write(); outfile->Write(); }