some changes in the moench executables

This commit is contained in:
2018-08-08 10:23:35 +02:00
parent 9ae1289616
commit 44fdc46c11
24 changed files with 829 additions and 263 deletions

View File

@ -709,6 +709,7 @@ template <class dataType> class analogDetector {
/**
Sets region of interest in which data should be processed
\param xmi minimum x. if -1 or out of range remains unchanged

View File

@ -31,23 +31,28 @@ class moench02CtbData : public slsDetectorData<uint16_t> {
*/
moench02CtbData(int ns=6400): slsDetectorData<uint16_t>(160, 160, ns*2*32, NULL, NULL) , nadc(4), sc_width(40), sc_height(160) {
moench02CtbData(int ns=6400): slsDetectorData<uint16_t>(160, 160, ns*2*32, NULL, NULL) , nadc(32), sc_width(40), sc_height(160) {
int adc_nr[4]={120,0,80,40};
int adc_off[4]={0,40,80,120};
int adc_nr[4]={8,10,20,23};
int row, col;
int isample;
int iadc;
int iadc, iiadc;
int ix, iy;
maplength=this->getDataSize()/2;
//cout << maplength << endl;
for (iadc=0; iadc<nadc; iadc++) {
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_nr[iadc]+(i%sc_width);
col=adc_off[iiadc]+(i%sc_width);
row=i/sc_width;
dataMap[row][col]=(32*i+iadc+2)*2;
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;
}
@ -56,12 +61,17 @@ class moench02CtbData : public slsDetectorData<uint16_t> {
}
for (int i=0; i<maplength; i++) {
//cout << i << endl;
isample=i/32;
iadc=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>1 && iadc<6){
xmap[i]=adc_nr[iadc-2]+ix;
if(iadc>=0){
xmap[i]=adc_off[iadc]+ix;
ymap[i]=iy;
}else{
xmap[i]=-1;
@ -71,7 +81,7 @@ class moench02CtbData : public slsDetectorData<uint16_t> {
iframe=0;
cout << "data struct created" << endl;
};
void getPixel(int ip, int &x, int &y) {
if(ip>=0 && ip<maplength){
x=xmap[ip];
@ -137,7 +147,9 @@ class moench02CtbData : public slsDetectorData<uint16_t> {
}
if (ib>0) {
iframe++;
//cout << ib << "-" << endl;
//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;

View File

@ -17,10 +17,7 @@
#include <iostream>
using namespace std;
#define XMIN 350/2
#define XMAX 600/2
#define YMIN 0
#define YMAX 400
class interpolatingDetector : public singlePhotonDetector {
@ -50,7 +47,7 @@ class interpolatingDetector : public singlePhotonDetector {
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), xmin(XMIN), xmax(XMAX), ymin(YMIN), ymax(YMAX) {
singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0) {
cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl;
};
@ -60,10 +57,10 @@ class interpolatingDetector : public singlePhotonDetector {
interpolatingDetector(interpolatingDetector *orig) : singlePhotonDetector(orig) {
interp=(orig->interp)->Clone();
id=orig->id;
xmin=orig->xmin;
xmax=orig->xmax;
ymin=orig->ymin;
ymax=orig->ymax;
/* xmin=orig->xmin; */
/* xmax=orig->xmax; */
/* ymin=orig->ymin; */
/* ymax=orig->ymax; */
}
@ -157,10 +154,10 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
int cy=(clusterSizeY+1)/2;
int cs=(clusterSize+1)/2;
int ir, ic;
double rms;
double int_x,int_y, eta_x, eta_y;
double max=0, tl=0, tr=0, bl=0,br=0, *v, vv;
// cout << "********** Add frame "<< iframe << endl;
if (ph==NULL)
ph=image;
@ -169,6 +166,7 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
return 0;
}
newFrame();
// cout << "********** Data "<< endl;
for (int ix=xmin; ix<xmax; ix++) {
for (int iy=ymin; iy<ymax; iy++) {
@ -185,8 +183,8 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
eventMask[iy][ix]=PEDESTAL;
(clusters+nph)->rms=getPedestalRMS(ix,iy);
rms=getPedestalRMS(ix,iy);
(clusters+nph)->rms=rms;
@ -213,7 +211,7 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
if (ir==0 && ic==0) {
if (*v<-nSigma*cluster->rms)
if (*v<-nSigma*rms)
eventMask[iy][ix]=NEGATIVE_PEDESTAL;
}
@ -234,7 +232,7 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
(clusters+nph)->quadTot=tr;
}
if (max>nSigma*cluster->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*cluster->rms) {
if (max>nSigma*rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*rms) {
if (val[iy][ix]>=max) {
eventMask[iy][ix]=PHOTON_MAX;
(clusters+nph)->tot=tot;
@ -646,8 +644,6 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
slsInterpolation *interp;
int id;
//should put it to analogDetector
int xmin, xmax, ymin, ymax;
};

View File

@ -97,7 +97,9 @@ class etaInterpolationBase : public slsInterpolation {
#ifndef MYROOT1
int *setEta(int *h, int nb=-1, double emin=1, double emax=0)
{
if (h) {heta=h;
if (h) {
if (heta) delete [] heta;
heta=h;
nbeta=nb;
if (nb<=0) nbeta=nSubPixels*10;
etamin=emin;

View File

@ -15,11 +15,11 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
etaInterpolationPosXY(etaInterpolationPosXY *orig): etaInterpolationBase(orig) {};
virtual etaInterpolationPosXY* Clone()=0;/** {
virtual etaInterpolationPosXY* Clone()=0; /* { */
return new etaInterpolationPosXY(this);
/* return new etaInterpolationPosXY(this); */
};*/
/* }; */
virtual void prepareInterpolation(int &ok)
{

View File

@ -40,7 +40,21 @@ class linearInterpolation : public slsInterpolation{
return;
};
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax,etay;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixels>2)
calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y) {
double eta_x, eta_y;
@ -78,6 +92,7 @@ class linearInterpolation : public slsInterpolation{
cc[1][1]=cluster[yoff+1][xoff+1];
calcEta(totquad,cc,eta_x,eta_y);
}
// cout << x << " " << y << " " << eta_x << " " << eta_y << " " << int_x << " " << int_y << endl;
return getInterpolatedPosition(x,y,eta_x, eta_y,quad,int_x,int_y);
@ -86,6 +101,49 @@ class linearInterpolation : public slsInterpolation{
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double cc[2][2];
int *cluster[3];
int xoff, yoff;
cluster[0]=cl;
cluster[1]=cl+3;
cluster[2]=cl+6;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
double etax, etay;
if (nSubPixels>2) {
cc[0][0]=cluster[yoff][xoff];
cc[1][0]=cluster[yoff+1][xoff];
cc[0][1]=cluster[yoff][xoff+1];
cc[1][1]=cluster[yoff+1][xoff+1];
calcEta(totquad,cc,etax,etay);
}
// cout << x << " " << y << " " << etax << " " << etay << " " << int_x << " " << int_y << endl;
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
@ -125,11 +183,11 @@ class linearInterpolation : public slsInterpolation{
ypos_eta=(etay)+dY;
} else {
xpos_eta=0.5*dX+0.25;
xpos_eta=0.5*dY+0.25;
ypos_eta=0.5*dY+0.25;
}
int_x=((double)x) + xpos_eta;
int_y=((double)y) + ypos_eta;
// cout <<"**"<< x << " " << y << " " << xpos_eta << " " << ypos_eta << " " << corner << endl;
return;
};
@ -162,8 +220,10 @@ class linearInterpolation : public slsInterpolation{
////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){};
virtual int addToFlatField(int *cluster, double &etax, double &etay){};
virtual int addToFlatField(double etax, double etay){};
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {};
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {};
protected:
;

View File

@ -24,7 +24,10 @@
#endif
#include <memory.h>
#include <stdio.h>
#include <iostream>
using namespace std;
//#ifdef MYROOT1
//: public TObject
//#endif
@ -84,7 +87,13 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny);
#endif
#ifndef MYROOT1
virtual int *getInterpolatedImage(){return hint;};
virtual int *getInterpolatedImage(){
// cout << "return interpolated image " << endl;
/* for (int i=0; i<nSubPixels* nSubPixels* nPixelsX*nPixelsY; i++) { */
/* cout << i << " " << hint[i] << endl; */
/* } */
return hint;
};
#endif
@ -146,8 +155,13 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny);
virtual int *addToImage(double int_x, double int_y){
int iy=((double)nSubPixels)*int_y;
int ix=((double)nSubPixels)*int_x;
// cout << int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << endl;
if (ix>=0 && ix<(nPixelsX*nSubPixels) && iy<(nSubPixels*nPixelsY) && iy>=0 )(*(hint+ix+iy*nPixelsX*nSubPixels))+=1;
if (ix>=0 && ix<(nPixelsX*nSubPixels) && iy<(nSubPixels*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;
// cout << " " << hint[ix+iy*nPixelsX*nSubPixels] << endl;
}// else
// cout << "bad! "<< int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << endl;
return hint;
};
#endif

View File

@ -0,0 +1,22 @@
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

@ -2,12 +2,14 @@
#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$(CBFLIBDIR)/include/ -I$(ROOTSYS)/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$(ROOTSYS)/include
#-I$(CBFLIBDIR)/include/
#LIBHDF5=
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -L$(CBFLIBDIR)/lib/ -lhdf5 -ltiff
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -ltiff
#-L$(CBFLIBDIR)/lib/ -lhdf5
MAIN=tiff_to_th2f.cpp
@ -18,8 +20,8 @@ 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) $(LIBHDF5) $(LIBRARYCBF) ../tiffIO.cpp
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

@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
}
int p=10000;
int fifosize=1000;
int nthreads=8;
int nthreads=1;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;

View File

@ -30,9 +30,10 @@ int main(int argc, char *argv[]) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 0;
}
int ii=0;
int p=10000;
int fifosize=1000;
int nthreads=1;
int nthreads=5;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
@ -165,6 +166,14 @@ int main(int argc, char *argv[]) {
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();

View File

@ -0,0 +1,163 @@
//#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

@ -22,15 +22,19 @@ 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;
int nsubpixels=2;
int int_ready=0;
int ok;
// help
if (argc < 3 ) {
cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n");
@ -58,6 +62,10 @@ int main(int argc, char *argv[]) {
"\nsd port num : " << portnum2;
}
cout << endl;
int nsubpixels=2;
if (argc > 5) {
nsubpixels=atoi(argv[5]);
}
//slsDetectorData *det=new moench03T1ZmqDataNew();
int npx, npy;
moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew();
@ -70,7 +78,8 @@ int main(int argc, char *argv[]) {
char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
mt->setFrameMode(eFrame);
int frameMode=eFrame;
mt->setFrameMode(frameMode);
mt->StartThreads();
mt->popFree(buff);
@ -113,6 +122,9 @@ int main(int argc, char *argv[]) {
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))]();
@ -139,35 +151,42 @@ int main(int argc, char *argv[]) {
// cprintf(RED, "Got Dummy\n");
while (mt->isBusy()) {;}//wait until all data are processed from the queues
if (frameMode==eFrame) {
detimage=mt->getImage(nix,niy,nis);
if (detimage) {
for (ix=0; ix<nnx; ix++) {
for (iy=0; iy<nny; iy++) {
for (ix=0; ix<nnx/nis; ix++) {
for (iy=0; iy<nny/nis; iy++) {
dout[iy*nnx+ix]=0;
for (isx=0; isx<nis; isx++) {
for (isy=0; isy<nis; isy++) {
dout[iy*nnx+ix]+=detimage[(iy+isy)*nix+(ix+isx)];
// if (detimage[(iy+isy)*nix+(ix+isx)]) cout << ix << " " << iy << " " << isx << " " << isy << " " << detimage[(iy+isy)*nix+(ix+isx)] << " " << dout[iy*nnx+ix] << endl;
}
}
}
}
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",filename.c_str(),fileindex);
mt->writeImage(ofname);
}
}
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);
@ -184,7 +203,8 @@ int main(int argc, char *argv[]) {
}
if (of==NULL) {
if (of==NULL) {
while (mt->isBusy()) {;}
sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex);
of=fopen(ofname,"w");
if (of) {
@ -193,6 +213,32 @@ int main(int argc, char *argv[]) {
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

View File

@ -50,7 +50,7 @@ public:
virtual int setFrameMode(int fm) {fMode=fm; if (fMode>=0) det->setFrameMode((frameMode)fMode);};
virtual void newDataSet(){det->newDataSet();};
//fMode=fm; return fMode;}
/* void prepareInterpolation(int &ok) { */
@ -235,6 +235,7 @@ public:
int setFrameMode(int fm) { int ret; for (int i=0; i<nThreads; i++) ret=dets[i]->setFrameMode(fm); return ret;};
void newDataSet(){for (int i=0; i<nThreads; i++) dets[i]->newDataSet();};
int *getImage(int &nnx, int &nny, int &ns) {
int *img;
// int nnx, nny, ns;
@ -242,13 +243,14 @@ public:
//for (i=0; i<nn; i++) image[i]=0;
for (int ii=0; ii<nThreads; ii++) {
// cout << ii << " " << dets[ii]->getImageSize(nnx, nny, ns) << " " << nnx << " " << nny << " " << ns << endl;
//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;
}
}
@ -280,8 +282,8 @@ public:
float *gm=new float[nn];
if (gm) {
for (int ix=0; ix<nn; ix++) {
// if (image[ix]>0) cout << ix << " " << image[ix]<< endl;
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);
@ -403,7 +405,7 @@ public:
} else cout << "Could not allocate float image " << endl;
}
} else
cout << "Not interpolating detector! " << endl;
cout << "Detector without flat field! " << endl;
return NULL;

View File

@ -187,10 +187,10 @@ public analogDetector<uint16_t> {
double g=1.;
double tthr=thr;
double tthr=thr, tthr1, tthr2;
int nn=0;
double max=0, tl=0, tr=0, bl=0,br=0, v;
double rms=0;
int cm=0;
if (cmSub) cm=1;
@ -240,56 +240,62 @@ public analogDetector<uint16_t> {
tot=0;
quadTot=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->set_data(rest[iy+ir][ix+ic], ic, ir);
if (rest[iy][ix]>0.25*tthr) {
eventMask[iy][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);
v=rest[iy+ir][ix+ic];//clusters->get_data(ic,ir);
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>tthr) {
eventMask[iy][ix]=NEIGHBOUR;
v=rest[iy+ir][ix+ic];//clusters->get_data(ic,ir);
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 (rest[iy][ix]>=max) {
if (bl>=br && bl>=tl && bl>=tr) {
quad=BOTTOM_LEFT;
quadTot=bl;
} else if (br>=bl && br>=tl && br>=tr) {
quad=BOTTOM_RIGHT;
quadTot=br;
if (rest[iy][ix]>=max) {
if (bl>=br && bl>=tl && bl>=tr) {
quad=BOTTOM_LEFT;
quadTot=bl;
} else if (br>=bl && br>=tl && br>=tr) {
quad=BOTTOM_RIGHT;
quadTot=br;
} else if (tl>=br && tl>=bl && tl>=tr) {
quad=TOP_LEFT;
quadTot=tl;
quad=TOP_LEFT;
quadTot=tl;
} else if (tr>=bl && tr>=tl && tr>=br) {
quad=TOP_RIGHT;
quadTot=tr;
quad=TOP_RIGHT;
quadTot=tr;
}
rms=getPedestalRMS(ix,iy);
tthr1=tthr-sqrt(ccy*ccs)*rms;
tthr2=tthr-sqrt(cy*cs)*rms;
if (tthr>sqrt(ccy*ccs)*rms) tthr1=tthr-sqrt(ccy*ccs)*rms; else tthr1=sqrt(ccy*ccs)*rms;
if (tthr>sqrt(cy*cs)*rms) tthr2=tthr-sqrt(cy*cs)*rms; else tthr2=sqrt(cy*cs)*rms;
if (tot>tthr1 || quadTot>tthr2) {
eventMask[iy][ix]=PHOTON;
nph[ix+nx*iy]++;
nphFrame++;
nphTot++;
}
}
if (max>tthr || tot>sqrt(ccy*ccs)*tthr || quadTot>sqrt(cy*cs)*tthr) {
eventMask[iy][ix]=PHOTON;
nph[ix+nx*iy]++;
nphFrame++;
nphTot++;
}
}
}
}