diff --git a/Framework/Algorithms/CMakeLists.txt b/Framework/Algorithms/CMakeLists.txt index d045be7561bcc89ade3f78ea121361ce6307d4bc..dd1dc1bb0e795adc475cbfd5b669ad8b860719af 100644 --- a/Framework/Algorithms/CMakeLists.txt +++ b/Framework/Algorithms/CMakeLists.txt @@ -6,28 +6,22 @@ set ( SRC_FILES src/AddSampleLog.cpp src/AddTimeSeriesLog.cpp src/AlignDetectors.cpp -# src/AlphaCalc.cpp src/AnnularRingAbsorption.cpp src/AnyShapeAbsorption.cpp src/ApodizationFunctions.cpp src/AppendSpectra.cpp src/ApplyCalibration.cpp -# src/ApplyDeadTimeCorr.cpp src/ApplyDetailedBalance.cpp src/ApplyTransmissionCorrection.cpp -# src/AsymmetryCalc.cpp src/AverageLogData.cpp src/Bin2DPowderDiffraction.cpp src/BinaryOperateMasks.cpp src/BinaryOperation.cpp -# src/CalMuonDeadTime.cpp -# src/CalMuonDetectorPhases.cpp src/CalculateCountRate.cpp src/CalculateDIFC.cpp src/CalculateEfficiency.cpp src/CalculateFlatBackground.cpp src/CalculateCarpenterSampleCorrection.cpp -# src/CalculateMuonAsymmetry.cpp src/CalculatePolynomialBackground.cpp src/CalculateSlits.cpp src/CalculateTransmission.cpp @@ -113,7 +107,6 @@ set ( SRC_FILES src/EditInstrumentGeometry.cpp src/ElasticWindow.cpp src/EstimateDivergence.cpp -# src/EstimateMuonAsymmetryFromCounts.cpp src/EstimateResolutionDiffraction.cpp src/EventWorkspaceAccess.cpp src/Exponential.cpp @@ -202,8 +195,6 @@ set ( SRC_FILES src/MostLikelyMean.cpp src/Multiply.cpp src/MultiplyRange.cpp -# src/MuonAsymmetryHelper.cpp -# src/MuonGroupDetectors.cpp src/NRCalculateSlitResolution.cpp src/NormaliseByCurrent.cpp src/NormaliseByDetector.cpp @@ -216,8 +207,6 @@ set ( SRC_FILES src/PaddingAndApodization.cpp src/Pause.cpp src/PerformIndexOperations.cpp -# src/PhaseQuadMuon.cpp -# src/PlotAsymmetryByLogValue.cpp src/Plus.cpp src/PointByPointVCorrection.cpp src/PoissonErrors.cpp @@ -231,7 +220,6 @@ set ( SRC_FILES src/Q1DWeighted.cpp src/Qhelper.cpp src/Qxy.cpp -# src/RRFMuon.cpp src/RadiusSum.cpp src/RayTracerTester.cpp src/ReadGroupsFromFile.cpp @@ -253,7 +241,6 @@ set ( SRC_FILES src/Regroup.cpp src/RemoveBackground.cpp src/RemoveBins.cpp -# src/RemoveExpDecay.cpp src/RemoveLowResTOF.cpp src/RemoveMaskedSpectra.cpp src/RemovePromptPulse.cpp @@ -341,29 +328,23 @@ set ( INC_FILES inc/MantidAlgorithms/AddSampleLog.h inc/MantidAlgorithms/AddTimeSeriesLog.h inc/MantidAlgorithms/AlignDetectors.h -# inc/MantidAlgorithms/AlphaCalc.h inc/MantidAlgorithms/AnnularRingAbsorption.h inc/MantidAlgorithms/AnyShapeAbsorption.h inc/MantidAlgorithms/ApodizationFunctions.h inc/MantidAlgorithms/AppendSpectra.h inc/MantidAlgorithms/ApplyCalibration.h -# inc/MantidAlgorithms/ApplyDeadTimeCorr.h inc/MantidAlgorithms/ApplyDetailedBalance.h inc/MantidAlgorithms/ApplyTransmissionCorrection.h -# inc/MantidAlgorithms/AsymmetryCalc.h inc/MantidAlgorithms/AverageLogData.h inc/MantidAlgorithms/Bin2DPowderDiffraction.h inc/MantidAlgorithms/BinaryOperateMasks.h inc/MantidAlgorithms/BinaryOperation.h inc/MantidAlgorithms/BoostOptionalToAlgorithmProperty.h -# inc/MantidAlgorithms/CalMuonDeadTime.h -# inc/MantidAlgorithms/CalMuonDetectorPhases.h inc/MantidAlgorithms/CalculateCountRate.h inc/MantidAlgorithms/CalculateDIFC.h inc/MantidAlgorithms/CalculateEfficiency.h inc/MantidAlgorithms/CalculateFlatBackground.h inc/MantidAlgorithms/CalculateCarpenterSampleCorrection.h -# inc/MantidAlgorithms/CalculateMuonAsymmetry.h inc/MantidAlgorithms/CalculatePolynomialBackground.h inc/MantidAlgorithms/CalculateSlits.h inc/MantidAlgorithms/CalculateTransmission.h @@ -449,7 +430,6 @@ set ( INC_FILES inc/MantidAlgorithms/EditInstrumentGeometry.h inc/MantidAlgorithms/ElasticWindow.h inc/MantidAlgorithms/EstimateDivergence.h -# inc/MantidAlgorithms/EstimateMuonAsymmetryFromCounts.h inc/MantidAlgorithms/EstimateResolutionDiffraction.h inc/MantidAlgorithms/EventWorkspaceAccess.h inc/MantidAlgorithms/Exponential.h @@ -542,8 +522,6 @@ set ( INC_FILES inc/MantidAlgorithms/MostLikelyMean.h inc/MantidAlgorithms/Multiply.h inc/MantidAlgorithms/MultiplyRange.h -# inc/MantidAlgorithms/MuonAsymmetryHelper.h -# inc/MantidAlgorithms/MuonGroupDetectors.h inc/MantidAlgorithms/NRCalculateSlitResolution.h inc/MantidAlgorithms/NormaliseByCurrent.h inc/MantidAlgorithms/NormaliseByDetector.h @@ -556,8 +534,6 @@ set ( INC_FILES inc/MantidAlgorithms/PaddingAndApodization.h inc/MantidAlgorithms/Pause.h inc/MantidAlgorithms/PerformIndexOperations.h -# inc/MantidAlgorithms/PhaseQuadMuon.h -# inc/MantidAlgorithms/PlotAsymmetryByLogValue.h inc/MantidAlgorithms/Plus.h inc/MantidAlgorithms/PointByPointVCorrection.h inc/MantidAlgorithms/PoissonErrors.h @@ -571,7 +547,6 @@ set ( INC_FILES inc/MantidAlgorithms/Q1DWeighted.h inc/MantidAlgorithms/Qhelper.h inc/MantidAlgorithms/Qxy.h -# inc/MantidAlgorithms/RRFMuon.h inc/MantidAlgorithms/RadiusSum.h inc/MantidAlgorithms/RayTracerTester.h inc/MantidAlgorithms/ReadGroupsFromFile.h @@ -593,7 +568,6 @@ set ( INC_FILES inc/MantidAlgorithms/Regroup.h inc/MantidAlgorithms/RemoveBackground.h inc/MantidAlgorithms/RemoveBins.h -# inc/MantidAlgorithms/RemoveExpDecay.h inc/MantidAlgorithms/RemoveLowResTOF.h inc/MantidAlgorithms/RemoveMaskedSpectra.h inc/MantidAlgorithms/RemovePromptPulse.h @@ -694,27 +668,21 @@ set ( TEST_FILES AddSampleLogTest.h AddTimeSeriesLogTest.h AlignDetectorsTest.h -# AlphaCalcTest.h AnnularRingAbsorptionTest.h AnyShapeAbsorptionTest.h AppendSpectraTest.h ApplyCalibrationTest.h -# ApplyDeadTimeCorrTest.h ApplyDetailedBalanceTest.h ApplyTransmissionCorrectionTest.h -# AsymmetryCalcTest.h AverageLogDataTest.h Bin2DPowderDiffractionTest.h BinaryOperateMasksTest.h BinaryOperationTest.h -# CalMuonDeadTimeTest.h -# CalMuonDetectorPhasesTest.h CalculateCarpenterSampleCorrectionTest.h CalculateCountRateTest.h CalculateDIFCTest.h CalculateEfficiencyTest.h CalculateFlatBackgroundTest.h -# CalculateMuonAsymmetryTest.h CalculatePolynomialBackgroundTest.h CalculateSlitsTest.h CalculateTransmissionBeamSpreaderTest.h @@ -799,7 +767,6 @@ set ( TEST_FILES EditInstrumentGeometryTest.h ElasticWindowTest.h EstimateDivergenceTest.h -# EstimateMuonAsymmetryFromCountsTest.h EstimateResolutionDiffractionTest.h ExponentialCorrectionTest.h ExponentialTest.h @@ -886,7 +853,6 @@ set ( TEST_FILES MostLikelyMeanTest.h MultiplyRangeTest.h MultiplyTest.h -# MuonGroupDetectorsTest.h NRCalculateSlitResolutionTest.h NormaliseByCurrentTest.h NormaliseByDetectorTest.h @@ -898,8 +864,6 @@ set ( TEST_FILES PaddingAndApodizationTest.h PauseTest.h PerformIndexOperationsTest.h -# PhaseQuadMuonTest.h -# PlotAsymmetryByLogValueTest.h PlusTest.h PointByPointVCorrectionTest.h PoissonErrorsTest.h @@ -912,7 +876,6 @@ set ( TEST_FILES Q1D2Test.h Q1DWeightedTest.h QxyTest.h -# RRFMuonTest.h RadiusSumTest.h RayTracerTesterTest.h ReadGroupsFromFileTest.h @@ -931,7 +894,6 @@ set ( TEST_FILES RegroupTest.h RemoveBackgroundTest.h RemoveBinsTest.h -# RemoveExpDecayTest.h RemoveLowResTOFTest.h RemoveMaskedSpectraTest.h RemovePromptPulseTest.h diff --git a/Framework/Algorithms/inc/MantidAlgorithms/AlphaCalc.h b/Framework/Algorithms/inc/MantidAlgorithms/AlphaCalc.h deleted file mode 100644 index 049a4e8687017157346751dc6161af6d61a545f1..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/AlphaCalc.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef MANTID_ALGORITHM_MUONALPHACALC_H_ -#define MANTID_ALGORITHM_MUONALPHACALC_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" - -namespace Mantid { -namespace Algorithms { -/**Muon algorithm for calculating the detector efficiency between two groups of -detectors. - -Required Properties: -<UL> -<LI> InputWorkspace - The name of the Workspace2D to take as input </LI> -<LI> ForwardSpectra - The spectra numbers of the forward group </LI> -<LI> BackwardSpectra - The spectra numbers of the backward group </LI> -<LI> FirstGoodValue - First good value </LI> -<LI> LastGoodValue - Last good value </LI> -<LI> Alpha (output) </LI> -</UL> - - -@author Anders Markvardsen, ISIS, RAL -@date 21/09/2010 - -Copyright © 2008-10 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport AlphaCalc : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "AlphaCalc"; } - /// Summary of algorithms purpose - const std::string summary() const override { - return "Muon algorithm for calculating the detector efficiency between two " - "groups of detectors."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -private: - // Overridden Algorithm methods - void init() override; - void exec() override; -}; - -} // namespace Algorithm -} // namespace Mantid - -#endif /*MANTID_ALGORITHM_MUONALPHACALC_H_*/ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/ApplyDeadTimeCorr.h b/Framework/Algorithms/inc/MantidAlgorithms/ApplyDeadTimeCorr.h deleted file mode 100644 index d5ab58b031d0b0acbc80ce46f94b3d15c30fcdcb..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/ApplyDeadTimeCorr.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef MANTID_ALGORITHMS_APPLYDEADTIMECORR_H_ -#define MANTID_ALGORITHMS_APPLYDEADTIMECORR_H_ - -#include "MantidKernel/System.h" -#include "MantidAPI/Algorithm.h" - -namespace Mantid { -namespace Algorithms { - -/** ApplyDeadTimeCorr : The dead-time is here applied according to the - non-extendable paralyzable dead time model. - - @author Robert Whitley, RAL - @date 2011-11-30 - - Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge - National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport ApplyDeadTimeCorr : public API::Algorithm { -public: - /// Algorithm's name for identification - const std::string name() const override { return "ApplyDeadTimeCorr"; }; - /// Summary of algorithms purpose - const std::string summary() const override { - return "Apply deadtime correction to each spectrum of a workspace."; - } - - /// Algorithm's version for identification - int version() const override { return 1; }; - const std::vector<std::string> seeAlso() const override { - return {"CalMuonDeadTime"}; - } - /// Algorithm's category for identification - const std::string category() const override { - return "Muon;CorrectionFunctions\\EfficiencyCorrections"; - } - -private: - /// Initialise the properties - void init() override; - /// Run the algorithm - void exec() override; -}; - -} // namespace Algorithms -} // namespace Mantid - -#endif /* MANTID_ALGORITHMS_APPLYDEADTIMECORR_H_ */ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/AsymmetryCalc.h b/Framework/Algorithms/inc/MantidAlgorithms/AsymmetryCalc.h deleted file mode 100644 index 753103dba02176380d1662e1d318e7d55386de30..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/AsymmetryCalc.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef MANTID_ALGORITHM_ASYMMETRYCALC_H_ -#define MANTID_ALGORITHM_ASYMMETRYCALC_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" - -namespace Mantid { -namespace Algorithms { -/**Takes a muon workspace as input and sums all the spectra into two spectra -which represent - the two detector groupings. The resultant spectra are used to calculate -(F-aB) / (F+aB) the results of which - are stored in the output workspace. - -Required Properties: -<UL> -<LI> InputWorkspace - The name of the Workspace2D to take as input </LI> -<LI> OutputWorkspace - The name of the workspace in which to store the result -</LI> -<LI> ForwardSpectra - The detector number of the first group </LI> -<LI> BackwardSpectra - The detector number of the second group </LI> -<LI> Alpha - ?? </LI> -</UL> - - -@author -@date 11/07/2008 - -Copyright © 2008 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport AsymmetryCalc : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "AsymmetryCalc"; } - /// Summary of algorithms purpose - const std::string summary() const override { - return "Calculates the asymmetry between two groups of detectors for a " - "muon workspace."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - const std::vector<std::string> seeAlso() const override { - return {"CalculateMuonAsymmetry"}; - } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -protected: - std::map<std::string, std::string> validateInputs() override; - -private: - // Overridden Algorithm methods - void init() override; - void exec() override; -}; - -} // namespace Algorithm -} // namespace Mantid - -#endif /*MANTID_ALGORITHM_ASYMMETRYCALC_H_*/ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDeadTime.h b/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDeadTime.h deleted file mode 100644 index b69e9cb25e1e29f9c4a080923be0f7b9b8bfc5bd..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDeadTime.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef MANTID_ALGORITHM_CALMUONDEADTIME_H_ -#define MANTID_ALGORITHM_CALMUONDEADTIME_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" - -namespace Mantid { -namespace Algorithms { -/**Algorithm for calculating Muon dead times. - -@author Anders Markvardsen, ISIS, RAL -@date 1/12/2011 - -Copyright © 2008-11 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport CalMuonDeadTime : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "CalMuonDeadTime"; } - /// Summary of algorithms purpose - const std::string summary() const override { - return "Calculate Muon deadtime for each spectra in a workspace."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - const std::vector<std::string> seeAlso() const override { - return {"ApplyDeadTimeCorr"}; - } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -private: - // Overridden Algorithm methods - void init() override; - void exec() override; -}; - -} // namespace Algorithm -} // namespace Mantid - -#endif /*MANTID_ALGORITHM_CALMUONDEADTIME_H_*/ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDetectorPhases.h b/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDetectorPhases.h deleted file mode 100644 index c9e5a2bf34210d3f5bfa5bda88a33fd1f6dbaf48..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDetectorPhases.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef MANTID_ALGORITHMS_CALMUONDETECTORPHASES_H_ -#define MANTID_ALGORITHMS_CALMUONDETECTORPHASES_H_ - -#include "MantidAlgorithms/DllConfig.h" -#include "MantidAPI/Algorithm.h" -#include "MantidAPI/ITableWorkspace_fwd.h" -#include "MantidAPI/WorkspaceGroup_fwd.h" -#include "MantidGeometry/IDTypes.h" - -namespace Mantid { -namespace Indexing { -class SpectrumNumber; -} -namespace Algorithms { - -/** CalMuonDetectorPhases : Calculates asymmetry and phase for each spectra in a - workspace - - Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge - National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport CalMuonDetectorPhases : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "CalMuonDetectorPhases"; } - /// Summary of algorithms purpose - const std::string summary() const override { - return "Calculates the asymmetry and phase for each detector in a " - "workspace."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -protected: - /// Validate the inputs - std::map<std::string, std::string> validateInputs() override; - -private: - /// Initialise the algorithm - void init() override; - /// Execute the algorithm - void exec() override; - /// Prepare workspace for fit by extracting data - API::MatrixWorkspace_sptr extractDataFromWorkspace(double startTime, - double endTime); - /// Remove exponential data from workspace - API::MatrixWorkspace_sptr - removeExpDecay(const API::MatrixWorkspace_sptr &wsInput); - /// Fit the workspace - void fitWorkspace(const API::MatrixWorkspace_sptr &ws, double freq, - std::string groupName, API::ITableWorkspace_sptr &resTab, - API::WorkspaceGroup_sptr &resGroup); - /// Create the fitting function as string - std::string createFittingFunction(double freq, bool fixFreq); - /// Extract asymmetry and phase from fitting results - void extractDetectorInfo(const API::ITableWorkspace_sptr ¶mTab, - const API::ITableWorkspace_sptr &resultsTab, - const Indexing::SpectrumNumber spectrumNumber); - /// Find frequency to use in sequential fit - double getFrequency(const API::MatrixWorkspace_sptr &ws); - /// Get frequency hint to use when finding frequency - double getFrequencyHint() const; - /// Get start time for fit - double getStartTime() const; - /// Get end time for fit - double getEndTime() const; - /// Calculate detector efficiency (alpha) - double getAlpha(const API::MatrixWorkspace_sptr &ws, - const std::vector<int> &forward, - const std::vector<int> &backward); - /// Calculate asymmetry - API::MatrixWorkspace_sptr getAsymmetry(const API::MatrixWorkspace_sptr &ws, - const std::vector<int> &forward, - const std::vector<int> &backward, - const double alpha); - /// Fit asymmetry to get frequency - double fitFrequencyFromAsymmetry(const API::MatrixWorkspace_sptr &wsAsym); - /// Find the grouping from the instrument - void getGroupingFromInstrument(const API::MatrixWorkspace_sptr &ws, - std::vector<int> &forward, - std::vector<int> &backward); - /// Report progress in GUI - void reportProgress(const int thisSpectrum, const int totalSpectra); - /// Pointer to input workspace - API::MatrixWorkspace_sptr m_inputWS; -}; -} // namespace Algorithms -} // namespace Mantid - -#endif /* MANTID_ALGORITHMS_CALMUONDETECTORPHASES_H_ */ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CalculateMuonAsymmetry.h b/Framework/Algorithms/inc/MantidAlgorithms/CalculateMuonAsymmetry.h deleted file mode 100644 index b4c25a7346d3fb6d507ea5df6f2fd6387c28146d..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/CalculateMuonAsymmetry.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef MANTID_ALGORITHM_CALCULATEMUONASYMMETRY_H_ -#define MANTID_ALGORITHM_CALCULATEMUONASYMMETRY_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" -#include "MantidAPI/CompositeFunction.h" -#include "MantidHistogramData/Histogram.h" -#include "MantidKernel/cow_ptr.h" - -namespace Mantid { -namespace Algorithms { -/**Takes a muon workspace as input and calculates the -asymmetry, using a function fo the form - -N_0* [ 1 + sum_j f(t,{lambda}_j) ] - -where the sum is over a set of functions and {lambda}_j is the jth -set of input parameters. The above equation is fitted to the normalised -counts to get the asymmetry. - -Required Properties: -<UL> -<LI> InputWorkspace - The name of the Workspace2D to take as input </LI> -<LI> OutputWorkspace - The name of the workspace in which to store the result -</LI> -<LI> Spectra - The spectra to be adjusted (by default all spectra are done)</LI> -<LI> StartX - The minimum time to include the analysis </LI> -<LI> EndX - The maximum time to include in the analysis </LI> -<LI> FittingFucntion - The composite function to be used in the fitting (sum_j -f(t,{lambda}_j) ) </LI> -<LI> InputDataType - If the input data is counts or asymmetry </LI> -<LI> Minimizer - The minimizer method to use for the calculation </LI> -<LI> MaxIterations - The maximum number of iterations in the calculation </LI> -</UL> - - -@author -@date 03/03/2017 - -Copyright © 2008-9 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport CalculateMuonAsymmetry : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "CalculateMuonAsymmetry"; } - /// Summary of algorithms purpose - const std::string summary() const override { - return "This algorithm calculates the asymmetry for a transverse field."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - const std::vector<std::string> seeAlso() const override { - return {"Fit", "ConvertFitFunctionForMuonTFAsymmetry", - "EstimateMuonAsymmetryFromCounts"}; - } - - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -private: - // Overridden Algorithm methods - void init() override; - void exec() override; - // calculate Muon normalisation constant - std::vector<double> getNormConstants(std::vector<std::string> wsNames); - std::map<std::string, std::string> validateInputs() override; - double getNormValue(API::CompositeFunction_sptr &func); -}; - -} // namespace Algorithm -} // namespace Mantid - -#endif /*MANTID_ALGORITHM_CALCULATEMUONASYMMETRY_H_*/ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/EstimateMuonAsymmetryFromCounts.h b/Framework/Algorithms/inc/MantidAlgorithms/EstimateMuonAsymmetryFromCounts.h deleted file mode 100644 index 4c40b57672d000b18c39f1a0c613ef2d1edbf686..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/EstimateMuonAsymmetryFromCounts.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef MANTID_ALGORITHM_ESTIMATEMUONASYMMETRYFROMCOUNTS_H_ -#define MANTID_ALGORITHM_ESTIMATEMUONASYMMETRYFROMCOUNTS_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" -#include "MantidHistogramData/Histogram.h" -#include "MantidKernel/cow_ptr.h" - -namespace Mantid { -namespace Algorithms { -/**Takes a muon workspace as input and estimates the asymmetry, using a simple -method. - -Required Properties: -<UL> -<LI> InputWorkspace - The name of the Workspace2D to take as input </LI> -<LI> OutputWorkspace - The name of the workspace in which to store the result -</LI> -<LI> Spectra - The spectra to be adjusted (by default all spectra are done)</LI> -<LI> StartX - The minimum time to include in the analysis </LI> -<LI> EndX - The maximum time to include in the analysis </LI> -</UL> - - -@author -@date 03/03/2017 - -Copyright © 2008-9 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport EstimateMuonAsymmetryFromCounts : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { - return "EstimateMuonAsymmetryFromCounts"; - } - /// Summary of algorithms purpose - const std::string summary() const override { - return "This algorithm gives an estimate " - "for the asymmetry."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - /// Algorithm's seeAlso - const std::vector<std::string> seeAlso() const override { - return {"ConvertFitFunctionForMuonTFAsymmetry", "CalculateMuonAsymmetry"}; - }; - -private: - // Overridden Algorithm methods - void init() override; - void exec() override; - std::map<std::string, std::string> validateInputs() override; -}; - -} // namespace Algorithm -} // namespace Mantid - -#endif /*MANTID_ESTIMATEMUONASYMMETRYFROMCOUNTS_H_*/ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/MuonAsymmetryHelper.h b/Framework/Algorithms/inc/MantidAlgorithms/MuonAsymmetryHelper.h deleted file mode 100644 index bea8e2ca74d745cd87685d82cbcc87813517f961..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/MuonAsymmetryHelper.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef MANTID_ALGORITHM_MUONASYMMETRYHELPER_H_ -#define MANTID_ALGORITHM_MUONASYMMETRYHELPER_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidHistogramData/Histogram.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidKernel/cow_ptr.h" - -namespace Mantid { -/* -A set of helper functions for calculating asymmetry. Including: - Calculating the normalised counts, estimating the normalisation constant and -finding the range - of data to use in the analysis. - - -@author -@date 03/03/2017 - -Copyright © 2008-9 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -HistogramData::Histogram -normaliseCounts(const HistogramData::Histogram &histogram, - const double numGoodFrames); -// calculate Muon normalisation constant -double estimateNormalisationConst(const HistogramData::Histogram &histogram, - const double numGoodFrames, - const double startX, const double endX); -size_t startIndexFromTime(const HistogramData::BinEdges &xData, - const double startX); -size_t endIndexFromTime(const HistogramData::BinEdges &xData, - const double endX); - -void updateNormalizationTable(Mantid::API::ITableWorkspace_sptr &table, - const std::vector<std::string> &wsNamse, - const std::vector<double> &norms, - const std::vector<std::string> &methods); - -} // namespace Mantid - -#endif /*MANTID_MUONASYMMETRYHELPER_H_*/ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/MuonGroupDetectors.h b/Framework/Algorithms/inc/MantidAlgorithms/MuonGroupDetectors.h deleted file mode 100644 index ccd927821b1901968ea3697ce586f93fc45eb361..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/MuonGroupDetectors.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef MANTID_ALGORITHMS_MUONGROUPDETECTORS_H_ -#define MANTID_ALGORITHMS_MUONGROUPDETECTORS_H_ - -#include "MantidKernel/System.h" -#include "MantidAPI/Algorithm.h" - -namespace Mantid { -namespace Algorithms { - -/** MuonGroupDetectors : applies detector grouping to a workspace. (Muon - version) - - Copyright © 2013 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge - National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport MuonGroupDetectors : public API::Algorithm { -public: - const std::string name() const override; - /// Summary of algorithms purpose - const std::string summary() const override { - return "Applies detector grouping to a workspace. (Muon version)."; - } - - int version() const override; - const std::string category() const override; - -private: - void init() override; - void exec() override; -}; - -} // namespace Algorithms -} // namespace Mantid - -#endif /* MANTID_ALGORITHMS_MUONGROUPDETECTORS_H_ */ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/PhaseQuadMuon.h b/Framework/Algorithms/inc/MantidAlgorithms/PhaseQuadMuon.h deleted file mode 100644 index 8b9ffafb6b58e2918fac970b76ee09232462dc25..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/PhaseQuadMuon.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef MANTID_ALGORITHM_PHASEQUADMUON_H_ -#define MANTID_ALGORITHM_PHASEQUADMUON_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" -#include "MantidAPI/ITableWorkspace_fwd.h" -#include "MantidAPI/MatrixWorkspace_fwd.h" - -namespace Mantid { -namespace Algorithms { -/**Algorithm for calculating Muon spectra. - -@author Raquel Alvarez, ISIS, RAL -@date 1/12/2014 - -Copyright © 2014-12 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge -National Laboratory - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport PhaseQuadMuon : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "PhaseQuad"; } - /// Summary of algorithm's purpose - const std::string summary() const override { - return "Generates a quadrature phase signal."; - } - const std::vector<std::string> seeAlso() const override { - return {"MuonMaxent"}; - } - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -private: - /// Initialise the properties - void init() override; - /// Run the algorithm - void exec() override; - /// Validate inputs - std::map<std::string, std::string> validateInputs() override; - /// Calculate the normalization constants - std::vector<double> getExponentialDecay(const API::MatrixWorkspace_sptr &ws); - /// Create squashograms - API::MatrixWorkspace_sptr squash(const API::MatrixWorkspace_sptr &ws, - const API::ITableWorkspace_sptr &phase, - const std::vector<double> &n0); -}; - -} // namespace Algorithms -} // namespace Mantid - -#endif /*MANTID_ALGORITHM_PHASEQUAD_H_*/ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/PlotAsymmetryByLogValue.h b/Framework/Algorithms/inc/MantidAlgorithms/PlotAsymmetryByLogValue.h deleted file mode 100644 index f804ee642d97f165e1ea1ac3625c2827c66c7610..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/PlotAsymmetryByLogValue.h +++ /dev/null @@ -1,179 +0,0 @@ -#ifndef MANTID_ALGORITHM_PLOTASYMMETRYBULOGVALUE_H_ -#define MANTID_ALGORITHM_PLOTASYMMETRYBULOGVALUE_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" -#include "MantidDataObjects/Workspace2D.h" - -namespace Mantid { -//---------------------------------------------------------------------- -// Forward declarations -//---------------------------------------------------------------------- -namespace API { -class MatrixWorkspace; -} - -namespace Algorithms { -/**Takes a muon workspace as input and sums all the spectra into two spectra -which represent - the two detector groupings. The resultant spectra are used to calculate -(F-aB) / (F+aB) the results of which - are stored in the output workspace. - -Required Properties: -<UL> -<LI> InputWorkspace - The name of the Workspace2D to take as input </LI> -<LI> OutputWorkspace - The name of the workspace in which to store the result -</LI> -<LI> ForwardSpectra - The spectrum numbers of the forward group </LI> -<LI> BackwardSpectra - The spectrum numbers of the backward group </LI> -<LI> Alpha - balance parameter </LI> -</UL> - - -@author -@date 11/07/2008 - -Copyright © 2008 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport PlotAsymmetryByLogValue : public API::Algorithm { -public: - /// Default constructor - PlotAsymmetryByLogValue(); - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "PlotAsymmetryByLogValue"; } - /// Summary of algorithms purpose - const std::string summary() const override { - return "Calculates asymmetry for a series of log values"; - } - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - const std::vector<std::string> seeAlso() const override { - return {"AsymmetryCalc", "CalculateMuonAsymmetry", "PlotPeakByLogValue"}; - } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -private: - // Overridden Algorithm methods - void init() override; - void exec() override; - // Load run, apply dead time corrections and detector grouping - API::Workspace_sptr doLoad(size_t runNumber); - // Analyse loaded run - void doAnalysis(API::Workspace_sptr loadedWs, size_t index); - // Parse run names - void parseRunNames(std::string &firstFN, std::string &lastFN, - std::string &fnBase, std::string &fnExt, int &fnZeros); - // Load dead-time corrections from specified file - API::Workspace_sptr loadCorrectionsFromFile(const std::string &deadTimeFile); - // Apply dead-time corrections - void applyDeadtimeCorr(API::Workspace_sptr &loadedWs, - API::Workspace_sptr deadTimes); - /// Create custom detector grouping - API::Workspace_sptr createCustomGrouping(const std::vector<int> &fwd, - const std::vector<int> &bwd); - /// Group detectors - void groupDetectors(API::Workspace_sptr &loadedWs, - API::Workspace_sptr grouping); - /// Calculate the integral asymmetry for a workspace (single period) - void calcIntAsymmetry(API::MatrixWorkspace_sptr ws, double &Y, double &E); - /// Calculate the integral asymmetry for a workspace (red & green) - void calcIntAsymmetry(API::MatrixWorkspace_sptr ws_red, - API::MatrixWorkspace_sptr ws_green, double &Y, - double &E); - /// Group detectors - void groupDetectors(API::MatrixWorkspace_sptr &ws, - const std::vector<int> &spectraList); - /// Get log value - double getLogValue(API::MatrixWorkspace &ws); - /// Populate output workspace with results - void populateOutputWorkspace(API::MatrixWorkspace_sptr &outWS, int nplots); - /// Populate the hidden ws storing current results - void saveResultsToADS(API::MatrixWorkspace_sptr &outWS, int nplots); - /// Check input properties - void checkProperties(size_t &is, size_t &ie); - - /// Properties needed to load a run - /// Stores base name shared by all runs - std::string m_filenameBase; - /// Stores extension shared by all runs - std::string m_filenameExt; - /// Stores number of zeros in run name - int m_filenameZeros; - /// Store type of dead time corrections - std::string m_dtcType; - /// File to read corrections from - std::string m_dtcFile; - /// Store forward spectra - std::vector<int> m_forward_list; - /// Store backward spectra - std::vector<int> m_backward_list; - - /// Properties needed to analyse a run - /// Type of calculation: integral or differential - bool m_int; - /// Red period - int m_red; - /// Green period - int m_green; - /// Minimum time for the analysis - double m_minTime; - /// Maximum time for the analysis - double m_maxTime; - - /// Properties needed to get the log value - // LogValue name - std::string m_logName; - /// LogValue function - std::string m_logFunc; - - /// Mantid maps to store intermediate results - // Map to store log value - std::map<size_t, double> m_logValue; - // Red values - std::map<size_t, double> m_redY; - std::map<size_t, double> m_redE; - // Green values - std::map<size_t, double> m_greenY; - std::map<size_t, double> m_greenE; - // Sum values (Red + Green) - std::map<size_t, double> m_sumY; - std::map<size_t, double> m_sumE; - // Diff values (Red - Green) - std::map<size_t, double> m_diffY; - std::map<size_t, double> m_diffE; - - // String containing all the properties - std::string m_allProperties; - // Name of the hidden ws - std::string m_currResName; - /// Cached start time for first run - int64_t m_firstStart_ns; -}; - -} // namespace Algorithm -} // namespace Mantid - -#endif /*MANTID_ALGORITHM_PLOTASYMMETRYBULOGVALUE_H_*/ diff --git a/Framework/Algorithms/inc/MantidAlgorithms/RRFMuon.h b/Framework/Algorithms/inc/MantidAlgorithms/RRFMuon.h deleted file mode 100644 index 3fe15b988d54022df644550bb5456aa69796be96..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/RRFMuon.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef MANTID_ALGORITHM_RRFMUON_H_ -#define MANTID_ALGORITHM_RRFMUON_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" -#include "MantidKernel/ListValidator.h" -namespace Mantid { -namespace Algorithms { -/**Algorithm for calculating Muon decay envelope. - -@author Raquel Alvarez, ISIS, RAL -@date 5/12/2014 - -Copyright © 2014-12 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge -National Laboratory - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport RRFMuon : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "RRFMuon"; } - /// Summary of algorithm's purpose - const std::string summary() const override { - return "Calculate Muon asymmetry in the rotating reference frame (RRF)."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - const std::vector<std::string> seeAlso() const override { - return {"CalculateMuonAsymmetry"}; - } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -private: - /// Initialise the properties - void init() override; - /// Run the algorithm - void exec() override; - /// Get conversion factor from frequency units to input workspace units - double unitConversionFactor(std::string uin, std::string uuser); -}; - -} // namespace Algorithms -} // namespace Mantid - -#endif /*MANTID_ALGORITHM_RRFMUON_H_*/ \ No newline at end of file diff --git a/Framework/Algorithms/inc/MantidAlgorithms/RemoveExpDecay.h b/Framework/Algorithms/inc/MantidAlgorithms/RemoveExpDecay.h deleted file mode 100644 index 21769da0facb552071b2646d032c5bee4b5b5bc6..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/inc/MantidAlgorithms/RemoveExpDecay.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef MANTID_ALGORITHM_MUONREMOVEEXPDECAY_H_ -#define MANTID_ALGORITHM_MUONREMOVEEXPDECAY_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" -#include "MantidHistogramData/Histogram.h" -#include "MantidKernel/cow_ptr.h" - -namespace Mantid { -namespace Algorithms { -/**Takes a muon workspace as input and removes the exponential decay from a time -channel. - This is done by multiplying the data by exp(t/tmuon). - -Required Properties: -<UL> -<LI> InputWorkspace - The name of the Workspace2D to take as input </LI> -<LI> OutputWorkspace - The name of the workspace in which to store the result -</LI> -<LI> Spectra - The spectra to be adjusted (by default all spectra are done)</LI> -</UL> - - -@author -@date 11/07/2008 - -Copyright © 2008-9 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge -National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid> -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport MuonRemoveExpDecay : public API::Algorithm { -public: - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "RemoveExpDecay"; } - /// Summary of algorithms purpose - const std::string summary() const override { - return "This algorithm removes the exponential decay from a muon " - "workspace."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - const std::vector<std::string> seeAlso() const override { return {"Fit"}; } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "Muon"; } - -private: - // Overridden Algorithm methods - void init() override; - void exec() override; - // Remove exponential decay from Y and E - HistogramData::Histogram - removeDecay(const HistogramData::Histogram &histogram) const; - // calculate Muon normalisation constant - double calNormalisationConst(API::MatrixWorkspace_sptr ws, int wsIndex); -}; - -} // namespace Algorithm -} // namespace Mantid - -#endif /*MANTID_ALGORITHM_MUONREMOVEEXPDECAY_H_*/ diff --git a/Framework/Algorithms/src/AlphaCalc.cpp b/Framework/Algorithms/src/AlphaCalc.cpp deleted file mode 100644 index 49f17e8eed828791231745eec14e3cf3d145a766..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/AlphaCalc.cpp +++ /dev/null @@ -1,148 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAlgorithms/AlphaCalc.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidKernel/ArrayProperty.h" - -#include <cmath> -#include <vector> - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(AlphaCalc) - -/** Initialisation method. Declares properties to be used in algorithm. - * - */ -void AlphaCalc::init() { - - declareProperty(Kernel::make_unique<API::WorkspaceProperty<>>( - "InputWorkspace", "", Direction::Input), - "Name of the input workspace"); - - std::vector<int> forwardDefault{1}; - declareProperty( - Kernel::make_unique<ArrayProperty<int>>("ForwardSpectra", forwardDefault), - "The spectra numbers of the forward group (default to 1)"); - - std::vector<int> backwardDefault{2}; - declareProperty(Kernel::make_unique<ArrayProperty<int>>("BackwardSpectra", - backwardDefault), - "The spectra numbers of the backward group (default to 2)"); - - declareProperty("FirstGoodValue", EMPTY_DBL(), - "First good value (default lowest value of x)", - Direction::Input); - declareProperty("LastGoodValue", EMPTY_DBL(), - "Last good value (default highest value of x)", - Direction::Input); - - declareProperty("Alpha", 1.0, "The alpha efficiency (default to 1.0)", - Direction::Output); -} - -/** Executes the algorithm - * - */ -void AlphaCalc::exec() { - std::vector<int> forwardSpectraList = getProperty("ForwardSpectra"); - std::vector<int> backwardSpectraList = getProperty("BackwardSpectra"); - - double alpha = getProperty("Alpha"); - - // no point in attempting to calculate alpha if input workspace on contains - // one spectra - API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace"); - if (inputWS->getNumberHistograms() < 2) { - g_log.error() - << "Can't calculate alpha value for workspace which" - << " contains one spectrum. A default value of alpha = 1.0 is returned"; - setProperty("Alpha", alpha); - return; - } - - // if for some reason the size of forward and backward lists are zero - // default these to their defaults - if (forwardSpectraList.empty()) - forwardSpectraList.push_back(1); - if (backwardSpectraList.empty()) - backwardSpectraList.push_back(2); - - // first step is to create two workspaces which groups all forward and - // backward spectra - - API::IAlgorithm_sptr groupForward = createChildAlgorithm("GroupDetectors"); - groupForward->setProperty("InputWorkspace", inputWS); - groupForward->setProperty("OutputWorkspace", "tmp"); - groupForward->setProperty("SpectraList", forwardSpectraList); - groupForward->setProperty("KeepUngroupedSpectra", false); - groupForward->execute(); - API::MatrixWorkspace_sptr forwardWS = - groupForward->getProperty("OutputWorkspace"); - - API::IAlgorithm_sptr groupBackward = createChildAlgorithm("GroupDetectors"); - groupBackward->setProperty("InputWorkspace", inputWS); - groupBackward->setProperty("OutputWorkspace", "tmp"); - groupBackward->setProperty("SpectraList", backwardSpectraList); - groupBackward->setProperty("KeepUngroupedSpectra", false); - groupBackward->execute(); - API::MatrixWorkspace_sptr backwardWS = - groupBackward->getProperty("OutputWorkspace"); - - // calculate sum of forward counts - - double firstGoodvalue = getProperty("FirstGoodValue"); - double lastGoodvalue = getProperty("LastGoodValue"); - - API::IAlgorithm_sptr integr = createChildAlgorithm("Integration"); - integr->setProperty("InputWorkspace", forwardWS); - integr->setPropertyValue("OutputWorkspace", "tmp"); - if (firstGoodvalue != EMPTY_DBL()) - integr->setProperty("RangeLower", firstGoodvalue); - if (lastGoodvalue != EMPTY_DBL()) - integr->setProperty("RangeUpper", lastGoodvalue); - integr->execute(); - API::MatrixWorkspace_sptr out = integr->getProperty("OutputWorkspace"); - - double sumForward = out->readY(0)[0]; - - if (sumForward < 0) { - g_log.error() << "Sum of forward detector counts is negative." - << "Therefore can't calculate alpha. Return alpha = 1.0."; - setProperty("Alpha", alpha); - return; - } - - // calculate sum of backward counts - - API::IAlgorithm_sptr integrB = createChildAlgorithm("Integration"); - integrB->setProperty("InputWorkspace", backwardWS); - integrB->setPropertyValue("OutputWorkspace", "tmp"); - if (firstGoodvalue != EMPTY_DBL()) - integrB->setProperty("RangeLower", firstGoodvalue); - if (lastGoodvalue != EMPTY_DBL()) - integrB->setProperty("RangeUpper", lastGoodvalue); - integrB->execute(); - out = integrB->getProperty("OutputWorkspace"); - - double sumBackward = out->readY(0)[0]; - - if (sumBackward <= 0) { - g_log.error() << "Sum of backward detector counts is negative or zero." - << "Therefore can't calculate alpha. Return alpha = 1.0."; - setProperty("Alpha", alpha); - return; - } - - // finally calculate alpha - - setProperty("Alpha", sumForward / sumBackward); -} - -} // namespace Algorithm -} // namespace Mantid diff --git a/Framework/Algorithms/src/ApplyDeadTimeCorr.cpp b/Framework/Algorithms/src/ApplyDeadTimeCorr.cpp deleted file mode 100644 index 79331df9c003a07904a9e9e3e40723c19439ed88..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/ApplyDeadTimeCorr.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "MantidAlgorithms/ApplyDeadTimeCorr.h" -#include "MantidAPI/EqualBinSizesValidator.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/Run.h" -#include "MantidAPI/TableRow.h" -#include "MantidKernel/PropertyWithValue.h" -#include "MantidKernel/System.h" -#include "MantidKernel/TimeSeriesProperty.h" - -#include "boost/lexical_cast.hpp" - -#include <cmath> - -using std::string; -using namespace Mantid::Kernel; -using namespace Mantid::API; - -namespace Mantid { -namespace Algorithms { - -// Register the algorithm into the AlgorithmFactory -DECLARE_ALGORITHM(ApplyDeadTimeCorr) - -/** Initialize the algorithm's properties. - */ -void ApplyDeadTimeCorr::init() { - - declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "InputWorkspace", "", Direction::Input, - boost::make_shared<EqualBinSizesValidator>(0.5)), - "The name of the input workspace containing measured counts"); - - declareProperty(make_unique<API::WorkspaceProperty<API::ITableWorkspace>>( - "DeadTimeTable", "", Direction::Input), - "Name of the Dead Time Table"); - - declareProperty( - make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "OutputWorkspace", "", Direction::Output), - "The name of the output workspace containing corrected counts"); -} - -/** Execute the algorithm. - */ -void ApplyDeadTimeCorr::exec() { - // Get pointers to the workspace and dead time table - API::MatrixWorkspace_sptr inputWs = getProperty("InputWorkspace"); - API::ITableWorkspace_sptr deadTimeTable = getProperty("DeadTimeTable"); - - if (!(deadTimeTable->rowCount() > inputWs->getNumberHistograms())) { - // Get number of good frames from Run object. This also serves as - // a test to see if valid input workspace has been provided - - const API::Run &run = inputWs->run(); - if (run.hasProperty("goodfrm")) { - double numGoodFrames = - boost::lexical_cast<double>(run.getProperty("goodfrm")->value()); - - if (numGoodFrames == 0) { - throw std::runtime_error( - "Number of good frames in the workspace is zero"); - } - - // Duplicate the input workspace. Only need to change Y values based on - // dead time corrections - IAlgorithm_sptr duplicate = createChildAlgorithm("CloneWorkspace"); - duplicate->initialize(); - duplicate->setProperty<Workspace_sptr>( - "InputWorkspace", boost::dynamic_pointer_cast<Workspace>(inputWs)); - duplicate->execute(); - Workspace_sptr temp = duplicate->getProperty("OutputWorkspace"); - MatrixWorkspace_sptr outputWs = - boost::dynamic_pointer_cast<MatrixWorkspace>(temp); - - // Presumed to be the same for all data - double timeBinWidth(inputWs->x(0)[1] - inputWs->x(0)[0]); - - if (timeBinWidth != 0) { - try { - // Apply Dead Time - for (size_t i = 0; i < deadTimeTable->rowCount(); ++i) { - API::TableRow deadTimeRow = deadTimeTable->getRow(i); - size_t index = - static_cast<size_t>(inputWs->getIndexFromSpectrumNumber( - static_cast<int>(deadTimeRow.Int(0)))); - const auto &yIn = inputWs->y(index); - auto &yOut = outputWs->mutableY(index); - for (size_t j = 0; j < yIn.size(); ++j) { - const double temp(1 - - yIn[j] * (deadTimeRow.Double(1) / - (timeBinWidth * numGoodFrames))); - if (temp != 0) { - yOut[j] = yIn[j] / temp; - } else { - g_log.error() << "1 - MeasuredCount * (Deadtime/TimeBin width " - "is currently (" << temp - << "). Can't divide by this amount.\n"; - - throw std::invalid_argument("Can't divide by 0"); - } - } - } - - setProperty("OutputWorkspace", outputWs); - } catch (std::runtime_error &) { - throw std::invalid_argument("Invalid argument for algorithm."); - } - } else { - g_log.error() << "The time bin width is currently (" << timeBinWidth - << "). Can't divide by this amount.\n"; - - throw std::invalid_argument("Can't divide by 0"); - } - } else { - const std::string message = "To calculate Muon deadtime requires that " - "goodfrm (number of good frames) is stored " - "in InputWorkspace Run object\n"; - g_log.error() << message; - throw std::invalid_argument(message); - } - } else { - g_log.error() - << "Row count(" << deadTimeTable->rowCount() - << ") of Dead time table is bigger than the Number of Histograms(" - << inputWs->getNumberHistograms() << ").\n"; - - throw std::invalid_argument( - "Row count was bigger than the Number of Histograms."); - } -} - -} // namespace Mantid -} // namespace Algorithms diff --git a/Framework/Algorithms/src/AsymmetryCalc.cpp b/Framework/Algorithms/src/AsymmetryCalc.cpp deleted file mode 100644 index c0df464f6e29ecbe8e042efeebc464a4cce6279f..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/AsymmetryCalc.cpp +++ /dev/null @@ -1,171 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAlgorithms/AsymmetryCalc.h" -#include "MantidAPI/HistoWorkspace.h" -#include "MantidDataObjects/WorkspaceCreation.h" -#include "MantidKernel/ArrayProperty.h" - -#include <cmath> -#include <vector> - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; -using API::Progress; -using std::size_t; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(AsymmetryCalc) - -/** Initialisation method. Declares properties to be used in algorithm. - * - */ -void AsymmetryCalc::init() { - - declareProperty(make_unique<API::WorkspaceProperty<>>("InputWorkspace", "", - Direction::Input), - "Name of the input workspace"); - declareProperty( - make_unique<API::WorkspaceProperty<>>("OutputWorkspace", "", - Direction::Output), - "The name of the workspace to be created as the output of the algorithm"); - - declareProperty(make_unique<ArrayProperty<int>>("ForwardSpectra"), - "The spectra numbers of the forward group"); - declareProperty(make_unique<ArrayProperty<int>>("BackwardSpectra"), - "The spectra numbers of the backward group"); - declareProperty("Alpha", 1.0, "The balance parameter (default 1)", - Direction::Input); -} - -//---------------------------------------------------------------------------------------------- -/** Validates the inputs. - */ -std::map<std::string, std::string> AsymmetryCalc::validateInputs() { - - std::map<std::string, std::string> result; - - std::vector<int> forwd = getProperty("ForwardSpectra"); - std::vector<int> backwd = getProperty("BackwardSpectra"); - - API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace"); - if (inputWS) { - auto list = inputWS->getIndicesFromSpectra(forwd); - if (forwd.size() != list.size()) { - result["ForwardSpectra"] = - "Some of the spectra can not be found in the input workspace"; - } - - list = inputWS->getIndicesFromSpectra(backwd); - if (backwd.size() != list.size()) { - result["BackwardSpectra"] = - "Some of the spectra can not be found in the input workspace"; - } - } - return result; -} - -/** Executes the algorithm - * - */ -void AsymmetryCalc::exec() { - std::vector<int> forward_list = getProperty("ForwardSpectra"); - std::vector<int> backward_list = getProperty("BackwardSpectra"); - int forward = !forward_list.empty() ? forward_list[0] : 1; - int backward = !backward_list.empty() ? backward_list[0] : 2; - double alpha = getProperty("Alpha"); - - // Get original workspace - API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace"); - - // Make an intermediate workspace and prepare it for asymmetry calculation - API::MatrixWorkspace_sptr tmpWS; - if (forward_list.size() > 1 || backward_list.size() > 1) { - // If forward or backward lists have more than 1 entries spectra need to be - // grouped - - // First group spectra from the backward list leaving the rest ungrouped - API::IAlgorithm_sptr group = createChildAlgorithm("GroupDetectors"); - group->setProperty("InputWorkspace", inputWS); - group->setProperty("SpectraList", backward_list); - group->setProperty("KeepUngroupedSpectra", true); - group->execute(); - tmpWS = group->getProperty("OutputWorkspace"); - - // Then group spectra from the forward list leaving the rest ungrouped - group = createChildAlgorithm("GroupDetectors"); - group->setProperty("InputWorkspace", tmpWS); - group->setProperty("SpectraList", forward_list); - group->setProperty("KeepUngroupedSpectra", true); - group->execute(); - tmpWS = group->getProperty("OutputWorkspace"); - - // The order of grouping leaves the forward spectra group in the first - // histogram - // and the barckward one is the second - forward = 0; - backward = 1; - } else { - // If the forward and backward lists are empty or have at most 1 index - // there is no need for grouping and the input workspace can be used - // directly - tmpWS = inputWS; - - // get workspace indices from spectra ids for forward and backward - std::vector<specnum_t> specIDs(2); - specIDs[0] = forward; - specIDs[1] = backward; - std::vector<size_t> indices = tmpWS->getIndicesFromSpectra(specIDs); - - forward = static_cast<int>(indices[0]); - backward = static_cast<int>(indices[1]); - } - - const size_t blocksize = inputWS->blocksize(); - assert(tmpWS->blocksize() == blocksize); - - // Create a point data workspace with only one spectra for forward - auto outputWS = DataObjects::create<API::HistoWorkspace>( - *inputWS, 1, tmpWS->points(forward)); - outputWS->getSpectrum(0).setDetectorID(static_cast<detid_t>(1)); - - // Calculate asymmetry for each time bin - // asym = (F - a*B) / (F + a*B) - Progress prog(this, 0.0, 1.0, blocksize); - for (size_t j = 0; j < blocksize; ++j) { - double numerator = tmpWS->y(forward)[j] - alpha * tmpWS->y(backward)[j]; - double denominator = (tmpWS->y(forward)[j] + alpha * tmpWS->y(backward)[j]); - if (denominator != 0.0) { - outputWS->mutableY(0)[j] = numerator / denominator; - } else { - outputWS->mutableY(0)[j] = 0.; - } - - // Work out the error (as in 1st attachment of ticket #4188) - // using standard error propagation formula and simplifying the result we - // get : error_asym = Sqrt( 1 + asym^2) * Sqrt( error_F^2 + a^2 * - // error_B^2) / (F + a) F, B are counts and so using Poisson errors (i.e. - // error_F = Sqrt(F) ) - double error = 1.0; - if (denominator != 0.0) { - double q1 = tmpWS->y(forward)[j] + alpha * alpha * tmpWS->y(backward)[j]; - double q2 = 1 + numerator * numerator / (denominator * denominator); - error = sqrt(q1 * q2) / denominator; - } - outputWS->mutableE(0)[j] = error; - - prog.report(); - } - - assert(outputWS->x(0).size() == blocksize); - - // Update Y axis units - outputWS->setYUnit("Asymmetry"); - - setProperty("OutputWorkspace", std::move(outputWS)); -} - -} // namespace Algorithm -} // namespace Mantid diff --git a/Framework/Algorithms/src/CalMuonDeadTime.cpp b/Framework/Algorithms/src/CalMuonDeadTime.cpp deleted file mode 100644 index 9a20acc268106670ba8eff2352868796325005bb..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/CalMuonDeadTime.cpp +++ /dev/null @@ -1,229 +0,0 @@ -#include "MantidAlgorithms/CalMuonDeadTime.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/IFunction.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/Run.h" -#include "MantidAPI/TableRow.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/PhysicalConstants.h" - -#include <cmath> -#include <vector> - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(CalMuonDeadTime) - -/** Initialisation method. Declares properties to be used in algorithm. - * - */ -void CalMuonDeadTime::init() { - - declareProperty(make_unique<API::WorkspaceProperty<>>("InputWorkspace", "", - Direction::Input), - "Name of the input workspace"); - - declareProperty(make_unique<API::WorkspaceProperty<API::ITableWorkspace>>( - "DeadTimeTable", "", Direction::Output), - "The name of the TableWorkspace in which to store the list " - "of deadtimes for each spectrum"); - - declareProperty("FirstGoodData", 0.5, "The first good data point in units of " - "micro-seconds as measured from time " - "zero (default to 0.5)", - Direction::Input); - - declareProperty("LastGoodData", 5.0, "The last good data point in units of " - "micro-seconds as measured from time " - "zero (default to 5.0)", - Direction::Input); - - declareProperty(make_unique<API::WorkspaceProperty<API::Workspace>>( - "DataFitted", "", Direction::Output), - "The data which the deadtime equation is fitted to"); -} - -/** Executes the algorithm - * - */ -void CalMuonDeadTime::exec() { - // Muon lifetime - - const double muonLifetime = Mantid::PhysicalConstants::MuonLifetime * - 1e6; // in units of micro-seconds - - // get input properties - - API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace"); - const double firstgooddata = getProperty("FirstGoodData"); - const double lastgooddata = getProperty("LastGoodData"); - - // Seem to have to do this to avoid MantidPlot to crash when - // running this algorithm where the "DataFitted" WS already exists - - std::string dataFittedName = getPropertyValue("DataFitted"); - if (API::AnalysisDataService::Instance().doesExist(dataFittedName)) - API::AnalysisDataService::Instance().remove(dataFittedName); - - // Get number of good frames from Run object. This also serves as - // a test to see if valid input workspace has been provided - - const double numGoodFrames = [&inputWS]() { - const API::Run &run = inputWS->run(); - if (run.hasProperty("goodfrm")) { - return boost::lexical_cast<double>(run.getProperty("goodfrm")->value()); - } else { - throw std::runtime_error( - "To calculate Muon deadtime requires that goodfrm (number of " - "good frames) is stored in InputWorkspace Run object"); - } - }(); - - // Do the initial setup of the ouput table-workspace - - API::ITableWorkspace_sptr outTable = - API::WorkspaceFactory::Instance().createTable("TableWorkspace"); - outTable->addColumn("int", "spectrum"); - outTable->addColumn("double", "dead-time"); - - // Start created a temperary workspace with data we are going to fit - // against. First step is to crop to only include data between firstgooddata - // and lastgooddata - - std::string wsName = "TempForMuonCalDeadTime"; - API::IAlgorithm_sptr cropWS; - cropWS = createChildAlgorithm("CropWorkspace", -1, -1); - cropWS->setProperty("InputWorkspace", inputWS); - cropWS->setPropertyValue("OutputWorkspace", "croppedWS"); - cropWS->setProperty("XMin", firstgooddata); - cropWS->setProperty("XMax", lastgooddata); - cropWS->executeAsChildAlg(); - - // get cropped input workspace - - boost::shared_ptr<API::MatrixWorkspace> wsCrop = - cropWS->getProperty("OutputWorkspace"); - - // next step is to take these data. Create a point workspace - // which will change the x-axis values to mid-point time values - // and populate - // x-axis with measured counts - // y-axis with measured counts * exp(t/t_mu) - - API::IAlgorithm_sptr convertToPW; - convertToPW = createChildAlgorithm("ConvertToPointData", -1, -1); - convertToPW->setProperty("InputWorkspace", wsCrop); - convertToPW->setPropertyValue("OutputWorkspace", wsName); - convertToPW->executeAsChildAlg(); - - // get pointworkspace - - boost::shared_ptr<API::MatrixWorkspace> wsFitAgainst = - convertToPW->getProperty("OutputWorkspace"); - - const size_t numSpec = wsFitAgainst->getNumberHistograms(); - size_t timechannels = wsFitAgainst->y(0).size(); - for (size_t i = 0; i < numSpec; i++) { - auto &fitX = wsFitAgainst->mutableX(i); - auto &fitY = wsFitAgainst->mutableY(i); - auto &fitE = wsFitAgainst->mutableE(i); - auto &cFitX = wsFitAgainst->x(i); - auto &cropY = wsCrop->y(i); - auto &cropE = wsCrop->e(i); - - for (size_t t = 0; t < timechannels; t++) { - const double time = cFitX[t]; // mid-point time value because point WS - const double decayFac = exp(time / muonLifetime); - if (cropY[t] > 0) { - fitY[t] = cropY[t] * decayFac; - fitX[t] = cropY[t]; - fitE[t] = cropE[t] * decayFac; - } else { - // For the Muon data which I have looked at when zero counts - // the errors are zero which is likely nonsense. Hence to get - // around this problem treat such counts to be 0.1 with standard - // of one........ - - fitY[t] = 0.1 * decayFac; - fitX[t] = 0.1; - fitE[t] = decayFac; - } - } - } - - // This property is returned for instrument scientists to - // play with on the odd occasion - - setProperty("DataFitted", wsFitAgainst); - - // cal deadtime for each spectrum - - for (size_t i = 0; i < numSpec; i++) { - // Do linear fit - - const double in_bg0 = inputWS->y(i)[0]; - const double in_bg1 = 0.0; - - API::IAlgorithm_sptr fit; - fit = createChildAlgorithm("Fit", -1, -1, true); - - std::stringstream ss; - ss << "name=LinearBackground,A0=" << in_bg0 << ",A1=" << in_bg1; - std::string function = ss.str(); - - fit->setPropertyValue("Function", function); - const int wsindex = static_cast<int>(i); - fit->setProperty("InputWorkspace", wsFitAgainst); - fit->setProperty("WorkspaceIndex", wsindex); - fit->setPropertyValue("Minimizer", "Levenberg-MarquardtMD"); - - fit->executeAsChildAlg(); - - std::string fitStatus = fit->getProperty("OutputStatus"); - // std::vector<double> params = fit->getProperty("Parameters"); - // std::vector<std::string> paramnames = fit->getProperty("ParameterNames"); - API::IFunction_sptr result = fit->getProperty("Function"); - - // Check order of names - if (result->parameterName(0) != "A0") { - g_log.error() << "Parameter 0 should be A0, but is " - << result->parameterName(0) << '\n'; - throw std::invalid_argument( - "Parameters are out of order @ 0, should be A0"); - } - if (result->parameterName(1) != "A1") { - g_log.error() << "Parameter 1 should be A1, but is " - << result->parameterName(1) << '\n'; - throw std::invalid_argument( - "Parameters are out of order @ 0, should be A1"); - } - - // time bin - assumed constant for histogram - const double time_bin = inputWS->x(i)[1] - inputWS->x(i)[0]; - - if (fitStatus == "success") { - const double A0 = result->getParameter(0); - const double A1 = result->getParameter(1); - - // add row to output table - API::TableRow t = outTable->appendRow(); - t << wsindex + 1 << -(A1 / A0) * time_bin * numGoodFrames; - } else { - g_log.warning() << "Fit falled. Status = " << fitStatus - << "\nFor workspace index " << i << '\n'; - } - } - - // finally calculate alpha - - setProperty("DeadTimeTable", outTable); -} - -} // namespace Algorithm -} // namespace Mantid diff --git a/Framework/Algorithms/src/CalMuonDetectorPhases.cpp b/Framework/Algorithms/src/CalMuonDetectorPhases.cpp deleted file mode 100644 index 552cc623db6a4a0af10c52758ae550e1a82d8c6e..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/CalMuonDetectorPhases.cpp +++ /dev/null @@ -1,580 +0,0 @@ -#include "MantidAlgorithms/CalMuonDetectorPhases.h" - -#include "MantidAPI/Axis.h" -#include "MantidAPI/FunctionFactory.h" -#include "MantidAPI/GroupingLoader.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/IFunction.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/MultiDomainFunction.h" -#include "MantidAPI/Run.h" -#include "MantidAPI/TableRow.h" -#include "MantidIndexing/IndexInfo.h" -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/PhysicalConstants.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidAPI/WorkspaceGroup.h" - -namespace { -int PHASE_ROW = 2; -double ASYMM_ERROR = 999.0; -} - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; - -// Register the algorithm into the AlgorithmFactory -DECLARE_ALGORITHM(CalMuonDetectorPhases) - -/** Initializes the algorithm's properties. - */ -void CalMuonDetectorPhases::init() { - - declareProperty(make_unique<API::WorkspaceProperty<>>("InputWorkspace", "", - Direction::Input), - "Name of the reference input workspace"); - - declareProperty("FirstGoodData", EMPTY_DBL(), - "First good data point in units of micro-seconds", - Direction::Input); - - declareProperty("LastGoodData", EMPTY_DBL(), - "Last good data point in units of micro-seconds", - Direction::Input); - - declareProperty("Frequency", EMPTY_DBL(), - "Starting hint for the frequency in MHz", Direction::Input); - - declareProperty(make_unique<API::WorkspaceProperty<API::ITableWorkspace>>( - "DetectorTable", "", Direction::Output), - "Name of the TableWorkspace in which to store the list " - "of phases and asymmetries"); - - declareProperty(make_unique<API::WorkspaceProperty<API::WorkspaceGroup>>( - "DataFitted", "", Direction::Output), - "Name of the output workspace holding fitting results"); - - declareProperty( - make_unique<ArrayProperty<int>>("ForwardSpectra", Direction::Input), - "The spectra numbers of the forward group. If not specified " - "will read from file."); - - declareProperty( - make_unique<ArrayProperty<int>>("BackwardSpectra", Direction::Input), - "The spectra numbers of the backward group. If not specified " - "will read from file."); -} - -/** Validates the inputs. - */ -std::map<std::string, std::string> CalMuonDetectorPhases::validateInputs() { - - std::map<std::string, std::string> result; - - API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace"); - - if (inputWS) { - // Check units, should be microseconds - Unit_const_sptr unit = inputWS->getAxis(0)->unit(); - if ((unit->label().ascii() != "Microseconds") && - (unit->label().ascii() != "microsecond")) { - result["InputWorkspace"] = "InputWorkspace units must be microseconds"; - } - - // Check spectra numbers are valid, if specified - int nspec = static_cast<int>(inputWS->getNumberHistograms()); - std::vector<int> forward = getProperty("ForwardSpectra"); - std::vector<int> backward = getProperty("BackwardSpectra"); - for (int spec : forward) { - if (spec < 1 || spec > nspec) { - result["ForwardSpectra"] = "Invalid spectrum numbers in ForwardSpectra"; - } - } - for (int spec : backward) { - if (spec < 1 || spec > nspec) { - result["BackwardSpectra"] = - "Invalid spectrum numbers in BackwardSpectra"; - } - } - } - return result; -} -//---------------------------------------------------------------------------------------------- -/** Executes the algorithm. - */ -void CalMuonDetectorPhases::exec() { - - // Get the input ws - m_inputWS = getProperty("InputWorkspace"); - - // Get start and end time - double startTime = getStartTime(); - double endTime = getEndTime(); - - // Prepares the workspaces: extracts data from [startTime, endTime] - API::MatrixWorkspace_sptr tempWS = - extractDataFromWorkspace(startTime, endTime); - - // Get the frequency - double freq = getFrequency(tempWS); - - // Create the output workspaces - auto tab = API::WorkspaceFactory::Instance().createTable("TableWorkspace"); - auto group = boost::make_shared<API::WorkspaceGroup>(); - - // Get the name of 'DataFitted' - std::string groupName = getPropertyValue("DataFitted"); - - // Remove exponential decay and fit the workspace - auto wsToFit = removeExpDecay(tempWS); - fitWorkspace(wsToFit, freq, groupName, tab, group); - - // Set the table - setProperty("DetectorTable", tab); - // Set the group - setProperty("DataFitted", group); -} - -/** Fits each spectrum in the workspace to f(x) = A * sin( w * x + p) -* @param ws :: [input] The workspace to fit -* @param freq :: [input] Hint for the frequency (w) -* @param groupName :: [input] The name of the output workspace group -* @param resTab :: [output] Table workspace storing the asymmetries and phases -* @param resGroup :: [output] Workspace group storing the fitting results -*/ -void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws, - double freq, std::string groupName, - API::ITableWorkspace_sptr &resTab, - API::WorkspaceGroup_sptr &resGroup) { - - int nhist = static_cast<int>(ws->getNumberHistograms()); - - // Create the fitting function f(x) = A * sin ( w * x + p ) - // The same function and initial parameters are used for each fit - std::string funcStr = createFittingFunction(freq, true); - - // Set up results table - resTab->addColumn("int", "Spectrum number"); - resTab->addColumn("double", "Asymmetry"); - resTab->addColumn("double", "Phase"); - - const auto &indexInfo = ws->indexInfo(); - - // Loop through fitting all spectra individually - const static std::string success = "success"; - for (int wsIndex = 0; wsIndex < nhist; wsIndex++) { - reportProgress(wsIndex, nhist); - auto yValues = ws->y(wsIndex); - auto emptySpectrum = std::all_of(yValues.begin(), yValues.end(), - [](double value) { return value == 0.; }); - if (emptySpectrum) { - g_log.warning("Spectrum " + std::to_string(wsIndex) + " is empty"); - auto tab = - API::WorkspaceFactory::Instance().createTable("TableWorkspace"); - tab->addColumn("str", "Name"); - tab->addColumn("double", "Value"); - tab->addColumn("double", "Error"); - for (int j = 0; j < 4; j++) { - API::TableRow row = tab->appendRow(); - if (j == PHASE_ROW) { - row << "dummy" << 0.0 << 0.0; - } else { - row << "dummy" << ASYMM_ERROR << 0.0; - } - } - - extractDetectorInfo(tab, resTab, indexInfo.spectrumNumber(wsIndex)); - - } else { - auto fit = createChildAlgorithm("Fit"); - fit->initialize(); - fit->setPropertyValue("Function", funcStr); - fit->setProperty("InputWorkspace", ws); - fit->setProperty("WorkspaceIndex", wsIndex); - fit->setProperty("CreateOutput", true); - fit->setPropertyValue("Output", groupName); - fit->execute(); - - std::string status = fit->getProperty("OutputStatus"); - if (!fit->isExecuted() || status != success) { - std::ostringstream error; - error << "Fit failed for spectrum at workspace index " << wsIndex; - error << ": " << status; - throw std::runtime_error(error.str()); - } - - API::MatrixWorkspace_sptr fitOut = fit->getProperty("OutputWorkspace"); - resGroup->addWorkspace(fitOut); - API::ITableWorkspace_sptr tab = fit->getProperty("OutputParameters"); - // Now we have our fitting results stored in tab - // but we need to extract the relevant information, i.e. - // the detector phases (parameter 'p') and asymmetries ('A') - extractDetectorInfo(tab, resTab, indexInfo.spectrumNumber(wsIndex)); - } - } -} - -/** Extracts detector asymmetries and phases from fitting results -* and adds a new row to the results table with them -* @param paramTab :: [input] Output parameter table resulting from the fit -* @param resultsTab :: [input] Results table to update with a new row -* @param spectrumNumber :: [input] Spectrum number -*/ -void CalMuonDetectorPhases::extractDetectorInfo( - const API::ITableWorkspace_sptr ¶mTab, - const API::ITableWorkspace_sptr &resultsTab, - const Indexing::SpectrumNumber spectrumNumber) { - - double asym = paramTab->Double(0, 1); - double phase = paramTab->Double(2, 1); - // If asym<0, take the absolute value and add \pi to phase - // f(x) = A * cos( w * x - p) = -A * cos( w * x - p - PI) - if (asym < 0) { - asym = -asym; - phase = phase - M_PI; - } - // Now convert phases to interval [0, 2PI) - int factor = static_cast<int>(floor(phase / (2. * M_PI))); - if (factor) { - phase = phase - factor * 2. * M_PI; - } - // Copy parameters to new row in results table - API::TableRow row = resultsTab->appendRow(); - row << static_cast<int>(spectrumNumber) << asym << phase; -} - -/** Creates the fitting function f(x) = A * cos( w*x - p) + B as string -* Two modes: -* 1) Fixed frequency, no background - for main sequential fit -* 2) Varying frequency, flat background - for finding frequency from asymmetry -* @param freq :: [input] Value for the frequency (w) -* @param fixFreq :: [input] True: fixed frequency, no background. False: varying -* frequency with flat background. -* @returns :: The fitting function as a string -*/ -std::string CalMuonDetectorPhases::createFittingFunction(double freq, - bool fixFreq) { - // The fitting function is: - // f(x) = A * sin ( w * x - p ) [+ B] - std::ostringstream ss; - ss << "name=UserFunction,"; - if (fixFreq) { - // no background - ss << "Formula=A*cos(w*x-p),"; - } else { - // flat background - ss << "Formula=A*cos(w*x-p)+B,"; - ss << "B=0.5,"; - } - ss << "A=0.5,"; - ss << "w=" << freq << ","; - ss << "p=0.5;"; - if (fixFreq) { - // w is shared across workspaces - ss << "ties=(f0.w=" << freq << ")"; - } - - return ss.str(); -} - -/** Extracts relevant data from a workspace -* @param startTime :: [input] First X value to consider -* @param endTime :: [input] Last X value to consider -* @return :: Pre-processed workspace to fit -*/ -API::MatrixWorkspace_sptr -CalMuonDetectorPhases::extractDataFromWorkspace(double startTime, - double endTime) { - // Extract counts from startTime to endTime - API::IAlgorithm_sptr crop = createChildAlgorithm("CropWorkspace"); - crop->setProperty("InputWorkspace", m_inputWS); - crop->setProperty("XMin", startTime); - crop->setProperty("XMax", endTime); - crop->executeAsChildAlg(); - boost::shared_ptr<API::MatrixWorkspace> wsCrop = - crop->getProperty("OutputWorkspace"); - return wsCrop; -} - -/** - * Removes exponential decay from a workspace - * @param wsInput :: [input] Workspace to work on - * @return :: Workspace with decay removed - */ -API::MatrixWorkspace_sptr CalMuonDetectorPhases::removeExpDecay( - const API::MatrixWorkspace_sptr &wsInput) { - API::IAlgorithm_sptr remove = createChildAlgorithm("RemoveExpDecay"); - remove->setProperty("InputWorkspace", wsInput); - remove->executeAsChildAlg(); - API::MatrixWorkspace_sptr wsRem = remove->getProperty("OutputWorkspace"); - return wsRem; -} - -/** - * Returns the frequency hint to use as a starting point for finding the - * frequency. - * - * If user has provided a frequency (MHz) as input, use that converted to - * Mrad/s. - * Otherwise, use 2*pi*g_mu*(sample_magn_field). - * (2*pi to convert MHz to Mrad/s) - * - * @return :: Frequency hint to use in Mrad/s - */ -double CalMuonDetectorPhases::getFrequencyHint() const { - double freq = getProperty("Frequency"); - - if (freq == EMPTY_DBL()) { - try { - // Read sample_magn_field from workspace logs - freq = m_inputWS->run().getLogAsSingleValue("sample_magn_field"); - // Multiply by muon gyromagnetic ratio: 0.01355 MHz/G - freq *= PhysicalConstants::MuonGyromagneticRatio; - } catch (...) { - throw std::runtime_error( - "Couldn't read sample_magn_field. Please provide a value for " - "the frequency"); - } - } - - // Convert from MHz to Mrad/s - freq *= 2 * M_PI; - - return freq; -} - -/** - * Returns the frequency to use in the sequential fit. - * - * Finds this by grouping the spectra and calculating the asymmetry, then - * fitting this to get the frequency. - * The starting value for this fit is taken from the frequency hint or logs. - * @param ws :: [input] Pointer to cropped workspace with exp decay removed - * @return :: Fixed frequency value to use in the sequential fit - */ -double -CalMuonDetectorPhases::getFrequency(const API::MatrixWorkspace_sptr &ws) { - std::vector<int> forward = getProperty("ForwardSpectra"); - std::vector<int> backward = getProperty("BackwardSpectra"); - - // If grouping not provided, read it from the instrument - if (forward.empty() || backward.empty()) { - getGroupingFromInstrument(ws, forward, backward); - } - - // Calculate asymmetry - const double alpha = getAlpha(ws, forward, backward); - const API::MatrixWorkspace_sptr wsAsym = - getAsymmetry(ws, forward, backward, alpha); - - // Fit an oscillating function, allowing frequency to vary - double frequency = fitFrequencyFromAsymmetry(wsAsym); - - return frequency; -} - -/** - * If grouping was not provided, find the instrument from the input workspace - * and read the default grouping from its IDF. Returns the forward and backward - * groupings as arrays of integers. - * @param ws :: [input] Workspace to find grouping for - * @param forward :: [output] Forward spectrum indices for given instrument - * @param backward :: [output] Backward spectrum indices for given instrument - */ -void CalMuonDetectorPhases::getGroupingFromInstrument( - const API::MatrixWorkspace_sptr &ws, std::vector<int> &forward, - std::vector<int> &backward) { - // make sure both arrays are empty - forward.clear(); - backward.clear(); - - const auto instrument = ws->getInstrument(); - auto loader = Kernel::make_unique<API::GroupingLoader>(instrument); - - if (instrument->getName() == "MUSR") { - // Two possibilities for grouping - use workspace log - auto fieldDir = ws->run().getLogData("main_field_direction"); - if (fieldDir) { - loader = Kernel::make_unique<API::GroupingLoader>(instrument, - fieldDir->value()); - } - if (!fieldDir) { - throw std::invalid_argument( - "Cannot use default instrument grouping for MUSR " - "as main field direction is unknown"); - } - } - - // Load grouping and find forward, backward groups - std::string fwdRange, bwdRange; - const auto grouping = loader->getGroupingFromIDF(); - size_t nGroups = grouping->groups.size(); - for (size_t iGroup = 0; iGroup < nGroups; iGroup++) { - const std::string name = grouping->groupNames[iGroup]; - if (name == "fwd") { - fwdRange = grouping->groups[iGroup]; - } else if (name == "bwd" || name == "bkwd") { - bwdRange = grouping->groups[iGroup]; - } - } - - // Use ArrayProperty's functionality to convert string ranges to groups - this->setProperty("ForwardSpectra", fwdRange); - this->setProperty("BackwardSpectra", bwdRange); - forward = getProperty("ForwardSpectra"); - backward = getProperty("BackwardSpectra"); -} - -/** - * Get start time for fit - * If not provided as input, try to read from workspace logs. - * If it's not there either, set to 0 and warn user. - * @return :: Start time for fit - */ -double CalMuonDetectorPhases::getStartTime() const { - double startTime = getProperty("FirstGoodData"); - if (startTime == EMPTY_DBL()) { - try { - // Read FirstGoodData from workspace logs if possible - double firstGoodData = - m_inputWS->run().getLogAsSingleValue("FirstGoodData"); - startTime = firstGoodData; - } catch (...) { - g_log.warning("Couldn't read FirstGoodData, setting to 0"); - startTime = 0.; - } - } - return startTime; -} - -/** - * Get end time for fit - * If it's not there, use the last available time in the workspace. - * @return :: End time for fit - */ -double CalMuonDetectorPhases::getEndTime() const { - double endTime = getProperty("LastGoodData"); - if (endTime == EMPTY_DBL()) { - // Last available time - endTime = m_inputWS->readX(0).back(); - } - return endTime; -} - -/** - * Calculate alpha (detector efficiency) from the given workspace - * If calculation fails, returns default 1.0 - * @param ws :: [input] Workspace to calculate alpha from - * @param forward :: [input] Forward group spectra numbers - * @param backward :: [input] Backward group spectra numbers - * @return :: Alpha, or 1.0 if calculation failed - */ -double CalMuonDetectorPhases::getAlpha(const API::MatrixWorkspace_sptr &ws, - const std::vector<int> &forward, - const std::vector<int> &backward) { - double alpha = 1.0; - try { - auto alphaAlg = createChildAlgorithm("AlphaCalc"); - alphaAlg->setProperty("InputWorkspace", ws); - alphaAlg->setProperty("ForwardSpectra", forward); - alphaAlg->setProperty("BackwardSpectra", backward); - alphaAlg->executeAsChildAlg(); - alpha = alphaAlg->getProperty("Alpha"); - } catch (const std::exception &e) { - // Eat the error and return default 1.0 so algorithm can continue. - // Warn the user that calculating alpha failed - std::ostringstream message; - message << "Calculating alpha failed, default to 1.0: " << e.what(); - g_log.error(message.str()); - } - return alpha; -} - -/** - * Calculate asymmetry for the given workspace - * @param ws :: [input] Workspace to calculate asymmetry from - * @param forward :: [input] Forward group spectra numbers - * @param backward :: [input] Backward group spectra numbers - * @param alpha :: [input] Detector efficiency - * @return :: Asymmetry for workspace - */ -API::MatrixWorkspace_sptr CalMuonDetectorPhases::getAsymmetry( - const API::MatrixWorkspace_sptr &ws, const std::vector<int> &forward, - const std::vector<int> &backward, const double alpha) { - auto alg = createChildAlgorithm("AsymmetryCalc"); - alg->setProperty("InputWorkspace", ws); - alg->setProperty("OutputWorkspace", "__NotUsed"); - alg->setProperty("ForwardSpectra", forward); - alg->setProperty("BackwardSpectra", backward); - alg->setProperty("Alpha", alpha); - alg->executeAsChildAlg(); - API::MatrixWorkspace_sptr wsAsym = alg->getProperty("OutputWorkspace"); - return wsAsym; -} - -/** - * Fit the asymmetry and return the frequency found. - * Starting value for the frequency is taken from the hint. - * If the fit fails, return the initial hint. - * @param wsAsym :: [input] Workspace with asymmetry to fit - * @return :: Frequency found from fit - */ -double CalMuonDetectorPhases::fitFrequencyFromAsymmetry( - const API::MatrixWorkspace_sptr &wsAsym) { - // Starting value for frequency is hint - double hint = getFrequencyHint(); - std::string funcStr = createFittingFunction(hint, false); - double frequency = hint; - - std::string fitStatus = "success"; - try { - auto func = API::FunctionFactory::Instance().createInitialized(funcStr); - auto fit = createChildAlgorithm("Fit"); - fit->setProperty("Function", func); - fit->setProperty("InputWorkspace", wsAsym); - fit->setProperty("WorkspaceIndex", 0); - fit->setProperty("CreateOutput", true); - fit->setProperty("OutputParametersOnly", true); - fit->setProperty("Output", "__Invisible"); - fit->executeAsChildAlg(); - fitStatus = fit->getPropertyValue("OutputStatus"); - if (fitStatus == "success") { - API::ITableWorkspace_sptr params = fit->getProperty("OutputParameters"); - const size_t rows = params->rowCount(); - static size_t colName(0), colValue(1); - for (size_t iRow = 0; iRow < rows; iRow++) { - if (params->cell<std::string>(iRow, colName) == "w") { - frequency = params->cell<double>(iRow, colValue); - break; - } - } - } - } catch (const std::exception &e) { - // Report fit failure to user - fitStatus = e.what(); - } - if (fitStatus != "success") { // Either failed, or threw an exception - std::ostringstream message; - message << "Fit failed (" << fitStatus << "), using omega hint = " << hint; - g_log.error(message.str()); - } - return frequency; -} - -/** - * Updates the algorithm progress - * @param thisSpectrum :: [input] Spectrum number currently being fitted - * @param totalSpectra :: [input] Total number of spectra to fit - */ -void CalMuonDetectorPhases::reportProgress(const int thisSpectrum, - const int totalSpectra) { - double proportionDone = (double)thisSpectrum / (double)totalSpectra; - std::ostringstream progMessage; - progMessage << "Fitting " << thisSpectrum + 1 << " of " << totalSpectra; - this->progress(proportionDone, progMessage.str()); -} - -} // namespace Algorithms -} // namespace Mantid diff --git a/Framework/Algorithms/src/CalculateMuonAsymmetry.cpp b/Framework/Algorithms/src/CalculateMuonAsymmetry.cpp deleted file mode 100644 index e7bc6faefa7f4468186f0000d976b4169c0c55ef..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/CalculateMuonAsymmetry.cpp +++ /dev/null @@ -1,291 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- - -#include "MantidAlgorithms/CalculateMuonAsymmetry.h" -#include "MantidAlgorithms/MuonAsymmetryHelper.h" - -#include "MantidAPI/ADSValidator.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FuncMinimizerFactory.h" -#include "MantidAPI/FunctionProperty.h" -#include "MantidAPI/IFuncMinimizer.h" -#include "MantidAPI/IFunction.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/MultiDomainFunction.h" -#include "MantidAPI/WorkspaceFactory.h" - -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/BoundedValidator.h" -#include "MantidKernel/ListValidator.h" -#include "MantidKernel/StartsWithValidator.h" - -#include <cmath> -#include <numeric> -#include <vector> - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; -using API::Progress; -using std::size_t; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(CalculateMuonAsymmetry) - -/** Initialisation method. Declares properties to be used in algorithm. -* -*/ -void CalculateMuonAsymmetry::init() { - // norm table to update - declareProperty( - make_unique<API::WorkspaceProperty<API::ITableWorkspace>>( - "NormalizationTable", "", Direction::Input), - "Name of the table containing the normalizations for the asymmetries."); - // list of uNonrm workspaces to fit to - declareProperty( - Kernel::make_unique<Kernel::ArrayProperty<std::string>>( - "UnNormalizedWorkspaceList", boost::make_shared<API::ADSValidator>()), - "An ordered list of workspaces (to get the initial values " - "for the normalizations)."); - // list of workspaces to output renormalized result to - declareProperty( - Kernel::make_unique<Kernel::ArrayProperty<std::string>>( - "ReNormalizedWorkspaceList", boost::make_shared<API::ADSValidator>()), - "An ordered list of workspaces (to get the initial values " - "for the normalizations)."); - - declareProperty("OutputFitWorkspace", "fit", - "The name of the output fit workspace."); - - declareProperty( - "StartX", 0.1, - "The lower limit for calculating the asymmetry (an X value)."); - declareProperty( - "EndX", 15.0, - "The upper limit for calculating the asymmetry (an X value)."); - declareProperty(make_unique<API::FunctionProperty>("InputFunction"), - "The fitting function to be converted."); - - std::vector<std::string> minimizerOptions = - API::FuncMinimizerFactory::Instance().getKeys(); - Kernel::IValidator_sptr minimizerValidator = - boost::make_shared<Kernel::StartsWithValidator>(minimizerOptions); - declareProperty("Minimizer", "Levenberg-MarquardtMD", minimizerValidator, - "Minimizer to use for fitting."); - auto mustBePositive = boost::make_shared<Kernel::BoundedValidator<int>>(); - mustBePositive->setLower(0); - declareProperty( - "MaxIterations", 500, mustBePositive->clone(), - "Stop after this number of iterations if a good fit is not found"); - declareProperty("OutputStatus", "", Kernel::Direction::Output); - declareProperty(make_unique<API::FunctionProperty>("OutputFunction", - Kernel::Direction::Output), - "The fitting function after fit."); -} -/* -* Validate the input parameters -* @returns map with keys corresponding to properties with errors and values -* containing the error messages. -*/ -std::map<std::string, std::string> CalculateMuonAsymmetry::validateInputs() { - // create the map - std::map<std::string, std::string> validationOutput; - // check start and end times - double startX = getProperty("StartX"); - double endX = getProperty("EndX"); - if (startX > endX) { - validationOutput["StartX"] = "Start time is after the end time."; - } else if (startX == endX) { - validationOutput["StartX"] = "Start and end times are equal, there is no " - "data to apply the algorithm to."; - } - // check inputs - std::vector<std::string> unnormWS = getProperty("UnNormalizedWorkspaceList"); - std::vector<std::string> normWS = getProperty("ReNormalizedWorkspaceList"); - if (normWS.size() != unnormWS.size()) { - validationOutput["ReNormalizedWorkspaceList"] = - "The ReNormalizedWorkspaceList and UnNormalizedWorkspaceList must " - "contain the same number of workspaces."; - } - API::IFunction_sptr tmp = getProperty("InputFunction"); - auto function = boost::dynamic_pointer_cast<API::CompositeFunction>(tmp); - if (function->getNumberDomains() != normWS.size()) { - validationOutput["InputFunction"] = "The Fitting function does not have " - "the same number of domains as the " - "number of domains to fit."; - } - - // check norm table is correct -> move this to helper when move muon algs to - // muon folder - API::ITableWorkspace_const_sptr tabWS = getProperty("NormalizationTable"); - - if (tabWS->columnCount() == 0) { - validationOutput["NormalizationTable"] = - "Please provide a non-empty NormalizationTable."; - } - // NormalizationTable should have three columns: (norm, name, method) - if (tabWS->columnCount() != 3) { - validationOutput["NormalizationTable"] = - "NormalizationTable must have three columns"; - } - auto names = tabWS->getColumnNames(); - int normCount = 0; - int wsNamesCount = 0; - for (const std::string &name : names) { - - if (name == "norm") { - normCount += 1; - } - - if (name == "name") { - wsNamesCount += 1; - } - } - if (normCount == 0) { - validationOutput["NormalizationTable"] = - "NormalizationTable needs norm column"; - } - if (wsNamesCount == 0) { - validationOutput["NormalizationTable"] = - "NormalizationTable needs a name column"; - } - if (normCount > 1) { - validationOutput["NormalizationTable"] = - "NormalizationTable has " + std::to_string(normCount) + " norm columns"; - } - if (wsNamesCount > 1) { - validationOutput["NormalizationTable"] = "NormalizationTable has " + - std::to_string(wsNamesCount) + - " name columns"; - } - - return validationOutput; -} -/** Executes the algorithm -* -*/ - -void CalculateMuonAsymmetry::exec() { - const std::vector<std::string> wsNamesUnNorm = - getProperty("UnNormalizedWorkspaceList"); - std::vector<std::string> wsNames = getProperty("reNormalizedWorkspaceList"); - - // get new norm - std::vector<double> norms = - getNormConstants(wsNamesUnNorm); // this will do the fit - // update the ws to new norm - for (size_t j = 0; j < wsNames.size(); j++) { - API::MatrixWorkspace_sptr ws = - API::AnalysisDataService::Instance().retrieveWS<API::MatrixWorkspace>( - wsNamesUnNorm[j]); - API::MatrixWorkspace_sptr normWS = - API::AnalysisDataService::Instance().retrieveWS<API::MatrixWorkspace>( - wsNames[j]); - - normWS->mutableY(0) = ws->y(0) / norms[j]; - normWS->mutableY(0) -= 1.0; - normWS->mutableE(0) = ws->e(0) / norms[j]; - } - // update table with new norm - std::vector<std::string> methods(wsNames.size(), "Calculated"); - API::ITableWorkspace_sptr table = getProperty("NormalizationTable"); - updateNormalizationTable(table, wsNames, norms, methods); -} - -/** - * Calculate normalization constant after the exponential decay has been removed - * to a linear fitting function - * @param wsNames :: names of workspaces to fit to - * @return normalization constants -*/ - -std::vector<double> CalculateMuonAsymmetry::getNormConstants( - const std::vector<std::string> wsNames) { - std::vector<double> norms; - - double startX = getProperty("StartX"); - double endX = getProperty("EndX"); - int maxIterations = getProperty("MaxIterations"); - auto minimizer = getProperty("Minimizer"); - API::IAlgorithm_sptr fit = API::AlgorithmManager::Instance().create("Fit"); - fit->initialize(); - - API::IFunction_sptr function = getProperty("InputFunction"); - - fit->setProperty("Function", function); - - fit->setProperty("MaxIterations", maxIterations); - - fit->setPropertyValue("Minimizer", minimizer); - - std::string output = getPropertyValue("OutputFitWorkspace"); - - fit->setProperty("Output", output); - - fit->setProperty("InputWorkspace", wsNames[0]); - fit->setProperty("StartX", startX); - fit->setProperty("EndX", endX); - fit->setProperty("WorkspaceIndex", 0); - - if (wsNames.size() > 1) { - for (size_t j = 1; j < wsNames.size(); j++) { - std::string suffix = boost::lexical_cast<std::string>(j); - - fit->setPropertyValue("InputWorkspace_" + suffix, wsNames[j]); - fit->setProperty("WorkspaceIndex_" + suffix, 0); - fit->setProperty("StartX_" + suffix, startX); - fit->setProperty("EndX_" + suffix, endX); - } - } - - fit->execute(); - auto status = fit->getPropertyValue("OutputStatus"); - setProperty("OutputStatus", status); - - API::IFunction_sptr tmp = fit->getProperty("Function"); - setProperty("OutputFunction", tmp); - try { - if (wsNames.size() == 1) { - // N(1+g) + exp - auto TFFunc = boost::dynamic_pointer_cast<API::CompositeFunction>(tmp); - norms.push_back(getNormValue(TFFunc)); - } else { - auto result = boost::dynamic_pointer_cast<API::MultiDomainFunction>(tmp); - for (size_t j = 0; j < wsNames.size(); j++) { - // get domain - auto TFFunc = boost::dynamic_pointer_cast<API::CompositeFunction>( - result->getFunction(j)); - // N(1+g) + exp - TFFunc = boost::dynamic_pointer_cast<API::CompositeFunction>(TFFunc); - norms.push_back(getNormValue(TFFunc)); - } - } - } catch (...) { - throw std::invalid_argument("The fitting function is not of the expected " - "form. Try using " - "ConvertFitFunctionForMuonTFAsymmetry"); - } - return norms; -} -/** -* Gets the normalization from a fitting function -* @param func :: fittef function -* @return normalization constant -*/ -double CalculateMuonAsymmetry::getNormValue(API::CompositeFunction_sptr &func) { - - // getFunction(0) -> N(1+g) - auto TFFunc = - boost::dynamic_pointer_cast<API::CompositeFunction>(func->getFunction(0)); - - auto fdas = TFFunc->asString(); - // getFunction(0) -> N - auto flat = TFFunc->getFunction(0); - - return flat->getParameter("A0"); -} -} // namespace Algorithm -} // namespace Mantid diff --git a/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp b/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp deleted file mode 100644 index 848c049647a115ed25c295364fc1f33f395fd560..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp +++ /dev/null @@ -1,216 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAlgorithms/EstimateMuonAsymmetryFromCounts.h" -#include "MantidAlgorithms/MuonAsymmetryHelper.h" - -#include "MantidAPI/IFunction.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/Run.h" -#include "MantidAPI/Workspace_fwd.h" -#include "MantidAPI/WorkspaceFactory.h" - -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/PhysicalConstants.h" - -#include <cmath> -#include <numeric> -#include <vector> - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; -using API::Progress; -using std::size_t; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(EstimateMuonAsymmetryFromCounts) - -/** Initialisation method. Declares properties to be used in algorithm. - * - */ -void EstimateMuonAsymmetryFromCounts::init() { - declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "InputWorkspace", "", Direction::Input), - "The name of the input 2D workspace."); - declareProperty("WorkspaceName", "", "The name used in the normalization " - "table. If this is blank the " - "InputWorkspace's name will be used."); - - declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "OutputWorkspace", "", Direction::Output), - "The name of the output 2D workspace."); - declareProperty( - "OutputUnNormData", false, - "If to output the data with just the exponential decay removed."); - - declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "OutputUnNormWorkspace", "unNormalisedData", - Direction::Output, API::PropertyMode::Optional), - "The name of the output unnormalized workspace."); - - std::vector<int> empty; - declareProperty( - Kernel::make_unique<Kernel::ArrayProperty<int>>("Spectra", empty), - "The workspace indices to remove the exponential decay from."); - declareProperty( - "StartX", 0.1, - "The lower limit for calculating the asymmetry (an X value)."); - declareProperty( - "EndX", 15.0, - "The upper limit for calculating the asymmetry (an X value)."); - declareProperty("NormalizationIn", 0.0, "If this value is non-zero then this " - "is used for the normalization, " - "instead of being estimated."); - - declareProperty( - make_unique<API::WorkspaceProperty<API::ITableWorkspace>>( - "NormalizationTable", "", Direction::InOut), - "Name of the table containing the normalizations for the asymmetries."); -} - -/* -* Validate the input parameters -* @returns map with keys corresponding to properties with errors and values -* containing the error messages. -*/ -std::map<std::string, std::string> -EstimateMuonAsymmetryFromCounts::validateInputs() { - // create the map - std::map<std::string, std::string> validationOutput; - // check start and end times - double startX = getProperty("StartX"); - double endX = getProperty("EndX"); - if (startX > endX) { - validationOutput["StartX"] = "Start time is after the end time."; - } else if (startX == endX) { - validationOutput["StartX"] = "Start and end times are equal, there is no " - "data to apply the algorithm to."; - } - double norm = getProperty("NormalizationIn"); - if (norm < 0.0) { - validationOutput["NormalizationIn"] = - "Normalization to use must be positive."; - } - return validationOutput; -} - -/** Executes the algorithm - * - */ -void EstimateMuonAsymmetryFromCounts::exec() { - std::vector<int> spectra = getProperty("Spectra"); - // Get original workspace - API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace"); - std::string wsName = getProperty("WorkspaceName"); - if (wsName == "") { - wsName = inputWS->getName(); - } - auto numSpectra = inputWS->getNumberHistograms(); - // Create output workspace with same dimensions as input - API::MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace"); - if (inputWS != outputWS) { - outputWS = API::WorkspaceFactory::Instance().create(inputWS); - } - bool extraData = getProperty("OutputUnNormData"); - API::MatrixWorkspace_sptr unnormWS = - API::WorkspaceFactory::Instance().create(outputWS); - double startX = getProperty("StartX"); - double endX = getProperty("EndX"); - const Mantid::API::Run &run = inputWS->run(); - double numGoodFrames = std::stod(run.getProperty("goodfrm")->value()); - if (numGoodFrames == 0) { - g_log.warning("The data has no good frames, assuming a value of 1"); - numGoodFrames = 1; - } - // Share the X values - for (size_t i = 0; i < static_cast<size_t>(numSpectra); ++i) { - outputWS->setSharedX(i, inputWS->sharedX(i)); - } - - // No spectra specified = process all spectra - if (spectra.empty()) { - spectra = std::vector<int>(numSpectra); - std::iota(spectra.begin(), spectra.end(), 0); - } - - Progress prog(this, 0.0, 1.0, numSpectra + spectra.size()); - if (inputWS != outputWS) { - - // Copy all the Y and E data - PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS)) - for (int64_t i = 0; i < int64_t(numSpectra); ++i) { - PARALLEL_START_INTERUPT_REGION - const auto index = static_cast<size_t>(i); - outputWS->setSharedY(index, inputWS->sharedY(index)); - outputWS->setSharedE(index, inputWS->sharedE(index)); - prog.report(); - PARALLEL_END_INTERUPT_REGION - } - PARALLEL_CHECK_INTERUPT_REGION - } - - // Do the specified spectra only - int specLength = static_cast<int>(spectra.size()); - std::vector<double> norm(specLength, 0.0); - - double normConst = getProperty("NormalizationIn"); - - std::string status = (normConst == 0) ? "Estimate" : "Fixed"; - std::vector<std::string> methods(specLength, status); - std::string name = (specLength > 1) ? wsName + "_spec_" : wsName; - std::vector<std::string> wsNames(specLength, name); - - PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS)) - for (int i = 0; i < specLength; ++i) { - PARALLEL_START_INTERUPT_REGION - const auto specNum = static_cast<size_t>(spectra[i]); - - if (spectra[i] > static_cast<int>(numSpectra)) { - g_log.error("The spectral index " + std::to_string(spectra[i]) + - " is greater than the number of spectra!"); - throw std::invalid_argument("The spectral index " + - std::to_string(spectra[i]) + - " is greater than the number of spectra!"); - } - // Calculate the normalised counts - if (normConst == 0.0) { - normConst = estimateNormalisationConst(inputWS->histogram(specNum), - numGoodFrames, startX, endX); - } - if (spectra.size() > 1) { - wsNames[i] += std::to_string(spectra[i]); - } - - // Calculate the asymmetry - outputWS->setHistogram( - specNum, normaliseCounts(inputWS->histogram(specNum), numGoodFrames)); - if (extraData) { - unnormWS->mutableX(specNum) = outputWS->x(specNum); - unnormWS->mutableY(specNum) = outputWS->y(specNum); - unnormWS->mutableE(specNum) = outputWS->e(specNum); - } - outputWS->mutableY(specNum) /= normConst; - outputWS->mutableY(specNum) -= 1.0; - outputWS->mutableE(specNum) /= normConst; - norm[i] = normConst; - prog.report(); - PARALLEL_END_INTERUPT_REGION - } - PARALLEL_CHECK_INTERUPT_REGION - if (extraData) { - unnormWS->setYUnit("Asymmetry"); - setProperty("OutputUnNormWorkspace", unnormWS); - } - // update table - Mantid::API::ITableWorkspace_sptr table = getProperty("NormalizationTable"); - updateNormalizationTable(table, wsNames, norm, methods); - setProperty("NormalizationTable", table); - // Update Y axis units - outputWS->setYUnit("Asymmetry"); - - setProperty("OutputWorkspace", outputWS); -} -} // namespace Algorithm -} // namespace Mantid diff --git a/Framework/Algorithms/src/MuonAsymmetryHelper.cpp b/Framework/Algorithms/src/MuonAsymmetryHelper.cpp deleted file mode 100644 index ef982ab5e2cf6e60b25116ed06029cd1b864ae5b..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/MuonAsymmetryHelper.cpp +++ /dev/null @@ -1,164 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAlgorithms/MuonAsymmetryHelper.h" -#include "MantidAPI/IFunction.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/Progress.h" -#include "MantidAPI/Run.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidAPI/Workspace_fwd.h" - -#include "MantidAPI/TableRow.h" -#include "MantidAPI/AnalysisDataService.h" - -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/PhysicalConstants.h" - -#include <algorithm> -#include <cmath> -#include <iterator> -#include <numeric> -#include <vector> - -namespace { -/// Number of microseconds in one second (10^6) -constexpr double MICROSECONDS_PER_SECOND{1000000.0}; -/// Muon lifetime in microseconds -constexpr double MUON_LIFETIME_MICROSECONDS{ - Mantid::PhysicalConstants::MuonLifetime * MICROSECONDS_PER_SECOND}; -} - -namespace Mantid { -using namespace Kernel; -using std::size_t; - -/** - * Corrects the data and errors for one spectrum. - * The muon lifetime is in microseconds, not seconds, because the data is in - * microseconds. - * @param histogram :: [input] Input histogram - * @param numGoodFrames :: [input] the number of good frames - * @returns :: Histogram of the normalised counts - */ -HistogramData::Histogram -normaliseCounts(const HistogramData::Histogram &histogram, - const double numGoodFrames) { - HistogramData::Histogram result(histogram); - auto &yData = result.mutableY(); - auto &eData = result.mutableE(); - for (size_t i = 0; i < yData.size(); ++i) { - const double factor = exp(result.x()[i] / MUON_LIFETIME_MICROSECONDS); - // Correct the Y data - if (yData[i] != 0.0) { - yData[i] *= factor / numGoodFrames; - } else { - yData[i] = 0.1 * factor / numGoodFrames; - } - - // Correct the E data - if (eData[i] != 0.0) { - eData[i] *= factor / numGoodFrames; - } else { - eData[i] = factor / numGoodFrames; - } - } - - return result; -} -/** -* Estimates normalisation constant via -* N_0 = (Delta/f)*(sum_i W_i)/(int_a^b exp(-t/tau)dt ) -* where W is the raw data, tau is the muon -* lifetime, t is time, f is the -* number of good frames Delta is the time step, -* a is the start of the range and b is the end of the range. -* @param histogram :: [input] Input histogram -* @param numGoodFrames :: [input] the number of good frames -* @param startX :: [input] the start time -* @param endX :: [input] the end time -* @returns :: The normalization constant N_0 -*/ -double estimateNormalisationConst(const HistogramData::Histogram &histogram, - const double numGoodFrames, - const double startX, const double endX) { - - auto &&xData = histogram.binEdges(); - auto &&yData = histogram.y(); - - size_t i0 = startIndexFromTime(xData, startX); - size_t iN = endIndexFromTime(xData, endX); - // remove an extra index as XData is bin boundaries and not point data - auto iy0 = std::next(yData.rawData().begin(), i0); - auto iyN = std::next(yData.rawData().begin(), iN); - double summation = std::accumulate(iy0, iyN, 0.0); - double denominator = 0.0; - /* this replaces (from doc): - delta_t/tau(exp(-t_N/tau) - exp(-t_0/tau)) - with trapezium rule (convert it to integral first): - 1/(sum_{j=0}{N} exp(-t_j/tau)) - 0.5*(exp(-t_0/tau)+exp(-t_N/tau)) - */ - for (size_t k = i0; k < iN; k++) { - denominator += exp(-xData[k] / MUON_LIFETIME_MICROSECONDS); - } - denominator -= 0.5 * (exp(-xData[i0] / MUON_LIFETIME_MICROSECONDS)); - denominator -= 0.5 * (exp(-xData[iN] / MUON_LIFETIME_MICROSECONDS)); - return summation / (denominator * numGoodFrames); -} -/** -* Finds the first index in bin edges that is after -* the start time. -* @param xData :: [input] Input HistogramData as bin edges -* @param startX :: [input] the start time -* @returns :: The index to start calculations from -*/ -size_t startIndexFromTime(const HistogramData::BinEdges &xData, - const double startX) { - auto upper = - std::lower_bound(xData.rawData().begin(), xData.rawData().end(), startX); - return std::distance(xData.rawData().begin(), upper + 1); -} -/** -* find the first index in bin edges that is after -* the end time. -* @param xData :: [input] HistogramData as bin edges -* @param endX :: [input] the end time -* @returns :: The last index to include in calculations -*/ -size_t endIndexFromTime(const HistogramData::BinEdges &xData, - const double endX) { - auto lower = - std::upper_bound(xData.rawData().begin(), xData.rawData().end(), endX); - return std::distance(xData.rawData().begin(), lower - 1); -} - -/***** - The following functions are for manipulating the normalisation table -******/ -void updateNormalizationTable(Mantid::API::ITableWorkspace_sptr &table, - const std::vector<std::string> &wsNames, - const std::vector<double> &norms, - const std::vector<std::string> &methods) { - - for (size_t j = 0; j < wsNames.size(); j++) { - bool updated = false; - std::string tmp = wsNames[j]; - std::replace(tmp.begin(), tmp.end(), ' ', ';'); - for (size_t row = 0; row < table->rowCount(); row++) { - - if (table->String(row, 1) == tmp) { - table->removeRow(row); - table->insertRow(row); - Mantid::API::TableRow tableRow = table->getRow(row); - tableRow << static_cast<double>(norms[j]) << tmp << methods[j]; - updated = true; - } - } - if (!updated) { - Mantid::API::TableRow tableRow = table->appendRow(); - tableRow << static_cast<double>(norms[j]) << tmp << methods[j]; - } - } -} - -} // namespace Mantid diff --git a/Framework/Algorithms/src/MuonGroupDetectors.cpp b/Framework/Algorithms/src/MuonGroupDetectors.cpp deleted file mode 100644 index dfa178286fe4784cb6ec5ccc593ff973fc7b695b..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/MuonGroupDetectors.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "MantidAlgorithms/MuonGroupDetectors.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataObjects/TableWorkspace.h" -#include "MantidHistogramData/HistogramMath.h" - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; -using namespace API; -using namespace DataObjects; -using namespace HistogramData; - -// Register the algorithm into the AlgorithmFactory -DECLARE_ALGORITHM(MuonGroupDetectors) - -//---------------------------------------------------------------------------------------------- -/// Algorithm's name for identification. @see Algorithm::name -const std::string MuonGroupDetectors::name() const { - return "MuonGroupDetectors"; -} - -/// Algorithm's version for identification. @see Algorithm::version -int MuonGroupDetectors::version() const { return 1; } - -/// Algorithm's category for identification. @see Algorithm::category -const std::string MuonGroupDetectors::category() const { return "Muon"; } - -//---------------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------------- -/** Initialize the algorithm's properties. - */ -void MuonGroupDetectors::init() { - declareProperty(make_unique<WorkspaceProperty<MatrixWorkspace>>( - "InputWorkspace", "", Direction::Input), - "Workspace to apply grouping to."); - - declareProperty(make_unique<WorkspaceProperty<TableWorkspace>>( - "DetectorGroupingTable", "", Direction::Input), - "Table with detector grouping information. Check wiki page " - "for table format expected."); - - declareProperty(make_unique<WorkspaceProperty<MatrixWorkspace>>( - "OutputWorkspace", "", Direction::Output), - "Workspace with detectors grouped."); -} - -//---------------------------------------------------------------------------------------------- -/** Execute the algorithm. - */ -void MuonGroupDetectors::exec() { - TableWorkspace_sptr table = getProperty("DetectorGroupingTable"); - - // Check that table does have expected format - if (table->columnCount() != 1) - throw std::invalid_argument("Grouping table should have one column only"); - - if (table->getColumn(0)->type() != "vector_int") - throw std::invalid_argument("Column should be of integer vector type"); - - std::vector<size_t> nonEmptyRows; // Rows with non-empty groups - nonEmptyRows.reserve(table->rowCount()); // Most of rows will be non-empty - - // First pass to determine how many non-empty groups we have - for (size_t row = 0; row < table->rowCount(); ++row) { - if (!table->cell<std::vector<int>>(row, 0).empty()) - nonEmptyRows.push_back(row); - } - - if (nonEmptyRows.empty()) - throw std::invalid_argument( - "Detector Grouping Table doesn't contain any non-empty groups"); - - MatrixWorkspace_sptr inWS = getProperty("InputWorkspace"); - - // Create output workspace with all the same parameters as an input one except - // number of histograms - MatrixWorkspace_sptr outWS = - WorkspaceFactory::Instance().create(inWS, nonEmptyRows.size()); - - // Compile the groups - for (auto rowIt = nonEmptyRows.begin(); rowIt != nonEmptyRows.end(); - ++rowIt) { - // Group index in the output workspace - size_t groupIndex = - static_cast<size_t>(std::distance(nonEmptyRows.begin(), rowIt)); - - std::vector<int> &detectorIDs = table->cell<std::vector<int>>(*rowIt, 0); - - // Recieve detector IDs, but need workspace indices to group, so convert - std::vector<size_t> wsIndices = - inWS->getIndicesFromDetectorIDs(detectorIDs); - - if (wsIndices.size() != detectorIDs.size()) - throw std::invalid_argument("Some of the detector IDs were not found"); - - // We will be setting them anew - outWS->getSpectrum(groupIndex).clearDetectorIDs(); - - // Using the first detector X values - outWS->setSharedX(groupIndex, inWS->sharedX(wsIndices.front())); - - auto hist = outWS->histogram(groupIndex); - for (auto &wsIndex : wsIndices) { - hist += inWS->histogram(wsIndex); - // Detectors list of the group should contain all the detectors of - // it's - // elements - outWS->getSpectrum(groupIndex) - .addDetectorIDs(inWS->getSpectrum(wsIndex).getDetectorIDs()); - } - - outWS->setHistogram(groupIndex, hist); - - outWS->getSpectrum(groupIndex) - .setSpectrumNo(static_cast<specnum_t>(groupIndex + 1)); - } - - setProperty("OutputWorkspace", outWS); -} - -} // namespace Algorithms -} // namespace Mantid diff --git a/Framework/Algorithms/src/PhaseQuadMuon.cpp b/Framework/Algorithms/src/PhaseQuadMuon.cpp deleted file mode 100644 index 0afe09b696b256444f3fbe879635fc03691062db..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/PhaseQuadMuon.cpp +++ /dev/null @@ -1,341 +0,0 @@ -#include "MantidAlgorithms/PhaseQuadMuon.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/Axis.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidAPI/MatrixWorkspaceValidator.h" -#include "MantidKernel/PhysicalConstants.h" -#include "MantidKernel/Unit.h" - -namespace { -const std::array<std::string, 2> phaseNames = {{"phase", "phi"}}; -const std::array<std::string, 3> asymmNames = {{"asymmetry", "asymm", "asym"}}; - -template <typename T1, typename T2> -int findName(const T1 &patterns, const T2 &names) { - for (const std::string &pattern : patterns) { - auto it = std::find_if(names.begin(), names.end(), - [pattern](const std::string &s) { - if (s == pattern) { - return true; - } else { - return false; - } - }); - if (it != names.end()) { - return static_cast<int>(std::distance(names.begin(), it)); - } - } - return -1; -} -double ASYMM_ERROR = 999.0; -} - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(PhaseQuadMuon) - -/** Initialisation method. Declares properties to be used in algorithm. - * - */ -void PhaseQuadMuon::init() { - declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "InputWorkspace", "", Direction::Input), - "Name of the input workspace containing the spectra"); - - declareProperty( - make_unique<API::WorkspaceProperty<API::ITableWorkspace>>( - "PhaseTable", "", Direction::Input), - "Name of the table containing the detector phases and asymmetries"); - - declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "OutputWorkspace", "", Direction::Output), - "Name of the output workspace"); -} - -/** Executes the algorithm - * - */ -void PhaseQuadMuon::exec() { - - // Get the input workspace - API::MatrixWorkspace_sptr inputWs = getProperty("InputWorkspace"); - - // Get the input phase table - // Should have two columns (detector, phase) - API::ITableWorkspace_sptr phaseTable = getProperty("PhaseTable"); - - // Get N0, the normalization constant: N(t) = N0 * exp(-x/tau) - // for each spectrum/detector - std::vector<double> n0 = getExponentialDecay(inputWs); - - // Compute squashograms - API::MatrixWorkspace_sptr ows = squash(inputWs, phaseTable, n0); - - setProperty("OutputWorkspace", ows); -} - -//------------------------------------------------------------------------------------------------ -/** Checks that the input workspace and table have compatible dimensions - * @return a map where: Key = string name of the the property; Value = string - * describing the problem with the property. -*/ -std::map<std::string, std::string> PhaseQuadMuon::validateInputs() { - - std::map<std::string, std::string> result; - - // Check that input ws and table ws have compatible dimensions - API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace"); - API::ITableWorkspace_const_sptr tabWS = getProperty("PhaseTable"); - if (!inputWS) { - result["InputWorkspace"] = "InputWorkspace is of Incorrect type. Please " - "provide a MatrixWorkspace as the " - "InputWorkspace"; - return result; - } - size_t nspec = inputWS->getNumberHistograms(); - size_t ndet = tabWS->rowCount(); - - if (tabWS->columnCount() == 0) { - result["PhaseTable"] = "Please provide a non-empty PhaseTable."; - } - - if (nspec != ndet) { - result["PhaseTable"] = "PhaseTable must have one row per spectrum"; - } - - // PhaseTable should have three columns: (detector, asymmetry, phase) - if (tabWS->columnCount() != 3) { - result["PhaseTable"] = "PhaseTable must have three columns"; - } - auto names = tabWS->getColumnNames(); - for (auto &name : names) { - std::transform(name.begin(), name.end(), name.begin(), ::tolower); - } - int phaseCount = 0; - int asymmetryCount = 0; - for (const std::string &name : names) { - for (const std::string &goodName : phaseNames) { - if (name == goodName) { - phaseCount += 1; - } - } - for (const std::string &goodName : asymmNames) { - if (name == goodName) { - asymmetryCount += 1; - } - } - } - if (phaseCount == 0) { - result["PhaseTable"] = "PhaseTable needs phases column"; - } - if (asymmetryCount == 0) { - result["PhaseTable"] = "PhaseTable needs a asymmetry/asymm/asym column"; - } - if (phaseCount > 1) { - result["PhaseTable"] = - "PhaseTable has " + std::to_string(phaseCount) + " phase columns"; - } - if (asymmetryCount > 1) { - result["PhaseTable"] = "PhaseTable has " + std::to_string(asymmetryCount) + - " asymmetry/asymm/asym columns"; - } - // Check units, should be microseconds - Unit_const_sptr unit = inputWS->getAxis(0)->unit(); - if ((unit->caption() != "Time") || (unit->label().ascii() != "microsecond")) { - result["InputWorkspace"] = "InputWorkspace units must be microseconds"; - } - - return result; -} - -//---------------------------------------------------------------------------------------------- -/** Calculates the normalization constant for the exponential decay -* @param ws :: [input] Workspace containing the spectra to remove exponential -* from -* @return :: Vector containing the normalization constants, N0, for each -* spectrum -*/ -std::vector<double> -PhaseQuadMuon::getExponentialDecay(const API::MatrixWorkspace_sptr &ws) { - - const size_t nspec = ws->getNumberHistograms(); - - // Muon life time in microseconds - constexpr double muLife = PhysicalConstants::MuonLifetime * 1e6; - - std::vector<double> n0(nspec, 0.); - - for (size_t h = 0; h < ws->getNumberHistograms(); h++) { - - const auto &X = ws->getSpectrum(h).x(); - const auto &Y = ws->getSpectrum(h).y(); - const auto &E = ws->getSpectrum(h).e(); - - double s, sx, sy; - s = sx = sy = 0.; - for (size_t i = 0; i < Y.size(); i++) { - - if (Y[i] > 0) { - double sig = E[i] * E[i] / Y[i] / Y[i]; - s += 1. / sig; - sx += (X[i] - X[0]) / sig; - sy += log(Y[i]) / sig; - } - } - n0[h] = exp((sy + sx / muLife) / s); - } - - return n0; -} - -//---------------------------------------------------------------------------------------------- -/** Forms the quadrature phase signal (squashogram) -* @param ws :: [input] workspace containing the measured spectra -* @param phase :: [input] table workspace containing the detector phases -* @param n0 :: [input] vector containing the normalization constants -* @return :: workspace containing the quadrature phase signal -*/ -API::MatrixWorkspace_sptr -PhaseQuadMuon::squash(const API::MatrixWorkspace_sptr &ws, - const API::ITableWorkspace_sptr &phase, - const std::vector<double> &n0) { - - // Poisson limit: below this number we consider we don't have enough - // statistics - // to apply sqrt(N). This is an arbitrary number used in the original code - // provided by scientists - const double poissonLimit = 30.; - - // Muon life time in microseconds - const double muLife = PhysicalConstants::MuonLifetime * 1e6; - - const size_t nspec = ws->getNumberHistograms(); - - if (n0.size() != nspec) { - throw std::invalid_argument("Invalid normalization constants"); - } - - auto names = phase->getColumnNames(); - for (auto &name : names) { - std::transform(name.begin(), name.end(), name.begin(), ::tolower); - } - auto phaseIndex = findName(phaseNames, names); - auto asymmetryIndex = findName(asymmNames, names); - - // Get the maximum asymmetry - double maxAsym = 0.; - for (size_t h = 0; h < nspec; h++) { - if (phase->Double(h, asymmetryIndex) > maxAsym && - phase->Double(h, asymmetryIndex) != ASYMM_ERROR) { - maxAsym = phase->Double(h, asymmetryIndex); - } - } - - if (maxAsym == 0.0) { - throw std::invalid_argument("Invalid detector asymmetries"); - } - std::vector<bool> emptySpectrum; - emptySpectrum.reserve(nspec); - std::vector<double> aj, bj; - { - // Calculate coefficients aj, bj - - double sxx = 0.; - double syy = 0.; - double sxy = 0.; - for (size_t h = 0; h < nspec; h++) { - emptySpectrum.push_back( - std::all_of(ws->y(h).begin(), ws->y(h).end(), - [](double value) { return value == 0.; })); - if (!emptySpectrum[h]) { - const double asym = phase->Double(h, asymmetryIndex) / maxAsym; - const double phi = phase->Double(h, phaseIndex); - const double X = n0[h] * asym * cos(phi); - const double Y = n0[h] * asym * sin(phi); - sxx += X * X; - syy += Y * Y; - sxy += X * Y; - } - } - - const double lam1 = 2 * syy / (sxx * syy - sxy * sxy); - const double mu1 = 2 * sxy / (sxy * sxy - sxx * syy); - const double lam2 = 2 * sxy / (sxy * sxy - sxx * syy); - const double mu2 = 2 * sxx / (sxx * syy - sxy * sxy); - for (size_t h = 0; h < nspec; h++) { - if (emptySpectrum[h]) { - aj.push_back(0.0); - bj.push_back(0.0); - } else { - const double asym = phase->Double(h, asymmetryIndex) / maxAsym; - const double phi = phase->Double(h, phaseIndex); - const double X = n0[h] * asym * cos(phi); - const double Y = n0[h] * asym * sin(phi); - aj.push_back((lam1 * X + mu1 * Y) * 0.5); - bj.push_back((lam2 * X + mu2 * Y) * 0.5); - } - } - } - - const size_t npoints = ws->blocksize(); - // Create and populate output workspace - API::MatrixWorkspace_sptr ows = - API::WorkspaceFactory::Instance().create(ws, 2, npoints + 1, npoints); - - // X - ows->setSharedX(0, ws->sharedX(0)); - ows->setSharedX(1, ws->sharedX(0)); - - // Phase quadrature - auto &realY = ows->mutableY(0); - auto &imagY = ows->mutableY(1); - auto &realE = ows->mutableE(0); - auto &imagE = ows->mutableE(1); - - const auto xPointData = ws->histogram(0).points(); - // First X value - const double X0 = xPointData.front(); - - // calculate exponential decay outside of the loop - std::vector<double> expDecay = xPointData.rawData(); - std::transform(expDecay.begin(), expDecay.end(), expDecay.begin(), - [X0, muLife](double x) { return exp(-(x - X0) / muLife); }); - - for (size_t i = 0; i < npoints; i++) { - for (size_t h = 0; h < nspec; h++) { - if (!emptySpectrum[h]) { - // (X,Y,E) with exponential decay removed - const double X = ws->x(h)[i]; - const double exponential = n0[h] * exp(-(X - X0) / muLife); - const double Y = ws->y(h)[i] - exponential; - const double E = - (ws->y(h)[i] > poissonLimit) ? ws->e(h)[i] : sqrt(exponential); - - realY[i] += aj[h] * Y; - imagY[i] += bj[h] * Y; - realE[i] += aj[h] * aj[h] * E * E; - imagE[i] += bj[h] * bj[h] * E * E; - } - } - realE[i] = sqrt(realE[i]); - imagE[i] = sqrt(imagE[i]); - - // Regain exponential decay - realY[i] /= expDecay[i]; - imagY[i] /= expDecay[i]; - realE[i] /= expDecay[i]; - imagE[i] /= expDecay[i]; - } - - // New Y axis label - ows->setYUnit("Asymmetry"); - - return ows; -} -} -} diff --git a/Framework/Algorithms/src/PlotAsymmetryByLogValue.cpp b/Framework/Algorithms/src/PlotAsymmetryByLogValue.cpp deleted file mode 100644 index 6d00f31e2971aa45b7bf52c7e7423a4ee4a8e58a..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/PlotAsymmetryByLogValue.cpp +++ /dev/null @@ -1,874 +0,0 @@ -#include <cmath> -#include <vector> - -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/FileProperty.h" -#include "MantidAPI/Progress.h" -#include "MantidAPI/Run.h" -#include "MantidAPI/ScopedWorkspace.h" -#include "MantidAPI/TableRow.h" -#include "MantidAPI/TextAxis.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidAlgorithms/PlotAsymmetryByLogValue.h" -#include "MantidDataObjects/TableWorkspace.h" -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/ListValidator.h" -#include "MantidKernel/MandatoryValidator.h" -#include "MantidKernel/PropertyWithValue.h" -#include "MantidKernel/TimeSeriesProperty.h" -#include "Poco/File.h" -#include <MantidAPI/FileFinder.h> -#include "MantidAPI/WorkspaceGroup.h" - -namespace // anonymous - { - -/** - * Convert a log property to a double value. - * - * @param property :: Pointer to a TimeSeriesProperty. - * @param value :: Returned double value. - * @return :: True if successful - */ -template <typename T> -bool convertLogToDouble(const Mantid::Kernel::Property *property, double &value, - const std::string &function) { - const Mantid::Kernel::TimeSeriesProperty<T> *log = - dynamic_cast<const Mantid::Kernel::TimeSeriesProperty<T> *>(property); - if (log) { - if (function == "Mean") { - value = static_cast<double>(log->timeAverageValue()); - } else if (function == "First") { - value = static_cast<double>(log->firstValue()); - } else if (function == "Min") { - value = static_cast<double>(log->minValue()); - } else if (function == "Max") { - value = static_cast<double>(log->maxValue()); - } else { // Default - value = static_cast<double>(log->lastValue()); - } - return true; - } - auto tlog = - dynamic_cast<const Mantid::Kernel::PropertyWithValue<T> *>(property); - if (tlog) { - value = static_cast<double>(*tlog); - return true; - } - return false; -} - -} // anonymous - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; -using namespace API; -using namespace DataObjects; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(PlotAsymmetryByLogValue) - -PlotAsymmetryByLogValue::PlotAsymmetryByLogValue() - : Algorithm(), m_filenameBase(), m_filenameExt(), m_filenameZeros(), - m_dtcType(), m_dtcFile(), m_forward_list(), m_backward_list(), - m_int(true), m_red(-1), m_green(-1), m_minTime(-1.0), m_maxTime(-1.0), - m_logName(), m_logFunc(), m_logValue(), m_redY(), m_redE(), m_greenY(), - m_greenE(), m_sumY(), m_sumE(), m_diffY(), m_diffE(), - m_allProperties("default"), m_currResName("__PABLV_results"), - m_firstStart_ns(0) {} - -/** Initialisation method. Declares properties to be used in algorithm. -* -*/ -void PlotAsymmetryByLogValue::init() { - std::string nexusExt(".nxs"); - - declareProperty(Kernel::make_unique<FileProperty>( - "FirstRun", "", FileProperty::Load, nexusExt), - "The name of the first workspace in the series."); - declareProperty(Kernel::make_unique<FileProperty>( - "LastRun", "", FileProperty::Load, nexusExt), - "The name of the last workspace in the series."); - declareProperty( - make_unique<WorkspaceProperty<>>("OutputWorkspace", "", - Direction::Output), - "The name of the output workspace containing the resulting asymmetries."); - declareProperty("LogValue", "", - boost::make_shared<MandatoryValidator<std::string>>(), - "The name of the log values which will be used as the x-axis " - "in the output workspace."); - - std::vector<std::string> optionsLog{"Mean", "Min", "Max", "First", "Last"}; - declareProperty( - "Function", "Last", boost::make_shared<StringListValidator>(optionsLog), - "The function to apply: 'Mean', 'Min', 'Max', 'First' or 'Last'."); - - declareProperty("Red", 1, "The period number for the 'red' data."); - declareProperty("Green", EMPTY_INT(), - "The period number for the 'green' data."); - - std::vector<std::string> options{"Integral", "Differential"}; - declareProperty("Type", "Integral", - boost::make_shared<StringListValidator>(options), - "The calculation type: 'Integral' or 'Differential'."); - declareProperty( - "TimeMin", EMPTY_DBL(), - "The beginning of the time interval used in the calculations."); - declareProperty("TimeMax", EMPTY_DBL(), - "The end of the time interval used in the calculations."); - - declareProperty(make_unique<ArrayProperty<int>>("ForwardSpectra"), - "The list of spectra for the forward group. If not specified " - "the following happens. The data will be grouped according " - "to grouping information in the data, if available. The " - "forward will use the first of these groups."); - declareProperty(make_unique<ArrayProperty<int>>("BackwardSpectra"), - "The list of spectra for the backward group. If not " - "specified the following happens. The data will be grouped " - "according to grouping information in the data, if " - "available. The backward will use the second of these " - "groups."); - - std::vector<std::string> deadTimeCorrTypes{"None", "FromRunData", - "FromSpecifiedFile"}; - - declareProperty("DeadTimeCorrType", deadTimeCorrTypes[0], - boost::make_shared<StringListValidator>(deadTimeCorrTypes), - "Type of Dead Time Correction to apply."); - - declareProperty(Kernel::make_unique<FileProperty>("DeadTimeCorrFile", "", - FileProperty::OptionalLoad, - nexusExt), - "Custom file with Dead Times. Will be used only if " - "appropriate DeadTimeCorrType is set."); -} - -/** -* Executes the algorithm -*/ -void PlotAsymmetryByLogValue::exec() { - - // Check input properties to decide whether or not we can reuse previous - // results, if any - size_t is, ie; - checkProperties(is, ie); - - Progress progress(this, 0, 1, ie - is + 1); - - // Loop through runs - for (size_t i = is; i <= ie; i++) { - - // Check if run i was already loaded - std::ostringstream logMessage; - if (m_logValue.count(i)) { - logMessage << "Found run " << i; - } else { - // Load run, apply dead time corrections and detector grouping - Workspace_sptr loadedWs = doLoad(i); - - if (loadedWs) { - // Analyse loadedWs - doAnalysis(loadedWs, i); - } - logMessage << "Loaded run " << i; - } - progress.report(logMessage.str()); - } - - // Create the 2D workspace for the output - int nplots = !m_greenY.empty() ? 4 : 1; - size_t npoints = m_logValue.size(); - MatrixWorkspace_sptr outWS = WorkspaceFactory::Instance().create( - "Workspace2D", - nplots, // the number of plots - npoints, // the number of data points on a plot - npoints // it's not a histogram - ); - // Populate output workspace with data - populateOutputWorkspace(outWS, nplots); - // Assign the result to the output workspace property - setProperty("OutputWorkspace", outWS); - - outWS = WorkspaceFactory::Instance().create("Workspace2D", nplots + 1, - npoints, npoints); - // Populate ws holding current results - saveResultsToADS(outWS, nplots + 1); -} - -/** Checks input properties and compares them to previous values -* @param is :: [output] Number of the first run -* @param ie :: [output] Number of the last run -*/ -void PlotAsymmetryByLogValue::checkProperties(size_t &is, size_t &ie) { - - // Log Value - m_logName = getPropertyValue("LogValue"); - // Get function to apply to logValue - m_logFunc = getPropertyValue("Function"); - // Get type of computation - m_int = (getPropertyValue("Type") == "Integral"); - // Get grouping properties - m_forward_list = getProperty("ForwardSpectra"); - m_backward_list = getProperty("BackwardSpectra"); - // Get green and red periods - m_red = getProperty("Red"); - m_green = getProperty("Green"); - // Get time min and time max - m_minTime = getProperty("TimeMin"); - m_maxTime = getProperty("TimeMax"); - // Get type of dead-time corrections - m_dtcType = getPropertyValue("DeadTimeCorrType"); - m_dtcFile = getPropertyValue("DeadTimeCorrFile"); - // Get runs - std::string firstFN = getProperty("FirstRun"); - std::string lastFN = getProperty("LastRun"); - - // Parse run names and get the number of runs - parseRunNames(firstFN, lastFN, m_filenameBase, m_filenameExt, - m_filenameZeros); - is = std::stoul(firstFN); // starting run number - ie = std::stoul(lastFN); // last run number - if (ie < is) { - throw std::runtime_error( - "First run number is greater than last run number"); - } - - // Create a string holding all the properties - std::ostringstream ss; - ss << m_filenameBase << "," << m_filenameExt << "," << m_filenameZeros << ","; - ss << m_dtcType << "," << m_dtcFile << ","; - ss << getPropertyValue("ForwardSpectra") << "," - << getPropertyValue("BackwardSpectra") << ","; - ss << m_int << "," << m_minTime << "," << m_maxTime << ","; - ss << m_red << "," << m_green << ","; - ss << m_logName << ", " << m_logFunc; - m_allProperties = ss.str(); - - // Check if we can re-use results from previous run - // We can reuse results if: - // 1. There is a ws in the ADS with name m_currResName - // 2. It is a MatrixWorkspace - // 3. It has a title equatl to m_allProperties - // This ws stores previous results as described below - if (AnalysisDataService::Instance().doesExist(m_currResName)) { - MatrixWorkspace_sptr prevResults = - AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( - m_currResName); - if (prevResults) { - if (m_allProperties == prevResults->getTitle()) { - // We can re-use results - size_t nPoints = prevResults->blocksize(); - size_t nHisto = prevResults->getNumberHistograms(); - - if (nHisto == 2) { - // Only 'red' data - for (size_t i = 0; i < nPoints; i++) { - // The first spectrum contains: X -> run number, Y -> log value - // The second spectrum contains: Y -> redY, E -> redE - size_t run = static_cast<size_t>(prevResults->x(0)[i]); - if ((run >= is) && (run <= ie)) { - m_logValue[run] = prevResults->y(0)[i]; - m_redY[run] = prevResults->y(1)[i]; - m_redE[run] = prevResults->e(1)[i]; - } - } - } else { - // 'Red' and 'Green' data - for (size_t i = 0; i < nPoints; i++) { - // The first spectrum contains: X -> run number, Y -> log value - // The second spectrum contains: Y -> diffY, E -> diffE - // The third spectrum contains: Y -> redY, E -> redE - // The fourth spectrum contains: Y -> greenY, E -> greeE - // The fifth spectrum contains: Y -> sumY, E -> sumE - size_t run = static_cast<size_t>(prevResults->x(0)[i]); - if ((run >= is) && (run <= ie)) { - m_logValue[run] = prevResults->y(0)[i]; - m_diffY[run] = prevResults->y(1)[i]; - m_diffE[run] = prevResults->e(1)[i]; - m_redY[run] = prevResults->y(2)[i]; - m_redE[run] = prevResults->e(2)[i]; - m_greenY[run] = prevResults->y(3)[i]; - m_greenE[run] = prevResults->e(3)[i]; - m_sumY[run] = prevResults->y(4)[i]; - m_sumE[run] = prevResults->e(4)[i]; - } - } - } - } - } - } -} - -/** Loads one run and applies dead-time corrections and detector grouping if -* required -* @param runNumber :: [input] Run number specifying run to load -* @return :: Loaded workspace -*/ -Workspace_sptr PlotAsymmetryByLogValue::doLoad(size_t runNumber) { - - // Get complete run name - std::ostringstream fn, fnn; - fnn << std::setw(m_filenameZeros) << std::setfill('0') << runNumber; - fn << m_filenameBase << fnn.str() << m_filenameExt; - - // Check if file exists - if (!Poco::File(fn.str()).exists()) { - m_log.warning() << "File " << fn.str() << " not found\n"; - return Workspace_sptr(); - } - - // Load run - IAlgorithm_sptr load = createChildAlgorithm("LoadMuonNexus"); - load->setPropertyValue("Filename", fn.str()); - load->setPropertyValue("DetectorGroupingTable", "detGroupTable"); - load->setPropertyValue("DeadTimeTable", "deadTimeTable"); - load->execute(); - Workspace_sptr loadedWs = load->getProperty("OutputWorkspace"); - - // Check if dead-time corrections have to be applied - if (m_dtcType != "None") { - - Workspace_sptr deadTimes; - - if (m_dtcType == "FromSpecifiedFile") { - // Load corrections from file - deadTimes = loadCorrectionsFromFile(m_dtcFile); - } else { - // Load corrections from run - deadTimes = load->getProperty("DeadTimeTable"); - } - if (!deadTimes) { - throw std::runtime_error("Couldn't load dead times"); - } - applyDeadtimeCorr(loadedWs, deadTimes); - } - - // Group detectors - Workspace_sptr grouping; - if (m_forward_list.empty() && m_backward_list.empty()) { - // Auto group - grouping = load->getProperty("DetectorGroupingTable"); - } else { - // Custom grouping - grouping = createCustomGrouping(m_forward_list, m_backward_list); - } - if (!grouping) - throw std::runtime_error("Couldn't load detector grouping"); - - // Apply grouping - groupDetectors(loadedWs, grouping); - - return loadedWs; -} - -/** Load dead-time corrections from specified file -* @param deadTimeFile :: [input] File to read corrections from -* @return :: Deadtime corrections loaded from file -*/ -Workspace_sptr PlotAsymmetryByLogValue::loadCorrectionsFromFile( - const std::string &deadTimeFile) { - - IAlgorithm_sptr alg = createChildAlgorithm("LoadNexusProcessed"); - alg->setPropertyValue("Filename", deadTimeFile); - alg->setLogging(false); - alg->execute(); - Workspace_sptr deadTimes = alg->getProperty("OutputWorkspace"); - return deadTimes; -} - -/** Populate output workspace with results -* @param outWS :: [input/output] Output workspace to populate -* @param nplots :: [input] Number of histograms -*/ -void PlotAsymmetryByLogValue::populateOutputWorkspace( - MatrixWorkspace_sptr &outWS, int nplots) { - - auto tAxis = new TextAxis(nplots); - if (nplots == 1) { - size_t i = 0; - for (auto &value : m_logValue) { - outWS->mutableX(0)[i] = value.second; - outWS->mutableY(0)[i] = m_redY[value.first]; - outWS->mutableE(0)[i] = m_redE[value.first]; - i++; - } - tAxis->setLabel(0, "Asymmetry"); - - } else { - size_t i = 0; - for (auto &value : m_logValue) { - outWS->mutableX(0)[i] = value.second; - outWS->mutableY(0)[i] = m_diffY[value.first]; - outWS->mutableE(0)[i] = m_diffE[value.first]; - outWS->mutableX(1)[i] = value.second; - outWS->mutableY(1)[i] = m_redY[value.first]; - outWS->mutableE(1)[i] = m_redE[value.first]; - outWS->mutableX(2)[i] = value.second; - outWS->mutableY(2)[i] = m_greenY[value.first]; - outWS->mutableE(2)[i] = m_greenE[value.first]; - outWS->mutableX(3)[i] = value.second; - outWS->mutableY(3)[i] = m_sumY[value.first]; - outWS->mutableE(3)[i] = m_sumE[value.first]; - i++; - } - tAxis->setLabel(0, "Red-Green"); - tAxis->setLabel(1, "Red"); - tAxis->setLabel(2, "Green"); - tAxis->setLabel(3, "Red+Green"); - } - outWS->replaceAxis(1, tAxis); - outWS->getAxis(0)->title() = m_logName; - outWS->setYUnitLabel("Asymmetry"); -} - -/** Populate output workspace with results -* @param outWS :: [input/output] Output workspace to populate -* @param nplots :: [input] Number of histograms -*/ -void PlotAsymmetryByLogValue::saveResultsToADS(MatrixWorkspace_sptr &outWS, - int nplots) { - - if (nplots == 2) { - size_t i = 0; - for (auto &value : m_logValue) { - size_t run = value.first; - outWS->mutableX(0)[i] = static_cast<double>(run); // run number - outWS->mutableY(0)[i] = value.second; // log value - outWS->mutableY(1)[i] = m_redY[run]; // redY - outWS->mutableE(1)[i] = m_redE[run]; // redE - i++; - } - } else { - size_t i = 0; - for (auto &value : m_logValue) { - size_t run = value.first; - outWS->mutableX(0)[i] = static_cast<double>(run); // run number - outWS->mutableY(0)[i] = value.second; // log value - outWS->mutableY(1)[i] = m_diffY[run]; // diffY - outWS->mutableE(1)[i] = m_diffE[run]; // diffE - outWS->mutableY(2)[i] = m_redY[run]; // redY - outWS->mutableE(2)[i] = m_redE[run]; // redE - outWS->mutableY(3)[i] = m_greenY[run]; // greenY - outWS->mutableE(3)[i] = m_greenE[run]; // greenE - outWS->mutableY(4)[i] = m_sumY[run]; // sumY - outWS->mutableE(4)[i] = m_sumE[run]; // sumE - i++; - } - } - // Set the title! - outWS->setTitle(m_allProperties); - - // Save results to ADS - // We can't set an output property to store the results as this algorithm - // is executed as a child algorithm in the Muon ALC interface - // If current results were saved as a property we couln't used - // the functionality to re-use previous results in ALC - AnalysisDataService::Instance().addOrReplace(m_currResName, outWS); -} - -/** Parse run names -* @param firstFN :: [input/output] First run's name -* @param lastFN :: [input/output] Last run's name -* @param fnBase :: [output] Runs base name -* @param fnExt :: [output] Runs extension -* @param fnZeros :: [output] Number of zeros in run's name -*/ -void PlotAsymmetryByLogValue::parseRunNames(std::string &firstFN, - std::string &lastFN, - std::string &fnBase, - std::string &fnExt, int &fnZeros) { - - // Parse first run's name - std::string firstExt = firstFN.substr(firstFN.find_last_of('.')); - firstFN.erase(firstFN.size() - 4); - - std::string firstBase = firstFN; - size_t i = firstBase.size() - 1; - while (isdigit(firstBase[i])) - i--; - if (i == firstBase.size() - 1) { - throw Exception::FileError("File name must end with a number.", firstFN); - } - firstBase.erase(i + 1); - firstFN.erase(0, firstBase.size()); - - // Parse last run's name - std::string lastExt = lastFN.substr(lastFN.find_last_of('.')); - lastFN.erase(lastFN.size() - 4); - - std::string lastBase = lastFN; - i = lastBase.size() - 1; - while (isdigit(lastBase[i])) - i--; - if (i == lastBase.size() - 1) { - throw Exception::FileError("File name must end with a number.", lastFN); - } - lastBase.erase(i + 1); - lastFN.erase(0, lastBase.size()); - - // Compare first and last - if (firstBase != lastBase) { - // Runs are not in the same directory - - // First run number with last base name - std::ostringstream tempFirst; - tempFirst << lastBase << firstFN << firstExt << '\n'; - std::string pathFirst = FileFinder::Instance().getFullPath(tempFirst.str()); - // Last run number with first base name - std::ostringstream tempLast; - tempLast << firstBase << lastFN << lastExt << '\n'; - std::string pathLast = FileFinder::Instance().getFullPath(tempLast.str()); - - // Try to correct this on the fly by - // checking if the last run can be found in the first directory... - if (Poco::File(pathLast).exists()) { - fnBase = firstBase; - fnExt = firstExt; - g_log.warning() - << "First and last run are not in the same directory. File " - << pathLast << " will be used instead.\n"; - } else if (Poco::File(pathFirst).exists()) { - // ...or viceversa - fnBase = lastBase; - fnExt = lastExt; - g_log.warning() - << "First and last run are not in the same directory. File " - << pathFirst << " will be used instead.\n"; - } else { - throw std::runtime_error( - "First and last runs are not in the same directory."); - } - - } else { - - fnBase = firstBase; - fnExt = firstExt; - } - fnZeros = static_cast<int>(firstFN.size()); -} - -/** Apply dead-time corrections. The calculation is done by ApplyDeadTimeCorr -* algorithm -* @param loadedWs :: [input/output] Workspace to apply corrections to -* @param deadTimes :: [input] Corrections to apply -*/ -void PlotAsymmetryByLogValue::applyDeadtimeCorr(Workspace_sptr &loadedWs, - Workspace_sptr deadTimes) { - ScopedWorkspace ws(loadedWs); - ScopedWorkspace dt(deadTimes); - - IAlgorithm_sptr applyCorr = - AlgorithmManager::Instance().create("ApplyDeadTimeCorr"); - applyCorr->setLogging(false); - applyCorr->setRethrows(true); - applyCorr->setPropertyValue("InputWorkspace", ws.name()); - applyCorr->setPropertyValue("OutputWorkspace", ws.name()); - applyCorr->setProperty("DeadTimeTable", dt.name()); - applyCorr->execute(); - // Workspace should've been replaced in the ADS by ApplyDeadTimeCorr, so - // need to - // re-assign it - loadedWs = ws.retrieve(); -} - -/** Creates grouping table from supplied forward and backward spectra -* @param fwd :: [Input] Forward spectra -* @param bwd :: [Input] Backward spectra -* @return :: Workspace containing custom grouping -*/ -Workspace_sptr -PlotAsymmetryByLogValue::createCustomGrouping(const std::vector<int> &fwd, - const std::vector<int> &bwd) { - - ITableWorkspace_sptr group = - WorkspaceFactory::Instance().createTable("TableWorkspace"); - group->addColumn("vector_int", "group"); - TableRow row = group->appendRow(); - row << fwd; - row = group->appendRow(); - row << bwd; - - return boost::dynamic_pointer_cast<Workspace>(group); -} - -/** Group detectors from table -* @param loadedWs :: [input/output] Workspace to apply grouping to -* @param grouping :: [input] Workspace containing grouping to apply -*/ -void PlotAsymmetryByLogValue::groupDetectors(Workspace_sptr &loadedWs, - Workspace_sptr grouping) { - - // Could be groups of workspaces, so need to work with ADS - ScopedWorkspace inWS(loadedWs); - ScopedWorkspace grWS(grouping); - ScopedWorkspace outWS; - - IAlgorithm_sptr alg = - AlgorithmManager::Instance().create("MuonGroupDetectors"); - alg->setLogging(false); - alg->setPropertyValue("InputWorkspace", inWS.name()); - alg->setPropertyValue("DetectorGroupingTable", grWS.name()); - alg->setPropertyValue("OutputWorkspace", outWS.name()); - alg->execute(); - loadedWs = outWS.retrieve(); -} - -/** Performs asymmetry analysis on a loaded workspace -* @param loadedWs :: [input] Workspace to apply analysis to -* @param index :: [input] Vector index where results will be stored -*/ -void PlotAsymmetryByLogValue::doAnalysis(Workspace_sptr loadedWs, - size_t index) { - - // Check if workspace is a workspace group - WorkspaceGroup_sptr group = - boost::dynamic_pointer_cast<WorkspaceGroup>(loadedWs); - - // If it is not, we only have 'red' data - if (!group) { - MatrixWorkspace_sptr ws_red = - boost::dynamic_pointer_cast<MatrixWorkspace>(loadedWs); - - double Y, E; - calcIntAsymmetry(ws_red, Y, E); - m_logValue[index] = getLogValue(*ws_red); - m_redY[index] = Y; - m_redE[index] = E; - - } else { - // It is a group - - // Process red data - MatrixWorkspace_sptr ws_red; - try { - ws_red = boost::dynamic_pointer_cast<MatrixWorkspace>( - group->getItem(m_red - 1)); - } catch (std::out_of_range &) { - throw std::out_of_range("Red period out of range"); - } - double YR, ER; - calcIntAsymmetry(ws_red, YR, ER); - double logValue = getLogValue(*ws_red); - m_logValue[index] = logValue; - m_redY[index] = YR; - m_redE[index] = ER; - - if (m_green != EMPTY_INT()) { - // Process green period if supplied by user - MatrixWorkspace_sptr ws_green; - try { - ws_green = boost::dynamic_pointer_cast<MatrixWorkspace>( - group->getItem(m_green - 1)); - } catch (std::out_of_range &) { - throw std::out_of_range("Green period out of range"); - } - double YG, EG; - calcIntAsymmetry(ws_green, YG, EG); - // Red data - m_redY[index] = YR; - m_redE[index] = ER; - // Green data - m_greenY[index] = YG; - m_greenE[index] = EG; - // Sum - m_sumY[index] = YR + YG; - m_sumE[index] = sqrt(ER * ER + EG * EG); - // Diff - calcIntAsymmetry(ws_red, ws_green, YR, ER); - m_diffY[index] = YR; - m_diffE[index] = ER; - } - } // else loadedGroup -} - -/** Calculate the integral asymmetry for a workspace. -* The calculation is done by AsymmetryCalc and Integration algorithms. -* @param ws :: The workspace -* @param Y :: Reference to a variable receiving the value of asymmetry -* @param E :: Reference to a variable receiving the value of the error -*/ -void PlotAsymmetryByLogValue::calcIntAsymmetry(MatrixWorkspace_sptr ws, - double &Y, double &E) { - - // Output workspace - MatrixWorkspace_sptr out; - - if (!m_int) { // "Differential asymmetry" - IAlgorithm_sptr asym = createChildAlgorithm("AsymmetryCalc"); - asym->setLogging(false); - asym->setProperty("InputWorkspace", ws); - asym->execute(); - MatrixWorkspace_sptr asymWS = asym->getProperty("OutputWorkspace"); - - IAlgorithm_sptr integr = createChildAlgorithm("Integration"); - integr->setLogging(false); - integr->setProperty("InputWorkspace", asymWS); - integr->setProperty("RangeLower", m_minTime); - integr->setProperty("RangeUpper", m_maxTime); - integr->execute(); - out = integr->getProperty("OutputWorkspace"); - - } else { - // "Integral asymmetry" - IAlgorithm_sptr integr = createChildAlgorithm("Integration"); - integr->setLogging(false); - integr->setProperty("InputWorkspace", ws); - integr->setProperty("RangeLower", m_minTime); - integr->setProperty("RangeUpper", m_maxTime); - integr->execute(); - MatrixWorkspace_sptr intWS = integr->getProperty("OutputWorkspace"); - - IAlgorithm_sptr asym = createChildAlgorithm("AsymmetryCalc"); - asym->setLogging(false); - asym->setProperty("InputWorkspace", intWS); - asym->execute(); - out = asym->getProperty("OutputWorkspace"); - } - - Y = out->y(0)[0]; - E = out->e(0)[0]; -} - -/** Calculate the integral asymmetry for a pair of workspaces (red & green). -* @param ws_red :: The red workspace -* @param ws_green :: The green workspace -* @param Y :: Reference to a variable receiving the value of asymmetry -* @param E :: Reference to a variable receiving the value of the error -*/ -void PlotAsymmetryByLogValue::calcIntAsymmetry(MatrixWorkspace_sptr ws_red, - MatrixWorkspace_sptr ws_green, - double &Y, double &E) { - if (!m_int) { // "Differential asymmetry" - - MatrixWorkspace_sptr tmpWS = WorkspaceFactory::Instance().create( - ws_red, 1, ws_red->x(0).size(), ws_red->y(0).size()); - - for (size_t i = 0; i < tmpWS->y(0).size(); i++) { - double FNORM = ws_green->y(0)[i] + ws_red->y(0)[i]; - FNORM = FNORM != 0.0 ? 1.0 / FNORM : 1.0; - double BNORM = ws_green->y(1)[i] + ws_red->y(1)[i]; - BNORM = BNORM != 0.0 ? 1.0 / BNORM : 1.0; - double ZF = (ws_green->y(0)[i] - ws_red->y(0)[i]) * FNORM; - double ZB = (ws_green->y(1)[i] - ws_red->y(1)[i]) * BNORM; - tmpWS->mutableY(0)[i] = ZB - ZF; - tmpWS->mutableE(0)[i] = (1.0 + ZF * ZF) * FNORM + (1.0 + ZB * ZB) * BNORM; - } - - IAlgorithm_sptr integr = createChildAlgorithm("Integration"); - integr->setProperty("InputWorkspace", tmpWS); - integr->setProperty("RangeLower", m_minTime); - integr->setProperty("RangeUpper", m_maxTime); - integr->execute(); - MatrixWorkspace_sptr out = integr->getProperty("OutputWorkspace"); - - Y = out->y(0)[0] / static_cast<double>(tmpWS->y(0).size()); - E = out->e(0)[0] / static_cast<double>(tmpWS->y(0).size()); - } else { - // "Integral asymmetry" - IAlgorithm_sptr integr = createChildAlgorithm("Integration"); - integr->setProperty("InputWorkspace", ws_red); - integr->setProperty("RangeLower", m_minTime); - integr->setProperty("RangeUpper", m_maxTime); - integr->execute(); - MatrixWorkspace_sptr intWS_red = integr->getProperty("OutputWorkspace"); - - integr = createChildAlgorithm("Integration"); - integr->setProperty("InputWorkspace", ws_green); - integr->setProperty("RangeLower", m_minTime); - integr->setProperty("RangeUpper", m_maxTime); - integr->execute(); - MatrixWorkspace_sptr intWS_green = integr->getProperty("OutputWorkspace"); - - double YIF = (intWS_green->y(0)[0] - intWS_red->y(0)[0]) / - (intWS_green->y(0)[0] + intWS_red->y(0)[0]); - double YIB = (intWS_green->y(1)[0] - intWS_red->y(1)[0]) / - (intWS_green->y(1)[0] + intWS_red->y(1)[0]); - - Y = YIB - YIF; - - double VARIF = - (1.0 + YIF * YIF) / (intWS_green->y(0)[0] + intWS_red->y(0)[0]); - double VARIB = - (1.0 + YIB * YIB) / (intWS_green->y(1)[0] + intWS_red->y(1)[0]); - - E = sqrt(VARIF + VARIB); - } -} - -/** - * Get log value from a workspace. Convert to double if possible. - * - * @param ws :: [Input] The input workspace. - * @return :: Log value. - * @throw :: std::invalid_argument if the log cannot be converted to a double or - *doesn't exist. - */ -double PlotAsymmetryByLogValue::getLogValue(MatrixWorkspace &ws) { - - const Run &run = ws.run(); - - // Get the start & end time for the run - Mantid::Types::Core::DateAndTime start, end; - if (run.hasProperty("run_start") && run.hasProperty("run_end")) { - start = run.getProperty("run_start")->value(); - end = run.getProperty("run_end")->value(); - } - - // If this is the first run, cache the start time - if (m_firstStart_ns == 0) { - m_firstStart_ns = start.totalNanoseconds(); - } - - // If the log asked for is the start or end time, we already have these. - // Return it as a double in seconds, relative to start of first run - constexpr static double nanosec_to_sec = 1.e-9; - if (m_logName == "run_start") { - return static_cast<double>(start.totalNanoseconds() - m_firstStart_ns) * - nanosec_to_sec; - } else if (m_logName == "run_end") { - return static_cast<double>(end.totalNanoseconds() - m_firstStart_ns) * - nanosec_to_sec; - } - - // Otherwise, try converting the log value to a double - auto *property = run.getLogData(m_logName); - if (!property) { - throw std::invalid_argument("Log " + m_logName + " does not exist."); - } - property->filterByTime(start, end); - - double value = 0; - // try different property types - if (convertLogToDouble<double>(property, value, m_logFunc)) - return value; - if (convertLogToDouble<float>(property, value, m_logFunc)) - return value; - if (convertLogToDouble<int32_t>(property, value, m_logFunc)) - return value; - if (convertLogToDouble<int64_t>(property, value, m_logFunc)) - return value; - if (convertLogToDouble<uint32_t>(property, value, m_logFunc)) - return value; - if (convertLogToDouble<uint64_t>(property, value, m_logFunc)) - return value; - // try if it's a string and can be lexically cast to double - auto slog = - dynamic_cast<const Mantid::Kernel::PropertyWithValue<std::string> *>( - property); - if (slog) { - try { - value = boost::lexical_cast<double>(slog->value()); - return value; - } catch (std::exception &) { - // do nothing, goto throw - } - } - - throw std::invalid_argument("Log " + m_logName + - " cannot be converted to a double type."); -} - -} // namespace Algorithm -} // namespace Mantid diff --git a/Framework/Algorithms/src/RRFMuon.cpp b/Framework/Algorithms/src/RRFMuon.cpp deleted file mode 100644 index 4771ec10aa27962c5d4cdd9c17d67a4daaa27a03..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/RRFMuon.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "MantidAlgorithms/RRFMuon.h" -#include "MantidAPI/Axis.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidKernel/Unit.h" - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(RRFMuon) - -/** Initialisation method. Declares properties to be used in algorithm. - * - */ -void RRFMuon::init() { - - declareProperty( - make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "InputWorkspace", "", Direction::Input), - "Name of the input workspace containing the spectra in the lab frame"); - - declareProperty( - make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "OutputWorkspace", "", Direction::Output), - "Name of the output workspace containing the spectra in the RRF"); - - declareProperty( - make_unique<PropertyWithValue<double>>("Frequency", 0, Direction::Input), - "Frequency of the oscillations"); - - std::vector<std::string> unitOptions{"MHz", "Gauss", "Mrad/s"}; - declareProperty("FrequencyUnits", "MHz", - boost::make_shared<StringListValidator>(unitOptions), - "The frequency units"); - - declareProperty( - make_unique<PropertyWithValue<double>>("Phase", 0, Direction::Input), - "Phase accounting for any misalignment of the counters"); -} - -/** Executes the algorithm - * - */ -void RRFMuon::exec() { - // Get input workspace containing polarization in the lab-frame - API::MatrixWorkspace_sptr inputWs = getProperty("InputWorkspace"); - // Get frequency - double freq = getProperty("Frequency"); - // Get units - std::string units = getProperty("FrequencyUnits"); - // Convert frequency to input workspace X units - double factor = - unitConversionFactor(inputWs->getAxis(0)->unit()->label().ascii(), units); - // Get phase - double phase = getProperty("Phase"); - // Get number of histograms - const size_t nHisto = inputWs->getNumberHistograms(); - if (nHisto != 2) { - throw std::runtime_error("Invalid number of spectra in input workspace"); - } - // Set number of data points - const size_t nData = inputWs->blocksize(); - - // Compute the RRF polarization - const double twoPiFreq = 2. * M_PI * freq * factor; - const auto &time = inputWs->x(0); // X axis: time - const auto &labRe = inputWs->y(0); // Lab-frame polarization (real part) - const auto &labIm = inputWs->y(1); // Lab-frame polarization (imaginary part) - - MantidVec rrfRe(nData), - rrfIm(nData); // Rotating Reference frame (RRF) polarizations - for (size_t t = 0; t < nData; t++) { - rrfRe[t] = labRe[t] * cos(twoPiFreq * time[t] + phase) + - labIm[t] * sin(twoPiFreq * time[t] + phase); - rrfIm[t] = -labRe[t] * sin(twoPiFreq * time[t] + phase) + - labIm[t] * cos(twoPiFreq * time[t] + phase); - } - - // Create output workspace to put results into - API::MatrixWorkspace_sptr outputWs = - boost::dynamic_pointer_cast<API::MatrixWorkspace>( - API::WorkspaceFactory::Instance().create("Workspace2D", nHisto, - nData + 1, nData)); - outputWs->getAxis(0)->unit() = inputWs->getAxis(0)->unit(); - - // Put results into output workspace - // Real RRF polarization - outputWs->setSharedX(0, inputWs->sharedX(0)); - outputWs->mutableY(0) = rrfRe; - // Imaginary RRF polarization - outputWs->setSharedX(1, inputWs->sharedX(1)); - outputWs->mutableY(1) = rrfIm; - - // Set output workspace - setProperty("OutputWorkspace", outputWs); -} - -/** Gets factor to convert frequency units to input workspace units, typically - * in microseconds - * @param uin :: [input] input workspace units - * @param uuser :: [input] units selected by user - */ -double RRFMuon::unitConversionFactor(std::string uin, std::string uuser) { - - if ((uin == "microsecond")) { - - if (uuser == "MHz") { - return 1.0; - } else if (uuser == "Gauss") { - // Factor = 2 * PI * MU - // where MU is the muon gyromagnetic ratio: - // MU = 135.538817 MHz/T, 1T = 10000 Gauss - return 2.0 * M_PI * 135.538817 * 0.0001; - } else if (uuser == "Mrad/s") { - // Factor = 2 * PI - return 2.0 * M_PI; - } else { - throw std::runtime_error("Could not find units"); - } - - } else { - throw std::runtime_error("X units must be in microseconds"); - } -} -} -} diff --git a/Framework/Algorithms/src/RemoveExpDecay.cpp b/Framework/Algorithms/src/RemoveExpDecay.cpp deleted file mode 100644 index 3dda4c625d9db6cd29e14ed29baaa54918f99bb6..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/src/RemoveExpDecay.cpp +++ /dev/null @@ -1,230 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAlgorithms/RemoveExpDecay.h" -#include "MantidAPI/IFunction.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/Workspace_fwd.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidKernel/PhysicalConstants.h" -#include "MantidKernel/ArrayProperty.h" - -#include <cmath> -#include <numeric> -#include <vector> - -namespace { -/// Number of microseconds in one second (10^6) -constexpr double MICROSECONDS_PER_SECOND{1000000.0}; -/// Muon lifetime in microseconds -constexpr double MUON_LIFETIME_MICROSECONDS{ - Mantid::PhysicalConstants::MuonLifetime * MICROSECONDS_PER_SECOND}; -} - -namespace Mantid { -namespace Algorithms { - -using namespace Kernel; -using API::Progress; -using std::size_t; - -// Register the class into the algorithm factory -DECLARE_ALGORITHM(MuonRemoveExpDecay) - -/** Initialisation method. Declares properties to be used in algorithm. - * - */ -void MuonRemoveExpDecay::init() { - declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "InputWorkspace", "", Direction::Input), - "The name of the input 2D workspace."); - declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( - "OutputWorkspace", "", Direction::Output), - "The name of the output 2D workspace."); - std::vector<int> empty; - declareProperty( - Kernel::make_unique<Kernel::ArrayProperty<int>>("Spectra", empty), - "The workspace indices to remove the exponential decay from."); -} - -/** Executes the algorithm - * - */ -void MuonRemoveExpDecay::exec() { - std::vector<int> spectra = getProperty("Spectra"); - - // Get original workspace - API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace"); - int numSpectra = static_cast<int>(inputWS->size() / inputWS->blocksize()); - // Create output workspace with same dimensions as input - API::MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace"); - if (inputWS != outputWS) { - outputWS = API::WorkspaceFactory::Instance().create(inputWS); - } - // Share the X values - for (size_t i = 0; i < static_cast<size_t>(numSpectra); ++i) { - outputWS->setSharedX(i, inputWS->sharedX(i)); - } - - // No spectra specified = process all spectra - if (spectra.empty()) { - std::vector<int> allSpectra(numSpectra); - std::iota(allSpectra.begin(), allSpectra.end(), 0); - spectra.swap(allSpectra); - } - - Progress prog(this, 0.0, 1.0, numSpectra + spectra.size()); - if (inputWS != outputWS) { - - // Copy all the Y and E data - PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS)) - for (int64_t i = 0; i < int64_t(numSpectra); ++i) { - PARALLEL_START_INTERUPT_REGION - const auto index = static_cast<size_t>(i); - outputWS->setSharedY(index, inputWS->sharedY(index)); - outputWS->setSharedE(index, inputWS->sharedE(index)); - prog.report(); - PARALLEL_END_INTERUPT_REGION - } - PARALLEL_CHECK_INTERUPT_REGION - } - - // Do the specified spectra only - int specLength = static_cast<int>(spectra.size()); - PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS)) - for (int i = 0; i < specLength; ++i) { - PARALLEL_START_INTERUPT_REGION - const auto specNum = static_cast<size_t>(spectra[i]); - if (spectra[i] > numSpectra) { - g_log.error("Spectra size greater than the number of spectra!"); - throw std::invalid_argument( - "Spectra size greater than the number of spectra!"); - } - auto emptySpectrum = - std::all_of(inputWS->y(specNum).begin(), inputWS->y(specNum).end(), - [](double value) { return value == 0.; }); - if (emptySpectrum) { - // if the y values are all zero do not change them - m_log.warning("Dead detector found at spectrum number " + - std::to_string(specNum)); - outputWS->setHistogram(specNum, inputWS->histogram(specNum)); - } else { - // Remove decay from Y and E - outputWS->setHistogram(specNum, removeDecay(inputWS->histogram(specNum))); - - // do scaling and subtract 1 - const double normConst = calNormalisationConst(outputWS, spectra[i]); - outputWS->mutableY(specNum) /= normConst; - outputWS->mutableY(specNum) -= 1.0; - outputWS->mutableE(specNum) /= normConst; - } - - prog.report(); - PARALLEL_END_INTERUPT_REGION - } - PARALLEL_CHECK_INTERUPT_REGION - - // Update Y axis units - outputWS->setYUnit("Asymmetry"); - - setProperty("OutputWorkspace", outputWS); -} - -/** - * Corrects the data and errors for one spectrum. - * The muon lifetime is in microseconds, not seconds, because the data is in - * microseconds. - * @param histogram :: [input] Input histogram - * @returns :: Histogram with exponential removed from Y and E - */ -HistogramData::Histogram MuonRemoveExpDecay::removeDecay( - const HistogramData::Histogram &histogram) const { - HistogramData::Histogram result(histogram); - - auto &yData = result.mutableY(); - auto &eData = result.mutableE(); - for (size_t i = 0; i < yData.size(); ++i) { - const double factor = exp(result.x()[i] / MUON_LIFETIME_MICROSECONDS); - // Correct the Y data - if (yData[i] != 0.0) { - yData[i] *= factor; - } else { - yData[i] = 0.1 * factor; - } - - // Correct the E data - if (eData[i] != 0.0) { - eData[i] *= factor; - } else { - eData[i] = factor; - } - } - - return result; -} - -/** - * calculate normalisation constant after the exponential decay has been removed - * to a linear fitting function - * @param ws :: workspace - * @param wsIndex :: workspace index - * @return normalisation constant -*/ -double MuonRemoveExpDecay::calNormalisationConst(API::MatrixWorkspace_sptr ws, - int wsIndex) { - double retVal = 1.0; - - API::IAlgorithm_sptr fit; - fit = createChildAlgorithm("Fit", -1, -1, true); - - std::stringstream ss; - ss << "name=LinearBackground,A0=" << ws->y(wsIndex)[0] << ",A1=" << 0.0 - << ",ties=(A1=0.0)"; - std::string function = ss.str(); - - fit->setPropertyValue("Function", function); - fit->setProperty("InputWorkspace", ws); - fit->setProperty("WorkspaceIndex", wsIndex); - fit->setPropertyValue("Minimizer", "Levenberg-MarquardtMD"); - fit->setProperty("Ties", "A1=0.0"); - fit->execute(); - - std::string fitStatus = fit->getProperty("OutputStatus"); - API::IFunction_sptr result = fit->getProperty("Function"); - std::vector<std::string> paramnames = result->getParameterNames(); - - // Check order of names - if (paramnames[0] != "A0") { - g_log.error() << "Parameter 0 should be A0, but is " << paramnames[0] - << '\n'; - throw std::invalid_argument( - "Parameters are out of order @ 0, should be A0"); - } - if (paramnames[1] != "A1") { - g_log.error() << "Parameter 1 should be A1, but is " << paramnames[1] - << '\n'; - throw std::invalid_argument( - "Parameters are out of order @ 0, should be A1"); - } - - if (fitStatus == "success") { - const double A0 = result->getParameter(0); - - if (A0 < 0) { - g_log.warning() << "When trying to fit Asymmetry normalisation constant " - "this constant comes out negative." - << "To proceed Asym norm constant set to 1.0\n"; - } else { - retVal = A0; - } - } else { - g_log.warning() << "Fit falled. Status = " << fitStatus - << "\nFor workspace index " << wsIndex - << "\nAsym norm constant set to 1.0\n"; - } - - return retVal; -} - -} // namespace Algorithm -} // namespace Mantid diff --git a/Framework/Algorithms/test/AlphaCalcTest.h b/Framework/Algorithms/test/AlphaCalcTest.h deleted file mode 100644 index a3dbab79dbaba79a2d60ddd79f5b3e15c927b0d0..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/AlphaCalcTest.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef MUONALPHACALCTEST_H_ -#define MUONALPHACALCTEST_H_ - -#include <cxxtest/TestSuite.h> - -#include "MantidDataHandling/LoadMuonNexus2.h" -#include "MantidDataHandling/LoadInstrument.h" -#include "MantidDataHandling/GroupDetectors.h" -#include "MantidAPI/IAlgorithm.h" -#include "MantidAlgorithms/AlphaCalc.h" -#include "MantidAPI/Workspace.h" -#include "MantidDataObjects/Workspace2D.h" -#include "MantidAPI/AnalysisDataService.h" -#include <stdexcept> - -using namespace Mantid::Algorithms; -using namespace Mantid::API; - -class AlphaCalcTest : public CxxTest::TestSuite { -public: - void testName() { TS_ASSERT_EQUALS(alphaCalc.name(), "AlphaCalc") } - - void testCategory() { TS_ASSERT_EQUALS(alphaCalc.category(), "Muon") } - - void testInit() { - alphaCalc.initialize(); - TS_ASSERT(alphaCalc.isInitialized()) - } - - void testCalAlphaManySpectra() { - // system("pause"); - // Load the muon nexus file - loader.initialize(); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "EMU6473"); - TS_ASSERT_THROWS_NOTHING(loader.execute()); - TS_ASSERT_EQUALS(loader.isExecuted(), true); - - alphaCalc.setPropertyValue("InputWorkspace", "EMU6473"); - alphaCalc.setPropertyValue("ForwardSpectra", - "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16"); - alphaCalc.setPropertyValue( - "BackwardSpectra", "17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32"); - alphaCalc.setPropertyValue("FirstGoodValue", "0.3"); - - try { - TS_ASSERT_EQUALS(alphaCalc.execute(), true); - } catch (std::runtime_error &e) { - TS_FAIL(e.what()); - } - double alpha = alphaCalc.getProperty("Alpha"); - TS_ASSERT_DELTA(alpha, 1.7875, 0.0001); - } - - void testCalAlphaTwoSpectra() { - // Load the muon nexus file - loader.initialize(); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "EMU6473"); - TS_ASSERT_THROWS_NOTHING(loader.execute()); - TS_ASSERT_EQUALS(loader.isExecuted(), true); - - alphaCalc.setPropertyValue("InputWorkspace", "EMU6473"); - alphaCalc.setPropertyValue("ForwardSpectra", "1"); - alphaCalc.setPropertyValue("BackwardSpectra", "17"); - alphaCalc.setPropertyValue("FirstGoodValue", "0.3"); - - try { - TS_ASSERT_EQUALS(alphaCalc.execute(), true); - } catch (std::runtime_error &e) { - TS_FAIL(e.what()); - } - double alpha = alphaCalc.getProperty("Alpha"); - TS_ASSERT_DELTA(alpha, 1.6880, 0.0001); - } - -private: - AlphaCalc alphaCalc; - Mantid::DataHandling::LoadMuonNexus2 loader; -}; - -#endif /*MUONALPHACALCTEST_H_*/ diff --git a/Framework/Algorithms/test/ApplyDeadTimeCorrTest.h b/Framework/Algorithms/test/ApplyDeadTimeCorrTest.h deleted file mode 100644 index 18b2d5c4a25a18b8d720a5afb06f1b096e4bb63b..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/ApplyDeadTimeCorrTest.h +++ /dev/null @@ -1,261 +0,0 @@ -#ifndef MANTID_ALGORITHMS_APPLYDEADTIMECORRTEST_H_ -#define MANTID_ALGORITHMS_APPLYDEADTIMECORRTEST_H_ - -#include <cxxtest/TestSuite.h> - -#include "MantidAPI/FrameworkManager.h" -#include "MantidAPI/IAlgorithm.h" -#include "MantidAPI/TableRow.h" -#include "MantidAPI/Workspace.h" -#include "MantidAlgorithms/ApplyDeadTimeCorr.h" -#include "MantidDataHandling/LoadMuonNexus2.h" -#include "MantidDataObjects/TableWorkspace.h" -#include "MantidDataObjects/Workspace2D.h" -#include "MantidTestHelpers/WorkspaceCreationHelper.h" - -#include <stdexcept> - -using namespace Mantid::Algorithms; -using namespace Mantid::API; - -class ApplyDeadTimeCorrTest : public CxxTest::TestSuite { -public: - void testName() { - ApplyDeadTimeCorr applyDeadTime; - TS_ASSERT_EQUALS(applyDeadTime.name(), "ApplyDeadTimeCorr") - } - - void testCategory() { - ApplyDeadTimeCorr applyDeadTime; - TS_ASSERT_EQUALS(applyDeadTime.category(), - "Muon;CorrectionFunctions\\EfficiencyCorrections") - } - - void testInit() { - ApplyDeadTimeCorr applyDeadTime; - applyDeadTime.initialize(); - TS_ASSERT(applyDeadTime.isInitialized()) - } - - void testExec() { - MatrixWorkspace_sptr inputWs = loadDataFromFile(); - auto deadTimes = makeDeadTimeTable(32); - - ApplyDeadTimeCorr applyDeadTime; - applyDeadTime.initialize(); - applyDeadTime.setChild(true); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("InputWorkspace", inputWs)); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("DeadTimeTable", deadTimes)); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("OutputWorkspace", "__NotUsed")); - TS_ASSERT_THROWS_NOTHING(applyDeadTime.execute()); - TS_ASSERT(applyDeadTime.isExecuted()); - - double numGoodFrames = 1.0; - const Run &run = inputWs->run(); - TS_ASSERT(run.hasProperty("goodfrm")) - - numGoodFrames = - boost::lexical_cast<double>(run.getProperty("goodfrm")->value()); - - MatrixWorkspace_sptr outputWs = - applyDeadTime.getProperty("OutputWorkspace"); - TS_ASSERT(outputWs); - - TS_ASSERT_EQUALS( - outputWs->y(0)[0], - inputWs->y(0)[0] / - (1 - - inputWs->y(0)[0] * - (deadValue() / - ((inputWs->x(0)[1] - inputWs->x(0)[0]) * numGoodFrames)))); - TS_ASSERT_EQUALS( - outputWs->y(0)[40], - inputWs->y(0)[40] / - (1 - - inputWs->y(0)[40] * - (deadValue() / - ((inputWs->x(0)[1] - inputWs->x(0)[0]) * numGoodFrames)))); - TS_ASSERT_EQUALS( - outputWs->y(31)[20], - inputWs->y(31)[20] / - (1 - - inputWs->y(31)[20] * - (deadValue() / - ((inputWs->x(0)[1] - inputWs->x(0)[0]) * numGoodFrames)))); - - TS_ASSERT_DELTA(35.9991, outputWs->y(12)[2], 0.001); - TS_ASSERT_DELTA(4901.5439, outputWs->y(20)[14], 0.001); - } - - void testDifferentSize() { - MatrixWorkspace_sptr inputWs = loadDataFromFile(); - - // Bigger row count than file (expect to fail) - auto deadTimes = makeDeadTimeTable(64); - - ApplyDeadTimeCorr applyDeadTime; - applyDeadTime.initialize(); - applyDeadTime.setChild(true); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("InputWorkspace", inputWs)); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("DeadTimeTable", deadTimes)); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("OutputWorkspace", "__NotUsed")); - TS_ASSERT_THROWS(applyDeadTime.execute(), std::logic_error); - - // Check new table wasn't created - MatrixWorkspace_sptr output = applyDeadTime.getProperty("OutputWorkspace"); - TS_ASSERT(!output); - } - - void testSelectedSpectrum() { - MatrixWorkspace_sptr inputWs = loadDataFromFile(); - - boost::shared_ptr<ITableWorkspace> deadTimes = - boost::make_shared<Mantid::DataObjects::TableWorkspace>(); - deadTimes->addColumn("int", "Spectrum Number"); - deadTimes->addColumn("double", "DeadTime Value"); - - // Spectrum: 3,6,9,12,15,18,21 ..... - for (int i = 0; i < 7; ++i) { - Mantid::API::TableRow row = deadTimes->appendRow(); - row << (i + 1) * 3 << deadValue(); - } - - //.... Index will therefore be 2,5,8,11,14,17,20 - - ApplyDeadTimeCorr applyDeadTime; - applyDeadTime.initialize(); - applyDeadTime.setChild(true); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("InputWorkspace", inputWs)); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("DeadTimeTable", deadTimes)); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("OutputWorkspace", "__NotUsed")); - TS_ASSERT_THROWS_NOTHING(applyDeadTime.execute()); - TS_ASSERT(applyDeadTime.isExecuted()); - - double numGoodFrames = 1.0; - const Run &run = inputWs->run(); - TS_ASSERT(run.hasProperty("goodfrm")) - - numGoodFrames = - boost::lexical_cast<double>(run.getProperty("goodfrm")->value()); - - MatrixWorkspace_sptr outputWs = - applyDeadTime.getProperty("OutputWorkspace"); - TS_ASSERT(outputWs); - - TS_ASSERT_EQUALS(outputWs->y(0)[0], inputWs->y(0)[0]); - TS_ASSERT_EQUALS( - outputWs->y(14)[40], - inputWs->y(14)[40] / - (1 - - inputWs->y(14)[40] * - (deadValue() / - ((inputWs->x(0)[1] - inputWs->x(0)[0]) * numGoodFrames)))); - TS_ASSERT_EQUALS(outputWs->y(31)[20], inputWs->y(31)[20]); - - // Should be the same (no dead time associated with it) - TS_ASSERT_DELTA(36.0, outputWs->y(12)[2], 0.1); - - // Should be new value (dead time applied based on spectrum number) - TS_ASSERT_DELTA(4901.5439, outputWs->y(20)[14], 0.001); - } - - /// Test algorithm rejects an input workspace with uneven bin widths - void testUnevenBinWidths() { - constexpr size_t numSpectra(2); - auto workspace = WorkspaceCreationHelper::create2DWorkspace( - static_cast<int>(numSpectra), 10); - - // Rebin the workspace to make bin widths uneven - auto rebin = AlgorithmFactory::Instance().create("Rebin", 1); - rebin->initialize(); - rebin->setChild(true); - rebin->setProperty("InputWorkspace", workspace); - rebin->setPropertyValue("OutputWorkspace", "__NotUsed"); - rebin->setPropertyValue("Params", "0, 3, 6, 1, 10"); // uneven bins - rebin->execute(); - MatrixWorkspace_sptr rebinned = rebin->getProperty("OutputWorkspace"); - - // Dead time table - auto deadTimes = makeDeadTimeTable(numSpectra); - - // Test that algorithm throws when property is set - ApplyDeadTimeCorr applyDT; - applyDT.initialize(); - applyDT.setChild(true); - TS_ASSERT_THROWS(applyDT.setProperty("InputWorkspace", rebinned), - std::invalid_argument); - } - - // Test that algorithm throws if input workspace does not contain number of - // good frames - void testNoGoodfrmPresent() { - MatrixWorkspace_sptr inputWs = loadDataFromFile(); - auto deadTimes = makeDeadTimeTable(32); - - auto &run = inputWs->mutableRun(); - run.removeLogData("goodfrm"); - TS_ASSERT(!run.hasProperty("goodfrm")); - - ApplyDeadTimeCorr applyDeadTime; - applyDeadTime.initialize(); - applyDeadTime.setChild(true); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("InputWorkspace", inputWs)); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("DeadTimeTable", deadTimes)); - TS_ASSERT_THROWS_NOTHING( - applyDeadTime.setProperty("OutputWorkspace", "__NotUsed")); - TS_ASSERT_THROWS(applyDeadTime.execute(), std::invalid_argument); - TS_ASSERT(!applyDeadTime.isExecuted()); - } - -private: - /** - * Generates a dead time table with the given number of spectra - * @param numSpectra :: [input] Number of rows in the table - * @returns :: Dead time table - */ - boost::shared_ptr<ITableWorkspace> makeDeadTimeTable(size_t numSpectra) { - boost::shared_ptr<ITableWorkspace> deadTimes = - boost::make_shared<Mantid::DataObjects::TableWorkspace>(); - deadTimes->addColumn("int", "Spectrum Number"); - deadTimes->addColumn("double", "DeadTime Value"); - for (size_t i = 0; i < numSpectra; i++) { - Mantid::API::TableRow row = deadTimes->appendRow(); - row << static_cast<int>(i + 1) << deadValue(); - } - return deadTimes; - } - - /** - * Loads data from the test data file - * @returns :: Workspace with loaded data - */ - MatrixWorkspace_sptr loadDataFromFile() { - Mantid::DataHandling::LoadMuonNexus2 loader; - loader.initialize(); - loader.setChild(true); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "__NotUsed"); - TS_ASSERT_THROWS_NOTHING(loader.execute()); - TS_ASSERT_EQUALS(loader.isExecuted(), true); - Workspace_sptr data = loader.getProperty("OutputWorkspace"); - auto matrixWS = boost::dynamic_pointer_cast<MatrixWorkspace>(data); - TS_ASSERT(data); - return matrixWS; - } - - /// Test dead time value - double deadValue() const { return -0.00456; } -}; - -#endif /* MANTID_ALGORITHMS_APPLYDEADTIMECORRTEST_H_ */ diff --git a/Framework/Algorithms/test/AsymmetryCalcTest.h b/Framework/Algorithms/test/AsymmetryCalcTest.h deleted file mode 100644 index 19e8c2d8d9dc0374d25b913192e9b74f338e8e2d..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/AsymmetryCalcTest.h +++ /dev/null @@ -1,193 +0,0 @@ -#ifndef ASYMMETRYCALCTEST_H_ -#define ASYMMETRYCALCTEST_H_ - -#include "MantidTestHelpers/WorkspaceCreationHelper.h" -#include <cxxtest/TestSuite.h> - -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/IAlgorithm.h" -#include "MantidAPI/Workspace.h" -#include "MantidAPI/WorkspaceGroup.h" -#include "MantidAlgorithms/AsymmetryCalc.h" -#include "MantidDataHandling/GroupDetectors.h" -#include "MantidDataHandling/LoadInstrument.h" -#include "MantidDataHandling/LoadMuonNexus2.h" -#include "MantidDataObjects/Workspace2D.h" -#include <algorithm> -#include <stdexcept> - -using namespace Mantid::Algorithms; -using namespace Mantid::API; - -/** - * This is a test class that exists to test the method validateInputs() - */ -class TestAsymmetryCalc : public Mantid::Algorithms::AsymmetryCalc { -public: - std::map<std::string, std::string> wrapValidateInputs() { - return this->validateInputs(); - } -}; - -class AsymmetryCalcTest : public CxxTest::TestSuite { -public: - void testName() { - AsymmetryCalc asymCalc; - TS_ASSERT_EQUALS(asymCalc.name(), "AsymmetryCalc") - } - - void testCategory() { - AsymmetryCalc asymCalc; - TS_ASSERT_EQUALS(asymCalc.category(), "Muon") - } - - void testInit() { - AsymmetryCalc asymCalc; - asymCalc.initialize(); - TS_ASSERT(asymCalc.isInitialized()) - } - - void testProperties() { - AsymmetryCalc asymCalc; - asymCalc.initialize(); - asymCalc.setProperty("Alpha", "1.0"); - TS_ASSERT_EQUALS(asymCalc.getPropertyValue("Alpha"), "1"); - } - - void testExecuteOnDataFile() { - MatrixWorkspace_sptr data; - TS_ASSERT_THROWS_NOTHING(data = loadDataFile()); - TS_ASSERT(data); - AsymmetryCalc asymCalc; - try { - asymCalc.initialize(); - asymCalc.setChild(true); - asymCalc.setProperty("InputWorkspace", data); - asymCalc.setPropertyValue("OutputWorkspace", "__Unused"); - asymCalc.setPropertyValue("Alpha", "1.0"); - asymCalc.setPropertyValue("ForwardSpectra", - "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16"); - asymCalc.setPropertyValue( - "BackwardSpectra", "17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32"); - TS_ASSERT_EQUALS(asymCalc.execute(), true); - } catch (std::runtime_error &err) { - TS_FAIL(err.what()); - } - - // Check the result - MatrixWorkspace_const_sptr outputWS = - asymCalc.getProperty("OutputWorkspace"); - TS_ASSERT_DELTA(outputWS->y(0)[100], 0.2965, 0.005); - TS_ASSERT(!outputWS->isHistogramData()); - } - - void test_single_spectra() { - auto ws = WorkspaceCreationHelper::create2DWorkspace(3, 10); - for (size_t i = 0; i < ws->getNumberHistograms(); ++i) { - auto &y = ws->mutableY(i); - std::fill(y.begin(), y.end(), static_cast<double>(i + 1)); - } - - AsymmetryCalc alg; - alg.initialize(); - alg.setChild(true); - alg.setProperty("InputWorkspace", ws); - alg.setPropertyValue("OutputWorkspace", "__Unused"); - alg.setPropertyValue("ForwardSpectra", "1"); - alg.setPropertyValue("BackwardSpectra", "3"); - alg.execute(); - - MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace"); - TS_ASSERT_EQUALS(outputWS->y(0)[0], -0.5); // == (1 - 3)/(1 + 3) - TS_ASSERT_EQUALS(outputWS->y(0)[6], -0.5); // == (1 - 3)/(1 + 3) - TS_ASSERT_EQUALS(outputWS->y(0)[9], -0.5); // == (1 - 3)/(1 + 3) - TS_ASSERT(!outputWS->isHistogramData()); - } - - void test_yUnitLabel() { - auto ws = WorkspaceCreationHelper::create2DWorkspace(2, 1); - - AsymmetryCalc alg; - alg.initialize(); - alg.setChild(true); - alg.setProperty("InputWorkspace", ws); - alg.setPropertyValue("OutputWorkspace", "__Unused"); - alg.execute(); - - MatrixWorkspace_const_sptr result = alg.getProperty("OutputWorkspace"); - - TS_ASSERT(result); - - if (result) { - TS_ASSERT_EQUALS(result->YUnitLabel(), "Asymmetry"); - } - } - - void test_validateInputs() { - auto ws = WorkspaceCreationHelper::create2DWorkspace(2, 1); - AsymmetryCalc asymCalc; - asymCalc.initialize(); - asymCalc.setChild(true); - asymCalc.setProperty("InputWorkspace", ws); - asymCalc.setPropertyValue("OutputWorkspace", "__Unused"); - asymCalc.setPropertyValue("ForwardSpectra", "1"); - asymCalc.setPropertyValue("BackwardSpectra", "3"); - // Bad spectrum number for BackwardSpectra - TS_ASSERT_THROWS(asymCalc.execute(), std::runtime_error); - asymCalc.setPropertyValue("BackwardSpectra", "1"); - asymCalc.setPropertyValue("ForwardSpectra", "3"); - // Bad spectrum number for ForwardSpectra - TS_ASSERT_THROWS(asymCalc.execute(), std::runtime_error); - } - - /** - * Test that the algorithm can handle a WorkspaceGroup as input without - * crashing - * We have to use the ADS to test WorkspaceGroups - */ - void testValidateInputsWithWSGroup() { - auto ws1 = boost::static_pointer_cast<Workspace>( - WorkspaceCreationHelper::create2DWorkspace(2, 1)); - auto ws2 = boost::static_pointer_cast<Workspace>( - WorkspaceCreationHelper::create2DWorkspace(2, 1)); - AnalysisDataService::Instance().add("workspace1", ws1); - AnalysisDataService::Instance().add("workspace2", ws2); - auto group = boost::make_shared<WorkspaceGroup>(); - AnalysisDataService::Instance().add("group", group); - group->add("workspace1"); - group->add("workspace2"); - TestAsymmetryCalc calc; - calc.initialize(); - calc.setChild(true); - TS_ASSERT_THROWS_NOTHING(calc.setPropertyValue("InputWorkspace", "group")); - calc.setPropertyValue("OutputWorkspace", "__Unused"); - calc.setPropertyValue("ForwardSpectra", "1"); - calc.setPropertyValue("BackwardSpectra", "2"); - TS_ASSERT_THROWS_NOTHING(calc.wrapValidateInputs()); - AnalysisDataService::Instance().clear(); - } - -private: - /// Load data from file - MatrixWorkspace_sptr loadDataFile() { - Mantid::DataHandling::LoadMuonNexus2 loader; - loader.initialize(); - loader.setChild(true); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "__Unused"); - loader.execute(); - if (loader.isExecuted()) { - Workspace_sptr outWS = loader.getProperty("OutputWorkspace"); - auto matrixWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outWS); - if (matrixWS) { - return matrixWS; - } else { - throw std::runtime_error("Failed to cast loaded workspace"); - } - } else { - throw std::runtime_error("Failed to load test data file"); - } - } -}; - -#endif /*ASYMMETRYCALCTEST_H_*/ diff --git a/Framework/Algorithms/test/CalMuonDeadTimeTest.h b/Framework/Algorithms/test/CalMuonDeadTimeTest.h deleted file mode 100644 index 0ccc535f44e095cc6f41ef0cf71a33542ab618ff..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/CalMuonDeadTimeTest.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef CALMUONDEADTIMETEST_H_ -#define CALMUONDEADTIMETEST_H_ - -#include <cxxtest/TestSuite.h> - -#include "MantidDataHandling/LoadMuonNexus1.h" -#include "MantidAPI/IAlgorithm.h" -#include "MantidAPI/Column.h" -#include "MantidAPI/Run.h" -#include "MantidAlgorithms/CalMuonDeadTime.h" -#include "MantidAPI/Workspace.h" -#include "MantidDataObjects/Workspace2D.h" -#include "MantidDataObjects/TableWorkspace.h" -#include "MantidAPI/AnalysisDataService.h" -#include <stdexcept> - -using namespace Mantid::Algorithms; -using namespace Mantid::API; -using namespace Mantid::DataObjects; - -class CalMuonDeadTimeTest : public CxxTest::TestSuite { -public: - void testName() { - CalMuonDeadTime calDeadTime; - TS_ASSERT_EQUALS(calDeadTime.name(), "CalMuonDeadTime") - } - - void testCategory() { - CalMuonDeadTime calDeadTime; - TS_ASSERT_EQUALS(calDeadTime.category(), "Muon") - } - - void testInit() { - CalMuonDeadTime calDeadTime; - calDeadTime.initialize(); - TS_ASSERT(calDeadTime.isInitialized()) - } - - void testCalDeadTime() { - auto inputWS = loadData(); - - CalMuonDeadTime calDeadTime; - calDeadTime.initialize(); - calDeadTime.setProperty("InputWorkspace", inputWS); - calDeadTime.setPropertyValue("DeadTimeTable", "deadtimetable"); - calDeadTime.setPropertyValue("DataFitted", "fittedData"); - calDeadTime.setPropertyValue("FirstGoodData", "1.0"); - calDeadTime.setPropertyValue("LastGoodData", "2.0"); - - try { - TS_ASSERT_EQUALS(calDeadTime.execute(), true); - } catch (std::runtime_error &e) { - TS_FAIL(e.what()); - } - - ITableWorkspace_sptr table = - boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>( - Mantid::API::AnalysisDataService::Instance().retrieve( - "DeadTimeTable")); - - Column_const_sptr col = table->getColumn(1); - const Column *tableC = col.get(); - TS_ASSERT_DELTA(tableC->operator[](0), -0.0238, 0.0001); - - Mantid::API::AnalysisDataService::Instance().remove("deadtimetable"); - Mantid::API::AnalysisDataService::Instance().remove("fittedData"); - Mantid::API::AnalysisDataService::Instance().remove("EMU6473"); - } - - void testNoGoodfrmPresent() { - auto inputWS = loadData(); - - auto &run = inputWS->mutableRun(); - run.removeLogData("goodfrm"); - TS_ASSERT(!run.hasProperty("goodfrm")); - - CalMuonDeadTime calDeadTime; - calDeadTime.initialize(); - calDeadTime.setRethrows(true); - calDeadTime.setProperty("InputWorkspace", inputWS); - calDeadTime.setPropertyValue("DeadTimeTable", "deadtimetable"); - calDeadTime.setPropertyValue("DataFitted", "fittedData"); - calDeadTime.setPropertyValue("FirstGoodData", "1.0"); - calDeadTime.setPropertyValue("LastGoodData", "2.0"); - - TS_ASSERT_THROWS(calDeadTime.execute(), std::runtime_error); - TS_ASSERT(!calDeadTime.isExecuted()); - } - -private: - // Load the muon nexus file - MatrixWorkspace_sptr loadData() { - Mantid::DataHandling::LoadMuonNexus1 loader; - loader.initialize(); - loader.setChild(true); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "__NotUsed"); - TS_ASSERT_THROWS_NOTHING(loader.execute()); - TS_ASSERT_EQUALS(loader.isExecuted(), true); - Workspace_sptr outputWS = loader.getProperty("OutputWorkspace"); - return boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS); - } -}; - -#endif /*CALMUONDEADTIMETEST_H_*/ diff --git a/Framework/Algorithms/test/CalMuonDetectorPhasesTest.h b/Framework/Algorithms/test/CalMuonDetectorPhasesTest.h deleted file mode 100644 index 97b7204b90b2ed77a47b9a8c169263cc4d7cc8ae..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/CalMuonDetectorPhasesTest.h +++ /dev/null @@ -1,221 +0,0 @@ -#ifndef CALMUONDETECTORPHASESTEST_H_ -#define CALMUONDETECTORPHASESTEST_H_ - -#include <cxxtest/TestSuite.h> - -#include "MantidAlgorithms/CalMuonDetectorPhases.h" -#include "MantidAPI/FrameworkManager.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/Axis.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/Run.h" -#include "MantidAPI/Workspace.h" -#include "MantidAPI/WorkspaceGroup.h" -#include "MantidGeometry/Instrument.h" -#include "MantidKernel/cow_ptr.h" -#include "MantidKernel/PhysicalConstants.h" - -using namespace Mantid::API; -using Mantid::MantidVec; - -const std::string outputName = "MuonRemoveExpDecay_Output"; - -/** - * This is a test class that exists to test the method validateInputs() - */ -class TestCalMuonDetectorPhases - : public Mantid::Algorithms::CalMuonDetectorPhases { -public: - std::map<std::string, std::string> wrapValidateInputs() { - return this->validateInputs(); - } -}; - -class CalMuonDetectorPhasesTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static CalMuonDetectorPhasesTest *createSuite() { - return new CalMuonDetectorPhasesTest(); - } - static void destroySuite(CalMuonDetectorPhasesTest *suite) { delete suite; } - - CalMuonDetectorPhasesTest() { FrameworkManager::Instance(); } - - void testInit() { - IAlgorithm_sptr alg = - AlgorithmManager::Instance().create("CalMuonDetectorPhases"); - alg->initialize(); - TS_ASSERT(alg->isInitialized()) - } - - void testExecute() { - auto ws = createWorkspace(4, 100, "Microseconds"); - runExecutionTest(ws); - } - - void testBadWorkspaceUnits() { - - auto ws = createWorkspace(2, 4, "Wavelength"); - auto calc = AlgorithmManager::Instance().create("CalMuonDetectorPhases"); - calc->initialize(); - calc->setChild(true); - calc->setProperty("InputWorkspace", ws); - calc->setPropertyValue("Frequency", "4"); - calc->setPropertyValue("DataFitted", "fit"); - calc->setPropertyValue("DetectorTable", "tab"); - calc->setProperty("ForwardSpectra", std::vector<int>{1}); - calc->setProperty("BackwardSpectra", std::vector<int>{2}); - - TS_ASSERT_THROWS(calc->execute(), std::runtime_error); - TS_ASSERT(!calc->isExecuted()); - } - - void testNoFrequencySupplied() { - - auto ws = createWorkspace(2, 4, "Microseconds"); - auto calc = AlgorithmManager::Instance().create("CalMuonDetectorPhases"); - calc->initialize(); - calc->setChild(true); - calc->setProperty("InputWorkspace", ws); - calc->setPropertyValue("DataFitted", "fit"); - calc->setPropertyValue("DetectorTable", "tab"); - calc->setProperty("ForwardSpectra", std::vector<int>{1}); - calc->setProperty("BackwardSpectra", std::vector<int>{2}); - - TS_ASSERT_THROWS(calc->execute(), std::runtime_error); - TS_ASSERT(!calc->isExecuted()); - } - - /** - * Test that the algorithm can handle a WorkspaceGroup as input without - * crashing - * We have to use the ADS to test WorkspaceGroups - */ - void testValidateInputsWithWSGroup() { - auto ws1 = boost::static_pointer_cast<Workspace>( - createWorkspace(2, 4, "Microseconds")); - auto ws2 = boost::static_pointer_cast<Workspace>( - createWorkspace(2, 4, "Microseconds")); - AnalysisDataService::Instance().add("workspace1", ws1); - AnalysisDataService::Instance().add("workspace2", ws2); - auto group = boost::make_shared<WorkspaceGroup>(); - AnalysisDataService::Instance().add("group", group); - group->add("workspace1"); - group->add("workspace2"); - TestCalMuonDetectorPhases calc; - calc.initialize(); - calc.setChild(true); - TS_ASSERT_THROWS_NOTHING(calc.setPropertyValue("InputWorkspace", "group")); - calc.setPropertyValue("DataFitted", "fit"); - calc.setPropertyValue("DetectorTable", "tab"); - calc.setProperty("ForwardSpectra", std::vector<int>{1}); - calc.setProperty("BackwardSpectra", std::vector<int>{2}); - TS_ASSERT_THROWS_NOTHING(calc.wrapValidateInputs()); - AnalysisDataService::Instance().clear(); - } - - void testWithMUSRWorkspaceLongitudinal() { - auto ws = createWorkspace(4, 100, "Microseconds", "MUSR", "Longitudinal"); - runExecutionTest(ws); - } - - void testWithMUSRWorkspaceTransverse() { - auto ws = createWorkspace(4, 100, "Microseconds", "MUSR", "Transverse"); - runExecutionTest(ws); - } - -private: - MatrixWorkspace_sptr createWorkspace(size_t nspec, size_t maxt, - const std::string &units) { - - // Create a fake muon dataset - double a = 0.1; // Amplitude of the oscillations - double w = 25.; // Frequency of the oscillations - double tau = Mantid::PhysicalConstants::MuonLifetime * - 1e6; // Muon life time in microseconds - - MantidVec X; - MantidVec Y; - MantidVec E; - for (size_t s = 0; s < nspec; s++) { - for (size_t t = 0; t < maxt; t++) { - double x = static_cast<double>(t) / static_cast<double>(maxt); - double e = exp(-x / tau); - X.push_back(x); - Y.push_back(a * sin(w * x + - static_cast<double>(s) * M_PI / - static_cast<double>(nspec)) * - e + - e); - E.push_back(0.005); - } - } - - auto createWS = AlgorithmManager::Instance().create("CreateWorkspace"); - createWS->initialize(); - createWS->setChild(true); - createWS->setProperty("UnitX", units); - createWS->setProperty("DataX", X); - createWS->setProperty("DataY", Y); - createWS->setProperty("DataE", E); - createWS->setProperty("NSpec", static_cast<int>(nspec)); - createWS->setPropertyValue("OutputWorkspace", "ws"); - createWS->execute(); - MatrixWorkspace_sptr ws = createWS->getProperty("OutputWorkspace"); - - return ws; - } - - /// overload that adds instrument and main field direction log to workspace - MatrixWorkspace_sptr createWorkspace(size_t nspec, size_t maxt, - const std::string &units, - const std::string &instrumentName, - const std::string &mainFieldDirection) { - auto ws = createWorkspace(nspec, maxt, units); - auto instrument = - boost::make_shared<Mantid::Geometry::Instrument>(instrumentName); - ws->setInstrument(instrument); - ws->mutableRun().addProperty("main_field_direction", mainFieldDirection); - return ws; - } - - /// Runs test of execution on the given workspace - void runExecutionTest(const MatrixWorkspace_sptr workspace) { - auto calc = AlgorithmManager::Instance().create("CalMuonDetectorPhases"); - calc->initialize(); - calc->setChild(true); - calc->setProperty("InputWorkspace", workspace); - calc->setPropertyValue("Frequency", "4"); - calc->setPropertyValue("DataFitted", "fit"); - calc->setPropertyValue("DetectorTable", "tab"); - calc->setProperty("ForwardSpectra", std::vector<int>{1, 2}); - calc->setProperty("BackwardSpectra", std::vector<int>{3, 4}); - - TS_ASSERT_THROWS_NOTHING(calc->execute()); - - ITableWorkspace_sptr tab = calc->getProperty("DetectorTable"); - - // Check the table workspace - TS_ASSERT_EQUALS(tab->rowCount(), 4); - TS_ASSERT_EQUALS(tab->columnCount(), 3); - // Test detector IDs - TS_ASSERT_EQUALS(tab->Int(0, 0), 1); - TS_ASSERT_EQUALS(tab->Int(1, 0), 2); - TS_ASSERT_EQUALS(tab->Int(2, 0), 3); - TS_ASSERT_EQUALS(tab->Int(3, 0), 4); - // Test asymmetries - TS_ASSERT_DELTA(tab->Double(0, 1), 0.099, 0.001); - TS_ASSERT_DELTA(tab->Double(1, 1), 0.100, 0.001); - TS_ASSERT_DELTA(tab->Double(2, 1), 0.100, 0.001); - TS_ASSERT_DELTA(tab->Double(3, 1), 0.100, 0.001); - // Test phases - TS_ASSERT_DELTA(tab->Double(0, 2), 1.576, 0.001); - TS_ASSERT_DELTA(tab->Double(1, 2), 0.789, 0.001); - TS_ASSERT_DELTA(tab->Double(2, 2), 0.005, 0.001); - TS_ASSERT_DELTA(tab->Double(3, 2), 5.504, 0.001); - } -}; - -#endif /*CALMUONDETECTORPHASESTEST_H_*/ diff --git a/Framework/Algorithms/test/CalculateMuonAsymmetryTest.h b/Framework/Algorithms/test/CalculateMuonAsymmetryTest.h deleted file mode 100644 index f3e6125870281db1e2c54bbd4fc7b2a9183390a7..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/CalculateMuonAsymmetryTest.h +++ /dev/null @@ -1,365 +0,0 @@ -#ifndef CALCULATEMUONASYMMETRYTEST_H_ -#define CALCULATEMUONASYMMETRYTEST_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidAlgorithms/CalculateMuonAsymmetry.h" -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/VectorHelper.h" -#include "MantidKernel/PhysicalConstants.h" -#include "MantidAPI/FrameworkManager.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidHistogramData/LinearGenerator.h" -#include "MantidTestHelpers/WorkspaceCreationHelper.h" - -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/TableRow.h" -#include "MantidAPI/FunctionFactory.h" -#include "MantidAPI/IFunction.h" - -using namespace Mantid::API; -using Mantid::MantidVec; -using Mantid::Algorithms::CalculateMuonAsymmetry; - -const std::string outputName = "CalculateMuonAsymmetry_Output"; - -namespace { - -struct yData { - double operator()(const double x, size_t) { - - // Create a fake muon dataset - double a = 0.20; // Amplitude of the oscillations - double w = 5.0; // Frequency of the oscillations - double phi = 0.1; - return (3.4 * (1.0 + a * sin(w * x + phi))); - } -}; - -struct eData { - double operator()(const double, size_t) { return 0.005; } -}; - -MatrixWorkspace_sptr createWorkspace(size_t nspec, size_t maxt) { - MatrixWorkspace_sptr ws = - WorkspaceCreationHelper::create2DWorkspaceFromFunction( - yData(), static_cast<int>(nspec), 0.0, 10.0, - 10.0 * (1.0 / static_cast<double>(maxt)), true, eData()); - ws->setYUnit("Asymmetry"); - return ws; -} - -void genData() { - auto ws1 = createWorkspace(1, 200); - AnalysisDataService::Instance().addOrReplace("ws1", ws1); - - auto ws2 = createWorkspace(1, 200); - AnalysisDataService::Instance().addOrReplace("ws2", ws2); - - auto ws3 = createWorkspace(1, 200); - AnalysisDataService::Instance().addOrReplace("ws3", ws3); - - auto ws4 = createWorkspace(1, 200); - AnalysisDataService::Instance().addOrReplace("ws4", ws4); -} - -ITableWorkspace_sptr genTable() { - Mantid::API::ITableWorkspace_sptr table = - Mantid::API::WorkspaceFactory::Instance().createTable(); - table->addColumn("double", "norm"); - table->addColumn("str", "name"); - table->addColumn("str", "method"); - - // populate table - TableRow row = table->appendRow(); - row << 2.2 << "ws1" - << "Estimate"; - row = table->appendRow(); - row << 2.2 << "ws2" - << "Estimate"; - row = table->appendRow(); - row << 2.2 << "ws3" - << "Estimate"; - row = table->appendRow(); - row << 2.2 << "ws4" - << "Estimate"; - return table; -} - -IAlgorithm_sptr setUpFuncAlg(std::vector<std::string> wsNames, - const IFunction_sptr &func) { - IAlgorithm_sptr asymmAlg = AlgorithmManager::Instance().create( - "ConvertFitFunctionForMuonTFAsymmetry"); - asymmAlg->initialize(); - asymmAlg->setChild(true); - asymmAlg->setProperty("WorkspaceList", wsNames); - ITableWorkspace_sptr table = genTable(); - asymmAlg->setProperty("NormalizationTable", table); - asymmAlg->setProperty("InputFunction", func); - return asymmAlg; -} - -IFunction_sptr genSingleFunc(std::vector<std::string> wsNames) { - IFunction_sptr func = FunctionFactory::Instance().createInitialized( - "name=GausOsc,Frequency=3.0"); - IAlgorithm_sptr alg = setUpFuncAlg(wsNames, func); - alg->execute(); - IFunction_sptr funcOut = alg->getProperty("OutputFunction"); - return funcOut; -} - -IFunction_sptr genDoubleFunc(std::vector<std::string> wsNames) { - std::string multiFuncString = "composite=MultiDomainFunction,NumDeriv=1;"; - multiFuncString += "name=GausOsc,$domains=i,Frequency=3.0;"; - multiFuncString += "name=GausOsc,$domains=i,Frequency=3.0;"; - IFunction_sptr func = - FunctionFactory::Instance().createInitialized(multiFuncString); - IAlgorithm_sptr alg = setUpFuncAlg(wsNames, func); - alg->execute(); - IFunction_sptr funcOut = alg->getProperty("OutputFunction"); - std::cout << funcOut << std::endl; - return funcOut; -} - -IAlgorithm_sptr setUpAlg(ITableWorkspace_sptr &table, IFunction_sptr func, - std::vector<std::string> wsNamesNorm, - std::vector<std::string> wsOut) { - IAlgorithm_sptr asymmAlg = - AlgorithmManager::Instance().create("CalculateMuonAsymmetry"); - asymmAlg->initialize(); - asymmAlg->setChild(true); - asymmAlg->setProperty("NormalizationTable", table); - asymmAlg->setProperty("StartX", 0.1); - asymmAlg->setProperty("EndX", 0.9); - asymmAlg->setProperty("InputFunction", func); - asymmAlg->setProperty("UnNormalizedWorkspaceList", wsNamesNorm); - asymmAlg->setProperty("ReNormalizedWorkspaceList", wsOut); - - return asymmAlg; -} - -void clearADS() { AnalysisDataService::Instance().clear(); } - -class CalculateMuonAsymmetryTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static CalculateMuonAsymmetryTest *createSuite() { - return new CalculateMuonAsymmetryTest(); - } - static void destroySuite(CalculateMuonAsymmetryTest *suite) { delete suite; } - - CalculateMuonAsymmetryTest() { FrameworkManager::Instance(); } - - void testInit() { - // IAlgorithm_sptr alg = setUpAlg(); - - // TS_ASSERT(alg->isInitialized()); - } - - void test_Execute() { - - genData(); - std::vector<std::string> wsNames = {"ws1"}; - std::vector<std::string> wsOut = {"ws2"}; - auto func = genSingleFunc(wsNames); - auto table = genTable(); - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - clearADS(); - // MatrixWorkspace_sptr outWS = alg->getProperty("OutputWorkspace"); - } - void test_singleFit() { - - genData(); - std::vector<std::string> wsNames = {"ws1"}; - std::vector<std::string> wsOut = {"ws2"}; - auto func = genSingleFunc(wsNames); - auto table = genTable(); - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - std::vector<std::string> output = - alg->getProperty("ReNormalizedWorkspaceList"); - - MatrixWorkspace_sptr outWS = - AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(output[0]); - - double delta = 0.0001; - - TS_ASSERT_DELTA(table->Double(1, 0), 3.4, delta); - TS_ASSERT_EQUALS(table->String(1, 1), "ws2"); - TS_ASSERT_EQUALS(table->String(1, 2), "Calculated"); - - TS_ASSERT_DELTA(outWS->x(0)[10], 0.5, delta); - TS_ASSERT_DELTA(outWS->x(0)[40], 2.0, delta); - TS_ASSERT_DELTA(outWS->x(0)[100], 5.0, delta); - - TS_ASSERT_DELTA(outWS->y(0)[10], 0.1031, delta); - TS_ASSERT_DELTA(outWS->y(0)[40], -0.1250, delta); - TS_ASSERT_DELTA(outWS->y(0)[100], -0.0065, delta); - - TS_ASSERT_DELTA(outWS->e(0)[10], 0.0015, delta); - TS_ASSERT_DELTA(outWS->e(0)[40], 0.0015, delta); - TS_ASSERT_DELTA(outWS->e(0)[100], 0.0015, delta); - - clearADS(); - } - void test_badFittingRange() { - - genData(); - std::vector<std::string> wsNames = {"ws1"}; - std::vector<std::string> wsOut = {"ws2"}; - auto func = genSingleFunc(wsNames); - auto table = genTable(); - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - alg->setProperty("StartX", 10.); - alg->setProperty("EndX", 1.); - TS_ASSERT_THROWS(alg->execute(), std::runtime_error); - clearADS(); - } - - void test_mismatchWSLists() { - - genData(); - std::vector<std::string> wsNames = {"ws1"}; - std::vector<std::string> wsOut = {"ws2", "ws3"}; - auto func = genSingleFunc(wsNames); - auto table = genTable(); - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - TS_ASSERT_THROWS(alg->execute(), std::runtime_error); - clearADS(); - } - - void test_multiFuncSingleWS() { - - genData(); - // need the 2 here to get multi func - std::vector<std::string> wsNames = {"ws1", "ws3"}; - std::vector<std::string> wsOut = {"ws2"}; - auto func = genDoubleFunc(wsNames); - auto table = genTable(); - wsNames = {"ws1"}; - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - TS_ASSERT_THROWS(alg->execute(), std::runtime_error); - clearADS(); - } - - void test_yUnitLabel() { - - genData(); - std::vector<std::string> wsNames = {"ws1"}; - std::vector<std::string> wsOut = {"ws2"}; - auto func = genSingleFunc(wsNames); - auto table = genTable(); - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - std::vector<std::string> output = - alg->getProperty("ReNormalizedWorkspaceList"); - - MatrixWorkspace_sptr outWS = - AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(output[0]); - - TS_ASSERT_EQUALS(outWS->YUnitLabel(), "Asymmetry"); - } - - void test_multiFuncWS() { - - genData(); - // need the 2 here to get multi func - std::vector<std::string> wsNames = {"ws1", "ws2"}; - std::vector<std::string> wsOut = {"ws3", "ws4"}; - auto func = genDoubleFunc(wsNames); - auto table = genTable(); - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - std::vector<std::string> output = - alg->getProperty("ReNormalizedWorkspaceList"); - - for (int j = 0; j < 2; j++) { - MatrixWorkspace_sptr outWS = - AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( - output[j]); - - double delta = 0.0001; - - TS_ASSERT_DELTA(table->Double(j + 2, 0), 3.4, delta); - TS_ASSERT_EQUALS(table->String(j + 2, 1), output[j]); - TS_ASSERT_EQUALS(table->String(j + 2, 2), "Calculated"); - - TS_ASSERT_DELTA(outWS->x(0)[10], 0.5, delta); - TS_ASSERT_DELTA(outWS->x(0)[40], 2.0, delta); - TS_ASSERT_DELTA(outWS->x(0)[100], 5.0, delta); - - TS_ASSERT_DELTA(outWS->y(0)[10], 0.1031, delta); - TS_ASSERT_DELTA(outWS->y(0)[40], -0.1250, delta); - TS_ASSERT_DELTA(outWS->y(0)[100], -0.0065, delta); - - TS_ASSERT_DELTA(outWS->e(0)[10], 0.0015, delta); - TS_ASSERT_DELTA(outWS->e(0)[40], 0.0015, delta); - TS_ASSERT_DELTA(outWS->e(0)[100], 0.0015, delta); - } - - clearADS(); - } -}; - -class CalculateMuonAsymmetryTestPerformance : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static CalculateMuonAsymmetryTestPerformance *createSuite() { - return new CalculateMuonAsymmetryTestPerformance(); - } - static void destroySuite(CalculateMuonAsymmetryTestPerformance *suite) { - AnalysisDataService::Instance().clear(); - delete suite; - } - - CalculateMuonAsymmetryTestPerformance() { FrameworkManager::Instance(); } - - void setUp() override { input = createWorkspace(1000, 100); } - - void testExec1D() { - - genData(); - std::vector<std::string> wsNames = {"ws1"}; - std::vector<std::string> wsOut = {"ws2"}; - auto func = genSingleFunc(wsNames); - auto table = genTable(); - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - - alg->execute(); - clearADS(); - } - - void testExec2D() { - - genData(); - std::vector<std::string> wsNames = {"ws1", "ws2"}; - std::vector<std::string> wsOut = {"ws3", "ws4"}; - auto func = genDoubleFunc(wsNames); - auto table = genTable(); - - IAlgorithm_sptr alg = setUpAlg(table, func, wsNames, wsOut); - - alg->execute(); - clearADS(); - } - -private: - MatrixWorkspace_sptr input; -}; -} // close namespace -#endif /*CALCULATEMUONASYMMETRYF_H_*/ diff --git a/Framework/Algorithms/test/EstimateMuonAsymmetryFromCountsTest.h b/Framework/Algorithms/test/EstimateMuonAsymmetryFromCountsTest.h deleted file mode 100644 index 0aa9947770466ee1d34f8f9f090f887b679101b5..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/EstimateMuonAsymmetryFromCountsTest.h +++ /dev/null @@ -1,352 +0,0 @@ -#ifndef ESTIMATEMUONASYMMETRYFROMCOUNTSTEST_H_ -#define ESTIMATEMUONASYMMETRYFROMCOUNTSTEST_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidAlgorithms/EstimateMuonAsymmetryFromCounts.h" -#include "MantidKernel/PhysicalConstants.h" -#include "MantidKernel/VectorHelper.h" -#include "MantidAPI/FrameworkManager.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidHistogramData/LinearGenerator.h" -#include "MantidTestHelpers/WorkspaceCreationHelper.h" -#include "MantidAPI/ITableWorkspace.h" - -using namespace Mantid::API; -using Mantid::MantidVec; -using Mantid::Algorithms::EstimateMuonAsymmetryFromCounts; - -const std::string outputName = "EstimateMuonAsymmetryFromCounts_Output"; - -namespace { -struct yData { - double operator()(const double x, size_t) { - // Create a fake muon dataset - double a = 0.1; // Amplitude of the oscillations - double w = 25.; // Frequency of the oscillations - double tau = Mantid::PhysicalConstants::MuonLifetime * - 1e6; // Muon life time in microseconds - double phi = 0.05; - double e = exp(-x / tau); - return (20. * (1.0 + a * cos(w * x + phi)) * e); - } -}; - -struct eData { - double operator()(const double, size_t) { return 0.005; } -}; - -MatrixWorkspace_sptr createWorkspace(size_t nspec, size_t maxt) { - MatrixWorkspace_sptr ws = - WorkspaceCreationHelper::create2DWorkspaceFromFunction( - yData(), static_cast<int>(nspec), 0.0, 1.0, - (1.0 / static_cast<double>(maxt)), true, eData()); - // Add number of good frames - ws->mutableRun().addProperty("goodfrm", 10); - // AnalysisDataService::Instance().addOrReplace("ws",ws); - return ws; -} - -ITableWorkspace_sptr genTable() { - Mantid::API::ITableWorkspace_sptr table = - Mantid::API::WorkspaceFactory::Instance().createTable(); - table->addColumn("double", "norm"); - table->addColumn("str", "name"); - table->addColumn("str", "method"); - return table; -} - -IAlgorithm_sptr setUpAlg(ITableWorkspace_sptr &table) { - IAlgorithm_sptr asymmAlg = - AlgorithmManager::Instance().create("EstimateMuonAsymmetryFromCounts"); - asymmAlg->initialize(); - asymmAlg->setChild(true); - asymmAlg->setProperty("NormalizationTable", table); - asymmAlg->setProperty("WorkspaceName", "ws"); - asymmAlg->setProperty("StartX", 0.1); - asymmAlg->setProperty("EndX", 0.9); - return asymmAlg; -} -} - -class EstimateMuonAsymmetryFromCountsTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static EstimateMuonAsymmetryFromCountsTest *createSuite() { - return new EstimateMuonAsymmetryFromCountsTest(); - } - static void destroySuite(EstimateMuonAsymmetryFromCountsTest *suite) { - delete suite; - } - - EstimateMuonAsymmetryFromCountsTest() { FrameworkManager::Instance(); } - - void testInit() { - auto table = genTable(); - IAlgorithm_sptr alg = setUpAlg(table); - TS_ASSERT(alg->isInitialized()) - } - - void test_Execute() { - - auto ws = createWorkspace(1, 50); - auto table = genTable(); - IAlgorithm_sptr alg = setUpAlg(table); - - alg->setProperty("InputWorkspace", ws); - alg->setPropertyValue("OutputWorkspace", outputName); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - - MatrixWorkspace_sptr outWS = alg->getProperty("OutputWorkspace"); - } - void test_EmptySpectrumList() { - - auto ws = createWorkspace(2, 50); - auto table = genTable(); - IAlgorithm_sptr alg = setUpAlg(table); - - alg->setProperty("InputWorkspace", ws); - alg->setPropertyValue("OutputWorkspace", outputName); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - - MatrixWorkspace_sptr outWS = alg->getProperty("OutputWorkspace"); - - double Delta = 0.0001; - for (int j = 0; j < 2; j++) { - // Test some X values - TS_ASSERT_DELTA(outWS->x(j)[10], 0.2000, Delta); - TS_ASSERT_DELTA(outWS->x(j)[19], 0.3800, Delta); - TS_ASSERT_DELTA(outWS->x(j)[49], 0.9800, Delta); - // Test some Y values - TS_ASSERT_DELTA(outWS->y(j)[10], 0.0099, Delta); - TS_ASSERT_DELTA(outWS->y(j)[19], -0.1195, Delta); - TS_ASSERT_DELTA(outWS->y(j)[49], 0.0592, Delta); - // Test some E values - TS_ASSERT_DELTA(outWS->e(j)[10], 0.0002, Delta); - TS_ASSERT_DELTA(outWS->e(j)[19], 0.0003, Delta); - TS_ASSERT_DELTA(outWS->e(j)[49], 0.0004, Delta); - } - } - void test_SpectrumList() { - - std::vector<MatrixWorkspace_sptr> workspaces; - workspaces.push_back(createWorkspace(2, 50)); - - // First, run the algorithm without specifying any spectrum - auto table = genTable(); - IAlgorithm_sptr alg1 = setUpAlg(table); - - alg1->setProperty("InputWorkspace", workspaces[0]); - alg1->setPropertyValue("OutputWorkspace", outputName); - TS_ASSERT_THROWS_NOTHING(alg1->execute()); - TS_ASSERT(alg1->isExecuted()); - - workspaces.push_back(alg1->getProperty("OutputWorkspace")); - - // Then run the algorithm on the second spectrum only - IAlgorithm_sptr alg2 = setUpAlg(table); - - alg2->setProperty("InputWorkspace", workspaces[0]); - alg2->setPropertyValue("OutputWorkspace", outputName); - alg2->setPropertyValue("Spectra", "1"); - TS_ASSERT_THROWS_NOTHING(alg2->execute()); - TS_ASSERT(alg2->isExecuted()); - workspaces.push_back(alg2->getProperty("OutputWorkspace")); - - for (int j = 0; j < 3; j++) { - if (j != 0) { // check we have 2 spectra - TS_ASSERT_EQUALS(workspaces[j]->getNumberHistograms(), - workspaces[0]->getNumberHistograms()); - } - if (j != 2) { // check results match - TS_ASSERT_EQUALS(workspaces[j]->x(j).rawData(), - workspaces[2]->x(j).rawData()); - TS_ASSERT_EQUALS(workspaces[j]->y(j).rawData(), - workspaces[2]->y(j).rawData()); - TS_ASSERT_EQUALS(workspaces[j]->e(j).rawData(), - workspaces[2]->e(j).rawData()); - } - } - } - void test_yUnitLabel() { - - auto ws = createWorkspace(1, 50); - - auto table = genTable(); - IAlgorithm_sptr alg = setUpAlg(table); - alg->setProperty("InputWorkspace", ws); - alg->setProperty("OutputWorkspace", outputName); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()) - MatrixWorkspace_sptr result = alg->getProperty("OutputWorkspace"); - TS_ASSERT(result); - TS_ASSERT_EQUALS(result->YUnitLabel(), "Asymmetry"); - } - void test_NoRange() { - auto ws = createWorkspace(1, 50); - - auto table = genTable(); - IAlgorithm_sptr alg = setUpAlg(table); - alg->setProperty("InputWorkspace", ws); - alg->setProperty("StartX", 0.1); - alg->setProperty("EndX", 0.1); - alg->setProperty("OutputWorkspace", outputName); - TS_ASSERT_THROWS(alg->execute(), std::runtime_error); - } - void test_BackwardsRange() { - auto ws = createWorkspace(1, 50); - - auto table = genTable(); - IAlgorithm_sptr alg = setUpAlg(table); - - alg->setProperty("InputWorkspace", ws); - alg->setProperty("StartX", 0.9); - alg->setProperty("EndX", 0.1); - alg->setProperty("OutputWorkspace", outputName); - TS_ASSERT_THROWS(alg->execute(), std::runtime_error); - } - void test_NumberOfDataPoints() { - - double dx = (1.0 / 300.0); - auto fineWS = WorkspaceCreationHelper::create2DWorkspaceFromFunction( - yData(), 1, 0.0, 1.0, dx, true, eData()); - fineWS->mutableRun().addProperty("goodfrm", 10); - auto coarseWS = WorkspaceCreationHelper::create2DWorkspaceFromFunction( - yData(), 1, dx, 1.0 + dx, 3.0 * dx, true, eData()); - - coarseWS->mutableRun().addProperty("goodfrm", 10); - - auto table = genTable(); - IAlgorithm_sptr fineAlg = setUpAlg(table); - - fineAlg->setProperty("WorkspaceName", "fine"); - fineAlg->setProperty("InputWorkspace", fineWS); - fineAlg->setPropertyValue("OutputWorkspace", "fineOutWS"); - TS_ASSERT_THROWS_NOTHING(fineAlg->execute()); - TS_ASSERT(fineAlg->isExecuted()); - MatrixWorkspace_sptr fineOutWS = fineAlg->getProperty("OutputWorkspace"); - - IAlgorithm_sptr coarseAlg = setUpAlg(table); - coarseAlg->setProperty("InputWorkspace", coarseWS); - coarseAlg->setProperty("WorkspaceName", "coarse"); - coarseAlg->setPropertyValue("OutputWorkspace", "coarseOutWS"); - TS_ASSERT_THROWS_NOTHING(coarseAlg->execute()); - TS_ASSERT(coarseAlg->isExecuted()); - MatrixWorkspace_sptr coarseOutWS = - coarseAlg->getProperty("OutputWorkspace"); - - // check names in table - - TS_ASSERT_EQUALS(table->String(0, 1), "fine"); - TS_ASSERT_EQUALS(table->String(1, 1), "coarse"); - - double Delta = 0.05; // only expect numbers to be similar - for (int j = 0; j < 28; j++) { - // Test some X values - TS_ASSERT_DELTA(fineOutWS->x(0)[1 + j * 3], coarseOutWS->x(0)[j], Delta); - // Test some Y values - TS_ASSERT_DELTA(fineOutWS->y(0)[1 + j * 3], coarseOutWS->y(0)[j], Delta); - // Test some E values - TS_ASSERT_DELTA(fineOutWS->e(0)[1 + j * 3], coarseOutWS->e(0)[j], Delta); - } - } - void test_UserDefinedNorm() { - - auto ws = createWorkspace(1, 50); - double userNorm = 10.2; - - auto table = genTable(); - IAlgorithm_sptr alg = setUpAlg(table); - alg->setProperty("InputWorkspace", ws); - alg->setPropertyValue("OutputWorkspace", outputName); - alg->setProperty("NormalizationIn", userNorm); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - - MatrixWorkspace_sptr outWS = alg->getProperty("OutputWorkspace"); - double normFromAlg = table->Double(0, 0); - - double Delta = 0.0001; - TS_ASSERT_DELTA(normFromAlg, userNorm, Delta); - // Test some X values - TS_ASSERT_DELTA(outWS->x(0)[10], 0.2000, Delta); - TS_ASSERT_DELTA(outWS->x(0)[19], 0.3800, Delta); - TS_ASSERT_DELTA(outWS->x(0)[49], 0.9800, Delta); - // Test some Y values - TS_ASSERT_DELTA(outWS->y(0)[10], -0.7974, Delta); - TS_ASSERT_DELTA(outWS->y(0)[19], -0.8233, Delta); - TS_ASSERT_DELTA(outWS->y(0)[49], -0.7875, Delta); - } - void test_unNorm() { - - auto ws = createWorkspace(1, 50); - - auto table = genTable(); - IAlgorithm_sptr alg = setUpAlg(table); - alg->setProperty("InputWorkspace", ws); - alg->setPropertyValue("OutputWorkspace", outputName); - alg->setProperty("OutputUnNormData", true); - alg->setProperty("OutputUnNormWorkspace", "out"); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - - MatrixWorkspace_sptr outWS = alg->getProperty("OutputUnNormWorkspace"); - - double Delta = 0.0001; - // Test some X values - TS_ASSERT_DELTA(outWS->x(0)[10], 0.2000, Delta); - TS_ASSERT_DELTA(outWS->x(0)[19], 0.3800, Delta); - TS_ASSERT_DELTA(outWS->x(0)[49], 0.9800, Delta); - // Test some Y values - TS_ASSERT_DELTA(outWS->y(0)[10], 2.0662, Delta); - TS_ASSERT_DELTA(outWS->y(0)[19], 1.8016, Delta); - TS_ASSERT_DELTA(outWS->y(0)[49], 2.1670, Delta); - } -}; -// turn clang off, otherwise this does not compile -// clang-format off -class EstimateMuonAsymmetryFromCountsTestPerformance : public CxxTest::TestSuite { - // clang-format on -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static EstimateMuonAsymmetryFromCountsTestPerformance *createSuite() { - return new EstimateMuonAsymmetryFromCountsTestPerformance(); - } - // clang-format off - static void destroySuite(EstimateMuonAsymmetryFromCountsTestPerformance *suite) { - // clang-format on - AnalysisDataService::Instance().clear(); - delete suite; - } - - EstimateMuonAsymmetryFromCountsTestPerformance() { - FrameworkManager::Instance(); - } - - void setUp() override { input = createWorkspace(1000, 100); } - - void testExec2D() { - EstimateMuonAsymmetryFromCounts alg; - alg.initialize(); - alg.setProperty("InputWorkspace", input); - alg.setPropertyValue("OutputWorkspace", "output"); - alg.setProperty("StartX", 0.1); - alg.setProperty("EndX", 0.9); - - Mantid::API::ITableWorkspace_sptr table = - Mantid::API::WorkspaceFactory::Instance().createTable(); - table->addColumn("double", "norm"); - table->addColumn("str", "name"); - table->addColumn("str", "method"); - alg.setProperty("NormalizationTable", table); - - alg.execute(); - } - -private: - MatrixWorkspace_sptr input; -}; -#endif /*ESTIMATEMUONASYMMETRYFROMCOUNTSTEST_H_*/ diff --git a/Framework/Algorithms/test/MuonGroupDetectorsTest.h b/Framework/Algorithms/test/MuonGroupDetectorsTest.h deleted file mode 100644 index b59025c97719804a48a288349d16a781a8ef509c..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/MuonGroupDetectorsTest.h +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef MANTID_ALGORITHMS_MUONGROUPDETECTORSTEST_H_ -#define MANTID_ALGORITHMS_MUONGROUPDETECTORSTEST_H_ - -#include <cxxtest/TestSuite.h> - -#include "MantidAPI/TableRow.h" -#include "MantidAlgorithms/MuonGroupDetectors.h" -#include "MantidDataObjects/TableWorkspace.h" -#include "MantidTestHelpers/WorkspaceCreationHelper.h" - -using Mantid::Algorithms::MuonGroupDetectors; - -using namespace Mantid; -using namespace Mantid::Kernel; -using namespace Mantid::API; -using namespace Mantid::DataObjects; - -class MuonGroupDetectorsTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static MuonGroupDetectorsTest *createSuite() { - return new MuonGroupDetectorsTest(); - } - static void destroySuite(MuonGroupDetectorsTest *suite) { delete suite; } - - void test_Init() { - MuonGroupDetectors alg; - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) - } - - void test_exec() { - // Name of the output workspace. - const std::string outWSName("MuonGroupDetectorsTest_OutputWS"); - - MatrixWorkspace_sptr inWS = - WorkspaceCreationHelper::create2DWorkspace123(5, 3); - - for (size_t i = 0; i < inWS->getNumberHistograms(); ++i) - inWS->getSpectrum(i).setDetectorID(static_cast<detid_t>( - i + 1)); // To be consistent with how LoadMuonNexus works - - TableWorkspace_sptr grouping = createDetectorGroupingTable(); - - MuonGroupDetectors alg; - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) - TS_ASSERT_THROWS_NOTHING(alg.setProperty("InputWorkspace", inWS)); - TS_ASSERT_THROWS_NOTHING( - alg.setProperty("DetectorGroupingTable", grouping)); - TS_ASSERT_THROWS_NOTHING( - alg.setPropertyValue("OutputWorkspace", outWSName)); - TS_ASSERT_THROWS_NOTHING(alg.execute();); - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr ws; - TS_ASSERT_THROWS_NOTHING( - ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( - outWSName)); - TS_ASSERT(ws); - - if (ws) { - TS_ASSERT_EQUALS(ws->getNumberHistograms(), 2); - TS_ASSERT_EQUALS(ws->blocksize(), 3); - - TS_ASSERT_EQUALS(ws->y(0)[0], 4); - TS_ASSERT_EQUALS(ws->y(1)[0], 6); - - TS_ASSERT_EQUALS(ws->x(0)[1], 2); - TS_ASSERT_EQUALS(ws->x(1)[1], 2); - - TS_ASSERT_DELTA(ws->e(0)[2], 4.243, 0.001); - TS_ASSERT_DELTA(ws->e(1)[2], 5.196, 0.001); - - TS_ASSERT_EQUALS(ws->getSpectrum(0).getSpectrumNo(), 1); - TS_ASSERT_EQUALS(ws->getSpectrum(1).getSpectrumNo(), 2); - - std::set<detid_t> d1; - d1.insert(1); - d1.insert(2); - TS_ASSERT_EQUALS(ws->getSpectrum(0).getDetectorIDs(), d1); - - std::set<detid_t> d2; - d2.insert(3); - d2.insert(4); - d2.insert(5); - TS_ASSERT_EQUALS(ws->getSpectrum(1).getDetectorIDs(), d2); - } - - // Remove workspace from the data service. - AnalysisDataService::Instance().remove(outWSName); - } - -private: - TableWorkspace_sptr createDetectorGroupingTable() { - auto t = boost::make_shared<TableWorkspace>(); - - t->addColumn("vector_int", "Detectors"); - - std::vector<int> group1; - group1.push_back(1); - group1.push_back(2); - TableRow row1 = t->appendRow(); - row1 << group1; - - std::vector<int> group2; - group2.push_back(3); - group2.push_back(4); - group2.push_back(5); - TableRow row2 = t->appendRow(); - row2 << group2; - - return t; - } -}; - -#endif /* MANTID_ALGORITHMS_MUONGROUPDETECTORSTEST_H_ */ diff --git a/Framework/Algorithms/test/PhaseQuadMuonTest.h b/Framework/Algorithms/test/PhaseQuadMuonTest.h deleted file mode 100644 index b95164aedea956c3eb1f8bd05a2ce0c26d55d2c0..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/PhaseQuadMuonTest.h +++ /dev/null @@ -1,345 +0,0 @@ -#ifndef MANTID_ALGORITHMS_PHASEQUADMUONTEST_H_ -#define MANTID_ALGORITHMS_PHASEQUADMUONTEST_H_ - -#include <math.h> - -#include <cxxtest/TestSuite.h> -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/Axis.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/Run.h" -#include "MantidAPI/TableRow.h" -#include "MantidDataObjects/TableWorkspace.h" - -using namespace Mantid::DataObjects; -using namespace Mantid::API; - -namespace { - -const int dead1 = 4; -const int dead2 = 12; - -void populatePhaseTableWithDeadDetectors(ITableWorkspace_sptr phaseTable, - const MatrixWorkspace_sptr ws) { - phaseTable->addColumn("int", "DetectprID"); - phaseTable->addColumn("double", "Asymmetry"); - phaseTable->addColumn("double", "phase"); - double asym(1.); - for (size_t i = 0; i < ws->getNumberHistograms(); i++) { - TableRow phaseRow1 = phaseTable->appendRow(); - if (i == dead1 || i == dead2) { - phaseRow1 << int(i) << 999. << 0.0; - } else { - phaseRow1 << int(i) << asym - << 2. * M_PI * double(i + 1) / - (1. + double(ws->getNumberHistograms())); - } - } -} -void populatePhaseTable(ITableWorkspace_sptr phaseTable, - std::vector<std::string> names, bool swap = false) { - phaseTable->addColumn("int", names[0]); - phaseTable->addColumn("double", names[1]); - phaseTable->addColumn("double", names[2]); - double asym(1.), phase(2.); - if (swap) { - std::swap(asym, phase); - } - for (int i = 0; i < 16; i++) { - TableRow phaseRow1 = phaseTable->appendRow(); - phaseRow1 << i << asym << phase; - TableRow phaseRow2 = phaseTable->appendRow(); - phaseRow2 << i << asym << phase; - } -} -void populatePhaseTable(ITableWorkspace_sptr phaseTable) { - populatePhaseTable(phaseTable, {"DetectorID", "Asymmetry", "Phase"}); -} - -IAlgorithm_sptr setupAlg(MatrixWorkspace_sptr m_loadedData, bool isChildAlg, - ITableWorkspace_sptr phaseTable) { - // Set up PhaseQuad - IAlgorithm_sptr phaseQuad = AlgorithmManager::Instance().create("PhaseQuad"); - phaseQuad->setChild(isChildAlg); - phaseQuad->initialize(); - phaseQuad->setProperty("InputWorkspace", m_loadedData); - phaseQuad->setProperty("PhaseTable", phaseTable); - phaseQuad->setPropertyValue("OutputWorkspace", "outputWs"); - return phaseQuad; -} - -IAlgorithm_sptr setupAlg(MatrixWorkspace_sptr m_loadedData, bool isChildAlg) { - // Create and populate a detector table - boost::shared_ptr<ITableWorkspace> phaseTable( - new Mantid::DataObjects::TableWorkspace); - populatePhaseTable(phaseTable); - - return setupAlg(m_loadedData, isChildAlg, phaseTable); -} - -IAlgorithm_sptr setupAlg(MatrixWorkspace_sptr m_loadedData, bool isChildAlg, - std::vector<std::string> names, bool swap = false) { - // Create and populate a detector table - boost::shared_ptr<ITableWorkspace> phaseTable( - new Mantid::DataObjects::TableWorkspace); - populatePhaseTable(phaseTable, names, swap); - - return setupAlg(m_loadedData, isChildAlg, phaseTable); -} - -IAlgorithm_sptr setupAlgDead(MatrixWorkspace_sptr m_loadedData) { - // Create and populate a detector table - boost::shared_ptr<ITableWorkspace> phaseTable( - new Mantid::DataObjects::TableWorkspace); - populatePhaseTableWithDeadDetectors(phaseTable, m_loadedData); - - return setupAlg(m_loadedData, true, phaseTable); -} - -MatrixWorkspace_sptr setupWS(MatrixWorkspace_sptr m_loadedData) { - boost::shared_ptr<ITableWorkspace> phaseTable( - new Mantid::DataObjects::TableWorkspace); - MatrixWorkspace_sptr ws = m_loadedData->clone(); - // create toy data set - populatePhaseTableWithDeadDetectors(phaseTable, ws); - auto xData = ws->points(0); - for (size_t spec = 0; spec < ws->getNumberHistograms(); spec++) { - for (size_t j = 0; j < xData.size(); j++) { - if (spec == dead1 || spec == dead2) { - ws->mutableY(spec)[j] = 0.0; - ws->mutableE(spec)[j] = 0.0; - } else { - ws->mutableY(spec)[j] = - sin(2.3 * xData[j] + phaseTable->Double(spec, 2)) * - exp(-xData[j] / 2.19703); - ws->mutableE(spec)[j] = cos(0.2 * xData[j]); - } - } - } - return ws; -} - -MatrixWorkspace_sptr loadMuonDataset() { - IAlgorithm_sptr loader = AlgorithmManager::Instance().create("Load"); - loader->setChild(true); - loader->initialize(); - loader->setProperty("Filename", "emu00006473.nxs"); - loader->setPropertyValue("OutputWorkspace", "outputWs"); - loader->execute(); - Workspace_sptr temp = loader->getProperty("OutputWorkspace"); - MatrixWorkspace_sptr m_loadedData = - boost::dynamic_pointer_cast<MatrixWorkspace>(temp); - return m_loadedData; -} -} - -class PhaseQuadMuonTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static PhaseQuadMuonTest *createSuite() { return new PhaseQuadMuonTest(); } - - static void destroySuite(PhaseQuadMuonTest *suite) { delete suite; } - - void setUp() override { - if (!m_loadedData) { - m_loadedData = loadMuonDataset(); - } - } - - void testTheBasics() { - IAlgorithm_sptr phaseQuad = - AlgorithmManager::Instance().create("PhaseQuad"); - TS_ASSERT_EQUALS(phaseQuad->name(), "PhaseQuad"); - TS_ASSERT_EQUALS(phaseQuad->category(), "Muon"); - TS_ASSERT_THROWS_NOTHING(phaseQuad->initialize()); - TS_ASSERT(phaseQuad->isInitialized()); - } - void testDead() { - MatrixWorkspace_sptr ws = setupWS(m_loadedData); - size_t nspec = ws->getNumberHistograms(); - // check got some dead detectors - std::vector<bool> emptySpectrum; - for (size_t h = 0; h < nspec; h++) { - emptySpectrum.push_back( - std::all_of(ws->y(h).begin(), ws->y(h).end(), - [](double value) { return value == 0.; })); - } - for (size_t j = 0; j < emptySpectrum.size(); j++) { - if (j == dead1 || j == dead2) { - TS_ASSERT(emptySpectrum[j]); - } else { - TS_ASSERT(!emptySpectrum[j]); - } - } - // do phase Quad - IAlgorithm_sptr phaseQuad = setupAlgDead(ws); - TS_ASSERT_THROWS_NOTHING(phaseQuad->execute()); - TS_ASSERT(phaseQuad->isExecuted()); - - // Get the output ws - MatrixWorkspace_sptr outputWs = phaseQuad->getProperty("OutputWorkspace"); - - TS_ASSERT_EQUALS(outputWs->getNumberHistograms(), 2); - TS_ASSERT_EQUALS( - outputWs->getSpectrum(0).readX(), - m_loadedData->getSpectrum(0).readX()); // Check outputWs X values - TS_ASSERT_EQUALS(outputWs->getSpectrum(1).readX(), - m_loadedData->getSpectrum(1).readX()); - // Check output log is not empty - TS_ASSERT(outputWs->mutableRun().getLogData().size() > 0); - - const auto specReY = outputWs->getSpectrum(0).y(); - const auto specReE = outputWs->getSpectrum(0).e(); - const auto specImY = outputWs->getSpectrum(1).y(); - const auto specImE = outputWs->getSpectrum(1).e(); - // Check real Y values - TS_ASSERT_DELTA(specReY[0], -0.6149, 0.0001); - TS_ASSERT_DELTA(specReY[20], 0.2987, 0.0001); - TS_ASSERT_DELTA(specReY[50], 1.2487, 0.0001); - // Check real E values - TS_ASSERT_DELTA(specReE[0], 0.2927, 0.0001); - TS_ASSERT_DELTA(specReE[20], 0.31489, 0.0001); - TS_ASSERT_DELTA(specReE[50], 0.3512, 0.0001); - // Check imaginary Y values - TS_ASSERT_DELTA(specImY[0], 1.0823, 0.0001); - TS_ASSERT_DELTA(specImY[20], 1.3149, 0.0001); - TS_ASSERT_DELTA(specImY[50], 0.4965, 0.0001); - // Check imaginary E values - TS_ASSERT_DELTA(specImE[0], 0.2801, 0.0001); - TS_ASSERT_DELTA(specImE[20], 0.3013, 0.0001); - TS_ASSERT_DELTA(specImE[50], 0.3360, 0.0001); - } - void testExecPhaseTable() { - IAlgorithm_sptr phaseQuad = setupAlg(m_loadedData, true); - TS_ASSERT_THROWS_NOTHING(phaseQuad->execute()); - TS_ASSERT(phaseQuad->isExecuted()); - - // Get the output ws - MatrixWorkspace_sptr outputWs = phaseQuad->getProperty("OutputWorkspace"); - - TS_ASSERT_EQUALS(outputWs->getNumberHistograms(), 2); - TS_ASSERT_EQUALS( - outputWs->getSpectrum(0).readX(), - m_loadedData->getSpectrum(0).readX()); // Check outputWs X values - TS_ASSERT_EQUALS(outputWs->getSpectrum(1).readX(), - m_loadedData->getSpectrum(1).readX()); - // Check output log is not empty - TS_ASSERT(outputWs->mutableRun().getLogData().size() > 0); - - const auto specReY = outputWs->getSpectrum(0).y(); - const auto specReE = outputWs->getSpectrum(0).e(); - const auto specImY = outputWs->getSpectrum(1).y(); - const auto specImE = outputWs->getSpectrum(1).e(); - // Check real Y values - TS_ASSERT_DELTA(specReY[0], 2.1969, 0.0001); - TS_ASSERT_DELTA(specReY[20], 0.0510, 0.0001); - TS_ASSERT_DELTA(specReY[50], -0.0525, 0.0001); - // Check real E values - TS_ASSERT_DELTA(specReE[0], 0.0024, 0.0001); - TS_ASSERT_DELTA(specReE[20], 0.0041, 0.0001); - TS_ASSERT_DELTA(specReE[50], 0.0047, 0.0001); - // Check imaginary Y values - TS_ASSERT_DELTA(specImY[0], -0.1035, 0.0001); - TS_ASSERT_DELTA(specImY[20], -0.0006, 0.0001); - TS_ASSERT_DELTA(specImY[50], 0.0047, 0.0001); - // Check imaginary E values - TS_ASSERT_DELTA(specImE[0], 0.0002, 0.0001); - TS_ASSERT_DELTA(specImE[20], 0.0004, 0.0001); - TS_ASSERT_DELTA(specImE[50], 0.0005, 0.0001); - } - void testNoPhase() { - std::vector<std::string> names = {"ID", "Asym", "dummy"}; - IAlgorithm_sptr phaseQuad = setupAlg(m_loadedData, true, names); - TS_ASSERT_THROWS(phaseQuad->execute(), std::runtime_error); - } - void testNoAsymm() { - std::vector<std::string> names = {"ID", "AsYMg", "phase"}; - MatrixWorkspace_sptr m_loadedData = loadMuonDataset(); - IAlgorithm_sptr phaseQuad = setupAlg(m_loadedData, true, names); - TS_ASSERT_THROWS(phaseQuad->execute(), std::runtime_error); - } - void testTwoPhases() { - std::vector<std::string> names = {"ID", "Phase", "phi"}; - IAlgorithm_sptr phaseQuad = setupAlg(m_loadedData, true, names); - TS_ASSERT_THROWS(phaseQuad->execute(), std::runtime_error); - } - void testTwoAsymm() { - std::vector<std::string> names = {"ID", "Asym", "Asymm"}; - IAlgorithm_sptr phaseQuad = setupAlg(m_loadedData, true, names); - TS_ASSERT_THROWS(phaseQuad->execute(), std::runtime_error); - } - void testSwapOrder() { - std::vector<std::string> names = {"ID", "phase", "Asymm"}; - IAlgorithm_sptr phaseQuad = setupAlg(m_loadedData, true, names, true); - TS_ASSERT_THROWS_NOTHING(phaseQuad->execute()); - TS_ASSERT(phaseQuad->isExecuted()); - - // Get the output ws - MatrixWorkspace_sptr outputWs = phaseQuad->getProperty("OutputWorkspace"); - - TS_ASSERT_EQUALS(outputWs->getNumberHistograms(), 2); - TS_ASSERT_EQUALS( - outputWs->getSpectrum(0).readX(), - m_loadedData->getSpectrum(0).readX()); // Check outputWs X values - TS_ASSERT_EQUALS(outputWs->getSpectrum(1).readX(), - m_loadedData->getSpectrum(1).readX()); - - const auto specReY = outputWs->getSpectrum(0).y(); - const auto specReE = outputWs->getSpectrum(0).e(); - const auto specImY = outputWs->getSpectrum(1).y(); - const auto specImE = outputWs->getSpectrum(1).e(); - // Check real Y values - TS_ASSERT_DELTA(specReY[0], 2.1969, 0.0001); - TS_ASSERT_DELTA(specReY[20], 0.0510, 0.0001); - TS_ASSERT_DELTA(specReY[50], -0.0525, 0.0001); - // Check real E values - TS_ASSERT_DELTA(specReE[0], 0.0024, 0.0001); - TS_ASSERT_DELTA(specReE[20], 0.0041, 0.0001); - TS_ASSERT_DELTA(specReE[50], 0.0047, 0.0001); - // Check imaginary Y values - TS_ASSERT_DELTA(specImY[0], -0.1035, 0.0001); - TS_ASSERT_DELTA(specImY[20], -0.0006, 0.0001); - TS_ASSERT_DELTA(specImY[50], 0.0047, 0.0001); - // Check imaginary E values - TS_ASSERT_DELTA(specImE[0], 0.0002, 0.0001); - TS_ASSERT_DELTA(specImE[20], 0.0004, 0.0001); - TS_ASSERT_DELTA(specImE[50], 0.0005, 0.0001); - } - // add test for different order - -private: - MatrixWorkspace_sptr m_loadedData; -}; - -class PhaseQuadMuonTestPerformance : public CxxTest::TestSuite { - -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static PhaseQuadMuonTestPerformance *createSuite() { - return new PhaseQuadMuonTestPerformance(); - } - - static void destroySuite(PhaseQuadMuonTestPerformance *suite) { - delete suite; - } - - void setUp() override { - m_loadedData = loadMuonDataset(); - phaseQuad = setupAlg(m_loadedData, false); - } - - void tearDown() override { - Mantid::API::AnalysisDataService::Instance().remove("outputWs"); - } - - void testPerformanceWs() { phaseQuad->execute(); } - -private: - MatrixWorkspace_sptr m_loadedData; - IAlgorithm_sptr phaseQuad; -}; - -#endif /* MANTID_ALGORITHMS_PHASEQUADMUONTEST_H_ */ diff --git a/Framework/Algorithms/test/PlotAsymmetryByLogValueTest.h b/Framework/Algorithms/test/PlotAsymmetryByLogValueTest.h deleted file mode 100644 index f6421e330654c235dc8cb2938aa8823b9118f823..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/PlotAsymmetryByLogValueTest.h +++ /dev/null @@ -1,621 +0,0 @@ -#ifndef PLOTASYMMETRYBYLOGVALUTEST_H_ -#define PLOTASYMMETRYBYLOGVALUTEST_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidAlgorithms/PlotAsymmetryByLogValue.h" -#include "MantidDataObjects/Workspace2D.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/TextAxis.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/TableRow.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataHandling/LoadMuonNexus.h" -#include "MantidDataHandling/LoadInstrument.h" -#include "MantidDataHandling/SaveNexus.h" - -#include <Poco/File.h> -#include <Poco/NObserver.h> -#include <Poco/TemporaryFile.h> - -using namespace Mantid::API; -using namespace Mantid::Algorithms; -using namespace Mantid::DataObjects; -using namespace Mantid::DataHandling; - -/// RAII class to temporarily rename a file for the duration of a test -/// Original name is restored on destruction. -class TemporaryRenamer { -public: - /// Constructor: rename the file and store its original name - explicit TemporaryRenamer(const std::string &fileName) - : m_originalName(fileName) { - try { - Poco::File file(m_originalName); - TS_ASSERT(file.exists() && file.canWrite() && file.isFile()); - m_tempName = Poco::TemporaryFile::tempName(); - file.copyTo(m_tempName); - file.remove(); - } catch (const Poco::FileException &ex) { - failCopyWithError(m_originalName, m_tempName, ex); - } - } - /// Destructor: restore the file's original name - ~TemporaryRenamer() { - try { - Poco::File file(m_tempName); - file.copyTo(m_originalName); - file.remove(); - } catch (const Poco::FileException &ex) { // Do not throw in the destructor! - failCopyWithError(m_tempName, m_originalName, ex); - } - } - /// Fail with an error - void failCopyWithError(const std::string &from, const std::string &to, - const Poco::FileException &error) const { - std::ostringstream message; - message << "Failed to copy " << from << " to " << to << ": " - << error.displayText(); - TS_FAIL(message.str()); - } - -private: - const std::string m_originalName; - std::string m_tempName; -}; - -/// Class to count number of progress reports given out by an algorithm -class ProgressWatcher { -public: - /// Constructor - ProgressWatcher() - : m_loadedCount(0), m_foundCount(0), - m_observer(*this, &ProgressWatcher::handleProgress) {} - /// Add a notification to the count - void handleProgress(const Poco::AutoPtr< - Mantid::API::Algorithm::ProgressNotification> ¬ification) { - const auto &message = notification->message; - if (0 == message.compare(0, 5, "Found")) { - ++m_foundCount; - } else if (0 == message.compare(0, 6, "Loaded")) { - ++m_loadedCount; - } - } - /// Return the number of "found" progress reports seen so far - size_t getFoundCount() { return m_foundCount; } - /// Return the number of "loaded" progress reports seen so far - size_t getLoadedCount() { return m_loadedCount; } - /// Getter for the observer - Poco::NObserver<ProgressWatcher, Mantid::API::Algorithm::ProgressNotification> - getObserver() { - return m_observer; - } - -private: - /// Count of "file loaded" progress reports seen so far - size_t m_loadedCount; - /// Count of "file found" progress reports seen so far - size_t m_foundCount; - /// Observer - Poco::NObserver<ProgressWatcher, Mantid::API::Algorithm::ProgressNotification> - m_observer; -}; - -class PlotAsymmetryByLogValueTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static PlotAsymmetryByLogValueTest *createSuite() { - return new PlotAsymmetryByLogValueTest(); - } - static void destroySuite(PlotAsymmetryByLogValueTest *suite) { delete suite; } - PlotAsymmetryByLogValueTest() - : firstRun("MUSR00015189.nxs"), lastRun("MUSR00015190.nxs") {} - - /// Clear the ADS at the end of every test - void tearDown() override { AnalysisDataService::Instance().clear(); } - - void testExec() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "Field_Danfysik"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve( - "PlotAsymmetryByLogValueTest_WS")); - - TS_ASSERT(outWS); - TS_ASSERT_EQUALS(outWS->blocksize(), 2); - TS_ASSERT_EQUALS(outWS->getNumberHistograms(), 4); - const auto Y = outWS->y(0); - TS_ASSERT_DELTA(Y[0], 0.0128845, 0.001); - TS_ASSERT_DELTA(Y[1], 0.0224898, 0.00001); - - const TextAxis *axis = dynamic_cast<const TextAxis *>(outWS->getAxis(1)); - TS_ASSERT(axis); - if (axis) { - TS_ASSERT_EQUALS(axis->length(), 4); - TS_ASSERT_EQUALS(axis->label(0), "Red-Green"); - TS_ASSERT_EQUALS(axis->label(1), "Red"); - TS_ASSERT_EQUALS(axis->label(2), "Green"); - TS_ASSERT_EQUALS(axis->label(3), "Red+Green"); - } - } - - void testDifferential() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "Field_Danfysik"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - alg.setPropertyValue("Type", "Differential"); - - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve( - "PlotAsymmetryByLogValueTest_WS")); - - TS_ASSERT(outWS); - TS_ASSERT_EQUALS(outWS->blocksize(), 2); - TS_ASSERT_EQUALS(outWS->getNumberHistograms(), 4); - const auto Y = outWS->y(0); - TS_ASSERT_DELTA(Y[0], -0.01236, 0.001); - TS_ASSERT_DELTA(Y[1], 0.019186, 0.00001); - } - - void test_int_log() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "nspectra"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - alg.execute(); - - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve( - "PlotAsymmetryByLogValueTest_WS")); - - TS_ASSERT(outWS); - } - - void test_string_log() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "run_number"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - alg.execute(); - - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve( - "PlotAsymmetryByLogValueTest_WS")); - - TS_ASSERT(outWS); - } - - void test_text_log() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "run_title"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - alg.execute(); - - TS_ASSERT(!alg.isExecuted()); - } - - void test_DeadTimeCorrection_FromSpecifiedFile() { - const std::string ws = "Ws"; - const std::string deadTimeWs = "DeadTimeWs"; - const std::string deadTimeFile = "TestDeadTimeFile.nxs"; - - ITableWorkspace_sptr deadTimeTable = - Mantid::API::WorkspaceFactory::Instance().createTable("TableWorkspace"); - deadTimeTable->addColumn("int", "spectrum"); - deadTimeTable->addColumn("double", "dead-time"); - - for (int i = 0; i < 64; i++) { - TableRow row = deadTimeTable->appendRow(); - row << (i + 1) << 0.015; - } - - AnalysisDataService::Instance().addOrReplace(deadTimeWs, deadTimeTable); - - // Save dead time table to file - SaveNexus saveNexusAlg; - TS_ASSERT_THROWS_NOTHING(saveNexusAlg.initialize()); - saveNexusAlg.setPropertyValue("InputWorkspace", deadTimeWs); - saveNexusAlg.setPropertyValue("Filename", deadTimeFile); - TS_ASSERT_THROWS_NOTHING(saveNexusAlg.execute()); - TS_ASSERT(saveNexusAlg.isExecuted()); - - PlotAsymmetryByLogValue alg; - - TS_ASSERT_THROWS_NOTHING(alg.initialize()); - - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", ws); - alg.setPropertyValue("LogValue", "run_number"); - alg.setPropertyValue("DeadTimeCorrType", "FromSpecifiedFile"); - alg.setPropertyValue("DeadTimeCorrFile", deadTimeFile); - - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - if (!alg.isExecuted()) - return; - - MatrixWorkspace_sptr outWs = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve(ws)); - - TS_ASSERT(outWs); - TS_ASSERT_EQUALS(outWs->blocksize(), 2); - TS_ASSERT_EQUALS(outWs->getNumberHistograms(), 1); - - const auto Y = outWs->y(0); - - TS_ASSERT_DELTA(Y[0], 0.15214, 0.00001); - TS_ASSERT_DELTA(Y[1], 0.14492, 0.00001); - Poco::File(deadTimeFile).remove(); - } - - void test_DeadTimeCorrection_FromRunData() { - const std::string ws = "Test_DeadTimeCorrection_FromRunData_Ws"; - - PlotAsymmetryByLogValue alg; - - TS_ASSERT_THROWS_NOTHING(alg.initialize()); - - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", ws); - alg.setPropertyValue("LogValue", "run_number"); - alg.setPropertyValue("DeadTimeCorrType", "FromRunData"); - - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - if (!alg.isExecuted()) - return; - - MatrixWorkspace_sptr outWs = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve(ws)); - - TS_ASSERT(outWs); - TS_ASSERT_EQUALS(outWs->blocksize(), 2); - TS_ASSERT_EQUALS(outWs->getNumberHistograms(), 1); - - const auto Y = outWs->y(0); - - TS_ASSERT_DELTA(Y[0], 0.151202, 0.00001); - TS_ASSERT_DELTA(Y[1], 0.144008, 0.00001); - } - - void test_customGrouping() { - PlotAsymmetryByLogValue alg; - - TS_ASSERT_THROWS_NOTHING(alg.initialize()); - - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "run_number"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - alg.setPropertyValue("ForwardSpectra", "1-16,33-48"); - alg.setPropertyValue("BackwardSpectra", "17-32,49-64"); - alg.setPropertyValue("DeadTimeCorrType", "None"); - - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - if (!alg.isExecuted()) - return; - - MatrixWorkspace_sptr outWs = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve( - "PlotAsymmetryByLogValueTest_WS")); - - TS_ASSERT(outWs); - TS_ASSERT_EQUALS(outWs->blocksize(), 2); - TS_ASSERT_EQUALS(outWs->getNumberHistograms(), 4); - - const auto YDiff = outWs->y(0); - const auto EDiff = outWs->e(0); - const auto YSum = outWs->y(3); - const auto ESum = outWs->e(3); - - TS_ASSERT_DELTA(YDiff[0], 0.001135, 0.000001); - TS_ASSERT_DELTA(EDiff[0], 0.001805, 0.000001); - TS_ASSERT_DELTA(YDiff[1], -0.000151, 0.000001); - TS_ASSERT_DELTA(EDiff[1], 0.001806, 0.000001); - - TS_ASSERT_DELTA(YSum[0], 0.170842, 0.000001); - TS_ASSERT_DELTA(ESum[0], 0.001805, 0.000001); - TS_ASSERT_DELTA(YSum[1], 0.171467, 0.000001); - TS_ASSERT_DELTA(ESum[1], 0.001806, 0.000001); - } - - void test_customTimeLimits() { - const std::string ws = "Test_customTimeLimits"; - - PlotAsymmetryByLogValue alg; - - TS_ASSERT_THROWS_NOTHING(alg.initialize()); - - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", ws); - alg.setPropertyValue("LogValue", "run_number"); - alg.setPropertyValue("TimeMin", "0.5"); - alg.setPropertyValue("TimeMax", "0.6"); - - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWs = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve(ws)); - - TS_ASSERT(outWs); - TS_ASSERT_EQUALS(outWs->blocksize(), 2); - TS_ASSERT_EQUALS(outWs->getNumberHistograms(), 1); - - const auto Y = outWs->y(0); - TS_ASSERT_DELTA(Y[0], 0.14700, 0.00001); - TS_ASSERT_DELTA(Y[1], 0.13042, 0.00001); - } - - void test_LogValueFunction() { - const std::string ws = "Test_LogValueFunction"; - - PlotAsymmetryByLogValue alg; - - TS_ASSERT_THROWS_NOTHING(alg.initialize()); - - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", ws); - // We use 'beamlog_current' as log value because - // we want to test the 'Mean' function below and this is - // one of the few properties that contains different values over time - alg.setPropertyValue("LogValue", "beamlog_current"); - alg.setPropertyValue("Function", "Mean"); - alg.setPropertyValue("DeadTimeCorrType", "None"); - - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWs = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve(ws)); - - TS_ASSERT(outWs); - TS_ASSERT_EQUALS(outWs->blocksize(), 2); - TS_ASSERT_EQUALS(outWs->getNumberHistograms(), 1); - - // Now we want to test X values (log values) in the output workspace - // rather than asymmetry (Y values) - const auto X = outWs->x(0); - - TS_ASSERT_DELTA(X[0], 178.740476, 0.00001); - TS_ASSERT_DELTA(X[1], 178.849998, 0.00001); - } - - void test_invalidRunNumbers() { - const std::string ws = "Test_LogValueFunction"; - - PlotAsymmetryByLogValue alg; - - TS_ASSERT_THROWS_NOTHING(alg.initialize()); - - alg.setPropertyValue("FirstRun", lastRun); - alg.setPropertyValue("LastRun", firstRun); - alg.setPropertyValue("OutputWorkspace", ws); - - TS_ASSERT_THROWS(alg.execute(), std::runtime_error); - TS_ASSERT(!alg.isExecuted()); - } - - void test_singlePeriodGreen() { - // Load a single-period dataset and set the green period to a - // number. The algorithm should ignore the supplied green and/or red periods - // as the input nexus file is single-period - const std::string ws = "Test_singlePeriodGreen"; - PlotAsymmetryByLogValue alg; - alg.initialize(); - alg.setPropertyValue("FirstRun", "emu00006473.nxs"); - alg.setPropertyValue("LastRun", "emu00006473.nxs"); - alg.setPropertyValue("OutputWorkspace", ws); - alg.setPropertyValue("LogValue", "run_number"); - alg.setPropertyValue("Red", "3"); - alg.setPropertyValue("Green", "1"); - - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve(ws)); - - TS_ASSERT(outWS); - TS_ASSERT_EQUALS(outWS->blocksize(), 1); - TS_ASSERT_EQUALS(outWS->getNumberHistograms(), 1); - - TS_ASSERT_EQUALS(outWS->x(0)[0], 6473); - TS_ASSERT_DELTA(outWS->y(0)[0], 0.283444, 0.000001); - TS_ASSERT_DELTA(outWS->e(0)[0], 0.000145, 0.000001); - } - - void test_run_start_log() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "run_start"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - TS_ASSERT_THROWS_NOTHING(alg.execute()); - - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve( - "PlotAsymmetryByLogValueTest_WS")); - - TS_ASSERT(outWS); - - const auto outputX = outWS->points(0); - TS_ASSERT_EQUALS(outputX.size(), 2); - // Zero = start time of first run (17:10:35) - TS_ASSERT_DELTA(outputX[0], 0.0, 1.e-7); - // 17:10:35 to 17:12:30 is 115 seconds - TS_ASSERT_DELTA(outputX[1], 115.0, 1.e-7); - } - - void test_run_end_log() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "run_end"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - TS_ASSERT_THROWS_NOTHING(alg.execute()); - - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve( - "PlotAsymmetryByLogValueTest_WS")); - - TS_ASSERT(outWS); - - const auto outputX = outWS->points(0); - TS_ASSERT_EQUALS(outputX.size(), 2); - // Zero = start time of first run (17:10:35) - // 17:10:35 to 17:12:16 is 101 seconds - TS_ASSERT_DELTA(outputX[0], 101.0, 1.e-7); - // 17:10:35 to 17:14:10 is 215 seconds - TS_ASSERT_DELTA(outputX[1], 215.0, 1.e-7); - } - - void test_skip_missing_file() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - - alg.setPropertyValue("FirstRun", "MUSR00015193.nxs"); - alg.setPropertyValue("LastRun", "MUSR00015195.nxs"); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "run_number"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - - MatrixWorkspace_sptr outWS = boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve( - "PlotAsymmetryByLogValueTest_WS")); - TS_ASSERT(outWS); - const auto &outputX = outWS->points(0); - TS_ASSERT_EQUALS(outputX.size(), 2); - TS_ASSERT_DELTA(outputX[0], 15193.0, 1.e-7); - TS_ASSERT_DELTA(outputX[1], 15195.0, 1.e-7); - } - - void test_extend_run_sequence() { - PlotAsymmetryByLogValue alg; - alg.initialize(); - - // Watch for the algorithm's progress reports as it loads each file - ProgressWatcher watcher; - alg.addObserver(watcher.getObserver()); - - // Load the first two runs - alg.setPropertyValue("FirstRun", "MUSR00015189.nxs"); - alg.setPropertyValue("LastRun", "MUSR00015190.nxs"); - alg.setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueTest_WS"); - alg.setPropertyValue("LogValue", "run_number"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - TS_ASSERT_EQUALS(watcher.getLoadedCount(), 2); - TS_ASSERT_EQUALS(watcher.getFoundCount(), 0); - - // Now extend the run sequence with an extra run - alg.setPropertyValue("LastRun", "MUSR00015191.nxs"); - TS_ASSERT_THROWS_NOTHING(alg.execute()); - TS_ASSERT(alg.isExecuted()); - TS_ASSERT_EQUALS(watcher.getLoadedCount(), 3); // i.e. not 5 loads - TS_ASSERT_EQUALS(watcher.getFoundCount(), 2); // reused 2 - } - -private: - std::string firstRun, lastRun; -}; - -class PlotAsymmetryByLogValueTestPerformance : public CxxTest::TestSuite { - -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static PlotAsymmetryByLogValueTestPerformance *createSuite() { - return new PlotAsymmetryByLogValueTestPerformance(); - } - - static void destroySuite(PlotAsymmetryByLogValueTestPerformance *suite) { - delete suite; - } - - PlotAsymmetryByLogValueTestPerformance() - : firstRun("MUSR00015189.nxs"), lastRun("MUSR00015190.nxs") {} - - void setUp() override { - alg.initialize(); - alg.setPropertyValue("FirstRun", firstRun); - alg.setPropertyValue("LastRun", lastRun); - alg.setPropertyValue("OutputWorkspace", "outputWS"); - alg.setPropertyValue("LogValue", "Field_Danfysik"); - alg.setPropertyValue("Red", "2"); - alg.setPropertyValue("Green", "1"); - } - - void tearDown() override { - Mantid::API::AnalysisDataService::Instance().remove("outputWS"); - } - - void testPerformanceWS() { alg.execute(); } - -private: - PlotAsymmetryByLogValue alg; - std::string firstRun, lastRun; -}; - -#endif /*PLOTASYMMETRYBYLOGVALUTEST_H_*/ diff --git a/Framework/Algorithms/test/RRFMuonTest.h b/Framework/Algorithms/test/RRFMuonTest.h deleted file mode 100644 index bd8deab5baf0b9cce469eb78bf6646e1ce91cd76..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/RRFMuonTest.h +++ /dev/null @@ -1,210 +0,0 @@ -#ifndef MANTID_ALGORITHMS_RRFMUON_H_ -#define MANTID_ALGORITHMS_RRFMUON_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidAlgorithms/RRFMuon.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/Axis.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidKernel/UnitFactory.h" -#include "MantidTestHelpers/HistogramDataTestHelper.h" - -using namespace Mantid::Algorithms; -using namespace Mantid::API; - -class RRFMuonTest : public CxxTest::TestSuite { -public: - void testName() { TS_ASSERT_EQUALS(rrfMuon.name(), "RRFMuon"); } - - void testCategory() { TS_ASSERT_EQUALS(rrfMuon.category(), "Muon") } - - void testRRFMuonZeroFrequency() { - // Test of the algorithm at zero frequency - // At zero frequency input and output workspaces should contain the same X, - // Y data - - // Create input workspace with three spectra - MatrixWorkspace_sptr ws = createDummyWorkspace(); - - // Initialise - TS_ASSERT_THROWS_NOTHING(rrfMuon.initialize()); - TS_ASSERT(rrfMuon.isInitialized()); - // Set Values - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("InputWorkspace", ws)); - TS_ASSERT_THROWS_NOTHING( - rrfMuon.setProperty("OutputWorkspace", "outputWs")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("Frequency", "0")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("FrequencyUnits", "MHz")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("Phase", "0")); - // Execute - TS_ASSERT_THROWS_NOTHING(rrfMuon.execute()); - TS_ASSERT(rrfMuon.isExecuted()); - // Get result - MatrixWorkspace_const_sptr ows = - boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve("outputWs")); - TS_ASSERT(ows); - - // Checks - // X values - TS_ASSERT_EQUALS(ws->x(0), ows->x(0)); - TS_ASSERT_EQUALS(ws->x(1), ows->x(1)); - // Y values - TS_ASSERT_EQUALS(ws->y(0), ows->y(0)); - TS_ASSERT_EQUALS(ws->y(1), ows->y(1)); - } - - void testRRFMuonNonZeroFrequency() { - // Test of the algorithm at non-zero frequency - - // Create input workspace with three spectra - MatrixWorkspace_sptr ws = createDummyWorkspace(); - - // Initialise - TS_ASSERT_THROWS_NOTHING(rrfMuon.initialize()); - TS_ASSERT(rrfMuon.isInitialized()); - // Set Values - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("InputWorkspace", ws)); - TS_ASSERT_THROWS_NOTHING( - rrfMuon.setProperty("OutputWorkspace", "outputWs")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("Frequency", "1")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("FrequencyUnits", "MHz")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("Phase", "0")); - // Execute - TS_ASSERT_THROWS_NOTHING(rrfMuon.execute()); - TS_ASSERT(rrfMuon.isExecuted()); - // Get result - MatrixWorkspace_const_sptr ows = - boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve("outputWs")); - TS_ASSERT(ows); - - // Checks - // X values - TS_ASSERT_EQUALS(ws->x(0), ows->x(0)); - TS_ASSERT_EQUALS(ws->x(1), ows->x(1)); - // Y values - // The input frequency is close to the precession frequency, so: - // The real part of the RRF polarization should be close to 1 for all X - // values - // The imaginary part should be close to 0 for all X values - TS_ASSERT_DELTA(ows->y(0)[0], 1, 0.001); - TS_ASSERT_DELTA(ows->y(0)[100], 1, 0.001); - TS_ASSERT_DELTA(ows->y(0)[200], 1, 0.001); - TS_ASSERT_DELTA(ows->y(1)[0], 0, 0.001); - TS_ASSERT_DELTA(ows->y(1)[100], 0, 0.001); - TS_ASSERT_DELTA(ows->y(1)[200], 0, 0.001); - } - - void testRRFMuonUnits() { - // Test of the algorithm at non-zero frequency - - // Create input workspace with three spectra - MatrixWorkspace_sptr ws = createDummyWorkspace(); - - // Initialise - TS_ASSERT_THROWS_NOTHING(rrfMuon.initialize()); - TS_ASSERT_THROWS_NOTHING(rrfMuon2.initialize()); - TS_ASSERT_THROWS_NOTHING(rrfMuon3.initialize()); - TS_ASSERT(rrfMuon.isInitialized()); - TS_ASSERT(rrfMuon2.isInitialized()); - TS_ASSERT(rrfMuon3.isInitialized()); - // Set Values - // First run - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("InputWorkspace", ws)); - TS_ASSERT_THROWS_NOTHING( - rrfMuon.setProperty("OutputWorkspace", "outputWs1")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("Frequency", "1")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("FrequencyUnits", "MHz")); - TS_ASSERT_THROWS_NOTHING(rrfMuon.setProperty("Phase", "0")); - // Second run - TS_ASSERT_THROWS_NOTHING(rrfMuon2.setProperty("InputWorkspace", ws)); - TS_ASSERT_THROWS_NOTHING( - rrfMuon2.setProperty("OutputWorkspace", "outputWs2")); - TS_ASSERT_THROWS_NOTHING(rrfMuon2.setProperty("Frequency", "0.159155")); - TS_ASSERT_THROWS_NOTHING(rrfMuon2.setProperty("FrequencyUnits", "Mrad/s")); - TS_ASSERT_THROWS_NOTHING(rrfMuon2.setProperty("Phase", "0")); - // Third run - TS_ASSERT_THROWS_NOTHING(rrfMuon3.setProperty("InputWorkspace", ws)); - TS_ASSERT_THROWS_NOTHING( - rrfMuon3.setProperty("OutputWorkspace", "outputWs3")); - TS_ASSERT_THROWS_NOTHING(rrfMuon3.setProperty("Frequency", "11.742398")); - TS_ASSERT_THROWS_NOTHING(rrfMuon3.setProperty("FrequencyUnits", "Gauss")); - TS_ASSERT_THROWS_NOTHING(rrfMuon3.setProperty("Phase", "0")); - // Execute all of them - TS_ASSERT_THROWS_NOTHING(rrfMuon.execute()); - TS_ASSERT_THROWS_NOTHING(rrfMuon2.execute()); - TS_ASSERT_THROWS_NOTHING(rrfMuon3.execute()); - TS_ASSERT(rrfMuon.isExecuted()); - TS_ASSERT(rrfMuon2.isExecuted()); - TS_ASSERT(rrfMuon3.isExecuted()); - // Get results - MatrixWorkspace_const_sptr ows1 = - boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve("outputWs1")); - TS_ASSERT(ows1); - MatrixWorkspace_const_sptr ows2 = - boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve("outputWs2")); - TS_ASSERT(ows2); - MatrixWorkspace_const_sptr ows3 = - boost::dynamic_pointer_cast<MatrixWorkspace>( - AnalysisDataService::Instance().retrieve("outputWs3")); - TS_ASSERT(ows3); - - // Check Y values - // ows1 vs ows2 - // Results with different frequency units should be very similar - TS_ASSERT_DELTA(ows1->y(0)[5], ows2->y(0)[5], 0.000001); - TS_ASSERT_DELTA(ows1->y(0)[98], ows2->y(0)[98], 0.000001); - TS_ASSERT_DELTA(ows1->y(0)[276], ows2->y(0)[276], 0.000001); - // But not exactly the same - // (They should only be the same if the input frequency in rrfMuon2 were - // exactly 1/2/M_PI) - TS_ASSERT_DIFFERS(ows1->y(0)[5], ows2->y(0)[5]); - TS_ASSERT_DIFFERS(ows1->y(0)[98], ows2->y(0)[98]); - TS_ASSERT_DIFFERS(ows1->y(0)[276], ows2->y(0)[276]); - // ows1 vs ows3 - // Results with different frequency units should be very similar - TS_ASSERT_DELTA(ows1->y(0)[8], ows3->y(0)[8], 0.000001); - TS_ASSERT_DELTA(ows1->y(0)[109], ows3->y(0)[109], 0.000001); - TS_ASSERT_DELTA(ows1->y(0)[281], ows3->y(0)[281], 0.000001); - // But not exactly the same - // (They should only be the same if the input frequency in rrfMuon3 were - // exactly 1/2/M_PI/MU - // being MU the muon gyromagnetic ratio) - TS_ASSERT_DIFFERS(ows1->y(0)[8], ows3->y(0)[8]); - TS_ASSERT_DIFFERS(ows1->y(0)[109], ows3->y(0)[109]); - TS_ASSERT_DIFFERS(ows1->y(0)[281], ows3->y(0)[281]); - } - -private: - RRFMuon rrfMuon; - RRFMuon rrfMuon2, rrfMuon3; - - MatrixWorkspace_sptr createDummyWorkspace() { - int nBins = 300; - MatrixWorkspace_sptr ws = - WorkspaceFactory::Instance().create("Workspace2D", 2, nBins + 1, nBins); - - for (int i = 0; i < nBins; i++) { - double x = i / static_cast<double>(nBins); - ws->mutableX(0)[i] = x; - ws->mutableY(0)[i] = cos(2 * M_PI * x); - ws->mutableX(1)[i] = x; - ws->mutableY(1)[i] = sin(2 * M_PI * x); - } - - ws->mutableX(0)[nBins] = nBins; - ws->mutableX(1)[nBins] = nBins; - - // Units - ws->getAxis(0)->unit() = - Mantid::Kernel::UnitFactory::Instance().create("TOF"); - - return ws; - } -}; - -#endif /* MANTID_ALGORITHMS_RRFMUON_H_ */ diff --git a/Framework/Algorithms/test/RemoveExpDecayTest.h b/Framework/Algorithms/test/RemoveExpDecayTest.h deleted file mode 100644 index 76a136302b9d7260f3e8d8b1ca7abecc2c8a474b..0000000000000000000000000000000000000000 --- a/Framework/Algorithms/test/RemoveExpDecayTest.h +++ /dev/null @@ -1,220 +0,0 @@ -#ifndef MUONREMOVEEXPDECAYTEST_H_ -#define MUONREMOVEEXPDECAYTEST_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidAlgorithms/RemoveExpDecay.h" -#include "MantidKernel/PhysicalConstants.h" -#include "MantidAPI/FrameworkManager.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidHistogramData/LinearGenerator.h" -#include "MantidTestHelpers/WorkspaceCreationHelper.h" - -using namespace Mantid::API; -using Mantid::MantidVec; -using Mantid::Algorithms::MuonRemoveExpDecay; - -const std::string outputName = "MuonRemoveExpDecay_Output"; - -namespace { -MatrixWorkspace_sptr createWorkspace(size_t nspec, size_t maxt) { - - // Create a fake muon dataset - double a = 0.1; // Amplitude of the oscillations - double w = 25.; // Frequency of the oscillations - double tau = Mantid::PhysicalConstants::MuonLifetime * - 1e6; // Muon life time in microseconds - - MantidVec X; - MantidVec Y; - MantidVec E; - for (size_t s = 0; s < nspec; s++) { - for (size_t t = 0; t < maxt; t++) { - double x = static_cast<double>(t) / static_cast<double>(maxt); - double e = exp(-x / tau); - X.push_back(x); - Y.push_back( - a * sin(w * x + - static_cast<double>(s) * M_PI / static_cast<double>(nspec)) * - e + - e); - E.push_back(0.005); - } - } - - auto createWS = AlgorithmManager::Instance().create("CreateWorkspace"); - createWS->initialize(); - createWS->setChild(true); - createWS->setProperty("DataX", X); - createWS->setProperty("DataY", Y); - createWS->setProperty("DataE", E); - createWS->setProperty("NSpec", static_cast<int>(nspec)); - createWS->setPropertyValue("OutputWorkspace", "ws"); - createWS->execute(); - MatrixWorkspace_sptr ws = createWS->getProperty("OutputWorkspace"); - - return ws; -} -} - -class RemoveExpDecayTest : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static RemoveExpDecayTest *createSuite() { return new RemoveExpDecayTest(); } - static void destroySuite(RemoveExpDecayTest *suite) { delete suite; } - - RemoveExpDecayTest() { FrameworkManager::Instance(); } - - void testInit() { - IAlgorithm_sptr alg = AlgorithmManager::Instance().create("RemoveExpDecay"); - alg->initialize(); - TS_ASSERT(alg->isInitialized()) - } - - void test_Execute() { - - auto ws = createWorkspace(1, 50); - - IAlgorithm_sptr alg = AlgorithmManager::Instance().create("RemoveExpDecay"); - alg->initialize(); - alg->setChild(true); - alg->setProperty("InputWorkspace", ws); - alg->setPropertyValue("OutputWorkspace", outputName); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - - MatrixWorkspace_sptr outWS = alg->getProperty("OutputWorkspace"); - } - - void test_EmptySpectrumList() { - - auto ws = createWorkspace(2, 50); - - IAlgorithm_sptr alg = AlgorithmManager::Instance().create("RemoveExpDecay"); - alg->initialize(); - alg->setChild(true); - alg->setProperty("InputWorkspace", ws); - alg->setPropertyValue("OutputWorkspace", outputName); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - - MatrixWorkspace_sptr outWS = alg->getProperty("OutputWorkspace"); - - // First spectrum - // Test some X values - TS_ASSERT_DELTA(outWS->x(0)[10], 0.2000, 0.0001); - TS_ASSERT_DELTA(outWS->x(0)[19], 0.3800, 0.0001); - TS_ASSERT_DELTA(outWS->x(0)[49], 0.9800, 0.0001); - // Test some Y values - TS_ASSERT_DELTA(outWS->y(0)[10], -0.0992, 0.0001); - TS_ASSERT_DELTA(outWS->y(0)[19], -0.0111, 0.0001); - TS_ASSERT_DELTA(outWS->y(0)[49], -0.0625, 0.0001); - // Test some E values - TS_ASSERT_DELTA(outWS->e(0)[10], 0.0054, 0.0001); - TS_ASSERT_DELTA(outWS->e(0)[19], 0.0059, 0.0001); - TS_ASSERT_DELTA(outWS->e(0)[49], 0.0077, 0.0001); - - // Second spectrum - // Test some X values - TS_ASSERT_DELTA(outWS->x(1)[10], 0.2000, 0.0001); - TS_ASSERT_DELTA(outWS->x(1)[19], 0.3800, 0.0001); - TS_ASSERT_DELTA(outWS->x(1)[49], 0.9800, 0.0001); - // Test some Y values - TS_ASSERT_DELTA(outWS->y(1)[10], 0.0276, 0.0001); - TS_ASSERT_DELTA(outWS->y(1)[19], -0.1003, 0.0001); - TS_ASSERT_DELTA(outWS->y(1)[49], 0.0798, 0.0001); - // Test some E values - TS_ASSERT_DELTA(outWS->e(1)[10], 0.0054, 0.0001); - TS_ASSERT_DELTA(outWS->e(1)[19], 0.0059, 0.0001); - TS_ASSERT_DELTA(outWS->e(1)[49], 0.0078, 0.0001); - } - - void test_SpectrumList() { - - auto ws = createWorkspace(2, 50); - - // First, run the algorithm without specifying any spectrum - IAlgorithm_sptr alg1 = - AlgorithmManager::Instance().create("RemoveExpDecay"); - alg1->initialize(); - alg1->setChild(true); - alg1->setProperty("InputWorkspace", ws); - alg1->setPropertyValue("OutputWorkspace", outputName); - TS_ASSERT_THROWS_NOTHING(alg1->execute()); - TS_ASSERT(alg1->isExecuted()); - MatrixWorkspace_sptr out1 = alg1->getProperty("OutputWorkspace"); - - // Then run the algorithm on the second spectrum only - IAlgorithm_sptr alg2 = - AlgorithmManager::Instance().create("RemoveExpDecay"); - alg2->initialize(); - alg2->setChild(true); - alg2->setProperty("InputWorkspace", ws); - alg2->setPropertyValue("OutputWorkspace", outputName); - alg2->setPropertyValue("Spectra", "1"); - TS_ASSERT_THROWS_NOTHING(alg2->execute()); - TS_ASSERT(alg2->isExecuted()); - MatrixWorkspace_sptr out2 = alg2->getProperty("OutputWorkspace"); - - // Both output workspaces should have 2 spectra - TS_ASSERT_EQUALS(out1->getNumberHistograms(), ws->getNumberHistograms()); - TS_ASSERT_EQUALS(out2->getNumberHistograms(), ws->getNumberHistograms()); - - // Compare results, they should match for the selected spectrum - TS_ASSERT_EQUALS(out1->x(1).rawData(), out2->x(1).rawData()); - TS_ASSERT_EQUALS(out1->y(1).rawData(), out2->y(1).rawData()); - TS_ASSERT_EQUALS(out1->e(1).rawData(), out2->e(1).rawData()); - - // Compare non-selected spectra, the should match the input ones - TS_ASSERT_EQUALS(ws->x(0).rawData(), out2->x(0).rawData()); - TS_ASSERT_EQUALS(ws->y(0).rawData(), out2->y(0).rawData()); - TS_ASSERT_EQUALS(ws->e(0).rawData(), out2->e(0).rawData()); - } - - void test_yUnitLabel() { - - auto ws = createWorkspace(4, 50); - - IAlgorithm_sptr alg = AlgorithmManager::Instance().create("RemoveExpDecay"); - alg->initialize(); - alg->setChild(true); - alg->setProperty("InputWorkspace", ws); - alg->setPropertyValue("OutputWorkspace", outputName); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()) - - MatrixWorkspace_sptr result = alg->getProperty("OutputWorkspace"); - TS_ASSERT(result); - TS_ASSERT_EQUALS(result->YUnitLabel(), "Asymmetry"); - } -}; - -class RemoveExpDecayTestPerformance : public CxxTest::TestSuite { -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static RemoveExpDecayTestPerformance *createSuite() { - return new RemoveExpDecayTestPerformance(); - } - static void destroySuite(RemoveExpDecayTestPerformance *suite) { - AnalysisDataService::Instance().clear(); - delete suite; - } - - RemoveExpDecayTestPerformance() { FrameworkManager::Instance(); } - - void setUp() override { input = createWorkspace(1000, 100); } - - void testExec2D() { - MuonRemoveExpDecay alg; - alg.initialize(); - alg.setProperty("InputWorkspace", input); - alg.setPropertyValue("OutputWorkspace", "output"); - alg.execute(); - } - -private: - MatrixWorkspace_sptr input; -}; - -#endif /*MUONREMOVEEXPDECAYTEST_H_*/