本文整理汇总了C++中api::MatrixWorkspace_sptr::setYUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_sptr::setYUnit方法的具体用法?C++ MatrixWorkspace_sptr::setYUnit怎么用?C++ MatrixWorkspace_sptr::setYUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::MatrixWorkspace_sptr
的用法示例。
在下文中一共展示了MatrixWorkspace_sptr::setYUnit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setOutputUnits
void Divide::setOutputUnits(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs,API::MatrixWorkspace_sptr out)
{
if ( rhs->YUnit().empty() || !WorkspaceHelpers::matchingBins(lhs,rhs,true) )
{
// Do nothing
}
// If the Y units match, then the output will be a distribution and will be dimensionless
else if ( lhs->YUnit() == rhs->YUnit() && rhs->blocksize() > 1 )
{
out->setYUnit("");
out->isDistribution(true);
}
// Else we need to set the unit that results from the division
else
{
if ( ! lhs->YUnit().empty() ) out->setYUnit(lhs->YUnit() + "/" + rhs->YUnit());
else out->setYUnit("1/" + rhs->YUnit());
}
}
示例2: invalid_argument
//.........这里部分代码省略.........
throw std::invalid_argument("Invalid detector asymmetries");
}
std::vector<bool> emptySpectrum;
emptySpectrum.reserve(nspec);
std::vector<double> aj, bj;
{
// Calculate coefficients aj, bj
double sxx = 0.;
double syy = 0.;
double sxy = 0.;
for (size_t h = 0; h < nspec; h++) {
emptySpectrum.push_back(
std::all_of(ws->y(h).begin(), ws->y(h).end(),
[](double value) { return value == 0.; }));
if (!emptySpectrum[h]) {
const double asym = phase->Double(h, asymmetryIndex) / maxAsym;
const double phi = phase->Double(h, phaseIndex);
const double X = n0[h] * asym * cos(phi);
const double Y = n0[h] * asym * sin(phi);
sxx += X * X;
syy += Y * Y;
sxy += X * Y;
}
}
const double lam1 = 2 * syy / (sxx * syy - sxy * sxy);
const double mu1 = 2 * sxy / (sxy * sxy - sxx * syy);
const double lam2 = 2 * sxy / (sxy * sxy - sxx * syy);
const double mu2 = 2 * sxx / (sxx * syy - sxy * sxy);
for (size_t h = 0; h < nspec; h++) {
if (emptySpectrum[h]) {
aj.push_back(0.0);
bj.push_back(0.0);
} else {
const double asym = phase->Double(h, asymmetryIndex) / maxAsym;
const double phi = phase->Double(h, phaseIndex);
const double X = n0[h] * asym * cos(phi);
const double Y = n0[h] * asym * sin(phi);
aj.push_back((lam1 * X + mu1 * Y) * 0.5);
bj.push_back((lam2 * X + mu2 * Y) * 0.5);
}
}
}
const size_t npoints = ws->blocksize();
// Create and populate output workspace
API::MatrixWorkspace_sptr ows =
API::WorkspaceFactory::Instance().create(ws, 2, npoints + 1, npoints);
// X
ows->setSharedX(0, ws->sharedX(0));
ows->setSharedX(1, ws->sharedX(0));
// Phase quadrature
auto &realY = ows->mutableY(0);
auto &imagY = ows->mutableY(1);
auto &realE = ows->mutableE(0);
auto &imagE = ows->mutableE(1);
const auto xPointData = ws->histogram(0).points();
// First X value
const double X0 = xPointData.front();
// calculate exponential decay outside of the loop
std::vector<double> expDecay = xPointData.rawData();
std::transform(expDecay.begin(), expDecay.end(), expDecay.begin(),
[X0, muLife](double x) { return exp(-(x - X0) / muLife); });
for (size_t i = 0; i < npoints; i++) {
for (size_t h = 0; h < nspec; h++) {
if (!emptySpectrum[h]) {
// (X,Y,E) with exponential decay removed
const double X = ws->x(h)[i];
const double exponential = n0[h] * exp(-(X - X0) / muLife);
const double Y = ws->y(h)[i] - exponential;
const double E =
(ws->y(h)[i] > poissonLimit) ? ws->e(h)[i] : sqrt(exponential);
realY[i] += aj[h] * Y;
imagY[i] += bj[h] * Y;
realE[i] += aj[h] * aj[h] * E * E;
imagE[i] += bj[h] * bj[h] * E * E;
}
}
realE[i] = sqrt(realE[i]);
imagE[i] = sqrt(imagE[i]);
// Regain exponential decay
realY[i] /= expDecay[i];
imagY[i] /= expDecay[i];
realE[i] /= expDecay[i];
imagE[i] /= expDecay[i];
}
// New Y axis label
ows->setYUnit("Asymmetry");
return ows;
}