Interpolation changed for rectangular pixels

This commit is contained in:
2019-12-09 13:53:11 +01:00
parent a2c26664ee
commit 9584ea626d
7 changed files with 331 additions and 291 deletions

View File

@ -13,7 +13,7 @@
class eta2InterpolationBase : public virtual etaInterpolationBase { class eta2InterpolationBase : public virtual etaInterpolationBase {
public: public:
eta2InterpolationBase(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nb, emin, emax) { eta2InterpolationBase(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax) {
/* if (etamin>=etamax) { */ /* if (etamin>=etamax) { */
/* etamin=-1; */ /* etamin=-1; */
@ -37,7 +37,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
int corner; int corner;
corner=calcQuad(data, tot, totquad, sDum); corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixels>2) if (nSubPixelsX>2 || nSubPixelsY>2)
calcEta(totquad, sDum, etax, etay); calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y); getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
@ -53,7 +53,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
int corner; int corner;
corner=calcQuad(data, tot, totquad, sDum); corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixels>2) if (nSubPixelsX>2 || nSubPixelsY>2 )
calcEta(totquad, sDum, etax, etay); calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y); getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
@ -93,7 +93,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
; ;
} }
double etax=0, etay=0; double etax=0, etay=0;
if (nSubPixels>2) { if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff]; cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)]; cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff]; cc[0][1]=cl[xoff+1+3*yoff];
@ -133,7 +133,7 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
; ;
} }
double etax=0, etay=0; double etax=0, etay=0;
if (nSubPixels>2) { if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff]; cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)]; cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff]; cc[0][1]=cl[xoff+1+3*yoff];
@ -182,31 +182,31 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
} }
if (nSubPixels>2) { if (nSubPixelsX>2 || nSubPixelsY>2 ) {
ex=(etax-etamin)/etastep; ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastep; ey=(etay-etamin)/etastepY;
if (ex<0) { if (ex<0) {
cout << "x*"<< ex << endl; cout << "x*"<< ex << endl;
ex=0; ex=0;
} }
if (ex>=nbeta) { if (ex>=nbetaX) {
cout << "x?"<< ex << endl; cout << "x?"<< ex << endl;
ex=nbeta-1; ex=nbetaX-1;
} }
if (ey<0) { if (ey<0) {
cout << "y*"<< ey << endl; cout << "y*"<< ey << endl;
ey=0; ey=0;
} }
if (ey>=nbeta) { if (ey>=nbetaY) {
cout << "y?"<< ey << endl; cout << "y?"<< ey << endl;
ey=nbeta-1; ey=nbetaY-1;
} }
xpos_eta=(((double)hhx[(ey*nbeta+ex)]))+dX ;///((double)nSubPixels); xpos_eta=(((double)hhx[(ey*nbetaX+ex)]))+dX ;///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbeta+ex)]))+dY ;///((double)nSubPixels); ypos_eta=(((double)hhy[(ey*nbetaX+ex)]))+dY ;///((double)nSubPixels);
} else { } else {
xpos_eta=0.5*dX+0.25; xpos_eta=0.5*dX+0.25;
@ -347,10 +347,10 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
#endif #endif
#ifndef MYROOT1 #ifndef MYROOT1
int ex,ey; int ex,ey;
ex=(etax-etamin)/etastep; ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastep; ey=(etay-etamin)/etastepY;
if (ey<nbeta && ex<nbeta && ex>=0 && ey>=0) if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbeta+ex]++; heta[ey*nbetaX+ex]++;
#endif #endif
return 0; return 0;
}; };
@ -360,22 +360,22 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
// cout << "ff" << endl; // cout << "ff" << endl;
calcDiff(1, hhx, hhy); //get flat calcDiff(1, hhx, hhy); //get flat
double avg=0; double avg=0;
for (ipx=0; ipx<nSubPixels; ipx++) for (ipx=0; ipx<nSubPixelsX; ipx++)
for (ipy=0; ipy<nSubPixels; ipy++) for (ipy=0; ipy<nSubPixelsY; ipy++)
avg+=flat[ipx+ipy*nSubPixels]; avg+=flat[ipx+ipy*nSubPixelsX];
avg/=nSubPixels*nSubPixels; avg/=nSubPixelsY*nSubPixelsX;
for (int ibx=0 ; ibx<nSubPixels*nPixelsX; ibx++) { for (int ibx=0 ; ibx<nSubPixelsX*nPixelsX; ibx++) {
ipx=ibx%nSubPixels-nSubPixels/2; ipx=ibx%nSubPixelsX-nSubPixelsX/2;
if (ipx<0) ipx=nSubPixels+ipx; if (ipx<0) ipx=nSubPixelsX+ipx;
for (int iby=0 ; iby<nSubPixels*nPixelsY; iby++) { for (int iby=0 ; iby<nSubPixelsY*nPixelsY; iby++) {
ipy=iby%nSubPixels-nSubPixels/2; ipy=iby%nSubPixelsY-nSubPixelsY/2;
if (ipy<0) ipy=nSubPixels+ipy; if (ipy<0) ipy=nSubPixelsY+ipy;
// cout << ipx << " " << ipy << " " << ibx << " " << iby << endl; // cout << ipx << " " << ipy << " " << ibx << " " << iby << endl;
if (flat[ipx+ipy*nSubPixels]>0) if (flat[ipx+ipy*nSubPixelsX]>0)
hintcorr[ibx+iby*nSubPixels*nPixelsX]=hint[ibx+iby*nSubPixels*nPixelsX]*(avg/flat[ipx+ipy*nSubPixels]); hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX]*(avg/flat[ipx+ipy*nSubPixelsX]);
else else
hintcorr[ibx+iby*nSubPixels*nPixelsX]=hint[ibx+iby*nSubPixels*nPixelsX]; hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX];
} }

