some changes in slsCalibration for moench

This commit is contained in:
2018-03-15 12:26:45 +01:00
parent e95b444908
commit 10209b75df
22 changed files with 842 additions and 1050 deletions

View File

@ -11,23 +11,29 @@ MAIN=moench03ClusterFinder.cpp
#-lhdf5
#DESTDIR?=../bin
all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation
all: moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter moenchAnalog
moenchClusterFinder: $(MAIN) $(INCS) clean
g++ -o moenchClusterFinder $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DOLDDATA
g++ -o moenchClusterFinder $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DOLDDATA #-DNEWRECEIVER
moenchMakeEta: moench03MakeEta.cpp $(INCS) clean
g++ -o moenchMakeEta moench03MakeEta.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
moenchInterpolation: moench03Interpolation.cpp $(INCS) clean
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
g++ -o moenchInterpolation moench03Interpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
moenchNoInterpolation: moench03NoInterpolation.cpp $(INCS) clean
g++ -o moenchNoInterpolation moench03NoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL
moenchPhotonCounter: moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchPhotonCounter moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER
moenchAnalog: moenchPhotonCounter.cpp $(INCS) clean
g++ -o moenchAnalog moenchPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER -DANALOG
clean:
rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation
rm -f moenchClusterFinder moenchMakeEta moenchInterpolation moenchNoInterpolation moenchPhotonCounter

View File

