Mantid
Loading...
Searching...
No Matches
CalculatePlaczekSelfScattering2.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
9#include "MantidAPI/Axis.h"
10#include "MantidAPI/Sample.h"
16#include "MantidKernel/Atom.h"
19#include "MantidKernel/Unit.h"
20
21#include <utility>
22
23namespace Mantid::Algorithms {
24
25DECLARE_ALGORITHM(CalculatePlaczekSelfScattering2)
26
28 declareProperty(
29 std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>("InputWorkspace", "", Kernel::Direction::Input),
30 "Raw diffraction data workspace for associated correction to be "
31 "calculated for. Workspace must have instrument and sample data.");
32 declareProperty(
33 std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>("IncidentSpecta", "", Kernel::Direction::Input),
34 "Workspace of fitted incident spectrum with it's first derivative. Must be in units of Wavelength.");
35 declareProperty(
36 std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>("OutputWorkspace", "", Kernel::Direction::Output),
37 "Workspace with the Self scattering correction");
38 declareProperty("CrystalDensity", EMPTY_DBL(), "The crystalographic density of the sample material.");
39}
40
41//----------------------------------------------------------------------------------------------
45 const API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
46 const API::MatrixWorkspace_sptr incidentWS = getProperty("IncidentSpecta");
47 const double crystalDensity = getProperty("CrystalDensity");
48
49 auto alg = createChildAlgorithm("CalculatePlaczek");
50 alg->setProperty("IncidentSpectra", incidentWS);
51 alg->setProperty("InputWorkspace", inWS);
52 alg->setProperty("CrystalDensity", crystalDensity);
53 alg->setProperty("Order", 1); // default order is one, just being explicit here
54 alg->execute();
55 API::MatrixWorkspace_sptr outputWS = alg->getProperty("OutputWorkspace");
56 if (!bool(outputWS)) {
57 throw std::runtime_error("Failed to get the outputworkspace");
58 }
59
60 // NOTE: the original version forces the output to be in TOF instead of matching the
61 // input. Therefore, we need to mimic that behaviour here by explicitly converting
62 // the unit of the output workspace to TOF.
63 auto cvtalg = createChildAlgorithm("ConvertUnits");
64 cvtalg->setProperty("InputWorkspace", outputWS);
65 cvtalg->setProperty("outputWorkspace", outputWS);
66 cvtalg->setProperty("Target", "TOF");
67 cvtalg->execute();
68 outputWS = cvtalg->getProperty("OutputWorkspace");
69
70 setProperty("OutputWorkspace", outputWS);
71}
72
73} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Definition: Algorithm.cpp:842
A property class for workspaces.
CalculatePlaczekSelfScattering2 : TODO: DESCRIPTION.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54