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 @li version is the version number of this structure format
*/ */
#include <algorithm>
#include <numeric>
#include <tuple>
namespace strixelSingleChip { namespace strixelSingleChip {
constexpr int nc_rawimg = 1024; // for full images //256; constexpr int nc_rawimg = 1024; // for full images //256;
constexpr int nr_rawimg = 512; 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 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 = 1; // CHANGE IF YOU CHANGE MODULE! constexpr int bond_shift_y = 0; // CHANGE IF YOU CHANGE MODULE!
} // namespace strixelSingleChip } // namespace strixelSingleChip
@ -97,6 +101,13 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
int chip_x0; int chip_x0;
int chip_y0; int chip_y0;
int x0, y0, x1, y1, shifty; 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 getMultiplicator(const int group) {
int multiplicator; 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 // 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) { if (ymax <= c1g1_yend + bond_shift_y) {
group = 1; group = 1;
mchip = 1; mchip = 1;
@ -243,18 +358,17 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
group = -1; group = -1;
mchip = -1; mchip = -1;
} }
*/
int multiplicator = getMultiplicator(group); int multiplicator = getMultiplicator(group);
setMappingShifts(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 << ", x0: " << x0 << ", x1: " << x1 << ", y0: " << y0
<< ", y1: " << y1 << std::endl; << ", y1: " << y1 << std::endl;
std::cout << "Adjusted roi: [" << xmin << ", " << xmax << ", " << ymin << ", " << ymax << "]" << std::endl;
// get ROI raw image number of columns
int nc_roi = xmax - xmin + 1;
std::cout << "nc_roi = " << nc_roi << std::endl;
// make sure loop bounds are correct // make sure loop bounds are correct
/*
if (y0 < ymin) if (y0 < ymin)
std::cout << "Error ymin" << std::endl; std::cout << "Error ymin" << std::endl;
if (y1 > ymax) if (y1 > ymax)
@ -264,6 +378,7 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
std::cout << "Error xmin" << std::endl; std::cout << "Error xmin" << std::endl;
if (x1 > xmax) if (x1 > xmax)
std::cout << "Error xmax" << std::endl; std::cout << "Error xmax" << std::endl;
*/
// remapping loop // remapping loop
int ix, iy = 0; int ix, iy = 0;
@ -277,8 +392,10 @@ class jungfrauLGADStrixelsData : public slsDetectorData<uint16_t> {
} }
// if (iy< 40) cout << iy << " " << ix <<endl; // if (iy< 40) cout << iy << " " << ix <<endl;
dataMap[iy][ix] = if ( ipx>=xmin && ipx<=xmax && ipy>=ymin && ipy <=ymax )
sizeof(header) + (nc_roi * (ipy - ymin) + (ipx - xmin)) * 2; dataMap[iy][ix] =
sizeof(header) + (globalROI.nc * (ipy - globalROI.ymin) + (ipx - globalROI.xmin)) * 2;
else dataMap[iy][ix] = sizeof(header);
groupmap[iy][ix] = group - 1; 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 << "sizeofheader = " << sizeof(header) << std::endl;
std::cout << "Jungfrau strixels 2X single chip with full module data " std::cout << "Jungfrau strixels 2X single chip with full module data "
<< std::endl; << std::endl;
if (xmin < xmax && ymin < ymax) { if (xmin < xmax && ymin < ymax) {
dataSize = // get ROI raw image number of columns
(xmax - xmin + 1) * (ymax - ymin + 1) * 2 + sizeof(header); globalROI.nc = xmax - xmin + 1;
std::cout << "datasize " << dataSize << std::endl; std::cout << "nc_roi = " << globalROI.nc << std::endl;
remapROI(xmin, xmax, ymin, ymax);
dataSize =
(xmax - xmin + 1) * (ymax - ymin + 1) * 2 + sizeof(header);
std::cout << "datasize " << dataSize << std::endl;
//[ 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 { } else {

View File

@ -3,6 +3,7 @@
#ifndef JUNGFRAUMODULEDATA_H #ifndef JUNGFRAUMODULEDATA_H
#define JUNGFRAUMODULEDATA_H #define JUNGFRAUMODULEDATA_H
#include <cstdint> #include <cstdint>
#include "sls/sls_detector_defs.h"
#include "slsDetectorData.h" #include "slsDetectorData.h"
//#define VERSION_V2 //#define VERSION_V2
@ -27,7 +28,7 @@ typedef struct {
uint64_t bunchNumber; /**< is the frame number */ uint64_t bunchNumber; /**< is the frame number */
uint64_t pre; /**< something */ uint64_t pre; /**< something */
} jf_header; } jf_header; //Aldo's header!
using namespace std; using namespace std;
class jungfrauModuleData : public slsDetectorData<uint16_t> { 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 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 #ifndef ZMQ
#define off sizeof(jf_header) #define off sizeof(header)
#endif #endif
#ifdef ZMQ #ifdef ZMQ
#define off 0 #define off 0
#endif #endif
jungfrauModuleData() jungfrauModuleData(uint16_t xmin=0, uint16_t xmax=0,
uint16_t ymin=0, uint16_t ymax=0)
: slsDetectorData<uint16_t>(1024, 512, : slsDetectorData<uint16_t>(1024, 512,
1024* 512 * 2 + off) { 1024* 512 * 2 + off) {
for (int ix = 0; ix < 1024; ix++) { for (int ix = 0; ix != 1024; ++ix) {
for (int iy = 0; iy < 512; iy++) { 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; dataMap[iy][ix] = off + (1024 * iy + ix) * 2;
#ifdef HIGHZ #ifdef HIGHZ
dataMask[iy][ix] = 0x3fff; dataMask[iy][ix] = 0x3fff;
@ -63,7 +100,7 @@ class jungfrauModuleData : public slsDetectorData<uint16_t> {
} }
} }
}
iframe = 0; iframe = 0;
@ -150,7 +187,7 @@ class jungfrauModuleData : public slsDetectorData<uint16_t> {
//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()) {

View File

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

View File

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

View File

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

View File

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

View File

@ -3323,6 +3323,27 @@ void *start_timer(void *arg) {
break; 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 // sleep for exposure time
struct timespec begin, end; struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin); clock_gettime(CLOCK_REALTIME, &begin);

View File

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