Jf strixelmap with roi (#715)

* Fix ROI mapping, Formatting, Minor edit
---------

Co-authored-by: vhinger182 <viktoria.hinger@psi.ch>
Co-authored-by: vhinger182 <hinger_v@hv_home_lt1.localdomain>
This commit is contained in:
Dhanya Thattil
2023-04-12 14:03:04 +02:00
committed by GitHub
parent cab2b335dc
commit a5022ff0ee
2 changed files with 177 additions and 173 deletions

View File

@ -74,7 +74,7 @@ namespace strixelSingleChip {
constexpr int c6g1_yend = c6g2_yend + 64 - gr; //502 constexpr int c6g1_yend = c6g2_yend + 64 - gr; //502
//y shift due to faulty bonding (relevant for M408) //y shift due to faulty bonding (relevant for M408)
constexpr int bond_shift_y = 0; //CHANGE IF YOU CHANGE MODULE! constexpr int bond_shift_y = 1; //CHANGE IF YOU CHANGE MODULE!
} }
@ -126,21 +126,21 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
x0 = 10+chip_x0; //9 gr + 1 sq pixel x0 = 10+chip_x0; //9 gr + 1 sq pixel
x1 = 246+chip_x0; x1 = 246+chip_x0;
y0 = 9+chip_y0; y0 = 9+chip_y0;
y1 = 64+chip_y0; y1 = 63+chip_y0;
shifty = 0; shifty = 0;
break; break;
case 2: case 2:
x0 = 12+chip_x0; x0 = 12+chip_x0;
x1 = 247+chip_x0; x1 = 247+chip_x0;
y0 = 64+chip_y0; y0 = 64+chip_y0;
y1 = 128+chip_y0; y1 = 127+chip_y0;
shifty = g1_nrows; shifty = g1_nrows;
break; break;
case 3: case 3:
x0 = 11+chip_x0; x0 = 11+chip_x0;
x1 = 247+chip_x0; x1 = 247+chip_x0;
y0 = 128+chip_y0; y0 = 128+chip_y0;
y1 = 247+chip_y0; y1 = 246+chip_y0;
shifty = g2_nrows+g1_nrows; shifty = g2_nrows+g1_nrows;
break; break;
} }
@ -240,9 +240,9 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
for ( int ipy=y0; ipy<=y1; ++ipy) { for ( int ipy=y0; ipy<=y1; ++ipy) {
for ( int ipx=x0; ipx<=x1; ++ipx ) { for ( int ipx=x0; ipx<=x1; ++ipx ) {
ix = int ((ipx-x0-xmin)/multiplicator); ix = int ((ipx-x0/*-xmin*/)/multiplicator);
for ( int m=0; m<multiplicator;m++ ) { for ( int m=0; m<multiplicator;m++ ) {
if ( (ipx-x0-xmin)%multiplicator==m ) iy=(ipy-y0-ymin)*multiplicator +m + shifty; if ( (ipx-x0/*-xmin*/)%multiplicator==m ) iy=(ipy-y0/*-ymin*/)*multiplicator +m + shifty;
} }
// if (iy< 40) cout << iy << " " << ix <<endl; // if (iy< 40) cout << iy << " " << ix <<endl;

View File

@ -38,21 +38,21 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <ctime> #include <ctime>
using namespace std; //using namespace std;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc < 5) { if (argc < 5) {
cout << "Usage is " << argv[0] std::cout << "Usage is " << argv[0]
<< "indir outdir fname(no extension) fextension [runmin] [runmax] [pedfile (raw or tiff)] [threshold] " << "indir outdir fname(with formatting, no extension) fextension [runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
"[nframes] [xmin xmax ymin ymax] [gainmap]" "[nframes] [xmin xmax ymin ymax] [gainmap]"
<< endl; << std::endl;
cout << "threshold <0 means analog; threshold=0 means cluster finder; " std::cout << "threshold <0 means analog; threshold=0 means cluster finder; "
"threshold>0 means photon counting" "threshold>0 means photon counting"
<< endl; << std::endl;
cout << "nframes <0 means sum everything; nframes=0 means one file per " std::cout << "nframes <0 means sum everything; nframes=0 means one file per "
"run; nframes>0 means one file every nframes" "run; nframes>0 means one file every nframes"
<< endl; << std::endl;
return 1; return 1;
} }
@ -151,6 +151,10 @@ int main(int argc, char *argv[]) {
if ( filebin.read( (char *)&hbuffer, sizeof(header) ) ) { if ( filebin.read( (char *)&hbuffer, sizeof(header) ) ) {
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8); memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", " << croi.ymin << ", " << croi.ymax << "]" << std::endl; std::cout << "Read ROI [" << croi.xmin << ", " << croi.xmax << ", " << croi.ymin << ", " << croi.ymax << "]" << std::endl;
xxmin = croi.xmin;
xxmax = croi.xmax;
yymin = croi.ymin;
yymax = croi.ymax;
} else } else
std::cout << "reading error" << std::endl; std::cout << "reading error" << std::endl;
filebin.close(); filebin.close();
@ -158,7 +162,7 @@ int main(int argc, char *argv[]) {
std::cout << "Could not open " << fname << " for reading " << std::endl; std::cout << "Could not open " << fname << " for reading " << std::endl;
#endif #endif
jungfrauLGADStrixelsData *decoder = new jungfrauLGADStrixelsData( croi.xmin, croi.xmax, croi.ymin, croi.ymax ); jungfrauLGADStrixelsData *decoder = new jungfrauLGADStrixelsData( xxmin, xxmax, yymin, yymax );
int nx = 1024/3, ny = 512*5; int nx = 1024/3, ny = 512*5;
#endif #endif
#ifdef JFSTRXCHIP1 #ifdef JFSTRXCHIP1
@ -231,9 +235,9 @@ int main(int argc, char *argv[]) {
//int dsize = decoder->getDataSize(); //int dsize = decoder->getDataSize();
if (thr > 0) { if (thr > 0) {
cout << "threshold is " << thr << endl; std::cout << "threshold is " << thr << std::endl;
filter->setThreshold(thr); filter->setThreshold(thr);
cf = 0; cf = 0;
} else } else
cf = 1; cf = 1;
@ -287,71 +291,71 @@ int main(int argc, char *argv[]) {
froot[pos]='\0'; froot[pos]='\0';
} }
cout << "PEDESTAL " << endl; std::cout << "PEDESTAL " << std::endl;
// sprintf(imgfname, "%s/pedestals.tiff", outdir); // sprintf(imgfname, "%s/pedestals.tiff", outdir);
if (string(pedfile).find(".tif") == std::string::npos) { if (string(pedfile).find(".tif") == std::string::npos) {
sprintf(fname, "%s", pedfile); sprintf(fname, "%s", pedfile);
std::cout << fname << std::endl; std::cout << fname << std::endl;
std::time(&end_time); std::time(&end_time);
std::cout << "aaa" << std::ctime(&end_time) << std::endl; std::cout << "aaa" << std::ctime(&end_time) << std::endl;
mt->setFrameMode(ePedestal); mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun); // sprintf(fn,fformat,irun);
filebin.open((const char *)(fname), ios::in | ios::binary); filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file // //open file
if (filebin.is_open()) { if (filebin.is_open()) {
std::cout << "bbbb" << std::ctime(&end_time) << std::endl; std::cout << "bbbb" << std::ctime(&end_time) << std::endl;
ff = -1; ff = -1;
while (decoder->readNextFrame(filebin, ff, np, buff)) { while (decoder->readNextFrame(filebin, ff, np, buff)) {
// if (np == 40) { // if (np == 40) {
if ((ifr+1) % 100 == 0) { if ((ifr+1) % 100 == 0) {
std::cout << " ****" << decoder->getValue(buff,20,20);// << endl; std::cout << " ****" << decoder->getValue(buff,20,20);// << endl;
} }
mt->pushData(buff); mt->pushData(buff);
mt->nextThread(); mt->nextThread();
mt->popFree(buff); mt->popFree(buff);
ifr++; ifr++;
if (ifr % 100 == 0) { if (ifr % 100 == 0) {
std::cout << " ****" << ifr << " " << ff << " " << np << std::endl; std::cout << " ****" << ifr << " " << ff << " " << np << std::endl;
} //else } //else
//cout << ifr << " " << ff << " " << np << endl; //cout << ifr << " " << ff << " " << np << endl;
if (ifr>=1000) if (ifr>=1000)
break; break;
ff = -1; ff = -1;
} }
filebin.close(); filebin.close();
while (mt->isBusy()) { while (mt->isBusy()) {
; ;
} }
sprintf(imgfname, "%s/%s_ped.tiff", outdir, froot); sprintf(imgfname, "%s/%s_ped.tiff", outdir, froot);
mt->writePedestal(imgfname); mt->writePedestal(imgfname);
sprintf(imgfname, "%s/%s_rms.tiff", outdir, froot); sprintf(imgfname, "%s/%s_rms.tiff", outdir, froot);
mt->writePedestalRMS(imgfname); mt->writePedestalRMS(imgfname);
} else } else
std::cout << "Could not open pedestal file " << fname std::cout << "Could not open pedestal file " << fname
<< " for reading " << std::endl; << " for reading " << std::endl;
} else { } else {
float *pp = ReadFromTiff(pedfile, nny, nnx); float *pp = ReadFromTiff(pedfile, nny, nnx);
if (pp && (int)nnx == nx && (int)nny == ny) { if (pp && (int)nnx == nx && (int)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];
} }
delete[] pp; delete[] pp;
mt->setPedestal(ped); mt->setPedestal(ped);
std::cout << "Pedestal set from tiff file " << pedfile << std::endl; std::cout << "Pedestal set from tiff file " << pedfile << std::endl;
} else { } else {
std::cout << "Could not open pedestal tiff file " << pedfile std::cout << "Could not open pedestal tiff file " << pedfile
<< " for reading " << std::endl; << " for reading " << std::endl;
} }
} }
std::time(&end_time); std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl; std::cout << std::ctime(&end_time) << std::endl;
} }
ifr = 0; ifr = 0;
int ifile = 0; int ifile = 0;
@ -359,101 +363,101 @@ int main(int argc, char *argv[]) {
for (int irun = runmin; irun <= runmax; irun++) { for (int irun = runmin; irun <= runmax; irun++) {
std::cout << "DATA "; std::cout << "DATA ";
// sprintf(fn,fformat,irun); // sprintf(fn,fformat,irun);
sprintf(ffname, "%s/%s.%s", indir, fformat, fext); sprintf(ffname, "%s/%s.%s", indir, fformat, fext);
sprintf(fname, (const char*)ffname, irun); sprintf(fname, (const char*)ffname, irun);
sprintf(ffname, "%s/%s.tiff", outdir, fformat); sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, (const char*)ffname, irun); sprintf(imgfname, (const char*)ffname, irun);
sprintf(ffname, "%s/%s.clust", outdir, fformat); sprintf(ffname, "%s/%s.clust", outdir, fformat);
sprintf(cfname, (const char*)ffname, irun); sprintf(cfname, (const char*)ffname, irun);
std::cout << fname << " "; std::cout << fname << " ";
std::cout << imgfname << std::endl; std::cout << imgfname << std::endl;
std::time(&end_time); std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl;
// cout << fname << " " << outfname << " " << imgfname << endl;
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) {
of = fopen(cfname, "w");
if (of) {
mt->setFilePointer(of);
std::cout << "file pointer set " << std::endl;
} else {
std::cout << "Could not open " << cfname << " for writing "
<< std::endl;
mt->setFilePointer(NULL);
return 1;
}
}
}
// //while read frame
ff = -1;
ifr = 0;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
// if (np == 40) {
// //push
if ((ifr+1) % 100 == 0) {
std::cout << " ****" << decoder->getValue(buff,20,20);// << endl;
}
mt->pushData(buff);
// // //pop
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr % 100 == 0)
std::cout << " " << ifr << " " << ff << std::endl;
if (nframes > 0) {
if (ifr % nframes == 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
ifile);
sprintf(imgfname, (const char*)ffname, irun);
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
}
}
// } else
// cout << ifr << " " << ff << " " << np << endl;
ff = -1;
}
std::cout << "--" << std::endl;
filebin.close();
while (mt->isBusy()) {
;
}
if (nframes >= 0) {
if (nframes > 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, ifile);
sprintf(imgfname, (const char*)ffname, irun);
} else {
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, (const char*)ffname, irun);
}
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
mt->writeImage(imgfname, thr1);
mt->clearImage();
if (of) {
fclose(of);
of = NULL;
mt->setFilePointer(NULL);
}
}
std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl; std::cout << std::ctime(&end_time) << std::endl;
// cout << fname << " " << outfname << " " << imgfname << endl; } else
filebin.open((const char *)(fname), ios::in | ios::binary); std::cout << "Could not open " << fname << " for reading " << std::endl;
// //open file
ifile = 0;
if (filebin.is_open()) {
if (thr <= 0 && cf != 0) { // cluster finder
if (of == NULL) {
of = fopen(cfname, "w");
if (of) {
mt->setFilePointer(of);
std::cout << "file pointer set " << std::endl;
} else {
std::cout << "Could not open " << cfname << " for writing "
<< std::endl;
mt->setFilePointer(NULL);
return 1;
}
}
}
// //while read frame
ff = -1;
ifr = 0;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
// if (np == 40) {
// //push
if ((ifr+1) % 100 == 0) {
std::cout << " ****" << decoder->getValue(buff,20,20);// << endl;
}
mt->pushData(buff);
// // //pop
mt->nextThread();
mt->popFree(buff);
ifr++;
if (ifr % 100 == 0)
std::cout << " " << ifr << " " << ff << std::endl;
if (nframes > 0) {
if (ifr % nframes == 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
ifile);
sprintf(imgfname, (const char*)ffname, irun);
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
}
}
// } else
// cout << ifr << " " << ff << " " << np << endl;
ff = -1;
}
std::cout << "--" << std::endl;
filebin.close();
while (mt->isBusy()) {
;
}
if (nframes >= 0) {
if (nframes > 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, ifile);
sprintf(imgfname, (const char*)ffname, irun);
} else {
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, (const char*)ffname, irun);
}
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
mt->writeImage(imgfname, thr1);
mt->clearImage();
if (of) {
fclose(of);
of = NULL;
mt->setFilePointer(NULL);
}
}
std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl;
} else
std::cout << "Could not open " << fname << " for reading " << std::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);
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl; std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
mt->writeImage(imgfname, thr1); mt->writeImage(imgfname, thr1);
} }
return 0; return 0;
} }