From 846d2702430c93b31fef4560a2ef44f4cf7a7890 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 13 Aug 2019 16:06:32 +0200 Subject: [PATCH] Implemenging common mode and ghost corrections for moench03 (and generalized) --- slsDetectorCalibration/analogDetector.h | 84 ++++++++++++++----- .../commonModeSubtractionNew.h | 16 +++- .../moench03T1ReceiverDataNew.h | 77 ++++++++++++++++- .../dataStructures/moench03T1ZmqDataNew.h | 77 ++++++++++++++++- slsDetectorCalibration/ghostSummation.h | 61 ++++++++++++++ .../interpolatingDetector.h | 4 +- slsDetectorCalibration/moench03CommonMode.h | 67 ++++++++------- .../moench03GhostSummation.h | 57 +++++++++++++ .../moenchExecutables/moenchPhotonCounter.cpp | 51 +++++++---- .../moenchExecutables/moenchZmqProcess.cpp | 23 +++-- slsDetectorCalibration/singlePhotonDetector.h | 6 +- 11 files changed, 437 insertions(+), 86 deletions(-) create mode 100644 slsDetectorCalibration/ghostSummation.h create mode 100644 slsDetectorCalibration/moench03GhostSummation.h diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h index 49197f0a6..f98f4bf78 100644 --- a/slsDetectorCalibration/analogDetector.h +++ b/slsDetectorCalibration/analogDetector.h @@ -6,7 +6,8 @@ #include #include "slsDetectorData.h" #include "pedestalSubtraction.h" -#include "commonModeSubtraction.h" +#include "commonModeSubtractionNew.h" +#include "ghostSummation.h" #include "tiffIO.h" #include "slsInterpolation.h" @@ -61,7 +62,7 @@ template class analogDetector { analogDetector(slsDetectorData *d, int sign=1, - commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), iframe(-1), dataSign(sign), gmap(gm), id(0) { + commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation *gs=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), iframe(-1), dataSign(sign), gmap(gm), ghSum(gs), id(0) { if (det) det->getDetectorSize(nx,ny); @@ -118,7 +119,7 @@ template class analogDetector { dataSign=orig->dataSign; iframe=orig->iframe; gmap=orig->gmap; - cmSub=orig->cmSub; + // cmSub=orig->cmSub; id=orig->id; xmin=orig->xmin; xmax=orig->xmax; @@ -153,7 +154,9 @@ template class analogDetector { hs9=(TH2F*)(orig->hs9)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); #endif #endif - + if (orig->cmSub) cmSub=(orig->cmSub)->Clone(); + if (orig->ghSum) ghSum=(orig->ghSum)->Clone(); + else ghSum=NULL; } @@ -275,6 +278,9 @@ template class analogDetector { /** resets the commonModeSubtraction and increases the frame index */ virtual void newFrame(){iframe++; if (cmSub) cmSub->newFrame();}; + + /** resets the commonModeSubtraction and increases the frame index */ + virtual void newFrame(char *data){iframe++; if (cmSub) cmSub->newFrame(); calcGhost(data);}; /** sets the commonModeSubtraction algorithm to be used @@ -289,6 +295,11 @@ template class analogDetector { commonModeSubtraction *getCommonModeSubtraction() {return cmSub;}; + ghostSummation *getGhostSummation(){return ghSum;}; + ghostSummation *setGhostSummation(ghostSummation *gs){ghSum=gs; return ghSum;}; + + + /** sets the sign of the data \param sign 1 means positive values for photons, -1 negative, 0 gets @@ -306,9 +317,15 @@ template class analogDetector { */ virtual void addToPedestal(double val, int ix, int iy=0, int cm=0){ if (ix>=0 && ix=0 && iy0) { val-= getCommonMode(ix, iy); } + // cout << val << " " ; + val+=getGhost(ix,iy); + // cout << val ; + // cout << endl; stat[iy][ix].addToPedestal(val); /* if (cmSub && cm>0) { */ /* if (det) if (det->isGood(ix, iy)==0) return; */ @@ -324,23 +341,29 @@ template class analogDetector { virtual void addToCommonMode(char *data){ + // cout << "+"<< endl; if (cmSub) { + // cout << "*" << endl; for (int iy=ymin; iy0) - if (det->isGood(ix,iy)) + // if (det->isGood(ix,iy)) { addToCommonMode(data, ix, iy); - } + // cout << ":"; + // } } + } //cout << "cm " << getCommonMode(0,0) << " " << getCommonMode(1,0) << endl; } } + virtual void addToCommonMode(char *data, int ix, int iy=0){ if (cmSub) { if (det) if (det->isGood(ix, iy)==0) return; if (getNumpedestals(ix,iy)>0){ cmSub->addToCommonMode(subtractPedestal(data,ix,iy,0), ix, iy); - // cout << ix << " " < class analogDetector { \param cm 0 (default) without common mode subtraction, 1 with common mode subtraction (if defined) \returns pedestal value */ - virtual double getPedestal(int ix, int iy, int cm=0){ + virtual double getPedestal (int ix, int iy, int cm=0){ if (ix>=0 && ix=0 && iy0) return stat[iy][ix].getPedestal()+getCommonMode(ix,iy); @@ -482,7 +505,10 @@ template class analogDetector { } + virtual void calcGhost(char *data, int ix, int iy=1) {if (ghSum) ghSum->calcGhost(data, ix, iy);}; + virtual void calcGhost(char *data){if (ghSum) ghSum->calcGhost(data);}; + virtual double getGhost(int ix, int iy) {if (ghSum) return ghSum->getGhost(ix, iy); return 0;}; /** write 32bit tiff file with detector image data @@ -691,9 +717,12 @@ template class analogDetector { virtual void addToPedestal(char *data, int cm=0) { // cout << "add to pedestal " << endl; - newFrame(); + newFrame(data); - if (cmSub) { + //calcGhost(data); + + + if (cmSub && cm) { addToCommonMode(data); } @@ -702,7 +731,8 @@ template class analogDetector { for (int iy=ymin; iyisGood(ix,iy)) { - addToPedestal(data,ix,iy,1); + // addToPedestal(data,ix,iy,1); + addToPedestal(data,ix,iy,cm); //if (ix==10 && iy==10) // cout < class analogDetector { val=dataSign*det->getValue(data, ix, iy); else val=((double*)data)[iy*nx+ix]; - + // cout << val << endl; + val+=getGhost(ix,iy); /* if (ix==10 && iy==10) */ /* cout << ix << " " << iy << " " << val ; */ /* if (ix==100 && iy==100) */ /* cout << ix << " " << iy << " " << val; */ addToPedestal(val,ix,iy); + // cout << val << endl; /* if (ix==10 && iy==10) */ /* cout <<" " << getPedestal(ix,iy)<< endl; */ /* if (ix==100 && iy==100) */ @@ -818,15 +850,17 @@ template class analogDetector { virtual int *subtractPedestal(char *data, int *val=NULL, int cm=0) { - newFrame(); + newFrame(data); if (val==NULL) val=image;//new double[nx*ny]; - for (int iy=ymin; iyisGood(ix,iy)) - val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm); + //calcGhost(data); + + for (int iy=ymin; iyisGood(ix,iy)) + val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm); } } return val; @@ -861,6 +895,8 @@ template class analogDetector { } else val= (((double*)data)[iy*nx+ix]-getPedestal(ix,iy))/g; + val+=getGhost(ix,iy)/g; + #ifdef ROOTSPECTRUM hs->Fill(val,(iy-ymin)*(xmax-xmin)+(ix-xmin)); #ifdef ROOTCLUST @@ -949,10 +985,10 @@ template class analogDetector { double val; if (nph==NULL) nph=image; - newFrame(); + newFrame(data); + //calcGhost(data); addToCommonMode(data); - for (int iy=ymin; iyisGood(ix,iy)) @@ -1032,13 +1068,16 @@ template class analogDetector { if (ymi<0) ymi=ymin; if (yma<0) yma=ymax; - for (int iy=ymi; iyisGood(ix,iy)) { if (ix>=0 && ix=0 && iy *ghSum;/**< ghostSummation class */ int *image; int id; //int xmin, xmax, ymin, ymax; int xmin; /**< minimum x of the region of interest */ diff --git a/slsDetectorCalibration/commonModeSubtractionNew.h b/slsDetectorCalibration/commonModeSubtractionNew.h index 255500644..5e32fd960 100644 --- a/slsDetectorCalibration/commonModeSubtractionNew.h +++ b/slsDetectorCalibration/commonModeSubtractionNew.h @@ -23,6 +23,13 @@ class commonModeSubtraction { /** destructor - deletes the moving average(s) and the sum of pedestals calculator(s) */ virtual ~commonModeSubtraction() {delete [] mean; delete [] mean2; delete [] nCm;}; + /* commonModeSubtraction(commonModeSubtraction *cs) { */ + /* if (cs) new commonModeSubtraction(cs->getNRoi(), cs->nsigma); */ + /* } */ + + virtual commonModeSubtraction *Clone() { + new commonModeSubtraction(this->nROI, this->nsigma); + } /** clears the moving average and the sum of pedestals calculation - virtual func*/ virtual void Clear(){ @@ -52,7 +59,9 @@ class commonModeSubtraction { // if (iroi==0) val=100; // else val=-100; // if (isc>=0 && isc=0 && iroi=0 && iroi0) + if (nCm[iroi]>0) return mean[iroi]/nCm[iroi]; } return 0; @@ -96,8 +105,7 @@ class commonModeSubtraction { gets the common mode ROI for pixel ix, iy -should be overloaded! */ virtual int getROI(int ix, int iy){ (void) ix; (void) iy; return 0;}; - - + int getNRoi(){return nROI;}; protected: double *mean; /** { int sc_height; const int nSamples; + double ghost[200][25]; public: @@ -64,7 +65,7 @@ class moench03T1ReceiverDataNew : public slsDetectorData { \param c crosstalk parameter for the output buffer */ - moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(400, 400, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(400, 400, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { int nadc=32; int sc_width=25; @@ -106,6 +107,11 @@ class moench03T1ReceiverDataNew : public slsDetectorData { } } } + // double ghost[200][25]; + + for (int ix=0; ix<25; ix++) + for (int iy=0; iy<200; iy++) + ghost[iy][ix]=0.; int ipacket; int ibyte; @@ -142,6 +148,73 @@ class moench03T1ReceiverDataNew : public slsDetectorData { }; + + /** + Returns the value of the selected channel for the given dataset as double. + \param data pointer to the dataset (including headers etc) + \param ix pixel number in the x direction + \param iy pixel number in the y direction + \returns data for the selected channel, with inversion if required as double + + */ + virtual double getValue(char *data, int ix, int iy=0) { + /* cout << " x "<< ix << " y"<< iy << " val " << getChannel(data, ix, iy)<< endl;*/ + /* double val=0, vout=getChannel(data, ix, iy); */ + /* int x1=ix%25; */ + /* for (int ix=0; ix<16; ix++) { */ + /* for (int ii=0; ii<2; ii++) { */ + /* val+=getChannel(data,x1+25*ix,iy); */ + /* val+=getChannel(data,x1+25*ix,399-iy); */ + /* } */ + /* } */ + /* vout+=0.0008*val-6224; */ + /* return vout; //(double)getChannel(data, ix, iy); + */ + uint16_t val=getChannel(data, ix, iy)&0x3fff; + return val; + }; + + + + virtual void calcGhost(char *data, int ix, int iy) { + double val=0; + /* for (int ix=0; ix<25; ix++){ */ + /* for (int iy=0; iy<200; iy++) { */ + val=0; + // cout << "** "; + for (int isc=0; isc<16; isc++) { + // for (int ii=0; ii<2; ii++) { + val+=getChannel(data,ix+25*isc,iy); + // cout << "(" << isc << "," << val << " " ; + val+=getChannel(data,ix+25*isc,399-iy); + // cout << val << " " ; + // } + } + ghost[iy][ix]=val;//-6224; + // cout << " --"<< endl; + /* } */ + /* } */ + // cout << "*" << endl; + + } + + + + virtual void calcGhost(char *data) { + for (int ix=0; ix<25; ix++){ + for (int iy=0; iy<200; iy++) { + calcGhost(data, ix,iy); + } + } + // cout << "*" << endl; + } + + + double getGhost(int ix, int iy) { + if (iy<200) return ghost[iy][ix%25]; + if (iy<400) return ghost[399-iy][ix%25]; + return 0; + }; /** @@ -278,8 +351,6 @@ class moench03T1ReceiverDataNew : public slsDetectorData { } - - //int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;}; }; diff --git a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h index 1622e2792..479170ea1 100644 --- a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h +++ b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h @@ -14,6 +14,9 @@ class moench03T1ZmqDataNew : public slsDetectorData { const int nSamples; const int offset; + double ghost[200][25]; + double xtalk; + public: @@ -25,7 +28,7 @@ class moench03T1ZmqDataNew : public slsDetectorData { \param c crosstalk parameter for the output buffer */ - moench03T1ZmqDataNew(int ns=5000): slsDetectorData(400, 400, ns*32*2+sizeof(int)), nSamples(ns), offset(sizeof(int)) { + moench03T1ZmqDataNew(int ns=5000): slsDetectorData(400, 400, ns*32*2+sizeof(int)), nSamples(ns), offset(sizeof(int)), xtalk(0.00021) { int nadc=32; int sc_width=25; @@ -100,12 +103,84 @@ class moench03T1ZmqDataNew : public slsDetectorData { + for (int ix=0; ix<25; ix++) + for (int iy=0; iy<200; iy++) + ghost[iy][ix]=0.; + // iframe=0; // cout << "data struct created" << endl; }; + double getXTalk(){return xtalk;}; + void setXTalk(double g) {xtalk=g;}; + + /** + Returns the value of the selected channel for the given dataset as double. + \param data pointer to the dataset (including headers etc) + \param ix pixel number in the x direction + \param iy pixel number in the y direction + \returns data for the selected channel, with inversion if required as double + + */ + virtual double getValue(char *data, int ix, int iy=0) { + /* cout << " x "<< ix << " y"<< iy << " val " << getChannel(data, ix, iy)<< endl;*/ + /* double val=0, vout=getChannel(data, ix, iy); */ + /* int x1=ix%25; */ + /* for (int ix=0; ix<16; ix++) { */ + /* for (int ii=0; ii<2; ii++) { */ + /* val+=getChannel(data,x1+25*ix,iy); */ + /* val+=getChannel(data,x1+25*ix,399-iy); */ + /* } */ + /* } */ + /* vout+=0.0008*val-6224; */ + /* return vout; //(double)getChannel(data, ix, iy); + */ + return ((double)getChannel(data, ix, iy))+xtalk*getGhost(iy,iy); + }; + + + + virtual void calcGhost(char *data, int ix, int iy) { + double val=0; + /* for (int ix=0; ix<25; ix++){ */ + /* for (int iy=0; iy<200; iy++) { */ + val=0; + for (int isc=0; isc<16; isc++) { + for (int ii=0; ii<2; ii++) { + val+=getChannel(data,ix+25*isc,iy); + // cout << val << " " ; + val+=getChannel(data,ix+25*isc,399-iy); + // cout << val << " " ; + } + } + ghost[iy][ix]=val;//-6224; + // cout << endl; + /* } */ + /* } */ + // cout << "*" << endl; + + } + + + + virtual void calcGhost(char *data) { + for (int ix=0; ix<25; ix++){ + for (int iy=0; iy<200; iy++) { + calcGhost(data, ix,iy); + } + } + // cout << "*" << endl; + } + + + double getGhost(int ix, int iy) { + if (iy<200) return ghost[iy][ix%25]; + if (iy<400) return ghost[399-iy][ix%25]; + return 0; + }; + /** diff --git a/slsDetectorCalibration/ghostSummation.h b/slsDetectorCalibration/ghostSummation.h new file mode 100644 index 000000000..02bb0a359 --- /dev/null +++ b/slsDetectorCalibration/ghostSummation.h @@ -0,0 +1,61 @@ +#ifndef GHOSTSUMMATION_H +#define GHOSTSUMMATION_H + +#include +#include "slsDetectorData.h" + +template class ghostSummation { + + /** @short virtual calss to handle ghosting*/ + + public: + + /** constructor + \param xt crosstalk + */ + ghostSummation(slsDetectorData *d, double xt) : xtalk(xt),det(d) { + if (det) + det->getDetectorSize(nx,ny); + ghost=new double[nx*ny]; + }; + + ghostSummation(ghostSummation *orig) { + xtalk=orig->xtalk; + det=orig->det; + ghost=new double[nx*ny]; + + } + ~ghostSummation() {delete [] ghost;}; + + virtual ghostSummation *Clone() { + new ghostSummation(this); + } + + double getXTalk(){return xtalk;}; + void setXTalk(double g) {xtalk=g;}; + + virtual double calcGhost(char *data, int ix, int iy=1){ghost[iy*nx+ix]=0;}; + + virtual void calcGhost(char *data){ + for (int iy=0; iy=nx || iy<0 || iy>=ny) return 0; + return ghost[iy*nx+ix]; + } + + protected: + double xtalk; + slsDetectorData *det; + double *ghost; + int nx, ny; + +}; + + + + + +#endif diff --git a/slsDetectorCalibration/interpolatingDetector.h b/slsDetectorCalibration/interpolatingDetector.h index f5ce437bd..dc9002caa 100644 --- a/slsDetectorCalibration/interpolatingDetector.h +++ b/slsDetectorCalibration/interpolatingDetector.h @@ -46,8 +46,8 @@ class interpolatingDetector : public singlePhotonDetector { int sign=1, commonModeSubtraction *cm=NULL, int nped=1000, - int nd=100, int nnx=-1, int nny=-1) : - singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0) { + int nd=100, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation *gs=NULL) : + singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny, gm, gs) , interp(inte), id(0) { //cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl; fi=new pthread_mutex_t ; diff --git a/slsDetectorCalibration/moench03CommonMode.h b/slsDetectorCalibration/moench03CommonMode.h index 7c950a9e4..f4e3b1f43 100644 --- a/slsDetectorCalibration/moench03CommonMode.h +++ b/slsDetectorCalibration/moench03CommonMode.h @@ -1,43 +1,52 @@ #ifndef MOENCH03COMMONMODE_H #define MOENCH03COMMONMODE_H -#include "commonModeSubtraction.h" +#include "commonModeSubtractionNew.h" -class moench03CommonMode : public commonModeSubtraction { +class commonModeSubtractionColumn: public commonModeSubtraction{ +public: + commonModeSubtractionColumn(int nr=200) : commonModeSubtraction(800), rows(nr) {}; + virtual int getROI(int ix, int iy){return ix+(iy/200)*400;}; + + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + if (ix399-rows) { + int iroi=getROI(ix,iy); + if (iroi>=0 && iroi=0 && isc=0 && isc0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); - } - return 0; - }; }; diff --git a/slsDetectorCalibration/moench03GhostSummation.h b/slsDetectorCalibration/moench03GhostSummation.h new file mode 100644 index 000000000..64ec787dd --- /dev/null +++ b/slsDetectorCalibration/moench03GhostSummation.h @@ -0,0 +1,57 @@ +#ifndef MOENCH03GHOSTSUMMATION_H +#define MOENCH03GHOSTSUMMATION_H + +#include "ghostSummation.h" + +class moench03GhostSummation : public ghostSummation { + + /** @short virtual calss to handle ghosting*/ + + public: + + /** constructor + \param xt crosstalk + */ + moench03GhostSummation(slsDetectorData *d, double xt) : ghostSummation(d, xt) {} + + virtual void calcGhost(char *data){ + for (int iy=0; iy<200; iy++){ + for (int ix=0; ix<25; ix++){ + calcGhost(data,ix,iy); + } + } + }; + + + virtual double calcGhost(char *data, int x, int y=0){ + int ix=x%25; + int iy=y; + if (y>=200) iy=399-y; + if (iy<0 || ix<0) return 0; + double val=0; + val=0; + for (int isc=0; isc<16; isc++) { + val+=det->getChannel(data,ix+25*isc,iy); + // cout << val << " " ; + val+=det->getChannel(data,ix+25*isc,399-iy); + // cout << val << " " ; + } + ghost[iy*nx+ix]=xtalk*val; + return ghost[iy*nx+ix]; + }; + + + virtual double getGhost(int ix, int iy) { + if (iy >=0 && iy<200) return ghost[iy*nx+(ix%25)]; + if (iy<400) return ghost[(399-iy)*nx+(ix%25)]; + return 0; + }; + + +}; + + + + + +#endif diff --git a/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp b/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp index 6ce266150..8c8c82b20 100644 --- a/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp +++ b/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp @@ -1,6 +1,6 @@ //#include "ansi.h" #include - +#define CORR //#define VERSION_V1 @@ -28,8 +28,11 @@ //#include "etaInterpolationPosXY.h" // #include "linearInterpolation.h" // #include "noInterpolation.h" -#include "multiThreadedAnalogDetector.h" +#include "multiThreadedCountingDetector.h" +//#include "multiThreadedAnalogDetector.h" #include "singlePhotonDetector.h" +#include "moench03GhostSummation.h" +#include "moench03CommonMode.h" //#include "interpolatingDetector.h" #include @@ -89,7 +92,18 @@ int main(int argc, char *argv[]) { decoder->getDetectorSize(nx,ny); - singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200); + int ncol_cm=20; + double xt_ghost=0.00045; + moench03CommonMode *cm=NULL; + moench03GhostSummation *gs; + double *gainmap=NULL; +#ifdef CORR + cout << "Applying common mode and ghost correction " << endl; + cm=new moench03CommonMode(ncol_cm); + gs=new moench03GhostSummation(decoder, xt_ghost); +#endif + + singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, cm, nped, 200, -1, -1, gainmap, gs); int size = 327680;////atoi(argv[3]); @@ -171,9 +185,10 @@ int main(int argc, char *argv[]) { if (thr>0) { cout << "threshold is " << thr << endl; - //#ifndef ANALOG +#ifndef ANALOG filter->setThreshold(thr); - //#endif +#endif + cf=0; } else cf=1; @@ -181,17 +196,13 @@ int main(int argc, char *argv[]) { filter->setROI(xmin,xmax,ymin,ymax); -#ifdef SOLEIL - filter->setROI(150,210,170,230); - nframes=-1; -#endif std::time(&end_time); cout << std::ctime(&end_time) << endl; char* buff; - multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); - + // multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); + multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize); #ifndef ANALOG mt->setDetectorMode(ePhotonCounting); cout << "Counting!" << endl; @@ -204,7 +215,7 @@ int main(int argc, char *argv[]) { mt->setDetectorMode(eAnalog); cout << "Analog!" << endl; cf=0; - // thr1=thr; + thr1=thr; #endif // } @@ -240,7 +251,7 @@ int main(int argc, char *argv[]) { mt->nextThread(); mt->popFree(buff); ifr++; - if (ifr%10000==0) + if (ifr%100==0) cout << ifr << " " << ff << " " << np << endl; } else cout << ifr << " " << ff << " " << np << endl; @@ -308,7 +319,7 @@ int main(int argc, char *argv[]) { // // // cout << " " << (void*)buff; mt->popFree(buff); ifr++; - if (ifr%1000==0) cout << ifr << " " << ff << endl; + if (ifr%100==0) cout << ifr << " " << ff << endl; if (nframes>0) { if (ifr%nframes==0) { //The name has an additional "_fXXXXX" at the end, where "XXXXX" is the initial frame number of the image (0,1000,2000...) @@ -334,9 +345,10 @@ int main(int argc, char *argv[]) { if (nframes>0) { sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile); sprintf(imgfname,ffname,irun); + } else { + sprintf(ffname,"%s/%s.tiff",outdir,fformat); + sprintf(imgfname,ffname,irun); } - sprintf(ffname,"%s/%s.tiff",outdir,fformat); - sprintf(imgfname,ffname,irun); cout << "Writing tiff to " << imgfname << " " << thr1 <writeImage(imgfname, thr1); mt->clearImage(); @@ -351,6 +363,13 @@ int main(int argc, char *argv[]) { } else cout << "Could not open "<< fname << " for reading " << endl; } + if (nframes<0){ + sprintf(ffname,"%s/%s.tiff",outdir,fformat); + strcpy(imgfname,ffname); + cout << "Writing tiff to " << imgfname << " " << thr1 <writeImage(imgfname, thr1); + } + return 0; diff --git a/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp b/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp index 3eb1a039f..587a136b6 100644 --- a/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp +++ b/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp @@ -3,13 +3,15 @@ #include "sls_detector_defs.h" #include "ZmqSocket.h" #include "moench03T1ZmqDataNew.h" +#include "moench03GhostSummation.h" +#include "moench03CommonMode.h" #include #include #include #include #include #include "tiffIO.h" -//#include + #include //json header in zmq stream #include @@ -110,12 +112,16 @@ int main(int argc, char *argv[]) { int dataSize=size; char dummybuff[size]; - - - + + int ncol_cm=20; + double xt_ghost=0.00045; + moench03CommonMode *cm=new moench03CommonMode(ncol_cm); + moench03GhostSummation *gs=new moench03GhostSummation(det, xt_ghost); + double *gainmap=NULL; + //analogDetector *filter=new analogDetector(det,1,NULL,1000); #ifndef INTERP - singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10); + singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, cm, 1000, 10, -1, -1, gainmap, gs); multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize); @@ -126,7 +132,7 @@ int main(int argc, char *argv[]) { if (etafname) interp->readFlatField(etafname); - interpolatingDetector *filter=new interpolatingDetector(det,interp, 5, 1, 0, 1000, 10); + interpolatingDetector *filter=new interpolatingDetector(det,interp, 5, 1, cm, 1000, 10, -1, -1, gainmap, gs); multiThreadedInterpolatingDetector *mt=new multiThreadedInterpolatingDetector(filter,nthreads,fifosize); #endif @@ -654,7 +660,12 @@ int main(int argc, char *argv[]) { // cout << "file" << endl; // cout << "data " << endl; if (of==NULL) { +#ifdef WRITE_QUAD + sprintf(ofname,"%s_%d.clust2",filename.c_str(),fileindex); +#endif +#ifndef WRITE_QUAD sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex); +#endif of=fopen(ofname,"w"); if (of) { mt->setFilePointer(of); diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 0ff15b03f..6ef4eee2f 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -58,7 +58,7 @@ public analogDetector { int sign=1, commonModeSubtraction *cm=NULL, int nped=1000, - int nd=100, int nnx=-1, int nny=-1, double *gm=NULL) : analogDetector(d, sign, cm, nped, nnx, nny, gm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), clusters(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0), eMin(-1), eMax(-1) { + int nd=100, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation *gs=NULL) : analogDetector(d, sign, cm, nped, nnx, nny, gm, gs), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), clusters(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0), eMin(-1), eMax(-1) { @@ -213,7 +213,7 @@ public analogDetector { return nph; } else { if (thr>0) { - newFrame(); + newFrame(data); if (cmSub) { cout << "add to common mode?"<< endl; addToCommonMode(data); @@ -362,7 +362,7 @@ int *getClusters(char *data, int *ph=NULL) { addToPedestal(data); return 0; } - newFrame(); + newFrame(data);