included accumulate, pedestal and binary

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@204 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
l_maliakal_d 2013-07-17 14:54:42 +00:00
parent 12f48fb0d2
commit d84f95456b
5 changed files with 922 additions and 436 deletions

File diff suppressed because it is too large Load Diff

View File

@ -131,6 +131,9 @@ public:
*/
void UpdateAfterCloning(bool points, bool logy, bool interpolate, bool contour, bool logz);
/** set binary range */
void SetBinary(bool enable, int from=0, int to=0);
public slots:
/** To select 1D or 2D plot
@param i is 1 for 1D, else 2D plot */
@ -161,14 +164,14 @@ void SetMarkers(bool enable){markers = enable;};
void SetScanArgument(int scanArg);
/** sets stop_signal to true */
void StopAcquisition(){ stop_signal = true; };
//pedestal
/** reset pedestal */
void ResetPedestal();
/** Calculate Pedestal */
void CalculatePedestal();
/** Set/unset pedestal */
void SetPedestal(bool enable);
/** Recalculate Pedestal */
void RecalculatePedestal();
/** Set/unset accumulate */
void SetAccumulate(bool enable);
/** Reset accumulation */
void ResetAccumulate();
private:
@ -491,12 +494,27 @@ bool originally2D;
//pedstal
/** Number of pedestal frames*/
static const int NUM_PEDESTAL_FRAMES = 20;
/**reset pedestal*/
bool resetPedestal;
/** set/unset pedestal*/
bool pedestal;
/** pedestal values */
double* pedestalVals;
/** temporary pedestal values to hide while recalculating*/
double* tempPedestalVals;
/** count for 20 frames to calculate the pedestal */
int pedestalCount;
/** start pedestal calculation */
bool startPedestalCal;
//accumulation
/** set/unset accumulation */
bool accumulate;
/** to reset accumulation */
bool resetAccumulate;
/** range for binary plot output */
bool binary;
int binaryFrom;
int binaryTo;
/** this is set when client starts/stops acquisition
* and is reset once the gui really starts/stops */

View File

@ -147,12 +147,14 @@ private slots:
/** Set Plot to none, data graph, histogram*/
void SetPlot();
/** Change pages in 1D box*/
void Set1DPage();
/** Change pages in plot options box to the right*/
void SetPlotOptionsRightPage();
/** Change pages in 2D box*/
void Set2DPage();
/** Change pages in plot options box to the left*/
void SetPlotOptionsLeftPage();
/** Plot binary plot */
void SetBinary();
signals:
void DisableZoomSignal(bool);

View File

