Skip to content

Commit

Permalink
Refs #9445. Created 2D-spectrum calculation test
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed May 16, 2014
1 parent af76395 commit 39124fb
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/SINQ/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
@@ -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 <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

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_ */
108 changes: 108 additions & 0 deletions 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<MatrixWorkspace>("InputWorkspace","",Direction::Input), "An input workspace.");
declareProperty(new WorkspaceProperty<MatrixWorkspace>("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<MultiDomainFunction> mdFunction(new MultiDomainFunction);
mdFunction->addFunction(peakFunction);

MatrixWorkspace_sptr ws = getProperty("InputWorkspace");

std::vector<size_t> 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<IFunction>(mdFunction));
fit->setProperty("InputWorkspace", ws);

for(size_t i = 1; i < 400; ++i) {
fit->setProperty("InputWorkspace_" + boost::lexical_cast<std::string>(i), ws);
//fit->setProperty("WorkspaceIndex_" + boost::lexical_cast<std::string>(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

0 comments on commit 39124fb

Please sign in to comment.