From 6b34cb8e7101c1480ffd33bf4b6f2d6d2684e2b7 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Wed, 5 Sep 2012 10:12:49 +0000 Subject: [PATCH] AngularConversion splitted in a static file and in one file dependent on slsDetectorBase git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@240 951219d9-93cf-4727-9268-0efd64621fa3 --- slsDetectorSoftware/Makefile | 4 +- .../slsDetectorAnalysis/angCalLogClass.h | 133 ++++- .../angleConversionConstant.h | 19 + .../slsDetectorAnalysis/angularConversion.cpp | 273 +-------- .../slsDetectorAnalysis/angularConversion.h | 124 ++--- .../angularConversionStatic.cpp | 268 +++++++++ .../angularConversionStatic.cpp~ | 526 ++++++++++++++++++ .../angularConversionStatic.h | 158 ++++++ .../angularConversionStatic.h~ | 486 ++++++++++++++++ .../angularConversionStatic.o | Bin 0 -> 11384 bytes .../slsDetectorAnalysis/enCalLogClass.h | 1 - .../slsDetectorAnalysis/fileIOStatic.h | 6 +- .../usersFunctions/angleFunction.h | 13 +- .../usersFunctions/usersFunctions.h | 5 +- 14 files changed, 1636 insertions(+), 380 deletions(-) create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/angleConversionConstant.h create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.cpp create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.cpp~ create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h~ create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.o diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index e858bf7b5..bd00444a5 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -9,11 +9,11 @@ INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsD CC=g++ -SRC_CLNT= slsDetectorAnalysis/fileIO.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/angularConversion.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp +SRC_CLNT= slsDetectorAnalysis/fileIO.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/angularConversion.cpp slsDetectorAnalysis/angularConversionStatic.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp OBJS = $(SRC_CLNT:.cpp=.o) -HEADERS = $(SRC_CLNT:.cpp=.h) commonFiles/sls_detector_defs.h slsDetectorAnalysis/detectorData.h slsDetector/slsDetectorBase.h slsDetector/slsDetectorUsers.h multiSlsDetector/multiSlsDetectorCommand.h slsDetectorAnalysis/enCalLogClass.h slsDetectorAnalysis/angCalLogClass.h +HEADERS = $(SRC_CLNT:.cpp=.h) commonFiles/sls_detector_defs.h slsDetectorAnalysis/detectorData.h slsDetector/slsDetectorBase.h slsDetector/slsDetectorUsers.h multiSlsDetector/multiSlsDetectorCommand.h slsDetectorAnalysis/enCalLogClass.h slsDetectorAnalysis/angCalLogClass.h slsDetectorAnalysis/angleConversionConstant.h usersFunctions/angleFunction.h diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angCalLogClass.h b/slsDetectorSoftware/slsDetectorAnalysis/angCalLogClass.h index 7b56af02e..120e0b2cd 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/angCalLogClass.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/angCalLogClass.h @@ -3,9 +3,15 @@ #include #include +#ifdef __CINT__ +#define MYROOT +#endif + +#ifndef MYROOT #include "slsDetectorCommand.h" #include "slsDetectorUtils.h" #include "sls_detector_defs.h" +#endif using namespace std; @@ -15,45 +21,128 @@ class angCalLogClass { public: - angCalLogClass(slsDetectorUtils *det){ \ - char cmd[1000]; +#ifndef MYROOT + angCalLogClass(slsDetectorUtils *det){ createVars(); + char cmd[1000]; \ char *argv[2]; \ argv[0]=cmd; \ sprintf(cmd,"_%d.angcal",det->getFileIndex()); \ outfile.open(string(det->getFilePath()+string("/")+det->getFileName()+string(cmd)).c_str()); \ myDet=new slsDetectorCommand(det); \ - strcpy(cmd,"type"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ - strcpy(cmd,"nmod"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ - strcpy(cmd,"angconv"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ - strcpy(cmd,"globaloff"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ - strcpy(cmd,"fineoff"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ - strcpy(cmd,"angdir"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ - strcpy(cmd,"ffdir"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ - strcpy(cmd,"flatfield"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ - strcpy(cmd,"badchannels"); \ - outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + if (outfile.is_open()) { \ + for (int iv=0; ivexecuteLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + }; \ + }; \ }; - ~angCalLogClass(){delete myDet; outfile.close();}; +#else + angCalLogClass() { createVars(); }; + ~angCalLogClass(){}; +#endif + int addStep(double pos, string fname) {outfile << pos << " " << fname << endl; return 0;}; + // + + int readHeader(ifstream &infile, char *settings, int &maxmod, int &nmod, int &chanspermod, char *angconvfile, double &globaloff, double &fineoff, int &angdir, char *ffdir, char *fffile, char *badfile ) { \ + nmod=0; chanspermod=0; globaloff=0; fineoff=0; angdir=1; \ + strcpy(angconvfile,"none"); strcpy(ffdir,"none"); strcpy(fffile,"none"); strcpy(badfile,"none"); \ + char line[1000], myvar[100], myarg[100]; \ + int dum; \ + float v; \ + for (int iv=0; iv #include #include -#include "usersFunctions.h" + using namespace std; -angularConversion::angularConversion(): currentPosition(0), - currentPositionIndex(0) +angularConversion::angularConversion(): angularConversionStatic(), currentPosition(0), + currentPositionIndex(0) + { //angleFunctionPointer=0; - registerAngleFunctionCallback(&defaultAngleFunction); + // registerAngleFunctionCallback(&defaultAngleFunction); } @@ -20,267 +21,33 @@ angularConversion::~angularConversion(){ } -// int angularConversion::setAngularConversionPointer(angleConversionConstant *p, int *nm, int nch, int idet) { -// if (p) { -// angOff[idet]=p; -// nMods[idet]=nm; -// nCh[idet]=nch; -// } else { -// angOff[idet]=NULL; -// nMods[idet]=NULL; -// } - -// return OK; -// } - double* angularConversion::convertAngles(double pos) { - int imod=0; - double *ang=new double[getTotalNumberOfChannels()]; - double enc=pos; - angleConversionConstant *p=NULL; - - int ch0=0; - int chlast=getChansPerMod(0); - int nchmod=getChansPerMod(0); - p=getAngularConversionPointer(imod); - if (getMoveFlag(imod)==0) - enc=0; - else - enc=pos; - - for (int ip=0; ip=chlast) { - imod++; - p=getAngularConversionPointer(imod); - if (getMoveFlag(imod)==0) - enc=0; - else - enc=pos; - - ch0=chlast; - nchmod=getChansPerMod(imod); - if (nchmod>0) - chlast+=nchmod; - } - - if (p) - ang[ip]=angle(ip-ch0, \ - enc, \ - (*fineOffset)+(*globalOffset), \ - p->r_conversion, \ - p->center, \ - p->offset, \ - p->tilt, \ - *angDirection ); - } - return ang; -} - - - -//static! -int angularConversion::readAngularConversion(string fname, int nmod, angleConversionConstant *angOff) { - - ifstream infile; - string ss; - -#ifdef VERBOSE - std::cout<< "Opening file "<< fname << std::endl; -#endif - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { - readAngularConversion(infile, nmod, angOff); - infile.close(); - } else { - std::cout<< "Could not open calibration file "<< fname << std::endl; - return -1; - } - return 0; -} - - -//static -int angularConversion::readAngularConversion( ifstream& infile, int nmod, angleConversionConstant *angOff) { - string str; - int mod; - double center, ecenter; - double r_conv, er_conv; - double off, eoff; - string ss; - int interrupt=0; - int nm=0; - //" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n" - while (infile.good() and interrupt==0) { - getline(infile,str); -#ifdef VERBOSE - cout << "** mod " << nm << " " ; - std::cout<< str << std::endl; -#endif - istringstream ssstr(str); - ssstr >> ss >> mod; - ssstr >> ss >> center; - ssstr >> ss >> ecenter; - ssstr >> ss >> r_conv; - ssstr >> ss >> er_conv; - ssstr >> ss >> off; - ssstr >> ss >> eoff; - if (nm=0 ) { - angOff[nm].center=center; - angOff[nm].r_conversion=r_conv; - angOff[nm].offset=off; - angOff[nm].ecenter=ecenter; - angOff[nm].er_conversion=er_conv; - angOff[nm].eoffset=eoff; - } else - break; - //cout << nm<<" " << angOff[nm].offset << endl; - nm++; - if (nm>=nmod) - break; + int nmod=getNMods(); + int *chansPerMod=new int[nmod]; + angleConversionConstant **angOff=new angleConversionConstant*[nmod]; + int *mF=new int[nmod]; + double fo=*fineOffset; + double go=*globalOffset; + int angdir=*angDirection; + for (int im=0; im0) { - -#ifdef VERBOSE - cout << "finalize " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl; -#endif - mp[np]=mp[ibin]/mm[ibin]; - mv[np]=mv[ibin]/mm[ibin]; - me[np]=me[ibin]/mm[ibin]; - me[np]=sqrt(me[ibin]); - mm[np]=mm[ibin]; - np++; - } - } - return np; -} - -//static -int angularConversion::addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int nchans, double binsize,int nbins, int *badChanMask ) { - - - double binmi=-180.; - int ibin=0; - - if (p1==NULL) - return 0; - if (v1==NULL) - return FAIL; - - if (mp==NULL) //can be changed if we want to use a fixed bin algorithm! - return FAIL; - - if (mv==NULL) - return FAIL; - if (me==NULL) - return FAIL; - if (mm==NULL) - return FAIL; - if (nchans==0) - return FAIL; - - if (binsize<=0) - return FAIL; - - if (nbins<=0) - return FAIL; - - for (int ip=0; ip=0) { - mp[ibin]+=p1[ip]; - mv[ibin]+=v1[ip]; - if (e1) - me[ibin]+=(e1[ip]*e1[ip]); - else - me[ibin]+=v1[ip]; - mm[ibin]++; - -#ifdef VERBOSE - cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl; -#endif - } else - return FAIL; - } - - - return OK; - -} int angularConversion::deleteMerging() { @@ -317,7 +84,7 @@ int angularConversion::resetMerging() { int angularConversion::resetMerging(double *mp, double *mv, double *me, int *mm) { getAngularConversionParameter(BIN_SIZE); if (nBins) - return resetMerging(mp, mv, me, mm,nBins); + return angularConversionStatic::resetMerging(mp, mv, me, mm,nBins); else return FAIL; } @@ -340,7 +107,7 @@ int angularConversion::finalizeMerging() { int angularConversion::finalizeMerging(double *mp, double *mv, double *me, int *mm) { if (nBins) - return finalizeMerging(mp, mv, me, mm, nBins); + return angularConversionStatic::finalizeMerging(mp, mv, me, mm, nBins); else return FAIL; } @@ -373,7 +140,7 @@ int angularConversion::addToMerging(double *p1, double *v1, double *e1, double } - int ret=addToMerging(p1, v1, e1, mp, mv,me, mm,getTotalNumberOfChannels(), *binSize,nBins, badChanMask ); + int ret=angularConversionStatic::addToMerging(p1, v1, e1, mp, mv,me, mm,getTotalNumberOfChannels(), *binSize,nBins, badChanMask ); if (del) { diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h b/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h index 212e583a2..de9e3c3bc 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h @@ -2,12 +2,19 @@ #ifndef ANGULARCONVERSION_H #define ANGULARCONVERSION_H +#ifdef __CINT +#define MYROOT +#endif +#ifndef MYROOT #include "slsDetectorBase.h" +#else +#include "sls_detector_defs.h" +#endif #include #include - +#include "angularConversionStatic.h" //double angle(int ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction) @@ -17,16 +24,6 @@ using namespace std; /** @short Angular conversion constants needed for a detector 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; /** @@ -38,7 +35,9 @@ 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 : public virtual slsDetectorBase { +class angularConversion : public virtual slsDetectorBase, public virtual angularConversionStatic + +{ public: /** default constructor */ @@ -53,59 +52,11 @@ class angularConversion : public virtual slsDetectorBase { - /** - - reads an angular conversion file - \param fname file to be read - \param nmod number of modules (maximum) to be read - \param angOff pointer to array of angleConversionConstants - \returns OK or FAIL - */ - static int readAngularConversion(string fname, int nmod, angleConversionConstant *angOff); - - /** - reads an angular conversion file - \param ifstream input file stream to be read - \param nmod number of modules (maximum) to be read - \param angOff pointer to array of angleConversionConstants - \returns OK or FAIL - - */ - static int readAngularConversion(ifstream& ifs, int nmod, angleConversionConstant *angOff); - /** - writes an angular conversion file - \param fname file to be written - \param nmod number of modules to be written - \param angOff pointer to array of angleConversionConstants - \returns OK or FAIL - */ - static int writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff); - - /** - writes an angular conversion file - \param ofstream output file stream - \param nmod number of modules to be written - \param angOff pointer to array of angleConversionConstants - \returns OK or FAIL - */ - 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 - \param mv already merged data - \param me already merged errors (squared sum) - \param mm multiplicity of merged arrays - \param nbins number of bins - \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 @@ -121,23 +72,6 @@ class angularConversion : public virtual slsDetectorBase { */ int resetMerging(); - /** - 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 nchans number of channels - \param binsize size of angular bin - \param nb number of angular bins - \param badChanMask badchannelmask (if NULL does not correct for bad channels) - \returns OK or FAIL - */ - - 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 @@ -164,17 +98,6 @@ class angularConversion : public virtual slsDetectorBase { int addToMerging(double *p1, double *v1, double *e1,int *badChanMask); - /** - 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 - \param nb number of bins - \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) - */ - - 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 @@ -368,6 +291,9 @@ class angularConversion : public virtual slsDetectorBase { \returns array of angles corresponding to the channels */ double* convertAngles(double pos); + + + /** converts channel number to angle for the current encoder position \returns array of angles corresponding to the channels @@ -377,6 +303,7 @@ class angularConversion : public virtual slsDetectorBase { /** \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; @@ -385,8 +312,11 @@ class angularConversion : public virtual slsDetectorBase { */ int getNumberOfPositions() {return *numberOfPositions;}; + + protected: + /** pointer to number of positions for the acquisition*/ int *numberOfPositions; @@ -439,11 +369,21 @@ class angularConversion : public virtual slsDetectorBase { - void registerAngleFunctionCallback(double( *fun)(double, double, double, double, double, double, double, int)) {angle = fun;}; - - private: + + + + + // int nChans; + // int nMods; + // int chansPerMod; + // int moveFlag; + + + + + /** merging bins */ double *mergingBins; @@ -456,8 +396,6 @@ class angularConversion : public virtual slsDetectorBase { /** merging multiplicity */ int *mergingMultiplicity; - double (*angle)(double, double, double, double, double, double, double, int); - }; #endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.cpp b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.cpp new file mode 100644 index 000000000..e6a1bf832 --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.cpp @@ -0,0 +1,268 @@ +#include "angularConversionStatic.h" + +#include +#include +#include +#include + +#include "angleFunction.h" +using namespace std; + +angularConversionStatic::angularConversionStatic() +{ + //angleFunctionPointer=0; + registerAngleFunctionCallback(&defaultAngleFunction); + +} + +angularConversionStatic::~angularConversionStatic(){ + +} + + + +double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir) { + int imod=0; + double *ang=new double[nch]; + double enc=pos; + angleConversionConstant *p=NULL; + + int ch0=0; + int chlast=chansPerMod[0]; + int nchmod=chansPerMod[0]; + p=angOff[imod]; + if (mF[imod]==0) + enc=0; + else + enc=pos; + + for (int ip=0; ip=chlast) { + imod++; + p=angOff[imod]; + if (mF[imod]==0) + enc=0; + else + enc=pos; + + ch0=chlast; + nchmod=chansPerMod[imod]; + if (nchmod>0) + chlast+=nchmod; + } + + if (p) + ang[ip]=angle(ip-ch0, \ + enc, \ + fo+go, \ + p->r_conversion, \ + p->center, \ + p->offset, \ + p->tilt, \ + angdir ); + } + return ang; +} + + + +//static! +int angularConversionStatic::readAngularConversion(string fname, int nmod, angleConversionConstant *angOff) { + + ifstream infile; + string ss; + +#ifdef VERBOSE + std::cout<< "Opening file "<< fname << std::endl; +#endif + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()) { + readAngularConversion(infile, nmod, angOff); + infile.close(); + } else { + std::cout<< "Could not open calibration file "<< fname << std::endl; + return -1; + } + return 0; +} + + +//static +int angularConversionStatic::readAngularConversion( ifstream& infile, int nmod, angleConversionConstant *angOff) { + string str; + int mod; + double center, ecenter; + double r_conv, er_conv; + double off, eoff; + string ss; + int interrupt=0; + int nm=0; + //" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n" + while (infile.good() and interrupt==0) { + getline(infile,str); +#ifdef VERBOSE + cout << "** mod " << nm << " " ; + std::cout<< str << std::endl; +#endif + istringstream ssstr(str); + ssstr >> ss >> mod; + ssstr >> ss >> center; + ssstr >> ss >> ecenter; + ssstr >> ss >> r_conv; + ssstr >> ss >> er_conv; + ssstr >> ss >> off; + ssstr >> ss >> eoff; + if (nm=0 ) { + angOff[nm].center=center; + angOff[nm].r_conversion=r_conv; + angOff[nm].offset=off; + angOff[nm].ecenter=ecenter; + angOff[nm].er_conversion=er_conv; + angOff[nm].eoffset=eoff; + } else + break; + //cout << nm<<" " << angOff[nm].offset << endl; + nm++; + if (nm>=nmod) + break; + + + + + } + return nm; + } + +//static +int angularConversionStatic:: writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff) { + + ofstream outfile; + outfile.open (fname.c_str(),ios_base::out); + if (outfile.is_open()) + { + writeAngularConversion(outfile, nmod, angOff); + outfile.close(); + } else { + std::cout<< "Could not open file " << fname << "for writing"<< std::endl; + return -1; + } + //" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n" + return 0; +} + + + +//static +int angularConversionStatic:: writeAngularConversion(ofstream& outfile, int nmod, angleConversionConstant *angOff) { + + for (int imod=0; imod0) { + +#ifdef VERBOSE + cout << "finalize " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl; +#endif + mp[np]=mp[ibin]/mm[ibin]; + mv[np]=mv[ibin]/mm[ibin]; + me[np]=me[ibin]/mm[ibin]; + me[np]=sqrt(me[ibin]); + mm[np]=mm[ibin]; + np++; + } + } + return np; +} + +//static +int angularConversionStatic::addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int nchans, double binsize,int nbins, int *badChanMask ) { + + + double binmi=-180.; + int ibin=0; + + if (p1==NULL) + return 0; + if (v1==NULL) + return FAIL; + + if (mp==NULL) //can be changed if we want to use a fixed bin algorithm! + return FAIL; + + if (mv==NULL) + return FAIL; + if (me==NULL) + return FAIL; + if (mm==NULL) + return FAIL; + if (nchans==0) + return FAIL; + + if (binsize<=0) + return FAIL; + + if (nbins<=0) + return FAIL; + + for (int ip=0; ip=0) { + mp[ibin]+=p1[ip]; + mv[ibin]+=v1[ip]; + if (e1) + me[ibin]+=(e1[ip]*e1[ip]); + else + me[ibin]+=v1[ip]; + mm[ibin]++; + +#ifdef VERBOSE + cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl; +#endif + } else + return FAIL; + } + + + return OK; + +} diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.cpp~ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.cpp~ new file mode 100644 index 000000000..2466b0baf --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.cpp~ @@ -0,0 +1,526 @@ +#include "angularConversion.h" + +#include +#include +#include +#include +#ifndef MYROOT +#include "usersFunctions.h" + +#endif +#include "angleFunction.h" +using namespace std; + +angularConversion::angularConversion(): currentPosition(0), + currentPositionIndex(0) +{ + //angleFunctionPointer=0; + registerAngleFunctionCallback(&defaultAngleFunction); + +} + +angularConversion::~angularConversion(){ + +} + +// int angularConversion::setAngularConversionPointer(angleConversionConstant *p, int *nm, int nch, int idet) { +// if (p) { +// angOff[idet]=p; +// nMods[idet]=nm; +// nCh[idet]=nch; +// } else { +// angOff[idet]=NULL; +// nMods[idet]=NULL; +// } + +// return OK; +// } + + + + +double* angularConversion::convertAngles(double pos, int nch) { + int imod=0; + double *ang=new double[nch]; + double enc=pos; + angleConversionConstant *p=NULL; + + int ch0=0; + int chlast=getChansPerMod(0); + int nchmod=getChansPerMod(0); + p=getAngularConversionPointer(imod); + if (getMoveFlag(imod)==0) + enc=0; + else + enc=pos; + + for (int ip=0; ip=chlast) { + imod++; + p=getAngularConversionPointer(imod); + if (getMoveFlag(imod)==0) + enc=0; + else + enc=pos; + + ch0=chlast; + nchmod=getChansPerMod(imod); + if (nchmod>0) + chlast+=nchmod; + } + + if (p) + ang[ip]=angle(ip-ch0, \ + enc, \ + (*fineOffset)+(*globalOffset), \ + p->r_conversion, \ + p->center, \ + p->offset, \ + p->tilt, \ + *angDirection ); + } + return ang; +} + + + +//static! +int angularConversion::readAngularConversion(string fname, int nmod, angleConversionConstant *angOff) { + + ifstream infile; + string ss; + +#ifdef VERBOSE + std::cout<< "Opening file "<< fname << std::endl; +#endif + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()) { + readAngularConversion(infile, nmod, angOff); + infile.close(); + } else { + std::cout<< "Could not open calibration file "<< fname << std::endl; + return -1; + } + return 0; +} + + +//static +int angularConversion::readAngularConversion( ifstream& infile, int nmod, angleConversionConstant *angOff) { + string str; + int mod; + double center, ecenter; + double r_conv, er_conv; + double off, eoff; + string ss; + int interrupt=0; + int nm=0; + //" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n" + while (infile.good() and interrupt==0) { + getline(infile,str); +#ifdef VERBOSE + cout << "** mod " << nm << " " ; + std::cout<< str << std::endl; +#endif + istringstream ssstr(str); + ssstr >> ss >> mod; + ssstr >> ss >> center; + ssstr >> ss >> ecenter; + ssstr >> ss >> r_conv; + ssstr >> ss >> er_conv; + ssstr >> ss >> off; + ssstr >> ss >> eoff; + if (nm=0 ) { + angOff[nm].center=center; + angOff[nm].r_conversion=r_conv; + angOff[nm].offset=off; + angOff[nm].ecenter=ecenter; + angOff[nm].er_conversion=er_conv; + angOff[nm].eoffset=eoff; + } else + break; + //cout << nm<<" " << angOff[nm].offset << endl; + nm++; + if (nm>=nmod) + break; + + + + + } + return nm; + } + +//static +int angularConversion:: writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff) { + + ofstream outfile; + outfile.open (fname.c_str(),ios_base::out); + if (outfile.is_open()) + { + writeAngularConversion(outfile, nmod, angOff); + outfile.close(); + } else { + std::cout<< "Could not open file " << fname << "for writing"<< std::endl; + return -1; + } + //" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n" + return 0; +} + + + +//static +int angularConversion:: writeAngularConversion(ofstream& outfile, int nmod, angleConversionConstant *angOff) { + + for (int imod=0; imod0) { + +#ifdef VERBOSE + cout << "finalize " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl; +#endif + mp[np]=mp[ibin]/mm[ibin]; + mv[np]=mv[ibin]/mm[ibin]; + me[np]=me[ibin]/mm[ibin]; + me[np]=sqrt(me[ibin]); + mm[np]=mm[ibin]; + np++; + } + } + return np; +} + +//static +int angularConversion::addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int nchans, double binsize,int nbins, int *badChanMask ) { + + + double binmi=-180.; + int ibin=0; + + if (p1==NULL) + return 0; + if (v1==NULL) + return FAIL; + + if (mp==NULL) //can be changed if we want to use a fixed bin algorithm! + return FAIL; + + if (mv==NULL) + return FAIL; + if (me==NULL) + return FAIL; + if (mm==NULL) + return FAIL; + if (nchans==0) + return FAIL; + + if (binsize<=0) + return FAIL; + + if (nbins<=0) + return FAIL; + + for (int ip=0; ip=0) { + mp[ibin]+=p1[ip]; + mv[ibin]+=v1[ip]; + if (e1) + me[ibin]+=(e1[ip]*e1[ip]); + else + me[ibin]+=v1[ip]; + mm[ibin]++; + +#ifdef VERBOSE + cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl; +#endif + } else + return FAIL; + } + + + return OK; + +} + +int angularConversion::deleteMerging() { + + if (mergingBins) + delete [] mergingBins; + + if (mergingCounts) + delete [] mergingCounts; + + if (mergingErrors) + delete [] mergingErrors; + +} + + +int angularConversion::resetMerging() { + getAngularConversionParameter(BIN_SIZE); + + mergingBins=new double[nBins]; + + + mergingCounts=new double[nBins]; + + + mergingErrors=new double[nBins]; + + + mergingMultiplicity=new int[nBins]; + + return resetMerging(mergingBins, mergingCounts, mergingErrors, mergingMultiplicity); + +} + +int angularConversion::resetMerging(double *mp, double *mv, double *me, int *mm) { + getAngularConversionParameter(BIN_SIZE); + if (nBins) + return resetMerging(mp, mv, me, mm,nBins); + else + return FAIL; +} + + + + +int angularConversion::finalizeMerging() { + int np=finalizeMerging(mergingBins, mergingCounts, mergingErrors, mergingMultiplicity); + + if (mergingMultiplicity) + delete [] mergingMultiplicity; + + return np; + +} + + + + +int angularConversion::finalizeMerging(double *mp, double *mv, double *me, int *mm) { + if (nBins) + return finalizeMerging(mp, mv, me, mm, nBins); + else + return FAIL; +} + +int angularConversion::addToMerging(double *p1, double *v1, double *e1, int *badChanMask ) { + + return addToMerging(p1,v1,e1,mergingBins,mergingCounts, mergingErrors, mergingMultiplicity, badChanMask); + + +} + + +int angularConversion::addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int *badChanMask ) { + + int del=0; + + if (getAngularConversionParameter(BIN_SIZE)==0){ + cout << "no bin size " << endl; + return FAIL; + } + + if (nBins==0) { + cout << "no bins " << endl; + return FAIL; + } + + if (p1==NULL) { + del=1; + p1=convertAngles(); + } + + + int ret=addToMerging(p1, v1, e1, mp, mv,me, mm,getTotalNumberOfChannels(), *binSize,nBins, badChanMask ); + + + if (del) { + delete [] p1; + p1=NULL; + } + return ret; +} + + + + /** + sets the value of s angular conversion parameter + \param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE + \param v the value to be set + \returns the actual value + */ + +double angularConversion::setAngularConversionParameter(angleConversionParameter c, double v){ + + + switch (c) { + case ANGULAR_DIRECTION: + if (v<0) + *angDirection=-1; + else + *angDirection=1; + return *angDirection; + case GLOBAL_OFFSET: + *globalOffset=v; + return *globalOffset; + case FINE_OFFSET: + *fineOffset=v; + return *fineOffset; + case BIN_SIZE: + if (v>0) { + *binSize=v; + nBins=360./(*binSize); + } + return *binSize; + case MOVE_FLAG: + if (moveFlag) { + if (v>0) + *moveFlag=1; + else if (v==0) + *moveFlag=0; + return *moveFlag; + } + return -1; + default: + return 0; + } +} + + /** + returns the value of an angular conversion parameter + \param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE + \returns the actual value + + */ + +double angularConversion::getAngularConversionParameter(angleConversionParameter c) { + + switch (c) { + case ANGULAR_DIRECTION: + return *angDirection; + case GLOBAL_OFFSET: + return *globalOffset; + case FINE_OFFSET: + return *fineOffset; + case BIN_SIZE: + if (*binSize>0) + nBins=360./(*binSize); + else + nBins=0; + return *binSize; + case MOVE_FLAG: + if (moveFlag) + return *moveFlag; + else + return -1; + default: + return 0; + } +} + + + + +int angularConversion::setAngularConversionFile(string fname) { + if (fname=="") { + setAngularCorrectionMask(0); +#ifdef VERBOSE + std::cout << "Unsetting angular conversion" << std::endl; +#endif + } else { + if (fname=="default") { + fname=string(angConvFile); + } + +#ifdef VERBOSE + std::cout << "Setting angular conversion to " << fname << std:: endl; +#endif + if (readAngularConversionFile(fname)>=0) { + setAngularCorrectionMask(1); + strcpy(angConvFile,fname.c_str()); + } + } + return setAngularCorrectionMask(); +} + + + + + + /* + set positions for the acquisition + \param nPos number of positions + \param pos array with the encoder positions + \returns number of positions + */ +int angularConversion::setPositions(int nPos, double *pos){ + if (nPos>=0) + *numberOfPositions=nPos; + for (int ip=0; ip +#include + +#include "angleConversionConstant.h" + + //double angle(int ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction) + + +using namespace std; + +/** + @short Angular conversion constants needed for a detector module + */ + + +/** + +@short methods to set/unset the angular conversion and merge the data +class containing the methods to set/unset the angular conversion and merge the data + + +The angular conversion itself is defined by the angle() function defined in usersFunctions.cpp + +*/ +class angularConversionStatic : public virtual slsDetectorDefs +{ + + public: + /** default constructor */ + angularConversionStatic(); + /** virtual destructor */ + virtual ~angularConversionStatic(); + + + + //virtual int readAngularConversion(string fname)=0; + + + + + /** + + reads an angular conversion file + \param fname file to be read + \param nmod number of modules (maximum) to be read + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + */ + static int readAngularConversion(string fname, int nmod, angleConversionConstant *angOff); + + /** + reads an angular conversion file + \param ifstream input file stream to be read + \param nmod number of modules (maximum) to be read + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + + */ + static int readAngularConversion(ifstream& ifs, int nmod, angleConversionConstant *angOff); + /** + writes an angular conversion file + \param fname file to be written + \param nmod number of modules to be written + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + */ + static int writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff); + + /** + writes an angular conversion file + \param ofstream output file stream + \param nmod number of modules to be written + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + */ + static int writeAngularConversion(ofstream& ofs, int nmod, angleConversionConstant *angOff); + + /** + 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 + \param mv already merged data + \param me already merged errors (squared sum) + \param mm multiplicity of merged arrays + \param nbins number of bins + \returns OK or FAIL + */ + static int resetMerging(double *mp, double *mv,double *me, int *mm, int nbins); + + /** + 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 nchans number of channels + \param binsize size of angular bin + \param nb number of angular bins + \param badChanMask badchannelmask (if NULL does not correct for bad channels) + \returns OK or FAIL + */ + + 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 ); + + + /** + 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 + \param nb number of bins + \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) + */ + + static int finalizeMerging(double *mp, double *mv,double *me, int *mm, int nb); + + /** + converts channel number to angle + \param pos encoder position + \returns array of angles corresponding to the channels + */ + + double* convertAngles(double pos, int nch, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir); + + + + protected: + + + + + 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); + +}; + +#endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h~ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h~ new file mode 100644 index 000000000..05d2bf2de --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.h~ @@ -0,0 +1,486 @@ + +#ifndef ANGULARCONVERSIONSTATIC_H +#define ANGULARCONVERSIONSTATIC_H + +#ifdef __CINT +#define MYROOT +#endif + + +#include "sls_detector_defs.h" + + +#include +#include + +#include "angleConversionConstant.h" + + //double angle(int ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction) + + +using namespace std; + +/** + @short Angular conversion constants needed for a detector module + */ + + +/** + +@short methods to set/unset the angular conversion and merge the data +class containing the methods to set/unset the angular conversion and merge the data + + +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 +{ + + public: + /** default constructor */ + angularConversion(); + /** virtual destructor */ + virtual ~angularConversion(); + + + + //virtual int readAngularConversion(string fname)=0; + + + + + /** + + reads an angular conversion file + \param fname file to be read + \param nmod number of modules (maximum) to be read + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + */ + static int readAngularConversion(string fname, int nmod, angleConversionConstant *angOff); + + /** + reads an angular conversion file + \param ifstream input file stream to be read + \param nmod number of modules (maximum) to be read + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + + */ + static int readAngularConversion(ifstream& ifs, int nmod, angleConversionConstant *angOff); + /** + writes an angular conversion file + \param fname file to be written + \param nmod number of modules to be written + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + */ + static int writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff); + + /** + writes an angular conversion file + \param ofstream output file stream + \param nmod number of modules to be written + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + */ + 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 + \param mv already merged data + \param me already merged errors (squared sum) + \param mm multiplicity of merged arrays + \param nbins number of bins + \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 + \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 nchans number of channels + \param binsize size of angular bin + \param nb number of angular bins + \param badChanMask badchannelmask (if NULL does not correct for bad channels) + \returns OK or FAIL + */ + + 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 + \param mp already merged postions + \param mv already merged data + \param me already merged errors (squared sum) + \param mm multiplicity of merged arrays + \param nb number of bins + \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) + */ + + 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;}; + + + + 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;}; + + + + 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); + +}; + +#endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.o b/slsDetectorSoftware/slsDetectorAnalysis/angularConversionStatic.o new file mode 100644 index 0000000000000000000000000000000000000000..1bb505f1f6307ec1843641a0799bbc7eff363ec1 GIT binary patch literal 11384 zcmbVS4{(&nb>F)aAjdLNV~wra#6D3u2-~QV5C-G80iy*g{ISdlmk=}`$K6R>E$PVJ z2?Jx<#zJFX4iYzRn{=k`G;K1ir_KzSx{aENJ+dJcxOPUFaZ`wOR5PWnsEDJ?sHx)8 zs=wcUyQjTR(jj+;@7}&Y`*!!ew{QQ5XXTEqKA%sR;u8TeiwSY<(=Mk;fm-ofBB=Pw zfm5zrLyA@E`fVECuHkQLcqibV%)j+tE6vKXtjN5bm8F@A;pUnWFa(j3n(^y1Gcy;? zzGUR`v>%jdnfV(i`HEqAovJ1_X65y_#sUFZdg-HFl|jmEq#}>_1F~|M%|ySv?t}0{ zvg+wK2T8baR_P69Wo<@|XXX7Fc`dhuoLu|lu$*SCzpqsEmJQ1>B3J(zM(OV>b15{? z)gLKJrA7H0MX9nV-%^wn7UgS-60|6Nic(`yo&+T)$1i>Kv#b9y_NOWT1V;gyxcaz~ ztryScDW3;LTjy#}ahpW?R%IE?zbPvQhRO#5U>IYS=EP`ha>x6$gAke>q$X8rv`zKnn3CT+Zl z+w);iQ-13G|DBo9zRk)p9S>C*c|Egdy1(zbueaeu-}KCk5WTg-B{eXCP!WuvE+t}u z8@#&$nwO96AF$mZY%a#XV@JKMNcXrw2b*yr*Pd}+rE=a^uR_o4+_A*;3eZMklxIcj z2PHM9qctU$e{K7r%m~9eme%=&D~zx)|3aFxdn$Z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Q_&C0 z2;qk^K>Fb`gz&>Xq{HrOh{Nu!gkKOMqT!bbTZQ;z4Zll>@yrlnar_YPCH{~Q?*OtN z7On$KTlm`CcWmG1-S-#Y!-}o^rR08B2!y-vJ)!x0NFn}3P2b0RI&eHK!Np21T&G}E e!;>0*Tf^@XVl3x0{+`CKX#D3IFTtA%$N7K9*0ogt literal 0 HcmV?d00001 diff --git a/slsDetectorSoftware/slsDetectorAnalysis/enCalLogClass.h b/slsDetectorSoftware/slsDetectorAnalysis/enCalLogClass.h index 957b33755..6bbcd1617 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/enCalLogClass.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/enCalLogClass.h @@ -123,7 +123,6 @@ class enCalLogClass { slsDetectorCommand *myDet; #endif ofstream outfile; - ifstream infile; char vars[4][100]; }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h b/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h index 25f135624..fcfbd385f 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h @@ -9,8 +9,12 @@ #include #include #include -#include "sls_detector_defs.h" +#ifdef __CINT +#define MYROOT +#endif + +#include "sls_detector_defs.h" using namespace std; /** @short class handling the data file I/O flags diff --git a/slsDetectorSoftware/usersFunctions/angleFunction.h b/slsDetectorSoftware/usersFunctions/angleFunction.h index 65e3decd3..afd708dd6 100644 --- a/slsDetectorSoftware/usersFunctions/angleFunction.h +++ b/slsDetectorSoftware/usersFunctions/angleFunction.h @@ -1,12 +1,15 @@ - +#ifndef DEFAULT_ANGLE_FUNCTION_H +#define DEFAULT_ANGLE_FUNCTION_H /* contains the conversion channel-angle for a module channel conv_r=pitch/radius */ +#define PI 3.14159265358979323846 +#include +double defaultAngleFunction(double ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction) {\ + (void) tilt; \ + return 180./PI*(center*conv_r+direction*atan((double)(ichan-center)*conv_r))+encoder+totalOffset+offset; }; -double defaultAngleFunction(double ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction) {\ - (void) tilt; \ - return 180./PI*(center*conv_r+direction*atan((double)(ichan-center)*conv_r))+encoder+totalOffset+offset;\ -}; +#endif diff --git a/slsDetectorSoftware/usersFunctions/usersFunctions.h b/slsDetectorSoftware/usersFunctions/usersFunctions.h index eabc26b71..a1028fe3f 100644 --- a/slsDetectorSoftware/usersFunctions/usersFunctions.h +++ b/slsDetectorSoftware/usersFunctions/usersFunctions.h @@ -6,7 +6,7 @@ Functions depending on the experimental setup should be defined here ******************************************************************/ -#define PI 3.14159265358979323846 +//#define PI 3.14159265358979323846 #ifdef EPICS @@ -14,7 +14,6 @@ Functions depending on the experimental setup should be defined here #include #endif #include "detectorData.h" -#include "angleFunction.h" #ifdef __cplusplus extern "C" { @@ -30,7 +29,7 @@ extern "C" { #endif - double defaultAngleFunction(double ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction); + // double defaultAngleFunction(double ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction); double defaultGetPosition(void *d); int defaultGoToPosition(double p,void *d); int defaultGoToPositionNoWait(double p,void *d);