mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 23:30:03 +02:00
Merge remote branch 'slsDetectorCalibration/3.0' into 3.0
This commit is contained in:
commit
735b8ea206
2
slsDetectorCalibration/.gitignore
vendored
Normal file
2
slsDetectorCalibration/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.o
|
||||
*.*~
|
113
slsDetectorCalibration/IntMap.h
Normal file
113
slsDetectorCalibration/IntMap.h
Normal file
@ -0,0 +1,113 @@
|
||||
#ifndef INTMAP_H
|
||||
#define INTMAP_H
|
||||
#define N 60
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
|
||||
class IntMap{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
IntMap(){};
|
||||
|
||||
~IntMap(){};
|
||||
|
||||
void Init(){
|
||||
//lookup table of the output intensity for IR laser
|
||||
//measurements performed by Dominic april 2014
|
||||
//intensity[59]=intensity with 0 Optical Density
|
||||
//intensity[0]=intensity with 5.9 Optical Density
|
||||
intensity[0]=29;//5.9
|
||||
intensity[1]=21;//5.8
|
||||
intensity[2]=31;//5.7
|
||||
intensity[3]=43;//5.6
|
||||
intensity[4]=60;//5.5
|
||||
intensity[5]=91;//5.4
|
||||
intensity[6]=69;//5.3
|
||||
intensity[7]=102;//5.2
|
||||
intensity[8]=136;//5.1
|
||||
intensity[9]=196;//5.0
|
||||
intensity[10]=425;//4.9
|
||||
intensity[11]=311;//4.8
|
||||
intensity[12]=462;//4.7
|
||||
intensity[13]=653;//4.6
|
||||
intensity[14]=926;//4.5
|
||||
intensity[15]=1423;//4.4
|
||||
intensity[16]=1072;//4.3
|
||||
intensity[17]=1592;//4.2
|
||||
intensity[18]=2142;//4.1
|
||||
intensity[19]=3085;//4.0
|
||||
intensity[20]=729;//3.9
|
||||
intensity[21]=533;//3.8
|
||||
intensity[22]=793;//3.7
|
||||
intensity[23]=1121;//3.6
|
||||
intensity[24]=1588;//3.5
|
||||
intensity[25]=2439;//3.4
|
||||
intensity[26]=1842;//3.3
|
||||
intensity[27]=2730;//3.2
|
||||
intensity[28]=3663;//3.1
|
||||
intensity[29]=5271;//3.0
|
||||
intensity[30]=8102;//2.9
|
||||
intensity[31]=5933;//2.8
|
||||
intensity[32]=8789;//2.7
|
||||
intensity[33]=12350;//2.6
|
||||
intensity[34]=17358;//2.5
|
||||
intensity[35]=26300;//2.4
|
||||
intensity[36]=20029;//2.3
|
||||
intensity[37]=29414;//2.2
|
||||
intensity[38]=39202;//2.1
|
||||
intensity[39]=55724;//2.0
|
||||
intensity[40]=15697;//1.9
|
||||
intensity[41]=11541;//1.8
|
||||
intensity[42]=16976;//1.7
|
||||
intensity[43]=23866;//1.6
|
||||
intensity[44]=33478;//1.5
|
||||
intensity[45]=50567;//1.4
|
||||
intensity[46]=38552;//1.3
|
||||
intensity[47]=56394;//1.2
|
||||
intensity[48]=74897;//1.1
|
||||
intensity[49]=106023;//1.0
|
||||
intensity[50]=157384;//0.9
|
||||
intensity[51]=117677;//0.8
|
||||
intensity[52]=171101;//0.7
|
||||
intensity[53]=236386;//0.6
|
||||
intensity[54]=327248;//0.5
|
||||
intensity[55]=492781;//0.4
|
||||
intensity[56]=379641;//0.3
|
||||
intensity[57]=546927;//0.2
|
||||
intensity[58]=717203;//0.1
|
||||
intensity[59]=1000000;//0.
|
||||
return;
|
||||
};
|
||||
//_od is the total Optical Density
|
||||
int getIntensity(float _od){
|
||||
int _int(-1);
|
||||
|
||||
//these lines are to take into account rounding errors with floats
|
||||
float hun_od = 100.*_od;
|
||||
int Ihun_od = (int)round(hun_od);
|
||||
float R_od =(float) Ihun_od/10.;
|
||||
int I_od = (int)R_od;
|
||||
|
||||
if(I_od >-1 && I_od <60){
|
||||
int index=59-I_od;
|
||||
cerr<<index<<endl;
|
||||
_int=intensity[index];
|
||||
}else{
|
||||
cerr<<"Optical density out of range!"<<endl;
|
||||
}
|
||||
return _int;
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int intensity[N];
|
||||
|
||||
};
|
||||
|
||||
#endif
|
143
slsDetectorCalibration/MovingStat.h
Executable file
143
slsDetectorCalibration/MovingStat.h
Executable file
@ -0,0 +1,143 @@
|
||||
#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)
|
||||
{
|
||||
m_n = n;
|
||||
m_newM=val*n;
|
||||
if (rms<=0)
|
||||
m_newM2=val*val*n;
|
||||
else
|
||||
m_newM2=(n*rms*rms+m_newM*m_newM/n);
|
||||
}
|
||||
|
||||
|
||||
/** sets number of samples parameter
|
||||
\param i number of samples parameter to be set
|
||||
*/
|
||||
|
||||
void SetN(int i) {if (i>=1) n=i;};
|
||||
|
||||
/**
|
||||
gets number of samples parameter
|
||||
\returns actual number of samples parameter
|
||||
*/
|
||||
int GetN() {return 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
|
123
slsDetectorCalibration/Mythen3_01_jctbData.h
Normal file
123
slsDetectorCalibration/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
|
194
slsDetectorCalibration/PlotGifs.C
Normal file
194
slsDetectorCalibration/PlotGifs.C
Normal file
@ -0,0 +1,194 @@
|
||||
#include "moench03ReadData.C"
|
||||
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
TH2F *readExactImage(char *fname, int iframe=0, int frperfile,TH2F *hped=NULL) {
|
||||
ifstream filebin;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
TH2F *h2=new TH2F("h2","",400,0,400,400,0,400);
|
||||
int framen(0);
|
||||
moench03CtbData *decoder=new moench03CtbData();
|
||||
char *buff=decoder->readNextFrame(filebin);
|
||||
framen=decoder->getFrameNumber(buff);
|
||||
|
||||
int counter(0);
|
||||
|
||||
while(framen<iframe && counter<frperfile){
|
||||
buff=decoder->readNextFrame(filebin);
|
||||
framen=decoder->getFrameNumber(buff);
|
||||
cerr<<"...";
|
||||
if(framen%1000==0) cerr<<framen;
|
||||
counter++;
|
||||
}
|
||||
if(counter<frperfile){
|
||||
h2->SetName(Form("frame_%d",framen));
|
||||
h2->SetTitle(Form("frame_%d",framen));
|
||||
cout << "==" << endl;
|
||||
for (int ix=0; ix<400; ix++) {
|
||||
for (int iy=0; iy<400; iy++) {
|
||||
// cout << decoder->getDataSize() << " " << decoder->getValue(buff,ix,iy)<< endl;
|
||||
h2->SetBinContent(ix+1,iy+1,decoder->getValue(buff,ix,iy));
|
||||
// h1->SetBinContent(++ip,decoder->getValue(buff,ix,iy));
|
||||
}
|
||||
}
|
||||
if (hped) h2->Add(hped,-1);
|
||||
|
||||
}else{
|
||||
cerr<<"frame number not found"<<endl;
|
||||
}
|
||||
|
||||
return h2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
//fnamein filename: ..._f0_%d.raw
|
||||
//runmin, runmax to calculate pedestals
|
||||
//framen0, framen1 first and last frame you want to add to the gif
|
||||
//frperfile number of frames per file
|
||||
void PlotRawFrameGif(char * fnamein, int runmin, int runmax, int framen0,int framen1, int frperfile){
|
||||
cerr<<"/***********************************/"<<endl;
|
||||
cerr<<"calculating pedestals"<<endl;
|
||||
|
||||
TH2F * hp = calcPedestal(fnamein,runmin,runmax);
|
||||
int filen = (int)(framen0/frperfile);
|
||||
char fname[1000];
|
||||
sprintf(fname,fnamein,filen);
|
||||
cerr<<"/***********************************/"<<endl;
|
||||
cerr<<"retrieving frame from"<<fname<<endl;
|
||||
|
||||
int fileframe0 = framen0%frperfile;
|
||||
int fileframe1 = framen1%frperfile;
|
||||
|
||||
TImage * img = NULL;
|
||||
TH2F * hf = NULL;
|
||||
TCanvas * c1 =NULL;
|
||||
for(int fileframe=fileframe0; fileframe<fileframe1; fileframe++){
|
||||
hf=readExactImage(fname, fileframe,frperfile,hp);
|
||||
delete img;
|
||||
delete c1;
|
||||
c1 = new TCanvas("c1","",800,600);
|
||||
c1->cd();
|
||||
|
||||
hf->SetTitle(Form("Frame_%d",fileframe+framen0));
|
||||
hf->SetName(Form("Frame_%d",fileframe+framen0));
|
||||
hf->GetXaxis()->SetRangeUser(0,50);
|
||||
hf->GetXaxis()->SetTitle("Column");
|
||||
hf->GetYaxis()->SetRangeUser(240,290);
|
||||
hf->GetYaxis()->SetTitle("Row");
|
||||
hf->GetZaxis()->SetRangeUser(-50.,1300.);
|
||||
hf->SetStats(kFALSE);
|
||||
// c1->SetLogz();
|
||||
hf->Draw("colz");
|
||||
c1->Print(Form("/afs/psi/project/mythen/Marco/Pics/Fe_Raw3_%d.png",fileframe));
|
||||
img = TImage::Open(Form("/afs/psi/project/mythen/Marco/Pics/Fe_Raw3_%d.png",fileframe));
|
||||
if(fileframe<fileframe1-1){
|
||||
img->WriteImage(Form("/afs/psi/project/mythen/Marco/Pics/Fe_Raw3_%d.gif+200",fileframe1-fileframe0));
|
||||
}else{
|
||||
img->WriteImage(Form("/afs/psi/project/mythen/Marco/Pics/Fe_Raw3_%d.gif++200++",fileframe1-fileframe0));
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
/*********************************************************************/
|
||||
TProfile2D * GetHitMap(TTree * treein, int framen,double zlow, double zup){
|
||||
TProfile2D* map = new TProfile2D("map","",400,-0.5,399.5,400,-0.5,399.5,zlow,zup);
|
||||
|
||||
|
||||
int x, y, iFrame;
|
||||
double data[9];
|
||||
|
||||
TBranch * b_x = (TBranch*)treein->GetBranch("x");
|
||||
TBranch * b_y = (TBranch*)treein->GetBranch("y");
|
||||
TBranch * b_data = (TBranch*)treein->GetBranch("data");
|
||||
TBranch * b_iFrame = (TBranch*)treein->GetBranch("iFrame");
|
||||
|
||||
b_x->SetAddress(&x);
|
||||
b_y->SetAddress(&y);
|
||||
b_data->SetAddress(data);
|
||||
b_iFrame->SetAddress(&iFrame);
|
||||
|
||||
Int_t nEnt=treein->GetEntries();
|
||||
|
||||
for(Int_t i=0; i<nEnt; i++){
|
||||
b_iFrame->GetEntry(i);
|
||||
if(iFrame==framen){
|
||||
b_x->GetEntry(i);
|
||||
b_y->GetEntry(i);
|
||||
b_data->GetEntry(i);
|
||||
map->SetBinEntries(map->FindFixBin(x-1,y-1),1);
|
||||
map->SetBinEntries(map->FindFixBin(x,y-1),1);
|
||||
map->SetBinEntries(map->FindFixBin(x+1,y-1),1);
|
||||
|
||||
map->SetBinEntries(map->FindFixBin(x-1,y),1);
|
||||
map->SetBinEntries(map->FindFixBin(x,y),1);
|
||||
map->SetBinEntries(map->FindFixBin(x+1,y),1);
|
||||
|
||||
map->SetBinEntries(map->FindFixBin(x-1,y+1),1);
|
||||
map->SetBinEntries(map->FindFixBin(x,y+1),1);
|
||||
map->SetBinEntries(map->FindFixBin(x+1,y+1),1);
|
||||
|
||||
|
||||
map->SetBinContent(map->FindFixBin(x-1,y-1),data[0]);
|
||||
map->SetBinContent(map->FindFixBin(x,y-1),data[1]);
|
||||
map->SetBinContent(map->FindFixBin(x+1,y-1),data[2]);
|
||||
|
||||
map->SetBinContent(map->FindFixBin(x-1,y),data[3]);
|
||||
map->SetBinContent(map->FindFixBin(x,y),data[4]);
|
||||
map->SetBinContent(map->FindFixBin(x+1,y),data[5]);
|
||||
|
||||
map->SetBinContent(map->FindFixBin(x-1,y+1),data[6]);
|
||||
map->SetBinContent(map->FindFixBin(x,y+1),data[7]);
|
||||
map->SetBinContent(map->FindFixBin(x+1,y+1),data[8]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return map;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/** creates an infinitely looping gif from clustered data
|
||||
**/
|
||||
void PlotClusterHitMapGif(std::string filename, std::string treename,int framen0,int framen1){
|
||||
|
||||
TFile * fin = new TFile(filename.c_str(),"read");
|
||||
TTree * treein = (TTree*)fin->Get(treename.c_str());
|
||||
|
||||
TCanvas * c1 = NULL;
|
||||
|
||||
|
||||
TProfile2D* hmap = NULL;
|
||||
TImage * img = NULL;
|
||||
for(int framen=framen0; framen<framen1; framen++){
|
||||
delete c1;
|
||||
c1 = new TCanvas("c1","",800,600);
|
||||
c1->cd();
|
||||
// c1->SetLogz();
|
||||
hmap=GetHitMap(treein,framen,-50.,1300.);
|
||||
hmap->SetName(Form("Frame_%d",framen));
|
||||
hmap->SetTitle(Form("Frame_%d",framen));
|
||||
hmap->GetXaxis()->SetRangeUser(0,50);
|
||||
hmap->GetXaxis()->SetTitle("Column");
|
||||
hmap->GetYaxis()->SetRangeUser(240,290);
|
||||
hmap->GetYaxis()->SetTitle("Row");
|
||||
hmap->GetZaxis()->SetRangeUser(-50.,1300.);
|
||||
hmap->SetStats(kFALSE);
|
||||
hmap->Draw("colz");
|
||||
c1->Print(Form("/afs/psi/project/mythen/Marco/Pics/Fe_Cluster3_%d.png",framen));
|
||||
img = TImage::Open(Form("/afs/psi/project/mythen/Marco/Pics/Fe_Cluster3_%d.png",framen));
|
||||
if(framen<framen1-1){
|
||||
img->WriteImage(Form("/afs/psi/project/mythen/Marco/Pics/Fe_Cluster3_%d.gif+200",framen1-framen0));
|
||||
}else{
|
||||
img->WriteImage(Form("/afs/psi/project/mythen/Marco/Pics/Fe_Cluster3_%d.gif++200++",framen1-framen0));
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
|
||||
}
|
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;
|
||||
};
|
63
slsDetectorCalibration/adcSar2_jctbData.h
Normal file
63
slsDetectorCalibration/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/chiptestBoardData.h
Normal file
89
slsDetectorCalibration/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
|
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
|
31
slsDetectorCalibration/demoCreateTree.C
Normal file
31
slsDetectorCalibration/demoCreateTree.C
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
|
||||
//.L moenchReadData.C
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TFile *fout;
|
||||
THStack *hs2N;
|
||||
|
||||
fout=new TFile("/scratch/outfile.root","RECREATE");
|
||||
|
||||
hs2N=moenchReadData("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_12us_120V_cds_g4_f00000%04d000_0.raw","dum",0,20,1500,-500,2500,1,0.,1,159,1,159, 0,1);
|
||||
hs2N->SetName("cds_g4");
|
||||
hs2N->SetTitle("cds_g4");
|
||||
(TH2F*)(hs2N->GetHists()->At(0))->Write();
|
||||
|
||||
(TH2F*)(hs2N->GetHists()->At(1))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(2))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(3))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(4))->Write();
|
||||
|
||||
|
||||
fout->Close();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
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
|
||||
|
470
slsDetectorCalibration/eigerHalfModuleData.h
Normal file
470
slsDetectorCalibration/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
|
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
678
slsDetectorCalibration/etaVEL/EVELAlg.C
Normal file
678
slsDetectorCalibration/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/etaVEL/EtaVEL.cpp
Normal file
679
slsDetectorCalibration/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/etaVEL/EtaVEL.h
Normal file
164
slsDetectorCalibration/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/etaVEL/EtaVELTr.py
Normal file
393
slsDetectorCalibration/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]]
|
||||
|
457
slsDetectorCalibration/etaVEL/imageMacro.C
Normal file
457
slsDetectorCalibration/etaVEL/imageMacro.C
Normal file
@ -0,0 +1,457 @@
|
||||
TH2D *imageMacro(char *name) {
|
||||
|
||||
//TH2D *makeNorm(){
|
||||
|
||||
//TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta_gmap.root");
|
||||
//TH2D *hff=(TH2D*)ff.Get("imgHR");
|
||||
TFile *ff=new TFile("/mnt/moench_data/tomcat_20160528_img/img_blank_eta_nb25.root");
|
||||
// TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta_gcorr_nb25.root");
|
||||
TH2D *hff=(TH2D*)ff->Get("blankHR");
|
||||
hff->SetName("imgBlank");
|
||||
TH2D *hpixel=new TH2D("hpixel","hpixel",25,0,25,25,0,25);
|
||||
for (int ibx=10*25; ibx<hff->GetNbinsX()-10*25; ibx++) {
|
||||
for (int iby=20*25; iby<hff->GetNbinsY()-20*25; iby++) {
|
||||
hpixel->Fill((ibx-12)%25,(iby-12)%25,hff->GetBinContent(ibx+1,iby+1));
|
||||
}
|
||||
}
|
||||
hpixel->Scale(1./hpixel->GetBinContent(13,13));
|
||||
|
||||
// new TCanvas();
|
||||
// hpixel->Draw("colz");
|
||||
|
||||
// TH2D *hraw=(TH2D*)hff->Clone("hraw");
|
||||
TH2D *hpix=(TH2D*)hff->Clone("hpix");
|
||||
|
||||
for (int ibx=0; ibx<hff->GetNbinsX(); ibx++) {
|
||||
for (int iby=0; iby<hff->GetNbinsY(); iby++) {
|
||||
hpix->SetBinContent(ibx+1,iby+1,hpixel->GetBinContent(hpixel->GetXaxis()->FindBin((ibx-12)%25),hpixel->GetXaxis()->FindBin((iby-12)%25)));
|
||||
}
|
||||
}
|
||||
// return hpix;
|
||||
//}
|
||||
|
||||
//void imageMacro(char *name,TH2D *hpix=NULL){
|
||||
// hff->Divide(hpix);
|
||||
|
||||
// new TCanvas();
|
||||
// hff->Draw("colz");
|
||||
|
||||
// if (hpix==NULL)
|
||||
// hpix=makeNorm();
|
||||
TH2D *hg;
|
||||
|
||||
char nn[1000];
|
||||
if (strcmp(name,"blank")==NULL) {
|
||||
hg=hff;
|
||||
} else {
|
||||
|
||||
|
||||
sprintf(nn,"/mnt/moench_data/tomcat_20160528_img/img_%s_eta_nb25.root", name);
|
||||
// if (strcmp(name,"blank"))
|
||||
TFile *fg=new TFile(nn);
|
||||
// else
|
||||
// TFile fg=gDirectory;
|
||||
|
||||
//TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_1d_eta_gmap.root");
|
||||
//TH2D *hg=(TH2D*)fg.Get("imgHR");
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_1d_eta_nb25.root");
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_sample_eta_nb25.root");
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_1d_eta_gcorr_nb25.root");
|
||||
sprintf(nn,"%sHR",name);
|
||||
TH2D *hg=(TH2D*)fg->Get(nn);
|
||||
// hg->SetName("imgGrating");
|
||||
|
||||
//hg->Divide(hff);
|
||||
}
|
||||
if (hpix)
|
||||
hg->Divide(hpix);
|
||||
new TCanvas();
|
||||
hg->Draw("colz");
|
||||
|
||||
return hg;
|
||||
}
|
||||
|
||||
|
||||
void imageMacro(TH2D *hg){
|
||||
|
||||
Double_t imageData[200*400*25*25];
|
||||
const int nsigma=5.;
|
||||
int ip=0;
|
||||
int max=0;
|
||||
Double_t avg=0, rms=0;
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
imageData[ip]=hg->GetBinContent(ibx+1,iby+1);
|
||||
if (imageData[ip]>max) max=imageData[ip];
|
||||
// if (imageData[ip]>3000) imageData[ip]=3000.;
|
||||
avg+=((Double_t)imageData[ip])/(hg->GetNbinsY()*hg->GetNbinsX());
|
||||
rms+=((Double_t)imageData[ip])*((Double_t)imageData[ip])/(hg->GetNbinsY()*hg->GetNbinsX());
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
rms=TMath::Sqrt(rms-avg*avg);
|
||||
ip=0;
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
if (imageData[ip]>avg+nsigma*rms) imageData[ip]=avg+nsigma*rms;
|
||||
// if (imageData[ip]>3000) imageData[ip]=3000.;
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
cout << "MAXIMUM IS "<< max << endl;
|
||||
cout << "AVERAGE IS "<< avg << endl;
|
||||
cout << "RMS IS "<< rms << endl;
|
||||
|
||||
|
||||
int nbx=hg->GetNbinsX();
|
||||
int nby=hg->GetNbinsY();
|
||||
Short_t *buffer=new Short_t[nbx];
|
||||
// // cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
// // cout << "width is "<<nbx<< endl;
|
||||
// // cout << "height is "<<nby<< endl;
|
||||
sprintf(nn,"%s_HR.bin", name);
|
||||
ofstream myFile (nn, ios::out | ios::binary);
|
||||
ip=0;
|
||||
for (int iy=0; iy<nby; iy++) {
|
||||
for (int ix=0; ix<nbx; ix++) {
|
||||
buffer[ix]=imageData[ip]*65535/nsigma/avg;
|
||||
ip++;
|
||||
}
|
||||
myFile.write((char*)buffer, nbx*sizeof(Short_t));
|
||||
}
|
||||
myFile.close();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TASImage *img=new TASImage ( "img",imageData, 400*25, 200*25);// TImagePalette * palette = 0
|
||||
new TCanvas();
|
||||
img->SetImageCompression(0);
|
||||
img->SetImageQuality(TAttImage::kImgBest);
|
||||
// img->Gray(kTRUE);
|
||||
img->Draw();
|
||||
|
||||
sprintf(nn,"%s_HR.tiff", name);
|
||||
|
||||
img->WriteImage(nn, TImage::kTiff);
|
||||
|
||||
// new TCanvas();
|
||||
// hg->SetMaximum(3000);
|
||||
// hg->DrawCopy("colz");
|
||||
|
||||
|
||||
hg->Rebin2D(25,25);
|
||||
|
||||
Double_t imageDataLR[200*400];
|
||||
|
||||
ip=0; max=0;avg=0; rms=0;
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
imageDataLR[ip]=hg->GetBinContent(ibx+1,iby+1);
|
||||
if (imageDataLR[ip]>max) max=imageDataLR[ip];
|
||||
avg+=((Double_t)imageDataLR[ip])/(hg->GetNbinsY()*hg->GetNbinsX());
|
||||
rms+=((Double_t)imageDataLR[ip])*((Double_t)imageDataLR[ip])/(hg->GetNbinsY()*hg->GetNbinsX());
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
rms=TMath::Sqrt(rms-avg*avg);
|
||||
ip=0;
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
if (imageDataLR[ip]>avg+nsigma*rms) imageDataLR[ip]=avg+nsigma*rms;
|
||||
// if (imageData[ip]>3000) imageData[ip]=3000.;
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
cout << "MAXIMUM IS "<< max << endl;
|
||||
cout << "AVERAGE IS "<< avg << endl;
|
||||
cout << "RMS IS "<< rms << endl;
|
||||
|
||||
TASImage *imgLR=new TASImage ( "imgLR",imageDataLR, 400, 200);// TImagePalette * palette = 0
|
||||
new TCanvas();
|
||||
imgLR->SetImageCompression(0);
|
||||
imgLR->SetImageQuality(TAttImage::kImgBest);
|
||||
// imgLR->Gray(kTRUE);
|
||||
imgLR->Draw();
|
||||
|
||||
|
||||
sprintf(nn,"%s_LR.tiff", name);
|
||||
|
||||
imgLR->WriteImage(nn, TImage::kTiff);
|
||||
|
||||
|
||||
int nbx1=hg->GetNbinsX();
|
||||
int nby1=hg->GetNbinsY();
|
||||
Short_t *buffer1=new Short_t[nbx1];
|
||||
// // cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
// // cout << "width is "<<nbx<< endl;
|
||||
// // cout << "height is "<<nby<< endl;
|
||||
sprintf(nn,"%s_LR.bin", name);
|
||||
ofstream myFile1 (nn, ios::out | ios::binary);
|
||||
ip=0;
|
||||
for (int iy=0; iy<nby1; iy++) {
|
||||
for (int ix=0; ix<nbx1; ix++) {
|
||||
buffer1[ix]=imageDataLR[ip]*256/nsigma/avg;
|
||||
ip++;
|
||||
}
|
||||
myFile1.write((char*)buffer1, nbx1*sizeof(Short_t));
|
||||
}
|
||||
myFile1.close();
|
||||
|
||||
cout << sizeof(Short_t) << endl;
|
||||
//for grating2D the gratings are in the pixels (150-260)x(80-190)
|
||||
|
||||
|
||||
|
||||
|
||||
// // hg->Draw("colz");
|
||||
// int off=13;
|
||||
// // hg->Divide(hpix);
|
||||
// int ix,iy, sbx, sby, ibx2, iby2, sbx2, sby2;
|
||||
// TH2F *hh13b=new TH2F("hh13b","hh13b",400*24,0,400,200*24,100,300);
|
||||
// TH2F *hh13=new TH2F("hh13","hh13",400*23,0,400,200*23,100,300);
|
||||
// TH2F *hh=new TH2F("hh","hh",400*21,0,400,200*21,100,300);
|
||||
// TH2F *h1=new TH2F("h1","h1",400*23,0,400,200*23,100,300);
|
||||
// for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
// for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
// ix=(ibx-off)/25;
|
||||
// iy=(iby-off)/25;
|
||||
// sbx=(ibx-off)%25;
|
||||
// sby=(iby-off)%25;
|
||||
// sbx2=sbx-1;
|
||||
// sby2=sby-1;
|
||||
// if (sbx2<0) sbx2=0;
|
||||
// if (sby2<0) sby2=0;
|
||||
// if (sbx2>22) sbx2=22;
|
||||
// if (sby2>22) sby2=22;
|
||||
// ibx2=ix*23+(sbx2+off);
|
||||
// iby2=iy*23+(sby2+off);
|
||||
|
||||
// hh13->Fill(hh13->GetXaxis()->GetBinCenter(ibx2+1),hh13->GetYaxis()->GetBinCenter(iby2+1),hg->GetBinContent(ibx+1,iby+1));
|
||||
// // h1->Fill(h1->GetXaxis()->GetBinCenter(ibx2+1),h1->GetYaxis()->GetBinCenter(iby2+1),hpix->GetBinContent(ibx+1,iby+1));
|
||||
|
||||
// off=13;
|
||||
|
||||
// ix=(ibx-off)/25;
|
||||
// iy=(iby-off)/25;
|
||||
// sbx=(ibx-off)%25;
|
||||
// sby=(iby-off)%25;
|
||||
// sbx2=sbx-1;
|
||||
// sby2=sby-1;
|
||||
// // if (sbx2<0) sbx2=0;
|
||||
// // if (sby2<0) sby2=0;
|
||||
// ibx2=ix*24+(sbx2+off);
|
||||
// iby2=iy*24+(sby2+off);
|
||||
|
||||
// if (sbx2<0 && sby2>=0) {
|
||||
// ibx2=ix*24+(sbx2+off);
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.5*hg->GetBinContent(ibx+1,iby+1));
|
||||
// ibx2=ix*24+(sbx2+off)+1;
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.5*hg->GetBinContent(ibx+1,iby+1));
|
||||
// } else if (sby2<0 && sbx2>=0){
|
||||
// iby2=iy*24+(sby2+off);
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.5*hg->GetBinContent(ibx+1,iby+1));
|
||||
// iby2=iy*24+(sby2+off)+1;
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.5*hg->GetBinContent(ibx+1,iby+1));
|
||||
// } else if (sby2<0 && sbx2<0){
|
||||
// iby2=iy*24+(sby2+off);
|
||||
// ibx2=ix*24+(sbx2+off);
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.25*hg->GetBinContent(ibx+1,iby+1));
|
||||
// iby2=iy*24+(sby2+off)+1;
|
||||
// ibx2=ix*24+(sbx2+off);
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.25*hg->GetBinContent(ibx+1,iby+1));
|
||||
// iby2=iy*24+(sby2+off);
|
||||
// ibx2=ix*24+(sbx2+off)+1;
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.25*hg->GetBinContent(ibx+1,iby+1));
|
||||
// iby2=iy*24+(sby2+off)+1;
|
||||
// ibx2=ix*24+(sbx2+off)+1;
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.25*hg->GetBinContent(ibx+1,iby+1));
|
||||
// }else {
|
||||
|
||||
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),hg->GetBinContent(ibx+1,iby+1));
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// ix=(ibx-off)/25;
|
||||
// iy=(iby-off)/25;
|
||||
// sbx=(ibx-off)%25;
|
||||
// sby=(iby-off)%25;
|
||||
// sbx2=sbx-2;
|
||||
// sby2=sby-2;
|
||||
// if (sbx2<0) sbx2=-1;
|
||||
// if (sby2<0) sby2=-1;
|
||||
// if (sbx2>20) sbx2=-1;
|
||||
// if (sby2>20) sby2=-1;
|
||||
// ibx2=ix*21+(sbx2+off);
|
||||
// iby2=iy*21+(sby2+off);
|
||||
// if (sbx2>=0 && sby2>=0) hh->Fill(hh->GetXaxis()->GetBinCenter(ibx2+1),hh->GetYaxis()->GetBinCenter(iby2+1),hg->GetBinContent(ibx+1,iby+1));
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
// new TCanvas();
|
||||
// hg->GetXaxis()->SetRangeUser(84,87);
|
||||
// hg->GetYaxis()->SetRangeUser(120,124);
|
||||
// hg->Draw("colz");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// new TCanvas();
|
||||
// // hh->Divide(h1);
|
||||
// hh->GetXaxis()->SetRangeUser(84,87);
|
||||
// hh->GetYaxis()->SetRangeUser(120,124);
|
||||
// hh->Draw("colz");
|
||||
|
||||
|
||||
// new TCanvas();
|
||||
// // hh->Divide(h1);
|
||||
// hh13b->GetXaxis()->SetRangeUser(84,87);
|
||||
// hh13b->GetYaxis()->SetRangeUser(120,124);
|
||||
// hh13b->Draw("colz");
|
||||
|
||||
// new TCanvas();
|
||||
// // hh->Divide(h1);
|
||||
// hh13->GetXaxis()->SetRangeUser(84,87);
|
||||
// hh13->GetYaxis()->SetRangeUser(120,124);
|
||||
// hh13->Draw("colz");
|
||||
|
||||
// // //TFile fsg("/local_zfs_raid/tomcat_20160528/trees/img_sample_grating_1d_eta_gmap.root");
|
||||
// // //TH2D *hsg=(TH2D*)fsg.Get("sample_grating_1dHR");
|
||||
// // TFile fsg("/local_zfs_raid/tomcat_20160528/trees/img_sample_grating_1d_eta.root");
|
||||
// // TH2D *hsg=(TH2D*)fsg.Get("imgHR");
|
||||
// // hsg->SetName("imgGratingSample");
|
||||
|
||||
|
||||
// // hsg->Divide(hpix);
|
||||
|
||||
// // Double_t nf=hff->Integral(100,hff->GetNbinsX()-100,hff->GetYaxis()->FindBin(130), hff->GetYaxis()->FindBin(140))/((hff->GetNbinsX()-200)*250);
|
||||
// // hff->Scale(1./nf);
|
||||
|
||||
// // // hg->Divide(hff);
|
||||
// // //hsg->Divide(hff);
|
||||
|
||||
// // Double_t ng=hg->Integral(100,hg->GetNbinsX()-100,hg->GetYaxis()->FindBin(130), hg->GetYaxis()->FindBin(140))/((hg->GetNbinsX()-200)*250);
|
||||
// // Double_t nsg=hsg->Integral(100,hsg->GetNbinsX()-100,hsg->GetYaxis()->FindBin(130), hsg->GetYaxis()->FindBin(140))/((hsg->GetNbinsX()-200)*250);
|
||||
|
||||
// // hg->Scale(1/ng);
|
||||
// // hsg->Scale(1/nsg);
|
||||
|
||||
// // // new TCanvas();
|
||||
// // // hg->SetMaximum(1.);
|
||||
// // // hg->Draw("colz");
|
||||
// // // new TCanvas();
|
||||
// // // hsg->SetMaximum(1.);
|
||||
// // // hsg->Draw("colz");
|
||||
|
||||
// // // TH1D *pg=hg->ProjectionX("pg",hg->GetYaxis()->FindBin(174.5)+1,hg->GetYaxis()->FindBin(175.5));
|
||||
// // // TH1D *psg=hsg->ProjectionX("psg",hsg->GetYaxis()->FindBin(174.5)+1,hsg->GetYaxis()->FindBin(175.5));
|
||||
// // // psg->SetLineColor(2);
|
||||
// // // new TCanvas();
|
||||
|
||||
// // // pg->Draw("l");
|
||||
// // // psg->Draw("l same");
|
||||
|
||||
// // int nbx=hg->GetNbinsX();
|
||||
// // int nby=hg->GetNbinsY();
|
||||
// // char buffer[nbx];
|
||||
// // cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
// // cout << "width is "<<nbx<< endl;
|
||||
// // cout << "height is "<<nby<< endl;
|
||||
// // ofstream myFile ("grating_1d.bin", ios::out | ios::binary);
|
||||
// // for (int iy=0; iy<nby; iy++) {
|
||||
// // for (int ix=0; ix<nbx; ix++) {
|
||||
// // buffer[ix]=hg->GetBinContent(ix+1,iy+1);
|
||||
// // }
|
||||
// // myFile.write((char*)buffer, nbx*sizeof(char));
|
||||
// // }
|
||||
// // myFile.close();
|
||||
|
||||
|
||||
// // nbx=hsg->GetNbinsX();
|
||||
// // nby=hsg->GetNbinsY();
|
||||
|
||||
// // cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
// // cout << "width is "<<nbx<< endl;
|
||||
// // cout << "height is "<<nby<< endl;
|
||||
|
||||
// // ofstream myFile1 ("sample_grating_1d.bin", ios::out | ios::binary);
|
||||
// // for (int iy=0; iy<nby; iy++) {
|
||||
// // for (int ix=0; ix<nbx; ix++) {
|
||||
// // buffer[ix]=hsg->GetBinContent(ix+1,iy+1);
|
||||
// // }
|
||||
// // myFile1.write((char*)buffer, nbx*sizeof(char));
|
||||
// // }
|
||||
// // myFile1.close();
|
||||
|
||||
// // NAME
|
||||
// // raw2tiff - create a TIFF file from a raw data
|
||||
|
||||
// // SYNOPSIS
|
||||
// // raw2tiff [ options ] input.raw output.tif
|
||||
|
||||
// // DESCRIPTION
|
||||
// // raw2tiff converts a raw byte sequence into TIFF. By default, the TIFF image is created with data samples packed (PlanarConfiguration=1), compressed with the PackBits algorithm (Compression=32773),
|
||||
// // and with each strip no more than 8 kilobytes. These characteristics can overridden, or explicitly specified with the options described below.
|
||||
|
||||
// // OPTIONS
|
||||
// // -H number
|
||||
// // size of input image file header in bytes (0 by default). This amount of data just will be skipped from the start of file while reading.
|
||||
|
||||
// // -w number
|
||||
// // width of input image in pixels (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// // -l number
|
||||
// // length of input image in lines (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// // -b number
|
||||
// // number of bands in input image (1 by default).
|
||||
|
||||
// // -d data_type
|
||||
// // type of samples in input image, where data_type may be:
|
||||
// // byte 8-bit unsigned integer (default),
|
||||
// // short 16-bit unsigned integer,
|
||||
// // long 32-bit unsigned integer,
|
||||
// // sbyte 8-bit signed integer,
|
||||
// // sshort 16-bit signed integer,
|
||||
// // slong 32-bit signed integer,
|
||||
// // float 32-bit IEEE floating point,
|
||||
// // double 64-bit IEEE floating point.
|
||||
|
||||
// // -i config
|
||||
// // type of samples interleaving in input image, where config may be:
|
||||
// // pixel pixel interleaved data (default),
|
||||
// // band band interleaved data.
|
||||
|
||||
// // -p photo
|
||||
// // photometric interpretation (color space) of the input image, where photo may be:
|
||||
// // miniswhite white color represented with 0 value,
|
||||
// // minisblack black color represented with 0 value (default),
|
||||
// // rgb image has RGB color model,
|
||||
// // cmyk image has CMYK (separated) color model,
|
||||
// // ycbcr image has YCbCr color model,
|
||||
// // cielab image has CIE L*a*b color model,
|
||||
// // icclab image has ICC L*a*b color model,
|
||||
// // itulab image has ITU L*a*b color model.
|
||||
|
||||
// // -s swap bytes fetched from the input file.
|
||||
|
||||
// // -L input data has LSB2MSB bit order (default).
|
||||
|
||||
// // -M input data has MSB2LSB bit order.
|
||||
|
||||
// // -c Specify a compression scheme to use when writing image data: -c none for no compression, -c packbits for the PackBits compression algorithm (the default), -c jpeg for the baseline JPEG compres-
|
||||
// // sion algorithm, -c zip for the Deflate compression algorithm, and -c lzw for Lempel-Ziv & Welch.
|
||||
|
||||
// // -r number
|
||||
// // Write data with a specified number of rows per strip; by default the number of rows/strip is selected so that each strip is approximately 8 kilobytes.
|
||||
// //width is 10000
|
||||
// //height is 5000
|
||||
|
||||
|
||||
}
|
185
slsDetectorCalibration/etaVEL/imageMacroG2D.C
Normal file
185
slsDetectorCalibration/etaVEL/imageMacroG2D.C
Normal file
@ -0,0 +1,185 @@
|
||||
{
|
||||
TColor::InitializeColors();
|
||||
const Int_t NRGBs = 5;
|
||||
const Int_t NCont = 255;//90;
|
||||
|
||||
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
|
||||
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
|
||||
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
|
||||
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
|
||||
Double_t gray[NRGBs] = { 1., 0.34, 0.61, 0.84, 1.00};
|
||||
Double_t zero[NRGBs] = { 0., 0.0,0.0, 0.0, 0.00};
|
||||
//TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
|
||||
TColor::CreateGradientColorTable(NRGBs, stops, gray, gray, gray, NCont);
|
||||
|
||||
gStyle->SetNumberContours(NCont);
|
||||
|
||||
gStyle->SetPadTopMargin(0);
|
||||
gStyle->SetPadRightMargin(0);
|
||||
gStyle->SetPadBottomMargin(0);
|
||||
gStyle->SetPadLeftMargin(0);
|
||||
|
||||
|
||||
|
||||
gROOT->ForceStyle();
|
||||
|
||||
// TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta.root");
|
||||
// TH2D *hff=(TH2D*)ff.Get("imgHR");
|
||||
TFile ff("/mnt/moench_data/tomcat_20160528_img/img_blank_eta_nb25.root");
|
||||
TH2D *hff=(TH2D*)ff.Get("blankHR");
|
||||
hff->SetName("imgBlank");
|
||||
TH2D *hpixel=new TH2D("hpixel","hpixel",25,0,25,25,0,25);
|
||||
for (int ibx=10*25; ibx<hff->GetNbinsX()-10*25; ibx++) {
|
||||
for (int iby=20*25; iby<hff->GetNbinsY()-20*25; iby++) {
|
||||
hpixel->Fill((ibx-12)%25,(iby-12)%25,hff->GetBinContent(ibx+1,iby+1));
|
||||
}
|
||||
}
|
||||
hpixel->Scale(1./hpixel->GetBinContent(13,13));
|
||||
|
||||
// new TCanvas();
|
||||
// hpixel->Draw("colz");
|
||||
|
||||
TH2D *hraw=(TH2D*)hff->Clone("hraw");
|
||||
TH2D *hpix=(TH2D*)hff->Clone("hpix");
|
||||
|
||||
for (int ibx=0; ibx<hff->GetNbinsX(); ibx++) {
|
||||
for (int iby=0; iby<hff->GetNbinsY(); iby++) {
|
||||
hpix->SetBinContent(ibx+1,iby+1,hpixel->GetBinContent(hpixel->GetXaxis()->FindBin((ibx-12)%25),hpixel->GetXaxis()->FindBin((iby-12)%25)));
|
||||
}
|
||||
}
|
||||
|
||||
hff->Divide(hpix);
|
||||
|
||||
// new TCanvas();
|
||||
// hff->Draw("colz");
|
||||
|
||||
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_2d_eta.root");
|
||||
// TH2D *hg=(TH2D*)fg.Get("imgHR");
|
||||
TFile fg("/mnt/moench_data/tomcat_20160528_img/img_grating_2d_eta_nb25.root");
|
||||
TH2D *hg=(TH2D*)fg.Get("grating_2dHR");
|
||||
hg->SetName("imgGrating");
|
||||
|
||||
hg->Divide(hpix);
|
||||
|
||||
|
||||
|
||||
Double_t nf=hff->Integral(100,hff->GetNbinsX()-100,hff->GetYaxis()->FindBin(130), hff->GetYaxis()->FindBin(140))/((hff->GetNbinsX()-200)*250);
|
||||
hff->Scale(1./nf);
|
||||
|
||||
// hg->Divide(hff);
|
||||
//hsg->Divide(hff);
|
||||
|
||||
Double_t ng=hg->Integral(100,hg->GetNbinsX()-100,hg->GetYaxis()->FindBin(130), hg->GetYaxis()->FindBin(140))/((hg->GetNbinsX()-200)*250);
|
||||
|
||||
hg->Scale(1/ng);
|
||||
|
||||
new TCanvas("c1","c1",800,800);
|
||||
hg->SetMaximum(2.);
|
||||
Double_t xmin=hg->GetXaxis()->GetXmin();
|
||||
Double_t xmax=hg->GetXaxis()->GetXmax();
|
||||
Double_t ymin=hg->GetYaxis()->GetXmin();
|
||||
Double_t ymax=hg->GetYaxis()->GetXmax();
|
||||
hg->SetTitle(";mm;mm;Normalized intensity (a.u.)");
|
||||
hg->GetXaxis()->Set(hg->GetXaxis()->GetNbins(),xmin*0.025-180.*0.025+0.1,xmax*0.025-180.*0.025+0.1);
|
||||
hg->GetYaxis()->Set(hg->GetYaxis()->GetNbins(),ymin*0.025-180.*0.025-1.5,ymax*0.025-180*0.025-1.5);
|
||||
|
||||
hg->GetXaxis()->SetRangeUser(0,0.5);
|
||||
hg->GetYaxis()->SetRangeUser(0,0.5);
|
||||
|
||||
hg->Draw("col");
|
||||
hg->SetStats(kFALSE);
|
||||
// new TCanvas();
|
||||
// hsg->SetMaximum(1.);
|
||||
// hsg->Draw("colz");
|
||||
|
||||
// TH1D *pg=hg->ProjectionX("pg",hg->GetYaxis()->FindBin(174.5)+1,hg->GetYaxis()->FindBin(175.5));
|
||||
// TH1D *psg=hsg->ProjectionX("psg",hsg->GetYaxis()->FindBin(174.5)+1,hsg->GetYaxis()->FindBin(175.5));
|
||||
// psg->SetLineColor(2);
|
||||
// new TCanvas();
|
||||
|
||||
// pg->Draw("l");
|
||||
// psg->Draw("l same");
|
||||
|
||||
int nbx=hg->GetNbinsX();
|
||||
int nby=hg->GetNbinsY();
|
||||
char buffer[nbx];
|
||||
cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
cout << "width is "<<nbx<< endl;
|
||||
cout << "height is "<<nby<< endl;
|
||||
ofstream myFile ("grating_2d.bin", ios::out | ios::binary);
|
||||
for (int iy=0; iy<nby; iy++) {
|
||||
for (int ix=0; ix<nbx; ix++) {
|
||||
buffer[ix]=hg->GetBinContent(ix+1,iy+1);
|
||||
}
|
||||
myFile.write((char*)buffer, nbx*sizeof(char));
|
||||
}
|
||||
myFile.close();
|
||||
|
||||
|
||||
// NAME
|
||||
// raw2tiff - create a TIFF file from a raw data
|
||||
|
||||
// SYNOPSIS
|
||||
// raw2tiff [ options ] input.raw output.tif
|
||||
|
||||
// DESCRIPTION
|
||||
// raw2tiff converts a raw byte sequence into TIFF. By default, the TIFF image is created with data samples packed (PlanarConfiguration=1), compressed with the PackBits algorithm (Compression=32773),
|
||||
// and with each strip no more than 8 kilobytes. These characteristics can overridden, or explicitly specified with the options described below.
|
||||
|
||||
// OPTIONS
|
||||
// -H number
|
||||
// size of input image file header in bytes (0 by default). This amount of data just will be skipped from the start of file while reading.
|
||||
|
||||
// -w number
|
||||
// width of input image in pixels (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// -l number
|
||||
// length of input image in lines (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// -b number
|
||||
// number of bands in input image (1 by default).
|
||||
|
||||
// -d data_type
|
||||
// type of samples in input image, where data_type may be:
|
||||
// byte 8-bit unsigned integer (default),
|
||||
// short 16-bit unsigned integer,
|
||||
// long 32-bit unsigned integer,
|
||||
// sbyte 8-bit signed integer,
|
||||
// sshort 16-bit signed integer,
|
||||
// slong 32-bit signed integer,
|
||||
// float 32-bit IEEE floating point,
|
||||
// double 64-bit IEEE floating point.
|
||||
|
||||
// -i config
|
||||
// type of samples interleaving in input image, where config may be:
|
||||
// pixel pixel interleaved data (default),
|
||||
// band band interleaved data.
|
||||
|
||||
// -p photo
|
||||
// photometric interpretation (color space) of the input image, where photo may be:
|
||||
// miniswhite white color represented with 0 value,
|
||||
// minisblack black color represented with 0 value (default),
|
||||
// rgb image has RGB color model,
|
||||
// cmyk image has CMYK (separated) color model,
|
||||
// ycbcr image has YCbCr color model,
|
||||
// cielab image has CIE L*a*b color model,
|
||||
// icclab image has ICC L*a*b color model,
|
||||
// itulab image has ITU L*a*b color model.
|
||||
|
||||
// -s swap bytes fetched from the input file.
|
||||
|
||||
// -L input data has LSB2MSB bit order (default).
|
||||
|
||||
// -M input data has MSB2LSB bit order.
|
||||
|
||||
// -c Specify a compression scheme to use when writing image data: -c none for no compression, -c packbits for the PackBits compression algorithm (the default), -c jpeg for the baseline JPEG compres-
|
||||
// sion algorithm, -c zip for the Deflate compression algorithm, and -c lzw for Lempel-Ziv & Welch.
|
||||
|
||||
// -r number
|
||||
// Write data with a specified number of rows per strip; by default the number of rows/strip is selected so that each strip is approximately 8 kilobytes.
|
||||
//width is 10000
|
||||
//height is 5000
|
||||
|
||||
|
||||
}
|
173
slsDetectorCalibration/etaVEL/imageMacroSample.C
Normal file
173
slsDetectorCalibration/etaVEL/imageMacroSample.C
Normal file
@ -0,0 +1,173 @@
|
||||
{
|
||||
// TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta.root");
|
||||
// TH2D *hff=(TH2D*)ff.Get("imgHR");
|
||||
// TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta_gmap_v2.root");
|
||||
// TH2D *hff=(TH2D*)ff.Get("blankHR");
|
||||
// hff->SetName("imgBlank");
|
||||
// TH2D *hpixel=new TH2D("hpixel","hpixel",25,0,25,25,0,25);
|
||||
// for (int ibx=10*25; ibx<hff->GetNbinsX()-10*25; ibx++) {
|
||||
// for (int iby=20*25; iby<hff->GetNbinsY()-20*25; iby++) {
|
||||
// hpixel->Fill((ibx-12)%25,(iby-12)%25,hff->GetBinContent(ibx+1,iby+1));
|
||||
// }
|
||||
// }
|
||||
// hpixel->Scale(1./hpixel->GetBinContent(13,13));
|
||||
|
||||
// // new TCanvas();
|
||||
// // hpixel->Draw("colz");
|
||||
|
||||
// TH2D *hraw=(TH2D*)hff->Clone("hraw");
|
||||
// TH2D *hpix=(TH2D*)hff->Clone("hpix");
|
||||
|
||||
// for (int ibx=0; ibx<hff->GetNbinsX(); ibx++) {
|
||||
// for (int iby=0; iby<hff->GetNbinsY(); iby++) {
|
||||
// hpix->SetBinContent(ibx+1,iby+1,hpixel->GetBinContent(hpixel->GetXaxis()->FindBin((ibx-12)%25),hpixel->GetXaxis()->FindBin((iby-12)%25)));
|
||||
// }
|
||||
// }
|
||||
|
||||
// hff->Divide(hpix);
|
||||
|
||||
// Double_t nf=hff->Integral(100,hff->GetNbinsX()-100,hff->GetYaxis()->FindBin(130), hff->GetYaxis()->FindBin(140))/((hff->GetNbinsX()-200)*250);
|
||||
// hff->Scale(1./nf);
|
||||
|
||||
// new TCanvas();
|
||||
// hff->Draw("colz");
|
||||
|
||||
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_2d_eta.root");
|
||||
// TH2D *hg=(TH2D*)fg.Get("imgHR");
|
||||
TFile fg("/mnt/moench_data/tomcat_20160528_img/img_sample_eta_gmap_v2.root");
|
||||
TH2D *hg=(TH2D*)fg.Get("sampleHR");
|
||||
hg->SetName("imgSample");
|
||||
|
||||
// hg->Divide(hpix);
|
||||
|
||||
|
||||
|
||||
|
||||
// hg->Divide(hff);
|
||||
//hsg->Divide(hff);
|
||||
|
||||
Double_t ng=hg->Integral(100,hg->GetNbinsX()-100,hg->GetYaxis()->FindBin(130), hg->GetYaxis()->FindBin(140))/((hg->GetNbinsX()-200)*250);
|
||||
|
||||
hg->Scale(1/ng);
|
||||
|
||||
// new TCanvas();
|
||||
// hsg->SetMaximum(1.);
|
||||
// hsg->Draw("colz");
|
||||
|
||||
// TH1D *pg=hg->ProjectionX("pg",hg->GetYaxis()->FindBin(174.5)+1,hg->GetYaxis()->FindBin(175.5));
|
||||
// TH1D *psg=hsg->ProjectionX("psg",hsg->GetYaxis()->FindBin(174.5)+1,hsg->GetYaxis()->FindBin(175.5));
|
||||
// psg->SetLineColor(2);
|
||||
// new TCanvas();
|
||||
|
||||
// pg->Draw("l");
|
||||
// psg->Draw("l same");
|
||||
TH2D *hpixel1=new TH2D("hpixel1","hpixel1",25,0,25,25,0,25);
|
||||
for (int ibx=10*25; ibx<35*25; ibx++) {
|
||||
for (int iby=25*25; iby<50*25; iby++) {
|
||||
hpixel1->Fill((ibx-12)%25,(iby-12)%25,hg->GetBinContent(ibx+1,iby+1));
|
||||
}
|
||||
}
|
||||
hpixel1->Scale(1./hpixel1->GetBinContent(13,13));
|
||||
|
||||
// new TCanvas();
|
||||
// hpixel->Draw("colz");
|
||||
|
||||
TH2D *hpix1=(TH2D*)hg->Clone("hpix1");
|
||||
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
hpix1->SetBinContent(ibx+1,iby+1,hpixel1->GetBinContent(hpixel1->GetXaxis()->FindBin((ibx-12)%25),hpixel1->GetXaxis()->FindBin((iby-12)%25)));
|
||||
}
|
||||
}
|
||||
|
||||
hg->Divide(hpix1);
|
||||
|
||||
new TCanvas();
|
||||
hg->SetMaximum(4);
|
||||
hg->SetMinimum(0.5);
|
||||
hg->Draw("colz");
|
||||
|
||||
|
||||
int nbx=hg->GetNbinsX();
|
||||
int nby=hg->GetNbinsY();
|
||||
char buffer[nbx];
|
||||
cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
cout << "width is "<<nbx<< endl;
|
||||
cout << "height is "<<nby<< endl;
|
||||
ofstream myFile ("sample.bin", ios::out | ios::binary);
|
||||
for (int iy=0; iy<nby; iy++) {
|
||||
for (int ix=0; ix<nbx; ix++) {
|
||||
buffer[ix]=hg->GetBinContent(ix+1,iy+1);
|
||||
}
|
||||
myFile.write((char*)buffer, nbx*sizeof(char));
|
||||
}
|
||||
myFile.close();
|
||||
|
||||
|
||||
// NAME
|
||||
// raw2tiff - create a TIFF file from a raw data
|
||||
|
||||
// SYNOPSIS
|
||||
// raw2tiff [ options ] input.raw output.tif
|
||||
|
||||
// DESCRIPTION
|
||||
// raw2tiff converts a raw byte sequence into TIFF. By default, the TIFF image is created with data samples packed (PlanarConfiguration=1), compressed with the PackBits algorithm (Compression=32773),
|
||||
// and with each strip no more than 8 kilobytes. These characteristics can overridden, or explicitly specified with the options described below.
|
||||
|
||||
// OPTIONS
|
||||
// -H number
|
||||
// size of input image file header in bytes (0 by default). This amount of data just will be skipped from the start of file while reading.
|
||||
|
||||
// -w number
|
||||
// width of input image in pixels (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// -l number
|
||||
// length of input image in lines (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// -b number
|
||||
// number of bands in input image (1 by default).
|
||||
|
||||
// -d data_type
|
||||
// type of samples in input image, where data_type may be:
|
||||
// byte 8-bit unsigned integer (default),
|
||||
// short 16-bit unsigned integer,
|
||||
// long 32-bit unsigned integer,
|
||||
// sbyte 8-bit signed integer,
|
||||
// sshort 16-bit signed integer,
|
||||
// slong 32-bit signed integer,
|
||||
// float 32-bit IEEE floating point,
|
||||
// double 64-bit IEEE floating point.
|
||||
|
||||
// -i config
|
||||
// type of samples interleaving in input image, where config may be:
|
||||
// pixel pixel interleaved data (default),
|
||||
// band band interleaved data.
|
||||
|
||||
// -p photo
|
||||
// photometric interpretation (color space) of the input image, where photo may be:
|
||||
// miniswhite white color represented with 0 value,
|
||||
// minisblack black color represented with 0 value (default),
|
||||
// rgb image has RGB color model,
|
||||
// cmyk image has CMYK (separated) color model,
|
||||
// ycbcr image has YCbCr color model,
|
||||
// cielab image has CIE L*a*b color model,
|
||||
// icclab image has ICC L*a*b color model,
|
||||
// itulab image has ITU L*a*b color model.
|
||||
|
||||
// -s swap bytes fetched from the input file.
|
||||
|
||||
// -L input data has LSB2MSB bit order (default).
|
||||
|
||||
// -M input data has MSB2LSB bit order.
|
||||
|
||||
// -c Specify a compression scheme to use when writing image data: -c none for no compression, -c packbits for the PackBits compression algorithm (the default), -c jpeg for the baseline JPEG compres-
|
||||
// sion algorithm, -c zip for the Deflate compression algorithm, and -c lzw for Lempel-Ziv & Welch.
|
||||
|
||||
// -r number
|
||||
// Write data with a specified number of rows per strip; by default the number of rows/strip is selected so that each strip is approximately 8 kilobytes.
|
||||
//width is 10000
|
||||
//height is 5000
|
||||
|
||||
|
||||
}
|
3109
slsDetectorCalibration/etaVEL/interpolationMacro.C
Normal file
3109
slsDetectorCalibration/etaVEL/interpolationMacro.C
Normal file
File diff suppressed because it is too large
Load Diff
52
slsDetectorCalibration/etaVEL/interpolation_EtaVEL.h
Normal file
52
slsDetectorCalibration/etaVEL/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
|
134
slsDetectorCalibration/etaVEL/interpolation_etaVEL.cpp
Normal file
134
slsDetectorCalibration/etaVEL/interpolation_etaVEL.cpp
Normal file
@ -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);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
224
slsDetectorCalibration/etaVEL/slsInterpolation.h
Normal file
224
slsDetectorCalibration/etaVEL/slsInterpolation.h
Normal file
@ -0,0 +1,224 @@
|
||||
#ifndef SLS_INTERPOLATION_H
|
||||
#define SLS_INTERPOLATION_H
|
||||
|
||||
#include <TObject.h>
|
||||
#include <TTree.h>
|
||||
#include <TH2F.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
|
||||
|
||||
class slsInterpolation : public TObject{
|
||||
|
||||
public:
|
||||
slsInterpolation(int nx=40, int ny=160, int ns=25) :nPixelsX(nx), nPixelsY(ny), nSubPixels(ns) {hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny);};
|
||||
|
||||
//create eta distribution, eta rebinnining etc.
|
||||
//returns flat field image
|
||||
virtual void prepareInterpolation(int &ok)=0;
|
||||
|
||||
//create interpolated image
|
||||
//returns interpolated image
|
||||
virtual TH2F *getInterpolatedImage(){return hint;};
|
||||
//return position inside the pixel for the given photon
|
||||
virtual void getInterpolatedPosition(Int_t x, Int_t y, Double_t *data, Double_t &int_x, Double_t &int_y)=0;
|
||||
|
||||
TH2F *addToImage(Double_t int_x, Double_t int_y){hint->Fill(int_x, int_y); return hint;};
|
||||
|
||||
|
||||
|
||||
virtual int addToFlatField(Double_t *cluster, Double_t &etax, Double_t &etay)=0;
|
||||
virtual int addToFlatField(Double_t etax, Double_t etay)=0;
|
||||
|
||||
//virtual void Streamer(TBuffer &b);
|
||||
|
||||
|
||||
static int calcQuad(Double_t *cl, Double_t &sum, Double_t &totquad, Double_t sDum[2][2]){
|
||||
|
||||
int corner = UNDEFINED_QUADRANT;
|
||||
Double_t *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_t totquad, Double_t sDum[2][2], Double_t &etax, Double_t &etay){
|
||||
Double_t 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_t *cl, Double_t &etax, Double_t &etay, Double_t &sum, Double_t &totquad, Double_t sDum[2][2]) {
|
||||
int corner = calcQuad(cl,sum,totquad,sDum);
|
||||
calcEta(totquad, sDum, etax, etay);
|
||||
|
||||
return corner;
|
||||
}
|
||||
|
||||
|
||||
static int calcEtaL(Double_t totquad, int corner, Double_t sDum[2][2], Double_t &etax, Double_t &etay){
|
||||
Double_t t,r, toth, totv;
|
||||
if (totquad>0) {
|
||||
switch(corner) {
|
||||
case TOP_LEFT:
|
||||
t = sDum[1][1] ;
|
||||
r = sDum[0][1] ;
|
||||
toth=sDum[1][1]+sDum[1][0];
|
||||
totv=sDum[0][1]+sDum[1][1];
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
t = sDum[1][0] ;
|
||||
r = sDum[0][1] ;
|
||||
toth=sDum[0][0]+t;
|
||||
totv=sDum[0][0]+r;
|
||||
break;
|
||||
case BOTTOM_LEFT:
|
||||
r = sDum[1][1] ;
|
||||
t = sDum[1][1] ;
|
||||
toth=sDum[1][0]+t;
|
||||
totv=sDum[0][1]+r;
|
||||
break;
|
||||
case BOTTOM_RIGHT:
|
||||
t = sDum[1][0] ;
|
||||
r = sDum[1][1] ;
|
||||
toth=sDum[1][1]+t;
|
||||
totv=sDum[0][1]+r;
|
||||
break;
|
||||
default:
|
||||
etax=-1;
|
||||
etay=-1;
|
||||
return 0;
|
||||
}
|
||||
etax=r/totv;
|
||||
etay=t/toth;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int calcEtaL(Double_t *cl, Double_t &etax, Double_t &etay, Double_t &sum, Double_t &totquad, Double_t sDum[2][2]) {
|
||||
int corner = calcQuad(cl,sum,totquad,sDum);
|
||||
calcEtaL(totquad, corner, sDum, etax, etay);
|
||||
|
||||
return corner;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int calcEtaC3(Double_t *cl, Double_t &etax, Double_t &etay, Double_t &sum, Double_t &totquad, Double_t sDum[2][2]){
|
||||
|
||||
int corner = calcQuad(cl,sum,totquad,sDum);
|
||||
calcEta(sum, sDum, etax, etay);
|
||||
return corner;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int calcEta3(Double_t *cl, Double_t &etax, Double_t &etay, Double_t &sum) {
|
||||
Double_t 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 calcEta3X(Double_t *cl, Double_t &etax, Double_t &etay, Double_t &sum) {
|
||||
Double_t 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;
|
||||
TH2F *hint;
|
||||
|
||||
|
||||
// ClassDefNV(slsInterpolation,1);
|
||||
// #pragma link C++ class slsInterpolation-;
|
||||
};
|
||||
|
||||
#endif
|
11
slsDetectorCalibration/gMapDemo.C
Normal file
11
slsDetectorCalibration/gMapDemo.C
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
//.L energyCalibration.cpp+
|
||||
//.L gainMap.C+
|
||||
TFile fin("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_cds_g4.root");
|
||||
TH2F *h2=fin.Get("h2");
|
||||
TH2F *gMap=gainMap(h2,4);
|
||||
gMap->Draw("colz");
|
||||
|
||||
|
||||
|
||||
}
|
228
slsDetectorCalibration/gainMap.C
Normal file
228
slsDetectorCalibration/gainMap.C
Normal file
@ -0,0 +1,228 @@
|
||||
#define MYROOT
|
||||
#include <TH2F.h>
|
||||
#include <TSpectrum.h>
|
||||
#include <TH1D.h>
|
||||
#include <TFile.h>
|
||||
#include <TList.h>
|
||||
#include <TPolyMarker.h>
|
||||
#include <THStack.h>
|
||||
#include <TF1.h>
|
||||
#include <TGraphErrors.h>
|
||||
#include <iostream>
|
||||
#include <energyCalibration.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#define FOPT "0"
|
||||
|
||||
TH2F *gainMap(TH2F *h2, float g) {
|
||||
// int npx, npy;
|
||||
int npx=160, npy=160;
|
||||
// det->getDetectorSize(npx, npy);
|
||||
|
||||
TH2F *gMap=new TH2F("gmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5);
|
||||
|
||||
Double_t ens[3]={0,8,17.5}, eens[3]={0.,0.1,0.1};
|
||||
Double_t peaks[3], epeaks[3];
|
||||
|
||||
|
||||
|
||||
int ibin;
|
||||
TH1D *px;
|
||||
|
||||
|
||||
energyCalibration *enCal=new energyCalibration();
|
||||
enCal->setPlotFlag(0);
|
||||
// enCal->setChargeSharing(0);
|
||||
enCal->setScanSign(1);
|
||||
|
||||
Double_t gain, off, egain, eoff;
|
||||
|
||||
|
||||
TList *functions;
|
||||
TPolyMarker *pm ;
|
||||
Double_t *peakX, *peakY;
|
||||
TSpectrum *s=new TSpectrum();
|
||||
Double_t mypar[10], emypar[10];
|
||||
Double_t prms, np;
|
||||
int iit=0;
|
||||
TGraph *glin;
|
||||
Double_t peakdum, hpeakdum;
|
||||
|
||||
for (int ix=1; ix<npx-1; ix++) {
|
||||
for (int iy=1; iy<npy-1; iy++) {
|
||||
// cout << ix << " " << iy << " " << ibin << endl;
|
||||
ibin=ix*npy+iy;
|
||||
px=h2->ProjectionX("px",ibin+1,ibin+1);
|
||||
prms=10*g;
|
||||
iit=0;
|
||||
np=s->Search(px,prms,"",0.2);
|
||||
while (np !=2) {
|
||||
if (np>2)
|
||||
prms+=0.5*prms;
|
||||
else
|
||||
prms-=0.5*prms;
|
||||
iit++;
|
||||
if (iit>=10)
|
||||
break;
|
||||
np=s->Search(px,prms,"",0.2);
|
||||
}
|
||||
if (np!=2)
|
||||
cout << "peak search could not converge " << ibin << endl;
|
||||
if (np==2) {
|
||||
pm=NULL;
|
||||
functions=px->GetListOfFunctions();
|
||||
if (functions)
|
||||
pm = (TPolyMarker*)functions->FindObject("TPolyMarker");
|
||||
if (pm) {
|
||||
peakX=pm->GetX();
|
||||
peakY=pm->GetY();
|
||||
|
||||
|
||||
if (peakX[0]>peakX[1]) {
|
||||
peakdum=peakX[0];
|
||||
hpeakdum=peakY[0];
|
||||
peakX[0]= peakX[1];
|
||||
peakY[0]= peakY[1];
|
||||
peakX[1]= peakdum;
|
||||
peakY[1]= hpeakdum;
|
||||
|
||||
}
|
||||
|
||||
cout << "("<< ix << "," << iy << ") " << endl;
|
||||
for (int ip=0; ip<np; ip++) {
|
||||
// cout << ip << " " << peakX[ip] << " " << peakY[ip] << endl;
|
||||
|
||||
enCal->setFitRange(peakX[ip]-10*g,peakX[ip]+10*g);
|
||||
mypar[0]=0;
|
||||
mypar[1]=0;
|
||||
mypar[2]=peakX[ip];
|
||||
mypar[3]=g*10;
|
||||
mypar[4]=peakY[ip];
|
||||
mypar[5]=0;
|
||||
|
||||
|
||||
|
||||
enCal->setStartParameters(mypar);
|
||||
enCal->fitSpectrum(px,mypar,emypar);
|
||||
|
||||
|
||||
peaks[ip+1]=mypar[2];
|
||||
epeaks[ip+1]=emypar[2];
|
||||
}
|
||||
|
||||
peaks[0]=0;
|
||||
epeaks[0]=1;
|
||||
|
||||
// for (int i=0; i<3; i++) cout << i << " " << ens[i] << " " << eens[i]<< " "<< peaks[i]<< " " << epeaks[i] << endl;
|
||||
|
||||
glin= enCal->linearCalibration(3,ens,eens,peaks,epeaks,gain,off,egain,eoff);
|
||||
|
||||
// cout << "Gain " << gain << " off " << off << endl;
|
||||
if (off>-10 && off<10) {
|
||||
gMap->SetBinContent(ix+1,iy+1,gain);
|
||||
gMap->SetBinError(ix+1,iy+1,egain);
|
||||
}
|
||||
if (glin)
|
||||
delete glin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return gMap;
|
||||
}
|
||||
|
||||
|
||||
TH2F *noiseMap(TH2F *h2) {
|
||||
// int npx, npy;
|
||||
int npx=160, npy=160;
|
||||
// det->getDetectorSize(npx, npy);
|
||||
|
||||
TH2F *nMap=new TH2F("nmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5);
|
||||
|
||||
int ibin;
|
||||
TH1D *px;
|
||||
|
||||
for (int ix=0; ix<npx; ix++) {
|
||||
for (int iy=0; iy<npy; iy++) {
|
||||
cout << ix << " " << iy << " " << ibin << endl;
|
||||
ibin=ix*npy+iy;
|
||||
px=h2->ProjectionX("px",ibin+1,ibin+1);
|
||||
px->Fit("gaus", FOPT);
|
||||
if (px->GetFunction("gaus")) {
|
||||
nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2));
|
||||
}
|
||||
// delete px;
|
||||
}
|
||||
}
|
||||
|
||||
return nMap;
|
||||
}
|
||||
|
||||
|
||||
THStack *noiseHistos(char *tit) {
|
||||
char fname[10000];
|
||||
|
||||
sprintf(fname,"/data/moench_xbox_20140116/noise_map_%s.root",tit);
|
||||
TFile *fn=new TFile(fname);
|
||||
TH2F *nmap=(TH2F*)fn->Get("nmap");
|
||||
|
||||
if (nmap==NULL) {
|
||||
cout << "No noise map in file " << fname << endl;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sprintf(fname,"/data/moench_xbox_20140113/gain_map_%s.root",tit);
|
||||
TFile *fg=new TFile(fname);
|
||||
TH2F *gmap=(TH2F*)fg->Get("gmap");
|
||||
|
||||
if (gmap==NULL) {
|
||||
cout << "No gain map in file " << fname << endl;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nmap->Divide(gmap);
|
||||
nmap->Scale(1000./3.6);
|
||||
|
||||
THStack *hs=new THStack(tit,tit);
|
||||
hs->SetTitle(tit);
|
||||
|
||||
TH1F *h;
|
||||
char hname[100];
|
||||
|
||||
cout << tit << endl;
|
||||
for (int is=0; is<4; is++) {
|
||||
sprintf(hname,"h%ds",is+1);
|
||||
|
||||
h=new TH1F(hname,tit,500,0,500);
|
||||
hs->Add(h);
|
||||
// cout << hs->GetHists()->GetEntries() << endl;
|
||||
for (int ix=40*is+2; ix<40*(is+1)-2; ix++) {
|
||||
|
||||
for (int iy=2; iy<158; iy++) {
|
||||
if (ix<100 || ix>120)
|
||||
h->Fill(nmap->GetBinContent(ix+1,iy+1));
|
||||
}
|
||||
}
|
||||
cout << is+1 << "SC: " << "" << h->GetMean() << "+-" << h->GetRMS();
|
||||
h->Fit("gaus","0Q");
|
||||
h->SetLineColor(is+1);
|
||||
if (h->GetFunction("gaus")) {
|
||||
h->GetFunction("gaus")->SetLineColor(is+1);
|
||||
cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParError(1);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
// cout << hs->GetHists()->GetEntries() << endl;
|
||||
|
||||
return hs;
|
||||
|
||||
|
||||
}
|
148
slsDetectorCalibration/gotthardModuleData.h
Normal file
148
slsDetectorCalibration/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/gotthardShortModuleData.h
Normal file
127
slsDetectorCalibration/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/jungfrau02Data.h
Normal file
156
slsDetectorCalibration/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/jungfrau10ModuleData.h
Normal file
155
slsDetectorCalibration/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
|
264
slsDetectorCalibration/jungfrauReadData.C
Normal file
264
slsDetectorCalibration/jungfrauReadData.C
Normal file
@ -0,0 +1,264 @@
|
||||
#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 <stdio.h>
|
||||
//#include <deque>
|
||||
//#include <list>
|
||||
//#include <queue>
|
||||
#include <fstream>
|
||||
#include "jungfrau02Data.h"
|
||||
#include "jungfrau02CommonMode.h"
|
||||
#include "singlePhotonDetector.h"
|
||||
|
||||
//#include "MovingStat.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define NC 48
|
||||
#define NR 48
|
||||
|
||||
|
||||
#define MY_DEBUG 1
|
||||
#ifdef MY_DEBUG
|
||||
#include <TCanvas.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Loops over data file to find single photons, fills the tree (and writes it to file, although the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (48*x+y) on the y axis.
|
||||
|
||||
\param fformat file name format
|
||||
\param tit title of the tree etc.
|
||||
\param runmin minimum run number
|
||||
\param runmax max run number
|
||||
\param nbins number of bins for spectrum hists
|
||||
\param hmin histo minimum for spectrum hists
|
||||
\param hmax histo maximum for spectrum hists
|
||||
\param sign sign of the spectrum to find hits
|
||||
\param hc readout correlation coefficient with previous pixel
|
||||
\param xmin minimum x coordinate
|
||||
\param xmax maximum x coordinate
|
||||
\param ymin minimum y coordinate
|
||||
\param ymax maximum y coordinate
|
||||
\param cmsub enable commonmode subtraction
|
||||
\param hitfinder if 0: performs pedestal subtraction, not hit finding; if 1: performs both pedestal subtraction and hit finding
|
||||
\returns pointer to histo stack with cluster spectra
|
||||
*/
|
||||
|
||||
|
||||
THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1){
|
||||
/*
|
||||
// read in calibration file
|
||||
ifstream calfile("/home/l_msdetect/TriesteBeam2014/dummy data for scripts/CalibrationParametersTest_fake.txt");
|
||||
if (calfile.is_open()==0){cout << "Unable to open calibration file!" << endl;}
|
||||
int pix;
|
||||
double of0,sl0,of1,sl1,of2,sl2;
|
||||
double of_0[NC*NR], of_1[NC*NR], of_2[NC*NR], sl_0[NC*NR], sl_1[NC*NR], sl_2[NC*NR];
|
||||
while (calfile >> pix >> of0 >> sl0 >> of1 >> sl1 >> of2 >> sl2){
|
||||
of_0[pix]=of0;
|
||||
sl_0[pix]=sl0;
|
||||
of_1[pix]=of1;
|
||||
sl_1[pix]=sl1;
|
||||
of_2[pix]=of2;
|
||||
sl_2[pix]=sl2; //if(pix==200) cout << "sl_2[200] " << sl_2[200] << endl;
|
||||
}
|
||||
calfile.close();
|
||||
*/
|
||||
double adc_value, num_photon;
|
||||
|
||||
jungfrau02Data *decoder=new jungfrau02Data(1,0,0);//(1,0,0); // (adc,offset,crosstalk) //(1,0,0) //(3,0,0) for readout of GB
|
||||
jungfrau02CommonMode *cmSub=NULL;
|
||||
if (cmsub)
|
||||
cmSub=new jungfrau02CommonMode();
|
||||
|
||||
int nph=0;
|
||||
int iev=0;
|
||||
singlePhotonDetector<uint16_t> *filter=new singlePhotonDetector<uint16_t>(decoder, 3, 5, sign, cmSub);
|
||||
|
||||
char *buff;
|
||||
char fname[10000];
|
||||
int nf=0;
|
||||
|
||||
eventType thisEvent=PEDESTAL;
|
||||
|
||||
// int iframe;
|
||||
// double *data, ped, sigma;
|
||||
|
||||
// data=decoder->getCluster();
|
||||
|
||||
TH2F *h2;
|
||||
TH2F *h3;
|
||||
TH2F *hetaX; // not needed for JF?
|
||||
TH2F *hetaY; // not needed for JF?
|
||||
|
||||
THStack *hs=new THStack("hs",fformat);
|
||||
|
||||
|
||||
TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
hs->Add(h1);
|
||||
|
||||
if (hitfinder) {
|
||||
h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // not needed for JF?
|
||||
hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // not needed for JF?
|
||||
hs->Add(h2);
|
||||
hs->Add(h3);
|
||||
hs->Add(hetaX); // not needed for JF?
|
||||
hs->Add(hetaY); // not needed for JF?
|
||||
}
|
||||
|
||||
|
||||
ifstream filebin;
|
||||
|
||||
|
||||
int ix=20, iy=20, ir, ic;
|
||||
|
||||
|
||||
Int_t iFrame;
|
||||
TTree *tall;
|
||||
if (hitfinder)
|
||||
tall=filter->initEventTree(tit, &iFrame);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
|
||||
TCanvas *myC;
|
||||
TH2F *he;
|
||||
TCanvas *cH1;
|
||||
TCanvas *cH2;
|
||||
TCanvas *cH3;
|
||||
|
||||
if (hitfinder) {
|
||||
myC=new TCanvas();
|
||||
he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax);
|
||||
he->SetStats(kFALSE);
|
||||
he->Draw("colz");
|
||||
cH1=new TCanvas();
|
||||
cH1->SetLogz();
|
||||
h1->Draw("colz");
|
||||
cH2=new TCanvas();
|
||||
cH2->SetLogz();
|
||||
h2->Draw("colz");
|
||||
cH3=new TCanvas();
|
||||
cH3->SetLogz();
|
||||
h3->Draw("colz");
|
||||
}
|
||||
#endif
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
for (int irun=runmin; irun<=runmax; irun++){
|
||||
sprintf(fname,fformat,irun);
|
||||
cout << "file name " << fname << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
nph=0;
|
||||
while ((buff=decoder->readNextFrame(filebin))) {
|
||||
|
||||
|
||||
if (hitfinder) {
|
||||
filter->newFrame();
|
||||
|
||||
//calculate pedestals and common modes
|
||||
if (cmsub) {
|
||||
// cout << "cm" << endl;
|
||||
for (ix=xmin-1; ix<xmax+1; ix++)
|
||||
for (iy=ymin-1; iy<ymax+1; iy++) {
|
||||
thisEvent=filter->getEventType(buff, ix, iy,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cout << "new frame " << endl;
|
||||
|
||||
for (ix=xmin-1; ix<xmax+1; ix++)
|
||||
for (iy=ymin-1; iy<ymax+1; iy++) {
|
||||
// cout << ix << " " << iy << endl;
|
||||
|
||||
|
||||
|
||||
thisEvent=filter->getEventType(buff, ix, iy, cmsub);
|
||||
int gainBits=decoder->getGainBits(buff,ix,iy); //XXX
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
if (hitfinder) {
|
||||
if (iev%1000==0)
|
||||
//he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); // show single photon hits // original
|
||||
//he->SetBinContent(ix+1-xmin, iy+1-ymin, cmSub->getCommonMode(ix,iy)); //show common mode!
|
||||
he->SetBinContent(iy+1-ymin, ix+1-xmin, (int)gainBits); //show gain bits
|
||||
//he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)gainBits); // rows and columns reversed!!!
|
||||
}
|
||||
#endif
|
||||
|
||||
if (nf>1000) { // only start filing data after 1000 frames
|
||||
|
||||
// h1->Fill(decoder->getValue(buff,ix,iy), iy+NR*ix);
|
||||
h1->Fill(filter->getClusterTotal(1), iy+NR*ix);
|
||||
|
||||
|
||||
if (hitfinder) {
|
||||
|
||||
if (thisEvent==PHOTON_MAX ) {
|
||||
nph++;
|
||||
|
||||
h2->Fill(filter->getClusterTotal(2), iy+NR*ix);
|
||||
h3->Fill(filter->getClusterTotal(3), iy+NR*ix);
|
||||
iFrame=decoder->getFrameNumber(buff);
|
||||
|
||||
tall->Fill();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
if (iev%1000==0) {
|
||||
myC->Modified();
|
||||
myC->Update();
|
||||
cH1->Modified();
|
||||
cH1->Update();
|
||||
cH2->Modified();
|
||||
cH2->Update();
|
||||
cH3->Modified();
|
||||
cH3->Update();
|
||||
}
|
||||
iev++;
|
||||
#endif
|
||||
nf++;
|
||||
|
||||
cout << "="; // one "=" for every frame that's been processed
|
||||
delete [] buff;
|
||||
}
|
||||
cout << nph << endl; // number of photons found in file
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
else
|
||||
cout << "Could not open file :( ... " << fname << endl;
|
||||
}
|
||||
if (hitfinder)
|
||||
tall->Write(tall->GetName(),TObject::kOverwrite);
|
||||
|
||||
|
||||
|
||||
delete decoder;
|
||||
cout << "Read " << nf << " frames." << endl;
|
||||
return hs;
|
||||
}
|
||||
|
10
slsDetectorCalibration/makefile
Normal file
10
slsDetectorCalibration/makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC=gcc
|
||||
CFLAGS= -g -c -W -lstdc++
|
||||
|
||||
ROOTINCLUDE=$(ROOTSYS)/include
|
||||
|
||||
energyCalibration.o: energyCalibration.cpp
|
||||
$(CC) $(CFLAGS) energyCalibration.cpp -I $(ROOTINCLUDE)
|
||||
|
||||
clean:
|
||||
rm -f energyCalibration.o
|
246
slsDetectorCalibration/moench02Ctb10GbData.h
Normal file
246
slsDetectorCalibration/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/moench02CtbData.h
Normal file
157
slsDetectorCalibration/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/moench02ModuleData.h
Normal file
137
slsDetectorCalibration/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
|
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
|
285
slsDetectorCalibration/moench03Ctb10GbData.h
Normal file
285
slsDetectorCalibration/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
|
235
slsDetectorCalibration/moench03Ctb10GbT1Data.h
Normal file
235
slsDetectorCalibration/moench03Ctb10GbT1Data.h
Normal file
@ -0,0 +1,235 @@
|
||||
#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
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// moench03Ctb10GbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, 8208*40, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
moench03Ctb10GbT1Data(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
|
||||
|
||||
*/
|
||||
|
||||
/* 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& 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;};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int fnum;
|
||||
return readNextFrame(filebin, fnum);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
154
slsDetectorCalibration/moench03CtbData.h
Normal file
154
slsDetectorCalibration/moench03CtbData.h
Normal file
@ -0,0 +1,154 @@
|
||||
#ifndef MOENCH03CTBDATA_H
|
||||
#define MOENCH03CTBDATA_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 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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
1117
slsDetectorCalibration/moench03ReadData.C
Normal file
1117
slsDetectorCalibration/moench03ReadData.C
Normal file
File diff suppressed because it is too large
Load Diff
490
slsDetectorCalibration/moench03ReadData10Gb.C
Normal file
490
slsDetectorCalibration/moench03ReadData10Gb.C
Normal file
@ -0,0 +1,490 @@
|
||||
#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 <TGraph.h>
|
||||
#include <stdio.h>
|
||||
//#include <deque>
|
||||
//#include <list>
|
||||
//#include <queue>
|
||||
#include <fstream>
|
||||
#include "moench03Ctb10GbData.h"
|
||||
#include "moench03CommonMode.h"
|
||||
#define MYROOT1
|
||||
#include "singlePhotonDetector.h"
|
||||
|
||||
//#include "MovingStat.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define NC 400
|
||||
#define NR 400
|
||||
|
||||
|
||||
//#define MY_DEBUG 1
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
#include <TCanvas.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
TH2F *readImage(ifstream &filebin, TH2F *h2=NULL, TH2F *hped=NULL) {
|
||||
moench03Ctb10GbData *decoder=new moench03Ctb10GbData();
|
||||
char *buff=decoder->readNextFrame(filebin);
|
||||
|
||||
|
||||
// TH1F *h1=new TH1F("h1","",400*400,0,400*400);
|
||||
// int ip=0;
|
||||
if (buff) {
|
||||
if (h2==NULL) {
|
||||
h2=new TH2F("h2","",400,0,400,400,0,400);
|
||||
h2->SetStats(kFALSE);
|
||||
}
|
||||
// cout << "." << endl;
|
||||
for (int ix=0; ix<400; ix++) {
|
||||
for (int iy=0; iy<400; iy++) {
|
||||
// cout << decoder->getDataSize() << " " << decoder->getValue(buff,ix,iy)<< endl;
|
||||
h2->SetBinContent(ix+1,iy+1,decoder->getValue(buff,ix,iy));
|
||||
// h1->SetBinContent(++ip,decoder->getValue(buff,ix,iy));
|
||||
}
|
||||
}
|
||||
if (hped) h2->Add(hped,-1);
|
||||
return h2;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
TH2F *readImage(char *fname, int iframe=0, TH2F *hped=NULL) {
|
||||
ifstream filebin;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
TH2F *h2=new TH2F("h2","",400,0,400,400,0,400);
|
||||
TH2F *hh;
|
||||
hh=readImage(filebin, h2, hped );
|
||||
if (hh==NULL) {
|
||||
|
||||
delete h2;
|
||||
return NULL;
|
||||
}
|
||||
for (int i=0; i<iframe; i++) {
|
||||
if (hh==NULL) break;
|
||||
hh=readImage(filebin, h2, hped );
|
||||
if (hh)
|
||||
;// cout << "="<< endl;
|
||||
else {
|
||||
delete h2;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
if (hped!=NULL)
|
||||
h2->Add(hped,-1);
|
||||
|
||||
return h2;
|
||||
}
|
||||
|
||||
|
||||
TH2F *calcPedestal(char *fformat, int runmin, int runmax){
|
||||
ifstream filebin;
|
||||
char fname[10000];
|
||||
moench03Ctb10GbData *decoder=new moench03Ctb10GbData();
|
||||
singlePhotonDetector<uint16_t> *filter=new singlePhotonDetector<uint16_t>(decoder, 3, 5, 1, NULL);
|
||||
char *buff;
|
||||
int ix,iy;
|
||||
int ii=0;
|
||||
TH2F* h2=NULL;
|
||||
|
||||
for (int irun=runmin; irun<=runmax; irun++) {
|
||||
sprintf(fname,fformat,irun);
|
||||
|
||||
cout << fname << endl;
|
||||
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
while ((buff=decoder->readNextFrame(filebin))) {
|
||||
for (ix=0; ix<400; ix++) {
|
||||
for (iy=0; iy<400; iy++) {
|
||||
if (decoder->getValue(buff,ix,iy)>1000)
|
||||
filter->addToPedestal(decoder->getValue(buff,ix,iy), ix, iy);
|
||||
}
|
||||
}
|
||||
delete [] buff;
|
||||
//cout << "="<< endl;
|
||||
ii++;
|
||||
}
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
|
||||
}
|
||||
if (ii>0) {
|
||||
h2=new TH2F("hped","",400,0,400,400,0,400);
|
||||
|
||||
for (ix=0; ix<400; ix++) {
|
||||
for (iy=0; iy<400; iy++) {
|
||||
h2->SetBinContent(ix+1, iy+1,filter->getPedestal(ix,iy));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return h2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
TH1D *calcSpectrum(char *fformat, int runmin, int runmax, TH2F *hped=NULL){
|
||||
ifstream filebin;
|
||||
char fname[10000];
|
||||
moench03Ctb10GbData *decoder=new moench03Ctb10GbData();
|
||||
TH1D *hspectrum=new TH1D("hsp","hsp",2500,-500,10000);
|
||||
char *buff;
|
||||
int ix,iy;
|
||||
int ii=0;
|
||||
TH2F* h2=NULL;
|
||||
int ich=0;
|
||||
Double_t ped=0;
|
||||
|
||||
for (int irun=runmin; irun<=runmax; irun++) {
|
||||
sprintf(fname,fformat,irun);
|
||||
|
||||
cout << fname << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
while ((buff=decoder->readNextFrame(filebin))) {
|
||||
for (ix=0; ix<200; ix++) {
|
||||
for (iy=200; iy<400; iy++) {
|
||||
if (decoder->getValue(buff,ix,iy)>1000) {
|
||||
if(hped) ped=hped->GetBinContent(ix+1,iy+1);
|
||||
hspectrum->Fill(decoder->getValue(buff,ix,iy)-ped);
|
||||
}
|
||||
ich++;
|
||||
}
|
||||
}
|
||||
delete [] buff;
|
||||
//cout << "="<< endl;
|
||||
ii++;
|
||||
}
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
|
||||
}
|
||||
return hspectrum;
|
||||
|
||||
}
|
||||
TH2F *drawImage(char *fformat, int runmin, int runmax, TH2F *hped=NULL){
|
||||
ifstream filebin;
|
||||
char fname[10000];
|
||||
moench03Ctb10GbData *decoder=new moench03Ctb10GbData();
|
||||
TH2F *hspectrum=new TH2F("hsp","hsp",400,0,400,400,0,400);
|
||||
char *buff;
|
||||
int ix,iy;
|
||||
int ii=0;
|
||||
TH2F* h2=NULL;
|
||||
int ich=0;
|
||||
Double_t ped=0;
|
||||
|
||||
for (int irun=runmin; irun<=runmax; irun++) {
|
||||
sprintf(fname,fformat,irun);
|
||||
|
||||
cout << fname << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
while ((buff=decoder->readNextFrame(filebin))) {
|
||||
for (ix=0; ix<400; ix++) {
|
||||
for (iy=0; iy<400; iy++) {
|
||||
if (decoder->getValue(buff,ix,iy)>1000) {
|
||||
if(hped) ped=hped->GetBinContent(ix+1,iy+1);
|
||||
hspectrum->Fill(ix, iy, decoder->getValue(buff,ix,iy)-ped);
|
||||
}
|
||||
ich++;
|
||||
}
|
||||
}
|
||||
delete [] buff;
|
||||
//cout << "="<< endl;
|
||||
ii++;
|
||||
}
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
|
||||
}
|
||||
return hspectrum;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis.
|
||||
|
||||
\param fformat file name format
|
||||
\param tit title of the tree etc.
|
||||
\param runmin minimum run number
|
||||
\param runmax max run number
|
||||
\param nbins number of bins for spectrum hists
|
||||
\param hmin histo minimum for spectrum hists
|
||||
\param hmax histo maximum for spectrum hists
|
||||
\param xmin minimum x coordinate
|
||||
\param xmax maximum x coordinate
|
||||
\param ymin minimum y coordinate
|
||||
\param ymax maximum y coordinate
|
||||
\param cmsub enable commonmode subtraction
|
||||
\returns pointer to histo stack with cluster spectra
|
||||
*/
|
||||
|
||||
THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1) {
|
||||
double hc=0;
|
||||
int sign=1;
|
||||
|
||||
moench03Ctb10GbData *decoder=new moench03Ctb10GbData();
|
||||
cout << "decoder allocated " << endl;
|
||||
|
||||
moench03CommonMode *cmSub=NULL;
|
||||
if (cmsub) {
|
||||
cmSub=new moench03CommonMode(100);
|
||||
cout << "common mode allocated " << endl;
|
||||
|
||||
} else {
|
||||
|
||||
cout << "non allocating common mode " << endl;
|
||||
}
|
||||
int iev=0;
|
||||
int nph=0;
|
||||
|
||||
singlePhotonDetector<uint16_t> *filter=new singlePhotonDetector<uint16_t>(decoder, 3, 5, sign, cmSub, 100, 10);
|
||||
cout << "filter allocated " << endl;
|
||||
|
||||
char *buff;
|
||||
char fname[10000];
|
||||
int nf=0;
|
||||
|
||||
eventType thisEvent=PEDESTAL;
|
||||
|
||||
// int iframe;
|
||||
// double *data, ped, sigma;
|
||||
|
||||
// data=decoder->getCluster();
|
||||
|
||||
|
||||
THStack *hs=new THStack("hs",fformat);
|
||||
|
||||
cout << "hstack allocated " << endl;
|
||||
|
||||
|
||||
TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
hs->Add(h1);
|
||||
cout << "h1 allocated " << endl;
|
||||
|
||||
TH2F *h2;
|
||||
TH2F *h3;
|
||||
if (hitfinder) {
|
||||
h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
cout << "h2 allocated " << endl;
|
||||
h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
cout << "h3 allocated " << endl;
|
||||
// hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5);
|
||||
// hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5);
|
||||
hs->Add(h2);
|
||||
hs->Add(h3);
|
||||
// hs->Add(hetaX);
|
||||
// hs->Add(hetaY);
|
||||
}
|
||||
if (hs->GetHists()) {
|
||||
for (int i=0; i<3; i++)
|
||||
if (hs->GetHists()->At(1)) cout << i << " " ;
|
||||
cout << " histos allocated " << endl;
|
||||
} else
|
||||
cout << "no hists in stack " << endl;
|
||||
|
||||
|
||||
ifstream filebin;
|
||||
|
||||
|
||||
int ix=20, iy=20, ir, ic;
|
||||
|
||||
|
||||
Int_t iFrame;
|
||||
TTree *tall;
|
||||
if (hitfinder)
|
||||
tall=filter->initEventTree(tit, &iFrame);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
|
||||
cout << "debug mode " << endl;
|
||||
|
||||
TCanvas *myC;
|
||||
TH2F *he;
|
||||
TCanvas *cH1;
|
||||
TCanvas *cH2;
|
||||
TCanvas *cH3;
|
||||
|
||||
if (hitfinder) {
|
||||
myC=new TCanvas("myc");
|
||||
he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax);
|
||||
he->SetStats(kFALSE);
|
||||
he->Draw("colz");
|
||||
cH1=new TCanvas("ch1");
|
||||
cH1->SetLogz();
|
||||
h1->Draw("colz");
|
||||
cH2=new TCanvas("ch2");
|
||||
cH2->SetLogz();
|
||||
h2->Draw("colz");
|
||||
cH3=new TCanvas("ch3");
|
||||
cH3->SetLogz();
|
||||
h3->Draw("colz");
|
||||
}
|
||||
#endif
|
||||
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
for (int irun=runmin; irun<runmax; irun++) {
|
||||
sprintf(fname,fformat,irun);
|
||||
cout << "file name " << fname << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
nph=0;
|
||||
while ((buff=decoder->readNextFrame(filebin))) {
|
||||
|
||||
filter->newFrame();
|
||||
|
||||
if (cmsub) {
|
||||
// cout << "cm" << endl;
|
||||
for (ix=xmin-1; ix<xmax+1; ix++)
|
||||
for (iy=ymin-1; iy<ymax+1; iy++) {
|
||||
thisEvent=filter->getEventType(buff, ix, iy,0);
|
||||
}
|
||||
}
|
||||
// if (hitfinder) {
|
||||
|
||||
// //calculate pedestals and common modes
|
||||
// }
|
||||
|
||||
// cout << "new frame " << endl;
|
||||
|
||||
for (ix=xmin-1; ix<xmax+1; ix++)
|
||||
for (iy=ymin-1; iy<ymax+1; iy++) {
|
||||
// cout << ix << " " << iy << endl;
|
||||
thisEvent=filter->getEventType(buff, ix, iy, cmsub);
|
||||
// if (nf>10) {
|
||||
h1->Fill(filter->getClusterTotal(1), iy+NR*ix);
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
// if (iev%10==0)
|
||||
he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent);
|
||||
#endif
|
||||
|
||||
if (hitfinder) {
|
||||
|
||||
if (thisEvent==PHOTON_MAX ) {
|
||||
nph++;
|
||||
|
||||
h2->Fill(filter->getClusterTotal(2), iy+NR*ix);
|
||||
h3->Fill(filter->getClusterTotal(3), iy+NR*ix);
|
||||
iFrame=decoder->getFrameNumber(buff);
|
||||
|
||||
tall->Fill();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // else {
|
||||
// filter->addToPedestal(decoder->getValue(buff,ix,iy, cmsub));
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
// cout << iev << " " << h1->GetEntries() << " " << h2->GetEntries() << endl;
|
||||
// if (iev%10==0) {
|
||||
// myC->Modified();
|
||||
// myC->Update();
|
||||
// cH1->Modified();
|
||||
// cH1->Update();
|
||||
// cH2->Modified();
|
||||
// cH2->Update();
|
||||
// cH3->Modified();
|
||||
// cH3->Update();
|
||||
// }
|
||||
iev++;
|
||||
#endif
|
||||
nf++;
|
||||
|
||||
// cout << "=" ;
|
||||
delete [] buff;
|
||||
}
|
||||
// cout << nph << endl;
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
else
|
||||
cout << "could not open file " << fname << endl;
|
||||
}
|
||||
if (hitfinder)
|
||||
tall->Write(tall->GetName(),TObject::kOverwrite);
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
myC->Modified();
|
||||
myC->Update();
|
||||
cH1->Modified();
|
||||
cH1->Update();
|
||||
cH2->Modified();
|
||||
cH2->Update();
|
||||
cH3->Modified();
|
||||
cH3->Update();
|
||||
#endif
|
||||
|
||||
delete decoder;
|
||||
cout << "Read " << nf << " frames" << endl;
|
||||
return hs;
|
||||
}
|
||||
|
||||
TGraph* checkFrameNumber(char *fformat, int runmin, int runmax, int ix, int iy){
|
||||
ifstream filebin;
|
||||
char fname[10000];
|
||||
moench03Ctb10GbData *decoder=new moench03Ctb10GbData();
|
||||
char *buff;
|
||||
int ii=0;
|
||||
|
||||
TGraph *g=new TGraph();
|
||||
|
||||
|
||||
|
||||
for (int irun=runmin; irun<=runmax; irun++) {
|
||||
sprintf(fname,fformat,irun);
|
||||
|
||||
cout << fname << endl;
|
||||
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
|
||||
if (filebin.is_open()) {
|
||||
while ((buff=decoder->readNextFrame(filebin))) {
|
||||
g->SetPoint(ii,decoder->getFrameNumber(buff),decoder->getValue(buff,ix,iy));
|
||||
ii++;
|
||||
delete [] buff;
|
||||
}
|
||||
//cout << "="<< endl;
|
||||
filebin.close();
|
||||
} else
|
||||
cout << "Could not open file " << fname << endl;
|
||||
|
||||
}
|
||||
|
||||
return g;
|
||||
|
||||
}
|
285
slsDetectorCalibration/moench03TCtb10GbData.h
Normal file
285
slsDetectorCalibration/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
|
154
slsDetectorCalibration/moench03TCtbData.h
Normal file
154
slsDetectorCalibration/moench03TCtbData.h
Normal file
@ -0,0 +1,154 @@
|
||||
#ifndef MOENCH03TCTBDATA_H
|
||||
#define MOENCH03TCTBDATA_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 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;
|
||||
|
||||
}
|
||||
}
|
||||
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
|
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
|
244
slsDetectorCalibration/moenchMakeTree.C
Normal file
244
slsDetectorCalibration/moenchMakeTree.C
Normal file
@ -0,0 +1,244 @@
|
||||
#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 <stdio.h>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <fstream>
|
||||
#include "RunningStat.h"
|
||||
#include "MovingStat.h"
|
||||
#include "moench02ModuleData.h"
|
||||
#include <TThread.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//tree variables
|
||||
int xC,yC,iFrameC;
|
||||
double meC,sigC;
|
||||
Double_t dataC[3][3];
|
||||
TTree* tall;
|
||||
|
||||
typedef struct task_s{
|
||||
char *fformat;
|
||||
char *tname;
|
||||
int runmin;
|
||||
int runmax;
|
||||
int sign;
|
||||
} Task;
|
||||
|
||||
void setUpTree(char *tname){
|
||||
tall=new TTree(tname,tname);
|
||||
tall->Branch("iFrame",&iFrameC,"iframe/I");
|
||||
tall->Branch("x",&xC,"x/I");
|
||||
tall->Branch("y",&yC,"y/I");
|
||||
tall->Branch("data",dataC,"data[3][3]/D");
|
||||
tall->Branch("pedestal",&meC,"pedestal/D");
|
||||
tall->Branch("rms",&sigC,"rms/D");
|
||||
}
|
||||
|
||||
inline void storeEvent(int iF,int x,int y, Double_t data[][3], double me, double sig){
|
||||
TThread::Lock();
|
||||
xC = x; yC = y; iFrameC = iF;
|
||||
memcpy(dataC,data,sizeof(Double_t)*3*3);
|
||||
//cout << "X: " << x << " Y: " << y << endl;
|
||||
/* for(int i = 0; i < 3; i++){
|
||||
for(int j = 0; j < 3; j++){
|
||||
cout << "i: " << i << " j: " << j << " dataC " << dataC[i][j] << " data " << data[i][j] << endl;
|
||||
}
|
||||
}*/
|
||||
meC = me; sigC = sig;
|
||||
tall->Fill();
|
||||
TThread::UnLock();
|
||||
}
|
||||
|
||||
void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign=1) {
|
||||
double nThSigma = 3.;
|
||||
moench02ModuleData *decoder=new moench02ModuleData();
|
||||
char *buff;
|
||||
char fname[10000];
|
||||
|
||||
int nf=0;
|
||||
|
||||
int dum, nPhotons;
|
||||
double me, sig, tot, maxNei, val, valNei;
|
||||
|
||||
MovingStat stat[160][160];
|
||||
MovingStat nPhotonsStat;
|
||||
|
||||
ifstream filebin;
|
||||
|
||||
int nbg=20;
|
||||
|
||||
int ix, iy, ir, ic, mx,my;
|
||||
Double_t data[3][3];
|
||||
|
||||
nPhotonsStat.Clear();
|
||||
nPhotonsStat.SetN(1000);
|
||||
|
||||
for (ir=0; ir<160; ir++) {
|
||||
for (ic=0; ic<160; ic++) {
|
||||
stat[ir][ic].Clear();
|
||||
stat[ir][ic].SetN(nbg);
|
||||
}
|
||||
}
|
||||
|
||||
for (int irun=runmin; irun<runmax; irun++) {
|
||||
sprintf(fname,fformat,irun);
|
||||
//cout << "process file " << fname; // cout.flush();
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
|
||||
while ((buff=decoder->readNextFrame(filebin))) {
|
||||
nPhotons=0;
|
||||
//for (ix=0; ix<160; ix++){
|
||||
for (ix=0; ix<40; ix++){
|
||||
for (iy=0; iy<160; iy++) {
|
||||
|
||||
|
||||
|
||||
dum=0; //no hit
|
||||
// tot=0;
|
||||
|
||||
me=stat[iy][ix].Mean();
|
||||
sig=stat[iy][ix].StandardDeviation();
|
||||
val=sign*(decoder->getChannelShort(buff,ix,iy)-me);
|
||||
|
||||
|
||||
if (nf>nbg) {
|
||||
me=stat[iy][ix].Mean();
|
||||
sig=stat[iy][ix].StandardDeviation();
|
||||
val=sign*decoder->getChannel(buff,ix,iy)-me;
|
||||
|
||||
// dum=0; //no hit
|
||||
tot=0;
|
||||
maxNei = 0;
|
||||
|
||||
if (val>nThSigma*sig)//{ //hit check if neighbors are higher
|
||||
dum=1;
|
||||
for (ir=-1; ir<2; ir++){
|
||||
for (ic=-1; ic<2; ic++){
|
||||
if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) {
|
||||
valNei = sign*decoder->getChannel(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean();
|
||||
if (sign*decoder->getChannel(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit!
|
||||
tot+=valNei;
|
||||
data[ir+1][ic+1] = valNei;
|
||||
if(valNei/stat[iy+ir][ix+ic].StandardDeviation() > maxNei){
|
||||
maxNei = valNei/stat[iy+ir][ix+ic].StandardDeviation();
|
||||
mx = ir;
|
||||
my = ic;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
if (val<(-nThSigma*sig)) dum=2; //discard negative events!
|
||||
|
||||
if(dum == 1 && mx == 0 && my == 0){ // this is an event and we are in the center
|
||||
storeEvent(nf,ix,iy,data,me,sig);
|
||||
nPhotons++;
|
||||
//cout << "BF X: " << ix << " Y: " << iy << " val: " << val << " tot: " << tot << " me: " << me << " sig: " << sig << endl;
|
||||
}
|
||||
|
||||
|
||||
//if (tot>9.*sig && dum == 1){ dum=3;}
|
||||
//cout << dum;
|
||||
}
|
||||
//if (ix==20 && iy==40)
|
||||
//cout << decoder->getChannelShort(buff,ix,iy)<< " " << val << " " << me << " " << sig << " " << dum << endl;
|
||||
|
||||
if ( dum==0) {
|
||||
|
||||
stat[iy][ix].Calc(decoder->getChannelShort(buff,ix,iy));
|
||||
}
|
||||
if (nf<nbg || dum==0)
|
||||
stat[iy][ix].Calc(sign*decoder->getChannel(buff,ix,iy));
|
||||
|
||||
}
|
||||
}
|
||||
delete [] buff;
|
||||
//cout << "="; cout.flush();
|
||||
if(nf>nbg) nPhotonsStat.Calc((double)nPhotons);
|
||||
nf++;
|
||||
}
|
||||
//cout << endl;
|
||||
cout << "processed File " << fname << " done. Avg. Photons/Frame: " << nPhotonsStat.Mean() << " sig: " << nPhotonsStat.StandardDeviation() << " " << runmax-irun << " files need processing" << endl;
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
else
|
||||
cout << "could not open file " << fname << endl;
|
||||
}
|
||||
|
||||
delete decoder;
|
||||
cout << "Read " << nf << " frames" << endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void *moenchMakeTreeTask(void *p){
|
||||
Task *t = (Task *)p;
|
||||
moenchMakeTree(t->fformat,t->tname,t->runmin,t->runmax,t->sign);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//to compile: g++ -DMYROOT -g `root-config --cflags --glibs` -o moenchMakeTree moenchMakeTree.C
|
||||
int main(int argc, char **argv){
|
||||
if(argc != 6){ cout << "Usage: inFile outdir tname fileNrStart fileNrEnd" << endl; exit(-1); }
|
||||
|
||||
int nThreads = 10;
|
||||
TThread *threads[nThreads];
|
||||
|
||||
char *inFile = argv[1];
|
||||
char *outDir = argv[2];
|
||||
char *tName = argv[3];
|
||||
int start = atoi(argv[4]);
|
||||
int end = atoi(argv[5]);
|
||||
|
||||
TFile *f;
|
||||
char outfname[1000];
|
||||
char threadName[1000];
|
||||
|
||||
sprintf(outfname,"%s/%s.root",outDir,tName);
|
||||
f=new TFile(outfname,"RECREATE");
|
||||
|
||||
cout << "outputfile: " << outfname << endl;
|
||||
setUpTree(tName);
|
||||
|
||||
for(int i = 0; i < nThreads; i++){
|
||||
sprintf(threadName,"t%i",i);
|
||||
Task *t = (Task *)malloc(sizeof(Task));
|
||||
t->fformat = inFile;
|
||||
t->tname = tName;
|
||||
t->sign = 1.;
|
||||
t->runmin = start + (end-start)/(nThreads)*i;
|
||||
t->runmax = start + (end-start)/(nThreads)*(i+1);
|
||||
if(i == nThreads - 1) t->runmax = end;
|
||||
cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl;
|
||||
threads[i] = new TThread(threadName, moenchMakeTreeTask, t);
|
||||
threads[i]->Run();
|
||||
//moenchMakeTreeTask(t);
|
||||
}
|
||||
|
||||
|
||||
//TThread::Ps();
|
||||
|
||||
for(int i = 0; i < nThreads; i++){
|
||||
threads[i]->Join();
|
||||
}
|
||||
|
||||
|
||||
tall->Write();
|
||||
tall->Print();
|
||||
f->Close();
|
||||
}
|
||||
|
238
slsDetectorCalibration/moenchReadData.C
Normal file
238
slsDetectorCalibration/moenchReadData.C
Normal file
@ -0,0 +1,238 @@
|
||||
#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 <stdio.h>
|
||||
//#include <deque>
|
||||
//#include <list>
|
||||
//#include <queue>
|
||||
#include <fstream>
|
||||
#include "moench02ModuleData.h"
|
||||
#include "moenchCommonMode.h"
|
||||
|
||||
#include "singlePhotonDetector.h"
|
||||
|
||||
//#include "MovingStat.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define NC 160
|
||||
#define NR 160
|
||||
|
||||
|
||||
#define MY_DEBUG 1
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
#include <TCanvas.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis.
|
||||
|
||||
\param fformat file name format
|
||||
\param tit title of the tree etc.
|
||||
\param runmin minimum run number
|
||||
\param runmax max run number
|
||||
\param nbins number of bins for spectrum hists
|
||||
\param hmin histo minimum for spectrum hists
|
||||
\param hmax histo maximum for spectrum hists
|
||||
\param sign sign of the spectrum to find hits
|
||||
\param hc readout correlation coefficient with previous pixel
|
||||
\param xmin minimum x coordinate
|
||||
\param xmax maximum x coordinate
|
||||
\param ymin minimum y coordinate
|
||||
\param ymax maximum y coordinate
|
||||
\param cmsub enable commonmode subtraction
|
||||
\returns pointer to histo stack with cluster spectra
|
||||
*/
|
||||
|
||||
|
||||
THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1) {
|
||||
|
||||
moench02ModuleData *decoder=new moench02ModuleData(hc);
|
||||
moenchCommonMode *cmSub=NULL;
|
||||
if (cmsub)
|
||||
cmSub=new moenchCommonMode();
|
||||
|
||||
int nph=0;
|
||||
|
||||
singlePhotonDetector<uint16_t> *filter=new singlePhotonDetector<uint16_t>(decoder, 3, 5, sign, cmSub);
|
||||
|
||||
char *buff;
|
||||
char fname[10000];
|
||||
int nf=0;
|
||||
|
||||
eventType thisEvent=PEDESTAL;
|
||||
|
||||
// int iframe;
|
||||
// double *data, ped, sigma;
|
||||
|
||||
// data=decoder->getCluster();
|
||||
|
||||
TH2F *h2;
|
||||
TH2F *h3;
|
||||
TH2F *hetaX;
|
||||
TH2F *hetaY;
|
||||
|
||||
THStack *hs=new THStack("hs",fformat);
|
||||
|
||||
|
||||
|
||||
TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
hs->Add(h1);
|
||||
|
||||
if (hitfinder) {
|
||||
h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5);
|
||||
hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5);
|
||||
hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5);
|
||||
hs->Add(h2);
|
||||
hs->Add(h3);
|
||||
hs->Add(hetaX);
|
||||
hs->Add(hetaY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ifstream filebin;
|
||||
|
||||
|
||||
int ix=20, iy=20, ir, ic;
|
||||
|
||||
|
||||
Int_t iFrame;
|
||||
TTree *tall;
|
||||
if (hitfinder)
|
||||
tall=filter->initEventTree(tit, &iFrame);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
|
||||
TCanvas *myC;
|
||||
TH2F *he;
|
||||
TCanvas *cH1;
|
||||
TCanvas *cH2;
|
||||
TCanvas *cH3;
|
||||
|
||||
if (hitfinder) {
|
||||
myC=new TCanvas();
|
||||
he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax);
|
||||
he->SetStats(kFALSE);
|
||||
he->Draw("colz");
|
||||
cH1=new TCanvas();
|
||||
cH1->SetLogz();
|
||||
h1->Draw("colz");
|
||||
cH2=new TCanvas();
|
||||
cH2->SetLogz();
|
||||
h2->Draw("colz");
|
||||
cH3=new TCanvas();
|
||||
cH3->SetLogz();
|
||||
h3->Draw("colz");
|
||||
}
|
||||
#endif
|
||||
filter->newDataSet();
|
||||
|
||||
|
||||
for (int irun=runmin; irun<runmax; irun++) {
|
||||
sprintf(fname,fformat,irun);
|
||||
cout << "file name " << fname << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
nph=0;
|
||||
while ((buff=decoder->readNextFrame(filebin))) {
|
||||
|
||||
|
||||
if (hitfinder) {
|
||||
filter->newFrame();
|
||||
|
||||
//calculate pedestals and common modes
|
||||
if (cmsub) {
|
||||
// cout << "cm" << endl;
|
||||
for (ix=xmin-1; ix<xmax+1; ix++)
|
||||
for (iy=ymin-1; iy<ymax+1; iy++) {
|
||||
thisEvent=filter->getEventType(buff, ix, iy,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cout << "new frame " << endl;
|
||||
|
||||
for (ix=xmin-1; ix<xmax+1; ix++)
|
||||
for (iy=ymin-1; iy<ymax+1; iy++) {
|
||||
// cout << ix << " " << iy << endl;
|
||||
thisEvent=filter->getEventType(buff, ix, iy, cmsub);
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
if (hitfinder) {
|
||||
if (iev%1000==0)
|
||||
he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (nf>1000) {
|
||||
h1->Fill(filter->getClusterTotal(1), iy+NR*ix);
|
||||
if (hitfinder) {
|
||||
|
||||
if (thisEvent==PHOTON_MAX ) {
|
||||
nph++;
|
||||
|
||||
h2->Fill(filter->getClusterTotal(2), iy+NR*ix);
|
||||
h3->Fill(filter->getClusterTotal(3), iy+NR*ix);
|
||||
iFrame=decoder->getFrameNumber(buff);
|
||||
|
||||
tall->Fill();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
if (iev%1000==0) {
|
||||
myC->Modified();
|
||||
myC->Update();
|
||||
cH1->Modified();
|
||||
cH1->Update();
|
||||
cH2->Modified();
|
||||
cH2->Update();
|
||||
cH3->Modified();
|
||||
cH3->Update();
|
||||
}
|
||||
iev++;
|
||||
#endif
|
||||
nf++;
|
||||
|
||||
cout << "=" ;
|
||||
delete [] buff;
|
||||
}
|
||||
cout << nph << endl;
|
||||
if (filebin.is_open())
|
||||
filebin.close();
|
||||
else
|
||||
cout << "could not open file " << fname << endl;
|
||||
}
|
||||
if (hitfinder)
|
||||
tall->Write(tall->GetName(),TObject::kOverwrite);
|
||||
|
||||
|
||||
|
||||
delete decoder;
|
||||
cout << "Read " << nf << " frames" << endl;
|
||||
return hs;
|
||||
}
|
||||
|
52
slsDetectorCalibration/moenchReadDataMT.C
Normal file
52
slsDetectorCalibration/moenchReadDataMT.C
Normal file
@ -0,0 +1,52 @@
|
||||
#include <TFile.h>
|
||||
#include <TThread.h>
|
||||
#include "moenchReadData.C"
|
||||
|
||||
typedef struct task_s{
|
||||
char *fformat;
|
||||
char *tname;
|
||||
char *tdir;
|
||||
int runmin;
|
||||
int runmax;
|
||||
int treeIndex;
|
||||
} Task;
|
||||
|
||||
void *moenchMakeTreeTask(void *p){
|
||||
TThread::Lock();
|
||||
char fname[1000];
|
||||
Task *t = (Task *)p;
|
||||
sprintf(fname,"%s%s_%i.root",t->tdir,t->tname,t->treeIndex);
|
||||
TFile *f = new TFile(fname,"RECREATE");
|
||||
cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<")" << endl;
|
||||
TThread::UnLock();
|
||||
moenchReadData(t->fformat,t->tname,t->runmin,t->runmax);
|
||||
f->Close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0){
|
||||
char threadName[1000];
|
||||
TThread *threads[nThreads];
|
||||
for(int i = 0; i < nThreads; i++){
|
||||
sprintf(threadName,"t%i",i);
|
||||
Task *t = (Task *)malloc(sizeof(Task));
|
||||
t->fformat = fformat;
|
||||
t->tname = tit;
|
||||
t->tdir = tdir;
|
||||
t->runmin = runmin + i*runoffset;
|
||||
t->runmax = runmin + (i+1)*runoffset - 1;
|
||||
t->treeIndex = treeIndexStart + i;
|
||||
cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl;
|
||||
threads[i] = new TThread(threadName, moenchMakeTreeTask, t);
|
||||
threads[i]->Run();
|
||||
}
|
||||
|
||||
for(int i = 0; i < nThreads; i++){
|
||||
threads[i]->Join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
51
slsDetectorCalibration/pedestalSubtraction.h
Normal file
51
slsDetectorCalibration/pedestalSubtraction.h
Normal file
@ -0,0 +1,51 @@
|
||||
#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) {if (i>0) stat.SetN(i); return stat.GetN();};
|
||||
|
||||
/** sets the moving average */
|
||||
virtual void setPedestal(double val, double rms=0) {stat.Set(val, rms);}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
MovingStat stat; /**< approximated moving average struct */
|
||||
|
||||
};
|
||||
#endif
|
136
slsDetectorCalibration/raedNoiseData.C
Normal file
136
slsDetectorCalibration/raedNoiseData.C
Normal file
@ -0,0 +1,136 @@
|
||||
#include "moenchReadData.C"
|
||||
|
||||
|
||||
|
||||
void raedNoiseData(char *tit, int sign=1){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char fname[1000];
|
||||
char f[1000];
|
||||
TFile *fout;
|
||||
THStack *hs2N;
|
||||
|
||||
sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_0.root",tit);
|
||||
fout=new TFile(fname,"RECREATE");
|
||||
|
||||
sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit);
|
||||
|
||||
hs2N=moenchReadData(fname,0,3000,1500,-500,2500,1,0.,1,159,1,159, 0,1);
|
||||
hs2N->SetName(tit);
|
||||
hs2N->SetTitle(tit);
|
||||
(TH2F*)(hs2N->GetHists()->At(0))->Write();
|
||||
|
||||
(TH2F*)(hs2N->GetHists()->At(1))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(2))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(3))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(4))->Write();
|
||||
|
||||
|
||||
fout->Close();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void raedNoiseDataN(char *tit, int sign=1){
|
||||
|
||||
|
||||
|
||||
char fname[1000];
|
||||
char f[1000];
|
||||
TFile *fout;
|
||||
THStack *hs2N;
|
||||
|
||||
sprintf(fname,"/data/moench_xbox_20140116/noise_%s.root",tit);
|
||||
fout=new TFile(fname,"RECREATE");
|
||||
|
||||
sprintf(fname,"/data/moench_xbox_20140116/noise_%s_f00000%%04d000_0.raw",tit);
|
||||
|
||||
hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,0);
|
||||
hs2N->SetName(tit);
|
||||
hs2N->SetTitle(tit);
|
||||
(TH2F*)(hs2N->GetHists()->At(0))->Write();
|
||||
|
||||
// (TH2F*)(hs2N->GetHists()->At(1))->Write();
|
||||
// (TH2F*)(hs2N->GetHists()->At(2))->Write();
|
||||
// (TH2F*)(hs2N->GetHists()->At(3))->Write();
|
||||
// (TH2F*)(hs2N->GetHists()->At(4))->Write();
|
||||
|
||||
|
||||
fout->Close();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void g4() {
|
||||
|
||||
raedNoiseData("cds_g4_low_gain");
|
||||
raedNoiseData("cds_g4_sto1_only");
|
||||
raedNoiseData("cds_g4_no sto");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void no_cds() {
|
||||
|
||||
raedNoiseData("cds_disable_low_gain",-1);
|
||||
raedNoiseData("cds_disable_sto1_only",-1);
|
||||
raedNoiseData("cds_disable_no sto",-1);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void all_gains() {
|
||||
|
||||
raedNoiseData("cds_g2");
|
||||
raedNoiseData("cds_g2HC");
|
||||
raedNoiseData("cds_g1_2");
|
||||
raedNoiseData("cds_g2_3");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void all_low_gains() {
|
||||
|
||||
raedNoiseData("cds_g2_low_gain");
|
||||
raedNoiseData("cds_g2HC_low_gain");
|
||||
raedNoiseData("cds_g1_2_low_gain");
|
||||
raedNoiseData("cds_g2_3_low_gain");
|
||||
}
|
||||
|
||||
/*
|
||||
clkdivider data
|
||||
/data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv17_f000000010000_0.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 12:40 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv25_f000000010000_0.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 13:26 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv35_f000000010000_0.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:09 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv50_f000000010000_0.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:54 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv70_f000000010000_0.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 16:42 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv110_f000000010000_0.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 17:27 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv170_f000000010000_0.raw
|
||||
*/
|
||||
|
||||
|
||||
/* oversampled data
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:12 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_0.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:47 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_1.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 19:22 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_2.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:02 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_3.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:41 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_4.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:16 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_5.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:56 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_6.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 22:35 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_7.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:11 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_8.raw
|
||||
-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:50 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_9.raw
|
||||
*/
|
||||
|
31
slsDetectorCalibration/readJungfrauData.C
Normal file
31
slsDetectorCalibration/readJungfrauData.C
Normal file
@ -0,0 +1,31 @@
|
||||
{ // script to run Jungfrau data analysis
|
||||
|
||||
gROOT->ProcessLine(".L jungfrauReadData.C++");//");
|
||||
|
||||
TFile *fout; // output file
|
||||
THStack *hs2N; // collection of objects
|
||||
|
||||
//fout=new TFile("/mnt/slitnas/datadir_jungfrau02/analysis_tests/tests_random.root","RECREATE"); //
|
||||
fout=new TFile("/mnt/slitnas/datadir_jungfrau02/20140404_lowEXrays/test.root","RECREATE");
|
||||
|
||||
hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140404_lowEXrays/Ti_1000clk_13kV40mA_%d.bin","tit",0,86,3000,-499.5,2500.5,1,0,1,47,1,47,1,1); //1,1);
|
||||
|
||||
//hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140228_GainBits/GSdata_laser_%d.bin","tit",0,5,1500,-500,2500,1,0.,1,47,1,47,0,1);//,"/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); //1,1); // data set test GB -> set (3,0,0) in junfrauReadData.C
|
||||
|
||||
//hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/digital_bit_adc_test/vb_1825_%d.bin","tit",0,7,1500,-500,2500,1,0.,1,47,1,47,0,1);//,"/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); //1,1); // data set test GB -> set (3,0,0) in junfrauReadData.C
|
||||
|
||||
//hs2N->SetName("cds_g4");
|
||||
//hs2N->SetTitle("cds_g4");
|
||||
|
||||
(TH2F*)(hs2N->GetHists()->At(0))->Write(); // write hists
|
||||
(TH2F*)(hs2N->GetHists()->At(1))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(2))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(3))->Write();
|
||||
(TH2F*)(hs2N->GetHists()->At(4))->Write();
|
||||
//(TH2F*)(hs2N->GetHists()->At(5))->Write();
|
||||
//(TH2F*)(hs2N->GetHists()->At(6))->Write();
|
||||
|
||||
fout->Close(); // uncomment
|
||||
|
||||
}
|
||||
|
366
slsDetectorCalibration/readMoench03Data.C
Normal file
366
slsDetectorCalibration/readMoench03Data.C
Normal file
@ -0,0 +1,366 @@
|
||||
#include "moench03ReadData.C"
|
||||
|
||||
|
||||
|
||||
void readMoench03Data(std::string path,char* tit, std::string phase, std::string wtime,int sign=1,int runmin=0, int runmax=100, int sc_num=0,int hitfinder=1){
|
||||
|
||||
// int runmin(150);
|
||||
// int runmax(200);
|
||||
int nbins(2000);
|
||||
int hmin(-1000);
|
||||
int hmax(3000);
|
||||
int xmin(1);
|
||||
int xmax(399);
|
||||
int ymin(1);
|
||||
int ymax(399);
|
||||
int cmsub(0);
|
||||
|
||||
|
||||
|
||||
|
||||
char fname[1000];
|
||||
TFile *fout;
|
||||
// TFile *fouth1;
|
||||
THStack *hs;
|
||||
sprintf(fname,"%s/%s_%s_%s_%d_%d_Csub%d_HF%d.root",path.c_str(),tit,phase.c_str(),wtime.c_str(),runmin,runmax-1,cmsub,hitfinder);
|
||||
fout=new TFile(fname,"RECREATE");
|
||||
cerr<<"creating output file:"<<endl;
|
||||
cerr<<fname<<endl;
|
||||
cerr<<"/****************************/"<<endl;
|
||||
|
||||
sprintf(fname,"%s/%s_%s_%s_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str()); // sprintf(fname,"%s/%s_phase%s_wtime%s_period0.075_OD%1.1f_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str(),OD);
|
||||
|
||||
cerr<<fname<<endl;
|
||||
|
||||
// Int_t out = moench03DrawPedestals(fname,"Mo",runmin,runmax,nbins,hmin,hmax,xmin,xmax,ymin,ymax, cmsub,hitfinder);
|
||||
|
||||
fout->cd();
|
||||
hs=moench03ReadData(fname,tit,runmin,runmax,nbins,hmin,hmax,xmin,xmax,ymin,ymax, cmsub,hitfinder);
|
||||
|
||||
|
||||
cout << "returned" << endl;
|
||||
hs->SetName(tit);
|
||||
hs->SetTitle(tit);
|
||||
cout << "name/title set" << endl;
|
||||
|
||||
Int_t nH=1;
|
||||
|
||||
TH2F * h=NULL;
|
||||
|
||||
|
||||
|
||||
if (hs->GetHists()) {
|
||||
for (int i=0; i<nH; i++) {
|
||||
if (hs->GetHists()->At(i)) {
|
||||
(TH2F*)(hs->GetHists()->At(i))->Write();
|
||||
// h->SetName(Form("h%d",i+1));
|
||||
// h->SetTitle(Form("h%d",i+1));
|
||||
// cerr<<h->GetEntries()<<" entries"<<endl;
|
||||
// can->cd(i+1);
|
||||
// h->Draw("colz");
|
||||
// fout->cd();
|
||||
// h->Write();
|
||||
cout << i << " " ;
|
||||
}
|
||||
}
|
||||
|
||||
cout << " histos written " << endl;
|
||||
} else
|
||||
cout << "no hists in stack " << endl;
|
||||
if(fout->IsOpen())fout->Close();
|
||||
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
/**********************************************************/
|
||||
void readPixelCharge(std::string path,char* tit, std::string phase, std::string wtime, float OD, int sign,int runmin, int runmax, int x0, int y0){
|
||||
char fname[1000];
|
||||
sprintf(fname,"%s/%s_%s_%2.0fumSi_%s_f0_%%d.raw",path.c_str(),tit,phase.c_str(),OD,wtime.c_str());
|
||||
char fnameout[1000];
|
||||
sprintf(fnameout,"%s/%s_%s_%2.0fumSi_%s.root",path.c_str(),tit,phase.c_str(),OD,wtime.c_str());
|
||||
// sprintf(fnameout,"%s/%s_phase%s_wtime%s_period0.2_OD%1.1f.root",path.c_str(),tit,phase.c_str(),wtime.c_str(),OD);
|
||||
TFile * fout = new TFile(fnameout,"recreate");
|
||||
|
||||
for(int i=0; i<12; i++){
|
||||
TH1F * hpix = SinglePixelHisto(fname,15000,-0.5,29999.5,runmin,runmax,x0+i,y0);
|
||||
hpix->SetName(Form("h_%d_%d",x0+i,y0));
|
||||
fout->cd();
|
||||
hpix->Write();
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
/*************************************************/
|
||||
void LoopOnPixelCharge(std::string path,char* tit, std::string phase, std::string wtime, int sign,int runmin, int runmax, int x0, int y0){
|
||||
float OD=700;
|
||||
|
||||
for(int i=0; i<6; i++){
|
||||
readPixelCharge(path,tit,phase,wtime,OD,sign,runmin,runmax,x0,y0);
|
||||
OD += 200;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**********************************************************/
|
||||
void readPixelCorrelation(std::string path,char* tit, std::string frame, std::string phase, std::string wtime,int sign,int runmin, int runmax,int supercolumn){
|
||||
|
||||
int npx(400);
|
||||
int npy(400);
|
||||
|
||||
char fname[1000];
|
||||
int sc_width(25);
|
||||
int sc_height(200);
|
||||
int sc_number=supercolumn;
|
||||
int xmin(0);
|
||||
int xmax(0);
|
||||
int ymin(0);
|
||||
int ymax(0);
|
||||
|
||||
|
||||
ADCMap * map = new ADCMap(npx,npy,sc_width,sc_height);
|
||||
int ret = map->Init();
|
||||
|
||||
xmin=map->getXmin(sc_number);
|
||||
xmax=map->getXmax(sc_number);
|
||||
ymin=map->getYmin(sc_number);
|
||||
ymax=map->getYmax(sc_number);
|
||||
|
||||
cerr<<"/**********************************/"<<endl;
|
||||
cerr<<"Checking super column "<<sc_number<<endl;
|
||||
cerr<<"x: "<<map->getXmin(sc_number)<<" - "<<map->getXmax(sc_number)<<endl;
|
||||
cerr<<"y: "<<map->getYmin(sc_number)<<" - "<<map->getYmax(sc_number)<<endl;
|
||||
cerr<<"/**********************************/"<<endl;
|
||||
|
||||
|
||||
|
||||
|
||||
char fnameout[1000];
|
||||
sprintf(fnameout,"%s/%s_wtime%s_%d_%d_Corr_SC%d.root",path.c_str(),tit,wtime.c_str(),runmin,runmax-1,sc_number);
|
||||
TFile * fout = new TFile(fnameout,"recreate");
|
||||
Int_t nbins(3000);
|
||||
Float_t xlow(6999.5);
|
||||
Float_t xup(9999.5);
|
||||
TH2F * hcorr=NULL;
|
||||
for(int i=0; i<25; i++){
|
||||
phase.clear();
|
||||
phase=(std::string)Form("%d",i*5);
|
||||
cerr<<"check ADC phase "<<phase.c_str()<<endl;
|
||||
|
||||
sprintf(fname,"%s/%s_phase%s_wtime%s_period0.075_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str());
|
||||
// TH1F * h1 = new TH1F("h1",Form("ch%d",nchan1),nbins,xlow,xup);
|
||||
// TH1F * h2 = new TH1F("h2",Form("ch%d",nchan2),nbins,xlow,xup);
|
||||
|
||||
hcorr= new TH2F(Form("hcorr_ph%s",phase.c_str()),Form("hcorr_ph%s",phase.c_str()),nbins,xlow,xup,nbins,xlow,xup);
|
||||
|
||||
DrawAllPixelCorrelation(fname,frame,runmin,runmax,xmin,xmax,ymin,ymax,sc_width,hcorr);
|
||||
// h1->GetXaxis()->SetTitle("ADC");
|
||||
// h2->GetXaxis()->SetTitle("ADC");
|
||||
|
||||
|
||||
|
||||
fout->cd();
|
||||
// h1->Write();
|
||||
// h2->Write();
|
||||
hcorr->Write();
|
||||
}
|
||||
return;
|
||||
fout->Close();
|
||||
}
|
||||
|
||||
|
||||
/****************************************************/
|
||||
void readNoise(std::string path, char *tit, std::string flag, std::string phase, std::string wtime,float OD,int sign,int runmin, int runmax){
|
||||
TFile * fout = new TFile(Form("%s/%s_%s_%s_noiseMap%s.root",path.c_str(),tit,phase.c_str(),wtime.c_str(),flag.c_str()),"recreate");
|
||||
char fname[1000];
|
||||
int nfiles=runmax-runmin;
|
||||
// int runmin(382);
|
||||
// int runmax(442);
|
||||
// std::string target("Cu");
|
||||
|
||||
|
||||
|
||||
// THStack * hsnoise = NULL;
|
||||
TH2F * hped=NULL;
|
||||
TH2F * hnoise=NULL;
|
||||
// for(int i=0; i<25; i++){
|
||||
// phase.clear();
|
||||
// phase=(std::string)Form("%d",i*5);
|
||||
// sprintf(fname,"%s/%s_phase%s_wtime%s_period0.2_OD%1.1f_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str(),OD);
|
||||
// sprintf(fname,"%s/%s_phase%s_wtime%s_period0.2_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str());
|
||||
sprintf(fname,"%s/%s_%s_%s_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str());
|
||||
THStack * hsnoise=calcNoise(fname,flag,runmin,runmax,nfiles);
|
||||
hsnoise->SetName(Form("%s_noiseMap_ph%s",tit,phase.c_str()));
|
||||
|
||||
fout->cd();
|
||||
|
||||
if (hsnoise->GetHists()) {
|
||||
hped=(TH2F*)(hsnoise->GetHists()->At(0));
|
||||
hped->SetName(Form("hped_ph%s",phase.c_str()));
|
||||
hped->Write();
|
||||
hnoise=(TH2F*)(hsnoise->GetHists()->At(1));
|
||||
hnoise->SetName(Form("hnoise_ph%s",phase.c_str()));
|
||||
hnoise->Write();
|
||||
cout << " histos written for ADC Phase " << phase.c_str()<<endl;
|
||||
} else
|
||||
cout << "no hists in stack " << endl;
|
||||
delete hsnoise;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
fout->Close();
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
/************************************************************************/
|
||||
void readFrames(std::string path, char *tit, std::string phase, std::string wtime,int sign,int runnum, int framemin, int framemax){
|
||||
char fformat[1000];
|
||||
char fname[1000];
|
||||
sprintf(fformat,"%s/%s_phase%s_wtime%s_period0.075_f0_%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str(),runnum);
|
||||
THStack * hs = DrawFrames(fformat,framemin,framemax);
|
||||
int nframes=framemax-framemin;
|
||||
TFile * fout = new TFile(Form("%s/Frames_phase%s_wtime%s_period0.075_f0_%d_fr%d-%d.root",path.c_str(),phase.c_str(),wtime.c_str(),runnum,framemin,framemax),"recreate");
|
||||
|
||||
TCanvas * c1= new TCanvas("c1","",800,600);
|
||||
c1->Print(Form("%s/Frames_phase%s_wtime%s_period0.075_f0_%d_fr%d-%d.pdf[",path.c_str(),phase.c_str(),wtime.c_str(),runnum,framemin,framemax));
|
||||
TH2F * h=NULL;
|
||||
|
||||
for(int hnum=0; hnum<nframes; hnum++){
|
||||
h=(TH2F*)hs->GetHists()->At(hnum);
|
||||
h->SetName(Form("h_%d",hnum+framemin));
|
||||
h->SetTitle(Form("h_%d",hnum+framemin));
|
||||
h->GetZaxis()->SetRangeUser(5000.,10000.);
|
||||
h->Draw("colz");
|
||||
|
||||
|
||||
c1->Print(Form("%s/Frames_phase%s_wtime%s_period0.075_f0_%d_fr%d-%d.pdf",path.c_str(),phase.c_str(),wtime.c_str(),runnum,framemin,framemax));
|
||||
fout->cd();
|
||||
h->Write();
|
||||
|
||||
|
||||
}
|
||||
|
||||
c1->Print(Form("%s/Frames_phase%s_wtime%s_period0.075_f0_%d_fr%d-%d.pdf]",path.c_str(),phase.c_str(),wtime.c_str(),runnum,framemin,framemax));
|
||||
|
||||
fout->Close();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
/************************************************************************************/
|
||||
void PlotSinglePixelHisto(std::string path, char *tit, std::string flag, std::string phase, std::string wtime,float OD,int sign,int runmin, int runmax, int x0, int y0){
|
||||
char fname[1000];
|
||||
sprintf(fname,"%s/%s_%s_%s_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str());
|
||||
|
||||
int nbins(8000);
|
||||
float xmin(-0.5);
|
||||
float xmax(15999.5);
|
||||
|
||||
TH1F * h1 = SinglePixelHisto(fname,nbins,xmin,xmax,runmin,runmax,x0,y0);
|
||||
h1->Draw("hist");
|
||||
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
// void raedNoiseDataN(char *tit, int sign=1){
|
||||
|
||||
|
||||
|
||||
// char fname[1000];
|
||||
// char f[1000];
|
||||
// TFile *fout;
|
||||
// THStack *hs2N;
|
||||
|
||||
// sprintf(fname,"/data/moench_xbox_20140116/noise_%s.root",tit);
|
||||
// fout=new TFile(fname,"RECREATE");
|
||||
|
||||
// sprintf(fname,"/data/moench_xbox_20140116/noise_%s_f00000%%04d000_0.raw",tit);
|
||||
|
||||
// hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,0);
|
||||
// hs2N->SetName(tit);
|
||||
// hs2N->SetTitle(tit);
|
||||
// (TH2F*)(hs2N->GetHists()->At(0))->Write();
|
||||
|
||||
// // (TH2F*)(hs2N->GetHists()->At(1))->Write();
|
||||
// // (TH2F*)(hs2N->GetHists()->At(2))->Write();
|
||||
// // (TH2F*)(hs2N->GetHists()->At(3))->Write();
|
||||
// // (TH2F*)(hs2N->GetHists()->At(4))->Write();
|
||||
|
||||
|
||||
// fout->Close();
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// void g4() {
|
||||
|
||||
// raedNoiseData("cds_g4_low_gain");
|
||||
// raedNoiseData("cds_g4_sto1_only");
|
||||
// raedNoiseData("cds_g4_no sto");
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// void no_cds() {
|
||||
|
||||
// raedNoiseData("cds_disable_low_gain",-1);
|
||||
// raedNoiseData("cds_disable_sto1_only",-1);
|
||||
// raedNoiseData("cds_disable_no sto",-1);
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// void all_gains() {
|
||||
|
||||
// raedNoiseData("cds_g2");
|
||||
// raedNoiseData("cds_g2HC");
|
||||
// raedNoiseData("cds_g1_2");
|
||||
// raedNoiseData("cds_g2_3");
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// void all_low_gains() {
|
||||
|
||||
// raedNoiseData("cds_g2_low_gain");
|
||||
// raedNoiseData("cds_g2HC_low_gain");
|
||||
// raedNoiseData("cds_g1_2_low_gain");
|
||||
// raedNoiseData("cds_g2_3_low_gain");
|
||||
// }
|
||||
|
||||
// /*
|
||||
// clkdivider data
|
||||
// /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv17_f000000010000_0.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 12:40 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv25_f000000010000_0.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 13:26 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv35_f000000010000_0.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:09 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv50_f000000010000_0.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:54 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv70_f000000010000_0.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 16:42 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv110_f000000010000_0.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 17:27 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv170_f000000010000_0.raw
|
||||
// */
|
||||
|
||||
|
||||
// /* oversampled data
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:12 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_0.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:47 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_1.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 19:22 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_2.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:02 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_3.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:41 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_4.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:16 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_5.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:56 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_6.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 22:35 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_7.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:11 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_8.raw
|
||||
// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:50 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_9.raw
|
||||
// */
|
||||
|
519
slsDetectorCalibration/singlePhotonDetector.h
Normal file
519
slsDetectorCalibration/singlePhotonDetector.h
Normal file
@ -0,0 +1,519 @@
|
||||
#ifndef SINGLEPHOTONDETECTOR_H
|
||||
#define SINGLEPHOTONDETECTOR_H
|
||||
|
||||
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
#include "single_photon_hit.h"
|
||||
#include "pedestalSubtraction.h"
|
||||
#include "commonModeSubtraction.h"
|
||||
|
||||
|
||||
//#define MYROOT1
|
||||
|
||||
#ifdef MYROOT1
|
||||
#include <TTree.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
enum eventType {
|
||||
PEDESTAL=0,
|
||||
NEIGHBOUR=1,
|
||||
PHOTON=2,
|
||||
PHOTON_MAX=3,
|
||||
NEGATIVE_PEDESTAL=4,
|
||||
UNDEFINED_EVENT=-1
|
||||
};
|
||||
|
||||
#ifndef DEF_QUAD
|
||||
#define DEF_QUAD
|
||||
enum quadrant {
|
||||
TOP_LEFT=0,
|
||||
TOP_RIGHT=1,
|
||||
BOTTOM_LEFT=2,
|
||||
BOTTOM_RIGHT=3,
|
||||
UNDEFINED_QUADRANT=-1
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
template <class dataType>
|
||||
class 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
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
singlePhotonDetector(slsDetectorData<dataType> *d,
|
||||
int csize=3,
|
||||
double nsigma=5,
|
||||
int sign=1,
|
||||
commonModeSubtraction *cm=NULL,
|
||||
int nped=1000,
|
||||
int nd=100) : det(d), nx(0), ny(0), stat(NULL), cmSub(cm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), cluster(NULL), iframe(-1), dataSign(sign), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) {
|
||||
|
||||
|
||||
det->getDetectorSize(nx,ny);
|
||||
|
||||
|
||||
|
||||
stat=new pedestalSubtraction*[ny];
|
||||
eventMask=new eventType*[ny];
|
||||
for (int i=0; i<ny; i++) {
|
||||
stat[i]=new pedestalSubtraction[nx];
|
||||
stat[i]->SetNPedestals(nped);
|
||||
eventMask[i]=new eventType[nx];
|
||||
}
|
||||
|
||||
if (ny==1)
|
||||
clusterSizeY=1;
|
||||
|
||||
cluster=new single_photon_hit(clusterSize,clusterSizeY);
|
||||
setClusterSize(csize);
|
||||
|
||||
};
|
||||
/**
|
||||
destructor. Deletes the cluster structure and the pdestalSubtraction array
|
||||
*/
|
||||
virtual ~singlePhotonDetector() {delete cluster; for (int i=0; i<ny; i++) delete [] stat[i]; delete [] stat;};
|
||||
|
||||
|
||||
/** resets the pedestalSubtraction array and the commonModeSubtraction */
|
||||
void newDataSet(){iframe=-1; for (int iy=0; iy<ny; iy++) for (int ix=0; ix<nx; ix++) stat[iy][ix].Clear(); if (cmSub) cmSub->Clear(); };
|
||||
|
||||
/** resets the eventMask to undefined and the commonModeSubtraction */
|
||||
void newFrame(){iframe++; for (int iy=0; iy<ny; iy++) for (int ix=0; ix<nx; ix++) eventMask[iy][ix]=UNDEFINED_EVENT; 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;};
|
||||
|
||||
|
||||
/**
|
||||
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
|
||||
*/
|
||||
virtual void addToPedestal(double val, int ix, int iy){
|
||||
// cout << "*"<< ix << " " << iy << " " << val << endl;
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
// cout << ix << " " << iy << " " << val << endl;
|
||||
stat[iy][ix].addToPedestal(val);
|
||||
if (cmSub && det->isGood(ix, iy) )
|
||||
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)
|
||||
*/
|
||||
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
|
||||
*/
|
||||
double getPedestalRMS(int ix, int iy){if (ix>=0 && ix<nx && iy>=0 && iy<ny) return stat[iy][ix].getPedestalRMS();else return -1;};
|
||||
|
||||
|
||||
/**
|
||||
sets pedestal
|
||||
\param ix pixel x coordinate
|
||||
\param iy pixel y coordinate
|
||||
\param val value to set
|
||||
*/
|
||||
virtual void setPedestal(int ix, int iy, double val, double rms=0){if (ix>=0 && ix<nx && iy>=0 && iy<ny) stat[iy][ix].setPedestal(val,rms);};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** 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>1)
|
||||
clusterSizeY=clusterSize;
|
||||
cluster=new single_photon_hit(clusterSize,clusterSizeY);
|
||||
}
|
||||
return clusterSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int *getNPhotons(char *data, double thr=-1) {
|
||||
|
||||
double val;
|
||||
int *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 tthr=thr;
|
||||
int nn;
|
||||
double max=0, tl=0, tr=0, bl=0,br=0, v;
|
||||
|
||||
|
||||
if (thr>=0) {
|
||||
cy=1;
|
||||
cs=1;
|
||||
ccs=1;
|
||||
ccy=1;
|
||||
}
|
||||
|
||||
|
||||
for (int ix=0; ix<nx; ix++) {
|
||||
for (int iy=0; iy<ny; iy++) {
|
||||
|
||||
val=dataSign*(det->getValue(data, ix, iy)-getPedestal(ix,iy,0));
|
||||
|
||||
if (thr<=0) tthr=nSigma*getPedestalRMS(ix,iy);
|
||||
|
||||
nn=val/tthr;
|
||||
|
||||
if (nn>0) {
|
||||
rest[iy][ix]=val-nn*tthr;
|
||||
nph[ix+nx*iy]=nn;
|
||||
} else {
|
||||
rest[iy][ix]=val;
|
||||
nph[ix+nx*iy]=0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for (int ix=clusterSize/2; ix<clusterSize/2-1; ix++) {
|
||||
for (int iy=clusterSizeY/2; iy<ny-clusterSizeY/2; iy++) {
|
||||
eventMask[iy][ix]=PEDESTAL;
|
||||
|
||||
if (thr<=0) tthr=nSigma*getPedestalRMS(ix,iy);
|
||||
|
||||
max=0;
|
||||
tl=0;
|
||||
tr=0;
|
||||
bl=0;
|
||||
br=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]=PHOTON;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if (cluster->get_data(0,0)>=max) {
|
||||
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 (rest[iy][ix]>tthr || tot>sqrt(ccy*ccs)*tthr || quadTot>sqrt(cy*cs)*tthr) {
|
||||
nph[ix+nx*iy]++;
|
||||
rest[iy][ix]-=tthr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return nph;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 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;
|
||||
|
||||
|
||||
|
||||
tot=0;
|
||||
quadTot=0;
|
||||
quad=UNDEFINED_QUADRANT;
|
||||
|
||||
|
||||
if (iframe<nDark) {
|
||||
if (cm==0) {
|
||||
// cout << "=" << endl;
|
||||
addToPedestal(det->getValue(data, ix, iy),ix,iy);
|
||||
cluster->set_data(dataSign*(det->getValue(data, ix, iy)-getPedestal(ix,iy,cm)), 0,0 );
|
||||
// cout << "=" << endl;
|
||||
}
|
||||
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) {
|
||||
cluster->set_data(dataSign*(det->getValue(data, ix+ic, iy+ir)-getPedestal(ix+ic,iy+ir,cm)), 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)
|
||||
addToPedestal(det->getValue(data, ix, iy),ix,iy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return eventMask[iy][ix];
|
||||
|
||||
};
|
||||
|
||||
/**<
|
||||
retrurns 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;};
|
||||
|
||||
/** 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();};
|
||||
|
||||
/** 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");
|
||||
return tall;
|
||||
};
|
||||
#else
|
||||
/** write cluster to filer*/
|
||||
void writeCluster(FILE* myFile){cluster->write(myFile);};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
private:
|
||||
|
||||
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 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 */
|
||||
int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */
|
||||
int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */
|
||||
quadrant quad; /**< quadrant where the photon is located */
|
||||
double tot; /**< sum of the 3x3 cluster */
|
||||
double quadTot; /**< sum of the maximum 2x2cluster */
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
62
slsDetectorCalibration/single_photon_hit.h
Normal file
62
slsDetectorCalibration/single_photon_hit.h
Normal file
@ -0,0 +1,62 @@
|
||||
#ifndef SINGLE_PHOTON_HIT_H
|
||||
#define SINGLE_PHOTON_HIT_h
|
||||
|
||||
typedef double double32_t;
|
||||
typedef float float32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
|
||||
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, int ny=1): 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
|
||||
*/
|
||||
void write(FILE *myFile) {fwrite((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);};
|
||||
|
||||
/**
|
||||
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
|
||||
*/
|
||||
void read(FILE *myFile) {fread((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fread((void*)data, 1, dx*dy*sizeof(double), myFile);};
|
||||
|
||||
/**
|
||||
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;};
|
||||
|
||||
|
||||
/**
|
||||
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];};
|
||||
|
||||
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*/
|
||||
int iframe; /**< frame number */
|
||||
double *data; /**< pointer to data */
|
||||
const int dx; /**< size of data cluster in x */
|
||||
const int dy; /**< size of data cluster in y */
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
300
slsDetectorCalibration/slsDetectorData.h
Normal file
300
slsDetectorCalibration/slsDetectorData.h
Normal file
@ -0,0 +1,300 @@
|
||||
#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;
|
||||
}
|
||||
// }
|
||||
|
||||
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;*/
|
||||
|
||||
if (dMap==NULL) {
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);
|
||||
} else {
|
||||
//cout << "set dmap "<< dataMap << " " << dMap << endl;
|
||||
for (int iy=0; iy<ny; iy++){
|
||||
// cout << iy << endl;
|
||||
for (int 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*/
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
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) {
|
||||
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
|
178
slsDetectorCalibration/viewMoenchDRXRays.C
Normal file
178
slsDetectorCalibration/viewMoenchDRXRays.C
Normal file
@ -0,0 +1,178 @@
|
||||
|
||||
#define MYROOT1
|
||||
|
||||
#include <TH1D.h>
|
||||
#include <TF1.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 <stdio.h>
|
||||
#include <fstream>
|
||||
#include "moench03CtbData.h"
|
||||
//#include "moench03CommonMode.h"
|
||||
//#include "singlePhotonDetector.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
THStack *viewMoenchDRXRays(int ix=70, int iy=88){
|
||||
|
||||
TF1 *poiss = new TF1("poiss", "[0]*TMath::Power(([1]/[2]),(x/[2]))*(TMath::Exp( ([1]/[2])))/TMath::Gamma((x/[2])+1)", 0, 5);
|
||||
|
||||
|
||||
int thick[]={1700,1500,1300,1100,900,700};
|
||||
int nt=6;
|
||||
int nf=5;
|
||||
char fname[1000];
|
||||
char *data;
|
||||
char tit[100];
|
||||
TH1F *hh[nt], *hh3[nt], *hh5[nt];
|
||||
TH2F *h2[nt], *hpix[nt];
|
||||
Double_t val, val3, val5, val1;
|
||||
int it=0;
|
||||
Double_t ped[25];
|
||||
TH1D *p;
|
||||
|
||||
THStack *hs=new THStack();
|
||||
cout << nt << endl;
|
||||
ifstream filebin;
|
||||
moench03CtbData *decoder=new moench03CtbData();
|
||||
|
||||
sprintf(tit,"hpix_%dumSi_g1",thick[it]);
|
||||
cout << tit << endl;
|
||||
|
||||
|
||||
hpix[it]=new TH2F(tit,tit,2500,6000,16000,25,0,25);
|
||||
hs->Add(hpix[it]);
|
||||
|
||||
sprintf(tit,"%dumSi_g1",thick[it]);
|
||||
cout << tit << endl;
|
||||
|
||||
for (int iff=0; iff<nf; iff++) {
|
||||
// cout << tit << " " << iff << endl;
|
||||
sprintf(fname,"/mnt/moench/Moench03_MS_20150606/direct_beam_12.4keV_filter_scan/direct_beam_12.4keV_%s_400clk_f0_%d.raw",tit,iff);
|
||||
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
if (filebin.is_open()) cout << "ok "<< fname << endl;
|
||||
else cout << "could not open "<< fname << endl;
|
||||
|
||||
while ((data=decoder->readNextFrame(filebin))) {
|
||||
|
||||
for (int iiy=-2; iiy<3; iiy++)
|
||||
for (int iix=-2; iix<3; iix++)
|
||||
hpix[it]->Fill(decoder->getChannel(data,ix+iix,iy+iiy), (iiy+2)*5+iix+2);
|
||||
|
||||
delete [] data;
|
||||
}
|
||||
filebin.close();
|
||||
cout << endl;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (int iix=-2; iix<3; iix++) {
|
||||
for (int iiy=-2; iiy<3; iiy++) {
|
||||
cout << iix << " " << iiy << " " ;// <<endl;
|
||||
p=hpix[0]->ProjectionX("p",(iiy+2)*5+iix+2+1,(2+iiy)*5+iix+2+1);
|
||||
|
||||
ped[(iiy+2)*5+iix+2]=p->GetBinCenter(p->GetMaximumBin());
|
||||
|
||||
cout << ped[(iiy+2)*5+iix+2] <<endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (it=0; it<nt; it++) {
|
||||
|
||||
sprintf(tit,"hh_%dumSi_g1",thick[it]);
|
||||
cout << tit << endl;
|
||||
hh[it]=new TH1F(tit,tit,5000,0,10000);
|
||||
hs->Add(hh[it]);
|
||||
sprintf(tit,"hh3_%dumSi_g1",thick[it]);
|
||||
hh3[it]=new TH1F(tit,tit,5000,0,30000);
|
||||
hs->Add(hh3[it]);
|
||||
|
||||
sprintf(tit,"hh5_%dumSi_g1",thick[it]);
|
||||
hh5[it]=new TH1F(tit,tit,5000,0,50000);
|
||||
hs->Add(hh5[it]);
|
||||
|
||||
sprintf(tit,"%dumSi_g1",thick[it]);
|
||||
cout << tit << endl;
|
||||
hs->Add(hh[it]);
|
||||
for (int iff=0; iff<nf; iff++) {
|
||||
// cout << tit << " " << iff << endl;
|
||||
sprintf(fname,"/mnt/moench/Moench03_MS_20150606/direct_beam_12.4keV_filter_scan/direct_beam_12.4keV_%s_400clk_f0_%d.raw",tit,iff);
|
||||
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
if (filebin.is_open()) cout << "ok "<< fname << endl;
|
||||
else cout << "could not open "<< fname << endl;
|
||||
|
||||
while ((data=decoder->readNextFrame(filebin))) {
|
||||
cout << "-" ;
|
||||
// for (int iy=0; iy<40; iy++)
|
||||
// for (int ix=0; ix<350; ix++){
|
||||
|
||||
|
||||
|
||||
|
||||
val1=0;
|
||||
val3=0;
|
||||
val5=0;
|
||||
|
||||
|
||||
for (int iix=-2; iix<3; iix++) {
|
||||
for (int iiy=-2; iiy<3; iiy++) {
|
||||
// cout << iix << " " << iiy << " " ;// <<endl;
|
||||
// p=hpix[]->ProjectionX("p",(iiy+2)*5+iix+2+1,(2+iiy)*5+iix+2+1);
|
||||
|
||||
// ped[it]=p->GetBinCenter(p->GetMaximumBin());
|
||||
|
||||
// cout << ped[it] <<endl;
|
||||
val=decoder->getChannel(data,ix+iix,iy+iiy)-ped[(iiy+2)*5+iix+2];
|
||||
if ((iix<-1 || iix>1) || (iiy<-1 || iiy>1))
|
||||
val5+=val;
|
||||
else if (iix!=0 || iiy!=0) {
|
||||
val5+=val;
|
||||
val3+=val;
|
||||
} else {
|
||||
val5+=val;
|
||||
val3+=val;
|
||||
val1+=val;
|
||||
}
|
||||
// if (iiy==1 && iix==0)
|
||||
// h2[it]->Fill(val1,val);
|
||||
|
||||
}
|
||||
}
|
||||
hh5[it]->Fill(val5);
|
||||
hh3[it]->Fill(val3);
|
||||
hh[it]->Fill(val1);
|
||||
|
||||
|
||||
|
||||
delete [] data;
|
||||
}
|
||||
filebin.close();
|
||||
cout << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return hs;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user