Compare commits

..

29 Commits

Author SHA1 Message Date
70048a9220 added photon counter no thread 2021-03-12 08:41:48 +01:00
f11cc4a7f3 Merge branch 'moench' of https://github.com/slsdetectorgroup/slsDetectorPackage into moench 2020-07-16 12:30:30 +02:00
f99c431722 changing zmq process to allow for partial readout and fixing interpolation 2020-07-16 12:27:40 +02:00
bce4a615fa some fixes from 4.2.0 that might be important formoench 2020-06-19 13:30:56 +02:00
8747ca04f3 zmq back in 2020-06-19 13:28:54 +02:00
2afa620a97 pedestal and data structures moved from 2D to 1D array; fixed bug with the file pointer in the zmq process 2020-06-16 13:52:36 +02:00
1d9341f031 Merge branch 'moench' of https://github.com/slsdetectorgroup/slsDetectorPackage into moench 2020-06-03 10:43:53 +02:00
ab3877d9dd function to write pedestal rms and some fixes 2020-06-03 10:43:16 +02:00
2a31e921ac memory leak when running single task 2020-04-20 13:42:33 +02:00
eac02479c5 rxr bug fix: master file not created, rxr does not return 2020-04-20 11:40:21 +02:00
8096d4078c Merge branch 'moench' of https://github.com/slsdetectorgroup/slsDetectorPackage into moench 2020-04-17 17:24:01 +02:00
5710dda12a fixed mistake in moench03 data stucture when calculating xmap, ymap 2020-04-17 17:23:24 +02:00
a510010b27 rxr bug fix: master file not created, rxr does not return 2020-04-16 16:08:34 +02:00
c55d19dbfe some corrections to cluster writing 2020-04-14 17:48:04 +02:00
163eb2710f Some fixes to the offline processing - could also affect hte zmq process 2020-04-06 09:42:38 +02:00
95351d0924 fixed bug by pedestal cloning 2020-03-24 12:05:10 +01:00
ded757b40c Merge branch 'moench' of https://github.com/slsdetectorgroup/slsDetectorPackage into moench 2020-03-19 11:29:05 +01:00
8b6eb0985f one of client warnings fixed 2020-03-19 11:28:16 +01:00
14b572cdd9 Merge branch 'moench' of https://github.com/slsdetectorgroup/slsDetectorPackage into moench 2020-03-19 11:16:10 +01:00
770ca7bb96 zmq fix sprintf serveraddress 2020-03-19 11:15:49 +01:00
d551bac3f7 fixed warnings to avoid crashing 2020-03-19 11:13:56 +01:00
d43d74a92d fixed warning for fname in zmqheader 2020-03-19 10:18:37 +01:00
e61d1a1651 zmqsocket bug fix: memcpy source and destination overlap 2020-02-25 10:28:23 +01:00
63f5b52a6e jctbDetectorServer compilation flags match only for moench 2020-02-19 12:26:35 +01:00
53ba22dbc4 fixed for current rectangular sensor geometry 2020-02-18 11:37:10 +01:00
124e2a7714 now rectangular interpolation possible 2020-02-18 11:36:31 +01:00
fcd4821b8d fixed compilation problem with rectangular pixels for zmq process 2020-02-18 11:23:54 +01:00
940c8f05cd interpolation without quads 2020-01-24 15:32:48 +01:00
e4ab4547db Interpolation in both directions for rect pixels works, saving of the rectangular image is done by rebinning 2020-01-15 17:27:46 +01:00
47 changed files with 2314 additions and 1587 deletions

5
cmk.sh
View File

@ -60,6 +60,7 @@ while getopts ":bchd:j:trge" opt ; do
b) b)
echo "Building of CMake files Required" echo "Building of CMake files Required"
REBUILD=1 REBUILD=1
CLEAN=1
;; ;;
c) c)
echo "Clean Required" echo "Clean Required"
@ -69,6 +70,7 @@ while getopts ":bchd:j:trge" opt ; do
echo "Building of CMake files with HDF5 option Required" echo "Building of CMake files with HDF5 option Required"
HDF5=1 HDF5=1
REBUILD=1 REBUILD=1
CLEAN=1
;; ;;
d) d)
echo "New HDF5 directory: $OPTARG" echo "New HDF5 directory: $OPTARG"
@ -82,16 +84,19 @@ while getopts ":bchd:j:trge" opt ; do
echo "Compiling Options: Text Client" echo "Compiling Options: Text Client"
TEXTCLIENT=1 TEXTCLIENT=1
REBUILD=1 REBUILD=1
CLEAN=1
;; ;;
r) r)
echo "Compiling Options: Receiver" echo "Compiling Options: Receiver"
RECEIVER=1 RECEIVER=1
REBUILD=1 REBUILD=1
CLEAN=1
;; ;;
g) g)
echo "Compiling Options: GUI" echo "Compiling Options: GUI"
GUI=1 GUI=1
REBUILD=1 REBUILD=1
CLEAN=1
;; ;;
e) e)
echo "Compiling Options: Debug" echo "Compiling Options: Debug"

View File

@ -1,4 +1,4 @@
hostname bchip020+ hostname bchip071+
patword 0000 0000000000000000 patword 0000 0000000000000000
patword 0001 0000000000000000 patword 0001 0000000000000000
@ -417,18 +417,23 @@ patwaittime2 0
####mcp2011 ####mcp2011
0:rx_tcpport 1954 0:rx_tcpport 1954
0:rx_udpip 10.1.1.102
0:detectorip 10.1.1.19
0:rx_udpport 32411 0:rx_udpport 32411
####gui listening to ####gui listening to
zmqip 129.129.202.106
zmqport 50001 zmqport 50001
####data streaming out of ####data streaming out of
rx_zmqip 10.1.2.103
rx_zmqport 50003 rx_zmqport 50003
0:rx_hostname mpc2011 #zmqip 129.129.202.86
#0:rx_udpip 10.1.2.117
#0:detectorip 10.1.2.19
#rx_zmqip 10.1.2.117
#0:rx_hostname mpc2608
zmqip 129.129.202.98
0:rx_udpip 10.1.1.102
0:detectorip 10.1.1.19
rx_zmqip 10.1.1.102
0:rx_hostname mpc2011
####pcmoench01 ####pcmoench01
#0:rx_tcpport 1977 #0:rx_tcpport 1977
@ -478,16 +483,17 @@ adcphase 90
adcpipeline 15 adcpipeline 15
adcreg 14 40 adcreg 14 40
powerchip 1 powerchip 1
vhighvoltage 90 vhighvoltage 200
period 0.005 period 0.005
r_discardpolicy discardpartial
frames 100 frames 100
period 0.1 period 0.1
outdir /scratch/ outdir /mnt/moench_data/scratch/
enablefwrite 0 enablefwrite 0

View File

@ -31,7 +31,7 @@ class MovingStat
*/ */
void Set(double val, double rms=0, int m=-1) void Set(double val, double rms=0, int m=-1)
{ {
if (m>0) m_n = m; else m_n = n; if (m>=0) m_n = m; else m_n = n;
m_newM=val*m_n; m_newM=val*m_n;
// cout << "set " << val << " " << m << " " << m_n << " " << m_newM << endl; // cout << "set " << val << " " << m << " " << m_n << " " << m_newM << endl;
SetRMS(rms); SetRMS(rms);

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));
} }
} }
@ -199,7 +196,7 @@ template <class dataType> class analogDetector {
\param nns reference to number of subpixels for interpolating detector, will always be 1 in this case \param nns reference to number of subpixels for interpolating detector, will always be 1 in this case
\returns number of pixels of the detector image \returns number of pixels of the detector image
*/ */
virtual int getImageSize(int &nnx, int &nny, int &nns){nnx=nx; nny=ny; nns=1; return nx*ny;}; virtual int getImageSize(int &nnx, int &nny, int &nnsx, int &nnsy){nnx=nx; nny=ny; nnsx=1; nnsy=1; return nx*ny;};
/** /**
Returns data size of the detector image matrix Returns data size of the detector image matrix
\param nnx reference to pixel size in x \param nnx reference to pixel size in x
@ -226,8 +223,11 @@ template <class dataType> class analogDetector {
\returns pointer to current gain map is file reading succeeded, NULL is file reading didn't work. \returns pointer to current gain map is file reading succeeded, NULL is file reading didn't work.
*/ */
double *readGainMap(const char * imgname) { double *readGainMap(const char * imgname) {
uint32 nnx, nny; uint32 unnx, unny;
float *gm=ReadFromTiff( imgname, nny, nnx); int nnx, nny;
float *gm=ReadFromTiff( imgname, unny, unnx);
nnx=unnx;
nny=unny;
if (gm) { if (gm) {
if (gmap) delete [] gmap; if (gmap) delete [] gmap;
gmap=new double[nnx*nny]; gmap=new double[nnx*nny];
@ -269,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();
@ -339,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); */
@ -402,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;
}; };
@ -423,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;
}; };
/** /**
@ -441,11 +441,12 @@ template <class dataType> class analogDetector {
\returns pedestal value \returns pedestal value
*/ */
virtual double* getPedestal(double *ped){ virtual double* getPedestal(double *ped){
if (ped==NULL) if (ped==NULL) {
ped=new double[nx*ny]; ped=new double[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++) {
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] << " " ;
} }
} }
@ -459,11 +460,12 @@ template <class dataType> class analogDetector {
\returns pedestal rms \returns pedestal rms
*/ */
virtual double* getPedestalRMS(double *ped=NULL){ virtual double* getPedestalRMS(double *ped=NULL){
if (ped==NULL) if (ped==NULL) {
ped=new double[nx*ny]; ped=new double[nx*ny];
for (int iy=0; iy<ny; iy++) { }
for (int ix=0; ix<nx; ix++) { for (int iy=0; iy<ny; iy++) {
ped[iy*nx+ix]=stat[iy][ix].getPedestalRMS(); for (int ix=0; ix<nx; ix++) {
ped[iy*nx+ix]=stat[iy*nx+ix].getPedestalRMS();
} }
} }
return ped; return ped;
@ -489,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
@ -504,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;
}; };
}; };
@ -521,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);};
@ -533,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]);
}; };
}; };
@ -623,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
@ -669,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;
@ -720,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);
@ -742,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;
@ -1018,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;
@ -1095,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
@ -1104,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;
}; };
@ -1232,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

@ -77,9 +77,9 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
int row, col; int row, col;
int isample; // int isample;
int iadc; int iadc;
int ix, iy; // int ix, iy;
int npackets=40; int npackets=40;
int i; int i;
@ -99,46 +99,46 @@ 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;
} }
} }
} }
} }
int ipacket; // int ipacket;
int ibyte; // int ibyte;
int ii=0; // int ii=0;
for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){ // for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){
xmap[ibyte]=-1; // xmap[ibyte]=-1;
ymap[ibyte]=-1; // ymap[ibyte]=-1;
} // }
int off=sizeof(sls_detector_header)/2; // int off=sizeof(sls_detector_header)/2;
for (ipacket=0; ipacket<npackets; ipacket++) { // for (ipacket=0; ipacket<npackets; ipacket++) {
for (ibyte=0; ibyte< 8192/2; ibyte++) { // for (ibyte=0; ibyte< 8192/2; ibyte++) {
i=ipacket*8208/2+ibyte; // i=ipacket*8208/2+ibyte;
isample=ii/nadc; // isample=ii/nadc;
if (isample<nSamples) { // if (isample<nSamples) {
iadc=ii%nadc; // iadc=ii%nadc;
adc4 = (int)iadc/4; // adc4 = (int)iadc/4;
ix=isample%sc_width; // ix=isample%sc_width;
iy=isample/sc_width; // iy=isample/sc_width;
if (adc4%2==0) { // if (adc4%2==0) {
xmap[i+off]=adc_nr[iadc]+ix; // xmap[i+off]=adc_nr[iadc]+ix;
ymap[i+off]=ny/2-1-iy; // ymap[i+off]=ny/2-1-iy;
} else { // } else {
xmap[i+off]=adc_nr[iadc]+ix; // xmap[i+off]=adc_nr[iadc]+ix;
ymap[i+off]=ny/2+iy; // ymap[i+off]=ny/2+iy;
} // }
} // }
ii++; // ii++;
// } // // }
} // }
} // }
iframe=0; iframe=0;
// cout << "data struct created" << endl; // cout << "data struct created" << endl;
@ -240,15 +240,15 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
char *retval=0; //char *retval=0;
int nd; // int nd;
int fnum = -1; //int fnum = -1;
np=0; // np=0;
int pn; // int pn;
// cout << dataSize << endl; // cout << dataSize << endl;
if (ff>=0) // if (ff>=0)
fnum=ff; // fnum=ff;
if (filebin.is_open()) { if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){ if (filebin.read(data, dataSize) ){

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;
} }
} }
} }
@ -74,8 +74,8 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
int ii=0; int ii=0;
for (i=0; i< dataSize; i++) { for (i=0; i< dataSize/2; i++) {
if (i<offset) { if (i<offset/2) {
//header! */ //header! */
xmap[i]=-1; xmap[i]=-1;
ymap[i]=-1; ymap[i]=-1;

View File

@ -46,7 +46,7 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
int row, col; int row, col;
int isample; // int isample;
int iadc; int iadc;
int ix, iy; int ix, iy;
@ -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,35 +37,25 @@ 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);
xmap=new int[dsize/sizeof(dataType)]; xmap=new int[el];
ymap=new int[dsize/sizeof(dataType)]; ymap=new int[el];
// 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<dsize/sizeof(dataType); ip++){
for (int ip=0; ip<el; ip++){
xmap[ip]=-1; xmap[ip]=-1;
ymap[ip]=-1; ymap[ip]=-1;
} }
@ -77,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;
@ -94,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 {
@ -109,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;
@ -119,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;
} }
@ -135,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;
} }
}; };
/** /**
@ -153,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;
} }
@ -178,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
@ -204,38 +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);
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<(dsize/sizeof(dataType)); 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++) { int el=dsize/sizeof(dataType);
data[i]=new double[nx];
}
if (dsize<=0 || dsize>dataSize) dsize=dataSize; if (dsize<=0 || dsize>dataSize) dsize=dataSize;
for (int ip=0; ip<(dsize/sizeof(dataType)); 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;
@ -251,12 +231,13 @@ 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; 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];
d=*((dataType*)(data+dataMap[iy][ix])); p=(dataType*)(data+dataMap[iy*nx+ix]);
d=*p;
} }
return d^m; return d^m;
}; };

View File

@ -13,7 +13,7 @@ template <class dataType> class ghostSummation {
/** constructor /** constructor
\param xt crosstalk \param xt crosstalk
*/ */
ghostSummation(slsDetectorData<dataType> *d, double xt) : xtalk(xt),det(d) { ghostSummation(slsDetectorData<dataType> *d, double xt) : xtalk(xt),det(d), nx(1), ny(1) {
if (det) if (det)
det->getDetectorSize(nx,ny); det->getDetectorSize(nx,ny);
ghost=new double[nx*ny]; ghost=new double[nx*ny];
@ -22,6 +22,9 @@ template <class dataType> class ghostSummation {
ghostSummation(ghostSummation *orig) { ghostSummation(ghostSummation *orig) {
xtalk=orig->xtalk; xtalk=orig->xtalk;
det=orig->det; det=orig->det;
nx=1;
ny=1;
det->getDetectorSize(nx,ny);
ghost=new double[nx*ny]; ghost=new double[nx*ny];
} }

View File

@ -50,7 +50,12 @@ class interpolatingDetector : public singlePhotonDetector {
singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny, gm, gs) , interp(inte), id(0) { singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny, gm, gs) , interp(inte), id(0) {
//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");
}
}; };
@ -107,11 +112,11 @@ class interpolatingDetector : public singlePhotonDetector {
singlePhotonDetector::clearImage(); singlePhotonDetector::clearImage();
}; };
int getImageSize(int &nnx, int &nny, int &ns) { int getImageSize(int &nnx, int &nny, int &nsx, int &nsy) {
if (interp) if (interp)
return interp->getImageSize(nnx, nny, ns); return interp->getImageSize(nnx, nny, nsx, nsy);
else else
return analogDetector<uint16_t>::getImageSize(nnx, nny, ns); return analogDetector<uint16_t>::getImageSize(nnx, nny, nsx, nsy);
}; };
@ -251,6 +256,7 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
} }
virtual int getNSubPixels(){ if (interp) return interp->getNSubPixels(); else return 1;} virtual int getNSubPixels(){ if (interp) return interp->getNSubPixels(); else return 1;}
virtual int setNSubPixels(int ns) { virtual int setNSubPixels(int ns) {
if (interp) { if (interp) {
pthread_mutex_lock(fi); pthread_mutex_lock(fi);

View File

@ -0,0 +1,406 @@
#ifndef ETA2_INTERPOLATION_BASE_H
#define ETA2_INTERPOLATION_BASE_H
#ifdef MYROOT1
#include <TObject.h>
#include <TTree.h>
#include <TH2D.h>
#include <TH2F.h>
#endif
#include "etaInterpolationBase.h"
class eta2InterpolationBase : public virtual etaInterpolationBase {
public:
eta2InterpolationBase(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax) {
/* if (etamin>=etamax) { */
/* etamin=-1; */
/* etamax=2; */
/* // cout << ":" <<endl; */
/* } */
/* etastep=(etamax-etamin)/nbeta; */
};
eta2InterpolationBase(eta2InterpolationBase *orig): etaInterpolationBase(orig){ };
//////////////////////////////////////////////////////////////////////////////
//////////// /*It return position hit for the event in input */ //////////////
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixelsX>2 || nSubPixelsY>2)
calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixelsX>2 || nSubPixelsY>2 )
calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y) {
double cc[2][2];
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
double etax=0, etay=0;
if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(yoff+1)];
calcEta(totquad,cc,etax,etay);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double cc[2][2];
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
double etax=0, etay=0;
if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(xoff+1)];
calcEta(totquad,cc,etax,etay);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
{
double xpos_eta=0,ypos_eta=0;
double dX,dY;
int ex,ey;
switch (corner)
{
case TOP_LEFT:
dX=-1.;
dY=0;
break;
case TOP_RIGHT:
;
dX=0;
dY=0;
break;
case BOTTOM_LEFT:
dX=-1.;
dY=-1.;
break;
case BOTTOM_RIGHT:
dX=0;
dY=-1.;
break;
default:
cout << "bad quadrant" << endl;
dX=0.;
dY=0.;
}
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
cout << "x*"<< ex << endl;
ex=0;
}
if (ex>=nbetaX) {
cout << "x?"<< ex << endl;
ex=nbetaX-1;
}
if (ey<0) {
cout << "y*"<< ey << " " << nbetaY << endl;
ey=0;
}
if (ey>=nbetaY) {
cout << "y?"<< ey << " " << nbetaY << endl;
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]))+dX ;///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]))+dY ;///((double)nSubPixels);
} else {
xpos_eta=0.5*dX+0.25;
ypos_eta=0.5*dY+0.25;
}
int_x=((double)x) + xpos_eta+0.5;
int_y=((double)y) + ypos_eta+0.5;
}
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
double cc[2][2];
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(yoff+1)];
//calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc,etax, etay);
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax,etay);
}
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
double cc[2][2];
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[(yoff+1)*3+xoff];
cc[0][1]=cl[yoff*3+xoff+1];
cc[1][1]=cl[(yoff+1)*3+xoff+1];
/* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; */
/* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; */
/* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; */
/* cout <<"******"<<totquad << " " << quad << endl; */
/* cout << cc[0][0]<< " " << cc[0][1] << endl; */
/* cout << cc[1][0]<< " " << cc[1][1] << endl; */
//calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc,etax, etay);
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax,etay);
}
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
// int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
//double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
//int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
// double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(double etax, double etay){
#ifdef MYROOT1
heta->Fill(etax,etay);
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
virtual int *getInterpolatedImage(){
int ipx, ipy;
// cout << "ff" << endl;
calcDiff(1, hhx, hhy); //get flat
double avg=0;
for (ipx=0; ipx<nSubPixelsX; ipx++)
for (ipy=0; ipy<nSubPixelsY; ipy++)
avg+=flat[ipx+ipy*nSubPixelsX];
avg/=nSubPixelsY*nSubPixelsX;
for (int ibx=0 ; ibx<nSubPixelsX*nPixelsX; ibx++) {
ipx=ibx%nSubPixelsX-nSubPixelsX/2;
if (ipx<0) ipx=nSubPixelsX+ipx;
for (int iby=0 ; iby<nSubPixelsY*nPixelsY; iby++) {
ipy=iby%nSubPixelsY-nSubPixelsY/2;
if (ipy<0) ipy=nSubPixelsY+ipy;
// cout << ipx << " " << ipy << " " << ibx << " " << iby << endl;
if (flat[ipx+ipy*nSubPixelsX]>0)
hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX]*(avg/flat[ipx+ipy*nSubPixelsX]);
else
hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX];
}
}
return hintcorr;
};
/* protected: */
/* #ifdef MYROOT1 */
/* TH2D *heta; */
/* TH2D *hhx; */
/* TH2D *hhy; */
/* #endif */
/* #ifndef MYROOT1 */
/* int *heta; */
/* float *hhx; */
/* float *hhy; */
/* #endif */
/* int nbeta; */
/* double etamin, etamax, etastep; */
};
#endif

