@@ -25,22 +25,12 @@ namespace {
25
25
// / Property names.
26
26
namespace Prop {
27
27
static const std::string FLIPPERS{" Flippers" };
28
+ static const std::string SPIN_STATES{" SpinStates" };
28
29
static const std::string EFFICIENCIES{" Efficiencies" };
29
30
static const std::string INPUT_WS{" InputWorkspaces" };
30
31
static const std::string OUTPUT_WS{" OutputWorkspace" };
31
32
} // namespace Prop
32
33
33
- // / Flipper configurations.
34
- namespace Flippers {
35
- using namespace Mantid ::Algorithms;
36
- static const std::string Off{SpinStateValidator::ZERO};
37
- static const std::string OffOff{SpinStateValidator::ZERO_ZERO};
38
- static const std::string OffOn{SpinStateValidator::ZERO_ONE};
39
- static const std::string On{SpinStateValidator::ONE};
40
- static const std::string OnOff{SpinStateValidator::ONE_ZERO};
41
- static const std::string OnOn{SpinStateValidator::ONE_ONE};
42
- } // namespace Flippers
43
-
44
34
/* *
45
35
* Throw if given ws is nullptr.
46
36
* @param ws a workspace to check
@@ -313,8 +303,9 @@ const std::string PolarizationCorrectionWildes::summary() const {
313
303
" and analyzer efficiencies." ;
314
304
}
315
305
306
+ // / Algorithm's related algorithms. @see Algorithm::seeAlso
316
307
const std::vector<std::string> PolarizationCorrectionWildes::seeAlso () const {
317
- return {" PolarizationEfficienciesWildes" };
308
+ return {" PolarizationEfficiencyCor " , " PolarizationEfficienciesWildes" };
318
309
}
319
310
320
311
/* *
@@ -337,10 +328,14 @@ void PolarizationCorrectionWildes::init() {
337
328
std::make_unique<API::WorkspaceProperty<API::WorkspaceGroup>>(Prop::OUTPUT_WS, " " , Kernel::Direction::Output),
338
329
" A group of polarization efficiency corrected workspaces." );
339
330
340
- const auto spinStateValidator = std::make_shared<SpinStateValidator>(std::unordered_set<int >{1 , 2 , 3 , 4 }, true );
331
+ const auto flipperConfigValidator = std::make_shared<SpinStateValidator>(std::unordered_set<int >{1 , 2 , 3 , 4 }, true );
341
332
declareProperty (Prop::FLIPPERS,
342
- Flippers::OffOff + " , " + Flippers::OffOn + " , " + Flippers::OnOff + " , " + Flippers::OnOn,
343
- spinStateValidator, " Flipper configurations of the input workspaces." );
333
+ std::string (FlipperConfigurations::OFF_OFF) + " , " + FlipperConfigurations::OFF_ON + " , " +
334
+ FlipperConfigurations::ON_OFF + " , " + FlipperConfigurations::ON_ON,
335
+ flipperConfigValidator, " Flipper configurations of the input workspaces." );
336
+ const auto spinStateValidator =
337
+ std::make_shared<SpinStateValidator>(std::unordered_set<int >{0 , 2 , 4 }, false , ' +' , ' -' , true );
338
+ declareProperty (Prop::SPIN_STATES, " " , spinStateValidator, " The order of the spin states in the output workspace." );
344
339
declareProperty (
345
340
std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>(Prop::EFFICIENCIES, " " , Kernel::Direction::Input),
346
341
" A workspace containing the efficiency factors P1, P2, F1 and F2 as "
@@ -410,12 +405,28 @@ std::map<std::string, std::string> PolarizationCorrectionWildes::validateInputs(
410
405
}
411
406
}
412
407
const std::vector<std::string> inputs = getProperty (Prop::INPUT_WS);
413
- const std::string flipperProperty = getProperty ( Prop::FLIPPERS);
414
- const auto flipperCount = PolarizationCorrectionsHelpers::splitSpinStateString (flipperProperty) .size ();
408
+ const auto flipperConfig = PolarizationCorrectionsHelpers::splitSpinStateString ( getPropertyValue ( Prop::FLIPPERS) );
409
+ const auto flipperCount = flipperConfig .size ();
415
410
if (inputs.size () != flipperCount) {
416
411
issues[Prop::FLIPPERS] = " The number of flipper configurations (" + std::to_string (flipperCount) +
417
412
" ) does not match the number of input workspaces (" + std::to_string (inputs.size ()) + " )" ;
418
413
}
414
+ // SpinStates checks.
415
+ const auto spinStates = PolarizationCorrectionsHelpers::splitSpinStateString (getPropertyValue (Prop::SPIN_STATES));
416
+ if (inputs.size () == 1 && !spinStates.empty ()) {
417
+ issues[Prop::SPIN_STATES] = " Output workspace order cannot be set for direct beam calculations." ;
418
+ } else if (!spinStates.empty ()) {
419
+ if (flipperConfig.front ().size () == 1 && spinStates.size () != 2 ) {
420
+ issues[Prop::SPIN_STATES] =
421
+ " Incorrect number of workspaces in output configuration: " + std::to_string (spinStates.size ()) +
422
+ " . Only two output workspaces are produced when an analyzer is not used." ;
423
+ }
424
+ if (flipperConfig.front ().size () == 2 && spinStates.size () != 4 ) {
425
+ issues[Prop::SPIN_STATES] =
426
+ " Incorrect number of workspaces in output configuration: " + std::to_string (spinStates.size ()) +
427
+ " . Four output workspaces are produced by the corrections." ;
428
+ }
429
+ }
419
430
return issues;
420
431
}
421
432
@@ -438,16 +449,16 @@ void PolarizationCorrectionWildes::checkConsistentNumberHistograms(const Workspa
438
449
}
439
450
};
440
451
if (inputs.mmWS ) {
441
- checkNHist (inputs.mmWS , Flippers::OnOn );
452
+ checkNHist (inputs.mmWS , FlipperConfigurations::ON_ON );
442
453
}
443
454
if (inputs.mpWS ) {
444
- checkNHist (inputs.mpWS , Flippers::OnOff );
455
+ checkNHist (inputs.mpWS , FlipperConfigurations::ON_OFF );
445
456
}
446
457
if (inputs.pmWS ) {
447
- checkNHist (inputs.pmWS , Flippers::OffOn );
458
+ checkNHist (inputs.pmWS , FlipperConfigurations::OFF_ON );
448
459
}
449
460
if (inputs.ppWS ) {
450
- checkNHist (inputs.ppWS , Flippers::OffOff );
461
+ checkNHist (inputs.ppWS , FlipperConfigurations::OFF_OFF );
451
462
}
452
463
}
453
464
@@ -484,16 +495,16 @@ void PolarizationCorrectionWildes::checkConsistentX(const WorkspaceMap &inputs,
484
495
}
485
496
};
486
497
if (inputs.mmWS ) {
487
- checkWS (inputs.mmWS , Flippers::OnOn );
498
+ checkWS (inputs.mmWS , FlipperConfigurations::ON_ON );
488
499
}
489
500
if (inputs.mpWS ) {
490
- checkWS (inputs.mpWS , Flippers::OnOff );
501
+ checkWS (inputs.mpWS , FlipperConfigurations::ON_OFF );
491
502
}
492
503
if (inputs.pmWS ) {
493
- checkWS (inputs.pmWS , Flippers::OffOn );
504
+ checkWS (inputs.pmWS , FlipperConfigurations::OFF_ON );
494
505
}
495
506
if (inputs.ppWS ) {
496
- checkWS (inputs.ppWS , Flippers::OffOff );
507
+ checkWS (inputs.ppWS , FlipperConfigurations::OFF_OFF );
497
508
}
498
509
}
499
510
@@ -505,24 +516,26 @@ void PolarizationCorrectionWildes::checkConsistentX(const WorkspaceMap &inputs,
505
516
* @return a group workspace
506
517
*/
507
518
API::WorkspaceGroup_sptr PolarizationCorrectionWildes::groupOutput (const WorkspaceMap &outputs) {
508
- const std::string outWSName = getProperty (Prop::OUTPUT_WS);
519
+ const auto &outWSName = getPropertyValue (Prop::OUTPUT_WS);
520
+ auto spinStateOrder = getPropertyValue (Prop::SPIN_STATES);
509
521
std::vector<std::string> names;
522
+ if (!spinStateOrder.empty ()) {
523
+ names.resize (PolarizationCorrectionsHelpers::splitSpinStateString (spinStateOrder).size ());
524
+ }
525
+
510
526
if (outputs.ppWS ) {
511
- names.emplace_back (outWSName + " _++" );
512
- API::AnalysisDataService::Instance ().addOrReplace (names.back (), outputs.ppWS );
527
+ addSpinStateOutput (names, spinStateOrder, outWSName, outputs.ppWS , SpinStateConfigurationsWildes::PLUS_PLUS);
513
528
}
514
529
if (outputs.pmWS ) {
515
- names.emplace_back (outWSName + " _+-" );
516
- API::AnalysisDataService::Instance ().addOrReplace (names.back (), outputs.pmWS );
530
+ addSpinStateOutput (names, spinStateOrder, outWSName, outputs.pmWS , SpinStateConfigurationsWildes::PLUS_MINUS);
517
531
}
518
532
if (outputs.mpWS ) {
519
- names.emplace_back (outWSName + " _-+" );
520
- API::AnalysisDataService::Instance ().addOrReplace (names.back (), outputs.mpWS );
533
+ addSpinStateOutput (names, spinStateOrder, outWSName, outputs.mpWS , SpinStateConfigurationsWildes::MINUS_PLUS);
521
534
}
522
535
if (outputs.mmWS ) {
523
- names.emplace_back (outWSName + " _--" );
524
- API::AnalysisDataService::Instance ().addOrReplace (names.back (), outputs.mmWS );
536
+ addSpinStateOutput (names, spinStateOrder, outWSName, outputs.mmWS , SpinStateConfigurationsWildes::MINUS_MINUS);
525
537
}
538
+
526
539
auto group = createChildAlgorithm (" GroupWorkspaces" );
527
540
group->initialize ();
528
541
group->setProperty (" InputWorkspaces" , names);
@@ -532,6 +545,34 @@ API::WorkspaceGroup_sptr PolarizationCorrectionWildes::groupOutput(const Workspa
532
545
return outWS;
533
546
}
534
547
548
+ /* *
549
+ * Add an output name in the correct position in the vector and to the ADS.
550
+ * @param names A list of the names of the workspaces the algorithm has generated.
551
+ * @param spinStateOrder The order the output should be in.
552
+ * @param baseName The base name for the output workspaces ("BASENAME_SPINSTATE" e.g "OUTNAME_+-")
553
+ * @param ws The workspace to add to the vector and ADS.
554
+ * @param spinState The spin state the workspace represents.
555
+ */
556
+ void PolarizationCorrectionWildes::addSpinStateOutput (std::vector<std::string> &names,
557
+ const std::string &spinStateOrder, const std::string &baseName,
558
+ const API::MatrixWorkspace_sptr &ws,
559
+ const std::string &spinState) {
560
+ if (spinStateOrder.empty ()) {
561
+ names.emplace_back (baseName + " _" + spinState);
562
+ API::AnalysisDataService::Instance ().addOrReplace (names.back (), ws);
563
+ } else {
564
+ const auto &maybeIndex = PolarizationCorrectionsHelpers::indexOfWorkspaceForSpinState (
565
+ PolarizationCorrectionsHelpers::splitSpinStateString (spinStateOrder), spinState);
566
+ if (!maybeIndex.has_value ()) {
567
+ throw std::invalid_argument (" Required spin state (" + spinState + " ) not found in spin state order (" +
568
+ spinStateOrder + " )." );
569
+ }
570
+ const auto index = maybeIndex.value ();
571
+ names[index] = baseName + " _" + spinState;
572
+ API::AnalysisDataService::Instance ().addOrReplace (names[index], ws);
573
+ }
574
+ }
575
+
535
576
/* *
536
577
* Make a convenience access object to the efficiency factors.
537
578
* @return an EfficiencyMap object
@@ -566,7 +607,7 @@ PolarizationCorrectionWildes::EfficiencyMap PolarizationCorrectionWildes::effici
566
607
PolarizationCorrectionWildes::WorkspaceMap
567
608
PolarizationCorrectionWildes::directBeamCorrections (const WorkspaceMap &inputs, const EfficiencyMap &efficiencies) {
568
609
using namespace boost ::math;
569
- checkInputExists (inputs.ppWS , Flippers::Off );
610
+ checkInputExists (inputs.ppWS , FlipperConfigurations::OFF );
570
611
WorkspaceMap outputs;
571
612
outputs.ppWS = createWorkspaceWithHistory (inputs.ppWS );
572
613
const size_t nHisto = inputs.ppWS ->getNumberHistograms ();
@@ -603,8 +644,8 @@ PolarizationCorrectionWildes::directBeamCorrections(const WorkspaceMap &inputs,
603
644
PolarizationCorrectionWildes::WorkspaceMap
604
645
PolarizationCorrectionWildes::analyzerlessCorrections (const WorkspaceMap &inputs, const EfficiencyMap &efficiencies) {
605
646
using namespace boost ::math;
606
- checkInputExists (inputs.mmWS , Flippers::On );
607
- checkInputExists (inputs.ppWS , Flippers::Off );
647
+ checkInputExists (inputs.mmWS , FlipperConfigurations::ON );
648
+ checkInputExists (inputs.ppWS , FlipperConfigurations::OFF );
608
649
WorkspaceMap outputs;
609
650
outputs.mmWS = createWorkspaceWithHistory (inputs.mmWS );
610
651
outputs.ppWS = createWorkspaceWithHistory (inputs.ppWS );
@@ -667,8 +708,8 @@ PolarizationCorrectionWildes::analyzerlessCorrections(const WorkspaceMap &inputs
667
708
PolarizationCorrectionWildes::WorkspaceMap
668
709
PolarizationCorrectionWildes::twoInputCorrections (const WorkspaceMap &inputs, const EfficiencyMap &efficiencies) {
669
710
using namespace boost ::math;
670
- checkInputExists (inputs.mmWS , Flippers::OnOn );
671
- checkInputExists (inputs.ppWS , Flippers::OffOff );
711
+ checkInputExists (inputs.mmWS , FlipperConfigurations::ON_ON );
712
+ checkInputExists (inputs.ppWS , FlipperConfigurations::OFF_OFF );
672
713
WorkspaceMap fullInputs = inputs;
673
714
fullInputs.mpWS = createWorkspaceWithHistory (inputs.mmWS );
674
715
fullInputs.pmWS = createWorkspaceWithHistory (inputs.ppWS );
@@ -688,13 +729,13 @@ PolarizationCorrectionWildes::twoInputCorrections(const WorkspaceMap &inputs, co
688
729
PolarizationCorrectionWildes::WorkspaceMap
689
730
PolarizationCorrectionWildes::threeInputCorrections (const WorkspaceMap &inputs, const EfficiencyMap &efficiencies) {
690
731
WorkspaceMap fullInputs = inputs;
691
- checkInputExists (inputs.mmWS , Flippers::OnOn );
692
- checkInputExists (inputs.ppWS , Flippers::OffOff );
732
+ checkInputExists (inputs.mmWS , FlipperConfigurations::ON_ON );
733
+ checkInputExists (inputs.ppWS , FlipperConfigurations::OFF_OFF );
693
734
if (!inputs.mpWS ) {
694
- checkInputExists (inputs.pmWS , Flippers::OffOn );
735
+ checkInputExists (inputs.pmWS , FlipperConfigurations::OFF_ON );
695
736
threeInputsSolve10 (fullInputs, efficiencies);
696
737
} else {
697
- checkInputExists (inputs.mpWS , Flippers::OnOff );
738
+ checkInputExists (inputs.mpWS , FlipperConfigurations::ON_OFF );
698
739
threeInputsSolve01 (fullInputs, efficiencies);
699
740
}
700
741
return fullCorrections (fullInputs, efficiencies);
@@ -711,10 +752,10 @@ PolarizationCorrectionWildes::threeInputCorrections(const WorkspaceMap &inputs,
711
752
PolarizationCorrectionWildes::WorkspaceMap
712
753
PolarizationCorrectionWildes::fullCorrections (const WorkspaceMap &inputs, const EfficiencyMap &efficiencies) {
713
754
using namespace boost ::math;
714
- checkInputExists (inputs.mmWS , Flippers::OnOn );
715
- checkInputExists (inputs.mpWS , Flippers::OnOff );
716
- checkInputExists (inputs.pmWS , Flippers::OffOn );
717
- checkInputExists (inputs.ppWS , Flippers::OffOff );
755
+ checkInputExists (inputs.mmWS , FlipperConfigurations::ON_ON );
756
+ checkInputExists (inputs.mpWS , FlipperConfigurations::ON_OFF );
757
+ checkInputExists (inputs.pmWS , FlipperConfigurations::OFF_ON );
758
+ checkInputExists (inputs.ppWS , FlipperConfigurations::OFF_OFF );
718
759
WorkspaceMap outputs;
719
760
outputs.mmWS = createWorkspaceWithHistory (inputs.mmWS );
720
761
outputs.mpWS = createWorkspaceWithHistory (inputs.mpWS );
@@ -781,13 +822,13 @@ PolarizationCorrectionWildes::mapInputsToDirections(const std::vector<std::strin
781
822
throw std::runtime_error (" One of the input workspaces doesn't seem to be a MatrixWorkspace." );
782
823
}
783
824
const auto &f = flippers[i];
784
- if (f == Flippers::OnOn || f == Flippers::On ) {
825
+ if (f == FlipperConfigurations::ON_ON || f == FlipperConfigurations::ON ) {
785
826
inputs.mmWS = ws;
786
- } else if (f == Flippers::OnOff ) {
827
+ } else if (f == FlipperConfigurations::ON_OFF ) {
787
828
inputs.mpWS = ws;
788
- } else if (f == Flippers::OffOn ) {
829
+ } else if (f == FlipperConfigurations::OFF_ON ) {
789
830
inputs.pmWS = ws;
790
- } else if (f == Flippers::OffOff || f == Flippers::Off ) {
831
+ } else if (f == FlipperConfigurations::OFF_OFF || f == FlipperConfigurations::OFF ) {
791
832
inputs.ppWS = ws;
792
833
} else {
793
834
throw std::runtime_error (std::string{" Unknown entry in " } + Prop::FLIPPERS);
0 commit comments