本文整理汇总了C++中typenameMDEventWorkspace::getDimension方法的典型用法代码示例。如果您正苦于以下问题:C++ typenameMDEventWorkspace::getDimension方法的具体用法?C++ typenameMDEventWorkspace::getDimension怎么用?C++ typenameMDEventWorkspace::getDimension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typenameMDEventWorkspace
的用法示例。
在下文中一共展示了typenameMDEventWorkspace::getDimension方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addFakeUniformData
void FakeMDEventData::addFakeUniformData(
typename MDEventWorkspace<MDE, nd>::sptr ws) {
std::vector<double> params = getProperty("UniformParams");
if (params.empty())
return;
bool randomEvents = true;
if (params[0] < 0) {
randomEvents = false;
params[0] = -params[0];
}
if (params.size() == 1) {
if (randomEvents) {
for (size_t d = 0; d < nd; ++d) {
params.push_back(ws->getDimension(d)->getMinimum());
params.push_back(ws->getDimension(d)->getMaximum());
}
} else // regular events
{
size_t nPoints = size_t(params[0]);
double Vol = 1;
for (size_t d = 0; d < nd; ++d)
Vol *= (ws->getDimension(d)->getMaximum() -
ws->getDimension(d)->getMinimum());
if (Vol == 0 || Vol > std::numeric_limits<float>::max())
throw std::invalid_argument(
" Domain ranges are not defined properly for workspace: " +
ws->getName());
double dV = Vol / double(nPoints);
double delta0 = std::pow(dV, 1. / double(nd));
for (size_t d = 0; d < nd; ++d) {
double min = ws->getDimension(d)->getMinimum();
params.push_back(min * (1 + FLT_EPSILON) - min + FLT_EPSILON);
double extent = ws->getDimension(d)->getMaximum() - min;
size_t nStrides = size_t(extent / delta0);
if (nStrides < 1)
nStrides = 1;
params.push_back(extent / static_cast<double>(nStrides));
}
}
}
if ((params.size() != 1 + nd * 2))
throw std::invalid_argument(
"UniformParams: needs to have ndims*2+1 arguments ");
if (randomEvents)
addFakeRandomData<MDE, nd>(params, ws);
else
addFakeRegularData<MDE, nd>(params, ws);
ws->splitBox();
Kernel::ThreadScheduler *ts = new ThreadSchedulerFIFO();
ThreadPool tp(ts);
ws->splitAllIfNeeded(ts);
tp.joinAll();
ws->refreshCache();
}
示例2: findPeaks
void FindPeaksMD::findPeaks(typename MDEventWorkspace<MDE, nd>::sptr ws)
{
if (nd < 3)
throw std::invalid_argument("Workspace must have at least 3 dimensions.");
progress(0.01, "Refreshing Centroids");
// TODO: This might be slow, progress report?
// Make sure all centroids are fresh
ws->getBox()->refreshCentroid();
typedef IMDBox<MDE,nd>* boxPtr;
if (ws->getNumExperimentInfo() == 0)
throw std::runtime_error("No instrument was found in the MDEventWorkspace. Cannot find peaks.");
// TODO: Do we need to pick a different instrument info?
ExperimentInfo_sptr ei = ws->getExperimentInfo(0);
// Instrument associated with workspace
Geometry::Instrument_const_sptr inst = ei->getInstrument();
// Find the run number
int runNumber = ei->getRunNumber();
// Check that the workspace dimensions are in Q-sample-frame or Q-lab-frame.
eDimensionType dimType;
std::string dim0 = ws->getDimension(0)->getName();
if (dim0 == "H")
{
dimType = HKL;
throw std::runtime_error("Cannot find peaks in a workspace that is already in HKL space.");
}
else if (dim0 == "Q_lab_x")
{
dimType = QLAB;
}
else if (dim0 == "Q_sample_x")
dimType = QSAMPLE;
else
throw std::runtime_error("Unexpected dimensions: need either Q_lab_x or Q_sample_x.");
// Find the goniometer rotation matrix
Mantid::Kernel::Matrix<double> goniometer(3,3, true); // Default IDENTITY matrix
try
{
goniometer = ei->mutableRun().getGoniometerMatrix();
}
catch (std::exception & e)
{
g_log.warning() << "Error finding goniometer matrix. It will not be set in the peaks found." << std::endl;
g_log.warning() << e.what() << std::endl;
}
/// Arbitrary scaling factor for density to make more manageable numbers, especially for older file formats.
signal_t densityScalingFactor = 1e-6;
// Calculate a threshold below which a box is too diffuse to be considered a peak.
signal_t thresholdDensity = 0.0;
thresholdDensity = ws->getBox()->getSignalNormalized() * DensityThresholdFactor * densityScalingFactor;
g_log.notice() << "Threshold signal density: " << thresholdDensity << std::endl;
// We will fill this vector with pointers to all the boxes (up to a given depth)
typename std::vector<boxPtr> boxes;
// Get all the MDboxes
progress(0.10, "Getting Boxes");
ws->getBox()->getBoxes(boxes, 1000, true);
// TODO: Here keep only the boxes > e.g. 3 * mean.
typedef std::pair<double, boxPtr> dens_box;
// Map that will sort the boxes by increasing density. The key = density; value = box *.
typename std::multimap<double, boxPtr> sortedBoxes;
progress(0.20, "Sorting Boxes by Density");
typename std::vector<boxPtr>::iterator it1;
typename std::vector<boxPtr>::iterator it1_end = boxes.end();
for (it1 = boxes.begin(); it1 != it1_end; it1++)
{
boxPtr box = *it1;
double density = box->getSignalNormalized() * densityScalingFactor;
// Skip any boxes with too small a signal density.
if (density > thresholdDensity)
sortedBoxes.insert(dens_box(density,box));
}
// List of chosen possible peak boxes.
std::vector<boxPtr> peakBoxes;
prog = new Progress(this, 0.30, 0.95, MaxPeaks);
int64_t numBoxesFound = 0;
// Now we go (backwards) through the map
// e.g. from highest density down to lowest density.
typename std::multimap<double, boxPtr>::reverse_iterator it2;
typename std::multimap<double, boxPtr>::reverse_iterator it2_end = sortedBoxes.rend();
for (it2 = sortedBoxes.rbegin(); it2 != it2_end; it2++)
{
//.........这里部分代码省略.........
示例3: addFakeRegularData
void FakeMDEventData::addFakeRegularData(
const std::vector<double> ¶ms,
typename MDEventWorkspace<MDE, nd>::sptr ws) {
// the parameters for regular distribution of events over the box
std::vector<double> startPoint(nd), delta(nd);
std::vector<size_t> indexMax(nd);
size_t gridSize(0);
// bool RandomizeSignal = getProperty("RandomizeSignal");
size_t num = size_t(params[0]);
if (num == 0)
throw std::invalid_argument(
" number of distributed events can not be equal to 0");
Progress prog(this, 0.0, 1.0, 100);
size_t progIncrement = num / 100;
if (progIncrement == 0)
progIncrement = 1;
// Inserter to help choose the correct event type
auto eventHelper =
MDEvents::MDEventInserter<typename MDEventWorkspace<MDE, nd>::sptr>(ws);
gridSize = 1;
for (size_t d = 0; d < nd; ++d) {
double min = ws->getDimension(d)->getMinimum();
double max = ws->getDimension(d)->getMaximum();
double shift = params[d * 2 + 1];
double step = params[d * 2 + 2];
if (shift < 0)
shift = 0;
if (shift >= step)
shift = step * (1 - FLT_EPSILON);
startPoint[d] = min + shift;
if ((startPoint[d] < min) || (startPoint[d] >= max))
throw std::invalid_argument("RegularData: starting point must be within "
"the box for all dimensions.");
if (step <= 0)
throw(std::invalid_argument(
"Step of the regular grid is less or equal to 0"));
indexMax[d] = size_t((max - min) / step);
if (indexMax[d] == 0)
indexMax[d] = 1;
// deal with round-off errors
while ((startPoint[d] + double(indexMax[d] - 1) * step) >= max)
step *= (1 - FLT_EPSILON);
delta[d] = step;
gridSize *= indexMax[d];
}
// Create all the requested events
std::vector<size_t> indexes;
size_t cellCount(0);
for (size_t i = 0; i < num; ++i) {
coord_t centers[nd];
Kernel::Utils::getIndicesFromLinearIndex(cellCount, indexMax, indexes);
++cellCount;
if (cellCount >= gridSize)
cellCount = 0;
for (size_t d = 0; d < nd; d++) {
centers[d] = coord_t(startPoint[d] + delta[d] * double(indexes[d]));
}
// Default or randomized error/signal
float signal = 1.0;
float errorSquared = 1.0;
// if (RandomizeSignal)
//{
// signal = float(0.5 + genUnit());
// errorSquared = float(0.5 + genUnit());
//}
// Create and add the event.
eventHelper.insertMDEvent(signal, errorSquared, 1, pickDetectorID(),
centers); // 1 = run number
// Progress report
if ((i % progIncrement) == 0)
prog.report();
}
}