Mantid
Loading...
Searching...
No Matches
PolarizationCorrectionsHelpers.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2024 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
9#include "MantidAPI/Run.h"
12
13#include <algorithm>
14#include <boost/algorithm/string.hpp>
15#include <boost/algorithm/string/trim.hpp>
16#include <vector>
17
18namespace Mantid {
19namespace Algorithms {
20namespace PolarizationCorrectionsHelpers {
21
31 const std::string &spinStateOrder, const std::string &targetSpinState) {
32 const auto &spinStateOrderVec = Mantid::Kernel::SpinStateHelpers::splitSpinStateString(spinStateOrder);
33 const auto &wsIndex =
35 if (!wsIndex.has_value()) {
36 return nullptr;
37 }
38 return std::dynamic_pointer_cast<API::MatrixWorkspace>(group->getItem(wsIndex.value()));
39}
40} // namespace PolarizationCorrectionsHelpers
41
42namespace SpinStatesORSO {
43/*
44 * For a given polarization spin state, return the corresponding Reflectometry ORSO file format notation.
45 * @param spinState The spin state to find the ORSO notation for.
46 * @return The ORSO notation that represents the given polarization spin state.
47 * @throw std::invalid_argument if no corresponding ORSO notation can be found.
48 */
49const std::string &getORSONotationForSpinState(const std::string &spinState) {
52 return SpinStatesORSO::PP;
53 }
54
57 return SpinStatesORSO::PM;
58 }
59
62 return SpinStatesORSO::MP;
63 }
64
67 return SpinStatesORSO::MM;
68 }
69
71 return SpinStatesORSO::PO;
72 }
73
75 return SpinStatesORSO::MO;
76 }
77
78 throw std::invalid_argument("Cannot convert spin state " + spinState + " into ORSO notation.");
79}
80
81/*
82 * Add a sample log entry for the given polarization spin state using the corresponding Reflectometry ORSO file format
83 * notation.
84 * @param spinState The spin state to add the ORSO spin state sample log for.
85 * @throw std::invalid_argument if no corresponding ORSO spin state notation can be found.
86 */
87void addORSOLogForSpinState(const Mantid::API::MatrixWorkspace_sptr &ws, const std::string &spinState) {
88 const auto &logValue = getORSONotationForSpinState(spinState);
89 ws->mutableRun().addProperty(SpinStatesORSO::LOG_NAME, logValue, true);
90}
91} // namespace SpinStatesORSO
92} // namespace Algorithms
93} // namespace Mantid
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
MANTID_ALGORITHMS_DLL API::MatrixWorkspace_sptr workspaceForSpinState(const API::WorkspaceGroup_sptr &group, const std::string &spinStateOrder, const std::string &targetSpinState)
Returns the workspace in the group associated with the given targetSpinState according to the order d...
MANTID_ALGORITHMS_DLL void addORSOLogForSpinState(const Mantid::API::MatrixWorkspace_sptr &ws, const std::string &spinState)
MANTID_ALGORITHMS_DLL const std::string & getORSONotationForSpinState(const std::string &spinState)
MANTID_KERNEL_DLL std::vector< std::string > splitSpinStateString(const std::string &spinStates)
MANTID_KERNEL_DLL std::optional< size_t > indexOfWorkspaceForSpinState(const std::vector< std::string > &spinStateOrder, std::string targetSpinState)
Helper class which provides the Collimation Length for SANS instruments.