-
Notifications
You must be signed in to change notification settings - Fork 122
/
AlignAndFocusPowder.cpp
1230 lines (1109 loc) · 53.5 KB
/
AlignAndFocusPowder.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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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/AlignAndFocusPowder.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/Axis.h"
#include "MantidAPI/FileFinder.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/SpectrumInfo.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataObjects/GroupingWorkspace.h"
#include "MantidDataObjects/MaskWorkspace.h"
#include "MantidDataObjects/OffsetsWorkspace.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/DateTimeValidator.h"
#include "MantidKernel/EnabledWhenProperty.h"
#include "MantidKernel/InstrumentInfo.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/PropertyManager.h"
#include "MantidKernel/PropertyManagerDataService.h"
#include "MantidKernel/System.h"
using Mantid::Geometry::Instrument_const_sptr;
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
namespace Mantid::WorkflowAlgorithms {
using namespace Kernel;
using API::FileProperty;
using API::MatrixWorkspace;
using API::MatrixWorkspace_sptr;
using API::WorkspaceProperty;
namespace {
namespace PropertyNames {
const std::string INPUT_WKSP("InputWorkspace");
const std::string OUTPUT_WKSP("OutputWorkspace");
const std::string UNFOCUS_WKSP("UnfocussedWorkspace");
const std::string CAL_FILE("CalFileName");
const std::string GROUP_FILE("GroupFilename");
const std::string GROUP_WKSP("GroupingWorkspace");
const std::string CAL_WKSP("CalibrationWorkspace");
const std::string OFFSET_WKSP("OffsetsWorkspace");
const std::string MASK_WKSP("MaskWorkspace");
const std::string MASK_TABLE("MaskBinTable");
const std::string BINNING("Params");
const std::string RESAMPLEX("ResampleX");
const std::string BIN_IN_D("Dspacing");
const std::string D_MINS("DMin");
const std::string D_MAXS("DMax");
const std::string RAGGED_DELTA("DeltaRagged");
const std::string TOF_MIN("TMin");
const std::string TOF_MAX("TMax");
const std::string WL_MIN("CropWavelengthMin");
const std::string WL_MAX("CropWavelengthMax");
const std::string PRESERVE_EVENTS("PreserveEvents");
const std::string REMOVE_PROMPT_PULSE("RemovePromptPulseWidth");
const std::string RESONANCE_UNITS("ResonanceFilterUnits");
const std::string RESONANCE_LOWER_LIMITS("ResonanceFilterLowerLimits");
const std::string RESONANCE_UPPER_LIMITS("ResonanceFilterUpperLimits");
const std::string COMPRESS_TOF_TOL("CompressTolerance");
const std::string COMPRESS_WALL_TOL("CompressWallClockTolerance");
const std::string COMPRESS_WALL_START("CompressStartTime");
const std::string L1("PrimaryFlightPath");
const std::string SPEC_IDS("SpectrumIDs");
const std::string L2("L2");
const std::string POLAR("Polar");
const std::string AZIMUTHAL("Azimuthal");
const std::string PM_NAME("ReductionProperties");
const std::string LORENTZ("LorentzCorrection");
const std::string UNWRAP_REF("UnwrapRef");
const std::string LOWRES_REF("LowResRef");
const std::string LOWRES_SPEC_OFF("LowResSpectrumOffset");
} // namespace PropertyNames
} // namespace
// Register the class into the algorithm factory
DECLARE_ALGORITHM(AlignAndFocusPowder)
//----------------------------------------------------------------------------------------------
/** Initialisation method. Declares properties to be used in algorithm.
*/
void AlignAndFocusPowder::init() {
declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropertyNames::INPUT_WKSP, "", Direction::Input),
"The input workspace");
declareProperty(
std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropertyNames::OUTPUT_WKSP, "", Direction::Output),
"The result of diffraction focussing of InputWorkspace");
declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropertyNames::UNFOCUS_WKSP, "",
Direction::Output, PropertyMode::Optional),
"Treated data in d-spacing before focussing (optional). This will likely "
"need rebinning.");
// declareProperty(
// new WorkspaceProperty<MatrixWorkspace>("LowResTOFWorkspace", "",
// Direction::Output, PropertyMode::Optional),
// "The name of the workspace containing the filtered low resolution TOF
// data.");
declareProperty(std::make_unique<FileProperty>(PropertyNames::CAL_FILE, "", FileProperty::OptionalLoad,
std::vector<std::string>{".h5", ".hd5", ".hdf", ".cal"}),
"The name of the calibration file with offset, masking, and "
"grouping data");
declareProperty(std::make_unique<FileProperty>(PropertyNames::GROUP_FILE, "", FileProperty::OptionalLoad,
std::vector<std::string>{".xml", ".cal"}),
"Overrides grouping from CalFileName");
declareProperty(std::make_unique<WorkspaceProperty<GroupingWorkspace>>(PropertyNames::GROUP_WKSP, "",
Direction::InOut, PropertyMode::Optional),
"Optional: A GroupingWorkspace giving the grouping info.");
declareProperty(std::make_unique<WorkspaceProperty<ITableWorkspace>>(PropertyNames::CAL_WKSP, "", Direction::InOut,
PropertyMode::Optional),
"Optional: A Workspace containing the calibration information. Either "
"this or CalibrationFile needs to be specified.");
declareProperty(std::make_unique<WorkspaceProperty<OffsetsWorkspace>>(PropertyNames::OFFSET_WKSP, "",
Direction::Input, PropertyMode::Optional),
"Optional: An OffsetsWorkspace giving the detector calibration values.");
declareProperty(std::make_unique<WorkspaceProperty<MaskWorkspace>>(PropertyNames::MASK_WKSP, "", Direction::InOut,
PropertyMode::Optional),
"Optional: A workspace giving which detectors are masked.");
declareProperty(
std::make_unique<WorkspaceProperty<TableWorkspace>>("MaskBinTable", "", Direction::Input, PropertyMode::Optional),
"Optional: A workspace giving pixels and bins to mask.");
declareProperty( // intentionally not using the RebinParamsValidator
std::make_unique<ArrayProperty<double>>(PropertyNames::BINNING),
"A comma separated list of first bin boundary, width, last bin boundary. "
"Optionally\n"
"this can be followed by a comma and more widths and last boundary "
"pairs.\n"
"Negative width values indicate logarithmic binning.");
declareProperty(PropertyNames::RESAMPLEX, 0,
"Number of bins in x-axis. Non-zero value "
"overrides \"Params\" property. Negative "
"value means logarithmic binning.");
setPropertySettings(PropertyNames::BINNING,
std::make_unique<EnabledWhenProperty>(PropertyNames::RESAMPLEX, IS_DEFAULT));
declareProperty(PropertyNames::BIN_IN_D, true, "Bin in Dspace. (True is Dspace; False is TOF)");
declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::D_MINS),
"Minimum for Dspace axis. (Default 0.) ");
mapPropertyName(PropertyNames::D_MINS, "d_min");
declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::D_MAXS),
"Maximum for Dspace axis. (Default 0.) ");
mapPropertyName(PropertyNames::D_MAXS, "d_max");
declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::RAGGED_DELTA), "Step parameter for rebin");
mapPropertyName(PropertyNames::RAGGED_DELTA, "delta");
declareProperty(PropertyNames::TOF_MIN, EMPTY_DBL(), "Minimum for TOF axis. Defaults to 0. ");
mapPropertyName(PropertyNames::TOF_MIN, "tof_min");
declareProperty(PropertyNames::TOF_MAX, EMPTY_DBL(), "Maximum for TOF or dspace axis. Defaults to 0. ");
mapPropertyName(PropertyNames::TOF_MAX, "tof_max");
declareProperty(PropertyNames::PRESERVE_EVENTS, true,
"If the InputWorkspace is an "
"EventWorkspace, this will preserve "
"the full event list (warning: this "
"will use much more memory!).");
declareProperty(PropertyNames::REMOVE_PROMPT_PULSE, 0.,
"Width of events (in "
"microseconds) near the prompt "
"pulse to remove. 0 disables");
auto mustBePositive = std::make_shared<BoundedValidator<double>>();
mustBePositive->setLower(0.0);
std::vector<std::string> allowedResonanceUnits({"Energy", "Wavelength"});
declareProperty(PropertyNames::RESONANCE_UNITS, allowedResonanceUnits.back(),
std::make_shared<StringListValidator>(allowedResonanceUnits),
"Units for resonances to be filtered in. "
"The data will be converted to these units temporarily to filter.");
declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::RESONANCE_LOWER_LIMITS),
"Minimum values to filter absorption resonance. This must have same number of values as "
"ResonanceFilterUpperLimits. Default behavior is to not filter.");
declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::RESONANCE_UPPER_LIMITS),
"Maximum values to filter absorption resonance. This must have same number of values as "
"ResonanceFilterLowerLimits. Default behavior is to not filter.");
declareProperty(std::make_unique<PropertyWithValue<double>>(PropertyNames::COMPRESS_TOF_TOL, 1e-5, mustBePositive,
Direction::Input),
"Compress events (in "
"microseconds) within this "
"tolerance. (Default 1e-5)");
declareProperty(std::make_unique<PropertyWithValue<double>>(PropertyNames::COMPRESS_WALL_TOL, EMPTY_DBL(),
mustBePositive, Direction::Input),
"The tolerance (in seconds) on the wall-clock time for comparison. Unset "
"means compressing all wall-clock times together disabling pulsetime "
"resolution.");
auto dateValidator = std::make_shared<DateTimeValidator>();
dateValidator->allowEmpty(true);
declareProperty(PropertyNames::COMPRESS_WALL_START, "", dateValidator,
"An ISO formatted date/time string specifying the timestamp for "
"starting filtering. Ignored if WallClockTolerance is not specified. "
"Default is start of run",
Direction::Input);
declareProperty(PropertyNames::LORENTZ, false,
"Multiply each spectrum by "
"sin(theta) where theta is "
"half of the Bragg angle");
declareProperty(PropertyNames::UNWRAP_REF, 0.,
"Reference total flight path for frame "
"unwrapping. Zero skips the correction");
declareProperty(PropertyNames::LOWRES_REF, 0., "Reference DIFC for resolution removal. Zero skips the correction");
declareProperty("CropWavelengthMin", 0., "Crop the data at this minimum wavelength. Overrides LowResRef.");
mapPropertyName(PropertyNames::WL_MIN, "wavelength_min");
declareProperty("CropWavelengthMax", EMPTY_DBL(),
"Crop the data at this maximum wavelength. Forces use of "
"CropWavelengthMin.");
mapPropertyName(PropertyNames::WL_MAX, "wavelength_max");
declareProperty(PropertyNames::L1, -1.0, "If positive, focus positions are changed. (Default -1) ");
declareProperty(std::make_unique<ArrayProperty<int32_t>>(PropertyNames::SPEC_IDS),
"Optional: Spectrum Nos (note that it is not detector ID or "
"workspace indices).");
declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::L2),
"Optional: Secondary flight (L2) paths for each detector");
declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::POLAR),
"Optional: Polar angles (two thetas) for detectors");
declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::AZIMUTHAL),
"Azimuthal angles (out-of-plain) for detectors");
declareProperty(PropertyNames::LOWRES_SPEC_OFF, -1,
"Offset on spectrum No of low resolution spectra from high "
"resolution one. "
"If negative, then all the low resolution TOF will not be "
"processed. Otherwise, low resolution TOF "
"will be stored in an additional set of spectra. "
"If offset is equal to 0, then the low resolution will have "
"same spectrum Nos as the normal ones. "
"Otherwise, the low resolution spectra will have spectrum "
"IDs offset from normal ones. ");
declareProperty(PropertyNames::PM_NAME, "__powdereduction", Direction::Input);
}
std::map<std::string, std::string> AlignAndFocusPowder::validateInputs() {
std::map<std::string, std::string> result;
if (!isDefault(PropertyNames::UNFOCUS_WKSP)) {
if (getPropertyValue(PropertyNames::OUTPUT_WKSP) == getPropertyValue(PropertyNames::UNFOCUS_WKSP)) {
result[PropertyNames::OUTPUT_WKSP] = "Cannot be the same as UnfocussedWorkspace";
result[PropertyNames::UNFOCUS_WKSP] = "Cannot be the same as OutputWorkspace";
}
}
if ((!isDefault(PropertyNames::RAGGED_DELTA)) && (!isDefault(PropertyNames::RESAMPLEX))) {
result[PropertyNames::RAGGED_DELTA] = "Cannot specify with " + PropertyNames::RESAMPLEX;
result[PropertyNames::RESAMPLEX] = "Cannot specify with " + PropertyNames::RAGGED_DELTA;
}
m_inputW = getProperty(PropertyNames::INPUT_WKSP);
m_inputEW = std::dynamic_pointer_cast<EventWorkspace>(m_inputW);
if (m_inputEW && m_inputEW->getNumberEvents() <= 0)
result[PropertyNames::INPUT_WKSP] = "Empty workspace encounter, possibly due to beam down."
"Please plot the pCharge-time to identify suitable range for "
"re-time-slicing";
m_resonanceLower = getProperty(PropertyNames::RESONANCE_LOWER_LIMITS);
m_resonanceUpper = getProperty(PropertyNames::RESONANCE_UPPER_LIMITS);
// verify that they are the same length
if (m_resonanceLower.size() == m_resonanceUpper.size()) {
// verify that the lowers are less than the uppers
const size_t NUM_WINDOWS = m_resonanceLower.size();
bool ok = true;
for (size_t i = 0; i < NUM_WINDOWS; ++i) {
if (m_resonanceLower[i] >= m_resonanceUpper[i])
ok = false;
}
if (!ok) {
const std::string msg = "Lower limits must be less than upper limits";
result[PropertyNames::RESONANCE_LOWER_LIMITS] = msg;
result[PropertyNames::RESONANCE_UPPER_LIMITS] = msg;
}
} else {
result[PropertyNames::RESONANCE_LOWER_LIMITS] =
"Must have same number of values as " + PropertyNames::RESONANCE_UPPER_LIMITS;
result[PropertyNames::RESONANCE_UPPER_LIMITS] =
"Must have same number of values as " + PropertyNames::RESONANCE_LOWER_LIMITS;
}
return result;
}
template <typename NumT> struct RegLowVectorPair {
std::vector<NumT> reg;
std::vector<NumT> low;
};
template <typename NumT>
RegLowVectorPair<NumT> splitVectors(const std::vector<NumT> &orig, const size_t numVal, const std::string &label) {
RegLowVectorPair<NumT> out;
// check that there is work to do
if (!orig.empty()) {
// do the spliting
if (orig.size() == numVal) {
out.reg.assign(orig.begin(), orig.end());
out.low.assign(orig.begin(), orig.end());
} else if (orig.size() == 2 * numVal) {
out.reg.assign(orig.begin(), orig.begin() + numVal);
out.low.assign(orig.begin() + numVal, orig.begin());
} else {
std::stringstream msg;
msg << "Input number of " << label << " ids is not equal to "
<< "the number of histograms or empty (" << orig.size() << " != 0 or " << numVal << " or " << (2 * numVal)
<< ")";
throw std::runtime_error(msg.str());
}
}
return out;
}
//----------------------------------------------------------------------------------------------
/**
* Function to get a vector property either from a PropertyManager or the
* algorithm
* properties. If both PM and algorithm properties are specified, the algorithm
* one wins.
* The return value is the first element in the vector if it is not empty.
* @param name : The algorithm property to retrieve.
* @param avec : The vector to hold the property value.
* @return : The default value of the requested property.
*/
double AlignAndFocusPowder::getVecPropertyFromPmOrSelf(const std::string &name, std::vector<double> &avec) {
avec = getProperty(name);
if (!avec.empty()) {
return avec[0];
}
// No overrides provided.
return 0.0;
}
//----------------------------------------------------------------------------------------------
/** Executes the algorithm
* @throw Exception::FileError If the grouping file cannot be opened or read
* successfully
* @throw runtime_error If unable to run one of the Child Algorithms
* successfully
*/
void AlignAndFocusPowder::exec() {
// retrieve the properties
m_inputW = getProperty(PropertyNames::INPUT_WKSP);
m_inputEW = std::dynamic_pointer_cast<EventWorkspace>(m_inputW);
m_instName = m_inputW->getInstrument()->getName();
try {
m_instName = Kernel::ConfigService::Instance().getInstrument(m_instName).shortName();
} catch (Exception::NotFoundError &) {
; // not noteworthy
}
std::string calFilename = getPropertyValue(PropertyNames::CAL_FILE);
std::string groupFilename = getPropertyValue(PropertyNames::GROUP_FILE);
m_calibrationWS = getProperty(PropertyNames::CAL_WKSP);
m_maskWS = getProperty(PropertyNames::MASK_WKSP);
m_groupWS = getProperty(PropertyNames::GROUP_WKSP);
DataObjects::TableWorkspace_sptr maskBinTableWS = getProperty(PropertyNames::MASK_TABLE);
m_l1 = getProperty(PropertyNames::L1);
specids = getProperty(PropertyNames::SPEC_IDS);
l2s = getProperty(PropertyNames::L2);
tths = getProperty(PropertyNames::POLAR);
phis = getProperty(PropertyNames::AZIMUTHAL);
m_params = getProperty(PropertyNames::BINNING);
dspace = getProperty(PropertyNames::BIN_IN_D);
auto dmin = getVecPropertyFromPmOrSelf(PropertyNames::D_MINS, m_dmins);
auto dmax = getVecPropertyFromPmOrSelf(PropertyNames::D_MAXS, m_dmaxs);
this->getVecPropertyFromPmOrSelf(PropertyNames::RAGGED_DELTA, m_delta_ragged);
LRef = getProperty(PropertyNames::UNWRAP_REF);
DIFCref = getProperty(PropertyNames::LOWRES_REF);
const bool applyLorentz = getProperty(PropertyNames::LORENTZ);
minwl = getProperty(PropertyNames::WL_MIN);
maxwl = getProperty(PropertyNames::WL_MAX);
if (maxwl == 0.)
maxwl = EMPTY_DBL(); // python can only specify 0 for unused
tmin = getProperty(PropertyNames::TOF_MIN);
tmax = getProperty(PropertyNames::TOF_MAX);
m_preserveEvents = getProperty(PropertyNames::PRESERVE_EVENTS);
m_resampleX = getProperty(PropertyNames::RESAMPLEX);
const double compressEventsTolerance = getProperty(PropertyNames::COMPRESS_TOF_TOL);
const double wallClockTolerance = getProperty(PropertyNames::COMPRESS_WALL_TOL);
// determine some bits about d-space and binning
if (m_resampleX != 0) {
// ignore the normal rebin parameters
m_params.clear();
} else if (m_params.size() == 1 && m_delta_ragged.empty()) {
// if there is 1 binning parameter and not in ragged rebinning mode
// ignore what people asked for
dspace = bool(dmax > 0.);
}
if (dspace) {
if (m_params.size() == 1 && (!isEmpty(dmin)) && (!isEmpty(dmax))) {
if (dmin > 0. && dmax > dmin) {
double step = m_params[0];
m_params.clear();
m_params.emplace_back(dmin);
m_params.emplace_back(step);
m_params.emplace_back(dmax);
g_log.information() << "d-Spacing binning updated: " << m_params[0] << " " << m_params[1] << " "
<< m_params[2] << "\n";
} else {
g_log.warning() << "something is wrong with dmin (" << dmin << ") and dmax (" << dmax
<< "). They are being ignored.\n";
}
}
} else {
if (m_params.size() == 1 && (!isEmpty(tmin)) && (!isEmpty(tmax))) {
if (tmin > 0. && tmax > tmin) {
double step = m_params[0];
m_params[0] = tmin;
m_params.emplace_back(step);
m_params.emplace_back(tmax);
g_log.information() << "TOF binning updated: " << m_params[0] << " " << m_params[1] << " " << m_params[2]
<< "\n";
} else {
g_log.warning() << "something is wrong with tmin (" << tmin << ") and tmax (" << tmax
<< "). They are being ignored.\n";
}
}
}
xmin = 0.;
xmax = 0.;
if (tmin > 0.) {
xmin = tmin;
}
if (tmax > 0.) {
xmax = tmax;
}
if (!dspace && m_params.size() == 3) {
xmin = m_params[0];
xmax = m_params[2];
}
// Low resolution
int lowresoffset = getProperty(PropertyNames::LOWRES_SPEC_OFF);
if (lowresoffset < 0) {
m_processLowResTOF = false;
} else {
m_processLowResTOF = true;
m_lowResSpecOffset = static_cast<size_t>(lowresoffset);
}
loadCalFile(calFilename, groupFilename);
// Now setup the output workspace
m_outputW = getProperty(PropertyNames::OUTPUT_WKSP);
if (m_inputEW) {
// event workspace
if (m_outputW != m_inputW) {
// out-of-place: clone the input EventWorkspace
m_outputEW = m_inputEW->clone();
m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(m_outputEW);
} else {
// in-place
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
}
} else {
// workspace2D
if (m_outputW != m_inputW) {
m_outputW = m_inputW->clone();
}
}
if (m_processLowResTOF) {
if (!m_inputEW) {
throw std::runtime_error("Input workspace is not EventWorkspace. It is not supported now.");
} else {
// Make a brand new EventWorkspace
m_lowResEW = std::dynamic_pointer_cast<EventWorkspace>(
WorkspaceFactory::Instance().create("EventWorkspace", m_inputEW->getNumberHistograms(), 2, 1));
// Cast to the matrixOutputWS and save it
m_lowResW = std::dynamic_pointer_cast<MatrixWorkspace>(m_lowResEW);
// m_lowResW->setName(lowreswsname);
}
}
// set up a progress bar with the "correct" number of steps
m_progress = std::make_unique<Progress>(this, 0., 1., 22);
if (m_inputEW) {
if (compressEventsTolerance > 0.) {
g_log.information() << "running CompressEvents(Tolerance=" << compressEventsTolerance;
if (!isEmpty(wallClockTolerance))
g_log.information() << " and WallClockTolerance=" << wallClockTolerance;
g_log.information() << ") started at " << Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr compressAlg = createChildAlgorithm("CompressEvents");
compressAlg->setProperty("InputWorkspace", m_outputEW);
compressAlg->setProperty("OutputWorkspace", m_outputEW);
compressAlg->setProperty("OutputWorkspace", m_outputEW);
compressAlg->setProperty("Tolerance", compressEventsTolerance);
if (!isEmpty(wallClockTolerance)) {
compressAlg->setProperty("WallClockTolerance", wallClockTolerance);
compressAlg->setPropertyValue("StartTime", getPropertyValue(PropertyNames::COMPRESS_WALL_START));
}
compressAlg->executeAsChildAlg();
m_outputEW = compressAlg->getProperty("OutputWorkspace");
m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(m_outputEW);
} else {
g_log.information() << "Not compressing event list\n";
doSortEvents(m_outputW); // still sort to help some thing out
}
}
m_progress->report();
// crop the workspace in time-of-flight
if (xmin >= 0. || xmax > 0.) {
double tempmin;
double tempmax;
m_outputW->getXMinMax(tempmin, tempmax);
g_log.information() << "running CropWorkspace(TOFmin=" << xmin << ", TOFmax=" << xmax << ") started at "
<< Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr cropAlg = createChildAlgorithm("CropWorkspace");
cropAlg->setProperty("InputWorkspace", m_outputW);
cropAlg->setProperty("OutputWorkspace", m_outputW);
if ((xmin >= 0.) && (xmin > tempmin))
cropAlg->setProperty("Xmin", xmin);
if ((xmax > 0.) && (xmax < tempmax))
cropAlg->setProperty("Xmax", xmax);
cropAlg->executeAsChildAlg();
m_outputW = cropAlg->getProperty("OutputWorkspace");
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
}
m_progress->report();
// filter the input events if appropriate
double removePromptPulseWidth = getProperty(PropertyNames::REMOVE_PROMPT_PULSE);
if (removePromptPulseWidth > 0.) {
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
if (m_outputEW->getNumberEvents() > 0) {
g_log.information() << "running RemovePromptPulse(Width=" << removePromptPulseWidth << ") started at "
<< Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr filterPAlg = createChildAlgorithm("RemovePromptPulse");
filterPAlg->setProperty("InputWorkspace", m_outputW);
filterPAlg->setProperty("OutputWorkspace", m_outputW);
filterPAlg->setProperty("Width", removePromptPulseWidth);
filterPAlg->executeAsChildAlg();
m_outputW = filterPAlg->getProperty("OutputWorkspace");
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
} else {
g_log.information("skipping RemovePromptPulse on empty EventWorkspace");
}
}
m_progress->report();
if (maskBinTableWS) {
g_log.information() << "running MaskBinsFromTable started at " << Types::Core::DateAndTime::getCurrentTime()
<< "\n";
API::IAlgorithm_sptr alg = createChildAlgorithm("MaskBinsFromTable");
alg->setProperty("InputWorkspace", m_outputW);
alg->setProperty("OutputWorkspace", m_outputW);
alg->setProperty("MaskingInformation", maskBinTableWS);
alg->executeAsChildAlg();
m_outputW = alg->getProperty("OutputWorkspace");
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
}
m_progress->report();
if (m_maskWS) {
g_log.information() << "running MaskDetectors started at " << Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr maskDetAlg = createChildAlgorithm("MaskDetectors");
// cast to Workspace for MaksDetectors alg
Workspace_sptr outputw = std::dynamic_pointer_cast<Workspace>(m_outputW);
maskDetAlg->setProperty("Workspace", outputw);
MatrixWorkspace_sptr mksws = std::dynamic_pointer_cast<MatrixWorkspace>(m_maskWS);
maskDetAlg->setProperty("MaskedWorkspace", mksws);
maskDetAlg->executeAsChildAlg();
outputw = maskDetAlg->getProperty("Workspace");
// casting
m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(outputw);
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
}
m_progress->report();
if (!dspace)
m_outputW = rebin(m_outputW);
m_progress->report();
if (m_calibrationWS) {
// ApplyDiffCal and update m_outputW
g_log.information() << "apply calibration workspace to input workspace at "
<< Types::Core::DateAndTime::getCurrentTime() << "\n";
Workspace_sptr outputw = std::dynamic_pointer_cast<Workspace>(m_outputW);
API::IAlgorithm_sptr applyDiffCalAlg = createChildAlgorithm("ApplyDiffCal");
applyDiffCalAlg->setProperty("InstrumentWorkspace", outputw);
applyDiffCalAlg->setProperty("CalibrationWorkspace", m_calibrationWS);
applyDiffCalAlg->executeAsChildAlg();
// grab and cast
outputw = applyDiffCalAlg->getProperty("InstrumentWorkspace");
m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(outputw);
}
m_outputW = convertUnits(m_outputW, "dSpacing");
// update the other pointer that people use
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
m_progress->report();
if (m_calibrationWS) {
// NOTE:
// The conventional workflow for AlignAndFocusPowder allows users to modify the instrument so that the averaged
// pixel position can be used when converting back to TOF.
// With the recent changes in Unit.h, Mantid is using the averaged DIFC attached to workspace to convert from
// d-spacing to TOF by default, which unfortunately breaks the intended workflow here.
// To bypass this issue, we are going to remove the attached paramter map so taht Unit.h cannot perform the default
// conversion, which will effectively forcing Mantid to revert back to the original intended method.
Workspace_sptr outputw = std::dynamic_pointer_cast<Workspace>(m_outputW);
API::IAlgorithm_sptr applyDiffCalAlg = createChildAlgorithm("ApplyDiffCal");
applyDiffCalAlg->setProperty("InstrumentWorkspace", outputw);
applyDiffCalAlg->setProperty("ClearCalibration", true);
applyDiffCalAlg->executeAsChildAlg();
// grab and cast
outputw = applyDiffCalAlg->getProperty("InstrumentWorkspace");
m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(outputw);
}
// filter out absorption resonances
if (!m_resonanceLower.empty()) {
m_outputW = filterResonances(m_outputW);
}
m_progress->report(); // the step wil be really fast if the option isn't selected
// ----------------- WACKY LORENTZ THING HERE
// TODO should call LorentzCorrection as a sub-algorithm
if (applyLorentz) {
g_log.information() << "Applying Lorentz correction started at " << Types::Core::DateAndTime::getCurrentTime()
<< "\n";
API::IAlgorithm_sptr alg = createChildAlgorithm("LorentzCorrection");
alg->setProperty("InputWorkspace", m_outputW);
alg->setProperty("OutputWorkspace", m_outputW);
alg->setPropertyValue("Type", "PowderTOF");
alg->executeAsChildAlg();
m_outputW = alg->getProperty("OutputWorkspace");
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
}
if (LRef > 0. || minwl > 0. || DIFCref > 0. || (!isEmpty(maxwl))) {
m_outputW = convertUnits(m_outputW, "TOF");
}
m_progress->report();
// Beyond this point, low resolution TOF workspace is considered.
if (LRef > 0.) {
g_log.information() << "running UnwrapSNS(LRef=" << LRef << ",Tmin=" << tmin << ",Tmax=" << tmax << ") started at "
<< Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr removeAlg = createChildAlgorithm("UnwrapSNS");
removeAlg->setProperty("InputWorkspace", m_outputW);
removeAlg->setProperty("OutputWorkspace", m_outputW);
removeAlg->setProperty("LRef", LRef);
if (tmin > 0.)
removeAlg->setProperty("Tmin", tmin);
if (tmax > tmin)
removeAlg->setProperty("Tmax", tmax);
removeAlg->executeAsChildAlg();
m_outputW = removeAlg->getProperty("OutputWorkspace");
}
m_progress->report();
if (minwl > 0. || (!isEmpty(maxwl))) { // just crop the worksapce
// turn off the low res stuff
m_processLowResTOF = false;
EventWorkspace_sptr ews = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
if (ews)
g_log.information() << "Number of events = " << ews->getNumberEvents() << ". ";
g_log.information("\n");
m_outputW = convertUnits(m_outputW, "Wavelength");
g_log.information() << "running CropWorkspace(WavelengthMin=" << minwl;
if (!isEmpty(maxwl))
g_log.information() << ", WavelengthMax=" << maxwl;
g_log.information() << ") started at " << Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr removeAlg = createChildAlgorithm("CropWorkspace");
removeAlg->setProperty("InputWorkspace", m_outputW);
removeAlg->setProperty("OutputWorkspace", m_outputW);
removeAlg->setProperty("XMin", minwl);
removeAlg->setProperty("XMax", maxwl);
removeAlg->executeAsChildAlg();
m_outputW = removeAlg->getProperty("OutputWorkspace");
if (ews)
g_log.information() << "Number of events = " << ews->getNumberEvents() << ".\n";
} else if (DIFCref > 0.) {
g_log.information() << "running RemoveLowResTof(RefDIFC=" << DIFCref << ",K=3.22) started at "
<< Types::Core::DateAndTime::getCurrentTime() << "\n";
EventWorkspace_sptr ews = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
if (ews)
g_log.information() << "Number of events = " << ews->getNumberEvents() << ". ";
g_log.information("\n");
API::IAlgorithm_sptr removeAlg = createChildAlgorithm("RemoveLowResTOF");
removeAlg->setProperty("InputWorkspace", m_outputW);
removeAlg->setProperty("OutputWorkspace", m_outputW);
removeAlg->setProperty("ReferenceDIFC", DIFCref);
removeAlg->setProperty("K", 3.22);
if (tmin > 0.)
removeAlg->setProperty("Tmin", tmin);
if (m_processLowResTOF)
removeAlg->setProperty("LowResTOFWorkspace", m_lowResW);
removeAlg->executeAsChildAlg();
m_outputW = removeAlg->getProperty("OutputWorkspace");
if (m_processLowResTOF)
m_lowResW = removeAlg->getProperty("LowResTOFWorkspace");
}
m_progress->report();
EventWorkspace_sptr ews = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
if (ews) {
size_t numhighevents = ews->getNumberEvents();
if (m_processLowResTOF) {
EventWorkspace_sptr lowes = std::dynamic_pointer_cast<EventWorkspace>(m_lowResW);
size_t numlowevents = lowes->getNumberEvents();
g_log.information() << "Number of high TOF events = " << numhighevents << "; "
<< "Number of low TOF events = " << numlowevents << ".\n";
}
}
m_progress->report();
// Convert units
if (LRef > 0. || minwl > 0. || DIFCref > 0. || (!isEmpty(maxwl))) {
m_outputW = convertUnits(m_outputW, "dSpacing");
if (m_processLowResTOF)
m_lowResW = convertUnits(m_lowResW, "dSpacing");
}
m_progress->report();
if (dspace) {
m_outputW = rebin(m_outputW);
if (m_processLowResTOF)
m_lowResW = rebin(m_lowResW);
}
m_progress->report();
doSortEvents(m_outputW);
if (m_processLowResTOF)
doSortEvents(m_lowResW);
m_progress->report();
// copy the output workspace just before `DiffractionFocusing`
// this probably should be binned by callers before inspecting
if (!isDefault("UnfocussedWorkspace")) {
auto wkspCopy = m_outputW->clone();
setProperty("UnfocussedWorkspace", std::move(wkspCopy));
}
// Diffraction focus
m_outputW = diffractionFocus(m_outputW);
if (m_processLowResTOF)
m_lowResW = diffractionFocus(m_lowResW);
m_progress->report();
doSortEvents(m_outputW);
if (m_processLowResTOF)
doSortEvents(m_lowResW);
m_progress->report();
// this next call should probably be in for rebin as well
// but it changes the system tests
if (dspace) {
if (m_resampleX != 0.) {
m_outputW = rebin(m_outputW);
if (m_processLowResTOF)
m_lowResW = rebin(m_lowResW);
} else if (!m_delta_ragged.empty()) {
m_outputW = rebinRagged(m_outputW, true);
if (m_processLowResTOF)
m_lowResW = rebinRagged(m_lowResW, true);
}
}
m_progress->report();
// edit the instrument geometry
if (m_groupWS && (m_l1 > 0 || !tths.empty() || !l2s.empty() || !phis.empty())) {
size_t numreg = m_outputW->getNumberHistograms();
try {
// set up the vectors for doing everything
auto specidsSplit = splitVectors(specids, numreg, "specids");
auto tthsSplit = splitVectors(tths, numreg, "two-theta");
auto l2sSplit = splitVectors(l2s, numreg, "L2");
auto phisSplit = splitVectors(phis, numreg, "phi");
// Edit instrument
m_outputW = editInstrument(m_outputW, tthsSplit.reg, specidsSplit.reg, l2sSplit.reg, phisSplit.reg);
if (m_processLowResTOF) {
m_lowResW = editInstrument(m_lowResW, tthsSplit.low, specidsSplit.low, l2sSplit.low, phisSplit.low);
}
} catch (std::runtime_error &e) {
g_log.warning("Not editing instrument geometry:");
g_log.warning(e.what());
}
}
m_progress->report();
// Conjoin 2 workspaces if there is low resolution
if (m_processLowResTOF) {
m_outputW = conjoinWorkspaces(m_outputW, m_lowResW, m_lowResSpecOffset);
}
m_progress->report();
// Convert units to TOF
m_outputW = convertUnits(m_outputW, "TOF");
m_progress->report();
// compress again if appropriate
m_outputEW = std::dynamic_pointer_cast<EventWorkspace>(m_outputW);
if ((m_outputEW) && (compressEventsTolerance > 0.)) {
g_log.information() << "running CompressEvents(Tolerance=" << compressEventsTolerance;
if (!isEmpty(wallClockTolerance))
g_log.information() << " and WallClockTolerance=" << wallClockTolerance;
g_log.information() << ") started at " << Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr compressAlg = createChildAlgorithm("CompressEvents");
compressAlg->setProperty("InputWorkspace", m_outputEW);
compressAlg->setProperty("OutputWorkspace", m_outputEW);
compressAlg->setProperty("Tolerance", compressEventsTolerance);
if (!isEmpty(wallClockTolerance)) {
compressAlg->setProperty("WallClockTolerance", wallClockTolerance);
compressAlg->setPropertyValue("StartTime", getPropertyValue("CompressStartTime"));
}
compressAlg->executeAsChildAlg();
m_outputEW = compressAlg->getProperty("OutputWorkspace");
m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(m_outputEW);
}
m_progress->report();
if (!dspace && !m_delta_ragged.empty()) {
m_outputW = rebinRagged(m_outputW, false);
}
// return the output workspace
setProperty("OutputWorkspace", m_outputW);
}
//----------------------------------------------------------------------------------------------
/** Call edit instrument geometry
*/
API::MatrixWorkspace_sptr AlignAndFocusPowder::editInstrument(API::MatrixWorkspace_sptr ws,
const std::vector<double> &polars,
const std::vector<specnum_t> &specids,
const std::vector<double> &l2s,
const std::vector<double> &phis) {
g_log.information() << "running EditInstrumentGeometry started at " << Types::Core::DateAndTime::getCurrentTime()
<< "\n";
API::IAlgorithm_sptr editAlg = createChildAlgorithm("EditInstrumentGeometry");
editAlg->setProperty("Workspace", ws);
if (m_l1 > 0.)
editAlg->setProperty("PrimaryFlightPath", m_l1);
if (!polars.empty())
editAlg->setProperty("Polar", polars);
if (!specids.empty())
editAlg->setProperty("SpectrumIDs", specids);
if (!l2s.empty())
editAlg->setProperty("L2", l2s);
if (!phis.empty())
editAlg->setProperty("Azimuthal", phis);
editAlg->executeAsChildAlg();
ws = editAlg->getProperty("Workspace");
return ws;
}
//----------------------------------------------------------------------------------------------
/** Call diffraction focus to a matrix workspace.
*/
API::MatrixWorkspace_sptr AlignAndFocusPowder::diffractionFocus(API::MatrixWorkspace_sptr ws) {
if (!m_groupWS) {
g_log.information() << "not focussing data\n";
return ws;
}
if (m_maskWS) {
API::IAlgorithm_sptr maskAlg = createChildAlgorithm("MaskDetectors");
maskAlg->setProperty("Workspace", m_groupWS);
maskAlg->setProperty("MaskedWorkspace", m_maskWS);
maskAlg->executeAsChildAlg();
}
g_log.information() << "running DiffractionFocussing started at " << Types::Core::DateAndTime::getCurrentTime()
<< "\n";
API::IAlgorithm_sptr focusAlg = createChildAlgorithm("DiffractionFocussing");
focusAlg->setProperty("InputWorkspace", ws);
focusAlg->setProperty("OutputWorkspace", ws);
focusAlg->setProperty("GroupingWorkspace", m_groupWS);
focusAlg->setProperty("PreserveEvents", m_preserveEvents);
focusAlg->executeAsChildAlg();
ws = focusAlg->getProperty("OutputWorkspace");
return ws;
}
//----------------------------------------------------------------------------------------------
/** Convert units
*/
API::MatrixWorkspace_sptr AlignAndFocusPowder::convertUnits(API::MatrixWorkspace_sptr matrixws,
const std::string &target) {
g_log.information() << "running ConvertUnits(Target=" << target << ") started at "
<< Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr convert2Alg = createChildAlgorithm("ConvertUnits");
convert2Alg->setProperty("InputWorkspace", matrixws);
convert2Alg->setProperty("OutputWorkspace", matrixws);
convert2Alg->setProperty("Target", target);
convert2Alg->executeAsChildAlg();
matrixws = convert2Alg->getProperty("OutputWorkspace");
return matrixws;
}
API::MatrixWorkspace_sptr AlignAndFocusPowder::filterResonances(API::MatrixWorkspace_sptr matrixws) {
// determine the previous units
const std::string PREVIOUS_UNITS(matrixws->getAxis(0)->unit()->unitID());
// number of resonance windows to be removed
const size_t NUM_WINDOWS = m_resonanceLower.size();
// convert to the units requested
matrixws = convertUnits(matrixws, getPropertyValue(PropertyNames::RESONANCE_UNITS));
// filter out the requested area
API::IAlgorithm_sptr maskBinsAlg = createChildAlgorithm("MaskBins");
for (size_t i = 0; i < NUM_WINDOWS; ++i) {
g_log.information() << "running MaskBins(XMin=" << m_resonanceLower[i] << ", XMax=" << m_resonanceUpper[i]
<< ") started at " << Types::Core::DateAndTime::getCurrentTime() << "\n";
maskBinsAlg->setProperty("InputWorkspace", matrixws);
maskBinsAlg->setProperty("OutputWorkspace", matrixws); // operate in-place
maskBinsAlg->setProperty("XMin", m_resonanceLower[i]);
maskBinsAlg->setProperty("XMax", m_resonanceUpper[i]);
maskBinsAlg->executeAsChildAlg();
matrixws = maskBinsAlg->getProperty("OutputWorkspace"); // update workspace pointer
}
// convert back to the original units
matrixws = convertUnits(matrixws, PREVIOUS_UNITS);
return matrixws;
}
//----------------------------------------------------------------------------------------------
/** Rebin
*/
API::MatrixWorkspace_sptr AlignAndFocusPowder::rebin(API::MatrixWorkspace_sptr matrixws) {
if (!m_delta_ragged.empty()) {
return matrixws;
} else if (m_resampleX != 0) {
// ResampleX
g_log.information() << "running ResampleX(NumberBins=" << abs(m_resampleX) << ", LogBinning=" << (m_resampleX < 0)
<< ", dMin(" << m_dmins.size() << "), dmax(" << m_dmaxs.size() << ")) started at "
<< Types::Core::DateAndTime::getCurrentTime() << "\n";
API::IAlgorithm_sptr alg = createChildAlgorithm("ResampleX");
alg->setProperty("InputWorkspace", matrixws);
alg->setProperty("OutputWorkspace", matrixws);
if ((!m_dmins.empty()) && (!m_dmaxs.empty())) {
size_t numHist = m_outputW->getNumberHistograms();
if ((numHist == m_dmins.size()) && (numHist == m_dmaxs.size())) {
alg->setProperty("XMin", m_dmins);
alg->setProperty("XMax", m_dmaxs);
} else {
g_log.information() << "Number of dmin and dmax values don't match the "
<< "number of workspace indices. Ignoring the parameters.\n";
}
}
alg->setProperty("NumberBins", abs(m_resampleX));
alg->setProperty("LogBinning", (m_resampleX < 0));
alg->executeAsChildAlg();
matrixws = alg->getProperty("OutputWorkspace");
return matrixws;
} else {
g_log.information() << "running Rebin( ";
for (double param : m_params)
g_log.information() << param << " ";
g_log.information() << ") started at " << Types::Core::DateAndTime::getCurrentTime() << "\n";
for (double param : m_params)
if (isEmpty(param))
g_log.warning("encountered empty binning parameter");
API::IAlgorithm_sptr rebin3Alg = createChildAlgorithm("Rebin");
rebin3Alg->setProperty("InputWorkspace", matrixws);
rebin3Alg->setProperty("OutputWorkspace", matrixws);
rebin3Alg->setProperty("Params", m_params);
rebin3Alg->executeAsChildAlg();
matrixws = rebin3Alg->getProperty("OutputWorkspace");
return matrixws;
}
}
//----------------------------------------------------------------------------------------------
/** RebinRagged this should only be done on the final focussed workspace
*/
API::MatrixWorkspace_sptr AlignAndFocusPowder::rebinRagged(API::MatrixWorkspace_sptr matrixws, const bool inDspace) {
// local variables to control whether or not to log individual values
bool print_xmin = false;
bool print_xmax = false;