View File

@ -0,0 +1,271 @@
#ifndef ETA3_INTERPOLATION_BASE_H
#define ETA3_INTERPOLATION_BASE_H
#ifdef MYROOT1
#include <TObject.h>
#include <TTree.h>
#include <TH2D.h>
#include <TH2F.h>
#endif
#include "etaInterpolationBase.h"
class eta3InterpolationBase : public virtual etaInterpolationBase {
public:
eta3InterpolationBase(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx, ny, ns, nsy, nb, nby, emin, emax) {
// cout << "e3ib " << nb << " " << emin << " " << emax << endl;
/* if (nbeta<=0) { */
/* nbeta=nSubPixels*10; */
/* } */
// cout << nbeta << " " << etamin << " " << etamax << endl;
};
eta3InterpolationBase(eta3InterpolationBase *orig): etaInterpolationBase(orig){ };
/* virtual eta3InterpolationBase* Clone()=0; */
// virtual void prepareInterpolation(int &ok){};
//////////////////////////////////////////////////////////////////////////////
//////////// /*It return position hit for the event in input */ //////////////
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, tot);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
{
//double sDum[2][2];
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, tot);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y) {
double etax, etay;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double etax, etay;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
{
double xpos_eta=0,ypos_eta=0;
int ex,ey;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
#ifdef MYROOT1
xpos_eta=(hhx->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixelsX);
ypos_eta=(hhy->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixelsY);
#endif
#ifndef MYROOT1
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x*"<< ex << endl; */
ex=0;
}
if (ex>=nbetaX) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x?"<< ex << endl; */
ex=nbetaX-1;
}
if (ey<0) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y*"<< ey << endl; */
ey=0;
}
if (ey>=nbetaY) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y?"<< ey << endl; */
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]));///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]));///((double)nSubPixels);
#endif
} else {
switch (corner) {
case BOTTOM_LEFT:
xpos_eta=-0.25;
ypos_eta=-0.25;
break;
case BOTTOM_RIGHT:
xpos_eta=0.25;
ypos_eta=-0.25;
break;
case TOP_LEFT:
xpos_eta=-0.25;
ypos_eta=0.25;
break;
case TOP_RIGHT:
xpos_eta=0.25;
ypos_eta=0.25;
break;
default:
xpos_eta=0;
ypos_eta=0;
}
}
int_x=((double)x) + xpos_eta;
int_y=((double)y) + ypos_eta;
// int_x=5. + xpos_eta;
// int_y=5. + ypos_eta;
}
/* ///////////////////////////////////////////////////////////////////////////////////////////////// */
/* virtual void getPositionETA3(int x, int y, double *data, double &int_x, double &int_y) */
/* { */
/* double sDum[2][2]; */
/* double tot, totquad; */
/* double eta3x,eta3y; */
/* double ex,ey; */
/* calcQuad(data, tot, totquad, sDum); */
/* calcEta3(data,eta3x, eta3y,tot); */
/* double xpos_eta,ypos_eta; */
/* #ifdef MYROOT1 */
/* xpos_eta=((hhx->GetBinContent(hhx->GetXaxis()->FindBin(eta3x),hhy->GetYaxis()->FindBin(eta3y))))/((double)nSubPixels); */
/* ypos_eta=((hhy->GetBinContent(hhx->GetXaxis()->FindBin(eta3x),hhy->GetYaxis()->FindBin(eta3y))))/((double)nSubPixels); */
/* #endif */
/* #ifndef MYROOT1 */
/* ex=(eta3x-etamin)/etastep; */
/* ey=(eta3y-etamin)/etastep; */
/* if (ex<0) ex=0; */
/* if (ex>=nbeta) ex=nbeta-1; */
/* if (ey<0) ey=0; */
/* if (ey>=nbeta) ey=nbeta-1; */
/* xpos_eta=(((double)hhx[(int)(ey*nbeta+ex)]))/((double)nSubPixels); */
/* ypos_eta=(((double)hhy[(int)(ey*nbeta+ex)]))/((double)nSubPixels); */
/* #endif */
/* int_x=((double)x) + xpos_eta; */
/* int_y=((double)y) + ypos_eta; */
/* return; */
/* }; */
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax,etay);
}
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax,etay);
}
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(double etax, double etay){
#ifdef MYROOT1
heta->Fill(etax,etay);
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
/* protected: */
/* #ifdef MYROOT1 */
/* TH2D *heta; */
/* TH2D *hhx; */
/* TH2D *hhy; */
/* #endif */
/* #ifndef MYROOT1 */
/* int *heta; */
/* float *hhx; */
/* float *hhy; */
/* #endif */
/* int nbeta; */
/* double etamin, etamax, etastep; */
};
#endif

View File

@ -12,19 +12,6 @@
#include "tiffIO.h" #include "tiffIO.h"
class etaInterpolationBase : public slsInterpolation { class etaInterpolationBase : public slsInterpolation {
protected:
float *hhx;
float *hhy;
int *heta;
int nbetaX, nbetaY;
double etamin, etamax, etastepX, etastepY;
double rangeMin, rangeMax;
double *flat;
int *hintcorr;
public: public:
@ -203,10 +190,19 @@ float *gethhx()
// hhy->Scale((double)nSubPixels); // hhy->Scale((double)nSubPixels);
return hhy; return hhy;
}; };
virtual int addToFlatField(double etax, double etay){
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
return 0;
};
// virtual void prepareInterpolation(int &ok)=0;
void debugSaveAll(int ind=0) { void debugSaveAll(int ind=0) {
int ibx, iby; int ibx, iby;
char tit[10000]; char tit[10000];
@ -227,15 +223,15 @@ float *gethhx()
for (int ii=0; ii<nbetaX*nbetaY; ii++) { for (int ii=0; ii<nbetaX*nbetaY; ii++) {
//ibb=hhx[ii];//*nSubPixelsX); ibb=(hhx[ii]*nSubPixelsX);
etah[ii]=hhx[ii]; etah[ii]=ibb;
} }
sprintf(tit,"/scratch/eta_hhx_%d.tiff",ind); sprintf(tit,"/scratch/eta_hhx_%d.tiff",ind);
WriteToTiff(etah, tit, nbetaX, nbetaY); WriteToTiff(etah, tit, nbetaX, nbetaY);
for (int ii=0; ii<nbetaX*nbetaY; ii++) { for (int ii=0; ii<nbetaX*nbetaY; ii++) {
//ibb=hhy[ii];//*nSubPixelsY; ibb=hhy[ii]*nSubPixelsY;
etah[ii]=hhy[ii]; etah[ii]=ibb;
} }
sprintf(tit,"/scratch/eta_hhy_%d.tiff",ind); sprintf(tit,"/scratch/eta_hhy_%d.tiff",ind);
WriteToTiff(etah, tit, nbetaX, nbetaY); WriteToTiff(etah, tit, nbetaX, nbetaY);
@ -295,37 +291,6 @@ float *gethhx()
} }
virtual int *getInterpolatedImage(){
/* int ipx, ipy; */
/* // cout << "ff" << endl; */
/* calcDiff(1, hhx, hhy); //get flat */
/* double avg=0; */
/* for (ipx=0; ipx<nSubPixelsX; ipx++) */
/* for (ipy=0; ipy<nSubPixelsY; ipy++) */
/* avg+=flat[ipx+ipy*nSubPixelsX]; */
/* avg/=nSubPixelsY*nSubPixelsX; */
/* for (int ibx=0 ; ibx<nSubPixelsX*nPixelsX; ibx++) { */
/* ipx=ibx%nSubPixelsX-nSubPixelsX/2; */
/* if (ipx<0) ipx=nSubPixelsX+ipx; */
/* for (int iby=0 ; iby<nSubPixelsY*nPixelsY; iby++) { */
/* ipy=iby%nSubPixelsY-nSubPixelsY/2; */
/* if (ipy<0) ipy=nSubPixelsY+ipy; */
/* // cout << ipx << " " << ipy << " " << ibx << " " << iby << endl; */
/* if (flat[ipx+ipy*nSubPixelsX]>0) */
/* hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX]*(avg/flat[ipx+ipy*nSubPixelsX]); */
/* else */
/* hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX]; */
/* } */
/* } */
return hint;
/* return hintcorr; */
};
protected: protected:
@ -398,575 +363,19 @@ float *gethhx()
return sqrt(diff); return sqrt(diff);
} }
float *hhx;
float *hhy;
int *heta;
int nbetaX, nbetaY;
double etamin, etamax, etastepX, etastepY;
double rangeMin, rangeMax;
double *flat;
int *hintcorr;
}; };
class eta2InterpolationBase : public virtual etaInterpolationBase {
public:
eta2InterpolationBase(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax) {
};
eta2InterpolationBase(eta2InterpolationBase *orig): etaInterpolationBase(orig){ };
//////////////////////////////////////////////////////////////////////////////
//////////// /*It return position hit for the event in input */ //////////////
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixelsX>2 || nSubPixelsY>2)
calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixelsX>2 || nSubPixelsY>2 )
calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y) {
double cc[2][2];
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
double etax=0, etay=0;
if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(yoff+1)];
calcEta(totquad,cc,etax,etay);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double cc[2][2];
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
double etax=0, etay=0;
if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(xoff+1)];
calcEta(totquad,cc,etax,etay);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
{
double xpos_eta=0,ypos_eta=0;
double dX,dY;
int ex,ey;
switch (corner)
{
case TOP_LEFT:
dX=-1.;
dY=0;
break;
case TOP_RIGHT:
;
dX=0;
dY=0;
break;
case BOTTOM_LEFT:
dX=-1.;
dY=-1.;
break;
case BOTTOM_RIGHT:
dX=0;
dY=-1.;
break;
default:
cout << "bad quadrant" << endl;
dX=0.;
dY=0.;
}
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
cout << "x*"<< ex << endl;
ex=0;
}
if (ex>=nbetaX) {
cout << "x?"<< ex << endl;
ex=nbetaX-1;
}
if (ey<0) {
cout << "y*"<< ey << " " << nbetaY << endl;
ey=0;
}
if (ey>=nbetaY) {
cout << "y?"<< ey << " " << nbetaY << endl;
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]));
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]));
if (xpos_eta<0 || xpos_eta>1)
xpos_eta=-100;
else
xpos_eta+=dX ;///((double)nSubPixels);
if (ypos_eta<0 || ypos_eta>1)
ypos_eta=-100;
else
ypos_eta+=dY ;///((double)nSubPixels);
} else {
xpos_eta=0.5*dX+0.25;
ypos_eta=0.5*dY+0.25;
}
if (xpos_eta<-1)
int_x=-100;
else
int_x=((double)x) + xpos_eta+0.5;
if (ypos_eta<-1)
int_y=-100;
else
int_y=((double)y) + ypos_eta+0.5;
}
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
double cc[2][2];
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(yoff+1)];
//calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc,etax, etay);
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax,etay);
}
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
double cc[2][2];
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[(yoff+1)*3+xoff];
cc[0][1]=cl[yoff*3+xoff+1];
cc[1][1]=cl[(yoff+1)*3+xoff+1];
/* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; */
/* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; */
/* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; */
/* cout <<"******"<<totquad << " " << quad << endl; */
/* cout << cc[0][0]<< " " << cc[0][1] << endl; */
/* cout << cc[1][0]<< " " << cc[1][1] << endl; */
//calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc,etax, etay);
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax,etay);
}
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
// int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
//double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
//int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
// double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(double etax, double etay){
#ifdef MYROOT1
heta->Fill(etax,etay);
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
};
class eta3InterpolationBase : public virtual etaInterpolationBase {
public:
eta3InterpolationBase(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx, ny, ns, nsy, nb, nby, emin, emax) {
cout << "e3ib " << nb << " " << emin << " " << emax << endl;
};
eta3InterpolationBase(eta3InterpolationBase *orig): etaInterpolationBase(orig){ };
//////////////////////////////////////////////////////////////////////////////
//////////// /*It return position hit for the event in input */ //////////////
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, tot);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
{
//double sDum[2][2];
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, tot);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y) {
double etax, etay;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double etax, etay;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
{
//cout << "**";
double xpos_eta=0,ypos_eta=0;
int ex,ey;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
#ifdef MYROOT1
xpos_eta=(hhx->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixelsX);
ypos_eta=(hhy->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixelsY);
#endif
#ifndef MYROOT1
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x*"<< ex << endl; */
ex=0;
}
if (ex>=nbetaX) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x?"<< ex << endl; */
ex=nbetaX-1;
}
if (ey<0) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y*"<< ey << endl; */
ey=0;
}
if (ey>=nbetaY) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y?"<< ey << endl; */
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]));///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]));///((double)nSubPixels);
#endif
} else {
switch (corner) {
case BOTTOM_LEFT:
xpos_eta=-0.25;
ypos_eta=-0.25;
break;
case BOTTOM_RIGHT:
xpos_eta=0.25;
ypos_eta=-0.25;
break;
case TOP_LEFT:
xpos_eta=-0.25;
ypos_eta=0.25;
break;
case TOP_RIGHT:
xpos_eta=0.25;
ypos_eta=0.25;
break;
default:
xpos_eta=0;
ypos_eta=0;
}
}
/* if (xpos_eta<0 || xpos_eta>1) */
/* int_x=-1; */
/* else */
int_x=((double)x) + xpos_eta;
/* if (ypos_eta<0 || ypos_eta>1) */
/* int_y=-1; */
/* else */
int_y=((double)y) + ypos_eta;
// int_x=5. + xpos_eta;
// int_y=5. + ypos_eta;
}
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax,etay);
}
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax,etay);
}
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(double etax, double etay){
#ifdef MYROOT1
heta->Fill(etax,etay);
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
};
#endif #endif

View File

@ -4,12 +4,12 @@
#include "etaInterpolationBase.h" #include "etaInterpolationBase.h"
class etaInterpolationGlobal : public virtual etaInterpolationBase { class etaInterpolationGlobal : public etaInterpolationBase{
public: public:
etaInterpolationGlobal(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny,ns,nsy, nb, nby,emin,emax){}; globalEtaInterpolation(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny,ns, nb, emin,emax){};
virtual void prepareInterpolation(int &ok) virtual void prepareInterpolation(int &ok)
{ {
ok=1; ok=1;
@ -24,106 +24,62 @@ class etaInterpolationGlobal : public virtual etaInterpolationBase {
///*Eta Distribution Rebinning*/// ///*Eta Distribution Rebinning*///
// double bsizeX=1./nSubPixelsX; //precision double bsize=1./nSubPixels; //precision
// cout<<"nPixelsX = "<<nPixelsX<<" nPixelsY = "<<nPixelsY<<" nSubPixels = "<<nSubPixels<<endl; // cout<<"nPixelsX = "<<nPixelsX<<" nPixelsY = "<<nPixelsY<<" nSubPixels = "<<nSubPixels<<endl;
double tot_eta=0; double tot_eta=0;
for (int ip=0; ip<nbetaX*nbetaY; ip++) for (int ip=0; ip<nbeta*nbeta; ip++)
tot_eta+=heta[ip]; tot_eta+=heta[ip];
cout << "total eta entries is :"<< tot_eta << endl; cout << "total eta entries is :"<< tot_eta << endl;
if (tot_eta<=0) {ok=0; return;}; if (tot_eta<=0) {ok=0; return;};
double hx[nbetaX]; //projection x double hx[nbeta]; //projection x
double hy[nbetaY]; //projection y double hy[nbeta]; //projection y
for (int ibx=0; ibx<nbetaX; ibx++) { hx[ibx]=0;} for (int ibx=0; ibx<nbeta; ibx++) {
for (int iby=0; iby<nbeta; iby++) {
for (int iby=0; iby<nbetaY; iby++) { hy[iby]=0;} hx[ibx]=hx[ibx]+heta[ibx+iby*nbeta];
hy[iby]=hx[iby]+heta[ibx+iby*nbeta];
for (int ibx=0; ibx<nbetaX; ibx++) {
for (int iby=0; iby<nbetaY; iby++) {
hx[ibx]=hx[ibx]+heta[ibx+iby*nbetaX];
hy[iby]=hy[iby]+heta[ibx+iby*nbetaX];
} }
} }
double hix[nbetaX]; //integral of projection x double hix[nbeta]; //integral of projection x
double hiy[nbetaY]; //integral of projection y double hiy[nbeta]; //integral of projection y
hix[0]=hx[0]; hix[0]=hx[0];
hiy[0]=hy[0]; hiy[0]=hy[0];
for (int ib=1; ib<nbetaX; ib++) { for (int ib=1; ib<nbeta; ib++) {
hix[ib]=hix[ib-1]+hx[ib]; hix[ib]=hix[ib-1]+hx[ib];
hiy[ib]=hiy[ib-1]+hx[ib];
} }
for (int ib=1; ib<nbetaY; ib++) {
hiy[ib]=hiy[ib-1]+hy[ib];
}
double tot_x=hix[nbetaX-1]+1;
double tot_y=hiy[nbetaY-1]+1;
int ib=0; int ib=0;
for (int ibx=0; ibx<nbeta; ibx++) {
for (int ibx=0; ibx<nbetaX; ibx++) { if (hix[ibx]>(ib+1)*tot_eta*bsize) ib++;
// if (hix[ibx]>(ib+1)*tot_eta*bsize) ib++; for (int iby=0; iby<nbeta; iby++) {
for (int iby=0; iby<nbetaY; iby++) { #ifdef MYROOT1
hhx->SetBinContent(ibx+1,iby+1,ib);
if (tot_x>0) #endif
hhx[ibx+iby*nbetaX]=hix[ibx]/tot_x; #ifndef MYROOT1
else hhx[ibx+iby*nbeta]=ib;
hhx[ibx+iby*nbetaX]=-1; #endif
}
if (tot_y>0) }
hhy[ibx+iby*nbetaX]=hiy[iby]/tot_y; ib=0;
else for (int iby=0; iby<nbeta; iby++) {
hhy[ibx+iby*nbetaX]=-1; if (hiy[iby]>(ib+1)*tot_eta*bsize) ib++;
for (int ibx=0; ibx<nbeta; ibx++) {
#ifdef MYROOT1
hhy->SetBinContent(ibx+1,iby+1,ib);
#endif
#ifndef MYROOT1
hhy[ibx+iby*nbeta]=ib;
#endif
} }
} }
/* ib=0; */
/* for (int iby=0; iby<nbeta; iby++) { */
/* if (hiy[iby]>(ib+1)*tot_eta*bsize) ib++; */
/* for (int ibx=0; ibx<nbeta; ibx++) { */
/* #ifdef MYROOT1 */
/* hhy->SetBinContent(ibx+1,iby+1,ib); */
/* #endif */
/* #ifndef MYROOT1 */
/* hhy[ibx+iby*nbeta]=ib; */
/* #endif */
/* } */
/* } */
return ; return ;
}; };
etaInterpolationGlobal(etaInterpolationGlobal *orig): etaInterpolationBase(orig) {};
}; };
//etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),
class eta2InterpolationGlobal : public virtual eta2InterpolationBase, public virtual etaInterpolationGlobal {
public:
eta2InterpolationGlobal(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : eta2InterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax), etaInterpolationGlobal(nx,ny, ns, nsy, nb, nby, emin, emax){
cout << "e2pxy " << nbetaX << " " << nbetaY << etamin << " " << etamax << " " << nSubPixelsX<< " " << nSubPixelsY << endl;
};
eta2InterpolationGlobal(eta2InterpolationGlobal *orig): etaInterpolationBase(orig), etaInterpolationGlobal(orig) {};
virtual eta2InterpolationGlobal* Clone() { return new eta2InterpolationGlobal(this);};
};
//etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),
class eta3InterpolationGlobal : public virtual eta3InterpolationBase, public virtual etaInterpolationGlobal {
public:
eta3InterpolationGlobal(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : eta3InterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax), etaInterpolationGlobal(nx,ny, ns, nsy, nb, nby, emin, emax){
cout << "e3pxy " << nbetaX << " " << nbetaY << etamin << " " << etamax << " " << nSubPixelsX<< " " << nSubPixelsY << endl;
};
eta3InterpolationGlobal(eta3InterpolationGlobal *orig): etaInterpolationBase(orig), etaInterpolationGlobal(orig) {};
virtual eta3InterpolationGlobal* Clone() {return new eta3InterpolationGlobal(this);};
};
#endif #endif

