Skip to content

Commit

Permalink
Correct error in merge
Browse files Browse the repository at this point in the history
Refs #10277
  • Loading branch information
DanNixon committed Nov 3, 2014
1 parent b6974eb commit fa72b47
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
Expand Up @@ -84,6 +84,8 @@ namespace CustomInterfaces
/// Function to get details about the instrument configuration defined on C2E tab
std::map<QString, QString> getInstrumentDetails();

std::map<std::string, double> getRangesFromInstrument(QString instName = "", QString analyser = "", QString reflection = "");

protected:
Ui::IndirectDataReduction m_uiForm;

Expand Down
108 changes: 108 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp
Expand Up @@ -172,5 +172,113 @@ namespace CustomInterfaces
return instDetails;
}

/**
* Gets default peak and background ranges for an instrument in time of flight.
*
* @param instName Name of instrument
* @param analyser Analyser component
* @param reflection Reflection used
*
* @returns A map of range ID to value
*/
std::map<std::string, double> IndirectDataReductionTab::getRangesFromInstrument(
QString instName, QString analyser, QString reflection)
{
// Get any unset parameters
if(instName.isEmpty())
instName = m_uiForm.cbInst->currentText();
if(analyser.isEmpty())
analyser = m_uiForm.cbAnalyser->currentText();
if(reflection.isEmpty())
reflection = m_uiForm.cbReflection->currentText();

std::map<std::string, double> ranges;

// Get the instrument
auto instWs = loadInstrumentIfNotExist(instName.toStdString(), analyser.toStdString(), reflection.toStdString());
auto inst = instWs->getInstrument();

// Get the analyser component
auto comp = inst->getComponentByName(analyser.toStdString());
if(!comp)
return ranges;

// Get the resolution of the analyser
auto resParams = comp->getNumberParameter("resolution", true);
if(resParams.size() < 1)
return ranges;
double resolution = resParams[0];

std::vector<double> x;
x.push_back(-6 * resolution);
x.push_back(-5 * resolution);
x.push_back(-2 * resolution);
x.push_back(0);
x.push_back(2 * resolution);
std::vector<double> y;
y.push_back(1);
y.push_back(2);
y.push_back(3);
y.push_back(4);
std::vector<double> e(4, 0);

IAlgorithm_sptr createWsAlg = AlgorithmManager::Instance().create("CreateWorkspace");
createWsAlg->initialize();
createWsAlg->setProperty("OutputWorkspace", "__energy");
createWsAlg->setProperty("DataX", x);
createWsAlg->setProperty("DataY", y);
createWsAlg->setProperty("DataE", e);
createWsAlg->setProperty("Nspec", 1);
createWsAlg->setProperty("UnitX", "DeltaE");
createWsAlg->execute();

IAlgorithm_sptr convertHistAlg = AlgorithmManager::Instance().create("ConvertToHistogram");
convertHistAlg->initialize();
convertHistAlg->setProperty("InputWorkspace", "__energy");
convertHistAlg->setProperty("OutputWorkspace", "__energy");
convertHistAlg->execute();

IAlgorithm_sptr loadInstAlg = AlgorithmManager::Instance().create("LoadInstrument");
loadInstAlg->initialize();
loadInstAlg->setProperty("Workspace", "__energy");
loadInstAlg->setProperty("InstrumentName", instName.toStdString());
loadInstAlg->execute();

QString ipfFilename = instName + "_" + analyser + "_" + reflection + "_Parameters.xml";

IAlgorithm_sptr loadParamAlg = AlgorithmManager::Instance().create("LoadParameterFile");
loadParamAlg->initialize();
loadParamAlg->setProperty("Workspace", "__energy");
loadParamAlg->setProperty("Filename", ipfFilename.toStdString());
loadParamAlg->execute();

auto energyWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("__energy");
double efixed = energyWs->getInstrument()->getNumberParameter("efixed-val")[0];

auto spectrum = energyWs->getSpectrum(0);
spectrum->setSpectrumNo(3);
spectrum->clearDetectorIDs();
spectrum->addDetectorID(3);

IAlgorithm_sptr convUnitsAlg = AlgorithmManager::Instance().create("ConvertUnits");
convUnitsAlg->initialize();
convUnitsAlg->setProperty("InputWorkspace", "__energy");
convUnitsAlg->setProperty("OutputWorkspace", "__tof");
convUnitsAlg->setProperty("Target", "TOF");
convUnitsAlg->setProperty("EMode", "Indirect");
convUnitsAlg->setProperty("EFixed", efixed);
convUnitsAlg->execute();

auto tofWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("__tof");

std::vector<double> tofData = tofWs->readX(0);
ranges["peak-start-tof"] = tofData[0];
ranges["peak-end-tof"] = tofData[2];
ranges["back-start-tof"] = tofData[3];
ranges["back-end-tof"] = tofData[4];

return ranges;
}

} // namespace CustomInterfaces
} // namespace Mantid

0 comments on commit fa72b47

Please sign in to comment.