/** * @brief Copies the sorted inputworkspace into the output workspace without * using clone because of how histograms are supported, for the Y Axis and the E * Axis. * * @param workspaceIndicies the sorted vector of indicies * @param inputWorkspace the unsorted input workspaces * @param outputWorkspace the empty output workspace * @param specNum the spectrum number being copied into * @param isAProperHistogram whether or not it has been determined to be a valid * histogram earlier on. */ void SortXAxis::copyYandEToOutputWorkspace( std::vector<std::size_t> &workspaceIndicies, const Mantid::API::MatrixWorkspace &inputWorkspace, Mantid::API::MatrixWorkspace &outputWorkspace, unsigned int specNum, bool isAProperHistogram) { // If Histogram data find the biggest index value and remove it from // workspaceIndicies if (isAProperHistogram) { auto lastIndexIt = std::find(workspaceIndicies.begin(), workspaceIndicies.end(), inputWorkspace.y(specNum).size()); workspaceIndicies.erase(lastIndexIt); } auto &inSpaceY = inputWorkspace.y(specNum); for (auto workspaceIndex = 0u; workspaceIndex < inputWorkspace.y(specNum).size(); workspaceIndex++) { outputWorkspace.mutableY(specNum)[workspaceIndex] = inSpaceY[workspaceIndicies[workspaceIndex]]; } auto &inSpaceE = inputWorkspace.e(specNum); for (auto workspaceIndex = 0u; workspaceIndex < inputWorkspace.e(specNum).size(); workspaceIndex++) { outputWorkspace.mutableE(specNum)[workspaceIndex] = inSpaceE[workspaceIndicies[workspaceIndex]]; } }
/** * @brief Determines whether it is a valid histogram or not. * * @param inputWorkspace the unsorted input workspace * @return true if it is a valid histogram else produce a runtime_error * @return false if it is not a histogram, and is thus point data */ bool SortXAxis::determineIfHistogramIsValid( const Mantid::API::MatrixWorkspace &inputWorkspace) { // Assuming all X and Ys are the same, if X is not the same size as y, assume // it is a histogram if (inputWorkspace.x(0).size() != inputWorkspace.y(0).size()) { // The only way to guarantee that a histogram is a proper histogram, is to // check whether each data value is in the correct order. if (!isItSorted(std::greater<double>(), inputWorkspace)) { if (!isItSorted(std::less<double>(), inputWorkspace)) { throw std::runtime_error("Data entered looks like a histogram, but is " "not a valid histogram"); } } return true; } return false; }