mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 13:27:14 +02:00
postprocessing based on external functions - can work with f90 interface
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@285 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -9,7 +9,7 @@ INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsD
|
|||||||
CC=g++
|
CC=g++
|
||||||
|
|
||||||
|
|
||||||
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 slsDetector/slsDetectorUsers.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 slsDetector/slsDetectorUsers.cpp slsDetectorAnalysis/postProcessingFuncs.cpp
|
||||||
|
|
||||||
OBJS = $(SRC_CLNT:.cpp=.o)
|
OBJS = $(SRC_CLNT:.cpp=.o)
|
||||||
|
|
||||||
|
@ -225,19 +225,7 @@ int acceptConnection(int socketDescriptor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* for (j=0; j<maxfd+1; j++) { */
|
|
||||||
/* if (FD_ISSET(j, &tempset)) { */
|
|
||||||
|
|
||||||
/* printf("%d is set!\n",j); */
|
|
||||||
/* ///////////executes the function!!!! */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* } // end if (FD_ISSET(j, &tempset)) */
|
|
||||||
/* } // end for (j=0;...) */
|
|
||||||
/* } // end else if (result > 0) */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return file_des;
|
return file_des;
|
||||||
@ -312,8 +300,8 @@ void exitServer(int socketDescriptor) {
|
|||||||
if (total_received>0)
|
if (total_received>0)
|
||||||
strcpy(thisClientIP,dummyClientIP);
|
strcpy(thisClientIP,dummyClientIP);
|
||||||
|
|
||||||
if (strcmp(lastClientIP,"none")==0)
|
//if (strcmp(lastClientIP,"none")==0)
|
||||||
strcpy(lastClientIP,thisClientIP);
|
//strcpy(lastClientIP,thisClientIP);
|
||||||
|
|
||||||
if (strcmp(lastClientIP,thisClientIP))
|
if (strcmp(lastClientIP,thisClientIP))
|
||||||
differentClients=1;
|
differentClients=1;
|
||||||
|
@ -497,7 +497,9 @@ enum angleConversionParameter {
|
|||||||
GLOBAL_OFFSET, /**< global offset of the diffractometer */
|
GLOBAL_OFFSET, /**< global offset of the diffractometer */
|
||||||
FINE_OFFSET, /**< fine offset of the diffractometer */
|
FINE_OFFSET, /**< fine offset of the diffractometer */
|
||||||
BIN_SIZE, /**< angular bin size */
|
BIN_SIZE, /**< angular bin size */
|
||||||
MOVE_FLAG /**< wether the detector moves with the motor or not in a multi detector system */
|
MOVE_FLAG, /**< wether the detector moves with the motor or not in a multi detector system */
|
||||||
|
SAMPLE_X, /**< sample displacement in the beam direction */
|
||||||
|
SAMPLE_Y /**< sample displacement orthogonal to the beam */
|
||||||
};
|
};
|
||||||
|
|
||||||
//typedef struct {
|
//typedef struct {
|
||||||
|
@ -23,26 +23,25 @@ int externPostProcessing::InitDataset(int *nModules,int *chPerMod,int moduleMask
|
|||||||
{
|
{
|
||||||
|
|
||||||
init_dataset(nModules,chPerMod,moduleMask,badChans,ffcoeff,fferr,tDead,angRadius,angOffset,angCentre,totalOffset,binSize,sampleX,sampleY);
|
init_dataset(nModules,chPerMod,moduleMask,badChans,ffcoeff,fferr,tDead,angRadius,angOffset,angCentre,totalOffset,binSize,sampleX,sampleY);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int externPostProcessing::finalizeDataset(double ang[], double val[], double err[])
|
int externPostProcessing::finalizeDataset(double ang[], double val[], double err[], int *np)
|
||||||
{
|
{
|
||||||
cout<<"Finalize Dataset"<<endl;
|
finalize_dataset(ang, val, err, np);
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int addFrame(double data[], double *pos, double *IO, double expTime, const char *filename, int *var=0)
|
int addFrame(double data[], double *pos, double *IO, double *expTime, const char *filename, int *var)
|
||||||
{
|
{
|
||||||
cout<<"Do Processing"<<endl;
|
add_frame(data, pos, i0, expTime, filename, var);
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
int calculateFlatField(int* nModules, int badChannelMask[], double ffData[], double ffCoeff[], double ffErr[])
|
int calculateFlatField(int* nModules, int *chPerMod, int modMask[], int badChanMask[], double data[], double ffCoeff[], double ffErr[])
|
||||||
{
|
{
|
||||||
cout<<"Outputs Flat Field Coefficient and errors from the input data"<<endl;
|
calculate_flat_field(nModules, chPerMod, modMask, badChanMask, data, ffCoeff, ffErr);
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
@ -3,10 +3,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "detectorData.h"
|
#include "detectorData.h"
|
||||||
#include "sls_detector_defs.h"
|
|
||||||
#include "slsDetectorBase_Standalone.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -34,13 +30,10 @@ void calculate_flat_field(int *nMod, int *chPerMod, int *modMask,int *badChanMas
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class externPostProcessing : public virtual slsDetectorBase1
|
class externPostProcessing
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
externPostProcessing(){};
|
externPostProcessing(){};
|
||||||
virtual ~externPostProcessing(){};
|
virtual ~externPostProcessing(){};
|
||||||
@ -50,11 +43,11 @@ class externPostProcessing : public virtual slsDetectorBase1
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int finalizeDataset(double ang[], double val[], double err[]);
|
static int finalizeDataset(double ang[], double val[], double err[], int *np);
|
||||||
|
|
||||||
int addFrame(double data[], double *pos, double *IO, double expTime, const char *filename, int *var=0);
|
static int addFrame(double data[], double *pos, double *IO, double expTime, const char *filename, int *var=0);
|
||||||
|
|
||||||
int calculateFlatField(int* nModules, int badChannelMask[], double ffData[], double ffCoeff[], double ffErr[]);
|
static int calculateFlatField(int* nModules, int *chPerMod, int moduleMask[], int badChannelMask[], double ffData[], double ffCoeff[], double ffErr[]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,10 +106,10 @@ end subroutine finalizedataset
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
subroutine addframe(data, pos, i0, fname, var) bind(c, name='add_frame')
|
subroutine addframe(data, pos, i0, exptime, fname, var) bind(c, name='add_frame')
|
||||||
IMPLICIT NONE
|
IMPLICIT NONE
|
||||||
real(C_DOUBLE), intent(IN) :: data(totalnumberofchannels)
|
real(C_DOUBLE), intent(IN) :: data(totalnumberofchannels)
|
||||||
real(C_DOUBLE), intent(IN) :: pos, i0, var
|
real(C_DOUBLE), intent(IN) :: pos, i0, exptime, var
|
||||||
character(kind=c_char), dimension(*), intent(IN) :: fname
|
character(kind=c_char), dimension(*), intent(IN) :: fname
|
||||||
integer :: l
|
integer :: l
|
||||||
integer :: i
|
integer :: i
|
||||||
@ -132,6 +132,9 @@ print*,pos
|
|||||||
print*,'I0: '
|
print*,'I0: '
|
||||||
print*,i0
|
print*,i0
|
||||||
|
|
||||||
|
print*,'Exposure time: '
|
||||||
|
print*,exptime
|
||||||
|
|
||||||
print*,'Var: '
|
print*,'Var: '
|
||||||
print*,var
|
print*,var
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ ID: $Id$
|
|||||||
#include "slsDetector.h"
|
#include "slsDetector.h"
|
||||||
#include "multiSlsDetectorCommand.h"
|
#include "multiSlsDetectorCommand.h"
|
||||||
#include "multiSlsDetectorClient.h"
|
#include "multiSlsDetectorClient.h"
|
||||||
|
#include "postProcessingFuncs.h"
|
||||||
#include "usersFunctions.h"
|
#include "usersFunctions.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
@ -205,40 +206,12 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
|
|||||||
for (int i=thisMultiDetector->numberOfDetectors; i<MAXDET; i++)
|
for (int i=thisMultiDetector->numberOfDetectors; i<MAXDET; i++)
|
||||||
detectors[i]=NULL;
|
detectors[i]=NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** modifies the last PID accessing the detector system*/
|
/** modifies the last PID accessing the detector system*/
|
||||||
thisMultiDetector->lastPID=getpid();
|
thisMultiDetector->lastPID=getpid();
|
||||||
|
|
||||||
|
|
||||||
// getPointers(&thisMultiDetector->stoppedFlag, \
|
|
||||||
// &thisMultiDetector->threadedProcessing, \
|
|
||||||
// &thisMultiDetector->actionMask, \
|
|
||||||
// thisMultiDetector->actionScript, \
|
|
||||||
// thisMultiDetector->actionParameter, \
|
|
||||||
// thisMultiDetector->nScanSteps, \
|
|
||||||
// thisMultiDetector->scanMode, \
|
|
||||||
// thisMultiDetector->scanScript, \
|
|
||||||
// thisMultiDetector->scanParameter, \
|
|
||||||
// thisMultiDetector->scanSteps, \
|
|
||||||
// thisMultiDetector->scanPrecision, \
|
|
||||||
// &thisMultiDetector->numberOfPositions, \
|
|
||||||
// thisMultiDetector->detPositions, \
|
|
||||||
// thisMultiDetector->angConvFile, \
|
|
||||||
// &thisMultiDetector->correctionMask, \
|
|
||||||
// &thisMultiDetector->binSize, \
|
|
||||||
// &thisMultiDetector->fineOffset, \
|
|
||||||
// &thisMultiDetector->globalOffset, \
|
|
||||||
// &thisMultiDetector->angDirection, \
|
|
||||||
// thisMultiDetector->flatFieldDir, \
|
|
||||||
// thisMultiDetector->flatFieldFile, \
|
|
||||||
// thisMultiDetector->badChanFile, \
|
|
||||||
// thisMultiDetector->timerValue, \
|
|
||||||
// &thisMultiDetector->currentSettings, \
|
|
||||||
// &thisMultiDetector->currentThresholdEV, \
|
|
||||||
// thisMultiDetector->filePath, \
|
|
||||||
// thisMultiDetector->fileName, \
|
|
||||||
// &thisMultiDetector->fileIndex);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -272,6 +245,10 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
|
|||||||
fileIndex=&thisMultiDetector->fileIndex;
|
fileIndex=&thisMultiDetector->fileIndex;
|
||||||
moveFlag=NULL;
|
moveFlag=NULL;
|
||||||
|
|
||||||
|
sampleDisplacement=thisMultiDetector->sampleDisplacement;
|
||||||
|
|
||||||
|
getNMods();
|
||||||
|
getMaxMods();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +314,9 @@ int multiSlsDetector::addSlsDetector(int id, int pos) {
|
|||||||
|
|
||||||
thisMultiDetector->numberOfChannels+=detectors[pos]->getTotalNumberOfChannels();
|
thisMultiDetector->numberOfChannels+=detectors[pos]->getTotalNumberOfChannels();
|
||||||
thisMultiDetector->maxNumberOfChannels-=detectors[j]->getMaxNumberOfChannels();
|
thisMultiDetector->maxNumberOfChannels-=detectors[j]->getMaxNumberOfChannels();
|
||||||
|
getMaxMods();
|
||||||
|
getNMods();
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "Detector added " << thisMultiDetector->numberOfDetectors<< endl;
|
cout << "Detector added " << thisMultiDetector->numberOfDetectors<< endl;
|
||||||
|
|
||||||
@ -376,6 +355,11 @@ string multiSlsDetector::setHostname(const char* name, int pos){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "-----------------------------set online!" << endl;
|
||||||
|
#endif
|
||||||
|
setOnline(ONLINE_FLAG);
|
||||||
|
|
||||||
return getHostname(pos);
|
return getHostname(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,8 +567,10 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) {
|
|||||||
cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl;
|
cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl;
|
||||||
#endif
|
#endif
|
||||||
s=new slsDetector(t, id);
|
s=new slsDetector(t, id);
|
||||||
if (online)
|
if (online) {
|
||||||
s->setTCPSocket(name);
|
s->setTCPSocket(name);
|
||||||
|
setOnline(ONLINE_FLAG);
|
||||||
|
}
|
||||||
delete s;
|
delete s;
|
||||||
}
|
}
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -871,7 +857,8 @@ slsDetectorDefs::synchronizationMode multiSlsDetector::setSynchronization(synchr
|
|||||||
|
|
||||||
|
|
||||||
int multiSlsDetector::setOnline(int off) {
|
int multiSlsDetector::setOnline(int off) {
|
||||||
|
int retdet;
|
||||||
|
|
||||||
if (off!=GET_ONLINE_FLAG) {
|
if (off!=GET_ONLINE_FLAG) {
|
||||||
thisMultiDetector->onlineFlag=off;
|
thisMultiDetector->onlineFlag=off;
|
||||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||||
@ -1182,11 +1169,6 @@ int* multiSlsDetector::getDataFromDetector() {
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "Detector " << id << " returned " << n << " bytes " << endl;
|
cout << "Detector " << id << " returned " << n << " bytes " << endl;
|
||||||
#endif
|
#endif
|
||||||
// memcpy(p,retdet,n);
|
|
||||||
//#ifdef VERBOSE
|
|
||||||
//cout << "Copied to pointer "<< p << endl;
|
|
||||||
//#endif
|
|
||||||
// delete [] retdet;
|
|
||||||
} else {
|
} else {
|
||||||
nodatadet=id;
|
nodatadet=id;
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -1296,7 +1278,7 @@ int* multiSlsDetector::readAll(){
|
|||||||
//#else
|
//#else
|
||||||
// std::cout << std::endl;
|
// std::cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return dataQueue.front(); // check what we return!
|
return dataQueueFront(); // check what we return!
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1337,7 +1319,7 @@ int* multiSlsDetector::startAndReadAll(){
|
|||||||
//#else
|
//#else
|
||||||
// std::cout << std::endl;
|
// std::cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return dataQueue.front(); // check what we return!
|
return dataQueueFront(); // check what we return!
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -1637,6 +1619,13 @@ double* multiSlsDetector::decodeData(int *datain, double *fdata) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int multiSlsDetector::setFlatFieldCorrection(string fname){
|
int multiSlsDetector::setFlatFieldCorrection(string fname){
|
||||||
double data[thisMultiDetector->numberOfChannels], xmed[thisMultiDetector->numberOfChannels];
|
double data[thisMultiDetector->numberOfChannels], xmed[thisMultiDetector->numberOfChannels];
|
||||||
double ffcoefficients[thisMultiDetector->numberOfChannels], fferrors[thisMultiDetector->numberOfChannels];
|
double ffcoefficients[thisMultiDetector->numberOfChannels], fferrors[thisMultiDetector->numberOfChannels];
|
||||||
@ -1647,12 +1636,18 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
|
|||||||
int badlist[MAX_BADCHANS];
|
int badlist[MAX_BADCHANS];
|
||||||
int im=0;
|
int im=0;
|
||||||
|
|
||||||
if (fname=="default") {
|
if (fname=="default") {
|
||||||
fname=string(thisMultiDetector->flatFieldFile);
|
fname=string(thisMultiDetector->flatFieldFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
thisMultiDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (fname=="") {
|
if (fname=="") {
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "disabling flat field correction" << std::endl;
|
std::cout<< "disabling flat field correction" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
thisMultiDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
thisMultiDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
||||||
// strcpy(thisMultiDetector->flatFieldFile,"none");
|
// strcpy(thisMultiDetector->flatFieldFile,"none");
|
||||||
@ -1662,118 +1657,41 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "Setting flat field correction from file " << fname << std::endl;
|
std::cout<< "Setting flat field correction from file " << fname << std::endl;
|
||||||
#endif
|
#endif
|
||||||
sprintf(ffffname,"%s/%s",thisMultiDetector->flatFieldDir,fname.c_str());
|
sprintf(ffffname,"%s/%s",thisMultiDetector->flatFieldDir,fname.c_str());
|
||||||
nch=readDataFile(string(ffffname),data);
|
nch=readDataFile(string(ffffname),data);
|
||||||
|
|
||||||
if (nch>thisMultiDetector->numberOfChannels)
|
if (nch>thisMultiDetector->numberOfChannels)
|
||||||
nch=thisMultiDetector->numberOfChannels;
|
nch=thisMultiDetector->numberOfChannels;
|
||||||
|
|
||||||
if (nch>0) {
|
if (nch>0) {
|
||||||
strcpy(thisMultiDetector->flatFieldFile,fname.c_str());
|
|
||||||
|
//???? bad ff chans?
|
||||||
|
int nm=getNMods();
|
||||||
|
int chpm[nm];
|
||||||
for (int ichan=0; ichan<nch; ichan++) {
|
int mMask[nm];
|
||||||
if (detectors[idet]) {
|
for (int i=0; i<nm; i++) {
|
||||||
if (ichdet>=detectors[idet]->getTotalNumberOfChannels()) {
|
chpm[im]=getChansPerMod(im);
|
||||||
ichdet=0;
|
mMask[im]=im;
|
||||||
detectors[idet]->setBadChannelCorrection(nbad,badlist,1);
|
|
||||||
idet++;
|
|
||||||
nbad=0;
|
|
||||||
} else
|
|
||||||
ichdet++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data[ichan]>0) {
|
|
||||||
/* add to median */
|
|
||||||
im=0;
|
|
||||||
while ((im<nmed) && (xmed[im]<data[ichan]))
|
|
||||||
im++;
|
|
||||||
for (int i=nmed; i>im; i--)
|
|
||||||
xmed[i]=xmed[i-1];
|
|
||||||
xmed[im]=data[ichan];
|
|
||||||
nmed++;
|
|
||||||
} else {
|
|
||||||
if (nbad<MAX_BADCHANS) {
|
|
||||||
badlist[nbad]=ichdet;
|
|
||||||
nbad++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (detectors[idet])
|
|
||||||
detectors[idet]->setBadChannelCorrection(nbad,badlist,1);
|
if ((postProcessingFuncs::calculateFlatField(&nm, chpm, mMask, badChannelMask, data, ffcoefficients, fferrors))) {
|
||||||
|
strcpy(thisMultiDetector->flatFieldFile,fname.c_str());
|
||||||
|
|
||||||
if (nmed>1 && xmed[nmed/2]>0) {
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "Flat field median is " << xmed[nmed/2] << " calculated using "<< nmed << " points" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
thisMultiDetector->correctionMask|=(1<<FLAT_FIELD_CORRECTION);
|
thisMultiDetector->correctionMask|=(1<<FLAT_FIELD_CORRECTION);
|
||||||
|
|
||||||
// add to ff coefficients and errors of single detectors
|
setFlatFieldCorrection(ffcoefficients, fferrors);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
idet=0;
|
std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl;
|
||||||
ichdet=0;
|
}
|
||||||
int detoff=0;
|
|
||||||
|
|
||||||
for (int ichan=0; ichan<nch; ichan++) {
|
|
||||||
|
|
||||||
if (detectors[idet]) {
|
|
||||||
if (ichdet>=detectors[idet]->getTotalNumberOfChannels()) {
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "Set flat field detector " << idet << "(offset "<< detoff << ")" << endl;
|
|
||||||
#endif
|
|
||||||
detectors[idet]->setFlatFieldCorrection(ffcoefficients+detoff, fferrors+detoff);
|
|
||||||
ichdet=0;//ichan;
|
|
||||||
detoff=ichan;
|
|
||||||
idet++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (data[ichan]>0) {
|
|
||||||
ffcoefficients[ichan]=xmed[nmed/2]/data[ichan];
|
|
||||||
fferrors[ichan]=ffcoefficients[ichan]*sqrt(data[ichan])/data[ichan];
|
|
||||||
} else {
|
|
||||||
ffcoefficients[ichan]=0.;
|
|
||||||
fferrors[ichan]=1.;
|
|
||||||
}
|
|
||||||
ichdet++;
|
|
||||||
}
|
|
||||||
if (detectors[idet]) {
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "**Set flat field detector " << idet << "(offset "<< detoff << ")" << endl;
|
|
||||||
#endif
|
|
||||||
detectors[idet]->setFlatFieldCorrection(ffcoefficients+detoff, fferrors+detoff);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std::cout<< "Flat field data from file " << fname << " are not valid (" << nmed << "///" << xmed[nmed/2] << std::endl;
|
|
||||||
thisMultiDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
|
||||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
|
||||||
if (detectors[i])
|
|
||||||
detectors[i]->setFlatFieldCorrection(NULL, NULL);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl;
|
|
||||||
thisMultiDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
|
||||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
|
||||||
if (detectors[i])
|
|
||||||
detectors[i]->setFlatFieldCorrection(NULL, NULL);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return thisMultiDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
|
return thisMultiDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int multiSlsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
|
int multiSlsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
|
||||||
@ -1807,6 +1725,7 @@ int multiSlsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
|
|||||||
int multiSlsDetector::getFlatFieldCorrection(double *corr, double *ecorr) {
|
int multiSlsDetector::getFlatFieldCorrection(double *corr, double *ecorr) {
|
||||||
int ichdet=0;
|
int ichdet=0;
|
||||||
double *p, *ep;
|
double *p, *ep;
|
||||||
|
int ff=1, dff;
|
||||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||||
if (detectors[idet]) {
|
if (detectors[idet]) {
|
||||||
if (corr!=NULL)
|
if (corr!=NULL)
|
||||||
@ -1817,11 +1736,13 @@ int multiSlsDetector::getFlatFieldCorrection(double *corr, double *ecorr) {
|
|||||||
ep=ecorr+ichdet;
|
ep=ecorr+ichdet;
|
||||||
else
|
else
|
||||||
ep=NULL;
|
ep=NULL;
|
||||||
detectors[idet]->getFlatFieldCorrection(p, ep);
|
dff=detectors[idet]->getFlatFieldCorrection(p, ep);
|
||||||
|
if (dff==0)
|
||||||
|
ff=0;
|
||||||
ichdet+=detectors[idet]->getTotalNumberOfChannels();
|
ichdet+=detectors[idet]->getTotalNumberOfChannels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1845,6 +1766,10 @@ int multiSlsDetector::getNMods(){
|
|||||||
nm+=detectors[idet]->getNMods();
|
nm+=detectors[idet]->getNMods();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "total number of modules is " << nm << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
return nm;
|
return nm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +155,10 @@ class multiSlsDetector : public slsDetectorUtils {
|
|||||||
double binSize;
|
double binSize;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//X and Y displacement
|
||||||
|
double sampleDisplacement[2];
|
||||||
|
|
||||||
/** number of positions at which the detector should acquire */
|
/** number of positions at which the detector should acquire */
|
||||||
int numberOfPositions;
|
int numberOfPositions;
|
||||||
/** list of encoder positions at which the detector should acquire */
|
/** list of encoder positions at which the detector should acquire */
|
||||||
|
@ -34,17 +34,20 @@ class multiSlsDetectorClient {
|
|||||||
char *c; \
|
char *c; \
|
||||||
char cmd[100]; \
|
char cmd[100]; \
|
||||||
if (action==slsDetectorDefs::PUT_ACTION && argc<2) { \
|
if (action==slsDetectorDefs::PUT_ACTION && argc<2) { \
|
||||||
cout << "Wrong usage - should be: "<< argv[0] << "[id-][pos:]channel arg" << endl; \
|
cout << "Wrong usage - should be: "<< argv[0] << \
|
||||||
|
"[id-][pos:]channel arg" << endl; \
|
||||||
cout << endl; \
|
cout << endl; \
|
||||||
return; \
|
return; \
|
||||||
|
if (del) delete myDetector; \
|
||||||
};
|
};
|
||||||
if (action==slsDetectorDefs::GET_ACTION && argc<1) { \
|
if (action==slsDetectorDefs::GET_ACTION && argc<1) { \
|
||||||
cout << "Wrong usage - should be: "<< argv[0] << "[id-][pos:]channel arg" << endl; \
|
cout << "Wrong usage - should be: "<< argv[0] << \
|
||||||
|
"[id-][pos:]channel arg" << endl; \
|
||||||
cout << endl; \
|
cout << endl; \
|
||||||
|
if (del) delete myDetector; \
|
||||||
return; \
|
return; \
|
||||||
}; \
|
}; \
|
||||||
if (myDetector==NULL) {
|
if (myDetector==NULL) { \
|
||||||
iv=sscanf(argv[0],"%d-%s",&id, cmd); \
|
iv=sscanf(argv[0],"%d-%s",&id, cmd); \
|
||||||
if (iv==2 && id>=0) { \
|
if (iv==2 && id>=0) { \
|
||||||
myDetector=new multiSlsDetector(id); \
|
myDetector=new multiSlsDetector(id); \
|
||||||
@ -52,8 +55,8 @@ class multiSlsDetectorClient {
|
|||||||
cout << id << "-" ; \
|
cout << id << "-" ; \
|
||||||
} else { \
|
} else { \
|
||||||
myDetector=new multiSlsDetector(); \
|
myDetector=new multiSlsDetector(); \
|
||||||
};
|
}; \
|
||||||
del=1;
|
del=1; \
|
||||||
} \
|
} \
|
||||||
iv=sscanf(argv[0],"%d:%s",&pos, cmd); \
|
iv=sscanf(argv[0],"%d:%s",&pos, cmd); \
|
||||||
if (iv==2 && pos>=0) { \
|
if (iv==2 && pos>=0) { \
|
||||||
|
@ -2640,7 +2640,12 @@ int send_update(int file_des) {
|
|||||||
|
|
||||||
n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP));
|
n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP));
|
||||||
n = sendDataOnly(file_des,&nModX,sizeof(nModX));
|
n = sendDataOnly(file_des,&nModX,sizeof(nModX));
|
||||||
n = sendDataOnly(file_des,&nModY,sizeof(nModY));
|
// n = sendDataOnly(file_des,&nModY,sizeof(nModY));
|
||||||
|
//sends back max modules instead of nmodulesY!
|
||||||
|
|
||||||
|
thr = getNModBoard();
|
||||||
|
sendDataOnly(file_des,&thr,sizeof(thr));
|
||||||
|
|
||||||
n = sendDataOnly(file_des,&dynamicRange,sizeof(dynamicRange));
|
n = sendDataOnly(file_des,&dynamicRange,sizeof(dynamicRange));
|
||||||
n = sendDataOnly(file_des,&dataBytes,sizeof(dataBytes));
|
n = sendDataOnly(file_des,&dataBytes,sizeof(dataBytes));
|
||||||
t=setSettings(GET_SETTINGS);
|
t=setSettings(GET_SETTINGS);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "slsDetector.h"
|
#include "slsDetector.h"
|
||||||
#include "usersFunctions.h"
|
#include "usersFunctions.h"
|
||||||
#include "slsDetectorCommand.h"
|
#include "slsDetectorCommand.h"
|
||||||
|
#include "postProcessingFuncs.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@ -662,9 +663,10 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
|||||||
fileName=thisDetector->fileName;
|
fileName=thisDetector->fileName;
|
||||||
fileIndex=&thisDetector->fileIndex;
|
fileIndex=&thisDetector->fileIndex;
|
||||||
moveFlag=&thisDetector->moveFlag;
|
moveFlag=&thisDetector->moveFlag;
|
||||||
|
sampleDisplacement=NULL;
|
||||||
settingsFile=thisDetector->settingsFile;
|
settingsFile=thisDetector->settingsFile;
|
||||||
|
|
||||||
|
|
||||||
// setAngularConversionPointer(thisDetector->angOff,&thisDetector->nMods, thisDetector->nChans*thisDetector->nChips);
|
// setAngularConversionPointer(thisDetector->angOff,&thisDetector->nMods, thisDetector->nChans*thisDetector->nChips);
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -900,10 +902,16 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
|
|||||||
|
|
||||||
|
|
||||||
int slsDetector::setOnline(int off) {
|
int slsDetector::setOnline(int off) {
|
||||||
|
int old=thisDetector->onlineFlag;
|
||||||
if (off!=GET_ONLINE_FLAG) {
|
if (off!=GET_ONLINE_FLAG) {
|
||||||
thisDetector->onlineFlag=off;
|
thisDetector->onlineFlag=off;
|
||||||
if (thisDetector->onlineFlag==ONLINE_FLAG)
|
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||||
setTCPSocket();
|
setTCPSocket();
|
||||||
|
if (thisDetector->onlineFlag==ONLINE_FLAG && old==OFFLINE_FLAG) {
|
||||||
|
cout << "Detector connecting for the first time - updating!" << endl;
|
||||||
|
updateDetector();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return thisDetector->onlineFlag;
|
return thisDetector->onlineFlag;
|
||||||
}
|
}
|
||||||
@ -911,7 +919,7 @@ int slsDetector::setOnline(int off) {
|
|||||||
|
|
||||||
|
|
||||||
string slsDetector::checkOnline() {
|
string slsDetector::checkOnline() {
|
||||||
string retval = "";
|
string retval = string("");
|
||||||
if(!controlSocket){
|
if(!controlSocket){
|
||||||
//this already sets the online/offline flag
|
//this already sets the online/offline flag
|
||||||
setTCPSocket();
|
setTCPSocket();
|
||||||
@ -927,7 +935,7 @@ string slsDetector::checkOnline() {
|
|||||||
thisDetector->onlineFlag=OFFLINE_FLAG;
|
thisDetector->onlineFlag=OFFLINE_FLAG;
|
||||||
delete controlSocket;
|
delete controlSocket;
|
||||||
controlSocket=NULL;
|
controlSocket=NULL;
|
||||||
retval = thisDetector->hostname;
|
retval = string(thisDetector->hostname);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "offline!" << std::endl;
|
std::cout<< "offline!" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -2854,7 +2862,17 @@ int slsDetector::updateDetectorNoWait() {
|
|||||||
n = controlSocket->ReceiveDataOnly(&nm,sizeof(nm));
|
n = controlSocket->ReceiveDataOnly(&nm,sizeof(nm));
|
||||||
thisDetector->nMod[X]=nm;
|
thisDetector->nMod[X]=nm;
|
||||||
n = controlSocket->ReceiveDataOnly( &nm,sizeof(nm));
|
n = controlSocket->ReceiveDataOnly( &nm,sizeof(nm));
|
||||||
thisDetector->nMod[Y]=nm;
|
/// Should be overcome at a certain point!
|
||||||
|
|
||||||
|
if (thisDetector->myDetectorType==MYTHEN) {
|
||||||
|
thisDetector->nModMax[X]=nm;
|
||||||
|
thisDetector->nModMax[Y]=1;
|
||||||
|
thisDetector->nModsMax=thisDetector->nModMax[Y]*thisDetector->nModMax[X];
|
||||||
|
thisDetector->nMod[Y]=1;
|
||||||
|
} else {
|
||||||
|
thisDetector->nMod[Y]=nm;
|
||||||
|
}
|
||||||
|
|
||||||
thisDetector->nMods=thisDetector->nMod[Y]*thisDetector->nMod[X];
|
thisDetector->nMods=thisDetector->nMod[Y]*thisDetector->nMod[X];
|
||||||
if (thisDetector->nModsMax<thisDetector->nMods)
|
if (thisDetector->nModsMax<thisDetector->nMods)
|
||||||
thisDetector->nModsMax=thisDetector->nMods;
|
thisDetector->nModsMax=thisDetector->nMods;
|
||||||
@ -3342,8 +3360,13 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
|
|||||||
thisDetector->timerValue[index]=retval;
|
thisDetector->timerValue[index]=retval;
|
||||||
}
|
}
|
||||||
controlSocket->Disconnect();
|
controlSocket->Disconnect();
|
||||||
if (ret==FORCE_UPDATE)
|
if (ret==FORCE_UPDATE) {
|
||||||
updateDetector();
|
updateDetector();
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout<< "Updated!" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -4035,7 +4058,7 @@ int slsDetector::setFlatFieldCorrection(string fname)
|
|||||||
|
|
||||||
char ffffname[MAX_STR_LENGTH*2];
|
char ffffname[MAX_STR_LENGTH*2];
|
||||||
if (fname=="default") {
|
if (fname=="default") {
|
||||||
fname=string("thisDetector->flatFieldFile");
|
fname=string(thisDetector->flatFieldFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fname=="") {
|
if (fname=="") {
|
||||||
@ -4043,77 +4066,50 @@ int slsDetector::setFlatFieldCorrection(string fname)
|
|||||||
std::cout<< "disabling flat field correction" << std::endl;
|
std::cout<< "disabling flat field correction" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
thisDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
thisDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
||||||
//strcpy(thisDetector->flatFieldFile,"none");
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "Setting flat field correction from file " << fname << std::endl;
|
std::cout<< "Setting flat field correction from file " << fname << std::endl;
|
||||||
#endif
|
|
||||||
sprintf(ffffname,"%s/%s",thisDetector->flatFieldDir,fname.c_str());
|
|
||||||
nch=readDataFile(string(ffffname),data);
|
|
||||||
if (nch>0) {
|
|
||||||
strcpy(thisDetector->flatFieldFile,fname.c_str());
|
|
||||||
for (int ichan=0; ichan<nch; ichan++) {
|
|
||||||
if (data[ichan]>0) {
|
|
||||||
/* add to median */
|
|
||||||
im=0;
|
|
||||||
while ((im<nmed) && (xmed[im]<data[ichan]))
|
|
||||||
im++;
|
|
||||||
for (int i=nmed; i>im; i--)
|
|
||||||
xmed[i]=xmed[i-1];
|
|
||||||
xmed[im]=data[ichan];
|
|
||||||
nmed++;
|
|
||||||
} else {
|
|
||||||
//add the channel to the ff bad channel list
|
|
||||||
if (thisDetector->nBadFF<MAX_BADCHANS) {
|
|
||||||
thisDetector->badFFList[thisDetector->nBadFF]=ichan;
|
|
||||||
(thisDetector->nBadFF)++;
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "Channel " << ichan << " added to the bad channel list" << std::endl;
|
|
||||||
#endif
|
|
||||||
} else
|
|
||||||
std::cout<< "Too many bad channels " << std::endl;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nmed>1 && xmed[nmed/2]>0) {
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "Flat field median is " << xmed[nmed/2] << " calculated using "<< nmed << " points" << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
sprintf(ffffname,"%s/%s",thisDetector->flatFieldDir,fname.c_str());
|
||||||
|
nch=readDataFile(string(ffffname),data);
|
||||||
|
if (nch>0) {
|
||||||
|
|
||||||
|
//???? bad ff chans?
|
||||||
|
int nm=getNMods();
|
||||||
|
int chpm[nm];
|
||||||
|
int mMask[nm];
|
||||||
|
for (int i=0; i<nm; i++) {
|
||||||
|
chpm[im]=getChansPerMod(im);
|
||||||
|
mMask[im]=im;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((postProcessingFuncs::calculateFlatField(&nm, chpm, mMask, badChannelMask, data, ffcoefficients, fferrors))) {
|
||||||
|
strcpy(thisDetector->flatFieldFile,fname.c_str());
|
||||||
|
|
||||||
|
|
||||||
thisDetector->correctionMask|=(1<<FLAT_FIELD_CORRECTION);
|
thisDetector->correctionMask|=(1<<FLAT_FIELD_CORRECTION);
|
||||||
for (int ichan=0; ichan<nch; ichan++) {
|
|
||||||
if (data[ichan]>0) {
|
setFlatFieldCorrection(ffcoefficients, fferrors);
|
||||||
ffcoefficients[ichan]=xmed[nmed/2]/data[ichan];
|
|
||||||
fferrors[ichan]=ffcoefficients[ichan]*sqrt(data[ichan])/data[ichan];
|
}
|
||||||
} else {
|
} else {
|
||||||
ffcoefficients[ichan]=0.;
|
std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl;
|
||||||
fferrors[ichan]=1.;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int ichan=nch; ichan<thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ichan++) {
|
|
||||||
ffcoefficients[ichan]=1.;
|
|
||||||
fferrors[ichan]=0.;
|
|
||||||
}
|
|
||||||
|
|
||||||
fillBadChannelMask();
|
return thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
|
||||||
|
|
||||||
} else {
|
|
||||||
std::cout<< "Flat field data from file " << fname << " are not valid (" << nmed << "///" << xmed[nmed/2] << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int slsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
|
int slsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
|
||||||
if (corr!=NULL) {
|
if (corr!=NULL) {
|
||||||
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nChans*thisDetector->nChips; ichan++) {
|
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nChans*thisDetector->nChips; ichan++) {
|
||||||
@ -4129,7 +4125,11 @@ int slsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
|
|||||||
thisDetector->correctionMask|=(1<<FLAT_FIELD_CORRECTION);
|
thisDetector->correctionMask|=(1<<FLAT_FIELD_CORRECTION);
|
||||||
} else
|
} else
|
||||||
thisDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
thisDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "set ff corrections " << ((thisDetector->correctionMask)&(1<<FLAT_FIELD_CORRECTION)) << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
return thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
|
return thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4184,7 +4184,7 @@ int slsDetector::flatFieldCorrect(double* datain, double *errin, double* dataout
|
|||||||
} else {
|
} else {
|
||||||
e=errin[ichan];
|
e=errin[ichan];
|
||||||
}
|
}
|
||||||
flatFieldCorrect(datain[ichan],e,dataout[ichan],eo,ffcoefficients[ichan],fferrors[ichan]);
|
postProcessingFuncs::flatFieldCorrect(datain[ichan],e,dataout[ichan],eo,ffcoefficients[ichan],fferrors[ichan]);
|
||||||
if (errout)
|
if (errout)
|
||||||
errout[ichan]=eo;
|
errout[ichan]=eo;
|
||||||
// #ifdef VERBOSE
|
// #ifdef VERBOSE
|
||||||
@ -4257,8 +4257,6 @@ double slsDetector::getRateCorrectionTau(){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int slsDetector::getRateCorrection(){
|
int slsDetector::getRateCorrection(){
|
||||||
|
|
||||||
if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) {
|
if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) {
|
||||||
@ -4286,7 +4284,7 @@ int slsDetector::rateCorrect(double* datain, double *errin, double* dataout, dou
|
|||||||
} else
|
} else
|
||||||
e=errin[ichan];
|
e=errin[ichan];
|
||||||
|
|
||||||
rateCorrect(datain[ichan], e, dataout[ichan], errout[ichan], tau, t);
|
postProcessingFuncs::rateCorrect(datain[ichan], e, dataout[ichan], errout[ichan], tau, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4638,38 +4636,6 @@ int slsDetector::getAngularConversion(int &direction, angleConversionConstant *
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// double* slsDetector::convertAngles(double pos) {
|
|
||||||
// int imod;
|
|
||||||
// double *ang=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
|
|
||||||
// for (int ip=0; ip<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ip++) {
|
|
||||||
// imod=ip/(thisDetector->nChans*thisDetector->nChips);
|
|
||||||
// ang[ip]=angle(ip%(thisDetector->nChans*thisDetector->nChips),\
|
|
||||||
// pos, \
|
|
||||||
// thisDetector->fineOffset+thisDetector->globalOffset, \
|
|
||||||
// thisDetector->angOff[imod].r_conversion, \
|
|
||||||
// thisDetector->angOff[imod].center, \
|
|
||||||
// thisDetector->angOff[imod].offset, \
|
|
||||||
// thisDetector->angOff[imod].tilt, \
|
|
||||||
// thisDetector->angDirection
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// return ang;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int slsDetector:: writeAngularConversion(string fname) {
|
int slsDetector:: writeAngularConversion(string fname) {
|
||||||
|
|
||||||
return writeAngularConversion(fname, thisDetector->nMods, thisDetector->angOff);
|
return writeAngularConversion(fname, thisDetector->nMods, thisDetector->angOff);
|
||||||
@ -4843,12 +4809,7 @@ int slsDetector::readConfigurationFile(string const fname){
|
|||||||
string ans;
|
string ans;
|
||||||
string str;
|
string str;
|
||||||
ifstream infile;
|
ifstream infile;
|
||||||
// int iargval;
|
|
||||||
// int interrupt=0;
|
|
||||||
char *args[1000];
|
char *args[1000];
|
||||||
// for (int ia=0; ia<100; ia++) {
|
|
||||||
// args[ia]=new char[1000];
|
|
||||||
// }
|
|
||||||
|
|
||||||
string sargname, sargval;
|
string sargname, sargval;
|
||||||
int iline=0;
|
int iline=0;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include "angleConversionConstant.h"
|
#include "angleConversionConstant.h"
|
||||||
#include "MySocketTCP.h"
|
#include "MySocketTCP.h"
|
||||||
|
|
||||||
|
#include "angleConversionConstant.h";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,6 +244,7 @@ typedef struct sharedSlsDetector {
|
|||||||
/** online flag - is set if the receiver is connected, unset if socket connection is not possible */
|
/** online flag - is set if the receiver is connected, unset if socket connection is not possible */
|
||||||
int receiverOnlineFlag;
|
int receiverOnlineFlag;
|
||||||
|
|
||||||
|
|
||||||
} sharedSlsDetector;
|
} sharedSlsDetector;
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,6 +123,15 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
|||||||
descrToFuncMap[i].m_pFuncName="moveflag" ;//
|
descrToFuncMap[i].m_pFuncName="moveflag" ;//
|
||||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv;
|
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
descrToFuncMap[i].m_pFuncName="samplex" ;//
|
||||||
|
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
|
||||||
|
descrToFuncMap[i].m_pFuncName="sampley" ;//
|
||||||
|
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1682,7 +1691,14 @@ string slsDetectorCommand::cmdAngConv(int narg, char *args[], int action){
|
|||||||
|
|
||||||
} else if (string(args[0])==string("moveflag")) {
|
} else if (string(args[0])==string("moveflag")) {
|
||||||
c=MOVE_FLAG;
|
c=MOVE_FLAG;
|
||||||
} else
|
} else if (string(args[0])==string("samplex")) {
|
||||||
|
c=SAMPLE_X;
|
||||||
|
} else if (string(args[0])==string("sampley")) {
|
||||||
|
c=SAMPLE_Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
else
|
||||||
return string("could not decode angular conversion parameter ")+cmd;
|
return string("could not decode angular conversion parameter ")+cmd;
|
||||||
|
|
||||||
|
|
||||||
@ -1712,6 +1728,10 @@ string slsDetectorCommand::helpAngConv(int narg, char *args[], int action){
|
|||||||
t=4;
|
t=4;
|
||||||
} else if (string(args[0])==string("binsize")) {
|
} else if (string(args[0])==string("binsize")) {
|
||||||
t=8;
|
t=8;
|
||||||
|
} else if (string(args[0])==string("samplex")) {
|
||||||
|
t=16;
|
||||||
|
} else if (string(args[0])==string("sampley")) {
|
||||||
|
t=32;
|
||||||
}
|
}
|
||||||
if (t&1) {
|
if (t&1) {
|
||||||
if (action==GET_ACTION || action==HELP_ACTION)
|
if (action==GET_ACTION || action==HELP_ACTION)
|
||||||
@ -1739,11 +1759,19 @@ string slsDetectorCommand::helpAngConv(int narg, char *args[], int action){
|
|||||||
if (action==PUT_ACTION || action==HELP_ACTION)
|
if (action==PUT_ACTION || action==HELP_ACTION)
|
||||||
os << string("binsize f\t sets the bin size used for the angular conversion \n");
|
os << string("binsize f\t sets the bin size used for the angular conversion \n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (t&16) {
|
||||||
|
if (action==GET_ACTION || action==HELP_ACTION)
|
||||||
|
os << string("samplex \t gets the sample displacement in th direction parallel to the beam \n");
|
||||||
|
if (action==PUT_ACTION || action==HELP_ACTION)
|
||||||
|
os << string("samplex f\t sets the sample displacement in th direction parallel to the beam \n");
|
||||||
|
}
|
||||||
|
if (t&32) {
|
||||||
|
if (action==GET_ACTION || action==HELP_ACTION)
|
||||||
|
os << string("sampley \t gets the sample displacement in the direction orthogonal to the beam \n");
|
||||||
|
if (action==PUT_ACTION || action==HELP_ACTION)
|
||||||
|
os << string("sampley f\t sets the sample displacement in the direction orthogonal to the beam \n");
|
||||||
|
}
|
||||||
|
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
slsDetectorUtils::slsDetectorUtils() {
|
||||||
slsDetectorUtils::slsDetectorUtils() {
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -34,13 +33,13 @@ slsDetectorUtils::slsDetectorUtils() {
|
|||||||
cout << "done " << endl;
|
cout << "done " << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
expTime=timerValue+ACQUISITION_TIME;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void slsDetectorUtils::acquire(int delflag){
|
void slsDetectorUtils::acquire(int delflag){
|
||||||
|
|
||||||
// setTotalProgress();
|
// setTotalProgress();
|
||||||
@ -80,13 +79,36 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_lock(&mp);
|
|
||||||
resetFinalDataQueue();
|
setJoinThread(0);
|
||||||
resetDataQueue();
|
positionFinished(0);
|
||||||
jointhread=0;
|
|
||||||
queuesize=0;
|
|
||||||
posfinished=0;
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
|
int nm=timerValue[MEASUREMENTS_NUMBER];
|
||||||
|
if (nm<1)
|
||||||
|
nm=1;
|
||||||
|
|
||||||
|
int np=getNumberOfPositions();
|
||||||
|
if (np<1)
|
||||||
|
np=1;
|
||||||
|
|
||||||
|
|
||||||
|
int ns0=1;
|
||||||
|
if (*actionMask & (1 << MAX_ACTIONS)) {
|
||||||
|
ns0=getScanSteps(0);
|
||||||
|
if (ns0<1)
|
||||||
|
ns0=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ns1=1;
|
||||||
|
if (*actionMask & (1 << (MAX_ACTIONS+1))) {
|
||||||
|
ns1=getScanSteps(1);
|
||||||
|
if (ns1<1)
|
||||||
|
ns1=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (*threadedProcessing) {
|
if (*threadedProcessing) {
|
||||||
startThread(delflag);
|
startThread(delflag);
|
||||||
@ -96,48 +118,21 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int nm=1;
|
|
||||||
|
|
||||||
if (timerValue[MEASUREMENTS_NUMBER]>0)
|
|
||||||
nm=timerValue[MEASUREMENTS_NUMBER];
|
|
||||||
|
|
||||||
for(int im=0;im<nm;im++) {
|
for(int im=0;im<nm;im++) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << " starting measurement "<< im << " of " << nm << endl;
|
cout << " starting measurement "<< im << " of " << nm << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//cout << "data thread started " << endl;
|
//cout << "data thread started " << endl;
|
||||||
int np=1;
|
|
||||||
if (*numberOfPositions>0)
|
|
||||||
np=*numberOfPositions;
|
|
||||||
|
|
||||||
int ns0=1;
|
|
||||||
if (*actionMask & (1 << MAX_ACTIONS)) {
|
|
||||||
ns0=nScanSteps[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ns0<1)
|
|
||||||
ns0=1;
|
|
||||||
|
|
||||||
int ns1=1;
|
|
||||||
if (*actionMask & (1 << (MAX_ACTIONS+1))) {
|
|
||||||
ns1=nScanSteps[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ns1<1)
|
|
||||||
ns1=1;
|
|
||||||
|
|
||||||
//loop measurements
|
//loop measurements
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
setStartIndex(*fileIndex);
|
setStartIndex(*fileIndex);
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
|
|
||||||
//cout << "action at start" << endl;
|
//cout << "action at start" << endl;
|
||||||
if (*stoppedFlag==0) {
|
if (*stoppedFlag==0) {
|
||||||
@ -166,14 +161,14 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
currentPositionIndex=0;
|
ResetPositionIndex();
|
||||||
|
|
||||||
for (int ip=0; ip<np; ip++) {
|
for (int ip=0; ip<np; ip++) {
|
||||||
// cout << "positions " << endl;
|
// cout << "positions " << endl;
|
||||||
if (*stoppedFlag==0) {
|
if (*stoppedFlag==0) {
|
||||||
if (*numberOfPositions>0) {
|
if (getNumberOfPositions()>0) {
|
||||||
moveDetector(detPositions[ip]);
|
moveDetector(detPositions[ip]);
|
||||||
currentPositionIndex=ip+1;
|
IncrementPositionIndex();
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "moving to position" << std::endl;
|
std::cout<< "moving to position" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -200,23 +195,15 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
|
|
||||||
executeAction(headerBefore);
|
executeAction(headerBefore);
|
||||||
|
|
||||||
if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
|
if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog || eclog) {
|
||||||
pthread_mutex_lock(&mp);
|
positionFinished(0);
|
||||||
currentPosition=getDetectorPosition();
|
setCurrentPosition(getDetectorPosition());
|
||||||
posfinished=0;
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aclog) {
|
|
||||||
if ((*correctionMask&(1<< ANGULAR_CONVERSION))==0) {
|
if (aclog)
|
||||||
pthread_mutex_lock(&mp);
|
aclog->addStep(getCurrentPosition(), getCurrentFileName());
|
||||||
currentPosition=getDetectorPosition();
|
|
||||||
posfinished=0;
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
}
|
|
||||||
|
|
||||||
aclog->addStep(currentPosition, getCurrentFileName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eclog)
|
if (eclog)
|
||||||
eclog->addStep(setDAC(-1,THRESHOLD), getCurrentFileName());
|
eclog->addStep(setDAC(-1,THRESHOLD), getCurrentFileName());
|
||||||
@ -229,16 +216,23 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
}
|
}
|
||||||
|
|
||||||
startAndReadAll();
|
startAndReadAll();
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "returned! " << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (*correctionMask&(1<< I0_NORMALIZATION)) {
|
if (*correctionMask&(1<< I0_NORMALIZATION)) {
|
||||||
if (get_i0)
|
if (get_i0)
|
||||||
currentI0=get_i0(1,IOarg); // this is the correct i0!!!!!
|
currentI0=get_i0(1,IOarg); // this is the correct i0!!!!!
|
||||||
}
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "pos finished? " << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
positionFinished(1);
|
||||||
|
|
||||||
pthread_mutex_lock(&mp);
|
#ifdef VERBOSE
|
||||||
posfinished=1;
|
cout << "done! " << endl;
|
||||||
pthread_mutex_unlock(&mp);
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (*threadedProcessing==0){
|
if (*threadedProcessing==0){
|
||||||
@ -254,15 +248,11 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
|
|
||||||
// wait until data processing thread has finished the data
|
// wait until data processing thread has finished the data
|
||||||
|
|
||||||
pthread_mutex_lock(&mp);
|
while (dataQueueSize()){
|
||||||
while (queuesize){
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
pthread_mutex_lock(&mp);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mp);
|
pthread_mutex_lock(&mp);
|
||||||
|
|
||||||
if (*stoppedFlag==0) {
|
if (*stoppedFlag==0) {
|
||||||
executeAction(headerAfter);
|
executeAction(headerAfter);
|
||||||
setLastIndex(*fileIndex);
|
setLastIndex(*fileIndex);
|
||||||
@ -270,7 +260,7 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
setLastIndex(*fileIndex);
|
setLastIndex(*fileIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
|
|
||||||
|
|
||||||
if (*stoppedFlag) {
|
if (*stoppedFlag) {
|
||||||
@ -279,7 +269,9 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
} else if (ip<(np-1)) {
|
} else if (ip<(np-1)) {
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
*fileIndex=setStartIndex();
|
*fileIndex=setStartIndex();
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
}
|
}
|
||||||
} // loop on position finished
|
} // loop on position finished
|
||||||
|
|
||||||
@ -296,7 +288,9 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
} else if (is1<(ns1-1)) {
|
} else if (is1<(ns1-1)) {
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
*fileIndex=setStartIndex();
|
*fileIndex=setStartIndex();
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,12 +303,16 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
} else if (is0<(ns0-1)) {
|
} else if (is0<(ns0-1)) {
|
||||||
*fileIndex=setStartIndex();
|
pthread_mutex_lock(&mp);
|
||||||
|
*fileIndex=setStartIndex();
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
} //end scan0 loop is0
|
} //end scan0 loop is0
|
||||||
|
|
||||||
*fileIndex=setLastIndex();
|
pthread_mutex_lock(&mp);
|
||||||
|
*fileIndex=setLastIndex();
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
if (*stoppedFlag==0) {
|
if (*stoppedFlag==0) {
|
||||||
executeAction(stopScript);
|
executeAction(stopScript);
|
||||||
} else
|
} else
|
||||||
@ -335,9 +333,7 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
|
|
||||||
// waiting for the data processing thread to finish!
|
// waiting for the data processing thread to finish!
|
||||||
if (*threadedProcessing) {
|
if (*threadedProcessing) {
|
||||||
pthread_mutex_lock(&mp);
|
setJoinThread(1);
|
||||||
jointhread=1;
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
pthread_join(dataProcessingThread, &status);
|
pthread_join(dataProcessingThread, &status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,17 +345,15 @@ void slsDetectorUtils::acquire(int delflag){
|
|||||||
|
|
||||||
if (aclog)
|
if (aclog)
|
||||||
delete aclog;
|
delete aclog;
|
||||||
|
|
||||||
if (eclog)
|
if (eclog)
|
||||||
delete eclog;
|
delete eclog;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (acquisition_finished)
|
if (acquisition_finished)
|
||||||
acquisition_finished(getCurrentProgress(),getDetectorStatus(),acqFinished_p);
|
acquisition_finished(getCurrentProgress(),getDetectorStatus(),acqFinished_p);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -491,17 +485,21 @@ int slsDetectorUtils::setBadChannelCorrection(string fname, int &nbadtot, int *b
|
|||||||
|
|
||||||
|
|
||||||
double slsDetectorUtils::getCurrentProgress() {
|
double slsDetectorUtils::getCurrentProgress() {
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << progressIndex << " / " << totalProgress << endl;
|
cout << progressIndex << " / " << totalProgress << endl;
|
||||||
#endif
|
#endif
|
||||||
return 100.*((double)progressIndex)/((double)totalProgress);
|
return 100.*((double)progressIndex)/((double)totalProgress);
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void slsDetectorUtils::incrementProgress() {
|
void slsDetectorUtils::incrementProgress() {
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
progressIndex++;
|
progressIndex++;
|
||||||
cout << fixed << setprecision(2) << setw (6) << getCurrentProgress() << " \%";
|
cout << fixed << setprecision(2) << setw (6) << 100.*((double)progressIndex)/((double)totalProgress) << " \%";
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << endl;
|
cout << endl;
|
||||||
#else
|
#else
|
||||||
@ -838,115 +836,3 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// int slsDetectorUtils::setFlatFieldCorrectionFile(string fname){
|
|
||||||
// int tch=getTotalNumberOfChannels();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// double data[tch], xmed[tch];
|
|
||||||
// double ffcoefficients[tch], fferrors[tch];
|
|
||||||
// int nmed=0;
|
|
||||||
// int idet=0, ichdet=-1;
|
|
||||||
// char ffffname[MAX_STR_LENGTH*2];
|
|
||||||
// int nbad=0, nch;
|
|
||||||
// int badlist[MAX_BADCHANS];
|
|
||||||
// int im=0;
|
|
||||||
|
|
||||||
// if (fname=="default") {
|
|
||||||
// fname=string(flatFieldFile);
|
|
||||||
// }
|
|
||||||
// if (fname=="") {
|
|
||||||
// #ifdef VERBOSE
|
|
||||||
// std::cout<< "disabling flat field correction" << std::endl;
|
|
||||||
// #endif
|
|
||||||
// (*correctionMask)&=~(1<<FLAT_FIELD_CORRECTION);
|
|
||||||
// // strcpy(thisMultiDetector->flatFieldFile,"none");
|
|
||||||
|
|
||||||
// setFlatFieldCorrection(NULL, NULL);
|
|
||||||
// } else {
|
|
||||||
|
|
||||||
// #ifdef VERBOSE
|
|
||||||
// std::cout<< "Setting flat field correction from file " << fname << std::endl;
|
|
||||||
// #endif
|
|
||||||
// sprintf(ffffname,"%s/%s",flatFieldDir,fname.c_str());
|
|
||||||
// nch=readDataFile(string(ffffname),data);
|
|
||||||
|
|
||||||
// if (nch>tch)
|
|
||||||
// nch=tch;
|
|
||||||
|
|
||||||
// if (nch>0) {
|
|
||||||
// strcpy(flatFieldFile,fname.c_str());
|
|
||||||
|
|
||||||
|
|
||||||
// nbad=0;
|
|
||||||
// for (int ichan=0; ichan<nch; ichan++) {
|
|
||||||
|
|
||||||
// if (data[ichan]>0) {
|
|
||||||
// /* add to median */
|
|
||||||
// im=0;
|
|
||||||
// while ((im<nmed) && (xmed[im]<data[ichan]))
|
|
||||||
// im++;
|
|
||||||
// for (int i=nmed; i>im; i--)
|
|
||||||
// xmed[i]=xmed[i-1];
|
|
||||||
// xmed[im]=data[ichan];
|
|
||||||
// nmed++;
|
|
||||||
// } else {
|
|
||||||
// if (nbad<MAX_BADCHANS) {
|
|
||||||
// badlist[nbad]=ichan;
|
|
||||||
// nbad++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// if (nmed>1 && xmed[nmed/2]>0) {
|
|
||||||
// #ifdef VERBOSE
|
|
||||||
// std::cout<< "Flat field median is " << xmed[nmed/2] << " calculated using "<< nmed << " points" << std::endl;
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// thisMultiDetector->correctionMask|=(1<<FLAT_FIELD_CORRECTION);
|
|
||||||
|
|
||||||
// // add to ff coefficients and errors of single detectors
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// for (int ichan=0; ichan<nch; ichan++) {
|
|
||||||
|
|
||||||
// setFlatFieldCorrection(ffcoefficients, fferrors);
|
|
||||||
|
|
||||||
// if (data[ichan]>0) {
|
|
||||||
// ffcoefficients[ichan]=xmed[nmed/2]/data[ichan];
|
|
||||||
// fferrors[ichan]=ffcoefficients[ichan]*sqrt(data[ichan])/data[ichan];
|
|
||||||
// } else {
|
|
||||||
// ffcoefficients[ichan]=0.;
|
|
||||||
// fferrors[ichan]=1.;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// setFlatFieldCorrection(ffcoefficients, fferrors);
|
|
||||||
|
|
||||||
|
|
||||||
// } else {
|
|
||||||
// std::cout<< "Flat field data from file " << fname << " are not valid (" << nmed << "///" << xmed[nmed/2] << std::endl;
|
|
||||||
// thisMultiDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
|
||||||
// for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
|
||||||
// if (detectors[i])
|
|
||||||
// detectors[i]->setFlatFieldCorrection(NULL, NULL);
|
|
||||||
// }
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl;
|
|
||||||
// thisMultiDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
|
|
||||||
// for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
|
||||||
// if (detectors[i])
|
|
||||||
// detectors[i]->setFlatFieldCorrection(NULL, NULL);
|
|
||||||
// }
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return thisMultiDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
@ -50,11 +50,9 @@ using namespace std;
|
|||||||
(used in the PSi command line interface)
|
(used in the PSi command line interface)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//class postProcessing;
|
|
||||||
|
|
||||||
class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
||||||
|
|
||||||
//public postProcessing
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -599,7 +597,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
|||||||
detectorSettings *currentSettings;
|
detectorSettings *currentSettings;
|
||||||
int *currentThresholdEV;
|
int *currentThresholdEV;
|
||||||
|
|
||||||
|
|
||||||
int totalProgress;
|
int totalProgress;
|
||||||
|
|
||||||
int progressIndex;
|
int progressIndex;
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
class angleConversionConstant {
|
class angleConversionConstant {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
angleConversionConstant(){};
|
||||||
|
angleConversionConstant(double c, double r, double o, double t){center=c; r_conversion=r; offset=o; tilt=t;};
|
||||||
|
|
||||||
//typedef struct {
|
//typedef struct {
|
||||||
double center; /**< center of the module (channel at which the radius is perpendicular to the module surface) */
|
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 ecenter; /**< error in the center determination */
|
||||||
@ -20,7 +24,7 @@ class angleConversionConstant {
|
|||||||
double getOffset(){return offset;};
|
double getOffset(){return offset;};
|
||||||
double getTilt(){return tilt;};
|
double getTilt(){return tilt;};
|
||||||
|
|
||||||
int setAngConvConstant(angleConversionConstant *acc) {\
|
void setAngConvConstant(angleConversionConstant *acc) {\
|
||||||
center=acc->center; \
|
center=acc->center; \
|
||||||
ecenter=acc->ecenter; \
|
ecenter=acc->ecenter; \
|
||||||
r_conversion=acc->r_conversion; \
|
r_conversion=acc->r_conversion; \
|
||||||
|
@ -190,6 +190,18 @@ double angularConversion::setAngularConversionParameter(angleConversionParameter
|
|||||||
return *moveFlag;
|
return *moveFlag;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
case SAMPLE_X:
|
||||||
|
if (sampleDisplacement) {
|
||||||
|
sampleDisplacement[X]=v;
|
||||||
|
return sampleDisplacement[X];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
case SAMPLE_Y:
|
||||||
|
if (sampleDisplacement) {
|
||||||
|
sampleDisplacement[Y]=v;
|
||||||
|
return sampleDisplacement[Y];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -345,6 +345,8 @@ class angularConversion : public virtual slsDetectorBase, public angularConversi
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double *sampleDisplacement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
current position of the detector
|
current position of the detector
|
||||||
*/
|
*/
|
||||||
@ -367,6 +369,8 @@ class angularConversion : public virtual slsDetectorBase, public angularConversi
|
|||||||
*/
|
*/
|
||||||
int getCurrentPositionIndex() {return currentPositionIndex;};
|
int getCurrentPositionIndex() {return currentPositionIndex;};
|
||||||
void incrementPositionIndex() {currentPositionIndex++;};
|
void incrementPositionIndex() {currentPositionIndex++;};
|
||||||
|
void resetPositionIndex() {currentPositionIndex=0;};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -385,7 +389,6 @@ class angularConversion : public virtual slsDetectorBase, public angularConversi
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** merging bins */
|
/** merging bins */
|
||||||
double *mergingBins;
|
double *mergingBins;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPe
|
|||||||
angleConversionConstant *p=NULL;
|
angleConversionConstant *p=NULL;
|
||||||
|
|
||||||
int ch0=0;
|
int ch0=0;
|
||||||
int chlast=chansPerMod[0];
|
int chlast=chansPerMod[0]-1;
|
||||||
int nchmod=chansPerMod[0];
|
int nchmod=chansPerMod[0];
|
||||||
p=angOff[imod];
|
p=angOff[imod];
|
||||||
if (mF[imod]==0)
|
if (mF[imod]==0)
|
||||||
@ -42,7 +42,7 @@ double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPe
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
// cout << "ip " << ip << " ch0 " << ch0 << " chlast " << chlast << " imod " << imod << endl;
|
// cout << "ip " << ip << " ch0 " << ch0 << " chlast " << chlast << " imod " << imod << endl;
|
||||||
#endif
|
#endif
|
||||||
if (ip>=chlast) {
|
if (ip>chlast) {
|
||||||
imod++;
|
imod++;
|
||||||
p=angOff[imod];
|
p=angOff[imod];
|
||||||
if (mF[imod]==0)
|
if (mF[imod]==0)
|
||||||
@ -50,10 +50,10 @@ double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPe
|
|||||||
else
|
else
|
||||||
enc=pos;
|
enc=pos;
|
||||||
|
|
||||||
ch0=chlast;
|
ch0=chlast+1;
|
||||||
nchmod=chansPerMod[imod];
|
nchmod=chansPerMod[imod];
|
||||||
if (nchmod>0)
|
if (nchmod>0)
|
||||||
chlast+=nchmod;
|
chlast=ch0+nchmod-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
@ -69,6 +69,72 @@ double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPe
|
|||||||
return ang;
|
return ang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double angularConversionStatic::convertAngle(double pos, int ich, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir) {
|
||||||
|
|
||||||
|
int imod=0;
|
||||||
|
double ang;
|
||||||
|
double enc=0, trans=0;
|
||||||
|
angleConversionConstant *p=NULL;
|
||||||
|
|
||||||
|
int ch0=0;
|
||||||
|
int chlast=chansPerMod[0]-1;
|
||||||
|
int nchmod=chansPerMod[0];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
while (ich>chlast) {
|
||||||
|
imod++;
|
||||||
|
ch0=chlast+1;
|
||||||
|
nchmod=chansPerMod[imod];
|
||||||
|
chlast=ch0+nchmod-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p=angOff[imod];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
switch (mF[imod]) {
|
||||||
|
case 0:
|
||||||
|
enc=0;
|
||||||
|
trans=0;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
enc=pos;
|
||||||
|
trans=0;
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
enc=-pos;
|
||||||
|
trans=0;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
enc=0;
|
||||||
|
trans=pos;
|
||||||
|
break;
|
||||||
|
case -2:
|
||||||
|
enc=0;
|
||||||
|
trans=-pos;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
enc=0;
|
||||||
|
trans=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (p)
|
||||||
|
ang=angle(ich-ch0, \
|
||||||
|
enc, \
|
||||||
|
fo+go, \
|
||||||
|
p->r_conversion, \
|
||||||
|
p->center, \
|
||||||
|
p->offset, \
|
||||||
|
trans, \
|
||||||
|
angdir );
|
||||||
|
|
||||||
|
return ang;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//static!
|
//static!
|
||||||
@ -265,6 +331,53 @@ int angularConversionStatic::addToMerging(double *p1, double *v1, double *e1, d
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return slsDetectorDefs::OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int angularConversionStatic::addPointToMerging(double p1, double v1, double e1, double *mp, double *mv,double *me, int *mm, double binsize,int nbins) {
|
||||||
|
|
||||||
|
|
||||||
|
double binmi=-180.;
|
||||||
|
int ibin=0;
|
||||||
|
|
||||||
|
|
||||||
|
if (mp==NULL) //can be changed if we want to use a fixed bin algorithm!
|
||||||
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
|
if (mv==NULL)
|
||||||
|
return slsDetectorDefs::FAIL;
|
||||||
|
if (me==NULL)
|
||||||
|
return slsDetectorDefs::FAIL;
|
||||||
|
if (mm==NULL)
|
||||||
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
|
if (binsize<=0)
|
||||||
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
|
if (nbins<=0)
|
||||||
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
|
|
||||||
|
ibin=(int)((p1-binmi)/binsize);
|
||||||
|
|
||||||
|
|
||||||
|
if (ibin<nbins && ibin>=0) {
|
||||||
|
mp[ibin]+=p1;
|
||||||
|
mv[ibin]+=v1;
|
||||||
|
if (e1)
|
||||||
|
me[ibin]+=(e1*e1);
|
||||||
|
else
|
||||||
|
me[ibin]+=v1;
|
||||||
|
mm[ibin]++;
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||||
|
#endif
|
||||||
|
} else
|
||||||
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
|
|
||||||
return slsDetectorDefs::OK;
|
return slsDetectorDefs::OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include "angleConversionConstant.h"
|
||||||
|
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
#include "angleFunction.h"
|
#include "angleFunction.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -180,7 +182,7 @@ int angularConversionStatic::resetMerging(double *mp, double *mv, double *me, in
|
|||||||
me[ibin]=0;
|
me[ibin]=0;
|
||||||
mm[ibin]=0;
|
mm[ibin]=0;
|
||||||
}
|
}
|
||||||
return OK;
|
return slsDetectorDefs::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -214,25 +216,25 @@ int angularConversionStatic::addToMerging(double *p1, double *v1, double *e1, d
|
|||||||
if (p1==NULL)
|
if (p1==NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if (v1==NULL)
|
if (v1==NULL)
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
if (mp==NULL) //can be changed if we want to use a fixed bin algorithm!
|
if (mp==NULL) //can be changed if we want to use a fixed bin algorithm!
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
if (mv==NULL)
|
if (mv==NULL)
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
if (me==NULL)
|
if (me==NULL)
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
if (mm==NULL)
|
if (mm==NULL)
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
if (nchans==0)
|
if (nchans==0)
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
if (binsize<=0)
|
if (binsize<=0)
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
if (nbins<=0)
|
if (nbins<=0)
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
|
|
||||||
for (int ip=0; ip<nchans; ip++) {
|
for (int ip=0; ip<nchans; ip++) {
|
||||||
if (badChanMask) {
|
if (badChanMask) {
|
||||||
@ -259,10 +261,10 @@ int angularConversionStatic::addToMerging(double *p1, double *v1, double *e1, d
|
|||||||
cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||||
#endif
|
#endif
|
||||||
} else
|
} else
|
||||||
return FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return OK;
|
return slsDetectorDefs::OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,26 @@ class angularConversionStatic
|
|||||||
\returns OK or FAIL
|
\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 );
|
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=NULL);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
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 addPointToMerging(double p1, double v1, double e1, double *mp, double *mv,double *me, int *mm, double binsize, int nb);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,6 +158,8 @@ class angularConversionStatic
|
|||||||
|
|
||||||
double* convertAngles(double pos, int nch, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir);
|
double* convertAngles(double pos, int nch, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir);
|
||||||
|
|
||||||
|
double convertAngle(double pos, int ich, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -7,17 +7,17 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "sls_detector_defs.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "angleConversionConstant.h"
|
//#include "angleConversionConstant.h"
|
||||||
|
|
||||||
|
|
||||||
//double angle(int ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction)
|
//double angle(int ichan, double encoder, double totalOffset, double conv_r, double center, double offset, double tilt, int direction)
|
||||||
|
|
||||||
|
class angleConversionConstant;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -35,7 +35,8 @@ 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
|
The angular conversion itself is defined by the angle() function defined in usersFunctions.cpp
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class angularConversionStatic : public virtual slsDetectorDefs
|
class angularConversionStatic
|
||||||
|
// : public virtual slsDetectorDefs
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -45,6 +45,13 @@ class badChannelCorrections{
|
|||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
return nbad; };
|
return nbad; };
|
||||||
|
|
||||||
|
|
||||||
|
static int setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff){ \
|
||||||
|
int retval=readBadChannelCorrectionFile(infile,nbad,badlist); \
|
||||||
|
for (int ich=0; ich<nbad; ich++) badlist[ich]=badlist[ich]+moff; \
|
||||||
|
return retval; \
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
#include "postProcessing.h"
|
#include "postProcessing.h"
|
||||||
|
#include "postProcessingFuncs.h"
|
||||||
|
#include "angleConversionConstant.h"
|
||||||
|
#ifdef VERBOSE
|
||||||
#include "usersFunctions.h"
|
#include "usersFunctions.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -12,63 +16,21 @@ postProcessing::postProcessing(){
|
|||||||
//cout << "reg callback "<< endl;
|
//cout << "reg callback "<< endl;
|
||||||
dataReady = 0;
|
dataReady = 0;
|
||||||
pCallbackArg = 0;
|
pCallbackArg = 0;
|
||||||
|
#ifdef VERBOSE
|
||||||
registerDataCallback(&defaultDataReadyFunc, NULL);
|
registerDataCallback(&defaultDataReadyFunc, NULL);
|
||||||
|
#endif
|
||||||
//cout << "done "<< endl;
|
//cout << "done "<< endl;
|
||||||
rawDataReady = 0;
|
rawDataReady = 0;
|
||||||
pRawDataArg = 0;
|
pRawDataArg = 0;
|
||||||
|
|
||||||
|
ppFun=new postProcessingFuncs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
postProcessing::~postProcessing(){delete ppFun;};
|
||||||
int postProcessing::flatFieldCorrect(double datain, double errin, double &dataout, double &errout, double ffcoefficient, double fferr){
|
|
||||||
double e;
|
|
||||||
|
|
||||||
dataout=datain*ffcoefficient;
|
|
||||||
|
|
||||||
if (errin==0 && datain>=0)
|
|
||||||
e=sqrt(datain);
|
|
||||||
else
|
|
||||||
e=errin;
|
|
||||||
|
|
||||||
if (dataout>0)
|
|
||||||
errout=sqrt(e*ffcoefficient*e*ffcoefficient+datain*fferr*datain*fferr);
|
|
||||||
else
|
|
||||||
errout=1.0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int postProcessing::rateCorrect(double datain, double errin, double &dataout, double &errout, double tau, double t){
|
|
||||||
|
|
||||||
// double data;
|
|
||||||
double e;
|
|
||||||
|
|
||||||
dataout=(datain*exp(tau*datain/t));
|
|
||||||
|
|
||||||
if (errin==0 && datain>=0)
|
|
||||||
e=sqrt(datain);
|
|
||||||
else
|
|
||||||
e=errin;
|
|
||||||
|
|
||||||
if (dataout>0)
|
|
||||||
errout=e*dataout*sqrt((1/(datain*datain)+tau*tau/(t*t)));
|
|
||||||
else
|
|
||||||
errout=1.;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -82,47 +44,62 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
|||||||
string fname;
|
string fname;
|
||||||
// double *fdata=NULL;
|
// double *fdata=NULL;
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
incrementProgress();
|
cout << "start processing"<< endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
incrementProgress();
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "prog incremented"<< endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
/** decode data */
|
/** decode data */
|
||||||
|
|
||||||
fdata=decodeData(myData, fdata);
|
fdata=decodeData(myData, fdata);
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "decode"<< endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
fname=createFileName();
|
|
||||||
|
fname=createFileName();
|
||||||
//Checking for write flag
|
|
||||||
if(*correctionMask&(1<<WRITE_FILE))
|
//Checking for write flag
|
||||||
{
|
if(*correctionMask&(1<<WRITE_FILE)) {
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "writing raw data " << endl;
|
cout << "writing raw data " << endl;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
//uses static function?!?!?!?
|
//uses static function?!?!?!?
|
||||||
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
|
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "done " << endl;
|
cout << "done " << endl;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (rawDataReady)
|
||||||
|
rawDataReady(fdata,pRawDataArg);
|
||||||
|
|
||||||
|
if (*correctionMask & ~(1<<WRITE_FILE))
|
||||||
|
doProcessing(fdata,delflag, fname);
|
||||||
|
|
||||||
doProcessing(fdata,delflag, fname);
|
delete [] myData;
|
||||||
|
delete [] fdata;
|
||||||
delete [] myData;
|
myData=NULL;
|
||||||
myData=NULL;
|
fdata=NULL;
|
||||||
fdata=NULL;
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "Pop data queue " << *fileIndex << endl;
|
cout << "Pop data queue " << *fileIndex << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pthread_mutex_lock(&mp);
|
if(*correctionMask&(1<<WRITE_FILE))
|
||||||
dataQueue.pop(); //remove the data from the queue
|
IncrementFileIndex();
|
||||||
queuesize=dataQueue.size();
|
|
||||||
pthread_mutex_unlock(&mp);
|
popDataQueue(); //remove the data from the queue
|
||||||
|
queuesize=dataQueueSize();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -132,210 +109,53 @@ if(*correctionMask&(1<<WRITE_FILE))
|
|||||||
|
|
||||||
void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
|
void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
|
||||||
|
|
||||||
|
double *ang=new double[arraySize];
|
||||||
|
double *val=new double[arraySize];
|
||||||
|
double *err=new double[arraySize];
|
||||||
|
int np;
|
||||||
|
detectorData *thisData;
|
||||||
|
|
||||||
// /** write raw data file */
|
int npos=getNumberOfPositions();
|
||||||
// if (*correctionMask==0 && delflag==1) {
|
|
||||||
// // delete [] fdata;
|
|
||||||
// ;
|
|
||||||
// } else {
|
|
||||||
|
|
||||||
|
string ext=".dat";
|
||||||
|
|
||||||
double *rcdata=NULL, *rcerr=NULL;
|
double t=(*expTime)*1E-9;
|
||||||
double *ffcdata=NULL, *ffcerr=NULL;
|
if (GetCurrentPositionIndex()<=1) {
|
||||||
double *ang=NULL;
|
|
||||||
// int imod;
|
|
||||||
int np;
|
|
||||||
//string fname;
|
|
||||||
detectorData *thisData;
|
|
||||||
|
|
||||||
|
|
||||||
string ext=".dat";
|
|
||||||
// fname=createFileName();
|
|
||||||
|
|
||||||
/** rate correction */
|
|
||||||
if (*correctionMask&(1<<RATE_CORRECTION)) {
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "rate correcting " << endl;
|
cout << "init dataset" << endl;
|
||||||
#endif
|
#endif
|
||||||
rcdata=new double[getTotalNumberOfChannels()];
|
ppFun->initDataset();
|
||||||
rcerr=new double[getTotalNumberOfChannels()];
|
|
||||||
rateCorrect(lfdata,NULL,rcdata,rcerr);
|
|
||||||
delete [] lfdata;
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "done " << endl;
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
rcdata=lfdata;
|
|
||||||
}
|
}
|
||||||
lfdata=NULL;
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "add frame" << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ppFun->addFrame(lfdata, ¤tPosition, ¤tI0, &t, (fname+ext).c_str(), NULL);
|
||||||
|
|
||||||
|
if ((GetCurrentPositionIndex()>=npos && positionFinished() && dataQueueSize()) || npos==0) {
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "finalize dataset" << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ppFun->finalizeDataset(ang, val, err, &np);
|
||||||
|
IncrementPositionIndex();
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
|
fname=createFileName();
|
||||||
/** flat field correction */
|
|
||||||
if (*correctionMask&(1<<FLAT_FIELD_CORRECTION)) {
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "ff correcting " << endl;
|
|
||||||
#endif
|
|
||||||
ffcdata=new double[getTotalNumberOfChannels()];
|
|
||||||
ffcerr=new double[getTotalNumberOfChannels()];
|
|
||||||
flatFieldCorrect(rcdata,rcerr,ffcdata,ffcerr);
|
|
||||||
delete [] rcdata;
|
|
||||||
rcdata=NULL;
|
|
||||||
if (rcerr)
|
|
||||||
delete [] rcerr;
|
|
||||||
rcerr=NULL;
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "done " << endl;
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
ffcdata=rcdata;
|
|
||||||
ffcerr=rcerr;
|
|
||||||
rcdata=NULL;
|
|
||||||
rcerr=NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// writes angualr converted files
|
|
||||||
|
|
||||||
if (*correctionMask!=0) {
|
|
||||||
if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "ang conv " << endl;
|
|
||||||
#endif
|
|
||||||
ang=convertAngles();
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "done - write position data file " << endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
writeDataFile (fname+ext, ffcdata, ffcerr,ang);
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "done " << endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (*correctionMask&(1<< ANGULAR_CONVERSION) && getNumberOfPositions()>0) {
|
|
||||||
if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "**************Current position index is " << getCurrentPositionIndex() << endl;
|
|
||||||
#endif
|
|
||||||
// if (*numberOfPositions>0) {
|
|
||||||
if (getCurrentPositionIndex()<=1) {
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "reset merging " << endl;
|
|
||||||
#endif
|
|
||||||
resetMerging();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "add to merging "<< getCurrentPositionIndex() << endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
addToMerging(ang, ffcdata, ffcerr, badChannelMask );
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << getCurrentPositionIndex() << " " << getNumberOfPositions() << endl;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// cout << "lock 1" << endl;
|
|
||||||
pthread_mutex_lock(&mp);
|
|
||||||
if ((getCurrentPositionIndex()>=getNumberOfPositions() && posfinished==1 && queuesize==1)) {
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "finalize merging " << getCurrentPositionIndex()<< endl;
|
|
||||||
#endif
|
|
||||||
np=finalizeMerging();
|
|
||||||
/** file writing */
|
|
||||||
incrementPositionIndex();
|
|
||||||
// cout << "unlock 1" << endl;
|
|
||||||
pthread_mutex_unlock(&mp);
|
pthread_mutex_unlock(&mp);
|
||||||
|
|
||||||
|
if(*correctionMask&(1<<WRITE_FILE))
|
||||||
fname=createFileName();
|
writeDataFile (fname+ext,np,ang, val, err,'f');
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "writing merged data file" << endl;
|
|
||||||
#endif
|
|
||||||
writeDataFile (fname+ext,np,getMergedCounts(), getMergedErrors(), getMergedPositions(),'f');
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << " done" << endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if (delflag) {
|
|
||||||
// deleteMerging();
|
|
||||||
// } else {
|
|
||||||
thisData=new detectorData(getMergedCounts(),getMergedErrors(),getMergedPositions(),getCurrentProgress(),(fname+ext).c_str(),np);
|
|
||||||
|
|
||||||
// // cout << "lock 2" << endl;
|
|
||||||
// pthread_mutex_lock(&mg);
|
|
||||||
// finalDataQueue.push(thisData);
|
|
||||||
// // cout << "unlock 2" << endl;
|
|
||||||
|
|
||||||
// pthread_mutex_unlock(&mg);
|
|
||||||
|
|
||||||
if (dataReady) {
|
|
||||||
|
|
||||||
dataReady(thisData, pCallbackArg);
|
|
||||||
delete thisData;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }
|
|
||||||
// cout << "lock 3" << endl;
|
|
||||||
pthread_mutex_lock(&mp);
|
|
||||||
}
|
|
||||||
// cout << "unlock 3" << endl;
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
|
|
||||||
if (ffcdata)
|
|
||||||
delete [] ffcdata;
|
|
||||||
|
|
||||||
ffcdata=NULL;
|
|
||||||
|
|
||||||
if (ffcerr)
|
|
||||||
delete [] ffcerr;
|
|
||||||
ffcerr=NULL;
|
|
||||||
|
|
||||||
if (ang)
|
|
||||||
delete [] ang;
|
|
||||||
ang=NULL;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// if (delflag) {
|
|
||||||
// if (ffcdata)
|
|
||||||
// delete [] ffcdata;
|
|
||||||
// if (ffcerr)
|
|
||||||
// delete [] ffcerr;
|
|
||||||
// if ( ang)
|
|
||||||
// delete [] ang;
|
|
||||||
// } else {
|
|
||||||
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+ext).c_str(),getTotalNumberOfChannels());
|
|
||||||
|
|
||||||
|
thisData=new detectorData(ang,val,err,getCurrentProgress(),(fname+ext).c_str(),np);
|
||||||
|
|
||||||
if (dataReady) {
|
if (dataReady) {
|
||||||
dataReady(thisData, pCallbackArg);
|
dataReady(thisData, pCallbackArg);
|
||||||
delete thisData;
|
|
||||||
}
|
}
|
||||||
// pthread_mutex_lock(&mg);
|
delete thisData;
|
||||||
// finalDataQueue.push(thisData);
|
|
||||||
|
|
||||||
|
|
||||||
// pthread_mutex_unlock(&mg);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
incrementFileIndex();
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "fdata is " << fdata << endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -422,70 +242,89 @@ void* postProcessing::processData(int delflag) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setTotalProgress();
|
queuesize=dataQueueSize();
|
||||||
pthread_mutex_lock(&mp);
|
|
||||||
queuesize=dataQueue.size();
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
|
|
||||||
int *myData;
|
int *myData;
|
||||||
int dum=1;
|
int dum=1;
|
||||||
|
|
||||||
fdata=NULL;
|
fdata=NULL;
|
||||||
|
|
||||||
|
|
||||||
while(dum | *threadedProcessing) { // ????????????????????????
|
while(dum | *threadedProcessing) { // ????????????????????????
|
||||||
|
|
||||||
|
|
||||||
/* IF THERE ARE DATA PROCESS THEM*/
|
/* IF THERE ARE DATA PROCESS THEM*/
|
||||||
pthread_mutex_lock(&mp);
|
while((queuesize=dataQueueSize())>0) {
|
||||||
while((queuesize=dataQueue.size())>0) {
|
|
||||||
/** Pop data queue */
|
/** Pop data queue */
|
||||||
myData=dataQueue.front(); // get the data from the queue
|
#ifdef VERBOSE
|
||||||
pthread_mutex_unlock(&mp);
|
cout << "data found"<< endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
myData=dataQueueFront(); // get the data from the queue
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "got them"<< endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (myData) {
|
if (myData) {
|
||||||
processFrame(myData,delflag);
|
processFrame(myData,delflag);
|
||||||
//usleep(1000);
|
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&mp);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
|
|
||||||
/* IF THERE ARE NO DATA look if acquisition is finished */
|
/* IF THERE ARE NO DATA look if acquisition is finished */
|
||||||
pthread_mutex_lock(&mp);
|
if (checkJoinThread()) {
|
||||||
if (jointhread) {
|
if (dataQueueSize()==0) {
|
||||||
if (dataQueue.size()==0) {
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mp);
|
}
|
||||||
} else {
|
|
||||||
pthread_mutex_unlock(&mp);
|
|
||||||
}
|
|
||||||
dum=0;
|
dum=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fdata) {
|
if (fdata) {
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "delete fdata" << endl;
|
|
||||||
#endif
|
|
||||||
delete [] fdata;
|
delete [] fdata;
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "done " << endl;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int postProcessing::checkJoinThread() {
|
||||||
|
int retval;
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
|
retval=jointhread;
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void postProcessing::setJoinThread( int v) {
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
|
jointhread=v;
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int* postProcessing::dataQueueFront() {
|
||||||
|
int *retval=NULL;
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
|
if( !dataQueue.empty() ) {
|
||||||
|
retval=dataQueue.front();
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
int postProcessing::dataQueueSize() {
|
||||||
|
int retval;
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
|
retval=dataQueue.size();
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int* postProcessing::popDataQueue() {
|
int* postProcessing::popDataQueue() {
|
||||||
int *retval=NULL;
|
int *retval=NULL;
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
if( !dataQueue.empty() ) {
|
if( !dataQueue.empty() ) {
|
||||||
retval=dataQueue.front();
|
retval=dataQueue.front();
|
||||||
dataQueue.pop();
|
dataQueue.pop();
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,11 +341,13 @@ detectorData* postProcessing::popFinalDataQueue() {
|
|||||||
|
|
||||||
void postProcessing::resetDataQueue() {
|
void postProcessing::resetDataQueue() {
|
||||||
int *retval=NULL;
|
int *retval=NULL;
|
||||||
|
pthread_mutex_lock(&mp);
|
||||||
while( !dataQueue.empty() ) {
|
while( !dataQueue.empty() ) {
|
||||||
retval=dataQueue.front();
|
retval=dataQueue.front();
|
||||||
dataQueue.pop();
|
dataQueue.pop();
|
||||||
delete [] retval;
|
delete [] retval;
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&mp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,12 +364,125 @@ void postProcessing::resetFinalDataQueue() {
|
|||||||
|
|
||||||
|
|
||||||
void postProcessing::startThread(int delflag) {
|
void postProcessing::startThread(int delflag) {
|
||||||
|
|
||||||
|
/////////////////////////////////// Initialize dataset
|
||||||
|
|
||||||
|
//resetDataQueue();
|
||||||
|
|
||||||
|
setTotalProgress();
|
||||||
|
|
||||||
|
int nmod=getNMods();
|
||||||
|
int *chPM=new int[nmod];
|
||||||
|
int *mM=new int[nmod];
|
||||||
|
int totch=0;
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "init dataset stuff" << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int im=0; im<nmod; im++) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "MODULE " << im << endl;
|
||||||
|
#endif
|
||||||
|
chPM[im]=getChansPerMod(im);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "chanspermod" << endl;
|
||||||
|
#endif
|
||||||
|
mM[im]=getMoveFlag(im);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "moveflag" << endl;
|
||||||
|
#endif
|
||||||
|
totch+=chPM[im];
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "total channels is " << totch << endl;
|
||||||
|
#endif
|
||||||
|
double *ffcoeff=NULL, *fferr=NULL;
|
||||||
|
|
||||||
|
if (*correctionMask&(1<<FLAT_FIELD_CORRECTION)) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "get ff " << endl;
|
||||||
|
#endif
|
||||||
|
ffcoeff=new double[totch];
|
||||||
|
fferr=new double[totch];
|
||||||
|
|
||||||
|
getFlatFieldCorrection(ffcoeff,fferr);
|
||||||
|
}
|
||||||
|
|
||||||
|
double tdead;
|
||||||
|
if (*correctionMask&(1<<RATE_CORRECTION)) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "get tau " << endl;
|
||||||
|
#endif
|
||||||
|
tdead=getRateCorrectionTau();
|
||||||
|
} else
|
||||||
|
tdead=0;
|
||||||
|
|
||||||
|
|
||||||
|
int angdir=getAngularDirection();
|
||||||
|
|
||||||
|
double to=0;
|
||||||
|
double bs=0;
|
||||||
|
double sx=0, sy=0;
|
||||||
|
double *angRad=NULL;
|
||||||
|
double *angOff=NULL;
|
||||||
|
double *angCenter=NULL;
|
||||||
|
angleConversionConstant *p=NULL;
|
||||||
|
|
||||||
|
if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "get angconv " << endl;
|
||||||
|
#endif
|
||||||
|
bs=getBinSize();
|
||||||
|
to=getGlobalOffset()+getFineOffset();
|
||||||
|
angRad=new double[nmod];
|
||||||
|
angOff=new double[nmod];
|
||||||
|
angCenter=new double[nmod];
|
||||||
|
for (int im=0; im<nmod; im++) {
|
||||||
|
p=getAngularConversionPointer(im);
|
||||||
|
angRad[im]=p->r_conversion;
|
||||||
|
angOff[im]=p->offset;
|
||||||
|
angCenter[im]=p->center;
|
||||||
|
}
|
||||||
|
sx=getAngularConversionParameter(SAMPLE_X);
|
||||||
|
sy=getAngularConversionParameter(SAMPLE_Y);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "init dataset" << endl;
|
||||||
|
#endif
|
||||||
|
ppFun->initDataset(&nmod,chPM,mM,badChannelMask, ffcoeff, fferr, &tdead, &angdir, angRad, angOff, angCenter, &to, &bs, &sx, &sy);
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "done" << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
|
||||||
|
arraySize=getNumberOfAngularBins();
|
||||||
|
if (arraySize<=0)
|
||||||
|
arraySize=totch;
|
||||||
|
} else {
|
||||||
|
arraySize=totch;
|
||||||
|
}
|
||||||
|
|
||||||
|
queuesize=dataQueueSize();
|
||||||
|
|
||||||
|
resetFinalDataQueue();
|
||||||
|
resetDataQueue();
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////// Start thread ////////////////////////////////////////////////////////
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "start thread stuff" << endl;
|
||||||
|
#endif
|
||||||
pthread_attr_t tattr;
|
pthread_attr_t tattr;
|
||||||
int ret;
|
int ret;
|
||||||
sched_param param, mparam;
|
sched_param param, mparam;
|
||||||
int policy= SCHED_OTHER;
|
int policy= SCHED_OTHER;
|
||||||
|
|
||||||
|
|
||||||
// set the priority; others are unchanged
|
// set the priority; others are unchanged
|
||||||
//newprio = 30;
|
//newprio = 30;
|
||||||
mparam.sched_priority =1;
|
mparam.sched_priority =1;
|
||||||
@ -553,7 +507,8 @@ void postProcessing::startThread(int delflag) {
|
|||||||
ret = pthread_create(&dataProcessingThread, &tattr,startProcessDataNoDelete, (void*)this);
|
ret = pthread_create(&dataProcessingThread, &tattr,startProcessDataNoDelete, (void*)this);
|
||||||
|
|
||||||
pthread_attr_destroy(&tattr);
|
pthread_attr_destroy(&tattr);
|
||||||
// scheduling parameters of target thread
|
|
||||||
|
// scheduling parameters of target thread
|
||||||
ret = pthread_setschedparam(dataProcessingThread, policy, ¶m);
|
ret = pthread_setschedparam(dataProcessingThread, policy, ¶m);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
class postProcessingFuncs;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -39,7 +42,7 @@ class postProcessing : public angularConversion, public fileIO, public badChanne
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
postProcessing();
|
postProcessing();
|
||||||
virtual ~postProcessing(){};
|
virtual ~postProcessing();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +78,6 @@ class postProcessing : public angularConversion, public fileIO, public badChanne
|
|||||||
*/
|
*/
|
||||||
virtual int setBadChannelCorrection(string fname="")=0;
|
virtual int setBadChannelCorrection(string fname="")=0;
|
||||||
|
|
||||||
static int setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff){int retval=readBadChannelCorrectionFile(infile,nbad,badlist); for (int ich=0; ich<nbad; ich++) badlist[ich]=badlist[ich]+moff; return retval;};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
set bad channels correction
|
set bad channels correction
|
||||||
@ -85,7 +87,7 @@ class postProcessing : public angularConversion, public fileIO, public badChanne
|
|||||||
\returns 0 if bad channel disabled, >0 otherwise
|
\returns 0 if bad channel disabled, >0 otherwise
|
||||||
*/
|
*/
|
||||||
virtual int setBadChannelCorrection(string fname, int &nbad, int *badlist, int off=0)=0;
|
virtual int setBadChannelCorrection(string fname, int &nbad, int *badlist, int off=0)=0;
|
||||||
|
using badChannelCorrections::setBadChannelCorrection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
set bad channels correction
|
set bad channels correction
|
||||||
@ -96,30 +98,7 @@ class postProcessing : public angularConversion, public fileIO, public badChanne
|
|||||||
*/
|
*/
|
||||||
virtual int setBadChannelCorrection(int nch, int *chs, int ff=0)=0;
|
virtual int setBadChannelCorrection(int nch, int *chs, int ff=0)=0;
|
||||||
|
|
||||||
/**
|
|
||||||
flat field correct data
|
|
||||||
\param datain data
|
|
||||||
\param errin error on data (if<=0 will default to sqrt(datain)
|
|
||||||
\param dataout corrected data
|
|
||||||
\param errout error on corrected data
|
|
||||||
\param ffcoefficient flat field correction coefficient
|
|
||||||
\param fferr erro on ffcoefficient
|
|
||||||
\returns 0
|
|
||||||
*/
|
|
||||||
static int flatFieldCorrect(double datain, double errin, double &dataout, double &errout, double ffcoefficient, double fferr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
rate correct data
|
|
||||||
\param datain data
|
|
||||||
\param errin error on data (if<=0 will default to sqrt(datain)
|
|
||||||
\param dataout corrected data
|
|
||||||
\param errout error on corrected data
|
|
||||||
\param tau dead time 9in ns)
|
|
||||||
\param t acquisition time (in ns)
|
|
||||||
\returns 0
|
|
||||||
*/
|
|
||||||
static int rateCorrect(double datain, double errin, double &dataout, double &errout, double tau, double t);
|
|
||||||
|
|
||||||
|
|
||||||
int enableWriteToFile(int i=-1) {if (i>0) ((*correctionMask)|=(1<<WRITE_FILE)); else if (i==0) ((*correctionMask)&=~(1<< WRITE_FILE)); return (((*correctionMask)&(1<< WRITE_FILE ))>>WRITE_FILE) ;};
|
int enableWriteToFile(int i=-1) {if (i>0) ((*correctionMask)|=(1<<WRITE_FILE)); else if (i==0) ((*correctionMask)&=~(1<< WRITE_FILE)); return (((*correctionMask)&(1<< WRITE_FILE ))>>WRITE_FILE) ;};
|
||||||
|
|
||||||
@ -201,6 +180,10 @@ s
|
|||||||
*/
|
*/
|
||||||
int* popDataQueue();
|
int* popDataQueue();
|
||||||
|
|
||||||
|
int* dataQueueFront();
|
||||||
|
|
||||||
|
int dataQueueSize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
pops the data from thepostprocessed data queue
|
pops the data from thepostprocessed data queue
|
||||||
\returns pointer to the popped data or NULL if the queue is empty.
|
\returns pointer to the popped data or NULL if the queue is empty.
|
||||||
@ -209,6 +192,10 @@ s
|
|||||||
detectorData* popFinalDataQueue();
|
detectorData* popFinalDataQueue();
|
||||||
|
|
||||||
|
|
||||||
|
int checkJoinThread();
|
||||||
|
void setJoinThread(int v);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
resets the raw data queue
|
resets the raw data queue
|
||||||
\sa dataQueue
|
\sa dataQueue
|
||||||
@ -234,9 +221,14 @@ s
|
|||||||
virtual int flatFieldCorrect(double*, double*, double*, double*)=0;
|
virtual int flatFieldCorrect(double*, double*, double*, double*)=0;
|
||||||
|
|
||||||
|
|
||||||
|
virtual int getNMods()=0;
|
||||||
|
|
||||||
|
|
||||||
|
int GetCurrentPositionIndex(){ pthread_mutex_lock(&mp); int retval=getCurrentPositionIndex(); pthread_mutex_unlock(&mp); return retval;};
|
||||||
|
void IncrementPositionIndex(){ pthread_mutex_lock(&mp); incrementPositionIndex(); pthread_mutex_unlock(&mp);};
|
||||||
|
void IncrementFileIndex(){ pthread_mutex_lock(&mp); incrementFileIndex(); pthread_mutex_unlock(&mp);};
|
||||||
|
|
||||||
|
void ResetPositionIndex(){pthread_mutex_lock(&mp); resetPositionIndex(); pthread_mutex_unlock(&mp);};
|
||||||
|
|
||||||
|
|
||||||
void registerDataCallback(int( *userCallback)(detectorData*, void*), void *pArg) {dataReady = userCallback; pCallbackArg = pArg;};
|
void registerDataCallback(int( *userCallback)(detectorData*, void*), void *pArg) {dataReady = userCallback; pCallbackArg = pArg;};
|
||||||
@ -246,8 +238,14 @@ s
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
virtual double getRateCorrectionTau()=0;
|
||||||
|
|
||||||
|
|
||||||
|
int positionFinished(int v=-1){pthread_mutex_lock(&mp); if (v>=0) posfinished=v; int retval=posfinished; pthread_mutex_unlock(&mp); return retval;};
|
||||||
|
|
||||||
|
double getCurrentPosition() {double p; pthread_mutex_lock(&mp); p=currentPosition; pthread_mutex_unlock(&mp); return p;}
|
||||||
|
int setCurrentPosition(double v) { pthread_mutex_lock(&mp); currentPosition=v; pthread_mutex_unlock(&mp); }
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -257,7 +255,8 @@ s
|
|||||||
|
|
||||||
char *flatFieldDir;
|
char *flatFieldDir;
|
||||||
char *flatFieldFile;
|
char *flatFieldFile;
|
||||||
|
|
||||||
|
int64_t *expTime;
|
||||||
|
|
||||||
/** mutex to synchronize main and data processing threads */
|
/** mutex to synchronize main and data processing threads */
|
||||||
pthread_mutex_t mp;
|
pthread_mutex_t mp;
|
||||||
@ -309,26 +308,22 @@ s
|
|||||||
*/
|
*/
|
||||||
double currentI0;
|
double currentI0;
|
||||||
|
|
||||||
|
|
||||||
|
int arraySize;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
double *fdata;
|
double *fdata;
|
||||||
|
|
||||||
// private:
|
|
||||||
|
|
||||||
|
|
||||||
/* virtual void incrementProgress()=0; */
|
|
||||||
/* virtual double getCurrentProgress()=0; */
|
|
||||||
/* virtual void incrementFileIndex()=0; */
|
|
||||||
/* virtual int setTotalProgress()=0; */
|
|
||||||
|
|
||||||
|
|
||||||
/* virtual double* decodeData(int *datain, double *fdata=NULL)=0; */
|
|
||||||
/* virtual int getTotalNumberOfChannels()=0; */
|
|
||||||
|
|
||||||
|
|
||||||
int (*dataReady)(detectorData*,void*);
|
int (*dataReady)(detectorData*,void*);
|
||||||
void *pCallbackArg;
|
void *pCallbackArg;
|
||||||
|
|
||||||
int (*rawDataReady)(double*,void*);
|
int (*rawDataReady)(double*,void*);
|
||||||
void *pRawDataArg;
|
void *pRawDataArg;
|
||||||
|
|
||||||
|
|
||||||
|
postProcessingFuncs *ppFun;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
438
slsDetectorSoftware/slsDetectorAnalysis/postProcessingFuncs.cpp
Normal file
438
slsDetectorSoftware/slsDetectorAnalysis/postProcessingFuncs.cpp
Normal file
@ -0,0 +1,438 @@
|
|||||||
|
#include "postProcessingFuncs.h"
|
||||||
|
#include "angleConversionConstant.h"
|
||||||
|
|
||||||
|
|
||||||
|
postProcessingFuncs::postProcessingFuncs(int *nModules,int *chPerMod,int modMask[],int badCh[], double ffcoeff[], double fferr[], double* t, int *dir, double angRadius[], double angOffset[], double angCentre[], double* to, double* bs, double *sX, double *sY):
|
||||||
|
nMods(0), chansPerMod(NULL), moduleMask(NULL), badChannelMask(NULL), ffCoeff(NULL), ffErr(NULL), tDead(0), angDir(1), angConv(NULL), totalOffset(0), binSize(0), sampleX(0), sampleY(0), totalChans(0), nBins(0), mp(NULL), mv(NULL), me(NULL), mm(NULL)
|
||||||
|
{
|
||||||
|
initDataset(nModules, chPerMod,modMask,badCh, ffcoeff, fferr, t, dir, angRadius, angOffset, angCentre, to, bs, sX, sY);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int postProcessingFuncs::initDataset() {
|
||||||
|
|
||||||
|
if (nBins) {
|
||||||
|
mp=new double[nBins];
|
||||||
|
mv=new double[nBins];
|
||||||
|
me=new double[nBins];
|
||||||
|
mm=new int[nBins];
|
||||||
|
resetMerging(mp,mv,me,mm, nBins);
|
||||||
|
} else {
|
||||||
|
mv=new double[totalChans];
|
||||||
|
me=new double[totalChans];
|
||||||
|
}
|
||||||
|
totalI0=0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int postProcessingFuncs::finalizeDataset(double *ang, double *val, double *err, int *np) {
|
||||||
|
|
||||||
|
if (nBins)
|
||||||
|
*np=finalizeMerging(mp,mv,me,mm,nBins);
|
||||||
|
else
|
||||||
|
*np=totalChans;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (totalI0<=0)
|
||||||
|
totalI0=1.;
|
||||||
|
|
||||||
|
|
||||||
|
for (int ip=0; ip<(*np); ip++) {
|
||||||
|
|
||||||
|
if (mp)
|
||||||
|
ang[ip]=mp[ip];
|
||||||
|
|
||||||
|
if (mv)
|
||||||
|
val[ip]=mv[ip]*totalI0;
|
||||||
|
|
||||||
|
if (me)
|
||||||
|
err[ip]=me[ip]*totalI0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (mp)
|
||||||
|
delete [] mp;
|
||||||
|
if (mv)
|
||||||
|
delete [] mv;
|
||||||
|
if (me)
|
||||||
|
delete [] me;
|
||||||
|
if (mm)
|
||||||
|
delete [] mm;
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int postProcessingFuncs::addFrame(double *data, double *pos, double *I0, double *expTime, const char *filename, int *var) {
|
||||||
|
|
||||||
|
|
||||||
|
double p1, vin, ein, vout, eout;
|
||||||
|
double e=0.;
|
||||||
|
double i0=*I0;
|
||||||
|
|
||||||
|
if (i0>0)
|
||||||
|
totalI0+=i0;
|
||||||
|
|
||||||
|
for (int ich=0; ich<totalChans; ich++) {
|
||||||
|
|
||||||
|
vin=data[ich];
|
||||||
|
ein=0;
|
||||||
|
vout=data[ich];
|
||||||
|
if (vout>=0)
|
||||||
|
eout=sqrt(vout);
|
||||||
|
else
|
||||||
|
eout=0;
|
||||||
|
|
||||||
|
//ratecorrect
|
||||||
|
|
||||||
|
if (tDead) {
|
||||||
|
rateCorrect(vin, ein, vout, eout, tDead, *expTime);
|
||||||
|
vin=vout;
|
||||||
|
ein=eout;
|
||||||
|
}
|
||||||
|
//ffcorrect
|
||||||
|
|
||||||
|
if (ffCoeff) {
|
||||||
|
if (ffErr)
|
||||||
|
e=ffErr[ich];
|
||||||
|
else
|
||||||
|
e=0;
|
||||||
|
flatFieldCorrect(vin, ein, vout, eout, ffCoeff[ich], e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//i0correct
|
||||||
|
if (i0>0) {
|
||||||
|
vout/=i0;
|
||||||
|
eout/=i0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (badChannelMask)
|
||||||
|
if (badChannelMask[ich])
|
||||||
|
continue;
|
||||||
|
if (nBins) {
|
||||||
|
//angconv
|
||||||
|
|
||||||
|
//check module mask?!?!?!?
|
||||||
|
|
||||||
|
|
||||||
|
p1=convertAngle(*pos,ich,chansPerMod,angConv,moduleMask,totalOffset,0,angDir);
|
||||||
|
|
||||||
|
addPointToMerging(p1,vout,eout,mp,mv,me,mm, binSize, nBins);
|
||||||
|
} else {
|
||||||
|
mv[ich]+=vout;
|
||||||
|
me[ich]+=eout*eout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int postProcessingFuncs::initDataset(int *nModules,int *chPerMod,int modMask[],int badCh[], double ffcoeff[], double fferr[], double* t, int *dir, double angRadius[], double angOffset[], double angCenter[], double* to, double* bs, double *sX, double *sY) {
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "delete pointers " << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
deletePointers();
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "nmod " << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (nModules)
|
||||||
|
nMods=*nModules;
|
||||||
|
else
|
||||||
|
nMods=0;
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "tdead " << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (t)
|
||||||
|
tDead=*t;
|
||||||
|
else
|
||||||
|
t=0;
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "toffset " << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (to)
|
||||||
|
totalOffset=*to;
|
||||||
|
else
|
||||||
|
to=0;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "binsize " << endl;
|
||||||
|
#endif
|
||||||
|
if (bs)
|
||||||
|
binSize=*bs;
|
||||||
|
else
|
||||||
|
binSize=0;
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "samplex " << endl;
|
||||||
|
#endif
|
||||||
|
if (sX)
|
||||||
|
sampleX=*sX;
|
||||||
|
else
|
||||||
|
sampleX=0;
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "sampley " << endl;
|
||||||
|
#endif
|
||||||
|
if (sY)
|
||||||
|
sampleY=*sY;
|
||||||
|
else
|
||||||
|
sampleY=0;
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "angdir " << endl;
|
||||||
|
#endif
|
||||||
|
if (dir)
|
||||||
|
angDir=*dir;
|
||||||
|
else
|
||||||
|
angDir=1;
|
||||||
|
|
||||||
|
totalChans=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
chansPerMod=new int [nMods];
|
||||||
|
|
||||||
|
|
||||||
|
moduleMask=new int [nMods];
|
||||||
|
|
||||||
|
nBins=0;
|
||||||
|
if (angRadius && angOffset && angCenter && (binSize>0)) {
|
||||||
|
angConv=new angleConversionConstant*[nMods];
|
||||||
|
nBins=360./binSize+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int im=0; im<nMods; im++) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "MODULE "<< im << endl;
|
||||||
|
#endif
|
||||||
|
chansPerMod[im]=chPerMod[im];
|
||||||
|
moduleMask[im]=modMask[im];
|
||||||
|
totalChans+=chansPerMod[im];
|
||||||
|
|
||||||
|
if (angConv) {
|
||||||
|
angConv[im]=new angleConversionConstant(angCenter[im], angRadius[im], angOffset[im], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "badchans " << endl;
|
||||||
|
#endif
|
||||||
|
if (badCh)
|
||||||
|
badChannelMask= new int[totalChans];
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "ffcoeff " << endl;
|
||||||
|
#endif
|
||||||
|
if (ffcoeff)
|
||||||
|
ffCoeff=new double[totalChans];
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "fferr " << endl;
|
||||||
|
#endif
|
||||||
|
if (fferr)
|
||||||
|
ffErr=new double[totalChans];
|
||||||
|
|
||||||
|
|
||||||
|
for (int ich=0; ich<totalChans; ich++) {
|
||||||
|
if (badChannelMask)
|
||||||
|
badChannelMask[ich]=badCh[ich];
|
||||||
|
if (ffCoeff)
|
||||||
|
ffCoeff[ich]=ffcoeff[ich];
|
||||||
|
if (ffErr)
|
||||||
|
ffErr[ich]=fferr[ich];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void postProcessingFuncs::deletePointers() {
|
||||||
|
|
||||||
|
delete [] chansPerMod;
|
||||||
|
|
||||||
|
delete [] moduleMask;
|
||||||
|
if (badChannelMask)
|
||||||
|
delete [] badChannelMask;
|
||||||
|
|
||||||
|
if (ffCoeff)
|
||||||
|
delete [] ffCoeff;
|
||||||
|
|
||||||
|
if (ffErr)
|
||||||
|
delete [] ffErr;
|
||||||
|
|
||||||
|
if (angConv) {
|
||||||
|
for (int im=0; im<nMods; im++) {
|
||||||
|
if (angConv[im])
|
||||||
|
delete angConv[im];
|
||||||
|
}
|
||||||
|
delete [] angConv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
postProcessingFuncs::~postProcessingFuncs(){
|
||||||
|
|
||||||
|
deletePointers();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int postProcessingFuncs::flatFieldCorrect(double datain, double errin, double &dataout, double &errout, double ffcoefficient, double fferr){
|
||||||
|
double e;
|
||||||
|
|
||||||
|
dataout=datain*ffcoefficient;
|
||||||
|
|
||||||
|
if (errin==0 && datain>=0)
|
||||||
|
e=sqrt(datain);
|
||||||
|
else
|
||||||
|
e=errin;
|
||||||
|
|
||||||
|
if (dataout>0)
|
||||||
|
errout=sqrt(e*ffcoefficient*e*ffcoefficient+datain*fferr*datain*fferr);
|
||||||
|
else
|
||||||
|
errout=1.0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int postProcessingFuncs::rateCorrect(double datain, double errin, double &dataout, double &errout, double tau, double t){
|
||||||
|
|
||||||
|
// double data;
|
||||||
|
double e;
|
||||||
|
|
||||||
|
dataout=(datain*exp(tau*datain/t));
|
||||||
|
|
||||||
|
if (errin==0 && datain>=0)
|
||||||
|
e=sqrt(datain);
|
||||||
|
else
|
||||||
|
e=errin;
|
||||||
|
|
||||||
|
if (dataout>0)
|
||||||
|
errout=e*dataout*sqrt((1/(datain*datain)+tau*tau/(t*t)));
|
||||||
|
else
|
||||||
|
errout=1.;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int postProcessingFuncs::calculateFlatField(int* nModules, int *chPerMod, int *moduleMask, int *badChannelMask, double *ffData, double *ffCoeff, double *ffErr) {
|
||||||
|
int nmed=0, im=0;
|
||||||
|
double *xmed;
|
||||||
|
|
||||||
|
if (chPerMod==NULL)
|
||||||
|
return -1;
|
||||||
|
// if (moduleMask==NULL)
|
||||||
|
// return -1;
|
||||||
|
if (ffData==NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (ffErr==NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
|
int totch=0;
|
||||||
|
for (int im=0; im<*nModules; im++) {
|
||||||
|
totch+=chPerMod[im];
|
||||||
|
}
|
||||||
|
|
||||||
|
xmed=new double[totch];
|
||||||
|
|
||||||
|
for (int ich=0; ich<totch; ich++) {
|
||||||
|
|
||||||
|
if (badChannelMask)
|
||||||
|
if (badChannelMask[ich])
|
||||||
|
continue;
|
||||||
|
// calculate median if ffData is positive and channel is good
|
||||||
|
|
||||||
|
if (ffData[ich]>0) {
|
||||||
|
im=0;
|
||||||
|
while ((im<nmed) && (xmed[im]<ffData[ich]))
|
||||||
|
im++;
|
||||||
|
for (int i=nmed; i>im; i--)
|
||||||
|
xmed[i]=xmed[i-1];
|
||||||
|
|
||||||
|
xmed[im]=ffData[ich];
|
||||||
|
nmed++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (nmed>1 && xmed[nmed/2]>0) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout<< "Flat field median is " << xmed[nmed/2] << " calculated using "<< nmed << " points" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (int ich=0; ich<totch; ich++) {
|
||||||
|
if (badChannelMask)
|
||||||
|
if (badChannelMask[ich]) {
|
||||||
|
ffCoeff[ich]=0.;
|
||||||
|
ffErr[ich]=1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (ffData[ich]>0) {
|
||||||
|
ffCoeff[ich]=xmed[nmed/2]/ffData[ich];
|
||||||
|
ffErr[ich]=ffCoeff[ich]*sqrt(ffData[ich])/ffData[ich];
|
||||||
|
} else {
|
||||||
|
ffCoeff[ich]=0.;
|
||||||
|
ffErr[ich]=1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] xmed;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
|||||||
|
#ifndef POSTPROCESSINGFUNCS_H
|
||||||
|
#define POSTPROCESSINGFUNC_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <queue>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "angularConversionStatic.h"
|
||||||
|
class angleConversionConstant;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
class postProcessingFuncs : public virtual angularConversionStatic
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
postProcessingFuncs(int *nModules=NULL,int *chPerMod=NULL,int *modMask=NULL,int *badChMask=NULL, double *ffcoeff=NULL, double *fferr=NULL, double* t=NULL, int *dir=NULL, double *angRadius=NULL, double *angOffset=NULL, double *angCentre=NULL, double* to=NULL, double* bs=NULL, double *sX=NULL, double *sY=NULL);
|
||||||
|
|
||||||
|
|
||||||
|
~postProcessingFuncs();
|
||||||
|
|
||||||
|
|
||||||
|
int initDataset(int *nModules,int *chPerMod,int modMask[],int badCh[], double ffcoeff[], double fferr[], double* tDead, int *dir, double angRadius[], double angOffset[], double angCentre[], double* to, double* bs, double *sX, double *sY);
|
||||||
|
|
||||||
|
int initDataset();
|
||||||
|
|
||||||
|
|
||||||
|
int finalizeDataset(double ang[], double val[], double err[], int *np);
|
||||||
|
|
||||||
|
int addFrame(double data[], double *pos, double *IO, double *expTime, const char *filename, int *var=0);
|
||||||
|
|
||||||
|
static int calculateFlatField(int* nModules, int *chPerMod, int moduleMask[], int badChannelMask[], double ffData[], double ffCoeff[], double ffErr[]);
|
||||||
|
|
||||||
|
static int flatFieldCorrect(double datain, double errin, double &dataout, double &errout, double ffcoefficient, double fferr);
|
||||||
|
|
||||||
|
|
||||||
|
static int rateCorrect(double datain, double errin, double &dataout, double &errout, double tau, double t);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void deletePointers();
|
||||||
|
|
||||||
|
|
||||||
|
int nMods;
|
||||||
|
int *chansPerMod;
|
||||||
|
int *moduleMask;
|
||||||
|
int *badChannelMask;
|
||||||
|
double *ffCoeff;
|
||||||
|
double *ffErr;
|
||||||
|
double tDead;
|
||||||
|
int angDir;
|
||||||
|
angleConversionConstant **angConv;
|
||||||
|
double totalOffset;
|
||||||
|
double binSize;
|
||||||
|
double sampleX;
|
||||||
|
double sampleY;
|
||||||
|
int totalChans;
|
||||||
|
|
||||||
|
int nBins;
|
||||||
|
|
||||||
|
double totalI0;
|
||||||
|
|
||||||
|
|
||||||
|
double *mp, *mv,*me;
|
||||||
|
int *mm;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user