本文整理汇总了C++中api::MatrixWorkspace_sptr::maskedBins方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_sptr::maskedBins方法的具体用法?C++ MatrixWorkspace_sptr::maskedBins怎么用?C++ MatrixWorkspace_sptr::maskedBins使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::MatrixWorkspace_sptr
的用法示例。
在下文中一共展示了MatrixWorkspace_sptr::maskedBins方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exec
/** Executes the algorithm
*
*/
void SplineBackground::exec()
{
API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
int spec = getProperty("WorkspaceIndex");
if (spec > static_cast<int>(inWS->getNumberHistograms()))
throw std::out_of_range("WorkspaceIndex is out of range.");
const MantidVec& X = inWS->readX(spec);
const MantidVec& Y = inWS->readY(spec);
const MantidVec& E = inWS->readE(spec);
const bool isHistogram = inWS->isHistogramData();
const int ncoeffs = getProperty("NCoeff");
const int k = 4; // order of the spline + 1 (cubic)
const int nbreak = ncoeffs - (k - 2);
if (nbreak <= 0)
throw std::out_of_range("Too low NCoeff");
gsl_bspline_workspace *bw;
gsl_vector *B;
gsl_vector *c, *w, *x, *y;
gsl_matrix *Z, *cov;
gsl_multifit_linear_workspace *mw;
double chisq;
int n = static_cast<int>(Y.size());
bool isMasked = inWS->hasMaskedBins(spec);
std::vector<int> masked(Y.size());
if (isMasked)
{
for(API::MatrixWorkspace::MaskList::const_iterator it=inWS->maskedBins(spec).begin();it!=inWS->maskedBins(spec).end();++it)
masked[it->first] = 1;
n -= static_cast<int>(inWS->maskedBins(spec).size());
}
if (n < ncoeffs)
{
g_log.error("Too many basis functions (NCoeff)");
throw std::out_of_range("Too many basis functions (NCoeff)");
}
/* allocate a cubic bspline workspace (k = 4) */
bw = gsl_bspline_alloc(k, nbreak);
B = gsl_vector_alloc(ncoeffs);
x = gsl_vector_alloc(n);
y = gsl_vector_alloc(n);
Z = gsl_matrix_alloc(n, ncoeffs);
c = gsl_vector_alloc(ncoeffs);
w = gsl_vector_alloc(n);
cov = gsl_matrix_alloc(ncoeffs, ncoeffs);
mw = gsl_multifit_linear_alloc(n, ncoeffs);
/* this is the data to be fitted */
int j = 0;
for (MantidVec::size_type i = 0; i < Y.size(); ++i)
{
if (isMasked && masked[i]) continue;
gsl_vector_set(x, j, (isHistogram ? (0.5*(X[i]+X[i+1])) : X[i])); // Middle of the bins, if a histogram
gsl_vector_set(y, j, Y[i]);
gsl_vector_set(w, j, E[i]>0.?1./(E[i]*E[i]):0.);
++j;
}
if (n != j)
{
gsl_bspline_free(bw);
gsl_vector_free(B);
gsl_vector_free(x);
gsl_vector_free(y);
gsl_matrix_free(Z);
gsl_vector_free(c);
gsl_vector_free(w);
gsl_matrix_free(cov);
gsl_multifit_linear_free(mw);
throw std::runtime_error("Assertion failed: n != j");
}
double xStart = X.front();
double xEnd = X.back();
/* use uniform breakpoints */
gsl_bspline_knots_uniform(xStart, xEnd, bw);
/* construct the fit matrix X */
for (int i = 0; i < n; ++i)
{
double xi=gsl_vector_get(x, i);
/* compute B_j(xi) for all j */
gsl_bspline_eval(xi, B, bw);
//.........这里部分代码省略.........