Compare commits

...

12 Commits

9 changed files with 447 additions and 153 deletions

View File

@ -28,6 +28,10 @@
@li version is the version number of this structure format
*/
#include <algorithm>
#include <numeric>
#include <tuple>
namespace strixelSingleChip {
constexpr int nc_rawimg = 1024; // for full images //256;
constexpr int nr_rawimg = 512;
@ -77,7 +81,7 @@ constexpr int c6g1_ystart = c6g2_yend + 1; // 448
constexpr int c6g1_yend = c6g2_yend + 64 - gr; // 502
// y shift due to faulty bonding (relevant for M408)
constexpr int bond_shift_y = 1; // CHANGE IF YOU CHANGE MODULE!
constexpr int bond_shift_y = 0; // CHANGE IF YOU CHANGE MODULE!
} // namespace strixelSingleChip
@ -97,6 +101,13 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
int chip_x0;
int chip_y0;
int x0, y0, x1, y1, shifty;
struct {
uint16_t xmin;
uint16_t xmax;
uint16_t ymin;
uint16_t ymax;
int nc;
} globalROI;
int getMultiplicator(const int group) {
int multiplicator;
@ -215,9 +226,113 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
}
}
void remapROI(uint16_t xmin, uint16_t xmax, uint16_t ymin, uint16_t ymax) {
std::tuple< uint16_t, uint16_t, uint16_t, uint16_t > adjustROItoLimits(uint16_t xmin,
uint16_t xmax,
uint16_t ymin,
uint16_t ymax,
uint16_t lim_roi_xmin,
uint16_t lim_roi_xmax,
uint16_t lim_roi_ymin,
uint16_t lim_roi_ymax) {
uint16_t xmin_roi, xmax_roi, ymin_roi, ymax_roi;
if ( xmin < lim_roi_xmin)
xmin_roi = lim_roi_xmin;
else
xmin_roi = xmin;
if ( xmax > lim_roi_xmax )
xmax_roi = lim_roi_xmax;
else
xmax_roi = xmax;
if ( ymin < lim_roi_ymin )
ymin_roi = lim_roi_ymin;
else
ymin_roi = ymin;
if ( ymax > lim_roi_ymax )
ymax_roi = lim_roi_ymax;
else
ymax_roi = ymax;
return std::make_tuple(xmin_roi, xmax_roi, ymin_roi, ymax_roi);
}
std::vector < std::tuple< int, int, uint16_t, uint16_t, uint16_t, uint16_t > > mapSubROIs(uint16_t xmin,
uint16_t xmax,
uint16_t ymin,
uint16_t ymax) {
bool chip_1_1 = false;
bool chip_1_2 = false;
bool chip_1_3 = false;
bool chip_6_1 = false;
bool chip_6_2 = false;
bool chip_6_3 = false;
for ( int x=xmin; x!=xmax+1; ++x ) {
for ( int y=ymin; y!=ymax; ++y ) {
if ( c1g1_xstart<=x && x<=c1_xend && (c1g1_ystart+bond_shift_y)<=y && y<=(c1g1_yend+bond_shift_y) )
chip_1_1 = true;
if ( c1g2_xstart<=x && x<=c1_xend && (c1g2_ystart+bond_shift_y)<=y && y<=(c1g2_yend+bond_shift_y) )
chip_1_2 = true;
if ( c1g3_xstart<=x && x<=c1_xend && (c1g3_ystart+bond_shift_y)<=y && y<=(c1g3_yend+bond_shift_y) )
chip_1_3 = true;
if ( c6_xstart<=x && x<=c6g1_xend && (c6g1_ystart-bond_shift_y)<=y && y<=(c6g1_yend-bond_shift_y) )
chip_6_1 = true;
if ( c6_xstart<=x && x<=c6g2_xend && (c6g2_ystart-bond_shift_y)<=y && y<=(c6g2_yend-bond_shift_y) )
chip_6_2 = true;
if ( c6_xstart<=x && x<=c6g3_xend && (c6g3_ystart-bond_shift_y)<=y && y<=(c6g3_yend-bond_shift_y) )
chip_6_3 = true;
}
}
uint16_t xmin_roi{}, xmax_roi{}, ymin_roi{}, ymax_roi{};
//[ chip, group, xmin, xmax, ymin, ymax ]
std::vector < std::tuple< int, int, uint16_t, uint16_t, uint16_t, uint16_t > > rois{};
if (chip_1_1) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c1g1_xstart, c1_xend, 0, c1g1_yend+bond_shift_y );
rois.push_back( std::make_tuple( 1, 1, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_1_2) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c1g2_xstart, c1_xend, c1g2_ystart+bond_shift_y, c1g2_yend+bond_shift_y );
rois.push_back( std::make_tuple( 1, 2, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_1_3) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c1g3_xstart, c1_xend, c1g3_ystart+bond_shift_y, c1g3_yend+bond_shift_y );
rois.push_back( std::make_tuple( 1, 3, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_6_3) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c6_xstart, c6g3_xend, c6g3_ystart-bond_shift_y, c6g3_yend-bond_shift_y );
rois.push_back( std::make_tuple( 6, 3, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_6_2) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c6_xstart, c6g2_xend, c6g2_ystart-bond_shift_y, c6g2_yend-bond_shift_y );
rois.push_back( std::make_tuple( 6, 2, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
if (chip_6_1) {
std::tie( xmin_roi, xmax_roi, ymin_roi, ymax_roi ) =
adjustROItoLimits( xmin, xmax, ymin, ymax,
c6_xstart, c6g1_xend, c6g1_ystart-bond_shift_y, 511 );
rois.push_back( std::make_tuple( 6, 1, xmin_roi, xmax_roi, ymin_roi, ymax_roi ) );
}
return rois;
}
void remapROI(std::tuple< int, int, uint16_t, uint16_t, uint16_t, uint16_t > roi) {
// determine group and chip selected by ROI
int group;
int group, xmin, xmax, ymin, ymax;
std::tie( mchip, group, xmin, xmax, ymin, ymax ) = roi;
/*
if (ymax <= c1g1_yend + bond_shift_y) {
group = 1;
mchip = 1;
@ -243,18 +358,17 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
group = -1;
mchip = -1;
}
*/
int multiplicator = getMultiplicator(group);
setMappingShifts(group);
std::cout << "chip: " << mchip << ", group: " << group << ", m: " << multiplicator
std::cout << "remapping chip: " << mchip << ", group: " << group << ", m: " << multiplicator
<< ", x0: " << x0 << ", x1: " << x1 << ", y0: " << y0
<< ", y1: " << y1 << std::endl;
// get ROI raw image number of columns
int nc_roi = xmax - xmin + 1;
std::cout << "nc_roi = " << nc_roi << std::endl;
std::cout << "Adjusted roi: [" << xmin << ", " << xmax << ", " << ymin << ", " << ymax << "]" << std::endl;
// make sure loop bounds are correct
/*
if (y0 < ymin)
std::cout << "Error ymin" << std::endl;
if (y1 > ymax)
@ -264,6 +378,7 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
std::cout << "Error xmin" << std::endl;
if (x1 > xmax)
std::cout << "Error xmax" << std::endl;
*/
// remapping loop
int ix, iy = 0;
@ -277,8 +392,10 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
}
// if (iy< 40) cout << iy << " " << ix <<endl;
if ( ipx>=xmin && ipx<=xmax && ipy>=ymin && ipy <=ymax )
dataMap[iy][ix] =
sizeof(header) + (nc_roi * (ipy - ymin) + (ipx - xmin)) * 2;
sizeof(header) + (globalROI.nc * (ipy - globalROI.ymin) + (ipx - globalROI.xmin)) * 2;
else dataMap[iy][ix] = sizeof(header);
groupmap[iy][ix] = group - 1;
}
}
@ -307,16 +424,31 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
}
}
globalROI.xmin = xmin;
globalROI.xmax = xmax;
globalROI.ymin = ymin;
globalROI.ymax = ymax;
std::cout << "sizeofheader = " << sizeof(header) << std::endl;
std::cout << "Jungfrau strixels 2X single chip with full module data "
<< std::endl;
if (xmin < xmax && ymin < ymax) {
// get ROI raw image number of columns
globalROI.nc = xmax - xmin + 1;
std::cout << "nc_roi = " << globalROI.nc << std::endl;
dataSize =
(xmax - xmin + 1) * (ymax - ymin + 1) * 2 + sizeof(header);
std::cout << "datasize " << dataSize << std::endl;
remapROI(xmin, xmax, ymin, ymax);
//[ chip, group, xmin, xmax, ymin, ymax ]
auto rois = mapSubROIs(xmin, xmax, ymin, ymax);
//function to fill vector of rois from globalROI
for ( auto roi : rois )
remapROI(roi);
} else {

View File

@ -3,6 +3,7 @@
#ifndef JUNGFRAUMODULEDATA_H
#define JUNGFRAUMODULEDATA_H
#include <cstdint>
#include "sls/sls_detector_defs.h"
#include "slsDetectorData.h"
//#define VERSION_V2
@ -27,7 +28,7 @@ typedef struct {
uint64_t bunchNumber; /**< is the frame number */
uint64_t pre; /**< something */
} jf_header;
} jf_header; //Aldo's header!
using namespace std;
class jungfrauModuleData : public slsDetectorData<uint16_t> {
@ -42,20 +43,56 @@ class jungfrauModuleData : public slsDetectorData<uint16_t> {
1286 large etc.) \param c crosstalk parameter for the output buffer
*/
#ifdef ALDO
using header = jf_header;
#else
using header = sls::defs::sls_receiver_header;
#endif
#ifndef ZMQ
#define off sizeof(jf_header)
#define off sizeof(header)
#endif
#ifdef ZMQ
#define off 0
#endif
jungfrauModuleData()
jungfrauModuleData(uint16_t xmin=0, uint16_t xmax=0,
uint16_t ymin=0, uint16_t ymax=0)
: slsDetectorData<uint16_t>(1024, 512,
1024* 512 * 2 + off) {
for (int ix = 0; ix < 1024; ix++) {
for (int iy = 0; iy < 512; iy++) {
for (int ix = 0; ix != 1024; ++ix) {
for (int iy = 0; iy != 512; ++iy) {
dataMap[iy][ix] = off;
}
}
if (xmin < xmax && ymin < ymax) {
int nc_roi = xmax - xmin + 1;
int nr_roi = ymax - ymin + 1;
std::cout << "nc_roi = " << nc_roi << std::endl;
std::cout << "nr_roi = " << nr_roi << std::endl;
dataSize =
(xmax - xmin + 1) * (ymax - ymin + 1) * 2 + off;
std::cout << "datasize " << dataSize << std::endl;
for (int ix = xmin; ix < xmax+1; ++ix) {
for (int iy = ymin; iy < ymax+1; ++iy) {
dataMap[iy][ix] = off + (nc_roi * iy + ix) * 2;
#ifdef HIGHZ
dataMask[iy][ix] = 0x3fff;
#endif
}
}
} else {
for (int ix = 0; ix < 1024; ++ix) {
for (int iy = 0; iy < 512; ++iy) {
dataMap[iy][ix] = off + (1024 * iy + ix) * 2;
#ifdef HIGHZ
dataMask[iy][ix] = 0x3fff;
@ -63,7 +100,7 @@ class jungfrauModuleData : public slsDetectorData<uint16_t> {
}
}
}
iframe = 0;
@ -150,7 +187,7 @@ class jungfrauModuleData : public slsDetectorData<uint16_t> {
//int pn;
// cout << dataSize << endl;
if (ff >= 0)
//if (ff >= 0)
//fnum = ff;
if (filebin.is_open()) {

View File

@ -7,6 +7,7 @@
set(JUNGFRAU_EXECUTABLES)
find_package(fmt REQUIRED)
find_package(nlohmann_json 3.11.2 REQUIRED)
# jungfrauRawDataProcess
add_executable(jungfrauRawDataProcess jungfrauRawDataProcess.cpp)
@ -79,6 +80,7 @@ foreach(exe ${JUNGFRAU_EXECUTABLES})
pthread
tiffio
fmt::fmt
nlohmann_json::nlohmann_json
#-L/usr/lib64/
#-lm -lstdc++ -lrt

View File

@ -41,6 +41,9 @@
#include <ctime>
#include <fmt/core.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
std::string getRootString( const std::string& filepath ) {
size_t pos1 = filepath.find_last_of("/");
@ -61,20 +64,24 @@ std::string getRootString( const std::string& filepath ) {
std::string createFileName( const std::string& dir, const std::string& fprefix="run", const std::string& fsuffix="", const std::string& fext="raw", int aindex=0, int mindex=0, int findex=0, int outfilecounter=-1 ) {
if (outfilecounter >= 0)
return fmt::format("{:s}/{:s}_d{:d}_f{:d}_{:d}_f{:05d}.{:s}", dir, fprefix, mindex, findex, aindex, outfilecounter, fext);
else if (fsuffix.length()!=0)
else if (fsuffix.length()!=0) {
if (fsuffix == "master")
return fmt::format("{:s}/{:s}_master_{:d}.{:s}", dir, fprefix, aindex, fext);
else
return fmt::format("{:s}/{:s}_{:s}.{:s}", dir, fprefix, fsuffix, fext);
}
else
return fmt::format("{:s}/{:s}_d{:d}_f{:d}_{:d}.{:s}", dir, fprefix, mindex, findex, aindex, fext);
}
int main(int argc, char *argv[]) {
if (argc < 5) {
if (argc < 6) {
std::cout
<< "Usage is " << argv[0]
<< "indir outdir fprefix(excluding slsDetector standard suffixes and extension) fextension "
"[runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
"[nframes] [xmin xmax ymin ymax] [gainmap]"
<< "indir outdir [fprefix(excluding slsDetector standard suffixes and extension)] [fextension] "
"[fmin] [fmax] [runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
"[nframes] [xmin xmax ymin ymax] [optional: bool read rxroi from data file header] [gainmap]"
<< std::endl;
std::cout
<< "threshold <0 means analog; threshold=0 means cluster finder; "
@ -106,34 +113,69 @@ int main(int argc, char *argv[]) {
std::string outdir(argv[2]);
std::string fprefix(argv[3]);
std::string fext(argv[4]);
int fmin = 0;
if (argc >= 6)
fmin = atoi(argv[5]);
int fmax = fmin;
if (argc >= 7)
fmax = atoi(argv[6]);
int runmin = 0;
// cout << "argc is " << argc << endl;
if (argc >= 6) {
runmin = atoi(argv[5]);
if (argc >= 8) {
runmin = atoi(argv[7]);
}
int runmax = runmin;
if (argc >= 7) {
runmax = atoi(argv[6]);
if (argc >= 9) {
runmax = atoi(argv[8]);
}
std::string pedfilename{};
if (argc >= 8) {
pedfilename = argv[7];
if (argc >= 10) {
pedfilename = argv[9];
}
double thr = 0;
double thr1 = 1;
if (argc >= 9) {
thr = atof(argv[8]);
if (argc >= 11) {
thr = atof(argv[10]);
}
int nframes = 0;
if (argc >= 10) {
nframes = atoi(argv[9]);
if (argc >= 12) {
nframes = atoi(argv[11]);
}
bool readrxroifromdatafile = false;
if (argc >= 17)
readrxroifromdatafile = atoi(argv[16]);
// Receiver ROI
uint16_t rxroi_xmin = 0;
uint16_t rxroi_xmax = 0;
uint16_t rxroi_ymin = 0;
uint16_t rxroi_ymax = 0;
{ //protective scope so ifstream gets destroyed properly
auto jsonmastername = createFileName( indir, fprefix, "master", "json", runmin );
std::cout << "json master file " << jsonmastername << std::endl;
std::ifstream masterfile(jsonmastername); //, ios::in | ios::binary);
if (masterfile.is_open()) {
json j;
masterfile >> j;
rxroi_xmin = j["Receiver Roi"]["xmin"];
rxroi_xmax = j["Receiver Roi"]["xmax"];
rxroi_ymin = j["Receiver Roi"]["ymin"];
rxroi_ymax = j["Receiver Roi"]["ymax"];
masterfile.close();
std::cout << "Read Receiver ROI [" << rxroi_xmin << ", " << rxroi_xmax << ", "
<< rxroi_ymin << ", " << rxroi_ymax << "] from json master file" << std::endl;
} else
std::cout << "Could not open master file " << jsonmastername << std::endl;
}
// Define decoders...
@ -144,20 +186,16 @@ int main(int argc, char *argv[]) {
int nx = 256, ny = 256;
#endif
#ifdef MODULE
jungfrauModuleData *decoder = new jungfrauModuleData();
jungfrauModuleData *decoder = new jungfrauModuleData(rxroi_xmin, rxroi_xmax, rxroi_ymin, rxroi_ymax);
int nx = 1024, ny = 512;
#endif
#endif
#ifdef JFSTRX
cout << "Jungfrau strixel full module readout" << endl;
// ROI
uint16_t xxmin = 0;
uint16_t xxmax = 0;
uint16_t yymin = 0;
uint16_t yymax = 0;
#ifndef ALDO
if (readrxroifromdatafile)
{ //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream)
using header = sls::defs::sls_receiver_header;
// check if there is a roi in the header
@ -180,10 +218,10 @@ int main(int argc, char *argv[]) {
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
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;
rxroi_xmin = croi.xmin;
rxroi_xmax = croi.xmax;
rxroi_ymin = croi.ymin;
rxroi_ymax = croi.ymax;
} else
std::cout << "reading error" << std::endl;
firstfile.close();
@ -193,7 +231,7 @@ int main(int argc, char *argv[]) {
#endif
jungfrauLGADStrixelsData *decoder =
new jungfrauLGADStrixelsData(xxmin, xxmax, yymin, yymax);
new jungfrauLGADStrixelsData(rxroi_xmin, rxroi_xmax, rxroi_ymin, rxroi_ymax);
int nx = 1024 / 3, ny = 512 * 5;
#endif
#ifdef JFSTRXCHIP1
@ -218,19 +256,20 @@ int main(int argc, char *argv[]) {
decoder->getDetectorSize(nx, ny);
std::cout << "Detector size is " << nx << " " << ny << std::endl;
int xmin = 0, xmax = nx, ymin = 0, ymax = ny;
if (argc >= 14) {
xmin = atoi(argv[10]);
xmax = atoi(argv[11]);
ymin = atoi(argv[12]);
ymax = atoi(argv[13]);
//Cluster finder ROI
int xmin = 0, xmax = nx-1, ymin = 0, ymax = ny-1;
if (argc >= 16) {
xmin = atoi(argv[12]);
xmax = atoi(argv[13]);
ymin = atoi(argv[14]);
ymax = atoi(argv[15]);
}
std::cout << xmin << " " << xmax << " " << ymin << " " << ymax << " "
std::cout << "Cluster finder ROI: [" << xmin << ", " << xmax << ", " << ymin << ", " << ymax << "]"
<< std::endl;
char *gainfname = NULL;
if (argc > 14) {
gainfname = argv[14];
if (argc > 17) {
gainfname = argv[17];
std::cout << "Gain map file name is: " << gainfname << std::endl;
}
@ -239,6 +278,8 @@ int main(int argc, char *argv[]) {
std::cout << "input directory is " << indir << std::endl;
std::cout << "output directory is " << outdir << std::endl;
std::cout << "input file prefix is " << fprefix << std::endl;
std::cout << "fmin is " << fmin << std::endl;
std::cout << "fmax is " << fmax << std::endl;
std::cout << "runmin is " << runmin << std::endl;
std::cout << "runmax is " << runmax << std::endl;
if (pedfilename.length()!=0)
@ -319,7 +360,7 @@ int main(int argc, char *argv[]) {
mt->setFrameMode(ePedestal);
ifstream pedefile(fname, ios::in | ios::binary);
std::ifstream pedefile(fname, ios::in | ios::binary);
// //open file
if (pedefile.is_open()) {
std::cout << "bbbb " << std::ctime(&end_time) << std::endl;
@ -380,26 +421,27 @@ int main(int argc, char *argv[]) {
}
ifr = 0;
int ifile = 0;
int ioutfile = 0;
mt->setFrameMode(eFrame);
FILE *of = NULL;
for (int irun = runmin; irun <= runmax; irun++) {
for (int irun = runmin; irun <= runmax; ++irun) {
for (int ifile = fmin; ifile <= fmax; ++ifile) {
std::cout << "DATA ";
std::string fsuffix{};
auto fname = createFileName( indir, fprefix, fsuffix, fext, irun );
auto imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun );
auto cfname = createFileName( outdir, fprefix, fsuffix, "clust", irun );
auto fname = createFileName( indir, fprefix, fsuffix, fext, irun, 0, ifile );
auto imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, ifile );
auto cfname = createFileName( outdir, fprefix, fsuffix, "clust", irun, 0, ifile );
std::cout << fname << " ";
std::cout << imgfname << std::endl;
std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl;
// std::cout << fname << " " << outfname << " " << imgfname << std::endl;
ifstream filebin(fname, ios::in | ios::binary);
std::ifstream filebin(fname, ios::in | ios::binary);
// //open file
ifile = 0;
ioutfile = 0;
if (filebin.is_open()) {
if (thr <= 0 && cf != 0) { // cluster finder
if (of == NULL) {
@ -436,10 +478,10 @@ int main(int argc, char *argv[]) {
std::cout << " " << ifr << " " << ff << std::endl;
if (nframes > 0) {
if (ifr % nframes == 0) {
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ifile );
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ioutfile );
mt->writeImage(imgfname.c_str(), thr1);
mt->clearImage();
ifile++;
ioutfile++;
}
}
// } else
@ -453,7 +495,7 @@ int main(int argc, char *argv[]) {
}
if (nframes >= 0) {
if (nframes > 0)
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ifile );
imgfname = createFileName( outdir, fprefix, fsuffix, "tiff", irun, 0, 0, ioutfile );
std::cout << "Writing tiff to " << imgfname << " " << thr1
<< std::endl;
mt->writeImage(imgfname.c_str(), thr1);
@ -470,8 +512,9 @@ int main(int argc, char *argv[]) {
std::cout << "Could not open " << fname << " for reading "
<< std::endl;
}
}
if (nframes < 0) {
auto imgfname = createFileName( outdir, fprefix, "sum", "tiff", -1, 0, 0, -1 );
auto imgfname = createFileName( outdir, fprefix, "sum", "tiff", runmin, 0, fmin, -1 );
std::cout << "Writing tiff to " << imgfname << " " << thr1 << std::endl;
mt->writeImage(imgfname.c_str(), thr1);
}

View File

@ -41,6 +41,9 @@
#include <ctime>
#include <fmt/core.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
std::string getRootString( const std::string& filepath ) {
size_t pos1;
@ -71,11 +74,11 @@ std::string createFileName( const std::string& dir, const std::string& fprefix="
//NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS!
int main(int argc, char *argv[]) {
if (argc < 10) {
if (argc < 11) {
std::cout
<< "Usage is " << argv[0]
<< " filestxt outdir [pedfile (raw or tiff)] [xmin xmax ymin ymax] "
"[threshold] [nframes] "
<< " filestxt outdir [json master] [pedfile (raw or tiff)] [xmin xmax ymin ymax] "
"[threshold] [nframes] [optional: bool read rxroi from data file header]"
"NOTE THAT THE DATA FILES HAVE TO BE IN THE RIGHT ORDER SO THAT PEDESTAL TRACKING WORKS! "
<< std::endl;
std::cout
@ -105,19 +108,19 @@ int main(int argc, char *argv[]) {
const std::string txtfilename(argv[1]);
const std::string outdir(argv[2]);
const std::string pedfilename(argv[3]);
int xmin = atoi(argv[4]);
int xmax = atoi(argv[5]);
int ymin = atoi(argv[6]);
int ymax = atoi(argv[7]);
const std::string jsonmastername(argv[3]);
const std::string pedfilename(argv[4]);
double thr = 0;
double thr1 = 1;
thr = atof(argv[8]);
thr = atof(argv[9]);
int nframes = 0;
nframes = atoi(argv[9]);
nframes = atoi(argv[10]);
bool readrxroifromdatafile = false;
if (argc > 11)
readrxroifromdatafile = atoi(argv[11]);
//Get vector of filenames from input txt-file
std::vector<std::string> filenames{};
@ -147,6 +150,30 @@ int main(int argc, char *argv[]) {
std::cout << "###############" << std::endl;
// Receiver ROI
uint16_t rxroi_xmin = 0;
uint16_t rxroi_xmax = 0;
uint16_t rxroi_ymin = 0;
uint16_t rxroi_ymax = 0;
{ //protective scope so ifstream gets destroyed properly
std::ifstream masterfile(jsonmastername); //, ios::in | ios::binary);
if (masterfile.is_open()) {
json j;
masterfile >> j;
rxroi_xmin = j["Receiver Roi"]["xmin"];
rxroi_xmax = j["Receiver Roi"]["xmax"];
rxroi_ymin = j["Receiver Roi"]["ymin"];
rxroi_ymax = j["Receiver Roi"]["ymax"];
masterfile.close();
std::cout << "Read rxROI [" << rxroi_xmin << ", " << rxroi_xmax << ", "
<< rxroi_ymin << ", " << rxroi_ymax << "]" << std::endl;
} else
std::cout << "Could not open master file " << jsonmastername << std::endl;
}
// Define decoders...
#if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && \
!defined JFSTRXCHIP6
@ -162,13 +189,9 @@ int main(int argc, char *argv[]) {
#ifdef JFSTRX
cout << "Jungfrau strixel full module readout" << endl;
// ROI
uint16_t xxmin = 0;
uint16_t xxmax = 0;
uint16_t yymin = 0;
uint16_t yymax = 0;
#ifndef ALDO
if (readrxroifromdatafile)
{ //THIS SCOPE IS IMPORTANT! (To ensure proper destruction of ifstream)
using header = sls::defs::sls_receiver_header;
// check if there is a roi in the header
@ -182,7 +205,7 @@ int main(int argc, char *argv[]) {
//std::string filepath(argv[9]); //This is a problem if the input files have different ROIs!
std::cout << "Reading header of file " << filenames[0] << " to check for ROI "
<< std::endl;
ifstream firstfile(filenames[0], ios::in | ios::binary);
std::ifstream firstfile( filenames[0], ios::in | ios::binary);
if (firstfile.is_open()) {
header hbuffer;
std::cout << "sizeof(header) = " << sizeof(header) << std::endl;
@ -190,10 +213,10 @@ int main(int argc, char *argv[]) {
memcpy(&croi, &hbuffer.detHeader.detSpec1, 8);
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;
rxroi_xmin = croi.xmin;
rxroi_xmax = croi.xmax;
rxroi_ymin = croi.ymin;
rxroi_ymax = croi.ymax;
} else
std::cout << "reading error" << std::endl;
firstfile.close();
@ -203,7 +226,7 @@ int main(int argc, char *argv[]) {
#endif
jungfrauLGADStrixelsData *decoder =
new jungfrauLGADStrixelsData(xxmin, xxmax, yymin, yymax);
new jungfrauLGADStrixelsData(rxroi_xmin, rxroi_xmax, rxroi_ymin, rxroi_ymax);
int nx = 1024 / 3, ny = 512 * 5;
#endif
#ifdef JFSTRXCHIP1
@ -228,7 +251,16 @@ int main(int argc, char *argv[]) {
decoder->getDetectorSize(nx, ny);
std::cout << "Detector size is " << nx << " " << ny << std::endl;
//Cluster finder ROI
int xmin = 0, xmax = nx-1, ymin = 0, ymax = ny-1;
xmin = atoi(argv[5]);
xmax = atoi(argv[6]);
ymin = atoi(argv[7]);
ymax = atoi(argv[8]);
std::cout << "Cluster finder ROI: [" << xmin << ", " << xmax << ", " << ymin << ", " << ymax << "]"
<< std::endl;
/* old
if ( xmin == xmax ) {
xmin = 0;
xmax = nx;
@ -239,6 +271,7 @@ int main(int argc, char *argv[]) {
}
std::cout << xmin << " " << xmax << " " << ymin << " " << ymax << " "
<< std::endl;
*/
/*
char *gainfname = NULL;
@ -410,7 +443,7 @@ int main(int argc, char *argv[]) {
std::time(&end_time);
std::cout << std::ctime(&end_time) << std::endl;
ifstream filebin(filenames[ifile], ios::in | ios::binary);
std::ifstream filebin(filenames[ifile], ios::in | ios::binary);
// //open file
ioutfile = 0;
if (filebin.is_open()) {

View File

@ -193,6 +193,7 @@ void qDrawPlot::SetupPlots() {
gainplot2d = new SlsQt2DPlot(boxPlot, true);
gainplot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5,
nPixelsY - 0.5, gainData);
gainplot2d->Update();
gainplot2d->hide();
connect(plot2d, SIGNAL(PlotZoomedSignal(const QRectF &)), this,
SLOT(Zoom2DGainPlot(const QRectF &)));
@ -1009,6 +1010,7 @@ void qDrawPlot::Update2dPlot() {
if (isGainDataExtracted) {
gainplot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5,
nPixelsY - 0.5, gainData);
gainplot2d->Update();
if (!gainplot2d->isVisible()) {
gainplot2d->setFixedWidth(plot2d->width() /
qDefs::DATA_GAIN_PLOT_RATIO);

View File

@ -3323,6 +3323,27 @@ void *start_timer(void *arg) {
break;
}
// change gain and data for every frame
{
const int nchannels = NCHIP * NCHAN;
int gainVal = 0;
for (int i = 0; i < nchannels; ++i) {
if ((i % nchannels) < 400) {
gainVal = 1 + frameNr;
} else if ((i % nchannels) < 800) {
gainVal = 2 + frameNr;
} else {
gainVal = 3 + frameNr;
}
int dataVal =
*((uint16_t *)(imageData + i * sizeof(uint16_t)));
dataVal += frameNr;
int channelVal =
(dataVal & ~GAIN_VAL_MSK) | (gainVal << GAIN_VAL_OFST);
*((uint16_t *)(imageData + i * sizeof(uint16_t))) =
(uint16_t)channelVal;
}
}
// sleep for exposure time
struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin);

View File

@ -2552,8 +2552,7 @@ void setPedestalMode(int enable, uint8_t frames, uint16_t loops) {
if (enable) {
LOG(logINFOBLUE, ("Enabling pedestal mode [frames: %hhu, loops: %hu]\n",
frames, loops));
// enable
bus_w(addr, bus_r(addr) | PEDESTAL_MODE_ENBLE_MSK);
// frames
bus_w(addr, bus_r(addr) & ~PEDESTAL_MODE_LNGTH_MSK);
bus_w(addr, bus_r(addr) | ((frames << PEDESTAL_MODE_LNGTH_OFST) &
@ -2562,6 +2561,8 @@ void setPedestalMode(int enable, uint8_t frames, uint16_t loops) {
bus_w(addr, bus_r(addr) & ~PEDESTAL_MODE_ITRTNS_MSK);
bus_w(addr, bus_r(addr) | ((loops << PEDESTAL_MODE_ITRTNS_OFST) &
PEDESTAL_MODE_ITRTNS_MSK));
// enable
bus_w(addr, bus_r(addr) | PEDESTAL_MODE_ENBLE_MSK);
// if it was switched off before, remember the #frames and #triggers
if (prevPedestalEnable == 0) {
@ -2726,6 +2727,7 @@ void *start_timer(void *arg) {
if (i % pixelsPerPacket == 0) {
++dataVal;
}
if ((i % 1024) < 300) {
gainVal = 1;
} else if ((i % 1024) < 600) {
@ -2766,6 +2768,28 @@ void *start_timer(void *arg) {
clock_gettime(CLOCK_REALTIME, &begin);
usleep(expUs);
// change gain and data for every frame
{
const int npixels = (NCHAN * NCHIP);
for (int i = 0; i < npixels; ++i) {
int gainVal = 0;
if ((i % 1024) < 300) {
gainVal = 1 + iframes;
} else if ((i % 1024) < 600) {
gainVal = 2 + iframes;
} else {
gainVal = 3 + iframes;
}
int dataVal =
*((uint16_t *)(imageData + i * sizeof(uint16_t)));
dataVal += iframes;
int pixelVal =
(dataVal & ~GAIN_VAL_MSK) | (gainVal << GAIN_VAL_OFST);
*((uint16_t *)(imageData + i * sizeof(uint16_t))) =
(uint16_t)pixelVal;
}
}
int srcOffset = 0;
int srcOffset2 = DATA_BYTES / 2;
int row0 = (numInterfaces == 1 ? detPos[1] : detPos[3]);