Interpolation has problems. To be checked

This commit is contained in:
2019-12-17 17:09:50 +01:00
parent 27f2321d64
commit f7695113b8
9 changed files with 923 additions and 843 deletions

View File

@ -1,4 +1,4 @@
hostname bchip064+
hostname bchip020+
patword 0000 0000000000000000
patword 0001 0000000000000000
@ -429,6 +429,7 @@ rx_zmqport 50003
0:rx_hostname mpc2011
####pcmoench01
#0:rx_tcpport 1977
#0:rx_udpip 10.1.1.100

View File

@ -1,406 +0,0 @@
#ifndef ETA2_INTERPOLATION_BASE_H
#define ETA2_INTERPOLATION_BASE_H
#ifdef MYROOT1
#include <TObject.h>
#include <TTree.h>
#include <TH2D.h>
#include <TH2F.h>
#endif
#include "etaInterpolationBase.h"
class eta2InterpolationBase : public virtual etaInterpolationBase {
public:
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) { */
/* etamin=-1; */
/* etamax=2; */
/* // cout << ":" <<endl; */
/* } */
/* etastep=(etamax-etamin)/nbeta; */
};
eta2InterpolationBase(eta2InterpolationBase *orig): etaInterpolationBase(orig){ };
//////////////////////////////////////////////////////////////////////////////
//////////// /*It return position hit for the event in input */ //////////////
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixelsX>2 || nSubPixelsY>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 *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixelsX>2 || nSubPixelsY>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 cc[2][2];
int xoff=0, yoff=0;
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=0, etay=0;
if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(yoff+1)];
calcEta(totquad,cc,etax,etay);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double cc[2][2];
int xoff=0, yoff=0;
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=0, etay=0;
if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(xoff+1)];
calcEta(totquad,cc,etax,etay);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
{
double xpos_eta=0,ypos_eta=0;
double dX,dY;
int ex,ey;
switch (corner)
{
case TOP_LEFT:
dX=-1.;
dY=0;
break;
case TOP_RIGHT:
;
dX=0;
dY=0;
break;
case BOTTOM_LEFT:
dX=-1.;
dY=-1.;
break;
case BOTTOM_RIGHT:
dX=0;
dY=-1.;
break;
default:
cout << "bad quadrant" << endl;
dX=0.;
dY=0.;
}
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
cout << "x*"<< ex << endl;
ex=0;
}
if (ex>=nbetaX) {
cout << "x?"<< ex << endl;
ex=nbetaX-1;
}
if (ey<0) {
cout << "y*"<< ey << " " << nbetaY << endl;
ey=0;
}
if (ey>=nbetaY) {
cout << "y?"<< ey << " " << nbetaY << endl;
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]))+dX ;///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]))+dY ;///((double)nSubPixels);
} else {
xpos_eta=0.5*dX+0.25;
ypos_eta=0.5*dY+0.25;
}
int_x=((double)x) + xpos_eta+0.5;
int_y=((double)y) + ypos_eta+0.5;
}
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
double cc[2][2];
int xoff=0, yoff=0;
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:
;
}
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(yoff+1)];
//calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc,etax, etay);
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax,etay);
}
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
double cc[2][2];
int xoff=0, yoff=0;
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:
;
}
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[(yoff+1)*3+xoff];
cc[0][1]=cl[yoff*3+xoff+1];
cc[1][1]=cl[(yoff+1)*3+xoff+1];
/* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; */
/* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; */
/* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; */
/* cout <<"******"<<totquad << " " << quad << endl; */
/* cout << cc[0][0]<< " " << cc[0][1] << endl; */
/* cout << cc[1][0]<< " " << cc[1][1] << endl; */
//calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc,etax, etay);
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax,etay);
}
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
// int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
//double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
//int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
// double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(double etax, double etay){
#ifdef MYROOT1
heta->Fill(etax,etay);
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
virtual int *getInterpolatedImage(){
int ipx, ipy;
// cout << "ff" << endl;
calcDiff(1, hhx, hhy); //get flat
double avg=0;
for (ipx=0; ipx<nSubPixelsX; ipx++)
for (ipy=0; ipy<nSubPixelsY; ipy++)
avg+=flat[ipx+ipy*nSubPixelsX];
avg/=nSubPixelsY*nSubPixelsX;
for (int ibx=0 ; ibx<nSubPixelsX*nPixelsX; ibx++) {
ipx=ibx%nSubPixelsX-nSubPixelsX/2;
if (ipx<0) ipx=nSubPixelsX+ipx;
for (int iby=0 ; iby<nSubPixelsY*nPixelsY; iby++) {
ipy=iby%nSubPixelsY-nSubPixelsY/2;
if (ipy<0) ipy=nSubPixelsY+ipy;
// cout << ipx << " " << ipy << " " << ibx << " " << iby << endl;
if (flat[ipx+ipy*nSubPixelsX]>0)
hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX]*(avg/flat[ipx+ipy*nSubPixelsX]);
else
hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX];
}
}
return hintcorr;
};
/* protected: */
/* #ifdef MYROOT1 */
/* TH2D *heta; */
/* TH2D *hhx; */
/* TH2D *hhy; */
/* #endif */
/* #ifndef MYROOT1 */
/* int *heta; */
/* float *hhx; */
/* float *hhy; */
/* #endif */
/* int nbeta; */
/* double etamin, etamax, etastep; */
};
#endif

View File