@ -119,53 +119,11 @@ int main(int argc, char *argv[]) {
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "fileformat is " << fformat << endl;
// cout << "pedestal file is " << fformat << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
// filter->setFrameMode(eFrame);
// mt->setFrameMode(ePedestal);
// cout << pedfname<< endl;
// filebin.open((const char *)(pedfname), ios::in | ios::binary);
// //filebin.open((const char *)(fname), ios::in | ios::binary);
// // //open file
// if (filebin.is_open()){
// // //while read frame
// cout << "pedestal file " << endl;
// while (decoder->readNextFrame(filebin, ff, np,data)) {
// // cout << ff << " " << np << endl;
// // //push
// // mt->pushData(buff);
// // // //pop
// //mt->nextThread();
// // // // cout << " " << (void*)buff;
// //mt->popFree(buff);
// filter->processData(data);
// }
// filebin.close();
// // //close file
// // //join threads
// // while (mt->isBusy()) {;}//wait until all data are processed from the queues
// // cout << outfname << endl;
// // filter->writePedestals(outfname);
// // sprintf(outfname,"%s/%s_pedimg.tiff",outdir,fn);
// // cout << outfname << endl;
// // filter->writeImage(outfname);
// // //mt->clearImage();
// } else
// cout << "Could not open "<< pedfname << " for reading " << endl;
// // for (int ix=0; ix<400; ix++)
// // for (int iy=0; iy<400; iy++)
// // cout << ix << " " << iy << " " << filter->getPedestal(ix,iy) << " " << filter->getPedestalRMS(ix,iy) << endl;
@ -176,9 +134,7 @@ int main(int argc, char *argv[]) {
char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
// mt->setFrameMode(eFrame); //need to find a way to switch between flat and frames!
// mt->prepareInterpolation(ok);
mt->setFrameMode(eFrame);
mt->StartThreads();
mt->popFree(buff);
@ -187,46 +143,7 @@ int main(int argc, char *argv[]) {
cout << "mt " << endl;
int ifr=0;
// //loop on files
// mt->setFrameMode(eFrame);
//mt->setFrameMode(eFlat);
// for (int irun=runmin; irun<runmin+5; irun++) {
// sprintf(fn,fformat,irun);
// sprintf(fname,"%s/%s.raw",indir,fn);
// filebin.open((const char *)(fname), ios::in | ios::binary);
// // //open file
// if (filebin.is_open()){
// // //while read frame
// while (decoder->readNextFrame(filebin, ff, np,buff)) {
// // cout << "*"<<ifr++<<"*"<<ff<< endl;
// // cout << ff << " " << np << endl;
// // //push
// mt->pushData(buff);
// // // //pop
// mt->nextThread();
// // // // cout << " " << (void*)buff;
// mt->popFree(buff);
// }
// // cout << "--" << endl;
// filebin.close();
// }
// }
// while (mt->isBusy()) {;}//wait until all data are processed from the queues
// mt->clearImage();
for (int irun=runmin; irun<runmax; irun++) {
sprintf(fn,fformat,irun);
@ -259,6 +176,8 @@ int main(int argc, char *argv[]) {
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr%10000==0) cout << ifr << " " << ff << endl;
ff=-1;
}
cout << "--" << endl;

View File

@ -2,53 +2,101 @@
#include "ansi.h"
#include <iostream>
#include "moench03T1ZmqData.h"
#include "single_photon_hit.h"
//#include "moench03T1ZmqData.h"
//#define DOUBLE_SPH
//#define MANYFILES
// #include "etaInterpolationPosXY.h"
#include "etaInterpolationAdaptiveBins.h"
#ifdef DOUBLE_SPH
#include "single_photon_hit_double.h"
#endif
#ifndef DOUBLE_SPH
#include "single_photon_hit.h"
#endif
#include "etaInterpolationPosXY.h"
#include "noInterpolation.h"
//#include "etaInterpolationAdaptiveBins.h"
//#include "etaInterpolationRandomBins.h"
using namespace std;
#define NC 400
#define NR 400
#define XTALK
int main(int argc, char *argv[]) {
/**
* trial.o [socket ip] [starting port number] [outfname]
*
*/
if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " etafile outfile runmin runmax ns" << endl;
if (argc<9) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " etafile outfile runmin runmax ns cmin cmax" << endl;
return 1;
}
char infname[10000];
char fname[10000];
char outfname[10000];
int runmin=atoi(argv[4]);
int runmax=atoi(argv[5]);
int nsubpix=atoi(argv[6]);
float cmin=atof(argv[7]);
float cmax=atof(argv[8]);
int etabins=1000;//nsubpix*2*100;
double etamin=-1, etamax=2;
double eta3min=-2, eta3max=2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ok;
int f0=-1;
int ix, iy, isx, isy;
int nframes=0, lastframe=-1;
double d_x, d_y, res=5, xx, yy;
#ifdef MANYFILES
int ff=1000;
#endif
int nph=0, badph=0, totph=0;
FILE *f=NULL;
#ifdef DOUBLE_SPH
single_photon_hit_double cl(3,3);
#endif
#ifndef DOUBLE_SPH
single_photon_hit cl(3,3);
// etaInterpolationPosXY *interp=new etaInterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
etaInterpolationAdaptiveBins *interp=new etaInterpolationAdaptiveBins (NC, NR, nsubpix, etabins, etamin, etamax);
#endif
#ifdef XTALK
int old_val[3][3];
int new_val[3][3];
double xcorr=0.04;
// int ix=0;
#endif
eta2InterpolationPosXY *interp=new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
eta3InterpolationPosXY *interp3=new eta3InterpolationPosXY(NC, NR, nsubpix, etabins, eta3min, eta3max);
noInterpolation *dummy=new noInterpolation(NC, NR, nsubpix);
noInterpolation *nointerp=new noInterpolation(NC, NR, nsubpix);
noInterpolation *mult=new noInterpolation(NC, NR, nsubpix);
//etaInterpolationAdaptiveBins *interp=new etaInterpolationAdaptiveBins (NC, NR, nsubpix, etabins, etamin, etamax);
//etaInterpolationRandomBins *interp=new etaInterpolationRandomBins (NC, NR, nsubpix, etabins, etamin, etamax);
//#ifndef FF
cout << "read ff " << argv[2] << endl;
interp->readFlatField(argv[2]);
sprintf(fname,"%s_eta2.tiff",argv[2]);
interp->readFlatField(fname);
interp->prepareInterpolation(ok);
sprintf(fname,"%s_eta3.tiff",argv[2]);
interp3->readFlatField(fname);
interp3->prepareInterpolation(ok);
//#endif
int *img;
@ -70,20 +118,99 @@ int main(int argc, char *argv[]) {
#endif
for (int irun=runmin; irun<runmax; irun++) {
int irun;
for (irun=runmin; irun<runmax; irun++) {
sprintf(infname,argv[1],irun);
#ifndef MANYFILES
sprintf(outfname,argv[3],irun);
#endif
f=fopen(infname,"r");
if (f) {
cout << infname << endl;
nframes=0;
f0=-1;
while (cl.read(f)) {
quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
if (sum>200 && sum<580) {
interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y);
interp->addToImage(int_x, int_y);
totph++;
if (lastframe!=cl.iframe) {
lastframe=cl.iframe;
// cout << cl.iframe << endl;
// f0=cl.iframe;
if (nframes==0) f0=lastframe;
nframes++;
#ifdef MANYFILES
if (nframes%ff==0) {
sprintf(outfname,argv[3],irun,nframes-ff);
cout << outfname << endl;
interp->writeInterpolatedImage(outfname);
interp->clearInterpolatedImage();
}
#endif
}
#ifdef XTALK
if ((cl.x+1)%25!=0) {
for (int ix=-1; ix<2; ix++) {
for (int iy=-1; iy<2; iy++) {
old_val[iy+1][ix+1]=cl.get_data(ix,iy);
if (ix>=0) {
new_val[iy+1][ix+1]=old_val[iy+1][ix+1]-old_val[iy+1][ix]*xcorr;
cl.set_data(new_val[iy+1][ix+1],ix,iy);
}
}
}
}
#endif
quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && totquad<cmax && quad<cmax) {
nph++;
// if (sum>200 && sum<580) {
// interp->getInterpolatedPosition(cl.x,cl.y, totquad,quad,cl.get_cluster(),int_x, int_y);
interp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y);
interp->addToImage(int_x, int_y);
interp3->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int3_x, int3_y);
interp3->addToImage(int3_x, int3_y);
nointerp->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),noint_x, noint_y);
nointerp->addToImage(noint_x, noint_y);
d_x= (int_x-int3_x)*25.;
d_y= (int_y-int3_y)*25.;
dummy->calcEta(totquad, sDum, etax, etay);
xx=int_x;
yy=int_y;
if (etax<0.1 || etax>0.9) xx=int3_x;
if (etay<0.1 || etay>0.9) yy=int3_y;
dummy->addToImage(xx,yy);
if (d_x>res || d_x<-res || d_y>res || d_y<-res) {
badph++;
// cout << "delta (um): "<< d_x << " " << d_y << " " << cl.x << " " << cl.y << endl;
// cout << sum << " " << totquad << " " << etax << " "<< etay << endl;
// //cout<< int_x << " " << int_y << " " << int3_x << " " << int3_y << endl;
}
mult->addToImage(noint_x, noint_y);
if (nph%1000000==0) cout << nph << endl;
if (nph%100000000==0) {
sprintf(outfname,"%s_inteta2.tiff", argv[3]);
interp->writeInterpolatedImage(outfname);
sprintf(outfname,"%s_inteta3.tiff", argv[3]);
interp3->writeInterpolatedImage(outfname);
sprintf(outfname,"%s_mix.tiff", argv[3]);
dummy->writeInterpolatedImage(outfname);
sprintf(outfname,"%s_noint.tiff", argv[3]);
nointerp->writeInterpolatedImage(outfname);
sprintf(outfname,"%s_mult.tiff", argv[3]);
mult->writeInterpolatedImage(outfname);
}
} else {
mult->getInterpolatedPosition(cl.x,cl.y, cl.get_cluster(),int_x, int_y);
for (int imult=0; imult<2.*sum/(cmax+cmin); imult++) mult->addToImage(int_x, int_y);
}
}
fclose(f);
#ifdef FF
@ -147,8 +274,22 @@ int main(int argc, char *argv[]) {
}
#endif
#ifndef FF
#ifdef MANYFILES
sprintf(outfname,argv[3],irun,nframes-ff);
cout << outfname << endl;
#endif
sprintf(outfname,"%s_inteta2.tiff", argv[3]);
interp->writeInterpolatedImage(outfname);
img=interp->getInterpolatedImage();
sprintf(outfname,"%s_inteta3.tiff", argv[3]);
interp3->writeInterpolatedImage(outfname);
sprintf(outfname,"%s_mix.tiff", argv[3]);
dummy->writeInterpolatedImage(outfname);
sprintf(outfname,"%s_mult.tiff", argv[3]);
mult->writeInterpolatedImage(outfname);
#ifndef MANYFILES
img=interp->getInterpolatedImage();
for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) {
for (isx=0; isx<nsubpix; isx++) {
@ -158,18 +299,24 @@ int main(int argc, char *argv[]) {
}
}
}
#endif
#endif
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ")"<<endl;
interp->clearInterpolatedImage();
interp3->clearInterpolatedImage();
dummy->clearInterpolatedImage();
mult->clearInterpolatedImage();
}
} else
cout << "could not open file " << infname << endl;
}
cout << irun << " " << runmax << endl;
#ifndef MANYFILES
sprintf(outfname,argv[3],11111);
WriteToTiff(totimg, outfname,NC*nsubpix,NR*nsubpix);
#endif
cout << "Filled " << nph << " (/"<< totph <<") of which " << badph << " badly interpolated " << endl;
return 0;
}

