/** * This performs a similar operation to divide, but is a separate algorithm so *that the correct spectra are used in the case of detector scans. This *currently does not support event workspaces properly, but should be made to in *the future. * * @param inputWorkspace The workspace with the spectra to divide by the monitor * @param outputWorkspace The resulting workspace */ void NormaliseToMonitor::performHistogramDivision( const MatrixWorkspace_sptr &inputWorkspace, MatrixWorkspace_sptr &outputWorkspace) { if (outputWorkspace != inputWorkspace) outputWorkspace = inputWorkspace->clone(); size_t monitorWorkspaceIndex = 0; Progress prog(this, 0.0, 1.0, m_workspaceIndexes.size()); const auto &specInfo = inputWorkspace->spectrumInfo(); for (const auto workspaceIndex : m_workspaceIndexes) { // Errors propagated according to // http://docs.mantidproject.org/nightly/concepts/ErrorPropagation.html#error-propagation // This is similar to that in MantidAlgorithms::Divide prog.report("Performing normalisation"); size_t timeIndex = 0; if (m_scanInput) timeIndex = specInfo.spectrumDefinition(workspaceIndex)[0].second; const auto newYFactor = 1.0 / m_monitor->histogram(monitorWorkspaceIndex).y()[0]; const auto divisorError = m_monitor->histogram(monitorWorkspaceIndex).e()[0]; const double yErrorFactor = pow(divisorError * newYFactor, 2); monitorWorkspaceIndex++; PARALLEL_FOR_IF(Kernel::threadSafe(*outputWorkspace)) for (int64_t i = 0; i < int64_t(outputWorkspace->getNumberHistograms()); ++i) { PARALLEL_START_INTERUPT_REGION const auto &specDef = specInfo.spectrumDefinition(i); if (!spectrumDefinitionsMatchTimeIndex(specDef, timeIndex)) continue; auto hist = outputWorkspace->histogram(i); auto &yValues = hist.mutableY(); auto &eValues = hist.mutableE(); for (size_t j = 0; j < yValues.size(); ++j) { eValues[j] = newYFactor * sqrt(eValues[j] * eValues[j] + yValues[j] * yValues[j] * yErrorFactor); yValues[j] *= newYFactor; } outputWorkspace->setHistogram(i, hist); PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION } }
MatrixWorkspace_sptr JoinISISPolarizationEfficiencies::interpolatePointDataWorkspace( MatrixWorkspace_sptr ws, size_t const maxSize) { auto const &x = ws->x(0); auto const startX = x.front(); auto const endX = x.back(); Counts yVals(maxSize, 0.0); auto const dX = (endX - startX) / double(maxSize - 1); Points xVals(maxSize, LinearGenerator(startX, dX)); auto newHisto = Histogram(xVals, yVals); interpolateLinearInplace(ws->histogram(0), newHisto); auto interpolatedWS = boost::make_shared<Workspace2D>(); interpolatedWS->initialize(1, newHisto); assert(interpolatedWS->y(0).size() == maxSize); return interpolatedWS; }
/** Spread the average over all the pixels */ void SmoothNeighbours::spreadPixels(MatrixWorkspace_sptr outws) { // Get some stuff from the input workspace const size_t numberOfSpectra = inWS->getNumberHistograms(); const size_t YLength = inWS->blocksize(); MatrixWorkspace_sptr outws2; // Make a brand new Workspace2D if (boost::dynamic_pointer_cast<OffsetsWorkspace>(inWS)) { g_log.information() << "Creating new OffsetsWorkspace\n"; outws2 = MatrixWorkspace_sptr(new OffsetsWorkspace(inWS->getInstrument())); } else { outws2 = boost::dynamic_pointer_cast<MatrixWorkspace>( API::WorkspaceFactory::Instance().create("Workspace2D", numberOfSpectra, YLength + 1, YLength)); } // Copy geometry over. API::WorkspaceFactory::Instance().initializeFromParent(*inWS, *outws2, false); // Go through all the input workspace for (int outWIi = 0; outWIi < int(numberOfSpectra); outWIi++) { const auto &inSpec = inWS->getSpectrum(outWIi); auto &outSpec2 = outws2->getSpectrum(outWIi); outSpec2.mutableX() = inSpec.x(); outSpec2.addDetectorIDs(inSpec.getDetectorIDs()); // Zero the Y and E vectors outSpec2.clearData(); } // Go through all the output workspace const size_t numberOfSpectra2 = outws->getNumberHistograms(); for (int outWIi = 0; outWIi < int(numberOfSpectra2); outWIi++) { // Which are the neighbours? for (const auto &neighbor : m_neighbours[outWIi]) { outws2->setHistogram(neighbor.first, outws->histogram(outWIi)); } } this->setProperty("OutputWorkspace", outws2); }