@ -1,271 +0,0 @@
#ifndef ETA3_INTERPOLATION_BASE_H
#define ETA3_INTERPOLATION_BASE_H
#ifdef MYROOT1
#include <TObject.h>
#include <TTree.h>
#include <TH2D.h>
#include <TH2F.h>
#endif
#include "etaInterpolationBase.h"
class eta3InterpolationBase : public virtual etaInterpolationBase {
public:
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;
/* if (nbeta<=0) { */
/* nbeta=nSubPixels*10; */
/* } */
// cout << nbeta << " " << etamin << " " << etamax << endl;
};
eta3InterpolationBase(eta3InterpolationBase *orig): etaInterpolationBase(orig){ };
/* virtual eta3InterpolationBase* Clone()=0; */
// virtual void prepareInterpolation(int &ok){};
//////////////////////////////////////////////////////////////////////////////
//////////// /*It return position hit for the event in input */ //////////////
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, tot);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
{
//double sDum[2][2];
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, tot);
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 etax, etay;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double etax, etay;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
{
double xpos_eta=0,ypos_eta=0;
int ex,ey;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
#ifdef MYROOT1
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)nSubPixelsY);
#endif
#ifndef MYROOT1
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x*"<< ex << endl; */
ex=0;
}
if (ex>=nbetaX) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x?"<< ex << endl; */
ex=nbetaX-1;
}
if (ey<0) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y*"<< ey << endl; */
ey=0;
}
if (ey>=nbetaY) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y?"<< ey << endl; */
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]));///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]));///((double)nSubPixels);
#endif
} else {
switch (corner) {
case BOTTOM_LEFT:
xpos_eta=-0.25;
ypos_eta=-0.25;
break;
case BOTTOM_RIGHT:
xpos_eta=0.25;
ypos_eta=-0.25;
break;
case TOP_LEFT:
xpos_eta=-0.25;
ypos_eta=0.25;
break;
case TOP_RIGHT:
xpos_eta=0.25;
ypos_eta=0.25;
break;
default:
xpos_eta=0;
ypos_eta=0;
}
}
int_x=((double)x) + xpos_eta;
int_y=((double)y) + ypos_eta;
// int_x=5. + xpos_eta;
// int_y=5. + ypos_eta;
}
/* ///////////////////////////////////////////////////////////////////////////////////////////////// */
/* virtual void getPositionETA3(int x, int y, double *data, double &int_x, double &int_y) */
/* { */
/* double sDum[2][2]; */
/* double tot, totquad; */
/* double eta3x,eta3y; */
/* double ex,ey; */
/* calcQuad(data, tot, totquad, sDum); */
/* calcEta3(data,eta3x, eta3y,tot); */
/* double xpos_eta,ypos_eta; */
/* #ifdef MYROOT1 */
/* xpos_eta=((hhx->GetBinContent(hhx->GetXaxis()->FindBin(eta3x),hhy->GetYaxis()->FindBin(eta3y))))/((double)nSubPixels); */
/* ypos_eta=((hhy->GetBinContent(hhx->GetXaxis()->FindBin(eta3x),hhy->GetYaxis()->FindBin(eta3y))))/((double)nSubPixels); */
/* #endif */
/* #ifndef MYROOT1 */
/* ex=(eta3x-etamin)/etastep; */
/* ey=(eta3y-etamin)/etastep; */
/* if (ex<0) ex=0; */
/* if (ex>=nbeta) ex=nbeta-1; */
/* if (ey<0) ey=0; */
/* if (ey>=nbeta) ey=nbeta-1; */
/* xpos_eta=(((double)hhx[(int)(ey*nbeta+ex)]))/((double)nSubPixels); */
/* ypos_eta=(((double)hhy[(int)(ey*nbeta+ex)]))/((double)nSubPixels); */
/* #endif */
/* int_x=((double)x) + xpos_eta; */
/* int_y=((double)y) + ypos_eta; */
/* return; */
/* }; */
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax,etay);
}
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax,etay);
}
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(double etax, double etay){
#ifdef MYROOT1
heta->Fill(etax,etay);
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
/* protected: */
/* #ifdef MYROOT1 */
/* TH2D *heta; */
/* TH2D *hhx; */
/* TH2D *hhy; */
/* #endif */
/* #ifndef MYROOT1 */
/* int *heta; */
/* float *hhx; */
/* float *hhy; */
/* #endif */
/* int nbeta; */
/* double etamin, etamax, etastep; */
};
#endif

View File

