#include "onlinedisp_zmq.h" bool hasallpede; TH1F * his102;TH1F * his101; int processedf; sls::zmqHeader zHeader; #define PEDEFNAME "current_pede.dat" #define NPRO 50 #define NPRI 50 #define JFSTRX #ifdef JFSTRX #include "jungfrauLGADStrixelsData_new.h" #include "sls/sls_detector_defs.h" #include "slsDetectorData.h" using header = sls::defs::sls_receiver_header; #endif int main(int argc, char* argv[]) { goout=1; hasallpede=false; dophotonmap=true; if ((argc<3)) {printf("USAGE: command photon_energy_(peakinADC) [rx_ip] [port] \n"); return -1 ;} else { phene=atoi(argv[1]); if (phene<0) dophotonmap=false; threshold=float (phene/2); printf( " \n"); printf( "phene %d \n",phene); } if (argc>=3) { strcpy(serverip,argv[2]); printf("ip is %s ",serverip); } portnum=30001; if (argc>=4 ){ portnum= atoi(argv[3]); } printf(", port number is %d ",portnum); printf(". \n"); #ifdef JFSTRX cout << "JFSTRX" << endl; jungfrauLGADStrixelsData *decoder = new jungfrauLGADStrixelsData(); decoder->getDetectorSize(nx,ny); cout<< decoder->dataMap[22][22] <getValue((char*)(hchptr),279,130)<SetOption("colz"); his1001->SetOption("colz"); his1002->SetOption("colz"); his1060->SetOption("colz"); his1061->SetOption("colz"); his1062->SetOption("colz"); #else his1000= new TH2F("his1000","2d , ev. pede corrected",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5); his1000->SetOption("colz"); #endif his2000= new TH2F("his2000","2d gain ",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5); his2000->GetZaxis()->SetRangeUser(0,4); if (dophotonmap) { his3000= new TH2F("his3000"," photon map ",1024,-0.5,1024-0.5,512,-0.5,512-0.5); } else { his3000= new TH2F("his3000"," raw adc ",1024,-0.5,1024-0.5,512,-0.5,512-0.5); } his4500= new TH2F("his4500","T vs B",101,-500,MAX_POS,101,-500,MAX_POS); hchip=new TH1I*[8]; #ifdef JFSTRX for (i=0;i<8;i++) { if(i<3) sprintf(hname,"%d_hchip1group%d",i,i+1); else if (i>4) sprintf(hname,"%d_hchip6group%d",i, i-4); else sprintf(hname,"%d_",i); hchip[i] = new TH1I(hname,hname,NBIN,MIN_POS,MAX_POS); } #else for (i=0;i<8;i++) { sprintf(hname,"hchip%d",i); hchip[i] = new TH1I(hname,hname,NBIN,MIN_POS,MAX_POS); } #endif cout <<"end of histo booking" <Draw(); p2 = new TPad("p2","p2",0.51,0.75,0.99,0.97); p2->Draw(); p3 = new TPad("p3","p3",0.01,0.25,0.49,0.47); p3->Draw(); p4 = new TPad("p4","p4",0.51,0.53,0.99,0.75); p4->Draw(); p5 = new TPad("p5","p5",0.01,0.03,0.49,0.25); p5->Draw(); p6 = new TPad("p6","p6",0.51,0.,0.99,0.5); p6->Draw(); //A3->Divide(2,3); // TVirtualPad* g=A3->cd(1); // g->SetCanvasSize( g->GetWw(), 2*g->GetWw()); // g=A3->cd(6); // g->SetCanvasSize( g->GetWw(), 2*g->GetWw()); #else A3 = new TCanvas("A3","Plotting Canvas ADC",150,360,1200,550); #endif } if (A4==NULL) A4 = new TCanvas("A4","Plotting Canvas PHs",750,300,1000,800); A4->Clear(); A4->Divide(4,2,0.005,0.005); if (A5==NULL) A5 = new TCanvas("A5","Plotting Canvas Photon Map",750,300,1000,600); if (A6==NULL) A6 = new TCanvas("A6","Plotting Canvas LvsR",650,250,650,660); gSystem->ProcessEvents(); int running=0; char runc[15]="*\\-/|"; printhelp(); while (1==1) { // loop on streamed frames if(!zmqSocket->ReceiveHeader(0,zHeader, SLS_DETECTOR_JSON_HEADER_VERSION)){ cout<< "Receiver stopped, waiting for new stream" << endl; zmqSocket->Disconnect(); zmqSocket->Connect(); } else { // if (((icount++)%10)==0) cout <<"recived frameindex "<ReceiveData(0, (char *)(&image_data), NCH*2); } { memcpy(&croi, &zHeader.detSpec1, 8); ROIxmin=croi.xmin; ROIxmax=croi.xmax; ROIymin=croi.ymin; ROIymax=croi.ymax; cout<<" ROIymin "<< ROIymin<Reset(); his1001->Reset(); his1002->Reset(); his1060->Reset(); his1061->Reset(); his1062->Reset(); #else his1000->Reset(); #endif his2000->Reset(); if (!dophotonmap) his3000->Reset(); //FOR RAW ADC DISPLAY } if ((fill1Ds)or(show2Ds)or(dophotonmap)) { // do something, otherwise skip to the next processedf++; for (i=0 ;i>14) & 0x3;} else {gain=0;} if (pede_flag){ if (gain_flag) { if ((gain==0)||(!hasallpede)) adcpedecorr=(adcvalue&0x3fff)*fgaind[i]-fpeded[i]*fgaind[i]; if ((gain==1)&&hasallpede) adcpedecorr=(fpedeG1d[i]*fgaind[i]+G1Poffset-adcvalue*fgaind[i])*30.0; if ((gain==3)&&hasallpede) adcpedecorr=(fpedeG2d[i]*fgaind[i]+G2Poffset-adcvalue*fgaind[i])*340.0; } else { if ((gain==0)||(!hasallpede)) adcpedecorr=(adcvalue&0x3fff)-fpeded[i]; if ((gain==1)&&hasallpede) adcpedecorr=(fpedeG1d[i]+G1Poffset-adcvalue)*30.0; if ((gain==3)&&hasallpede) adcpedecorr=(fpedeG2d[i]+G2Poffset-adcvalue)*340.0; } } else {adcpedecorr=float (adcvalue);} //end of if pede if ((adcpedecorr>threshold)&&(pede_flag)) hchptr[(i)]= hchptr[(i)]+(int)((adcpedecorr+threshold)/phene); if (fill1Ds) { if (((i%1024)<1004)&&((i%1024)>20)&&((i/1024)>20)) { //skip the pix near guardring for PH plots ichip= i/(256*256*4)*4+((i/256)%4) ; #ifdef JFSTRX int new_ichip=0; //exclude border rows of each group if (ichip==1) { if (i<=(1024*(64-2))) new_ichip=0; //chip 1 group 1 if (i>(1024*(64+6))&&(i<=(1024*(64*2-4)))) new_ichip=1; //chip 1 group 2 if (i>(1024*(64*2+5))) new_ichip=2; //chip 1 group 3 } if (ichip==6) { if (i<=(1024*(256+2*64-5))) new_ichip=7; //chip 6 group 3 if (i>(1024*(256+2*64+4))&&(i<=(1024*(256+64*3-6)))) new_ichip=6; //chip 6 group 2 if (i>(1024*(256+64*3-4))) new_ichip=5; //chip 6 group 1 } hchip[new_ichip]->Fill(adcpedecorr,1); #else hchip[ichip]->Fill(adcpedecorr,1); #endif // if (((i%256)<253)&&((i%256)>2)) his4500->Fill(adcpedecorrold,adcpedecorr,1); adcpedecorrold=adcpedecorr; } }//if (fill1Ds) }// for (i=0 ;idataMap[ipy][ipx])/2 << endl; i=int (((decoder->dataMap[ipy][ipx])-sizeof(header)) /2); group=(decoder->groupmap[ipy][ipx]); // cout<Fill(float(ipx),float(ipy),value); // if ((ipy>165)&&(ipy<320+165)){ his1000->Fill(float(ipx)*5/3.0,float(ipy),value);} // else { his1000->Fill(float(ipx),float(ipy),value);} #ifdef JFSTRX static const int mc1g1y_start = 0; static const int mc1g2y_start = g1_nrows; static const int mc1g3y_start = g1_nrows+g2_nrows; static const int mc6g3y_start = g1_nrows+g2_nrows+g3_nrows; static const int mc6g2y_start = mc6g3y_start + g3_nrows; static const int mc6g1y_start = mc6g3y_start + g3_nrows + g2_nrows; if (group==0) { if (ipy<165){ his1000->Fill(float(ipx),float(ipy-mc1g1y_start),value);} if (ipy>=mc6g1y_start){ his1060->Fill(float(ipx),float(ipy-mc6g1y_start),value);} } if (group==1) { if (ipy<(165+320)){ his1001->Fill(float(ipx),float(ipy-mc1g2y_start),value);} if ( (ipy>=mc6g2y_start) && (ipyFill(value,oldvalue,1.0); oldvalue=value; his1061->Fill(float(ipx),float(ipy-mc6g2y_start),value);} } if (group==2) { if (ipy<(165+320+476)) his1002->Fill(float(ipx),float(ipy-mc1g3y_start),value); if ( (ipy>=mc6g3y_start) && (ipyFill(float(ipx),float(ipy-mc6g3y_start),value); } #else his1000->Fill(float(ipx),float(ipy),value); #endif his2000->Fill(float(ipx),float(ipy) ,gain); // if (!dophotonmap)his3000->Fill(float(ipx),float(ipy) ,value); // value=(int)(hchptr[i]); // if (dophotonmap) his3000->Fill(float(ipx),float(ipy),float(value)); }// for ipx } //for ipy for (ipx=0;ipx<1024;ipx++){ for (ipy=0;ipy<512;ipy++){ i=ipx+ipy*1024; value= ((image_data[i]) & 0x3fff) -fpeded[i]; if (!dophotonmap)his3000->Fill(float(ipx),float(ipy) ,value); value=(int)(hchptr[i]); if (dophotonmap) his3000->Fill(float(ipx),float(ipy),float(value)); } } }// endo of show2d }// /end of do something if ((show2Ds)) { for (i=0;iProcessEvents(); } }// end of infinite loop rootapp->Run(); nonblock(NB_DISABLE); return 0; } void processifp(int ifp){ if (ifp!=0){ c=fgetc(stdin); if (c=='s') {if (goout==0){goout=1;}else {myloop();}} if (c=='S') SetRanges(); if (c=='+') { HDraw_every=HDraw_every*0.8;cout<< endl <<"Drawing every "<< HDraw_every<<" frames "<SetOption("surf2z"); if (c=='C') his1000->SetOption("colz"); if (c=='q') exit(0); if (c=='r') historeset(); if (c=='R') axisreset(); } } void loadallpede(){ cout <<"not implemented "<< endl; // hasallpede=true; // system("./sls_detector_put setbit 0x5d 12 "); //setting to FSG1 ; // loadpede(); // loadpede(); // for (i=0;iReceiveHeader(0,zHeader, SLS_DETECTOR_JSON_HEADER_VERSION)){ return; } cout <<"received frameindex "<ReceiveData(0, (char *)(&image_data), NCH*2); framesinstream++;nframes++; for (ipx=0;ipxProcessEvents(); usleep(5000); } } void printhelp(){ cout<< endl << "s=start/pause| p/n=getnewpede/raw | o/O=read/save pede | n=nopede(raw) | r/R=rst His/Axis | +/- = faster/slower ref. |q=exit | U/C sUrf2/Colz " <Reset(); his3000->Reset(); for (i=0;i<8;i++) { hchip[i]->Reset(); } Plot2DHistos(); Plot1DHistos(); } void SetRanges() { string str; std::cin.clear(); //cin.ignore(std::numeric_limits::max(), '\n'); cout<< endl; cout<< " adc min " <> adcmin; cout<< " adc max " <> adcmax; cout<< " p.map min " <> pmmin; cout<< " p.map max " <> pmmax; fixranges=true; } void axisreset(){ fixranges=false; #ifdef JFSTRX his1000->GetXaxis()->UnZoom(); his1000->GetYaxis()->UnZoom(); his1000->GetZaxis()->UnZoom(); his1001->GetXaxis()->UnZoom(); his1001->GetYaxis()->UnZoom(); his1001->GetZaxis()->UnZoom(); his1002->GetXaxis()->UnZoom(); his1002->GetYaxis()->UnZoom(); his1002->GetZaxis()->UnZoom(); his1060->GetXaxis()->UnZoom(); his1060->GetYaxis()->UnZoom(); his1060->GetZaxis()->UnZoom(); his1061->GetXaxis()->UnZoom(); his1061->GetYaxis()->UnZoom(); his1061->GetZaxis()->UnZoom(); his1062->GetXaxis()->UnZoom(); his1062->GetYaxis()->UnZoom(); his1062->GetZaxis()->UnZoom(); #else his1000->GetXaxis()->UnZoom(); his1000->GetYaxis()->UnZoom(); his1000->GetZaxis()->UnZoom(); #endif his2000->GetXaxis()->UnZoom(); his2000->GetYaxis()->UnZoom(); his3000->GetZaxis()->UnZoom(); for (i=0;i<8;i++) { hchip[i]->GetXaxis()->UnZoom(); hchip[i]->GetYaxis()->UnZoom(); } his4500->GetXaxis()->UnZoom(); his4500->GetYaxis()->UnZoom(); his4500->GetZaxis()->UnZoom(); Plot2DHistos(); Plot1DHistos(); } void nonblock(int state) { struct termios ttystate; //get the terminal state tcgetattr(STDIN_FILENO, &ttystate); if (state==NB_ENABLE) { //turn off canonical mode ttystate.c_lflag &= ~ICANON; //minimum of number input read. ttystate.c_cc[VMIN] = 1; } else if (state==NB_DISABLE) { //turn on canonical mode ttystate.c_lflag |= ICANON; } //set the terminal attributes. tcsetattr(STDIN_FILENO, TCSANOW, &ttystate); } void LoadPaletteFalse(){ const Int_t NRGBs = 5; const Int_t NCont = 90; Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; TColor::CreateGradientColorTable(NRGBs, stops, red,green, blue, NCont); gStyle->SetNumberContours(NCont); TColor::CreateGradientColorTable(NRGBs, stops, red,green ,blue, NCont); gStyle->SetNumberContours(NCont); } void LoadPaletteBW(float gammatune){ vgamma=vgamma*gammatune; cout<< "gamma is "<SetNumberContours(NCont); // TColor::SetPalette(52,0,1); } void Plot1DHistos(void){ if (hchip[0]->GetXaxis()->GetLast()!=oldh0xlast){ oldh0xlast=hchip[0]->GetXaxis()->GetLast(); oldh0xfirst=hchip[0]->GetXaxis()->GetFirst(); for (int ipad=1; ipad<8;ipad++) { hchip[ipad]->GetXaxis()->SetRange(oldh0xfirst,oldh0xlast); } } for (int ipad=0; ipad<8;ipad++) { A4->cd(ipad+1); gStyle->SetOptStat(1); gPad->SetLogy(); hchip[ipad%4+(1-int(ipad/4))*4]->Draw(); } A4->cd(); A4->Update(); } void Plot2DHistos(void){ gStyle->SetOptStat(0); // if (bw_flag) LoadPaletteBW(1.0); if (fixranges) { his1000->GetZaxis()->SetRangeUser(float(adcmin),float(adcmax)); his3000->GetZaxis()->SetRangeUser(float(pmmin),float(pmmax)); } his1000->SetMinimum(-200); #ifdef JFSTRX p5->cd(); his1000->Draw("colz"); p3->cd(); his1001->Draw("colz"); p1->cd(); his1002->Draw("colz"); p2->cd(); his1060->Draw("colz"); p4->cd(); his1061->Draw("colz"); p6->cd(); his1062->Draw("colz"); #else A3->cd(); his1000->Draw("colz"); #endif A3->Update(); A2->cd(); // if (bw_flag) LoadPaletteFalse(); his2000->GetXaxis()->SetRange(his1000->GetXaxis()->GetFirst(),his1000->GetXaxis()->GetLast()); his2000->GetYaxis()->SetRange(his1000->GetYaxis()->GetFirst(),his1000->GetYaxis()->GetLast()); his2000->Draw("colz"); A2->Update(); A5->cd(); //his3000->GetXaxis()->SetRange(his1000->GetXaxis()->GetFirst(),his1000->GetXaxis()->GetLast()); //his3000->GetYaxis()->SetRange(his1000->GetYaxis()->GetFirst(),his1000->GetYaxis()->GetLast()); his3000->Draw("colz"); box = new TBox(ROIxmin,ROIymin,ROIxmax,ROIymax); box->SetLineColor(kRed); box->SetFillStyle(0); box->SetLineWidth(2); box->Draw(); A5->Update(); A6->cd(); his4500->Draw("colz"); A6->Update(); } void startsocket(void) { try { zmqSocket = new sls::ZmqSocket(serverip, portnum); } catch (...) { cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, serverip); delete zmqSocket; return; } zmqSocket->SetReceiveHighWaterMark(3); zmqSocket->SetReceiveBuffer(1024*1024); zmqSocket->Connect(); cout<<"Zmq Client[] "<< zmqSocket->GetZmqServerAddress()<~ZmqSocket (); haveconnection=false; } void savepede(void) { int pfd; pfd=open(PEDEFNAME,O_CREAT|O_WRONLY, 0666); if (pfd==-1) perror("open pede file"); write(pfd,fpeded,2*NCH*sizeof(float)); write(pfd,fpedeG1d,2*NCH*sizeof(float)); write(pfd,fpedeG2d,2*NCH*sizeof(float)); close(pfd); } void readpede(void) { int pfd; pfd=open(PEDEFNAME,O_RDONLY); if (pfd==-1) perror("open pede file"); read(pfd,fpeded,NCH*2*sizeof(float)); read(pfd,fpedeG1d,NCH*2*sizeof(float)); read(pfd,fpedeG2d,NCH*2*sizeof(float)); close(pfd); pede_flag=true; hasallpede=true; }