From 6e4be40f375d2462420db2b73afa41d125db42ef Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 6 Sep 2012 12:03:22 +0000 Subject: [PATCH] Bad channels correction separated from postProcessing git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@241 951219d9-93cf-4727-9268-0efd64621fa3 --- .../angleConversionConstant.h | 19 + .../slsDetectorAnalysis/angularCalibration.h | 18 +- .../slsDetectorAnalysis/angularConversion.h | 4 +- .../angularConversionStatic.h | 9 +- .../angularConversionStatic.h~ | 338 +----------------- .../badChannelCorrections.h | 59 +++ .../slsDetectorAnalysis/postProcessing.cpp | 63 ---- .../slsDetectorAnalysis/postProcessing.h | 50 +-- 8 files changed, 98 insertions(+), 462 deletions(-) create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/badChannelCorrections.h diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angleConversionConstant.h b/slsDetectorSoftware/slsDetectorAnalysis/angleConversionConstant.h index 213096450..ee8c7338f 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/angleConversionConstant.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/angleConversionConstant.h @@ -14,6 +14,25 @@ class angleConversionConstant { double tilt; /**< ossible tilt in the orthogonal direction (unused)*/ double etilt; /**< error in the tilt determination */ //} angleConversionConstant; + + double getCenter(){return center;}; + double getConversion(){return r_conversion;}; + double getOffset(){return offset;}; + double getTilt(){return tilt;}; + + int setAngConvConstant(angleConversionConstant *acc) {\ + center=acc->center; \ + ecenter=acc->ecenter; \ + r_conversion=acc->r_conversion; \ + er_conversion=acc->er_conversion; \ + offset=acc->offset; \ + eoffset=acc->eoffset; \ + tilt=acc->tilt; \ + etilt=acc->etilt; \ + }; + + + }; #endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularCalibration.h b/slsDetectorSoftware/slsDetectorAnalysis/angularCalibration.h index 7a3c8c973..b67d90f38 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/angularCalibration.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularCalibration.h @@ -16,22 +16,6 @@ class TH1; -/** - angular conversion constant for a module - */ -typedef struct { - double center; /**< center of the module (channel at which the radius is perpendicular to the module surface) */ - double ecenter; /**< error in the center determination */ - double r_conversion; /**< detector pixel size (or strip pitch) divided by the diffractometer radius */ - double er_conversion; /**< error in the r_conversion determination */ - double offset; /**< the module offset i.e. the position of channel 0 with respect to the diffractometer 0 */ - double eoffset; /**< error in the offset determination */ - double tilt; /**< ossible tilt in the orthogonal direction (unused)*/ - double etilt; /**< error in the tilt determination */ -} angleConversionConstant; - - - class angularCalibration { public: @@ -155,7 +139,7 @@ class angularCalibration { int nmod; int nchmod; - angleConversionConstant *angConv; + angleConversionConstant angConv[MAXMOD*MAXDET]; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h b/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h index de9e3c3bc..89346f72f 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h @@ -49,7 +49,9 @@ class angularConversion : public virtual slsDetectorBase, public virtual angular //virtual int readAngularConversion(string fname)=0; - + using angularConversionStatic::writeAngularConversion; + using angularConversionStatic::readAngularConversion; + /** diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h index 201c09a49..45ce07c95 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h @@ -15,6 +15,7 @@ #include "angleConversionConstant.h" + //double angle(int ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction) @@ -147,12 +148,12 @@ class angularConversionStatic : public virtual slsDetectorDefs int registerAngleFunctionCallback(double (*fun)(double, double, double, double, double, double, double, int)) {angle = fun; return 0;}; - - private: - - double (*angle)(double, double, double, double, double, double, double, int); + + // private: + + }; #endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h~ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h~ index 05d2bf2de..201c09a49 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h~ +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h~ @@ -34,19 +34,14 @@ class containing the methods to set/unset the angular conversion and merge the d The angular conversion itself is defined by the angle() function defined in usersFunctions.cpp */ -class angularConversion -#ifndef MYROOT -: public virtual slsDetectorBase -#else -: public virtual slsDetectorDefs -#endif +class angularConversionStatic : public virtual slsDetectorDefs { public: /** default constructor */ - angularConversion(); + angularConversionStatic(); /** virtual destructor */ - virtual ~angularConversion(); + virtual ~angularConversionStatic(); @@ -92,12 +87,6 @@ class angularConversion */ static int writeAngularConversion(ofstream& ofs, int nmod, angleConversionConstant *angOff); - /** - pure virtual function - \param file name to be written (nmod and array of angular conversion constants default to the ones ot the slsDetector - */ - virtual int writeAngularConversion(string fname)=0; - /** sets the arrays of the merged data to 0. NB The array should be created with size nbins >= 360./getBinSize(); \param mp already merged postions @@ -108,20 +97,6 @@ class angularConversion \returns OK or FAIL */ static int resetMerging(double *mp, double *mv,double *me, int *mm, int nbins); - /** - sets the arrays of the merged data to 0. NB The array should be created with size >= 360./getBinSize(); - \param mp already merged postions - \param mv already merged data - \param me already merged errors (squared sum) - \param mm multiplicity of merged arrays - \returns OK or FAIL - */ - int resetMerging(double *mp, double *mv,double *me, int *mm); - - /** - creates the arrays for merging the data and sets them to 0. - */ - int resetMerging(); /** merge dataset @@ -141,30 +116,6 @@ class angularConversion static int addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int nchans, double binsize,int nb, int *badChanMask ); - /** - merge dataset - \param p1 angular positions of dataset - \param v1 data - \param e1 errors - \param mp already merged postions - \param mv already merged data - \param me already merged errors (squared sum) - \param mm multiplicity of merged arrays - \param badChanMask badchannelmask (if NULL does not correct for bad channels) - \returns OK or FAIL - */ - - int addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int *badChanMask); - /** - merge dataset - \param p1 angular positions of dataset - \param v1 data - \param e1 errors - \param badChanMask badchannelmask (if NULL does not correct for bad channels) - \returns OK or FAIL - */ - - int addToMerging(double *p1, double *v1, double *e1,int *badChanMask); /** calculates the "final" positions, data value and errors for the merged data @@ -177,307 +128,28 @@ class angularConversion */ static int finalizeMerging(double *mp, double *mv,double *me, int *mm, int nb); - /** - calculates the "final" positions, data value and errors for the merged data - \param mp already merged postions - \param mv already merged data - \param me already merged errors (squared sum) - \param mm multiplicity of merged arrays - \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) - */ - - int finalizeMerging(double *mp, double *mv,double *me, int *mm); - -/** - calculates the "final" positions, data value and errors for the merged data - \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) - */ - - int finalizeMerging(); - - - /** - set detector global offset - \param f global offset to be set - \returns actual global offset - */ - double setGlobalOffset(double f){return setAngularConversionParameter(GLOBAL_OFFSET,f);}; - - /** - set detector fine offset - \param f global fine to be set - \returns actual fine offset - */ - double setFineOffset(double f){return setAngularConversionParameter(FINE_OFFSET,f);}; - - /** - get detector fine offset - \returns actual fine offset - */ - double getFineOffset(){return getAngularConversionParameter(FINE_OFFSET);}; - - /** - get detector global offset - \returns actual global offset - */ - double getGlobalOffset(){return getAngularConversionParameter(GLOBAL_OFFSET);}; - - /** - - set detector bin size - \param bs bin size to be set - \returns actual bin size - */ - double setBinSize(double bs){if (bs>0) nBins=360/bs; return setAngularConversionParameter(BIN_SIZE,bs);}; - - /** - get detector bin size - \returns detector bin size used for merging (approx angular resolution) - */ - double getBinSize() {return getAngularConversionParameter(BIN_SIZE);}; - - - - /** - - get angular direction - \returns actual angular direction (1 is channel number increasing with angle, -1 decreasing) - */ - int getAngularDirection(){return (int)getAngularConversionParameter(ANGULAR_DIRECTION);}; - - - /** - - set angular direction - \param d angular direction to be set (1 is channel number increasing with angle, -1 decreasing) - \returns actual angular direction (1 is channel number increasing with angle, -1 decreasing) - */ - int setAngularDirection(int d){return (int)setAngularConversionParameter(ANGULAR_DIRECTION, (double)d);}; - - /** - \returns number of angular bins in the merging (360./binsize) - */ - int getNumberOfAngularBins(){return nBins;}; - - /** - get angular conversion - \param direction reference to diffractometer direction - \param angconv array that will be filled with the angular conversion constants - \returns 0 if angular conversion disabled, >0 otherwise - */ - virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0; - - - /** - set angular conversion parameter - \param c parameter type (globaloffset, fineoffset, binsize, angular direction, move flag) - \param v value to be set - \returns actual value - */ - double setAngularConversionParameter(angleConversionParameter c, double v); - /** - get angular conversion parameter - \param c parameter type (globaloffset, fineoffset, binsize, angular direction, move flag) - \returns actual value - */ - double getAngularConversionParameter(angleConversionParameter c); - - - - - /** - set positions for the acquisition - \param nPos number of positions - \param pos array with the encoder positions - \returns number of positions - */ - virtual int setPositions(int nPos, double *pos); - /** - get positions for the acquisition - \param pos array which will contain the encoder positions - \returns number of positions - */ - virtual int getPositions(double *pos=NULL); - - /** - deletes the array of merged data - \returns OK - */ - int deleteMerging(); - - /** - \returns pointer to the array o merged positions - */ - double *getMergedPositions(){return mergingBins;}; - /** - \returns pointer to the array of merged counts - */ - double *getMergedCounts(){return mergingCounts;}; - /** - \returns pointer to the array of merged errors - */ - double *getMergedErrors(){return mergingErrors;}; - - - - /** - sets the angular conversion file - \param fname file to read - \returns angular conversion flag - */ - - int setAngularConversionFile(string fname); - - - /** - returns the angular conversion file - */ - string getAngularConversionFile(){if (setAngularCorrectionMask()) return string(angConvFile); else return string("none");}; - - - /** - reads teh angular conversion file for the (multi)detector and writes it to shared memory - */ - virtual int readAngularConversionFile(string fname="")=0; - - - - - - /** - \returns number of modules of the (multi)detector - */ - virtual int getNMods()=0; - - /** - returns number of channels in the module - \param imod module number - \returns number of channels in the module - */ - virtual int getChansPerMod(int imod=0)=0; - - /** - get the angular conversion contant of one modules - \param imod module number - \returns pointer to the angular conversion constant - */ - virtual angleConversionConstant *getAngularConversionPointer(int imod=0)=0; - /** converts channel number to angle \param pos encoder position \returns array of angles corresponding to the channels */ - double* convertAngles(double pos){return convertAngles(pos, getTotalNumberOfChannels());} - - double* convertAngles(double pos, int nch); - - /** - converts channel number to angle for the current encoder position - \returns array of angles corresponding to the channels - */ - double *convertAngles(){return convertAngles(currentPosition);}; - - /** - \param imod module number - \returns move flag of the module (1 encoder is added to the angle, 0 not) - Shold be module dependent! - */ - virtual int getMoveFlag(int imod)=0; - - /** - returns number of positions - */ - int getNumberOfPositions() {return *numberOfPositions;}; + double* convertAngles(double pos, int nch, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir); protected: - /** pointer to number of positions for the acquisition*/ - int *numberOfPositions; - - /** pointer to the detector positions for the acquisition*/ - double *detPositions; - - /** pointer to angular conversion file name*/ - char *angConvFile; - - /** pointer to angular bin size*/ - double *binSize; - - /** pointer to beamlien fine offset*/ - double *fineOffset; - /** pointer to beamlien global offset*/ - double *globalOffset; - /** pointer to beamlien angular direction*/ - int *angDirection; - /** pointer to detector move flag (1 moves with encoder, 0 not)*/ - int *moveFlag; - - /** number of bins for angular conversion (360./binsize)*/ - int nBins; - - - - /** - current position of the detector - */ - double currentPosition; - /** - current position index of the detector - */ - int currentPositionIndex; - - - /** - enables/disable the angular conversion - \param i 1 sets, 0 unsets,, -1 gets - \returns actual angular conversion flag - */ - virtual int setAngularCorrectionMask(int i=-1)=0; - - /** - returns current position index - */ - int getCurrentPositionIndex() {return currentPositionIndex;}; - void incrementPositionIndex() {currentPositionIndex++;}; - - - void registerAngleFunctionCallback(double( *fun)(double, double, double, double, double, double, double, int)) {angle = fun;}; + int registerAngleFunctionCallback(double (*fun)(double, double, double, double, double, double, double, int)) {angle = fun; return 0;}; private: - - - - // int nChans; - // int nMods; - // int chansPerMod; - // int moveFlag; - - - - - - /** merging bins */ - double *mergingBins; - - /** merging counts */ - double *mergingCounts; - - /** merging errors */ - double *mergingErrors; - - /** merging multiplicity */ - int *mergingMultiplicity; double (*angle)(double, double, double, double, double, double, double, int); diff --git a/slsDetectorSoftware/slsDetectorAnalysis/badChannelCorrections.h b/slsDetectorSoftware/slsDetectorAnalysis/badChannelCorrections.h new file mode 100644 index 000000000..d9101526b --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/badChannelCorrections.h @@ -0,0 +1,59 @@ +#ifndef BAD_CHANNEL_CORRECTIONS_H +#define BAD_CHANNEL_CORRECTIONS_H + + +#include +#include +#include + +using namespace std; +class badChannelCorrections{ + + public: + + + + static int readBadChannelCorrectionFile(ifstream &infile, int &nbad, int *badlist, int moff=0){ \ + int interrupt=0; \ + int ich; \ + int chmin,chmax; \ + string str; \ + nbad=0; \ + while (infile.good() and interrupt==0) { \ + getline(infile,str); \ + istringstream ssstr; \ + ssstr.str(str); \ + if (ssstr.bad() || ssstr.fail() || infile.eof()) { \ + interrupt=1; \ + break; \ + } \ + if (str.find('-')!=string::npos) { \ + ssstr >> chmin ; \ + ssstr.str(str.substr(str.find('-')+1,str.size())); \ + ssstr >> chmax; \ + for (ich=chmin; ich<=chmax; ich++) { \ + badlist[nbad]=ich; \ + nbad++; \ + } \ + } else { \ + ssstr >> ich; \ + badlist[nbad]=ich; \ + nbad++; \ + } \ + } \ + return nbad; }; + + protected: + + + char *badChanFile; + int *nBadChans; + int *badChansList; + int *nBadFF; + int *badFFList; + + + + +}; +#endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index d7d6b1867..2f91b98ba 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -66,69 +66,6 @@ int postProcessing::flatFieldCorrect(double datain, double errin, double &dataou -int postProcessing::setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff){ - - int interrupt=0; - int ich; - int chmin,chmax; - string str; - - - - nbad=0; - while (infile.good() and interrupt==0) { - getline(infile,str); -#ifdef VERBOSE - std::cout << str << std::endl; -#endif - istringstream ssstr; - ssstr.str(str); - if (ssstr.bad() || ssstr.fail() || infile.eof()) { - interrupt=1; - break; - } - if (str.find('-')!=string::npos) { - ssstr >> chmin ; - ssstr.str(str.substr(str.find('-')+1,str.size())); - ssstr >> chmax; -#ifdef VERBOSE - std::cout << "channels between"<< chmin << " and " << chmax << std::endl; -#endif - for (ich=chmin; ich<=chmax; ich++) { - if (nbad> ich; -#ifdef VERBOSE - std::cout << "channel "<< ich << std::endl; -#endif - if (nbad @@ -20,7 +21,7 @@ using namespace std; -#define MAX_BADCHANS 2000 +#define MAX_BADCHANS 20000 #define defaultTDead {170,90,750} /**< should be changed in order to have it separate for the different detector types */ @@ -32,7 +33,7 @@ using namespace std; (including thread for writing data files and plotting in parallel with the acquisition) */ -class postProcessing : public angularConversion, public fileIO { +class postProcessing : public angularConversion, public fileIO, public badChannelCorrections { //public virtual angularConversion, public virtual fileIO { @@ -73,8 +74,9 @@ class postProcessing : public angularConversion, public fileIO { \returns 0 if bad channel disabled, >0 otherwise */ virtual int setBadChannelCorrection(string fname="")=0; - - static int setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff=0); + + static int setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff){int retval=readBadChannelCorrectionFile(infile,nbad,badlist); for (int ich=0; ich