mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 13:27:14 +02:00
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
This commit is contained in:
@ -0,0 +1,268 @@
|
||||
#include "angularConversionStatic.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <math.h>
|
||||
|
||||
#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<nch; ip++) {
|
||||
#ifdef VERBOSE
|
||||
// cout << "ip " << ip << " ch0 " << ch0 << " chlast " << chlast << " imod " << imod << endl;
|
||||
#endif
|
||||
if (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<nmod && 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; imod<nmod; imod++) {
|
||||
outfile << " module " << imod << " center "<< angOff[imod].center<<" +- "<< angOff[imod].ecenter<<" conversion "<< angOff[imod].r_conversion << " +- "<< angOff[imod].er_conversion << " offset "<< angOff[imod].offset << " +- "<< angOff[imod].eoffset << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//static
|
||||
int angularConversionStatic::resetMerging(double *mp, double *mv, double *me, int *mm, int nb) {
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "creating merging arrays "<< nb << endl;
|
||||
#endif
|
||||
|
||||
|
||||
for (int ibin=0; ibin<nb; ibin++) {
|
||||
mp[ibin]=0;
|
||||
mv[ibin]=0;
|
||||
me[ibin]=0;
|
||||
mm[ibin]=0;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
//static
|
||||
int angularConversionStatic::finalizeMerging(double *mp, double *mv, double *me, int *mm,int nb) {
|
||||
int np=0;
|
||||
for (int ibin=0; ibin<nb; ibin++) {
|
||||
if (mm[ibin]>0) {
|
||||
|
||||
#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<nchans; ip++) {
|
||||
if (badChanMask) {
|
||||
if (badChanMask[ip]) {
|
||||
#ifdef VERBOSE
|
||||
cout << "channel " << ip << " is bad " << endl;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ibin=(int)((p1[ip]-binmi)/binsize);
|
||||
|
||||
|
||||
if (ibin<nbins && ibin>=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;
|
||||
|
||||
}
|
Reference in New Issue
Block a user