View File

@ -4,6 +4,8 @@
//#include "tiffIO.h" //#include "tiffIO.h"
#include "etaInterpolationBase.h" #include "etaInterpolationBase.h"
#include "eta2InterpolationBase.h"
#include "eta3InterpolationBase.h"
class etaInterpolationPosXY : public virtual etaInterpolationBase{ class etaInterpolationPosXY : public virtual etaInterpolationBase{
public: public:
@ -42,8 +44,9 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
double hiy[nbetaY]; //integral of projection y double hiy[nbetaY]; //integral of projection y
// int ii=0; // int ii=0;
double etax, etay; double etax, etay;
for (int ib=0; ib<nbetaX; ib++) { for (int ib=0; ib<nbetaX; ib++) {
//tot_eta_y=0; //tot_eta_y=0;
for (int iby=0; iby<nbetaY; iby++) { for (int iby=0; iby<nbetaY; iby++) {
@ -51,10 +54,10 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
//cout << etax << endl; //cout << etax << endl;
// tot_eta_x+=hx[iby]; // tot_eta_x+=hx[iby];
// if (etay>=0 && etay<=1) if (etay>=0 && etay<=1)
hy[iby]=heta[ib+iby*nbetaX]; hy[iby]=heta[ib+iby*nbetaX];
// else else
// hy[iby]=0; hy[iby]=0;
// tot_eta_y+=hy[iby]; // tot_eta_y+=hy[iby];
} }
@ -68,7 +71,7 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
tot_eta_y=hiy[nbetaY-1]+1; tot_eta_y=hiy[nbetaY-1]+1;
for (int iby=0; iby<nbetaY; iby++) { for (int iby=0; iby<nbetaY; iby++) {
if (tot_eta_y<=1) { if (tot_eta_y<=0) {
hhy[ib+iby*nbetaX]=-1; hhy[ib+iby*nbetaX]=-1;
//ii=(ibx*nSubPixels)/nbeta; //ii=(ibx*nSubPixels)/nbeta;
} else { } else {
@ -77,7 +80,7 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
} }
} }
} }
cout << "hhy filled " << endl;
for (int ib=0; ib<nbetaY; ib++) { for (int ib=0; ib<nbetaY; ib++) {
@ -85,11 +88,11 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
for (int ibx=0; ibx<nbetaX; ibx++) { for (int ibx=0; ibx<nbetaX; ibx++) {
etax=etamin+ibx*etastepX; etax=etamin+ibx*etastepX;
//cout << etax << endl; //cout << etax << endl;
// if (etax>=0 && etax<=1) if (etax>=0 && etax<=1)
hx[ibx]=heta[ibx+ib*nbetaX]; hx[ibx]=heta[ibx+ib*nbetaX];
// else { else {
// hx[ibx]=0; hx[ibx]=0;
// } }
} }
hix[0]=hx[0]; hix[0]=hx[0];
@ -101,7 +104,7 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
tot_eta_x=hix[nbetaX-1]+1; tot_eta_x=hix[nbetaX-1]+1;
for (int ibx=0; ibx<nbetaX; ibx++) { for (int ibx=0; ibx<nbetaX; ibx++) {
if (tot_eta_x<=1) { if (tot_eta_x<=0) {
hhx[ibx+ib*nbetaX]=-1; hhx[ibx+ib*nbetaX]=-1;
} }
else { else {
@ -119,49 +122,40 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
hhx[ibx+ib*nbetaX]=hix[ibx]/tot_eta_x; hhx[ibx+ib*nbetaX]=hix[ibx]/tot_eta_x;
} }
} }
}
}
/* cout << "hhx filled " << endl; */ int ibx, iby, ib;
/* int ibx, iby, ib; */
/* iby=0; */ iby=0;
/* while (hhx[iby*nbetaY+nbetaY/2]<0 && iby<nbetaY/2) iby++; */ while (hhx[iby*nbetaY+nbetaY/2]<0) iby++;
/* for (ib=0; ib<iby;ib++) { */ for (ib=0; ib<iby;ib++) {
/* for (ibx=0; ibx<nbetaX;ibx++) */ for (ibx=0; ibx<nbetaX;ibx++)
/* hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby]; */ hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby];
/* } */ }
iby=nbetaY-1;
/* cout << "hhx low optimized" << endl; */ while (hhx[iby*nbetaY+nbetaY/2]<0) iby--;
for (ib=iby+1; ib<nbetaY;ib++) {
/* iby=nbetaY-1; */ for (ibx=0; ibx<nbetaX;ibx++)
/* while (hhx[iby*nbetaY+nbetaY/2]<0 && iby>0) iby--; */ hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby];
}
/* for (ib=iby+1; ib<nbetaY;ib++) { */ iby=0;
/* for (ibx=0; ibx<nbetaX;ibx++){ */ while (hhy[nbetaX/2*nbetaX+iby]<0) iby++;
/* cout << iby << " " << ib << " " << ibx << " " << ibx+nbetaX*ib << " " << ibx+nbetaX*iby << " " << nbetaX*nbetaY << endl; */ for (ib=0; ib<iby;ib++) {
/* hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby]; */ for (ibx=0; ibx<nbetaY;ibx++)
/* } */ hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx];
/* } */ }
iby=nbetaX-1;
/* cout << "hhx high optimized" << endl; */ while (hhy[nbetaX/2*nbetaX+iby]<0) iby--;
for (ib=iby+1; ib<nbetaX;ib++) {
for (ibx=0; ibx<nbetaY;ibx++)
hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx];
}
/* iby=0; */
/* while (hhy[nbetaX/2*nbetaX+iby]<0 && iby<nbetaX) iby++; */
/* for (ib=0; ib<iby;ib++) { */
/* for (ibx=0; ibx<nbetaY;ibx++) */
/* hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx]; */
/* } */
/* cout << "hhy low optimized" << endl; */
/* iby=nbetaX-1; */
/* while (hhy[nbetaX/2*nbetaX+iby]<0 && iby>) iby--; */
/* for (ib=iby+1; ib<nbetaX;ib++) { */
/* for (ibx=0; ibx<nbetaY;ibx++) */
/* hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx]; */
/* } */
/* cout << "hhy high optimized" << endl; */
@ -186,7 +180,7 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
class eta2InterpolationPosXY : public virtual eta2InterpolationBase, public virtual etaInterpolationPosXY { class eta2InterpolationPosXY : public virtual eta2InterpolationBase, public virtual etaInterpolationPosXY {
public: public:
eta2InterpolationPosXY(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),eta2InterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),etaInterpolationPosXY(nx,ny, ns, nsy, nb, nby, emin, emax){ eta2InterpolationPosXY(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),eta2InterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),etaInterpolationPosXY(nx,ny, ns, nsy, nb, nby, emin, emax){
cout << "e2pxy " << nbetaX << " " << nbetaY << etamin << " " << etamax << " " << nSubPixelsX<< " " << nSubPixelsY << endl; // cout << "e2pxy " << nb << " " << emin << " " << emax << endl;
}; };
eta2InterpolationPosXY(eta2InterpolationPosXY *orig): etaInterpolationBase(orig), etaInterpolationPosXY(orig) {}; eta2InterpolationPosXY(eta2InterpolationPosXY *orig): etaInterpolationBase(orig), etaInterpolationPosXY(orig) {};
@ -195,12 +189,12 @@ class eta2InterpolationPosXY : public virtual eta2InterpolationBase, public virt
}; };
//
class eta3InterpolationPosXY : public virtual eta3InterpolationBase, public virtual etaInterpolationPosXY { class eta3InterpolationPosXY : public virtual eta3InterpolationBase, public virtual etaInterpolationPosXY {
public: public:
eta3InterpolationPosXY(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax), eta3InterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax), etaInterpolationPosXY(nx,ny, ns, nsy, nb, nby, emin, emax){ eta3InterpolationPosXY(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),eta3InterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax), etaInterpolationPosXY(nx,ny, ns, nsy, nb, nby, emin, emax){
cout << "e3pxy " << nbetaX << " " << nbetaY << etamin << " " << etamax << " " << nSubPixelsX<< " " << nSubPixelsY << endl; // cout << "e3pxy " << nbeta << " " << etamin << " " << etamax << " " << nSubPixels<< endl;
}; };
eta3InterpolationPosXY(eta3InterpolationPosXY *orig): etaInterpolationBase(orig), etaInterpolationPosXY(orig) {}; eta3InterpolationPosXY(eta3InterpolationPosXY *orig): etaInterpolationBase(orig), etaInterpolationPosXY(orig) {};

View File

