24#include <boost/algorithm/string/erase.hpp>
49 std::string sampleSetup =
"Sample Setup";
51 "File containing the sample data to reduce");
52 this->declareProperty(
54 "Workspace to be reduced");
57 "A monitor workspace associated with the input sample workspace.");
59 "A detector calibration file.");
60 this->declareProperty(
"RelocateDetectors",
false,
"Move detectors to position specified in cal file.");
61 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
62 mustBePositive->setLower(0.0);
63 auto mustBePosInt = std::make_shared<BoundedValidator<int>>();
64 mustBePosInt->setLower(0);
65 this->declareProperty(
"IncidentEnergyGuess",
EMPTY_DBL(), mustBePositive,
66 "Set the value of the incident energy guess in meV.");
67 this->declareProperty(
"UseIncidentEnergyGuess",
false,
68 "Use the incident energy guess as the actual value "
69 "(will not be calculated).");
70 this->declareProperty(
"TimeZeroGuess",
EMPTY_DBL(),
"Set the value of time zero offset in microseconds.");
71 this->setPropertySettings(
"TimeZeroGuess",
72 std::make_unique<VisibleWhenProperty>(
"UseIncidentEnergyGuess",
IS_EQUAL_TO,
"1"));
73 auto mustBePositiveInt = std::make_shared<BoundedValidator<int>>();
74 mustBePositiveInt->setLower(0);
75 this->declareProperty(
"Monitor1SpecId",
EMPTY_INT(), mustBePositiveInt,
76 "Spectrum No for the first monitor to use in Ei calculation.");
77 this->declareProperty(
"Monitor2SpecId",
EMPTY_INT(), mustBePositiveInt,
78 "Spectrum No for the second monitor to use in Ei calculation.");
79 this->declareProperty(
80 std::make_unique<
ArrayProperty<double>>(
"EnergyTransferRange", std::make_shared<RebinParamsValidator>(
true)),
81 "A comma separated list of first bin boundary, width, last bin "
83 "Negative width value indicates logarithmic binning.");
84 this->declareProperty(
"SofPhiEIsDistribution",
true,
"The final S(Phi, E) data is made to be a distribution.");
86 "A file or workspace containing a hard mask.");
88 "A file containing grouping (mapping) information.");
89 this->declareProperty(
"ShowIntermediateWorkspaces",
false,
90 "Flag to show the intermediate workspaces (diagnostic "
91 "mask, integrated detector vanadium, "
92 "integrated absolute units) from the reduction.");
94 this->setPropertyGroup(
"SampleInputFile", sampleSetup);
95 this->setPropertyGroup(
"SampleInputWorkspace", sampleSetup);
96 this->setPropertyGroup(
"SampleInputMonitorWorkspace", sampleSetup);
97 this->setPropertyGroup(
"DetCalFilename", sampleSetup);
98 this->setPropertyGroup(
"RelocateDetectors", sampleSetup);
99 this->setPropertyGroup(
"IncidentEnergyGuess", sampleSetup);
100 this->setPropertyGroup(
"UseIncidentEnergyGuess", sampleSetup);
101 this->setPropertyGroup(
"TimeZeroGuess", sampleSetup);
102 this->setPropertyGroup(
"Monitor1SpecId", sampleSetup);
103 this->setPropertyGroup(
"Monitor2SpecId", sampleSetup);
104 this->setPropertyGroup(
"EnergyTransferRange", sampleSetup);
105 this->setPropertyGroup(
"SofPhiEIsDistribution", sampleSetup);
106 this->setPropertyGroup(
"HardMaskFile", sampleSetup);
107 this->setPropertyGroup(
"GroupingFile", sampleSetup);
108 this->setPropertyGroup(
"ShowIntermediateWorkspaces", sampleSetup);
111 std::string dataCorr =
"Data Corrections";
114 std::vector<std::string> incidentBeamNormOptions;
115 incidentBeamNormOptions.emplace_back(
"None");
116 incidentBeamNormOptions.emplace_back(
"ByCurrent");
117 incidentBeamNormOptions.emplace_back(
"ToMonitor");
118 this->declareProperty(
"IncidentBeamNormalisation",
"None",
119 std::make_shared<StringListValidator>(incidentBeamNormOptions),
120 "Options for incident beam normalisation on data.");
121 this->declareProperty(
"MonitorIntRangeLow",
EMPTY_DBL(),
"Set the lower bound for monitor integration.");
122 this->setPropertySettings(
"MonitorIntRangeLow", std::make_unique<VisibleWhenProperty>(
"IncidentBeamNormalisation",
124 this->declareProperty(
"MonitorIntRangeHigh",
EMPTY_DBL(),
"Set the upper bound for monitor integration.");
125 this->setPropertySettings(
"MonitorIntRangeHigh", std::make_unique<VisibleWhenProperty>(
"IncidentBeamNormalisation",
127 this->declareProperty(
"TimeIndepBackgroundSub",
false,
128 "If true, time-independent background will be calculated and removed.");
129 this->declareProperty(
"TibTofRangeStart",
EMPTY_DBL(),
130 "Set the lower TOF bound for time-independent background subtraction.");
131 this->setPropertySettings(
"TibTofRangeStart",
132 std::make_unique<VisibleWhenProperty>(
"TimeIndepBackgroundSub",
IS_EQUAL_TO,
"1"));
133 this->declareProperty(
"TibTofRangeEnd",
EMPTY_DBL(),
134 "Set the upper TOF bound for time-independent background subtraction.");
135 this->setPropertySettings(
"TibTofRangeEnd",
136 std::make_unique<VisibleWhenProperty>(
"TimeIndepBackgroundSub",
IS_EQUAL_TO,
"1"));
137 this->declareProperty(
"CorrectKiKf",
true,
"Apply the ki/kf correction.");
138 this->declareProperty(
140 "File containing the sample detector vanadium data to reduce");
143 "Sample detector vanadium workspace to be reduced");
144 this->declareProperty(std::make_unique<
WorkspaceProperty<>>(
"DetectorVanadiumInputMonitorWorkspace",
"",
146 "A monitor workspace associated with the input sample detector vanadium "
148 this->declareProperty(
"SaveProcessedDetVan",
false,
"Save the processed detector vanadium workspace");
149 this->setPropertySettings(
"SaveProcessedDetVan",
150 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
151 this->declareProperty(
153 "Provide a filename for saving the processed detector vanadium.");
154 this->declareProperty(
"UseProcessedDetVan",
false,
155 "If true, treat the detector vanadium as processed.\n"
156 "This includes not running diagnostics on the processed data.");
157 this->declareProperty(
"UseBoundsForDetVan",
false,
"If true, integrate the detector vanadium over a given range.");
158 this->declareProperty(
"DetVanIntRangeLow",
EMPTY_DBL(),
"Set the lower bound for integrating the detector vanadium.");
159 this->setPropertySettings(
"DetVanIntRangeLow",
160 std::make_unique<VisibleWhenProperty>(
"UseBoundsForDetVan",
IS_EQUAL_TO,
"1"));
161 this->declareProperty(
"DetVanIntRangeHigh",
EMPTY_DBL(),
162 "Set the upper bound for integrating the detector vanadium.");
163 this->setPropertySettings(
"DetVanIntRangeHigh",
164 std::make_unique<VisibleWhenProperty>(
"UseBoundsForDetVan",
IS_EQUAL_TO,
"1"));
165 std::vector<std::string> detvanIntRangeUnits;
166 detvanIntRangeUnits.emplace_back(
"Energy");
167 detvanIntRangeUnits.emplace_back(
"Wavelength");
168 detvanIntRangeUnits.emplace_back(
"TOF");
169 this->declareProperty(
"DetVanIntRangeUnits",
"Energy", std::make_shared<StringListValidator>(detvanIntRangeUnits),
170 "Options for the units on the detector vanadium integration.");
171 this->setPropertySettings(
"DetVanIntRangeUnits",
172 std::make_unique<VisibleWhenProperty>(
"UseBoundsForDetVan",
IS_EQUAL_TO,
"1"));
175 this->setPropertyGroup(
"IncidentBeamNormalisation", dataCorr);
176 this->setPropertyGroup(
"MonitorIntRangeLow", dataCorr);
177 this->setPropertyGroup(
"MonitorIntRangeHigh", dataCorr);
178 this->setPropertyGroup(
"TimeIndepBackgroundSub", dataCorr);
179 this->setPropertyGroup(
"TibTofRangeStart", dataCorr);
180 this->setPropertyGroup(
"TibTofRangeEnd", dataCorr);
181 this->setPropertyGroup(
"CorrectKiKf", dataCorr);
182 this->setPropertyGroup(
"DetectorVanadiumInputFile", dataCorr);
183 this->setPropertyGroup(
"DetectorVanadiumInputWorkspace", dataCorr);
184 this->setPropertyGroup(
"DetectorVanadiumInputMonitorWorkspace", dataCorr);
185 this->setPropertyGroup(
"SaveProcessedDetVan", dataCorr);
186 this->setPropertyGroup(
"SaveProcDetVanFilename", dataCorr);
187 this->setPropertyGroup(
"UseProcessedDetVan", dataCorr);
188 this->setPropertyGroup(
"UseBoundsForDetVan", dataCorr);
189 this->setPropertyGroup(
"DetVanIntRangeLow", dataCorr);
190 this->setPropertyGroup(
"DetVanIntRangeHigh", dataCorr);
191 this->setPropertyGroup(
"DetVanIntRangeUnits", dataCorr);
194 std::string findBadDets =
"Finding Bad Detectors";
195 this->declareProperty(
"HighCounts",
EMPTY_DBL(), mustBePositive,
"Mask detectors above this threshold.");
196 this->setPropertySettings(
"HighCounts",
197 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
198 this->declareProperty(
"LowCounts",
EMPTY_DBL(), mustBePositive,
"Mask detectors below this threshold.");
199 this->setPropertySettings(
"LowCounts",
200 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
201 this->declareProperty(
"LowOutlier",
EMPTY_DBL(),
"Lower bound defining outliers as fraction of median value");
202 this->setPropertySettings(
"LowOutlier",
203 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
204 this->declareProperty(
"HighOutlier",
EMPTY_DBL(),
"Upper bound defining outliers as fraction of median value");
205 this->setPropertySettings(
"HighOutlier",
206 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
207 this->declareProperty(
"MedianTestHigh",
EMPTY_DBL(), mustBePositive,
"Mask detectors above this threshold.");
208 this->setPropertySettings(
"MedianTestHigh",
209 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
210 this->declareProperty(
"MedianTestLow",
EMPTY_DBL(), mustBePositive,
"Mask detectors below this threshold.");
211 this->setPropertySettings(
"MedianTestLow",
212 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
213 this->declareProperty(
"MedianTestLevelsUp", 0., mustBePositive,
"Mask detectors below this threshold.");
214 this->setPropertySettings(
"MedianTestLevelsUp",
215 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
216 this->declareProperty(
"MedianTestCorrectForSolidAngle",
false,
"Flag to correct for solid angle efficiency.");
217 this->setPropertySettings(
"MedianTestCorrectForSolidAngle",
218 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
219 this->declareProperty(
"ErrorBarCriterion",
EMPTY_DBL(), mustBePositive,
220 "Some selection criteria for the detector tests.");
221 this->setPropertySettings(
"ErrorBarCriterion",
222 std::make_unique<VisibleWhenProperty>(
"DetectorVanadiumInputFile",
IS_NOT_EQUAL_TO,
""));
223 this->declareProperty(
225 "File containing detector vanadium data to compare against");
228 "Detector vanadium workspace to compare against");
229 this->declareProperty(std::make_unique<
WorkspaceProperty<>>(
"DetectorVanadium2InputMonitorWorkspace",
"",
231 "A monitor workspace associated with the input comparison detector "
232 "vanadium workspace.");
234 this->declareProperty(
"DetVanRatioVariation",
EMPTY_DBL(), mustBePositive,
235 "Mask detectors if the time variation is above this threshold.");
236 this->setPropertySettings(
"DetVanRatioVariation",
237 std::make_unique<VisibleWhenProperty>(
"DetectorVanadium2InputFile",
IS_NOT_EQUAL_TO,
""));
239 this->declareProperty(
"BackgroundCheck",
false,
"If true, run a background check on detector vanadium.");
240 this->declareProperty(
"SamBkgMedianTestHigh",
EMPTY_DBL(), mustBePositive,
"Mask detectors above this threshold.");
241 this->setPropertySettings(
"SamBkgMedianTestHigh",
242 std::make_unique<VisibleWhenProperty>(
"BackgroundCheck",
IS_EQUAL_TO,
"1"));
243 this->declareProperty(
"SamBkgMedianTestLow",
EMPTY_DBL(), mustBePositive,
"Mask detectors below this threshold.");
244 this->setPropertySettings(
"SamBkgMedianTestLow",
245 std::make_unique<VisibleWhenProperty>(
"BackgroundCheck",
IS_EQUAL_TO,
"1"));
246 this->declareProperty(
"SamBkgErrorBarCriterion",
EMPTY_DBL(), mustBePositive,
247 "Some selection criteria for the detector tests.");
248 this->setPropertySettings(
"SamBkgErrorBarCriterion",
249 std::make_unique<VisibleWhenProperty>(
"BackgroundCheck",
IS_EQUAL_TO,
"1"));
250 this->declareProperty(
"BackgroundTofStart",
EMPTY_DBL(), mustBePositive,
"Start TOF for the background check.");
251 this->setPropertySettings(
"BackgroundTofStart",
252 std::make_unique<VisibleWhenProperty>(
"BackgroundCheck",
IS_EQUAL_TO,
"1"));
253 this->declareProperty(
"BackgroundTofEnd",
EMPTY_DBL(), mustBePositive,
"End TOF for the background check.");
254 this->setPropertySettings(
"BackgroundTofEnd",
255 std::make_unique<VisibleWhenProperty>(
"BackgroundCheck",
IS_EQUAL_TO,
"1"));
256 this->declareProperty(
"RejectZeroBackground",
false,
"If true, check the background region for anomolies.");
257 this->declareProperty(
"PsdBleed",
false,
"If true, perform a PSD bleed test.");
258 this->declareProperty(
"MaxFramerate",
EMPTY_DBL(),
"The maximum framerate to check.");
259 this->setPropertySettings(
"MaxFramerate", std::make_unique<VisibleWhenProperty>(
"PsdBleed",
IS_EQUAL_TO,
"1"));
260 this->declareProperty(
"IgnoredPixels",
EMPTY_DBL(),
"A list of pixels to ignore in the calculations.");
261 this->setPropertySettings(
"IgnoredPixels", std::make_unique<VisibleWhenProperty>(
"PsdBleed",
IS_EQUAL_TO,
"1"));
263 this->setPropertyGroup(
"HighCounts", findBadDets);
264 this->setPropertyGroup(
"LowCounts", findBadDets);
265 this->setPropertyGroup(
"LowOutlier", findBadDets);
266 this->setPropertyGroup(
"HighOutlier", findBadDets);
267 this->setPropertyGroup(
"MedianTestHigh", findBadDets);
268 this->setPropertyGroup(
"MedianTestLow", findBadDets);
269 this->setPropertyGroup(
"MedianTestLevelsUp", findBadDets);
270 this->setPropertyGroup(
"MedianTestCorrectForSolidAngle", findBadDets);
271 this->setPropertyGroup(
"ErrorBarCriterion", findBadDets);
272 this->setPropertyGroup(
"DetectorVanadium2InputFile", findBadDets);
273 this->setPropertyGroup(
"DetectorVanadium2InputWorkspace", findBadDets);
274 this->setPropertyGroup(
"DetectorVanadium2InputMonitorWorkspace", findBadDets);
275 this->setPropertyGroup(
"DetVanRatioVariation", findBadDets);
276 this->setPropertyGroup(
"BackgroundCheck", findBadDets);
277 this->setPropertyGroup(
"SamBkgMedianTestHigh", findBadDets);
278 this->setPropertyGroup(
"SamBkgMedianTestLow", findBadDets);
279 this->setPropertyGroup(
"SamBkgErrorBarCriterion", findBadDets);
280 this->setPropertyGroup(
"BackgroundTofStart", findBadDets);
281 this->setPropertyGroup(
"BackgroundTofEnd", findBadDets);
282 this->setPropertyGroup(
"RejectZeroBackground", findBadDets);
283 this->setPropertyGroup(
"PsdBleed", findBadDets);
284 this->setPropertyGroup(
"MaxFramerate", findBadDets);
285 this->setPropertyGroup(
"IgnoredPixels", findBadDets);
288 std::string absUnitsCorr =
"Absolute Units Correction";
289 this->declareProperty(
"DoAbsoluteUnits",
false,
"If true, perform an absolute units normalisation.");
291 "The sample (vanadium) file used in the absolute units normalisation.");
292 this->setPropertySettings(
"AbsUnitsSampleInputFile",
293 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
296 "The sample (vanadium) workspace for absolute units normalisation.");
297 this->setPropertySettings(
"AbsUnitsSampleInputWorkspace",
298 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
299 this->declareProperty(std::make_unique<
WorkspaceProperty<>>(
"AbsUnitsSampleInputMonitorWorkspace",
"",
301 "A monitor workspace associated with the input absolute units sample "
303 this->setPropertySettings(
"AbsUnitsSampleInputMonitorWorkspace",
304 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
305 this->declareProperty(
"AbsUnitsGroupingFile",
"",
"Grouping file for absolute units normalisation.");
306 this->setPropertySettings(
"AbsUnitsGroupingFile",
307 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
308 this->declareProperty(
310 "The detector vanadium file used in the absolute units normalisation.");
311 this->setPropertySettings(
"AbsUnitsDetectorVanadiumInputFile",
312 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
313 this->declareProperty(std::make_unique<
WorkspaceProperty<>>(
"AbsUnitsDetectorVanadiumInputWorkspace",
"",
315 "The detector vanadium workspace for absolute units normalisation.");
316 this->setPropertySettings(
"AbsUnitsDetectorVanadiumInputWorkspace",
317 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
318 this->declareProperty(std::make_unique<
WorkspaceProperty<>>(
"AbsUnitsDetectorVanadiumInputMonitorWorkspace",
"",
320 "A monitor workspace associated with the input absolute units sample "
321 "detector vanadium workspace.");
322 this->setPropertySettings(
"AbsUnitsDetectorVanadiumInputMonitorWorkspace",
323 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
324 this->declareProperty(
"AbsUnitsIncidentEnergy",
EMPTY_DBL(), mustBePositive,
325 "The incident energy for the vanadium sample.");
326 this->setPropertySettings(
"AbsUnitsIncidentEnergy",
327 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
328 this->declareProperty(
"AbsUnitsMinimumEnergy",
EMPTY_DBL(),
"The minimum energy for the integration range.");
329 this->setPropertySettings(
"AbsUnitsMinimumEnergy",
330 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
331 this->declareProperty(
"AbsUnitsMaximumEnergy",
EMPTY_DBL(),
"The maximum energy for the integration range.");
332 this->setPropertySettings(
"AbsUnitsMaximumEnergy",
333 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
334 this->declareProperty(
"VanadiumMass",
EMPTY_DBL(),
"The mass of vanadium.");
335 this->setPropertySettings(
"VanadiumMass", std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
336 this->declareProperty(
"SampleMass", 1.0,
"The mass of sample.");
337 this->setPropertySettings(
"SampleMass", std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
338 this->declareProperty(
"SampleRmm", 1.0,
"The rmm of sample.");
339 this->setPropertySettings(
"SampleRmm", std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
340 this->declareProperty(
"AbsUnitsLowOutlier",
EMPTY_DBL(),
"Lower bound defining outliers as fraction of median value");
341 this->setPropertySettings(
"AbsUnitsLowOutlier",
342 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
343 this->declareProperty(
"AbsUnitsHighOutlier",
EMPTY_DBL(),
344 "Upper bound defining outliers as fraction of median value");
345 this->setPropertySettings(
"AbsUnitsHighOutlier",
346 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
347 this->declareProperty(
"AbsUnitsMedianTestHigh",
EMPTY_DBL(), mustBePositive,
"Mask detectors above this threshold.");
348 this->setPropertySettings(
"AbsUnitsMedianTestHigh",
349 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
350 this->declareProperty(
"AbsUnitsMedianTestLow",
EMPTY_DBL(), mustBePositive,
"Mask detectors below this threshold.");
351 this->setPropertySettings(
"AbsUnitsMedianTestLow",
352 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
353 this->declareProperty(
"AbsUnitsErrorBarCriterion",
EMPTY_DBL(), mustBePositive,
354 "Some selection criteria for the detector tests.");
355 this->setPropertySettings(
"AbsUnitsErrorBarCriterion",
356 std::make_unique<VisibleWhenProperty>(
"DoAbsoluteUnits",
IS_EQUAL_TO,
"1"));
358 this->setPropertyGroup(
"DoAbsoluteUnits", absUnitsCorr);
359 this->setPropertyGroup(
"AbsUnitsSampleInputFile", absUnitsCorr);
360 this->setPropertyGroup(
"AbsUnitsSampleInputWorkspace", absUnitsCorr);
361 this->setPropertyGroup(
"AbsUnitsSampleInputMonitorWorkspace", absUnitsCorr);
362 this->setPropertyGroup(
"AbsUnitsGroupingFile", absUnitsCorr);
363 this->setPropertyGroup(
"AbsUnitsDetectorVanadiumInputFile", absUnitsCorr);
364 this->setPropertyGroup(
"AbsUnitsDetectorVanadiumInputWorkspace", absUnitsCorr);
365 this->setPropertyGroup(
"AbsUnitsDetectorVanadiumInputMonitorWorkspace", absUnitsCorr);
366 this->setPropertyGroup(
"AbsUnitsIncidentEnergy", absUnitsCorr);
367 this->setPropertyGroup(
"AbsUnitsMinimumEnergy", absUnitsCorr);
368 this->setPropertyGroup(
"AbsUnitsMaximumEnergy", absUnitsCorr);
369 this->setPropertyGroup(
"VanadiumMass", absUnitsCorr);
370 this->setPropertyGroup(
"SampleMass", absUnitsCorr);
371 this->setPropertyGroup(
"SampleRmm", absUnitsCorr);
372 this->setPropertyGroup(
"AbsUnitsLowOutlier", absUnitsCorr);
373 this->setPropertyGroup(
"AbsUnitsHighOutlier", absUnitsCorr);
374 this->setPropertyGroup(
"AbsUnitsMedianTestHigh", absUnitsCorr);
375 this->setPropertyGroup(
"AbsUnitsMedianTestLow", absUnitsCorr);
376 this->setPropertyGroup(
"AbsUnitsErrorBarCriterion", absUnitsCorr);
379 std::string powder =
"Powder Data Conversion";
380 this->declareProperty(
"DoPowderDataConversion",
false,
"Flag to switch on converting DeltaE to SQW.");
381 this->declareProperty(
382 std::make_unique<
ArrayProperty<double>>(
"PowderMomTransferRange", std::make_shared<RebinParamsValidator>(
true)),
383 "A comma separated list of first bin boundary, width, last bin "
385 "Negative width value indicates logarithmic binning.");
386 this->setPropertySettings(
"PowderMomTransferRange",
387 std::make_unique<VisibleWhenProperty>(
"DoPowderDataConversion",
IS_EQUAL_TO,
"1"));
388 this->declareProperty(
"SavePowderNexusFile",
true,
"Flag to use to save a processed NeXus file for powder data.");
389 this->setPropertySettings(
"SavePowderNexusFile",
390 std::make_unique<VisibleWhenProperty>(
"DoPowderDataConversion",
IS_EQUAL_TO,
"1"));
391 this->declareProperty(
393 "Provide a filename for saving the processed powder data.");
394 this->setPropertySettings(
"SavePowderNexusFilename",
395 std::make_unique<VisibleWhenProperty>(
"DoPowderDataConversion",
IS_EQUAL_TO,
"1"));
397 this->setPropertyGroup(
"DoPowderDataConversion", powder);
398 this->setPropertyGroup(
"PowderMomTransferRange", powder);
399 this->setPropertyGroup(
"SavePowderNexusFile", powder);
400 this->setPropertyGroup(
"SavePowderNexusFilename", powder);
405 "Provide a name for the output workspace.");
406 this->declareProperty(
"ReductionProperties",
"__dgs_reduction_properties",
Direction::Output);
414 g_log.
debug() <<
"MustLoad = " << mustLoad <<
'\n';
417 const std::string inFileProp = prop +
"InputFile";
418 const std::string inWsProp = prop +
"InputWorkspace";
422 if (!inputWSName.empty() && !inputData.empty()) {
424 std::ostringstream mess;
425 mess <<
"DgsReduction: Either the " << inFileProp <<
" property or ";
426 mess << inWsProp <<
" property must be provided, NOT BOTH!";
427 throw std::runtime_error(mess.str());
429 return std::shared_ptr<Workspace>();
431 }
else if (!inputWSName.empty()) {
432 inputWS = this->
load(inputWSName);
433 }
else if (!inputData.empty()) {
436 if (
"ISIS" == facility) {
437 std::string detCalFileFromAlg = this->
getProperty(
"DetCalFilename");
438 std::string detCalFileProperty = prop +
"DetCalFilename";
439 if (!detCalFileFromAlg.empty()) {
445 inputWS = this->
load(inputData,
true);
448 smlog->setProperty(
"Workspace", inputWS);
449 smlog->setProperty(
"LogName",
"Filename");
450 smlog->setProperty(
"LogText", inputData);
451 smlog->executeAsChildAlg();
454 std::ostringstream mess;
455 mess <<
"DgsReduction: Either the " << inFileProp <<
" property or ";
456 mess << inWsProp <<
" property must be provided!";
457 throw std::runtime_error(mess.str());
459 return std::shared_ptr<Workspace>();
467 const std::string hardMask = this->
getProperty(
"HardMaskFile");
468 if (hardMask.empty()) {
469 return std::shared_ptr<MatrixWorkspace>();
472 bool castWorkspace =
false;
473 if (boost::ends_with(hardMask,
".nxs")) {
475 loadMask->setProperty(
"Filename", hardMask);
477 const std::string instName = this->
reductionManager->getProperty(
"InstrumentName");
479 loadMask->setProperty(
"Instrument", instName);
480 loadMask->setProperty(
"InputFile", hardMask);
481 castWorkspace =
true;
486 return std::dynamic_pointer_cast<MatrixWorkspace>(
tmp);
488 return loadMask->getProperty(
"OutputWorkspace");
493 const std::string propName = prop +
"GroupingFile";
494 const std::string groupFile = this->
getProperty(propName);
495 if (groupFile.empty()) {
496 return std::shared_ptr<MatrixWorkspace>();
500 loadGrpFile->setProperty(
"InputFile", groupFile);
501 loadGrpFile->execute();
502 return loadGrpFile->getProperty(
"OutputWorkspace");
506 g_log.
warning() <<
"Old format grouping file in use.\n";
509 return std::shared_ptr<MatrixWorkspace>();
515 const std::string &altParam) {
518 param = ws->getInstrument()->getNumberParameter(altParam)[0];
529 const std::string reductionManagerName = this->
getProperty(
"ReductionProperties");
530 if (reductionManagerName.empty()) {
531 g_log.
error() <<
"ERROR: Reduction Property Manager name is empty\n";
538 const std::vector<Property *> props = this->getProperties();
539 for (
auto prop : props) {
540 if (!boost::contains(prop->name(),
"Input")) {
541 this->
reductionManager->declareProperty(std::unique_ptr<Property>(prop->clone()));
545 Progress progress(
this, 0.0, 1.0, 7);
562 std::ostringstream mess;
563 mess <<
"Default facility must be set to " << info.
facility().
name();
564 mess <<
" in order for reduction to work!";
565 throw std::runtime_error(mess.str());
570 const bool showIntermedWS = this->
getProperty(
"ShowIntermediateWorkspaces");
573 if (boost::ends_with(outputWsName,
"_spe")) {
574 boost::erase_all(outputWsName,
"_spe");
577 progress.
report(
"Loading hard mask...");
581 if (hardMaskWS && showIntermedWS) {
582 std::string hardMaskName = outputWsName +
"_hardmask";
584 this->setProperty(
"ReductionHardMask", hardMaskWS);
587 progress.
report(
"Loading grouping file...");
590 if (groupingWS && showIntermedWS) {
591 std::string groupName = outputWsName +
"_grouping";
593 this->setProperty(
"ReductionGrouping", groupingWS);
602 bool isProcessedDetVan = this->
getProperty(
"UseProcessedDetVan");
608 if (detVanWS && !isProcessedDetVan) {
609 std::string detVanMaskName = outputWsName +
"_diagmask";
612 diag->setProperty(
"DetVanWorkspace", detVanWS);
613 diag->setProperty(
"DetVanMonitorWorkspace", detVanMonWS);
614 diag->setProperty(
"DetVanCompWorkspace", detVan2WS);
615 diag->setProperty(
"DetVanCompMonitorWorkspace", detVan2MonWS);
616 diag->setProperty(
"SampleWorkspace", sampleWS);
617 diag->setProperty(
"SampleMonitorWorkspace", sampleMonWS);
618 diag->setProperty(
"HardMaskWorkspace", hardMaskWS);
619 diag->setProperty(
"ReductionProperties",
getPropertyValue(
"ReductionProperties"));
620 diag->executeAsChildAlg();
621 maskWS = diag->getProperty(
"OutputWorkspace");
623 if (showIntermedWS) {
624 this->declareProperty(
626 this->setProperty(
"SampleDetVanDiagMask", maskWS);
630 detVan->setProperty(
"InputWorkspace", detVanWS);
631 detVan->setProperty(
"InputMonitorWorkspace", detVanMonWS);
632 detVan->setProperty(
"MaskWorkspace", maskWS);
633 std::string idetVanName = outputWsName +
"_idetvan";
634 detVan->setProperty(
"ReductionProperties",
getPropertyValue(
"ReductionProperties"));
635 detVan->executeAsChildAlg();
637 idetVanWS = std::dynamic_pointer_cast<Workspace>(oWS);
639 if (showIntermedWS) {
640 this->declareProperty(
642 this->setProperty(
"IntegratedNormWorkspace", idetVanWS);
645 idetVanWS = detVanWS;
646 maskWS = std::dynamic_pointer_cast<MatrixWorkspace>(idetVanWS);
650 progress.
report(
"Converting to energy transfer...");
652 etConv->setProperty(
"InputWorkspace", sampleWS);
653 etConv->setProperty(
"InputMonitorWorkspace", sampleMonWS);
654 etConv->setProperty(
"IntegratedDetectorVanadium", idetVanWS);
655 const double ei = this->
getProperty(
"IncidentEnergyGuess");
656 etConv->setProperty(
"IncidentEnergyGuess", ei);
657 if (!maskWS && hardMaskWS) {
660 etConv->setProperty(
"MaskWorkspace", maskWS);
662 etConv->setProperty(
"GroupingWorkspace", groupingWS);
664 etConv->setProperty(
"ReductionProperties",
getPropertyValue(
"ReductionProperties"));
666 etConv->executeAsChildAlg();
670 if (tibWS && showIntermedWS) {
672 this->setProperty(
"SampleTibWorkspace", tibWS);
677 progress.
report(
"Absolute units reduction...");
681 std::string absWsName = outputWsName +
"_absunits";
691 absUnitsRed->setProperty(
"InputWorkspace", absSampleWS);
692 absUnitsRed->setProperty(
"InputMonitorWorkspace", absSampleMonWS);
693 absUnitsRed->setProperty(
"DetectorVanadiumWorkspace", absDetVanWS);
694 absUnitsRed->setProperty(
"DetectorVanadiumMonitorWorkspace", absDetVanMonWS);
695 absUnitsRed->setProperty(
"GroupingWorkspace", absGroupingWS);
696 absUnitsRed->setProperty(
"MaskWorkspace", maskWS);
697 absUnitsRed->setProperty(
"ReductionProperties",
getPropertyValue(
"ReductionProperties"));
698 absUnitsRed->executeAsChildAlg();
705 mask->setProperty(
"Workspace", outputWS);
706 mask->setProperty(
"MaskedWorkspace", absMaskWS);
707 mask->executeAsChildAlg();
708 outputWS = mask->getProperty(
"Workspace");
711 outputWS =
divide(outputWS, absUnitsWS);
713 if (showIntermedWS) {
715 this->setProperty(
"AbsUnitsWorkspace", absUnitsWS);
718 this->setProperty(
"AbsUnitsDiagMask", absMaskWS);
725 const bool doPowderConvert = this->
getProperty(
"DoPowderDataConversion");
726 if (doPowderConvert) {
729 std::string sqwWsName = outputWsName +
"_pd_sqw";
730 std::vector<double> qBinning = this->
getProperty(
"PowderMomTransferRange");
731 const auto initialEnergy = outputWS->run().getPropertyValueAsType<
double>(
"Ei");
734 sofqw->setProperty(
"InputWorkspace", outputWS);
735 sofqw->setProperty(
"QAxisBinning", qBinning);
736 sofqw->setProperty(
"EMode",
"Direct");
737 sofqw->setProperty(
"EFixed", initialEnergy);
738 sofqw->executeAsChildAlg();
741 this->setProperty(
"PowderSqwWorkspace", sqwWS);
743 const bool saveProcNexus = this->
getProperty(
"SavePowderNexusFile");
745 std::string saveProcNexusFilename = this->
getProperty(
"SavePowderNexusFilename");
746 if (saveProcNexusFilename.empty()) {
747 saveProcNexusFilename = sqwWsName +
".nxs";
750 saveNxs->setProperty(
"InputWorkspace", sqwWS);
751 saveNxs->setProperty(
"Filename", saveProcNexusFilename);
752 saveNxs->executeAsChildAlg();
758 this->setProperty(
"OutputWorkspace", outputWS);
#define DECLARE_ALGORITHM(classname)
@ OptionalSave
to specify a file to write to but an empty string is
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
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.
Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override
Get the property held by this object.
std::string getPropertyValue(const std::string &name) const override
Get the property held by this object.
void setLoadAlg(const std::string &alg)
Workspace_sptr load(const std::string &inputData, const bool loadQuiet=false)
Determine what kind of input data we have and load it.
MatrixWorkspace_sptr divide(const MatrixWorkspace_sptr lhs, const MatrixWorkspace_sptr rhs)
Divide a matrix workspace by another matrix workspace.
Helper class for reporting progress from algorithms.
A property class for workspaces.
Support for a property that holds an array of values.
A class that holds information about a facility.
const std::string & name() const
Return the name of the facility.
A class that holds information about an instrument.
const FacilityInfo & facility() const
The facility to which this instrument belongs.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
DgsReduction : This is the top-level workflow algorithm for controlling direct geometry spectrometer ...
int version() const override
Algorithm's version for identification.
std::shared_ptr< Kernel::PropertyManager > reductionManager
API::MatrixWorkspace_sptr loadHardMask()
void exec() override
Execute the algorithm.
API::MatrixWorkspace_sptr loadGroupingFile(const std::string &prop)
double getParameter(const std::string &algParam, const API::MatrixWorkspace_sptr &ws, const std::string &altParam)
void init() override
Initialize the algorithm's properties.
const std::string category() const override
Algorithm's category for identification.
API::Workspace_sptr loadInputData(const std::string &prop, const bool mustLoad=true)
Create a workspace by either loading a file or using an existing workspace.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< MaskWorkspace > MaskWorkspace_sptr
shared pointer to the MaskWorkspace class
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.