Skip to content
Snippets Groups Projects
Commit 73f190c6 authored by Harriet Brown's avatar Harriet Brown
Browse files

Fix broken code from mistakes in rebase.

parent 3b111435
No related branches found
No related tags found
No related merge requests found
......@@ -5,13 +5,15 @@
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidAlgorithms/CalculatePlaczekSelfScattering.h"
#include "MantidAPI/Axis.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/SpectrumInfo.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidKernel/Atom.h"
#include "MantidKernel/Material.h"
#include "MantidKernel/Unit.h"
#include <utility>
......@@ -52,8 +54,12 @@ void CalculatePlaczekSelfScattering::init() {
declareProperty(
std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>(
"InputWorkspace", "", Kernel::Direction::Input),
"Workspace of fitted incident spectrum with it's first derivative. "
"Workspace must have instument and sample data.");
"Raw diffraction data workspace for associated correction to be "
"calculated for. Workspace must have instument and sample data.");
declareProperty(
std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>(
"IncidentSpecta", "", Kernel::Direction::Input),
"Workspace of fitted incident spectrum with it's first derivative.");
declareProperty(
std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>(
"OutputWorkspace", "", Kernel::Direction::Output),
......@@ -66,8 +72,8 @@ std::map<std::string, std::string>
CalculatePlaczekSelfScattering::validateInputs() {
std::map<std::string, std::string> issues;
const API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
const Geometry::DetectorInfo detInfo = inWS->detectorInfo();
if (detInfo.size() == 0) {
const API::SpectrumInfo specInfo = inWS->spectrumInfo();
if (specInfo.size() == 0) {
issues["InputWorkspace"] =
"Input workspace does not have detector information";
}
......@@ -84,6 +90,7 @@ CalculatePlaczekSelfScattering::validateInputs() {
*/
void CalculatePlaczekSelfScattering::exec() {
const API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
const API::MatrixWorkspace_sptr incidentWS = getProperty("IncidentSpecta");
API::MatrixWorkspace_sptr outWS = getProperty("OutputWorkspace");
constexpr double factor =
1.0 / 1.66053906660e-27; // atomic mass unit-kilogram relationship
......@@ -98,9 +105,9 @@ void CalculatePlaczekSelfScattering::exec() {
neutronMass / atom.second["mass"];
}
// get incident spectrum and 1st derivative
const MantidVec xLambda = inWS->readX(0);
const MantidVec incident = inWS->readY(0);
const MantidVec incidentPrime = inWS->readY(1);
const MantidVec xLambda = incidentWS->readX(0);
const MantidVec incident = incidentWS->readY(0);
const MantidVec incidentPrime = incidentWS->readY(1);
double dx = (xLambda[1] - xLambda[0]) / 2.0;
std::vector<double> phi1;
for (size_t i = 0; i < xLambda.size() - 1; i++) {
......@@ -127,15 +134,16 @@ void CalculatePlaczekSelfScattering::exec() {
MantidVec xLambdas;
MantidVec placzekCorrection;
size_t nReserve = 0;
const Geometry::DetectorInfo detInfo = inWS->detectorInfo();
for (size_t detIndex = 0; detIndex < detInfo.size(); detIndex++) {
if (!detInfo.isMonitor(detIndex)) {
nReserve += 1;
const API::SpectrumInfo specInfo = inWS->spectrumInfo();
for (size_t detIndex = 0; detIndex < specInfo.size(); detIndex++) {
if (!specInfo.isMonitor(detIndex)) {
if (!specInfo.l2(detIndex) == 0) {
nReserve += 1;
}
}
}
xLambdas.reserve(nReserve);
placzekCorrection.reserve(nReserve);
API::MatrixWorkspace_sptr outputWS =
DataObjects::create<API::HistoWorkspace>(*inWS);
// The algorithm computes the signal values at bin centres so they should
......@@ -178,4 +186,4 @@ void CalculatePlaczekSelfScattering::exec() {
}
} // namespace Algorithms
} // namespace Mantid
} // namespace Mantid
\ No newline at end of file
......@@ -53,10 +53,13 @@ class Polaris(AbstractInst):
# Generate pdf
run_details = self._get_run_details(self._inst_settings.run_number)
focus_file_path = self._generate_out_file_paths(run_details)["nxs_filename"]
cal_file_name = self._inst_settings.calibration_dir + '/' + self._inst_settings.grouping_file_name
pdf_output = polaris_algs.generate_ts_pdf(run_number=self._inst_settings.run_number,
focus_file_path=focus_file_path,
merge_banks=self._inst_settings.merge_banks,
q_lims=q_lims)
q_lims=q_lims,
cal_file_name=cal_file_name,
sample_details=self._sample_details)
return pdf_output
def set_sample_details(self, **kwargs):
......
......@@ -79,11 +79,11 @@ def save_unsplined_vanadium(vanadium_ws, output_path):
mantid.DeleteWorkspace(converted_group)
def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, q_lims=None):
def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, q_lims=None, cal_file_name=None, sample_details=None):
focused_ws = _obtain_focused_run(run_number, focus_file_path)
if merge_banks:
pdf_output = _generate_grouped_ts_pdf(focused_ws, q_lims)
pdf_output = _generate_grouped_ts_pdf(run_number, focused_ws, q_lims, cal_file_name, sample_details)
else:
focused_ws = mantid.ConvertUnits(InputWorkspace=focused_ws.name(), Target="MomentumTransfer")
pdf_output = mantid.PDFFourierTransform(Inputworkspace=focused_ws, InputSofQType="S(Q)", PDFType="G(r)",
......@@ -120,7 +120,7 @@ def _obtain_focused_run(run_number, focus_file_path):
return focused_ws
def _generate_grouped_ts_pdf(focused_ws, q_lims):
def _generate_grouped_ts_pdf(run_number, focused_ws, q_lims, cal_file_name, sample_details):
focused_ws = mantid.ConvertUnits(InputWorkspace=focused_ws, Target="MomentumTransfer", EMode='Elastic')
min_x = np.inf
max_x = -np.inf
......@@ -134,7 +134,6 @@ def _generate_grouped_ts_pdf(focused_ws, q_lims):
binning = [min_x, width_x, max_x]
focused_ws = mantid.Rebin(InputWorkspace=focused_ws, Params=binning)
focused_data_combined = mantid.ConjoinSpectra(InputWorkspaces=focused_ws)
mantid.ConvertFromDistribution(Workspace=focused_data_combined)
raw_ws = mantid.LoadRaw(Filename='POL'+str(run_number))
mantid.SetSample(InputWorkspace=raw_ws,
......@@ -167,7 +166,6 @@ def _generate_grouped_ts_pdf(focused_ws, q_lims):
mantid.ConvertToDistribution(Workspace=placzek)
placzek = mantid.ConvertUnits(InputWorkspace=placzek, Target="MomentumTransfer", EMode='Elastic')
placzek = mantid.RebinToWorkspace(WorkspaceToRebin=placzek, WorkspaceToMatch=focused_data_combined)
mantid.ConvertFromDistribution(Workspace=placzek)
mantid.Subtract(LHSWorkspace=focused_data_combined,
RHSWorkspace=placzek,
OutputWorkspace=focused_data_combined)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment