diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h index 00d692cc0..9d3720b1b 100755 --- a/slsDetectorCalibration/MovingStat.h +++ b/slsDetectorCalibration/MovingStat.h @@ -27,7 +27,7 @@ class MovingStat } - /** sets number of samples parameter + /** sets number of samples parameter \param i number of samples parameter to be set */ diff --git a/slsDetectorCalibration/chiptestBoardData.h b/slsDetectorCalibration/chiptestBoardData.h index 86bdbcc35..0ef633c44 100644 --- a/slsDetectorCalibration/chiptestBoardData.h +++ b/slsDetectorCalibration/chiptestBoardData.h @@ -62,7 +62,7 @@ class chiptestBoardData : public slsDetectorData { if (filebin.is_open()) { if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) { setDataSize(afifo_length*nAdc*sizeof(uint16_t)); - afifo_cont=new uint16_t[afifo_length]; + afifo_cont=new uint16_t[afifo_length*nAdc]; if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) { iframe++; return (char*)afifo_cont; diff --git a/slsDetectorCalibration/commonModeSubtraction.h b/slsDetectorCalibration/commonModeSubtraction.h index 2de635a45..0484e6746 100644 --- a/slsDetectorCalibration/commonModeSubtraction.h +++ b/slsDetectorCalibration/commonModeSubtraction.h @@ -31,7 +31,7 @@ class commonModeSubtraction { cmPed[i]=0; }}; - /** adds the average of pedestals to the moving average and reienitialize the calculation of the sum of pedestals for all ROIs. - virtual func*/ + /** adds the average of pedestals to the moving average and reinitializes the calculation of the sum of pedestals for all ROIs. - virtual func*/ virtual void newFrame(){ for (int i=0; i0) cmStat[i].Calc(cmPed[i]/nCm[i]); diff --git a/slsDetectorCalibration/energyCalibration.cpp b/slsDetectorCalibration/energyCalibration.cpp index 1e5df8c0c..1872e20ef 100644 --- a/slsDetectorCalibration/energyCalibration.cpp +++ b/slsDetectorCalibration/energyCalibration.cpp @@ -235,7 +235,7 @@ energyCalibration::energyCalibration() : fspectrum(NULL), #endif funcs(NULL), - plot_flag(1), + plot_flag(1), // fit parameters output to screen cs_flag(1) { @@ -441,7 +441,7 @@ TF1* energyCalibration::fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t strcpy(fname, fun->GetName()); if (plot_flag) { - h1->Fit(fname,"R"); + h1->Fit(fname,"R0Q"); } else h1->Fit(fname,"R0Q"); @@ -526,4 +526,4 @@ TGraphErrors* energyCalibration::calibrate(int nscan, Double_t *en, Double_t *ee - +Fit data is empty diff --git a/slsDetectorCalibration/jungfrau02Data.h b/slsDetectorCalibration/jungfrau02Data.h index 2a43dad1f..e7b3d6b77 100644 --- a/slsDetectorCalibration/jungfrau02Data.h +++ b/slsDetectorCalibration/jungfrau02Data.h @@ -41,21 +41,24 @@ class jungfrau02Data : public chiptestBoardData { for (int iy=0; iy<48; iy++) { for (int ix=0; ix<48; ix++) { - dMap[iy][ix]=offset+(iy*48+ix)*nAdc; + dMap[ix][iy]=offset+(iy*48+ix)*nAdc;//dMap[iy][ix]=offset+(iy*48+ix)*nAdc; // cout << ix << " " << iy << " " << dMap[ix][iy] << endl; } } + cout << (0,0) << " " << dMap[0][0] << endl; + cout << (47,47) << " " << dMap[47][47] << endl; + + for (int ix=0; ix<48; ix++) { for (int iy=0; iy<48; iy++) - dMask[iy][ix]=0x0; - } + dMask[iy][ix]=0x0; setDataMap(dMap); setDataMask(dMask); + } - }; @@ -69,18 +72,18 @@ class jungfrau02Data : public chiptestBoardData { */ - virtual uint16_t getChannel(char *data, int ix, int iy=0) { + virtual uint16_t getChannel(char *data, int ix, int iy=0) { uint16_t m=0, d=0; - if (ix>=0 && ix=0 && iy=0 && dataMap[iy][ix]=0 && ix=0 && iy=0 && dataMap[iy][ix]8000) - d|=(1<<14); // set gain bit 0 - if (*((uint16_t*)(data)+dataMap[iy][ix]+2)>8000) - d|=(1<<15); // set gain bit 1 + //cout << "Gain bit!" << endl; + if (*((uint16_t*)(data)+dataMap[iy][ix]+2)>8000) //exchange if gainBits==2 is returned! + d|=(1<<14); // gain bit 1 + if (*((uint16_t*)(data)+dataMap[iy][ix]+1)>8000) //exchange if gainBits==2 is returned! + d|=(1<<15); // gain bit 0 } @@ -96,7 +99,7 @@ class jungfrau02Data : public chiptestBoardData { \returns channel value as double */ - double getValue(char *data, int ix, int iy=0) { + double getValue(char *data, int ix, int iy=0) { // cout << "##" << (void*)data << " " << ix << " " < the gain bits are read out the wrong way around (i.e. GB0 and GB1 have to be reversed!) + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns gain bits as int + */ + int getGainBits(char *data, int ix, int iy=0) { + uint16_t d=getChannel(data, ix, iy); + return ((d&0xc000)>>14); + }; + //*/ + + /** sets the output buffer crosstalk correction parameter diff --git a/slsDetectorCalibration/jungfrauReadData.C b/slsDetectorCalibration/jungfrauReadData.C index b59d75c44..f57787737 100644 --- a/slsDetectorCalibration/jungfrauReadData.C +++ b/slsDetectorCalibration/jungfrauReadData.C @@ -15,12 +15,12 @@ //#include #include #include "jungfrau02Data.h" -#include "moenchCommonMode.h" #include "jungfrau02CommonMode.h" #include "singlePhotonDetector.h" //#include "MovingStat.h" + using namespace std; #define NC 48 @@ -49,18 +49,37 @@ Loops over data file to find single photons, fills the tree (and writes it to fi \param xmax maximum x coordinate \param ymin minimum y coordinate \param ymax maximum y coordinate - \param cmsub enable commonmode subtraction -> Currently, CM subtraction is not implemented for Jungfrau! + \param cmsub enable commonmode subtraction \param hitfinder if 0: performs pedestal subtraction, not hit finding; if 1: performs both pedestal subtraction and hit finding + \param fcal -> calibration file, which contains 7 columns per pixel; 1) pixel #, 2) cal. offset G0, 3) cal. slope G0, 4) cal. offset G1, 5) cal. slope G1, 6) cal. offset G2, 7) cal. slope G2 \returns pointer to histo stack with cluster spectra */ -THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1) { +THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1){ + + // read in calibration file + ifstream calfile("/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); + if (calfile.is_open()==0){cout << "Unable to open calibration file!" << endl;} + int pix; + double of0,sl0,of1,sl1,of2,sl2; + double of_0[NC*NR], of_1[NC*NR], of_2[NC*NR], sl_0[NC*NR], sl_1[NC*NR], sl_2[NC*NR]; + while (calfile >> pix >> of0 >> sl0 >> of1 >> sl1 >> of2 >> sl2){ + of_0[pix]=of0; + sl_0[pix]=sl0; + of_1[pix]=of1; + sl_1[pix]=sl1; + of_2[pix]=of2; + sl_2[pix]=sl2; //if(pix==200) cout << "sl_2[200] " << sl_2[200] << endl; + } + calfile.close(); - jungfrau02Data *decoder=new jungfrau02Data(1,0,0); - jungfrau02CommonMode *cmSub=NULL;//moenchCommonMode *cmSub=NULL; // -// if (cmsub) -// cmSub=new moenchCommonMode(); + double adc_value, num_photon; + + jungfrau02Data *decoder=new jungfrau02Data(1,0,0);//(3,0,0); // (adc,offset,crosstalk) //(1,0,0) //(3,0,0) for readout of GB + jungfrau02CommonMode *cmSub=NULL; + if (cmsub) + cmSub=new jungfrau02CommonMode(); int nph=0; int iev=0; @@ -85,9 +104,11 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int THStack *hs=new THStack("hs",fformat); - TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); hs->Add(h1); + + + if (hitfinder) { h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); @@ -101,7 +122,6 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int } - ifstream filebin; @@ -143,7 +163,7 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int filter->newDataSet(); - for (int irun=runmin; irun<=runmax; irun++){ //{for (int irun=runmin; irungetEventType(buff, ix, iy, cmsub); + int gainBits=decoder->getGainBits(buff,ix,iy); // get gain bits #ifdef MY_DEBUG if (hitfinder) { if (iev%1000==0) - he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); - + //he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); // show single photon hits // original + //he->SetBinContent(ix+1-xmin, iy+1-ymin, cmSub->getCommonMode(ix,iy)); //show common mode! + he->SetBinContent(iy+1-ymin, ix+1-xmin, (int)gainBits); //show gain bits + //he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)gainBits); // rows and columns reversed!!! } #endif - if (nf>1000) { + if (nf>1000) { // only start filing data after 1000 frames // h1->Fill(decoder->getValue(buff,ix,iy), iy+NR*ix); h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + + + if (hitfinder) { if (thisEvent==PHOTON_MAX ) { diff --git a/slsDetectorCalibration/pedestalSubtraction.h b/slsDetectorCalibration/pedestalSubtraction.h index 29bc98628..ee3aff8aa 100644 --- a/slsDetectorCalibration/pedestalSubtraction.h +++ b/slsDetectorCalibration/pedestalSubtraction.h @@ -21,7 +21,7 @@ class pedestalSubtraction { /** adds the element to the moving average \param val value to be added */ - virtual void addToPedestal(double val){ stat.Calc(val);}; + virtual void addToPedestal(double val){stat.Calc(val);}; /** returns the average value of the pedestal \returns mean of the moving average diff --git a/slsDetectorCalibration/readJungfrauData.C b/slsDetectorCalibration/readJungfrauData.C index c472d2d75..8ad92381a 100644 --- a/slsDetectorCalibration/readJungfrauData.C +++ b/slsDetectorCalibration/readJungfrauData.C @@ -1,13 +1,19 @@ { // script to run Jungfrau data analysis - gROOT->ProcessLine(".L jungfrauReadData.C+"); + gROOT->ProcessLine(".L jungfrauReadData.C++");//"); TFile *fout; // output file THStack *hs2N; // collection of objects - fout=new TFile("/mnt/slitnas/datadir_jungfrau02/20140131_analysis/test/outfile.root","RECREATE"); // careful "RECREATE" will OVERWRITE! + fout=new TFile("/mnt/slitnas/datadir_jungfrau02/jungfrau_Trieste_2014/TriesteBeam2014/Analysis/D4_M1_HG_2000clk_CD986_CMsub.root","RECREATE"); // + + //hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140131_BeamSLS/datadir_310114/21keV_10us_HIGHG0_CDS550_%d.bin","tit",0,75,1500,-500,2500,1,0.,1,47,1,47,1,1); //1,1); + + //hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140228_GainBits/GSdata_laser_%d.bin","tit",0,5,1500,-500,2500,1,0.,1,47,1,47,0,1);//,"/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); //1,1); // data set test GB -> set (3,0,0) in junfrauReadData.C + + hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/jungfrau_Trieste_2014/Trieste_20140314/HG_20keV_CDS986_2000clk_%d.bin","tit",0,201,3000,-499.5,2500.5,1,0.,1,47,1,47,1,1); +//,"/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); //1,1); // data set test GB -> set (3,0,0) in junfrauReadData.C - hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140131_BeamSLS/datadir_310114/18keV_10us_HIGHG0_CDS550_%d.bin","tit",0,10,1500,-500,2500,1,0.,1,47,1,47,1,1); //0,1); //hs2N->SetName("cds_g4"); //hs2N->SetTitle("cds_g4"); @@ -16,11 +22,10 @@ (TH2F*)(hs2N->GetHists()->At(2))->Write(); (TH2F*)(hs2N->GetHists()->At(3))->Write(); (TH2F*)(hs2N->GetHists()->At(4))->Write(); + //(TH2F*)(hs2N->GetHists()->At(5))->Write(); + //(TH2F*)(hs2N->GetHists()->At(6))->Write(); - - fout->Close(); - - + //fout->Close(); // uncomment } diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index c4616a624..809b23de3 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -44,6 +44,8 @@ class slsDetectorData { dataROIMask=new int*[ny]; for(int i = 0; i < ny; i++) { dataROIMask[i] = new int[nx]; + for (int j=0; j