Interpolation in both directions for rect pixels works, saving of the rectangular image is done by rebinning

This commit is contained in:
2020-01-15 17:27:46 +01:00
parent 27f2321d64
commit e4ab4547db
4 changed files with 196 additions and 86 deletions

View File

@ -196,11 +196,12 @@ class slsInterpolation
/* cluster[2]=cl+6; */ /* cluster[2]=cl+6; */
sum=0; sum=0;
int xoff=0, yoff=0;
#ifndef WRITE_QUAD
double sumBL=0; double sumBL=0;
double sumTL=0; double sumTL=0;
double sumBR=0; double sumBR=0;
double sumTR=0; double sumTR=0;
int xoff=0, yoff=0;
for (int ix=0; ix<3; ix++) { for (int ix=0; ix<3; ix++) {
for (int iy=0; iy<3; iy++) { for (int iy=0; iy<3; iy++) {
sum+=cl[ix+3*iy]; sum+=cl[ix+3*iy];
@ -220,34 +221,95 @@ class slsInterpolation
if(sumTL >= totquad){ if(sumTL >= totquad){
/* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; */ /* #ifdef WRITE_QUAD */
/* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; */ /* /\* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; *\/ */
/* /\* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; *\/ */
/* if (sumTL ==sum) { */
/* #endif */
corner = TOP_LEFT; corner = TOP_LEFT;
totquad=sumTL; totquad=sumTL;
xoff=0; xoff=0;
yoff=1; yoff=1;
/* #ifdef WRITE_QUAD */
/* } */
/* #endif */
} }
if(sumBR >= totquad){ if(sumBR >= totquad){
/* sDum[0][0] = cluster[0][1]; sDum[1][0] = cluster[1][1]; */ /* sDum[0][0] = cluster[0][1]; sDum[1][0] = cluster[1][1]; */
/* sDum[0][1] = cluster[0][2]; sDum[1][1] = cluster[1][2]; */ /* sDum[0][1] = cluster[0][2]; sDum[1][1] = cluster[1][2]; */
/* #ifdef WRITE_QUAD */
/* /\* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; *\/ */
/* /\* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; *\/ */
/* if (sumBR ==sum) { */
/* #endif */
corner = BOTTOM_RIGHT;
xoff=1; xoff=1;
yoff=0; yoff=0;
corner = BOTTOM_RIGHT;
totquad=sumBR; totquad=sumBR;
/* #ifdef WRITE_QUAD */
/* } */
/* #endif */
} }
if(sumTR >= totquad){ if(sumTR >= totquad){
/* #ifdef WRITE_QUAD */
/* /\* sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0]; *\/ */
/* /\* sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1]; *\/ */
/* if (sumTR ==sum) { */
/* #endif */
xoff=1; xoff=1;
yoff=1; yoff=1;
/* sDum[0][0] = cluster[1][1]; sDum[1][0] = cluster[2][1]; */ /* sDum[0][0] = cluster[1][1]; sDum[1][0] = cluster[2][1]; */
/* sDum[0][1] = cluster[1][2]; sDum[1][1] = cluster[2][2]; */ /* sDum[0][1] = cluster[1][2]; sDum[1][1] = cluster[2][2]; */
corner = TOP_RIGHT; corner = TOP_RIGHT;
totquad=sumTR; totquad=sumTR;
/* #ifdef WRITE_QUAD */
/* } */
/* #endif */
} }
#endif
#ifdef WRITE_QUAD
double sumB=0;
double sumT=0;
double sumR=0;
double sumL=0;
for (int ix=0; ix<3; ix++) {
for (int iy=0; iy<3; iy++) {
sum+=cl[ix+3*iy];
if (ix<1 ) sumL+=cl[ix+iy*3];
if (ix>1) sumR+=cl[ix+iy*3];
if (iy<1) sumB=cl[ix+iy*3];
if (iy>1) sumT+=cl[ix+iy*3];
}
}
totquad=sum;
if ( sumT==0 && sumR==0) {
corner = BOTTOM_LEFT;
xoff=0;
yoff=0;
} else if ( sumB==0 && sumR==0 ) {
corner = TOP_LEFT;
xoff=0;
yoff=1;
} else if ( sumT==0 && sumL==0) {
corner = BOTTOM_RIGHT;
xoff=1;
yoff=0;
} else if ( sumB==0 && sumL==0) {
xoff=1;
yoff=1;
corner = TOP_RIGHT;
} else
printf("** bad 2x2 cluster!\n");
#endif
for (int ix=0; ix<2; ix++) { for (int ix=0; ix<2; ix++) {
for (int iy=0; iy<2; iy++) { for (int iy=0; iy<2; iy++) {

View File

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

View File

@ -5,7 +5,7 @@
//#include "moench03T1ZmqData.h" //#include "moench03T1ZmqData.h"
//#define DOUBLE_SPH //#define DOUBLE_SPH
//#define MANYFILES //#define MANYFILES
#define WRITE_QUAD
#ifdef DOUBLE_SPH #ifdef DOUBLE_SPH
#include "single_photon_hit_double.h" #include "single_photon_hit_double.h"
#endif #endif
@ -101,10 +101,14 @@ int main(int argc, char *argv[]) {
#endif #endif
int nSubPixels=nsubpix; int nSubPixels=nsubpix;
int nSubPixelsY=nsubpix; int nSubPixelsY=nsubpix;
#ifdef RECT #ifdef RECT1
nSubPixels=1; //might make more sense using 2? // nSubPixels=2; //might make more sense using 2?
etabins=2; // etabins=100;
float *rectimg=new float[NC*NR*nSubPixelsY];;
#endif #endif
// #endif
#ifndef NOINTERPOLATION #ifndef NOINTERPOLATION
eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax); eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax);
//eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax); //eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
@ -172,6 +176,8 @@ int main(int argc, char *argv[]) {
// #ifdef SOLEIL // #ifdef SOLEIL
// if (cl.x>210 && cl.x<240 && cl.y>210 && cl.y<240) { // if (cl.x>210 && cl.x<240 && cl.y>210 && cl.y<240) {
// #endif // #endif
if (cl.x<0 || cl.y<0 || cl.x>NC || cl.y>NR) {
} else {
#ifndef FF #ifndef FF
// interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y); // interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y);
interp->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,int_x, int_y); interp->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,int_x, int_y);
@ -181,14 +187,14 @@ int main(int argc, char *argv[]) {
// cout << int_x << " " << int_y << endl; // cout << int_x << " " << int_y << endl;
// cout <<"**************"<< endl; // cout <<"**************"<< endl;
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1) // if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToImage(int_x, int_y); if (int_x<-1 || int_y<-1 || int_x>NC+1 || int_y>NR+1) {
if (int_x<0 || int_y<0 || int_x>NC || int_y>NR) { cout <<"**************"<< endl;
cout <<"**************"<< endl; cout << cl.x << " " << cl.y << " " << sum << endl;
cout << cl.x << " " << cl.y << " " << sum << endl; cl.print();
cl.print(); cout << int_x << " " << int_y << endl;
cout << int_x << " " << int_y << endl; cout <<"**************"<< endl;
cout <<"**************"<< endl; } else
} interp->addToImage(int_x, int_y);
#endif #endif
#ifdef FF #ifdef FF
// interp->addToFlatField(cl.get_cluster(), etax, etay); // interp->addToFlatField(cl.get_cluster(), etax, etay);
@ -200,6 +206,7 @@ int main(int argc, char *argv[]) {
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl; // if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl;
#endif #endif
}
// #ifdef SOLEIL // #ifdef SOLEIL
// } // }
// #endif // #endif
@ -225,18 +232,31 @@ int main(int argc, char *argv[]) {
#endif #endif
#ifndef FF #ifndef FF
#ifndef RECT1
interp->writeInterpolatedImage(outfname); interp->writeInterpolatedImage(outfname);
#endif
img=interp->getInterpolatedImage(); img=interp->getInterpolatedImage();
for (ix=0; ix<NC; ix++) { for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) { for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nSubPixels; isx++) {
for (isx=0; isx<nSubPixels; isx++) {
for (isy=0; isy<nSubPixelsY; isy++) { for (isy=0; isy<nSubPixelsY; isy++) {
totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]; totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
#ifdef RECT1
if (isx==0)
rectimg[ix+(iy*nSubPixelsY+isy)*(NC)]=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
else
rectimg[ix+(iy*nSubPixelsY+isy)*(NC)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
#endif
} }
} }
} }
} }
#ifdef RECT1
WriteToTiff(rectimg, outfname,NC,NR*nSubPixelsY);
#endif
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl; cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl;
interp->clearInterpolatedImage(); interp->clearInterpolatedImage();
#endif #endif
@ -246,7 +266,29 @@ int main(int argc, char *argv[]) {
} }
#ifndef FF #ifndef FF
sprintf(outfname,argv[3],11111); sprintf(outfname,argv[3],11111);
#ifndef RECT1
WriteToTiff(totimg, outfname,NC*nSubPixels,NR*nSubPixelsY); WriteToTiff(totimg, outfname,NC*nSubPixels,NR*nSubPixelsY);
#endif
#ifdef RECT1
img=interp->getInterpolatedImage();
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nSubPixels; isx++) {
for (isy=0; isy<nSubPixelsY; isy++) {
if (isx==0)
rectimg[ix+(iy*nSubPixelsY+isy)*(NC)]=totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
else
rectimg[ix+(iy*nSubPixelsY+isy)*(NC)]+=totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
}
}
}
}
WriteToTiff(rectimg, outfname,NC,NR*nSubPixelsY);
#endif
#endif #endif
#ifdef FF #ifdef FF

