/** * Execute the algorithm. */ void FitResolutionConvolvedModel::exec() { API::IAlgorithm_sptr fit = createFittingAlgorithm(); fit->setPropertyValue("Function", createFunctionString()); fit->setProperty("InputWorkspace", getPropertyValue(INPUT_WS_NAME)); fit->setProperty("DomainType", "Simple"); // Parallel not quite giving correct answers fit->setProperty("Minimizer", "Levenberg-MarquardtMD"); const int maxIter = niterations(); fit->setProperty("MaxIterations", maxIter); fit->setProperty("CreateOutput", true); fit->setPropertyValue("Output", getPropertyValue(SIMULATED_NAME)); try { fit->execute(); } catch (std::exception &exc) { throw std::runtime_error( std::string("FitResolutionConvolvedModel - Error running Fit: ") + exc.what()); } // Pass on the relevant properties IMDEventWorkspace_sptr simulatedData = fit->getProperty("OutputWorkspace"); this->setProperty(SIMULATED_NAME, simulatedData); if (this->existsProperty(OUTPUT_PARS)) { ITableWorkspace_sptr outputPars = fit->getProperty("OutputParameters"); setProperty(OUTPUT_PARS, outputPars); } if (this->existsProperty(OUTPUTCOV_MATRIX)) { ITableWorkspace_sptr covarianceMatrix = fit->getProperty("OutputNormalisedCovarianceMatrix"); setProperty(OUTPUTCOV_MATRIX, covarianceMatrix); } }
/** Perform SortHKL on the output workspaces * * @param ws :: any PeaksWorkspace * @param runName :: string to put in statistics table */ void StatisticsOfPeaksWorkspace::doSortHKL(Mantid::API::Workspace_sptr ws, std::string runName) { std::string pointGroup = getPropertyValue("PointGroup"); std::string latticeCentering = getPropertyValue("LatticeCentering"); std::string wkspName = getPropertyValue("OutputWorkspace"); std::string tableName = getPropertyValue("StatisticsTable"); API::IAlgorithm_sptr statsAlg = createChildAlgorithm("SortHKL"); statsAlg->setProperty("InputWorkspace", ws); statsAlg->setPropertyValue("OutputWorkspace", wkspName); statsAlg->setPropertyValue("StatisticsTable", tableName); statsAlg->setProperty("PointGroup", pointGroup); statsAlg->setProperty("LatticeCentering", latticeCentering); statsAlg->setProperty("RowName", runName); if (runName.compare("Overall") != 0) statsAlg->setProperty("Append", true); statsAlg->executeAsChildAlg(); PeaksWorkspace_sptr statsWksp = statsAlg->getProperty("OutputWorkspace"); ITableWorkspace_sptr tablews = statsAlg->getProperty("StatisticsTable"); if (runName.compare("Overall") == 0) setProperty("OutputWorkspace", statsWksp); setProperty("StatisticsTable", tablews); }
/// Run ConvertUnits as a sub-algorithm to convert to dSpacing MatrixWorkspace_sptr DiffractionFocussing::convertUnitsToDSpacing(const API::MatrixWorkspace_sptr& workspace) { const std::string CONVERSION_UNIT = "dSpacing"; Unit_const_sptr xUnit = workspace->getAxis(0)->unit(); g_log.information() << "Converting units from "<< xUnit->label() << " to " << CONVERSION_UNIT<<".\n"; API::IAlgorithm_sptr childAlg = createSubAlgorithm("ConvertUnits", 0.34, 0.66); childAlg->setProperty("InputWorkspace", workspace); childAlg->setPropertyValue("Target",CONVERSION_UNIT); childAlg->executeAsSubAlg(); return childAlg->getProperty("OutputWorkspace"); }
void LoadNexusMonitors2::runLoadLogs(const std::string filename, API::MatrixWorkspace_sptr localWorkspace) { // do the actual work API::IAlgorithm_sptr loadLogs = createChildAlgorithm("LoadNexusLogs"); // Now execute the Child Algorithm. Catch and log any error, but don't stop. try { g_log.information() << "Loading logs from NeXus file..." << std::endl; loadLogs->setPropertyValue("Filename", filename); loadLogs->setProperty<API::MatrixWorkspace_sptr>("Workspace", localWorkspace); loadLogs->execute(); } catch (...) { g_log.error() << "Error while loading Logs from Nexus. Some sample logs " "may be missing." << std::endl; } }
/** Run the Child Algorithm LoadInstrument (as for LoadRaw) * @param inst_name :: The name written in the Nexus file * @param localWorkspace :: The workspace to insert the instrument into */ void LoadSpice2D::runLoadInstrument( const std::string &inst_name, DataObjects::Workspace2D_sptr localWorkspace) { API::IAlgorithm_sptr loadInst = createChildAlgorithm("LoadInstrument"); // Now execute the Child Algorithm. Catch and log any error, but don't stop. try { loadInst->setPropertyValue("InstrumentName", inst_name); loadInst->setProperty<API::MatrixWorkspace_sptr>("Workspace", localWorkspace); loadInst->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(true)); loadInst->execute(); } catch (std::invalid_argument &) { g_log.information("Invalid argument to LoadInstrument Child Algorithm"); } catch (std::runtime_error &) { g_log.information( "Unable to successfully run LoadInstrument Child Algorithm"); } }
/** * Execute the algorithm. */ void LoadBBY::exec() { // Delete the output workspace name if it existed std::string outName = getPropertyValue("OutputWorkspace"); if (API::AnalysisDataService::Instance().doesExist(outName)) API::AnalysisDataService::Instance().remove(outName); // Get the name of the data file. std::string filename = getPropertyValue(FilenameStr); ANSTO::Tar::File tarFile(filename); if (!tarFile.good()) throw std::invalid_argument("invalid BBY file"); // region of intreset std::vector<bool> roi = createRoiVector(getPropertyValue(MaskStr)); double tofMinBoundary = getProperty(FilterByTofMinStr); double tofMaxBoundary = getProperty(FilterByTofMaxStr); double timeMinBoundary = getProperty(FilterByTimeStartStr); double timeMaxBoundary = getProperty(FilterByTimeStopStr); if (isEmpty(tofMaxBoundary)) tofMaxBoundary = std::numeric_limits<double>::infinity(); if (isEmpty(timeMaxBoundary)) timeMaxBoundary = std::numeric_limits<double>::infinity(); API::Progress prog(this, 0.0, 1.0, Progress_Total); prog.doReport("creating instrument"); // create workspace DataObjects::EventWorkspace_sptr eventWS = boost::make_shared<DataObjects::EventWorkspace>(); eventWS->initialize(HISTO_BINS_Y * HISTO_BINS_X, 2, // number of TOF bin boundaries 1); // set the units eventWS->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("TOF"); eventWS->setYUnit("Counts"); // set title const std::vector<std::string> &subFiles = tarFile.files(); for (const auto &subFile : subFiles) if (subFile.compare(0, 3, "BBY") == 0) { std::string title = subFile; if (title.rfind(".hdf") == title.length() - 4) title.resize(title.length() - 4); if (title.rfind(".nx") == title.length() - 3) title.resize(title.length() - 3); eventWS->setTitle(title); break; } // create instrument InstrumentInfo instrumentInfo; // Geometry::Instrument_sptr instrument = createInstrument(tarFile, /* ref */ instrumentInfo); // eventWS->setInstrument(instrument); // load events size_t numberHistograms = eventWS->getNumberHistograms(); std::vector<EventVector_pt> eventVectors(numberHistograms, nullptr); std::vector<size_t> eventCounts(numberHistograms, 0); // phase correction Kernel::Property *periodMasterProperty = getPointerToProperty(PeriodMasterStr); Kernel::Property *periodSlaveProperty = getPointerToProperty(PeriodSlaveStr); Kernel::Property *phaseSlaveProperty = getPointerToProperty(PhaseSlaveStr); double periodMaster; double periodSlave; double phaseSlave; if (periodMasterProperty->isDefault() || periodSlaveProperty->isDefault() || phaseSlaveProperty->isDefault()) { if (!periodMasterProperty->isDefault() || !periodSlaveProperty->isDefault() || !phaseSlaveProperty->isDefault()) { throw std::invalid_argument("Please specify PeriodMaster, PeriodSlave " "and PhaseSlave or none of them."); } // if values have not been specified in loader then use values from hdf file periodMaster = instrumentInfo.period_master; periodSlave = instrumentInfo.period_slave; phaseSlave = instrumentInfo.phase_slave; } else { periodMaster = getProperty(PeriodMasterStr); periodSlave = getProperty(PeriodSlaveStr); phaseSlave = getProperty(PhaseSlaveStr); if ((periodMaster < 0.0) || (periodSlave < 0.0)) throw std::invalid_argument( "Please specify a positive value for PeriodMaster and PeriodSlave."); } double period = periodSlave; double shift = -1.0 / 6.0 * periodMaster - periodSlave * phaseSlave / 360.0; // count total events per pixel to reserve necessary memory ANSTO::EventCounter eventCounter( roi, HISTO_BINS_Y, period, shift, tofMinBoundary, tofMaxBoundary, timeMinBoundary, timeMaxBoundary, eventCounts); loadEvents(prog, "loading neutron counts", tarFile, eventCounter); // prepare event storage ANSTO::ProgressTracker progTracker(prog, "creating neutron event lists", numberHistograms, Progress_ReserveMemory); for (size_t i = 0; i != numberHistograms; ++i) { DataObjects::EventList &eventList = eventWS->getEventList(i); eventList.setSortOrder(DataObjects::PULSETIME_SORT); eventList.reserve(eventCounts[i]); eventList.setDetectorID(static_cast<detid_t>(i)); eventList.setSpectrumNo(static_cast<detid_t>(i)); DataObjects::getEventsFrom(eventList, eventVectors[i]); progTracker.update(i); } progTracker.complete(); ANSTO::EventAssigner eventAssigner( roi, HISTO_BINS_Y, period, shift, tofMinBoundary, tofMaxBoundary, timeMinBoundary, timeMaxBoundary, eventVectors); loadEvents(prog, "loading neutron events", tarFile, eventAssigner); Kernel::cow_ptr<MantidVec> axis; MantidVec &xRef = axis.access(); xRef.resize(2, 0.0); xRef[0] = std::max( 0.0, floor(eventCounter.tofMin())); // just to make sure the bins hold it all xRef[1] = eventCounter.tofMax() + 1; eventWS->setAllX(axis); // count total number of masked bins size_t maskedBins = 0; for (size_t i = 0; i != roi.size(); i++) if (!roi[i]) maskedBins++; if (maskedBins > 0) { // create list of masked bins std::vector<size_t> maskIndexList(maskedBins); size_t maskIndex = 0; for (size_t i = 0; i != roi.size(); i++) if (!roi[i]) maskIndexList[maskIndex++] = i; API::IAlgorithm_sptr maskingAlg = createChildAlgorithm("MaskDetectors"); maskingAlg->setProperty("Workspace", eventWS); maskingAlg->setProperty("WorkspaceIndexList", maskIndexList); maskingAlg->executeAsChildAlg(); } // set log values API::LogManager &logManager = eventWS->mutableRun(); logManager.addProperty("filename", filename); logManager.addProperty("att_pos", static_cast<int>(instrumentInfo.att_pos)); logManager.addProperty("frame_count", static_cast<int>(eventCounter.numFrames())); logManager.addProperty("period", period); // currently beam monitor counts are not available, instead number of frames // times period is used logManager.addProperty( "bm_counts", static_cast<double>(eventCounter.numFrames()) * period / 1.0e6); // static_cast<double>(instrumentInfo.bm_counts) // currently Kernel::time_duration duration = boost::posix_time::microseconds(static_cast<boost::int64_t>( static_cast<double>(eventCounter.numFrames()) * period)); Kernel::DateAndTime start_time("2000-01-01T00:00:00"); Kernel::DateAndTime end_time(start_time + duration); logManager.addProperty("start_time", start_time.toISO8601String()); logManager.addProperty("end_time", end_time.toISO8601String()); std::string time_str = start_time.toISO8601String(); AddSinglePointTimeSeriesProperty(logManager, time_str, "L1_chopper_value", instrumentInfo.L1_chopper_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_det_value", instrumentInfo.L2_det_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainl_value", instrumentInfo.L2_curtainl_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainr_value", instrumentInfo.L2_curtainr_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainu_value", instrumentInfo.L2_curtainu_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtaind_value", instrumentInfo.L2_curtaind_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "D_det_value", instrumentInfo.D_det_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainl_value", instrumentInfo.D_curtainl_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainr_value", instrumentInfo.D_curtainr_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainu_value", instrumentInfo.D_curtainu_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtaind_value", instrumentInfo.D_curtaind_value); AddSinglePointTimeSeriesProperty(logManager, time_str, "curtain_rotation", 10.0); API::IAlgorithm_sptr loadInstrumentAlg = createChildAlgorithm("LoadInstrument"); loadInstrumentAlg->setProperty("Workspace", eventWS); loadInstrumentAlg->setPropertyValue("InstrumentName", "BILBY"); loadInstrumentAlg->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false)); loadInstrumentAlg->executeAsChildAlg(); setProperty("OutputWorkspace", eventWS); }
/** * Executes the algorithm */ void PlotPeakByLogValue::exec() { // Create a list of the input workspace const std::vector<InputData> wsNames = makeNames(); std::string fun = getPropertyValue("Function"); //int wi = getProperty("WorkspaceIndex"); std::string logName = getProperty("LogValue"); bool sequential = getPropertyValue("FitType") == "Sequential"; bool isDataName = false; // if true first output column is of type string and is the data source name ITableWorkspace_sptr result = WorkspaceFactory::Instance().createTable("TableWorkspace"); if (logName == "SourceName") { result->addColumn("str","Source name"); isDataName = true; } else if (logName.empty()) { result->addColumn("double","axis-1"); } else { result->addColumn("double",logName); } // Create an instance of the fitting function to obtain the names of fitting parameters IFitFunction* ifun = FunctionFactory::Instance().createInitialized(fun); if (!ifun) { throw std::invalid_argument("Fitting function failed to initialize"); } for(size_t iPar=0;iPar<ifun->nParams();++iPar) { result->addColumn("double",ifun->parameterName(iPar)); result->addColumn("double",ifun->parameterName(iPar)+"_Err"); } result->addColumn("double","Chi_squared"); delete ifun; setProperty("OutputWorkspace",result); double dProg = 1./static_cast<double>(wsNames.size()); double Prog = 0.; for(int i=0;i<static_cast<int>(wsNames.size());++i) { InputData data = getWorkspace(wsNames[i]); if (!data.ws) { g_log.warning() << "Cannot access workspace " << wsNames[i].name << '\n'; continue; } if (data.i < 0 && data.indx.empty()) { g_log.warning() << "Zero spectra selected for fitting in workspace " << wsNames[i].name << '\n'; continue; } int j,jend; if (data.i >= 0) { j = data.i; jend = j + 1; } else {// no need to check data.indx.empty() j = data.indx.front(); jend = data.indx.back() + 1; } dProg /= abs(jend - j); for(;j < jend;++j) { // Find the log value: it is either a log-file value or simply the workspace number double logValue; if (logName.empty()) { API::Axis* axis = data.ws->getAxis(1); logValue = (*axis)(j); } else if (logName != "SourceName") { Kernel::Property* prop = data.ws->run().getLogData(logName); if (!prop) { throw std::invalid_argument("Log value "+logName+" does not exist"); } TimeSeriesProperty<double>* logp = dynamic_cast<TimeSeriesProperty<double>*>(prop); logValue = logp->lastValue(); } std::string resFun = fun; std::vector<double> errors; double chi2; try { // Fit the function API::IAlgorithm_sptr fit = createSubAlgorithm("Fit"); fit->initialize(); fit->setProperty("InputWorkspace",data.ws); //fit->setPropertyValue("InputWorkspace",data.ws->getName()); fit->setProperty("WorkspaceIndex",j); fit->setPropertyValue("Function",fun); fit->setPropertyValue("StartX",getPropertyValue("StartX")); fit->setPropertyValue("EndX",getPropertyValue("EndX")); fit->setPropertyValue("Minimizer",getPropertyValue("Minimizer")); fit->setPropertyValue("CostFunction",getPropertyValue("CostFunction")); fit->execute(); resFun = fit->getPropertyValue("Function"); errors = fit->getProperty("Errors"); chi2 = fit->getProperty("OutputChi2overDoF"); } catch(...) { g_log.error("Error in Fit subalgorithm"); throw; } if (sequential) { fun = resFun; } // Extract the fitted parameters and put them into the result table TableRow row = result->appendRow(); if (isDataName) { row << wsNames[i].name; } else { row << logValue; } ifun = FunctionFactory::Instance().createInitialized(resFun); for(size_t iPar=0;iPar<ifun->nParams();++iPar) { row << ifun->getParameter(iPar) << errors[iPar]; } row << chi2; delete ifun; Prog += dProg; progress(Prog); interruption_point(); } // for(;j < jend;++j) } }
/** Get a workspace identified by an InputData structure. * @param data :: InputData with name and either spec or i fields defined. * @return InputData structure with the ws field set if everything was OK. */ PlotPeakByLogValue::InputData PlotPeakByLogValue::getWorkspace(const InputData& data) { InputData out(data); if (API::AnalysisDataService::Instance().doesExist(data.name)) { DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>( API::AnalysisDataService::Instance().retrieve(data.name)); if (ws) { out.ws = ws; } else { return data; } } else { std::ifstream fil(data.name.c_str()); if (!fil) { g_log.warning() << "File "<<data.name<<" does not exist\n"; return data; } fil.close(); std::string::size_type i = data.name.find_last_of('.'); if (i == std::string::npos) { g_log.warning() << "Cannot open file "<<data.name<<"\n"; return data; } std::string ext = data.name.substr(i); try { API::IAlgorithm_sptr load = createSubAlgorithm("Load"); load->initialize(); load->setPropertyValue("FileName",data.name); load->execute(); if (load->isExecuted()) { API::Workspace_sptr rws = load->getProperty("OutputWorkspace"); if (rws) { DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(rws); if (ws) { out.ws = ws; } else { API::WorkspaceGroup_sptr gws = boost::dynamic_pointer_cast<API::WorkspaceGroup>(rws); if (gws) { std::vector<std::string> wsNames = gws->getNames(); std::string propName = "OUTPUTWORKSPACE_" + boost::lexical_cast<std::string>(data.period); if (load->existsProperty(propName)) { Workspace_sptr rws1 = load->getProperty(propName); out.ws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(rws1); } } } } } } catch(std::exception& e) { g_log.error(e.what()); return data; } } if (!out.ws) return data; API::Axis* axis = out.ws->getAxis(1); if (axis->isSpectra()) {// spectra axis if (out.spec < 0) { if (out.i >= 0) { out.spec = axis->spectraNo(out.i); } else {// i < 0 && spec < 0 => use start and end for(size_t i=0;i<axis->length();++i) { double s = double(axis->spectraNo(i)); if (s >= out.start && s <= out.end) { out.indx.push_back(static_cast<int>(i)); } } } } else { for(size_t i=0;i<axis->length();++i) { int j = axis->spectraNo(i); if (j == out.spec) { out.i = static_cast<int>(i); break; } } } if (out.i < 0 && out.indx.empty()) { return data; } } else {// numeric axis out.spec = -1; if (out.i >= 0) { out.indx.clear(); } else { if (out.i < -1) { out.start = (*axis)(0); out.end = (*axis)(axis->length()-1); } for(size_t i=0;i<axis->length();++i) { double s = (*axis)(i); if (s >= out.start && s <= out.end) { out.indx.push_back(static_cast<int>(i)); } } } } return out; }
void MaskBinsFromTable::exec() { MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace"); DataObjects::TableWorkspace_sptr paramWS = getProperty("MaskingInformation"); // 1. Check input table workspace and column order g_log.debug() << "Lines of parameters workspace = " << paramWS->rowCount() << std::endl; bool colname_specx = false; if (!paramWS) { throw std::invalid_argument("Input table workspace is not accepted."); } else { std::vector<std::string> colnames = paramWS->getColumnNames(); // check colum name order if (colnames.size() < 3) { g_log.error() << "Input MaskingInformation table workspace has fewer than 3 columns. " << colnames.size() << " columns indeed" << std::endl; throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns."); } if (colnames[0].compare("XMin") == 0) { // 1. Style XMin, XMax, SpectraList. Check rest if (colnames[1].compare("XMax") != 0 || colnames[2].compare("SpectraList") != 0) { g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl; throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns."); } } else if (colnames[0].compare("SpectraList") == 0) { // 2. Style SpectraList, XMin, XMax colname_specx = true; if (colnames[1].compare("XMin") != 0 || colnames[2].compare("XMax") != 0) { g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl; throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns."); } } else { g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl; throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns."); } } // 2. Loop over all rows bool firstloop = true; API::MatrixWorkspace_sptr outputws = this->getProperty("OutputWorkspace"); for (size_t ib = 0; ib < paramWS->rowCount(); ++ib) { API::TableRow therow = paramWS->getRow(ib); double xmin, xmax; std::string speclist; if (colname_specx) { therow >> speclist >> xmin >> xmax; } else { therow >> xmin >> xmax >> speclist; } g_log.debug() << "Row " << ib << " XMin = " << xmin << " XMax = " << xmax << " SpectraList = " << speclist << std::endl; API::IAlgorithm_sptr maskbins = this->createChildAlgorithm("MaskBins", 0, 0.3, true); maskbins->initialize(); if (firstloop) { maskbins->setProperty("InputWorkspace", inputWS); firstloop = false; } else { maskbins->setProperty("InputWorkspace", outputws); } maskbins->setProperty("OutputWorkspace", outputws); maskbins->setPropertyValue("SpectraList", speclist); maskbins->setProperty("XMin", xmin); maskbins->setProperty("XMax", xmax); bool isexec = maskbins->execute(); if (!isexec) { g_log.error() << "MaskBins() is not executed for row " << ib << std::endl; throw std::runtime_error("MaskBins() is not executed"); } outputws = maskbins->getProperty("OutputWorkspace"); if (!outputws) { g_log.error() << "OutputWorkspace is not retrieved for row " << ib << ". " << std::endl; throw std::runtime_error("OutputWorkspace is not got from MaskBins"); } }
/// Execute the algorithm void SassenaFFT::exec() { const std::string gwsName = this->getPropertyValue("InputWorkspace"); API::WorkspaceGroup_sptr gws = this->getProperty("InputWorkspace"); const std::string ftqReName = gwsName + "_fqt.Re"; const std::string ftqImName = gwsName + "_fqt.Im"; // Make sure the intermediate structure factor is there if(!gws->contains(ftqReName) ) { const std::string errMessg = "workspace "+gwsName+" does not contain an intermediate structure factor"; this->g_log.error(errMessg); throw Kernel::Exception::NotFoundError("group workspace does not contain",ftqReName); } // Retrieve the real and imaginary parts of the intermediate scattering function DataObjects::Workspace2D_sptr fqtRe = boost::dynamic_pointer_cast<DataObjects::Workspace2D>( gws->getItem( ftqReName ) ); DataObjects::Workspace2D_sptr fqtIm = boost::dynamic_pointer_cast<DataObjects::Workspace2D>( gws->getItem( ftqImName ) ); // Calculate the FFT for all spectra, retaining only the real part since F(q,-t) = F*(q,t) int part=3; // extract the real part of the transform, assuming I(Q,t) is real const std::string sqwName = gwsName + "_sqw"; API::IAlgorithm_sptr fft = this->createChildAlgorithm("ExtractFFTSpectrum"); fft->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace", fqtRe); if( !this->getProperty("FFTonlyRealPart") ) { part=0; // extract the real part of the transform, assuming I(Q,t) is complex fft->setProperty<DataObjects::Workspace2D_sptr>("InputImagWorkspace", fqtIm); } fft->setPropertyValue("OutputWorkspace", sqwName ); fft->setProperty<int>("FFTPart",part); // extract the real part fft->executeAsChildAlg(); API::MatrixWorkspace_sptr sqw0 = fft->getProperty("OutputWorkspace"); DataObjects::Workspace2D_sptr sqw = boost::dynamic_pointer_cast<DataObjects::Workspace2D>( sqw0 ); API::AnalysisDataService::Instance().addOrReplace( sqwName, sqw ); // Transform the X-axis to appropriate dimensions // We assume the units of the intermediate scattering function are in picoseconds // The resulting frequency unit is in mili-eV, thus use m_ps2meV API::IAlgorithm_sptr scaleX = this->createChildAlgorithm("ScaleX"); scaleX->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace",sqw); scaleX->setProperty<double>("Factor", m_ps2meV); scaleX->setProperty<DataObjects::Workspace2D_sptr>("OutputWorkspace", sqw); scaleX->executeAsChildAlg(); //Do we apply the detailed balance condition exp(E/(2*kT)) ? if( this->getProperty("DetailedBalance") ) { double T = this->getProperty("Temp"); // The ExponentialCorrection algorithm assumes the form C0*exp(-C1*x). Note the explicit minus in the exponent API::IAlgorithm_sptr ec = this->createChildAlgorithm("ExponentialCorrection"); ec->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace", sqw); ec->setProperty<DataObjects::Workspace2D_sptr>("OutputWorkspace", sqw); ec->setProperty<double>("C0",1.0); ec->setProperty<double>("C1",-1.0/(2.0*T*m_T2ueV)); // Temperature in units of ueV ec->setPropertyValue("Operation","Multiply"); ec->executeAsChildAlg(); } // Set the Energy unit for the X-axis sqw->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("DeltaE"); // Add to group workspace, except if we are replacing the workspace. In this case, the group workspace // is already notified of the changes by the analysis data service. if(!gws->contains(sqwName)) { gws->add( sqwName ); } else { this->g_log.information("Workspace "+sqwName+" replaced with new contents"); } }