Some fixes to the offline processing - could also affect hte zmq process

This commit is contained in:
2020-04-06 09:42:38 +02:00
parent 95351d0924
commit 163eb2710f
12 changed files with 332 additions and 218 deletions

View File

@ -1,4 +1,4 @@
hostname bchip071+ hostname bchip135+
patword 0000 0000000000000000 patword 0000 0000000000000000
patword 0001 0000000000000000 patword 0001 0000000000000000

View File

@ -226,8 +226,11 @@ template <class dataType> class analogDetector {
\returns pointer to current gain map is file reading succeeded, NULL is file reading didn't work. \returns pointer to current gain map is file reading succeeded, NULL is file reading didn't work.
*/ */
double *readGainMap(const char * imgname) { double *readGainMap(const char * imgname) {
uint32 nnx, nny; uint32 unnx, unny;
float *gm=ReadFromTiff( imgname, nny, nnx); int nnx, nny;
float *gm=ReadFromTiff( imgname, unny, unnx);
nnx=unnx;
nny=unny;
if (gm) { if (gm) {
if (gmap) delete [] gmap; if (gmap) delete [] gmap;
gmap=new double[nnx*nny]; gmap=new double[nnx*nny];

View File

@ -77,9 +77,9 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
int row, col; int row, col;
int isample; // int isample;
int iadc; int iadc;
int ix, iy; // int ix, iy;
int npackets=40; int npackets=40;
int i; int i;
@ -110,35 +110,35 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
} }
} }
int ipacket; // int ipacket;
int ibyte; // int ibyte;
int ii=0; // int ii=0;
for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){ // for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){
xmap[ibyte]=-1; // xmap[ibyte]=-1;
ymap[ibyte]=-1; // ymap[ibyte]=-1;
} // }
int off=sizeof(sls_detector_header)/2; // int off=sizeof(sls_detector_header)/2;
for (ipacket=0; ipacket<npackets; ipacket++) { // for (ipacket=0; ipacket<npackets; ipacket++) {
for (ibyte=0; ibyte< 8192/2; ibyte++) { // for (ibyte=0; ibyte< 8192/2; ibyte++) {
i=ipacket*8208/2+ibyte; // i=ipacket*8208/2+ibyte;
isample=ii/nadc; // isample=ii/nadc;
if (isample<nSamples) { // if (isample<nSamples) {
iadc=ii%nadc; // iadc=ii%nadc;
adc4 = (int)iadc/4; // adc4 = (int)iadc/4;
ix=isample%sc_width; // ix=isample%sc_width;
iy=isample/sc_width; // iy=isample/sc_width;
if (adc4%2==0) { // if (adc4%2==0) {
xmap[i+off]=adc_nr[iadc]+ix; // xmap[i+off]=adc_nr[iadc]+ix;
ymap[i+off]=ny/2-1-iy; // ymap[i+off]=ny/2-1-iy;
} else { // } else {
xmap[i+off]=adc_nr[iadc]+ix; // xmap[i+off]=adc_nr[iadc]+ix;
ymap[i+off]=ny/2+iy; // ymap[i+off]=ny/2+iy;
} // }
} // }
ii++; // ii++;
// } // // }
} // }
} // }
iframe=0; iframe=0;
// cout << "data struct created" << endl; // cout << "data struct created" << endl;
@ -240,15 +240,15 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) { virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
char *retval=0; //char *retval=0;
int nd; // int nd;
int fnum = -1; //int fnum = -1;
np=0; // np=0;
int pn; // int pn;
// cout << dataSize << endl; // cout << dataSize << endl;
if (ff>=0) // if (ff>=0)
fnum=ff; // fnum=ff;
if (filebin.is_open()) { if (filebin.is_open()) {
if (filebin.read(data, dataSize) ){ if (filebin.read(data, dataSize) ){

View File

@ -253,12 +253,13 @@ class slsDetectorData {
*/ */
virtual dataType getChannel(char *data, int ix, int iy=0) { virtual dataType getChannel(char *data, int ix, int iy=0) {
dataType m=0, d=0; dataType m=0, d=0, *p;
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) { if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) {
// cout << ix << " " << iy << " " ; // cout << ix << " " << iy << " " ;
//cout << dataMap[ix][iy] << " " << (void*)data << " " << dataSize<< endl; //cout << dataMap[ix][iy] << " " << (void*)data << " " << dataSize<< endl;
m=dataMask[iy][ix]; m=dataMask[iy][ix];
d=*((dataType*)(data+dataMap[iy][ix])); p=(dataType*)(data+dataMap[iy][ix]);
d=*p;
} }
return d^m; return d^m;
}; };

View File

@ -1,8 +1,10 @@
#module add CBFlib/0.9.5 #module add CBFlib/0.9.5
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include/
LDFLAG= ../tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -O3 -std=c++11
LDFLAG= ../tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -std=c++11 -Wall -O3
#-g3
#-fsanitize=thread -fno-omit-frame-pointer
#-fsanitize=address,undefined,
MAIN=moench03ClusterFinder.cpp MAIN=moench03ClusterFinder.cpp

View File

@ -1,6 +1,7 @@
//#include "ansi.h" //#include "ansi.h"
#include <iostream> #include <iostream>
// bin/moenchClusterFinder moench03_25022020 moench_fluo_outputs flat_27keV_d0_f000000%d00000_1 0 10
//#include "moench03T1ZmqData.h" //#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER #ifdef NEWRECEIVER
@ -34,6 +35,8 @@
#include "singlePhotonDetector.h" #include "singlePhotonDetector.h"
//#include "interpolatingDetector.h" //#include "interpolatingDetector.h"
#include <string>
#include <sstream>
#include <stdio.h> #include <stdio.h>
#include <map> #include <map>
#include <fstream> #include <fstream>
@ -50,20 +53,20 @@ int main(int argc, char *argv[]) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl; cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 1; return 1;
} }
int p=10000; //int p=10000;
int fifosize=1000; int fifosize=1000;
int nthreads=1; int nthreads=16;
int nsubpix=25; //int nsubpix=25;
int etabins=nsubpix*10; //int etabins=nsubpix*10;
double etamin=-1, etamax=2; //double etamin=-1, etamax=2;
int csize=3; int csize=3;
int nx=400, ny=400; int nx=400, ny=400;
int save=1; //int save=1;
int nsigma=1; int nsigma=5;
int nped=1000; int nped=1000;
int ndark=100; //int ndark=100;
int ok; //int ok;
int iprog=0; //int iprog=0;
@ -108,9 +111,9 @@ int main(int argc, char *argv[]) {
// cout << "filter "<< endl; // cout << "filter "<< endl;
int size = 327680;////atoi(argv[3]); //int size = 327680;////atoi(argv[3]);
int* image; //int* image;
//int* image =new int[327680/sizeof(int)]; //int* image =new int[327680/sizeof(int)];
filter->newDataSet(); filter->newDataSet();
@ -120,21 +123,21 @@ int main(int argc, char *argv[]) {
cout << " data size is " << dsize; cout << " data size is " << dsize;
char data[dsize]; //char data[dsize];
ifstream filebin; ifstream filebin;
char *indir=argv[1]; string indir=string(argv[1]);
char *outdir=argv[2]; string outdir=string(argv[2]);
char *fformat=argv[3]; string fformat=string(argv[3]);
int runmin=atoi(argv[4]); int runmin=atoi(argv[4]);
int runmax=atoi(argv[5]); int runmax=atoi(argv[5]);
char fname[10000]; string fname;
char outfname[10000]; string outfname;
char imgfname[10000]; string imgfname;
char pedfname[10000]; //char pedfname[10000];
// strcpy(pedfname,argv[6]); // strcpy(pedfname,argv[6]);
char fn[10000]; char fn[10000];
std::time_t end_time; std::time_t end_time;
@ -148,12 +151,6 @@ int main(int argc, char *argv[]) {
cout << std::ctime(&end_time) << endl; cout << std::ctime(&end_time) << endl;
char* buff; char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
@ -170,17 +167,26 @@ int main(int argc, char *argv[]) {
for (int irun=runmin; irun<runmax; irun++) { for (int irun=runmin; irun<runmax; irun++) {
sprintf(fn,fformat,irun); sprintf(fn,fformat.c_str(),irun);
sprintf(fname,"%s/%s.raw",indir,fn); fname=indir+"/"+string(fn)+".raw";
sprintf(outfname,"%s/%s.clust",outdir,fn); //sprintf(fname,"%s/%s.raw",indir,fn);
sprintf(imgfname,"%s/%s.tiff",outdir,fn); #ifndef WRITE_QUAD
outfname=outdir+string(fn)+".clust";
//sprintf(outfname,"%s/%s.clust",outdir,fn);
#endif
#ifdef WRITE_QUAD
outfname=outdir+string(fn)+".clust2";
// sprintf(outfname,"%s/%s.clust2",outdir,fn);
#endif
imgfname=outdir+string(fn)+".tiff";
//sprintf(imgfname,"%s/%s.tiff",outdir,fn);
std::time(&end_time); std::time(&end_time);
cout << std::ctime(&end_time) << endl; cout << std::ctime(&end_time) << endl;
cout << fname << " " << outfname << " " << imgfname << endl; cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary); filebin.open(fname.c_str(), ios::in | ios::binary);
// //open file // //open file
if (filebin.is_open()){ if (filebin.is_open()){
of=fopen(outfname,"w"); of=fopen(outfname.c_str(),"w");
if (of) { if (of) {
mt->setFilePointer(of); mt->setFilePointer(of);
// cout << "file pointer set " << endl; // cout << "file pointer set " << endl;
@ -212,7 +218,7 @@ int main(int argc, char *argv[]) {
} }
ff=-1; ff=-1;
} }
cout << "--" << endl; cout << "--" << endl;
filebin.close(); filebin.close();
// //close file // //close file
// //join threads // //join threads
@ -220,7 +226,7 @@ int main(int argc, char *argv[]) {
if (of) if (of)
fclose(of); fclose(of);
mt->writeImage(imgfname); mt->writeImage(imgfname.c_str());
mt->clearImage(); mt->clearImage();
std::time(&end_time); std::time(&end_time);

View File

@ -50,9 +50,9 @@ int main(int argc, char *argv[]) {
#endif #endif
int iarg=4; int iarg=4;
char infname[10000]; char infname[10000];
char fname[10000];
char outfname[10000]; char outfname[10000];
#ifndef FF #ifndef FF
char fname[10000];
iarg=4; iarg=4;
#endif #endif
@ -74,23 +74,46 @@ int main(int argc, char *argv[]) {
cout << "Energy min: " << cmin << endl; cout << "Energy min: " << cmin << endl;
cout << "Energy max: " << cmax << endl; cout << "Energy max: " << cmax << endl;
//int etabins=500; //int etabins=500;
#ifndef NOINTERPOLATION
int etabins=1000;//nsubpix*2*100; int etabins=1000;//nsubpix*2*100;
int etabinsY=etabins;//nsubpix*2*100; int etabinsY=etabins;//nsubpix*2*100;
#ifndef ETA3
double etamin=-1, etamax=2; double etamin=-1, etamax=2;
//double etamin=-0.1, etamax=1.1; //double etamin=-0.1, etamax=1.1;
double etax=0, etay=0;
#ifndef FF
double int_x, int_y;
// double d_x, d_y, res=5, xx, yy;
int ok;
#endif
#endif
#ifdef ETA3
double eta3min=-2, eta3max=2; double eta3min=-2, eta3max=2;
double eta3x, eta3y;
#ifndef FF
double int3_x, int3_y;
#endif
#endif
#endif
#ifndef FF
int quad; int quad;
#endif
double sum, totquad; double sum, totquad;
double sDum[2][2]; double sDum[2][2];
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y; #ifdef NOINTERPOLATION
int ok; #ifndef FF
double noint_x, noint_y;
#endif
#endif
int f0=-1; int f0=-1;
int ix, iy, isx, isy; int ix, iy, isx, isy;
int nframes=0, lastframe=-1; int nframes=0, lastframe=-1;
double d_x, d_y, res=5, xx, yy;
int nph=0, badph=0, totph=0; //badph=0,
FILE *f=NULL; int nph=0, totph=0;
FILE *f=NULL;
#ifdef DOUBLE_SPH #ifdef DOUBLE_SPH
single_photon_hit_double cl(3,3); single_photon_hit_double cl(3,3);
@ -120,6 +143,7 @@ int main(int argc, char *argv[]) {
#ifndef FF #ifndef FF
int *img;
#ifndef NOINTERPOLATION #ifndef NOINTERPOLATION
cout << "read ff " << argv[2] << endl; cout << "read ff " << argv[2] << endl;
sprintf(fname,"%s",argv[2]); sprintf(fname,"%s",argv[2]);
@ -132,7 +156,6 @@ int main(int argc, char *argv[]) {
cout << "Will write eta file " << argv[2] << endl; cout << "Will write eta file " << argv[2] << endl;
#endif #endif
int *img;
float *totimg=new float[NC*NR*nSubPixels*nSubPixelsY]; float *totimg=new float[NC*NR*nSubPixels*nSubPixelsY];
for (ix=0; ix<NC; ix++) { for (ix=0; ix<NC; ix++) {
for (iy=0; iy<NR; iy++) { for (iy=0; iy<NR; iy++) {
@ -168,7 +191,13 @@ int main(int argc, char *argv[]) {
if (nframes==0) f0=lastframe; if (nframes==0) f0=lastframe;
nframes++; nframes++;
} }
#ifndef FF
quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum); quad=interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
#endif
#ifdef FF
interp->calcEta(cl.get_cluster(), etax, etay, sum, totquad, sDum);
#endif
if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) { if (sum>cmin && totquad/sum>0.8 && totquad/sum<1.2 && sum<cmax ) {
nph++; nph++;
// if (sum>200 && sum<580) { // if (sum>200 && sum<580) {
@ -263,9 +292,9 @@ int main(int argc, char *argv[]) {
#ifdef RECT1 #ifdef RECT1
WriteToTiff(rectimg, outfname,NC,NR*nSubPixelsY); WriteToTiff(rectimg, outfname,NC,NR*nSubPixelsY);
#endif #endif
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl;
interp->clearInterpolatedImage(); interp->clearInterpolatedImage();
#endif #endif
cout << "Read " << nframes << " frames (first frame: " << f0 << " last frame: " << lastframe << " delta:" << lastframe-f0 << ") nph="<< nph <<endl;
} else } else
cout << "could not open file " << infname << endl; cout << "could not open file " << infname << endl;

View File

@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
*/ */
if (argc<7) { if (argc<7) {
cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " etafile outfile runmin runmax ns" << endl; cout << "Wrong usage! Should be: "<< argv[0] << " infile " << " outfile runmin runmax ns" << endl;
return 1; return 1;
} }
@ -28,13 +28,14 @@ int main(int argc, char *argv[]) {
int runmax=atoi(argv[5]); int runmax=atoi(argv[5]);
int nsubpix=atoi(argv[6]); int nsubpix=atoi(argv[6]);
int etabins=1000;//nsubpix*2*100; // int etabins=1000;//nsubpix*2*100;
double etamin=-1, etamax=2; // double etamin=-1, etamax=2;
int quad; int quad;
double sum, totquad; double sum, totquad;
double sDum[2][2]; double sDum[2][2];
double etax, etay, int_x, int_y; //double etax, etay,
int ok; double int_x, int_y;
//int ok;
int ix, iy, isx, isy; int ix, iy, isx, isy;

View File

@ -43,7 +43,7 @@
#include <map> #include <map>
#include <fstream> #include <fstream>
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h>
#include <ctime> #include <ctime>
using namespace std; using namespace std;
@ -58,19 +58,19 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
int p=10000; //int p=10000;
int fifosize=1000; int fifosize=1000;
int nthreads=10; int nthreads=10;
int nsubpix=25; //int nsubpix=25;
int etabins=nsubpix*10; //int etabins=nsubpix*10;
double etamin=-1, etamax=2; //double etamin=-1, etamax=2;
int csize=3; int csize=3;
int save=1; //int save=1;
int nsigma=5; int nsigma=5;
int nped=10000; int nped=10000;
int ndark=100; //int ndark=100;
int ok; //int ok;
int iprog=0; //int iprog=0;
int cf=0; int cf=0;
@ -101,13 +101,13 @@ int main(int argc, char *argv[]) {
moench03CommonMode *cm=NULL; moench03CommonMode *cm=NULL;
moench03GhostSummation *gs; moench03GhostSummation *gs;
double *gainmap=NULL; double *gainmap=NULL;
float *gm; //float *gm;
int size = 327680;////atoi(argv[3]); //int size = 327680;////atoi(argv[3]);
int* image; //int* image;
//int* image =new int[327680/sizeof(int)]; //int* image =new int[327680/sizeof(int)];
int ff, np; int ff, np;
@ -171,7 +171,7 @@ int main(int argc, char *argv[]) {
char fname[10000]; char fname[10000];
char imgfname[10000]; char imgfname[10000];
char cfname[10000]; char cfname[10000];
char fn[10000]; //char fn[10000];
std::time_t end_time; std::time_t end_time;
@ -185,9 +185,9 @@ int main(int argc, char *argv[]) {
cout << "pedestal file is " << pedfile << endl; cout << "pedestal file is " << pedfile << endl;
if (thr>0) if (thr>0)
cout << "threshold is " << thr << endl; cout << "threshold is " << thr << endl;
uint32 unnx, unny;
uint32 nnx, nny; int nnx, nny;
double *gmap; //double *gmap;
// if (gainfname) { // if (gainfname) {
// gm=ReadFromTiff(gainfname, nny, nnx); // gm=ReadFromTiff(gainfname, nny, nnx);
@ -221,10 +221,10 @@ int main(int argc, char *argv[]) {
} else } else
thr=0.15*thr; thr=0.15*thr;
filter->newDataSet(); filter->newDataSet();
int dsize=decoder->getDataSize(); //int dsize=decoder->getDataSize();
char data[dsize]; //char data[dsize];
@ -270,12 +270,14 @@ int main(int argc, char *argv[]) {
mt->StartThreads(); mt->StartThreads();
mt->popFree(buff); mt->popFree(buff);
DIR *dir;
struct dirent *ent;
// cout << "mt " << endl; // cout << "mt " << endl;
int ifr=0; int ifr=0;
double ped[nx*ny], *ped1; double ped[nx*ny];//, *ped1;
if (pedfile) { if (pedfile) {
@ -314,7 +316,9 @@ int main(int argc, char *argv[]) {
} else } else
cout << "Could not open pedestal file "<< fname << " for reading " << endl; cout << "Could not open pedestal file "<< fname << " for reading " << endl;
} else { } else {
float *pp=ReadFromTiff(pedfile, nny, nnx); float *pp=ReadFromTiff(pedfile, unny, unnx);
nny=unny;
nnx=unnx;
if (pp && nnx==nx && nny==ny) { if (pp && nnx==nx && nny==ny) {
for (int i=0; i<nx*ny; i++) { for (int i=0; i<nx*ny; i++) {
ped[i]=pp[i]; ped[i]=pp[i];
@ -341,28 +345,23 @@ int main(int argc, char *argv[]) {
ifr=0; ifr=0;
int ifile=0; int ifile=0;
char ext[100];
mt->setFrameMode(eFrame); mt->setFrameMode(eFrame);
for (int irun=runmin; irun<=runmax; irun++) { for (int irun=runmin; irun<=runmax; irun++) {
cout << "DATA " ; cout << "DATA " ;
// sprintf(fn,fformat,irun); // sprintf(fn,fformat,irun);
sprintf(ffname,"%s/%s.raw",indir,fformat); sprintf(ext,"_%d.raw",irun);
sprintf(fname,ffname,irun);
sprintf(ffname,"%s/%s.tiff",outdir,fformat);
sprintf(imgfname,ffname,irun); sprintf(imgfname,"%s/%s_%d.tiff",outdir,fformat,irun);
sprintf(ffname,"%s/%s.clust",outdir,fformat); // sprintf(imgfname,ffname,irun);
sprintf(cfname,ffname,irun); sprintf(cfname,"%s/%s_%d.clust",outdir,fformat, irun);
cout << fname << " " ; //sprintf(cfname,ffname,irun);
cout << cfname << " " ;
cout << imgfname << endl; cout << imgfname << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
// cout << fname << " " << outfname << " " << imgfname << endl; if (thr<=0 && cf!=0) { //cluster finder
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
ifile=0;
if (filebin.is_open()){
if (thr<=0 && cf!=0) { //cluster finder
if (of==NULL) { if (of==NULL) {
of=fopen(cfname,"w"); of=fopen(cfname,"w");
if (of) { if (of) {
@ -375,6 +374,33 @@ int main(int argc, char *argv[]) {
} }
} }
} }
if ((dir = opendir (indir)) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
printf ("----------- %s\n", ent->d_name);
// printf ("************** %s", ent->d_name);
// cout << string(ent->d_name).find(fformat) << endl;
if (string(ent->d_name).find(string(fformat)+"_d0_f0")==0) {
printf ("+++++++++++++++ %s\n", ent->d_name);
if (string(ent->d_name).find(ext)!= string::npos) {
printf ("**************8 %s\n", ent->d_name);
sprintf(fname,"%s/%s",indir,ent->d_name);
//sprintf(fname,ffname,irun);
cout << fname << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
// cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
ifile=0;
if (filebin.is_open()){
// //while read frame // //while read frame
ff=-1; ff=-1;
ifr=0; ifr=0;
@ -412,18 +438,28 @@ int main(int argc, char *argv[]) {
} }
cout << "--" << endl; cout << "--" << endl;
filebin.close(); filebin.close();
} else
cout << "Could not open "<< fname << " for reading " << endl;
}
}
// //close file // //close file
// //join threads // //join threads
while (mt->isBusy()) {;}
if (nframes>=0) {
if (nframes>0) { }
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(imgfname,ffname,irun); while (mt->isBusy()) {;}
} else { if (nframes>=0) {
sprintf(ffname,"%s/%s.tiff",outdir,fformat); if (nframes>0) {
sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile);
sprintf(imgfname,ffname,irun); sprintf(imgfname,ffname,irun);
} } else {
cout << "Writing tiff to " << imgfname << " " << thr1 <<endl; sprintf(imgfname,"%s/%s_%d.tiff",outdir,fformat,irun);
//sprintf(imgfname,ffname,irun);
}
cout << "Writing tiff to " << imgfname << " " << thr1 <<endl;
mt->writeImage(imgfname, thr1); mt->writeImage(imgfname, thr1);
mt->clearImage(); mt->clearImage();
if (of) { if (of) {
@ -431,12 +467,18 @@ int main(int argc, char *argv[]) {
of=NULL; of=NULL;
mt->setFilePointer(NULL); mt->setFilePointer(NULL);
} }
} }
std::time(&end_time); std::time(&end_time);
cout << std::ctime(&end_time) << endl; cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open "<< fname << " for reading " << endl; closedir (dir);
} else {
/* could not open directory */
cout << "could not open directory " << indir << endl;
} }
}
if (nframes<0){ if (nframes<0){
sprintf(ffname,"%s/%s.tiff",outdir,fformat); sprintf(ffname,"%s/%s.tiff",outdir,fformat);
strcpy(imgfname,ffname); strcpy(imgfname,ffname);

View File

@ -1,4 +1,4 @@
#define WRITE_QUAD //#define WRITE_QUAD
#define MOENCH_BRANCH #define MOENCH_BRANCH
#define C_GHOST 0.0004 #define C_GHOST 0.0004
@ -139,8 +139,12 @@ int main(int argc, char *argv[]) {
int ncol_cm=CM_ROWS; int ncol_cm=CM_ROWS;
double xt_ghost=C_GHOST; double xt_ghost=C_GHOST;
moench03CommonMode *cm=new moench03CommonMode(ncol_cm); moench03CommonMode *cm=NULL;
moench03GhostSummation *gs=new moench03GhostSummation(det, xt_ghost); moench03GhostSummation *gs=NULL;
#ifdef CORR
gs=new moench03GhostSummation(det, xt_ghost);
cm=new moench03CommonMode(ncol_cm);
#endif
double *gainmap=NULL; double *gainmap=NULL;
float *gm; float *gm;
double *gmap=NULL; double *gmap=NULL;

View File

@ -322,31 +322,39 @@ public:
virtual int *getImage(int &nnx, int &nny, int &ns, int &nsy) { virtual int *getImage(int &nnx, int &nny, int &ns, int &nsy) {
int *img; int *img;
cout << "get image "<< image << endl;
// int nnx, nny, ns; // int nnx, nny, ns;
// int nnx, nny, ns; // int nnx, nny, ns;
int nn=dets[0]->getImageSize(nnx, nny,ns, nsy); int nn=dets[0]->getImageSize(nnx, nny,ns, nsy);
if (image) { if (image) {
delete image; cout << "del image "<< image << endl;
delete [] image;
image=NULL; image=NULL;
} }
image=new int[nn]; image=new int[nn];
cout << "new image" << image << endl;
//int nn=dets[0]->getImageSize(nnx, nny, ns); //int nn=dets[0]->getImageSize(nnx, nny, ns);
//for (i=0; i<nn; i++) image[i]=0; //for (i=0; i<nn; i++) image[i]=0;
if (image) {
for (int ii=0; ii<nThreads; ii++) { for (int ii=0; ii<nThreads; ii++) {
//cout << ii << " " << nn << " " << nnx << " " << nny << " " << ns << endl; cout << ii << " " << nn << " " << nnx << " " << nny << " " << nsy << endl;
img=dets[ii]->getImage(); img=dets[ii]->getImage();
for (int i=0; i<nn; i++) { for (int i=0; i<nn; i++) {
if (ii==0) if (ii==0)
// if (img[i]>0) // if (img[i]>0)
image[i]=img[i]; image[i]=img[i];
// else // else
// image[i]=0; // image[i]=0;
else //if (img[i]>0) else //if (img[i]>0)
image[i]+=img[i]; image[i]+=img[i];
//if (img[i]) cout << "det " << ii << " pix " << i << " val " << img[i] << " " << image[i] << endl; /***
} gdb runtime error
../multiThreadedAnalogDetector.h:349:14: runtime error: signed integer overflow: -1094794611 + -1094795013 cannot be rep
**/
//if (img[i]) cout << "det " << ii << " pix " << i << " val " << img[i] << " " << image[i] << endl;
}
}
} }
return image; return image;
@ -369,29 +377,32 @@ public:
/* dets[ii]->writeImage(tit); */ /* dets[ii]->writeImage(tit); */
/* } */ /* } */
/* #endif */ /* #endif */
cout << "write image" << endl;
int nnx, nny, ns, nsy; int nnx, nny, ns, nsy;
getImage(nnx, nny, ns, nsy); getImage(nnx, nny, ns, nsy);
//int nnx, nny, ns; //int nnx, nny, ns;
int nn=dets[0]->getImageSize(nnx, nny, ns, nsy); int nn=dets[0]->getImageSize(nnx, nny, ns, nsy);
float *gm=new float[nn]; float *gm=new float[nn];
if (gm) { if (gm) {
for (int ix=0; ix<nn; ix++) { for (int ix=0; ix<nn; ix++) {
if (t) { if (t) {
if (image[ix]<0) if (image[ix]<0)
gm[ix]=0; gm[ix]=0;
else else
gm[ix]=(image[ix])/t; gm[ix]=(image[ix])/t;
} else } else
gm[ix]=image[ix]; gm[ix]=image[ix];
//if (image[ix]>0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl; //if (image[ix]>0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl;
} }
//cout << "image " << nnx << " " << nny << endl; cout << "image " << nnx << " " << nny << endl;
WriteToTiff(gm,imgname ,nnx, nny); WriteToTiff(gm,imgname ,nnx, nny);
delete [] gm; cout << imgname << endl;
} else cout << "Could not allocate float image " << endl; delete [] gm;
return NULL; cout << "del" << endl;
} } else cout << "Could not allocate float image " << endl;
return NULL;
}
virtual void StartThreads() { virtual void StartThreads() {
@ -560,7 +571,7 @@ public:
int *ff; int *ff;
double *ped; double *ped;
pthread_mutex_t fmutex; pthread_mutex_t fmutex;
}; };
#endif #endif

View File

@ -4,7 +4,7 @@
#include "analogDetector.h" #include "analogDetector.h"
#include "single_photon_hit.h" #include "single_photon_hit.h"
#include <mutex>
//#define MYROOT1 //#define MYROOT1
@ -62,8 +62,8 @@ public analogDetector<uint16_t> {
fm=new mutex;
fm=new pthread_mutex_t ; // fm=new pthread_mutex_t ;
eventMask=new eventType*[ny]; eventMask=new eventType*[ny];
for (int i=0; i<ny; i++) { for (int i=0; i<ny; i++) {
@ -117,6 +117,9 @@ public analogDetector<uint16_t> {
setClusterSize(clusterSize); setClusterSize(clusterSize);
fm=orig->fm; fm=orig->fm;
//setMutex(orig->fm);
quad=UNDEFINED_QUADRANT; quad=UNDEFINED_QUADRANT;
tot=0; tot=0;
@ -350,7 +353,7 @@ int *getClusters(char *data, int *ph=NULL) {
int cy=(clusterSizeY+1)/2; int cy=(clusterSizeY+1)/2;
int cs=(clusterSize+1)/2; int cs=(clusterSize+1)/2;
//int ir, ic; //int ir, ic;
int iframe=det->getFrameNumber(data);
double max=0, tl=0, tr=0, bl=0,br=0, *v; double max=0, tl=0, tr=0, bl=0,br=0, *v;
int cm=0; int cm=0;
int good=1; int good=1;
@ -394,9 +397,9 @@ int *getClusters(char *data, int *ph=NULL) {
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
if ((iy+ir)>=iy && (iy+ir)<ny && (ix+ic)>=ix && (ix+ic)<nx) { if ((iy+ir)>=0 && (iy+ir)>=iy && (iy+ir)<ny && (ix+ic)>=0 &&(ix+ic)>=ix && (ix+ic)<nx) {
val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm); val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm);
} (clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir);
v=&(val[iy+ir][ix+ic]); v=&(val[iy+ir][ix+ic]);
tot+=*v; tot+=*v;
@ -420,6 +423,9 @@ int *getClusters(char *data, int *ph=NULL) {
eventMask[iy][ix]=PHOTON; eventMask[iy][ix]=PHOTON;
} }
} else
(clusters+nph)->set_data(0,ic,ir);
} }
} }
if (eventMask[iy][ix]==PHOTON && val[iy][ix]<max) if (eventMask[iy][ix]==PHOTON && val[iy][ix]<max)
@ -441,25 +447,29 @@ int *getClusters(char *data, int *ph=NULL) {
if (max>nSigma*(clusters+nph)->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*(clusters+nph)->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*(clusters+nph)->rms) { if (max>nSigma*(clusters+nph)->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*(clusters+nph)->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*(clusters+nph)->rms) {
if (val[iy][ix]>=max) { if (val[iy][ix]>=max) {
eventMask[iy][ix]=PHOTON_MAX; eventMask[iy][ix]=PHOTON_MAX;
(clusters+nph)->tot=tot; // (clusters+nph)->tot=tot;
(clusters+nph)->x=ix; (clusters+nph)->x=ix;
(clusters+nph)->y=iy; (clusters+nph)->y=iy;
// (clusters+nph)->iframe=det->getFrameNumber(data); (clusters+nph)->iframe=iframe;
// cout << det->getFrameNumber(data) << " " << (clusters+nph)->iframe << endl; // cout << det->getFrameNumber(data) << " " << (clusters+nph)->iframe << endl;
(clusters+nph)->ped=getPedestal(ix,iy,0); // (clusters+nph)->ped=getPedestal(ix,iy,0);
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { // for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { // for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
(clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); // if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx)
// (clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir);
// else
// (clusters+nph)->set_data(0,ic,ir);
// }
// }
good=1;
if (eMin>0 && tot<eMin) good=0;
if (eMax>0 && tot>eMax) good=0;
if (good) {
nph++;
image[iy*nx+ix]++;
} }
}
good=1;
if (eMin>0 && tot<eMin) good=0;
if (eMax>0 && tot>eMax) good=0;
if (good) {
nph++;
image[iy*nx+ix]++;
}
} else { } else {
@ -474,8 +484,9 @@ int *getClusters(char *data, int *ph=NULL) {
nphFrame=nph; nphFrame=nph;
nphTot+=nph; nphTot+=nph;
//cout << nphFrame << endl; //cout << nphFrame << endl;
// cout <<"**********************************"<< det->getFrameNumber(data) << " " << nphFrame << endl; if (iframe%10000==0)
writeClusters(det->getFrameNumber(data)); cout <<"**********************************"<< iframe << " " << nphFrame << endl;
writeClusters(iframe);
return image; return image;
}; };
@ -576,12 +587,15 @@ int *getClusters(char *data, int *ph=NULL) {
void writeClusters(int fn){ void writeClusters(int fn){
if (myFile) { if (myFile) {
//cout << "++" << endl; //cout << "++" << endl;
pthread_mutex_lock(fm); //pthread_mutex_lock(fm);
// cout <<"**********************************"<< fn << " " << nphFrame << endl; fm->lock();
// cout <<id << " **********************************"<< fn << " " << nphFrame << endl;
writeClusters(myFile,clusters,nphFrame, fn); writeClusters(myFile,clusters,nphFrame, fn);
// for (int i=0; i<nphFrame; i++) // for (int i=0; i<nphFrame; i++)
// (clusters+i)->write(myFile); // (clusters+i)->write(myFile);
pthread_mutex_unlock(fm); // cout << "--" << endl;
fm->unlock();
//pthread_mutex_unlock(fm);
//cout << "--" << endl; //cout << "--" << endl;
} }
}; };
@ -613,7 +627,8 @@ int *getClusters(char *data, int *ph=NULL) {
void setEnergyRange(double emi, double ema){eMin=emi; eMax=ema;}; void setEnergyRange(double emi, double ema){eMin=emi; eMax=ema;};
void getEnergyRange(double &emi, double &ema){emi=eMin; ema=eMax;}; void getEnergyRange(double &emi, double &ema){emi=eMin; ema=eMax;};
void setMutex(pthread_mutex_t *m){fm=m;}; // void setMutex(pthread_mutex_t *m){fm=m;};
void setMutex(mutex *m){fm=m;};
protected: protected:
@ -631,8 +646,8 @@ int *getClusters(char *data, int *ph=NULL) {
int nphTot; int nphTot;
int nphFrame; int nphFrame;
pthread_mutex_t *fm; // pthread_mutex_t *fm;
mutex *fm;
}; };