View File

@ -119,44 +119,44 @@ class single_photon_hit {
if (fread((void*)qq, 1, 4*sizeof(int), myFile)) { if (fread((void*)qq, 1, 4*sizeof(int), myFile)) {
quad=TOP_RIGHT; quad=TOP_RIGHT;
/* int mm=qq[0]; */ int mm=qq[0];
/* for (int i=1; i<4; i++) { */ for (int i=1; i<4; i++) {
/* if (qq[i]>mm) { */ if (qq[i]>mm) {
/* switch (i) { */ switch (i) {
/* case 1: */ case 1:
/* quad=TOP_LEFT; */ quad=TOP_LEFT;
/* break; */ break;
/* case 2: */ case 2:
/* quad=BOTTOM_RIGHT; */ quad=BOTTOM_RIGHT;
/* break; */ break;
/* case 3: */ case 3:
/* quad=BOTTOM_LEFT; */ quad=BOTTOM_LEFT;
/* break; */ break;
/* default: */ default:
/* ; */ ;
/* } */ }
mm=qq[i];
}
/* } */ }
/* } */
/* switch(quad) { */ switch(quad) {
/* case TOP_LEFT: */ case TOP_LEFT:
/* data[0]=0; */ data[0]=0;
/* data[1]=0; */ data[1]=0;
/* data[2]=0; */ data[2]=0;
/* data[3]=qq[0]; */ data[3]=qq[0];
/* data[4]=qq[1]; */ data[4]=qq[1];
/* data[5]=0; */ data[5]=0;
/* data[6]=qq[2]; */ data[6]=qq[2];
/* data[7]=qq[3]; */ data[7]=qq[3];
/* data[8]=0; */ data[8]=0;
/* x=x+1; */ x=x+1;
/* y=y; */ y=y;
/* break; */ break;
/* case TOP_RIGHT: */ case TOP_RIGHT:
data[0]=0; data[0]=0;
data[1]=0; data[1]=0;
data[2]=0; data[2]=0;
@ -168,40 +168,40 @@ class single_photon_hit {
data[8]=qq[3]; data[8]=qq[3];
x=x; x=x;
y=y; y=y;
/* break; */ break;
/* case BOTTOM_LEFT: */ case BOTTOM_LEFT:
/* data[0]=qq[0]; */ data[0]=qq[0];
/* data[1]=qq[1]; */ data[1]=qq[1];
/* data[2]=0; */ data[2]=0;
/* data[3]=qq[2]; */ data[3]=qq[2];
/* data[4]=qq[3]; */ data[4]=qq[3];
/* data[5]=0; */ data[5]=0;
/* data[6]=0; */ data[6]=0;
/* data[7]=0; */ data[7]=0;
/* data[8]=0; */ data[8]=0;
/* x=x+1; */ x=x+1;
/* y=y+1; */ y=y+1;
/* break; */ break;
/* case BOTTOM_RIGHT: */ case BOTTOM_RIGHT:
/* data[0]=0; */ data[0]=0;
/* data[1]=qq[0]; */ data[1]=qq[0];
/* data[2]=qq[1]; */ data[2]=qq[1];
/* data[3]=0; */ data[3]=0;
/* data[4]=qq[2]; */ data[4]=qq[2];
/* data[5]=qq[3]; */ data[5]=qq[3];
/* data[6]=0; */ data[6]=0;
/* data[7]=0; */ data[7]=0;
/* data[8]=0; */ data[8]=0;
/* x=x; */ x=x;
/* y=y+1; */ y=y+1;
/* break; */ break;
/* default: */ default:
/* ; */ ;
/* } */ }
return 1; return 1;
} }
#endif #endif