Skip to content

Commit

Permalink
Call the correction algorithms from the UI
Browse files Browse the repository at this point in the history
Refs #10903
  • Loading branch information
DanNixon committed Mar 26, 2015
1 parent c747647 commit 96dceb1
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 10 deletions.
Expand Up @@ -23,7 +23,13 @@ namespace IDA
virtual bool validate();
virtual void loadSettings(const QSettings & settings);

private slots:
virtual void algorithmComplete(bool error);

private:
void addShapeSpecificSampleOptions(Mantid::API::IAlgorithm_sptr alg, QString shape);
void addShapeSpecificCanOptions(Mantid::API::IAlgorithm_sptr alg, QString shape);

Ui::AbsorptionCorrections m_uiForm;

};
Expand Down
Expand Up @@ -322,6 +322,23 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbCylEvents">
<property name="text">
<string>Neutron Events:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="spAnnEvents">
<property name="maximum">
<number>1000000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="pgCylinder">
Expand Down Expand Up @@ -363,6 +380,23 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spCylEvents">
<property name="maximum">
<number>1000000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbAnnEvents">
<property name="text">
<string>Neutron Events:</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down Expand Up @@ -425,15 +459,18 @@
<string>Container Details</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="lbCanChemicalFormula">
<property name="text">
<string>Chemical Formula:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="leCanChemicalFormula">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -442,8 +479,11 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="spCanNumberDensity">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string> A^-3</string>
</property>
Expand All @@ -455,7 +495,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="lbCanNumberDensity">
<property name="text">
<string>Number Density:</string>
Expand All @@ -479,8 +519,8 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="cbUseContainerCorrections">
<item row="2" column="0">
<widget class="QCheckBox" name="ckUseCanCorrections">
<property name="text">
<string>Use Container Corrections</string>
</property>
Expand All @@ -502,7 +542,7 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="cbKeepFactors">
<widget class="QCheckBox" name="ckKeepFactors">
<property name="text">
<string>Keep Correction Factors</string>
</property>
Expand Down Expand Up @@ -562,6 +602,31 @@
</customwidgets>
<tabstops>
<tabstop>ckUseCan</tabstop>
<tabstop>cbShape</tabstop>
<tabstop>spFlatSampleHeight</tabstop>
<tabstop>spFlatSampleWidth</tabstop>
<tabstop>spFlatSampleThickness</tabstop>
<tabstop>spFlatCanFrontThickness</tabstop>
<tabstop>spFlatCanBackThickness</tabstop>
<tabstop>spFlatElementSize</tabstop>
<tabstop>spAnnCanInnerRadius</tabstop>
<tabstop>spAnnSampleInnerRadius</tabstop>
<tabstop>spAnnSampleOuterRadius</tabstop>
<tabstop>spAnnCanOuterRadius</tabstop>
<tabstop>spAnnEvents</tabstop>
<tabstop>spCylSampleRadius</tabstop>
<tabstop>spCylCanRadius</tabstop>
<tabstop>spCylEvents</tabstop>
<tabstop>spSampleNumberDensity</tabstop>
<tabstop>leSampleChemicalFormula</tabstop>
<tabstop>ckScaleCan</tabstop>
<tabstop>spCanScale</tabstop>
<tabstop>ckUseCanCorrections</tabstop>
<tabstop>spCanNumberDensity</tabstop>
<tabstop>leCanChemicalFormula</tabstop>
<tabstop>ckKeepFactors</tabstop>
<tabstop>ckPlot</tabstop>
<tabstop>ckSave</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down Expand Up @@ -629,5 +694,37 @@
</hint>
</hints>
</connection>
<connection>
<sender>ckUseCanCorrections</sender>
<signal>toggled(bool)</signal>
<receiver>leCanChemicalFormula</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>156</x>
<y>447</y>
</hint>
<hint type="destinationlabel">
<x>436</x>
<y>528</y>
</hint>
</hints>
</connection>
<connection>
<sender>ckUseCanCorrections</sender>
<signal>toggled(bool)</signal>
<receiver>spCanNumberDensity</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>156</x>
<y>447</y>
</hint>
<hint type="destinationlabel">
<x>436</x>
<y>501</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@@ -1,6 +1,8 @@
#include "MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h"
#include "MantidQtCustomInterfaces/UserInputValidator.h"

using namespace Mantid::API;

namespace
{
Mantid::Kernel::Logger g_log("AbsorptionCorrections");
Expand All @@ -16,21 +18,166 @@ namespace IDA
IDATab(parent)
{
m_uiForm.setupUi(parent);

// Handle algorithm completion
connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)),
this, SLOT(algorithmComplete(bool)));
}


void AbsorptionCorrections::setup()
{
//TODO
}


