pedestal and data structures moved from 2D to 1D array; fixed bug with the file pointer in the zmq process

This commit is contained in:
2020-06-16 13:52:36 +02:00
parent 1d9341f031
commit 2afa620a97
10 changed files with 149 additions and 171 deletions

View File

@ -67,11 +67,11 @@ template <class dataType> class analogDetector {
if (det) if (det)
det->getDetectorSize(nx,ny); det->getDetectorSize(nx,ny);
stat=new pedestalSubtraction*[ny]; stat=new pedestalSubtraction[ny*nx];
for (int i=0; i<ny; i++) { for (int i=0; i<ny; i++) {
stat[i]=new pedestalSubtraction[nx]; // stat[i]=new pedestalSubtraction[nx];
for (int ix=0; ix<nx; ix++) { for (int ix=0; ix<nx; ix++) {
stat[i][ix].SetNPedestals(nped); stat[i*nx+ix].SetNPedestals(nped);
} }
} }
image=new int[nx*ny]; image=new int[nx*ny];
@ -95,7 +95,7 @@ template <class dataType> class analogDetector {
/** /**
destructor. Deletes the pdestalSubtraction array and the image destructor. Deletes the pdestalSubtraction array and the image
*/ */
virtual ~analogDetector() {for (int i=0; i<ny; i++) delete [] stat[i]; delete [] stat; delete [] image; virtual ~analogDetector() {for (int i=0; i<ny; i++) delete [] stat; delete [] image;
#ifdef ROOTSPECTRUM #ifdef ROOTSPECTRUM
delete hs; delete hs;
#ifdef ROOTCLUST #ifdef ROOTCLUST
@ -131,16 +131,13 @@ template <class dataType> class analogDetector {
myFile=orig->myFile; myFile=orig->myFile;
stat=new pedestalSubtraction*[ny]; stat=new pedestalSubtraction[ny*nx];
for (int i=0; i<ny; i++) {
stat[i]=new pedestalSubtraction[nx];
}
int nped=orig->SetNPedestals(); int nped=orig->SetNPedestals();
//cout << nped << " " << orig->getPedestal(ix,iy) << orig->getPedestalRMS(ix,iy) << endl; //cout << nped << " " << orig->getPedestal(ix,iy) << orig->getPedestalRMS(ix,iy) << endl;
for (int iy=0; iy<ny; iy++) { for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) { for (int ix=0; ix<nx; ix++) {
stat[iy][ix].SetNPedestals(nped); stat[iy*nx+ix].SetNPedestals(nped);
setPedestal(ix,iy,orig->getPedestal(ix,iy),orig->getPedestalRMS(ix,iy),orig->GetNPedestals(ix,iy)); setPedestal(ix,iy,orig->getPedestal(ix,iy),orig->getPedestalRMS(ix,iy),orig->GetNPedestals(ix,iy));
} }
} }
@ -272,7 +269,7 @@ template <class dataType> class analogDetector {
iframe=-1; iframe=-1;
for (int iy=0; iy<ny; iy++) for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++) { for (int ix=0; ix<nx; ix++) {
stat[iy][ix].Clear(); stat[iy*nx+ix].Clear();
image[iy*nx+ix]=0; image[iy*nx+ix]=0;
} }
if (cmSub) cmSub->Clear(); if (cmSub) cmSub->Clear();
@ -342,7 +339,7 @@ template <class dataType> class analogDetector {
val+=getGhost(ix,iy); val+=getGhost(ix,iy);
// cout << val ; // cout << val ;
// cout << endl; // cout << endl;
stat[iy][ix].addToPedestal(val); stat[iy*nx+ix].addToPedestal(val);
/* if (cmSub && cm>0) { */ /* if (cmSub && cm>0) { */
/* if (det) if (det->isGood(ix, iy)==0) return; */ /* if (det) if (det->isGood(ix, iy)==0) return; */
/* cmSub->addToCommonMode(val, ix, iy); */ /* cmSub->addToCommonMode(val, ix, iy); */
@ -405,9 +402,9 @@ template <class dataType> class analogDetector {
virtual double getPedestal (int ix, int iy, int cm=0){ virtual double getPedestal (int ix, int iy, int cm=0){
if (ix>=0 && ix<nx && iy>=0 && iy<ny) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
if (cmSub && cm>0) { if (cmSub && cm>0) {
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; } else return -1;
}; };
@ -426,14 +423,14 @@ template <class dataType> class analogDetector {
if (g==0) g=-1.; 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; return -1;
}; };
virtual int getNumpedestals(int ix, int iy){ virtual int getNumpedestals(int ix, int iy){
if (ix>=0 && ix<nx && iy>=0 && iy<ny) if (ix>=0 && ix<nx && iy>=0 && iy<ny)
return stat[iy][ix].getNumpedestals(); return stat[iy*nx+ix].getNumpedestals();
return -1; return -1;
}; };
/** /**
@ -449,7 +446,7 @@ template <class dataType> class analogDetector {
} }
for (int iy=0; iy<ny; iy++) { for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) { for (int ix=0; ix<nx; ix++) {
ped[iy*nx+ix]=stat[iy][ix].getPedestal(); ped[iy*nx+ix]=stat[iy*nx+ix].getPedestal();
//cout << ped[iy*nx+ix] << " " ; //cout << ped[iy*nx+ix] << " " ;
} }
} }
@ -468,7 +465,7 @@ template <class dataType> class analogDetector {
} }
for (int iy=0; iy<ny; iy++) { for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) { for (int ix=0; ix<nx; ix++) {
ped[iy*nx+ix]=stat[iy][ix].getPedestalRMS(); ped[iy*nx+ix]=stat[iy*nx+ix].getPedestalRMS();
} }
} }
return ped; return ped;
@ -494,7 +491,7 @@ template <class dataType> class analogDetector {
\param rms rms to be set if any, defaults to 0 \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 \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<nx && iy>=0 && iy<ny) stat[iy][ix].setPedestal(val,rms, m);}; virtual void setPedestal(int ix, int iy, double val, double rms=0, int m=-1){if (ix>=0 && ix<nx && iy>=0 && iy<ny) stat[iy*nx+ix].setPedestal(val,rms, m);};
/** /**
sets pedestal sets pedestal
@ -509,8 +506,8 @@ template <class dataType> class analogDetector {
for (int iy=ymin; iy<ymax; iy++) { for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) { for (int ix=xmin; ix<xmax; ix++) {
if (rms) rr=rms[iy*nx+ix]; if (rms) rr=rms[iy*nx+ix];
stat[iy][ix].setPedestal(ped[iy*nx+ix],rr, m); stat[iy*nx+ix].setPedestal(ped[iy*nx+ix],rr, m);
// cout << ix << " " << iy << " " << ped[iy*nx+ix] << " " << stat[iy][ix].getPedestal() << endl; // cout << ix << " " << iy << " " << ped[iy*nx+ix] << " " << stat[iy*nx+ix].getPedestal() << endl;
}; };
}; };
@ -526,7 +523,7 @@ template <class dataType> class analogDetector {
\param iy pixel y coordinate \param iy pixel y coordinate
\param rms value to set \param rms value to set
*/ */
virtual void setPedestalRMS(int ix, int iy, double rms=0){if (ix>=0 && ix<nx && iy>=0 && iy<ny) stat[iy][ix].setPedestalRMS(rms);}; virtual void setPedestalRMS(int ix, int iy, double rms=0){if (ix>=0 && ix<nx && iy>=0 && iy<ny) stat[iy*nx+ix].setPedestalRMS(rms);};
@ -538,7 +535,7 @@ template <class dataType> class analogDetector {
virtual void setPedestalRMS(double *rms){ virtual void setPedestalRMS(double *rms){
for (int iy=ymin; iy<ymax; iy++) { for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) { for (int ix=xmin; ix<xmax; ix++) {
stat[iy][ix].setPedestalRMS(rms[iy*nx+ix]); stat[iy*nx+ix].setPedestalRMS(rms[iy*nx+ix]);
}; };
}; };
@ -628,9 +625,9 @@ template <class dataType> class analogDetector {
for (int iy=0; iy<ny; iy++) { for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) { for (int ix=0; ix<nx; ix++) {
/* if (cmSub) */ /* if (cmSub) */
/* gm[iy*nx+ix]=stat[iy][ix].getPedestal()-cmSub->getCommonMode(); */ /* gm[iy*nx+ix]=stat[iy*nx+ix].getPedestal()-cmSub->getCommonMode(); */
/* else */ /* else */
gm[iy*nx+ix]=stat[iy][ix].getPedestal(); gm[iy*nx+ix]=stat[iy*nx+ix].getPedestal();
#ifdef ROOTSPECTRUM #ifdef ROOTSPECTRUM
hmap->SetBinContent(ix+1, iy+1,gm[iy*nx+ix]); hmap->SetBinContent(ix+1, iy+1,gm[iy*nx+ix]);
#endif #endif
@ -674,7 +671,7 @@ template <class dataType> class analogDetector {
if (gm) { if (gm) {
for (int iy=0; iy<nny; iy++) { for (int iy=0; iy<nny; iy++) {
for (int ix=0; ix<nnx; ix++) { for (int ix=0; ix<nnx; ix++) {
stat[iy][ix].setPedestal(gm[iy*nx+ix],-1,-1); stat[iy*nx+ix].setPedestal(gm[iy*nx+ix],-1,-1);
} }
} }
delete [] gm; delete [] gm;
@ -725,7 +722,7 @@ template <class dataType> class analogDetector {
gm=new float[nx*ny]; gm=new float[nx*ny];
for (int iy=0; iy<ny; iy++) { for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) { for (int ix=0; ix<nx; ix++) {
gm[iy*nx+ix]=stat[iy][ix].getPedestalRMS(); gm[iy*nx+ix]=stat[iy*nx+ix].getPedestalRMS();
} }
} }
ret=WriteToTiff(gm, imgname, ny, nx); ret=WriteToTiff(gm, imgname, ny, nx);
@ -747,7 +744,7 @@ template <class dataType> class analogDetector {
if (gm) { if (gm) {
for (int iy=0; iy<nny; iy++) { for (int iy=0; iy<nny; iy++) {
for (int ix=0; ix<nnx; ix++) { for (int ix=0; ix<nnx; ix++) {
stat[iy][ix].setPedestalRMS(gm[iy*nx+ix]); stat[iy*nx+ix].setPedestalRMS(gm[iy*nx+ix]);
} }
} }
delete [] gm; delete [] gm;
@ -1023,7 +1020,7 @@ template <class dataType> class analogDetector {
nph=v/thr; nph=v/thr;
/* if (ix ==10 && iy<20) */ /* 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; // cout << subtractPedestal(data,ix,iy,0) << " " << subtractPedestal(data,ix,iy,1) << " " << nph << endl;
if (nph>0) { if (nph>0) {
//cout << " " << nph << endl; //cout << " " << nph << endl;
@ -1100,8 +1097,8 @@ template <class dataType> class analogDetector {
if (i>0) if (i>0)
for (iy=0; iy<ny; iy++) for (iy=0; iy<ny; iy++)
for (ix=0; ix<nx; ix++) for (ix=0; ix<nx; ix++)
stat[iy][ix].SetNPedestals(i); stat[iy*nx+ix].SetNPedestals(i);
return stat[0][0].SetNPedestals(); return stat[0].SetNPedestals();
}; };
/** gets number of samples for moving average pedestal calculation /** gets number of samples for moving average pedestal calculation
@ -1109,7 +1106,7 @@ template <class dataType> class analogDetector {
*/ */
int GetNPedestals(int ix, int iy) { int GetNPedestals(int ix, int iy) {
if (ix>=0 && ix<nx && iy>=0 && iy<ny) if (ix>=0 && ix<nx && iy>=0 && iy<ny)
return stat[iy][ix].GetNPedestals(); return stat[iy*nx+ix].GetNPedestals();
else else
return -1; return -1;
}; };
@ -1237,7 +1234,7 @@ FILE *getFilePointer(){return myFile;};
slsDetectorData<dataType> *det; /**< slsDetectorData to be used */ slsDetectorData<dataType> *det; /**< slsDetectorData to be used */
int nx; /**< Size of the detector in x direction */ int nx; /**< Size of the detector in x direction */
int ny; /**< Size of the detector in y direction */ int ny; /**< Size of the detector in y direction */
pedestalSubtraction **stat; /**< pedestalSubtraction class */ pedestalSubtraction *stat; /**< pedestalSubtraction class */
commonModeSubtraction *cmSub;/**< commonModeSubtraction class */ commonModeSubtraction *cmSub;/**< commonModeSubtraction class */
int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */ 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 */ int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */

View File

@ -99,12 +99,12 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
} else { } else {
row=200+i/sc_width; 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 #ifdef HIGHZ
dataMask[row][col]=0x3fff; dataMask[row*nx+col]=0x3fff;
#endif #endif
if (dataMap[row][col]<0 || dataMap[row][col]>=nSamples*2*32) if (dataMap[row*nx+col]<0 || dataMap[row*nx+col]>=nSamples*2*32)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; cout << "Error: pointer " << dataMap[row*nx+col] << " out of range "<< endl;
} }
} }
} }

View File

@ -60,12 +60,12 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
} else { } else {
row=200+i/sc_width; 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 #ifdef HIGHZ
dataMask[row][col]=0x3fff; dataMask[row*nx+col]=0x3fff;
#endif #endif
if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) if (dataMap[row*nx+col]<0 || dataMap[row*nx+col]>=dataSize)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; cout << "Error: pointer " << dataMap[row*nx+col] << " out of range "<< endl;
} }
} }
} }

View File

@ -102,7 +102,7 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
iy=row*2; iy=row*2;
} }
#endif #endif
dataMap[iy][ix]=pix; dataMap[iy*nx+ix]=pix;
} }
} }
} }