@ -13,6 +13,19 @@
class etaInterpolationBase : public slsInterpolation {
protected:
float *hhx;
float *hhy;
int *heta;
int nbetaX, nbetaY;
double etamin, etamax, etastepX, etastepY;
double rangeMin, rangeMax;
double *flat;
int *hintcorr;
public:
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) {
@ -190,17 +203,8 @@ float *gethhx()
// hhy->Scale((double)nSubPixels);
return hhy;
};
virtual int addToFlatField(double etax, double etay){
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
return 0;
};
// virtual void prepareInterpolation(int &ok)=0;
void debugSaveAll(int ind=0) {
@ -223,15 +227,15 @@ float *gethhx()
for (int ii=0; ii<nbetaX*nbetaY; ii++) {
ibb=(hhx[ii]*nSubPixelsX);
etah[ii]=ibb;
//ibb=hhx[ii];//*nSubPixelsX);
etah[ii]=hhx[ii];
}
sprintf(tit,"/scratch/eta_hhx_%d.tiff",ind);
WriteToTiff(etah, tit, nbetaX, nbetaY);
for (int ii=0; ii<nbetaX*nbetaY; ii++) {
ibb=hhy[ii]*nSubPixelsY;
etah[ii]=ibb;
//ibb=hhy[ii];//*nSubPixelsY;
etah[ii]=hhy[ii];
}
sprintf(tit,"/scratch/eta_hhy_%d.tiff",ind);
WriteToTiff(etah, tit, nbetaX, nbetaY);
@ -291,6 +295,37 @@ float *gethhx()
}
virtual int *getInterpolatedImage(){
/* int ipx, ipy; */
/* // cout << "ff" << endl; */
/* calcDiff(1, hhx, hhy); //get flat */
/* double avg=0; */
/* for (ipx=0; ipx<nSubPixelsX; ipx++) */
/* for (ipy=0; ipy<nSubPixelsY; ipy++) */
/* avg+=flat[ipx+ipy*nSubPixelsX]; */
/* avg/=nSubPixelsY*nSubPixelsX; */
/* for (int ibx=0 ; ibx<nSubPixelsX*nPixelsX; ibx++) { */
/* ipx=ibx%nSubPixelsX-nSubPixelsX/2; */
/* if (ipx<0) ipx=nSubPixelsX+ipx; */
/* for (int iby=0 ; iby<nSubPixelsY*nPixelsY; iby++) { */
/* ipy=iby%nSubPixelsY-nSubPixelsY/2; */
/* if (ipy<0) ipy=nSubPixelsY+ipy; */
/* // cout << ipx << " " << ipy << " " << ibx << " " << iby << endl; */
/* if (flat[ipx+ipy*nSubPixelsX]>0) */
/* hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX]*(avg/flat[ipx+ipy*nSubPixelsX]); */
/* else */
/* hintcorr[ibx+iby*nSubPixelsX*nPixelsX]=hint[ibx+iby*nSubPixelsX*nPixelsX]; */
/* } */
/* } */
return hint;
/* return hintcorr; */
};
protected:
@ -363,17 +398,573 @@ float *gethhx()
return sqrt(diff);
}
float *hhx;
float *hhy;
int *heta;
int nbetaX, nbetaY;
double etamin, etamax, etastepX, etastepY;
double rangeMin, rangeMax;
};
double *flat;
int *hintcorr;
class eta2InterpolationBase : public virtual etaInterpolationBase {
public:
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) {
};
eta2InterpolationBase(eta2InterpolationBase *orig): etaInterpolationBase(orig){ };
//////////////////////////////////////////////////////////////////////////////
//////////// /*It return position hit for the event in input */ //////////////
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixelsX>2 || nSubPixelsY>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 *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax=0,etay=0;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixelsX>2 || nSubPixelsY>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 cc[2][2];
int xoff=0, yoff=0;
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=0, etay=0;
if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(yoff+1)];
calcEta(totquad,cc,etax,etay);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double cc[2][2];
int xoff=0, yoff=0;
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=0, etay=0;
if (nSubPixelsX>2 || nSubPixelsY>2) {
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(xoff+1)];
calcEta(totquad,cc,etax,etay);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
{
double xpos_eta=0,ypos_eta=0;
double dX,dY;
int ex,ey;
switch (corner)
{
case TOP_LEFT:
dX=-1.;
dY=0;
break;
case TOP_RIGHT:
;
dX=0;
dY=0;
break;
case BOTTOM_LEFT:
dX=-1.;
dY=-1.;
break;
case BOTTOM_RIGHT:
dX=0;
dY=-1.;
break;
default:
cout << "bad quadrant" << endl;
dX=0.;
dY=0.;
}
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
cout << "x*"<< ex << endl;
ex=0;
}
if (ex>=nbetaX) {
cout << "x?"<< ex << endl;
ex=nbetaX-1;
}
if (ey<0) {
cout << "y*"<< ey << " " << nbetaY << endl;
ey=0;
}
if (ey>=nbetaY) {
cout << "y?"<< ey << " " << nbetaY << endl;
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]));
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]));
if (xpos_eta<0 || xpos_eta>1)
xpos_eta=-100;
else
xpos_eta+=dX ;///((double)nSubPixels);
if (ypos_eta<0 || ypos_eta>1)
ypos_eta=-100;
else
ypos_eta+=dY ;///((double)nSubPixels);
} else {
xpos_eta=0.5*dX+0.25;
ypos_eta=0.5*dY+0.25;
}
if (xpos_eta<-1)
int_x=-100;
else
int_x=((double)x) + xpos_eta+0.5;
if (ypos_eta<-1)
int_y=-100;
else
int_y=((double)y) + ypos_eta+0.5;
}
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
double cc[2][2];
int xoff=0, yoff=0;
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:
;
}
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[xoff+3*(yoff+1)];
cc[0][1]=cl[xoff+1+3*yoff];
cc[1][1]=cl[xoff+1+3*(yoff+1)];
//calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc,etax, etay);
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax,etay);
}
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
double cc[2][2];
int xoff=0, yoff=0;
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:
;
}
cc[0][0]=cl[xoff+3*yoff];
cc[1][0]=cl[(yoff+1)*3+xoff];
cc[0][1]=cl[yoff*3+xoff+1];
cc[1][1]=cl[(yoff+1)*3+xoff+1];
/* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; */
/* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; */
/* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; */
/* cout <<"******"<<totquad << " " << quad << endl; */
/* cout << cc[0][0]<< " " << cc[0][1] << endl; */
/* cout << cc[1][0]<< " " << cc[1][1] << endl; */
//calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc,etax, etay);
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatField(etax,etay);
}
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
// int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
//double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double sDum[2][2];
double tot, totquad;
//int corner;
//corner=
calcQuad(cluster, tot, totquad, sDum);
// double xpos_eta,ypos_eta;
//double dX,dY;
calcEta(totquad, sDum, etax, etay);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(double etax, double etay){
#ifdef MYROOT1
heta->Fill(etax,etay);
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
};
class eta3InterpolationBase : public virtual etaInterpolationBase {
public:
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;
};
eta3InterpolationBase(eta3InterpolationBase *orig): etaInterpolationBase(orig){ };
//////////////////////////////////////////////////////////////////////////////
//////////// /*It return position hit for the event in input */ //////////////
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, tot);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
{
//double sDum[2][2];
double tot;
double etax,etay;
int corner=calcEta3(data,etax,etay, tot);
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 etax, etay;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double etax, etay;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
calcEta3(cl,etax,etay, totquad);
}
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
}
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
{
//cout << "**";
double xpos_eta=0,ypos_eta=0;
int ex,ey;
if (nSubPixelsX>2 || nSubPixelsY>2 ) {
#ifdef MYROOT1
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)nSubPixelsY);
#endif
#ifndef MYROOT1
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ex<0) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x*"<< ex << endl; */
ex=0;
}
if (ex>=nbetaX) {
/* cout << etax << " " << etamin << " "; */
/* cout << "3x?"<< ex << endl; */
ex=nbetaX-1;
}
if (ey<0) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y*"<< ey << endl; */
ey=0;
}
if (ey>=nbetaY) {
/* cout << etay << " " << etamin << " "; */
/* cout << "3y?"<< ey << endl; */
ey=nbetaY-1;
}
xpos_eta=(((double)hhx[(ey*nbetaX+ex)]));///((double)nSubPixels);
ypos_eta=(((double)hhy[(ey*nbetaX+ex)]));///((double)nSubPixels);
#endif
} else {
switch (corner) {
case BOTTOM_LEFT:
xpos_eta=-0.25;
ypos_eta=-0.25;
break;
case BOTTOM_RIGHT:
xpos_eta=0.25;
ypos_eta=-0.25;
break;
case TOP_LEFT:
xpos_eta=-0.25;
ypos_eta=0.25;
break;
case TOP_RIGHT:
xpos_eta=0.25;
ypos_eta=0.25;
break;
default:
xpos_eta=0;
ypos_eta=0;
}
}
/* if (xpos_eta<0 || xpos_eta>1) */
/* int_x=-1; */
/* else */
int_x=((double)x) + xpos_eta;
/* if (ypos_eta<0 || ypos_eta>1) */
/* int_y=-1; */
/* else */
int_y=((double)y) + ypos_eta;
// int_x=5. + xpos_eta;
// int_y=5. + ypos_eta;
}
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax,etay);
}
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax,etay);
}
//////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(int *cluster, double &etax, double &etay){
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax,etay);
};
virtual int addToFlatField(double etax, double etay){
#ifdef MYROOT1
heta->Fill(etax,etay);
#endif
#ifndef MYROOT1
int ex,ey;
ex=(etax-etamin)/etastepX;
ey=(etay-etamin)/etastepY;
if (ey<nbetaY && ex<nbetaX && ex>=0 && ey>=0)
heta[ey*nbetaX+ex]++;
#endif
return 0;
};
};

