From 1bd813d62070d99c31a5eef28ef50a638e1b61d8 Mon Sep 17 00:00:00 2001 From: vhinger182 Date: Fri, 17 Mar 2023 15:34:08 +0100 Subject: [PATCH] Fix bug to allow larger clusters --- slsDetectorCalibration/analogDetector.h | 3 ++ .../multiThreadedAnalogDetector.h | 5 +++ .../multiThreadedCountingDetector.h | 7 +++- slsDetectorCalibration/singlePhotonDetector.h | 4 +- slsDetectorCalibration/single_photon_hit.h | 40 ++++++++++++------- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h index 73c624a0e..6f6af9d09 100644 --- a/slsDetectorCalibration/analogDetector.h +++ b/slsDetectorCalibration/analogDetector.h @@ -1097,6 +1097,9 @@ template class analogDetector { return thr; }; + virtual int setClusterSize(int n = -1) { + }; + /** gets threshold value for conversion into number of photons \returns threshold value diff --git a/slsDetectorCalibration/multiThreadedAnalogDetector.h b/slsDetectorCalibration/multiThreadedAnalogDetector.h index 090be60b4..8ae978003 100644 --- a/slsDetectorCalibration/multiThreadedAnalogDetector.h +++ b/slsDetectorCalibration/multiThreadedAnalogDetector.h @@ -69,6 +69,11 @@ class threadedAnalogDetector { }; virtual double setThreshold(double th) { return det->setThreshold(th); }; + virtual double setClusterSize(int csx, int csy) { + //cout << "44" << endl; + return det->setClusterSize(csx); + }; + virtual void setROI(int xmin, int xmax, int ymin, int ymax) { det->setROI(xmin, xmax, ymin, ymax); }; diff --git a/slsDetectorCalibration/multiThreadedCountingDetector.h b/slsDetectorCalibration/multiThreadedCountingDetector.h index fb77866b1..2fde56f2d 100644 --- a/slsDetectorCalibration/multiThreadedCountingDetector.h +++ b/slsDetectorCalibration/multiThreadedCountingDetector.h @@ -19,7 +19,7 @@ using namespace std; class multiThreadedCountingDetector : public multiThreadedAnalogDetector { public: - multiThreadedCountingDetector(singlePhotonDetector *d, int n, int fs = 1000) + multiThreadedCountingDetector(singlePhotonDetector *d, int n, int fs = 1000) : multiThreadedAnalogDetector(d, n, fs){}; // virtual // ~multiThreadedCountingDetector{multiThreadedAnalogDetector::~multiThreadedAnalogDetector();}; @@ -33,6 +33,11 @@ class multiThreadedCountingDetector : public multiThreadedAnalogDetector { for (int i = 0; i < nThreads; i++) (dets[i])->setEnergyRange(emi, ema); }; + virtual void setClusterSize(int sizex, int sizey) { + for (int i = 0; i < nThreads; i++) + ((dets[i]))->setClusterSize(sizex, sizey); + //std::cout << "+++++++++++++ sizex " << sizex << std::endl; + }; }; #endif diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index d647cde16..202ad55b7 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -174,8 +174,9 @@ class singlePhotonDetector : public analogDetector { clusterSizeY = clusterSize; else clusterSizeY = 1; - for (int ip = 0; ip < nx * ny; ip++) + for (int ip = 0; ip < nx * ny; ip++) { (clusters + ip)->set_cluster_size(clusterSize, clusterSizeY); + } // cluster=new single_photon_hit(clusterSize,clusterSizeY); } return clusterSize; @@ -533,6 +534,7 @@ class singlePhotonDetector : public analogDetector { (clusters + nph)->print(); cout << max << " " << val[iy * nx + ix] << endl; } + //else (clusters + nph)->print(); good = 1; if (eMin > 0 && tot < eMin) good = 0; diff --git a/slsDetectorCalibration/single_photon_hit.h b/slsDetectorCalibration/single_photon_hit.h index 0317e6e4d..da2c24a1d 100644 --- a/slsDetectorCalibration/single_photon_hit.h +++ b/slsDetectorCalibration/single_photon_hit.h @@ -44,14 +44,12 @@ class single_photon_hit { // fwrite((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), // myFile); // if (fwrite((void*)this, 1, // sizeof(int)+2*sizeof(int16_t), myFile)) -#ifdef OLDFORMAT - if (fwrite((void *)&iframe, 1, sizeof(int), myFile)) { - }; -#endif #ifndef WRITE_QUAD // printf("no quad "); - if (fwrite((void *)&x, sizeof(int16_t), 2, myFile)) + if ( fwrite( (void*)&x, sizeof(int16_t), 1, myFile ) ) { + if ( fwrite( (void*)&y, sizeof(int16_t), 1, myFile ) ) return fwrite((void *)data, sizeof(int), dx * dy, myFile); + } #endif #ifdef WRITE_QUAD // printf("quad "); @@ -109,14 +107,27 @@ class single_photon_hit { // fread((void*)this, 1, 3*sizeof(int)+4*sizeof(double)+sizeof(quad), // myFile); -#ifdef OLDFORMAT - if (fread((void *)&iframe, 1, sizeof(int), myFile)) { - } -#endif #ifndef WRITE_QUAD - // printf( "no quad \n"); + //printf( "no quad \n"); + //This reads two values of size int16_t into x + //If x is located next to y (int16_t distance), this reads the values into x and y + //How can I be sure, this is always the case? + //If, e.g., the memory is padded after int16_t x, do we read the padding instead of y? + //How can I be sure the memory is packed and y follows right after x with no padding? + //Anyway, this is dangerous if anyone, at any point, changes the order of variable declaration, + //or uses another architecture (64 bit vs 32 bit for instance). + /* if (fread((void *)&x, sizeof(int16_t), 2, myFile)) return fread((void *)data, sizeof(int), dx * dy, myFile); + */ + + //Suggestion + if ( fread( (void*)&x, sizeof(int16_t), 1, myFile) ) { //reads x + if ( fread( (void*)&y, sizeof(int16_t), 1, myFile ) ) //reads y + return fread( (void*)data, sizeof(int), dx*dy, myFile ); //reads and returns data + } + + #endif #ifdef WRITE_QUAD int qq[4]; @@ -217,7 +228,7 @@ class single_photon_hit { // int ix, iy; printf("***************\n"); - printf("** %d %d **\n",x,y); + printf("** %d %d ** %d %d **\n", x, y, dx, dy); for (int iy = 0; iy < dy; iy++) { for (int ix = 0; ix < dx; ix++) { printf("%d \t", data[ix + iy * dx]); @@ -261,10 +272,11 @@ class single_photon_hit { x within the cluster (center is (0,0)) \param iy coordinate y within the cluster (center is (0,0)) \returns value of the cluster element */ - double get_data(int ix, int iy = 0) { - return data[(iy + dy / 2) * dx + ix + dx / 2]; + //Why not make these const? VH + double get_data(int ix, int iy = 0) const { + return data[(iy + dy / 2) * dx + ix + dx / 2]; //NOTE: those are int divisions }; - int *get_cluster() { return data; }; + int *get_cluster() const { return data; }; int iframe; /**< frame number */ double