本文整理汇总了C++中EventWorkspace_const_sptr::getEventList方法的典型用法代码示例。如果您正苦于以下问题:C++ EventWorkspace_const_sptr::getEventList方法的具体用法?C++ EventWorkspace_const_sptr::getEventList怎么用?C++ EventWorkspace_const_sptr::getEventList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventWorkspace_const_sptr
的用法示例。
在下文中一共展示了EventWorkspace_const_sptr::getEventList方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: progress
void FindCenterOfMassPosition2::exec()
{
MatrixWorkspace_sptr inputWSWvl = getProperty("InputWorkspace");
MatrixWorkspace_sptr inputWS;
// Option to exclude beam area
bool direct_beam = getProperty("DirectBeam");
//TODO: Need an input for the X bin to use, assume 0 for now
int specID = 0;
// Initial center location
double center_x = getProperty("CenterX");
double center_y = getProperty("CenterY");
const double tolerance = getProperty("Tolerance");
// Iteration cutoff
int max_iteration = 200;
// Radius of the beam area, in pixels
double beam_radius = getProperty("BeamRadius");
// Get the number of monitors. We assume that all monitors are stored in the first spectra
const int numSpec = static_cast<int>(inputWSWvl->getNumberHistograms());
// Set up the progress reporting object
Progress progress(this,0.0,1.0,max_iteration);
EventWorkspace_const_sptr inputEventWS = boost::dynamic_pointer_cast<const EventWorkspace>(inputWSWvl);
if(inputEventWS)
{
std::vector<double> y_values(numSpec);
std::vector<double> e_values(numSpec);
PARALLEL_FOR_NO_WSP_CHECK()
for (int i = 0; i < numSpec; i++)
{
double sum_i(0), err_i(0);
progress.report("Integrating events");
const EventList& el = inputEventWS->getEventList(i);
el.integrate(0,0,true,sum_i,err_i);
y_values[i] = sum_i;
e_values[i] = err_i;
}
IAlgorithm_sptr algo = createChildAlgorithm("CreateWorkspace", 0.7, 1.0);
algo->setProperty< std::vector<double> >("DataX", std::vector<double>(2,0.0) );
algo->setProperty< std::vector<double> >("DataY", y_values );
algo->setProperty< std::vector<double> >("DataE", e_values );
algo->setProperty<int>("NSpec", numSpec );
algo->execute();
inputWS = algo->getProperty("OutputWorkspace");
WorkspaceFactory::Instance().initializeFromParent(inputWSWvl, inputWS, false);
}
else
{
示例2: exec
/** Executes the algorithm
*/
void FilterByTime::exec()
{
EventWorkspace_const_sptr inputWS = this->getProperty("InputWorkspace");
// ---- Find the start/end times ----
DateAndTime start, stop;
double start_dbl, stop_dbl;
start_dbl = getProperty("StartTime");
stop_dbl = getProperty("StopTime");
std::string start_str, stop_str;
start_str = getPropertyValue("AbsoluteStartTime");
stop_str = getPropertyValue("AbsoluteStopTime");
if ( (start_str != "") && (stop_str != "") && (start_dbl <= 0.0) && (stop_dbl <= 0.0) )
{
// Use the absolute string
start = DateAndTime( start_str );
stop = DateAndTime( stop_str );
}
else if ( (start_str == "") && (stop_str == "") && ((start_dbl > 0.0) || (stop_dbl > 0.0)) )
{
// Use the relative times in seconds.
DateAndTime first = inputWS->getFirstPulseTime();
DateAndTime last = inputWS->getLastPulseTime();
start = first + start_dbl;
if (stop_dbl > 0.0)
{
stop = first + stop_dbl;
}
else
{
this->getLogger().debug() << "No end filter time specified - assuming last pulse" << std::endl;
stop = last + 10000.0; // so we get all events - needs to be past last pulse
}
}
else
{
//Either both or none were specified
throw std::invalid_argument("You need to specify either the StartTime or StopTime parameters; or both the AbsoluteStartTime and AbsoluteStopTime parameters; but not other combinations.");
}
if (stop <= start)
throw std::invalid_argument("The stop time should be larger than the start time.");
// Make a brand new EventWorkspace
EventWorkspace_sptr outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
// But we don't copy the data.
setProperty("OutputWorkspace", outputWS);
size_t numberOfSpectra = inputWS->getNumberHistograms();
// Initialise the progress reporting object
Progress prog(this,0.0,1.0,numberOfSpectra);
// Loop over the histograms (detector spectra)
PARALLEL_FOR_NO_WSP_CHECK()
for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i)
{
PARALLEL_START_INTERUPT_REGION
//Get the output event list (should be empty)
EventList& output_el = outputWS->getEventList(i);
//and this is the input event list
const EventList& input_el = inputWS->getEventList(i);
//Perform the filtering
input_el.filterByPulseTime(start, stop, output_el);
prog.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
//Now filter out the run, using the DateAndTime type.
outputWS->mutableRun().filterByTime(start, stop);
}
示例3: execEvent
/** Executes the algorithm
*@param localworkspace :: the input workspace
*@param indices :: set of indices to sum up
*/
void SumSpectra::execEvent(EventWorkspace_const_sptr localworkspace,
std::set<int> &indices) {
// Make a brand new EventWorkspace
EventWorkspace_sptr outputWorkspace =
boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create("EventWorkspace", 1, 2, 1));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(localworkspace,
outputWorkspace, true);
Progress progress(this, 0, 1, indices.size());
// Get the pointer to the output event list
EventList &outEL = outputWorkspace->getEventList(0);
outEL.setSpectrumNo(m_outSpecId);
outEL.clearDetectorIDs();
// Loop over spectra
std::set<int>::iterator it;
size_t numSpectra(0);
size_t numMasked(0);
size_t numZeros(0);
// for (int i = m_minSpec; i <= m_maxSpec; ++i)
for (it = indices.begin(); it != indices.end(); ++it) {
int i = *it;
// Don't go outside the range.
if ((i >= m_numberOfSpectra) || (i < 0)) {
g_log.error() << "Invalid index " << i
<< " was specified. Sum was aborted.\n";
break;
}
try {
// Get the detector object for this spectrum
Geometry::IDetector_const_sptr det = localworkspace->getDetector(i);
// Skip monitors, if the property is set to do so
if (!m_keepMonitors && det->isMonitor())
continue;
// Skip masked detectors
if (det->isMasked()) {
numMasked++;
continue;
}
} catch (...) {
// if the detector not found just carry on
}
numSpectra++;
// Add the event lists with the operator
const EventList &tOutEL = localworkspace->getEventList(i);
if (tOutEL.empty()) {
++numZeros;
}
outEL += tOutEL;
progress.report();
}
// Set all X bins on the output
cow_ptr<MantidVec> XValues;
XValues.access() = localworkspace->readX(0);
outputWorkspace->setAllX(XValues);
outputWorkspace->mutableRun().addProperty("NumAllSpectra", int(numSpectra),
"", true);
outputWorkspace->mutableRun().addProperty("NumMaskSpectra", int(numMasked),
"", true);
outputWorkspace->mutableRun().addProperty("NumZeroSpectra", int(numZeros), "",
true);
// Assign it to the output workspace property
setProperty("OutputWorkspace",
boost::dynamic_pointer_cast<MatrixWorkspace>(outputWorkspace));
}
示例4: exec
//.........这里部分代码省略.........
// Now, determine if the input workspace is actually an EventWorkspace
EventWorkspace_const_sptr eventInputWS =
boost::dynamic_pointer_cast<const EventWorkspace>(inputWS);
if (eventInputWS != NULL) {
//------- EventWorkspace as input -------------------------------------
EventWorkspace_sptr eventOutputWS =
boost::dynamic_pointer_cast<EventWorkspace>(outputWS);
if (inPlace && PreserveEvents) {
// -------------Rebin in-place, preserving events
// ----------------------------------------------
// This only sets the X axis. Actual rebinning will be done upon data
// access.
eventOutputWS->setAllX(XValues_new);
this->setProperty(
"OutputWorkspace",
boost::dynamic_pointer_cast<MatrixWorkspace>(eventOutputWS));
} else if (!inPlace && PreserveEvents) {
// -------- NOT in-place, but you want to keep events for some reason.
// ----------------------
// Must copy the event workspace to a new EventWorkspace (and bin that).
// Make a brand new EventWorkspace
eventOutputWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create(
"EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(
inputWS, eventOutputWS, false);
// You need to copy over the data as well.
eventOutputWS->copyDataFrom((*eventInputWS));
// This only sets the X axis. Actual rebinning will be done upon data
// access.
eventOutputWS->setAllX(XValues_new);
// Cast to the matrixOutputWS and save it
this->setProperty(
"OutputWorkspace",
boost::dynamic_pointer_cast<MatrixWorkspace>(eventOutputWS));
} else {
//--------- Different output, OR you're inplace but not preserving Events
//--- create a Workspace2D -------
g_log.information() << "Creating a Workspace2D from the EventWorkspace "
<< eventInputWS->getName() << ".\n";
// Create a Workspace2D
// This creates a new Workspace2D through a torturous route using the
// WorkspaceFactory.
// The Workspace2D is created with an EMPTY CONSTRUCTOR
outputWS = WorkspaceFactory::Instance().create("Workspace2D", histnumber,
ntcnew, ntcnew - 1);
WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS,
true);
// Initialize progress reporting.
Progress prog(this, 0.0, 1.0, histnumber);
// Go through all the histograms and set the data
PARALLEL_FOR3(inputWS, eventInputWS, outputWS)
for (int i = 0; i < histnumber; ++i) {
PARALLEL_START_INTERUPT_REGION
// Set the X axis for each output histogram
outputWS->setX(i, XValues_new);
// Get a const event list reference. eventInputWS->dataY() doesn't work.
const EventList &el = eventInputWS->getEventList(i);
MantidVec y_data, e_data;
// The EventList takes care of histogramming.
el.generateHistogram(*XValues_new, y_data, e_data);
// Copy the data over.
outputWS->dataY(i).assign(y_data.begin(), y_data.end());
outputWS->dataE(i).assign(e_data.begin(), e_data.end());
// Report progress
prog.report(name());
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
// Copy all the axes
for (int i = 1; i < inputWS->axes(); i++) {
outputWS->replaceAxis(i, inputWS->getAxis(i)->clone(outputWS.get()));
outputWS->getAxis(i)->unit() = inputWS->getAxis(i)->unit();
}
// Copy the units over too.
for (int i = 0; i < outputWS->axes(); ++i)
outputWS->getAxis(i)->unit() = inputWS->getAxis(i)->unit();
outputWS->setYUnit(eventInputWS->YUnit());
outputWS->setYUnitLabel(eventInputWS->YUnitLabel());
// Assign it to the output workspace property
setProperty("OutputWorkspace", outputWS);
}
} // END ---- EventWorkspace
示例5: exec
//.........这里部分代码省略.........
// copy over the data as well.
outputEventWS->copyDataFrom((*inputEventWS));
}
if (common_limits) {
// get the delta from the first since they are all the same
MantidVecPtr xValues;
double delta =
this->determineBinning(xValues.access(), xmins[0], xmaxs[0]);
g_log.debug() << "delta = " << delta << "\n";
outputEventWS->setAllX(xValues);
} else {
// initialize progress reporting.
Progress prog(this, 0.0, 1.0, numSpectra);
// do the rebinning
PARALLEL_FOR2(inputEventWS, outputWS)
for (int wkspIndex = 0; wkspIndex < numSpectra; ++wkspIndex) {
PARALLEL_START_INTERUPT_REGION
MantidVec xValues;
double delta = this->determineBinning(xValues, xmins[wkspIndex],
xmaxs[wkspIndex]);
g_log.debug() << "delta[wkspindex=" << wkspIndex << "] = " << delta
<< " xmin=" << xmins[wkspIndex]
<< " xmax=" << xmaxs[wkspIndex] << "\n";
outputEventWS->getSpectrum(wkspIndex)->setX(xValues);
prog.report(name()); // Report progress
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
}
this->setProperty(
"OutputWorkspace",
boost::dynamic_pointer_cast<MatrixWorkspace>(outputEventWS));
} // end if (m_preserveEvents)
else // event workspace -> matrix workspace
{
//--------- Different output, OR you're inplace but not preserving Events
//--- create a Workspace2D -------
g_log.information() << "Creating a Workspace2D from the EventWorkspace "
<< inputEventWS->getName() << ".\n";
// Create a Workspace2D
// This creates a new Workspace2D through a torturous route using the
// WorkspaceFactory.
// The Workspace2D is created with an EMPTY CONSTRUCTOR
outputWS = WorkspaceFactory::Instance().create("Workspace2D", numSpectra,
m_numBins, m_numBins - 1);
WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS,
true);
// Initialize progress reporting.
Progress prog(this, 0.0, 1.0, numSpectra);
// Go through all the histograms and set the data
PARALLEL_FOR2(inputEventWS, outputWS)
for (int wkspIndex = 0; wkspIndex < numSpectra; ++wkspIndex) {
PARALLEL_START_INTERUPT_REGION
// Set the X axis for each output histogram
MantidVec xValues;
double delta =
this->determineBinning(xValues, xmins[wkspIndex], xmaxs[wkspIndex]);
g_log.debug() << "delta[wkspindex=" << wkspIndex << "] = " << delta
<< "\n";
outputWS->setX(wkspIndex, xValues);
// Get a const event list reference. inputEventWS->dataY() doesn't work.
const EventList &el = inputEventWS->getEventList(wkspIndex);
MantidVec y_data, e_data;
// The EventList takes care of histogramming.
el.generateHistogram(xValues, y_data, e_data);
// Copy the data over.
outputWS->dataY(wkspIndex).assign(y_data.begin(), y_data.end());
outputWS->dataE(wkspIndex).assign(e_data.begin(), e_data.end());
// Report progress
prog.report(name());
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
// Copy all the axes
for (int i = 1; i < inputWS->axes(); i++) {
outputWS->replaceAxis(i, inputWS->getAxis(i)->clone(outputWS.get()));
outputWS->getAxis(i)->unit() = inputWS->getAxis(i)->unit();
}
// Copy the units over too.
for (int i = 0; i < outputWS->axes(); ++i)
outputWS->getAxis(i)->unit() = inputWS->getAxis(i)->unit();
outputWS->setYUnit(inputEventWS->YUnit());
outputWS->setYUnitLabel(inputEventWS->YUnitLabel());
// Assign it to the output workspace property
setProperty("OutputWorkspace", outputWS);
}
return;
} else // (inputeventWS != NULL)
示例6: exec
/** Executes the algorithm
*
* @throw Exception::FileError If the grouping file cannot be opened or read successfully
*/
void GetDetOffsetsMultiPeaks::exec()
{
const double BAD_OFFSET(1000.); // mark things that didn't work with this
MatrixWorkspace_sptr inputW=getProperty("InputWorkspace");
double maxOffset=getProperty("MaxOffset");
int nspec=static_cast<int>(inputW->getNumberHistograms());
// Create the output OffsetsWorkspace
OffsetsWorkspace_sptr outputW(new OffsetsWorkspace(inputW->getInstrument()));
// determine min/max d-spacing of the workspace
double wkspDmin, wkspDmax;
inputW->getXMinMax(wkspDmin, wkspDmax);
// Create the output MaskWorkspace
MatrixWorkspace_sptr maskWS(new MaskWorkspace(inputW->getInstrument()));
//To get the workspace index from the detector ID
detid2index_map * pixel_to_wi = maskWS->getDetectorIDToWorkspaceIndexMap(true);
// the peak positions and where to fit
std::vector<double> peakPositions = getProperty("DReference");
std::sort(peakPositions.begin(), peakPositions.end());
std::vector<double> fitWindows = generateWindows(wkspDmin, wkspDmax, peakPositions, this->getProperty("FitWindowMaxWidth"));
g_log.information() << "windows : ";
if (fitWindows.empty())
{
g_log.information() << "empty\n";
}
else
{
for (std::vector<double>::const_iterator it = fitWindows.begin(); it != fitWindows.end(); ++it)
g_log.information() << *it << " ";
g_log.information() << "\n";
}
// some shortcuts for event workspaces
EventWorkspace_const_sptr eventW = boost::dynamic_pointer_cast<const EventWorkspace>( inputW );
bool isEvent = false;
if (eventW)
isEvent = true;
// cache the peak and background function names
m_peakType = this->getPropertyValue("PeakFunction");
m_backType = this->getPropertyValue("BackgroundType");
// the maximum allowable chisq value for an individual peak fit
m_maxChiSq = this->getProperty("MaxChiSq");
// Fit all the spectra with a gaussian
Progress prog(this, 0, 1.0, nspec);
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1) )
for (int wi=0;wi<nspec;++wi)
{
PARALLEL_START_INTERUPT_REGION
double offset = 0.0;
double fitSum = 0.0;
// checks for dead detectors
if ((isEvent) && (eventW->getEventList(wi).empty()))
{
// dead detector will be masked
offset = BAD_OFFSET;
}
else {
const MantidVec& Y = inputW->readY(wi);
const int YLength = static_cast<int>(Y.size());
double sumY = 0.0;
for (int i = 0; i < YLength; i++) sumY += Y[i];
if (sumY < 1.e-30)
{
// Dead detector will be masked
offset=BAD_OFFSET;
}
}
if (offset < 10.)
{
// Fit the peak
std::vector<double> peakPosToFit, peakPosFitted, chisq;
size_t nparams;
double minD, maxD;
fitSpectra(wi, inputW, peakPositions, fitWindows, nparams, minD, maxD, peakPosToFit, peakPosFitted, chisq);
if (nparams > 0)
{
//double * params = new double[2*nparams+1];
double params[153];
if(nparams > 50) nparams = 50;
params[0] = static_cast<double>(nparams);
params[1] = minD;
params[2] = maxD;
for (size_t i = 0; i < nparams; i++)
{
params[i+3] = peakPosToFit[i];
}
for (size_t i = 0; i < nparams; i++)
{
params[i+3+nparams] = peakPosFitted[i];
}
for (size_t i = 0; i < nparams; i++)
{
params[i+3+2*nparams] = chisq[i];
//.........这里部分代码省略.........