// fileAnalyzer.cc // shell for analyzing evio files // ejw, 20-jun-2008 #include #include #include #include // root stuff #include #include #include #include #include "fileAnalyzer.h" using namespace std; using namespace evio; int evtCount = 0; // prototypes void analyzeEvent(evioDOMTree &eventTree); void analyzeBank(evioDOMNodeP bankPtr); void initRootTree(const char* filename); // Define bit masks // F1 bit masks #define F1_RAW_DATA 0xFF000000 //-------------------------------------------------------------- //-------------------------------------------------------------- int main(int argc, char **argv) { char filename[128]; strcpy(filename, argv[1]); try { // open the file cout << "open data file " << filename < 30)) continue; if(evtCount%100==0)cout << "fileAnalyzer read " << evtCount << " events" << endl; // create event tree and analyze evioDOMTree eventTree(chan); analyzeEvent(eventTree); } // reached eof, close file chan.close(); ROOTfile->cd(); ROOTfile->Write(); ROOTfile->Close(); delete ROOTfile; cout<toString() << endl << endl; exit(EXIT_FAILURE); } // done cout << endl << endl << " ***File analyzer done after " << evtCount << " events***" << endl << endl; exit(EXIT_SUCCESS); } //------------------------------------------------------------------------------- void analyzeEvent(evioDOMTree &eventTree) { cout << endl << endl << endl << "analyzing event " << evtCount << endl << endl; // get list of all banks in event evioDOMNodeListP bankList = eventTree.getNodeList(); // analyze each bank for_each(bankList->begin(),bankList->end(),analyzeBank); cout << " Filling root File " << endl; test->Fill(); } //------------------------------------------------------------------------------- void analyzeBank(evioDOMNodeP bankPtr) { // dump bank info for all banks // cout << left << hex << "bank content type: 0x" << setw(6) << bankPtr->getContentType() // << dec << " tag: " << setw(6) << bankPtr->tag // << hex << " num: 0x" << setw(6) << (int)bankPtr->num << dec << endl; // decode banks switch (bankPtr->tag) { // header bank case 0: // cout << "found event bank" << endl << endl; break; case 3: { const vector *vec = bankPtr->getVector(); if(vec==NULL) {cerr << "?unable to get header bank vector" << endl; return;} // cout << dec << "found header bank: run number " << (*vec)[0] << " Event number " << (*vec)[1] << endl << endl; break; } // fadc data bank case 4: { const vector *vec = bankPtr->getVector(); if(vec==NULL) {cerr << "?unable to get fadc bank vector" << endl; return;} // unsigned int data_type = // cout << "found fadc bank: bank length " << vec->size() // << " block length " << int( (*vec)[vec->size()-1] & 0x3fffff) // << " block number " << int((*vec)[0]&0x3ff) // << " slot number " << int(((*vec)[0]>>22)&0x1f) // << endl; // Loop over data unsigned int data_new_type = 0; unsigned int data_type = 0; int channel = -1; unsigned int time_stamp = 0; cout << " Vector Size = " << vec->size() << endl; for (unsigned i = 0; i < vec->size(); i++){ if( (*vec)[i] & 0x80000000 ) /* data type defining word */ { data_type = ((*vec)[i] & 0x78000000) >> 27; // data_type == 4 - window raw data data_new_type = 1; } else { data_new_type = 0; }; // cout << "SASCHA Data type = " << data_type << endl; // WINDOW RAW DATA if(data_type == 4 ){ if(data_new_type == 1){ unsigned int fadc_width = ((*vec)[i] & 0xFFF); channel = ((*vec)[i] & 0x7800000) >> 23; // cout << " Data Type = " << data_type << " Fadc_width = " << fadc_width << " Channel = " << channel << endl; time_stamp = 1; } else{ unsigned int valid_1 = 1; unsigned int valid_2 = 1; unsigned int adc_1 = ((*vec)[i] & 0x1FFF0000) >> 16; if((*vec)[i] & 0x20000000 ) valid_1 = 0; unsigned int adc_2 = ((*vec)[i] & 0x1FFF); if( (*vec)[i] & 0x2000 ) valid_2 = 0; if((channel == 0) && (time_stamp == 14)) { // cout << "CHANNEL = " << channel << " Time stamp " << time_stamp << // " Amplitude = " << adc_1 << " " << adc_2 << endl; ach1->Fill(float(adc_1)); ach2->Fill(float(adc_2)); } switch(channel){ case 0: ch0->Fill(float(time_stamp*2-2),float(adc_1),1.); ch0->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 1: ch1->Fill(float(time_stamp*2-2),float(adc_1),1.); ch1->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 2: ch2->Fill(float(time_stamp*2-2),float(adc_1),1.); ch2->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 3: ch3->Fill(float(time_stamp*2-2),float(adc_1),1.); ch3->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 4: ch4->Fill(float(time_stamp*2-2),float(adc_1),1.); ch4->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 5: ch5->Fill(float(time_stamp*2-2),float(adc_1),1.); ch5->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 6: ch6->Fill(float(time_stamp*2-2),float(adc_1),1.); ch6->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 7: ch7->Fill(float(time_stamp*2-2),float(adc_1),1.); ch7->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 8: ch8->Fill(float(time_stamp*2-2),float(adc_1),1.); ch8->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 9: ch9->Fill(float(time_stamp*2-2),float(adc_1),1.); ch9->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 10: ch10->Fill(float(time_stamp*2-2),float(adc_1),1.); ch10->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 11: ch11->Fill(float(time_stamp*2-2),float(adc_1),1.); ch11->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 12: ch12->Fill(float(time_stamp*2-2),float(adc_1),1.); ch12->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 13: ch13->Fill(float(time_stamp*2-2),float(adc_1),1.); ch13->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 14: ch14->Fill(float(time_stamp*2-2),float(adc_1),1.); ch14->Fill(float(time_stamp*2-1),float(adc_2),1.); break; case 15: ch15->Fill(float(time_stamp*2-2),float(adc_1),1.); ch15->Fill(float(time_stamp*2-1),float(adc_2),1.); break; default: break; } time_stamp++; // if(channel == 10){ // printf("%8X - RAW SAMPLES - valid = %d adc = %d valid = %d adc = %d channel = %d\n", // (*vec)[i], valid_1, adc_1, valid_2, adc_2, channel); // } // cout << " Time Stamp = " << time_stamp << endl; // cout << hex << (*vec)[i] << endl; } } // Data type 4, raw window data // Pulse Integral data if(data_type == 7 ){ channel = ((*vec)[i] & 0x7800000) >> 23; unsigned int pulse_numb = ((*vec)[i] & 0x200000) >> 21; unsigned int pulse_int = ((*vec)[i] & 0x3FFFF); // cout << " Channel = " << channel << " Pulse number = " << pulse_numb << // " Pulse int = " << pulse_int << endl; // pulse_int = pulse_int - 13.4*12.; switch(channel){ case 0: pc0->Fill(float(pulse_int)); break; case 1: pc1->Fill(float(pulse_int)); break; case 2: pc2->Fill(float(pulse_int)); break; case 3: pc3->Fill(float(pulse_int)); break; case 4: pc4->Fill(float(pulse_int)); break; case 5: pc5->Fill(float(pulse_int)); break; case 6: pc6->Fill(float(pulse_int)); break; case 7: pc7->Fill(float(pulse_int)); break; case 8: pc8->Fill(float(pulse_int)); break; case 9: pc9->Fill(float(pulse_int)); break; case 10: pc10->Fill(float(pulse_int)); break; case 11: pc11->Fill(float(pulse_int)); break; case 12: pc12->Fill(float(pulse_int)); break; case 13: pc13->Fill(float(pulse_int)); break; case 14: pc14->Fill(float(pulse_int)); break; case 15: pc15->Fill(float(pulse_int)); break; default: break; } } } break; } // F1TDC data case 5: { const vector *vec = bankPtr->getVector(); if(vec==NULL) {cerr << "?unable to get tdc bank vector" << endl; return;} // Loop over data unsigned int data_new_type = 0; unsigned int data_type = 0; int channel = -1; unsigned int time_stamp = 0; unsigned int F1_SLOT = 6; cout << " -------------------" << endl; cout << " F1TDC Vector Size = " << vec->size() << endl; cout << " -------------------" << endl; int time1 = -10; int time2 = -10; for (unsigned i = 0; i < vec->size(); i++){ cout << "------------" << endl; cout << hex << (*vec)[i] << dec << endl; cout << "------------" << endl; // Slot ID unsigned int slot_id = ((*vec)[i] & 0xF8000000) >> 27; unsigned int chip_res_locked = ((*vec)[i] & 0x4000000) >> 26; unsigned int overflow = ((*vec)[i] & 0x3000000) >> 24; unsigned int data_type = ((*vec)[i] & 0x800000) >> 23; cout << " Slot id = " << slot_id << " chip_res_locked = " << chip_res_locked << " Overflow = " << overflow << " Data_type = " << data_type << endl; unsigned int f1_chip = 100; unsigned int f1_chan = 100; unsigned int f1_time = 0; if(data_type == 0){ unsigned int event_number = ((*vec)[i] & 0x3f0000) >> 16; unsigned int trigger_time = ((*vec)[i] & 0xff80) >> 7; f1_chip = ((*vec)[i] & 0x38) >> 3; f1_chan = ((*vec)[i] & 0x7); cout << endl; cout << " Event number = " << event_number << " Trigger time = " << trigger_time << " Chip = " << f1_chip << " Channel = " << f1_chan << endl; cout << endl; } else if(data_type == 1){ // Data f1_chip = ((*vec)[i] & 0x380000) >> 19; f1_chan = ((*vec)[i] & 0x70000) >> 16; f1_time = ((*vec)[i] & 0xffff); cout << " Chip = " << f1_chip << " Channel = " << f1_chan << " Time = " << f1_time << endl; if((f1_chip == 0) && ((f1_chan == 2) || (f1_chan == 3))) time1 = f1_time; if((f1_chip == 3) && ((f1_chan == 6) || (f1_chan == 7))) time2 = f1_time; } if(slot_id != F1_SLOT) cout << " Wrong slot number " << slot_id << endl; } cout << " Time difference = " << time2 - time1 << endl; time_diff->Fill(float(time2-time1)); } default: { break; } } } //------------------------------------------------------------------------------- void initRootTree(const char* fname){ // open ROOT file ROOTfile = new TFile(fname,"RECREATE","new"); cout<<"Opened ROOT file "<cd(); test = new TTree( "trigTest", "Trigger Test" ); test->Branch( "n_evt", &n_evt, "n_evt/I" ); test->Branch( "adc0", &adc0, "adc0[50]/I" ); int window_size = 125; ch0 = new TProfile("ch 0","ch 0",window_size,-0.5,window_size-0.5,-10.,2048.); ch1 = new TProfile("ch 1","ch 1",window_size,-0.5,window_size-0.5,-10.,2048.); ch2 = new TProfile("ch 2","ch 2",window_size,-0.5,window_size-0.5,-10.,2048.); ch3 = new TProfile("ch 3","ch 3",window_size,-0.5,window_size-0.5,-10.,2048.); ch4 = new TProfile("ch 4","ch 4",window_size,-0.5,window_size-0.5,-10.,2048.); ch5 = new TProfile("ch 5","ch 5",window_size,-0.5,window_size-0.5,-10.,2048.); ch6 = new TProfile("ch 6","ch 6",window_size,-0.5,window_size-0.5,-10.,2048.); ch7 = new TProfile("ch 7","ch 7",window_size,-0.5,window_size-0.5,-10.,2048.); ch8 = new TProfile("ch 8","ch 8",window_size,-0.5,window_size-0.5,-10.,2048.); ch9 = new TProfile("ch 9","ch 9",window_size,-0.5,window_size-0.5,-10.,2048.); ch10 = new TProfile("ch 10","ch 10",window_size,-0.5,window_size-0.5,-10.,2048.); ch11 = new TProfile("ch 11","ch 11",window_size,-0.5,window_size-0.5,-10.,2048.); ch12 = new TProfile("ch 12","ch 12",window_size,-0.5,window_size-0.5,-10.,2048.); ch13 = new TProfile("ch 13","ch 13",window_size,-0.5,window_size-0.5,-10.,2048.); ch14 = new TProfile("ch 14","ch 14",window_size,-0.5,window_size-0.5,-10.,2048.); ch15 = new TProfile("ch 15","ch 15",window_size,-0.5,window_size-0.5,-10.,2048.); pc0 = new TH1F("pch 0","pch 0",3400,-0.5,3399.5); pc1 = new TH1F("pch 1","pch 1",3400,-0.5,3399.5); pc2 = new TH1F("pch 2","pch 2",3400,-0.5,3399.5); pc3 = new TH1F("pch 3","pch 3",3400,-0.5,3399.5); pc4 = new TH1F("pch 4","pch 4",3400,-0.5,3399.5); pc5 = new TH1F("pch 5","pch 5",3400,-0.5,3399.5); pc6 = new TH1F("pch 6","pch 6",3400,-0.5,3399.5); pc7 = new TH1F("pch 7","pch 7",3400,-0.5,3399.5); pc8 = new TH1F("pch 8","pch 8",3400,-0.5,3399.5); pc9 = new TH1F("pch 9","pch 9",3400,-0.5,3399.5); pc10 = new TH1F("pch 10","pch 10",3400,-0.5,3399.5); pc11 = new TH1F("pch 11","pch 11",3400,-0.5,3399.5); pc12 = new TH1F("pch 12","pch 12",3400,-0.5,3399.5); pc13 = new TH1F("pch 13","pch 13",3400,-0.5,3399.5); // pc14 = new TH1F("pch 14","pch 14",10000,-0.5,9999.5); pc14 = new TH1F("pch 14","pch 14",40000,14999.5,54999.5); pc15 = new TH1F("pch 15","pch 15",300,-0.5,299.5); ach1 = new TH1F("ach 1","ach 1",1024,-0.5,1023.5); ach2 = new TH1F("ach 2","ach 2",1024,-0.5,1023.5); time_diff = new TH1F("Dt","Dt",100,120.,220.); } //------------------------------------------------------------------------------- //-------------------------------------------------------------------------------