//static char vcid[] = "$Id: main.cpp 254 2011-04-28 16:52:15Z xiangming Sun $"; //static const char __attribute__ ((used )) *Get_vcid(){return vcid;} #include "log/def.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define SEQUENCE_OFFSET 5 #ifdef PHASE1_H #define NSENSOR 4 #define NROW 640 #define NCOL 640 #else #define NSENSOR 3 #define NCOL 960 #define NROW 928 #endif #define MAX_CLUSTER 1000 int help=0; int gargc;char** gargv;int para(char *a);int para(char *a){if(help==1)cout< *x,vector *y); int get_ultimate_Event(ifstream & datafile, vector *x,vector *y); unsigned int shtoi(string strg){ unsigned int ival; sscanf(strg.data(), "%x", &ival); return ival; }; unsigned int mid(int start,int end, unsigned int input){ unsigned int buf; buf=input<<(32-end); buf=buf>>(32-end); //cout<<"mid "<>start; }; int element_getbit(int data,int position){ int sd=data>>position; return sd%2; } int element_setbit(unsigned int & data,int position){ if(position>31) return -1; unsigned int mask=0; mask=1< x; vector y; float xc; float yc; void centering(){ float xsum=0; float ysum=0; for(int i=0;i clu[NSENSOR]; bitset bsbit[NSENSOR][NROW]; pxl_cluster tc; // int cluster_hist[NSENSOR][MAX_CLUSTER]; void clear_bsbit(){ for(int k=0;k *x,vector *y){ for(int k=0;k *x,vector *y){ for(int k=0;kMAX_CLUSTER) return; } } } }; void clustering_clearbit(vector *x,vector *y){ for(int k=0;kMAX_CLUSTER) return; } } } }; void find_cluster(int sen,int x,int y,int keep){ if(bsbit[sen][y][x]==0) return; bsbit[sen][y][x]=0; if(x+1=0) find_cluster(sen,x-1,y,keep); if(y+1=0) find_cluster(sen,x,y-1,keep); tc.nhits++; tc.x.push_back(x); tc.y.push_back(y); bsbit[sen][y][x]=keep; }; }; //------------------------------------------------------ int correlation(int type, char *fn) { #ifdef PHASE1_H int offsetx[4]={0,0,-4,-14}; int offsety[4]={0,-22,-49,-70}; cout<<"phase1"<>buffer; if(!in.good()) break; if(in.eof()) break; if(strstr(buffer,".txt")==NULL)continue; #endif // cout< x[NSENSOR]; vector y[NSENSOR]; ifstream datafile; TFile * correlation_root_file=new TFile(root_file,"RECREATE"); TH1F *hx[NSENSOR]; TH1F *hy[NSENSOR]; TH1F *hx_align[NSENSOR]; TH1F *hy_align[NSENSOR]; TH1F *cluster_nhits[NSENSOR]; for(int i=0;i500) break; cf.load_bsbit(x,y); cf.clustering_clearbit(x,y); for(int i=0;iFill((x[k][j])-(x[0][i])); hy[k]->Fill((y[k][j])-(y[0][i])); } } } for(int i=0;iFill((cf.clu[k][j].xc+offsetx[k])-(cf.clu[0][i].xc+offsetx[0])); hy_align[k]->Fill((cf.clu[k][j].yc+offsety[k])-(cf.clu[0][i].yc+offsety[0])); } } } for(int k=0;kFill(cf.clu[k][i].nhits); } } int ref1=0; int ref2=NSENSOR-1; int meas=1; float window=8; int cand=0; int cand_match=0; for(int i=0;iwindow) continue; if(fabs(ref1y-ref2y)>window) continue; cand++; for(int j=0;jwindow) continue; if(fabs(ref1y-measy)>window) continue; cand_match++; cf.clu[meas][j].nhits=0; cf.clu[ref2][h].nhits=0; cf.clu[ref1][i].nhits=0; break; } } } candidate->Fill(cand); candidate_match->Fill(cand_match); cf.clear_cluster(); for(int i=0;iWrite(); correlation_root_file->Close(); #ifdef PDSF_H #else }while(!in.eof()); #endif return 1; // int wait;cout<<"press any key + enter to go!"<> hex; #ifdef LOCALDEBUG cout << hex; #endif while (datafile.good()) { datafile >> value; if (!datafile.good()) break; #ifdef LOCALDEBUG cout << "0x"; cout.width(8); cout.fill('0'); cout << value; #endif int dataType = int( (value & 0xffff0000)>> 16 ); switch (dataType) { case 0xaaaa: // header #ifdef LOCALDEBUG if ( (value&0xaaaa) == 0xaaaa) cout << "\tStart of event\n"; else cout << "\t1st header word\n"; #endif break; case 0xbbbb: // header #ifdef LOCALDEBUG cout << "\t2nd header word\n"; #endif break; case 0xccc0: // header case 0xccc1: // header case 0xcccc: // header #ifdef LOCALDEBUG cout << "\t3rd header word\n"; #endif break; case 0xdddd: // header #ifdef LOCALDEBUG cout << "\t4th header word\n"; #endif break; case 0xeeee: // end-of-event #ifdef LOCALDEBUG cout << "\tend of event\n"; #endif if (numEventFlags == 2) return 0; break; case 0xf777: case 0x7777: // event flag numEventFlags++; bSensor1and2 = ((value & 0xf) == 0); #ifdef LOCALDEBUG cout << "\tevent flag: "; if ( bSensor1and2 ) cout << "sensor 1 and 2\n"; else cout << "sensor 3 and 4\n"; #endif break; default: // data sequence = ( (value & 0xfffff000)>>12 ); #ifdef LOCALDEBUG cout << "\tsequence 0x"; cout.width(5); cout.fill('0'); cout << sequence; cout.fill(' '); #endif sequence += SEQUENCE_OFFSET; row = ((int)(sequence / 160))%640; remainder = sequence % 160; col = ((remainder % 4)*40 + (remainder/4))%160; #ifdef LOCALDEBUG cout << dec; #endif if (bSensor1and2) { // Sensors 1 and 2 if ( (value&0xf) != 0) { // Sensor 1 sensor = 1; if ( (value&0x1) == 0x1) { #ifdef LOCALDEBUG _PS(sensor, row, col); #endif y[0].push_back(row);x[0].push_back(col); } if ( (value&0x2) == 0x2) { #ifdef LOCALDEBUG _PS(sensor, row, col+160); #endif y[0].push_back(row);x[0].push_back(col+160); } if ( (value&0x4) == 0x4) { #ifdef LOCALDEBUG _PS(sensor, row, col+320); #endif y[0].push_back(row);x[0].push_back(col+320); } if ( (value&0x8) == 0x8) { #ifdef LOCALDEBUG _PS(sensor, row, col+480); #endif y[0].push_back(row);x[0].push_back(col+480); } } if ( (value&0xf0) != 0 ) { // Sensor 2 sensor = 2; if ( (value&0x10) == 0x10) { #ifdef LOCALDEBUG _PS(sensor, row, col); #endif y[1].push_back(row);x[1].push_back(col); } if ( (value&0x20) == 0x20) { #ifdef LOCALDEBUG _PS(sensor, row, col+160); #endif y[1].push_back(row);x[1].push_back(col+160); } if ( (value&0x40) == 0x40) { #ifdef LOCALDEBUG _PS(sensor, row, col+320); #endif y[1].push_back(row);x[1].push_back(col+320); } if ( (value&0x80) == 0x80) { #ifdef LOCALDEBUG _PS(sensor, row, col+480); #endif y[1].push_back(row);x[1].push_back(col+480); } } } else { // Sensors 3 and 4 if ( (value&0xf) != 0 ) { // Sensor 3 sensor = 3; if ( (value&0x1) == 0x1) { #ifdef LOCALDEBUG _PS(sensor, row, col); #endif y[2].push_back(row);x[2].push_back(col); } if ( (value&0x2) == 0x2) { #ifdef LOCALDEBUG _PS(sensor, row, col+160); #endif y[2].push_back(row);x[2].push_back(col+160); } if ( (value&0x4) == 0x4) { #ifdef LOCALDEBUG _PS(sensor, row, col+320); #endif y[2].push_back(row);x[2].push_back(col+320); } if ( (value&0x8) == 0x8) { #ifdef LOCALDEBUG _PS(sensor, row, col+480); #endif y[2].push_back(row);x[2].push_back(col+480); } } if ( (value&0xf0) != 0 ) { // Sensor 4 sensor = 4; if ( (value&0x10) == 0x10) { #ifdef LOCALDEBUG _PS(sensor, row, col); #endif y[3].push_back(row);x[3].push_back(col); } if ( (value&0x20) == 0x20) { #ifdef LOCALDEBUG _PS(sensor, row, col+160); #endif y[3].push_back(row);x[3].push_back(col+160); } if ( (value&0x40) == 0x40) { #ifdef LOCALDEBUG _PS(sensor, row, col+320); #endif y[3].push_back(row);x[3].push_back(col+320); } if ( (value&0x80) == 0x80) { #ifdef LOCALDEBUG _PS(sensor, row, col+480); #endif y[3].push_back(row);x[3].push_back(col+480); } } } // Marker if ( (value&0x100) == 0x100) { #ifdef LOCALDEBUG cout << " Marker "; #endif } #ifdef LOCALDEBUG cout << endl << hex; #endif break; } } // end while loop // got out of the "while" loop, so must have bad file status if (datafile.eof()) { #ifdef LOCALDEBUG cout << "End of File\n"; #endif posLabel->setText("End of File"); } else { #ifdef LOCALDEBUG cout << "Bad datafile status\n"; #endif posLabel->setText("Bad file status on datafile"); } return 1; } */ int get_phase1_Event(ifstream & datafile, vector *x,vector *y) { unsigned int value; unsigned int sequence; bool bSensor1and2 = false; int sensor; int row; int col; int remainder; int numEventFlags; numEventFlags = 0; datafile >> hex; #ifdef LOCALDEBUG cout << hex; #endif while (datafile.good()) { datafile >> value; if (!datafile.good()) break; #ifdef LOCALDEBUG cout << "0x"; cout.width(8); cout.fill('0'); cout << value; #endif int dataType = int( (value & 0xffff0000)>> 16 ); switch (dataType) { case 0xaaaa: // header #ifdef LOCALDEBUG if ( (value&0xaaaa) == 0xaaaa) cout << "\tStart of event\n"; else cout << "\t1st header word\n"; #endif break; case 0xbbbb: // header #ifdef LOCALDEBUG cout << "\t2nd header word\n"; #endif break; case 0xccc0: // header case 0xccc1: // header case 0xcccc: // header #ifdef LOCALDEBUG cout << "\t3rd header word\n"; #endif break; case 0xdddd: // header #ifdef LOCALDEBUG cout << "\t4th header word\n"; #endif break; case 0xeeee: // end-of-event #ifdef LOCALDEBUG cout << "\tend of event\n"; #endif if (numEventFlags == 2) return 0; break; case 0xf777: case 0x7777: // event flag numEventFlags++; bSensor1and2 = ((value & 0xf) == 0); #ifdef LOCALDEBUG cout << "\tevent flag: "; if ( bSensor1and2 ) cout << "sensor 1 and 2\n"; else cout << "sensor 3 and 4\n"; #endif break; default: // data sequence = ( (value & 0xfffff000)>>12 ); #ifdef LOCALDEBUG cout << "\tsequence 0x"; cout.width(5); cout.fill('0'); cout << sequence; cout.fill(' '); #endif sequence += SEQUENCE_OFFSET; row = ((int)(sequence / 160))%640; remainder = sequence % 160; col = ((remainder % 4)*40 + (remainder/4))%160; #ifdef LOCALDEBUG cout << dec; #endif if (bSensor1and2) { // Sensors 1 and 2 if ( (value&0xf) != 0) { // Sensor 1 sensor = 1; if ( (value&0x1) == 0x1) { #ifdef LOCALDEBUG _PS(sensor, row, col); #endif y[0].push_back(row);x[0].push_back(col); } if ( (value&0x2) == 0x2) { #ifdef LOCALDEBUG _PS(sensor, row, col+160); #endif y[0].push_back(row);x[0].push_back(col+160); } if ( (value&0x4) == 0x4) { #ifdef LOCALDEBUG _PS(sensor, row, col+320); #endif y[0].push_back(row);x[0].push_back(col+320); } if ( (value&0x8) == 0x8) { #ifdef LOCALDEBUG _PS(sensor, row, col+480); #endif y[0].push_back(row);x[0].push_back(col+480); } } if ( (value&0xf0) != 0 ) { // Sensor 2 sensor = 2; if ( (value&0x10) == 0x10) { #ifdef LOCALDEBUG _PS(sensor, row, col); #endif y[1].push_back(row);x[1].push_back(col); } if ( (value&0x20) == 0x20) { #ifdef LOCALDEBUG _PS(sensor, row, col+160); #endif y[1].push_back(row);x[1].push_back(col+160); } if ( (value&0x40) == 0x40) { #ifdef LOCALDEBUG _PS(sensor, row, col+320); #endif y[1].push_back(row);x[1].push_back(col+320); } if ( (value&0x80) == 0x80) { #ifdef LOCALDEBUG _PS(sensor, row, col+480); #endif y[1].push_back(row);x[1].push_back(col+480); } } } else { // Sensors 3 and 4 if ( (value&0xf) != 0 ) { // Sensor 3 sensor = 3; if ( (value&0x1) == 0x1) { #ifdef LOCALDEBUG _PS(sensor, row, col); #endif y[2].push_back(row);x[2].push_back(col); } if ( (value&0x2) == 0x2) { #ifdef LOCALDEBUG _PS(sensor, row, col+160); #endif y[2].push_back(row);x[2].push_back(col+160); } if ( (value&0x4) == 0x4) { #ifdef LOCALDEBUG _PS(sensor, row, col+320); #endif y[2].push_back(row);x[2].push_back(col+320); } if ( (value&0x8) == 0x8) { #ifdef LOCALDEBUG _PS(sensor, row, col+480); #endif y[2].push_back(row);x[2].push_back(col+480); } } if ( (value&0xf0) != 0 ) { // Sensor 4 sensor = 4; if ( (value&0x10) == 0x10) { #ifdef LOCALDEBUG _PS(sensor, row, col); #endif y[3].push_back(row);x[3].push_back(col); } if ( (value&0x20) == 0x20) { #ifdef LOCALDEBUG _PS(sensor, row, col+160); #endif y[3].push_back(row);x[3].push_back(col+160); } if ( (value&0x40) == 0x40) { #ifdef LOCALDEBUG _PS(sensor, row, col+320); #endif y[3].push_back(row);x[3].push_back(col+320); } if ( (value&0x80) == 0x80) { #ifdef LOCALDEBUG _PS(sensor, row, col+480); #endif y[3].push_back(row);x[3].push_back(col+480); } } } // Marker if ( (value&0x100) == 0x100) { #ifdef LOCALDEBUG cout << " Marker "; #endif } #ifdef LOCALDEBUG cout << endl << hex; #endif break; } } // end while loop // got out of the "while" loop, so must have bad file status if (datafile.eof()) { #ifdef LOCALDEBUG cout << "End of File\n"; #endif cout << "End of File"< *x,vector *y) { //char bs[4*NROW*NCOL]; // int selectedSensor; // int selectedQuarter; // bool useFiltered; //bitset bsbit[NSENSOR][NROW]; //bitset bsbit_rotate[NROW]; // bitset bsbit_filter[NSENSOR][NROW]; int nEvents=0; do{ if(datafile.eof()) break; if(!datafile.good()) break; if(read_read==1){ datafile.getline(buf,12);nline++; sval=buf; } ////////////////////////// if(state==0||state==3){ if(sval.substr(0,10)=="0xaaaaaaaa"){ state=1;// find the header worder if(debug>3)cout<<"0xaaaaaaaa found"<>5; if(sval.substr(0,6)=="0xdddd"){ state=4;// find the last word in header; //write header; for(int i=0;i<5;i++){ // fprintf(out,"0x%08lx\n",header[i]); } frame_number=0; continue; }else{ cout<<"no 0xdddd found"<1)cout<<"frame found"<1)cout<<"from eeeeeeeeee"<0)cout<<"trucated frame!!!"<<" nline "<=6){ state=3; //one event is end nEvents++; cout<<"unexpected ffffffff"<<" nline "<>16; int val0=val&(0xffff); if(state==4){ if(debug>2)cout<<"start of sensor "<2)cout<<"previous length "<2)cout<<"frame_counter "<>16; int data_length0=dl&(0xffff); if(data_length1!=data_length0) { //cout<<"data_length1!=data_length0 "<<" nline "<2){ if(new_state==0){ number=val0&(0xf); row=(val0>>4)&(0x3ff); OVF=element_getbit(val0,15); new_state++; coding=val1&3; column=(val1>>2)&(0x3ff); new_state++; if((row>trigger_row&&image==0)||(row<=trigger_row&&image==1)){ if(debug>0) cout<<"hit founded 1"<<" nline "<>2)&(0x3ff); new_state++; if((row>trigger_row&&image==0)||(row<=trigger_row&&image==1)){ if(debug>0) cout<<"hit founded 2"<<" nline "<>4)&(0x3ff); OVF=element_getbit(val1,15); new_state++; if(new_state==number+1){ new_state=0; } }else{ coding=val1&3; column=(val1>>2)&(0x3ff); new_state++; if((row>trigger_row&&image==0)||(row<=trigger_row&&image==1)){ if(debug>0) cout<<"hit founded 3"<<" nline "<0){ if(nEvents==read_depth){ if(state!=0&&state!=3) break; } } }while(!datafile.eof()); //fclose(out); if(datafile.eof()) return 1; return 0; } int batch_correlation(int start, int stop){ for(int i=start;i