modifications for on the fly analysis working at cSAXS

This commit is contained in:
2017-11-15 12:21:58 +01:00
parent 10e57319bf
commit 9ad0fd0bc9
15 changed files with 1426 additions and 410 deletions

View File

@ -6,6 +6,7 @@
#include "slsInterpolation.h"
#define M015
#ifdef MYROOT1
#include <TTree.h>
@ -16,7 +17,10 @@
#include <iostream>
using namespace std;
#define XMIN 350/2
#define XMAX 600/2
#define YMIN 0
#define YMAX 400
class interpolatingDetector : public singlePhotonDetector {
@ -46,13 +50,21 @@ 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) {};
singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0), xmin(XMIN), xmax(XMAX), ymin(YMIN), ymax(YMAX) {
cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl;
};
interpolatingDetector(interpolatingDetector *orig) : singlePhotonDetector(orig) {
interp=(orig->interp)->Clone();
id=orig->id;
xmin=orig->xmin;
xmax=orig->xmax;
ymin=orig->ymin;
ymax=orig->ymax;
}
@ -75,19 +87,27 @@ class interpolatingDetector : public singlePhotonDetector {
writeGainMap(tit);
}
#endif
interp->prepareInterpolation(ok);
if (interp)
interp->prepareInterpolation(ok);
}
int getImageSize(int &nnx, int &nny, int &ns) {return interp->getImageSize(nnx, nny, ns);};
void clearImage() {if (interp) interp->clearInterpolatedImage(); else singlePhotonDetector::clearImage();};
int getImageSize(int &nnx, int &nny, int &ns) {if (interp) return interp->getImageSize(nnx, nny, ns); else return analogDetector<uint16_t>::getImageSize(nnx, nny, ns);};
#ifdef MYROOT1
virtual TH2F *getInterpolatedImage()
virtual TH2F *getImage()
#endif
#ifndef MYROOT1
virtual int *getInterpolatedImage()
virtual int *getImage()
#endif
{
// cout << "image " << endl;
if (interp)
return interp->getInterpolatedImage();
else
return analogDetector<uint16_t>::getImage();
//cout << "null " << endl;
}
#ifdef MYROOT1
@ -101,7 +121,8 @@ class interpolatingDetector : public singlePhotonDetector {
if (interp)
return interp->getInterpolatedImage();
else
return NULL;
singlePhotonDetector::getImage();
//return NULL;
};
@ -119,15 +140,19 @@ class interpolatingDetector : public singlePhotonDetector {
return NULL;
};
void *writeInterpolatedImage(const char * imgname) {
cout << id << "=" << imgname<< endl;
interp->writeInterpolatedImage(imgname);
void *writeImage(const char * imgname) {
// cout << id << "=" << imgname<< endl;
if (interp)
interp->writeInterpolatedImage(imgname);
else
analogDetector<uint16_t>::writeImage(imgname);
return NULL;
}
int addFrame(char *data, single_photon_hit *clusters=NULL, int ff=0) {
double g=1;
single_photon_hit *cl;
single_photon_hit clust;
@ -136,16 +161,22 @@ class interpolatingDetector : public singlePhotonDetector {
else
cl=&clust;
int ccs=clusterSize;
int ccy=clusterSizeY;
double int_x,int_y, eta_x, eta_y;
int nph=0;
double val[ny][nx];
double rest[ny][nx];
int cy=(clusterSizeY+1)/2;
int cs=(clusterSize+1)/2;
int ir, ic;
double cc[2][2];
double max=0, tl=0, tr=0, bl=0,br=0, *v, vv;
double max=0, tl=0, tr=0, bl=0,br=0, v, vv;
int xoff,yoff;
int skip=0;
// cout <<"fr"<< endl;
double tthr;
if (iframe<nDark) {
//cout << iframe << "+"<< nDark <<endl;
addToPedestal(data);
@ -153,186 +184,334 @@ class interpolatingDetector : public singlePhotonDetector {
}
newFrame();
for (int ix=1; ix<nx-1; ix++) {
for (int iy=1; iy<ny-1; iy++) {
skip=0;
max=0;
tl=0;
tr=0;
bl=0;
br=0;
tot=0;
quadTot=0;
quad=UNDEFINED_QUADRANT;
cl->rms=getPedestalRMS(ix,iy);
//(clusters+nph)->rms=getPedestalRMS(ix,iy);
// cout << iframe << " " << nph << " " << ix << " " << iy << endl;
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) {
// cout << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
for (int ix=xmin; ix<xmax; ix++) {
for (int iy=ymin; iy<ymax; iy++) {
// for (int ix=clusterSize/2; ix<clusterSize/2-1; ix++) {
// for (int iy=clusterSizeY/2; iy<ny-clusterSizeY/2; iy++) {
// cout << ix << " " << iy << endl;
eventMask[iy][ix]=PEDESTAL;
if ((iy>1 && ir<=0)) {
;
} else if (ix>1 && ic<=0) {
;
} else {
val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir);
eventMask[iy+ir][ix+ic]=PEDESTAL;
}
/* if ((iy+ir)>=iy && (ix+ic)>=ix) { */
/* val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir); */
/* eventMask[iy+ir][ix+ic]=PEDESTAL; */
/* } */
// cout << ir << " " << ic << " " << val[iy+ir][ix+ic] << endl;
v=&(val[iy+ir][ix+ic]);
if (ir==0 && ic==0) {
if (*v<-nSigma*cl->rms) {
eventMask[iy][ix]=NEGATIVE_PEDESTAL;
// cout << "neg ped" << endl;
}
}
// if (skip==0) {
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;
}
// }
// } else skip=1;
}
}
if (bl>=br && bl>=tl && bl>=tr) {
cl->quad=BOTTOM_LEFT;
cl->quadTot=bl;
xoff=0;
yoff=0;
} else if (br>=bl && br>=tl && br>=tr) {
cl->quad=BOTTOM_RIGHT;
cl->quadTot=br;
xoff=1;
yoff=0;
} else if (tl>=br && tl>=bl && tl>=tr) {
cl->quad=TOP_LEFT;
cl->quadTot=tl;
xoff=0;
yoff=1;
} else if (tr>=bl && tr>=tl && tr>=br) {
cl->quad=TOP_RIGHT;
cl->quadTot=tr;
xoff=1;
yoff=1;
}
if (max>nSigma*cl->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cl->rms || (cl->quadTot)>sqrt(cy*cs)*nSigma*cl->rms) {
if (val[iy][ix]>=max) {
// cout << "max" << endl;
eventMask[iy][ix]=PHOTON_MAX;
cl->tot=tot;
cl->x=ix;
cl->y=iy;
cl->ped=getPedestal(ix,iy, 0);
// cout << iframe << " " << ix << " " << iy << " "<< (clusters+nph)->tot << " " << (clusters+nph)->quadTot << " " << (clusters+nph)->ped<< " " << (clusters+nph)->rms << endl;
tthr=nSigma*getPedestalRMS(ix,iy)/g;
if (ix==xmin || iy==ymin)
rest[iy][ix]=subtractPedestal(data,ix,iy);
max=0;
tl=0;
tr=0;
bl=0;
br=0;
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) {
cl->set_data(val[iy+ir][ix+ic],ic,ir);
if ((iy+ir)>=ymin && (iy+ir)<ymax && (ix+ic)>=xmin && (ix+ic)<xmax) {
//cluster->set_data(rest[iy+ir][ix+ic], ic, ir);
// cout << val[iy+ir][ix+ic] << " " ;
if (ir>=0 && ic>=0 )
rest[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir);
v=rest[iy+ir][ix+ic];//cluster->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;
}
//}
}
}
}
if (rest[iy][ix]<=-tthr) {
eventMask[iy][ix]=NEGATIVE_PEDESTAL;
//if (cluster->get_data(0,0)>=max) {
} else if (max>tthr || tot>sqrt(ccy*ccs)*tthr || quadTot>sqrt(cy*cs)*tthr) {
if (rest[iy][ix]>=max) {
if (bl>=br && bl>=tl && bl>=tr) {
cl->quad=BOTTOM_LEFT;
cl->quadTot=bl;
} else if (br>=bl && br>=tl && br>=tr) {
cl->quad=BOTTOM_RIGHT;
cl->quadTot=br;
} else if (tl>=br && tl>=bl && tl>=tr) {
cl->quad=TOP_LEFT;
cl->quadTot=tl;
} else if (tr>=bl && tr>=tl && tr>=br) {
cl->quad=TOP_RIGHT;
cl->quadTot=tr;
}
/* cout << ix << " " << iy << " " << rest[iy][ix] <<" " << tot << " " << quadTot << endl; */
/* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */
/* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) */
/* cout << rest[iy+ir][ix+ic] << " " ; */
/* cout << endl; */
/* } */
eventMask[iy][ix]=PHOTON_MAX;
cl->tot=tot;
cl->x=ix;
cl->y=iy;
cl->ped=getPedestal(ix,iy, 0);
cl->rms=getPedestalRMS(ix,iy);
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
if ((iy+ir)>=ymin && (iy+ir)<ymax && (ix+ic)>=xmin && (ix+ic)<xmax) {
cl->set_data(rest[iy+ir][ix+ic],ic,ir);
}
}
// cout << endl << " " ;
}
// cout << endl << " " ;
cc[0][0]=cl->get_data(-1+xoff,-1+yoff);
cc[1][0]=cl->get_data(-1+xoff,0+yoff);
cc[0][1]=cl->get_data(0+xoff,-1+yoff);
cc[1][1]=cl->get_data(0+xoff,0+yoff);
// cout << cc[0][0] << " " << cc[0][1] << endl;
// cout << cc[1][0] << " " << cc[1][1] << endl;
if (interp) {
if (ff) {
#ifdef M015
if (iy>100)
#endif
interp->addToFlatField(cl->quadTot,cl->quad,cl->get_cluster(),eta_x, eta_y);
// if ((eta_x<0.1 || eta_x>0.9)&&(eta_y<0.1 || eta_y>0.9))
// cout << ix << " " << iy << " " << eta_x <<" " << eta_y << endl;
} else {
interp->getInterpolatedPosition(ix, iy, cl->quadTot,cl->quad,cl->get_cluster(),int_x, int_y);
interp->addToImage(int_x, int_y);
}
} else
image[ix+nx*iy]++;
nph++;
if (clusters) cl=(clusters+nph);
// cout << endl << " " ;
// rest[iy][ix]-=tthr;
} else
eventMask[iy][ix]=PHOTON;
//else if (thr<=0 ) {
//addToPedestal(data,ix,iy);
// }
}
if (eventMask[iy][ix]==PEDESTAL) {
addToPedestal(data,ix,iy);
}
}
}
return nph;
}
/* for (int ix=0; ix<nx; ix++) { */
/* for (int iy=0; iy<ny; iy++) { */
/* skip=0; */
/* max=0; */
/* tl=0; */
/* tr=0; */
/* bl=0; */
/* br=0; */
/* tot=0; */
/* quadTot=0; */
/* quad=UNDEFINED_QUADRANT; */
/* cl->rms=getPedestalRMS(ix,iy); */
/* //(clusters+nph)->rms=getPedestalRMS(ix,iy); */
/* // cout << iframe << " " << nph << " " << ix << " " << iy << endl; */
/* if (ix==0 || iy==0) */
/* val[iy][ix]=subtractPedestal(data,ix,iy); */
/* if (val[iy][ix]<-nSigma*cl->rms) { */
/* eventMask[iy][ix]=NEGATIVE_PEDESTAL; */
/* // cout << "neg ped" << endl; */
/* } else { */
/* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */
/* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { */
if (interp) {
//interp->calcEta((clusters+nph)->quadTot,cc,eta_x, eta_y);
interp->calcEtaL(cl->quadTot,cl->quad,cc,eta_x, eta_y);
// cout << eta_x << " " << eta_y << endl;
// cout << "eta" << endl;
if (ff) {
interp->addToFlatField(eta_x,eta_y);
// cout << "**************************************************************************"<< endl;
} else {
// cout << "interp" << endl;
interp->getInterpolatedPosition(ix,iy,eta_x,eta_y,cl->quad,int_x,int_y);
// cout << "add" << endl;
interp->addToImage(int_x, int_y);
}
// cout << "done" << endl;
}
if (clusters) cl=(clusters+nph);
/* if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) { */
/* if (ir>=0 && ic>=0) { */
/* val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir); */
/* eventMask[iy+ir][ix+ic]=PEDESTAL; */
/* } */
/* // cout << ir << " " << ic << " " << val[iy+ir][ix+ic] << endl; */
/* v=&(val[iy+ir][ix+ic]); */
/* // if (skip==0) { */
/* 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; */
/* } */
/* } */
/* } */
/* } */
nph++;
} else {
// cout << "ph" << endl;
eventMask[iy][ix]=PHOTON;
}
} else if (eventMask[iy][ix]==PEDESTAL) {
// cout << "ped" << endl;
addToPedestal(data,ix,iy);
}
/* if (bl>=br && bl>=tl && bl>=tr) { */
/* cl->quad=BOTTOM_LEFT; */
/* cl->quadTot=bl; */
/* } else if (br>=bl && br>=tl && br>=tr) { */
/* cl->quad=BOTTOM_RIGHT; */
/* cl->quadTot=br; */
/* } else if (tl>=br && tl>=bl && tl>=tr) { */
/* cl->quad=TOP_LEFT; */
/* cl->quadTot=tl; */
/* } else if (tr>=bl && tr>=tl && tr>=br) { */
/* cl->quad=TOP_RIGHT; */
/* cl->quadTot=tr; */
/* } */
}
}
/* if (max>nSigma*cl->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cl->rms || (cl->quadTot)>sqrt(cy*cs)*nSigma*cl->rms) { */
/* if (val[iy][ix]>=max) { */
/* eventMask[iy][ix]=PHOTON_MAX; */
/* cl->tot=tot; */
/* cl->x=ix; */
/* cl->y=iy; */
/* cl->ped=getPedestal(ix,iy, 0); */
/* if (interp) { */
/* if (ff) { */
/* interp->addToFlatField(cl->quadTot,cl->quad,cl->get_cluster(),eta_x, eta_y); */
/* // if ((eta_x<0.1 || eta_x>0.9)&&(eta_y<0.1 || eta_y>0.9)) */
/* // cout << ix << " " << iy << " " << eta_x <<" " << eta_y << endl; */
/* } else { */
/* interp->getInterpolatedPosition(ix, iy, cl->quadTot,cl->quad,cl->get_cluster(),int_x, int_y); */
/* interp->addToImage(int_x, int_y); */
/* } */
/* } else */
/* image[ix+nx*iy]++; */
/* if (clusters) cl=(clusters+nph); */
/* nph++; */
/* } else { */
/* eventMask[iy][ix]=PHOTON; */
/* } */
/* } else if (eventMask[iy][ix]==PEDESTAL) { */
/* addToPedestal(data,ix,iy); */
/* } */
/* } */
/* } */
/* } */
/* return nph; */
return nph;
};
/* }; */
virtual void processData(char *data, frameMode i=eFrame, int *val=NULL) {
if (interp){
switch(i) {
case ePedestal:
addToPedestal(data);
break;
case eFlat:
addFrame(data,NULL,1);
addFrame(data,NULL,1);
break;
default:
addFrame(data);
addFrame(data,NULL,0);
}
} else
singlePhotonDetector::processData(data,i,val);
};
virtual char *getInterpolation(){return (char*)interp;};
protected:
slsInterpolation *interp;
int id;
//should put it to analogDetector
int xmin, xmax, ymin, ymax;
};