-
Notifications
You must be signed in to change notification settings - Fork 121
/
DgsConvertToEnergyTransfer.cpp
585 lines (527 loc) · 23.7 KB
/
DgsConvertToEnergyTransfer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
122
123
124
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidWorkflowAlgorithms/DgsConvertToEnergyTransfer.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/SpectrumInfo.h"
#include "MantidGeometry/IDetector.h"
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/PropertyManager.h"
#include "MantidKernel/PropertyManagerDataService.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidWorkflowAlgorithms/WorkflowAlgorithmHelpers.h"
#include <boost/lexical_cast.hpp>
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace WorkflowAlgorithmHelpers;
namespace Mantid {
namespace WorkflowAlgorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(DgsConvertToEnergyTransfer)
/// Algorithm's name for identification. @see Algorithm::name
const std::string DgsConvertToEnergyTransfer::name() const {
return "DgsConvertToEnergyTransfer";
}
/// Algorithm's version for identification. @see Algorithm::version
int DgsConvertToEnergyTransfer::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string DgsConvertToEnergyTransfer::category() const {
return "Workflow\\Inelastic\\UsesPropertyManager";
}
/** Initialize the algorithm's properties.
*/
void DgsConvertToEnergyTransfer::init() {
this->declareProperty(std::make_unique<WorkspaceProperty<>>(
"InputWorkspace", "", Direction::Input),
"A sample data workspace.");
this->declareProperty(
std::make_unique<WorkspaceProperty<>>("InputMonitorWorkspace", "",
Direction::Input,
PropertyMode::Optional),
"A monitor workspace associated with the sample workspace.");
this->declareProperty(
"IncidentEnergyGuess", EMPTY_DBL(),
"This is the starting point for the incident energy calculation.");
this->declareProperty(std::make_unique<WorkspaceProperty<>>(
"IntegratedDetectorVanadium", "", Direction::Input,
PropertyMode::Optional),
"A workspace containing the "
"integrated detector vanadium.");
this->declareProperty(
std::make_unique<WorkspaceProperty<MatrixWorkspace>>(
"MaskWorkspace", "", Direction::Input, PropertyMode::Optional),
"A mask workspace");
this->declareProperty(
std::make_unique<WorkspaceProperty<MatrixWorkspace>>(
"GroupingWorkspace", "", Direction::Input, PropertyMode::Optional),
"A grouping workspace");
this->declareProperty(
"AlternateGroupingTag", "",
"Allows modification to the OldGroupingFile property name");
this->declareProperty(std::make_unique<WorkspaceProperty<>>(
"OutputWorkspace", "", Direction::Output),
"The name for the output workspace.");
this->declareProperty(std::make_unique<WorkspaceProperty<>>(
"OutputTibWorkspace", "", Direction::Output),
"The name for the output TIB workspace.");
this->declareProperty("ReductionProperties", "__dgs_reduction_properties",
Direction::Input);
}
/** Execute the algorithm.
*/
void DgsConvertToEnergyTransfer::exec() {
g_log.notice() << "Starting DgsConvertToEnergyTransfer\n";
// Get the reduction property manager
const std::string reductionManagerName =
this->getProperty("ReductionProperties");
std::shared_ptr<PropertyManager> reductionManager;
if (PropertyManagerDataService::Instance().doesExist(reductionManagerName))
reductionManager =
PropertyManagerDataService::Instance().retrieve(reductionManagerName);
else
throw std::runtime_error("DgsConvertToEnergyTransfer cannot run without a "
"reduction PropertyManager.");
MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");
MatrixWorkspace_sptr monWS = this->getProperty("InputMonitorWorkspace");
// Make a monitor workspace name for SNS data
std::string monWsName = inputWS->getName() + "_monitors";
bool preserveEvents = false;
// Calculate the initial energy and time zero
const std::string facility = ConfigService::Instance().getFacility().name();
g_log.notice() << "Processing for " << facility << '\n';
double eiGuess = this->getProperty("IncidentEnergyGuess");
if (EMPTY_DBL() == eiGuess) {
// SNS has a log called EnergyRequest that can be used to get the
// incident energy guess.
if ("SNS" == facility) {
TimeSeriesProperty<double> *eiLog =
inputWS->run().getTimeSeriesProperty<double>("EnergyRequest");
eiGuess = eiLog->getStatistics().mean;
} else {
throw std::runtime_error("Incident energy guess MUST be given!");
}
}
const bool useEiGuess =
reductionManager->getProperty("UseIncidentEnergyGuess");
const double tZeroGuess = reductionManager->getProperty("TimeZeroGuess");
std::vector<double> etBinning =
reductionManager->getProperty("EnergyTransferRange");
// Create a default set of binning parameters: (-0.5Ei, 0.01Ei, 0.99Ei)
if (etBinning.empty()) {
double emin = -0.5 * eiGuess;
double deltaE = 0.01 * eiGuess;
double emax = 0.99 * eiGuess;
etBinning.emplace_back(emin);
etBinning.emplace_back(deltaE);
etBinning.emplace_back(emax);
}
double incidentEnergy = 0.0;
double monPeak = 0.0;
specnum_t eiMon1Spec =
static_cast<specnum_t>(reductionManager->getProperty("Monitor1SpecId"));
specnum_t eiMon2Spec =
static_cast<specnum_t>(reductionManager->getProperty("Monitor2SpecId"));
if ("SNS" == facility) {
// SNS wants to preserve events until the last
preserveEvents = true;
double tZero = 0.0;
if (useEiGuess) {
incidentEnergy = eiGuess;
if (EMPTY_DBL() != tZeroGuess)
tZero = tZeroGuess;
} else {
if (!monWS) {
g_log.notice() << "Trying to determine file name\n";
std::string runFileName =
inputWS->run().getProperty("Filename")->value();
if (runFileName.empty())
throw std::runtime_error("Cannot find run filename, therefore cannot "
"find the initial energy");
std::string loadAlgName;
std::string fileProp;
if (boost::ends_with(runFileName, "_event.nxs") ||
boost::ends_with(runFileName, ".nxs.h5") ||
boost::ends_with(runFileName, ".nxs")) {
g_log.notice() << "Loading NeXus monitors\n";
loadAlgName = "LoadNexusMonitors";
fileProp = "Filename";
}
if (boost::ends_with(runFileName, "_neutron_event.dat")) {
g_log.notice() << "Loading PreNeXus monitors\n";
loadAlgName = "LoadPreNexusMonitors";
boost::replace_first(runFileName, "_neutron_event.dat",
"_runinfo.xml");
fileProp = "RunInfoFilename";
}
// Load the monitors
IAlgorithm_sptr loadmon = this->createChildAlgorithm(loadAlgName);
loadmon->setProperty(fileProp, runFileName);
loadmon->setProperty("OutputWorkspace", monWsName);
loadmon->executeAsChildAlg();
Workspace_sptr monWSOutput = loadmon->getProperty("OutputWorkspace");
// the algorithm can return a group workspace if the file is multi
// period
monWS = std::dynamic_pointer_cast<MatrixWorkspace>(monWSOutput);
if ((monWSOutput) && (!monWS))
// this was a group workspace - DGSReduction does not support multi
// period data yet
throw Exception::NotImplementedError(
"The file contains multi period data, support for this is not "
"implemented in DGSReduction yet");
}
// Calculate Ei
IAlgorithm_sptr getei = this->createChildAlgorithm("GetEi");
getei->setProperty("InputWorkspace", monWS);
getei->setProperty("Monitor1Spec", eiMon1Spec);
getei->setProperty("Monitor2Spec", eiMon2Spec);
getei->setProperty("EnergyEstimate", eiGuess);
getei->executeAsChildAlg();
incidentEnergy = getei->getProperty("IncidentEnergy");
tZero = getei->getProperty("Tzero");
}
g_log.notice() << "Adjusting for T0\n";
IAlgorithm_sptr alg = this->createChildAlgorithm("ChangeBinOffset");
alg->setProperty("InputWorkspace", inputWS);
alg->setProperty("OutputWorkspace", outputWS);
alg->setProperty("Offset", -tZero);
alg->executeAsChildAlg();
outputWS = alg->getProperty("OutputWorkspace");
// Add T0 to sample logs
IAlgorithm_sptr addLog = this->createChildAlgorithm("AddSampleLog");
addLog->setProperty("Workspace", outputWS);
addLog->setProperty("LogName", "CalculatedT0");
addLog->setProperty("LogType", "Number");
addLog->setProperty("LogText", boost::lexical_cast<std::string>(tZero));
addLog->executeAsChildAlg();
}
// Do ISIS
else {
IAlgorithm_sptr getei = this->createChildAlgorithm("GetEi");
getei->setProperty("InputWorkspace", inputWS);
getei->setProperty("Monitor1Spec", eiMon1Spec);
getei->setProperty("Monitor2Spec", eiMon2Spec);
getei->setProperty("EnergyEstimate", eiGuess);
getei->executeAsChildAlg();
monPeak = getei->getProperty("FirstMonitorPeak");
const specnum_t monIndex =
static_cast<specnum_t>(getei->getProperty("FirstMonitorIndex"));
// Why did the old way get it from the log?
incidentEnergy = getei->getProperty("IncidentEnergy");
IAlgorithm_sptr cbo = this->createChildAlgorithm("ChangeBinOffset");
cbo->setProperty("InputWorkspace", inputWS);
cbo->setProperty("OutputWorkspace", outputWS);
cbo->setProperty("Offset", -monPeak);
cbo->executeAsChildAlg();
outputWS = cbo->getProperty("OutputWorkspace");
const auto &specInfo = inputWS->spectrumInfo();
const V3D &monPos = specInfo.position(monIndex);
std::string srcName = inputWS->getInstrument()->getSource()->getName();
IAlgorithm_sptr moveInstComp =
this->createChildAlgorithm("MoveInstrumentComponent");
moveInstComp->setProperty("Workspace", outputWS);
moveInstComp->setProperty("ComponentName", srcName);
moveInstComp->setProperty("X", monPos.X());
moveInstComp->setProperty("Y", monPos.Y());
moveInstComp->setProperty("Z", monPos.Z());
moveInstComp->setProperty("RelativePosition", false);
moveInstComp->executeAsChildAlg();
}
const double binOffset = -monPeak;
if ("ISIS" == facility) {
std::string detcalFile;
if (reductionManager->existsProperty("SampleDetCalFilename"))
detcalFile = reductionManager->getPropertyValue("SampleDetCalFilename");
// Try to get it from run object.
else
detcalFile = inputWS->run().getProperty("Filename")->value();
if (!detcalFile.empty()) {
const bool relocateDets =
reductionManager->getProperty("RelocateDetectors");
IAlgorithm_sptr loaddetinfo =
this->createChildAlgorithm("LoadDetectorInfo");
loaddetinfo->setProperty("Workspace", outputWS);
loaddetinfo->setProperty("DataFilename", detcalFile);
loaddetinfo->setProperty("RelocateDets", relocateDets);
loaddetinfo->executeAsChildAlg();
outputWS = loaddetinfo->getProperty("Workspace");
} else {
throw std::runtime_error(
"Cannot find detcal filename in run object or as parameter.");
}
}
// Subtract time-independent background if necessary
const bool doTibSub = reductionManager->getProperty("TimeIndepBackgroundSub");
if (doTibSub) {
// Setup for later use
IAlgorithm_sptr cnvToDist =
this->createChildAlgorithm("ConvertToDistribution");
// Set the binning parameters for the background region
double tibTofStart = getDblPropOrParam("TibTofRangeStart", reductionManager,
"bkgd-range-min", inputWS);
tibTofStart += binOffset;
double tibTofEnd = getDblPropOrParam("TibTofRangeEnd", reductionManager,
"bkgd-range-max", inputWS);
tibTofEnd += binOffset;
const double tibTofWidth = tibTofEnd - tibTofStart;
std::vector<double> params{tibTofStart, tibTofWidth, tibTofEnd};
bool treatTibAsEvents = false;
// Do we want to treat the TIB as events
std::vector<std::string> backgroundType =
inputWS->getInstrument()->getStringParameter(
"treat-background-as-events");
if (backgroundType.empty()) {
// Set the default behaviour.
treatTibAsEvents = false;
} else {
if ("yes" == backgroundType[0] || "true" == backgroundType[0]) {
treatTibAsEvents = true;
}
}
if ("SNS" == facility) {
MatrixWorkspace_sptr bkgWS;
// Do we want to treat the constant background as events ?
if (treatTibAsEvents) {
g_log.notice("TIB removal using event mode.");
// Treat background as events
IAlgorithm_sptr createBkg =
this->createChildAlgorithm("CreateFlatEventWorkspace");
createBkg->setProperty("InputWorkspace", outputWS);
createBkg->setProperty("RangeStart", tibTofStart);
createBkg->setProperty("RangeEnd", tibTofEnd);
createBkg->executeAsChildAlg();
bkgWS = createBkg->getProperty("OutputWorkspace");
} else {
g_log.notice("TIB removal using legacy mode.");
// Create an original background workspace from a portion of the
// result workspace.
std::string origBkgWsName = "background_origin_ws";
IAlgorithm_sptr rebin = this->createChildAlgorithm("Rebin");
rebin->setProperty("InputWorkspace", outputWS);
rebin->setProperty("OutputWorkspace", origBkgWsName);
rebin->setProperty("Params", params);
rebin->setProperty("PreserveEvents", false);
rebin->setProperty("IgnoreBinErrors", true);
rebin->executeAsChildAlg();
MatrixWorkspace_sptr origBkgWS = rebin->getProperty("OutputWorkspace");
// Convert result workspace to DeltaE since we have Et binning
IAlgorithm_sptr cnvun = this->createChildAlgorithm("ConvertUnits");
cnvun->setProperty("InputWorkspace", outputWS);
cnvun->setProperty("OutputWorkspace", outputWS);
cnvun->setProperty("Target", "DeltaE");
cnvun->setProperty("EMode", "Direct");
cnvun->setProperty("EFixed", incidentEnergy);
cnvun->executeAsChildAlg();
outputWS = cnvun->getProperty("OutputWorkspace");
// Rebin to Et
rebin->setProperty("InputWorkspace", outputWS);
rebin->setProperty("OutputWorkspace", outputWS);
rebin->setProperty("Params", etBinning);
rebin->setProperty("PreserveEvents", false);
rebin->executeAsChildAlg();
outputWS = rebin->getProperty("OutputWorkspace");
// Convert result workspace to TOF
cnvun->setProperty("InputWorkspace", outputWS);
cnvun->setProperty("OutputWorkspace", outputWS);
cnvun->setProperty("Target", "TOF");
cnvun->setProperty("EMode", "Direct");
cnvun->setProperty("EFixed", incidentEnergy);
cnvun->executeAsChildAlg();
outputWS = cnvun->getProperty("OutputWorkspace");
// Make result workspace a distribution
cnvToDist->setProperty("Workspace", outputWS);
cnvToDist->executeAsChildAlg();
outputWS = cnvToDist->getProperty("Workspace");
// Calculate the background
IAlgorithm_sptr flatBg =
this->createChildAlgorithm("CalculateFlatBackground");
flatBg->setProperty("InputWorkspace", origBkgWS);
flatBg->setProperty("StartX", tibTofStart);
flatBg->setProperty("EndX", tibTofEnd);
flatBg->setProperty("Mode", "Mean");
flatBg->setProperty("OutputMode", "Return Background");
flatBg->executeAsChildAlg();
bkgWS = flatBg->getProperty("OutputWorkspace");
// Remove unneeded original background workspace
origBkgWS.reset();
// Make background workspace a distribution
cnvToDist->setProperty("Workspace", bkgWS);
cnvToDist->executeAsChildAlg();
bkgWS = cnvToDist->getProperty("Workspace");
}
// Subtract background from result workspace
IAlgorithm_sptr minus = this->createChildAlgorithm("Minus");
minus->setProperty("LHSWorkspace", outputWS);
minus->setProperty("RHSWorkspace", bkgWS);
minus->setProperty("OutputWorkspace", outputWS);
minus->executeAsChildAlg();
this->setProperty("OutputTibWorkspace", bkgWS);
}
// Do ISIS
else {
// Make result workspace a distribution
cnvToDist->setProperty("Workspace", outputWS);
cnvToDist->executeAsChildAlg();
outputWS = cnvToDist->getProperty("Workspace");
IAlgorithm_sptr flatBg =
this->createChildAlgorithm("CalculateFlatBackground");
flatBg->setProperty("InputWorkspace", outputWS);
flatBg->setProperty("OutputWorkspace", outputWS);
flatBg->setProperty("StartX", tibTofStart);
flatBg->setProperty("EndX", tibTofEnd);
flatBg->setProperty("Mode", "Mean");
flatBg->executeAsChildAlg();
outputWS = flatBg->getProperty("OutputWorkspace");
}
if (!treatTibAsEvents) {
// Convert result workspace back to histogram
IAlgorithm_sptr cnvFrDist =
this->createChildAlgorithm("ConvertFromDistribution");
cnvFrDist->setProperty("Workspace", outputWS);
cnvFrDist->executeAsChildAlg();
outputWS = cnvFrDist->getProperty("Workspace");
}
}
// Normalise result workspace to incident beam parameter
IAlgorithm_sptr norm = this->createChildAlgorithm("DgsPreprocessData");
norm->setProperty("InputWorkspace", outputWS);
norm->setProperty("OutputWorkspace", outputWS);
norm->setProperty("InputMonitorWorkspace", monWS);
norm->setProperty("TofRangeOffset", binOffset);
norm->executeAsChildAlg();
outputWS = norm->getProperty("OutputWorkspace");
// Convert to energy transfer
g_log.notice() << "Converting to energy transfer.\n";
IAlgorithm_sptr cnvun = this->createChildAlgorithm("ConvertUnits");
cnvun->setProperty("InputWorkspace", outputWS);
cnvun->setProperty("OutputWorkspace", outputWS);
cnvun->setProperty("Target", "DeltaE");
cnvun->setProperty("EMode", "Direct");
cnvun->setProperty("EFixed", incidentEnergy);
cnvun->executeAsChildAlg();
outputWS = cnvun->getProperty("OutputWorkspace");
g_log.notice() << "Rebinning data\n";
IAlgorithm_sptr rebin = this->createChildAlgorithm("Rebin");
rebin->setProperty("InputWorkspace", outputWS);
rebin->setProperty("OutputWorkspace", outputWS);
rebin->setProperty("Params", etBinning);
rebin->setProperty("IgnoreBinErrors", true);
rebin->setProperty("PreserveEvents", preserveEvents);
rebin->executeAsChildAlg();
outputWS = rebin->getProperty("OutputWorkspace");
// Correct for detector efficiency
if ("SNS" == facility) {
// He3TubeEfficiency requires the workspace to be in wavelength
cnvun->setProperty("InputWorkspace", outputWS);
cnvun->setProperty("OutputWorkspace", outputWS);
cnvun->setProperty("Target", "Wavelength");
cnvun->executeAsChildAlg();
outputWS = cnvun->getProperty("OutputWorkspace");
// Do the correction
IAlgorithm_sptr alg2 = this->createChildAlgorithm("He3TubeEfficiency");
alg2->setProperty("InputWorkspace", outputWS);
alg2->setProperty("OutputWorkspace", outputWS);
alg2->executeAsChildAlg();
outputWS = alg2->getProperty("OutputWorkspace");
// Convert back to energy transfer
cnvun->setProperty("InputWorkspace", outputWS);
cnvun->setProperty("OutputWorkspace", outputWS);
cnvun->setProperty("Target", "DeltaE");
cnvun->executeAsChildAlg();
outputWS = cnvun->getProperty("OutputWorkspace");
}
// Do ISIS
else {
IAlgorithm_sptr alg = this->createChildAlgorithm("DetectorEfficiencyCor");
alg->setProperty("InputWorkspace", outputWS);
alg->setProperty("OutputWorkspace", outputWS);
alg->executeAsChildAlg();
outputWS = alg->getProperty("OutputWorkspace");
}
const bool correctKiKf = reductionManager->getProperty("CorrectKiKf");
if (correctKiKf) {
// Correct for Ki/Kf
IAlgorithm_sptr kikf = this->createChildAlgorithm("CorrectKiKf");
kikf->setProperty("InputWorkspace", outputWS);
kikf->setProperty("OutputWorkspace", outputWS);
kikf->setProperty("EMode", "Direct");
kikf->executeAsChildAlg();
outputWS = kikf->getProperty("OutputWorkspace");
}
// Rebin to ensure consistency
const bool sofphieIsDistribution =
reductionManager->getProperty("SofPhiEIsDistribution");
g_log.notice() << "Rebinning data\n";
rebin->setProperty("InputWorkspace", outputWS);
rebin->setProperty("OutputWorkspace", outputWS);
rebin->setProperty("IgnoreBinErrors", true);
if (sofphieIsDistribution)
rebin->setProperty("PreserveEvents", false);
rebin->executeAsChildAlg();
outputWS = rebin->getProperty("OutputWorkspace");
if (sofphieIsDistribution) {
g_log.notice() << "Making distribution\n";
IAlgorithm_sptr distrib =
this->createChildAlgorithm("ConvertToDistribution");
distrib->setProperty("Workspace", outputWS);
distrib->executeAsChildAlg();
outputWS = distrib->getProperty("Workspace");
} else {
// Discard events outside nominal bounds
IAlgorithm_sptr crop = this->createChildAlgorithm("CropWorkspace");
crop->setProperty("InputWorkspace", outputWS);
crop->setProperty("OutputWorkspace", outputWS);
crop->setProperty("XMin", etBinning[0]);
crop->setProperty("XMax", etBinning[2]);
crop->executeAsChildAlg();
outputWS = crop->getProperty("OutputWorkspace");
}
// Normalise by the detector vanadium if necessary
MatrixWorkspace_sptr detVanWS =
this->getProperty("IntegratedDetectorVanadium");
if (detVanWS) {
IAlgorithm_sptr divide = this->createChildAlgorithm("Divide");
divide->setProperty("LHSWorkspace", outputWS);
divide->setProperty("RHSWorkspace", detVanWS);
divide->setProperty("OutputWorkspace", outputWS);
divide->executeAsChildAlg();
outputWS = divide->getProperty("OutputWorkspace");
}
// Mask and group workspace if necessary.
MatrixWorkspace_sptr maskWS = this->getProperty("MaskWorkspace");
MatrixWorkspace_sptr groupWS = this->getProperty("GroupingWorkspace");
std::string oldGroupFile;
std::string filePropMod = this->getProperty("AlternateGroupingTag");
std::string fileProp = filePropMod + "OldGroupingFilename";
if (reductionManager->existsProperty(fileProp))
oldGroupFile = reductionManager->getPropertyValue(fileProp);
IAlgorithm_sptr remap = this->createChildAlgorithm("DgsRemap");
remap->setProperty("InputWorkspace", outputWS);
remap->setProperty("OutputWorkspace", outputWS);
remap->setProperty("MaskWorkspace", maskWS);
remap->setProperty("GroupingWorkspace", groupWS);
remap->setProperty("OldGroupingFile", oldGroupFile);
remap->executeAsChildAlg();
outputWS = remap->getProperty("OutputWorkspace");
if ("ISIS" == facility) {
double scaleFactor =
inputWS->getInstrument()->getNumberParameter("scale-factor")[0];
IAlgorithm_sptr scaleAlg = this->createChildAlgorithm("Scale");
scaleAlg->setProperty("InputWorkspace", outputWS);
scaleAlg->setProperty("Factor", scaleFactor);
scaleAlg->setProperty("Operation", "Multiply");
scaleAlg->setProperty("OutputWorkspace", outputWS);
scaleAlg->executeAsChildAlg();
}
this->setProperty("OutputWorkspace", outputWS);
}
} // namespace WorkflowAlgorithms
} // namespace Mantid