View File

@ -15,9 +15,9 @@ class slsDetectorData {
const int nx; /**< Number of pixels in the x direction */ const int nx; /**< Number of pixels in the x direction */
const int ny; /**< Number of pixels in the y direction */ const int ny; /**< Number of pixels in the y direction */
int dataSize; /**<size of the data constituting one frame */ int dataSize; /**<size of the data constituting one frame */
int **dataMap; /**< Array of size nx*ny storing the pointers to the data in the dataset (as offset)*/ int *dataMap; /**< Array of size nx*ny storing the pointers to the data in the dataset (as offset)*/
dataType **dataMask; /**< Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) */ dataType *dataMask; /**< Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) */
int **dataROIMask; /**< Array of size nx*ny 1 if channel is good (or in the ROI), 0 if bad channel (or out of ROI) */ int *dataROIMask; /**< Array of size nx*ny 1 if channel is good (or in the ROI), 0 if bad channel (or out of ROI) */
int *xmap; int *xmap;
int *ymap; int *ymap;
@ -37,7 +37,7 @@ class slsDetectorData {
\param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
*/ */
slsDetectorData(int npx, int npy, int dsize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), dataSize(dsize) { slsDetectorData(int npx, int npy, int dsize, int *dMap=NULL, dataType *dMask=NULL, int *dROI=NULL): nx(npx), ny(npy), dataSize(dsize) {
int el=dsize/sizeof(dataType); int el=dsize/sizeof(dataType);
xmap=new int[el]; xmap=new int[el];
@ -45,25 +45,14 @@ class slsDetectorData {
// if (dataMask==NULL) { // if (dataMask==NULL) {
dataMask=new dataType*[ny]; dataMask=new dataType[ny*nx];
for(int i = 0; i < ny; i++) {
dataMask[i] = new dataType[nx];
}
// } // }
// if (dataMap==NULL) { // if (dataMap==NULL) {
dataMap=new int*[ny]; dataMap=new int[ny*nx];
for(int i = 0; i < ny; i++) {
dataMap[i] = new int[nx];
}
// } // }
// if (dataROIMask==NULL) { // if (dataROIMask==NULL) {
dataROIMask=new int*[ny]; dataROIMask=new int [ny*nx];
for(int i = 0; i < ny; i++) {
dataROIMask[i] = new int[nx];
for (int j=0; j<nx; j++)
dataROIMask[i][j]=1;
}
// } // }
for (int ip=0; ip<el; ip++){ for (int ip=0; ip<el; ip++){
@ -78,11 +67,6 @@ class slsDetectorData {
}; };
virtual ~slsDetectorData() { virtual ~slsDetectorData() {
for(int i = 0; i < ny; i++) {
delete [] dataMap[i];
delete [] dataMask[i];
delete [] dataROIMask[i];
}
delete [] dataMap; delete [] dataMap;
delete [] dataMask; delete [] dataMask;
delete [] dataROIMask; delete [] dataROIMask;
@ -95,14 +79,14 @@ class slsDetectorData {
defines the data map (as offset) - no error checking if datasize and offsets are compatible! defines the data map (as offset) - no error checking if datasize and offsets are compatible!
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset). If NULL (default),the data are arranged as if read out row by row (dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);) \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset). If NULL (default),the data are arranged as if read out row by row (dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);)
*/ */
void setDataMap(int **dMap=NULL) { void setDataMap(int *dMap=NULL) {
int ip=0; int ip=0;
int ix, iy; int ix, iy;
if (dMap==NULL) { if (dMap==NULL) {
for (iy=0; iy<ny; iy++) { for (iy=0; iy<ny; iy++) {
for (ix=0; ix<nx; ix++) { for (ix=0; ix<nx; ix++) {
dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType); dataMap[iy*nx+ix]=(iy*nx+ix)*sizeof(dataType);
} }
} }
} else { } else {
@ -110,7 +94,7 @@ class slsDetectorData {
for (iy=0; iy<ny; iy++){ for (iy=0; iy<ny; iy++){
// cout << iy << endl; // cout << iy << endl;
for (ix=0; ix<nx; ix++) { for (ix=0; ix<nx; ix++) {
dataMap[iy][ix]=dMap[iy][ix]; dataMap[iy*nx+ix]=dMap[iy*nx+ix];
// cout << ix << " " << iy << endl; // cout << ix << " " << iy << endl;
/*ip=dataMap[ix][iy]/sizeof(dataType); /*ip=dataMap[ix][iy]/sizeof(dataType);
xmap[ip]=ix; xmap[ip]=ix;
@ -120,7 +104,7 @@ class slsDetectorData {
} }
for (iy=0; iy<ny; iy++){ for (iy=0; iy<ny; iy++){
for (ix=0; ix<nx; ix++) { for (ix=0; ix<nx; ix++) {
ip=dataMap[iy][ix]/sizeof(dataType); ip=dataMap[iy*nx+ix]/sizeof(dataType);
xmap[ip]=ix; xmap[ip]=ix;
ymap[ip]=iy; ymap[ip]=iy;
} }
@ -136,17 +120,17 @@ class slsDetectorData {
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
*/ */
void setDataMask(dataType **dMask=NULL){ void setDataMask(dataType *dMask=NULL){
if (dMask!=NULL) { if (dMask!=NULL) {
for (int iy=0; iy<ny; iy++) for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++) for (int ix=0; ix<nx; ix++)
dataMask[iy][ix]=dMask[iy][ix]; dataMask[iy*nx+ix]=dMask[iy*nx+ix];
} else { } else {
for (int iy=0; iy<ny; iy++) for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++) for (int ix=0; ix<nx; ix++)
dataMask[iy][ix]=0; dataMask[iy*nx+ix]=0;
} }
}; };
/** /**
@ -154,18 +138,18 @@ class slsDetectorData {
\param dROI Array of size nx*ny. The lements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. \param dROI Array of size nx*ny. The lements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
*/ */
void setDataROIMask(int **dROI=NULL){ void setDataROIMask(int *dROI=NULL){
if (dROI!=NULL) { if (dROI!=NULL) {
for (int iy=0; iy<ny; iy++) for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++) for (int ix=0; ix<nx; ix++)
dataROIMask[iy][ix]=dROI[iy][ix]; dataROIMask[iy*nx+ix]=dROI[iy*nx+ix];
} else { } else {
for (int iy=0; iy<ny; iy++) for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++) for (int ix=0; ix<nx; ix++)
dataROIMask[iy][ix]=1; dataROIMask[iy*nx+ix]=1;
} }
@ -179,14 +163,14 @@ class slsDetectorData {
\param i 1 if pixel is good (or in the roi), 0 if bad \param i 1 if pixel is good (or in the roi), 0 if bad
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range \returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
*/ */
int setGood(int ix, int iy, int i=1) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) dataROIMask[iy][ix]=i; return isGood(ix,iy);}; int setGood(int ix, int iy, int i=1) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) dataROIMask[iy*nx+ix]=i; return isGood(ix,iy);};
/** /**
Define bad channel or roi mask for a single channel Define bad channel or roi mask for a single channel
\param ix channel x coordinate \param ix channel x coordinate
\param iy channel y coordinate (1 for strips) \param iy channel y coordinate (1 for strips)
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range \returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
*/ */
int isGood(int ix, int iy) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) return dataROIMask[iy][ix]; else return -1;}; int isGood(int ix, int iy) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) return dataROIMask[iy*nx+ix]; else return -1;};
/** /**
Returns detector size in x,y Returns detector size in x,y
@ -205,39 +189,33 @@ class slsDetectorData {
virtual void getPixel(int ip, int &x, int &y) {x=xmap[ip]; y=ymap[ip];}; virtual void getPixel(int ip, int &x, int &y) {x=xmap[ip]; y=ymap[ip];};
virtual dataType **getData(char *ptr, int dsize=-1) { virtual dataType *getData(char *ptr, int dsize=-1) {
int el=dsize/sizeof(dataType); int el=dsize/sizeof(dataType);
dataType **data; dataType *data;
int ix,iy; int ix,iy;
data=new dataType*[ny]; data=new dataType[ny*nx];
for(int i = 0; i < ny; i++) {
data[i]=new dataType[nx];
}
if (dsize<=0 || dsize>dataSize) dsize=dataSize; if (dsize<=0 || dsize>dataSize) dsize=dataSize;
for (int ip=0; ip<(el); ip++) { for (int ip=0; ip<(el); ip++) {
getPixel(ip,ix,iy); getPixel(ip,ix,iy);
if (ix>=0 && ix<nx && iy>=0 && iy<ny) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
data[iy][ix]=getChannel(ptr,ix,iy); data[iy*nx+ix]=getChannel(ptr,ix,iy);
} }
} }
return data; return data;
}; };
virtual double **getImage(char *ptr, int dsize=-1) { virtual double *getImage(char *ptr, int dsize=-1) {
double **data; double *data;
int ix,iy; int ix,iy;
data=new double*[ny]; data=new double[ny*nx];
for(int i = 0; i < ny; i++) {
data[i]=new double[nx];
}
int el=dsize/sizeof(dataType); int el=dsize/sizeof(dataType);
if (dsize<=0 || dsize>dataSize) dsize=dataSize; if (dsize<=0 || dsize>dataSize) dsize=dataSize;
for (int ip=0; ip<el; ip++) { for (int ip=0; ip<el; ip++) {
getPixel(ip,ix,iy); getPixel(ip,ix,iy);
if (ix>=0 && ix<nx && iy>=0 && iy<ny) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
data[iy][ix]=getValue(ptr,ix,iy); data[iy*nx+ix]=getValue(ptr,ix,iy);
} }
} }
return data; return data;
@ -254,11 +232,11 @@ class slsDetectorData {
*/ */
virtual dataType getChannel(char *data, int ix, int iy=0) { virtual dataType getChannel(char *data, int ix, int iy=0) {
dataType m=0, d=0, *p; dataType m=0, d=0, *p;
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) { if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy*nx+ix]>=0 && dataMap[iy*nx+ix]<dataSize) {
// cout << ix << " " << iy << " " ; // cout << ix << " " << iy << " " ;
//cout << dataMap[ix][iy] << " " << (void*)data << " " << dataSize<< endl; //cout << dataMap[ix][iy] << " " << (void*)data << " " << dataSize<< endl;
m=dataMask[iy][ix]; m=dataMask[iy*nx+ix];
p=(dataType*)(data+dataMap[iy][ix]); p=(dataType*)(data+dataMap[iy*nx+ix]);
d=*p; d=*p;
} }
return d^m; return d^m;

View File

@ -51,6 +51,11 @@ class interpolatingDetector : public singlePhotonDetector {
//cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl; //cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl;
fi=new pthread_mutex_t ; fi=new pthread_mutex_t ;
if (pthread_mutex_init(fi, NULL) != 0)
{
printf("\n mutex init failed\n");
}
}; };

View File

@ -364,8 +364,9 @@ int main(int argc, char *argv[]) {
while (mt->isBusy()) {;}//wait until all data are processed from the queues while (mt->isBusy()) {;}//wait until all data are processed from the queues
usleep(1000);
if (of) { if (of) {
mt->setFilePointer(NULL);
fclose(of); fclose(of);
of=NULL; of=NULL;
} }
@ -536,8 +537,8 @@ int main(int argc, char *argv[]) {
// auto meas_duration = duration_cast<microseconds>( t2 - t0 ).count(); // auto meas_duration = duration_cast<microseconds>( t2 - t0 ).count();
// auto real_duration = duration_cast<microseconds>( t2 - t1 ).count(); // auto real_duration = duration_cast<microseconds>( t2 - t1 ).count();
cout << "Measurement lasted " << difftime(end,begin) << endl; // cout << "Measurement lasted " << difftime(end,begin) << endl;
cout << "Processing lasted " << difftime(finished,begin) << endl; //cout << "Processing lasted " << difftime(finished,begin) << endl;
continue; //continue to not get out continue; //continue to not get out

View File

@ -65,10 +65,7 @@ public analogDetector<uint16_t> {
fm=new mutex; fm=new mutex;
// fm=new pthread_mutex_t ; // fm=new pthread_mutex_t ;
eventMask=new eventType*[ny]; eventMask=new eventType[ny*nx];
for (int i=0; i<ny; i++) {
eventMask[i]=new eventType[nx];
}
if (ny==1) if (ny==1)
clusterSizeY=1; clusterSizeY=1;
@ -84,7 +81,7 @@ public analogDetector<uint16_t> {
/** /**
destructor. Deletes the cluster structure, the pdestalSubtraction and the image array destructor. Deletes the cluster structure, the pdestalSubtraction and the image array
*/ */
virtual ~singlePhotonDetector() {delete [] clusters; for (int i=0; i<ny; i++) delete [] eventMask[i]; delete [] eventMask; }; virtual ~singlePhotonDetector() {delete [] clusters; for (int i=0; i<ny; i++) delete [] eventMask; };
@ -99,10 +96,7 @@ public analogDetector<uint16_t> {
nDark=orig->nDark; nDark=orig->nDark;
myFile=orig->myFile; myFile=orig->myFile;
eventMask=new eventType*[ny]; eventMask=new eventType[ny*nx];
for (int i=0; i<ny; i++) {
eventMask[i]=new eventType[nx];
}
eMin=orig->eMin; eMin=orig->eMin;
eMax=orig->eMax; eMax=orig->eMax;
@ -185,7 +179,7 @@ public analogDetector<uint16_t> {
nph=image; nph=image;
//nph=new int[nx*ny]; //nph=new int[nx*ny];
double rest[ny][nx]; double rest[ny*nx];
//int cy=(clusterSizeY+1)/2; //quad size //int cy=(clusterSizeY+1)/2; //quad size
//int cs=(clusterSize+1)/2; //quad size //int cs=(clusterSize+1)/2; //quad size
@ -229,11 +223,11 @@ public analogDetector<uint16_t> {
nn=analogDetector<uint16_t>::getNPhotons(data,ix,iy);//val/thr;// nn=analogDetector<uint16_t>::getNPhotons(data,ix,iy);//val/thr;//
if (nn>0) { if (nn>0) {
nph[ix+nx*iy]+=nn; 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; nphFrame+=nn;
nphTot+=nn; nphTot+=nn;
} else } else
rest[iy][ix]=val; rest[iy*nx+ix]=val;
} }
} }
@ -243,7 +237,7 @@ public analogDetector<uint16_t> {
for (int ix=xmin; ix<xmax; ix++) { for (int ix=xmin; ix<xmax; ix++) {
if (det->isGood(ix,iy)) { if (det->isGood(ix,iy)) {
eventMask[iy][ix]=PEDESTAL; eventMask[iy*nx+ix]=PEDESTAL;
max=0; max=0;
tl=0; tl=0;
tr=0; tr=0;
@ -252,15 +246,15 @@ public analogDetector<uint16_t> {
tot=0; tot=0;
quadTot=0; quadTot=0;
if (rest[iy][ix]>0.25*thr) { if (rest[iy*nx+ix]>0.25*thr) {
eventMask[iy][ix]=NEIGHBOUR; eventMask[iy*nx+ix]=NEIGHBOUR;
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) { if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) {
//clusters->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; tot+=v;
if (ir<=0 && ic<=0) if (ir<=0 && ic<=0)
@ -279,8 +273,9 @@ public analogDetector<uint16_t> {
//} //}
} }
} }
}
if (rest[iy][ix]>=max) { if (rest[iy*nx+ix]>=max) {
if (bl>=br && bl>=tl && bl>=tr) { if (bl>=br && bl>=tl && bl>=tr) {
quad=BOTTOM_LEFT; quad=BOTTOM_LEFT;
quadTot=bl; quadTot=bl;
@ -315,9 +310,9 @@ public analogDetector<uint16_t> {
} }
if (tot>tthr1 || quadTot>tthr2 || max>tthr) { if (tot>tthr1 || quadTot>tthr2 || max>tthr) {
eventMask[iy][ix]=PHOTON; eventMask[iy*nx+ix]=PHOTON;
nph[ix+nx*iy]++; nph[ix+nx*iy]++;
rest[iy][ix]-=thr; rest[iy*nx+ix]-=thr;
nphFrame++; nphFrame++;
nphTot++; nphTot++;
@ -327,7 +322,6 @@ public analogDetector<uint16_t> {
} }
} }
} }
}
} else return getClusters(data, nph); } else return getClusters(data, nph);
} }
return NULL; return NULL;
@ -349,7 +343,7 @@ int *getClusters(char *data, int *ph=NULL) {
int nph=0; int nph=0;
double val[ny][nx]; double val[ny*nx];
int cy=(clusterSizeY+1)/2; int cy=(clusterSizeY+1)/2;
int cs=(clusterSize+1)/2; int cs=(clusterSize+1)/2;
//int ir, ic; //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); (clusters+nph)->rms=getPedestalRMS(ix,iy);
@ -399,11 +393,11 @@ int *getClusters(char *data, int *ph=NULL) {
if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) { if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) {
if ((iy+ir)>=iy &&(ix+ic)>=ix) if ((iy+ir)>=iy &&(ix+ic)>=ix)
val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm); val[(iy+ir)*nx+ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm);
(clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); (clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir);
v=&(val[iy+ir][ix+ic]); v=&(val[(iy+ir)*nx+ix+ic]);
tot+=*v; tot+=*v;
if (ir<=0 && ic<=0) if (ir<=0 && ic<=0)
bl+=*v; bl+=*v;
@ -420,9 +414,9 @@ int *getClusters(char *data, int *ph=NULL) {
if (ir==0 && ic==0) { if (ir==0 && ic==0) {
if (*v<-nSigma*(clusters+nph)->rms) if (*v<-nSigma*(clusters+nph)->rms)
eventMask[iy][ix]=NEGATIVE_PEDESTAL; eventMask[iy*nx+ix]=NEGATIVE_PEDESTAL;
else if (*v>nSigma*(clusters+nph)->rms) else if (*v>nSigma*(clusters+nph)->rms)
eventMask[iy][ix]=PHOTON; eventMask[iy*nx+ix]=PHOTON;
} }
} else } else
@ -430,7 +424,7 @@ int *getClusters(char *data, int *ph=NULL) {
} }
} }
if (eventMask[iy][ix]==PHOTON && val[iy][ix]<max) if (eventMask[iy*nx+ix]==PHOTON && val[iy*nx+ix]<max)
continue; continue;
if (bl>=br && bl>=tl && bl>=tr) { if (bl>=br && bl>=tl && bl>=tr) {
@ -448,8 +442,8 @@ int *getClusters(char *data, int *ph=NULL) {
} }
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 (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) { if (val[iy*nx+ix]>=max) {
eventMask[iy][ix]=PHOTON_MAX; eventMask[iy*nx+ix]=PHOTON_MAX;
// (clusters+nph)->tot=tot; // (clusters+nph)->tot=tot;
(clusters+nph)->x=ix; (clusters+nph)->x=ix;
(clusters+nph)->y=iy; (clusters+nph)->y=iy;
@ -459,7 +453,7 @@ int *getClusters(char *data, int *ph=NULL) {
// for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { // for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
// for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { // for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
// if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) // if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx)
// (clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); // (clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir);
// else // else
// (clusters+nph)->set_data(0,ic,ir); // (clusters+nph)->set_data(0,ic,ir);
@ -472,12 +466,10 @@ int *getClusters(char *data, int *ph=NULL) {
nph++; nph++;
image[iy*nx+ix]++; image[iy*nx+ix]++;
} }
} else { } 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); addToPedestal(data,ix,iy,cm);
} }
} }
@ -530,7 +522,7 @@ int *getClusters(char *data, int *ph=NULL) {
\param ir y coordinate (center is (0,0)) \param ir y coordinate (center is (0,0))
\returns event mask enum for the given pixel \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 #ifdef MYROOT1
@ -579,7 +571,9 @@ int *getClusters(char *data, int *ph=NULL) {
/* if (fwrite((void*)&fn, 1, sizeof(int), f)) */ /* if (fwrite((void*)&fn, 1, sizeof(int), f)) */
/* if (fwrite((void*)&nph, 1, sizeof(int), f)) */ /* if (fwrite((void*)&nph, 1, sizeof(int), f)) */
/* #endif */ /* #endif */
if (f)
for (int i=0; i<nph; i++) (cl+i)->write(f); for (int i=0; i<nph; i++) (cl+i)->write(f);
}; };
void writeClusters(FILE *f, int fn=0){ void writeClusters(FILE *f, int fn=0){
writeClusters(f,clusters,nphFrame, fn); writeClusters(f,clusters,nphFrame, fn);
@ -635,7 +629,7 @@ int *getClusters(char *data, int *ph=NULL) {
protected: protected:
int nDark; /**< number of frames to be used at the beginning of the dataset to calculate pedestal without applying photon discrimination */ 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 nSigma; /**< number of sigma parameter for photon discrimination */
double eMin, eMax; double eMin, eMax;
int clusterSize; /**< cluster size in the x direction */ int clusterSize; /**< cluster size in the x direction */

View File

@ -41,12 +41,12 @@ include_directories(
include 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(ZMQ_STATIC_ARCHIVE ${CMAKE_CURRENT_SOURCE_DIR}/include/libzmq.a)
set_target_properties(zmq PROPERTIES #set_target_properties(zmq PROPERTIES
IMPORTED_LOCATION ${ZMQ_STATIC_ARCHIVE} # IMPORTED_LOCATION ${ZMQ_STATIC_ARCHIVE}
) #)
add_library(slsReceiverStatic STATIC add_library(slsReceiverStatic STATIC
${SOURCES} ${SOURCES}
@ -88,7 +88,7 @@ set_target_properties(slsReceiver PROPERTIES
target_link_libraries(slsReceiver target_link_libraries(slsReceiver
slsReceiverShared slsReceiverShared
pthread pthread
zmq # zmq
rt rt
) )
@ -105,5 +105,7 @@ install(TARGETS slsReceiverShared slsReceiverStatic slsReceiver
PUBLIC_HEADER DESTINATION include) PUBLIC_HEADER DESTINATION include)
install(FILES ${ZMQ_STATIC_ARCHIVE} #install(FILES ${ZMQ_STATIC_ARCHIVE}
#DESTINATION lib)
install(FILES
DESTINATION lib) DESTINATION lib)

View File

@ -62,6 +62,7 @@ else
$(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -pthread $(FLAGS) $(LIBZMQ) -lrt $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -pthread $(FLAGS) $(LIBZMQ) -lrt
endif endif
versioning: versioning:
$(call colorecho,`./updateGitVersion.sh`) $(call colorecho,`./updateGitVersion.sh`)