/** Unwraps the Y & E vectors of a spectrum according to the ranges found in * unwrapX. * @param tempWS :: A pointer to the temporary workspace in which the * results are being stored * @param spectrum :: The workspace index * @param rangeBounds :: The upper and lower ranges for the unwrapping */ void UnwrapMonitor::unwrapYandE(const API::MatrixWorkspace_sptr &tempWS, const int &spectrum, const std::vector<int> &rangeBounds) { // Copy over the relevant ranges of Y & E data MantidVec &Y = tempWS->dataY(spectrum); MantidVec &E = tempWS->dataE(spectrum); // Get references to the input data const MantidVec &YIn = m_inputWS->dataY(spectrum); const MantidVec &EIn = m_inputWS->dataE(spectrum); if (rangeBounds[2] != -1) { // Copy in the upper range Y.assign(YIn.begin() + rangeBounds[2], YIn.end()); E.assign(EIn.begin() + rangeBounds[2], EIn.end()); // Propagate masking, if necessary if (m_inputWS->hasMaskedBins(spectrum)) { const MatrixWorkspace::MaskList &inputMasks = m_inputWS->maskedBins(spectrum); MatrixWorkspace::MaskList::const_iterator it; for (it = inputMasks.begin(); it != inputMasks.end(); ++it) { if (static_cast<int>((*it).first) >= rangeBounds[2]) tempWS->flagMasked(spectrum, (*it).first - rangeBounds[2], (*it).second); } } } else { // Y & E are references to existing vector. Assign above clears them, so // need to explicitly here Y.clear(); E.clear(); } if (rangeBounds[0] != -1 && rangeBounds[1] > 0) { // Now append the lower range MantidVec::const_iterator YStart = YIn.begin(); MantidVec::const_iterator EStart = EIn.begin(); Y.insert(Y.end(), YStart + rangeBounds[0], YStart + rangeBounds[1]); E.insert(E.end(), EStart + rangeBounds[0], EStart + rangeBounds[1]); // Propagate masking, if necessary if (m_inputWS->hasMaskedBins(spectrum)) { const MatrixWorkspace::MaskList &inputMasks = m_inputWS->maskedBins(spectrum); MatrixWorkspace::MaskList::const_iterator it; for (it = inputMasks.begin(); it != inputMasks.end(); ++it) { const int maskIndex = static_cast<int>((*it).first); if (maskIndex >= rangeBounds[0] && maskIndex < rangeBounds[1]) tempWS->flagMasked(spectrum, maskIndex - rangeBounds[0], (*it).second); } } } }
/** * Read the bin masking information from the mantid_workspace_i/workspace group. * @param wksp_cls :: The data group * @param local_workspace :: The workspace to read into */ void LoadNexusProcessed::readBinMasking(NXData & wksp_cls, API::MatrixWorkspace_sptr local_workspace) { if (wksp_cls.getDataSetInfo("masked_spectra").stat == NX_ERROR) { return; } NXInt spec = wksp_cls.openNXInt("masked_spectra"); spec.load(); NXInt bins = wksp_cls.openNXInt("masked_bins"); bins.load(); NXDouble weights = wksp_cls.openNXDouble("mask_weights"); weights.load(); const int n = spec.dim0(); const int n1 = n - 1; for(int i = 0; i < n; ++i) { int si = spec(i,0); int j0 = spec(i,1); int j1 = i < n1 ? spec(i+1,1) : bins.dim0(); for(int j = j0; j < j1; ++j) { local_workspace->flagMasked(si,bins[j],weights[j]); } } }