From 2afa620a97fd9e6e879b9278f675ffb9f1f5f6da Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 16 Jun 2020 13:52:36 +0200 Subject: [PATCH] pedestal and data structures moved from 2D to 1D array; fixed bug with the file pointer in the zmq process --- slsDetectorCalibration/analogDetector.h | 61 ++++----- .../moench03T1ReceiverDataNew.h | 8 +- .../dataStructures/moench03T1ZmqDataNew.h | 8 +- .../dataStructures/moench03T1ZmqDataNewRect.h | 2 +- .../dataStructures/slsDetectorData.h | 82 ++++------- .../interpolatingDetector.h | 5 + .../moenchExecutables/moenchZmqProcess.cpp | 7 +- slsDetectorCalibration/singlePhotonDetector.h | 128 +++++++++--------- slsReceiverSoftware/CMakeLists.txt | 18 +-- slsReceiverSoftware/Makefile | 1 + 10 files changed, 149 insertions(+), 171 deletions(-) diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h index 9f372ea06..21cb87be2 100644 --- a/slsDetectorCalibration/analogDetector.h +++ b/slsDetectorCalibration/analogDetector.h @@ -67,11 +67,11 @@ template class analogDetector { if (det) det->getDetectorSize(nx,ny); - stat=new pedestalSubtraction*[ny]; + stat=new pedestalSubtraction[ny*nx]; for (int i=0; i class analogDetector { /** destructor. Deletes the pdestalSubtraction array and the image */ - virtual ~analogDetector() {for (int i=0; i class analogDetector { myFile=orig->myFile; - stat=new pedestalSubtraction*[ny]; - for (int i=0; iSetNPedestals(); //cout << nped << " " << orig->getPedestal(ix,iy) << orig->getPedestalRMS(ix,iy) << endl; for (int iy=0; iygetPedestal(ix,iy),orig->getPedestalRMS(ix,iy),orig->GetNPedestals(ix,iy)); } } @@ -272,7 +269,7 @@ template class analogDetector { iframe=-1; for (int iy=0; iyClear(); @@ -342,7 +339,7 @@ template class analogDetector { val+=getGhost(ix,iy); // cout << val ; // cout << endl; - stat[iy][ix].addToPedestal(val); + stat[iy*nx+ix].addToPedestal(val); /* if (cmSub && cm>0) { */ /* if (det) if (det->isGood(ix, iy)==0) return; */ /* cmSub->addToCommonMode(val, ix, iy); */ @@ -405,9 +402,9 @@ template class analogDetector { virtual double getPedestal (int ix, int iy, int cm=0){ if (ix>=0 && ix=0 && iy0) { - return stat[iy][ix].getPedestal()+getCommonMode(ix,iy); + return stat[iy*nx+ix].getPedestal()+getCommonMode(ix,iy); - } else return stat[iy][ix].getPedestal(); + } else return stat[iy*nx+ix].getPedestal(); } else return -1; }; @@ -426,14 +423,14 @@ template class analogDetector { if (g==0) g=-1.; } - return stat[iy][ix].getPedestalRMS()/g;//divide by gain? + return stat[iy*nx+ix].getPedestalRMS()/g;//divide by gain? } return -1; }; virtual int getNumpedestals(int ix, int iy){ if (ix>=0 && ix=0 && iy class analogDetector { } for (int iy=0; iy class analogDetector { } for (int iy=0; iy class analogDetector { \param rms rms to be set if any, defaults to 0 \param m number of pedestal samples to be set or the moving stat structure is any, defaults to 0 */ - virtual void setPedestal(int ix, int iy, double val, double rms=0, int m=-1){if (ix>=0 && ix=0 && iy=0 && ix=0 && iy class analogDetector { for (int iy=ymin; iy class analogDetector { \param iy pixel y coordinate \param rms value to set */ - virtual void setPedestalRMS(int ix, int iy, double rms=0){if (ix>=0 && ix=0 && iy=0 && ix=0 && iy class analogDetector { virtual void setPedestalRMS(double *rms){ for (int iy=ymin; iy class analogDetector { for (int iy=0; iygetCommonMode(); */ + /* gm[iy*nx+ix]=stat[iy*nx+ix].getPedestal()-cmSub->getCommonMode(); */ /* else */ - gm[iy*nx+ix]=stat[iy][ix].getPedestal(); + gm[iy*nx+ix]=stat[iy*nx+ix].getPedestal(); #ifdef ROOTSPECTRUM hmap->SetBinContent(ix+1, iy+1,gm[iy*nx+ix]); #endif @@ -674,7 +671,7 @@ template class analogDetector { if (gm) { for (int iy=0; iy class analogDetector { gm=new float[nx*ny]; for (int iy=0; iy class analogDetector { if (gm) { for (int iy=0; iy class analogDetector { nph=v/thr; /* if (ix ==10 && iy<20) */ - /* cout << det->getValue(data,ix,iy) << " " << stat[iy][ix].getPedestal() << " " << getCommonMode(ix,iy) << " " << getPedestal(ix,iy,0)<< " " << getPedestal(ix,iy,1) << endl; */ + /* cout << det->getValue(data,ix,iy) << " " << stat[iy*nx+ix].getPedestal() << " " << getCommonMode(ix,iy) << " " << getPedestal(ix,iy,0)<< " " << getPedestal(ix,iy,1) << endl; */ // cout << subtractPedestal(data,ix,iy,0) << " " << subtractPedestal(data,ix,iy,1) << " " << nph << endl; if (nph>0) { //cout << " " << nph << endl; @@ -1100,8 +1097,8 @@ template class analogDetector { if (i>0) for (iy=0; iy class analogDetector { */ int GetNPedestals(int ix, int iy) { if (ix>=0 && ix=0 && iy *det; /**< slsDetectorData to be used */ int nx; /**< Size of the detector in x direction */ int ny; /**< Size of the detector in y direction */ - pedestalSubtraction **stat; /**< pedestalSubtraction class */ + pedestalSubtraction *stat; /**< pedestalSubtraction class */ commonModeSubtraction *cmSub;/**< commonModeSubtraction class */ int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */ int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */ diff --git a/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h index 62fe17db0..a0ce0c3aa 100644 --- a/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h +++ b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h @@ -99,12 +99,12 @@ class moench03T1ReceiverDataNew : public slsDetectorData { } else { row=200+i/sc_width; } - dataMap[row][col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1); + dataMap[row*nx+col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1); #ifdef HIGHZ - dataMask[row][col]=0x3fff; + dataMask[row*nx+col]=0x3fff; #endif - if (dataMap[row][col]<0 || dataMap[row][col]>=nSamples*2*32) - cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + if (dataMap[row*nx+col]<0 || dataMap[row*nx+col]>=nSamples*2*32) + cout << "Error: pointer " << dataMap[row*nx+col] << " out of range "<< endl; } } } diff --git a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h index 268ec027a..bf359279b 100644 --- a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h +++ b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h @@ -60,12 +60,12 @@ class moench03T1ZmqDataNew : public slsDetectorData { } else { row=200+i/sc_width; } - dataMap[row][col]=(nadc*i+iadc)*2+offset;//+16*(ip+1); + dataMap[row*nx+col]=(nadc*i+iadc)*2+offset;//+16*(ip+1); #ifdef HIGHZ - dataMask[row][col]=0x3fff; + dataMask[row*nx+col]=0x3fff; #endif - if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) - cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + if (dataMap[row*nx+col]<0 || dataMap[row*nx+col]>=dataSize) + cout << "Error: pointer " << dataMap[row*nx+col] << " out of range "<< endl; } } } diff --git a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNewRect.h b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNewRect.h index ac7b3cc0e..dcaf687d4 100644 --- a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNewRect.h +++ b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNewRect.h @@ -102,7 +102,7 @@ class moench03T1ZmqDataNew : public slsDetectorData { iy=row*2; } #endif - dataMap[iy][ix]=pix; + dataMap[iy*nx+ix]=pix; } } } diff --git a/slsDetectorCalibration/dataStructures/slsDetectorData.h b/slsDetectorCalibration/dataStructures/slsDetectorData.h index 7b49392be..b36d3ee31 100644 --- a/slsDetectorCalibration/dataStructures/slsDetectorData.h +++ b/slsDetectorCalibration/dataStructures/slsDetectorData.h @@ -15,9 +15,9 @@ class slsDetectorData { const int nx; /**< Number of pixels in the x direction */ const int ny; /**< Number of pixels in the y direction */ int dataSize; /**=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iydataSize) dsize=dataSize; for (int ip=0; ip<(el); ip++) { getPixel(ip,ix,iy); if (ix>=0 && ix=0 && iydataSize) dsize=dataSize; for (int ip=0; ip=0 && ix=0 && iy=0 && ix=0 && iy=0 && dataMap[iy][ix]=0 && ix=0 && iy=0 && dataMap[iy*nx+ix]isBusy()) {;}//wait until all data are processed from the queues - + usleep(1000); if (of) { + mt->setFilePointer(NULL); fclose(of); of=NULL; } @@ -536,8 +537,8 @@ int main(int argc, char *argv[]) { // auto meas_duration = duration_cast( t2 - t0 ).count(); // auto real_duration = duration_cast( t2 - t1 ).count(); - cout << "Measurement lasted " << difftime(end,begin) << endl; - cout << "Processing lasted " << difftime(finished,begin) << endl; + // cout << "Measurement lasted " << difftime(end,begin) << endl; + //cout << "Processing lasted " << difftime(finished,begin) << endl; continue; //continue to not get out diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index b07e48658..7a6956e21 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -65,10 +65,7 @@ public analogDetector { fm=new mutex; // fm=new pthread_mutex_t ; - eventMask=new eventType*[ny]; - for (int i=0; i { /** destructor. Deletes the cluster structure, the pdestalSubtraction and the image array */ - virtual ~singlePhotonDetector() {delete [] clusters; for (int i=0; i { nDark=orig->nDark; myFile=orig->myFile; - eventMask=new eventType*[ny]; - for (int i=0; ieMin; eMax=orig->eMax; @@ -185,7 +179,7 @@ public analogDetector { nph=image; //nph=new int[nx*ny]; - double rest[ny][nx]; + double rest[ny*nx]; //int cy=(clusterSizeY+1)/2; //quad size //int cs=(clusterSize+1)/2; //quad size @@ -221,19 +215,19 @@ public analogDetector { cout << "add to common mode?"<< endl; addToCommonMode(data); } - for (int iy=ymin; iyisGood(ix,iy)) { val=subtractPedestal(data,ix,iy, cm); nn=analogDetector::getNPhotons(data,ix,iy);//val/thr;// if (nn>0) { nph[ix+nx*iy]+=nn; - rest[iy][ix]=(val-nn*thr);//?+0.5*thr + rest[iy*nx+ix]=(val-nn*thr);//?+0.5*thr nphFrame+=nn; nphTot+=nn; } else - rest[iy][ix]=val; + rest[iy*nx+ix]=val; } } @@ -243,7 +237,7 @@ public analogDetector { for (int ix=xmin; ixisGood(ix,iy)) { - eventMask[iy][ix]=PEDESTAL; + eventMask[iy*nx+ix]=PEDESTAL; max=0; tl=0; tr=0; @@ -252,15 +246,15 @@ public analogDetector { tot=0; quadTot=0; - if (rest[iy][ix]>0.25*thr) { - eventMask[iy][ix]=NEIGHBOUR; + if (rest[iy*nx+ix]>0.25*thr) { + eventMask[iy*nx+ix]=NEIGHBOUR; for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(rest[iy+ir][ix+ic], ic, ir); + //clusters->set_data(rest[(iy+ir)*nx+ix+ic], ic, ir); - v=rest[iy+ir][ix+ic];//clusters->get_data(ic,ir); + v=rest[(iy+ir)*nx+ix+ic];//clusters->get_data(ic,ir); tot+=v; if (ir<=0 && ic<=0) @@ -279,8 +273,9 @@ public analogDetector { //} } } + } - if (rest[iy][ix]>=max) { + if (rest[iy*nx+ix]>=max) { if (bl>=br && bl>=tl && bl>=tr) { quad=BOTTOM_LEFT; quadTot=bl; @@ -292,9 +287,9 @@ public analogDetector { quadTot=tl; } else if (tr>=bl && tr>=tl && tr>=br) { quad=TOP_RIGHT; - quadTot=tr; + quadTot=tr; } - + if (nSigma==0) { tthr=thr; tthr1=thr; @@ -315,9 +310,9 @@ public analogDetector { } if (tot>tthr1 || quadTot>tthr2 || max>tthr) { - eventMask[iy][ix]=PHOTON; + eventMask[iy*nx+ix]=PHOTON; nph[ix+nx*iy]++; - rest[iy][ix]-=thr; + rest[iy*nx+ix]-=thr; nphFrame++; nphTot++; @@ -325,9 +320,8 @@ public analogDetector { } } } - } - } } + } } else return getClusters(data, nph); } return NULL; @@ -349,7 +343,7 @@ int *getClusters(char *data, int *ph=NULL) { int nph=0; - double val[ny][nx]; + double val[ny*nx]; int cy=(clusterSizeY+1)/2; int cs=(clusterSize+1)/2; //int ir, ic; @@ -387,7 +381,7 @@ int *getClusters(char *data, int *ph=NULL) { - eventMask[iy][ix]=PEDESTAL; + eventMask[iy*nx+ix]=PEDESTAL; (clusters+nph)->rms=getPedestalRMS(ix,iy); @@ -399,38 +393,38 @@ int *getClusters(char *data, int *ph=NULL) { if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)=iy &&(ix+ic)>=ix) - val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm); - - (clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); - - v=&(val[iy+ir][ix+ic]); - tot+=*v; - if (ir<=0 && ic<=0) - bl+=*v; - if (ir<=0 && ic>=0) - br+=*v; - if (ir>=0 && ic<=0) - tl+=*v; - if (ir>=0 && ic>=0) - tr+=*v; - if (*v>max) { - max=*v; - } + val[(iy+ir)*nx+ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm); + + (clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir); + + v=&(val[(iy+ir)*nx+ix+ic]); + tot+=*v; + if (ir<=0 && ic<=0) + bl+=*v; + if (ir<=0 && ic>=0) + br+=*v; + if (ir>=0 && ic<=0) + tl+=*v; + if (ir>=0 && ic>=0) + tr+=*v; + if (*v>max) { + max=*v; + } - if (ir==0 && ic==0) { - if (*v<-nSigma*(clusters+nph)->rms) - eventMask[iy][ix]=NEGATIVE_PEDESTAL; - else if (*v>nSigma*(clusters+nph)->rms) - eventMask[iy][ix]=PHOTON; - } - + if (ir==0 && ic==0) { + if (*v<-nSigma*(clusters+nph)->rms) + eventMask[iy*nx+ix]=NEGATIVE_PEDESTAL; + else if (*v>nSigma*(clusters+nph)->rms) + eventMask[iy*nx+ix]=PHOTON; + } + } else - (clusters+nph)->set_data(0,ic,ir); + (clusters+nph)->set_data(0,ic,ir); } } - if (eventMask[iy][ix]==PHOTON && val[iy][ix]=br && bl>=tl && bl>=tr) { @@ -438,7 +432,7 @@ int *getClusters(char *data, int *ph=NULL) { (clusters+nph)->quadTot=bl; } else if (br>=bl && br>=tl && br>=tr) { (clusters+nph)->quad=BOTTOM_RIGHT; - (clusters+nph)->quadTot=br; + (clusters+nph)->quadTot=br; } else if (tl>=br && tl>=bl && tl>=tr) { (clusters+nph)->quad=TOP_LEFT; (clusters+nph)->quadTot=tl; @@ -446,20 +440,20 @@ int *getClusters(char *data, int *ph=NULL) { (clusters+nph)->quad=TOP_RIGHT; (clusters+nph)->quadTot=tr; } - + if (max>nSigma*(clusters+nph)->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*(clusters+nph)->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*(clusters+nph)->rms) { - if (val[iy][ix]>=max) { - eventMask[iy][ix]=PHOTON_MAX; + if (val[iy*nx+ix]>=max) { + eventMask[iy*nx+ix]=PHOTON_MAX; // (clusters+nph)->tot=tot; (clusters+nph)->x=ix; (clusters+nph)->y=iy; (clusters+nph)->iframe=iframe; - // cout << det->getFrameNumber(data) << " " << (clusters+nph)->iframe << endl; + // cout << det->getFrameNumber(data) << " " << (clusters+nph)->iframe << endl; // (clusters+nph)->ped=getPedestal(ix,iy,0); // for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { // for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { // if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(val[iy+ir][ix+ic],ic,ir); + // (clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir); // else // (clusters+nph)->set_data(0,ic,ir); @@ -472,12 +466,10 @@ int *getClusters(char *data, int *ph=NULL) { nph++; image[iy*nx+ix]++; } - - } else { - eventMask[iy][ix]=PHOTON; + eventMask[iy*nx+ix]=PHOTON; } - } else if (eventMask[iy][ix]==PEDESTAL) { + } else if (eventMask[iy*nx+ix]==PEDESTAL) { addToPedestal(data,ix,iy,cm); } } @@ -530,7 +522,7 @@ int *getClusters(char *data, int *ph=NULL) { \param ir y coordinate (center is (0,0)) \returns event mask enum for the given pixel */ - eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];}; + eventType getEventMask(int ic, int ir=0){return eventMask[ir*nx+ic];}; #ifdef MYROOT1 @@ -579,7 +571,9 @@ int *getClusters(char *data, int *ph=NULL) { /* if (fwrite((void*)&fn, 1, sizeof(int), f)) */ /* if (fwrite((void*)&nph, 1, sizeof(int), f)) */ /* #endif */ - for (int i=0; iwrite(f); + if (f) + for (int i=0; iwrite(f); + }; void writeClusters(FILE *f, int fn=0){ writeClusters(f,clusters,nphFrame, fn); @@ -635,7 +629,7 @@ int *getClusters(char *data, int *ph=NULL) { protected: int nDark; /**< number of frames to be used at the beginning of the dataset to calculate pedestal without applying photon discrimination */ - eventType **eventMask; /**< matrix of event type or each pixel */ + eventType *eventMask; /**< matrix of event type or each pixel */ double nSigma; /**< number of sigma parameter for photon discrimination */ double eMin, eMax; int clusterSize; /**< cluster size in the x direction */ diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index 7fdc5d042..9c1a6a343 100644 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -41,12 +41,12 @@ include_directories( include ) -add_library(zmq STATIC IMPORTED GLOBAL) +#add_library(zmq STATIC IMPORTED GLOBAL) -set(ZMQ_STATIC_ARCHIVE ${CMAKE_CURRENT_SOURCE_DIR}/include/libzmq.a) -set_target_properties(zmq PROPERTIES - IMPORTED_LOCATION ${ZMQ_STATIC_ARCHIVE} -) +#set(ZMQ_STATIC_ARCHIVE ${CMAKE_CURRENT_SOURCE_DIR}/include/libzmq.a) +#set_target_properties(zmq PROPERTIES +# IMPORTED_LOCATION ${ZMQ_STATIC_ARCHIVE} +#) add_library(slsReceiverStatic STATIC ${SOURCES} @@ -88,7 +88,7 @@ set_target_properties(slsReceiver PROPERTIES target_link_libraries(slsReceiver slsReceiverShared pthread - zmq +# zmq rt ) @@ -105,5 +105,7 @@ install(TARGETS slsReceiverShared slsReceiverStatic slsReceiver PUBLIC_HEADER DESTINATION include) -install(FILES ${ZMQ_STATIC_ARCHIVE} -DESTINATION lib) \ No newline at end of file +#install(FILES ${ZMQ_STATIC_ARCHIVE} +#DESTINATION lib) +install(FILES +DESTINATION lib) \ No newline at end of file diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 655d0c1dc..142b3b465 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -62,6 +62,7 @@ else $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -pthread $(FLAGS) $(LIBZMQ) -lrt endif + versioning: $(call colorecho,`./updateGitVersion.sh`)