View File

@ -4,9 +4,9 @@
#include "etaInterpolationBase.h"
class etaInterpolationGlobal : public etaInterpolationBase{
class etaInterpolationGlobal : public virtual etaInterpolationBase {
public:
globalEtaInterpolation(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){};
etaInterpolationGlobal(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){};
@ -24,62 +24,106 @@ class etaInterpolationGlobal : public etaInterpolationBase{
///*Eta Distribution Rebinning*///
double bsize=1./nSubPixels; //precision
// double bsizeX=1./nSubPixelsX; //precision
// cout<<"nPixelsX = "<<nPixelsX<<" nPixelsY = "<<nPixelsY<<" nSubPixels = "<<nSubPixels<<endl;
double tot_eta=0;
for (int ip=0; ip<nbeta*nbeta; ip++)
for (int ip=0; ip<nbetaX*nbetaY; ip++)
tot_eta+=heta[ip];
cout << "total eta entries is :"<< tot_eta << endl;
if (tot_eta<=0) {ok=0; return;};
double hx[nbeta]; //projection x
double hy[nbeta]; //projection y
double hx[nbetaX]; //projection x
double hy[nbetaY]; //projection y
for (int ibx=0; ibx<nbeta; ibx++) {
for (int iby=0; iby<nbeta; iby++) {
hx[ibx]=hx[ibx]+heta[ibx+iby*nbeta];
hy[iby]=hx[iby]+heta[ibx+iby*nbeta];
for (int ibx=0; ibx<nbetaX; ibx++) { hx[ibx]=0;}
for (int iby=0; iby<nbetaY; iby++) { hy[iby]=0;}
for (int ibx=0; ibx<nbetaX; ibx++) {
for (int iby=0; iby<nbetaY; iby++) {
hx[ibx]=hx[ibx]+heta[ibx+iby*nbetaX];
hy[iby]=hy[iby]+heta[ibx+iby*nbetaX];
}
}
double hix[nbeta]; //integral of projection x
double hiy[nbeta]; //integral of projection y
double hix[nbetaX]; //integral of projection x
double hiy[nbetaY]; //integral of projection y
hix[0]=hx[0];
hiy[0]=hy[0];
for (int ib=1; ib<nbeta; ib++) {
for (int ib=1; ib<nbetaX; ib++) {
hix[ib]=hix[ib-1]+hx[ib];
hiy[ib]=hiy[ib-1]+hx[ib];
}
for (int ib=1; ib<nbetaY; ib++) {
hiy[ib]=hiy[ib-1]+hy[ib];
}
double tot_x=hix[nbetaX-1]+1;
double tot_y=hiy[nbetaY-1]+1;
int ib=0;
for (int ibx=0; ibx<nbeta; ibx++) {
if (hix[ibx]>(ib+1)*tot_eta*bsize) ib++;
for (int iby=0; iby<nbeta; iby++) {
#ifdef MYROOT1
hhx->SetBinContent(ibx+1,iby+1,ib);
#endif
#ifndef MYROOT1
hhx[ibx+iby*nbeta]=ib;
#endif
}
}
ib=0;
for (int iby=0; iby<nbeta; iby++) {
if (hiy[iby]>(ib+1)*tot_eta*bsize) ib++;
for (int ibx=0; ibx<nbeta; ibx++) {
#ifdef MYROOT1
hhy->SetBinContent(ibx+1,iby+1,ib);
#endif
#ifndef MYROOT1
hhy[ibx+iby*nbeta]=ib;
#endif
for (int ibx=0; ibx<nbetaX; ibx++) {
// if (hix[ibx]>(ib+1)*tot_eta*bsize) ib++;
for (int iby=0; iby<nbetaY; iby++) {
if (tot_x>0)
hhx[ibx+iby*nbetaX]=hix[ibx]/tot_x;
else
hhx[ibx+iby*nbetaX]=-1;
if (tot_y>0)
hhy[ibx+iby*nbetaX]=hiy[iby]/tot_y;
else
hhy[ibx+iby*nbetaX]=-1;
}
}
/* ib=0; */
/* for (int iby=0; iby<nbeta; iby++) { */
/* if (hiy[iby]>(ib+1)*tot_eta*bsize) ib++; */
/* for (int ibx=0; ibx<nbeta; ibx++) { */
/* #ifdef MYROOT1 */
/* hhy->SetBinContent(ibx+1,iby+1,ib); */
/* #endif */
/* #ifndef MYROOT1 */
/* hhy[ibx+iby*nbeta]=ib; */
/* #endif */
/* } */
/* } */
return ;
};
etaInterpolationGlobal(etaInterpolationGlobal *orig): etaInterpolationBase(orig) {};
};
//etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),
class eta2InterpolationGlobal : public virtual eta2InterpolationBase, public virtual etaInterpolationGlobal {
public:
eta2InterpolationGlobal(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : eta2InterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax), etaInterpolationGlobal(nx,ny, ns, nsy, nb, nby, emin, emax){
cout << "e2pxy " << nbetaX << " " << nbetaY << etamin << " " << etamax << " " << nSubPixelsX<< " " << nSubPixelsY << endl;
};
eta2InterpolationGlobal(eta2InterpolationGlobal *orig): etaInterpolationBase(orig), etaInterpolationGlobal(orig) {};
virtual eta2InterpolationGlobal* Clone() { return new eta2InterpolationGlobal(this);};
};
//etaInterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax),
class eta3InterpolationGlobal : public virtual eta3InterpolationBase, public virtual etaInterpolationGlobal {
public:
eta3InterpolationGlobal(int nx=400, int ny=400, int ns=25, int nsy=25, int nb=-1, int nby=-1, double emin=1, double emax=0) : eta3InterpolationBase(nx,ny, ns, nsy, nb, nby, emin, emax), etaInterpolationGlobal(nx,ny, ns, nsy, nb, nby, emin, emax){
cout << "e3pxy " << nbetaX << " " << nbetaY << etamin << " " << etamax << " " << nSubPixelsX<< " " << nSubPixelsY << endl;
};
eta3InterpolationGlobal(eta3InterpolationGlobal *orig): etaInterpolationBase(orig), etaInterpolationGlobal(orig) {};
virtual eta3InterpolationGlobal* Clone() {return new eta3InterpolationGlobal(this);};
};
#endif

View File

@ -4,8 +4,6 @@
//#include "tiffIO.h"
#include "etaInterpolationBase.h"
#include "eta2InterpolationBase.h"
#include "eta3InterpolationBase.h"
class etaInterpolationPosXY : public virtual etaInterpolationBase{
public:
@ -44,9 +42,8 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
double hiy[nbetaY]; //integral of projection y
// int ii=0;
double etax, etay;
for (int ib=0; ib<nbetaX; ib++) {
//tot_eta_y=0;
for (int iby=0; iby<nbetaY; iby++) {
@ -54,10 +51,10 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
//cout << etax << endl;
// tot_eta_x+=hx[iby];
if (etay>=0 && etay<=1)
// if (etay>=0 && etay<=1)
hy[iby]=heta[ib+iby*nbetaX];
else
hy[iby]=0;
// else
// hy[iby]=0;
// tot_eta_y+=hy[iby];
}
@ -71,7 +68,7 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
tot_eta_y=hiy[nbetaY-1]+1;
for (int iby=0; iby<nbetaY; iby++) {
if (tot_eta_y<=0) {
if (tot_eta_y<=1) {
hhy[ib+iby*nbetaX]=-1;
//ii=(ibx*nSubPixels)/nbeta;
} else {
@ -80,7 +77,7 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
}
}
}
cout << "hhy filled " << endl;
for (int ib=0; ib<nbetaY; ib++) {
@ -88,11 +85,11 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
for (int ibx=0; ibx<nbetaX; ibx++) {
etax=etamin+ibx*etastepX;
//cout << etax << endl;
if (etax>=0 && etax<=1)
// if (etax>=0 && etax<=1)
hx[ibx]=heta[ibx+ib*nbetaX];
else {
hx[ibx]=0;
}
// else {
// hx[ibx]=0;
// }
}
hix[0]=hx[0];
@ -104,7 +101,7 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
tot_eta_x=hix[nbetaX-1]+1;
for (int ibx=0; ibx<nbetaX; ibx++) {
if (tot_eta_x<=0) {
if (tot_eta_x<=1) {
hhx[ibx+ib*nbetaX]=-1;
}
else {
@ -122,40 +119,49 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
hhx[ibx+ib*nbetaX]=hix[ibx]/tot_eta_x;
}
}
}
int ibx, iby, ib;
/* cout << "hhx filled " << endl; */
/* int ibx, iby, ib; */
iby=0;
while (hhx[iby*nbetaY+nbetaY/2]<0) iby++;
for (ib=0; ib<iby;ib++) {
for (ibx=0; ibx<nbetaX;ibx++)
hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby];
}
iby=nbetaY-1;
/* iby=0; */
/* while (hhx[iby*nbetaY+nbetaY/2]<0 && iby<nbetaY/2) iby++; */
/* for (ib=0; ib<iby;ib++) { */
/* for (ibx=0; ibx<nbetaX;ibx++) */
/* hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby]; */
/* } */
while (hhx[iby*nbetaY+nbetaY/2]<0) iby--;
for (ib=iby+1; ib<nbetaY;ib++) {
for (ibx=0; ibx<nbetaX;ibx++)
hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby];
}
/* cout << "hhx low optimized" << endl; */
iby=0;
while (hhy[nbetaX/2*nbetaX+iby]<0) iby++;
for (ib=0; ib<iby;ib++) {
for (ibx=0; ibx<nbetaY;ibx++)
hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx];
}
iby=nbetaX-1;
/* iby=nbetaY-1; */
/* while (hhx[iby*nbetaY+nbetaY/2]<0 && iby>0) iby--; */
while (hhy[nbetaX/2*nbetaX+iby]<0) iby--;
for (ib=iby+1; ib<nbetaX;ib++) {
for (ibx=0; ibx<nbetaY;ibx++)
hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx];
}
/* for (ib=iby+1; ib<nbetaY;ib++) { */
/* for (ibx=0; ibx<nbetaX;ibx++){ */
/* cout << iby << " " << ib << " " << ibx << " " << ibx+nbetaX*ib << " " << ibx+nbetaX*iby << " " << nbetaX*nbetaY << endl; */
/* hhx[ibx+nbetaX*ib]=hhx[ibx+nbetaX*iby]; */
/* } */
/* } */
/* cout << "hhx high optimized" << endl; */
/* iby=0; */
/* while (hhy[nbetaX/2*nbetaX+iby]<0 && iby<nbetaX) iby++; */
/* for (ib=0; ib<iby;ib++) { */
/* for (ibx=0; ibx<nbetaY;ibx++) */
/* hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx]; */
/* } */
/* cout << "hhy low optimized" << endl; */
/* iby=nbetaX-1; */
/* while (hhy[nbetaX/2*nbetaX+iby]<0 && iby>) iby--; */
/* for (ib=iby+1; ib<nbetaX;ib++) { */
/* for (ibx=0; ibx<nbetaY;ibx++) */
/* hhy[ib+nbetaX*ibx]=hhy[iby+nbetaX*ibx]; */
/* } */
/* cout << "hhy high optimized" << endl; */
@ -180,7 +186,7 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
class eta2InterpolationPosXY : public virtual eta2InterpolationBase, public virtual etaInterpolationPosXY {
public:
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 " << nbetaX << " " << nbetaY << etamin << " " << etamax << " " << nSubPixelsX<< " " << nSubPixelsY << endl;
};
eta2InterpolationPosXY(eta2InterpolationPosXY *orig): etaInterpolationBase(orig), etaInterpolationPosXY(orig) {};
@ -189,12 +195,12 @@ class eta2InterpolationPosXY : public virtual eta2InterpolationBase, public virt
};
//
class eta3InterpolationPosXY : public virtual eta3InterpolationBase, public virtual etaInterpolationPosXY {
public:
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 " << nbetaX << " " << nbetaY << etamin << " " << etamax << " " << nSubPixelsX<< " " << nSubPixelsY << endl;
};
eta3InterpolationPosXY(eta3InterpolationPosXY *orig): etaInterpolationBase(orig), etaInterpolationPosXY(orig) {};

View File

@ -94,10 +94,7 @@ class slsInterpolation
//create interpolated image
//returns interpolated image
virtual int *getInterpolatedImage(){
// cout << "return interpolated image " << endl;
/* for (int i=0; i<nSubPixels* nSubPixels* nPixelsX*nPixelsY; i++) { */
/* cout << i << " " << hint[i] << endl; */
/* } */
//cout << "?" <<endl;
return hint;
};
@ -105,17 +102,21 @@ class slsInterpolation
void *writeInterpolatedImage(const char * imgname) {
//cout << "!" <<endl;
float *gm=NULL;
//cout << "!" <<endl;
int *dummy=getInterpolatedImage();
cout << "got interpolated image " << endl;
gm=new float[ nSubPixelsX* nSubPixelsY* nPixelsX*nPixelsY];
cout << "created dummy " << endl;
if (gm) {
for (int ix=0; ix<nPixelsX*nSubPixelsX; ix++) {
for (int iy=0; iy<nPixelsY*nSubPixelsY; iy++) {
gm[iy*nPixelsX*nSubPixelsX+ix]=dummy[iy*nPixelsX*nSubPixelsX+ix];
// cout << "++" << ix << " " << iy << " " << iy*nPixelsX*nSubPixelsX+ix << endl;
}
}
WriteToTiff(gm, imgname,nSubPixelsY* nPixelsX ,nSubPixelsY* nPixelsY);
WriteToTiff(gm, imgname,nSubPixelsX* nPixelsX ,nSubPixelsY* nPixelsY);
// cout << "wrote to tiff " << endl;
delete [] gm;
} else cout << "Could not allocate float image " << endl;
return NULL;
@ -188,6 +189,7 @@ class slsInterpolation
static int calcQuad(double *cl, double &sum, double &totquad, double sDum[2][2]){
//cout << "2";
int corner = UNDEFINED_QUADRANT;
/* double *cluster[3]; */
@ -368,6 +370,7 @@ class slsInterpolation
static int calcEta3(double *cl, double &etax, double &etay, double &sum) {
// cout << "3";
double l=0,r=0,t=0,b=0, val;
sum=0;
// int quad;
@ -375,10 +378,10 @@ class slsInterpolation
for (int iy=0; iy<3; iy++) {
val=cl[ix+3*iy];
sum+=val;
if (iy==0) l+=val;
if (iy==2) r+=val;
if (ix==0) b+=val;
if (ix==2) t+=val;
if (ix==0) l+=val;
if (ix==2) r+=val;
if (iy==0) b+=val;
if (iy==2) t+=val;
}
}
if (sum>0) {

View File

@ -17,22 +17,22 @@ all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolati
moenchClusterFinder : moench03ClusterFinder.cpp $(INCS) clean
g++ -o moenchClusterFinder moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) -DSAVE_ALL -DNEWRECEIVER
g++ -o moenchClusterFinder moench03ClusterFinder.cpp $(LDFLAG) $(INCDIR) -DSAVE_ALL -DNEWRECEIVER -DWRITE_QUAD
moenchMakeEta : moench03Interpolation.cpp $(INCS) clean
g++ -o moenchMakeEta moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF
g++ -o moenchMakeEta moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF -DWRITE_QUAD
moenchInterpolation : moench03Interpolation.cpp $(INCS) clean
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR)
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) -DWRITE_QUAD
moenchNoInterpolation : moench03NoInterpolation.cpp $(INCS) clean
g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR)
g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) -DWRITE_QUAD
moenchPhotonCounter : moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchPhotonCounter moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $ -DNEWRECEIVER
g++ -o moenchPhotonCounter moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $ -DNEWRECEIVER -DWRITE_QUAD
moenchAnalog : moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchAnalog moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) -DNEWRECEIVER -DANALOG
g++ -o moenchAnalog moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) -DNEWRECEIVER -DANALOG -DWRITE_QUAD
clean:
rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog

