Newer
Older
#include "MantidWorkflowAlgorithms/DgsProcessDetectorVanadium.h"
Federico Montesino Pouzols
committed
#include "MantidWorkflowAlgorithms/WorkflowAlgorithmHelpers.h"
Federico Montesino Pouzols
committed
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/PropertyManagerDataService.h"
Federico Montesino Pouzols
committed
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
#include <boost/algorithm/string/predicate.hpp>
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace WorkflowAlgorithmHelpers;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
namespace Mantid {
namespace WorkflowAlgorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(DgsProcessDetectorVanadium)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
DgsProcessDetectorVanadium::DgsProcessDetectorVanadium() {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
DgsProcessDetectorVanadium::~DgsProcessDetectorVanadium() {}
//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string DgsProcessDetectorVanadium::name() const {
return "DgsProcessDetectorVanadium";
}
/// Algorithm's version for identification. @see Algorithm::version
int DgsProcessDetectorVanadium::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string DgsProcessDetectorVanadium::category() const {
return "Workflow\\Inelastic\\UsesPropertyManager";
}
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void DgsProcessDetectorVanadium::init() {
// auto wsValidator = boost::make_shared<CompositeValidator>();
// wsValidator->add<WorkspaceUnitValidator>("TOF");
this->declareProperty(
new WorkspaceProperty<>("InputWorkspace", "", Direction::Input),
"An input workspace containing the detector vanadium data in TOF units.");
this->declareProperty(
new WorkspaceProperty<>("InputMonitorWorkspace", "", Direction::Input,
PropertyMode::Optional),
"A monitor workspace associated with the input workspace.");
this->declareProperty(new WorkspaceProperty<>("MaskWorkspace", "",
Direction::Input,
PropertyMode::Optional),
"A mask workspace");
this->declareProperty(
new WorkspaceProperty<>("OutputWorkspace", "", Direction::Output),
"The name for the output workspace.");
this->declareProperty("ReductionProperties", "__dgs_reduction_properties",
Direction::Output);
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void DgsProcessDetectorVanadium::exec() {
g_log.notice() << "Starting DgsProcessDetectorVanadium" << std::endl;
// Get the reduction property manager
const std::string reductionManagerName =
this->getProperty("ReductionProperties");
boost::shared_ptr<PropertyManager> reductionManager;
if (PropertyManagerDataService::Instance().doesExist(reductionManagerName)) {
reductionManager =
PropertyManagerDataService::Instance().retrieve(reductionManagerName);
} else {
throw std::runtime_error("DgsProcessDetectorVanadium cannot run without a "
"reduction PropertyManager.");
}
MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");
MatrixWorkspace_sptr monWS = this->getProperty("InputMonitorWorkspace");
// Normalise result workspace to incident beam parameter
IAlgorithm_sptr norm = this->createChildAlgorithm("DgsPreprocessData");
norm->setProperty("InputWorkspace", inputWS);
norm->setProperty("OutputWorkspace", inputWS);
norm->setProperty("InputMonitorWorkspace", monWS);
norm->executeAsChildAlg();
inputWS.reset();
inputWS = norm->getProperty("OutputWorkspace");
double detVanIntRangeLow = getDblPropOrParam(
"DetVanIntRangeLow", reductionManager, "wb-integr-min", inputWS);
double detVanIntRangeHigh = getDblPropOrParam(
"DetVanIntRangeHigh", reductionManager, "wb-integr-max", inputWS);
const std::string detVanIntRangeUnits =
reductionManager->getProperty("DetVanIntRangeUnits");
if ("TOF" != detVanIntRangeUnits) {
// Convert the data to the appropriate units
IAlgorithm_sptr cnvun = this->createChildAlgorithm("ConvertUnits");
cnvun->setProperty("InputWorkspace", inputWS);
cnvun->setProperty("OutputWorkspace", inputWS);
cnvun->setProperty("Target", detVanIntRangeUnits);
cnvun->setProperty("EMode", "Elastic");
cnvun->executeAsChildAlg();
inputWS = cnvun->getProperty("OutputWorkspace");
}
// Rebin the data (not Integration !?!?!?)
std::vector<double> binning{detVanIntRangeLow,
detVanIntRangeHigh - detVanIntRangeLow,
detVanIntRangeHigh};
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
IAlgorithm_sptr rebin = this->createChildAlgorithm("Rebin");
rebin->setProperty("InputWorkspace", inputWS);
rebin->setProperty("OutputWorkspace", outputWS);
rebin->setProperty("PreserveEvents", false);
rebin->setProperty("Params", binning);
rebin->executeAsChildAlg();
outputWS = rebin->getProperty("OutputWorkspace");
// Mask and group workspace if necessary.
MatrixWorkspace_sptr maskWS = this->getProperty("MaskWorkspace");
//!!! I see masks here but where is the map workspace used for vanadium
// grouping (In ISIS)?
IAlgorithm_sptr remap = this->createChildAlgorithm("DgsRemap");
remap->setProperty("InputWorkspace", outputWS);
remap->setProperty("OutputWorkspace", outputWS);
remap->setProperty("MaskWorkspace", maskWS);
remap->executeAsChildAlg();
outputWS = remap->getProperty("OutputWorkspace");
const std::string facility = ConfigService::Instance().getFacility().name();
if ("ISIS" == facility) {
// Scale results by a constant
double wbScaleFactor =
inputWS->getInstrument()->getNumberParameter("wb-scale-factor")[0];
outputWS *= wbScaleFactor;
}
if (reductionManager->existsProperty("SaveProcessedDetVan")) {
bool saveProc = reductionManager->getProperty("SaveProcessedDetVan");
if (saveProc) {
std::string outputFile("");
if (reductionManager->existsProperty("SaveProcDetVanFilename")) {
outputFile =
reductionManager->getPropertyValue("SaveProcDetVanFilename");
if (outputFile.empty()) {
outputFile = this->getPropertyValue("OutputWorkspace");
outputFile += ".nxs";
// Don't save private calculation workspaces
if (!outputFile.empty() &&
!boost::starts_with(outputFile, "ChildAlgOutput") &&
!boost::starts_with(outputFile, "__")) {
IAlgorithm_sptr save = this->createChildAlgorithm("SaveNexus");
save->setProperty("InputWorkspace", outputWS);
save->setProperty("FileName", outputFile);
save->execute();
}
this->setProperty("OutputWorkspace", outputWS);
}
} // namespace WorkflowAlgorithms