View File

@ -13,35 +13,12 @@
class eta3InterpolationBase : public virtual etaInterpolationBase { class eta3InterpolationBase : public virtual etaInterpolationBase {
public: public:
eta3InterpolationBase(int nx=400, int ny=400, int ns=25, int nb=-1, double emin=1, double emax=0) : etaInterpolationBase(nx, ny, ns, nb, emin, emax) { eta3InterpolationBase(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : etaInterpolationBase(nx, ny, ns, nsy, nb, nby, emin, emax) {
// cout << "e3ib " << nb << " " << emin << " " << emax << endl; // cout << "e3ib " << nb << " " << emin << " " << emax << endl;
/* if (nbeta<=0) { */ /* if (nbeta<=0) { */
/* nbeta=nSubPixels*10; */ /* nbeta=nSubPixels*10; */
/* } */ /* } */
if (etamin>=etamax) {
etamin=-1;
etamax=1;
}
etastep=(etamax-etamin)/nbeta;
#ifdef MYROOT1
delete heta;
delete hhx;
delete hhy;
heta=new TH2D("heta","heta",nbeta,etamin,etamax,nbeta,etamin,etamax);
hhx=new TH2D("hhx","hhx",nbeta,etamin,etamax,nbeta,etamin,etamax);
hhy=new TH2D("hhy","hhy",nbeta,etamin,etamax,nbeta,etamin,etamax);
#endif
#ifndef MYROOT1
/* delete [] heta; */
/* delete [] hhx; */
/* delete [] hhy; */
/* heta=new int[nbeta*nbeta]; */
/* hhx=new float[nbeta*nbeta]; */
/* hhy=new float[nbeta*nbeta]; */
#endif
// cout << nbeta << " " << etamin << " " << etamax << endl; // cout << nbeta << " " << etamin << " " << etamax << endl;
}; };
@ -88,7 +65,7 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
double etax, etay; double etax, etay;
if (nSubPixels>2) { if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad); calcEta3(cl,etax,etay, totquad);
} }
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y); return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
@ -101,7 +78,7 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
double etax, etay; double etax, etay;
if (nSubPixels>2) { if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad); calcEta3(cl,etax,etay, totquad);
} }
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y); return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
@ -117,38 +94,38 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
double xpos_eta=0,ypos_eta=0; double xpos_eta=0,ypos_eta=0;
int ex,ey; int ex,ey;
if (nSubPixels>2) { if (nSubPixelsX>2 || nSubPixelsY>2 ) {
#ifdef MYROOT1 #ifdef MYROOT1
xpos_eta=(hhx->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixels); xpos_eta=(hhx->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixelsX);
ypos_eta=(hhy->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixels); ypos_eta=(hhy->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixelsY);
#endif #endif
#ifndef MYROOT1 #ifndef MYROOT1
ex=(etax-etamin)/etastep; ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastep; ey=(etay-etamin)/etastepY;
if (ex<0) { if (ex<0) {
/* cout << etax << " " << etamin << " "; */ /* cout << etax << " " << etamin << " "; */
/* cout << "3x*"<< ex << endl; */ /* cout << "3x*"<< ex << endl; */
ex=0; ex=0;
} }
if (ex>=nbeta) { if (ex>=nbetaX) {
/* cout << etax << " " << etamin << " "; */ /* cout << etax << " " << etamin << " "; */
/* cout << "3x?"<< ex << endl; */ /* cout << "3x?"<< ex << endl; */
ex=nbeta-1; ex=nbetaX-1;
} }
if (ey<0) { if (ey<0) {
/* cout << etay << " " << etamin << " "; */ /* cout << etay << " " << etamin << " "; */
/* cout << "3y*"<< ey << endl; */ /* cout << "3y*"<< ey << endl; */
ey=0; ey=0;
} }
if (ey>=nbeta) { if (ey>=nbetaY) {
/* cout << etay << " " << etamin << " "; */ /* cout << etay << " " << etamin << " "; */
/* cout << "3y?"<< ey << endl; */ /* cout << "3y?"<< ey << endl; */
ey=nbeta-1; ey=nbetaY-1;
} }
xpos_eta=(((double)hhx[(ey*nbeta+ex)]));///((double)nSubPixels); xpos_eta=(((double)hhx[(ey*nbetaX+ex)]));///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbeta+ex)]));///((double)nSubPixels); ypos_eta=(((double)hhy[(ey*nbetaX+ex)]));///((double)nSubPixels);
#endif #endif
@ -265,10 +242,10 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
#endif #endif
#ifndef MYROOT1 #ifndef MYROOT1
int ex,ey; int ex,ey;
ex=(etax-etamin)/etastep; ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastep; ey=(etay-etamin)/etastepY;
if (ey<nbeta && ex<nbeta && ex>=0 && ey>=0) if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbeta+ex]++; heta[ey*nbetaX+ex]++;
#endif #endif
return 0; return 0;
}; };