View File

@ -14,7 +14,12 @@
#include "single_photon_hit.h"
#endif
#ifdef RECT
#include "etaInterpolationGlobal.h"
#endif
#ifndef RECT
#include "etaInterpolationPosXY.h"
#endif
#include "noInterpolation.h"
//#include "etaInterpolationCleverAdaptiveBins.h"
//#include "etaInterpolationRandomBins.h"
@ -36,6 +41,7 @@ using namespace std;
int main(int argc, char *argv[]) {
#ifndef FF
cout << "INTERPOLATING" << endl;
if (argc<9) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile outfile runmin runmax ns cmin cmax" << endl;
return 1;
@ -43,6 +49,7 @@ int main(int argc, char *argv[]) {
#endif
#ifdef FF
cout << "CALC ETA" << endl;
if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile etafile runmin runmax cmin cmax" << endl;
return 1;
@ -74,11 +81,11 @@ int main(int argc, char *argv[]) {
cout << "Energy min: " << cmin << endl;
cout << "Energy max: " << cmax << endl;
//int etabins=500;
int etabins=1000;//nsubpix*2*100;
int etabins=999;//nsubpix*2*100;
int etabinsY=etabins;//nsubpix*2*100;
double etamin=-1, etamax=2;
double etamin=0, etamax=1;
//double etamin=-0.1, etamax=1.1;
double eta3min=-2, eta3max=2;
double eta3min=-1, eta3max=1;
int quad;
double sum, totquad;
double sDum[2][2];
@ -92,6 +99,9 @@ int main(int argc, char *argv[]) {
int nph=0, badph=0, totph=0;
FILE *f=NULL;
char fff[10000];
#ifdef DOUBLE_SPH
single_photon_hit_double cl(3,3);
#endif
@ -102,12 +112,23 @@ int main(int argc, char *argv[]) {
int nSubPixels=nsubpix;
int nSubPixelsY=nsubpix;
#ifdef RECT
nSubPixels=1; //might make more sense using 2?
etabins=2;
nSubPixels=5; //might make more sense using 2?
// etabins=5;
#endif
#ifndef NOINTERPOLATION
eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax);
etaInterpolationBase *interp;
#ifndef RECT
interp=new eta2InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, etamin, etamax);
//eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
#endif
#ifdef RECT
interp=new eta2InterpolationGlobal(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, eta3min, eta3max);
// eta3InterpolationPosXY *interpOdd=new eta3InterpolationPosXY(NC, NR, nSubPixels, nSubPixelsY, etabins, etabinsY, eta3min, eta3max);
//eta2InterpolationCleverAdaptiveBins *interp=new eta2InterpolationCleverAdaptiveBins(NC, NR, nsubpix, etabins, etamin, etamax);
#endif
#endif
#ifdef NOINTERPOLATION
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix, nSubPixelsY);
@ -119,8 +140,21 @@ int main(int argc, char *argv[]) {
#ifndef NOINTERPOLATION
cout << "read ff " << argv[2] << endl;
sprintf(fname,"%s",argv[2]);
//#ifndef RECT
interp->readFlatField(fname, etamin, etamax);
interp->prepareInterpolation(ok);//, MAX_ITERATIONS);
interp->debugSaveAll(0);
//#endif
// #ifdef RECT
// sprintf(fff,"%s.even",fname);
// interpEven->readFlatField(fff, etamin, etamax);
// interpEven->prepareInterpolation(ok);, MAX_ITERATIONS);
// interpEven->debugSaveAll(1);
// sprintf(fff,"%s.odd",fname);
// interpOdd->readFlatField(fff, etamin, etamax);
// interpOdd->prepareInterpolation(ok);, MAX_ITERATIONS);
// interpOdd->debugSaveAll(2);
// #endif
#endif
// return 0;
#endif
@ -144,6 +178,9 @@ int main(int argc, char *argv[]) {
sprintf(outfname,argv[2]);
#endif
int tl=0, tr=0, bl=0, br=0;
int irun;
for (irun=runmin; irun<runmax; irun++) {
sprintf(infname,argv[1],irun);
@ -164,53 +201,80 @@ int main(int argc, char *argv[]) {
if (nframes==0) f0=lastframe;
nframes++;
}
#ifdef RECT
// quad=interp->calcEta3(cl.get_cluster(), etax, etay, sum);
quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
nph++;
// if (sum>200 && sum<580) {
// interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y);
// #ifdef SOLEIL
// if (cl.x>210 && cl.x<240 && cl.y>210 && cl.y<240) {
// #endif
#ifndef FF
// 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);
// cout <<"**************"<< endl;
// cout << cl.x << " " << cl.y << " " << sum << endl;
// cl.print();
// cout << int_x << " " << int_y << endl;
// cout <<"**************"<< endl;
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToImage(int_x, int_y);
if (int_x<0 || int_y<0 || int_x>NC || int_y>NR) {
cout <<"**************"<< endl;
cout << cl.x << " " << cl.y << " " << sum << endl;
cl.print();
cout << int_x << " " << int_y << endl;
cout <<"**************"<< endl;
}
#endif
#ifdef FF
// interp->addToFlatField(cl.get_cluster(), etax, etay);
// #ifdef UCL
// if (cl.x>50)
// #endif
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToFlatField(etax, etay);
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y << endl;
// if (cl.y%2==0)
// if (etay>0)
// interp=interpEven;
// else
// interp=interpOdd;
// else
// if (etay>0)
// interp=interpOdd;
// else
// interp=interpEven;
#endif
// #ifdef SOLEIL
// }
// #endif
#ifndef RECT
quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
#endif
switch(quad) {
case TOP_LEFT:
tl++;
break;
case TOP_RIGHT:
tr++;
break;
case BOTTOM_LEFT:
bl++;
break;
case BOTTOM_RIGHT:
br++;
break;
}
// if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
if (sum>cmin && sum<cmax ) {
nph++;
#ifndef FF
interp->getInterpolatedPosition(cl.x,cl.y, etax, etay, quad,int_x, int_y);
interp->addToImage(int_x, int_y);
#endif
#ifdef FF
interp->addToFlatField(etax, etay);
#endif
if (nph%1000000==0) cout << nph << endl;
if (nph%10000000==0) {
#ifndef FF
cout << "writing interpolated iamge" << endl;
//#ifndef RECT
interp->writeInterpolatedImage(outfname);
//#endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeInterpolatedImage(fff);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeInterpolatedImage(fff);
// #endif
cout << "done" << endl;
#endif
#ifdef FF
cout << "writing eta" << endl;
//#ifndef RECT
interp->writeFlatField(outfname);
//#endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeFlatField(fff);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeFlatField(fff);
// #endif
cout << "done" << endl;
#endif
}
@ -221,24 +285,64 @@ int main(int argc, char *argv[]) {
fclose(f);
#ifdef FF
//#ifndef RECT
interp->writeFlatField(outfname);
// #endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeFlatField(outfname);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeFlatField(outfname);
// #endif
#endif
#ifndef FF
//#ifndef RECT
interp->writeInterpolatedImage(outfname);
// #endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeInterpolatedImage(fff);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeInterpolatedImage(fff);
// #endif
//#ifdef RECT
//interp=interpEven;
//#endif
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++) {
totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
// cout << "--" << ix << " " << iy <<" " << ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels) << endl;
}
}
}
}
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl;
cout << "Top-Left=" << tl << " " << " Top-Right=" << tr << " Bottom-Left="<< bl << " Bottom-Right=" << br << endl;
interp->clearInterpolatedImage();
// #ifdef RECT
// interp=interpOdd;
// 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++) {
// totimg[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)]+=img[ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels)];
// // cout << "--" << ix << " " << iy <<" " << ix*nSubPixels+isx+(iy*nSubPixelsY+isy)*(NC*nSubPixels) << endl;
// }
// }
// }
// }
// interp->clearInterpolatedImage();
// #endif
#endif
} else
@ -250,7 +354,15 @@ int main(int argc, char *argv[]) {
#endif
#ifdef FF
//#ifndef RECT
interp->writeFlatField(outfname);
//#endif
// #ifdef RECT
// sprintf(fff,"%s.even",outfname);
// interpEven->writeFlatField(fff);
// sprintf(fff,"%s.odd",outfname);
// interpOdd->writeFlatField(fff);
// #endif
#endif
cout << "Filled " << nph << " (/"<< totph <<") " << endl;