diff --git a/Code/Mantid/Framework/SINQ/CMakeLists.txt b/Code/Mantid/Framework/SINQ/CMakeLists.txt index 2bbfc3208287..e527f331e1e9 100644 --- a/Code/Mantid/Framework/SINQ/CMakeLists.txt +++ b/Code/Mantid/Framework/SINQ/CMakeLists.txt @@ -3,6 +3,7 @@ set ( SRC_FILES src/LoadFlexiNexus.cpp src/MDHistoToWorkspace2D.cpp src/PoldiAutoCorrelation5.cpp + src/PoldiCalculateSpectrum2D.cpp src/PoldiFitPeaks1D.cpp src/PoldiLoadChopperSlits.cpp src/PoldiLoadIPP.cpp @@ -38,6 +39,7 @@ set ( INC_FILES inc/MantidSINQ/LoadFlexiNexus.h inc/MantidSINQ/MDHistoToWorkspace2D.h inc/MantidSINQ/PoldiAutoCorrelation5.h + inc/MantidSINQ/PoldiCalculateSpectrum2D.h inc/MantidSINQ/PoldiFitPeaks1D.h inc/MantidSINQ/PoldiLoadChopperSlits.h inc/MantidSINQ/PoldiLoadIPP.h diff --git a/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiCalculateSpectrum2D.h b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiCalculateSpectrum2D.h new file mode 100644 index 000000000000..ee9de445a456 --- /dev/null +++ b/Code/Mantid/Framework/SINQ/inc/MantidSINQ/PoldiCalculateSpectrum2D.h @@ -0,0 +1,59 @@ +#ifndef MANTID_SINQ_POLDICALCULATESPECTRUM2D_H_ +#define MANTID_SINQ_POLDICALCULATESPECTRUM2D_H_ + +#include "MantidKernel/System.h" +#include "MantidSINQ/DllConfig.h" +#include "MantidAPI/Algorithm.h" +#include "MantidAPI/IDomainCreator.h" + +namespace Mantid +{ +namespace Poldi +{ + +/** PoldiCalculateSpectrum2D : TODO: DESCRIPTION + + Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + File change history is stored at: + Code Documentation is available at: + */ + +class MANTID_SINQ_DLL PoldiCalculateSpectrum2D : public API::Algorithm +{ +public: + PoldiCalculateSpectrum2D(); + virtual ~PoldiCalculateSpectrum2D(); + + virtual const std::string name() const; + virtual int version() const; + virtual const std::string category() const; + +private: + virtual void initDocs(); + void init(); + void exec(); + + +}; + + +} // namespace Poldi +} // namespace Mantid + +#endif /* MANTID_SINQ_POLDICALCULATESPECTRUM2D_H_ */ diff --git a/Code/Mantid/Framework/SINQ/src/PoldiCalculateSpectrum2D.cpp b/Code/Mantid/Framework/SINQ/src/PoldiCalculateSpectrum2D.cpp new file mode 100644 index 000000000000..308617060357 --- /dev/null +++ b/Code/Mantid/Framework/SINQ/src/PoldiCalculateSpectrum2D.cpp @@ -0,0 +1,108 @@ +/*WIKI* +TODO: Enter a full wiki-markup description of your algorithm here. You can then use the Build/wiki_maker.py script to generate your full wiki page. +*WIKI*/ + +#include "MantidSINQ/PoldiCalculateSpectrum2D.h" + +#include "MantidDataObjects/Workspace2D.h" +#include "MantidAPI/FunctionFactory.h" +#include "MantidAPI/MultiDomainFunction.h" +#include "MantidSINQ/PoldiUtilities/PoldiSpectrumDomainFunction.h" + +namespace Mantid +{ +namespace Poldi +{ + // Register the algorithm into the AlgorithmFactory + DECLARE_ALGORITHM(PoldiCalculateSpectrum2D) + + using namespace API; + + + //---------------------------------------------------------------------------------------------- + /** Constructor + */ + PoldiCalculateSpectrum2D::PoldiCalculateSpectrum2D() + { + } + + //---------------------------------------------------------------------------------------------- + /** Destructor + */ + PoldiCalculateSpectrum2D::~PoldiCalculateSpectrum2D() + { + } + + + //---------------------------------------------------------------------------------------------- + /// Algorithm's name for identification. @see Algorithm::name + const std::string PoldiCalculateSpectrum2D::name() const { return "PoldiCalculateSpectrum2D";} + + /// Algorithm's version for identification. @see Algorithm::version + int PoldiCalculateSpectrum2D::version() const { return 1;} + + /// Algorithm's category for identification. @see Algorithm::category + const std::string PoldiCalculateSpectrum2D::category() const { return "SINQ\\Poldi\\PoldiSet";} + + //---------------------------------------------------------------------------------------------- + /// Sets documentation strings for this algorithm + void PoldiCalculateSpectrum2D::initDocs() + { + this->setWikiSummary("TODO: Enter a quick description of your algorithm."); + this->setOptionalMessage("TODO: Enter a quick description of your algorithm."); + } + + //---------------------------------------------------------------------------------------------- + /** Initialize the algorithm's properties. + */ + void PoldiCalculateSpectrum2D::init() + { + declareProperty(new WorkspaceProperty("InputWorkspace","",Direction::Input), "An input workspace."); + declareProperty(new WorkspaceProperty("OutputWorkspace","",Direction::Output), "An output workspace."); + } + + //---------------------------------------------------------------------------------------------- + /** Execute the algorithm. + */ + void PoldiCalculateSpectrum2D::exec() + { + IFunction_sptr peakFunction = FunctionFactory::Instance().createFunction("PoldiSpectrumDomainFunction"); + peakFunction->setParameter("Area", 1.9854805); + peakFunction->setParameter("Fwhm", 0.00274463167); + peakFunction->setParameter("Centre", 1.1086444); + + boost::shared_ptr mdFunction(new MultiDomainFunction); + mdFunction->addFunction(peakFunction); + + MatrixWorkspace_sptr ws = getProperty("InputWorkspace"); + + std::vector wsi(400); + for(size_t w = 0; w < wsi.size(); ++w) { + wsi[w] = w; + } + + mdFunction->setDomainIndices(0, wsi); + mdFunction->setLocalAttribute(0, "domains", API::IFunction::Attribute("All")); + + IAlgorithm_sptr fit = createChildAlgorithm("Fit", -1, -1, true); + fit->setProperty("Function", boost::dynamic_pointer_cast(mdFunction)); + fit->setProperty("InputWorkspace", ws); + + for(size_t i = 1; i < 400; ++i) { + fit->setProperty("InputWorkspace_" + boost::lexical_cast(i), ws); + //fit->setProperty("WorkspaceIndex_" + boost::lexical_cast(i + 1), i); + } + + fit->setProperty("CreateOutput", true); + fit->setProperty("MaxIterations", 0); + + fit->execute(); + + setProperty("OutputWorkspace", fit->getPropertyValue("OutputWorkspace")); + } + // TODO Auto-generated execute stub + + + +} // namespace Poldi +} // namespace Mantid