-
Notifications
You must be signed in to change notification settings - Fork 122
/
MDNorm.cpp
1821 lines (1673 loc) · 77.7 KB
/
MDNorm.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 "MantidMDAlgorithms/MDNorm.h"
#include "MantidAPI/CommonBinsValidator.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidAPI/InstrumentValidator.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/SpectrumInfo.h"
#include "MantidDataObjects/MDHistoWorkspace.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidGeometry/Crystal/PointGroupFactory.h"
#include "MantidGeometry/Crystal/SpaceGroupFactory.h"
#include "MantidGeometry/Crystal/SymmetryOperationFactory.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/MDGeometry/HKL.h"
#include "MantidGeometry/MDGeometry/MDFrameFactory.h"
#include "MantidGeometry/MDGeometry/QSample.h"
#include "MantidKernel/ArrayLengthValidator.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/CompositeValidator.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/Strings.h"
#include "MantidKernel/UnitLabelTypes.h"
#include "MantidKernel/VectorHelper.h"
#include "MantidKernel/VisibleWhenProperty.h"
#include <boost/lexical_cast.hpp>
#include <iostream>
namespace Mantid {
namespace MDAlgorithms {
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::DataObjects;
namespace {
using VectorDoubleProperty = Kernel::PropertyWithValue<std::vector<double>>;
// function to compare two intersections (h,k,l,Momentum) by Momentum
bool compareMomentum(const std::array<double, 4> &v1, const std::array<double, 4> &v2) { return (v1[3] < v2[3]); }
// k=sqrt(energyToK * E)
constexpr double energyToK = 8.0 * M_PI * M_PI * PhysicalConstants::NeutronMass * PhysicalConstants::meV * 1e-20 /
(PhysicalConstants::h * PhysicalConstants::h);
// compare absolute values of doubles
static bool abs_compare(double a, double b) { return (std::fabs(a) < std::fabs(b)); }
} // namespace
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(MDNorm)
//----------------------------------------------------------------------------------------------
/**
* Constructor
*/
MDNorm::MDNorm()
: m_normWS(), m_inputWS(), m_isRLU(false), m_UB(3, 3, true), m_W(3, 3, true), m_transformation(), m_hX(), m_kX(),
m_lX(), m_eX(), m_hIdx(-1), m_kIdx(-1), m_lIdx(-1), m_eIdx(-1), m_numExptInfos(0), m_Ei(0.0), m_diffraction(true),
m_accumulate(false), m_dEIntegrated(true), m_samplePos(), m_beamDir(), convention("") {}
/// Algorithms name for identification. @see Algorithm::name
const std::string MDNorm::name() const { return "MDNorm"; }
/// Algorithm's version for identification. @see Algorithm::version
int MDNorm::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string MDNorm::category() const { return "MDAlgorithms\\Normalisation"; }
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string MDNorm::summary() const {
return "Bins multidimensional data and calculate the normalization on the "
"same grid";
}
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void MDNorm::init() {
declareProperty(
std::make_unique<WorkspaceProperty<API::IMDEventWorkspace>>("InputWorkspace", "", Kernel::Direction::Input),
"An input MDEventWorkspace. Must be in Q_sample frame.");
declareProperty(std::make_unique<WorkspaceProperty<API::IMDEventWorkspace>>(
"BackgroundWorkspace", "", Kernel::Direction::Input, PropertyMode::Optional),
"An (optional) input MDEventWorkspace for background. Must be in Q_lab frame.");
// RLU and settings
declareProperty("RLU", true, "Use reciprocal lattice units. If false, use Q_sample");
setPropertyGroup("RLU", "Q projections RLU");
auto mustBe3D = std::make_shared<Kernel::ArrayLengthValidator<double>>(3);
std::vector<double> Q0(3, 0.), Q1(3, 0), Q2(3, 0);
Q0[0] = 1.;
Q1[1] = 1.;
Q2[2] = 1.;
declareProperty(std::make_unique<ArrayProperty<double>>("QDimension0", Q0, mustBe3D),
"The first Q projection axis - Default is (1,0,0)");
setPropertySettings("QDimension0", std::make_unique<Kernel::VisibleWhenProperty>("RLU", IS_EQUAL_TO, "1"));
setPropertyGroup("QDimension0", "Q projections RLU");
declareProperty(std::make_unique<ArrayProperty<double>>("QDimension1", Q1, mustBe3D),
"The second Q projection axis - Default is (0,1,0)");
setPropertySettings("QDimension1", std::make_unique<Kernel::VisibleWhenProperty>("RLU", IS_EQUAL_TO, "1"));
setPropertyGroup("QDimension1", "Q projections RLU");
declareProperty(std::make_unique<ArrayProperty<double>>("QDimension2", Q2, mustBe3D),
"The thirdtCalculateCover Q projection axis - Default is (0,0,1)");
setPropertySettings("QDimension2", std::make_unique<Kernel::VisibleWhenProperty>("RLU", IS_EQUAL_TO, "1"));
setPropertyGroup("QDimension2", "Q projections RLU");
// vanadium
auto fluxValidator = std::make_shared<CompositeValidator>();
fluxValidator->add<InstrumentValidator>();
fluxValidator->add<CommonBinsValidator>();
auto solidAngleValidator = fluxValidator->clone();
declareProperty(std::make_unique<WorkspaceProperty<>>("SolidAngleWorkspace", "", Direction::Input,
API::PropertyMode::Optional, solidAngleValidator),
"An input workspace containing integrated vanadium "
"(a measure of the solid angle).\n"
"Mandatory for diffraction, optional for direct geometry inelastic");
declareProperty(std::make_unique<WorkspaceProperty<>>("FluxWorkspace", "", Direction::Input,
API::PropertyMode::Optional, fluxValidator),
"An input workspace containing momentum dependent flux.\n"
"Mandatory for diffraction. No effect on direct geometry inelastic");
setPropertyGroup("SolidAngleWorkspace", "Vanadium normalization");
setPropertyGroup("FluxWorkspace", "Vanadium normalization");
// Define slicing
for (std::size_t i = 0; i < 6; i++) {
std::string propName = "Dimension" + Strings::toString(i) + "Name";
std::string propBinning = "Dimension" + Strings::toString(i) + "Binning";
std::string defaultName = "";
if (i < 3) {
defaultName = "QDimension" + Strings::toString(i);
}
declareProperty(std::make_unique<PropertyWithValue<std::string>>(propName, defaultName, Direction::Input),
"Name for the " + Strings::toString(i) + "th dimension. Leave blank for NONE.");
auto atMost3 = std::make_shared<ArrayLengthValidator<double>>(0, 3);
std::vector<double> temp;
declareProperty(std::make_unique<ArrayProperty<double>>(propBinning, temp, atMost3),
"Binning for the " + Strings::toString(i) + "th dimension.\n" +
"- Leave blank for complete integration\n" +
"- One value is interpreted as step\n"
"- Two values are interpreted integration interval\n" +
"- Three values are interpreted as min, step, max");
setPropertyGroup(propName, "Binning");
setPropertyGroup(propBinning, "Binning");
}
// symmetry operations
declareProperty(std::make_unique<PropertyWithValue<std::string>>("SymmetryOperations", "", Direction::Input),
"If specified the symmetry will be applied, "
"can be space group name, point group name, or list "
"individual symmetries.");
// temporary workspaces
declareProperty(std::make_unique<WorkspaceProperty<IMDHistoWorkspace>>("TemporaryDataWorkspace", "", Direction::Input,
PropertyMode::Optional),
"An (optional) input MDHistoWorkspace used to accumulate data from "
"multiple MDEventWorkspaces. If unspecified a blank "
"MDHistoWorkspace will be created.");
declareProperty(std::make_unique<WorkspaceProperty<IMDHistoWorkspace>>("TemporaryNormalizationWorkspace", "",
Direction::Input, PropertyMode::Optional),
"An (optional) input MDHistoWorkspace used to accumulate normalization "
"from multiple MDEventWorkspaces. If unspecified a blank "
"MDHistoWorkspace will be created.");
// temporary background workspace
declareProperty(std::make_unique<WorkspaceProperty<IMDHistoWorkspace>>("TemporaryBackgroundDataWorkspace", "",
Direction::Input, PropertyMode::Optional),
"An (optional) input MDHistoWorkspace used to accumulate background from "
"multiple background MDEventWorkspaces. If unspecified but "
"BackgroundWorkspace is specified, a blank "
"MDHistoWorkspace will be created.");
declareProperty(std::make_unique<WorkspaceProperty<IMDHistoWorkspace>>("TemporaryBackgroundNormalizationWorkspace",
"", Direction::Input, PropertyMode::Optional),
"An (optional) input MDHistoWorkspace used to accumulate background normalization "
"from multiple background MDEventWorkspaces. If unspecified but "
"BackgroundWorkspace is specified, a blank "
"MDHistoWorkspace will be created.");
setPropertyGroup("TemporaryDataWorkspace", "Temporary workspaces");
setPropertyGroup("TemporaryNormalizationWorkspace", "Temporary workspaces");
setPropertyGroup("TemporaryBackgroundDataWorkspace", "Temporary workspaces");
setPropertyGroup("TemporaryBackgroundNormalizationWorkspace", "Temporary workspaces");
declareProperty(std::make_unique<WorkspaceProperty<API::Workspace>>("OutputWorkspace", "", Kernel::Direction::Output),
"A name for the normalized output MDHistoWorkspace.");
declareProperty(
std::make_unique<WorkspaceProperty<API::Workspace>>("OutputDataWorkspace", "", Kernel::Direction::Output),
"A name for the output data MDHistoWorkspace.");
declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("OutputNormalizationWorkspace", "", Direction::Output),
"A name for the output normalization MDHistoWorkspace.");
declareProperty(std::make_unique<WorkspaceProperty<API::Workspace>>(
"OutputBackgroundDataWorkspace", "", Kernel::Direction::Output, PropertyMode::Optional),
"A name for the optional output background data MDHistoWorkspace.");
declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("OutputBackgroundNormalizationWorkspace", "",
Direction::Output, PropertyMode::Optional),
"A name for the optional output background normalization MDHistoWorkspace.");
}
//----------------------------------------------------------------------------------------------
/// Validate the input workspace @see Algorithm::validateInputs
std::map<std::string, std::string> MDNorm::validateInputs() {
std::map<std::string, std::string> errorMessage;
// Check for input workspace frame
Mantid::API::IMDEventWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
if (inputWS->getNumDims() < 3) {
errorMessage.emplace("InputWorkspace", "The input workspace must be at least 3D");
} else {
for (size_t i = 0; i < 3; i++) {
if (inputWS->getDimension(i)->getMDFrame().name() != Mantid::Geometry::QSample::QSampleName) {
errorMessage.emplace("InputWorkspace", "The input workspace must be in Q_sample");
}
}
}
// Optional background input IMDE
Mantid::API::IMDEventWorkspace_sptr bkgdWS = this->getProperty("BackgroundWorkspace");
if (bkgdWS) {
if (bkgdWS->getNumDims() < 3) {
// must have at least 3 dimensions
errorMessage.emplace("BackgroundWorkspace", "The input background workspace must be at least 3D");
} else {
// Check first 3 dimension for Q lab,
for (size_t i = 0; i < 3; i++) {
if (bkgdWS->getDimension(i)->getMDFrame().name() != Mantid::Geometry::QLab::QLabName) {
errorMessage.emplace("BackgroundWorkspace", "The input backgound workspace must be in Q_lab");
}
}
// Check 4th dimension if input workspace is elastic
if (inputWS->getNumDims() > 3) {
if (bkgdWS->getNumDims() <= 3) {
errorMessage.emplace("BackgroundWorkspace", "The input background workspace must have at 4 dimensions when "
"input workspace has more than 4 dimensions (inelastic case).");
} else if (bkgdWS->getDimension(3)->getMDFrame().name() != inputWS->getDimension(3)->getMDFrame().name()) {
errorMessage.emplace("BackgroundWorkspace", "The input background workspace 4th dimension must be DeltaE "
"for inelastic case.");
}
}
}
}
// Check if the vanadium is available for diffraction
bool diffraction = true;
if ((inputWS->getNumDims() > 3) && (inputWS->getDimension(3)->getName() == "DeltaE")) {
diffraction = false;
}
if (diffraction) {
API::MatrixWorkspace_const_sptr solidAngleWS = getProperty("SolidAngleWorkspace");
API::MatrixWorkspace_const_sptr fluxWS = getProperty("FluxWorkspace");
if (solidAngleWS == nullptr) {
errorMessage.emplace("SolidAngleWorkspace", "SolidAngleWorkspace is required for diffraction");
}
if (fluxWS == nullptr) {
errorMessage.emplace("FluxWorkspace", "FluxWorkspace is required for diffraction");
}
}
// Check for property MDNorm_low and MDNorm_high
size_t nExperimentInfos = inputWS->getNumExperimentInfo();
if (nExperimentInfos == 0) {
errorMessage.emplace("InputWorkspace", "There must be at least one experiment info");
} else {
for (size_t iExpInfo = 0; iExpInfo < nExperimentInfos; iExpInfo++) {
auto ¤tExptInfo = *(inputWS->getExperimentInfo(static_cast<uint16_t>(iExpInfo)));
if (!currentExptInfo.run().hasProperty("MDNorm_low")) {
errorMessage.emplace("InputWorkspace", "Missing MDNorm_low log. Please "
"use CropWorkspaceForMDNorm "
"before converting to MD");
}
if (!currentExptInfo.run().hasProperty("MDNorm_high")) {
errorMessage.emplace("InputWorkspace", "Missing MDNorm_high log. Please use "
"CropWorkspaceForMDNorm before converting to MD");
}
}
}
// check projections and UB
if (getProperty("RLU")) {
DblMatrix W = DblMatrix(3, 3);
std::vector<double> Q0Basis = getProperty("QDimension0");
std::vector<double> Q1Basis = getProperty("QDimension1");
std::vector<double> Q2Basis = getProperty("QDimension2");
W.setColumn(0, Q0Basis);
W.setColumn(1, Q1Basis);
W.setColumn(2, Q2Basis);
if (fabs(W.determinant()) < 1e-5) {
errorMessage.emplace("QDimension0", "The projection dimensions are coplanar or zero");
errorMessage.emplace("QDimension1", "The projection dimensions are coplanar or zero");
errorMessage.emplace("QDimension2", "The projection dimensions are coplanar or zero");
}
if (!inputWS->getExperimentInfo(0)->sample().hasOrientedLattice()) {
errorMessage.emplace("InputWorkspace", "There is no oriented lattice "
"associated with the input workspace. "
"Use SetUB algorithm");
}
}
// check dimension names
std::vector<std::string> originalDimensionNames;
for (size_t i = 3; i < inputWS->getNumDims(); i++) {
originalDimensionNames.emplace_back(inputWS->getDimension(i)->getName());
}
originalDimensionNames.emplace_back("QDimension0");
originalDimensionNames.emplace_back("QDimension1");
originalDimensionNames.emplace_back("QDimension2");
std::vector<std::string> selectedDimensions;
for (std::size_t i = 0; i < 6; i++) {
std::string propName = "Dimension" + Strings::toString(i) + "Name";
std::string dimName = getProperty(propName);
std::string binningName = "Dimension" + Strings::toString(i) + "Binning";
std::vector<double> binning = getProperty(binningName);
if (!dimName.empty()) {
auto it = std::find(originalDimensionNames.begin(), originalDimensionNames.end(), dimName);
if (it == originalDimensionNames.end()) {
errorMessage.emplace(propName, "Name '" + dimName +
"' is not one of the "
"original workspace names or a directional dimension");
} else {
// make sure dimension is unique
auto itSel = std::find(selectedDimensions.begin(), selectedDimensions.end(), dimName);
if (itSel == selectedDimensions.end()) {
selectedDimensions.emplace_back(dimName);
} else {
errorMessage.emplace(propName, "Name '" + dimName + "' was already selected");
}
}
} else {
if (!binning.empty()) {
errorMessage.emplace(binningName, "There should be no binning if the dimension name is empty");
}
}
}
// since Q dimensions can be non - orthogonal, all must be present
if ((std::find(selectedDimensions.begin(), selectedDimensions.end(), "QDimension0") == selectedDimensions.end()) ||
(std::find(selectedDimensions.begin(), selectedDimensions.end(), "QDimension1") == selectedDimensions.end()) ||
(std::find(selectedDimensions.begin(), selectedDimensions.end(), "QDimension2") == selectedDimensions.end())) {
for (std::size_t i = 0; i < 6; i++) {
std::string propName = "Dimension" + Strings::toString(i) + "Name";
errorMessage.emplace(propName, "All of QDimension0, QDimension1, QDimension2 must be present");
}
}
// symmetry operations
std::string symOps = this->getProperty("SymmetryOperations");
if (!symOps.empty()) {
bool isSpaceGroup = Geometry::SpaceGroupFactory::Instance().isSubscribed(symOps);
bool isPointGroup = Geometry::PointGroupFactory::Instance().isSubscribed(symOps);
if (!isSpaceGroup && !isPointGroup) {
try {
Geometry::SymmetryOperationFactory::Instance().createSymOps(symOps);
} catch (const Mantid::Kernel::Exception::ParseError &) {
errorMessage.emplace("SymmetryOperations", "The input is not a space group, a point group, "
"or a list of symmetry operations");
}
}
}
// validate accumulation workspaces, if provided
std::shared_ptr<IMDHistoWorkspace> tempNormWS = this->getProperty("TemporaryNormalizationWorkspace");
Mantid::API::IMDHistoWorkspace_sptr tempDataWS = this->getProperty("TemporaryDataWorkspace");
// check that either both or neuther accumulation workspaces are provied
if ((tempNormWS && !tempDataWS) || (!tempNormWS && tempDataWS)) {
errorMessage.emplace("TemporaryDataWorkspace", "Must provide either no accumulation workspaces or,"
"both TemporaryNormalizationWorkspaces and TemporaryDataWorkspace");
}
// check that both accumulation workspaces are on the same grid
if (tempNormWS && tempDataWS) {
size_t numNormDims = tempNormWS->getNumDims();
size_t numDataDims = tempDataWS->getNumDims();
if (numNormDims == numDataDims) {
for (size_t i = 0; i < numNormDims; i++) {
const auto dim1 = tempNormWS->getDimension(i);
const auto dim2 = tempDataWS->getDimension(i);
if ((dim1->getMinimum() != dim2->getMinimum()) || (dim1->getMaximum() != dim2->getMaximum()) ||
(dim1->getNBins() != dim2->getNBins()) || (dim1->getName() != dim2->getName())) {
errorMessage.emplace("TemporaryDataWorkspace", "Binning for TemporaryNormalizationWorkspaces "
"and TemporaryDataWorkspace must be the same.");
break;
}
}
} else { // accumulation workspaces have different number of dimensions
errorMessage.emplace("TemporaryDataWorkspace", "TemporaryNormalizationWorkspace and TemporaryDataWorkspace "
"do not have the same number of dimensions");
}
}
// validate accumulated background workspaces
Mantid::API::IMDHistoWorkspace_sptr tempBkgdDataWS = this->getProperty("TemporaryBackgroundDataWorkspace");
Mantid::API::IMDHistoWorkspace_sptr tempBkgdNormWS = this->getProperty("TemporaryBackgroundNormalizationWorkspace");
// check existing criteria: Background, TempBackgroundData and
// TempBackgroundNormalization must be specified
if (tempBkgdDataWS && (!bkgdWS || !tempDataWS || !tempBkgdNormWS)) {
errorMessage.emplace("TemporaryBackgroundDataWorkspace", "TemporaryBackgroundDataWorkspace is specified but at "
"least one of these is not.");
} else if (tempBkgdNormWS && (!bkgdWS || !tempNormWS || !tempBkgdDataWS)) {
errorMessage.emplace("TemporaryBackgroundNormalizationWorkspace", "TemporaryBackgroundNormalizationWorkspace is "
"specified but at least one of these is not.");
} else if (bkgdWS && tempDataWS && !tempBkgdDataWS) {
errorMessage.emplace("TemporaryDataWorkspace",
"With Background is specifed and TemporaryDataWorkspace is specifed, "
"TemporaryBackgroundDataWorkspace must be specified.");
} else if (tempBkgdDataWS && tempNormWS) {
// check when they both exist
size_t numBkgdDataDims = tempBkgdDataWS->getNumDims();
size_t numBkgdNormDims = tempBkgdNormWS->getNumDims();
size_t numDataDims = tempDataWS->getNumDims();
if (numBkgdDataDims == numBkgdNormDims && numBkgdDataDims == numDataDims) {
// On each dimension, compare min, max, NBins and name
for (size_t idim = 0; idim < numBkgdDataDims; ++idim) {
const auto dimB = tempBkgdDataWS->getDimension(idim);
const auto dimN = tempBkgdNormWS->getDimension(idim);
const auto dimD = tempDataWS->getDimension(idim);
if ((dimB->getMinimum() != dimN->getMinimum()) || (dimB->getMinimum() != dimD->getMinimum()) ||
(dimB->getMaximum() != dimN->getMaximum()) || (dimB->getMaximum() != dimD->getMaximum()) ||
(dimB->getNBins() != dimN->getNBins()) || (dimB->getNBins() != dimD->getNBins()) ||
(dimB->getName() != dimN->getName()) || (dimB->getName() != dimD->getName())) {
errorMessage.emplace("TemporaryBackgroundDataWorkspace",
"TemporaryBackgroundDataWorkspace, "
"TemporaryBackgroundNormalizationWorkspace and "
"TemporaryDataWorkspace "
"must have same minimum, maximum, number of bins and name.");
break;
}
}
} else {
errorMessage.emplace("TemporaryBackgroundDataWorkspace", "TemporaryBackgroundDataWorkspace, "
"TemporaryBackgroundNormalizationWorkspace and "
"TemporaryDataWorkspace must have same dimensions");
}
}
return errorMessage;
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void MDNorm::exec() {
convention = Kernel::ConfigService::Instance().getString("Q.convention");
// symmetry operations
std::string symOps = this->getProperty("SymmetryOperations");
std::vector<Geometry::SymmetryOperation> symmetryOps;
if (symOps.empty()) {
symOps = "x,y,z";
}
if (Geometry::SpaceGroupFactory::Instance().isSubscribed(symOps)) {
auto spaceGroup = Geometry::SpaceGroupFactory::Instance().createSpaceGroup(symOps);
auto pointGroup = spaceGroup->getPointGroup();
symmetryOps = pointGroup->getSymmetryOperations();
} else if (Geometry::PointGroupFactory::Instance().isSubscribed(symOps)) {
auto pointGroup = Geometry::PointGroupFactory::Instance().createPointGroup(symOps);
symmetryOps = pointGroup->getSymmetryOperations();
} else {
symmetryOps = Geometry::SymmetryOperationFactory::Instance().createSymOps(symOps);
}
g_log.debug() << "Symmetry operations\n";
for (auto so : symmetryOps) {
g_log.debug() << so.identifier() << "\n";
}
m_numSymmOps = symmetryOps.size();
m_isRLU = getProperty("RLU");
// get the workspaces
m_inputWS = this->getProperty("InputWorkspace");
const auto &exptInfoZero = *(m_inputWS->getExperimentInfo(0));
auto source = exptInfoZero.getInstrument()->getSource();
auto sample = exptInfoZero.getInstrument()->getSample();
if (source == nullptr || sample == nullptr) {
throw Kernel::Exception::InstrumentDefinitionError(
"Instrument not sufficiently defined: failed to get source and/or "
"sample");
}
m_samplePos = sample->getPos();
m_beamDir = normalize(m_samplePos - source->getPos());
if ((m_inputWS->getNumDims() > 3) && (m_inputWS->getDimension(3)->getName() == "DeltaE")) {
// DeltaE in input MDE: it cannot be diffraction!
m_diffraction = false;
if (exptInfoZero.run().hasProperty("Ei")) {
Kernel::Property *eiprop = exptInfoZero.run().getProperty("Ei");
m_Ei = boost::lexical_cast<double>(eiprop->value());
if (m_Ei <= 0) {
throw std::invalid_argument("Ei stored in the workspace is not positive");
}
} else {
throw std::invalid_argument("Could not find Ei value in the workspace.");
}
}
// Calculate (BinMD) input sample MDE to MDH and create noramlization MDH from
// it
auto outputDataWS = binInputWS(symmetryOps);
createNormalizationWS(*outputDataWS);
this->setProperty("OutputNormalizationWorkspace", m_normWS);
this->setProperty("OutputDataWorkspace", outputDataWS);
// Background
m_backgroundWS = this->getProperty("BackgroundWorkspace");
DataObjects::MDHistoWorkspace_sptr outputBackgroundDataWS(nullptr);
// Outputs for background related
if (m_backgroundWS) {
outputBackgroundDataWS = binBackgroundWS(symmetryOps);
createBackgroundNormalizationWS(*outputBackgroundDataWS);
this->setProperty("OutputBackgroundNormalizationWorkspace", m_bkgdNormWS);
this->setProperty("OutputBackgroundDataWorkspace", outputBackgroundDataWS);
}
m_numExptInfos = outputDataWS->getNumExperimentInfo();
// loop over all experiment infos
for (uint16_t expInfoIndex = 0; expInfoIndex < m_numExptInfos; expInfoIndex++) {
// Check for other dimensions if we could measure anything in the original
// data
bool skipNormalization = false;
const std::vector<coord_t> otherValues = getValuesFromOtherDimensions(skipNormalization, expInfoIndex);
cacheDimensionXValues();
if (!skipNormalization) {
size_t symmOpsIndex = 0;
for (const auto &so : symmetryOps) {
calculateNormalization(otherValues, so, expInfoIndex, symmOpsIndex);
symmOpsIndex++;
}
} else {
g_log.warning("Binning limits are outside the limits of the MDWorkspace. "
"Not applying normalization.");
}
// if more than one experiment info, keep accumulating
m_accumulate = true;
}
API::IMDWorkspace_sptr out(nullptr);
if (m_backgroundWS) {
// Normalize binned (BinMD) sample workspace with background
out = divideMD(outputDataWS, m_normWS, getPropertyValue("OutputWorkspace"), 0.97, 0.98);
// Normalize background
const std::string normedBkgdWSName("_normedBkgd");
API::IMDWorkspace_sptr outbkgd = divideMD(outputBackgroundDataWS, m_bkgdNormWS, normedBkgdWSName, 0.98, 0.99);
// Clean workspace
IAlgorithm_sptr minusMD = createChildAlgorithm("MinusMD", 0.99, 1.00);
// set up
minusMD->setProperty("LHSWorkspace", out);
minusMD->setProperty("RHSWorkspace", outbkgd);
minusMD->setPropertyValue("OutputWorkspace", getPropertyValue("OutputWorkspace"));
// run and return
minusMD->executeAsChildAlg();
out = minusMD->getProperty("OutputWorkspace");
} else {
// Normalize binned (BinMD) sample workspace without background
out = divideMD(outputDataWS, m_normWS, getPropertyValue("OutputWorkspace"), 0.97, 1.);
}
// Set output workspace
this->setProperty("OutputWorkspace", out);
}
inline API::IMDWorkspace_sptr MDNorm::divideMD(API::IMDHistoWorkspace_sptr lhs, API::IMDHistoWorkspace_sptr rhs,
const std::string &outputwsname, const double &startProgress,
const double &endProgress) {
IAlgorithm_sptr divideMD = createChildAlgorithm("DivideMD", startProgress, endProgress);
divideMD->setProperty("LHSWorkspace", lhs);
divideMD->setProperty("RHSWorkspace", rhs);
divideMD->setPropertyValue("OutputWorkspace", outputwsname);
divideMD->executeAsChildAlg();
// API::IMDWorkspace_sptr
API::IMDWorkspace_sptr out = divideMD->getProperty("OutputWorkspace");
return out;
}
/**
* Get the dimension name when not using reciprocal lattice units.
* @param i - axis number to return axis name for. Can be 0, 1, or 2.
* @return string containing the name
*/
std::string MDNorm::QDimensionNameQSample(int i) {
if (i == 0)
return std::string("Q_sample_x");
else if (i == 1)
return std::string("Q_sample_y");
else if (i == 2)
return std::string("Q_sample_z");
else
throw std::invalid_argument("Index must be 0, 1, or 2 for QDimensionNameQSample");
}
/**
* Get the dimension name when using reciprocal lattice units.
* @param projection - a vector with 3 elements, containing a
* description of the projection ("1,-1,0" for "[H,-H,0]")
* @return string containing the name
*/
std::string MDNorm::QDimensionName(std::vector<double> projection) {
std::vector<double>::iterator result;
result = std::max_element(projection.begin(), projection.end(), abs_compare);
std::vector<char> symbol{'H', 'K', 'L'};
char character = symbol[std::distance(projection.begin(), result)];
std::stringstream name;
name << "[";
for (size_t i = 0; i < 3; i++) {
if (projection[i] == 0) {
name << "0";
} else if (projection[i] == 1) {
name << character;
} else if (projection[i] == -1) {
name << "-" << character;
} else {
name << std::defaultfloat << std::setprecision(3) << projection[i] << character;
}
if (i != 2) {
name << ",";
}
}
name << "]";
return name.str();
}
/**
* Calculate binning parameters
* @return map of parameters to be passed to BinMD (non axis-aligned)
*/
std::map<std::string, std::string> MDNorm::getBinParameters() {
std::map<std::string, std::string> parameters;
std::stringstream extents;
std::stringstream bins;
std::vector<std::string> originalDimensionNames;
originalDimensionNames.emplace_back("QDimension0");
originalDimensionNames.emplace_back("QDimension1");
originalDimensionNames.emplace_back("QDimension2");
for (size_t i = 3; i < m_inputWS->getNumDims(); i++) {
originalDimensionNames.emplace_back(m_inputWS->getDimension(i)->getName());
}
if (m_isRLU) {
m_Q0Basis = getProperty("QDimension0");
m_Q1Basis = getProperty("QDimension1");
m_Q2Basis = getProperty("QDimension2");
m_UB = m_inputWS->getExperimentInfo(0)->sample().getOrientedLattice().getUB() * 2 * M_PI;
}
std::vector<double> W(m_Q0Basis);
W.insert(W.end(), m_Q1Basis.begin(), m_Q1Basis.end());
W.insert(W.end(), m_Q2Basis.begin(), m_Q2Basis.end());
m_W = DblMatrix(W);
m_W.Transpose();
// Find maximum Q
auto &exptInfo0 = *(m_inputWS->getExperimentInfo(static_cast<uint16_t>(0)));
auto upperLimitsVector =
(*(dynamic_cast<Kernel::PropertyWithValue<std::vector<double>> *>(exptInfo0.getLog("MDNorm_high"))))();
double maxQ;
if (m_diffraction) {
maxQ = 2. * (*std::max_element(upperLimitsVector.begin(), upperLimitsVector.end()));
} else {
double Ei;
double maxDE = *std::max_element(upperLimitsVector.begin(), upperLimitsVector.end());
auto loweLimitsVector =
(*(dynamic_cast<Kernel::PropertyWithValue<std::vector<double>> *>(exptInfo0.getLog("MDNorm_low"))))();
double minDE = *std::min_element(loweLimitsVector.begin(), loweLimitsVector.end());
if (exptInfo0.run().hasProperty("Ei")) {
Kernel::Property *eiprop = exptInfo0.run().getProperty("Ei");
Ei = boost::lexical_cast<double>(eiprop->value());
if (Ei <= 0) {
throw std::invalid_argument("Ei stored in the workspace is not positive");
}
} else {
throw std::invalid_argument("Could not find Ei value in the workspace.");
}
const double energyToK = 8.0 * M_PI * M_PI * PhysicalConstants::NeutronMass * PhysicalConstants::meV * 1e-20 /
(PhysicalConstants::h * PhysicalConstants::h);
double ki = std::sqrt(energyToK * Ei);
double kfmin = std::sqrt(energyToK * (Ei - minDE));
double kfmax = std::sqrt(energyToK * (Ei - maxDE));
maxQ = ki + std::max(kfmin, kfmax);
}
size_t basisVectorIndex = 0;
std::vector<coord_t> transformation;
for (std::size_t i = 0; i < 6; i++) {
std::string propName = "Dimension" + Strings::toString(i) + "Name";
std::string binningName = "Dimension" + Strings::toString(i) + "Binning";
std::string dimName = getProperty(propName);
std::vector<double> binning = getProperty(binningName);
std::string bv = "BasisVector";
if (!dimName.empty()) {
std::string property = bv + Strings::toString(basisVectorIndex);
std::stringstream propertyValue;
propertyValue << dimName;
// get the index in the original workspace
auto dimIndex = std::distance(originalDimensionNames.begin(),
std::find(originalDimensionNames.begin(), originalDimensionNames.end(), dimName));
auto dimension = m_inputWS->getDimension(dimIndex);
propertyValue << "," << dimension->getMDUnits().getUnitLabel().ascii();
for (size_t j = 0; j < originalDimensionNames.size(); j++) {
if (j == static_cast<size_t>(dimIndex)) {
propertyValue << ",1";
transformation.emplace_back(1.f);
} else {
propertyValue << ",0";
transformation.emplace_back(0.f);
}
}
parameters.emplace(property, propertyValue.str());
// get the extents an number of bins
coord_t dimMax = dimension->getMaximum();
coord_t dimMin = dimension->getMinimum();
if (m_isRLU) {
Mantid::Geometry::OrientedLattice ol;
ol.setUB(m_UB * m_W); // note that this is already multiplied by 2Pi
if (dimIndex == 0) {
dimMax = static_cast<coord_t>(ol.a() * maxQ);
dimMin = -dimMax;
} else if (dimIndex == 1) {
dimMax = static_cast<coord_t>(ol.b() * maxQ);
dimMin = -dimMax;
} else if (dimIndex == 2) {
dimMax = static_cast<coord_t>(ol.c() * maxQ);
dimMin = -dimMax;
}
}
if (binning.size() == 0) {
// only one bin, integrating from min to max
extents << dimMin << "," << dimMax << ",";
bins << 1 << ",";
} else if (binning.size() == 2) {
// only one bin, integrating from min to max
extents << binning[0] << "," << binning[1] << ",";
bins << 1 << ",";
} else if (binning.size() == 1) {
auto step = binning[0];
double nsteps = (dimMax - dimMin) / step;
if (nsteps + 1 - std::ceil(nsteps) >= 1e-4) {
nsteps = std::ceil(nsteps);
} else {
nsteps = std::floor(nsteps);
}
bins << static_cast<int>(nsteps) << ",";
extents << dimMin << "," << dimMin + nsteps * step << ",";
} else if (binning.size() == 3) {
dimMin = static_cast<coord_t>(binning[0]);
auto step = binning[1];
dimMax = static_cast<coord_t>(binning[2]);
double nsteps = (dimMax - dimMin) / step;
if (nsteps + 1 - std::ceil(nsteps) >= 1e-4) {
nsteps = std::ceil(nsteps);
} else {
nsteps = std::floor(nsteps);
}
bins << static_cast<int>(nsteps) << ",";
extents << dimMin << "," << dimMin + nsteps * step << ",";
}
basisVectorIndex++;
}
}
parameters.emplace("OutputExtents", extents.str());
parameters.emplace("OutputBins", bins.str());
m_transformation = Mantid::Kernel::Matrix<coord_t>(
transformation, static_cast<size_t>((transformation.size()) / m_inputWS->getNumDims()), m_inputWS->getNumDims());
return parameters;
}
/**
* Create & cached the normalization workspace
* @param dataWS The binned workspace that will be used for the data
*/
void MDNorm::createNormalizationWS(const DataObjects::MDHistoWorkspace &dataWS) {
// Copy the MDHisto workspace, and change signals and errors to 0.
std::shared_ptr<IMDHistoWorkspace> tmp = this->getProperty("TemporaryNormalizationWorkspace");
m_normWS = std::dynamic_pointer_cast<MDHistoWorkspace>(tmp);
if (!m_normWS) {
m_normWS = dataWS.clone();
m_normWS->setTo(0., 0., 0.);
} else {
// Temp is given. Accumulation mode is on
m_accumulate = true;
}
}
void MDNorm::createBackgroundNormalizationWS(const DataObjects::MDHistoWorkspace &bkgdDataWS) {
// requiring background workspace is specified
if (!m_backgroundWS) {
return;
}
// Copy the MDHisto workspace, and change signals and errors to 0.
std::shared_ptr<IMDHistoWorkspace> tmp = this->getProperty("TemporaryBackgroundNormalizationWorkspace");
m_bkgdNormWS = std::dynamic_pointer_cast<MDHistoWorkspace>(tmp);
if (!m_bkgdNormWS) {
m_bkgdNormWS = bkgdDataWS.clone();
m_bkgdNormWS->setTo(0., 0., 0.);
}
}
/**
* Validates the TemporaryDataWorkspace has the same binning
* as the input binning parameters
* @param parameters :: map of binning parameters
* @param tempDataWS :: the workspace weare using to aggregate from
* @return :: bool - true means the binning is correct to aggreagete using
* tempDataWS
*/
void MDNorm::validateBinningForTemporaryDataWorkspace(const std::map<std::string, std::string> ¶meters,
const Mantid::API::IMDHistoWorkspace_sptr &tempDataWS) {
// parse the paramters map and get extents from tempDataWS
const std::string numBinsStr = parameters.at("OutputBins");
const std::string extentsStr = parameters.at("OutputExtents");
const std::vector<size_t> numBins = VectorHelper::splitStringIntoVector<size_t>(numBinsStr);
const std::vector<double> extents = VectorHelper::splitStringIntoVector<double>(extentsStr);
// make sure the number of dimensions is the same for both workspaces
size_t numDimsTemp = tempDataWS->getNumDims();
if ((numBins.size() != numDimsTemp) || (extents.size() != numDimsTemp * 2)) {
std::stringstream errorMessage;
errorMessage << "The number of dimensions in the output and ";
errorMessage << "TemporaryDataWorkspace are not the same.";
throw(std::invalid_argument(errorMessage.str()));
}
// compare the extents and number of bins
for (size_t i = 0; i < numDimsTemp; i++) {
auto ax = tempDataWS->getDimension(i);
if (numBins[i] != ax->getNBins()) {
std::stringstream errorMessage;
errorMessage << "The number of bins output and number of bins in ";
errorMessage << "TemporaryDataWorkspace are not the same along ";
errorMessage << "dimension " << i;
throw(std::invalid_argument(errorMessage.str()));
}
if (std::abs(extents[2 * i] - ax->getMinimum()) > 1.e-5) {
std::stringstream errorMessage;
errorMessage << "The minimum binning value for the output and ";
errorMessage << "TemporaryDataWorkspace are not the same along ";
errorMessage << "dimension " << i;
throw(std::invalid_argument(errorMessage.str()));
}
if (std::abs(extents[2 * i + 1] - ax->getMaximum()) > 1.e-5) {
std::stringstream errorMessage;
errorMessage << "The maximum binning value for the output and ";
errorMessage << "TemporaryDataWorkspace are not the same along ";
errorMessage << "dimension " << i;
throw(std::invalid_argument(errorMessage.str()));
}
}
// sort out which axes are dimensional and check names
size_t parametersIndex = 0;
std::vector<size_t> dimensionIndex(numDimsTemp + 1, 3); // stores h, k, l or Qx, Qy, Qz dimensions
for (auto const &p : parameters) {
auto key = p.first;
auto value = p.second;
// value starts with QDimension0, then other stuff
// do not use ==
if (value.find("QDimension0") != std::string::npos) {
dimensionIndex[0] = parametersIndex;
const std::string dimXName = tempDataWS->getDimension(parametersIndex)->getName();
if (m_isRLU) { // hkl
if (dimXName != QDimensionName(m_Q0Basis)) {
std::stringstream errorMessage;
std::stringstream debugMessage;
errorMessage << "TemporaryDataWorkspace does not have the ";
errorMessage << "correct name for dimension " << parametersIndex;
debugMessage << "QDimension0 Names: Output will be: " << QDimensionName(m_Q0Basis);
debugMessage << " TemporaryDataWorkspace: " << dimXName;
g_log.warning(debugMessage.str());
throw(std::invalid_argument(errorMessage.str()));
}
} else {
if (dimXName != QDimensionNameQSample(0)) {
std::stringstream errorMessage;
std::stringstream debugMessage;
errorMessage << "TemporaryDataWorkspace does not have the ";
errorMessage << "correct name for dimension " << parametersIndex;
debugMessage << "QDimension0 Names: Output will be: " << QDimensionNameQSample(0);
debugMessage << " TemporaryDataWorkspace: " << dimXName;
g_log.warning(debugMessage.str());
throw(std::invalid_argument(errorMessage.str()));
}
}
} else if (value.find("QDimension1") != std::string::npos) {
dimensionIndex[1] = parametersIndex;
const std::string dimYName = tempDataWS->getDimension(parametersIndex)->getName();
if (m_isRLU) { // hkl
if (dimYName != QDimensionName(m_Q1Basis)) {
std::stringstream errorMessage;
std::stringstream debugMessage;
errorMessage << "TemporaryDataWorkspace does not have the ";
errorMessage << "correct name for dimension " << parametersIndex;
debugMessage << "QDimension1 Names: Output will be: " << QDimensionName(m_Q1Basis);
debugMessage << " TemporaryDataWorkspace: " << dimYName;
g_log.warning(debugMessage.str());
throw(std::invalid_argument(errorMessage.str()));
}
} else {
if (dimYName != QDimensionNameQSample(1)) {
std::stringstream errorMessage;
std::stringstream debugMessage;
errorMessage << "TemporaryDataWorkspace does not have the ";
errorMessage << "correct name for dimension " << parametersIndex;
debugMessage << "QDimension1 Names: Output will be: " << QDimensionNameQSample(1);
debugMessage << " TemporaryDataWorkspace: " << dimYName;
g_log.warning(debugMessage.str());
throw(std::invalid_argument(errorMessage.str()));
}
}
} else if (value.find("QDimension2") != std::string::npos) {
dimensionIndex[2] = parametersIndex;
const std::string dimZName = tempDataWS->getDimension(parametersIndex)->getName();
if (m_isRLU) { // hkl
if (dimZName != QDimensionName(m_Q2Basis)) {
std::stringstream errorMessage;
std::stringstream debugMessage;
errorMessage << "TemporaryDataWorkspace does not have the ";
errorMessage << "correct name for dimension " << parametersIndex;
debugMessage << "QDimension2 Names: Output will be: " << QDimensionName(m_Q2Basis);
debugMessage << " TemporaryDataWorkspace: " << dimZName;
g_log.warning(debugMessage.str());
throw(std::invalid_argument(errorMessage.str()));
}
} else {
if (dimZName != QDimensionNameQSample(2)) {
std::stringstream errorMessage;
std::stringstream debugMessage;
errorMessage << "TemporaryDataWorkspace does not have the ";
errorMessage << "correct name for dimension " << parametersIndex;
debugMessage << "QDimension2 Names: Output will be: " << QDimensionNameQSample(2);
debugMessage << " TemporaryDataWorkspace: " << dimZName;
g_log.warning(debugMessage.str());
throw(std::invalid_argument(errorMessage.str()));
}
}
} else if ((key != "OutputBins") && (key != "OutputExtents")) {
// make sure the names of non-directional dimensions are the same
const std::string nameData = tempDataWS->getDimension(parametersIndex)->getName();
if (value.find(nameData) != 0) {
g_log.error() << "Dimension " << nameData
<< " from the temporary workspace"
" is not one of the binning dimensions, "
" or dimensions are in the wrong order."
<< std::endl;
throw(std::invalid_argument("Beside the Q dimensions, "
"TemporaryDataWorkspace does not have the "
"same dimension names as OutputWorkspace."));
}
}
parametersIndex++;
}
for (auto &idx : dimensionIndex) {
if (idx > numDimsTemp)
throw(std::invalid_argument("Cannot find at least one of QDimension0, "
"QDimension1, or QDimension2"));
}
}
/**
* Calculate symmetry operation matrix from Symmetry operation
* @param so :: symmetry operation
* @return :: matrix
*/
inline DblMatrix MDNorm::buildSymmetryMatrix(const Geometry::SymmetryOperation &so) {
// calculate dimensions for binning
DblMatrix soMatrix(3, 3);
auto v = so.transformHKL(V3D(1, 0, 0));
soMatrix.setColumn(0, v);
v = so.transformHKL(V3D(0, 1, 0));
soMatrix.setColumn(1, v);
v = so.transformHKL(V3D(0, 0, 1));
soMatrix.setColumn(2, v);
return soMatrix;
}
// projection: input/output
// requiring: m_hIdx, m_kIndex, m_lIdx, meidx, m_dEintegrated, m_Q0Basis,
// mQ1Basis,
/**
* @brief MDNorm::determineBasisVector
* @param qindex
* @param value
* @param Qtransform
* @param projection
* @param basisVector
* @param qDimensionIndices :: output, Q dimension index mapped to input qindex
*/
inline void MDNorm::determineBasisVector(const size_t &qindex, const std::string &value,
const Mantid::Kernel::DblMatrix &Qtransform, std::vector<double> &projection,