本文整理汇总了C++中api::MatrixWorkspace_sptr::getIndicesFromDetectorIDs方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_sptr::getIndicesFromDetectorIDs方法的具体用法?C++ MatrixWorkspace_sptr::getIndicesFromDetectorIDs怎么用?C++ MatrixWorkspace_sptr::getIndicesFromDetectorIDs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::MatrixWorkspace_sptr
的用法示例。
在下文中一共展示了MatrixWorkspace_sptr::getIndicesFromDetectorIDs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getInWSMonitorSpectrum
/** Checks and retrieves the requested spectrum out of the input workspace
* @param inputWorkspace The input workspace.
* @param spectra_num The spectra number.
* @returns A workspace containing the monitor spectrum only.
* @returns spectra number (WS ID) which is used to normalize by.
* @throw std::runtime_error If the properties are invalid
*/
API::MatrixWorkspace_sptr NormaliseToMonitor::getInWSMonitorSpectrum(
const API::MatrixWorkspace_sptr &inputWorkspace, int &spectra_num) {
// this is the index of the spectra within the workspace and we need to
// identify it either from DetID or from SpecID
// size_t spectra_num(-1);
// try monitor spectrum. If it is specified, it overrides everything
int monitorSpec = getProperty("MonitorSpectrum");
if (monitorSpec < 0) {
// Get hold of the monitor spectrum through detector ID
int monitorID = getProperty("MonitorID");
if (monitorID < 0) {
throw std::runtime_error(
"Both MonitorSpectrum and MonitorID can not be negative");
}
// set spectra of detector's ID of one selected monitor ID
std::vector<detid_t> detID(1, monitorID);
// got the index of correspondent spectra (should be only one).
auto indexList = inputWorkspace->getIndicesFromDetectorIDs(detID);
if (indexList.empty()) {
throw std::runtime_error(
"Can not find spectra, corresponding to the requested monitor ID");
}
if (indexList.size() > 1) {
throw std::runtime_error("More then one spectra corresponds to the "
"requested monitor ID, which is unheard of");
}
spectra_num = static_cast<int>(indexList[0]);
} else { // monitor spectrum is specified.
const SpectraAxis *axis =
dynamic_cast<const SpectraAxis *>(inputWorkspace->getAxis(1));
if (!axis) {
throw std::runtime_error("Cannot retrieve monitor spectrum - spectrum "
"numbers not attached to workspace");
}
auto specs = axis->getSpectraIndexMap();
if (!specs.count(monitorSpec)) {
throw std::runtime_error("Input workspace does not contain spectrum "
"number given for MonitorSpectrum");
}
spectra_num = static_cast<int>(specs[monitorSpec]);
}
return this->extractMonitorSpectrum(inputWorkspace, spectra_num);
}