void AbsorptionCorrections::run()
{
//TODO
// Get correct corrections algorithm
QString sampleShape = m_uiForm.cbShape->currentText();
QString algorithmName = "Indirect" + sampleShape.replace(" ", "") + "Absorption";

IAlgorithm_sptr absCorAlgo = AlgorithmManager::Instance().create(algorithmName.toStdString());
absCorAlgo->initialize();

// Sample details
QString sampleWsName = m_uiForm.dsSampleInput->getCurrentDataName();
absCorAlgo->setProperty("SampleWorkspace", sampleWsName.toStdString());

double sampleNumberDensity = m_uiForm.spSampleNumberDensity->value();
absCorAlgo->setProperty("SampleNumberDensity", sampleNumberDensity);

QString sampleChemicalFormula = m_uiForm.leSampleChemicalFormula->text();
absCorAlgo->setProperty("SampleChemicalFormula", sampleChemicalFormula.toStdString());

addShapeSpecificSampleOptions(absCorAlgo, sampleShape);

// Can details
bool useCan = m_uiForm.ckUseCan->isChecked();
if(useCan)
{
QString canWsName = m_uiForm.dsCanInput->getCurrentDataName();
absCorAlgo->setProperty("CanWorkspace", canWsName.toStdString());

bool useCanCorrections = m_uiForm.ckUseCanCorrections->isChecked();
absCorAlgo->setProperty("UseCanCorrections", useCanCorrections);

if(useCanCorrections)
{
double canNumberDensity = m_uiForm.spCanNumberDensity->value();
absCorAlgo->setProperty("CanNumberDensity", canNumberDensity);

QString canChemicalFormula = m_uiForm.leCanChemicalFormula->text();
absCorAlgo->setProperty("CanChemicalFormula", canChemicalFormula.toStdString());
}

addShapeSpecificCanOptions(absCorAlgo, sampleShape);
}

bool plot = m_uiForm.ckPlot->isChecked();
absCorAlgo->setProperty("Plot", plot);

// Generate workspace names
int nameCutIndex = sampleWsName.lastIndexOf("_");
if(nameCutIndex == -1)
nameCutIndex = sampleWsName.length();

QString outputBaseName = sampleWsName.left(nameCutIndex);

QString outputWsName = outputBaseName + "Corrected";
absCorAlgo->setProperty("OutputWorkspace", outputWsName.toStdString());

bool keepCorrectionFactors = m_uiForm.ckKeepFactors->isChecked();
if(keepCorrectionFactors)
{
QString outputFactorsWsName = outputBaseName + "Factors";
absCorAlgo->setProperty("CorrectionsWorkspace", outputFactorsWsName.toStdString());
}

// Run corrections algorithm
m_batchAlgoRunner->addAlgorithm(absCorAlgo);
m_batchAlgoRunner->executeBatchAsync();

// Set the result workspace for Python script export
m_pythonExportWsName = "";
}


/**
* Sets algorithm properties specific to the sample for a given shape.
*
* @param alg Algorithm to set properties of
* @param shape Sample shape
*/
void AbsorptionCorrections::addShapeSpecificSampleOptions(IAlgorithm_sptr alg, QString shape)
{
if(shape == "Flat Plate")
{
double sampleHeight = m_uiForm.spFlatSampleHeight->value();
alg->setProperty("SampleHeight", sampleHeight);

double sampleWidth = m_uiForm.spFlatSampleWidth->value();
alg->setProperty("SampleWidth", sampleWidth);

double sampleThickness = m_uiForm.spFlatSampleThickness->value();
alg->setProperty("SampleThickness", sampleThickness);

double elementSize = m_uiForm.spFlatElementSize->value();
alg->setProperty("ElementSize", elementSize);
}
else if(shape == "Annulus")
{
double sampleInnerRadius = m_uiForm.spAnnSampleInnerRadius->value();
alg->setProperty("SampleInnerRadius", sampleInnerRadius);

double sampleOuterRadius = m_uiForm.spAnnSampleOuterRadius->value();
alg->setProperty("SampleOuterRadius", sampleOuterRadius);

double canInnerRadius = m_uiForm.spAnnCanInnerRadius->value();
alg->setProperty("CanInnerRadius", canInnerRadius);

double canOuterRadius = m_uiForm.spAnnCanOuterRadius->value();
alg->setProperty("CanOuterRadius", canOuterRadius);

long events = static_cast<long>(m_uiForm.spAnnEvents->value());
alg->setProperty("Events", events);
}
else if(shape == "Cylinder")
{
double sampleRadius = m_uiForm.spCylSampleRadius->value();
alg->setProperty("SampleRadius", sampleRadius);

long events = static_cast<long>(m_uiForm.spCylEvents->value());
alg->setProperty("Events", events);
}
}


/**
* Sets algorithm properties specific to the can for a given shape.
*
* All options for Annulus are added in addShapeSpecificSampleOptions.
*
* @param alg Algorithm to set properties of
* @param shape Sample shape
*/
void AbsorptionCorrections::addShapeSpecificCanOptions(IAlgorithm_sptr alg, QString shape)
{
if(shape == "Flat Plate")
{
double canFrontThickness = m_uiForm.spFlatCanFrontThickness->value();
alg->setProperty("CanFrontThickness", canFrontThickness);

double canBackThickness = m_uiForm.spFlatCanBackThickness->value();
alg->setProperty("CanBackThickness", canBackThickness);
}
else if(shape == "Cylinder")
{
double canRadius = m_uiForm.spCylCanRadius->value();
alg->setProperty("CanRadius", canRadius);
}
}


bool AbsorptionCorrections::validate()
{
UserInputValidator uiv;
Expand All @@ -46,10 +193,25 @@ namespace IDA
return uiv.isAllInputValid();
}


void AbsorptionCorrections::loadSettings(const QSettings & settings)
{
UNUSED_ARG(settings);
//TODO
}


/**
* Handle completion of the absorption correction algorithm.
*
* @param error True if algorithm has failed.
*/
void AbsorptionCorrections::algorithmComplete(bool error)
{
if(error)
{
emit showMessageBox("Could not run absorption corrections.\nSee Results Log for details.");
return;
}
}

} // namespace IDA
Expand Down

0 comments on commit 96dceb1

Please sign in to comment.