diff --git a/slsDetectorCalibration/interpolations/etaVEL/etaVELInterpolation.cpp b/slsDetectorCalibration/interpolations/etaVEL/etaVELInterpolation.cpp new file mode 100644 index 000000000..1cdd3c718 --- /dev/null +++ b/slsDetectorCalibration/interpolations/etaVEL/etaVELInterpolation.cpp @@ -0,0 +1,134 @@ +#include "interpolation_EtaVEL.h" +#include "TH2F.h" +#include "TCanvas.h" +#include "TROOT.h" +//#include "EtaVEL.h" +#include "EtaVEL.cpp" +/* +Zum erstellen der correction map ist createGainAndEtaFile(...) in EVELAlg.C der entry point. +Zum erstellen des HR images ist createImage(...) der entry point. +*/ +interpolation_EtaVEL::interpolation_EtaVEL(int nx, int ny, int ns, double etamin, double etamax, int p) : slsInterpolation(nx, ny, ns), newEta(NULL), heta(NULL), plot(p) { + newEta = new EtaVEL(nSubPixels,etamin,etamax,nPixelsX, nPixelsY); + heta= new TH2F("heta","heta",50*nSubPixels, etamin,etamax,50*nSubPixels, etamin,etamax); + heta->SetStats(kFALSE); +} + +interpolation_EtaVEL::~interpolation_EtaVEL() { + delete newEta; + delete heta; +} + + +void interpolation_EtaVEL::prepareInterpolation(int &ok, int maxit) { + int nit=0; + while ((newEta->converged != 1) && nit++Modified(); + gPad->Update(); + } + if (newEta->converged==1) ok=1; else ok=0; +} + +int interpolation_EtaVEL::addToFlatField(Double_t *cluster, Double_t &etax, Double_t &etay) { + Double_t sum, totquad, sDum[2][2]; + int corner =calcEta(cluster, etax, etay, sum, totquad, sDum); + //check if it's OK...should redo it every time? + //or should we fill a finer histogram and afterwards re-fill the newEta? + addToFlatField(etax, etay); + return corner; +} + +int interpolation_EtaVEL::addToFlatField(Double_t etax, Double_t etay) { + // newEta->fill(etaX,etaY); + heta->Fill(etax,etay); + return 0; +} + +void interpolation_EtaVEL::iterate() { + cout << " -------------- newEta refilled"<< endl; + for (int ibx=0; ibxGetNbinsX(); ibx++) { + for (int iby=0; ibyGetNbinsY(); iby++) { + newEta->fill(heta->GetXaxis()->GetBinCenter(ibx+1),heta->GetYaxis()->GetBinCenter(iby+1),heta->GetBinContent(ibx+1,iby+1)); + } + } + newEta->updatePixelPos(); + cout << " -------------- pixelPosition updated"<< endl; +} + +void interpolation_EtaVEL::DrawH() { + heta->Draw("col"); + (newEta->plotPixelBorder())->Draw(); +} + + +void interpolation_EtaVEL::getInterpolatedPosition(Int_t x, Int_t y, Double_t *cluster, Double_t &int_x, Double_t &int_y) { + + Double_t etax, etay, sum, totquad, sDum[2][2]; + + int corner =calcEta(cluster, etax, etay, sum, totquad, sDum); + + int bin = newEta->findBin(etax,etay); + if (bin<=0) { + int_x=-1; + int_y=-1; + return; + } + double subX = ((double)(newEta->getXBin(bin))+.5)/((double)newEta->getNPixels()); + double subY = ((double)(newEta->getYBin(bin))+.5)/((double)newEta->getNPixels()); + + double dX, dY; + switch (corner) { + case TOP_LEFT: + dX=-1.; + dY=+1.; + break; + case TOP_RIGHT: + dX=+1.; + dY=+1.; + break; + case BOTTOM_LEFT: + dX=-1.; + dY=-1.; + break; + case BOTTOM_RIGHT: + dX=+1.; + dY=-1.; + break; + default: + dX=0; + dY=0; + } + + int_x=((double)x)+ subX+0.5*dX; + int_y=((double)y)+ subY+0.5*dY; + + // cout << corner << " " << subX<< " " << subY << " " << dX << " " << dY << " " << int_x << " " << int_y << endl; + +}; + + +// void interpolation_EtaVEL::Streamer(TBuffer &b){newEta->Streamer(b);}; +void interpolation_EtaVEL::getInterpolatedBin(Double_t *cluster, Int_t &int_x, Int_t &int_y) { + + Double_t etax, etay, sum, totquad, sDum[2][2]; + + int corner =calcEta(cluster, etax, etay, sum, totquad, sDum); + + int bin = newEta->findBin(etax,etay); + if (bin<0) { + int_x=-1; + int_y=-1; + return; + } + int_x=newEta->getXBin(bin); + int_y=newEta->getYBin(bin); + + + +}; + diff --git a/slsDetectorCalibration/interpolations/etaVEL/etaVELInterpolation.h b/slsDetectorCalibration/interpolations/etaVEL/etaVELInterpolation.h new file mode 100644 index 000000000..8fbacf96d --- /dev/null +++ b/slsDetectorCalibration/interpolations/etaVEL/etaVELInterpolation.h @@ -0,0 +1,55 @@ +#ifndef INTERPOLATION_ETAVEL_H +#define INTERPOLATION_ETAVEL_H + +#include +#include "EtaVEL.h" +//#include "TH2F.h" +//#include "EtaVEL.cpp" +//class EtaVEL; + +class etaVELInterpolation: public etaInterpolationBase { + + public: + interpolation_EtaVEL(int nx=40, int ny=160, int ns=25, double etamin=-0.02, double etamax=1.02, int p=0); + ~interpolation_EtaVEL(); + + + //create eta distribution, eta rebinnining etc. + //returns flat field image + void prepareInterpolation(int &ok){prepareInterpolation(ok,10000);}; + void prepareInterpolation(int &ok, int maxit); + + //create interpolated image + //returns interpolated image + + //return position inside the pixel for the given photon + void getInterpolatedPosition(Int_t x, Int_t y, Double_t *data, Double_t &int_x, Double_t &int_y); + void getInterpolatedBin(Double_t *cluster, Int_t &int_x, Int_t &int_y); + + + + int addToFlatField(Double_t *cluster, Double_t &etax, Double_t &etay); + int addToFlatField(Double_t etax, Double_t etay); + int setPlot(int p=-1) {if (p>=0) plot=p; return plot;}; + // int WriteH(){newEta->Write("newEta"); heta->Write("heta");}; + EtaVEL *setEta(EtaVEL *ev){if (ev) {delete newEta; newEta=ev;} return newEta;}; + + + + // TH2F *setEta(TH2F *ev){if (ev) {delete heta; heta=ev;} return heta;}; + void iterate(); + // void DrawH(); + double getChiSq(){return newEta->getChiSq();}; + + + + protected: + EtaVEL *newEta; + // TH2F *heta; + int plot; + + // ClassDefNV(interpolation_EtaVEL,1); + // #pragma link C++ class interpolation_EtaVEL-; +}; + +#endif