--- quicklook/anticounter/src/AcQLOOK.cpp 2006/07/07 12:56:18 1.2 +++ quicklook/anticounter/src/AcQLOOK.cpp 2006/07/11 12:01:17 1.4 @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -13,22 +14,25 @@ #include #include #include +#include #include #define DEBUG 0 -#define VERSION 1.4 +#define VERSION 1.5 #define INTERVAL 100 +#define FORMAT "png" using namespace std; +UInt_t found; Int_t minevent,maxevent; UShort_t ACheader[2]; TString *cardname = new TString[2]; TString *detector = new TString[16]; -int AcQLOOKbasic(TString base,int fromevent=0, int toevent=0, TString outDir = "./", TString format = "jpg"){ +int AcQLOOKbasic(TString base,int fromevent=0, int toevent=0, TString outDir = "./", TString format = FORMAT){ ofstream outputFile; stringstream oss; @@ -47,9 +51,60 @@ //Takes the tree of the header file TTree *tr = (TTree*)rootFile->Get("Physics"); + tr->SetBranchStatus("*",0,&found); //disable all branches + + tr->SetBranchStatus("header*",1,&found); + // printf("header: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("status*",1,&found); + // printf("status: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("hitmap*",1,&found); + // printf("hitmap: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("regist*",1,&found); + // printf("regist: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("shift*",1,&found); + // printf("shift: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("counters*",1,&found); + // printf("counters: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("coinc*",1,&found); + // printf("coinc: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("trigg*",1,&found); + // printf("trigg: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("clock*",1,&found); + // printf("clock: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("temp*",1,&found); + // printf("temp: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("DAC*",1,&found); + // printf("DAC: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("CRC*",1,&found); + // printf("CRC: enabled %i branches \n",found); + + found = 0; + tr->SetBranchStatus("Pscu*",1,&found); + // printf("enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("Anticounter*",1,&found); + // printf("Ac enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("Header*",1,&found); + // printf("head enabled %i branches \n",found); + tr->SetBranchAddress("Anticounter", &ace); tr->SetBranchAddress("Header", &eh); + + + Int_t nevents = tr->GetEntries(); //check that the selected range of events is ok @@ -253,7 +308,12 @@ } //end AcBasic -int AcQLOOKpro(TString base,int fromevent=0, int toevent=0, TString outDir = "./", TString format = "jpg"){ +int AcQLOOKpro(TString base,int fromevent=0, int toevent=0, TString outDir = "./", TString format = FORMAT){ + + //Float_t startTime,stopTime; + //Float_t time1,time2,time3,time4; + + //startTime = clock(); ofstream outputFile; stringstream oss; @@ -271,7 +331,55 @@ //Takes the tree of the header file TTree *tr = (TTree*)rootFile->Get("Physics"); + + tr->SetBranchStatus("*",0,&found); //disable all branches + tr->SetBranchStatus("header*",1,&found); + // printf("header: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("status*",1,&found); + // printf("status: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("hitmap*",1,&found); + // printf("hitmap: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("regist*",1,&found); + // printf("regist: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("shift*",1,&found); + // printf("shift: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("counters*",1,&found); + // printf("counters: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("coinc*",1,&found); + // printf("coinc: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("trigg*",1,&found); + // printf("trigg: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("clock*",1,&found); + // printf("clock: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("temp*",1,&found); + // printf("temp: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("DAC*",1,&found); + // printf("DAC: enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("CRC*",1,&found); + // printf("CRC: enabled %i branches \n",found); + found = 0; + + tr->SetBranchStatus("Pscu*",1,&found); + // printf("enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("Anticounter*",1,&found); + // printf("Ac enabled %i branches \n",found); + found = 0; + tr->SetBranchStatus("Header*",1,&found); + // printf("head enabled %i branches \n",found); + tr->SetBranchAddress("Anticounter", &ace); tr->SetBranchAddress("Header", &eh); @@ -321,11 +429,15 @@ Int_t paramEvents; Int_t minevent,maxevent; char *figsave = " "; - Int_t ch_cnt; UShort_t ACheader[2]; ACheader[0]=0xAC11; ACheader[1]=0xAC22; + vector Err_type(0); + vector Err_obt(0); + vector Err_evt(0); + + Int_t *det_map = new Int_t[12]; det_map[0]=2; det_map[1]=14; @@ -433,17 +545,19 @@ } } - TH1D *status_h = new TH1D("Status","Status",10,0.,10.); - status_h->GetXaxis()->SetBinLabel(1,"CRC event M"); - status_h->GetXaxis()->SetBinLabel(2,"Headers M"); - status_h->GetXaxis()->SetBinLabel(3,"CRC M"); - status_h->GetXaxis()->SetBinLabel(4,"Dsp M"); + TH1D *status_h = new TH1D("Status","Status",12,0.,12.); + status_h->GetXaxis()->SetBinLabel(1,"Headers M"); + status_h->GetXaxis()->SetBinLabel(2,"CRC M"); + status_h->GetXaxis()->SetBinLabel(3,"Dsp M"); + status_h->GetXaxis()->SetBinLabel(4,"Temp M"); status_h->GetXaxis()->SetBinLabel(5,"Reg M"); - status_h->GetXaxis()->SetBinLabel(6,"CRC event E"); + status_h->GetXaxis()->SetBinLabel(6,"CRC Event M"); status_h->GetXaxis()->SetBinLabel(7,"Headers E"); status_h->GetXaxis()->SetBinLabel(8,"CRC E"); status_h->GetXaxis()->SetBinLabel(9,"Dsp E"); - status_h->GetXaxis()->SetBinLabel(10,"Reg E"); + status_h->GetXaxis()->SetBinLabel(10,"Temp E"); + status_h->GetXaxis()->SetBinLabel(11,"Reg E"); + status_h->GetXaxis()->SetBinLabel(12,"CRC Event E"); status_h->GetYaxis()->SetTitle("# of Errors"); status_h->SetMinimum(0); @@ -483,7 +597,11 @@ /********************* MAIN LOOP **********************/ - //UShort_t tshift[16]; + //time1 = clock(); + //printf("Init time: %f\n",(Double_t) (time1 - startTime) / (Double_t) CLOCKS_PER_SEC); + + //iterators used in the loop + Int_t card, ch, bin; for (Int_t i = minevent; i < maxevent; i++){ @@ -495,28 +613,11 @@ hitsCARD=hitsCAT=hitsCAS=0; - /* - for(Int_t ii=0;ii<16;ii++) - tshift[ii]=0; - for(Int_t ii=0;ii<16;ii++) - { - for(Int_t jj=0;jj<16;jj++) - { - if(ace->shift[0][jj] & (1<Fill(kk,tshift[ii] & 0x1<CRCcheck[card]); + //printf("Hitmap: %hx\n\n",ace->hitmap[card]); if(ace->CRCcheck[card]==1) { //clock @@ -531,45 +632,65 @@ time_between_trigg_h[card]->Fill( 0.000000025*ac_clock_diff[card] ); //counters, singlesrate & shift reg content - for(Int_t ch=0;ch<16;ch++){ - counter_old[card][ch] = counter_new[card][ch]; - counter_new[card][ch] = ace->counters[card][ch]; - if(counter_new[card][ch] - counter_old[card][ch] < 0.) - counter_diff[card][ch] = 0xFFFF + counter_new[card][ch] - counter_old[card][ch]; - else - counter_diff[card][ch] = counter_new[card][ch] - counter_old[card][ch]; - - singles_gr[card][ch][paramEvent] += (Double_t)counter_diff[card][ch]; - - - for(Int_t bin = 0; bin < 16; bin++){ - shiftreg_h[card][bin]->Fill(ch,ace->shift[card][ch] & 0x1<hitmap[card] & (0x1< 0 ){ - hitmap_h[card]->Fill(ch_cnt,1.); - if(ch_cnt==0 || ch_cnt==4 || ch_cnt==8 || ch_cnt==12) + counter_old[card][ch] = counter_new[card][ch]; + counter_new[card][ch] = ace->counters[card][ch]; + if(counter_new[card][ch] - counter_old[card][ch] < 0.) + counter_diff[card][ch] = 0xFFFF + counter_new[card][ch] - counter_old[card][ch]; + else + counter_diff[card][ch] = counter_new[card][ch] - counter_old[card][ch]; + + singles_gr[card][ch][paramEvent] += (Double_t)counter_diff[card][ch]; + + for(bin = 0; bin < 16; bin++){ + shiftreg_h[card][bin]->Fill(ch,ace->shift[card][ch] & 0x1<hitmap[card] & (0x1< 0 ){ + hitmap_h[card]->Fill(ch,1.); + if(ch==0 || ch==4 || ch==8 || ch==12) hitsCARD++; - else if(ch_cnt==1 || ch_cnt==5 || ch_cnt==9 || ch_cnt==13) + else if(ch==1 || ch==5 || ch==9 || ch==13) hitsCAT++; - else if(ch_cnt==2 || ch_cnt==6 || ch_cnt==10 || ch_cnt==14) + else if(ch==2 || ch==6 || ch==10 || ch==14) hitsCAS++; } + } - + //Status - if((ace->header[card][0] != 0xACAC) || (ace->header[card][1] != ACheader[card])) - status_h->Fill(1.+5.*card,1.); - if((ace->status[card] & 0x8000) < 0x8000) //crc - status_h->Fill(2.+5.*card,1.); - if((ace->status[card] & 0x4000) < 0x4000) //dsp - status_h->Fill(3.+5.*card,1.); - if((ace->status[card] & 0x01FF) < 0x01FF) //reg - status_h->Fill(4.+5*card,1.); + if((ace->header[card][0] != 0xACAC) || (ace->header[card][1] != ACheader[card])){ + status_h->Fill(6.*card,1.); + Err_type.push_back(6*card); + Err_obt.push_back(ph->GetOrbitalTime()); + Err_evt.push_back(i); + } + if((ace->status[card] & 0x8000) < 0x8000){ //crc + status_h->Fill(1.+6.*card,1.); + Err_type.push_back(1+6*card); + Err_obt.push_back(ph->GetOrbitalTime()); + Err_evt.push_back(i); + } + if((ace->status[card] & 0x6000) < 0x6000){ //dsp + status_h->Fill(2.+6.*card,1.); + Err_type.push_back(2+6*card); + Err_obt.push_back(ph->GetOrbitalTime()); + Err_evt.push_back(i); + } + if((ace->status[card] & 0x0E00) < 0x0E00){ //temp + status_h->Fill(3.+6.*card,1.); + Err_type.push_back(3+6*card); + Err_obt.push_back(ph->GetOrbitalTime()); + Err_evt.push_back(i); + } + if((ace->status[card] & 0x01FF) < 0x01FF){ //reg + status_h->Fill(4.+6.*card,1.); + Err_type.push_back(4+6*card); + Err_obt.push_back(ph->GetOrbitalTime()); + Err_evt.push_back(i); + } //temperature (left on cards) temp_gr[card][0][paramEvent] += ( ((ace->temp[card][0] & 0x00FF))*2.8 - 273. )/(Float_t)INTERVAL; @@ -578,9 +699,12 @@ temp_gr[card][3][paramEvent] += ( ((ace->temp[card][1] & 0xFF00)/256)*2.8 - 273. )/(Float_t)INTERVAL; }//if(crc check) - /******************************************************/ - else - status_h->Fill(5.*card,1.); //event crc + else{ + status_h->Fill(5.+6.*card,1.); //event crc + Err_type.push_back(5+6*card); + Err_obt.push_back(ph->GetOrbitalTime()); + Err_evt.push_back(i); + } }//for(card) nmbhitpmtCARD_h->Fill(hitsCARD); @@ -588,12 +712,11 @@ nmbhitpmtCAT_h->Fill(hitsCAT); - if(interval_cnt==(Int_t)((Float_t)INTERVAL/2.)) - event_obt[paramEvent] = ph->GetOrbitalTime(); - if(interval_cnt==INTERVAL) { - for(Int_t card=0;card<2;card++) + event_obt[paramEvent] = ph->GetOrbitalTime(); + + for(card=0;card<2;card++) { ac_clock100_old[card] = ac_clock100_new[card]; ac_clock100_new[card] = (ace->clock[card][1])*0xFFFF + ace->clock[card][0]; @@ -604,20 +727,21 @@ trigger_gr[card][paramEvent] = (Float_t)INTERVAL/(0.000000025*ac_clock100_diff[card]); - for(Int_t ch=0;ch<16;ch++) + for(ch=0;ch<16;ch++) singles_gr[card][ch][paramEvent] = singles_gr[card][ch][paramEvent]/(Double_t)(0.000000025*ac_clock100_diff[card]); }//for(card) interval_cnt=0; paramEvent++; }//if(interval_cnt)) - /* - for(card=0;card<2;card++) - for(Int_t ch=0;ch<16;ch++) - for(Int_t bin=0;bin<16;bin++) - shiftreg_h[card][ch]->Fill(bin,vec[card][bin][ch]); - */ + } //for(events) + + //for(Int_t i=0;iDraw(); pd4->cd(); - char *namn2 = "Anticounter Quicklook"; char namn3[30]; - sprintf(namn3,"Version %.1f",VERSION); + char namn4[40]; + char namn5[30]; + sprintf(namn3,"Anticounter Quicklook v%.1f",VERSION); + sprintf(namn4,"File: %s",fileName.Data()); + sprintf(namn5,"Events: %d",nevents); t->SetTextSize(0.1); - t->DrawLatex(20,60,namn2); - t->DrawLatex(20,40,namn3); + t->DrawLatex(5,90,namn3); + t->SetTextSize(0.1); + t->DrawLatex(20,50,namn4); + t->DrawLatex(20,40,namn5); + t->SetTextSize(0.02); pd3->cd(); @@ -673,10 +803,14 @@ temperatureACTEL_M_g->SetMarkerColor(2); temperatureLEFT_M_g->SetMarkerColor(3); temperatureDSP_M_g->SetMarkerColor(4); - temperatureRIGHT_M_g->Draw("AP"); - temperatureACTEL_M_g->Draw("PSAME"); - temperatureLEFT_M_g->Draw("PSAME"); - temperatureDSP_M_g->Draw("PSAME"); + temperatureRIGHT_M_g->SetLineColor(1); + temperatureACTEL_M_g->SetLineColor(2); + temperatureLEFT_M_g->SetLineColor(3); + temperatureDSP_M_g->SetLineColor(4); + temperatureRIGHT_M_g->Draw("AL"); + temperatureACTEL_M_g->Draw("LSAME"); + temperatureLEFT_M_g->Draw("LSAME"); + temperatureDSP_M_g->Draw("LSAME"); TLegend *legTempM = new TLegend(0.72,0.63,0.85,0.8); legTempM->AddEntry(temperatureRIGHT_M_g,"Right","P"); @@ -697,19 +831,24 @@ temperatureACTEL_E_g->SetMarkerColor(2); temperatureLEFT_E_g->SetMarkerColor(3); temperatureDSP_E_g->SetMarkerColor(4); + temperatureRIGHT_E_g->SetLineColor(1); + temperatureACTEL_E_g->SetLineColor(2); + temperatureLEFT_E_g->SetLineColor(3); + temperatureDSP_E_g->SetLineColor(4); + temperatureRIGHT_E_g->SetMaximum(50.); temperatureRIGHT_E_g->SetMinimum(0.); - temperatureRIGHT_E_g->Draw("AP"); - temperatureACTEL_E_g->Draw("PSAME"); - temperatureLEFT_E_g->Draw("PSAME"); - temperatureDSP_E_g->Draw("PSAME"); + temperatureRIGHT_E_g->Draw("AL"); + temperatureACTEL_E_g->Draw("LSAME"); + temperatureLEFT_E_g->Draw("LSAME"); + temperatureDSP_E_g->Draw("LSAME"); TLegend *legTempE = new TLegend(0.72,0.63,0.86,0.8); - legTempE->AddEntry(temperatureRIGHT_E_g,"Right","P"); - legTempE->AddEntry(temperatureACTEL_E_g,"Actel","P"); - legTempE->AddEntry(temperatureLEFT_E_g,"Left","P"); - legTempE->AddEntry(temperatureDSP_E_g,"Dsp","P"); + legTempE->AddEntry(temperatureRIGHT_E_g,"Right","L"); + legTempE->AddEntry(temperatureACTEL_E_g,"Actel","L"); + legTempE->AddEntry(temperatureLEFT_E_g,"Left","L"); + legTempE->AddEntry(temperatureDSP_E_g,"Dsp","L"); legTempE->Draw(); /************************/ @@ -748,8 +887,10 @@ triggM_gr->GetYaxis()->SetTitle("f [Hz]"); triggM_gr->SetMarkerColor(1); triggE_gr->SetMarkerColor(2); - triggM_gr->Draw("AP"); - triggE_gr->Draw("PSAME"); + triggM_gr->SetLineColor(1); + triggE_gr->SetLineColor(2); + triggM_gr->Draw("AL"); + triggE_gr->Draw("LSAME"); pd23->cd(); gPad->SetLogy(1); @@ -883,14 +1024,14 @@ singles_Pads[k]->cd(); singles_gr[card][det_map[k]][0]=0.0; singlesrate_g[card][k] = new TGraph(paramEvents,event_obt,singles_gr[card][det_map[k]]); - singlesrate_g[card][k]->SetMarkerColor(card+1); + singlesrate_g[card][k]->SetLineColor(card+1); singlesrate_g[card][k]->GetXaxis()->SetTitle("Obt [ms]"); singlesrate_g[card][k]->GetYaxis()->SetTitle("f [Hz]"); singlesrate_g[card][k]->SetTitle(detector[det_map[k]].Data()); if(card==0) - singlesrate_g[card][k]->Draw("AP"); + singlesrate_g[card][k]->Draw("AL"); else - singlesrate_g[card][k]->Draw("PSAME"); + singlesrate_g[card][k]->Draw("LSAME"); k++; } } @@ -954,25 +1095,104 @@ } } } + + // Plot error report if any error occurs + //char *namn6 = "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"; + int mposition = 80; + int eposition = 80; + char *mystring = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"; + TString *merr; + TBox *b1,*b2; + + TCanvas *sheetError; - figsave = Form("%s/%s_AcQLOOK1.%s",outDir.Data(),fileName.Data(),format.Data()); + if(Err_type.size() > 0) + { + merr = new TString[12]; + merr[0]="Header"; + merr[1]="CRC"; + merr[2]="Dsp"; + merr[3]="Temp"; + merr[4]="Reg"; + merr[5]="Event CRC"; + merr[6]="Header"; + merr[7]="CRC"; + merr[8]="Dsp"; + merr[9]="Temp"; + merr[10]="Reg"; + merr[11]="Event CRC"; + + sheetError = new TCanvas("Sheet Error","Sheet Error"); //base + sheetError->Range(0,0,100,100); + sheetError->Draw(); + b1 = new TBox(10,83.5,90,84.5); + b2 = new TBox(49.5,90,50.5,5); + b1->SetFillColor(1); + b2->SetFillColor(1); + b1->Draw(); + b2->Draw(); + + t->SetTextFont(40); + t->SetTextColor(1); + t->SetTextAlign(12); + t->SetTextSize(0.04); + namn = "AntiCounter Error Report"; + t->DrawLatex(37,94,namn); + t->SetTextColor(1); + namn = "MAIN card"; + t->DrawLatex(15,87,namn); + t->SetTextColor(1); + namn = "EXTRA card"; + t->DrawLatex(65,87,namn); + t->SetTextSize(0.015); + + + //for(Int_t i=0;iSetTextColor(2); + if(Err_type.at(iter) < 7 && mposition>10){ + mposition -= 2; + t->DrawLatex(15,mposition,mystring); + } + else if(eposition>10){ + eposition -= 2; + t->DrawLatex(65,eposition,mystring); + } + iter++; + } + if(mposition<10) + t->DrawLatex(15,5,"More errors in run!"); + if(eposition<10) + t->DrawLatex(65,5,"More errors in run!"); + + figsave = Form("%s/%s_AcQLOOK_Error.%s",outDir.Data(),fileName.Data(),format.Data()); + sheetError->SaveAs(figsave); + } + + figsave = Form("%s/%s_AcQLOOK_Status.%s",outDir.Data(),fileName.Data(),format.Data()); sheet1->SaveAs(figsave); - figsave = Form("%s/%s_AcQLOOK2.%s",outDir.Data(),fileName.Data(),format.Data()); + figsave = Form("%s/%s_AcQLOOK_Trigger.%s",outDir.Data(),fileName.Data(),format.Data()); sheet2->SaveAs(figsave); - figsave = Form("%s/%s_AcQLOOK3.%s",outDir.Data(),fileName.Data(),format.Data()); + figsave = Form("%s/%s_AcQLOOK_Singles.%s",outDir.Data(),fileName.Data(),format.Data()); sheet3->SaveAs(figsave); - figsave = Form("%s/%s_AcQLOOK4.%s",outDir.Data(),fileName.Data(),format.Data()); + figsave = Form("%s/%s_AcQLOOK_Shift.%s",outDir.Data(),fileName.Data(),format.Data()); sheet4->SaveAs(figsave); - delete sheet1; delete hitmap_h[0]; delete hitmap_h[1]; + //stopTime = clock(); + //printf("Draw time: %f\n\n",(Double_t) (stopTime - time2) / (Double_t) CLOCKS_PER_SEC); + //printf("Exc time: %f\n",(Double_t) (stopTime-startTime) / (Double_t) CLOCKS_PER_SEC); + return 1; } @@ -980,7 +1200,7 @@ int main(int argc, char* argv[]){ TString outDir = "."; - TString format = "jpg"; + TString format = FORMAT; int from = 0; int to = 0; int mode = 0;