View File

@ -11,6 +11,7 @@ using namespace std;
#define NC 400
#define NR 400
#define XTALK
int main(int argc, char *argv[]) {
/**
@ -20,6 +21,7 @@ int main(int argc, char *argv[]) {
int nsubpix=10;
int etabins=nsubpix*100;
double etamin=-1, etamax=2;
double eta3min=-2, eta3max=2;
int quad;
double sum, totquad;
double sDum[2][2];
@ -27,16 +29,29 @@ int main(int argc, char *argv[]) {
double etax, etay;
int runmin, runmax;
single_photon_hit cl(3,3);
if (argc<5) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " outfile runmin runmax" << endl;
int iph=0;
if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " outfile runmin runmax cmin cmax" << endl;
return 1;
}
etaInterpolationPosXY *interp=new etaInterpolationPosXY(NR, NC, nsubpix, etabins, etamin, etamax);
eta2InterpolationPosXY *interp2=new eta2InterpolationPosXY(NR, NC, nsubpix, etabins, etamin, etamax);
cout << "###########"<< endl;
eta3InterpolationPosXY *interp3=new eta3InterpolationPosXY(NR, NC, nsubpix, etabins, eta3min, eta3max);
// cout << eta3min << " " << eta3max << endl;
runmin=atoi(argv[3]);
runmax=atoi(argv[4]);
double cmin=atof(argv[5]); //200
double cmax=atof(argv[6]); //3000
#ifdef XTALK
int old_val[3][3];
int new_val[3][3];
double xcorr=0.04;
// int ix=0;
#endif
FILE *f;
for (int i=runmin; i<runmax; i++) {
@ -45,18 +60,55 @@ int main(int argc, char *argv[]) {
if (f) {
cout << "*" << endl;
while (cl.read(f)) {
interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
if (sum>200 && sum<580 && cl.y<350)
interp->addToFlatField(cl.get_cluster(),etax, etay);
#ifdef XTALK
if ((cl.x+1)%25!=0) {
for (int ix=-1; ix<2; ix++) {
for (int iy=-1; iy<2; iy++) {
old_val[iy+1][ix+1]=cl.get_data(ix,iy);
if (ix>=0) {
new_val[iy+1][ix+1]=old_val[iy+1][ix+1]-old_val[iy+1][ix]*xcorr;
cl.set_data(new_val[iy+1][ix+1],ix,iy);
}
}
}
}
#endif
quad=interp2->calcQuad(cl.get_cluster(), sum, totquad, sDum);
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && totquad<cmax && quad<cmax) {
/* Cross talk corrections !!! */
// for (int ix=0; ix<2; ix++) {
interp2->addToFlatField(cl.get_cluster(),etax, etay);
// if (etax>0.49 && etax<0.51 && etay>0.49 && etay<0.51 ) {
// cout << cl.y << " " << cl.x << " " << quad << " "<< totquad << " " <<sum << endl;
// }
interp3->addToFlatField(cl.get_cluster(),etax, etay);
iph++;
if (iph%1000000==0) cout << iph << endl;
if (iph%100000000==0) {
sprintf(fname,"%s_eta2.tiff",argv[2]);
interp2->writeFlatField(fname);
sprintf(fname,"%s_eta3.tiff",argv[2]);
interp3->writeFlatField(fname);
}
// if (iph>1E8) break;
}
// }
}
fclose(f);
interp->writeFlatField(argv[2]);
}
else cout << "could not open file " << fname << endl;
}
interp->writeFlatField(argv[2]);
sprintf(fname,"%s_eta2.tiff",argv[2]);
interp2->writeFlatField(fname);
sprintf(fname,"%s_eta3.tiff",argv[2]);
interp3->writeFlatField(fname);
return 0;
}

