From 25541b37f6e23303106b841c576bd78036e7d67c Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Wed, 29 May 2019 11:38:43 +0200 Subject: [PATCH] added patternGenerator and slsDteectorCalibration directory in order to compile the ctbGui --- ctbGui/Makefile.root6 | 4 +- ctbGui/patternGenerator/deserializer.cpp | 110 ++ ctbGui/patternGenerator/generate.sh | 30 + ctbGui/patternGenerator/generator.c | 177 +++ ctbGui/patternGenerator/test.p | 201 +++ slsDetectorCalibration/MovingStat.h | 156 +++ slsDetectorCalibration/RunningStat.h | 55 + slsDetectorCalibration/Stat.h | 45 + slsDetectorCalibration/analogDetector.h | 1166 +++++++++++++++++ .../commonModeSubtraction.h | 82 ++ .../commonModeSubtractionNew.h | 116 ++ .../dataStructures/Mythen3_01_jctbData.h | 123 ++ .../dataStructures/Mythen3_02_jctbData.h | 130 ++ .../dataStructures/adcSar2_jctbData.h | 63 + .../dataStructures/chiptestBoardData.h | 89 ++ .../gotthardDoubleModuleDataNew.h | 172 +++ .../dataStructures/gotthardShortModuleData.h | 127 ++ .../dataStructures/moench02CtbData.h | 169 +++ .../dataStructures/moench03CtbData.h | 157 +++ .../dataStructures/moench03T1CtbData.h | 158 +++ .../moench03T1ReceiverDataNew.h | 290 ++++ .../moench03T1ReceiverDataNewRect.h | 321 +++++ .../dataStructures/moench03T1ReorderedData.h | 176 +++ .../dataStructures/moench03T1ZmqDataNew.h | 268 ++++ .../dataStructures/moench03TCtbData.h | 180 +++ .../dataStructures/moench04CtbReceiverData.h | 291 ++++ .../dataStructures/slsDetectorData.h | 338 +++++ .../dataStructures/slsReceiverData.h | 238 ++++ slsDetectorCalibration/doxy.config | 85 ++ slsDetectorCalibration/energyCalibration.h | 462 +++++++ .../gotthardExecutables/Makefile | 14 + .../interpolatingDetector.h | 275 ++++ .../interpolations/eta2InterpolationBase.h | 403 ++++++ .../interpolations/eta3InterpolationBase.h | 294 +++++ .../etaInterpolationAdaptiveBins.h | 285 ++++ .../interpolations/etaInterpolationBase.h | 369 ++++++ .../etaInterpolationCleverAdaptiveBins.h | 263 ++++ .../interpolations/etaInterpolationGlobal.h | 85 ++ .../interpolations/etaInterpolationPosXY.h | 184 +++ .../etaInterpolationRandomBins.h | 417 ++++++ .../interpolations/etaVEL/EVELAlg.C | 678 ++++++++++ .../interpolations/etaVEL/EtaVEL.cpp | 679 ++++++++++ .../interpolations/etaVEL/EtaVEL.h | 164 +++ .../interpolations/etaVEL/EtaVELTr.py | 393 ++++++ .../etaVEL/etaVELInterpolation.cpp | 134 ++ .../etaVEL/etaVELInterpolation.h | 55 + .../interpolations/linearInterpolation.h | 234 ++++ .../interpolations/noInterpolation.h | 104 ++ .../interpolations/slsInterpolation.h | 503 +++++++ slsDetectorCalibration/moench03CommonMode.h | 45 + slsDetectorCalibration/moenchCommonMode.h | 45 + .../moenchExecutables/Makefile.cluster_finder | 34 + .../moenchExecutables/Makefile.zmq | 16 + .../moench03ClusterFinder.cpp | 237 ++++ .../moench03Interpolation.cpp | 249 ++++ .../moench03NoInterpolation.cpp | 170 +++ .../moenchExecutables/moenchPhotonCounter.cpp | 358 +++++ .../moenchExecutables/moenchZmqProcess.cpp | 707 ++++++++++ .../multiThreadedAnalogDetector.h | 568 ++++++++ .../multiThreadedCountingDetector.h | 51 + .../multiThreadedInterpolatingDetector.h | 112 ++ slsDetectorCalibration/pedestalSubtraction.h | 63 + slsDetectorCalibration/singlePhotonDetector.h | 642 +++++++++ slsDetectorCalibration/single_photon_hit.h | 263 ++++ slsDetectorCalibration/tiffIO.cpp | 77 ++ slsDetectorCalibration/tiffIO.h | 36 + this_build_bin_path.sh | 30 + 67 files changed, 15213 insertions(+), 2 deletions(-) create mode 100644 ctbGui/patternGenerator/deserializer.cpp create mode 100755 ctbGui/patternGenerator/generate.sh create mode 100755 ctbGui/patternGenerator/generator.c create mode 100755 ctbGui/patternGenerator/test.p create mode 100755 slsDetectorCalibration/MovingStat.h create mode 100755 slsDetectorCalibration/RunningStat.h create mode 100644 slsDetectorCalibration/Stat.h create mode 100644 slsDetectorCalibration/analogDetector.h create mode 100644 slsDetectorCalibration/commonModeSubtraction.h create mode 100644 slsDetectorCalibration/commonModeSubtractionNew.h create mode 100644 slsDetectorCalibration/dataStructures/Mythen3_01_jctbData.h create mode 100644 slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h create mode 100644 slsDetectorCalibration/dataStructures/adcSar2_jctbData.h create mode 100644 slsDetectorCalibration/dataStructures/chiptestBoardData.h create mode 100644 slsDetectorCalibration/dataStructures/gotthardDoubleModuleDataNew.h create mode 100644 slsDetectorCalibration/dataStructures/gotthardShortModuleData.h create mode 100644 slsDetectorCalibration/dataStructures/moench02CtbData.h create mode 100644 slsDetectorCalibration/dataStructures/moench03CtbData.h create mode 100644 slsDetectorCalibration/dataStructures/moench03T1CtbData.h create mode 100644 slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h create mode 100644 slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNewRect.h create mode 100644 slsDetectorCalibration/dataStructures/moench03T1ReorderedData.h create mode 100644 slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h create mode 100644 slsDetectorCalibration/dataStructures/moench03TCtbData.h create mode 100644 slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h create mode 100644 slsDetectorCalibration/dataStructures/slsDetectorData.h create mode 100644 slsDetectorCalibration/dataStructures/slsReceiverData.h create mode 100644 slsDetectorCalibration/doxy.config create mode 100644 slsDetectorCalibration/energyCalibration.h create mode 100644 slsDetectorCalibration/gotthardExecutables/Makefile create mode 100644 slsDetectorCalibration/interpolatingDetector.h create mode 100644 slsDetectorCalibration/interpolations/eta2InterpolationBase.h create mode 100644 slsDetectorCalibration/interpolations/eta3InterpolationBase.h create mode 100644 slsDetectorCalibration/interpolations/etaInterpolationAdaptiveBins.h create mode 100644 slsDetectorCalibration/interpolations/etaInterpolationBase.h create mode 100644 slsDetectorCalibration/interpolations/etaInterpolationCleverAdaptiveBins.h create mode 100644 slsDetectorCalibration/interpolations/etaInterpolationGlobal.h create mode 100644 slsDetectorCalibration/interpolations/etaInterpolationPosXY.h create mode 100644 slsDetectorCalibration/interpolations/etaInterpolationRandomBins.h create mode 100644 slsDetectorCalibration/interpolations/etaVEL/EVELAlg.C create mode 100644 slsDetectorCalibration/interpolations/etaVEL/EtaVEL.cpp create mode 100644 slsDetectorCalibration/interpolations/etaVEL/EtaVEL.h create mode 100644 slsDetectorCalibration/interpolations/etaVEL/EtaVELTr.py create mode 100644 slsDetectorCalibration/interpolations/etaVEL/etaVELInterpolation.cpp create mode 100644 slsDetectorCalibration/interpolations/etaVEL/etaVELInterpolation.h create mode 100644 slsDetectorCalibration/interpolations/linearInterpolation.h create mode 100644 slsDetectorCalibration/interpolations/noInterpolation.h create mode 100644 slsDetectorCalibration/interpolations/slsInterpolation.h create mode 100644 slsDetectorCalibration/moench03CommonMode.h create mode 100644 slsDetectorCalibration/moenchCommonMode.h create mode 100644 slsDetectorCalibration/moenchExecutables/Makefile.cluster_finder create mode 100644 slsDetectorCalibration/moenchExecutables/Makefile.zmq create mode 100644 slsDetectorCalibration/moenchExecutables/moench03ClusterFinder.cpp create mode 100644 slsDetectorCalibration/moenchExecutables/moench03Interpolation.cpp create mode 100644 slsDetectorCalibration/moenchExecutables/moench03NoInterpolation.cpp create mode 100644 slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp create mode 100644 slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp create mode 100644 slsDetectorCalibration/multiThreadedAnalogDetector.h create mode 100644 slsDetectorCalibration/multiThreadedCountingDetector.h create mode 100644 slsDetectorCalibration/multiThreadedInterpolatingDetector.h create mode 100644 slsDetectorCalibration/pedestalSubtraction.h create mode 100644 slsDetectorCalibration/singlePhotonDetector.h create mode 100644 slsDetectorCalibration/single_photon_hit.h create mode 100644 slsDetectorCalibration/tiffIO.cpp create mode 100644 slsDetectorCalibration/tiffIO.h create mode 100755 this_build_bin_path.sh diff --git a/ctbGui/Makefile.root6 b/ctbGui/Makefile.root6 index c80b29fed..2251e5888 100644 --- a/ctbGui/Makefile.root6 +++ b/ctbGui/Makefile.root6 @@ -8,11 +8,11 @@ ZMQLIB=../slsReceiverSoftware/include LIBRARYCBF=$(CBFLIBDIR)/lib/*.o INCDIR=-I../slsReceiverSoftware/include/ -I../slsDetectorSoftware/include/ -I../slsSupportLib/include/ -I../slsDetectorCalibration -I../slsDetectorCalibration/dataStructures -I$(CBFLIBDIR)/include -I../slsDetectorCalibration/interpolations -LDFLAG=-L../bin -lSlsDetector -lSlsSupport -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -L$(ZMQLIB) -L$(CBFLIBDIR)/lib/ -std=c++11 +LDFLAG=-L../build/bin -lSlsDetector -lSlsSupport -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -L$(ZMQLIB) -L$(CBFLIBDIR)/lib/ -std=c++11 # MAIN=ctbGui.cpp -DESTDIR?=../bin +DESTDIR?=../build/bin OBJS = $(SRC:.cpp=.o) $(MAIN:.cpp=.o) diff --git a/ctbGui/patternGenerator/deserializer.cpp b/ctbGui/patternGenerator/deserializer.cpp new file mode 100644 index 000000000..c315ca419 --- /dev/null +++ b/ctbGui/patternGenerator/deserializer.cpp @@ -0,0 +1,110 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + + int iarg; + char fname[10000]; + uint64_t word; + int val[64]; + int bit[64]; + FILE *fdin; + + int nb=2; + int off=0; + int ioff=0; + int dr=24; + int idr=0; + int ib=0; + int iw=0; + bit[0]=19; + bit[1]=8; + // for (iarg=0; iarg2) dr=atoi(argv[2]); + if (argc>3) off=atoi(argv[3]); + if (argc>4) { + for (ib=0; ib<64; ib++) { + if (argc>4+ib) { + bit[ib]=atoi(argv[4+ib]); + nb++; + } + } + + } + + idr=0; + for (ib=0; ib +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXLOOPS 3 +#define MAXTIMERS 3 +#define MAXWORDS 1024 + + + +uint64_t pat=0; +uint64_t iopat=0; +uint64_t clkpat=0; + +int iaddr=0; +int waitaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS}; +int startloopaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS}; +int stoploopaddr[3]={MAXWORDS,MAXWORDS,MAXWORDS}; +int start=0, stop=0; +uint64_t waittime[3]={0,0,0}; +int nloop[3]={0,0,0}; + +char infile[10000], outfile[10000]; + +FILE *fd, *fd1; +uint64_t PAT[MAXWORDS]; + + +int i,ii,iii,j,jj,jjj,pixx,pixy,memx,memy,muxout,memclk,colclk,rowclk,muxclk,memcol,memrow,loopcounter; + +void setstart() { + start=iaddr; +} + +void setstop() { + stop=iaddr; +} + +void setinput(int bit) { + uint64_t mask=1; + mask=mask<>bit; +} + +void setstartloop(int iloop) { + if (iloop>=0 && iloop=0 && iloop=0 && iloop=0 && iloop=0 && iloop=MAXWORDS) printf("ERROR: too many word in the pattern (%d instead of %d)!",iaddr, MAXWORDS); +} + +int parseCommand(int clk, int cmdbit, int cmd, int length) { + int ibit; + clearbit(clk); + for (ibit=0; ibit>ibit)) + setbit(cmdbit); + else + clearbit(cmdbit); + pw(); + /******/ + setbit(clk); + pw(); + /******/ + } +}; + + + +main(void) { + int iloop=0; + fd=fopen(OUTFILE,"w"); +#include INFILE + + fprintf(fd,"patioctrl %016llx\n",iopat); + fprintf(fd,"patclkctrl %016llx\n",clkpat); + fprintf(fd,"patlimits %04x %04x\n",start, stop); + + for (iloop=0; iloop + + +class MovingStat + { + + /** @short approximated moving average structure */ + public: + + + /** constructor + \param nn number of samples parameter to be used + */ + MovingStat(int nn=1000) : n(nn), m_n(0) {} + + /** + clears the moving average number of samples parameter, mean and standard deviation + */ + void Clear() + { + m_n = 0; + m_newM=0; + m_newM2=0; + } + + /** + clears the moving average number of samples parameter, mean and standard deviation + */ + void Set(double val, double rms=0, int m=-1) + { + if (m>=0) m_n = m; else m_n = n; + m_newM=val*m_n; + 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; + } else { + if (m_n>0) + m_newM2=(m_n*rms*rms+m_newM*m_newM/m_n); + else { + m_newM2=(m_n*rms*rms+m_newM*m_newM/n); + m_n=0; + } + } + } + + /** sets number of samples parameter + \param i number of samples parameter to be set + */ + + int SetN(int i) {if (i>=1) n=i; return n;}; + + /** + gets number of samples parameter + \returns actual number of samples parameter + */ + int GetN() {return m_n;}; + + /** calculates the moving average i.e. adds if number of elements is lower than number of samples parameter, pushes otherwise + \param x value to calculate the moving average + */ + inline void Calc(double x) { + if (m_n 0) ? m_newM/m_n : 0.0; + } + + /** returns the squared mean, 0 if no elements are inside + \returns returns the squared average + */ + double M2() const + { + return ( (m_n > 1) ? m_newM2/m_n : 0.0 ); + } + + /** returns the variance, 0 if no elements are inside + \returns returns the variance + */ + inline double Variance() const + { + return ( (m_n > 1) ? (M2()-Mean()*Mean()) : 0.0 ); + } + + /** returns the standard deviation, 0 if no elements are inside + \returns returns the standard deviation + */ + inline double StandardDeviation() const + { + return ( (Variance() > 0) ? sqrt( Variance() ) : -1 ); + } + + private: + int n; /**< number of samples parameter */ + int m_n; /**< current number of elements */ + double m_newM; /**< accumulated average */ + double m_newM2; /**< accumulated squared average */ + }; +#endif diff --git a/slsDetectorCalibration/RunningStat.h b/slsDetectorCalibration/RunningStat.h new file mode 100755 index 000000000..1197ffc0f --- /dev/null +++ b/slsDetectorCalibration/RunningStat.h @@ -0,0 +1,55 @@ + class RunningStat + { + public: + RunningStat() : m_n(0) {} + + void Clear() + { + m_n = 0; + } + + void Push(double x) + { + m_n++; + + // See Knuth TAOCP vol 2, 3rd edition, page 232 + if (m_n == 1) + { + m_oldM = m_newM = x; + m_oldS = 0.0; + } + else + { + m_newM = m_oldM + (x - m_oldM)/m_n; + m_newS = m_oldS + (x - m_oldM)*(x - m_newM); + + // set up for next iteration + m_oldM = m_newM; + m_oldS = m_newS; + } + } + + int NumDataValues() const + { + return m_n; + } + + double Mean() const + { + return (m_n > 0) ? m_newM : 0.0; + } + + double Variance() const + { + return ( (m_n > 1) ? m_newS/(m_n - 1) : 0.0 ); + } + + double StandardDeviation() const + { + return sqrt( Variance() ); + } + + private: + int m_n; + double m_oldM, m_newM, m_oldS, m_newS; + }; diff --git a/slsDetectorCalibration/Stat.h b/slsDetectorCalibration/Stat.h new file mode 100644 index 000000000..196f5bbb7 --- /dev/null +++ b/slsDetectorCalibration/Stat.h @@ -0,0 +1,45 @@ +class Stat + { + public: + + Stat() : n(0), m(0.), m2(0.) {} + + void Clear() + { + n = 0; + m=0; + m2=0; + } + + void Push(double x) + { + + m+=x; + m2+=x*x; + n++; + } + + int NumDataValues() const + { + return n; + } + + double Mean() const + { + return (n > 0) ? m/n : 0.0; + } + + double Variance() const + { + return ( (n >0 ) ? (m2/n-m*m/(n*n)) : 0.0 ); + } + + double StandardDeviation() const + { + return sqrt( Variance() ); + } + + private: + int n; + double m, m2; + }; diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h new file mode 100644 index 000000000..49197f0a6 --- /dev/null +++ b/slsDetectorCalibration/analogDetector.h @@ -0,0 +1,1166 @@ +#ifndef ANALOGDETECTOR_H +#define ANALOGDETECTOR_H + +//#include + +#include +#include "slsDetectorData.h" +#include "pedestalSubtraction.h" +#include "commonModeSubtraction.h" +#include "tiffIO.h" +#include "slsInterpolation.h" + + +#ifdef ROOTSPECTRUM +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +using namespace std; + +#ifndef FRAMEMODE_DEF +#define FRAMEMODE_DEF +/** +enum to define the flags of the data set, which are needed to seect the type of processing it should undergo: frame, pedestal, flat +*/ + enum frameMode { eFrame, ePedestal, eFlat }; +/** +enum to define the detector mode +*/ + enum detectorMode { eAnalog, ePhotonCounting, eInterpolating }; +#endif + + +template class analogDetector { + + /** @short class to perform pedestal subtraction etc. for an analog detector */ + + public: + + + + /** + + Constructor (no error checking if datasize and offsets are compatible!) + \param d detector data structure to be used - if null it is assumed that the data are in ordered ip=iy*nx+ix + \param sign is the sign of the data + \param nped number of samples for pedestal averaging + \param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none + \param nnx detector size in x - must be specified if no data structure is defined, otherwise defaults to the size of the data structure. + \param nny detector size in y - must be specified if no data structure is defined, otherwise defaults to the size of the data structure. + \param gm pointer to tha gain map matrix + + + */ + + + analogDetector(slsDetectorData *d, int sign=1, + commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), iframe(-1), dataSign(sign), gmap(gm), id(0) { + + if (det) + det->getDetectorSize(nx,ny); + + stat=new pedestalSubtraction*[ny]; + for (int i=0; idet; + nx=orig->nx; + ny=orig->ny; + dataSign=orig->dataSign; + iframe=orig->iframe; + gmap=orig->gmap; + cmSub=orig->cmSub; + id=orig->id; + xmin=orig->xmin; + xmax=orig->xmax; + ymin=orig->ymin; + ymax=orig->ymax; + thr=orig->thr; + // nSigma=orig->nSigma; + fMode=orig->fMode; + myFile=orig->myFile; + + + stat=new pedestalSubtraction*[ny]; + for (int i=0; iSetNPedestals(); + //cout << nped << " " << orig->getPedestal(ix,iy) << orig->getPedestalRMS(ix,iy) << endl; + for (int iy=0; iygetPedestal(ix,iy),orig->getPedestalRMS(ix,iy),orig->GetNPedestals(ix,iy)); + } + } + image=new int[nx*ny]; +#ifdef ROOTSPECTRUM + hs=(TH2F*)(orig->hs)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); +#ifdef ROOTCLUST + hs3=(TH2F*)(orig->hs3)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs5=(TH2F*)(orig->hs5)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs7=(TH2F*)(orig->hs7)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs9=(TH2F*)(orig->hs9)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); +#endif +#endif + + } + + + /** + clone. Must be virtual! + \returns a clone of the original analog detector + */ + virtual analogDetector *Clone() { + return new analogDetector(this); + } + + /** + Gives an id to the structure. For debugging purposes in case of multithreading. + \param i is to be set + \returns current id + */ + int setId(int i){id=i; return id;}; + + /** + Returns id of the structure. For debugging purposes in case of multithreading. + \returns current id + */ + int getId() {return id; }; + /** + Returns data size of the detector data structure + \returns data size of the detector data structurein bytes + */ + int getDataSize(){return det->getDataSize();}; + /** + Returns data size of the detector image matrix + \param nnx reference to image size in x + \param nny reference to image size in y + \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;}; + /** + Returns data size of the detector image matrix + \param nnx reference to pixel size in x + \param nny reference to pixel size in y + \returns number of pixels of the detector image + */ + virtual int getDetectorSize(int &nnx, int &nny){nnx=nx; nny=ny; return nx*ny;}; + + /** + set gain map + \param gm pointer to gain map matrix to be set - NULL unsets + \returns pointer to current gain map + */ + double *setGainMap(double *gm) {gmap=gm; return gmap;}; + + /** + return gain map + \returns pointer to current gain map + */ + double *getGainMap() {return gmap;}; + /** + reads a 32 bit tiff file of the size of the detector and sets its values as gain map for the detector. If file does not exist returns NULL, but does not change gainmap compared to previous settings. + \param imgname complete name of the file containing the gain map data + \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); + if (gm) { + if (gmap) delete [] gmap; + gmap=new double[nnx*nny]; + for (int iy=0; iyClear(); +#ifdef ROOTSPECTRUM + hs->Reset(); +#ifdef ROOTCLUST + hs3->Reset();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs5->Reset();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs7->Reset();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); + hs9->Reset();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); +#endif +#endif + }; + + /** resets the commonModeSubtraction and increases the frame index */ + virtual void newFrame(){iframe++; if (cmSub) cmSub->newFrame();}; + + + /** sets the commonModeSubtraction algorithm to be used + \param cm commonModeSubtraction algorithm to be used (NULL unsets) + \returns pointer to the actual common mode subtraction algorithm + */ + commonModeSubtraction *setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;}; +/** + gets the commonModeSubtraction algorithm to be used + \returns pointer to the actual common mode subtraction algorithm + */ + commonModeSubtraction *getCommonModeSubtraction() {return cmSub;}; + + + /** + sets the sign of the data + \param sign 1 means positive values for photons, -1 negative, 0 gets + \returns current sign for the data + */ + int setDataSign(int sign=0) {if (sign==1 || sign==-1) dataSign=sign; return dataSign;}; + + + /** + adds value to pedestal (and common mode) for the given pixel + \param val value to be added + \param ix pixel x coordinate + \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){ + if (ix>=0 && ix=0 && iy0) { + val-= getCommonMode(ix, iy); + } + stat[iy][ix].addToPedestal(val); + /* if (cmSub && cm>0) { */ + /* if (det) if (det->isGood(ix, iy)==0) return; */ + /* cmSub->addToCommonMode(val, ix, iy); */ + /* }; */ + }; + } + + double getCommonMode(int ix, int iy) { + if (cmSub) return cmSub->getCommonMode(ix, iy); + else return 0; + } + + + virtual void addToCommonMode(char *data){ + if (cmSub) { + for (int iy=ymin; iy0) + if (det->isGood(ix,iy)) + addToCommonMode(data, ix, iy); + } + } + //cout << "cm " << getCommonMode(0,0) << " " << getCommonMode(1,0) << endl; + } + } + virtual void addToCommonMode(char *data, int ix, int iy=0){ + if (cmSub) { + if (det) if (det->isGood(ix, iy)==0) return; + if (getNumpedestals(ix,iy)>0){ + cmSub->addToCommonMode(subtractPedestal(data,ix,iy,0), ix, iy); + // cout << ix << " " <=0 && ix=0 && iy0) + return stat[iy][ix].getPedestal()+getCommonMode(ix,iy); + else return stat[iy][ix].getPedestal(); + else return -1; + }; + + + /** + gets pedestal rms (i.e. noise) + \param ix pixel x coordinate + \param iy pixel y coordinate + \returns pedestal rms + */ + virtual double getPedestalRMS(int ix, int iy){ + if (ix>=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iySetBinContent(ix+1, iy+1,image[iy*nx+ix]); +#endif + } + } + ret=WriteToTiff(gm, imgname, ny, nx); + delete [] gm; +#ifdef ROOTSPECTRUM + char rootfn[10000]; + sprintf(rootfn,"%s.root",imgname); + TFile *f=new TFile(rootfn,"RECREATE"); + hs->Write("hs"); +#ifdef ROOTCLUST + hs3->Write("hs3"); + hs5->Write("hs5"); + hs7->Write("hs7"); + hs9->Write("hs9"); +#endif + hmap->Write("hmap"); + + + f->Close(); + delete f; + delete hmap; +#endif + return ret; + } +#ifdef ROOTSPECTRUM + TH2F *getSpectrum(){return hs;}; +#endif + /** + write 32bit tiff file containing the pedestals + \param imgname file name to be written + \returns NULL if file writing didn't succed, otherwise a pointer + */ + + virtual void *writePedestals(const char * imgname) { + float *gm=NULL; + void *ret; + gm=new float[nx*ny]; +#ifdef ROOTSPECTRUM + + TH2F *hmap=new TH2F("hmap","hmap",nx, -0.5,nx-0.5, ny, -0.5, ny-0.5); + +#endif + for (int iy=0; iygetCommonMode(); */ + /* else */ + gm[iy*nx+ix]=stat[iy][ix].getPedestal(); +#ifdef ROOTSPECTRUM + hmap->SetBinContent(ix+1, iy+1,gm[iy*nx+ix]); +#endif + } + } + ret=WriteToTiff(gm, imgname, ny, nx); + delete [] gm; + +#ifdef ROOTSPECTRUM + char rootfn[10000]; + sprintf(rootfn,"%s.root",imgname); + TFile *f=new TFile(rootfn,"RECREATE"); + hs->Write("hs"); +#ifdef ROOTCLUST + hs3->Write("hs3"); + hs5->Write("hs5"); + hs7->Write("hs7"); + hs9->Write("hs9"); +#endif + hmap->Write("hmap"); + f->Close(); + delete f; + delete hmap; +#endif + return ret; + } + + /** + read 32bit tiff file containing the pedestals + \param imgname file name to be read + \returns 0 if file reading didn't succed, otherwise 1 + */ + int readPedestals(const char * imgname) { + uint32 nnx, nny; + float *gm=ReadFromTiff( imgname, nny, nnx); + if (nnx>nx) nnx=nx; + if (nny>ny) nny=ny; + + + + if (gm) { + for (int iy=0; iynx) nnx=nx; + if (nny>ny) nny=ny; + + + + if (gm) { + for (int iy=0; iynx) nnx=nx; + if (nny>ny) nny=ny; + if (gm) { + for (int iy=0; iyisGood(ix,iy)) { + addToPedestal(data,ix,iy,1); + //if (ix==10 && iy==10) + // cout <=0 && xmi<=nx) xmin=xmi; + if (xma>=0 && xma<=nx) xmax=xma; + if (xmax=0 && ymi<=ny) ymin=ymi; + if (yma>=0 && yma<=ny) ymax=yma; + if (ymax=0 && ix=0 && iygetValue(data, ix, iy); + else + val=((double*)data)[iy*nx+ix]; + + /* if (ix==10 && iy==10) */ + /* cout << ix << " " << iy << " " << val ; */ + /* if (ix==100 && iy==100) */ + /* cout << ix << " " << iy << " " << val; */ + addToPedestal(val,ix,iy); + /* if (ix==10 && iy==10) */ + /* cout <<" " << getPedestal(ix,iy)<< endl; */ + /* if (ix==100 && iy==100) */ + /* cout << " " << getPedestal(ix,iy)<< endl; */ + } + return ; + + }; + + + /** + Subtracts pedestal from the data array in the region of interest + \param data pointer to the data + \param val pointer where the pedestal subtracted data should be added. If NULL, the internal image is used + \returns pointer to the pedestal subtracted data + */ + // virtual int *subtractPedestal(char *data, int *val=NULL) { + + virtual int *subtractPedestal(char *data, int *val=NULL, int cm=0) { + + newFrame(); + + if (val==NULL) + val=image;//new double[nx*ny]; + + for (int iy=ymin; iyisGood(ix,iy)) + val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm); + } + } + return val; + }; + + + + + /** + Subtracts pedestal from the data for a selected pixel + \param data pointer to the data + \param ix pixel x coordinate + \param iy pixel y coordinate + \returns pedestal subtracted value + */ + + + + virtual double subtractPedestal(char *data, int ix, int iy=0, int cm=0) { + double g=1.; + double val; + if (ix>=0 && ix=0 && iygetChannel(data, ix, iy)>=0x3fff) */ + /* cout << ix << " " << iy << " " << det->getChannel(data, ix, iy) <getValue(data, ix, iy)-getPedestal(ix,iy,cm))/g; + } else + val= (((double*)data)[iy*nx+ix]-getPedestal(ix,iy))/g; + +#ifdef ROOTSPECTRUM + hs->Fill(val,(iy-ymin)*(xmax-xmin)+(ix-xmin)); +#ifdef ROOTCLUST + double v3=0,v5=0,v7=0,v9=0; + for (int iix=-4; iix<5; iix++) + for (int iiy=-4; iiy<5; iiy++) { + if (det) + val= (dataSign*det->getValue(data, ix+iix, iy+iiy)-getPedestal(ix+iix,iy+iiy,cm))/g; + else + val= (((double*)data)[(iy+iiy)*nx+ix+iix]-getPedestal(ix+iix,iy+iiy,cm))/g; + + if (iix>-4 && iiy>-4 && iix<4 && iiy<4) { + if (iix>-3 && iiy>-3 && iix<3 && iiy<3){ + if (iix>-2 && iiy>-2 && iix<2 && iiy<2){ + v3+=val; + } + v5+=val; + } + v7+=val; + } + v9+=val; + } + hs3->Fill(v3,(iy-ymin)*(xmax-xmin)+(ix-xmin)); + hs5->Fill(v5,(iy-ymin)*(xmax-xmin)+(ix-xmin)); + hs7->Fill(v7,(iy-ymin)*(xmax-xmin)+(ix-xmin)); + hs9->Fill(v9,(iy-ymin)*(xmax-xmin)+(ix-xmin)); + +#endif +#endif + return val; + } + }; + + + /** + sets threshold value for conversion into number of photons + \param t threshold to be set + \returns threshold value + */ + double setThreshold(double t){thr=t; return thr;}; + + /** + gets threshold value for conversion into number of photons + \returns threshold value + */ + double getThreshold(){return thr;}; + /** + converts the data into number of photons for the selected pixel + \param data pointer to the data + \param ix pixel x coordinate + \param iy pixel y coordinate + \returns converted number of photons. If no threshold is set, returns gain converted pedestal subtracted data. + */ + + virtual int getNPhotons(char *data, int ix, int iy=0) { + int nph=0; + double v; + if (ix>=0 && ix=0 && iyFill(v,(iy-ymin)*(xmax-xmin)+(ix-xmin)); */ +/* #endif */ + if (thr>0) { + v+=0.5*thr; + nph=v/thr; + if (nph>0) + return nph; + return 0; + } + return v; + } + return 0; + }; + + /** + converts the data into number of photons for all pixels + \param data pointer to the data + \param nph pointer where the photons should added. If NULL,the internal image is used + \returns pointer to array containing the number of photons + */ + int *getNPhotons(char *data, int *nph=NULL) { + + double val; + if (nph==NULL) + nph=image; + newFrame(); + + addToCommonMode(data); + + for (int iy=ymin; iyisGood(ix,iy)) + nph[iy*nx+ix]+=getNPhotons(data, ix, iy); + } + } + return nph; + + } + + /** + clears the image array + + */ + virtual void clearImage(){ + for (int iy=0; iyReset(); +#ifdef ROOTCLUST + + if (hs3) + hs3->Reset(); + if (hs5) + hs5->Reset(); + if (hs7) + hs7->Reset(); + if (hs9) + hs9->Reset(); +#endif + //cout << "done " << endl; +#endif + }; + + /** sets/gets number of samples for moving average pedestal calculation + \param i number of samples to be set (0 or negative gets) + \returns actual number of samples + */ + int SetNPedestals(int i=-1) { + int ix=0, iy=0; + if (i>0) + for (iy=0; iy=0 && ix=0 && iyisGood(ix,iy)) { + if (ix>=0 && ix=0 && iy *det; /**< slsDetectorData to be used */ + int nx; /**< Size of the detector in x direction */ + int ny; /**< Size of the detector in y direction */ + pedestalSubtraction **stat; /**< pedestalSubtraction class */ + 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; + int *image; + int id; + //int xmin, xmax, ymin, ymax; int xmin; /**< minimum x of the region of interest */ + int xmin; /**< minimum x of the region of interest */ + int xmax; /**< maximum x of the region of interest */ + int ymin;/**< minimum y of the region of interest */ + int ymax;/**< maximum y of the region of interest */ + double thr; /**< threshold to be used for conversion into number of photons */ + // int nSigma; /**< number of sigma to be used for conversion into number of photons if threshold is undefined */ + frameMode fMode; /**< current detector frame mode */ + detectorMode dMode; /**< current detector frame mode */ + FILE *myFile; /**< file pointer to write to */ +#ifdef ROOTSPECTRUM + TH2F *hs; +#ifdef ROOTCLUST + TH2F *hs3; + TH2F *hs5; + TH2F *hs7; + TH2F *hs9; +#endif +#endif +}; + +#endif diff --git a/slsDetectorCalibration/commonModeSubtraction.h b/slsDetectorCalibration/commonModeSubtraction.h new file mode 100644 index 000000000..0484e6746 --- /dev/null +++ b/slsDetectorCalibration/commonModeSubtraction.h @@ -0,0 +1,82 @@ +#ifndef COMMONMODESUBTRACTION_H +#define COMMONMODESUBTRACTION_H + +#include "MovingStat.h" + + + + +class 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 + + */ + commonModeSubtraction(int nn=1000, int iroi=1) : cmStat(NULL), cmPed(NULL), nCm(NULL), nROI(iroi) {cmStat=new MovingStat[nROI]; for (int i=0; i0) cmStat[i].Calc(cmPed[i]/nCm[i]); + nCm[i]=0; + cmPed[i]=0; + }}; + + /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest + \param val value to add + \param ix pixel x coordinate + \param iy pixel y coordinate + */ + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + (void) ix; (void) iy; + + //if (isc>=0 && isc0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); + return 0;}; + + + + + + protected: + MovingStat *cmStat; /** + +class 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 + + */ + commonModeSubtraction(int iroi=1, int ns=3) : nROI(iroi), nsigma(ns) { + mean=new double[nROI]; + mean2=new double[nROI]; + nCm=new double[nROI]; + }; + + /** destructor - deletes the moving average(s) and the sum of pedestals calculator(s) */ + virtual ~commonModeSubtraction() {delete [] mean; delete [] mean2; delete [] nCm;}; + + + /** clears the moving average and the sum of pedestals calculation - virtual func*/ + virtual void Clear(){ + for (int i=0; i0) cmStat[i].Calc(cmPed[i]/nCm[i]); + nCm[i]=0; + mean[i]=0; + mean2[i]=0; + }}; + + /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest + \param val value to add + \param ix pixel x coordinate + \param iy pixel y coordinate + */ + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + + int iroi=getROI(ix,iy); + // if (iroi==0) val=100; + // else val=-100; + // if (isc>=0 && isc=0 && iroi=0 && iroi0) + return mean[iroi]/nCm[iroi]; + } + return 0; + }; + + /** gets the common mode i.e. the difference between the current average sum of pedestals mode and the average pedestal + \param ix pixel x coordinate + \param iy pixel y coordinate + \return the difference between the current average sum of pedestals and the average pedestal + */ + virtual double getCommonModeRMS(int ix=0, int iy=0) { + int iroi=getROI(ix,iy); + if (iroi>=0 && iroi0) + return sqrt(mean2[iroi]/nCm[iroi]-(mean[iroi]/nCm[iroi])*(mean[iroi]/nCm[iroi])); + } + return 0; + }; + + /** + 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;}; + + + + protected: + double *mean; /** { + + + public: + mythen3_01_jctbData( int nch=64*3,int dr=24, int off=5): slsDetectorData(64*3,1,dr*8*nch,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch) {}; + + virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;}; + + virtual short unsigned int getChannel(char *data, int ix, int iy=0) { + int ret=-1; + short unsigned int *val=mythen03_frame(data,dynamicRange,numberOfCounters,serialOffset); + if (ix>=0 && ix=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;}; + + + private: + + int dynamicRange; + int serialOffset; + int frameNumber; + int numberOfCounters; + + + + +}; + +#endif diff --git a/slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h b/slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h new file mode 100644 index 000000000..a76e2cbaf --- /dev/null +++ b/slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h @@ -0,0 +1,130 @@ +#ifndef MYTHEN302JCTBDATA_H +#define MYTHEN302JCTBDATA_H + + +#include "Mythen3_01_jctbData.h" +//class mythen3_02_jctbData : public slsDetectorData { +class mythen3_02_jctbData : public mythen3_01_jctbData { + + + public: + mythen3_02_jctbData( int nch=64*3,int dr=24, int off=5): mythen3_01_jctbData( nch,dr, off) + //slsDetectorData(64*3,1,dr*8*nch,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch) + {}; + + /* virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;}; */ + + /* virtual short unsigned int getChannel(char *data, int ix, int iy=0) { */ + /* int ret=-1; */ + /* short unsigned int *val=mythen03_frame(data,dynamicRange,numberOfCounters,serialOffset); */ + /* if (ix>=0 && ix=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;}; */ + + + /* private: */ + + /* int dynamicRange; */ + /* int serialOffset; */ + /* int frameNumber; */ + /* int numberOfCounters; */ + + + + +}; + +#endif diff --git a/slsDetectorCalibration/dataStructures/adcSar2_jctbData.h b/slsDetectorCalibration/dataStructures/adcSar2_jctbData.h new file mode 100644 index 000000000..0b0665aaf --- /dev/null +++ b/slsDetectorCalibration/dataStructures/adcSar2_jctbData.h @@ -0,0 +1,63 @@ +#ifndef ADCSAR2_JCTBDATA_H +#define ADCSAR2_JCTBDATA_H + + +class adcSar2_jctbData : public slsDetectorData { + + + public: + adcSar2_jctbData(int nsamples=1000): slsDetectorData(nsamples,1,nsamples*8,NULL,NULL,NULL){}; + + virtual void getPixel(int ip, int &x, int &y) {x=ip/8; y=1;}; + + virtual short unsigned int getChannel(char *data, int ix, int iy=0) { + int adcvalue=0; + int vv1= *((int16_t*) (data+8*ix)); + int vv2= *((int16_t*) (data+8*ix+2)); + for (int jj=0;jj<8;jj++){ + adcvalue=adcvalue+ (((vv1>>(jj*2)) & 0x1)<<(jj)); + } + for (int jj=0;jj<4;jj++){ + adcvalue=adcvalue+ (((vv2>>(jj*2)) & 0x1)<<(jj+8)); + } + return adcvalue; + }; + + 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]=mythen03_frame(ptr,dynamicRange,nx,serialOffset); */ + /* return val; */ + + /* } */ + + + + virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; }; + + private: + + int frameNumber; + + + + +}; + +#endif diff --git a/slsDetectorCalibration/dataStructures/chiptestBoardData.h b/slsDetectorCalibration/dataStructures/chiptestBoardData.h new file mode 100644 index 000000000..0ef633c44 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/chiptestBoardData.h @@ -0,0 +1,89 @@ +#ifndef CHIPTESTDATA_H +#define CHIPTESTDATA_H + +#include "slsDetectorData.h" + +class chiptestBoardData : public slsDetectorData { + + + public: + + /** + chiptestBoard data structure. Works for data acquired using the chiptestBoard. + Inherits and implements slsDetectorData. + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param nadc number of adcs + \param offset offset at the beginning of the pattern + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param 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. + + */ + chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; // should be? nadc*(npx*npy+offset) + + + + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + \param buff pointer to the dataset + \returns frame number + + */ + + virtual int getFrameNumber(char *buff){(void)buff; return iframe;}; + + + /** + + Loops over a memory slot 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 data pointer to the memory to be analyzed + \param ndata size of frame returned + \param dsize size of the memory slot to be analyzed + \returns always return the pointer to data (no frame loss!) + */ + + 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 first packet 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; + + if (filebin.is_open()) { + if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) { + setDataSize(afifo_length*nAdc*sizeof(uint16_t)); + afifo_cont=new uint16_t[afifo_length*nAdc]; + if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) { + iframe++; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } else { + return NULL; + } + } + return NULL; + }; + + private: + const int nAdc; /** { + + private: + const int nModules; + const int offset; + int iframe; + + +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 + + */ + + + gotthardDoubleModuleDataNew(int off=24*2, int nmod=2): slsDetectorData(1280*nmod, 1, nmod*(1280*2+off)), nModules(nmod), offset(off),iframe(0) { + + + + +#ifdef BCHIP074_BCHIP075 + cout << "This is a bchip074-bchip075 system " << endl; +#endif + + + uint16_t **dMask; + int **dMap; + int ix, iy; + int ypixels=1; + int xpixels=1280*nmod; + int imod, ipix; + dMask=new uint16_t*[1]; + dMap=new int*[1]; + dMap[0] = new int[1280*nmod]; + dMask[0] = new uint16_t[1280*nmod]; + + for(int ix=0; ix=128*4 && ibad<128*5) || (ibad>=9*128 && ibad<10*128) || (ibad>=(1280+128*4) && ibad=(1280+128*6))) + dataROIMask[0][ix]=0; +#endif + } + + 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=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, dataSize) ){ + ff=getFrameNumber(data); + np=getPacketNumber(data); + return data; + } + } + return NULL; + + + + }; + + + + +}; + + + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/gotthardShortModuleData.h b/slsDetectorCalibration/dataStructures/gotthardShortModuleData.h new file mode 100644 index 000000000..4d853c7b0 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/gotthardShortModuleData.h @@ -0,0 +1,127 @@ +#ifndef GOTTHARDSHORTMODULEDATA_H +#define GOTTHARDSHORTMODULEDATA_H +#include "slsReceiverData.h" + + + + + + +class gotthardShortModuleData : public slsReceiverData { +public: + + + + + /** + Implements the slsReceiverData structure for the gotthard short read out by a module i.e. using the slsReceiver + (1x256 pixels, 1 packet 256 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + gotthardShortModuleData(double c=0): slsReceiverData(xpixels, ypixels, npackets, buffersize), xtalk(c){ + + uint16_t **dMask; + int **dMap; + int ix, iy; + int offset = 2; + + 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::getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::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; /** { + + 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 + + */ + + + moench02CtbData(int ns=6400): slsDetectorData(160, 160, ns*2*32, NULL, NULL) , nadc(32), sc_width(40), sc_height(160) { + + + int adc_off[4]={40,0,120,80}; + int adc_nr[4]={8,10,20,22}; + 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=dataSize) { + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + + } + } + + for (int i=0; i=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 && ip0) { + iframe++; + //cout << ib/2 << "-" << endl; + //for (int i=0; i { + + private: + + 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 + + */ + + + moench03CtbData(int ns=5000): slsDetectorData(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) { + + + int row, col; + + int isample; + int iadc; + int ix, iy; + + 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 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}; */ + + + for (iadc=0; iadc=2*400*400) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + } + for (int i=0; i0) { + iframe++; + // cout << ib << "-" << endl; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } + return NULL; + }; + + + + +}; + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/moench03T1CtbData.h b/slsDetectorCalibration/dataStructures/moench03T1CtbData.h new file mode 100644 index 000000000..4a99d3746 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench03T1CtbData.h @@ -0,0 +1,158 @@ +#ifndef MOENCH03T1CTBDATA_H +#define MOENCH03T1CTBDATA_H +#include "slsDetectorData.h" + + + +class moench03T1CtbData : public slsDetectorData { + + private: + + 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 + + */ + + + moench03T1CtbData(int ns=5000): slsDetectorData(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), 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 row, col; + + int isample; + int iadc; + int ix, iy; + + + + + + for (iadc=0; iadc=2*400*400) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + } + int adc4; + for (int i=0; i0) { + iframe++; + // cout << ib << "-" << endl; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } + return NULL; + }; + + + + +}; + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h new file mode 100644 index 000000000..d3a5e55e1 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench03T1ReceiverDataNew.h @@ -0,0 +1,290 @@ +#ifndef MOENCH03T1RECDATANEW_H +#define MOENCH03T1RECDATANEW_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 */ +#ifndef VERSION_V1 + uint64_t packetCaught[8]; /**< is the version number of this structure format */ +#endif + + } sls_detector_header; + + + + +class moench03T1ReceiverDataNew : public slsDetectorData { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + const int nSamples; + + + 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 + + */ + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(400, 400, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { + + 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 row, col; + + int isample; + int iadc; + int ix, iy; + + int npackets=40; + int i; + int adc4(0); + + for (int ip=0; ip=nSamples*2*32) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + } + } + } + + int ipacket; + int ibyte; + int ii=0; + for (ibyte=0; ibyteframeNumber;};//*((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 { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + const int nSamples; + + + 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 + + */ +#ifdef HOR + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(800, 200, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { +#endif +#ifdef VERT + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(200, 800, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { +#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,\ + 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); + 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=nSamples*2*32+sizeof(sls_detector_header)) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + ix=col; + iy=row; +#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][ix]=pix; + } + } + } + } + + /* int ipacket; */ + /* int ibyte; */ + /* int ii=0; */ + /* for (ibyte=0; ibyteframeNumber;};//*((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 { + + 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(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 { + + private: + + // int iframe; + int nadc; + int sc_width; + int sc_height; + const int nSamples; + const int offset; + + 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 + + */ + moench03T1ZmqDataNew(int ns=5000): slsDetectorData(400, 400, ns*32*2+sizeof(int)), nSamples(ns), offset(sizeof(int)) { + + 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 row, col; + + int isample; + int iadc; + int ix, iy; + + int npackets=40; + int i; + int adc4(0); + + for (int ip=0; ip=dataSize) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + } + } + } + + + int ii=0; + + for (i=0; i< dataSize; i++) { + if (i0) { */ +/* 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[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; + np=0; + int pn; + + + if (ff>=0) + fnum=ff; + + if (filebin.is_open()) { + if (filebin.read(data, 32*2*nSamples) ){ + // iframe++; + //ff=iframe; + 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<32*2*nSamples) ndata=dsize; + else ndata=32*2*nSamples; + return data; + + } + + + + + + + // virtual int setFrameNumber(int ff){iframe=ff}; + + + + + + + + + + +int getPacketNumber(int x, int y) {return 0;}; + +}; + + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/moench03TCtbData.h b/slsDetectorCalibration/dataStructures/moench03TCtbData.h new file mode 100644 index 000000000..5edbdd247 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench03TCtbData.h @@ -0,0 +1,180 @@ +#ifndef MOENCH03TCTBDATA_H +#define MOENCH03TCTBDATA_H +#include "slsDetectorData.h" + + + +class moench03TCtbData : public slsDetectorData { + + private: + + 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 + + */ + + + moench03TCtbData(int ns=5000): slsDetectorData(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) { + + + int row, col; + + int isample; + int iadc; + int ix, iy; + + + + 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]={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}; */ + + + for (iadc=0; iadc=2*400*400) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + } + int adc4; + for (int i=0; i0) { + iframe++; + // cout << ib << "-" << endl; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } + return NULL; + }; + + + + +}; + + + +#endif diff --git a/slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h b/slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h new file mode 100644 index 000000000..a639cf1a7 --- /dev/null +++ b/slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h @@ -0,0 +1,291 @@ +#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 + @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 moench04ReceiverData : public slsDetectorData { + + 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 + + */ + moench04ReceiverData(int nas=5000, int nds=0): slsDetectorData(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; ip0) { + 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]>=nSamples*2*32) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + } + } + } + + int ipacket; + int ibyte; + int ii=0; + for (ibyte=0; ibyteframeNumber;};//*((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 +#include +#include + +using namespace std; + + +template +class slsDetectorData { + + protected: + const int nx; /**< Number of pixels in the x direction */ + const int ny; /**< Number of pixels in the y direction */ + int dataSize; /**=0 && ix=0 && iy=0 && ix=0 && iydataSize) dsize=dataSize; + for (int ip=0; ip<(dsize/sizeof(dataType)); ip++) { + getPixel(ip,ix,iy); + if (ix>=0 && ix=0 && iydataSize) dsize=dataSize; + for (int ip=0; ip<(dsize/sizeof(dataType)); ip++) { + getPixel(ip,ix,iy); + if (ix>=0 && ix=0 && iy=0 && ix=0 && iy=0 && dataMap[iy][ix] +#include // exit() +template +class slsReceiverData : public slsDetectorData { + + +public: + + /** + slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. + Inherits and implements slsDetectorData. + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param np number of packets + \param psize packets size + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param 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. + + */ + slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; + + + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + \param buff pointer to the dataset + \returns frame number + + */ + + virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; + + /** + + Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. + \param buff pointer to the dataset + \returns packet number number + + */ + + virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;}; + + + + /** + + Loops over a memory slot 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 data pointer to the memory to be analyzed + \param ndata size of frame returned + \param dsize size of the memory slot to be analyzed + \returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found + + */ + + virtual char *findNextFrame(char *data, int &ndata, int dsize) { + char *retval=NULL, *p=data; + int dd=0; + int fn, fnum=-1, np=0, pnum=-1; + while (dd<=(dsize-packetSize)) { + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + //cout <<"fnum:"<nPackets) { + //cout << "Bad packet number " << pnum << " frame "<< fn << endl; + retval=NULL; + np=0; + } else if (pnum==1) { + retval=p; + if (np>0) + /*cout << "*Incomplete frame number " << fnum << endl;*/ + np=0; + fnum=fn; + } else if (fn!=fnum) { + if (fnum!=-1) { + /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ + retval=NULL; + } + np=0; + } + p+=packetSize; + dd+=packetSize; + np++; + //cout <<"fnum:"<0){ + //cprintf(BG_RED, "Too few packets for this frame! fnum:%d, pnum:%d np:%d\n",fnum,pnum,np); + cout << "Too few packets for this frame! "<< fnum << " " << pnum << " " << np <nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else if (retval!=NULL) { + // cout << "+" << endl;; + for (int ip=0; ipnPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + // cout << "." << endl;; + np++; + } + } + } + delete [] data; + return NULL; + }; + + + /** + + 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) + \param fnum frame number of frame returned + \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete + + */ + + virtual char *readNextFrame(ifstream &filebin, int& fnum) { + char *data=new char[packetSize*nPackets]; + char *retval=0; + int np=0, nd; + fnum = -1; + + if (filebin.is_open()) { + while (filebin.read(data+np*packetSize,packetSize)) { + + if (np==(nPackets-1)) { + + fnum=getFrameNumber(data); //cout << "fnum:"<nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else if (retval!=NULL) { + // cout << "+" << endl;; + for (int ip=0; ipnPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + // cout << "." << endl;; + np++; + //cout<<"np:"<