mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 08:10:02 +02:00
Merge remote branch 'slsDetectorCalibration/developer' into developer
This commit is contained in:
commit
5958cf9278
2
slsDetectorCalibration/.gitignore
vendored
Normal file
2
slsDetectorCalibration/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.o
|
||||
*.*~
|
156
slsDetectorCalibration/MovingStat.h
Executable file
156
slsDetectorCalibration/MovingStat.h
Executable file
@ -0,0 +1,156 @@
|
||||
#ifndef MOVINGSTAT_H
|
||||
#define MOVINGSTAT_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
class MovingStat
|
||||
{
|
||||
|
||||
/** @short approximated moving average structure */
|
||||
public:
|
||||
|
||||
|
||||
/** constructor
|
||||
\param nn number of samples parameter to be used
|
||||
*/
|
||||
MovingStat(int nn=1000) : n(nn), m_n(0) {}
|
||||
|
||||
/**
|
||||
clears the moving average number of samples parameter, mean and standard deviation
|
||||
*/
|
||||
void Clear()
|
||||
{
|
||||
m_n = 0;
|
||||
m_newM=0;
|
||||
m_newM2=0;
|
||||
}
|
||||
|
||||
/**
|
||||
clears the moving average number of samples parameter, mean and standard deviation
|
||||
*/
|
||||
void Set(double val, double rms=0, int m=-1)
|
||||
{
|
||||
if (m>=0) m_n = m; else m_n = n;
|
||||
m_newM=val*m_n;
|
||||
SetRMS(rms);
|
||||
}
|
||||
/**
|
||||
clears the moving average number of samples parameter, mean and standard deviation
|
||||
*/
|
||||
void SetRMS(double rms)
|
||||
{
|
||||
if (rms<=0) {
|
||||
m_newM2=m_newM*m_newM/n;
|
||||
m_n=0;
|
||||
} else {
|
||||
if (m_n>0)
|
||||
m_newM2=(m_n*rms*rms+m_newM*m_newM/m_n);
|
||||
else {
|
||||
m_newM2=(m_n*rms*rms+m_newM*m_newM/n);
|
||||
m_n=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** sets number of samples parameter
|
||||
\param i number of samples parameter to be set
|
||||
*/
|
||||
|
||||
int SetN(int i) {if (i>=1) n=i; return n;};
|
||||
|
||||
/**
|
||||
gets number of samples parameter
|
||||
\returns actual number of samples parameter
|
||||
*/
|
||||
int GetN() {return m_n;};
|
||||
|
||||
/** calculates the moving average i.e. adds if number of elements is lower than number of samples parameter, pushes otherwise
|
||||
\param x value to calculate the moving average
|
||||
*/
|
||||
inline void Calc(double x) {
|
||||
if (m_n<n) Add(x);
|
||||
else Push(x);
|
||||
}
|
||||
/** adds the element to the accumulated average and standard deviation
|
||||
\param x value to add
|
||||
*/
|
||||
inline void Add(double x) {
|
||||
m_n++;
|
||||
|
||||
if (m_n == 1)
|
||||
{
|
||||
m_newM = x;
|
||||
m_newM2 = x*x;
|
||||
} else {
|
||||
m_newM = m_newM + x;
|
||||
m_newM2 = m_newM2 + x*x;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void Push(double x)
|
||||
{
|
||||
/** adds the element to the accumulated average and squared mean, while subtracting the current value of the average and squared average
|
||||
\param x value to push
|
||||
*/
|
||||
if (m_n == 0)
|
||||
{
|
||||
m_newM = x;
|
||||
m_newM2 = x*x;
|
||||
m_n++;
|
||||
} else {
|
||||
m_newM = m_newM + x - m_newM/m_n;
|
||||
m_newM2 = m_newM2 + x*x - m_newM2/m_n;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** returns the current number of elements of the moving average
|
||||
\returns returns the current number of elements of the moving average
|
||||
*/
|
||||
int NumDataValues() const
|
||||
{
|
||||
return m_n;
|
||||
}
|
||||
/** returns the mean, 0 if no elements are inside
|
||||
\returns returns the mean
|
||||
*/
|
||||
inline double Mean() const
|
||||
{
|
||||
return (m_n > 0) ? m_newM/m_n : 0.0;
|
||||
}
|
||||
|
||||
/** returns the squared mean, 0 if no elements are inside
|
||||
\returns returns the squared average
|
||||
*/
|
||||
double M2() const
|
||||
{
|
||||
return ( (m_n > 1) ? m_newM2/m_n : 0.0 );
|
||||
}
|
||||
|
||||
/** returns the variance, 0 if no elements are inside
|
||||
\returns returns the variance
|
||||
*/
|
||||
inline double Variance() const
|
||||
{
|
||||
return ( (m_n > 1) ? (M2()-Mean()*Mean()) : 0.0 );
|
||||
}
|
||||
|
||||
/** returns the standard deviation, 0 if no elements are inside
|
||||
\returns returns the standard deviation
|
||||
*/
|
||||
inline double StandardDeviation() const
|
||||
{
|
||||
return ( (Variance() > 0) ? sqrt( Variance() ) : -1 );
|
||||
}
|
||||
|
||||
private:
|
||||
int n; /**< number of samples parameter */
|
||||
int m_n; /**< current number of elements */
|
||||
double m_newM; /**< accumulated average */
|
||||
double m_newM2; /**< accumulated squared average */
|
||||
};
|
||||
#endif
|
55
slsDetectorCalibration/RunningStat.h
Executable file
55
slsDetectorCalibration/RunningStat.h
Executable file
@ -0,0 +1,55 @@
|
||||
class RunningStat
|
||||
{
|
||||
public:
|
||||
RunningStat() : m_n(0) {}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_n = 0;
|
||||
}
|
||||
|
||||
void Push(double x)
|
||||
{
|
||||
m_n++;
|
||||
|
||||
// See Knuth TAOCP vol 2, 3rd edition, page 232
|
||||
if (m_n == 1)
|
||||
{
|
||||
m_oldM = m_newM = x;
|
||||
m_oldS = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_newM = m_oldM + (x - m_oldM)/m_n;
|
||||
m_newS = m_oldS + (x - m_oldM)*(x - m_newM);
|
||||
|
||||
// set up for next iteration
|
||||
m_oldM = m_newM;
|
||||
m_oldS = m_newS;
|
||||
}
|
||||
}
|
||||
|
||||
int NumDataValues() const
|
||||
{
|
||||
return m_n;
|
||||
}
|
||||
|
||||
double Mean() const
|
||||
{
|
||||
return (m_n > 0) ? m_newM : 0.0;
|
||||
}
|
||||
|
||||
double Variance() const
|
||||
{
|
||||
return ( (m_n > 1) ? m_newS/(m_n - 1) : 0.0 );
|
||||
}
|
||||
|
||||
double StandardDeviation() const
|
||||
{
|
||||
return sqrt( Variance() );
|
||||
}
|
||||
|
||||
private:
|
||||
int m_n;
|
||||
double m_oldM, m_newM, m_oldS, m_newS;
|
||||
};
|
866
slsDetectorCalibration/analogDetector.h
Normal file
866
slsDetectorCalibration/analogDetector.h
Normal file
@ -0,0 +1,866 @@
|
||||
#ifndef ANALOGDETECTOR_H
|
||||
#define ANALOGDETECTOR_H
|
||||
|
||||
//#include <mutex>
|
||||
|
||||
#include <pthread.h>
|
||||
#include "slsDetectorData.h"
|
||||
#include "pedestalSubtraction.h"
|
||||
#include "commonModeSubtraction.h"
|
||||
#include "tiffIO.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef FRAMEMODE_DEF
|
||||
#define FRAMEMODE_DEF
|
||||
/**
|
||||
enum to define the flags of the data set, which are needed to seect the type of processing it should undergo: frame, pedestal, flat
|
||||
*/
|
||||
enum frameMode { eFrame, ePedestal, eFlat };
|
||||
#endif
|
||||
|
||||
|
||||
template <class dataType> class analogDetector {
|
||||
|
||||
/** @short class to perform pedestal subtraction etc. for an analog detector */
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param d detector data structure to be used - if null it is assumed that the data are in ordered ip=iy*nx+ix
|
||||
\param sign is the sign of the data
|
||||
\param nped number of samples for pedestal averaging
|
||||
\param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none
|
||||
\param nnx detector size in x - must be specified if no data structure is defined, otherwise defaults to the size of the data structure.
|
||||
\param nny detector size in y - must be specified if no data structure is defined, otherwise defaults to the size of the data structure.
|
||||
\param gm pointer to tha gain map matrix
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
analogDetector(slsDetectorData<dataType> *d, int sign=1,
|
||||
commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), iframe(-1), dataSign(sign), gmap(gm), id(0) {
|
||||
|
||||
if (det)
|
||||
det->getDetectorSize(nx,ny);
|
||||
|
||||
stat=new pedestalSubtraction*[ny];
|
||||
for (int i=0; i<ny; i++) {
|
||||
stat[i]=new pedestalSubtraction[nx];
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
stat[i][ix].SetNPedestals(nped);
|
||||
}
|
||||
}
|
||||
image=new int[nx*ny];
|
||||
xmin=0;
|
||||
xmax=nx;
|
||||
ymin=0;
|
||||
ymax=ny;
|
||||
fMode=ePedestal;
|
||||
thr=0;
|
||||
myFile=NULL;
|
||||
fm=new pthread_mutex_t ;
|
||||
};
|
||||
/**
|
||||
destructor. Deletes the pdestalSubtraction array and the image
|
||||
*/
|
||||
virtual ~analogDetector() {for (int i=0; i<ny; i++) delete [] stat[i]; delete [] stat; delete [] image;};
|
||||
|
||||
/**
|
||||
constructor cloning another analog detector
|
||||
\param orig analog Detector structure to be cloned
|
||||
*/
|
||||
analogDetector(analogDetector* orig) {
|
||||
/* copy construction from orig*/
|
||||
det=orig->det;
|
||||
nx=orig->nx;
|
||||
ny=orig->ny;
|
||||
dataSign=orig->dataSign;
|
||||
iframe=orig->iframe;
|
||||
gmap=orig->gmap;
|
||||
cmSub=orig->cmSub;
|
||||
id=orig->id;
|
||||
xmin=orig->xmin;
|
||||
xmax=orig->xmax;
|
||||
ymin=orig->ymin;
|
||||
ymax=orig->ymax;
|
||||
thr=orig->thr;
|
||||
// nSigma=orig->nSigma;
|
||||
fMode=orig->fMode;
|
||||
myFile=orig->myFile;
|
||||
fm=orig->fm;
|
||||
|
||||
|
||||
stat=new pedestalSubtraction*[ny];
|
||||
for (int i=0; i<ny; i++) {
|
||||
stat[i]=new pedestalSubtraction[nx];
|
||||
}
|
||||
|
||||
int nped=orig->SetNPedestals();
|
||||
//cout << nped << " " << orig->getPedestal(ix,iy) << orig->getPedestalRMS(ix,iy) << endl;
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
stat[iy][ix].SetNPedestals(nped);
|
||||
setPedestal(ix,iy,orig->getPedestal(ix,iy),orig->getPedestalRMS(ix,iy),orig->GetNPedestals(ix,iy));
|
||||
}
|
||||
}
|
||||
image=new int[nx*ny];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
clone. Must be virtual!
|
||||
\returns a clone of the original analog detector
|
||||
*/
|
||||
virtual analogDetector *Clone() {
|
||||
return new analogDetector(this);
|
||||
}
|
||||
|
||||
/**
|
||||
Gives an id to the structure. For debugging purposes in case of multithreading.
|
||||
\param i is to be set
|
||||
\returns current id
|
||||
*/
|
||||
int setId(int i){id=i; return id;};
|
||||
|
||||
/**
|
||||
Returns id of the structure. For debugging purposes in case of multithreading.
|
||||
\returns current id
|
||||
*/
|
||||
int getId() {return id; };
|
||||
/**
|
||||
Returns data size of the detector data structure
|
||||
\returns data size of the detector data structurein bytes
|
||||
*/
|
||||
int getDataSize(){return det->getDataSize();};
|
||||
/**
|
||||
Returns data size of the detector image matrix
|
||||
\param nnx reference to image size in x
|
||||
\param nny reference to image size in y
|
||||
\param nns reference to number of subpixels for interpolating detector, will always be 1 in this case
|
||||
\returns number of pixels of the detector image
|
||||
*/
|
||||
virtual int getImageSize(int &nnx, int &nny, int &nns){nnx=nx; nny=ny; nns=1; return nx*ny;};
|
||||
/**
|
||||
Returns data size of the detector image matrix
|
||||
\param nnx reference to pixel size in x
|
||||
\param nny reference to pixel size in y
|
||||
\returns number of pixels of the detector image
|
||||
*/
|
||||
virtual int getDetectorSize(int &nnx, int &nny){nnx=nx; nny=ny; return nx*ny;};
|
||||
|
||||
/**
|
||||
set gain map
|
||||
\param gm pointer to gain map matrix to be set - NULL unsets
|
||||
\returns pointer to current gain map
|
||||
*/
|
||||
double *setGainMap(double *gm) {gmap=gm; return gmap;};
|
||||
|
||||
/**
|
||||
return gain map
|
||||
\returns pointer to current gain map
|
||||
*/
|
||||
double *getGainMap() {return gmap;};
|
||||
/**
|
||||
reads a 32 bit tiff file of the size of the detector and sets its values as gain map for the detector. If file does not exist returns NULL, but does not change gainmap compared to previous settings.
|
||||
\param imgname complete name of the file containing the gain map data
|
||||
\returns pointer to current gain map is file reading succeeded, NULL is file reading didn't work.
|
||||
*/
|
||||
double *readGainMap(const char * imgname) {
|
||||
uint32 nnx, nny;
|
||||
float *gm=ReadFromTiff( imgname, nny, nnx);
|
||||
if (gm) {
|
||||
if (gmap) delete [] gmap;
|
||||
gmap=new double[nnx*nny];
|
||||
for (int ix=0; ix<nnx; ix++) {
|
||||
for (int iy=0; iy<nny; iy++) {
|
||||
gmap[iy*nnx+ix]=gm[iy*nnx+ix];
|
||||
}
|
||||
}
|
||||
return gmap;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/**
|
||||
writes a 32 bit tiff file of the size of the detector and contaning the gain map value, if any. If file doesn'e exist or gainmap is undefined, does not do anything.
|
||||
\param imgname complete name of the file to be written
|
||||
\returns NULL if file writing didn't succeed, else a pointer
|
||||
*/
|
||||
void *writeGainMap(const char * imgname) {
|
||||
float *gm=NULL;
|
||||
void *ret;
|
||||
if (gmap) {
|
||||
gm=new float[nx*ny];
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
gm[iy*nx+ix]=gmap[iy*nx+ix];
|
||||
}
|
||||
}
|
||||
ret=WriteToTiff(gm, imgname, ny, nx);
|
||||
delete [] gm;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/** resets the pedestalSubtraction array, the commonModeSubtraction and the image data*/
|
||||
|
||||
virtual void newDataSet(){
|
||||
iframe=-1;
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
stat[iy][ix].Clear();
|
||||
image[iy*nx+ix]=0;
|
||||
}
|
||||
if (cmSub) cmSub->Clear();
|
||||
};
|
||||
|
||||
/** resets the commonModeSubtraction and increases the frame index */
|
||||
virtual void newFrame(){iframe++; if (cmSub) cmSub->newFrame();};
|
||||
|
||||
|
||||
/** sets the commonModeSubtraction algorithm to be used
|
||||
\param cm commonModeSubtraction algorithm to be used (NULL unsets)
|
||||
\returns pointer to the actual common mode subtraction algorithm
|
||||
*/
|
||||
commonModeSubtraction *setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;};
|
||||
/**
|
||||
gets the commonModeSubtraction algorithm to be used
|
||||
\returns pointer to the actual common mode subtraction algorithm
|
||||
*/
|
||||
commonModeSubtraction *getCommonModeSubtraction() {return cmSub;};
|
||||
|
||||
|
||||
/**
|
||||
sets the sign of the data
|
||||
\param sign 1 means positive values for photons, -1 negative, 0 gets
|
||||
\returns current sign for the data
|
||||
*/
|
||||
int setDataSign(int sign=0) {if (sign==1 || sign==-1) dataSign=sign; return dataSign;};
|
||||
|
||||
|
||||
/**
|
||||
adds value to pedestal (and common mode) for the given pixel
|
||||
\param val value to be added
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\param cm 1 adds the value to common mod, 0 skips it. Defaults to 0. - not properly implemented
|
||||
*/
|
||||
virtual void addToPedestal(double val, int ix, int iy=0){
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
stat[iy][ix].addToPedestal(val);
|
||||
if (cmSub) {
|
||||
if (det) if (det->isGood(ix, iy)==0) return;
|
||||
cmSub->addToCommonMode(val, ix, iy);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
gets pedestal (and common mode)
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\param cm 0 (default) without common mode subtraction, 1 with common mode subtraction (if defined)
|
||||
\returns pedestal value
|
||||
*/
|
||||
virtual double getPedestal(int ix, int iy, int cm=0){if (ix>=0 && ix<nx && iy>=0 && iy<ny) if (cmSub && cm>0) return stat[iy][ix].getPedestal()-cmSub->getCommonMode(); else return stat[iy][ix].getPedestal(); else return -1;};
|
||||
|
||||
/**
|
||||
gets pedestal rms (i.e. noise)
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\returns pedestal rms
|
||||
*/
|
||||
virtual double getPedestalRMS(int ix, int iy){if (ix>=0 && ix<nx && iy>=0 && iy<ny) return stat[iy][ix].getPedestalRMS();else return -1;};
|
||||
|
||||
|
||||
/**
|
||||
gets pedestal (and common mode)
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\param cm 0 (default) without common mode subtraction, 1 with common mode subtraction (if defined)
|
||||
\returns pedestal value
|
||||
*/
|
||||
virtual double* getPedestal(double *ped){
|
||||
if (ped==NULL)
|
||||
ped=new double[nx*ny];
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
ped[iy*nx+ix]=stat[iy][ix].getPedestal();
|
||||
}
|
||||
}
|
||||
return ped;
|
||||
};
|
||||
|
||||
/**
|
||||
gets pedestal rms (i.e. noise)
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\returns pedestal rms
|
||||
*/
|
||||
virtual double* getPedestalRMS(double *ped=NULL){
|
||||
if (ped==NULL)
|
||||
ped=new double[nx*ny];
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
ped[iy*nx+ix]=stat[iy][ix].getPedestalRMS();
|
||||
}
|
||||
}
|
||||
return ped;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
sets pedestal
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\param val value to set
|
||||
\param rms rms to be set if any, defaults to 0
|
||||
\param m number of pedestal samples to be set or the moving stat structure is any, defaults to 0
|
||||
*/
|
||||
virtual void setPedestal(int ix, int iy, double val, double rms=0, int m=-1){if (ix>=0 && ix<nx && iy>=0 && iy<ny) stat[iy][ix].setPedestal(val,rms, m);};
|
||||
|
||||
/**
|
||||
sets pedestal
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\param val value to set
|
||||
\param rms rms to be set if any, defaults to 0
|
||||
\param m number of pedestal samples to be set or the moving stat structure is any, defaults to 0
|
||||
*/
|
||||
virtual void setPedestal(double *ped, double *rms=NULL, int m=-1){
|
||||
double rr=0;
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
if (rms) rr=rms[iy*nx+ix];
|
||||
stat[iy][ix].setPedestal(ped[iy*nx+ix],rr, m);
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
sets pedestal rms
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\param rms value to set
|
||||
*/
|
||||
virtual void setPedestalRMS(int ix, int iy, double rms=0){if (ix>=0 && ix<nx && iy>=0 && iy<ny) stat[iy][ix].setPedestalRMS(rms);};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
sets pedestal rms for all pixels
|
||||
\param rms pointer to array of pedestal rms
|
||||
*/
|
||||
virtual void setPedestalRMS(double *rms){
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
stat[iy][ix].setPedestalRMS(rms[iy*nx+ix]);
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
write 32bit tiff file with detector image data
|
||||
\param imgname file name to be written
|
||||
\returns NULL if file writing didn't succed, otherwise a pointer
|
||||
*/
|
||||
virtual void *writeImage(const char * imgname) {
|
||||
float *gm=NULL;
|
||||
void *ret;
|
||||
gm=new float[nx*ny];
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
gm[iy*nx+ix]=image[iy*nx+ix];
|
||||
}
|
||||
}
|
||||
ret=WriteToTiff(gm, imgname, ny, nx);
|
||||
delete [] gm;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
write 32bit tiff file containing the pedestals
|
||||
\param imgname file name to be written
|
||||
\returns NULL if file writing didn't succed, otherwise a pointer
|
||||
*/
|
||||
|
||||
virtual void *writePedestals(const char * imgname) {
|
||||
float *gm=NULL;
|
||||
void *ret;
|
||||
gm=new float[nx*ny];
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
if (cmSub)
|
||||
gm[iy*nx+ix]=stat[iy][ix].getPedestal()-cmSub->getCommonMode();
|
||||
else
|
||||
gm[iy*nx+ix]=stat[iy][ix].getPedestal();
|
||||
}
|
||||
}
|
||||
ret=WriteToTiff(gm, imgname, ny, nx);
|
||||
delete [] gm;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
read 32bit tiff file containing the pedestals
|
||||
\param imgname file name to be read
|
||||
\returns 0 if file reading didn't succed, otherwise 1
|
||||
*/
|
||||
int readPedestals(const char * imgname) {
|
||||
uint32 nnx, nny;
|
||||
float *gm=ReadFromTiff( imgname, nny, nnx);
|
||||
if (nnx>nx) nnx=nx;
|
||||
if (nny>ny) nny=ny;
|
||||
|
||||
|
||||
|
||||
if (gm) {
|
||||
for (int ix=0; ix<nnx; ix++) {
|
||||
for (int iy=0; iy<nny; iy++) {
|
||||
stat[iy][ix].setPedestal(gm[iy*nx+ix],-1,-1);
|
||||
}
|
||||
}
|
||||
delete [] gm;
|
||||
return 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
read 32bit tiff file containing the image data
|
||||
\param imgname file name to be read
|
||||
\returns 0 if file reading didn't succed, otherwise 1
|
||||
*/
|
||||
int readImage(const char * imgname) {
|
||||
uint32 nnx, nny;
|
||||
float *gm=ReadFromTiff( imgname, nny, nnx);
|
||||
if (nnx>nx) nnx=nx;
|
||||
if (nny>ny) nny=ny;
|
||||
|
||||
|
||||
|
||||
if (gm) {
|
||||
for (int ix=0; ix<nnx; ix++) {
|
||||
for (int iy=0; iy<nny; iy++) {
|
||||
image[iy*nx+ix]=gm[iy*nx+ix];
|
||||
}
|
||||
}
|
||||
delete [] gm;
|
||||
return 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
returns pointer to image data
|
||||
\returns pointer to image data
|
||||
*/
|
||||
virtual int *getImage(){return image;};
|
||||
/**
|
||||
write 32bit tiff file containing the pedestals RMS
|
||||
\param imgname file name to be written
|
||||
\returns NULL if file writing didn't succed, otherwise a pointer
|
||||
*/
|
||||
void *writePedestalRMS(const char * imgname) {
|
||||
float *gm=NULL;
|
||||
void *ret;
|
||||
gm=new float[nx*ny];
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
gm[iy*nx+ix]=stat[iy][ix].getPedestalRMS();
|
||||
}
|
||||
}
|
||||
ret=WriteToTiff(gm, imgname, ny, nx);
|
||||
delete [] gm;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
read 32bit tiff file containing the pedestals RMS
|
||||
\param imgname file name to be read
|
||||
\returns 0 if file reading didn't succed, otherwise 1
|
||||
*/
|
||||
|
||||
int readPedestalRMS(const char * imgname) {
|
||||
uint32 nnx, nny;
|
||||
float *gm=ReadFromTiff( imgname, nny, nnx);
|
||||
if (nnx>nx) nnx=nx;
|
||||
if (nny>ny) nny=ny;
|
||||
if (gm) {
|
||||
for (int ix=0; ix<nnx; ix++) {
|
||||
for (int iy=0; iy<nny; iy++) {
|
||||
stat[iy][ix].setPedestalRMS(gm[iy*nx+ix]);
|
||||
}
|
||||
}
|
||||
delete [] gm;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Adds all the data for each pixels in the selected region of interest to the pedestal
|
||||
\param data pointer to the data
|
||||
*/
|
||||
|
||||
virtual void addToPedestal(char *data) {
|
||||
|
||||
|
||||
newFrame();
|
||||
|
||||
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
|
||||
|
||||
addToPedestal(data,ix,iy);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return ;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Sets region of interest in which data should be processed
|
||||
\param xmi minimum x. if -1 or out of range remains unchanged
|
||||
\param xma maximum x. if -1 or out of range remains unchanged
|
||||
\param ymi minimum y. if -1 or out of range remains unchanged
|
||||
\param yma maximum y. if -1 or out of range remains unchanged
|
||||
*/
|
||||
|
||||
void setROI(int xmi=-1, int xma=-1, int ymi=-1, int yma=-1) {
|
||||
if (xmi>=0 && xmi<=nx) xmin=xmi;
|
||||
if (xma>=0 && xma<=nx) xmax=xma;
|
||||
if (xmax<xmin) {
|
||||
xmi=xmin;
|
||||
xmin=xmax;
|
||||
xmax=xmi;
|
||||
}
|
||||
|
||||
if (ymi>=0 && ymi<=ny) ymin=ymi;
|
||||
if (yma>=0 && yma<=ny) ymax=yma;
|
||||
if (ymax<ymin) {
|
||||
ymi=ymin;
|
||||
ymin=ymax;
|
||||
ymax=ymi;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
/**
|
||||
Gets region of interest in which data are processed
|
||||
\param xmi reference to minimum x.
|
||||
\param xma reference to maximum x.
|
||||
\param ymi reference to minimum y.
|
||||
\param yma reference to maximum y.
|
||||
*/
|
||||
|
||||
void getROI(int &xmi, int &xma, int &ymi, int &yma) {xmi=xmin; xma=xmax; ymi=ymin; yma=ymax;};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Adds all the data for the selected pixel to the pedestal
|
||||
\param data pointer to the data
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
*/
|
||||
|
||||
|
||||
virtual void addToPedestal(char *data, int ix, int iy=0) {
|
||||
|
||||
|
||||
double val;
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
|
||||
if (det)
|
||||
val=dataSign*det->getValue(data, ix, iy);
|
||||
else
|
||||
val=((double*)data)[iy*nx+ix];
|
||||
|
||||
addToPedestal(val,ix,iy);
|
||||
}
|
||||
return ;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Subtracts pedestal from the data array in the region of interest
|
||||
\param data pointer to the data
|
||||
\param val pointer where the pedestal subtracted data should be added. If NULL, the internal image is used
|
||||
\returns pointer to the pedestal subtracted data
|
||||
*/
|
||||
|
||||
|
||||
virtual double *subtractPedestal(char *data, double *val=NULL) {
|
||||
|
||||
newFrame();
|
||||
|
||||
if (val==NULL)
|
||||
val=new double[nx*ny];
|
||||
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
val[iy*nx+ix]+=subtractPedestal(data, ix, iy);
|
||||
}
|
||||
}
|
||||
return val;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Subtracts pedestal from the data for a selected pixel
|
||||
\param data pointer to the data
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\returns pedestal subtracted value
|
||||
*/
|
||||
|
||||
|
||||
|
||||
virtual double subtractPedestal(char *data, int ix, int iy=0) {
|
||||
double g=1.;
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
if (gmap) {
|
||||
g=gmap[iy*nx+ix];
|
||||
if (g==0) g=-1.;
|
||||
}
|
||||
|
||||
if (det)
|
||||
return (dataSign*det->getValue(data, ix, iy)-getPedestal(ix,iy))/g;
|
||||
else
|
||||
return (((double*)data)[iy*nx+ix]-getPedestal(ix,iy))/g;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
sets threshold value for conversion into number of photons
|
||||
\param t threshold to be set
|
||||
\returns threshold value
|
||||
*/
|
||||
double setThreshold(double t){thr=t; return thr;};
|
||||
|
||||
/**
|
||||
gets threshold value for conversion into number of photons
|
||||
\returns threshold value
|
||||
*/
|
||||
double getThreshold(){return thr;};
|
||||
/**
|
||||
converts the data into number of photons for the selected pixel
|
||||
\param data pointer to the data
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\returns converted number of photons. If no threshold is set, returns gain converted pedestal subtracted data.
|
||||
*/
|
||||
|
||||
virtual int getNPhotons(char *data, int ix, int iy=0) {
|
||||
int nph=0;
|
||||
double v;
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
v=subtractPedestal(data,ix,iy);
|
||||
if (thr>0) {
|
||||
v+=0.5*thr;
|
||||
nph=v/thr;
|
||||
return nph;
|
||||
} else
|
||||
return v;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
converts the data into number of photons for all pixels
|
||||
\param data pointer to the data
|
||||
\param nph pointer where the photons should added. If NULL,the internal image is used
|
||||
\returns pointer to array containing the number of photons
|
||||
*/
|
||||
int *getNPhotons(char *data, int *nph=NULL) {
|
||||
|
||||
double val;
|
||||
if (nph==NULL)
|
||||
nph=image;
|
||||
newFrame();
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
nph[iy*nx+ix]+=getNPhotons(data, ix, iy);
|
||||
}
|
||||
}
|
||||
return nph;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
clears the image array
|
||||
|
||||
*/
|
||||
virtual void clearImage(){
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
image[iy*nx+ix]=0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** sets/gets number of samples for moving average pedestal calculation
|
||||
\param i number of samples to be set (0 or negative gets)
|
||||
\returns actual number of samples
|
||||
*/
|
||||
int SetNPedestals(int i=-1) {
|
||||
int ix=0, iy=0;
|
||||
if (i>0)
|
||||
for (ix=0; ix<nx; ix++)
|
||||
for (iy=0; iy<ny; iy++)
|
||||
stat[iy][ix].SetNPedestals(i);
|
||||
return stat[0][0].SetNPedestals();
|
||||
};
|
||||
|
||||
/** gets number of samples for moving average pedestal calculation
|
||||
\returns actual number of samples
|
||||
*/
|
||||
int GetNPedestals(int ix, int iy) {
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny)
|
||||
return stat[iy][ix].GetNPedestals();
|
||||
else
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
||||
/** calculates the sum of photons in the specified region of interest.
|
||||
\param data pointer to the data
|
||||
\param xmi minimum x for the calculation. If -1 the minimum x of the predefined region of interest is used
|
||||
\param xma maximum x for the calculation. If -1 the maximum x of the predefined region of interest is used
|
||||
\param ymi minimum y for the calculation. If -1 the minimum y of the predefined region of interest is used
|
||||
\param yma maximum y for the calculation. If -1 the maximum y of the predefined region of interest is used
|
||||
|
||||
\returns total number of photons in
|
||||
*/
|
||||
virtual int getTotalNumberOfPhotons(char *data, int xmi=-1, int xma=-1, int ymi=-1, int yma=-1) {
|
||||
int val=0;
|
||||
if (xmi<0) xmi=xmin;
|
||||
if (xma<0) xma=xmax;
|
||||
if (ymi<0) ymi=ymin;
|
||||
if (yma<0) yma=ymax;
|
||||
|
||||
for (int ix=xmi; ix<xma; ix++)
|
||||
for (int iy=ymi; iy<yma; iy++)
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny)
|
||||
val+=getNPhotons(data, ix, iy);
|
||||
return val;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
calculates the image converted into number of photons. If the frame mode is pedestal, it also it to the pdedestal subtraction.
|
||||
\param data pointer to the data to be processed
|
||||
\param val pointer of the data to be added to. If NULL, the internal image will be used
|
||||
\param pointer to the processed data
|
||||
\returns
|
||||
*/
|
||||
|
||||
virtual void processData(char *data,int *val=NULL) {
|
||||
switch(fMode) {
|
||||
case ePedestal:
|
||||
addToPedestal(data);
|
||||
break;
|
||||
default:
|
||||
getNPhotons(data,val);
|
||||
}
|
||||
};
|
||||
|
||||
virtual char *getInterpolation(){return NULL;};
|
||||
|
||||
/** sets the current frame mode for the detector
|
||||
\param f frame mode to be set
|
||||
|
||||
\returns current frame mode
|
||||
*/
|
||||
frameMode setFrameMode(frameMode f) {fMode=f; return fMode;};
|
||||
|
||||
/** gets the current frame mode for the detector
|
||||
\returns current frame mode
|
||||
*/
|
||||
frameMode getFrameMode() {return fMode;};
|
||||
|
||||
/** sets file pointer where to write the clusters to
|
||||
\param f file pointer
|
||||
\returns current file pointer
|
||||
*/
|
||||
FILE *setFilePointer(FILE *f){myFile=f; return myFile;};
|
||||
|
||||
/** gets file pointer where to write the clusters to
|
||||
\returns current file pointer
|
||||
*/
|
||||
FILE *getFilePointer(){return myFile;};
|
||||
void setMutex(pthread_mutex_t *m){fm=m;};
|
||||
protected:
|
||||
|
||||
slsDetectorData<dataType> *det; /**< slsDetectorData to be used */
|
||||
int nx; /**< Size of the detector in x direction */
|
||||
int ny; /**< Size of the detector in y direction */
|
||||
pedestalSubtraction **stat; /**< pedestalSubtraction class */
|
||||
commonModeSubtraction *cmSub;/**< commonModeSubtraction class */
|
||||
int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */
|
||||
int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */
|
||||
double *gmap;
|
||||
int *image;
|
||||
int id;
|
||||
//int xmin, xmax, ymin, ymax; int xmin; /**< minimum x of the region of interest */
|
||||
int xmin; /**< minimum x of the region of interest */
|
||||
int xmax; /**< maximum x of the region of interest */
|
||||
int ymin;/**< minimum y of the region of interest */
|
||||
int ymax;/**< maximum y of the region of interest */
|
||||
double thr; /**< threshold to be used for conversion into number of photons */
|
||||
// int nSigma; /**< number of sigma to be used for conversion into number of photons if threshold is undefined */
|
||||
frameMode fMode; /**< current detector frame mode */
|
||||
FILE *myFile; /**< file pointer to write to */
|
||||
|
||||
pthread_mutex_t *fm;
|
||||
};
|
||||
|
||||
#endif
|
82
slsDetectorCalibration/commonModeSubtraction.h
Normal file
82
slsDetectorCalibration/commonModeSubtraction.h
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef COMMONMODESUBTRACTION_H
|
||||
#define COMMONMODESUBTRACTION_H
|
||||
|
||||
#include "MovingStat.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class commonModeSubtraction {
|
||||
|
||||
/** @short class to calculate the common mode of the pedestals based on an approximated moving average*/
|
||||
|
||||
public:
|
||||
|
||||
/** constructor
|
||||
\param nn number of samples for the moving average to calculate the average common mode
|
||||
\param iroi number of regions on which one can calculate the common mode separately. Defaults to 1 i.e. whole detector
|
||||
|
||||
*/
|
||||
commonModeSubtraction(int nn=1000, int iroi=1) : cmStat(NULL), cmPed(NULL), nCm(NULL), nROI(iroi) {cmStat=new MovingStat[nROI]; for (int i=0; i<nROI; i++) cmStat[i].SetN(nn); cmPed=new double[nROI]; nCm=new double[nROI];};
|
||||
|
||||
/** destructor - deletes the moving average(s) and the sum of pedestals calculator(s) */
|
||||
virtual ~commonModeSubtraction() {delete [] cmStat; delete [] cmPed; delete [] nCm;};
|
||||
|
||||
|
||||
/** clears the moving average and the sum of pedestals calculation - virtual func*/
|
||||
virtual void Clear(){
|
||||
for (int i=0; i<nROI; i++) {
|
||||
cmStat[i].Clear();
|
||||
nCm[i]=0;
|
||||
cmPed[i]=0;
|
||||
}};
|
||||
|
||||
/** adds the average of pedestals to the moving average and reinitializes the calculation of the sum of pedestals for all ROIs. - virtual func*/
|
||||
virtual void newFrame(){
|
||||
for (int i=0; i<nROI; i++) {
|
||||
if (nCm[i]>0) cmStat[i].Calc(cmPed[i]/nCm[i]);
|
||||
nCm[i]=0;
|
||||
cmPed[i]=0;
|
||||
}};
|
||||
|
||||
/** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest
|
||||
\param val value to add
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
*/
|
||||
virtual void addToCommonMode(double val, int ix=0, int iy=0) {
|
||||
(void) ix; (void) iy;
|
||||
|
||||
//if (isc>=0 && isc<nROI) {
|
||||
cmPed[0]+=val;
|
||||
nCm[0]++;//}
|
||||
};
|
||||
|
||||
/** gets the common mode i.e. the difference between the current average sum of pedestals mode and the average pedestal -- virtual func must be overloaded to define the regions of interest
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\return the difference between the current average sum of pedestals and the average pedestal
|
||||
*/
|
||||
virtual double getCommonMode(int ix=0, int iy=0) {
|
||||
(void) ix; (void) iy;
|
||||
if (nCm[0]>0) return cmPed[0]/nCm[0]-cmStat[0].Mean();
|
||||
return 0;};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
MovingStat *cmStat; /**<array of moving average of the pedestal average per region of interest */
|
||||
double *cmPed; /**< array storing the sum of pedestals per region of interest */
|
||||
double *nCm; /**< array storing the number of pixels currently contributing to the pedestals */
|
||||
const int nROI; /**< constant parameter for number of regions on which the common mode should be calculated separately e.g. supercolumns */
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
123
slsDetectorCalibration/dataStructures/Mythen3_01_jctbData.h
Normal file
123
slsDetectorCalibration/dataStructures/Mythen3_01_jctbData.h
Normal file
@ -0,0 +1,123 @@
|
||||
#ifndef MYTHEN301JCTBDATA_H
|
||||
#define MYTHEN301JCTBDATA_H
|
||||
|
||||
|
||||
class mythen3_01_jctbData : public slsDetectorData<short unsigned int> {
|
||||
|
||||
|
||||
public:
|
||||
mythen3_01_jctbData( int nch=64*3,int dr=24, int off=5): slsDetectorData<short unsigned int>(64*3,1,dr*8*nch,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch) {};
|
||||
|
||||
virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;};
|
||||
|
||||
virtual short unsigned int getChannel(char *data, int ix, int iy=0) {
|
||||
int ret=-1;
|
||||
short unsigned int *val=mythen03_frame(data,dynamicRange,numberOfCounters,serialOffset);
|
||||
if (ix>=0 && ix<numberOfCounters) ret=val[ix];
|
||||
delete [] val;
|
||||
return ret;
|
||||
};
|
||||
|
||||
virtual int getFrameNumber(char *buff) {return frameNumber;};
|
||||
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
|
||||
ndata=dsize;
|
||||
return data;
|
||||
}
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
char *data=NULL;
|
||||
if (filebin.is_open()) {
|
||||
data=new char[dataSize];
|
||||
filebin.read(data,dataSize);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
virtual short unsigned int **getData(char *ptr, int dsize=-1) {
|
||||
short unsigned int **val;
|
||||
val=new short unsigned int*[1];
|
||||
val[0]=mythen03_frame(ptr,dynamicRange,nx,serialOffset);
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static short unsigned int* mythen03_frame(char *ptr, int dr=24, int nch=64*3, int off=5) {
|
||||
// off=0;
|
||||
int iarg;
|
||||
int64_t word, *wp;
|
||||
short unsigned int* val=new short unsigned int[nch];
|
||||
int bit[64];
|
||||
int nb=2;
|
||||
int ioff=0;
|
||||
int idr=0;
|
||||
int ib=0;
|
||||
int iw=0;
|
||||
int ii=0;
|
||||
bit[0]=19;
|
||||
bit[1]=8;
|
||||
idr=0;
|
||||
for (ib=0; ib<nch; ib++) {
|
||||
val[ib]=0;
|
||||
}
|
||||
wp=(int64_t*)ptr;
|
||||
|
||||
for (iw=0; iw<nch/nb; iw) {
|
||||
word=*wp;;
|
||||
if (ioff<off) {
|
||||
ioff++;
|
||||
cout <<"*";
|
||||
} else {
|
||||
|
||||
if (idr<16) {
|
||||
for (ib=0; ib<nb; ib++) {
|
||||
if (word&(1<<bit[ib])) {
|
||||
cout << "+" ;
|
||||
val[iw+nch*(ib/nb)]|=(1<<idr);
|
||||
} else {
|
||||
cout << "-" ;
|
||||
}
|
||||
}//end for()
|
||||
}
|
||||
|
||||
idr++;
|
||||
|
||||
|
||||
if (idr==dr) {
|
||||
idr=0;
|
||||
// cout << dec << " " << iw << " " << val[iw] << " " << val[iw+nch/2] << endl;
|
||||
cout <<dec << iw<<endl;
|
||||
iw++;
|
||||
}//end if()
|
||||
|
||||
}//end else()
|
||||
wp+=1;
|
||||
ii++;
|
||||
}//end for
|
||||
|
||||
cout << "Decoded "<<ii << " samples"<< endl;
|
||||
cout << "Should be "<< nch/nb*dr+off << " samples"<< endl;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; };
|
||||
virtual int setDynamicRange(int d=-1) {if (d>0 && d<=24) dynamicRange=d; return dynamicRange;};
|
||||
virtual int setSerialOffset(int d=-1) {if (d>=0) serialOffset=d; return serialOffset;};
|
||||
virtual int setNumberOfCounters(int d=-1) {if (d>=0) numberOfCounters=d; return numberOfCounters;};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int dynamicRange;
|
||||
int serialOffset;
|
||||
int frameNumber;
|
||||
int numberOfCounters;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
63
slsDetectorCalibration/dataStructures/adcSar2_jctbData.h
Normal file
63
slsDetectorCalibration/dataStructures/adcSar2_jctbData.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef ADCSAR2_JCTBDATA_H
|
||||
#define ADCSAR2_JCTBDATA_H
|
||||
|
||||
|
||||
class adcSar2_jctbData : public slsDetectorData<short unsigned int> {
|
||||
|
||||
|
||||
public:
|
||||
adcSar2_jctbData(int nsamples=1000): slsDetectorData<short unsigned int>(nsamples,1,nsamples*8,NULL,NULL,NULL){};
|
||||
|
||||
virtual void getPixel(int ip, int &x, int &y) {x=ip/8; y=1;};
|
||||
|
||||
virtual short unsigned int getChannel(char *data, int ix, int iy=0) {
|
||||
int adcvalue=0;
|
||||
int vv1= *((int16_t*) (data+8*ix));
|
||||
int vv2= *((int16_t*) (data+8*ix+2));
|
||||
for (int jj=0;jj<8;jj++){
|
||||
adcvalue=adcvalue+ (((vv1>>(jj*2)) & 0x1)<<(jj));
|
||||
}
|
||||
for (int jj=0;jj<4;jj++){
|
||||
adcvalue=adcvalue+ (((vv2>>(jj*2)) & 0x1)<<(jj+8));
|
||||
}
|
||||
return adcvalue;
|
||||
};
|
||||
|
||||
virtual int getFrameNumber(char *buff) {return frameNumber;};
|
||||
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
|
||||
ndata=dsize;
|
||||
return data;
|
||||
}
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
char *data=NULL;
|
||||
if (filebin.is_open()) {
|
||||
data=new char[dataSize];
|
||||
filebin.read(data,dataSize);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/* virtual int **getData(char *ptr, int dsize=-1) { */
|
||||
/* int **val; */
|
||||
/* val=new int*[1]; */
|
||||
/* val[0]=mythen03_frame(ptr,dynamicRange,nx,serialOffset); */
|
||||
/* return val; */
|
||||
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; };
|
||||
|
||||
private:
|
||||
|
||||
int frameNumber;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
89
slsDetectorCalibration/dataStructures/chiptestBoardData.h
Normal file
89
slsDetectorCalibration/dataStructures/chiptestBoardData.h
Normal file
@ -0,0 +1,89 @@
|
||||
#ifndef CHIPTESTDATA_H
|
||||
#define CHIPTESTDATA_H
|
||||
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
class chiptestBoardData : public slsDetectorData<uint16_t> {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
chiptestBoard data structure. Works for data acquired using the chiptestBoard.
|
||||
Inherits and implements slsDetectorData.
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param npx number of pixels in the x direction
|
||||
\param npy number of pixels in the y direction (1 for strips)
|
||||
\param nadc number of adcs
|
||||
\param offset offset at the beginning of the pattern
|
||||
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset)
|
||||
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
|
||||
\param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
|
||||
|
||||
*/
|
||||
chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData<uint16_t>(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; // should be? nadc*(npx*npy+offset)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata size of frame returned
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns always return the pointer to data (no frame loss!)
|
||||
*/
|
||||
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize) {ndata=dsize;setDataSize(dsize); return data;};
|
||||
|
||||
/**
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
*/
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
|
||||
int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) {
|
||||
setDataSize(afifo_length*nAdc*sizeof(uint16_t));
|
||||
afifo_cont=new uint16_t[afifo_length*nAdc];
|
||||
if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) {
|
||||
iframe++;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
private:
|
||||
const int nAdc; /**<number of ADC read out */
|
||||
const int offSize; /**< offset at the beginning of the frame (depends on the pattern) */
|
||||
int iframe; /**< frame number (calculated in software! not in the data)*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
470
slsDetectorCalibration/dataStructures/eigerHalfModuleData.h
Normal file
470
slsDetectorCalibration/dataStructures/eigerHalfModuleData.h
Normal file
@ -0,0 +1,470 @@
|
||||
#ifndef EIGERMODULEDATA_H
|
||||
#define EIGERMODULEDATA_H
|
||||
#include "slsReceiverData.h"
|
||||
|
||||
|
||||
|
||||
class eigerHalfModuleData : public slsReceiverData<uint32_t> {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the eiger prototype read out by a half module i.e. using the slsReceiver
|
||||
(256*256 pixels, 512 packets for 16 bit mode, 256 for 8, 128 for 4, 1024 for 32, 1040 etc.)
|
||||
\param d dynamic range
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
eigerHalfModuleData(bool t, bool l, int dr, int tg, int psize, int dsize, int npf, int x, int y, double c=0):
|
||||
slsReceiverData<uint32_t>(x, y, npf, psize),
|
||||
top(t), left(l),
|
||||
dynamicRange(dr), tenGiga(tg),
|
||||
packetSize(psize), onepacketdataSize(dsize), numberofPacketsPerFrame(npf),
|
||||
xtalk(c),
|
||||
header_t(0), footer_t(0){
|
||||
|
||||
|
||||
int **dMap;
|
||||
uint32_t **dMask;
|
||||
|
||||
dMap=new int*[ny];
|
||||
dMask=new uint32_t*[ny];
|
||||
|
||||
|
||||
for (int i = 0; i < ny; i++) {
|
||||
dMap[i] = new int[nx];
|
||||
dMask[i] = new uint32_t[nx];
|
||||
}
|
||||
|
||||
//Map
|
||||
int totalNumberOfBytes = numberofPacketsPerFrame * packetSize;
|
||||
int iPacket = 8;
|
||||
int iData = 0;
|
||||
int increment = (dynamicRange/8);
|
||||
int ic_increment = 1;
|
||||
if (dynamicRange == 4) {
|
||||
increment = 1;
|
||||
ic_increment = 2;
|
||||
}
|
||||
|
||||
if(top){
|
||||
for (int ir=0; ir<ny; ir++) {
|
||||
for (int ic=0; ic<nx; ic = ic + ic_increment) {
|
||||
dMap[ir][ic] = iPacket;
|
||||
iPacket += increment;
|
||||
iData += increment;
|
||||
//increment header
|
||||
if(iData >= onepacketdataSize){
|
||||
iPacket += 16;
|
||||
iData = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//bottom
|
||||
else{
|
||||
iData = 0;
|
||||
int numbytesperline;
|
||||
switch(dynamicRange){
|
||||
case 4: numbytesperline = 256; break;
|
||||
case 8: numbytesperline = 512; break;
|
||||
case 16:numbytesperline = 1024; break;
|
||||
case 32:numbytesperline = 2048; break;
|
||||
}
|
||||
iPacket = totalNumberOfBytes - numbytesperline - 8;
|
||||
if((dynamicRange == 32) && (!tenGiga))
|
||||
iPacket -= 16;
|
||||
|
||||
for (int ir=0; ir<ny; ir++) {
|
||||
for (int ic=0; ic<nx; ic = ic + ic_increment) {
|
||||
dMap[ir][ic] = iPacket;
|
||||
iPacket += increment;
|
||||
iData += increment;
|
||||
//--------------------32 bit 1giga -------------------
|
||||
if((dynamicRange == 32) && (!tenGiga)){
|
||||
if(iData == numbytesperline){
|
||||
iPacket -= (numbytesperline*2 + 16*3);
|
||||
iData = 0;
|
||||
}
|
||||
if(iData == onepacketdataSize){
|
||||
iPacket += 16;
|
||||
}
|
||||
}//------------end of 32 bit -------------------------
|
||||
else if((iData % numbytesperline) == 0){
|
||||
iPacket -= (numbytesperline*2);
|
||||
if(iData == onepacketdataSize){
|
||||
iPacket -= 16;
|
||||
iData = 0;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Mask
|
||||
for(int ir=0; ir<ny; ++ir)
|
||||
for(int ic=0; ic<nx; ++ic)
|
||||
dMask[ir][ic] = 0x0;
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** Returns the frame number for the given dataset.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
*/
|
||||
int getFrameNumber(char *buff){
|
||||
footer_t = (eiger_packet_footer_t*)(buff + onepacketdataSize + sizeof(eiger_packet_header_t));
|
||||
return ((uint32_t)(*( (uint64_t*) footer_t)));
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** gets the packets number
|
||||
\param buff pointer to the memory
|
||||
\returns packet number
|
||||
*/
|
||||
int getPacketNumber(char *buff){
|
||||
footer_t = (eiger_packet_footer_t*)(buff + onepacketdataSize + sizeof(eiger_packet_header_t));
|
||||
return(*( (uint16_t*) footer_t->packetnum));
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
returns the pixel value as double correcting for the output buffer crosstalk
|
||||
\param data pointer to the memory
|
||||
\param ix coordinate in the x direction
|
||||
\param iy coordinate in the y direction
|
||||
\returns channel value as double
|
||||
|
||||
*/
|
||||
double getValue(char *data, int ix, int iy=0) {
|
||||
// cout << "##" << (void*)data << " " << ix << " " <<iy << endl;
|
||||
if (xtalk==0)
|
||||
return getChannelwithMissingPackets(data, ix, iy);
|
||||
else
|
||||
return getChannelwithMissingPackets(data, ix, iy)-xtalk * getChannelwithMissingPackets(data, ix-1, iy);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded.
|
||||
\param data pointer to the dataset (including headers etc)
|
||||
\param ix pixel number in the x direction
|
||||
\param iy pixel number in the y direction
|
||||
\returns data for the selected channel, with inversion if required
|
||||
|
||||
*/
|
||||
|
||||
virtual int getChannelwithMissingPackets(char *data, int ix, int iy) {
|
||||
uint32_t m=0, n = 0;
|
||||
int linesperpacket,newix, newiy,origX;
|
||||
|
||||
|
||||
//cout <<"ix:"<<ix<<" nx:"<<nx<<" iy:"<<iy<<" ny:"<<ny<<" datamap[iy][ix]:"<< dataMap[iy][ix] <<" datasize:"<< dataSize <<endl;
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) {
|
||||
m=dataMask[iy][ix];
|
||||
|
||||
|
||||
//pixelpos1d = (nx * iy + ix);
|
||||
|
||||
switch(dynamicRange){
|
||||
case 4: if(tenGiga) linesperpacket=16; else linesperpacket=4;break;
|
||||
case 8: if(tenGiga) linesperpacket=8; else linesperpacket=2;break;
|
||||
case 16: if(tenGiga) linesperpacket=4; else linesperpacket=1;break;
|
||||
case 32: if(tenGiga) linesperpacket=2; else linesperpacket=1;break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//each byte is shared by 2 pixels for 4 bit mode
|
||||
origX = ix;
|
||||
if((dynamicRange == 4) && (ix%2))
|
||||
ix--;
|
||||
|
||||
|
||||
|
||||
// ------check if missing packet, get to pixel at start of packet-----------------
|
||||
|
||||
//to get the starting of a packet (except 1g 32 bit)
|
||||
newix = 0;
|
||||
// 0.5 Lines per packet for 1g 32 bit
|
||||
if(dynamicRange == 32 && !tenGiga)
|
||||
newix = ix - (ix%256);
|
||||
|
||||
//iy divided by linesperpacket depending on bitmode
|
||||
if(!(iy%linesperpacket))
|
||||
newiy = iy;
|
||||
else
|
||||
newiy = (iy - (iy%linesperpacket));
|
||||
|
||||
header_t = (eiger_packet_header_t*)((char*)(data +(dataMap[newiy][newix]-8)));
|
||||
uint16_t identifier = (uint16_t)*( (uint16_t*) header_t->missingpacket);
|
||||
|
||||
if(identifier==deactivatedPacketValue){
|
||||
// cprintf(RED,"deactivated packet\n");
|
||||
return -2;
|
||||
}
|
||||
// -----END OF CHECK -------------------------------------------------------------
|
||||
|
||||
|
||||
}else{
|
||||
cprintf(RED,"outside limits\n");
|
||||
return -99;
|
||||
}
|
||||
|
||||
//get proper data
|
||||
n = ((uint32_t)(*((uint32_t*)(((char*)data)+(dataMap[iy][ix])))));
|
||||
|
||||
//each byte is shared by 2 pixels for 4 bit mode
|
||||
if(dynamicRange == 4){
|
||||
if(ix != origX)
|
||||
return ((n & 0xf0)>>4)^m;
|
||||
return (n & 0xf)^m;
|
||||
}
|
||||
else if(dynamicRange == 8) return (n & 0xff)^m;
|
||||
else if(dynamicRange == 16) return (n & 0xffff)^m;
|
||||
else return (n & 0xffffffff)^m;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** sets the output buffer crosstalk correction parameter
|
||||
\param c output buffer crosstalk correction parameter to be set
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
|
||||
*/
|
||||
double setXTalk(double c) {xtalk=c; return xtalk;}
|
||||
|
||||
|
||||
/** gets the output buffer crosstalk parameter
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
*/
|
||||
double getXTalk() {return xtalk;}
|
||||
|
||||
void getChannelArray(double* data, char* buffer){
|
||||
for(int iy = 0; iy < ny; iy++){
|
||||
for(int ix = 0; ix < nx; ix++){
|
||||
data[iy*nx+ix] = getValue((char*)buffer,ix,iy);
|
||||
//cprintf(BLUE,"%d,%d :%f\n",ix,iy,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int* decodeData(int *datain) {
|
||||
|
||||
int dataBytes = numberofPacketsPerFrame * onepacketdataSize;
|
||||
int nch = nx*ny;
|
||||
int* dataout = new int [nch];
|
||||
char *ptr=(char*)datain;
|
||||
char iptr;
|
||||
|
||||
const int bytesize=8;
|
||||
int ival=0;
|
||||
int ipos=0, ichan=0, ibyte;
|
||||
|
||||
switch (dynamicRange) {
|
||||
case 4:
|
||||
for (ibyte=0; ibyte<dataBytes; ++ibyte) {//for every byte (1 pixel = 1/2 byte)
|
||||
iptr=ptr[ibyte]&0xff; //???? a byte mask
|
||||
for (ipos=0; ipos<2; ++ipos) { //loop over the 8bit (twice)
|
||||
ival=(iptr>>(ipos*4))&0xf; //pick the right 4bit
|
||||
dataout[ichan]=ival;
|
||||
ichan++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
for (ichan=0; ichan<dataBytes; ++ichan) {//for every pixel (1 pixel = 1 byte)
|
||||
ival=ptr[ichan]&0xff; //????? a byte mask
|
||||
dataout[ichan]=ival;
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
for (ichan=0; ichan<nch; ++ichan) { //for every pixel
|
||||
ival=0;
|
||||
for (ibyte=0; ibyte<2; ++ibyte) { //for each byte (concatenate 2 bytes to get 16 bit value)
|
||||
iptr=ptr[ichan*2+ibyte];
|
||||
ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
|
||||
}
|
||||
dataout[ichan]=ival;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//for every 32 bit (every element in datain array)
|
||||
for (ichan=0; ichan<nch; ++ichan) { //for every pixel
|
||||
ival=datain[ichan]&0xffffff;
|
||||
dataout[ichan]=ival;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return dataout;
|
||||
|
||||
};
|
||||
|
||||
|
||||
int* readNextFrameOnlyData(ifstream &filebin, int& fnum) {
|
||||
int framesize = numberofPacketsPerFrame * onepacketdataSize;
|
||||
|
||||
int* data = new int[framesize/(sizeof(int))];
|
||||
char *packet=new char[packetSize];
|
||||
fnum = -1;
|
||||
int pn=-1;
|
||||
int dataoffset = 0;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
|
||||
while (filebin.read(packet,packetSize)) {
|
||||
|
||||
fnum = getFrameNumber(packet); //cout << "fn:"<<fn<<endl;
|
||||
pn = getPacketNumber(packet); //cout << "pn:"<<pn<<endl;
|
||||
|
||||
memcpy(((char*)data)+dataoffset,packet+DATA_PACKET_HEADER_SIZE,onepacketdataSize);
|
||||
dataoffset+=onepacketdataSize;
|
||||
if(pn == numberofPacketsPerFrame)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] packet;
|
||||
if(!dataoffset){
|
||||
delete [] data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
/*
|
||||
when u get packet form next frames
|
||||
//to remember the position to read next frame
|
||||
filebin.seekg (position, filebin.beg);
|
||||
position = filebin.tellg();
|
||||
|
||||
*/
|
||||
|
||||
int *readNextFramewithMissingPackets(ifstream &filebin, int& fnum) {
|
||||
|
||||
int* data = new int[(numberofPacketsPerFrame * onepacketdataSize)/(sizeof(int))];
|
||||
char *packet=new char[packetSize];
|
||||
fnum = -1;
|
||||
int pnum = 0;
|
||||
int fn = -1;
|
||||
int pn =-1;
|
||||
int dataoffset = 0;
|
||||
int missingpackets;
|
||||
|
||||
|
||||
if (filebin.is_open()) {
|
||||
|
||||
while (filebin.read(packet,packetSize)) {
|
||||
|
||||
fn = getFrameNumber(packet); //cout << "fn:"<<fn<<endl;
|
||||
pn = getPacketNumber(packet); //cout << "pn:"<<pn<<endl;
|
||||
|
||||
//first packet
|
||||
if(fnum == -1){
|
||||
fnum = fn;
|
||||
}
|
||||
//next frame packet
|
||||
else if (fnum != fn){
|
||||
//set file reading to the last frame's packet in file
|
||||
filebin.seekg(-packetSize, ios::cur);//filebin.beg
|
||||
break;
|
||||
}
|
||||
|
||||
//missing packets
|
||||
missingpackets = pn - pnum - 1;
|
||||
if(missingpackets){
|
||||
memset(((char*)data)+dataoffset,0xFF,missingpackets*onepacketdataSize);
|
||||
dataoffset+=(missingpackets*onepacketdataSize);
|
||||
pnum+=missingpackets;
|
||||
}
|
||||
|
||||
memcpy(((char*)data)+dataoffset,packet+DATA_PACKET_HEADER_SIZE,onepacketdataSize);
|
||||
dataoffset+=onepacketdataSize;
|
||||
pnum++;
|
||||
if(pnum == numberofPacketsPerFrame)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
delete [] packet;
|
||||
if(!pnum){
|
||||
delete [] data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//missing packets (added here to also catch end of file)
|
||||
missingpackets = numberofPacketsPerFrame - pnum;
|
||||
if(missingpackets){
|
||||
memset(((char*)data)+dataoffset,0xFF,missingpackets*onepacketdataSize);
|
||||
dataoffset+=(missingpackets*onepacketdataSize);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
/** Missing Packet identifier value */
|
||||
const static uint16_t deactivatedPacketValue = 0xFEFE;
|
||||
|
||||
const static int DATA_PACKET_HEADER_SIZE = 8;
|
||||
const bool top;
|
||||
const bool left;
|
||||
const int dynamicRange;
|
||||
const bool tenGiga;
|
||||
const int packetSize;
|
||||
const int onepacketdataSize;
|
||||
const int numberofPacketsPerFrame;
|
||||
double xtalk; /**<output buffer crosstalk correction parameter */
|
||||
|
||||
|
||||
/** structure of an eiger packet*/
|
||||
typedef struct{
|
||||
unsigned char subframenum[4];
|
||||
unsigned char missingpacket[2];
|
||||
unsigned char portnum[1];
|
||||
unsigned char dynamicrange[1];
|
||||
} eiger_packet_header_t;
|
||||
|
||||
typedef struct{
|
||||
unsigned char framenum[6];
|
||||
unsigned char packetnum[2];
|
||||
} eiger_packet_footer_t;
|
||||
|
||||
eiger_packet_header_t* header_t;
|
||||
eiger_packet_footer_t* footer_t;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
148
slsDetectorCalibration/dataStructures/gotthardModuleData.h
Normal file
148
slsDetectorCalibration/dataStructures/gotthardModuleData.h
Normal file
@ -0,0 +1,148 @@
|
||||
#ifndef GOTTHARDMODULEDATA_H
|
||||
#define GOTTHARDMODULEDATA_H
|
||||
#include "slsReceiverData.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define FRAMEMASK 0xFFFFFFFE
|
||||
#define PACKETMASK 1
|
||||
#define FRAMEOFFSET 0x1
|
||||
|
||||
|
||||
class gotthardModuleData : public slsReceiverData<uint16_t> {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the gotthard read out by a module i.e. using the slsReceiver
|
||||
(1x1280 pixels, 2 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
gotthardModuleData(double c=0): slsReceiverData<uint16_t>(xpixels, ypixels, npackets, buffersize), xtalk(c) {
|
||||
|
||||
uint16_t **dMask;
|
||||
int **dMap;
|
||||
int ix, iy;
|
||||
int initial_offset = 2;
|
||||
int offset = initial_offset;
|
||||
|
||||
dMask=new uint16_t*[ypixels];
|
||||
dMap=new int*[ypixels];
|
||||
for (int i = 0; i < ypixels; i++) {
|
||||
dMap[i] = new int[xpixels];
|
||||
dMask[i] = new uint16_t[xpixels];
|
||||
}
|
||||
|
||||
for(ix=0; ix<ypixels; ++ix)
|
||||
for(iy=0; iy<xpixels; ++iy)
|
||||
dMask[ix][iy] = 0x0;
|
||||
|
||||
for(ix=0; ix<ypixels; ++ix){
|
||||
if(ix == (ypixels/2)){
|
||||
offset += initial_offset;//2
|
||||
offset++;
|
||||
}
|
||||
for(iy=0; iy<xpixels; ++iy){
|
||||
dMap[ix][iy] = offset;
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
int getFrameNumber(char *buff){
|
||||
int np=(*(int*)buff);
|
||||
//gotthards frame header must be incremented
|
||||
++np;
|
||||
//packet index should be 1 or 2
|
||||
return ((np&FRAMEMASK)>>FRAMEOFFSET);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
gets the packets number (last packet is labelled with 0 and is replaced with 40)
|
||||
\param buff pointer to the memory
|
||||
\returns packet number
|
||||
|
||||
*/
|
||||
|
||||
int getPacketNumber(char *buff){
|
||||
int np=(*(int*)buff);
|
||||
//gotthards frame header must be incremented
|
||||
++np;
|
||||
//packet index should be 1 or 2
|
||||
return ((np&PACKETMASK)+1);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
returns the pixel value as double correcting for the output buffer crosstalk
|
||||
\param data pointer to the memory
|
||||
\param ix coordinate in the x direction
|
||||
\param iy coordinate in the y direction
|
||||
\returns channel value as double
|
||||
|
||||
*/
|
||||
double getValue(char *data, int ix, int iy=0) {
|
||||
//check how it is for gotthard
|
||||
if (xtalk==0)
|
||||
return slsDetectorData<uint16_t>::getValue(data, ix, iy);
|
||||
else
|
||||
return slsDetectorData<uint16_t>::getValue(data, ix, iy)-xtalk*slsDetectorData<uint16_t>::getValue(data, ix-1, iy);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** sets the output buffer crosstalk correction parameter
|
||||
\param c output buffer crosstalk correction parameter to be set
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
|
||||
*/
|
||||
double setXTalk(double c) {xtalk=c; return xtalk;}
|
||||
|
||||
|
||||
/** gets the output buffer crosstalk parameter
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
*/
|
||||
double getXTalk() {return xtalk;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
double xtalk; /**<output buffer crosstalk correction parameter */
|
||||
const static int xpixels = 1280;
|
||||
const static int ypixels = 1;
|
||||
const static int npackets = 2;
|
||||
const static int buffersize = 1286;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
127
slsDetectorCalibration/dataStructures/gotthardShortModuleData.h
Normal file
127
slsDetectorCalibration/dataStructures/gotthardShortModuleData.h
Normal file
@ -0,0 +1,127 @@
|
||||
#ifndef GOTTHARDSHORTMODULEDATA_H
|
||||
#define GOTTHARDSHORTMODULEDATA_H
|
||||
#include "slsReceiverData.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class gotthardShortModuleData : public slsReceiverData<uint16_t> {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the gotthard short read out by a module i.e. using the slsReceiver
|
||||
(1x256 pixels, 1 packet 256 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
gotthardShortModuleData(double c=0): slsReceiverData<uint16_t>(xpixels, ypixels, npackets, buffersize), xtalk(c){
|
||||
|
||||
uint16_t **dMask;
|
||||
int **dMap;
|
||||
int ix, iy;
|
||||
int offset = 2;
|
||||
|
||||
dMask=new uint16_t*[ypixels];
|
||||
dMap=new int*[ypixels];
|
||||
for (int i = 0; i < ypixels; i++) {
|
||||
dMap[i] = new int[xpixels];
|
||||
dMask[i] = new uint16_t[xpixels];
|
||||
}
|
||||
|
||||
for(ix=0; ix<ypixels; ++ix)
|
||||
for(iy=0; iy<xpixels; ++iy)
|
||||
dMask[ix][iy] = 0x0;
|
||||
|
||||
for(ix=0; ix<ypixels; ++ix)
|
||||
for(iy=0; iy<xpixels; ++iy){
|
||||
dMap[ix][iy] = offset;
|
||||
offset++;
|
||||
}
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
int getFrameNumber(char *buff){
|
||||
return (*(int*)buff);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
gets the packets number (last packet is labelled with 0 and is replaced with 40)
|
||||
\param buff pointer to the memory
|
||||
\returns packet number
|
||||
|
||||
*/
|
||||
|
||||
int getPacketNumber(char *buff){
|
||||
return 1;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
returns the pixel value as double correcting for the output buffer crosstalk
|
||||
\param data pointer to the memory
|
||||
\param ix coordinate in the x direction
|
||||
\param iy coordinate in the y direction
|
||||
\returns channel value as double
|
||||
|
||||
*/
|
||||
double getValue(char *data, int ix, int iy=0) {
|
||||
//check how it is for gotthard
|
||||
if (xtalk==0)
|
||||
return slsDetectorData<uint16_t>::getValue(data, ix, iy);
|
||||
else
|
||||
return slsDetectorData<uint16_t>::getValue(data, ix, iy)-xtalk*slsDetectorData<uint16_t>::getValue(data, ix-1, iy);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** sets the output buffer crosstalk correction parameter
|
||||
\param c output buffer crosstalk correction parameter to be set
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
|
||||
*/
|
||||
double setXTalk(double c) {xtalk=c; return xtalk;}
|
||||
|
||||
|
||||
/** gets the output buffer crosstalk parameter
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
*/
|
||||
double getXTalk() {return xtalk;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
double xtalk; /**<output buffer crosstalk correction parameter */
|
||||
const static int xpixels = 256;
|
||||
const static int ypixels = 1;
|
||||
const static int npackets = 1;
|
||||
const static int buffersize = 518;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
156
slsDetectorCalibration/dataStructures/jungfrau02Data.h
Normal file
156
slsDetectorCalibration/dataStructures/jungfrau02Data.h
Normal file
@ -0,0 +1,156 @@
|
||||
#ifndef JUNGFRAU02DATA_H
|
||||
#define JUNGFRAU02DATA_H
|
||||
|
||||
#include "chiptestBoardData.h"
|
||||
|
||||
|
||||
|
||||
class jungfrau02Data : public chiptestBoardData {
|
||||
public:
|
||||
|
||||
/* test :) */
|
||||
|
||||
|
||||
/**
|
||||
Implements the chiptestBoardData structure for the jungfrau02 prototype
|
||||
(48x48 pixels, ADC2 for analog output, 2 more ADCs used for readout of digital bits, pixel offset configurable.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
jungfrau02Data(int nadc, int offset, double c=0): chiptestBoardData(48, 48, nadc, offset),
|
||||
xtalk(c) {
|
||||
|
||||
|
||||
|
||||
|
||||
uint16_t **dMask;
|
||||
int **dMap;
|
||||
|
||||
|
||||
|
||||
dMask=new uint16_t*[48];
|
||||
dMap=new int*[48];
|
||||
for (int i = 0; i < 48; i++) {
|
||||
dMap[i] = new int[48];
|
||||
dMask[i] = new uint16_t[48];
|
||||
}
|
||||
|
||||
|
||||
for (int iy=0; iy<48; iy++) {
|
||||
for (int ix=0; ix<48; ix++) {
|
||||
|
||||
dMap[ix][iy]=offset+(iy*48+ix)*nAdc;//dMap[iy][ix]=offset+(iy*48+ix)*nAdc;
|
||||
// cout << ix << " " << iy << " " << dMap[ix][iy] << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << (0,0) << " " << dMap[0][0] << endl;
|
||||
cout << (47,47) << " " << dMap[47][47] << endl;
|
||||
|
||||
|
||||
for (int ix=0; ix<48; ix++) {
|
||||
for (int iy=0; iy<48; iy++)
|
||||
dMask[iy][ix]=0x0;
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Returns the value of the selected channel for the given dataset. Since the ADC is only 14bit wide, only bit 0-13 are occupied. If the gain bits are read out, they are returned in bit 14-15.
|
||||
\param data pointer to the dataset (including headers etc)
|
||||
\param ix pixel number in the x direction
|
||||
\param iy pixel number in the y direction
|
||||
\returns data for the selected channel, with inversion if required
|
||||
|
||||
*/
|
||||
|
||||
virtual uint16_t getChannel(char *data, int ix, int iy=0) {
|
||||
uint16_t m=0, d=0;
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) {
|
||||
m=dataMask[iy][ix];
|
||||
d=*(((uint16_t*)(data))+dataMap[iy][ix]);
|
||||
// cout << ix << " " << iy << " " << (uint16_t*)data << " " << ((uint16_t*)(data))+dataMap[iy][ix] << " " << d << endl;
|
||||
if (nAdc==3) {
|
||||
//cout << "Gain bit!" << endl;
|
||||
if (*((uint16_t*)(data)+dataMap[iy][ix]+2)>8000) //exchange if gainBits==2 is returned!
|
||||
d|=(1<<14); // gain bit 1
|
||||
if (*((uint16_t*)(data)+dataMap[iy][ix]+1)>8000) //exchange if gainBits==2 is returned!
|
||||
d|=(1<<15); // gain bit 0
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return d^m;
|
||||
};
|
||||
|
||||
/**
|
||||
returns the pixel value as double correcting for the output buffer crosstalk
|
||||
\param data pointer to the memory
|
||||
\param ix coordinate in the x direction
|
||||
\param iy coordinate in the y direction
|
||||
\returns channel value as double
|
||||
|
||||
*/
|
||||
double getValue(char *data, int ix, int iy=0) {
|
||||
// cout << "##" << (void*)data << " " << ix << " " <<iy << endl;
|
||||
uint16_t d=getChannel(data, ix, iy);
|
||||
// cout << d << " " << (d&0x3fff) << endl;
|
||||
if (xtalk==0 || ix==0)
|
||||
return (double)(getChannel(data, ix, iy)&0x3fff);
|
||||
else
|
||||
return (double)(getChannel(data, ix, iy)&0x3fff)-xtalk* (double)(getChannel(data, ix, iy)&0x3fff);
|
||||
};
|
||||
|
||||
/**
|
||||
returns the gain bit value, i.e. returns 0 if(GB0==0 && GB1==0), returns 1 if(GB0==1 && GB1==0), returns 3 if(GB0==1 && GB1==1), if it returns 2 -> the gain bits are read out the wrong way around (i.e. GB0 and GB1 have to be reversed!)
|
||||
\param data pointer to the memory
|
||||
\param ix coordinate in the x direction
|
||||
\param iy coordinate in the y direction
|
||||
\returns gain bits as int
|
||||
*/
|
||||
int getGainBits(char *data, int ix, int iy=0) {
|
||||
uint16_t d=getChannel(data, ix, iy);
|
||||
return ((d&0xc000)>>14);
|
||||
};
|
||||
//*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** sets the output buffer crosstalk correction parameter
|
||||
\param c output buffer crosstalk correction parameter to be set
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
|
||||
*/
|
||||
double setXTalk(double c) {xtalk=c; return xtalk;}
|
||||
|
||||
|
||||
/** gets the output buffer crosstalk parameter
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
*/
|
||||
double getXTalk() {return xtalk;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
double xtalk; /**<output buffer crosstalk correction parameter */
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
155
slsDetectorCalibration/dataStructures/jungfrau10ModuleData.h
Normal file
155
slsDetectorCalibration/dataStructures/jungfrau10ModuleData.h
Normal file
@ -0,0 +1,155 @@
|
||||
#ifndef JUNGFRAU10MODULEDATA_H
|
||||
#define JUNGFRAU10MODULEBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class jungfrau10ModuleData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
jungfrau10ModuleData(int ns=16384): slsDetectorData<uint16_t>(256*4, 256*2, 256*256*8*2, NULL, NULL, NULL) , iframe(0), nadc(32), sc_width(64), sc_height(256) {
|
||||
|
||||
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int ichip;
|
||||
|
||||
// cout << sizeof(uint16_t) << endl;
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
ichip=iadc/4;
|
||||
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
|
||||
if (ichip%2==0) {
|
||||
row=sc_height+i/sc_width;
|
||||
col=(ichip/2)*256+iadc%4*sc_width+(i%sc_width);
|
||||
} else {
|
||||
row=sc_height-1-i/sc_width;
|
||||
col=((ichip/2)*256+iadc%4*sc_width)+sc_width-(i%sc_width)-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* if (iadc<nadc/2) { */
|
||||
/* row=sc_height+i/sc_width; */
|
||||
/* col=iadc*sc_width+(i%sc_width); */
|
||||
/* } else { */
|
||||
/* row=sc_height-1-i/sc_width; */
|
||||
/* col=(nx-1)-((iadc-16)*sc_width)-(i%sc_width); */
|
||||
/* } */
|
||||
if (row<0 || row>=ny || col<0 || col>=nx) {
|
||||
cout << "Wrong row, column " << row << " " << col << " " << iadc << " " << i << endl;
|
||||
} else
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range " << row << " " << col <<" " << iadc << " " << i << endl;
|
||||
else {
|
||||
xmap[nadc*i+iadc]=col;
|
||||
ymap[nadc*i+iadc]=row;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
// cout << ib << "-" << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
246
slsDetectorCalibration/dataStructures/moench02Ctb10GbData.h
Normal file
246
slsDetectorCalibration/dataStructures/moench02Ctb10GbData.h
Normal file
@ -0,0 +1,246 @@
|
||||
#ifndef MOENCH02CTB10GBDATA_H
|
||||
#define MOENCH02CTB10GBDATA_H
|
||||
#include <stdio.h>
|
||||
#include "slsDetectorData.h"
|
||||
#include "slsReceiverData.h"
|
||||
|
||||
|
||||
class moench02Ctb10GbData : public slsReceiverData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
// int *xmap, *ymap;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
|
||||
int maplength;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench02Ctb10GbData(int ns=6400): slsReceiverData<uint16_t>(160, 160, 50, 8208) , nadc(4), sc_width(40), sc_height(160) {
|
||||
|
||||
|
||||
int adc_nr[4]={120,0,80,40};
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
int i;
|
||||
int npackets=50;
|
||||
maplength = 8208*npackets;
|
||||
//this->setDataSize(maplength);
|
||||
/* maplength=this->getDataSize()/2; */
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
if (i<sc_width*sc_height) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
row=i/sc_width;
|
||||
dataMap[row][col]=(32*i+iadc+2)*2+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=8208*npackets) {
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
|
||||
for (int ipacket=0; ipacket<npackets; ipacket++) {
|
||||
for (int ibyte=0; ibyte< 8208/2; ibyte++) {
|
||||
i=ipacket*8208/2+ibyte;
|
||||
if(ibyte<8){
|
||||
xmap[i]=-1;
|
||||
ymap[i]=-1;
|
||||
}else{
|
||||
isample=ii/32;
|
||||
iadc=ii%32;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if(iadc>=2 && iadc<=5){
|
||||
xmap[i]=adc_nr[iadc-2]+ix;
|
||||
ymap[i]=iy;
|
||||
}else{
|
||||
xmap[i]=-1;
|
||||
ymap[i]=-1;
|
||||
}
|
||||
ii++;
|
||||
}
|
||||
}//end loop on bytes
|
||||
}//end loop on packets
|
||||
|
||||
iframe=0;
|
||||
cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
void getPixel(int ip, int &x, int &y) {
|
||||
if(ip>=0 && ip<maplength){
|
||||
x=xmap[ip];
|
||||
y=ymap[ip];
|
||||
}else{
|
||||
cerr<<"WRONG ARRAY LENGTH"<<endl;
|
||||
cerr<<"Trying to access the "<<ip<<"-th element"<<endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
int getFrameNumber(char *buff){return *((int*)buff)&0xffffffff;};
|
||||
/* virtual int getFrameNumber(char *buff){(void)buff; return iframe;}; */
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return ((*(((int*)(buff+4))))&0xff)+1;};
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
//virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* //cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[packetSize*nPackets];
|
||||
char *retval=0;
|
||||
int nd;
|
||||
np=0;
|
||||
int pn;
|
||||
char aa[8224]={0};
|
||||
char *packet=(char *)aa;
|
||||
int fnum = -1;
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
|
||||
|
||||
cout << "+";
|
||||
|
||||
while(filebin.read((char*)packet, 8208)){
|
||||
|
||||
pn=getPacketNumber(packet);
|
||||
if (fnum<0)
|
||||
fnum= getFrameNumber(packet);
|
||||
|
||||
|
||||
if (fnum>=0) {
|
||||
if (getFrameNumber(packet) !=fnum) {
|
||||
|
||||
if (np==0){
|
||||
cout << "-";
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else
|
||||
filebin.seekg(-8208,ios_base::cur);
|
||||
return data;
|
||||
}
|
||||
|
||||
memcpy(data+(pn-1)*packetSize, packet, packetSize);
|
||||
|
||||
np++;
|
||||
if (np==nPackets)
|
||||
break;
|
||||
if (pn==nPackets)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
cerr<<filebin<<" not open!!!"<<endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (np==0){
|
||||
cout << "?";
|
||||
delete [] data;
|
||||
return NULL;
|
||||
}// else if (np<nPackets)
|
||||
// cout << "Frame " << fnum << " lost " << nPackets-np << " packets " << endl;
|
||||
|
||||
|
||||
return data;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int fnum=-1, np;
|
||||
return readNextFrame(filebin, fnum, np);
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
157
slsDetectorCalibration/dataStructures/moench02CtbData.h
Normal file
157
slsDetectorCalibration/dataStructures/moench02CtbData.h
Normal file
@ -0,0 +1,157 @@
|
||||
#ifndef MOENCH02CTBDATA_H
|
||||
#define MOENCH02CTBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench02CtbData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
// int *xmap, *ymap;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
|
||||
int maplength;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench02CtbData(int ns=6400): slsDetectorData<uint16_t>(160, 160, ns*2*32, NULL, NULL) , nadc(4), sc_width(40), sc_height(160) {
|
||||
|
||||
|
||||
int adc_nr[4]={120,0,80,40};
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
maplength=this->getDataSize()/2;
|
||||
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
row=i/sc_width;
|
||||
dataMap[row][col]=(32*i+iadc+2)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) {
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<maplength; i++) {
|
||||
isample=i/32;
|
||||
iadc=i%32;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if(iadc>1 && iadc<6){
|
||||
xmap[i]=adc_nr[iadc-2]+ix;
|
||||
ymap[i]=iy;
|
||||
}else{
|
||||
xmap[i]=-1;
|
||||
ymap[i]=-1;
|
||||
}
|
||||
}
|
||||
iframe=0;
|
||||
cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
void getPixel(int ip, int &x, int &y) {
|
||||
if(ip>=0 && ip<maplength){
|
||||
x=xmap[ip];
|
||||
y=ymap[ip];
|
||||
}else{
|
||||
cerr<<"WRONG ARRAY LENGTH"<<endl;
|
||||
cerr<<"Trying to access the "<<ip<<"-th element"<<endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
//cout << ib << "-" << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
137
slsDetectorCalibration/dataStructures/moench02ModuleData.h
Normal file
137
slsDetectorCalibration/dataStructures/moench02ModuleData.h
Normal file
@ -0,0 +1,137 @@
|
||||
#ifndef MOENCH02MODULEDATA_H
|
||||
#define MOENCH02MODULEDATA_H
|
||||
#include "slsReceiverData.h"
|
||||
|
||||
|
||||
|
||||
class moench02ModuleData : public slsReceiverData<uint16_t> {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench02ModuleData(double c=0): slsReceiverData<uint16_t>(160, 160, 40, 1286),
|
||||
xtalk(c) {
|
||||
|
||||
|
||||
|
||||
|
||||
uint16_t **dMask;
|
||||
int **dMap;
|
||||
int ix, iy;
|
||||
|
||||
|
||||
|
||||
dMask=new uint16_t*[160];
|
||||
dMap=new int*[160];
|
||||
for (int i = 0; i < 160; i++) {
|
||||
dMap[i] = new int[160];
|
||||
dMask[i] = new uint16_t[160];
|
||||
}
|
||||
|
||||
for (int isc=0; isc<4; isc++) {
|
||||
for (int ip=0; ip<10; ip++) {
|
||||
|
||||
for (int ir=0; ir<16; ir++) {
|
||||
for (int ic=0; ic<40; ic++) {
|
||||
|
||||
ix=isc*40+ic;
|
||||
iy=ip*16+ir;
|
||||
|
||||
dMap[iy][ix]=1286*(isc*10+ip)+2*ir*40+2*ic+4;
|
||||
// cout << ix << " " << iy << " " << dMap[ix][iy] << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ix=0; ix<120; ix++) {
|
||||
for (iy=0; iy<160; iy++)
|
||||
dMask[iy][ix]=0x3fff;
|
||||
}
|
||||
for (ix=120; ix<160; ix++) {
|
||||
for (iy=0; iy<160; iy++)
|
||||
dMask[iy][ix]=0x0;
|
||||
}
|
||||
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
gets the packets number (last packet is labelled with 0 and is replaced with 40)
|
||||
\param buff pointer to the memory
|
||||
\returns packet number
|
||||
|
||||
*/
|
||||
|
||||
int getPacketNumber(char *buff){
|
||||
int np=(*(int*)buff)&0xff;
|
||||
if (np==0)
|
||||
np=40;
|
||||
return np;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
returns the pixel value as double correcting for the output buffer crosstalk
|
||||
\param data pointer to the memory
|
||||
\param ix coordinate in the x direction
|
||||
\param iy coordinate in the y direction
|
||||
\returns channel value as double
|
||||
|
||||
*/
|
||||
double getValue(char *data, int ix, int iy=0) {
|
||||
// cout << "##" << (void*)data << " " << ix << " " <<iy << endl;
|
||||
if (xtalk==0 || ix%40==0)
|
||||
return slsDetectorData<uint16_t>::getValue(data, ix, iy);
|
||||
else
|
||||
return slsDetectorData<uint16_t>::getValue(data, ix, iy)-xtalk*slsDetectorData<uint16_t>::getValue(data, ix-1, iy);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** sets the output buffer crosstalk correction parameter
|
||||
\param c output buffer crosstalk correction parameter to be set
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
|
||||
*/
|
||||
double setXTalk(double c) {xtalk=c; return xtalk;}
|
||||
|
||||
|
||||
/** gets the output buffer crosstalk parameter
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
*/
|
||||
double getXTalk() {return xtalk;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
double xtalk; /**<output buffer crosstalk correction parameter */
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
285
slsDetectorCalibration/dataStructures/moench03Ctb10GbData.h
Normal file
285
slsDetectorCalibration/dataStructures/moench03Ctb10GbData.h
Normal file
@ -0,0 +1,285 @@
|
||||
#ifndef MOENCH03CTB10GBDATA_H
|
||||
#define MOENCH03CTB10GBDATA_H
|
||||
#include "slsReceiverData.h"
|
||||
|
||||
|
||||
|
||||
class moench03Ctb10GbData : public slsReceiverData<uint16_t> {
|
||||
|
||||
protected:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// moench03Ctb10GbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, 8208*40, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
moench03Ctb10GbData(int ns=5000): slsReceiverData<uint16_t>(400, 400, 40, 8208), nadc(32), sc_width(25), sc_height(200) {
|
||||
|
||||
int adc_nr[32]={200,225,250,275,300,325,350,375,\
|
||||
0,25,50,75,100,125,150,175,\
|
||||
175,150,125,100,75,50,25,0,\
|
||||
375,350,325,300,275,250,225,200};
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int npackets=40;
|
||||
int i;
|
||||
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (iadc<16) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=8208*40)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ipacket;
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
for (int ipacket=0; ipacket<npackets; ipacket++) {
|
||||
for (int ibyte=0; ibyte< 8208/2; ibyte++) {
|
||||
i=ipacket*8208/2+ibyte;
|
||||
if (ibyte<8) {
|
||||
//header!
|
||||
xmap[i]=-1;
|
||||
ymap[i]=-1;
|
||||
} else {
|
||||
// ii=ibyte+128*32*ipacket;
|
||||
isample=ii/nadc;
|
||||
iadc=ii%nadc;
|
||||
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (iadc<(nadc/2)) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return *((int*)buff)&0xffffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return ((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& fnum, char *data=NULL) {
|
||||
int dd=0;
|
||||
if (data==NULL) {
|
||||
data=new char[packetSize*nPackets];
|
||||
dd=1;
|
||||
}
|
||||
char *retval=0;
|
||||
int np=0, nd;
|
||||
fnum = -1;
|
||||
int pn;
|
||||
char aa[8224];
|
||||
char *packet=(char *)aa;
|
||||
int place;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
|
||||
|
||||
|
||||
place=filebin.tellg();
|
||||
while(filebin.read((char*)packet, 8208) && np<nPackets){
|
||||
pn=getPacketNumber(packet);
|
||||
if (pn==1 && fnum<0)
|
||||
fnum= getFrameNumber(packet);
|
||||
|
||||
// cout <<getFrameNumber(packet)<< " fn: " << fnum << "\t pn: " << pn << " np " << np << endl;
|
||||
if (fnum>=0) {
|
||||
if (getFrameNumber(packet) !=fnum) {
|
||||
cout << "-"<<endl;
|
||||
filebin.seekg(place);
|
||||
if (np==0){
|
||||
if (dd)
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(data+(pn-1)*packetSize, packet, packetSize);
|
||||
np++;
|
||||
if (np==nPackets)
|
||||
return data;
|
||||
|
||||
}
|
||||
place=filebin.tellg();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (np==0){
|
||||
cout << "-"<<endl;
|
||||
filebin.seekg(place);
|
||||
if (dd)
|
||||
delete [] data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//filebin.seekg(place);
|
||||
return data;
|
||||
};
|
||||
|
||||
/* virtual char *readNextFrame(ifstream &filebin, int& fnum) { */
|
||||
/* char *data=new char[packetSize*nPackets]; */
|
||||
/* char *retval=0; */
|
||||
/* int np=0, nd; */
|
||||
/* fnum = -1; */
|
||||
/* int pn; */
|
||||
/* char aa[8224]; */
|
||||
/* char *packet=(char *)aa; */
|
||||
|
||||
/* if (filebin.is_open()) { */
|
||||
|
||||
|
||||
|
||||
|
||||
/* while(filebin.read((char*)packet, 8208) && np<nPackets){ */
|
||||
/* pn=getPacketNumber(packet); */
|
||||
|
||||
/* if (pn==1 && fnum<0) */
|
||||
/* fnum= getFrameNumber(packet); */
|
||||
|
||||
/* // cout << "fn: " << fnum << "\t pn: " << pn << endl; */
|
||||
/* if (fnum>=0) { */
|
||||
/* if (getFrameNumber(packet) !=fnum) { */
|
||||
|
||||
/* if (np==0){ */
|
||||
/* delete [] data; */
|
||||
/* return NULL; */
|
||||
/* } else */
|
||||
/* return data; */
|
||||
/* } */
|
||||
|
||||
/* memcpy(data+(pn-1)*packetSize, packet, packetSize); */
|
||||
/* np++; */
|
||||
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* } */
|
||||
|
||||
/* if (np==0){ */
|
||||
/* delete [] data; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
|
||||
/* }; */
|
||||
|
||||
int getPacketNumber(int x, int y) {return dataMap[y][x]/8208;};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
284
slsDetectorCalibration/dataStructures/moench03Ctb10GbT1Data.h
Normal file
284
slsDetectorCalibration/dataStructures/moench03Ctb10GbT1Data.h
Normal file
@ -0,0 +1,284 @@
|
||||
#ifndef MOENCH03CTB10GBT1DATA_H
|
||||
#define MOENCH03CTB10GBT1DATA_H
|
||||
#include "slsReceiverData.h"
|
||||
|
||||
|
||||
|
||||
class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
moench03Ctb10GbT1Data(int ns=5000): slsReceiverData<uint16_t>(400, 400, 40, 8208), nadc(32), sc_width(25), sc_height(200) {
|
||||
|
||||
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (adc4%2==0) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=8208*40)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ipacket;
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
for (int ipacket=0; ipacket<npackets; ipacket++) {
|
||||
for (int ibyte=0; ibyte< 8208/2; ibyte++) {
|
||||
i=ipacket*8208/2+ibyte;
|
||||
if (ibyte<8) {
|
||||
//header!
|
||||
xmap[i]=-1;
|
||||
ymap[i]=-1;
|
||||
} else {
|
||||
// ii=ibyte+128*32*ipacket;
|
||||
isample=ii/nadc;
|
||||
iadc=ii%nadc;
|
||||
adc4 = (int)iadc/4;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (adc4%2==0) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return *((int*)(buff+5))&0xffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return ((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[packetSize*nPackets];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
char aa[8224];
|
||||
char *packet=(char *)aa;
|
||||
// cout << packetSize*nPackets << endl;
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
|
||||
|
||||
|
||||
|
||||
while(filebin.read((char*)packet, 8208) ){
|
||||
pn=getPacketNumber(packet);
|
||||
|
||||
if (fnum<0)
|
||||
fnum= getFrameNumber(packet);
|
||||
|
||||
// cout << "fn: " << fnum << "\t pn: " << pn << endl;
|
||||
if (fnum>=0) {
|
||||
if (getFrameNumber(packet) !=fnum) {
|
||||
|
||||
if (np==0){
|
||||
// delete [] data;
|
||||
return NULL;
|
||||
} else
|
||||
filebin.seekg(-8208,ios_base::cur);
|
||||
return data;
|
||||
}
|
||||
if (pn>nPackets) {
|
||||
cout << "Bad packet number " << pn << endl;
|
||||
}
|
||||
|
||||
memcpy(data+(pn-1)*packetSize, packet, packetSize);
|
||||
np++;
|
||||
|
||||
if (np==nPackets)
|
||||
break;
|
||||
|
||||
if (pn==nPackets)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (np==0){
|
||||
// delete [] data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ff=fnum;
|
||||
return data;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int getPacketNumber(int x, int y) {return dataMap[y][x]/8208;};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
157
slsDetectorCalibration/dataStructures/moench03CtbData.h
Normal file
157
slsDetectorCalibration/dataStructures/moench03CtbData.h
Normal file
@ -0,0 +1,157 @@
|
||||
#ifndef MOENCH03CTBDATA_H
|
||||
#define MOENCH03CTBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench03CtbData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench03CtbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int adc_nr[32]={200,225,250,275,300,325,350,375,\
|
||||
0,25,50,75,100,125,150,175,\
|
||||
175,150,125,100,75,50,25,0,\
|
||||
375,350,325,300,275,250,225,200};
|
||||
|
||||
/* int adc_nr[32]={300,325,350,375,300,325,350,375, \ */
|
||||
/* 200,225,250,275,200,225,250,275,\ */
|
||||
/* 100,125,150,175,100,125,150,175,\ */
|
||||
/* 0,25,50,75,0,25,50,75}; */
|
||||
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (iadc<16) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=2*400*400)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
|
||||
}
|
||||
}
|
||||
for (int i=0; i<nx*ny; i++) {
|
||||
isample=i/nadc;
|
||||
iadc=i%nadc;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (iadc<(nadc/2)) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
// cout << ib << "-" << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
158
slsDetectorCalibration/dataStructures/moench03T1CtbData.h
Normal file
158
slsDetectorCalibration/dataStructures/moench03T1CtbData.h
Normal file
@ -0,0 +1,158 @@
|
||||
#ifndef MOENCH03T1CTBDATA_H
|
||||
#define MOENCH03T1CTBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench03T1CtbData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench03T1CtbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (iadc<16) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=2*400*400)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
|
||||
}
|
||||
}
|
||||
int adc4;
|
||||
for (int i=0; i<nx*ny; i++) {
|
||||
isample=i/nadc;
|
||||
iadc=i%nadc;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
adc4 = (int)iadc/4;
|
||||
// if (iadc<(nadc/2)) {
|
||||
if (adc4%2==0) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
// cout << ib << "-" << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
285
slsDetectorCalibration/dataStructures/moench03T1ReceiverData.h
Normal file
285
slsDetectorCalibration/dataStructures/moench03T1ReceiverData.h
Normal file
@ -0,0 +1,285 @@
|
||||
#ifndef MOENCH03T1ZMQDATA_H
|
||||
#define MOENCH03T1ZMQDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
/**
|
||||
@short structure for a Detector Packet or Image Header
|
||||
@li frameNumber is the frame number
|
||||
@li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others)
|
||||
@li packetNumber is the packet number
|
||||
@li bunchId is the bunch id from beamline
|
||||
@li timestamp is the time stamp with 10 MHz clock
|
||||
@li modId is the unique module id (unique even for left, right, top, bottom)
|
||||
@li xCoord is the x coordinate in the complete detector system
|
||||
@li yCoord is the y coordinate in the complete detector system
|
||||
@li zCoord is the z coordinate in the complete detector system
|
||||
@li debug is for debugging purposes
|
||||
@li roundRNumber is the round robin set number
|
||||
@li detType is the detector type see :: detectorType
|
||||
@li version is the version number of this structure format
|
||||
*/
|
||||
typedef struct {
|
||||
uint64_t frameNumber; /**< is the frame number */
|
||||
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */
|
||||
uint32_t packetNumber; /**< is the packet number */
|
||||
uint64_t bunchId; /**< is the bunch id from beamline */
|
||||
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
|
||||
uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */
|
||||
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
|
||||
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
|
||||
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
|
||||
uint32_t debug; /**< is for debugging purposes */
|
||||
uint16_t roundRNumber; /**< is the round robin set number */
|
||||
uint8_t detType; /**< is the detector type see :: detectorType */
|
||||
uint8_t version; /**< is the version number of this structure format */
|
||||
} sls_detector_header;
|
||||
|
||||
|
||||
|
||||
|
||||
class moench03T1ReceiverData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
const int nPackets; /**<number of UDP packets constituting one frame */
|
||||
const int packetSize; /**< size of a udp packet */
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
moench03T1ReceiverData(int npackets=40, int ps=8192): slsDetectorData<uint16_t>(400, 400, ps*npackets+sizeof(sls_detector_header)), packetSize(ps), nPackets(npackets) {
|
||||
|
||||
int nadc=32;
|
||||
int sc_width=25;
|
||||
int sc_height=200;
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
// int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (adc4%2==0) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=8192*40)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ipacket;
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){
|
||||
xmap[ibyte]=-1;
|
||||
ymap[ibyte]=-1;
|
||||
}
|
||||
int off=sizeof(sls_detector_header)/2;
|
||||
for (ipacket=0; ipacket<npackets; ipacket++) {
|
||||
for (ibyte=0; ibyte< 8192/2; ibyte++) {
|
||||
i=ipacket*8208/2+ibyte;
|
||||
isample=ii/nadc;
|
||||
iadc=ii%nadc;
|
||||
adc4 = (int)iadc/4;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (adc4%2==0) {
|
||||
xmap[i+off]=adc_nr[iadc]+ix;
|
||||
ymap[i+off]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i+off]=adc_nr[iadc]+ix;
|
||||
ymap[i+off]=ny/2+iy;
|
||||
}
|
||||
|
||||
ii++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return ((sls_detector_header*)buff)->frameNumber;};//*((int*)(buff+5))&0xffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[dataSize];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
// cout << dataSize << endl;
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, dataSize) ){
|
||||
ff=getFrameNumber(data);
|
||||
np=getPacketNumber(data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<dataSize) ndata=dsize;
|
||||
else ndata=dataSize;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
268
slsDetectorCalibration/dataStructures/moench03T1ZmqData.h
Normal file
268
slsDetectorCalibration/dataStructures/moench03T1ZmqData.h
Normal file
@ -0,0 +1,268 @@
|
||||
#ifndef MOENCH03T1ZMQDATA_H
|
||||
#define MOENCH03T1ZMQDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench03T1ZmqData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
const int nPackets; /**<number of UDP packets constituting one frame */
|
||||
const int packetSize; /**< size of a udp packet */
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
moench03T1ZmqData(int npackets=40, int ps=8192): slsDetectorData<uint16_t>(400, 400, ps*npackets), packetSize(ps), nPackets(npackets) {
|
||||
|
||||
int nadc=32;
|
||||
int sc_width=25;
|
||||
int sc_height=200;
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
// int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (adc4%2==0) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;//+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=8192*40)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ipacket;
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
for (int ipacket=0; ipacket<npackets; ipacket++) {
|
||||
for (int ibyte=0; ibyte< 8192/2; ibyte++) {
|
||||
i=ipacket*8208/2+ibyte;
|
||||
/* if (ibyte<8) { */
|
||||
/* //header! */
|
||||
/* xmap[i]=-1; */
|
||||
/* ymap[i]=-1; */
|
||||
/* } else { */
|
||||
// ii=ibyte+128*32*ipacket;
|
||||
isample=ii/nadc;
|
||||
iadc=ii%nadc;
|
||||
adc4 = (int)iadc/4;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (adc4%2==0) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
ii++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return iframe;};//*((int*)(buff+5))&0xffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return 0;}//((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[packetSize*nPackets];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, packetSize*nPackets) ){
|
||||
iframe++;
|
||||
ff=iframe;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<packetSize*nPackets) ndata=dsize;
|
||||
else ndata=packetSize*nPackets;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
268
slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h
Normal file
268
slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h
Normal file
@ -0,0 +1,268 @@
|
||||
#ifndef MOENCH03T1ZMQDATANEW_H
|
||||
#define MOENCH03T1ZMQDATANEW_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
const int nSamples;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
moench03T1ZmqDataNew(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*32*2), nSamples(ns) {
|
||||
|
||||
int nadc=32;
|
||||
int sc_width=25;
|
||||
int sc_height=200;
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (adc4%2==0) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;//+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=nSamples*2*32)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ipacket;
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
for (int ipacket=0; ipacket<npackets; ipacket++) {
|
||||
for (int ibyte=0; ibyte< 8192/2; ibyte++) {
|
||||
i=ipacket*8208/2+ibyte;
|
||||
/* if (ibyte<8) { */
|
||||
/* //header! */
|
||||
/* xmap[i]=-1; */
|
||||
/* ymap[i]=-1; */
|
||||
/* } else { */
|
||||
// ii=ibyte+128*32*ipacket;
|
||||
isample=ii/nadc;
|
||||
if (isample<nSamples) {
|
||||
iadc=ii%nadc;
|
||||
adc4 = (int)iadc/4;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (adc4%2==0) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
}
|
||||
|
||||
ii++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return iframe;};//*((int*)(buff+5))&0xffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return 0;}//((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[32*2*nSamples];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, 32*2*nSamples) ){
|
||||
iframe++;
|
||||
ff=iframe;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<32*2*nSamples) ndata=dsize;
|
||||
else ndata=32*2*nSamples;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int getPacketNumber(int x, int y) {return 0;};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
285
slsDetectorCalibration/dataStructures/moench03TCtb10GbData.h
Normal file
285
slsDetectorCalibration/dataStructures/moench03TCtb10GbData.h
Normal file
@ -0,0 +1,285 @@
|
||||
#ifndef MOENCH03TCTB10GBDATA_H
|
||||
#define MOENCH03TCTB10GBDATA_H
|
||||
#include "moench03Ctb10GbData.h"
|
||||
|
||||
|
||||
|
||||
class moench03TCtb10GbData : public moench03Ctb10GbData { //slsReceiverData<uint16_t> {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// moench03TCtb10GbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, 8208*40, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
moench03TCtb10GbData(int ns=5000): moench03Ctb10GbData(ns) {//slsReceiverData<uint16_t>(400, 400, 40, 8208), nadc(32), sc_width(25), sc_height(200) {
|
||||
// cout <<"constructor"<< endl;
|
||||
// nadc=32;
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
//cout << i << endl;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (adc4%2==0) {
|
||||
// if (iadc<(nadc/2)) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=8208*40)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// cout <<"map"<< endl;
|
||||
int ipacket;
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
for (int ipacket=0; ipacket<npackets; ipacket++) {
|
||||
for (int ibyte=0; ibyte< 8208/2; ibyte++) {
|
||||
i=ipacket*8208/2+ibyte;
|
||||
// cout << i << " ";
|
||||
if (ibyte<8) {
|
||||
//header!
|
||||
xmap[i]=-1;
|
||||
ymap[i]=-1;
|
||||
} else {
|
||||
// ii=ibyte+128*32*ipacket;
|
||||
// cout << nadc << endl;
|
||||
isample=ii/nadc;
|
||||
iadc=ii%nadc;
|
||||
|
||||
adc4 = (int)iadc/4;
|
||||
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
// cout << isample << " " << iadc << " " << ix << " " << iy ;//<< endl;
|
||||
if (adc4%2==0) {//iadc<(nadc/2)) {
|
||||
//if (iadc<(nadc/2)) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* int ipacket; */
|
||||
/* int ibyte; */
|
||||
/* int ii=0; */
|
||||
|
||||
/* for (int ipacket=0; ipacket<npackets; ipacket++) { */
|
||||
/* for (int ibyte=0; ibyte< 8208/2; ibyte++) { */
|
||||
/* i=ipacket*8208/2+ibyte; */
|
||||
/* cout << i << endl; */
|
||||
/* if (ibyte<8) { */
|
||||
/* //header! */
|
||||
/* xmap[i]=-1; */
|
||||
/* ymap[i]=-1; */
|
||||
/* } else { */
|
||||
/* ii=ibyte+128*32*ipacket; */
|
||||
/* isample=ii/nadc; */
|
||||
/* iadc=ii%nadc; */
|
||||
/* adc4 = (int)iadc/4; */
|
||||
|
||||
/* ix=isample%sc_width; */
|
||||
/* iy=isample/sc_width; */
|
||||
/* if (adc4%2==0) { */
|
||||
/* xmap[i]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i]=ny/2-1-iy; */
|
||||
|
||||
|
||||
|
||||
/* } else { */
|
||||
/* xmap[i]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i]=ny/2+iy; */
|
||||
|
||||
/* } */
|
||||
|
||||
/* ii++; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
// cout <<"done"<< endl;
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Returns the frame number for the given dataset. Purely virtual func. */
|
||||
/* \param buff pointer to the dataset */
|
||||
/* \returns frame number */
|
||||
|
||||
/* *\/ */
|
||||
|
||||
|
||||
/* int getFrameNumber(char *buff){return *((int*)buff)&0xffffffff;}; */
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Returns the packet number for the given dataset. purely virtual func */
|
||||
/* \param buff pointer to the dataset */
|
||||
/* \returns packet number number */
|
||||
|
||||
|
||||
|
||||
/* *\/ */
|
||||
/* int getPacketNumber(char *buff){return ((*(((int*)(buff+4))))&0xff)+1;}; */
|
||||
|
||||
/* /\* /\\** *\/ */
|
||||
|
||||
/* /\* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func *\/ */
|
||||
/* /\* \param data pointer to the memory to be analyzed *\/ */
|
||||
/* /\* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot *\/ */
|
||||
/* /\* \param dsize size of the memory slot to be analyzed *\/ */
|
||||
/* /\* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found *\/ */
|
||||
|
||||
/* /\* *\\/ *\/ */
|
||||
/* /\* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; *\/ */
|
||||
|
||||
|
||||
/* /\* /\\** *\/ */
|
||||
|
||||
/* /\* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! *\/ */
|
||||
/* /\* \param filebin input file stream (binary) *\/ */
|
||||
/* /\* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete *\/ */
|
||||
|
||||
/* /\* *\\/ *\/ */
|
||||
/* /\* virtual char *readNextFrame(ifstream &filebin){ *\/ */
|
||||
/* /\* // int afifo_length=0; *\/ */
|
||||
/* /\* uint16_t *afifo_cont; *\/ */
|
||||
/* /\* int ib=0; *\/ */
|
||||
/* /\* if (filebin.is_open()) { *\/ */
|
||||
/* /\* afifo_cont=new uint16_t[dataSize/2]; *\/ */
|
||||
/* /\* while (filebin.read(((char*)afifo_cont)+ib,2)) { *\/ */
|
||||
/* /\* ib+=2; *\/ */
|
||||
/* /\* if (ib==dataSize) break; *\/ */
|
||||
/* /\* } *\/ */
|
||||
/* /\* if (ib>0) { *\/ */
|
||||
/* /\* iframe++; *\/ */
|
||||
/* /\* // cout << ib << "-" << endl; *\/ */
|
||||
/* /\* return (char*)afifo_cont; *\/ */
|
||||
/* /\* } else { *\/ */
|
||||
/* /\* delete [] afifo_cont; *\/ */
|
||||
/* /\* return NULL; *\/ */
|
||||
/* /\* } *\/ */
|
||||
/* /\* } *\/ */
|
||||
/* /\* return NULL; *\/ */
|
||||
/* /\* }; *\/ */
|
||||
|
||||
|
||||
/* virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) { */
|
||||
/* char *data=new char[packetSize*nPackets]; */
|
||||
/* char *retval=0; */
|
||||
/* int nd; */
|
||||
/* np=0; */
|
||||
/* int pn; */
|
||||
/* char aa[8224]={0}; */
|
||||
/* char *packet=(char *)aa; */
|
||||
/* int fnum = -1; */
|
||||
|
||||
/* if (ff>=0) */
|
||||
/* fnum=ff; */
|
||||
|
||||
/* if (filebin.is_open()) { */
|
||||
|
||||
|
||||
/* cout << "+"; */
|
||||
|
||||
/* while(filebin.read((char*)packet, 8208)){ */
|
||||
|
||||
/* pn=getPacketNumber(packet); */
|
||||
|
||||
/* if (fnum<0) */
|
||||
/* fnum= getFrameNumber(packet); */
|
||||
|
||||
/* if (fnum>=0) { */
|
||||
/* if (getFrameNumber(packet) !=fnum) { */
|
||||
|
||||
/* if (np==0){ */
|
||||
/* cout << "-"; */
|
||||
/* delete [] data; */
|
||||
/* return NULL; */
|
||||
/* } else */
|
||||
/* filebin.seekg(-8208,ios_base::cur); */
|
||||
|
||||
/* return data; */
|
||||
/* } */
|
||||
|
||||
/* memcpy(data+(pn-1)*packetSize, packet, packetSize); */
|
||||
/* np++; */
|
||||
/* if (np==nPackets) */
|
||||
/* break; */
|
||||
/* if (pn==nPackets) */
|
||||
/* break; */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* } */
|
||||
|
||||
/* if (np==0){ */
|
||||
/* cout << "?"; */
|
||||
/* delete [] data; */
|
||||
/* return NULL; */
|
||||
/* }// else if (np<nPackets) */
|
||||
/* // cout << "Frame " << fnum << " lost " << nPackets-np << " packets " << endl; */
|
||||
|
||||
/* return data; */
|
||||
|
||||
/* }; */
|
||||
|
||||
/* int getPacketNumber(int x, int y) {return dataMap[y][x]/8208;}; */
|
||||
|
||||
/* virtual char *readNextFrame(ifstream &filebin) { */
|
||||
/* int fnum=-1, np; */
|
||||
/* return readNextFrame(filebin, fnum, np); */
|
||||
/* }; */
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
180
slsDetectorCalibration/dataStructures/moench03TCtbData.h
Normal file
180
slsDetectorCalibration/dataStructures/moench03TCtbData.h
Normal file
@ -0,0 +1,180 @@
|
||||
#ifndef MOENCH03TCTBDATA_H
|
||||
#define MOENCH03TCTBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench03TCtbData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench03TCtbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
|
||||
|
||||
/* int adc_nr[32]={200,225,250,275,300,325,350,375,\ */
|
||||
/* 0,25,50,75,100,125,150,175,\ */
|
||||
/* 175,150,125,100,75,50,25,0,\ */
|
||||
/* 375,350,325,300,275,250,225,200}; */
|
||||
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (iadc<16) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=2*400*400)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
|
||||
}
|
||||
}
|
||||
int adc4;
|
||||
for (int i=0; i<nx*ny; i++) {
|
||||
isample=i/nadc;
|
||||
iadc=i%nadc;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
adc4 = (int)iadc/4;
|
||||
// if (iadc<(nadc/2)) {
|
||||
if (adc4%2==0) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* for (int i=0; i<nx*ny; i++) { */
|
||||
/* isample=i/nadc; */
|
||||
/* iadc=i%nadc; */
|
||||
/* ix=isample%sc_width; */
|
||||
/* iy=isample/sc_width; */
|
||||
/* if (iadc<(nadc/2)) { */
|
||||
/* xmap[i]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i]=ny/2-1-iy; */
|
||||
/* } else { */
|
||||
/* xmap[i]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i]=ny/2+iy; */
|
||||
/* } */
|
||||
|
||||
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
// cout << ib << "-" << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
85
slsDetectorCalibration/doxy.config
Normal file
85
slsDetectorCalibration/doxy.config
Normal file
@ -0,0 +1,85 @@
|
||||
# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
|
||||
# documentation are documented, even if no documentation was available.
|
||||
# Private class members and static file members will be hidden unless
|
||||
# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
|
||||
|
||||
EXTRACT_ALL = YES
|
||||
|
||||
# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
|
||||
# will be included in the documentation.
|
||||
|
||||
EXTRACT_PRIVATE = NO
|
||||
|
||||
|
||||
|
||||
# If the EXTRACT_STATIC tag is set to YES all static members of a file
|
||||
# will be included in the documentation.
|
||||
|
||||
EXTRACT_STATIC = YES
|
||||
|
||||
# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
|
||||
# defined locally in source files will be included in the documentation.
|
||||
# If set to NO only classes defined in header files are included.
|
||||
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
|
||||
# This flag is only useful for Objective-C code. When set to YES local
|
||||
# methods, which are defined in the implementation section but not in
|
||||
# the interface are included in the documentation.
|
||||
# If set to NO (the default) only methods in the interface are included.
|
||||
|
||||
EXTRACT_LOCAL_METHODS = YES
|
||||
|
||||
# If this flag is set to YES, the members of anonymous namespaces will be
|
||||
# extracted and appear in the documentation as a namespace called
|
||||
# 'anonymous_namespace{file}', where file will be replaced with the base
|
||||
# name of the file that contains the anonymous namespace. By default
|
||||
# anonymous namespace are hidden.
|
||||
|
||||
EXTRACT_ANON_NSPACES = NO
|
||||
|
||||
# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
|
||||
# undocumented members of documented classes, files or namespaces.
|
||||
# If set to NO (the default) these members will be included in the
|
||||
# various overviews, but no documentation section is generated.
|
||||
# This option has no effect if EXTRACT_ALL is enabled.
|
||||
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
|
||||
# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
|
||||
# undocumented classes that are normally visible in the class hierarchy.
|
||||
# If set to NO (the default) these classes will be included in the various
|
||||
# overviews. This option has no effect if EXTRACT_ALL is enabled.
|
||||
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
|
||||
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
|
||||
# friend (class|struct|union) declarations.
|
||||
# If set to NO (the default) these declarations will be included in the
|
||||
# documentation.
|
||||
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
|
||||
INTERNAL_DOCS = NO
|
||||
|
||||
SHOW_INCLUDE_FILES = NO
|
||||
|
||||
SHOW_FILES = NO
|
||||
|
||||
SHOW_NAMESPACES = NO
|
||||
|
||||
COMPACT_LATEX = YES
|
||||
|
||||
PAPER_TYPE = a4
|
||||
|
||||
PDF_HYPERLINKS = YES
|
||||
|
||||
USE_PDFLATEX = YES
|
||||
|
||||
LATEX_HIDE_INDICES = YES
|
||||
|
||||
PREDEFINED = __cplusplus
|
||||
|
||||
INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h chiptestBoardData.h jungfrau02Data.h jungfrauReadData.C jungfrau02CommonMode.h
|
||||
OUTPUT_DIRECTORY = docs
|
||||
|
534
slsDetectorCalibration/energyCalibration.cpp
Normal file
534
slsDetectorCalibration/energyCalibration.cpp
Normal file
@ -0,0 +1,534 @@
|
||||
#include "energyCalibration.h"
|
||||
|
||||
#ifdef __CINT
|
||||
#define MYROOT
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MYROOT
|
||||
#include <TMath.h>
|
||||
#include <TH1F.h>
|
||||
#include <TH2F.h>
|
||||
#include <TGraphErrors.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef MYROOT
|
||||
|
||||
Double_t energyCalibrationFunctions::pedestal(Double_t *x, Double_t *par) {
|
||||
return par[0]-par[1]*sign*x[0];
|
||||
}
|
||||
|
||||
|
||||
Double_t energyCalibrationFunctions::gaussChargeSharing(Double_t *x, Double_t *par) {
|
||||
Double_t f, arg=0;
|
||||
if (par[3]!=0) arg=sign*(x[0]-par[2])/par[3];
|
||||
f=TMath::Exp(-1*arg*arg/2.);
|
||||
f=f+par[5]/2.*(TMath::Erfc(arg/(TMath::Sqrt(2.))));
|
||||
return par[4]*f+pedestal(x,par);
|
||||
}
|
||||
|
||||
Double_t energyCalibrationFunctions::gaussChargeSharingPixel(Double_t *x, Double_t *par) {
|
||||
Double_t f;
|
||||
if (par[3]<=0 || par[2]*(*x)<=0 || par[5]<0 || par[4]<=0) return 0;
|
||||
|
||||
Double_t pp[3];
|
||||
|
||||
pp[0]=0;
|
||||
pp[1]=par[2];
|
||||
pp[2]=par[3];
|
||||
|
||||
|
||||
f=(par[5]-par[6]*(TMath::Log(*x/par[2])))*erfBox(x,pp);
|
||||
f+=par[4]*TMath::Gaus(*x, par[2], par[3], kTRUE);
|
||||
return f+pedestal(x,par);
|
||||
}
|
||||
|
||||
Double_t energyCalibrationFunctions::erfBox(Double_t *z, Double_t *par) {
|
||||
|
||||
|
||||
|
||||
Double_t m=par[0];
|
||||
Double_t M=par[1];
|
||||
|
||||
if (par[0]>par[1]) {
|
||||
m=par[1];
|
||||
M=par[0];
|
||||
}
|
||||
|
||||
if (m==M)
|
||||
return 0;
|
||||
|
||||
|
||||
if (par[2]<=0) {
|
||||
if (*z>=m && *z<=M)
|
||||
return 1./(M-m);
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
return (TMath::Erfc((z[0]-M)/par[2])-TMath::Erfc((z[0]-m)/par[2]))*0.5/(M-m);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// basic erf function
|
||||
Double_t energyCalibrationFunctions::erfFunction(Double_t *x, Double_t *par) {
|
||||
double arg=0;
|
||||
if (par[1]!=0) arg=(par[0]-x[0])/par[1];
|
||||
return ((par[2]/2.*(1+TMath::Erf(sign*arg/(TMath::Sqrt(2))))));
|
||||
};
|
||||
|
||||
|
||||
Double_t energyCalibrationFunctions::erfFunctionChargeSharing(Double_t *x, Double_t *par) {
|
||||
Double_t f;
|
||||
|
||||
f=erfFunction(x, par+2)*(1+par[5]*(par[2]-x[0]))+par[0]-par[1]*x[0]*sign;
|
||||
return f;
|
||||
};
|
||||
|
||||
|
||||
Double_t energyCalibrationFunctions::erfFuncFluo(Double_t *x, Double_t *par) {
|
||||
Double_t f;
|
||||
f=erfFunctionChargeSharing(x, par)+erfFunction(x, par+6)*(1+par[9]*(par[6]-x[0]));
|
||||
return f;
|
||||
};
|
||||
#endif
|
||||
|
||||
double energyCalibrationFunctions::median(double *x, int n){
|
||||
// sorts x into xmed array and returns median
|
||||
// n is number of values already in the xmed array
|
||||
double xmed[n];
|
||||
int k,i,j;
|
||||
|
||||
for (i=0; i<n; i++) {
|
||||
k=0;
|
||||
for (j=0; j<n; j++) {
|
||||
if(*(x+i)>*(x+j))
|
||||
k++;
|
||||
if (*(x+i)==*(x+j)) {
|
||||
if (i>j)
|
||||
k++;
|
||||
}
|
||||
}
|
||||
xmed[k]=*(x+i);
|
||||
}
|
||||
k=n/2;
|
||||
return xmed[k];
|
||||
}
|
||||
|
||||
|
||||
int energyCalibrationFunctions::quick_select(int arr[], int n){
|
||||
int low, high ;
|
||||
int median;
|
||||
int middle, ll, hh;
|
||||
|
||||
low = 0 ; high = n-1 ; median = (low + high) / 2;
|
||||
for (;;) {
|
||||
if (high <= low) /* One element only */
|
||||
return arr[median] ;
|
||||
|
||||
if (high == low + 1) { /* Two elements only */
|
||||
if (arr[low] > arr[high])
|
||||
ELEM_SWAP(arr[low], arr[high]) ;
|
||||
return arr[median] ;
|
||||
}
|
||||
|
||||
/* Find median of low, middle and high items; swap into position low */
|
||||
middle = (low + high) / 2;
|
||||
if (arr[middle] > arr[high]) ELEM_SWAP(arr[middle], arr[high]) ;
|
||||
if (arr[low] > arr[high]) ELEM_SWAP(arr[low], arr[high]) ;
|
||||
if (arr[middle] > arr[low]) ELEM_SWAP(arr[middle], arr[low]) ;
|
||||
|
||||
/* Swap low item (now in position middle) into position (low+1) */
|
||||
ELEM_SWAP(arr[middle], arr[low+1]) ;
|
||||
|
||||
/* Nibble from each end towards middle, swapping items when stuck */
|
||||
ll = low + 1;
|
||||
hh = high;
|
||||
for (;;) {
|
||||
do ll++; while (arr[low] > arr[ll]) ;
|
||||
do hh--; while (arr[hh] > arr[low]) ;
|
||||
|
||||
if (hh < ll)
|
||||
break;
|
||||
|
||||
ELEM_SWAP(arr[ll], arr[hh]) ;
|
||||
}
|
||||
|
||||
/* Swap middle item (in position low) back into correct position */
|
||||
ELEM_SWAP(arr[low], arr[hh]) ;
|
||||
|
||||
/* Re-set active partition */
|
||||
if (hh <= median)
|
||||
low = ll;
|
||||
if (hh >= median)
|
||||
high = hh - 1;
|
||||
}
|
||||
}
|
||||
|
||||
int energyCalibrationFunctions::kth_smallest(int *a, int n, int k){
|
||||
register int i,j,l,m ;
|
||||
register double x ;
|
||||
|
||||
l=0 ; m=n-1 ;
|
||||
while (l<m) {
|
||||
x=a[k] ;
|
||||
i=l ;
|
||||
j=m ;
|
||||
do {
|
||||
while (a[i]<x) i++ ;
|
||||
while (x<a[j]) j-- ;
|
||||
if (i<=j) {
|
||||
ELEM_SWAP(a[i],a[j]) ;
|
||||
i++ ; j-- ;
|
||||
}
|
||||
} while (i<=j) ;
|
||||
if (j<k) l=i ;
|
||||
if (k<i) m=j ;
|
||||
}
|
||||
return a[k] ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef MYROOT
|
||||
Double_t energyCalibrationFunctions::spectrum(Double_t *x, Double_t *par) {
|
||||
return gaussChargeSharing(x,par);
|
||||
}
|
||||
|
||||
Double_t energyCalibrationFunctions::spectrumPixel(Double_t *x, Double_t *par) {
|
||||
return gaussChargeSharingPixel(x,par);
|
||||
}
|
||||
|
||||
|
||||
Double_t energyCalibrationFunctions::scurve(Double_t *x, Double_t *par) {
|
||||
return erfFunctionChargeSharing(x,par);
|
||||
}
|
||||
|
||||
|
||||
Double_t energyCalibrationFunctions::scurveFluo(Double_t *x, Double_t *par) {
|
||||
return erfFuncFluo(x,par);
|
||||
}
|
||||
#endif
|
||||
|
||||
energyCalibration::energyCalibration() :
|
||||
#ifdef MYROOT
|
||||
fit_min(-1),
|
||||
fit_max(-1),
|
||||
bg_offset(-1),
|
||||
bg_slope(-1),
|
||||
flex(-1),
|
||||
noise(-1),
|
||||
ampl(-1),
|
||||
cs_slope(-1),
|
||||
fscurve(NULL),
|
||||
fspectrum(NULL),
|
||||
#endif
|
||||
funcs(NULL),
|
||||
plot_flag(1), // fit parameters output to screen
|
||||
cs_flag(1)
|
||||
{
|
||||
|
||||
#ifdef MYROOT
|
||||
funcs=new energyCalibrationFunctions();
|
||||
|
||||
fscurve=new TF1("fscurve",funcs,&energyCalibrationFunctions::scurve,0,1000,6,"energyCalibrationFunctions","scurve");
|
||||
fscurve->SetParNames("Background Offset","Background Slope","Inflection Point","Noise RMS", "Number of Photons","Charge Sharing Slope");
|
||||
|
||||
fspectrum=new TF1("fspectrum",funcs,&energyCalibrationFunctions::spectrum,0,1000,6,"energyCalibrationFunctions","spectrum");
|
||||
fspectrum->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal");
|
||||
|
||||
fspixel=new TF1("fspixel",funcs,&energyCalibrationFunctions::spectrumPixel,0,1000,7,"energyCalibrationFunctions","spectrumPixel");
|
||||
fspixel->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal","Corner");
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void energyCalibration::fixParameter(int ip, Double_t val){
|
||||
|
||||
fscurve->FixParameter(ip, val);
|
||||
fspectrum->FixParameter(ip, val);
|
||||
}
|
||||
|
||||
|
||||
void energyCalibration::releaseParameter(int ip){
|
||||
|
||||
fscurve->ReleaseParameter(ip);
|
||||
fspectrum->ReleaseParameter(ip);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
energyCalibration::~energyCalibration(){
|
||||
#ifdef MYROOT
|
||||
delete fscurve;
|
||||
delete fspectrum;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifdef MYROOT
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch, int direction) {
|
||||
|
||||
if (h2==NULL || nch==0)
|
||||
return NULL;
|
||||
|
||||
double *x=new double[nch];
|
||||
TH1F *h1=NULL;
|
||||
|
||||
double val=-1;
|
||||
|
||||
if (direction==0) {
|
||||
h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax());
|
||||
for (int ib=0; ib<h1->GetXaxis()->GetNbins(); ib++) {
|
||||
for (int ich=0; ich<nch; ich++) {
|
||||
x[ich]=h2->GetBinContent(ch0+ich+1,ib+1);
|
||||
}
|
||||
val=energyCalibrationFunctions::median(x, nch);
|
||||
h1->SetBinContent(ib+1,val);
|
||||
}
|
||||
} else if (direction==1) {
|
||||
h1=new TH1F("median","Median",h2->GetXaxis()->GetNbins(),h2->GetXaxis()->GetXmin(),h2->GetXaxis()->GetXmax());
|
||||
for (int ib=0; ib<h1->GetYaxis()->GetNbins(); ib++) {
|
||||
for (int ich=0; ich<nch; ich++) {
|
||||
x[ich]=h2->GetBinContent(ib+1,ch0+ich+1);
|
||||
}
|
||||
val=energyCalibrationFunctions::median(x, nch);
|
||||
h1->SetBinContent(ib+1,val);
|
||||
}
|
||||
}
|
||||
delete [] x;
|
||||
|
||||
return h1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void energyCalibration::setStartParameters(Double_t *par){
|
||||
bg_offset=par[0];
|
||||
bg_slope=par[1];
|
||||
flex=par[2];
|
||||
noise=par[3];
|
||||
ampl=par[4];
|
||||
cs_slope=par[5];
|
||||
}
|
||||
|
||||
|
||||
void energyCalibration::getStartParameters(Double_t *par){
|
||||
par[0]=bg_offset;
|
||||
par[1]=bg_slope;
|
||||
par[2]=flex;
|
||||
par[3]=noise;
|
||||
par[4]=ampl;
|
||||
par[5]=cs_slope;
|
||||
}
|
||||
|
||||
#endif
|
||||
int energyCalibration::setChargeSharing(int p) {
|
||||
if (p>=0) {
|
||||
cs_flag=p;
|
||||
#ifdef MYROOT
|
||||
if (p) {
|
||||
fscurve->ReleaseParameter(5);
|
||||
fspectrum->ReleaseParameter(1);
|
||||
} else {
|
||||
fscurve->FixParameter(5,0);
|
||||
fspectrum->FixParameter(1,0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return cs_flag;
|
||||
}
|
||||
|
||||
|
||||
#ifdef MYROOT
|
||||
void energyCalibration::initFitFunction(TF1 *fun, TH1 *h1) {
|
||||
|
||||
Double_t min=fit_min, max=fit_max;
|
||||
|
||||
Double_t mypar[6];
|
||||
|
||||
if (max==-1)
|
||||
max=h1->GetXaxis()->GetXmax();
|
||||
|
||||
if (min==-1)
|
||||
min=h1->GetXaxis()->GetXmin();
|
||||
|
||||
|
||||
if (bg_offset==-1)
|
||||
mypar[0]=0;
|
||||
else
|
||||
mypar[0]=bg_offset;
|
||||
|
||||
|
||||
if (bg_slope==-1)
|
||||
mypar[1]=0;
|
||||
else
|
||||
mypar[1]=bg_slope;
|
||||
|
||||
|
||||
if (flex==-1)
|
||||
mypar[2]=(min+max)/2.;
|
||||
else
|
||||
mypar[2]=flex;
|
||||
|
||||
|
||||
if (noise==-1)
|
||||
mypar[3]=0.1;
|
||||
else
|
||||
mypar[3]=noise;
|
||||
|
||||
if (ampl==-1)
|
||||
mypar[4]=h1->GetBinContent(h1->GetXaxis()->FindBin(0.5*(max+min)));
|
||||
else
|
||||
mypar[4]=ampl;
|
||||
|
||||
if (cs_slope==-1)
|
||||
mypar[5]=0;
|
||||
else
|
||||
mypar[5]=cs_slope;
|
||||
|
||||
fun->SetParameters(mypar);
|
||||
|
||||
fun->SetRange(min,max);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TF1* energyCalibration::fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar) {
|
||||
|
||||
|
||||
TF1* fitfun;
|
||||
|
||||
char fname[100];
|
||||
|
||||
strcpy(fname, fun->GetName());
|
||||
|
||||
if (plot_flag) {
|
||||
h1->Fit(fname,"R0Q");
|
||||
} else
|
||||
h1->Fit(fname,"R0Q");
|
||||
|
||||
|
||||
fitfun= h1->GetFunction(fname);
|
||||
fitfun->GetParameters(mypar);
|
||||
for (int ip=0; ip<6; ip++) {
|
||||
emypar[ip]=fitfun->GetParError(ip);
|
||||
}
|
||||
return fitfun;
|
||||
}
|
||||
|
||||
TF1* energyCalibration::fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar) {
|
||||
initFitFunction(fscurve,h1);
|
||||
return fitFunction(fscurve, h1, mypar, emypar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TF1* energyCalibration::fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar) {
|
||||
initFitFunction(fspectrum,h1);
|
||||
return fitFunction(fspectrum, h1, mypar, emypar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TF1* energyCalibration::fitSpectrumPixel(TH1 *h1, Double_t *mypar, Double_t *emypar) {
|
||||
initFitFunction(fspixel,h1);
|
||||
return fitFunction(fspixel, h1, mypar, emypar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TGraphErrors* energyCalibration::linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff) {
|
||||
|
||||
TGraphErrors *gr;
|
||||
|
||||
Double_t mypar[2];
|
||||
|
||||
gr = new TGraphErrors(nscan,en,fl,een,efl);
|
||||
|
||||
if (plot_flag) {
|
||||
gr->Fit("pol1");
|
||||
gr->SetMarkerStyle(20);
|
||||
} else
|
||||
gr->Fit("pol1","0Q");
|
||||
|
||||
TF1 *fitfun= gr->GetFunction("pol1");
|
||||
fitfun->GetParameters(mypar);
|
||||
|
||||
egain=fitfun->GetParError(1);
|
||||
eoff=fitfun->GetParError(0);
|
||||
|
||||
gain=funcs->setScanSign()*mypar[1];
|
||||
|
||||
off=mypar[0];
|
||||
|
||||
return gr;
|
||||
}
|
||||
|
||||
|
||||
TGraphErrors* energyCalibration::calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral) {
|
||||
|
||||
TH1F *h;
|
||||
|
||||
Double_t mypar[6], emypar[6];
|
||||
Double_t fl[nscan], efl[nscan];
|
||||
|
||||
|
||||
for (int ien=0; ien<nscan; ien++) {
|
||||
h=h1[ien];
|
||||
if (integral)
|
||||
fitSCurve(h,mypar,emypar);
|
||||
else
|
||||
fitSpectrum(h,mypar,emypar);
|
||||
|
||||
fl[ien]=mypar[2];
|
||||
efl[ien]=emypar[2];
|
||||
}
|
||||
return linearCalibration(nscan,en,een,fl,efl,gain,off, egain, eoff);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
462
slsDetectorCalibration/energyCalibration.h
Normal file
462
slsDetectorCalibration/energyCalibration.h
Normal file
@ -0,0 +1,462 @@
|
||||
#ifndef ENERGYCALIBRATION_H
|
||||
#define ENERGYCALIBRATION_H
|
||||
|
||||
#ifdef __CINT__
|
||||
#define MYROOT
|
||||
#endif
|
||||
|
||||
#ifdef G__ROOT
|
||||
#define MYROOT
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __MAKECINT__
|
||||
#define MYROOT
|
||||
#endif
|
||||
|
||||
#ifdef ROOT_VERSION
|
||||
#define MYROOT
|
||||
#endif
|
||||
|
||||
#define MYROOT
|
||||
|
||||
#ifdef MYROOT
|
||||
#include <TROOT.h>
|
||||
#include <TF1.h>
|
||||
class TH1F;
|
||||
class TH2F;
|
||||
class TGraphErrors;
|
||||
#endif
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
const double conven=1000./3.6; /**< electrons/keV */
|
||||
const double el=1.67E-4; /**< electron charge in fC */
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\mainpage Common Root library for SLS detectors data analysis
|
||||
*
|
||||
* \section intro_sec Introduction
|
||||
We know very well s-curves etc. but at the end everybody uses different functions ;-).
|
||||
|
||||
* \subsection mot_sec Motivation
|
||||
It would be greate to use everybody the same functions...
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@libdoc The energiCalibration class contains all the necessary functions for s-curve fitting and linear calibration of the threshold.
|
||||
*
|
||||
* @short Energy calibration functions
|
||||
* @author Anna Bergamaschi
|
||||
* @version 0.1alpha
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
class containing all the possible energy calibration functions (scurves with and without charge sharing, gaussian spectrum with and without charge sharing, possibility of chosing the sign of the X-axis)
|
||||
|
||||
*/
|
||||
class energyCalibrationFunctions {
|
||||
|
||||
public:
|
||||
|
||||
energyCalibrationFunctions(int s=-1) {setScanSign(s);};
|
||||
|
||||
/** sets scan sign
|
||||
\param s can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) otherwise gets
|
||||
\returns current scan sign can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions)
|
||||
*/
|
||||
int setScanSign(int s=0) {if (s==1 || s==-1) sign=s; return sign;};;
|
||||
|
||||
|
||||
#ifdef MYROOT
|
||||
/**
|
||||
Gaussian Function with charge sharing pedestal
|
||||
par[0] is the absolute height of the background pedestal
|
||||
par[1] is the slope of the background pedestal
|
||||
*/
|
||||
Double_t pedestal(Double_t *x, Double_t *par);
|
||||
|
||||
/**
|
||||
Gaussian Function with charge sharing pedestal
|
||||
par[0] is the absolute height of the background pedestal
|
||||
par[1] is the slope of the background pedestal
|
||||
par[2] is the gaussian peak position
|
||||
par[3] is the RMS of the gaussian (and of the pedestal)
|
||||
par[4] is the height of the function
|
||||
par[5] is the fractional height of the charge sharing pedestal (scales with par[3])
|
||||
*/
|
||||
Double_t gaussChargeSharing(Double_t *x, Double_t *par);
|
||||
/**
|
||||
Gaussian Function with charge sharing pedestal
|
||||
par[0] is the absolute height of the background pedestal
|
||||
par[1] is the slope of the background pedestal
|
||||
par[2] is the gaussian peak position
|
||||
par[3] is the RMS of the gaussian (and of the pedestal)
|
||||
par[4] is the height of the function
|
||||
par[5] is the fractional height of the charge sharing pedestal (scales with par[3])
|
||||
*/
|
||||
Double_t gaussChargeSharingPixel(Double_t *x, Double_t *par);
|
||||
|
||||
/**
|
||||
Basic erf function
|
||||
par[0] is the inflection point
|
||||
par[1] is the RMS
|
||||
par[2] is the amplitude
|
||||
*/
|
||||
Double_t erfFunction(Double_t *x, Double_t *par) ;
|
||||
Double_t erfBox(Double_t *z, Double_t *par);
|
||||
/** Erf function with charge sharing slope
|
||||
par[0] is the pedestal
|
||||
par[1] is the slope of the pedestal
|
||||
par[2] is the inflection point
|
||||
par[3] is the RMS
|
||||
par[4] is the amplitude
|
||||
par[5] is the angual coefficient of the charge sharing slope (scales with par[3])
|
||||
*/
|
||||
Double_t erfFunctionChargeSharing(Double_t *x, Double_t *par);
|
||||
|
||||
/** Double Erf function with charge sharing slope
|
||||
par[0] is the pedestal
|
||||
par[1] is the slope of the pedestal
|
||||
par[2] is the inflection point of the first energy
|
||||
par[3] is the RMS of the first energy
|
||||
par[4] is the amplitude of the first energy
|
||||
par[5] is the angual coefficient of the charge sharing slope of the first energy (scales with par[3])
|
||||
par[6] is the inflection point of the second energy
|
||||
par[7] is the RMS of the second energy
|
||||
par[8] is the amplitude of the second energy
|
||||
par[9] is the angual coefficient of the charge sharing slope of the second energy (scales with par[8])
|
||||
*/
|
||||
|
||||
Double_t erfFuncFluo(Double_t *x, Double_t *par);
|
||||
|
||||
|
||||
/**
|
||||
static function Gaussian with charge sharing pedestal with the correct scan sign
|
||||
par[0] is the absolute height of the background pedestal
|
||||
par[1] is the slope of the pedestal
|
||||
par[2] is the gaussian peak position
|
||||
par[3] is the RMS of the gaussian (and of the pedestal)
|
||||
par[4] is the height of the function
|
||||
par[5] is the fractional height of the charge sharing pedestal (scales with par[4]
|
||||
*/
|
||||
Double_t spectrum(Double_t *x, Double_t *par);
|
||||
|
||||
/**
|
||||
static function Gaussian with charge sharing pedestal with the correct scan sign
|
||||
par[0] is the absolute height of the background pedestal
|
||||
par[1] is the slope of the pedestal
|
||||
par[2] is the gaussian peak position
|
||||
par[3] is the RMS of the gaussian (and of the pedestal)
|
||||
par[4] is the height of the function
|
||||
par[5] is the fractional height of the charge sharing pedestal (scales with par[4]
|
||||
*/
|
||||
Double_t spectrumPixel(Double_t *x, Double_t *par);
|
||||
|
||||
|
||||
/** Erf function with charge sharing slope with the correct scan sign
|
||||
par[0] is the pedestal
|
||||
par[1] is the slope of the pedestal
|
||||
par[2] is the inflection point
|
||||
par[3] is the RMS
|
||||
par[4] is the amplitude
|
||||
par[5] is the angual coefficient of the charge sharing slope (scales with par[3])
|
||||
*/
|
||||
Double_t scurve(Double_t *x, Double_t *par);
|
||||
|
||||
|
||||
|
||||
/** Double Erf function with charge sharing slope
|
||||
par[0] is the pedestal
|
||||
par[1] is the slope of the pedestal
|
||||
par[2] is the inflection point of the first energy
|
||||
par[3] is the RMS of the first energy
|
||||
par[4] is the amplitude of the first energy
|
||||
par[5] is the angual coefficient of the charge sharing slope of the first energy (scales with par[3])
|
||||
par[6] is the inflection point of the second energy
|
||||
par[7] is the RMS of the second energy
|
||||
par[8] is the amplitude of the second energy
|
||||
par[9] is the angual coefficient of the charge sharing slope of the second energy (scales with par[8])
|
||||
*/
|
||||
Double_t scurveFluo(Double_t *x, Double_t *par);
|
||||
|
||||
#endif
|
||||
|
||||
/** Calculates the median of an array of n elements */
|
||||
static double median(double *x, int n);
|
||||
/** Calculates the median of an array of n elements (swaps the arrays!)*/
|
||||
static int quick_select(int arr[], int n);
|
||||
/** Calculates the median of an array of n elements (swaps the arrays!)*/
|
||||
static int kth_smallest(int *a, int n, int k);
|
||||
|
||||
private:
|
||||
int sign;
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
class alowing the energy calibration of photon counting and anlogue detectors
|
||||
|
||||
*/
|
||||
|
||||
class energyCalibration {
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
default constructor - creates the function with which the s-curves will be fitted
|
||||
*/
|
||||
energyCalibration();
|
||||
|
||||
/**
|
||||
default destructor - deletes the function with which the s-curves will be fitted
|
||||
*/
|
||||
~energyCalibration();
|
||||
|
||||
/** sets plot flag
|
||||
\param p plot flag (-1 gets, 0 unsets, >0 plot)
|
||||
\returns current plot flag
|
||||
*/
|
||||
int setPlotFlag(int p=-1) {if (p>=0) plot_flag=p; return plot_flag;};
|
||||
|
||||
/** sets scan sign
|
||||
\param s can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) otherwise gets
|
||||
\returns current scan sign can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions)
|
||||
*/
|
||||
int setScanSign(int s=0) {return funcs->setScanSign(s);};
|
||||
|
||||
/** sets plot flag
|
||||
\param p plot flag (-1 gets, 0 unsets, >0 plot)
|
||||
\returns current plot flag
|
||||
*/
|
||||
int setChargeSharing(int p=-1);
|
||||
|
||||
|
||||
void fixParameter(int ip, Double_t val);
|
||||
|
||||
void releaseParameter(int ip);
|
||||
|
||||
#ifdef MYROOT
|
||||
|
||||
/**
|
||||
Creates an histogram with the median of nchannels starting from a specified one. the direction on which it is mediated can be selected (defaults to x=0)
|
||||
\param h2 2D histogram on which the median will be calculated
|
||||
\param ch0 starting channel
|
||||
\param nch number of channels to be mediated
|
||||
\param direction can be either 0 (x, default) or 1 (y)
|
||||
\returns a TH1F histogram with the X-axis as a clone of the h2 Y (if direction=0) or X (if direction=0) axis, and on the Y axis the median of the counts of the mediated channels f h2
|
||||
*/
|
||||
static TH1F* createMedianHistogram(TH2F* h2, int ch0, int nch, int direction=0);
|
||||
|
||||
|
||||
/** sets the s-curve fit range
|
||||
\param mi minimum of the fit range (-1 is histogram x-min)
|
||||
\param ma maximum of the fit range (-1 is histogram x-max)
|
||||
*/
|
||||
void setFitRange(Double_t mi, Double_t ma){fit_min=mi; fit_max=ma;};
|
||||
|
||||
/** gets the s-curve fit range
|
||||
\param mi reference for minimum of the fit range (-1 is histogram x-min)
|
||||
\param ma reference for maximum of the fit range (-1 is histogram x-max)
|
||||
*/
|
||||
void getFitRange(Double_t &mi, Double_t &ma){mi=fit_min; ma=fit_max;};
|
||||
|
||||
|
||||
/** set start parameters for the s-curve function
|
||||
\param par parameters, -1 sets to auto-calculation
|
||||
par[0] is the pedestal
|
||||
par[1] is the slope of the pedestal
|
||||
par[2] is the inflection point
|
||||
par[3] is the RMS
|
||||
par[4] is the amplitude
|
||||
par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) -- always positive
|
||||
*/
|
||||
void setStartParameters(Double_t *par);
|
||||
|
||||
/** get start parameters for the s-curve function
|
||||
\param par parameters, -1 means auto-calculated
|
||||
par[0] is the pedestal
|
||||
par[1] is the slope of the pedestal
|
||||
par[2] is the inflection point
|
||||
par[3] is the RMS
|
||||
par[4] is the amplitude
|
||||
par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) -- always positive
|
||||
*/
|
||||
void getStartParameters(Double_t *par);
|
||||
|
||||
/**
|
||||
fits histogram with the s-curve function
|
||||
\param h1 1d-histogram to be fitted
|
||||
\param mypar pointer to fit parameters array
|
||||
\param emypar pointer to fit parameter errors
|
||||
\returns the fitted function - can be used e.g. to get the Chi2 or similar
|
||||
*/
|
||||
TF1 *fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar);
|
||||
|
||||
|
||||
/**
|
||||
fits histogram with the spectrum
|
||||
\param h1 1d-histogram to be fitted
|
||||
\param mypar pointer to fit parameters array
|
||||
\param emypar pointer to fit parameter errors
|
||||
\returns the fitted function - can be used e.g. to get the Chi2 or similar
|
||||
*/
|
||||
TF1 *fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar);
|
||||
|
||||
|
||||
/**
|
||||
fits histogram with the spectrum
|
||||
\param h1 1d-histogram to be fitted
|
||||
\param mypar pointer to fit parameters array
|
||||
\param emypar pointer to fit parameter errors
|
||||
\returns the fitted function - can be used e.g. to get the Chi2 or similar
|
||||
*/
|
||||
TF1 *fitSpectrumPixel(TH1 *h1, Double_t *mypar, Double_t *emypar);
|
||||
|
||||
|
||||
/**
|
||||
calculates gain and offset for the set of inflection points
|
||||
\param nscan number of energy scans
|
||||
\param en array of energies (nscan long)
|
||||
\param een array of errors on energies (nscan long) - can be NULL!
|
||||
\param fl array of inflection points (nscan long)
|
||||
\param efl array of errors on the inflection points (nscan long)
|
||||
\param gain reference to gain resulting from the fit
|
||||
\param off reference to offset resulting from the fit
|
||||
\param egain reference to error on the gain resulting from the fit
|
||||
\param eoff reference to the error on the offset resulting from the fit
|
||||
\returns graph energy vs inflection point
|
||||
*/
|
||||
TGraphErrors* linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff);
|
||||
|
||||
/**
|
||||
calculates gain and offset for the set of energy scans
|
||||
\param nscan number of energy scans
|
||||
\param en array of energies (nscan long)
|
||||
\param een array of errors on energies (nscan long) - can be NULL!
|
||||
\param h1 array of TH1
|
||||
\param gain reference to gain resulting from the fit
|
||||
\param off reference to offset resulting from the fit
|
||||
\param egain reference to error on the gain resulting from the fit
|
||||
\param eoff reference to the error on the offset resulting from the fit
|
||||
\returns graph energy vs inflection point
|
||||
*/
|
||||
TGraphErrors* calibrateScurves(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff){return calibrate(nscan, en, een, h1, gain, off, egain, eoff, 1);};
|
||||
|
||||
/**
|
||||
calculates gain and offset for the set of energy spectra
|
||||
\param nscan number of energy scans
|
||||
\param en array of energies (nscan long)
|
||||
\param een array of errors on energies (nscan long) - can be NULL!
|
||||
\param h1 array of TH1
|
||||
\param gain reference to gain resulting from the fit
|
||||
\param off reference to offset resulting from the fit
|
||||
\param egain reference to error on the gain resulting from the fit
|
||||
\param eoff reference to the error on the offset resulting from the fit
|
||||
\returns graph energy vs peak
|
||||
*/
|
||||
TGraphErrors* calibrateSpectra(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff){return calibrate(nscan, en, een, h1, gain, off, egain, eoff, 0);};
|
||||
|
||||
|
||||
#endif
|
||||
private:
|
||||
|
||||
#ifdef MYROOT
|
||||
/**
|
||||
calculates gain and offset for the set of energies
|
||||
\param nscan number of energy scans
|
||||
\param en array of energies (nscan long)
|
||||
\param een array of errors on energies (nscan long) - can be NULL!
|
||||
\param h1 array of TH1
|
||||
\param gain reference to gain resulting from the fit
|
||||
\param off reference to offset resulting from the fit
|
||||
\param egain reference to error on the gain resulting from the fit
|
||||
\param eoff reference to the error on the offset resulting from the fit
|
||||
\param integral 1 is an s-curve set (default), 0 spectra
|
||||
\returns graph energy vs peak/inflection point
|
||||
*/
|
||||
TGraphErrors* calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral=1);
|
||||
|
||||
|
||||
/**
|
||||
Initializes the start parameters and the range of the fit depending on the histogram characteristics and/or on the start parameters specified by the user
|
||||
\param fun pointer to function to be initialized
|
||||
\param h1 histogram from which to extract the range and start parameters, if not already specified by the user
|
||||
|
||||
*/
|
||||
|
||||
void initFitFunction(TF1 *fun, TH1 *h1);
|
||||
|
||||
|
||||
/**
|
||||
Performs the fit according to the flags specified and returns the fitted function
|
||||
\param fun function to fit
|
||||
\param h1 histogram to fit
|
||||
\param mypar pointer to fit parameters array
|
||||
\param emypar pointer to fit parameter errors
|
||||
\returns the fitted function - can be used e.g. to get the Chi2 or similar
|
||||
*/
|
||||
TF1 *fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MYROOT
|
||||
Double_t fit_min; /**< minimum of the s-curve fitting range, -1 is histogram x-min */
|
||||
Double_t fit_max; /**< maximum of the s-curve fitting range, -1 is histogram x-max */
|
||||
|
||||
Double_t bg_offset; /**< start value for the background pedestal */
|
||||
Double_t bg_slope; /**< start value for the background slope */
|
||||
Double_t flex; /**< start value for the inflection point */
|
||||
Double_t noise; /**< start value for the noise */
|
||||
Double_t ampl; /**< start value for the number of photons */
|
||||
Double_t cs_slope; /**< start value for the charge sharing slope */
|
||||
|
||||
|
||||
TF1 *fscurve; /**< function with which the s-curve will be fitted */
|
||||
|
||||
TF1 *fspectrum; /**< function with which the spectrum will be fitted */
|
||||
|
||||
TF1 *fspixel; /**< function with which the spectrum will be fitted */
|
||||
|
||||
#endif
|
||||
|
||||
energyCalibrationFunctions *funcs;
|
||||
int plot_flag; /**< 0 does not plot, >0 plots (flags?) */
|
||||
|
||||
int cs_flag; /**< 0 functions without charge sharing contribution, >0 with charge sharing contribution */
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
521
slsDetectorCalibration/interpolatingDetector.h
Normal file
521
slsDetectorCalibration/interpolatingDetector.h
Normal file
@ -0,0 +1,521 @@
|
||||
#ifndef INTERPOLATINGDETECTOR_H
|
||||
#define INTERPOLATINGDETECTOR_H
|
||||
|
||||
|
||||
#include "singlePhotonDetector.h"
|
||||
|
||||
#include "slsInterpolation.h"
|
||||
|
||||
#define M015
|
||||
|
||||
#ifdef MYROOT1
|
||||
#include <TTree.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
#define XMIN 350/2
|
||||
#define XMAX 600/2
|
||||
#define YMIN 0
|
||||
#define YMAX 400
|
||||
|
||||
class interpolatingDetector : public singlePhotonDetector {
|
||||
|
||||
/** @short class to perform pedestal subtraction etc. and find single photon clusters for an analog detector */
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param d detector data structure to be used
|
||||
\param csize cluster size (should be an odd number). Defaults to 3
|
||||
\param nsigma number of rms to discriminate from the noise. Defaults to 5
|
||||
\param sign 1 if photons are positive, -1 if negative
|
||||
\param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none
|
||||
\param nped number of samples for pedestal averaging
|
||||
\param nd number of dark frames to average as pedestals without photon discrimination at the beginning of the measurement
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
interpolatingDetector(slsDetectorData<uint16_t> *d, slsInterpolation *inte,
|
||||
double nsigma=5,
|
||||
int sign=1,
|
||||
commonModeSubtraction *cm=NULL,
|
||||
int nped=1000,
|
||||
int nd=100, int nnx=-1, int nny=-1) :
|
||||
singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0), xmin(XMIN), xmax(XMAX), ymin(YMIN), ymax(YMAX) {
|
||||
cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
interpolatingDetector(interpolatingDetector *orig) : singlePhotonDetector(orig) {
|
||||
interp=(orig->interp)->Clone();
|
||||
id=orig->id;
|
||||
xmin=orig->xmin;
|
||||
xmax=orig->xmax;
|
||||
ymin=orig->ymin;
|
||||
ymax=orig->ymax;
|
||||
|
||||
}
|
||||
|
||||
|
||||
virtual interpolatingDetector *Clone() {
|
||||
return new interpolatingDetector(this);
|
||||
}
|
||||
|
||||
virtual int setId(int i) {id=i; interp->setId(id); return id;};
|
||||
|
||||
virtual void prepareInterpolation(int &ok) {
|
||||
cout << "*"<< endl;
|
||||
#ifdef SAVE_ALL
|
||||
char tit[1000];
|
||||
sprintf(tit,"/scratch/ped_%d.tiff",id);
|
||||
writePedestals(tit);
|
||||
sprintf(tit,"/scratch/ped_rms_%d.tiff",id);
|
||||
writePedestalRMS(tit);
|
||||
if (gmap) {
|
||||
sprintf(tit,"/scratch/gmap_%d.tiff",id);
|
||||
writeGainMap(tit);
|
||||
}
|
||||
#endif
|
||||
if (interp)
|
||||
interp->prepareInterpolation(ok);
|
||||
}
|
||||
|
||||
|
||||
void clearImage() {if (interp) interp->clearInterpolatedImage(); else singlePhotonDetector::clearImage();};
|
||||
|
||||
int getImageSize(int &nnx, int &nny, int &ns) {if (interp) return interp->getImageSize(nnx, nny, ns); else return analogDetector<uint16_t>::getImageSize(nnx, nny, ns);};
|
||||
#ifdef MYROOT1
|
||||
virtual TH2F *getImage()
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
virtual int *getImage()
|
||||
#endif
|
||||
{
|
||||
// cout << "image " << endl;
|
||||
if (interp)
|
||||
return interp->getInterpolatedImage();
|
||||
else
|
||||
return analogDetector<uint16_t>::getImage();
|
||||
//cout << "null " << endl;
|
||||
}
|
||||
|
||||
#ifdef MYROOT1
|
||||
virtual TH2F *addToInterpolatedImage(char *data, single_photon_hit *clusters, int &nph)
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
virtual int *addToInterpolatedImage(char *data, single_photon_hit *clusters, int &nph)
|
||||
#endif
|
||||
{
|
||||
nph=addFrame(data,clusters,0);
|
||||
if (interp)
|
||||
return interp->getInterpolatedImage();
|
||||
else
|
||||
singlePhotonDetector::getImage();
|
||||
//return NULL;
|
||||
};
|
||||
|
||||
|
||||
#ifdef MYROOT1
|
||||
virtual TH2F *addToFlatField(char *data, single_photon_hit *clusters, int &nph)
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
virtual int *addToFlatField(char *data, single_photon_hit *clusters, int &nph)
|
||||
#endif
|
||||
{
|
||||
nph=addFrame(data,clusters,1);
|
||||
if (interp)
|
||||
return interp->getFlatField();
|
||||
else
|
||||
return NULL;
|
||||
};
|
||||
|
||||
void *writeImage(const char * imgname) {
|
||||
// cout << id << "=" << imgname<< endl;
|
||||
if (interp)
|
||||
interp->writeInterpolatedImage(imgname);
|
||||
else
|
||||
analogDetector<uint16_t>::writeImage(imgname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int addFrame(char *data, single_photon_hit *clusters=NULL, int ff=0) {
|
||||
|
||||
double g=1;
|
||||
|
||||
single_photon_hit *cl;
|
||||
single_photon_hit clust;
|
||||
if (clusters)
|
||||
cl=clusters;
|
||||
else
|
||||
cl=&clust;
|
||||
|
||||
|
||||
int ccs=clusterSize;
|
||||
int ccy=clusterSizeY;
|
||||
|
||||
double int_x,int_y, eta_x, eta_y;
|
||||
int nph=0;
|
||||
double rest[ny][nx];
|
||||
int cy=(clusterSizeY+1)/2;
|
||||
int cs=(clusterSize+1)/2;
|
||||
int ir, ic;
|
||||
double cc[2][2];
|
||||
double max=0, tl=0, tr=0, bl=0,br=0, v, vv;
|
||||
int xoff,yoff;
|
||||
int skip=0;
|
||||
// cout <<"fr"<< endl;
|
||||
double tthr;
|
||||
if (iframe<nDark) {
|
||||
//cout << iframe << "+"<< nDark <<endl;
|
||||
addToPedestal(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
newFrame();
|
||||
|
||||
|
||||
|
||||
|
||||
// cout << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
// for (int ix=clusterSize/2; ix<clusterSize/2-1; ix++) {
|
||||
// for (int iy=clusterSizeY/2; iy<ny-clusterSizeY/2; iy++) {
|
||||
|
||||
// cout << ix << " " << iy << endl;
|
||||
eventMask[iy][ix]=PEDESTAL;
|
||||
|
||||
|
||||
tthr=nSigma*getPedestalRMS(ix,iy)/g;
|
||||
if (ix==xmin || iy==ymin)
|
||||
rest[iy][ix]=subtractPedestal(data,ix,iy);
|
||||
|
||||
|
||||
max=0;
|
||||
tl=0;
|
||||
tr=0;
|
||||
bl=0;
|
||||
br=0;
|
||||
tot=0;
|
||||
quadTot=0;
|
||||
|
||||
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
|
||||
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
|
||||
if ((iy+ir)>=ymin && (iy+ir)<ymax && (ix+ic)>=xmin && (ix+ic)<xmax) {
|
||||
//cluster->set_data(rest[iy+ir][ix+ic], ic, ir);
|
||||
|
||||
if (ir>=0 && ic>=0 )
|
||||
rest[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir);
|
||||
|
||||
v=rest[iy+ir][ix+ic];//cluster->get_data(ic,ir);
|
||||
tot+=v;
|
||||
|
||||
if (ir<=0 && ic<=0)
|
||||
bl+=v;
|
||||
if (ir<=0 && ic>=0)
|
||||
br+=v;
|
||||
if (ir>=0 && ic<=0)
|
||||
tl+=v;
|
||||
if (ir>=0 && ic>=0)
|
||||
tr+=v;
|
||||
|
||||
if (v>max) {
|
||||
max=v;
|
||||
}
|
||||
// if (ir==0 && ic==0) {
|
||||
if (v>tthr) {
|
||||
eventMask[iy][ix]=NEIGHBOUR;
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rest[iy][ix]<=-tthr) {
|
||||
eventMask[iy][ix]=NEGATIVE_PEDESTAL;
|
||||
//if (cluster->get_data(0,0)>=max) {
|
||||
} else if (max>tthr || tot>sqrt(ccy*ccs)*tthr || quadTot>sqrt(cy*cs)*tthr) {
|
||||
if (rest[iy][ix]>=max) {
|
||||
if (bl>=br && bl>=tl && bl>=tr) {
|
||||
cl->quad=BOTTOM_LEFT;
|
||||
cl->quadTot=bl;
|
||||
} else if (br>=bl && br>=tl && br>=tr) {
|
||||
cl->quad=BOTTOM_RIGHT;
|
||||
cl->quadTot=br;
|
||||
} else if (tl>=br && tl>=bl && tl>=tr) {
|
||||
cl->quad=TOP_LEFT;
|
||||
cl->quadTot=tl;
|
||||
} else if (tr>=bl && tr>=tl && tr>=br) {
|
||||
cl->quad=TOP_RIGHT;
|
||||
cl->quadTot=tr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* cout << ix << " " << iy << " " << rest[iy][ix] <<" " << tot << " " << quadTot << endl; */
|
||||
/* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */
|
||||
/* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) */
|
||||
/* cout << rest[iy+ir][ix+ic] << " " ; */
|
||||
/* cout << endl; */
|
||||
/* } */
|
||||
eventMask[iy][ix]=PHOTON_MAX;
|
||||
cl->tot=tot;
|
||||
cl->x=ix;
|
||||
cl->y=iy;
|
||||
cl->ped=getPedestal(ix,iy, 0);
|
||||
cl->rms=getPedestalRMS(ix,iy);
|
||||
|
||||
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
|
||||
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
|
||||
if ((iy+ir)>=ymin && (iy+ir)<ymax && (ix+ic)>=xmin && (ix+ic)<xmax) {
|
||||
cl->set_data(rest[iy+ir][ix+ic],ic,ir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (interp) {
|
||||
if (ff) {
|
||||
#ifdef M015
|
||||
if (iy>100)
|
||||
#endif
|
||||
interp->addToFlatField(cl->quadTot,cl->quad,cl->get_cluster(),eta_x, eta_y);
|
||||
// if ((eta_x<0.1 || eta_x>0.9)&&(eta_y<0.1 || eta_y>0.9))
|
||||
// cout << ix << " " << iy << " " << eta_x <<" " << eta_y << endl;
|
||||
|
||||
} else {
|
||||
interp->getInterpolatedPosition(ix, iy, cl->quadTot,cl->quad,cl->get_cluster(),int_x, int_y);
|
||||
interp->addToImage(int_x, int_y);
|
||||
}
|
||||
|
||||
} else
|
||||
image[ix+nx*iy]++;
|
||||
|
||||
nph++;
|
||||
|
||||
if (clusters) cl=(clusters+nph);
|
||||
|
||||
|
||||
// rest[iy][ix]-=tthr;
|
||||
} else
|
||||
eventMask[iy][ix]=PHOTON;
|
||||
//else if (thr<=0 ) {
|
||||
//addToPedestal(data,ix,iy);
|
||||
// }
|
||||
}
|
||||
if (eventMask[iy][ix]==PEDESTAL) {
|
||||
addToPedestal(data,ix,iy);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nph;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* for (int ix=0; ix<nx; ix++) { */
|
||||
/* for (int iy=0; iy<ny; iy++) { */
|
||||
/* skip=0; */
|
||||
/* max=0; */
|
||||
/* tl=0; */
|
||||
/* tr=0; */
|
||||
/* bl=0; */
|
||||
/* br=0; */
|
||||
/* tot=0; */
|
||||
/* quadTot=0; */
|
||||
/* quad=UNDEFINED_QUADRANT; */
|
||||
|
||||
|
||||
|
||||
|
||||
/* cl->rms=getPedestalRMS(ix,iy); */
|
||||
/* //(clusters+nph)->rms=getPedestalRMS(ix,iy); */
|
||||
|
||||
/* // cout << iframe << " " << nph << " " << ix << " " << iy << endl; */
|
||||
/* if (ix==0 || iy==0) */
|
||||
/* val[iy][ix]=subtractPedestal(data,ix,iy); */
|
||||
|
||||
/* if (val[iy][ix]<-nSigma*cl->rms) { */
|
||||
/* eventMask[iy][ix]=NEGATIVE_PEDESTAL; */
|
||||
/* // cout << "neg ped" << endl; */
|
||||
/* } else { */
|
||||
/* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */
|
||||
/* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { */
|
||||
|
||||
|
||||
/* if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) { */
|
||||
|
||||
/* if (ir>=0 && ic>=0) { */
|
||||
/* val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir); */
|
||||
/* eventMask[iy+ir][ix+ic]=PEDESTAL; */
|
||||
/* } */
|
||||
|
||||
/* // cout << ir << " " << ic << " " << val[iy+ir][ix+ic] << endl; */
|
||||
/* v=&(val[iy+ir][ix+ic]); */
|
||||
/* // if (skip==0) { */
|
||||
/* tot+=*v; */
|
||||
/* if (ir<=0 && ic<=0) */
|
||||
/* bl+=*v; */
|
||||
/* if (ir<=0 && ic>=0) */
|
||||
/* br+=*v; */
|
||||
/* if (ir>=0 && ic<=0) */
|
||||
/* tl+=*v; */
|
||||
/* if (ir>=0 && ic>=0) */
|
||||
/* tr+=*v; */
|
||||
/* if (*v>max) { */
|
||||
/* max=*v; */
|
||||
/* } */
|
||||
|
||||
/* } */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* if (bl>=br && bl>=tl && bl>=tr) { */
|
||||
/* cl->quad=BOTTOM_LEFT; */
|
||||
/* cl->quadTot=bl; */
|
||||
/* } else if (br>=bl && br>=tl && br>=tr) { */
|
||||
/* cl->quad=BOTTOM_RIGHT; */
|
||||
/* cl->quadTot=br; */
|
||||
/* } else if (tl>=br && tl>=bl && tl>=tr) { */
|
||||
/* cl->quad=TOP_LEFT; */
|
||||
/* cl->quadTot=tl; */
|
||||
/* } else if (tr>=bl && tr>=tl && tr>=br) { */
|
||||
/* cl->quad=TOP_RIGHT; */
|
||||
/* cl->quadTot=tr; */
|
||||
/* } */
|
||||
|
||||
/* if (max>nSigma*cl->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cl->rms || (cl->quadTot)>sqrt(cy*cs)*nSigma*cl->rms) { */
|
||||
/* if (val[iy][ix]>=max) { */
|
||||
/* eventMask[iy][ix]=PHOTON_MAX; */
|
||||
/* cl->tot=tot; */
|
||||
/* cl->x=ix; */
|
||||
/* cl->y=iy; */
|
||||
/* cl->ped=getPedestal(ix,iy, 0); */
|
||||
|
||||
/* if (interp) { */
|
||||
/* if (ff) { */
|
||||
/* interp->addToFlatField(cl->quadTot,cl->quad,cl->get_cluster(),eta_x, eta_y); */
|
||||
/* // if ((eta_x<0.1 || eta_x>0.9)&&(eta_y<0.1 || eta_y>0.9)) */
|
||||
/* // cout << ix << " " << iy << " " << eta_x <<" " << eta_y << endl; */
|
||||
/* } else { */
|
||||
/* interp->getInterpolatedPosition(ix, iy, cl->quadTot,cl->quad,cl->get_cluster(),int_x, int_y); */
|
||||
/* interp->addToImage(int_x, int_y); */
|
||||
/* } */
|
||||
/* } else */
|
||||
/* image[ix+nx*iy]++; */
|
||||
|
||||
/* if (clusters) cl=(clusters+nph); */
|
||||
|
||||
/* nph++; */
|
||||
|
||||
/* } else { */
|
||||
/* eventMask[iy][ix]=PHOTON; */
|
||||
/* } */
|
||||
/* } else if (eventMask[iy][ix]==PEDESTAL) { */
|
||||
/* addToPedestal(data,ix,iy); */
|
||||
/* } */
|
||||
|
||||
/* } */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return nph; */
|
||||
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void processData(char *data, frameMode i=eFrame, int *val=NULL) {
|
||||
if (interp){
|
||||
switch(i) {
|
||||
case ePedestal:
|
||||
addToPedestal(data);
|
||||
break;
|
||||
case eFlat:
|
||||
addFrame(data,NULL,1);
|
||||
break;
|
||||
default:
|
||||
addFrame(data,NULL,0);
|
||||
}
|
||||
} else
|
||||
singlePhotonDetector::processData(data,i,val);
|
||||
|
||||
|
||||
};
|
||||
|
||||
virtual char *getInterpolation(){return (char*)interp;};
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
slsInterpolation *interp;
|
||||
int id;
|
||||
//should put it to analogDetector
|
||||
int xmin, xmax, ymin, ymax;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
BIN
slsDetectorCalibration/interpolations/.__afs3A48
Executable file
BIN
slsDetectorCalibration/interpolations/.__afs3A48
Executable file
Binary file not shown.
516
slsDetectorCalibration/interpolations/etaInterpolationBase.h
Normal file
516
slsDetectorCalibration/interpolations/etaInterpolationBase.h
Normal file
@ -0,0 +1,516 @@
|
||||
#ifndef ETA_INTERPOLATION_BASE_H
|
||||
#define ETA_INTERPOLATION_BASE_H
|
||||
|
||||
#ifdef MYROOT1
|
||||
#include <TObject.h>
|
||||
#include <TTree.h>
|
||||
#include <TH2D.h>
|
||||
#include <TH2F.h>
|
||||
#endif
|
||||
|
||||
#include "slsInterpolation.h"
|
||||
#include "tiffIO.h"
|
||||
|
||||
class etaInterpolationBase : public slsInterpolation {
|
||||
|
||||
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) {
|
||||
if (nb<=0)
|
||||
nbeta=nSubPixels*10;
|
||||
if (etamin>=etamax) {
|
||||
etamin=-1;
|
||||
etamax=2;
|
||||
}
|
||||
etastep=(etamax-etamin)/nbeta;
|
||||
#ifdef MYROOT1
|
||||
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
|
||||
heta=new int[nbeta*nbeta];
|
||||
hhx=new float[nbeta*nbeta];
|
||||
hhy=new float[nbeta*nbeta];
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
etaInterpolationBase(etaInterpolationBase *orig): slsInterpolation(orig){
|
||||
nbeta=orig->nbeta;
|
||||
etamin=orig->etamin;
|
||||
etamax=orig->etamax;
|
||||
|
||||
etastep=(etamax-etamin)/nbeta;
|
||||
#ifdef MYROOT1
|
||||
heta=(TH2D*)(orig->heta)->Clone("heta");
|
||||
hhx=(TH2D*)(orig->hhx)->Clone("hhx");
|
||||
hhy=(TH2D*)(orig->hhy)->Clone("hhy");
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT1
|
||||
heta=new int[nbeta*nbeta];
|
||||
memcpy(heta,orig->heta,nbeta*nbeta*sizeof(int));
|
||||
hhx=new float[nbeta*nbeta];
|
||||
memcpy(hhx,orig->hhx,nbeta*nbeta*sizeof(float));
|
||||
hhy=new float[nbeta*nbeta];
|
||||
memcpy(hhy,orig->hhy,nbeta*nbeta*sizeof(float));
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
};
|
||||
virtual etaInterpolationBase* Clone() {
|
||||
|
||||
return new etaInterpolationBase(this);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef MYROOT1
|
||||
TH2D *setEta(TH2D *h, int nb=-1, double emin=1, double emax=0)
|
||||
{
|
||||
if (h) { heta=h;
|
||||
nbeta=heta->GetNbinsX();
|
||||
etamin=heta->GetXaxis()->GetXmin();
|
||||
etamax=heta->GetXaxis()->GetXmax();
|
||||
etastep=(etamax-etamin)/nbeta;
|
||||
}
|
||||
return heta;
|
||||
};
|
||||
TH2D *setFlatField(TH2D *h, int nb=-1, double emin=1, double emax=0)
|
||||
{
|
||||
return setEta(h, nb, emin, emax);
|
||||
};
|
||||
|
||||
TH2D *getFlatField(){return setEta(NULL);};
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT1
|
||||
int *setEta(int *h, int nb=-1, double emin=1, double emax=0)
|
||||
{
|
||||
if (h) {heta=h;
|
||||
nbeta=nb;
|
||||
if (nb<=0) nbeta=nSubPixels*10;
|
||||
etamin=emin;
|
||||
etamax=emax;
|
||||
if (etamin>=etamax) {
|
||||
etamin=-1;
|
||||
etamax=2;
|
||||
}
|
||||
etastep=(etamax-etamin)/nbeta;
|
||||
}
|
||||
return heta;
|
||||
};
|
||||
|
||||
int *setFlatField(int *h, int nb=-1, double emin=1, double emax=0)
|
||||
{
|
||||
return setEta(h, nb, emin, emax);
|
||||
};
|
||||
int *getFlatField(){return setEta(NULL);};
|
||||
|
||||
int *getFlatField(int &nb, double &emin, double &emax){
|
||||
nb=nbeta;
|
||||
//cout << "igff* ff has " << nb << " bins " << endl;
|
||||
emin=etamin;
|
||||
emax=etamax;
|
||||
return getFlatField();
|
||||
};
|
||||
|
||||
|
||||
void *writeFlatField(const char * imgname) {
|
||||
float *gm=NULL;
|
||||
gm=new float[nbeta*nbeta];
|
||||
for (int ix=0; ix<nbeta; ix++) {
|
||||
for (int iy=0; iy<nbeta; iy++) {
|
||||
gm[iy*nbeta+ix]=heta[iy*nbeta+ix];
|
||||
}
|
||||
}
|
||||
WriteToTiff(gm, imgname, nbeta, nbeta);
|
||||
delete [] gm;
|
||||
return NULL;
|
||||
};
|
||||
|
||||
int readFlatField(const char * imgname, double emin=1, double emax=0) {
|
||||
if (emax>=1) etamax=emax;
|
||||
if (emin<=0) etamin=emin;
|
||||
|
||||
if (etamin>=etamax) {
|
||||
etamin=-1;
|
||||
etamax=2;
|
||||
}
|
||||
|
||||
etastep=(etamax-etamin)/nbeta;
|
||||
uint32 nnx;
|
||||
uint32 nny;
|
||||
float *gm=ReadFromTiff(imgname, nnx, nny);
|
||||
if (nnx!=nny) {
|
||||
cout << "different number of bins in x " << nnx << " and y " << nny<< " !"<< endl;
|
||||
cout << "Aborting read"<< endl;
|
||||
return 0;
|
||||
}
|
||||
nbeta=nnx;
|
||||
if (gm) {
|
||||
if (heta) {
|
||||
delete [] heta;
|
||||
delete [] hhx;
|
||||
delete [] hhy;
|
||||
}
|
||||
|
||||
heta=new int[nbeta*nbeta];
|
||||
hhx=new float[nbeta*nbeta];
|
||||
hhy=new float[nbeta*nbeta];
|
||||
|
||||
for (int ix=0; ix<nbeta; ix++) {
|
||||
for (int iy=0; iy<nbeta; iy++) {
|
||||
heta[iy*nbeta+ix]=gm[iy*nbeta+ix];
|
||||
}
|
||||
}
|
||||
delete [] gm;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
virtual void prepareInterpolation(int &ok){};
|
||||
|
||||
/* ////////////////////////////////////////////////////////////////////////////// */
|
||||
|
||||
#ifdef MYROOT1
|
||||
TH2D *gethhx()
|
||||
{
|
||||
hhx->Scale((double)nSubPixels);
|
||||
return hhx;
|
||||
};
|
||||
|
||||
TH2D *gethhy()
|
||||
{
|
||||
hhy->Scale((double)nSubPixels);
|
||||
return hhy;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT1
|
||||
float *gethhx()
|
||||
{
|
||||
// hhx->Scale((double)nSubPixels);
|
||||
return hhx;
|
||||
};
|
||||
|
||||
float *gethhy()
|
||||
{
|
||||
// hhy->Scale((double)nSubPixels);
|
||||
return hhy;
|
||||
};
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////// /*It return position hit for the event in input */ //////////////
|
||||
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
|
||||
{
|
||||
double sDum[2][2];
|
||||
double tot, totquad;
|
||||
double etax,etay;
|
||||
|
||||
int corner;
|
||||
corner=calcQuad(data, tot, totquad, sDum);
|
||||
if (nSubPixels>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];
|
||||
double *cluster[3];
|
||||
int xoff, yoff;
|
||||
cluster[0]=cl;
|
||||
cluster[1]=cl+3;
|
||||
cluster[2]=cl+6;
|
||||
|
||||
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, etay;
|
||||
if (nSubPixels>2) {
|
||||
cc[0][0]=cluster[yoff][xoff];
|
||||
cc[1][0]=cluster[yoff+1][xoff];
|
||||
cc[0][1]=cluster[yoff][xoff+1];
|
||||
cc[1][1]=cluster[yoff+1][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.;//.99;
|
||||
dY=0;//+1.;//.99;
|
||||
//etay=1-etay;
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
;
|
||||
dX=0;//+1.;//.99;
|
||||
dY=0;//+1.;//.99;
|
||||
break;
|
||||
case BOTTOM_LEFT:
|
||||
//etax=1-etax;
|
||||
//etay=1-etay;
|
||||
dX=-1.;//99;
|
||||
dY=-1.;//.99;
|
||||
break;
|
||||
case BOTTOM_RIGHT:
|
||||
//etay=1-etay;
|
||||
dX=0;//1.;//+.99;
|
||||
dY=-1.;//-.99;
|
||||
break;
|
||||
default:
|
||||
cout << "bad quadrant" << endl;
|
||||
dX=0.;
|
||||
dY=0.;
|
||||
}
|
||||
|
||||
|
||||
if (nSubPixels>2) {
|
||||
|
||||
#ifdef MYROOT1
|
||||
xpos_eta=(hhx->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixels);
|
||||
ypos_eta=(hhy->GetBinContent(hhx->GetXaxis()->FindBin(etax),hhy->GetYaxis()->FindBin(etay)))/((double)nSubPixels);
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
ex=(etax-etamin)/etastep;
|
||||
ey=(etay-etamin)/etastep;
|
||||
if (ex<0) {
|
||||
ex=0;
|
||||
cout << "x*"<< ex << endl;
|
||||
}
|
||||
if (ex>=nbeta) {
|
||||
ex=nbeta-1;
|
||||
cout << "x?"<< ex << endl;
|
||||
|
||||
}
|
||||
if (ey<0) {
|
||||
ey=0;
|
||||
cout << "y*"<< ey << endl;
|
||||
}
|
||||
if (ey>=nbeta) {
|
||||
ey=nbeta-1;
|
||||
cout << "y?"<< ey << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
xpos_eta=(((double)hhx[(ey*nbeta+ex)]))+dX ;///((double)nSubPixels);
|
||||
ypos_eta=(((double)hhy[(ey*nbeta+ex)]))+dY ;///((double)nSubPixels);
|
||||
//else
|
||||
//return 0;
|
||||
|
||||
#endif
|
||||
} else {
|
||||
xpos_eta=0.5*dX+0.25;
|
||||
ypos_eta=0.5*dY+0.25;
|
||||
}
|
||||
|
||||
// int_x=((double)x) + 0.5*dX + xpos_eta;
|
||||
// int_y=((double)y) + 0.5*dY + ypos_eta;
|
||||
int_x=((double)x) + xpos_eta;
|
||||
int_y=((double)y) + ypos_eta;
|
||||
/* if (int_x<x-0.5 || int_y<y-0.5 ) { */
|
||||
/* // cout << "***"<< x <<" " << y << " " << int_x << " " << int_y << endl; */
|
||||
/* cout << corner << " X "<< x << " " << etax << " " << xpos_eta << " " << int_x <<" Y "<< y << " " << etay << " " << ypos_eta << " " <<int_y << endl; */
|
||||
/* } */
|
||||
|
||||
//return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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,double *cl,double &etax, double &etay) {
|
||||
double cc[2][2];
|
||||
double *cluster[3];
|
||||
int xoff, yoff;
|
||||
cluster[0]=cl;
|
||||
cluster[1]=cl+3;
|
||||
cluster[2]=cl+6;
|
||||
|
||||
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]=cluster[yoff][xoff];
|
||||
cc[1][0]=cluster[yoff+1][xoff];
|
||||
cc[0][1]=cluster[yoff][xoff+1];
|
||||
cc[1][1]=cluster[yoff+1][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(double etax, double etay){
|
||||
|
||||
int ex,ey;
|
||||
|
||||
#ifdef MYROOT1
|
||||
heta->Fill(etax,etay);
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
ex=(etax-etamin)/etastep;
|
||||
ey=(etay-etamin)/etastep;
|
||||
// cout << etax << " " << ex << " " << etay << " " << ey << " " << ey*nbeta+ex << endl;
|
||||
if (ey<nbeta && ex<nbeta && ex>=0 && ey>=0)
|
||||
heta[ey*nbeta+ex]++;
|
||||
// cout << "*"<< etax << " " << etay << endl;
|
||||
/* cout << etax << " " << etay << " " << ex << " " << ey << " " << ey*nbeta+ex << endl; */
|
||||
/* cout <<"********"<< endl << endl ; */
|
||||
#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
|
@ -0,0 +1,85 @@
|
||||
#ifndef ETA_INTERPOLATION_GLOBAL_H
|
||||
#define ETA_INTERPOLATION_GLOBAL_H
|
||||
|
||||
|
||||
#include "etaInterpolationBase.h"
|
||||
|
||||
class etaInterpolationGlobal : public 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){};
|
||||
|
||||
|
||||
|
||||
virtual void prepareInterpolation(int &ok)
|
||||
{
|
||||
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*///
|
||||
double bsize=1./nSubPixels; //precision
|
||||
// cout<<"nPixelsX = "<<nPixelsX<<" nPixelsY = "<<nPixelsY<<" nSubPixels = "<<nSubPixels<<endl;
|
||||
double tot_eta=0;
|
||||
for (int ip=0; ip<nbeta*nbeta; 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
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
double hix[nbeta]; //integral of projection x
|
||||
double hiy[nbeta]; //integral of projection y
|
||||
hix[0]=hx[0];
|
||||
hiy[0]=hy[0];
|
||||
|
||||
for (int ib=1; ib<nbeta; ib++) {
|
||||
hix[ib]=hix[ib-1]+hx[ib];
|
||||
hiy[ib]=hiy[ib-1]+hx[ib];
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
return ;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
152
slsDetectorCalibration/interpolations/etaInterpolationPosXY.h
Normal file
152
slsDetectorCalibration/interpolations/etaInterpolationPosXY.h
Normal file
@ -0,0 +1,152 @@
|
||||
#ifndef ETA_INTERPOLATION_POSXY_H
|
||||
#define ETA_INTERPOLATION_POSXY_H
|
||||
|
||||
|
||||
#include "tiffIO.h"
|
||||
#include "etaInterpolationBase.h"
|
||||
|
||||
class etaInterpolationPosXY : public etaInterpolationBase{
|
||||
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(etaInterpolationPosXY *orig): etaInterpolationBase(orig){};
|
||||
|
||||
virtual etaInterpolationPosXY* Clone() {
|
||||
|
||||
return new etaInterpolationPosXY(this);
|
||||
|
||||
};
|
||||
|
||||
virtual void prepareInterpolation(int &ok)
|
||||
{
|
||||
cout <<"?"<< endl;
|
||||
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*///
|
||||
double bsize=1./nSubPixels; //precision
|
||||
// cout<<"nPixelsX = "<<nPixelsX<<" nPixelsY = "<<nPixelsY<<" nSubPixels = "<<nSubPixels<<endl;
|
||||
double tot_eta=0;
|
||||
double tot_eta_x=0;
|
||||
double tot_eta_y=0;
|
||||
for (int ip=0; ip<nbeta*nbeta; ip++)
|
||||
tot_eta+=heta[ip];
|
||||
cout << "total eta entries is :"<< tot_eta << endl;
|
||||
if (tot_eta<=0) {ok=0; return;};
|
||||
|
||||
|
||||
double hx[nbeta]; //profile x
|
||||
double hy[nbeta]; //profile y
|
||||
double hix[nbeta]; //integral of projection x
|
||||
double hiy[nbeta]; //integral of projection y
|
||||
int ii=0;
|
||||
for (int ib=0; ib<nbeta; ib++) {
|
||||
|
||||
tot_eta_x=0;
|
||||
tot_eta_y=0;
|
||||
|
||||
for (int iby=0; iby<nbeta; iby++) {
|
||||
hx[iby]=heta[iby+ib*nbeta];
|
||||
tot_eta_x+=hx[iby];
|
||||
hy[iby]=heta[ib+iby*nbeta];
|
||||
tot_eta_y+=hy[iby];
|
||||
}
|
||||
|
||||
hix[0]=hx[0];
|
||||
hiy[0]=hy[0];
|
||||
|
||||
for (int iby=1; iby<nbeta; iby++) {
|
||||
hix[iby]=hix[iby-1]+hx[iby];
|
||||
hiy[iby]=hiy[iby-1]+hy[iby];
|
||||
}
|
||||
|
||||
ii=0;
|
||||
|
||||
for (int ibx=0; ibx<nbeta; ibx++) {
|
||||
if (tot_eta_x==0) {
|
||||
hhx[ibx+ib*nbeta]=((float)ibx)/((float)nbeta);
|
||||
ii=(ibx)/nbeta;
|
||||
} else //if (hix[ibx]>(ii+1)*tot_eta_x*bsize)
|
||||
{
|
||||
//ii++;
|
||||
// cout << ib << " x " << ibx << " " << tot_eta_x << " " << (ii)*tot_eta_x*bsize << " " << ii << endl;
|
||||
// }
|
||||
#ifdef MYROOT1
|
||||
hhx->SetBinContent(ibx+1,ib+1,ii);
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
hhx[ibx+ib*nbeta]=hix[ibx]/((float)tot_eta_x);//ii;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/* 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) {
|
||||
hhx[ibx+ib*nbeta]=((float)ibx)/((float)nbeta);
|
||||
ii=(ibx*nSubPixels)/nbeta;
|
||||
} else //if (hiy[ibx]>(ii+1)*tot_eta_y*bsize)
|
||||
{
|
||||
//ii++;
|
||||
//cout << ib << " y " << ibx << " " << tot_eta_y << " "<< (ii)*tot_eta_y*bsize << " " << ii << endl;
|
||||
//}
|
||||
#ifdef MYROOT1
|
||||
hhy->SetBinContent(ib+1,ibx+1,ii);
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
hhy[ib+ibx*nbeta]=hiy[ibx]/((float)tot_eta_y);//ii;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/* if (ii!=(nSubPixels-1)) */
|
||||
/* cout << ib << " y " << tot_eta_y << " " << (ii+1)*tot_eta_y*bsize << " " << ii << " " << hiy[nbeta-1]<< endl; */
|
||||
|
||||
// cout << "y " << nbeta << " " << (ii+1)*tot_eta_x*bsize << " " << ii << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#ifdef SAVE_ALL
|
||||
char tit[10000];
|
||||
|
||||
float *etah=new float[nbeta*nbeta];
|
||||
int etabins=nbeta;
|
||||
|
||||
for (int ii=0; ii<etabins*etabins; ii++) {
|
||||
etah[ii]=hhx[ii];
|
||||
}
|
||||
sprintf(tit,"/scratch/eta_hhx_%d.tiff",id);
|
||||
WriteToTiff(etah, tit, etabins, etabins);
|
||||
|
||||
for (int ii=0; ii<etabins*etabins; ii++) {
|
||||
etah[ii]=hhy[ii];
|
||||
}
|
||||
sprintf(tit,"/scratch/eta_hhy_%d.tiff",id);
|
||||
WriteToTiff(etah, tit, etabins, etabins);
|
||||
|
||||
for (int ii=0; ii<etabins*etabins; ii++) {
|
||||
etah[ii]=heta[ii];
|
||||
}
|
||||
sprintf(tit,"/scratch/eta_%d.tiff",id);
|
||||
WriteToTiff(etah, tit, etabins, etabins);
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
678
slsDetectorCalibration/interpolations/etaVEL/EVELAlg.C
Normal file
678
slsDetectorCalibration/interpolations/etaVEL/EVELAlg.C
Normal file
@ -0,0 +1,678 @@
|
||||
#include <TH1D.h>
|
||||
#include <TH2D.h>
|
||||
#include <TPad.h>
|
||||
#include <TDirectory.h>
|
||||
#include <TEntryList.h>
|
||||
#include <TFile.h>
|
||||
#include <TMath.h>
|
||||
#include <TTree.h>
|
||||
#include <TChain.h>
|
||||
#include <THStack.h>
|
||||
#include <TCanvas.h>
|
||||
#include <TF1.h>
|
||||
#include <TLegend.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <fstream>
|
||||
|
||||
#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.
|
||||
*/
|
||||
int etabins = 25;
|
||||
int nEtas = 25;
|
||||
Double_t dum[3][3];
|
||||
Int_t x,y,f,q;
|
||||
|
||||
int counter[5];
|
||||
int remoteCounter[5];
|
||||
|
||||
//TH2D *sum = new TH2D("sum","sum",3,-0.1,2.1,3,-0.1,2.1);
|
||||
//TH2F *subPos = new TH2F("subPos","subPos", 100, -1.,1. ,100, -1.,1.);
|
||||
TH2D *subPosAEta = new TH2D("subPosAEta","subPosAEta", 50, -.5,1.5 ,50, -.5,1.5);
|
||||
TH2D *subPosBEta = new TH2D("subPosBEta","subPosBEta", 50, -.5,1.5 ,50, -.5,1.5);
|
||||
|
||||
|
||||
|
||||
TH1D *cE = new TH1D("clusterEnergy","clusterEnergy",400, 0.,4000.);
|
||||
//TH1D *cES = new TH1D("clusterEnergyS","clusterEnergyS",400, 0.,4000.);
|
||||
|
||||
|
||||
TH2D *cES3vs2 = new TH2D("clusterEnergy3vs2","clusterEnergy3vs2",800, 0.,8000.,600,0.,6000.);
|
||||
TH2D *cES3vs2S = new TH2D("clusterEnergy3vs2S","clusterEnergy3vs2S",800, 0.,8000.,600,0.,6000.);
|
||||
|
||||
double th = 0.99;
|
||||
double sigmas = 1.0;
|
||||
|
||||
TH2D *imgRLR = new TH2D("imgRLR","imgRLR",160,0.0,160.0 ,160 ,0.0,160.0);
|
||||
TH2D *imgLR = new TH2D("imgLR","imgLR",160*2,0.0,160.0 ,160*2 ,0.0,160.0);
|
||||
|
||||
TH2D *clusHist= new TH2D("clusHist","clusHist",3,-0.5,2.5,3,-0.5,2.5);
|
||||
TH2D *clusHistC= new TH2D("clusHistC","clusHistC",3,-0.5,2.5,3,-0.5,2.5);
|
||||
|
||||
int **imgArray;
|
||||
|
||||
int findShape(Double_t cluster[3][3], double sDum[2][2]){
|
||||
int corner = -1;
|
||||
|
||||
double sum = cluster[0][0] + cluster[1][0] + cluster[2][0] + cluster[0][1] + cluster[1][1] + cluster[2][1] + cluster[0][2] + cluster[1][2] + cluster[2][2];
|
||||
|
||||
double sumTL = cluster[0][0] + cluster[1][0] + cluster[0][1] + cluster[1][1]; //2 ->BL
|
||||
double sumTR = cluster[1][0] + cluster[2][0] + cluster[2][1] + cluster[1][1]; //0 ->TL
|
||||
double sumBL = cluster[0][1] + cluster[0][2] + cluster[1][2] + cluster[1][1]; //3 ->BR
|
||||
double sumBR = cluster[1][2] + cluster[2][1] + cluster[2][2] + cluster[1][1]; //1 ->TR
|
||||
double sumMax = 0;
|
||||
|
||||
|
||||
//double **sDum = subCluster;
|
||||
Double_t ssDum[2][2];
|
||||
|
||||
// if(sumTL >= sumMax){
|
||||
sDum[0][0] = cluster[0][0]; sDum[1][0] = cluster[1][0];
|
||||
sDum[0][1] = cluster[0][1]; sDum[1][1] = cluster[1][1];
|
||||
|
||||
ssDum[0][0] = cluster[0][0]; ssDum[1][0] = cluster[0][1];
|
||||
ssDum[0][1] = cluster[1][0]; ssDum[1][1] = cluster[1][1];
|
||||
|
||||
corner = 2;
|
||||
sumMax=sumTL;
|
||||
// }
|
||||
|
||||
if(sumTR >= sumMax){
|
||||
sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0];
|
||||
sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1];
|
||||
|
||||
ssDum[0][0] = cluster[2][0]; ssDum[1][0] = cluster[2][1];
|
||||
ssDum[0][1] = cluster[1][0]; ssDum[1][1] = cluster[1][1];
|
||||
|
||||
corner = 0;
|
||||
sumMax=sumTR;
|
||||
}
|
||||
|
||||
if(sumBL >= sumMax){
|
||||
sDum[0][0] = cluster[0][1]; sDum[1][0] = cluster[1][1];
|
||||
sDum[0][1] = cluster[0][2]; sDum[1][1] = cluster[1][2];
|
||||
|
||||
ssDum[0][0] = cluster[0][2]; ssDum[1][0] = cluster[0][1];
|
||||
ssDum[0][1] = cluster[1][2]; ssDum[1][1] = cluster[1][1];
|
||||
|
||||
corner = 3;
|
||||
sumMax=sumBL;
|
||||
}
|
||||
|
||||
if(sumBR >= sumMax){
|
||||
sDum[0][0] = cluster[1][1]; sDum[1][0] = cluster[2][1];
|
||||
sDum[0][1] = cluster[1][2]; sDum[1][1] = cluster[2][2];
|
||||
|
||||
ssDum[0][0] = cluster[2][2]; ssDum[1][0] = cluster[2][1];
|
||||
ssDum[0][1] = cluster[1][2]; ssDum[1][1] = cluster[1][1];
|
||||
|
||||
corner = 1;
|
||||
sumMax=sumBR;
|
||||
}
|
||||
|
||||
switch(corner){
|
||||
case 0:
|
||||
cES3vs2->Fill(sum,sumTR); break;
|
||||
case 1:
|
||||
cES3vs2->Fill(sum,sumBR); break;
|
||||
case 2:
|
||||
cES3vs2->Fill(sum,sumTL); break;
|
||||
case 3:
|
||||
cES3vs2->Fill(sum,sumBL); break;
|
||||
}
|
||||
|
||||
counter[corner]++;
|
||||
remoteCounter[q]++;
|
||||
|
||||
// cout << "local corner is: " << corner << " remote corner is: " << q << endl;
|
||||
|
||||
return corner;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int placePhoton( TH2D *img, double subCluster[2][2], int cX, int cY, int corner, double *sX, double *sY, double *scX, double *scY){
|
||||
double tot = subCluster[0][0] + subCluster[0][1] + subCluster[1][0] + subCluster[1][1];
|
||||
double t = subCluster[1][0] + subCluster[1][1];
|
||||
double r = subCluster[0][1] + subCluster[1][1];
|
||||
|
||||
double xHitC = r/tot;
|
||||
double yHitC = t/tot;
|
||||
|
||||
imgRLR->Fill(cX,cY);
|
||||
|
||||
cE->Fill(tot);
|
||||
|
||||
double dX, dY;
|
||||
|
||||
//before looking at annas code
|
||||
/* if(corner == 0){ dX=-1.; dY=-1.; }
|
||||
if(corner == 1){ dX=-1.; dY=+1.; }
|
||||
if(corner == 2){ dX=+1.; dY=-1.; }
|
||||
if(corner == 3){ dX=+1.; dY=+1.; }*/
|
||||
|
||||
if(corner == 0){ dX=-1.; dY=+1.; } //top left
|
||||
if(corner == 1){ dX=+1.; dY=+1.; } //top right
|
||||
if(corner == 2){ dX=-1.; dY=-1.; } //bottom left
|
||||
if(corner == 3){ dX=+1.; dY=-1.; } //bottom right
|
||||
|
||||
imgLR->Fill(cX+0.25*dX,cY+0.25*dY);
|
||||
|
||||
double posX = ((double)cX) + 0.5*dX + xHitC;
|
||||
double posY = ((double)cY) + 0.5*dY + yHitC;
|
||||
|
||||
subPosBEta->Fill(xHitC ,yHitC);
|
||||
if(img){
|
||||
img->Fill(posX,posY);
|
||||
}
|
||||
|
||||
if(xHitC < 0.02&& yHitC < 0.02){
|
||||
|
||||
cES3vs2S->Fill(dum[0][0]+dum[0][1]+dum[0][2]+dum[1][0]+dum[1][1]+dum[1][2]+dum[2][0]+dum[2][1]+dum[2][2],subCluster[0][0]+subCluster[0][1]+subCluster[1][0]+subCluster[1][1]);
|
||||
}
|
||||
|
||||
|
||||
if(sX && sY && scX && scY){
|
||||
*sX = xHitC; //0.5 + 0.5*dX + xHitC;
|
||||
*sY = yHitC; //0.5 + 0.5*dY + yHitC;
|
||||
*scX = ((double)cX) + 0.5*dX;
|
||||
*scY = ((double)cY) + 0.5*dY;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void placePhotonCorr(TH2D *img, EtaVEL *e,double sX, double sY, double scX, double scY){
|
||||
int bin = e->findBin(sX,sY);
|
||||
if(bin <= 0) return;
|
||||
double subX = ((double)(e->getXBin(bin))+.5)/((double)e->getNPixels());
|
||||
double subY = ((double)(e->getYBin(bin))+.5)/((double)e->getNPixels());
|
||||
|
||||
if(img!=NULL){
|
||||
img->Fill(scX+ subX , scY+ subY);
|
||||
}
|
||||
subPosAEta->Fill(subX,subY);
|
||||
|
||||
int iscx = scX;
|
||||
int iscy = scY;
|
||||
if(iscx >=nx || iscx<0 || iscy >=ny || iscy<0) return;
|
||||
//cout << iscx*e->getNPixels()+e->getXBin(bin) << " " << iscy*e->getNPixels()+e->getXBin(bin) << endl;
|
||||
if(img==NULL) return;
|
||||
imgArray[iscx*e->getNPixels()+e->getXBin(bin)][iscy*e->getNPixels()+e->getYBin(bin)]++;
|
||||
}
|
||||
|
||||
void gainCorrection(Double_t corrected[3][3], TH2D *gainMap){
|
||||
|
||||
for(int xx = 0; xx < 3; xx++)
|
||||
for(int yy = 0; yy < 3; yy++){
|
||||
if(gainMap && gainMap->GetBinContent(x+xx+2,y+yy+2) != 0){
|
||||
corrected[xx][yy] = dum[xx][yy] / gainMap->GetBinContent(x+xx+2,y+yy+2);
|
||||
clusHistC->Fill(xx,yy,corrected[xx][yy]);
|
||||
}
|
||||
else
|
||||
corrected[xx][yy] = dum[xx][yy];
|
||||
|
||||
clusHist->Fill(xx,yy,dum[xx][yy]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EtaVEL *plotEtaDensity(TChain* tree2, TEntryList *el, EtaVEL *oldEta = NULL, TH2D **img = NULL, TH2D *gainMap=NULL, int nPixels=25) {
|
||||
|
||||
|
||||
|
||||
EtaVEL *newEta = new EtaVEL(25,-0.02,1.02);
|
||||
|
||||
Long64_t listEntries=el->GetN();
|
||||
Long64_t treeEntry;
|
||||
Long64_t chainEntry;
|
||||
|
||||
Int_t treenum=0;
|
||||
tree2->SetEntryList(el);
|
||||
|
||||
double gainCorrC[3][3];
|
||||
double subCluster[2][2];
|
||||
double sX, sY, scX, scY;
|
||||
|
||||
cout << "Events: " << listEntries << endl;
|
||||
if(oldEta == NULL){ cout << "Old Eta is NULL " << endl; }
|
||||
for(int i = 0; i<4; i++){ counter[i] = 0; remoteCounter[i] = 0; }
|
||||
|
||||
for (Long64_t il =0; il<listEntries;il++) {
|
||||
treeEntry = el->GetEntryAndTree(il,treenum);
|
||||
|
||||
chainEntry = treeEntry+tree2->GetTreeOffset()[treenum];
|
||||
if (tree2->GetEntry(chainEntry)) {
|
||||
|
||||
gainCorrection(gainCorrC,gainMap);
|
||||
//cout << gainCorrC[1][1] << endl;
|
||||
|
||||
//finds corner
|
||||
int corner = findShape(gainCorrC,subCluster);
|
||||
|
||||
int validEvent;
|
||||
|
||||
|
||||
if(img){
|
||||
validEvent = placePhoton(img[0],subCluster,x,y, corner, &sX, &sY, &scX, &scY);
|
||||
}else{
|
||||
//calc etaX, etaY
|
||||
validEvent = placePhoton(NULL,subCluster,x,y, corner, &sX, &sY, &scX, &scY);
|
||||
}
|
||||
|
||||
//fill etavel
|
||||
newEta->fill(sX,sY);
|
||||
|
||||
|
||||
|
||||
|
||||
if(oldEta && img && img[1]){
|
||||
placePhotonCorr(img[1],oldEta, sX,sY, scX, scY);
|
||||
}else{
|
||||
placePhotonCorr(NULL,newEta,sX,sY,scX,scY);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//cout << il << endl;
|
||||
int ssize = 500000;
|
||||
if(il % ssize == 0 && il != 0 && oldEta==NULL){
|
||||
|
||||
cout << " -------------- "<< endl;
|
||||
newEta->updatePixelPos();
|
||||
|
||||
|
||||
//newEta->resolveSelfIntersect();
|
||||
char tit[1000];
|
||||
/* TFile *ff = new TFile("/scratch/Spider.root","UPDATE");
|
||||
sprintf(tit,"subPosAEta%i",newEta->getIt()); subPosAEta->SetName(tit);
|
||||
subPosAEta->Write(); subPosAEta->Reset();
|
||||
sprintf(tit,"subPosBEta%i",newEta->getIt()); subPosBEta->SetName(tit);
|
||||
subPosBEta->Write(); subPosBEta->Reset();
|
||||
sprintf(tit,"Eta%i",newEta->getIt()); newEta->Write(tit);
|
||||
ff->Close(); */
|
||||
//il = 0;
|
||||
}
|
||||
|
||||
if(il % ssize == ssize-1){
|
||||
double prog = (double)il/(double)listEntries*100.;
|
||||
cout << prog << "%" << endl;
|
||||
//if(prog > 19.) return newEta;
|
||||
if(newEta->converged == 1){ cout << "converged ... " << endl; return newEta; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cout << "local corners: " ;
|
||||
for(int i = 0; i<4; i++) cout << i << ": " << counter[i] << " || " ;
|
||||
cout << endl;
|
||||
|
||||
//cout << "remote corners: " ;
|
||||
//for(int i = 0; i<4; i++) cout << i << ": " << remoteCounter[i] << " || " ;
|
||||
//cout << endl;
|
||||
|
||||
return newEta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TChain *openTree(char *tname, char *fname,double lEc, double hEc, double rms=5., char *chainName=">>thischan"){
|
||||
TChain *tree2;
|
||||
// TH1D **etaDI;
|
||||
char cut[1000];
|
||||
|
||||
tree2=new TChain(tname);
|
||||
tree2->Add(fname);
|
||||
tree2->Print();
|
||||
|
||||
//sprintf(cut,"(x<=40) && (data[%d][%d]>%f*rms) && Sum$(data)<%f && Sum$(data)>%f",1,1,rms, hEc, lEc);
|
||||
// sprintf(cut,"(x<=40) && (data[%d][%d]>%f*rms)",1,1,rms);// && Sum$(data)<%f && Sum$(data)>%f",1,1,rms, hEc, lEc);
|
||||
sprintf(cut,"(x<=40) && Sum$(data)<%f && Sum$(data)>%f", hEc, lEc);
|
||||
// sprintf(cut,"");
|
||||
cout << cut << endl;
|
||||
|
||||
tree2->Draw(chainName, cut, "entrylist");
|
||||
|
||||
|
||||
tree2->SetBranchAddress("iFrame",&f);
|
||||
tree2->SetBranchAddress("x",&x);
|
||||
tree2->SetBranchAddress("y",&y);
|
||||
tree2->SetBranchAddress("data",dum);
|
||||
//tree2->SetBranchAddress("q",&q);
|
||||
|
||||
cout << "openTree : end" << endl;
|
||||
return tree2;
|
||||
}
|
||||
|
||||
EtaVEL *etaDensity(char *tname, char *fname, double lEc = 1000, double hEc=3000, TH2D *gainMap=NULL, int nPixels=25) {
|
||||
/** open tree and make selection */
|
||||
TChain *tree2 = openTree(tname,fname,lEc,hEc);
|
||||
TEntryList *elist = (TEntryList*)gDirectory->Get("thischan");
|
||||
if(elist == NULL) { cout << "could not open tree " << endl; return NULL; }
|
||||
|
||||
EtaVEL *etaDen = plotEtaDensity(tree2,elist,NULL,NULL,gainMap,nPixels);
|
||||
|
||||
|
||||
//etaDen->Draw("colz");
|
||||
cout << "done" << endl;
|
||||
|
||||
return etaDen;
|
||||
}
|
||||
|
||||
void interpolate(char *tname, char *fname, EtaVEL *etaDI, double lEc = 1000, double hEc=3000, TH2D *gainMap=NULL) {
|
||||
|
||||
TChain *tree2 = openTree(tname,fname,lEc,hEc,5.,">>intChain");
|
||||
TEntryList *elist = (TEntryList*)gDirectory->Get("intChain");
|
||||
if(elist == NULL) { cout << "could not open tree " << endl; return; }
|
||||
|
||||
double nPixels = (double)etaDI->getNPixels();
|
||||
|
||||
TH2D **img = new TH2D*[3];
|
||||
img[0] = new TH2D("img","img",nPixels*160,0.0,160.0 ,nPixels*160 ,0.0,160.0);
|
||||
img[1] = new TH2D("imgE","imgE",nPixels*160,0.0,160.0 ,nPixels*160 ,0.0,160.0);
|
||||
|
||||
int inPixels = etaDI->getNPixels();
|
||||
|
||||
imgArray = new int*[inPixels*160];
|
||||
for(int i = 0; i < inPixels*160; i++){
|
||||
imgArray[i] = new int[inPixels*160];
|
||||
for(int j = 0; j < inPixels*160; j++){
|
||||
imgArray[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "starting" << endl;
|
||||
plotEtaDensity(tree2,elist, etaDI,img,gainMap);
|
||||
|
||||
//img->Draw("colz");
|
||||
}
|
||||
|
||||
|
||||
TH2D *createGainMap(char *tname, char *fname, double lEc = 0,double hEc=10000){
|
||||
char name[100];
|
||||
TH1D *avgSpec3 = new TH1D("avgSpec3", "avgSpec3",hEc/20,0,hEc);
|
||||
TH1D ***specs3 = new TH1D**[160];
|
||||
TH1D ***specs1 = new TH1D**[160];
|
||||
for(int xx = 0; xx < 160; xx++){
|
||||
specs3[xx] = new TH1D*[160];
|
||||
specs1[xx] = new TH1D*[160];
|
||||
for(int yy = 0; yy < 160; yy++){
|
||||
sprintf(name,"S3x%iy%i",xx,yy);
|
||||
specs3[xx][yy] = new TH1D(name,name,hEc/20,0,hEc);
|
||||
sprintf(name,"S1x%iy%i",xx,yy);
|
||||
specs1[xx][yy] = new TH1D(name,name,hEc/20,0,hEc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TChain *tree2 = openTree(tname,fname,0,hEc,5.,">>gainChan");
|
||||
TEntryList *elist = (TEntryList*)gDirectory->Get("gainChan");
|
||||
if(elist == NULL) { cout << "could not open tree " << endl; return NULL; }
|
||||
|
||||
Long64_t listEntries=elist->GetN();
|
||||
Long64_t treeEntry;
|
||||
Long64_t chainEntry;
|
||||
|
||||
Int_t treenum=0;
|
||||
tree2->SetEntryList(elist);
|
||||
|
||||
cout << "Events: " << listEntries << endl;
|
||||
for(int i = 0; i<4; i++) counter[i] = 0;
|
||||
for (Long64_t il =0; il<listEntries;il++) {
|
||||
treeEntry = elist->GetEntryAndTree(il,treenum);
|
||||
chainEntry = treeEntry+tree2->GetTreeOffset()[treenum];
|
||||
|
||||
if (tree2->GetEntry(chainEntry)) {
|
||||
double sum = 0;
|
||||
for(int xx = 0; xx < 3; xx++)
|
||||
for(int yy = 0; yy < 3; yy++)
|
||||
sum += dum[xx][yy];
|
||||
specs3[x][y]->Fill(sum);
|
||||
specs1[x][y]->Fill(dum[1][1]);
|
||||
avgSpec3->Fill(sum);
|
||||
}
|
||||
}
|
||||
|
||||
TH2D *gainMap3 = new TH2D("gainMap3","gainMap3",160,-0.5,160.-0.5,160,-.5,160.-.5);
|
||||
TH2D *gainMap1 = new TH2D("gainMap1","gainMap1",160,-0.5,160.-0.5,160,-.5,160.-.5);
|
||||
for(int xx = 0; xx < 160; xx++){
|
||||
for(int yy = 0; yy < 160; yy++){
|
||||
TF1 *gf3 = new TF1("gf3","gaus", lEc, hEc);
|
||||
specs3[xx][yy]->Fit(gf3,"Q");
|
||||
double e3 = gf3->GetParameter(1);
|
||||
gainMap3->Fill(xx,yy,e3);
|
||||
|
||||
TF1 *gf1 = new TF1("gf1","gaus", lEc, hEc);
|
||||
specs1[xx][yy]->Fit(gf1,"Q");
|
||||
double e1 = gf1->GetParameter(1);
|
||||
gainMap1->Fill(xx,yy,e1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return gainMap3;
|
||||
}
|
||||
|
||||
void writeMatlab2DHisto(int xx, int yy,char *outFileName){
|
||||
ofstream outFile;
|
||||
outFile.open (outFileName);
|
||||
|
||||
cout << "create matlab file with " << xx << " xbins and " << yy << " ybins" << endl;
|
||||
|
||||
for(int y = 0; y < yy; y++){
|
||||
for(int x = 0; x < xx; x++){
|
||||
outFile << imgArray[x][y] << "\t";
|
||||
}
|
||||
outFile << endl;
|
||||
}
|
||||
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
//COMPLETE STUFF
|
||||
|
||||
void createImage(char *tdir, char *tname, char *ftname, char *ifname = NULL, int useGM=0, double lEth=-1., double hEth=-1.){
|
||||
imgRLR->Reset();
|
||||
imgLR->Reset();
|
||||
|
||||
char fname[1000];
|
||||
char inFName[1000];
|
||||
char outFName[1000];
|
||||
char moutFName[1000];
|
||||
if(ifname == NULL){
|
||||
sprintf(fname,"%s/%s_*.root",tdir,tname);
|
||||
}else{
|
||||
sprintf(fname,"%s",ifname);
|
||||
}
|
||||
|
||||
if(useGM) sprintf(inFName,"%s/%s-PlotsWGMVEL.root",tdir,ftname);
|
||||
else sprintf(inFName,"%s/%s-PlotsVEL.root",tdir,ftname);
|
||||
|
||||
sprintf(outFName,"%s/%s-ImgVEL.root",tdir,tname);
|
||||
sprintf(moutFName,"%s/%s-ImgVEL.mf",tdir,tname);
|
||||
|
||||
TFile *inFile = new TFile(inFName,"READ");
|
||||
|
||||
cout << "Image Tree File Name: " << fname << endl;
|
||||
cout << "Eta File Name: " << inFName << endl;
|
||||
cout << "Out File Name: " << outFName << endl;
|
||||
cout << "Matlab Out File Name: " << moutFName << endl;
|
||||
|
||||
TH2D *gm = NULL;
|
||||
if(useGM){
|
||||
cout << "Load gain map" << endl;
|
||||
gm = (TH2D *)gDirectory->Get("gainMap");
|
||||
if(gm == NULL){ cout << "can not find gainMap in file" << endl; return; }
|
||||
}
|
||||
|
||||
cout << "Load eta" << endl;
|
||||
EtaVEL *ee = (EtaVEL *)gDirectory->Get("etaDist");
|
||||
|
||||
cout << "Select Energy BW" << endl;
|
||||
TH1D *spec = (TH1D *)gDirectory->Get("avgSpec3");
|
||||
if(spec == NULL){ cout << "can not find avgSpec3" << endl; return; }
|
||||
|
||||
TF1 *gf3 = new TF1("gf3","gaus", 0, 10000);
|
||||
spec->Fit(gf3,"Q");
|
||||
double avgE = gf3->GetParameter(1);
|
||||
double sigE = gf3->GetParameter(2);
|
||||
cout << "avgE: " << avgE << " sigE: " << sigE << endl;
|
||||
cout << endl;
|
||||
|
||||
if(lEth == -1.) lEth = avgE-5.*sigE;
|
||||
if(hEth == -1.) hEth = avgE+5.*sigE;
|
||||
cout << lEth << " < E < " << hEth << " (eV)" << endl;
|
||||
|
||||
cout << "start with interpolation" << endl;
|
||||
interpolate( tname, fname, ee,lEth,hEth ,gm);
|
||||
|
||||
|
||||
TH2D *img = (TH2D *)gDirectory->Get("img");
|
||||
if(img == NULL){ cout << "could not find 2d-histogram: img " << endl; return; }
|
||||
|
||||
|
||||
TH2D *imgE = (TH2D *)gDirectory->Get("imgE");
|
||||
if(imgE == NULL){ cout << "could not find 2d-histogram: imgE " << endl; return; }
|
||||
|
||||
|
||||
//TH2D *imgEOM = (TH2D *)gDirectory->Get("imgEOM");
|
||||
//if(imgEOM == NULL){ cout << "could not find 2d-histogram: imgEOM " << endl; return; }
|
||||
|
||||
TFile *outFile = new TFile(outFName,"UPDATE");
|
||||
imgLR->Write();
|
||||
imgRLR->Write();
|
||||
imgE->Write();
|
||||
//imgEOM->Write();
|
||||
img->Write();
|
||||
outFile->Close();
|
||||
inFile->Close();
|
||||
cout << "writing matlab file: " << moutFName << endl;
|
||||
writeMatlab2DHisto(160*ee->getNPixels(),160*ee->getNPixels(),moutFName);
|
||||
cout << "Done : " << outFName << endl;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
\par tdir input tree directory
|
||||
\par tname input tree name
|
||||
\par ifname input file name if different than tdir/tname_*.root
|
||||
\par useGM use gain map
|
||||
\par maxExpEinEv spectrum maximum
|
||||
\par nPixels sub-pixels bins
|
||||
\par lEth low threshold
|
||||
\par hEth high threshold
|
||||
|
||||
*/
|
||||
|
||||
|
||||
EtaVEL *createGainAndEtaFile(char *tdir, char *tname, char *ifname=NULL, int useGM=0, double maxExpEinEv=25000., int nPixels =25, double lEth=-1., double hEth=-1.){
|
||||
char fname[1000];
|
||||
char outFName[1000];
|
||||
|
||||
|
||||
if(ifname == NULL){
|
||||
sprintf(fname,"%s/%s_*.root",tdir,tname);
|
||||
}else{
|
||||
sprintf(fname,"%s",ifname);
|
||||
}
|
||||
|
||||
if(useGM) sprintf(outFName,"%s/%s-PlotsWGVEL.root",tdir,tname);
|
||||
else sprintf(outFName,"%s/%s-PlotsVEL.root",tdir,tname);
|
||||
|
||||
|
||||
cout << "Tree File Name: " << fname << endl;
|
||||
cout << "Output File Name: " << outFName << endl;
|
||||
|
||||
/** creates gain map and 3x3 spectrum */
|
||||
cout << "Creating gain map: " << endl;
|
||||
TH2D *gm = createGainMap(tname,fname,0,maxExpEinEv/10.);
|
||||
gm->SetName("gainMap");
|
||||
|
||||
|
||||
/** gets average 3x3 spectrum and fits it with a gaus */
|
||||
TH1D *spec = (TH1D *)gDirectory->Get("avgSpec3");
|
||||
if(spec == NULL){ cout << "can not find avgSpec3" << endl; return NULL; }
|
||||
TF1 *gf3 = new TF1("gf3","gaus", 0, maxExpEinEv/10.);
|
||||
spec->Fit(gf3,"Q");
|
||||
double avgE = gf3->GetParameter(1);
|
||||
double sigE = gf3->GetParameter(2);
|
||||
cout << "avgE: " << avgE << " sigE: " << sigE << endl;
|
||||
cout << endl;
|
||||
|
||||
|
||||
/** sets high and low threshold if not given by the user */
|
||||
if(lEth == -1.) lEth = avgE-5.*sigE;
|
||||
if(hEth == -1.) hEth = avgE+5.*sigE;
|
||||
cout << lEth << " < E < " << hEth << " (eV)" << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
cout << "calculating eta stuff" << endl;
|
||||
|
||||
EtaVEL *newEta;
|
||||
if(useGM) newEta = etaDensity(tname,fname,lEth,hEth,gm,nPixels);
|
||||
else newEta = etaDensity(tname,fname,lEth,hEth,NULL,nPixels);
|
||||
|
||||
cout << "writing to file " << outFName << endl;
|
||||
|
||||
TFile *outFile = new TFile(outFName,"UPDATE");
|
||||
|
||||
newEta->Write("etaDist");
|
||||
|
||||
gm->Write();
|
||||
spec->Write();
|
||||
subPosAEta->Write();
|
||||
cES3vs2->Write();
|
||||
|
||||
outFile->Close();
|
||||
cout << "Done : " << outFName << endl;
|
||||
return newEta;
|
||||
}
|
||||
|
||||
void exportSpec(char *tdir, char *tname){
|
||||
char tfname[1000];
|
||||
char ofname[1000];
|
||||
char cleanName[1000];
|
||||
|
||||
for(int p = 0; p < strlen(tname);p++){
|
||||
cleanName[p+1] = '\0';
|
||||
cleanName[p] = tname[p];
|
||||
|
||||
if(tname[p] == '-') cleanName[p] = '_';
|
||||
}
|
||||
|
||||
sprintf(tfname,"%s/%s-PlotsVEL.root",tdir,tname);
|
||||
sprintf(ofname,"%s/%s_SpecVEL.m",tdir,cleanName);
|
||||
TFile *tf = new TFile(tfname);
|
||||
TH1D *spec = (TH1D *)gDirectory->Get("avgSpec3");
|
||||
|
||||
ofstream outFile;
|
||||
outFile.open (ofname);
|
||||
|
||||
if(outFile.fail()){
|
||||
cout << "Could not open file : " << ofname << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "create matlab file with with spec " << ofname << endl;
|
||||
|
||||
|
||||
outFile << cleanName << " = [ " << endl;
|
||||
for(int i = 0; i < spec->GetNbinsX(); i++){
|
||||
outFile << i << " " << spec->GetBinCenter(i) << " " << spec->GetBinContent(i) << " ; " << endl;
|
||||
}
|
||||
|
||||
outFile << " ] ; " << endl;
|
||||
|
||||
outFile.close();
|
||||
}
|
679
slsDetectorCalibration/interpolations/etaVEL/EtaVEL.cpp
Normal file
679
slsDetectorCalibration/interpolations/etaVEL/EtaVEL.cpp
Normal file
@ -0,0 +1,679 @@
|
||||
#include "EtaVEL.h"
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
ClassImp(EtaVEL);
|
||||
|
||||
double Median(const TH1D * histo1) {
|
||||
|
||||
int numBins = histo1->GetXaxis()->GetNbins();
|
||||
Double_t *x = new Double_t[numBins];
|
||||
Double_t* y = new Double_t[numBins];
|
||||
for (int i = 0; i < numBins; i++) {
|
||||
x[i] = histo1->GetBinCenter(i);
|
||||
y[i] = histo1->GetBinContent(i);
|
||||
}
|
||||
return TMath::Median(numBins, x, y);
|
||||
}
|
||||
|
||||
|
||||
double *EtaVEL::getPixelCorners(int x, int y){
|
||||
double tlX,tlY,trX,trY,blX,blY,brX,brY;
|
||||
tlX = xPPos[getCorner(x,y+1)];
|
||||
tlY = yPPos[getCorner(x,y+1)];
|
||||
trX = xPPos[getCorner(x+1,y+1)];
|
||||
trY = yPPos[getCorner(x+1,y+1)];
|
||||
blX = xPPos[getCorner(x,y)];
|
||||
blY = yPPos[getCorner(x,y)];
|
||||
brX = xPPos[getCorner(x+1,y)];
|
||||
brY = yPPos[getCorner(x+1,y)];
|
||||
|
||||
//cout << "gPC: TL: " << getCorner(x,y+1) << " TR: " << getCorner(x+1,y+1) << " BL " << getCorner(x,y) << " BR " << getCorner(x+1,y) << endl;
|
||||
|
||||
double *c = new double[8];
|
||||
c[0] = tlX; c[1] = trX; c[2] = brX; c[3] = blX;
|
||||
c[4] = tlY; c[5] = trY; c[6] = brY; c[7] = blY;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
int EtaVEL::findBin(double xx, double yy){
|
||||
|
||||
double tlX,tlY,trX,trY,blX,blY,brX,brY;
|
||||
/********Added by anna ******/
|
||||
// if (xx<min) xx=min+1E-6;
|
||||
// if (xx>max) xx=max-1E-6;
|
||||
// if (yy<min) yy=min+1E-6;
|
||||
// if (yy>max) yy=max-1E-6;
|
||||
/**************/
|
||||
|
||||
|
||||
int bin = -1;
|
||||
for(int x = 0; x < nPixels; x++){
|
||||
for(int y = 0; y < nPixels; y++){
|
||||
double *c = getPixelCorners(x,y);
|
||||
tlX = c[0]; trX = c[1]; brX = c[2]; blX = c[3];
|
||||
tlY = c[4]; trY = c[5]; brY = c[6]; blY = c[7];
|
||||
|
||||
///if(y == 0){
|
||||
// cout << "x: " << x << " blY " << blY << " brY " << brY << endl;
|
||||
//}
|
||||
|
||||
int out = 0;
|
||||
|
||||
double tb = 0;
|
||||
double bb = 0;
|
||||
double lb = 0;
|
||||
double rb = 0;
|
||||
|
||||
if((trX-tlX)>0.)
|
||||
tb = (trY - tlY)/(trX-tlX);
|
||||
|
||||
if((brX-blX)>0.)
|
||||
bb = (brY - blY)/(brX-blX);
|
||||
|
||||
if((tlY-blY)>0.)
|
||||
lb = (tlX - blX)/(tlY-blY);
|
||||
|
||||
if((trY-brY)>0.)
|
||||
rb = (trX - brX)/(trY-brY);
|
||||
|
||||
double ty = tlY + tb * (xx - tlX);
|
||||
double by = blY + bb * (xx - blX);
|
||||
|
||||
double lx = blX + lb * (yy - blY);
|
||||
double rx = brX + rb * (yy - brY);
|
||||
|
||||
|
||||
|
||||
|
||||
if(yy >= ty) out++;
|
||||
if(yy < by) out++;
|
||||
if(xx < lx) out++;
|
||||
if(xx >= rx) out++;
|
||||
|
||||
//cout << "ty " << ty << endl;
|
||||
//cout << "by " << by << endl;
|
||||
//cout << "lx " << lx << endl;
|
||||
//cout << "rx " << rx << endl;
|
||||
|
||||
//double dist = (xx - xPPos[getBin(x,y)]) * (xx - xPPos[getBin(x,y)]) + (yy - yPPos[getBin(x,y)]) * (yy - yPPos[getBin(x,y)]);
|
||||
//cout << "x " << x << " y " << y << " out " << out << " ty " << ty << endl;
|
||||
//cout << "tl " << tlX << "/" << tlY << " tr " << trX << "/" << trY << endl;
|
||||
//cout << "bl " << blX << "/" << blY << " br " << brX << "/" << brY << endl;
|
||||
|
||||
//cout << " tb " << tb << endl;
|
||||
|
||||
|
||||
delete[] c;
|
||||
if(out == 0){ return getBin(x,y); }
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void EtaVEL::createLogEntry(){
|
||||
if(it >= nIterations){
|
||||
cerr << "log full" << endl;
|
||||
}
|
||||
log[it].itN = it;
|
||||
log[it].xPos = new double[nPixels*nPixels+1];
|
||||
log[it].yPos = new double[nPixels*nPixels+1];
|
||||
log[it].binCont = new double[nPixels*nPixels+1];
|
||||
for(int x = 0; x < nPixels; x++)
|
||||
for(int y = 0; y < nPixels; y++){
|
||||
log[it].xPos[getBin(x,y)] = xPPos[getBin(x,y)];
|
||||
log[it].yPos[getBin(x,y)] = yPPos[getBin(x,y)];
|
||||
log[it].binCont[getBin(x,y)] = binCont[getBin(x,y)];
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
void EtaVEL::updatePixelCorner(){
|
||||
double w = 20;
|
||||
int rows = (nPixels+1)*(nPixels+1) + 4 + 4 * 4;//(4*(nPixels+1))-4;
|
||||
int cols = (nPixels+1)*(nPixels+1);
|
||||
|
||||
double *rVx = new double[rows];
|
||||
double *rVy = new double[rows];
|
||||
|
||||
double *posMat = new double[rows*cols];
|
||||
for(int i = 0 ; i < rows*cols; i++) posMat[i] = 0;
|
||||
int boundaryPoint = 0;
|
||||
|
||||
cout << "linear sys stuff" << endl;
|
||||
|
||||
double minELength = 100000000000000; int minX=-1, minY=-1;
|
||||
|
||||
for(int y = 0; y < nPixels+1; y++){
|
||||
for(int x = 0; x < nPixels+1; x++){
|
||||
double bx = 0, by = 0;
|
||||
|
||||
//boundary conditions
|
||||
|
||||
if((x == 0 && y % 5 == 0) ||
|
||||
(x == nPixels && y % 5 == 0) ||
|
||||
(y == 0 && x % 5 == 0) ||
|
||||
(y == nPixels && x % 5 == 0)){
|
||||
|
||||
bx = xPPos[getCorner(x,y)];
|
||||
//cout << "bP " << boundaryPoint << " bx " << bx << endl;
|
||||
by = yPPos[getCorner(x,y)];
|
||||
rVx[(nPixels+1)*(nPixels+1) + boundaryPoint] = bx*w;
|
||||
rVy[(nPixels+1)*(nPixels+1) + boundaryPoint] = by*w;
|
||||
posMat[(nPixels+1)*(nPixels+1)*cols + boundaryPoint * cols + getCorner(x,y)-1] = w;
|
||||
boundaryPoint++;
|
||||
}
|
||||
|
||||
double tot = 4 - (x == 0) - (y == 0) - (x == nPixels) - (y == nPixels);
|
||||
//cout << "totW: " << tot << endl;
|
||||
//tot = 4.;
|
||||
double eLength = 0;
|
||||
if(x != 0) eLength += edgeL[getEdgeX(x-1,y)];
|
||||
if(y != 0) eLength += edgeL[getEdgeY(x,y-1)];
|
||||
if(x != nPixels) eLength += edgeL[getEdgeX(x,y)];
|
||||
if(y != nPixels) eLength += edgeL[getEdgeY(x,y)];
|
||||
|
||||
/*cout << "Corner X:" <<x << " Y: " << y ;
|
||||
cout << " C# " << getCorner(x,y);
|
||||
cout << " eXl " << getEdgeX(x-1,y) << "(C# " << getCorner(x-1,y) << " ) ";
|
||||
cout << " eXr " << getEdgeX(x,y) << "(C# " << getCorner(x+1,y) << " ) ";
|
||||
cout << " eYb " << getEdgeY(x,y-1) << "(C# " << getCorner(x,y-1) << " ) ";
|
||||
cout << " eYt " << getEdgeY(x,y) << "(C# " << getCorner(x,y+1) << " ) " << endl; */
|
||||
//" totW: " << tot << " totE: " << eLength << endl;
|
||||
|
||||
if(eLength < minELength & tot == 4){
|
||||
minELength = eLength;
|
||||
minX = x; minY = y;
|
||||
}
|
||||
|
||||
|
||||
//matrixes updated
|
||||
if(x != 0) posMat[y*(nPixels+1)*cols+x*cols+getCorner(x-1,y)-1] = -edgeL[getEdgeX(x-1,y)]/eLength;
|
||||
if(y != 0) posMat[y*(nPixels+1)*cols+x*cols+getCorner(x,y-1)-1] = -edgeL[getEdgeY(x,y-1)]/eLength;;
|
||||
if(x != nPixels) posMat[y*(nPixels+1)*cols+x*cols+getCorner(x+1,y)-1] = -edgeL[getEdgeX(x,y)]/eLength;;
|
||||
if(y != nPixels) posMat[y*(nPixels+1)*cols+x*cols+getCorner(x,y+1)-1] = -edgeL[getEdgeY(x,y)]/eLength;;
|
||||
|
||||
posMat[y*(nPixels+1)*cols+x*cols+getCorner(x,y)-1] = 1.;
|
||||
rVx[getCorner(x,y)-1] = 0.;
|
||||
rVy[getCorner(x,y)-1] = 0.;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Min Corner X: " <<minX << " Y: " << minY << " C# " << getCorner(minX,minY) << " length " << minELength << endl;
|
||||
|
||||
TMatrixD *k = new TMatrixD(rows,cols);
|
||||
TVectorD *fx = new TVectorD(rows,rVx);
|
||||
TVectorD *fy = new TVectorD(rows,rVy);
|
||||
// f->Print();
|
||||
k->SetMatrixArray(posMat);
|
||||
// k->Print();
|
||||
|
||||
|
||||
//solve linear system
|
||||
|
||||
Bool_t ok;
|
||||
TDecompSVD *s = new TDecompSVD(*k);
|
||||
s->Solve(*fx);
|
||||
s->Solve(*fy);
|
||||
|
||||
double *fxA = fx->GetMatrixArray();
|
||||
double *fyA = fy->GetMatrixArray();
|
||||
|
||||
|
||||
for(int y = 0; y < nPixels+1; y++){
|
||||
for(int x = 0; x < nPixels+1; x++){
|
||||
//do not update boundaries
|
||||
|
||||
if(!(x == 0 ||
|
||||
x == nPixels||
|
||||
y == 0 ||
|
||||
y == nPixels)){
|
||||
xPPos[getCorner(x,y)] = fxA[getCorner(x,y)-1];
|
||||
yPPos[getCorner(x,y)] = fyA[getCorner(x,y)-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EtaVEL::updatePixelPos(){
|
||||
double xMov, yMov, d1Mov, d2Mov;
|
||||
createLogEntry();
|
||||
double *chMap = getChangeMap();
|
||||
int ch =0;
|
||||
|
||||
cout << "update edge lengths" << endl;
|
||||
for(int x = 0; x < nPixels; x++)
|
||||
for(int y = 0; y < nPixels; y++){
|
||||
|
||||
|
||||
/*cout << "Pixel X:" <<x << " Y: " << y << " P# " << getBin(x,y) << " eXb " << getEdgeX(x,y);
|
||||
cout << " eXt " << getEdgeX(x,y+1) << " eYl " << getEdgeY(x,y) << " eYr " << getEdgeY(x+1,y) << endl;
|
||||
*/
|
||||
|
||||
edgeL[getEdgeX(x,y)] *= chMap[getBin(x,y)];
|
||||
edgeL[getEdgeX(x,y+1)] *= chMap[getBin(x,y)];
|
||||
edgeL[getEdgeY(x,y)] *= chMap[getBin(x,y)];
|
||||
edgeL[getEdgeY(x+1,y)] *= chMap[getBin(x,y)];
|
||||
|
||||
//cout << "Pixel x: " << x << " y: " << y << " Ch: " << chMap[getBin(x,y)] << " counts: " << binCont[getBin(x,y)] << endl;
|
||||
//cout << "BE " << getEdgeX(x,y) << endl;
|
||||
//cout << "TE " << getEdgeX(x,y+1) << endl;
|
||||
//cout << "LE " << getEdgeY(x,y) << endl;
|
||||
//cout << "RE " << getEdgeY(x+1,y) << endl;
|
||||
binCont[getBin(x,y)] = 0;
|
||||
}
|
||||
|
||||
updatePixelCorner();
|
||||
|
||||
//double *pSize = getSizeMap();
|
||||
double totEdgeLength = 0;
|
||||
for(int e = 1; e < 2*nPixels*(nPixels+1)+1; e++){
|
||||
totEdgeLength += edgeL[e];
|
||||
}
|
||||
cout << "tot edge Length: " << totEdgeLength << endl;
|
||||
|
||||
totCont = 0.;
|
||||
|
||||
}
|
||||
|
||||
double *EtaVEL::getSizeMap(){
|
||||
double tlX,tlY,trX,trY,blX,blY,brX,brY;
|
||||
double *szMap = new double[nPixels*nPixels+1];
|
||||
for(int x = 1; x < nPixels-1; x++)
|
||||
for(int y = 1; y < nPixels-1; y++){
|
||||
double *c = getPixelCorners(x,y);
|
||||
tlX = c[0]; trX = c[1]; brX = c[2]; blX = c[3];
|
||||
tlY = c[4]; trY = c[5]; brY = c[6]; blY = c[7];
|
||||
|
||||
//double area = dtl * dtr / 2. + dtr * dbr / 2. + dbr * dbl / 2. + dbl * dtl / 2.;
|
||||
|
||||
//http://en.wikipedia.org/wiki/Shoelace_formula
|
||||
double sl1 = tlX * trY + trX * brY + brX * blY + blX * tlY;
|
||||
double sl2 = tlY * trX + trY * brX + brY * blX + blY * tlX;
|
||||
double area = 1./2. * (- sl1 + sl2);
|
||||
if(area < 0.){
|
||||
cout << "negative area: X " << x << " Y " << y << " area " << endl;
|
||||
edgeL[getEdgeX(x,y)] *= 2.;
|
||||
edgeL[getEdgeX(x,y+1)] *= 2.;
|
||||
edgeL[getEdgeY(x,y)] *= 2.;
|
||||
edgeL[getEdgeY(x+1,y)] *= 2.;
|
||||
|
||||
}
|
||||
szMap[getBin(x,y)] = area / (max - min) / (max - min) * nPixels * nPixels;
|
||||
delete[] c;
|
||||
|
||||
}
|
||||
return szMap;
|
||||
}
|
||||
|
||||
double *EtaVEL::getChangeMap(){
|
||||
double *chMap = new double[nPixels*nPixels+1];
|
||||
double avg = totCont/(double)(nPixels*nPixels);
|
||||
// TH1D *hmed=getCounts();
|
||||
// double med = Median(hmed);
|
||||
// delete hmed;
|
||||
double acc = TMath::Sqrt(avg);
|
||||
cout << "totC: " << totCont << " avg " << avg << " acc: " << acc << endl;//<< " med " << med
|
||||
double totOffAcc = 0.;
|
||||
int totInRange03s = 0;
|
||||
int totInRange07s = 0;
|
||||
int totInRange12s = 0;
|
||||
int totInRange20s = 0;
|
||||
int totInRange25s = 0;
|
||||
double dd;
|
||||
int totInBins = 0;
|
||||
|
||||
//double
|
||||
chi_sq=0;
|
||||
|
||||
int maxC = 0, maxX=-1, maxY=-1;
|
||||
double minC = 1000000000000000, minX, minY;
|
||||
|
||||
for(int x = 0; x < nPixels; x++){
|
||||
for(int y = 0; y < nPixels; y++){
|
||||
totInBins += binCont[getBin(x,y)];
|
||||
double r = (double)binCont[getBin(x,y)];
|
||||
if(r > 0. & totCont > 0.){
|
||||
dd=sqrt(r/avg);
|
||||
/**Added by Anna */
|
||||
if (dd>2.) dd=1.5;
|
||||
if (dd<0.5) dd=0.75;
|
||||
chMap[getBin(x,y)] = dd;
|
||||
/** */
|
||||
//if( chMap[getBin(x,y)] < 1.){ chMap[getBin(x,y)] = 1/1.2; }
|
||||
//if( chMap[getBin(x,y)] > 1.){ chMap[getBin(x,y)] = 1.2; }
|
||||
//if( chMap[getBin(x,y)] < 1/1.2){ chMap[getBin(x,y)] = 1/1.2; }
|
||||
//if( chMap[getBin(x,y)] > 1.2){ chMap[getBin(x,y)] = 1.2; }
|
||||
}else if(totCont > 0.){
|
||||
chMap[getBin(x,y)] =0.5; //1/1.2;
|
||||
}else{
|
||||
chMap[getBin(x,y)] = 1.;
|
||||
}
|
||||
|
||||
//if(r < avg + 2*acc && r > avg - 2*acc){ totInRange++;}// chMap[getBin(x,y)] = 1.; }
|
||||
|
||||
/** Commente away by Anna
|
||||
if(converged == 0 && r < med+20*acc){ chMap[getBin(x,y)] = 1.; }
|
||||
if(converged == 2 && r < med+20*acc && r > med-03*acc){ chMap[getBin(x,y)] = 1.; }
|
||||
if(r < med+03*acc){ totInRange03s++; }
|
||||
if(r < med+07*acc){ totInRange07s++; }
|
||||
if(r < med+12*acc){ totInRange12s++; }
|
||||
if(r < med+20*acc){ totInRange20s++; }
|
||||
if(r < med+25*acc){ totInRange25s++; }
|
||||
*/
|
||||
|
||||
//cout << "x " << x << " y " << y << " r " << r << " ch " << chMap[getBin(x,y)] << endl;
|
||||
// if(r - avg > acc){ totOffAcc += r-avg;}
|
||||
//if(r - avg < -acc){ totOffAcc += avg-r;}
|
||||
totOffAcc += (avg-r)*(avg-r);
|
||||
chi_sq+=(avg-r)*(avg-r)/r;
|
||||
//cout << " x " << x << " y " << y << " bC " << binCont[x*nPixels+y] << " r " << r << endl;
|
||||
|
||||
if(r > maxC){ maxC = r; maxX = x; maxY = y; }
|
||||
if(r < minC){minC = r; minX = x; minY = y; }
|
||||
|
||||
}
|
||||
}
|
||||
// cout << "totInBins " << totInBins << " zero Bin " << binCont[0] << endl;
|
||||
cout << "AvgOffAcc: " << sqrt(totOffAcc/(double)(nPixels*nPixels)) << endl;
|
||||
cout << "***********Reduced Chi Square: " << chi_sq/((double)(nPixels*nPixels)) << endl;
|
||||
// cout << "totInRange03 (<" << med+03*acc << "): " << totInRange03s << endl;
|
||||
// cout << "totInRange07 (<" << med+07*acc << "): " << totInRange07s << endl;
|
||||
// cout << "totInRange12 (<" << med+12*acc << "): " << totInRange12s << endl;
|
||||
// cout << "totInRange20 (<" << med+20*acc << "): " << totInRange20s << endl;
|
||||
// cout << "totInRange25 (<" << med+25*acc << "): " << totInRange25s << endl;
|
||||
double maxSig = (maxC - avg)*(maxC - avg) / avg;//acc;
|
||||
double minSig = (avg - minC)*(avg - minC) / avg;//acc;
|
||||
cout << "Max Pixel X: " << maxX << " Y: " << maxY << " P# " << getBin(maxX,maxY) << " count: " << maxC << " sig: "<< maxSig << endl;
|
||||
cout << "Min Pixel X: " << minX << " Y: " << minY << " P# " << getBin(minX,minY) << " count: " << minC << " sig: "<< minSig << endl;
|
||||
|
||||
// if(maxSig <= 25){ converged = 2; cout << "reached first converstion step!!!" << endl; }
|
||||
//if(minSig <= 7 && converged == 2) { converged = 1; }
|
||||
if (chi_sq<3) converged=2;
|
||||
if (chi_sq<1) converged=1;
|
||||
cout << "Conversion step "<< converged << endl;
|
||||
return chMap;
|
||||
}
|
||||
|
||||
TH2D *EtaVEL::getContent(int it, int changeType){
|
||||
TH2D *cont = new TH2D("cont","cont",nPixels,min,max,nPixels,min,max);
|
||||
double *chMap = NULL;
|
||||
if(changeType ==1) chMap = getChangeMap();
|
||||
double *szMap = getSizeMap();
|
||||
for(int x = 0; x < nPixels; x++)
|
||||
for(int y = 0; y < nPixels; y++){
|
||||
if(changeType ==2 ){
|
||||
cont->SetBinContent(x+1,y+1,szMap[getBin(x,y)]);
|
||||
}
|
||||
if(changeType ==1 ){
|
||||
cont->SetBinContent(x+1,y+1,chMap[getBin(x,y)]);
|
||||
}
|
||||
if(changeType ==0 ){
|
||||
if(it == -1){
|
||||
cont->SetBinContent(x+1,y+1,binCont[getBin(x,y)]);
|
||||
//cout << "x " << x << " y " << y << " cont " << binCont[getBin(x,y)] << endl;
|
||||
}
|
||||
else{cont->SetBinContent(x+1,y+1,log[it].binCont[getBin(x,y)]);}
|
||||
}
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
|
||||
TH1D *EtaVEL::getCounts(){
|
||||
TH1D *ch = new TH1D("ch","ch",500,0,totCont/(nPixels*nPixels)*4);
|
||||
for(int x = 0; x < nPixels; x++)
|
||||
for(int y = 0; y < nPixels; y++){
|
||||
ch->Fill(binCont[getBin(x,y)]);
|
||||
}
|
||||
return ch;
|
||||
|
||||
}
|
||||
|
||||
void EtaVEL::printGrid(){
|
||||
|
||||
double *colSum = new double[nPixels+1];
|
||||
double *rowSum = new double[nPixels+1];
|
||||
|
||||
for(int i = 0; i < nPixels+1; i++){
|
||||
colSum[i] = 0.;
|
||||
rowSum[i] = 0.;
|
||||
for(int j = 0; j < nPixels; j++){
|
||||
rowSum[i] += edgeL[getEdgeX(j,i)];
|
||||
colSum[i] += edgeL[getEdgeY(i,j)];
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
||||
cout.precision(3); cout << fixed;
|
||||
cout << " ";
|
||||
for(int x = 0; x < nPixels+1; x++){
|
||||
cout << setw(2) << x << " (" << colSum[x] << ") ";
|
||||
}
|
||||
cout << endl;
|
||||
for(int y = 0; y < nPixels+1; y++){
|
||||
cout << setw(2) << y << " ";
|
||||
for(int x = 0; x < nPixels+1; x++){
|
||||
cout << "(" << xPPos[getCorner(x,y)] << "/" << yPPos[getCorner(x,y)] << ") " ;
|
||||
if(x < nPixels) cout << " -- " << edgeL[getEdgeX(x,y)]/rowSum[y]*(max-min) << " -- ";
|
||||
}
|
||||
cout << " | " << rowSum[y] << endl;
|
||||
|
||||
if(y < nPixels){
|
||||
cout << " ";
|
||||
for(int x = 0; x < nPixels+1; x++){
|
||||
cout << edgeL[getEdgeY(x,y)]/colSum[x]*(max-min) << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
}
|
||||
delete[] colSum;
|
||||
delete[] rowSum;
|
||||
|
||||
}
|
||||
|
||||
TMultiGraph *EtaVEL::plotPixelBorder(int plotCenters){
|
||||
TMultiGraph *mg = new TMultiGraph();
|
||||
double cx[5], cy[5];
|
||||
for(int x = 0; x < nPixels; x++)
|
||||
for(int y = 0; y < nPixels; y++){
|
||||
double *c = getPixelCorners(x,y);
|
||||
cx[0]=c[0]; cx[1]=c[1]; cx[2]=c[2]; cx[3]=c[3]; cx[4]=c[0];
|
||||
cy[0]=c[4]; cy[1]=c[5]; cy[2]=c[6]; cy[3]=c[7]; cy[4]=c[4];
|
||||
|
||||
|
||||
TGraph *g = new TGraph(5,cx,cy);
|
||||
mg->Add(g);
|
||||
if(plotCenters){
|
||||
g = new TGraph(1,&(xPPos[getBin(x,y)]),&(yPPos[getBin(x,y)]));
|
||||
mg->Add(g);
|
||||
}
|
||||
delete[] c;
|
||||
}
|
||||
return mg;
|
||||
}
|
||||
|
||||
TMultiGraph *EtaVEL::plotLog(int stepSize, int maxIt){
|
||||
int mIt;
|
||||
TMultiGraph *mg = new TMultiGraph();
|
||||
double **xposl = new double*[nPixels*nPixels+1];
|
||||
double **yposl = new double*[nPixels*nPixels+1];
|
||||
if(maxIt==-1){ mIt = it; } else{ mIt = maxIt; };
|
||||
cout << "mIt " << mIt << " steps " << mIt/stepSize << endl;
|
||||
for(int x = 0; x < nPixels; x++){
|
||||
for(int y = 0; y < nPixels; y++){
|
||||
xposl[getBin(x,y)] = new double[mIt/stepSize];
|
||||
yposl[getBin(x,y)] = new double[mIt/stepSize];
|
||||
for(int i = 0; i < mIt/stepSize; i++){
|
||||
xposl[getBin(x,y)][i] = log[i*stepSize].xPos[getBin(x,y)];
|
||||
yposl[getBin(x,y)][i] = log[i*stepSize].yPos[getBin(x,y)];
|
||||
}
|
||||
TGraph *g = new TGraph(mIt/stepSize,xposl[getBin(x,y)],yposl[getBin(x,y)]);
|
||||
g->SetLineColor((x*y % 9) + 1);
|
||||
|
||||
if(x == 0) g->SetLineColor(2);
|
||||
if(y == 0) g->SetLineColor(3);
|
||||
if(x == nPixels-1) g->SetLineColor(4);
|
||||
if(y == nPixels-1) g->SetLineColor(5);
|
||||
mg->Add(g);
|
||||
}
|
||||
}
|
||||
return mg;
|
||||
}
|
||||
|
||||
void EtaVEL::serialize(ostream &o){
|
||||
// b.WriteVersion(EtaVEL::IsA());
|
||||
char del = '|';
|
||||
o << min << del;
|
||||
o << max << del;
|
||||
o << ds << del;
|
||||
o << nPixels << del;
|
||||
o << it << del;
|
||||
o << totCont << del;
|
||||
for(int i = 0; i < (nPixels+1)*(nPixels+1)+1; i++){
|
||||
o << xPPos[i] << del;
|
||||
o << yPPos[i] << del;
|
||||
}
|
||||
for(int i = 0; i < nPixels*nPixels+1; i++){
|
||||
o << binCont[i] << del;
|
||||
}
|
||||
|
||||
for(int i = 0; i < it; i++){
|
||||
o << log[i].itN << del;
|
||||
for(int j = 0; j < (nPixels+1)*(nPixels+1)+1; j++){
|
||||
o << log[i].xPos[j] << del;
|
||||
o << log[i].yPos[j] << del;
|
||||
}
|
||||
for(int j = 0; j < nPixels*nPixels+1; j++){
|
||||
o << log[i].binCont[j] << del;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EtaVEL::deserialize(istream &is){
|
||||
delete[] xPPos;
|
||||
delete[] yPPos;
|
||||
delete[] binCont;
|
||||
|
||||
char del;
|
||||
|
||||
is >> min >> del;
|
||||
is >> max >> del;
|
||||
is >> ds >> del;
|
||||
is >> nPixels >> del;
|
||||
is >> it >> del;
|
||||
is >> totCont >> del;
|
||||
|
||||
xPPos = new double[(nPixels+1)*(nPixels+1)+1];
|
||||
yPPos = new double[(nPixels+1)*(nPixels+1)+1];
|
||||
binCont = new double[nPixels*nPixels+1];
|
||||
|
||||
cout << "d";
|
||||
|
||||
for(int i = 0; i < (nPixels+1)*(nPixels+1)+1; i++){
|
||||
is >> xPPos[i] >> del;
|
||||
is >> yPPos[i] >> del;
|
||||
}
|
||||
|
||||
cout << "d";
|
||||
|
||||
for(int i = 0; i < nPixels*nPixels+1; i++){
|
||||
is >> binCont[i] >> del;
|
||||
}
|
||||
|
||||
cout << "d";
|
||||
|
||||
for(int i = 0; i < it; i++){
|
||||
is >> log[i].itN >> del;
|
||||
log[i].xPos = new double[(nPixels+1)*(nPixels+1)+1];
|
||||
log[i].yPos = new double[(nPixels+1)*(nPixels+1)+1];
|
||||
log[i].binCont = new double[nPixels*nPixels+1];
|
||||
|
||||
for(int j = 0; j < (nPixels+1)*(nPixels+1)+1; j++){
|
||||
is >> log[i].xPos[j] >> del;
|
||||
is >> log[i].yPos[j] >> del;
|
||||
}
|
||||
for(int j = 0; j < nPixels*nPixels+1; j++){
|
||||
is >> log[i].binCont[j] >> del;
|
||||
}
|
||||
cout << "d";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void EtaVEL::Streamer(TBuffer &b){
|
||||
if (b.IsReading()) {
|
||||
Version_t v = b.ReadVersion();
|
||||
|
||||
delete[] xPPos;
|
||||
delete[] yPPos;
|
||||
delete[] binCont;
|
||||
|
||||
b >> min;
|
||||
b >> max;
|
||||
b >> ds;
|
||||
b >> nPixels;
|
||||
b >> it;
|
||||
b >> totCont;
|
||||
|
||||
xPPos = new double[(nPixels+1)*(nPixels+1)+1];
|
||||
yPPos = new double[(nPixels+1)*(nPixels+1)+1];
|
||||
binCont = new double[nPixels*nPixels+1];
|
||||
|
||||
for(int i = 0; i < (nPixels+1)*(nPixels+1)+1; i++){
|
||||
b >> xPPos[i];
|
||||
b >> yPPos[i];
|
||||
}
|
||||
for(int i = 0; i < nPixels*nPixels+1; i++){
|
||||
b >> binCont[i];
|
||||
}
|
||||
|
||||
for(int i = 0; i < it; i++){
|
||||
b >> log[i].itN;
|
||||
log[i].xPos = new double[(nPixels+1)*(nPixels+1)+1];
|
||||
log[i].yPos = new double[(nPixels+1)*(nPixels+1)+1];
|
||||
log[i].binCont = new double[nPixels*nPixels+1];
|
||||
|
||||
for(int j = 0; j < (nPixels+1)*(nPixels+1)+1; j++){
|
||||
b >> log[i].xPos[j];
|
||||
b >> log[i].yPos[j];
|
||||
}
|
||||
for(int j = 0; j < nPixels*nPixels+1; j++){
|
||||
b >> log[i].binCont[j];
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
b.WriteVersion(EtaVEL::IsA());
|
||||
b << min;
|
||||
b << max;
|
||||
b << ds;
|
||||
b << nPixels;
|
||||
b << it;
|
||||
b << totCont;
|
||||
for(int i = 0; i < (nPixels+1)*(nPixels+1)+1; i++){
|
||||
b << xPPos[i];
|
||||
b << yPPos[i];
|
||||
}
|
||||
for(int i = 0; i < nPixels*nPixels+1; i++){
|
||||
b << binCont[i];
|
||||
}
|
||||
|
||||
for(int i = 0; i < it; i++){
|
||||
b << log[i].itN;
|
||||
for(int j = 0; j < (nPixels+1)*(nPixels+1)+1; j++){
|
||||
b << log[i].xPos[j];
|
||||
b << log[i].yPos[j];
|
||||
}
|
||||
for(int j = 0; j < nPixels*nPixels+1; j++){
|
||||
b << log[i].binCont[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
164
slsDetectorCalibration/interpolations/etaVEL/EtaVEL.h
Normal file
164
slsDetectorCalibration/interpolations/etaVEL/EtaVEL.h
Normal file
@ -0,0 +1,164 @@
|
||||
#include <iostream>
|
||||
#include <TGraph.h>
|
||||
#include <TAxis.h>
|
||||
#include <TMultiGraph.h>
|
||||
#include <TH2D.h>
|
||||
#include <TMath.h>
|
||||
#include <TObject.h>
|
||||
#include <TBuffer.h>
|
||||
|
||||
#include <TMatrixD.h>
|
||||
|
||||
#include <TDecompSVD.h>
|
||||
//#include <TDecompQRH.h>
|
||||
|
||||
|
||||
#include <TH1.h>
|
||||
#include <TMath.h>
|
||||
#include <vector>
|
||||
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef ETAVPS
|
||||
#define ETAVPS
|
||||
|
||||
typedef struct {
|
||||
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;
|
||||
|
||||
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 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];
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 getIt(){ return it; };
|
||||
|
||||
int getNPixels(){ return nPixels; }
|
||||
double *getXPPos(){ return xPPos; }
|
||||
double *getYPPos(){ return yPPos; }
|
||||
|
||||
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();
|
||||
|
||||
void serialize(ostream &o);
|
||||
void deserialize(istream &is);
|
||||
|
||||
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-;
|
||||
};
|
||||
|
||||
#endif
|
393
slsDetectorCalibration/interpolations/etaVEL/EtaVELTr.py
Normal file
393
slsDetectorCalibration/interpolations/etaVEL/EtaVELTr.py
Normal file
@ -0,0 +1,393 @@
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
maxf = 2
|
||||
minf = 0.5
|
||||
|
||||
class EtaVELTr:
|
||||
def __init__(self, numberOfPixels = 25, minn=0., maxx=1.):
|
||||
self.nPixels = numberOfPixels
|
||||
self.nCorners = self.nPixels + 1
|
||||
self.minEta = minn
|
||||
self.maxEta = maxx
|
||||
#self.corners = []
|
||||
self.edgesX = []
|
||||
self.edgesY = []
|
||||
self.edgesE = []
|
||||
self.edgesF = []
|
||||
self.edgesG = []
|
||||
self.edgesH = []
|
||||
self.counts = []
|
||||
self.pOffset = (self.maxEta-self.minEta)/self.nPixels
|
||||
|
||||
self.cPosX = []
|
||||
self.cPosY = []
|
||||
self.zPosX = []
|
||||
self.zPosY = []
|
||||
|
||||
self.sqSums = []
|
||||
self.cIteration = 0
|
||||
self.bSqSum = 0
|
||||
|
||||
self.initGrid()
|
||||
#self.calculatePixelCorners()
|
||||
self.update()
|
||||
|
||||
def initGrid(self):
|
||||
dd = 1 / math.sqrt(2)
|
||||
|
||||
#self.corners = [ [self.minEta + x * pOffset, self.minEta + y * pOffset] for y in range(self.nPixels)] for x in range(self.nPixels)
|
||||
self.cPosX = [ [self.minEta + x * self.pOffset for x in range(self.nCorners)] for y in range(self.nCorners) ]
|
||||
self.cPosY = [ [self.minEta + y * self.pOffset for x in range(self.nCorners)] for y in range(self.nCorners) ]
|
||||
self.counts = [ [ [0,0,0,0] for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
self.edgesX = [ [ 1 for x in range(self.nCorners) ] for y in range(self.nCorners + 1) ]
|
||||
self.edgesY = [ [ 1 for x in range(self.nCorners+1) ] for y in range(self.nCorners) ]
|
||||
self.edgesE = [ [ dd for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
self.edgesF = [ [ dd for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
self.edgesG = [ [ dd for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
self.edgesH = [ [ dd for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
|
||||
|
||||
|
||||
def update(self):
|
||||
self.normalizeEdgeLengths()
|
||||
self.calculateEdgeLengths2()
|
||||
self.calculatePixelCorners2()
|
||||
conv = False
|
||||
out = 0
|
||||
outList = []
|
||||
tot = self.nPixels*self.nPixels*4
|
||||
sqSum = 0
|
||||
avg = self.getAvgCounts()
|
||||
avgPS = self.getAvgCounts() + 1*math.sqrt(self.getAvgCounts())
|
||||
avgMS = self.getAvgCounts() - 1*math.sqrt(self.getAvgCounts())
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
for t in range(4):
|
||||
sqSum += (avg -self.counts[y][x][t]) * (avg -self.counts[y][x][t])
|
||||
if self.counts[y][x][t] > avgPS or self.counts[y][x][t] < avgMS:
|
||||
|
||||
out += 1
|
||||
outList.append([y,x,t,self.counts[y][x][t]])
|
||||
|
||||
outList = sorted(outList,key=lambda t: abs(self.counts[t[0]][t[1]][t[2]]/self.getAvgCounts()))
|
||||
self.counts = [ [ [0,0,0,0] for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
print("There are {} of {} triangles out of 1 std ({} %)".format(out,tot,out/tot*100))
|
||||
print("Total Sq Err: {}".format(sqSum))
|
||||
|
||||
self.sqSums.append(sqSum)
|
||||
|
||||
if len(self.sqSums) > 2 and np.diff(self.sqSums)[-1] > 0:
|
||||
print("converged after {} steps: sqSums {} diff(sqSums) {}".format(self.cIteration,self.sqSums,np.diff(self.sqSums)))
|
||||
conv = True
|
||||
self.bSqSum = self.sqSums[-2]
|
||||
|
||||
self.cIteration += 1
|
||||
return [conv,outList,sqSum]
|
||||
|
||||
def normalizeEdgeLengths(self):
|
||||
sumL = 0
|
||||
sumL += sum(map(sum,zip(*self.edgesX)))
|
||||
sumL += sum(map(sum,zip(*self.edgesY)))
|
||||
sumL += sum(map(sum,zip(*self.edgesE)))
|
||||
sumL += sum(map(sum,zip(*self.edgesF)))
|
||||
sumL += sum(map(sum,zip(*self.edgesG)))
|
||||
sumL += sum(map(sum,zip(*self.edgesH)))
|
||||
avgL = sumL/(4*self.nPixels*self.nPixels+2*self.nCorners*(self.nCorners+1))
|
||||
print("total Sum is {} avg: {}".format(sumL,avgL))
|
||||
self.edgesX = [ [ x/avgL for x in y ] for y in self.edgesX ]
|
||||
self.edgesY = [ [ x/avgL for x in y ] for y in self.edgesY ]
|
||||
self.edgesE = [ [ x/avgL for x in y ] for y in self.edgesE ]
|
||||
self.edgesF = [ [ x/avgL for x in y ] for y in self.edgesF ]
|
||||
self.edgesG = [ [ x/avgL for x in y ] for y in self.edgesG ]
|
||||
self.edgesH = [ [ x/avgL for x in y ] for y in self.edgesH ]
|
||||
|
||||
def _shapeF(self,f):
|
||||
f = (f - 1) * 0.6 + 1
|
||||
if f > maxf:
|
||||
return maxf
|
||||
if f < minf:
|
||||
return minf
|
||||
return f
|
||||
|
||||
def calculateEdgeLengths2(self):
|
||||
if self.getTotalCounts() == 0:
|
||||
return
|
||||
avg = self.getAvgCounts()
|
||||
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
for t in range(4):
|
||||
pc = self.counts[y][x][t]
|
||||
if pc == 0:
|
||||
f = maxf
|
||||
else:
|
||||
f = math.sqrt(avg/pc)
|
||||
if pc > avg-math.sqrt(avg) and pc < avg+math.sqrt(avg):
|
||||
f = 1.
|
||||
sf = self._shapeF(f)
|
||||
if t == 0:
|
||||
self.edgesX[y][x] = self.edgesX[y][x] / sf
|
||||
self.edgesE[y][x] = self.edgesE[y][x] / sf
|
||||
self.edgesF[y][x] = self.edgesF[y][x] / sf
|
||||
if t == 1:
|
||||
self.edgesY[y][x+1] = self.edgesY[y][x+1] / sf
|
||||
self.edgesF[y][x] = self.edgesF[y][x] / sf
|
||||
self.edgesH[y][x] = self.edgesH[y][x] / sf
|
||||
if t == 2:
|
||||
self.edgesX[y+1][x] = self.edgesX[y+1][x] / sf
|
||||
self.edgesH[y][x] = self.edgesH[y][x] / sf
|
||||
self.edgesG[y][x] = self.edgesG[y][x] / sf
|
||||
if t == 3:
|
||||
self.edgesY[y][x] = self.edgesY[y][x] / sf
|
||||
self.edgesG[y][x] = self.edgesG[y][x] / sf
|
||||
self.edgesE[y][x] = self.edgesE[y][x] / sf
|
||||
|
||||
|
||||
def calculatePixelCorners2(self):
|
||||
w = 20
|
||||
posMat = []
|
||||
CrVx = np.zeros((self.nCorners,self.nCorners))
|
||||
CrVy = np.zeros((self.nCorners,self.nCorners))
|
||||
ZrVx = np.zeros((self.nPixels,self.nPixels))
|
||||
ZrVy = np.zeros((self.nPixels,self.nPixels))
|
||||
|
||||
#boundary conditions matrix/vectors
|
||||
BCposMatX = []
|
||||
BCposMatY = []
|
||||
BCrVx = []
|
||||
BCrVy = []
|
||||
|
||||
for y in range(self.nCorners):
|
||||
for x in range(self.nCorners):
|
||||
BClineX = np.zeros((self.nCorners,self.nCorners))
|
||||
BClineY = np.zeros((self.nCorners,self.nCorners))
|
||||
if (x == 0 and y == 0) or \
|
||||
(x == 0 and y == self.nPixels) or \
|
||||
(x == self.nPixels and y == 0) or \
|
||||
(x == self.nPixels and y == self.nPixels):
|
||||
BClineX[y][x] = w
|
||||
BClineY[y][x] = w
|
||||
BCrVx.append(self.getCornerPos(y,x)[0] * w)
|
||||
BCrVy.append(self.getCornerPos(y,x)[1] * w)
|
||||
#print("bclinex shape {} zeros shape {}".format( BClineX.reshape((self.nCorners*self.nCorners,)).shape , np.zeros((self.nPixels*self.nPixels)).shape ))
|
||||
BCposMatX.append(np.hstack((BClineX.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
BCposMatY.append(np.hstack((BClineY.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
|
||||
elif x == 0 or x == self.nPixels:
|
||||
BClineX[y][x] = w
|
||||
#BClineY[y][x] = 1
|
||||
BCrVx.append(self.getCornerPos(y,x)[0] * w)
|
||||
#BCrVy.append(self.getCornerPos(y,x)[1])
|
||||
BCposMatX.append(np.hstack((BClineX.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
#BCposMatY.append(np.hstack((BClineY.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
elif y == 0 or y == self.nPixels:
|
||||
#BClineX[y][x] = 1
|
||||
BClineY[y][x] = w
|
||||
#BCrVx.append(self.getCornerPos(y,x)[0])
|
||||
BCrVy.append(self.getCornerPos(y,x)[1] * w)
|
||||
#BCposMatX.append(np.hstack((BClineX.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
BCposMatY.append(np.hstack((BClineY.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
|
||||
|
||||
eLength = 0
|
||||
|
||||
if x != 0:
|
||||
eLength += self.edgesX[y][x-1]
|
||||
if y != 0:
|
||||
eLength += self.edgesY[y-1][x]
|
||||
if x != self.nPixels:
|
||||
eLength += self.edgesX[y][x]
|
||||
if y != self.nPixels:
|
||||
eLength += self.edgesY[y][x]
|
||||
|
||||
if y != 0 and x != 0:
|
||||
eLength += self.edgesH[y-1][x-1]
|
||||
if y != self.nPixels and x != 0:
|
||||
eLength += self.edgesF[y][x-1]
|
||||
if y != 0 and x != self.nPixels:
|
||||
eLength += self.edgesG[y-1][x]
|
||||
if y != self.nPixels and x != self.nPixels:
|
||||
eLength += self.edgesE[y][x]
|
||||
|
||||
line = np.zeros((self.nCorners,self.nCorners))
|
||||
lineZ = np.zeros((self.nPixels,self.nPixels))
|
||||
|
||||
|
||||
if x != 0:
|
||||
line[y][x-1] = - self.edgesX[y][x-1]/eLength
|
||||
if y != 0:
|
||||
line[y-1][x] = - self.edgesY[y-1][x]/eLength
|
||||
if x != self.nPixels:
|
||||
line[y][x+1] = - self.edgesX[y][x]/eLength
|
||||
if y != self.nPixels:
|
||||
line[y+1][x] = - self.edgesY[y][x]/eLength
|
||||
|
||||
if y != 0 and x != 0:
|
||||
lineZ[y-1][x-1] = -self.edgesH[y-1][x-1]/eLength
|
||||
if y != self.nPixels and x != 0:
|
||||
lineZ[y][x-1] = -self.edgesF[y][x-1]/eLength
|
||||
if y != 0 and x != self.nPixels:
|
||||
lineZ[y-1][x] = -self.edgesG[y-1][x]/eLength
|
||||
if y != self.nPixels and x != self.nPixels:
|
||||
lineZ[y][x] = -self.edgesE[y][x]/eLength
|
||||
|
||||
|
||||
line[y][x] = 1
|
||||
CrVx[y][x] = 0
|
||||
CrVy[y][x] = 0
|
||||
posMat.append( \
|
||||
np.hstack(( \
|
||||
line.reshape((self.nCorners*self.nCorners,)), \
|
||||
lineZ.reshape((self.nPixels*self.nPixels,)) \
|
||||
)) \
|
||||
)
|
||||
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
line = np.zeros((self.nCorners,self.nCorners))
|
||||
lineZ = np.zeros((self.nPixels,self.nPixels))
|
||||
|
||||
eLength = self.edgesE[y][x] + self.edgesF[y][x] +self.edgesG[y][x] +self.edgesH[y][x]
|
||||
line[y][x] = -self.edgesE[y][x] / eLength
|
||||
line[y][x+1] = -self.edgesF[y][x] / eLength
|
||||
line[y+1][x] = -self.edgesG[y][x] / eLength
|
||||
line[y+1][x+1] = -self.edgesH[y][x] / eLength
|
||||
|
||||
lineZ[y][x] = 1
|
||||
ZrVx[y][x] = 0
|
||||
ZrVy[y][x] = 0
|
||||
posMat.append( \
|
||||
np.hstack(( \
|
||||
line.reshape((self.nCorners*self.nCorners,)), \
|
||||
lineZ.reshape((self.nPixels*self.nPixels,)) \
|
||||
)) \
|
||||
)
|
||||
|
||||
CrVxFlat = CrVx.reshape((self.nCorners*self.nCorners,))
|
||||
CrVyFlat = CrVy.reshape((self.nCorners*self.nCorners,))
|
||||
ZrVxFlat = ZrVx.reshape((self.nPixels*self.nPixels,))
|
||||
ZrVyFlat = ZrVy.reshape((self.nPixels*self.nPixels,))
|
||||
posMat = np.asarray(posMat)
|
||||
|
||||
BCrVyFlat = np.asarray(BCrVy)
|
||||
BCrVxFlat = np.asarray(BCrVx)
|
||||
BCposMatX = np.asarray(BCposMatX)
|
||||
BCposMatY = np.asarray(BCposMatY)
|
||||
|
||||
print ("BCposMatY vy {} shape posMat {}".format(BCposMatY.shape,posMat.shape))
|
||||
|
||||
FinalrVy = np.hstack((CrVyFlat,ZrVyFlat,BCrVyFlat))
|
||||
FinalrVx = np.hstack((CrVxFlat,ZrVxFlat,BCrVxFlat))
|
||||
FinalposMatX = np.vstack((posMat,BCposMatX))
|
||||
FinalposMatY = np.vstack((posMat,BCposMatY))
|
||||
|
||||
print("posMat shape {}".format(posMat.shape))
|
||||
print("posMatX shape {}".format(FinalposMatX.shape))
|
||||
print("rVxFlat shape {}".format(FinalrVx.shape))
|
||||
|
||||
#print("posMat {}".format(FinalposMat))
|
||||
#print("rVxFlat {}".format(FinalrVx))
|
||||
|
||||
xPos = np.linalg.lstsq(FinalposMatX,FinalrVx)[0]
|
||||
yPos = np.linalg.lstsq(FinalposMatY,FinalrVy)[0]
|
||||
|
||||
print("xPosShape {} cutXPosShape {}".format(xPos.shape,xPos[:self.nCorners][:self.nCorners].shape))
|
||||
|
||||
self.cPosX = xPos[:self.nCorners*self.nCorners].reshape((self.nCorners,self.nCorners))
|
||||
self.cPosY = yPos[:self.nCorners*self.nCorners].reshape((self.nCorners,self.nCorners))
|
||||
|
||||
self.zPosX = xPos[self.nCorners*self.nCorners:].reshape((self.nPixels,self.nPixels))
|
||||
self.zPosY = yPos[self.nCorners*self.nCorners:].reshape((self.nPixels,self.nPixels))
|
||||
|
||||
|
||||
|
||||
def fill(self,yy,xx,count = 1):
|
||||
[y,x,t] = self.getPixel(yy,xx)
|
||||
self.counts[y][x][t] += count
|
||||
|
||||
def getCountDist(self):
|
||||
c = []
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
c.append(self.counts[y][x])
|
||||
return c
|
||||
|
||||
def getPixel(self,yy,xx, debug = False):
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
for t in range(4):
|
||||
[v1x,v1y,v2x,v2y,v3x,v3y] = self.getTriangleCorner(y,x,t)
|
||||
if self.pointInTriangle([xx,yy],[v1x,v1y],[v2x,v2y],[v3x,v3y]):
|
||||
return [y,x,t]
|
||||
|
||||
if not debug:
|
||||
raise Exception("not inside a pixel")
|
||||
else:
|
||||
print("no pixel found")
|
||||
return [0,0]
|
||||
|
||||
#http://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-2d-triangle
|
||||
def trSign (self, p1, p2, p3):
|
||||
return (p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1]);
|
||||
|
||||
def pointInTriangle (self,pt, v1, v2, v3):
|
||||
b1 = self.trSign(pt, v1, v2) < 0.0
|
||||
b2 = self.trSign(pt, v2, v3) < 0.0
|
||||
b3 = self.trSign(pt, v3, v1) < 0.0
|
||||
return ((b1 == b2) and (b2 == b3));
|
||||
|
||||
def getAvgCounts(self):
|
||||
return self.getTotalCounts() / self.nPixels/self.nPixels/4.
|
||||
|
||||
def getTotalCounts(self):
|
||||
tot = 0
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
for t in range(4):
|
||||
tot += self.counts[y][x][t]
|
||||
return tot
|
||||
|
||||
#tl tr bl br
|
||||
def getPixelCorners(self,iy,ix):
|
||||
return self.getCornerPos(iy,ix) + self.getCornerPos(iy,ix+1) + self.getCornerPos(iy+1,ix) + self.getCornerPos(iy+1,ix+1)
|
||||
|
||||
def getTriangleCorner(self,iy,ix,tr):
|
||||
if tr == 0:
|
||||
return self.getCornerPos(iy,ix) + self.getCornerPos(iy,ix+1) + [self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
if tr == 1:
|
||||
return self.getCornerPos(iy,ix+1) + self.getCornerPos(iy+1,ix+1) + [self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
if tr == 2:
|
||||
return self.getCornerPos(iy+1,ix+1) + self.getCornerPos(iy+1,ix) + [self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
if tr == 3:
|
||||
return self.getCornerPos(iy+1,ix) + self.getCornerPos(iy,ix) + [self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
||||
def getCornerPos(self,iy,ix):
|
||||
return [self.cPosX[iy][ix],self.cPosY[iy][ix]]
|
||||
|
||||
def getXEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy,ix)
|
||||
p2 = self.getCornerPos(iy,ix+1)
|
||||
return [p1[0],p1[1],p2[0],p2[1]]
|
||||
|
||||
def getYEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy,ix)
|
||||
p2 = self.getCornerPos(iy+1,ix)
|
||||
return [p1[0],p1[1],p2[0],p2[1]]
|
||||
|
||||
def getEEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy,ix)
|
||||
return [p1[0],p1[1],self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
||||
def getFEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy,ix+1)
|
||||
return [p1[0],p1[1],self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
||||
def getGEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy+1,ix)
|
||||
return [p1[0],p1[1],self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
||||
def getHEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy+1,ix+1)
|
||||
return [p1[0],p1[1],self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
@ -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++<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 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; 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();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
52
slsDetectorCalibration/interpolations/interpolation_EtaVEL.h
Normal file
52
slsDetectorCalibration/interpolations/interpolation_EtaVEL.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef INTERPOLATION_ETAVEL_H
|
||||
#define INTERPOLATION_ETAVEL_H
|
||||
|
||||
#include <slsInterpolation.h>
|
||||
#include "EtaVEL.h"
|
||||
#include "TH2F.h"
|
||||
//#include "EtaVEL.cpp"
|
||||
//class EtaVEL;
|
||||
|
||||
class interpolation_EtaVEL: public slsInterpolation {
|
||||
|
||||
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
|
172
slsDetectorCalibration/interpolations/linearInterpolation.h
Normal file
172
slsDetectorCalibration/interpolations/linearInterpolation.h
Normal file
@ -0,0 +1,172 @@
|
||||
#ifndef LINEAR_INTERPOLATION_H
|
||||
#define LINEAR_INTERPOLATION_H
|
||||
|
||||
//#include <TObject.h>
|
||||
//#include <TTree.h>
|
||||
//#include <TH2F.h>
|
||||
|
||||
#include "slsInterpolation.h"
|
||||
|
||||
class linearInterpolation : public slsInterpolation{
|
||||
|
||||
public:
|
||||
linearInterpolation(int nx=400, int ny=400, int ns=25) : slsInterpolation(nx,ny,ns) {};
|
||||
linearInterpolation(linearInterpolation *orig) : slsInterpolation(orig) {};
|
||||
|
||||
virtual void prepareInterpolation(int &ok){ok=1;};
|
||||
|
||||
virtual linearInterpolation* Clone() {
|
||||
|
||||
return new linearInterpolation(this);
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////// /*It return position hit for the event in input */ //////////////
|
||||
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
|
||||
{
|
||||
double sDum[2][2];
|
||||
double tot, totquad;
|
||||
double etax,etay;
|
||||
|
||||
int corner;
|
||||
corner=calcQuad(data, tot, totquad, sDum);
|
||||
if (ns>2) {
|
||||
calcEta(totquad, sDum, etax, etay);
|
||||
}
|
||||
getInterpolatedPosition(x, y, etax,etay, corner, int_x, int_y);
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
virtual int getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &etax, double &etay) {
|
||||
|
||||
if (ns>2) {
|
||||
double cc[2][2];
|
||||
double *cluster[3];
|
||||
cluster[0]=cl;
|
||||
cluster[1]=cl+3;
|
||||
cluster[2]=cl+6;
|
||||
|
||||
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]=cluster[yoff][xoff];
|
||||
cc[1][0]=cluster[yoff+1][xoff];
|
||||
cc[0][1]=cluster[yoff][xoff+1];
|
||||
cc[1][1]=cluster[yoff+1][xoff+1];
|
||||
double eta_x, eta_y;
|
||||
calcEta(quadTot,cc,eta_x,eta_y);
|
||||
}
|
||||
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,ypos_eta;
|
||||
double dX,dY;
|
||||
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:
|
||||
dX=0.;
|
||||
dY=0.;
|
||||
}
|
||||
|
||||
|
||||
if (ns>2) {
|
||||
xpos_eta=(etax);
|
||||
ypos_eta=(etay);
|
||||
} else {
|
||||
xpos_eta=0;
|
||||
xpos_eta=0;
|
||||
}
|
||||
int_x=((double)x) + dX + xpos_eta;
|
||||
int_y=((double)y) + dY + ypos_eta;
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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;
|
||||
|
||||
calcQuad(data, tot, totquad, sDum);
|
||||
calcEta3(data,eta3x, eta3y,tot);
|
||||
|
||||
double xpos_eta,ypos_eta;
|
||||
|
||||
xpos_eta=eta3x;
|
||||
ypos_eta=eta3y;
|
||||
|
||||
int_x=((double)x) + xpos_eta;
|
||||
int_y=((double)y) + ypos_eta;
|
||||
|
||||
return;
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual int addToFlatField(double *cluster, double &etax, double &etay){};
|
||||
virtual int addToFlatField(double etax, double etay){};
|
||||
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {};
|
||||
|
||||
protected:
|
||||
;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
72
slsDetectorCalibration/interpolations/noInterpolation.h
Normal file
72
slsDetectorCalibration/interpolations/noInterpolation.h
Normal file
@ -0,0 +1,72 @@
|
||||
#ifndef NO_INTERPOLATION_H
|
||||
#define NO_INTERPOLATION_H
|
||||
|
||||
/* #ifdef MYROOT1 */
|
||||
/* #include <TObject.h> */
|
||||
/* #include <TTree.h> */
|
||||
/* #include <TH2F.h> */
|
||||
/* #include <TROOT.h> */
|
||||
/* #include <TRandom.h> */
|
||||
/* #endif */
|
||||
|
||||
#include <cstdlib>
|
||||
#include "slsInterpolation.h"
|
||||
|
||||
|
||||
|
||||
class noInterpolation : public slsInterpolation{
|
||||
public:
|
||||
noInterpolation(int nx=400, int ny=400, int ns=25) : slsInterpolation(nx,ny,ns) {};// {eventGenerator=new TRandom();};
|
||||
noInterpolation(noInterpolation *orig) : slsInterpolation(orig){};
|
||||
virtual void prepareInterpolation(int &ok){ok=1;};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////// /*It return position hit for the event in input */ //////////////
|
||||
|
||||
virtual noInterpolation* Clone() {
|
||||
|
||||
return new noInterpolation(this);
|
||||
|
||||
};
|
||||
|
||||
|
||||
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)
|
||||
{
|
||||
//Random coordinate in the Pixel reference
|
||||
int_x = x + ((double)rand())/((double)RAND_MAX) -0.5;//eventGenerator->Uniform(-0.5,0.5);
|
||||
int_y = y + ((double)rand())/((double)RAND_MAX) -0.5;//eventGenerator->Uniform(-0.5,0.5);
|
||||
|
||||
return ;
|
||||
};
|
||||
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int corner, double &int_x, double &int_y)
|
||||
{
|
||||
getInterpolatedPosition(x, y, NULL, int_x, int_y);
|
||||
};
|
||||
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &etax, double &etay){
|
||||
getInterpolatedPosition(x, y, NULL, etax, etay);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void getPositionETA3(int x, int y, double *data, double &int_x, double &int_y)
|
||||
{
|
||||
//Random coordinate in the Pixel reference
|
||||
int_x = x + ((double)rand())/((double)RAND_MAX) -0.5;//eventGenerator->Uniform(-0.5,0.5);
|
||||
int_y = y + ((double)rand())/((double)RAND_MAX) -0.5;//eventGenerator->Uniform(-0.5,0.5);
|
||||
|
||||
return ;
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual int addToFlatField(double *cluster, double &etax, double &etay){return 0;};
|
||||
virtual int addToFlatField(double etax, double etay){return 0;};
|
||||
|
||||
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay){return 0;};
|
||||
|
||||
|
||||
protected:
|
||||
;
|
||||
// TRandom *eventGenerator;
|
||||
// ClassDefNV(slsInterpolation,1);
|
||||
// #pragma link C++ class slsInterpolation-;
|
||||
};
|
||||
|
||||
#endif
|
387
slsDetectorCalibration/interpolations/slsInterpolation.h
Normal file
387
slsDetectorCalibration/interpolations/slsInterpolation.h
Normal file
@ -0,0 +1,387 @@
|
||||
#ifndef SLS_INTERPOLATION_H
|
||||
#define SLS_INTERPOLATION_H
|
||||
|
||||
#ifdef MYROOT1
|
||||
#include <TObject.h>
|
||||
#include <TTree.h>
|
||||
#include <TH2F.h>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include "tiffIO.h"
|
||||
#ifndef DEF_QUAD
|
||||
#define DEF_QUAD
|
||||
enum quadrant {
|
||||
TOP_LEFT=0,
|
||||
TOP_RIGHT=1,
|
||||
BOTTOM_LEFT=2,
|
||||
BOTTOM_RIGHT=3,
|
||||
UNDEFINED_QUADRANT=-1
|
||||
};
|
||||
#endif
|
||||
#include <memory.h>
|
||||
|
||||
using namespace std;
|
||||
//#ifdef MYROOT1
|
||||
//: public TObject
|
||||
//#endif
|
||||
class slsInterpolation
|
||||
{
|
||||
|
||||
public:
|
||||
slsInterpolation(int nx=400, int ny=400, int ns=25) :nPixelsX(nx), nPixelsY(ny), nSubPixels(ns), id(0) {
|
||||
|
||||
#ifdef MYROOT1
|
||||
hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny);
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT1
|
||||
hint=new int[ns*nx*ns*ny];
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
slsInterpolation(slsInterpolation *orig){
|
||||
nPixelsX=orig->nPixelsX;
|
||||
nPixelsY=orig->nPixelsY;
|
||||
nSubPixels=orig->nSubPixels;
|
||||
#ifdef MYROOT1
|
||||
hint=(TH2F*)(orig->hint)->Clone("hint");
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT1
|
||||
hint=new int[nSubPixels*nPixelsX*nSubPixels*nPixelsY];
|
||||
memcpy(hint, orig->hint,nSubPixels*nPixelsX*nSubPixels*nPixelsY*sizeof(int));
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
virtual int setId(int i) {id=i; return id;};
|
||||
|
||||
virtual slsInterpolation* Clone() = 0;
|
||||
|
||||
int getNSubPixels() {return nSubPixels;};
|
||||
|
||||
int getImageSize(int &nnx, int &nny, int &ns) {
|
||||
nnx=nSubPixels*nPixelsX;
|
||||
nny=nSubPixels*nPixelsY;
|
||||
ns=nSubPixels;
|
||||
return nSubPixels*nSubPixels*nPixelsX*nPixelsY;
|
||||
};
|
||||
|
||||
|
||||
//create eta distribution, eta rebinnining etc.
|
||||
//returns flat field image
|
||||
virtual void prepareInterpolation(int &ok)=0;
|
||||
|
||||
//create interpolated image
|
||||
//returns interpolated image
|
||||
#ifdef MYROOT1
|
||||
virtual TH2F *getInterpolatedImage(){return hint;};
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT1
|
||||
virtual int *getInterpolatedImage(){return hint;};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
void *writeInterpolatedImage(const char * imgname) {
|
||||
cout << "!" <<endl;
|
||||
float *gm=NULL;
|
||||
gm=new float[ nSubPixels* nSubPixels* nPixelsX*nPixelsY];
|
||||
if (gm) {
|
||||
for (int ix=0; ix<nPixelsX*nSubPixels; ix++) {
|
||||
for (int iy=0; iy<nPixelsY*nSubPixels; iy++) {
|
||||
gm[iy*nPixelsX*nSubPixels+ix]=hint[iy*nPixelsX*nSubPixels+ix];
|
||||
}
|
||||
}
|
||||
WriteToTiff(gm, imgname,nSubPixels* nPixelsX ,nSubPixels* nPixelsY);
|
||||
delete [] gm;
|
||||
} else cout << "Could not allocate float image " << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//return position inside the pixel for the given photon
|
||||
virtual void getInterpolatedPosition(int x, int y, double *data, double &int_x, double &int_y)=0;
|
||||
//return position inside the pixel for the given photon
|
||||
virtual void getInterpolatedPosition(int x, int y, double etax, double etay, int quad, double &int_x, double &int_y)=0;
|
||||
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cluster,double &etax, double &etay)=0;
|
||||
|
||||
|
||||
//return position inside the pixel for the given photon
|
||||
virtual void clearInterpolatedImage() {
|
||||
|
||||
|
||||
#ifdef MYROOT1
|
||||
hint->Reset();
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
for (int ix=0; ix<nPixelsX*nSubPixels; ix++) {
|
||||
for (int iy=0; iy<nPixelsY*nSubPixels; iy++) {
|
||||
hint[iy*nPixelsX*nSubPixels+ix]=0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef MYROOT1
|
||||
TH2F *addToImage(double int_x, double int_y){hint->Fill(int_x, int_y); return hint;};
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT1
|
||||
virtual int *addToImage(double int_x, double int_y){ int iy=nSubPixels*int_y; int ix=nSubPixels*int_x;
|
||||
// cout << int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << endl;
|
||||
if (ix>=0 && ix<(nPixelsX*nSubPixels) && iy<(nSubPixels*nPixelsY) && iy>=0 )(*(hint+ix+iy*nPixelsX*nSubPixels))+=1;
|
||||
return hint;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
virtual int addToFlatField(double *cluster, double &etax, double &etay)=0;
|
||||
virtual int addToFlatField(double etax, double etay)=0;
|
||||
|
||||
virtual int addToFlatField(double totquad,int quad,double *cluster,double &etax, double &etay)=0;
|
||||
|
||||
#ifdef MYROOT1
|
||||
virtual TH2D *getFlatField(){return NULL;};
|
||||
virtual TH2D *setFlatField(TH2D *h, int nb=-1, double emin=-1, double emax=-1){return NULL;};
|
||||
virtual TH2D *getFlatField(int &nb, double &emin, double &emax){nb=0; emin=0; emax=0; return getFlatField();};
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT1
|
||||
virtual int *getFlatField(){return NULL;};
|
||||
virtual int *setFlatField(int *h, int nb=-1, double emin=-1, double emax=-1){return NULL;};
|
||||
void *writeFlatField(const char * imgname){return NULL;};
|
||||
void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){return NULL;};
|
||||
virtual int *getFlatField(int &nb, double &emin, double &emax){nb=0; emin=0; emax=0; return getFlatField();};
|
||||
#endif
|
||||
|
||||
//virtual void Streamer(TBuffer &b);
|
||||
|
||||
|
||||
static int calcQuad(double *cl, double &sum, double &totquad, double sDum[2][2]){
|
||||
|
||||
int corner = UNDEFINED_QUADRANT;
|
||||
double *cluster[3];
|
||||
cluster[0]=cl;
|
||||
cluster[1]=cl+3;
|
||||
cluster[2]=cl+6;
|
||||
|
||||
sum = cluster[0][0] + cluster[1][0] + cluster[2][0] + cluster[0][1] + cluster[1][1] + cluster[2][1] + cluster[0][2] + cluster[1][2] + cluster[2][2];
|
||||
|
||||
double sumBL = cluster[0][0] + cluster[1][0] + cluster[0][1] + cluster[1][1]; //2 ->BL
|
||||
double sumTL = cluster[1][0] + cluster[2][0] + cluster[2][1] + cluster[1][1]; //0 ->TL
|
||||
double sumBR = cluster[0][1] + cluster[0][2] + cluster[1][2] + cluster[1][1]; //3 ->BR
|
||||
double sumTR = cluster[1][2] + cluster[2][1] + cluster[2][2] + cluster[1][1]; //1 ->TR
|
||||
double sumMax = 0;
|
||||
double t, r;
|
||||
|
||||
// if(sumTL >= sumMax){
|
||||
sDum[0][0] = cluster[0][0]; sDum[1][0] = cluster[1][0];
|
||||
sDum[0][1] = cluster[0][1]; sDum[1][1] = cluster[1][1];
|
||||
corner = BOTTOM_LEFT;
|
||||
sumMax=sumBL;
|
||||
// }
|
||||
|
||||
if(sumTL >= sumMax){
|
||||
sDum[0][0] = cluster[1][0]; sDum[1][0] = cluster[2][0];
|
||||
sDum[0][1] = cluster[1][1]; sDum[1][1] = cluster[2][1];
|
||||
|
||||
corner = TOP_LEFT;
|
||||
sumMax=sumTL;
|
||||
}
|
||||
|
||||
if(sumBR >= sumMax){
|
||||
sDum[0][0] = cluster[0][1]; sDum[1][0] = cluster[1][1];
|
||||
sDum[0][1] = cluster[0][2]; sDum[1][1] = cluster[1][2];
|
||||
|
||||
corner = BOTTOM_RIGHT;
|
||||
sumMax=sumBR;
|
||||
}
|
||||
|
||||
if(sumTR >= sumMax){
|
||||
sDum[0][0] = cluster[1][1]; sDum[1][0] = cluster[2][1];
|
||||
sDum[0][1] = cluster[1][2]; sDum[1][1] = cluster[2][2];
|
||||
|
||||
corner = TOP_RIGHT;
|
||||
sumMax=sumTR;
|
||||
}
|
||||
|
||||
totquad=sumMax;
|
||||
|
||||
return corner;
|
||||
|
||||
}
|
||||
|
||||
static int calcEta(double totquad, double sDum[2][2], double &etax, double &etay){
|
||||
double t,r;
|
||||
|
||||
if (totquad>0) {
|
||||
t = sDum[1][0] + sDum[1][1];
|
||||
r = sDum[0][1] + sDum[1][1];
|
||||
etax=r/totquad;
|
||||
etay=t/totquad;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int calcEta(double *cl, double &etax, double &etay, double &sum, double &totquad, double sDum[2][2]) {
|
||||
int corner = calcQuad(cl,sum,totquad,sDum);
|
||||
calcEta(totquad, sDum, etax, etay);
|
||||
|
||||
return corner;
|
||||
}
|
||||
|
||||
|
||||
static int calcEtaL(double totquad, int corner, double sDum[2][2], double &etax, double &etay){
|
||||
double t,r, toth, totv;
|
||||
if (totquad>0) {
|
||||
switch(corner) {
|
||||
case TOP_LEFT:
|
||||
t = sDum[1][1];
|
||||
r = sDum[0][1] ;
|
||||
toth=sDum[0][1]+sDum[0][0];
|
||||
totv=sDum[0][1]+sDum[1][1];
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
t = sDum[1][0] ;
|
||||
r = sDum[0][1] ;
|
||||
toth=sDum[0][1]+sDum[0][0];
|
||||
totv=sDum[1][0]+sDum[0][0];
|
||||
break;
|
||||
case BOTTOM_LEFT:
|
||||
r = sDum[1][1] ;
|
||||
t = sDum[1][1] ;
|
||||
toth=sDum[1][0]+sDum[1][1];
|
||||
totv=sDum[0][1]+sDum[1][1];
|
||||
break;
|
||||
case BOTTOM_RIGHT:
|
||||
t = sDum[1][0] ;
|
||||
r = sDum[1][1] ;
|
||||
toth=sDum[1][0]+sDum[1][1];
|
||||
totv=sDum[1][0]+sDum[0][0];
|
||||
break;
|
||||
default:
|
||||
etax=-1000;
|
||||
etay=-1000;
|
||||
return 0;
|
||||
}
|
||||
//etax=r/totquad;
|
||||
//etay=t/totquad;
|
||||
etax=r/toth;
|
||||
etay=t/totv;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int calcEtaL(double *cl, double &etax, double &etay, double &sum, double &totquad, double sDum[2][2]) {
|
||||
int corner = calcQuad(cl,sum,totquad,sDum);
|
||||
calcEtaL(totquad, corner, sDum, etax, etay);
|
||||
|
||||
return corner;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int calcEtaC3(double *cl, double &etax, double &etay, double &sum, double &totquad, double sDum[2][2]){
|
||||
|
||||
int corner = calcQuad(cl,sum,totquad,sDum);
|
||||
calcEta(sum, sDum, etax, etay);
|
||||
return corner;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int calcEta3(double *cl, double &etax, double &etay, double &sum) {
|
||||
double l,r,t,b;
|
||||
sum=cl[0]+cl[1]+cl[2]+cl[3]+cl[4]+cl[5]+cl[6]+cl[7]+cl[8];
|
||||
if (sum>0) {
|
||||
l=cl[0]+cl[3]+cl[6];
|
||||
r=cl[2]+cl[5]+cl[8];
|
||||
b=cl[0]+cl[1]+cl[2];
|
||||
t=cl[6]+cl[7]+cl[8];
|
||||
etax=(-l+r)/sum;
|
||||
etay=(-b+t)/sum;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int calcMyEta(double totquad, int quad, double *cl, double &etax, double &etay) {
|
||||
double l,r,t,b, sum;
|
||||
int yoff;
|
||||
switch (quad) {
|
||||
case BOTTOM_LEFT:
|
||||
case BOTTOM_RIGHT:
|
||||
yoff=0;
|
||||
break;
|
||||
case TOP_LEFT:
|
||||
case TOP_RIGHT:
|
||||
yoff=1;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
l=cl[0+yoff*3]+cl[0+yoff*3+3];
|
||||
r=cl[2+yoff*3]+cl[2+yoff*3+3];
|
||||
b=cl[0+yoff*3]+cl[1+yoff*3]*cl[2+yoff*3];
|
||||
t=cl[0+yoff*3+3]+cl[1+yoff*3+3]*cl[0+yoff*3+3];
|
||||
sum=t+b;
|
||||
if (sum>0) {
|
||||
etax=(-l+r)/sum;
|
||||
etay=(+t)/sum;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int calcEta3X(double *cl, double &etax, double &etay, double &sum) {
|
||||
double l,r,t,b;
|
||||
sum=cl[0]+cl[1]+cl[2]+cl[3]+cl[4]+cl[5]+cl[6]+cl[7]+cl[8];
|
||||
if (sum>0) {
|
||||
l=cl[3];
|
||||
r=cl[5];
|
||||
b=cl[1];
|
||||
t=cl[7];
|
||||
etax=(-l+r)/sum;
|
||||
etay=(-b+t)/sum;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
int nPixelsX, nPixelsY;
|
||||
int nSubPixels;
|
||||
#ifdef MYROOT1
|
||||
TH2F *hint;
|
||||
#endif
|
||||
#ifndef MYROOT1
|
||||
int *hint;
|
||||
#endif
|
||||
int id;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
45
slsDetectorCalibration/moench03CommonMode.h
Normal file
45
slsDetectorCalibration/moench03CommonMode.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef MOENCH03COMMONMODE_H
|
||||
#define MOENCH03COMMONMODE_H
|
||||
|
||||
#include "commonModeSubtraction.h"
|
||||
|
||||
class moench03CommonMode : public commonModeSubtraction {
|
||||
/** @short class to calculate the common mode noise for moench02 i.e. on 4 supercolumns separately */
|
||||
public:
|
||||
/** constructor - initalizes a commonModeSubtraction with 4 different regions of interest
|
||||
\param nn number of samples for the moving average
|
||||
*/
|
||||
moench03CommonMode(int nn=1000) : commonModeSubtraction(nn,32){} ;
|
||||
|
||||
|
||||
/** add value to common mode as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each;
|
||||
\param val value to add to the common mode
|
||||
\param ix pixel coordinate in the x direction
|
||||
\param iy pixel coordinate in the y direction
|
||||
*/
|
||||
virtual void addToCommonMode(double val, int ix=0, int iy=0) {
|
||||
// (void) iy;
|
||||
int isc=ix/25+(iy/200)*16;
|
||||
if (isc>=0 && isc<nROI) {
|
||||
cmPed[isc]+=val;
|
||||
nCm[isc]++;
|
||||
}
|
||||
};
|
||||
/**returns common mode value as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each;
|
||||
\param ix pixel coordinate in the x direction
|
||||
\param iy pixel coordinate in the y direction
|
||||
\returns common mode value
|
||||
*/
|
||||
virtual double getCommonMode(int ix=0, int iy=0) {
|
||||
(void) iy;
|
||||
int isc=ix/25+(iy/200)*16;
|
||||
if (isc>=0 && isc<nROI) {
|
||||
if (nCm[isc]>0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean();
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
45
slsDetectorCalibration/moenchCommonMode.h
Normal file
45
slsDetectorCalibration/moenchCommonMode.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef MOENCHCOMMONMODE_H
|
||||
#define MOENCHCOMMONMODE_H
|
||||
|
||||
#include "commonModeSubtraction.h"
|
||||
|
||||
class moenchCommonMode : public commonModeSubtraction {
|
||||
/** @short class to calculate the common mode noise for moench02 i.e. on 4 supercolumns separately */
|
||||
public:
|
||||
/** constructor - initalizes a commonModeSubtraction with 4 different regions of interest
|
||||
\param nn number of samples for the moving average
|
||||
*/
|
||||
moenchCommonMode(int nn=1000) : commonModeSubtraction(nn,4){} ;
|
||||
|
||||
|
||||
/** add value to common mode as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each;
|
||||
\param val value to add to the common mode
|
||||
\param ix pixel coordinate in the x direction
|
||||
\param iy pixel coordinate in the y direction
|
||||
*/
|
||||
virtual void addToCommonMode(double val, int ix=0, int iy=0) {
|
||||
(void) iy;
|
||||
int isc=ix/40;
|
||||
if (isc>=0 && isc<nROI) {
|
||||
cmPed[isc]+=val;
|
||||
nCm[isc]++;
|
||||
}
|
||||
};
|
||||
/**returns common mode value as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each;
|
||||
\param ix pixel coordinate in the x direction
|
||||
\param iy pixel coordinate in the y direction
|
||||
\returns common mode value
|
||||
*/
|
||||
virtual double getCommonMode(int ix=0, int iy=0) {
|
||||
(void) iy;
|
||||
int isc=ix/40;
|
||||
if (isc>=0 && isc<nROI) {
|
||||
if (nCm[isc]>0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean();
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,33 @@
|
||||
|
||||
#CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/
|
||||
#ZMQLIB=../slsReceiverSoftware/include
|
||||
#LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
|
||||
INCDIR=-IslsDetectorCalibration -I. -IetaVEL -I../slsReceiverSoftware/include
|
||||
#-I$(CBFLIBDIR)/include/
|
||||
#LIBHDF5=
|
||||
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -L$(CBFLIBDIR)/lib/ -ltiff
|
||||
#-L$(ZMQLIB) -lzmq
|
||||
#-L../../bin
|
||||
MAIN=moench03ClusterFinder.cpp
|
||||
#-lhdf5
|
||||
#DESTDIR?=../bin
|
||||
|
||||
all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation
|
||||
|
||||
|
||||
|
||||
moenchClusterFinder: $(MAIN) $(INCS) clean
|
||||
g++ -o moenchClusterFinder $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
moenchMakeEta: moench03MakeEta.cpp $(INCS) clean
|
||||
g++ -o moenchMakeEta moench03MakeEta.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
moenchInterpolation: moench03Interpolation.cpp $(INCS) clean
|
||||
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
moenchNoInterpolation: moench03NoInterpolation.cpp $(INCS) clean
|
||||
g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
clean:
|
||||
rm -f moenchClusterFinder moenchMakeEta
|
||||
|
20
slsDetectorCalibration/moenchExecutables/Makefile.moench
Normal file
20
slsDetectorCalibration/moenchExecutables/Makefile.moench
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
CBFLIBDIR=/afs/psi.ch/project/sls_det_software/CBFlib-0.9.5
|
||||
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
|
||||
INCDIR=-IslsDetectorCalibration -I../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I. -IetaVEL
|
||||
LIBHDF5=-L$(CBFLIBDIR)/lib/ -lhdf5
|
||||
LDFLAG= -L/usr/lib64/ -lpthread
|
||||
#-L../../bin
|
||||
MAIN=moench03OnTheFlyAnalysis.C
|
||||
|
||||
#DESTDIR?=../bin
|
||||
|
||||
all: moench03OnTheFlyAnalysis
|
||||
|
||||
|
||||
|
||||
moench03OnTheFlyAnalysis: $(MAIN) $(INCS) clean
|
||||
g++ -o moench03OnTheFlyAnalysis $(MAIN) -lm -ltiff -lstdc++ $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
|
||||
|
||||
clean:
|
||||
rm -f moench03OnTheFlyAnalysis
|
23
slsDetectorCalibration/moenchExecutables/Makefile.moench_eta
Normal file
23
slsDetectorCalibration/moenchExecutables/Makefile.moench_eta
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
CBFLIBDIR= /home/l_msdetect/CBFlib-0.9.5
|
||||
ZMQLIB=../slsReceiverSoftware/include
|
||||
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
|
||||
INCDIR=-IslsDetectorCalibration -I../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I.
|
||||
#-IetaVEL
|
||||
LIBHDF5=
|
||||
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -lzmq -pthread -lrt -L$(CBFLIBDIR)/lib/ -lhdf5 -ltiff -L$(ZMQLIB)
|
||||
#-L../../bin
|
||||
MAIN=moench03ClusterFinder.cpp
|
||||
|
||||
#DESTDIR?=../bin
|
||||
|
||||
all: moench03ClusterFinder
|
||||
|
||||
|
||||
|
||||
moench03ClusterFinder: $(MAIN) $(INCS) clean
|
||||
g++ -o moenchClusterFinder $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
clean:
|
||||
rm -f moench03ClusterFinder
|
||||
|
22
slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq
Normal file
22
slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
CBFLIBDIR=/afs/psi.ch/project/sls_det_software/CBFlib-0.9.5
|
||||
ZMQLIB=../slsReceiverSoftware/include
|
||||
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
|
||||
INCDIR=-IslsDetectorCalibration -I../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I. -IetaVEL
|
||||
LIBHDF5=
|
||||
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -lzmq -pthread -lrt -L$(CBFLIBDIR)/lib/ -lhdf5 -ltiff -L$(ZMQLIB)
|
||||
#-L../../bin
|
||||
MAIN=moench03ZmqOnTheFly.cpp
|
||||
|
||||
#DESTDIR?=../bin
|
||||
|
||||
all: moench03ZmqOnTheFly
|
||||
|
||||
|
||||
|
||||
moench03ZmqOnTheFly: $(MAIN) $(INCS) clean
|
||||
g++ -o moench03ZmqOnTheFly $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
clean:
|
||||
rm -f moench03ZmqOnTheFlyEta
|
||||
|
30
slsDetectorCalibration/moenchExecutables/Makefile.phoenix
Normal file
30
slsDetectorCalibration/moenchExecutables/Makefile.phoenix
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/
|
||||
#ZMQLIB=../slsReceiverSoftware/include
|
||||
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
|
||||
INCDIR=-IslsDetectorCalibration -I. -IetaVEL -I../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/
|
||||
#LIBHDF5=
|
||||
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -L$(CBFLIBDIR)/lib/ -ltiff -lhdf5
|
||||
#-L$(ZMQLIB) -lzmq
|
||||
#-L../../bin
|
||||
MAIN=moench03ClusterFinderPhoenix.cpp
|
||||
#
|
||||
#DESTDIR?=../bin
|
||||
|
||||
all: moenchClusterFinderPhoenix
|
||||
#moenchMakeEtaPhoenix moenchInterpolationPhoenix
|
||||
|
||||
|
||||
|
||||
moenchClusterFinderPhoenix: $(MAIN) $(INCS) clean
|
||||
g++ -o moenchClusterFinderPhoenix $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
moenchMakeEtaPhoenix: moench03MakeEtaPhoenix.cpp $(INCS) clean
|
||||
g++ -o moenchMakeEta moench03MakeEta.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
moenchInterpolationPhoenix: moench03InterpolationPhoenix.cpp $(INCS) clean
|
||||
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL
|
||||
|
||||
clean:
|
||||
rm -f moenchClusterFinderPhoenix moenchMakeEtaPhoenix moenchInterpolationPhoenix
|
||||
|
@ -0,0 +1,25 @@
|
||||
#INCSROOT= receiverGui.h
|
||||
#INCS= $(INCSROOT) moench03_receiver.h
|
||||
#LINKDEF=receiverGuiLinkDef.h
|
||||
|
||||
CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/
|
||||
ZMQLIB=../slsReceiverSoftware/include
|
||||
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
|
||||
INCDIR=-IslsDetectorCalibration -I. -IetaVEL -I../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I$(ROOTSYS)/include
|
||||
#LIBHDF5=
|
||||
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -L$(CBFLIBDIR)/lib/ -lhdf5 -ltiff -L$(ZMQLIB) -lzmq
|
||||
|
||||
MAIN=tiff_to_th2f.cpp
|
||||
|
||||
|
||||
all: tiff_to_th2f
|
||||
|
||||
|
||||
|
||||
tiff_to_th2f: $(MAIN) $(INCS)
|
||||
|
||||
g++ -o tiff_to_th2f $(MAIN) `root-config --cflags --glibs` -lMinuit -lm -ltiff -lstdc++ $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp
|
||||
|
||||
clean:
|
||||
rm -f tiff_to_th2f
|
||||
|
@ -0,0 +1,255 @@
|
||||
//#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
//#include "moench03T1ZmqData.h"
|
||||
#include "moench03T1ReceiverData.h"
|
||||
|
||||
// #include "interpolatingDetector.h"
|
||||
//#include "etaInterpolationPosXY.h"
|
||||
// #include "linearInterpolation.h"
|
||||
// #include "noInterpolation.h"
|
||||
#include "multiThreadedAnalogDetector.h"
|
||||
#include "singlePhotonDetector.h"
|
||||
//#include "interpolatingDetector.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
if (argc<7) {
|
||||
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax pedfname" << endl;
|
||||
}
|
||||
int p=10000;
|
||||
int fifosize=1000;
|
||||
int nthreads=20;
|
||||
int nsubpix=25;
|
||||
int etabins=nsubpix*10;
|
||||
double etamin=-1, etamax=2;
|
||||
int csize=3;
|
||||
int nx=400, ny=400;
|
||||
int save=1;
|
||||
int nsigma=5;
|
||||
int nped=1000;
|
||||
int ndark=100;
|
||||
int ok;
|
||||
int iprog=0;
|
||||
|
||||
moench03T1ReceiverData *decoder=new moench03T1ReceiverData();
|
||||
//moench03T1ZmqData *decoder=new moench03T1ZmqData();
|
||||
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200);
|
||||
// char tit[10000];
|
||||
|
||||
|
||||
|
||||
|
||||
// filter->readPedestals("/scratch/ped_100.tiff");
|
||||
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
// cout << "filter "<< endl;
|
||||
|
||||
|
||||
int size = 327680;////atoi(argv[3]);
|
||||
|
||||
int* image;
|
||||
//int* image =new int[327680/sizeof(int)];
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
int ff, np;
|
||||
int dsize=decoder->getDataSize();
|
||||
cout << " data size is " << dsize;
|
||||
|
||||
|
||||
char data[dsize];
|
||||
|
||||
ifstream filebin;
|
||||
char *indir=argv[1];
|
||||
char *outdir=argv[2];
|
||||
char *fformat=argv[3];
|
||||
int runmin=atoi(argv[4]);
|
||||
int runmax=atoi(argv[5]);
|
||||
|
||||
char fname[10000];
|
||||
char outfname[10000];
|
||||
char imgfname[10000];
|
||||
char pedfname[10000];
|
||||
strcpy(pedfname,argv[6]);
|
||||
char fn[10000];
|
||||
|
||||
std::time_t end_time;
|
||||
|
||||
FILE *of=NULL;
|
||||
cout << "input directory is " << indir << endl;
|
||||
cout << "output directory is " << outdir << endl;
|
||||
cout << "fileformat is " << fformat << endl;
|
||||
cout << "pedestal file is " << fformat << endl;
|
||||
|
||||
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << endl;
|
||||
filter->setFrameMode(eFrame);
|
||||
// mt->setFrameMode(ePedestal);
|
||||
cout << pedfname<< endl;
|
||||
|
||||
filebin.open((const char *)(pedfname), ios::in | ios::binary);
|
||||
//filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
|
||||
// //open file
|
||||
if (filebin.is_open()){
|
||||
// //while read frame
|
||||
cout << "pedestal file " << endl;
|
||||
while (decoder->readNextFrame(filebin, ff, np,data)) {
|
||||
// cout << ff << " " << np << endl;
|
||||
// //push
|
||||
// mt->pushData(buff);
|
||||
// // //pop
|
||||
//mt->nextThread();
|
||||
// // // cout << " " << (void*)buff;
|
||||
//mt->popFree(buff);
|
||||
filter->processData(data);
|
||||
}
|
||||
filebin.close();
|
||||
// //close file
|
||||
// //join threads
|
||||
// while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
// cout << outfname << endl;
|
||||
// filter->writePedestals(outfname);
|
||||
// sprintf(outfname,"%s/%s_pedimg.tiff",outdir,fn);
|
||||
|
||||
// cout << outfname << endl;
|
||||
|
||||
// filter->writeImage(outfname);
|
||||
// //mt->clearImage();
|
||||
} else
|
||||
cout << "Could not open "<< pedfname << " for reading " << endl;
|
||||
|
||||
|
||||
|
||||
// for (int ix=0; ix<400; ix++)
|
||||
// for (int iy=0; iy<400; iy++)
|
||||
// cout << ix << " " << iy << " " << filter->getPedestal(ix,iy) << " " << filter->getPedestalRMS(ix,iy) << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char* buff;
|
||||
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
|
||||
|
||||
|
||||
// mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
|
||||
// mt->prepareInterpolation(ok);
|
||||
mt->setFrameMode(eFrame);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
|
||||
int ifr=0;
|
||||
// //loop on files
|
||||
// mt->setFrameMode(eFrame);
|
||||
//mt->setFrameMode(eFlat);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (int irun=runmin; irun<runmin+5; irun++) {
|
||||
sprintf(fn,fformat,irun);
|
||||
sprintf(fname,"%s/%s.raw",indir,fn);
|
||||
|
||||
|
||||
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
// //open file
|
||||
if (filebin.is_open()){
|
||||
// //while read frame
|
||||
while (decoder->readNextFrame(filebin, ff, np,buff)) {
|
||||
// cout << "*"<<ifr++<<"*"<<ff<< endl;
|
||||
// cout << ff << " " << np << endl;
|
||||
// //push
|
||||
mt->pushData(buff);
|
||||
// // //pop
|
||||
mt->nextThread();
|
||||
// // // cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
}
|
||||
// cout << "--" << endl;
|
||||
filebin.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
mt->clearImage();
|
||||
|
||||
for (int irun=runmin; irun<runmax; irun++) {
|
||||
sprintf(fn,fformat,irun);
|
||||
sprintf(fname,"%s/%s.raw",indir,fn);
|
||||
sprintf(outfname,"%s/%s.clust",outdir,fn);
|
||||
sprintf(imgfname,"%s/%s.tiff",outdir,fn);
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << endl;
|
||||
cout << fname << " " << outfname << " " << imgfname << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
// //open file
|
||||
if (filebin.is_open()){
|
||||
of=fopen(outfname,"w");
|
||||
if (of) {
|
||||
mt->setFilePointer(of);
|
||||
// cout << "file pointer set " << endl;
|
||||
} else {
|
||||
cout << "Could not open "<< outfname << " for writing " << endl;
|
||||
mt->setFilePointer(NULL);
|
||||
return 1;
|
||||
}
|
||||
// //while read frame
|
||||
while (decoder->readNextFrame(filebin, ff, np,buff)) {
|
||||
// cout << "*"<<ifr++<<"*"<<ff<< endl;
|
||||
// cout << ff << " " << np << endl;
|
||||
// //push
|
||||
mt->pushData(buff);
|
||||
// // //pop
|
||||
mt->nextThread();
|
||||
// // // cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
}
|
||||
// cout << "--" << endl;
|
||||
filebin.close();
|
||||
// //close file
|
||||
// //join threads
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
if (of)
|
||||
fclose(of);
|
||||
|
||||
mt->writeImage(imgfname);
|
||||
mt->clearImage();
|
||||
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << endl;
|
||||
|
||||
} else
|
||||
cout << "Could not open "<< fname << " for reading " << endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,192 @@
|
||||
//#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
//#include "moench03T1ZmqData.h"
|
||||
//#include "moench03T1ReceiverData.h"
|
||||
|
||||
#include "moench03Ctb10GbT1Data.h"
|
||||
|
||||
// #include "interpolatingDetector.h"
|
||||
//#include "etaInterpolationPosXY.h"
|
||||
// #include "linearInterpolation.h"
|
||||
// #include "noInterpolation.h"
|
||||
#include "multiThreadedAnalogDetector.h"
|
||||
#include "singlePhotonDetector.h"
|
||||
//#include "interpolatingDetector.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
if (argc<6) {
|
||||
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
|
||||
return 0;
|
||||
}
|
||||
int p=10000;
|
||||
int fifosize=1000;
|
||||
int nthreads=20;
|
||||
int nsubpix=25;
|
||||
int etabins=nsubpix*10;
|
||||
double etamin=-1, etamax=2;
|
||||
int csize=3;
|
||||
int nx=400, ny=400;
|
||||
int save=1;
|
||||
int nsigma=5;
|
||||
int nped=1000;
|
||||
int ndark=100;
|
||||
int ok;
|
||||
int iprog=0;
|
||||
moench03Ctb10GbT1Data *decoder=new moench03Ctb10GbT1Data();
|
||||
cout << "decoder" << endl;
|
||||
//moench03T1ReceiverData *decoder=new moench03T1ReceiverData();
|
||||
//moench03T1ZmqData *decoder=new moench03T1ZmqData();
|
||||
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200);
|
||||
// char tit[10000];
|
||||
cout << "filter" << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
// filter->readPedestals("/scratch/ped_100.tiff");
|
||||
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
// cout << "filter "<< endl;
|
||||
|
||||
|
||||
int size = 327680;////atoi(argv[3]);
|
||||
|
||||
int* image;
|
||||
//int* image =new int[327680/sizeof(int)];
|
||||
filter->newDataSet();
|
||||
|
||||
cout << "dataset" << endl;
|
||||
|
||||
int ff, np;
|
||||
int dsize=decoder->getDataSize();
|
||||
cout << " data size is " << dsize << endl;
|
||||
|
||||
|
||||
char data[dsize];
|
||||
|
||||
ifstream filebin;
|
||||
char *indir=argv[1];
|
||||
cout << "input directory is " << indir << endl;
|
||||
char *outdir=argv[2];
|
||||
cout << "output directory is " << outdir << endl;
|
||||
char *fformat=argv[3];
|
||||
cout << "fileformat is " << fformat << endl;
|
||||
int runmin=atoi(argv[4]);
|
||||
cout << "runmin : " << runmin << endl;
|
||||
int runmax=atoi(argv[5]);
|
||||
cout << "runmax : " << runmax << endl;
|
||||
|
||||
char fname[10000];
|
||||
char outfname[10000];
|
||||
char imgfname[10000];
|
||||
char pedfname[10000];
|
||||
char fn[10000];
|
||||
|
||||
std::time_t end_time;
|
||||
|
||||
FILE *of=NULL;
|
||||
|
||||
|
||||
cout << "time " << endl;
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << endl;
|
||||
filter->setFrameMode(eFrame);
|
||||
// mt->setFrameMode(ePedestal);
|
||||
|
||||
|
||||
// for (int ix=0; ix<400; ix++)
|
||||
// for (int iy=0; iy<400; iy++)
|
||||
// cout << ix << " " << iy << " " << filter->getPedestal(ix,iy) << " " << filter->getPedestalRMS(ix,iy) << endl;
|
||||
|
||||
|
||||
char* buff;
|
||||
cout << "aa " << endl;
|
||||
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
|
||||
cout << "mt " << endl;
|
||||
|
||||
// mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
|
||||
// mt->prepareInterpolation(ok);
|
||||
mt->setFrameMode(eFrame);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
|
||||
int ifr=0;
|
||||
// //loop on files
|
||||
// mt->setFrameMode(eFrame);
|
||||
//mt->setFrameMode(eFlat);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (int irun=runmin; irun<runmax; irun++) {
|
||||
sprintf(fn,fformat,irun);
|
||||
sprintf(fname,"%s/%s.raw",indir,fn);
|
||||
sprintf(outfname,"%s/%s.clust",outdir,fn);
|
||||
sprintf(imgfname,"%s/%s.tiff",outdir,fn);
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << endl;
|
||||
cout << fname << " " << outfname << " " << imgfname << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
// //open file
|
||||
if (filebin.is_open()){
|
||||
of=fopen(outfname,"w");
|
||||
if (of) {
|
||||
mt->setFilePointer(of);
|
||||
// cout << "file pointer set " << endl;
|
||||
} else {
|
||||
cout << "Could not open "<< outfname << " for writing " << endl;
|
||||
mt->setFilePointer(NULL);
|
||||
return 1;
|
||||
}
|
||||
// //while read frame
|
||||
ff=-1;
|
||||
while (decoder->readNextFrame(filebin, ff, np,buff)) {
|
||||
// cout << "*"<<ifr++<<"*"<<ff<< endl;
|
||||
// cout << ff << " " << np << endl;
|
||||
// //push
|
||||
mt->pushData(buff);
|
||||
// // //pop
|
||||
mt->nextThread();
|
||||
// // // cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
ff=-1;
|
||||
}
|
||||
// cout << "--" << endl;
|
||||
filebin.close();
|
||||
// //close file
|
||||
// //join threads
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
if (of)
|
||||
fclose(of);
|
||||
|
||||
mt->writeImage(imgfname);
|
||||
mt->clearImage();
|
||||
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << endl;
|
||||
|
||||
} else
|
||||
cout << "Could not open "<< fname << " for reading " << endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,171 @@
|
||||
|
||||
#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moench03T1ZmqData.h"
|
||||
#include "single_photon_hit.h"
|
||||
|
||||
#include "etaInterpolationPosXY.h"
|
||||
|
||||
using namespace std;
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [outfname]
|
||||
*
|
||||
*/
|
||||
|
||||
if (argc<7) {
|
||||
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " etafile outfile runmin runmax ns" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char infname[10000];
|
||||
char outfname[10000];
|
||||
int runmin=atoi(argv[4]);
|
||||
int runmax=atoi(argv[5]);
|
||||
int nsubpix=atoi(argv[6]);
|
||||
|
||||
int etabins=1000;//nsubpix*2*100;
|
||||
double etamin=-1, etamax=2;
|
||||
int quad;
|
||||
double sum, totquad;
|
||||
double sDum[2][2];
|
||||
double etax, etay, int_x, int_y;
|
||||
int ok;
|
||||
|
||||
int ix, iy, isx, isy;
|
||||
|
||||
|
||||
FILE *f=NULL;
|
||||
|
||||
single_photon_hit cl(3,3);
|
||||
etaInterpolationPosXY *interp=new etaInterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
|
||||
interp->readFlatField(argv[2]);
|
||||
interp->prepareInterpolation(ok);
|
||||
|
||||
int *img;
|
||||
float *totimg=new float[NC*NR*nsubpix*nsubpix];
|
||||
for (ix=0; ix<NC; ix++) {
|
||||
for (iy=0; iy<NR; iy++) {
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef FF
|
||||
|
||||
float ff[nsubpix*nsubpix];
|
||||
float *ffimg=new float[NC*NR*nsubpix*nsubpix];
|
||||
float totff=0;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
for (int irun=runmin; irun<runmax; irun++) {
|
||||
sprintf(infname,argv[1],irun);
|
||||
sprintf(outfname,argv[3],irun);
|
||||
|
||||
f=fopen(infname,"r");
|
||||
|
||||
if (f) {
|
||||
while (cl.read(f)) {
|
||||
quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
|
||||
if (sum>200 && sum<580) {
|
||||
interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y);
|
||||
interp->addToImage(int_x, int_y);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
#ifdef FF
|
||||
img=interp->getInterpolatedImage();
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
ff[isy*nsubpix+isx]=0;
|
||||
}
|
||||
}
|
||||
totff=0;
|
||||
for (ix=0; ix<NC; ix++) {
|
||||
for (iy=0; iy<NR-100; iy++) {
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
ff[isy*nsubpix+isx]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
totff+=ff[isy*nsubpix+isx];
|
||||
}
|
||||
}
|
||||
totff/=nsubpix*nsubpix;
|
||||
|
||||
|
||||
if (totff) {
|
||||
|
||||
cout << "ff: " << totff << endl;
|
||||
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
ff[isy*nsubpix+isx]/=totff;
|
||||
cout << ff[isy*nsubpix+isx] << "\t";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (ix=0; ix<NC; ix++) {
|
||||
for (iy=0; iy<NR; iy++) {
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
ffimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]/ff[isy*nsubpix+isx];
|
||||
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=ffimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WriteToTiff(ffimg, outfname,NC*nsubpix,NR*nsubpix);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
#ifndef FF
|
||||
interp->writeInterpolatedImage(outfname);
|
||||
img=interp->getInterpolatedImage();
|
||||
for (ix=0; ix<NC; ix++) {
|
||||
for (iy=0; iy<NR; iy++) {
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
interp->clearInterpolatedImage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sprintf(outfname,argv[3],11111);
|
||||
WriteToTiff(totimg, outfname,NC*nsubpix,NR*nsubpix);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
62
slsDetectorCalibration/moenchExecutables/moench03MakeEta.cpp
Normal file
62
slsDetectorCalibration/moenchExecutables/moench03MakeEta.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
|
||||
#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moench03T1ZmqData.h"
|
||||
#include "single_photon_hit.h"
|
||||
|
||||
#include "etaInterpolationPosXY.h"
|
||||
|
||||
using namespace std;
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [outfname]
|
||||
*
|
||||
*/
|
||||
int nsubpix=10;
|
||||
int etabins=nsubpix*100;
|
||||
double etamin=-1, etamax=2;
|
||||
int quad;
|
||||
double sum, totquad;
|
||||
double sDum[2][2];
|
||||
char fname[10000];
|
||||
double etax, etay;
|
||||
int runmin, runmax;
|
||||
single_photon_hit cl(3,3);
|
||||
|
||||
if (argc<5) {
|
||||
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " outfile runmin runmax" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
etaInterpolationPosXY *interp=new etaInterpolationPosXY(NR, NC, nsubpix, etabins, etamin, etamax);
|
||||
runmin=atoi(argv[3]);
|
||||
runmax=atoi(argv[4]);
|
||||
|
||||
|
||||
FILE *f;
|
||||
for (int i=runmin; i<runmax; i++) {
|
||||
sprintf(fname,argv[1],i);
|
||||
f=fopen(fname,"r");
|
||||
if (f) {
|
||||
cout << "*" << endl;
|
||||
while (cl.read(f)) {
|
||||
interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
|
||||
if (sum>200 && sum<580 && cl.y<350)
|
||||
interp->addToFlatField(cl.get_cluster(),etax, etay);
|
||||
}
|
||||
fclose(f);
|
||||
interp->writeFlatField(argv[2]);
|
||||
|
||||
}
|
||||
else cout << "could not open file " << fname << endl;
|
||||
}
|
||||
|
||||
interp->writeFlatField(argv[2]);
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,171 @@
|
||||
|
||||
#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moench03T1ZmqData.h"
|
||||
#include "single_photon_hit.h"
|
||||
|
||||
#include "noInterpolation.h"
|
||||
|
||||
using namespace std;
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [outfname]
|
||||
*
|
||||
*/
|
||||
|
||||
if (argc<7) {
|
||||
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " etafile outfile runmin runmax ns" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char infname[10000];
|
||||
char outfname[10000];
|
||||
int runmin=atoi(argv[4]);
|
||||
int runmax=atoi(argv[5]);
|
||||
int nsubpix=atoi(argv[6]);
|
||||
|
||||
int etabins=1000;//nsubpix*2*100;
|
||||
double etamin=-1, etamax=2;
|
||||
int quad;
|
||||
double sum, totquad;
|
||||
double sDum[2][2];
|
||||
double etax, etay, int_x, int_y;
|
||||
int ok;
|
||||
|
||||
int ix, iy, isx, isy;
|
||||
|
||||
|
||||
FILE *f=NULL;
|
||||
|
||||
single_photon_hit cl(3,3);
|
||||
// etaInterpolationPosXY *interp=new etaInterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
|
||||
noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
|
||||
// interp->readFlatField(argv[2]);
|
||||
// interp->prepareInterpolation(ok);
|
||||
|
||||
int *img;
|
||||
float *totimg=new float[NC*NR*nsubpix*nsubpix];
|
||||
for (ix=0; ix<NC; ix++) {
|
||||
for (iy=0; iy<NR; iy++) {
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef FF
|
||||
|
||||
float ff[nsubpix*nsubpix];
|
||||
float *ffimg=new float[NC*NR*nsubpix*nsubpix];
|
||||
float totff=0;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
for (int irun=runmin; irun<runmax; irun++) {
|
||||
sprintf(infname,argv[1],irun);
|
||||
sprintf(outfname,argv[3],irun);
|
||||
|
||||
f=fopen(infname,"r");
|
||||
|
||||
if (f) {
|
||||
while (cl.read(f)) {
|
||||
quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
|
||||
if (sum>200 && sum<580) {
|
||||
interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y);
|
||||
interp->addToImage(int_x, int_y);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
#ifdef FF
|
||||
img=interp->getInterpolatedImage();
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
ff[isy*nsubpix+isx]=0;
|
||||
}
|
||||
}
|
||||
totff=0;
|
||||
for (ix=0; ix<NC; ix++) {
|
||||
for (iy=0; iy<NR-100; iy++) {
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
ff[isy*nsubpix+isx]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
totff+=ff[isy*nsubpix+isx];
|
||||
}
|
||||
}
|
||||
totff/=nsubpix*nsubpix;
|
||||
|
||||
|
||||
if (totff) {
|
||||
|
||||
cout << "ff: " << totff << endl;
|
||||
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
ff[isy*nsubpix+isx]/=totff;
|
||||
cout << ff[isy*nsubpix+isx] << "\t";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (ix=0; ix<NC; ix++) {
|
||||
for (iy=0; iy<NR; iy++) {
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
ffimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]/ff[isy*nsubpix+isx];
|
||||
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=ffimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WriteToTiff(ffimg, outfname,NC*nsubpix,NR*nsubpix);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
#ifndef FF
|
||||
interp->writeInterpolatedImage(outfname);
|
||||
img=interp->getInterpolatedImage();
|
||||
for (ix=0; ix<NC; ix++) {
|
||||
for (iy=0; iy<NR; iy++) {
|
||||
for (isx=0; isx<nsubpix; isx++) {
|
||||
for (isy=0; isy<nsubpix; isy++) {
|
||||
totimg[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)]+=img[ix*nsubpix+isx+(iy*nsubpix+isy)*(NC*nsubpix)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
interp->clearInterpolatedImage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(outfname,argv[3],11111);
|
||||
WriteToTiff(totimg, outfname,NC*nsubpix,NR*nsubpix);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,160 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
//#include <deque>
|
||||
//#include <list>
|
||||
//#include <queue>
|
||||
#include <fstream>
|
||||
|
||||
#include "moench03Ctb10GbT1Data.h"
|
||||
|
||||
#include "interpolatingDetector.h"
|
||||
#include "etaInterpolationPosXY.h"
|
||||
#include "linearInterpolation.h"
|
||||
#include "noInterpolation.h"
|
||||
#include "multiThreadedDetector.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
#include "tiffIO.h"
|
||||
|
||||
|
||||
void *moenchProcessFrame() {
|
||||
char fname[10000];
|
||||
strcpy(fname,"/mnt/moench_data/m03-15_mufocustube/plant_40kV_10uA/m03-15_100V_g4hg_300us_dtf_0.raw");
|
||||
|
||||
int nthreads=3;
|
||||
|
||||
int nph, nph1;
|
||||
single_photon_hit clusters[NR*NC];
|
||||
// cout << "hits "<< endl;
|
||||
int etabins=550;
|
||||
double etamin=-1, etamax=2;
|
||||
int nsubpix=4;
|
||||
float *etah=new float[etabins*etabins];
|
||||
// cout << "etah "<< endl;
|
||||
cout << "image size "<< nsubpix*nsubpix*NC*NR << endl;
|
||||
float *image=new float[nsubpix*nsubpix*NC*NR];
|
||||
int *heta, *himage;
|
||||
|
||||
moench03Ctb10GbT1Data *decoder=new moench03Ctb10GbT1Data();
|
||||
// cout << "decoder "<< endl;
|
||||
etaInterpolationPosXY *interp=new etaInterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
|
||||
// cout << "interp "<< endl;
|
||||
//linearInterpolation *interp=new linearInterpolation(NC, NR, nsubpix);
|
||||
//noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
|
||||
interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
interpolatingDetector *filter=new interpolatingDetector(decoder,interp, 5, 1, 0, 1000, 10);
|
||||
filter->readPedestals("/scratch/ped_100.tiff");
|
||||
cout << "filter "<< endl;
|
||||
|
||||
|
||||
|
||||
char *buff;
|
||||
int nf=0;
|
||||
int ok=0;
|
||||
ifstream filebin;
|
||||
std::time_t end_time;
|
||||
|
||||
int iFrame=-1;
|
||||
int np=-1;
|
||||
|
||||
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
multiThreadedDetector *mt=new multiThreadedDetector(filter,nthreads,100);
|
||||
nph=0;
|
||||
nph1=0;
|
||||
//int np;
|
||||
int iph;
|
||||
|
||||
cout << "file name " << fname << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
if (filebin.is_open())
|
||||
cout << "Opened file " << fname<< endl;
|
||||
else
|
||||
cout << "Could not open file " << fname<< endl;
|
||||
mt->setFrameMode(eFrame);
|
||||
mt->prepareInterpolation(ok);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
while ((decoder->readNextFrame(filebin, iFrame, np, buff)) && nf<1.5E4) {
|
||||
if (nf<9E3)
|
||||
;
|
||||
else {
|
||||
|
||||
// if (nf>1.1E4 && ok==0) {
|
||||
// mt->prepareInterpolation(ok);
|
||||
// mt->setFrameMode(eFrame);
|
||||
// //ok=1;
|
||||
// }
|
||||
|
||||
mt->pushData(buff);
|
||||
mt->nextThread();
|
||||
// cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
// if (ok==0) {
|
||||
// cout << "**************************************************************************"<< endl;
|
||||
// heta=interp->getFlatField();
|
||||
// // for (int ii=0; ii<etabins*etabins; ii++) {
|
||||
// // etah[ii]=(float)heta[ii];
|
||||
// // }
|
||||
|
||||
|
||||
// std::time(&end_time);
|
||||
// cout << std::ctime(&end_time) << " " << nf << endl;
|
||||
// // WriteToTiff(etah, "/scratch/eta.tiff", etabins, etabins);
|
||||
|
||||
// interp->prepareInterpolation(ok);
|
||||
// cout << "**************************************************************************"<< endl;
|
||||
// std::time(&end_time);
|
||||
// cout << std::ctime(&end_time) << " " << nf << endl;
|
||||
// }
|
||||
// filter->processData(buff,eFrame);
|
||||
// }
|
||||
|
||||
// nph+=nph1;
|
||||
}
|
||||
if (nf%1000==0) {
|
||||
std::time(&end_time);
|
||||
cout << std::ctime(&end_time) << " " << nf << endl;
|
||||
}
|
||||
|
||||
nf++;
|
||||
//delete [] buff;
|
||||
iFrame=-1;
|
||||
}
|
||||
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
else
|
||||
cout << "could not open file " << fname << endl;
|
||||
|
||||
mt->StopThreads();
|
||||
|
||||
char tit[10000];
|
||||
sprintf(tit,"/scratch/int_image_mt%d.tiff",nthreads);
|
||||
|
||||
mt->writeInterpolatedImage(tit);
|
||||
// delete [] etah;
|
||||
|
||||
// delete interp;
|
||||
//delete decoder;
|
||||
//cout << "Read " << nf << " frames" << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
moenchProcessFrame();
|
||||
|
||||
}
|
272
slsDetectorCalibration/moenchExecutables/moench03ZmqOnTheFly.cpp
Normal file
272
slsDetectorCalibration/moenchExecutables/moench03ZmqOnTheFly.cpp
Normal file
@ -0,0 +1,272 @@
|
||||
#include "ZmqSocket.h"
|
||||
|
||||
#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moench03T1ZmqData.h"
|
||||
|
||||
// #include "interpolatingDetector.h"
|
||||
//#include "etaInterpolationPosXY.h"
|
||||
// #include "linearInterpolation.h"
|
||||
// #include "noInterpolation.h"
|
||||
#include "multiThreadedAnalogDetector.h"
|
||||
#include "singlePhotonDetector.h"
|
||||
#include "interpolatingDetector.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
|
||||
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [outfname]
|
||||
*
|
||||
*/
|
||||
|
||||
int p=10000;
|
||||
int fifosize=1000;
|
||||
int nthreads=20;
|
||||
int nsubpix=25;
|
||||
int etabins=nsubpix*10;
|
||||
double etamin=-1, etamax=2;
|
||||
int csize=3;
|
||||
int nx=400, ny=400;
|
||||
int save=1;
|
||||
int nsigma=5;
|
||||
int nped=1000;
|
||||
int ndark=100;
|
||||
int ok;
|
||||
int iprog=0;
|
||||
char outfname[10000];
|
||||
|
||||
|
||||
moench03T1ZmqData *decoder=new moench03T1ZmqData();
|
||||
// cout << "decoder "<< endl;
|
||||
//etaInterpolationPosXY *interp=new etaInterpolationPosXY(nx, ny, nsubpix, etabins, etamin, etamax);
|
||||
// linearInterpolation *interp=new linearInterpolation(NC, NR, nsubpix);
|
||||
//noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
|
||||
//interpolatingDetector *filter=new interpolatingDetector(decoder,interp, nsigma, 1, 0, nped, 100);
|
||||
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 100);
|
||||
char tit[10000];
|
||||
|
||||
|
||||
|
||||
|
||||
// filter->readPedestals("/scratch/ped_100.tiff");
|
||||
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
// cout << "filter "<< endl;
|
||||
|
||||
|
||||
int size = 327680;////atoi(argv[3]);
|
||||
|
||||
char* buff;
|
||||
int* image;
|
||||
//int* image =new int[327680/sizeof(int)];
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
|
||||
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
|
||||
|
||||
|
||||
//mt->setFrameMode(eFrame);
|
||||
mt->setFrameMode(eFlat);
|
||||
|
||||
// mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
|
||||
// mt->prepareInterpolation(ok);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
// help
|
||||
if (argc < 2 || (argc > 2)) {
|
||||
cprintf(RED, "Help: %s [receive socket ip]\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// receive parameters
|
||||
bool send = false;
|
||||
char* socketip = argv[1];
|
||||
uint32_t portnum = 30001;//atoi(argv[2]);
|
||||
// char fn[10000];
|
||||
// strcpy(fn, argv[2]);
|
||||
// send parameters if any
|
||||
// char* socketip2 = 0;
|
||||
// uint32_t portnum2 = 0;
|
||||
// if (argc > 4) {
|
||||
// send = true;
|
||||
// socketip2 = argv[4];
|
||||
// portnum2 = atoi(argv[5]);
|
||||
// }
|
||||
cout << "\nrx socket ip : " << socketip ; // <<
|
||||
// "\nrx port num : " << portnum <<
|
||||
// "\nsize : " << size;
|
||||
// "\nfname : " << fn ;
|
||||
// if (send) {
|
||||
// cout << "\nsd socket ip : " << socketip2 <<
|
||||
// "\nsd port num : " << portnum2;
|
||||
// }
|
||||
cout << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// receive socket
|
||||
ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum);
|
||||
if (zmqsocket->IsError()) {
|
||||
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
|
||||
delete zmqsocket;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress());
|
||||
|
||||
// send socket
|
||||
// ZmqSocket* zmqsocket2 = 0;
|
||||
// if (send) {
|
||||
// zmqsocket2 = new ZmqSocket(portnum2, socketip2);
|
||||
// if (zmqsocket2->IsError()) {
|
||||
// bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
|
||||
// delete zmqsocket2;
|
||||
// delete zmqsocket;
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress());
|
||||
// }
|
||||
|
||||
|
||||
// cout << "size " << 327680/sizeof(int) << endl;
|
||||
|
||||
// header variables
|
||||
uint64_t acqIndex = -1;
|
||||
uint64_t frameIndex = -1;
|
||||
uint32_t subframeIndex = -1;
|
||||
string filename = "";
|
||||
int nnx, nny, nns;
|
||||
int imsize=filter->getImageSize(nnx,nny,nns);
|
||||
//int imsize=nx*ny;
|
||||
int i_image=0;
|
||||
cout << "Image size is "<< nnx << " " << nny << " " << nns << " " << imsize << endl;
|
||||
int iframe=0;
|
||||
int ff=0;
|
||||
|
||||
// infinite loop
|
||||
while(1) {
|
||||
|
||||
|
||||
// cprintf(GREEN, "Got ?\n");
|
||||
// get header, (if dummy, fail is on parse error or end of acquisition)
|
||||
if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename)) {
|
||||
cprintf(RED, "Acquisition finished\n");
|
||||
|
||||
|
||||
|
||||
cout << "Received " << ff << " frames for a total of "<< iframe << endl;
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
|
||||
// stream dummy to socket2 to signal end of acquisition
|
||||
// if (send) {
|
||||
// zmqsocket2->SendData((char*)(mt->getImage()),imsize*sizeof(int));
|
||||
// cprintf(BLUE, "Sent Interpolated image\n");
|
||||
// // zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
|
||||
// // cprintf(RED, "Sent Dummy\n");
|
||||
// }
|
||||
// if (save) {
|
||||
sprintf(tit,"%s_%05d.tiff",filename.c_str(), ff);
|
||||
// cout << tit << endl;
|
||||
mt->writeImage(tit);
|
||||
mt->clearImage();
|
||||
// }
|
||||
// sprintf(tit,"%s_%05d_eta_i.tiff",filename.c_str(), ff);
|
||||
// interp->writeFlatField(tit);
|
||||
// sprintf(tit,"%s_%05d_eta.tiff",filename.c_str(), ff);
|
||||
// cout << tit << endl;
|
||||
// mt->writeFlatField(tit);
|
||||
|
||||
i_image++;
|
||||
ff=0;
|
||||
// dont get data
|
||||
continue; //continue to not get out
|
||||
}
|
||||
|
||||
if (ff==0)
|
||||
cprintf(GREEN, "Start acquisition \n");
|
||||
// cout << filename << endl;
|
||||
// cprintf(GREEN, "Got Header \n");
|
||||
// get data
|
||||
// cprintf(GREEN, "Got Header\n");
|
||||
//image=(int*)buff;
|
||||
//cout << buff << endl;
|
||||
int length = zmqsocket->ReceiveData(0, (int*)buff, size);
|
||||
// int length = zmqsocket->ReceiveData(0, (int*)image, size);
|
||||
// cprintf(GREEN, "Got Data\n");
|
||||
|
||||
//processing with image
|
||||
//...
|
||||
|
||||
|
||||
|
||||
|
||||
mt->pushData(buff);
|
||||
mt->nextThread();
|
||||
// cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
iframe++;
|
||||
ff++;
|
||||
// if (iframe%p==0) {
|
||||
|
||||
// while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
// sprintf(tit,"tmp.tiff",filename.c_str(), i_image);
|
||||
// mt->writeImage(tit);
|
||||
// // mt->clearImage();
|
||||
// // }
|
||||
// //interp->writeFlatField(tit);
|
||||
// // i_image++;
|
||||
// // sprintf(tit,"%s_tmp.tiff",fn);
|
||||
// // mt->writeImage(tit);
|
||||
// // //mt->clearImage();
|
||||
|
||||
// // cout <<"*"<< iprog++ << endl;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //stream data from socket 2
|
||||
// if (send) {
|
||||
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,
|
||||
// 0,0,0,acqIndex,frameIndex,(char*)"run", acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
|
||||
// cprintf(GREEN, "Sent Header\n");
|
||||
|
||||
// zmqsocket2->SendData((char*)image,length);
|
||||
// cprintf(GREEN, "Sent Data\n");
|
||||
// }
|
||||
|
||||
|
||||
}// exiting infinite loop
|
||||
|
||||
|
||||
|
||||
delete zmqsocket;
|
||||
// if (send)
|
||||
// delete zmqsocket2;
|
||||
|
||||
|
||||
// cout<<"Goodbye"<< endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,306 @@
|
||||
#include "ZmqSocket.h"
|
||||
|
||||
#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moench03T1ZmqData.h"
|
||||
|
||||
// #include "interpolatingDetector.h"
|
||||
#include "etaInterpolationPosXY.h"
|
||||
// #include "linearInterpolation.h"
|
||||
// #include "noInterpolation.h"
|
||||
#include "multiThreadedAnalogDetector.h"
|
||||
#include "singlePhotonDetector.h"
|
||||
#include "interpolatingDetector.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
|
||||
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [outfname]
|
||||
*
|
||||
*/
|
||||
|
||||
int p=1000; //1.5s with 15ms period
|
||||
int fifosize=1000;
|
||||
int nthreads=8;
|
||||
int nsubpix=2;
|
||||
int etabins=nsubpix*10;
|
||||
double etamin=-1, etamax=2;
|
||||
int csize=3;
|
||||
int nx=400, ny=400;
|
||||
int save=1;
|
||||
int nsigma=5;
|
||||
int nped=1000;
|
||||
int ndark=100;
|
||||
int ok;
|
||||
int iprog=0;
|
||||
char outfname[10000];
|
||||
|
||||
if (nsubpix>2) p=5000;
|
||||
|
||||
|
||||
moench03T1ZmqData *decoder=new moench03T1ZmqData();
|
||||
// cout << "decoder "<< endl;
|
||||
etaInterpolationPosXY *interp=new etaInterpolationPosXY(nx, ny, nsubpix, etabins, etamin, etamax);
|
||||
// linearInterpolation *interp=new linearInterpolation(NC, NR, nsubpix);
|
||||
//noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
|
||||
interpolatingDetector *filter=new interpolatingDetector(decoder,interp, nsigma, 1, 0, nped, 100);
|
||||
// singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 100);
|
||||
char tit[10000];
|
||||
|
||||
|
||||
|
||||
|
||||
// filter->readPedestals("/scratch/ped_100.tiff");
|
||||
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
// cout << "filter "<< endl;
|
||||
|
||||
|
||||
int size = 327680;////atoi(argv[3]);
|
||||
|
||||
char* buff;
|
||||
int* image;
|
||||
//int* image =new int[327680/sizeof(int)];
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
|
||||
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
|
||||
|
||||
|
||||
//
|
||||
if (nsubpix>2)
|
||||
mt->setFrameMode(eFlat);
|
||||
else
|
||||
mt->setFrameMode(eFrame);
|
||||
|
||||
// mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
|
||||
// mt->prepareInterpolation(ok);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
// help
|
||||
if (argc < 2 || (argc > 2)) {
|
||||
cprintf(RED, "Help: %s [receive socket ip]\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// receive parameters
|
||||
bool send = false;
|
||||
char* socketip = argv[1];
|
||||
uint32_t portnum = 30001;//atoi(argv[2]);
|
||||
// char fn[10000];
|
||||
// strcpy(fn, argv[2]);
|
||||
// send parameters if any
|
||||
// char* socketip2 = 0;
|
||||
// uint32_t portnum2 = 0;
|
||||
// if (argc > 4) {
|
||||
// send = true;
|
||||
// socketip2 = argv[4];
|
||||
// portnum2 = atoi(argv[5]);
|
||||
// }
|
||||
cout << "\nrx socket ip : " << socketip ; // <<
|
||||
// "\nrx port num : " << portnum <<
|
||||
// "\nsize : " << size;
|
||||
// "\nfname : " << fn ;
|
||||
// if (send) {
|
||||
// cout << "\nsd socket ip : " << socketip2 <<
|
||||
// "\nsd port num : " << portnum2;
|
||||
// }
|
||||
cout << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// receive socket
|
||||
ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum);
|
||||
if (zmqsocket->IsError()) {
|
||||
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
|
||||
delete zmqsocket;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress());
|
||||
|
||||
// send socket
|
||||
// ZmqSocket* zmqsocket2 = 0;
|
||||
// if (send) {
|
||||
// zmqsocket2 = new ZmqSocket(portnum2, socketip2);
|
||||
// if (zmqsocket2->IsError()) {
|
||||
// bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
|
||||
// delete zmqsocket2;
|
||||
// delete zmqsocket;
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress());
|
||||
// }
|
||||
|
||||
|
||||
// cout << "size " << 327680/sizeof(int) << endl;
|
||||
|
||||
// header variables
|
||||
uint64_t acqIndex = -1;
|
||||
uint64_t frameIndex = -1;
|
||||
uint32_t subframeIndex = -1;
|
||||
string filename = "";
|
||||
int nnx, nny, nns;
|
||||
int imsize=filter->getImageSize(nnx,nny,nns);
|
||||
//int imsize=nx*ny;
|
||||
int i_image=0;
|
||||
cout << "Image size is "<< nnx << " " << nny << " " << nns << " " << imsize << endl;
|
||||
int iframe=0;
|
||||
int ff=0;
|
||||
|
||||
// infinite loop
|
||||
while(1) {
|
||||
|
||||
|
||||
// cprintf(GREEN, "Got ?\n");
|
||||
// get header, (if dummy, fail is on parse error or end of acquisition)
|
||||
if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename)) {
|
||||
cprintf(RED, "Acquisition finished\n");
|
||||
|
||||
|
||||
|
||||
cout << "Received " << ff << " frames for a total of "<< iframe << endl;
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
|
||||
// stream dummy to socket2 to signal end of acquisition
|
||||
// if (send) {
|
||||
// zmqsocket2->SendData((char*)(mt->getImage()),imsize*sizeof(int));
|
||||
// cprintf(BLUE, "Sent Interpolated image\n");
|
||||
// // zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
|
||||
// // cprintf(RED, "Sent Dummy\n");
|
||||
// }
|
||||
// if (save) {
|
||||
// if (iframe>p) {
|
||||
sprintf(tit,"%s_%05d_%05d.tiff",filename.c_str(), ff, i_image);
|
||||
cout << tit << endl;
|
||||
mt->writeImage(tit);
|
||||
sprintf(tit,"/home/l_msdetect/slsbl/x07mb/x07mbop/Data1/2017/11/06/tmp.tiff");
|
||||
cout <<"*"<< iframe<< endl;
|
||||
mt->writeImage(tit);
|
||||
mt->clearImage();
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// }
|
||||
//sprintf(tit,"%s_%05d_eta_i.tiff",filename.c_str(), ff);
|
||||
//interp->writeFlatField(tit);
|
||||
// sprintf(tit,"%s_%05d_eta_%d.tiff",filename.c_str(), ff, acqIndex);
|
||||
// // cout << tit << endl;
|
||||
// mt->writeFlatField(tit);
|
||||
|
||||
i_image++;
|
||||
ff=0;
|
||||
//filter->newDataSet();
|
||||
|
||||
// dont get data
|
||||
continue; //continue to not get out
|
||||
}
|
||||
|
||||
if (ff==0)
|
||||
cprintf(GREEN, "Start acquisition %d\n",acqIndex);
|
||||
// cout << filename << endl;
|
||||
// cprintf(GREEN, "Got Header \n");
|
||||
// get data
|
||||
// cprintf(GREEN, "Got Header\n");
|
||||
//image=(int*)buff;
|
||||
//cout << buff << endl;
|
||||
int length = zmqsocket->ReceiveData(0, (int*)buff, size);
|
||||
// int length = zmqsocket->ReceiveData(0, (int*)image, size);
|
||||
// cprintf(GREEN, "Got Data\n");
|
||||
|
||||
//processing with image
|
||||
//...
|
||||
|
||||
|
||||
|
||||
|
||||
mt->pushData(buff);
|
||||
mt->nextThread();
|
||||
// cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
iframe++;
|
||||
if (nsubpix>2) {
|
||||
if (iframe==p) {
|
||||
mt->setFrameMode(eFrame);
|
||||
mt->prepareInterpolation(ok);
|
||||
|
||||
sprintf(tit,"%s_%05d_eta.tiff",filename.c_str(), ff);
|
||||
cout << tit << endl;
|
||||
mt->writeFlatField(tit);
|
||||
}
|
||||
} //else {
|
||||
// cout << iframe << " " << p << endl;
|
||||
if (iframe%p==0) {
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
sprintf(tit,"/home/l_msdetect/slsbl/x07mb/x07mbop/Data1/2017/11/06/tmp.tiff");
|
||||
cout <<"*"<< iframe<< endl;
|
||||
mt->writeImage(tit);
|
||||
// mt->clearImage();
|
||||
}
|
||||
//}
|
||||
ff++;
|
||||
// if (iframe%p==0) {
|
||||
|
||||
// while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
// sprintf(tit,"tmp.tiff",filename.c_str(), i_image);
|
||||
// mt->writeImage(tit);
|
||||
// // mt->clearImage();
|
||||
// // }
|
||||
// //interp->writeFlatField(tit);
|
||||
// // i_image++;
|
||||
// // sprintf(tit,"%s_tmp.tiff",fn);
|
||||
// // mt->writeImage(tit);
|
||||
// // //mt->clearImage();
|
||||
|
||||
// // cout <<"*"<< iprog++ << endl;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //stream data from socket 2
|
||||
// if (send) {
|
||||
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,
|
||||
// 0,0,0,acqIndex,frameIndex,(char*)"run", acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
|
||||
// cprintf(GREEN, "Sent Header\n");
|
||||
|
||||
// zmqsocket2->SendData((char*)image,length);
|
||||
// cprintf(GREEN, "Sent Data\n");
|
||||
// }
|
||||
|
||||
|
||||
}// exiting infinite loop
|
||||
|
||||
|
||||
|
||||
delete zmqsocket;
|
||||
// if (send)
|
||||
// delete zmqsocket2;
|
||||
|
||||
|
||||
// cout<<"Goodbye"<< endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,251 @@
|
||||
#include "ZmqSocket.h"
|
||||
|
||||
#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moench03T1ZmqData.h"
|
||||
|
||||
// #include "interpolatingDetector.h"
|
||||
#include "etaInterpolationPosXY.h"
|
||||
// #include "linearInterpolation.h"
|
||||
// #include "noInterpolation.h"
|
||||
#include "multiThreadedAnalogDetector.h"
|
||||
//#include "singlePhotonDetector.h"
|
||||
#include "interpolatingDetector.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
|
||||
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [outfname]
|
||||
*
|
||||
*/
|
||||
|
||||
int p=1000;
|
||||
int fifosize=1000;
|
||||
int nthreads=6;
|
||||
int nsubpix=25;
|
||||
int etabins=nsubpix*10;
|
||||
double etamin=-1, etamax=2;
|
||||
int csize=3;
|
||||
int nx=400, ny=400;
|
||||
int save=1;
|
||||
int nsigma=5;
|
||||
int nped=1000;
|
||||
int ndark=100;
|
||||
int ok;
|
||||
int iprog=0;
|
||||
char outfname[10000];
|
||||
|
||||
|
||||
moench03T1ZmqData *decoder=new moench03T1ZmqData();
|
||||
// cout << "decoder "<< endl;
|
||||
etaInterpolationPosXY *interp=new etaInterpolationPosXY(nx, ny, nsubpix, etabins, etamin, etamax);
|
||||
// linearInterpolation *interp=new linearInterpolation(NC, NR, nsubpix);
|
||||
//noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
|
||||
// interpolatingDetector *filter=new interpolatingDetector(decoder,interp, nsigma, 1, 0, nped, 100);
|
||||
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 100);
|
||||
char tit[10000];
|
||||
|
||||
|
||||
|
||||
|
||||
// filter->readPedestals("/scratch/ped_100.tiff");
|
||||
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
// cout << "filter "<< endl;
|
||||
|
||||
|
||||
int size = 327680;////atoi(argv[3]);
|
||||
|
||||
char* buff;
|
||||
int* image;
|
||||
//int* image =new int[327680/sizeof(int)];
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
|
||||
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
|
||||
|
||||
|
||||
mt->setFrameMode(eFrame);
|
||||
// mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
|
||||
// mt->prepareInterpolation(ok);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
// help
|
||||
if (argc < 3 || (argc > 3)) {
|
||||
cprintf(RED, "Help: %s [receive socket ip] [fname]\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// receive parameters
|
||||
bool send = false;
|
||||
char* socketip = argv[1];
|
||||
uint32_t portnum = 30001;//atoi(argv[2]);
|
||||
char fn[10000];
|
||||
strcpy(fn, argv[2]);
|
||||
// send parameters if any
|
||||
// char* socketip2 = 0;
|
||||
// uint32_t portnum2 = 0;
|
||||
// if (argc > 4) {
|
||||
// send = true;
|
||||
// socketip2 = argv[4];
|
||||
// portnum2 = atoi(argv[5]);
|
||||
// }
|
||||
cout << "\nrx socket ip : " << socketip <<
|
||||
// "\nrx port num : " << portnum <<
|
||||
// "\nsize : " << size;
|
||||
"\nfname : " << fn ;
|
||||
// if (send) {
|
||||
// cout << "\nsd socket ip : " << socketip2 <<
|
||||
// "\nsd port num : " << portnum2;
|
||||
// }
|
||||
cout << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// receive socket
|
||||
ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum);
|
||||
if (zmqsocket->IsError()) {
|
||||
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
|
||||
delete zmqsocket;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress());
|
||||
|
||||
// send socket
|
||||
// ZmqSocket* zmqsocket2 = 0;
|
||||
// if (send) {
|
||||
// zmqsocket2 = new ZmqSocket(portnum2, socketip2);
|
||||
// if (zmqsocket2->IsError()) {
|
||||
// bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
|
||||
// delete zmqsocket2;
|
||||
// delete zmqsocket;
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress());
|
||||
// }
|
||||
|
||||
|
||||
cout << "size " << 327680/sizeof(int) << endl;
|
||||
|
||||
// header variables
|
||||
uint64_t acqIndex = -1;
|
||||
uint64_t frameIndex = -1;
|
||||
uint32_t subframeIndex = -1;
|
||||
string filename = "";
|
||||
int nnx, nny, nns;
|
||||
int imsize=filter->getImageSize(nnx,nny,nns);
|
||||
//int imsize=nx*ny;
|
||||
int i_image=0;
|
||||
cout << "Image size is "<< nnx << " " << nny << " " << nns << " " << imsize << endl;
|
||||
int iframe=0;
|
||||
|
||||
// infinite loop
|
||||
while(1) {
|
||||
|
||||
|
||||
// cprintf(GREEN, "Got ?\n");
|
||||
// get header, (if dummy, fail is on parse error or end of acquisition)
|
||||
if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename)) {
|
||||
cprintf(RED, "Acquisition finished\n");
|
||||
|
||||
|
||||
|
||||
cout << "Recieved " << iframe << " frames " << endl;
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
|
||||
// stream dummy to socket2 to signal end of acquisition
|
||||
// if (send) {
|
||||
// zmqsocket2->SendData((char*)(mt->getImage()),imsize*sizeof(int));
|
||||
// cprintf(BLUE, "Sent Interpolated image\n");
|
||||
// // zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
|
||||
// // cprintf(RED, "Sent Dummy\n");
|
||||
// }
|
||||
// if (save) {
|
||||
sprintf(tit,"%s_%d.tiff",fn, i_image);
|
||||
mt->writeImage(tit);
|
||||
mt->clearImage();
|
||||
// }
|
||||
//interp->writeFlatField(tit);
|
||||
i_image++;
|
||||
// dont get data
|
||||
continue; //continue to not get out
|
||||
}
|
||||
// cprintf(GREEN, "Got Header \n");
|
||||
// get data
|
||||
// cprintf(GREEN, "Got Header\n");
|
||||
//image=(int*)buff;
|
||||
//cout << buff << endl;
|
||||
int length = zmqsocket->ReceiveData(0, (int*)buff, size);
|
||||
// int length = zmqsocket->ReceiveData(0, (int*)image, size);
|
||||
// cprintf(GREEN, "Got Data\n");
|
||||
|
||||
//processing with image
|
||||
//...
|
||||
|
||||
|
||||
|
||||
|
||||
mt->pushData(buff);
|
||||
mt->nextThread();
|
||||
// cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
iframe++;
|
||||
// if (iframe%p==0) {
|
||||
|
||||
// while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
// sprintf(tit,"%s_tmp.tiff",fn);
|
||||
// mt->writeImage(tit);
|
||||
// //mt->clearImage();
|
||||
|
||||
// cout <<"*"<< iprog++ << endl;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //stream data from socket 2
|
||||
// if (send) {
|
||||
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,
|
||||
// 0,0,0,acqIndex,frameIndex,(char*)"run", acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
|
||||
// cprintf(GREEN, "Sent Header\n");
|
||||
|
||||
// zmqsocket2->SendData((char*)image,length);
|
||||
// cprintf(GREEN, "Sent Data\n");
|
||||
// }
|
||||
|
||||
|
||||
}// exiting infinite loop
|
||||
|
||||
|
||||
|
||||
delete zmqsocket;
|
||||
// if (send)
|
||||
// delete zmqsocket2;
|
||||
|
||||
|
||||
// cout<<"Goodbye"<< endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,219 @@
|
||||
#include "ZmqSocket.h"
|
||||
|
||||
#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moench03T1ZmqData.h"
|
||||
|
||||
#include "interpolatingDetector.h"
|
||||
#include "etaInterpolationPosXY.h"
|
||||
#include "linearInterpolation.h"
|
||||
#include "noInterpolation.h"
|
||||
#include "multiThreadedDetector.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [image size] [send_socket ip] [send port number]
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int nthreads=3;
|
||||
int nsubpix=5;
|
||||
int etabins=550;
|
||||
double etamin=-1, etamax=2;
|
||||
int nx=400, ny=400;
|
||||
int save=1;
|
||||
int nsigma=5;
|
||||
int nped=1000;
|
||||
int ok;
|
||||
//int* image = new int[(size/sizeof(int))]();
|
||||
char* buff;
|
||||
|
||||
moench03T1ZmqData *decoder=new moench03T1ZmqData();
|
||||
// cout << "decoder "<< endl;
|
||||
etaInterpolationPosXY *interp=new etaInterpolationPosXY(nx, ny, nsubpix, etabins, etamin, etamax);
|
||||
//linearInterpolation *interp=new linearInterpolation(NC, NR, nsubpix);
|
||||
//noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
|
||||
interpolatingDetector *filter=new interpolatingDetector(decoder,interp, nsigma, 1, 0, nped, 10);
|
||||
|
||||
|
||||
|
||||
|
||||
filter->readPedestals("/scratch/ped_100.tiff");
|
||||
interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
cout << "filter "<< endl;
|
||||
|
||||
|
||||
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
|
||||
multiThreadedDetector *mt=new multiThreadedDetector(filter,nthreads,100);
|
||||
|
||||
|
||||
|
||||
mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
|
||||
mt->prepareInterpolation(ok);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
// help
|
||||
if (argc < 4 || (argc > 4 && argc != 6)) {
|
||||
cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [image size] [send_socket ip] [send starting port number]\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// receive parameters
|
||||
bool send = false;
|
||||
char* socketip = argv[1];
|
||||
uint32_t portnum = atoi(argv[2]);
|
||||
int size = atoi(argv[3]);
|
||||
|
||||
// send parameters if any
|
||||
char* socketip2 = 0;
|
||||
uint32_t portnum2 = 0;
|
||||
if (argc > 4) {
|
||||
send = true;
|
||||
socketip2 = argv[4];
|
||||
portnum2 = atoi(argv[5]);
|
||||
}
|
||||
cout << "\nrx socket ip : " << socketip <<
|
||||
"\nrx port num : " << portnum <<
|
||||
"\nsize : " << size;
|
||||
if (send) {
|
||||
cout << "\nsd socket ip : " << socketip2 <<
|
||||
"\nsd port num : " << portnum2;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// receive socket
|
||||
ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum);
|
||||
if (zmqsocket->IsError()) {
|
||||
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
|
||||
delete zmqsocket;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress());
|
||||
|
||||
// send socket
|
||||
ZmqSocket* zmqsocket2 = 0;
|
||||
if (send) {
|
||||
zmqsocket2 = new ZmqSocket(portnum2, socketip2);
|
||||
if (zmqsocket2->IsError()) {
|
||||
bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
|
||||
delete zmqsocket2;
|
||||
delete zmqsocket;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// header variables
|
||||
uint64_t acqIndex = -1;
|
||||
uint64_t frameIndex = -1;
|
||||
uint32_t subframeIndex = -1;
|
||||
string filename = "";
|
||||
int imsize=nx*ny*nsubpix*nsubpix;
|
||||
int i_image=0;
|
||||
|
||||
// infinite loop
|
||||
while(1) {
|
||||
|
||||
|
||||
// get header, (if dummy, fail is on parse error or end of acquisition)
|
||||
if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename)) {
|
||||
cprintf(RED, "Acquisition finished\n");
|
||||
|
||||
|
||||
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
|
||||
|
||||
// stream dummy to socket2 to signal end of acquisition
|
||||
if (send) {
|
||||
zmqsocket2->SendData((char*)(mt->getInterpolatedImage()),imsize*sizeof(int));
|
||||
cprintf(BLUE, "Sent Interpolated image\n");
|
||||
// zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
|
||||
// cprintf(RED, "Sent Dummy\n");
|
||||
}
|
||||
if (save) {
|
||||
char tit[10000];
|
||||
sprintf(tit,"/scratch/int_image_%d.tiff",i_image);
|
||||
mt->writeInterpolatedImage(tit);
|
||||
mt->clearInterpolatedImage(tit);
|
||||
}
|
||||
i_image++;
|
||||
// dont get data
|
||||
break; //continue to not get out
|
||||
}
|
||||
cprintf(GREEN, "Got Header \n");
|
||||
// get data
|
||||
int length = zmqsocket->ReceiveData(0, (int*)buff, size);
|
||||
cprintf(GREEN, "Got Data\n");
|
||||
|
||||
//processing with image
|
||||
//...
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mt->pushData(buff);
|
||||
mt->nextThread();
|
||||
// cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //stream data from socket 2
|
||||
// if (send) {
|
||||
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,
|
||||
// 0,0,0,acqIndex,frameIndex,(char*)"run", acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
|
||||
// cprintf(GREEN, "Sent Header\n");
|
||||
|
||||
// zmqsocket2->SendData((char*)image,length);
|
||||
// cprintf(GREEN, "Sent Data\n");
|
||||
// }
|
||||
|
||||
|
||||
}// exiting infinite loop
|
||||
|
||||
|
||||
|
||||
delete zmqsocket;
|
||||
if (send)
|
||||
delete zmqsocket2;
|
||||
|
||||
|
||||
cout<<"Goodbye"<< endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,248 @@
|
||||
#include "ZmqSocket.h"
|
||||
|
||||
#include "ansi.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moench03T1ZmqData.h"
|
||||
|
||||
// #include "interpolatingDetector.h"
|
||||
// #include "etaInterpolationPosXY.h"
|
||||
#include "linearInterpolation.h"
|
||||
// #include "noInterpolation.h"
|
||||
#include "multiThreadedAnalogDetector.h"
|
||||
//#include "singlePhotonDetector.h"
|
||||
#include "interpolatingDetector.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
|
||||
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [outfname]
|
||||
*
|
||||
*/
|
||||
|
||||
int p=1000;
|
||||
int fifosize=1000;
|
||||
int nthreads=6;
|
||||
int nsubpix=2;
|
||||
// int etabins=550;
|
||||
// double etamin=-1, etamax=2;
|
||||
int csize=3;
|
||||
int nx=400, ny=400;
|
||||
int save=1;
|
||||
int nsigma=5;
|
||||
int nped=1000;
|
||||
int ndark=100;
|
||||
int ok;
|
||||
//int* image = new int[(size/sizeof(int))]();
|
||||
char* buff;
|
||||
int iprog=0;
|
||||
char outfname[10000];
|
||||
|
||||
|
||||
moench03T1ZmqData *decoder=new moench03T1ZmqData();
|
||||
// cout << "decoder "<< endl;
|
||||
//etaInterpolationPosXY *interp=new etaInterpolationPosXY(nx, ny, nsubpix, etabins, etamin, etamax);
|
||||
// linearInterpolation *interp=new linearInterpolation(NC, NR, nsubpix);
|
||||
//noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
|
||||
// interpolatingDetector *filter=new interpolatingDetector(decoder,interp, nsigma, 1, 0, nped, 10);
|
||||
singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 100);
|
||||
char tit[10000];
|
||||
|
||||
|
||||
|
||||
|
||||
// filter->readPedestals("/scratch/ped_100.tiff");
|
||||
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
|
||||
// cout << "filter "<< endl;
|
||||
|
||||
|
||||
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
|
||||
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
|
||||
|
||||
|
||||
|
||||
mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
|
||||
// mt->prepareInterpolation(ok);
|
||||
mt->StartThreads();
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
// help
|
||||
if (argc < 4 || (argc > 4 && argc != 6)) {
|
||||
cprintf(RED, "Help: %s [receive socket ip] [receive starting port number] [fname]\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// receive parameters
|
||||
bool send = false;
|
||||
char* socketip = argv[1];
|
||||
uint32_t portnum = atoi(argv[2]);
|
||||
int size = 327680;////atoi(argv[3]);
|
||||
|
||||
char fn[10000];
|
||||
strcpy(fn, argv[3]);
|
||||
// send parameters if any
|
||||
// char* socketip2 = 0;
|
||||
// uint32_t portnum2 = 0;
|
||||
// if (argc > 4) {
|
||||
// send = true;
|
||||
// socketip2 = argv[4];
|
||||
// portnum2 = atoi(argv[5]);
|
||||
// }
|
||||
cout << "\nrx socket ip : " << socketip <<
|
||||
"\nrx port num : " << portnum <<
|
||||
// "\nsize : " << size;
|
||||
"\nfname : " << fn ;
|
||||
// if (send) {
|
||||
// cout << "\nsd socket ip : " << socketip2 <<
|
||||
// "\nsd port num : " << portnum2;
|
||||
// }
|
||||
cout << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// receive socket
|
||||
ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum);
|
||||
if (zmqsocket->IsError()) {
|
||||
cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip);
|
||||
delete zmqsocket;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress());
|
||||
|
||||
// send socket
|
||||
// ZmqSocket* zmqsocket2 = 0;
|
||||
// if (send) {
|
||||
// zmqsocket2 = new ZmqSocket(portnum2, socketip2);
|
||||
// if (zmqsocket2->IsError()) {
|
||||
// bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2);
|
||||
// delete zmqsocket2;
|
||||
// delete zmqsocket;
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress());
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// header variables
|
||||
uint64_t acqIndex = -1;
|
||||
uint64_t frameIndex = -1;
|
||||
uint32_t subframeIndex = -1;
|
||||
string filename = "";
|
||||
int nnx, nny, nns;
|
||||
int imsize=filter->getImageSize(nnx,nny,nns);
|
||||
//int imsize=nx*ny;
|
||||
int i_image=0;
|
||||
|
||||
int iframe=0;
|
||||
|
||||
// infinite loop
|
||||
while(1) {
|
||||
|
||||
|
||||
// get header, (if dummy, fail is on parse error or end of acquisition)
|
||||
if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename)) {
|
||||
cprintf(RED, "Acquisition finished\n");
|
||||
|
||||
|
||||
|
||||
cout << "Recieved " << iframe << " frames " << endl;
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
cout << "threads done " << endl;
|
||||
|
||||
// stream dummy to socket2 to signal end of acquisition
|
||||
// if (send) {
|
||||
// zmqsocket2->SendData((char*)(mt->getImage()),imsize*sizeof(int));
|
||||
// cprintf(BLUE, "Sent Interpolated image\n");
|
||||
// // zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
|
||||
// // cprintf(RED, "Sent Dummy\n");
|
||||
// }
|
||||
// if (save) {
|
||||
sprintf(tit,"%s_%d.tiff",fn, i_image);
|
||||
cout << tit << endl;
|
||||
mt->writeImage(tit);
|
||||
cout << "wrote" << endl;
|
||||
mt->clearImage();
|
||||
// }
|
||||
i_image++;
|
||||
// dont get data
|
||||
continue; //continue to not get out
|
||||
}
|
||||
// cprintf(GREEN, "Got Header \n");
|
||||
// get data
|
||||
int length = zmqsocket->ReceiveData(0, (int*)buff, size);
|
||||
// cprintf(GREEN, "Got Data\n");
|
||||
|
||||
//processing with image
|
||||
//...
|
||||
|
||||
|
||||
|
||||
|
||||
mt->pushData(buff);
|
||||
mt->nextThread();
|
||||
// cout << " " << (void*)buff;
|
||||
mt->popFree(buff);
|
||||
|
||||
|
||||
iframe++;
|
||||
if (iframe%p==0) {
|
||||
|
||||
while (mt->isBusy()) {;}//wait until all data are processed from the queues
|
||||
sprintf(tit,"%s_tmp.tiff",fn);
|
||||
mt->writeImage(tit);
|
||||
//mt->clearImage();
|
||||
|
||||
cout <<"*"<< iprog++ << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //stream data from socket 2
|
||||
// if (send) {
|
||||
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,
|
||||
// 0,0,0,acqIndex,frameIndex,(char*)"run", acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
|
||||
// cprintf(GREEN, "Sent Header\n");
|
||||
|
||||
// zmqsocket2->SendData((char*)image,length);
|
||||
// cprintf(GREEN, "Sent Data\n");
|
||||
// }
|
||||
|
||||
|
||||
}// exiting infinite loop
|
||||
|
||||
|
||||
|
||||
delete zmqsocket;
|
||||
// if (send)
|
||||
// delete zmqsocket2;
|
||||
|
||||
|
||||
cout<<"Goodbye"<< endl;
|
||||
return 0;
|
||||
}
|
||||
|
209
slsDetectorCalibration/moenchExecutables/readClusters.C
Normal file
209
slsDetectorCalibration/moenchExecutables/readClusters.C
Normal file
@ -0,0 +1,209 @@
|
||||
#include "single_photon_hit.h"
|
||||
//#include "etaVEL/etaInterpolationPosXY.h"
|
||||
|
||||
TH2F *readClusters(char *fname, int nx, int ny, TH2F *h2=NULL) {
|
||||
FILE *f=fopen(fname,"r");
|
||||
int iph=0;
|
||||
int ns=4;
|
||||
double px, py;
|
||||
double left, right, top, bottom;
|
||||
if (f) {
|
||||
int x1,y1;
|
||||
if (h2==NULL)
|
||||
h2=new TH2F("h2",fname,nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);
|
||||
h2mult=new TH2F("h2mult",fname,nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);
|
||||
TH2F *hint=new TH2F("hint",fname,nx*ns, -0.5, nx-0.5, ny*ns, -0.5, ny-0.5);
|
||||
TH2F *hff=new TH2F("hff","hff",ns, -0.5, 0.5, ns, -0.5, +0.5);
|
||||
TH1F *hsp=new TH1F("hsp",fname,500,0,2000);
|
||||
TCanvas *c=new TCanvas();
|
||||
c->SetLogz(kTRUE);
|
||||
h2->Draw("colz");
|
||||
TCanvas *c1=new TCanvas();
|
||||
hsp->Draw();
|
||||
TCanvas *c2=new TCanvas();
|
||||
hint->Draw("colz");
|
||||
c2->SetLogz(kTRUE);
|
||||
single_photon_hit cl(3,3);
|
||||
double tot;
|
||||
int w;
|
||||
double phw=340, phs=62;
|
||||
while (cl.read(f)) {
|
||||
//cl.get_pixel(x1, y1);
|
||||
//cout << cl.iframe << " " << cl.x << " " << cl.y << endl;
|
||||
//if (cl.x>80 && cl.x<280 && cl.y>80 && cl.y<300) {
|
||||
tot=0;
|
||||
left=0;
|
||||
right=0;
|
||||
top=0;
|
||||
bottom=0;
|
||||
for (int ix=-1; ix<2; ix++)
|
||||
for (int iy=-1; iy<2; iy++){
|
||||
tot+=cl.get_data(ix,iy);
|
||||
if (ix<0) left+=cl.get_data(ix,iy);
|
||||
if (ix>0) right+=cl.get_data(ix,iy);
|
||||
if (iy<0) bottom+=cl.get_data(ix,iy);
|
||||
if (iy>0) top+=cl.get_data(ix,iy);
|
||||
|
||||
}
|
||||
px=(-left+right)/tot;
|
||||
py=(-bottom+top)/tot;
|
||||
//max at 340
|
||||
if (tot>200) {
|
||||
w=(tot+3.5*phs)/phw;
|
||||
} else
|
||||
w=0;
|
||||
if (w) {
|
||||
hsp->Fill(tot);
|
||||
if (w==1) {
|
||||
h2->Fill(cl.x,cl.y,w);
|
||||
hint->Fill(px+cl.x,py+cl.y,w);
|
||||
if (cl.y<350)
|
||||
hff->Fill(px,py,w);
|
||||
}
|
||||
|
||||
h2mult->Fill(cl.x,cl.y,w);
|
||||
|
||||
//}
|
||||
iph+=w;
|
||||
if (iph%100000==0) {
|
||||
// c->Modified();
|
||||
// c->Update();
|
||||
c1->Modified();;
|
||||
c1->Update();
|
||||
// c2->Modified();;
|
||||
// c2->Update();
|
||||
}
|
||||
}
|
||||
// if (iph>0.5E7) break;
|
||||
}
|
||||
fclose(f);
|
||||
hff->Scale(hff->GetNbinsX()*hff->GetNbinsY()/hff->Integral());
|
||||
TH2F *hint2=(TH2F*)hint->Clone("hint2");
|
||||
double ff;
|
||||
for (int ibx=0; ibx<hint->GetNbinsX(); ibx++) {
|
||||
for (int iby=0; iby<hint->GetNbinsY(); iby++) {
|
||||
ff=hff->GetBinContent(ibx%ns+1, iby%ns+1);
|
||||
// cout << ibx << " " << iby << " " << ibx%ns << " " << iby%ns << " " << ff << endl;
|
||||
if (ff>0)
|
||||
hint2->SetBinContent(ibx+1, iby+1,hint->GetBinContent(ibx+1,iby+1)/ff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return h2;
|
||||
|
||||
} else
|
||||
cout << "could not open file " << fname << endl;
|
||||
return NULL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// TH2F *getEta(char *fname, int nx, int ny, TH2F *h2=NULL) {
|
||||
// int ns=10;
|
||||
// slsInterpolation *inte=new etaInterpolationPosXY(nx,ny,ns,
|
||||
|
||||
// FILE *f=fopen(fname,"r");
|
||||
// int iph=0;
|
||||
// int ns=4;
|
||||
// double px, py;
|
||||
// double left, right, top, bottom;
|
||||
// if (f) {
|
||||
// int x1,y1;
|
||||
// if (h2==NULL)
|
||||
// h2=new TH2F("h2",fname,nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);
|
||||
// h2mult=new TH2F("h2mult",fname,nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);
|
||||
// TH2F *hint=new TH2F("hint",fname,nx*ns, -0.5, nx-0.5, ny*ns, -0.5, ny-0.5);
|
||||
// // TH2F *hff=new TH2F("hff","hff",ns, -0.5, 0.5, ns, -0.5, +0.5);
|
||||
// TH1F *hsp=new TH1F("hsp",fname,500,0,2000);
|
||||
// TCanvas *c=new TCanvas();
|
||||
// c->SetLogz(kTRUE);
|
||||
// h2->Draw("colz");
|
||||
// TCanvas *c1=new TCanvas();
|
||||
// hsp->Draw();
|
||||
// TCanvas *c2=new TCanvas();
|
||||
// hint->Draw("colz");
|
||||
// c2->SetLogz(kTRUE);
|
||||
// single_photon_hit cl(3,3);
|
||||
// double tot;
|
||||
// int w;
|
||||
// double phw=340, phs=62;
|
||||
// while (cl.read(f)) {
|
||||
// //cl.get_pixel(x1, y1);
|
||||
// //cout << cl.iframe << " " << cl.x << " " << cl.y << endl;
|
||||
// //if (cl.x>80 && cl.x<280 && cl.y>80 && cl.y<300) {
|
||||
// tot=0;
|
||||
// left=0;
|
||||
// right=0;
|
||||
// top=0;
|
||||
// bottom=0;
|
||||
// for (int ix=-1; ix<2; ix++)
|
||||
// for (int iy=-1; iy<2; iy++){
|
||||
// tot+=cl.get_data(ix,iy);
|
||||
// if (ix<0) left+=cl.get_data(ix,iy);
|
||||
// if (ix>0) right+=cl.get_data(ix,iy);
|
||||
// if (iy<0) bottom+=cl.get_data(ix,iy);
|
||||
// if (iy>0) top+=cl.get_data(ix,iy);
|
||||
|
||||
// }
|
||||
// px=(-left+right)/tot;
|
||||
// py=(-bottom+top)/tot;
|
||||
// //max at 340
|
||||
// if (tot>200) {
|
||||
// w=(tot+3.5*phs)/phw;
|
||||
// } else
|
||||
// w=0;
|
||||
// if (w) {
|
||||
// hsp->Fill(tot);
|
||||
// if (w==1) {
|
||||
// h2->Fill(cl.x,cl.y,w);
|
||||
// hint->Fill(px+cl.x,py+cl.y,w);
|
||||
// }
|
||||
|
||||
// h2mult->Fill(cl.x,cl.y,w);
|
||||
|
||||
// // if (cl.y<350)
|
||||
// // hff->Fill(px,py,w);
|
||||
// //}
|
||||
// iph+=w;
|
||||
// if (iph%100000==0) {
|
||||
// // c->Modified();
|
||||
// // c->Update();
|
||||
// c1->Modified();;
|
||||
// c1->Update();
|
||||
// // c2->Modified();;
|
||||
// // c2->Update();
|
||||
// }
|
||||
// }
|
||||
// // if (iph>0.5E7) break;
|
||||
// }
|
||||
// fclose(f);
|
||||
// // hff->Scale(hff->GetNbinsX()*hff->GetNbinsY()/hff->Integral());
|
||||
// // TH2F *hint2=(TH2F*)hint->Clone("hint2");
|
||||
// // double ff;
|
||||
// // for (int ibx=0; ibx<hint->GetNbinsX(); ibx++) {
|
||||
// // for (int iby=0; iby<hint->GetNbinsY(); iby++) {
|
||||
// // ff=hff->GetBinContent(ibx%ns+1, iby%ns+1);
|
||||
// // // cout << ibx << " " << iby << " " << ibx%ns << " " << iby%ns << " " << ff << endl;
|
||||
// // if (ff>0)
|
||||
// // hint2->SetBinContent(ibx+1, iby+1,hint->GetBinContent(ibx+1,iby+1)/ff);
|
||||
// // }
|
||||
// // }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// return h2;
|
||||
|
||||
// } else
|
||||
// cout << "could not open file " << fname << endl;
|
||||
// return NULL;
|
||||
|
||||
|
||||
// }
|
57
slsDetectorCalibration/moenchExecutables/tiff_to_th2f.cpp
Normal file
57
slsDetectorCalibration/moenchExecutables/tiff_to_th2f.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <TPaveText.h>
|
||||
#include <TLegend.h>
|
||||
#include <TF1.h>
|
||||
#include <TGraphErrors.h>
|
||||
#include <TH2F.h>
|
||||
#include <TASImage.h>
|
||||
#include <TImage.h>
|
||||
#include <TFile.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include "tiffIO.h"
|
||||
|
||||
#include<iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* trial.o [socket ip] [starting port number] [outfname]
|
||||
*
|
||||
*/
|
||||
|
||||
if (argc<3) {
|
||||
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " outfile " << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32 nx, ny;
|
||||
|
||||
float *data=ReadFromTiff(argv[1],nx, ny);
|
||||
|
||||
TH2F *h2=NULL;
|
||||
if (data) {
|
||||
TFile *fout=new TFile(argv[2],"RECREATE");
|
||||
if (fout) {
|
||||
h2=new TH2F("h2",argv[1],nx,0,nx,ny,0, ny);
|
||||
for (int ix=0; ix<nx ; ix++) {
|
||||
for (int iy=0; iy<ny ; iy++) {
|
||||
|
||||
h2->SetBinContent(ix+1, iy+1, data[ix+iy*nx]);
|
||||
}
|
||||
}
|
||||
h2->Write();
|
||||
fout->Close();
|
||||
}
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
572
slsDetectorCalibration/multiThreadedAnalogDetector.h
Normal file
572
slsDetectorCalibration/multiThreadedAnalogDetector.h
Normal file
@ -0,0 +1,572 @@
|
||||
#ifndef MULTITHREADED_ANALOG_DETECTOR_H
|
||||
#define MULTITHREADED_ANALOG_DETECTOR_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
//#include <deque>
|
||||
//#include <list>
|
||||
//#include <queue>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "analogDetector.h"
|
||||
#include "singlePhotonDetector.h"
|
||||
//#include "interpolatingDetector.h"
|
||||
#include "circularFifo.h"
|
||||
#include "slsInterpolation.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <mutex>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class threadedAnalogDetector
|
||||
{
|
||||
public:
|
||||
threadedAnalogDetector(analogDetector<uint16_t> *d, int fs=10000) {
|
||||
char *mem, *mm;
|
||||
det=d;
|
||||
fifoFree=new CircularFifo<char>(fs);
|
||||
fifoData=new CircularFifo<char>(fs);
|
||||
mem=(char*)malloc(fs*det->getDataSize());
|
||||
// cout << "data size is " << det->getDataSize()*fs << endl;
|
||||
for (int i=0; i<fs; i++) {
|
||||
mm=mem+i*det->getDataSize();
|
||||
fifoFree->push(mm);
|
||||
}
|
||||
busy=0;
|
||||
stop=1;
|
||||
fMode=eFrame;
|
||||
ff=NULL;
|
||||
}
|
||||
|
||||
|
||||
virtual int setFrameMode(int fm) {fMode=fm; if (fMode>=0) det->setFrameMode((frameMode)fMode);};
|
||||
|
||||
//fMode=fm; return fMode;}
|
||||
|
||||
/* void prepareInterpolation(int &ok) { */
|
||||
/* cout << "-" << endl; */
|
||||
/* det->prepareInterpolation(ok); */
|
||||
/* }; */
|
||||
|
||||
virtual int *getImage() {
|
||||
return det->getImage();
|
||||
}
|
||||
virtual int getImageSize(int &nnx, int &nny, int &ns) {return det->getImageSize(nnx, nny, ns);};
|
||||
virtual int getDetectorSize(int &nnx, int &nny) {return det->getDetectorSize(nnx, nny);};
|
||||
|
||||
~threadedAnalogDetector() {StopThread(); free(mem); delete fifoFree; delete fifoData;}
|
||||
|
||||
/** Returns true if the thread was successfully started, false if there was an error starting the thread */
|
||||
virtual bool StartThread()
|
||||
{ stop=0;
|
||||
return (pthread_create(&_thread, NULL, processData, this) == 0);
|
||||
}
|
||||
|
||||
virtual void StopThread()
|
||||
{ stop=1;
|
||||
(void) pthread_join(_thread, NULL);
|
||||
}
|
||||
|
||||
|
||||
virtual bool pushData(char* &ptr) {
|
||||
fifoData->push(ptr);
|
||||
}
|
||||
|
||||
virtual bool popFree(char* &ptr) {
|
||||
fifoFree->pop(ptr);
|
||||
}
|
||||
|
||||
virtual int isBusy() {return busy;}
|
||||
|
||||
//protected:
|
||||
/** Implement this method in your subclass with the code you want your thread to run. */
|
||||
//virtual void InternalThreadEntry() = 0;
|
||||
virtual void *writeImage(const char * imgname) {cout << "a" <<endl; return det->writeImage(imgname);};
|
||||
|
||||
virtual void clearImage(){det->clearImage();};
|
||||
|
||||
virtual void prepareInterpolation(int &ok){
|
||||
slsInterpolation *interp=(slsInterpolation*)det->getInterpolation();
|
||||
if (interp)
|
||||
interp->prepareInterpolation(ok);
|
||||
}
|
||||
|
||||
virtual int *getFlatField(){
|
||||
slsInterpolation *interp=(slsInterpolation*)det->getInterpolation();
|
||||
if (interp)
|
||||
return interp->getFlatField();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual int *setFlatField(int *ff, int nb, double emin, double emax){
|
||||
slsInterpolation *interp=(slsInterpolation*)det->getInterpolation();
|
||||
if (interp)
|
||||
return interp->setFlatField(ff, nb, emin, emax);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual int *getFlatField(int &nb, double emi, double ema){
|
||||
slsInterpolation *interp=(slsInterpolation*)det->getInterpolation();
|
||||
int *ff;
|
||||
if (interp) {
|
||||
ff=interp->getFlatField(nb,emi,ema);
|
||||
// cout << "tdgff* ff has " << nb << " bins " << endl;
|
||||
return ff;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual char *getInterpolation() {
|
||||
return det->getInterpolation();
|
||||
}
|
||||
|
||||
virtual void setPedestal(double *ped, double *rms=NULL, int m=-1){det->setPedestal(ped,rms,m);};
|
||||
|
||||
|
||||
virtual void setPedestalRMS(double *rms){ det->setPedestalRMS(rms);};
|
||||
|
||||
virtual double *getPedestal(double *ped=NULL){return det->getPedestal(ped);};
|
||||
|
||||
|
||||
virtual double *getPedestalRMS(double *rms=NULL){ return det->getPedestalRMS(rms);};
|
||||
|
||||
|
||||
|
||||
|
||||
/** sets file pointer where to write the clusters to
|
||||
\param f file pointer
|
||||
\returns current file pointer
|
||||
*/
|
||||
FILE *setFilePointer(FILE *f){return det->setFilePointer(f); };
|
||||
|
||||
/** gets file pointer where to write the clusters to
|
||||
\returns current file pointer
|
||||
*/
|
||||
FILE *getFilePointer(){return det->getFilePointer();};
|
||||
|
||||
|
||||
void setMutex(pthread_mutex_t *fmutex){det->setMutex(fmutex);};
|
||||
|
||||
private:
|
||||
analogDetector<uint16_t> *det;
|
||||
int fMode;
|
||||
int *dataSize;
|
||||
pthread_t _thread;
|
||||
char *mem;
|
||||
CircularFifo<char> *fifoFree;
|
||||
CircularFifo<char> *fifoData;
|
||||
int stop;
|
||||
int busy;
|
||||
char *data;
|
||||
int *ff;
|
||||
|
||||
static void * processData(void * ptr) {
|
||||
threadedAnalogDetector *This=((threadedAnalogDetector *)ptr);
|
||||
return This->processData();
|
||||
}
|
||||
void * processData() {
|
||||
busy=1;
|
||||
while (!stop) {
|
||||
if (fifoData->isEmpty()) {
|
||||
busy=0;
|
||||
usleep(100);
|
||||
} else {
|
||||
busy=1;
|
||||
fifoData->pop(data); //blocking!
|
||||
det->processData(data);
|
||||
fifoFree->push(data);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class multiThreadedAnalogDetector
|
||||
{
|
||||
public:
|
||||
multiThreadedAnalogDetector(analogDetector<uint16_t> *d, int n, int fs=1000) : nThreads(n), ithread(0) {
|
||||
dd[0]=d;
|
||||
if (nThreads==1)
|
||||
dd[0]->setId(100);
|
||||
else
|
||||
dd[0]->setId(0);
|
||||
for (int i=1; i<nThreads; i++) {
|
||||
dd[i]=d->Clone();
|
||||
dd[i]->setId(i);
|
||||
}
|
||||
|
||||
for (int i=0; i<nThreads; i++) {
|
||||
dets[i]=new threadedAnalogDetector(dd[i], fs);
|
||||
}
|
||||
|
||||
int nnx, nny, ns;
|
||||
int nn=dets[0]->getImageSize(nnx, nny,ns);
|
||||
image=new int[nn];
|
||||
ff=NULL;
|
||||
ped=NULL;
|
||||
}
|
||||
|
||||
~multiThreadedAnalogDetector() {
|
||||
StopThreads();
|
||||
for (int i=0; i<nThreads; i++)
|
||||
delete dets[i];
|
||||
for (int i=1; i<nThreads; i++)
|
||||
delete dd[i];
|
||||
delete [] image;
|
||||
}
|
||||
|
||||
|
||||
int setFrameMode(int fm) { int ret; for (int i=0; i<nThreads; i++) ret=dets[i]->setFrameMode(fm); return ret;};
|
||||
|
||||
int *getImage(int &nnx, int &nny, int &ns) {
|
||||
int *img;
|
||||
// int nnx, nny, ns;
|
||||
int nn=dets[0]->getImageSize(nnx, nny, ns);
|
||||
//for (i=0; i<nn; i++) image[i]=0;
|
||||
|
||||
for (int ii=0; ii<nThreads; ii++) {
|
||||
// cout << ii << " " << dets[ii]->getImageSize(nnx, nny, ns) << " " << nnx << " " << nny << " " << ns << endl;
|
||||
img=dets[ii]->getImage();
|
||||
for (int i=0; i<nn; i++) {
|
||||
if (ii==0)
|
||||
image[i]=img[i];
|
||||
else
|
||||
image[i]+=img[i];
|
||||
}
|
||||
|
||||
}
|
||||
return image;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void clearImage() {
|
||||
|
||||
for (int ii=0; ii<nThreads; ii++) {
|
||||
dets[ii]->clearImage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual void *writeImage(const char * imgname) {
|
||||
/* #ifdef SAVE_ALL */
|
||||
/* for (int ii=0; ii<nThreads; ii++) { */
|
||||
/* char tit[10000];cout << "m" <<endl; */
|
||||
/* sprintf(tit,"/scratch/int_%d.tiff",ii); */
|
||||
/* dets[ii]->writeImage(tit); */
|
||||
/* } */
|
||||
/* #endif */
|
||||
int nnx, nny, ns;
|
||||
getImage(nnx, nny, ns);
|
||||
//int nnx, nny, ns;
|
||||
int nn=dets[0]->getImageSize(nnx, nny, ns);
|
||||
float *gm=new float[nn];
|
||||
if (gm) {
|
||||
for (int ix=0; ix<nn; ix++) {
|
||||
// if (image[ix]>0) cout << ix << " " << image[ix]<< endl;
|
||||
gm[ix]=image[ix];
|
||||
}
|
||||
//cout << "image " << nnx << " " << nny << endl;
|
||||
WriteToTiff(gm,imgname ,nnx, nny);
|
||||
delete [] gm;
|
||||
} else cout << "Could not allocate float image " << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
virtual void StartThreads() {
|
||||
for (int i=0; i<nThreads; i++)
|
||||
dets[i]->StartThread();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void StopThreads() {
|
||||
for (int i=0; i<nThreads; i++)
|
||||
dets[i]->StopThread();
|
||||
|
||||
}
|
||||
|
||||
|
||||
int isBusy() {
|
||||
int ret=0, ret1;
|
||||
for (int i=0; i<nThreads; i++) {
|
||||
ret1=dets[i]->isBusy();
|
||||
ret|=ret1;
|
||||
// if (ret1) cout << "thread " << i <<" still busy " << endl;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool pushData(char* &ptr) {
|
||||
dets[ithread]->pushData(ptr);
|
||||
}
|
||||
|
||||
bool popFree(char* &ptr) {
|
||||
dets[ithread]->popFree(ptr);
|
||||
}
|
||||
|
||||
int nextThread() {
|
||||
ithread++;
|
||||
if (ithread==nThreads) ithread=0;
|
||||
return ithread;
|
||||
}
|
||||
|
||||
virtual void prepareInterpolation(int &ok){
|
||||
getFlatField(); //sum up all etas
|
||||
setFlatField(); //set etas to all detectors
|
||||
for (int i=0; i<nThreads; i++) {
|
||||
dets[i]->prepareInterpolation(ok);
|
||||
}
|
||||
}
|
||||
|
||||
virtual int *getFlatField(){
|
||||
int nb=0;
|
||||
double emi, ema;
|
||||
int *f0;
|
||||
slsInterpolation* inte=(slsInterpolation*)dets[0]->getInterpolation();
|
||||
if (inte) {
|
||||
if (inte->getFlatField(nb,emi,ema)) {
|
||||
if (ff) delete [] ff;
|
||||
ff=new int[nb*nb];
|
||||
for (int i=0; i<nThreads; i++) {
|
||||
// cout << "mtgff* ff has " << nb << " bins " << endl;
|
||||
inte=(slsInterpolation*)dets[i]->getInterpolation();
|
||||
f0=inte->getFlatField();
|
||||
if (f0) {
|
||||
// cout << "ff " << i << endl;
|
||||
for (int ib=0; ib<nb*nb; ib++) {
|
||||
if (i==0)
|
||||
ff[ib]=f0[ib];
|
||||
else
|
||||
ff[ib]+=f0[ib];
|
||||
/* if (i==0 && f0[ib]>0) */
|
||||
/* cout << i << " " << ib << " " << f0[ib] << " " << ff[ib] << endl; */
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return ff;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
virtual int *setFlatField(int *h=NULL, int nb=-1, double emin=1, double emax=0){
|
||||
//int nb=0;
|
||||
double emi, ema;
|
||||
slsInterpolation* inte=(slsInterpolation*)dets[0]->getFlatField(nb,emi,ema);
|
||||
if (inte) {
|
||||
if (h==NULL) h=ff;
|
||||
for (int i=0; i<nThreads; i++) {
|
||||
dets[i]->setFlatField(h, nb, emin, emax);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
void *writeFlatField(const char * imgname){
|
||||
|
||||
int nb=0;
|
||||
double emi, ema;
|
||||
slsInterpolation* inte=(slsInterpolation*)dets[0]->getFlatField(nb,emi,ema);
|
||||
if (inte) {
|
||||
if (getFlatField()) {
|
||||
// cout << "mtwff* ff has " << nb << " bins " << endl;
|
||||
float *gm=new float[nb*nb];
|
||||
if (gm) {
|
||||
for (int ix=0; ix<nb*nb; ix++) {
|
||||
gm[ix]=ff[ix];
|
||||
}
|
||||
WriteToTiff(gm,imgname ,nb, nb);
|
||||
delete [] gm;
|
||||
} else cout << "Could not allocate float image " << endl;
|
||||
}
|
||||
} else
|
||||
cout << "Not interpolating detector! " << endl;
|
||||
|
||||
return NULL;
|
||||
|
||||
};
|
||||
|
||||
|
||||
void *readFlatField(const char * imgname, int nb=-1, double emin=1, double emax=0){
|
||||
|
||||
int* inte=(int*)dets[0]->getFlatField(nb,emin,emax);
|
||||
if (inte) {
|
||||
uint32 nnx;
|
||||
uint32 nny;
|
||||
float *gm=ReadFromTiff(imgname, nnx, nny);
|
||||
if (ff) delete [] ff;
|
||||
if (nnx>nb) nb=nnx;
|
||||
if (nny>nb) nb=nny;
|
||||
ff=new int[nb*nb];
|
||||
|
||||
for (int ix=0; ix<nb*nb; ix++) {
|
||||
ff[ix]=gm[ix];
|
||||
}
|
||||
delete [] gm;
|
||||
return setFlatField(ff,nb,emin,emax);
|
||||
} else
|
||||
cout << "Not interpolating detector! " << endl;
|
||||
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual double *getPedestal(){
|
||||
int nx, ny;
|
||||
dets[0]->getDetectorSize(nx,ny);
|
||||
if (ped) delete [] ped;
|
||||
ped=new double[nx*ny];
|
||||
double *p0=new double[nx*ny];
|
||||
|
||||
for (int i=0; i<nThreads; i++) {
|
||||
//inte=(slsInterpolation*)dets[i]->getInterpolation(nb,emi,ema);
|
||||
p0=dets[i]->getPedestal(p0);
|
||||
if (p0) {
|
||||
for (int ib=0; ib<nx*ny; ib++) {
|
||||
ped[ib]+=p0[ib];
|
||||
}
|
||||
}
|
||||
|
||||
delete [] p0;
|
||||
}
|
||||
return ped;
|
||||
};
|
||||
|
||||
|
||||
virtual double *setPedestal(double *h=NULL){
|
||||
//int nb=0;
|
||||
|
||||
int nx, ny;
|
||||
dets[0]->getDetectorSize(nx,ny);
|
||||
if (h==NULL) h=ped;
|
||||
for (int i=0; i<nThreads; i++) {
|
||||
dets[i]->setPedestal(h);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void *writePedestal(const char * imgname){
|
||||
|
||||
int nx, ny;
|
||||
dets[0]->getDetectorSize(nx,ny);
|
||||
|
||||
getPedestal();
|
||||
float *gm=new float[nx*ny];
|
||||
if (gm) {
|
||||
for (int ix=0; ix<nx*ny; ix++) {
|
||||
gm[ix]=ped[ix];
|
||||
}
|
||||
WriteToTiff(gm,imgname ,nx, ny);
|
||||
delete [] gm;
|
||||
} else cout << "Could not allocate float image " << endl;
|
||||
|
||||
return NULL;
|
||||
|
||||
};
|
||||
|
||||
|
||||
void *readPedestal(const char * imgname, int nb=-1, double emin=1, double emax=0){
|
||||
|
||||
int nx, ny;
|
||||
dets[0]->getDetectorSize(nx,ny);
|
||||
uint32 nnx;
|
||||
uint32 nny;
|
||||
float *gm=ReadFromTiff(imgname, nnx, nny);
|
||||
if (ped) delete [] ped;
|
||||
if (nnx>nx) nx=nnx;
|
||||
if (nny>ny) ny=nny;
|
||||
ped=new double[nx*ny];
|
||||
|
||||
for (int ix=0; ix<nx*ny; ix++) {
|
||||
ped[ix]=gm[ix];
|
||||
}
|
||||
delete [] gm;
|
||||
return setPedestal();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** sets file pointer where to write the clusters to
|
||||
\param f file pointer
|
||||
\returns current file pointer
|
||||
*/
|
||||
FILE *setFilePointer(FILE *f){
|
||||
for (int i=0; i<nThreads; i++) {
|
||||
dets[i]->setFilePointer(f);
|
||||
//dets[i]->setMutex(&fmutex);
|
||||
}
|
||||
return dets[0]->getFilePointer();
|
||||
};
|
||||
|
||||
/** gets file pointer where to write the clusters to
|
||||
\returns current file pointer
|
||||
*/
|
||||
FILE *getFilePointer(){return dets[0]->getFilePointer();};
|
||||
|
||||
|
||||
|
||||
private:
|
||||
bool stop;
|
||||
const int nThreads;
|
||||
threadedAnalogDetector *dets[20];
|
||||
analogDetector<uint16_t> *dd[20];
|
||||
int ithread;
|
||||
int *image;
|
||||
int *ff;
|
||||
double *ped;
|
||||
pthread_mutex_t fmutex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
60
slsDetectorCalibration/pedestalSubtraction.h
Normal file
60
slsDetectorCalibration/pedestalSubtraction.h
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef PEDESTALSUBTRACTION_H
|
||||
#define PEDESTALSUBTRACTION_H
|
||||
|
||||
#include "MovingStat.h"
|
||||
|
||||
class pedestalSubtraction {
|
||||
/** @short class defining the pedestal subtraction based on an approximated moving average */
|
||||
public:
|
||||
/** constructor
|
||||
\param nn number of samples to calculate the moving average (defaults to 1000)
|
||||
*/
|
||||
pedestalSubtraction (int nn=1000) : stat(nn) {};
|
||||
|
||||
/** virtual destructorr
|
||||
*/
|
||||
virtual ~pedestalSubtraction() {};
|
||||
|
||||
/** clears the moving average */
|
||||
virtual void Clear() {stat.Clear();}
|
||||
|
||||
/** adds the element to the moving average
|
||||
\param val value to be added
|
||||
*/
|
||||
virtual void addToPedestal(double val){stat.Calc(val);};
|
||||
|
||||
/** returns the average value of the pedestal
|
||||
\returns mean of the moving average
|
||||
*/
|
||||
virtual double getPedestal(){return stat.Mean();};
|
||||
|
||||
/** returns the standard deviation of the moving average
|
||||
\returns standard deviation of the moving average
|
||||
*/
|
||||
virtual double getPedestalRMS(){return stat.StandardDeviation();};
|
||||
|
||||
/**sets/gets the number of samples for the moving average
|
||||
\param i number of elements for the moving average. If -1 (default) or negative, gets.
|
||||
\returns actual number of samples for the moving average
|
||||
*/
|
||||
virtual int SetNPedestals(int i=-1) {return stat.SetN(i);};
|
||||
|
||||
/**sets/gets the number of samples for the moving average
|
||||
\returns actual number of samples for the moving average
|
||||
*/
|
||||
virtual int GetNPedestals() {return stat.GetN();};
|
||||
|
||||
/** sets the moving average */
|
||||
virtual void setPedestal(double val, double rms=0, int m=-1) {stat.Set(val, rms, m);}
|
||||
|
||||
|
||||
/** sets the moving average */
|
||||
virtual void setPedestalRMS(double rms) {stat.SetRMS(rms);}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
MovingStat stat; /**< approximated moving average struct */
|
||||
|
||||
};
|
||||
#endif
|
658
slsDetectorCalibration/singlePhotonDetector.h
Normal file
658
slsDetectorCalibration/singlePhotonDetector.h
Normal file
@ -0,0 +1,658 @@
|
||||
#ifndef SINGLEPHOTONDETECTOR_H
|
||||
#define SINGLEPHOTONDETECTOR_H
|
||||
|
||||
#include "analogDetector.h"
|
||||
|
||||
#include "single_photon_hit.h"
|
||||
|
||||
|
||||
|
||||
//#define MYROOT1
|
||||
|
||||
#ifdef MYROOT1
|
||||
#include <TTree.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef EVTYPE_DEF
|
||||
#define EVTYPE_DEF
|
||||
/** enum to define the even types */
|
||||
enum eventType {
|
||||
PEDESTAL=0, /** pedestal */
|
||||
NEIGHBOUR=1, /** neighbour i.e. below threshold, but in the cluster of a photon */
|
||||
PHOTON=2, /** photon i.e. above threshold */
|
||||
PHOTON_MAX=3, /** maximum of a cluster satisfying the photon conditions */
|
||||
NEGATIVE_PEDESTAL=4, /** negative value, will not be accounted for as pedestal in order to avoid drift of the pedestal towards negative values */
|
||||
UNDEFINED_EVENT=-1 /** undefined */
|
||||
};
|
||||
#endif
|
||||
|
||||
//template <class dataType> class singlePhotonDetector :
|
||||
//public analogDetector<dataType> {
|
||||
class singlePhotonDetector :
|
||||
public analogDetector<uint16_t> {
|
||||
|
||||
/** @short class to perform pedestal subtraction etc. and find single photon clusters for an analog detector */
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param d detector data structure to be used
|
||||
\param csize cluster size (should be an odd number). Defaults to 3
|
||||
\param nsigma number of rms to discriminate from the noise. Defaults to 5
|
||||
\param sign 1 if photons are positive, -1 if negative
|
||||
\param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none
|
||||
\param nped number of samples for pedestal averaging
|
||||
\param nd number of dark frames to average as pedestals without photon discrimination at the beginning of the measurement
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
singlePhotonDetector(slsDetectorData<uint16_t> *d,
|
||||
int csize=3,
|
||||
double nsigma=5,
|
||||
int sign=1,
|
||||
commonModeSubtraction *cm=NULL,
|
||||
int nped=1000,
|
||||
int nd=100, int nnx=-1, int nny=-1, double *gm=NULL) : analogDetector<uint16_t>(d, sign, cm, nped, nnx, nny, gm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), cluster(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) {
|
||||
|
||||
|
||||
|
||||
|
||||
eventMask=new eventType*[ny];
|
||||
for (int i=0; i<ny; i++) {
|
||||
eventMask[i]=new eventType[nx];
|
||||
}
|
||||
|
||||
if (ny==1)
|
||||
clusterSizeY=1;
|
||||
|
||||
// cluster=new single_photon_hit(clusterSize,clusterSizeY);
|
||||
clusters=new single_photon_hit[nx*ny];
|
||||
|
||||
cluster=clusters;
|
||||
setClusterSize(csize);
|
||||
nphTot=0;
|
||||
nphFrame=0;
|
||||
};
|
||||
/**
|
||||
destructor. Deletes the cluster structure, the pdestalSubtraction and the image array
|
||||
*/
|
||||
virtual ~singlePhotonDetector() {delete cluster; for (int i=0; i<ny; i++) delete [] eventMask[i]; delete [] eventMask; };
|
||||
|
||||
|
||||
|
||||
/**
|
||||
copy constructor
|
||||
\param orig detector to be copied
|
||||
|
||||
*/
|
||||
|
||||
singlePhotonDetector(singlePhotonDetector *orig) : analogDetector<uint16_t>(orig) {
|
||||
|
||||
nDark=orig->nDark;
|
||||
myFile=orig->myFile;
|
||||
|
||||
eventMask=new eventType*[ny];
|
||||
for (int i=0; i<ny; i++) {
|
||||
eventMask[i]=new eventType[nx];
|
||||
}
|
||||
|
||||
|
||||
nSigma=orig->nSigma;
|
||||
clusterSize=orig->clusterSize;
|
||||
clusterSizeY=orig->clusterSizeY;
|
||||
// cluster=new single_photon_hit(clusterSize,clusterSizeY);
|
||||
clusters=new single_photon_hit[nx*ny];
|
||||
|
||||
cluster=clusters;
|
||||
|
||||
setClusterSize(clusterSize);
|
||||
|
||||
quad=UNDEFINED_QUADRANT;
|
||||
tot=0;
|
||||
quadTot=0;
|
||||
gmap=orig->gmap;
|
||||
nphTot=0;
|
||||
nphFrame=0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
duplicates the detector structure
|
||||
\returns new single photon detector with same parameters
|
||||
|
||||
*/
|
||||
virtual singlePhotonDetector *Clone() {
|
||||
return new singlePhotonDetector(this);
|
||||
}
|
||||
/** sets/gets number of rms threshold to detect photons
|
||||
\param n number of sigma to be set (0 or negative gets)
|
||||
\returns actual number of sigma parameter
|
||||
*/
|
||||
double setNSigma(double n=-1){if (n>0) nSigma=n; return nSigma;}
|
||||
|
||||
/** sets/gets cluster size
|
||||
\param n cluster size to be set, (0 or negative gets). If even is incremented by 1.
|
||||
\returns actual cluster size
|
||||
*/
|
||||
int setClusterSize(int n=-1){
|
||||
if (n>0 && n!=clusterSize) {
|
||||
if (n%2==0)
|
||||
n+=1;
|
||||
clusterSize=n;
|
||||
if (cluster)
|
||||
delete cluster;
|
||||
if (ny>clusterSize)
|
||||
clusterSizeY=clusterSize;
|
||||
else
|
||||
clusterSizeY=1;
|
||||
for (int ip=0; ip<nx*ny; ip++)
|
||||
(clusters+ip)->set_cluster_size(clusterSize,clusterSizeY);
|
||||
//cluster=new single_photon_hit(clusterSize,clusterSizeY);
|
||||
}
|
||||
return clusterSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
converts the image into number of photons
|
||||
\param data pointer to data
|
||||
\param nph pointer where to add the calculated photons. If NULL, the internal image will be used
|
||||
\returns array with data converted into number of photons.
|
||||
*/
|
||||
|
||||
virtual int *getNPhotons(char *data, int *nph=NULL) {
|
||||
|
||||
nphFrame=0;
|
||||
double val;
|
||||
if (nph==NULL)
|
||||
nph=image;
|
||||
//nph=new int[nx*ny];
|
||||
|
||||
double rest[ny][nx];
|
||||
int cy=(clusterSizeY+1)/2;
|
||||
int cs=(clusterSize+1)/2;
|
||||
|
||||
int ccs=clusterSize;
|
||||
int ccy=clusterSizeY;
|
||||
|
||||
double g=1.;
|
||||
|
||||
|
||||
double tthr=thr;
|
||||
int nn=0;
|
||||
double max=0, tl=0, tr=0, bl=0,br=0, v;
|
||||
|
||||
|
||||
if (thr>=0) {
|
||||
cy=1;
|
||||
cs=1;
|
||||
ccs=1;
|
||||
ccy=1;
|
||||
}
|
||||
|
||||
if (iframe<nDark) {
|
||||
//cout << "ped " << iframe << endl;
|
||||
addToPedestal(data);
|
||||
return nph;
|
||||
} else {
|
||||
if (thr>0) {
|
||||
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
|
||||
val=subtractPedestal(data,ix,iy);
|
||||
|
||||
nn=analogDetector<uint16_t>::getNPhotons(data,ix,iy);
|
||||
nph[ix+nx*iy]+=nn;
|
||||
rest[iy][ix]=(val-nn*tthr);
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
|
||||
// for (int ix=clusterSize/2; ix<clusterSize/2-1; ix++) {
|
||||
// for (int iy=clusterSizeY/2; iy<ny-clusterSizeY/2; iy++) {
|
||||
eventMask[iy][ix]=PEDESTAL;
|
||||
max=0;
|
||||
tl=0;
|
||||
tr=0;
|
||||
bl=0;
|
||||
br=0;
|
||||
tot=0;
|
||||
quadTot=0;
|
||||
|
||||
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
|
||||
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
|
||||
if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) {
|
||||
//cluster->set_data(rest[iy+ir][ix+ic], ic, ir);
|
||||
|
||||
|
||||
v=rest[iy+ir][ix+ic];//cluster->get_data(ic,ir);
|
||||
tot+=v;
|
||||
|
||||
if (ir<=0 && ic<=0)
|
||||
bl+=v;
|
||||
if (ir<=0 && ic>=0)
|
||||
br+=v;
|
||||
if (ir>=0 && ic<=0)
|
||||
tl+=v;
|
||||
if (ir>=0 && ic>=0)
|
||||
tr+=v;
|
||||
|
||||
if (v>max) {
|
||||
max=v;
|
||||
}
|
||||
// if (ir==0 && ic==0) {
|
||||
if (v>tthr) {
|
||||
eventMask[iy][ix]=NEIGHBOUR;
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rest[iy][ix]>=max) {
|
||||
if (bl>=br && bl>=tl && bl>=tr) {
|
||||
quad=BOTTOM_LEFT;
|
||||
quadTot=bl;
|
||||
} else if (br>=bl && br>=tl && br>=tr) {
|
||||
quad=BOTTOM_RIGHT;
|
||||
quadTot=br;
|
||||
} else if (tl>=br && tl>=bl && tl>=tr) {
|
||||
quad=TOP_LEFT;
|
||||
quadTot=tl;
|
||||
} else if (tr>=bl && tr>=tl && tr>=br) {
|
||||
quad=TOP_RIGHT;
|
||||
quadTot=tr;
|
||||
}
|
||||
if (max>tthr || tot>sqrt(ccy*ccs)*tthr || quadTot>sqrt(cy*cs)*tthr) {
|
||||
eventMask[iy][ix]=PHOTON;
|
||||
nph[ix+nx*iy]++;
|
||||
nphFrame+=nph[ix+nx*iy];
|
||||
nphTot+=nph[ix+nx*iy];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nph;
|
||||
} else return getClusters(data);
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
/** finds event type for pixel and fills cluster structure. The algorithm loops only if the evenMask for this pixel is still undefined.
|
||||
if pixel or cluster around it are above threshold (nsigma*pedestalRMS) cluster is filled and pixel mask is PHOTON_MAX (if maximum in cluster) or NEIGHBOUR; If PHOTON_MAX, the elements of the cluster are also set as NEIGHBOURs in order to speed up the looping
|
||||
if below threshold the pixel is either marked as PEDESTAL (and added to the pedestal calculator) or NEGATIVE_PEDESTAL is case it's lower than -threshold, otherwise the pedestal average would drift to negative values while it should be 0.
|
||||
|
||||
/param data pointer to the data
|
||||
/param ix pixel x coordinate
|
||||
/param iy pixel y coordinate
|
||||
/param cm enable(1)/disable(0) common mode subtraction (if defined).
|
||||
/returns event type for the given pixel
|
||||
*/
|
||||
eventType getEventType(char *data, int ix, int iy, int cm=0) {
|
||||
|
||||
// eventType ret=PEDESTAL;
|
||||
double max=0, tl=0, tr=0, bl=0,br=0, v;
|
||||
// cout << iframe << endl;
|
||||
|
||||
int cy=(clusterSizeY+1)/2;
|
||||
int cs=(clusterSize+1)/2;
|
||||
double val;
|
||||
tot=0;
|
||||
quadTot=0;
|
||||
quad=UNDEFINED_QUADRANT;
|
||||
|
||||
if (iframe<nDark) {
|
||||
addToPedestal(data, ix,iy);
|
||||
return UNDEFINED_EVENT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// if (eventMask[iy][ix]==UNDEFINED) {
|
||||
|
||||
eventMask[iy][ix]=PEDESTAL;
|
||||
|
||||
|
||||
cluster->x=ix;
|
||||
cluster->y=iy;
|
||||
cluster->rms=getPedestalRMS(ix,iy);
|
||||
cluster->ped=getPedestal(ix,iy, cm);
|
||||
|
||||
|
||||
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
|
||||
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
|
||||
if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) {
|
||||
|
||||
v=subtractPedestal(data, ix+ic, iy+ir);
|
||||
|
||||
cluster->set_data(v, ic, ir);
|
||||
// v=cluster->get_data(ic,ir);
|
||||
tot+=v;
|
||||
if (ir<=0 && ic<=0)
|
||||
bl+=v;
|
||||
if (ir<=0 && ic>=0)
|
||||
br+=v;
|
||||
if (ir>=0 && ic<=0)
|
||||
tl+=v;
|
||||
if (ir>=0 && ic>=0)
|
||||
tr+=v;
|
||||
|
||||
if (v>max) {
|
||||
max=v;
|
||||
}
|
||||
if (ir==0 && ic==0) {
|
||||
if (v<-nSigma*cluster->rms)
|
||||
eventMask[iy][ix]=NEGATIVE_PEDESTAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bl>=br && bl>=tl && bl>=tr) {
|
||||
quad=BOTTOM_LEFT;
|
||||
quadTot=bl;
|
||||
} else if (br>=bl && br>=tl && br>=tr) {
|
||||
quad=BOTTOM_RIGHT;
|
||||
quadTot=br;
|
||||
} else if (tl>=br && tl>=bl && tl>=tr) {
|
||||
quad=TOP_LEFT;
|
||||
quadTot=tl;
|
||||
} else if (tr>=bl && tr>=tl && tr>=br) {
|
||||
quad=TOP_RIGHT;
|
||||
quadTot=tr;
|
||||
}
|
||||
|
||||
if (max>nSigma*cluster->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms || quadTot>cy*cs*nSigma*cluster->rms) {
|
||||
if (cluster->get_data(0,0)>=max) {
|
||||
eventMask[iy][ix]=PHOTON_MAX;
|
||||
} else {
|
||||
eventMask[iy][ix]=PHOTON;
|
||||
}
|
||||
} else if (eventMask[iy][ix]==PEDESTAL) {
|
||||
if (cm==0) {
|
||||
if (det)
|
||||
val=dataSign*det->getValue(data, ix, iy);
|
||||
else
|
||||
val=((double**)data)[iy][ix];
|
||||
addToPedestal(val,ix,iy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return eventMask[iy][ix];
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Loops in the region of interest to find the clusters
|
||||
\param data pointer to the data structure
|
||||
\returns number of clusters found
|
||||
|
||||
*/
|
||||
|
||||
int *getClusters(char *data) {
|
||||
|
||||
|
||||
int nph=0;
|
||||
double val[ny][nx];
|
||||
int cy=(clusterSizeY+1)/2;
|
||||
int cs=(clusterSize+1)/2;
|
||||
int ir, ic;
|
||||
|
||||
double max=0, tl=0, tr=0, bl=0,br=0, *v, vv;
|
||||
|
||||
if (iframe<nDark) {
|
||||
addToPedestal(data);
|
||||
return 0;
|
||||
}
|
||||
newFrame();
|
||||
for (int ix=xmin; ix<xmax; ix++) {
|
||||
for (int iy=ymin; iy<ymax; iy++) {
|
||||
|
||||
max=0;
|
||||
tl=0;
|
||||
tr=0;
|
||||
bl=0;
|
||||
br=0;
|
||||
tot=0;
|
||||
quadTot=0;
|
||||
quad=UNDEFINED_QUADRANT;
|
||||
|
||||
|
||||
|
||||
eventMask[iy][ix]=PEDESTAL;
|
||||
|
||||
|
||||
(clusters+nph)->rms=getPedestalRMS(ix,iy);
|
||||
|
||||
|
||||
|
||||
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
|
||||
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
|
||||
|
||||
if ((iy+ir)>=iy && (iy+ir)<ny && (ix+ic)>=ix && (ix+ic)<nx) {
|
||||
val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir);
|
||||
}
|
||||
|
||||
v=&(val[iy+ir][ix+ic]);
|
||||
tot+=*v;
|
||||
if (ir<=0 && ic<=0)
|
||||
bl+=*v;
|
||||
if (ir<=0 && ic>=0)
|
||||
br+=*v;
|
||||
if (ir>=0 && ic<=0)
|
||||
tl+=*v;
|
||||
if (ir>=0 && ic>=0)
|
||||
tr+=*v;
|
||||
if (*v>max) {
|
||||
max=*v;
|
||||
}
|
||||
|
||||
|
||||
if (ir==0 && ic==0) {
|
||||
if (*v<-nSigma*cluster->rms)
|
||||
eventMask[iy][ix]=NEGATIVE_PEDESTAL;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (bl>=br && bl>=tl && bl>=tr) {
|
||||
(clusters+nph)->quad=BOTTOM_LEFT;
|
||||
(clusters+nph)->quadTot=bl;
|
||||
} else if (br>=bl && br>=tl && br>=tr) {
|
||||
(clusters+nph)->quad=BOTTOM_RIGHT;
|
||||
(clusters+nph)->quadTot=br;
|
||||
} else if (tl>=br && tl>=bl && tl>=tr) {
|
||||
(clusters+nph)->quad=TOP_LEFT;
|
||||
(clusters+nph)->quadTot=tl;
|
||||
} else if (tr>=bl && tr>=tl && tr>=br) {
|
||||
(clusters+nph)->quad=TOP_RIGHT;
|
||||
(clusters+nph)->quadTot=tr;
|
||||
}
|
||||
|
||||
if (max>nSigma*cluster->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*cluster->rms) {
|
||||
if (val[iy][ix]>=max) {
|
||||
eventMask[iy][ix]=PHOTON_MAX;
|
||||
(clusters+nph)->tot=tot;
|
||||
(clusters+nph)->x=ix;
|
||||
(clusters+nph)->y=iy;
|
||||
(clusters+nph)->iframe=det->getFrameNumber(data);
|
||||
(clusters+nph)->ped=getPedestal(ix,iy,0);
|
||||
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
|
||||
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
|
||||
(clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir);
|
||||
}
|
||||
}
|
||||
nph++;
|
||||
image[iy*nx+ix]++;
|
||||
|
||||
} else {
|
||||
eventMask[iy][ix]=PHOTON;
|
||||
}
|
||||
} else if (eventMask[iy][ix]==PEDESTAL) {
|
||||
addToPedestal(data,ix,iy);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
nphFrame=nph;
|
||||
nphTot+=nph;
|
||||
//cout << nphFrame << endl;
|
||||
// cout <<"**********************************"<< endl;
|
||||
writeClusters();
|
||||
return image;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**<
|
||||
returns the total signal in a cluster
|
||||
\param size cluser size should be 1,2 or 3
|
||||
\returns cluster center if size=1, sum of the maximum quadrant if size=2, total of the cluster if size=3 or anything else
|
||||
*/
|
||||
|
||||
double getClusterTotal(int size) {
|
||||
switch (size) {
|
||||
case 1:
|
||||
return getClusterElement(0,0);
|
||||
case 2:
|
||||
return quadTot;
|
||||
default:
|
||||
return tot;
|
||||
};
|
||||
};
|
||||
|
||||
/**<
|
||||
retrurns the quadrant with maximum signal
|
||||
\returns quadrant where the cluster is located */
|
||||
|
||||
quadrant getQuadrant() {return quad;};
|
||||
|
||||
|
||||
/** returns value for cluster element in relative coordinates
|
||||
\param ic x coordinate (center is (0,0))
|
||||
\param ir y coordinate (center is (0,0))
|
||||
\returns cluster element
|
||||
*/
|
||||
double getClusterElement(int ic, int ir=0){return cluster->get_data(ic,ir);};
|
||||
|
||||
/** returns event mask for the given pixel
|
||||
\param ic x coordinate (center is (0,0))
|
||||
\param ir y coordinate (center is (0,0))
|
||||
\returns event mask enum for the given pixel
|
||||
*/
|
||||
eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];};
|
||||
|
||||
|
||||
#ifdef MYROOT1
|
||||
/** generates a tree and maps the branches
|
||||
\param tname name for the tree
|
||||
\param iFrame pointer to the frame number
|
||||
\returns returns pointer to the TTree
|
||||
*/
|
||||
TTree *initEventTree(char *tname, int *iFrame=NULL) {
|
||||
TTree* tall=new TTree(tname,tname);
|
||||
|
||||
if (iFrame)
|
||||
tall->Branch("iFrame",iFrame,"iframe/I");
|
||||
else
|
||||
tall->Branch("iFrame",&(cluster->iframe),"iframe/I");
|
||||
|
||||
tall->Branch("x",&(cluster->x),"x/I");
|
||||
tall->Branch("y",&(cluster->y),"y/I");
|
||||
char tit[100];
|
||||
sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY);
|
||||
tall->Branch("data",cluster->data,tit);
|
||||
tall->Branch("pedestal",&(cluster->ped),"pedestal/D");
|
||||
tall->Branch("rms",&(cluster->rms),"rms/D");
|
||||
tall->Branch("tot",&(cluster->tot),"tot/D");
|
||||
tall->Branch("quadTot",&(cluster->quadTot),"quadTot/D");
|
||||
tall->Branch("quad",&(cluster->quad),"quad/I");
|
||||
return tall;
|
||||
};
|
||||
#else
|
||||
/** write cluster to filer
|
||||
\param f file pointer
|
||||
*/
|
||||
void writeCluster(FILE* f){cluster->write(f);};
|
||||
|
||||
/**
|
||||
write clusters to file
|
||||
\param f file pointer
|
||||
\param clusters array of clusters structures
|
||||
\param nph number of clusters to be written to file
|
||||
|
||||
*/
|
||||
|
||||
static void writeClusters(FILE *f, single_photon_hit *clusters, int nph){for (int i=0; i<nph; i++) (clusters+i)->write(f);};
|
||||
void writeClusters(FILE *f){for (int i=0; i<nphFrame; i++) (clusters+i)->write(f);};
|
||||
void writeClusters(){if (myFile) {
|
||||
//cout << "++" << endl;
|
||||
pthread_mutex_lock(fm);
|
||||
for (int i=0; i<nphFrame; i++)
|
||||
(clusters+i)->write(myFile);
|
||||
pthread_mutex_unlock(fm);
|
||||
//cout << "--" << endl;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
virtual void processData(char *data, int *val=NULL) {
|
||||
// cout << "sp" << endl;
|
||||
switch(fMode) {
|
||||
case ePedestal:
|
||||
addToPedestal(data);
|
||||
break;
|
||||
default:
|
||||
getNPhotons(data,val);
|
||||
}
|
||||
iframe++;
|
||||
// cout << "done" << endl;
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
int nDark; /**< number of frames to be used at the beginning of the dataset to calculate pedestal without applying photon discrimination */
|
||||
eventType **eventMask; /**< matrix of event type or each pixel */
|
||||
double nSigma; /**< number of sigma parameter for photon discrimination */
|
||||
int clusterSize; /**< cluster size in the x direction */
|
||||
int clusterSizeY; /**< cluster size in the y direction i.e. 1 for strips, clusterSize for pixels */
|
||||
single_photon_hit *cluster; /**< single photon hit data structure */
|
||||
single_photon_hit *clusters; /**< single photon hit data structure */
|
||||
quadrant quad; /**< quadrant where the photon is located */
|
||||
double tot; /**< sum of the 3x3 cluster */
|
||||
double quadTot; /**< sum of the maximum 2x2cluster */
|
||||
int nphTot;
|
||||
int nphFrame;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
91
slsDetectorCalibration/single_photon_hit.h
Normal file
91
slsDetectorCalibration/single_photon_hit.h
Normal file
@ -0,0 +1,91 @@
|
||||
#ifndef SINGLE_PHOTON_HIT_H
|
||||
#define SINGLE_PHOTON_HIT_H
|
||||
|
||||
typedef double double32_t;
|
||||
typedef float float32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
#ifndef DEF_QUAD
|
||||
#define DEF_QUAD
|
||||
enum quadrant {
|
||||
TOP_LEFT=0,
|
||||
TOP_RIGHT=1,
|
||||
BOTTOM_LEFT=2,
|
||||
BOTTOM_RIGHT=3,
|
||||
UNDEFINED_QUADRANT=-1
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
class single_photon_hit {
|
||||
|
||||
/** @short Structure for a single photon hit */
|
||||
|
||||
public:
|
||||
/** constructor, instantiates the data array -- all class elements are public!
|
||||
\param nx cluster size in x direction
|
||||
\param ny cluster size in y direction (defaults to 1 for 1D detectors)
|
||||
*/
|
||||
single_photon_hit(int nx=3, int ny=3): dx(nx), dy(ny) {data=new double[dx*dy];};
|
||||
|
||||
~single_photon_hit(){delete [] data;}; /**< destructor, deletes the data array */
|
||||
|
||||
/** binary write to file of all elements of the structure, except size of the cluster
|
||||
\param myFile file descriptor
|
||||
*/
|
||||
size_t write(FILE *myFile) {
|
||||
//fwrite((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), myFile);
|
||||
if (fwrite((void*)this, 1, 3*sizeof(int), myFile))
|
||||
return fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
binary read from file of all elements of the structure, except size of the cluster. The structure is then filled with those args
|
||||
\param myFile file descriptor
|
||||
*/
|
||||
size_t read(FILE *myFile) {
|
||||
//fread((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), myFile);
|
||||
|
||||
if (fread((void*)this, 1, 3*sizeof(int), myFile))
|
||||
return fread((void*)data, 1, dx*dy*sizeof(double), myFile);
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
assign the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0)
|
||||
\param v value to be set
|
||||
\param ix coordinate x within the cluster (center is (0,0))
|
||||
\param iy coordinate y within the cluster (center is (0,0))
|
||||
*/
|
||||
void set_data(double v, int ix, int iy=0){data[(iy+dy/2)*dx+ix+dx/2]=v;};
|
||||
|
||||
void set_cluster_size(int nx, int ny) {if (nx>0) dx=nx; if (ny>0) dy=ny; delete [] data; data=new double[dx*dy];};
|
||||
void get_cluster_size(int &nx, int &ny) {nx=dx; ny=dy;};
|
||||
void get_pixel(int &x1, int &y1) {x1=x; y1=y;};
|
||||
|
||||
/**
|
||||
gets the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0)
|
||||
\param ix coordinate x within the cluster (center is (0,0))
|
||||
\param iy coordinate y within the cluster (center is (0,0))
|
||||
\returns value of the cluster element
|
||||
*/
|
||||
double get_data(int ix, int iy=0){return data[(iy+dy/2)*dx+ix+dx/2];};
|
||||
double *get_cluster() {return data;};
|
||||
|
||||
int iframe; /**< frame number */
|
||||
int x; /**< x-coordinate of the center of hit */
|
||||
int y; /**< x-coordinate of the center of hit */
|
||||
double rms; /**< noise of central pixel l -- at some point it can be removed*/
|
||||
double ped; /**< pedestal of the central pixel -- at some point it can be removed*/
|
||||
double tot; /**< sum of the 3x3 cluster */
|
||||
quadrant quad; /**< quadrant where the photon is located */
|
||||
double quadTot; /**< sum of the maximum 2x2cluster */
|
||||
int dx; /**< size of data cluster in x */
|
||||
int dy; /**< size of data cluster in y */
|
||||
double *data; /**< pointer to data */
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
103
slsDetectorCalibration/slsDetectorCalibration.doxy
Normal file
103
slsDetectorCalibration/slsDetectorCalibration.doxy
Normal file
@ -0,0 +1,103 @@
|
||||
# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
|
||||
# documentation are documented, even if no documentation was available.
|
||||
# Private class members and static file members will be hidden unless
|
||||
# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
|
||||
|
||||
EXTRACT_ALL = YES
|
||||
|
||||
# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
|
||||
# will be included in the documentation.
|
||||
|
||||
EXTRACT_PRIVATE = NO
|
||||
|
||||
|
||||
|
||||
# If the EXTRACT_STATIC tag is set to YES all static members of a file
|
||||
# will be included in the documentation.
|
||||
|
||||
EXTRACT_STATIC = YES
|
||||
|
||||
# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
|
||||
# defined locally in source files will be included in the documentation.
|
||||
# If set to NO only classes defined in header files are included.
|
||||
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
|
||||
# This flag is only useful for Objective-C code. When set to YES local
|
||||
# methods, which are defined in the implementation section but not in
|
||||
# the interface are included in the documentation.
|
||||
# If set to NO (the default) only methods in the interface are included.
|
||||
|
||||
EXTRACT_LOCAL_METHODS = YES
|
||||
|
||||
# If this flag is set to YES, the members of anonymous namespaces will be
|
||||
# extracted and appear in the documentation as a namespace called
|
||||
# 'anonymous_namespace{file}', where file will be replaced with the base
|
||||
# name of the file that contains the anonymous namespace. By default
|
||||
# anonymous namespace are hidden.
|
||||
|
||||
EXTRACT_ANON_NSPACES = NO
|
||||
|
||||
# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
|
||||
# undocumented members of documented classes, files or namespaces.
|
||||
# If set to NO (the default) these members will be included in the
|
||||
# various overviews, but no documentation section is generated.
|
||||
# This option has no effect if EXTRACT_ALL is enabled.
|
||||
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
|
||||
# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
|
||||
# undocumented classes that are normally visible in the class hierarchy.
|
||||
# If set to NO (the default) these classes will be included in the various
|
||||
# overviews. This option has no effect if EXTRACT_ALL is enabled.
|
||||
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
|
||||
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
|
||||
# friend (class|struct|union) declarations.
|
||||
# If set to NO (the default) these declarations will be included in the
|
||||
# documentation.
|
||||
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
|
||||
INTERNAL_DOCS = NO
|
||||
|
||||
SHOW_INCLUDE_FILES = NO
|
||||
|
||||
SHOW_FILES = NO
|
||||
|
||||
SHOW_NAMESPACES = NO
|
||||
|
||||
COMPACT_LATEX = YES
|
||||
|
||||
PAPER_TYPE = a4
|
||||
|
||||
PDF_HYPERLINKS = YES
|
||||
|
||||
USE_PDFLATEX = YES
|
||||
|
||||
LATEX_HIDE_INDICES = YES
|
||||
|
||||
PREDEFINED = __cplusplus
|
||||
|
||||
INPUT = analogDetector.h \
|
||||
pedestalSubtraction.h \
|
||||
MovingStat.h \
|
||||
singlePhotonDetector.h \
|
||||
interpolatingDetector.h tiffIO.h \
|
||||
single_photon_hit.h \
|
||||
dataStructures/slsDetectorData.h \
|
||||
commonModeSubtraction.h \
|
||||
RunningStat.h \
|
||||
interpolations/etaInterpolationBase.h \
|
||||
interpolations/slsInterpolation.h \
|
||||
interpolations/etaInterpolationPosXY.h \
|
||||
interpolations/linearInterpolation.h \
|
||||
interpolations/noInterpolation.h \
|
||||
interpolations/etaInterpolationGlobal.h \
|
||||
multiThreadedAnalogDetector.h
|
||||
|
||||
|
||||
OUTPUT_DIRECTORY = slsDetectorCalibrationDocs
|
||||
|
||||
#moench03Ctb10GbT1Data.h moench03TCtbData.h moench03T1CtbData.h moench03CtbData.h moench03Ctb10GbData.h moench03TCtb10GbData.h Mythen3_01_jctbData.h adcSar2_jctbData.h eigerHalfModuleData.h energyCalibration.h slsReceiverData.h gotthardModuleData.h gotthardShortModuleData.h jungfrau02Data.h jungfrau10ModuleData.h moench02Ctb10GbData.h moench02CtbData.h moench02ModuleData.h moench03CommonMode.h moenchCommonMode.h chiptestBoardData.h interpolation/etaVEL/interpolation_EtaVEL.h interpolation/etaVEL/EtaVEL.h etaVEL/iterativeEtaInterpolation.h dataStructures/moench03T1ZmqData.h
|
340
slsDetectorCalibration/slsDetectorData.h
Normal file
340
slsDetectorCalibration/slsDetectorData.h
Normal file
@ -0,0 +1,340 @@
|
||||
#ifndef SLSDETECTORDATA_H
|
||||
#define SLSDETECTORDATA_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
template <class dataType>
|
||||
class slsDetectorData {
|
||||
|
||||
protected:
|
||||
const int nx; /**< Number of pixels in the x direction */
|
||||
const int ny; /**< Number of pixels in the y direction */
|
||||
int dataSize; /**<size of the data constituting one frame */
|
||||
int **dataMap; /**< Array of size nx*ny storing the pointers to the data in the dataset (as offset)*/
|
||||
dataType **dataMask; /**< Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) */
|
||||
int **dataROIMask; /**< Array of size nx*ny 1 if channel is good (or in the ROI), 0 if bad channel (or out of ROI) */
|
||||
int *xmap;
|
||||
int *ymap;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
||||
|
||||
General slsDetectors data structure. Works for data acquired using the slsDetectorReceiver. Can be generalized to other detectors (many virtual funcs).
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param npx number of pixels in the x direction
|
||||
\param npy number of pixels in the y direction (1 for strips)
|
||||
\param dsize size of the data
|
||||
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset)
|
||||
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
|
||||
\param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
|
||||
|
||||
*/
|
||||
slsDetectorData(int npx, int npy, int dsize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), dataSize(dsize) {
|
||||
|
||||
|
||||
xmap=new int[dsize/sizeof(dataType)];
|
||||
ymap=new int[dsize/sizeof(dataType)];
|
||||
|
||||
|
||||
// if (dataMask==NULL) {
|
||||
dataMask=new dataType*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
dataMask[i] = new dataType[nx];
|
||||
}
|
||||
// }
|
||||
|
||||
// if (dataMap==NULL) {
|
||||
dataMap=new int*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
dataMap[i] = new int[nx];
|
||||
}
|
||||
// }
|
||||
// if (dataROIMask==NULL) {
|
||||
dataROIMask=new int*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
dataROIMask[i] = new int[nx];
|
||||
for (int j=0; j<nx; j++)
|
||||
dataROIMask[i][j]=1;
|
||||
}
|
||||
// }
|
||||
for (int ip=0; ip<dsize/sizeof(dataType); ip++){
|
||||
xmap[ip]=-1;
|
||||
ymap[ip]=-1;
|
||||
}
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
setDataROIMask(dROI);
|
||||
|
||||
};
|
||||
|
||||
virtual ~slsDetectorData() {
|
||||
for(int i = 0; i < ny; i++) {
|
||||
delete [] dataMap[i];
|
||||
delete [] dataMask[i];
|
||||
delete [] dataROIMask[i];
|
||||
}
|
||||
delete [] dataMap;
|
||||
delete [] dataMask;
|
||||
delete [] dataROIMask;
|
||||
delete [] xmap;
|
||||
delete [] ymap;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
defines the data map (as offset) - no error checking if datasize and offsets are compatible!
|
||||
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset). If NULL (default),the data are arranged as if read out row by row (dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);)
|
||||
*/
|
||||
void setDataMap(int **dMap=NULL) {
|
||||
|
||||
int ip=0;
|
||||
int ix, iy;
|
||||
if (dMap==NULL) {
|
||||
for (iy=0; iy<ny; iy++) {
|
||||
for (ix=0; ix<nx; ix++) {
|
||||
dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//cout << "set dmap "<< dataMap << " " << dMap << endl;
|
||||
for (iy=0; iy<ny; iy++){
|
||||
// cout << iy << endl;
|
||||
for (ix=0; ix<nx; ix++) {
|
||||
dataMap[iy][ix]=dMap[iy][ix];
|
||||
// cout << ix << " " << iy << endl;
|
||||
/*ip=dataMap[ix][iy]/sizeof(dataType);
|
||||
xmap[ip]=ix;
|
||||
ymap[ip]=iy;Annaa*/
|
||||
}
|
||||
}
|
||||
}
|
||||
for (iy=0; iy<ny; iy++){
|
||||
for (ix=0; ix<nx; ix++) {
|
||||
ip=dataMap[iy][ix]/sizeof(dataType);
|
||||
xmap[ip]=ix;
|
||||
ymap[ip]=iy;
|
||||
}
|
||||
}
|
||||
|
||||
// cout << "nx:" <<nx << " ny:" << ny << endl;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
defines the data mask i.e. the polarity of the data
|
||||
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
|
||||
|
||||
*/
|
||||
void setDataMask(dataType **dMask=NULL){
|
||||
|
||||
if (dMask!=NULL) {
|
||||
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataMask[iy][ix]=dMask[iy][ix];
|
||||
} else {
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataMask[iy][ix]=0;
|
||||
}
|
||||
};
|
||||
/**
|
||||
defines the region of interest and/or the bad channels mask
|
||||
\param dROI Array of size nx*ny. The lements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
|
||||
|
||||
*/
|
||||
void setDataROIMask(int **dROI=NULL){
|
||||
|
||||
if (dROI!=NULL) {
|
||||
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataROIMask[iy][ix]=dROI[iy][ix];
|
||||
} else {
|
||||
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataROIMask[iy][ix]=1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
Define bad channel or roi mask for a single channel
|
||||
\param ix channel x coordinate
|
||||
\param iy channel y coordinate (1 for strips)
|
||||
\param i 1 if pixel is good (or in the roi), 0 if bad
|
||||
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
|
||||
*/
|
||||
int setGood(int ix, int iy, int i=1) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) dataROIMask[iy][ix]=i; return isGood(ix,iy);};
|
||||
/**
|
||||
Define bad channel or roi mask for a single channel
|
||||
\param ix channel x coordinate
|
||||
\param iy channel y coordinate (1 for strips)
|
||||
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
|
||||
*/
|
||||
int isGood(int ix, int iy) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) return dataROIMask[iy][ix]; else return -1;};
|
||||
|
||||
/**
|
||||
Returns detector size in x,y
|
||||
\param npx reference to number of channels in x
|
||||
\param npy reference to number of channels in y (will be 1 for strips)
|
||||
\returns total number of channels
|
||||
*/
|
||||
int getDetectorSize(int &npx, int &npy){npx=nx; npy=ny; return nx*ny;};
|
||||
|
||||
/** Returns the size of the data frame */
|
||||
int getDataSize() {return dataSize;};
|
||||
|
||||
/** changes the size of the data frame */
|
||||
int setDataSize(int d) {dataSize=d; return dataSize;};
|
||||
|
||||
|
||||
virtual void getPixel(int ip, int &x, int &y) {x=xmap[ip]; y=ymap[ip];};
|
||||
|
||||
virtual dataType **getData(char *ptr, int dsize=-1) {
|
||||
|
||||
dataType **data;
|
||||
int ix,iy;
|
||||
data=new dataType*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
data[i]=new dataType[nx];
|
||||
}
|
||||
if (dsize<=0 || dsize>dataSize) dsize=dataSize;
|
||||
for (int ip=0; ip<(dsize/sizeof(dataType)); ip++) {
|
||||
getPixel(ip,ix,iy);
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
data[iy][ix]=getChannel(ptr,ix,iy);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
||||
};
|
||||
|
||||
virtual double **getImage(char *ptr, int dsize=-1) {
|
||||
|
||||
double **data;
|
||||
int ix,iy;
|
||||
data=new double*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
data[i]=new double[nx];
|
||||
}
|
||||
if (dsize<=0 || dsize>dataSize) dsize=dataSize;
|
||||
for (int ip=0; ip<(dsize/sizeof(dataType)); ip++) {
|
||||
getPixel(ip,ix,iy);
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
data[iy][ix]=getValue(ptr,ix,iy);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded.
|
||||
\param data pointer to the dataset (including headers etc)
|
||||
\param ix pixel number in the x direction
|
||||
\param iy pixel number in the y direction
|
||||
\returns data for the selected channel, with inversion if required
|
||||
|
||||
*/
|
||||
virtual dataType getChannel(char *data, int ix, int iy=0) {
|
||||
dataType m=0, d=0;
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) {
|
||||
// cout << ix << " " << iy << " " ;
|
||||
//cout << dataMap[ix][iy] << " " << (void*)data << " " << dataSize<< endl;
|
||||
m=dataMask[iy][ix];
|
||||
d=*((dataType*)(data+dataMap[iy][ix]));
|
||||
}
|
||||
return d^m;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded.
|
||||
\param data pointer to the dataset (including headers etc)
|
||||
\param ix pixel number in the x direction
|
||||
\param iy pixel number in the y direction
|
||||
\returns data for the selected channel, with inversion if required or -1 if its a missing packet
|
||||
|
||||
*/
|
||||
|
||||
virtual int getChannelwithMissingPackets(char *data, int ix, int iy) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Returns the value of the selected channel for the given dataset as double.
|
||||
\param data pointer to the dataset (including headers etc)
|
||||
\param ix pixel number in the x direction
|
||||
\param iy pixel number in the y direction
|
||||
\returns data for the selected channel, with inversion if required as double
|
||||
|
||||
*/
|
||||
virtual double getValue(char *data, int ix, int iy=0) {
|
||||
/* cout << " x "<< ix << " y"<< iy << " val " << getChannel(data, ix, iy)<< endl;*/
|
||||
return (double)getChannel(data, ix, iy);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
virtual int getFrameNumber(char *buff)=0;
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize)=0;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin)=0;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
238
slsDetectorCalibration/slsReceiverData.h
Normal file
238
slsDetectorCalibration/slsReceiverData.h
Normal file
@ -0,0 +1,238 @@
|
||||
#ifndef SLSRECEIVERDATA_H
|
||||
#define SLSRECEIVERDATA_H
|
||||
|
||||
#include "slsDetectorData.h"
|
||||
#include <cstring>
|
||||
#include <stdlib.h> // exit()
|
||||
template <class dataType>
|
||||
class slsReceiverData : public slsDetectorData<dataType> {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers.
|
||||
Inherits and implements slsDetectorData.
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param npx number of pixels in the x direction
|
||||
\param npy number of pixels in the y direction (1 for strips)
|
||||
\param np number of packets
|
||||
\param psize packets size
|
||||
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset)
|
||||
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
|
||||
\param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
|
||||
|
||||
*/
|
||||
slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData<dataType>(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded.
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
*/
|
||||
|
||||
virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata size of frame returned
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
|
||||
char *retval=NULL, *p=data;
|
||||
int dd=0;
|
||||
int fn, fnum=-1, np=0, pnum=-1;
|
||||
while (dd<=(dsize-packetSize)) {
|
||||
pnum=getPacketNumber(p);
|
||||
fn=getFrameNumber(p);
|
||||
//cout <<"fnum:"<<fn<<" pnum:"<<pnum<<" np:"<< np << "\t";
|
||||
|
||||
if (pnum<1 || pnum>nPackets) {
|
||||
//cout << "Bad packet number " << pnum << " frame "<< fn << endl;
|
||||
retval=NULL;
|
||||
np=0;
|
||||
} else if (pnum==1) {
|
||||
retval=p;
|
||||
if (np>0)
|
||||
/*cout << "*Incomplete frame number " << fnum << endl;*/
|
||||
np=0;
|
||||
fnum=fn;
|
||||
} else if (fn!=fnum) {
|
||||
if (fnum!=-1) {
|
||||
/* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/
|
||||
retval=NULL;
|
||||
}
|
||||
np=0;
|
||||
}
|
||||
p+=packetSize;
|
||||
dd+=packetSize;
|
||||
np++;
|
||||
//cout <<"fnum:"<<fn<<" pnum:"<<pnum<<" np:"<< np << "\t";
|
||||
// cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl;
|
||||
if (np==nPackets){
|
||||
if (pnum==nPackets) {
|
||||
//cprintf(BG_GREEN, "Frame Found\n");
|
||||
// cout << "Frame found!" << endl;
|
||||
break;
|
||||
} else {
|
||||
//cprintf(BG_RED, "Too many packets for this frame! fnum:%d, pnum:%d np:%d\n",fnum,pnum,np);
|
||||
cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl;//cprintf(BG_RED,"Exiting\n");exit(-1);
|
||||
retval=NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (np<nPackets) {
|
||||
if (np>0){
|
||||
//cprintf(BG_RED, "Too few packets for this frame! fnum:%d, pnum:%d np:%d\n",fnum,pnum,np);
|
||||
cout << "Too few packets for this frame! "<< fnum << " " << pnum << " " << np <<endl;//cprintf(BG_RED,"Exiting\n");exit(-1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ndata=np*packetSize;
|
||||
// cout << "return " << ndata << endl;
|
||||
return retval;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
char *data=new char[packetSize*nPackets];
|
||||
char *retval=0;
|
||||
int np=0, nd;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
while (filebin.read(data+np*packetSize,packetSize)) {
|
||||
|
||||
if (np==(nPackets-1)) {
|
||||
|
||||
retval=findNextFrame(data,nd,packetSize*nPackets);
|
||||
np=nd/packetSize;
|
||||
// cout << np << endl;
|
||||
|
||||
|
||||
if (retval==data && np==nPackets) {
|
||||
// cout << "-" << endl;
|
||||
return data;
|
||||
|
||||
} else if (np>nPackets) {
|
||||
cout << "too many packets!!!!!!!!!!" << endl;
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else if (retval!=NULL) {
|
||||
// cout << "+" << endl;;
|
||||
for (int ip=0; ip<np; ip++)
|
||||
memcpy(data+ip*packetSize,retval+ip*packetSize,packetSize);
|
||||
}
|
||||
|
||||
} else if (np>nPackets) {
|
||||
cout << "*******too many packets!!!!!!!!!!" << endl;
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else {
|
||||
// cout << "." << endl;;
|
||||
np++;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] data;
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\param fnum frame number of frame returned
|
||||
\returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& fnum) {
|
||||
char *data=new char[packetSize*nPackets];
|
||||
char *retval=0;
|
||||
int np=0, nd;
|
||||
fnum = -1;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
while (filebin.read(data+np*packetSize,packetSize)) {
|
||||
|
||||
if (np==(nPackets-1)) {
|
||||
|
||||
fnum=getFrameNumber(data); //cout << "fnum:"<<fnum<<endl;
|
||||
retval=findNextFrame(data,nd,packetSize*nPackets);
|
||||
np=nd/packetSize;
|
||||
// cout << np << endl;
|
||||
|
||||
|
||||
if (retval==data && np==nPackets) {
|
||||
// cout << "-" << endl;
|
||||
return data;
|
||||
|
||||
} else if (np>nPackets) {
|
||||
cout << "too many packets!!!!!!!!!!" << endl;
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else if (retval!=NULL) {
|
||||
// cout << "+" << endl;;
|
||||
for (int ip=0; ip<np; ip++)
|
||||
memcpy(data+ip*packetSize,retval+ip*packetSize,packetSize);
|
||||
}
|
||||
|
||||
} else if (np>nPackets) {
|
||||
cout << "*******too many packets!!!!!!!!!!" << endl;
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else {
|
||||
// cout << "." << endl;;
|
||||
np++;
|
||||
//cout<<"np:"<<np<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] data;
|
||||
return NULL;
|
||||
};
|
||||
|
||||
virtual int* readNextFramewithMissingPackets(ifstream &filebin, int& fnum) {return NULL;}
|
||||
virtual void getChannelArray(double* data, char* buffer){};
|
||||
virtual int* readNextFrameOnlyData(ifstream &filebin, int& fnum) {return NULL;};
|
||||
virtual int* decodeData(int* datain) {return NULL;};
|
||||
virtual int getPacketNumber(int x, int y) {return 0;};
|
||||
|
||||
protected:
|
||||
const int nPackets; /**<number of UDP packets constituting one frame */
|
||||
const int packetSize; /**< size of a udp packet */
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
76
slsDetectorCalibration/tiffIO.cpp
Normal file
76
slsDetectorCalibration/tiffIO.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
#include "tiffIO.h"
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
// #undef cbf_failnez
|
||||
// #define cbf_failnez(x) \
|
||||
// { \
|
||||
// int err; \
|
||||
// err = (x); \
|
||||
// if (err) { \
|
||||
// fprintf(stderr,"\nCBFlib fatal error %x \n",err); \
|
||||
// exit(-1); \
|
||||
// } \
|
||||
// }
|
||||
|
||||
void *WriteToTiff(float * imgData, const char * imgname, int nrow, int ncol){
|
||||
int sampleperpixel=1;
|
||||
// unsigned char * buff=NULL;
|
||||
tsize_t linebytes;
|
||||
cout << "--" <<endl;
|
||||
TIFF * tif = TIFFOpen(imgname,"w");
|
||||
if (tif) {
|
||||
TIFFSetField(tif,TIFFTAG_IMAGEWIDTH,ncol);
|
||||
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, nrow);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL,sampleperpixel);
|
||||
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32);
|
||||
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
|
||||
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
|
||||
|
||||
linebytes = sampleperpixel*ncol;
|
||||
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, ncol*sampleperpixel));
|
||||
for(int irow=0; irow<nrow; irow++){
|
||||
TIFFWriteScanline(tif,&imgData[irow*ncol],irow,0);
|
||||
}
|
||||
|
||||
TIFFClose(tif);
|
||||
} else
|
||||
cout << "could not open file " << imgname << " for writing " << endl;
|
||||
|
||||
return NULL;
|
||||
};
|
||||
|
||||
float *ReadFromTiff( const char * imgname, uint32 &nrow, uint32 &ncol){
|
||||
// unsigned char * buff=NULL;
|
||||
|
||||
TIFF * tif = TIFFOpen(imgname,"r");
|
||||
if (tif){
|
||||
uint32 bps;
|
||||
uint32 sampleperpixel=1;
|
||||
tsize_t linebytes;
|
||||
|
||||
uint32 imagelength;
|
||||
|
||||
TIFFGetField(tif,TIFFTAG_IMAGEWIDTH,&ncol);
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &nrow);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL,sampleperpixel);
|
||||
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, &bps);
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
|
||||
|
||||
float * imgData=new float[ncol*nrow];
|
||||
linebytes = sampleperpixel*ncol;
|
||||
// TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, ncol*sampleperpixel));
|
||||
for(int irow=0; irow<nrow; irow++){
|
||||
//tiffreadscanline(tif, buf, row);
|
||||
TIFFReadScanline(tif,&imgData[irow*ncol],irow);
|
||||
}
|
||||
|
||||
TIFFClose(tif);
|
||||
return imgData;
|
||||
} else
|
||||
cout << "could not open file " << imgname << " for reading " << endl;
|
||||
return NULL;
|
||||
};
|
||||
|
36
slsDetectorCalibration/tiffIO.h
Normal file
36
slsDetectorCalibration/tiffIO.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef MY_TIFF_IO_H
|
||||
#define MY_TIFF_IO_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
//
|
||||
//CBFlib must be installed to use this program
|
||||
//
|
||||
/*****************************************************************************/
|
||||
#include "tiffio.h"
|
||||
|
||||
#undef cbf_failnez
|
||||
#define cbf_failnez(x) \
|
||||
{ \
|
||||
int err; \
|
||||
err = (x); \
|
||||
if (err) { \
|
||||
fprintf(stderr,"\nCBFlib fatal error %x \n",err); \
|
||||
exit(-1); \
|
||||
} \
|
||||
}
|
||||
|
||||
void *WriteToTiff(float * imgData, const char * imgname, int nrow, int ncol);
|
||||
|
||||
float *ReadFromTiff( const char * imgname, uint32 &nrow, uint32 &ncol);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user