diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h index 6f6af9d09..87e2550ed 100644 --- a/slsDetectorCalibration/analogDetector.h +++ b/slsDetectorCalibration/analogDetector.h @@ -866,7 +866,7 @@ template class analogDetector { for (ix = xmin; ix < xmax; ++ix) { if (det->isGood(ix, iy)) { // addToPedestal(data,ix,iy,1); - addToPedestal(data, ix, iy, cm); + addToPedestal(data, ix, iy, 0); /* if (ix==50 && iy==50) */ /* cout<< "*ped* " << id << " " << ix << " " << iy << " " * << det->getChannel(data,ix,iy) << " " << @@ -1097,8 +1097,7 @@ template class analogDetector { return thr; }; - virtual int setClusterSize(int n = -1) { - }; + virtual int setClusterSize(int n = -1) { return 0; }; /** gets threshold value for conversion into number of photons diff --git a/slsDetectorCalibration/commonModeSubtractionNew.h b/slsDetectorCalibration/commonModeSubtractionNew.h index facfe0a35..eb7ea7ad9 100644 --- a/slsDetectorCalibration/commonModeSubtractionNew.h +++ b/slsDetectorCalibration/commonModeSubtractionNew.h @@ -100,7 +100,10 @@ class commonModeSubtraction { if (iroi >= 0 && iroi < nROI) { if (nCm[iroi] > 0) return mean[iroi] / nCm[iroi]; - } + else + std::cout << ix << " " << iy << " no data in cm " << iroi << std::endl; + } else + std::cout << ix << " " << iy << " bad roi " << iroi << std::endl; return 0; }; @@ -117,6 +120,8 @@ class commonModeSubtraction { return sqrt(mean2[iroi] / nCm[iroi] - (mean[iroi] / nCm[iroi]) * (mean[iroi] / nCm[iroi])); + else + std::cout << ix << " " << iy << " no data in cm " << iroi << std::endl; } return 0; }; diff --git a/slsDetectorCalibration/interpolations/slsInterpolation.h b/slsDetectorCalibration/interpolations/slsInterpolation.h index 39bd7c29d..17f36cadd 100644 --- a/slsDetectorCalibration/interpolations/slsInterpolation.h +++ b/slsDetectorCalibration/interpolations/slsInterpolation.h @@ -27,6 +27,8 @@ enum quadrant { //#ifdef MYROOT1 //: public TObject //#endif +using namespace std; + class slsInterpolation { public: diff --git a/slsDetectorCalibration/jungfrauCommonMode.h b/slsDetectorCalibration/jungfrauCommonMode.h index 791aede95..877367850 100644 --- a/slsDetectorCalibration/jungfrauCommonMode.h +++ b/slsDetectorCalibration/jungfrauCommonMode.h @@ -30,4 +30,29 @@ class commonModeSubtractionSuperColumnJF : public commonModeSubtraction { }; +class commonModeSubtractionChip : public commonModeSubtraction { + public: + commonModeSubtractionChip() + : commonModeSubtraction(8){}; + virtual int getROI(int ix, int iy) { int top=iy/256; int sc=ix/256; return sc+top*4; }; +/* + virtual void addToCommonMode(double val, int ix = 0, int iy = 0) { + int iroi = getROI(ix, iy); + // cout << iy << " " << ix << " " << iroi ; + if (iroi >= 0 && iroi < nROI) { + mean[iroi] += val; + mean2[iroi] += val * val; + nCm[iroi]++; + if (nCm[iroi] > 64*256) + std::cout << "Too many pixels added " << nCm[iroi] << std::endl; + + } + }; +*/ + virtual commonModeSubtractionChip *Clone() { + return new commonModeSubtractionChip(); + }; +}; + + #endif diff --git a/slsDetectorCalibration/jungfrauExecutables/jungfrauRawDataProcess.cpp b/slsDetectorCalibration/jungfrauExecutables/jungfrauRawDataProcess.cpp index 6e9b65ec0..006d77104 100644 --- a/slsDetectorCalibration/jungfrauExecutables/jungfrauRawDataProcess.cpp +++ b/slsDetectorCalibration/jungfrauExecutables/jungfrauRawDataProcess.cpp @@ -4,9 +4,9 @@ #include //enable common mode subtraction -//#define CMS +#define CMS //disable common mode subtraction -#undef CMS +//#undef CMS #undef CORR #define C_GHOST 0.0004 @@ -40,7 +40,8 @@ #include #include #include -//#include "jungfrauCommonMode.h" +//#include "commonModeSubtractionNew.h" +#include "jungfrauCommonMode.h" #include using namespace std; @@ -63,7 +64,7 @@ int main(int argc, char *argv[]) { } int fifosize = 1000; - int nthreads = 10; + int nthreads = 1; int csize = 3; //3 int nsigma = 5; int nped = 10000; @@ -73,10 +74,12 @@ int main(int argc, char *argv[]) { #if !defined JFSTRX && !defined JFSTRXOLD && !defined JFSTRXCHIP1 && !defined JFSTRXCHIP6 #ifndef MODULE + cout << "This is a JF single chip!" <readNextFrame(filebin, ff, np, buff)) { // if (np == 40) { - if ((ifr+1) % 100 == 0) { - cout << " ****" << decoder->getValue(buff,20,20);// << endl; - } + // if ((ifr+1) % 100 == 0) { + // cout << " ****" << decoder->getValue(buff,20,20);// << endl; + // } mt->pushData(buff); + + + // while (mt->isBusy()) + // ; + //if ((ifr+1) % 100 == 0) + + // double pix=0,ped=0,sub=0,cmp=0, sub0=0; + + // for (int ix=-1; ix<2; ix++) { + // for (int iy=-1; iy<2; iy++) { + // pix+=decoder->getValue(buff, ipixX+ix, ipixY+iy); + // sub+=filter->subtractPedestal(buff, ipixX+ix, ipixY+iy, 1); + // sub0+=filter->subtractPedestal(buff, ipixX+ix, ipixY+iy, 0); + // ped+=filter->getPedestal(ipixX+ix, ipixY+iy); + // cmp+=filter->getCommonMode(ipixX+ix, ipixY+iy); + // } + // } + + // cout << pix << " " << sub << " " sub0 << " " << ped << " " << cmp << endl; + + mt->nextThread(); mt->popFree(buff); ifr++; - if (ifr % 100 == 0) { - cout << " ****" << ifr << " " << ff << " " << np << endl; - } //else + // if (ifr % 100 == 0) { + // cout << " ****" << ifr << " " << ff << " " << np << endl; + // } + + //else //cout << ifr << " " << ff << " " << np << endl; - if (ifr>=1000) - break; + // if (ifr>=1000) + // break; + ff = -1; } filebin.close(); @@ -370,7 +398,25 @@ int main(int argc, char *argv[]) { if ((ifr+1) % 100 == 0) { cout << " ****" << decoder->getValue(buff,20,20);// << endl; } - mt->pushData(buff); + mt->pushData(buff); + + + // while (mt->isBusy()) + + // double pix=0,ped=0,sub=0,cmp=0, sub0=0; + + // for (int ix=-1; ix<2; ix++) { + // for (int iy=-1; iy<2; iy++) { + // pix+=decoder->getValue(buff, ipixX+ix, ipixY+iy); + // sub+=filter->subtractPedestal(buff, ipixX+ix, ipixY+iy, 1); + // sub0+=filter->subtractPedestal(buff, ipixX+ix, ipixY+iy, 0); + // ped+=filter->getPedestal(ipixX+ix, ipixY+iy); + // cmp+=filter->getCommonMode(ipixX+ix, ipixY+iy); + // } + // } + + // cout << pix << " " << sub << " " sub0 << " " << ped << " " << cmp << endl; + // // //pop mt->nextThread(); mt->popFree(buff); diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 202ad55b7..602455d5f 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -396,14 +396,14 @@ class singlePhotonDetector : public analogDetector { return 0; } newFrame(data); - + /* if (cmSub) { addToCommonMode(data); cm = 1; } - + */ double *val = new double[ny * nx]; - + cm=0; for (iy = ymin; iy < ymax; ++iy) { for (ix = xmin; ix < xmax; ++ix) { if (det->isGood(ix, iy) == 0) @@ -547,12 +547,50 @@ class singlePhotonDetector : public analogDetector { } else if (ee == PEDESTAL) { addToPedestal(data, ix, iy, cm); + if (cmSub) { + addToCommonMode(data, ix, iy); + } } /*else { eventMask[iy][ix]=PHOTON; }*/ // eventMask[iy][ix]=ee; } } + + if (cmSub) { + + double cmv=0; + for (int iph=0; iphx ; + iy=(clusters + nph)->y; + + for (ir = -(clusterSizeY / 2); ir < (clusterSizeY / 2) + 1; + ir++) { + for (ic = -(clusterSize / 2); + ic < (clusterSize / 2) + 1; ic++) { + if ((iy + ir) >= 0 && (iy + ir) < ny && + (ix + ic) >= 0 && (ix + ic) < nx) { + + cmv=getCommonMode(ix+ic, iy+ir); + //if (ir==0 && ic==0) + //cout << cmv << endl; + (clusters + iph) + ->set_data((clusters + iph) + ->get_data(ic,ir)-cmv, ic,ir); + } + + } + + } + + } + + + } + + + + nphFrame = nph; nphTot += nph;