本文整理汇总了C++中api::MatrixWorkspace_const_sptr::getIndexFromSpectrumNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_const_sptr::getIndexFromSpectrumNumber方法的具体用法?C++ MatrixWorkspace_const_sptr::getIndexFromSpectrumNumber怎么用?C++ MatrixWorkspace_const_sptr::getIndexFromSpectrumNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::MatrixWorkspace_const_sptr
的用法示例。
在下文中一共展示了MatrixWorkspace_const_sptr::getIndexFromSpectrumNumber方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getGeometry
/** Gets the distances between the source and detectors whose IDs you pass to it
* @param WS :: the input workspace
* @param mon0Spec :: Spectrum number of the output from the first monitor
* @param mon1Spec :: Spectrum number of the output from the second monitor
* @param monitor0Dist :: the calculated distance to the detector whose ID was
* passed to this function first
* @param monitor1Dist :: calculated distance to the detector whose ID was
* passed to this function second
* @throw NotFoundError if no detector is found for the detector ID given
*/
void GetEi::getGeometry(API::MatrixWorkspace_const_sptr WS, specid_t mon0Spec,
specid_t mon1Spec, double &monitor0Dist,
double &monitor1Dist) const {
const IComponent_const_sptr source = WS->getInstrument()->getSource();
// retrieve a pointer to the first detector and get its distance
size_t monWI = 0;
try {
monWI = WS->getIndexFromSpectrumNumber(mon0Spec);
} catch (std::runtime_error &) {
g_log.error()
<< "Could not find the workspace index for the monitor at spectrum "
<< mon0Spec << "\n";
g_log.error() << "Error retrieving data for the first monitor" << std::endl;
throw std::bad_cast();
}
const std::set<detid_t> &dets = WS->getSpectrum(monWI)->getDetectorIDs();
if (dets.size() != 1) {
g_log.error() << "The detector for spectrum number " << mon0Spec
<< " was either not found or is a group, grouped monitors "
"are not supported by this algorithm\n";
g_log.error() << "Error retrieving data for the first monitor" << std::endl;
throw std::bad_cast();
}
IDetector_const_sptr det = WS->getInstrument()->getDetector(*dets.begin());
monitor0Dist = det->getDistance(*(source.get()));
// repeat for the second detector
try {
monWI = WS->getIndexFromSpectrumNumber(mon0Spec);
} catch (std::runtime_error &) {
g_log.error()
<< "Could not find the workspace index for the monitor at spectrum "
<< mon0Spec << "\n";
g_log.error() << "Error retrieving data for the second monitor\n";
throw std::bad_cast();
}
const std::set<detid_t> &dets2 = WS->getSpectrum(monWI)->getDetectorIDs();
if (dets2.size() != 1) {
g_log.error() << "The detector for spectrum number " << mon1Spec
<< " was either not found or is a group, grouped monitors "
"are not supported by this algorithm\n";
g_log.error() << "Error retrieving data for the second monitor\n";
throw std::bad_cast();
}
det = WS->getInstrument()->getDetector(*dets2.begin());
monitor1Dist = det->getDistance(*(source.get()));
}