@ -94,7 +94,10 @@ class slsInterpolation
//create interpolated image //create interpolated image
//returns interpolated image //returns interpolated image
virtual int *getInterpolatedImage(){ virtual int *getInterpolatedImage(){
//cout << "?" <<endl; // cout << "return interpolated image " << endl;
/* for (int i=0; i<nSubPixels* nSubPixels* nPixelsX*nPixelsY; i++) { */
/* cout << i << " " << hint[i] << endl; */
/* } */
return hint; return hint;
}; };
@ -102,21 +105,17 @@ class slsInterpolation
void *writeInterpolatedImage(const char * imgname) { void *writeInterpolatedImage(const char * imgname) {
float *gm=NULL;
//cout << "!" <<endl; //cout << "!" <<endl;
float *gm=NULL;
int *dummy=getInterpolatedImage(); int *dummy=getInterpolatedImage();
cout << "got interpolated image " << endl;
gm=new float[ nSubPixelsX* nSubPixelsY* nPixelsX*nPixelsY]; gm=new float[ nSubPixelsX* nSubPixelsY* nPixelsX*nPixelsY];
cout << "created dummy " << endl;
if (gm) { if (gm) {
for (int ix=0; ix<nPixelsX*nSubPixelsX; ix++) { for (int ix=0; ix<nPixelsX*nSubPixelsX; ix++) {
for (int iy=0; iy<nPixelsY*nSubPixelsY; iy++) { for (int iy=0; iy<nPixelsY*nSubPixelsY; iy++) {
gm[iy*nPixelsX*nSubPixelsX+ix]=dummy[iy*nPixelsX*nSubPixelsX+ix]; gm[iy*nPixelsX*nSubPixelsX+ix]=dummy[iy*nPixelsX*nSubPixelsX+ix];
// cout << "++" << ix << " " << iy << " " << iy*nPixelsX*nSubPixelsX+ix << endl;
} }
} }
WriteToTiff(gm, imgname,nSubPixelsX* nPixelsX ,nSubPixelsY* nPixelsY); WriteToTiff(gm, imgname,nSubPixelsY* nPixelsX ,nSubPixelsY* nPixelsY);
// cout << "wrote to tiff " << endl;
delete [] gm; delete [] gm;
} else cout << "Could not allocate float image " << endl; } else cout << "Could not allocate float image " << endl;
return NULL; return NULL;
@ -173,7 +172,7 @@ class slsInterpolation
virtual int *setFlatField(int *h, int nb=-1, double emin=-1, double emax=-1){return NULL;}; virtual int *setFlatField(int *h, int nb=-1, double emin=-1, double emax=-1){return NULL;};
virtual void *writeFlatField(const char * imgname){return NULL;}; virtual void *writeFlatField(const char * imgname){return NULL;};
virtual void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){return NULL;}; virtual void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){return NULL;};
virtual int *getFlatField(int &nb, double &emin, double &emax){nb=0; emin=0; emax=0; return getFlatField();}; virtual int *getFlatField(int &nb, int &nby, double &emin, double &emax){nb=0; nby=0; emin=0; emax=0; return getFlatField();};
virtual void resetFlatField()=0; virtual void resetFlatField()=0;
@ -189,7 +188,6 @@ class slsInterpolation
static int calcQuad(double *cl, double &sum, double &totquad, double sDum[2][2]){ static int calcQuad(double *cl, double &sum, double &totquad, double sDum[2][2]){
//cout << "2";
int corner = UNDEFINED_QUADRANT; int corner = UNDEFINED_QUADRANT;
/* double *cluster[3]; */ /* double *cluster[3]; */
@ -198,11 +196,12 @@ class slsInterpolation
/* cluster[2]=cl+6; */ /* cluster[2]=cl+6; */
sum=0; sum=0;
int xoff=0, yoff=0;
#ifndef WRITE_QUAD
double sumBL=0; double sumBL=0;
double sumTL=0; double sumTL=0;
double sumBR=0; double sumBR=0;
double sumTR=0; double sumTR=0;
int xoff=0, yoff=0;
for (int ix=0; ix<3; ix++) { for (int ix=0; ix<3; ix++) {
for (int iy=0; iy<3; iy++) { for (int iy=0; iy<3; iy++) {
sum+=cl[ix+3*iy]; sum+=cl[ix+3*iy];
@ -222,34 +221,95 @@ class slsInterpolation
if(sumTL >= totquad){ if(sumTL >= totquad){
/* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; */ /* #ifdef WRITE_QUAD */
/* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; */ /* /\* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; *\/ */
/* /\* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; *\/ */
/* if (sumTL ==sum) { */
/* #endif */
corner = TOP_LEFT; corner = TOP_LEFT;
totquad=sumTL; totquad=sumTL;
xoff=0; xoff=0;
yoff=1; yoff=1;
/* #ifdef WRITE_QUAD */
/* } */
/* #endif */
} }
if(sumBR >= totquad){ if(sumBR >= totquad){
/* sDum[0][0] = cluster[0][1]; sDum[1][0] = cluster[1][1]; */ /* sDum[0][0] = cluster[0][1]; sDum[1][0] = cluster[1][1]; */
/* sDum[0][1] = cluster[0][2]; sDum[1][1] = cluster[1][2]; */ /* sDum[0][1] = cluster[0][2]; sDum[1][1] = cluster[1][2]; */
/* #ifdef WRITE_QUAD */
/* /\* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; *\/ */
/* /\* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; *\/ */
/* if (sumBR ==sum) { */
/* #endif */
corner = BOTTOM_RIGHT;
xoff=1; xoff=1;
yoff=0; yoff=0;
corner = BOTTOM_RIGHT;
totquad=sumBR; totquad=sumBR;
/* #ifdef WRITE_QUAD */
/* } */
/* #endif */
} }
if(sumTR >= totquad){ if(sumTR >= totquad){
/* #ifdef WRITE_QUAD */
/* /\* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; *\/ */
/* /\* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; *\/ */
/* if (sumTR ==sum) { */
/* #endif */
xoff=1; xoff=1;
yoff=1; yoff=1;
/* sDum[0][0] = cluster[1][1]; sDum[1][0] = cluster[2][1]; */ /* sDum[0][0] = cluster[1][1]; sDum[1][0] = cluster[2][1]; */
/* sDum[0][1] = cluster[1][2]; sDum[1][1] = cluster[2][2]; */ /* sDum[0][1] = cluster[1][2]; sDum[1][1] = cluster[2][2]; */
corner = TOP_RIGHT; corner = TOP_RIGHT;
totquad=sumTR; totquad=sumTR;
/* #ifdef WRITE_QUAD */
/* } */
/* #endif */
} }
#endif
#ifdef WRITE_QUAD
double sumB=0;
double sumT=0;
double sumR=0;
double sumL=0;
for (int ix=0; ix<3; ix++) {
for (int iy=0; iy<3; iy++) {
sum+=cl[ix+3*iy];
if (ix<1 ) sumL+=cl[ix+iy*3];
if (ix>1) sumR+=cl[ix+iy*3];
if (iy<1) sumB=cl[ix+iy*3];
if (iy>1) sumT+=cl[ix+iy*3];
}
}
totquad=sum;
if ( sumT==0 && sumR==0) {
corner = BOTTOM_LEFT;
xoff=0;
yoff=0;
} else if ( sumB==0 && sumR==0 ) {
corner = TOP_LEFT;
xoff=0;
yoff=1;
} else if ( sumT==0 && sumL==0) {
corner = BOTTOM_RIGHT;
xoff=1;
yoff=0;
} else if ( sumB==0 && sumL==0) {
xoff=1;
yoff=1;
corner = TOP_RIGHT;
} else
printf("** bad 2x2 cluster!\n");
#endif
for (int ix=0; ix<2; ix++) { for (int ix=0; ix<2; ix++) {
for (int iy=0; iy<2; iy++) { for (int iy=0; iy<2; iy++) {
@ -370,7 +430,6 @@ class slsInterpolation
static int calcEta3(double *cl, double &etax, double &etay, double &sum) { static int calcEta3(double *cl, double &etax, double &etay, double &sum) {
// cout << "3";
double l=0,r=0,t=0,b=0, val; double l=0,r=0,t=0,b=0, val;
sum=0; sum=0;
// int quad; // int quad;
@ -378,10 +437,10 @@ class slsInterpolation
for (int iy=0; iy<3; iy++) { for (int iy=0; iy<3; iy++) {
val=cl[ix+3*iy]; val=cl[ix+3*iy];
sum+=val; sum+=val;
if (ix==0) l+=val; if (iy==0) l+=val;
if (ix==2) r+=val; if (iy==2) r+=val;
if (iy==0) b+=val; if (ix==0) b+=val;
if (iy==2) t+=val; if (ix==2) t+=val;
} }
} }
if (sum>0) { if (sum>0) {

View File

@ -1,12 +1,14 @@
#module add CBFlib/0.9.5 #module add CBFlib/0.9.5
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include/
LDFLAG= ../tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -O3 -std=c++11
LDFLAG= ../tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -std=c++11 -Wall -O3
#-g3
#-fsanitize=thread -fno-omit-frame-pointer
#-fsanitize=address,undefined,
MAIN=moench03ClusterFinder.cpp MAIN=moench03ClusterFinder.cpp
all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog all: moenchClusterFinder moenchMakeEta moenchMakeEta3 moenchInterpolation moenchInterpolation3 moenchNoInterpolation moenchPhotonCounter moenchAnalog moenchPhotonCounterNoThread moenchAnalogNoThread
@ -23,9 +25,15 @@ moenchClusterFinderHighZ: moench03ClusterFinder.cpp $(INCS) clean
moenchMakeEta: moench03Interpolation.cpp $(INCS) clean moenchMakeEta: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchMakeEta moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF g++ -o moenchMakeEta moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF
moenchMakeEta3: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchMakeEta3 moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF -DETA3
moenchInterpolation: moench03Interpolation.cpp $(INCS) clean moenchInterpolation: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF)
moenchInterpolation3: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchInterpolation3 moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DETA3
moenchNoInterpolation: moench03NoInterpolation.cpp $(INCS) clean moenchNoInterpolation: moench03NoInterpolation.cpp $(INCS) clean
g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF)
@ -41,7 +49,13 @@ moenchPhotonCounterHighZ: moenchPhotonCounter.cpp $(INCS) clean
moenchAnalogHighZ: moenchPhotonCounter.cpp $(INCS) clean moenchAnalogHighZ: moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchAnalogHighZ moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DANALOG -DHIGHZ g++ -o moenchAnalogHighZ moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DANALOG -DHIGHZ
moenchAnalogNoThread : moenchPhotonCounterNoThread.cpp $(INCS) clean
g++ -o moenchAnalogNoThread moenchPhotonCounterNoThread.cpp $(LDFLAG) $(INCDIR) -DNEWRECEIVER -DANALOG
moenchPhotonCounterNoThread : moenchPhotonCounterNoThread.cpp $(INCS) clean
g++ -o moenchPhotonCounterNoThread moenchPhotonCounterNoThread.cpp $(LDFLAG) $(INCDIR) $ -DNEWRECEIVER
clean: clean:
rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog moenchPhotonCounterNoThread moenchAnalogNoThread

View File

@ -12,12 +12,12 @@ MAIN=moench03ClusterFinder.cpp
#-lhdf5 #-lhdf5
#DESTDIR?=../bin #DESTDIR?=../bin
all: moenchClusterFinderRect moenchMakeEtaRect moenchInterpolationRect moenchNoInterpolationRect moenchPhotonCounterRect moenchAnalogRect all: moenchClusterFinderRect moenchMakeEtaRect moenchInterpolationRect moenchNoInterpolationRect moenchPhotonCounterRect moenchAnalogRect moenchMakeEtaRect1 moenchInterpolationRect1
moenchClusterFinderRect: moench03ClusterFinder.cpp $(INCS) clean moenchClusterFinderRect: moench03ClusterFinder.cpp $(INCS) clean
g++ -o moenchClusterFinderRect moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) -DSAVE_ALL -DNEWRECEIVER -DRECT g++ -o moenchClusterFinderRect moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) -DSAVE_ALL -DNEWRECEIVER -DRECT
moenchMakeEtaRect: moench03Interpolation.cpp $(INCS) clean moenchMakeEtaRect: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchMakeEtaRect moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF -DRECT g++ -o moenchMakeEtaRect moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF -DRECT
@ -34,6 +34,12 @@ moenchPhotonCounterRect: moenchPhotonCounter.cpp $(INCS) clean
moenchAnalogRect: moenchPhotonCounter.cpp $(INCS) clean moenchAnalogRect: moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchAnalogRect moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) -DNEWRECEIVER -DANALOG -DRECT g++ -o moenchAnalogRect moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) -DNEWRECEIVER -DANALOG -DRECT
moenchMakeEtaRect1: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchMakeEtaRect1 moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF -DRECT -DRECT1
moenchInterpolationRect1: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchInterpolationRect1 moench03Interpolation.cpp $(LDFLAG) $(INCDIR) -DRECT -DRECT1
clean: clean:
rm -f moenchClusterFinderRect moenchMakeEtaRect moenchInterpolationRect moenchNoInterpolationRect moenchPhotonCounterRect moenchAnalogRect rm -f moenchClusterFinderRect moenchMakeEtaRect moenchInterpolationRect moenchNoInterpolationRect moenchPhotonCounterRect moenchAnalogRect

View File

@ -1,40 +0,0 @@
#CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/
#ZMQLIB=../slsReceiverSoftware/include
#LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include
#-I$(CBFLIBDIR)/include/
#LIBHDF5=
LDFLAG= ../tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -ltiff
#-L$(ZMQLIB) -lzmq -L$(CBFLIBDIR)/lib/
#-L../../bin
MAIN=moench03ClusterFinder.cpp
#-lhdf5
#DESTDIR?=../bin
all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog
moenchClusterFinder : moench03ClusterFinder.cpp $(INCS) clean
g++ -o moenchClusterFinder moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) -DSAVE_ALL -DNEWRECEIVER -DWRITE_QUAD
moenchMakeEta : moench03Interpolation.cpp $(INCS) clean
g++ -o moenchMakeEta moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF -DWRITE_QUAD
moenchInterpolation : moench03Interpolation.cpp $(INCS) clean
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) -DWRITE_QUAD
moenchNoInterpolation : moench03NoInterpolation.cpp $(INCS) clean
g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) -DWRITE_QUAD
moenchPhotonCounter : moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchPhotonCounter moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $ -DNEWRECEIVER -DWRITE_QUAD
moenchAnalog : moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchAnalog moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) -DNEWRECEIVER -DANALOG -DWRITE_QUAD
clean:
rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog

View File

@ -1,6 +1,7 @@
//#include "ansi.h" //#include "ansi.h"
#include <iostream> #include <iostream>
// bin/moenchClusterFinder moench03_25022020 moench_fluo_outputs flat_27keV_d0_f000000%d00000_1 0 10
//#include "moench03T1ZmqData.h" //#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER #ifdef NEWRECEIVER
@ -33,7 +34,9 @@
#include "multiThreadedAnalogDetector.h" #include "multiThreadedAnalogDetector.h"
#include "singlePhotonDetector.h" #include "singlePhotonDetector.h"
//#include "interpolatingDetector.h" //#include "interpolatingDetector.h"
#include <string>
#include <sstream>
#include <stdio.h> #include <stdio.h>
#include <map> #include <map>
#include <fstream> #include <fstream>
@ -50,20 +53,20 @@ int main(int argc, char *argv[]) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl; cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 1; return 1;
} }
int p=10000; //int p=10000;
int fifosize=1000; int fifosize=1000;
int nthreads=1; int nthreads=16;
int nsubpix=25; //int nsubpix=25;
int etabins=nsubpix*10; //int etabins=nsubpix*10;
double etamin=-1, etamax=2; //double etamin=-1, etamax=2;
int csize=3; int csize=3;
int nx=400, ny=400; int nx=400, ny=400;
int save=1; //int save=1;
int nsigma=1; int nsigma=5;
int nped=1000; int nped=1000;
int ndark=100; //int ndark=100;
int ok; //int ok;
int iprog=0; //int iprog=0;
@ -108,9 +111,9 @@ int main(int argc, char *argv[]) {
// cout << "filter "<< endl; // cout << "filter "<< endl;
int size = 327680;////atoi(argv[3]); //int size = 327680;////atoi(argv[3]);
int* image; //int* image;
//int* image =new int[327680/sizeof(int)]; //int* image =new int[327680/sizeof(int)];
filter->newDataSet(); filter->newDataSet();
@ -120,21 +123,21 @@ int main(int argc, char *argv[]) {
cout << " data size is " << dsize; cout << " data size is " << dsize;
char data[dsize]; //char data[dsize];
ifstream filebin; ifstream filebin;
char *indir=argv[1]; string indir=string(argv[1]);
char *outdir=argv[2]; string outdir=string(argv[2]);
char *fformat=argv[3]; string fformat=string(argv[3]);
int runmin=atoi(argv[4]); int runmin=atoi(argv[4]);
int runmax=atoi(argv[5]); int runmax=atoi(argv[5]);
char fname[10000]; string fname;
char outfname[10000]; string outfname;
char imgfname[10000]; string imgfname;
char pedfname[10000]; //char pedfname[10000];
// strcpy(pedfname,argv[6]); // strcpy(pedfname,argv[6]);
char fn[10000]; char fn[10000];
std::time_t end_time; std::time_t end_time;
@ -148,12 +151,6 @@ int main(int argc, char *argv[]) {
cout << std::ctime(&end_time) << endl; cout << std::ctime(&end_time) << endl;
char* buff; char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
@ -170,17 +167,26 @@ int main(int argc, char *argv[]) {
for (int irun=runmin; irun<runmax; irun++) { for (int irun=runmin; irun<runmax; irun++) {
sprintf(fn,fformat,irun); sprintf(fn,fformat.c_str(),irun);
sprintf(fname,"%s/%s.raw",indir,fn); fname=indir+"/"+string(fn)+".raw";
sprintf(outfname,"%s/%s.clust",outdir,fn); //sprintf(fname,"%s/%s.raw",indir,fn);
sprintf(imgfname,"%s/%s.tiff",outdir,fn); #ifndef WRITE_QUAD
outfname=outdir+string(fn)+".clust";
//sprintf(outfname,"%s/%s.clust",outdir,fn);
#endif
#ifdef WRITE_QUAD
outfname=outdir+string(fn)+".clust2";
// sprintf(outfname,"%s/%s.clust2",outdir,fn);
#endif
imgfname=outdir+string(fn)+".tiff";
//sprintf(imgfname,"%s/%s.tiff",outdir,fn);
std::time(&end_time); std::time(&end_time);
cout << std::ctime(&end_time) << endl; cout << std::ctime(&end_time) << endl;
cout << fname << " " << outfname << " " << imgfname << endl; cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary); filebin.open(fname.c_str(), ios::in | ios::binary);
// //open file // //open file
if (filebin.is_open()){ if (filebin.is_open()){
of=fopen(outfname,"w"); of=fopen(outfname.c_str(),"w");
if (of) { if (of) {
mt->setFilePointer(of); mt->setFilePointer(of);
// cout << "file pointer set " << endl; // cout << "file pointer set " << endl;
@ -212,7 +218,7 @@ int main(int argc, char *argv[]) {
} }
ff=-1; ff=-1;
} }
cout << "--" << endl; cout << "--" << endl;
filebin.close(); filebin.close();
// //close file // //close file
// //join threads // //join threads
@ -220,7 +226,7 @@ int main(int argc, char *argv[]) {
if (of) if (of)
fclose(of); fclose(of);
mt->writeImage(imgfname); mt->writeImage(imgfname.c_str());
mt->clearImage(); mt->clearImage();
std::time(&end_time); std::time(&end_time);

View File

@ -5,7 +5,7 @@
//#include "moench03T1ZmqData.h" //#include "moench03T1ZmqData.h"
//#define DOUBLE_SPH //#define DOUBLE_SPH
//#define MANYFILES //#define MANYFILES
//#define WRITE_QUAD
#ifdef DOUBLE_SPH #ifdef DOUBLE_SPH
#include "single_photon_hit_double.h" #include "single_photon_hit_double.h"
#endif #endif
@ -14,12 +14,7 @@
#include "single_photon_hit.h" #include "single_photon_hit.h"
#endif #endif
#ifdef RECT
#include "etaInterpolationGlobal.h"
#endif
#ifndef RECT
#include "etaInterpolationPosXY.h" #include "etaInterpolationPosXY.h"
#endif
#include "noInterpolation.h" #include "noInterpolation.h"
//#include "etaInterpolationCleverAdaptiveBins.h" //#include "etaInterpolationCleverAdaptiveBins.h"
//#include "etaInterpolationRandomBins.h" //#include "etaInterpolationRandomBins.h"
@ -41,7 +36,6 @@ using namespace std;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
#ifndef FF #ifndef FF
cout << "INTERPOLATING" << endl;
if (argc<9) { if (argc<9) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile outfile runmin runmax ns cmin cmax" << endl; cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile outfile runmin runmax ns cmin cmax" << endl;
return 1; return 1;
@ -49,7 +43,6 @@ int main(int argc, char *argv[]) {
#endif #endif
#ifdef FF #ifdef FF
cout << "CALC ETA" << endl;
if (argc<7) { if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile runmin runmax cmin cmax" << endl; cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile runmin runmax cmin cmax" << endl;
return 1; return 1;
@ -57,9 +50,9 @@ int main(int argc, char *argv[]) {
#endif #endif
int iarg=4; int iarg=4;
char infname[10000]; char infname[10000];
char fname[10000];
char outfname[10000]; char outfname[10000];
#ifndef FF #ifndef FF
char fname[10000];
iarg=4; iarg=4;
#endif #endif
@ -81,26 +74,42 @@ int main(int argc, char *argv[]) {
cout << "Energy min: " << cmin << endl; cout << "Energy min: " << cmin << endl;
cout << "Energy max: " << cmax << endl; cout << "Energy max: " << cmax << endl;
//int etabins=500; //int etabins=500;
int etabins=999;//nsubpix*2*100; #ifndef NOINTERPOLATION
int etabins=1000;//nsubpix*2*100;
int etabinsY=etabins;//nsubpix*2*100; int etabinsY=etabins;//nsubpix*2*100;
double etamin=0, etamax=1;
double etamin=-1, etamax=2;
//double etamin=-0.1, etamax=1.1; //double etamin=-0.1, etamax=1.1;
double eta3min=-1, eta3max=1;
double etax=0, etay=0;
#ifndef FF
double int_x, int_y;
// double d_x, d_y, res=5, xx, yy;
int ok;
#endif
#ifdef ETA3
etamin=-2;
etamax=2;
#endif
#endif
//#ifndef FF
int quad; int quad;
//#endif
double sum, totquad; double sum, totquad;
double sDum[2][2]; double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y; #ifdef NOINTERPOLATION
int ok; #ifndef FF
double noint_x, noint_y;
#endif
#endif
int f0=-1; int f0=-1;
int ix, iy, isx, isy; int ix, iy, isx, isy;
int nframes=0, lastframe=-1; int nframes=0, lastframe=-1;
double d_x, d_y, res=5, xx, yy;
int nph=0, badph=0, totph=0;
FILE *f=NULL;
//badph=0,
char fff[10000]; int nph=0, totph=0;
FILE *f=NULL;
#ifdef DOUBLE_SPH #ifdef DOUBLE_SPH
single_photon_hit_double cl(3,3); single_photon_hit_double cl(3,3);
@ -111,24 +120,23 @@ int main(int argc, char *argv[]) {
#endif #endif
int nSubPixels=nsubpix; int nSubPixels=nsubpix;
int nSubPixelsY=nsubpix; int nSubPixelsY=nsubpix;
#ifdef RECT #ifdef RECT1
nSubPixels=5; //might make more sense using 2? // nSubPixels=2; //might make more sense using 2?
// etabins=5; // etabins=100;
float *rectimg=new float[NC*NR*nSubPixelsY];;
#endif #endif
// #endif
#ifndef NOINTERPOLATION #ifndef NOINTERPOLATION
etaInterpolationBase *interp; #ifndef ETA3
#ifndef RECT eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax);
interp=new eta2InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax);
//eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
#endif #endif
#ifdef RECT #ifdef ETA3
interp=new eta2InterpolationGlobal(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, eta3min, eta3max); eta3InterpolationPosXY *interp=new eta3InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax);
// eta3InterpolationPosXY *interpOdd=new eta3InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, eta3min, eta3max);
//eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
#endif #endif
//eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
#endif #endif
#ifdef NOINTERPOLATION #ifdef NOINTERPOLATION
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix, nSubPixelsY); noInterpolation *interp=new noInterpolation(NC, NR, nsubpix, nSubPixelsY);
@ -137,24 +145,12 @@ int main(int argc, char *argv[]) {
#ifndef FF #ifndef FF
int *img;
#ifndef NOINTERPOLATION #ifndef NOINTERPOLATION
cout << "read ff " << argv[2] << endl; cout << "read ff " << argv[2] << endl;
sprintf(fname,"%s",argv[2]); sprintf(fname,"%s",argv[2]);
//#ifndef RECT
interp->readFlatField(fname, etamin, etamax); interp->readFlatField(fname, etamin, etamax);
interp->prepareInterpolation(ok);//, MAX_ITERATIONS); interp->prepareInterpolation(ok);//, MAX_ITERATIONS);
interp->debugSaveAll(0);
//#endif
// #ifdef RECT
// sprintf(fff,"%s.even",fname);
// interpEven->readFlatField(fff, etamin, etamax);
// interpEven->prepareInterpolation(ok);, MAX_ITERATIONS);
// interpEven->debugSaveAll(1);
// sprintf(fff,"%s.odd",fname);
// interpOdd->readFlatField(fff, etamin, etamax);
// interpOdd->prepareInterpolation(ok);, MAX_ITERATIONS);
// interpOdd->debugSaveAll(2);
// #endif
#endif #endif
// return 0; // return 0;
#endif #endif
@ -162,7 +158,6 @@ int main(int argc, char *argv[]) {
cout << "Will write eta file " << argv[2] << endl; cout << "Will write eta file " << argv[2] << endl;
#endif #endif
int *img;
float *totimg=new float[NC*NR*nSubPixels*nSubPixelsY]; float *totimg=new float[NC*NR*nSubPixels*nSubPixelsY];
for (ix=0; ix<NC; ix++) { for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) { for (iy=0; iy<NR; iy++) {
@ -177,9 +172,6 @@ int main(int argc, char *argv[]) {
#ifdef FF #ifdef FF
sprintf(outfname,argv[2]); sprintf(outfname,argv[2]);
#endif #endif
int tl=0, tr=0, bl=0, br=0;
int irun; int irun;
for (irun=runmin; irun<runmax; irun++) { for (irun=runmin; irun<runmax; irun++) {
@ -201,80 +193,76 @@ int main(int argc, char *argv[]) {
if (nframes==0) f0=lastframe; if (nframes==0) f0=lastframe;
nframes++; nframes++;
} }
#ifdef RECT //#ifndef FF
// quad=interp->calcEta3(cl.get_cluster(), etax, etay, sum); #ifndef ETA3
quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum); quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
// if (cl.y%2==0) #endif
// if (etay>0) #ifdef ETA3
// interp=interpEven; quad=interp->calcEta3(cl.get_cluster(), etax, etay, sum);
// else totquad=sum;
// interp=interpOdd; #endif
// else //#endif
// if (etay>0) // #ifdef FF
// interp=interpOdd; // #ifndef ETA3
// else // interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
// interp=interpEven; // #endif
// #endif
#endif if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
#ifndef RECT
quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
#endif
switch(quad) {
case TOP_LEFT:
tl++;
break;
case TOP_RIGHT:
tr++;
break;
case BOTTOM_LEFT:
bl++;
break;
case BOTTOM_RIGHT:
br++;
break;
}
// if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
if (sum>cmin && sum<cmax ) {
nph++; nph++;
#ifndef FF // if (sum>200 && sum<580) {
// interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y);
// #ifdef SOLEIL
// if (cl.x>210 && cl.x<240 && cl.y>210 && cl.y<240) {
// #endif
if (cl.x<0 || cl.y<0 || cl.x>NC || cl.y>NR) {
if (cl.x<-1 || cl.y<-1 || cl.x>NC+1 || cl.y>NR+1) {
cout <<"**************"<< endl;
cout << cl.x << " " << cl.y << " " << sum << endl;
cl.print();
cout <<"**************"<< endl;
}
} else {
#ifndef FF
// interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y);
interp->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,int_x, int_y); interp->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,int_x, int_y);
interp->addToImage(int_x, int_y); // cout <<"**************"<< endl;
// cout << cl.x << " " << cl.y << " " << sum << endl;
// cl.print();
// cout << int_x << " " << int_y << endl;
// cout <<"**************"<< endl;
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
if (int_x<-1 || int_y<-1 || int_x>NC+1 || int_y>NR+1) {
cout <<"**************"<< endl;
cout << cl.x << " " << cl.y << " " << sum << endl;
cl.print();
cout << int_x << " " << int_y << endl;
cout <<"**************"<< endl;
} else
interp->addToImage(int_x, int_y);
#endif #endif
#ifdef FF #ifdef FF
// interp->addToFlatField(cl.get_cluster(), etax, etay);
// #ifdef UCL
// if (cl.x>50)
// #endif
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToFlatField(etax, etay); interp->addToFlatField(etax, etay);
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl;
#endif #endif
}
// #ifdef SOLEIL
// }
// #endif
if (nph%1000000==0) cout << nph << endl; if (nph%1000000==0) cout << nph << endl;
if (nph%10000000==0) { if (nph%10000000==0) {
#ifndef FF #ifndef FF
interp->writeInterpolatedImage(outfname);
cout << "writing interpolated iamge" << endl;
//#ifndef RECT
interp->writeInterpolatedImage(outfname);
//#endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeInterpolatedImage(fff);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeInterpolatedImage(fff);
// #endif
cout << "done" << endl;
#endif #endif
#ifdef FF #ifdef FF
cout << "writing eta" << endl; interp->writeFlatField(outfname);
//#ifndef RECT
interp->writeFlatField(outfname);
//#endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeFlatField(fff);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeFlatField(fff);
// #endif
cout << "done" << endl;
#endif #endif
} }
@ -285,84 +273,71 @@ int main(int argc, char *argv[]) {
fclose(f); fclose(f);
#ifdef FF #ifdef FF
//#ifndef RECT
interp->writeFlatField(outfname); interp->writeFlatField(outfname);
// #endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeFlatField(outfname);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeFlatField(outfname);
// #endif
#endif #endif
#ifndef FF #ifndef FF
//#ifndef RECT #ifndef RECT1
interp->writeInterpolatedImage(outfname); interp->writeInterpolatedImage(outfname);
// #endif #endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeInterpolatedImage(fff);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeInterpolatedImage(fff);
// #endif
//#ifdef RECT
//interp=interpEven;
//#endif
img=interp->getInterpolatedImage(); img=interp->getInterpolatedImage();
for (ix=0; ix<NC; ix++) { for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) { for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nSubPixels; isx++) {
for (isx=0; isx<nSubPixels; isx++) {
for (isy=0; isy<nSubPixelsY; isy++) { for (isy=0; isy<nSubPixelsY; isy++) {
totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]; totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
// cout << "--" << ix << " " << iy <<" " << ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels) << endl; #ifdef RECT1
if (isx==0)
rectimg[ix+(iy*nSubPixelsY+isy)*(NC)]=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
else
rectimg[ix+(iy*nSubPixelsY+isy)*(NC)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
#endif
} }
} }
} }
} }
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl;
cout << "Top-Left=" << tl << " " << " Top-Right=" << tr << " Bottom-Left="<< bl << " Bottom-Right=" << br << endl; #ifdef RECT1
interp->clearInterpolatedImage(); WriteToTiff(rectimg, outfname,NC,NR*nSubPixelsY);
// #ifdef RECT
// interp=interpOdd;
// img=interp->getInterpolatedImage();
// for (ix=0; ix<NC; ix++) {
// for (iy=0; iy<NR; iy++) {
// for (isx=0; isx<nSubPixels; isx++) {
// for (isy=0; isy<nSubPixelsY; isy++) {
// totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
// // cout << "--" << ix << " " << iy <<" " << ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels) << endl;
// }
// }
// }
// }
// interp->clearInterpolatedImage();
// #endif
#endif #endif
interp->clearInterpolatedImage();
#endif
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl;
} else } else
cout << "could not open file " << infname << endl; cout << "could not open file " << infname << endl;
} }
#ifndef FF #ifndef FF
sprintf(outfname,argv[3],11111); sprintf(outfname,argv[3],11111);
#ifndef RECT1
WriteToTiff(totimg, outfname,NC*nSubPixels,NR*nSubPixelsY); WriteToTiff(totimg, outfname,NC*nSubPixels,NR*nSubPixelsY);
#endif
#ifdef RECT1
img=interp->getInterpolatedImage();
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nSubPixels; isx++) {
for (isy=0; isy<nSubPixelsY; isy++) {
if (isx==0)
rectimg[ix+(iy*nSubPixelsY+isy)*(NC)]=totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
else
rectimg[ix+(iy*nSubPixelsY+isy)*(NC)]+=totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
}
}
}
}
WriteToTiff(rectimg, outfname,NC,NR*nSubPixelsY);
#endif
#endif #endif
#ifdef FF #ifdef FF
//#ifndef RECT
interp->writeFlatField(outfname); interp->writeFlatField(outfname);
//#endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeFlatField(fff);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeFlatField(fff);
// #endif
#endif #endif
cout << "Filled " << nph << " (/"<< totph <<") " << endl; cout << "Filled " << nph << " (/"<< totph <<") " << endl;

View File

@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
*/ */
if (argc<7) { if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " etafile outfile runmin runmax ns" << endl; cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " outfile runmin runmax ns" << endl;
return 1; return 1;
} }
@ -28,13 +28,14 @@ int main(int argc, char *argv[]) {
int runmax=atoi(argv[5]); int runmax=atoi(argv[5]);
int nsubpix=atoi(argv[6]); int nsubpix=atoi(argv[6]);
int etabins=1000;//nsubpix*2*100; // int etabins=1000;//nsubpix*2*100;
double etamin=-1, etamax=2; // double etamin=-1, etamax=2;
int quad; int quad;
double sum, totquad; double sum, totquad;
double sDum[2][2]; double sDum[2][2];
double etax, etay, int_x, int_y; //double etax, etay,
int ok; double int_x, int_y;
//int ok;
int ix, iy, isx, isy; int ix, iy, isx, isy;

View File

@ -43,7 +43,7 @@
#include <map> #include <map>
#include <fstream> #include <fstream>
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h>
#include <ctime> #include <ctime>
using namespace std; using namespace std;
@ -58,19 +58,19 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
int p=10000; //int p=10000;
int fifosize=1000; int fifosize=1000;
int nthreads=10; int nthreads=10;
int nsubpix=25; //int nsubpix=25;
int etabins=nsubpix*10; //int etabins=nsubpix*10;
double etamin=-1, etamax=2; //double etamin=-1, etamax=2;
int csize=3; int csize=3;
int save=1; //int save=1;
int nsigma=5; int nsigma=5;
int nped=10000; int nped=10000;
int ndark=100; //int ndark=100;
int ok; //int ok;
int iprog=0; //int iprog=0;
int cf=0; int cf=0;
@ -101,13 +101,13 @@ int main(int argc, char *argv[]) {
moench03CommonMode *cm=NULL; moench03CommonMode *cm=NULL;
moench03GhostSummation *gs; moench03GhostSummation *gs;
double *gainmap=NULL; double *gainmap=NULL;
float *gm; //float *gm;
int size = 327680;////atoi(argv[3]); //int size = 327680;////atoi(argv[3]);
int* image; //int* image;
//int* image =new int[327680/sizeof(int)]; //int* image =new int[327680/sizeof(int)];
int ff, np; int ff, np;
@ -171,7 +171,7 @@ int main(int argc, char *argv[]) {
char fname[10000]; char fname[10000];
char imgfname[10000]; char imgfname[10000];
char cfname[10000]; char cfname[10000];
char fn[10000]; //char fn[10000];
std::time_t end_time; std::time_t end_time;
@ -185,9 +185,9 @@ int main(int argc, char *argv[]) {
cout << "pedestal file is " << pedfile << endl; cout << "pedestal file is " << pedfile << endl;
if (thr>0) if (thr>0)
cout << "threshold is " << thr << endl; cout << "threshold is " << thr << endl;
uint32 unnx, unny;
uint32 nnx, nny; int nnx, nny;
double *gmap; //double *gmap;
// if (gainfname) { // if (gainfname) {
// gm=ReadFromTiff(gainfname, nny, nnx); // gm=ReadFromTiff(gainfname, nny, nnx);
@ -221,10 +221,10 @@ int main(int argc, char *argv[]) {
} else } else
thr=0.15*thr; thr=0.15*thr;
filter->newDataSet(); filter->newDataSet();
int dsize=decoder->getDataSize(); //int dsize=decoder->getDataSize();
char data[dsize]; //char data[dsize];
@ -270,12 +270,14 @@ int main(int argc, char *argv[]) {
mt->StartThreads(); mt->StartThreads();
mt->popFree(buff); mt->popFree(buff);
DIR *dir;
struct dirent *ent;
// cout << "mt " << endl; // cout << "mt " << endl;
int ifr=0; int ifr=0;
double ped[nx*ny], *ped1; double ped[nx*ny];//, *ped1;
if (pedfile) { if (pedfile) {
@ -302,7 +304,7 @@ int main(int argc, char *argv[]) {
mt->nextThread(); mt->nextThread();
mt->popFree(buff); mt->popFree(buff);
ifr++; ifr++;
if (ifr%100==0) if (ifr%10000==0)
cout << ifr << " " << ff << " " << np << endl; cout << ifr << " " << ff << " " << np << endl;
} else } else
cout << ifr << " " << ff << " " << np << endl; cout << ifr << " " << ff << " " << np << endl;
@ -314,7 +316,9 @@ int main(int argc, char *argv[]) {
} else } else
cout << "Could not open pedestal file "<< fname << " for reading " << endl; cout << "Could not open pedestal file "<< fname << " for reading " << endl;
} else { } else {
float *pp=ReadFromTiff(pedfile, nny, nnx); float *pp=ReadFromTiff(pedfile, unny, unnx);
nny=unny;
nnx=unnx;
if (pp && nnx==nx && nny==ny) { if (pp && nnx==nx && nny==ny) {
for (int i=0; i<nx*ny; i++) { for (int i=0; i<nx*ny; i++) {
ped[i]=pp[i]; ped[i]=pp[i];
@ -341,28 +345,23 @@ int main(int argc, char *argv[]) {
ifr=0; ifr=0;
int ifile=0; int ifile=0;
char ext[100];
mt->setFrameMode(eFrame); mt->setFrameMode(eFrame);
for (int irun=runmin; irun<=runmax; irun++) { for (int irun=runmin; irun<=runmax; irun++) {
cout << "DATA " ; cout << "DATA " ;
// sprintf(fn,fformat,irun); // sprintf(fn,fformat,irun);
sprintf(ffname,"%s/%s.raw",indir,fformat); sprintf(ext,"_%d.raw",irun);
sprintf(fname,ffname,irun);
sprintf(ffname,"%s/%s.tiff",outdir,fformat);
sprintf(imgfname,ffname,irun); sprintf(imgfname,"%s/%s_%d.tiff",outdir,fformat,irun);
sprintf(ffname,"%s/%s.clust",outdir,fformat); // sprintf(imgfname,ffname,irun);
sprintf(cfname,ffname,irun); sprintf(cfname,"%s/%s_%d.clust",outdir,fformat, irun);
cout << fname << " " ; //sprintf(cfname,ffname,irun);
cout << cfname << " " ;
cout << imgfname << endl; cout << imgfname << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
// cout << fname << " " << outfname << " " << imgfname << endl; if (thr<=0 && cf!=0) { //cluster finder
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
ifile=0;
if (filebin.is_open()){
if (thr<=0 && cf!=0) { //cluster finder
if (of==NULL) { if (of==NULL) {
of=fopen(cfname,"w"); of=fopen(cfname,"w");
if (of) { if (of) {
@ -375,77 +374,105 @@ int main(int argc, char *argv[]) {
} }
} }
} }
// //while read frame
ff=-1; if ((dir = opendir (indir)) != NULL) {
ifr=0; /* print all the files and directories within directory */
while (decoder->readNextFrame(filebin, ff, np,buff)) { while ((ent = readdir (dir)) != NULL) {
if (np==40) { // printf ("----------- %s\n", ent->d_name);
// cout << "*"<<ifr++<<"*"<<ff<< endl; // printf ("************** %s", ent->d_name);
// cout << ff << " " << np << endl; // cout << string(ent->d_name).find(fformat) << endl;
// //push if (string(ent->d_name).find(string(fformat)+"_d0_f0")==0) {
mt->pushData(buff); // printf ("+++++++++++++++ %s\n", ent->d_name);
// // //pop if (string(ent->d_name).find(ext)!= string::npos) {
mt->nextThread(); //printf ("**************8 %s\n", ent->d_name);
// // // cout << " " << (void*)buff; sprintf(fname,"%s/%s",indir,ent->d_name);
mt->popFree(buff); //sprintf(fname,ffname,irun);
cout << fname << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
// cout << fname << " " << outfname << " " << imgfname << endl;
ifr++; filebin.open((const char *)(fname), ios::in | ios::binary);
if (ifr%100==0) cout << ifr << " " << ff << endl; // //open file
if (nframes>0) { ifile=0;
if (ifr%nframes==0) { if (filebin.is_open()){
//The name has an additional "_fXXXXX" at the end, where "XXXXX" is the initial frame number of the image (0,1000,2000...) // //while read frame
ff=-1;
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile); ifr=0;
sprintf(imgfname,ffname,irun); while (decoder->readNextFrame(filebin, ff, np,buff)) {
//cout << "Writing tiff to " << imgfname << " " << thr1 << endl; if (np==40) {
mt->writeImage(imgfname, thr1); mt->pushData(buff);
mt->clearImage(); mt->nextThread();
ifile++; mt->popFree(buff);
ifr++;
if (ifr%10000==0) cout << ifr << " " << ff << endl;
if (nframes>0) {
while (mt->isBusy()) {;}
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...)
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(imgfname,ffname,irun);
//cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
}
}
}
ff=-1;
} }
} filebin.close();
} else } else
cout << ifr << " " << ff << " " << np << endl; cout << "Could not open "<< fname << " for reading " << endl;
ff=-1; }
} }
cout << "--" << endl;
filebin.close();
// //close file }
// //join threads while (mt->isBusy()) {;}
while (mt->isBusy()) {;} if (nframes>=0) {
if (nframes>=0) { if (nframes>0) {
if (nframes>0) { sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile); sprintf(imgfname,ffname,irun);
sprintf(imgfname,ffname,irun); } else {
} else { sprintf(imgfname,"%s/%s_%d.tiff",outdir,fformat,irun);
sprintf(ffname,"%s/%s.tiff",outdir,fformat); //sprintf(imgfname,ffname,irun);
sprintf(imgfname,ffname,irun); }
} cout << "Writing tiff to " << imgfname << " " << ifr <<endl;
cout << "Writing tiff to " << imgfname << " " << thr1 <<endl; mt->writeImage(imgfname, thr1);
mt->writeImage(imgfname, thr1); mt->clearImage();
mt->clearImage(); if (of) {
if (of) { fclose(of);
fclose(of); of=NULL;
of=NULL; mt->setFilePointer(NULL);
mt->setFilePointer(NULL); }
} }
} std::time(&end_time);
std::time(&end_time); cout << std::ctime(&end_time) << endl;
cout << std::ctime(&end_time) << endl;
} else closedir (dir);
cout << "Could not open "<< fname << " for reading " << endl; } else {
/* could not open directory */
cout << "could not open directory " << indir << endl;
} }
}
if (nframes<0){ if (nframes<0){
sprintf(ffname,"%s/%s.tiff",outdir,fformat); sprintf(ffname,"%s/%s.tiff",outdir,fformat);
strcpy(imgfname,ffname); strcpy(imgfname,ffname);
cout << "Writing tiff to " << imgfname << " " << thr1 <<endl; cout << "Writing tiff to " << imgfname << " " << ifr <<endl;
mt->writeImage(imgfname, thr1); mt->writeImage(imgfname, thr1);
} }
sprintf(imgfname,"%s/%s_ped.tiff",outdir,fformat);
mt->writePedestal(imgfname);
sprintf(imgfname,"%s/%s_noise.tiff",outdir,fformat);
mt->writePedestalRMS(imgfname);
return 0; return 0;
} }

View File

@ -0,0 +1,527 @@
//#include "ansi.h"
#include <iostream>
//#define CORR
#define NOTHREAD
#define C_GHOST 0.0004
#define CM_ROWS 50
//#define VERSION_V1
//#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER
#ifndef RECT
#include "moench03T1ReceiverDataNew.h"
#endif
#ifdef RECT
#include "moench03T1ReceiverDataNewRect.h"
#endif
#endif
#ifdef CSAXS_FP
#include "moench03T1ReceiverData.h"
#endif
#ifdef OLDDATA
#include "moench03Ctb10GbT1Data.h"
#endif
// #include "interpolatingDetector.h"
//#include "etaInterpolationPosXY.h"
// #include "linearInterpolation.h"
// #include "noInterpolation.h"
#include "multiThreadedCountingDetector.h"
//#include "multiThreadedAnalogDetector.h"
#include "singlePhotonDetector.h"
#include "moench03GhostSummation.h"
#include "moench03CommonMode.h"
//#include "interpolatingDetector.h"
#include <stdio.h>
#include <map>
#include <fstream>
#include <sys/stat.h>
#include <dirent.h>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]) {
if (argc<4) {
cout << "Usage is " << argv[0] << "indir outdir fname [runmin] [runmax] [pedfile] [threshold] [nframes] [xmin xmax ymin ymax] [gainmap]" << endl;
cout << "threshold <0 means analog; threshold=0 means cluster finder; threshold>0 means photon counting" << endl;
cout << "nframes <0 means sum everything; nframes=0 means one file per run; nframes>0 means one file every nframes" << endl;
return 1;
}
//int p=10000;
int fifosize=1000;
int nthreads=10;
//int nsubpix=25;
//int etabins=nsubpix*10;
//double etamin=-1, etamax=2;
int csize=3;
//int save=1;
int nsigma=5;
int nped=10000;
//int ndark=100;
//int ok;
//int iprog=0;
int cf=0;
#ifdef NEWRECEIVER
#ifdef RECT
cout << "Should be rectangular!" <<endl;
#endif
moench03T1ReceiverDataNew *decoder=new moench03T1ReceiverDataNew();
cout << "RECEIVER DATA WITH ONE HEADER!"<<endl;
#endif
#ifdef CSAXS_FP
moench03T1ReceiverData *decoder=new moench03T1ReceiverData();
cout << "RECEIVER DATA WITH ALL HEADERS!"<<endl;
#endif
#ifdef OLDDATA
moench03Ctb10GbT1Data *decoder=new moench03Ctb10GbT1Data();
cout << "OLD RECEIVER DATA!"<<endl;
#endif
int nx=400, ny=400;
decoder->getDetectorSize(nx,ny);
int ncol_cm=CM_ROWS;
double xt_ghost=C_GHOST;
moench03CommonMode *cm=NULL;
moench03GhostSummation *gs;
double *gainmap=NULL;
//float *gm;
//int size = 327680;////atoi(argv[3]);
//int* image;
//int* image =new int[327680/sizeof(int)];
int ff, np;
//cout << " data size is " << dsize;
ifstream filebin;
char *indir=argv[1];
char *outdir=argv[2];
char *fformat=argv[3];
int runmin=0;
// cout << "argc is " << argc << endl;
if (argc>=5) {
runmin=atoi(argv[4]);
}
int runmax=runmin;
if (argc>=6) {
runmax=atoi(argv[5]);
}
char *pedfile=NULL;
if (argc>=7) {
pedfile=argv[6];
}
double thr=0;
double thr1=1;
if (argc>=8) {
thr=atof(argv[7]);
}
int nframes=0;
if (argc>=9) {
nframes=atoi(argv[8]);
}
int xmin=0, xmax=nx, ymin=0, ymax=ny;
if (argc>=13) {
xmin=atoi(argv[9]);
xmax=atoi(argv[10]);
ymin=atoi(argv[11]);
ymax=atoi(argv[12]);
}
char *gainfname=NULL;
if (argc>13) {
gainfname=argv[13];
cout << "Gain map file name is: " << gainfname << endl;
}
char ffname[10000];
char fname[10000];
char imgfname[10000];
char cfname[10000];
//char fn[10000];
std::time_t end_time;
FILE *of=NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "input file is " << fformat << endl;
cout << "runmin is " << runmin << endl;
cout << "runmax is " << runmax << endl;
if (pedfile)
cout << "pedestal file is " << pedfile << endl;
if (thr>0)
cout << "threshold is " << thr << endl;
uint32 unnx, unny;
int nnx, nny;
//double *gmap;
// if (gainfname) {
// gm=ReadFromTiff(gainfname, nny, nnx);
// if (gm && nnx==nx && nny==ny) {
// gmap=new double[nx*ny];
// for (int i=0; i<nx*ny; i++) {
// gmap[i]=gm[i];
// }
// delete gm;
// } else
// cout << "Could not open gain map " << gainfname << endl;
// }
#ifdef CORR
cout << "Applying common mode " << ncol_cm << endl;
cm=new moench03CommonMode(ncol_cm);
cout << "Applying ghost corrections " << xt_ghost << endl;
gs=new moench03GhostSummation(decoder, xt_ghost);
#endif
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, cm, nped, 200, -1, -1, gainmap, gs);
if (gainfname) {
if (filter->readGainMap(gainfname))
cout << "using gain map " << gainfname << endl;
else
cout << "Could not open gain map " << gainfname << endl;
} else
thr=0.15*thr;
filter->newDataSet();
//int dsize=decoder->getDataSize();
//char data[dsize];
//#ifndef ANALOG
if (thr>0) {
cout << "threshold is " << thr << endl;
//#ifndef ANALOG
filter->setThreshold(thr);
//#endif
cf=0;
} else
cf=1;
//#endif
filter->setROI(xmin,xmax,ymin,ymax);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char* buff;
// multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
#ifndef NOTHREAD
multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize);
#endif
#ifdef NOTHREAD
singlePhotonDetector *mt=filter;
#endif
#ifndef ANALOG
mt->setDetectorMode(ePhotonCounting);
cout << "Counting!" << endl;
if (thr>0) {
cf=0;
}
#endif
//{
#ifdef ANALOG
mt->setDetectorMode(eAnalog);
cout << "Analog!" << endl;
cf=0;
//thr1=thr;
#endif
// }
#ifndef NOTHREAD
mt->StartThreads();
mt->popFree(buff);
#endif
DIR *dir;
struct dirent *ent;
// cout << "mt " << endl;
int ifr=0;
double ped[nx*ny];//, *ped1;
if (pedfile) {
cout << "PEDESTAL " << endl;
sprintf(imgfname,"%s/pedestals.tiff",outdir);
if (string(pedfile).find(".tif")==std::string::npos){
sprintf(fname,"%s.raw",pedfile);
cout << fname << endl ;
std::time(&end_time);
cout << "aaa" << std::ctime(&end_time) << endl;
mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun);
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()){
ff=-1;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
if (np==40) {
#ifdef NOTHREAD
mt->processData(buff);
#endif
#ifndef NOTHREAD
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
#endif
ifr++;
if (ifr%10000==0)
cout << ifr << " " << ff << " " << np << endl;
} else
cout << ifr << " " << ff << " " << np << endl;
ff=-1;
}
filebin.close();
#ifndef NOTHREAD
while (mt->isBusy()) {;}
#endif
} else
cout << "Could not open pedestal file "<< fname << " for reading " << endl;
} else {
float *pp=ReadFromTiff(pedfile, unny, unnx);
nny=unny;
nnx=unnx;
if (pp && nnx==nx && nny==ny) {
for (int i=0; i<nx*ny; i++) {
ped[i]=pp[i];
}
delete [] pp;
mt->setPedestal(ped);
// ped1=mt->getPedestal();
// for (int i=0; i<nx*ny; i++) {
// cout << ped[i]<<"/"<<ped1[i] << " " ;
// }
cout << "Pedestal set from tiff file " << pedfile << endl;
} else {
cout << "Could not open pedestal tiff file "<< pedfile << " for reading " << endl;
}
}
#ifdef NOTHREAD
mt->writePedestals(imgfname);
#endif
#ifndef NOTHREAD
mt->writePedestal(imgfname);
#endif
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
}
ifr=0;
int ifile=0;
char ext[100];
mt->setFrameMode(eFrame);
for (int irun=runmin; irun<=runmax; irun++) {
cout << "DATA " ;
// sprintf(fn,fformat,irun);
sprintf(ext,"_%d.raw",irun);
sprintf(imgfname,"%s/%s_%d.tiff",outdir,fformat,irun);
// sprintf(imgfname,ffname,irun);
sprintf(cfname,"%s/%s_%d.clust",outdir,fformat, irun);
//sprintf(cfname,ffname,irun);
cout << cfname << " " ;
cout << imgfname << endl;
if (thr<=0 && cf!=0) { //cluster finder
if (of==NULL) {
of=fopen(cfname,"w");
if (of) {
mt->setFilePointer(of);
cout << "file pointer set " << endl;
} else {
cout << "Could not open "<< cfname << " for writing " << endl;
mt->setFilePointer(NULL);
return 1;
}
}
}
if ((dir = opendir (indir)) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
// printf ("----------- %s\n", ent->d_name);
// printf ("************** %s", ent->d_name);
// cout << string(ent->d_name).find(fformat) << endl;
if (string(ent->d_name).find(string(fformat)+"_d0_f0")==0) {
// printf ("+++++++++++++++ %s\n", ent->d_name);
if (string(ent->d_name).find(ext)!= string::npos) {
//printf ("**************8 %s\n", ent->d_name);
sprintf(fname,"%s/%s",indir,ent->d_name);
//sprintf(fname,ffname,irun);
cout << fname << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
// cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
ifile=0;
if (filebin.is_open()){
// //while read frame
ff=-1;
ifr=0;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
if (np==40) {
#ifdef NOTHREAD
mt->processData(buff);
#endif
#ifndef NOTHREAD
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
#endif
ifr++;
if (ifr%10000==0) cout << ifr << " " << ff << endl;
if (nframes>0) {
#ifndef NOTHREAD
while (mt->isBusy()) {;}
#endif
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...)
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(imgfname,ffname,irun);
//cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
#ifdef NOTHREAD
mt->writeImage(imgfname);
#endif
#ifndef NOTHREAD
mt->writeImage(imgfname, thr1);
#endif
mt->clearImage();
ifile++;
}
}
}
ff=-1;
}
filebin.close();
} else
cout << "Could not open "<< fname << " for reading " << endl;
}
}
}
#ifndef NOTHREAD
while (mt->isBusy()) {;}
#endif
if (nframes>=0) {
if (nframes>0) {
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(imgfname,ffname,irun);
} else {
sprintf(imgfname,"%s/%s_%d.tiff",outdir,fformat,irun);
//sprintf(imgfname,ffname,irun);
}
cout << "Writing tiff to " << imgfname << " " << ifr <<endl;
#ifdef NOTHREAD
mt->writeImage(imgfname);
#endif
#ifndef NOTHREAD
mt->writeImage(imgfname, thr1);
#endif
mt->clearImage();
if (of) {
fclose(of);
of=NULL;
mt->setFilePointer(NULL);
}
}
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
closedir (dir);
} else {
/* could not open directory */
cout << "could not open directory " << indir << endl;
}
}
if (nframes<0){
sprintf(ffname,"%s/%s.tiff",outdir,fformat);
strcpy(imgfname,ffname);
cout << "Writing tiff to " << imgfname << " " << ifr <<endl;
#ifdef NOTHREAD
mt->writeImage(imgfname);
#endif
#ifndef NOTHREAD
mt->writeImage(imgfname, thr1);
#endif
}
sprintf(imgfname,"%s/%s_ped.tiff",outdir,fformat);
#ifdef NOTHREAD
mt->writePedestals(imgfname);
#endif
#ifndef NOTHREAD
mt->writePedestal(imgfname);
#endif
sprintf(imgfname,"%s/%s_noise.tiff",outdir,fformat);
mt->writePedestalRMS(imgfname);
return 0;
}