View File

@ -1,160 +0,0 @@
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
//#include <deque>
//#include <list>
//#include <queue>
#include <fstream>
#include "moench03Ctb10GbT1Data.h"
#include "interpolatingDetector.h"
#include "etaInterpolationPosXY.h"
#include "linearInterpolation.h"
#include "noInterpolation.h"
#include "multiThreadedDetector.h"
#include <ctime>
#define NC 400
#define NR 400
#include "tiffIO.h"
void *moenchProcessFrame() {
char fname[10000];
strcpy(fname,"/mnt/moench_data/m03-15_mufocustube/plant_40kV_10uA/m03-15_100V_g4hg_300us_dtf_0.raw");
int nthreads=3;
int nph, nph1;
single_photon_hit clusters[NR*NC];
// cout << "hits "<< endl;
int etabins=550;
double etamin=-1, etamax=2;
int nsubpix=4;
float *etah=new float[etabins*etabins];
// cout << "etah "<< endl;
cout << "image size "<< nsubpix*nsubpix*NC*NR << endl;
float *image=new float[nsubpix*nsubpix*NC*NR];
int *heta, *himage;
moench03Ctb10GbT1Data *decoder=new moench03Ctb10GbT1Data();
// cout << "decoder "<< endl;
etaInterpolationPosXY *interp=new etaInterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
// cout << "interp "<< endl;
//linearInterpolation *interp=new linearInterpolation(NC, NR, nsubpix);
//noInterpolation *interp=new noInterpolation(NC, NR, nsubpix);
interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
interpolatingDetector *filter=new interpolatingDetector(decoder,interp, 5, 1, 0, 1000, 10);
filter->readPedestals("/scratch/ped_100.tiff");
cout << "filter "<< endl;
char *buff;
int nf=0;
int ok=0;
ifstream filebin;
std::time_t end_time;
int iFrame=-1;
int np=-1;
filter->newDataSet();
multiThreadedDetector *mt=new multiThreadedDetector(filter,nthreads,100);
nph=0;
nph1=0;
//int np;
int iph;
cout << "file name " << fname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
if (filebin.is_open())
cout << "Opened file " << fname<< endl;
else
cout << "Could not open file " << fname<< endl;
mt->setFrameMode(eFrame);
mt->prepareInterpolation(ok);
mt->StartThreads();
mt->popFree(buff);
while ((decoder->readNextFrame(filebin, iFrame, np, buff)) && nf<1.5E4) {
if (nf<9E3)
;
else {
// if (nf>1.1E4 && ok==0) {
// mt->prepareInterpolation(ok);
// mt->setFrameMode(eFrame);
// //ok=1;
// }
mt->pushData(buff);
mt->nextThread();
// cout << " " << (void*)buff;
mt->popFree(buff);
// if (ok==0) {
// cout << "**************************************************************************"<< endl;
// heta=interp->getFlatField();
// // for (int ii=0; ii<etabins*etabins; ii++) {
// // etah[ii]=(float)heta[ii];
// // }
// std::time(&end_time);
// cout << std::ctime(&end_time) << " " << nf << endl;
// // WriteToTiff(etah, "/scratch/eta.tiff", etabins, etabins);
// interp->prepareInterpolation(ok);
// cout << "**************************************************************************"<< endl;
// std::time(&end_time);
// cout << std::ctime(&end_time) << " " << nf << endl;
// }
// filter->processData(buff,eFrame);
// }
// nph+=nph1;
}
if (nf%1000==0) {
std::time(&end_time);
cout << std::ctime(&end_time) << " " << nf << endl;
}
nf++;
//delete [] buff;
iFrame=-1;
}
if (filebin.is_open())
filebin.close();
else
cout << "could not open file " << fname << endl;
mt->StopThreads();
char tit[10000];
sprintf(tit,"/scratch/int_image_mt%d.tiff",nthreads);
mt->writeInterpolatedImage(tit);
// delete [] etah;
// delete interp;
//delete decoder;
//cout << "Read " << nf << " frames" << endl;
return NULL;
}
int main(int argc, char *argv[]){
moenchProcessFrame();
}

