#include #include #include #include //#define PEDESTAL_RUN 1 //#define HTRACE_IF_OVER 50 //#define RATE_TOO_HIGH 3 void viewer(char *filename) { ifstream datafile(filename,std::ios::in); if (!datafile.is_open()) { std::cerr << "Error in viewer -- unable to open input file " << filename << std::endl; return; } TH1F *hamp = gROOT->FindObject("hamp"); if (hamp == 0) { hamp = new TH1F("hamp","peak height maximum",500,0,500); } TH1F *hampa = gROOT->FindObject("hampa"); if (hampa == 0) { hampa = new TH1F("hampa","peak height average",500,0,500); } TH1F *hampe = gROOT->FindObject("hampe"); if (hampe == 0) { hampe = new TH1F("hampe","even channels",500,0,500); } TH1F *hampo = gROOT->FindObject("hampo"); if (hampo == 0) { hampo = new TH1F("hampo","odd channels",500,0,500); } int count=0; int drop_count=0; int event_time_sec=0; int events_per_sec=0; int events_this_sec=0; while (!datafile.eof()) { int reclen; datafile.read((char*)&reclen,4); short int data[1000000]; datafile.read((char*)&data,reclen*2); if (!datafile.good() || reclen < 100) { break; } #if RATE_TOO_HIGH if (data[1] == event_time_sec) { ++events_this_sec; } else { events_per_sec = events_this_sec; events_this_sec = 1; event_time_sec = data[1]; } if (events_per_sec >= RATE_TOO_HIGH || events_this_sec >= RATE_TOO_HIGH) { ++drop_count; if (drop_count/1000*1000 == drop_count) { std::cout << "trace " << drop_count << " dropped for excess rate" << std::endl; } continue; } #endif count++; if (count/1000*1000 == count) { std::cout << "trace " << count << " found: " << reclen << " samples recorded" << std::endl; } int window = 24; #if PEDESTAL_RUN int i0 = window+4; // this starts at window 1 int iend = reclen-window-2; #else int i0 = 110; // this finds the trigger channel int iend = 110; // this restricts analysis to the trigger window #endif while (i0 <= iend) { float vbase=0; float vbase0=0; float vbase1=0; float vmin=999; float vpeak=0; for (int i=0; iFill(vbase-vmin); hampa->Fill(vbase-vpeak); hampe->Fill(vbase0); hampo->Fill(vbase1); i0 += window; #ifdef HTRACE_IF_OVER if (vbase-vpeak > HTRACE_IF_OVER) { char name[10]; char title[20]; sprintf(name,"e%d",count); sprintf(title,"event %d",count); TH1F *htrace = new TH1F(name,title,reclen,0,reclen); for (int ibin=1; ibin<=reclen; ++ibin) { if (ibin > 4) { htrace->SetBinContent(ibin,double(data[ibin])); } else { htrace->SetBinContent(ibin,0); } } TCanvas *c1 = gROOT->FindObject("c1"); if (c1 == 0) { c1 = new TCanvas("c1","c1",0,0,500,500); } htrace->Draw(); c1->Update(); std::cout << "vbase,vpeak,i0,reclen=" << vbase << "," << vpeak << "," << i0 << "," << reclen << std::endl; } #endif } } }