From 7ca31b2a62cc592504c66a2c004b252620117354 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 19 Sep 2013 14:30:30 +0000 Subject: [PATCH 001/104] Classes, Libraries and Functions for Characterization and Calibration of SLS Detectors. First import. git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@1 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/MovingStat.h | 88 ++++ slsDetectorCalibration/RunningStat.h | 55 +++ slsDetectorCalibration/energyCalibration.cpp | 457 ++++++++++++++++++ slsDetectorCalibration/energyCalibration.h | 412 ++++++++++++++++ .../energyCalibration_cpp.d | 6 + 5 files changed, 1018 insertions(+) create mode 100755 slsDetectorCalibration/MovingStat.h create mode 100755 slsDetectorCalibration/RunningStat.h create mode 100644 slsDetectorCalibration/energyCalibration.cpp create mode 100644 slsDetectorCalibration/energyCalibration.h create mode 100644 slsDetectorCalibration/energyCalibration_cpp.d diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h new file mode 100755 index 0000000000..7acba5706f --- /dev/null +++ b/slsDetectorCalibration/MovingStat.h @@ -0,0 +1,88 @@ + class MovingStat + { + public: + MovingStat() : m_n(0), n(0) {} + + void Clear() + { + m_n = 0; + } + + void SetN(int i) {n=i;}; + int GetN() {return n;}; + void Calc(double x) { + if (m_n 0) ? m_newM/m_n : 0.0; + } + double M2() const + { + return ( (m_n > 1) ? m_newM2/m_n : 0.0 ); + } + + double Variance() const + { + return ( (m_n > 1) ? (M2()-Mean()*Mean()) : 0.0 ); + } + + double StandardDeviation() const + { + return ( (Variance() > 0) ? sqrt( Variance() ) : -1 ); + } + + private: + int n; + int m_n; + double m_oldM, m_newM, m_oldM2, m_newM2; + }; diff --git a/slsDetectorCalibration/RunningStat.h b/slsDetectorCalibration/RunningStat.h new file mode 100755 index 0000000000..1197ffc0fa --- /dev/null +++ b/slsDetectorCalibration/RunningStat.h @@ -0,0 +1,55 @@ + class RunningStat + { + public: + RunningStat() : m_n(0) {} + + void Clear() + { + m_n = 0; + } + + void Push(double x) + { + m_n++; + + // See Knuth TAOCP vol 2, 3rd edition, page 232 + if (m_n == 1) + { + m_oldM = m_newM = x; + m_oldS = 0.0; + } + else + { + m_newM = m_oldM + (x - m_oldM)/m_n; + m_newS = m_oldS + (x - m_oldM)*(x - m_newM); + + // set up for next iteration + m_oldM = m_newM; + m_oldS = m_newS; + } + } + + int NumDataValues() const + { + return m_n; + } + + double Mean() const + { + return (m_n > 0) ? m_newM : 0.0; + } + + double Variance() const + { + return ( (m_n > 1) ? m_newS/(m_n - 1) : 0.0 ); + } + + double StandardDeviation() const + { + return sqrt( Variance() ); + } + + private: + int m_n; + double m_oldM, m_newM, m_oldS, m_newS; + }; diff --git a/slsDetectorCalibration/energyCalibration.cpp b/slsDetectorCalibration/energyCalibration.cpp new file mode 100644 index 0000000000..6264182cff --- /dev/null +++ b/slsDetectorCalibration/energyCalibration.cpp @@ -0,0 +1,457 @@ +#include "energyCalibration.h" + +#ifdef __CINT +#define MYROOT +#endif + + +#ifdef MYROOT +#include +#include +#include +#include +#endif + +#include + +#define max(a,b) ((a) > (b) ? (a) : (b)) +#define min(a,b) ((a) < (b) ? (a) : (b)) +#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; } + + +using namespace std; + +#ifdef MYROOT +Double_t energyCalibrationFunctions::gaussChargeSharing(Double_t *x, Double_t *par) { + Double_t f, arg=0; + if (par[3]!=0) arg=(x[0]-par[2])/par[3]; + f=par[4]*TMath::Exp(-1*arg*arg/2.); + f=f+par[5]*(par[4]/2*(TMath::Erfc(sign*arg/(TMath::Sqrt(2.)))))+par[0]-par[1]*sign*x[0]; + return f; +} + +// basic erf function +Double_t energyCalibrationFunctions::erfFunction(Double_t *x, Double_t *par) { + double arg=0; + if (par[1]!=0) arg=(par[0]-x[0])/par[1]; + return ((par[2]/2.*(1+TMath::Erf(sign*arg/(TMath::Sqrt(2)))))); +}; + + +Double_t energyCalibrationFunctions::erfFunctionChargeSharing(Double_t *x, Double_t *par) { + Double_t f; + + f=erfFunction(x, par+2)*(1+par[5]*(par[2]-x[0]))+par[0]-par[1]*x[0]*sign; + return f; +}; + + +Double_t energyCalibrationFunctions::erfFuncFluo(Double_t *x, Double_t *par) { + Double_t f; + f=erfFunctionChargeSharing(x, par)+erfFunction(x, par+6)*(1+par[9]*(par[6]-x[0])); + return f; +}; +#endif + +double energyCalibrationFunctions::median(double *x, int n){ + // sorts x into xmed array and returns median + // n is number of values already in the xmed array + double xmed[n]; + int k,i,j; + + for (i=0; i*(x+j)) + k++; + if (*(x+i)==*(x+j)) { + if (i>j) + k++; + } + } + xmed[k]=*(x+i); + } + k=n/2; + return xmed[k]; +} + + +int energyCalibrationFunctions::quick_select(int arr[], int n){ + int low, high ; + int median; + int middle, ll, hh; + + low = 0 ; high = n-1 ; median = (low + high) / 2; + for (;;) { + if (high <= low) /* One element only */ + return arr[median] ; + + if (high == low + 1) { /* Two elements only */ + if (arr[low] > arr[high]) + ELEM_SWAP(arr[low], arr[high]) ; + return arr[median] ; + } + + /* Find median of low, middle and high items; swap into position low */ + middle = (low + high) / 2; + if (arr[middle] > arr[high]) ELEM_SWAP(arr[middle], arr[high]) ; + if (arr[low] > arr[high]) ELEM_SWAP(arr[low], arr[high]) ; + if (arr[middle] > arr[low]) ELEM_SWAP(arr[middle], arr[low]) ; + + /* Swap low item (now in position middle) into position (low+1) */ + ELEM_SWAP(arr[middle], arr[low+1]) ; + + /* Nibble from each end towards middle, swapping items when stuck */ + ll = low + 1; + hh = high; + for (;;) { + do ll++; while (arr[low] > arr[ll]) ; + do hh--; while (arr[hh] > arr[low]) ; + + if (hh < ll) + break; + + ELEM_SWAP(arr[ll], arr[hh]) ; + } + + /* Swap middle item (in position low) back into correct position */ + ELEM_SWAP(arr[low], arr[hh]) ; + + /* Re-set active partition */ + if (hh <= median) + low = ll; + if (hh >= median) + high = hh - 1; + } +} + +int energyCalibrationFunctions::kth_smallest(int *a, int n, int k){ + register int i,j,l,m ; + register double x ; + + l=0 ; m=n-1 ; + while (lSetParNames("Background Offset","Background Slope","Inflection Point","Noise RMS", "Number of Photons","Charge Sharing Slope"); + + fspectrum=new TF1("fspectrum",funcs,&energyCalibrationFunctions::spectrum,0,1000,6,"energyCalibrationFunctions","spectrum"); + fspectrum->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal"); + +#endif + + +} + + + +void energyCalibration::fixParameter(int ip, Double_t val){ + + fscurve->FixParameter(ip, val); + fspectrum->FixParameter(ip, val); +} + + +void energyCalibration::releaseParameter(int ip){ + + fscurve->ReleaseParameter(ip); + fspectrum->ReleaseParameter(ip); +} + + + + + + + +energyCalibration::~energyCalibration(){ +#ifdef MYROOT + delete fscurve; + delete fspectrum; +#endif + +} + +#ifdef MYROOT + + + +TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch) { + + if (h2==NULL || nch==0) + return NULL; + + double *x=new double[nch]; + TH1F *h1=NULL; + + double val=-1; + + h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax()); + + + for (int ib=0; ibGetXaxis()->GetNbins(); ib++) { + for (int ich=0; ichGetBinContent(ch0+ich+1,ib+1); + } + val=energyCalibrationFunctions::median(x, nch); + h1->SetBinContent(ib+1,val); + } + return h1; + + + +} + + + + + + + + + + + + + + +void energyCalibration::setStartParameters(Double_t *par){ + bg_offset=par[0]; + bg_slope=par[1]; + flex=par[2]; + noise=par[3]; + ampl=par[4]; + cs_slope=par[5]; +} + + +void energyCalibration::getStartParameters(Double_t *par){ + par[0]=bg_offset; + par[1]=bg_slope; + par[2]=flex; + par[3]=noise; + par[4]=ampl; + par[5]=cs_slope; +} + +#endif +int energyCalibration::setChargeSharing(int p) { + if (p>=0) { + cs_flag=p; +#ifdef MYROOT + if (p) { + fscurve->ReleaseParameter(5); + fspectrum->ReleaseParameter(1); + } else { + fscurve->FixParameter(5,0); + fspectrum->FixParameter(1,0); + } +#endif + } + + return cs_flag; +} + + +#ifdef MYROOT +void energyCalibration::initFitFunction(TF1 *fun, TH1 *h1) { + + Double_t min=fit_min, max=fit_max; + + Double_t mypar[6]; + + if (max==-1) + max=h1->GetXaxis()->GetXmax(); + + if (min==-1) + min=h1->GetXaxis()->GetXmin(); + + + if (bg_offset==-1) + mypar[0]=0; + else + mypar[0]=bg_offset; + + + if (bg_slope==-1) + mypar[1]=0; + else + mypar[1]=bg_slope; + + + if (flex==-1) + mypar[2]=(min+max)/2.; + else + mypar[2]=flex; + + + if (noise==-1) + mypar[3]=0.1; + else + mypar[3]=noise; + + if (ampl==-1) + mypar[4]=h1->GetBinContent(h1->GetXaxis()->FindBin(0.5*(max+min))); + else + mypar[4]=ampl; + + if (cs_slope==-1) + mypar[5]=0; + else + mypar[5]=cs_slope; + + fun->SetParameters(mypar); + + fun->SetRange(min,max); + +} + + +TF1* energyCalibration::fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar) { + + + TF1* fitfun; + + char fname[100]; + + strcpy(fname, fun->GetName()); + + if (plot_flag) { + h1->Fit(fname,"R"); + } else + h1->Fit(fname,"R0Q"); + + + fitfun= h1->GetFunction(fname); + fitfun->GetParameters(mypar); + for (int ip=0; ip<6; ip++) { + emypar[ip]=fitfun->GetParError(ip); + } + return fitfun; +} + +TF1* energyCalibration::fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar) { + initFitFunction(fscurve,h1); + return fitFunction(fscurve, h1, mypar, emypar); +} + + + + + +TF1* energyCalibration::fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar) { + initFitFunction(fspectrum,h1); + return fitFunction(fspectrum, h1, mypar, emypar); +} + + + +TGraphErrors* energyCalibration::linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff) { + + TGraphErrors *gr; + + Double_t mypar[2]; + + gr = new TGraphErrors(nscan,en,fl,een,efl); + + if (plot_flag) { + gr->Fit("pol1"); + gr->SetMarkerStyle(20); + } else + gr->Fit("pol1","0Q"); + + TF1 *fitfun= gr->GetFunction("pol1"); + fitfun->GetParameters(mypar); + + egain=fitfun->GetParError(1); + eoff=fitfun->GetParError(0); + + gain=funcs->setScanSign()*mypar[1]; + off=mypar[0]; + + return gr; +} + + +TGraphErrors* energyCalibration::calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral) { + + TH1F *h; + + Double_t mypar[6], emypar[6]; + Double_t fl[nscan], efl[nscan]; + + + for (int ien=0; ien +#include +class TH1F; +class TH2F; +class TGraphErrors; +#endif + + +using namespace std; + + + + +const double conven=1000./3.6; /**< electrons/keV */ +const double el=1.67E-4; /**< electron charge in fC */ + + + +/** + \mainpage Common Root library for SLS detectors data analysis + * + * \section intro_sec Introduction + We know very well s-curves etc. but at the end everybody uses different functions ;-). + + * \subsection mot_sec Motivation + It would be greate to use everybody the same functions... + +*/ + + +/** + * + * +@libdoc The energiCalibration class contains all the necessary functions for s-curve fitting and linear calibration of the threshold. + * + * @short Energy calibration functions + * @author Anna Bergamaschi + * @version 0.1alpha + + + */ + +/** + class containing all the possible energy calibration functions (scurves with and without charge sharing, gaussian spectrum with and without charge sharing, possibility of chosing the sign of the X-axis) + +*/ +class energyCalibrationFunctions { + + public: + + energyCalibrationFunctions(int s=-1) {setScanSign(s);}; + + /** sets scan sign + \param s can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) otherwise gets + \returns current scan sign can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) + */ + int setScanSign(int s=0) {if (s==1 || s==-1) sign=s; return sign;};; + + +#ifdef MYROOT + /** + Gaussian Function with charge sharing pedestal + par[0] is the absolute height of the background pedestal + par[1] is the slope of the background pedestal + par[2] is the gaussian peak position + par[3] is the RMS of the gaussian (and of the pedestal) + par[4] is the height of the function + par[5] is the fractional height of the charge sharing pedestal (scales with par[3]) + */ + Double_t gaussChargeSharing(Double_t *x, Double_t *par); + + /** + Basic erf function + par[0] is the inflection point + par[1] is the RMS + par[2] is the amplitude + */ +Double_t erfFunction(Double_t *x, Double_t *par) ; + + /** Erf function with charge sharing slope + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point + par[3] is the RMS + par[4] is the amplitude + par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) + */ +Double_t erfFunctionChargeSharing(Double_t *x, Double_t *par); + + /** Double Erf function with charge sharing slope + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point of the first energy + par[3] is the RMS of the first energy + par[4] is the amplitude of the first energy + par[5] is the angual coefficient of the charge sharing slope of the first energy (scales with par[3]) + par[6] is the inflection point of the second energy + par[7] is the RMS of the second energy + par[8] is the amplitude of the second energy + par[9] is the angual coefficient of the charge sharing slope of the second energy (scales with par[8]) + */ + +Double_t erfFuncFluo(Double_t *x, Double_t *par); + + + /** + static function Gaussian with charge sharing pedestal with the correct scan sign + par[0] is the absolute height of the background pedestal + par[1] is the fractional height of the charge sharing pedestal (scales with par[3] + par[2] is the gaussian peak position + par[3] is the RMS of the gaussian (and of the pedestal) + par[4] is the height of the function + */ + Double_t spectrum(Double_t *x, Double_t *par); + + + /** Erf function with charge sharing slope with the correct scan sign + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point + par[3] is the RMS + par[4] is the amplitude + par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) + */ + Double_t scurve(Double_t *x, Double_t *par); + + + + /** Double Erf function with charge sharing slope + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point of the first energy + par[3] is the RMS of the first energy + par[4] is the amplitude of the first energy + par[5] is the angual coefficient of the charge sharing slope of the first energy (scales with par[3]) + par[6] is the inflection point of the second energy + par[7] is the RMS of the second energy + par[8] is the amplitude of the second energy + par[9] is the angual coefficient of the charge sharing slope of the second energy (scales with par[8]) + */ + Double_t scurveFluo(Double_t *x, Double_t *par); + +#endif + +/** Calculates the median of an array of n elements */ + static double median(double *x, int n); +/** Calculates the median of an array of n elements (swaps the arrays!)*/ + static int quick_select(int arr[], int n); +/** Calculates the median of an array of n elements (swaps the arrays!)*/ + static int kth_smallest(int *a, int n, int k); + + private: + int sign; + + +}; + +/** + class alowing the energy calibration of photon counting and anlogue detectors + +*/ + +class energyCalibration { + + + public: + /** + default constructor - creates the function with which the s-curves will be fitted + */ + energyCalibration(); + + /** + default destructor - deletes the function with which the s-curves will be fitted + */ + ~energyCalibration(); + + /** sets plot flag + \param p plot flag (-1 gets, 0 unsets, >0 plot) + \returns current plot flag + */ + int setPlotFlag(int p=-1) {if (p>=0) plot_flag=p; return plot_flag;}; + + /** sets scan sign + \param s can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) otherwise gets + \returns current scan sign can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) + */ + int setScanSign(int s=0) {return funcs->setScanSign(s);}; + + /** sets plot flag + \param p plot flag (-1 gets, 0 unsets, >0 plot) + \returns current plot flag + */ + int setChargeSharing(int p=-1); + + + void fixParameter(int ip, Double_t val); + + void releaseParameter(int ip); + +#ifdef MYROOT + + static TH1F* createMedianHistogram(TH2F* h2, int ch0, int nch); + + + /** sets the s-curve fit range + \param mi minimum of the fit range (-1 is histogram x-min) + \param ma maximum of the fit range (-1 is histogram x-max) + */ + void setFitRange(Double_t mi, Double_t ma){fit_min=mi; fit_max=ma;}; + + /** gets the s-curve fit range + \param mi reference for minimum of the fit range (-1 is histogram x-min) + \param ma reference for maximum of the fit range (-1 is histogram x-max) + */ + void getFitRange(Double_t &mi, Double_t &ma){mi=fit_min; ma=fit_max;}; + + +/** set start parameters for the s-curve function + \param par parameters, -1 sets to auto-calculation + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point + par[3] is the RMS + par[4] is the amplitude + par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) -- always positive + */ + void setStartParameters(Double_t *par); + +/** get start parameters for the s-curve function + \param par parameters, -1 means auto-calculated + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point + par[3] is the RMS + par[4] is the amplitude + par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) -- always positive + */ + void getStartParameters(Double_t *par); + + /** + fits histogram with the s-curve function + \param h1 1d-histogram to be fitted + \param mypar pointer to fit parameters array + \param emypar pointer to fit parameter errors + \returns the fitted function - can be used e.g. to get the Chi2 or similar + */ + TF1 *fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar); + + + /** + fits histogram with the spectrum + \param h1 1d-histogram to be fitted + \param mypar pointer to fit parameters array + \param emypar pointer to fit parameter errors + \returns the fitted function - can be used e.g. to get the Chi2 or similar + */ + TF1 *fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar); + + + /** + calculates gain and offset for the set of inflection points + \param nscan number of energy scans + \param en array of energies (nscan long) + \param een array of errors on energies (nscan long) - can be NULL! + \param fl array of inflection points (nscan long) + \param efl array of errors on the inflection points (nscan long) + \param gain reference to gain resulting from the fit + \param off reference to offset resulting from the fit + \param egain reference to error on the gain resulting from the fit + \param eoff reference to the error on the offset resulting from the fit + \returns graph energy vs inflection point + */ + TGraphErrors* linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff); + + /** + calculates gain and offset for the set of energy scans + \param nscan number of energy scans + \param en array of energies (nscan long) + \param een array of errors on energies (nscan long) - can be NULL! + \param h1 array of TH1 + \param gain reference to gain resulting from the fit + \param off reference to offset resulting from the fit + \param egain reference to error on the gain resulting from the fit + \param eoff reference to the error on the offset resulting from the fit + \returns graph energy vs inflection point + */ + TGraphErrors* calibrateScurves(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff){return calibrate(nscan, en, een, h1, gain, off, egain, eoff, 1);}; + + /** + calculates gain and offset for the set of energy spectra + \param nscan number of energy scans + \param en array of energies (nscan long) + \param een array of errors on energies (nscan long) - can be NULL! + \param h1 array of TH1 + \param gain reference to gain resulting from the fit + \param off reference to offset resulting from the fit + \param egain reference to error on the gain resulting from the fit + \param eoff reference to the error on the offset resulting from the fit + \returns graph energy vs peak + */ + TGraphErrors* calibrateSpectra(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff){return calibrate(nscan, en, een, h1, gain, off, egain, eoff, 0);}; + + +#endif + private: + +#ifdef MYROOT + /** + calculates gain and offset for the set of energies + \param nscan number of energy scans + \param en array of energies (nscan long) + \param een array of errors on energies (nscan long) - can be NULL! + \param h1 array of TH1 + \param gain reference to gain resulting from the fit + \param off reference to offset resulting from the fit + \param egain reference to error on the gain resulting from the fit + \param eoff reference to the error on the offset resulting from the fit + \param integral 1 is an s-curve set (default), 0 spectra + \returns graph energy vs peak/inflection point + */ + TGraphErrors* calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral=1); + + + /** + Initializes the start parameters and the range of the fit depending on the histogram characteristics and/or on the start parameters specified by the user + \param fun pointer to function to be initialized + \param h1 histogram from which to extract the range and start parameters, if not already specified by the user + +*/ + + void initFitFunction(TF1 *fun, TH1 *h1); + + + /** + Performs the fit according to the flags specified and returns the fitted function + \param fun function to fit + \param h1 histogram to fit + \param mypar pointer to fit parameters array + \param emypar pointer to fit parameter errors + \returns the fitted function - can be used e.g. to get the Chi2 or similar + */ + TF1 *fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar); + +#endif + +#ifdef MYROOT + Double_t fit_min; /**< minimum of the s-curve fitting range, -1 is histogram x-min */ + Double_t fit_max; /**< maximum of the s-curve fitting range, -1 is histogram x-max */ + + Double_t bg_offset; /**< start value for the background pedestal */ + Double_t bg_slope; /**< start value for the background slope */ + Double_t flex; /**< start value for the inflection point */ + Double_t noise; /**< start value for the noise */ + Double_t ampl; /**< start value for the number of photons */ + Double_t cs_slope; /**< start value for the charge sharing slope */ + + + TF1 *fscurve; /**< function with which the s-curve will be fitted */ + + TF1 *fspectrum; /**< function with which the spectrum will be fitted */ + +#endif + + energyCalibrationFunctions *funcs; + int plot_flag; /**< 0 does not plot, >0 plots (flags?) */ + + int cs_flag; /**< 0 functions without charge sharing contribution, >0 with charge sharing contribution */ + +}; + +#endif + + + + + + + + + + + + + + + + + + + diff --git a/slsDetectorCalibration/energyCalibration_cpp.d b/slsDetectorCalibration/energyCalibration_cpp.d new file mode 100644 index 0000000000..c7e9115cda --- /dev/null +++ b/slsDetectorCalibration/energyCalibration_cpp.d @@ -0,0 +1,6 @@ + +# DO NOT DELETE + +./energyCalibration_cpp.so: energyCalibration.h +./energyCalibration_cpp.so: /afs/psi.ch/project/sls_det_software/root_v5.32.01_sl5_32bit/include/cintdictversion.h /afs/psi.ch/project/sls_det_software/root_v5.32.01_sl5_32bit/include/RVersion.h +energyCalibration_cpp__ROOTBUILDVERSION= 5.32/01 From 6a1ffaeda08bb60d3fe76467762bcd363f406b45 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Tue, 24 Sep 2013 08:13:42 +0000 Subject: [PATCH 002/104] added slsDetectorData class to readout (analog) detectors git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@2 113b152e-814d-439b-b186-022a431db7b5 --- .../energyCalibration_cpp.d | 6 -- slsDetectorCalibration/slsDetectorData.h | 91 +++++++++++++++++++ 2 files changed, 91 insertions(+), 6 deletions(-) delete mode 100644 slsDetectorCalibration/energyCalibration_cpp.d create mode 100644 slsDetectorCalibration/slsDetectorData.h diff --git a/slsDetectorCalibration/energyCalibration_cpp.d b/slsDetectorCalibration/energyCalibration_cpp.d deleted file mode 100644 index c7e9115cda..0000000000 --- a/slsDetectorCalibration/energyCalibration_cpp.d +++ /dev/null @@ -1,6 +0,0 @@ - -# DO NOT DELETE - -./energyCalibration_cpp.so: energyCalibration.h -./energyCalibration_cpp.so: /afs/psi.ch/project/sls_det_software/root_v5.32.01_sl5_32bit/include/cintdictversion.h /afs/psi.ch/project/sls_det_software/root_v5.32.01_sl5_32bit/include/RVersion.h -energyCalibration_cpp__ROOTBUILDVERSION= 5.32/01 diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h new file mode 100644 index 0000000000..709afdb5bb --- /dev/null +++ b/slsDetectorCalibration/slsDetectorData.h @@ -0,0 +1,91 @@ +#ifndef SLSDETECTORDATA_H +#define SLSDETECTORDATA_H + +class slsDetectorData { + + /** + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction + \param ds size of the dataset + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + + + */ + slsDetectorData(int npx, int npy=1, int ds=-1, int **dMap=NULL, int **dMask=NULL) { + nx=npx; + ny=npy; + + if (ds<=0) + dataSize=nx*ny; + else + dataSize=ds; + + dataMap=new int[nx][ny]; + dataMask=new int[nx][ny]; + + if (dMap==NULL) { + for (int iy=0; iy Date: Fri, 18 Oct 2013 08:20:55 +0000 Subject: [PATCH 003/104] moench data classes git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@3 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/energyCalibration.cpp | 66 ++++++++- slsDetectorCalibration/energyCalibration.h | 36 ++++- slsDetectorCalibration/moench02ModuleData.h | 139 +++++++++++++++++++ slsDetectorCalibration/moenchReadData.C | 107 ++++++++++++++ slsDetectorCalibration/slsDetectorData.h | 63 +++++++-- 5 files changed, 393 insertions(+), 18 deletions(-) create mode 100644 slsDetectorCalibration/moench02ModuleData.h create mode 100644 slsDetectorCalibration/moenchReadData.C diff --git a/slsDetectorCalibration/energyCalibration.cpp b/slsDetectorCalibration/energyCalibration.cpp index 6264182cff..df548f1cf5 100644 --- a/slsDetectorCalibration/energyCalibration.cpp +++ b/slsDetectorCalibration/energyCalibration.cpp @@ -22,14 +22,65 @@ using namespace std; #ifdef MYROOT + +Double_t energyCalibrationFunctions::pedestal(Double_t *x, Double_t *par) { + return par[0]-par[1]*sign*x[0]; +} + + Double_t energyCalibrationFunctions::gaussChargeSharing(Double_t *x, Double_t *par) { Double_t f, arg=0; - if (par[3]!=0) arg=(x[0]-par[2])/par[3]; - f=par[4]*TMath::Exp(-1*arg*arg/2.); - f=f+par[5]*(par[4]/2*(TMath::Erfc(sign*arg/(TMath::Sqrt(2.)))))+par[0]-par[1]*sign*x[0]; - return f; + if (par[3]!=0) arg=sign*(x[0]-par[2])/par[3]; + f=TMath::Exp(-1*arg*arg/2.); + f=f+par[5]/2.*(TMath::Erfc(arg/(TMath::Sqrt(2.)))); + return par[4]*f+pedestal(x,par); } +Double_t energyCalibrationFunctions::gaussChargeSharingPixel(Double_t *x, Double_t *par) { + Double_t f; + if (par[3]<=0 || par[2]*(*x)<=0 || par[5]<0 || par[4]<=0) return 0; + + Double_t pp[3]; + + pp[0]=0; + pp[1]=par[2]; + pp[2]=par[3]; + + + f=(par[5]-par[6]*(TMath::Log(*x/par[2])))*erfBox(x,pp); + f+=par[4]*TMath::Gaus(*x, par[2], par[3], kTRUE); + return f+pedestal(x,par); +} + +Double_t energyCalibrationFunctions::erfBox(Double_t *z, Double_t *par) { + + + + Double_t m=par[0]; + Double_t M=par[1]; + + if (par[0]>par[1]) { + m=par[1]; + M=par[0]; + } + + if (m==M) + return 0; + + + if (par[2]<=0) { + if (*z>=m && *z<=M) + return 1./(M-m); + else + return 0; + + } + + return (TMath::Erfc((z[0]-M)/par[2])-TMath::Erfc((z[0]-m)/par[2]))*0.5/(M-m); + +} + + // basic erf function Double_t energyCalibrationFunctions::erfFunction(Double_t *x, Double_t *par) { double arg=0; @@ -155,6 +206,10 @@ Double_t energyCalibrationFunctions::spectrum(Double_t *x, Double_t *par) { return gaussChargeSharing(x,par); } +Double_t energyCalibrationFunctions::spectrumPixel(Double_t *x, Double_t *par) { + return gaussChargeSharingPixel(x,par); +} + Double_t energyCalibrationFunctions::scurve(Double_t *x, Double_t *par) { return erfFunctionChargeSharing(x,par); @@ -193,6 +248,9 @@ energyCalibration::energyCalibration() : fspectrum=new TF1("fspectrum",funcs,&energyCalibrationFunctions::spectrum,0,1000,6,"energyCalibrationFunctions","spectrum"); fspectrum->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal"); + fspixel=new TF1("fspixel",funcs,&energyCalibrationFunctions::spectrumPixel,0,1000,7,"energyCalibrationFunctions","spectrumPixel"); + fspixel->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal","Corner"); + #endif diff --git a/slsDetectorCalibration/energyCalibration.h b/slsDetectorCalibration/energyCalibration.h index 3e7a9717f6..904705aa34 100644 --- a/slsDetectorCalibration/energyCalibration.h +++ b/slsDetectorCalibration/energyCalibration.h @@ -18,6 +18,7 @@ #define MYROOT #endif +#define MYROOT #ifdef MYROOT #include @@ -80,6 +81,13 @@ class energyCalibrationFunctions { #ifdef MYROOT + /** + Gaussian Function with charge sharing pedestal + par[0] is the absolute height of the background pedestal + par[1] is the slope of the background pedestal + */ + Double_t pedestal(Double_t *x, Double_t *par); + /** Gaussian Function with charge sharing pedestal par[0] is the absolute height of the background pedestal @@ -90,6 +98,16 @@ class energyCalibrationFunctions { par[5] is the fractional height of the charge sharing pedestal (scales with par[3]) */ Double_t gaussChargeSharing(Double_t *x, Double_t *par); + /** + Gaussian Function with charge sharing pedestal + par[0] is the absolute height of the background pedestal + par[1] is the slope of the background pedestal + par[2] is the gaussian peak position + par[3] is the RMS of the gaussian (and of the pedestal) + par[4] is the height of the function + par[5] is the fractional height of the charge sharing pedestal (scales with par[3]) + */ + Double_t gaussChargeSharingPixel(Double_t *x, Double_t *par); /** Basic erf function @@ -98,7 +116,7 @@ class energyCalibrationFunctions { par[2] is the amplitude */ Double_t erfFunction(Double_t *x, Double_t *par) ; - + Double_t erfBox(Double_t *z, Double_t *par); /** Erf function with charge sharing slope par[0] is the pedestal par[1] is the slope of the pedestal @@ -128,13 +146,25 @@ Double_t erfFuncFluo(Double_t *x, Double_t *par); /** static function Gaussian with charge sharing pedestal with the correct scan sign par[0] is the absolute height of the background pedestal - par[1] is the fractional height of the charge sharing pedestal (scales with par[3] + par[1] is the slope of the pedestal par[2] is the gaussian peak position par[3] is the RMS of the gaussian (and of the pedestal) par[4] is the height of the function + par[5] is the fractional height of the charge sharing pedestal (scales with par[4] */ Double_t spectrum(Double_t *x, Double_t *par); + /** + static function Gaussian with charge sharing pedestal with the correct scan sign + par[0] is the absolute height of the background pedestal + par[1] is the slope of the pedestal + par[2] is the gaussian peak position + par[3] is the RMS of the gaussian (and of the pedestal) + par[4] is the height of the function + par[5] is the fractional height of the charge sharing pedestal (scales with par[4] + */ + Double_t spectrumPixel(Double_t *x, Double_t *par); + /** Erf function with charge sharing slope with the correct scan sign par[0] is the pedestal @@ -381,6 +411,8 @@ class energyCalibration { TF1 *fspectrum; /**< function with which the spectrum will be fitted */ + TF1 *fspixel; /**< function with which the spectrum will be fitted */ + #endif energyCalibrationFunctions *funcs; diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h new file mode 100644 index 0000000000..5009a86866 --- /dev/null +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -0,0 +1,139 @@ +#ifndef MOENCH02MODULEDATA_H +#define MOENCH02MODULEDATA_H +#include "slsDetectorData.h" + +#include +#include + +using namespace std; + +class moench02ModuleData : public slsDetectorData { + public: + /** + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction + \param ds size of the dataset + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + + + */ + + + moench02ModuleData(): slsDetectorData(160, 160, 1286*40) { + int headerOff=0; + int footerOff=1284; + int dataOff=4; + + int ix, iy; + + int **dMask; + int **dMap; + + dMask=new int*[160]; + for(int i = 0; i < 160; i++) { + dMask[i] = new int[160]; + } + dMap=new int*[160]; + for(int i = 0; i < 160; i++) { + dMap[i] = new int[160]; + } + + for (int isc=0; isc<4; isc++) { + for (int ip=0; ip<10; ip++) { + + for (int ir=0; ir<16; ir++) { + for (int ic=0; ic<40; ic++) { + + ix=isc*40+ic; + iy=ip*16+ir; + + dMap[iy][ix]=1280*(isc*10+ip)+2*ir*40+2*ic; + // cout << ix << " " << iy << " " << dMap[ix][iy] << endl; + } + } + } + } + + for (int ix=0; ix<120; ix++) { + for (int iy=0; iy<160; iy++) + dMask[iy][ix]=0x7fff; + } + for (int ix=120; ix<160; ix++) { + for (int iy=0; iy<160; iy++) + dMask[iy][ix]=0x0; + } + + + setDataMap(dMap); + setDataMask(dMask); + }; + + + int getFrameNumber(char *buff){ + return ((*(int*)buff)&(0xffffff00))>>8;; + }; + + int getPacketNumber(char *buff){ + return (*(int*)buff)&0xff; + }; + + + char *readNextFrame(ifstream &filebin) { + char *buff=new char[1280*40]; + char p[1286]; + + int fn, fnum=-1, np=0, pnum=-1; + + if (filebin.is_open()) { + while (filebin.read(p,4)) { //read header + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + + if (pnum<0 || pnum>39) { + cout << "Bad packet number " << pnum << " frame "<< fn << endl; + continue; + } + + if (pnum==0) + pnum=40; + + if (pnum==1) { + fnum=fn; + if (np>0) + cout << "*Incomplete frame number " << fnum << endl; + np=0; + } else if (fn!=fnum) { + if (fnum!=-1) + cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl; + np=0; + } + filebin.read(buff+1280*(pnum-1),1280); //readdata + np++; + filebin.read(p,2); //readfooter + + if (np==40) + if (pnum==40) + break; + else + cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; + + } + } + if (np<40) { + if (np>0) + cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; + delete [] buff; + buff=NULL; + } + return buff; + }; + + +}; + + + +#endif diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C new file mode 100644 index 0000000000..7d9f425e39 --- /dev/null +++ b/slsDetectorCalibration/moenchReadData.C @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "RunningStat.h" +#include "MovingStat.h" +#include "moench02ModuleData.h" + +using namespace std; + + +TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1) { + + moench02ModuleData *decoder=new moench02ModuleData(); + char *buff; + char fname[10000]; + + int nf=0; + + TH2F *h2=NULL; + h2=new TH2F("h2",fformat,nbins,hmin-0.5,hmax-0.5,160*160,-0.5,160*160-0.5); + + int val, dum; + double me, sig, tot; + + MovingStat stat[160][160]; + + ifstream filebin; + + int nbg=1000; + + int ix, iy, ir, ic; + + + for (ir=0; ir<160; ir++) { + for (ic=0; ic<160; ic++) { + stat[ir][ic].Clear(); + stat[ir][ic].SetN(nbg); + } + } + + for (int irun=runmin; irunreadNextFrame(filebin))) { + + for (ix=0; ix<160; ix++) + for (iy=0; iy<160; iy++) { + + dum=0; //no hit + tot=0; + + if (nf>1000) { + me=stat[iy][ix].Mean(); + sig=stat[iy][ix].StandardDeviation(); + val=sign*decoder->getChannelShort(buff,ix,iy)-me; + h2->Fill(val,ix*160+iy); + + dum=0; //no hit + tot=0; + + for (ir=-1; ir<2; ir++) + for (ic=-1; ic<2; ic++){ + if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) { + if (decoder->getChannelShort(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! + tot+=decoder->getChannelShort(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); + } + } + + if (tot>3.*sig) dum=3; //discard events where sum of the neighbours is too large. + + if (val<(me-3.*sig)) dum=2; //discard negative events! + } + if (nf<1000 || dum==0) + stat[iy][ix].Calc(sign*decoder->getChannelShort(buff,ix,iy)); + + } + delete [] buff; + cout << "=" ; + nf++; + } + cout << endl; + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + } + + delete decoder; + cout << "Read " << nf << " frames" << endl; + return h2; +} + diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 709afdb5bb..519014b7d3 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -1,8 +1,13 @@ #ifndef SLSDETECTORDATA_H #define SLSDETECTORDATA_H -class slsDetectorData { +#include +#include + +using namespace std; +class slsDetectorData { + public: /** Constructor (no error checking if datasize and offsets are compatible!) @@ -23,26 +28,58 @@ class slsDetectorData { else dataSize=ds; - dataMap=new int[nx][ny]; - dataMask=new int[nx][ny]; + dataMask=new int*[ny]; + for(int i = 0; i < ny; i++) { + dataMask[i] = new int[nx]; + } + dataMap=new int*[ny]; + for(int i = 0; i < ny; i++) { + dataMap[i] = new int[nx]; + } + setDataMap(dMap); + setDataMask(dMask); + + }; + + ~slsDetectorData() { + for(int i = 0; i < ny; i++) { + delete [] dataMap[i]; + delete [] dataMask[i]; + } + delete [] dataMap; + delete [] dataMask; + } + + void setDataMap(int **dMap=NULL) { + + if (dMap==NULL) { for (int iy=0; iy Date: Fri, 18 Oct 2013 12:26:31 +0000 Subject: [PATCH 004/104] moench Tree Maker added git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@4 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchMakeTree.C | 147 ++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 slsDetectorCalibration/moenchMakeTree.C diff --git a/slsDetectorCalibration/moenchMakeTree.C b/slsDetectorCalibration/moenchMakeTree.C new file mode 100644 index 0000000000..447050e1b0 --- /dev/null +++ b/slsDetectorCalibration/moenchMakeTree.C @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "RunningStat.h" +#include "MovingStat.h" +#include "moench02ModuleData.h" + +using namespace std; + + +void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign=1) { + + moench02ModuleData *decoder=new moench02ModuleData(); + char *buff; + char fname[10000]; + + int nf=0; + + int dum, nPhotons; + double me, sig, tot, maxNei, val, valNei; + + MovingStat stat[160][160]; + MovingStat nPhotonsStat; + + ifstream filebin; + + int nbg=1000; + + int ix, iy, ir, ic; + Double_t data[3][3]; + + TTree* tall=new TTree(tname,tname); + tall->Branch("iFrame",&nf,"iframe/I"); + tall->Branch("x",&ix,"x/I"); + tall->Branch("y",&iy,"y/I"); + tall->Branch("data",data,"data[3][3]/D"); + tall->Branch("pedestal",&me,"pedestal/D"); + tall->Branch("rms",&sig,"rms/D"); + + for (ir=0; ir<160; ir++) { + for (ic=0; ic<160; ic++) { + stat[ir][ic].Clear(); + stat[ir][ic].SetN(nbg); + } + } + + for (int irun=runmin; irunreadNextFrame(filebin))) { + nPhotons=0; + for (ix=0; ix<160; ix++){ + for (iy=0; iy<160; iy++) { + + dum=0; //no hit + tot=0; + + if (nf>1000) { + me=stat[iy][ix].Mean(); + sig=stat[iy][ix].StandardDeviation(); + val=sign*decoder->getChannelShort(buff,ix,iy)-me; + + dum=0; //no hit + tot=0; + maxNei; + + for (ir=-1; ir<2; ir++){ + for (ic=-1; ic<2; ic++){ + if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) { + valNei = decoder->getChannelShort(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); + if (decoder->getChannelShort(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! + tot+=valNei; + data[ir][ic]; + maxNei = max(maxNei,valNei); + } + } + } + + if (val<(me-3.*sig)) dum=2; //discard negative events! + + if(maxNei == val && dum == 1){ // this is an event and we are in the center + tall->Fill(); + nPhotons++; + } + + if (tot>3.*sig) dum=3; //discard events (for pedestal) where sum of the neighbours is too large. + } + if (nf<1000 || dum==0) + stat[iy][ix].Calc(sign*decoder->getChannelShort(buff,ix,iy)); + + } + } + delete [] buff; + //cout << "=" ; + nPhotonsStat.Calc(nPhotons); + nf++; + } + cout << endl; + cout << " done. Avg. Photons/Frame: " << nPhotonsStat.Mean() << " sig: " << nPhotonsStat.StandardDeviation() << endl; + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + } + + delete decoder; + cout << "Read " << nf << " frames" << endl; + tall->Write(); + tall->GetCurrentFile()->Close(); + +} + + +//to compile: g++ -DMYROOT -g `root-config --cflags --glibs` -o moenchMakeTree moenchMakeTree.C +int main(int argc, char **argv){ + if(argc != 6) cout << "Usage: inFile outdir tname fileNrStart fileNrEnd" << endl; exit(-1); + + char *inFile = argv[1]; + char *outDir = argv[2]; + char *tName = argv[3]; + int start = atoi(argv[4]); + int end = atoi(argv[5]); + + TFile *f; + char outfname[1000]; + + sprintf(outfname,"%s/%s.root",outDir,tName); + f=new TFile(outfname,"RECREATE"); + + moenchMakeTree(inFile,tName,start,end); +} + From b652a8560d0ddc34d15237b991113ccff7e44b02 Mon Sep 17 00:00:00 2001 From: l_msdetect Date: Fri, 18 Oct 2013 14:42:38 +0000 Subject: [PATCH 005/104] moench multithread tree maker git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@5 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/MovingStat.h | 12 +-- slsDetectorCalibration/moenchMakeTree.C | 116 ++++++++++++++++++----- slsDetectorCalibration/slsDetectorData.h | 4 +- 3 files changed, 100 insertions(+), 32 deletions(-) diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h index 7acba5706f..801c5a64a4 100755 --- a/slsDetectorCalibration/MovingStat.h +++ b/slsDetectorCalibration/MovingStat.h @@ -10,12 +10,12 @@ void SetN(int i) {n=i;}; int GetN() {return n;}; - void Calc(double x) { + inline void Calc(double x) { if (m_n 0) ? m_newM/m_n : 0.0; } @@ -71,12 +71,12 @@ return ( (m_n > 1) ? m_newM2/m_n : 0.0 ); } - double Variance() const + inline double Variance() const { return ( (m_n > 1) ? (M2()-Mean()*Mean()) : 0.0 ); } - double StandardDeviation() const + inline double StandardDeviation() const { return ( (Variance() > 0) ? sqrt( Variance() ) : -1 ); } diff --git a/slsDetectorCalibration/moenchMakeTree.C b/slsDetectorCalibration/moenchMakeTree.C index 447050e1b0..049bd18d91 100644 --- a/slsDetectorCalibration/moenchMakeTree.C +++ b/slsDetectorCalibration/moenchMakeTree.C @@ -17,10 +17,44 @@ #include "RunningStat.h" #include "MovingStat.h" #include "moench02ModuleData.h" +#include using namespace std; +//tree variables +int xC,yC,iFrameC; +double meC,sigC; +Double_t dataC[3][3]; +TTree* tall; + +typedef struct task_s{ + char *fformat; + char *tname; + int runmin; + int runmax; + int sign; +} Task; + +void setUpTree(char *tname){ + tall=new TTree(tname,tname); + tall->Branch("iFrame",&iFrameC,"iframe/I"); + tall->Branch("x",&xC,"x/I"); + tall->Branch("y",&yC,"y/I"); + tall->Branch("data",dataC,"data[3][3]/D"); + tall->Branch("pedestal",&meC,"pedestal/D"); + tall->Branch("rms",&sigC,"rms/D"); +} + +inline void storeEvent(int iF,int x,int y, Double_t data[][3], double me, double sig){ + TThread::Lock(); + xC = x; yC = y; iFrameC = iF; + memcpy(dataC,data,sizeof(Double_t)*3*3); + meC = me; sigC = sig; + tall->Fill(); + TThread::UnLock(); +} + void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign=1) { moench02ModuleData *decoder=new moench02ModuleData(); @@ -42,13 +76,8 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign int ix, iy, ir, ic; Double_t data[3][3]; - TTree* tall=new TTree(tname,tname); - tall->Branch("iFrame",&nf,"iframe/I"); - tall->Branch("x",&ix,"x/I"); - tall->Branch("y",&iy,"y/I"); - tall->Branch("data",data,"data[3][3]/D"); - tall->Branch("pedestal",&me,"pedestal/D"); - tall->Branch("rms",&sig,"rms/D"); + nPhotonsStat.Clear(); + nPhotonsStat.SetN(1000); for (ir=0; ir<160; ir++) { for (ic=0; ic<160; ic++) { @@ -59,7 +88,7 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign for (int irun=runmin; irunreadNextFrame(filebin))) { @@ -70,22 +99,22 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign dum=0; //no hit tot=0; - if (nf>1000) { + if (nf>nbg) { me=stat[iy][ix].Mean(); sig=stat[iy][ix].StandardDeviation(); val=sign*decoder->getChannelShort(buff,ix,iy)-me; dum=0; //no hit tot=0; - maxNei; + maxNei = 0; for (ir=-1; ir<2; ir++){ for (ic=-1; ic<2; ic++){ if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) { - valNei = decoder->getChannelShort(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); - if (decoder->getChannelShort(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! + valNei = sign*decoder->getChannelShort(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); + if (sign*decoder->getChannelShort(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! tot+=valNei; - data[ir][ic]; + data[ir+1][ic+1] = valNei; maxNei = max(maxNei,valNei); } } @@ -94,24 +123,28 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign if (val<(me-3.*sig)) dum=2; //discard negative events! if(maxNei == val && dum == 1){ // this is an event and we are in the center - tall->Fill(); + storeEvent(nf,ix,iy,data,me,sig); nPhotons++; + //cout << "X: " << ix << " Y: " << iy << " val: " << val << " tot: " << tot << endl; + }else{ + dum = 3; //discard events (for pedestal) where sum of the neighbours is too large. } - if (tot>3.*sig) dum=3; //discard events (for pedestal) where sum of the neighbours is too large. + //if (tot>3.*sig && dum == 1){ dum=3;} + //cout << dum; } - if (nf<1000 || dum==0) + if (nfgetChannelShort(buff,ix,iy)); } } delete [] buff; - //cout << "=" ; - nPhotonsStat.Calc(nPhotons); + //cout << "="; cout.flush(); + if(nf>nbg) nPhotonsStat.Calc((double)nPhotons); nf++; } - cout << endl; - cout << " done. Avg. Photons/Frame: " << nPhotonsStat.Mean() << " sig: " << nPhotonsStat.StandardDeviation() << endl; + //cout << endl; + cout << "processed File " << fname << " done. Avg. Photons/Frame: " << nPhotonsStat.Mean() << " sig: " << nPhotonsStat.StandardDeviation() << endl; if (filebin.is_open()) filebin.close(); else @@ -120,15 +153,23 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign delete decoder; cout << "Read " << nf << " frames" << endl; - tall->Write(); - tall->GetCurrentFile()->Close(); + } +void *moenchMakeTreeTask(void *p){ + Task *t = (Task *)p; + moenchMakeTree(t->fformat,t->tname,t->runmin,t->runmax,t->sign); + return 0; +} + //to compile: g++ -DMYROOT -g `root-config --cflags --glibs` -o moenchMakeTree moenchMakeTree.C int main(int argc, char **argv){ - if(argc != 6) cout << "Usage: inFile outdir tname fileNrStart fileNrEnd" << endl; exit(-1); + if(argc != 6){ cout << "Usage: inFile outdir tname fileNrStart fileNrEnd" << endl; exit(-1); } + + int nThreads = 15; + TThread *threads[nThreads]; char *inFile = argv[1]; char *outDir = argv[2]; @@ -138,10 +179,37 @@ int main(int argc, char **argv){ TFile *f; char outfname[1000]; + char threadName[1000]; sprintf(outfname,"%s/%s.root",outDir,tName); f=new TFile(outfname,"RECREATE"); - moenchMakeTree(inFile,tName,start,end); + cout << "outputfile: " << outfname << endl; + setUpTree(tName); + + for(int i = 0; i < nThreads; i++){ + sprintf(threadName,"t%i",i); + Task *t = (Task *)malloc(sizeof(Task)); + t->fformat = inFile; + t->tname = tName; + t->sign = -1; + t->runmin = start + (end-start)/(nThreads-1)*i; + t->runmax = start + (end-start)/(nThreads-1)*(i+1); + if(i == nThreads - 1) t->runmax = end; + cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; + threads[i] = new TThread(threadName, moenchMakeTreeTask, t); + threads[i]->Run(); + } + + + //TThread::Ps(); + + for(int i = 0; i < nThreads; i++){ + threads[i]->Join(); + } + + + tall->Write(); + tall->GetCurrentFile()->Close(); } diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 519014b7d3..1c3d62a42e 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -92,7 +92,7 @@ class slsDetectorData { */ - int getChannel(char *data, int ix, int iy=1) { + inline int getChannel(char *data, int ix, int iy=1) { return (*(data+dataMap[iy][ix]))^dataMask[iy][ix]; }; @@ -107,7 +107,7 @@ class slsDetectorData { */ - u_int16_t getChannelShort(char *data, int ix, int iy=1) { + inline u_int16_t getChannelShort(char *data, int ix, int iy=1) { u_int16_t m=dataMask[iy][ix], d=*(u_int16_t*)(data+dataMap[iy][ix]); // cout << ix << " " << iy << " " << dataMap[ix][iy] << endl; // return (*(dd+dataMap[ix][iy]))^((u_int16_t)dataMask[ix][iy]); From c562fff78be1bf34985394fa625892eeffc2f458 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 24 Oct 2013 11:47:48 +0000 Subject: [PATCH 006/104] generalized several funcs for hit finding and looping over meonch data git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@6 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moench02ModuleData.h | 166 +++++++++++++++++--- slsDetectorCalibration/moenchReadData.C | 84 +++++----- 2 files changed, 186 insertions(+), 64 deletions(-) diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index 5009a86866..7dc2d1bdf1 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -2,13 +2,31 @@ #define MOENCH02MODULEDATA_H #include "slsDetectorData.h" +#include "RunningStat.h" +#include "MovingStat.h" + #include #include using namespace std; + + class moench02ModuleData : public slsDetectorData { public: + + + enum eventType { + PEDESTAL, + NEIGHBOUR, + PHOTON, + PHOTON_MAX, + NEGATIVE_PEDESTAL, + }; + + + + /** Constructor (no error checking if datasize and offsets are compatible!) @@ -22,30 +40,38 @@ class moench02ModuleData : public slsDetectorData { */ - moench02ModuleData(): slsDetectorData(160, 160, 1286*40) { + moench02ModuleData(int nbg=1000): slsDetectorData(160, 160, 1286*40), nSigma(5), buff(NULL), oldbuff(NULL), pedSub(1) { int headerOff=0; int footerOff=1284; int dataOff=4; - int ix, iy; + int ix, iy, ir, ic, i, isc, ip; int **dMask; int **dMap; + for (ir=0; ir<160; ir++) { + for (ic=0; ic<160; ic++) { + stat[ir][ic].Clear(); + stat[ir][ic].SetN(nbg); + } + } + + dMask=new int*[160]; - for(int i = 0; i < 160; i++) { + for(i = 0; i < 160; i++) { dMask[i] = new int[160]; } dMap=new int*[160]; - for(int i = 0; i < 160; i++) { + for(i = 0; i < 160; i++) { dMap[i] = new int[160]; } - for (int isc=0; isc<4; isc++) { - for (int ip=0; ip<10; ip++) { + for (isc=0; isc<4; isc++) { + for (ip=0; ip<10; ip++) { - for (int ir=0; ir<16; ir++) { - for (int ic=0; ic<40; ic++) { + for (ir=0; ir<16; ir++) { + for (ic=0; ic<40; ic++) { ix=isc*40+ic; iy=ip*16+ir; @@ -57,12 +83,12 @@ class moench02ModuleData : public slsDetectorData { } } - for (int ix=0; ix<120; ix++) { - for (int iy=0; iy<160; iy++) - dMask[iy][ix]=0x7fff; + for (ix=0; ix<120; ix++) { + for (iy=0; iy<160; iy++) + dMask[iy][ix]=0x3fff; } - for (int ix=120; ix<160; ix++) { - for (int iy=0; iy<160; iy++) + for (ix=120; ix<160; ix++) { + for (iy=0; iy<160; iy++) dMask[iy][ix]=0x0; } @@ -70,9 +96,10 @@ class moench02ModuleData : public slsDetectorData { setDataMap(dMap); setDataMask(dMask); }; - + + ~moench02ModuleData() {if (buff) delete [] buff; if (oldbuff) delete [] oldbuff; }; - int getFrameNumber(char *buff){ + int getFrameNumber(char *buff){ return ((*(int*)buff)&(0xffffff00))>>8;; }; @@ -82,7 +109,13 @@ class moench02ModuleData : public slsDetectorData { char *readNextFrame(ifstream &filebin) { - char *buff=new char[1280*40]; + + if (oldbuff) + delete [] oldbuff; + + oldbuff=buff; + + char *data=new char[1280*40]; char p[1286]; int fn, fnum=-1, np=0, pnum=-1; @@ -110,7 +143,7 @@ class moench02ModuleData : public slsDetectorData { cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl; np=0; } - filebin.read(buff+1280*(pnum-1),1280); //readdata + filebin.read(data+1280*(pnum-1),1280); //readdata np++; filebin.read(p,2); //readfooter @@ -125,13 +158,108 @@ class moench02ModuleData : public slsDetectorData { if (np<40) { if (np>0) cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; - delete [] buff; + delete [] data; buff=NULL; } - return buff; + buff=data; + return data; }; + void addToPedestal(double val, int ix, int iy){stat[iy][ix].Calc(val);}; + double getPedestal(int ix, int iy){return stat[iy][ix].Mean();}; + double getPedestalRMS(int ix, int iy){return stat[iy][ix].StandardDeviation();}; + double setNSigma(double n){if (n>0) nSigma=n; return nSigma;} + 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;}; + + + double getChannelShort(int ix, int iy, double hc=0, double tc=0) { + + double val=slsDetectorData::getChannelShort(buff,ix,iy); + + if (ix>0 && hc!=0) + val-=hc*slsDetectorData::getChannelShort(buff,ix-1,iy); + + if (oldbuff && tc!=0) + val+=tc*slsDetectorData::getChannelShort(oldbuff,ix,iy); + + + return val; + }; + + + + eventType getEventType(int ix, int iy, double hcorr=0, double tcorr=0, int sign=1) { + + /* PEDESTAL, */ +/* NEIGHBOUR, */ +/* PHOTON, */ +/* PHOTON_MAX, */ + /* NEGATIVE_PEDESTAL */ + eventType ret=PEDESTAL; + double tot=0, v, max=0, sig; + + + sig=getPedestalRMS(ix,iy); + + 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); + if (pedSub) + v=sign*(v-getPedestal(ix+ic,iy+ir)); + cluster[ic+1][ir+1]=v; + tot+=v; + if (v>max) { + max=v; + } + if (ir==0 && ic==0) { + if (v>nSigma*getPedestalRMS(ix,iy)) { + ret=PHOTON; + } else if (v<-nSigma*getPedestalRMS(ix,iy)) + ret=NEGATIVE_PEDESTAL; + } + + + } + + } + } + + if (ret!=PHOTON && tot>3*nSigma*sig) + ret=NEIGHBOUR; + else if (ret==PHOTON) { + if (cluster[1][1]>=max) + ret=PHOTON_MAX; + } + + + + + return ret; + + }; + + + double getClusterElement(int ic, int ir){return cluster[ic+1][ir+1];}; + double *getCluster(){return &cluster[0][0];}; + + + + + private: + + MovingStat stat[160][160]; + double nSigma; + double cluster[3][3]; + char *buff; + char *oldbuff; + int pedSub; + + }; diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 7d9f425e39..078d5931a4 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -14,26 +14,33 @@ #include #include #include -#include "RunningStat.h" -#include "MovingStat.h" #include "moench02ModuleData.h" using namespace std; +#define NC 160 +#define NR 160 -TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1) { + +TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, int nsigma=5, double hc=0, double tc=0, int xmin=0, int xmax=NC, int ymin=0, int ymax=NR) { + moench02ModuleData *decoder=new moench02ModuleData(); char *buff; + char *oldbuff=NULL; char fname[10000]; - + double oldval; int nf=0; + + moench02ModuleData::eventType thisEvent=moench02ModuleData::PEDESTAL; + + TH2F *h2=NULL; - h2=new TH2F("h2",fformat,nbins,hmin-0.5,hmax-0.5,160*160,-0.5,160*160-0.5); - + h2=new TH2F("h2",fformat,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + int val, dum; - double me, sig, tot; + double me=0, sig, tot, vv; MovingStat stat[160][160]; @@ -41,15 +48,11 @@ TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int int nbg=1000; - int ix, iy, ir, ic; + int ix=20, iy=20, ir, ic; + // 6% x-talk from previous pixel + // 12% x-talk from previous frame - for (ir=0; ir<160; ir++) { - for (ic=0; ic<160; ic++) { - stat[ir][ic].Clear(); - stat[ir][ic].SetN(nbg); - } - } for (int irun=runmin; irunreadNextFrame(filebin))) { - for (ix=0; ix<160; ix++) - for (iy=0; iy<160; iy++) { - - dum=0; //no hit - tot=0; - - if (nf>1000) { - me=stat[iy][ix].Mean(); - sig=stat[iy][ix].StandardDeviation(); - val=sign*decoder->getChannelShort(buff,ix,iy)-me; - h2->Fill(val,ix*160+iy); - - dum=0; //no hit - tot=0; - - for (ir=-1; ir<2; ir++) - for (ic=-1; ic<2; ic++){ - if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) { - if (decoder->getChannelShort(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! - tot+=decoder->getChannelShort(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); - } - } - - if (tot>3.*sig) dum=3; //discard events where sum of the neighbours is too large. - - if (val<(me-3.*sig)) dum=2; //discard negative events! - } - if (nf<1000 || dum==0) - stat[iy][ix].Calc(sign*decoder->getChannelShort(buff,ix,iy)); - + for (ix=xmin-1; ix100) { + thisEvent= decoder->getEventType(ix, iy, hc, tc, 1); + } + + if (thisEvent==moench02ModuleData::PEDESTAL) { + decoder->addToPedestal(decoder->getClusterElement(0,0), ix, iy); } - delete [] buff; + + + /*********************************************************** +Add here the function that you want to call: fill histos, make trees etc. + ************************************************************/ + // getClusterElement to access quickly the photon and the neighbours + + } cout << "=" ; nf++; } @@ -99,7 +89,11 @@ TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int else cout << "could not open file " << fname << endl; } + + + + delete decoder; cout << "Read " << nf << " frames" << endl; return h2; From 957c73e200b4da8f23498d414160e7f5f6739574 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Wed, 6 Nov 2013 11:10:01 +0000 Subject: [PATCH 007/104] Generalized moenchReadData to generate tree and cluster histos file git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@7 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moench02ModuleData.h | 19 ++- slsDetectorCalibration/moenchReadData.C | 155 ++++++++++++++++++-- 2 files changed, 158 insertions(+), 16 deletions(-) diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index 7dc2d1bdf1..ca2e753c47 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -8,6 +8,7 @@ #include #include +#include using namespace std; @@ -110,7 +111,7 @@ class moench02ModuleData : public slsDetectorData { char *readNextFrame(ifstream &filebin) { - if (oldbuff) + if (oldbuff) delete [] oldbuff; oldbuff=buff; @@ -159,7 +160,7 @@ class moench02ModuleData : public slsDetectorData { if (np>0) cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; delete [] data; - buff=NULL; + data=NULL; } buff=data; return data; @@ -183,7 +184,7 @@ class moench02ModuleData : public slsDetectorData { if (ix>0 && hc!=0) val-=hc*slsDetectorData::getChannelShort(buff,ix-1,iy); - if (oldbuff && tc!=0) + if (oldbuff && tc!=0) val+=tc*slsDetectorData::getChannelShort(oldbuff,ix,iy); @@ -248,7 +249,19 @@ class moench02ModuleData : public slsDetectorData { double *getCluster(){return &cluster[0][0];}; + TTree *initMoenchTree(char *tname, Int_t *iframe, Int_t * x, Int_t* y, Double_t data[3][3], Double_t *ped, Double_t *sigma) { + TTree* tall=new TTree(tname,tname); + tall->Branch("iFrame",iframe,"iframe/I"); + tall->Branch("x",x,"x/I"); + tall->Branch("y",y,"y/I"); + tall->Branch("data",data,"data[3][3]/D"); + tall->Branch("pedestal",ped,"pedestal/D"); + tall->Branch("rms",sigma,"rms/D"); + return tall; + }; + + private: diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 078d5931a4..4a16ef9cee 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -23,7 +23,8 @@ using namespace std; -TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, int nsigma=5, double hc=0, double tc=0, int xmin=0, int xmax=NC, int ymin=0, int ymax=NR) { + +THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, double tc=0, int xmin=0, int xmax=NC, int ymin=0, int ymax=NR, int pedsub=1) { moench02ModuleData *decoder=new moench02ModuleData(); char *buff; @@ -35,21 +36,52 @@ TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int moench02ModuleData::eventType thisEvent=moench02ModuleData::PEDESTAL; + // int iframe; + // double *data, ped, sigma; + + // data=decoder->getCluster(); + + TH2F *h2; + TH2F *h3; + TH2F *hetaX; + TH2F *hetaY; - TH2F *h2=NULL; - h2=new TH2F("h2",fformat,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + THStack *hs=new THStack("hs",fformat); - int val, dum; - double me=0, sig, tot, vv; + 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 (pedsub) { + + h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h2); + hs->Add(h3); + hs->Add(hetaX); + hs->Add(hetaY); + } - MovingStat stat[160][160]; + ifstream filebin; - int nbg=1000; int ix=20, iy=20, ir, ic; + + Int_t iFrame, x, y; + Double_t data[3][3],ped,sigma; + + TTree *tall; + if (pedsub) { + cout << "Subtracting pedestal!!!! " << endl; + tall=decoder->initMoenchTree(tit, &iFrame, &x, &y, data, &ped, &sigma); + } + double tot, tl, tr, bl, br, v; + + // 6% x-talk from previous pixel // 12% x-talk from previous frame @@ -63,14 +95,16 @@ TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int for (ix=xmin-1; ix100) { thisEvent= decoder->getEventType(ix, iy, hc, tc, 1); } + + if (thisEvent==moench02ModuleData::PEDESTAL) { - decoder->addToPedestal(decoder->getClusterElement(0,0), ix, iy); + decoder->addToPedestal( decoder->getChannelShort(ix, iy, hc, tc), ix, iy); } @@ -78,6 +112,101 @@ TH2F *moenchReadData(char *fformat, int runmin, int runmax, int nbins=1500, int Add here the function that you want to call: fill histos, make trees etc. ************************************************************/ // getClusterElement to access quickly the photon and the neighbours + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + h1->Fill(decoder->getClusterElement(0,0), iy+NR*ix); + + if (thisEvent==moench02ModuleData::PHOTON_MAX ) { + + + for (ir=-1; ir<2; ir++) { + for (ic=-1; ic<2; ic++) { + v=decoder->getClusterElement(ic,ir); + data[ic+1][ir+1]=v; + tot+=v; + if (ir<1) { + + if (ic<1) { + bl+=v; + + } + if (ic>-1) { + br+=v; + } + } + + if (ir>-1) { + if (ic<1) { + tl+=v; + } + if (ic>-1) { + tr+=v; + } + } + } + } + + + if (bl>br && bl>tl && bl>tr) { + h2->Fill(bl, iy+NR*ix); + if (bl>0) { + hetaX->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(0,-1))/bl,iy+NR*ix); + hetaY->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(-1,0))/bl,iy+NR*ix); + hetaX->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(0,-1))/bl,iy+NR*(ix-1)); + hetaY->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(-1,0))/bl,(iy-1)+NR*ix); + } + } else if (br>bl && br>tl && br>tr) { + h2->Fill(br, iy+NR*ix); + if (br>0) { + hetaX->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(0,-1))/br,iy+NR*ix); + hetaY->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(1,0))/br,iy+NR*ix); + hetaX->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(0,-1))/br,iy+NR*(ix+1)); + hetaY->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(1,0))/br,iy-1+NR*ix); + } + } else if (tl>br && tl>bl && tl>tr) { + h2->Fill(tl, iy+NR*ix); + if (tl>0) { + hetaX->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(0,1))/tl,iy+NR*ix); + hetaY->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(-1,0))/tl,iy+NR*ix); + hetaX->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(0,1))/tl,iy+NR*(ix-1)); + hetaY->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(-1,0))/tl,iy+1+NR*ix); + } + } else if (tr>bl && tr>tl && tr>br) { + h2->Fill(tr, iy+NR*ix); + if (tr>0) { + hetaX->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(0,1))/tr,iy+NR*ix); + hetaY->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(1,0))/tr,iy+NR*ix); + hetaX->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(0,1))/tr,iy+NR*(ix+1)); + hetaY->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(1,0))/tr,iy+1+NR*ix); + } + + + + } + + h3->Fill(tot, iy+NR*ix); + iFrame=decoder->getFrameNumber(buff); + ped=decoder->getPedestal(ix,iy); + sigma=decoder->getPedestalRMS(ix,iy); + x=ix; + y=iy; + + tall->Fill(); + + } + + + + } + } else { + //cout << ix << " " << iy << endl; + h1->Fill(decoder->getChannelShort(ix, iy), iy+NR*ix); + } + ////////////////////////////////////////////////////////// } cout << "=" ; @@ -89,13 +218,13 @@ Add here the function that you want to call: fill histos, make trees etc. else cout << "could not open file " << fname << endl; } - - + if (pedsub) + tall->Write(); delete decoder; cout << "Read " << nf << " frames" << endl; - return h2; + return hs; } From 37196f14cabc5ac83acae68713b4513ee6c5abd7 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Wed, 6 Nov 2013 11:13:25 +0000 Subject: [PATCH 008/104] moenchReadData with ttree overwiting previous versions git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@8 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchReadData.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 4a16ef9cee..bf93138303 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -219,7 +219,7 @@ Add here the function that you want to call: fill histos, make trees etc. cout << "could not open file " << fname << endl; } if (pedsub) - tall->Write(); + tall->Write(tall->GetName(),TObject::kOverwrite); From 4f7c6f633f6257c684c830481e45a4d414cc16e0 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Mon, 25 Nov 2013 11:03:04 +0000 Subject: [PATCH 009/104] common mode subtraction implemented git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@9 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moench02ModuleData.h | 65 ++++++++++- slsDetectorCalibration/moenchReadData.C | 115 +++++++++++++------- 2 files changed, 137 insertions(+), 43 deletions(-) diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index ca2e753c47..7dd718f8fc 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -109,8 +109,55 @@ class moench02ModuleData : public slsDetectorData { }; + void calculateCommonMode(int xmin=0, int xmax=160, int ymin=0, int ymax=160, double hc=0, double tc=0) { + + int scmin=xmin/40; + int scmax=(xmax-1)/40+1; + int isc=0, ix, iy; + + for (isc=scmin; isc0) + cmStat[isc].Calc(cmPed[isc]/nCm[isc]); + } + + + }; + + double getCommonMode(int ix, int iy) { + int isc=ix/40; + if (nCm[isc]>0) + return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); + else + return 0; + }; + + + char *readNextFrame(ifstream &filebin) { + if (oldbuff) delete [] oldbuff; @@ -223,10 +270,7 @@ class moench02ModuleData : public slsDetectorData { } else if (v<-nSigma*getPedestalRMS(ix,iy)) ret=NEGATIVE_PEDESTAL; } - - } - } } @@ -238,14 +282,19 @@ class moench02ModuleData : public slsDetectorData { } - + cx=ix; + cy=iy; return ret; }; - double getClusterElement(int ic, int ir){return cluster[ic+1][ir+1];}; + 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 *getCluster(){return &cluster[0][0];}; @@ -271,8 +320,12 @@ class moench02ModuleData : public slsDetectorData { char *buff; char *oldbuff; int pedSub; + int cmSub; - + MovingStat cmStat[4]; //stores the common mode average per supercolumn + double cmPed[4]; // stores the common mode for this frame per supercolumn + double nCm[4]; // stores the number of pedestals to calculate the cm per supercolumn + int cx, cy; }; diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index bf93138303..c2ebd2efeb 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -16,15 +16,35 @@ #include #include "moench02ModuleData.h" +//#include "MovingStat.h" + using namespace std; #define NC 160 #define NR 160 - - - -THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, double tc=0, int xmin=0, int xmax=NC, int ymin=0, int ymax=NR, int pedsub=1) { +/** + char *fformat, file name format + char *tit, title of the tree etc. + int runmin, minimum run number + int runmax, max run number + int nbins=1500, number of bins for spectrum hists + int hmin=-500, minimum for spectrum hists + int hmax=1000, maximum for spectrum hists + int sign=1, sign of the spectrum to find hits + double hc=0, readout correlation coefficient with previous pixel + double tc=0, time correlation coefficient with previous frame (case of bad reset) + int xmin=0, minimum x coordinate + int xmax=NC, maximum x coordinate + int ymin=0, minimum y coordinate + int ymax=NR, maximum y coordinate + int pedsub=1, enable pedestal subtraction + int cmsub=0 enable commonmode subtraction + +*/ + + +THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, double tc=0, int xmin=0, int xmax=NC, int ymin=0, int ymax=NR, int pedsub=1, int cmsub=0) { moench02ModuleData *decoder=new moench02ModuleData(); char *buff; @@ -32,8 +52,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb char fname[10000]; double oldval; int nf=0; - - + moench02ModuleData::eventType thisEvent=moench02ModuleData::PEDESTAL; // int iframe; @@ -80,7 +99,9 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb tall=decoder->initMoenchTree(tit, &iFrame, &x, &y, data, &ped, &sigma); } double tot, tl, tr, bl, br, v; + + int scmin=xmin/40, scmax=(xmax-1)/40+1; // 6% x-talk from previous pixel // 12% x-talk from previous frame @@ -92,20 +113,40 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb filebin.open((const char *)(fname), ios::in | ios::binary); while ((buff=decoder->readNextFrame(filebin))) { - + + + + if (nf>100) { + if (cmsub) { + for (int isc=scmin; isccalculateCommonMode(3+isc*40, 40*(isc-1)-3, 3, NR-3, hc, tc); + } + } + } + + + + for (ix=xmin-1; ix100) { - thisEvent= decoder->getEventType(ix, iy, hc, tc, 1); - } - - + + + if (nf>100) { + thisEvent= decoder->getEventType(ix, iy, hc, tc, 1); + } + - if (thisEvent==moench02ModuleData::PEDESTAL) { - decoder->addToPedestal( decoder->getChannelShort(ix, iy, hc, tc), ix, iy); - } + + + if (thisEvent==moench02ModuleData::PEDESTAL) { + if (cmsub && nf>1000) + 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); + + } /*********************************************************** @@ -118,14 +159,14 @@ 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), iy+NR*ix); + h1->Fill(decoder->getClusterElement(0,0, cmsub), iy+NR*ix); if (thisEvent==moench02ModuleData::PHOTON_MAX ) { for (ir=-1; ir<2; ir++) { for (ic=-1; ic<2; ic++) { - v=decoder->getClusterElement(ic,ir); + v=decoder->getClusterElement(ic,ir,cmsub); data[ic+1][ir+1]=v; tot+=v; if (ir<1) { @@ -154,34 +195,34 @@ Add here the function that you want to call: fill histos, make trees etc. if (bl>br && bl>tl && bl>tr) { h2->Fill(bl, iy+NR*ix); if (bl>0) { - hetaX->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(0,-1))/bl,iy+NR*ix); - hetaY->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(-1,0))/bl,iy+NR*ix); - hetaX->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(0,-1))/bl,iy+NR*(ix-1)); - hetaY->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(-1,0))/bl,(iy-1)+NR*ix); + hetaX->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,-1,cmsub))/bl,iy+NR*ix); + hetaY->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(-1,0,cmsub))/bl,iy+NR*ix); + hetaX->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,-1,cmsub))/bl,iy+NR*(ix-1)); + hetaY->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(-1,0,cmsub))/bl,(iy-1)+NR*ix); } } else if (br>bl && br>tl && br>tr) { h2->Fill(br, iy+NR*ix); if (br>0) { - hetaX->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(0,-1))/br,iy+NR*ix); - hetaY->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(1,0))/br,iy+NR*ix); - hetaX->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(0,-1))/br,iy+NR*(ix+1)); - hetaY->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(1,0))/br,iy-1+NR*ix); + hetaX->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,-1,cmsub))/br,iy+NR*ix); + hetaY->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(1,0,cmsub))/br,iy+NR*ix); + hetaX->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,-1,cmsub))/br,iy+NR*(ix+1)); + hetaY->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(1,0,cmsub))/br,iy-1+NR*ix); } } else if (tl>br && tl>bl && tl>tr) { h2->Fill(tl, iy+NR*ix); if (tl>0) { - hetaX->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(0,1))/tl,iy+NR*ix); - hetaY->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(-1,0))/tl,iy+NR*ix); - hetaX->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(0,1))/tl,iy+NR*(ix-1)); - hetaY->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(-1,0))/tl,iy+1+NR*ix); + hetaX->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,1,cmsub))/tl,iy+NR*ix); + hetaY->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(-1,0,cmsub))/tl,iy+NR*ix); + hetaX->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,1,cmsub))/tl,iy+NR*(ix-1)); + hetaY->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(-1,0,cmsub))/tl,iy+1+NR*ix); } } else if (tr>bl && tr>tl && tr>br) { h2->Fill(tr, iy+NR*ix); if (tr>0) { - hetaX->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(0,1))/tr,iy+NR*ix); - hetaY->Fill((decoder->getClusterElement(0,0)+decoder->getClusterElement(1,0))/tr,iy+NR*ix); - hetaX->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(0,1))/tr,iy+NR*(ix+1)); - hetaY->Fill(1.-(decoder->getClusterElement(0,0)+decoder->getClusterElement(1,0))/tr,iy+1+NR*ix); + hetaX->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,1,cmsub))/tr,iy+NR*ix); + hetaY->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(1,0,cmsub))/tr,iy+NR*ix); + hetaX->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,1,cmsub))/tr,iy+NR*(ix+1)); + hetaY->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(1,0,cmsub))/tr,iy+1+NR*ix); } @@ -207,17 +248,17 @@ Add here the function that you want to call: fill histos, make trees etc. h1->Fill(decoder->getChannelShort(ix, iy), iy+NR*ix); } ////////////////////////////////////////////////////////// - } + cout << "=" ; nf++; - } + } cout << endl; if (filebin.is_open()) filebin.close(); else cout << "could not open file " << fname << endl; - } + } if (pedsub) tall->Write(tall->GetName(),TObject::kOverwrite); @@ -226,5 +267,5 @@ Add here the function that you want to call: fill histos, make trees etc. delete decoder; cout << "Read " << nf << " frames" << endl; return hs; -} + } From b8462e24ef655872012e0231963cbe5156dedc57 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Wed, 4 Dec 2013 11:12:13 +0000 Subject: [PATCH 010/104] common mode subtraction now works for moench - bad channel mask added to the data structure git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@10 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/MovingStat.h | 2 +- slsDetectorCalibration/moench02ModuleData.h | 42 ++++++++----- slsDetectorCalibration/moenchReadData.C | 67 ++++++++++++++++++--- slsDetectorCalibration/slsDetectorData.h | 38 ++++++++++-- 4 files changed, 116 insertions(+), 33 deletions(-) diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h index 801c5a64a4..634560000f 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 7dd718f8fc..d7757972b6 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 c2ebd2efeb..2095e380ee 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 1c3d62a42e..a8ffb85133 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) { @@ -75,9 +81,28 @@ class slsDetectorData { dataMask[iy][ix]=dMask[iy][ix]; } + }; + void setDataROIMask(int **dROI=NULL){ + + if (dROI!=NULL) { + + for (int iy=0; iy Date: Mon, 9 Dec 2013 10:26:50 +0000 Subject: [PATCH 011/104] added general class to detect photons git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@11 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/MovingStat.h | 11 +- slsDetectorCalibration/moench02ModuleData.h | 90 +------ slsDetectorCalibration/moenchReadData.C | 6 +- slsDetectorCalibration/singlePhotonDetector.h | 225 ++++++++++++++++++ slsDetectorCalibration/single_photon_hit.h | 44 ++++ slsDetectorCalibration/slsDetectorData.h | 136 +++++++++-- 6 files changed, 405 insertions(+), 107 deletions(-) create mode 100644 slsDetectorCalibration/singlePhotonDetector.h create mode 100644 slsDetectorCalibration/single_photon_hit.h diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h index 634560000f..9c8584d338 100755 --- a/slsDetectorCalibration/MovingStat.h +++ b/slsDetectorCalibration/MovingStat.h @@ -1,7 +1,13 @@ - class MovingStat +#ifndef MOVINGSTAT_H +#define MOVINGSTAT_H + +#include + + +class MovingStat { public: - MovingStat() : m_n(0), n(1000) {} + MovingStat() : n(1000), m_n(0) {} void Clear() { @@ -86,3 +92,4 @@ int m_n; double m_oldM, m_newM, m_oldM2, m_newM2; }; +#endif diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index d7757972b6..8a9a2d5790 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -1,6 +1,7 @@ #ifndef MOENCH02MODULEDATA_H #define MOENCH02MODULEDATA_H -#include "slsDetectorData.h" +//#include "slsDetectorData.h" +#include "singlePhotonDetector.h" #include "RunningStat.h" #include "MovingStat.h" @@ -13,19 +14,10 @@ using namespace std; -class moench02ModuleData : public slsDetectorData { +class moench02ModuleData : public slsDetectorData { public: - enum eventType { - PEDESTAL, - NEIGHBOUR, - PHOTON, - PHOTON_MAX, - NEGATIVE_PEDESTAL, - }; - - /** @@ -41,7 +33,7 @@ class moench02ModuleData : public slsDetectorData { */ - moench02ModuleData(int nbg=1000): slsDetectorData(160, 160, 1286*40), nSigma(5), buff(NULL), oldbuff(NULL), pedSub(1) { + moench02ModuleData(int nbg=1000): slsDetectorData(160, 160, 40, 1286), nSigma(5), buff(NULL), oldbuff(NULL), pedSub(1) { int headerOff=0; int footerOff=1284; int dataOff=4; @@ -77,7 +69,7 @@ class moench02ModuleData : public slsDetectorData { ix=isc*40+ic; iy=ip*16+ir; - dMap[iy][ix]=1280*(isc*10+ip)+2*ir*40+2*ic; + dMap[iy][ix]=1286*(isc*10+ip)+2*ir*40+2*ic; // cout << ix << " " << iy << " " << dMap[ix][iy] << endl; } } @@ -100,12 +92,12 @@ class moench02ModuleData : public slsDetectorData { ~moench02ModuleData() {if (buff) delete [] buff; if (oldbuff) delete [] oldbuff; }; - int getFrameNumber(char *buff){ - return ((*(int*)buff)&(0xffffff00))>>8;; - }; int getPacketNumber(char *buff){ - return (*(int*)buff)&0xff; + int np=(*(int*)buff)&0xff; + if (np==0) + np=40; + return np; }; @@ -166,64 +158,6 @@ class moench02ModuleData : public slsDetectorData { - char *readNextFrame(ifstream &filebin) { - - - if (oldbuff) - delete [] oldbuff; - - oldbuff=buff; - - char *data=new char[1280*40]; - char p[1286]; - - int fn, fnum=-1, np=0, pnum=-1; - - if (filebin.is_open()) { - while (filebin.read(p,4)) { //read header - pnum=getPacketNumber(p); - fn=getFrameNumber(p); - - if (pnum<0 || pnum>39) { - cout << "Bad packet number " << pnum << " frame "<< fn << endl; - continue; - } - - if (pnum==0) - pnum=40; - - if (pnum==1) { - fnum=fn; - if (np>0) - cout << "*Incomplete frame number " << fnum << endl; - np=0; - } else if (fn!=fnum) { - if (fnum!=-1) - cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl; - np=0; - } - filebin.read(data+1280*(pnum-1),1280); //readdata - np++; - filebin.read(p,2); //readfooter - - if (np==40) - if (pnum==40) - break; - else - cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; - - } - } - if (np<40) { - if (np>0) - cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; - delete [] data; - data=NULL; - } - buff=data; - return data; - }; - void addToPedestal(double val, int ix, int iy){stat[iy][ix].Calc(val);}; double getPedestal(int ix, int iy){return stat[iy][ix].Mean();}; @@ -237,13 +171,13 @@ class moench02ModuleData : public slsDetectorData { double getChannelShort(int ix, int iy, double hc=0, double tc=0) { - double val=slsDetectorData::getChannelShort(buff,ix,iy); + double val=slsDetectorData::getChannel(buff,ix,iy); if (ix>0 && hc!=0) - val-=hc*slsDetectorData::getChannelShort(buff,ix-1,iy); + val-=hc*slsDetectorData::getChannel(buff,ix-1,iy); if (oldbuff && tc!=0) - val+=tc*slsDetectorData::getChannelShort(oldbuff,ix,iy); + val+=tc*slsDetectorData::getChannel(oldbuff,ix,iy); return val; diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 2095e380ee..468817e45e 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -60,7 +60,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb double oldval; int nf=0; - moench02ModuleData::eventType thisEvent=moench02ModuleData::PEDESTAL; + eventType thisEvent=PEDESTAL; // int iframe; // double *data, ped, sigma; @@ -162,7 +162,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb - if (thisEvent==moench02ModuleData::PEDESTAL) { + if (thisEvent==PEDESTAL) { if (cmsub && nf>1000) decoder->addToPedestal(decoder->getChannelShort(ix, iy, hc, tc)-decoder->getCommonMode(ix,iy), ix, iy); else @@ -186,7 +186,7 @@ Add here the function that you want to call: fill histos, make trees etc. // if (nf%1000==0 && ix==20 && iy==20) cout << " val="<< decoder->getClusterElement(0,0)<< endl; - if (thisEvent==moench02ModuleData::PHOTON_MAX ) { + if (thisEvent==PHOTON_MAX ) { #ifdef MY_DEBUG if (iev%100000==0) { cout << "Event " << iev << " Frame "<< nf << endl; diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h new file mode 100644 index 0000000000..2c226a69e5 --- /dev/null +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -0,0 +1,225 @@ +#ifndef SINGLEPHOTONDETECTOR_H +#define SINGLEPHOTONDETECTOR_H +#include "slsDetectorData.h" + +#include "MovingStat.h" +#include "single_photon_hit.h" + +#include + +using namespace std; + + + enum eventType { + PEDESTAL, + NEIGHBOUR, + PHOTON, + PHOTON_MAX, + NEGATIVE_PEDESTAL, + }; + + + +template +class singlePhotonDetector { + + + public: + + + /** + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction + \param ds size of the dataset + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + + + */ + + + singlePhotonDetector(slsDetectorData *d, int csize=3, double nsigma=5) : det(d), clusterSize(csize), clusterSizeY(csize),nSigma(nsigma) { + + + + det->getDetectorSize(nx,ny); + + + + stat=new MovingStat*[ny]; + for (int i=0; i=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy0) nSigma=n; return nSigma;} + + int setClusterSize(int n=-1){ + if (n>0 && n!=clusterSize) { + if (n%2==0) + n+=1; + clusterSize=n; + delete cluster; + if (ny>1) + clusterSizeY=clusterSize; + + cluster=new single_photon_hit(clusterSize,clusterSizeY); + } + return clusterSize; + } + + + + eventType getEventType(char *data, int ix, int iy, double hcorr=0, double tcorr=0, int sign=1, int cm=0) { + + eventType ret=PEDESTAL; + double tot=0, v, max=0, sig; + + + sig=getPedestalRMS(ix,iy); + + cluster->x=ix; + cluster->y=iy; + cluster->rms=sig; + cluster->ped=getPedestal(ix,iy); + + + for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { + for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { + if ((iy+ir)>=0 && (iy+ir)<160 && (ix+ic)>=0 && (ix+ic)<160) { + v=sign*(det->getValue(data, ix+ic, iy+ir)-getPedestal(ix+ic,iy+ir)); + // if (cm) + // v-=sign*getCommonMode(ix+ic, iy+ic); + cluster->set_data(ic, ir, v); + tot+=v; + if (v>max) { + max=v; + } + if (ir==0 && ic==0) { + if (v>nSigma*getPedestalRMS(ix,iy)) { + ret=PHOTON; + } else if (v<-nSigma*getPedestalRMS(ix,iy)) + ret=NEGATIVE_PEDESTAL; + } + } + } + } + + if (ret!=PHOTON && tot>3*nSigma*sig) + ret=NEIGHBOUR; + else if (ret==PHOTON) { + if (cluster->get_data(0,0)>=max) + ret=PHOTON_MAX; + } + + return ret; + + }; + + + + + + + + double getClusterElement(int ic, int ir, int cmsub=0){return cluster->get_data(ic,ir);}; + + + private: + + slsDetectorData *det; + int nx, ny; + + + + MovingStat **stat; + double nSigma; + int clusterSize, clusterSizeY; + single_photon_hit *cluster; + + MovingStat cmStat[4]; //stores the common mode average per supercolumn + double cmPed[4]; // stores the common mode for this frame per supercolumn + double nCm[4]; // stores the number of pedestals to calculate the cm per supercolumn + int cx, cy; +}; + + + + + + + + /////////////////////////////////////////////////////// DONE UNTIL HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + /* void calculateCommonMode(int xmin=0, int xmax=160, int ymin=0, int ymax=160, double hc=0, double tc=0) { */ + +/* int scmin=xmin/40; */ +/* int scmax=(xmax-1)/40+1; */ +/* int isc=0, ix, iy; */ + +/* for (isc=scmin; isc0) */ +/* 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 (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 { */ +/* /\* if (ix==20 && iy==20) *\/ */ +/* /\* cout << "No common mode!" << endl; *\/ */ + +/* return 0; */ +/* } */ +/* }; */ + + + +#endif diff --git a/slsDetectorCalibration/single_photon_hit.h b/slsDetectorCalibration/single_photon_hit.h new file mode 100644 index 0000000000..278c9f691d --- /dev/null +++ b/slsDetectorCalibration/single_photon_hit.h @@ -0,0 +1,44 @@ +#ifndef SINGLE_PHOTON_HIT_H +#define SINGLE_PHOTON_HIT_h + +typedef double double32_t; +typedef float float32_t; +typedef int int32_t; + +/* /\** */ +/* @short structure for a single photon hit */ +/* *\/ */ +/* typedef struct{ */ +/* double* data; /\**< data size *\/ */ +/* int x; /\**< x-coordinate of the center of hit *\/ */ +/* int y; /\**< x-coordinate of the center of hit *\/ */ +/* double rms; /\**< noise of central pixel *\/ */ +/* double ped; /\**< pedestal of the central pixel *\/ */ +/* int iframe; /\**< frame number *\/ */ +/* }single_photon_hit; */ + + +class single_photon_hit { + + public: + single_photon_hit(int nx, int ny=1): dx(nx), dy(ny) {data=new double[dx*dy];}; + ~single_photon_hit(){delete [] data;}; + void write(FILE *myFile) {fwrite((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);}; + void read(FILE *myFile) {fread((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fread((void*)data, 1, dx*dy*sizeof(double), myFile);}; + void set_data(double v, int ix, int iy=0){data[(iy+dy/2)*dx+ix+dx/2]=v;}; + double get_data(int ix, int iy=0){return data[(iy+dy/2)*dx+ix+dx/2];}; + + + int x; /**< x-coordinate of the center of hit */ + int y; /**< x-coordinate of the center of hit */ + double rms; /**< noise of central pixel */ + double ped; /**< pedestal of the central pixel */ + int iframe; /**< frame number */ + double *data; /**< data size */ + const int dx; + const int dy; +}; + + + +#endif diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index a8ffb85133..527e4e9bb1 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -6,8 +6,13 @@ using namespace std; + +template class slsDetectorData { + + public: + /** Constructor (no error checking if datasize and offsets are compatible!) @@ -19,12 +24,9 @@ class slsDetectorData { */ - slsDetectorData(int npx, int npy=1, int ds=-1, int **dMap=NULL, int **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy) { + slsDetectorData(int npx, int npy, int np, int psize, int **dMap=NULL, int **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), nPackets(np), packetSize(psize) { - if (ds<=0) - dataSize=nx*ny; - else - dataSize=ds; + dataMask=new int*[ny]; for(int i = 0; i < ny; i++) { @@ -46,7 +48,7 @@ class slsDetectorData { }; - ~slsDetectorData() { + virtual ~slsDetectorData() { for(int i = 0; i < ny; i++) { delete [] dataMap[i]; delete [] dataMask[i]; @@ -100,11 +102,14 @@ class slsDetectorData { }; - int setBad(int ix, int iy, int i=1) {dataROIMask[iy][ix]=i; return isGood(ix,iy);}; + int setGood(int ix, int iy, int i=1) {dataROIMask[iy][ix]=i; return isGood(ix,iy);}; int isGood(int ix, int iy) {return dataROIMask[iy][ix];}; + void getDetectorSize(int &npx, int &npy){npx=nx; npy=ny;}; + + /** Returns the value of the selected channel for the given dataset (no error checking if number of pixels are compatible!) @@ -117,34 +122,117 @@ class slsDetectorData { */ - inline int getChannel(char *data, int ix, int iy=1) { - return (*(data+dataMap[iy][ix]))^dataMask[iy][ix]; + virtual dataType getChannel(char *data, int ix, int iy=0) { + dataType m=dataMask[iy][ix], d=*((dataType*)(data+dataMap[iy][ix])); + return d^m; }; - - /** - Returns the value of the selected channel for the given dataset (no error checking if number of pixels are compatible!) - \param data pointer to the dataset (including headers etc) - \param ix pixel numb er in the x direction - \param iy pixel number in the y direction + virtual double getValue(char *data, int ix, int iy=0) {return (double)getChannel(data, ix, iy);}; + + + virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; + virtual int getPacketNumber(char *buff) {return (*(int*)buff)&0xff;}; + + + virtual char *findNextFrame(char *data, int &npackets, int dsize) { + char *retval=NULL, *p=data; + int dd=0; + int fn, fnum=-1, np=0, pnum=-1; + while (dd<=(dsize-packetSize)) { + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + if (pnum<0 || pnum>=nPackets) { + cout << "Bad packet number " << pnum << " frame "<< fn << endl; + retval=NULL; + continue; + } + if (pnum==1) { + fnum=fn; + retval=p; + if (np>0) + cout << "*Incomplete frame number " << fnum << endl; + np=0; + } else if (fn!=fnum) { + if (fnum!=-1) { + cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl; + retval=NULL; + } + np=0; + } + p+=packetSize; + dd+=packetSize; + np++; + if (np==nPackets) + if (pnum==nPackets) + break; + else { + cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; + retval=NULL; + } + } + if (np<40) { + if (np>0) + cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; + } + + npackets=np; + + return retval; + }; - \returns data for the selected channel, with inversion if required - */ + virtual char *readNextFrame(ifstream &filebin) { + - inline u_int16_t getChannelShort(char *data, int ix, int iy=1) { - u_int16_t m=dataMask[iy][ix], d=*(u_int16_t*)(data+dataMap[iy][ix]); - // cout << ix << " " << iy << " " << dataMap[ix][iy] << endl; - // return (*(dd+dataMap[ix][iy]))^((u_int16_t)dataMask[ix][iy]); - return d^m; +/* if (oldbuff) */ +/* delete [] oldbuff; */ + +/* oldbuff=buff; */ + + // char *p=new char[1286]; + char *data=new char[packetSize*nPackets]; + char *retval=0; + int np=40; + + if (filebin.is_open()) { + while (filebin.read(data+np*packetSize,packetSize)) { + + if (np==nPackets) { + + retval=findNextFrame(data,np,packetSize*nPackets); + if (retval==data && np==nPackets) + return data; + else if (np>nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + for (int ip=0; ipnPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + // memcpy(data+np*1286,p,1286); + np++; + } + + } + } + delete [] data; + return NULL; }; - + private: const int nx; /**< Number of pixels in the x direction */ const int ny; /**< Number of pixels in the y direction */ - int dataSize; /**< Size of a dataset */ + const int nPackets; /** Date: Wed, 11 Dec 2013 09:56:09 +0000 Subject: [PATCH 012/104] general funcs for pedestal subtraction, common mode, photon finding developed and implemented specifically for moench git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@12 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/MovingStat.h | 8 +- .../commonModeSubtraction.h | 53 ++++ slsDetectorCalibration/moench02ModuleData.h | 208 ++------------ slsDetectorCalibration/moenchCommonMode.h | 34 +++ slsDetectorCalibration/moenchReadData.C | 177 +++++------- slsDetectorCalibration/pedestalSubtraction.h | 24 ++ slsDetectorCalibration/singlePhotonDetector.h | 257 ++++++++++-------- slsDetectorCalibration/slsDetectorData.h | 20 +- 8 files changed, 363 insertions(+), 418 deletions(-) create mode 100644 slsDetectorCalibration/commonModeSubtraction.h create mode 100644 slsDetectorCalibration/moenchCommonMode.h create mode 100644 slsDetectorCalibration/pedestalSubtraction.h diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h index 9c8584d338..d856228ddb 100755 --- a/slsDetectorCalibration/MovingStat.h +++ b/slsDetectorCalibration/MovingStat.h @@ -7,11 +7,15 @@ class MovingStat { public: - MovingStat() : n(1000), m_n(0) {} + MovingStat(int nn=1000) : n(nn), m_n(0) {} void Clear() { - m_n = 0; + m_n = 0; + m_oldM=0; + m_newM=0; + m_oldM2=0; + m_newM2=0; } void SetN(int i) {n=i;}; diff --git a/slsDetectorCalibration/commonModeSubtraction.h b/slsDetectorCalibration/commonModeSubtraction.h new file mode 100644 index 0000000000..89984ed816 --- /dev/null +++ b/slsDetectorCalibration/commonModeSubtraction.h @@ -0,0 +1,53 @@ +#ifndef COMMONMODESUBTRACTION_H +#define COMMONMODESUBTRACTION_H + +#include "MovingStat.h" + +class commonModeSubtraction { + + public: + commonModeSubtraction(int nn=1000, int iroi=1) : cmStat(NULL), cmPed(NULL), nCm(NULL), nROI(iroi) {cmStat=new MovingStat[nROI]; for (int i=0; i0) cmStat[i].Calc(cmPed[i]/nCm[i]); + nCm[i]=0; + cmPed[i]=0; + }}; + + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + (void)ix; (void)iy; + cmPed[0]+=val; + nCm[0]++;}; + + virtual double getCommonMode(int ix=0, int iy=0) { + (void)ix; (void)iy; + if (nCm[0]>0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); + else return 0;}; + + + + + + protected: + MovingStat *cmStat; //stores the common mode average per supercolumn */ + double *cmPed; // stores the common mode for this frame per supercolumn */ + double *nCm; // stores the number of pedestals to calculate the cm per supercolumn */ + const int nROI; + + +}; + + + + + +#endif diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index 8a9a2d5790..1791c74e0f 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -33,38 +33,29 @@ class moench02ModuleData : public slsDetectorData { */ - moench02ModuleData(int nbg=1000): slsDetectorData(160, 160, 40, 1286), nSigma(5), buff(NULL), oldbuff(NULL), pedSub(1) { - int headerOff=0; - int footerOff=1284; - int dataOff=4; + moench02ModuleData(double c=0): slsDetectorData(160, 160, 40, 1286), xtalk(c) { - int ix, iy, ir, ic, i, isc, ip; - int **dMask; + + + uint16_t **dMask; int **dMap; + int ix, iy; - for (ir=0; ir<160; ir++) { - for (ic=0; ic<160; ic++) { - stat[ir][ic].Clear(); - stat[ir][ic].SetN(nbg); - } - } - dMask=new int*[160]; - for(i = 0; i < 160; i++) { - dMask[i] = new int[160]; - } + dMask=new uint16_t*[160]; dMap=new int*[160]; - for(i = 0; i < 160; i++) { + for (int i = 0; i < 160; i++) { dMap[i] = new int[160]; + dMask[i] = new uint16_t[160]; } - for (isc=0; isc<4; isc++) { - for (ip=0; ip<10; ip++) { + for (int isc=0; isc<4; isc++) { + for (int ip=0; ip<10; ip++) { - for (ir=0; ir<16; ir++) { - for (ic=0; ic<40; ic++) { + for (int ir=0; ir<16; ir++) { + for (int ic=0; ic<40; ic++) { ix=isc*40+ic; iy=ip*16+ir; @@ -88,9 +79,13 @@ class moench02ModuleData : public slsDetectorData { setDataMap(dMap); setDataMask(dMask); + + + + }; - ~moench02ModuleData() {if (buff) delete [] buff; if (oldbuff) delete [] oldbuff; }; + // ~moench02ModuleData() {if (buff) delete [] buff; if (oldbuff) delete [] oldbuff; }; int getPacketNumber(char *buff){ @@ -100,176 +95,27 @@ class moench02ModuleData : public slsDetectorData { return np; }; - - void calculateCommonMode(int xmin=0, int xmax=160, int ymin=0, int ymax=160, double hc=0, double tc=0) { - - int scmin=xmin/40; - int scmax=(xmax-1)/40+1; - int isc=0, ix, iy; - - for (isc=scmin; isc0) - 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 (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 { - /* if (ix==20 && iy==20) */ -/* cout << "No common mode!" << endl; */ - - return 0; - } - }; - - - - - void addToPedestal(double val, int ix, int iy){stat[iy][ix].Calc(val);}; - double getPedestal(int ix, int iy){return stat[iy][ix].Mean();}; - double getPedestalRMS(int ix, int iy){return stat[iy][ix].StandardDeviation();}; - double setNSigma(double n){if (n>0) nSigma=n; return nSigma;} - char *getBuff(){return buff;} - char *getOldBuff(){return oldbuff;} - - int setPedestalSubstraction(int i=-1){if (i>=0) pedSub=i; return pedSub;}; - - - double getChannelShort(int ix, int iy, double hc=0, double tc=0) { - - double val=slsDetectorData::getChannel(buff,ix,iy); - - if (ix>0 && hc!=0) - val-=hc*slsDetectorData::getChannel(buff,ix-1,iy); - - if (oldbuff && tc!=0) - val+=tc*slsDetectorData::getChannel(oldbuff,ix,iy); - - - return val; + double getValue(char *data, int ix, int iy=0) { + if (xtalk==0 || ix%40==0) + return (double)getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); }; - - - eventType getEventType(int ix, int iy, double hcorr=0, double tcorr=0, int sign=1, int cm=0) { - - /* PEDESTAL, */ -/* NEIGHBOUR, */ -/* PHOTON, */ -/* PHOTON_MAX, */ - /* NEGATIVE_PEDESTAL */ - eventType ret=PEDESTAL; - double tot=0, v, max=0, sig; - - - sig=getPedestalRMS(ix,iy); - - 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=sign*getChannelShort(ix+ic, iy+ir, hcorr, tcorr); - if (pedSub) - 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) { - max=v; - } - if (ir==0 && ic==0) { - if (v>nSigma*getPedestalRMS(ix,iy)) { - ret=PHOTON; - } else if (v<-nSigma*getPedestalRMS(ix,iy)) - ret=NEGATIVE_PEDESTAL; - } - } - } - } - - if (ret!=PHOTON && tot>3*nSigma*sig) - ret=NEIGHBOUR; - else if (ret==PHOTON) { - if (cluster[1][1]>=max) - ret=PHOTON_MAX; - } - - - cx=ix; - cy=iy; - - return ret; - - }; - - - double getClusterElement(int ic, int ir, int cmsub=0){return cluster[ic+1][ir+1];}; + double setXTalk(double c) {xtalk=c; return xtalk;} + double getXTalk() {return xtalk;} - double *getCluster(){return &cluster[0][0];}; - TTree *initMoenchTree(char *tname, Int_t *iframe, Int_t * x, Int_t* y, Double_t data[3][3], Double_t *ped, Double_t *sigma) { - TTree* tall=new TTree(tname,tname); - tall->Branch("iFrame",iframe,"iframe/I"); - tall->Branch("x",x,"x/I"); - tall->Branch("y",y,"y/I"); - tall->Branch("data",data,"data[3][3]/D"); - tall->Branch("pedestal",ped,"pedestal/D"); - tall->Branch("rms",sigma,"rms/D"); - return tall; - }; private: - MovingStat stat[160][160]; - double nSigma; - double cluster[3][3]; - char *buff; - char *oldbuff; - int pedSub; - int cmSub; - - MovingStat cmStat[4]; //stores the common mode average per supercolumn - double cmPed[4]; // stores the common mode for this frame per supercolumn - double nCm[4]; // stores the number of pedestals to calculate the cm per supercolumn - int cx, cy; + double xtalk; + + }; diff --git a/slsDetectorCalibration/moenchCommonMode.h b/slsDetectorCalibration/moenchCommonMode.h new file mode 100644 index 0000000000..9a3a45c858 --- /dev/null +++ b/slsDetectorCalibration/moenchCommonMode.h @@ -0,0 +1,34 @@ +#ifndef MOENCHCOMMONMODE_H +#define MOENCHCOMMONMODE_H + +#include "commonModeSubtraction.h" + +class moenchCommonMode : public commonModeSubtraction { + + public: + moenchCommonMode(int nn=1000) : commonModeSubtraction(nn,4){} ; + + + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + (void)iy; + int isc=ix/40; + if (isc>=0 && isc<4) { + cmPed[isc]+=val; + nCm[isc]++; + } + + }; + + virtual double getCommonMode(int ix=0, int iy=0) { + (void)iy; + int isc=ix/40; + if (isc>=0 && isc<4) { + if (nCm[isc]>0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); + } + return 0;}; + + +}; + + +#endif diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 468817e45e..09388fe4a0 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -15,6 +15,8 @@ //#include #include #include "moench02ModuleData.h" +#include "moenchCommonMode.h" +#include "singlePhotonDetector.h" //#include "MovingStat.h" @@ -51,13 +53,19 @@ using namespace std; */ -THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, double tc=0, int xmin=0, int xmax=NC, int ymin=0, int ymax=NR, int pedsub=1, int cmsub=0) { +THStack *moenchReadData(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=0, int xmax=NC, int ymin=0, int ymax=NR, int cmsub=0) { - moench02ModuleData *decoder=new moench02ModuleData(); + moench02ModuleData *decoder=new moench02ModuleData(hc); + moenchCommonMode *cmSub=NULL; + if (cmsub) + cmSub=new moenchCommonMode(); + + + + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); + char *buff; - char *oldbuff=NULL; char fname[10000]; - double oldval; int nf=0; eventType thisEvent=PEDESTAL; @@ -80,50 +88,39 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb 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 (pedsub) { - h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); - hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); - hs->Add(h2); - hs->Add(h3); - hs->Add(hetaX); - hs->Add(hetaY); - } + h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h2); + hs->Add(h3); + hs->Add(hetaX); + hs->Add(hetaY); - + ifstream filebin; int ix=20, iy=20, ir, ic; - Int_t iFrame, x, y; - Double_t data[3][3],ped,sigma; + Int_t iFrame; + TTree *tall=filter->initEventTree(tit, &iFrame); + - TTree *tall; - if (pedsub) { - cout << "Subtracting pedestal!!!! " << endl; - tall=decoder->initMoenchTree(tit, &iFrame, &x, &y, data, &ped, &sigma); - } double tot, tl, tr, bl, br, v; - int scmin=xmin/40, scmax=(xmax-1)/40+1; - - // 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); + TH2F *he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); he->SetStats(kFALSE); he->Draw("colz"); - he->SetMinimum(0); - he->SetMaximum(0.5*hmax); #endif + filter->newDataSet(); + for (int irun=runmin; irunreadNextFrame(filebin))) { + filter->newFrame(); - if (nf>100) { - if (cmsub) { - for (int isc=scmin; isccalculateCommonMode(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 + //calculate pedestals and common modes + if (cmsub) { + for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); } - } - } - + for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); - - if (nf>100) { - thisEvent= decoder->getEventType(ix, iy, hc, tc, 1,1); - } - +#ifdef MY_DEBUG + if (iev%10000==0) + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); +#endif - - - if (thisEvent==PEDESTAL) { - if (cmsub && nf>1000) - 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); - - - } - - - /*********************************************************** -Add here the function that you want to call: fill histos, make trees etc. - ************************************************************/ - // getClusterElement to access quickly the photon and the neighbours if (nf>1000) { tot=0; tl=0; tr=0; bl=0; br=0; - h1->Fill(decoder->getClusterElement(0,0), iy+NR*ix); + h1->Fill(filter->getClusterElement(0,0), iy+NR*ix); // if (nf%1000==0 && ix==20 && iy==20) cout << " val="<< decoder->getClusterElement(0,0)<< endl; if (thisEvent==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 + v=filter->getClusterElement(ic,ir); + // data[ic+1][ir+1]=v; + tot+=v; @@ -233,34 +198,34 @@ Add here the function that you want to call: fill histos, make trees etc. if (bl>br && bl>tl && bl>tr) { h2->Fill(bl, iy+NR*ix); if (bl>0) { - hetaX->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,-1,cmsub))/bl,iy+NR*ix); - hetaY->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(-1,0,cmsub))/bl,iy+NR*ix); - hetaX->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,-1,cmsub))/bl,iy+NR*(ix-1)); - hetaY->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(-1,0,cmsub))/bl,(iy-1)+NR*ix); + hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/bl,iy+NR*ix); + hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/bl,iy+NR*ix); + hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/bl,iy+NR*(ix-1)); + hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/bl,(iy-1)+NR*ix); } } else if (br>bl && br>tl && br>tr) { h2->Fill(br, iy+NR*ix); if (br>0) { - hetaX->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,-1,cmsub))/br,iy+NR*ix); - hetaY->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(1,0,cmsub))/br,iy+NR*ix); - hetaX->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,-1,cmsub))/br,iy+NR*(ix+1)); - hetaY->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(1,0,cmsub))/br,iy-1+NR*ix); + hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/br,iy+NR*ix); + hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/br,iy+NR*ix); + hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/br,iy+NR*(ix+1)); + hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/br,iy-1+NR*ix); } } else if (tl>br && tl>bl && tl>tr) { h2->Fill(tl, iy+NR*ix); if (tl>0) { - hetaX->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,1,cmsub))/tl,iy+NR*ix); - hetaY->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(-1,0,cmsub))/tl,iy+NR*ix); - hetaX->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,1,cmsub))/tl,iy+NR*(ix-1)); - hetaY->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(-1,0,cmsub))/tl,iy+1+NR*ix); + hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tl,iy+NR*ix); + hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/tl,iy+NR*ix); + hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tl,iy+NR*(ix-1)); + hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/tl,iy+1+NR*ix); } } else if (tr>bl && tr>tl && tr>br) { h2->Fill(tr, iy+NR*ix); if (tr>0) { - hetaX->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,1,cmsub))/tr,iy+NR*ix); - hetaY->Fill((decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(1,0,cmsub))/tr,iy+NR*ix); - hetaX->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(0,1,cmsub))/tr,iy+NR*(ix+1)); - hetaY->Fill(1.-(decoder->getClusterElement(0,0,cmsub)+decoder->getClusterElement(1,0,cmsub))/tr,iy+1+NR*ix); + hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tr,iy+NR*ix); + hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/tr,iy+NR*ix); + hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tr,iy+NR*(ix+1)); + hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/tr,iy+1+NR*ix); } @@ -269,10 +234,6 @@ Add here the function that you want to call: fill histos, make trees etc. h3->Fill(tot, iy+NR*ix); iFrame=decoder->getFrameNumber(buff); - ped=decoder->getPedestal(ix,iy); - sigma=decoder->getPedestalRMS(ix,iy); - x=ix; - y=iy; tall->Fill(); @@ -290,29 +251,25 @@ Add here the function that you want to call: fill histos, make trees etc. } - } else { - //cout << ix << " " << iy << endl; - h1->Fill(decoder->getChannelShort(ix, iy), iy+NR*ix); - } + } ////////////////////////////////////////////////////////// - } + cout << "=" ; nf++; - } + } cout << endl; if (filebin.is_open()) filebin.close(); else cout << "could not open file " << fname << endl; - } - if (pedsub) - tall->Write(tall->GetName(),TObject::kOverwrite); - + } + tall->Write(tall->GetName(),TObject::kOverwrite); + delete decoder; cout << "Read " << nf << " frames" << endl; return hs; - } +} diff --git a/slsDetectorCalibration/pedestalSubtraction.h b/slsDetectorCalibration/pedestalSubtraction.h new file mode 100644 index 0000000000..f80991ec0e --- /dev/null +++ b/slsDetectorCalibration/pedestalSubtraction.h @@ -0,0 +1,24 @@ +#ifndef PEDESTALSUBTRACTION_H +#define PEDESTALSUBTRACTION_H + +#include "MovingStat.h" + +class pedestalSubtraction { + + public: + pedestalSubtraction (int nn=1000) : stat(nn) {}; + virtual ~pedestalSubtraction() {}; + + virtual void Clear() {stat.Clear();} + virtual void addToPedestal(double val){ stat.Calc(val);}; + virtual double getPedestal(){return stat.Mean();}; + virtual double getPedestalRMS(){return stat.StandardDeviation();}; + virtual int SetNPedestals(int i=-1) {if (i>0) stat.SetN(i); return stat.GetN();}; + + + + private: + MovingStat stat; + +}; +#endif diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 2c226a69e5..8868969719 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -1,9 +1,22 @@ #ifndef SINGLEPHOTONDETECTOR_H #define SINGLEPHOTONDETECTOR_H + + +#include #include "slsDetectorData.h" -#include "MovingStat.h" #include "single_photon_hit.h" +#include "pedestalSubtraction.h" +#include "commonModeSubtraction.h" + + +#define MYROOT1 + +#ifdef MYROOT1 +#include + +#endif + #include @@ -11,11 +24,12 @@ using namespace std; enum eventType { - PEDESTAL, - NEIGHBOUR, - PHOTON, - PHOTON_MAX, - NEGATIVE_PEDESTAL, + PEDESTAL=0, + NEIGHBOUR=1, + PHOTON=2, + PHOTON_MAX=3, + NEGATIVE_PEDESTAL=4, + UNDEFINED=-1 }; @@ -40,7 +54,13 @@ class singlePhotonDetector { */ - singlePhotonDetector(slsDetectorData *d, int csize=3, double nsigma=5) : det(d), clusterSize(csize), clusterSizeY(csize),nSigma(nsigma) { + singlePhotonDetector(slsDetectorData *d, + int csize=3, + double nsigma=5, + int sign=1, + commonModeSubtraction *cm=NULL, + int nped=1000, + int nd=100) : det(d), nx(0), ny(0), stat(NULL), cmSub(cm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), cluster(NULL), iframe(-1), dataSign(sign) { @@ -48,9 +68,13 @@ class singlePhotonDetector { - stat=new MovingStat*[ny]; - for (int i=0; iSetNPedestals(nped); + eventMask[i]=new eventType[nx]; + } if (ny==1) clusterSizeY=1; @@ -59,13 +83,24 @@ class singlePhotonDetector { }; - ~singlePhotonDetector() {delete cluster; delete [] stat;}; - + virtual ~singlePhotonDetector() {delete cluster; for (int i=0; iClear(); }; + void newFrame(){iframe++; for (int iy=0; iynewFrame();}; + + + commonModeSubtraction setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;}; + + int setDataSign(int sign=0) {if (sign==1 || sign==-1) dataSign=sign; return dataSign;}; + virtual void addToPedestal(double val, int ix, int iy){ if (ix>=0 && ix=0 && iyisGood(ix, iy) ) cmSub->addToCommonMode(val, ix, iy);}}; - void addToPedestal(double val, int ix, int iy){ if (ix>=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy0) return stat[iy][ix].getPedestal()-cmSub->getCommonMode(); else return stat[iy][ix].getPedestal(); else return -1;}; + + + double getPedestalRMS(int ix, int iy){if (ix>=0 && ix=0 && iy0) nSigma=n; return nSigma;} @@ -85,49 +120,74 @@ class singlePhotonDetector { - eventType getEventType(char *data, int ix, int iy, double hcorr=0, double tcorr=0, int sign=1, int cm=0) { + eventType getEventType(char *data, int ix, int iy, int cm=0) { - eventType ret=PEDESTAL; - double tot=0, v, max=0, sig; + // eventType ret=PEDESTAL; + double tot=0, max=0; + + if (iframegetValue(data, ix, iy),ix,iy); + return UNDEFINED; + } - - sig=getPedestalRMS(ix,iy); - - cluster->x=ix; - cluster->y=iy; - cluster->rms=sig; - cluster->ped=getPedestal(ix,iy); - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { - if ((iy+ir)>=0 && (iy+ir)<160 && (ix+ic)>=0 && (ix+ic)<160) { - v=sign*(det->getValue(data, ix+ic, iy+ir)-getPedestal(ix+ic,iy+ir)); - // if (cm) - // v-=sign*getCommonMode(ix+ic, iy+ic); - cluster->set_data(ic, ir, v); - tot+=v; - if (v>max) { - max=v; + if (eventMask[iy][ix]==UNDEFINED) { + + eventMask[iy][ix]=PEDESTAL; + + + cluster->x=ix; + cluster->y=iy; + cluster->rms=getPedestalRMS(ix,iy); + cluster->ped=getPedestal(ix,iy, cm); + + + for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { + for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { + if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(dataSign*(det->getValue(data, ix+ic, iy+ir)-getPedestal(ix+ic,iy+ir,cm)), ic, ir ); + tot+=cluster->get_data(ic,ir); + if (cluster->get_data(ic,ir)>max) { + max=cluster->get_data(ic,ir); + } + if (ir==0 && ic==0) { + if (cluster->get_data(ic,ir)>nSigma*cluster->rms) { + eventMask[iy][ix]=PHOTON; + } else if (cluster->get_data(ic,ir)<-nSigma*cluster->rms) + eventMask[iy][ix]=NEGATIVE_PEDESTAL; + } } - if (ir==0 && ic==0) { - if (v>nSigma*getPedestalRMS(ix,iy)) { - ret=PHOTON; - } else if (v<-nSigma*getPedestalRMS(ix,iy)) - ret=NEGATIVE_PEDESTAL; + } + } + + if (eventMask[iy][ix]!=PHOTON && tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms) { + eventMask[iy][ix]=NEIGHBOUR; + + } else if (eventMask[iy][ix]==PHOTON) { + if (cluster->get_data(0,0)>=max) { + for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { + for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { + + if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)getValue(data, ix, iy),ix,iy); } } - - if (ret!=PHOTON && tot>3*nSigma*sig) - ret=NEIGHBOUR; - else if (ret==PHOTON) { - if (cluster->get_data(0,0)>=max) - ret=PHOTON_MAX; - } - - return ret; + + return eventMask[iy][ix]; }; @@ -135,10 +195,31 @@ class singlePhotonDetector { + int SetNPedestals(int i=-1) {int ix=0, iy=0; if (i>0) for (ix=0; ixget_data(ic,ir);}; + eventType getEventMask(int ic, int ir){return eventMask[ir][ic];}; + +#ifdef MYROOT1 + TTree *initEventTree(char *tname, int *iFrame=NULL) { + TTree* tall=new TTree(tname,tname); + + if (iFrame) + tall->Branch("iFrame",iFrame,"iframe/I"); + else + tall->Branch("iFrame",&(cluster->iframe),"iframe/I"); + + tall->Branch("x",&(cluster->x),"x/I"); + tall->Branch("y",&(cluster->y),"y/I"); + char tit[100]; + sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY); + tall->Branch("data",cluster->data,tit); + tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); + tall->Branch("rms",&(cluster->rms),"rms/D"); + return tall; + }; +#endif - double getClusterElement(int ic, int ir, int cmsub=0){return cluster->get_data(ic,ir);}; - private: @@ -146,80 +227,22 @@ class singlePhotonDetector { int nx, ny; - - MovingStat **stat; + pedestalSubtraction **stat; + commonModeSubtraction *cmSub; + //MovingStat **stat; + int nDark; + eventType **eventMask; double nSigma; int clusterSize, clusterSizeY; single_photon_hit *cluster; + int iframe; + int dataSign; - MovingStat cmStat[4]; //stores the common mode average per supercolumn - double cmPed[4]; // stores the common mode for this frame per supercolumn - double nCm[4]; // stores the number of pedestals to calculate the cm per supercolumn - int cx, cy; + /* int cx, cy; */ }; - - - /////////////////////////////////////////////////////// DONE UNTIL HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - /* void calculateCommonMode(int xmin=0, int xmax=160, int ymin=0, int ymax=160, double hc=0, double tc=0) { */ - -/* int scmin=xmin/40; */ -/* int scmax=(xmax-1)/40+1; */ -/* int isc=0, ix, iy; */ - -/* for (isc=scmin; isc0) */ -/* 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 (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 { */ -/* /\* if (ix==20 && iy==20) *\/ */ -/* /\* cout << "No common mode!" << endl; *\/ */ - -/* return 0; */ -/* } */ -/* }; */ - - - #endif diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 527e4e9bb1..59bd872f00 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -24,13 +24,13 @@ class slsDetectorData { */ - slsDetectorData(int npx, int npy, int np, int psize, int **dMap=NULL, int **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), nPackets(np), packetSize(psize) { + slsDetectorData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), nPackets(np), packetSize(psize) { - dataMask=new int*[ny]; + dataMask=new dataType*[ny]; for(int i = 0; i < ny; i++) { - dataMask[i] = new int[nx]; + dataMask[i] = new dataType[nx]; } dataMap=new int*[ny]; for(int i = 0; i < ny; i++) { @@ -74,7 +74,7 @@ class slsDetectorData { }; - void setDataMask(int **dMask=NULL){ + void setDataMask(dataType **dMask=NULL){ if (dMask!=NULL) { @@ -102,9 +102,9 @@ class slsDetectorData { }; - int setGood(int ix, int iy, int i=1) {dataROIMask[iy][ix]=i; return isGood(ix,iy);}; + int setGood(int ix, int iy, int i=1) { if (ix>=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && dataMap[iy][ix] Date: Thu, 12 Dec 2013 16:05:24 +0000 Subject: [PATCH 013/104] some doxy comments added git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@13 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/MovingStat.h | 97 +++++--- .../commonModeSubtraction.h | 46 ++-- slsDetectorCalibration/moench02ModuleData.h | 60 +++-- slsDetectorCalibration/moenchCommonMode.h | 37 +-- slsDetectorCalibration/pedestalSubtraction.h | 28 ++- slsDetectorCalibration/singlePhotonDetector.h | 139 ++++++++--- slsDetectorCalibration/single_photon_hit.h | 66 ++++-- slsDetectorCalibration/slsDetectorData.h | 217 +++++++++--------- slsDetectorCalibration/slsReceiverData.h | 165 +++++++++++++ 9 files changed, 598 insertions(+), 257 deletions(-) create mode 100644 slsDetectorCalibration/slsReceiverData.h diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h index d856228ddb..00d692cc0f 100755 --- a/slsDetectorCalibration/MovingStat.h +++ b/slsDetectorCalibration/MovingStat.h @@ -6,43 +6,60 @@ class MovingStat { + + /** @short approximated moving average structure */ public: + + + /** constructor + \param nn number of samples parameter to be used + */ MovingStat(int nn=1000) : n(nn), m_n(0) {} + /** + clears the moving average number of samples parameter, mean and standard deviation + */ void Clear() { m_n = 0; - m_oldM=0; m_newM=0; - m_oldM2=0; m_newM2=0; } - void SetN(int i) {n=i;}; + + /** sets number of samples parameter + \param i number of samples parameter to be set + */ + + void SetN(int i) {if (i>=1) n=i;}; + + /** + gets number of samples parameter + \returns actual number of samples parameter + */ int GetN() {return n;}; + + /** calculates the moving average i.e. adds if number of elements is lower than number of samples parameter, pushes otherwise + \param x value to calculate the moving average + */ inline void Calc(double x) { if (m_n 0) ? m_newM/m_n : 0.0; } + + /** returns the squared mean, 0 if no elements are inside + \returns returns the squared average + */ double M2() const { return ( (m_n > 1) ? m_newM2/m_n : 0.0 ); } + /** returns the variance, 0 if no elements are inside + \returns returns the variance + */ inline double Variance() const { return ( (m_n > 1) ? (M2()-Mean()*Mean()) : 0.0 ); } + /** returns the standard deviation, 0 if no elements are inside + \returns returns the standard deviation + */ inline double StandardDeviation() const { return ( (Variance() > 0) ? sqrt( Variance() ) : -1 ); } private: - int n; - int m_n; - double m_oldM, m_newM, m_oldM2, m_newM2; + int n; /**< number of samples parameter */ + int m_n; /**< current number of elements */ + double m_newM; /**< accumulated average */ + double m_newM2; /**< accumulated squared average */ }; #endif diff --git a/slsDetectorCalibration/commonModeSubtraction.h b/slsDetectorCalibration/commonModeSubtraction.h index 89984ed816..4029e99b5a 100644 --- a/slsDetectorCalibration/commonModeSubtraction.h +++ b/slsDetectorCalibration/commonModeSubtraction.h @@ -5,10 +5,22 @@ class commonModeSubtraction { + /** @short class to calculate the common mode of the pedestals based on an approximated moving average*/ + public: + + /** constructor + \param nn number of samples for the moving average to calculate the average common mode + \param iroi number of regions on which one can calculate the common mode separately. Defaults to 1 i.e. whole detector + + */ commonModeSubtraction(int nn=1000, int iroi=1) : cmStat(NULL), cmPed(NULL), nCm(NULL), nROI(iroi) {cmStat=new MovingStat[nROI]; for (int i=0; i0) cmStat[i].Calc(cmPed[i]/nCm[i]); @@ -23,25 +36,32 @@ class commonModeSubtraction { cmPed[i]=0; }}; - virtual void addToCommonMode(double val, int ix=0, int iy=0) { - (void)ix; (void)iy; - cmPed[0]+=val; - nCm[0]++;}; - - virtual double getCommonMode(int ix=0, int iy=0) { - (void)ix; (void)iy; - if (nCm[0]>0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); - else return 0;}; + /** adds the pixel to the sum of pedestals -- virtual func + \param isc region of interest index + */ + virtual void addToCommonMode(double val, int isc=0) { + if (isc>=0 && isc=0 && isc0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); + return 0;}; protected: - MovingStat *cmStat; //stores the common mode average per supercolumn */ - double *cmPed; // stores the common mode for this frame per supercolumn */ - double *nCm; // stores the number of pedestals to calculate the cm per supercolumn */ - const int nROI; + MovingStat *cmStat; /** -#include -#include -using namespace std; - - - -class moench02ModuleData : public slsDetectorData { +class moench02ModuleData : public slsReceiverData { public: /** - - Constructor (no error checking if datasize and offsets are compatible!) - \param npx number of pixels in the x direction - \param npy number of pixels in the y direction - \param ds size of the dataset - \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) - \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) - + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer */ - moench02ModuleData(double c=0): slsDetectorData(160, 160, 40, 1286), xtalk(c) { + moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), xtalk(c) { @@ -60,7 +45,7 @@ class moench02ModuleData : public slsDetectorData { ix=isc*40+ic; iy=ip*16+ir; - dMap[iy][ix]=1286*(isc*10+ip)+2*ir*40+2*ic; + dMap[iy][ix]=1286*(isc*10+ip)+2*ir*40+2*ic+4; // cout << ix << " " << iy << " " << dMap[ix][iy] << endl; } } @@ -85,9 +70,15 @@ class moench02ModuleData : public slsDetectorData { }; - // ~moench02ModuleData() {if (buff) delete [] buff; if (oldbuff) delete [] oldbuff; }; + + /** + gets the packets number (last packet is labelled with 0 and is replaced with 40) + \param buff pointer to the memory + \returns packet number + */ + int getPacketNumber(char *buff){ int np=(*(int*)buff)&0xff; if (np==0) @@ -95,6 +86,15 @@ class moench02ModuleData : public slsDetectorData { return np; }; + + /** + returns the pixel value as double correcting for the output buffer crosstalk + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns channel value as double + + */ double getValue(char *data, int ix, int iy=0) { if (xtalk==0 || ix%40==0) return (double)getValue(data, ix, iy); @@ -102,7 +102,19 @@ class moench02ModuleData : public slsDetectorData { return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); }; + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ double getXTalk() {return xtalk;} @@ -113,7 +125,7 @@ class moench02ModuleData : public slsDetectorData { private: - double xtalk; + double xtalk; /**=0 && isc<4) { - cmPed[isc]+=val; - nCm[isc]++; - } - + (void) iy; + commonModeSubtraction::addToCommonMode(val, ix/40); }; - + /**returns common mode value as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each; + \param ix pixel coordinate in the x direction + \param iy pixel coordinate in the y direction + \returns common mode value + */ virtual double getCommonMode(int ix=0, int iy=0) { - (void)iy; - int isc=ix/40; - if (isc>=0 && isc<4) { - if (nCm[isc]>0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); - } - return 0;}; - + (void) iy; + return commonModeSubtraction::getCommonMode(ix/40); + }; }; diff --git a/slsDetectorCalibration/pedestalSubtraction.h b/slsDetectorCalibration/pedestalSubtraction.h index f80991ec0e..29bc986284 100644 --- a/slsDetectorCalibration/pedestalSubtraction.h +++ b/slsDetectorCalibration/pedestalSubtraction.h @@ -4,21 +4,45 @@ #include "MovingStat.h" class pedestalSubtraction { - + /** @short class defining the pedestal subtraction based on an approximated moving average */ public: + /** constructor + \param nn number of samples to calculate the moving average (defaults to 1000) + */ pedestalSubtraction (int nn=1000) : stat(nn) {}; + + /** virtual destructorr + */ virtual ~pedestalSubtraction() {}; + /** clears the moving average */ virtual void Clear() {stat.Clear();} + + /** adds the element to the moving average + \param val value to be added + */ virtual void addToPedestal(double val){ stat.Calc(val);}; + + /** returns the average value of the pedestal + \returns mean of the moving average + */ virtual double getPedestal(){return stat.Mean();}; + + /** returns the standard deviation of the moving average + \returns standard deviation of the moving average + */ virtual double getPedestalRMS(){return stat.StandardDeviation();}; + + /**sets/gets the number of samples for the moving average + \param i number of elements for the moving average. If -1 (default) or negative, gets. + \returns actual number of samples for the moving average + */ virtual int SetNPedestals(int i=-1) {if (i>0) stat.SetN(i); return stat.GetN();}; private: - MovingStat stat; + MovingStat stat; /**< approximated moving average struct */ }; #endif diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 8868969719..78c6e1ea29 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -2,7 +2,6 @@ #define SINGLEPHOTONDETECTOR_H -#include #include "slsDetectorData.h" #include "single_photon_hit.h" @@ -37,6 +36,7 @@ using namespace std; template class singlePhotonDetector { + /** @short class to perform pedestal subtraction etc. and find single photon clusters for an analog detector */ public: @@ -44,11 +44,12 @@ class singlePhotonDetector { /** Constructor (no error checking if datasize and offsets are compatible!) - \param npx number of pixels in the x direction - \param npy number of pixels in the y direction - \param ds size of the dataset - \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) - \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param s detector data structure to be used + \param csize cluster size (should be an odd number). Defaults to 3 + \param nsigma number of rms to discriminate from the noise. Defaults to 5 + \param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none + \param nped number of samples for pedestal averaging + \param nd number of dark frames to average as pedestals without photon discrimination at the beginning of the measurement */ @@ -63,7 +64,6 @@ class singlePhotonDetector { int nd=100) : det(d), nx(0), ny(0), stat(NULL), cmSub(cm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), cluster(NULL), iframe(-1), dataSign(sign) { - det->getDetectorSize(nx,ny); @@ -80,39 +80,80 @@ class singlePhotonDetector { clusterSizeY=1; cluster=new single_photon_hit(clusterSize,clusterSizeY); + setClusterSize(csize); }; - + /** + destructor. Deletes the cluster structure and the pdestalSubtraction array + */ virtual ~singlePhotonDetector() {delete cluster; for (int i=0; iClear(); }; + + /** resets the eventMask to undefined and the commonModeSubtraction */ void newFrame(){iframe++; for (int iy=0; iynewFrame();}; + /** sets the commonModeSubtraction algorithm to be used + \param cm commonModeSubtraction algorithm to be used (NULL unsets) + \returns pointer to the actual common mode subtraction algorithm + */ commonModeSubtraction setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;}; + + /** + sets the sign of the data + \param sign 1 means positive values for photons, -1 negative, 0 gets + \returns current sign for the data + */ int setDataSign(int sign=0) {if (sign==1 || sign==-1) dataSign=sign; return dataSign;}; + + /** + adds value to pedestal (and common mode) for the given pixel + \param val value to be added + \param ix pixel x coordinate + \param iy pixel y coordinate + */ virtual void addToPedestal(double val, int ix, int iy){ if (ix>=0 && ix=0 && iyisGood(ix, iy) ) cmSub->addToCommonMode(val, ix, iy);}}; - + /** + gets pedestal (and common mode) + \param ix pixel x coordinate + \param iy pixel y coordinate + \param cm 0 (default) without common mode subtraction, 1 with common mode subtraction (if defined) + */ virtual double getPedestal(int ix, int iy, int cm=0){if (ix>=0 && ix=0 && iy0) return stat[iy][ix].getPedestal()-cmSub->getCommonMode(); else return stat[iy][ix].getPedestal(); else return -1;}; - + /** + gets pedestal rms (i.e. noise) + \param ix pixel x coordinate + \param iy pixel y coordinate + */ double getPedestalRMS(int ix, int iy){if (ix>=0 && ix=0 && iy0) nSigma=n; return nSigma;} - + + /** sets/gets cluster size + \param n cluster size to be set, (0 or negative gets). If even is incremented by 1. + \returns actual cluster size + */ int setClusterSize(int n=-1){ if (n>0 && n!=clusterSize) { if (n%2==0) n+=1; clusterSize=n; - delete cluster; + if (cluster) + delete cluster; if (ny>1) clusterSizeY=clusterSize; - cluster=new single_photon_hit(clusterSize,clusterSizeY); } return clusterSize; @@ -120,6 +161,17 @@ class singlePhotonDetector { + + /** finds event type for pixel and fills cluster structure. The algorithm loops only if the evenMask for this pixel is still undefined. + if pixel or cluster around it are above threshold (nsigma*pedestalRMS) cluster is filled and pixel mask is PHOTON_MAX (if maximum in cluster) or NEIGHBOUR; If PHOTON_MAX, the elements of the cluster are also set as NEIGHBOURs in order to speed up the looping + if below threshold the pixel is either marked as PEDESTAL (and added to the pedestal calculator) or NEGATIVE_PEDESTAL is case it's lower than -threshold, otherwise the pedestal average would drift to negative values while it should be 0. + + /param data pointer to the data + /param ix pixel x coordinate + /param iy pixel y coordinate + /param cm enable(1)/disable(0) common mode subtraction (if defined). + /returns event type for the given pixel + */ eventType getEventType(char *data, int ix, int iy, int cm=0) { // eventType ret=PEDESTAL; @@ -194,13 +246,32 @@ class singlePhotonDetector { - + /** sets/gets number of samples for moving average pedestal calculation + \param i number of samples to be set (0 or negative gets) + \returns actual number of samples + */ int SetNPedestals(int i=-1) {int ix=0, iy=0; if (i>0) for (ix=0; ixget_data(ic,ir);}; - eventType getEventMask(int ic, int ir){return eventMask[ir][ic];}; + /** returns value for cluster element in relative coordinates + \param ic x coordinate (center is (0,0)) + \param ir y coordinate (center is (0,0)) + \returns cluster element + */ + double getClusterElement(int ic, int ir=0){return cluster->get_data(ic,ir);}; + + /** returns event mask for the given pixel + \param ic x coordinate (center is (0,0)) + \param ir y coordinate (center is (0,0)) + \returns event mask enum for the given pixel + */ + eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];}; -#ifdef MYROOT1 +#ifdef MYROOT1 + /** generates a tree and maps the branches + \param tname name for the tree + \param iframe pointer to the frame number + \returns returns pointer to the TTree + */ TTree *initEventTree(char *tname, int *iFrame=NULL) { TTree* tall=new TTree(tname,tname); @@ -223,22 +294,22 @@ class singlePhotonDetector { private: - slsDetectorData *det; - int nx, ny; - - - pedestalSubtraction **stat; - commonModeSubtraction *cmSub; - //MovingStat **stat; - int nDark; - eventType **eventMask; - double nSigma; - int clusterSize, clusterSizeY; - single_photon_hit *cluster; - int iframe; - int dataSign; - - /* int cx, cy; */ + slsDetectorData *det; /**< slsDetectorData to be used */ + int nx; /**< Size of the detector in x direction */ + int ny; /**< Size of the detector in y direction */ + + + pedestalSubtraction **stat; /**< pedestalSubtraction class */ + commonModeSubtraction *cmSub;/**< commonModeSubtraction class */ + int nDark; /**< number of frames to be used at the beginning of the dataset to calculate pedestal without applying photon discrimination */ + eventType **eventMask; /**< matrix of event type or each pixel */ + double nSigma; /**< number of sigma parameter for photon discrimination */ + int clusterSize; /**< cluster size in the x direction */ + int clusterSizeY; /**< cluster size in the y direction i.e. 1 for strips, clusterSize for pixels */ + single_photon_hit *cluster; /**< single photon hit data structure */ + int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */ + int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */ + }; diff --git a/slsDetectorCalibration/single_photon_hit.h b/slsDetectorCalibration/single_photon_hit.h index 278c9f691d..dda4d75714 100644 --- a/slsDetectorCalibration/single_photon_hit.h +++ b/slsDetectorCalibration/single_photon_hit.h @@ -5,38 +5,56 @@ typedef double double32_t; typedef float float32_t; typedef int int32_t; -/* /\** */ -/* @short structure for a single photon hit */ -/* *\/ */ -/* typedef struct{ */ -/* double* data; /\**< data size *\/ */ -/* int x; /\**< x-coordinate of the center of hit *\/ */ -/* int y; /\**< x-coordinate of the center of hit *\/ */ -/* double rms; /\**< noise of central pixel *\/ */ -/* double ped; /\**< pedestal of the central pixel *\/ */ -/* int iframe; /\**< frame number *\/ */ -/* }single_photon_hit; */ - class single_photon_hit { - public: + /** @short Structure for a single photon hit */ + + public: + /** constructor, instantiates the data array -- all class elements are public! + \param nx cluster size in x direction + \param ny cluster size in y direction (defaults to 1 for 1D detectors) + */ single_photon_hit(int nx, int ny=1): dx(nx), dy(ny) {data=new double[dx*dy];}; - ~single_photon_hit(){delete [] data;}; - void write(FILE *myFile) {fwrite((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);}; + + ~single_photon_hit(){delete [] data;}; /**< destructor, deletes the data array */ + + /** binary write to file of all elements of the structure, except size of the cluster + \param myFile file descriptor + */ + void write(FILE *myFile) {fwrite((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);}; + + /** + binary read from file of all elements of the structure, except size of the cluster. The structure is then filled with those args + \param myFile file descriptor + */ void read(FILE *myFile) {fread((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fread((void*)data, 1, dx*dy*sizeof(double), myFile);}; + + /** + assign the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0) + \param v value to be set + \param ix coordinate x within the cluster (center is (0,0)) + \param iy coordinate y within the cluster (center is (0,0)) + */ void set_data(double v, int ix, int iy=0){data[(iy+dy/2)*dx+ix+dx/2]=v;}; - double get_data(int ix, int iy=0){return data[(iy+dy/2)*dx+ix+dx/2];}; + + /** + gets the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0) + \param ix coordinate 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];}; - int x; /**< x-coordinate of the center of hit */ - int y; /**< x-coordinate of the center of hit */ - double rms; /**< noise of central pixel */ - double ped; /**< pedestal of the central pixel */ - int iframe; /**< frame number */ - double *data; /**< data size */ - const int dx; - const int dy; + int x; /**< x-coordinate of the center of hit */ + int y; /**< x-coordinate of the center of hit */ + double rms; /**< noise of central pixel l -- at some point it can be removed*/ + double ped; /**< pedestal of the central pixel -- at some point it can be removed*/ + int iframe; /**< frame number */ + double *data; /**< pointer to data */ + const int dx; /**< size of data cluster in x */ + const int dy; /**< size of data cluster in y */ }; diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 59bd872f00..c28e447aab 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -1,6 +1,7 @@ #ifndef SLSDETECTORDATA_H #define SLSDETECTORDATA_H +#include #include #include @@ -15,16 +16,19 @@ class slsDetectorData { /** - Constructor (no error checking if datasize and offsets are compatible!) - \param npx number of pixels in the x direction - \param npy number of pixels in the y direction - \param ds size of the dataset - \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) - \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + General slsDetectors data structure. Works for data acquired using the slsDetectorReceiver. Can be generalized to other detectors (many virtual funcs). + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param dsize size of the data + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. */ - slsDetectorData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), nPackets(np), packetSize(psize) { + slsDetectorData(int npx, int npy, int dsize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), dataSize(dsize) { @@ -59,13 +63,20 @@ class slsDetectorData { delete [] dataROIMask; } + /** + defines the data map (as offset) - no error checking if datasize and offsets are compatible! + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset). If NULL (default),the data are arranged as if read out row by row (dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);) + + */ + + void setDataMap(int **dMap=NULL) { if (dMap==NULL) { for (int iy=0; iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && dataMap[iy][ix]=0 && ix=0 && iy=0 && dataMap[iy][ix]>8;}; - virtual int getPacketNumber(char *buff) {return (*(int*)buff)&0xff;}; - - - virtual char *findNextFrame(char *data, int &npackets, int dsize) { - char *retval=NULL, *p=data; - int dd=0; - int fn, fnum=-1, np=0, pnum=-1; - while (dd<=(dsize-packetSize)) { - pnum=getPacketNumber(p); - fn=getFrameNumber(p); - if (pnum<0 || pnum>=nPackets) { - cout << "Bad packet number " << pnum << " frame "<< fn << endl; - retval=NULL; - continue; - } - if (pnum==1) { - fnum=fn; - retval=p; - if (np>0) - cout << "*Incomplete frame number " << fnum << endl; - np=0; - } else if (fn!=fnum) { - if (fnum!=-1) { - cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl; - retval=NULL; - } - np=0; - } - p+=packetSize; - dd+=packetSize; - np++; - if (np==nPackets) - if (pnum==nPackets) - break; - else { - cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; - retval=NULL; - } - } - if (np<40) { - if (np>0) - cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; - } - - npackets=np; - - return retval; - }; + Returns the frame number for the given dataset. Purely virtual func. + \param buff pointer to the dataset + \returns frame number + */ - virtual char *readNextFrame(ifstream &filebin) { - -/* if (oldbuff) */ -/* delete [] oldbuff; */ + virtual int getFrameNumber(char *buff)=0; -/* oldbuff=buff; */ - - // char *p=new char[1286]; - char *data=new char[packetSize*nPackets]; - char *retval=0; - int np=40; - - if (filebin.is_open()) { - while (filebin.read(data+np*packetSize,packetSize)) { - - if (np==nPackets) { - - retval=findNextFrame(data,np,packetSize*nPackets); - if (retval==data && np==nPackets) - return data; - else if (np>nPackets) { - cout << "too many packets!!!!!!!!!!" << endl; - delete [] data; - return NULL; - } else { - for (int ip=0; ipnPackets) { - cout << "*******too many packets!!!!!!!!!!" << endl; - delete [] data; - return NULL; - } else { - // memcpy(data+np*1286,p,1286); - np++; - } - - } - } - delete [] data; - return NULL; - }; + /** + + Returns the packet number for the given dataset. purely virtual func + \param buff pointer to the dataset + \returns packet number number + + */ + + virtual int getPacketNumber(char *buff)=0; + + + /** + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func + \param data pointer to the memory to be analyzed + \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot + \param dsize size of the memory slot to be analyzed + \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found + + */ + virtual char *findNextFrame(char *data, int &ndata, int dsize)=0; + + + /** + + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete + + */ + virtual char *readNextFrame(ifstream &filebin)=0; - private: + protected: const int nx; /**< Number of pixels in the x direction */ const int ny; /**< Number of pixels in the y direction */ - const int nPackets; /** +class slsReceiverData : public slsDetectorData { + + + public: + + /** + + + slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. + Inherits and implements slsDetectorData. + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param np number of packets + \param psize packets size + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. + + */ + slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; + + + + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + \param buff pointer to the dataset + \returns frame number + + */ + + virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; + + /** + + Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. + \param buff pointer to the dataset + \returns packet number number + + */ + + virtual int getPacketNumber(char *buff) {return (*(int*)buff)&0xff;}; + + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param data pointer to the memory to be analyzed + \param ndata + \param dsize size of the memory slot to be analyzed + \returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found + + */ + + virtual char *findNextFrame(char *data, int &npackets, int dsize) { + char *retval=NULL, *p=data; + int dd=0; + int fn, fnum=-1, np=0, pnum=-1; + while (dd<=(dsize-packetSize)) { + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + if (pnum<0 || pnum>=nPackets) { + cout << "Bad packet number " << pnum << " frame "<< fn << endl; + retval=NULL; + continue; + } + if (pnum==1) { + fnum=fn; + retval=p; + if (np>0) + cout << "*Incomplete frame number " << fnum << endl; + np=0; + } else if (fn!=fnum) { + if (fnum!=-1) { + cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl; + retval=NULL; + } + np=0; + } + p+=packetSize; + dd+=packetSize; + np++; + if (np==nPackets) + if (pnum==nPackets) + break; + else { + cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; + retval=NULL; + } + } + if (np<40) { + if (np>0) + cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; + } + + npackets=np*packetSize; + + return retval; + }; + + /** + + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete + + */ + + virtual char *readNextFrame(ifstream &filebin) { + char *data=new char[packetSize*nPackets]; + char *retval=0; + int np=0, nd; + + if (filebin.is_open()) { + while (filebin.read(data+np*packetSize,packetSize)) { + + if (np==(nPackets-1)) { + + retval=findNextFrame(data,nd,packetSize*nPackets); + np=nd/packetSize; + + if (retval==data && np==nPackets) + return data; + else if (np>nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + for (int ip=0; ipnPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + np++; + } + } + } + delete [] data; + return NULL; + }; + + + + private: + const int nPackets; /** Date: Mon, 16 Dec 2013 09:48:16 +0000 Subject: [PATCH 014/104] doxygen configuration file added git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@14 113b152e-814d-439b-b186-022a431db7b5 --- .../commonModeSubtraction.h | 25 +++--- slsDetectorCalibration/doxy.config | 85 +++++++++++++++++++ slsDetectorCalibration/moenchCommonMode.h | 14 ++- slsDetectorCalibration/moenchReadData.C | 32 ++++--- 4 files changed, 125 insertions(+), 31 deletions(-) create mode 100644 slsDetectorCalibration/doxy.config diff --git a/slsDetectorCalibration/commonModeSubtraction.h b/slsDetectorCalibration/commonModeSubtraction.h index 4029e99b5a..f68738d35c 100644 --- a/slsDetectorCalibration/commonModeSubtraction.h +++ b/slsDetectorCalibration/commonModeSubtraction.h @@ -36,21 +36,24 @@ class commonModeSubtraction { cmPed[i]=0; }}; - /** adds the pixel to the sum of pedestals -- virtual func - \param isc region of interest index + /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest + \param ix region of interest index */ - virtual void addToCommonMode(double val, int isc=0) { - if (isc>=0 && isc=0 && isc=0 && isc0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); + virtual double getCommonMode(int ix=0, int iy=0) { + (void) ix; (void) iy; + if (nCm[0]>0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); return 0;}; diff --git a/slsDetectorCalibration/doxy.config b/slsDetectorCalibration/doxy.config new file mode 100644 index 0000000000..66307cc554 --- /dev/null +++ b/slsDetectorCalibration/doxy.config @@ -0,0 +1,85 @@ +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + + + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = YES + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +INTERNAL_DOCS = NO + +SHOW_INCLUDE_FILES = NO + +SHOW_FILES = NO + +SHOW_NAMESPACES = NO + +COMPACT_LATEX = YES + +PAPER_TYPE = a4 + +PDF_HYPERLINKS = YES + +USE_PDFLATEX = YES + +LATEX_HIDE_INDICES = YES + +PREDEFINED = __cplusplus + +INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C +OUTPUT_DIRECTORY = docs + diff --git a/slsDetectorCalibration/moenchCommonMode.h b/slsDetectorCalibration/moenchCommonMode.h index 892c776bf5..dba0df2b7f 100644 --- a/slsDetectorCalibration/moenchCommonMode.h +++ b/slsDetectorCalibration/moenchCommonMode.h @@ -18,8 +18,12 @@ class moenchCommonMode : public commonModeSubtraction { \param iy pixel coordinate in the y direction */ virtual void addToCommonMode(double val, int ix=0, int iy=0) { - (void) iy; - commonModeSubtraction::addToCommonMode(val, ix/40); + (void) iy; + int isc=ix/40; + if (isc>=0 && isc=0 && isc0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); + } + return 0; }; }; diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 09388fe4a0..337f13c2de 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -33,23 +33,21 @@ using namespace std; /** - char *fformat, file name format - char *tit, title of the tree etc. - int runmin, minimum run number - int runmax, max run number - int nbins=1500, number of bins for spectrum hists - int hmin=-500, minimum for spectrum hists - int hmax=1000, maximum for spectrum hists - int sign=1, sign of the spectrum to find hits - double hc=0, readout correlation coefficient with previous pixel - double tc=0, time correlation coefficient with previous frame (case of bad reset) - int xmin=0, minimum x coordinate - int xmax=NC, maximum x coordinate - int ymin=0, minimum y coordinate - int ymax=NR, maximum y coordinate - int pedsub=1, enable pedestal subtraction - int cmsub=0 enable commonmode subtraction - + \param fformat, file name format + \param tit, title of the tree etc. + \param runmin, minimum run number + \param runmax, max run number + \param nbins=1500, number of bins for spectrum hists + \param hmin=-500, minimum for spectrum hists + \param hmax=1000, maximum for spectrum hists + \param sign=1, sign of the spectrum to find hits + \param hc=0, readout correlation coefficient with previous pixel + \param xmin=0, minimum x coordinate + \param xmax=NC, maximum x coordinate + \param ymin=0, minimum y coordinate + \param ymax=NR, maximum y coordinate + \param cmsub=0 enable commonmode subtraction + \returns pointer to histo stack with cluster spectra */ From 22f20507dbc9ba07f7ecc2a2fb099ffd903724ca Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Mon, 16 Dec 2013 16:01:20 +0000 Subject: [PATCH 015/104] Some improved documentation git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@15 113b152e-814d-439b-b186-022a431db7b5 --- .../commonModeSubtraction.h | 7 +++-- slsDetectorCalibration/doxy.config | 2 +- slsDetectorCalibration/moenchReadData.C | 30 ++++++++++--------- slsDetectorCalibration/singlePhotonDetector.h | 5 ++-- slsDetectorCalibration/slsDetectorData.h | 4 +-- slsDetectorCalibration/slsReceiverData.h | 6 ++-- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/slsDetectorCalibration/commonModeSubtraction.h b/slsDetectorCalibration/commonModeSubtraction.h index f68738d35c..04a0144186 100644 --- a/slsDetectorCalibration/commonModeSubtraction.h +++ b/slsDetectorCalibration/commonModeSubtraction.h @@ -37,7 +37,9 @@ class commonModeSubtraction { }}; /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest - \param ix region of interest index + \param val value to add + \param ix pixel x coordinate + \param iy pixel y coordinate */ virtual void addToCommonMode(double val, int ix=0, int iy=0) { (void) ix; (void) iy; @@ -48,7 +50,8 @@ class commonModeSubtraction { }; /** gets the common mode i.e. the difference between the current average sum of pedestals mode and the average pedestal -- virtual func must be overloaded to define the regions of interest - \param isc region of interest index + \param ix pixel x coordinate + \param iy pixel y coordinate \return the difference between the current average sum of pedestals and the average pedestal */ virtual double getCommonMode(int ix=0, int iy=0) { diff --git a/slsDetectorCalibration/doxy.config b/slsDetectorCalibration/doxy.config index 66307cc554..b81d49e48b 100644 --- a/slsDetectorCalibration/doxy.config +++ b/slsDetectorCalibration/doxy.config @@ -80,6 +80,6 @@ LATEX_HIDE_INDICES = YES PREDEFINED = __cplusplus -INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C +INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h OUTPUT_DIRECTORY = docs diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 337f13c2de..a948c3e2c5 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -33,20 +33,22 @@ using namespace std; /** - \param fformat, file name format - \param tit, title of the tree etc. - \param runmin, minimum run number - \param runmax, max run number - \param nbins=1500, number of bins for spectrum hists - \param hmin=-500, minimum for spectrum hists - \param hmax=1000, maximum for spectrum hists - \param sign=1, sign of the spectrum to find hits - \param hc=0, readout correlation coefficient with previous pixel - \param xmin=0, minimum x coordinate - \param xmax=NC, maximum x coordinate - \param ymin=0, minimum y coordinate - \param ymax=NR, maximum y coordinate - \param cmsub=0 enable commonmode subtraction +Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis. + + \param fformat file name format + \param tit title of the tree etc. + \param runmin minimum run number + \param runmax max run number + \param nbins number of bins for spectrum hists + \param hmin histo minimum for spectrum hists + \param hmax histo maximum for spectrum hists + \param sign sign of the spectrum to find hits + \param hc readout correlation coefficient with previous pixel + \param xmin minimum x coordinate + \param xmax maximum x coordinate + \param ymin minimum y coordinate + \param ymax maximum y coordinate + \param cmsub enable commonmode subtraction \returns pointer to histo stack with cluster spectra */ diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 78c6e1ea29..03d2585d84 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -44,9 +44,10 @@ class singlePhotonDetector { /** Constructor (no error checking if datasize and offsets are compatible!) - \param s detector data structure to be used + \param d detector data structure to be used \param csize cluster size (should be an odd number). Defaults to 3 \param nsigma number of rms to discriminate from the noise. Defaults to 5 + \param sign 1 if photons are positive, -1 if negative \param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none \param nped number of samples for pedestal averaging \param nd number of dark frames to average as pedestals without photon discrimination at the beginning of the measurement @@ -269,7 +270,7 @@ class singlePhotonDetector { #ifdef MYROOT1 /** generates a tree and maps the branches \param tname name for the tree - \param iframe pointer to the frame number + \param iFrame pointer to the frame number \returns returns pointer to the TTree */ TTree *initEventTree(char *tname, int *iFrame=NULL) { diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index c28e447aab..c4c5a6f328 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -148,8 +148,8 @@ class slsDetectorData { /** Returns detector size in x,y - \param nx reference to number of channels in x - \param ny reference to number of channels in y (will be 1 for strips) + \param npx reference to number of channels in x + \param npy reference to number of channels in y (will be 1 for strips) \returns total number of channels */ int getDetectorSize(int &npx, int &npy){npx=nx; npy=ny; return nx*ny;}; diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index 67d3cf51f2..a7f10dc21c 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -56,13 +56,13 @@ class slsReceiverData : public slsDetectorData { Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! \param data pointer to the memory to be analyzed - \param ndata + \param ndata size of frame returned \param dsize size of the memory slot to be analyzed \returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found */ - virtual char *findNextFrame(char *data, int &npackets, int dsize) { + virtual char *findNextFrame(char *data, int &ndata, int dsize) { char *retval=NULL, *p=data; int dd=0; int fn, fnum=-1, np=0, pnum=-1; @@ -103,7 +103,7 @@ class slsReceiverData : public slsDetectorData { cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; } - npackets=np*packetSize; + ndata=np*packetSize; return retval; }; From 574f9cf5661a499c1ac91767e09a8604002b122c Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Tue, 7 Jan 2014 13:39:25 +0000 Subject: [PATCH 016/104] common mode git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@16 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/commonModeSubtraction.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/slsDetectorCalibration/commonModeSubtraction.h b/slsDetectorCalibration/commonModeSubtraction.h index 04a0144186..2de635a45f 100644 --- a/slsDetectorCalibration/commonModeSubtraction.h +++ b/slsDetectorCalibration/commonModeSubtraction.h @@ -3,6 +3,9 @@ #include "MovingStat.h" + + + class commonModeSubtraction { /** @short class to calculate the common mode of the pedestals based on an approximated moving average*/ From facbce62cf952c7f1cd4f2a04e58979b1d161ca3 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Tue, 14 Jan 2014 13:46:21 +0000 Subject: [PATCH 017/104] Some bug fixes to slsReceiverData git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@17 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moench02ModuleData.h | 6 ++-- slsDetectorCalibration/moenchReadData.C | 4 ++- slsDetectorCalibration/singlePhotonDetector.h | 18 ++++++++-- slsDetectorCalibration/slsReceiverData.h | 35 +++++++++++-------- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index 20ad2ae3fa..34b4f17834 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -18,7 +18,8 @@ class moench02ModuleData : public slsReceiverData { */ - moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), xtalk(c) { + moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), + xtalk(c) { @@ -96,8 +97,9 @@ class moench02ModuleData : public slsReceiverData { */ double getValue(char *data, int ix, int iy=0) { + // cout << "##" << (void*)data << " " << ix << " " <::getValue(data, ix, iy); else return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); }; diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index a948c3e2c5..ff57c9b122 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -134,6 +134,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb //calculate pedestals and common modes if (cmsub) { + // cout << "cm" << endl; for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); @@ -141,10 +142,11 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb } - + // cout << "new frame " << endl; for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); #ifdef MY_DEBUG diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 03d2585d84..e28fe8eb41 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -118,7 +118,15 @@ class singlePhotonDetector { \param ix pixel x coordinate \param iy pixel y coordinate */ - virtual void addToPedestal(double val, int ix, int iy){ if (ix>=0 && ix=0 && iyisGood(ix, iy) ) cmSub->addToCommonMode(val, ix, iy);}}; + virtual void addToPedestal(double val, int ix, int iy){ + // cout << "*"<< ix << " " << iy << " " << val << endl; + if (ix>=0 && ix=0 && iyisGood(ix, iy) ) + cmSub->addToCommonMode(val, ix, iy); + }; + }; /** gets pedestal (and common mode) @@ -177,10 +185,14 @@ class singlePhotonDetector { // eventType ret=PEDESTAL; double tot=0, max=0; - + // cout << iframe << endl; + if (iframe { public: /** - - slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. Inherits and implements slsDetectorData. @@ -69,12 +67,13 @@ class slsReceiverData : public slsDetectorData { while (dd<=(dsize-packetSize)) { pnum=getPacketNumber(p); fn=getFrameNumber(p); - if (pnum<0 || pnum>=nPackets) { + + + if (pnum<1 || pnum>nPackets) { cout << "Bad packet number " << pnum << " frame "<< fn << endl; retval=NULL; - continue; - } - if (pnum==1) { + np=0; + } else if (pnum==1) { fnum=fn; retval=p; if (np>0) @@ -90,21 +89,23 @@ class slsReceiverData : public slsDetectorData { p+=packetSize; dd+=packetSize; np++; + // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; if (np==nPackets) - if (pnum==nPackets) + if (pnum==nPackets) { + // cout << "Frame found!" << endl; break; - else { + } else { cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; retval=NULL; } } - if (np<40) { + if (np0) cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; } ndata=np*packetSize; - + // cout << "return " << ndata << endl; return retval; }; @@ -128,14 +129,19 @@ class slsReceiverData : public slsDetectorData { retval=findNextFrame(data,nd,packetSize*nPackets); np=nd/packetSize; + // cout << np << endl; - if (retval==data && np==nPackets) + + if (retval==data && np==nPackets) { + // cout << "-" << endl; return data; - else if (np>nPackets) { - cout << "too many packets!!!!!!!!!!" << endl; + + } else if (np>nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; delete [] data; return NULL; - } else { + } else if (retval!=NULL) { + // cout << "+" << endl;; for (int ip=0; ip { delete [] data; return NULL; } else { + // cout << "." << endl;; np++; } } From 0d0b1fd3895b1625f41237704765ec7015a470e6 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 16 Jan 2014 09:57:29 +0000 Subject: [PATCH 018/104] commented define myroot1 insinglephotondetector.h git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@18 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/singlePhotonDetector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index e28fe8eb41..d10289fe39 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -9,7 +9,7 @@ #include "commonModeSubtraction.h" -#define MYROOT1 +/*#define MYROOT1*/ #ifdef MYROOT1 #include From df64805059a94c52e1b76afeee89565c63d1f67f Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Mon, 20 Jan 2014 13:47:10 +0000 Subject: [PATCH 019/104] bug in photon finder and memory leak corrected git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@19 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchReadData.C | 53 ++++++++++++------- slsDetectorCalibration/singlePhotonDetector.h | 20 +++---- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index ff57c9b122..bd74b34c7e 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -26,7 +26,7 @@ using namespace std; #define NR 160 -#define MY_DEBUG 1 +//#define MY_DEBUG 1 #ifdef MY_DEBUG #include #endif @@ -60,7 +60,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb if (cmsub) cmSub=new moenchCommonMode(); - + int nph=0; singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); @@ -118,6 +118,16 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb TH2F *he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); he->SetStats(kFALSE); he->Draw("colz"); + TCanvas *cH1=new TCanvas(); + cH1->SetLogz(); + h1->Draw("colz"); + TCanvas *cH2=new TCanvas(); + cH2->SetLogz(); + h2->Draw("colz"); + TCanvas *cH3=new TCanvas(); + cH3->SetLogz(); + h3->Draw("colz"); + #endif filter->newDataSet(); @@ -126,9 +136,9 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb sprintf(fname,fformat,irun); cout << "file name " << fname << endl; filebin.open((const char *)(fname), ios::in | ios::binary); - + nph=0; while ((buff=decoder->readNextFrame(filebin))) { - + filter->newFrame(); @@ -150,7 +160,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb thisEvent=filter->getEventType(buff, ix, iy, cmsub); #ifdef MY_DEBUG - if (iev%10000==0) + if (iev%1000==0) he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); #endif @@ -165,7 +175,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb // if (nf%1000==0 && ix==20 && iy==20) cout << " val="<< decoder->getClusterElement(0,0)<< endl; if (thisEvent==PHOTON_MAX ) { - + nph++; for (ir=-1; ir<2; ir++) { for (ic=-1; ic<2; ic++) { v=filter->getClusterElement(ic,ir); @@ -239,28 +249,35 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb tall->Fill(); -#ifdef MY_DEBUG - if (iev%100000==0) { - myC->Modified(); - myC->Update(); - } -#endif - - iev++; } + + } - - } - } + + } ////////////////////////////////////////////////////////// +#ifdef MY_DEBUG + if (iev%1000==0) { + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); + } + iev++; +#endif cout << "=" ; nf++; + delete [] buff; } - cout << endl; + cout << nph << endl; if (filebin.is_open()) filebin.close(); else diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index d10289fe39..c22e40ba70 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -232,20 +232,20 @@ class singlePhotonDetector { } else if (eventMask[iy][ix]==PHOTON) { if (cluster->get_data(0,0)>=max) { - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { + eventMask[iy][ix]=PHOTON_MAX; + /* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */ +/* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { */ - if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)=0 && (iy+ir)=0 && (ix+ic)getValue(data, ix, iy),ix,iy); From 4d71f07cde292602d55e38ff11d87eaf8a7f5a5e Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Mon, 20 Jan 2014 16:16:08 +0000 Subject: [PATCH 020/104] more debugging with moench git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@20 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchReadData.C | 244 ++++++++++-------- slsDetectorCalibration/singlePhotonDetector.h | 27 +- 2 files changed, 143 insertions(+), 128 deletions(-) diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index bd74b34c7e..f3c3999bac 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -26,7 +26,7 @@ using namespace std; #define NR 160 -//#define MY_DEBUG 1 +#define MY_DEBUG 1 #ifdef MY_DEBUG #include #endif @@ -53,7 +53,7 @@ Loops over data file to find single photons, fills the tree (and writes it to fi */ -THStack *moenchReadData(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=0, int xmax=NC, int ymin=0, int ymax=NR, int cmsub=0) { +THStack *moenchReadData(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=0, int xmax=NC, int ymin=0, int ymax=NR, int cmsub=0, int hitfinder=1) { moench02ModuleData *decoder=new moench02ModuleData(hc); moenchCommonMode *cmSub=NULL; @@ -88,15 +88,16 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); hs->Add(h1); - - h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); - hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); - hs->Add(h2); - hs->Add(h3); - hs->Add(hetaX); - hs->Add(hetaY); + if (hitfinder) { + h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h2); + hs->Add(h3); + hs->Add(hetaX); + hs->Add(hetaY); + } @@ -107,27 +108,37 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb Int_t iFrame; - TTree *tall=filter->initEventTree(tit, &iFrame); + TTree *tall; + if (hitfinder) + tall=filter->initEventTree(tit, &iFrame); double tot, tl, tr, bl, br, v; #ifdef MY_DEBUG - TCanvas *myC=new TCanvas(); - TH2F *he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); - he->SetStats(kFALSE); - he->Draw("colz"); - TCanvas *cH1=new TCanvas(); - cH1->SetLogz(); - h1->Draw("colz"); - TCanvas *cH2=new TCanvas(); - cH2->SetLogz(); - h2->Draw("colz"); - TCanvas *cH3=new TCanvas(); - cH3->SetLogz(); - h3->Draw("colz"); - + + TCanvas *myC; + TH2F *he; + TCanvas *cH1; + TCanvas *cH2; + TCanvas *cH3; + + if (hitfinder) { + myC=new TCanvas(); + he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); + he->SetStats(kFALSE); + he->Draw("colz"); + cH1=new TCanvas(); + cH1->SetLogz(); + h1->Draw("colz"); + cH2=new TCanvas(); + cH2->SetLogz(); + h2->Draw("colz"); + cH3=new TCanvas(); + cH3->SetLogz(); + h3->Draw("colz"); + } #endif filter->newDataSet(); @@ -160,89 +171,92 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb thisEvent=filter->getEventType(buff, ix, iy, cmsub); #ifdef MY_DEBUG - if (iev%1000==0) - he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); + if (hitfinder) { + if (iev%1000==0) + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); + } #endif if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; h1->Fill(filter->getClusterElement(0,0), iy+NR*ix); - - // if (nf%1000==0 && ix==20 && iy==20) cout << " val="<< decoder->getClusterElement(0,0)<< endl; - - if (thisEvent==PHOTON_MAX ) { - nph++; - for (ir=-1; ir<2; ir++) { - for (ic=-1; ic<2; ic++) { - v=filter->getClusterElement(ic,ir); - // data[ic+1][ir+1]=v; + if (hitfinder) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + + // if (nf%1000==0 && ix==20 && iy==20) cout << " val="<< decoder->getClusterElement(0,0)<< endl; + + if (thisEvent==PHOTON_MAX ) { + nph++; + for (ir=-1; ir<2; ir++) { + for (ic=-1; ic<2; ic++) { + v=filter->getClusterElement(ic,ir); + // data[ic+1][ir+1]=v; - - - tot+=v; - if (ir<1) { - if (ic<1) { - bl+=v; - - } - if (ic>-1) { - br+=v; - } - } - - if (ir>-1) { - if (ic<1) { - tl+=v; + + tot+=v; + if (ir<1) { + + if (ic<1) { + bl+=v; + + } + if (ic>-1) { + br+=v; + } } - if (ic>-1) { - tr+=v; + + if (ir>-1) { + if (ic<1) { + tl+=v; + } + if (ic>-1) { + tr+=v; + } } } } - } + - - if (bl>br && bl>tl && bl>tr) { + if (bl>br && bl>tl && bl>tr) { h2->Fill(bl, iy+NR*ix); - if (bl>0) { - hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/bl,iy+NR*ix); - hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/bl,iy+NR*ix); - hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/bl,iy+NR*(ix-1)); - hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/bl,(iy-1)+NR*ix); - } - } else if (br>bl && br>tl && br>tr) { + if (bl>0) { + hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/bl,iy+NR*ix); + hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/bl,iy+NR*ix); + hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/bl,iy+NR*(ix-1)); + hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/bl,(iy-1)+NR*ix); + } + } else if (br>bl && br>tl && br>tr) { h2->Fill(br, iy+NR*ix); - if (br>0) { - hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/br,iy+NR*ix); - hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/br,iy+NR*ix); - hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/br,iy+NR*(ix+1)); - hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/br,iy-1+NR*ix); - } - } else if (tl>br && tl>bl && tl>tr) { + if (br>0) { + hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/br,iy+NR*ix); + hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/br,iy+NR*ix); + hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/br,iy+NR*(ix+1)); + hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/br,iy-1+NR*ix); + } + } else if (tl>br && tl>bl && tl>tr) { h2->Fill(tl, iy+NR*ix); - if (tl>0) { - hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tl,iy+NR*ix); - hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/tl,iy+NR*ix); - hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tl,iy+NR*(ix-1)); - hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/tl,iy+1+NR*ix); - } - } else if (tr>bl && tr>tl && tr>br) { + if (tl>0) { + hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tl,iy+NR*ix); + hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/tl,iy+NR*ix); + hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tl,iy+NR*(ix-1)); + hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/tl,iy+1+NR*ix); + } + } else if (tr>bl && tr>tl && tr>br) { h2->Fill(tr, iy+NR*ix); - if (tr>0) { - hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tr,iy+NR*ix); - hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/tr,iy+NR*ix); - hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tr,iy+NR*(ix+1)); - hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/tr,iy+1+NR*ix); - } - - + if (tr>0) { + hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tr,iy+NR*ix); + hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/tr,iy+NR*ix); + hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tr,iy+NR*(ix+1)); + hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/tr,iy+1+NR*ix); + } + - } + + } h3->Fill(tot, iy+NR*ix); iFrame=decoder->getFrameNumber(buff); @@ -250,45 +264,47 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb tall->Fill(); - } + } - } + } + } } ////////////////////////////////////////////////////////// #ifdef MY_DEBUG - if (iev%1000==0) { - myC->Modified(); - myC->Update(); - cH1->Modified(); - cH1->Update(); - cH2->Modified(); - cH2->Update(); - cH3->Modified(); - cH3->Update(); - } - iev++; -#endif - - cout << "=" ; + if (iev%1000==0) { + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); + } + iev++; +#endif nf++; + + cout << "=" ; delete [] buff; } cout << nph << endl; if (filebin.is_open()) - filebin.close(); + filebin.close(); else cout << "could not open file " << fname << endl; - } - tall->Write(tall->GetName(),TObject::kOverwrite); - + } + if (hitfinder) + tall->Write(tall->GetName(),TObject::kOverwrite); + delete decoder; cout << "Read " << nf << " frames" << endl; return hs; } - + diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index c22e40ba70..d01aae737b 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -9,7 +9,7 @@ #include "commonModeSubtraction.h" -/*#define MYROOT1*/ +#define MYROOT1 #ifdef MYROOT1 #include @@ -198,7 +198,7 @@ class singlePhotonDetector { - if (eventMask[iy][ix]==UNDEFINED) { + // if (eventMask[iy][ix]==UNDEFINED) { eventMask[iy][ix]=PEDESTAL; @@ -229,28 +229,27 @@ class singlePhotonDetector { if (eventMask[iy][ix]!=PHOTON && tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms) { eventMask[iy][ix]=NEIGHBOUR; - } else if (eventMask[iy][ix]==PHOTON) { if (cluster->get_data(0,0)>=max) { eventMask[iy][ix]=PHOTON_MAX; - /* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */ -/* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { */ - -/* if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)=0 && (iy+ir)=0 && (ix+ic)get_data(ic,ir) << " "; */ /* } */ - /* } */ /* } */ - - - } +/* cout << endl;; */ +/* } */ + } } else if (eventMask[iy][ix]==PEDESTAL) { if (cm==0) addToPedestal(det->getValue(data, ix, iy),ix,iy); } - } + // } return eventMask[iy][ix]; From 37a52ebd32fe0c1fc4044904ea2fe08a6e2b9107 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Mon, 20 Jan 2014 16:34:49 +0000 Subject: [PATCH 021/104] read all photon data git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@21 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/raedNoiseData.C | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 slsDetectorCalibration/raedNoiseData.C diff --git a/slsDetectorCalibration/raedNoiseData.C b/slsDetectorCalibration/raedNoiseData.C new file mode 100644 index 0000000000..50d87d380d --- /dev/null +++ b/slsDetectorCalibration/raedNoiseData.C @@ -0,0 +1,74 @@ +#include "moenchReadData.C" + + +void raedNoiseData(char *tit, int sign=1){ + + + + char fname[1000]; + char f[1000]; + TFile *fout; + THStack *hs2N; + + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s.root",tit); + fout=new TFile(fname,"RECREATE"); + + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); + + hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0); + hs2N->SetName(tit); + hs2N->SetTitle(tit); + (TH2F*)(hs2N->GetHists()->At(0))->Write(); + + (TH2F*)(hs2N->GetHists()->At(1))->Write(); + (TH2F*)(hs2N->GetHists()->At(2))->Write(); + (TH2F*)(hs2N->GetHists()->At(3))->Write(); + (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + + fout->Close(); + + + +} + + + +void g4() { + + raedNoiseData("cds_g4_low_gain"); + raedNoiseData("cds_g4_sto1_only"); + raedNoiseData("cds_g4_no sto"); + + + +} + +void no_cds() { + + raedNoiseData("cds_disable_low_gain",-1); + raedNoiseData("cds_disable_sto1_only",-1); + raedNoiseData("cds_disable_no sto",-1); + + + +} + +void all_gains() { + + raedNoiseData("cds_g2"); + raedNoiseData("cds_g2HC"); + raedNoiseData("cds_g1_2"); + raedNoiseData("cds_g2_3"); + + + +} + +void all_low_gains() { + + raedNoiseData("cds_g2_low_gain"); + raedNoiseData("cds_g2HC_low_gain"); + raedNoiseData("cds_g1_2_low_gain"); + raedNoiseData("cds_g2_3_low_gain"); +} From cbf781aba34b33df306d98ccc239e49eeead12fc Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Tue, 21 Jan 2014 09:23:53 +0000 Subject: [PATCH 022/104] dummy change git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@22 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchReadData.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index f3c3999bac..7c4dcb297a 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -26,7 +26,7 @@ using namespace std; #define NR 160 -#define MY_DEBUG 1 +//#define MY_DEBUG 1 #ifdef MY_DEBUG #include #endif From fa060c5dc0e65419c08b879a043b1483c033cd83 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Tue, 21 Jan 2014 09:24:24 +0000 Subject: [PATCH 023/104] dummy change git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@23 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/raedNoiseData.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/raedNoiseData.C b/slsDetectorCalibration/raedNoiseData.C index 50d87d380d..33b323bd1c 100644 --- a/slsDetectorCalibration/raedNoiseData.C +++ b/slsDetectorCalibration/raedNoiseData.C @@ -13,7 +13,7 @@ void raedNoiseData(char *tit, int sign=1){ sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s.root",tit); fout=new TFile(fname,"RECREATE"); - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_12us_120V_%s_f00000%%04d000_0.raw",tit); hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0); hs2N->SetName(tit); From c74ecc78944b55829cec6a6ebc6f696a43e56d06 Mon Sep 17 00:00:00 2001 From: jungmann_j Date: Fri, 24 Jan 2014 08:01:15 +0000 Subject: [PATCH 024/104] git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@24 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/t | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 slsDetectorCalibration/t diff --git a/slsDetectorCalibration/t b/slsDetectorCalibration/t new file mode 100644 index 0000000000..e69de29bb2 From 5c245d6c62e2e03466c1f3a7d451dff639a3a89f Mon Sep 17 00:00:00 2001 From: jungmann_j Date: Fri, 24 Jan 2014 08:01:51 +0000 Subject: [PATCH 025/104] git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@25 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/t | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 slsDetectorCalibration/t diff --git a/slsDetectorCalibration/t b/slsDetectorCalibration/t deleted file mode 100644 index e69de29bb2..0000000000 From 849c5eb190a427d5bf0288624db46e76f0833ef6 Mon Sep 17 00:00:00 2001 From: l_cartier Date: Wed, 29 Jan 2014 11:27:02 +0000 Subject: [PATCH 026/104] multi threadet version of moenchReadData git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@26 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchMakeTree.C | 8 ++--- slsDetectorCalibration/moenchReadDataMT.C | 44 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 slsDetectorCalibration/moenchReadDataMT.C diff --git a/slsDetectorCalibration/moenchMakeTree.C b/slsDetectorCalibration/moenchMakeTree.C index 049bd18d91..ba109d6f20 100644 --- a/slsDetectorCalibration/moenchMakeTree.C +++ b/slsDetectorCalibration/moenchMakeTree.C @@ -102,7 +102,7 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign if (nf>nbg) { me=stat[iy][ix].Mean(); sig=stat[iy][ix].StandardDeviation(); - val=sign*decoder->getChannelShort(buff,ix,iy)-me; + val=sign*decoder->getChannel(buff,ix,iy)-me; dum=0; //no hit tot=0; @@ -111,8 +111,8 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign for (ir=-1; ir<2; ir++){ for (ic=-1; ic<2; ic++){ if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) { - valNei = sign*decoder->getChannelShort(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); - if (sign*decoder->getChannelShort(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! + valNei = sign*decoder->getChannel(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); + if (sign*decoder->getChannel(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! tot+=valNei; data[ir+1][ic+1] = valNei; maxNei = max(maxNei,valNei); @@ -134,7 +134,7 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign //cout << dum; } if (nfgetChannelShort(buff,ix,iy)); + stat[iy][ix].Calc(sign*decoder->getChannel(buff,ix,iy)); } } diff --git a/slsDetectorCalibration/moenchReadDataMT.C b/slsDetectorCalibration/moenchReadDataMT.C new file mode 100644 index 0000000000..c109da2511 --- /dev/null +++ b/slsDetectorCalibration/moenchReadDataMT.C @@ -0,0 +1,44 @@ +#include +#include +#include "moenchReadData.C" + +typedef struct task_s{ + char *fformat; + char *tname; + char *tdir; + int runmin; + int runmax; + int treeIndex; +} Task; + +void *moenchMakeTreeTask(void *p){ + char fname[1000]; + Task *t = (Task *)p; + sprintf(fname,"%s%s_%i.root",t->tdir,t->tname,t->treeIndex); + TFile *f = new TFile(fname,"RECREATE"); + moenchReadData(t->fformat,t->tname,t->runmin,t->runmax); + f->Close(); + return 0; +} + + +void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0){ + char threadName[1000]; + TThread *threads[nThreads]; + for(int i = 0; i < nThreads; i++){ + sprintf(threadName,"t%i",i); + Task *t = (Task *)malloc(sizeof(Task)); + t->fformat = fformat; + t->tname = tit; + t->tdir = tdir; + t->runmin = runmin + i*runoffset; + t->runmax = runmin + (i+1)*runoffset - 1; + t->treeIndex = treeIndexStart + i; + cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; + threads[i] = new TThread(threadName, moenchMakeTreeTask, t); + threads[i]->Run(); + } +} + + + From 50acdf562827f203102b0da9210a7a4f3123169d Mon Sep 17 00:00:00 2001 From: l_cartier Date: Wed, 29 Jan 2014 12:52:21 +0000 Subject: [PATCH 027/104] filter runs from 1..159 git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@27 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchReadData.C | 2 +- slsDetectorCalibration/moenchReadDataMT.C | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 7c4dcb297a..a6245fbba9 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -53,7 +53,7 @@ Loops over data file to find single photons, fills the tree (and writes it to fi */ -THStack *moenchReadData(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=0, int xmax=NC, int ymin=0, int ymax=NR, int cmsub=0, int hitfinder=1) { +THStack *moenchReadData(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) { moench02ModuleData *decoder=new moench02ModuleData(hc); moenchCommonMode *cmSub=NULL; diff --git a/slsDetectorCalibration/moenchReadDataMT.C b/slsDetectorCalibration/moenchReadDataMT.C index c109da2511..0720909c4e 100644 --- a/slsDetectorCalibration/moenchReadDataMT.C +++ b/slsDetectorCalibration/moenchReadDataMT.C @@ -12,10 +12,13 @@ typedef struct task_s{ } Task; void *moenchMakeTreeTask(void *p){ + TThread::Lock(); char fname[1000]; Task *t = (Task *)p; sprintf(fname,"%s%s_%i.root",t->tdir,t->tname,t->treeIndex); TFile *f = new TFile(fname,"RECREATE"); + cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<")" << endl; + TThread::UnLock(); moenchReadData(t->fformat,t->tname,t->runmin,t->runmax); f->Close(); return 0; @@ -38,6 +41,11 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo threads[i] = new TThread(threadName, moenchMakeTreeTask, t); threads[i]->Run(); } + + for(int i = 0; i < nThreads; i++){ + threads[i]->Join(); + } + } From d9a5e7e2a522f56a2b5971da2c6947a8f7240f0b Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 30 Jan 2014 17:51:11 +0000 Subject: [PATCH 028/104] got rid of unncessary printouts git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@28 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/slsReceiverData.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index 4143cc65ea..93c6453b49 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -77,11 +77,11 @@ class slsReceiverData : public slsDetectorData { fnum=fn; retval=p; if (np>0) - cout << "*Incomplete frame number " << fnum << endl; + /*cout << "*Incomplete frame number " << fnum << endl;*/ np=0; } else if (fn!=fnum) { if (fnum!=-1) { - cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl; + /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ retval=NULL; } np=0; From fea86709943ee46c5d534fcb492b916945088826 Mon Sep 17 00:00:00 2001 From: l_msdetect Date: Mon, 3 Feb 2014 12:48:57 +0000 Subject: [PATCH 029/104] some modifications git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@29 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchMakeTree.C | 79 +++++++++++++------ slsDetectorCalibration/moenchReadData.C | 3 +- slsDetectorCalibration/raedNoiseData.C | 61 +++++++++++++- slsDetectorCalibration/singlePhotonDetector.h | 1 + 4 files changed, 117 insertions(+), 27 deletions(-) diff --git a/slsDetectorCalibration/moenchMakeTree.C b/slsDetectorCalibration/moenchMakeTree.C index ba109d6f20..372052285d 100644 --- a/slsDetectorCalibration/moenchMakeTree.C +++ b/slsDetectorCalibration/moenchMakeTree.C @@ -23,9 +23,9 @@ using namespace std; //tree variables -int xC,yC,iFrameC; -double meC,sigC; -Double_t dataC[3][3]; + int xC,yC,iFrameC; + double meC,sigC; + Double_t dataC[3][3]; TTree* tall; typedef struct task_s{ @@ -50,13 +50,19 @@ inline void storeEvent(int iF,int x,int y, Double_t data[][3], double me, double TThread::Lock(); xC = x; yC = y; iFrameC = iF; memcpy(dataC,data,sizeof(Double_t)*3*3); + //cout << "X: " << x << " Y: " << y << endl; + /* for(int i = 0; i < 3; i++){ + for(int j = 0; j < 3; j++){ + cout << "i: " << i << " j: " << j << " dataC " << dataC[i][j] << " data " << data[i][j] << endl; + } + }*/ meC = me; sigC = sig; tall->Fill(); TThread::UnLock(); } void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign=1) { - + double nThSigma = 3.; moench02ModuleData *decoder=new moench02ModuleData(); char *buff; char fname[10000]; @@ -71,9 +77,9 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign ifstream filebin; - int nbg=1000; + int nbg=20; - int ix, iy, ir, ic; + int ix, iy, ir, ic, mx,my; Double_t data[3][3]; nPhotonsStat.Clear(); @@ -93,21 +99,31 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign while ((buff=decoder->readNextFrame(filebin))) { nPhotons=0; - for (ix=0; ix<160; ix++){ - for (iy=0; iy<160; iy++) { + //for (ix=0; ix<160; ix++){ + for (ix=0; ix<40; ix++){ + for (iy=0; iy<160; iy++) { + + + + dum=0; //no hit + // tot=0; + + me=stat[iy][ix].Mean(); + sig=stat[iy][ix].StandardDeviation(); + val=sign*(decoder->getChannelShort(buff,ix,iy)-me); - dum=0; //no hit - tot=0; if (nf>nbg) { me=stat[iy][ix].Mean(); sig=stat[iy][ix].StandardDeviation(); val=sign*decoder->getChannel(buff,ix,iy)-me; - dum=0; //no hit + // dum=0; //no hit tot=0; maxNei = 0; + if (val>nThSigma*sig)//{ //hit check if neighbors are higher + dum=1; for (ir=-1; ir<2; ir++){ for (ic=-1; ic<2; ic++){ if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) { @@ -115,23 +131,34 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign if (sign*decoder->getChannel(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! tot+=valNei; data[ir+1][ic+1] = valNei; - maxNei = max(maxNei,valNei); + if(valNei/stat[iy+ir][ix+ic].StandardDeviation() > maxNei){ + maxNei = valNei/stat[iy+ir][ix+ic].StandardDeviation(); + mx = ir; + my = ic; + } } } } + // } - if (val<(me-3.*sig)) dum=2; //discard negative events! + if (val<(-nThSigma*sig)) dum=2; //discard negative events! - if(maxNei == val && dum == 1){ // this is an event and we are in the center + if(dum == 1 && mx == 0 && my == 0){ // this is an event and we are in the center storeEvent(nf,ix,iy,data,me,sig); nPhotons++; - //cout << "X: " << ix << " Y: " << iy << " val: " << val << " tot: " << tot << endl; - }else{ - dum = 3; //discard events (for pedestal) where sum of the neighbours is too large. + //cout << "BF X: " << ix << " Y: " << iy << " val: " << val << " tot: " << tot << " me: " << me << " sig: " << sig << endl; } + - //if (tot>3.*sig && dum == 1){ dum=3;} + //if (tot>9.*sig && dum == 1){ dum=3;} //cout << dum; + } + //if (ix==20 && iy==40) + //cout << decoder->getChannelShort(buff,ix,iy)<< " " << val << " " << me << " " << sig << " " << dum << endl; + + if ( dum==0) { + + stat[iy][ix].Calc(decoder->getChannelShort(buff,ix,iy)); } if (nfgetChannel(buff,ix,iy)); @@ -144,7 +171,7 @@ void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign nf++; } //cout << endl; - cout << "processed File " << fname << " done. Avg. Photons/Frame: " << nPhotonsStat.Mean() << " sig: " << nPhotonsStat.StandardDeviation() << endl; + cout << "processed File " << fname << " done. Avg. Photons/Frame: " << nPhotonsStat.Mean() << " sig: " << nPhotonsStat.StandardDeviation() << " " << runmax-irun << " files need processing" << endl; if (filebin.is_open()) filebin.close(); else @@ -168,7 +195,7 @@ void *moenchMakeTreeTask(void *p){ int main(int argc, char **argv){ if(argc != 6){ cout << "Usage: inFile outdir tname fileNrStart fileNrEnd" << endl; exit(-1); } - int nThreads = 15; + int nThreads = 10; TThread *threads[nThreads]; char *inFile = argv[1]; @@ -192,24 +219,26 @@ int main(int argc, char **argv){ Task *t = (Task *)malloc(sizeof(Task)); t->fformat = inFile; t->tname = tName; - t->sign = -1; - t->runmin = start + (end-start)/(nThreads-1)*i; - t->runmax = start + (end-start)/(nThreads-1)*(i+1); + t->sign = 1.; + t->runmin = start + (end-start)/(nThreads)*i; + t->runmax = start + (end-start)/(nThreads)*(i+1); if(i == nThreads - 1) t->runmax = end; cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; threads[i] = new TThread(threadName, moenchMakeTreeTask, t); threads[i]->Run(); + //moenchMakeTreeTask(t); } //TThread::Ps(); - for(int i = 0; i < nThreads; i++){ + for(int i = 0; i < nThreads; i++){ threads[i]->Join(); } tall->Write(); - tall->GetCurrentFile()->Close(); + tall->Print(); + f->Close(); } diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index a6245fbba9..473a78f315 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -151,6 +151,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb while ((buff=decoder->readNextFrame(filebin))) { + if (hitfinder) { filter->newFrame(); //calculate pedestals and common modes @@ -161,7 +162,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb thisEvent=filter->getEventType(buff, ix, iy,0); } } - + } // cout << "new frame " << endl; diff --git a/slsDetectorCalibration/raedNoiseData.C b/slsDetectorCalibration/raedNoiseData.C index 33b323bd1c..0e7f24f211 100644 --- a/slsDetectorCalibration/raedNoiseData.C +++ b/slsDetectorCalibration/raedNoiseData.C @@ -13,7 +13,7 @@ void raedNoiseData(char *tit, int sign=1){ sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s.root",tit); fout=new TFile(fname,"RECREATE"); - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_12us_120V_%s_f00000%%04d000_0.raw",tit); + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0); hs2N->SetName(tit); @@ -34,6 +34,39 @@ void raedNoiseData(char *tit, int sign=1){ +void raedNoiseDataN(char *tit, int sign=1){ + + + + char fname[1000]; + char f[1000]; + TFile *fout; + THStack *hs2N; + + sprintf(fname,"/data/moench_xbox_20140116/noise_%s.root",tit); + fout=new TFile(fname,"RECREATE"); + + sprintf(fname,"/data/moench_xbox_20140116/noise_%s_f00000%%04d000_0.raw",tit); + + hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,0); + hs2N->SetName(tit); + hs2N->SetTitle(tit); + (TH2F*)(hs2N->GetHists()->At(0))->Write(); + + // (TH2F*)(hs2N->GetHists()->At(1))->Write(); + // (TH2F*)(hs2N->GetHists()->At(2))->Write(); + // (TH2F*)(hs2N->GetHists()->At(3))->Write(); + // (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + + fout->Close(); + + + +} + + + void g4() { raedNoiseData("cds_g4_low_gain"); @@ -72,3 +105,29 @@ void all_low_gains() { raedNoiseData("cds_g1_2_low_gain"); raedNoiseData("cds_g2_3_low_gain"); } + +/* +clkdivider data +/data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv17_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 12:40 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv25_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 13:26 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv35_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:09 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv50_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:54 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv70_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 16:42 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv110_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 17:27 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv170_f000000010000_0.raw +*/ + + +/* oversampled data +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:12 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:47 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_1.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 19:22 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_2.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:02 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_3.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:41 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_4.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:16 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_5.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:56 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_6.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 22:35 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_7.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:11 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_8.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:50 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_9.raw +*/ + diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index d01aae737b..363879d874 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -191,6 +191,7 @@ class singlePhotonDetector { if (cm==0) { // cout << "=" << endl; addToPedestal(det->getValue(data, ix, iy),ix,iy); + cluster->set_data(dataSign*(det->getValue(data, ix, iy)-getPedestal(ix,iy,cm)), 0,0 ); // cout << "=" << endl; } return UNDEFINED; From f3e58f95eab7d62d35ce90f1a784cdca13cf3b4d Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Mon, 3 Feb 2014 13:58:07 +0000 Subject: [PATCH 030/104] quadrant finding moved to singlePhotnDetector class git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@30 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/moenchReadData.C | 97 ++--------------- slsDetectorCalibration/singlePhotonDetector.h | 101 +++++++++++++----- 2 files changed, 87 insertions(+), 111 deletions(-) diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 473a78f315..e98fea4948 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -83,7 +83,6 @@ 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); @@ -113,7 +112,6 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb tall=filter->initEventTree(tit, &iFrame); - double tot, tl, tr, bl, br, v; #ifdef MY_DEBUG @@ -152,16 +150,16 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb if (hitfinder) { - filter->newFrame(); + filter->newFrame(); //calculate pedestals and common modes - if (cmsub) { + if (cmsub) { // cout << "cm" << endl; - for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); - } - } + for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); + } + } } // cout << "new frame " << endl; @@ -179,87 +177,14 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb #endif if (nf>1000) { - h1->Fill(filter->getClusterElement(0,0), iy+NR*ix); + h1->Fill(filter->getClusterTotal(1), iy+NR*ix); if (hitfinder) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - // if (nf%1000==0 && ix==20 && iy==20) cout << " val="<< decoder->getClusterElement(0,0)<< endl; - if (thisEvent==PHOTON_MAX ) { nph++; - for (ir=-1; ir<2; ir++) { - for (ic=-1; ic<2; ic++) { - v=filter->getClusterElement(ic,ir); - // data[ic+1][ir+1]=v; - - - - tot+=v; - if (ir<1) { - - if (ic<1) { - bl+=v; - - } - if (ic>-1) { - br+=v; - } - } - - if (ir>-1) { - if (ic<1) { - tl+=v; - } - if (ic>-1) { - tr+=v; - } - } - } - } - - - if (bl>br && bl>tl && bl>tr) { - h2->Fill(bl, iy+NR*ix); - if (bl>0) { - hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/bl,iy+NR*ix); - hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/bl,iy+NR*ix); - hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/bl,iy+NR*(ix-1)); - hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/bl,(iy-1)+NR*ix); - } - } else if (br>bl && br>tl && br>tr) { - h2->Fill(br, iy+NR*ix); - if (br>0) { - hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/br,iy+NR*ix); - hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/br,iy+NR*ix); - hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,-1))/br,iy+NR*(ix+1)); - hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/br,iy-1+NR*ix); - } - } else if (tl>br && tl>bl && tl>tr) { - h2->Fill(tl, iy+NR*ix); - if (tl>0) { - hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tl,iy+NR*ix); - hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/tl,iy+NR*ix); - hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tl,iy+NR*(ix-1)); - hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(-1,0))/tl,iy+1+NR*ix); - } - } else if (tr>bl && tr>tl && tr>br) { - h2->Fill(tr, iy+NR*ix); - if (tr>0) { - hetaX->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tr,iy+NR*ix); - hetaY->Fill((filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/tr,iy+NR*ix); - hetaX->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(0,1))/tr,iy+NR*(ix+1)); - hetaY->Fill(1.-(filter->getClusterElement(0,0)+filter->getClusterElement(1,0))/tr,iy+1+NR*ix); - } - - - - } - - h3->Fill(tot, iy+NR*ix); + + h2->Fill(filter->getClusterTotal(2), iy+NR*ix); + h3->Fill(filter->getClusterTotal(3), iy+NR*ix); iFrame=decoder->getFrameNumber(buff); tall->Fill(); diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 363879d874..1582030d40 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -28,7 +28,15 @@ using namespace std; PHOTON=2, PHOTON_MAX=3, NEGATIVE_PEDESTAL=4, - UNDEFINED=-1 + UNDEFINED_EVENT=-1 + }; + + enum quadrant { + TOP_LEFT=0, + TOP_RIGHT=1, + BOTTOM_LEFT=2, + BOTTOM_RIGHT=3, + UNDEFINED_QUADRANT=-1 }; @@ -62,7 +70,7 @@ class singlePhotonDetector { int sign=1, commonModeSubtraction *cm=NULL, int nped=1000, - int nd=100) : det(d), nx(0), ny(0), stat(NULL), cmSub(cm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), cluster(NULL), iframe(-1), dataSign(sign) { + int nd=100) : det(d), nx(0), ny(0), stat(NULL), cmSub(cm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), cluster(NULL), iframe(-1), dataSign(sign), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) { det->getDetectorSize(nx,ny); @@ -94,7 +102,7 @@ class singlePhotonDetector { void newDataSet(){iframe=-1; for (int iy=0; iyClear(); }; /** resets the eventMask to undefined and the commonModeSubtraction */ - void newFrame(){iframe++; for (int iy=0; iynewFrame();}; + void newFrame(){iframe++; for (int iy=0; iynewFrame();}; /** sets the commonModeSubtraction algorithm to be used @@ -184,8 +192,13 @@ class singlePhotonDetector { eventType getEventType(char *data, int ix, int iy, int cm=0) { // eventType ret=PEDESTAL; - double tot=0, max=0; + double max=0, tl=0, tr=0, bl=0,br=0, v; // cout << iframe << endl; + + tot=0; + quadTot=0; + quad=UNDEFINED_QUADRANT; + if (iframeset_data(dataSign*(det->getValue(data, ix, iy)-getPedestal(ix,iy,cm)), 0,0 ); // cout << "=" << endl; } - return UNDEFINED; + return UNDEFINED_EVENT; } @@ -214,12 +227,22 @@ class singlePhotonDetector { for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(dataSign*(det->getValue(data, ix+ic, iy+ir)-getPedestal(ix+ic,iy+ir,cm)), ic, ir ); - tot+=cluster->get_data(ic,ir); + v=cluster->get_data(ic,ir); + tot+=v; + if (ir<=0 && ic<=0) + bl+=v; + if (ir<=0 && ic>=0) + br+=v; + if (ir>=0 && ic<=0) + tl+=v; + if (ir>=0 && ic>=0) + tr+=v; + if (cluster->get_data(ic,ir)>max) { - max=cluster->get_data(ic,ir); + max=v; } if (ir==0 && ic==0) { - if (cluster->get_data(ic,ir)>nSigma*cluster->rms) { + if (v>nSigma*cluster->rms) { eventMask[iy][ix]=PHOTON; } else if (cluster->get_data(ic,ir)<-nSigma*cluster->rms) eventMask[iy][ix]=NEGATIVE_PEDESTAL; @@ -233,31 +256,54 @@ class singlePhotonDetector { } else if (eventMask[iy][ix]==PHOTON) { if (cluster->get_data(0,0)>=max) { eventMask[iy][ix]=PHOTON_MAX; - /* if (iframe%1000==0) { */ -/* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */ -/* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { */ -/* if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)get_data(ic,ir) << " "; */ -/* } */ -/* } */ -/* } */ -/* cout << endl;; */ -/* } */ } } else if (eventMask[iy][ix]==PEDESTAL) { if (cm==0) addToPedestal(det->getValue(data, ix, iy),ix,iy); } - // } - + + + if (bl>=br && bl>=tl && bl>=tr) { + quad=BOTTOM_LEFT; + quadTot=bl; + } else if (br>=bl && br>=tl && br>=tr) { + quad=BOTTOM_RIGHT; + quadTot=br; + } else if (tl>=br && tl>=bl && tl>=tr) { + quad=TOP_LEFT; + quadTot=tl; + } else if (tr>=bl && tr>=tl && tr>=br) { + quad=TOP_RIGHT; + quadTot=tr; + } + + return eventMask[iy][ix]; }; + /**< + retrurns the total signal in a cluster + \param size cluser size should be 1,2 or 3 + \returns cluster center if size=1, sum of the maximum quadrant if size=2, total of the cluster if size=3 or anything else + */ + + double getClusterTotal(int size) { + switch (size) { + case 1: + return getClusterElement(0,0); + case 2: + return quadTot; + default: + return tot; + }; + }; + /**< + retrurns the quadrant with maximum signal + \returns quadrant where the cluster is located */ + quadrant getQuadrant() {return quad;}; /** sets/gets number of samples for moving average pedestal calculation \param i number of samples to be set (0 or negative gets) @@ -279,6 +325,7 @@ class singlePhotonDetector { */ eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];}; + #ifdef MYROOT1 /** generates a tree and maps the branches \param tname name for the tree @@ -298,8 +345,8 @@ class singlePhotonDetector { char tit[100]; sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY); tall->Branch("data",cluster->data,tit); - tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); - tall->Branch("rms",&(cluster->rms),"rms/D"); + // tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); + // tall->Branch("rms",&(cluster->rms),"rms/D"); return tall; }; #endif @@ -322,7 +369,11 @@ class singlePhotonDetector { single_photon_hit *cluster; /**< single photon hit data structure */ int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */ int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */ - + quadrant quad; /**< quadrant where the photon is located */ + double tot; /**< sum of the 3x3 cluster */ + double quadTot; /**< sum of the maximum 2x2cluster */ + + }; From dd26dccde41c619acbe83b8edcd2451cce3fcd7c Mon Sep 17 00:00:00 2001 From: l_msdetect Date: Tue, 4 Feb 2014 11:25:33 +0000 Subject: [PATCH 031/104] some modifications and demos git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@31 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/demoCreateTree.C | 31 +++ slsDetectorCalibration/energyCalibration.cpp | 34 ++- slsDetectorCalibration/energyCalibration.h | 10 +- slsDetectorCalibration/gMapDemo.C | 11 + slsDetectorCalibration/gainMap.C | 228 +++++++++++++++++++ slsDetectorCalibration/moenchReadData.C | 2 +- slsDetectorCalibration/raedNoiseData.C | 7 +- 7 files changed, 308 insertions(+), 15 deletions(-) create mode 100644 slsDetectorCalibration/demoCreateTree.C create mode 100644 slsDetectorCalibration/gMapDemo.C create mode 100644 slsDetectorCalibration/gainMap.C diff --git a/slsDetectorCalibration/demoCreateTree.C b/slsDetectorCalibration/demoCreateTree.C new file mode 100644 index 0000000000..d14aa8b02d --- /dev/null +++ b/slsDetectorCalibration/demoCreateTree.C @@ -0,0 +1,31 @@ +{ + + //.L moenchReadData.C + + + + + + + TFile *fout; + THStack *hs2N; + + fout=new TFile("/scratch/outfile.root","RECREATE"); + + hs2N=moenchReadData("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_cds_g4_f00000%%04d000_0.raw",0,20,1500,-500,2500,1,0.,1,159,1,159, 0,1); + hs2N->SetName("cds_g4"); + hs2N->SetTitle("cds_g4"); + (TH2F*)(hs2N->GetHists()->At(0))->Write(); + + (TH2F*)(hs2N->GetHists()->At(1))->Write(); + (TH2F*)(hs2N->GetHists()->At(2))->Write(); + (TH2F*)(hs2N->GetHists()->At(3))->Write(); + (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + + fout->Close(); + + + +} + diff --git a/slsDetectorCalibration/energyCalibration.cpp b/slsDetectorCalibration/energyCalibration.cpp index df548f1cf5..cca067d145 100644 --- a/slsDetectorCalibration/energyCalibration.cpp +++ b/slsDetectorCalibration/energyCalibration.cpp @@ -289,7 +289,9 @@ energyCalibration::~energyCalibration(){ -TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch) { + + +TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch, int direction) { if (h2==NULL || nch==0) return NULL; @@ -299,19 +301,28 @@ TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch) { double val=-1; - h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax()); - - - for (int ib=0; ibGetXaxis()->GetNbins(); ib++) { - for (int ich=0; ichGetBinContent(ch0+ich+1,ib+1); + if (direction==0) { + h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax()); + for (int ib=0; ibGetXaxis()->GetNbins(); ib++) { + for (int ich=0; ichGetBinContent(ch0+ich+1,ib+1); + } + val=energyCalibrationFunctions::median(x, nch); + h1->SetBinContent(ib+1,val); + } + } else if (direction==1) { + h1=new TH1F("median","Median",h2->GetXaxis()->GetNbins(),h2->GetXaxis()->GetXmin(),h2->GetXaxis()->GetXmax()); + for (int ib=0; ibGetYaxis()->GetNbins(); ib++) { + for (int ich=0; ichGetBinContent(ib+1,ch0+ich+1); + } + val=energyCalibrationFunctions::median(x, nch); + h1->SetBinContent(ib+1,val); } - val=energyCalibrationFunctions::median(x, nch); - h1->SetBinContent(ib+1,val); } - return h1; + delete [] x; - + return h1; } @@ -480,6 +491,7 @@ TGraphErrors* energyCalibration::linearCalibration(int nscan, Double_t *en, Doub eoff=fitfun->GetParError(0); gain=funcs->setScanSign()*mypar[1]; + off=mypar[0]; return gr; diff --git a/slsDetectorCalibration/energyCalibration.h b/slsDetectorCalibration/energyCalibration.h index 904705aa34..7afda027a7 100644 --- a/slsDetectorCalibration/energyCalibration.h +++ b/slsDetectorCalibration/energyCalibration.h @@ -251,7 +251,15 @@ class energyCalibration { #ifdef MYROOT - static TH1F* createMedianHistogram(TH2F* h2, int ch0, int nch); + /** + Creates an histogram with the median of nchannels starting from a specified one. the direction on which it is mediated can be selected (defaults to x=0) + \param h2 2D histogram on which the median will be calculated + \param ch0 starting channel + \param nch number of channels to be mediated + \param direction can be either 0 (x, default) or 1 (y) + \returns a TH1F histogram with the X-axis as a clone of the h2 Y (if direction=0) or X (if direction=0) axis, and on the Y axis the median of the counts of the mediated channels f h2 + */ + static TH1F* createMedianHistogram(TH2F* h2, int ch0, int nch, int direction=0); /** sets the s-curve fit range diff --git a/slsDetectorCalibration/gMapDemo.C b/slsDetectorCalibration/gMapDemo.C new file mode 100644 index 0000000000..51addf69a7 --- /dev/null +++ b/slsDetectorCalibration/gMapDemo.C @@ -0,0 +1,11 @@ +{ + //.L energyCalibration.cpp+ + //.L gainMap.C+ + TFile fin("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_cds_g4.root"); + TH2F *h2=fin.Get("h2"); + TH2F *gMap=gainMap(h2,4); + gMap->Draw("colz"); + + + +} diff --git a/slsDetectorCalibration/gainMap.C b/slsDetectorCalibration/gainMap.C new file mode 100644 index 0000000000..7923fe687a --- /dev/null +++ b/slsDetectorCalibration/gainMap.C @@ -0,0 +1,228 @@ +#define MYROOT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + + +#define FOPT "0" + +TH2F *gainMap(TH2F *h2, float g) { + // int npx, npy; + int npx=160, npy=160; + // det->getDetectorSize(npx, npy); + + TH2F *gMap=new TH2F("gmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); + + Double_t ens[3]={0,8,17.5}, eens[3]={0.,0.1,0.1}; + Double_t peaks[3], epeaks[3]; + + + + int ibin; + TH1D *px; + + + energyCalibration *enCal=new energyCalibration(); + enCal->setPlotFlag(0); + // enCal->setChargeSharing(0); + enCal->setScanSign(1); + + Double_t gain, off, egain, eoff; + + + TList *functions; + TPolyMarker *pm ; + Double_t *peakX, *peakY; + TSpectrum *s=new TSpectrum(); + Double_t mypar[10], emypar[10]; + Double_t prms, np; + int iit=0; + TGraph *glin; + Double_t peakdum, hpeakdum; + + for (int ix=1; ixProjectionX("px",ibin+1,ibin+1); + prms=10*g; + iit=0; + np=s->Search(px,prms,"",0.2); + while (np !=2) { + if (np>2) + prms+=0.5*prms; + else + prms-=0.5*prms; + iit++; + if (iit>=10) + break; + np=s->Search(px,prms,"",0.2); + } + if (np!=2) + cout << "peak search could not converge " << ibin << endl; + if (np==2) { + pm=NULL; + functions=px->GetListOfFunctions(); + if (functions) + pm = (TPolyMarker*)functions->FindObject("TPolyMarker"); + if (pm) { + peakX=pm->GetX(); + peakY=pm->GetY(); + + + if (peakX[0]>peakX[1]) { + peakdum=peakX[0]; + hpeakdum=peakY[0]; + peakX[0]= peakX[1]; + peakY[0]= peakY[1]; + peakX[1]= peakdum; + peakY[1]= hpeakdum; + + } + + cout << "("<< ix << "," << iy << ") " << endl; + for (int ip=0; ipsetFitRange(peakX[ip]-10*g,peakX[ip]+10*g); + mypar[0]=0; + mypar[1]=0; + mypar[2]=peakX[ip]; + mypar[3]=g*10; + mypar[4]=peakY[ip]; + mypar[5]=0; + + + + enCal->setStartParameters(mypar); + enCal->fitSpectrum(px,mypar,emypar); + + + peaks[ip+1]=mypar[2]; + epeaks[ip+1]=emypar[2]; + } + + peaks[0]=0; + epeaks[0]=1; + + // for (int i=0; i<3; i++) cout << i << " " << ens[i] << " " << eens[i]<< " "<< peaks[i]<< " " << epeaks[i] << endl; + + glin= enCal->linearCalibration(3,ens,eens,peaks,epeaks,gain,off,egain,eoff); + + // cout << "Gain " << gain << " off " << off << endl; + if (off>-10 && off<10) { + gMap->SetBinContent(ix+1,iy+1,gain); + gMap->SetBinError(ix+1,iy+1,egain); + } + if (glin) + delete glin; + } + } + + + } + } + + return gMap; +} + + +TH2F *noiseMap(TH2F *h2) { + // int npx, npy; + int npx=160, npy=160; + // det->getDetectorSize(npx, npy); + + TH2F *nMap=new TH2F("nmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); + + int ibin; + TH1D *px; + + for (int ix=0; ixProjectionX("px",ibin+1,ibin+1); + px->Fit("gaus", FOPT); + if (px->GetFunction("gaus")) { + nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2)); + } + // delete px; + } + } + + return nMap; +} + + +THStack *noiseHistos(char *tit) { + char fname[10000]; + + sprintf(fname,"/data/moench_xbox_20140116/noise_map_%s.root",tit); + TFile *fn=new TFile(fname); + TH2F *nmap=(TH2F*)fn->Get("nmap"); + + if (nmap==NULL) { + cout << "No noise map in file " << fname << endl; + + return NULL; + } + + sprintf(fname,"/data/moench_xbox_20140113/gain_map_%s.root",tit); + TFile *fg=new TFile(fname); + TH2F *gmap=(TH2F*)fg->Get("gmap"); + + if (gmap==NULL) { + cout << "No gain map in file " << fname << endl; + + return NULL; + } + + nmap->Divide(gmap); + nmap->Scale(1000./3.6); + + THStack *hs=new THStack(tit,tit); + hs->SetTitle(tit); + + TH1F *h; + char hname[100]; + + cout << tit << endl; + for (int is=0; is<4; is++) { + sprintf(hname,"h%ds",is+1); + + h=new TH1F(hname,tit,500,0,500); + hs->Add(h); + // cout << hs->GetHists()->GetEntries() << endl; + for (int ix=40*is+2; ix<40*(is+1)-2; ix++) { + + for (int iy=2; iy<158; iy++) { + if (ix<100 || ix>120) + h->Fill(nmap->GetBinContent(ix+1,iy+1)); + } + } + cout << is+1 << "SC: " << "" << h->GetMean() << "+-" << h->GetRMS(); + h->Fit("gaus","0Q"); + h->SetLineColor(is+1); + if (h->GetFunction("gaus")) { + h->GetFunction("gaus")->SetLineColor(is+1); + cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParError(1); + } + cout << endl; + } + + // cout << hs->GetHists()->GetEntries() << endl; + + return hs; + + +} diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index e98fea4948..bf7173f0bb 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -26,7 +26,7 @@ using namespace std; #define NR 160 -//#define MY_DEBUG 1 +#define MY_DEBUG 1 #ifdef MY_DEBUG #include #endif diff --git a/slsDetectorCalibration/raedNoiseData.C b/slsDetectorCalibration/raedNoiseData.C index 0e7f24f211..b2021b29fe 100644 --- a/slsDetectorCalibration/raedNoiseData.C +++ b/slsDetectorCalibration/raedNoiseData.C @@ -1,21 +1,24 @@ #include "moenchReadData.C" + void raedNoiseData(char *tit, int sign=1){ + + char fname[1000]; char f[1000]; TFile *fout; THStack *hs2N; - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s.root",tit); + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_0.root",tit); fout=new TFile(fname,"RECREATE"); sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); - hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0); + hs2N=moenchReadData(fname,0,3000,1500,-500,2500,1,0.,1,159,1,159, 0,1); hs2N->SetName(tit); hs2N->SetTitle(tit); (TH2F*)(hs2N->GetHists()->At(0))->Write(); From 71c66775cc605a09f94c7d460edac42a7118ede9 Mon Sep 17 00:00:00 2001 From: jungmann_j Date: Wed, 5 Feb 2014 10:35:29 +0000 Subject: [PATCH 032/104] added Jungrfau02 - does not really work git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@32 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/chiptestBoardData.h | 90 ++++++++++++++ slsDetectorCalibration/jungfrau02Data.h | 135 +++++++++++++++++++++ slsDetectorCalibration/slsDetectorData.h | 6 +- 3 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 slsDetectorCalibration/chiptestBoardData.h create mode 100644 slsDetectorCalibration/jungfrau02Data.h diff --git a/slsDetectorCalibration/chiptestBoardData.h b/slsDetectorCalibration/chiptestBoardData.h new file mode 100644 index 0000000000..1972036f08 --- /dev/null +++ b/slsDetectorCalibration/chiptestBoardData.h @@ -0,0 +1,90 @@ +#ifndef CHIPTESTDATA_H +#define CHIPTESTDATA_H + +#include "slsDetectorData.h" + +class chiptestBoardData : public slsDetectorData { + + + public: + + /** + chiptestBoard data structure. Works for data acquired using the chiptestBoard. + Inherits and implements slsDetectorData. + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param nadc number of adcs + \param offset offset at the beginning of the pattern + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. + + */ + chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): \ + slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; + + + + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + \param buff pointer to the dataset + \returns frame number + + */ + + virtual int getFrameNumber(char *buff){(void)buff; return iframe;}; + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param data pointer to the memory to be analyzed + \param ndata size of frame returned + \param dsize size of the memory slot to be analyzed + \returns always return the pointer to data (no frame loss!) + */ + + virtual char *findNextFrame(char *data, int &ndata, int dsize) {ndata=dsize;setDataSize(dsize); return data;}; + + /** + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete + */ + + virtual char *readNextFrame(ifstream &filebin) { + + int afifo_length=0; //int afifo_length; + uint16_t *afifo_cont;//2343 values for + + if (filebin.is_open()) { + if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) { + setDataSize(afifo_length*nAdc); + afifo_cont=new uint16_t[afifo_length]; + if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) { + iframe++; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } else { + return NULL; + } + } + return NULL; + }; + + private: + const int nAdc; /**=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 + + } + + } + return d^m; + }; + + /** + returns the pixel value as double correcting for the output buffer crosstalk + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns channel value as double + + */ + double getValue(char *data, int ix, int iy=0) { + // cout << "##" << (void*)data << " " << ix << " " < Date: Wed, 5 Feb 2014 10:43:14 +0000 Subject: [PATCH 033/104] now it should work also with jungfrau git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@33 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/chiptestBoardData.h | 2 +- slsDetectorCalibration/slsDetectorData.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/slsDetectorCalibration/chiptestBoardData.h b/slsDetectorCalibration/chiptestBoardData.h index 1972036f08..37efd27701 100644 --- a/slsDetectorCalibration/chiptestBoardData.h +++ b/slsDetectorCalibration/chiptestBoardData.h @@ -3,7 +3,7 @@ #include "slsDetectorData.h" -class chiptestBoardData : public slsDetectorData { +class chiptestBoardData : public virtual slsDetectorData { public: diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index db53498e10..11cbf17e3b 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -154,6 +154,11 @@ class slsDetectorData { */ int getDetectorSize(int &npx, int &npy){npx=nx; npy=ny; return nx*ny;}; + /** Returns the size of the data frame */ + int getDataSize() {return dataSize;}; + /** changes the size of the data frame */ + int setDataSize(int d) {dataSize=d; return dataSize;}; + /** @@ -229,11 +234,6 @@ class slsDetectorData { */ virtual char *readNextFrame(ifstream &filebin)=0; - /** Returns the size of the data frame */ - int getDataSize() {return dataSize;}; - /** changes the size of the data frame */ - int setDataSize(int d) {};//dataSize=d; return dataSize;}; - protected: const int nx; /**< Number of pixels in the x direction */ const int ny; /**< Number of pixels in the y direction */ From 33aee60ab6635e333fc938257ad18c25c3e3732f Mon Sep 17 00:00:00 2001 From: jungmann_j Date: Wed, 5 Feb 2014 10:45:00 +0000 Subject: [PATCH 034/104] now it should work also with jungfrau bis git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@34 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/chiptestBoardData.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/slsDetectorCalibration/chiptestBoardData.h b/slsDetectorCalibration/chiptestBoardData.h index 37efd27701..f6374a761b 100644 --- a/slsDetectorCalibration/chiptestBoardData.h +++ b/slsDetectorCalibration/chiptestBoardData.h @@ -3,7 +3,7 @@ #include "slsDetectorData.h" -class chiptestBoardData : public virtual slsDetectorData { +class chiptestBoardData : public slsDetectorData { public: @@ -22,8 +22,7 @@ class chiptestBoardData : public virtual slsDetectorData { \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. */ - chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): \ - slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; + chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; From a70b13d849ad9e389067129a926e7bd1ccfd03b5 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Wed, 5 Feb 2014 11:31:49 +0000 Subject: [PATCH 035/104] testing jungfrau stuff git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@35 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/chiptestBoardData.h | 2 +- slsDetectorCalibration/jungfrau02Data.h | 6 +- slsDetectorCalibration/jungfrauReadData.C | 243 +++++++++++++++++++++ slsDetectorCalibration/slsDetectorData.h | 2 +- 4 files changed, 248 insertions(+), 5 deletions(-) create mode 100644 slsDetectorCalibration/jungfrauReadData.C diff --git a/slsDetectorCalibration/chiptestBoardData.h b/slsDetectorCalibration/chiptestBoardData.h index f6374a761b..46cacfcc61 100644 --- a/slsDetectorCalibration/chiptestBoardData.h +++ b/slsDetectorCalibration/chiptestBoardData.h @@ -61,7 +61,7 @@ class chiptestBoardData : public slsDetectorData { if (filebin.is_open()) { if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) { - setDataSize(afifo_length*nAdc); + setDataSize(afifo_length*nAdc*sizeof(uint16_t)); afifo_cont=new uint16_t[afifo_length]; if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) { iframe++; diff --git a/slsDetectorCalibration/jungfrau02Data.h b/slsDetectorCalibration/jungfrau02Data.h index 746038821a..eeb4eb7091 100644 --- a/slsDetectorCalibration/jungfrau02Data.h +++ b/slsDetectorCalibration/jungfrau02Data.h @@ -73,11 +73,11 @@ class jungfrau02Data : public chiptestBoardData { uint16_t m=0, d=0; if (ix>=0 && ix=0 && iy=0 && dataMap[iy][ix]8000) + if (*((uint16_t*)(data)+dataMap[iy][ix]+1)>8000) d|=(1<<14); // set gain bit 0 - if (*(uint16_t*)(data+dataMap[iy][ix]+2)>8000) + if (*((uint16_t*)(data)+dataMap[iy][ix]+2)>8000) d|=(1<<15); // set gain bit 1 } diff --git a/slsDetectorCalibration/jungfrauReadData.C b/slsDetectorCalibration/jungfrauReadData.C new file mode 100644 index 0000000000..093d816b51 --- /dev/null +++ b/slsDetectorCalibration/jungfrauReadData.C @@ -0,0 +1,243 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include +#include +#include "jungfrau02Data.h" +#include "moenchCommonMode.h" +#include "singlePhotonDetector.h" + +//#include "MovingStat.h" + +using namespace std; + +#define NC 48 +#define NR 48 + + +#define MY_DEBUG 1 +#ifdef MY_DEBUG +#include +#endif + +/** + +Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis. + + \param fformat file name format + \param tit title of the tree etc. + \param runmin minimum run number + \param runmax max run number + \param nbins number of bins for spectrum hists + \param hmin histo minimum for spectrum hists + \param hmax histo maximum for spectrum hists + \param sign sign of the spectrum to find hits + \param hc readout correlation coefficient with previous pixel + \param xmin minimum x coordinate + \param xmax maximum x coordinate + \param ymin minimum y coordinate + \param ymax maximum y coordinate + \param cmsub enable commonmode subtraction + \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) { + + jungfrau02Data *decoder=new jungfrau02Data(1,0,0); + moenchCommonMode *cmSub=NULL; + if (cmsub) + cmSub=new moenchCommonMode(); + + int nph=0; + int iev=0; + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); + + char *buff; + char fname[10000]; + int nf=0; + + eventType thisEvent=PEDESTAL; + + // int iframe; + // double *data, ped, sigma; + + // data=decoder->getCluster(); + + TH2F *h2; + TH2F *h3; + TH2F *hetaX; + TH2F *hetaY; + + 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); + h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h2); + hs->Add(h3); + hs->Add(hetaX); + hs->Add(hetaY); + } + + + + ifstream filebin; + + + int ix=20, iy=20, ir, ic; + + + Int_t iFrame; + TTree *tall; + if (hitfinder) + tall=filter->initEventTree(tit, &iFrame); + + + + +#ifdef MY_DEBUG + + TCanvas *myC; + TH2F *he; + TCanvas *cH1; + TCanvas *cH2; + TCanvas *cH3; + + if (hitfinder) { + myC=new TCanvas(); + he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); + he->SetStats(kFALSE); + he->Draw("colz"); + cH1=new TCanvas(); + cH1->SetLogz(); + h1->Draw("colz"); + cH2=new TCanvas(); + cH2->SetLogz(); + h2->Draw("colz"); + cH3=new TCanvas(); + cH3->SetLogz(); + h3->Draw("colz"); + } +#endif + filter->newDataSet(); + + + for (int irun=runmin; irunreadNextFrame(filebin))) { + + + if (hitfinder) { + filter->newFrame(); + + //calculate pedestals and common modes + if (cmsub) { + // cout << "cm" << endl; + for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); + } + } + } + + // cout << "new frame " << endl; + + for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); + +#ifdef MY_DEBUG + if (hitfinder) { + if (iev%1000==0) + he->SetBinContent(ix+1-xmin, iy+1-ymin, decoder->getValue(buff,ix,iy)); + //he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); + + } +#endif + + if (nf>1000) { + + h1->Fill(decoder->getValue(buff,ix,iy), iy+NR*ix); + // h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + if (hitfinder) { + + if (thisEvent==PHOTON_MAX ) { + nph++; + +// h2->Fill(filter->getClusterTotal(2), iy+NR*ix); +// h3->Fill(filter->getClusterTotal(3), iy+NR*ix); +// iFrame=decoder->getFrameNumber(buff); + +// tall->Fill(); + + + } + + + } + + + } + } + ////////////////////////////////////////////////////////// + +#ifdef MY_DEBUG + if (iev%1000==0) { + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); + } + iev++; +#endif + nf++; + + cout << "=" ; + delete [] buff; + } + cout << nph << endl; + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + } +// if (hitfinder) +// tall->Write(tall->GetName(),TObject::kOverwrite); + + + + delete decoder; + cout << "Read " << nf << " frames" << endl; + return hs; +} + diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 11cbf17e3b..3eee04c2b0 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -208,10 +208,10 @@ class slsDetectorData { \param buff pointer to the dataset \returns packet number number - */ virtual int getPacketNumber(char *buff)=0; + */ /** From 8c2ed9dcf4b911d990c3dfb5bc2ea9b6c3edc182 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 6 Feb 2014 09:54:10 +0000 Subject: [PATCH 036/104] jungfrau classes not work git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@36 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/doxy.config | 2 +- slsDetectorCalibration/jungfrau02Data.h | 24 +++++++++++-------- slsDetectorCalibration/jungfrauReadData.C | 28 +++++++++++------------ 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/slsDetectorCalibration/doxy.config b/slsDetectorCalibration/doxy.config index b81d49e48b..a8476899c2 100644 --- a/slsDetectorCalibration/doxy.config +++ b/slsDetectorCalibration/doxy.config @@ -80,6 +80,6 @@ LATEX_HIDE_INDICES = YES PREDEFINED = __cplusplus -INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h +INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h chiptestBoardData.h jungfrau02Data.h jungfrauReadData.C OUTPUT_DIRECTORY = docs diff --git a/slsDetectorCalibration/jungfrau02Data.h b/slsDetectorCalibration/jungfrau02Data.h index eeb4eb7091..857e2d9f49 100644 --- a/slsDetectorCalibration/jungfrau02Data.h +++ b/slsDetectorCalibration/jungfrau02Data.h @@ -38,13 +38,13 @@ 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; - // cout << ix << " " << iy << " " << dMap[ix][iy] << endl; - } - } + for (int iy=0; iy<48; iy++) { + for (int ix=0; ix<48; ix++) { + + dMap[iy][ix]=offset+(iy*48+ix)*nAdc; + // cout << ix << " " << iy << " " << dMap[ix][iy] << endl; + } + } for (int ix=0; ix<48; ix++) { for (int iy=0; iy<48; iy++) @@ -74,12 +74,14 @@ class jungfrau02Data : public chiptestBoardData { if (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 - + } } @@ -96,10 +98,12 @@ class jungfrau02Data : public chiptestBoardData { */ double getValue(char *data, int ix, int iy=0) { // cout << "##" << (void*)data << " " << ix << " " <getEventType(buff, ix, iy, cmsub); + thisEvent=filter->getEventType(buff, ix, iy, cmsub); #ifdef MY_DEBUG if (hitfinder) { if (iev%1000==0) - he->SetBinContent(ix+1-xmin, iy+1-ymin, decoder->getValue(buff,ix,iy)); - //he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); } #endif if (nf>1000) { - h1->Fill(decoder->getValue(buff,ix,iy), iy+NR*ix); - // h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + // h1->Fill(decoder->getValue(buff,ix,iy), iy+NR*ix); + h1->Fill(filter->getClusterTotal(1), iy+NR*ix); if (hitfinder) { if (thisEvent==PHOTON_MAX ) { nph++; -// h2->Fill(filter->getClusterTotal(2), iy+NR*ix); -// h3->Fill(filter->getClusterTotal(3), iy+NR*ix); -// iFrame=decoder->getFrameNumber(buff); + h2->Fill(filter->getClusterTotal(2), iy+NR*ix); + h3->Fill(filter->getClusterTotal(3), iy+NR*ix); + iFrame=decoder->getFrameNumber(buff); -// tall->Fill(); + tall->Fill(); } @@ -231,8 +231,8 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int else cout << "could not open file " << fname << endl; } -// if (hitfinder) -// tall->Write(tall->GetName(),TObject::kOverwrite); + if (hitfinder) + tall->Write(tall->GetName(),TObject::kOverwrite); From 835fa04a30582361326b49fcb793e2f213bc5830 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 6 Feb 2014 10:27:50 +0000 Subject: [PATCH 037/104] added script to read jungfrau data git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@37 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/readJungfrauData.C | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 slsDetectorCalibration/readJungfrauData.C diff --git a/slsDetectorCalibration/readJungfrauData.C b/slsDetectorCalibration/readJungfrauData.C new file mode 100644 index 0000000000..fb135cd037 --- /dev/null +++ b/slsDetectorCalibration/readJungfrauData.C @@ -0,0 +1,31 @@ +{ + + //.L jungfrauReadData.C + + + + + + + TFile *fout; + THStack *hs2N; + + fout=new TFile("/scratch/outfile.root","RECREATE"); + + hs2N=moenchReadData"/mnt/slitnas/datadir_jungfrau02/20140131_BeamSLS/datadir_310114/18keV_10us_HIGHG0_CDS550_%d.bin","tit",30,40,1500,-500,2500,1,0.,1,159,1,159, 0,1); + hs2N->SetName("cds_g4"); + hs2N->SetTitle("cds_g4"); + (TH2F*)(hs2N->GetHists()->At(0))->Write(); + + (TH2F*)(hs2N->GetHists()->At(1))->Write(); + (TH2F*)(hs2N->GetHists()->At(2))->Write(); + (TH2F*)(hs2N->GetHists()->At(3))->Write(); + (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + + fout->Close(); + + + +} + From 0e0ab98cd930263d5b1ddc69c2d896db94e4d866 Mon Sep 17 00:00:00 2001 From: jungmann_j Date: Thu, 6 Feb 2014 10:43:38 +0000 Subject: [PATCH 038/104] git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@38 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/readJungfrauData.C | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slsDetectorCalibration/readJungfrauData.C b/slsDetectorCalibration/readJungfrauData.C index fb135cd037..1ed776ad3a 100644 --- a/slsDetectorCalibration/readJungfrauData.C +++ b/slsDetectorCalibration/readJungfrauData.C @@ -1,6 +1,6 @@ { - //.L jungfrauReadData.C + gROOT->ProcessLine(".L jungfrauReadData.C+"); @@ -10,9 +10,9 @@ TFile *fout; THStack *hs2N; - fout=new TFile("/scratch/outfile.root","RECREATE"); + fout=new TFile("/mnt/slitnas/datadir_jungfrau02/20140131_analysis/test/outfile.root","RECREATE"); - hs2N=moenchReadData"/mnt/slitnas/datadir_jungfrau02/20140131_BeamSLS/datadir_310114/18keV_10us_HIGHG0_CDS550_%d.bin","tit",30,40,1500,-500,2500,1,0.,1,159,1,159, 0,1); + hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140131_BeamSLS/datadir_310114/18keV_10us_HIGHG0_CDS550_%d.bin","tit",30,40,1500,-500,2500,1,0.,1,159,1,159, 0,1); hs2N->SetName("cds_g4"); hs2N->SetTitle("cds_g4"); (TH2F*)(hs2N->GetHists()->At(0))->Write(); From 6b7d0d8c55f226d6a5ff74e3de1b50dc5b8d4530 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 6 Feb 2014 10:46:11 +0000 Subject: [PATCH 039/104] readJungfrauData works git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@39 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/readJungfrauData.C | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsDetectorCalibration/readJungfrauData.C b/slsDetectorCalibration/readJungfrauData.C index 1ed776ad3a..9a8a16a203 100644 --- a/slsDetectorCalibration/readJungfrauData.C +++ b/slsDetectorCalibration/readJungfrauData.C @@ -12,7 +12,7 @@ fout=new TFile("/mnt/slitnas/datadir_jungfrau02/20140131_analysis/test/outfile.root","RECREATE"); - hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140131_BeamSLS/datadir_310114/18keV_10us_HIGHG0_CDS550_%d.bin","tit",30,40,1500,-500,2500,1,0.,1,159,1,159, 0,1); + hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140131_BeamSLS/datadir_310114/18keV_10us_HIGHG0_CDS550_%d.bin","tit",30,40,1500,-500,2500,1,0.,1,47,1,47, 0,1); hs2N->SetName("cds_g4"); hs2N->SetTitle("cds_g4"); (TH2F*)(hs2N->GetHists()->At(0))->Write(); @@ -23,7 +23,7 @@ (TH2F*)(hs2N->GetHists()->At(4))->Write(); - fout->Close(); + // fout->Close(); From b90287e7241db53f2b34f4fd5cf1174249337f4c Mon Sep 17 00:00:00 2001 From: jungmann_j Date: Thu, 6 Feb 2014 15:38:26 +0000 Subject: [PATCH 040/104] New: jungfrau02CommonMode.h. Some extra documentation for Jungfrau. git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@40 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/chiptestBoardData.h | 8 +++--- slsDetectorCalibration/jungfrau02Data.h | 6 ++-- slsDetectorCalibration/jungfrauReadData.C | 33 +++++++++++----------- slsDetectorCalibration/readJungfrauData.C | 23 ++++++--------- slsDetectorCalibration/slsDetectorData.h | 2 +- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/slsDetectorCalibration/chiptestBoardData.h b/slsDetectorCalibration/chiptestBoardData.h index 46cacfcc61..86bdbcc35e 100644 --- a/slsDetectorCalibration/chiptestBoardData.h +++ b/slsDetectorCalibration/chiptestBoardData.h @@ -1,5 +1,5 @@ #ifndef CHIPTESTDATA_H -#define CHIPTESTDATA_H +#define CHIPTESTDATA_H #include "slsDetectorData.h" @@ -22,7 +22,7 @@ class chiptestBoardData : public slsDetectorData { \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. */ - chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; + chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; // should be? nadc*(npx*npy+offset) @@ -56,8 +56,8 @@ class chiptestBoardData : public slsDetectorData { virtual char *readNextFrame(ifstream &filebin) { - int afifo_length=0; //int afifo_length; - uint16_t *afifo_cont;//2343 values for + int afifo_length=0; + uint16_t *afifo_cont; if (filebin.is_open()) { if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) { diff --git a/slsDetectorCalibration/jungfrau02Data.h b/slsDetectorCalibration/jungfrau02Data.h index 857e2d9f49..2a43dad1f2 100644 --- a/slsDetectorCalibration/jungfrau02Data.h +++ b/slsDetectorCalibration/jungfrau02Data.h @@ -1,5 +1,5 @@ #ifndef JUNGFRAU02DATA_H -#define JUNGFRAU02DATA_H +#define JUNGFRAU02DATA_H #include "chiptestBoardData.h" @@ -13,7 +13,7 @@ class jungfrau02Data : public chiptestBoardData { /** Implements the chiptestBoardData structure for the jungfrau02 prototype - (48x48 pixels, ADC2 for analog output, eventually 2 more for digital bits , offset configurable etc.) + (48x48 pixels, ADC2 for analog output, 2 more ADCs used for readout of digital bits, pixel offset configurable.) \param c crosstalk parameter for the output buffer */ @@ -61,7 +61,7 @@ class jungfrau02Data : public chiptestBoardData { /** - Returns the value of the selected channel for the given dataset. Since the ADC is only 14bit wide, if the gain bits are read out they are returned in bit 14-15 + Returns the value of the selected channel for the given dataset. Since the ADC is only 14bit wide, only bit 0-13 are occupied. If the gain bits are read out, they are returned in bit 14-15. \param data pointer to the dataset (including headers etc) \param ix pixel number in the x direction \param iy pixel number in the y direction diff --git a/slsDetectorCalibration/jungfrauReadData.C b/slsDetectorCalibration/jungfrauReadData.C index 89b8df107a..b59d75c44d 100644 --- a/slsDetectorCalibration/jungfrauReadData.C +++ b/slsDetectorCalibration/jungfrauReadData.C @@ -16,6 +16,7 @@ #include #include "jungfrau02Data.h" #include "moenchCommonMode.h" +#include "jungfrau02CommonMode.h" #include "singlePhotonDetector.h" //#include "MovingStat.h" @@ -33,7 +34,7 @@ using namespace std; /** -Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis. +Loops over data file to find single photons, fills the tree (and writes it to file, although the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (48*x+y) on the y axis. \param fformat file name format \param tit title of the tree etc. @@ -48,8 +49,8 @@ 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 - \param hitfinder if 0, performs pedestal subtraction, not hit finding + \param cmsub enable commonmode subtraction -> Currently, CM subtraction is not implemented for Jungfrau! + \param hitfinder if 0: performs pedestal subtraction, not hit finding; if 1: performs both pedestal subtraction and hit finding \returns pointer to histo stack with cluster spectra */ @@ -57,7 +58,7 @@ Loops over data file to find single photons, fills the tree (and writes it to fi 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) { jungfrau02Data *decoder=new jungfrau02Data(1,0,0); - moenchCommonMode *cmSub=NULL; + jungfrau02CommonMode *cmSub=NULL;//moenchCommonMode *cmSub=NULL; // // if (cmsub) // cmSub=new moenchCommonMode(); @@ -78,8 +79,8 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int TH2F *h2; TH2F *h3; - TH2F *hetaX; - TH2F *hetaY; + TH2F *hetaX; // not needed for JF? + TH2F *hetaY; // not needed for JF? THStack *hs=new THStack("hs",fformat); @@ -91,12 +92,12 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int if (hitfinder) { h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); - hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // not needed for JF? + hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // not needed for JF? hs->Add(h2); hs->Add(h3); - hs->Add(hetaX); - hs->Add(hetaY); + hs->Add(hetaX); // not needed for JF? + hs->Add(hetaY); // not needed for JF? } @@ -142,7 +143,7 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int filter->newDataSet(); - for (int irun=runmin; irunWrite(tall->GetName(),TObject::kOverwrite); @@ -237,7 +238,7 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int delete decoder; - cout << "Read " << nf << " frames" << endl; + cout << "Read " << nf << " frames." << endl; return hs; } diff --git a/slsDetectorCalibration/readJungfrauData.C b/slsDetectorCalibration/readJungfrauData.C index 9a8a16a203..c472d2d753 100644 --- a/slsDetectorCalibration/readJungfrauData.C +++ b/slsDetectorCalibration/readJungfrauData.C @@ -1,29 +1,24 @@ -{ +{ // script to run Jungfrau data analysis 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! + 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"); - - - TFile *fout; - THStack *hs2N; - - fout=new TFile("/mnt/slitnas/datadir_jungfrau02/20140131_analysis/test/outfile.root","RECREATE"); - - hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140131_BeamSLS/datadir_310114/18keV_10us_HIGHG0_CDS550_%d.bin","tit",30,40,1500,-500,2500,1,0.,1,47,1,47, 0,1); - hs2N->SetName("cds_g4"); - hs2N->SetTitle("cds_g4"); - (TH2F*)(hs2N->GetHists()->At(0))->Write(); - + (TH2F*)(hs2N->GetHists()->At(0))->Write(); // write hists (TH2F*)(hs2N->GetHists()->At(1))->Write(); (TH2F*)(hs2N->GetHists()->At(2))->Write(); (TH2F*)(hs2N->GetHists()->At(3))->Write(); (TH2F*)(hs2N->GetHists()->At(4))->Write(); - // fout->Close(); + fout->Close(); diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 3eee04c2b0..0d4067e137 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -1,5 +1,5 @@ #ifndef SLSDETECTORDATA_H -#define SLSDETECTORDATA_H +#define SLSDETECTORDATA_H #include #include From 0a86011998f65eff5686f9872b5206684eea6701 Mon Sep 17 00:00:00 2001 From: jungmann_j Date: Thu, 6 Feb 2014 15:45:08 +0000 Subject: [PATCH 041/104] git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@41 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/doxy.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/doxy.config b/slsDetectorCalibration/doxy.config index a8476899c2..7d2a396ff4 100644 --- a/slsDetectorCalibration/doxy.config +++ b/slsDetectorCalibration/doxy.config @@ -80,6 +80,6 @@ LATEX_HIDE_INDICES = YES PREDEFINED = __cplusplus -INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h chiptestBoardData.h jungfrau02Data.h jungfrauReadData.C +INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h chiptestBoardData.h jungfrau02Data.h jungfrauReadData.C jungfrau02CommonMode.h OUTPUT_DIRECTORY = docs From 26003dc8676dc66cc510c8e54239d1172cf74ffc Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 13 Feb 2014 10:53:30 +0000 Subject: [PATCH 042/104] added gotthard specific instructions git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@42 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/gotthardModuleData.h | 165 ++++++++++++++++++++ slsDetectorCalibration/moench02ModuleData.h | 7 +- slsDetectorCalibration/slsDetectorData.h | 28 +++- slsDetectorCalibration/slsReceiverData.h | 134 +++++++++------- 4 files changed, 277 insertions(+), 57 deletions(-) create mode 100644 slsDetectorCalibration/gotthardModuleData.h diff --git a/slsDetectorCalibration/gotthardModuleData.h b/slsDetectorCalibration/gotthardModuleData.h new file mode 100644 index 0000000000..297f959894 --- /dev/null +++ b/slsDetectorCalibration/gotthardModuleData.h @@ -0,0 +1,165 @@ +#ifndef GOTTHARDMODULEDATA_H +#define GOTTHARDMODULEDATA_H +#include "slsReceiverData.h" + + + +#define X_PIXELS 1280 +#define Y_PIXELS 1 +#define NPACKETS 2 +#define BUFFERSIZE 1286 +#define NUMPACKETS 2 +#define NUMSHORTPACKETS 1 +#define FRAMEMASK 0xFFFFFFFE +#define PACKETMASK 1 +#define FRAMEOFFSET 0x1 +#define SHORT_FRAMEMASK 0xFFFFFFFF +#define SHORT_PACKETMASK 0 +#define SHORT_FRAMEOFFSET 0 + + +class gotthardModuleData : public slsReceiverData { +public: + + + + + /** + Implements the slsReceiverData structure for the gotthard read out by a module i.e. using the slsReceiver + (1x1280 pixels, 2 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + gotthardModuleData(double c=0, bool s=-1): slsReceiverData(X_PIXELS, Y_PIXELS, NPACKETS, BUFFERSIZE), xtalk(c),shortFrame(s) { + + + if(shortFrame == -1) + shortFrame = 0; + else + shortFrame = 1; + + uint16_t **dMask; + int **dMap; + int ix, iy; + int initial_offset = 2; + int offset = initial_offset; + + + dMask=new uint16_t*[Y_PIXELS]; + dMap=new int*[Y_PIXELS]; + for (int i = 0; i < Y_PIXELS; i++) { + dMap[i] = new int[X_PIXELS]; + dMask[i] = new uint16_t[X_PIXELS]; + } + + + for(ix=0; ix::getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); + }; + + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ + double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ + double getXTalk() {return xtalk;} + + + + + + + +private: + + double xtalk; /** { */ - moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), + moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), xtalk(c) { @@ -65,10 +65,11 @@ class moench02ModuleData : public slsReceiverData { setDataMap(dMap); setDataMask(dMask); + setFrameIndexMask(0xffffff00); + setPacketIndexMask(0xff); + setFrameIndexOffset(8); - - }; diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 0d4067e137..ffa2393738 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -82,7 +82,7 @@ class slsDetectorData { for (int ix=0; ix { \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. */ - slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; + slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize),frameIndexMask(0),packetIndexMask(0),frameIndexOffset(0) {}; - - /** + /** + + Sets frame index mask for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. + \param m frame index mask + + */ + + virtual void setFrameIndexMask(uint32_t m) {frameIndexMask = m;}; + + /** + + Sets the packet index mask for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. + \param m packet index mask + + */ + + virtual void setPacketIndexMask(uint32_t m) {packetIndexMask = m;}; + + /** + + Sets the frame index offset for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. + \param o frame index offset + */ + + virtual void setFrameIndexOffset(int o) {frameIndexOffset = o;}; + + /** Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. \param buff pointer to the dataset \returns frame number - */ + */ - virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; + virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(frameIndexMask))>>frameIndexOffset;};/*{return ((*(int*)buff)&(0xffffff00))>>8;};*/ - /** + /** Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. \param buff pointer to the dataset @@ -45,7 +70,7 @@ class slsReceiverData : public slsDetectorData { */ - virtual int getPacketNumber(char *buff) {return (*(int*)buff)&0xff;}; + virtual int getPacketNumber(char *buff) {return (*(int*)buff)&packetIndexMask;};/*{return (*(int*)buff)&0xff;};*/ @@ -61,52 +86,52 @@ class slsReceiverData : public slsDetectorData { */ virtual char *findNextFrame(char *data, int &ndata, int dsize) { - char *retval=NULL, *p=data; - int dd=0; - int fn, fnum=-1, np=0, pnum=-1; - while (dd<=(dsize-packetSize)) { - pnum=getPacketNumber(p); - fn=getFrameNumber(p); - - - if (pnum<1 || pnum>nPackets) { - cout << "Bad packet number " << pnum << " frame "<< fn << endl; - retval=NULL; - np=0; - } else if (pnum==1) { - fnum=fn; - retval=p; - if (np>0) - /*cout << "*Incomplete frame number " << fnum << endl;*/ - np=0; - } else if (fn!=fnum) { - if (fnum!=-1) { - /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ - retval=NULL; - } - np=0; - } - p+=packetSize; - dd+=packetSize; - np++; - // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; - if (np==nPackets) - if (pnum==nPackets) { - // cout << "Frame found!" << endl; - break; - } else { - cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; - retval=NULL; - } - } - if (np0) - cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; - } - - ndata=np*packetSize; - // cout << "return " << ndata << endl; - return retval; + char *retval=NULL, *p=data; + int dd=0; + int fn, fnum=-1, np=0, pnum=-1; + while (dd<=(dsize-packetSize)) { + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + + + if (pnum<1 || pnum>nPackets) { + cout << "Bad packet number " << pnum << " frame "<< fn << endl; + retval=NULL; + np=0; + } else if (pnum==1) { + fnum=fn; + retval=p; + if (np>0) + /*cout << "*Incomplete frame number " << fnum << endl;*/ + np=0; + } else if (fn!=fnum) { + if (fnum!=-1) { + /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ + retval=NULL; + } + np=0; + } + p+=packetSize; + dd+=packetSize; + np++; + // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; + if (np==nPackets) + if (pnum==nPackets) { + // cout << "Frame found!" << endl; + break; + } else { + cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; + retval=NULL; + } + } + if (np0) + cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; + } + + ndata=np*packetSize; + // cout << "return " << ndata << endl; + return retval; }; /** @@ -165,6 +190,9 @@ class slsReceiverData : public slsDetectorData { private: const int nPackets; /** Date: Tue, 18 Feb 2014 16:36:46 +0000 Subject: [PATCH 043/104] gotthard compression works..without shortframe git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@43 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/gotthardModuleData.h | 42 +++++++++++++-------- slsDetectorCalibration/moench02ModuleData.h | 4 -- slsDetectorCalibration/slsDetectorData.h | 29 +------------- slsDetectorCalibration/slsReceiverData.h | 37 ++---------------- 4 files changed, 32 insertions(+), 80 deletions(-) diff --git a/slsDetectorCalibration/gotthardModuleData.h b/slsDetectorCalibration/gotthardModuleData.h index 297f959894..d7aa9ba6aa 100644 --- a/slsDetectorCalibration/gotthardModuleData.h +++ b/slsDetectorCalibration/gotthardModuleData.h @@ -13,9 +13,6 @@ #define FRAMEMASK 0xFFFFFFFE #define PACKETMASK 1 #define FRAMEOFFSET 0x1 -#define SHORT_FRAMEMASK 0xFFFFFFFF -#define SHORT_PACKETMASK 0 -#define SHORT_FRAMEOFFSET 0 class gotthardModuleData : public slsReceiverData { @@ -32,8 +29,7 @@ class gotthardModuleData : public slsReceiverData { */ - gotthardModuleData(double c=0, bool s=-1): slsReceiverData(X_PIXELS, Y_PIXELS, NPACKETS, BUFFERSIZE), xtalk(c),shortFrame(s) { - + gotthardModuleData(double c=0, int s=-1): slsReceiverData(X_PIXELS, Y_PIXELS, NPACKETS, BUFFERSIZE), xtalk(c),shortFrame(s) { if(shortFrame == -1) shortFrame = 0; @@ -84,19 +80,31 @@ class gotthardModuleData : public slsReceiverData { setDataMap(dMap); setDataMask(dMask); - if(shortFrame){ - setFrameIndexMask(FRAMEMASK); - setPacketIndexMask(PACKETMASK); - setFrameIndexOffset(FRAMEOFFSET); - }else{ - setFrameIndexMask(SHORT_FRAMEMASK); - setPacketIndexMask(SHORT_PACKETMASK); - setFrameIndexOffset(SHORT_FRAMEOFFSET); - } }; + /** + + Returns the frame number for the given dataset. + \param buff pointer to the dataset + \returns frame number + + */ + + int getFrameNumber(char *buff){ + int np=(*(int*)buff); + + if(shortFrame) + return np; + + //gotthards frame header must be incremented + ++np; + //packet index should be 1 or 2 + return ((np&FRAMEMASK)>>FRAMEOFFSET); + }; + + /** gets the packets number (last packet is labelled with 0 and is replaced with 40) @@ -109,9 +117,11 @@ class gotthardModuleData : public slsReceiverData { if(shortFrame) return 1; - int np=(*(int*)buff)&0x1; + int np=(*(int*)buff); + //gotthards frame header must be incremented ++np; - return np; + //packet index should be 1 or 2 + return ((np&PACKETMASK)+1); }; diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index 6f39a96430..f248fd1a48 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -65,10 +65,6 @@ class moench02ModuleData : public slsReceiverData { setDataMap(dMap); setDataMask(dMask); - setFrameIndexMask(0xffffff00); - setPacketIndexMask(0xff); - setFrameIndexOffset(8); - }; diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index ffa2393738..3ca006476a 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -191,31 +191,6 @@ class slsDetectorData { */ virtual double getValue(char *data, int ix, int iy=0) {return (double)getChannel(data, ix, iy);}; - /** - - Sets frame index mask for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. - \param m frame index mask - - */ - - virtual void setFrameIndexMask(uint32_t m)=0; - - /** - - Sets the packet index mask for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. - \param m packet index mask - - */ - - virtual void setPacketIndexMask(uint32_t m)=0; - - /** - - Sets the frame index offset for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. - \param o frame index offset - */ - - virtual void setFrameIndexOffset(int o)=0; /** @@ -234,10 +209,10 @@ class slsDetectorData { \param buff pointer to the dataset \returns packet number number - +*/ virtual int getPacketNumber(char *buff)=0; - */ + /* /** diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index 0e5b3529cb..5a58096fb7 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -23,35 +23,9 @@ class slsReceiverData : public slsDetectorData { \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. */ - slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize),frameIndexMask(0),packetIndexMask(0),frameIndexOffset(0) {}; + slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; - /** - - Sets frame index mask for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. - \param m frame index mask - - */ - - virtual void setFrameIndexMask(uint32_t m) {frameIndexMask = m;}; - - /** - - Sets the packet index mask for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. - \param m packet index mask - - */ - - virtual void setPacketIndexMask(uint32_t m) {packetIndexMask = m;}; - - /** - - Sets the frame index offset for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. - \param o frame index offset - */ - - virtual void setFrameIndexOffset(int o) {frameIndexOffset = o;}; - /** Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. @@ -60,7 +34,7 @@ class slsReceiverData : public slsDetectorData { */ - virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(frameIndexMask))>>frameIndexOffset;};/*{return ((*(int*)buff)&(0xffffff00))>>8;};*/ + virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; /** @@ -70,7 +44,7 @@ class slsReceiverData : public slsDetectorData { */ - virtual int getPacketNumber(char *buff) {return (*(int*)buff)&packetIndexMask;};/*{return (*(int*)buff)&0xff;};*/ + virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;}; @@ -99,11 +73,11 @@ class slsReceiverData : public slsDetectorData { retval=NULL; np=0; } else if (pnum==1) { - fnum=fn; retval=p; if (np>0) /*cout << "*Incomplete frame number " << fnum << endl;*/ np=0; + fnum=fn; } else if (fn!=fnum) { if (fnum!=-1) { /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ @@ -190,9 +164,6 @@ class slsReceiverData : public slsDetectorData { private: const int nPackets; /** Date: Thu, 20 Feb 2014 13:24:52 +0000 Subject: [PATCH 044/104] gotthard works for short frame git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@44 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/gotthardModuleData.h | 48 ++----- .../gotthardShortModuleData.h | 128 ++++++++++++++++++ slsDetectorCalibration/slsDetectorData.h | 1 - 3 files changed, 138 insertions(+), 39 deletions(-) create mode 100644 slsDetectorCalibration/gotthardShortModuleData.h diff --git a/slsDetectorCalibration/gotthardModuleData.h b/slsDetectorCalibration/gotthardModuleData.h index d7aa9ba6aa..bd1d8280a7 100644 --- a/slsDetectorCalibration/gotthardModuleData.h +++ b/slsDetectorCalibration/gotthardModuleData.h @@ -8,8 +8,7 @@ #define Y_PIXELS 1 #define NPACKETS 2 #define BUFFERSIZE 1286 -#define NUMPACKETS 2 -#define NUMSHORTPACKETS 1 + #define FRAMEMASK 0xFFFFFFFE #define PACKETMASK 1 #define FRAMEOFFSET 0x1 @@ -29,12 +28,7 @@ class gotthardModuleData : public slsReceiverData { */ - gotthardModuleData(double c=0, int s=-1): slsReceiverData(X_PIXELS, Y_PIXELS, NPACKETS, BUFFERSIZE), xtalk(c),shortFrame(s) { - - if(shortFrame == -1) - shortFrame = 0; - else - shortFrame = 1; + gotthardModuleData(double c=0): slsReceiverData(X_PIXELS, Y_PIXELS, NPACKETS, BUFFERSIZE), xtalk(c) { uint16_t **dMask; int **dMap; @@ -42,7 +36,6 @@ class gotthardModuleData : public slsReceiverData { int initial_offset = 2; int offset = initial_offset; - dMask=new uint16_t*[Y_PIXELS]; dMap=new int*[Y_PIXELS]; for (int i = 0; i < Y_PIXELS; i++) { @@ -50,34 +43,21 @@ class gotthardModuleData : public slsReceiverData { dMask[i] = new uint16_t[X_PIXELS]; } - for(ix=0; ix { int getFrameNumber(char *buff){ int np=(*(int*)buff); - - if(shortFrame) - return np; - //gotthards frame header must be incremented ++np; //packet index should be 1 or 2 @@ -114,9 +90,6 @@ class gotthardModuleData : public slsReceiverData { */ int getPacketNumber(char *buff){ - if(shortFrame) - return 1; - int np=(*(int*)buff); //gotthards frame header must be incremented ++np; @@ -165,7 +138,6 @@ class gotthardModuleData : public slsReceiverData { private: double xtalk; /** { +public: + + + + + /** + Implements the slsReceiverData structure for the gotthard short read out by a module i.e. using the slsReceiver + (1x256 pixels, 1 packet 256 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + gotthardShortModuleData(double c=0): slsReceiverData(X_PIXELS, Y_PIXELS, NPACKETS, BUFFERSIZE), xtalk(c){ + + uint16_t **dMask; + int **dMap; + int ix, iy; + int offset = 2; + + dMask=new uint16_t*[Y_PIXELS]; + dMap=new int*[Y_PIXELS]; + for (int i = 0; i < Y_PIXELS; i++) { + dMap[i] = new int[X_PIXELS]; + dMask[i] = new uint16_t[X_PIXELS]; + } + + for(ix=0; ix::getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); + }; + + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ + double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ + double getXTalk() {return xtalk;} + + + + + + + +private: + + double xtalk; /** Date: Fri, 7 Mar 2014 12:07:40 +0000 Subject: [PATCH 045/104] included without root writing git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@45 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/gotthardModuleData.h | 33 ++++++++++--------- .../gotthardShortModuleData.h | 29 ++++++++-------- slsDetectorCalibration/singlePhotonDetector.h | 10 ++++-- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/slsDetectorCalibration/gotthardModuleData.h b/slsDetectorCalibration/gotthardModuleData.h index bd1d8280a7..3f674af57c 100644 --- a/slsDetectorCalibration/gotthardModuleData.h +++ b/slsDetectorCalibration/gotthardModuleData.h @@ -4,10 +4,7 @@ -#define X_PIXELS 1280 -#define Y_PIXELS 1 -#define NPACKETS 2 -#define BUFFERSIZE 1286 + #define FRAMEMASK 0xFFFFFFFE #define PACKETMASK 1 @@ -28,7 +25,7 @@ class gotthardModuleData : public slsReceiverData { */ - gotthardModuleData(double c=0): slsReceiverData(X_PIXELS, Y_PIXELS, NPACKETS, BUFFERSIZE), xtalk(c) { + gotthardModuleData(double c=0): slsReceiverData(xpixels, ypixels, npackets, buffersize), xtalk(c) { uint16_t **dMask; int **dMap; @@ -36,23 +33,23 @@ class gotthardModuleData : public slsReceiverData { int initial_offset = 2; int offset = initial_offset; - dMask=new uint16_t*[Y_PIXELS]; - dMap=new int*[Y_PIXELS]; - for (int i = 0; i < Y_PIXELS; i++) { - dMap[i] = new int[X_PIXELS]; - dMask[i] = new uint16_t[X_PIXELS]; + dMask=new uint16_t*[ypixels]; + dMap=new int*[ypixels]; + for (int i = 0; i < ypixels; i++) { + dMap[i] = new int[xpixels]; + dMask[i] = new uint16_t[xpixels]; } - for(ix=0; ix { private: double xtalk; /** { */ - gotthardShortModuleData(double c=0): slsReceiverData(X_PIXELS, Y_PIXELS, NPACKETS, BUFFERSIZE), xtalk(c){ + gotthardShortModuleData(double c=0): slsReceiverData(xpixels, ypixels, npackets, buffersize), xtalk(c){ uint16_t **dMask; int **dMap; int ix, iy; int offset = 2; - dMask=new uint16_t*[Y_PIXELS]; - dMap=new int*[Y_PIXELS]; - for (int i = 0; i < Y_PIXELS; i++) { - dMap[i] = new int[X_PIXELS]; - dMask[i] = new uint16_t[X_PIXELS]; + dMask=new uint16_t*[ypixels]; + dMap=new int*[ypixels]; + for (int i = 0; i < ypixels; i++) { + dMap[i] = new int[xpixels]; + dMask[i] = new uint16_t[xpixels]; } - for(ix=0; ix { private: double xtalk; /** @@ -92,6 +92,8 @@ class singlePhotonDetector { setClusterSize(csize); }; + + /** destructor. Deletes the cluster structure and the pdestalSubtraction array */ @@ -324,7 +326,7 @@ class singlePhotonDetector { \returns event mask enum for the given pixel */ eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];}; - + #ifdef MYROOT1 /** generates a tree and maps the branches @@ -349,6 +351,9 @@ class singlePhotonDetector { // tall->Branch("rms",&(cluster->rms),"rms/D"); return tall; }; +#else + /** write cluster to filer*/ + void writeCluster(FILE* myFile){cluster->write(myFile);}; #endif @@ -373,7 +378,6 @@ class singlePhotonDetector { double tot; /**< sum of the 3x3 cluster */ double quadTot; /**< sum of the maximum 2x2cluster */ - }; From fb40e2236e283b461eb8bd8503136fe85897815c Mon Sep 17 00:00:00 2001 From: l_msdetect Date: Wed, 19 Mar 2014 17:02:17 +0000 Subject: [PATCH 046/104] changes from pcmoench01 git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@46 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/demoCreateTree.C | 2 +- slsDetectorCalibration/gMapDemo.C | 18 ++++-- slsDetectorCalibration/gainMap.C | 55 ++++++++++++++-- slsDetectorCalibration/moench02ModuleData.h | 39 ++++++++++++ slsDetectorCalibration/moenchReadData.C | 6 +- slsDetectorCalibration/moenchReadDataMT.C | 19 ++++++ slsDetectorCalibration/raedNoiseData.C | 62 +++++++++++++++++-- slsDetectorCalibration/singlePhotonDetector.h | 12 ++-- slsDetectorCalibration/slsDetectorData.h | 2 +- 9 files changed, 192 insertions(+), 23 deletions(-) diff --git a/slsDetectorCalibration/demoCreateTree.C b/slsDetectorCalibration/demoCreateTree.C index d14aa8b02d..773a9ddac1 100644 --- a/slsDetectorCalibration/demoCreateTree.C +++ b/slsDetectorCalibration/demoCreateTree.C @@ -12,7 +12,7 @@ fout=new TFile("/scratch/outfile.root","RECREATE"); - hs2N=moenchReadData("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_cds_g4_f00000%%04d000_0.raw",0,20,1500,-500,2500,1,0.,1,159,1,159, 0,1); + hs2N=moenchReadData("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_12us_120V_cds_g4_f00000%04d000_0.raw","dum",0,20,1500,-500,2500,1,0.,1,159,1,159, 0,1); hs2N->SetName("cds_g4"); hs2N->SetTitle("cds_g4"); (TH2F*)(hs2N->GetHists()->At(0))->Write(); diff --git a/slsDetectorCalibration/gMapDemo.C b/slsDetectorCalibration/gMapDemo.C index 51addf69a7..c48ab002cd 100644 --- a/slsDetectorCalibration/gMapDemo.C +++ b/slsDetectorCalibration/gMapDemo.C @@ -1,11 +1,19 @@ -{ +void gMap(char *tit, float g=1) { //.L energyCalibration.cpp+ //.L gainMap.C+ - TFile fin("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_cds_g4.root"); - TH2F *h2=fin.Get("h2"); - TH2F *gMap=gainMap(h2,4); - gMap->Draw("colz"); + char fname[1000]; + + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s.root",tit); + TFile fin(fname); + TH2F *h2=fin.Get("h2"); + TH2F *gMap=(TH2F*)gainMap(h2,g); + gMap->Draw("colz"); + sprintf(fname,"/data/moench_xbox_20140113/gain_map_%s.root",tit); + TFile fout(fname,"RECREATE"); + gMap->Write(); + + fout.Close(); } diff --git a/slsDetectorCalibration/gainMap.C b/slsDetectorCalibration/gainMap.C index 7923fe687a..3c7abef3c1 100644 --- a/slsDetectorCalibration/gainMap.C +++ b/slsDetectorCalibration/gainMap.C @@ -137,7 +137,7 @@ TH2F *gainMap(TH2F *h2, float g) { } -TH2F *noiseMap(TH2F *h2) { +TH2F *noiseMap(TH2F *h2, TH2F *gMap=NULL) { // int npx, npy; int npx=160, npy=160; // det->getDetectorSize(npx, npy); @@ -150,8 +150,8 @@ TH2F *noiseMap(TH2F *h2) { for (int ix=0; ixProjectionX("px",ibin+1,ibin+1); + ibin=h2->GetYaxis()->FindBin(ix*npy+iy); + px=h2->ProjectionX("px",ibin,ibin); px->Fit("gaus", FOPT); if (px->GetFunction("gaus")) { nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2)); @@ -159,6 +159,10 @@ TH2F *noiseMap(TH2F *h2) { // delete px; } } + if (gMap) { + nMap->Divide(gMap); + nMap->Scale(1000./3.6); + } return nMap; } @@ -167,7 +171,7 @@ TH2F *noiseMap(TH2F *h2) { THStack *noiseHistos(char *tit) { char fname[10000]; - sprintf(fname,"/data/moench_xbox_20140116/noise_map_%s.root",tit); + sprintf(fname,"/data/moench_xbox_201401_trees/noise_map_%s.root",tit); TFile *fn=new TFile(fname); TH2F *nmap=(TH2F*)fn->Get("nmap"); @@ -177,7 +181,7 @@ THStack *noiseHistos(char *tit) { return NULL; } - sprintf(fname,"/data/moench_xbox_20140113/gain_map_%s.root",tit); + sprintf(fname,"/data/moench_xbox_201401_trees/gain_map_%s.root",tit); TFile *fg=new TFile(fname); TH2F *gmap=(TH2F*)fg->Get("gmap"); @@ -226,3 +230,44 @@ THStack *noiseHistos(char *tit) { } + +THStack *noiseHistos(TH2F *nmap) { + + + char tit[1000]; + + strcpy(tit,nmap->GetTitle()); + THStack *hs=new THStack(tit,tit); + hs->SetTitle(tit); + + TH1F *h; + char hname[100]; + cout << tit << endl; + for (int is=0; is<4; is++) { + sprintf(hname,"h%ds",is+1); + h=new TH1F(hname,tit,500,0,500); + hs->Add(h); + // cout << hs->GetHists()->GetEntries() << endl; + for (int ix=40*is+2; ix<40*(is+1)-2; ix++) { + + for (int iy=2; iy<158; iy++) { + if (ix<100 || ix>120) + h->Fill(nmap->GetBinContent(ix+1,iy+1)); + } + } + cout << is+1 << "SC: " << "" << h->GetMean() << "+-" << h->GetRMS(); + h->Fit("gaus","0Q"); + h->SetLineColor(is+1); + if (h->GetFunction("gaus")) { + h->GetFunction("gaus")->SetLineColor(is+1); + cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParError(1); + } + cout << endl; + } + + // cout << hs->GetHists()->GetEntries() << endl; + + return hs; + + +} diff --git a/slsDetectorCalibration/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index f248fd1a48..8c0d0c337c 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -129,6 +129,45 @@ class moench02ModuleData : public slsReceiverData { }; +class moench02OversampledData : public moench02ModuleData { + public: + moench02OversampledData(int nos, int off=0): moench02ModuleData(), nSamples(nos), offset(off){}; + + /** + returns the pixel value as double correcting for the output buffer crosstalk + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns channel value as double + + */ + double getValue(char *data, int ix, int iy=0) { + double v=0, is=0; + int ix1, iy1, isc=ix/40, ip=ix%40, ip1=iy*nSamples*40+ix; + + if (iy*nSamples<160) { + for (int i=offset; i=0 && iy1>=0 && ix1<160 && iy1<160) { + v+=moench02ModuleData::getValue(data,ix1,iy1); + is++; + } + } + if (is>0) + v/=is; + } + + return v; + }; + + + private: + int nSamples; + int offset; +}; + #endif diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index bf7173f0bb..f829ed791b 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -26,7 +26,7 @@ using namespace std; #define NR 160 -#define MY_DEBUG 1 +//#define MY_DEBUG 1 #ifdef MY_DEBUG #include #endif @@ -102,14 +102,16 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb ifstream filebin; - + int iev; int ix=20, iy=20, ir, ic; Int_t iFrame; TTree *tall; + cout << "init tree " << tit << endl; if (hitfinder) tall=filter->initEventTree(tit, &iFrame); + cout << "done" << endl; diff --git a/slsDetectorCalibration/moenchReadDataMT.C b/slsDetectorCalibration/moenchReadDataMT.C index 0720909c4e..2411e73ae9 100644 --- a/slsDetectorCalibration/moenchReadDataMT.C +++ b/slsDetectorCalibration/moenchReadDataMT.C @@ -50,3 +50,22 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo +//to compile: g++ -DMYROOT -DMYROOT1 -g `root-config --cflags --glibs` -o moenchReadDataMT moenchReadDataMT.C +int main(int argc, char **argv){ + if(argc != 8){ + cout << "Usage: " << argv[0] << " fformat tit tdir runmin runoffset nThreads treeIndexStart" << endl; + exit(-1); + } + + char *fformat = argv[1]; + char *tit = argv[2]; + char *tdir = argv[3]; + int runmin = atoi(argv[4]); + int runoffset = atoi(argv[5]); + int nThreads = atoi(argv[6]); + int treeIndexStart = atoi(argv[7]); + + moenchReadDataMT(fformat, tit, tdir,runmin,runoffset,nThreads,treeIndexStart); + +} + diff --git a/slsDetectorCalibration/raedNoiseData.C b/slsDetectorCalibration/raedNoiseData.C index b2021b29fe..c4b505df32 100644 --- a/slsDetectorCalibration/raedNoiseData.C +++ b/slsDetectorCalibration/raedNoiseData.C @@ -1,4 +1,5 @@ #include "moenchReadData.C" +#include "moenchReadOversampledData.C" @@ -13,12 +14,12 @@ void raedNoiseData(char *tit, int sign=1){ TFile *fout; THStack *hs2N; - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_0.root",tit); + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s.root",tit); fout=new TFile(fname,"RECREATE"); sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); - hs2N=moenchReadData(fname,0,3000,1500,-500,2500,1,0.,1,159,1,159, 0,1); + hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,1); hs2N->SetName(tit); hs2N->SetTitle(tit); (TH2F*)(hs2N->GetHists()->At(0))->Write(); @@ -36,6 +37,59 @@ void raedNoiseData(char *tit, int sign=1){ } +void raedOsNoiseData(){ + + + THStack *hs[10]; + + + + char fname[1000]; + char f[1000]; + TFile *fout; + + + + strcpy(fname,"/data/moench_xbox_201401_trees/noise_cds_g1_os10_2ndsample.root"); + fout=new TFile(fname,"RECREATE"); + + for (int ir=0; ir<10; ir++) { + sprintf(fname,"/data/moench_xbox_201401/moench_xbox_20140116/noise_os10_16rows_f00000%%04d000_%d.raw",ir); + hs[ir]=moenchReadOversampledData(fname,"cds_g1_os10",0,1000,1000,-500,500,1,10,0,160,0,16,0); + + } + TH2F *h; + int ii=0, ii1=0; + h=(TH2F*)(hs[0]->GetHists()->At(0)); + TH2F *hn=(TH2F*)h->Clone(); + for (int ir=1; ir<10; ir++) { + h=(TH2F*)(hs[ir]->GetHists()->At(0)); + for (int iy=0; iy<16; iy++) + for (int ix=0; ix<160; ix++) + for (int ib=0; ibGetNbinsX(); ib++) { + ii=h->GetYaxis()->FindBin(iy+ix*160); + ii1= hn->GetYaxis()->FindBin(iy+ir*16+ix*160); + hn->SetBinContent(ib+1,ii1,h->GetBinContent(ib+1,ii)); + + } + } + + + + hn->Write(); + + // (TH2F*)(hs2N->GetHists()->At(1))->Write(); + // (TH2F*)(hs2N->GetHists()->At(2))->Write(); + // (TH2F*)(hs2N->GetHists()->At(3))->Write(); + // (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + + fout->Close(); + + + +} + void raedNoiseDataN(char *tit, int sign=1){ @@ -74,7 +128,7 @@ void g4() { raedNoiseData("cds_g4_low_gain"); raedNoiseData("cds_g4_sto1_only"); - raedNoiseData("cds_g4_no sto"); + raedNoiseData("cds_g4_no_sto"); @@ -84,7 +138,7 @@ void no_cds() { raedNoiseData("cds_disable_low_gain",-1); raedNoiseData("cds_disable_sto1_only",-1); - raedNoiseData("cds_disable_no sto",-1); + raedNoiseData("cds_disable_no_sto",-1); diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 693f400225..24d58f9298 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -335,20 +335,22 @@ class singlePhotonDetector { \returns returns pointer to the TTree */ TTree *initEventTree(char *tname, int *iFrame=NULL) { + cout << tname << endl; TTree* tall=new TTree(tname,tname); - + cout << "tree instantiated" << endl; if (iFrame) tall->Branch("iFrame",iFrame,"iframe/I"); else tall->Branch("iFrame",&(cluster->iframe),"iframe/I"); - + cout << "iframe" << endl; + char tit[100]; tall->Branch("x",&(cluster->x),"x/I"); tall->Branch("y",&(cluster->y),"y/I"); - char tit[100]; sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY); tall->Branch("data",cluster->data,tit); - // tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); - // tall->Branch("rms",&(cluster->rms),"rms/D"); + tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); + tall->Branch("rms",&(cluster->rms),"rms/D"); + cout << "Cluster" << endl; return tall; }; #else diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 5fc204e347..c4616a6244 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -203,7 +203,7 @@ class slsDetectorData { virtual int getFrameNumber(char *buff)=0; - /** + /* Returns the packet number for the given dataset. purely virtual func \param buff pointer to the dataset From 0f881677d20159c10125155dfad6d829bdb1fc63 Mon Sep 17 00:00:00 2001 From: l_msdetect Date: Sat, 5 Apr 2014 09:39:32 +0000 Subject: [PATCH 047/104] quite moenchTree creator for first nanoscope beamtime git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@47 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/energyCalibration.cpp | 8 +- slsDetectorCalibration/gainMap.C | 200 +++++------------- slsDetectorCalibration/moenchReadData.C | 39 +++- slsDetectorCalibration/moenchReadDataMT.C | 31 ++- slsDetectorCalibration/raedNoiseData.C | 10 +- slsDetectorCalibration/singlePhotonDetector.h | 2 +- 6 files changed, 118 insertions(+), 172 deletions(-) diff --git a/slsDetectorCalibration/energyCalibration.cpp b/slsDetectorCalibration/energyCalibration.cpp index cca067d145..1e5df8c0c2 100644 --- a/slsDetectorCalibration/energyCalibration.cpp +++ b/slsDetectorCalibration/energyCalibration.cpp @@ -447,9 +447,11 @@ TF1* energyCalibration::fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t fitfun= h1->GetFunction(fname); - fitfun->GetParameters(mypar); - for (int ip=0; ip<6; ip++) { - emypar[ip]=fitfun->GetParError(ip); + if (fitfun) { + fitfun->GetParameters(mypar); + for (int ip=0; ip<6; ip++) { + emypar[ip]=fitfun->GetParError(ip); + } } return fitfun; } diff --git a/slsDetectorCalibration/gainMap.C b/slsDetectorCalibration/gainMap.C index 3c7abef3c1..2ef8904549 100644 --- a/slsDetectorCalibration/gainMap.C +++ b/slsDetectorCalibration/gainMap.C @@ -16,22 +16,25 @@ using namespace std; #define FOPT "0" -TH2F *gainMap(TH2F *h2, float g) { +THStack *gainMap(TH2F *h2, float g) { // int npx, npy; int npx=160, npy=160; // det->getDetectorSize(npx, npy); - TH2F *gMap=new TH2F("gmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); + THStack *hs=new THStack(); - Double_t ens[3]={0,8,17.5}, eens[3]={0.,0.1,0.1}; - Double_t peaks[3], epeaks[3]; + TH2F *gMap=new TH2F("gmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); + TH2F *nMap=new TH2F("nmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); + hs->Add(gMap); + hs->Add(nMap); + Double_t ens[1]={20.}, eens[1]={20.}; + Double_t peaks[1], epeaks[1]; int ibin; TH1D *px; - energyCalibration *enCal=new energyCalibration(); enCal->setPlotFlag(0); // enCal->setChargeSharing(0); @@ -50,94 +53,48 @@ TH2F *gainMap(TH2F *h2, float g) { TGraph *glin; Double_t peakdum, hpeakdum; - for (int ix=1; ixProjectionX("px",ibin+1,ibin+1); - prms=10*g; - iit=0; - np=s->Search(px,prms,"",0.2); - while (np !=2) { - if (np>2) - prms+=0.5*prms; - else - prms-=0.5*prms; - iit++; - if (iit>=10) - break; - np=s->Search(px,prms,"",0.2); - } - if (np!=2) - cout << "peak search could not converge " << ibin << endl; - if (np==2) { - pm=NULL; - functions=px->GetListOfFunctions(); - if (functions) - pm = (TPolyMarker*)functions->FindObject("TPolyMarker"); - if (pm) { - peakX=pm->GetX(); - peakY=pm->GetY(); - - - if (peakX[0]>peakX[1]) { - peakdum=peakX[0]; - hpeakdum=peakY[0]; - peakX[0]= peakX[1]; - peakY[0]= peakY[1]; - peakX[1]= peakdum; - peakY[1]= hpeakdum; - - } - - cout << "("<< ix << "," << iy << ") " << endl; - for (int ip=0; ipsetFitRange(peakX[ip]-10*g,peakX[ip]+10*g); - mypar[0]=0; - mypar[1]=0; - mypar[2]=peakX[ip]; - mypar[3]=g*10; - mypar[4]=peakY[ip]; - mypar[5]=0; - - - - enCal->setStartParameters(mypar); - enCal->fitSpectrum(px,mypar,emypar); - - - peaks[ip+1]=mypar[2]; - epeaks[ip+1]=emypar[2]; - } - - peaks[0]=0; - epeaks[0]=1; - - // for (int i=0; i<3; i++) cout << i << " " << ens[i] << " " << eens[i]<< " "<< peaks[i]<< " " << epeaks[i] << endl; - - glin= enCal->linearCalibration(3,ens,eens,peaks,epeaks,gain,off,egain,eoff); - - // cout << "Gain " << gain << " off " << off << endl; - if (off>-10 && off<10) { - gMap->SetBinContent(ix+1,iy+1,gain); - gMap->SetBinError(ix+1,iy+1,egain); - } - if (glin) - delete glin; - } + enCal->setFitRange(50,3000); + //enCal->setChargeSharing(0); + if (px) { + enCal->fixParameter(0,0); + enCal->fixParameter(1,0); + enCal->fixParameter(5,0); + mypar[0]=0; + mypar[1]=0; + mypar[2]=px->GetBinCenter(px->GetMaximumBin()); + mypar[3]=10; + mypar[4]=px->GetMaximum(); + mypar[5]=0; + + enCal->setStartParameters(mypar); + enCal->fitSpectrum(px,mypar,emypar); + + cout << ix << " " << iy << " " << mypar[2] << endl; } - - } + if (mypar[2]>0) { + gMap->SetBinContent(ix+1,iy+1,mypar[2]/ens[0]); + gMap->SetBinError(ix+1,iy+1,emypar[2]/ens[0]); + nMap->SetBinContent(ix+1,iy+1,mypar[3]); + nMap->SetBinError(ix+1,iy+1,emypar[3]); + } + } } - return gMap; + return hs; } -TH2F *noiseMap(TH2F *h2, TH2F *gMap=NULL) { +TH2F *noiseMap(TH2F *h2) { // int npx, npy; int npx=160, npy=160; // det->getDetectorSize(npx, npy); @@ -152,89 +109,36 @@ TH2F *noiseMap(TH2F *h2, TH2F *gMap=NULL) { cout << ix << " " << iy << " " << ibin << endl; ibin=h2->GetYaxis()->FindBin(ix*npy+iy); px=h2->ProjectionX("px",ibin,ibin); - px->Fit("gaus", FOPT); + px->Fit("gaus", FOPT,"",-100,100); if (px->GetFunction("gaus")) { - nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2)); + if (px->GetFunction("gaus")->GetParameter(1)>-5 && px->GetFunction("gaus")->GetParameter(1)<5) + nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2)); } // delete px; } } - if (gMap) { - nMap->Divide(gMap); - nMap->Scale(1000./3.6); - } + return nMap; } +THStack *noiseHistos(TH2F *nmap, TH2F *gmap=NULL) { -THStack *noiseHistos(char *tit) { - char fname[10000]; + + char tit[1000]; - sprintf(fname,"/data/moench_xbox_201401_trees/noise_map_%s.root",tit); - TFile *fn=new TFile(fname); - TH2F *nmap=(TH2F*)fn->Get("nmap"); if (nmap==NULL) { - cout << "No noise map in file " << fname << endl; + cout << "No noise map" << endl; return NULL; } - sprintf(fname,"/data/moench_xbox_201401_trees/gain_map_%s.root",tit); - TFile *fg=new TFile(fname); - TH2F *gmap=(TH2F*)fg->Get("gmap"); - - if (gmap==NULL) { - cout << "No gain map in file " << fname << endl; - - return NULL; - } - - nmap->Divide(gmap); - nmap->Scale(1000./3.6); - - THStack *hs=new THStack(tit,tit); - hs->SetTitle(tit); - - TH1F *h; - char hname[100]; - - cout << tit << endl; - for (int is=0; is<4; is++) { - sprintf(hname,"h%ds",is+1); - - h=new TH1F(hname,tit,500,0,500); - hs->Add(h); - // cout << hs->GetHists()->GetEntries() << endl; - for (int ix=40*is+2; ix<40*(is+1)-2; ix++) { - - for (int iy=2; iy<158; iy++) { - if (ix<100 || ix>120) - h->Fill(nmap->GetBinContent(ix+1,iy+1)); - } - } - cout << is+1 << "SC: " << "" << h->GetMean() << "+-" << h->GetRMS(); - h->Fit("gaus","0Q"); - h->SetLineColor(is+1); - if (h->GetFunction("gaus")) { - h->GetFunction("gaus")->SetLineColor(is+1); - cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParError(1); - } - cout << endl; + if (gmap) { + nmap->Divide(gmap); + nmap->Scale(1000./3.6); } - // cout << hs->GetHists()->GetEntries() << endl; - - return hs; - - -} - -THStack *noiseHistos(TH2F *nmap) { - - - char tit[1000]; strcpy(tit,nmap->GetTitle()); THStack *hs=new THStack(tit,tit); @@ -260,7 +164,7 @@ THStack *noiseHistos(TH2F *nmap) { h->SetLineColor(is+1); if (h->GetFunction("gaus")) { h->GetFunction("gaus")->SetLineColor(is+1); - cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParError(1); + cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParameter(2); } cout << endl; } diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index f829ed791b..619126ca02 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -26,7 +26,7 @@ using namespace std; #define NR 160 -//#define MY_DEBUG 1 +#define MY_DEBUG 1 #ifdef MY_DEBUG #include #endif @@ -79,6 +79,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb TH2F *h3; TH2F *hetaX; TH2F *hetaY; + TH2D *clustHist; THStack *hs=new THStack("hs",fformat); @@ -117,13 +118,19 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb #ifdef MY_DEBUG - + quadrant quad; + tall->Branch("q",&quad,"q/I"); + + TCanvas *myC; TH2F *he; TCanvas *cH1; TCanvas *cH2; TCanvas *cH3; + int quadrants[5]; + for(int i = 0; i < 5; i++){ quadrants[i] = 0; } + if (hitfinder) { myC=new TCanvas(); he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); @@ -138,6 +145,8 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb cH3=new TCanvas(); cH3->SetLogz(); h3->Draw("colz"); + + clustHist= new TH2D("clustHist","clustHist",3,-1.5,1.5,3,-1.5,1.5); } #endif filter->newDataSet(); @@ -145,7 +154,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb for (int irun=runmin; irunreadNextFrame(filebin))) { @@ -189,9 +198,17 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb h3->Fill(filter->getClusterTotal(3), iy+NR*ix); iFrame=decoder->getFrameNumber(buff); + +#ifdef MY_DEBUG + for(int cx=-1; cx <2; cx++) + for(int cy=-1; cy < 2; cy++) + clustHist->Fill(cx,cy,filter->getClusterElement(cx,cy)); + + quad = filter->getQuadrant(); + quadrants[quad]++; +#endif tall->Fill(); - - + } @@ -217,10 +234,10 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb #endif nf++; - cout << "=" ; + //cout << "=" ; delete [] buff; } - cout << nph << endl; + //cout << nph << endl; if (filebin.is_open()) filebin.close(); else @@ -233,6 +250,14 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb delete decoder; cout << "Read " << nf << " frames" << endl; + +#ifdef MY_DEBUG + cout << "quadrants: " ; + for(int i = 0; i<5; i++) cout << i << ": " << quadrants[i] << " || " ; + cout << endl; + cout << "Read Events " << nph << endl; +#endif + return hs; } diff --git a/slsDetectorCalibration/moenchReadDataMT.C b/slsDetectorCalibration/moenchReadDataMT.C index 2411e73ae9..54773f6b8f 100644 --- a/slsDetectorCalibration/moenchReadDataMT.C +++ b/slsDetectorCalibration/moenchReadDataMT.C @@ -9,23 +9,30 @@ typedef struct task_s{ int runmin; int runmax; int treeIndex; + int tNumber; + double xTalkFactor; } Task; +double hc = 0.1; // read - out crosstalk + void *moenchMakeTreeTask(void *p){ TThread::Lock(); char fname[1000]; Task *t = (Task *)p; sprintf(fname,"%s%s_%i.root",t->tdir,t->tname,t->treeIndex); TFile *f = new TFile(fname,"RECREATE"); - cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<")" << endl; + double xTalkC = t->xTalkFactor; //((double)t->tNumber) * 0.01; Calibrated with data in /data/moench_trieste_20140313_trees/xtalkScan + cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<") with xTalkC: " << xTalkC << endl; TThread::UnLock(); - moenchReadData(t->fformat,t->tname,t->runmin,t->runmax); - f->Close(); + moenchReadData(t->fformat,t->tname,t->runmin,t->runmax, 1500, -500, 1000, 1, xTalkC); + if(f && f->IsOpen()){ + f->Close(); + } return 0; } -void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0){ +void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0, double xTalkFactor=0.044){ char threadName[1000]; TThread *threads[nThreads]; for(int i = 0; i < nThreads; i++){ @@ -37,6 +44,8 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo t->runmin = runmin + i*runoffset; t->runmax = runmin + (i+1)*runoffset - 1; t->treeIndex = treeIndexStart + i; + t->tNumber = i; + t->xTalkFactor = xTalkFactor; cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; threads[i] = new TThread(threadName, moenchMakeTreeTask, t); threads[i]->Run(); @@ -45,15 +54,17 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo for(int i = 0; i < nThreads; i++){ threads[i]->Join(); } - + + cout << " ( DONE ) " << endl; + } //to compile: g++ -DMYROOT -DMYROOT1 -g `root-config --cflags --glibs` -o moenchReadDataMT moenchReadDataMT.C int main(int argc, char **argv){ - if(argc != 8){ - cout << "Usage: " << argv[0] << " fformat tit tdir runmin runoffset nThreads treeIndexStart" << endl; + if(argc < 8){ + cout << "Usage: " << argv[0] << " fformat tit tdir runmin runoffset nThreads treeIndexStart [xTalkFactor]" << endl; exit(-1); } @@ -64,8 +75,12 @@ int main(int argc, char **argv){ int runoffset = atoi(argv[5]); int nThreads = atoi(argv[6]); int treeIndexStart = atoi(argv[7]); + double xTalkFactor = 0.044; + + if(argc == 9) + xTalkFactor = atof(argv[8]); - moenchReadDataMT(fformat, tit, tdir,runmin,runoffset,nThreads,treeIndexStart); + moenchReadDataMT(fformat, tit, tdir,runmin,runoffset,nThreads,treeIndexStart, xTalkFactor); } diff --git a/slsDetectorCalibration/raedNoiseData.C b/slsDetectorCalibration/raedNoiseData.C index c4b505df32..141c0f6ef0 100644 --- a/slsDetectorCalibration/raedNoiseData.C +++ b/slsDetectorCalibration/raedNoiseData.C @@ -14,12 +14,12 @@ void raedNoiseData(char *tit, int sign=1){ TFile *fout; THStack *hs2N; - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s.root",tit); + sprintf(fname,"/data/moench_trieste_calibration_trees/flat_20keV_%s.root",tit); fout=new TFile(fname,"RECREATE"); - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); + sprintf(fname,"/data/moench_trieste_calibration/flat_20keV_%s_f00000%%04d000_0.raw",tit); - hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,1); + hs2N=moenchReadData(fname,tit,0,2000,1500,-500,2500,sign,0.,1,159,1,159, 0,1); hs2N->SetName(tit); hs2N->SetTitle(tit); (TH2F*)(hs2N->GetHists()->At(0))->Write(); @@ -100,10 +100,10 @@ void raedNoiseDataN(char *tit, int sign=1){ TFile *fout; THStack *hs2N; - sprintf(fname,"/data/moench_xbox_20140116/noise_%s.root",tit); + sprintf(fname,"/data/moench_noise_20140327_trees/noise_%s.root",tit); fout=new TFile(fname,"RECREATE"); - sprintf(fname,"/data/moench_xbox_20140116/noise_%s_f00000%%04d000_0.raw",tit); + sprintf(fname,"/data/moench_noise_20140327/noise_%s_f00000%%04d000_0.raw",tit); hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,0); hs2N->SetName(tit); diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 24d58f9298..0f382ec9c5 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -9,7 +9,7 @@ #include "commonModeSubtraction.h" -//#define MYROOT1 +#define MYROOT1 #ifdef MYROOT1 #include From 9297b14500e2a9a13296aa846a4e3f55a95518b3 Mon Sep 17 00:00:00 2001 From: jungmann_j Date: Tue, 8 Apr 2014 12:42:57 +0000 Subject: [PATCH 048/104] Jungfrau stuff updated git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@48 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/MovingStat.h | 2 +- slsDetectorCalibration/chiptestBoardData.h | 2 +- .../commonModeSubtraction.h | 2 +- slsDetectorCalibration/energyCalibration.cpp | 6 +-- slsDetectorCalibration/jungfrau02Data.h | 45 +++++++++++----- slsDetectorCalibration/jungfrauReadData.C | 52 ++++++++++++++----- slsDetectorCalibration/pedestalSubtraction.h | 2 +- slsDetectorCalibration/readJungfrauData.C | 19 ++++--- slsDetectorCalibration/slsDetectorData.h | 2 + 9 files changed, 91 insertions(+), 41 deletions(-) diff --git a/slsDetectorCalibration/MovingStat.h b/slsDetectorCalibration/MovingStat.h index 00d692cc0f..9d3720b1b8 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 86bdbcc35e..0ef633c44c 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 2de635a45f..0484e67469 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 1e5df8c0c2..1872e20ef5 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 2a43dad1f2..e7b3d6b77a 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 b59d75c44d..f577877378 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 29bc986284..ee3aff8aa8 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 c472d2d753..8ad92381ab 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 c4616a6244..809b23de32 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 Date: Tue, 8 Apr 2014 14:17:49 +0000 Subject: [PATCH 049/104] git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@49 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/energyCalibration.cpp | 8 +- slsDetectorCalibration/gMapDemo.C | 18 +- slsDetectorCalibration/gainMap.C | 161 ++++++++++++------ slsDetectorCalibration/jungfrauReadData.C | 18 +- slsDetectorCalibration/moench02ModuleData.h | 44 +---- slsDetectorCalibration/moenchReadData.C | 41 +---- slsDetectorCalibration/moenchReadDataMT.C | 44 +---- slsDetectorCalibration/raedNoiseData.C | 68 +------- slsDetectorCalibration/readJungfrauData.C | 12 +- slsDetectorCalibration/singlePhotonDetector.h | 20 +-- slsDetectorCalibration/slsDetectorData.h | 8 +- slsDetectorCalibration/slsReceiverData.h | 101 +++++------ 12 files changed, 211 insertions(+), 332 deletions(-) diff --git a/slsDetectorCalibration/energyCalibration.cpp b/slsDetectorCalibration/energyCalibration.cpp index 1872e20ef5..6911220955 100644 --- a/slsDetectorCalibration/energyCalibration.cpp +++ b/slsDetectorCalibration/energyCalibration.cpp @@ -447,11 +447,9 @@ TF1* energyCalibration::fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t fitfun= h1->GetFunction(fname); - if (fitfun) { - fitfun->GetParameters(mypar); - for (int ip=0; ip<6; ip++) { - emypar[ip]=fitfun->GetParError(ip); - } + fitfun->GetParameters(mypar); + for (int ip=0; ip<6; ip++) { + emypar[ip]=fitfun->GetParError(ip); } return fitfun; } diff --git a/slsDetectorCalibration/gMapDemo.C b/slsDetectorCalibration/gMapDemo.C index c48ab002cd..51addf69a7 100644 --- a/slsDetectorCalibration/gMapDemo.C +++ b/slsDetectorCalibration/gMapDemo.C @@ -1,19 +1,11 @@ -void gMap(char *tit, float g=1) { +{ //.L energyCalibration.cpp+ //.L gainMap.C+ - - char fname[1000]; - - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s.root",tit); - - TFile fin(fname); + TFile fin("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_cds_g4.root"); TH2F *h2=fin.Get("h2"); - TH2F *gMap=(TH2F*)gainMap(h2,g); + TH2F *gMap=gainMap(h2,4); gMap->Draw("colz"); - sprintf(fname,"/data/moench_xbox_20140113/gain_map_%s.root",tit); - TFile fout(fname,"RECREATE"); - gMap->Write(); - - fout.Close(); + + } diff --git a/slsDetectorCalibration/gainMap.C b/slsDetectorCalibration/gainMap.C index 2ef8904549..7923fe687a 100644 --- a/slsDetectorCalibration/gainMap.C +++ b/slsDetectorCalibration/gainMap.C @@ -16,25 +16,22 @@ using namespace std; #define FOPT "0" -THStack *gainMap(TH2F *h2, float g) { +TH2F *gainMap(TH2F *h2, float g) { // int npx, npy; int npx=160, npy=160; // det->getDetectorSize(npx, npy); - THStack *hs=new THStack(); - TH2F *gMap=new TH2F("gmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); - TH2F *nMap=new TH2F("nmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); - hs->Add(gMap); - hs->Add(nMap); + Double_t ens[3]={0,8,17.5}, eens[3]={0.,0.1,0.1}; + Double_t peaks[3], epeaks[3]; + - Double_t ens[1]={20.}, eens[1]={20.}; - Double_t peaks[1], epeaks[1]; int ibin; TH1D *px; + energyCalibration *enCal=new energyCalibration(); enCal->setPlotFlag(0); // enCal->setChargeSharing(0); @@ -53,44 +50,90 @@ THStack *gainMap(TH2F *h2, float g) { TGraph *glin; Double_t peakdum, hpeakdum; - int ix=20; - int iy=40; - - - for ( ix=1; ixProjectionX("px",ibin+1,ibin+1); - enCal->setFitRange(50,3000); - //enCal->setChargeSharing(0); - if (px) { - enCal->fixParameter(0,0); - enCal->fixParameter(1,0); - enCal->fixParameter(5,0); - mypar[0]=0; - mypar[1]=0; - mypar[2]=px->GetBinCenter(px->GetMaximumBin()); - mypar[3]=10; - mypar[4]=px->GetMaximum(); - mypar[5]=0; - - enCal->setStartParameters(mypar); - enCal->fitSpectrum(px,mypar,emypar); - - cout << ix << " " << iy << " " << mypar[2] << endl; + prms=10*g; + iit=0; + np=s->Search(px,prms,"",0.2); + while (np !=2) { + if (np>2) + prms+=0.5*prms; + else + prms-=0.5*prms; + iit++; + if (iit>=10) + break; + np=s->Search(px,prms,"",0.2); } - - if (mypar[2]>0) { - gMap->SetBinContent(ix+1,iy+1,mypar[2]/ens[0]); - gMap->SetBinError(ix+1,iy+1,emypar[2]/ens[0]); - nMap->SetBinContent(ix+1,iy+1,mypar[3]); - nMap->SetBinError(ix+1,iy+1,emypar[3]); + if (np!=2) + cout << "peak search could not converge " << ibin << endl; + if (np==2) { + pm=NULL; + functions=px->GetListOfFunctions(); + if (functions) + pm = (TPolyMarker*)functions->FindObject("TPolyMarker"); + if (pm) { + peakX=pm->GetX(); + peakY=pm->GetY(); + + + if (peakX[0]>peakX[1]) { + peakdum=peakX[0]; + hpeakdum=peakY[0]; + peakX[0]= peakX[1]; + peakY[0]= peakY[1]; + peakX[1]= peakdum; + peakY[1]= hpeakdum; + + } + + cout << "("<< ix << "," << iy << ") " << endl; + for (int ip=0; ipsetFitRange(peakX[ip]-10*g,peakX[ip]+10*g); + mypar[0]=0; + mypar[1]=0; + mypar[2]=peakX[ip]; + mypar[3]=g*10; + mypar[4]=peakY[ip]; + mypar[5]=0; + + + + enCal->setStartParameters(mypar); + enCal->fitSpectrum(px,mypar,emypar); + + + peaks[ip+1]=mypar[2]; + epeaks[ip+1]=emypar[2]; + } + + peaks[0]=0; + epeaks[0]=1; + + // for (int i=0; i<3; i++) cout << i << " " << ens[i] << " " << eens[i]<< " "<< peaks[i]<< " " << epeaks[i] << endl; + + glin= enCal->linearCalibration(3,ens,eens,peaks,epeaks,gain,off,egain,eoff); + + // cout << "Gain " << gain << " off " << off << endl; + if (off>-10 && off<10) { + gMap->SetBinContent(ix+1,iy+1,gain); + gMap->SetBinError(ix+1,iy+1,egain); + } + if (glin) + delete glin; + } } - } + + + } } - return hs; + return gMap; } @@ -107,48 +150,56 @@ TH2F *noiseMap(TH2F *h2) { for (int ix=0; ixGetYaxis()->FindBin(ix*npy+iy); - px=h2->ProjectionX("px",ibin,ibin); - px->Fit("gaus", FOPT,"",-100,100); + ibin=ix*npy+iy; + px=h2->ProjectionX("px",ibin+1,ibin+1); + px->Fit("gaus", FOPT); if (px->GetFunction("gaus")) { - if (px->GetFunction("gaus")->GetParameter(1)>-5 && px->GetFunction("gaus")->GetParameter(1)<5) - nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2)); + nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2)); } // delete px; } } - return nMap; } -THStack *noiseHistos(TH2F *nmap, TH2F *gmap=NULL) { - - char tit[1000]; +THStack *noiseHistos(char *tit) { + char fname[10000]; + sprintf(fname,"/data/moench_xbox_20140116/noise_map_%s.root",tit); + TFile *fn=new TFile(fname); + TH2F *nmap=(TH2F*)fn->Get("nmap"); if (nmap==NULL) { - cout << "No noise map" << endl; + cout << "No noise map in file " << fname << endl; return NULL; } - if (gmap) { - nmap->Divide(gmap); - nmap->Scale(1000./3.6); + sprintf(fname,"/data/moench_xbox_20140113/gain_map_%s.root",tit); + TFile *fg=new TFile(fname); + TH2F *gmap=(TH2F*)fg->Get("gmap"); + + if (gmap==NULL) { + cout << "No gain map in file " << fname << endl; + + return NULL; } + nmap->Divide(gmap); + nmap->Scale(1000./3.6); - strcpy(tit,nmap->GetTitle()); THStack *hs=new THStack(tit,tit); hs->SetTitle(tit); TH1F *h; char hname[100]; - cout << tit << endl; + + cout << tit << endl; for (int is=0; is<4; is++) { sprintf(hname,"h%ds",is+1); + h=new TH1F(hname,tit,500,0,500); hs->Add(h); // cout << hs->GetHists()->GetEntries() << endl; @@ -164,7 +215,7 @@ THStack *noiseHistos(TH2F *nmap, TH2F *gmap=NULL) { h->SetLineColor(is+1); if (h->GetFunction("gaus")) { h->GetFunction("gaus")->SetLineColor(is+1); - cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParameter(2); + cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParError(1); } cout << endl; } diff --git a/slsDetectorCalibration/jungfrauReadData.C b/slsDetectorCalibration/jungfrauReadData.C index f577877378..743a88e70d 100644 --- a/slsDetectorCalibration/jungfrauReadData.C +++ b/slsDetectorCalibration/jungfrauReadData.C @@ -20,7 +20,6 @@ //#include "MovingStat.h" - using namespace std; #define NC 48 @@ -51,15 +50,14 @@ Loops over data file to find single photons, fills the tree (and writes it to fi \param ymax maximum y coordinate \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){ - +/* // read in calibration file - ifstream calfile("/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); + ifstream calfile("/home/l_msdetect/TriesteBeam2014/dummy data for scripts/CalibrationParametersTest_fake.txt"); if (calfile.is_open()==0){cout << "Unable to open calibration file!" << endl;} int pix; double of0,sl0,of1,sl1,of2,sl2; @@ -73,10 +71,10 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int sl_2[pix]=sl2; //if(pix==200) cout << "sl_2[200] " << sl_2[200] << endl; } calfile.close(); - +*/ 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 + jungfrau02Data *decoder=new jungfrau02Data(1,0,0);//(1,0,0); // (adc,offset,crosstalk) //(1,0,0) //(3,0,0) for readout of GB jungfrau02CommonMode *cmSub=NULL; if (cmsub) cmSub=new jungfrau02CommonMode(); @@ -106,9 +104,6 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int 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); @@ -193,7 +188,7 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int thisEvent=filter->getEventType(buff, ix, iy, cmsub); - int gainBits=decoder->getGainBits(buff,ix,iy); // get gain bits + int gainBits=decoder->getGainBits(buff,ix,iy); //XXX #ifdef MY_DEBUG if (hitfinder) { @@ -210,8 +205,7 @@ THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int // 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/moench02ModuleData.h b/slsDetectorCalibration/moench02ModuleData.h index 8c0d0c337c..34b4f17834 100644 --- a/slsDetectorCalibration/moench02ModuleData.h +++ b/slsDetectorCalibration/moench02ModuleData.h @@ -18,7 +18,7 @@ class moench02ModuleData : public slsReceiverData { */ - moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), + moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), xtalk(c) { @@ -66,6 +66,9 @@ class moench02ModuleData : public slsReceiverData { setDataMap(dMap); setDataMask(dMask); + + + }; @@ -129,45 +132,6 @@ class moench02ModuleData : public slsReceiverData { }; -class moench02OversampledData : public moench02ModuleData { - public: - moench02OversampledData(int nos, int off=0): moench02ModuleData(), nSamples(nos), offset(off){}; - - /** - returns the pixel value as double correcting for the output buffer crosstalk - \param data pointer to the memory - \param ix coordinate in the x direction - \param iy coordinate in the y direction - \returns channel value as double - - */ - double getValue(char *data, int ix, int iy=0) { - double v=0, is=0; - int ix1, iy1, isc=ix/40, ip=ix%40, ip1=iy*nSamples*40+ix; - - if (iy*nSamples<160) { - for (int i=offset; i=0 && iy1>=0 && ix1<160 && iy1<160) { - v+=moench02ModuleData::getValue(data,ix1,iy1); - is++; - } - } - if (is>0) - v/=is; - } - - return v; - }; - - - private: - int nSamples; - int offset; -}; - #endif diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 619126ca02..bf7173f0bb 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -79,7 +79,6 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb TH2F *h3; TH2F *hetaX; TH2F *hetaY; - TH2D *clustHist; THStack *hs=new THStack("hs",fformat); @@ -103,34 +102,26 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb ifstream filebin; - int iev; + int ix=20, iy=20, ir, ic; Int_t iFrame; TTree *tall; - cout << "init tree " << tit << endl; if (hitfinder) tall=filter->initEventTree(tit, &iFrame); - cout << "done" << endl; #ifdef MY_DEBUG - quadrant quad; - tall->Branch("q",&quad,"q/I"); - - + TCanvas *myC; TH2F *he; TCanvas *cH1; TCanvas *cH2; TCanvas *cH3; - int quadrants[5]; - for(int i = 0; i < 5; i++){ quadrants[i] = 0; } - if (hitfinder) { myC=new TCanvas(); he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); @@ -145,8 +136,6 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb cH3=new TCanvas(); cH3->SetLogz(); h3->Draw("colz"); - - clustHist= new TH2D("clustHist","clustHist",3,-1.5,1.5,3,-1.5,1.5); } #endif filter->newDataSet(); @@ -154,7 +143,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb for (int irun=runmin; irunreadNextFrame(filebin))) { @@ -198,17 +187,9 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb h3->Fill(filter->getClusterTotal(3), iy+NR*ix); iFrame=decoder->getFrameNumber(buff); - -#ifdef MY_DEBUG - for(int cx=-1; cx <2; cx++) - for(int cy=-1; cy < 2; cy++) - clustHist->Fill(cx,cy,filter->getClusterElement(cx,cy)); - - quad = filter->getQuadrant(); - quadrants[quad]++; -#endif tall->Fill(); - + + } @@ -234,10 +215,10 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb #endif nf++; - //cout << "=" ; + cout << "=" ; delete [] buff; } - //cout << nph << endl; + cout << nph << endl; if (filebin.is_open()) filebin.close(); else @@ -250,14 +231,6 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb delete decoder; cout << "Read " << nf << " frames" << endl; - -#ifdef MY_DEBUG - cout << "quadrants: " ; - for(int i = 0; i<5; i++) cout << i << ": " << quadrants[i] << " || " ; - cout << endl; - cout << "Read Events " << nph << endl; -#endif - return hs; } diff --git a/slsDetectorCalibration/moenchReadDataMT.C b/slsDetectorCalibration/moenchReadDataMT.C index 54773f6b8f..0720909c4e 100644 --- a/slsDetectorCalibration/moenchReadDataMT.C +++ b/slsDetectorCalibration/moenchReadDataMT.C @@ -9,30 +9,23 @@ typedef struct task_s{ int runmin; int runmax; int treeIndex; - int tNumber; - double xTalkFactor; } Task; -double hc = 0.1; // read - out crosstalk - void *moenchMakeTreeTask(void *p){ TThread::Lock(); char fname[1000]; Task *t = (Task *)p; sprintf(fname,"%s%s_%i.root",t->tdir,t->tname,t->treeIndex); TFile *f = new TFile(fname,"RECREATE"); - double xTalkC = t->xTalkFactor; //((double)t->tNumber) * 0.01; Calibrated with data in /data/moench_trieste_20140313_trees/xtalkScan - cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<") with xTalkC: " << xTalkC << endl; + cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<")" << endl; TThread::UnLock(); - moenchReadData(t->fformat,t->tname,t->runmin,t->runmax, 1500, -500, 1000, 1, xTalkC); - if(f && f->IsOpen()){ - f->Close(); - } + moenchReadData(t->fformat,t->tname,t->runmin,t->runmax); + f->Close(); return 0; } -void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0, double xTalkFactor=0.044){ +void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0){ char threadName[1000]; TThread *threads[nThreads]; for(int i = 0; i < nThreads; i++){ @@ -44,8 +37,6 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo t->runmin = runmin + i*runoffset; t->runmax = runmin + (i+1)*runoffset - 1; t->treeIndex = treeIndexStart + i; - t->tNumber = i; - t->xTalkFactor = xTalkFactor; cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; threads[i] = new TThread(threadName, moenchMakeTreeTask, t); threads[i]->Run(); @@ -54,33 +45,8 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo for(int i = 0; i < nThreads; i++){ threads[i]->Join(); } - - cout << " ( DONE ) " << endl; - -} - +} -//to compile: g++ -DMYROOT -DMYROOT1 -g `root-config --cflags --glibs` -o moenchReadDataMT moenchReadDataMT.C -int main(int argc, char **argv){ - if(argc < 8){ - cout << "Usage: " << argv[0] << " fformat tit tdir runmin runoffset nThreads treeIndexStart [xTalkFactor]" << endl; - exit(-1); - } - - char *fformat = argv[1]; - char *tit = argv[2]; - char *tdir = argv[3]; - int runmin = atoi(argv[4]); - int runoffset = atoi(argv[5]); - int nThreads = atoi(argv[6]); - int treeIndexStart = atoi(argv[7]); - double xTalkFactor = 0.044; - if(argc == 9) - xTalkFactor = atof(argv[8]); - moenchReadDataMT(fformat, tit, tdir,runmin,runoffset,nThreads,treeIndexStart, xTalkFactor); - -} - diff --git a/slsDetectorCalibration/raedNoiseData.C b/slsDetectorCalibration/raedNoiseData.C index 141c0f6ef0..b2021b29fe 100644 --- a/slsDetectorCalibration/raedNoiseData.C +++ b/slsDetectorCalibration/raedNoiseData.C @@ -1,5 +1,4 @@ #include "moenchReadData.C" -#include "moenchReadOversampledData.C" @@ -14,12 +13,12 @@ void raedNoiseData(char *tit, int sign=1){ TFile *fout; THStack *hs2N; - sprintf(fname,"/data/moench_trieste_calibration_trees/flat_20keV_%s.root",tit); + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_0.root",tit); fout=new TFile(fname,"RECREATE"); - sprintf(fname,"/data/moench_trieste_calibration/flat_20keV_%s_f00000%%04d000_0.raw",tit); + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); - hs2N=moenchReadData(fname,tit,0,2000,1500,-500,2500,sign,0.,1,159,1,159, 0,1); + hs2N=moenchReadData(fname,0,3000,1500,-500,2500,1,0.,1,159,1,159, 0,1); hs2N->SetName(tit); hs2N->SetTitle(tit); (TH2F*)(hs2N->GetHists()->At(0))->Write(); @@ -37,59 +36,6 @@ void raedNoiseData(char *tit, int sign=1){ } -void raedOsNoiseData(){ - - - THStack *hs[10]; - - - - char fname[1000]; - char f[1000]; - TFile *fout; - - - - strcpy(fname,"/data/moench_xbox_201401_trees/noise_cds_g1_os10_2ndsample.root"); - fout=new TFile(fname,"RECREATE"); - - for (int ir=0; ir<10; ir++) { - sprintf(fname,"/data/moench_xbox_201401/moench_xbox_20140116/noise_os10_16rows_f00000%%04d000_%d.raw",ir); - hs[ir]=moenchReadOversampledData(fname,"cds_g1_os10",0,1000,1000,-500,500,1,10,0,160,0,16,0); - - } - TH2F *h; - int ii=0, ii1=0; - h=(TH2F*)(hs[0]->GetHists()->At(0)); - TH2F *hn=(TH2F*)h->Clone(); - for (int ir=1; ir<10; ir++) { - h=(TH2F*)(hs[ir]->GetHists()->At(0)); - for (int iy=0; iy<16; iy++) - for (int ix=0; ix<160; ix++) - for (int ib=0; ibGetNbinsX(); ib++) { - ii=h->GetYaxis()->FindBin(iy+ix*160); - ii1= hn->GetYaxis()->FindBin(iy+ir*16+ix*160); - hn->SetBinContent(ib+1,ii1,h->GetBinContent(ib+1,ii)); - - } - } - - - - hn->Write(); - - // (TH2F*)(hs2N->GetHists()->At(1))->Write(); - // (TH2F*)(hs2N->GetHists()->At(2))->Write(); - // (TH2F*)(hs2N->GetHists()->At(3))->Write(); - // (TH2F*)(hs2N->GetHists()->At(4))->Write(); - - - fout->Close(); - - - -} - void raedNoiseDataN(char *tit, int sign=1){ @@ -100,10 +46,10 @@ void raedNoiseDataN(char *tit, int sign=1){ TFile *fout; THStack *hs2N; - sprintf(fname,"/data/moench_noise_20140327_trees/noise_%s.root",tit); + sprintf(fname,"/data/moench_xbox_20140116/noise_%s.root",tit); fout=new TFile(fname,"RECREATE"); - sprintf(fname,"/data/moench_noise_20140327/noise_%s_f00000%%04d000_0.raw",tit); + sprintf(fname,"/data/moench_xbox_20140116/noise_%s_f00000%%04d000_0.raw",tit); hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,0); hs2N->SetName(tit); @@ -128,7 +74,7 @@ void g4() { raedNoiseData("cds_g4_low_gain"); raedNoiseData("cds_g4_sto1_only"); - raedNoiseData("cds_g4_no_sto"); + raedNoiseData("cds_g4_no sto"); @@ -138,7 +84,7 @@ void no_cds() { raedNoiseData("cds_disable_low_gain",-1); raedNoiseData("cds_disable_sto1_only",-1); - raedNoiseData("cds_disable_no_sto",-1); + raedNoiseData("cds_disable_no sto",-1); diff --git a/slsDetectorCalibration/readJungfrauData.C b/slsDetectorCalibration/readJungfrauData.C index 8ad92381ab..504a152586 100644 --- a/slsDetectorCalibration/readJungfrauData.C +++ b/slsDetectorCalibration/readJungfrauData.C @@ -5,14 +5,14 @@ TFile *fout; // output file THStack *hs2N; // collection of objects - 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); + //fout=new TFile("/mnt/slitnas/datadir_jungfrau02/analysis_tests/tests_random.root","RECREATE"); // + fout=new TFile("/mnt/slitnas/datadir_jungfrau02/20140404_lowEXrays/test.root","RECREATE"); + + hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140404_lowEXrays/Ti_1000clk_13kV40mA_%d.bin","tit",0,86,3000,-499.5,2500.5,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/digital_bit_adc_test/vb_1825_%d.bin","tit",0,7,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->SetName("cds_g4"); //hs2N->SetTitle("cds_g4"); @@ -25,7 +25,7 @@ //(TH2F*)(hs2N->GetHists()->At(5))->Write(); //(TH2F*)(hs2N->GetHists()->At(6))->Write(); - //fout->Close(); // uncomment + fout->Close(); // uncomment } diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 0f382ec9c5..1582030d40 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -92,8 +92,6 @@ class singlePhotonDetector { setClusterSize(csize); }; - - /** destructor. Deletes the cluster structure and the pdestalSubtraction array */ @@ -326,7 +324,7 @@ class singlePhotonDetector { \returns event mask enum for the given pixel */ eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];}; - + #ifdef MYROOT1 /** generates a tree and maps the branches @@ -335,27 +333,22 @@ class singlePhotonDetector { \returns returns pointer to the TTree */ TTree *initEventTree(char *tname, int *iFrame=NULL) { - cout << tname << endl; TTree* tall=new TTree(tname,tname); - cout << "tree instantiated" << endl; + if (iFrame) tall->Branch("iFrame",iFrame,"iframe/I"); else tall->Branch("iFrame",&(cluster->iframe),"iframe/I"); - cout << "iframe" << endl; - char tit[100]; + tall->Branch("x",&(cluster->x),"x/I"); tall->Branch("y",&(cluster->y),"y/I"); + char tit[100]; sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY); tall->Branch("data",cluster->data,tit); - tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); - tall->Branch("rms",&(cluster->rms),"rms/D"); - cout << "Cluster" << endl; + // tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); + // tall->Branch("rms",&(cluster->rms),"rms/D"); return tall; }; -#else - /** write cluster to filer*/ - void writeCluster(FILE* myFile){cluster->write(myFile);}; #endif @@ -380,6 +373,7 @@ class singlePhotonDetector { double tot; /**< sum of the 3x3 cluster */ double quadTot; /**< sum of the maximum 2x2cluster */ + }; diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 809b23de32..294f7c8717 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -84,7 +84,7 @@ class slsDetectorData { for (int ix=0; ix { slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; - /** + + /** Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. \param buff pointer to the dataset \returns frame number - */ + */ virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; - /** + /** Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. \param buff pointer to the dataset @@ -44,7 +45,7 @@ class slsReceiverData : public slsDetectorData { */ - virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;}; + virtual int getPacketNumber(char *buff) {return (*(int*)buff)&0xff;}; @@ -60,52 +61,52 @@ class slsReceiverData : public slsDetectorData { */ virtual char *findNextFrame(char *data, int &ndata, int dsize) { - char *retval=NULL, *p=data; - int dd=0; - int fn, fnum=-1, np=0, pnum=-1; - while (dd<=(dsize-packetSize)) { - pnum=getPacketNumber(p); - fn=getFrameNumber(p); - - - if (pnum<1 || pnum>nPackets) { - cout << "Bad packet number " << pnum << " frame "<< fn << endl; - retval=NULL; - np=0; - } else if (pnum==1) { - retval=p; - if (np>0) - /*cout << "*Incomplete frame number " << fnum << endl;*/ - np=0; - fnum=fn; - } else if (fn!=fnum) { - if (fnum!=-1) { - /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ - retval=NULL; - } - np=0; - } - p+=packetSize; - dd+=packetSize; - np++; - // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; - if (np==nPackets) - if (pnum==nPackets) { - // cout << "Frame found!" << endl; - break; - } else { - cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; - retval=NULL; - } - } - if (np0) - cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; - } - - ndata=np*packetSize; - // cout << "return " << ndata << endl; - return retval; + char *retval=NULL, *p=data; + int dd=0; + int fn, fnum=-1, np=0, pnum=-1; + while (dd<=(dsize-packetSize)) { + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + + + if (pnum<1 || pnum>nPackets) { + cout << "Bad packet number " << pnum << " frame "<< fn << endl; + retval=NULL; + np=0; + } else if (pnum==1) { + fnum=fn; + retval=p; + if (np>0) + /*cout << "*Incomplete frame number " << fnum << endl;*/ + np=0; + } else if (fn!=fnum) { + if (fnum!=-1) { + /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ + retval=NULL; + } + np=0; + } + p+=packetSize; + dd+=packetSize; + np++; + // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; + if (np==nPackets) + if (pnum==nPackets) { + // cout << "Frame found!" << endl; + break; + } else { + cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; + retval=NULL; + } + } + if (np0) + cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; + } + + ndata=np*packetSize; + // cout << "return " << ndata << endl; + return retval; }; /** From f8aeb91752c26219f11b3c8637022e0662bd66c6 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 10 Apr 2014 09:08:13 +0000 Subject: [PATCH 050/104] put in the myroot1 definition git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@50 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/singlePhotonDetector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 1582030d40..b3cfd2ab59 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -9,7 +9,7 @@ #include "commonModeSubtraction.h" -#define MYROOT1 +//#define MYROOT1 #ifdef MYROOT1 #include From c352fbec21348978ac84fa13a918eed5e49a4b44 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 10 Apr 2014 12:48:55 +0000 Subject: [PATCH 051/104] reverted singlephotondetector and slreceiverdata git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@51 113b152e-814d-439b-b186-022a431db7b5 --- slsDetectorCalibration/singlePhotonDetector.h | 8 +- slsDetectorCalibration/slsReceiverData.h | 225 +++++++++--------- 2 files changed, 118 insertions(+), 115 deletions(-) diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index b3cfd2ab59..f090730a10 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -345,10 +345,14 @@ class singlePhotonDetector { char tit[100]; sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY); tall->Branch("data",cluster->data,tit); - // tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); - // tall->Branch("rms",&(cluster->rms),"rms/D"); + tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); + tall->Branch("rms",&(cluster->rms),"rms/D"); return tall; }; +#else + /** write cluster to filer*/ + void writeCluster(FILE* myFile){cluster->write(myFile);}; + #endif diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index 93c6453b49..e07a757fd6 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -7,164 +7,163 @@ template class slsReceiverData : public slsDetectorData { - public: +public: - /** - slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. + /** + slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. Inherits and implements slsDetectorData. Constructor (no error checking if datasize and offsets are compatible!) \param npx number of pixels in the x direction \param npy number of pixels in the y direction (1 for strips) \param np number of packets - \param psize packets size + \param psize packets size \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) - \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. - */ - slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; + */ + slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; - - - /** - Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. \param buff pointer to the dataset \returns frame number - */ + */ - virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; + virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; - /** + /** - Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. + Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. \param buff pointer to the dataset \returns packet number number - */ + */ - virtual int getPacketNumber(char *buff) {return (*(int*)buff)&0xff;}; + virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;}; - /** + /** Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! \param data pointer to the memory to be analyzed \param ndata size of frame returned \param dsize size of the memory slot to be analyzed - \returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found - - */ - - virtual char *findNextFrame(char *data, int &ndata, int dsize) { - char *retval=NULL, *p=data; - int dd=0; - int fn, fnum=-1, np=0, pnum=-1; - while (dd<=(dsize-packetSize)) { - pnum=getPacketNumber(p); - fn=getFrameNumber(p); - - - if (pnum<1 || pnum>nPackets) { - cout << "Bad packet number " << pnum << " frame "<< fn << endl; - retval=NULL; - np=0; - } else if (pnum==1) { - fnum=fn; - retval=p; - if (np>0) - /*cout << "*Incomplete frame number " << fnum << endl;*/ - np=0; - } else if (fn!=fnum) { - if (fnum!=-1) { - /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ - retval=NULL; - } - np=0; - } - p+=packetSize; - dd+=packetSize; - np++; - // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; - if (np==nPackets) - if (pnum==nPackets) { - // cout << "Frame found!" << endl; - break; - } else { - cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; - retval=NULL; - } - } - if (np0) - cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; - } - - ndata=np*packetSize; - // cout << "return " << ndata << endl; - return retval; - }; - - /** - - Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found + + */ + + virtual char *findNextFrame(char *data, int &ndata, int dsize) { + char *retval=NULL, *p=data; + int dd=0; + int fn, fnum=-1, np=0, pnum=-1; + while (dd<=(dsize-packetSize)) { + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + + + if (pnum<1 || pnum>nPackets) { + cout << "Bad packet number " << pnum << " frame "<< fn << endl; + retval=NULL; + np=0; + } else if (pnum==1) { + retval=p; + if (np>0) + /*cout << "*Incomplete frame number " << fnum << endl;*/ + np=0; + fnum=fn; + } else if (fn!=fnum) { + if (fnum!=-1) { + /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ + retval=NULL; + } + np=0; + } + p+=packetSize; + dd+=packetSize; + np++; + // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; + if (np==nPackets) + if (pnum==nPackets) { + // cout << "Frame found!" << endl; + break; + } else { + cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; + retval=NULL; + } + } + if (np0) + cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; + } + + ndata=np*packetSize; + // cout << "return " << ndata << endl; + return retval; + }; + + /** + + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! \param filebin input file stream (binary) \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete - */ + */ - virtual char *readNextFrame(ifstream &filebin) { - char *data=new char[packetSize*nPackets]; - char *retval=0; - int np=0, nd; + virtual char *readNextFrame(ifstream &filebin) { + char *data=new char[packetSize*nPackets]; + char *retval=0; + int np=0, nd; - if (filebin.is_open()) { - while (filebin.read(data+np*packetSize,packetSize)) { + if (filebin.is_open()) { + while (filebin.read(data+np*packetSize,packetSize)) { - if (np==(nPackets-1)) { + if (np==(nPackets-1)) { - retval=findNextFrame(data,nd,packetSize*nPackets); - np=nd/packetSize; - // cout << np << endl; + retval=findNextFrame(data,nd,packetSize*nPackets); + np=nd/packetSize; + // cout << np << endl; - if (retval==data && np==nPackets) { - // cout << "-" << endl; - return data; + if (retval==data && np==nPackets) { + // cout << "-" << endl; + return data; - } else if (np>nPackets) { - cout << "too many packets!!!!!!!!!!" << endl; - delete [] data; - return NULL; - } else if (retval!=NULL) { - // cout << "+" << endl;; - for (int ip=0; ipnPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else if (retval!=NULL) { + // cout << "+" << endl;; + for (int ip=0; ipnPackets) { - cout << "*******too many packets!!!!!!!!!!" << endl; - delete [] data; - return NULL; - } else { - // cout << "." << endl;; - np++; - } - } - } - delete [] data; - return NULL; - }; + } else if (np>nPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + // cout << "." << endl;; + np++; + } + } + } + delete [] data; + return NULL; + }; - private: - const int nPackets; /** Date: Thu, 3 Jul 2014 13:59:11 +0200 Subject: [PATCH 052/104] git ignore added --- slsDetectorCalibration/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 slsDetectorCalibration/.gitignore diff --git a/slsDetectorCalibration/.gitignore b/slsDetectorCalibration/.gitignore new file mode 100644 index 0000000000..5761abcfdf --- /dev/null +++ b/slsDetectorCalibration/.gitignore @@ -0,0 +1 @@ +*.o From b5193b9bc39aa98dd280cda71332075ed399ba41 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Thu, 3 Jul 2014 14:03:31 +0200 Subject: [PATCH 053/104] no change --- slsDetectorCalibration/doxy.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/doxy.config b/slsDetectorCalibration/doxy.config index 7d2a396ff4..7f1241be06 100644 --- a/slsDetectorCalibration/doxy.config +++ b/slsDetectorCalibration/doxy.config @@ -80,6 +80,6 @@ LATEX_HIDE_INDICES = YES PREDEFINED = __cplusplus -INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h chiptestBoardData.h jungfrau02Data.h jungfrauReadData.C jungfrau02CommonMode.h +INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h chiptestBoardData.h jungfrau02Data.h jungfrauReadData.C jungfrau02CommonMode.h OUTPUT_DIRECTORY = docs From baac5df54e9e6ba5ef710897441da8706f2c517d Mon Sep 17 00:00:00 2001 From: Smith Julia Helga Date: Thu, 3 Jul 2014 14:47:30 +0200 Subject: [PATCH 054/104] Julia's first test :) --- slsDetectorCalibration/.gitignore | 1 + slsDetectorCalibration/jungfrau02Data.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/slsDetectorCalibration/.gitignore b/slsDetectorCalibration/.gitignore index 5761abcfdf..5f41dcb883 100644 --- a/slsDetectorCalibration/.gitignore +++ b/slsDetectorCalibration/.gitignore @@ -1 +1,2 @@ *.o +*.*~ diff --git a/slsDetectorCalibration/jungfrau02Data.h b/slsDetectorCalibration/jungfrau02Data.h index e7b3d6b77a..ebc18ed937 100644 --- a/slsDetectorCalibration/jungfrau02Data.h +++ b/slsDetectorCalibration/jungfrau02Data.h @@ -8,7 +8,7 @@ class jungfrau02Data : public chiptestBoardData { public: - +/* test :) */ /** From 02a69a0a6ca4495f9e527b185ad3d6e602fca29f Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 27 Jan 2015 17:34:20 +0100 Subject: [PATCH 055/104] moench03Ctb data structure and readout funcs added --- slsDetectorCalibration/moench03CtbData.h | 150 ++++++++++++ slsDetectorCalibration/moench03ReadData.C | 267 ++++++++++++++++++++++ slsDetectorCalibration/slsDetectorData.h | 25 +- 3 files changed, 433 insertions(+), 9 deletions(-) create mode 100644 slsDetectorCalibration/moench03CtbData.h create mode 100644 slsDetectorCalibration/moench03ReadData.C diff --git a/slsDetectorCalibration/moench03CtbData.h b/slsDetectorCalibration/moench03CtbData.h new file mode 100644 index 0000000000..226e1f2379 --- /dev/null +++ b/slsDetectorCalibration/moench03CtbData.h @@ -0,0 +1,150 @@ +#ifndef MOENCH03CTBDATA_H +#define MOENCH03CTBDATA_H +#include "slsDetectorData.h" + + + +class moench03CtbData : public slsDetectorData { + + private: + + int iframe; + int *xmap, *ymap; + int nadc; + int sc_width; + int sc_height; + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + moench03CtbData(int ns=5000): slsDetectorData(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) { + + + int adc_nr[32]={200,225,250,275,300,325,350,375,0,25,50,75,100,125,150,175,175,150,125,100,75,50,25,0,375,350,325,300,275,250,225,200}; + int row, col; + + int isample; + int iadc; + int ix, iy; + + xmap=new int[nx*ny]; + ymap=new int[nx*ny]; + + + + + for (iadc=0; iadc=2*400*400) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + } + for (int i=0; i=0 && ip +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include +#include +#include "moench03CtbData.h" +#include "moenchCommonMode.h" +#define MYROOT1 +#include "singlePhotonDetector.h" + +//#include "MovingStat.h" + +using namespace std; + +#define NC 400 +#define NR 400 + + +#define MY_DEBUG 1 +#ifdef MY_DEBUG +#include +#endif + + + +TH2F *readImage(ifstream &filebin, int dsize=5000*32) { + moench03CtbData *decoder=new moench03CtbData(); + char *buff=decoder->readNextFrame(filebin); + TH2F *h2=NULL; + +// TH1F *h1=new TH1F("h1","",400*400,0,400*400); +// int ip=0; + if (buff) { + h2=new TH2F("h2","",400,0,400,400,0,400); + h2->SetStats(kFALSE); + for (int ix=0; ix<400; ix++) { + for (int iy=0; iy<400; iy++) { + // cout << decoder->getDataSize() << " " << decoder->getValue(buff,ix,iy)<< endl; + h2->SetBinContent(ix+1,iy+1,decoder->getValue(buff,ix,iy)); + // h1->SetBinContent(++ip,decoder->getValue(buff,ix,iy)); + } + } + } + return h2; +} + + +TH2F *readImage(char *fname) { + ifstream filebin; + filebin.open((const char *)(fname), ios::in | ios::binary); + TH2F *h2=readImage(filebin); + filebin.close(); + return h2; +} +/** + +Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis. + + \param fformat file name format + \param tit title of the tree etc. + \param runmin minimum run number + \param runmax max run number + \param nbins number of bins for spectrum hists + \param hmin histo minimum for spectrum hists + \param hmax histo maximum for spectrum hists + \param sign sign of the spectrum to find hits + \param hc readout correlation coefficient with previous pixel + \param xmin minimum x coordinate + \param xmax maximum x coordinate + \param ymin minimum y coordinate + \param ymax maximum y coordinate + \param cmsub enable commonmode subtraction + \returns pointer to histo stack with cluster spectra +*/ + +THStack *moench03ReadData(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) { + + moench03CtbData *decoder=new moench03CtbData(); + moenchCommonMode *cmSub=NULL; +// if (cmsub) +// cmSub=new moenchCommonMode(); + int iev=0; + int nph=0; + + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); + + char *buff; + char fname[10000]; + int nf=0; + + eventType thisEvent=PEDESTAL; + + // int iframe; + // double *data, ped, sigma; + + // data=decoder->getCluster(); + + TH2F *h2; + TH2F *h3; + TH2F *hetaX; + TH2F *hetaY; + + 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); + h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h2); + hs->Add(h3); + hs->Add(hetaX); + hs->Add(hetaY); + } + + + + ifstream filebin; + + + int ix=20, iy=20, ir, ic; + + + Int_t iFrame; + TTree *tall; + if (hitfinder) + tall=filter->initEventTree(tit, &iFrame); + + + + +#ifdef MY_DEBUG + + TCanvas *myC; + TH2F *he; + TCanvas *cH1; + TCanvas *cH2; + TCanvas *cH3; + + if (hitfinder) { + myC=new TCanvas(); + he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); + he->SetStats(kFALSE); + he->Draw("colz"); + cH1=new TCanvas(); + cH1->SetLogz(); + h1->Draw("colz"); + cH2=new TCanvas(); + cH2->SetLogz(); + h2->Draw("colz"); + cH3=new TCanvas(); + cH3->SetLogz(); + h3->Draw("colz"); + } +#endif + filter->newDataSet(); + + + for (int irun=runmin; irunreadNextFrame(filebin))) { + + + if (hitfinder) { + filter->newFrame(); + + //calculate pedestals and common modes + if (cmsub) { + // cout << "cm" << endl; + for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); + } + } + } + + // cout << "new frame " << endl; + + for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); + +#ifdef MY_DEBUG + if (hitfinder) { + if (iev%1000==0) + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); + } +#endif + + if (nf>1000) { + h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + if (hitfinder) { + + if (thisEvent==PHOTON_MAX ) { + nph++; + + h2->Fill(filter->getClusterTotal(2), iy+NR*ix); + h3->Fill(filter->getClusterTotal(3), iy+NR*ix); + iFrame=decoder->getFrameNumber(buff); + + tall->Fill(); + + + } + + + } + + + } + } + ////////////////////////////////////////////////////////// + +#ifdef MY_DEBUG + if (iev%1000==0) { + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); + } + iev++; +#endif + nf++; + + cout << "=" ; + delete [] buff; + } + cout << nph << endl; + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + } + if (hitfinder) + tall->Write(tall->GetName(),TObject::kOverwrite); + + + + delete decoder; + cout << "Read " << nf << " frames" << endl; + return hs; +} + diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 294f7c8717..8240a74845 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -11,6 +11,14 @@ using namespace std; template class slsDetectorData { + protected: + const int nx; /**< Number of pixels in the x direction */ + const int ny; /**< Number of pixels in the y direction */ + int dataSize; /** Date: Thu, 29 Jan 2015 11:20:24 +0100 Subject: [PATCH 056/104] possibility of reading images, pedestal etc. for moench03 implemented --- slsDetectorCalibration/moench03ReadData.C | 55 ++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/slsDetectorCalibration/moench03ReadData.C b/slsDetectorCalibration/moench03ReadData.C index 886d9621fd..badfada0d2 100644 --- a/slsDetectorCalibration/moench03ReadData.C +++ b/slsDetectorCalibration/moench03ReadData.C @@ -56,13 +56,66 @@ TH2F *readImage(ifstream &filebin, int dsize=5000*32) { } -TH2F *readImage(char *fname) { +TH2F *readImage(char *fname, int iframe=0, TH2F *hped=NULL) { ifstream filebin; filebin.open((const char *)(fname), ios::in | ios::binary); TH2F *h2=readImage(filebin); + for (int i=0; iSetBinContent(ix+1, iy+1,filter->getPedestal(ix,iy)); + } + } + + } return h2; + } + /** Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis. From 5735aff30c3410837fe0720457bb6055af3b318a Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 10 Feb 2015 10:15:16 +0100 Subject: [PATCH 057/104] Added Moench03 common mode and photon finder/pedestal funcs --- slsDetectorCalibration/moench03CommonMode.h | 45 ++++++ slsDetectorCalibration/moench03CtbData.h | 25 ++- slsDetectorCalibration/moench03ReadData.C | 136 +++++++++++------ slsDetectorCalibration/readMoench03Data.C | 143 ++++++++++++++++++ slsDetectorCalibration/singlePhotonDetector.h | 2 +- 5 files changed, 299 insertions(+), 52 deletions(-) create mode 100644 slsDetectorCalibration/moench03CommonMode.h create mode 100644 slsDetectorCalibration/readMoench03Data.C diff --git a/slsDetectorCalibration/moench03CommonMode.h b/slsDetectorCalibration/moench03CommonMode.h new file mode 100644 index 0000000000..7c950a9e4a --- /dev/null +++ b/slsDetectorCalibration/moench03CommonMode.h @@ -0,0 +1,45 @@ +#ifndef MOENCH03COMMONMODE_H +#define MOENCH03COMMONMODE_H + +#include "commonModeSubtraction.h" + +class moench03CommonMode : public commonModeSubtraction { + /** @short class to calculate the common mode noise for moench02 i.e. on 4 supercolumns separately */ + public: + /** constructor - initalizes a commonModeSubtraction with 4 different regions of interest + \param nn number of samples for the moving average + */ + moench03CommonMode(int nn=1000) : commonModeSubtraction(nn,32){} ; + + + /** add value to common mode as a function of the pixel value, subdividing the region of interest in the 4 supercolumns of 40 columns each; + \param val value to add to the common mode + \param ix pixel coordinate in the x direction + \param iy pixel coordinate in the y direction + */ + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + // (void) iy; + int isc=ix/25+(iy/200)*16; + if (isc>=0 && isc=0 && isc0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); + } + return 0; + }; + +}; + + +#endif diff --git a/slsDetectorCalibration/moench03CtbData.h b/slsDetectorCalibration/moench03CtbData.h index 226e1f2379..30bebed23c 100644 --- a/slsDetectorCalibration/moench03CtbData.h +++ b/slsDetectorCalibration/moench03CtbData.h @@ -29,7 +29,10 @@ class moench03CtbData : public slsDetectorData { moench03CtbData(int ns=5000): slsDetectorData(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) { - int adc_nr[32]={200,225,250,275,300,325,350,375,0,25,50,75,100,125,150,175,175,150,125,100,75,50,25,0,375,350,325,300,275,250,225,200}; + int adc_nr[32]={200,225,250,275,300,325,350,375,\ + 0,25,50,75,100,125,150,175,\ + 175,150,125,100,75,50,25,0,\ + 375,350,325,300,275,250,225,200}; int row, col; int isample; @@ -126,18 +129,24 @@ class moench03CtbData : public slsDetectorData { */ virtual char *readNextFrame(ifstream &filebin){ // int afifo_length=0; - uint16_t *afifo_cont; - if (filebin.is_open()) { + uint16_t *afifo_cont; + int ib=0; + if (filebin.is_open()) { afifo_cont=new uint16_t[dataSize/2]; - if (filebin.read((char*)afifo_cont,dataSize)) { + while (filebin.read(((char*)afifo_cont)+ib,2)) { + ib+=2; + if (ib==dataSize) break; + } + if (ib>0) { iframe++; + cout << ib << "-" << endl; return (char*)afifo_cont; } else { - delete [] afifo_cont; - return NULL; + delete [] afifo_cont; + return NULL; } - } - return NULL; + } + return NULL; }; diff --git a/slsDetectorCalibration/moench03ReadData.C b/slsDetectorCalibration/moench03ReadData.C index badfada0d2..a2f268aff1 100644 --- a/slsDetectorCalibration/moench03ReadData.C +++ b/slsDetectorCalibration/moench03ReadData.C @@ -15,7 +15,7 @@ //#include #include #include "moench03CtbData.h" -#include "moenchCommonMode.h" +#include "moench03CommonMode.h" #define MYROOT1 #include "singlePhotonDetector.h" @@ -28,22 +28,26 @@ using namespace std; #define MY_DEBUG 1 + #ifdef MY_DEBUG #include #endif -TH2F *readImage(ifstream &filebin, int dsize=5000*32) { +TH2F *readImage(ifstream &filebin, TH2F *h2=NULL, TH2F *hped=NULL) { moench03CtbData *decoder=new moench03CtbData(); char *buff=decoder->readNextFrame(filebin); - TH2F *h2=NULL; + // TH1F *h1=new TH1F("h1","",400*400,0,400*400); // int ip=0; if (buff) { - h2=new TH2F("h2","",400,0,400,400,0,400); - h2->SetStats(kFALSE); + if (h2==NULL) { + h2=new TH2F("h2","",400,0,400,400,0,400); + h2->SetStats(kFALSE); + } + cout << "." << endl; for (int ix=0; ix<400; ix++) { for (int iy=0; iy<400; iy++) { // cout << decoder->getDataSize() << " " << decoder->getValue(buff,ix,iy)<< endl; @@ -51,23 +55,37 @@ TH2F *readImage(ifstream &filebin, int dsize=5000*32) { // h1->SetBinContent(++ip,decoder->getValue(buff,ix,iy)); } } + if (hped) h2->Add(hped,-1); + return h2; } - return h2; + return NULL; } TH2F *readImage(char *fname, int iframe=0, TH2F *hped=NULL) { ifstream filebin; filebin.open((const char *)(fname), ios::in | ios::binary); - TH2F *h2=readImage(filebin); + TH2F *h2=new TH2F("h2","",400,0,400,400,0,400); + TH2F *hh; + hh=readImage(filebin, h2, hped ); + if (hh==NULL) { + + delete h2; + return NULL; + } for (int i=0; iAdd(hped,-1); return h2; @@ -96,6 +114,7 @@ TH2F *calcPedestal(char *fformat, int runmin, int runmax){ } } delete [] buff; + cout << "="<< endl; ii++; } if (filebin.is_open()) @@ -140,13 +159,22 @@ Loops over data file to find single photons, fills the tree (and writes it to fi THStack *moench03ReadData(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) { moench03CtbData *decoder=new moench03CtbData(); - moenchCommonMode *cmSub=NULL; -// if (cmsub) -// cmSub=new moenchCommonMode(); + cout << "decoder allocated " << endl; + + moench03CommonMode *cmSub=NULL; + if (cmsub) { + cmSub=new moench03CommonMode(100); + cout << "common mode allocated " << endl; + + } else { + + cout << "non allocating common mode " << endl; + } int iev=0; int nph=0; - singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 10, 100); + cout << "filter allocated " << endl; char *buff; char fname[10000]; @@ -159,29 +187,36 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int // data=decoder->getCluster(); - TH2F *h2; - TH2F *h3; - TH2F *hetaX; - TH2F *hetaY; THStack *hs=new THStack("hs",fformat); + cout << "hstack allocated " << endl; TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); hs->Add(h1); + cout << "h1 allocated " << endl; + TH2F *h2; + TH2F *h3; if (hitfinder) { h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + cout << "h2 allocated " << endl; h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); - hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + cout << "h3 allocated " << endl; + // hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + // hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); hs->Add(h2); hs->Add(h3); - hs->Add(hetaX); - hs->Add(hetaY); + // hs->Add(hetaX); + // hs->Add(hetaY); } - + if (hs->GetHists()) { + for (int i=0; i<3; i++) + if (hs->GetHists()->At(1)) cout << i << " " ; + cout << " histos allocated " << endl; + } else + cout << "no hists in stack " << endl; ifstream filebin; @@ -199,6 +234,8 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int #ifdef MY_DEBUG + + cout << "debug mode " << endl; TCanvas *myC; TH2F *he; @@ -207,21 +244,22 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int TCanvas *cH3; if (hitfinder) { - myC=new TCanvas(); + myC=new TCanvas("myc"); he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); he->SetStats(kFALSE); he->Draw("colz"); - cH1=new TCanvas(); + cH1=new TCanvas("ch1"); cH1->SetLogz(); h1->Draw("colz"); - cH2=new TCanvas(); + cH2=new TCanvas("ch2"); cH2->SetLogz(); h2->Draw("colz"); - cH3=new TCanvas(); + cH3=new TCanvas("ch3"); cH3->SetLogz(); h3->Draw("colz"); } #endif + filter->newDataSet(); @@ -255,12 +293,12 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int #ifdef MY_DEBUG if (hitfinder) { - if (iev%1000==0) + // if (iev%10==0) he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); } #endif - if (nf>1000) { + // if (nf>10) { h1->Fill(filter->getClusterTotal(1), iy+NR*ix); if (hitfinder) { @@ -280,21 +318,22 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int } - } + // } } ////////////////////////////////////////////////////////// #ifdef MY_DEBUG - if (iev%1000==0) { - myC->Modified(); - myC->Update(); - cH1->Modified(); - cH1->Update(); - cH2->Modified(); - cH2->Update(); - cH3->Modified(); - cH3->Update(); - } + cout << iev << " " << h1->GetEntries() << " " << h2->GetEntries() << endl; +// if (iev%10==0) { +// myC->Modified(); +// myC->Update(); +// cH1->Modified(); +// cH1->Update(); +// cH2->Modified(); +// cH2->Update(); +// cH3->Modified(); +// cH3->Update(); +// } iev++; #endif nf++; @@ -311,7 +350,18 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int if (hitfinder) tall->Write(tall->GetName(),TObject::kOverwrite); + ////////////////////////////////////////////////////////// +#ifdef MY_DEBUG + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); +#endif delete decoder; cout << "Read " << nf << " frames" << endl; diff --git a/slsDetectorCalibration/readMoench03Data.C b/slsDetectorCalibration/readMoench03Data.C new file mode 100644 index 0000000000..2bf22e111e --- /dev/null +++ b/slsDetectorCalibration/readMoench03Data.C @@ -0,0 +1,143 @@ +#include "moench03ReadData.C" + + + +void readMoench03Data(char *tit, int sign=1){ + + + + + + char fname[1000]; + TFile *fout; + THStack *hs; + + sprintf(fname,"/scratch/roberto/photons.root"); + fout=new TFile(fname,"RECREATE"); + + sprintf(fname,"/scratch/roberto/run_%%d.raw"); + + hs=moench03ReadData(fname,"photons",136,1135,1500,-500,2500,1,0.,1,399,1,399, 0,1); +// cout << "returned" << endl; +// hs->SetName(tit); +// hs->SetTitle(tit); +// cout << "name/title set" << endl; + + +// if (hs->GetHists()) { +// for (int i=0; i<3; i++) { +// if (hs->GetHists()->At(i)) { +// cout << i << " " ; +// (TH2F*)(hs->GetHists()->At(i))->Write(); +// } +// } +// cout << " histos written " << endl; +// } else +// cout << "no hists in stack " << endl; + + +// fout->Close(); + + + +} + + + +// void raedNoiseDataN(char *tit, int sign=1){ + + + +// char fname[1000]; +// char f[1000]; +// TFile *fout; +// THStack *hs2N; + +// sprintf(fname,"/data/moench_xbox_20140116/noise_%s.root",tit); +// fout=new TFile(fname,"RECREATE"); + +// sprintf(fname,"/data/moench_xbox_20140116/noise_%s_f00000%%04d000_0.raw",tit); + +// hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,0); +// hs2N->SetName(tit); +// hs2N->SetTitle(tit); +// (TH2F*)(hs2N->GetHists()->At(0))->Write(); + +// // (TH2F*)(hs2N->GetHists()->At(1))->Write(); +// // (TH2F*)(hs2N->GetHists()->At(2))->Write(); +// // (TH2F*)(hs2N->GetHists()->At(3))->Write(); +// // (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + +// fout->Close(); + + + +// } + + + +// void g4() { + +// raedNoiseData("cds_g4_low_gain"); +// raedNoiseData("cds_g4_sto1_only"); +// raedNoiseData("cds_g4_no sto"); + + + +// } + +// void no_cds() { + +// raedNoiseData("cds_disable_low_gain",-1); +// raedNoiseData("cds_disable_sto1_only",-1); +// raedNoiseData("cds_disable_no sto",-1); + + + +// } + +// void all_gains() { + +// raedNoiseData("cds_g2"); +// raedNoiseData("cds_g2HC"); +// raedNoiseData("cds_g1_2"); +// raedNoiseData("cds_g2_3"); + + + +// } + +// void all_low_gains() { + +// raedNoiseData("cds_g2_low_gain"); +// raedNoiseData("cds_g2HC_low_gain"); +// raedNoiseData("cds_g1_2_low_gain"); +// raedNoiseData("cds_g2_3_low_gain"); +// } + +// /* +// clkdivider data +// /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv17_f000000010000_0.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 12:40 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv25_f000000010000_0.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 13:26 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv35_f000000010000_0.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:09 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv50_f000000010000_0.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:54 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv70_f000000010000_0.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 16:42 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv110_f000000010000_0.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 17:27 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv170_f000000010000_0.raw +// */ + + +// /* oversampled data +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:12 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_0.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:47 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_1.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 19:22 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_2.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:02 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_3.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:41 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_4.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:16 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_5.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:56 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_6.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 22:35 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_7.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:11 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_8.raw +// -rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:50 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_9.raw +// */ + diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index f090730a10..007851e28c 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -109,7 +109,7 @@ class singlePhotonDetector { \param cm commonModeSubtraction algorithm to be used (NULL unsets) \returns pointer to the actual common mode subtraction algorithm */ - commonModeSubtraction setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;}; + commonModeSubtraction *setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;}; /** From 8a79e94fa84dae2c1697d22b4281808e0d93a7a7 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Fri, 20 Feb 2015 11:39:35 +0100 Subject: [PATCH 058/104] Added draft of moench02 JCTB data --- slsDetectorCalibration/moench02CtbData.h | 152 +++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 slsDetectorCalibration/moench02CtbData.h diff --git a/slsDetectorCalibration/moench02CtbData.h b/slsDetectorCalibration/moench02CtbData.h new file mode 100644 index 0000000000..03ffd4ac56 --- /dev/null +++ b/slsDetectorCalibration/moench02CtbData.h @@ -0,0 +1,152 @@ +#ifndef MOENCH02CTBDATA_H +#define MOENCH02CTBDATA_H +#include "slsDetectorData.h" + + + +class moench02CtbData : public slsDetectorData { + + private: + + int iframe; + int *xmap, *ymap; + int nadc; + int sc_width; + int sc_height; + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + moench02CtbData(int ns=6400): slsDetectorData(160, 160, ns*2*32, NULL, NULL) , nadc(4), sc_width(40), sc_height(160) { + + + int adc_nr[4]={0,40,40,120}; + int row, col; + + int isample; + int iadc; + int ix, iy; + + xmap=new int[nx*ny]; + ymap=new int[nx*ny]; + + + + + for (iadc=0; iadc=2*160*160) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + } + for (int i=0; i=0 && ip0) { + iframe++; + cout << ib << "-" << endl; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } + return NULL; + }; + + + + +}; + + + +#endif From 985b4d71b409c021a60eab8fdf987e7f72a5f069 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Thu, 5 Mar 2015 13:04:31 +0100 Subject: [PATCH 059/104] Added jungfrau1.0 data structure (bad) and added xmap, ymap and getPixel method to the slsDetectorData base class --- slsDetectorCalibration/jungfrau10ModuleData.h | 154 ++++++++++++++++++ slsDetectorCalibration/moench02CtbData.h | 4 +- slsDetectorCalibration/moench03CtbData.h | 7 +- slsDetectorCalibration/moench03ReadData.C | 51 +++--- slsDetectorCalibration/readMoench03Data.C | 36 ++-- slsDetectorCalibration/slsDetectorData.h | 30 +++- 6 files changed, 227 insertions(+), 55 deletions(-) create mode 100644 slsDetectorCalibration/jungfrau10ModuleData.h diff --git a/slsDetectorCalibration/jungfrau10ModuleData.h b/slsDetectorCalibration/jungfrau10ModuleData.h new file mode 100644 index 0000000000..a107f50584 --- /dev/null +++ b/slsDetectorCalibration/jungfrau10ModuleData.h @@ -0,0 +1,154 @@ +#ifndef JUNGFRAU10MODULEDATA_H +#define JUNGFRAU10MODULEBDATA_H +#include "slsDetectorData.h" + + + +class jungfrau10ModuleData : public slsDetectorData { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + jungfrau10ModuleData(int ns=16384): slsDetectorData(256*4, 256*2, ns*2*32, NULL, NULL) , nadc(32), sc_width(64), sc_height(256) { + + + + int row, col; + + int isample; + int iadc; + int ix, iy; + + + + cout << nx << " " << ny << " " << dataSize << endl; + + for (iadc=0; iadc=dataSize) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + + } + + } + for (int i=0; i0) { + iframe++; + // cout << ib << "-" << endl; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } + return NULL; + }; + + + + +}; + + + +#endif diff --git a/slsDetectorCalibration/moench02CtbData.h b/slsDetectorCalibration/moench02CtbData.h index 03ffd4ac56..37bf8304d0 100644 --- a/slsDetectorCalibration/moench02CtbData.h +++ b/slsDetectorCalibration/moench02CtbData.h @@ -47,9 +47,11 @@ class moench02CtbData : public slsDetectorData { col=adc_nr[iadc]+(i%sc_width); row=i/sc_width; dataMap[row][col]=(32*i+iadc)*2; - if (dataMap[row][col]<0 || dataMap[row][col]>=2*160*160) + if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) { cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + } } for (int i=0; i { private: int iframe; - int *xmap, *ymap; int nadc; int sc_width; int sc_height; @@ -39,8 +38,6 @@ class moench03CtbData : public slsDetectorData { int iadc; int ix, iy; - xmap=new int[nx*ny]; - ymap=new int[nx*ny]; @@ -83,8 +80,6 @@ class moench03CtbData : public slsDetectorData { // cout << "data struct created" << endl; }; - void getPixel(int ip, int &x, int &y) {if (ip>=0 && ip { } if (ib>0) { iframe++; - cout << ib << "-" << endl; + // cout << ib << "-" << endl; return (char*)afifo_cont; } else { delete [] afifo_cont; diff --git a/slsDetectorCalibration/moench03ReadData.C b/slsDetectorCalibration/moench03ReadData.C index a2f268aff1..c54a7655e9 100644 --- a/slsDetectorCalibration/moench03ReadData.C +++ b/slsDetectorCalibration/moench03ReadData.C @@ -27,7 +27,7 @@ using namespace std; #define NR 400 -#define MY_DEBUG 1 +//#define MY_DEBUG 1 #ifdef MY_DEBUG #include @@ -47,7 +47,7 @@ TH2F *readImage(ifstream &filebin, TH2F *h2=NULL, TH2F *hped=NULL) { h2=new TH2F("h2","",400,0,400,400,0,400); h2->SetStats(kFALSE); } - cout << "." << endl; + // cout << "." << endl; for (int ix=0; ix<400; ix++) { for (int iy=0; iy<400; iy++) { // cout << decoder->getDataSize() << " " << decoder->getValue(buff,ix,iy)<< endl; @@ -77,7 +77,7 @@ TH2F *readImage(char *fname, int iframe=0, TH2F *hped=NULL) { if (hh==NULL) break; hh=readImage(filebin, h2, hped ); if (hh) - cout << "="<< endl; + ;// cout << "="<< endl; else { delete h2; return NULL; @@ -114,7 +114,7 @@ TH2F *calcPedestal(char *fformat, int runmin, int runmax){ } } delete [] buff; - cout << "="<< endl; + //cout << "="<< endl; ii++; } if (filebin.is_open()) @@ -146,8 +146,6 @@ Loops over data file to find single photons, fills the tree (and writes it to fi \param nbins number of bins for spectrum hists \param hmin histo minimum for spectrum hists \param hmax histo maximum for spectrum hists - \param sign sign of the spectrum to find hits - \param hc readout correlation coefficient with previous pixel \param xmin minimum x coordinate \param xmax maximum x coordinate \param ymin minimum y coordinate @@ -156,8 +154,10 @@ Loops over data file to find single photons, fills the tree (and writes it to fi \returns pointer to histo stack with cluster spectra */ -THStack *moench03ReadData(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 *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1) { + double hc=0; + int sign=1; + moench03CtbData *decoder=new moench03CtbData(); cout << "decoder allocated " << endl; @@ -173,7 +173,7 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int int iev=0; int nph=0; - singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 10, 100); + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 100, 10); cout << "filter allocated " << endl; char *buff; @@ -270,11 +270,8 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int nph=0; while ((buff=decoder->readNextFrame(filebin))) { + filter->newFrame(); - if (hitfinder) { - filter->newFrame(); - - //calculate pedestals and common modes if (cmsub) { // cout << "cm" << endl; for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); } } - } + // if (hitfinder) { + + // //calculate pedestals and common modes + // } // cout << "new frame " << endl; for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); + thisEvent=filter->getEventType(buff, ix, iy, cmsub); + // if (nf>10) { + h1->Fill(filter->getClusterTotal(1), iy+NR*ix); #ifdef MY_DEBUG - if (hitfinder) { // if (iev%10==0) - he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); - } + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); #endif - // if (nf>10) { - h1->Fill(filter->getClusterTotal(1), iy+NR*ix); - if (hitfinder) { + if (hitfinder) { if (thisEvent==PHOTON_MAX ) { nph++; @@ -315,7 +313,10 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int } - } + } // else { + // filter->addToPedestal(decoder->getValue(buff,ix,iy, cmsub)); + + // } // } @@ -323,7 +324,7 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int ////////////////////////////////////////////////////////// #ifdef MY_DEBUG - cout << iev << " " << h1->GetEntries() << " " << h2->GetEntries() << endl; + // cout << iev << " " << h1->GetEntries() << " " << h2->GetEntries() << endl; // if (iev%10==0) { // myC->Modified(); // myC->Update(); @@ -338,10 +339,10 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int #endif nf++; - cout << "=" ; + // cout << "=" ; delete [] buff; } - cout << nph << endl; + // cout << nph << endl; if (filebin.is_open()) filebin.close(); else diff --git a/slsDetectorCalibration/readMoench03Data.C b/slsDetectorCalibration/readMoench03Data.C index 2bf22e111e..8bbee83b38 100644 --- a/slsDetectorCalibration/readMoench03Data.C +++ b/slsDetectorCalibration/readMoench03Data.C @@ -12,31 +12,31 @@ void readMoench03Data(char *tit, int sign=1){ TFile *fout; THStack *hs; - sprintf(fname,"/scratch/roberto/photons.root"); + sprintf(fname,"/mnt/moenchnas/big_moench_xbox_20150223/Mo.root"); fout=new TFile(fname,"RECREATE"); - sprintf(fname,"/scratch/roberto/run_%%d.raw"); + sprintf(fname,"/mnt/moenchnas/big_moench_xbox_20150223/Mo_f0_%%d.raw"); - hs=moench03ReadData(fname,"photons",136,1135,1500,-500,2500,1,0.,1,399,1,399, 0,1); -// cout << "returned" << endl; -// hs->SetName(tit); -// hs->SetTitle(tit); -// cout << "name/title set" << endl; + hs=moench03ReadData(fname,"Mo",25133,25187,1500,-500,2500,1,399,1,399, 0,1); + cout << "returned" << endl; + hs->SetName(tit); + hs->SetTitle(tit); + cout << "name/title set" << endl; -// if (hs->GetHists()) { -// for (int i=0; i<3; i++) { -// if (hs->GetHists()->At(i)) { -// cout << i << " " ; -// (TH2F*)(hs->GetHists()->At(i))->Write(); -// } -// } -// cout << " histos written " << endl; -// } else -// cout << "no hists in stack " << endl; + if (hs->GetHists()) { + for (int i=0; i<3; i++) { + if (hs->GetHists()->At(i)) { + cout << i << " " ; + (TH2F*)(hs->GetHists()->At(i))->Write(); + } + } + cout << " histos written " << endl; + } else + cout << "no hists in stack " << endl; -// fout->Close(); + fout->Close(); diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 8240a74845..b433960f33 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -19,6 +19,8 @@ class slsDetectorData { dataType **dataMask; /**< Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) */ int **dataROIMask; /**< Array of size nx*ny 1 if channel is good (or in the ROI), 0 if bad channel (or out of ROI) */ + int *xmap; + int *ymap; public: @@ -56,6 +58,16 @@ class slsDetectorData { dataROIMask[i][j]=1; } + + + xmap=new int[dataSize/sizeof(dataType)]; + ymap=new int[dataSize/sizeof(dataType)]; + + for (int i=0 ; i=0 && ip Date: Mon, 16 Mar 2015 17:53:54 +0100 Subject: [PATCH 060/104] included a cstring include for compilation in slsReceiverData.h --- slsDetectorCalibration/slsReceiverData.h | 1 + 1 file changed, 1 insertion(+) diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index e07a757fd6..51e371434b 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -2,6 +2,7 @@ #define SLSRECEIVERDATA_H #include "slsDetectorData.h" +#include template class slsReceiverData : public slsDetectorData { From 9b11df1c31e58a7a884326a9788929e16b8dab3b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 24 Mar 2015 10:42:22 +0100 Subject: [PATCH 061/104] a trial version of eiger mapping data --- slsDetectorCalibration/eigerHalfModuleData.h | 172 +++++++++++++++++++ slsDetectorCalibration/slsDetectorData.h | 38 ++++ 2 files changed, 210 insertions(+) create mode 100644 slsDetectorCalibration/eigerHalfModuleData.h diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h new file mode 100644 index 0000000000..9257c173b3 --- /dev/null +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -0,0 +1,172 @@ +#ifndef EIGERMODULEDATA_H +#define EIGERMODULEDATA_H +#include "slsReceiverData.h" + + + +class eigerHalfModuleData : public slsReceiverData { +public: + + + + + /** + Implements the slsReceiverData structure for the eiger prototype read out by a half module i.e. using the slsReceiver + (256*256 pixels, 512 packets for 16 bit mode, 256 for 8, 128 for 4, 1024 for 32, 1040 etc.) + \param d dynamic range + \param c crosstalk parameter for the output buffer + + */ + + + eigerHalfModuleData(int np, int dr, int t, int bsize, int dsize, double c=0): slsReceiverData(xpixels, ypixels, nPackets, bsize), + xtalk(c), nPackets(np), dynamicRange(dr), bufferSize(bsize), dataSize(dsize){ + + + int **dMap; + uint32_t **dMask; + int ix, iy; + + dMap=new int*[ypixels]; + dMask=new uint32_t*[ypixels]; + + + for (int i = 0; i < ypixels; i++) { + dMap[i] = new int[xpixels]; + dMask[i] = new uint32_t[xpixels]; + } + + //Map + int totalNumberOfBytes = 1040 * dynamicRange * 16 *2; //for both 1g and 10g + int iPacket1 = 8; + int iPacket2 = (totalNumberOfBytes/2) + 8; + int iData1 = 0, iData2 = 0; + int iPort; + + for (int ir=0; ir= dataSize){ + iPacket1 += 16; + iData1 = 0; + } + }else{ + dMap[ir][ic] = iPacket2; + iPacket2 += (dynamicRange / 8); + iData2 +=(dynamicRange / 8); + if(iData2 >= dataSize){ + iPacket2 += 16; + iData2 = 0; + } + } + } + } + + + + + //Mask + for(ix=0; ixfnum); + }; + + + /** gets the packets number (last packet is labelled with 0 and is replaced with 40) + \param buff pointer to the memory + \returns packet number + */ + int getPacketNumber(char *buff){ + return htonl(*(unsigned int*)((eiger_packet_header *)((char*)(buff)))->num2); + }; + + + /** + returns the pixel value as double correcting for the output buffer crosstalk + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns channel value as double + + */ + double getValue(char *data, int ix, int iy=0) { + // cout << "##" << (void*)data << " " << ix << " " <::getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); + }; + + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ + double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ + double getXTalk() {return xtalk;} + + + + + + + +private: + + double xtalk; /**=0 && ix=0 && iy=0 && dataMap[iy][ix] Date: Wed, 25 Mar 2015 15:14:03 +0100 Subject: [PATCH 062/104] some more changes for eiger mapping --- slsDetectorCalibration/eigerHalfModuleData.h | 5 +- slsDetectorCalibration/slsDetectorData.h | 50 +++++++++++++------- slsDetectorCalibration/slsReceiverData.h | 3 +- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 9257c173b3..555edee54a 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -19,8 +19,8 @@ class eigerHalfModuleData : public slsReceiverData { */ - eigerHalfModuleData(int np, int dr, int t, int bsize, int dsize, double c=0): slsReceiverData(xpixels, ypixels, nPackets, bsize), - xtalk(c), nPackets(np), dynamicRange(dr), bufferSize(bsize), dataSize(dsize){ + eigerHalfModuleData(int dr, int np, int bsize, int dsize, double c=0): slsReceiverData(xpixels, ypixels, np, bsize), + xtalk(c), dynamicRange(dr), bufferSize(bsize), dataSize(dsize){ int **dMap; @@ -146,7 +146,6 @@ class eigerHalfModuleData : public slsReceiverData { const static int ypixels = 256; const int bufferSize; const int dataSize; - const int nPackets; const int dynamicRange; diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 26efa53af9..d76310d212 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -87,19 +87,21 @@ class slsDetectorData { void setDataMap(int **dMap=NULL) { - if (dMap==NULL) { - for (int iy=0; iy=0 && ix=0 && iy=0 && dataMap[iy][ix] { dd+=packetSize; np++; // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; - if (np==nPackets) + if (np==nPackets){ if (pnum==nPackets) { // cout << "Frame found!" << endl; break; @@ -98,6 +98,7 @@ class slsReceiverData : public slsDetectorData { cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; retval=NULL; } + } } if (np0) From 70c98a663de9c01088a55fea85f908aaaab92085 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 27 Mar 2015 17:42:23 +0100 Subject: [PATCH 063/104] eiger mapping done --- slsDetectorCalibration/eigerHalfModuleData.h | 7 +- slsDetectorCalibration/slsDetectorData.h | 74 ++++++++++++-------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 555edee54a..1c878af8cf 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -25,7 +25,6 @@ class eigerHalfModuleData : public slsReceiverData { int **dMap; uint32_t **dMask; - int ix, iy; dMap=new int*[ypixels]; dMask=new uint32_t*[ypixels]; @@ -70,9 +69,9 @@ class eigerHalfModuleData : public slsReceiverData { //Mask - for(ix=0; ix=0 && ix=0 && iy=0 && dataMap[iy][ix]=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; + return ((t >> (pixelval*4)) & 0xf)^m; + else if(dr == 8) + //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; + return ((t >> (pixelval*8)) & 0xff)^m; + else if(dr == 16){ + //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; + return ((t >> (pixelval*16)) & 0xffff)^m; + }else{ + //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; + return ((t >> (pixelval*32)) & 0xffffffff)^m; + } }; /** @@ -262,7 +272,9 @@ class slsDetectorData { \returns data for the selected channel, with inversion if required as double */ - virtual double getValue(char *data, int ix, int iy, int dr) {return (double)getChannel(data, ix, iy, dr);}; + virtual double getValue(char *data, int ix, int iy, int dr) { + return ((double)getChannel(data, ix, iy, dr)); + }; /** From 5e59c86d7249b599e5b208c85e3ebde1d7284f1a Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 31 Mar 2015 14:41:06 +0200 Subject: [PATCH 064/104] Jungfrau10ModuleData modified --- slsDetectorCalibration/jungfrau10ModuleData.h | 59 ++++++++++--------- slsDetectorCalibration/moench02CtbData.h | 22 ------- slsDetectorCalibration/slsDetectorData.h | 28 ++++++--- 3 files changed, 49 insertions(+), 60 deletions(-) diff --git a/slsDetectorCalibration/jungfrau10ModuleData.h b/slsDetectorCalibration/jungfrau10ModuleData.h index a107f50584..39db072161 100644 --- a/slsDetectorCalibration/jungfrau10ModuleData.h +++ b/slsDetectorCalibration/jungfrau10ModuleData.h @@ -25,7 +25,7 @@ class jungfrau10ModuleData : public slsDetectorData { */ - jungfrau10ModuleData(int ns=16384): slsDetectorData(256*4, 256*2, ns*2*32, NULL, NULL) , nadc(32), sc_width(64), sc_height(256) { + jungfrau10ModuleData(int ns=16384): slsDetectorData(256*4, 256*2, 256*256*8*2, NULL, NULL, NULL) , iframe(0), nadc(32), sc_width(64), sc_height(256) { @@ -35,48 +35,49 @@ class jungfrau10ModuleData : public slsDetectorData { int iadc; int ix, iy; - + int ichip; - cout << nx << " " << ny << " " << dataSize << endl; + // cout << sizeof(uint16_t) << endl; for (iadc=0; iadc=dataSize) - cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; - } - } - for (int i=0; i=ny || col<0 || col>=nx) { + cout << "Wrong row, column " << row << " " << col << " " << iadc << " " << i << endl; + } else + dataMap[row][col]=(nadc*i+iadc)*2; + if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) + cout << "Error: pointer " << dataMap[row][col] << " out of range " << row << " " << col <<" " << iadc << " " << i << endl; + else { + xmap[nadc*i+iadc]=col; + ymap[nadc*i+iadc]=row; + } + } } - - - iframe=0; - // cout << "data struct created" << endl; }; diff --git a/slsDetectorCalibration/moench02CtbData.h b/slsDetectorCalibration/moench02CtbData.h index 37bf8304d0..b2860a3f3f 100644 --- a/slsDetectorCalibration/moench02CtbData.h +++ b/slsDetectorCalibration/moench02CtbData.h @@ -36,9 +36,6 @@ class moench02CtbData : public slsDetectorData { int iadc; int ix, iy; - xmap=new int[nx*ny]; - ymap=new int[nx*ny]; - @@ -54,25 +51,6 @@ class moench02CtbData : public slsDetectorData { } } - for (int i=0; i Date: Tue, 31 Mar 2015 14:45:45 +0200 Subject: [PATCH 065/104] messing up while updating and merging --- slsDetectorCalibration/slsDetectorData.h | 84 ++++++++++++++++++++++++ slsDetectorCalibration/slsReceiverData.h | 4 +- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 0030091d74..4f696ae293 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -112,6 +112,7 @@ class slsDetectorData { void setDataMap(int **dMap=NULL) { +<<<<<<< HEAD if (dMap==NULL) { for (int iy=0; iy>>>>>> 7ef3348d521f1a704f974b05dd763cd65253dd98 }; @@ -227,6 +245,58 @@ class slsDetectorData { return d^m; }; + + /** + + Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded. + \param data pointer to the dataset (including headers etc) + \param ix pixel number in the x direction + \param iy pixel number in the y direction + \param dr dynamic range + \returns data for the selected channel, with inversion if required + + */ + virtual dataType getChannel(char *data, int ix, int iy, int dr) { + dataType m=0, d=0; + uint64_t t; + int numBytes,divFactor,newix,pixelval; + + + if (ix>=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; + return ((t >> (pixelval*4)) & 0xf)^m; + else if(dr == 8) + //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; + return ((t >> (pixelval*8)) & 0xff)^m; + else if(dr == 16){ + //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; + return ((t >> (pixelval*16)) & 0xffff)^m; + }else{ + //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; + return ((t >> (pixelval*32)) & 0xffffffff)^m; + } + }; + /** Returns the value of the selected channel for the given dataset as double. @@ -238,6 +308,20 @@ class slsDetectorData { */ virtual double getValue(char *data, int ix, int iy=0) {return (double)getChannel(data, ix, iy);}; + /** + + Returns the value of the selected channel for the given dataset as double. + \param data pointer to the dataset (including headers etc) + \param ix pixel number in the x direction + \param iy pixel number in the y direction + \param dr dynamic range + \returns data for the selected channel, with inversion if required as double + + */ + virtual double getValue(char *data, int ix, int iy, int dr) { + return ((double)getChannel(data, ix, iy, dr)); + }; + /** Returns the frame number for the given dataset. Purely virtual func. diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index e07a757fd6..4781cb36ef 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -2,6 +2,7 @@ #define SLSRECEIVERDATA_H #include "slsDetectorData.h" +#include template class slsReceiverData : public slsDetectorData { @@ -89,7 +90,7 @@ class slsReceiverData : public slsDetectorData { dd+=packetSize; np++; // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; - if (np==nPackets) + if (np==nPackets){ if (pnum==nPackets) { // cout << "Frame found!" << endl; break; @@ -97,6 +98,7 @@ class slsReceiverData : public slsDetectorData { cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; retval=NULL; } + } } if (np0) From 48d672b918cd04af35535fc87c582c4ccec11d47 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 31 Mar 2015 15:07:53 +0200 Subject: [PATCH 066/104] Moved eiger related stuff from slsDetectorData to eigerHalfModule data, added xmap and ymap to slsDetectorData calss --- slsDetectorCalibration/eigerHalfModuleData.h | 57 ++++++++++++++++++ slsDetectorCalibration/slsDetectorData.h | 62 +++----------------- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 1c878af8cf..f81426bdec 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -81,6 +81,57 @@ class eigerHalfModuleData : public slsReceiverData { }; + /** + + Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded. + \param data pointer to the dataset (including headers etc) + \param ix pixel number in the x direction + \param iy pixel number in the y direction + \param dr dynamic range + \returns data for the selected channel, with inversion if required + + */ + virtual dataType getChannel(char *data, int ix, int iy=0, int dr=0) { + dataType m=0, d=0; + uint64_t t; + int numBytes,divFactor,newix,pixelval; + + + if (ix>=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; + return ((t >> (pixelval*4)) & 0xf)^m; + else if(dr == 8) + //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; + return ((t >> (pixelval*8)) & 0xff)^m; + else if(dr == 16){ + //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; + return ((t >> (pixelval*16)) & 0xffff)^m; + }else{ + //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; + return ((t >> (pixelval*32)) & 0xffffffff)^m; + } + }; + /** Returns the frame number for the given dataset. \param buff pointer to the dataset @@ -91,6 +142,12 @@ class eigerHalfModuleData : public slsReceiverData { }; + + + + + + /** gets the packets number (last packet is labelled with 0 and is replaced with 40) \param buff pointer to the memory \returns packet number diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 04ddc43d53..f5e42022c1 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -18,7 +18,8 @@ class slsDetectorData { int **dataMap; /**< Array of size nx*ny storing the pointers to the data in the dataset (as offset)*/ dataType **dataMask; /**< Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) */ int **dataROIMask; /**< Array of size nx*ny 1 if channel is good (or in the ROI), 0 if bad channel (or out of ROI) */ - + int *xmap; + int *ymap; public: @@ -55,7 +56,9 @@ class slsDetectorData { for (int j=0; j=0 && ix=0 && iy=0 && dataMap[iy][ix]=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; - return ((t >> (pixelval*4)) & 0xf)^m; - else if(dr == 8) - //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; - return ((t >> (pixelval*8)) & 0xff)^m; - else if(dr == 16){ - //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; - return ((t >> (pixelval*16)) & 0xffff)^m; - }else{ - //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; - return ((t >> (pixelval*32)) & 0xffffffff)^m; - } - }; - /** Returns the value of the selected channel for the given dataset as double. From 904462b582324458c751db0e5628d9261d957414 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Wed, 1 Apr 2015 13:04:27 +0200 Subject: [PATCH 067/104] xmap, ymap added again to slsDetectorData --- slsDetectorCalibration/slsDetectorData.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index f5e42022c1..643adad9a9 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -40,6 +40,8 @@ class slsDetectorData { slsDetectorData(int npx, int npy, int dsize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), dataSize(dsize) { + xmap=new int[nx*ny]; + ymap=new int[nx*ny]; dataMask=new dataType*[ny]; for(int i = 0; i < ny; i++) { @@ -56,8 +58,8 @@ class slsDetectorData { for (int j=0; j Date: Tue, 14 Apr 2015 17:13:09 +0200 Subject: [PATCH 068/104] eiger mapping for 32 bit done --- slsDetectorCalibration/eigerHalfModuleData.h | 112 ++++++++++++++----- slsDetectorCalibration/slsDetectorData.h | 10 +- slsDetectorCalibration/slsReceiverData.h | 2 +- 3 files changed, 87 insertions(+), 37 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 1c878af8cf..553e9dbd37 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -19,8 +19,8 @@ class eigerHalfModuleData : public slsReceiverData { */ - eigerHalfModuleData(int dr, int np, int bsize, int dsize, double c=0): slsReceiverData(xpixels, ypixels, np, bsize), - xtalk(c), dynamicRange(dr), bufferSize(bsize), dataSize(dsize){ + eigerHalfModuleData(int dr, int np, int bsize, int dsize, bool top, double c=0): slsReceiverData(xpixels, ypixels, np, bsize), + xtalk(c), bufferSize(bsize), dataSize(dsize), dynamicRange(dr), numberOfPackets(np){ int **dMap; @@ -42,29 +42,60 @@ class eigerHalfModuleData : public slsReceiverData { int iData1 = 0, iData2 = 0; int iPort; - for (int ir=0; ir= dataSize){ - iPacket1 += 16; - iData1 = 0; - } - }else{ - dMap[ir][ic] = iPacket2; - iPacket2 += (dynamicRange / 8); - iData2 +=(dynamicRange / 8); - if(iData2 >= dataSize){ - iPacket2 += 16; - iData2 = 0; + + if(top){ + for (int ir=0; ir= dataSize){ + iPacket1 += 16; + iData1 = 0; + } + }else{ + dMap[ir][ic] = iPacket2; + iPacket2 += (dynamicRange / 8); + iData2 +=(dynamicRange / 8); + if(iData2 >= dataSize){ + iPacket2 += 16; + iData2 = 0; + } } } } } +/* + else{ + iPacket1 = (totalNumberOfBytes/2) - 1040 - 8; + iPacket2 = totalNumberOfBytes - 1040 - 8; + for (int ir=0; ir= dataSize){ + iPacket1 += 16; + iData1 = 0; + } + }else{ + dMap[ir][ic] = iPacket2; + iPacket2 += (dynamicRange / 8); + iData2 +=(dynamicRange / 8); + if(iData2 >= dataSize){ + iPacket2 += 16; + iData2 = 0; + } + } + } + } + } +*/ @@ -87,7 +118,7 @@ class eigerHalfModuleData : public slsReceiverData { \returns frame number */ int getFrameNumber(char *buff){ - return htonl(*(unsigned int*)((eiger_image_header *)((char*)(buff)))->fnum); + return(*(unsigned int*)(((eiger_packet_header *)((char*)buff))->num1)); }; @@ -96,7 +127,31 @@ class eigerHalfModuleData : public slsReceiverData { \returns packet number */ int getPacketNumber(char *buff){ - return htonl(*(unsigned int*)((eiger_packet_header *)((char*)(buff)))->num2); + /*other way roud if its a bottom*/ + +#ifdef VERY_DEBUG + cprintf(RED, "\n0x%x - %d - %d", + (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(buff)))->num2))); +#endif + //32 bit packet number written in num2 + if(dynamicRange == 32){ + //both ports have same packet numbers, so reconstruct + if((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3))){ + return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+(numberOfPackets/2) +1); + }else{ + return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+1); + } + } + else{ + //both ports have same packet numbers, so reconstruct + if((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3))){ + return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+(numberOfPackets/2) +1); + }else{ + return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+1); + } + } }; @@ -146,21 +201,16 @@ class eigerHalfModuleData : public slsReceiverData { const int bufferSize; const int dataSize; const int dynamicRange; + const int numberOfPackets; - /** structure of an eiger image header*/ - typedef struct - { - unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; - } eiger_image_header; - /** structure of an eiger image header*/ typedef struct { unsigned char num1[4]; - unsigned char num2[4]; + unsigned char num2[2]; + unsigned char num3[1]; + unsigned char num4[1]; } eiger_packet_header; }; diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 04ddc43d53..cb364bc047 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -211,14 +211,14 @@ class slsDetectorData { */ virtual dataType getChannel(char *data, int ix, int iy, int dr) { - dataType m=0, d=0; + dataType m=0; uint64_t t; int numBytes,divFactor,newix,pixelval; if (ix>=0 && ix=0 && iy=0 && dataMap[iy][ix] { while (dd<=(dsize-packetSize)) { pnum=getPacketNumber(p); fn=getFrameNumber(p); - + //cout <<"pnum:"<nPackets) { cout << "Bad packet number " << pnum << " frame "<< fn << endl; From 5731ead4cba1d4ce9a11e9b03bfb9d23c823eff2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 15 Apr 2015 14:38:32 +0200 Subject: [PATCH 069/104] eiger top mapping done. bottom doesnt work --- slsDetectorCalibration/eigerHalfModuleData.h | 63 +++++++++++++++----- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 553e9dbd37..34ee0f7de6 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -20,7 +20,7 @@ class eigerHalfModuleData : public slsReceiverData { eigerHalfModuleData(int dr, int np, int bsize, int dsize, bool top, double c=0): slsReceiverData(xpixels, ypixels, np, bsize), - xtalk(c), bufferSize(bsize), dataSize(dsize), dynamicRange(dr), numberOfPackets(np){ + xtalk(c), bufferSize(bsize), dataSize(dsize), dynamicRange(dr), numberOfPackets(np), top(top){ int **dMap; @@ -40,6 +40,7 @@ class eigerHalfModuleData : public slsReceiverData { int iPacket1 = 8; int iPacket2 = (totalNumberOfBytes/2) + 8; int iData1 = 0, iData2 = 0; + /*int iData=0*/ int iPort; @@ -51,6 +52,7 @@ class eigerHalfModuleData : public slsReceiverData { dMap[ir][ic] = iPacket1; iPacket1 += (dynamicRange / 8); iData1 +=(dynamicRange / 8); + //increment header if(iData1 >= dataSize){ iPacket1 += 16; iData1 = 0; @@ -59,28 +61,38 @@ class eigerHalfModuleData : public slsReceiverData { dMap[ir][ic] = iPacket2; iPacket2 += (dynamicRange / 8); iData2 +=(dynamicRange / 8); + //increment header if(iData2 >= dataSize){ iPacket2 += 16; iData2 = 0; } } + /*iData +=(dynamicRange / 8); + //increment header + if(iData1 >= dataSize){ + iPacket1 += 16; + iData1 = 0; + }*/ } } } -/* + else{ - iPacket1 = (totalNumberOfBytes/2) - 1040 - 8; - iPacket2 = totalNumberOfBytes - 1040 - 8; + /*int iData=0;*/ + iData1 = 0; iData2 = 0; + iPacket1 = (totalNumberOfBytes/2) - bufferSize - 8; + iPacket2 = totalNumberOfBytes - bufferSize - 8; for (int ir=0; ir= dataSize){ - iPacket1 += 16; + iPacket1 -= (dataSize*2); + iPacket1 -= 16; iData1 = 0; } }else{ @@ -88,14 +100,24 @@ class eigerHalfModuleData : public slsReceiverData { iPacket2 += (dynamicRange / 8); iData2 +=(dynamicRange / 8); if(iData2 >= dataSize){ - iPacket2 += 16; + iPacket2 -= (dataSize*2); + iPacket2 -= 16; iData2 = 0; } } + /*iData +=(dynamicRange / 8); + //increment header + if(iData >= dataSize){ + iPacket1 -= (bufferSize*2); + iPacket2 -= (bufferSize*2); + iPacket1 += 16; + iPacket2 += 16; + iData = 0; + }*/ } } } -*/ + @@ -127,8 +149,6 @@ class eigerHalfModuleData : public slsReceiverData { \returns packet number */ int getPacketNumber(char *buff){ - /*other way roud if its a bottom*/ - #ifdef VERY_DEBUG cprintf(RED, "\n0x%x - %d - %d", (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num3)), @@ -137,19 +157,31 @@ class eigerHalfModuleData : public slsReceiverData { #endif //32 bit packet number written in num2 if(dynamicRange == 32){ - //both ports have same packet numbers, so reconstruct + //both ports have same packet numbers, so reconstruct, ports interchanged for bottom if((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3))){ - return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+(numberOfPackets/2) +1); + if (top) + return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+(numberOfPackets/2) +1); + else + return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+1); }else{ - return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+1); + if (top) + return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+1); + else + return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+(numberOfPackets/2) +1); } } else{ //both ports have same packet numbers, so reconstruct if((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3))){ - return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+(numberOfPackets/2) +1); + if (top) + return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+(numberOfPackets/2) +1); + else + return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+1); }else{ - return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+1); + if (top) + return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+1); + else + return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+(numberOfPackets/2) +1); } } }; @@ -202,6 +234,7 @@ class eigerHalfModuleData : public slsReceiverData { const int dataSize; const int dynamicRange; const int numberOfPackets; + bool top; /** structure of an eiger image header*/ From 83a766914f62124f52f7c1c8540e11f0824677b2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 15 Apr 2015 14:48:27 +0200 Subject: [PATCH 070/104] not necessary merge --- slsDetectorCalibration/slsDetectorData.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 0316b8ec60..d5f5675959 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -211,8 +211,6 @@ class slsDetectorData { /** - -<<<<<<< HEAD Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded. \param data pointer to the dataset (including headers etc) \param ix pixel number in the x direction @@ -263,9 +261,6 @@ class slsDetectorData { }; /** - -======= ->>>>>>> b3dac953736499019603c2201df6e7eb45cc890c Returns the value of the selected channel for the given dataset as double. \param data pointer to the dataset (including headers etc) \param ix pixel number in the x direction From 0c2bd83e968ea7b161629b8f3d524c399a12287e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 15 Apr 2015 15:49:52 +0200 Subject: [PATCH 071/104] moved getchannel back to slsdetectordata as it doesnt work for eiger --- slsDetectorCalibration/eigerHalfModuleData.h | 53 ++------------------ slsDetectorCalibration/slsDetectorData.h | 18 ++++--- 2 files changed, 14 insertions(+), 57 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 74e81d7b97..f6b301d82b 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -134,56 +134,9 @@ class eigerHalfModuleData : public slsReceiverData { }; - /** - - Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded. - \param data pointer to the dataset (including headers etc) - \param ix pixel number in the x direction - \param iy pixel number in the y direction - \param dr dynamic range - \returns data for the selected channel, with inversion if required - - */ - virtual dataType getChannel(char *data, int ix, int iy=0, int dr=0) { - dataType m=0, d=0; - uint64_t t; - int numBytes,divFactor,newix,pixelval; - - - if (ix>=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; - return ((t >> (pixelval*4)) & 0xf)^m; - else if(dr == 8) - //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; - return ((t >> (pixelval*8)) & 0xff)^m; - else if(dr == 16){ - //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; - return ((t >> (pixelval*16)) & 0xffff)^m; - }else{ - //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; - return ((t >> (pixelval*32)) & 0xffffffff)^m; - } - }; + + + /** Returns the frame number for the given dataset. diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index d5f5675959..c9637aa5aa 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -105,9 +105,9 @@ class slsDetectorData { for (int ix=0; ix=0 && ix=0 && iy=0 && dataMap[iy][ix]=0 && ix=0 && iy=0 && dataMap[iy][ix] Date: Tue, 19 May 2015 10:12:57 +0200 Subject: [PATCH 072/104] mapping of bottom and top for all bit modes work --- slsDetectorCalibration/eigerHalfModuleData.h | 104 ++++++++++++------- slsDetectorCalibration/slsDetectorData.h | 2 +- 2 files changed, 67 insertions(+), 39 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index f6b301d82b..381456a540 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -40,18 +40,23 @@ class eigerHalfModuleData : public slsReceiverData { int iPacket1 = 8; int iPacket2 = (totalNumberOfBytes/2) + 8; int iData1 = 0, iData2 = 0; - /*int iData=0*/ + int increment = (dynamicRange/8); + int ic_increment = 1; + if (dynamicRange == 4) { + increment = 1; + ic_increment = 2; + } int iPort; if(top){ for (int ir=0; ir= dataSize){ iPacket1 += 16; @@ -59,61 +64,84 @@ class eigerHalfModuleData : public slsReceiverData { } }else{ dMap[ir][ic] = iPacket2; - iPacket2 += (dynamicRange / 8); - iData2 +=(dynamicRange / 8); + iPacket2 += increment; + iData2 += increment; //increment header if(iData2 >= dataSize){ iPacket2 += 16; iData2 = 0; } } - /*iData +=(dynamicRange / 8); - //increment header - if(iData1 >= dataSize){ - iPacket1 += 16; - iData1 = 0; - }*/ } } } + //bottom else{ - /*int iData=0;*/ iData1 = 0; iData2 = 0; - iPacket1 = (totalNumberOfBytes/2) - bufferSize - 8; - iPacket2 = totalNumberOfBytes - bufferSize - 8; + int numbytesperlineperport = 1024; + if (dynamicRange == 8) + numbytesperlineperport = 512; + else if (dynamicRange == 4) + numbytesperlineperport = 256; + else if (dynamicRange == 32) + numbytesperlineperport = 2048; + + + + iPacket1 = (totalNumberOfBytes/2) - numbytesperlineperport - 8; + iPacket2 = totalNumberOfBytes - numbytesperlineperport - 8; + if (dynamicRange == 32){ + iPacket1 -= 16; + iPacket2 -= 16; + } + for (int ir=0; ir= dataSize){ - iPacket1 -= (dataSize*2); - iPacket1 -= 16; - iData1 = 0; + iPacket1 += increment; + iData1 += increment; + if(dynamicRange == 32){ + if(iData1 == numbytesperlineperport){ + iPacket1 -= (numbytesperlineperport*2 + 16*3); + iData1 = 0; + } + if(iData1 == dataSize){ + iPacket1 += 16; + } + }else if((iData1 % numbytesperlineperport) == 0){ + iPacket1 -= (numbytesperlineperport*2); + if(iData1 == dataSize){ + iPacket1 -= 16; + iData1 = 0; + } + } - }else{ + } + //other port + else{ dMap[ir][ic] = iPacket2; - iPacket2 += (dynamicRange / 8); - iData2 +=(dynamicRange / 8); - if(iData2 >= dataSize){ - iPacket2 -= (dataSize*2); - iPacket2 -= 16; - iData2 = 0; + iPacket2 += increment; + iData2 += increment; + if(dynamicRange == 32){ + if(iData2 == numbytesperlineperport){ + iPacket2 -= (numbytesperlineperport*2 + 16*3); + iData2 = 0; + } + if(iData2 == dataSize){ + iPacket2 += 16; + } + }else if((iData2 % numbytesperlineperport) == 0){ + iPacket2 -= (numbytesperlineperport*2); + if(iData2 == dataSize){ + iPacket2 -= 16; + iData2 = 0; + } } } - /*iData +=(dynamicRange / 8); - //increment header - if(iData >= dataSize){ - iPacket1 -= (bufferSize*2); - iPacket2 -= (bufferSize*2); - iPacket1 += 16; - iPacket2 += 16; - iData = 0; - }*/ } } } diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index c9637aa5aa..b130b7aa2d 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -228,7 +228,7 @@ class slsDetectorData { uint64_t t; int numBytes,divFactor,newix,pixelval; - +//cout <<"ix:"<=0 && ix=0 && iy=0 && dataMap[iy][ix] Date: Thu, 28 May 2015 14:28:17 +0200 Subject: [PATCH 073/104] main in moenchReadDataMT [multi threading] --- slsDetectorCalibration/moenchReadData.C | 5 ++-- slsDetectorCalibration/moenchReadDataMT.C | 36 +++++++++++++++++++++-- slsDetectorCalibration/slsDetectorData.h | 2 +- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index bf7173f0bb..965b2e88cc 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -16,6 +16,7 @@ #include #include "moench02ModuleData.h" #include "moenchCommonMode.h" +#define MYROOT1 #include "singlePhotonDetector.h" //#include "MovingStat.h" @@ -26,7 +27,7 @@ using namespace std; #define NR 160 -#define MY_DEBUG 1 +//#define MY_DEBUG 1 #ifdef MY_DEBUG #include #endif @@ -215,7 +216,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb #endif nf++; - cout << "=" ; + cout << "=" << decoder->getFrameNumber(buff); delete [] buff; } cout << nph << endl; diff --git a/slsDetectorCalibration/moenchReadDataMT.C b/slsDetectorCalibration/moenchReadDataMT.C index 0720909c4e..ecb5787720 100644 --- a/slsDetectorCalibration/moenchReadDataMT.C +++ b/slsDetectorCalibration/moenchReadDataMT.C @@ -1,5 +1,6 @@ #include #include +#include #include "moenchReadData.C" typedef struct task_s{ @@ -9,6 +10,7 @@ typedef struct task_s{ int runmin; int runmax; int treeIndex; + double xTalk; } Task; void *moenchMakeTreeTask(void *p){ @@ -19,13 +21,16 @@ void *moenchMakeTreeTask(void *p){ TFile *f = new TFile(fname,"RECREATE"); cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<")" << endl; TThread::UnLock(); - moenchReadData(t->fformat,t->tname,t->runmin,t->runmax); - f->Close(); + THStack *s = moenchReadData(t->fformat,t->tname,t->runmin,t->runmax, 1500, -500, 1000, 1, t->xTalk); + s->Write(); + if(f && f->IsOpen()){ + f->Close(); + } return 0; } -void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0){ +void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0, double xTalk=0.044){ char threadName[1000]; TThread *threads[nThreads]; for(int i = 0; i < nThreads; i++){ @@ -37,6 +42,7 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo t->runmin = runmin + i*runoffset; t->runmax = runmin + (i+1)*runoffset - 1; t->treeIndex = treeIndexStart + i; + t->xTalk = xTalk; cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; threads[i] = new TThread(threadName, moenchMakeTreeTask, t); threads[i]->Run(); @@ -50,3 +56,27 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo + +//to compile: g++ -DMYROOT -DMYROOT1 -g `root-config --cflags --glibs` -o moenchReadDataMT moenchReadDataMT.C +int main(int argc, char **argv){ + if(argc < 8){ + cout << "Usage: " << argv[0] << " fformat tit tdir runmin runoffset nThreads treeIndexStart [xTalkFactor]" << endl; + exit(-1); + } + + char *fformat = argv[1]; + char *tit = argv[2]; + char *tdir = argv[3]; + int runmin = atoi(argv[4]); + int runoffset = atoi(argv[5]); + int nThreads = atoi(argv[6]); + int treeIndexStart = atoi(argv[7]); + double xTalkFactor = 0.044; + + if(argc == 9) + xTalkFactor = atof(argv[8]); + + moenchReadDataMT(fformat, tit, tdir,runmin,runoffset,nThreads,treeIndexStart, xTalkFactor); + +} + diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 8240a74845..01f00a3167 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -96,7 +96,7 @@ class slsDetectorData { for (int iy=0; iy Date: Thu, 28 May 2015 14:46:46 +0200 Subject: [PATCH 074/104] fixed merge --- slsDetectorCalibration/moenchReadData.C | 7 ++++--- slsDetectorCalibration/slsDetectorData.h | 18 +----------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/slsDetectorCalibration/moenchReadData.C b/slsDetectorCalibration/moenchReadData.C index 965b2e88cc..632f743c3c 100644 --- a/slsDetectorCalibration/moenchReadData.C +++ b/slsDetectorCalibration/moenchReadData.C @@ -16,7 +16,7 @@ #include #include "moench02ModuleData.h" #include "moenchCommonMode.h" -#define MYROOT1 + #include "singlePhotonDetector.h" //#include "MovingStat.h" @@ -27,7 +27,8 @@ using namespace std; #define NR 160 -//#define MY_DEBUG 1 +#define MY_DEBUG 1 + #ifdef MY_DEBUG #include #endif @@ -216,7 +217,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb #endif nf++; - cout << "=" << decoder->getFrameNumber(buff); + cout << "=" ; delete [] buff; } cout << nph << endl; diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 932fd589e2..3da6a04078 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -92,23 +92,7 @@ class slsDetectorData { void setDataMap(int **dMap=NULL) { -<<<<<<< HEAD - - if (dMap==NULL) { - for (int iy=0; iy>>>>>> 844c207d55aa5279626c496c677446de61103a30 + }; From a4de9a914a852f1ea8304e8c824b743824fc94fb Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 11 Jun 2015 11:38:10 +0200 Subject: [PATCH 075/104] added a function to give frame number while reading next frame --- slsDetectorCalibration/eigerHalfModuleData.h | 2 +- slsDetectorCalibration/slsReceiverData.h | 55 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 381456a540..3b698c966b 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -172,7 +172,7 @@ class eigerHalfModuleData : public slsReceiverData { \returns frame number */ int getFrameNumber(char *buff){ - return(*(unsigned int*)(((eiger_packet_header *)((char*)buff))->num1)); + return(*(unsigned int*)(((eiger_packet_header *)((char*)buff))->num1)); }; diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index 15d324ef62..505d9264a8 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -162,6 +162,61 @@ class slsReceiverData : public slsDetectorData { }; + /** + + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \param fnum frame number of frame returned + \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete + + */ + + virtual char *readNextFrame(ifstream &filebin, int& fnum) { + char *data=new char[packetSize*nPackets]; + char *retval=0; + int np=0, nd; + fnum = -1; + + if (filebin.is_open()) { + while (filebin.read(data+np*packetSize,packetSize)) { + + if (np==(nPackets-1)) { + + fnum=getFrameNumber(data); cout << "fnum:"<nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else if (retval!=NULL) { + // cout << "+" << endl;; + for (int ip=0; ipnPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + // cout << "." << endl;; + np++; + } + } + } + delete [] data; + return NULL; + }; + + private: const int nPackets; /** Date: Thu, 11 Jun 2015 13:33:18 +0200 Subject: [PATCH 076/104] 32 bit mode image reconstuction should work for frame numbers as well --- slsDetectorCalibration/slsReceiverData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index 505d9264a8..bfe7a88c51 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -182,7 +182,7 @@ class slsReceiverData : public slsDetectorData { if (np==(nPackets-1)) { - fnum=getFrameNumber(data); cout << "fnum:"< Date: Wed, 17 Jun 2015 17:30:41 +0200 Subject: [PATCH 077/104] fix a typo and makefile --- slsDetectorCalibration/energyCalibration.cpp | 2 +- slsDetectorCalibration/makefile | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 slsDetectorCalibration/makefile diff --git a/slsDetectorCalibration/energyCalibration.cpp b/slsDetectorCalibration/energyCalibration.cpp index 6911220955..a4c78ffcfa 100644 --- a/slsDetectorCalibration/energyCalibration.cpp +++ b/slsDetectorCalibration/energyCalibration.cpp @@ -524,4 +524,4 @@ TGraphErrors* energyCalibration::calibrate(int nscan, Double_t *en, Double_t *ee -Fit data is empty + diff --git a/slsDetectorCalibration/makefile b/slsDetectorCalibration/makefile new file mode 100644 index 0000000000..daed15c566 --- /dev/null +++ b/slsDetectorCalibration/makefile @@ -0,0 +1,8 @@ +CC=gcc +CFLAGS= -g -c -W -lstdc++ + +ROOTINCLUDE=$(ROOTSYS)/include + +energyCalibration.o: energyCalibration.cpp + $(CC) $(CFLAGS) energyCalibration.cpp -I $(ROOTINCLUDE) + From 23a21b373eb912c9e09f75f06c6994ce3bcb2846 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Thu, 18 Jun 2015 14:16:43 +0200 Subject: [PATCH 078/104] modified readMoench03 by Marco --- slsDetectorCalibration/moench03ReadData.C | 916 ++++++++++++++++++++-- slsDetectorCalibration/readMoench03Data.C | 245 +++++- 2 files changed, 1065 insertions(+), 96 deletions(-) diff --git a/slsDetectorCalibration/moench03ReadData.C b/slsDetectorCalibration/moench03ReadData.C index c54a7655e9..0235231c2b 100644 --- a/slsDetectorCalibration/moench03ReadData.C +++ b/slsDetectorCalibration/moench03ReadData.C @@ -9,11 +9,14 @@ #include #include #include +#include #include //#include //#include //#include +#include #include +#include #include "moench03CtbData.h" #include "moench03CommonMode.h" #define MYROOT1 @@ -27,7 +30,7 @@ using namespace std; #define NR 400 -//#define MY_DEBUG 1 +#define MY_DEBUG 1 #ifdef MY_DEBUG #include @@ -47,7 +50,7 @@ TH2F *readImage(ifstream &filebin, TH2F *h2=NULL, TH2F *hped=NULL) { h2=new TH2F("h2","",400,0,400,400,0,400); h2->SetStats(kFALSE); } - // cout << "." << endl; + cout << "." << endl; for (int ix=0; ix<400; ix++) { for (int iy=0; iy<400; iy++) { // cout << decoder->getDataSize() << " " << decoder->getValue(buff,ix,iy)<< endl; @@ -77,7 +80,7 @@ TH2F *readImage(char *fname, int iframe=0, TH2F *hped=NULL) { if (hh==NULL) break; hh=readImage(filebin, h2, hped ); if (hh) - ;// cout << "="<< endl; + cout << "="<< endl; else { delete h2; return NULL; @@ -114,7 +117,7 @@ TH2F *calcPedestal(char *fformat, int runmin, int runmax){ } } delete [] buff; - //cout << "="<< endl; + cout << "="<< endl; ii++; } if (filebin.is_open()) @@ -134,7 +137,400 @@ TH2F *calcPedestal(char *fformat, int runmin, int runmax){ return h2; } +/******************************************************************************/ +TH2F * calcNoiseRMS(char *fformat, int runmin, int runmax){ + ifstream filebin; + char fname[10000]; + moench03CtbData *decoder=new moench03CtbData(); + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, 1, NULL); + char *buff; + int ix,iy; + int ii=0; + TH2F* h2=NULL; + + for (int irun=runmin; irun<=runmax; irun++) { + sprintf(fname,fformat,irun); + + + filebin.open((const char *)(fname), ios::in | ios::binary); + while ((buff=decoder->readNextFrame(filebin))) { + for (ix=0; ix<400; ix++) { + for (iy=0; iy<400; iy++) { + filter->addToPedestal(decoder->getValue(buff,ix,iy), ix, iy); + } + } + delete [] buff; + cout << "="<< endl; + ii++; + } + if (filebin.is_open()) + filebin.close(); + + } + if (ii>0) { + h2=new TH2F("hped","",400,0,400,400,0,400); + + for (ix=0; ix<400; ix++) { + for (iy=0; iy<400; iy++) { + h2->SetBinContent(ix+1, iy+1,filter->getPedestalRMS(ix,iy)); + } + } + + } + return h2; + +} + +/**********************************************************************************/ +THStack * calcNoise(char *fformat,std::string flag, int runmin, int runmax, int nfiles){ + std::map pixelMap; + cerr<<"Creating pedestal map for frames: "< *filter=new singlePhotonDetector(decoder, 3, 5, 1, NULL); + char *buff; + int ix,iy; + int ii=0; + TH2F* hped=NULL; + TH2F* hnoise=NULL; + int ibin(0); + int iframe(0); + Float_t sigma(0.); + int filefound(0); + pixelMap.clear(); + for (int irun=runmin; irun<=runmax; irun++) { + sprintf(fname,fformat,irun); + if( access(fname,F_OK) != -1){ + if(filefoundreadNextFrame(filebin))) { + iframe=decoder->getFrameNumber(buff); + if(iframe%n==r){ + for (ix=0; ix<400; ix++) { + for (iy=0; iy<400; iy++) { + ibin = ix*NR+iy; + if(pixelMap.find(ibin)!=pixelMap.end()){ + pixelMap[ibin]->Fill(decoder->getValue(buff,ix,iy)); + }else{ + pixelMap[ibin] = new TH1F(Form("h_%d",ibin),Form("h_%d",ibin),8000,-0.5,15999.5); + } + } + } + } + delete [] buff; + if(ii%1000==0)cout << "="<0){ + + hped=new TH2F("hped","",400,-0.5,399.5,400,-0.5,399.5); + hnoise=new TH2F("hnoise","",400,-0.5,399.5,400,-0.5,399.5); + hs->Add(hped); + hs->Add(hnoise); + Float_t p(0.); + Float_t perr(0.); + Float_t amp(0.); + Float_t sigmaerr(0.); + for(ix=0; ix<400; ix++){ + for (iy=0; iy<400; iy++){ + sigma=0.; + sigmaerr=0.; + p=0.; + perr=0.; + ibin = ix*NR+iy; + if(ibin%1000==0)cerr<GetBinCenter(pixelMap[ibin]->GetMaximumBin()); + // cerr<<"peak: "<GetBinContent(pixelMap[ibin]->GetMaximumBin()); + sigma=pixelMap[ibin]->GetRMS(); + + TF1 * g = new TF1("g","gaus(0)",p-sigma,p+sigma); + g->SetParameters(amp,p,sigma); + g->SetParLimits(1,p-sigma,p+sigma); + g->SetParLimits(2,0.1*sigma,2.*sigma); + + pixelMap[ibin]->Fit(g,"RQN0"); + p=g->GetParameter(1); + perr=g->GetParError(1); + sigma=g->GetParameter(2); + sigmaerr=g->GetParError(2); + // cerr<<"sigma: "<SetBinContent(ix+1,iy+1,p); + hped->SetBinError(ix+1,iy+1,perr); + hnoise->SetBinContent(ix+1,iy+1,sigma); + hnoise->SetBinError(ix+1,iy+1,sigmaerr); + + } + } + + } + + return hs; + +} +/****************************************************/ +THStack * DrawFrames(char *fformat,int framemin, int framemax){ + + int nbins(400); + int xmin(0); + int xmax(400); + + THStack * hs = new THStack(); + ifstream filebin; + char fname[10000]; + moench03CtbData *decoder=new moench03CtbData(); + char *buff; + int ix,iy; + int iframe(0); + if(access(fformat,F_OK) != -1){ + filebin.open((const char *)(fformat), ios::in | ios::binary); + while ((buff=decoder->readNextFrame(filebin))) { + iframe=decoder->getFrameNumber(buff); + if(iframe>=framemin && iframeSetBinContent(ix+1,iy+1,decoder->getValue(buff,ix,iy)); + } + }//end loop on pixels + hs->Add(h); + }//end check on frames + delete [] buff; + } + }else{//check if file exists + cerr<readNextFrame(filebin))){ + iframe=decoder->getFrameNumber(buff); + if(iframe%1000==0) cerr<Fill(decoder->getValue(buff,x0,y0)); + delete [] buff; + + }//end readout of frame + }else{//end check on file + cerr< *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 1000, 100); + char *buff; + char fname[10000]; + + float pix1(0.); + float pix2(0.); + ifstream filebin; + int iframe(0); + + for (int irun=runmin; irun<=runmax; irun++){//loop on files + sprintf(fname,fformat,irun); + iframe=0; + pix1=0.; + pix2=0.; + if( access(fname,F_OK) != -1){//check if file exists + filebin.open((const char *)(fname), ios::in | ios::binary); + while ((buff=decoder->readNextFrame(filebin))){//loop on frames + iframe=decoder->getFrameNumber(buff); + if(iframe%n==r){//check if frame is even or odd + for(int ix=xmin; ixgetValue(buff,ix,iy); + pix2=decoder->getValue(buff,ix+1,iy); + + hcorr->Fill(pix1,pix2); + }//end check on s_c edge + + } + }//end loop on pixels + }//edn check on frame number + delete [] buff; + + }//end loop on frames + + }else{//end check if file exists + cerr< *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 1000, 100); + char *buff; + char fname[10000]; + + float pix1(0.); + float pix2(0.); + ifstream filebin; + int ii=0; + int iframe(0); + + for (int irun=runmin; irun<=runmax; irun++){//loop on files + sprintf(fname,fformat,irun); + pix1=0.; + pix2=0.; + iframe=0; + if( access(fname,F_OK) != -1){//check if file exists + + filebin.open((const char *)(fname), ios::in | ios::binary); + while ((buff=decoder->readNextFrame(filebin))){//loop on frames + iframe=decoder->getFrameNumber(buff); + if(iframe%n==r){ + + + pix1=decoder->getValue(buff,px,py); + pix2=decoder->getValue(buff,px+1,py); + + h1->Fill(pix1); + h2->Fill(pix2); + hcorr->Fill(pix1,pix2); + delete [] buff; + + } + if(ii%1000==0)cerr<<"reading frame "< *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 100, 10); + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 1000, 100); cout << "filter allocated " << endl; char *buff; @@ -197,13 +595,235 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int hs->Add(h1); cout << "h1 allocated " << endl; - TH2F *h2; - TH2F *h3; + // TH2F *h2=NULL; + // TH2F *h3=NULL; + if (hitfinder) { + // h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + // cout << "h2 allocated " << endl; + // h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + // cout << "h3 allocated " << endl; + // // hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + // // hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + // hs->Add(h2); + // hs->Add(h3); + // hs->Add(hetaX); + // hs->Add(hetaY); + } + if (hs->GetHists()) { + for (int i=0; i<1; i++) + if (hs->GetHists()->At(i)) cout << i << " " ; + cout << " histos allocated " << endl; + } else + cout << "no hists in stack " << endl; + + + + + + int ix=20, iy=20, ir, ic; + int adc(0); + + ifstream filebin; + Int_t iFrame; + TTree *tall; + + if (hitfinder){ + tall=filter->initEventTree(tit, &iFrame); + + } + + +#ifdef MY_DEBUG + + cout << "debug mode " << endl; + + TCanvas *myC; + TH2F *he; + TCanvas *cH1; + // TCanvas *cH2; + // TCanvas *cH3; + cH1=new TCanvas("ch1"); + cH1->SetLogz(); + h1->Draw("colz"); + if (hitfinder) { + myC=new TCanvas("myc"); + he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); + he->SetStats(kFALSE); + he->Draw("colz"); + + // cH2=new TCanvas("ch2"); + // cH2->SetLogz(); + // h2->Draw("colz"); + // cH3=new TCanvas("ch3"); + // cH3->SetLogz(); + // h3->Draw("colz"); + } +#endif + + filter->newDataSet(); + + + for (int irun=runmin; irunreadNextFrame(filebin))) {//getting frames on the buffer + + + if (hitfinder) { + filter->newFrame(); + + //calculate pedestals and common modes + if (cmsub) { + // cout << "cm" << endl; + for (ix=xmin; ixgetEventType(buff, ix, iy,0); + }//loop on pixels + }//end if cmsub + }//end if hitfinder + + // cout << "new frame " << endl; + + for (ix=xmin; ixgetEventType(buff, ix, iy, cmsub); + iFrame=decoder->getFrameNumber(buff); + +#ifdef MY_DEBUG + if (hitfinder) { + // if (iev%10==0) + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); + } +#endif + + // if (nf>10) { + h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + if (hitfinder) { + + if (thisEvent==PHOTON_MAX ) { + nph++; + + // h2->Fill(filter->getClusterTotal(2), iy+NR*ix); + // h3->Fill(filter->getClusterTotal(3), iy+NR*ix); + + tall->Fill(); + }//end if PHOTON_MAX + }//end if hitfinder + }//end loop on pixels + ////////////////////////////////////////////////////////// + +#ifdef MY_DEBUG + // cout << iev << " " << h1->GetEntries() << " " << h2->GetEntries() << endl; + // if (iev%10==0) { + // myC->Modified(); + // myC->Update(); + // cH1->Modified(); + // cH1->Update(); + // cH2->Modified(); + // cH2->Update(); + // cH3->Modified(); + // cH3->Update(); + // } + iev++; +#endif + nf++; + + cout << "=" ; + delete [] buff; + }//end frame + cout << nph <<" Photons found"<< endl; + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + }else{ + cerr<<"File does not exist"<Write(tall->GetName(),TObject::kOverwrite); + } + ////////////////////////////////////////////////////////// + +#ifdef MY_DEBUG + if(hitfinder){ + myC->Modified(); + myC->Update(); + } + cH1->Modified(); + cH1->Update(); + // cH2->Modified(); + // cH2->Update(); + // cH3->Modified(); + // cH3->Update(); +#endif + + delete decoder; + cout << "Read " << nf << " frames" << endl; + return hs; +} +/*********************************************************************************************/ +THStack *moench03ReadDataEvenOdd(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1){ + + double hc(0); + int sign(1); + moench03CtbData *decoder=new moench03CtbData(); + cout << "decoder allocated " << endl; + + moench03CommonMode *cmSub=NULL; + if (cmsub) { + cmSub=new moench03CommonMode(100); + cout << "common mode allocated " << endl; + + } else { + + cout << "non allocating common mode " << endl; + } + int iev=0; + int nph=0; + + singlePhotonDetector *filterEven=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 1000, 100); + cout << "filter for even frames allocated " << endl; + singlePhotonDetector *filterOdd=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 1000, 100); + cout << "filter for odd frames allocated " << endl; + + char *buff; + char fname[10000]; + int nf=0; + + eventType thisEvent=PEDESTAL; + + // int iframe; + // double *data, ped, sigma; + + // data=decoder->getCluster(); + + + THStack *hs=new THStack("hs",fformat); + + cout << "hstack allocated " << endl; + + + TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h1); + cout << "h1 allocated " << endl; + + TH2F *h2=NULL; + TH2F *h3=NULL; if (hitfinder) { h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - cout << "h2 allocated " << endl; + cout << "h2 allocated " << endl; h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - cout << "h3 allocated " << endl; + cout << "h3 allocated " << endl; // hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); hs->Add(h2); @@ -211,9 +831,12 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int // hs->Add(hetaX); // hs->Add(hetaY); } + + + if (hs->GetHists()) { for (int i=0; i<3; i++) - if (hs->GetHists()->At(1)) cout << i << " " ; + if (hs->GetHists()->At(i)) cout << i << " " ; cout << " histos allocated " << endl; } else cout << "no hists in stack " << endl; @@ -223,14 +846,18 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int int ix=20, iy=20, ir, ic; + Int_t iFrame; - TTree *tall; - if (hitfinder) - tall=filter->initEventTree(tit, &iFrame); - - + TTree *tEven; + TTree *tOdd; + if (hitfinder){ + tEven=filterEven->initEventTree(Form("%s_Even",tit), &iFrame); + cout<< "TTree for even frames initialized"<initEventTree(Form("%s_Odd",tit), &iFrame); + cout<< "TTree for odd frames initialized"<SetLogz(); h3->Draw("colz"); + + cout<<"Canvas allocated"<newDataSet(); + filterEven->newDataSet(); + filterOdd->newDataSet(); + for (int irun=runmin; irunreadNextFrame(filebin))) { - - filter->newFrame(); + iFrame=decoder->getFrameNumber(buff); + + if (hitfinder) { + if(iFrame%2==0){ + filterEven->newFrame(); + }else{ + filterOdd->newFrame(); + } + //calculate pedestals and common modes if (cmsub) { - // cout << "cm" << endl; + // cout << "cm" << endl; for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); + if(iFrame%2==0){ + thisEvent=filterEven->getEventType(buff, ix, iy,0); + }else{ + thisEvent=filterOdd->getEventType(buff, ix, iy,0); + } } + } } - // if (hitfinder) { - - // //calculate pedestals and common modes - // } // cout << "new frame " << endl; for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); - // if (nf>10) { - h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + if(iFrame%2==0){ + thisEvent=filterEven->getEventType(buff, ix, iy, cmsub); + }else{ + thisEvent=filterOdd->getEventType(buff, ix, iy,cmsub); + } + + + #ifdef MY_DEBUG - // if (iev%10==0) + if (hitfinder) { + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); + } #endif + if(iFrame%2==0){ + h1->Fill(filterEven->getClusterTotal(1), iy+NR*ix); + }else{ + h1->Fill(filterOdd->getClusterTotal(1), iy+NR*ix); + } if (hitfinder) { - if (thisEvent==PHOTON_MAX ) { - nph++; + if (thisEvent==PHOTON_MAX ) { + nph++; + if(iFrame%2==0){ + h2->Fill(filterEven->getClusterTotal(2), iy+NR*ix); + h3->Fill(filterEven->getClusterTotal(3), iy+NR*ix); + tEven->Fill(); + }else{ + h2->Fill(filterOdd->getClusterTotal(2), iy+NR*ix); + h3->Fill(filterOdd->getClusterTotal(3), iy+NR*ix); + tOdd->Fill(); + } + + } + } - h2->Fill(filter->getClusterTotal(2), iy+NR*ix); - h3->Fill(filter->getClusterTotal(3), iy+NR*ix); - iFrame=decoder->getFrameNumber(buff); - tall->Fill(); - - - } - - - } // else { - // filter->addToPedestal(decoder->getValue(buff,ix,iy, cmsub)); - // } - - - // } } - ////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////// #ifdef MY_DEBUG - // cout << iev << " " << h1->GetEntries() << " " << h2->GetEntries() << endl; -// if (iev%10==0) { -// myC->Modified(); -// myC->Update(); -// cH1->Modified(); -// cH1->Update(); -// cH2->Modified(); -// cH2->Update(); -// cH3->Modified(); -// cH3->Update(); -// } + // cout << iev << " " << h1->GetEntries() << " " << h2->GetEntries() << endl; + // if (iev%10==0) { + // myC->Modified(); + // myC->Update(); + // cH1->Modified(); + // cH1->Update(); + // cH2->Modified(); + // cH2->Update(); + // cH3->Modified(); + // cH3->Update(); + // } iev++; #endif nf++; - // cout << "=" ; + cout << "=" ; delete [] buff; } - // cout << nph << endl; + cout << nph << endl; if (filebin.is_open()) - filebin.close(); + filebin.close(); else cout << "could not open file " << fname << endl; - } - if (hitfinder) - tall->Write(tall->GetName(),TObject::kOverwrite); - + } + + if (hitfinder){ + tEven->Write(tEven->GetName(),TObject::kOverwrite); + tOdd->Write(tOdd->GetName(),TObject::kOverwrite); + } ////////////////////////////////////////////////////////// #ifdef MY_DEBUG - myC->Modified(); - myC->Update(); - cH1->Modified(); - cH1->Update(); - cH2->Modified(); - cH2->Update(); - cH3->Modified(); - cH3->Update(); + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); #endif delete decoder; cout << "Read " << nf << " frames" << endl; return hs; } + +/***********************************************************************************/ +Int_t moench03DrawPedestals(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1){ + + double hc(0); + int sign(1); + moench03CtbData *decoder=new moench03CtbData(); + cout << "decoder allocated " << endl; + + moench03CommonMode *cmSub=NULL; + if (cmsub) { + cmSub=new moench03CommonMode(100); + cout << "common mode allocated " << endl; + + } else { + + cout << "non allocating common mode " << endl; + } + int iev=0; + int nph=0; + + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 1000, 100); + cout << "filter allocated " << endl; + + char *buff; + char fname[10000]; + int nf=0; + eventType thisEvent=PEDESTAL; + int iFrame(0); + + // int iframe; + // double *data, ped, sigma; + + // data=decoder->getCluster(); + + int nChx(xmax-xmin+2); + int nChy(ymax-ymin+2); + TH1F * HistoMap_All[nChx][nChy]; + TH1F * HistoMap_Even[nChx][nChy]; + TH1F * HistoMap_Odd[nChx][nChy]; + for(Int_t ix=0; ixnewDataSet(); + float adc(0.); + ifstream filebin; + for (int irun=runmin; irunreadNextFrame(filebin))) { + iFrame=decoder->getFrameNumber(buff); + filter->newFrame(); + + for(Int_t ix=0; ixgetEventType(buff, ix+xmin, iy+ymin,cmsub); + adc=decoder->getValue(buff,ix+xmin,iy+ymin); + HistoMap_All[ix][iy]->Fill(adc); + if(iFrame%2==0){ + HistoMap_Even[ix][iy]->Fill(adc); + }else{ + HistoMap_Odd[ix][iy]->Fill(adc); + } + } + }//end loop on pixels + + } + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + + + + }//end loop on files + + for(Int_t ix=0; ixWrite(); + HistoMap_Even[ix][iy]->Write(); + HistoMap_Odd[ix][iy]->Write(); + } + } + + delete decoder; + return 1; + +} diff --git a/slsDetectorCalibration/readMoench03Data.C b/slsDetectorCalibration/readMoench03Data.C index 8bbee83b38..591fe7437c 100644 --- a/slsDetectorCalibration/readMoench03Data.C +++ b/slsDetectorCalibration/readMoench03Data.C @@ -2,48 +2,271 @@ -void readMoench03Data(char *tit, int sign=1){ - - - +void readMoench03Data(std::string path,char* tit, std::string phase, std::string wtime,int sign=1,int runmin=0, int runmax=100, int sc_num=0,int hitfinder=1){ + + // int runmin(150); + // int runmax(200); + int nbins(2000); + int hmin(-1000); + int hmax(3000); + int xmin(1); + int xmax(399); + int ymin(1); + int ymax(399); + int cmsub(0); + + char fname[1000]; TFile *fout; + // TFile *fouth1; THStack *hs; - - sprintf(fname,"/mnt/moenchnas/big_moench_xbox_20150223/Mo.root"); + sprintf(fname,"%s/%s_%s_%s_%d_%d_Csub%d_HF%d.root",path.c_str(),tit,phase.c_str(),wtime.c_str(),runmin,runmax-1,cmsub,hitfinder); fout=new TFile(fname,"RECREATE"); + cerr<<"creating output file:"<cd(); + hs=moench03ReadData(fname,tit,runmin,runmax,nbins,hmin,hmax,xmin,xmax,ymin,ymax, cmsub,hitfinder); - sprintf(fname,"/mnt/moenchnas/big_moench_xbox_20150223/Mo_f0_%%d.raw"); - hs=moench03ReadData(fname,"Mo",25133,25187,1500,-500,2500,1,399,1,399, 0,1); cout << "returned" << endl; hs->SetName(tit); hs->SetTitle(tit); cout << "name/title set" << endl; - + + Int_t nH=1; + + TH2F * h=NULL; + + if (hs->GetHists()) { - for (int i=0; i<3; i++) { + for (int i=0; iGetHists()->At(i)) { - cout << i << " " ; (TH2F*)(hs->GetHists()->At(i))->Write(); + // h->SetName(Form("h%d",i+1)); + // h->SetTitle(Form("h%d",i+1)); + // cerr<GetEntries()<<" entries"<cd(i+1); + // h->Draw("colz"); + // fout->cd(); + // h->Write(); + cout << i << " " ; } } + cout << " histos written " << endl; } else cout << "no hists in stack " << endl; + if(fout->IsOpen())fout->Close(); + + + return; + +} +/**********************************************************/ +void readPixelCharge(std::string path,char* tit, std::string phase, std::string wtime, float OD, int sign,int runmin, int runmax, int x0, int y0){ + char fname[1000]; + sprintf(fname,"%s/%s_%s_%2.0fumSi_%s_f0_%%d.raw",path.c_str(),tit,phase.c_str(),OD,wtime.c_str()); + char fnameout[1000]; + sprintf(fnameout,"%s/%s_%s_%2.0fumSi_%s.root",path.c_str(),tit,phase.c_str(),OD,wtime.c_str()); + // sprintf(fnameout,"%s/%s_phase%s_wtime%s_period0.2_OD%1.1f.root",path.c_str(),tit,phase.c_str(),wtime.c_str(),OD); + TFile * fout = new TFile(fnameout,"recreate"); + + for(int i=0; i<12; i++){ + TH1F * hpix = SinglePixelHisto(fname,15000,-0.5,29999.5,runmin,runmax,x0+i,y0); + hpix->SetName(Form("h_%d_%d",x0+i,y0)); + fout->cd(); + hpix->Write(); + } + + + return; +} +/*************************************************/ +void LoopOnPixelCharge(std::string path,char* tit, std::string phase, std::string wtime, int sign,int runmin, int runmax, int x0, int y0){ + float OD=700; + + for(int i=0; i<6; i++){ + readPixelCharge(path,tit,phase,wtime,OD,sign,runmin,runmax,x0,y0); + OD += 200; + } + return; +} + +/**********************************************************/ +void readPixelCorrelation(std::string path,char* tit, std::string frame, std::string phase, std::string wtime,int sign,int runmin, int runmax,int supercolumn){ + + int npx(400); + int npy(400); + + char fname[1000]; + int sc_width(25); + int sc_height(200); + int sc_number=supercolumn; + int xmin(0); + int xmax(0); + int ymin(0); + int ymax(0); + + + ADCMap * map = new ADCMap(npx,npy,sc_width,sc_height); + int ret = map->Init(); + xmin=map->getXmin(sc_number); + xmax=map->getXmax(sc_number); + ymin=map->getYmin(sc_number); + ymax=map->getYmax(sc_number); + + cerr<<"/**********************************/"<getXmin(sc_number)<<" - "<getXmax(sc_number)<getYmin(sc_number)<<" - "<getYmax(sc_number)<GetXaxis()->SetTitle("ADC"); + // h2->GetXaxis()->SetTitle("ADC"); + + + + fout->cd(); + // h1->Write(); + // h2->Write(); + hcorr->Write(); + } + return; fout->Close(); +} + + +/****************************************************/ +void readNoise(std::string path, char *tit, std::string flag, std::string phase, std::string wtime,float OD,int sign,int runmin, int runmax){ + TFile * fout = new TFile(Form("%s/%s_%s_%s_noiseMap%s.root",path.c_str(),tit,phase.c_str(),wtime.c_str(),flag.c_str()),"recreate"); + char fname[1000]; + int nfiles=runmax-runmin; + // int runmin(382); + // int runmax(442); + // std::string target("Cu"); + + + + // THStack * hsnoise = NULL; + TH2F * hped=NULL; + TH2F * hnoise=NULL; + // for(int i=0; i<25; i++){ + // phase.clear(); + // phase=(std::string)Form("%d",i*5); + // sprintf(fname,"%s/%s_phase%s_wtime%s_period0.2_OD%1.1f_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str(),OD); + // sprintf(fname,"%s/%s_phase%s_wtime%s_period0.2_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str()); + sprintf(fname,"%s/%s_%s_%s_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str()); + THStack * hsnoise=calcNoise(fname,flag,runmin,runmax,nfiles); + hsnoise->SetName(Form("%s_noiseMap_ph%s",tit,phase.c_str())); + + fout->cd(); + if (hsnoise->GetHists()) { + hped=(TH2F*)(hsnoise->GetHists()->At(0)); + hped->SetName(Form("hped_ph%s",phase.c_str())); + hped->Write(); + hnoise=(TH2F*)(hsnoise->GetHists()->At(1)); + hnoise->SetName(Form("hnoise_ph%s",phase.c_str())); + hnoise->Write(); + cout << " histos written for ADC Phase " << phase.c_str()<Close(); + return; } +/************************************************************************/ +void readFrames(std::string path, char *tit, std::string phase, std::string wtime,int sign,int runnum, int framemin, int framemax){ + char fformat[1000]; + char fname[1000]; + sprintf(fformat,"%s/%s_phase%s_wtime%s_period0.075_f0_%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str(),runnum); + THStack * hs = DrawFrames(fformat,framemin,framemax); + int nframes=framemax-framemin; + TFile * fout = new TFile(Form("%s/Frames_phase%s_wtime%s_period0.075_f0_%d_fr%d-%d.root",path.c_str(),phase.c_str(),wtime.c_str(),runnum,framemin,framemax),"recreate"); + + TCanvas * c1= new TCanvas("c1","",800,600); + c1->Print(Form("%s/Frames_phase%s_wtime%s_period0.075_f0_%d_fr%d-%d.pdf[",path.c_str(),phase.c_str(),wtime.c_str(),runnum,framemin,framemax)); + TH2F * h=NULL; + + for(int hnum=0; hnumGetHists()->At(hnum); + h->SetName(Form("h_%d",hnum+framemin)); + h->SetTitle(Form("h_%d",hnum+framemin)); + h->GetZaxis()->SetRangeUser(5000.,10000.); + h->Draw("colz"); + + + c1->Print(Form("%s/Frames_phase%s_wtime%s_period0.075_f0_%d_fr%d-%d.pdf",path.c_str(),phase.c_str(),wtime.c_str(),runnum,framemin,framemax)); + fout->cd(); + h->Write(); + } + + c1->Print(Form("%s/Frames_phase%s_wtime%s_period0.075_f0_%d_fr%d-%d.pdf]",path.c_str(),phase.c_str(),wtime.c_str(),runnum,framemin,framemax)); + + fout->Close(); + + return; +} +/************************************************************************************/ +void PlotSinglePixelHisto(std::string path, char *tit, std::string flag, std::string phase, std::string wtime,float OD,int sign,int runmin, int runmax, int x0, int y0){ + char fname[1000]; + sprintf(fname,"%s/%s_%s_%s_f0_%%d.raw",path.c_str(),tit,phase.c_str(),wtime.c_str()); + + int nbins(8000); + float xmin(-0.5); + float xmax(15999.5); + + TH1F * h1 = SinglePixelHisto(fname,nbins,xmin,xmax,runmin,runmax,x0,y0); + h1->Draw("hist"); + + + return; + +} // void raedNoiseDataN(char *tit, int sign=1){ From 1941ecb3c36442d369fc769273533cff5e3e21af Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 23 Jun 2015 09:15:23 +0200 Subject: [PATCH 079/104] Adedde sturctures for moench03 10Gb data --- slsDetectorCalibration/moench03Ctb10GbData.h | 225 +++++++++ slsDetectorCalibration/moench03ReadData10Gb.C | 455 ++++++++++++++++++ slsDetectorCalibration/slsDetectorData.h | 78 +-- slsDetectorCalibration/slsReceiverData.h | 4 +- slsDetectorCalibration/viewMoenchDRXRays.C | 178 +++++++ 5 files changed, 900 insertions(+), 40 deletions(-) create mode 100644 slsDetectorCalibration/moench03Ctb10GbData.h create mode 100644 slsDetectorCalibration/moench03ReadData10Gb.C create mode 100644 slsDetectorCalibration/viewMoenchDRXRays.C diff --git a/slsDetectorCalibration/moench03Ctb10GbData.h b/slsDetectorCalibration/moench03Ctb10GbData.h new file mode 100644 index 0000000000..68ab2e1674 --- /dev/null +++ b/slsDetectorCalibration/moench03Ctb10GbData.h @@ -0,0 +1,225 @@ +#ifndef MOENCH03CTB10GBDATA_H +#define MOENCH03CTB10GBDATA_H +#include "slsReceiverData.h" + + + +class moench03Ctb10GbData : public slsReceiverData { + + private: + + int iframe; + int nadc; + int sc_width; + int sc_height; + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + // moench03Ctb10GbData(int ns=5000): slsDetectorData(400, 400, 8208*40, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) { + moench03Ctb10GbData(int ns=5000): slsReceiverData(400, 400, 40, 8208), nadc(32), sc_width(25), sc_height(200) { + + int adc_nr[32]={200,225,250,275,300,325,350,375,\ + 0,25,50,75,100,125,150,175,\ + 175,150,125,100,75,50,25,0,\ + 375,350,325,300,275,250,225,200}; + int row, col; + + int isample; + int iadc; + int ix, iy; + + int npackets=40; + int i; + + + for (int ip=0; ip=8208*40) + cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; + } + } + } + } + + int ipacket; + int ibyte; + int ii=0; + for (int ipacket=0; ipacket0) { */ +/* iframe++; */ +/* // cout << ib << "-" << endl; */ +/* return (char*)afifo_cont; */ +/* } else { */ +/* delete [] afifo_cont; */ +/* return NULL; */ +/* } */ +/* } */ +/* return NULL; */ +/* }; */ + + + virtual char *readNextFrame(ifstream &filebin, int& fnum) { + char *data=new char[packetSize*nPackets]; + char *retval=0; + int np=0, nd; + fnum = -1; + int pn; + char aa[8224]; + char *packet=(char *)aa; + + if (filebin.is_open()) { + + + + + while(filebin.read((char*)packet, 8208) && np=0) { + if (getFrameNumber(packet) !=fnum) { + + if (np==0){ + delete [] data; + return NULL; + } else + return data; + } + + memcpy(data+(pn-1)*packetSize, packet, packetSize); + np++; + + } + } + + } + + if (np==0){ + delete [] data; + return NULL; + } + + }; + + + virtual char *readNextFrame(ifstream &filebin) { + int fnum; + return readNextFrame(filebin, fnum); + }; + +}; + + + + +#endif diff --git a/slsDetectorCalibration/moench03ReadData10Gb.C b/slsDetectorCalibration/moench03ReadData10Gb.C new file mode 100644 index 0000000000..2b67f35f99 --- /dev/null +++ b/slsDetectorCalibration/moench03ReadData10Gb.C @@ -0,0 +1,455 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include +#include +#include "moench03Ctb10GbData.h" +#include "moench03CommonMode.h" +#define MYROOT1 +#include "singlePhotonDetector.h" + +//#include "MovingStat.h" + +using namespace std; + +#define NC 400 +#define NR 400 + + +//#define MY_DEBUG 1 + +#ifdef MY_DEBUG +#include +#endif + + + +TH2F *readImage(ifstream &filebin, TH2F *h2=NULL, TH2F *hped=NULL) { + moench03Ctb10GbData *decoder=new moench03Ctb10GbData(); + char *buff=decoder->readNextFrame(filebin); + + +// TH1F *h1=new TH1F("h1","",400*400,0,400*400); +// int ip=0; + if (buff) { + if (h2==NULL) { + h2=new TH2F("h2","",400,0,400,400,0,400); + h2->SetStats(kFALSE); + } + // cout << "." << endl; + for (int ix=0; ix<400; ix++) { + for (int iy=0; iy<400; iy++) { + // cout << decoder->getDataSize() << " " << decoder->getValue(buff,ix,iy)<< endl; + h2->SetBinContent(ix+1,iy+1,decoder->getValue(buff,ix,iy)); + // h1->SetBinContent(++ip,decoder->getValue(buff,ix,iy)); + } + } + if (hped) h2->Add(hped,-1); + return h2; + } + return NULL; +} + + +TH2F *readImage(char *fname, int iframe=0, TH2F *hped=NULL) { + ifstream filebin; + filebin.open((const char *)(fname), ios::in | ios::binary); + TH2F *h2=new TH2F("h2","",400,0,400,400,0,400); + TH2F *hh; + hh=readImage(filebin, h2, hped ); + if (hh==NULL) { + + delete h2; + return NULL; + } + for (int i=0; i0) { + h2=new TH2F("hped","",400,0,400,400,0,400); + + for (ix=0; ix<400; ix++) { + for (iy=0; iy<400; iy++) { + h2->SetBinContent(ix+1, iy+1,filter->getPedestal(ix,iy)); + } + } + + } + return h2; + +} + + +TH1D *calcSpectrum(char *fformat, int runmin, int runmax, TH2F *hped=NULL){ + ifstream filebin; + char fname[10000]; + moench03Ctb10GbData *decoder=new moench03Ctb10GbData(); + TH1D *hspectrum=new TH1D("hsp","hsp",2500,-500,10000); + char *buff; + int ix,iy; + int ii=0; + TH2F* h2=NULL; + int ich=0; + Double_t ped=0; + + for (int irun=runmin; irun<=runmax; irun++) { + sprintf(fname,fformat,irun); + + cout << fname << endl; + filebin.open((const char *)(fname), ios::in | ios::binary); + while ((buff=decoder->readNextFrame(filebin))) { + for (ix=0; ix<200; ix++) { + for (iy=200; iy<400; iy++) { + if (decoder->getValue(buff,ix,iy)>1000) { + if(hped) ped=hped->GetBinContent(ix+1,iy+1); + hspectrum->Fill(decoder->getValue(buff,ix,iy)-ped); + } + ich++; + } + } + delete [] buff; + //cout << "="<< endl; + ii++; + } + if (filebin.is_open()) + filebin.close(); + + } + return hspectrum; + +} +TH2F *drawImage(char *fformat, int runmin, int runmax, TH2F *hped=NULL){ + ifstream filebin; + char fname[10000]; + moench03Ctb10GbData *decoder=new moench03Ctb10GbData(); + TH2F *hspectrum=new TH2F("hsp","hsp",400,0,400,400,0,400); + char *buff; + int ix,iy; + int ii=0; + TH2F* h2=NULL; + int ich=0; + Double_t ped=0; + + for (int irun=runmin; irun<=runmax; irun++) { + sprintf(fname,fformat,irun); + + cout << fname << endl; + filebin.open((const char *)(fname), ios::in | ios::binary); + while ((buff=decoder->readNextFrame(filebin))) { + for (ix=0; ix<400; ix++) { + for (iy=0; iy<400; iy++) { + if (decoder->getValue(buff,ix,iy)>1000) { + if(hped) ped=hped->GetBinContent(ix+1,iy+1); + hspectrum->Fill(ix, iy, decoder->getValue(buff,ix,iy)-ped); + } + ich++; + } + } + delete [] buff; + //cout << "="<< endl; + ii++; + } + if (filebin.is_open()) + filebin.close(); + + } + return hspectrum; + +} + + + + + +/** + +Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis. + + \param fformat file name format + \param tit title of the tree etc. + \param runmin minimum run number + \param runmax max run number + \param nbins number of bins for spectrum hists + \param hmin histo minimum for spectrum hists + \param hmax histo maximum for spectrum hists + \param xmin minimum x coordinate + \param xmax maximum x coordinate + \param ymin minimum y coordinate + \param ymax maximum y coordinate + \param cmsub enable commonmode subtraction + \returns pointer to histo stack with cluster spectra +*/ + +THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1) { + double hc=0; + int sign=1; + + moench03Ctb10GbData *decoder=new moench03Ctb10GbData(); + cout << "decoder allocated " << endl; + + moench03CommonMode *cmSub=NULL; + if (cmsub) { + cmSub=new moench03CommonMode(100); + cout << "common mode allocated " << endl; + + } else { + + cout << "non allocating common mode " << endl; + } + int iev=0; + int nph=0; + + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub, 100, 10); + cout << "filter allocated " << endl; + + char *buff; + char fname[10000]; + int nf=0; + + eventType thisEvent=PEDESTAL; + + // int iframe; + // double *data, ped, sigma; + + // data=decoder->getCluster(); + + + THStack *hs=new THStack("hs",fformat); + + cout << "hstack allocated " << endl; + + + TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h1); + cout << "h1 allocated " << endl; + + TH2F *h2; + TH2F *h3; + if (hitfinder) { + h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + cout << "h2 allocated " << endl; + h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + cout << "h3 allocated " << endl; + // hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + // hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h2); + hs->Add(h3); + // hs->Add(hetaX); + // hs->Add(hetaY); + } + if (hs->GetHists()) { + for (int i=0; i<3; i++) + if (hs->GetHists()->At(1)) cout << i << " " ; + cout << " histos allocated " << endl; + } else + cout << "no hists in stack " << endl; + + + ifstream filebin; + + + int ix=20, iy=20, ir, ic; + + + Int_t iFrame; + TTree *tall; + if (hitfinder) + tall=filter->initEventTree(tit, &iFrame); + + + + +#ifdef MY_DEBUG + + cout << "debug mode " << endl; + + TCanvas *myC; + TH2F *he; + TCanvas *cH1; + TCanvas *cH2; + TCanvas *cH3; + + if (hitfinder) { + myC=new TCanvas("myc"); + he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); + he->SetStats(kFALSE); + he->Draw("colz"); + cH1=new TCanvas("ch1"); + cH1->SetLogz(); + h1->Draw("colz"); + cH2=new TCanvas("ch2"); + cH2->SetLogz(); + h2->Draw("colz"); + cH3=new TCanvas("ch3"); + cH3->SetLogz(); + h3->Draw("colz"); + } +#endif + + filter->newDataSet(); + + + for (int irun=runmin; irunreadNextFrame(filebin))) { + + filter->newFrame(); + + if (cmsub) { + // cout << "cm" << endl; + for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); + } + } + // if (hitfinder) { + + // //calculate pedestals and common modes + // } + + // cout << "new frame " << endl; + + for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); + // if (nf>10) { + h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + +#ifdef MY_DEBUG + // if (iev%10==0) + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); +#endif + + if (hitfinder) { + + if (thisEvent==PHOTON_MAX ) { + nph++; + + h2->Fill(filter->getClusterTotal(2), iy+NR*ix); + h3->Fill(filter->getClusterTotal(3), iy+NR*ix); + iFrame=decoder->getFrameNumber(buff); + + tall->Fill(); + + + } + + + } // else { + // filter->addToPedestal(decoder->getValue(buff,ix,iy, cmsub)); + + // } + + + // } + } + ////////////////////////////////////////////////////////// + +#ifdef MY_DEBUG + // cout << iev << " " << h1->GetEntries() << " " << h2->GetEntries() << endl; +// if (iev%10==0) { +// myC->Modified(); +// myC->Update(); +// cH1->Modified(); +// cH1->Update(); +// cH2->Modified(); +// cH2->Update(); +// cH3->Modified(); +// cH3->Update(); +// } + iev++; +#endif + nf++; + + // cout << "=" ; + delete [] buff; + } + // cout << nph << endl; + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + } + if (hitfinder) + tall->Write(tall->GetName(),TObject::kOverwrite); + + ////////////////////////////////////////////////////////// + +#ifdef MY_DEBUG + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); +#endif + + delete decoder; + cout << "Read " << nf << " frames" << endl; + return hs; +} + diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index 3da6a04078..b46f59f387 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -40,8 +40,8 @@ class slsDetectorData { slsDetectorData(int npx, int npy, int dsize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), dataSize(dsize) { - xmap=new int[nx*ny]; - ymap=new int[nx*ny]; + xmap=new int[dsize/sizeof(dataType)]; + ymap=new int[dsize/sizeof(dataType)]; dataMask=new dataType*[ny]; for(int i = 0; i < ny; i++) { @@ -228,42 +228,44 @@ class slsDetectorData { virtual dataType getChannel(char *data, int ix, int iy, int dr) { dataType m=0; uint64_t t; - int numBytes,divFactor,newix,pixelval; - -//cout <<"ix:"<=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; - return ((t >> (pixelval*4)) & 0xf)^m; - else if(dr == 8) - //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; - return ((t >> (pixelval*8)) & 0xff)^m; - else if(dr == 16){ - //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; - return ((t >> (pixelval*16)) & 0xffff)^m; - }else{ - //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; - return ((t >> (pixelval*32)) & 0xffffffff)^m; - } + + /////All this stuff should go to eiger detector!!!!!!!!!!!!!!! +/* int numBytes,divFactor,newix,pixelval; */ + +/* //cout <<"ix:"<=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; */ +/* return ((t >> (pixelval*4)) & 0xf)^m; */ +/* else if(dr == 8) */ +/* //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; */ +/* return ((t >> (pixelval*8)) & 0xff)^m; */ +/* else if(dr == 16){ */ +/* //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; */ +/* return ((t >> (pixelval*16)) & 0xffff)^m; */ +/* }else{ */ +/* //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; */ +/* return ((t >> (pixelval*32)) & 0xffffffff)^m; */ +/* } */ }; /** diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index bfe7a88c51..c62e79ec76 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -67,10 +67,10 @@ class slsReceiverData : public slsDetectorData { while (dd<=(dsize-packetSize)) { pnum=getPacketNumber(p); fn=getFrameNumber(p); - //cout <<"pnum:"<nPackets) { - cout << "Bad packet number " << pnum << " frame "<< fn << endl; + cout << "Bad packet number " << pnum << " frame "<< fn << endl; retval=NULL; np=0; } else if (pnum==1) { diff --git a/slsDetectorCalibration/viewMoenchDRXRays.C b/slsDetectorCalibration/viewMoenchDRXRays.C new file mode 100644 index 0000000000..7df5b926e6 --- /dev/null +++ b/slsDetectorCalibration/viewMoenchDRXRays.C @@ -0,0 +1,178 @@ + +#define MYROOT1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "moench03CtbData.h" +//#include "moench03CommonMode.h" +//#include "singlePhotonDetector.h" + + +using namespace std; + + +THStack *viewMoenchDRXRays(int ix=70, int iy=88){ + + TF1 *poiss = new TF1("poiss", "[0]*TMath::Power(([1]/[2]),(x/[2]))*(TMath::Exp( ([1]/[2])))/TMath::Gamma((x/[2])+1)", 0, 5); + + + int thick[]={1700,1500,1300,1100,900,700}; + int nt=6; + int nf=5; + char fname[1000]; + char *data; + char tit[100]; + TH1F *hh[nt], *hh3[nt], *hh5[nt]; + TH2F *h2[nt], *hpix[nt]; + Double_t val, val3, val5, val1; + int it=0; + Double_t ped[25]; + TH1D *p; + + THStack *hs=new THStack(); + cout << nt << endl; + ifstream filebin; + moench03CtbData *decoder=new moench03CtbData(); + + sprintf(tit,"hpix_%dumSi_g1",thick[it]); + cout << tit << endl; + + + hpix[it]=new TH2F(tit,tit,2500,6000,16000,25,0,25); + hs->Add(hpix[it]); + + sprintf(tit,"%dumSi_g1",thick[it]); + cout << tit << endl; + + for (int iff=0; iffreadNextFrame(filebin))) { + + for (int iiy=-2; iiy<3; iiy++) + for (int iix=-2; iix<3; iix++) + hpix[it]->Fill(decoder->getChannel(data,ix+iix,iy+iiy), (iiy+2)*5+iix+2); + + delete [] data; + } + filebin.close(); + cout << endl; + + + + } + + + for (int iix=-2; iix<3; iix++) { + for (int iiy=-2; iiy<3; iiy++) { + cout << iix << " " << iiy << " " ;// <ProjectionX("p",(iiy+2)*5+iix+2+1,(2+iiy)*5+iix+2+1); + + ped[(iiy+2)*5+iix+2]=p->GetBinCenter(p->GetMaximumBin()); + + cout << ped[(iiy+2)*5+iix+2] <Add(hh[it]); + sprintf(tit,"hh3_%dumSi_g1",thick[it]); + hh3[it]=new TH1F(tit,tit,5000,0,30000); + hs->Add(hh3[it]); + + sprintf(tit,"hh5_%dumSi_g1",thick[it]); + hh5[it]=new TH1F(tit,tit,5000,0,50000); + hs->Add(hh5[it]); + + sprintf(tit,"%dumSi_g1",thick[it]); + cout << tit << endl; + hs->Add(hh[it]); + for (int iff=0; iffreadNextFrame(filebin))) { + cout << "-" ; + // for (int iy=0; iy<40; iy++) + // for (int ix=0; ix<350; ix++){ + + + + + val1=0; + val3=0; + val5=0; + + + for (int iix=-2; iix<3; iix++) { + for (int iiy=-2; iiy<3; iiy++) { + // cout << iix << " " << iiy << " " ;// <ProjectionX("p",(iiy+2)*5+iix+2+1,(2+iiy)*5+iix+2+1); + + // ped[it]=p->GetBinCenter(p->GetMaximumBin()); + + // cout << ped[it] <getChannel(data,ix+iix,iy+iiy)-ped[(iiy+2)*5+iix+2]; + if ((iix<-1 || iix>1) || (iiy<-1 || iiy>1)) + val5+=val; + else if (iix!=0 || iiy!=0) { + val5+=val; + val3+=val; + } else { + val5+=val; + val3+=val; + val1+=val; + } + // if (iiy==1 && iix==0) + // h2[it]->Fill(val1,val); + + } + } + hh5[it]->Fill(val5); + hh3[it]->Fill(val3); + hh[it]->Fill(val1); + + + + delete [] data; + } + filebin.close(); + cout << endl; + + } + + + } + + + + return hs; + +} From b820ae0cad9e5cb301543fd51bf44c86e82c4071 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 23 Jun 2015 11:03:49 +0200 Subject: [PATCH 080/104] checkFrameNumber added to moench03 read data --- slsDetectorCalibration/moench03ReadData10Gb.C | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/slsDetectorCalibration/moench03ReadData10Gb.C b/slsDetectorCalibration/moench03ReadData10Gb.C index 2b67f35f99..44af13623e 100644 --- a/slsDetectorCalibration/moench03ReadData10Gb.C +++ b/slsDetectorCalibration/moench03ReadData10Gb.C @@ -9,6 +9,7 @@ #include #include #include +#include #include //#include //#include @@ -453,3 +454,37 @@ THStack *moench03ReadData(char *fformat, char *tit, int runmin, int runmax, int return hs; } +TGraph* checkFrameNumber(char *fformat, int runmin, int runmax, int ix, int iy){ + ifstream filebin; + char fname[10000]; + moench03Ctb10GbData *decoder=new moench03Ctb10GbData(); + char *buff; + int ii=0; + + TGraph *g=new TGraph(); + + + + for (int irun=runmin; irun<=runmax; irun++) { + sprintf(fname,fformat,irun); + + cout << fname << endl; + + filebin.open((const char *)(fname), ios::in | ios::binary); + + if (filebin.is_open()) { + while ((buff=decoder->readNextFrame(filebin))) { + g->SetPoint(ii,decoder->getFrameNumber(buff),decoder->getValue(buff,ix,iy)); + ii++; + delete [] buff; + } + //cout << "="<< endl; + filebin.close(); + } else + cout << "Could not open file " << fname << endl; + + } + + return g; + +} From 9041c48bbf14d5be673788da7f9c9c69757c7b19 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 26 Jun 2015 11:52:17 +0200 Subject: [PATCH 081/104] offline headers for dynamic range, fixed port to be same 1 bit always --- slsDetectorCalibration/eigerHalfModuleData.h | 60 ++++++++++---------- slsDetectorCalibration/slsReceiverData.h | 9 +++ 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 3b698c966b..f727a8ee8a 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -182,49 +182,51 @@ class eigerHalfModuleData : public slsReceiverData { - /** gets the packets number (last packet is labelled with 0 and is replaced with 40) + /** gets the packets number \param buff pointer to the memory \returns packet number */ int getPacketNumber(char *buff){ #ifdef VERY_DEBUG cprintf(RED, "\n0x%x - %d - %d", - (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(buff)))->num2))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num3)),//port and dr + (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num4)),//non 32 bit packet# + (*(uint16_t*)(((eiger_packet_header *)((char*)(buff)))->num2)));//32 bit packet# #endif - //32 bit packet number written in num2 + + //both ports have same packet numbers, so reconstruct + //16 bit packet number written in num2 for 32 bit mode + if(dynamicRange == 32){ - //both ports have same packet numbers, so reconstruct, ports interchanged for bottom - if((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3))){ - if (top) - return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+(numberOfPackets/2) +1); - else - return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+1); - }else{ - if (top) - return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+1); - else - return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+(numberOfPackets/2) +1); - } + if((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3)) & 0x1) + return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+(numberOfPackets/2) +1); + else + return ((*(uint16_t*)(((eiger_packet_header *)((char*)buff))->num2))+1); } else{ - //both ports have same packet numbers, so reconstruct - if((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3))){ - if (top) - return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+(numberOfPackets/2) +1); - else - return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+1); - }else{ - if (top) - return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+1); - else - return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+(numberOfPackets/2) +1); - } + if((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3)) &0x1) + return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+(numberOfPackets/2) +1); + else + return ((*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num4))+1); } }; + + /** gets the dynamic range for offline processing + \param buff pointer to the memory + \returns dynamic range + */ + static int getDynamicRange(char *buff){ +#ifdef VERY_DEBUG + cprintf(RED, "\n0x%x", + (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num3))); +#endif + return (*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3)) >> 2; + }; + + + /** returns the pixel value as double correcting for the output buffer crosstalk \param data pointer to the memory diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index bfe7a88c51..2658ad27e7 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -48,6 +48,15 @@ class slsReceiverData : public slsDetectorData { virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;}; + /** gets the dynamic range for offline processing + \param buff pointer to the memory + \returns dynamic range + * + */ + //virtual int getDynamicRange(char *buff){return 16;}; + + + /** From 49ef6659d4b9c98a2b7bdc9f2e9fadf1eaa5c1ac Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 26 Jun 2015 15:45:38 +0200 Subject: [PATCH 082/104] eiger dynamic range offline header, moved eiger specific stuff from slsDetectorData to eigerHalfmodule --- slsDetectorCalibration/eigerHalfModuleData.h | 86 ++++++++++++++++---- slsDetectorCalibration/slsDetectorData.h | 41 +--------- slsDetectorCalibration/slsReceiverData.h | 2 +- 3 files changed, 71 insertions(+), 58 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index f727a8ee8a..992543293f 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -20,7 +20,7 @@ class eigerHalfModuleData : public slsReceiverData { eigerHalfModuleData(int dr, int np, int bsize, int dsize, bool top, double c=0): slsReceiverData(xpixels, ypixels, np, bsize), - xtalk(c), bufferSize(bsize), dataSize(dsize), dynamicRange(dr), numberOfPackets(np), top(top){ + xtalk(c), bufferSize(bsize), actualDataSize(dsize), dynamicRange(dr), numberOfPackets(np), top(top){ int **dMap; @@ -58,7 +58,7 @@ class eigerHalfModuleData : public slsReceiverData { iPacket1 += increment; iData1 += increment; //increment header - if(iData1 >= dataSize){ + if(iData1 >= actualDataSize){ iPacket1 += 16; iData1 = 0; } @@ -67,7 +67,7 @@ class eigerHalfModuleData : public slsReceiverData { iPacket2 += increment; iData2 += increment; //increment header - if(iData2 >= dataSize){ + if(iData2 >= actualDataSize){ iPacket2 += 16; iData2 = 0; } @@ -109,12 +109,12 @@ class eigerHalfModuleData : public slsReceiverData { iPacket1 -= (numbytesperlineperport*2 + 16*3); iData1 = 0; } - if(iData1 == dataSize){ + if(iData1 == actualDataSize){ iPacket1 += 16; } }else if((iData1 % numbytesperlineperport) == 0){ iPacket1 -= (numbytesperlineperport*2); - if(iData1 == dataSize){ + if(iData1 == actualDataSize){ iPacket1 -= 16; iData1 = 0; } @@ -131,12 +131,12 @@ class eigerHalfModuleData : public slsReceiverData { iPacket2 -= (numbytesperlineperport*2 + 16*3); iData2 = 0; } - if(iData2 == dataSize){ + if(iData2 == actualDataSize){ iPacket2 += 16; } }else if((iData2 % numbytesperlineperport) == 0){ iPacket2 -= (numbytesperlineperport*2); - if(iData2 == dataSize){ + if(iData2 == actualDataSize){ iPacket2 -= 16; iData2 = 0; } @@ -172,11 +172,11 @@ class eigerHalfModuleData : public slsReceiverData { \returns frame number */ int getFrameNumber(char *buff){ - return(*(unsigned int*)(((eiger_packet_header *)((char*)buff))->num1)); + return(*(unsigned int*)(((eiger_packet_header *)((char*)buff))->num1)); }; - + @@ -189,9 +189,9 @@ class eigerHalfModuleData : public slsReceiverData { int getPacketNumber(char *buff){ #ifdef VERY_DEBUG cprintf(RED, "\n0x%x - %d - %d", - (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num3)),//port and dr - (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num4)),//non 32 bit packet# - (*(uint16_t*)(((eiger_packet_header *)((char*)(buff)))->num2)));//32 bit packet# + (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num3)),//port and dr + (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num4)),//non 32 bit packet# + (*(uint16_t*)(((eiger_packet_header *)((char*)(buff)))->num2)));//32 bit packet# #endif //both ports have same packet numbers, so reconstruct @@ -217,12 +217,12 @@ class eigerHalfModuleData : public slsReceiverData { \param buff pointer to the memory \returns dynamic range */ - static int getDynamicRange(char *buff){ + static int getDynamicRange(char *buff){ #ifdef VERY_DEBUG cprintf(RED, "\n0x%x", (*(uint8_t*)(((eiger_packet_header *)((char*)(buff)))->num3))); #endif - return (*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3)) >> 2; + return (*(uint8_t*)(((eiger_packet_header *)((char*)buff))->num3)) >> 2; }; @@ -238,12 +238,64 @@ class eigerHalfModuleData : public slsReceiverData { double getValue(char *data, int ix, int iy=0) { // cout << "##" << (void*)data << " " << ix << " " <::getValue(data, ix, iy); + return getChannel(data, ix, iy, dynamicRange); else - return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); + return getChannel(data, ix, iy,dynamicRange)-xtalk * getChannel(data, ix-1, iy,dynamicRange); }; + /** + + Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded. + \param data pointer to the dataset (including headers etc) + \param ix pixel number in the x direction + \param iy pixel number in the y direction + \param dr dynamic range + \returns data for the selected channel, with inversion if required + + */ + + virtual uint32_t getChannel(char *data, int ix, int iy, int dr) { + uint32_t m=0; + uint64_t t; + int numBytes,divFactor,newix,pixelval; + + //cout <<"ix:"<=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; + return ((t >> (pixelval*4)) & 0xf)^m; + else if(dr == 8) + //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; + return ((t >> (pixelval*8)) & 0xff)^m; + else if(dr == 16){ + //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; + return ((t >> (pixelval*16)) & 0xffff)^m; + }else{ + //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; + return ((t >> (pixelval*32)) & 0xffffffff)^m; + } + }; + /** sets the output buffer crosstalk correction parameter \param c output buffer crosstalk correction parameter to be set @@ -271,7 +323,7 @@ class eigerHalfModuleData : public slsReceiverData { const static int xpixels = 1024; const static int ypixels = 256; const int bufferSize; - const int dataSize; + const int actualDataSize; const int dynamicRange; const int numberOfPackets; bool top; diff --git a/slsDetectorCalibration/slsDetectorData.h b/slsDetectorCalibration/slsDetectorData.h index b46f59f387..bfb284bc0e 100644 --- a/slsDetectorCalibration/slsDetectorData.h +++ b/slsDetectorCalibration/slsDetectorData.h @@ -226,46 +226,7 @@ class slsDetectorData { */ virtual dataType getChannel(char *data, int ix, int iy, int dr) { - dataType m=0; - uint64_t t; - - /////All this stuff should go to eiger detector!!!!!!!!!!!!!!! -/* int numBytes,divFactor,newix,pixelval; */ - -/* //cout <<"ix:"<=0 && ix=0 && iy=0 && dataMap[iy][ix]> (pixelval*4); cout <<"value:"<< value << endl; */ -/* return ((t >> (pixelval*4)) & 0xf)^m; */ -/* else if(dr == 8) */ -/* //uint8_t value = t >> (pixelval*8); cout <<"value:"<< value << endl; */ -/* return ((t >> (pixelval*8)) & 0xff)^m; */ -/* else if(dr == 16){ */ -/* //uint16_t value = t >> (pixelval*16); cout <<"value:"<< value << endl; */ -/* return ((t >> (pixelval*16)) & 0xffff)^m; */ -/* }else{ */ -/* //uint32_t value = t >> (pixelval*32); cout <<"value:"<< value << endl; */ -/* return ((t >> (pixelval*32)) & 0xffffffff)^m; */ -/* } */ + return 0; }; /** diff --git a/slsDetectorCalibration/slsReceiverData.h b/slsDetectorCalibration/slsReceiverData.h index b927c1d894..fac829c5bd 100644 --- a/slsDetectorCalibration/slsReceiverData.h +++ b/slsDetectorCalibration/slsReceiverData.h @@ -76,7 +76,7 @@ class slsReceiverData : public slsDetectorData { while (dd<=(dsize-packetSize)) { pnum=getPacketNumber(p); fn=getFrameNumber(p); - cout <<"pnum:"<nPackets) { cout << "Bad packet number " << pnum << " frame "<< fn << endl; From 47d51674b465bae7b9c69c40b564286a69429148 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 26 Jun 2015 15:57:10 +0200 Subject: [PATCH 083/104] resolved flip bytes in eiger --- slsDetectorCalibration/eigerHalfModuleData.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 992543293f..1b3f23def1 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -258,7 +258,7 @@ class eigerHalfModuleData : public slsReceiverData { virtual uint32_t getChannel(char *data, int ix, int iy, int dr) { uint32_t m=0; uint64_t t; - int numBytes,divFactor,newix,pixelval; + int numBytes,divFactor,pixelval; //cout <<"ix:"<=0 && ix=0 && iy=0 && dataMap[iy][ix] { else if (dr == 16) divFactor = 4; pixelval = numBytes % divFactor; - newix = ix - pixelval; - //cout <<"pixelval:"< Date: Fri, 26 Jun 2015 16:32:10 +0200 Subject: [PATCH 084/104] adding script for gifs --- slsDetectorCalibration/PlotGifs.C | 194 ++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 slsDetectorCalibration/PlotGifs.C diff --git a/slsDetectorCalibration/PlotGifs.C b/slsDetectorCalibration/PlotGifs.C new file mode 100644 index 0000000000..97c5ea713a --- /dev/null +++ b/slsDetectorCalibration/PlotGifs.C @@ -0,0 +1,194 @@ +#include "moench03ReadData.C" + + + +/************************************************************************/ +TH2F *readExactImage(char *fname, int iframe=0, int frperfile,TH2F *hped=NULL) { + ifstream filebin; + filebin.open((const char *)(fname), ios::in | ios::binary); + TH2F *h2=new TH2F("h2","",400,0,400,400,0,400); + int framen(0); + moench03CtbData *decoder=new moench03CtbData(); + char *buff=decoder->readNextFrame(filebin); + framen=decoder->getFrameNumber(buff); + + int counter(0); + + while(framen