View File

@ -1,267 +0,0 @@
#include "../single_photon_hit.h"
//#include "etaVEL/etaInterpolationPosXY.h"
#include <TH1F.h>
#include <TH2F.h>
#include <TCanvas.h>
#include <iostream>
using namespace std;
TH2F *readClusters(char *fname, int nx, int ny, TH2F *h2=NULL) {
FILE *f=fopen(fname,"r");
int iph=0;
int ns=4;
double px, py;
double left, right, top, bottom;
if (f) {
int x1,y1;
if (h2==NULL)
h2=new TH2F("h2",fname,nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);
//h2mult=new TH2F("h2mult",fname,nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);
// TH2F *hint=new TH2F("hint",fname,nx*ns, -0.5, nx-0.5, ny*ns, -0.5, ny-0.5);
TH1F *hf=new TH1F("hf","hf",1000,0,10E6);
//TH2F *hff=new TH2F("hff","hff",ns, -0.5, 0.5, ns, -0.5, +0.5);
TH1F *hsp=new TH1F("hsp",fname,500,0,10000);
// TH1F *hsp1=new TH1F("hsp1",fname,500,0,10000);
// TH1F *hsp2=new TH1F("hsp2",fname,500,0,1000);
// TH1F *hsp3=new TH1F("hsp3",fname,500,0,1000);
// hsp1->SetLineColor(2);
// hsp2->SetLineColor(3);
// hsp3->SetLineColor(4);
TCanvas *c=new TCanvas();
h2->Draw("colz");
TCanvas *c1=new TCanvas();
hsp->Draw();
c1->SetLogy(kTRUE);
// hsp1->Draw("same");
// hsp2->Draw("same");
// hsp3->Draw("same");
TCanvas *c2=new TCanvas();
hf->Draw();
// hint->Draw("colz");
//c2->SetLogz(kTRUE);
single_photon_hit cl(3,3);
double tot;
int w;
double phw=340, phs=62;
int f0=-1;
double tl, bl, tr, br, qt;
int iimage=0;
while (cl.read(f)) {
//cl.get_pixel(x1, y1);
//cout << cl.iframe << " " << cl.x << " " << cl.y << endl;
//if (cl.x>80 && cl.x<280 && cl.y>80 && cl.y<300) {
tot=0; /*
left=0;
right=0;
top=0;
bottom=0;*/
tl=0; tr=0; bl=0; br=0;
for (int ix=-1; ix<2; ix++)
for (int iy=-1; iy<2; iy++){
tot+=cl.get_data(ix,iy);
if (ix<=0 && iy<=0) bl+=cl.get_data(ix,iy);
if (ix<=0 && iy>=0) tl+=cl.get_data(ix,iy);
if (ix>=0 && iy<=0) br+=cl.get_data(ix,iy);
if (ix>=0 && iy>=0) tr+=cl.get_data(ix,iy);
//if (ix<0) left+=cl.get_data(ix,iy);
// if (ix>0) right+=cl.get_data(ix,iy);
// if (iy<0) bottom+=cl.get_data(ix,iy);
// if (iy>0) top+=cl.get_data(ix,iy);
}
qt=bl;
if (br>qt) qt=br;
if (tl>qt) qt=tl;
if (tr>qt) qt=tr;
/*
px=(-left+right)/tot;
py=(-bottom+top)/tot;*/
//max at 340
//if (tot>200) {
w=1;
if (qt>1000) {
if (qt/tot>0.8 && qt/tot<1.2){
if (f0<0)
f0=cl.iframe;
hf->Fill(cl.iframe-f0);
// if (qt>540) w++;
// if (qt>820) w++;
//(tot+3.5*phs)/phw;
//} else
//w=0;
// if (w) {
// if (cl.y<350) {
// if (cl.y<100 || cl.y>300) {
// if (cl.x>150 && cl.x<250 && cl.y>200 && cl.y<250)
// hsp1->Fill(qt);
// else
hsp->Fill(qt);
// hsp2->Fill(cl.get_data(0,0));
// } else {
// hsp1->Fill(qt);
// hsp3->Fill(cl.get_data(0,0));
// }
//if (cl.x>160 && cl.x<260 && cl.y>30 && cl.y<80 && tot>0)
//if (w==1) {
// if (w==2)
h2->Fill(cl.x,cl.y,w);
// }
//}
// hint->Fill(px+cl.x,py+cl.y,w);
// if (cl.y<350)
// hff->Fill(px,py,w);
// }
//h2mult->Fill(cl.x,cl.y,w);
}
iph+=w;
if (iph%100000==0) {
c->Modified();
c->Update();
c1->Modified();;
c1->Update();
c2->Modified();;
c2->Update();
}
// if (iph>1E7)
// break;
//}
// if (iph>0.5E7) break;
}
}
fclose(f);
// hff->Scale(hff->GetNbinsX()*hff->GetNbinsY()/hff->Integral());
// TH2F *hint2=(TH2F*)hint->Clone("hint2");
// double ff;
// for (int ibx=0; ibx<hint->GetNbinsX(); ibx++) {
// for (int iby=0; iby<hint->GetNbinsY(); iby++) {
// ff=hff->GetBinContent(ibx%ns+1, iby%ns+1);
// // cout << ibx << " " << iby << " " << ibx%ns << " " << iby%ns << " " << ff << endl;
// if (ff>0)
// hint2->SetBinContent(ibx+1, iby+1,hint->GetBinContent(ibx+1,iby+1)/ff);
// }
// }
return h2;
} else
cout << "could not open file " << fname << endl;
return NULL;
}
// TH2F *getEta(char *fname, int nx, int ny, TH2F *h2=NULL) {
// int ns=10;
// slsInterpolation *inte=new etaInterpolationPosXY(nx,ny,ns,
// FILE *f=fopen(fname,"r");
// int iph=0;
// int ns=4;
// double px, py;
// double left, right, top, bottom;
// if (f) {
// int x1,y1;
// if (h2==NULL)
// h2=new TH2F("h2",fname,nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);
// h2mult=new TH2F("h2mult",fname,nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);
// TH2F *hint=new TH2F("hint",fname,nx*ns, -0.5, nx-0.5, ny*ns, -0.5, ny-0.5);
// // TH2F *hff=new TH2F("hff","hff",ns, -0.5, 0.5, ns, -0.5, +0.5);
// TH1F *hsp=new TH1F("hsp",fname,500,0,2000);
// TCanvas *c=new TCanvas();
// c->SetLogz(kTRUE);
// h2->Draw("colz");
// TCanvas *c1=new TCanvas();
// hsp->Draw();
// TCanvas *c2=new TCanvas();
// hint->Draw("colz");
// c2->SetLogz(kTRUE);
// single_photon_hit cl(3,3);
// double tot;
// int w;
// double phw=340, phs=62;
// while (cl.read(f)) {
// //cl.get_pixel(x1, y1);
// //cout << cl.iframe << " " << cl.x << " " << cl.y << endl;
// //if (cl.x>80 && cl.x<280 && cl.y>80 && cl.y<300) {
// tot=0;
// left=0;
// right=0;
// top=0;
// bottom=0;
// for (int ix=-1; ix<2; ix++)
// for (int iy=-1; iy<2; iy++){
// tot+=cl.get_data(ix,iy);
// if (ix<0) left+=cl.get_data(ix,iy);
// if (ix>0) right+=cl.get_data(ix,iy);
// if (iy<0) bottom+=cl.get_data(ix,iy);
// if (iy>0) top+=cl.get_data(ix,iy);
// }
// px=(-left+right)/tot;
// py=(-bottom+top)/tot;
// //max at 340
// if (tot>200) {
// w=(tot+3.5*phs)/phw;
// } else
// w=0;
// if (w) {
// hsp->Fill(tot);
// if (w==1) {
// h2->Fill(cl.x,cl.y,w);
// hint->Fill(px+cl.x,py+cl.y,w);
// }
// h2mult->Fill(cl.x,cl.y,w);
// // if (cl.y<350)
// // hff->Fill(px,py,w);
// //}
// iph+=w;
// if (iph%100000==0) {
// // c->Modified();
// // c->Update();
// c1->Modified();;
// c1->Update();
// // c2->Modified();;
// // c2->Update();
// }
// }
// // if (iph>0.5E7) break;
// }
// fclose(f);
// // hff->Scale(hff->GetNbinsX()*hff->GetNbinsY()/hff->Integral());
// // TH2F *hint2=(TH2F*)hint->Clone("hint2");
// // double ff;
// // for (int ibx=0; ibx<hint->GetNbinsX(); ibx++) {
// // for (int iby=0; iby<hint->GetNbinsY(); iby++) {
// // ff=hff->GetBinContent(ibx%ns+1, iby%ns+1);
// // // cout << ibx << " " << iby << " " << ibx%ns << " " << iby%ns << " " << ff << endl;
// // if (ff>0)
// // hint2->SetBinContent(ibx+1, iby+1,hint->GetBinContent(ibx+1,iby+1)/ff);
// // }
// // }
// return h2;
// } else
// cout << "could not open file " << fname << endl;
// return NULL;
// }