formatted slsDetectorCalibration

This commit is contained in:
Erik Frojdh
2022-01-24 11:26:56 +01:00
parent 623b1de8a0
commit c554bbb2d3
77 changed files with 15998 additions and 15890 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,25 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include <iostream>
#include <TGraph.h>
#include <TAxis.h>
#include <TMultiGraph.h>
#include <TBuffer.h>
#include <TGraph.h>
#include <TH2D.h>
#include <TMath.h>
#include <TMultiGraph.h>
#include <TObject.h>
#include <TBuffer.h>
#include <iostream>
#include <TMatrixD.h>
#include <TDecompSVD.h>
//#include <TDecompQRH.h>
#include <TH1.h>
#include <TMath.h>
#include <vector>
#include <ostream>
#include <istream>
#include <ostream>
using namespace std;
@ -28,139 +27,133 @@ using namespace std;
#define ETAVPS
typedef struct {
int itN;
double *xPos;
double *yPos;
double *binCont;
int itN;
double *xPos;
double *yPos;
double *binCont;
} itLog;
class EtaVEL : public TObject {
public:
EtaVEL(int numberOfPixels = 25, double minn = 0., double maxx = 1.,
int nnx = 160, int nny = 160)
: nPixels(numberOfPixels), min(minn), max(maxx), converged(0), nx(nnx),
ny(nny), chi_sq(0) {
// acc = 0.02;
ds = 0.005;
class EtaVEL : public TObject{
init();
}
void init() {
double pOffset = (max - min) / (double)nPixels;
xPPos = new double[(nPixels + 1) * (nPixels + 1) + 1];
yPPos = new double[(nPixels + 1) * (nPixels + 1) + 1];
binCont = new double[nPixels * nPixels + 1];
totCont = 0.;
edgeL = new double[2 * nPixels * (nPixels + 1) + 1];
public:
EtaVEL(int numberOfPixels = 25, double minn=0., double maxx=1., int nnx=160, int nny=160) : nPixels(numberOfPixels), min(minn), max(maxx), converged(0), nx(nnx), ny(nny), chi_sq(0){
//acc = 0.02;
ds = 0.005;
init();
}
void init(){
double pOffset = (max-min)/(double)nPixels;
xPPos = new double[(nPixels+1)*(nPixels+1)+1];
yPPos = new double[(nPixels+1)*(nPixels+1)+1];
binCont = new double[nPixels*nPixels+1];
totCont = 0.;
edgeL = new double[2*nPixels*(nPixels+1)+1];
for (int ii = 0; ii < 2 * nPixels * (nPixels + 1) + 1; ii++) {
edgeL[ii] = 1.0;
// cout << "ii " << ii << endl;
}
for(int ii = 0; ii < 2*nPixels*(nPixels+1)+1; ii++){
edgeL[ii] = 1.0;
//cout << "ii " << ii << endl;
for (int x = 0; x < nPixels + 1; x++) {
for (int y = 0; y < nPixels + 1; y++) {
xPPos[getCorner(x, y)] = min + (double)x * pOffset;
yPPos[getCorner(x, y)] = min + (double)y * pOffset;
if (x < nPixels && y < nPixels)
binCont[getBin(x, y)] = 0;
}
}
// edgeL[1] = 3.0;
updatePixelCorner();
it = 0;
log = new itLog[nIterations];
}
for(int x = 0; x < nPixels+1; x++){
for(int y = 0; y < nPixels+1; y++){
xPPos[getCorner(x,y)] = min + (double)x * pOffset;
yPPos[getCorner(x,y)] = min + (double)y * pOffset;
if(x < nPixels && y < nPixels) binCont[getBin(x,y)] = 0;
}
void fill(double x, double y, double amount = 1.) {
totCont += amount;
int bin = findBin(x, y);
if (bin < 0) {
// cout << "can not find bin x: " << x << " y: " << y << endl;
totCont -= amount;
}
binCont[bin] += amount;
}
// edgeL[1] = 3.0;
updatePixelCorner();
it = 0;
log = new itLog[nIterations];
}
void fill(double x, double y, double amount = 1.){
totCont+=amount;
int bin = findBin(x,y);
if(bin < 0) {
//cout << "can not find bin x: " << x << " y: " << y << endl;
totCont-=amount;
int getBin(int x, int y) {
if (x < 0 || x >= nPixels || y < 0 || y >= nPixels) {
// cout << "getBin: out of bounds : x " << x << " y " << y << endl;
return 0;
}
return y * nPixels + x + 1;
}
binCont[bin]+=amount;
}
int getBin(int x, int y){
if(x < 0 || x >= nPixels || y < 0 || y >= nPixels){
//cout << "getBin: out of bounds : x " << x << " y " << y << endl;
return 0;
int getXBin(int bin) { return (bin - 1) % nPixels; }
int getYBin(int bin) { return (bin - 1) / nPixels; }
int getCorner(int x, int y) { return y * (nPixels + 1) + x + 1; }
int getEdgeX(int x, int row) {
int ret = row * nPixels + x + 1;
// cout << "| edge X x " << x << " row " << row << ": "<< ret << " | ";
return ret;
}
return y*nPixels+x+1;
}
int getXBin(int bin){
return (bin-1)%nPixels;
}
int getYBin(int bin){
return (bin-1)/nPixels;
}
int getEdgeY(int col, int y) {
int ret = nPixels * (nPixels + 1) + col * nPixels + y + 1;
// cout << "| edge Y col " << col << " y " << y << ": "<< ret << " | ";
return ret;
}
int getCorner(int x, int y){
return y*(nPixels+1)+x+1;
}
int getIt() { return it; };
int getEdgeX(int x,int row){
int ret = row*nPixels+x+1;
//cout << "| edge X x " << x << " row " << row << ": "<< ret << " | ";
return ret;
}
int getNPixels() { return nPixels; }
double *getXPPos() { return xPPos; }
double *getYPPos() { return yPPos; }
int getEdgeY(int col, int y){
int ret = nPixels*(nPixels+1)+col*nPixels+y+1;
//cout << "| edge Y col " << col << " y " << y << ": "<< ret << " | ";
return ret;
}
void updatePixelCorner();
double *getPixelCorners(int x, int y);
int findBin(double xx, double yy);
void createLogEntry();
int getIt(){ return it; };
void updatePixelPos();
double *getSizeMap();
double *getChangeMap();
TH2D *getContent(int it = -1, int changeType = 0);
TMultiGraph *plotPixelBorder(int plotCenters = 0);
TMultiGraph *plotLog(int stepSize = 1, int maxIt = -1);
void printGrid();
TH1D *getCounts();
int getNPixels(){ return nPixels; }
double *getXPPos(){ return xPPos; }
double *getYPPos(){ return yPPos; }
void serialize(ostream &o);
void deserialize(istream &is);
void updatePixelCorner();
double *getPixelCorners(int x, int y);
int findBin(double xx, double yy);
void createLogEntry();
void updatePixelPos();
double *getSizeMap();
double *getChangeMap();
TH2D *getContent(int it=-1, int changeType = 0);
TMultiGraph *plotPixelBorder(int plotCenters=0);
TMultiGraph *plotLog(int stepSize=1, int maxIt=-1);
void printGrid();
TH1D *getCounts();
int converged;
double getChiSq() { return chi_sq; };
void serialize(ostream &o);
void deserialize(istream &is);
private:
itLog *log;
int it;
const static int nIterations = 10000;
int nx, ny;
int nPixels;
double *xPPos;
double *yPPos;
double *binCont;
double totCont;
double *edgeL;
// double acc;
double ds;
double min, max;
double chi_sq;
int converged ;
double getChiSq(){return chi_sq;};
private:
itLog *log;
int it;
const static int nIterations =10000;
int nx, ny;
int nPixels;
double *xPPos;
double *yPPos;
double *binCont;
double totCont;
double *edgeL;
// double acc;
double ds;
double min,max;
double chi_sq;
ClassDefNV(EtaVEL,1);
#pragma link C++ class EtaVEL-;
ClassDefNV(EtaVEL, 1);
#pragma link C++ class EtaVEL - ;
};
#endif

View File

@ -1,136 +1,144 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "interpolation_EtaVEL.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TH2F.h"
#include "TROOT.h"
#include "interpolation_EtaVEL.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.
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(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;
delete newEta;
delete heta;
}
void interpolation_EtaVEL::prepareInterpolation(int &ok, int maxit) {
int nit=0;
while ((newEta->converged != 1) && nit++<maxit) {
cout << " -------------- new step "<< nit << endl;
iterate();
}
if (plot) {
Draw();
gPad->Modified();
gPad->Update();
}
if (newEta->converged==1) ok=1; else ok=0;
int nit = 0;
while ((newEta->converged != 1) && nit++ < maxit) {
cout << " -------------- new step " << nit << endl;
iterate();
}
if (plot) {
Draw();
gPad->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 *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;
// newEta->fill(etaX,etaY);
heta->Fill(etax, etay);
return 0;
}
void interpolation_EtaVEL::iterate() {
cout << " -------------- newEta refilled"<< endl;
for (int ibx=0; ibx<heta->GetNbinsX(); ibx++) {
for (int iby=0; iby<heta->GetNbinsY(); 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;
cout << " -------------- newEta refilled" << endl;
for (int ibx = 0; ibx < heta->GetNbinsX(); ibx++) {
for (int iby = 0; iby < heta->GetNbinsY(); 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();
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) {
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];
Double_t etax, etay, sum, totquad, sDum[2][2];
int corner = calcEta(cluster, etax, etay, sum, totquad, sDum);
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;
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) {
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);
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);
};

View File

@ -3,55 +3,61 @@
#ifndef INTERPOLATION_ETAVEL_H
#define INTERPOLATION_ETAVEL_H
#include <slsInterpolation.h>
#include "EtaVEL.h"
#include <slsInterpolation.h>
//#include "TH2F.h"
//#include "EtaVEL.cpp"
//class EtaVEL;
// class EtaVEL;
class etaVELInterpolation: public etaInterpolationBase {
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);
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 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);
// 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
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;};
// 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(); };
// 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;
protected:
EtaVEL *newEta;
// TH2F *heta;
int plot;
// ClassDefNV(interpolation_EtaVEL,1);
// #pragma link C++ class interpolation_EtaVEL-;
// ClassDefNV(interpolation_EtaVEL,1);
// #pragma link C++ class interpolation_EtaVEL-;
};
#endif