/// Fetch the properties and set the appropriate member variables void AbsorptionCorrection::retrieveBaseProperties() { double sigma_atten = getProperty("AttenuationXSection"); // in barns double sigma_s = getProperty("ScatteringXSection"); // in barns double rho = getProperty("SampleNumberDensity"); // in Angstroms-3 const Material &sampleMaterial = m_inputWS->sample().getShape().material(); if (sampleMaterial.totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0) { if (rho == EMPTY_DBL()) rho = sampleMaterial.numberDensity(); if (sigma_s == EMPTY_DBL()) sigma_s = sampleMaterial.totalScatterXSection(NeutronAtom::ReferenceLambda); if (sigma_atten == EMPTY_DBL()) sigma_atten = sampleMaterial.absorbXSection(NeutronAtom::ReferenceLambda); } else // Save input in Sample with wrong atomic number and name { NeutronAtom neutron(0, 0, 0.0, 0.0, sigma_s, 0.0, sigma_s, sigma_atten); auto shape = boost::shared_ptr<IObject>( m_inputWS->sample().getShape().cloneWithMaterial( Material("SetInAbsorptionCorrection", neutron, rho))); m_inputWS->mutableSample().setShape(shape); } rho *= 100; // Will give right units in going from // mu in cm^-1 to m^-1 for mu*total flight path( in m ) // NOTE: the angstrom^-2 to barns and the angstrom^-1 to cm^-1 // will cancel for mu to give units: cm^-1 m_refAtten = -sigma_atten * rho / NeutronAtom::ReferenceLambda; m_scattering = -sigma_s * rho; n_lambda = getProperty("NumberOfWavelengthPoints"); std::string exp_string = getProperty("ExpMethod"); if (exp_string == "Normal") // Use the system exp function EXPONENTIAL = exp; else if (exp_string == "FastApprox") // Use the compact approximation EXPONENTIAL = fast_exp; // Get the energy mode const std::string emodeStr = getProperty("EMode"); // Convert back to an integer representation m_emode = 0; if (emodeStr == "Direct") m_emode = 1; else if (emodeStr == "Indirect") m_emode = 2; // If inelastic, get the fixed energy and convert it to a wavelength if (m_emode) { const double efixed = getProperty("Efixed"); Unit_const_sptr energy = UnitFactory::Instance().create("Energy"); double factor, power; energy->quickConversion(*UnitFactory::Instance().create("Wavelength"), factor, power); m_lambdaFixed = factor * std::pow(efixed, power); } // Call the virtual function for any further properties retrieveProperties(); }
/** Calculate and show the full (integrated) line, using the latest * integrated workspace. The apply() method must have been called * before calling this. */ void LineViewer::showFull() { if (!m_sliceWS) return; MatrixWorkspace_const_sptr sliceMatrix = boost::dynamic_pointer_cast<const MatrixWorkspace>(m_sliceWS); if (sliceMatrix) { MantidQwtMatrixWorkspaceData curveData(sliceMatrix, 0, false /*not logScale*/); m_fullCurve->setData(curveData); Unit_const_sptr unit = sliceMatrix->getAxis(0)->unit(); std::string title = unit->caption() + " (" + unit->label() + ")"; m_plot->setAxisTitle( QwtPlot::xBottom, QString::fromStdString(title));; title = sliceMatrix->YUnit() + " (" + sliceMatrix->YUnitLabel() + ")"; m_plot->setAxisTitle( QwtPlot::yLeft, QString::fromStdString(title));; } else { MantidQwtIMDWorkspaceData curveData(m_sliceWS, false, VMD(), VMD(), m_lineOptions->getNormalization()); curveData.setPreviewMode(false); curveData.setPlotAxisChoice(m_lineOptions->getPlotAxis()); m_fullCurve->setData(curveData); m_plot->setAxisTitle( QwtPlot::xBottom, QString::fromStdString( curveData.getXAxisLabel() ));; m_plot->setAxisTitle( QwtPlot::yLeft, QString::fromStdString( curveData.getYAxisLabel() ));; } if (m_previewCurve->isVisible()) { m_previewCurve->setVisible(false); m_previewCurve->detach(); m_fullCurve->attach(m_plot); } m_fullCurve->setVisible(true); m_plot->replot(); m_plot->setTitle("Integrated Line Plot"); }
/// Run ConvertUnits as a sub-algorithm to convert to dSpacing MatrixWorkspace_sptr DiffractionFocussing::convertUnitsToDSpacing(const API::MatrixWorkspace_sptr& workspace) { const std::string CONVERSION_UNIT = "dSpacing"; Unit_const_sptr xUnit = workspace->getAxis(0)->unit(); g_log.information() << "Converting units from "<< xUnit->label() << " to " << CONVERSION_UNIT<<".\n"; API::IAlgorithm_sptr childAlg = createSubAlgorithm("ConvertUnits", 0.34, 0.66); childAlg->setProperty("InputWorkspace", workspace); childAlg->setPropertyValue("Target",CONVERSION_UNIT); childAlg->executeAsSubAlg(); return childAlg->getProperty("OutputWorkspace"); }
/** Checks that the input workspace and table have compatible dimensions * @return a map where: Key = string name of the the property; Value = string * describing the problem with the property. */ std::map<std::string, std::string> PhaseQuadMuon::validateInputs() { std::map<std::string, std::string> result; // Check that input ws and table ws have compatible dimensions API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace"); API::ITableWorkspace_const_sptr tabWS = getProperty("PhaseTable"); if (!inputWS) { result["InputWorkspace"] = "InputWorkspace is of Incorrect type. Please " "provide a MatrixWorkspace as the " "InputWorkspace"; return result; } size_t nspec = inputWS->getNumberHistograms(); size_t ndet = tabWS->rowCount(); if (tabWS->columnCount() == 0) { result["PhaseTable"] = "Please provide a non-empty PhaseTable."; } if (nspec != ndet) { result["PhaseTable"] = "PhaseTable must have one row per spectrum"; } // PhaseTable should have three columns: (detector, asymmetry, phase) if (tabWS->columnCount() != 3) { result["PhaseTable"] = "PhaseTable must have three columns"; } // Check units, should be microseconds Unit_const_sptr unit = inputWS->getAxis(0)->unit(); if ((unit->caption() != "Time") || (unit->label().ascii() != "microsecond")) { result["InputWorkspace"] = "InputWorkspace units must be microseconds"; } return result; }
/** Checks that the input workspace and table have compatible dimensions * @return a map where: Key = string name of the the property; Value = string * describing the problem with the property. */ std::map<std::string, std::string> PhaseQuadMuon::validateInputs() { std::map<std::string, std::string> result; // Check that input ws and table ws have compatible dimensions API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace"); API::ITableWorkspace_const_sptr tabWS = getProperty("PhaseTable"); if (!inputWS) { result["InputWorkspace"] = "InputWorkspace is of Incorrect type. Please " "provide a MatrixWorkspace as the " "InputWorkspace"; return result; } size_t nspec = inputWS->getNumberHistograms(); size_t ndet = tabWS->rowCount(); if (tabWS->columnCount() == 0) { result["PhaseTable"] = "Please provide a non-empty PhaseTable."; } if (nspec != ndet) { result["PhaseTable"] = "PhaseTable must have one row per spectrum"; } // PhaseTable should have three columns: (detector, asymmetry, phase) if (tabWS->columnCount() != 3) { result["PhaseTable"] = "PhaseTable must have three columns"; } auto names = tabWS->getColumnNames(); for (auto &name : names) { std::transform(name.begin(), name.end(), name.begin(), ::tolower); } int phaseCount = 0; int asymmetryCount = 0; for (const std::string &name : names) { for (const std::string &goodName : phaseNames) { if (name == goodName) { phaseCount += 1; } } for (const std::string &goodName : asymmNames) { if (name == goodName) { asymmetryCount += 1; } } } if (phaseCount == 0) { result["PhaseTable"] = "PhaseTable needs phases column"; } if (asymmetryCount == 0) { result["PhaseTable"] = "PhaseTable needs a asymmetry/asymm/asym column"; } if (phaseCount > 1) { result["PhaseTable"] = "PhaseTable has " + std::to_string(phaseCount) + " phase columns"; } if (asymmetryCount > 1) { result["PhaseTable"] = "PhaseTable has " + std::to_string(asymmetryCount) + " asymmetry/asymm/asym columns"; } // Check units, should be microseconds Unit_const_sptr unit = inputWS->getAxis(0)->unit(); if ((unit->caption() != "Time") || (unit->label().ascii() != "microsecond")) { result["InputWorkspace"] = "InputWorkspace units must be microseconds"; } return result; }
/** Perform transmission correction by running 'CreateTransmissionWorkspace' on * the input workspace * @param detectorWS :: the input workspace * @param detectorWSReduced:: whether the input detector workspace has been * reduced * @return :: the input workspace normalized by transmission */ MatrixWorkspace_sptr ReflectometryReductionOne2::transmissionCorrection( MatrixWorkspace_sptr detectorWS, const bool detectorWSReduced) { MatrixWorkspace_sptr transmissionWS = getProperty("FirstTransmissionRun"); // Reduce the transmission workspace, if not already done (assume that if // the workspace is in wavelength then it has already been reduced) Unit_const_sptr xUnit = transmissionWS->getAxis(0)->unit(); if (xUnit->unitID() == "TOF") { // If TransmissionProcessingInstructions are not passed then use // passed processing instrucions std::string transmissionCommands = ""; if (getPointerToProperty("TransmissionProcessingInstructions") ->isDefault()) { transmissionCommands = m_processingInstructions; } else { transmissionCommands = getPropertyValue("TransmissionProcessingInstructions"); } MatrixWorkspace_sptr secondTransmissionWS = getProperty("SecondTransmissionRun"); auto alg = this->createChildAlgorithm("CreateTransmissionWorkspace"); alg->initialize(); alg->setProperty("FirstTransmissionRun", transmissionWS); alg->setProperty("SecondTransmissionRun", secondTransmissionWS); alg->setPropertyValue("Params", getPropertyValue("Params")); alg->setPropertyValue("StartOverlap", getPropertyValue("StartOverlap")); alg->setPropertyValue("EndOverlap", getPropertyValue("EndOverlap")); alg->setProperty("ScaleRHSWorkspace", getPropertyValue("ScaleRHSWorkspace")); alg->setPropertyValue("I0MonitorIndex", getPropertyValue("I0MonitorIndex")); alg->setPropertyValue("WavelengthMin", getPropertyValue("WavelengthMin")); alg->setPropertyValue("WavelengthMax", getPropertyValue("WavelengthMax")); alg->setPropertyValue("MonitorBackgroundWavelengthMin", getPropertyValue("MonitorBackgroundWavelengthMin")); alg->setPropertyValue("MonitorBackgroundWavelengthMax", getPropertyValue("MonitorBackgroundWavelengthMax")); alg->setPropertyValue("MonitorIntegrationWavelengthMin", getPropertyValue("MonitorIntegrationWavelengthMin")); alg->setPropertyValue("MonitorIntegrationWavelengthMax", getPropertyValue("MonitorIntegrationWavelengthMax")); alg->setProperty("ProcessingInstructions", transmissionCommands); alg->setProperty("NormalizeByIntegratedMonitors", getPropertyValue("NormalizeByIntegratedMonitors")); alg->setPropertyValue("Debug", getPropertyValue("Debug")); alg->execute(); transmissionWS = alg->getProperty("OutputWorkspace"); } // Rebin the transmission run to be the same as the input. auto rebinToWorkspaceAlg = this->createChildAlgorithm("RebinToWorkspace"); rebinToWorkspaceAlg->initialize(); rebinToWorkspaceAlg->setProperty("WorkspaceToMatch", detectorWS); rebinToWorkspaceAlg->setProperty("WorkspaceToRebin", transmissionWS); rebinToWorkspaceAlg->execute(); transmissionWS = rebinToWorkspaceAlg->getProperty("OutputWorkspace"); // If the detector workspace has been reduced then the spectrum maps // should match AFTER reducing the transmission workspace if (detectorWSReduced) { verifySpectrumMaps(detectorWS, transmissionWS); } MatrixWorkspace_sptr normalized = divide(detectorWS, transmissionWS); return normalized; }