本文整理汇总了C++中EventWorkspace_sptr::copyDataFrom方法的典型用法代码示例。如果您正苦于以下问题:C++ EventWorkspace_sptr::copyDataFrom方法的具体用法?C++ EventWorkspace_sptr::copyDataFrom怎么用?C++ EventWorkspace_sptr::copyDataFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventWorkspace_sptr
的用法示例。
在下文中一共展示了EventWorkspace_sptr::copyDataFrom方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execEvent
void ScaleX::execEvent()
{
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS = this->getProperty("InputWorkspace");
const std::string op = getPropertyValue("Operation");
EventWorkspace_const_sptr inputWS=boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS = this->getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS)
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
else
{
//Make a brand new EventWorkspace
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);
//You need to copy over the data as well.
outputWS->copyDataFrom( (*inputWS) );
//Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
this->setProperty("OutputWorkspace", matrixOutputWS);
}
int numHistograms = static_cast<int>(inputWS->getNumberHistograms());
PARALLEL_FOR1(outputWS)
for (int i=0; i < numHistograms; ++i)
{
PARALLEL_START_INTERUPT_REGION
//Do the offsetting
if ((i >= m_wi_min) && (i <= m_wi_max))
{
if(op=="Multiply")
{
outputWS->getEventList(i).scaleTof(getScaleFactor(inputWS, i));
if( m_algFactor < 0 )
{
outputWS->getEventList(i).reverse();
}
}
else if(op=="Add")
{
outputWS->getEventList(i).addTof(getScaleFactor(inputWS, i));
}
}
m_progress->report("Scaling X");
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
outputWS->clearMRU();
}
示例2: normaliseBinByBin
/** Carries out the bin-by-bin normalisation
* @param inputWorkspace The input workspace
* @param outputWorkspace The result workspace
*/
void NormaliseToMonitor::normaliseBinByBin(API::MatrixWorkspace_sptr inputWorkspace,
API::MatrixWorkspace_sptr& outputWorkspace)
{
EventWorkspace_sptr inputEvent = boost::dynamic_pointer_cast<EventWorkspace>(inputWorkspace);
EventWorkspace_sptr outputEvent;
// Only create output workspace if different to input one
if (outputWorkspace != inputWorkspace )
{
if (inputEvent)
{
//Make a brand new EventWorkspace
outputEvent = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create("EventWorkspace", inputEvent->getNumberHistograms(), 2, 1));
//Copy geometry and data
API::WorkspaceFactory::Instance().initializeFromParent(inputEvent, outputEvent, false);
outputEvent->copyDataFrom( (*inputEvent) );
outputWorkspace = boost::dynamic_pointer_cast<MatrixWorkspace>(outputEvent);
}
else
outputWorkspace = WorkspaceFactory::Instance().create(inputWorkspace);
}
// Get hold of the monitor spectrum
const MantidVec& monX = m_monitor->readX(0);
MantidVec& monY = m_monitor->dataY(0);
MantidVec& monE = m_monitor->dataE(0);
// Calculate the overall normalisation just the once if bins are all matching
if (m_commonBins) this->normalisationFactor(m_monitor->readX(0),&monY,&monE);
const size_t numHists = inputWorkspace->getNumberHistograms();
MantidVec::size_type specLength = inputWorkspace->blocksize();
Progress prog(this,0.0,1.0,numHists);
// Loop over spectra
PARALLEL_FOR3(inputWorkspace,outputWorkspace,m_monitor)
for (int64_t i = 0; i < int64_t(numHists); ++i)
{
PARALLEL_START_INTERUPT_REGION
prog.report();
const MantidVec& X = inputWorkspace->readX(i);
// If not rebinning, just point to our monitor spectra, otherwise create new vectors
MantidVec* Y = ( m_commonBins ? &monY : new MantidVec(specLength) );
MantidVec* E = ( m_commonBins ? &monE : new MantidVec(specLength) );
if (!m_commonBins)
{
// ConvertUnits can give X vectors of all zeroes - skip these, they cause problems
if (X.back() == 0.0 && X.front() == 0.0) continue;
// Rebin the monitor spectrum to match the binning of the current data spectrum
VectorHelper::rebinHistogram(monX,monY,monE,X,*Y,*E,false);
// Recalculate the overall normalisation factor
this->normalisationFactor(X,Y,E);
}
if (inputEvent)
{
// ----------------------------------- EventWorkspace ---------------------------------------
EventList & outEL = outputEvent->getEventList(i);
outEL.divide(X, *Y, *E);
}
else
{
// ----------------------------------- Workspace2D ---------------------------------------
const MantidVec& inY = inputWorkspace->readY(i);
const MantidVec& inE = inputWorkspace->readE(i);
MantidVec& YOut = outputWorkspace->dataY(i);
MantidVec& EOut = outputWorkspace->dataE(i);
outputWorkspace->dataX(i) = inputWorkspace->readX(i);
// The code below comes more or less straight out of Divide.cpp
for (MantidVec::size_type k = 0; k < specLength; ++k)
{
// Get references to the input Y's
const double& leftY = inY[k];
const double& rightY = (*Y)[k];
// Calculate result and store in local variable to avoid overwriting original data if
// output workspace is same as one of the input ones
const double newY = leftY/rightY;
if (fabs(rightY)>1.0e-12 && fabs(newY)>1.0e-12)
{
const double lhsFactor = (inE[k]<1.0e-12|| fabs(leftY)<1.0e-12) ? 0.0 : pow((inE[k]/leftY),2);
const double rhsFactor = (*E)[k]<1.0e-12 ? 0.0 : pow(((*E)[k]/rightY),2);
EOut[k] = std::abs(newY) * sqrt(lhsFactor+rhsFactor);
}
// Now store the result
YOut[k] = newY;
} // end Workspace2D case
} // end loop over current spectrum
if (!m_commonBins) { delete Y; delete E; }
PARALLEL_END_INTERUPT_REGION
} // end loop over spectra
//.........这里部分代码省略.........
示例3: execEvent
void SANSSolidAngleCorrection::execEvent() {
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
EventWorkspace_sptr inputEventWS =
boost::dynamic_pointer_cast<EventWorkspace>(inputWS);
const int numberOfSpectra =
static_cast<int>(inputEventWS->getNumberHistograms());
Progress progress(this, 0.0, 1.0, inputEventWS->getNumberHistograms());
// generate the output workspace pointer
MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");
EventWorkspace_sptr outputEventWS;
if (outputWS == inputWS)
outputEventWS = boost::dynamic_pointer_cast<EventWorkspace>(outputWS);
else {
// Make a brand new EventWorkspace
outputEventWS = boost::dynamic_pointer_cast<EventWorkspace>(
WorkspaceFactory::Instance().create(
"EventWorkspace", inputEventWS->getNumberHistograms(), 2, 1));
// Copy geometry over.
WorkspaceFactory::Instance().initializeFromParent(inputEventWS,
outputEventWS, false);
// You need to copy over the data as well.
outputEventWS->copyDataFrom((*inputEventWS));
// Cast to the matrixOutputWS and save it
outputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputEventWS);
this->setProperty("OutputWorkspace", outputWS);
}
progress.report("Solid Angle Correction");
PARALLEL_FOR2(inputEventWS, outputEventWS)
for (int i = 0; i < numberOfSpectra; i++) {
PARALLEL_START_INTERUPT_REGION
IDetector_const_sptr det;
try {
det = inputEventWS->getDetector(i);
} catch (Exception::NotFoundError &) {
g_log.warning() << "Spectrum index " << i
<< " has no detector assigned to it - discarding"
<< std::endl;
// Catch if no detector. Next line tests whether this happened - test
// placed
// outside here because Mac Intel compiler doesn't like 'continue' in a
// catch
// in an openmp block.
}
if (!det)
continue;
// Skip if we have a monitor or if the detector is masked.
if (det->isMonitor() || det->isMasked())
continue;
// Compute solid angle correction factor
const bool is_tube = getProperty("DetectorTubes");
const double tanTheta = tan(inputEventWS->detectorTwoTheta(det));
const double theta_term = sqrt(tanTheta * tanTheta + 1.0);
double corr;
if (is_tube) {
const double tanAlpha = tan(getYTubeAngle(det, inputWS));
const double alpha_term = sqrt(tanAlpha * tanAlpha + 1.0);
corr = alpha_term * theta_term * theta_term;
} else {
corr = theta_term * theta_term * theta_term;
}
EventList &el = outputEventWS->getEventList(i);
el *= corr;
progress.report("Solid Angle Correction");
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
setProperty("OutputMessage", "Solid angle correction applied");
}
示例4: execEvent
/// Executes the algorithm for events
void UnaryOperation::execEvent() {
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS =
this->getProperty(inputPropName());
EventWorkspace_const_sptr inputWS =
boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS =
this->getProperty(outputPropName());
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS) {
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
} else {
// Make a brand new EventWorkspace
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);
// You need to copy over the data as well.
outputWS->copyDataFrom((*inputWS));
// Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
this->setProperty("OutputWorkspace", matrixOutputWS);
}
// Now fetch any properties defined by concrete algorithm
retrieveProperties();
int64_t numHistograms = static_cast<int64_t>(inputWS->getNumberHistograms());
API::Progress prog = API::Progress(this, 0.0, 1.0, numHistograms);
PARALLEL_FOR1(outputWS)
for (int64_t i = 0; i < numHistograms; ++i) {
PARALLEL_START_INTERUPT_REGION
// switch to weighted events if needed, and use the appropriate helper
// function
EventList *evlist = outputWS->getEventListPtr(i);
switch (evlist->getEventType()) {
case TOF:
// Switch to weights if needed.
evlist->switchTo(WEIGHTED);
/* no break */
// Fall through
case WEIGHTED:
unaryOperationEventHelper(evlist->getWeightedEvents());
break;
case WEIGHTED_NOTIME:
unaryOperationEventHelper(evlist->getWeightedEventsNoTime());
break;
}
prog.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
outputWS->clearMRU();
if (inputWS->getNumberEvents() != outputWS->getNumberEvents()) {
g_log.information() << "Number of events has changed!!!" << std::endl;
}
}
示例5: execEvent
void ModeratorTzero::execEvent()
{
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS = getProperty("InputWorkspace");
EventWorkspace_const_sptr inputWS= boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
const size_t numHists = static_cast<size_t>(inputWS->getNumberHistograms());
Mantid::API::MatrixWorkspace_sptr matrixOutputWS = getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS)
{
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
}
else
{
//Make a brand new EventWorkspace
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(WorkspaceFactory::Instance().create("EventWorkspace", numHists, 2, 1));
//Copy geometry over.
WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
//You need to copy over the data as well.
outputWS->copyDataFrom( (*inputWS) );
//Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
setProperty("OutputWorkspace", matrixOutputWS);
}
//Get a pointer to the sample
IComponent_const_sptr sample = outputWS->getInstrument()->getSample();
// Loop over the spectra
Progress prog(this,0.0,1.0,numHists); //report progress of algorithm
PARALLEL_FOR1(outputWS)
for (int i = 0; i < static_cast<int>(numHists); ++i)
{
PARALLEL_START_INTERUPT_REGION
size_t wsIndex = static_cast<size_t>(i);
EventList &evlist=outputWS->getEventList(wsIndex);
if( evlist.getNumberEvents() > 0 ) //don't bother with empty lists
{
double L1=CalculateL1(matrixOutputWS, wsIndex); // distance from source to sample or monitor
double t2=CalculateT2(matrixOutputWS, wsIndex); // time from sample to detector
if(t2>=0) //t2 < 0 when no detector info is available
{
double tof, E1;
mu::Parser parser;
parser.DefineVar("incidentEnergy", &E1); // associate variable E1 to this parser
parser.SetExpr(m_formula);
E1=m_convfactor*(L1/m_t1min)*(L1/m_t1min);
double min_t0_next=parser.Eval(); // fast neutrons are shifted by min_t0_next, irrespective of tof
// fix the histogram bins
MantidVec &x=evlist.dataX();
for (MantidVec::iterator iter=x.begin(); iter!=x.end(); ++iter)
{
tof=*iter;
if(tof<m_t1min+t2)
tof-=min_t0_next;
else
tof-=CalculateT0(tof, L1, t2, E1, parser);
*iter=tof;
}
MantidVec tofs=evlist.getTofs();
for(unsigned int itof=0; itof<tofs.size(); itof++)
{
tof=tofs[itof]+0.002*(rand()%100 -50); // add a [-0.1,0.1] microsecond noise to avoid artifacts resulting from original tof data
if(tof<m_t1min+t2)
tof-=min_t0_next;
else
tof-=CalculateT0(tof, L1, t2, E1, parser);
tofs[itof]=tof;
}
evlist.setTofs(tofs);
evlist.setSortOrder(Mantid::DataObjects::EventSortType::UNSORTED);
}
}
prog.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
outputWS->clearMRU(); // Clears the Most Recent Used lists */
} // end of void ModeratorTzero::execEvent()
示例6: if
//.........这里部分代码省略.........
// --------------- Create the partial workspaces
// ------------------------------------------
// Vector of partial workspaces, for parallel processing.
std::vector<EventWorkspace_sptr> partWorkspaces;
std::vector<DasEvent *> buffers;
/// Pointer to the vector of events
typedef std::vector<TofEvent> *EventVector_pt;
/// Bare array of arrays of pointers to the EventVectors
EventVector_pt **eventVectors;
/// How many threads will we use?
size_t numThreads = 1;
if (parallelProcessing)
numThreads = size_t(PARALLEL_GET_MAX_THREADS);
partWorkspaces.resize(numThreads);
buffers.resize(numThreads);
eventVectors = new EventVector_pt *[numThreads];
// cppcheck-suppress syntaxError
PRAGMA_OMP( parallel for if (parallelProcessing) )
for (int i = 0; i < int(numThreads); i++) {
// This is the partial workspace we are about to create (if in parallel)
EventWorkspace_sptr partWS;
if (parallelProcessing) {
prog->report("Creating Partial Workspace");
// Create a partial workspace
partWS = EventWorkspace_sptr(new EventWorkspace());
// Make sure to initialize.
partWS->initialize(1, 1, 1);
// Copy all the spectra numbers and stuff (no actual events to copy
// though).
partWS->copyDataFrom(*workspace);
// Push it in the array
partWorkspaces[i] = partWS;
} else
partWS = workspace;
// Allocate the buffers
buffers[i] = new DasEvent[loadBlockSize];
// For each partial workspace, make an array where index = detector ID and
// value = pointer to the events vector
eventVectors[i] = new EventVector_pt[detid_max + 1];
EventVector_pt *theseEventVectors = eventVectors[i];
for (detid_t j = 0; j < detid_max + 1; j++) {
size_t wi = pixel_to_wkspindex[j];
// Save a POINTER to the vector<tofEvent>
theseEventVectors[j] = &partWS->getEventList(wi).getEvents();
}
}
g_log.debug() << tim << " to create " << partWorkspaces.size()
<< " workspaces for parallel loading." << std::endl;
prog->resetNumSteps(numBlocks, 0.1, 0.8);
// ---------------------------------- LOAD THE DATA --------------------------
PRAGMA_OMP( parallel for schedule(dynamic, 1) if (parallelProcessing) )
for (int blockNum = 0; blockNum < int(numBlocks); blockNum++) {
PARALLEL_START_INTERUPT_REGION
// Find the workspace for this particular thread
EventWorkspace_sptr ws;
size_t threadNum = 0;
示例7: execEvent
/**
* Execute the align detectors algorithm for an event workspace.
*/
void AlignDetectors::execEvent() {
// g_log.information("Processing event workspace");
// the calibration information is already read in at this point
// convert the input workspace into the event workspace we already know it is
const MatrixWorkspace_const_sptr matrixInputWS =
this->getProperty("InputWorkspace");
EventWorkspace_const_sptr inputWS =
boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS =
this->getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS)
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
else {
// Make a brand new EventWorkspace
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);
// You need to copy over the data as well.
outputWS->copyDataFrom((*inputWS));
// Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
this->setProperty("OutputWorkspace", matrixOutputWS);
}
// Set the final unit that our output workspace will have
setXAxisUnits(outputWS);
ConversionFactors converter = ConversionFactors(m_calibrationWS);
Progress progress(this, 0.0, 1.0, m_numberOfSpectra);
PARALLEL_FOR_NO_WSP_CHECK()
for (int64_t i = 0; i < m_numberOfSpectra; ++i) {
PARALLEL_START_INTERUPT_REGION
auto toDspacing = converter.getConversionFunc(
inputWS->getSpectrum(size_t(i))->getDetectorIDs());
outputWS->getEventList(i).convertTof(toDspacing);
progress.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
if (outputWS->getTofMin() < 0.) {
std::stringstream msg;
msg << "Something wrong with the calibration. Negative minimum d-spacing "
"created. d_min = " << outputWS->getTofMin() << " d_max "
<< outputWS->getTofMax();
g_log.warning(msg.str());
}
outputWS->clearMRU();
}
示例8: execEvent
void CorrectKiKf::execEvent()
{
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS = this->getProperty("InputWorkspace");
EventWorkspace_const_sptr inputWS= boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS = this->getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS)
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
else
{
//Make a brand new EventWorkspace
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);
//You need to copy over the data as well.
outputWS->copyDataFrom( (*inputWS) );
//Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
this->setProperty("OutputWorkspace", matrixOutputWS);
}
const std::string emodeStr = getProperty("EMode");
double efixedProp = getProperty("EFixed"),efixed;
if( efixedProp == EMPTY_DBL() )
{
if (emodeStr == "Direct")
{
// Check if it has been store on the run object for this workspace
if( this->inputWS->run().hasProperty("Ei"))
{
Kernel::Property* eiprop = this->inputWS->run().getProperty("Ei");
efixedProp = boost::lexical_cast<double>(eiprop->value());
g_log.debug() << "Using stored Ei value " << efixedProp << "\n";
}
else
{
throw std::invalid_argument("No Ei value has been set or stored within the run information.");
}
}
else
{
// If not specified, will try to get Ef from the parameter file for indirect geometry,
// but it will be done for each spectrum separately, in case of different analyzer crystals
}
}
// Get the parameter map
const ParameterMap& pmap = outputWS->constInstrumentParameters();
int64_t numHistograms = static_cast<int64_t>(inputWS->getNumberHistograms());
API::Progress prog = API::Progress(this, 0.0, 1.0, numHistograms);
PARALLEL_FOR1(outputWS)
for (int64_t i=0; i < numHistograms; ++i)
{
PARALLEL_START_INTERUPT_REGION
double Efi = 0;
// Now get the detector object for this histogram to check if monitor
// or to get Ef for indirect geometry
if (emodeStr == "Indirect")
{
if ( efixedProp != EMPTY_DBL()) Efi = efixedProp;
else try
{
IDetector_const_sptr det = inputWS->getDetector(i);
if (!det->isMonitor())
{
try
{
Parameter_sptr par = pmap.getRecursive(det.get(),"Efixed");
if (par)
{
Efi = par->value<double>();
g_log.debug() << "Detector: " << det->getID() << " EFixed: " << Efi << "\n";
}
}
catch (std::runtime_error&) { /* Throws if a DetectorGroup, use single provided value */ }
}
}
catch(std::runtime_error&) { g_log.information() << "Workspace Index " << i << ": cannot find detector" << "\n"; }
}
if (emodeStr == "Indirect") efixed=Efi;
else efixed=efixedProp;
//Do the correction
EventList *evlist=outputWS->getEventListPtr(i);
switch (evlist->getEventType())
{
case TOF:
//Switch to weights if needed.
evlist->switchTo(WEIGHTED);
//.........这里部分代码省略.........
示例9: exec
/** Executes the rebin algorithm
*
* @throw runtime_error Thrown if the bin range does not intersect the range of
*the input workspace
*/
void Rebin::exec() {
// Get the input workspace
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
// Are we preserving event workspace-iness?
bool PreserveEvents = getProperty("PreserveEvents");
// Rebinning in-place
bool inPlace = (inputWS == outputWS);
std::vector<double> rbParams =
rebinParamsFromInput(getProperty("Params"), *inputWS, g_log);
const bool dist = inputWS->isDistribution();
const bool isHist = inputWS->isHistogramData();
// workspace independent determination of length
const int histnumber = static_cast<int>(inputWS->getNumberHistograms());
//-------------------------------------------------------
bool fullBinsOnly = getProperty("FullBinsOnly");
MantidVecPtr XValues_new;
// create new output X axis
const int ntcnew = VectorHelper::createAxisFromRebinParams(
rbParams, XValues_new.access(), true, fullBinsOnly);
//---------------------------------------------------------------------------------
// 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
//.........这里部分代码省略.........
示例10: execEvent
/**
* Execute the align detectors algorithm for an event workspace.
*/
void AlignDetectors::execEvent()
{
//g_log.information("Processing event workspace");
// the calibration information is already read in at this point
// convert the input workspace into the event workspace we already know it is
const MatrixWorkspace_const_sptr matrixInputWS = this->getProperty("InputWorkspace");
EventWorkspace_const_sptr inputWS
= boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS = this->getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS)
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
else
{
//Make a brand new EventWorkspace
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);
//outputWS->mutableSpectraMap().clear();
//You need to copy over the data as well.
outputWS->copyDataFrom( (*inputWS) );
//Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
this->setProperty("OutputWorkspace", matrixOutputWS);
}
// Set the final unit that our output workspace will have
outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("dSpacing");
const int64_t numberOfSpectra = static_cast<int64_t>(inputWS->getNumberHistograms());
// Initialise the progress reporting object
Progress progress(this,0.0,1.0,numberOfSpectra);
PARALLEL_FOR_NO_WSP_CHECK()
for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i)
{
PARALLEL_START_INTERUPT_REGION
// Compute the conversion factor
double factor = calcConversionFromMap(this->tofToDmap, inputWS->getSpectrum(size_t(i))->getDetectorIDs());
//Perform the multiplication on all events
outputWS->getEventList(i).convertTof(factor);
progress.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
if (outputWS->getTofMin() < 0.)
{
std::stringstream msg;
msg << "Something wrong with the calibration. Negative minimum d-spacing created. d_min = "
<< outputWS->getTofMin() << " d_max " << outputWS->getTofMax();
throw std::runtime_error(msg.str());
}
outputWS->clearMRU();
}
示例11: execEvent
void ModeratorTzero::execEvent(const std::string &emode) {
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS =
getProperty("InputWorkspace");
EventWorkspace_const_sptr inputWS =
boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
const size_t numHists = static_cast<size_t>(inputWS->getNumberHistograms());
Mantid::API::MatrixWorkspace_sptr matrixOutputWS =
getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS) {
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
} else {
// Make a brand new EventWorkspace
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
WorkspaceFactory::Instance().create("EventWorkspace", numHists, 2, 1));
// Copy geometry over.
WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
// You need to copy over the data as well.
outputWS->copyDataFrom((*inputWS));
// Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
setProperty("OutputWorkspace", matrixOutputWS);
}
// Get pointers to sample and source
IComponent_const_sptr source = m_instrument->getSource();
IComponent_const_sptr sample = m_instrument->getSample();
double Lss = source->getDistance(*sample); // distance from source to sample
// calculate tof shift once for all neutrons if emode==Direct
double t0_direct(-1);
if (emode == "Direct") {
Kernel::Property *eiprop = inputWS->run().getProperty("Ei");
double Ei = boost::lexical_cast<double>(eiprop->value());
mu::Parser parser;
parser.DefineVar("incidentEnergy", &Ei); // associate E1 to this parser
parser.SetExpr(m_formula);
t0_direct = parser.Eval();
}
// Loop over the spectra
Progress prog(this, 0.0, 1.0, numHists); // report progress of algorithm
PARALLEL_FOR1(outputWS)
for (int i = 0; i < static_cast<int>(numHists); ++i) {
PARALLEL_START_INTERUPT_REGION
size_t wsIndex = static_cast<size_t>(i);
EventList &evlist = outputWS->getEventList(wsIndex);
if (evlist.getNumberEvents() > 0) // don't bother with empty lists
{
IDetector_const_sptr det;
double L1(Lss); // distance from source to sample
double L2(-1); // distance from sample to detector
try {
det = inputWS->getDetector(i);
if (det->isMonitor()) {
// redefine the sample as the monitor
L1 = source->getDistance(*det);
L2 = 0;
} else {
L2 = sample->getDistance(*det);
}
} catch (Exception::NotFoundError &) {
g_log.error() << "Unable to calculate distances to/from detector" << i
<< std::endl;
}
if (L2 >= 0) {
// One parser for each parallel processor needed (except Edirect mode)
double E1;
mu::Parser parser;
parser.DefineVar("incidentEnergy", &E1); // associate E1 to this parser
parser.SetExpr(m_formula);
// fast neutrons are shifted by min_t0_next, irrespective of tof
double v1_max = L1 / m_t1min;
E1 = m_convfactor * v1_max * v1_max;
double min_t0_next = parser.Eval();
if (emode == "Indirect") {
double t2(-1.0); // time from sample to detector. (-1) signals error
if (det->isMonitor()) {
t2 = 0.0;
} else {
static const double convFact =
1.0e-6 * sqrt(2 * PhysicalConstants::meV /
PhysicalConstants::NeutronMass);
std::vector<double> wsProp = det->getNumberParameter("Efixed");
if (!wsProp.empty()) {
double E2 = wsProp.at(0); //[E2]=meV
double v2 = convFact * sqrt(E2); //[v2]=meter/microsec
t2 = L2 / v2;
} else {
// t2 is kept to -1 if no Efixed is found
g_log.debug() << "Efixed not found for detector " << i
<< std::endl;
//.........这里部分代码省略.........
示例12: exec
/** Execute the algorithm.
*/
void ResampleX::exec() {
// generically having access to the input workspace is a good idea
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
bool inPlace = (inputWS == outputWS); // Rebinning in-place
m_isDistribution = inputWS->isDistribution();
m_isHistogram = inputWS->isHistogramData();
int numSpectra = static_cast<int>(inputWS->getNumberHistograms());
// the easy parameters
m_useLogBinning = getProperty("LogBinning");
m_numBins = getProperty("NumberBins");
m_preserveEvents = getProperty("PreserveEvents");
// determine the xmin/xmax for the workspace
vector<double> xmins = getProperty("XMin");
vector<double> xmaxs = getProperty("XMax");
string error = determineXMinMax(inputWS, xmins, xmaxs);
if (!error.empty())
throw std::runtime_error(error);
bool common_limits = true;
{
double xmin_common = xmins[0];
double xmax_common = xmaxs[0];
for (size_t i = 1; i < xmins.size(); ++i) {
if (xmins[i] != xmin_common) {
common_limits = false;
break;
}
if (xmaxs[i] != xmax_common) {
common_limits = false;
break;
}
}
}
if (common_limits) {
g_log.debug() << "Common limits between all spectra\n";
} else {
g_log.debug() << "Does not have common limits between all spectra\n";
}
// start doing actual work
EventWorkspace_const_sptr inputEventWS =
boost::dynamic_pointer_cast<const EventWorkspace>(inputWS);
if (inputEventWS != NULL) {
if (m_preserveEvents) {
EventWorkspace_sptr outputEventWS =
boost::dynamic_pointer_cast<EventWorkspace>(outputWS);
if (inPlace) {
g_log.debug() << "Rebinning event workspace in place\n";
} else {
g_log.debug() << "Rebinning event workspace out of place\n";
// copy the event workspace to a new EventWorkspace
outputEventWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create(
"EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
// copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(
inputEventWS, outputEventWS, false);
// 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
//.........这里部分代码省略.........