diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h index 801c5a64a..634560000 100755 --- a/slsDetectorCalibration/MovingStat.h +++ b/slsDetectorCalibration/MovingStat.h @@ -1,7 +1,7 @@ class MovingStat { public: - MovingStat() : m_n(0), n(0) {} + MovingStat() : m_n(0), n(1000) {} void Clear() { diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index 7dd718f8f..d7757972b 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -126,31 +126,42 @@ class moench02ModuleData : public slsDetectorData { for (ix=xmin-1; ix0) cmStat[isc].Calc(cmPed[isc]/nCm[isc]); - } + // cout << "SC " << isc << nCm[isc] << " " << cmPed[isc]/nCm[isc] << " " << cmStat[isc].Mean() << endl; + + } + }; double getCommonMode(int ix, int iy) { int isc=ix/40; - if (nCm[isc]>0) + if (nCm[isc]>0) { + /* if (ix==20 && iy==20) */ +/* cout << cmPed[isc] << " " << nCm[isc] << " " << cmStat[isc].Mean() << " " << cmPed[isc]/nCm[isc]-cmStat[isc].Mean() << endl; */ return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); - else + } else { + /* if (ix==20 && iy==20) */ +/* cout << "No common mode!" << endl; */ + return 0; + } }; @@ -221,7 +232,7 @@ class moench02ModuleData : public slsDetectorData { char *getBuff(){return buff;} char *getOldBuff(){return oldbuff;} - int setPedestalSubstraction(int i=-1){if (i==0) pedSub=0; if (i==1) pedSub=1; return pedSub;}; + int setPedestalSubstraction(int i=-1){if (i>=0) pedSub=i; return pedSub;}; double getChannelShort(int ix, int iy, double hc=0, double tc=0) { @@ -240,7 +251,7 @@ class moench02ModuleData : public slsDetectorData { - eventType getEventType(int ix, int iy, double hcorr=0, double tcorr=0, int sign=1) { + eventType getEventType(int ix, int iy, double hcorr=0, double tcorr=0, int sign=1, int cm=0) { /* PEDESTAL, */ /* NEIGHBOUR, */ @@ -256,9 +267,11 @@ class moench02ModuleData : public slsDetectorData { for (int ir=-1; ir<2; ir++) { for (int ic=-1; ic<2; ic ++) { if ((iy+ir)>=0 && (iy+ir)<160 && (ix+ic)>=0 && (ix+ic)<160) { - v=getChannelShort(ix+ic, iy+ir, hcorr, tcorr); + v=sign*getChannelShort(ix+ic, iy+ir, hcorr, tcorr); if (pedSub) - v=sign*(v-getPedestal(ix+ic,iy+ir)); + v-=sign*getPedestal(ix+ic,iy+ir); + if (cm) + v-=sign*getCommonMode(ix+ic, iy+ic); cluster[ic+1][ir+1]=v; tot+=v; if (v>max) { @@ -290,10 +303,7 @@ class moench02ModuleData : public slsDetectorData { }; - double getClusterElement(int ic, int ir, int cm=0){ - if (cm) cluster[ic+1][ir+1]-getCommonMode(cx,cy); - else return cluster[ic+1][ir+1]; - }; + double getClusterElement(int ic, int ir, int cmsub=0){return cluster[ic+1][ir+1];}; double *getCluster(){return &cluster[0][0];}; diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index c2ebd2efe..2095e380e 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -10,9 +10,9 @@ #include #include #include -#include -#include -#include +//#include +//#include +//#include #include #include "moench02ModuleData.h" @@ -23,7 +23,14 @@ using namespace std; #define NC 160 #define NR 160 + +#define MY_DEBUG 1 +#ifdef MY_DEBUG +#include +#endif + /** + char *fformat, file name format char *tit, title of the tree etc. int runmin, minimum run number @@ -67,6 +74,9 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb THStack *hs=new THStack("hs",fformat); + + int iev=0; + TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); hs->Add(h1); @@ -106,6 +116,14 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb // 6% x-talk from previous pixel // 12% x-talk from previous frame +#ifdef MY_DEBUG + TCanvas *myC=new TCanvas(); + TH2F *he=new TH2F("he","Event",3,-1.5,1.5,3,-1.5,1.5); + he->SetStats(kFALSE); + he->Draw("colz"); + he->SetMinimum(0); + he->SetMaximum(0.5*hmax); +#endif for (int irun=runmin; irun100) { if (cmsub) { for (int isc=scmin; isccalculateCommonMode(3+isc*40, 40*(isc-1)-3, 3, NR-3, hc, tc); + decoder->calculateCommonMode(3+isc*40, 40*(isc+1)-3, 3, NR-3, hc, tc); +#ifdef MY_DEBUG + if (nf%1000==0) cout << "sc=" << isc << " CM="<< decoder->getCommonMode(3+isc*40, NR/2)<< endl; +#endif } } + } @@ -134,7 +156,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb if (nf>100) { - thisEvent= decoder->getEventType(ix, iy, hc, tc, 1); + thisEvent= decoder->getEventType(ix, iy, hc, tc, 1,1); } @@ -142,10 +164,11 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb if (thisEvent==moench02ModuleData::PEDESTAL) { if (cmsub && nf>1000) - decoder->addToPedestal( decoder->getChannelShort(ix, iy, hc, tc)- decoder->getCommonMode(ix,iy), ix, iy); + decoder->addToPedestal(decoder->getChannelShort(ix, iy, hc, tc)-decoder->getCommonMode(ix,iy), ix, iy); else decoder->addToPedestal( decoder->getChannelShort(ix, iy, hc, tc), ix, iy); + } @@ -159,15 +182,30 @@ Add here the function that you want to call: fill histos, make trees etc. tr=0; bl=0; br=0; - h1->Fill(decoder->getClusterElement(0,0, cmsub), iy+NR*ix); + h1->Fill(decoder->getClusterElement(0,0), iy+NR*ix); + + // if (nf%1000==0 && ix==20 && iy==20) cout << " val="<< decoder->getClusterElement(0,0)<< endl; if (thisEvent==moench02ModuleData::PHOTON_MAX ) { - - + #ifdef MY_DEBUG + if (iev%100000==0) { + cout << "Event " << iev << " Frame "<< nf << endl; + } +#endif + + for (ir=-1; ir<2; ir++) { for (ic=-1; ic<2; ic++) { v=decoder->getClusterElement(ic,ir,cmsub); data[ic+1][ir+1]=v; +#ifdef MY_DEBUG + if (iev%100000==0) { + he->SetBinContent(ic+2,ir+2,v); + cout << "Histo("<< ix+ic << ","<< iy+ir <<")" << v << endl; + } +#endif + + tot+=v; if (ir<1) { @@ -237,7 +275,16 @@ Add here the function that you want to call: fill histos, make trees etc. y=iy; tall->Fill(); - + +#ifdef MY_DEBUG + if (iev%100000==0) { + myC->Modified(); + myC->Update(); + } +#endif + + iev++; + } diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 1c3d62a42..a8ffb8513 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -19,9 +19,7 @@ class slsDetectorData { */ - slsDetectorData(int npx, int npy=1, int ds=-1, int **dMap=NULL, int **dMask=NULL) { - nx=npx; - ny=npy; + slsDetectorData(int npx, int npy=1, int ds=-1, int **dMap=NULL, int **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy) { if (ds<=0) dataSize=nx*ny; @@ -37,8 +35,14 @@ class slsDetectorData { dataMap[i] = new int[nx]; } + dataROIMask=new int*[ny]; + for(int i = 0; i < ny; i++) { + dataROIMask[i] = new int[nx]; + } + setDataMap(dMap); setDataMask(dMask); + setDataROIMask(dROI); }; @@ -46,9 +50,11 @@ class slsDetectorData { for(int i = 0; i < ny; i++) { delete [] dataMap[i]; delete [] dataMask[i]; + delete [] dataROIMask[i]; } delete [] dataMap; delete [] dataMask; + delete [] dataROIMask; } void setDataMap(int **dMap=NULL) { @@ -76,8 +82,27 @@ class slsDetectorData { } }; + void setDataROIMask(int **dROI=NULL){ + if (dROI!=NULL) { + for (int iy=0; iy