Mantid
Loading...
Searching...
No Matches
ComputeSensitivity.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
18
20
21// Register the algorithm into the AlgorithmFactory
22DECLARE_ALGORITHM(ComputeSensitivity)
23
24using namespace Kernel;
25using namespace API;
26using namespace DataObjects;
27
29 declareProperty(std::make_unique<API::FileProperty>("Filename", "", API::FileProperty::Load, "_event.nxs"),
30 "Flood field or sensitivity file.");
31 declareProperty(std::make_unique<WorkspaceProperty<>>("PatchWorkspace", "", Direction::Input, PropertyMode::Optional),
32 "Workspace defining the area of the detector to be patched. "
33 "All masked pixels in this workspace will be patched.");
34 declareProperty("ReductionProperties", "__eqsans_reduction_properties", Direction::Input);
35 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
36 "Workspace containing the sensitivity correction.");
37 declareProperty("OutputMessage", "", Direction::Output);
38}
39
41 std::string outputMessage;
42 progress(0.1, "Setting up sensitivity calculation");
43
44 // Reduction property manager
45 std::shared_ptr<PropertyManager> reductionManager = getProcessProperties();
46
47 const std::string outputWS = getPropertyValue("OutputWorkspace");
48
49 // Find beam center
50 if (reductionManager->existsProperty("SANSBeamFinderAlgorithm")) {
51 // const std::string algTxt =
52 // reductionManager->getPropertyValue("SANSBeamFinderAlgorithm");
53
54 IAlgorithm_sptr ctrAlg = reductionManager->getProperty("SANSBeamFinderAlgorithm");
55 ctrAlg->setPropertyValue("ReductionProperties", getPropertyValue("ReductionProperties"));
56 ctrAlg->setChild(true);
57 ctrAlg->execute();
58 std::string outMsg2 = ctrAlg->getPropertyValue("OutputMessage");
59 outputMessage += outMsg2;
60 }
61
62 progress(0.2, "Computing sensitivity");
63
64 // Set patch information so that the SANS sensitivity algorithm can
65 // patch the sensitivity workspace
66 const std::string patchWSName = getPropertyValue("PatchWorkspace");
67 if (!patchWSName.empty()) {
68 auto patchAlg = createChildAlgorithm("EQSANSPatchSensitivity");
69 patchAlg->setPropertyValue("PatchWorkspace", patchWSName);
70 if (!reductionManager->existsProperty("SensitivityPatchAlgorithm")) {
71 reductionManager->declareProperty(std::make_unique<AlgorithmProperty>("SensitivityPatchAlgorithm"));
72 }
73 reductionManager->setProperty("SensitivityPatchAlgorithm", patchAlg);
74 }
75
76 if (reductionManager->existsProperty("SensitivityAlgorithm")) {
77 const std::string fileName = getPropertyValue("Filename");
78 IAlgorithm_sptr effAlg = reductionManager->getProperty("SensitivityAlgorithm");
79 effAlg->setChild(true);
80 effAlg->setProperty("Filename", fileName);
81 effAlg->setPropertyValue("OutputSensitivityWorkspace", outputWS);
82 effAlg->execute();
83 MatrixWorkspace_sptr effWS = effAlg->getProperty("OutputSensitivityWorkspace");
84 setProperty("OutputWorkspace", effWS);
85 std::string outMsg2 = effAlg->getPropertyValue("OutputMessage");
86 outputMessage += outMsg2;
87 setProperty("OutputMessage", outputMessage);
88 } else {
89 g_log.error() << "Could not find sensitivity algorithm\n";
90 }
91}
92
93} // namespace Mantid::WorkflowAlgorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
std::shared_ptr< Kernel::PropertyManager > getProcessProperties(const std::string &propertyManager=std::string()) const
Get the property manager object of a given name from the property manager data service,...
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) override
Create a Child Algorithm.
std::string getPropertyValue(const std::string &name) const override
Get the property held by this object.
A property class for workspaces.
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
void init() override
Initialisation code.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54