本文整理汇总了C++中Workspace2D_sptr::dataE方法的典型用法代码示例。如果您正苦于以下问题:C++ Workspace2D_sptr::dataE方法的具体用法?C++ Workspace2D_sptr::dataE怎么用?C++ Workspace2D_sptr::dataE使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workspace2D_sptr
的用法示例。
在下文中一共展示了Workspace2D_sptr::dataE方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/** Sets error of workspace to specified value
*
* Since an estimation of the error is calculated from background counts, this
*value is assigned to the workspace via this method.
*
* @param correlationWorkspace :: Workspace containing the correlation spectrum
*on which the peak search was performed.
* @param error :: Error that is set on the workspace.
*/
void
PoldiPeakSearch::setErrorsOnWorkspace(Workspace2D_sptr correlationWorkspace,
double error) const {
MantidVec &errors = correlationWorkspace->dataE(0);
std::fill(errors.begin(), errors.end(), error);
}
示例2: recurseData
void MDHistoToWorkspace2D::recurseData(IMDHistoWorkspace_sptr inWS,
Workspace2D_sptr outWS,
size_t currentDim, coord_t *pos) {
boost::shared_ptr<const IMDDimension> dim = inWS->getDimension(currentDim);
if (currentDim == rank - 1) {
MantidVec &Y = outWS->dataY(currentSpectra);
for (unsigned int j = 0; j < dim->getNBins(); j++) {
pos[currentDim] = dim->getX(j);
Y[j] = inWS->getSignalAtCoord(
pos, static_cast<Mantid::API::MDNormalization>(0));
}
MantidVec &E = outWS->dataE(currentSpectra);
// MSVC compiler can't figure out the correct overload with out the function
// cast on sqrt
std::transform(Y.begin(), Y.end(), E.begin(),
(double (*)(double))std::sqrt);
std::vector<double> xData;
for (unsigned int i = 0; i < dim->getNBins(); i++) {
xData.push_back(dim->getX(i));
}
outWS->setX(currentSpectra, xData);
outWS->getSpectrum(currentSpectra)
->setSpectrumNo(static_cast<specid_t>(currentSpectra));
currentSpectra++;
} else {
// recurse deeper
for (int i = 0; i < static_cast<int>(dim->getNBins()); i++) {
pos[currentDim] = dim->getX(i);
recurseData(inWS, outWS, currentDim + 1, pos);
}
}
}
示例3: runtime_error
/** Remove peaks from a input workspace
*/
Workspace2D_sptr
RemovePeaks::removePeaks(API::MatrixWorkspace_const_sptr dataws, int wsindex,
double numfwhm) {
// Check
if (m_vecPeakCentre.empty())
throw runtime_error("RemovePeaks has not been setup yet. ");
// Initialize vectors
const MantidVec &vecX = dataws->readX(wsindex);
const MantidVec &vecY = dataws->readY(wsindex);
const MantidVec &vecE = dataws->readE(wsindex);
size_t sizex = vecX.size();
vector<bool> vec_useX(sizex, true);
// Exclude regions
size_t numbkgdpoints =
excludePeaks(vecX, vec_useX, m_vecPeakCentre, m_vecPeakFWHM, numfwhm);
size_t numbkgdpointsy = numbkgdpoints;
size_t sizey = vecY.size();
if (sizex > sizey)
--numbkgdpointsy;
// Construct output workspace
Workspace2D_sptr outws = boost::dynamic_pointer_cast<Workspace2D>(
WorkspaceFactory::Instance().create("Workspace2D", 1, numbkgdpoints,
numbkgdpointsy));
outws->getAxis(0)->setUnit(dataws->getAxis(0)->unit()->unitID());
MantidVec &outX = outws->dataX(0);
MantidVec &outY = outws->dataY(0);
MantidVec &outE = outws->dataE(0);
size_t index = 0;
for (size_t i = 0; i < sizex; ++i) {
if (vec_useX[i]) {
if (index >= numbkgdpoints)
throw runtime_error("Programming logic error (1)");
outX[index] = vecX[i];
++index;
}
}
index = 0;
for (size_t i = 0; i < sizey; ++i) {
if (vec_useX[i]) {
if (index >= numbkgdpointsy)
throw runtime_error("Programming logic error (2)");
outY[index] = vecY[i];
outE[index] = vecE[i];
++index;
}
}
return outws;
}
示例4: readDataToWorkspace
/**
* Reads the data (FITS matrix) from a single FITS file into a
* workspace (directly into the spectra, using one spectrum per image
* row).
*
* @param fileInfo information on the FITS file to load, including its path
* @param cmpp centimeters per pixel, to scale/normalize values
* @param ws workspace with the required dimensions
* @param buffer pre-allocated buffer to read from file
*
* @throws std::runtime_error if there are file input issues
*/
void LoadFITS::readDataToWorkspace(const FITSInfo &fileInfo, double cmpp,
Workspace2D_sptr ws,
std::vector<char> &buffer) {
const size_t bytespp = (fileInfo.bitsPerPixel / 8);
const size_t len = m_pixelCount * bytespp;
readInBuffer(fileInfo, buffer, len);
const size_t nrows(fileInfo.axisPixelLengths[1]),
ncols(fileInfo.axisPixelLengths[0]);
// Treat buffer as a series of bytes
uint8_t *buffer8 = reinterpret_cast<uint8_t *>(buffer.data());
PARALLEL_FOR_NO_WSP_CHECK()
for (int i = 0; i < static_cast<int>(nrows); ++i) {
auto &dataX = ws->dataX(i);
auto &dataY = ws->dataY(i);
auto &dataE = ws->dataE(i);
std::fill(dataX.begin(), dataX.end(), static_cast<double>(i) * cmpp);
for (size_t j = 0; j < ncols; ++j) {
// Map from 2D->1D index
const size_t start = ((i * (bytespp)) * nrows) + (j * (bytespp));
uint8_t const *const buffer8Start = buffer8 + start;
// Reverse byte order of current value. Make sure we allocate enough
// enough space to hold the size
uint8_t byteValue[g_maxBytesPP];
std::reverse_copy(buffer8Start, buffer8Start + bytespp, byteValue);
double val = 0;
if (fileInfo.bitsPerPixel == 8) {
val = toDouble<uint8_t>(byteValue);
} else if (fileInfo.bitsPerPixel == 16) {
val = toDouble<uint16_t>(byteValue);
} else if (fileInfo.bitsPerPixel == 32 && !fileInfo.isFloat) {
val = toDouble<uint32_t>(byteValue);
} else if (fileInfo.bitsPerPixel == 64 && !fileInfo.isFloat) {
val = toDouble<uint32_t>(byteValue);
} else if (fileInfo.bitsPerPixel == 32 && fileInfo.isFloat) {
val = toDouble<float>(byteValue);
} else if (fileInfo.bitsPerPixel == 64 && fileInfo.isFloat) {
val = toDouble<double>(byteValue);
}
val = fileInfo.scale * val - fileInfo.offset;
dataY[j] = val;
dataE[j] = sqrt(val);
}
}
}
示例5: values
/** Filter non-background data points out and create a background workspace
*/
Workspace2D_sptr
ProcessBackground::filterForBackground(BackgroundFunction_sptr bkgdfunction) {
double posnoisetolerance = getProperty("NoiseTolerance");
double negnoisetolerance = getProperty("NegativeNoiseTolerance");
if (isEmpty(negnoisetolerance))
negnoisetolerance = posnoisetolerance;
// Calcualte theoretical values
const std::vector<double> x = m_dataWS->readX(m_wsIndex);
API::FunctionDomain1DVector domain(x);
API::FunctionValues values(domain);
bkgdfunction->function(domain, values);
g_log.information() << "Function used to select background points : "
<< bkgdfunction->asString() << "\n";
// Optional output
string userbkgdwsname = getPropertyValue("UserBackgroundWorkspace");
if (userbkgdwsname.size() == 0)
throw runtime_error("In mode SelectBackgroundPoints, "
"UserBackgroundWorkspace must be given!");
size_t sizex = domain.size();
size_t sizey = values.size();
MatrixWorkspace_sptr visualws = boost::dynamic_pointer_cast<MatrixWorkspace>(
WorkspaceFactory::Instance().create("Workspace2D", 4, sizex, sizey));
for (size_t i = 0; i < sizex; ++i) {
for (size_t j = 0; j < 4; ++j) {
visualws->dataX(j)[i] = domain[i];
}
}
for (size_t i = 0; i < sizey; ++i) {
visualws->dataY(0)[i] = values[i];
visualws->dataY(1)[i] = m_dataWS->readY(m_wsIndex)[i] - values[i];
visualws->dataY(2)[i] = posnoisetolerance;
visualws->dataY(3)[i] = -negnoisetolerance;
}
setProperty("UserBackgroundWorkspace", visualws);
// Filter for background
std::vector<double> vecx, vecy, vece;
for (size_t i = 0; i < domain.size(); ++i) {
// double y = m_dataWS->readY(m_wsIndex)[i];
// double theoryy = values[i]; y-theoryy
double purey = visualws->readY(1)[i];
if (purey < posnoisetolerance && purey > -negnoisetolerance) {
// Selected
double x = domain[i];
double y = m_dataWS->readY(m_wsIndex)[i];
double e = m_dataWS->readE(m_wsIndex)[i];
vecx.push_back(x);
vecy.push_back(y);
vece.push_back(e);
}
}
g_log.information() << "Found " << vecx.size() << " background points out of "
<< m_dataWS->readX(m_wsIndex).size()
<< " total data points. "
<< "\n";
// Build new workspace for OutputWorkspace
size_t nspec = 3;
Workspace2D_sptr outws =
boost::dynamic_pointer_cast<DataObjects::Workspace2D>(
API::WorkspaceFactory::Instance().create("Workspace2D", nspec,
vecx.size(), vecy.size()));
for (size_t i = 0; i < vecx.size(); ++i) {
for (size_t j = 0; j < nspec; ++j)
outws->dataX(j)[i] = vecx[i];
outws->dataY(0)[i] = vecy[i];
outws->dataE(0)[i] = vece[i];
}
return outws;
}
示例6: exec
/**
* Executes the algorithm.
* Saves the workspace specified by the user to the VTK XML format
*/
void SaveVTK::exec()
{
std::string filename = getProperty("Filename");
g_log.debug() << "Parameters: Filename='" << filename << "'" << std::endl;
//add extension
filename += ".vtu";
MatrixWorkspace_sptr inputWorkspace = getProperty("InputWorkspace");
if( !inputWorkspace )
{
g_log.error("Failed to retrieve inputWorkspace.");
throw Exception::NullPointerException("SaveVTK::exec()", "inputWorkspace");
}
checkOptionalProperties();
//Open file for writing
std::ofstream outVTP(filename.c_str());
if( !outVTP )
{
g_log.error("Failed to open file: " + filename);
throw Exception::FileError("Failed to open file ", filename);
}
// First write document level XML header
outVTP << "<?xml version=\"1.0\"?>\n"
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n"
"<UnstructuredGrid>\n";
const std::string workspaceID = inputWorkspace->id();
if( workspaceID.find("Workspace2D") != std::string::npos )
{
const Workspace2D_sptr localWorkspace =
boost::dynamic_pointer_cast<Workspace2D>(inputWorkspace);
// const size_t numberOfHist = localWorkspace->getNumberHistograms();
//Write out whole range
bool xMin(m_Xmin > 0.0), xMax(m_Xmax > 0.0);
Progress prog(this,0.0,1.0,97);
if( !xMin && !xMax )
{
for( int hNum = 2; hNum < 100; ++hNum )
{
writeVTKPiece(outVTP, localWorkspace->dataX(hNum), localWorkspace->dataY(hNum),
localWorkspace->dataE(hNum), hNum);
prog.report();
}
}
else
{
for( int hNum = 2; hNum < 100; ++hNum )
{
std::vector<double> xValue, yValue, errors;
std::vector<double>::size_type nVals(localWorkspace->dataY(hNum).size());
for( int i = 0; i < (int)nVals; ++i )
{
if( xMin && localWorkspace->dataX(hNum)[i] < m_Xmin ) continue;
if( xMax && localWorkspace->dataX(hNum)[i+1] > m_Xmax)
{
xValue.push_back(localWorkspace->dataX(hNum)[i]);
break;
}
xValue.push_back(localWorkspace->dataX(hNum)[i]);
if( i == (int)nVals - 1 )
{
xValue.push_back(localWorkspace->dataX(hNum)[i+1]);
}
yValue.push_back(localWorkspace->dataY(hNum)[i]);
errors.push_back(localWorkspace->dataE(hNum)[i]);
}
//sanity check
assert( (int)xValue.size() == (int)yValue.size() + 1 );
writeVTKPiece(outVTP, xValue, yValue, errors, hNum);
prog.report();
}
}
}
else
{
outVTP.close();
Poco::File(filename).remove();
throw Exception::NotImplementedError("SaveVTK only implemented for Workspace2D\n");
}
// Final XML end block tags
outVTP << "</UnstructuredGrid>\n</VTKFile>\n";
outVTP.close();
}