View File

@ -1,4 +1,4 @@
#define WRITE_QUAD //#define WRITE_QUAD
#define MOENCH_BRANCH #define MOENCH_BRANCH
#define C_GHOST 0.0004 #define C_GHOST 0.0004
@ -54,10 +54,11 @@ int main(int argc, char *argv[]) {
*/ */
FILE *of=NULL; FILE *of=NULL;
int fifosize=5000; int fifosize=5000;
int etabins=1000;//nsubpix*2*100; int etabins=1000, etabinsy=1000;//nsubpix*2*100;
double etamin=-1, etamax=2; double etamin=-1, etamax=2;
int nSubPixels=2; int nSubPixelsX=2;
// int emin, emax; // int emin, emax;
int nSubPixelsY=2;
// help // help
if (argc < 3 ) { if (argc < 3 ) {
cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number] [nthreads] [nsubpix] [gainmap] [etafile]\n"); cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number] [nthreads] [nsubpix] [gainmap] [etafile]\n");
@ -98,10 +99,14 @@ int main(int argc, char *argv[]) {
nthreads=atoi(argv[5]); nthreads=atoi(argv[5]);
cout << "Number of threads is: " << nthreads << endl; cout << "Number of threads is: " << nthreads << endl;
if (argc>6) if (argc>6) {
nSubPixels=atoi(argv[6]); nSubPixelsX=atoi(argv[6]);
cout << "Number of subpixels is: " << nSubPixels << endl; nSubPixelsY=nSubPixelsX;
#ifdef RECT
nSubPixelsX=2;
#endif
}
cout << "Number of subpixels is: " << nSubPixelsX << " " << nSubPixelsY << endl;
char *gainfname=NULL; char *gainfname=NULL;
if (argc>7) { if (argc>7) {
@ -134,8 +139,12 @@ int main(int argc, char *argv[]) {
int ncol_cm=CM_ROWS; int ncol_cm=CM_ROWS;
double xt_ghost=C_GHOST; double xt_ghost=C_GHOST;
moench03CommonMode *cm=new moench03CommonMode(ncol_cm); moench03CommonMode *cm=NULL;
moench03GhostSummation *gs=new moench03GhostSummation(det, xt_ghost); moench03GhostSummation *gs=NULL;
#ifdef CORR
gs=new moench03GhostSummation(det, xt_ghost);
cm=new moench03CommonMode(ncol_cm);
#endif
double *gainmap=NULL; double *gainmap=NULL;
float *gm; float *gm;
double *gmap=NULL; double *gmap=NULL;
@ -170,7 +179,7 @@ int main(int argc, char *argv[]) {
// multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); // multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
#endif #endif
#ifdef INTERP #ifdef INTERP
eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(npx, npy, nSubPixels, etabins, etamin, etamax); eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(npx, npy, nSubPixelsX,nSubPixelsY, etabins, etabinsy, etamin, etamax);
if (etafname) interp->readFlatField(etafname); if (etafname) interp->readFlatField(etafname);
@ -285,10 +294,10 @@ int main(int argc, char *argv[]) {
int iframe=0; int iframe=0;
char ofname[10000]; char ofname[10000];
char fname[10000]; string fname;
// int length; // int length;
int *detimage=NULL; int *detimage=NULL;
int nnx, nny,nns; int nnx, nny,nnsx, nnsy;
//uint32_t imageSize = 0, nPixelsX = 0, nPixelsY = 0, //uint32_t imageSize = 0, nPixelsX = 0, nPixelsY = 0,
//uint32_t dynamicRange = 0; //uint32_t dynamicRange = 0;
// infinite loop // infinite loop
@ -326,7 +335,7 @@ int main(int argc, char *argv[]) {
frameMode fMode=eFrame; frameMode fMode=eFrame;
double *ped; double *ped;
filter->getImageSize(nnx, nny,nns); filter->getImageSize(nnx, nny,nnsx, nnsy);
@ -355,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;
} }
@ -369,7 +379,7 @@ int main(int argc, char *argv[]) {
} else { } else {
send_something=0; send_something=0;
if (fMode==ePedestal) { if (fMode==ePedestal) {
sprintf(ofname,"%s_%ld_ped.tiff",fname,fileindex); sprintf(ofname,"%s_%ld_ped.tiff",fname.c_str(),fileindex);
mt->writePedestal(ofname); mt->writePedestal(ofname);
cout << "Writing pedestal to " << ofname << endl; cout << "Writing pedestal to " << ofname << endl;
send_something=1; send_something=1;
@ -377,7 +387,7 @@ int main(int argc, char *argv[]) {
#ifdef INTERP #ifdef INTERP
else if (fMode==eFlat) { else if (fMode==eFlat) {
mt->prepareInterpolation(ok); mt->prepareInterpolation(ok);
sprintf(ofname,"%s_%ld_eta.tiff",fname,fileindex); sprintf(ofname,"%s_%ld_eta.tiff",fname.c_str(),fileindex);
mt->writeFlatField(ofname); mt->writeFlatField(ofname);
cout << "Writing eta to " << ofname << endl; cout << "Writing eta to " << ofname << endl;
send_something=1; send_something=1;
@ -386,7 +396,7 @@ int main(int argc, char *argv[]) {
else { else {
if (subframes>0 ) { if (subframes>0 ) {
if (insubframe>0) { if (insubframe>0) {
sprintf(ofname,"%s_sf%ld_%ld.tiff",fname,nnsubframe,fileindex); sprintf(ofname,"%s_sf%ld_%ld.tiff",fname.c_str(),nnsubframe,fileindex);
// mt->writeImage(ofname); // mt->writeImage(ofname);
doutf= new float[nnx*nny]; doutf= new float[nnx*nny];
if (subframes>0 && insubframe!=subframes && insubframe>0) if (subframes>0 && insubframe!=subframes && insubframe>0)
@ -411,7 +421,7 @@ int main(int argc, char *argv[]) {
send_something=1; send_something=1;
} }
} else { } else {
sprintf(ofname,"%s_%ld.tiff",fname,fileindex); sprintf(ofname,"%s_%ld.tiff",fname.c_str(),fileindex);
mt->writeImage(ofname); mt->writeImage(ofname);
send_something=1; send_something=1;
} }
@ -424,11 +434,13 @@ int main(int argc, char *argv[]) {
if (fMode==ePedestal) { if (fMode==ePedestal) {
cprintf(MAGENTA,"Get pedestal!\n"); cprintf(MAGENTA,"Get pedestal!\n");
nns=1; nnsx=1;
nnsy=1;
nnx=npx; nnx=npx;
nny=npy; nny=npy;
//dout= new int16_t[nnx*nny*nns*nns]; //dout= new int16_t[nnx*nny*nns*nns];
dout= new int32_t[nnx*nny*nns*nns]; dout= new int32_t[nnx*nny*nnsx*nnsy];
// cout << "get pedestal " << endl; // cout << "get pedestal " << endl;
ped=mt->getPedestal(); ped=mt->getPedestal();
// cout << "got pedestal " << endl; // cout << "got pedestal " << endl;
@ -442,11 +454,11 @@ int main(int argc, char *argv[]) {
} }
#ifdef INTERP #ifdef INTERP
else if (fMode==eFlat) { else if (fMode==eFlat) {
int nb; int nb, nby;
double emi=0, ema=1; double emi=0, ema=1;
int *ff=mt->getFlatField(nb, emi, ema); int *ff=mt->getFlatField(nb, nby, emi, ema);
nnx=nb; nnx=nb;
nny=nb; nny=nby;
dout= new int32_t[nb*nb]; dout= new int32_t[nb*nb];
for (int ix=0; ix<nb*nb; ix++) { for (int ix=0; ix<nb*nb; ix++) {
dout[ix]=ff[ix]; dout[ix]=ff[ix];
@ -454,9 +466,9 @@ int main(int argc, char *argv[]) {
} }
#endif #endif
else { else {
detimage=mt->getImage(nnx,nny,nns); detimage=mt->getImage(nnx,nny,nnsx, nnsy);
cprintf(MAGENTA,"Get image!\n"); cprintf(MAGENTA,"Get image!\n");
cout << nnx << " " << nny << " " << nns << endl; cout << nnx << " " << nny << " " << nnsx << " " << nnsy << endl;
// nns=1; // nns=1;
// nnx=npx; // nnx=npx;
// nny=npy; // nny=npy;
@ -489,16 +501,16 @@ int main(int argc, char *argv[]) {
if(send_something) { if(send_something) {
#ifndef DEVELOPER #ifndef DEVELOPER
#ifndef MOENCH_BRANCH #ifndef MOENCH_BRANCH
zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, 0,0, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname, acqIndex,0 , packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, additionalJsonHeader); zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, 0,0, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname.c_str(), acqIndex,0 , packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, additionalJsonHeader);
#endif #endif
#endif #endif
#ifdef DEVELOPER #ifdef DEVELOPER
zmqsocket2->SendHeaderData (0, false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, 0,0,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname,acqIndex,0 , packetNumber,bunchId, timestamp, modId,xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, 0,additionalJsonHeader); zmqsocket2->SendHeaderData (0, false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, 0,0,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname.c_str(),acqIndex,0 , packetNumber,bunchId, timestamp, modId,xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, 0,additionalJsonHeader);
#endif #endif
#ifdef MOENCH_BRANCH #ifdef MOENCH_BRANCH
zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname, acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader); zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname.c_str(), acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader);
#endif #endif
@ -525,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
@ -560,8 +572,8 @@ int main(int argc, char *argv[]) {
//dataSize=size; //dataSize=size;
strcpy(fname,filename.c_str()); //strcpy(fname,filename.c_str());
fname=filename;
// cprintf(BLUE, "Header Info:\n" // cprintf(BLUE, "Header Info:\n"
// "size: %u\n" // "size: %u\n"
// "multisize: %u\n" // "multisize: %u\n"
@ -799,7 +811,7 @@ int main(int argc, char *argv[]) {
// timestamp=doc["timestamp"].GetUint(); // timestamp=doc["timestamp"].GetUint();
packetNumber=doc["packetNumber"].GetUint(); packetNumber=doc["packetNumber"].GetUint();
// cout << acqIndex << " " << frameIndex << " " << subFrameIndex << " "<< bunchId << " " << timestamp << " " << packetNumber << endl; // cout << acqIndex << " " << frameIndex << " " << subFrameIndex << " "<< bunchId << " " << timestamp << " " << packetNumber << endl;
if (packetNumber>=40) { if (packetNumber>0) {
//*((int*)buff)=frameIndex; //*((int*)buff)=frameIndex;
if (insubframe==0) f0=frameIndex; if (insubframe==0) f0=frameIndex;
memcpy(buff,&frameIndex,sizeof(int)); memcpy(buff,&frameIndex,sizeof(int));
@ -811,7 +823,7 @@ int main(int argc, char *argv[]) {
insubframe++; insubframe++;
nsubframes=frameIndex+1-f0; nsubframes=frameIndex+1-f0;
} else { } else {
cprintf(RED, "Incomplete frame: received only %d packet\n", packetNumber); cprintf(RED, "Empty frame %d\n", frameIndex);
//length = //length =
zmqsocket->ReceiveData(0, dummybuff, size); zmqsocket->ReceiveData(0, dummybuff, size);
} }
@ -821,7 +833,7 @@ int main(int argc, char *argv[]) {
if (subframes>0 && insubframe>=subframes && fMode==eFrame) { if (subframes>0 && insubframe>=subframes && fMode==eFrame) {
while (mt->isBusy()) {;}//wait until all data are processed from the queues while (mt->isBusy()) {;}//wait until all data are processed from the queues
detimage=mt->getImage(nnx,nny,nns); detimage=mt->getImage(nnx,nny,nnsx, nnsy);
cprintf(MAGENTA,"Get image!\n"); cprintf(MAGENTA,"Get image!\n");
dout= new int32_t[nnx*nny]; dout= new int32_t[nnx*nny];
doutf= new float[nnx*nny]; doutf= new float[nnx*nny];
@ -834,7 +846,7 @@ int main(int argc, char *argv[]) {
if (dout[ix]<0) dout[ix]=0; if (dout[ix]<0) dout[ix]=0;
doutf[ix]=dout[ix]; doutf[ix]=dout[ix];
} }
sprintf(ofname,"%s_sf%ld_%ld.tiff",fname,nnsubframe,fileindex); sprintf(ofname,"%s_sf%ld_%ld.tiff",fname.c_str(),nnsubframe,fileindex);
cout << "Writing image to " << ofname << endl; cout << "Writing image to " << ofname << endl;
@ -846,16 +858,16 @@ int main(int argc, char *argv[]) {
#ifndef DEVELOPER #ifndef DEVELOPER
#ifndef MOENCH_BRANCH #ifndef MOENCH_BRANCH
zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, 0,0, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname, acqIndex,0 , packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, additionalJsonHeader); zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, 0,0, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname.c_str(), acqIndex,0 , packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, additionalJsonHeader);
#endif #endif
#endif #endif
#ifdef DEVELOPER #ifdef DEVELOPER
zmqsocket2->SendHeaderData (0, false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, 0,0,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname,acqIndex,0 , packetNumber,bunchId, timestamp, modId,xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, 0,additionalJsonHeader); zmqsocket2->SendHeaderData (0, false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, 0,0,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname.c_str(),acqIndex,0 , packetNumber,bunchId, timestamp, modId,xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, 0,additionalJsonHeader);
#endif #endif
#ifdef MOENCH_BRANCH #ifdef MOENCH_BRANCH
zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname, acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader); zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname.c_str(), acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader);
#endif #endif

View File

@ -95,7 +95,7 @@ public:
virtual int *getImage() { virtual int *getImage() {
return det->getImage(); return det->getImage();
} }
virtual int getImageSize(int &nnx, int &nny, int &ns) {return det->getImageSize(nnx, nny, ns);}; virtual int getImageSize(int &nnx, int &nny, int &nsx,int &nsy) {return det->getImageSize(nnx, nny, nsx, nsy);};
virtual int getDetectorSize(int &nnx, int &nny) {return det->getDetectorSize(nnx, nny);}; virtual int getDetectorSize(int &nnx, int &nny) {return det->getDetectorSize(nnx, nny);};
virtual ~threadedAnalogDetector() {StopThread(); delete fifoFree; delete fifoData;} virtual ~threadedAnalogDetector() {StopThread(); delete fifoFree; delete fifoData;}
@ -208,11 +208,11 @@ FILE *getFilePointer(){return det->getFilePointer();};
return NULL; return NULL;
} }
virtual int *getFlatField(int &nb, double emi, double ema){ virtual int *getFlatField(int &nb, int &nby, double emi, double ema){
slsInterpolation *interp=(det)->getInterpolation(); slsInterpolation *interp=(det)->getInterpolation();
int *ff=NULL; int *ff=NULL;
if (interp) { if (interp) {
ff=interp->getFlatField(nb,emi,ema); ff=interp->getFlatField(nb,nby,emi,ema);
} }
return ff; return ff;
} }
@ -320,33 +320,41 @@ public:
virtual void newDataSet(){for (int i=0; i<nThreads; i++) dets[i]->newDataSet();}; virtual void newDataSet(){for (int i=0; i<nThreads; i++) dets[i]->newDataSet();};
virtual int *getImage(int &nnx, int &nny, int &ns) { virtual int *getImage(int &nnx, int &nny, int &ns, int &nsy) {
int *img; int *img;
cout << "get image "<< image << endl;
// int nnx, nny, ns; // int nnx, nny, ns;
// int nnx, nny, ns; // int nnx, nny, ns;
int nn=dets[0]->getImageSize(nnx, nny,ns); int nn=dets[0]->getImageSize(nnx, nny,ns, nsy);
if (image) { if (image) {
delete image; cout << "del image "<< image << endl;
delete [] image;
image=NULL; image=NULL;
} }
image=new int[nn]; image=new int[nn];
cout << "new image" << image << endl;
//int nn=dets[0]->getImageSize(nnx, nny, ns); //int nn=dets[0]->getImageSize(nnx, nny, ns);
//for (i=0; i<nn; i++) image[i]=0; //for (i=0; i<nn; i++) image[i]=0;
if (image) {
for (int ii=0; ii<nThreads; ii++) { for (int ii=0; ii<nThreads; ii++) {
//cout << ii << " " << nn << " " << nnx << " " << nny << " " << ns << endl; cout << ii << " " << nn << " " << nnx << " " << nny << " " << nsy << endl;
img=dets[ii]->getImage(); img=dets[ii]->getImage();
for (int i=0; i<nn; i++) { for (int i=0; i<nn; i++) {
if (ii==0) if (ii==0)
// if (img[i]>0) // if (img[i]>0)
image[i]=img[i]; image[i]=img[i];
// else // else
// image[i]=0; // image[i]=0;
else //if (img[i]>0) else //if (img[i]>0)
image[i]+=img[i]; image[i]+=img[i];
//if (img[i]) cout << "det " << ii << " pix " << i << " val " << img[i] << " " << image[i] << endl; /***
gdb runtime error
../multiThreadedAnalogDetector.h:349:14: runtime error: signed integer overflow: -1094794611 + -1094795013 cannot be rep
**/
//if (img[i]) cout << "det " << ii << " pix " << i << " val " << img[i] << " " << image[i] << endl;
}
} }
} }
return image; return image;
@ -369,29 +377,32 @@ public:
/* dets[ii]->writeImage(tit); */ /* dets[ii]->writeImage(tit); */
/* } */ /* } */
/* #endif */ /* #endif */
int nnx, nny, ns; cout << "write image" << endl;
getImage(nnx, nny, ns); int nnx, nny, ns, nsy;
getImage(nnx, nny, ns, nsy);
//int nnx, nny, ns; //int nnx, nny, ns;
int nn=dets[0]->getImageSize(nnx, nny, ns); int nn=dets[0]->getImageSize(nnx, nny, ns, nsy);
float *gm=new float[nn]; float *gm=new float[nn];
if (gm) { if (gm) {
for (int ix=0; ix<nn; ix++) { for (int ix=0; ix<nn; ix++) {
if (t) { if (t) {
if (image[ix]<0) if (image[ix]<0)
gm[ix]=0; gm[ix]=0;
else else
gm[ix]=(image[ix])/t; gm[ix]=(image[ix])/t;
} else } else
gm[ix]=image[ix]; gm[ix]=image[ix];
//if (image[ix]>0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl; //if (image[ix]>0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl;
} }
//cout << "image " << nnx << " " << nny << endl; cout << "image " << nnx << " " << nny << endl;
WriteToTiff(gm,imgname ,nnx, nny); WriteToTiff(gm,imgname ,nnx, nny);
delete [] gm; cout << imgname << endl;
} else cout << "Could not allocate float image " << endl; delete [] gm;
return NULL; cout << "del" << endl;
} } else cout << "Could not allocate float image " << endl;
return NULL;
}
virtual void StartThreads() { virtual void StartThreads() {
@ -468,6 +479,37 @@ public:
return ped; return ped;
}; };
virtual double *getPedestalRMS(){
int nx, ny;
dets[0]->getDetectorSize(nx,ny);
double *rms=new double[nx*ny];
double *p0=new double[nx*ny];
for (int i=0; i<nThreads; i++) {
//inte=(slsInterpolation*)dets[i]->getInterpolation(nb,emi,ema);
// cout << i << endl;
p0=dets[i]->getPedestalRMS(p0);
if (p0) {
if (i==0) {
for (int ib=0; ib<nx*ny; ib++) {
rms[ib]=p0[ib]/((double)nThreads);
// cout << p0[ib] << " ";
}
} else {
for (int ib=0; ib<nx*ny; ib++) {
rms[ib]+=p0[ib]/((double)nThreads);
// cout << p0[ib] << " ";
}
}
}
}
delete [] p0;
return rms;
};
virtual double *setPedestal(double *h=NULL){ virtual double *setPedestal(double *h=NULL){
//int nb=0; //int nb=0;
@ -504,6 +546,26 @@ public:
}; };
virtual void *writePedestalRMS(const char * imgname){
int nx, ny;
dets[0]->getDetectorSize(nx,ny);
double *rms=getPedestalRMS();
float *gm=new float[nx*ny];
if (gm) {
for (int ix=0; ix<nx*ny; ix++) {
gm[ix]=rms[ix];
}
WriteToTiff(gm,imgname ,nx, ny);
delete [] gm;
delete [] rms;
} else cout << "Could not allocate float image " << endl;
return NULL;
};
virtual void *readPedestal(const char * imgname, int nb=-1, double emin=1, double emax=0){ virtual void *readPedestal(const char * imgname, int nb=-1, double emin=1, double emax=0){
@ -560,7 +622,7 @@ public:
int *ff; int *ff;
double *ped; double *ped;
pthread_mutex_t fmutex; pthread_mutex_t fmutex;
}; };
#endif #endif

View File

@ -28,8 +28,8 @@ public:
return (dets[0])->getFlatField(); return (dets[0])->getFlatField();
} }
virtual int *getFlatField(int &nb, double emi, double ema){ virtual int *getFlatField(int &nb, int &nby, double emi, double ema){
return (dets[0])->getFlatField(nb,emi,ema); return (dets[0])->getFlatField(nb,nby,emi,ema);
} }
virtual int *setFlatField(int *h=NULL, int nb=-1, double emin=1, double emax=0){ virtual int *setFlatField(int *h=NULL, int nb=-1, double emin=1, double emax=0){
@ -46,7 +46,7 @@ public:
}; };
virtual int setNSubPixels(int ns) { return (dets[0])->setNSubPixels(ns);}; /* virtual int setNSubPixels(int ns) { return (dets[0])->setNSubPixels(ns);}; */
virtual void resetFlatField() {(dets[0])->resetFlatField();}; virtual void resetFlatField() {(dets[0])->resetFlatField();};
@ -69,15 +69,15 @@ public:
virtual int *getImage(int &nnx, int &nny, int &ns) { virtual int *getImage(int &nnx, int &nny, int &nsx, int &nsy) {
if (getInterpolation()==NULL) return multiThreadedAnalogDetector::getImage(nnx,nny,ns); if (getInterpolation()==NULL) return multiThreadedAnalogDetector::getImage(nnx,nny,nsx, nsy);
//if one interpolates, the whole image is stored in detector 0; //if one interpolates, the whole image is stored in detector 0;
int *img; int *img;
// int nnx, nny, ns; // int nnx, nny, ns;
// int nnx, nny, ns; // int nnx, nny, ns;
int nn=dets[0]->getImageSize(nnx, nny,ns); int nn=dets[0]->getImageSize(nnx, nny,nsx, nsy);
if (image) { if (image) {
delete image; delete [] image;
image=NULL; image=NULL;
} }
image=new int[nn]; image=new int[nn];

View File

@ -4,7 +4,7 @@
#include "analogDetector.h" #include "analogDetector.h"
#include "single_photon_hit.h" #include "single_photon_hit.h"
#include <mutex>
//#define MYROOT1 //#define MYROOT1
@ -62,13 +62,10 @@ public analogDetector<uint16_t> {
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;
@ -117,6 +111,9 @@ public analogDetector<uint16_t> {
setClusterSize(clusterSize); setClusterSize(clusterSize);
fm=orig->fm; fm=orig->fm;
//setMutex(orig->fm);
quad=UNDEFINED_QUADRANT; quad=UNDEFINED_QUADRANT;
tot=0; tot=0;
@ -182,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
@ -218,19 +215,19 @@ public analogDetector<uint16_t> {
cout << "add to common mode?"<< endl; cout << "add to common mode?"<< endl;
addToCommonMode(data); addToCommonMode(data);
} }
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 (det->isGood(ix,iy)) { if (det->isGood(ix,iy)) {
val=subtractPedestal(data,ix,iy, cm); val=subtractPedestal(data,ix,iy, cm);
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;
} }
} }
@ -240,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;
@ -249,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)
@ -276,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;
@ -289,9 +287,9 @@ public analogDetector<uint16_t> {
quadTot=tl; quadTot=tl;
} else if (tr>=bl && tr>=tl && tr>=br) { } else if (tr>=bl && tr>=tl && tr>=br) {
quad=TOP_RIGHT; quad=TOP_RIGHT;
quadTot=tr; quadTot=tr;
} }
if (nSigma==0) { if (nSigma==0) {
tthr=thr; tthr=thr;
tthr1=thr; tthr1=thr;
@ -312,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++;
@ -322,9 +320,8 @@ public analogDetector<uint16_t> {
} }
} }
} }
}
}
} }
}
} else return getClusters(data, nph); } else return getClusters(data, nph);
} }
return NULL; return NULL;
@ -346,11 +343,11 @@ 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;
int iframe=det->getFrameNumber(data);
double max=0, tl=0, tr=0, bl=0,br=0, *v; double max=0, tl=0, tr=0, bl=0,br=0, *v;
int cm=0; int cm=0;
int good=1; int good=1;
@ -366,12 +363,12 @@ int *getClusters(char *data, int *ph=NULL) {
if (cm) if (cm) {
addToCommonMode(data); addToCommonMode(data);
}
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 (det->isGood(ix,iy)) { if (det->isGood(ix,iy)) {
max=0; max=0;
tl=0; tl=0;
@ -384,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);
@ -394,35 +391,40 @@ 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)>=iy && (iy+ir)<ny && (ix+ic)>=ix && (ix+ic)<nx) { if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) {
val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm); if ((iy+ir)>=iy &&(ix+ic)>=ix)
} val[(iy+ir)*nx+ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm);
v=&(val[iy+ir][ix+ic]); (clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir);
tot+=*v;
if (ir<=0 && ic<=0) v=&(val[(iy+ir)*nx+ix+ic]);
bl+=*v; tot+=*v;
if (ir<=0 && ic>=0) if (ir<=0 && ic<=0)
br+=*v; bl+=*v;
if (ir>=0 && ic<=0) if (ir<=0 && ic>=0)
tl+=*v; br+=*v;
if (ir>=0 && ic>=0) if (ir>=0 && ic<=0)
tr+=*v; tl+=*v;
if (*v>max) { if (ir>=0 && ic>=0)
max=*v; tr+=*v;
} if (*v>max) {
max=*v;
}
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
(clusters+nph)->set_data(0,ic,ir);
} }
} }
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) {
@ -430,7 +432,7 @@ int *getClusters(char *data, int *ph=NULL) {
(clusters+nph)->quadTot=bl; (clusters+nph)->quadTot=bl;
} else if (br>=bl && br>=tl && br>=tr) { } else if (br>=bl && br>=tl && br>=tr) {
(clusters+nph)->quad=BOTTOM_RIGHT; (clusters+nph)->quad=BOTTOM_RIGHT;
(clusters+nph)->quadTot=br; (clusters+nph)->quadTot=br;
} else if (tl>=br && tl>=bl && tl>=tr) { } else if (tl>=br && tl>=bl && tl>=tr) {
(clusters+nph)->quad=TOP_LEFT; (clusters+nph)->quad=TOP_LEFT;
(clusters+nph)->quadTot=tl; (clusters+nph)->quadTot=tl;
@ -438,34 +440,36 @@ int *getClusters(char *data, int *ph=NULL) {
(clusters+nph)->quad=TOP_RIGHT; (clusters+nph)->quad=TOP_RIGHT;
(clusters+nph)->quadTot=tr; (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 (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;
// (clusters+nph)->iframe=det->getFrameNumber(data); (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); // (clusters+nph)->ped=getPedestal(ix,iy,0);
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++) {
(clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); // if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx)
// (clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir);
// else
// (clusters+nph)->set_data(0,ic,ir);
// }
// }
good=1;
if (eMin>0 && tot<eMin) good=0;
if (eMax>0 && tot>eMax) good=0;
if (good) {
nph++;
image[iy*nx+ix]++;
} }
}
good=1;
if (eMin>0 && tot<eMin) good=0;
if (eMax>0 && tot>eMax) good=0;
if (good) {
nph++;
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);
} }
} }
@ -474,8 +478,9 @@ int *getClusters(char *data, int *ph=NULL) {
nphFrame=nph; nphFrame=nph;
nphTot+=nph; nphTot+=nph;
//cout << nphFrame << endl; //cout << nphFrame << endl;
// cout <<"**********************************"<< det->getFrameNumber(data) << " " << nphFrame << endl; if (iframe%10000==0)
writeClusters(det->getFrameNumber(data)); cout <<"**********************************"<< iframe << " " << nphFrame << endl;
writeClusters(iframe);
return image; return image;
}; };
@ -517,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
@ -566,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 */
for (int i=0; i<nph; i++) (cl+i)->write(f); if (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);
@ -576,12 +583,15 @@ int *getClusters(char *data, int *ph=NULL) {
void writeClusters(int fn){ void writeClusters(int fn){
if (myFile) { if (myFile) {
//cout << "++" << endl; //cout << "++" << endl;
pthread_mutex_lock(fm); //pthread_mutex_lock(fm);
// cout <<"**********************************"<< fn << " " << nphFrame << endl; fm->lock();
// cout <<id << " **********************************"<< fn << " " << nphFrame << endl;
writeClusters(myFile,clusters,nphFrame, fn); writeClusters(myFile,clusters,nphFrame, fn);
// for (int i=0; i<nphFrame; i++) // for (int i=0; i<nphFrame; i++)
// (clusters+i)->write(myFile); // (clusters+i)->write(myFile);
pthread_mutex_unlock(fm); // cout << "--" << endl;
fm->unlock();
//pthread_mutex_unlock(fm);
//cout << "--" << endl; //cout << "--" << endl;
} }
}; };
@ -613,12 +623,13 @@ int *getClusters(char *data, int *ph=NULL) {
void setEnergyRange(double emi, double ema){eMin=emi; eMax=ema;}; void setEnergyRange(double emi, double ema){eMin=emi; eMax=ema;};
void getEnergyRange(double &emi, double &ema){emi=eMin; ema=eMax;}; void getEnergyRange(double &emi, double &ema){emi=eMin; ema=eMax;};
void setMutex(pthread_mutex_t *m){fm=m;}; // void setMutex(pthread_mutex_t *m){fm=m;};
void setMutex(mutex *m){fm=m;};
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 */
@ -631,8 +642,8 @@ int *getClusters(char *data, int *ph=NULL) {
int nphTot; int nphTot;
int nphFrame; int nphFrame;
pthread_mutex_t *fm; // pthread_mutex_t *fm;
mutex *fm;
}; };

View File

@ -44,8 +44,8 @@ class single_photon_hit {
//#endif //#endif
#ifndef WRITE_QUAD #ifndef WRITE_QUAD
//printf("no quad "); //printf("no quad ");
if (fwrite((void*)&x, 2, sizeof(int16_t), myFile)) if (fwrite((void*)&x, sizeof(int16_t), 2, myFile))
return fwrite((void*)data, 1, dx*dy*sizeof(int), myFile); return fwrite((void*)data, sizeof(int),dx*dy, myFile);
#endif #endif
#ifdef WRITE_QUAD #ifdef WRITE_QUAD
// printf("quad "); // printf("quad ");
@ -91,8 +91,8 @@ class single_photon_hit {
default: default:
; ;
} }
if (fwrite((void*)&x, 2, sizeof(int16_t), myFile)) if (fwrite((void*)&x, sizeof(int16_t), 2, myFile))
return fwrite((void*)qq, 1, 4*sizeof(int), myFile); return fwrite((void*)qq, sizeof(int), 4, myFile);
#endif #endif
return 0; return 0;
}; };
@ -110,53 +110,53 @@ class single_photon_hit {
#ifndef WRITE_QUAD #ifndef WRITE_QUAD
// printf( "no quad \n"); // printf( "no quad \n");
if (fread((void*)&x, 2, sizeof(int16_t), myFile)) if (fread((void*)&x, 2, sizeof(int16_t), myFile))
return fread((void*)data, 1, dx*dy*sizeof(int), myFile); return fread((void*)data,sizeof(int), dx*dy, myFile);
#endif #endif
#ifdef WRITE_QUAD #ifdef WRITE_QUAD
int qq[4]; int qq[4];
// printf( "quad \n"); // printf( "quad \n");
if (fread((void*)&x, 2, sizeof(int16_t), myFile)) if (fread((void*)&x, sizeof(int16_t), 2, myFile))
if (fread((void*)qq, 1, 4*sizeof(int), myFile)) { if (fread((void*)qq, sizeof(int), 4, myFile)) {
quad=TOP_RIGHT; quad=TOP_RIGHT;
/* int mm=qq[0]; */ int mm=qq[0];
/* for (int i=1; i<4; i++) { */ for (int i=1; i<4; i++) {
/* if (qq[i]>mm) { */ if (qq[i]>mm) {
/* switch (i) { */ switch (i) {
/* case 1: */ case 1:
/* quad=TOP_LEFT; */ quad=TOP_LEFT;
/* break; */ break;
/* case 2: */ case 2:
/* quad=BOTTOM_RIGHT; */ quad=BOTTOM_RIGHT;
/* break; */ break;
/* case 3: */ case 3:
/* quad=BOTTOM_LEFT; */ quad=BOTTOM_LEFT;
/* break; */ break;
/* default: */ default:
/* ; */ ;
/* } */ }
mm=qq[i];
}
/* } */ }
/* } */
/* switch(quad) { */ switch(quad) {
/* case TOP_LEFT: */ case TOP_LEFT:
/* data[0]=0; */ data[0]=0;
/* data[1]=0; */ data[1]=0;
/* data[2]=0; */ data[2]=0;
/* data[3]=qq[0]; */ data[3]=qq[0];
/* data[4]=qq[1]; */ data[4]=qq[1];
/* data[5]=0; */ data[5]=0;
/* data[6]=qq[2]; */ data[6]=qq[2];
/* data[7]=qq[3]; */ data[7]=qq[3];
/* data[8]=0; */ data[8]=0;
/* x=x+1; */ x=x+1;
/* y=y; */ y=y;
/* break; */ break;
/* case TOP_RIGHT: */ case TOP_RIGHT:
data[0]=0; data[0]=0;
data[1]=0; data[1]=0;
data[2]=0; data[2]=0;
@ -168,40 +168,40 @@ class single_photon_hit {
data[8]=qq[3]; data[8]=qq[3];
x=x; x=x;
y=y; y=y;
/* break; */ break;
/* case BOTTOM_LEFT: */ case BOTTOM_LEFT:
/* data[0]=qq[0]; */ data[0]=qq[0];
/* data[1]=qq[1]; */ data[1]=qq[1];
/* data[2]=0; */ data[2]=0;
/* data[3]=qq[2]; */ data[3]=qq[2];
/* data[4]=qq[3]; */ data[4]=qq[3];
/* data[5]=0; */ data[5]=0;
/* data[6]=0; */ data[6]=0;
/* data[7]=0; */ data[7]=0;
/* data[8]=0; */ data[8]=0;
/* x=x+1; */ x=x+1;
/* y=y+1; */ y=y+1;
/* break; */ break;
/* case BOTTOM_RIGHT: */ case BOTTOM_RIGHT:
/* data[0]=0; */ data[0]=0;
/* data[1]=qq[0]; */ data[1]=qq[0];
/* data[2]=qq[1]; */ data[2]=qq[1];
/* data[3]=0; */ data[3]=0;
/* data[4]=qq[2]; */ data[4]=qq[2];
/* data[5]=qq[3]; */ data[5]=qq[3];
/* data[6]=0; */ data[6]=0;
/* data[7]=0; */ data[7]=0;
/* data[8]=0; */ data[8]=0;
/* x=x; */ x=x;
/* y=y+1; */ y=y+1;
/* break; */ break;
/* default: */ default:
/* ; */ ;
/* } */ }
return 1; return 1;
} }
#endif #endif
@ -210,7 +210,10 @@ class single_photon_hit {
}; };
void print() { void print() {
#ifdef WRITE_QUAD
printf("Q");
#endif
// int ix, iy; // int ix, iy;
printf("*** %d %d %d\n",iframe, x, y); printf("*** %d %d %d\n",iframe, x, y);
for (int iy=0; iy<dy; iy++) { for (int iy=0; iy<dy; iy++) {

View File

@ -6,7 +6,7 @@
CROSS = bfin-uclinux- CROSS = bfin-uclinux-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1 -DCTB CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1 -DCTB -DOLDVERSION
PROGS= jctbDetectorServer PROGS= jctbDetectorServer

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/jctbDetectorServer Path: slsDetectorsPackage/slsDetectorSoftware/jctbDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: 9e5ec6a57bf206fe9384260fc4040867a9bbd71c Repsitory UUID: 53ba22dbc40d17c8ca77647d4ca2edad230f9f8a
Revision: 33 Revision: 34
Branch: developer Branch: moench
Last Changed Author: Erik_Frojdh Last Changed Author: Anna_Bergamaschi
Last Changed Rev: 4065 Last Changed Rev: 4088
Last Changed Date: 2019-01-30 17:38:35.000000002 +0100 ./firmware_funcs.c Last Changed Date: 2020-02-19 12:03:18.000000002 +0100 ./Makefile

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "9e5ec6a57bf206fe9384260fc4040867a9bbd71c" #define GITREPUUID "53ba22dbc40d17c8ca77647d4ca2edad230f9f8a"
#define GITAUTH "Erik_Frojdh" #define GITAUTH "Anna_Bergamaschi"
#define GITREV 0x4065 #define GITREV 0x4088
#define GITDATE 0x20190130 #define GITDATE 0x20200219
#define GITBRANCH "developer" #define GITBRANCH "moench"

View File

@ -4952,6 +4952,9 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
cout << "Destroyed Receiving Data Socket(s)" << endl; cout << "Destroyed Receiving Data Socket(s)" << endl;
return OK; return OK;
} }
if (client_downstream) {
return OK;
}
cprintf(MAGENTA, "Going to create data sockets\n"); cprintf(MAGENTA, "Going to create data sockets\n");

View File

@ -3242,13 +3242,13 @@ string slsDetector::getSettingsDir() {
return std::string(thisDetector->settingsDir); return std::string(thisDetector->settingsDir);
} }
string slsDetector::setSettingsDir(string s) { string slsDetector::setSettingsDir(string s) {
sprintf(thisDetector->settingsDir, s.c_str()); return thisDetector->settingsDir; sprintf(thisDetector->settingsDir, "%s", s.c_str()); return thisDetector->settingsDir;
} }
string slsDetector::getCalDir() { string slsDetector::getCalDir() {
return thisDetector->calDir; return thisDetector->calDir;
} }
string slsDetector::setCalDir(string s) { string slsDetector::setCalDir(string s) {
sprintf(thisDetector->calDir, s.c_str()); return thisDetector->calDir; sprintf(thisDetector->calDir, "%s", s.c_str()); return thisDetector->calDir;
} }
@ -4110,10 +4110,13 @@ int slsDetector::configureMAC() {
//converting IPaddress to hex //converting IPaddress to hex
stringstream ss(arg[0]); stringstream ss(arg[0]);
char cword[50]=""; char cword[50]="";
bzero(cword, 50); memset(cword, 0, sizeof(cword));
string s; string s;
while (getline(ss, s, '.')) { while (getline(ss, s, '.')) {
sprintf(cword,"%s%02x",cword,atoi(s.c_str())); char temp[20]="";
memset(temp, 0, sizeof(temp));
sprintf(temp,"%02x",atoi(s.c_str()));
strcat(cword, temp);
} }
bzero(arg[0], 50); bzero(arg[0], 50);
strcpy(arg[0],cword); strcpy(arg[0],cword);
@ -4126,12 +4129,12 @@ int slsDetector::configureMAC() {
//converting MACaddress to hex //converting MACaddress to hex
stringstream ss(arg[1]); stringstream ss(arg[1]);
char cword[50]=""; char cword[50]="";
bzero(cword, 50); memset(cword, 0, sizeof(cword));
string s; string s;
while (getline(ss, s, ':')) { while (getline(ss, s, ':')) {
sprintf(cword,"%s%s",cword,s.c_str()); strcat(cword, s.c_str());
} }
bzero(arg[1], 50); memset(arg[1], 0, sizeof(arg[1]));
strcpy(arg[1],cword); strcpy(arg[1],cword);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"receiver mac:"<<arg[1]<<"."<<std::endl; std::cout<<"receiver mac:"<<arg[1]<<"."<<std::endl;
@ -4145,12 +4148,12 @@ int slsDetector::configureMAC() {
{ {
stringstream ss(arg[3]); stringstream ss(arg[3]);
char cword[50]=""; char cword[50]="";
bzero(cword, 50); memset(cword, 0, sizeof(cword));
string s; string s;
while (getline(ss, s, ':')) { while (getline(ss, s, ':')) {
sprintf(cword,"%s%s",cword,s.c_str()); strcat(cword, s.c_str());
} }
bzero(arg[3], 50); memset(arg[3], 0, sizeof(arg[3]));
strcpy(arg[3],cword); strcpy(arg[3],cword);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"detecotor mac:"<<arg[3]<<"."<<std::endl; std::cout<<"detecotor mac:"<<arg[3]<<"."<<std::endl;
@ -4161,12 +4164,15 @@ int slsDetector::configureMAC() {
//converting IPaddress to hex //converting IPaddress to hex
stringstream ss(arg[4]); stringstream ss(arg[4]);
char cword[50]=""; char cword[50]="";
bzero(cword, 50); memset(cword, 0, sizeof(cword));
string s; string s;
while (getline(ss, s, '.')) { while (getline(ss, s, '.')) {
sprintf(cword,"%s%02x",cword,atoi(s.c_str())); char temp[20]="";
memset(temp, 0, sizeof(temp));
sprintf(temp,"%02x",atoi(s.c_str()));
strcat(cword, temp);
} }
bzero(arg[4], 50); memset(arg[4], 0, sizeof(arg[4]));
strcpy(arg[4],cword); strcpy(arg[4],cword);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"detector ip:"<<arg[4]<<"."<<std::endl; std::cout<<"detector ip:"<<arg[4]<<"."<<std::endl;
@ -4426,7 +4432,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index, int imod) {
int fnum=F_GET_TIME_LEFT; int fnum=F_GET_TIME_LEFT;
int64_t retval; int64_t retval = FAIL;
char mess[MAX_STR_LENGTH]=""; char mess[MAX_STR_LENGTH]="";
int ret=OK; int ret=OK;
@ -6051,8 +6057,10 @@ int slsDetector::setUDPConnection() {
std::cout << "could not configure mac" << endl; std::cout << "could not configure mac" << endl;
} }
} }
}else }else{
ret=FAIL; ret=FAIL;
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
}
#ifdef VERBOSE #ifdef VERBOSE
printReceiverConfiguration(); printReceiverConfiguration();
#endif #endif

View File

@ -846,6 +846,7 @@ virtual int enableDataStreamingFromReceiver(int enable=-1)=0;
case RUNNING: return std::string("running");\ case RUNNING: return std::string("running");\
case TRANSMITTING: return std::string("data"); \ case TRANSMITTING: return std::string("data"); \
case RUN_FINISHED: return std::string("finished"); \ case RUN_FINISHED: return std::string("finished"); \
case STOPPED: return std::string("stopped"); \
default: return std::string("idle"); \ default: return std::string("idle"); \
}}; }};

