本文整理汇总了C++中api::MatrixWorkspace_sptr::setSharedRun方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_sptr::setSharedRun方法的具体用法?C++ MatrixWorkspace_sptr::setSharedRun怎么用?C++ MatrixWorkspace_sptr::setSharedRun使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::MatrixWorkspace_sptr
的用法示例。
在下文中一共展示了MatrixWorkspace_sptr::setSharedRun方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
API::MatrixWorkspace_sptr
CreateFloodWorkspace::removeBackground(API::MatrixWorkspace_sptr ws) {
g_log.information() << "Remove background "
<< getPropertyValue(Prop::BACKGROUND) << '\n';
auto fitWS = transpose(ws);
auto const &x = fitWS->x(0);
// Define the fitting interval
double startX = getProperty(Prop::START_X);
double endX = getProperty(Prop::END_X);
std::vector<double> excludeFromFit;
if (isDefault(Prop::START_X)) {
startX = x.front();
} else {
excludeFromFit.push_back(x.front());
excludeFromFit.push_back(startX);
}
if (isDefault(Prop::END_X)) {
endX = x.back();
} else {
excludeFromFit.push_back(endX);
excludeFromFit.push_back(x.back());
}
// Exclude any bad detectors.
for (auto i : m_excludedSpectra) {
excludeFromFit.push_back(i);
excludeFromFit.push_back(i);
}
std::string const function = getBackgroundFunction();
// Fit the data to determine unwanted background
auto alg = createChildAlgorithm("Fit", 0.9, 0.99);
alg->setProperty("Function", function);
alg->setProperty("InputWorkspace", fitWS);
alg->setProperty("WorkspaceIndex", 0);
if (!excludeFromFit.empty()) {
alg->setProperty("Exclude", excludeFromFit);
}
alg->setProperty("Output", "fit");
alg->execute();
IFunction_sptr func = alg->getProperty("Function");
g_log.information() << "Background function parameters:\n";
for (size_t i = 0; i < func->nParams(); ++i) {
g_log.information() << " " << func->parameterName(i) << ": "
<< func->getParameter(i) << '\n';
}
// Divide the workspace by the fitted curve to remove the background
// and scale to values around 1
MatrixWorkspace_sptr bkgWS = alg->getProperty("OutputWorkspace");
auto const &bkg = bkgWS->y(1);
auto const nHisto = static_cast<int>(ws->getNumberHistograms());
PARALLEL_FOR_IF(Kernel::threadSafe(*ws, *bkgWS))
for (int i = 0; i < nHisto; ++i) {
PARALLEL_START_INTERUPT_REGION
auto const xVal = x[i];
if (isExcludedSpectrum(xVal)) {
ws->mutableY(i)[0] = VERY_BIG_VALUE;
ws->mutableE(i)[0] = 0.0;
} else if (xVal >= startX && xVal <= endX) {
auto const background = bkg[i];
if (background <= 0.0) {
throw std::runtime_error(
"Background is expected to be positive, found value " +
std::to_string(background) + " at spectrum with workspace index " +
std::to_string(i));
}
ws->mutableY(i)[0] /= background;
ws->mutableE(i)[0] /= background;
} else {
ws->mutableY(i)[0] = 1.0;
ws->mutableE(i)[0] = 0.0;
}
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
// Remove the logs
ws->setSharedRun(make_cow<Run>());
return ws;
}