Compare commits

...

43 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
Erik Frojdh
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
Erik Frojdh
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
Dhanya Thattil
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
27f2321d64 fixed probelm with interpolation of rectangular pixels 2019-12-10 11:10:58 +01:00
545684c8e3 Fixed corordinate inversion 2019-12-09 16:51:15 +01:00
9584ea626d Interpolation changed for rectangular pixels 2019-12-09 13:53:11 +01:00
a2c26664ee added and corrected data structures for rectangular pixels 2019-12-06 12:17:31 +01:00
02a36a148f fixed process make file 2019-11-07 13:28:03 +01:00
142b184e62 fixed last frame with subframes 2019-09-30 12:43:37 +02:00
dd2fe28ce6 finxed subframe index in zmq process 2019-09-30 12:39:49 +02:00
0afd096eae removed log messages in receiver 2019-09-30 12:27:48 +02:00
98ae93fdde Possibility to sum up only fractions of frames in the Zmq process 2019-09-27 13:05:29 +02:00
c654ac7f1f Added sls_detector_process executable for acquire blocking on zmq 2019-09-27 10:12:21 +02:00
db2742495a Added defines to invert the data for HIGHZ in the moench data structures 2019-09-26 12:22:23 +02:00
d0c5c2a6e5 moenchZmqProcess and Makefile adjusted to work with this branch 2019-09-26 11:42:10 +02:00
2c09d394a6 slsDetectorCalibration updated to latest version 2019-09-26 11:34:11 +02:00
52f74142b1 Moench working version 2019-03-28 13:29:12 +01:00
107 changed files with 4615 additions and 7380 deletions

5
cmk.sh
View File

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

View File

@@ -1,4 +1,4 @@
hostname bchip085+
hostname bchip071+
patword 0000 0000000000000000
patword 0001 0000000000000000
@@ -416,28 +416,37 @@ patwaittime2 0
####mcp2011
#0:rx_udpip 10.1.1.102
0:rx_tcpport 1954
0:rx_udpport 32411
####gui listening to
zmqport 50001
####data streaming out of
rx_zmqport 50003
#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
#0:rx_tcpport 1977
#0:rx_udpip 10.1.1.100
#0:detectorip 10.1.1.19
#0:rx_udpport 32410
####gui listening to
#zmqip 129.129.202.131
#zmqport 30001
####data streaming out of
#rx_zmqip 10.1.2.103
#rx_zmqport 30003
#0:rx_hostname mpc2011
####mx-test-1
0:rx_udpip 10.1.1.100
0:detectorip 10.1.1.19
0:rx_udpport 32410
####gui listening to (on receiver pc)
zmqip 129.129.202.92
zmqport 30001
#zmqip 129.129.202.92
#zmqport 50001
####data streaming out of
rx_zmqip 10.1.1.100
rx_zmqport 30003
0:rx_hostname pcmoench01
#rx_zmqip 10.1.1.100
#rx_zmqport 50003
#0:rx_hostname mx-test-1
@@ -474,16 +483,17 @@ adcphase 90
adcpipeline 15
adcreg 14 40
powerchip 1
vhighvoltage 90
vhighvoltage 200
period 0.005
r_discardpolicy discardpartial
frames 100
period 0.1
outdir /scratch/
outdir /mnt/moench_data/scratch/
enablefwrite 0

View File

@@ -1,2 +0,0 @@
*.o
*.*~

View File

@@ -33,16 +33,17 @@ class MovingStat
{
if (m>=0) m_n = m; else m_n = n;
m_newM=val*m_n;
// cout << "set " << val << " " << m << " " << m_n << " " << m_newM << endl;
SetRMS(rms);
}
/**
/**
clears the moving average number of samples parameter, mean and standard deviation
*/
void SetRMS(double rms)
{
if (rms<=0) {
m_newM2=m_newM*m_newM/n;
m_n=0;
//m_n=0;
} else {
if (m_n>0)
m_newM2=(m_n*rms*rms+m_newM*m_newM/m_n);
@@ -120,6 +121,7 @@ class MovingStat
*/
inline double Mean() const
{
// cout << "get " << m_n << " " << m_newM << " " << m_newM/m_n << endl;
return (m_n > 0) ? m_newM/m_n : 0.0;
}

View File

@@ -6,7 +6,8 @@
#include <pthread.h>
#include "slsDetectorData.h"
#include "pedestalSubtraction.h"
#include "commonModeSubtraction.h"
#include "commonModeSubtractionNew.h"
#include "ghostSummation.h"
#include "tiffIO.h"
#include "slsInterpolation.h"
@@ -61,16 +62,16 @@ template <class dataType> class analogDetector {
analogDetector(slsDetectorData<dataType> *d, int sign=1,
commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), iframe(-1), dataSign(sign), gmap(gm), id(0) {
commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation<dataType> *gs=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), dataSign(sign), iframe(-1), gmap(gm), ghSum(gs), id(0) {
if (det)
det->getDetectorSize(nx,ny);
stat=new pedestalSubtraction*[ny];
stat=new pedestalSubtraction[ny*nx];
for (int i=0; i<ny; i++) {
stat[i]=new pedestalSubtraction[nx];
// stat[i]=new pedestalSubtraction[nx];
for (int ix=0; ix<nx; ix++) {
stat[i][ix].SetNPedestals(nped);
stat[i*nx+ix].SetNPedestals(nped);
}
}
image=new int[nx*ny];
@@ -94,7 +95,7 @@ template <class dataType> class analogDetector {
/**
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
delete hs;
#ifdef ROOTCLUST
@@ -118,7 +119,7 @@ template <class dataType> class analogDetector {
dataSign=orig->dataSign;
iframe=orig->iframe;
gmap=orig->gmap;
cmSub=orig->cmSub;
// cmSub=orig->cmSub;
id=orig->id;
xmin=orig->xmin;
xmax=orig->xmax;
@@ -130,16 +131,13 @@ template <class dataType> class analogDetector {
myFile=orig->myFile;
stat=new pedestalSubtraction*[ny];
for (int i=0; i<ny; i++) {
stat[i]=new pedestalSubtraction[nx];
}
stat=new pedestalSubtraction[ny*nx];
int nped=orig->SetNPedestals();
//cout << nped << " " << orig->getPedestal(ix,iy) << orig->getPedestalRMS(ix,iy) << endl;
for (int iy=0; iy<ny; iy++) {
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));
}
}
@@ -153,7 +151,16 @@ template <class dataType> class analogDetector {
hs9=(TH2F*)(orig->hs9)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5);
#endif
#endif
if (orig->cmSub) {
cmSub=(orig->cmSub)->Clone();
cout <<"cloning cm" << endl;
}
else cmSub=NULL;
if (orig->ghSum) {
ghSum=(orig->ghSum)->Clone();
cout <<"cloning gs" << endl;
}
else ghSum=NULL;
}
@@ -189,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
\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
\param nnx reference to pixel size in x
@@ -216,14 +223,18 @@ template <class dataType> class analogDetector {
\returns pointer to current gain map is file reading succeeded, NULL is file reading didn't work.
*/
double *readGainMap(const char * imgname) {
uint32 nnx, nny;
float *gm=ReadFromTiff( imgname, nny, nnx);
uint32 unnx, unny;
int nnx, nny;
float *gm=ReadFromTiff( imgname, unny, unnx);
nnx=unnx;
nny=unny;
if (gm) {
if (gmap) delete [] gmap;
gmap=new double[nnx*nny];
for (int iy=0; iy<nny; iy++) {
for (int ix=0; ix<nnx; ix++) {
for (int iy=0; iy<nny; iy++) {
for (int ix=0; ix<nnx; ix++) {
gmap[iy*nnx+ix]=gm[iy*nnx+ix];
// cout << gmap[iy*nnx+ix] << " " ;
}
}
return gmap;
@@ -258,7 +269,7 @@ template <class dataType> class analogDetector {
iframe=-1;
for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++) {
stat[iy][ix].Clear();
stat[iy*nx+ix].Clear();
image[iy*nx+ix]=0;
}
if (cmSub) cmSub->Clear();
@@ -275,6 +286,14 @@ template <class dataType> class analogDetector {
/** resets the commonModeSubtraction and increases the frame index */
virtual void newFrame(){iframe++; if (cmSub) cmSub->newFrame();};
/** resets the commonModeSubtraction and increases the frame index */
virtual void newFrame(char *data){
iframe++;
if (cmSub) cmSub->newFrame();
calcGhost(data);
// cout << getId() << " Calc ghost " << getGhost(15,15) << endl;
};
/** sets the commonModeSubtraction algorithm to be used
@@ -289,6 +308,11 @@ template <class dataType> class analogDetector {
commonModeSubtraction *getCommonModeSubtraction() {return cmSub;};
ghostSummation<dataType> *getGhostSummation(){return ghSum;};
ghostSummation<dataType> *setGhostSummation(ghostSummation<dataType> *gs){ghSum=gs; return ghSum;};
/**
sets the sign of the data
\param sign 1 means positive values for photons, -1 negative, 0 gets
@@ -304,12 +328,18 @@ template <class dataType> class analogDetector {
\param iy pixel y coordinate
\param cm 1 adds the value to common mod, 0 skips it. Defaults to 0. - not properly implemented
*/
virtual void addToPedestal(double val, int ix, int iy=0, int cm=0){
virtual void addToPedestal(double val, int ix, int iy, int cm=0){
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
// cout << val << " " ;
if (cmSub && cm>0) {
val-= getCommonMode(ix, iy);
}
stat[iy][ix].addToPedestal(val);
// cout << val << " " ;
val+=getGhost(ix,iy);
// cout << val ;
// cout << endl;
stat[iy*nx+ix].addToPedestal(val);
/* if (cmSub && cm>0) { */
/* if (det) if (det->isGood(ix, iy)==0) return; */
/* cmSub->addToCommonMode(val, ix, iy); */
@@ -318,29 +348,47 @@ template <class dataType> class analogDetector {
}
double getCommonMode(int ix, int iy) {
if (cmSub) return cmSub->getCommonMode(ix, iy);
else return 0;
if (cmSub) {
return cmSub->getCommonMode(ix, iy);
}
return 0;
}
virtual void addToCommonMode(char *data){
// cout << "+"<< getId() << endl;
if (cmSub) {
//cout << "*" << endl;
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
// if (getNumpedestals(ix,iy)>0)
if (det->isGood(ix,iy))
// if (det->isGood(ix,iy)) {
addToCommonMode(data, ix, iy);
}
// cout << ":";
// }
}
}
//cout << "cm " << getCommonMode(0,0) << " " << getCommonMode(1,0) << endl;
}
}
virtual void addToCommonMode(char *data, int ix, int iy=0){
// cout <<".";
if (cmSub) {
//cout <<":";
if (det) if (det->isGood(ix, iy)==0) return;
if (getNumpedestals(ix,iy)>0){
cmSub->addToCommonMode(subtractPedestal(data,ix,iy,0), ix, iy);
// cout << ix << " " <<subtractPedestal(data,ix,iy,0) << endl;
double val;
if (det) {
/* if (det->getChannel(data, ix, iy)>=0x3fff) */
/* cout << ix << " " << iy << " " << det->getChannel(data, ix, iy) <<endl; */
val= (dataSign*det->getValue(data, ix, iy)-getPedestal(ix,iy,0));
} else
val= (((double*)data)[iy*nx+ix]-getPedestal(ix,iy));
val+=getGhost(ix,iy);
cmSub->addToCommonMode(val, ix, iy);
//cout << ":";
}
}
}
@@ -351,12 +399,13 @@ template <class dataType> class analogDetector {
\param cm 0 (default) without common mode subtraction, 1 with common mode subtraction (if defined)
\returns pedestal value
*/
virtual double getPedestal(int ix, int iy, int cm=0){
if (ix>=0 && ix<nx && iy>=0 && iy<ny)
if (cmSub && cm>0)
return stat[iy][ix].getPedestal()+getCommonMode(ix,iy);
else return stat[iy][ix].getPedestal();
else return -1;
virtual double getPedestal (int ix, int iy, int cm=0){
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
if (cmSub && cm>0) {
return stat[iy*nx+ix].getPedestal()+getCommonMode(ix,iy);
} else return stat[iy*nx+ix].getPedestal();
} else return -1;
};
@@ -367,15 +416,22 @@ template <class dataType> class analogDetector {
\returns pedestal rms
*/
virtual double getPedestalRMS(int ix, int iy){
if (ix>=0 && ix<nx && iy>=0 && iy<ny)
return stat[iy][ix].getPedestalRMS();
else return -1;
double g=1;
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
if (gmap) {
g=gmap[iy*nx+ix];
if (g==0) g=-1.;
}
return stat[iy*nx+ix].getPedestalRMS()/g;//divide by gain?
}
return -1;
};
virtual int getNumpedestals(int ix, int iy){
if (ix>=0 && ix<nx && iy>=0 && iy<ny)
return stat[iy][ix].getNumpedestals();
else return -1;
return stat[iy*nx+ix].getNumpedestals();
return -1;
};
/**
gets pedestal (and common mode)
@@ -385,12 +441,13 @@ template <class dataType> class analogDetector {
\returns pedestal value
*/
virtual double* getPedestal(double *ped){
if (ped==NULL)
if (ped==NULL) {
ped=new double[nx*ny];
for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) {
ped[iy*nx+ix]=stat[iy][ix].getPedestal();
//cout << ped[iy*nx+ix] << " " ;
}
for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) {
ped[iy*nx+ix]=stat[iy*nx+ix].getPedestal();
//cout << ped[iy*nx+ix] << " " ;
}
}
return ped;
@@ -403,11 +460,12 @@ template <class dataType> class analogDetector {
\returns pedestal rms
*/
virtual double* getPedestalRMS(double *ped=NULL){
if (ped==NULL)
if (ped==NULL) {
ped=new double[nx*ny];
for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) {
ped[iy*nx+ix]=stat[iy][ix].getPedestalRMS();
}
for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) {
ped[iy*nx+ix]=stat[iy*nx+ix].getPedestalRMS();
}
}
return ped;
@@ -433,7 +491,7 @@ template <class dataType> class analogDetector {
\param rms rms to be set if any, defaults to 0
\param m number of pedestal samples to be set or the moving stat structure is any, defaults to 0
*/
virtual void setPedestal(int ix, int iy, double val, double rms=0, int m=-1){if (ix>=0 && ix<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
@@ -445,13 +503,14 @@ template <class dataType> class analogDetector {
*/
virtual void setPedestal(double *ped, double *rms=NULL, int m=-1){
double rr=0;
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; 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*nx+ix].getPedestal() << endl;
};
};
}
@@ -464,7 +523,7 @@ template <class dataType> class analogDetector {
\param iy pixel y coordinate
\param rms value to set
*/
virtual void setPedestalRMS(int ix, int iy, double rms=0){if (ix>=0 && ix<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);};
@@ -476,13 +535,30 @@ template <class dataType> class analogDetector {
virtual void setPedestalRMS(double *rms){
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
stat[iy][ix].setPedestalRMS(rms[iy*nx+ix]);
stat[iy*nx+ix].setPedestalRMS(rms[iy*nx+ix]);
};
};
}
virtual void calcGhost(char *data, int ix, int iy=1) {
if (ghSum) {
ghSum->calcGhost(data, ix, iy);
}
};
virtual void calcGhost(char *data){if (ghSum) {
ghSum->calcGhost(data);
// cout << getId() << " @ " << ghSum->getXTalk() << " " << ghSum->getGhost(15,15) << endl;
}
};
virtual double getGhost(int ix, int iy) {if (ghSum) return ghSum->getGhost(ix, iy); return 0;};
/**
write 32bit tiff file with detector image data
@@ -549,9 +625,9 @@ template <class dataType> class analogDetector {
for (int iy=0; iy<ny; iy++) {
for (int ix=0; ix<nx; ix++) {
/* if (cmSub) */
/* gm[iy*nx+ix]=stat[iy][ix].getPedestal()-cmSub->getCommonMode(); */
/* gm[iy*nx+ix]=stat[iy*nx+ix].getPedestal()-cmSub->getCommonMode(); */
/* else */
gm[iy*nx+ix]=stat[iy][ix].getPedestal();
gm[iy*nx+ix]=stat[iy*nx+ix].getPedestal();
#ifdef ROOTSPECTRUM
hmap->SetBinContent(ix+1, iy+1,gm[iy*nx+ix]);
#endif
@@ -595,13 +671,13 @@ template <class dataType> class analogDetector {
if (gm) {
for (int iy=0; iy<nny; iy++) {
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;
return 1;
}
return NULL;
return 0;
}
/**
@@ -626,7 +702,7 @@ template <class dataType> class analogDetector {
delete [] gm;
return 1;
}
return NULL;
return 0;
}
@@ -646,7 +722,7 @@ template <class dataType> class analogDetector {
gm=new float[nx*ny];
for (int iy=0; iy<ny; iy++) {
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);
@@ -668,7 +744,7 @@ template <class dataType> class analogDetector {
if (gm) {
for (int iy=0; iy<nny; iy++) {
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;
@@ -690,19 +766,24 @@ template <class dataType> class analogDetector {
virtual void addToPedestal(char *data, int cm=0) {
// cout << "add to pedestal " << endl;
newFrame();
// cout << "add to pedestal " << endl;
newFrame(data);
if (cmSub) {
//calcGhost(data);
if (cmSub && cm) {
// cout <<",";
addToCommonMode(data);
}
}
//cout << xmin << " " << xmax << endl;
// cout << ymin << " " << ymax << endl;
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
if (det->isGood(ix,iy)) {
addToPedestal(data,ix,iy,1);
// addToPedestal(data,ix,iy,1);
addToPedestal(data,ix,iy,cm);
//if (ix==10 && iy==10)
// cout <<ix << " " << iy << " " << getPedestal(ix,iy)<< endl;
#ifdef ROOTSPECTRUM
@@ -782,7 +863,7 @@ template <class dataType> class analogDetector {
*/
virtual void addToPedestal(char *data, int ix, int iy=0, int cm=0) {
virtual void addToPedestal(char *data, int ix, int iy, int cm=0) {
double val;
@@ -792,12 +873,13 @@ template <class dataType> class analogDetector {
val=dataSign*det->getValue(data, ix, iy);
else
val=((double*)data)[iy*nx+ix];
// cout << val << endl;
/* if (ix==10 && iy==10) */
/* cout << ix << " " << iy << " " << val ; */
/* if (ix==100 && iy==100) */
/* cout << ix << " " << iy << " " << val; */
addToPedestal(val,ix,iy);
// cout << val << endl;
/* if (ix==10 && iy==10) */
/* cout <<" " << getPedestal(ix,iy)<< endl; */
/* if (ix==100 && iy==100) */
@@ -818,15 +900,17 @@ template <class dataType> class analogDetector {
virtual int *subtractPedestal(char *data, int *val=NULL, int cm=0) {
newFrame();
newFrame(data);
if (val==NULL)
val=image;//new double[nx*ny];
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
if (det->isGood(ix,iy))
val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm);
//calcGhost(data);
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
if (det->isGood(ix,iy))
val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm);
}
}
return val;
@@ -847,18 +931,25 @@ template <class dataType> class analogDetector {
virtual double subtractPedestal(char *data, int ix, int iy=0, int cm=0) {
double g=1.;
double val;
double val =0;
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
if (gmap) {
g=gmap[iy*nx+ix];
if (g==0) g=-1.;
}
if (det)
if (det) {
/* if (det->getChannel(data, ix, iy)>=0x3fff) */
/* cout << ix << " " << iy << " " << det->getChannel(data, ix, iy) <<endl; */
val= (dataSign*det->getValue(data, ix, iy)-getPedestal(ix,iy,cm))/g;
else
} else
val= (((double*)data)[iy*nx+ix]-getPedestal(ix,iy))/g;
//if (val>=0.5*thr)
// cout << val << " " << (dataSign*det->getValue(data, ix, iy)-getPedestal(ix,iy,cm)) << " " << g << " ";
val+=getGhost(ix,iy)/g;
#ifdef ROOTSPECTRUM
hs->Fill(val,(iy-ymin)*(xmax-xmin)+(ix-xmin));
#ifdef ROOTCLUST
@@ -890,6 +981,7 @@ template <class dataType> class analogDetector {
#endif
return val;
}
return val;
};
@@ -917,8 +1009,7 @@ template <class dataType> class analogDetector {
int nph=0;
double v;
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
v=subtractPedestal(data,ix,iy);
v=subtractPedestal(data,ix,iy,1);
/* // cout << v << " " ; */
/* #ifdef ROOTSPECTRUM */
/* // cout << (iy-ymin)*(xmax-xmin)+(ix-xmin) << endl; */
@@ -927,8 +1018,14 @@ template <class dataType> class analogDetector {
if (thr>0) {
v+=0.5*thr;
nph=v/thr;
if (nph>0)
/* if (ix ==10 && iy<20) */
/* cout << det->getValue(data,ix,iy) << " " << stat[iy*nx+ix].getPedestal() << " " << getCommonMode(ix,iy) << " " << getPedestal(ix,iy,0)<< " " << getPedestal(ix,iy,1) << endl; */
// cout << subtractPedestal(data,ix,iy,0) << " " << subtractPedestal(data,ix,iy,1) << " " << nph << endl;
if (nph>0) {
//cout << " " << nph << endl;
return nph;
}
return 0;
}
return v;
@@ -944,15 +1041,16 @@ template <class dataType> class analogDetector {
*/
int *getNPhotons(char *data, int *nph=NULL) {
double val;
//double val;
if (nph==NULL)
nph=image;
newFrame();
newFrame(data);
//calcGhost(data);
addToCommonMode(data);
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
if (det->isGood(ix,iy))
nph[iy*nx+ix]+=getNPhotons(data, ix, iy);
}
@@ -999,8 +1097,8 @@ template <class dataType> class analogDetector {
if (i>0)
for (iy=0; iy<ny; iy++)
for (ix=0; ix<nx; ix++)
stat[iy][ix].SetNPedestals(i);
return stat[0][0].SetNPedestals();
stat[iy*nx+ix].SetNPedestals(i);
return stat[0].SetNPedestals();
};
/** gets number of samples for moving average pedestal calculation
@@ -1008,7 +1106,7 @@ template <class dataType> class analogDetector {
*/
int GetNPedestals(int ix, int iy) {
if (ix>=0 && ix<nx && iy>=0 && iy<ny)
return stat[iy][ix].GetNPedestals();
return stat[iy*nx+ix].GetNPedestals();
else
return -1;
};
@@ -1030,13 +1128,16 @@ template <class dataType> class analogDetector {
if (ymi<0) ymi=ymin;
if (yma<0) yma=ymax;
for (int iy=ymi; iy<yma; iy++)
for (int ix=xmi; ix<xma; ix++)
newFrame(data);
//calcGhost(data);
addToCommonMode(data);
for (int iy=ymi; iy<yma; iy++)
for (int ix=xmi; ix<xma; ix++)
if (det->isGood(ix,iy)) {
if (ix>=0 && ix<nx && iy>=0 && iy<ny)
val+=getNPhotons(data, ix, iy);
}
return val;
};
@@ -1054,7 +1155,7 @@ template <class dataType> class analogDetector {
switch(fMode) {
case ePedestal:
//cout << "analog ped " << endl;
addToPedestal(data);
addToPedestal(data,1);
break;
default:
// cout << "analog " << endl;
@@ -1133,11 +1234,12 @@ FILE *getFilePointer(){return myFile;};
slsDetectorData<dataType> *det; /**< slsDetectorData to be used */
int nx; /**< Size of the detector in x direction */
int ny; /**< Size of the detector in y direction */
pedestalSubtraction **stat; /**< pedestalSubtraction class */
pedestalSubtraction *stat; /**< pedestalSubtraction class */
commonModeSubtraction *cmSub;/**< commonModeSubtraction class */
int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */
int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */
double *gmap;
ghostSummation<dataType> *ghSum;/**< ghostSummation class */
int *image;
int id;
//int xmin, xmax, ymin, ymax; int xmin; /**< minimum x of the region of interest */

View File

@@ -14,7 +14,7 @@ class commonModeSubtraction {
\param iroi number of regions on which one can calculate the common mode separately. Defaults to 1 i.e. whole detector
*/
commonModeSubtraction(int iroi=1, int ns=3) : nROI(iroi), nsigma(ns) {
commonModeSubtraction(int iroi=1, int ns=3) : nsigma(ns), nROI(iroi) {
mean=new double[nROI];
mean2=new double[nROI];
nCm=new double[nROI];
@@ -23,6 +23,13 @@ class commonModeSubtraction {
/** destructor - deletes the moving average(s) and the sum of pedestals calculator(s) */
virtual ~commonModeSubtraction() {delete [] mean; delete [] mean2; delete [] nCm;};
/* commonModeSubtraction(commonModeSubtraction *cs) { */
/* if (cs) new commonModeSubtraction(cs->getNRoi(), cs->nsigma); */
/* } */
virtual commonModeSubtraction *Clone() {
return new commonModeSubtraction(this->nROI, this->nsigma);
}
/** clears the moving average and the sum of pedestals calculation - virtual func*/
virtual void Clear(){
@@ -34,6 +41,7 @@ class commonModeSubtraction {
/** adds the average of pedestals to the moving average and reinitializes the calculation of the sum of pedestals for all ROIs. - virtual func*/
virtual void newFrame(){
//cout << "Reset CM" << endl;
for (int i=0; i<nROI; i++) {
// if (nCm[i]>0) cmStat[i].Calc(cmPed[i]/nCm[i]);
nCm[i]=0;
@@ -52,7 +60,10 @@ class commonModeSubtraction {
// if (iroi==0) val=100;
// else val=-100;
// if (isc>=0 && isc<nROI) {
// cout << ix << " " << iy << " " << iroi << endl;
//if (ix==15 && iy==15) cout << "=" << val << endl;
if (iroi>=0 && iroi<nROI) {
// cout << ix << " " << iy << " " << iroi << endl;
mean[iroi]+=val;
mean2[iroi]+=val*val;
nCm[iroi]++;
@@ -70,9 +81,10 @@ class commonModeSubtraction {
/* return 100; */
/* else */
/* return -100; */
// cout << "*" << ix << " " << iy << " " << iroi << " " << mean[iroi] << " " << nCm[iroi]<< endl;
// if (ix==15 && iy==15) cout << "-" << mean[iroi]/nCm[iroi] << endl;
if (iroi>=0 && iroi<nROI) {
if (nCm[iroi]>0)
if (nCm[iroi]>0)
return mean[iroi]/nCm[iroi];
}
return 0;
@@ -96,8 +108,7 @@ class commonModeSubtraction {
gets the common mode ROI for pixel ix, iy -should be overloaded!
*/
virtual int getROI(int ix, int iy){ (void) ix; (void) iy; return 0;};
int getNRoi(){return nROI;};
protected:
double *mean; /**<array of moving average of the pedestal average per region of interest */

View File

@@ -45,7 +45,7 @@ class mythen3_01_jctbData : public slsDetectorData<short unsigned int> {
virtual short unsigned int* mythen03_frame(char *ptr, int dr=24, int nch=64*3, int off=5) {
// off=0;
int iarg;
//int iarg;
int64_t word, *wp;
short unsigned int* val=new short unsigned int[nch];
int bit[64];

View File

@@ -49,7 +49,7 @@ class mythen3_02_jctbData : public mythen3_01_jctbData {
virtual short unsigned int* mythen03_frame(char *ptr, int dr=24, int nch=64*3, int off=5) {
// off=0;
int iarg;
//int iarg;
int64_t word, *wp;
short unsigned int* val=new short unsigned int[nch];
int bit[64];
@@ -57,7 +57,7 @@ class mythen3_02_jctbData : public mythen3_01_jctbData {
int ioff=0;
int idr=0;
int ib=0;
int ich=0;
//int ich=0;
int ii=0;
int iw=0;
bit[0]=17;//19;

View File

@@ -0,0 +1,171 @@
#ifndef DESERIALIZER_H
#define DESERIALIZER_H
#include <vector>
class deserializer : public slsDetectorData<int> {
public:
deserializer( std::vector <int> dbl, int nch=64*3,int dr=24, int off=2): slsDetectorData<int>(nch,1,nch*dr*8+off*8,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch), dbitlist(dbl) {};
deserializer( std::vector <int> dbl, int nch,int dr, int off, int ds): slsDetectorData<int>(nch,1,ds,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch), dbitlist(dbl) {};
virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;};
virtual int getChannel(char *data, int ix, int iy=0) {
int ret=-1;
if (ix>=0 && ix<numberOfCounters) {
int *val=deserializeAll(data,dbitlist,dynamicRange,numberOfCounters,serialOffset);
ret=val[ix];
delete [] val;
}
return ret;
};
virtual int getFrameNumber(char *buff) {return frameNumber;};
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
ndata=dsize;
return data;
}
virtual char *readNextFrame(ifstream &filebin) {
char *data=NULL;
if (filebin.is_open()) {
data=new char[dataSize];
filebin.read(data,dataSize);
}
return data;
}
virtual int **getData(char *ptr, int dsize=-1) {
int **val;
val=new int*[1];
val[0]=deserializeAll(ptr,dbitlist,dynamicRange,nx,serialOffset);
return val;
}
static int* deserializeAll(char *ptr, std::vector <int> dbl, int dr=24, int nch=64*3, int off=5) {
// off=0;
//int iarg;
int64_t word, *wp;
int* val=new int[nch];
int ioff=0;
int idr=0;
int ib=0;
int iw=0;
int ii=0;
int ich;
int nb=dbl.size();
idr=0;
for (ib=0; ib<nch; ib++) {
val[ib]=0;
}
wp=(int64_t*)ptr;
for (iw=0; iw<nch/nb; iw) {
word=*wp;;
if (ioff<off) {
ioff++;
// cout <<"*";
} else {
//if (idr<16) {
ib=0;
for (const auto &bit : dbl) {
ich=iw+nch/nb*(ib);
if (word&(1<<bit) && ich<nch) {
//cout << "+" ;
val[ich]|=(1<<idr);
} //else {
//cout << "-" ;
//}
ib++;
}
}
idr++;
if (idr==dr) {
idr=0;
// cout << dec << " " << iw << " " << val[iw] << " " << val[iw+nch/2] << endl;
cout <<dec << iw<<endl;
iw++;
}//end if()
//end else()
wp+=1;
ii++;
}//end for
return val;
}
static int* deserializeList(char *ptr, std::vector <int> dbl, int dr=24, int nch=64*3, int off=5) {
// off=0;
//int iarg;
// int64_t word;
int* val=new int[nch];
//int ioff=0;
int idr=0;
int ib=0;
int iw=0;
int ii=0;
int ich;
int nb=dbl.size();
char *dval;
idr=0;
for (ib=0; ib<nch; ib++) {
val[ib]=0;
}
dval=ptr;
ib=0;
ich=0;
for (const auto &bit : dbl) {
//ioff=off;
idr=0;
for (iw=0; iw<(nch*dr/nb)/8; iw++) {
val[ich]|=(*dval)<<idr;
idr+=8;
dval++;
if (idr>=dr) {
idr=0;
ich++;
}
}
ii++;
ib++;
}//end for
return val;
}
virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; };
virtual int setDynamicRange(int d=-1) {if (d>0 && d<=24) dynamicRange=d; return dynamicRange;};
virtual int setSerialOffset(int d=-1) {if (d>=0) serialOffset=d; return serialOffset;};
virtual int setNumberOfCounters(int d=-1) {if (d>=0) numberOfCounters=d; return numberOfCounters;};
virtual std::vector <int> setDBitList(std::vector <int> dbl) {dbitlist=dbl; return dbitlist;};
virtual std::vector <int> getDBitList() {return dbitlist;};
private:
int dynamicRange;
int serialOffset;
int frameNumber;
int numberOfCounters;
std::vector <int> dbitlist;
};
#endif

View File

@@ -1,470 +0,0 @@
#ifndef EIGERMODULEDATA_H
#define EIGERMODULEDATA_H
#include "slsReceiverData.h"
class eigerHalfModuleData : public slsReceiverData<uint32_t> {
public:
/**
Implements the slsReceiverData structure for the eiger prototype read out by a half module i.e. using the slsReceiver
(256*256 pixels, 512 packets for 16 bit mode, 256 for 8, 128 for 4, 1024 for 32, 1040 etc.)
\param d dynamic range
\param c crosstalk parameter for the output buffer
*/
eigerHalfModuleData(bool t, bool l, int dr, int tg, int psize, int dsize, int npf, int x, int y, double c=0):
slsReceiverData<uint32_t>(x, y, npf, psize),
top(t), left(l),
dynamicRange(dr), tenGiga(tg),
packetSize(psize), onepacketdataSize(dsize), numberofPacketsPerFrame(npf),
xtalk(c),
header_t(0), footer_t(0){
int **dMap;
uint32_t **dMask;
dMap=new int*[ny];
dMask=new uint32_t*[ny];
for (int i = 0; i < ny; i++) {
dMap[i] = new int[nx];
dMask[i] = new uint32_t[nx];
}
//Map
int totalNumberOfBytes = numberofPacketsPerFrame * packetSize;
int iPacket = 8;
int iData = 0;
int increment = (dynamicRange/8);
int ic_increment = 1;
if (dynamicRange == 4) {
increment = 1;
ic_increment = 2;
}
if(top){
for (int ir=0; ir<ny; ir++) {
for (int ic=0; ic<nx; ic = ic + ic_increment) {
dMap[ir][ic] = iPacket;
iPacket += increment;
iData += increment;
//increment header
if(iData >= onepacketdataSize){
iPacket += 16;
iData = 0;
}
}
}
}
//bottom
else{
iData = 0;
int numbytesperline;
switch(dynamicRange){
case 4: numbytesperline = 256; break;
case 8: numbytesperline = 512; break;
case 16:numbytesperline = 1024; break;
case 32:numbytesperline = 2048; break;
}
iPacket = totalNumberOfBytes - numbytesperline - 8;
if((dynamicRange == 32) && (!tenGiga))
iPacket -= 16;
for (int ir=0; ir<ny; ir++) {
for (int ic=0; ic<nx; ic = ic + ic_increment) {
dMap[ir][ic] = iPacket;
iPacket += increment;
iData += increment;
//--------------------32 bit 1giga -------------------
if((dynamicRange == 32) && (!tenGiga)){
if(iData == numbytesperline){
iPacket -= (numbytesperline*2 + 16*3);
iData = 0;
}
if(iData == onepacketdataSize){
iPacket += 16;
}
}//------------end of 32 bit -------------------------
else if((iData % numbytesperline) == 0){
iPacket -= (numbytesperline*2);
if(iData == onepacketdataSize){
iPacket -= 16;
iData = 0;
}
}
//---------------------------------------------------
}
}
}
//Mask
for(int ir=0; ir<ny; ++ir)
for(int ic=0; ic<nx; ++ic)
dMask[ir][ic] = 0x0;
setDataMap(dMap);
setDataMask(dMask);
};
/** Returns the frame number for the given dataset.
\param buff pointer to the dataset
\returns frame number
*/
int getFrameNumber(char *buff){
footer_t = (eiger_packet_footer_t*)(buff + onepacketdataSize + sizeof(eiger_packet_header_t));
return ((uint32_t)(*( (uint64_t*) footer_t)));
};
/** gets the packets number
\param buff pointer to the memory
\returns packet number
*/
int getPacketNumber(char *buff){
footer_t = (eiger_packet_footer_t*)(buff + onepacketdataSize + sizeof(eiger_packet_header_t));
return(*( (uint16_t*) footer_t->packetnum));
};
/**
returns the pixel value as double correcting for the output buffer crosstalk
\param data pointer to the memory
\param ix coordinate in the x direction
\param iy coordinate in the y direction
\returns channel value as double
*/
double getValue(char *data, int ix, int iy=0) {
// cout << "##" << (void*)data << " " << ix << " " <<iy << endl;
if (xtalk==0)
return getChannelwithMissingPackets(data, ix, iy);
else
return getChannelwithMissingPackets(data, ix, iy)-xtalk * getChannelwithMissingPackets(data, ix-1, iy);
};
/**
Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded.
\param data pointer to the dataset (including headers etc)
\param ix pixel number in the x direction
\param iy pixel number in the y direction
\returns data for the selected channel, with inversion if required
*/
virtual int getChannelwithMissingPackets(char *data, int ix, int iy) {
uint32_t m=0, n = 0;
int linesperpacket,newix, newiy,origX;
//cout <<"ix:"<<ix<<" nx:"<<nx<<" iy:"<<iy<<" ny:"<<ny<<" datamap[iy][ix]:"<< dataMap[iy][ix] <<" datasize:"<< dataSize <<endl;
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) {
m=dataMask[iy][ix];
//pixelpos1d = (nx * iy + ix);
switch(dynamicRange){
case 4: if(tenGiga) linesperpacket=16; else linesperpacket=4;break;
case 8: if(tenGiga) linesperpacket=8; else linesperpacket=2;break;
case 16: if(tenGiga) linesperpacket=4; else linesperpacket=1;break;
case 32: if(tenGiga) linesperpacket=2; else linesperpacket=1;break;
}
//each byte is shared by 2 pixels for 4 bit mode
origX = ix;
if((dynamicRange == 4) && (ix%2))
ix--;
// ------check if missing packet, get to pixel at start of packet-----------------
//to get the starting of a packet (except 1g 32 bit)
newix = 0;
// 0.5 Lines per packet for 1g 32 bit
if(dynamicRange == 32 && !tenGiga)
newix = ix - (ix%256);
//iy divided by linesperpacket depending on bitmode
if(!(iy%linesperpacket))
newiy = iy;
else
newiy = (iy - (iy%linesperpacket));
header_t = (eiger_packet_header_t*)((char*)(data +(dataMap[newiy][newix]-8)));
uint16_t identifier = (uint16_t)*( (uint16_t*) header_t->missingpacket);
if(identifier==deactivatedPacketValue){
// cprintf(RED,"deactivated packet\n");
return -2;
}
// -----END OF CHECK -------------------------------------------------------------
}else{
cprintf(RED,"outside limits\n");
return -99;
}
//get proper data
n = ((uint32_t)(*((uint32_t*)(((char*)data)+(dataMap[iy][ix])))));
//each byte is shared by 2 pixels for 4 bit mode
if(dynamicRange == 4){
if(ix != origX)
return ((n & 0xf0)>>4)^m;
return (n & 0xf)^m;
}
else if(dynamicRange == 8) return (n & 0xff)^m;
else if(dynamicRange == 16) return (n & 0xffff)^m;
else return (n & 0xffffffff)^m;
};
/** sets the output buffer crosstalk correction parameter
\param c output buffer crosstalk correction parameter to be set
\returns current value for the output buffer crosstalk correction parameter
*/
double setXTalk(double c) {xtalk=c; return xtalk;}
/** gets the output buffer crosstalk parameter
\returns current value for the output buffer crosstalk correction parameter
*/
double getXTalk() {return xtalk;}
void getChannelArray(double* data, char* buffer){
for(int iy = 0; iy < ny; iy++){
for(int ix = 0; ix < nx; ix++){
data[iy*nx+ix] = getValue((char*)buffer,ix,iy);
//cprintf(BLUE,"%d,%d :%f\n",ix,iy,value);
}
}
}
int* decodeData(int *datain) {
int dataBytes = numberofPacketsPerFrame * onepacketdataSize;
int nch = nx*ny;
int* dataout = new int [nch];
char *ptr=(char*)datain;
char iptr;
const int bytesize=8;
int ival=0;
int ipos=0, ichan=0, ibyte;
switch (dynamicRange) {
case 4:
for (ibyte=0; ibyte<dataBytes; ++ibyte) {//for every byte (1 pixel = 1/2 byte)
iptr=ptr[ibyte]&0xff; //???? a byte mask
for (ipos=0; ipos<2; ++ipos) { //loop over the 8bit (twice)
ival=(iptr>>(ipos*4))&0xf; //pick the right 4bit
dataout[ichan]=ival;
ichan++;
}
}
break;
case 8:
for (ichan=0; ichan<dataBytes; ++ichan) {//for every pixel (1 pixel = 1 byte)
ival=ptr[ichan]&0xff; //????? a byte mask
dataout[ichan]=ival;
}
break;
case 16:
for (ichan=0; ichan<nch; ++ichan) { //for every pixel
ival=0;
for (ibyte=0; ibyte<2; ++ibyte) { //for each byte (concatenate 2 bytes to get 16 bit value)
iptr=ptr[ichan*2+ibyte];
ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
}
dataout[ichan]=ival;
}
break;
default:
//for every 32 bit (every element in datain array)
for (ichan=0; ichan<nch; ++ichan) { //for every pixel
ival=datain[ichan]&0xffffff;
dataout[ichan]=ival;
}
}
return dataout;
};
int* readNextFrameOnlyData(ifstream &filebin, int& fnum) {
int framesize = numberofPacketsPerFrame * onepacketdataSize;
int* data = new int[framesize/(sizeof(int))];
char *packet=new char[packetSize];
fnum = -1;
int pn=-1;
int dataoffset = 0;
if (filebin.is_open()) {
while (filebin.read(packet,packetSize)) {
fnum = getFrameNumber(packet); //cout << "fn:"<<fn<<endl;
pn = getPacketNumber(packet); //cout << "pn:"<<pn<<endl;
memcpy(((char*)data)+dataoffset,packet+DATA_PACKET_HEADER_SIZE,onepacketdataSize);
dataoffset+=onepacketdataSize;
if(pn == numberofPacketsPerFrame)
break;
}
}
delete [] packet;
if(!dataoffset){
delete [] data;
return NULL;
}
return data;
}
/*
when u get packet form next frames
//to remember the position to read next frame
filebin.seekg (position, filebin.beg);
position = filebin.tellg();
*/
int *readNextFramewithMissingPackets(ifstream &filebin, int& fnum) {
int* data = new int[(numberofPacketsPerFrame * onepacketdataSize)/(sizeof(int))];
char *packet=new char[packetSize];
fnum = -1;
int pnum = 0;
int fn = -1;
int pn =-1;
int dataoffset = 0;
int missingpackets;
if (filebin.is_open()) {
while (filebin.read(packet,packetSize)) {
fn = getFrameNumber(packet); //cout << "fn:"<<fn<<endl;
pn = getPacketNumber(packet); //cout << "pn:"<<pn<<endl;
//first packet
if(fnum == -1){
fnum = fn;
}
//next frame packet
else if (fnum != fn){
//set file reading to the last frame's packet in file
filebin.seekg(-packetSize, ios::cur);//filebin.beg
break;
}
//missing packets
missingpackets = pn - pnum - 1;
if(missingpackets){
memset(((char*)data)+dataoffset,0xFF,missingpackets*onepacketdataSize);
dataoffset+=(missingpackets*onepacketdataSize);
pnum+=missingpackets;
}
memcpy(((char*)data)+dataoffset,packet+DATA_PACKET_HEADER_SIZE,onepacketdataSize);
dataoffset+=onepacketdataSize;
pnum++;
if(pnum == numberofPacketsPerFrame)
break;
}
}
delete [] packet;
if(!pnum){
delete [] data;
return NULL;
}
//missing packets (added here to also catch end of file)
missingpackets = numberofPacketsPerFrame - pnum;
if(missingpackets){
memset(((char*)data)+dataoffset,0xFF,missingpackets*onepacketdataSize);
dataoffset+=(missingpackets*onepacketdataSize);
}
return data;
}
private:
/** Missing Packet identifier value */
const static uint16_t deactivatedPacketValue = 0xFEFE;
const static int DATA_PACKET_HEADER_SIZE = 8;
const bool top;
const bool left;
const int dynamicRange;
const bool tenGiga;
const int packetSize;
const int onepacketdataSize;
const int numberofPacketsPerFrame;
double xtalk; /**<output buffer crosstalk correction parameter */
/** structure of an eiger packet*/
typedef struct{
unsigned char subframenum[4];
unsigned char missingpacket[2];
unsigned char portnum[1];
unsigned char dynamicrange[1];
} eiger_packet_header_t;
typedef struct{
unsigned char framenum[6];
unsigned char packetnum[2];
} eiger_packet_footer_t;
eiger_packet_header_t* header_t;
eiger_packet_footer_t* footer_t;
};
#endif

View File

@@ -1,148 +0,0 @@
#ifndef GOTTHARDMODULEDATA_H
#define GOTTHARDMODULEDATA_H
#include "slsReceiverData.h"
#define FRAMEMASK 0xFFFFFFFE
#define PACKETMASK 1
#define FRAMEOFFSET 0x1
class gotthardModuleData : public slsReceiverData<uint16_t> {
public:
/**
Implements the slsReceiverData structure for the gotthard read out by a module i.e. using the slsReceiver
(1x1280 pixels, 2 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
gotthardModuleData(double c=0): slsReceiverData<uint16_t>(xpixels, ypixels, npackets, buffersize), xtalk(c) {
uint16_t **dMask;
int **dMap;
int ix, iy;
int initial_offset = 2;
int offset = initial_offset;
dMask=new uint16_t*[ypixels];
dMap=new int*[ypixels];
for (int i = 0; i < ypixels; i++) {
dMap[i] = new int[xpixels];
dMask[i] = new uint16_t[xpixels];
}
for(ix=0; ix<ypixels; ++ix)
for(iy=0; iy<xpixels; ++iy)
dMask[ix][iy] = 0x0;
for(ix=0; ix<ypixels; ++ix){
if(ix == (ypixels/2)){
offset += initial_offset;//2
offset++;
}
for(iy=0; iy<xpixels; ++iy){
dMap[ix][iy] = offset;
offset++;
}
}
setDataMap(dMap);
setDataMask(dMask);
};
/**
Returns the frame number for the given dataset.
\param buff pointer to the dataset
\returns frame number
*/
int getFrameNumber(char *buff){
int np=(*(int*)buff);
//gotthards frame header must be incremented
++np;
//packet index should be 1 or 2
return ((np&FRAMEMASK)>>FRAMEOFFSET);
};
/**
gets the packets number (last packet is labelled with 0 and is replaced with 40)
\param buff pointer to the memory
\returns packet number
*/
int getPacketNumber(char *buff){
int np=(*(int*)buff);
//gotthards frame header must be incremented
++np;
//packet index should be 1 or 2
return ((np&PACKETMASK)+1);
};
/**
returns the pixel value as double correcting for the output buffer crosstalk
\param data pointer to the memory
\param ix coordinate in the x direction
\param iy coordinate in the y direction
\returns channel value as double
*/
double getValue(char *data, int ix, int iy=0) {
//check how it is for gotthard
if (xtalk==0)
return slsDetectorData<uint16_t>::getValue(data, ix, iy);
else
return slsDetectorData<uint16_t>::getValue(data, ix, iy)-xtalk*slsDetectorData<uint16_t>::getValue(data, ix-1, iy);
};
/** sets the output buffer crosstalk correction parameter
\param c output buffer crosstalk correction parameter to be set
\returns current value for the output buffer crosstalk correction parameter
*/
double setXTalk(double c) {xtalk=c; return xtalk;}
/** gets the output buffer crosstalk parameter
\returns current value for the output buffer crosstalk correction parameter
*/
double getXTalk() {return xtalk;}
private:
double xtalk; /**<output buffer crosstalk correction parameter */
const static int xpixels = 1280;
const static int ypixels = 1;
const static int npackets = 2;
const static int buffersize = 1286;
};
#endif

View File

@@ -1,170 +0,0 @@
#ifndef GOTTHARDMODULEDATANEW_H
#define GOTTHARDMODULEDATANEW_H
#include "slsDetectorData.h"
typedef struct {
uint64_t frameNumber; /**< is the frame number */
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */
uint32_t packetNumber; /**< is the packet number */
uint64_t bunchId; /**< is the bunch id from beamline */
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
uint32_t debug; /**< is for debugging purposes */
uint16_t roundRNumber; /**< is the round robin set number */
uint8_t detType; /**< is the detector type see :: detectorType */
uint8_t version; /**< is the version number of this structure format */
} sls_detector_header;
class gotthardModuleDataNew : public slsDetectorData<uint16_t> {
private:
int iframe;
const int offset;
public:
/**
Implements the slsReceiverData structure for the gotthard read out by a module i.e. using the slsReceiver
(1x1280 pixels, 2 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
gotthardModuleDataNew(int off=24*2, int nch=1280): slsDetectorData<uint16_t>(nch, 1, nch*2+off), offset(off) {
uint16_t **dMask;
int **dMap;
int ix, iy;
int ypixels=1;
int xpixels=nch;
dMask=new uint16_t*[1];
dMap=new int*[1];
dMap[0] = new int[nch];
dMask[0] = new uint16_t[nch];
for(int ix=0; ix<xpixels; ix++) {
dMap[0][ix] = 2*ix+offset;
dMask[0][ix] = 0x0;
}
setDataMap(dMap);
setDataMask(dMask);
};
/**
Returns the frame number for the given dataset.
\param buff pointer to the dataset
\returns frame number
*/
int getFrameNumber(char *buff){if (offset>=sizeof(sls_detector_header)) return ((sls_detector_header*)buff)->frameNumber; return iframe;};//*((int*)(buff+5))&0xffffff;};
/**
gets the packets number (last packet is labelled with 0 and is replaced with 40)
\param buff pointer to the memory
\returns packet number
*/
int getPacketNumber(char *buff){if (offset>=sizeof(sls_detector_header))return ((sls_detector_header*)buff)->packetNumber;};
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize){
if (dsize<dataSize) ndata=dsize;
else ndata=dataSize;
return data;
}
virtual char *readNextFrame(ifstream &filebin) {
int ff=-1, np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int &ff) {
int np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
char *data=new char[dataSize];
char *d=readNextFrame(filebin, ff, np, data);
if (d==NULL) {delete [] data; data=NULL;}
return data;
}
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
char *retval=0;
int nd;
int fnum = -1;
np=0;
int pn;
// cout << dataSize << endl;
if (ff>=0)
fnum=ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){
ff=getFrameNumber(data);
np=getPacketNumber(data);
return data;
}
}
return NULL;
};
};
#endif

View File

@@ -1,156 +0,0 @@
#ifndef JUNGFRAU02DATA_H
#define JUNGFRAU02DATA_H
#include "chiptestBoardData.h"
class jungfrau02Data : public chiptestBoardData {
public:
/* test :) */
/**
Implements the chiptestBoardData structure for the jungfrau02 prototype
(48x48 pixels, ADC2 for analog output, 2 more ADCs used for readout of digital bits, pixel offset configurable.)
\param c crosstalk parameter for the output buffer
*/
jungfrau02Data(int nadc, int offset, double c=0): chiptestBoardData(48, 48, nadc, offset),
xtalk(c) {
uint16_t **dMask;
int **dMap;
dMask=new uint16_t*[48];
dMap=new int*[48];
for (int i = 0; i < 48; i++) {
dMap[i] = new int[48];
dMask[i] = new uint16_t[48];
}
for (int iy=0; iy<48; iy++) {
for (int ix=0; ix<48; ix++) {
dMap[ix][iy]=offset+(iy*48+ix)*nAdc;//dMap[iy][ix]=offset+(iy*48+ix)*nAdc;
// cout << ix << " " << iy << " " << dMap[ix][iy] << endl;
}
}
cout << (0,0) << " " << dMap[0][0] << endl;
cout << (47,47) << " " << dMap[47][47] << endl;
for (int ix=0; ix<48; ix++) {
for (int iy=0; iy<48; iy++)
dMask[iy][ix]=0x0;
setDataMap(dMap);
setDataMask(dMask);
}
};
/**
Returns the value of the selected channel for the given dataset. Since the ADC is only 14bit wide, only bit 0-13 are occupied. If the gain bits are read out, they are returned in bit 14-15.
\param data pointer to the dataset (including headers etc)
\param ix pixel number in the x direction
\param iy pixel number in the y direction
\returns data for the selected channel, with inversion if required
*/
virtual uint16_t getChannel(char *data, int ix, int iy=0) {
uint16_t m=0, d=0;
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) {
m=dataMask[iy][ix];
d=*(((uint16_t*)(data))+dataMap[iy][ix]);
// cout << ix << " " << iy << " " << (uint16_t*)data << " " << ((uint16_t*)(data))+dataMap[iy][ix] << " " << d << endl;
if (nAdc==3) {
//cout << "Gain bit!" << endl;
if (*((uint16_t*)(data)+dataMap[iy][ix]+2)>8000) //exchange if gainBits==2 is returned!
d|=(1<<14); // gain bit 1
if (*((uint16_t*)(data)+dataMap[iy][ix]+1)>8000) //exchange if gainBits==2 is returned!
d|=(1<<15); // gain bit 0
}
}
return d^m;
};
/**
returns the pixel value as double correcting for the output buffer crosstalk
\param data pointer to the memory
\param ix coordinate in the x direction
\param iy coordinate in the y direction
\returns channel value as double
*/
double getValue(char *data, int ix, int iy=0) {
// cout << "##" << (void*)data << " " << ix << " " <<iy << endl;
uint16_t d=getChannel(data, ix, iy);
// cout << d << " " << (d&0x3fff) << endl;
if (xtalk==0 || ix==0)
return (double)(getChannel(data, ix, iy)&0x3fff);
else
return (double)(getChannel(data, ix, iy)&0x3fff)-xtalk* (double)(getChannel(data, ix, iy)&0x3fff);
};
/**
returns the gain bit value, i.e. returns 0 if(GB0==0 && GB1==0), returns 1 if(GB0==1 && GB1==0), returns 3 if(GB0==1 && GB1==1), if it returns 2 -> the gain bits are read out the wrong way around (i.e. GB0 and GB1 have to be reversed!)
\param data pointer to the memory
\param ix coordinate in the x direction
\param iy coordinate in the y direction
\returns gain bits as int
*/
int getGainBits(char *data, int ix, int iy=0) {
uint16_t d=getChannel(data, ix, iy);
return ((d&0xc000)>>14);
};
//*/
/** sets the output buffer crosstalk correction parameter
\param c output buffer crosstalk correction parameter to be set
\returns current value for the output buffer crosstalk correction parameter
*/
double setXTalk(double c) {xtalk=c; return xtalk;}
/** gets the output buffer crosstalk parameter
\returns current value for the output buffer crosstalk correction parameter
*/
double getXTalk() {return xtalk;}
private:
double xtalk; /**<output buffer crosstalk correction parameter */
};
#endif

View File

@@ -1,217 +0,0 @@
#ifndef JUNGFRAU10MODULEDATA_H
#define JUNGFRAU10MODULEBDATA_H
#include "slsDetectorData.h"
class jungfrau10ModuleData : public slsDetectorData<uint16_t> {
private:
typedef struct {
uint64_t frameNumber; /**< is the frame number */
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */
uint32_t packetNumber; /**< is the packet number */
uint64_t bunchId; /**< is the bunch id from beamline */
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
uint32_t debug; /**< is for debugging purposes */
uint16_t roundRNumber; /**< is the round robin set number */
uint8_t detType; /**< is the detector type see :: detectorType */
uint8_t version; /**< is the version number of this structure format */
} sls_detector_header;
int iframe;
int nadc;
int sc_width;
int sc_height;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
jungfrau10ModuleData(int ns=16384): slsDetectorData<uint16_t>(256*4, 256*2, 256*256*8*2+48, NULL, NULL, NULL) , iframe(0) {
int row, col;
int isample;
int iadc;
int ix, iy;
int ichip;
// cout << sizeof(uint16_t) << endl;
int ip=0;
for (int iy=0; iy<256*2; iy++) {
for (int ix=0; ix<256*4; ix++){
dataMap[iy][ix]=ip*2+48;
ip++;
}
}
/* for (iadc=0; iadc<nadc; iadc++) { */
/* ichip=iadc/4; */
/* for (int i=0; i<sc_width*sc_height; i++) { */
/* if (ichip%2==0) { */
/* row=sc_height+i/sc_width; */
/* col=(ichip/2)*256+iadc%4*sc_width+(i%sc_width); */
/* } else { */
/* row=sc_height-1-i/sc_width; */
/* col=((ichip/2)*256+iadc%4*sc_width)+sc_width-(i%sc_width)-1; */
/* } */
/* /\* if (iadc<nadc/2) { *\/ */
/* /\* row=sc_height+i/sc_width; *\/ */
/* /\* col=iadc*sc_width+(i%sc_width); *\/ */
/* /\* } else { *\/ */
/* /\* row=sc_height-1-i/sc_width; *\/ */
/* /\* col=(nx-1)-((iadc-16)*sc_width)-(i%sc_width); *\/ */
/* /\* } *\/ */
/* if (row<0 || row>=ny || col<0 || col>=nx) { */
/* cout << "Wrong row, column " << row << " " << col << " " << iadc << " " << i << endl; */
/* } else */
/* dataMap[row][col]=(nadc*i+iadc)*2; */
/* if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) */
/* cout << "Error: pointer " << dataMap[row][col] << " out of range " << row << " " << col <<" " << iadc << " " << i << endl; */
/* else { */
/* xmap[nadc*i+iadc]=col; */
/* ymap[nadc*i+iadc]=row; */
/* } */
/* } */
// }
};
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
int getFrameNumber(return (sls_detector_header*)buff)->frameNumber;};
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
virtual int getPacketNumber(char *buff)=0;
*/
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
/**
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
\param filebin input file stream (binary)
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
*/
virtual char *readNextFrame(ifstream &filebin) {
int ff=-1, np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int &ff) {
int np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
char *data=new char[dataSize];
char *d=readNextFrame(filebin, ff, np, data);
if (d==NULL) {delete [] data; data=NULL;}
return data;
}
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
// char *readNextFrame(ifstream &filebin){
// int afifo_length=0;
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* // cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
char *retval=0;
int nd;
int fnum = -1;
np=0;
int pn;
// cout << dataSize << endl;
if (ff>=0)
fnum=ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){
ff=getFrameNumber(data);
np=getPacketNumber(data);
return data;
}
}
return NULL;
};
#endif

View File

@@ -1,246 +0,0 @@
#ifndef MOENCH02CTB10GBDATA_H
#define MOENCH02CTB10GBDATA_H
#include <stdio.h>
#include "slsDetectorData.h"
#include "slsReceiverData.h"
class moench02Ctb10GbData : public slsReceiverData<uint16_t> {
private:
int iframe;
// int *xmap, *ymap;
int nadc;
int sc_width;
int sc_height;
int maplength;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
moench02Ctb10GbData(int ns=6400): slsReceiverData<uint16_t>(160, 160, 50, 8208) , nadc(4), sc_width(40), sc_height(160) {
int adc_nr[4]={120,0,80,40};
int row, col;
int isample;
int iadc;
int ix, iy;
int i;
int npackets=50;
maplength = 8208*npackets;
//this->setDataSize(maplength);
/* maplength=this->getDataSize()/2; */
for (int ip=0; ip<npackets; ip++) {
for (int is=0; is<128; is++) {
for (iadc=0; iadc<nadc; iadc++) {
i=128*ip+is;
if (i<sc_width*sc_height) {
col=adc_nr[iadc]+(i%sc_width);
row=i/sc_width;
dataMap[row][col]=(32*i+iadc+2)*2+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=8208*npackets) {
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
}
}
}
}
}
int ibyte;
int ii=0;
for (int ipacket=0; ipacket<npackets; ipacket++) {
for (int ibyte=0; ibyte< 8208/2; ibyte++) {
i=ipacket*8208/2+ibyte;
if(ibyte<8){
xmap[i]=-1;
ymap[i]=-1;
}else{
isample=ii/32;
iadc=ii%32;
ix=isample%sc_width;
iy=isample/sc_width;
if(iadc>=2 && iadc<=5){
xmap[i]=adc_nr[iadc-2]+ix;
ymap[i]=iy;
}else{
xmap[i]=-1;
ymap[i]=-1;
}
ii++;
}
}//end loop on bytes
}//end loop on packets
iframe=0;
cout << "data struct created" << endl;
};
void getPixel(int ip, int &x, int &y) {
if(ip>=0 && ip<maplength){
x=xmap[ip];
y=ymap[ip];
}else{
cerr<<"WRONG ARRAY LENGTH"<<endl;
cerr<<"Trying to access the "<<ip<<"-th element"<<endl;
}
};
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
int getFrameNumber(char *buff){return *((int*)buff)&0xffffffff;};
/* virtual int getFrameNumber(char *buff){(void)buff; return iframe;}; */
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
virtual int getPacketNumber(char *buff)=0;
*/
int getPacketNumber(char *buff){return ((*(((int*)(buff+4))))&0xff)+1;};
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
//virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
/**
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
\param filebin input file stream (binary)
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
*/
/* virtual char *readNextFrame(ifstream &filebin){ */
/* // int afifo_length=0; */
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* //cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
char *data=new char[packetSize*nPackets];
char *retval=0;
int nd;
np=0;
int pn;
char aa[8224]={0};
char *packet=(char *)aa;
int fnum = -1;
if (ff>=0)
fnum=ff;
if (filebin.is_open()) {
cout << "+";
while(filebin.read((char*)packet, 8208)){
pn=getPacketNumber(packet);
if (fnum<0)
fnum= getFrameNumber(packet);
if (fnum>=0) {
if (getFrameNumber(packet) !=fnum) {
if (np==0){
cout << "-";
delete [] data;
return NULL;
} else
filebin.seekg(-8208,ios_base::cur);
return data;
}
memcpy(data+(pn-1)*packetSize, packet, packetSize);
np++;
if (np==nPackets)
break;
if (pn==nPackets)
break;
}
}
}else{
cerr<<filebin<<" not open!!!"<<endl;
return NULL;
}
if (np==0){
cout << "?";
delete [] data;
return NULL;
}// else if (np<nPackets)
// cout << "Frame " << fnum << " lost " << nPackets-np << " packets " << endl;
return data;
};
virtual char *readNextFrame(ifstream &filebin) {
int fnum=-1, np;
return readNextFrame(filebin, fnum, np);
};
};
#endif

View File

@@ -1,187 +0,0 @@
#ifndef MOENCH02CTBDATADGS_H
#define MOENCH02CTBDATADGS_H
#include "slsDetectorData.h"
class moench02CtbData : public slsDetectorData<uint16_t> {
private:
int iframe;
// int *xmap, *ymap;
//int nadc;
int sc_width;
int sc_height;
int maplength;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
moench02CtbDataDGS(int ns=6400): slsDetectorData<uint16_t>(160, 160, ns*(2*32+8), NULL, NULL) , sc_width(40), sc_height(160) {
int adc_off[4]={40,0,120,80};
int adc_nr[4]={8,10,20,23};
int row, col;
int isample;
int iadc, iiadc;
int ix, iy;
maplength=this->getDataSize()/2;
//cout << maplength << endl;
for (iiadc=0; iiadc<4; iiadc++) {
iadc=adc_nr[iiadc];
//cout << iiadc << endl;
for (int i=0; i<sc_width*sc_height; i++) {
col=adc_off[iiadc]+(i%sc_width);
row=i/sc_width;
dataMap[row][col]=(32*i+iadc)*2;
if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) {
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
}
}
}
for (int i=0; i<maplength; i++) {
//cout << i << endl;
isample=i/32;
iiadc=i%32;
iadc=-1;
for (int iii=0; iii<4; iii++) {
if (iiadc==adc_nr[iii]) iadc=iii;
}
ix=isample%sc_width;
iy=isample/sc_width;
if(iadc>=0){
xmap[i]=adc_off[iadc]+ix;
ymap[i]=iy;
}else{
xmap[i]=-1;
ymap[i]=-1;
}
}
iframe=0;
cout << "data struct created" << endl;
};
void getPixel(int ip, int &x, int &y) {
if(ip>=0 && ip<maplength){
x=xmap[ip];
y=ymap[ip];
}/*else{
cerr<<"WRONG ARRAY LENGTH"<<endl;
cerr<<"Trying to access the "<<ip<<"-th element"<<endl;
}*/
};
/**
Returns the gain for the selected pixel (at the moemnt only 3rd supercolumn)
\param buff pointer to the dataset
\param ix x coordinate
\param iy y coordinate
\returns gain value
*/
int getGain(char *buff, int ix, int iy) {
int isample=iy*sc_width+iy;
if (ix<sc_width) return 0; //first supercolumn no gain switching - could return the static gain if wished
if (ix<2*sc_width) return 0; //second supercolumn no gain switching - could return the static gain if wished
if (ix<3*sc_width){
if(*((long*)(buff+(32*2*isample+8*(isample-1)))&(1>>31)) return 1;
return 0;
}
return 0; //not yet implemented for 4th supercolumn
}
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
virtual int getPacketNumber(char *buff)=0;
*/
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
/**
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
\param filebin input file stream (binary)
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
*/
virtual char *readNextFrame(ifstream &filebin){
// int afifo_length=0;
uint16_t *afifo_cont;
int ib=0;
if (filebin.is_open()) {
afifo_cont=new uint16_t[dataSize/2];
while (filebin.read(((char*)afifo_cont)+ib,2)) {
ib+=2;
if (ib==dataSize) break;
}
if (ib>0) {
iframe++;
//cout << ib/2 << "-" << endl;
//for (int i=0; i<ib/2; i++)
//cout << i << " " << afifo_cont[i] << endl;
return (char*)afifo_cont;
} else {
delete [] afifo_cont;
return NULL;
}
}
return NULL;
};
};
#endif

View File

@@ -1,137 +0,0 @@
#ifndef MOENCH02MODULEDATA_H
#define MOENCH02MODULEDATA_H
#include "slsReceiverData.h"
class moench02ModuleData : public slsReceiverData<uint16_t> {
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
moench02ModuleData(double c=0): slsReceiverData<uint16_t>(160, 160, 40, 1286),
xtalk(c) {
uint16_t **dMask;
int **dMap;
int ix, iy;
dMask=new uint16_t*[160];
dMap=new int*[160];
for (int i = 0; i < 160; i++) {
dMap[i] = new int[160];
dMask[i] = new uint16_t[160];
}
for (int isc=0; isc<4; isc++) {
for (int ip=0; ip<10; ip++) {
for (int ir=0; ir<16; ir++) {
for (int ic=0; ic<40; ic++) {
ix=isc*40+ic;
iy=ip*16+ir;
dMap[iy][ix]=1286*(isc*10+ip)+2*ir*40+2*ic+4;
// cout << ix << " " << iy << " " << dMap[ix][iy] << endl;
}
}
}
}
for (ix=0; ix<120; ix++) {
for (iy=0; iy<160; iy++)
dMask[iy][ix]=0x3fff;
}
for (ix=120; ix<160; ix++) {
for (iy=0; iy<160; iy++)
dMask[iy][ix]=0x0;
}
setDataMap(dMap);
setDataMask(dMask);
};
/**
gets the packets number (last packet is labelled with 0 and is replaced with 40)
\param buff pointer to the memory
\returns packet number
*/
int getPacketNumber(char *buff){
int np=(*(int*)buff)&0xff;
if (np==0)
np=40;
return np;
};
/**
returns the pixel value as double correcting for the output buffer crosstalk
\param data pointer to the memory
\param ix coordinate in the x direction
\param iy coordinate in the y direction
\returns channel value as double
*/
double getValue(char *data, int ix, int iy=0) {
// cout << "##" << (void*)data << " " << ix << " " <<iy << endl;
if (xtalk==0 || ix%40==0)
return slsDetectorData<uint16_t>::getValue(data, ix, iy);
else
return slsDetectorData<uint16_t>::getValue(data, ix, iy)-xtalk*slsDetectorData<uint16_t>::getValue(data, ix-1, iy);
};
/** sets the output buffer crosstalk correction parameter
\param c output buffer crosstalk correction parameter to be set
\returns current value for the output buffer crosstalk correction parameter
*/
double setXTalk(double c) {xtalk=c; return xtalk;}
/** gets the output buffer crosstalk parameter
\returns current value for the output buffer crosstalk correction parameter
*/
double getXTalk() {return xtalk;}
private:
double xtalk; /**<output buffer crosstalk correction parameter */
};
#endif

View File

@@ -1,285 +0,0 @@
#ifndef MOENCH03CTB10GBDATA_H
#define MOENCH03CTB10GBDATA_H
#include "slsReceiverData.h"
class moench03Ctb10GbData : public slsReceiverData<uint16_t> {
protected:
int iframe;
int nadc;
int sc_width;
int sc_height;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
// moench03Ctb10GbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, 8208*40, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
moench03Ctb10GbData(int ns=5000): slsReceiverData<uint16_t>(400, 400, 40, 8208), nadc(32), sc_width(25), sc_height(200) {
int adc_nr[32]={200,225,250,275,300,325,350,375,\
0,25,50,75,100,125,150,175,\
175,150,125,100,75,50,25,0,\
375,350,325,300,275,250,225,200};
int row, col;
int isample;
int iadc;
int ix, iy;
int npackets=40;
int i;
for (int ip=0; ip<npackets; ip++) {
for (int is=0; is<128; is++) {
for (iadc=0; iadc<nadc; iadc++) {
i=128*ip+is;
if (i<sc_width*sc_height) {
// for (int i=0; i<sc_width*sc_height; i++) {
col=adc_nr[iadc]+(i%sc_width);
if (iadc<16) {
row=199-i/sc_width;
} else {
row=200+i/sc_width;
}
dataMap[row][col]=(nadc*i+iadc)*2+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=8208*40)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
}
}
}
}
int ipacket;
int ibyte;
int ii=0;
for (int ipacket=0; ipacket<npackets; ipacket++) {
for (int ibyte=0; ibyte< 8208/2; ibyte++) {
i=ipacket*8208/2+ibyte;
if (ibyte<8) {
//header!
xmap[i]=-1;
ymap[i]=-1;
} else {
// ii=ibyte+128*32*ipacket;
isample=ii/nadc;
iadc=ii%nadc;
ix=isample%sc_width;
iy=isample/sc_width;
if (iadc<(nadc/2)) {
xmap[i]=adc_nr[iadc]+ix;
ymap[i]=ny/2-1-iy;
} else {
xmap[i]=adc_nr[iadc]+ix;
ymap[i]=ny/2+iy;
}
ii++;
}
}
}
iframe=0;
// cout << "data struct created" << endl;
};
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
int getFrameNumber(char *buff){return *((int*)buff)&0xffffffff;};
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
*/
int getPacketNumber(char *buff){return ((*(((int*)(buff+4))))&0xff)+1;};
/* /\** */
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
/* \param data pointer to the memory to be analyzed */
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
/* \param dsize size of the memory slot to be analyzed */
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
/* *\/ */
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
/* /\** */
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
/* \param filebin input file stream (binary) */
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
/* *\/ */
/* virtual char *readNextFrame(ifstream &filebin){ */
/* // int afifo_length=0; */
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* // cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
virtual char *readNextFrame(ifstream &filebin, int& fnum, char *data=NULL) {
int dd=0;
if (data==NULL) {
data=new char[packetSize*nPackets];
dd=1;
}
char *retval=0;
int np=0, nd;
fnum = -1;
int pn;
char aa[8224];
char *packet=(char *)aa;
int place;
if (filebin.is_open()) {
place=filebin.tellg();
while(filebin.read((char*)packet, 8208) && np<nPackets){
pn=getPacketNumber(packet);
if (pn==1 && fnum<0)
fnum= getFrameNumber(packet);
// cout <<getFrameNumber(packet)<< " fn: " << fnum << "\t pn: " << pn << " np " << np << endl;
if (fnum>=0) {
if (getFrameNumber(packet) !=fnum) {
cout << "-"<<endl;
filebin.seekg(place);
if (np==0){
if (dd)
delete [] data;
return NULL;
} else {
return data;
}
}
memcpy(data+(pn-1)*packetSize, packet, packetSize);
np++;
if (np==nPackets)
return data;
}
place=filebin.tellg();
}
}
if (np==0){
cout << "-"<<endl;
filebin.seekg(place);
if (dd)
delete [] data;
return NULL;
}
//filebin.seekg(place);
return data;
};
/* virtual char *readNextFrame(ifstream &filebin, int& fnum) { */
/* char *data=new char[packetSize*nPackets]; */
/* char *retval=0; */
/* int np=0, nd; */
/* fnum = -1; */
/* int pn; */
/* char aa[8224]; */
/* char *packet=(char *)aa; */
/* if (filebin.is_open()) { */
/* while(filebin.read((char*)packet, 8208) && np<nPackets){ */
/* pn=getPacketNumber(packet); */
/* if (pn==1 && fnum<0) */
/* fnum= getFrameNumber(packet); */
/* // cout << "fn: " << fnum << "\t pn: " << pn << endl; */
/* if (fnum>=0) { */
/* if (getFrameNumber(packet) !=fnum) { */
/* if (np==0){ */
/* delete [] data; */
/* return NULL; */
/* } else */
/* return data; */
/* } */
/* memcpy(data+(pn-1)*packetSize, packet, packetSize); */
/* np++; */
/* } */
/* } */
/* } */
/* if (np==0){ */
/* delete [] data; */
/* return NULL; */
/* } */
/* }; */
int getPacketNumber(int x, int y) {return dataMap[y][x]/8208;};
};
#endif

View File

@@ -2,7 +2,7 @@
#define MOENCH03T1RECDATANEW_H
#include "slsDetectorData.h"
#define VERSION_V2
//#define VERSION_V2
/**
@short structure for a Detector Packet or Image Header
@li frameNumber is the frame number
@@ -33,7 +33,7 @@
uint16_t roundRNumber; /**< is the round robin set number */
uint8_t detType; /**< is the detector type see :: detectorType */
uint8_t version; /**< is the version number of this structure format */
#ifdef VERSION_V2
#ifndef VERSION_V1
uint64_t packetCaught[8]; /**< is the version number of this structure format */
#endif
@@ -77,9 +77,9 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
int row, col;
int isample;
// int isample;
int iadc;
int ix, iy;
// int ix, iy;
int npackets=40;
int i;
@@ -99,43 +99,46 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
} else {
row=200+i/sc_width;
}
dataMap[row][col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=nSamples*2*32)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
dataMap[row*nx+col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1);
#ifdef HIGHZ
dataMask[row*nx+col]=0x3fff;
#endif
if (dataMap[row*nx+col]<0 || dataMap[row*nx+col]>=nSamples*2*32)
cout << "Error: pointer " << dataMap[row*nx+col] << " out of range "<< endl;
}
}
}
}
int ipacket;
int ibyte;
int ii=0;
for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){
xmap[ibyte]=-1;
ymap[ibyte]=-1;
}
int off=sizeof(sls_detector_header)/2;
for (ipacket=0; ipacket<npackets; ipacket++) {
for (ibyte=0; ibyte< 8192/2; ibyte++) {
i=ipacket*8208/2+ibyte;
isample=ii/nadc;
if (isample<nSamples) {
iadc=ii%nadc;
adc4 = (int)iadc/4;
ix=isample%sc_width;
iy=isample/sc_width;
if (adc4%2==0) {
xmap[i+off]=adc_nr[iadc]+ix;
ymap[i+off]=ny/2-1-iy;
} else {
xmap[i+off]=adc_nr[iadc]+ix;
ymap[i+off]=ny/2+iy;
}
}
ii++;
// }
}
}
// int ipacket;
// int ibyte;
// int ii=0;
// for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){
// xmap[ibyte]=-1;
// ymap[ibyte]=-1;
// }
// int off=sizeof(sls_detector_header)/2;
// for (ipacket=0; ipacket<npackets; ipacket++) {
// for (ibyte=0; ibyte< 8192/2; ibyte++) {
// i=ipacket*8208/2+ibyte;
// isample=ii/nadc;
// if (isample<nSamples) {
// iadc=ii%nadc;
// adc4 = (int)iadc/4;
// ix=isample%sc_width;
// iy=isample/sc_width;
// if (adc4%2==0) {
// xmap[i+off]=adc_nr[iadc]+ix;
// ymap[i+off]=ny/2-1-iy;
// } else {
// xmap[i+off]=adc_nr[iadc]+ix;
// ymap[i+off]=ny/2+iy;
// }
// }
// ii++;
// // }
// }
// }
iframe=0;
// cout << "data struct created" << endl;
@@ -237,15 +240,15 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
char *retval=0;
int nd;
int fnum = -1;
np=0;
int pn;
//char *retval=0;
// int nd;
//int fnum = -1;
// np=0;
// int pn;
// cout << dataSize << endl;
if (ff>=0)
fnum=ff;
// if (ff>=0)
// fnum=ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){

View File

@@ -34,6 +34,9 @@
uint16_t roundRNumber; /**< is the round robin set number */
uint8_t detType; /**< is the detector type see :: detectorType */
uint8_t version; /**< is the version number of this structure format */
#ifndef VERSION_V1
uint64_t packetCaught[8]; /**< is the version number of this structure format */
#endif
} sls_detector_header;

View File

@@ -0,0 +1,176 @@
#ifndef MOENCH03T1REORDERED_H
#define MOENCH03T1REORDERED_H
#include "slsDetectorData.h"
class moench03T1ReorderedData : public slsDetectorData<uint16_t> {
private:
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
fwrite(&ff, 8, 1,of);//write detector frame number
fwrite(&ifr, 8, 1,of);//write datset frame number
fwrite(data,2,NX*NY,of);//write reordered data
*/
moench03T1ReorderedData(): slsDetectorData<uint16_t>(400, 400, 2*400*400+2*8) {
for (int iy=0; iy<400; iy++)
for (int ix=0; ix<400; ix++)
dataMap[iy][ix]=2*8+2*(iy*400+ix);
int ibyte;
for (ibyte=0; ibyte<8; ibyte++){
xmap[ibyte]=-1;
ymap[ibyte]=-1;
}
for (ibyte=0; ibyte<400*400; ibyte++){
xmap[ibyte+8]=ibyte%400;
ymap[ibyte+8]=ibyte/400;
}
// cout << "data struct created" << endl;
};
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
/* class jfrau_packet_header_t { */
/* public: */
/* unsigned char reserved[4]; */
/* unsigned char packetNumber[1]; */
/* unsigned char frameNumber[3]; */
/* unsigned char bunchid[8]; */
/* }; */
int getFrameNumber(char *buff){return *((int*)buff);};
/* /\** */
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
/* \param data pointer to the memory to be analyzed */
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
/* \param dsize size of the memory slot to be analyzed */
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
/* *\/ */
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
/* /\** */
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
/* \param filebin input file stream (binary) */
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
/* *\/ */
/* virtual char *readNextFrame(ifstream &filebin){ */
/* // int afifo_length=0; */
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* // cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
virtual char *readNextFrame(ifstream &filebin) {
int ff=-1, np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int &ff) {
int np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
char *data=new char[dataSize];
char *d=readNextFrame(filebin, ff, np, data);
if (d==NULL) {delete [] data; data=NULL;}
return data;
}
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
char *retval=0;
int nd;
int fnum = -1;
np=0;
int pn;
if (ff>=0)
fnum=ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){
ff=getFrameNumber(data);
np=40;
return data;
}
}
return NULL;
};
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize){
if (dsize<dataSize) ndata=dsize;
else ndata=dataSize;
return data;
}
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
};
#endif

View File

@@ -60,9 +60,12 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
} else {
row=200+i/sc_width;
}
dataMap[row][col]=(nadc*i+iadc)*2+offset;//+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
dataMap[row*nx+col]=(nadc*i+iadc)*2+offset;//+16*(ip+1);
#ifdef HIGHZ
dataMask[row*nx+col]=0x3fff;
#endif
if (dataMap[row*nx+col]<0 || dataMap[row*nx+col]>=dataSize)
cout << "Error: pointer " << dataMap[row*nx+col] << " out of range "<< endl;
}
}
}
@@ -71,8 +74,8 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
int ii=0;
for (i=0; i< dataSize; i++) {
if (i<offset) {
for (i=0; i< dataSize/2; i++) {
if (i<offset/2) {
//header! */
xmap[i]=-1;
ymap[i]=-1;
@@ -201,15 +204,15 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
char *retval=0;
int nd;
int fnum = -1;
/* char *retval=0; */
/* int nd; */
/* int fnum = -1; */
np=0;
int pn;
/* int pn; */
if (ff>=0)
fnum=ff;
/* if (ff>=0) */
/* fnum=ff; */
if (filebin.is_open()) {
if (filebin.read(data, 32*2*nSamples) ){
@@ -218,7 +221,7 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
return data;
}
}
return NULL;
return NULL;

View File

@@ -1,10 +1,12 @@
#ifndef MOENCH03CTB10GBT1DATA_H
#define MOENCH03CTB10GBT1DATA_H
#include "slsReceiverData.h"
#ifndef MOENCH03T1ZMQNEWRECT_H
#define MOENCH03T1ZMQNEWRECT_H
#include "slsDetectorData.h"
#define VERT 1
class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
private:
@@ -12,9 +14,12 @@ class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
int nadc;
int sc_width;
int sc_height;
public:
const int nSamples;
const int offset;
public:
/**
@@ -23,9 +28,16 @@ class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
\param c crosstalk parameter for the output buffer
*/
moench03Ctb10GbT1Data(int ns=5000): slsReceiverData<uint16_t>(400, 400, 40, 8208), nadc(32), sc_width(25), sc_height(200) {
#ifdef HOR
moench03T1ZmqDataNew(int ns=5000): slsDetectorData<uint16_t>(800, 200, ns*2*32), nSamples(ns), offset(sizeof(int)) {
#endif
#ifdef VERT
moench03T1ZmqDataNew(int ns=5000): slsDetectorData<uint16_t>(200, 800, ns*2*32), nSamples(ns), offset(sizeof(int)) {
#endif
int nadc=32;
int sc_width=25;
int sc_height=200;
int adc_nr[32]={300,325,350,375,300,325,350,375, \
200,225,250,275,200,225,250,275,\
@@ -34,13 +46,21 @@ class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
int row, col;
int isample;
// int isample;
int iadc;
int ix, iy;
int npackets=40;
int npackets=40;
int i;
int adc4(0);
int pix;
int off=0;
#ifdef OFF_1
off=1;
#endif
cout << "This is a MOENCH with rectangular pixels!" << endl;
for (int ip=0; ip<npackets; ip++) {
for (int is=0; is<128; is++) {
@@ -56,46 +76,67 @@ class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
} else {
row=200+i/sc_width;
}
dataMap[row][col]=(nadc*i+iadc)*2+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=8208*40)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
pix=(nadc*i+iadc)*2+offset;//+16*(ip+1);
if (pix<0 || pix>=nSamples*2*32)
cout << "Error: pointer " << pix << " out of range "<< endl;
ix=col;
iy=row;
//col and row have to do with data sequence
//ix and iy have to do with implant position
#ifdef HOR
if (row%2==off) {
ix=2*col;
iy=row/2;
} else {
ix=2*col+1;
iy=row/2;
}
#endif
#ifdef VERT
if (col%2==off) {
ix=col/2;
iy=row*2+1;
} else {
ix=col/2;
iy=row*2;
}
#endif
dataMap[iy*nx+ix]=pix;
}
}
}
}
int ipacket;
int ibyte;
int ii=0;
for (int ipacket=0; ipacket<npackets; ipacket++) {
for (int ibyte=0; ibyte< 8208/2; ibyte++) {
i=ipacket*8208/2+ibyte;
if (ibyte<8) {
//header!
xmap[i]=-1;
ymap[i]=-1;
} else {
// ii=ibyte+128*32*ipacket;
isample=ii/nadc;
iadc=ii%nadc;
adc4 = (int)iadc/4;
ix=isample%sc_width;
iy=isample/sc_width;
if (adc4%2==0) {
xmap[i]=adc_nr[iadc]+ix;
ymap[i]=ny/2-1-iy;
} else {
xmap[i]=adc_nr[iadc]+ix;
ymap[i]=ny/2+iy;
}
ii++;
}
}
}
/* int ipacket; */
/* int ibyte; */
/* int ii=0; */
/* for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){ */
/* xmap[ibyte]=-1; */
/* ymap[ibyte]=-1; */
/* } */
/* int off=sizeof(sls_detector_header)/2; */
/* for (ipacket=0; ipacket<npackets; ipacket++) { */
/* for (ibyte=0; ibyte< 8192/2; ibyte++) { */
/* i=ipacket*8208/2+ibyte; */
/* isample=ii/nadc; */
/* if (isample<nSamples) { */
/* iadc=ii%nadc; */
/* adc4 = (int)iadc/4; */
/* ix=isample%sc_width; */
/* iy=isample/sc_width; */
/* if (adc4%2==0) { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2-1-iy; */
/* } else { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2+iy; */
/* } */
/* } */
/* ii++; */
/* // } */
/* } */
/* } */
iframe=0;
// cout << "data struct created" << endl;
@@ -121,8 +162,7 @@ class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
// int getFrameNumber(char *buff){return *((int*)buff)&0xffffffff;};
int getFrameNumber(char *buff){return *((int*)(buff+5))&0xffffff;};
int getFrameNumber(char *buff){return *((int*)buff);};//*((int*)(buff+5))&0xffffff;};
/**
@@ -133,7 +173,7 @@ class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
*/
int getPacketNumber(char *buff){return ((*(((int*)(buff+4))))&0xff)+1;};
int getPacketNumber(char *buff){return 0;}//((*(((int*)(buff+4))))&0xff)+1;};
/* /\** */
@@ -188,79 +228,63 @@ class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
};
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
char *data=new char[packetSize*nPackets];
char *data=new char[32*2*nSamples];
char *d=readNextFrame(filebin, ff, np, data);
if (d==NULL) {delete [] data; data=NULL;}
return data;
}
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
char *retval=0;
int nd;
int fnum = -1;
/* char *retval=0; */
/* int nd; */
/* int fnum = -1; */
np=0;
int pn, po=0;
char aa[8224];
char *packet=(char *)aa;
// cout << packetSize*nPackets << endl;
if (ff>=0)
fnum=ff;
/* int pn; */
/* if (ff>=0) */
/* fnum=ff; */
if (filebin.is_open()) {
while(filebin.read((char*)packet, 8208) ){
pn=getPacketNumber(packet);
if (fnum<0)
fnum= getFrameNumber(packet);
// cout << "fn: " << fnum << "\t pn: " << pn << endl;
if (fnum>=0) {
if (getFrameNumber(packet) !=fnum || pn<po) {
if (np==0){
// delete [] data;
return NULL;
} else
filebin.seekg(-8208,ios_base::cur);
po =pn;
return data;
}
if (pn>nPackets) {
cout << "Bad packet number " << pn << endl;
}
memcpy(data+(pn-1)*packetSize, packet, packetSize);
np++;
po =pn;
if (np==nPackets)
break;
if (pn==nPackets)
break;
}
if (filebin.read(data, 32*2*nSamples) ){
// iframe++;
//ff=iframe;
return data;
}
}
return NULL;
}
if (np==0){
// delete [] data;
return NULL;
}
ff=fnum;
return data;
};
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize){
if (dsize<32*2*nSamples) ndata=dsize;
else ndata=32*2*nSamples;
return data;
}
// virtual int setFrameNumber(int ff){iframe=ff};
@@ -271,13 +295,7 @@ class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
int getPacketNumber(int x, int y) {return dataMap[y][x]/8208;};
int getPacketNumber(int x, int y) {return 0;};
};
@@ -285,3 +303,4 @@ int getPacketNumber(int x, int y) {return dataMap[y][x]/8208;};
#endif

View File

@@ -1,285 +0,0 @@
#ifndef MOENCH03TCTB10GBDATA_H
#define MOENCH03TCTB10GBDATA_H
#include "moench03Ctb10GbData.h"
class moench03TCtb10GbData : public moench03Ctb10GbData { //slsReceiverData<uint16_t> {
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
// moench03TCtb10GbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, 8208*40, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
moench03TCtb10GbData(int ns=5000): moench03Ctb10GbData(ns) {//slsReceiverData<uint16_t>(400, 400, 40, 8208), nadc(32), sc_width(25), sc_height(200) {
// cout <<"constructor"<< endl;
// nadc=32;
int adc_nr[32]={300,325,350,375,300,325,350,375, \
200,225,250,275,200,225,250,275,\
100,125,150,175,100,125,150,175,\
0,25,50,75,0,25,50,75};
int row, col;
int isample;
int iadc;
int ix, iy;
int npackets=40;
int i;
int adc4(0);
for (int ip=0; ip<npackets; ip++) {
for (int is=0; is<128; is++) {
for (iadc=0; iadc<nadc; iadc++) {
i=128*ip+is;
//cout << i << endl;
adc4=(int)iadc/4;
if (i<sc_width*sc_height) {
// for (int i=0; i<sc_width*sc_height; i++) {
col=adc_nr[iadc]+(i%sc_width);
if (adc4%2==0) {
// if (iadc<(nadc/2)) {
row=199-i/sc_width;
} else {
row=200+i/sc_width;
}
dataMap[row][col]=(nadc*i+iadc)*2+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=8208*40)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
}
}
}
}
// cout <<"map"<< endl;
int ipacket;
int ibyte;
int ii=0;
for (int ipacket=0; ipacket<npackets; ipacket++) {
for (int ibyte=0; ibyte< 8208/2; ibyte++) {
i=ipacket*8208/2+ibyte;
// cout << i << " ";
if (ibyte<8) {
//header!
xmap[i]=-1;
ymap[i]=-1;
} else {
// ii=ibyte+128*32*ipacket;
// cout << nadc << endl;
isample=ii/nadc;
iadc=ii%nadc;
adc4 = (int)iadc/4;
ix=isample%sc_width;
iy=isample/sc_width;
// cout << isample << " " << iadc << " " << ix << " " << iy ;//<< endl;
if (adc4%2==0) {//iadc<(nadc/2)) {
//if (iadc<(nadc/2)) {
xmap[i]=adc_nr[iadc]+ix;
ymap[i]=ny/2-1-iy;
} else {
xmap[i]=adc_nr[iadc]+ix;
ymap[i]=ny/2+iy;
}
ii++;
}
}
}
/* int ipacket; */
/* int ibyte; */
/* int ii=0; */
/* for (int ipacket=0; ipacket<npackets; ipacket++) { */
/* for (int ibyte=0; ibyte< 8208/2; ibyte++) { */
/* i=ipacket*8208/2+ibyte; */
/* cout << i << endl; */
/* if (ibyte<8) { */
/* //header! */
/* xmap[i]=-1; */
/* ymap[i]=-1; */
/* } else { */
/* ii=ibyte+128*32*ipacket; */
/* isample=ii/nadc; */
/* iadc=ii%nadc; */
/* adc4 = (int)iadc/4; */
/* ix=isample%sc_width; */
/* iy=isample/sc_width; */
/* if (adc4%2==0) { */
/* xmap[i]=adc_nr[iadc]+ix; */
/* ymap[i]=ny/2-1-iy; */
/* } else { */
/* xmap[i]=adc_nr[iadc]+ix; */
/* ymap[i]=ny/2+iy; */
/* } */
/* ii++; */
/* } */
/* } */
/* } */
// cout <<"done"<< endl;
iframe=0;
// cout << "data struct created" << endl;
};
/* /\** */
/* Returns the frame number for the given dataset. Purely virtual func. */
/* \param buff pointer to the dataset */
/* \returns frame number */
/* *\/ */
/* int getFrameNumber(char *buff){return *((int*)buff)&0xffffffff;}; */
/* /\** */
/* Returns the packet number for the given dataset. purely virtual func */
/* \param buff pointer to the dataset */
/* \returns packet number number */
/* *\/ */
/* int getPacketNumber(char *buff){return ((*(((int*)(buff+4))))&0xff)+1;}; */
/* /\* /\\** *\/ */
/* /\* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func *\/ */
/* /\* \param data pointer to the memory to be analyzed *\/ */
/* /\* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot *\/ */
/* /\* \param dsize size of the memory slot to be analyzed *\/ */
/* /\* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found *\/ */
/* /\* *\\/ *\/ */
/* /\* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; *\/ */
/* /\* /\\** *\/ */
/* /\* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! *\/ */
/* /\* \param filebin input file stream (binary) *\/ */
/* /\* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete *\/ */
/* /\* *\\/ *\/ */
/* /\* virtual char *readNextFrame(ifstream &filebin){ *\/ */
/* /\* // int afifo_length=0; *\/ */
/* /\* uint16_t *afifo_cont; *\/ */
/* /\* int ib=0; *\/ */
/* /\* if (filebin.is_open()) { *\/ */
/* /\* afifo_cont=new uint16_t[dataSize/2]; *\/ */
/* /\* while (filebin.read(((char*)afifo_cont)+ib,2)) { *\/ */
/* /\* ib+=2; *\/ */
/* /\* if (ib==dataSize) break; *\/ */
/* /\* } *\/ */
/* /\* if (ib>0) { *\/ */
/* /\* iframe++; *\/ */
/* /\* // cout << ib << "-" << endl; *\/ */
/* /\* return (char*)afifo_cont; *\/ */
/* /\* } else { *\/ */
/* /\* delete [] afifo_cont; *\/ */
/* /\* return NULL; *\/ */
/* /\* } *\/ */
/* /\* } *\/ */
/* /\* return NULL; *\/ */
/* /\* }; *\/ */
/* virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { */
/* char *data=new char[packetSize*nPackets]; */
/* char *retval=0; */
/* int nd; */
/* np=0; */
/* int pn; */
/* char aa[8224]={0}; */
/* char *packet=(char *)aa; */
/* int fnum = -1; */
/* if (ff>=0) */
/* fnum=ff; */
/* if (filebin.is_open()) { */
/* cout << "+"; */
/* while(filebin.read((char*)packet, 8208)){ */
/* pn=getPacketNumber(packet); */
/* if (fnum<0) */
/* fnum= getFrameNumber(packet); */
/* if (fnum>=0) { */
/* if (getFrameNumber(packet) !=fnum) { */
/* if (np==0){ */
/* cout << "-"; */
/* delete [] data; */
/* return NULL; */
/* } else */
/* filebin.seekg(-8208,ios_base::cur); */
/* return data; */
/* } */
/* memcpy(data+(pn-1)*packetSize, packet, packetSize); */
/* np++; */
/* if (np==nPackets) */
/* break; */
/* if (pn==nPackets) */
/* break; */
/* } */
/* } */
/* } */
/* if (np==0){ */
/* cout << "?"; */
/* delete [] data; */
/* return NULL; */
/* }// else if (np<nPackets) */
/* // cout << "Frame " << fnum << " lost " << nPackets-np << " packets " << endl; */
/* return data; */
/* }; */
/* int getPacketNumber(int x, int y) {return dataMap[y][x]/8208;}; */
/* virtual char *readNextFrame(ifstream &filebin) { */
/* int fnum=-1, np; */
/* return readNextFrame(filebin, fnum, np); */
/* }; */
};
#endif

View File

@@ -0,0 +1,294 @@
#ifndef MOENCH04REC10GBDATA_H
#define MOENCH04REC10GBDATA_H
#include "slsDetectorData.h"
//#define VERSION_V2
/**
@short structure for a Detector Packet or Image Header
@li frameNumber is the frame number
@li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others)
@li packetNumber is the packet number
@li bunchId is the bunch id from beamline
@li timestamp is the time stamp with 10 MHz clock
@li modId is the unique module id (unique even for left, right, top, bottom)
@li xCoord is the x coordinate in the complete detector system
@li yCoord is the y coordinate in the complete detector system
@li zCoord is the z coordinate in the complete detector system
@li debug is for debugging purposes
@li roundRNumber is the round robin set number
@li detType is the detector type see :: detectorType
@li version is the version number of this structure format
*/
typedef struct {
uint64_t frameNumber; /**< is the frame number */
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */
uint32_t packetNumber; /**< is the packet number */
uint64_t bunchId; /**< is the bunch id from beamline */
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
uint32_t debug; /**< is for debugging purposes */
uint16_t roundRNumber; /**< is the round robin set number */
uint8_t detType; /**< is the detector type see :: detectorType */
uint8_t version; /**< is the version number of this structure format */
uint64_t packetCaught[8]; /**< is the version number of this structure format */
} sls_detector_header;
class moench04CtbReceiver10GbData : public slsDetectorData<uint16_t> {
private:
int iframe;
int nadc;
int sc_width;
int sc_height;
const int aSamples;
const int dSamples;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
moench04CtbReceiver10GbData(int nas=5000, int nds=0): slsDetectorData<uint16_t>(400, 400, nas*2*32+sizeof(sls_detector_header)+nds*8), aSamples(nas), dSamples(nds) {
int nadc=32;
int sc_width=25;
int sc_height=200;
int adc_nr[32]={9, 8,11,10,13,12,15,14,1,0,3,2,5,4,7,6,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24 };
int row, col;
int isample;
int iadc;
int ix, iy;
int npackets=40;
int i;
int adc4(0);
for (int ip=0; ip<npackets; ip++) {
for (int is=0; is<128; is++) {
for (iadc=0; iadc<nadc; iadc++) {
i=128*ip+is;
adc4=(int)iadc/4;
if (i<sc_width*sc_height) {
// for (int i=0; i<sc_width*sc_height; i++) {
col=(adc_nr[iadc]%16)*sc_width+(i%sc_width);
// if (adc4%2==0) {
if (iadc/16>0) {
row=199-i/sc_width;
} else {
row=200+i/sc_width;
}
if (nds>0)
dataMap[row][col]=sizeof(sls_detector_header)+((nadc+4)*i+iadc)*2;//+16*(ip+1);
else
dataMap[row][col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=aSamples*2*32)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
}
}
}
}
int ipacket;
int ibyte;
int ii=0;
for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){
xmap[ibyte]=-1;
ymap[ibyte]=-1;
}
/* int off=sizeof(sls_detector_header)/2; */
/* for (ibyte=0; ibyte<dataSize; ibyte++) { */
/* for (ipacket=0; ipacket<npackets; ipacket++) { */
/* for (ibyte=0; ibyte< 8192/2; ibyte++) { */
/* i=ipacket*8208/2+ibyte; */
/* isample=ii/nadc; */
/* if (isample<nSamples) { */
/* iadc=ii%nadc; */
/* adc4 = (int)iadc/4; */
/* ix=isample%sc_width; */
/* iy=isample/sc_width; */
/* if (adc4%2==0) { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2-1-iy; */
/* } else { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2+iy; */
/* } */
/* } */
/* ii++; */
/* // } */
/* } */
/* } */
iframe=0;
// cout << "data struct created" << endl;
};
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
/* class jfrau_packet_header_t { */
/* public: */
/* unsigned char reserved[4]; */
/* unsigned char packetNumber[1]; */
/* unsigned char frameNumber[3]; */
/* unsigned char bunchid[8]; */
/* }; */
int getFrameNumber(char *buff){return ((sls_detector_header*)buff)->frameNumber;};//*((int*)(buff+5))&0xffffff;};
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
*/
int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
/* /\** */
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
/* \param data pointer to the memory to be analyzed */
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
/* \param dsize size of the memory slot to be analyzed */
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
/* *\/ */
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
/* /\** */
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
/* \param filebin input file stream (binary) */
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
/* *\/ */
/* virtual char *readNextFrame(ifstream &filebin){ */
/* // int afifo_length=0; */
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* // cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
virtual char *readNextFrame(ifstream &filebin) {
int ff=-1, np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int &ff) {
int np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
char *data=new char[dataSize];
char *d=readNextFrame(filebin, ff, np, data);
if (d==NULL) {delete [] data; data=NULL;}
return data;
}
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
char *retval=0;
int nd;
int fnum = -1;
np=0;
int pn;
// cout << dataSize << endl;
if (ff>=0)
fnum=ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){
ff=getFrameNumber(data);
np=getPacketNumber(data);
return data;
}
}
return NULL;
};
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize){
if (dsize<dataSize) ndata=dsize;
else ndata=dataSize;
return data;
}
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
};
#endif

View File

@@ -1,7 +1,8 @@
#ifndef MOENCH03T1ZMQDATA_H
#define MOENCH03T1ZMQDATA_H
#ifndef MOENCH04RECDATA_H
#define MOENCH04RECDATA_H
#include "slsDetectorData.h"
//#define VERSION_V2
/**
@short structure for a Detector Packet or Image Header
@li frameNumber is the frame number
@@ -32,12 +33,14 @@
uint16_t roundRNumber; /**< is the round robin set number */
uint8_t detType; /**< is the detector type see :: detectorType */
uint8_t version; /**< is the version number of this structure format */
uint64_t packetCaught[8]; /**< is the version number of this structure format */
} sls_detector_header;
class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
class moench04CtbReceiverData : public slsDetectorData<uint16_t> {
private:
@@ -45,8 +48,8 @@ class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
int nadc;
int sc_width;
int sc_height;
const int nPackets; /**<number of UDP packets constituting one frame */
const int packetSize; /**< size of a udp packet */
const int aSamples;
const int dSamples;
public:
@@ -60,16 +63,13 @@ class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
\param c crosstalk parameter for the output buffer
*/
moench03T1ReceiverData(int npackets=40, int ps=8192): slsDetectorData<uint16_t>(400, 400, ps*npackets+sizeof(sls_detector_header)), packetSize(ps), nPackets(npackets) {
moench04CtbReceiverData(int nas=5000, int nds=0): slsDetectorData<uint16_t>(400, 400, nas*2*32+sizeof(sls_detector_header)+nds*8), aSamples(nas), dSamples(nds) {
int nadc=32;
int sc_width=25;
int sc_height=200;
int adc_nr[32]={300,325,350,375,300,325,350,375, \
200,225,250,275,200,225,250,275,\
100,125,150,175,100,125,150,175,\
0,25,50,75,0,25,50,75};
int adc_nr[32]={9, 8,11,10,13,12,15,14,1,0,3,2,5,4,7,6,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24 };
int row, col;
@@ -77,7 +77,7 @@ class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
int iadc;
int ix, iy;
// int npackets=40;
int npackets=40;
int i;
int adc4(0);
@@ -89,14 +89,15 @@ class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
adc4=(int)iadc/4;
if (i<sc_width*sc_height) {
// for (int i=0; i<sc_width*sc_height; i++) {
col=adc_nr[iadc]+(i%sc_width);
if (adc4%2==0) {
col=(adc_nr[iadc]%16)*sc_width+(i%sc_width);
// if (adc4%2==0) {
if (iadc/16>0) {
row=199-i/sc_width;
} else {
row=200+i/sc_width;
}
dataMap[row][col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=8192*40)
if (dataMap[row][col]<0 || dataMap[row][col]>=aSamples*2*32)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
}
}
@@ -110,27 +111,32 @@ class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
xmap[ibyte]=-1;
ymap[ibyte]=-1;
}
int off=sizeof(sls_detector_header)/2;
for (ipacket=0; ipacket<npackets; ipacket++) {
for (ibyte=0; ibyte< 8192/2; ibyte++) {
i=ipacket*8208/2+ibyte;
isample=ii/nadc;
iadc=ii%nadc;
adc4 = (int)iadc/4;
ix=isample%sc_width;
iy=isample/sc_width;
if (adc4%2==0) {
xmap[i+off]=adc_nr[iadc]+ix;
ymap[i+off]=ny/2-1-iy;
} else {
xmap[i+off]=adc_nr[iadc]+ix;
ymap[i+off]=ny/2+iy;
}
ii++;
// }
}
}
/* int off=sizeof(sls_detector_header)/2; */
/* for (ibyte=0; ibyte<dataSize; ibyte++) { */
/* for (ipacket=0; ipacket<npackets; ipacket++) { */
/* for (ibyte=0; ibyte< 8192/2; ibyte++) { */
/* i=ipacket*8208/2+ibyte; */
/* isample=ii/nadc; */
/* if (isample<nSamples) { */
/* iadc=ii%nadc; */
/* adc4 = (int)iadc/4; */
/* ix=isample%sc_width; */
/* iy=isample/sc_width; */
/* if (adc4%2==0) { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2-1-iy; */
/* } else { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2+iy; */
/* } */
/* } */
/* ii++; */
/* // } */
/* } */
/* } */
iframe=0;
// cout << "data struct created" << endl;
@@ -167,7 +173,7 @@ class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
*/
int getPacketNumber(char *buff){((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
/* /\** */
@@ -275,7 +281,7 @@ class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
};

View File

@@ -0,0 +1,290 @@
#ifndef MOENCH04ZMQ10GBDATA_H
#define MOENCH04ZMQ10GBDATA_H
#include "slsDetectorData.h"
class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
private:
int iframe;
int nadc;
int sc_width;
int sc_height;
const int aSamples;
const int dSamples;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
//moench04CtbZmq10GbData(int nas=5000, int nds=0): slsDetectorData<uint16_t>(400, 400, nas*2*32+nds*8), aSamples(nas), dSamples(nds), nadc(32), sc_width(25), sc_height(200) {
moench04CtbZmq10GbData(int nas=5000, int nds=0): slsDetectorData<uint16_t>(400, 400, (nas > 0) && (nds>0) ? max(nas,nds)*(32*2+8) : nas*32*2+nds*8), nadc(32), sc_width(25), sc_height(200), aSamples(nas), dSamples(nds) {
/* int ds; */
/* if (nas && nds) */
/* if (nds>nas) */
/* ds=nds*(32*2+8); */
/* else */
/* ds=nas*(32*2+8); */
/* else */
/* ds=nas*32*2+nds*8; */
/* new slsDetectorData<uint16_t>(400, 400, ds); */
int adc_nr[32]={9, 8,11,10,13,12,15,14,1,0,3,2,5,4,7,6,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24 };
int row, col;
//int isample;
int iadc;
// int ix, iy;
// int npackets=40;
int i;
//int adc4(0);
for (int is=0; is<aSamples; is++) {
for (iadc=0; iadc<nadc; iadc++) {
i=is;
// adc4=(int)iadc/4;
if (i<sc_width*sc_height) {
// for (int i=0; i<sc_width*sc_height; i++) {
col=(adc_nr[iadc]%16)*sc_width+(i%sc_width);
// if (adc4%2==0) {
if (iadc<16) {
row=199-i/sc_width;
} else {
row=200+i/sc_width;
}
if (nds>0)
dataMap[row][col]=((nadc+4)*i+iadc)*2;//+16*(ip+1);
else
dataMap[row][col]=(nadc*i+iadc)*2;//+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=aSamples*2*32)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
}
}
}
/* for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){ */
/* xmap[ibyte]=-1; */
/* ymap[ibyte]=-1; */
/* } */
/* int off=sizeof(sls_detector_header)/2; */
/* for (ibyte=0; ibyte<dataSize; ibyte++) { */
/* for (ipacket=0; ipacket<npackets; ipacket++) { */
/* for (ibyte=0; ibyte< 8192/2; ibyte++) { */
/* i=ipacket*8208/2+ibyte; */
/* isample=ii/nadc; */
/* if (isample<nSamples) { */
/* iadc=ii%nadc; */
/* adc4 = (int)iadc/4; */
/* ix=isample%sc_width; */
/* iy=isample/sc_width; */
/* if (adc4%2==0) { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2-1-iy; */
/* } else { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2+iy; */
/* } */
/* } */
/* ii++; */
/* // } */
/* } */
/* } */
iframe=0;
// cout << "data struct created" << endl;
}
int getGain(char *data, int x, int y) {
// int aoff=aSamples*2*32;
int irow;
int isc=x/sc_width;
int icol=x%sc_width;
if (y<200) irow=sc_height-1-y;
else {
irow=y-sc_height;
isc++;
}
int ibit[32]={-1,-1,-1,-1,-1,-1,1,3,5,7,-1,-1,-1,-1,-1,-1,62,60,58,56,54,52,50,48,63,61,59,57,55,53,51,49};
int isample=irow*sc_width+icol;
uint64_t sample;
char *ptr;
if (isc<0 || isc>=32) return 0;
if (ibit[isc]<0 || ibit[isc]>=64) return 0;
if (dSamples>isample) {
ptr=data+32*(isample+1)+8*isample;
sample=*((uint64_t*)ptr);
cout << isc << " " << ibit[isc] << " " << isample << hex << sample << dec << endl;
if (sample & (1<<ibit[isc]))
return 1;
else
return 0;
} else
return 0;
}
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
/* class jfrau_packet_header_t { */
/* public: */
/* unsigned char reserved[4]; */
/* unsigned char packetNumber[1]; */
/* unsigned char frameNumber[3]; */
/* unsigned char bunchid[8]; */
/* }; */
int getFrameNumber(char *buff){return iframe;};//((sls_detector_header*)buff)->frameNumber;};//*((int*)(buff+5))&0xffffff;};
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
*/
//int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
/* /\** */
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
/* \param data pointer to the memory to be analyzed */
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
/* \param dsize size of the memory slot to be analyzed */
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
/* *\/ */
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
/* /\** */
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
/* \param filebin input file stream (binary) */
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
/* *\/ */
/* virtual char *readNextFrame(ifstream &filebin){ */
/* // int afifo_length=0; */
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* // cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
virtual char *readNextFrame(ifstream &filebin) {
int ff=-1, np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int &ff) {
int np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
char *data=new char[dataSize];
char *d=readNextFrame(filebin, ff, np, data);
if (d==NULL) {delete [] data; data=NULL;}
return data;
}
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
// char *retval=0;
// int nd;
// int fnum = -1;
np=0;
//int pn;
// cout << dataSize << endl;
if (ff>=0)
// fnum=ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){
ff=getFrameNumber(data);
// np=getPacketNumber(data);
return data;
}
}
return NULL;
};
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize){
if (dsize<dataSize) ndata=dsize;
else ndata=dataSize;
return data;
}
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
};
#endif

View File

@@ -0,0 +1,276 @@
#ifndef MOENCH04ZMQDATA_H
#define MOENCH04ZMQDATA_H
#include "slsDetectorData.h"
class moench04CtbZmqData : public slsDetectorData<uint16_t> {
private:
int iframe;
int nadc;
int sc_width;
int sc_height;
const int aSamples;
const int dSamples;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
(160x160 pixels, 40 packets 1286 large etc.)
\param c crosstalk parameter for the output buffer
*/
moench04CtbZmqData(int nas=5000, int nds=0): slsDetectorData<uint16_t>(400, 400, nas*2*32+nds*8), nadc(32), sc_width(25), sc_height(200), aSamples(nas), dSamples(nds) {
int adc_nr[32]={9, 8,11,10,13,12,15,14,1,0,3,2,5,4,7,6,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24 };
int row, col;
//int isample;
int iadc;
//int ix, iy;
// int npackets=40;
int i;
//int adc4(0);
for (int is=0; is<aSamples; is++) {
for (iadc=0; iadc<nadc; iadc++) {
i=is;
// adc4=(int)iadc/4;
if (i<sc_width*sc_height) {
// for (int i=0; i<sc_width*sc_height; i++) {
col=(adc_nr[iadc]%16)*sc_width+(i%sc_width);
// if (adc4%2==0) {
if (iadc<16) {
row=199-i/sc_width;
} else {
row=200+i/sc_width;
}
dataMap[row][col]=(nadc*i+iadc)*2;//+16*(ip+1);
if (dataMap[row][col]<0 || dataMap[row][col]>=aSamples*2*32)
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
}
}
}
/* for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){ */
/* xmap[ibyte]=-1; */
/* ymap[ibyte]=-1; */
/* } */
/* int off=sizeof(sls_detector_header)/2; */
/* for (ibyte=0; ibyte<dataSize; ibyte++) { */
/* for (ipacket=0; ipacket<npackets; ipacket++) { */
/* for (ibyte=0; ibyte< 8192/2; ibyte++) { */
/* i=ipacket*8208/2+ibyte; */
/* isample=ii/nadc; */
/* if (isample<nSamples) { */
/* iadc=ii%nadc; */
/* adc4 = (int)iadc/4; */
/* ix=isample%sc_width; */
/* iy=isample/sc_width; */
/* if (adc4%2==0) { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2-1-iy; */
/* } else { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2+iy; */
/* } */
/* } */
/* ii++; */
/* // } */
/* } */
/* } */
iframe=0;
// cout << "data struct created" << endl;
}
int getGain(char *data, int x, int y) {
int aoff=aSamples*2*32;
int irow;
int isc=x/sc_width;
int icol=x%sc_width;
if (y<200) irow=sc_height-1-y;
else {
irow=y-sc_height;
isc++;
}
int ibit[32]={-1,-1,-1,-1,-1,-1,1,3,5,7,-1,-1,-1,-1,-1,-1,62,60,58,56,54,52,50,48,63,61,59,57,55,53,51,49};
int isample=irow*sc_width+icol;
uint64_t sample;
char *ptr;
if (isc<0 || isc>=32) return 0;
if (ibit[isc]<0 || ibit[isc]>=64) return 0;
if (dSamples>isample) {
ptr=data+aoff+8*isample;
sample=*((uint64_t*)ptr);
cout << isc << " " << ibit[isc] << " " << isample << hex << sample << dec << endl;
if (sample & (1<<ibit[isc]))
return 1;
else
return 0;
} else
return 0;
}
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
/* class jfrau_packet_header_t { */
/* public: */
/* unsigned char reserved[4]; */
/* unsigned char packetNumber[1]; */
/* unsigned char frameNumber[3]; */
/* unsigned char bunchid[8]; */
/* }; */
int getFrameNumber(char *buff){return iframe;};//((sls_detector_header*)buff)->frameNumber;};//*((int*)(buff+5))&0xffffff;};
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
*/
//int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
/* /\** */
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
/* \param data pointer to the memory to be analyzed */
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
/* \param dsize size of the memory slot to be analyzed */
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
/* *\/ */
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
/* /\** */
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
/* \param filebin input file stream (binary) */
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
/* *\/ */
/* virtual char *readNextFrame(ifstream &filebin){ */
/* // int afifo_length=0; */
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* // cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
virtual char *readNextFrame(ifstream &filebin) {
int ff=-1, np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int &ff) {
int np=-1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
char *data=new char[dataSize];
char *d=readNextFrame(filebin, ff, np, data);
if (d==NULL) {delete [] data; data=NULL;}
return data;
}
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
// char *retval=0;
//int nd;
//int fnum = -1;
np=0;
//int pn;
// cout << dataSize << endl;
if (ff>=0)
// fnum=ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){
ff=getFrameNumber(data);
// np=getPacketNumber(data);
return data;
}
}
return NULL;
};
/**
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
\param data pointer to the memory to be analyzed
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
\param dsize size of the memory slot to be analyzed
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize){
if (dsize<dataSize) ndata=dsize;
else ndata=dataSize;
return data;
}
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
};
#endif

View File

@@ -15,9 +15,9 @@ class slsDetectorData {
const int nx; /**< Number of pixels in the x direction */
const int ny; /**< Number of pixels in the y direction */
int dataSize; /**<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)*/
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 *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) */
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 *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.
*/
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) {
xmap=new int[dsize/sizeof(dataType)];
ymap=new int[dsize/sizeof(dataType)];
int el=dsize/sizeof(dataType);
xmap=new int[el];
ymap=new int[el];
// if (dataMask==NULL) {
dataMask=new dataType*[ny];
for(int i = 0; i < ny; i++) {
dataMask[i] = new dataType[nx];
}
dataMask=new dataType[ny*nx];
// }
// if (dataMap==NULL) {
dataMap=new int*[ny];
for(int i = 0; i < ny; i++) {
dataMap[i] = new int[nx];
}
dataMap=new int[ny*nx];
// }
// if (dataROIMask==NULL) {
dataROIMask=new int*[ny];
for(int i = 0; i < ny; i++) {
dataROIMask[i] = new int[nx];
for (int j=0; j<nx; j++)
dataROIMask[i][j]=1;
}
dataROIMask=new int [ny*nx];
// }
for (int ip=0; ip<dsize/sizeof(dataType); ip++){
for (int ip=0; ip<el; ip++){
xmap[ip]=-1;
ymap[ip]=-1;
}
@@ -77,11 +67,6 @@ class slsDetectorData {
};
virtual ~slsDetectorData() {
for(int i = 0; i < ny; i++) {
delete [] dataMap[i];
delete [] dataMask[i];
delete [] dataROIMask[i];
}
delete [] dataMap;
delete [] dataMask;
delete [] dataROIMask;
@@ -94,14 +79,14 @@ class slsDetectorData {
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);)
*/
void setDataMap(int **dMap=NULL) {
void setDataMap(int *dMap=NULL) {
int ip=0;
int ix, iy;
if (dMap==NULL) {
for (iy=0; iy<ny; iy++) {
for (ix=0; ix<nx; ix++) {
dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);
dataMap[iy*nx+ix]=(iy*nx+ix)*sizeof(dataType);
}
}
} else {
@@ -109,7 +94,7 @@ class slsDetectorData {
for (iy=0; iy<ny; iy++){
// cout << iy << endl;
for (ix=0; ix<nx; ix++) {
dataMap[iy][ix]=dMap[iy][ix];
dataMap[iy*nx+ix]=dMap[iy*nx+ix];
// cout << ix << " " << iy << endl;
/*ip=dataMap[ix][iy]/sizeof(dataType);
xmap[ip]=ix;
@@ -119,7 +104,7 @@ class slsDetectorData {
}
for (iy=0; iy<ny; iy++){
for (ix=0; ix<nx; ix++) {
ip=dataMap[iy][ix]/sizeof(dataType);
ip=dataMap[iy*nx+ix]/sizeof(dataType);
xmap[ip]=ix;
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)
*/
void setDataMask(dataType **dMask=NULL){
void setDataMask(dataType *dMask=NULL){
if (dMask!=NULL) {
for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++)
dataMask[iy][ix]=dMask[iy][ix];
dataMask[iy*nx+ix]=dMask[iy*nx+ix];
} else {
for (int iy=0; iy<ny; iy++)
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.
*/
void setDataROIMask(int **dROI=NULL){
void setDataROIMask(int *dROI=NULL){
if (dROI!=NULL) {
for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++)
dataROIMask[iy][ix]=dROI[iy][ix];
dataROIMask[iy*nx+ix]=dROI[iy*nx+ix];
} else {
for (int iy=0; iy<ny; iy++)
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
\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
\param ix channel x coordinate
\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
*/
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
@@ -204,38 +189,33 @@ class slsDetectorData {
virtual void getPixel(int ip, int &x, int &y) {x=xmap[ip]; y=ymap[ip];};
virtual dataType **getData(char *ptr, int dsize=-1) {
dataType **data;
virtual dataType *getData(char *ptr, int dsize=-1) {
int el=dsize/sizeof(dataType);
dataType *data;
int ix,iy;
data=new dataType*[ny];
for(int i = 0; i < ny; i++) {
data[i]=new dataType[nx];
}
data=new dataType[ny*nx];
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);
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;
};
virtual double **getImage(char *ptr, int dsize=-1) {
virtual double *getImage(char *ptr, int dsize=-1) {
double **data;
double *data;
int ix,iy;
data=new double*[ny];
for(int i = 0; i < ny; i++) {
data[i]=new double[nx];
}
data=new double[ny*nx];
int el=dsize/sizeof(dataType);
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);
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;
@@ -251,16 +231,19 @@ class slsDetectorData {
*/
virtual dataType getChannel(char *data, int ix, int iy=0) {
dataType m=0, d=0;
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) {
dataType m=0, d=0, *p;
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy*nx+ix]>=0 && dataMap[iy*nx+ix]<dataSize) {
// cout << ix << " " << iy << " " ;
//cout << dataMap[ix][iy] << " " << (void*)data << " " << dataSize<< endl;
m=dataMask[iy][ix];
d=*((dataType*)(data+dataMap[iy][ix]));
m=dataMask[iy*nx+ix];
p=(dataType*)(data+dataMap[iy*nx+ix]);
d=*p;
}
return d^m;
};
virtual int getGain(char *data, int ix, int iy=0){return 0;};
/**
Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded.

View File

@@ -1,534 +0,0 @@
#include "energyCalibration.h"
#ifdef __CINT
#define MYROOT
#endif
#ifdef MYROOT
#include <TMath.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TGraphErrors.h>
#endif
#include <iostream>
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
using namespace std;
#ifdef MYROOT
Double_t energyCalibrationFunctions::pedestal(Double_t *x, Double_t *par) {
return par[0]-par[1]*sign*x[0];
}
Double_t energyCalibrationFunctions::gaussChargeSharing(Double_t *x, Double_t *par) {
Double_t f, arg=0;
if (par[3]!=0) arg=sign*(x[0]-par[2])/par[3];
f=TMath::Exp(-1*arg*arg/2.);
f=f+par[5]/2.*(TMath::Erfc(arg/(TMath::Sqrt(2.))));
return par[4]*f+pedestal(x,par);
}
Double_t energyCalibrationFunctions::gaussChargeSharingPixel(Double_t *x, Double_t *par) {
Double_t f;
if (par[3]<=0 || par[2]*(*x)<=0 || par[5]<0 || par[4]<=0) return 0;
Double_t pp[3];
pp[0]=0;
pp[1]=par[2];
pp[2]=par[3];
f=(par[5]-par[6]*(TMath::Log(*x/par[2])))*erfBox(x,pp);
f+=par[4]*TMath::Gaus(*x, par[2], par[3], kTRUE);
return f+pedestal(x,par);
}
Double_t energyCalibrationFunctions::erfBox(Double_t *z, Double_t *par) {
Double_t m=par[0];
Double_t M=par[1];
if (par[0]>par[1]) {
m=par[1];
M=par[0];
}
if (m==M)
return 0;
if (par[2]<=0) {
if (*z>=m && *z<=M)
return 1./(M-m);
else
return 0;
}
return (TMath::Erfc((z[0]-M)/par[2])-TMath::Erfc((z[0]-m)/par[2]))*0.5/(M-m);
}
// basic erf function
Double_t energyCalibrationFunctions::erfFunction(Double_t *x, Double_t *par) {
double arg=0;
if (par[1]!=0) arg=(par[0]-x[0])/par[1];
return ((par[2]/2.*(1+TMath::Erf(sign*arg/(TMath::Sqrt(2))))));
};
Double_t energyCalibrationFunctions::erfFunctionChargeSharing(Double_t *x, Double_t *par) {
Double_t f;
f=erfFunction(x, par+2)*(1+par[5]*(par[2]-x[0]))+par[0]-par[1]*x[0]*sign;
return f;
};
Double_t energyCalibrationFunctions::erfFuncFluo(Double_t *x, Double_t *par) {
Double_t f;
f=erfFunctionChargeSharing(x, par)+erfFunction(x, par+6)*(1+par[9]*(par[6]-x[0]));
return f;
};
#endif
double energyCalibrationFunctions::median(double *x, int n){
// sorts x into xmed array and returns median
// n is number of values already in the xmed array
double xmed[n];
int k,i,j;
for (i=0; i<n; i++) {
k=0;
for (j=0; j<n; j++) {
if(*(x+i)>*(x+j))
k++;
if (*(x+i)==*(x+j)) {
if (i>j)
k++;
}
}
xmed[k]=*(x+i);
}
k=n/2;
return xmed[k];
}
int energyCalibrationFunctions::quick_select(int arr[], int n){
int low, high ;
int median;
int middle, ll, hh;
low = 0 ; high = n-1 ; median = (low + high) / 2;
for (;;) {
if (high <= low) /* One element only */
return arr[median] ;
if (high == low + 1) { /* Two elements only */
if (arr[low] > arr[high])
ELEM_SWAP(arr[low], arr[high]) ;
return arr[median] ;
}
/* Find median of low, middle and high items; swap into position low */
middle = (low + high) / 2;
if (arr[middle] > arr[high]) ELEM_SWAP(arr[middle], arr[high]) ;
if (arr[low] > arr[high]) ELEM_SWAP(arr[low], arr[high]) ;
if (arr[middle] > arr[low]) ELEM_SWAP(arr[middle], arr[low]) ;
/* Swap low item (now in position middle) into position (low+1) */
ELEM_SWAP(arr[middle], arr[low+1]) ;
/* Nibble from each end towards middle, swapping items when stuck */
ll = low + 1;
hh = high;
for (;;) {
do ll++; while (arr[low] > arr[ll]) ;
do hh--; while (arr[hh] > arr[low]) ;
if (hh < ll)
break;
ELEM_SWAP(arr[ll], arr[hh]) ;
}
/* Swap middle item (in position low) back into correct position */
ELEM_SWAP(arr[low], arr[hh]) ;
/* Re-set active partition */
if (hh <= median)
low = ll;
if (hh >= median)
high = hh - 1;
}
}
int energyCalibrationFunctions::kth_smallest(int *a, int n, int k){
register int i,j,l,m ;
register double x ;
l=0 ; m=n-1 ;
while (l<m) {
x=a[k] ;
i=l ;
j=m ;
do {
while (a[i]<x) i++ ;
while (x<a[j]) j-- ;
if (i<=j) {
ELEM_SWAP(a[i],a[j]) ;
i++ ; j-- ;
}
} while (i<=j) ;
if (j<k) l=i ;
if (k<i) m=j ;
}
return a[k] ;
}
#ifdef MYROOT
Double_t energyCalibrationFunctions::spectrum(Double_t *x, Double_t *par) {
return gaussChargeSharing(x,par);
}
Double_t energyCalibrationFunctions::spectrumPixel(Double_t *x, Double_t *par) {
return gaussChargeSharingPixel(x,par);
}
Double_t energyCalibrationFunctions::scurve(Double_t *x, Double_t *par) {
return erfFunctionChargeSharing(x,par);
}
Double_t energyCalibrationFunctions::scurveFluo(Double_t *x, Double_t *par) {
return erfFuncFluo(x,par);
}
#endif
energyCalibration::energyCalibration() :
#ifdef MYROOT
fit_min(-1),
fit_max(-1),
bg_offset(-1),
bg_slope(-1),
flex(-1),
noise(-1),
ampl(-1),
cs_slope(-1),
fscurve(NULL),
fspectrum(NULL),
#endif
funcs(NULL),
plot_flag(1), // fit parameters output to screen
cs_flag(1)
{
#ifdef MYROOT
funcs=new energyCalibrationFunctions();
fscurve=new TF1("fscurve",funcs,&energyCalibrationFunctions::scurve,0,1000,6,"energyCalibrationFunctions","scurve");
fscurve->SetParNames("Background Offset","Background Slope","Inflection Point","Noise RMS", "Number of Photons","Charge Sharing Slope");
fspectrum=new TF1("fspectrum",funcs,&energyCalibrationFunctions::spectrum,0,1000,6,"energyCalibrationFunctions","spectrum");
fspectrum->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal");
fspixel=new TF1("fspixel",funcs,&energyCalibrationFunctions::spectrumPixel,0,1000,7,"energyCalibrationFunctions","spectrumPixel");
fspixel->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal","Corner");
#endif
}
void energyCalibration::fixParameter(int ip, Double_t val){
fscurve->FixParameter(ip, val);
fspectrum->FixParameter(ip, val);
}
void energyCalibration::releaseParameter(int ip){
fscurve->ReleaseParameter(ip);
fspectrum->ReleaseParameter(ip);
}
energyCalibration::~energyCalibration(){
#ifdef MYROOT
delete fscurve;
delete fspectrum;
#endif
}
#ifdef MYROOT
TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch, int direction) {
if (h2==NULL || nch==0)
return NULL;
double *x=new double[nch];
TH1F *h1=NULL;
double val=-1;
if (direction==0) {
h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax());
for (int ib=0; ib<h1->GetXaxis()->GetNbins(); ib++) {
for (int ich=0; ich<nch; ich++) {
x[ich]=h2->GetBinContent(ch0+ich+1,ib+1);
}
val=energyCalibrationFunctions::median(x, nch);
h1->SetBinContent(ib+1,val);
}
} else if (direction==1) {
h1=new TH1F("median","Median",h2->GetXaxis()->GetNbins(),h2->GetXaxis()->GetXmin(),h2->GetXaxis()->GetXmax());
for (int ib=0; ib<h1->GetYaxis()->GetNbins(); ib++) {
for (int ich=0; ich<nch; ich++) {
x[ich]=h2->GetBinContent(ib+1,ch0+ich+1);
}
val=energyCalibrationFunctions::median(x, nch);
h1->SetBinContent(ib+1,val);
}
}
delete [] x;
return h1;
}
void energyCalibration::setStartParameters(Double_t *par){
bg_offset=par[0];
bg_slope=par[1];
flex=par[2];
noise=par[3];
ampl=par[4];
cs_slope=par[5];
}
void energyCalibration::getStartParameters(Double_t *par){
par[0]=bg_offset;
par[1]=bg_slope;
par[2]=flex;
par[3]=noise;
par[4]=ampl;
par[5]=cs_slope;
}
#endif
int energyCalibration::setChargeSharing(int p) {
if (p>=0) {
cs_flag=p;
#ifdef MYROOT
if (p) {
fscurve->ReleaseParameter(5);
fspectrum->ReleaseParameter(1);
} else {
fscurve->FixParameter(5,0);
fspectrum->FixParameter(1,0);
}
#endif
}
return cs_flag;
}
#ifdef MYROOT
void energyCalibration::initFitFunction(TF1 *fun, TH1 *h1) {
Double_t min=fit_min, max=fit_max;
Double_t mypar[6];
if (max==-1)
max=h1->GetXaxis()->GetXmax();
if (min==-1)
min=h1->GetXaxis()->GetXmin();
if (bg_offset==-1)
mypar[0]=0;
else
mypar[0]=bg_offset;
if (bg_slope==-1)
mypar[1]=0;
else
mypar[1]=bg_slope;
if (flex==-1)
mypar[2]=(min+max)/2.;
else
mypar[2]=flex;
if (noise==-1)
mypar[3]=0.1;
else
mypar[3]=noise;
if (ampl==-1)
mypar[4]=h1->GetBinContent(h1->GetXaxis()->FindBin(0.5*(max+min)));
else
mypar[4]=ampl;
if (cs_slope==-1)
mypar[5]=0;
else
mypar[5]=cs_slope;
fun->SetParameters(mypar);
fun->SetRange(min,max);
}
TF1* energyCalibration::fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar) {
TF1* fitfun;
char fname[100];
strcpy(fname, fun->GetName());
if (plot_flag) {
h1->Fit(fname,"R0Q");
} else
h1->Fit(fname,"R0Q");
fitfun= h1->GetFunction(fname);
fitfun->GetParameters(mypar);
for (int ip=0; ip<6; ip++) {
emypar[ip]=fitfun->GetParError(ip);
}
return fitfun;
}
TF1* energyCalibration::fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar) {
initFitFunction(fscurve,h1);
return fitFunction(fscurve, h1, mypar, emypar);
}
TF1* energyCalibration::fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar) {
initFitFunction(fspectrum,h1);
return fitFunction(fspectrum, h1, mypar, emypar);
}
TF1* energyCalibration::fitSpectrumPixel(TH1 *h1, Double_t *mypar, Double_t *emypar) {
initFitFunction(fspixel,h1);
return fitFunction(fspixel, h1, mypar, emypar);
}
TGraphErrors* energyCalibration::linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff) {
TGraphErrors *gr;
Double_t mypar[2];
gr = new TGraphErrors(nscan,en,fl,een,efl);
if (plot_flag) {
gr->Fit("pol1");
gr->SetMarkerStyle(20);
} else
gr->Fit("pol1","0Q");
TF1 *fitfun= gr->GetFunction("pol1");
fitfun->GetParameters(mypar);
egain=fitfun->GetParError(1);
eoff=fitfun->GetParError(0);
gain=funcs->setScanSign()*mypar[1];
off=mypar[0];
return gr;
}
TGraphErrors* energyCalibration::calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral) {
TH1F *h;
Double_t mypar[6], emypar[6];
Double_t fl[nscan], efl[nscan];
for (int ien=0; ien<nscan; ien++) {
h=h1[ien];
if (integral)
fitSCurve(h,mypar,emypar);
else
fitSpectrum(h,mypar,emypar);
fl[ien]=mypar[2];
efl[ien]=emypar[2];
}
return linearCalibration(nscan,en,een,fl,efl,gain,off, egain, eoff);
}
#endif

View File

@@ -0,0 +1,65 @@
#ifndef GHOSTSUMMATION_H
#define GHOSTSUMMATION_H
#include <cmath>
#include "slsDetectorData.h"
template <class dataType> class ghostSummation {
/** @short virtual calss to handle ghosting*/
public:
/** constructor
\param xt crosstalk
*/
ghostSummation(slsDetectorData<dataType> *d, double xt) : xtalk(xt),det(d), nx(1), ny(1) {
if (det)
det->getDetectorSize(nx,ny);
ghost=new double[nx*ny];
};
ghostSummation(ghostSummation *orig) {
xtalk=orig->xtalk;
det=orig->det;
nx=1;
ny=1;
det->getDetectorSize(nx,ny);
ghost=new double[nx*ny];
}
~ghostSummation() {delete [] ghost;};
virtual ghostSummation *Clone() {
return new ghostSummation(this);
}
double getXTalk(){return xtalk;};
void setXTalk(double g) {xtalk=g;};
virtual double calcGhost(char *data, int ix, int iy=1){ghost[iy*nx+ix]=0; return 0;};
virtual void calcGhost(char *data){
for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++)
ghost[iy*nx+ix]=calcGhost(data, ix, iy);
}
virtual double getGhost(int ix, int iy) {
if (ix<0 || ix>=nx || iy<0 || iy>=ny) return 0;
return ghost[iy*nx+ix];
}
protected:
double xtalk;
slsDetectorData<dataType> *det;
double *ghost;
int nx, ny;
};
#endif

View File

@@ -1,30 +0,0 @@
#ifndef GOTTHARDDOUBLECOMMONMODESUBTRACTION_H
#define GOTTHARDDOUBLECOMMONMODESUBTRACTION_H
#include "commonModeSubtractionNew.h"
class gotthardDoubleModuleCommonModeSubtraction : public commonModeSubtraction {
/** @short class to calculate the common mode of the pedestals based on an approximated moving average*/
public:
/** constructor
\param nn number of samples for the moving average to calculate the average common mode
\param iroi number of regions on which one can calculate the common mode separately. Defaults to 1 i.e. whole detector
*/
gotthardDoubleModuleCommonModeSubtraction(int ns=3) : commonModeSubtraction(2, ns) {};
/**
gets the common mode ROI for pixel ix, iy
*/
virtual int getROI(int ix, int iy){return ix%2;};
};
#endif

View File

@@ -1,22 +0,0 @@
CBFLIBDIR=/afs/psi.ch/project/sls_det_software/CBFlib-0.9.5
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o ../tiffIO.cpp
ZMQLIB=../../slsReceiverSoftware/include
INCDIR=-I.. -I../../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I. -I../interpolations -I../dataStructures
LIBHDF5=-L$(CBFLIBDIR)/lib/ -lhdf5
LDFLAG= -L/usr/lib64/ -lpthread
#-L../../bin
MAIN=gotthard25umZmqAnalysis.C
#DESTDIR?=../bin
all: gotthard25umOnTheFlyAnalysis gotthard25umZmq
gotthard25umOnTheFlyAnalysis: $(MAIN) $(INCS) clean
g++ -o gotthard25umOnTheAnalysis $(MAIN) -lm -ltiff -lstdc++ $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF)
gotthard25umZmq: $(MAIN) $(INCS) clean
g++ -o gotthard25umZmq $(MAIN) -lm -ltiff -lstdc++ $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DZMQ -L$(ZMQLIB) -lzmq
clean:
rm -f gotthard25umOnTheFlyAnalysis

View File

@@ -0,0 +1,40 @@
detsizechan 2560 1
hostname bchip074+bchip075+
#hostname bchip092+bchip093+
settingsdir settingsdir/gotthard
angdir 1.000000
caldir settingsdir/gotthard
0:extsig:0 trigger_in_rising_edge
0:rx_tcpport 1954
0:rx_udpport 50001
0:vhighvoltage 0
#0:rx_zmqip pc8829
#0:rx_zmqport 30003
#0:zmqip pc8829
#0:zmqport 40003
1:extsig:0 trigger_in_rising_edge
1:rx_tcpport 1955
1:rx_udpport 50002
#1:detectorip 10.1.1.52
1:vhighvoltage 0
#1:rx_zmqip pc8829
#1:rx_zmqport 30004
#1:zmqip pc8829
#1:zmqport 40004
r_readfreq 1
rx_datastream 1
#rx_udpip 10.1.1.100
rx_hostname pc8498
rx_datastream 1
outdir /tmp/
angconv none
threaded 1

View File

@@ -1,517 +0,0 @@
#include "sls_receiver_defs.h"
//#ifdef ZMQ
#include "ZmqSocket.h"
//#endif
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
//#include <deque>
//#include <list>
//#include <queue>
#include <fstream>
#include <cstring>
//#define BCHIP074_BCHIP075
#include "gotthardModuleDataNew.h"
#include "gotthardDoubleModuleDataNew.h"
#include "gotthardDoubleModuleCommonModeSubtractionNew.h"
#include "singlePhotonDetector.h"
//#include "interpolatingDetector.h"
//#include "linearInterpolation.h"
#include "multiThreadedAnalogDetector.h"
#include <ctime>
#define NC 1280
#define NR 1
//#include "tiffIO.h"
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
int main(int argc, char *argv[]){
//void *gotthardProcessFrame() {
int fifosize=1000;
int nthreads=1;
int nph, nph1;
int etabins=550;
double etamin=-1, etamax=2;
int nsubpix=1;
float *etah=new float[etabins*etabins];
int *heta, *himage;
int offset=48;
#ifdef ZMQ
offset=0;
#endif
#ifndef ZMQ
offset=48;
#endif
//commonModeSubtraction *cm=NULL;
gotthardDoubleModuleCommonModeSubtraction *cm=new gotthardDoubleModuleCommonModeSubtraction();
gotthardModuleDataNew *decoder=new gotthardModuleDataNew();
gotthardDoubleModuleDataNew *det=new gotthardDoubleModuleDataNew(offset);
singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, cm, 1000, 100);
// analogDetector<uint16_t> *filter=new analogDetector<uint16_t>(det, 1, cm, 1000);
// analogDetector<uint16_t> *filter_nocm=new analogDetector<uint16_t>(det, 1, NULL, 1000);
filter->setROI(0,2560,0,1);
char *buff;//[2*(48+1280*2)];
char *buff0;
char *buff1;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
mt->setFrameMode(eFrame);
// mt->setFrameMode(eFrame);
// mt->setFrameMode(ePedestal);
mt->StartThreads();
mt->popFree(buff);
buff0=buff;
buff1=buff+offset*2+1280*2;
int photons[1280*2];
int nf=0;
int ok=0;
std::time_t end_time;
//int16_t dout[1280*2];
int iFrame=-1;
int np=-1;
nph=0;
nph1=0;
//int np;
int iph;
int data_ready=1;
int *image;
int length;
int nnx, nny,nns;
int nix, niy,nis;
// infinite loop
int ix, iy, isx, isy;
filter->getImageSize(nnx, nny,nns);
int16_t *dout=new int16_t [nnx*nny];
#ifdef ZMQ
if (argc < 3 ) {
cprintf(RED, "Help: %s [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n",argv[0]);
return EXIT_FAILURE;
}
// receive parameters
bool send = false;
char* socketip=argv[1];
uint32_t portnum = atoi(argv[2]);
int size = nnx*nny*2;
// send parameters if any
char* socketip2 = 0;
uint32_t portnum2 = 0;
if (argc > 3) {
send = true;
socketip2 = argv[3];
portnum2 = atoi(argv[4]);
}
cout << "\nrx socket ip : " << socketip <<
"\nrx port num : " << portnum ;
if (send) {
cout << "\nsd socket ip : " << socketip2 <<
"\nsd port num : " << portnum2;
}
cout << endl;
// receive socket
ZmqSocket* zmqsocket0 = new ZmqSocket(socketip,portnum);
if (zmqsocket0->IsError()) {
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
delete zmqsocket0;
return EXIT_FAILURE;
}
ZmqSocket* zmqsocket1 = new ZmqSocket(socketip,portnum+1);
if (zmqsocket1->IsError()) {
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum+1, socketip);
delete zmqsocket1;
delete zmqsocket0;
return EXIT_FAILURE;
}
zmqsocket0->Connect();
printf("Zmq Client 0 at %s\n", zmqsocket0->GetZmqServerAddress());
zmqsocket1->Connect();
printf("Zmq Client 1 at %s\n", zmqsocket1->GetZmqServerAddress());
// send socket
ZmqSocket* zmqsocket2 = 0;
ZmqSocket* zmqsocket3 = 0;
if (send) {
zmqsocket2 = new ZmqSocket(portnum2, socketip2);
if (zmqsocket2->IsError()) {
bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
delete zmqsocket2;
delete zmqsocket1;
delete zmqsocket0;
return EXIT_FAILURE;
}
zmqsocket3 = new ZmqSocket(portnum2+1, socketip2);
if (zmqsocket3->IsError()) {
bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2+1, socketip2);
delete zmqsocket3;
delete zmqsocket2;
delete zmqsocket1;
delete zmqsocket0;
return EXIT_FAILURE;
}
zmqsocket2->Connect();
printf("Zmq Server 0 started at %s\n", zmqsocket2->GetZmqServerAddress());
zmqsocket3->Connect();
printf("Zmq Server 1 started at %s\n", zmqsocket3->GetZmqServerAddress());
}
uint64_t acqIndex1 = -1;
uint64_t frameIndex1 = -1;
uint32_t subframeIndex1 = -1;
uint64_t fileindex1 = -1;
string filename1 = "";
uint64_t acqIndex0 = -1;
uint64_t frameIndex0 = -1;
uint32_t subframeIndex0 = -1;
uint64_t fileindex0 = -1;
string filename0 = "";
int eoa0=0;
int eoa1=0;
#endif
char ofname[10000];
char fn0[10000], fn1[10000];
FILE *fout=NULL;
FILE *fclust=NULL;
for (int i=0; i<nnx; i++)
dout[i]=0;
char fname0[10000], fname1[10000];
int irun;
#ifndef ZMQ
char ff[10000];
if (argc < 6 ) {
cprintf(RED, "Help: %s [indir] [fformat] [runmin] [runmax] [out file format]\n",argv[0]);
return EXIT_FAILURE;
}
char *indir=argv[1];
char *fformat=argv[2];
int runmin=atoi(argv[3]);
int runmax=atoi(argv[4]);
char *outdir=argv[5];
sprintf(ff,"%s/%s",indir,fformat);
// strcpy(fformat,"/external_pool/gotthard_data/datadir_gotthardI/bchip074075/20170731/Xray/xray_15kV_200uA_5us_d%d_f000000000000_0.raw");
// sprintf(fname0,fformat,0,0);
// sprintf(fname1,fformat,1,1);
ifstream filebin0,filebin1;
for (irun=runmin; irun<runmax; irun++) {
sprintf(fname0,ff,0,irun);
sprintf(fname1,ff,1,irun);
sprintf(ofname,outdir,irun);
filebin0.open((const char *)(fname0), ios::in | ios::binary);
filebin1.open((const char *)(fname1), ios::in | ios::binary);
if (filebin0.is_open() && filebin1.is_open()) {
cout << "Opened file " << fname0<< endl;
cout << "Opened file " << fname1<< endl;
nf=0;
iFrame=-1;
while ((decoder->readNextFrame(filebin0, iFrame, np, buff0)) && (decoder->readNextFrame(filebin1, iFrame, np, buff1))) {
#endif
#ifdef ZMQ
int end_of_acquisition;
while(1) {
end_of_acquisition=0;
eoa0=0;
eoa1=0;
// cout << "Receive header " << nf << endl;
if (!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) {
// cout << "************************************************************************** packet0!*****************************"<< endl;
eoa0=1;
end_of_acquisition++;
}
if (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1)) {
//cout << "************************************************************************** packet1!*****************************"<< endl;
eoa1=1;
end_of_acquisition++;
}
// if ((!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) && (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1))){
if (end_of_acquisition==0) {
if (acqIndex0!=acqIndex1)
cout << "different acquisition indexes " << acqIndex0 << " and " << acqIndex1 << endl;
if (frameIndex0!=frameIndex1)
cout << "different frame indexes " << frameIndex0 << " and " << frameIndex1 << endl;
while (frameIndex0<frameIndex1) {
cout << "aligning det 0 " << endl;
length = zmqsocket0->ReceiveData(0, buff0, size/2);
if (!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) {
end_of_acquisition++;
eoa0=1;
break;
}
}
while (frameIndex1<frameIndex0) {
cout << "aligning det 1 " << endl;
length = zmqsocket1->ReceiveData(0, buff1, size/2);
if (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1)) {
end_of_acquisition++;
eoa1=1;
break;
}
}
}
if (eoa0!=eoa1) {
while (eoa0<1) {
length = zmqsocket0->ReceiveData(0, buff0, size/2);
if (!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) {
end_of_acquisition++;
eoa0=1;
}
}
while (eoa1<1) {
length = zmqsocket1->ReceiveData(0, buff1, size/2);
if (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1)) {
end_of_acquisition++;
eoa1=1;
}
}
}
if (end_of_acquisition) {
// cout << "************************************************************************** END OF FRAME" << end_of_acquisition << " !*****************************"<< endl;
// return 0;
sprintf(ofname,"%s_%d.ph",fn0,irun);
while (mt->isBusy()) {;}
image=filter->getImage();
if (image) {
fout=fopen(ofname,"w");
cout << nf << "*****************" << endl;
for (int i=0; i<2560; i++) {
fprintf(fout,"%d %d\n",i,image[i]);
dout[i]=image[i];
if (dout[i]<0)
dout[i]=0;
}
fclose(fout);
}
if (send) {
zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fn0, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket3->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fn1, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket2->SendData((char*)dout,size/2);
zmqsocket3->SendData(((char*)dout)+size/2,size/2);
// // cprintf(GREEN, "Sent Data\n");
zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
zmqsocket3->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
}
//mt->setFrameMode(eFrame);
filter->clearImage();
// std::time(&end_time);
// cout << std::ctime(&end_time) << " " << nf << endl;
fclose(fclust);
fclust=NULL;
continue;
}
if (fclust==NULL) {
strcpy(fn0,filename0.c_str());
strcpy(fn1,filename1.c_str());
sprintf(ofname,"%s_%d.clust",fn0,irun);
fclust=fopen(ofname,"w");
while (mt->isBusy()) {;}
mt->setFilePointer(fclust);
}
// strcpy(fn0,filename0.c_str());
// strcpy(fn1,filename1.c_str());
// cout << "Receive data " << nf << endl;
length = zmqsocket0->ReceiveData(0, buff0, size/2);
length += zmqsocket1->ReceiveData(0, buff1, size/2);
irun=fileindex0;
// // if (nf>100)
// // mt->setFrameMode(eFrame);
// //filter->clearImage();
#endif
mt->pushData(buff);
mt->nextThread();
// cout << "==" << nf << endl;
// while (mt->isBusy()) {;}
// image=filter->getImage();
// if (image) {
// for (int i=0; i<2560; i++) {
// // if (i<512)
// // fprintf(fout,"%d %d\n",i,image[i]);
// dout[i]=filter->subtractPedestal(buff,i,0,1);//image[i];//filter->getPedestal(i,0);//
// if (dout[i]<0)
// dout[i]=0;
// // cout << i << " " << image[i] << " " << dout[i] << endl;
// }
// }
// if (send) {
// strcpy(fname0,filename0.c_str());
// strcpy(fname1,filename1.c_str());
// // zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,16,fileindex,400,400,400*400, acqIndex,frameIndex,fname, acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname0, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
// zmqsocket3->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname1, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
// zmqsocket2->SendData((char*)dout,size/2);
// zmqsocket3->SendData(((char*)dout)+size/2,size/2);
// // cprintf(GREEN, "Sent Data\n");
// // zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
// // zmqsocket3->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
// // cprintf(RED, "Received %d frames\n", nf);
// }
mt->popFree(buff);
buff0=buff;
buff1=buff+offset*2+1280*2;
nf++;
#ifndef ZMQ
while (mt->isBusy()) {;}
image=filter->getImage();
if (image) {
fout=fopen(ofname,"w");
//cout << nf << "*****************" << endl;
for (int i=0; i<512; i++) {
fprintf(fout,"%d %d\n",i,image[i]);
}
fclose(fout);
}
filter->clearImage();
iFrame=-1;
}
filebin0.close();
filebin1.close();
}
else
cout << "Could not open file " << fname0<< " or " << fname1 << endl;
#endif
}
return NULL;
}

View File

@@ -0,0 +1,14 @@
slsReceiver --rx_tcpport 1954 &
slsReceiver --rx_tcpport 1955 &
./gotthard25umZmq pc8829 30003 129.129.202.98 40003 &
slsDetectorGui -f examples/bchip2modules_pc8829.config &
sls_detector_put settings veryhighgain
sls_detector_put exptime 0.000005
sls_detector_put period 0.01
sls_detector_put vhighvoltage 90

View File

@@ -46,11 +46,16 @@ class interpolatingDetector : public singlePhotonDetector {
int sign=1,
commonModeSubtraction *cm=NULL,
int nped=1000,
int nd=100, int nnx=-1, int nny=-1) :
singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0) {
int nd=100, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation<uint16_t> *gs=NULL) :
singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny, gm, gs) , interp(inte), id(0) {
//cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl;
fi=new pthread_mutex_t ;
if (pthread_mutex_init(fi, NULL) != 0)
{
printf("\n mutex init failed\n");
}
};
@@ -107,11 +112,11 @@ class interpolatingDetector : public singlePhotonDetector {
singlePhotonDetector::clearImage();
};
int getImageSize(int &nnx, int &nny, int &ns) {
int getImageSize(int &nnx, int &nny, int &nsx, int &nsy) {
if (interp)
return interp->getImageSize(nnx, nny, ns);
return interp->getImageSize(nnx, nny, nsx, nsy);
else
return analogDetector<uint16_t>::getImageSize(nnx, nny, ns);
return analogDetector<uint16_t>::getImageSize(nnx, nny, nsx, nsy);
};
@@ -139,8 +144,8 @@ class interpolatingDetector : public singlePhotonDetector {
nph=addFrame(data,val,0);
if (interp)
return interp->getInterpolatedImage();
else
singlePhotonDetector::getImage();
//else
return singlePhotonDetector::getImage();
//return NULL;
};
@@ -233,7 +238,7 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
};
virtual slsInterpolation *setInterpolation(slsInterpolation *ii){
int ok;
// int ok;
interp=ii;
/* pthread_mutex_lock(fi);
if (interp)
@@ -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 setNSubPixels(int ns) {
if (interp) {
pthread_mutex_lock(fi);

View File

@@ -13,7 +13,7 @@
class eta2InterpolationBase : public virtual etaInterpolationBase {
public:
eta2InterpolationBase(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) {
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; */
@@ -33,11 +33,11 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
{
double sDum[2][2];
double tot, totquad;
double etax,etay;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixels>2)
if (nSubPixelsX>2 || nSubPixelsY>2)
calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
@@ -49,11 +49,11 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
{
double sDum[2][2];
double tot, totquad;
double etax,etay;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixels>2)
if (nSubPixelsX>2 || nSubPixelsY>2 )
calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
@@ -71,7 +71,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
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, yoff;
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
@@ -92,14 +92,15 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
default:
;
}
double etax, etay;
if (nSubPixels>2) {
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);
}
@@ -109,7 +110,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
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, yoff;
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
@@ -131,8 +132,8 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
default:
;
}
double etax, etay;
if (nSubPixels>2) {
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];
@@ -181,31 +182,31 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
}
if (nSubPixels>2) {
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
ex=(etax-etamin)/etastep;
ey=(etay-etamin)/etastep;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
cout << "x*"<< ex << endl;
ex=0;
}
if (ex>=nbeta) {
if (ex>=nbetaX) {
cout << "x?"<< ex << endl;
ex=nbeta-1;
ex=nbetaX-1;
}
if (ey<0) {
cout << "y*"<< ey << endl;
cout << "y*"<< ey << " " << nbetaY << endl;
ey=0;
}
if (ey>=nbeta) {
cout << "y?"<< ey << endl;
ey=nbeta-1;
if (ey>=nbetaY) {
cout << "y?"<< ey << " " << nbetaY << endl;
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbeta+ex)]))+dX ;///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbeta+ex)]))+dY ;///((double)nSubPixels);
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;
@@ -222,7 +223,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
double cc[2][2];
int xoff, yoff;
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
@@ -260,7 +261,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
double cc[2][2];
int xoff, yoff;
int xoff=0, yoff=0;
switch (quad) {
case BOTTOM_LEFT:
@@ -308,11 +309,12 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
int corner;
corner=calcQuad(cluster, tot, totquad, sDum);
// int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
double xpos_eta,ypos_eta;
double dX,dY;
//double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
@@ -324,11 +326,12 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
int corner;
corner=calcQuad(cluster, tot, totquad, sDum);
//int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
double xpos_eta,ypos_eta;
double dX,dY;
// double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
@@ -344,10 +347,10 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastep;
ey=(etay-etamin)/etastep;
if (ey<nbeta && ex<nbeta && ex>=0 && ey>=0)
heta[ey*nbeta+ex]++;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
@@ -357,22 +360,22 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
// cout << "ff" << endl;
calcDiff(1, hhx, hhy); //get flat
double avg=0;
for (ipx=0; ipx<nSubPixels; ipx++)
for (ipy=0; ipy<nSubPixels; ipy++)
avg+=flat[ipx+ipy*nSubPixels];
avg/=nSubPixels*nSubPixels;
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<nSubPixels*nPixelsX; ibx++) {
ipx=ibx%nSubPixels-nSubPixels/2;
if (ipx<0) ipx=nSubPixels+ipx;
for (int iby=0 ; iby<nSubPixels*nPixelsY; iby++) {
ipy=iby%nSubPixels-nSubPixels/2;
if (ipy<0) ipy=nSubPixels+ipy;
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*nSubPixels]>0)
hintcorr[ibx+iby*nSubPixels*nPixelsX]=hint[ibx+iby*nSubPixels*nPixelsX]*(avg/flat[ipx+ipy*nSubPixels]);
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*nSubPixels*nPixelsX]=hint[ibx+iby*nSubPixels*nPixelsX];
hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX];
}

View File

@@ -13,35 +13,12 @@
class eta3InterpolationBase : public virtual etaInterpolationBase {
public:
eta3InterpolationBase(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) {
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; */
/* } */
if (etamin>=etamax) {
etamin=-1;
etamax=1;
}
etastep=(etamax-etamin)/nbeta;
#ifdef MYROOT1
delete heta;
delete hhx;
delete hhy;
heta=new TH2D("heta","heta",nbeta,etamin,etamax,nbeta,etamin,etamax);
hhx=new TH2D("hhx","hhx",nbeta,etamin,etamax,nbeta,etamin,etamax);
hhy=new TH2D("hhy","hhy",nbeta,etamin,etamax,nbeta,etamin,etamax);
#endif
#ifndef MYROOT1
/* delete [] heta; */
/* delete [] hhx; */
/* delete [] hhy; */
/* heta=new int[nbeta*nbeta]; */
/* hhx=new float[nbeta*nbeta]; */
/* hhy=new float[nbeta*nbeta]; */
#endif
// cout << nbeta << " " << etamin << " " << etamax << endl;
};
@@ -59,10 +36,10 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
//////////// /*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, totquad;
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, totquad);
int corner=calcEta3(data,etax,etay, tot);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
@@ -72,11 +49,11 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
//double sDum[2][2];
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, totquad);
int corner=calcEta3(data,etax,etay, tot);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
@@ -88,7 +65,7 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
double etax, etay;
if (nSubPixels>2) {
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
@@ -101,7 +78,7 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
double etax, etay;
if (nSubPixels>2) {
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
@@ -117,38 +94,38 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
double xpos_eta=0,ypos_eta=0;
int ex,ey;
if (nSubPixels>2) {
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
#ifdef MYROOT1
xpos_eta=(hhx->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixels);
ypos_eta=(hhy->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixels);
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)/etastep;
ey=(etay-etamin)/etastep;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x*"<< ex << endl; */
ex=0;
}
if (ex>=nbeta) {
if (ex>=nbetaX) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x?"<< ex << endl; */
ex=nbeta-1;
ex=nbetaX-1;
}
if (ey<0) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y*"<< ey << endl; */
ey=0;
}
if (ey>=nbeta) {
if (ey>=nbetaY) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y?"<< ey << endl; */
ey=nbeta-1;
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbeta+ex)]));///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbeta+ex)]));///((double)nSubPixels);
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]));///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]));///((double)nSubPixels);
#endif
@@ -265,10 +242,10 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastep;
ey=(etay-etamin)/etastep;
if (ey<nbeta && ex<nbeta && ex>=0 && ey>=0)
heta[ey*nbeta+ex]++;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};

View File

@@ -7,7 +7,7 @@
#include <TH2D.h>
#include <TH2F.h>
#endif
#include <cmath>
#include "slsInterpolation.h"
#include "tiffIO.h"
@@ -15,44 +15,51 @@ class etaInterpolationBase : public slsInterpolation {
public:
etaInterpolationBase(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : slsInterpolation(nx,ny,ns), hhx(NULL), hhy(NULL), heta(NULL), nbeta(nb), etamin(emin), etamax(emax) {
etaInterpolationBase(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : slsInterpolation(nx,ny,ns,nsy), hhx(NULL), hhy(NULL), heta(NULL), nbetaX(nb), nbetaY(nby), etamin(emin), etamax(emax) {
// cout << "eb " << nb << " " << emin << " " << emax << endl;
// cout << nb << " " << etamin << " " << etamax << endl;
if (nbeta<=0) {
if (nbetaX<=0) {
//cout << "aaa:" <<endl;
nbeta=nSubPixels*10;
nbetaX=nSubPixelsX*10;
}
if (nbetaY<=0) {
//cout << "aaa:" <<endl;
nbetaY=nSubPixelsY*10;
}
if (etamin>=etamax) {
etamin=-1;
etamax=2;
}
etastep=(etamax-etamin)/nbeta;
heta=new int[nbeta*nbeta];
hhx=new float[nbeta*nbeta];
hhy=new float[nbeta*nbeta];
etastepX=(etamax-etamin)/nbetaX;
etastepY=(etamax-etamin)/nbetaY;
heta=new int[nbetaX*nbetaY];
hhx=new float[nbetaX*nbetaY];
hhy=new float[nbetaX*nbetaY];
rangeMin=etamin;
rangeMax=etamax;
flat= new double[nSubPixels*nSubPixels];
hintcorr=new int [nSubPixels*nSubPixels*nPixelsX*nPixelsY];
flat= new double[nSubPixelsX*nSubPixelsY];
hintcorr=new int [nSubPixelsX*nSubPixelsY*nPixelsX*nPixelsY];
};
etaInterpolationBase(etaInterpolationBase *orig): slsInterpolation(orig){
nbeta=orig->nbeta;
nbetaX=orig->nbetaX;
nbetaY=orig->nbetaY;
etamin=orig->etamin;
etamax=orig->etamax;
rangeMin=orig->rangeMin;
rangeMax=orig->rangeMax;
etastep=(etamax-etamin)/nbeta;
heta=new int[nbeta*nbeta];
memcpy(heta,orig->heta,nbeta*nbeta*sizeof(int));
hhx=new float[nbeta*nbeta];
memcpy(hhx,orig->hhx,nbeta*nbeta*sizeof(float));
hhy=new float[nbeta*nbeta];
memcpy(hhy,orig->hhy,nbeta*nbeta*sizeof(float));
hintcorr=new int [nSubPixels*nSubPixels*nPixelsX*nPixelsY];
etastepX=(etamax-etamin)/nbetaX;
etastepY=(etamax-etamin)/nbetaY;
heta=new int[nbetaX*nbetaY];
memcpy(heta,orig->heta,nbetaX*nbetaY*sizeof(int));
hhx=new float[nbetaX*nbetaY];
memcpy(hhx,orig->hhx,nbetaX*nbetaY*sizeof(float));
hhy=new float[nbetaX*nbetaY];
memcpy(hhy,orig->hhy,nbetaX*nbetaY*sizeof(float));
hintcorr=new int [nSubPixelsX*nSubPixelsY*nPixelsX*nPixelsY];
};
@@ -61,7 +68,7 @@ class etaInterpolationBase : public slsInterpolation {
virtual void resetFlatField() {
for (int ibx=0; ibx<nbeta*nbeta; ibx++) {
for (int ibx=0; ibx<nbetaX*nbetaY; ibx++) {
heta[ibx]=0;
hhx[ibx]=0;
hhy[ibx]=0;
@@ -70,13 +77,16 @@ class etaInterpolationBase : public slsInterpolation {
};
int *setEta(int *h, int nb=-1, double emin=1, double emax=0)
int *setEta(int *h, int nb=-1, int nby=-1, double emin=1, double emax=0)
{
if (h) {
if (heta) delete [] heta;
heta=h;
nbeta=nb;
if (nb<=0) nbeta=nSubPixels*10;
nbetaX=nb;
nbetaY=nby;
if (nbetaX<=0) nbetaX=nSubPixelsX*10;
if (nbetaY<=0) nbetaY=nSubPixelsY*10;
etamin=emin;
etamax=emax;
if (etamin>=etamax) {
@@ -85,22 +95,24 @@ class etaInterpolationBase : public slsInterpolation {
}
rangeMin=etamin;
rangeMax=etamax;
etastep=(etamax-etamin)/nbeta;
etastepX=(etamax-etamin)/nbetaX;
etastepY=(etamax-etamin)/nbetaY;
}
return heta;
};
int *setFlatField(int *h, int nb=-1, double emin=1, double emax=0)
int *setFlatField(int *h, int nb=-1, int nby=-1, double emin=1, double emax=0)
{
return setEta(h, nb, emin, emax);
return setEta(h, nb, nby, emin, emax);
};
int *getFlatField(){return setEta(NULL);};
int *getFlatField(int &nb, double &emin, double &emax){
nb=nbeta;
int *getFlatField(int &nb, int &nby, double &emin, double &emax){
nb=nbetaX;
nby=nbetaY;
emin=etamin;
emax=etamax;
return getFlatField();
@@ -109,13 +121,13 @@ class etaInterpolationBase : public slsInterpolation {
void *writeFlatField(const char * imgname) {
float *gm=NULL;
gm=new float[nbeta*nbeta];
for (int ix=0; ix<nbeta; ix++) {
for (int iy=0; iy<nbeta; iy++) {
gm[iy*nbeta+ix]=heta[iy*nbeta+ix];
gm=new float[nbetaX*nbetaY];
for (int ix=0; ix<nbetaX; ix++) {
for (int iy=0; iy<nbetaY; iy++) {
gm[iy*nbetaX+ix]=heta[iy*nbetaX+ix];
}
}
WriteToTiff(gm, imgname, nbeta, nbeta);
WriteToTiff(gm, imgname, nbetaX, nbetaY);
delete [] gm;
return NULL;
};
@@ -129,16 +141,18 @@ class etaInterpolationBase : public slsInterpolation {
etamax=2;
}
etastep=(etamax-etamin)/nbeta;
etastepX=(etamax-etamin)/nbetaX;
etastepY=(etamax-etamin)/nbetaY;
uint32 nnx;
uint32 nny;
float *gm=ReadFromTiff(imgname, nnx, nny);
if (nnx!=nny) {
cout << "different number of bins in x " << nnx << " and y " << nny<< " !"<< endl;
cout << "Aborting read"<< endl;
return 0;
}
nbeta=nnx;
/* if (nnx!=nny) { */
/* cout << "different number of bins in x " << nnx << " and y " << nny<< " !"<< endl; */
/* cout << "Aborting read"<< endl; */
/* return 0; */
/* } */
nbetaX=nnx;
nbetaY=nny;
if (gm) {
if (heta) {
delete [] heta;
@@ -146,13 +160,13 @@ class etaInterpolationBase : public slsInterpolation {
delete [] hhy;
}
heta=new int[nbeta*nbeta];
hhx=new float[nbeta*nbeta];
hhy=new float[nbeta*nbeta];
heta=new int[nbetaX*nbetaY];
hhx=new float[nbetaX*nbetaY];
hhy=new float[nbetaX*nbetaY];
for (int ix=0; ix<nbeta; ix++) {
for (int iy=0; iy<nbeta; iy++) {
heta[iy*nbeta+ix]=gm[iy*nbeta+ix];
for (int ix=0; ix<nbetaX; ix++) {
for (int iy=0; iy<nbetaY; iy++) {
heta[iy*nbetaX+ix]=gm[iy*nbetaX+ix];
}
}
delete [] gm;
@@ -178,10 +192,10 @@ float *gethhx()
};
virtual int addToFlatField(double etax, double etay){
int ex,ey;
ex=(etax-etamin)/etastep;
ey=(etay-etamin)/etastep;
if (ey<nbeta && ex<nbeta && ex>=0 && ey>=0)
heta[ey*nbeta+ex]++;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
return 0;
};
@@ -190,85 +204,85 @@ float *gethhx()
void debugSaveAll(int ind=0) {
int ib, ibx, iby;
int ibx, iby;
char tit[10000];
float tot_eta=0;
float *etah=new float[nbeta*nbeta];
int etabins=nbeta;
float *etah=new float[nbetaX*nbetaY];
// int etabins=nbeta;
int ibb=0;
for (int ii=0; ii<etabins*etabins; ii++) {
for (int ii=0; ii<nbetaX*nbetaY; ii++) {
etah[ii]=heta[ii];
tot_eta+=heta[ii];
}
sprintf(tit,"/scratch/eta.tiff",ind);
WriteToTiff(etah, tit, etabins, etabins);
sprintf(tit,"/scratch/eta_%d.tiff",ind);
WriteToTiff(etah, tit, nbetaX, nbetaY);
for (int ii=0; ii<etabins*etabins; ii++) {
ibb=(hhx[ii]*nSubPixels);
for (int ii=0; ii<nbetaX*nbetaY; ii++) {
ibb=(hhx[ii]*nSubPixelsX);
etah[ii]=ibb;
}
sprintf(tit,"/scratch/eta_hhx_%d.tiff",ind);
WriteToTiff(etah, tit, etabins, etabins);
WriteToTiff(etah, tit, nbetaX, nbetaY);
for (int ii=0; ii<etabins*etabins; ii++) {
ibb=hhy[ii]*nSubPixels;
for (int ii=0; ii<nbetaX*nbetaY; ii++) {
ibb=hhy[ii]*nSubPixelsY;
etah[ii]=ibb;
}
sprintf(tit,"/scratch/eta_hhy_%d.tiff",ind);
WriteToTiff(etah, tit, etabins, etabins);
WriteToTiff(etah, tit, nbetaX, nbetaY);
float *ftest=new float[nSubPixels*nSubPixels];
float *ftest=new float[nSubPixelsX*nSubPixelsY];
for (int ib=0; ib<nSubPixels*nSubPixels; ib++) ftest[ib]=0;
for (int ib=0; ib<nSubPixelsX*nSubPixelsY; ib++) ftest[ib]=0;
//int ibx=0, iby=0;
for (int ii=0; ii<nbeta*nbeta; ii++) {
for (int ii=0; ii<nbetaX*nbetaY; ii++) {
ibx=nSubPixels*hhx[ii];
iby=nSubPixels*hhy[ii];
ibx=nSubPixelsX*hhx[ii];
iby=nSubPixelsY*hhy[ii];
if (ibx<0) ibx=0;
if (iby<0) iby=0;
if (ibx>=nSubPixels) ibx=nSubPixels-1;
if (iby>=nSubPixels) iby=nSubPixels-1;
if (ibx>=nSubPixelsX) ibx=nSubPixelsX-1;
if (iby>=nSubPixelsY) iby=nSubPixelsY-1;
if (ibx>=0 && ibx<nSubPixels && iby>=0 && iby<nSubPixels) {
if (ibx>=0 && ibx<nSubPixelsX && iby>=0 && iby<nSubPixelsY) {
//
// if (ibx>0 && iby>0) cout << ibx << " " << iby << " " << ii << endl;
ftest[ibx+iby*nSubPixels]+=heta[ii];
ftest[ibx+iby*nSubPixelsX]+=heta[ii];
} else
cout << "Bad interpolation "<< ii << " " << ibx << " " << iby<< endl;
}
sprintf(tit,"/scratch/ftest_%d.tiff",ind);
WriteToTiff(ftest, tit, nSubPixels, nSubPixels);
WriteToTiff(ftest, tit, nSubPixelsX, nSubPixelsY);
//int ibx=0, iby=0;
tot_eta/=nSubPixels*nSubPixels;
tot_eta/=nSubPixelsX*nSubPixelsY;
int nbad=0;
for (int ii=0; ii<etabins*etabins; ii++) {
ibx=nSubPixels*hhx[ii];
iby=nSubPixels*hhy[ii];
if (ftest[ibx+iby*nSubPixels]<tot_eta*0.5) {
for (int ii=0; ii<nbetaX*nbetaY; ii++) {
ibx=nSubPixelsX*hhx[ii];
iby=nSubPixelsY*hhy[ii];
if (ftest[ibx+iby*nSubPixelsX]<tot_eta*0.5) {
etah[ii]=1;
nbad++;
} else if(ftest[ibx+iby*nSubPixels]>tot_eta*2.){
} else if(ftest[ibx+iby*nSubPixelsX]>tot_eta*2.){
etah[ii]=2;
nbad++;
} else
etah[ii]=0;
}
sprintf(tit,"/scratch/eta_bad_%d.tiff",ind);
WriteToTiff(etah, tit, etabins, etabins);
WriteToTiff(etah, tit, nbetaX, nbetaY);
// cout << "Index: " << ind << "\t Bad bins: "<< nbad << endl;
//int ibx=0, iby=0;
@@ -284,48 +298,46 @@ float *gethhx()
double calcDiff(double avg, float *hx, float *hy) {
//double p_tot=0;
double diff=0, d;
double bsize=1./nSubPixels;
//double bsize=1./nSubPixels;
int nbad=0;
double p_tot_x[nSubPixels], p_tot_y[nSubPixels], p_tot[nSubPixels*nSubPixels];
double maxdiff=0, mindiff=avg*nSubPixels*nSubPixels;
double p_tot_x[nSubPixelsX], p_tot_y[nSubPixelsY], p_tot[nSubPixelsX*nSubPixelsY];
double maxdiff=0, mindiff=avg*nSubPixelsX*nSubPixelsY;
int ipx, ipy;
for (ipy=0; ipy<nSubPixels; ipy++) {
for (ipx=0; ipx<nSubPixels; ipx++) {
p_tot[ipx+ipy*nSubPixels]=0;
for (ipy=0; ipy<nSubPixelsY; ipy++) {
for (ipx=0; ipx<nSubPixelsX; ipx++) {
p_tot[ipx+ipy*nSubPixelsX]=0;
}
p_tot_y[ipy]=0;
p_tot_x[ipy]=0;
}
for (int ibx=0; ibx<nbeta; ibx++) {
for (int iby=0; iby<nbeta; iby++) {
ipx=hx[ibx+iby*nbeta]*nSubPixels;
for (int ibx=0; ibx<nbetaX; ibx++) {
for (int iby=0; iby<nbetaY; iby++) {
ipx=hx[ibx+iby*nbetaX]*nSubPixelsX;
if (ipx<0) ipx=0;
if (ipx>=nSubPixels) ipx=nSubPixels-1;
if (ipx>=nSubPixelsX) ipx=nSubPixelsX-1;
ipy=hy[ibx+iby*nbeta]*nSubPixels;
ipy=hy[ibx+iby*nbetaX]*nSubPixelsY;
if (ipy<0) ipy=0;
if (ipy>=nSubPixels) ipy=nSubPixels-1;
if (ipy>=nSubPixelsY) ipy=nSubPixelsY-1;
p_tot[ipx+ipy*nSubPixels]+=heta[ibx+iby*nbeta];
p_tot_y[ipy]+=heta[ibx+iby*nbeta];
p_tot_x[ipx]+=heta[ibx+iby*nbeta];
p_tot[ipx+ipy*nSubPixelsX]+=heta[ibx+iby*nbetaX];
p_tot_y[ipy]+=heta[ibx+iby*nbetaX];
p_tot_x[ipx]+=heta[ibx+iby*nbetaX];
}
}
// cout << endl << endl;
for (ipy=0; ipy<nSubPixels; ipy++) {
for (ipy=0; ipy<nSubPixelsY; ipy++) {
cout.width(5);
//flat_y[ipy]=p_tot_y[ipy];//avg/nSubPixels;
for (ipx=0; ipx<nSubPixels; ipx++) {
for (ipx=0; ipx<nSubPixelsX; ipx++) {
// flat_x[ipx]=p_tot_x[ipx];///avg/nSubPixels;
flat[ipx+nSubPixels*ipy]=p_tot[ipx+nSubPixels*ipy];///avg;
d=p_tot[ipx+nSubPixels*ipy]-avg;
flat[ipx+nSubPixelsX*ipy]=p_tot[ipx+nSubPixelsX*ipy];///avg;
d=p_tot[ipx+nSubPixelsX*ipy]-avg;
if (d<0) d*=-1.;
if (d>5*sqrt(avg) )
nbad++;
@@ -351,11 +363,11 @@ float *gethhx()
return sqrt(diff);
}
int *heta;
float *hhx;
float *hhy;
int nbeta;
double etamin, etamax, etastep;
int *heta;
int nbetaX, nbetaY;
double etamin, etamax, etastepX, etastepY;
double rangeMin, rangeMax;

View File

@@ -9,7 +9,7 @@
class etaInterpolationPosXY : public virtual etaInterpolationBase{
public:
etaInterpolationPosXY(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){
etaInterpolationPosXY(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 << "epxy " << nb << " " << emin << " " << emax << endl; cout << nbeta << " " << etamin << " " << etamax << endl;
};
@@ -24,122 +24,136 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
virtual void prepareInterpolation(int &ok)
{
ok=1;
#ifdef MYROOT1
if (hhx) delete hhx;
if (hhy) delete hhy;
hhx=new TH2D("hhx","hhx",heta->GetNbinsX(),heta->GetXaxis()->GetXmin(),heta->GetXaxis()->GetXmax(), heta->GetNbinsY(),heta->GetYaxis()->GetXmin(),heta->GetYaxis()->GetXmax());
hhy=new TH2D("hhy","hhy",heta->GetNbinsX(),heta->GetXaxis()->GetXmin(),heta->GetXaxis()->GetXmax(), heta->GetNbinsY(),heta->GetYaxis()->GetXmin(),heta->GetYaxis()->GetXmax());
#endif
///*Eta Distribution Rebinning*///
double bsize=1./nSubPixels; //precision
// double bsize=1./nSubPixels; //precision
// cout<<"nPixelsX = "<<nPixelsX<<" nPixelsY = "<<nPixelsY<<" nSubPixels = "<<nSubPixels<<endl;
double tot_eta=0;
double tot_eta_x=0;
double tot_eta_y=0;
for (int ip=0; ip<nbeta*nbeta; ip++)
for (int ip=0; ip<nbetaX*nbetaY; ip++)
tot_eta+=heta[ip];
cout << "total eta entries is :"<< tot_eta << endl;
if (tot_eta<=0) {ok=0; return;};
double hx[nbeta]; //profile x
double hy[nbeta]; //profile y
double hix[nbeta]; //integral of projection x
double hiy[nbeta]; //integral of projection y
int ii=0;
double hx[nbetaX]; //profile x
double hy[nbetaY]; //profile y
double hix[nbetaX]; //integral of projection x
double hiy[nbetaY]; //integral of projection y
// int ii=0;
double etax, etay;
for (int ib=0; ib<nbeta; ib++) {
for (int ib=0; ib<nbetaX; ib++) {
tot_eta_x=0;
tot_eta_y=0;
//tot_eta_y=0;
for (int iby=0; iby<nbeta; iby++) {
etax=etamin+iby*etastep;
for (int iby=0; iby<nbetaY; iby++) {
etay=etamin+iby*etastepY;
//cout << etax << endl;
if (etax>=0 && etax<=1)
hx[iby]=heta[iby+ib*nbeta];
else {
hx[iby]=0;
}
// tot_eta_x+=hx[iby];
if (etax>=0 && etax<=1)
hy[iby]=heta[ib+iby*nbeta];
if (etay>=0 && etay<=1)
hy[iby]=heta[ib+iby*nbetaX];
else
hy[iby]=0;
// tot_eta_y+=hy[iby];
}
hix[0]=hx[0];
hiy[0]=hy[0];
for (int iby=1; iby<nbeta; iby++) {
hix[iby]=hix[iby-1]+hx[iby];
for (int iby=1; iby<nbetaY; iby++) {
hiy[iby]=hiy[iby-1]+hy[iby];
}
ii=0;
tot_eta_x=hix[nbeta-1]+1;
tot_eta_y=hiy[nbeta-1]+1;
tot_eta_y=hiy[nbetaY-1]+1;
for (int ibx=0; ibx<nbeta; ibx++) {
if (tot_eta_x<=0) {
hhx[ibx+ib*nbeta]=-1;
//ii=(ibx)/nbeta;
} else //if (hix[ibx]>(ii+1)*tot_eta_x*bsize)
{
//if (hix[ibx]>tot_eta_x*(ii+1)/nSubPixels) ii++;
hhx[ibx+ib*nbeta]=hix[ibx]/tot_eta_x;
}
}
/* if (ii!=(nSubPixels-1)) */
/* cout << ib << " x " << tot_eta_x << " " << (ii+1)*tot_eta_x*bsize << " " << ii << " " << hix[nbeta-1]<< endl; */
ii=0;
for (int ibx=0; ibx<nbeta; ibx++) {
for (int iby=0; iby<nbetaY; iby++) {
if (tot_eta_y<=0) {
hhy[ib+ibx*nbeta]=-1;
hhy[ib+iby*nbetaX]=-1;
//ii=(ibx*nSubPixels)/nbeta;
} else {
//if (hiy[ibx]>tot_eta_y*(ii+1)/nSubPixels) ii++;
hhy[ib+ibx*nbeta]=hiy[ibx]/tot_eta_y;
hhy[ib+iby*nbetaX]=hiy[iby]/tot_eta_y;
}
}
}
for (int ib=0; ib<nbetaY; ib++) {
for (int ibx=0; ibx<nbetaX; ibx++) {
etax=etamin+ibx*etastepX;
//cout << etax << endl;
if (etax>=0 && etax<=1)
hx[ibx]=heta[ibx+ib*nbetaX];
else {
hx[ibx]=0;
}
}
hix[0]=hx[0];
for (int ibx=1; ibx<nbetaX; ibx++) {
hix[ibx]=hix[ibx-1]+hx[ibx];
}
tot_eta_x=hix[nbetaX-1]+1;
for (int ibx=0; ibx<nbetaX; ibx++) {
if (tot_eta_x<=0) {
hhx[ibx+ib*nbetaX]=-1;
}
else {
hhx[ibx+ib*nbetaX]=hix[ibx]/tot_eta_x;
}
}
for (int ibx=0; ibx<nbetaX; ibx++) {
if (tot_eta_x<=0) {
hhx[ibx+ib*nbetaX]=-1;
} else {
//if (hix[ibx]>tot_eta_x*(ii+1)/nSubPixels) ii++;
hhx[ibx+ib*nbetaX]=hix[ibx]/tot_eta_x;
}
}
}
int ibx, iby, ib;
iby=0;
while (hhx[iby*nbeta+nbeta/2]<0) iby++;
while (hhx[iby*nbetaY+nbetaY/2]<0) iby++;
for (ib=0; ib<iby;ib++) {
for (ibx=0; ibx<nbeta;ibx++)
hhx[ibx+nbeta*ib]=hhx[ibx+nbeta*iby];
for (ibx=0; ibx<nbetaX;ibx++)
hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby];
}
iby=nbeta-1;
iby=nbetaY-1;
while (hhx[iby*nbeta+nbeta/2]<0) iby--;
for (ib=iby+1; ib<nbeta;ib++) {
for (ibx=0; ibx<nbeta;ibx++)
hhx[ibx+nbeta*ib]=hhx[ibx+nbeta*iby];
while (hhx[iby*nbetaY+nbetaY/2]<0) iby--;
for (ib=iby+1; ib<nbetaY;ib++) {
for (ibx=0; ibx<nbetaX;ibx++)
hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby];
}
iby=0;
while (hhy[nbeta/2*nbeta+iby]<0) iby++;
while (hhy[nbetaX/2*nbetaX+iby]<0) iby++;
for (ib=0; ib<iby;ib++) {
for (ibx=0; ibx<nbeta;ibx++)
hhy[ib+nbeta*ibx]=hhy[iby+nbeta*ibx];
for (ibx=0; ibx<nbetaY;ibx++)
hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx];
}
iby=nbeta-1;
iby=nbetaX-1;
while (hhy[nbeta/2*nbeta+iby]<0) iby--;
for (ib=iby+1; ib<nbeta;ib++) {
for (ibx=0; ibx<nbeta;ibx++)
hhy[ib+nbeta*ibx]=hhy[iby+nbeta*ibx];
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];
}
@@ -156,9 +170,16 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
};
class eta2InterpolationPosXY : public virtual eta2InterpolationBase, public virtual etaInterpolationPosXY {
public:
eta2InterpolationPosXY(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),eta2InterpolationBase(nx,ny,ns, nb, emin,emax),etaInterpolationPosXY(nx,ny,ns, nb, 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 " << nb << " " << emin << " " << emax << endl;
};
@@ -172,8 +193,8 @@ class eta2InterpolationPosXY : public virtual eta2InterpolationBase, public virt
class eta3InterpolationPosXY : public virtual eta3InterpolationBase, public virtual etaInterpolationPosXY {
public:
eta3InterpolationPosXY(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),eta3InterpolationBase(nx,ny,ns, nb, emin,emax), etaInterpolationPosXY(nx,ny,ns, nb, emin,emax){
cout << "e3pxy " << nbeta << " " << etamin << " " << etamax << " " << nSubPixels<< endl;
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 " << nbeta << " " << etamin << " " << etamax << " " << nSubPixels<< endl;
};
eta3InterpolationPosXY(eta3InterpolationPosXY *orig): etaInterpolationBase(orig), etaInterpolationPosXY(orig) {};

View File

@@ -0,0 +1,52 @@
#ifndef INTERPOLATION_ETAVEL_H
#define INTERPOLATION_ETAVEL_H
#include <slsInterpolation.h>
#include "EtaVEL.h"
#include "TH2F.h"
//#include "EtaVEL.cpp"
//class EtaVEL;
class interpolation_EtaVEL: public slsInterpolation {
public:
interpolation_EtaVEL(int nx=40, int ny=160, int ns=25, double etamin=-0.02, double etamax=1.02, int p=0);
~interpolation_EtaVEL();
//create eta distribution, eta rebinnining etc.
//returns flat field image
void prepareInterpolation(int &ok){prepareInterpolation(ok,10000);};
void prepareInterpolation(int &ok, int maxit);
//create interpolated image
//returns interpolated image
//return position inside the pixel for the given photon
void getInterpolatedPosition(Int_t x, Int_t y, Double_t *data, Double_t &int_x, Double_t &int_y);
void getInterpolatedBin(Double_t *cluster, Int_t &int_x, Int_t &int_y);
int addToFlatField(Double_t *cluster, Double_t &etax, Double_t &etay);
int addToFlatField(Double_t etax, Double_t etay);
int setPlot(int p=-1) {if (p>=0) plot=p; return plot;};
int WriteH(){newEta->Write("newEta"); heta->Write("heta");};
EtaVEL *setEta(EtaVEL *ev){if (ev) {delete newEta; newEta=ev;} return newEta;};
TH2F *setEta(TH2F *ev){if (ev) {delete heta; heta=ev;} return heta;};
void iterate();
void DrawH();
double getChiSq(){return newEta->getChiSq();};
protected:
EtaVEL *newEta;
TH2F *heta;
int plot;
// ClassDefNV(interpolation_EtaVEL,1);
// #pragma link C++ class interpolation_EtaVEL-;
};
#endif

View File

@@ -29,19 +29,21 @@ class slsInterpolation
{
public:
slsInterpolation(int nx=400, int ny=400, int ns=25) :nPixelsX(nx), nPixelsY(ny), nSubPixels(ns), id(0) {
slsInterpolation(int nx=400, int ny=400, int ns=25, int nsy=-1) :nPixelsX(nx), nPixelsY(ny), nSubPixelsX(ns), nSubPixelsY(nsy),id(0) {
hint=new int[ns*nx*ns*ny];
if (nSubPixelsY<=0) nSubPixelsY=nSubPixelsX;
hint=new int[nSubPixelsX*nx*nSubPixelsY*ny];
};
slsInterpolation(slsInterpolation *orig){
nPixelsX=orig->nPixelsX;
nPixelsY=orig->nPixelsY;
nSubPixels=orig->nSubPixels;
nSubPixelsX=orig->nSubPixelsX;
nSubPixelsY=orig->nSubPixelsY;
hint=new int[nSubPixels*nPixelsX*nSubPixels*nPixelsY];
memcpy(hint, orig->hint,nSubPixels*nPixelsX*nSubPixels*nPixelsY*sizeof(int));
hint=new int[nSubPixelsX*nPixelsX*nSubPixelsY*nPixelsY];
memcpy(hint, orig->hint,nSubPixelsX*nPixelsX*nSubPixelsY*nPixelsY*sizeof(int));
};
@@ -51,23 +53,37 @@ class slsInterpolation
return new slsInterpolation(this);
}*/
int getNSubPixels() {return nSubPixels;};
int getNSubPixelsX() {return nSubPixelsX;};
int getNSubPixelsY() {return nSubPixelsY;};
int getNSubPixels() {if (nSubPixelsX==nSubPixelsY) return nSubPixelsX; else return 0;};
void getNSubPixels(int &nsx, int &nsy) {nsx=nSubPixelsX; nsy=nsx=nSubPixelsY;}
int setNSubPixels(int ns) {
if (ns>0 && ns!=nSubPixels) {
void setNSubPixels(int ns, int nsy=-1) {
delete [] hint;
nSubPixels=ns;
hint=new int[nSubPixels*nPixelsX*nSubPixels*nPixelsY];
}
return nSubPixels;
nSubPixelsX=ns;
if (nsy>0) nSubPixelsY=nsy;
else nSubPixelsY=ns;
hint=new int[nSubPixelsX*nPixelsX*nSubPixelsY*nPixelsY];
//return nSubPixels;
}
int getImageSize(int &nnx, int &nny, int &ns) {
nnx=nSubPixels*nPixelsX;
nny=nSubPixels*nPixelsY;
ns=nSubPixels;
return nSubPixels*nSubPixels*nPixelsX*nPixelsY;
int getImageSize(int &nnx, int &nny, int &nsx, int &nsy) {
nnx=nSubPixelsX*nPixelsX;
nny=nSubPixelsY*nPixelsY;
nsx=nSubPixelsX;
nsy=nSubPixelsY;
return nSubPixelsX*nSubPixelsY*nPixelsX*nPixelsY;
};
int getImageSize() {
return nSubPixelsX*nSubPixelsY*nPixelsX*nPixelsY;
};
@@ -92,14 +108,14 @@ class slsInterpolation
//cout << "!" <<endl;
float *gm=NULL;
int *dummy=getInterpolatedImage();
gm=new float[ nSubPixels* nSubPixels* nPixelsX*nPixelsY];
gm=new float[ nSubPixelsX* nSubPixelsY* nPixelsX*nPixelsY];
if (gm) {
for (int ix=0; ix<nPixelsX*nSubPixels; ix++) {
for (int iy=0; iy<nPixelsY*nSubPixels; iy++) {
gm[iy*nPixelsX*nSubPixels+ix]=dummy[iy*nPixelsX*nSubPixels+ix];
for (int ix=0; ix<nPixelsX*nSubPixelsX; ix++) {
for (int iy=0; iy<nPixelsY*nSubPixelsY; iy++) {
gm[iy*nPixelsX*nSubPixelsX+ix]=dummy[iy*nPixelsX*nSubPixelsX+ix];
}
}
WriteToTiff(gm, imgname,nSubPixels* nPixelsX ,nSubPixels* nPixelsY);
WriteToTiff(gm, imgname,nSubPixelsY* nPixelsX ,nSubPixelsY* nPixelsY);
delete [] gm;
} else cout << "Could not allocate float image " << endl;
return NULL;
@@ -120,9 +136,9 @@ class slsInterpolation
virtual void clearInterpolatedImage() {
for (int ix=0; ix<nPixelsX*nSubPixels; ix++) {
for (int iy=0; iy<nPixelsY*nSubPixels; iy++) {
hint[iy*nPixelsX*nSubPixels+ix]=0;
for (int ix=0; ix<nPixelsX*nSubPixelsX; ix++) {
for (int iy=0; iy<nPixelsY*nSubPixelsY; iy++) {
hint[iy*nPixelsX*nSubPixelsX+ix]=0;
}
}
@@ -133,11 +149,11 @@ class slsInterpolation
virtual int *addToImage(double int_x, double int_y){
int iy=((double)nSubPixels)*int_y;
int ix=((double)nSubPixels)*int_x;
if (ix>=0 && ix<(nPixelsX*nSubPixels) && iy<(nSubPixels*nPixelsY) && iy>=0 ){
int iy=((double)nSubPixelsY)*int_y;
int ix=((double)nSubPixelsX)*int_x;
if (ix>=0 && ix<(nPixelsX*nSubPixelsX) && iy<(nSubPixelsY*nPixelsY) && iy>=0 ){
// cout << int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << " " << hint[ix+iy*nPixelsX*nSubPixels];
(*(hint+ix+iy*nPixelsX*nSubPixels))+=1;
(*(hint+ix+iy*nPixelsX*nSubPixelsX))+=1;
// cout << " " << hint[ix+iy*nPixelsX*nSubPixels] << endl;
}// else
// cout << "bad! "<< int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << endl;
@@ -156,7 +172,7 @@ class slsInterpolation
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 *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;
@@ -180,11 +196,12 @@ class slsInterpolation
/* cluster[2]=cl+6; */
sum=0;
int xoff=0, yoff=0;
#ifndef WRITE_QUAD
double sumBL=0;
double sumTL=0;
double sumBR=0;
double sumTR=0;
int xoff=0, yoff=0;
for (int ix=0; ix<3; ix++) {
for (int iy=0; iy<3; iy++) {
sum+=cl[ix+3*iy];
@@ -204,34 +221,95 @@ class slsInterpolation
if(sumTL >= totquad){
/* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; */
/* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; */
/* #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 (sumTL ==sum) { */
/* #endif */
corner = TOP_LEFT;
totquad=sumTL;
xoff=0;
yoff=1;
/* #ifdef WRITE_QUAD */
/* } */
/* #endif */
}
if(sumBR >= totquad){
/* sDum[0][0] = cluster[0][1]; sDum[1][0] = cluster[1][1]; */
/* 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;
yoff=0;
corner = BOTTOM_RIGHT;
totquad=sumBR;
/* #ifdef WRITE_QUAD */
/* } */
/* #endif */
}
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;
yoff=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]; */
corner = TOP_RIGHT;
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 iy=0; iy<2; iy++) {
@@ -495,7 +573,7 @@ class slsInterpolation
protected:
int nPixelsX, nPixelsY;
int nSubPixels;
int nSubPixelsX, nSubPixelsY;
int id;
int *hint;
};

View File

@@ -1,44 +1,60 @@
#ifndef MOENCH03COMMONMODE_H
#define MOENCH03COMMONMODE_H
#include "commonModeSubtraction.h"
#include "commonModeSubtractionNew.h"
class moench03CommonMode : public commonModeSubtraction {
class commonModeSubtractionColumn: public commonModeSubtraction{
public:
commonModeSubtractionColumn(int nr=200) : commonModeSubtraction(800), rows(nr) {};
virtual int getROI(int ix, int iy){return ix+(iy/200)*400;};
virtual void addToCommonMode(double val, int ix=0, int iy=0) {
if (iy<rows || iy>399-rows) {
int iroi=getROI(ix,iy);
// cout << iy << " " << ix << " " << iroi ;
if (iroi>=0 && iroi<nROI) {
mean[iroi]+=val;
mean2[iroi]+=val*val;
nCm[iroi]++;
if (nCm[iroi]>rows) cout << "Too many pixels added " << nCm[iroi] << endl;
/* if (ix==10 && iy<20) */
/* cout << " ** "<<val << " " << mean[iroi] << " " << nCm[iroi] << " " << getCommonMode(ix, iy) << endl; */
}
}
};
virtual commonModeSubtractionColumn *Clone() {
return new commonModeSubtractionColumn(this->rows);
}
private:
int rows;
};
class commonModeSubtractionSuperColumn: public commonModeSubtraction{
public:
commonModeSubtractionSuperColumn() : commonModeSubtraction(32) {};
virtual int getROI(int ix, int iy){ return ix/25+(iy/200)*16;};
};
class commonModeSubtractionHalf: public commonModeSubtraction{
public:
commonModeSubtractionHalf() : commonModeSubtraction(2) {};
virtual int getROI(int ix, int iy){ (void) ix; return iy/200;};
};
class moench03CommonMode : public commonModeSubtractionColumn {
/** @short class to calculate the common mode noise for moench02 i.e. on 4 supercolumns separately */
public:
/** constructor - initalizes a commonModeSubtraction with 4 different regions of interest
\param nn number of samples for the moving average
*/
moench03CommonMode(int nn=1000) : commonModeSubtraction(nn,32){} ;
moench03CommonMode(int nr=20) : commonModeSubtractionColumn(nr){} ;
/** add value to common mode as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each;
\param val value to add to the common mode
\param ix pixel coordinate in the x direction
\param iy pixel coordinate in the y direction
*/
virtual void addToCommonMode(double val, int ix=0, int iy=0) {
// (void) iy;
int isc=ix/25+(iy/200)*16;
if (isc>=0 && isc<nROI) {
cmPed[isc]+=val;
nCm[isc]++;
}
};
/**returns common mode value as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each;
\param ix pixel coordinate in the x direction
\param iy pixel coordinate in the y direction
\returns common mode value
*/
virtual double getCommonMode(int ix=0, int iy=0) {
(void) iy;
int isc=ix/25+(iy/200)*16;
if (isc>=0 && isc<nROI) {
if (nCm[isc]>0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean();
}
return 0;
};
};

View File

@@ -0,0 +1,64 @@
#ifndef MOENCH03GHOSTSUMMATION_H
#define MOENCH03GHOSTSUMMATION_H
#include "ghostSummation.h"
class moench03GhostSummation : public ghostSummation<uint16_t> {
/** @short virtual calss to handle ghosting*/
public:
/** constructor
\param xt crosstalk
*/
moench03GhostSummation(slsDetectorData<uint16_t> *d, double xt=0.0004) : ghostSummation<uint16_t>(d, xt) {}
virtual void calcGhost(char *data){
for (int iy=0; iy<200; iy++){
for (int ix=0; ix<25; ix++){
calcGhost(data,ix,iy);
}
}
};
moench03GhostSummation(moench03GhostSummation *orig) : ghostSummation(orig) {
}
virtual moench03GhostSummation *Clone() {
return new moench03GhostSummation(this);
}
virtual double calcGhost(char *data, int x, int y=0){
int ix=x%25;
int iy=y;
if (y>=200) iy=399-y;
if (iy<0 || ix<0) return 0;
double val=0;
val=0;
for (int isc=0; isc<16; isc++) {
val+=det->getChannel(data,ix+25*isc,iy);
// cout << val << " " ;
val+=det->getChannel(data,ix+25*isc,399-iy);
// cout << val << " " ;
}
ghost[iy*nx+ix]=xtalk*val;
// if (ix==15 && iy==15) cout << ":" << ghost[iy*nx+ix] << " " << val << endl;
return ghost[iy*nx+ix];
};
virtual double getGhost(int ix, int iy) {
if (iy >=0 && iy<200) return ghost[iy*nx+(ix%25)];
if (iy<400) return ghost[(399-iy)*nx+(ix%25)];
return 0;
};
};
#endif

View File

@@ -1,7 +1,7 @@
#ifndef MOENCHCOMMONMODE_H
#define MOENCHCOMMONMODE_H
#include "commonModeSubtraction.h"
#include "commonModeSubtractionNew.h"
class moenchCommonMode : public commonModeSubtraction {
/** @short class to calculate the common mode noise for moench02 i.e. on 4 supercolumns separately */
@@ -9,35 +9,36 @@ class moenchCommonMode : public commonModeSubtraction {
/** constructor - initalizes a commonModeSubtraction with 4 different regions of interest
\param nn number of samples for the moving average
*/
moenchCommonMode(int nn=1000) : commonModeSubtraction(nn,4){} ;
moenchCommonMode(int nn=0) : commonModeSubtraction(0){} ;
/** add value to common mode as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each;
\param val value to add to the common mode
\param ix pixel coordinate in the x direction
\param iy pixel coordinate in the y direction
*/
virtual void addToCommonMode(double val, int ix=0, int iy=0) {
(void) iy;
int isc=ix/40;
if (isc>=0 && isc<nROI) {
cmPed[isc]+=val;
nCm[isc]++;
}
};
/**returns common mode value as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each;
\param ix pixel coordinate in the x direction
\param iy pixel coordinate in the y direction
\returns common mode value
*/
virtual double getCommonMode(int ix=0, int iy=0) {
(void) iy;
int isc=ix/40;
if (isc>=0 && isc<nROI) {
if (nCm[isc]>0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean();
}
return 0;
};
/* /\** add value to common mode as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each; */
/* \param val value to add to the common mode */
/* \param ix pixel coordinate in the x direction */
/* \param iy pixel coordinate in the y direction */
/* *\/ */
/* virtual void addToCommonMode(double val, int ix=0, int iy=0) { */
/* (void) iy; */
/* int isc=ix/40; */
/* if (isc>=0 && isc<nROI) { */
/* cmPed[isc]+=val; */
/* nCm[isc]++; */
/* } */
/* }; */
/* /\**returns common mode value as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each; */
/* \param ix pixel coordinate in the x direction */
/* \param iy pixel coordinate in the y direction */
/* \returns common mode value */
/* *\/ */
/* virtual double getCommonMode(int ix=0, int iy=0) { */
/* (void) iy; */
/* int isc=ix/40; */
/* if (isc>=0 && isc<nROI) { */
/* if (nCm[isc]>0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); */
/* } */
/* return 0; */
/* }; */
};

View File

@@ -1,39 +1,61 @@
#module add CBFlib/0.9.5
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include/
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 -L$(CBFLIBDIR)/lib/ -ltiff
#-L$(ZMQLIB) -lzmq
#-L../../bin
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
#-lhdf5
#DESTDIR?=../bin
all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog
all: moenchClusterFinder moenchMakeEta moenchMakeEta3 moenchInterpolation moenchInterpolation3 moenchNoInterpolation moenchPhotonCounter moenchAnalog moenchPhotonCounterNoThread moenchAnalogNoThread
moenchClusterFinder: $(MAIN) $(INCS) clean
g++ -o moenchClusterFinder $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DOLDDATA #-DNEWRECEIVER
moenchClusterFinder: moench03ClusterFinder.cpp $(INCS) clean
g++ -o moenchClusterFinder moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER
moenchMakeEta: moench03MakeEta.cpp $(INCS) clean
g++ -o moenchMakeEta moench03MakeEta.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
moenchClusterFinderHighZ: moench03ClusterFinder.cpp $(INCS) clean
g++ -o moenchClusterFinderHighZ moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER -DHIGHZ
moenchMakeEta: moench03Interpolation.cpp $(INCS) clean
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
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
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
g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF)
moenchPhotonCounter: moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchPhotonCounter moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER
g++ -o moenchPhotonCounter moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER
moenchAnalog: moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchAnalog moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER -DANALOG
g++ -o moenchAnalog moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DANALOG
moenchPhotonCounterHighZ: moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchPhotonCounterHighZ moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DHIGHZ
moenchAnalogHighZ: moenchPhotonCounter.cpp $(INCS) clean
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:
rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter
rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog moenchPhotonCounterNoThread moenchAnalogNoThread

View File

@@ -0,0 +1,46 @@
#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: moenchClusterFinderRect moenchMakeEtaRect moenchInterpolationRect moenchNoInterpolationRect moenchPhotonCounterRect moenchAnalogRect moenchMakeEtaRect1 moenchInterpolationRect1
moenchClusterFinderRect: moench03ClusterFinder.cpp $(INCS) clean
g++ -o moenchClusterFinderRect moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) -DSAVE_ALL -DNEWRECEIVER -DRECT
moenchMakeEtaRect: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchMakeEtaRect moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF -DRECT
moenchInterpolationRect: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchInterpolationRect moench03Interpolation.cpp $(LDFLAG) $(INCDIR) -DRECT
moenchNoInterpolationRect: moench03NoInterpolation.cpp $(INCS) clean
g++ -o moenchNoInterpolationRect moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) -DRECT
moenchPhotonCounterRect: moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchPhotonCounterRect moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $ -DNEWRECEIVER -DRECT
moenchAnalogRect: moenchPhotonCounter.cpp $(INCS) clean
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:
rm -f moenchClusterFinderRect moenchMakeEtaRect moenchInterpolationRect moenchNoInterpolationRect moenchPhotonCounterRect moenchAnalogRect

View File

@@ -1,10 +1,15 @@
#module add CBFlib/0.9.5
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
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 -L$(CBFLIBDIR)/lib/ -ltiff
#-L$(ZMQLIB) -lzmq
#-L../../bin
MAIN=moench03ClusterFinder.cpp
#-lhdf5
#DESTDIR?=../bin
all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog

View File

@@ -1,20 +0,0 @@
CBFLIBDIR=/afs/psi.ch/project/sls_det_software/CBFlib-0.9.5
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
INCDIR=-IslsDetectorCalibration -I../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I. -IetaVEL
LIBHDF5=-L$(CBFLIBDIR)/lib/ -lhdf5
LDFLAG= -L/usr/lib64/ -lpthread
#-L../../bin
MAIN=moench03OnTheFlyAnalysis.C
#DESTDIR?=../bin
all: moench03OnTheFlyAnalysis
moench03OnTheFlyAnalysis: $(MAIN) $(INCS) clean
g++ -o moench03OnTheFlyAnalysis $(MAIN) -lm -ltiff -lstdc++ $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
clean:
rm -f moench03OnTheFlyAnalysis

View File

@@ -1,23 +0,0 @@
CBFLIBDIR= /home/l_msdetect/CBFlib-0.9.5
ZMQLIB=../slsReceiverSoftware/include
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
INCDIR=-IslsDetectorCalibration -I../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I.
#-IetaVEL
LIBHDF5=
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -lzmq -pthread -lrt -L$(CBFLIBDIR)/lib/ -lhdf5 -ltiff -L$(ZMQLIB)
#-L../../bin
MAIN=moench03ClusterFinder.cpp
#DESTDIR?=../bin
all: moench03ClusterFinder
moench03ClusterFinder: $(MAIN) $(INCS) clean
g++ -o moenchClusterFinder $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
clean:
rm -f moench03ClusterFinder

View File

@@ -1,17 +0,0 @@
ZMQLIB=../../slsReceiverSoftware/include
INCDIR= -I$(ZMQLIB) -I. -I../dataStructures ../tiffIO.cpp -I../ -I../interpolations/
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -L$(ZMQLIB) -O3 -g
#-L../../bin -lhdf5 -L.
#DESTDIR?=../bin
all: moenchZmqProcess
moenchZmqProcess: moenchZmqProcess.cpp clean
g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP
clean:
rm -f moenchZmqProcess

View File

@@ -1,12 +1,8 @@
CBFLIBDIR=/afs/psi.ch/project/sls_det_software/CBFlib-0.9.5
CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/
ZMQLIB=../../slsReceiverSoftware/include
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
INCDIR=-I../../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I. -I../dataStructures ../tiffIO.cpp -I../ -I../interpolations/
LIBHDF5=
#-I../interpolations/etaVEL
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -lzmq -pthread -lrt -lhdf5 -ltiff -L$(ZMQLIB) -L$(CBFLIBDIR)/lib/ -O3
#-L../../bin
INCDIR= -I$(ZMQLIB) -I. -I../dataStructures ../tiffIO.cpp -I../ -I../interpolations/ -I$(CBFLIBDIR)/include/
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -lrt -L$(CBFLIBDIR)/lib/ -ltiff -L$(ZMQLIB) -O3
#-L../../bin -lhdf5 -L.
#DESTDIR?=../bin
@@ -14,7 +10,7 @@ aaa: moenchZmqProcess
all: moenchZmqClusterFinder moenchZmqInterpolating moenchZmqAnalog
moenchZmqProcess: moenchZmqProcess.cpp $(INCS) clean
moenchZmqProcess: moenchZmqProcess.cpp clean
g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ
moenchZmqInterpolating: $(MAIN) $(INCS) clean

View File

@@ -1,24 +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../../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ ../tiffIO.cpp -I../dataStructures
#LIBHDF5=
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -L$(CBFLIBDIR)/lib/ -ltiff -lhdf5
#-L$(ZMQLIB) -lzmq
#-L../../bin
MAIN=moench03ClusterFinderPhoenix.cpp
#
#DESTDIR?=../bin
all: moenchClusterFinderPhoenix
#moenchMakeEtaPhoenix moenchInterpolationPhoenix
moenchClusterFinderPhoenix: $(MAIN) $(INCS) clean
g++ -o moenchClusterFinderPhoenix $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF)
clean:
rm -f moenchClusterFinderPhoenix

View File

@@ -1,22 +0,0 @@
CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/
#ZMQLIB=../slsReceiverSoftware/include
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/
LDFLAG= ../tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -L$(CBFLIBDIR)/lib/ -ltiff
MAIN=moench03ReorderImage.cpp
all: moenchReorderImage moenchClusterFinder
moenchReorderImage: $(MAIN) $(INCS) clean
g++ -o moenchReorderImage $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER
moenchClusterFinder: moench03ClusterFinder.cpp
g++ -o moenchClusterFinder $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER
clean:
rm -f moenchReorderImage moenchClusterFinder

View File

@@ -1,27 +0,0 @@
#INCSROOT= receiverGui.h
#INCS= $(INCSROOT) moench03_receiver.h
#LINKDEF=receiverGuiLinkDef.h
#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$(ROOTSYS)/include
#-I$(CBFLIBDIR)/include/
#LIBHDF5=
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -ltiff
#-L$(CBFLIBDIR)/lib/ -lhdf5
MAIN=tiff_to_th2f.cpp
all: tiff_to_th2f
tiff_to_th2f: $(MAIN) $(INCS)
g++ -o tiff_to_th2f $(MAIN) `root-config --cflags --glibs` -lMinuit -lm -ltiff -lstdc++ $(LDFLAG) $(INCDIR) ../tiffIO.cpp
#$(LIBRARYCBF) $(LIBHDF5)
clean:
rm -f tiff_to_th2f

View File

@@ -0,0 +1,24 @@
INCDIR= -I. -I../dataStructures ../tiffIO.cpp -I../ -I../interpolations/ -I../../slsDetectorSoftware/commonFiles/ -I../../slsReceiverSoftware/include/
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -O3 -g -std=c++11 -Wall
#-L../../bin -lhdf5 -L.
#DESTDIR?=../bin
all: moenchZmqProcess moenchZmqProcessHighZ moenchZmqProcessRect
moenchZmqProcess: moenchZmqProcess.cpp clean
g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP
moenchZmqProcessRect: moenchZmqProcess.cpp clean
g++ -o moenchZmqProcessRect moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DRECT
moenchZmqProcessHighZ: moenchZmqProcess.cpp clean
g++ -o moenchZmqProcessHighZ moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DHIGHZ
clean:
rm -f moenchZmqProcess moenchZmqProcessHighZ

View File

@@ -1,6 +1,7 @@
//#include "ansi.h"
#include <iostream>
// bin/moenchClusterFinder moench03_25022020 moench_fluo_outputs flat_27keV_d0_f000000%d00000_1 0 10
//#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER
@@ -22,6 +23,10 @@
#include "moench03Ctb10GbT1Data.h"
#endif
#ifdef REORDERED
#include "moench03T1ReorderedData.h"
#endif
// #include "interpolatingDetector.h"
//#include "etaInterpolationPosXY.h"
// #include "linearInterpolation.h"
@@ -29,7 +34,9 @@
#include "multiThreadedAnalogDetector.h"
#include "singlePhotonDetector.h"
//#include "interpolatingDetector.h"
#include <string>
#include <sstream>
#include <stdio.h>
#include <map>
#include <fstream>
@@ -46,20 +53,20 @@ int main(int argc, char *argv[]) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 1;
}
int p=10000;
//int p=10000;
int fifosize=1000;
int nthreads=24;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
int nthreads=16;
//int nsubpix=25;
//int etabins=nsubpix*10;
//double etamin=-1, etamax=2;
int csize=3;
int nx=400, ny=400;
int save=1;
//int save=1;
int nsigma=5;
int nped=1000;
int ndark=100;
int ok;
int iprog=0;
//int ndark=100;
//int ok;
//int iprog=0;
@@ -83,6 +90,14 @@ int main(int argc, char *argv[]) {
cout << "OLD RECEIVER DATA!"<<endl;
#endif
#ifdef REORDERED
moench03T1ReorderedData *decoder=new moench03T1ReorderedData();
cout << "REORDERED DATA!"<<endl;
#endif
decoder->getDetectorSize(nx,ny);
cout << "nx " << nx << " ny " << ny << endl;
//moench03T1ZmqData *decoder=new moench03T1ZmqData();
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200);
@@ -96,9 +111,9 @@ int main(int argc, char *argv[]) {
// 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)];
filter->newDataSet();
@@ -108,21 +123,21 @@ int main(int argc, char *argv[]) {
cout << " data size is " << dsize;
char data[dsize];
//char data[dsize];
ifstream filebin;
char *indir=argv[1];
char *outdir=argv[2];
char *fformat=argv[3];
string indir=string(argv[1]);
string outdir=string(argv[2]);
string fformat=string(argv[3]);
int runmin=atoi(argv[4]);
int runmax=atoi(argv[5]);
char fname[10000];
char outfname[10000];
char imgfname[10000];
char pedfname[10000];
string fname;
string outfname;
string imgfname;
//char pedfname[10000];
// strcpy(pedfname,argv[6]);
char fn[10000];
char fn[10000];
std::time_t end_time;
@@ -136,12 +151,6 @@ int main(int argc, char *argv[]) {
cout << std::ctime(&end_time) << endl;
char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
@@ -158,17 +167,26 @@ int main(int argc, char *argv[]) {
for (int irun=runmin; irun<runmax; irun++) {
sprintf(fn,fformat,irun);
sprintf(fname,"%s/%s.raw",indir,fn);
sprintf(outfname,"%s/%s.clust",outdir,fn);
sprintf(imgfname,"%s/%s.tiff",outdir,fn);
sprintf(fn,fformat.c_str(),irun);
fname=indir+"/"+string(fn)+".raw";
//sprintf(fname,"%s/%s.raw",indir,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);
cout << std::ctime(&end_time) << 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
if (filebin.is_open()){
of=fopen(outfname,"w");
of=fopen(outfname.c_str(),"w");
if (of) {
mt->setFilePointer(of);
// cout << "file pointer set " << endl;
@@ -183,16 +201,24 @@ int main(int argc, char *argv[]) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr%10000==0) cout << ifr << " " << ff << endl;
// for (int ix=0; ix<400; ix++)
// for (int iy=0; iy<400; iy++) {
// if (decoder->getChannel(buff, ix, iy)<3000 || decoder->getChannel(buff, ix, iy)>8000) {
// cout << ifr << " " << ff << " " << ix << " " << iy << " " << decoder->getChannel(buff, ix, iy) << endl ;
// }
// }
if (np==40) {
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr%10000==0) cout << ifr << " " << ff << endl;
}
ff=-1;
}
cout << "--" << endl;
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
@@ -200,7 +226,7 @@ int main(int argc, char *argv[]) {
if (of)
fclose(of);
mt->writeImage(imgfname);
mt->writeImage(imgfname.c_str());
mt->clearImage();
std::time(&end_time);

View File

@@ -1,201 +0,0 @@
//#include "ansi.h"
#include <iostream>
//#include "moench03T1ZmqData.h"
//#include "moench03T1ReceiverData.h"
#include "moench03Ctb10GbT1Data.h"
// #include "interpolatingDetector.h"
//#include "etaInterpolationPosXY.h"
// #include "linearInterpolation.h"
// #include "noInterpolation.h"
#include "multiThreadedAnalogDetector.h"
#include "singlePhotonDetector.h"
//#include "interpolatingDetector.h"
#include <stdio.h>
#include <map>
#include <fstream>
#include <sys/stat.h>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]) {
if (argc<6) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 0;
}
int ii=0;
int p=10000;
int fifosize=1000;
int nthreads=5;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
int csize=3;
int nx=400, ny=400;
int save=1;
int nsigma=5;
int nped=1000;
int ndark=100;
int ok;
int iprog=0;
moench03Ctb10GbT1Data *decoder=new moench03Ctb10GbT1Data();
cout << "decoder" << endl;
//moench03T1ReceiverData *decoder=new moench03T1ReceiverData();
//moench03T1ZmqData *decoder=new moench03T1ZmqData();
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 100);
// char tit[10000];
cout << "filter" << endl;
// filter->readPedestals("/scratch/ped_100.tiff");
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
// cout << "filter "<< endl;
int size = 327680;////atoi(argv[3]);
int* image;
//int* image =new int[327680/sizeof(int)];
filter->newDataSet();
cout << "dataset" << endl;
int ff, np;
int dsize=decoder->getDataSize();
cout << " data size is " << dsize << endl;
char data[dsize];
ifstream filebin;
char *indir=argv[1];
cout << "input directory is " << indir << endl;
char *outdir=argv[2];
cout << "output directory is " << outdir << endl;
char *fformat=argv[3];
cout << "fileformat is " << fformat << endl;
int runmin=atoi(argv[4]);
cout << "runmin : " << runmin << endl;
int runmax=atoi(argv[5]);
cout << "runmax : " << runmax << endl;
char fname[10000];
char outfname[10000];
char imgfname[10000];
char pedfname[10000];
char fn[10000];
std::time_t end_time;
FILE *of=NULL;
cout << "time " << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
filter->setFrameMode(eFrame);
// mt->setFrameMode(ePedestal);
// for (int ix=0; ix<400; ix++)
// for (int iy=0; iy<400; iy++)
// cout << ix << " " << iy << " " << filter->getPedestal(ix,iy) << " " << filter->getPedestalRMS(ix,iy) << endl;
char* buff;
cout << "aa " << endl;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
cout << "mt " << endl;
// mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
// mt->prepareInterpolation(ok);
mt->setFrameMode(eFrame);
mt->StartThreads();
mt->popFree(buff);
int ifr=0;
// //loop on files
// mt->setFrameMode(eFrame);
//mt->setFrameMode(eFlat);
for (int irun=runmin; irun<runmax; irun++) {
sprintf(fn,fformat,irun);
sprintf(fname,"%s/%s.raw",indir,fn);
sprintf(outfname,"%s/%s.clust",outdir,fn);
sprintf(imgfname,"%s/%s.tiff",outdir,fn);
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
if (filebin.is_open()){
of=fopen(outfname,"w");
if (of) {
mt->setFilePointer(of);
// cout << "file pointer set " << endl;
} else {
cout << "Could not open "<< outfname << " for writing " << endl;
mt->setFilePointer(NULL);
return 1;
}
// //while read frame
ff=-1;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
//cout << "*"<<ifr++<<"*"<<ff<< endl;
//cout << ff << " " << np << endl;
// //push
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ff=-1;
ii++;
if (ii%10000==0) {
cout << ii << endl;
while (mt->isBusy()) {;}//wait until all data are processed from the queues
mt->writeImage("/scratch/tmp.tiff");
}
}
// cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {;}//wait until all data are processed from the queues
if (of)
fclose(of);
mt->writeImage(imgfname);
mt->clearImage();
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open "<< fname << " for reading " << endl;
}
return 0;
}

View File

@@ -0,0 +1,245 @@
#include "ansi.h"
#include <iostream>
#include <math.h>
//#include "moench03T1ZmqData.h"
//#define DOUBLE_SPH
//#define MANYFILES
#ifdef DOUBLE_SPH
#include "single_photon_hit_double.h"
#endif
#ifndef DOUBLE_SPH
#include "single_photon_hit.h"
#endif
//#include "etaInterpolationPosXY.h"
#include "slsInterpolation.h"
#include "Stat.h"
//#include "etaInterpolationRandomBins.h"
using namespace std;
#define NC 400
#define NR 400
#define MAX_EBINS 100
int main(int argc, char *argv[]) {
if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile outfile runmin runmax cmin cmax nb" << endl;
return 1;
}
int iarg=4;
char infname[10000];
char fname[10000];
char outfname[10000];
float img[NC*NR];
iarg=3;
int runmin=atoi(argv[iarg++]);
int runmax=atoi(argv[iarg++]);
cout << "Run min: " << runmin << endl;
cout << "Run max: " << runmax << endl;
float cmin=atof(argv[iarg++]);
float cmax=atof(argv[iarg++]);
cout << "Energy min: " << cmin << endl;
cout << "Energy max: " << cmax << endl;
int n_ebins=1;
if (argc>iarg)
n_ebins=atoi(argv[iarg++]);
//int etabins=500;
int etabins=1000;//nsubpix*2*100;
double etamin=-1, etamax=2;
//double etamin=-0.1, etamax=1.1;
double eta3min=-2, eta3max=2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ok;
int f0=-1;
int ix, iy, isx, isy;
int nframes=0, lastframe=-1;
double d_x, d_y, res=5, xx, yy;
int nph=0, badph=0, totph=0;
FILE *f=NULL;
single_photon_hit cl(3,3);
int iebin=0;
double eb_size=(cmax-cmin)/n_ebins;
Stat *statsX=new Stat[(n_ebins+1)*NC*NR];
Stat *statsY=new Stat[(n_ebins+1)*NC*NR];
int irun;
for (irun=runmin; irun<runmax; irun++) {
sprintf(infname,argv[1],irun);
f=fopen(infname,"r");
if (f) {
cout << infname << endl;
nframes=0;
f0=-1;
while (cl.read(f)) {
totph++;
if (lastframe!=cl.iframe) {
lastframe=cl.iframe;
// cout << cl.iframe << endl;
// f0=cl.iframe;
if (nframes==0) f0=lastframe;
nframes++;
}
slsInterpolation::calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
nph++;
iebin=(sum-cmin)/eb_size;
if (iebin>=0 && iebin<n_ebins && cl.x>=0 && cl.x<NC && cl.y>=0 && cl.y<NR) {
statsX[iebin+cl.x*(n_ebins+1)+cl.y*(NC*(n_ebins+1))].Push(etax);
statsY[iebin+cl.x*(n_ebins+1)+cl.y*(NC*(n_ebins+1))].Push(etay);
statsX[n_ebins+cl.x*(n_ebins+1)+cl.y*(NC*(n_ebins+1))].Push(etax);
statsY[n_ebins+cl.x*(n_ebins+1)+cl.y*(NC*(n_ebins+1))].Push(etay);
}
if (nph%1000000==0) cout << nph << endl;
}
}
fclose(f);
} else
cout << "could not open file " << infname << endl;
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_abs_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsX[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].NumDataValues();
}
}
WriteToTiff(img, outfname, NR, NC);
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_etameanX_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsX[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].Mean();
}
}
WriteToTiff(img, outfname, NR, NC);
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_etarmsX_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsX[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].StandardDeviation();
}
}
WriteToTiff(img, outfname, NR, NC);
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_etameanY_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsY[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].Mean();
}
}
WriteToTiff(img, outfname, NR, NC);
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_etarmsY_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsY[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].StandardDeviation();
}
}
WriteToTiff(img, outfname, NR, NC);
}
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_abs_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsX[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].NumDataValues();
}
}
WriteToTiff(img, outfname, NR, NC);
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_etameanX_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsX[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].Mean();
}
}
WriteToTiff(img, outfname, NR, NC);
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_etarmsX_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsX[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].StandardDeviation();
}
}
WriteToTiff(img, outfname, NR, NC);
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_etameanY_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsY[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].Mean();
}
}
WriteToTiff(img, outfname, NR, NC);
}
for (int ien=0; ien<n_ebins+1; ien++) {
sprintf(outfname,"%s_etarmsY_energy%d.tiff",argv[2],ien);
for (int iy=0; iy<NR; iy++) {
for (int ix=0; ix<NC; ix++) {
img[ix+NC*iy]= statsY[ien+ix*(n_ebins+1)+iy*(NC*(n_ebins+1))].StandardDeviation();
}
}
WriteToTiff(img, outfname, NR, NC);
}
cout << "Filled " << nph << " (/"<< totph <<") " << endl;
return 0;
}

View File

@@ -5,7 +5,7 @@
//#include "moench03T1ZmqData.h"
//#define DOUBLE_SPH
//#define MANYFILES
//#define WRITE_QUAD
#ifdef DOUBLE_SPH
#include "single_photon_hit_double.h"
#endif
@@ -14,13 +14,21 @@
#include "single_photon_hit.h"
#endif
//#include "etaInterpolationPosXY.h"
#include "etaInterpolationPosXY.h"
#include "noInterpolation.h"
#include "etaInterpolationCleverAdaptiveBins.h"
//#include "etaInterpolationCleverAdaptiveBins.h"
//#include "etaInterpolationRandomBins.h"
using namespace std;
#ifndef RECT
#define NC 400
#define NR 400
#endif
#ifdef RECT
#define NC 200
#define NR 800
#endif
#define MAX_ITERATIONS (nSubPixels*100)
#define XTALK
@@ -42,9 +50,9 @@ int main(int argc, char *argv[]) {
#endif
int iarg=4;
char infname[10000];
char fname[10000];
char outfname[10000];
#ifndef FF
char fname[10000];
iarg=4;
#endif
@@ -66,22 +74,42 @@ int main(int argc, char *argv[]) {
cout << "Energy min: " << cmin << endl;
cout << "Energy max: " << cmax << endl;
//int etabins=500;
#ifndef NOINTERPOLATION
int etabins=1000;//nsubpix*2*100;
int etabinsY=etabins;//nsubpix*2*100;
double etamin=-1, etamax=2;
//double etamin=-0.1, etamax=1.1;
double eta3min=-2, eta3max=2;
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;
//#endif
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ok;
#ifdef NOINTERPOLATION
#ifndef FF
double noint_x, noint_y;
#endif
#endif
int f0=-1;
int ix, iy, isx, isy;
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,
int nph=0, totph=0;
FILE *f=NULL;
#ifdef DOUBLE_SPH
single_photon_hit_double cl(3,3);
@@ -90,23 +118,38 @@ int main(int argc, char *argv[]) {
#ifndef DOUBLE_SPH
single_photon_hit cl(3,3);
#endif
int nSubPixels=nsubpix;
int nSubPixelsY=nsubpix;
#ifdef RECT1
// nSubPixels=2; //might make more sense using 2?
// etabins=100;
float *rectimg=new float[NC*NR*nSubPixelsY];;
#endif
// #endif
#ifndef NOINTERPOLATION
eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
#ifndef ETA3
eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax);
#endif
#ifdef ETA3
eta3InterpolationPosXY *interp=new eta3InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax);
#endif
//eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
#endif
#ifdef NOINTERPOLATION
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix, nSubPixelsY);
#endif
#ifndef FF
int *img;
#ifndef NOINTERPOLATION
cout << "read ff " << argv[2] << endl;
sprintf(fname,"%s",argv[2]);
interp->readFlatField(fname);
interp->readFlatField(fname, etamin, etamax);
interp->prepareInterpolation(ok);//, MAX_ITERATIONS);
#endif
// return 0;
@@ -115,13 +158,12 @@ int main(int argc, char *argv[]) {
cout << "Will write eta file " << argv[2] << endl;
#endif
int *img;
float *totimg=new float[NC*NR*nsubpix*nsubpix];
float *totimg=new float[NC*NR*nSubPixels*nSubPixelsY];
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=0;
for (isx=0; isx<nSubPixels; isx++) {
for (isy=0; isy<nSubPixelsY; isy++) {
totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]=0;
}
}
}
@@ -148,37 +190,56 @@ int main(int argc, char *argv[]) {
totph++;
if (lastframe!=cl.iframe) {
lastframe=cl.iframe;
// cout << cl.iframe << endl;
// f0=cl.iframe;
if (nframes==0) f0=lastframe;
nframes++;
}
//quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
//#ifndef FF
#ifndef ETA3
quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
#endif
#ifdef ETA3
quad=interp->calcEta3(cl.get_cluster(), etax, etay, sum);
totquad=sum;
#endif
//#endif
// #ifdef FF
// #ifndef ETA3
// interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
// #endif
// #endif
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
nph++;
nph++;
// 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, cl.get_cluster(),int_x, int_y);
interp->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,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)
interp->addToImage(int_x, int_y);
if (int_x<0 || int_y<0 || int_x>400 || int_y>400) {
cout <<"**************"<< endl;
cout << cl.x << " " << cl.y << " " << sum << endl;
cl.print();
cout << int_x << " " << int_y << endl;
cout <<"**************"<< endl;
}
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
#ifdef FF
// interp->addToFlatField(cl.get_cluster(), etax, etay);
@@ -190,6 +251,7 @@ int main(int argc, char *argv[]) {
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl;
#endif
}
// #ifdef SOLEIL
// }
// #endif
@@ -215,28 +277,63 @@ int main(int argc, char *argv[]) {
#endif
#ifndef FF
#ifndef RECT1
interp->writeInterpolatedImage(outfname);
#endif
img=interp->getInterpolatedImage();
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
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)];
#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;
#ifdef RECT1
WriteToTiff(rectimg, outfname,NC,NR*nSubPixelsY);
#endif
interp->clearInterpolatedImage();
#endif
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl;
} else
cout << "could not open file " << infname << endl;
}
#ifndef FF
sprintf(outfname,argv[3],11111);
WriteToTiff(totimg, outfname,NC*nsubpix,NR*nsubpix);
#ifndef RECT1
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
#ifdef FF

View File

@@ -1,269 +0,0 @@
#include "ansi.h"
#include <iostream>
//#include "moench03T1ZmqData.h"
//#define DOUBLE_SPH
//#define MANYFILES
#ifdef DOUBLE_SPH
#include "single_photon_hit_double.h"
#endif
#ifndef DOUBLE_SPH
#include "single_photon_hit.h"
#endif
//#include "etaInterpolationPosXY.h"
#include "noInterpolation.h"
#include "etaInterpolationCleverAdaptiveBins.h"
//#include "etaInterpolationRandomBins.h"
using namespace std;
#define NC 400
#define NR 400
#define MAX_ITERATIONS (nSubPixels*100)
#define MAX_EBINS 100
#define XTALK
int main(int argc, char *argv[]) {
#ifndef FF
if (argc<9) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile outfile runmin runmax ns cmin cmax" << endl;
return 1;
}
#endif
#ifdef FF
if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile runmin runmax cmin cmax" << endl;
return 1;
}
#endif
int iarg=4;
char infname[10000];
char fname[10000];
char outfname[10000];
#ifndef FF
iarg=4;
#endif
#ifdef FF
iarg=3;
#endif
int runmin=atoi(argv[iarg++]);
int runmax=atoi(argv[iarg++]);
cout << "Run min: " << runmin << endl;
cout << "Run max: " << runmax << endl;
int nsubpix=4;
#ifndef FF
nsubpix=atoi(argv[iarg++]);
cout << "Subpix: " << nsubpix << endl;
#endif
float cmin=atof(argv[iarg++]);
float cmax=atof(argv[iarg++]);
cout << "Energy min: " << cmin << endl;
cout << "Energy max: " << cmax << endl;
int n_ebins=1;
if (argc>iarg)
n_ebins=atoi(argv[iarg++]);
//int etabins=500;
int etabins=1000;//nsubpix*2*100;
double etamin=-1, etamax=2;
//double etamin=-0.1, etamax=1.1;
double eta3min=-2, eta3max=2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ok;
int f0=-1;
int ix, iy, isx, isy;
int nframes=0, lastframe=-1;
double d_x, d_y, res=5, xx, yy;
int nph=0, badph=0, totph=0;
FILE *f=NULL;
#ifdef DOUBLE_SPH
single_photon_hit_double cl(3,3);
#endif
#ifndef DOUBLE_SPH
single_photon_hit cl(3,3);
#endif
int nSubPixels=nsubpix;
int iebin=0;
double eb_size=(cmax-cmin)/n_ebins;
#ifndef NOINTERPOLATION
// eta2InterpolationPosXY *interp[MAX_EBINS];
eta2InterpolationCleverAdaptiveBins *interp[MAX_EBINS];
for (int i=0; i< n_ebins; i++) {
//interp[i]=new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
interp[i]=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
}
#endif
#ifdef NOINTERPOLATION
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
#endif
#ifndef FF
#ifndef NOINTERPOLATION
cout << "read ff " << argv[2] << endl;
for (int i=0; i< n_ebins; i++) {
sprintf(fname,argv[2],i);
interp[i]->readFlatField(fname);
interp[i]->prepareInterpolation(ok);//, MAX_ITERATIONS);
}
#endif
// return 0;
#endif
#ifdef FF
cout << "Will write eta file " << argv[2] << endl;
#endif
int *img;
float *totimg=new float[NC*NR*nsubpix*nsubpix];
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=0;
}
}
}
}
#ifdef FF
sprintf(outfname,argv[2]);
#endif
int irun;
for (irun=runmin; irun<runmax; irun++) {
sprintf(infname,argv[1],irun);
#ifndef FF
sprintf(outfname,argv[3],irun);
#endif
f=fopen(infname,"r");
if (f) {
cout << infname << endl;
nframes=0;
f0=-1;
while (cl.read(f)) {
totph++;
if (lastframe!=cl.iframe) {
lastframe=cl.iframe;
// cout << cl.iframe << endl;
// f0=cl.iframe;
if (nframes==0) f0=lastframe;
nframes++;
}
//quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
quad=interp[0]->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
nph++;
iebin=(sum-cmin)/eb_size;
if (iebin>=0 && iebin<n_ebins) {
// 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
#ifndef FF
// interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y);
interp[iebin]->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,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)
interp[iebin]->addToImage(int_x, int_y);
#endif
#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[iebin]->addToFlatField(etax, etay);
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl;
#endif
// #ifdef SOLEIL
// }
// #endif
if (nph%1000000==0) cout << nph << endl;
if (nph%10000000==0) {
#ifndef FF
for (int i=0; i<n_ebins; i++) {
sprintf(outfname,argv[3],i);
interp[i]->writeInterpolatedImage(outfname);
}
#endif
#ifdef FF
for (int i=0; i<n_ebins; i++) {
sprintf(outfname,argv[2],i);
cout << outfname << " " << argv[2] << " " << i << endl;
interp[i]->writeFlatField(outfname);
}
#endif
}
}
}
}
fclose(f);
#ifdef FF
for (int i=0; i<n_ebins; i++) {
sprintf(outfname,argv[2],i);
cout << outfname << " " << argv[2] << " " << i << endl;
interp[i]->writeFlatField(outfname);
}
#endif
#ifndef FF
for (int i=0; i<n_ebins; i++) {
sprintf(outfname,argv[3],i,irun);
interp[i]->writeInterpolatedImage(outfname);
img=interp[i]->getInterpolatedImage();
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
for (isy=0; isy<nsubpix; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
}
}
}
}
//interp[i]->clearInterpolatedImage();
}
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ")"<<endl;
#endif
} else
cout << "could not open file " << infname << endl;
}
#ifndef FF
sprintf(outfname,argv[3], 11111);
WriteToTiff(totimg, outfname,NC*nsubpix,NR*nsubpix);
#endif
#ifdef FF
interp[iebin]->writeFlatField(outfname);
#endif
cout << "Filled " << nph << " (/"<< totph <<") " << endl;
return 0;
}

View File

@@ -1,114 +0,0 @@
#include "ansi.h"
#include <iostream>
#include "moench03T1ZmqData.h"
#include "single_photon_hit.h"
#include "etaInterpolationPosXY.h"
using namespace std;
#define NC 400
#define NR 400
#define XTALK
int main(int argc, char *argv[]) {
/**
* trial.o [socket ip] [starting port number] [outfname]
*
*/
int nsubpix=10;
int etabins=nsubpix*100;
double etamin=-1, etamax=2;
double eta3min=-2, eta3max=2;
int quad;
double sum, totquad;
double sDum[2][2];
char fname[10000];
double etax, etay;
int runmin, runmax;
single_photon_hit cl(3,3);
int iph=0;
if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " outfile runmin runmax cmin cmax" << endl;
return 1;
}
eta2InterpolationPosXY *interp2=new eta2InterpolationPosXY(NR, NC, nsubpix, etabins, etamin, etamax);
cout << "###########"<< endl;
eta3InterpolationPosXY *interp3=new eta3InterpolationPosXY(NR, NC, nsubpix, etabins, eta3min, eta3max);
// cout << eta3min << " " << eta3max << endl;
runmin=atoi(argv[3]);
runmax=atoi(argv[4]);
double cmin=atof(argv[5]); //200
double cmax=atof(argv[6]); //3000
#ifdef XTALK
int old_val[3][3];
int new_val[3][3];
double xcorr=0.04;
// int ix=0;
#endif
FILE *f;
for (int i=runmin; i<runmax; i++) {
sprintf(fname,argv[1],i);
f=fopen(fname,"r");
if (f) {
cout << "*" << endl;
while (cl.read(f)) {
#ifdef XTALK
if ((cl.x+1)%25!=0) {
for (int ix=-1; ix<2; ix++) {
for (int iy=-1; iy<2; iy++) {
old_val[iy+1][ix+1]=cl.get_data(ix,iy);
if (ix>=0) {
new_val[iy+1][ix+1]=old_val[iy+1][ix+1]-old_val[iy+1][ix]*xcorr;
cl.set_data(new_val[iy+1][ix+1],ix,iy);
}
}
}
}
#endif
quad=interp2->calcQuad(cl.get_cluster(), sum, totquad, sDum);
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && totquad<cmax && quad<cmax) {
/* Cross talk corrections !!! */
// for (int ix=0; ix<2; ix++) {
interp2->addToFlatField(cl.get_cluster(),etax, etay);
// if (etax>0.49 && etax<0.51 && etay>0.49 && etay<0.51 ) {
// cout << cl.y << " " << cl.x << " " << quad << " "<< totquad << " " <<sum << endl;
// }
interp3->addToFlatField(cl.get_cluster(),etax, etay);
iph++;
if (iph%1000000==0) cout << iph << endl;
if (iph%100000000==0) {
sprintf(fname,"%s_eta2.tiff",argv[2]);
interp2->writeFlatField(fname);
sprintf(fname,"%s_eta3.tiff",argv[2]);
interp3->writeFlatField(fname);
}
// if (iph>1E8) break;
}
// }
}
fclose(f);
}
else cout << "could not open file " << fname << endl;
}
sprintf(fname,"%s_eta2.tiff",argv[2]);
interp2->writeFlatField(fname);
sprintf(fname,"%s_eta3.tiff",argv[2]);
interp3->writeFlatField(fname);
return 0;
}

View File

@@ -2,7 +2,6 @@
#include "ansi.h"
#include <iostream>
#include "moench03T1ZmqData.h"
#include "single_photon_hit.h"
#include "noInterpolation.h"
@@ -19,7 +18,7 @@ int main(int argc, char *argv[]) {
*/
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;
}
@@ -29,13 +28,14 @@ int main(int argc, char *argv[]) {
int runmax=atoi(argv[5]);
int nsubpix=atoi(argv[6]);
int etabins=1000;//nsubpix*2*100;
double etamin=-1, etamax=2;
// int etabins=1000;//nsubpix*2*100;
// double etamin=-1, etamax=2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
int ok;
//double etax, etay,
double int_x, int_y;
//int ok;
int ix, iy, isx, isy;

View File

@@ -1,163 +0,0 @@
//#include "ansi.h"
#include <iostream>
//#include "moench03T1ZmqData.h"
#include "moench03T1ReceiverDataNew.h"
// #include "interpolatingDetector.h"
//#include "etaInterpolationPosXY.h"
// #include "linearInterpolation.h"
// #include "noInterpolation.h"
//#include "interpolatingDetector.h"
#include <stdio.h>
#include <map>
#include <fstream>
#include <sys/stat.h>
#include <cstdlib>
#include <ctime>
using namespace std;
#define NX 400 //number of x pixels
#define NY 400 //number of y pixels
int main(int argc, char *argv[]) {
if (argc<6) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 1;
}
int p=10000;
int fifosize=1000;
int nthreads=8;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
int csize=3;
int nx=400, ny=400;
int save=1;
int nsigma=5;
int nped=1000;
int ndark=100;
int ok;
int iprog=0;
moench03T1ReceiverDataNew *decoder=new moench03T1ReceiverDataNew();
uint16_t data[NY*NX];
int size = 327680;////atoi(argv[3]);
int* image;
int ff, np;
int dsize=decoder->getDataSize();
//char data[dsize];
ifstream filebin;
char *indir=argv[1];
char *outdir=argv[2];
char *fformat=argv[3];
int runmin=atoi(argv[4]);
int runmax=atoi(argv[5]);
char fname[10000];
char outfname[10000];
char imgfname[10000];
char pedfname[10000];
// strcpy(pedfname,argv[6]);
char fn[10000];
std::time_t end_time;
FILE *of=NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "fileformat is " << fformat << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char* buff;
int ifr=0;
for (int irun=runmin; irun<runmax; irun++) {
sprintf(fn,fformat,irun);
sprintf(fname,"%s/%s.raw",indir,fn);
sprintf(outfname,"%s/%s_image.raw",outdir,fn);
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
if (filebin.is_open()){
of=fopen(outfname,"w");
if (of) {
;
} else {
cout << "Could not open "<< outfname << " for writing " << endl;
return 1;
}
// //while read frame
ff=-1;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
for (int ix=0; ix<400; ix++)
for (int iy=0; iy<400; iy++)
data[iy*NX+ix]=decoder->getChannel(buff,ix,iy);
ifr++;
fwrite(&ff, 8, 1,of);//write detector frame number
fwrite(&ifr, 8, 1,of);//write datset frame number
fwrite(data,2,NX*NY,of);//write reordered data
if (ifr%10000==0) cout << ifr << " " << ff << endl;
ff=-1;
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
if (of)
fclose(of);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open "<< fname << " for reading " << endl;
}
return 0;
}

View File

@@ -1,242 +0,0 @@
//#include "ansi.h"
#include <iostream>
//#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER
#include "moench03T1ReceiverDataNew.h"
#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 "multiThreadedAnalogDetector.h"
#include "singlePhotonDetector.h"
//#include "interpolatingDetector.h"
#include <stdio.h>
#include <map>
#include <fstream>
#include <sys/stat.h>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]) {
if (argc<4) {
cout << "Usage is " << argv[0] << "indir outdir fname [pedfile] [threshold]" << endl;
return 1;
}
int p=10000;
int fifosize=1000;
int nthreads=8;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
int csize=3;
int nx=400, ny=400;
int save=1;
int nsigma=5;
int nped=1000;
int ndark=100;
int ok;
int iprog=0;
#ifdef NEWRECEIVER
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
#ifndef ANALOG
//moench03T1ZmqData *decoder=new moench03T1ZmqData();
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200);
// char tit[10000];
cout << "filter " << endl;
#endif
#ifdef ANALOG
//moench03T1ZmqData *decoder=new moench03T1ZmqData();
analogDetector<uint16_t> *filter=new analogDetector<uint16_t>(decoder, 1, 0, nped);
// char tit[10000];
cout << "filter " << endl;
#endif
// filter->readPedestals("/scratch/ped_100.tiff");
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
// cout << "filter "<< endl;
int size = 327680;////atoi(argv[3]);
int* image;
//int* image =new int[327680/sizeof(int)];
filter->newDataSet();
int ff, np;
int dsize=decoder->getDataSize();
cout << " data size is " << dsize;
char data[dsize];
ifstream filebin;
char *indir=argv[1];
char *outdir=argv[2];
char *fformat=argv[3];
char *pedfile=NULL;
if (argc>=5) {
pedfile=argv[4];
}
double thr=0;
if (argc>=6) {
thr=atoi(argv[5]);
}
char fname[10000];
char imgfname[10000];
// strcpy(pedfname,argv[6]);
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;
if (pedfile)
cout << "pedestal file is " << pedfile << endl;
if (thr>0) {
cout << "threshold is " << thr << endl;
filter->setThreshold(thr);
}
filter->setROI(0,150,0,150);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
mt->StartThreads();
mt->popFree(buff);
cout << "mt " << endl;
int ifr=0;
for (int irun=0; irun<2; irun++) {
if (irun>0) {
mt->setFrameMode(eFrame);
// sprintf(fn,fformat,irun);
sprintf(fname,"%s/%s.raw",indir,fformat);
// sprintf(outfname,"%s/%s.clust",outdir,fn);
sprintf(imgfname,"%s/%s.tiff",outdir,fformat);
} else {
mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun);
sprintf(fname,"%s/%s.raw",indir,pedfile);
// sprintf(outfname,"%s/%s.clust",outdir,fn);
// sprintf(imgfname,"%s/%s.tiff",outdir,fn);
}
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
if (filebin.is_open()){
// of=fopen(outfname,"w");
// if (of) {
// mt->setFilePointer(of);
// // cout << "file pointer set " << endl;
// } else {
// cout << "Could not open "<< outfname << " for writing " << endl;
// mt->setFilePointer(NULL);
// return 1;
// }
// //while read frame
ff=-1;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr%10000==0) cout << ifr << " " << ff << endl;
ff=-1;
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {;}//wait until all data are processed from the queues
// if (of)
// fclose(of);
if (irun>0) {
cout << "Writing tiff to " << imgfname << endl;
mt->writeImage(imgfname);
// mt->clearImage();
}
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open "<< fname << " for reading " << endl;
}
return 0;
}

View File

@@ -1,7 +1,12 @@
//#include "ansi.h"
#include <iostream>
#define CORR
#define C_GHOST 0.0004
#define CM_ROWS 50
//#define VERSION_V1
//#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER
@@ -27,15 +32,18 @@
//#include "etaInterpolationPosXY.h"
// #include "linearInterpolation.h"
// #include "noInterpolation.h"
#include "multiThreadedAnalogDetector.h"
#include "multiThreadedCountingDetector.h"
//#include "multiThreadedAnalogDetector.h"
#include "singlePhotonDetector.h"
#include "moench03GhostSummation.h"
#include "moench03CommonMode.h"
//#include "interpolatingDetector.h"
#include <stdio.h>
#include <map>
#include <fstream>
#include <sys/stat.h>
#include <dirent.h>
#include <ctime>
using namespace std;
@@ -44,25 +52,25 @@ 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]" << endl;
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 p=10000;
int fifosize=1000;
int nthreads=8;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
int nthreads=10;
//int nsubpix=25;
//int etabins=nsubpix*10;
//double etamin=-1, etamax=2;
int csize=3;
int save=1;
//int save=1;
int nsigma=5;
int nped=1000;
int ndark=100;
int ok;
int iprog=0;
int nped=10000;
//int ndark=100;
//int ok;
//int iprog=0;
int cf=0;
@@ -88,21 +96,24 @@ int main(int argc, char *argv[]) {
decoder->getDetectorSize(nx,ny);
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200);
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 size = 327680;////atoi(argv[3]);
int* image;
//int* image;
//int* image =new int[327680/sizeof(int)];
filter->newDataSet();
int ff, np;
int dsize=decoder->getDataSize();
//cout << " data size is " << dsize;
char data[dsize];
ifstream filebin;
char *indir=argv[1];
@@ -129,7 +140,7 @@ int main(int argc, char *argv[]) {
double thr1=1;
if (argc>=8) {
thr=atoi(argv[7]);
thr=atof(argv[7]);
}
@@ -147,6 +158,12 @@ int main(int argc, char *argv[]) {
}
char *gainfname=NULL;
if (argc>13) {
gainfname=argv[13];
cout << "Gain map file name is: " << gainfname << endl;
}
@@ -154,7 +171,7 @@ int main(int argc, char *argv[]) {
char fname[10000];
char imgfname[10000];
char cfname[10000];
char fn[10000];
//char fn[10000];
std::time_t end_time;
@@ -166,25 +183,74 @@ int main(int argc, char *argv[]) {
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);
#ifdef SOLEIL
filter->setROI(150,210,170,230);
nframes=-1;
#endif
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
// multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize);
#ifndef ANALOG
mt->setDetectorMode(ePhotonCounting);
cout << "Counting!" << endl;
@@ -197,81 +263,105 @@ int main(int argc, char *argv[]) {
mt->setDetectorMode(eAnalog);
cout << "Analog!" << endl;
cf=0;
// #ifdef ANALOG
// thr1=thr;
//thr1=thr;
#endif
// }
mt->StartThreads();
mt->popFree(buff);
DIR *dir;
struct dirent *ent;
// cout << "mt " << endl;
int ifr=0;
double ped[nx*ny];//, *ped1;
if (pedfile) {
cout << "PEDESTAL " ;
sprintf(fname,"%s.raw",pedfile);
cout << fname << endl ;
sprintf(imgfname,"%s/pedestals.tiff",outdir,fformat);
std::time(&end_time);
cout << "aaa" << std::ctime(&end_time) << endl;
cout << "PEDESTAL " << endl;
sprintf(imgfname,"%s/pedestals.tiff",outdir);
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)) {
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr%10000==0)
cout << ifr << " " << ff << " " << np << endl;
ff=-1;
}
filebin.close();
while (mt->isBusy()) {;}
mt->writePedestal(imgfname);
if (string(pedfile).find(".tif")==std::string::npos){
sprintf(fname,"%s.raw",pedfile);
cout << fname << endl ;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
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) {
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr%10000==0)
cout << ifr << " " << ff << " " << np << endl;
} else
cout << ifr << " " << ff << " " << np << endl;
ff=-1;
}
filebin.close();
while (mt->isBusy()) {;}
} else
cout << "Could not open "<< fname << " for reading " << endl;
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;
}
}
mt->writePedestal(imgfname);
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 " ;
mt->setFrameMode(eFrame);
// sprintf(fn,fformat,irun);
sprintf(ffname,"%s/%s.raw",indir,fformat);
sprintf(fname,ffname,irun);
sprintf(ffname,"%s/%s.tiff",outdir,fformat);
sprintf(imgfname,ffname,irun);
sprintf(ffname,"%s/%s.clust",outdir,fformat);
sprintf(cfname,ffname,irun);
cout << fname << " " ;
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;
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()){
if (thr<=0) {
if (cf) {
if (thr<=0 && cf!=0) { //cluster finder
if (of==NULL) {
of=fopen(cfname,"w");
if (of) {
@@ -283,65 +373,106 @@ int main(int argc, char *argv[]) {
return 1;
}
}
}
}
// //while read frame
ff=-1;
ifr=0;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr%1000==0) cout << ifr << " " << ff << endl;
if (nframes>0) {
if (ifr%nframes==0) {
//The name has an additional "_fXXXXX" at the end, where "XXXXX" is the initial frame number of the image (0,1000,2000...)
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++;
}
}
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;
ff=-1;
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) {
mt->pushData(buff);
mt->nextThread();
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
cout << "Could not open "<< fname << " for reading " << endl;
}
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {;}
if (nframes>=0) {
if (nframes>0) {
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(imgfname,ffname,irun);
}
sprintf(ffname,"%s/%s.tiff",outdir,fformat);
}
while (mt->isBusy()) {;}
if (nframes>=0) {
if (nframes>0) {
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();
if (of) {
fclose(of);
of=NULL;
mt->setFilePointer(NULL);
}
}
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open "<< fname << " for reading " << endl;
} else {
sprintf(imgfname,"%s/%s_%d.tiff",outdir,fformat,irun);
//sprintf(imgfname,ffname,irun);
}
cout << "Writing tiff to " << imgfname << " " << ifr <<endl;
mt->writeImage(imgfname, thr1);
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;
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;
}

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,394 +0,0 @@
//#define ROOTSPECTRUM
#include "multiThreadedAnalogDetector.h"
#include "sls_receiver_defs.h"
#include "ZmqSocket.h"
#include "moench03T1ZmqDataNew.h"
#ifdef ROOTSPECTRUM
#include <TPaveText.h>
#include <TLegend.h>
#include <TF1.h>
#include <TGraphErrors.h>
#include <TH2F.h>
#include <TASImage.h>
#include <TImage.h>
#include <TFile.h>
#endif
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <fstream>
#include "tiffIO.h"
#include<iostream>
//#include "analogDetector.h"
#include "singlePhotonDetector.h"
#include "ansi.h"
#include <iostream>
using namespace std;
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
int main(int argc, char *argv[]) {
/**
* trial.o [socket ip] [starting port number] [send_socket ip] [send port number]
*
*/
int fifosize=1000;
int nthreads=20;
char* buff;
char tit[10000];
// help
if (argc < 3 ) {
cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n");
return EXIT_FAILURE;
}
// receive parameters
bool send = false;
char* socketip=argv[1];
uint32_t portnum = atoi(argv[2]);
int size = 32*2*5000;//atoi(argv[3]);
// send parameters if any
char* socketip2 = 0;
uint32_t portnum2 = 0;
if (argc > 3) {
send = true;
socketip2 = argv[3];
portnum2 = atoi(argv[4]);
}
cout << "\nrx socket ip : " << socketip <<
"\nrx port num : " << portnum ;
if (send) {
cout << "\nsd socket ip : " << socketip2 <<
"\nsd port num : " << portnum2;
}
cout << endl;
//slsDetectorData *det=new moench03T1ZmqDataNew();
moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew();
analogDetector<uint16_t> *filter=new analogDetector<uint16_t>(det,1,NULL,1000);
//singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10);
//filter->setROI(250, 400, 30, 150);
float threshold=1;
if (argc > 5) {
threshold=atof(argv[5]);
filter->setThreshold(threshold);
cout << "Threshold set to " << threshold << endl;
}
int nnx, nny, nns;
int imsize=filter->getImageSize(nnx,nny,nns);
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
// mt->prepareInterpolation(ok);
mt->StartThreads();
mt->popFree(buff);
cout << "det " << endl;
int16_t dout[400*400];
double ddark[400*400];
cout << "dout " << endl;
// receive socket
ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum);
#ifdef ROOTSPECTRUM
TH2F *h2=NULL;
TH2F *hmap=NULL;
TFile *froot=NULL;
h2=new TH2F("hs","hs",500,-500,500,400*400,-0.5,400*400-0.5);
hmap=new TH2F("hmap","hmap",400,-0.5,400-0.5,400,-0.5,400-0.5);
#endif
cout << "zmq1 " << endl;
if (zmqsocket->IsError()) {
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
delete zmqsocket;
return EXIT_FAILURE;
}
zmqsocket->Connect();
printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress());
// send socket
ZmqSocket* zmqsocket2 = 0;
cout << "zmq2 " << endl;
if (send) {
zmqsocket2 = new ZmqSocket(portnum2, socketip2);
if (zmqsocket2->IsError()) {
bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
delete zmqsocket2;
delete zmqsocket;
return EXIT_FAILURE;
}
zmqsocket2->Connect();
printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress());
// zmqsocket2->Disconnect();
}
// header variables
uint64_t acqIndex = -1;
uint64_t frameIndex = -1;
uint32_t subframeIndex = -1;
uint64_t fileindex = -1;
string filename = "";
//char* image = new char[size];
//int* image = new int[(size/sizeof(int))]();
int *nph;//[400*400];
int iframe=0;
char rootfname[10000];
char fname[10000];
char ff[10000];
int fi;
int length;
char newped=-1, ped=-1, dat=-1, isdark=-1;
double *peds;
int *im;
int fnumber;
float *gm=new float[400*400];
// infinite loop
while(1) {
// cout << "+++++++++++++++++++++++++++++++LOOP" << endl;
// get header, (if dummy, fail is on parse error or end of acquisition)
if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)){
// if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)) {
cprintf(RED, "Got Dummy\n");
while (mt->isBusy()) {;}//wait until all data are processed from the queues
if (dat==1) {
sprintf(tit,"%s_%lld.tiff",filename.c_str(),fi);
cout << tit << endl;
im=mt->getImage(nnx,nny,nns);
if (isdark) cout << "getting dark "<< endl;
else cout << "subtracting dark"<< endl;
if (gm) {
for (int ii=0; ii<400*400; ii++) {
// if (image[ix]>0) cout << ix << " " << image[ix]<< endl;
if (isdark) {
ddark[ii]=(double)im[ii]/((double)iframe);
if (ddark[ii]>0) cout << "*" ;
gm[ii]=im[ii];
if (send) dout[ii]=im[ii];
} else {
gm[ii]=im[ii];//-ddark[ii]*iframe;
if (gm[ii]<0) gm[ii]=0;
if (send) dout[ii]=gm[ii];
}
//cout << endl;
}
cout << endl;
//cout << "image " << nnx << " " << nny << endl;
WriteToTiff(gm,tit ,nnx, nny);
// delete [] gm;
} else cout << "Could not allocate float image " << endl;
} else {
sprintf(tit,"%s_%lld.tiff",filename.c_str(),fi);
cout << tit << endl;
mt->writePedestal(tit);
}
// mt->writeImage(tit);
// cout << "wrote" << endl;
if (send) {
if (dat==1) {
//im=mt->getImage(nnx,nny,nns);
//if (im)
// cout << "got image" << endl;
//else
// cout << "could not get image" << endl;
//for (int ii=0; ii<400*400; ii++) {
//if (im[ii]>0)
//cout << im[ii] << endl;
// if (im[ii]>=0)
// if (isdark) {
//ddark[ii]=im[ii];
// dout[ii]=im[ii];
// } else {
// dout[ii]=im[ii]-ddark[ii];
// if (dout[ii]<0) dout[ii]=0;
// }
// else
// dout[ii]=0;
//else
//dout[ii]=0;
// cout << im[ii] << " " << dout[ii] << endl;
// }
//for (int iiy=49; iiy<52; iiy++)
// for (int iix=80; iix<83; iix++)
// dout[iiy*400+iix]=0;
;
} else {
peds=mt->getPedestal();
// sprintf(tit,"%s_%lld.tiff",filename.c_str(),fi);
//cout << tit << endl;
//mt->writePedestal(tit);
if (peds)
cout << "got peds" << endl;
else
cout << "could not get peds" << endl;
for (int ii=0; ii<400*400; ii++) {
dout[ii]=peds[ii];
// if (ii%400==10 && ii/400==10)
// cout << ii/400 << " " << ii%400 << " " << peds[ii] << " " << dout[ii] << endl;
// if (ii%400==100 && ii/400==100)
// cout << ii/400 << " " << ii%400 << " " << peds[ii] << " " << dout[ii] << endl;
}
}
// zmqsocket2 = new ZmqSocket(portnum2, socketip2);
// if (zmqsocket2->IsError()) {
// bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
// delete zmqsocket2;
// delete zmqsocket;
// return EXIT_FAILURE;
// }
// zmqsocket2->Connect();
// printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress());
//zmqsocket2->Connect();
zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,ff, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket2->SendData((char*)dout,length);
cprintf(GREEN, "Sent Data %d \n",length);
zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
cprintf(RED, "Sent Dummy\n");
// zmqsocket2->Disconnect();
// delete zmqsocket2;
}
cout << "Acquired "<< iframe << " frames " << endl;
iframe=0;
newped=-1;
ped=-1;
dat=-1;
mt->clearImage();
isdark=0;
continue; //continue to not get out
}
// cprintf(GREEN, "Got Header \n");
strcpy(ff,filename.c_str());
fi=fileindex;
//isdark=0;
if (newped<0) {
if (filename.find("newped")!=std::string::npos) {
cout << "NEWPED" << endl;
if (newped<=0) {
newped=1;
ped=1;
while (mt->isBusy()) {;}
mt->newDataSet(); //resets pedestal
mt->setFrameMode(ePedestal);
cout << "New data set"<< endl;
}
} else {
newped=0;
}
}
if (ped<0) {
if (filename.find("ped")!=std::string::npos) {
ped=1;
dat=0;
while (mt->isBusy()) {;}
mt->setFrameMode(ePedestal);
cout << "pedestal!"<< endl;
} else {
ped=0;
dat=1;
while (mt->isBusy()) {;}
mt->setFrameMode(eFrame);
cout << "data!"<< endl;
if (filename.find("dark")!=std::string::npos) {
isdark=1;
cout << "this is a dark image" << endl;
}
}
}
// get data
length = zmqsocket->ReceiveData(0, buff, size);
// cprintf(GREEN, "Got Data\n");
//processing with image
//...
// if (iframe<10) {
// filter->addToPedestal(image);
//} else {
//SLOW!!!
//***
//filter->getNPhotons(image);
//nph=filter->getImage();
//filter->addToPedestal(image);
//*****
// cprintf(BLUE, "Data processed\n");
mt->pushData(buff);
mt->nextThread();
// cout << " " << (void*)buff;
mt->popFree(buff);
//stream data from socket 2
iframe++;
}
// }// exiting infinite loop
delete zmqsocket;
if (send)
delete zmqsocket2;
cout<<"Goodbye"<< endl;
return 0;
}

View File

@@ -1,402 +0,0 @@
#include "sls_receiver_defs.h"
#include "ZmqSocket.h"
#include "moench03T1ZmqDataNew.h"
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <fstream>
#include "tiffIO.h"
//#define NEWZMQ
#ifdef NEWZMQ
#include <rapidjson/document.h> //json header in zmq stream
#endif
#include<iostream>
//#include "analogDetector.h"
#include "singlePhotonDetector.h"
#include "multiThreadedAnalogDetector.h"
#include "ansi.h"
#include <iostream>
using namespace std;
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
int main(int argc, char *argv[]) {
/**
* trial.o [socket ip] [starting port number] [send_socket ip] [send port number]
*
*/
FILE *of=NULL;
int fifosize=1000;
int nthreads=20;
// help
if (argc < 3 ) {
cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n");
return EXIT_FAILURE;
}
// receive parameters
bool send = false;
char* socketip=argv[1];
uint32_t portnum = atoi(argv[2]);
int maxSize = 32*2*8192;//5000;//atoi(argv[3]);
int size= 32*2*5000;
int multisize=size;
// send parameters if any
char* socketip2 = 0;
uint32_t portnum2 = 0;
if (argc > 3) {
send = true;
socketip2 = argv[3];
portnum2 = atoi(argv[4]);
}
cout << "\nrx socket ip : " << socketip <<
"\nrx port num : " << portnum ;
if (send) {
cout << "\nsd socket ip : " << socketip2 <<
"\nsd port num : " << portnum2;
}
cout << endl;
//slsDetectorData *det=new moench03T1ZmqDataNew();
moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew();
//analogDetector<uint16_t> *filter=new analogDetector<uint16_t>(det,1,NULL,1000);
singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10);
char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
mt->setFrameMode(eFrame);
mt->StartThreads();
mt->popFree(buff);
ZmqSocket* zmqsocket=NULL;
#ifdef NEWZMQ
// receive socket
try{
#endif
zmqsocket = new ZmqSocket(socketip,portnum);
#ifdef NEWZMQ
} catch (...) {
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
delete zmqsocket;
return EXIT_FAILURE;
}
#endif
#ifndef NEWZMQ
if (zmqsocket->IsError()) {
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
delete zmqsocket;
return EXIT_FAILURE;
}
#endif
if (zmqsocket->Connect()) {
cprintf(RED, "Error: Could not connect to socket %s\n",
zmqsocket->GetZmqServerAddress());
delete zmqsocket;
return EXIT_FAILURE;
} else
printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress());
// send socket
ZmqSocket* zmqsocket2 = 0;
cout << "zmq2 " << endl;
if (send) {
#ifdef NEWZMQ
// receive socket
try{
#endif
zmqsocket2 = new ZmqSocket(portnum2, socketip2);
#ifdef NEWZMQ
} catch (...) {
cprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
delete zmqsocket2;
delete zmqsocket;
return EXIT_FAILURE;
}
#endif
#ifndef NEWZMQ
if (zmqsocket2->IsError()) {
cprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
delete zmqsocket2;
delete zmqsocket;
return EXIT_FAILURE;
}
#endif
if (zmqsocket2->Connect()) {
cprintf(RED, "Error: Could not connect to socket %s\n",
zmqsocket2->GetZmqServerAddress());
delete zmqsocket2;
return EXIT_FAILURE;
} else
printf("Zmq Client at %s\n", zmqsocket2->GetZmqServerAddress());
}
// header variables
uint64_t acqIndex = -1;
uint64_t frameIndex = -1;
uint32_t subFrameIndex = -1;
uint64_t fileindex = -1;
string filename = "";
// char* image = new char[size];
//int* image = new int[(size/sizeof(int))]();
uint32_t flippedDataX = -1;
int *nph;
int iframe=0;
char ofname[10000];
char fname[10000];
int length;
int *detimage;
int nnx, nny,nns;
uint32_t imageSize = 0, nPixelsX = 0, nPixelsY = 0, dynamicRange = 0;
filter->getImageSize(nnx, nny,nns);
int16_t *dout=new int16_t [nnx*nny];
// infinite loop
uint32_t packetNumber = 0;
uint64_t bunchId = 0;
uint64_t timestamp = 0;
int16_t modId = 0;
uint16_t xCoord = 0;
uint16_t yCoord = 0;
uint16_t zCoord = 0;
uint32_t debug = 0;
uint32_t dr = 16;
uint16_t roundRNumber = 0;
uint8_t detType = 0;
uint8_t version = 0;
int* flippedData = 0;
char* additionalJsonHeader = 0;
uint32_t threshold=0;
uint32_t xmin=0, xmax=400, ymin=0, ymax=400;
string frameMode_s, detectorMode_s;
int emin, emax;
int newFrame=1;
while(1) {
// cout << "+++++++++++++++++++++++++++++++LOOP" << endl;
// get header, (if dummy, fail is on parse error or end of acquisition)
#ifndef NEWZMQ
if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)){
#endif
#ifdef NEWZMQ
rapidjson::Document doc;
if (!zmqsocket->ReceiveHeader(0, doc, SLS_DETECTOR_JSON_HEADER_VERSION)) {
zmqsocket->CloseHeaderMessage();
#endif
// if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)) {
cprintf(RED, "Got Dummy\n");
while (mt->isBusy()) {;}//wait until all data are processed from the queues
detimage=mt->getImage(nnx,nny,nns);
for (int ix=0; ix<nnx; ix++) {
for (int iy=0; iy<nny; iy++) {
dout[iy*nnx+ix]=detimage[iy*nnx+ix];
}
}
if (send) {
strcpy(fname,filename.c_str());
#ifdef NEWZMQ
//zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dynamicRange, fileindex,
// nnx, nny, nns*dynamicRange/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, nns*dr/8,acqIndex, frameIndex, fname, acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader);
#endif
#ifndef NEWZMQ
zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
#endif
zmqsocket2->SendData((char*)dout,length);
cprintf(GREEN, "Sent Data\n");
}
// stream dummy to socket2 to signal end of acquisition
if (send) {
zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
cprintf(RED, "Sent Dummy\n");
}
mt->clearImage();
if (of) {
fclose(of);
of=NULL;
}
newFrame=1;
continue; //continue to not get out
}
#ifdef NEWZMQ
if (newFrame) {
// acqIndex, frameIndex, subframeIndex, filename, fileindex
size = doc["size"].GetUint();
multisize = size;// * zmqsocket->size();
dynamicRange = doc["bitmode"].GetUint();
nPixelsX = doc["shape"][0].GetUint();
nPixelsY = doc["shape"][1].GetUint();
filename = doc["fname"].GetString();
acqIndex = doc["acqIndex"].GetUint64();
frameIndex = doc["fIndex"].GetUint64();
fileindex = doc["fileIndex"].GetUint64();
subFrameIndex = doc["expLength"].GetUint();
xCoord = doc["xCoord"].GetUint();
yCoord = doc["yCoord"].GetUint();
zCoord = doc["zCoord"].GetUint();
flippedDataX=doc["flippedDataX"].GetUint();
packetNumber=doc["packetNumber"].GetUint();
bunchId=doc["bunchId"].GetUint();
timestamp=doc["timestamp"].GetUint();
modId=doc["modId"].GetUint();
debug=doc["debug"].GetUint();
roundRNumber=doc["roundRNumber"].GetUint();
detType=doc["detType"].GetUint();
version=doc["version"].GetUint();
cprintf(BLUE, "Header Info:\n"
"size: %u\n"
"multisize: %u\n"
"dynamicRange: %u\n"
"nPixelsX: %u\n"
"nPixelsY: %u\n"
"currentFileName: %s\n"
"currentAcquisitionIndex: %lu\n"
"currentFrameIndex: %lu\n"
"currentFileIndex: %lu\n"
"currentSubFrameIndex: %u\n"
"xCoordX: %u\n"
"yCoordY: %u\n"
"zCoordZ: %u\n"
"flippedDataX: %u\n"
"packetNumber: %u\n"
"bunchId: %u\n"
"timestamp: %u\n"
"modId: %u\n"
"debug: %u\n"
"roundRNumber: %u\n"
"detType: %u\n"
"version: %u\n",
size, multisize, dynamicRange, nPixelsX, nPixelsY,
filename.c_str(), acqIndex,
frameIndex, fileindex, subFrameIndex,
xCoord, yCoord,zCoord,
flippedDataX, packetNumber, bunchId, timestamp, modId, debug, roundRNumber, detType, version);
if (doc.HasMember("threshold")) {
version=doc["threshold"].GetUint();
}
if (doc.HasMember("roi")) {
xmin=doc["roi"][0].GetUint();
xmax=doc["roi"][1].GetUint();
ymin=doc["roi"][2].GetUint();
ymax=doc["roi"][3].GetUint();
}
if (doc.HasMember("frameMode")) {
frameMode_s=doc["frameMode"].GetString();
}
if (doc.HasMember("detectorMode")) {
detectorMode_s=doc["detectorMode"].GetString();
}
if (doc.HasMember("energyRange")) {
emin=doc["energyRange"][0].GetUint();
emax=doc["energyRange"][0].GetUint();
}
if (doc.HasMember("dynamicRange")) {
dr=doc["dynamicRange"].GetUint();
}
if (doc.HasMember("nSubPixels")) {
nsubPixels=doc["nSubPixels"].GetUint();
}
newFrame=0;
zmqsocket->CloseHeaderMessage();
}
#endif
if (of==NULL) {
sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex);
of=fopen(ofname,"w");
if (of) {
mt->setFilePointer(of);
}else {
cout << "Could not open "<< ofname << " for writing " << endl;
mt->setFilePointer(NULL);
}
}
// get data
length = zmqsocket->ReceiveData(0, buff, size);
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
iframe++;
} // exiting infinite loop
delete zmqsocket;
if (send)
delete zmqsocket2;
cout<<"Goodbye"<< endl;
return 0;
}

View File

@@ -1,292 +0,0 @@
#include "sls_receiver_defs.h"
#include "ZmqSocket.h"
#include "moench03T1ZmqDataNew.h"
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <fstream>
#include "tiffIO.h"
#include<iostream>
//#include "analogDetector.h"
#include "interpolatingDetector.h"
#include "linearInterpolation.h"
#include "multiThreadedAnalogDetector.h"
#include "ansi.h"
#include <iostream>
using namespace std;
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
int main(int argc, char *argv[]) {
/**
* trial.o [socket ip] [starting port number] [send_socket ip] [send port number]
*
*/
int nthreads=20;
int nsigma=5;
int xmin=0;
int xmax=400;
int ymin=0;
int ymax=400;
int nsubpixels=2;
FILE *of=NULL;
int fifosize=1000;
int int_ready=0;
int ok;
// help
if (argc < 3 ) {
cprintf(RED, "Help: %s [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number] [nsubpixels] [nthreads] [nsigma] [xmin xmax ymin ymax]\n", argv[0]);
return EXIT_FAILURE;
}
char* socketip2 = 0;
uint32_t portnum2 = 0;
// receive parameters
int size = 32*2*5000;//atoi(argv[3]);
bool send = false;
char* socketip=argv[1];
uint32_t portnum = atoi(argv[2]);
if (argc > 3) {
send = true;
socketip2 = argv[3];
portnum2 = atoi(argv[4]);
}
if (argc > 5) {
nsubpixels=atoi(argv[5]);
}
if (argc>6) {
nthreads=atoi(argv[6]);
}
if (argc>7) {
nsigma=atoi(argv[7]);
}
if (argc>11) {
xmin=atoi(argv[8]);
xmax=atoi(argv[8]);
ymin=atoi(argv[10]);
ymax=atoi(argv[11]);
}
cout << "\nrx socket ip : " << socketip <<
"\nrx port num : " << portnum ;
if (send) {
cout << "\nsd socket ip : " << socketip2 <<
"\nsd port num : " << portnum2;
}
cout << endl;
//slsDetectorData *det=new moench03T1ZmqDataNew();
int npx, npy;
moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew();
det->getDetectorSize(npx, npy);
linearInterpolation *interp=new linearInterpolation(npx,npy,nsubpixels);
interpolatingDetector *filter=new interpolatingDetector(det,interp, nsigma, 1, 0, 1000, 100,npx,npy);
cout << "Setting noise cut to " << nsigma << " sigma"<< endl;
filter->setROI(xmin,xmax,ymin,ymax);
cout << "Setting ROI to "<< xmin << " " << xmax << " " << ymin << " " << ymax << endl;
char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
int frameMode=eFrame;
mt->setFrameMode(frameMode);
mt->StartThreads();
mt->popFree(buff);
// receive socket
ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum);
if (zmqsocket->IsError()) {
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
delete zmqsocket;
return EXIT_FAILURE;
}
zmqsocket->Connect();
printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress());
// send socket
ZmqSocket* zmqsocket2 = 0;
if (send) {
zmqsocket2 = new ZmqSocket(portnum2, socketip2);
if (zmqsocket2->IsError()) {
bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
delete zmqsocket2;
delete zmqsocket;
return EXIT_FAILURE;
}
zmqsocket2->Connect();
printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress());
}
// header variables
uint64_t acqIndex = -1;
uint64_t frameIndex = -1;
uint32_t subframeIndex = -1;
uint64_t fileindex = -1;
string filename = "";
char ffname[10000];
int ffindex;
char* image = new char[size];
//int* image = new int[(size/sizeof(int))]();
int *nph;
int iframe=0;
char ofname[10000];
char fname[10000];
int length;
int *detimage;
int nnx, nny,nns;
int nix, niy,nis;
filter->getImageSize(nnx, nny,nns);
int16_t *dout=new int16_t [nnx*nny];
// infinite loop
int ix, iy, isx, isy;
while(1) {
// cout << "+++++++++++++++++++++++++++++++LOOP" << endl;
// get header, (if dummy, fail is on parse error or end of acquisition)
if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)){
// if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)) {
// cprintf(RED, "Got Dummy\n");
while (mt->isBusy()) {;}//wait until all data are processed from the queues
if (frameMode==ePedestal) {
detped=mt->getPedestal();
if (detped) {
for (ix=0; ix<400; ix++) {
for (iy=0; iy<400; iy++) {
dout[iy*400+ix]+=detped[iy*400+ix];
}
}
}
} else {
detimage=mt->getImage(nix,niy,nis);
if (detimage) {
for (ix=0; ix<nix/nis; ix++) {
for (iy=0; iy<niy/nis; iy++) {
dout[iy*(nix/nis)+ix]=0;
}
}
for (ix=0; ix<nix; ix++) {
for (iy=0; iy<niy; iy++) {
dout[(iy/nis)*(nix/nis)+(ix/nis)]+=detimage[iy*nix+ix];
}
}
}
}
if (send) {
strcpy(fname,filename.c_str());
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,16,fileindex,400,400,400*400, acqIndex,frameIndex,fname, acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket2->SendData((char*)dout,length);
cprintf(GREEN, "Sent Data\n");
}
sprintf(ofname,"%s_%d.tiff",ffname,ffindex);
if (frameMode==eFlat)
mt->writeFlatField(ofname);
else if (frameMode==ePedestal)
mt->writePedestal(ofname);
else
mt->writeImage(ofname);
// stream dummy to socket2 to signal end of acquisition
if (send) {
zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
// cprintf(RED, "Sent Dummy\n");
cprintf(RED, "Received %d frames\n", iframe);
}
mt->clearImage();
if (of) {
fclose(of);
of=NULL;
}
iframe=0;
continue; //continue to not get out
}
if (of==NULL) {
while (mt->isBusy()) {;}
sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex);
of=fopen(ofname,"w");
if (of) {
mt->setFilePointer(of);
}else {
cout << "Could not open "<< ofname << " for writing " << endl;
mt->setFilePointer(NULL);
}
ffindex=fileindex;
strcpy(ffname,filename.c_str());
if (filename.find("flat")!=std::string::npos) {
cout << "add to ff" << endl;
frameMode=eFlat;//ePedestal;
int_ready=0;
} else if (filename.find("newped")!=std::string::npos) {
frameMode=ePedestal;
cout << "new pedestal" << endl;
mt->newDataSet();
} else if (filename.find("ped")!=std::string::npos){
frameMode=ePedestal;
cout << "pedestal" << endl;
} else {
frameMode=eFrame;
cout << "data" << endl;
if (int_ready==0) {
mt->prepareInterpolation(ok);
cout << "prepare interpolation " << endl;
int_ready=1;
}
}
mt->setFrameMode(frameMode);
}
// get data
length = zmqsocket->ReceiveData(0, buff, size);
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
iframe++;
} // exiting infinite loop
delete zmqsocket;
if (send)
delete zmqsocket2;
// cout<<"Goodbye"<< endl;
return 0;
}

View File

@@ -1,8 +1,20 @@
#define WRITE_QUAD
//#define WRITE_QUAD
#define MOENCH_BRANCH
#include "sls_receiver_defs.h"
#define C_GHOST 0.0004
#define CM_ROWS 20
#include "sls_detector_defs.h"
#include "ZmqSocket.h"
#ifndef RECT
#include "moench03T1ZmqDataNew.h"
#endif
#ifdef RECT
#include "moench03T1ZmqDataNewRect.h"
#endif
#include "moench03GhostSummation.h"
#include "moench03CommonMode.h"
#include <vector>
#include <string>
#include <sstream>
@@ -10,10 +22,7 @@
#include <fstream>
#include "tiffIO.h"
//#define NEWZMQ
#ifdef NEWZMQ
#include <rapidjson/document.h> //json header in zmq stream
#endif
#include<iostream>
@@ -45,11 +54,14 @@ int main(int argc, char *argv[]) {
*/
FILE *of=NULL;
int fifosize=5000;
int etabins=1000;//nsubpix*2*100;
int etabins=1000, etabinsy=1000;//nsubpix*2*100;
double etamin=-1, etamax=2;
int nSubPixelsX=2;
// int emin, emax;
int nSubPixelsY=2;
// help
if (argc < 3 ) {
cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number] [nthreads] [nsubpix] [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");
return EXIT_FAILURE;
}
@@ -61,6 +73,7 @@ int main(int argc, char *argv[]) {
char* socketip2 = 0;
uint32_t portnum2 = 0;
uint32_t nSigma=5;
int ok;
@@ -86,17 +99,26 @@ int main(int argc, char *argv[]) {
nthreads=atoi(argv[5]);
cout << "Number of threads is: " << nthreads << endl;
int nSubPixels=2;
if (argc>6)
nSubPixels=atoi(argv[6]);
cout << "Number of subpixels is: " << nSubPixels << endl;
char *etafname=NULL;
if (argc>6) {
nSubPixelsX=atoi(argv[6]);
nSubPixelsY=nSubPixelsX;
#ifdef RECT
nSubPixelsX=2;
#endif
}
cout << "Number of subpixels is: " << nSubPixelsX << " " << nSubPixelsY << endl;
char *gainfname=NULL;
if (argc>7) {
etafname=argv[7];
cout << "Eta file name is: " << etafname << endl;
gainfname=argv[7];
cout << "Gain map file name is: " << gainfname << endl;
}
char *etafname=NULL;
if (argc>8) {
etafname=argv[8];
cout << "Eta file name is: " << etafname << endl;
}
//slsDetectorData *det=new moench03T1ZmqDataNew();
moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew();
@@ -104,32 +126,64 @@ int main(int argc, char *argv[]) {
int npx, npy;
det->getDetectorSize(npx, npy);
int send_something=0;
int maxSize = npx*npy*2;//32*2*8192;//5000;//atoi(argv[3]);
int size= maxSize;//32*2*5000;
int multisize=size;
int dataSize=size;
//int multisize=size;
//int dataSize=size;
char dummybuff[size];
int ncol_cm=CM_ROWS;
double xt_ghost=C_GHOST;
moench03CommonMode *cm=NULL;
moench03GhostSummation *gs=NULL;
#ifdef CORR
gs=new moench03GhostSummation(det, xt_ghost);
cm=new moench03CommonMode(ncol_cm);
#endif
double *gainmap=NULL;
float *gm;
double *gmap=NULL;
uint32_t nnnx, nnny;
if (gainfname) {
gm=ReadFromTiff(gainfname, nnny, nnnx);
if (gm && nnnx==(uint)npx && nnny==(uint)npy) {
gmap=new double[npx*npy];
for (int i=0; i<npx*npy; i++) {
gmap[i]=gm[i];
}
delete [] gm;
} else
cout << "Could not open gain map " << gainfname << endl;
}
//analogDetector<uint16_t> *filter=new analogDetector<uint16_t>(det,1,NULL,1000);
#ifndef INTERP
singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10);
singlePhotonDetector *filter=new singlePhotonDetector(det,3, nSigma, 1, cm, 1000, 10, -1, -1, gainmap, gs);
multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize);
// multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
#endif
#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);
interpolatingDetector *filter=new interpolatingDetector(det,interp, 5, 1, 0, 1000, 10);
interpolatingDetector *filter=new interpolatingDetector(det,interp, nSigma, 1, cm, 1000, 10, -1, -1, gainmap, gs);
multiThreadedInterpolatingDetector *mt=new multiThreadedInterpolatingDetector(filter,nthreads,fifosize);
#endif
@@ -220,21 +274,32 @@ int main(int argc, char *argv[]) {
// header variables
uint64_t acqIndex = -1;
uint64_t frameIndex = -1;
uint32_t subFrameIndex = -1;
#ifdef MOENCH_BRANCH
uint32_t subFrameIndex = -1;
int* flippedData = 0;
#endif
uint64_t subframes=0;
//uint64_t isubframe=0;
uint64_t insubframe=0;
double subnorm=1;
uint64_t f0=-1, nsubframes=0, nnsubframe=0;
uint64_t fileindex = -1;
string filename = "";
// char* image = new char[size];
//int* image = new int[(size/sizeof(int))]();
uint32_t flippedDataX = -1;
int *nph;
//uint32_t flippedDataX = -1;
//int *nph;
int iframe=0;
char ofname[10000];
char fname[10000];
int length;
int *detimage;
int nnx, nny,nns;
uint32_t imageSize = 0, nPixelsX = 0, nPixelsY = 0, dynamicRange = 0;
string fname;
// int length;
int *detimage=NULL;
int nnx, nny,nnsx, nnsy;
//uint32_t imageSize = 0, nPixelsX = 0, nPixelsY = 0,
//uint32_t dynamicRange = 0;
// infinite loop
uint32_t packetNumber = 0;
uint64_t bunchId = 0;
@@ -248,11 +313,10 @@ int main(int argc, char *argv[]) {
//int16_t *dout;//=new int16_t [nnx*nny];
uint32_t dr = 32;
int32_t *dout=NULL;//=new int32_t [nnx*nny];
uint32_t nSigma=5;
float *doutf=NULL;//=new int32_t [nnx*nny];
uint16_t roundRNumber = 0;
uint8_t detType = 0;
uint8_t version = 0;
int* flippedData = 0;
char* additionalJsonHeader = 0;
int32_t threshold=0;
@@ -261,18 +325,17 @@ int main(int argc, char *argv[]) {
string frameMode_s, detectorMode_s, intMode_s;
int emin, emax;
int resetFlat=0;
int resetPed=0;
int nsubPixels=1;
int isPedestal;
int isFlat=0;
// int resetFlat=0;
//int resetPed=0;
// int nsubPixels=1;
//int isPedestal=0;
//int isFlat=0;
int newFrame=1;
detectorMode dMode;
frameMode fMode;
detectorMode dMode=eAnalog;
frameMode fMode=eFrame;
double *ped;
filter->getImageSize(nnx, nny,nns);
filter->getImageSize(nnx, nny,nnsx, nnsy);
@@ -301,8 +364,9 @@ int main(int argc, char *argv[]) {
while (mt->isBusy()) {;}//wait until all data are processed from the queues
usleep(1000);
if (of) {
mt->setFilePointer(NULL);
fclose(of);
of=NULL;
}
@@ -313,35 +377,70 @@ int main(int argc, char *argv[]) {
cprintf(RED, "Sent Dummy\n");
}
} else {
if (fMode==ePedestal) {
sprintf(ofname,"%s_%d_ped.tiff",fname,fileindex);
mt->writePedestal(ofname);
cout << "Writing pedestal to " << ofname << endl;
}
send_something=0;
if (fMode==ePedestal) {
sprintf(ofname,"%s_%ld_ped.tiff",fname.c_str(),fileindex);
mt->writePedestal(ofname);
cout << "Writing pedestal to " << ofname << endl;
send_something=1;
}
#ifdef INTERP
else if (fMode==eFlat) {
mt->prepareInterpolation(ok);
sprintf(ofname,"%s_%d_eta.tiff",fname,fileindex);
mt->writeFlatField(ofname);
cout << "Writing eta to " << ofname << endl;
}
else if (fMode==eFlat) {
mt->prepareInterpolation(ok);
sprintf(ofname,"%s_%ld_eta.tiff",fname.c_str(),fileindex);
mt->writeFlatField(ofname);
cout << "Writing eta to " << ofname << endl;
send_something=1;
}
#endif
else {
sprintf(ofname,"%s_%d.tiff",fname,fileindex);
mt->writeImage(ofname);
cout << "Writing image to " << ofname << endl;
}
// cout << nns*nnx*nny*nns*dr/8 << " " << length << endl;
else {
if (subframes>0 ) {
if (insubframe>0) {
sprintf(ofname,"%s_sf%ld_%ld.tiff",fname.c_str(),nnsubframe,fileindex);
// mt->writeImage(ofname);
doutf= new float[nnx*nny];
if (subframes>0 && insubframe!=subframes && insubframe>0)
subnorm=((double)subframes)/((double)insubframe);
else
subnorm=1.;
for (int ix=0; ix<nnx*nny; ix++) {
doutf[ix]=detimage[ix]*subnorm;
if (doutf[ix]<0) doutf[ix]=0;
}
cout << "Writing image to " << ofname << endl;
WriteToTiff(doutf,ofname ,nnx, nny);
if (doutf)
delete [] doutf;
doutf=NULL;
nsubframes++;
insubframe=0;
send_something=1;
}
} else {
sprintf(ofname,"%s_%ld.tiff",fname.c_str(),fileindex);
mt->writeImage(ofname);
send_something=1;
}
cout << "Writing image to " << ofname << endl;
}
// cout << nns*nnx*nny*nns*dr/8 << " " << length << endl;
if (send) {
if (fMode==ePedestal) {
cprintf(MAGENTA,"Get pedestal!\n");
nns=1;
nnsx=1;
nnsy=1;
nnx=npx;
nny=npy;
//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;
ped=mt->getPedestal();
// cout << "got pedestal " << endl;
@@ -355,11 +454,11 @@ int main(int argc, char *argv[]) {
}
#ifdef INTERP
else if (fMode==eFlat) {
int nb;
double emi, ema;
int *ff=mt->getFlatField(nb, emi, ema);
int nb, nby;
double emi=0, ema=1;
int *ff=mt->getFlatField(nb, nby, emi, ema);
nnx=nb;
nny=nb;
nny=nby;
dout= new int32_t[nb*nb];
for (int ix=0; ix<nb*nb; ix++) {
dout[ix]=ff[ix];
@@ -367,15 +466,19 @@ int main(int argc, char *argv[]) {
}
#endif
else {
detimage=mt->getImage(nnx,nny,nns);
detimage=mt->getImage(nnx,nny,nnsx, nnsy);
cprintf(MAGENTA,"Get image!\n");
cout << nnx << " " << nny << " " << nns << endl;
cout << nnx << " " << nny << " " << nnsx << " " << nnsy << endl;
// nns=1;
// nnx=npx;
// nny=npy;
// nnx=nnx*nns;
//nny=nny*nns;
dout= new int32_t[nnx*nny];
if (subframes>0 && insubframe!=subframes && insubframe>0)
subnorm=((double)subframes)/((double)insubframe);
else
subnorm=1.;
for (int ix=0; ix<nnx*nny; ix++) {
// for (int iy=0; iy<nny*nns; iy++) {
// for (int isx=0; isx<nns; isx++) {
@@ -387,34 +490,41 @@ int main(int argc, char *argv[]) {
// }
// }
dout[ix]=detimage[ix];
dout[ix]=detimage[ix]*subnorm;
if (dout[ix]<0) dout[ix]=0;
// cout << ix << " " << dout[ix] << endl;
// }
}
}
//if ((insubframe>0 && subframes>0) || (subframes<=0) ){
#ifdef NEWZMQ
cout << "Sending image size " << nnx << " " << nny << endl;
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);
if(send_something) {
#ifndef DEVELOPER
#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.c_str(), acqIndex,0 , packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, additionalJsonHeader);
#endif
#ifndef NEWZMQ
zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
#endif
zmqsocket2->SendData((char*)dout,nnx*nny*dr/8);
cprintf(GREEN, "Sent Data\n");
zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
cprintf(RED, "Sent Dummy\n");
if (dout)
delete [] dout;
dout=NULL;
#ifdef DEVELOPER
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
#ifdef MOENCH_BRANCH
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
zmqsocket2->SendData((char*)dout,nnx*nny*dr/8);
cprintf(GREEN, "Sent Data\n");
}
zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
cprintf(RED, "Sent Dummy\n");
if (dout)
delete [] dout;
dout=NULL;
}
}
@@ -427,8 +537,8 @@ int main(int argc, char *argv[]) {
// auto meas_duration = duration_cast<microseconds>( t2 - t0 ).count();
// auto real_duration = duration_cast<microseconds>( t2 - t1 ).count();
cout << "Measurement lasted " << difftime(end,begin) << endl;
cout << "Processing lasted " << difftime(finished,begin) << endl;
// cout << "Measurement lasted " << difftime(end,begin) << endl;
//cout << "Processing lasted " << difftime(finished,begin) << endl;
continue; //continue to not get out
@@ -443,7 +553,7 @@ int main(int argc, char *argv[]) {
// acqIndex, frameIndex, subframeIndex, filename, fileindex
size = doc["size"].GetUint();
// multisize = size;// * zmqsocket->size();
dynamicRange = doc["bitmode"].GetUint();
// dynamicRange = doc["bitmode"].GetUint();
// nPixelsX = doc["shape"][0].GetUint();
// nPixelsY = doc["shape"][1].GetUint();
filename = doc["fname"].GetString();
@@ -460,10 +570,10 @@ int main(int argc, char *argv[]) {
//detType=doc["detType"].GetUint();
//version=doc["version"].GetUint();
dataSize=size;
strcpy(fname,filename.c_str());
//dataSize=size;
//strcpy(fname,filename.c_str());
fname=filename;
// cprintf(BLUE, "Header Info:\n"
// "size: %u\n"
// "multisize: %u\n"
@@ -494,8 +604,8 @@ int main(int argc, char *argv[]) {
// flippedDataX, packetNumber, bunchId, timestamp, modId, debug, roundRNumber, detType, version);
/* Analog detector commands */
isPedestal=0;
isFlat=0;
//isPedestal=0;
//isFlat=0;
fMode=eFrame;
frameMode_s="frame";
cprintf(MAGENTA, "Frame mode: ");
@@ -504,28 +614,28 @@ int main(int argc, char *argv[]) {
frameMode_s=doc["frameMode"].GetString();
if (frameMode_s == "pedestal"){
fMode=ePedestal;
isPedestal=1;
//isPedestal=1;
} else if (frameMode_s == "newPedestal"){
mt->newDataSet(); //resets pedestal
// cprintf(MAGENTA, "Resetting pedestal\n");
fMode=ePedestal;
isPedestal=1;
//isPedestal=1;
}
#ifdef INTERP
else if (frameMode_s == "flatfield") {
fMode=eFlat;
isFlat=1;
//isFlat=1;
} else if (frameMode_s == "newFlatfield") {
mt->resetFlatField();
isFlat=1;
//isFlat=1;
cprintf(MAGENTA, "Resetting flatfield\n");
fMode=eFlat;
}
#endif
else {
fMode=eFrame;
isPedestal=0;
isFlat=0;
//isPedestal=0;
//isFlat=0;
fMode=eFrame;
frameMode_s="frame";
}
@@ -648,6 +758,21 @@ int main(int argc, char *argv[]) {
// mt->setNSubPixels(nSubPixels);
// }
// threshold=0;
cprintf(MAGENTA, "Subframes: ");
subframes=0;
//isubframe=0;
insubframe=0;
subnorm=1;
f0=0;
nnsubframe=0;
if (doc.HasMember("subframes")) {
if (doc["subframes"].IsInt()) {
subframes=doc["subframes"].GetInt();
}
}
cprintf(MAGENTA, "%ld\n", subframes);
newFrame=0;
/* zmqsocket->CloseHeaderMessage();*/
@@ -657,7 +782,12 @@ int main(int argc, char *argv[]) {
// cout << "file" << endl;
// cout << "data " << endl;
if (of==NULL) {
sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex);
#ifdef WRITE_QUAD
sprintf(ofname,"%s_%ld.clust2",filename.c_str(),fileindex);
#endif
#ifndef WRITE_QUAD
sprintf(ofname,"%s_%ld.clust",filename.c_str(),fileindex);
#endif
of=fopen(ofname,"w");
if (of) {
mt->setFilePointer(of);
@@ -666,31 +796,109 @@ int main(int argc, char *argv[]) {
mt->setFilePointer(NULL);
}
}
// cout << "data" << endl;
// get data
// acqIndex = doc["acqIndex"].GetUint64();
frameIndex = doc["fIndex"].GetUint64();
// subFrameIndex = doc["expLength"].GetUint();
// bunchId=doc["bunchId"].GetUint();
// timestamp=doc["timestamp"].GetUint();
packetNumber=doc["packetNumber"].GetUint();
// cout << acqIndex << " " << frameIndex << " " << subFrameIndex << " "<< bunchId << " " << timestamp << " " << packetNumber << endl;
if (packetNumber>=40) {
//*((int*)buff)=frameIndex;
memcpy(buff,&frameIndex,sizeof(int));
length = zmqsocket->ReceiveData(0, buff+sizeof(int), size);
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
} else {
cprintf(RED, "Incomplete frame: received only %d packet\n", packetNumber);
length = zmqsocket->ReceiveData(0, dummybuff, size);
packetNumber=doc["packetNumber"].GetUint();
// cout << acqIndex << " " << frameIndex << " " << subFrameIndex << " "<< bunchId << " " << timestamp << " " << packetNumber << endl;
if (packetNumber>0) {
//*((int*)buff)=frameIndex;
if (insubframe==0) f0=frameIndex;
memcpy(buff,&frameIndex,sizeof(int));
//length =
zmqsocket->ReceiveData(0, buff+sizeof(int), size);
mt->pushData(buff);
mt->nextThread();
mt->popFree(buff);
insubframe++;
nsubframes=frameIndex+1-f0;
} else {
cprintf(RED, "Empty frame %d\n", frameIndex);
//length =
zmqsocket->ReceiveData(0, dummybuff, size);
}
if (subframes>0 && insubframe>=subframes && fMode==eFrame) {
while (mt->isBusy()) {;}//wait until all data are processed from the queues
detimage=mt->getImage(nnx,nny,nnsx, nnsy);
cprintf(MAGENTA,"Get image!\n");
dout= new int32_t[nnx*nny];
doutf= new float[nnx*nny];
if (subframes>0 && insubframe!=subframes && insubframe>0)
subnorm=((double)subframes)/((double)insubframe);
else
subnorm=1.;
for (int ix=0; ix<nnx*nny; ix++) {
dout[ix]=detimage[ix]*subnorm;
if (dout[ix]<0) dout[ix]=0;
doutf[ix]=dout[ix];
}
sprintf(ofname,"%s_sf%ld_%ld.tiff",fname.c_str(),nnsubframe,fileindex);
cout << "Writing image to " << ofname << endl;
WriteToTiff(doutf,ofname ,nnx, nny);
nsubframes++;
insubframe=0;
nnsubframe++;
#ifndef DEVELOPER
#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.c_str(), acqIndex,0 , packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, additionalJsonHeader);
#endif
#endif
#ifdef DEVELOPER
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
#ifdef MOENCH_BRANCH
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
zmqsocket2->SendData((char*)dout,nnx*nny*dr/8);
cprintf(GREEN, "Sent subdata\n");
if (dout)
delete [] dout;
dout=NULL;
if (doutf)
delete [] doutf;
doutf=NULL;
mt->clearImage();
}
}
iframe++;

View File

@@ -1,57 +0,0 @@
#include <TPaveText.h>
#include <TLegend.h>
#include <TF1.h>
#include <TGraphErrors.h>
#include <TH2F.h>
#include <TASImage.h>
#include <TImage.h>
#include <TFile.h>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <fstream>
#include "tiffIO.h"
#include<iostream>
using namespace std;
int main(int argc, char *argv[]) {
/**
* trial.o [socket ip] [starting port number] [outfname]
*
*/
if (argc<3) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " outfile " << endl;
return 1;
}
uint32 nx, ny;
float *data=ReadFromTiff(argv[1],nx, ny);
TH2F *h2=NULL;
if (data) {
TFile *fout=new TFile(argv[2],"RECREATE");
if (fout) {
h2=new TH2F("h2",argv[1],nx,0,nx,ny,0, ny);
for (int ix=0; ix<nx ; ix++) {
for (int iy=0; iy<ny ; iy++) {
h2->SetBinContent(ix+1, iy+1, data[ix+iy*nx]);
}
}
h2->Write();
fout->Close();
}
delete [] data;
}
return 0;
}

View File

@@ -32,11 +32,11 @@ class threadedAnalogDetector
{
public:
threadedAnalogDetector(analogDetector<uint16_t> *d, int fs=10000) {
char *mem, *mm;
char *mm;//*mem,
det=d;
fifoFree=new CircularFifo<char>(fs);
fifoData=new CircularFifo<char>(fs);
// mem==NULL;
/* mem=(char*)calloc(fs, det->getDataSize()); */
/* if (mem) */
/* memset(mem,0, fs*det->getDataSize()); */
@@ -46,6 +46,7 @@ public:
// mm=mem+i*det->getDataSize();
// cout << i << endl;
mm=(char*)calloc(1, det->getDataSize());
if (mm) {
//memset(mm,0, det->getDataSize());
fifoFree->push(mm);
@@ -60,7 +61,8 @@ public:
fMode=eFrame;
ff=NULL;
}
virtual int setFrameMode(int fm) {
if (fm>=0) {
@@ -93,14 +95,17 @@ public:
virtual int *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);};
~threadedAnalogDetector() {StopThread(); free(mem); delete fifoFree; delete fifoData;}
virtual ~threadedAnalogDetector() {StopThread(); delete fifoFree; delete fifoData;}
/** Returns true if the thread was successfully started, false if there was an error starting the thread */
virtual bool StartThread()
{ stop=0;
{ stop=0;
cout << "Detector number " << det->getId() << endl;
cout << "common mode is " << det->getCommonModeSubtraction()<< endl;
cout << "ghost summation is " << det->getGhostSummation()<< endl;
return (pthread_create(&_thread, NULL, processData, this) == 0);
}
@@ -111,14 +116,20 @@ public:
virtual bool pushData(char* &ptr) {
fifoData->push(ptr);
return fifoData->push(ptr);
}
virtual bool popFree(char* &ptr) {
fifoFree->pop(ptr);
return fifoFree->pop(ptr);
}
virtual int isBusy() {return busy;}
virtual int isBusy() {
if (fifoData->isEmpty())
busy=0;
else
busy=1;
return busy;
}
//protected:
/** Implement this method in your subclass with the code you want your thread to run. */
@@ -182,23 +193,26 @@ FILE *getFilePointer(){return det->getFilePointer();};
void *writeFlatField(const char * imgname) {
slsInterpolation *interp=(det)->getInterpolation();
cout << "interp " << interp << endl;
//cout << "interp " << interp << endl;
if (interp) {
cout << imgname << endl;
interp->writeFlatField(imgname);
return interp->writeFlatField(imgname);
}
return NULL;
}
void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){
slsInterpolation *interp=(det)->getInterpolation();
if (interp)
interp->readFlatField(imgname, nb, emin, emax);
return interp->readFlatField(imgname, nb, emin, emax);
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();
int *ff=NULL;
if (interp) {
ff=interp->getFlatField(nb,emi,ema);
ff=interp->getFlatField(nb,nby,emi,ema);
}
return ff;
}
@@ -213,10 +227,11 @@ FILE *getFilePointer(){return det->getFilePointer();};
}
virtual int setNSubPixels(int ns) {
virtual void setNSubPixels(int ns, int nsy=-1) {
slsInterpolation *interp=(det)->getInterpolation();
if (interp) return interp->setNSubPixels(ns);
else return 1;};
if (interp) interp->setNSubPixels(ns, nsy);
//else return 1;
};
virtual slsInterpolation *setInterpolation(slsInterpolation *f){
@@ -228,7 +243,6 @@ protected:
int dMode;
int *dataSize;
pthread_t _thread;
char *mem;
CircularFifo<char> *fifoFree;
CircularFifo<char> *fifoData;
int stop;
@@ -242,13 +256,13 @@ protected:
}
void * processData() {
busy=1;
// busy=1;
while (!stop) {
if (fifoData->isEmpty()) {
busy=0;
// busy=0;
usleep(100);
} else {
busy=1;
// busy=1;
fifoData->pop(data); //blocking!
det->processData(data);
fifoFree->push(data);
@@ -292,44 +306,55 @@ public:
StopThreads();
for (int i=0; i<nThreads; i++)
delete dets[i];
for (int i=1; i<nThreads; i++)
delete dd[i];
/* for (int i=1; i<nThreads; i++) */
/* delete dd[i]; */
//delete [] image;
}
virtual int setFrameMode(int fm) { int ret; for (int i=0; i<nThreads; i++) { ret=dets[i]->setFrameMode(fm);} return ret;};
virtual double setThreshold(int fm) { double ret; for (int i=0; i<nThreads; i++) ret=dets[i]->setThreshold(fm); return ret;};
virtual int setDetectorMode(int dm) { int ret; for (int i=0; i<nThreads; i++) ret=dets[i]->setDetectorMode(dm); return ret;};
virtual int setFrameMode(int fm) { int ret=dets[0]->setFrameMode(fm); for (int i=1; i<nThreads; i++) { dets[i]->setFrameMode(fm);} return ret;};
virtual double setThreshold(int fm) { double ret=dets[0]->setThreshold(fm); for (int i=1; i<nThreads; i++) dets[i]->setThreshold(fm); return ret;};
virtual int setDetectorMode(int dm) { int ret=dets[0]->setDetectorMode(dm);; for (int i=1; i<nThreads; i++) dets[i]->setDetectorMode(dm); return ret;};
virtual void setROI(int xmin, int xmax, int ymin, int ymax) { for (int i=0; i<nThreads; i++) dets[i]->setROI(xmin, xmax,ymin,ymax);};
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;
cout << "get image "<< image << endl;
// 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) {
delete image;
cout << "del image "<< image << endl;
delete [] image;
image=NULL;
}
image=new int[nn];
cout << "new image" << image << endl;
//int nn=dets[0]->getImageSize(nnx, nny, ns);
//for (i=0; i<nn; i++) image[i]=0;
for (int ii=0; ii<nThreads; ii++) {
//cout << ii << " " << nn << " " << nnx << " " << nny << " " << ns << endl;
img=dets[ii]->getImage();
for (int i=0; i<nn; i++) {
if (ii==0)
image[i]=img[i];
else
image[i]+=img[i];
//if (img[i]) cout << "det " << ii << " pix " << i << " val " << img[i] << " " << image[i] << endl;
if (image) {
for (int ii=0; ii<nThreads; ii++) {
cout << ii << " " << nn << " " << nnx << " " << nny << " " << nsy << endl;
img=dets[ii]->getImage();
for (int i=0; i<nn; i++) {
if (ii==0)
// if (img[i]>0)
image[i]=img[i];
// else
// image[i]=0;
else //if (img[i]>0)
image[i]+=img[i];
/***
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;
@@ -352,26 +377,32 @@ public:
/* dets[ii]->writeImage(tit); */
/* } */
/* #endif */
int nnx, nny, ns;
getImage(nnx, nny, ns);
cout << "write image" << endl;
int nnx, nny, ns, nsy;
getImage(nnx, nny, ns, nsy);
//int nnx, nny, ns;
int nn=dets[0]->getImageSize(nnx, nny, ns);
float *gm=new float[nn];
if (gm) {
for (int ix=0; ix<nn; ix++) {
if (t)
gm[ix]=(image[ix])/t;
else
gm[ix]=image[ix];
//if (image[ix]>0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl;
}
//cout << "image " << nnx << " " << nny << endl;
WriteToTiff(gm,imgname ,nnx, nny);
delete [] gm;
} else cout << "Could not allocate float image " << endl;
return NULL;
}
int nn=dets[0]->getImageSize(nnx, nny, ns, nsy);
float *gm=new float[nn];
if (gm) {
for (int ix=0; ix<nn; ix++) {
if (t) {
if (image[ix]<0)
gm[ix]=0;
else
gm[ix]=(image[ix])/t;
} else
gm[ix]=image[ix];
//if (image[ix]>0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl;
}
cout << "image " << nnx << " " << nny << endl;
WriteToTiff(gm,imgname ,nnx, nny);
cout << imgname << endl;
delete [] gm;
cout << "del" << endl;
} else cout << "Could not allocate float image " << endl;
return NULL;
}
virtual void StartThreads() {
@@ -402,12 +433,12 @@ public:
virtual bool pushData(char* &ptr) {
dets[ithread]->pushData(ptr);
return dets[ithread]->pushData(ptr);
}
virtual bool popFree(char* &ptr) {
// cout << ithread << endl;
dets[ithread]->popFree(ptr);
return dets[ithread]->popFree(ptr);
}
virtual int nextThread() {
@@ -448,6 +479,37 @@ public:
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){
//int nb=0;
@@ -484,23 +546,44 @@ public:
};
virtual void *readPedestal(const char * imgname, int nb=-1, double emin=1, double emax=0){
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){
int nx, ny;
dets[0]->getDetectorSize(nx,ny);
uint32 nnx;
uint32 nny;
float *gm=ReadFromTiff(imgname, nnx, nny);
if (ped) delete [] ped;
if (nnx>nx) nx=nnx;
if (nny>ny) ny=nny;
if (nnx>(uint)nx) nx=nnx;
if (nny>(uint)ny) ny=nny;
ped=new double[nx*ny];
for (int ix=0; ix<nx*ny; ix++) {
ped[ix]=gm[ix];
}
delete [] gm;
return setPedestal();
};
@@ -539,7 +622,7 @@ public:
int *ff;
double *ped;
pthread_mutex_t fmutex;
};
};
#endif

View File

@@ -25,7 +25,7 @@ class multiThreadedCountingDetector : public multiThreadedAnalogDetector
public:
multiThreadedCountingDetector(singlePhotonDetector *d, int n, int fs=1000) : multiThreadedAnalogDetector(d,n,fs) { };
virtual double setNSigma(double n) {double ret; for (int i=0; i<nThreads; i++) ret=(dets[i])->setNSigma(n); return ret;};
virtual double setNSigma(double n) {double ret=(dets[0])->setNSigma(n); for (int i=1; i<nThreads; i++) (dets[i])->setNSigma(n); return ret;};
virtual void setEnergyRange(double emi, double ema) {for (int i=0; i<nThreads; i++) (dets[i])->setEnergyRange(emi,ema);};
};

View File

@@ -28,8 +28,8 @@ public:
return (dets[0])->getFlatField();
}
virtual int *getFlatField(int &nb, double emi, double ema){
return (dets[0])->getFlatField(nb,emi,ema);
virtual int *getFlatField(int &nb, int &nby, double emi, double ema){
return (dets[0])->getFlatField(nb,nby,emi,ema);
}
virtual int *setFlatField(int *h=NULL, int nb=-1, double emin=1, double emax=0){
@@ -37,16 +37,16 @@ public:
};
void *writeFlatField(const char * imgname){
dets[0]->writeFlatField(imgname);
return dets[0]->writeFlatField(imgname);
};
void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){
(dets[0])->readFlatField(imgname, nb, emin, emax);
return (dets[0])->readFlatField(imgname, nb, emin, emax);
};
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();};
@@ -56,7 +56,7 @@ public:
\returns current file pointer
*/
virtual slsInterpolation *setInterpolation(slsInterpolation *f){
int ok;
//int ok;
for (int i=0; i<nThreads; i++)
(dets[i])->setInterpolation(f);
return (dets[0])->getInterpolation();
@@ -69,15 +69,15 @@ public:
virtual int *getImage(int &nnx, int &nny, int &ns) {
if (getInterpolation()==NULL) return multiThreadedAnalogDetector::getImage(nnx,nny,ns);
virtual int *getImage(int &nnx, int &nny, int &nsx, int &nsy) {
if (getInterpolation()==NULL) return multiThreadedAnalogDetector::getImage(nnx,nny,nsx, nsy);
//if one interpolates, the whole image is stored in detector 0;
int *img;
// 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) {
delete image;
delete [] image;
image=NULL;
}
image=new int[nn];

View File

@@ -4,7 +4,7 @@
#include "analogDetector.h"
#include "single_photon_hit.h"
#include <mutex>
//#define MYROOT1
@@ -58,17 +58,14 @@ public analogDetector<uint16_t> {
int sign=1,
commonModeSubtraction *cm=NULL,
int nped=1000,
int nd=100, int nnx=-1, int nny=-1, double *gm=NULL) : analogDetector<uint16_t>(d, sign, cm, nped, nnx, nny, gm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), clusters(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0), eMin(-1), eMax(-1) {
int nd=100, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation<uint16_t> *gs=NULL) : analogDetector<uint16_t>(d, sign, cm, nped, nnx, nny, gm, gs), nDark(nd), eventMask(NULL),nSigma (nsigma), eMin(-1), eMax(-1), clusterSize(csize), clusterSizeY(csize), clusters(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) {
fm=new pthread_mutex_t ;
fm=new mutex;
// fm=new pthread_mutex_t ;
eventMask=new eventType*[ny];
for (int i=0; i<ny; i++) {
eventMask[i]=new eventType[nx];
}
eventMask=new eventType[ny*nx];
if (ny==1)
clusterSizeY=1;
@@ -84,7 +81,7 @@ public analogDetector<uint16_t> {
/**
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;
myFile=orig->myFile;
eventMask=new eventType*[ny];
for (int i=0; i<ny; i++) {
eventMask[i]=new eventType[nx];
}
eventMask=new eventType[ny*nx];
eMin=orig->eMin;
eMax=orig->eMax;
@@ -117,6 +111,9 @@ public analogDetector<uint16_t> {
setClusterSize(clusterSize);
fm=orig->fm;
//setMutex(orig->fm);
quad=UNDEFINED_QUADRANT;
tot=0;
@@ -182,14 +179,14 @@ public analogDetector<uint16_t> {
nph=image;
//nph=new int[nx*ny];
double rest[ny][nx];
int cy=(clusterSizeY+1)/2; //quad size
int cs=(clusterSize+1)/2; //quad size
double rest[ny*nx];
//int cy=(clusterSizeY+1)/2; //quad size
//int cs=(clusterSize+1)/2; //quad size
int ccs=clusterSize; //cluster size
int ccy=clusterSizeY; //cluster size
//int ccs=clusterSize; //cluster size
//int ccy=clusterSizeY; //cluster size
double g=1.;
//double g=1.;
double tthr=thr, tthr1, tthr2;
@@ -201,10 +198,10 @@ public analogDetector<uint16_t> {
if (cmSub) cm=1;
if (thr>0) {
cy=1;
cs=1;
ccs=1;
ccy=1;
//cy=1;
//cs=1;
//ccs=1;
//ccy=1;
}
if (iframe<nDark) {
// cout << "ped " << iframe << endl;
@@ -213,24 +210,24 @@ public analogDetector<uint16_t> {
return nph;
} else {
if (thr>0) {
newFrame();
newFrame(data);
if (cmSub) {
cout << "add to common mode?"<< endl;
addToCommonMode(data);
}
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
if (det->isGood(ix,iy)) {
val=subtractPedestal(data,ix,iy, cm);
nn=analogDetector<uint16_t>::getNPhotons(data,ix,iy);//val/thr;//
if (nn>0) {
nph[ix+nx*iy]+=nn;
rest[iy][ix]=(val-nn*thr);//?+0.5*thr
rest[iy*nx+ix]=(val-nn*thr);//?+0.5*thr
nphFrame+=nn;
nphTot+=nn;
} else
rest[iy][ix]=val;
rest[iy*nx+ix]=val;
}
}
@@ -240,7 +237,7 @@ public analogDetector<uint16_t> {
for (int ix=xmin; ix<xmax; ix++) {
if (det->isGood(ix,iy)) {
eventMask[iy][ix]=PEDESTAL;
eventMask[iy*nx+ix]=PEDESTAL;
max=0;
tl=0;
tr=0;
@@ -249,15 +246,15 @@ public analogDetector<uint16_t> {
tot=0;
quadTot=0;
if (rest[iy][ix]>0.25*thr) {
eventMask[iy][ix]=NEIGHBOUR;
if (rest[iy*nx+ix]>0.25*thr) {
eventMask[iy*nx+ix]=NEIGHBOUR;
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
if ((iy+ir)>=0 && (iy+ir)<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;
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) {
quad=BOTTOM_LEFT;
quadTot=bl;
@@ -289,9 +287,9 @@ public analogDetector<uint16_t> {
quadTot=tl;
} else if (tr>=bl && tr>=tl && tr>=br) {
quad=TOP_RIGHT;
quadTot=tr;
quadTot=tr;
}
if (nSigma==0) {
tthr=thr;
tthr1=thr;
@@ -312,9 +310,9 @@ public analogDetector<uint16_t> {
}
if (tot>tthr1 || quadTot>tthr2 || max>tthr) {
eventMask[iy][ix]=PHOTON;
eventMask[iy*nx+ix]=PHOTON;
nph[ix+nx*iy]++;
rest[iy][ix]-=thr;
rest[iy*nx+ix]-=thr;
nphFrame++;
nphTot++;
@@ -322,9 +320,8 @@ public analogDetector<uint16_t> {
}
}
}
}
}
}
}
} else return getClusters(data, nph);
}
return NULL;
@@ -346,12 +343,12 @@ int *getClusters(char *data, int *ph=NULL) {
int nph=0;
double val[ny][nx];
double val[ny*nx];
int cy=(clusterSizeY+1)/2;
int cs=(clusterSize+1)/2;
int ir, ic;
double max=0, tl=0, tr=0, bl=0,br=0, *v, vv;
//int ir, ic;
int iframe=det->getFrameNumber(data);
double max=0, tl=0, tr=0, bl=0,br=0, *v;
int cm=0;
int good=1;
if (cmSub) cm=1;
@@ -362,16 +359,16 @@ int *getClusters(char *data, int *ph=NULL) {
addToPedestal(data);
return 0;
}
newFrame();
newFrame(data);
if (cm)
if (cm) {
addToCommonMode(data);
}
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
for (int iy=ymin; iy<ymax; iy++) {
for (int ix=xmin; ix<xmax; ix++) {
if (det->isGood(ix,iy)) {
max=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);
@@ -394,35 +391,40 @@ int *getClusters(char *data, int *ph=NULL) {
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
if ((iy+ir)>=iy && (iy+ir)<ny && (ix+ic)>=ix && (ix+ic)<nx) {
val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm);
}
v=&(val[iy+ir][ix+ic]);
tot+=*v;
if (ir<=0 && ic<=0)
bl+=*v;
if (ir<=0 && ic>=0)
br+=*v;
if (ir>=0 && ic<=0)
tl+=*v;
if (ir>=0 && ic>=0)
tr+=*v;
if (*v>max) {
max=*v;
}
if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) {
if ((iy+ir)>=iy &&(ix+ic)>=ix)
val[(iy+ir)*nx+ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm);
(clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir);
v=&(val[(iy+ir)*nx+ix+ic]);
tot+=*v;
if (ir<=0 && ic<=0)
bl+=*v;
if (ir<=0 && ic>=0)
br+=*v;
if (ir>=0 && ic<=0)
tl+=*v;
if (ir>=0 && ic>=0)
tr+=*v;
if (*v>max) {
max=*v;
}
if (ir==0 && ic==0) {
if (*v<-nSigma*(clusters+nph)->rms)
eventMask[iy][ix]=NEGATIVE_PEDESTAL;
else if (*v>nSigma*(clusters+nph)->rms)
eventMask[iy][ix]=PHOTON;
}
if (ir==0 && ic==0) {
if (*v<-nSigma*(clusters+nph)->rms)
eventMask[iy*nx+ix]=NEGATIVE_PEDESTAL;
else if (*v>nSigma*(clusters+nph)->rms)
eventMask[iy*nx+ix]=PHOTON;
}
} else
(clusters+nph)->set_data(0,ic,ir);
}
}
if (eventMask[iy][ix]==PHOTON && val[iy][ix]<max)
if (eventMask[iy*nx+ix]==PHOTON && val[iy*nx+ix]<max)
continue;
if (bl>=br && bl>=tl && bl>=tr) {
@@ -430,7 +432,7 @@ int *getClusters(char *data, int *ph=NULL) {
(clusters+nph)->quadTot=bl;
} else if (br>=bl && br>=tl && br>=tr) {
(clusters+nph)->quad=BOTTOM_RIGHT;
(clusters+nph)->quadTot=br;
(clusters+nph)->quadTot=br;
} else if (tl>=br && tl>=bl && tl>=tr) {
(clusters+nph)->quad=TOP_LEFT;
(clusters+nph)->quadTot=tl;
@@ -438,34 +440,36 @@ int *getClusters(char *data, int *ph=NULL) {
(clusters+nph)->quad=TOP_RIGHT;
(clusters+nph)->quadTot=tr;
}
if (max>nSigma*(clusters+nph)->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*(clusters+nph)->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*(clusters+nph)->rms) {
if (val[iy][ix]>=max) {
eventMask[iy][ix]=PHOTON_MAX;
(clusters+nph)->tot=tot;
(clusters+nph)->x=ix;
(clusters+nph)->y=iy;
// (clusters+nph)->iframe=det->getFrameNumber(data);
// cout << det->getFrameNumber(data) << " " << (clusters+nph)->iframe << endl;
(clusters+nph)->ped=getPedestal(ix,iy,0);
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
(clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir);
if (val[iy*nx+ix]>=max) {
eventMask[iy*nx+ix]=PHOTON_MAX;
// (clusters+nph)->tot=tot;
(clusters+nph)->x=ix;
(clusters+nph)->y=iy;
(clusters+nph)->iframe=iframe;
// cout << det->getFrameNumber(data) << " " << (clusters+nph)->iframe << endl;
// (clusters+nph)->ped=getPedestal(ix,iy,0);
// for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
// for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
// if ((iy+ir)>=0 && (iy+ir)<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 {
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);
}
}
@@ -474,8 +478,9 @@ int *getClusters(char *data, int *ph=NULL) {
nphFrame=nph;
nphTot+=nph;
//cout << nphFrame << endl;
// cout <<"**********************************"<< det->getFrameNumber(data) << " " << nphFrame << endl;
writeClusters(det->getFrameNumber(data));
if (iframe%10000==0)
cout <<"**********************************"<< iframe << " " << nphFrame << endl;
writeClusters(iframe);
return image;
};
@@ -517,7 +522,7 @@ int *getClusters(char *data, int *ph=NULL) {
\param ir y coordinate (center is (0,0))
\returns event mask enum for the given pixel
*/
eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];};
eventType getEventMask(int ic, int ir=0){return eventMask[ir*nx+ic];};
#ifdef MYROOT1
@@ -566,7 +571,9 @@ int *getClusters(char *data, int *ph=NULL) {
/* if (fwrite((void*)&fn, 1, sizeof(int), f)) */
/* if (fwrite((void*)&nph, 1, sizeof(int), f)) */
/* #endif */
for (int i=0; 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){
writeClusters(f,clusters,nphFrame, fn);
@@ -576,12 +583,15 @@ int *getClusters(char *data, int *ph=NULL) {
void writeClusters(int fn){
if (myFile) {
//cout << "++" << endl;
pthread_mutex_lock(fm);
// cout <<"**********************************"<< fn << " " << nphFrame << endl;
//pthread_mutex_lock(fm);
fm->lock();
// cout <<id << " **********************************"<< fn << " " << nphFrame << endl;
writeClusters(myFile,clusters,nphFrame, fn);
// for (int i=0; i<nphFrame; i++)
// (clusters+i)->write(myFile);
pthread_mutex_unlock(fm);
// cout << "--" << endl;
fm->unlock();
//pthread_mutex_unlock(fm);
//cout << "--" << endl;
}
};
@@ -592,7 +602,7 @@ int *getClusters(char *data, int *ph=NULL) {
switch(fMode) {
case ePedestal:
//cout <<"spc add to ped " << endl;
addToPedestal(data);
addToPedestal(data,1);
break;
default:
switch (dMode) {
@@ -613,12 +623,13 @@ int *getClusters(char *data, int *ph=NULL) {
void setEnergyRange(double emi, double ema){eMin=emi; eMax=ema;};
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:
int nDark; /**< number of frames to be used at the beginning of the dataset to calculate pedestal without applying photon discrimination */
eventType **eventMask; /**< matrix of event type or each pixel */
eventType *eventMask; /**< matrix of event type or each pixel */
double nSigma; /**< number of sigma parameter for photon discrimination */
double eMin, eMax;
int clusterSize; /**< cluster size in the x direction */
@@ -631,8 +642,8 @@ int *getClusters(char *data, int *ph=NULL) {
int nphTot;
int nphFrame;
pthread_mutex_t *fm;
// pthread_mutex_t *fm;
mutex *fm;
};

View File

@@ -44,8 +44,8 @@ class single_photon_hit {
//#endif
#ifndef WRITE_QUAD
//printf("no quad ");
if (fwrite((void*)&x, 2, sizeof(int16_t), myFile))
return fwrite((void*)data, 1, dx*dy*sizeof(int), myFile);
if (fwrite((void*)&x, sizeof(int16_t), 2, myFile))
return fwrite((void*)data, sizeof(int),dx*dy, myFile);
#endif
#ifdef WRITE_QUAD
// printf("quad ");
@@ -91,8 +91,8 @@ class single_photon_hit {
default:
;
}
if (fwrite((void*)&x, 2, sizeof(int16_t), myFile))
return fwrite((void*)qq, 1, 4*sizeof(int), myFile);
if (fwrite((void*)&x, sizeof(int16_t), 2, myFile))
return fwrite((void*)qq, sizeof(int), 4, myFile);
#endif
return 0;
};
@@ -110,20 +110,20 @@ class single_photon_hit {
#ifndef WRITE_QUAD
// printf( "no quad \n");
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
#ifdef WRITE_QUAD
int qq[4];
// printf( "quad \n");
if (fread((void*)&x, 2, sizeof(int16_t), myFile))
if (fread((void*)qq, 1, 4*sizeof(int), myFile)) {
if (fread((void*)&x, sizeof(int16_t), 2, myFile))
if (fread((void*)qq, sizeof(int), 4, myFile)) {
quad=TOP_RIGHT;
int mm=qq[0];
for (int i=1; i<4; i++) {
if (qq[i]<mm) {
if (qq[i]>mm) {
switch (i) {
case 1:
case 1:
quad=TOP_LEFT;
break;
case 2:
@@ -135,7 +135,7 @@ class single_photon_hit {
default:
;
}
mm=qq[i];
}
}
@@ -210,9 +210,12 @@ class single_photon_hit {
};
void print() {
int ix, iy;
#ifdef WRITE_QUAD
printf("Q");
#endif
// int ix, iy;
printf("*** %d %d %d\n",iframe, x, y);
for (int iy=0; iy<dy; iy++) {
for (int ix=0; ix<dx; ix++) {
printf("%d \t",data[ix+iy*dx]);
@@ -220,7 +223,7 @@ class single_photon_hit {
}
printf("\n");
}
printf("***\n");
}

View File

@@ -1,98 +0,0 @@
#ifndef SINGLE_PHOTON_HIT_H
#define SINGLE_PHOTON_HIT_H
#include <stdio.h>
#include <stdint.h>
typedef double double32_t;
typedef float float32_t;
typedef int int32_t;
#ifndef DEF_QUAD
#define DEF_QUAD
enum quadrant {
TOP_LEFT=0,
TOP_RIGHT=1,
BOTTOM_LEFT=2,
BOTTOM_RIGHT=3,
UNDEFINED_QUADRANT=-1
};
#endif
class single_photon_hit_double {
/** @short Structure for a single photon hit */
public:
/** constructor, instantiates the data array -- all class elements are public!
\param nx cluster size in x direction
\param ny cluster size in y direction (defaults to 1 for 1D detectors)
*/
single_photon_hit_double(int nx=3, int ny=3): dx(nx), dy(ny) {
data=new double[dx*dy];
};
~single_photon_hit_double(){delete [] data;}; /**< destructor, deletes the data array */
/** binary write to file of all elements of the structure, except size of the cluster
\param myFile file descriptor
*/
size_t write(FILE *myFile) {
//fwrite((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), myFile);
if (fwrite((void*)this, 1, sizeof(int)+2*sizeof(int), myFile))
return fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);
return 0;
};
/**
binary read from file of all elements of the structure, except size of the cluster. The structure is then filled with those args
\param myFile file descriptor
*/
size_t read(FILE *myFile) {
//fread((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), myFile);
if (fread((void*)this, 1, sizeof(int)+2*sizeof(int), myFile))
return fread((void*)data, 1, dx*dy*sizeof(double), myFile);
return 0;
};
/**
assign the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0)
\param v value to be set
\param ix coordinate x within the cluster (center is (0,0))
\param iy coordinate y within the cluster (center is (0,0))
*/
void set_data(double v, int ix, int iy=0){data[(iy+dy/2)*dx+ix+dx/2]=v;};
void set_cluster_size(int nx, int ny) {
if (nx>0) dx=nx; if (ny>0) dy=ny; delete [] data; data=new double[dx*dy];
};
void get_cluster_size(int &nx, int &ny) {nx=dx; ny=dy;};
void get_pixel(int &x1, int &y1) {x1=x; y1=y;};
/**
gets the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0)
\param ix coordinate x within the cluster (center is (0,0))
\param iy coordinate y within the cluster (center is (0,0))
\returns value of the cluster element
*/
double get_data(int ix, int iy=0){return data[(iy+dy/2)*dx+ix+dx/2];};
double *get_cluster() {return data;};
int iframe; /**< frame number */
int x; /**< x-coordinate of the center of hit */
int y; /**< x-coordinate of the center of hit */
double rms; /**< noise of central pixel l -- at some point it can be removed*/
double ped; /**< pedestal of the central pixel -- at some point it can be removed*/
double tot; /**< sum of the 3x3 cluster */
quadrant quad; /**< quadrant where the photon is located */
double quadTot; /**< sum of the maximum 2x2cluster */
int dx; /**< size of data cluster in x */
int dy; /**< size of data cluster in y */
double *data; /**< pointer to data */
};
#endif

View File

@@ -1,93 +0,0 @@
#ifndef SINGLE_PHOTON_HIT_H
#define SINGLE_PHOTON_HIT_H
#include <stdio.h>
#include <stdint.h>
typedef double double32_t;
typedef float float32_t;
typedef int int32_t;
#ifndef DEF_QUAD
#define DEF_QUAD
enum quadrant {
TOP_LEFT=0,
TOP_RIGHT=1,
BOTTOM_LEFT=2,
BOTTOM_RIGHT=3,
UNDEFINED_QUADRANT=-1
};
#endif
class single_photon_hit {
/** @short Structure for a single photon hit */
public:
/** constructor, instantiates the data array -- all class elements are public!
\param nx cluster size in x direction
\param ny cluster size in y direction (defaults to 1 for 1D detectors)
*/
single_photon_hit(int nx=3, int ny=3): dx(nx), dy(ny) {data=new int[dx*dy];};
~single_photon_hit(){delete [] data;}; /**< destructor, deletes the data array */
/** binary write to file of all elements of the structure, except size of the cluster
\param myFile file descriptor
*/
size_t write(FILE *myFile) {
//fwrite((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), myFile);
if (fwrite((void*)this, 1, sizeof(int)+2*sizeof(int16_t), myFile))
return fwrite((void*)data, 1, dx*dy*sizeof(int), myFile);
return 0;
};
/**
binary read from file of all elements of the structure, except size of the cluster. The structure is then filled with those args
\param myFile file descriptor
*/
size_t read(FILE *myFile) {
//fread((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), myFile);
if (fread((void*)this, 1, sizeof(int)+2*sizeof(int16_t), myFile))
return fread((void*)data, 1, dx*dy*sizeof(int), myFile);
return 0;
};
/**
assign the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0)
\param v value to be set
\param ix coordinate x within the cluster (center is (0,0))
\param iy coordinate y within the cluster (center is (0,0))
*/
void set_data(double v, int ix, int iy=0){data[(iy+dy/2)*dx+ix+dx/2]=v;};
void set_cluster_size(int nx, int ny) {if (nx>0) dx=nx; if (ny>0) dy=ny; delete [] data; data=new int[dx*dy];};
void get_cluster_size(int &nx, int &ny) {nx=dx; ny=dy;};
void get_pixel(int &x1, int &y1) {x1=x; y1=y;};
/**
gets the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0)
\param ix coordinate x within the cluster (center is (0,0))
\param iy coordinate y within the cluster (center is (0,0))
\returns value of the cluster element
*/
double get_data(int ix, int iy=0){return data[(iy+dy/2)*dx+ix+dx/2];};
int *get_cluster() {return data;};
int iframe; /**< frame number */
int16_t x; /**< x-coordinate of the center of hit */
int16_t y; /**< x-coordinate of the center of hit */
double rms; /**< noise of central pixel l -- at some point it can be removed*/
double ped; /**< pedestal of the central pixel -- at some point it can be removed*/
double tot; /**< sum of the 3x3 cluster */
quadrant quad; /**< quadrant where the photon is located */
double quadTot; /**< sum of the maximum 2x2cluster */
int dx; /**< size of data cluster in x */
int dy; /**< size of data cluster in y */
int *data; /**< pointer to data */
};
#endif

View File

@@ -1,103 +0,0 @@
# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
# documentation are documented, even if no documentation was available.
# Private class members and static file members will be hidden unless
# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
EXTRACT_ALL = YES
# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
# will be included in the documentation.
EXTRACT_PRIVATE = NO
# If the EXTRACT_STATIC tag is set to YES all static members of a file
# will be included in the documentation.
EXTRACT_STATIC = YES
# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
# defined locally in source files will be included in the documentation.
# If set to NO only classes defined in header files are included.
EXTRACT_LOCAL_CLASSES = YES
# This flag is only useful for Objective-C code. When set to YES local
# methods, which are defined in the implementation section but not in
# the interface are included in the documentation.
# If set to NO (the default) only methods in the interface are included.
EXTRACT_LOCAL_METHODS = YES
# If this flag is set to YES, the members of anonymous namespaces will be
# extracted and appear in the documentation as a namespace called
# 'anonymous_namespace{file}', where file will be replaced with the base
# name of the file that contains the anonymous namespace. By default
# anonymous namespace are hidden.
EXTRACT_ANON_NSPACES = NO
# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
# undocumented members of documented classes, files or namespaces.
# If set to NO (the default) these members will be included in the
# various overviews, but no documentation section is generated.
# This option has no effect if EXTRACT_ALL is enabled.
HIDE_UNDOC_MEMBERS = NO
# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
# undocumented classes that are normally visible in the class hierarchy.
# If set to NO (the default) these classes will be included in the various
# overviews. This option has no effect if EXTRACT_ALL is enabled.
HIDE_UNDOC_CLASSES = NO
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
# friend (class|struct|union) declarations.
# If set to NO (the default) these declarations will be included in the
# documentation.
HIDE_FRIEND_COMPOUNDS = NO
INTERNAL_DOCS = NO
SHOW_INCLUDE_FILES = NO
SHOW_FILES = NO
SHOW_NAMESPACES = NO
COMPACT_LATEX = YES
PAPER_TYPE = a4
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_HIDE_INDICES = YES
PREDEFINED = __cplusplus
INPUT = analogDetector.h \
pedestalSubtraction.h \
MovingStat.h \
singlePhotonDetector.h \
interpolatingDetector.h tiffIO.h \
single_photon_hit.h \
dataStructures/slsDetectorData.h \
commonModeSubtraction.h \
RunningStat.h \
interpolations/etaInterpolationBase.h \
interpolations/slsInterpolation.h \
interpolations/etaInterpolationPosXY.h \
interpolations/linearInterpolation.h \
interpolations/noInterpolation.h \
interpolations/etaInterpolationGlobal.h \
multiThreadedAnalogDetector.h
OUTPUT_DIRECTORY = slsDetectorCalibrationDocs
#moench03Ctb10GbT1Data.h moench03TCtbData.h moench03T1CtbData.h moench03CtbData.h moench03Ctb10GbData.h moench03TCtb10GbData.h Mythen3_01_jctbData.h adcSar2_jctbData.h eigerHalfModuleData.h energyCalibration.h slsReceiverData.h gotthardModuleData.h gotthardShortModuleData.h jungfrau02Data.h jungfrau10ModuleData.h moench02Ctb10GbData.h moench02CtbData.h moench02ModuleData.h moench03CommonMode.h moenchCommonMode.h chiptestBoardData.h interpolation/etaVEL/interpolation_EtaVEL.h interpolation/etaVEL/EtaVEL.h etaVEL/iterativeEtaInterpolation.h dataStructures/moench03T1ZmqData.h

View File

@@ -4,20 +4,20 @@
#include<iostream>
using namespace std;
// #undef cbf_failnez
// #define cbf_failnez(x) \
// { \
// int err; \
// err = (x); \
// if (err) { \
// fprintf(stderr,"\nCBFlib fatal error %x \n",err); \
// exit(-1); \
// } \
// #define cbf_failnez(x)
// {
// int err;
// err = (x);
// if (err) {
// fprintf(stderr,"\nCBFlib fatal error %x \n",err);
// exit(-1);
// }
// }
void *WriteToTiff(float * imgData, const char * imgname, int nrow, int ncol){
void *WriteToTiff(float * imgData, const char * imgname, int ncol, int nrow){
int sampleperpixel=1;
// unsigned char * buff=NULL;
tsize_t linebytes;
//tsize_t linebytes;
// cout << "--" <<endl;
TIFF * tif = TIFFOpen(imgname,"w");
if (tif) {
@@ -30,7 +30,7 @@ void *WriteToTiff(float * imgData, const char * imgname, int nrow, int ncol){
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
linebytes = sampleperpixel*ncol;
//linebytes = sampleperpixel*ncol;
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, ncol*sampleperpixel));
for(int irow=0; irow<nrow; irow++){
TIFFWriteScanline(tif,&imgData[irow*ncol],irow,0);
@@ -43,14 +43,14 @@ void *WriteToTiff(float * imgData, const char * imgname, int nrow, int ncol){
return NULL;
};
float *ReadFromTiff( const char * imgname, uint32 &nrow, uint32 &ncol){
float *ReadFromTiff( const char * imgname, uint32 &ncol, uint32 &nrow){
// unsigned char * buff=NULL;
TIFF * tif = TIFFOpen(imgname,"r");
if (tif){
uint32 bps;
uint32 sampleperpixel=1;
tsize_t linebytes;
//tsize_t linebytes;
uint32 imagelength;
@@ -61,9 +61,9 @@ float *ReadFromTiff( const char * imgname, uint32 &nrow, uint32 &ncol){
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
float * imgData=new float[ncol*nrow];
linebytes = sampleperpixel*ncol;
//linebytes = sampleperpixel*ncol;
// TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, ncol*sampleperpixel));
for(int irow=0; irow<nrow; irow++){
for(uint32 irow=0; irow<nrow; irow++){
//tiffreadscanline(tif, buf, row);
TIFFReadScanline(tif,&imgData[irow*ncol],irow);
}

View File

@@ -195,7 +195,7 @@ enum networkParameter {
/**
type of action performed (for text client)
*/
enum {GET_ACTION, PUT_ACTION, READOUT_ACTION, HELP_ACTION};
enum {GET_ACTION, PUT_ACTION, READOUT_ACTION, HELP_ACTION, PROCESS_ACTION};
/** online flags enum \sa setOnline*/
enum {GET_ONLINE_FLAG=-1, /**< returns wether the detector is in online or offline state */

View File

@@ -6,7 +6,7 @@
CROSS = bfin-uclinux-
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

View File

@@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/jctbDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: 9e5ec6a57bf206fe9384260fc4040867a9bbd71c
Revision: 33
Branch: developer
Last Changed Author: Erik_Frojdh
Last Changed Rev: 4065
Last Changed Date: 2019-01-30 17:38:35.000000002 +0100 ./firmware_funcs.c
Repsitory UUID: 53ba22dbc40d17c8ca77647d4ca2edad230f9f8a
Revision: 34
Branch: moench
Last Changed Author: Anna_Bergamaschi
Last Changed Rev: 4088
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 GITREPUUID "9e5ec6a57bf206fe9384260fc4040867a9bbd71c"
#define GITAUTH "Erik_Frojdh"
#define GITREV 0x4065
#define GITDATE 0x20190130
#define GITBRANCH "developer"
#define GITREPUUID "53ba22dbc40d17c8ca77647d4ca2edad230f9f8a"
#define GITAUTH "Anna_Bergamaschi"
#define GITREV 0x4088
#define GITDATE 0x20200219
#define GITBRANCH "moench"

View File

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

View File

@@ -8,10 +8,14 @@
#include <stdlib.h>
int progressCallback(double f,void* arg) { cout << f << "%"<< endl; return 0;};
int dummyAcquisitionFinished(double prog,int status,void* p){cout <<"Acquisition finished callback! " << prog << " " << status << endl; return 0;};
int dummyMeasurementFinished(int im,int findex,void* p){cout <<"Measurement finished callback! " << im << " " << findex << endl; return 0;};
int dummyCallback(detectorData* d, int p,void*) {
cout << "got data " << p << endl;
//int (*)(detectorData*, int, int, void*)
int dummyCallback(detectorData*, int p , int p1, void*) {
cout << p << endl;
return 0;
};
@@ -25,7 +29,8 @@ public:
bool verify = true, update = true; \
int del = 0; \
char cmd[100] = ""; \
if (action==slsDetectorDefs::PUT_ACTION && argc<2) { \
cout << "Wrong usage - should be: "<< argv[0] << \
"[id-][pos:]channel arg" << endl; \
@@ -41,7 +46,9 @@ public:
return; \
}; \
if (action==slsDetectorDefs::READOUT_ACTION) { \
if (action==slsDetectorDefs::READOUT_ACTION || action==slsDetectorDefs::PROCESS_ACTION) { \
id = 0; \
pos = -1; \
if (argc) { \
@@ -125,6 +132,18 @@ public:
del=1; \
} \
if (action==slsDetectorDefs::PROCESS_ACTION) {
/* myDetector->registerAcquisitionFinishedCallback(&dummyAcquisitionFinished,NULL); */
/* myDetector->registerMeasurementFinishedCallback(&dummyMeasurementFinished,NULL); */
action=slsDetectorDefs::READOUT_ACTION;
myDetector->registerDataCallback(&dummyCallback, NULL);
// myDetector->registerProgressCallback(&progressCallback, NULL);
}
// call multi detector command line
myCmd=new multiSlsDetectorCommand(myDetector); \
try { \
@@ -142,9 +161,9 @@ public:
} \
if (action!=slsDetectorDefs::READOUT_ACTION) { \
cout << argv[0] << " " ; \
} \
} \
cout << answer<< endl; \
delete myCmd; \
delete myCmd; \
if (del) delete myDetector; \
};

View File

@@ -3242,13 +3242,13 @@ string slsDetector::getSettingsDir() {
return std::string(thisDetector->settingsDir);
}
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() {
return thisDetector->calDir;
}
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
stringstream ss(arg[0]);
char cword[50]="";
bzero(cword, 50);
memset(cword, 0, sizeof(cword));
string 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);
strcpy(arg[0],cword);
@@ -4126,12 +4129,12 @@ int slsDetector::configureMAC() {
//converting MACaddress to hex
stringstream ss(arg[1]);
char cword[50]="";
bzero(cword, 50);
memset(cword, 0, sizeof(cword));
string 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);
#ifdef VERBOSE
std::cout<<"receiver mac:"<<arg[1]<<"."<<std::endl;
@@ -4145,12 +4148,12 @@ int slsDetector::configureMAC() {
{
stringstream ss(arg[3]);
char cword[50]="";
bzero(cword, 50);
memset(cword, 0, sizeof(cword));
string 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);
#ifdef VERBOSE
std::cout<<"detecotor mac:"<<arg[3]<<"."<<std::endl;
@@ -4161,12 +4164,15 @@ int slsDetector::configureMAC() {
//converting IPaddress to hex
stringstream ss(arg[4]);
char cword[50]="";
bzero(cword, 50);
memset(cword, 0, sizeof(cword));
string 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);
#ifdef VERBOSE
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;
int64_t retval;
int64_t retval = FAIL;
char mess[MAX_STR_LENGTH]="";
int ret=OK;
@@ -6051,8 +6057,10 @@ int slsDetector::setUDPConnection() {
std::cout << "could not configure mac" << endl;
}
}
}else
}else{
ret=FAIL;
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
}
#ifdef VERBOSE
printReceiverConfiguration();
#endif

View File

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

View File

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

View File

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

View File

@@ -54,6 +54,20 @@ set_target_properties(sls_detector_acquire PROPERTIES
COMPILE_DEFINITIONS READOUT=1
)
add_executable(sls_detector_process
${SOURCES}
)
target_link_libraries(sls_detector_process
slsDetectorShared
pthread
zmq
rt
)
set_target_properties(sls_detector_process PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
COMPILE_DEFINITIONS PROCESS=1
)
add_executable(sls_detector_help
${SOURCES}
)

View File

@@ -24,7 +24,7 @@ all: clients
nonstatic: clients
clients: builddir lib $(DESTDIR)/sls_detector_put $(DESTDIR)/sls_detector_get $(DESTDIR)/sls_detector_acquire $(DESTDIR)/sls_detector_help
clients: builddir lib $(DESTDIR)/sls_detector_put $(DESTDIR)/sls_detector_get $(DESTDIR)/sls_detector_acquire $(DESTDIR)/sls_detector_help $(DESTDIR)/sls_detector_process
static_clients: builddir lib $(DESTDIR)/ssls_detector_put $(DESTDIR)/ssls_detector_get $(DESTDIR)/ssls_detector_acquire $(DESTDIR)/ssls_detector_help
@@ -89,6 +89,13 @@ $(DESTDIR)/sls_detector_acquire: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DEST
$(CXX) -o $(BIN)/sls_detector_acquire $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DREADOUT $(LIBS) $(LDFLAG)
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
$(DESTDIR)/sls_detector_process: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a
$(call colorecho,"#######################################")
$(call colorecho,"# Compiling sls_detector_process #")
$(call colorecho,"#######################################")
$(CXX) -o $(BIN)/sls_detector_process $(SRC_CLNT) $(FLAGS) $(INCLUDES) -DREADOUT $(LIBS) $(LDFLAG) -DPROCESS
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
$(DESTDIR)/sls_detector_help: $(SRC_CLNT) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a
$(call colorecho,"#######################################")
$(call colorecho,"# Compiling sls_detector_help #")

View File

@@ -4,6 +4,10 @@
#include <stdlib.h>
using namespace std;
#ifdef PROCESS
#endif
int main(int argc, char *argv[])
@@ -15,31 +19,37 @@ int main(int argc, char *argv[])
return 0;
}
}
int action=slsDetectorDefs::HELP_ACTION;
#ifdef PUT
int action=slsDetectorDefs::PUT_ACTION;
action=slsDetectorDefs::PUT_ACTION;
#endif
#ifdef GET
int action=slsDetectorDefs::GET_ACTION;
action=slsDetectorDefs::GET_ACTION;
#endif
#ifdef READOUT
int action=slsDetectorDefs::READOUT_ACTION;
action=slsDetectorDefs::READOUT_ACTION;
#endif
#ifdef PROCESS
action=slsDetectorDefs::PROCESS_ACTION;
#endif
#ifdef HELP
int action=slsDetectorDefs::HELP_ACTION;
action=slsDetectorDefs::HELP_ACTION;
#endif
multiSlsDetectorClient *cl;
if (argc>1)
cl=new multiSlsDetectorClient(argc-1, argv+1, action);
else
else {
cl=new multiSlsDetectorClient(argc-1, argv, action);
}
delete cl;
}

View File

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

View File

@@ -106,4 +106,4 @@ install(TARGETS slsReceiverShared slsReceiverStatic slsReceiver
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
endif
versioning:
$(call colorecho,`./updateGitVersion.sh`)

Some files were not shown because too many files have changed in this diff Show More