@ -179,15 +179,23 @@ void qDrawPlot::SetupWidgetWindow(){
fileSaveEnable= myDet->enableWriteToFile();
//pedestal
resetPedestal = true;
pedestal = false;
pedestalVals = 0;
pedestalCount = -1;
tempPedestalVals = 0;
pedestalCount = 0;
startPedestalCal = false;
if(myDet->getDetectorsType()==slsDetectorDefs::GOTTHARD)
pedestalCount = 0;
//accumulate
accumulate = false;
resetAccumulate = false;
clientInitiated = false;
//binary plot output
binary = false;
binaryFrom = 0;
binaryTo = 0;
//widget related initialization
// clone
@ -854,70 +862,95 @@ int qDrawPlot::GetData(detectorData *data,int fIndex){
for(int i=currentPersistency;i>0;i--)
memcpy(histYAxis[i],histYAxis[i-1],nPixelsX*sizeof(double));
//normal data
if(resetPedestal){
memcpy(histYAxis[0],data->values,nPixelsX*sizeof(double));
}else{
//recalculating pedestal
if(startPedestalCal){
pedestalCount++;
//start adding frames to get to the pedestal value
if(pedestalCount<NUM_PEDESTAL_FRAMES){
for(unsigned int px=0;px<nPixelsX;px++)
pedestalVals[px] += data->values[px];
tempPedestalVals[px] += data->values[px];
memcpy(histYAxis[0],data->values,nPixelsX*sizeof(double));
}
//calculate the pedestal value
else if(pedestalCount==NUM_PEDESTAL_FRAMES){
cout << "Pedestal Calculated" << endl;
for(unsigned int px=0;px<nPixelsX;px++)
pedestalVals[px] = pedestalVals[px]/(double)NUM_PEDESTAL_FRAMES;
memcpy(histYAxis[0],data->values,nPixelsX*sizeof(double));
tempPedestalVals[px] = tempPedestalVals[px]/(double)NUM_PEDESTAL_FRAMES;
memcpy(pedestalVals,tempPedestalVals,nPixelsX*sizeof(double));
startPedestalCal = 0;
}
//use this pedestal value henceforth
else{
for(unsigned int px=0;px<nPixelsX;px++)
histYAxis[0][px] = data->values[px] - (pedestalVals[px]);
}
pedestalCount++;
}
//normal data
if(((!pedestal)&(!accumulate)) || (resetAccumulate)){
memcpy(histYAxis[0],data->values,nPixelsX*sizeof(double));
resetAccumulate = false;
}
//pedestal or accumulate
else{
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++){
if(accumulate)
histYAxis[0][px] += data->values[px];
else
histYAxis[0][px] = data->values[px];
if(pedestal)
histYAxis[0][px] = histYAxis[0][px] - (pedestalVals[px]);
if(binary) {
if ((histYAxis[0][px] >= binaryFrom) && (histYAxis[0][px] <= binaryTo))
histYAxis[0][px] = 1;
else
histYAxis[0][px] = 0;
}
}
}
}
//2d
else{
// Titles
imageTitle = temp_title;
// manufacture data for now
/* default data
for(unsigned int px=0;px<nPixelsX;px++)
for(unsigned int py=0;py<nPixelsY;py++)
lastImageArray[py*nPixelsX+px] = sqrt(pow(currentFrame+1,2)*pow(double(px)-nPixelsX/2,2)/pow(nPixelsX/2,2)/pow(number_of_exposures+1,2) + pow(double(py)-nPixelsY/2,2)/pow(nPixelsY/2,2))/sqrt(2);
*/
// copy data
/*memcpy(lastImageArray,data->values,nPixelsX*nPixelsY*sizeof(double));*/
//normal data
if(resetPedestal){
memcpy(lastImageArray,data->values,nPixelsX*nPixelsY*sizeof(double));
}else{
//recalculating pedestal
if(startPedestalCal){
pedestalCount++;
//start adding frames to get to the pedestal value
if(pedestalCount<NUM_PEDESTAL_FRAMES){
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
pedestalVals[px] += data->values[px];
tempPedestalVals[px] += data->values[px];
memcpy(lastImageArray,data->values,nPixelsX*nPixelsY*sizeof(double));
}
//calculate the pedestal value
else if(pedestalCount==NUM_PEDESTAL_FRAMES){
cout << "Pedestal Calculated" << endl;
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
pedestalVals[px] = pedestalVals[px]/(double)NUM_PEDESTAL_FRAMES;
memcpy(lastImageArray,data->values,nPixelsX*nPixelsY*sizeof(double));
}
//use this pedestal value henceforth
else{
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
lastImageArray[px] = data->values[px] - (pedestalVals[px]);
}
pedestalCount++;
tempPedestalVals[px] = tempPedestalVals[px]/(double)NUM_PEDESTAL_FRAMES;
memcpy(pedestalVals,tempPedestalVals,nPixelsX*nPixelsY*sizeof(double));
startPedestalCal = 0;
}
}
//normal data
if(((!pedestal)&(!accumulate)) || (resetAccumulate)){
memcpy(lastImageArray,data->values,nPixelsX*nPixelsY*sizeof(double));
resetAccumulate = false;
}
//pedestal or accumulate or binary
else{
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++){
if(accumulate)
lastImageArray[px] += data->values[px];
else
lastImageArray[px] = data->values[px];
if(pedestal)
lastImageArray[px] = lastImageArray[px] - (pedestalVals[px]);
if(binary) {
if ((lastImageArray[px] >= binaryFrom) && (lastImageArray[px] <= binaryTo))
lastImageArray[px] = 1;
else
lastImageArray[px] = 0;
}
}
}
}
pthread_mutex_unlock(&(last_image_complete_mutex));
}
@ -1591,15 +1624,41 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::ResetPedestal(){
void qDrawPlot::SetPedestal(bool enable){
#ifdef VERBOSE
cout << "Resetting Pedestal" << endl;
cout << "Setting Pedestal to " << enable << endl;
#endif
if(enable){
pedestal = true;
if(pedestalVals == 0)
RecalculatePedestal();
}else{
pedestal = false;
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::RecalculatePedestal(){
#ifdef VERBOSE
cout << "Recalculating Pedestal" << endl;
#endif
while(1){
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){
pedestalVals = 0;
startPedestalCal = 1;
pedestalCount = 0;
resetPedestal = true;
//create array
if(pedestalVals) delete [] pedestalVals; pedestalVals = new double[nPixelsX*nPixelsY];
if(tempPedestalVals) delete [] tempPedestalVals; tempPedestalVals = new double[nPixelsX*nPixelsY];
//reset all values
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
pedestalVals[px] = 0;
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
tempPedestalVals[px] = 0;
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
@ -1610,20 +1669,23 @@ void qDrawPlot::ResetPedestal(){
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::CalculatePedestal(){
void qDrawPlot::SetAccumulate(bool enable){
#ifdef VERBOSE
cout << "Calculating Pedestal" << endl;
cout << "Setting Accumulate to " << enable << endl;
#endif
accumulate = enable;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::ResetAccumulate(){
#ifdef VERBOSE
cout << "Resetting Accumulation" << endl;
#endif
while(1){
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){
//create array
if(pedestalVals) delete [] pedestalVals; pedestalVals = new double[nPixelsX*nPixelsY];
//reset all values
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
pedestalVals[px] = 0;
pedestalCount = 0;
resetPedestal = false;
resetAccumulate = true;
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
@ -1672,3 +1734,19 @@ void qDrawPlot::UpdateAfterCloning(bool points, bool logy, bool interpolate, boo
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::SetBinary(bool enable, int from, int to){
#ifdef VERBOSE
if(!enable)
cout << "Disabling Binary output " << endl;
else
cout << "Enabling Binary output from " << from << " to " << to << endl;
#endif
binary = enable;
binaryFrom = from;
binaryTo = to;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -139,13 +139,37 @@ void qTabPlot::SetupWidgetWindow(){
stackedLayout->addWidget(spinNthFrame);
stackWidget->setLayout(stackedLayout);
stackedWidget->setCurrentIndex(0);
stackedWidget_2->setCurrentIndex(0);
// Depending on whether the detector is 1d or 2d
switch(myDet->getDetectorsType()){
case slsDetectorDefs::MYTHEN: isOriginallyOneD = true; break;
case slsDetectorDefs::EIGER: isOriginallyOneD = false; break;
case slsDetectorDefs::GOTTHARD: isOriginallyOneD = true; break;
case slsDetectorDefs::MOENCH: isOriginallyOneD = false; break;
case slsDetectorDefs::MYTHEN:
isOriginallyOneD = true;
chkPedestal->setEnabled(false);
btnRecalPedestal->setEnabled(false);
layoutThreshold->setEnabled(false);
chkPedestal_2->setEnabled(false);
btnRecalPedestal_2->setEnabled(false);
chkBinary->setEnabled(false);
chkBinary_2->setEnabled(false);
break;
case slsDetectorDefs::EIGER:
isOriginallyOneD = false;
chkPedestal->setEnabled(false);
btnRecalPedestal->setEnabled(false);
layoutThreshold->setEnabled(false);
chkPedestal_2->setEnabled(false);
btnRecalPedestal_2->setEnabled(false);
chkBinary->setEnabled(false);
chkBinary_2->setEnabled(false);
break;
case slsDetectorDefs::GOTTHARD:
isOriginallyOneD = true;
break;
case slsDetectorDefs::MOENCH:
isOriginallyOneD = false;
break;
default:
cout << "ERROR: Detector Type is Generic" << endl;
exit(-1);
@ -158,17 +182,6 @@ void qTabPlot::SetupWidgetWindow(){
//to check if this should be enabled
EnableScanBox();
stackedWidget->setCurrentIndex(0);
stackedWidget_2->setCurrentIndex(0);
if(myDet->getDetectorsType()!=slsDetectorDefs::GOTTHARD){
btnCalPedestal->setEnabled(false);
btnResetPedestal->setEnabled(false);
}
if(myDet->getDetectorsType()!=slsDetectorDefs::MOENCH){
btnCalPedestal_2->setEnabled(false);
btnResetPedestal_2->setEnabled(false);
}
qDefs::checkErrorMessage(myDet);
}
@ -176,36 +189,44 @@ void qTabPlot::SetupWidgetWindow(){
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabPlot::Set2DPage(){
//QPushButton *clickedButton = qobject_cast<QPushButton *>(sender());
if(stackedWidget_2->currentIndex()==0){
stackedWidget_2->setCurrentIndex(1);
box2D->setTitle("2D Plot Options 2");
void qTabPlot::SetPlotOptionsRightPage(){
if(isOneD){
int i = stackedWidget->currentIndex();
if(i == (stackedWidget->count()-1))
stackedWidget->setCurrentIndex(0);
else
stackedWidget->setCurrentIndex(i+1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget->currentIndex()+1));
}
else{
stackedWidget_2->setCurrentIndex(0);
box2D->setTitle("2D Plot Options 1");
int i = stackedWidget_2->currentIndex();
if(i == (stackedWidget_2->count()-1))
stackedWidget_2->setCurrentIndex(0);
else
stackedWidget_2->setCurrentIndex(i+1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget_2->currentIndex()+1));
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabPlot::Set1DPage(){
//QPushButton *clickedButton = qobject_cast<QPushButton *>(sender());
if(stackedWidget->currentIndex()==0){
//if(clickedButton->icon().pixmap(QSize(16,16)).toImage()==btnLeft->icon().pixmap(QSize(16,16)).toImage())
stackedWidget->setCurrentIndex(1);
box1D->setTitle("1D Plot Options 2");
}
else if(stackedWidget->currentIndex()==1){
stackedWidget->setCurrentIndex(2);
box1D->setTitle("1D Plot Options 3");
void qTabPlot::SetPlotOptionsLeftPage(){
if(isOneD){
int i = stackedWidget->currentIndex();
if(i == 0)
stackedWidget->setCurrentIndex(stackedWidget->count()-1);
else
stackedWidget->setCurrentIndex(i-1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget->currentIndex()+1));
}
else{
stackedWidget->setCurrentIndex(0);
box1D->setTitle("1D Plot Options 1");
int i = stackedWidget_2->currentIndex();
if(i == 0)
stackedWidget_2->setCurrentIndex(stackedWidget_2->count()-1);
else
stackedWidget_2->setCurrentIndex(i-1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget_2->currentIndex()+1));
}
}
@ -215,6 +236,14 @@ void qTabPlot::Set1DPage(){
void qTabPlot::Select1DPlot(bool b){
isOneD = b;
lblFrom->setEnabled(false);
lblTo->setEnabled(false);
lblFrom_2->setEnabled(false);
lblTo_2->setEnabled(false);
spinFrom->setEnabled(false);
spinFrom_2->setEnabled(false);
spinTo->setEnabled(false);
spinTo_2->setEnabled(false);
if(b){
box1D->show();
box2D->hide();
@ -247,22 +276,20 @@ void qTabPlot::Initialization(){
connect(btnCloseClones, SIGNAL(clicked()),myPlot, SLOT(CloseClones()));
connect(btnSaveClones, SIGNAL(clicked()),myPlot, SLOT(SaveClones()));
// 1D Plot box
//to change pages
connect(btnRight, SIGNAL(clicked()), this, SLOT(SetPlotOptionsRightPage()));
connect(btnLeft, SIGNAL(clicked()), this, SLOT(SetPlotOptionsLeftPage()));
connect(chkSuperimpose, SIGNAL(toggled(bool)), this, SLOT(EnablePersistency(bool)));
connect(spinPersistency,SIGNAL(valueChanged(int)), myPlot,SLOT(SetPersistency(int)));
connect(chkPoints, SIGNAL(toggled(bool)), myPlot, SLOT(SetMarkers(bool)));
connect(chkLines, SIGNAL(toggled(bool)), myPlot, SLOT(SetLines(bool)));
connect(chk1DLog, SIGNAL(toggled(bool)), myPlot, SIGNAL(LogySignal(bool)));
//to change pages
connect(btnRight, SIGNAL(clicked()), this, SLOT(Set1DPage()));
connect(btnRight2, SIGNAL(clicked()), this, SLOT(Set1DPage()));
connect(btnRight3, SIGNAL(clicked()), this, SLOT(Set1DPage()));
// 2D Plot box
connect(chkInterpolate, SIGNAL(toggled(bool)),myPlot, SIGNAL(InterpolateSignal(bool)));
connect(chkContour, SIGNAL(toggled(bool)),myPlot, SIGNAL(ContourSignal(bool)));
connect(chkLogz, SIGNAL(toggled(bool)),myPlot, SIGNAL(LogzSignal(bool)));
//to change pages
connect(btn2DRight, SIGNAL(clicked()), this, SLOT(Set2DPage()));
connect(btn2DRight2, SIGNAL(clicked()), this, SLOT(Set2DPage()));
// Plotting frequency box
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFrequency()));
connect(comboTimeGapUnit,SIGNAL(currentIndexChanged(int)), this, SLOT(SetFrequency()));
@ -299,11 +326,24 @@ void qTabPlot::Initialization(){
connect(this,SIGNAL(SetZRangeSignal(double,double)),myPlot, SIGNAL(SetZRangeSignal(double,double)));
//pedstal
connect(btnResetPedestal, SIGNAL(clicked()),myPlot, SLOT(ResetPedestal()));
connect(btnCalPedestal, SIGNAL(clicked()),myPlot, SLOT(CalculatePedestal()));
connect(btnResetPedestal_2, SIGNAL(clicked()),myPlot, SLOT(ResetPedestal()));
connect(btnCalPedestal_2, SIGNAL(clicked()),myPlot, SLOT(CalculatePedestal()));
connect(chkPedestal, SIGNAL(toggled(bool)), myPlot, SLOT(SetPedestal(bool)));
connect(btnRecalPedestal, SIGNAL(clicked()), myPlot, SLOT(RecalculatePedestal()));
connect(chkPedestal_2, SIGNAL(toggled(bool)), myPlot, SLOT(SetPedestal(bool)));
connect(btnRecalPedestal_2, SIGNAL(clicked()), myPlot, SLOT(RecalculatePedestal()));
//accumulate
connect(chkAccumulate, SIGNAL(toggled(bool)), myPlot, SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate, SIGNAL(clicked()), myPlot, SLOT(ResetAccumulate()));
connect(chkAccumulate_2, SIGNAL(toggled(bool)), myPlot, SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate_2, SIGNAL(clicked()), myPlot, SLOT(ResetAccumulate()));
//binary
connect(chkBinary, SIGNAL(toggled(bool)), this, SLOT(SetBinary()));
connect(chkBinary_2, SIGNAL(toggled(bool)), this, SLOT(SetBinary()));
connect(spinFrom, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
connect(spinFrom_2, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
connect(spinTo, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
connect(spinTo_2, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
}
@ -906,4 +946,57 @@ void qTabPlot::UpdateAfterCloning(){
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabPlot::SetBinary(){
//1d
if(isOneD){
if(chkBinary->isChecked()){
#ifdef VERBOSE
cout << endl << "Enabling Binary" << endl;
#endif
lblFrom->setEnabled(true);
lblTo->setEnabled(true);
spinFrom->setEnabled(true);
spinTo->setEnabled(true);
myPlot->SetBinary(true,spinFrom->value(),spinTo->value());
}else{
#ifdef VERBOSE
cout << endl << "Disabling Binary" << endl;
#endif
lblFrom->setEnabled(false);
lblTo->setEnabled(false);
spinFrom->setEnabled(false);
spinTo->setEnabled(false);
myPlot->SetBinary(false);
}
}
//2d
else{
if(chkBinary_2->isChecked()){
#ifdef VERBOSE
cout << endl << "Enabling Binary" << endl;
#endif
lblFrom_2->setEnabled(true);
lblTo_2->setEnabled(true);
spinFrom_2->setEnabled(true);
spinTo_2->setEnabled(true);
myPlot->SetBinary(true,spinFrom_2->value(),spinTo_2->value());
}else{
#ifdef VERBOSE
cout << endl << "Disabling Binary" << endl;
#endif
lblFrom_2->setEnabled(false);
lblTo_2->setEnabled(false);
spinFrom_2->setEnabled(false);
spinTo_2->setEnabled(false);
myPlot->SetBinary(false);
}
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------