View File

@ -64,9 +64,12 @@ int slsDetectorUtils::acquire(int delflag){
if(!receiver){ if(!receiver){
setDetectorIndex(-1); setDetectorIndex(-1);
} }
pthread_mutex_lock(&mg);
int nc=setTimer(CYCLES_NUMBER,-1); int nc=setTimer(CYCLES_NUMBER,-1);
int nf=setTimer(FRAME_NUMBER,-1); int nf=setTimer(FRAME_NUMBER,-1);
pthread_mutex_unlock(&mg);
if (nc==0) nc=1; if (nc==0) nc=1;
if (nf==0) nf=1; if (nf==0) nf=1;
int multiframe = nc*nf; int multiframe = nc*nf;

View File

@ -93,7 +93,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
*/ */
virtual std::string setFilePath(std::string s) { virtual std::string setFilePath(std::string s) {
pthread_mutex_lock(&mf); pthread_mutex_lock(&mf);
sprintf(filePath, s.c_str()); sprintf(filePath, "%s", s.c_str());
pthread_mutex_unlock(&mf); pthread_mutex_unlock(&mf);
return std::string(filePath); return std::string(filePath);
}; };

View File

@ -151,6 +151,7 @@ void* ThreadPool::execute_thread(){
int ThreadPool::add_task(Task* task){ int ThreadPool::add_task(Task* task){
if(m_pool_size == 1){ if(m_pool_size == 1){
(*task)(); (*task)();
delete task;
return 0; return 0;
} }
m_task_mutex.lock(); m_task_mutex.lock();

View File

@ -106,4 +106,4 @@ install(TARGETS slsReceiverShared slsReceiverStatic slsReceiver
install(FILES ${ZMQ_STATIC_ARCHIVE} install(FILES ${ZMQ_STATIC_ARCHIVE}
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`)

View File

@ -206,7 +206,7 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
uint64_t firstMeasurementIndex; uint64_t firstMeasurementIndex;
/* File name to stream */ /* File name to stream */
char fileNametoStream[MAX_STR_LENGTH]; std::string fileNametoStream;
/** Complete buffer used for roi, eg. shortGotthard */ /** Complete buffer used for roi, eg. shortGotthard */
char* completeBuffer; char* completeBuffer;

View File

@ -56,8 +56,10 @@ public:
(ConvertInternetAddresstoIpString(result, ip, MAX_STR_LENGTH))) (ConvertInternetAddresstoIpString(result, ip, MAX_STR_LENGTH)))
throw std::exception(); throw std::exception();
std::string sip(ip);
// construct address // construct address
sprintf (sockfd.serverAddress, "tcp://%s:%d", ip, portno); sprintf (sockfd.serverAddress, "tcp://%s:%d", sip.c_str(), portno);
#ifdef VERBOSE #ifdef VERBOSE
cprintf(BLUE,"address:%s\n",sockfd.serverAddress); cprintf(BLUE,"address:%s\n",sockfd.serverAddress);
#endif #endif
@ -245,7 +247,7 @@ public:
*/ */
int SendHeaderData ( int index, bool dummy, uint32_t jsonversion, uint32_t dynamicrange = 0, uint64_t fileIndex = 0, int SendHeaderData ( int index, bool dummy, uint32_t jsonversion, uint32_t dynamicrange = 0, uint64_t fileIndex = 0,
uint32_t npixelsx = 0, uint32_t npixelsy = 0, uint32_t imageSize = 0, uint32_t npixelsx = 0, uint32_t npixelsy = 0, uint32_t imageSize = 0,
uint64_t acqIndex = 0, uint64_t fIndex = 0, char* fname = NULL, uint64_t acqIndex = 0, uint64_t fIndex = 0, std::string fname = "",
uint64_t frameNumber = 0, uint32_t expLength = 0, uint32_t packetNumber = 0, uint64_t frameNumber = 0, uint32_t expLength = 0, uint32_t packetNumber = 0,
uint64_t bunchId = 0, uint64_t timestamp = 0, uint64_t bunchId = 0, uint64_t timestamp = 0,
uint16_t modId = 0, uint16_t row = 0, uint16_t column = 0, uint16_t reserved = 0, uint16_t modId = 0, uint16_t row = 0, uint16_t column = 0, uint16_t reserved = 0,
@ -286,9 +288,9 @@ public:
"\"flippedDataX\":%u" "\"flippedDataX\":%u"
;//"}\n"; ;//"}\n";
int length = sprintf(buf, jsonHeaderFormat, sprintf(buf, jsonHeaderFormat,
jsonversion, dynamicrange, fileIndex, npixelsx, npixelsy, imageSize, jsonversion, dynamicrange, fileIndex, npixelsx, npixelsy, imageSize,
acqIndex, fIndex, (fname == NULL)? "":fname, dummy?0:1, acqIndex, fIndex, fname.c_str(), dummy?0:1,
frameNumber, expLength, packetNumber, bunchId, timestamp, frameNumber, expLength, packetNumber, bunchId, timestamp,
modId, row, column, reserved, debug, roundRNumber, modId, row, column, reserved, debug, roundRNumber,
@ -298,10 +300,12 @@ public:
((flippedData == 0 ) ? 0 :flippedData[0]) ((flippedData == 0 ) ? 0 :flippedData[0])
); );
if (additionalJsonHeader && strlen(additionalJsonHeader)) { if (additionalJsonHeader && strlen(additionalJsonHeader)) {
length = sprintf(buf, "%s, %s}\n", buf, additionalJsonHeader); strcat(buf, ", ");
} else { strcat(buf, additionalJsonHeader);
length = sprintf(buf, "%s}\n", buf);
} }
strcat(buf,"}\n");
int length = strlen(buf);
#ifdef VERBOSE #ifdef VERBOSE
//if(!index) //if(!index)

View File

@ -21,7 +21,7 @@
#define FILE_BUFFER_SIZE (16*1024*1024) //16mb #define FILE_BUFFER_SIZE (16*1024*1024) //16mb
//fifo //fifo
#define FIFO_HEADER_NUMBYTES 4 #define FIFO_HEADER_NUMBYTES 8
//hdf5 //hdf5

View File

@ -146,7 +146,7 @@ void DataProcessor::ResetParametersforNewMeasurement(){
delete [] tempBuffer; delete [] tempBuffer;
tempBuffer = 0; tempBuffer = 0;
} }
if (*gapPixelsEnable >= 0) { if (*gapPixelsEnable) {
tempBuffer = new char[generalData->imageSize]; tempBuffer = new char[generalData->imageSize];
memset(tempBuffer, 0, generalData->imageSize); memset(tempBuffer, 0, generalData->imageSize);
} }

View File

@ -40,7 +40,6 @@ DataStreamer::DataStreamer(int ind, Fifo*& f, uint32_t* dr, std::vector<ROI>* r,
FILE_LOG(logDEBUG) << "DataStreamer " << ind << " created"; FILE_LOG(logDEBUG) << "DataStreamer " << ind << " created";
memset(fileNametoStream, 0, MAX_STR_LENGTH);
} }
@ -83,7 +82,7 @@ void DataStreamer::ResetParametersforNewMeasurement(char* fname){
runningFlag = false; runningFlag = false;
firstMeasurementIndex = 0; firstMeasurementIndex = 0;
measurementStartedFlag = false; measurementStartedFlag = false;
strcpy(fileNametoStream, fname); fileNametoStream.assign(fname);
if (completeBuffer) { if (completeBuffer) {
delete [] completeBuffer; delete [] completeBuffer;
completeBuffer = 0; completeBuffer = 0;

View File

@ -64,9 +64,11 @@ Listener::Listener(int ind, detectorType dtype, Fifo*& f, runStatus* s,
Listener::~Listener() { Listener::~Listener() {
if (udpSocket) delete udpSocket; if (udpSocket) {
sem_post(&semaphore_socket); delete udpSocket;
sem_destroy(&semaphore_socket); sem_post(&semaphore_socket);
sem_destroy(&semaphore_socket);
}
if (carryOverPacket) delete [] carryOverPacket; if (carryOverPacket) delete [] carryOverPacket;
if (listeningPacket) delete [] listeningPacket; if (listeningPacket) delete [] listeningPacket;
ThreadObject::DestroyThread(); ThreadObject::DestroyThread();
@ -228,7 +230,9 @@ void Listener::ShutDownUDPSocket() {
FILE_LOG(logINFO) << "Shut down of UDP port " << *udpPortNumber; FILE_LOG(logINFO) << "Shut down of UDP port " << *udpPortNumber;
fflush(stdout); fflush(stdout);
//delete socket at stoplistening //delete socket at stoplistening
sem_wait(&semaphore_socket); if (runningFlag) {
sem_wait(&semaphore_socket);
}
delete udpSocket; delete udpSocket;
udpSocket = 0; udpSocket = 0;
sem_destroy(&semaphore_socket); sem_destroy(&semaphore_socket);

View File

@ -16,12 +16,13 @@
#include <sys/wait.h> //wait #include <sys/wait.h> //wait
#include <unistd.h> //usleep #include <unistd.h> //usleep
#include <syscall.h> #include <syscall.h>
#include <semaphore.h>
sem_t semaphore;
bool keeprunning;
void sigInterruptHandler(int p){ void sigInterruptHandler(int p){
keeprunning = false; sem_post(&semaphore);
} }
/* /*
@ -65,7 +66,7 @@ void GetData(char* metadata, char* datapointer, uint32_t datasize, void* p){
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
keeprunning = true; sem_init(&semaphore,1,0);
cprintf(BLUE,"Created [ Tid: %ld ]\n", (long)syscall(SYS_gettid)); cprintf(BLUE,"Created [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
// Catch signal SIGINT to close files and call destructors properly // Catch signal SIGINT to close files and call destructors properly
@ -148,8 +149,8 @@ int main(int argc, char *argv[]) {
FILE_LOG(logINFO) << "Ready ... "; FILE_LOG(logINFO) << "Ready ... ";
cprintf(RESET, "\n[ Press \'Ctrl+c\' to exit ]\n"); cprintf(RESET, "\n[ Press \'Ctrl+c\' to exit ]\n");
while(keeprunning) sem_wait(&semaphore);
pause(); sem_destroy(&semaphore);
delete receiver; delete receiver;
cprintf(BLUE,"Exiting [ Tid: %ld ]\n", (long)syscall(SYS_gettid)); cprintf(BLUE,"Exiting [ Tid: %ld ]\n", (long)syscall(SYS_gettid));