View File

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

View File

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

View File

@ -29,19 +29,21 @@ class slsInterpolation
{ {
public: public:
slsInterpolation(int nx=400, int ny=400, int ns=25) :nPixelsX(nx), nPixelsY(ny), nSubPixels(ns), id(0) { slsInterpolation(int nx=400, int ny=400, int ns=25, int nsy=-1) :nPixelsX(nx), nPixelsY(ny), nSubPixelsX(ns), nSubPixelsY(nsy),id(0) {
hint=new int[ns*nx*ns*ny]; if (nSubPixelsY<=0) nSubPixelsY=nSubPixelsX;
hint=new int[nSubPixelsX*nx*nSubPixelsY*ny];
}; };
slsInterpolation(slsInterpolation *orig){ slsInterpolation(slsInterpolation *orig){
nPixelsX=orig->nPixelsX; nPixelsX=orig->nPixelsX;
nPixelsY=orig->nPixelsY; nPixelsY=orig->nPixelsY;
nSubPixels=orig->nSubPixels; nSubPixelsX=orig->nSubPixelsX;
nSubPixelsY=orig->nSubPixelsY;
hint=new int[nSubPixels*nPixelsX*nSubPixels*nPixelsY]; hint=new int[nSubPixelsX*nPixelsX*nSubPixelsY*nPixelsY];
memcpy(hint, orig->hint,nSubPixels*nPixelsX*nSubPixels*nPixelsY*sizeof(int)); memcpy(hint, orig->hint,nSubPixelsX*nPixelsX*nSubPixelsY*nPixelsY*sizeof(int));
}; };
@ -51,23 +53,37 @@ class slsInterpolation
return new slsInterpolation(this); return new slsInterpolation(this);
}*/ }*/
int getNSubPixels() {return nSubPixels;}; int getNSubPixelsX() {return nSubPixelsX;};
int getNSubPixelsY() {return nSubPixelsY;};
int getNSubPixels() {if (nSubPixelsX==nSubPixelsY) return nSubPixelsX; else return 0;};
void getNSubPixels(int &nsx, int &nsy) {nsx=nSubPixelsX; nsy=nsx=nSubPixelsY;}
void setNSubPixels(int ns, int nsy=-1) {
int setNSubPixels(int ns) {
if (ns>0 && ns!=nSubPixels) {
delete [] hint; delete [] hint;
nSubPixels=ns; nSubPixelsX=ns;
hint=new int[nSubPixels*nPixelsX*nSubPixels*nPixelsY]; if (nsy>0) nSubPixelsY=nsy;
} else nSubPixelsY=ns;
return nSubPixels;
hint=new int[nSubPixelsX*nPixelsX*nSubPixelsY*nPixelsY];
//return nSubPixels;
} }
int getImageSize(int &nnx, int &nny, int &ns) {
nnx=nSubPixels*nPixelsX;
nny=nSubPixels*nPixelsY;
ns=nSubPixels; int getImageSize(int &nnx, int &nny, int &nsx, int &nsy) {
return nSubPixels*nSubPixels*nPixelsX*nPixelsY; nnx=nSubPixelsX*nPixelsX;
nny=nSubPixelsY*nPixelsY;
nsx=nSubPixelsX;
nsy=nSubPixelsY;
return nSubPixelsX*nSubPixelsY*nPixelsX*nPixelsY;
};
int getImageSize() {
return nSubPixelsX*nSubPixelsY*nPixelsX*nPixelsY;
}; };
@ -92,14 +108,14 @@ class slsInterpolation
//cout << "!" <<endl; //cout << "!" <<endl;
float *gm=NULL; float *gm=NULL;
int *dummy=getInterpolatedImage(); int *dummy=getInterpolatedImage();
gm=new float[ nSubPixels* nSubPixels* nPixelsX*nPixelsY]; gm=new float[ nSubPixelsX* nSubPixelsY* nPixelsX*nPixelsY];
if (gm) { if (gm) {
for (int ix=0; ix<nPixelsX*nSubPixels; ix++) { for (int ix=0; ix<nPixelsX*nSubPixelsX; ix++) {
for (int iy=0; iy<nPixelsY*nSubPixels; iy++) { for (int iy=0; iy<nPixelsY*nSubPixelsY; iy++) {
gm[iy*nPixelsX*nSubPixels+ix]=dummy[iy*nPixelsX*nSubPixels+ix]; gm[iy*nPixelsX*nSubPixelsX+ix]=dummy[iy*nPixelsX*nSubPixelsX+ix];
} }
} }
WriteToTiff(gm, imgname,nSubPixels* nPixelsX ,nSubPixels* nPixelsY); WriteToTiff(gm, imgname,nSubPixelsY* nPixelsX ,nSubPixelsY* nPixelsY);
delete [] gm; delete [] gm;
} else cout << "Could not allocate float image " << endl; } else cout << "Could not allocate float image " << endl;
return NULL; return NULL;
@ -120,9 +136,9 @@ class slsInterpolation
virtual void clearInterpolatedImage() { virtual void clearInterpolatedImage() {
for (int ix=0; ix<nPixelsX*nSubPixels; ix++) { for (int ix=0; ix<nPixelsX*nSubPixelsX; ix++) {
for (int iy=0; iy<nPixelsY*nSubPixels; iy++) { for (int iy=0; iy<nPixelsY*nSubPixelsY; iy++) {
hint[iy*nPixelsX*nSubPixels+ix]=0; hint[iy*nPixelsX*nSubPixelsX+ix]=0;
} }
} }
@ -133,11 +149,11 @@ class slsInterpolation
virtual int *addToImage(double int_x, double int_y){ virtual int *addToImage(double int_x, double int_y){
int iy=((double)nSubPixels)*int_y; int iy=((double)nSubPixelsY)*int_y;
int ix=((double)nSubPixels)*int_x; int ix=((double)nSubPixelsX)*int_x;
if (ix>=0 && ix<(nPixelsX*nSubPixels) && iy<(nSubPixels*nPixelsY) && iy>=0 ){ if (ix>=0 && ix<(nPixelsX*nSubPixelsX) && iy<(nSubPixelsY*nPixelsY) && iy>=0 ){
// cout << int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << " " << hint[ix+iy*nPixelsX*nSubPixels]; // cout << int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << " " << hint[ix+iy*nPixelsX*nSubPixels];
(*(hint+ix+iy*nPixelsX*nSubPixels))+=1; (*(hint+ix+iy*nPixelsX*nSubPixelsX))+=1;
// cout << " " << hint[ix+iy*nPixelsX*nSubPixels] << endl; // cout << " " << hint[ix+iy*nPixelsX*nSubPixels] << endl;
}// else }// else
// cout << "bad! "<< int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << endl; // cout << "bad! "<< int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << endl;
@ -495,7 +511,7 @@ class slsInterpolation
protected: protected:
int nPixelsX, nPixelsY; int nPixelsX, nPixelsY;
int nSubPixels; int nSubPixelsX, nSubPixelsY;
int id; int id;
int *hint; int *hint;
}; };

View File

@ -14,13 +14,21 @@
#include "single_photon_hit.h" #include "single_photon_hit.h"
#endif #endif
//#include "etaInterpolationPosXY.h" #include "etaInterpolationPosXY.h"
#include "noInterpolation.h" #include "noInterpolation.h"
#include "etaInterpolationCleverAdaptiveBins.h" //#include "etaInterpolationCleverAdaptiveBins.h"
//#include "etaInterpolationRandomBins.h" //#include "etaInterpolationRandomBins.h"
using namespace std; using namespace std;
#ifndef RECT
#define NC 400 #define NC 400
#define NR 400 #define NR 400
#endif
#ifdef RECT
#define NC 200
#define NR 800
#endif
#define MAX_ITERATIONS (nSubPixels*100) #define MAX_ITERATIONS (nSubPixels*100)
#define XTALK #define XTALK
@ -67,6 +75,7 @@ int main(int argc, char *argv[]) {
cout << "Energy max: " << cmax << endl; cout << "Energy max: " << cmax << endl;
//int etabins=500; //int etabins=500;
int etabins=1000;//nsubpix*2*100; int etabins=1000;//nsubpix*2*100;
int etabinsY=etabins;//nsubpix*2*100;
double etamin=-1, etamax=2; double etamin=-1, etamax=2;
//double etamin=-0.1, etamax=1.1; //double etamin=-0.1, etamax=1.1;
double eta3min=-2, eta3max=2; double eta3min=-2, eta3max=2;
@ -90,14 +99,18 @@ int main(int argc, char *argv[]) {
#ifndef DOUBLE_SPH #ifndef DOUBLE_SPH
single_photon_hit cl(3,3); single_photon_hit cl(3,3);
#endif #endif
int nSubPixels=nsubpix; int nSubPixels=nsubpix;
int nSubPixelsY=nsubpix;
#ifdef RECT
nSubPixelsY=1; //might make more sense using 2?
etabinsY=2;
#endif
#ifndef NOINTERPOLATION #ifndef NOINTERPOLATION
eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, 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);
#endif #endif
#ifdef NOINTERPOLATION #ifdef NOINTERPOLATION
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix); noInterpolation *interp=new noInterpolation(NC, NR, nsubpix, nSubPixelsY);
#endif #endif
@ -116,12 +129,12 @@ int main(int argc, char *argv[]) {
#endif #endif
int *img; int *img;
float *totimg=new float[NC*NR*nsubpix*nsubpix]; float *totimg=new float[NC*NR*nSubPixels*nSubPixelsY];
for (ix=0; ix<NC; ix++) { for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) { for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) { for (isx=0; isx<nSubPixels; isx++) {
for (isy=0; isy<nsubpix; isy++) { for (isy=0; isy<nSubPixelsY; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=0; totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]=0;
} }
} }
} }
@ -172,7 +185,7 @@ int main(int argc, char *argv[]) {
// 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); interp->addToImage(int_x, int_y);
if (int_x<0 || int_y<0 || int_x>400 || int_y>400) { 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();
@ -220,9 +233,9 @@ int main(int argc, char *argv[]) {
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<nsubpix; isx++) { for (isx=0; isx<nSubPixels; isx++) {
for (isy=0; isy<nsubpix; isy++) { for (isy=0; isy<nSubPixelsY; isy++) {
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]; totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
} }
} }
} }
@ -236,7 +249,7 @@ int main(int argc, char *argv[]) {
} }
#ifndef FF #ifndef FF
sprintf(outfname,argv[3],11111); sprintf(outfname,argv[3],11111);
WriteToTiff(totimg, outfname,NC*nsubpix,NR*nsubpix); WriteToTiff(totimg, outfname,NC*nSubPixels,NR*nSubPixelsY);
#endif #endif
#ifdef FF #ifdef FF

View File

@ -227,10 +227,11 @@ FILE *getFilePointer(){return det->getFilePointer();};
} }
virtual int setNSubPixels(int ns) { virtual void setNSubPixels(int ns, int nsy=-1) {
slsInterpolation *interp=(det)->getInterpolation(); slsInterpolation *interp=(det)->getInterpolation();
if (interp) return interp->setNSubPixels(ns); if (interp) interp->setNSubPixels(ns, nsy);
else return 1;}; //else return 1;
};
virtual slsInterpolation *setInterpolation(slsInterpolation *f){ virtual slsInterpolation *setInterpolation(slsInterpolation *f){